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 threading 21 22 23class MyThread(threading.Thread): 24 def run(self): 25 time.sleep(1) 26 subprocess.call('hdc shell aa force-stop com.example.insight_test_stage') 27 time.sleep(2) 28 subprocess.call('hdc shell aa start -a EntryAbility -b com.example.insight_test_stage') 29 30 31class TestStatLaunch: 32 res = False 33 34 def setup(self): 35 print("test_stat_launch setup") 36 37 def record_cmd(self): 38 if os.path.exists('./perf_launch.json') == True: 39 os.remove('./perf_launch.json') 40 subprocess.call("hdc shell rm /data/local/tmp/hiprofiler_data.htrace /data/local/tmp/perf.data /data/local/tmp/perf_launch.json") 41 subprocess.call('hdc shell aa start -a EntryAbility -b com.example.insight_test_stage') 42 thread = MyThread() 43 thread.start() 44 output = os.popen('hdc shell hiperf stat -d 5 --app com.example.insight_test_stage --restart').read() 45 thread.join() 46 return output 47 48 @pytest.mark.L0 49 def test_stat_launch(self): 50 subprocess.call('hdc shell rm -rf /data/local/tmp/85dcdfa') 51 subprocess.call('hdc shell aa force-stop com.example.insight_test_stage') 52 subprocess.call('hdc shell mkdir /data/local/tmp/85dcdfa') 53 subprocess.call('hdc file send .\libraryhsp1-default-signed.hsp /data/local/tmp/85dcdfa') 54 subprocess.call('hdc file send .\entry-default-signed.hap /data/local/tmp/85dcdfa') 55 subprocess.call('hdc file send .\libraryhsp2cpp-default-signed.hsp /data/local/tmp/85dcdfa') 56 subprocess.call('hdc shell bm install -p /data/local/tmp/85dcdfa') 57 subprocess.call('hdc shell rm -rf /data/local/tmp/85dcdfa') 58 subprocess.call('hdc file send config_launch.txt /data/local/tmp') 59 output = self.record_cmd() 60 subprocess.call('hdc shell aa force-stop com.example.insight_test_stage') 61 arr = ["hw-branch-instructions", "hw-branch-misses", "hw-cpu-cycles", "hw-instructions"] 62 for a in arr: 63 assert a in output 64