import pytest
import subprocess
import json
from hiperf_utils import validate_json
class TestParseABC:
res = False
def setup(self):
print('test_parse_abc setup')
def fun(self, jo, val):
call_tack = jo['callStack']
if jo['symbol'] == val:
self.res = True
return
for a in call_tack:
self.fun(a, val)
@pytest.mark.L0
def test_parse_abc(self):
subprocess.call('hdc shell rm /data/local/tmp/perf_parse_abc.json')
subprocess.call('hdc file send perf_parse_abc.data /data/local/tmp')
subprocess.call('hdc shell hiperf report --json -i /data/local/tmp/perf_parse_abc.data -o /data/local/tmp/perf_parse_abc.json')
subprocess.call('hdc file recv /data/local/tmp/perf_parse_abc.json')
with open('./perf_parse_abc.json', 'r') as file:
json_data = file.read()
assert validate_json(json_data) == True
jo = json.loads(json_data)
arr = jo['symbolsFileList']
index = 0
for a in arr:
if a.find('.abc') > 0:
break
index = index + 1
print(index)
arrmap = jo['SymbolMap']
val = 0
for a in arrmap:
if arrmap[a]['file'] == index and 'UpdateElement:' in arrmap[a]['symbol']:
print(arrmap[a]['symbol'])
val = int(a)
print(val)
break
record = jo['recordSampleInfo']
for a in record:
processes = a['processes']
for b in processes:
threads = b['threads']
for c in threads:
print(c['tid'])
call_stack = c['CallOrder']['callStack']
for d in call_stack:
self.fun(d, val)
assert self.res == True