• 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.
15#
16import pytest
17import subprocess
18import json
19from hiperf_utils import validate_json
20
21
22class TestParseABC:
23    res = False
24
25    def setup(self):
26        print('test_parse_abc setup')
27
28    def fun(self, jo, val):
29        call_tack = jo['callStack']
30        if jo['symbol'] == val:
31            self.res = True
32            return
33
34        for a in call_tack:
35            self.fun(a, val)
36
37    @pytest.mark.L0
38    def test_parse_abc(self):
39        subprocess.call('hdc shell rm /data/local/tmp/perf_parse_abc.json')
40        subprocess.call('hdc file send perf_parse_abc.data /data/local/tmp')
41        subprocess.call('hdc shell hiperf report --json -i /data/local/tmp/perf_parse_abc.data -o /data/local/tmp/perf_parse_abc.json')
42        subprocess.call('hdc file recv /data/local/tmp/perf_parse_abc.json')
43        with open('./perf_parse_abc.json', 'r') as file:
44            json_data = file.read()
45            assert validate_json(json_data) == True
46            jo = json.loads(json_data)
47            arr = jo['symbolsFileList']
48            index = 0
49            for a in arr:
50                if a.find('.abc') > 0:
51                    break
52                index = index + 1
53            print(index)
54            arrmap = jo['SymbolMap']
55            val = 0
56            for a in arrmap:
57                if arrmap[a]['file'] == index and 'UpdateElement:' in arrmap[a]['symbol']:
58                    print(arrmap[a]['symbol'])
59                    val = int(a)
60                    print(val)
61                    break
62            record = jo['recordSampleInfo']
63            for a in record:
64                processes = a['processes']
65                for b in processes:
66                    threads = b['threads']
67                    for c in threads:
68                        print(c['tid'])
69                        call_stack = c['CallOrder']['callStack']
70                        for d in call_stack:
71                            self.fun(d, val)
72        assert self.res == True
73