1# -*- coding: utf-8 -*- 2# Copyright (c) 2022 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15from ast import parse 16import json 17import sys 18import os 19import time 20import argparse 21import re 22import subprocess 23import shlex 24import datetime 25 26def PrintToLog(str): 27 time = datetime.datetime.now() 28 str = "[{}] {}".format(time, str) 29 print(str) 30 with open(os.path.join(args.save_path, 'shot_test_{}.log'.format(args.device_num)),\ 31 mode='a', encoding='utf-8') as log_file: 32 console = sys.stdout 33 sys.stdout = log_file 34 print(str) 35 sys.stdout = console 36 log_file.close() 37 38def EnterCmd(mycmd, waittime=0, printresult=1): 39 if mycmd == "": 40 return 41 global CmdRetryCnt 42 CmdRetryCnt = 1 43 EnterCmdRetry = 2 44 while EnterCmdRetry: 45 EnterCmdRetry -= 1 46 try: 47 p = subprocess.Popen(mycmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 48 result, unused_err = p.communicate(timeout=25) 49 try: 50 result=result.decode(encoding="utf-8") 51 except UnicodeDecodeError: 52 result=result.decode('gbk', errors='ignore') 53 break 54 except Exception as e: 55 result = 'retry failed again' 56 PrintToLog(e) 57 CmdRetryCnt += 1 58 p.kill() 59 if printresult == 1: 60 with open(os.path.join(args.save_path, 'shot_test_{}.bat'.format(args.device_num)),\ 61 mode='a', encoding='utf-8') as cmd_file: 62 cmd_file.write(mycmd + '\n') 63 cmd_file.close() 64 PrintToLog(mycmd) 65 PrintToLog(result) 66 sys.stdout.flush() 67 if waittime != 0: 68 time.sleep(waittime) 69 if printresult == 1: 70 with open(os.path.join(args.save_path, 'shot_test_{}.bat'.format(args.device_num)),\ 71 mode='a', encoding='utf-8') as cmd_file: 72 cmd_file.write("ping -n {} 127.0.0.1>null\n".format(waittime)) 73 cmd_file.close() 74 return result 75 76def EnterShellCmd(shellcmd, waittime=0, printresult=1): 77 if shellcmd == "": 78 return 79 cmd = "hdc_std -t {} shell \"{}\"".format(args.device_num, shellcmd) 80 return EnterCmd(cmd, waittime, printresult) 81 82def SysExit(): 83 EnterShellCmd("cd /data/log/faultlog/temp && tar -cf after_test_crash_log_{}.tar cppcrash*".format(args.device_num)) 84 GetFileFromDev("/data/log/faultlog/temp/after_test_crash_log_{}.tar".format(args.device_num),\ 85 os.path.normpath(args.save_path)) 86 sys.exit(99) 87 88def SendFileToDev(src, dst): 89 cmd = "hdc_std -t {} file send \"{}\" \"{}\"".format(args.device_num, src, dst) 90 return EnterCmd(cmd, 1, 1) 91 92def GetFileFromDev(src, dst): 93 cmd = "hdc_std -t {} file recv \"{}\" \"{}\"".format(args.device_num, src, dst) 94 return EnterCmd(cmd, 1, 1) 95 96def connection_judgment(): 97 connection_status = EnterCmd("hdc_std list targets", 2) 98 connection_cnt = 0 99 while "7001005458323933328a" not in connection_status and connection_cnt < 15: 100 connection_status = EnterCmd("hdc_std list targets", 2) 101 connection_cnt += 1 102 if connection_cnt == 15: 103 PrintToLog("Device disconnection!!") 104 PrintToLog("End of check, test failed!") 105 sys.exit(101) 106 107def ConnectToWifi(tools_path): 108 EnterShellCmd("mkdir /data/l2tool", 1) 109 SendFileToDev(os.path.normpath(os.path.join(tools_path, "l2tool/busybox")), "/data/l2tool/") 110 SendFileToDev(os.path.normpath(os.path.join(tools_path, "l2tool/dhcpc.sh")), "/data/l2tool/") 111 SendFileToDev(os.path.normpath(os.path.join(tools_path, "l2tool/wpa_supplicant.conf")), "/data/l2tool/") 112 EnterShellCmd("wpa_supplicant -B -d -i wlan0 -c /data/l2tool/wpa_supplicant.conf", 1) 113 EnterShellCmd("chmod 777 ./data/l2tool/busybox", 1) 114 cnt = 2 115 while cnt: 116 try: 117 PrintToLog("hdc_std shell ./data/l2tool/busybox udhcpc -i wlan0 -s /data/l2tool/dhcpc.sh") 118 p = subprocess.check_output(shlex.split("hdc_std -t {} shell ./data/l2tool/busybox udhcpc -i\ 119 wlan0 -s /data/l2tool/dhcpc.sh".format(args.device_num)), timeout=8) 120 PrintToLog(p.decode(encoding="utf-8")) 121 with open(os.path.join(args.save_path, 'shot_test_{}.bat'.format(args.device_num)),\ 122 mode='a', encoding='utf-8') as cmd_file: 123 cmd_file.write('hdc_std shell ./data/l2tool/busybox udhcpc -i wlan0 -s /data/l2tool/dhcpc.sh' + '\n') 124 cmd_file.close() 125 ret_code = 0 126 except subprocess.TimeoutExpired as time_e: 127 PrintToLog(time_e) 128 ret_code = 1 129 if ret_code == 0: 130 ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", p.decode(encoding="utf-8")) 131 PrintToLog(ip) 132 if len(ip) <= 0: 133 break 134 if len(re.findall(r'(?<!\d)\d{1,3}\.\d{1,3}\.\d{1,3}(?=\.\d)', ip[0])) <= 0: 135 break 136 gate = str(re.findall(r'(?<!\d)\d{1,3}\.\d{1,3}\.\d{1,3}(?=\.\d)', ip[0])[0]) + ".1" 137 PrintToLog(gate) 138 ifconfig="ifconfig wlan0 {}".format(ip[0]) 139 EnterShellCmd(ifconfig) 140 routeconfig="./data/l2tool/busybox route add default gw {} dev wlan0".format(gate) 141 EnterShellCmd(routeconfig) 142 break 143 PrintToLog("try {}".format(cnt)) 144 cnt -= 1 145 time.sleep(5) 146 147if __name__ == "__main__": 148 parser = argparse.ArgumentParser(description='manual to this script') 149 parser.add_argument('--config', type=str, default = './app_capture_screen_test_config.json') 150 parser.add_argument('--test_num', type=str, default = '1/1') 151 parser.add_argument('--tools_path', type=str, default = 'D:\\DeviceTestTools\\screenshot\\') 152 parser.add_argument('--anwser_path', type=str, default = 'D:\\DeviceTestTools\\screenshot\\resource') 153 parser.add_argument('--save_path', type=str, default = 'D:\\DeviceTestTools\\screenshot') 154 parser.add_argument('--device_num', type=str, default = 'null') 155 parser.add_argument('--pr_url', type=str, default = 'https://gitee.com/openharmony/applications_sample_wifi_iot/') 156 args = parser.parse_args() 157 158 if args.device_num == 'null': 159 result = EnterCmd("hdc_std list targets", 1, 0) 160 print(result) 161 args.device_num = result.split()[0] 162 163 with open(args.config) as f: 164 all_app = json.load(f) 165 166 cmp_status = 0 167 global_pos = all_app[0] 168 169 #rmlock 170 rebootcnt = 2 171 while rebootcnt: 172 rebootcnt -= 1 173 EnterCmd("hdc_std list targets", 1) 174 EnterShellCmd("mkdir -p /data/screen_test/train_set") 175 SendFileToDev(os.path.normpath(os.path.join(args.tools_path, "resource/printscreen")), "/data/screen_test/") 176 EnterShellCmd("chmod 777 /data/screen_test/printscreen") 177 rmlockcnt = 5 178 while rmlockcnt: 179 EnterShellCmd("uinput -T -m 425 1000 425 400;power-shell wakeup;uinput -T -m 425 400 425 1000;\ 180 power-shell setmode 602;uinput -T -m 425 1000 425 400;", 1) 181 rmlockcnt -= 1 182 183 EnterShellCmd("hilog -w stop", 1) 184 EnterShellCmd("cd /data/log/hilog && tar -cf system_start_log_{}.tar *".format(args.device_num), 1) 185 GetFileFromDev("/data/log/hilog/system_start_log_{}.tar".format(args.device_num), args.save_path) 186 #print(os.path.normpath(os.path.join(args.anwser_path, "launcher.pngraw"))) 187 SendFileToDev(os.path.normpath(os.path.join(args.anwser_path, "launcher.pngraw")),\ 188 "/data/screen_test/train_set") 189 EnterShellCmd("/data/screen_test/printscreen -f /data/screen_test/launcher_{}.png".format(args.device_num), 1) 190 GetFileFromDev("/data/screen_test/launcher_{}.pngraw".format(args.device_num), args.save_path) 191 GetFileFromDev("/data/screen_test/launcher_{}.png".format(args.device_num), args.save_path) 192 connection_judgment() 193 cmp_launcher = "cmp -l /data/screen_test/launcher_{}.pngraw\ 194 /data/screen_test/train_set/launcher.pngraw | wc -l".format(args.device_num) 195 p = EnterShellCmd(cmp_launcher, 1) 196 num = re.findall(r'[-+]?\d+', p) 197 PrintToLog(num) 198 if type(num) == list and len(num) > 0 and int(num[0]) < 184320 and\ 199 p.find('No such file or directory', 0, len(p)) == -1: 200 PrintToLog("remove lock is ok!\n\n") 201 break 202 elif rebootcnt >= 1: 203 PrintToLog("remove lock failed, reboot and try!!!\n\n") 204 EnterShellCmd("rm -rf /data/*;reboot") 205 for i in range(5): 206 EnterCmd("hdc_std list targets", 10) 207 else: 208 PrintToLog("ERROR: remove lock failed\n\n") 209 PrintToLog("SmokeTest find some fatal problems!") 210 PrintToLog("End of check, test failed!") 211 SysExit() 212 213 PrintToLog("\n\n########## First check key processes start ##############") 214 lose_process = [] 215 process_pid = {} 216 with open(os.path.normpath(os.path.join(args.tools_path, "resource/process.txt")), "r+") as f: 217 text = f.read() 218 two_check_process_list = text.split('#####')[1].split()[0:-1] 219 other_process_list = text.split('#####')[2].split() 220 #for pname in two_check_process_list + other_process_list: 221 for pname in two_check_process_list: 222 pids = EnterCmd("hdc_std -t {} shell pidof {}".format(args.device_num, pname), 0, 1) 223 try: 224 pidlist = pids.split() 225 int(pidlist[0]) 226 for pid in pidlist: 227 int(pid) 228 process_pid[pname] = pidlist 229 except: 230 lose_process.append(pname) 231 all_p = EnterShellCmd("ps -elf") 232 for pname in other_process_list: 233 findp = all_p.find(pname, 0, len(all_p)) 234 if findp == -1: 235 lose_process.append(pname) 236 237 if lose_process: 238 PrintToLog("\n\nERROR: %s, These processes are not exist!!!\n" % lose_process) 239 PrintToLog("SmokeTest find some fatal problems!") 240 PrintToLog("End of check, test failed!") 241 SysExit() 242 else: 243 PrintToLog("First processes check is ok\n") 244 245 try: 246 args.test_num.index('/') 247 idx_total = args.test_num.split('/') 248 if len(idx_total) != 2: 249 PrintToLog("test_num is invaild !!!") 250 PrintToLog("SmokeTest find some key problems!") 251 PrintToLog("End of check, test failed!") 252 sys.exit(98) 253 elif idx_total[1] == '1': 254 idx_list = list(range(1, len(all_app))) 255 else: 256 idx_list = global_pos['DEVICE_{}'.format(idx_total[0])] 257 except ValueError as e: 258 PrintToLog(e) 259 idx_list = list(map(eval, args.test_num.split())) 260 PrintToLog(idx_list) 261 262 fail_idx_list = [] 263 fail_name_list = [] 264 smoke_first_failed = '' 265 for idx in idx_list: 266 single_app = all_app[idx] 267 sys.stdout.flush() 268 call_app_cmd = single_app['entry'] 269 capture_screen_cmd = "/data/screen_test/printscreen -f /data/screen_test/{}_{}" 270 cmp_cmd = "cmp -l /data/screen_test/{}_{} /data/screen_test/train_set/{} | wc -l" 271 PrintToLog("\n\n########## case {} : {} test start ##############".format(idx, single_app['app_name'])) 272 with open(os.path.join(args.save_path, 'shot_test_{}.bat'.format(args.device_num)),\ 273 mode='a', encoding='utf-8') as cmd_file: 274 cmd_file.write("\n\n::::::case {} --- {} test start \n".format(idx, single_app['app_name'])) 275 cmd_file.close() 276 testcnt = 3 277 while testcnt: 278 testok = 0 279 checkok = 1 280 if testcnt != 3: 281 PrintToLog(">>>>>>>>>>>>>>>>>>>>>>>Try again:\n") 282 with open(os.path.join(args.save_path, 'shot_test_{}.bat'.format(args.device_num)),\ 283 mode='a', encoding='utf-8') as cmd_file: 284 cmd_file.write("\n::::::Last failed, Try again \n") 285 cmd_file.close() 286 EnterShellCmd("rm /data/log/hilog/*;hilog -r;hilog -w start -l 400000000 -m none", 1) 287 if single_app['entry'] != "": 288 EnterShellCmd(call_app_cmd, 5) 289 PrintToLog(single_app['all_actions']) 290 raw_pic_name = '' 291 pic_name = '' 292 for single_action in single_app['all_actions']: 293 #shot_cmd is stable, different to other cmd,so handle it specialy 294 if type(single_action[1]) == str and single_action[1] == 'shot_cmd': 295 if len(single_action) == 3: 296 pic_name = "{}{}".format(single_action[2], ".png") 297 raw_pic_name = single_action[2] + ".pngraw" 298 else: 299 pic_name = "{}{}".format(single_app['app_name'], ".png") 300 raw_pic_name = single_app['app_name'] + ".pngraw" 301 EnterShellCmd("rm /data/screen_test/{}_{}*".format(4 - testcnt, pic_name), 1) 302 EnterShellCmd(capture_screen_cmd.format(4 - testcnt, pic_name), 1) 303 GetFileFromDev("/data/screen_test/{}_{}".format(4 - testcnt, pic_name), args.save_path) 304 next_cmd = "" 305 #cmp_cmd-level is stable, different to other cmd,so handle it specialy 306 elif type(single_action[1]) == str and single_action[1] == 'cmp_cmd-level': 307 next_cmd = "" 308 sys.stdout.flush() 309 EnterShellCmd("rm /data/train_set/{}".format(raw_pic_name), 1) 310 SendFileToDev(os.path.normpath(os.path.join(args.anwser_path, raw_pic_name)),\ 311 "/data/screen_test/train_set") 312 new_cmp_cmd = cmp_cmd.format(4 - testcnt, raw_pic_name, raw_pic_name) 313 if len(single_action) == 3: 314 tolerance = single_action[2] 315 else: 316 tolerance = global_pos['cmp_cmd-level'][1] 317 p = EnterShellCmd(new_cmp_cmd, single_action[0]) 318 #no_such = re.findall(r'No such file or directory', p) 319 #PrintToLog(no_such) 320 num = re.findall(r'[-+]?\d+', p) 321 PrintToLog(num) 322 if type(num) == list and len(num) > 0 and int(num[0]) < tolerance and\ 323 p.find('No such file or directory', 0, len(p)) == -1: 324 if testok == 0: 325 testok = 1 326 PrintToLog("{} screenshot check is ok!\n\n".format(raw_pic_name)) 327 else: 328 testok = -1 329 PrintToLog("{} screenshot check is abnarmal!\n\n".format(raw_pic_name)) 330 sys.stdout.flush() 331 if testok == 1 or testcnt == 1 or smoke_first_failed != '': 332 old_name = os.path.normpath(os.path.join(args.save_path, "{}_{}".format(4 - testcnt, pic_name))) 333 GetFileFromDev("/data/screen_test/{}_{}".format(4 - testcnt, raw_pic_name), args.save_path) 334 os.system("rename {} {}".format(old_name, pic_name)) 335 os.system("rename {}raw {}raw".format(old_name, pic_name)) 336 raw_pic_name = '' 337 elif type(single_action[1]) == str and single_action[1] == 'install_hap': 338 next_cmd = "" 339 if len(single_action) == 3: 340 EnterCmd("hdc_std -t {} install \"{}\"".format(args.device_num,\ 341 os.path.normpath(os.path.join(args.tools_path, single_action[2])))) 342 elif type(single_action[1]) == str and single_action[1] == 'get_file_from_dev': 343 next_cmd = "" 344 if len(single_action) == 3: 345 EnterCmd("hdc_std -t {} file recv \"{}\" \"{}\"".format(args.device_num,\ 346 single_action[2], os.path.normpath(args.save_path))) 347 elif type(single_action[1]) == str and single_action[1] == 'send_file_to_dev': 348 next_cmd = "" 349 if len(single_action) == 4: 350 EnterCmd("hdc_std -t {} file send \"{}\" \"{}\"".format(args.device_num,\ 351 os.path.normpath(os.path.join(args.tools_path, single_action[2])), single_action[3])) 352 elif type(single_action[1]) == str and single_action[1] == 'connect_wifi': 353 next_cmd = "" 354 ConnectToWifi(args.tools_path) 355 elif type(single_action[1]) == str and single_action[1] == 'process_check': 356 next_cmd = "" 357 if len(single_action) == 3: 358 p = EnterShellCmd("ps -elf", single_action[0]) 359 result = "".join(p) 360 findsome = result.find(single_action[2], 0, len(result)) 361 if findsome != -1: 362 checkok = 1 363 PrintToLog("\"{}\" check execut result is ok, find\ 364 process \"{}\"!\n".format(single_action[1], single_action[2])) 365 else: 366 checkok = -1 367 PrintToLog("\"{}\" check execut result is not ok, not find\ 368 process \"{}\"!\n".format(single_action[1], single_action[2])) 369 sys.stdout.flush() 370 #process_crash_check 371 elif type(single_action[1]) == str and single_action[1] == 'process_crash_check': 372 next_cmd = "" 373 if len(single_action) == 3: 374 p = EnterShellCmd("cd /data/log/faultlog/temp && grep \"Process name\" -rnw ./",\ 375 single_action[0]) 376 result = "".join(p) 377 findsome = result.find(single_action[2], 0, len(result)) 378 if findsome != -1: 379 testok = -1 380 PrintToLog("\"{}\" ERROR:find fatal crash \"{}\"!\n".format(single_action[1],\ 381 single_action[2])) 382 PrintToLog("SmokeTest find some fatal problems!") 383 PrintToLog("End of check, test failed!") 384 SysExit() 385 else: 386 testok = 1 387 PrintToLog("\"{}\" check execut result is ok, not find fatal\ 388 crash \"{}\"!\n".format(single_action[1], single_action[2])) 389 sys.stdout.flush() 390 #other cmd handle 391 elif type(single_action[1]) == str: 392 if single_action[1] not in single_app.keys(): 393 target_ = global_pos[single_action[1]] 394 else: 395 target_ = single_app[single_action[1]] 396 #this cmd is real cmd,and have a except answer 397 if type(target_[0]) == str: 398 next_cmd = "" 399 p = EnterShellCmd(target_[0], single_action[0]) 400 result = "".join(p) 401 if len(target_) > 1: 402 findsome = result.find(target_[1], 0, len(result)) 403 if findsome != -1: 404 testok = 1 405 PrintToLog("\"{}\" check execut result is ok, find \"{}\"!\n".format(target_[0],\ 406 target_[1])) 407 else: 408 testok = -1 409 PrintToLog("\"{}\" check execut result is not ok, not find \"{}\"!\n".format(target_[0],\ 410 target_[1])) 411 sys.stdout.flush() 412 #this cmd only is a name of x,y postion, to get x,y an click it 413 else: 414 next_cmd = "uinput -M -m {} {} -c 0".format(target_[0], target_[1]) 415 #uinput x,y postion, to click it 416 else: 417 next_cmd = "uinput -M -m {} {} -c 0".format(single_action[1], single_action[2]) 418 EnterShellCmd(next_cmd, single_action[0]) 419 420 if testok == 1 and checkok == 1: 421 PrintToLog("testcase {}, {} is ok!\n\n".format(idx, single_app['app_name'])) 422 testcnt = 0 423 elif testok == 1 and checkok == -1: 424 if testcnt == 1: 425 fail_idx_list.append(idx) 426 fail_name_list.append(single_app['app_name']) 427 smoke_first_failed = single_app['app_name'] 428 PrintToLog("ERROR:testcase {}, {} is failed!\n\n".format(idx, single_app['app_name'])) 429 testcnt -= 1 430 elif testok == -1 and smoke_first_failed == '': 431 #PrintToLog("ERROR:testcase {}, {} is failed!\n\n".format(idx, single_app['app_name'])) 432 if testcnt == 1: 433 fail_idx_list.append(idx) 434 fail_name_list.append(single_app['app_name']) 435 smoke_first_failed = single_app['app_name'] 436 PrintToLog("ERROR:testcase {}, {} is failed!\n\n".format(idx, single_app['app_name'])) 437 testcnt -= 1 438 elif testok == -1 and smoke_first_failed != '': 439 fail_idx_list.append(idx) 440 fail_name_list.append(single_app['app_name']) 441 PrintToLog("ERROR:testcase {}, {} is failed!\n\n".format(idx, single_app['app_name'])) 442 testcnt = 0 443 else: 444 testcnt = 0 445 EnterShellCmd("hilog -w stop", 1) 446 connection_judgment() 447 if smoke_first_failed == 'launcher': 448 break 449 450 #key processes second check, and cmp to first check 451 PrintToLog("\n\n########## Second check key processes start ##############") 452 second_check_lose_process = [] 453 #for pname in two_check_process_list + other_process_list: 454 for pname in two_check_process_list: 455 pids = EnterCmd("hdc_std -t {} shell pidof {}".format(args.device_num, pname), 0, 1) 456 try: 457 pidlist = pids.split() 458 if process_pid[pname] != pidlist: 459 if pname in two_check_process_list: 460 PrintToLog("ERROR: pid of %s is different the first check" % pname) 461 PrintToLog("SmokeTest find some fatal problems!") 462 PrintToLog("End of check, test failed!") 463 SysExit() 464 else: 465 PrintToLog("WARNNING: pid of %s is different the first check" % pname) 466 elif len(pidlist) != 1: 467 if pname in two_check_process_list: 468 PrintToLog("ERROR: pid of %s is not only one" % pname) 469 PrintToLog("SmokeTest find some fatal problems!") 470 PrintToLog("End of check, test failed!") 471 SysExit() 472 else: 473 PrintToLog("WARNNING: pid of %s is not only one" % pname) 474 except: 475 second_check_lose_process.append(pname) 476 477 if second_check_lose_process: 478 PrintToLog("ERROR: pid of %s is not exist" % pname) 479 PrintToLog("SmokeTest find some fatal problems!") 480 PrintToLog("End of check, test failed!") 481 SysExit() 482 else: 483 PrintToLog("Second processes check is ok\n") 484 485 EnterShellCmd("cd /data/log/faultlog/temp && tar -cf after_test_crash_log_{}.tar cppcrash*".format(args.device_num)) 486 GetFileFromDev("/data/log/faultlog/temp/after_test_crash_log_{}.tar".format(args.device_num),\ 487 os.path.normpath(args.save_path)) 488 EnterShellCmd("cd /data/log/faultlog/temp && find . -name cppcrash*", 2) 489 EnterShellCmd("cd /data/log/faultlog/temp && grep \"Process name\" -rnw ./", 2) 490 491 fail_str_list = [str(x) for x in fail_idx_list] 492 reboot_test_num = " ".join(fail_str_list) 493 print(fail_str_list) 494 if len(fail_idx_list) != 0: 495 with open(os.path.normpath(os.path.join(args.tools_path, "reboot.txt")), mode='a+') as f: 496 f.seek(0) 497 reboot_result = f.read() 498 f.close() 499 if len(reboot_result) < 1 and rebootcnt >= 1: 500 os.system("mkdir {}\\reboot".format(args.save_path)) 501 with open(os.path.normpath(os.path.join(args.tools_path, "reboot.txt")), mode='w') as f: 502 f.write("reboot") 503 f.close() 504 PrintToLog("ERROR: name {}, index {}, these testcase is failed, reboot and try!!".format(fail_name_list,\ 505 fail_idx_list)) 506 EnterShellCmd("rm -rf /data/*;reboot") 507 reboot_result_list = EnterCmd("hdc_std list targets", 2) 508 number = 0 509 while args.device_num not in reboot_result_list and number < 15: 510 reboot_result_list = EnterCmd("hdc_std list targets", 2) 511 number += 1 512 EnterShellCmd("rm /data/log/hilog/*;hilog -r;hilog -w start -l 400000000 -m none", 1) 513 py_cmd = os.system("python {}\\resource\\capturescreentest.py --config\ 514 {}\\resource\\app_capture_screen_test_config.json --anwser_path {} --save_path {}\\reboot\ 515 --tools_path {} --device_num {} --test_num \"{}\"".format(args.tools_path, args.tools_path,\ 516 args.anwser_path, args.save_path, args.tools_path, args.device_num, reboot_test_num)) 517 if py_cmd == 0: 518 sys.exit(0) 519 elif py_cmd == 98: 520 sys.exit(98) 521 elif py_cmd == 99: 522 sys.exit(99) 523 else: 524 sys.exit(101) 525 else: 526 PrintToLog("ERROR: name {}, index {}, these testcase is failed".format(fail_name_list, fail_idx_list)) 527 PrintToLog("SmokeTest find some key problems!") 528 PrintToLog("End of check, test failed!") 529 sys.exit(98) 530 else: 531 PrintToLog("All testcase is ok") 532 PrintToLog("End of check, test succeeded!") 533 sys.exit(0)