diff --git a/screenshot32/DistributedTest/config/user_config.xml b/screenshot32/DistributedTest/config/user_config.xml new file mode 100644 index 0000000000000000000000000000000000000000..defc72ddf38608a2003f1b303d05ee044914815b --- /dev/null +++ b/screenshot32/DistributedTest/config/user_config.xml @@ -0,0 +1,66 @@ + + + + + + 7001005458323933328a017ce1b13800;7001005458323933328a258f3d043900 + + + + + cmd + 115200 + 8 + 1 + 20 + + + + deploy + 115200 + + + + + + cmd + 115200 + 8 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + DEBUG + \ No newline at end of file diff --git a/screenshot32/DistributedTest/main.py b/screenshot32/DistributedTest/main.py new file mode 100644 index 0000000000000000000000000000000000000000..3eeb592cd30fb4c3149f055927178de3442f9346 --- /dev/null +++ b/screenshot32/DistributedTest/main.py @@ -0,0 +1,9 @@ +import sys +from xdevice.__main__ import main_process +from testcases.set_sn import get_devices_sn + +if __name__ == '__main__': + get_devices_sn() + argv = "{} {} {}".format(sys.argv[1], sys.argv[2], sys.argv[3]) + print(">>>>>>>:{}".format(argv)) + main_process(argv) \ No newline at end of file diff --git a/screenshot32/DistributedTest/testcases/DistributedTest.json b/screenshot32/DistributedTest/testcases/DistributedTest.json new file mode 100644 index 0000000000000000000000000000000000000000..8188504822d6d044c229c768aa35df981ecad1bb --- /dev/null +++ b/screenshot32/DistributedTest/testcases/DistributedTest.json @@ -0,0 +1,17 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + }, + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["DistributedTest.py"] + } +} \ No newline at end of file diff --git a/screenshot32/DistributedTest/testcases/DistributedTest.py b/screenshot32/DistributedTest/testcases/DistributedTest.py new file mode 100644 index 0000000000000000000000000000000000000000..28965687baf07c78bbdbde91b8cd2a88c6fe3eda --- /dev/null +++ b/screenshot32/DistributedTest/testcases/DistributedTest.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +import time +from devicetest.core.test_case import TestCase +from devicetest.aw.OpenHarmony import CommonOH +import threading + + +class DistributedTest(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + # 设备组网 + "sub_distributed_smoke_testcase_0100", + # pin码连接 + "sub_distributed_smoke_testcase_0200", + # 结果校验 + "sub_distributed_smoke_testcase_0300" + ] + TestCase.__init__(self, self.TAG, controllers) + + def setup(self): + print("预置工作:初始化设备开始...........................") + print(self.devices[0].device_id) + print(self.devices[1].device_id) + + def sub_distributed_smoke_testcase_0100(self): + t1 = threading.Thread(target=self.net_connect1) + t2 = threading.Thread(target=self.net_connect2) + t1.start() + t2.start() + t1.join() + t2.join() + + def sub_distributed_smoke_testcase_0200(self): + CommonOH.startAbility(self.Phone1, "ohos.samples.distributedcalc.MainAbility", "ohos.samples.distributedcalc") + time.sleep(2) + # 授权 + CommonOH.click(self.Phone1, 500, 706) + CommonOH.click(self.Phone1, 500, 706) + CommonOH.touchByType(self.Phone1, "image", index=1) + CommonOH.touchByText(self.Phone1, "取消") + CommonOH.touchByType(self.Phone1, "image", index=1) + CommonOH.touchByType(self.Phone1, "input", index=1) + time.sleep(1) + #确定 + CommonOH.click(self.Phone2, 500, 620) + CommonOH.click(self.Phone2, 500, 620) + code = CommonOH.getTextByCondition(self.Phone2, "请在设备端输入链接码进行验证", relativePath="AFTER") + CommonOH.inputTextByType(self.Phone1, "input", code) + # 确定 + CommonOH.click(self.Phone1, 500, 690) + CommonOH.click(self.Phone1, 500, 690) + + def sub_distributed_smoke_testcase_0300(self): + # 切入后台,结束进程 + CommonOH.click(self.Phone1, 512, 1246) + CommonOH.click(self.Phone1, 360, 1168) + # 重启计算器应用 + CommonOH.startAbility(self.Phone1, "ohos.samples.distributedcalc.MainAbility", "ohos.samples.distributedcalc") + time.sleep(2) + # 拉起远端设备 + CommonOH.touchByType(self.Phone1, "image", index=1) + CommonOH.touchByType(self.Phone1, "input", index=1) + # 设备二授权 + time.sleep(2) + CommonOH.click(self.Phone2, 500, 706) + CommonOH.click(self.Phone2, 500, 706) + # 校验远端计算器是否被拉起 + CommonOH.checkIfTextExist(self.Phone2, "计算器", pattern="EQUALS", expect=True) + + def net_connect1(self): + # 点亮屏幕 + CommonOH.wake(self.Phone1) + # 设置不息屏 + CommonOH.hdc_std(self.Phone1, 'shell "power-shell setmode 602"') + # 设置 phone1 ip + CommonOH.hdc_std(self.Phone1, "shell ifconfig eth0 192.168.0.1") + + def net_connect2(self): + # 点亮屏幕 + CommonOH.wake(self.Phone2) + # 设置不息屏 + CommonOH.hdc_std(self.Phone2, 'shell "power-shell setmode 602"') + # 设置 phone1 ip + CommonOH.hdc_std(self.Phone2, "shell ifconfig eth0 192.168.0.2") + + def teardown(self): + # 切入后台,结束进程 + CommonOH.click(self.Phone1, 512, 1246) + CommonOH.click(self.Phone2, 512, 1246) + CommonOH.click(self.Phone1, 360, 1168) + CommonOH.click(self.Phone2, 360, 1168) diff --git a/screenshot32/DistributedTest/testcases/set_sn.py b/screenshot32/DistributedTest/testcases/set_sn.py new file mode 100644 index 0000000000000000000000000000000000000000..6ccbba0df5ffa912b6010907567300855f88445b --- /dev/null +++ b/screenshot32/DistributedTest/testcases/set_sn.py @@ -0,0 +1,21 @@ +import encodings +import os +import re +from xml.dom.minidom import parse + +def get_devices_sn(): + cmd_sn = os.popen("hdc_std list targets").read() + device_sn = re.findall('[\w+]{32}', cmd_sn) + re.findall('[\w+]{16}', cmd_sn) + dom_tree = parse('config\\user_config.xml') + collection = dom_tree.documentElement + sn1 = collection.getElementsByTagName('sn')[0] + if len(device_sn[0]) == len(device_sn[1]): + sn1.childNodes[0].data = "{};{}".format(device_sn[0], device_sn[1]) + else: + sn1.childNodes[0].data = device_sn[0] + with open('config\\user_config.xml', 'w', encoding='utf-8') as f: + dom_tree.writexml(f, encoding='utf-8') + f.close() + +if __name__ == '__main__': + get_devices_sn() \ No newline at end of file diff --git a/screenshot32/distributecalc_test/get_pin.hap b/screenshot32/distributecalc_test/get_pin.hap deleted file mode 100644 index 428c808050274752f3e2f736ead13b9f64eb5275..0000000000000000000000000000000000000000 Binary files a/screenshot32/distributecalc_test/get_pin.hap and /dev/null differ diff --git a/screenshot32/distributecalc_test/input_pin.hap b/screenshot32/distributecalc_test/input_pin.hap deleted file mode 100644 index 62c16731194796027fce20f7bfca567b445c9701..0000000000000000000000000000000000000000 Binary files a/screenshot32/distributecalc_test/input_pin.hap and /dev/null differ diff --git a/screenshot32/resource/app_capture_screen_test_config.json b/screenshot32/resource/app_capture_screen_test_config.json index 361d8fbbb5bc024d1c036086d138ba3f62437d40..bad214113f89db53e2a108e1ed2edddb994b06b3 100644 --- a/screenshot32/resource/app_capture_screen_test_config.json +++ b/screenshot32/resource/app_capture_screen_test_config.json @@ -1,7 +1,7 @@ [ { - "DEVICE_1":[2, 3, 4, 5, 8, 10, 11], - "DEVICE_2":[1, 6, 7, 9, 12, 13], + "DEVICE_1":[2, 3, 4, 6, 8, 10, 11], + "DEVICE_2":[1, 5, 7, 9, 12, 13], "return-x-y":[210, 1240], "recent-x-y":[515, 1240], "home-x-y":[360, 1240], @@ -94,14 +94,12 @@ "open_camera_log":["rm /data/log/hilog/* && hilog -b X;hilog -b D -T CAMERA;hilog -r"], "start_camera":["aa start -a com.ohos.camera.MainAbility -b com.ohos.camera"], "recover_log":["cd data/log/hilog/;hilog -x > camera_log.txt;hilog -b D"], - "cp_db": ["cp /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/rdb/media_library.db /data/video_photo.db"], + "cp_db": ["cp /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/rdb/media_library.db /data/camera_photo.db"], "all_actions": [ [1, "open_camera_log"], [5, "start_camera"], [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, "permisson_ok-x-y"], - [2, "take_photos-x-y"], [2, "take_photos-x-y"], [2, "convert_to_video-x-y"], [5, "take_photos-x-y"], [2, "stop_video-x-y"], [5, "take_photos-x-y"], [2, "stop_video-x-y"], [5, "convert_to_photos-x-y"], + [2, "take_photos-x-y"], [2, "take_photos-x-y"], [2, "convert_to_video-x-y"], [5, "take_photos-x-y"], [2, "stop_video-x-y"], [5, "take_photos-x-y"], [2, "stop_video-x-y"], [6, "convert_to_photos-x-y"], [2, "permisson_ok-x-y"], [2, "permisson_ok-x-y"], [1, "recover_log"], [1, "check_result"], [1, "shot_cmd", "camera_to_photos"], [1, "cmp_cmd-level", 921600], [2, "home-x-y"], [2, "recent-x-y"], - [2, "recent_del-x-y"], [5, "start_camera"], [2, "take_photos-x-y"], [2, "take_photos-x-y"], [2, "convert_to_video-x-y"], [5, "take_photos-x-y"], [2, "stop_video-x-y"], [5, "take_photos-x-y"], - [2, "stop_video-x-y"], [2, "home-x-y"], [2, "recent-x-y"], [2, "recent_del-x-y"], [1, "cp_db"], [1, "get_file_from_dev", "/data/video_photo.db"], [2, "photo_and_video_check"], [1, "compress_log"], - [1, "get_file_from_dev", "/data/log/hilog/camera_log.tar"] + [2, "recent_del-x-y"], [1, "cp_db"], [1, "get_file_from_dev", "/data/camera_photo.db"], [2, "camera_photo_check"], [1, "compress_log"], [1, "get_file_from_dev", "/data/log/hilog/camera_log.tar"] ] }, { diff --git a/screenshot32/resource/capturescreentest.py b/screenshot32/resource/capturescreentest.py index 011c9052fdaf1babe71d09865fd757ef4fad0509..dd306b142a8a7970ec8f875f256de17101e1646e 100644 --- a/screenshot32/resource/capturescreentest.py +++ b/screenshot32/resource/capturescreentest.py @@ -107,14 +107,14 @@ def ImageCheck(str, testnum=1): cursor_image.execute("""select * from files where mime_type = "image/*" """) except: PrintToLog("SmokeTest:: error: media_library.db cannot be found, please check media library path") - SysExit() + return -1 if testnum == 2: try: PrintToLog("SmokeTest:: select * from files where mime_type = video/mp4") cursor_video.execute("""select * from files where mime_type = "video/mp4" """) except: PrintToLog("SmokeTest:: error: media_library.db cannot be found, please check media library path") - SysExit() + return -1 PrintToLog("SmokeTest:: media library is ok") image_result = cursor_image.fetchone() video_result = cursor_video.fetchone() @@ -387,10 +387,10 @@ if __name__ == "__main__": elif type(single_action[1]) == str and single_action[1] == 'connect_wifi': next_cmd = "" ConnectToWifi(args.tools_path) - elif type(single_action[1]) == str and single_action[1] == 'photo_and_video_check': + elif type(single_action[1]) == str and single_action[1] == 'camera_photo_check': next_cmd = "" - if ImageCheck("{}\\video_photo.db".format(os.path.normpath(args.save_path)),\ - 2) == 1 and testok == 1: + if ImageCheck("{}\\camera_photo.db".format(os.path.normpath(args.save_path)),\ + 1) == 1 and testok == 1: testok = 1 else: testok = -1 @@ -531,8 +531,10 @@ if __name__ == "__main__": PrintToLog("SmokeTest:: second processes check is ok") pr_analysis = args.pr_url - if "applications_sample_wifi_iot" or "softbus" in pr_analysis: + PrintToLog("SmokeTest:: get pr: {}".format(args.pr_url)) + if "applications_sample_wifi_iot" in pr_analysis or "softbus" in pr_analysis: #distributed smoketest + EnterShellCmd("param set persist.ace.testmode.enabled 1", 1) PrintToLog("SmokeTest:: close selinux") EnterShellCmd("mount -o rw,remount /", 1) EnterShellCmd("sed -i 's/enforcing/permissive/g' /system/etc/selinux/config", 1) @@ -546,59 +548,49 @@ if __name__ == "__main__": EnterShellCmd("uinput -T -m 425 1000 425 400;power-shell wakeup;\ uinput -T -m 425 400 425 1000;power-shell setmode 602;uinput -T -m 425 1000 425 400;", 1) unlockcnt -= 1 - EnterCmd("hdc_std -t {} target mount".format(args.device_num), 1) - EnterShellCmd("mount -o rw,remount /", 1) - EnterShellCmd("hilog -r", 1) - EnterShellCmd("param set persist.ace.testmode.enabled 1", 1) - if args.test_num == "2/2": - EnterShellCmd("aa force-stop com.example.rkinputpin", 1) - EnterShellCmd("bm uninstall -n com.example.rkinputpin", 1) - EnterCmd("hdc_std -t {} app install -r {}\\distributecalc_test\\input_pin.hap".format(args.device_num,\ - args.tools_path), 1) + if args.test_num == "1/2": EnterShellCmd("ifconfig eth0 192.168.0.1", 1) ping_result = EnterShellCmd("ping 192.168.0.2 -i 1 -c 2", 3) ping_cnt = 0 - while "2 packets transmitted, 2 received" not in ping_result and ping_cnt < 15: - ping_result = EnterShellCmd("ping 192.168.0.2 -i 1 -c 2", 3) + while "2 packets transmitted, 2 received" not in ping_result and ping_cnt < 25: + ping_result = EnterShellCmd("ping 192.168.0.2 -i 1 -c 2", 5) ping_cnt += 1 - EnterShellCmd("hilog -Q pidoff;hilog -G 512M;hilog -w start -l 400000000 -m none") - PrintToLog("SmokeTest:: start distributed smoke test") - os.system("hdc_std -t {} shell aa test -b com.example.rkinputpin -p com.example.rkinputpin -s unittest\ - OpenHarmonyTestRunner -s class inputPINTestDemo -s timeout 3000000".format(args.device_num)) - EnterShellCmd("cd data/log/hilog/;hilog -x > hilog_inputpin.txt", 1) - EnterCmd("hdc_std -t {} file recv \"/data/log/hilog/hilog_inputpin.txt\" \"{}\"".format(args.device_num,\ - os.path.normpath(args.save_path)), 1) - elif args.test_num == "1/2": - EnterShellCmd("aa force-stop com.example.rkgetpin", 1) - EnterShellCmd("bm uninstall -n com.example.rkgetpin", 1) - EnterCmd("hdc_std -t {} app install -r {}\\distributecalc_test\\get_pin.hap".format(args.device_num,\ - args.tools_path), 1) + PrintToLog("SmokeTest:: ##### case 14 : distributed test start #####") + elif args.test_num == "2/2": EnterShellCmd("ifconfig eth0 192.168.0.2", 1) ping_result = EnterShellCmd("ping 192.168.0.1 -i 1 -c 2", 3) ping_cnt = 0 - while "2 packets transmitted, 2 received" not in ping_result and ping_cnt < 60: - ping_result = EnterShellCmd("ping 192.168.0.1 -i 1 -c 2", 3) + while "2 packets transmitted, 2 received" not in ping_result and ping_cnt < 25: + ping_result = EnterShellCmd("ping 192.168.0.1 -i 1 -c 2", 5) ping_cnt += 1 - EnterShellCmd("hilog -Q pidoff;hilog -G 512M;hilog -w start -l 400000000 -m none") - PrintToLog("SmokeTest:: start distributed smoke test") - os.system("hdc_std -t {} shell aa test -b com.example.rkgetpin -p com.example.rkgetpin -s unittest\ - OpenHarmonyTestRunner -s class getPINTestDemo -s timeout 3000000".format(args.device_num)) - EnterShellCmd("cd data/log/hilog/;hilog -x > hilog_getpin.txt", 1) - EnterCmd("hdc_std -t {} file recv \"/data/log/hilog/hilog_getpin.txt\" \"{}\"".format(args.device_num,\ - os.path.normpath(args.save_path)), 1) - getpin_result = 0 - with open(os.path.normpath(os.path.join(args.save_path, "hilog_getpin.txt")), mode='r', encoding='gbk',\ - errors='ignore') as fs: - getpin_lines = fs.readlines() - for content in getpin_lines: - if "rkgetpin:: distributedcalc test is ok!!!" in content: - getpin_result = 1 - break - fs.close() - if getpin_result == 1: - PrintToLog("SmokeTest:: distributed smoke test is ok!!!") + PrintToLog("SmokeTest:: ##### case 14 : distributed test start #####") + execute_path = os.path.normpath(os.path.join(args.tools_path, "DistributedTest")) + PrintToLog("SmokeTest:: execute_path {}".format(execute_path)) + os.system("cd {} && python main.py run -l DistributedTest".format(execute_path)) + report_path = os.path.normpath(os.path.join(args.tools_path, "DistributedTest\\reports")) + PrintToLog("SmokeTest:: report_path {}".format(report_path)) + task_file = "task_log.log" + file_name = '' + distributed_result = 0 + for root, dirs, files in os.walk(report_path): + if task_file in files: + file_name = os.path.join(root, task_file) + PrintToLog("SmokeTest:: file_name {}".format(file_name)) + try: + with open(file_name, mode='r', encoding='utf-8', errors='ignore') as fs: + report_lines = fs.readlines() + for content in report_lines: + if "total: 1, passed: 1" in content: + distributed_result = 1 + break + fs.close() + except Exception as reason: + PrintToLog("SmokeTest:: task_log.log is not exist!") + PrintToLog("SmokeTest:: error:testcase 14, distributed is failed!") + if distributed_result == 1: + PrintToLog("SmokeTest:: testcase 14, distributed is ok!") else: - PrintToLog("SmokeTest:: error: distributedcalc test failed") + PrintToLog("SmokeTest:: error:testcase 14, distributed is failed!") EnterShellCmd("cd /data/log/faultlog/temp && tar -cf after_test_crash_log_{}.tar cppcrash*".format(args.device_num)) GetFileFromDev("/data/log/faultlog/temp/after_test_crash_log_{}.tar".format(args.device_num), \ @@ -629,7 +621,7 @@ if __name__ == "__main__": EnterShellCmd("rm -rf /data/* && reboot") reboot_result_list = EnterCmd("hdc_std list targets", 2) number = 0 - while "7001005458323933328a" not in reboot_result_list and number < 15: + while args.device_num not in reboot_result_list and number < 15: reboot_result_list = EnterCmd("hdc_std list targets", 2) number += 1 EnterShellCmd("rm /data/log/hilog/*;hilog -r;hilog -w start -l 400000000 -m none", 1)