• 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 os
19import time
20import json
21from hiperf_utils import validate_json
22
23
24class TestLaunch:
25    res = False
26
27    def setup(self):
28        print("test_launch setup")
29
30    def record_cmd(self):
31        if os.path.exists('./perf_launch.json') == True:
32            os.remove('./perf_launch.json')
33        subprocess.call("hdc shell rm /data/local/tmp/hiprofiler_data.htrace /data/local/tmp/perf.data /data/local/tmp/perf_launch.json")
34        subprocess.call('hdc shell aa force-stop com.example.insight_test_stage')
35        subprocess.Popen(f'hdc shell "hiprofiler_cmd -o /data/local/tmp/hiprofiler_data.htrace -t 10 -s -k -c /data/local/tmp/config_launch.txt &"')
36        time.sleep(5)
37        subprocess.call('hdc shell aa start -a EntryAbility -b com.example.insight_test_stage')
38        time.sleep(20)
39        subprocess.call('hdc shell hiperf report --json -i /data/local/tmp/perf.data -o /data/local/tmp/perf_launch.json')
40        subprocess.call("hdc file recv /data/local/tmp/perf_launch.json ./")
41
42    @pytest.mark.L0
43    def test_launch(self):
44        subprocess.call('hdc shell rm -rf /data/local/tmp/85dcdfa')
45        subprocess.call('hdc shell aa force-stop com.example.insight_test_stage')
46        subprocess.call('hdc shell mkdir /data/local/tmp/85dcdfa')
47        subprocess.call('hdc file send .\libraryhsp1-default-signed.hsp /data/local/tmp/85dcdfa')
48        subprocess.call('hdc file send .\entry-default-signed.hap /data/local/tmp/85dcdfa')
49        subprocess.call('hdc file send .\libraryhsp2cpp-default-signed.hsp /data/local/tmp/85dcdfa')
50        subprocess.call('hdc shell bm install -p /data/local/tmp/85dcdfa')
51        subprocess.call('hdc shell rm -rf /data/local/tmp/85dcdfa')
52        subprocess.call('hdc shell setenforce 0')
53        subprocess.call('hdc file send config_launch.txt /data/local/tmp')
54        self.record_cmd()
55        subprocess.call('hdc shell aa force-stop com.example.insight_test_stage')
56        subprocess.call('hdc shell setenforce 1')
57        assert os.path.exists('./perf_launch.json') == True
58
59        with open('perf_launch.json', 'r') as file:
60            json_data = file.read()
61            assert validate_json(json_data) == True
62            jo = json.loads(json_data)
63            arr = jo['threadNameMap']
64            count = 0
65            for a in arr:
66                print(arr[a])
67                count = count + 1
68                if arr[a] == 'OS_DfxWatchdog':
69                    self.res = True
70            print(count)
71
72        assert self.res == True
73