• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#   Copyright (c) 2025 Huawei Device Co., Ltd.
4#   Licensed under the Apache License, Version 2.0 (the "License");
5#   you may not use this file except in compliance with the License.
6#   You may obtain a copy of the License at
7#
8#       http://www.apache.org/licenses/LICENSE-2.0
9#
10#   Unless required by applicable law or agreed to in writing, software
11#   distributed under the License is distributed on an "AS IS" BASIS,
12#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#   See the License for the specific language governing permissions and
14#   limitations under the License.
15import pytest
16import os
17import argparse
18import json
19from hiperf_utils import dir_check
20from hiperf_utils import file_check
21from hiperf_utils import get_used_binaries
22from hiperf_utils import validate_json
23
24
25class TestReport:
26    def setup(self):
27        print("TestReport setup")
28
29    @pytest.mark.L0
30    def test_report(self):
31        parser = argparse.ArgumentParser(description=""" To make a report, you
32        need to enter the data source and the path of the report.""")
33        parser.add_argument('-i', '--perf_data', default='perf.data',
34                            type=file_check, help=""" The path of profiling
35                            data.""")
36        parser.add_argument('-r', '--report_html', default='hiperf_report.html',
37                            help="""the path of the report.""")
38        parser.add_argument('-l', '--local_lib_dir', type=dir_check, default='./testModule/binary_cache',
39                            help="""Path to find symbol dir use to
40                            do offline unwind stack""")
41        args = parser.parse_args()
42
43        get_used_binaries(args.perf_data, args.report_html, args.local_lib_dir)
44
45        with open('./json.txt', 'r') as file:
46            json_data = file.read()
47            assert validate_json(json_data) == True
48            jo = json.loads(json_data)
49            record = jo['recordSampleInfo']
50            for a in record:
51                processes = a['processes']
52                for b in processes:
53                    threads = b['threads']
54                    for c in threads:
55                        print(c['tid'])
56                        call_stack = c['CallOrder']['callStack']
57                        assert len(call_stack) > 0
58
59        assert os.path.exists('./hiperf_report.html') == True
60