From 9950c44652dfb09dfa70b4bad29c3a2de1687a96 Mon Sep 17 00:00:00 2001 From: lnlan Date: Wed, 27 Apr 2022 11:38:36 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=8C=E5=96=84python=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lnlan Change-Id: I956bdb4501de0791dfd0c5223706a3534b326313 --- .../app_capture_screen_test_config.json | 37 +-- screenshot/rk_master/capturescreentest.py | 241 +++++++++++++----- 2 files changed, 178 insertions(+), 100 deletions(-) diff --git a/screenshot/rk_master/app_capture_screen_test_config.json b/screenshot/rk_master/app_capture_screen_test_config.json index 9c24f3c..da1bdbd 100644 --- a/screenshot/rk_master/app_capture_screen_test_config.json +++ b/screenshot/rk_master/app_capture_screen_test_config.json @@ -11,19 +11,13 @@ "cmp_cmd-level":["", 443200] }, { - "app_name": "lock", + "app_name": "launcher", "entry": "", - "hdc_list_cmd":["hdc_std list targets"], "rm_lock_cmd":["hdc_std shell uinput -T -m 350 900 350 300"], - "reboot_cmd":["hdc_std shell reboot"], - "rm_data_cmd":["hdc_std shell rm -rf data/*"], "powermode_cmd":["hdc_std shell \"power-shell setmode 602\""], - "mk_anwser_dir":["hdc_std shell mkdir -p /data/screen_test/train_set"], - "send_tool":["hdc_std file send D:\\DeviceTestTools\\printscreen\\printscreen /data/screen_test/"], - "chmod_tool":["hdc_std shell chmod 777 /data/screen_test/printscreen"], "all_actions": [ [2, "rm_lock_cmd"], [2, "powermode_cmd"], [2, "rm_lock_cmd"], [2, "powermode_cmd"], - [2, "rm_lock_cmd"], [2, "rm_lock_cmd"] + [2, "rm_lock_cmd"], [2, "rm_lock_cmd"], [2, "shot_cmd"], [2, "cmp_cmd-level"] ] }, { @@ -42,12 +36,7 @@ ] }, { - "app_name": "launcher", - "entry": "", - "all_actions": [[2, "shot_cmd"], [2, "cmp_cmd-level"]] - }, - { - "app_name": "settings", + "app_name": "settings_keyboard", "entry": "aa start -a com.ohos.settings.MainAbility -b com.ohos.settings", "all_actions": [ [3, "shot_cmd", "settings"], [3, "cmp_cmd-level"], [3, 400, 120], [3, 400, 120], [20, 400, 80], [3, 400, 80], @@ -57,31 +46,13 @@ { "app_name": "photos", "entry": "aa start -a com.ohos.photos.MainAbility -b com.ohos.photos", - "all_actions": [[2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], [2, "recent-x-y"], [2, "recent_del-x-y"], [2, "recent-x-y"], [2, "recent_del-x-y"]] - }, - { - "app_name": "photos", - "entry": "aa start -a com.ohos.photos.MainAbility -b com.ohos.photos", - "all_actions": [[2, "shot_cmd"], [2, "recent-x-y"], [2, "recent_del-x-y"], [2, "cmp_cmd-level"], [2, "recent-x-y"], [2, "recent_del-x-y"]] + "all_actions": [[2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], [2, "shot_cmd"], [2, "recent-x-y"], [2, "recent_del-x-y"], [2, "cmp_cmd-level"], [2, "recent-x-y"], [2, "recent_del-x-y"]] }, { "app_name": "distributedcalc", "entry": "aa start -a com.example.distributedcalc.default -b com.example.distributedcalc", "all_actions": [[2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], [2, "shot_cmd"], [2, "recent-x-y"], [2, "recent_del-x-y"], [2, "cmp_cmd-level", 3686400], [2, "recent-x-y"], [2, "recent_del-x-y"]] }, - { - "app_name": "camera", - "entry": "aa start -a com.ohos.camera.MainAbility -b com.ohos.camera", - "all_actions": [ - [2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], - [2, "recent-x-y"], [2, "recent_del-x-y"], [2, "recent-x-y"], [2, "recent_del-x-y"] - ] - }, - { - "app_name": "camera", - "entry": "aa start -a com.ohos.camera.MainAbility -b com.ohos.camera", - "all_actions": [[2, "shot_cmd"], [2, "recent-x-y"], [2, "recent_del-x-y"], [2, "recent-x-y"], [2, "recent_del-x-y"], [2, "cmp_cmd-level", 3686400]] - }, { "app_name": "note", "entry": "aa start -a com.ohos.note.MainAbility -b com.ohos.note", diff --git a/screenshot/rk_master/capturescreentest.py b/screenshot/rk_master/capturescreentest.py index 6672b8a..238965a 100644 --- a/screenshot/rk_master/capturescreentest.py +++ b/screenshot/rk_master/capturescreentest.py @@ -18,36 +18,108 @@ import os import time import argparse import re +import subprocess + +def MyPrint(str): + print(str) + with open(os.path.join(args.save_path, 'shot_test.log'), mode='a', encoding='utf-8') as log_file: + console = sys.stdout + sys.stdout = log_file + print(str) + sys.stdout = console + log_file.close() def EnterCmd(mycmd, waittime = 0, printresult = 1): if mycmd == "": return + with open(os.path.join(args.save_path, 'shot_test.bat'), mode='a', encoding='utf-8') as cmd_file: + cmd_file.write(mycmd + '\n') + cmd_file.close() with os.popen(mycmd) as p: - result = p.readlines() + result = ''.join(p.readlines()) if printresult == 1: - print(result) + MyPrint(mycmd) + MyPrint(result) sys.stdout.flush() if waittime != 0: time.sleep(waittime) + with open(os.path.join(args.save_path, 'shot_test.bat'), mode='a', encoding='utf-8') as cmd_file: + cmd_file.write("ping -n {} 127.0.0.1>null\n".format(waittime)) + cmd_file.close() return result +def connect_to_wifi(tools_path): + EnterCmd("hdc_std shell mkdir /data/l2tool") + EnterCmd("hdc_std file send {}\\l2tool\\busybox /data/l2tool".format(tools_path)) + EnterCmd("hdc_std file send {}\\l2tool\\dhcpc.sh /data/l2tool".format(tools_path)) + EnterCmd("hdc_std file send {}\\l2tool\\entry-debug-rich-signed.hap /data/l2tool".format(tools_path)) + EnterCmd("hdc_std file send {}\\l2tool\\hostapd.conf /data/l2tool".format(tools_path)) + EnterCmd("hdc_std file send {}\\l2tool\\iperf /data/l2tool".format(tools_path)) + EnterCmd("hdc_std file send {}\\l2tool\\p2p_supplicant.conf /data/l2tool".format(tools_path)) + EnterCmd("hdc_std file send {}\\l2tool\\p2p_supplicant1.conf /data/l2tool".format(tools_path)) + EnterCmd("hdc_std file send {}\\l2tool\\udhcpd.conf /data/l2tool".format(tools_path)) + EnterCmd("hdc_std file send {}\\l2tool\\wpa_supplicant.conf /data/l2tool".format(tools_path)) + EnterCmd("hdc_std shell wpa_supplicant -B -d -i wlan0 -c /data/l2tool/wpa_supplicant.conf") + EnterCmd("hdc_std shell chmod 777 ./data/l2tool/busybox") + time.sleep(3) + cnt = 3 + while 1: + try: + p = subprocess.check_output("hdc_std shell ./data/l2tool/busybox udhcpc -i wlan0 -s /data/l2tool/dhcpc.sh", timeout=12) + MyPrint("hdc_std shell ./data/l2tool/busybox udhcpc -i wlan0 -s /data/l2tool/dhcpc.sh") + MyPrint(p.decode(encoding="utf-8")) + with open(os.path.join(args.save_path, 'shot_test.bat'), mode='a', encoding='utf-8') as cmd_file: + cmd_file.write('hdc_std shell ./data/l2tool/busybox udhcpc -i wlan0 -s /data/l2tool/dhcpc.sh' + '\n') + cmd_file.close() + ret_code = 0; + except subprocess.TimeoutExpired as time_e: + MyPrint(time_e) + ret_code = 1 + if ret_code == 0: + break; + if cnt == 1: + return False + MyPrint("try {}".format(cnt)) + cnt -= 1 + time.sleep(15) + ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", p.decode(encoding="utf-8")) + MyPrint(ip) + gate = str(re.findall(r'(? 0 and int(num[0]) < tolerance: - print("{} screenshot check is ok!\n\n".format(raw_pic_name)) - else: - print("ERROR:{} screenshot check is abnarmal!\n\n".format(raw_pic_name)) - cmp_status = cmp_status + 1 - sys.stdout.flush() - #other cmd handle - elif type(single_action[1]) == str: - if single_action[1] not in single_app.keys(): - target_ = global_pos[single_action[1]] - else: - target_ = single_app[single_action[1]] - #this cmd is real cmd,and have a except answer - if type(target_[0]) == str: + EnterCmd(call_app_cmd, 5) + MyPrint(single_app['all_actions']) + testcnt = 2 + while testcnt: + testok = 0 + if testcnt == 1: + MyPrint(">>>>>>>>>>>>>>>>>>>>>>>Try again:\n") + for single_action in single_app['all_actions']: + #shot_cmd is stable, different to other cmd,so handle it specialy + if type(single_action[1]) == str and single_action[1] == 'shot_cmd': + if len(single_action) == 3: + pic_name = single_action[2] + ".png" + raw_pic_name = single_action[2] + ".pngraw" + else: + pic_name = single_app['app_name'] + ".png" + raw_pic_name = single_app['app_name'] + ".pngraw" + EnterCmd(capture_screen_cmd.format(pic_name), 1) + EnterCmd(recv_file_cmd.format(pic_name, args.save_path), 1) + EnterCmd(recv_file_cmd.format(raw_pic_name, args.save_path), 1) next_cmd = "" - p = EnterCmd(target_[0], single_action[0]) - result = "".join(p) - if len(target_) > 1: - findsome = result.find(target_[1], 0, len(result)) - if findsome != -1: - print("\"{}\" execut result success!\n\n".format(target_[0])) - else: - print("ERROR:\"{}\" execut result failed!\n\n".format(target_[0])) - cmp_status = cmp_status + 1 - sys.stdout.flush() - #this cmd only is a name of x,y postion, to get x,y an click it + #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': + next_cmd = "" + MyPrint(send_file_cmd.format(os.path.join(args.anwser_path, raw_pic_name), "/data/screen_test/train_set")) + sys.stdout.flush() + EnterCmd(send_file_cmd.format(os.path.join(args.anwser_path, raw_pic_name), "/data/screen_test/train_set")) + new_cmp_cmd = cmp_cmd.format(raw_pic_name, raw_pic_name) + if len(single_action) == 3: + tolerance = single_action[2] + else: + tolerance = global_pos['cmp_cmd-level'][1] + p = EnterCmd(new_cmp_cmd, single_action[0]) + num = re.findall(r'[-+]?\d+', p[0]) + if type(num) == list and len(num) > 0 and int(num[0]) < tolerance: + testok = 1 + MyPrint("{} screenshot check is ok!\n\n".format(raw_pic_name)) + else: + testok = -1 + MyPrint("{} screenshot check is abnarmal!\n\n".format(raw_pic_name)) + sys.stdout.flush() + elif type(single_action[1]) == str and single_action[1] == 'recv_log-file': + next_cmd = "" + if len(single_action) == 3: + logfilepath = single_action[2] + next_cmd = "hdc_std file recv {} {}".format(logfilepath, args.save_path) + #other cmd handle + elif type(single_action[1]) == str: + if single_action[1] not in single_app.keys(): + target_ = global_pos[single_action[1]] + else: + target_ = single_app[single_action[1]] + #this cmd is real cmd,and have a except answer + if type(target_[0]) == str: + next_cmd = "" + p = EnterCmd(target_[0], single_action[0]) + result = "".join(p) + if len(target_) > 1: + findsome = result.find(target_[1], 0, len(result)) + if findsome != -1: + testok = 1 + MyPrint("\"{}\" execut result is ok!\n".format(target_[0])) + else: + testok = -1 + MyPrint("\"{}\" execut result is abnarmal!\n".format(target_[0])) + sys.stdout.flush() + #this cmd only is a name of x,y postion, to get x,y an click it + else: + next_cmd = "hdc_std shell uinput -M -m {} {} -c 0".format(target_[0], target_[1]) + #uinput x,y postion, to click it else: - next_cmd = "hdc_std shell uinput -M -m {} {} -c 0".format(target_[0], target_[1]) - #uinput x,y postion, to click it + next_cmd = "hdc_std shell uinput -M -m {} {} -c 0".format(single_action[1], single_action[2]) + EnterCmd(next_cmd, single_action[0]) + if testok == 1: + MyPrint("testcase {}, {} is ok!\n\n".format(idx, single_app['app_name'])) + testcnt = 0 + elif testok == -1: + MyPrint("ERROR:testcase {}, {} is failed!\n\n".format(idx, single_app['app_name'])) + cmp_status = cmp_status + 1 + testcnt -= 1 else: - next_cmd = "hdc_std shell uinput -M -m {} {} -c 0".format(single_action[1], single_action[2]) - EnterCmd(next_cmd, single_action[0]) + testcnt = 0 + + if connect_to_wifi(args.tools_path) == False: + MyPrint("ERROR:wifi connect error, test failed!!!") + cmp_status += 1 if cmp_status != 0: - print("ERROR:screenshot check is abnarmal {}".format(cmp_status)) - print("End of check, test failed!") + MyPrint("ERROR:test is failed {}".format(cmp_status)) + MyPrint("End of check, test failed!") else: - print("screenshot check is ok {}".format(cmp_status)) - print("End of check, test succeeded!") + MyPrint("test is ok {}".format(cmp_status)) + MyPrint("End of check, test succeeded!") sys.stdout.flush() sys.exit(cmp_status) \ No newline at end of file -- Gitee From 5713d19852ecdd7a0ed74293170baae16b23d158 Mon Sep 17 00:00:00 2001 From: lnlan Date: Thu, 28 Apr 2022 13:15:55 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id0812306e5bc0cb9be291cda690e93333ac9a950 Signed-off-by: lnlan --- .../app_capture_screen_test_config.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/screenshot/rk_master/app_capture_screen_test_config.json b/screenshot/rk_master/app_capture_screen_test_config.json index da1bdbd..285bc18 100644 --- a/screenshot/rk_master/app_capture_screen_test_config.json +++ b/screenshot/rk_master/app_capture_screen_test_config.json @@ -53,6 +53,22 @@ "entry": "aa start -a com.example.distributedcalc.default -b com.example.distributedcalc", "all_actions": [[2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], [2, "shot_cmd"], [2, "recent-x-y"], [2, "recent_del-x-y"], [2, "cmp_cmd-level", 3686400], [2, "recent-x-y"], [2, "recent_del-x-y"]] }, + { + "app_name": "vedio_test", + "entry": "", + "install_vedio_test":["hdc_std install D:\\DeviceTestTools\\screenshot\\vediotest\\ActsVideoPlayerJsTest.hap"], + "mk_test_dir":["hdc_std shell mkdir -p /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile"], + "send_vedio":["hdc_std file send D:\\DeviceTestTools\\screenshot\\vediotest\\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/"], + "start_hilog":["hdc_std shell \"hilog -r && hilog -w start -f vedio_log -l 400000000 -m none\""], + "start_test":["hdc_std shell aa start -a ohos.acts.multimedia.video.videoplayer.MainAbility -b ohos.acts.multimedia.video.videoplayer"], + "stop_hilog":["hdc_std shell hilog -w stop"], + "check_result":["hdc_std shell \"cd /data/log/hilog && grep -nr 'total cases'\"", "failure 0,error 0,pass 1"], + "compress_log":["hdc_std shell \"cd /data/log/hilog && tar -cf vedio_log.tar vedio_*\""], + "clear_log":["hdc_std shell rm /data/log/hilog/*"], + "all_actions": [ + [2, "install_vedio_test"], [2, "mk_test_dir"], [2, "remount"], [2, "send_vedio"], [2, "clear_log"], [0, "start_hilog"], [15, "start_test"], [2, "stop_hilog"], [2, "check_result"], [2, "compress_log"], [2, "recv_log-file", "/data/log/hilog/vedio_log.tar"], [2, "clear_log"], [2, "recent-x-y"], [2, "recent_del-x-y"], [2, "recent-x-y"], [2, "recent_del-x-y"] + ] + }, { "app_name": "note", "entry": "aa start -a com.ohos.note.MainAbility -b com.ohos.note", -- Gitee