From a1e6ce9ccce5efccda6409e4d399b72d074a359a Mon Sep 17 00:00:00 2001 From: lnlan Date: Thu, 26 May 2022 01:53:08 +0000 Subject: [PATCH] =?UTF-8?q?fixed=20afde89d=20from=20https://gitee.com/lnla?= =?UTF-8?q?n/applications=5Fsample=5Fwifi=5Fiot/pulls/73=20=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E6=A3=80=E6=9F=A5=E7=94=A8=E4=BE=8B=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=88=B0=E5=86=92=E7=83=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lnlan Change-Id: I8bd5c62f344df08329489388b0c71f38d9b53340 --- screenshot/resource/capturescreentest.py | 90 ++++++++++++++++++++---- screenshot/resource/process.txt | 11 +-- 2 files changed, 84 insertions(+), 17 deletions(-) diff --git a/screenshot/resource/capturescreentest.py b/screenshot/resource/capturescreentest.py index 5f034fe..a972232 100644 --- a/screenshot/resource/capturescreentest.py +++ b/screenshot/resource/capturescreentest.py @@ -84,7 +84,7 @@ def GetFileFromDev(src, dst): cmd = "hdc_std -t {} file recv \"{}\" \"{}\"".format(args.device_num, src, dst) return EnterCmd(cmd, 1, 1) -def connect_to_wifi(tools_path): +def ConnectToWifi(tools_path): EnterShellCmd("mkdir /data/l2tool", 1) SendFileToDev(os.path.normpath(os.path.join(tools_path, "l2tool/busybox")), "/data/l2tool/") SendFileToDev(os.path.normpath(os.path.join(tools_path, "l2tool/dhcpc.sh")), "/data/l2tool/") @@ -139,10 +139,7 @@ if __name__ == "__main__": with open(args.config) as f: all_app = json.load(f) - with open(os.path.join(args.save_path, 'shot_test_{}.bat'.format(args.device_num)), mode='w', encoding='utf-8') as cmd_file: - cmd_file.close() - with open(os.path.join(args.save_path, 'shot_test_{}.log'.format(args.device_num)), mode='w', encoding='utf-8') as log_file: - log_file.close() + cmp_status = 0 global_pos = all_app[0] @@ -180,17 +177,45 @@ if __name__ == "__main__": os.system("hdc_std -t {} shell reboot".format(args.device_num)) for i in range(5): EnterCmd("hdc_std list targets", 10) - else: PrintToLog("remove lock failed\n\n") break + + PrintToLog("\n\n########## First check key processes start ##############") + lose_process = [] + process_pid = {} + with open(os.path.normpath(os.path.join(args.tools_path, "resource/process.txt")), "r+") as f: + text = f.read() + two_check_process_list = text.split('#####')[1].split()[0:-1] + other_process_list = text.split('#####')[2].split() + for pname in two_check_process_list + other_process_list: + #print(pname) + pids = EnterCmd("hdc_std shell pidof {}".format(pname), 0, 1) + #print(int(pid.split()[0])) + try: + pidlist = pids.split() + int(pidlist[0]) + for pid in pidlist: + int(pid) + process_pid[pname] = pidlist + except: + lose_process.append(pname) + if lose_process: + PrintToLog("\n\nERROR: %s, These processes are not exist!!!\n" % lose_process) + PrintToLog("SmokeTest find some fatal problems!") + PrintToLog("End of check, test failed!") + sys.exit(99) + else: + PrintToLog("First processes check is ok\n") + try: args.test_num.index('/') idx_total = args.test_num.split('/') if len(idx_total) != 2: PrintToLog("test_num is invaild !!!") + PrintToLog("SmokeTest find some key problems!") PrintToLog("End of check, test failed!") - sys.exit(1) + sys.exit(98) elif idx_total[1] == '1': idx_list = list(range(1, len(all_app))) else: @@ -198,7 +223,6 @@ if __name__ == "__main__": except ValueError as e: PrintToLog(e) idx_list = list(map(eval, args.test_num.split())) - PrintToLog(idx_list) fail_idx_list = [] @@ -244,8 +268,9 @@ if __name__ == "__main__": PrintToLog(no_such) if type(no_such) == list and len(no_such) > 0 and no_such[0] == 'No such file or directory': PrintToLog("ERROR: {} screenshot failed!\n\n".format(raw_pic_name)) + PrintToLog("SmokeTest find some key problems!") PrintToLog("End of check, test failed!") - sys.exit(255) + sys.exit(98) next_cmd = "" #cmp_cmd-level is stable, different to other cmd,so handle it specialy elif type(single_action[1]) == str and single_action[1] == 'cmp_cmd-level': @@ -287,7 +312,7 @@ if __name__ == "__main__": EnterCmd("hdc_std -t {} file send \"{}\" \"{}\"".format(args.device_num, os.path.normpath(os.path.join(args.tools_path, single_action[2])), single_action[3])) elif type(single_action[1]) == str and single_action[1] == 'connect_wifi': next_cmd = "" - connect_to_wifi(args.tools_path) + ConnectToWifi(args.tools_path) #other cmd handle elif type(single_action[1]) == str: if single_action[1] not in single_app.keys(): @@ -338,15 +363,54 @@ if __name__ == "__main__": if smoke_first_failed == 'launcher': break + #key processes second check, and cmp to first check + PrintToLog("\n\n########## Second check key processes start ##############") + second_check_lose_process = [] + for pname in two_check_process_list + other_process_list: + #print(pname) + pids = EnterCmd("hdc_std shell pidof {}".format(pname), 0, 1) + #print(int(pid.split()[0])) + try: + pidlist = pids.split() + if process_pid[pname] != pidlist: + if pname in two_check_process_list: + PrintToLog("ERROR: pid of %s is different the first check" % pname) + PrintToLog("SmokeTest find some fatal problems!") + PrintToLog("End of check, test failed!") + sys.exit(99) + else: + PrintToLog("WARNNING: pid of %s is different the first check" % pname) + elif len(pidlist) != 1: + if pname in two_check_process_list: + PrintToLog("ERROR: pid of %s is not only one" % pname) + PrintToLog("SmokeTest find some fatal problems!") + PrintToLog("End of check, test failed!") + sys.exit(99) + else: + PrintToLog("WARNNING: pid of %s is not only one" % pname) + except: + second_check_lose_process.append(pname) + + if second_check_lose_process: + PrintToLog("ERROR: pid of %s is not exist" % pname) + PrintToLog("SmokeTest find some fatal problems!") + PrintToLog("End of check, test failed!") + sys.exit(99) + else: + PrintToLog("Second processes check is ok\n") + EnterShellCmd("cd /data/log/faultlog/temp && tar -cf after_test_crash_log.tar cppcrash*") EnterCmd("hdc_std -t {} file recv /data/log/faultlog/temp/after_test_crash_log.tar {}".format(args.device_num, os.path.normpath(args.save_path))) if len(fail_idx_list) != 0: PrintToLog("ERROR: name {}, index {}, these testcase is failed".format(fail_name_list, fail_idx_list)) if fail_name_list.count('launcher') or fail_name_list.count('settings_keyboard'): - PrintToLog("End of check, Some Key APPs(launcher or setting) failed!") + PrintToLog("SmokeTest find some fatal problems!") + PrintToLog("End of check, test failed!") + sys.exit(99) + PrintToLog("SmokeTest find some key problems!") PrintToLog("End of check, test failed!") + sys.exit(98) else: PrintToLog("All testcase is ok") PrintToLog("End of check, test succeeded!") - sys.stdout.flush() - sys.exit(len(fail_idx_list)) \ No newline at end of file + sys.exit(0) \ No newline at end of file diff --git a/screenshot/resource/process.txt b/screenshot/resource/process.txt index 5ed23e4..6f840dd 100644 --- a/screenshot/resource/process.txt +++ b/screenshot/resource/process.txt @@ -1,3 +1,8 @@ +####First_check_at_begin__Second_check_at_end__Two_results_must_be_same##### +com.ohos.launcher +render_service + +####only_check_these_processes_are_exitst##### hdf_devmgr param_watcher storage_manager @@ -33,7 +38,6 @@ inputmethod_ser ui_service fms_service distributedfile -distributedfile netmanager battery_stats dslm_service @@ -46,7 +50,6 @@ hiview telephony usb_service camera_service -render_service thermal foundation accesstoken_ser @@ -65,5 +68,5 @@ blue_host wifi_hal_service com.ohos.systemui device_usage_st -com.ohos.launcher -power_host \ No newline at end of file +power_host + -- Gitee