1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright (C) 2024 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 re 19import time 20import sys 21sys.path.append("..") 22from tools.utils import * 23import threading 24 25OUTPUT_PATH = "testRoot/output" 26LIB_PATH = "/system/lib" 27THRESH = 25000000000 28CLICK_TIMES = 150 29SWIPE_TIMES = 20 30SLEEP_TWENTY = 20 31SLEEP_FIVE = 5 32SLEEP_FOUR = 4 33SLEEP_TWO = 2 34SETTING_INDEX = 13 35GC_INTERVAL = 10 36SLEEP_LONG = 195 37WAIT_TIMES = 7 38HOOK_SETTINGS_TIMES = 5 39TEST_TIMES = 20 40 41 42def task_cmd(index): 43 indexstr = str(index) 44 subprocess.check_output(f"hdc shell hiprofiler_cmd -c /data/local/tmp/config" + indexstr + ".txt -o /data/local/tmp/test" + indexstr + ".htrace -t 20 -s -k") 45 46 47def check_faultlog(): 48 check = True 49 with open(r'.\..\outputfiles\faultlog.txt', 'r') as file: 50 lines = file.readlines() 51 for line in lines: 52 if "com.ohos.launcher" in line and ("syswarning" not in line): 53 check = False 54 if "render_service" in line: 55 check = False 56 if "com.example.insight_test_stage" in line: 57 check = False 58 return check 59 60 61class TestHiprofilerReliability: 62 @pytest.mark.L0 63 def test_appfreeze_sceneboard_sa(self): 64 subprocess.check_output("hdc shell rm /data/local/tmp/test.htrace", text=True, encoding="utf-8") 65 subprocess.check_output("hdc shell rm /data/log/reliability/resource_leak/memory_leak/*", text=True, encoding="utf-8") 66 try: 67 subprocess.check_output(r"del .\..\outputfiles\nativehook.db ", text=True, encoding="utf-8") 68 subprocess.check_output(r"del .\..\outputfiles\test.htrace", text=True, encoding="utf-8") 69 except Exception as e: 70 print(f"An error occurred: {e}") 71 pass 72 subprocess.check_output("hdc target mount", text=True, encoding="utf-8") 73 subprocess.check_output(f"hdc file send .\..\inputfiles\process_resource_limit_reliability.json /data/local/tmp/", text=True, encoding="utf-8") 74 subprocess.check_output(f"hdc shell mv /data/local/tmp/process_resource_limit_reliability.json /data/local/tmp/process_resource_limit.json", text=True, encoding="utf-8") 75 subprocess.check_output(f"hdc shell cp /data/local/tmp/process_resource_limit.json /system/variant/phone/base/etc/efficiency_manager/", text=True, encoding="utf-8") 76 subprocess.check_output("hdc shell reboot", text=True, encoding="utf-8") 77 time.sleep(SLEEP_TWENTY) 78 j = 0 79 while j < WAIT_TIMES: 80 output = subprocess.check_output("hdc list targets", text=True, encoding="utf-8") 81 if output == '[Empty]\n\n': 82 time.sleep(SLEEP_FIVE) 83 j += 1 84 else: 85 break 86 87 #解除锁屏 88 subprocess.check_output("hdc shell uitest uinput drag 100 500 100 100 1000") 89 time.sleep(SLEEP_FIVE) 90 subprocess.check_output("hdc shell uitest uinput drag 100 500 100 100 1000") 91 time.sleep(SLEEP_FIVE) 92 subprocess.check_output("hdc shell uitest uinput drag 100 500 100 100 1000") 93 94 subprocess.check_output("hdc shell power-shell setmode 602") 95 96 subprocess.check_output("hdc shell killall com.example.insight_test_stage") 97 subprocess.check_output("hdc shell param set hiview.memleak.test disable") 98 subprocess.check_output("hdc shell killall hiview") 99 sceneboard = get_pid("com.ohos.launcher") 100 101 i = 0 102 while i < CLICK_TIMES: 103 subprocess.check_output("hdc shell uinput -T -m 200 1500 2000 1500") 104 subprocess.check_output("hdc shell uinput -T -m 2000 1500 200 1500") 105 time.sleep(SLEEP_FIVE) 106 if ((i % GC_INTERVAL) == 0): 107 subprocess.check_output("hdc shell hidumper --mem-jsheap " + str(sceneboard)) 108 i += 1 109 110 111 subprocess.check_output("hdc shell ls -lh /data/log/faultlog/faultlogger/ > /data/local/tmp/faultlog.txt") 112 subprocess.check_output(f"hdc file recv /data/local/tmp/faultlog.txt .\..\outputfiles\ ", text=True, encoding="utf-8") 113 check = True 114 with open(r'.\..\outputfiles\faultlog.txt', 'r') as file: 115 lines = file.readlines() 116 for line in lines: 117 if "com.ohos.launcher" in line and ("syswarning" not in line): 118 check = False 119 if "render_service" in line: 120 check = False 121 assert check 122 123 def test_appfreeze_profiler_test(self): 124 subprocess.check_output("hdc shell rm /data/log/reliability/resource_leak/memory_leak/*", text=True, encoding="utf-8") 125 subprocess.check_output("hdc shell param set hiview.memleak.test disable") 126 i = 0 127 check = True 128 while i < TEST_TIMES: 129 i += 1 130 subprocess.check_output("hdc shell killall hiview") 131 subprocess.check_output("hdc shell killall com.example.insight_test_stage") 132 subprocess.check_output("hdc shell aa start -a EntryAbility -b com.example.insight_test_stage") 133 time.sleep(SLEEP_FOUR) 134 touch_button("模板测试") 135 time.sleep(1) 136 subprocess.check_output("hdc shell uitest uinput drag 100 800 100 100 1000") 137 time.sleep(1) 138 touch_button("Allocations_Js_Depth") 139 i = 0 140 while i < CLICK_TIMES: 141 touch_button("malloc-release(depth 6)") 142 touch_button("small-malloc(depth 7)") 143 i += 1 144 time.sleep(SLEEP_FIVE) 145 146 subprocess.check_output("hdc shell ls -lh /data/log/faultlog/faultlogger/ > /data/local/tmp/faultlog.txt") 147 subprocess.check_output(f"hdc file recv /data/local/tmp/faultlog.txt .\..\outputfiles\ ", text=True, encoding="utf-8") 148 if not check_faultlog(): 149 check = False 150 assert check 151 152 def test_appfreeze_cmd_settings(self): 153 subprocess.check_output(f"hdc file send .\..\inputfiles\nativehook\config13.txt /data/local/tmp/", text=True, encoding="utf-8") 154 j = 0 155 i = 0 156 time.sleep(SLEEP_LONG) 157 while j < HOOK_SETTINGS_TIMES: 158 j += 1 159 task_thread = threading.Thread(target=task_cmd, args=(SETTING_INDEX, )) 160 task_thread.start() 161 i = 0 162 time.sleep(SLEEP_TWO) 163 subprocess.check_output("hdc shell killall com.ohos.launcher") 164 subprocess.check_output("hdc shell aa start -a EntryAbility -b com.ohos.launcher") 165 time.sleep(SLEEP_FIVE) 166 while (i < SWIPE_TIMES): 167 subprocess.check_output("hdc shell uinput -T -m 200 1500 200 200") 168 i += 1 169 task_thread.join() 170 j += 1 171 172 subprocess.check_output("hdc shell ls -lh /data/log/faultlog/faultlogger/ > /data/local/tmp/faultlog.txt") 173 subprocess.check_output(f"hdc file recv /data/local/tmp/faultlog.txt .\..\outputfiles\ ", text=True, encoding="utf-8") 174 check = True 175 with open(r'.\..\outputfiles\faultlog.txt', 'r') as file: 176 lines = file.readlines() 177 for line in lines: 178 if "com.ohos.launcher" in line: 179 check = False 180 if "render_service" in line: 181 check = False 182 assert check == True