def __init__(self, host_path): self.host_path = host_path multimedia_setting = MultiMediaSetting( CameraCommon().DEFAULT_CONFIG_FILE) self.iq_check_file_path = multimedia_setting.download_file_to_host( "Multimedia_Camera/apk/IQCheck") os.chmod(self.iq_check_file_path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH) self.__execute_command_with_popen("chmod 777 %s" % self.iq_check_file_path) self.zxing_jar_file_path = multimedia_setting.download_file_to_host( "Multimedia_Camera/apk/zxing-analyzer.jar") self.home_path = os.environ['HOME'] self.temp_dir = os.path.join(self.home_path, "tmp/checkiq_temp_dir/") if not os.path.exists(self.temp_dir): os.makedirs(self.temp_dir) self.check_IQ = CheckIQ(self.iq_check_file_path, self.temp_dir) self.num_list = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def __init__(self, toolPath="", tempDir=""): if toolPath != "": self.tool = toolPath #The folder where "IQCheck" exists else: from testlib.multimedia.multimedia_setting import MultiMediaSetting from testlib.camera.CameraCommon import CameraCommon multimedia_setting = MultiMediaSetting( CameraCommon().DEFAULT_CONFIG_FILE) localPath = CameraCommon().getTmpDir() binName = "IQCheck" remoteToolBinary = multimedia_setting.download_file_to_host( "Multimedia_Camera/apk/" + binName) self.tool = localPath + "/" + binName print self.tool if os.path.exists(self.tool) == False: os.system("cp " + remoteToolBinary + " " + self.tool) os.system("chmod 777 " + self.tool) self.tempDir = tempDir
def checkZoomEffect(self, file1, file2): from testlib.multimedia.multimedia_setting import MultiMediaSetting from testlib.camera.CameraCommon import CameraCommon localPath = CameraCommon().getTmpDir() multimedia_setting = MultiMediaSetting( CameraCommon().DEFAULT_CONFIG_FILE) remotejarFile = multimedia_setting.download_file_to_host( "Multimedia_Camera/apk/sikuli-api-ex2.jar") print remotejarFile jarFile = localPath + "/sikuli-api-ex2.jar" print jarFile if os.path.exists(jarFile) == False: os.system("cp " + remotejarFile + " " + jarFile) os.system("chmod 777 " + jarFile) os.environ['CLASSPATH'] = jarFile from jnius import autoclass Sikuli = autoclass('com.intel.sikuli.image.analysis.Sikuli') self.sikuli = Sikuli() img = cv2.imread(file1) # print img.shape samll_mage = cv2.imread(file2) # print samll_mage.shape if (samll_mage.shape[1] > img.shape[1]) or (samll_mage.shape[0] > img.shape[0]): print "size of pic1 should >= size of pic2" exit(-1) ratio1 = self.getZoomRatio(file1) ratio = self.getZoomRatio(file2) print ratio1, ratio def changeFormat(t_str): from fractions import Fraction if "/" in t_str: t_str = Fraction(t_str) return float(t_str) ratio1 = changeFormat(ratio1) ratio = changeFormat(ratio) print ratio1, ratio if ratio1 > ratio: print "zoom ratio of pic2 should >= zoom ratio of pic2" exit(-1) rat = ratio if rat > 1: l = file1.split("/") pic_name = l[len(l) - 1].split(".")[0] picPath1 = os.path.dirname( os.path.abspath(file1)) + os.sep + pic_name + "_ori.jpg" cv2.imwrite(picPath1, img) file1 = picPath1 l = file2.split("/") pic_name = l[len(l) - 1].split(".")[0] picPath2 = os.path.dirname( os.path.abspath(file2)) + os.sep + pic_name + "_zoom.jpg" samll_mage = cv2.imread(file2) newx, newy = int(samll_mage.shape[1] / rat), int( samll_mage.shape[0] / rat) #new size (w,h) newimage = cv2.resize(samll_mage, (newx, newy)) cv2.imwrite(picPath2, newimage) file2 = picPath2 ret = self.sikuli.sikuliFind(file1, file2, "image", "0.8") print ret ret_l = ret.split(" ") if ret_l[0] == "true": print "Zoom effect is correct" x = int(ret_l[1].split("=")[1]) y = int(ret_l[2].split("=")[1]) w = int(ret_l[3].split("=")[1]) h = int(ret_l[4].split("=")[1]) # a = np.array((img.shape[1]/2,img.shape[0]/2)) # b = np.array((x+w/2,y+h/2)) # dist_a_b = dist(a,b) # shape[0]: height/ shape[1]: width print self.getAngle(np.array((x + w / 2, y + h / 2)), img.shape[1], img.shape[0]) # print "---w=%d, h=%d, distance=%d"%(img.shape[1], img.shape[0], dist_a_b) # print "%d, %d, %d, %d"%(x,y,w,h) if rat > 1: cv2.rectangle(img, (x, y), (x + w, y + h), (127, 255, 0), 2) cv2.imwrite( os.path.dirname(os.path.abspath(file2)) + os.sep + pic_name + "_frame.jpg", img) return True else: print "Zoom effect is not correct" return False
class WidevineTest(UIATestBase): """ @summary: Test Widevine """ config = TestConfig() def setUp(self): """ @summary: set up @return: None """ super(WidevineTest, self).setUp() self.d = g_common_obj.get_device() self._test_name = __name__ self.video_button_widget_dict = { "play": "android:id/pause", "pause": "android:id/pause", "volume_up": "volume_up", "volume_down": "volume_down", "back": "back" } print "[Setup]: %s" % self._test_name def tearDown(self): """ @summary: tear tearDown @return: None """ super(WidevineTest, self).tearDown() print "[Teardown]: %s" % self._test_name g_common_obj.stop_exp_handle() def appPrepare(self, model=1): self.cfg_file = os.path.join(os.environ.get('TEST_DATA_ROOT', ''), \ 'tests.tablet.mum_auto_drm.conf') self.cfg = self.config.read(self.cfg_file, self.case_name) self.multimedia_handle = MultiMediaHandle() self.multimedia_setting = MultiMediaSetting(self.cfg_file) self.multimedia_drm_helper = MultiMediaDRMHelper() self.multimedia_setting.install_apk( "widevine_apk") #install widevine apk self.widevine_package_name, self.widevine_activity_name = self.multimedia_setting.get_package_and_activity_name( "widevine_apk") if model == 1: # play local video mode self.dst_path = self.cfg.get("dst_path") self.clearResourcefolder() self.dst_path = self.multimedia_setting.push_file_new( self.cfg.get("src_path"), self.dst_path) #push video file to device elif model == 2: # play network video mode self.src_path = self.cfg.get("src_path") # g_common_obj.set_vertical_screen() g_common_obj.stop_app_am(self.widevine_package_name) g_common_obj.adb_cmd_capture_msg("input keyevent 82") #Unlock screen def disableVerityDUT(self): serial = self.d.server.adb.device_serial() result = os.popen("adb -s %s disable-verity" % serial).read() logger.debug("result=%s" % result) assert "version" not in result and "error" not in result, "Please update sdk version!" assert "fail" not in result and "error" not in result, "The DUT can't disable-verity, please reboot and check it" def remountDUT(self): serial = self.d.server.adb.device_serial() os.system("adb -s %s remount" % serial) time.sleep(3) result = os.popen("adb -s %s remount" % serial).read() logger.debug("result=%s" % result) assert "fail" not in result and "error" not in result, "The DUT can't remount, please reboot and check it" def getDeviceTypeMapCfg(self): if "device_type_map" not in dir(self): self.device_type_map_cfg = self.config.read( self.cfg_file, "device_type_map") return self.device_type_map_cfg def executeCommandWithPopen(self, cmd): logger.debug(cmd) # return subprocess.Popen(cmd, shell=True) return subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) def clearResourcefolder(self): g_common_obj.adb_cmd_capture_msg("rm -rf %s" % os.path.split(self.dst_path)[0]) def launchWidevineApp(self): SystemUI().unlock_screen() # g_common_obj.stop_app_am(self.widevine_package_name) g_common_obj.launch_app_am(self.widevine_package_name, self.widevine_activity_name) time.sleep(5) for _ in range(5): if self.d(textContains="Downloads").exists: return time.sleep(5) assert self.d( textContains="Downloads").exists, "launch Winevine App failed!" def findVideoExistInWidevineApp(self, video_name): logger.debug("findVideoExistInWidevineApp video_name=%s" % video_name) time.sleep(5) for _ in range(10): if self.d(textContains=video_name).exists: break self.d(text=">>").click() time.sleep(20) assert self.d(textContains=video_name ).exists, "Video not exist! video_name=%s" % video_name bounds = self.d(textContains=video_name).info["bounds"] x = bounds["left"] + (bounds["right"] - bounds["left"]) / 2 y = bounds["top"] - (bounds["bottom"] - bounds["top"]) / 2 self.d.click(x, y) def clear_edit_text_layout(self, layout): while layout.text != "": layout.clear_text() def setContentPage(self, path): self.d(text="Settings").click() time.sleep(2) edit_text_layout = self.d( className="android.widget.EditText", resourceId="com.widevine.demo:id/content_page") if edit_text_layout.text != path: self.clear_edit_text_layout(edit_text_layout) edit_text_layout.set_text(path) self.d.press.back() time.sleep(1) self.d(text="Update Button").click() self.d(text="Ok").click() def wait_boot_completed(self, timeout=1000): ''' wait Android boot_completed args: timeout -- optional timeout in second, default 1000s ''' count = 0 sleep_time = 5 while count < timeout: prop_val = adb.adb_cmd_capture_msg('getprop sys.boot_completed') if '1' in prop_val: print 'boot_completed' return count += sleep_time time.sleep(sleep_time) raise Exception('%ds timeout waiting for boot_completed' % timeout) def widevineVideoPlayBack(self): self.d(text="Downloads").click() time.sleep(5) dst_name = os.path.split(self.dst_path)[1] assert self.d( textContains=dst_name ).exists, "resource file not exist! file_name=%s" % dst_name self.d(className="android.widget.ImageView", index="0").click() time.sleep(5) self.d(text="Acquire Rights").click() time.sleep(3) acquire_rights_value = -1 for _ in range(3): widevine_value = self.getWidevineValue() logger.debug("widevine_value=%s" % widevine_value) if "acquireRights" in widevine_value and "Rights installed" in widevine_value: acquire_rights_value = self.getWidevineValue_acquireRights() logger.debug("acquire_rights_value=%s" % str(acquire_rights_value)) break time.sleep(3) assert "error" not in widevine_value and "fail" not in widevine_value, "error widevine_value!! widevine_value=%s" % widevine_value assert acquire_rights_value == 0, "error acquire_rights_value!!! acquire_rights_value=%d" % acquire_rights_value self.d(text="Play").click() def widevineStreamingVideoPlayBack(self): self.d(text="Streaming").click() time.sleep(5) video_index = self.findVideoExistInWidevineApp(self.src_path) self.d(className="android.widget.ImageView", index=video_index).click() time.sleep(5) self.d(text="Acquire Rights").click() time.sleep(3) acquire_rights_value = -1 for _ in range(10): widevine_value = self.getWidevineValue() logger.debug("widevine_value=%s" % widevine_value) if "acquireRights" in widevine_value and "Rights installed" in widevine_value: acquire_rights_value = self.getWidevineValue_acquireRights() logger.debug("acquire_rights_value=%s" % str(acquire_rights_value)) break time.sleep(3) assert "error" not in widevine_value and "fail" not in widevine_value, "error widevine_value!! widevine_value=%s" % widevine_value assert acquire_rights_value == 0, "error acquire_rights_value!!! acquire_rights_value=%d" % acquire_rights_value self.d(text="Play").click() def getWidevineValue(self): self.widevine_value_text = self.d( className="android.widget.TextView").text return self.widevine_value_text def get_acquire_rights_pattern(self): if "acquire_rights_pattern" not in dir(self): GET_ACQUIRERIGHTS_PATTERN = ".*acquireRights = (.*)\n.*" self.acquire_rights_pattern = re.compile(GET_ACQUIRERIGHTS_PATTERN) return self.acquire_rights_pattern def getWidevineValue_acquireRights(self): try: acquire_rights_pattern = self.get_acquire_rights_pattern() widevine_value = self.getWidevineValue() acquire_rights_value = acquire_rights_pattern.findall( widevine_value) acquire_rights_value = int(acquire_rights_value[0]) except Exception as e: logger.debug("widevine_value=%s" % widevine_value) logger.debug("acquire_rights_value=%s" % str(acquire_rights_value)) assert 0, e return acquire_rights_value def getPlatform(self): cmd = "adb shell getprop ro.board.platform" platform = os.popen(cmd).read() platform = platform.replace("\n", "", 1) return platform.strip() def getDeviceTypeMapNum(self): device_platform = self.getPlatform() device_platform = device_platform.lower() if "sofia_lte" in device_platform: num = 2 else: num = 1 # num = self.getDeviceTypeMapCfg().get(device_platform) return num def clickScreen(self): self.multimedia_setting.clickScreen() def click_widget(self, t_widget): try: t_widget.click() self.s_t_text = 0 except Exception as e: logger.debug("click_widget error:%s" % e) self.s_t_text = -2 assert 0, "click_widget error:%s" % e def get_widget(self, t_str): logger.debug("get_widget---t_str=%s" % t_str) assert t_str in self.video_button_widget_dict, "%s not in video_button_widget_dict!" % t_str t_resource_id = self.video_button_widget_dict[t_str] if t_resource_id == t_str: return t_resource_id else: return self.d(resourceId=t_resource_id) def widget_operation_with_thread(self, t_str, t_operation): self.s_t_text = -1 t_widget = self.get_widget(t_str) if t_operation == "click": thread.start_new_thread(self.click_widget, (t_widget, )) else: assert 0, "Error operation!" while self.s_t_text == -1: if not t_widget.exists: self.clickScreen() time.sleep(1) return self.s_t_text def click_button(self, t_str): logger.debug("click_button---t_str=%s" % t_str) t_widget = self.video_button_widget_dict[t_str] if t_str != t_widget: result = self.widget_operation_with_thread(t_str, "click") assert result == 0, "click failed! reselt=%d" % result else: getattr(self.d.press, t_widget)() def checkVideoPlayBackWithWidevine(self): self.launchWidevineApp() # launch widevine app self.widevineVideoPlayBack() # play video file time.sleep(10) assert not self.d( textContains="can't" ).exists, "video playback failed!" #check play status of video time.sleep(140) assert not self.d( textContains="can't" ).exists, "video playback failed!" #check play status of video def checkStreamingVideoPlayBackWithWidevine(self): self.launchWidevineApp() self.setContentPage(self.cfg.get("web_page")) self.widevineStreamingVideoPlayBack() time.sleep(10) assert not self.d( textContains="can't").exists, "video playback failed!" time.sleep(140) assert not self.d( textContains="can't").exists, "video playback failed!" def checkVideoPlayBackWithClickButton(self, click_list): self.launchWidevineApp() # launch widevine app self.widevineVideoPlayBack() # play video file time.sleep(10) assert not self.d( textContains="can't" ).exists, "video playback failed!" #check play status of video for t_str in click_list: if t_str == "sleep": time.sleep(5) else: self.click_button(t_str) time.sleep(2) time.sleep(60) assert not self.d( textContains="can't" ).exists, "video playback failed!" #check play status of video def winevine_main_test(self, sub_func_name="", model=1, *arg, **keywords): """ This test used to test WinevineApp App The test case spec is following: 1. Start record video 2. do sub_func() 3. Stop record video """ self.case_name = sys._getframe().f_back.f_code.co_name if sub_func_name == "": sub_func_name = "%s_sub_func" % self.case_name logger.debug("case_name=%s" % self.case_name) logger.debug("exoplayer_main_test---sub_func_name=%s" % sub_func_name) self.appPrepare(model) try: self.multimedia_drm_helper.startRecord( self.case_name) #start record logger.debug("Arbitrary parameter is %s" % str(arg)) logger.debug("keywords parameter is %s" % str(keywords)) getattr(self, sub_func_name)(*arg, **keywords) self.d.press.back() self.d.press.back() self.d.press.home() if model == 1: self.clearResourcefolder() time.sleep(1) self.multimedia_drm_helper.stopRecord() #stop record except Exception as e: self.multimedia_drm_helper.stopRecord() assert 0, e assert 0, "Playback complete! Please check video!" logger.debug("Case %s is pass!" % self.case_name) def test_video_playback_with_check_S0I3(self): self.case_name = sys._getframe().f_back.f_code.co_name self.appPrepare() after_S0I3_str = self.multimedia_setting.getS0I3() self.launchWidevineApp() self.widevineVideoPlayBack() time.sleep(10) assert not self.d( textContains="can't").exists, "video playback failed!" self.d.press.power() logger.debug("Step: sleep 800s, please wait...") time.sleep(800) logger.debug("Step: sleep 800s, complete!") self.d.press.power() SystemUI().unlock_screen() self.d.press.back() self.d.press.home() before_S0I3_str = self.multimedia_setting.getS0I3() assert after_S0I3_str != before_S0I3_str, "after_S0I3_str=%s, before_S0I3_str=%s" % ( after_S0I3_str, before_S0I3_str) def checkVideoPlayBackWithWidevineWithReboot(self, t_time): self.case_name = sys._getframe().f_back.f_code.co_name self.appPrepare() self.launchWidevineApp() self.widevineVideoPlayBack() time.sleep(20) assert not self.d( textContains="can't").exists, "video playback failed!" for _ in range(t_time): adb.reboot_device() self.wait_boot_completed() time.sleep(20) self.launchWidevineApp() self.widevineVideoPlayBack() time.sleep(20) assert not self.d( textContains="can't").exists, "video playback failed!" def checkProvision(self): self.case_name = sys._getframe().f_back.f_code.co_name logger.debug("case_name=%s" % self.case_name) self.appPrepare(0) if "false" == self.cfg.get("test"): logger.debug("Case %s is skip auto test!" % self.case_name) return num = self.getDeviceTypeMapNum() if num == 1: g_common_obj.root_on_device() self.disableVerityDUT() adb.reboot_device() self.wait_boot_completed() g_common_obj.root_on_device() self.remountDUT() time.sleep(3) bin_src_path = self.getDeviceTypeMapCfg().get("%s_bin_src_path" % (num)) bin_dst_path = self.getDeviceTypeMapCfg().get("%s_bin_src_path" % (num)) bin_src_path = self.multimedia_setting.download_file_to_host( bin_src_path) bin_src_folder = os.path.split(bin_src_path)[0] bin_dst_filename = os.path.split(bin_dst_path)[1] unzip_cmd = self.getDeviceTypeMapCfg().get("unzip_command") self.executeCommandWithPopen(unzip_cmd % (bin_src_path, bin_src_folder)) bin_src_path = os.path.join(bin_src_folder, bin_dst_filename) bin_dst_path = self.multimedia_setting.push_file_to_dut( bin_src_path, bin_dst_path) tools_src_path = self.getDeviceTypeMapCfg().get("%s_tool_src_path" % (num)) tools_dst_path = self.getDeviceTypeMapCfg().get("%s_tool_dst_path" % (num)) tools_dst_path = self.multimedia_setting.push_file_new( tools_src_path, tools_dst_path) g_common_obj.adb_cmd_capture_msg("chmod 777 %s" % tools_dst_path) time.sleep(5) i = 1 while "%s_execute_command_%s" % (num, i) in self.getDeviceTypeMapCfg(): cmd = self.getDeviceTypeMapCfg().get("%s_execute_command_%s" % (num, i)) fdp = self.executeCommandWithPopen(cmd) time.sleep(3) stdout_log = fdp.stdout.read() assert "cannot" not in stdout_log and "error" not in stdout_log and "fail" not in stdout_log and "not found" not in stdout_log, "(%s) cmd error: %s" % ( cmd, stdout_log) i += 1 logger.debug("Case %s is pass!" % self.case_name) def testWVClassicPlayback_WVDemo_Local_720p(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_Local_1080p(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_Local_360(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_SD(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_Local_480p(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_HD_Local(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_WiFi_360p(self): self.winevine_main_test("checkStreamingVideoPlayBackWithWidevine", 2) def testWVClassic_WVDemo_WiFi_480P(self): self.winevine_main_test("checkStreamingVideoPlayBackWithWidevine", 2) def testWVClassic_WVDemo_WiFi_720p(self): self.winevine_main_test("checkStreamingVideoPlayBackWithWidevine", 2) def testWVClassic_WVDemo_WiFi_1080p(self): self.winevine_main_test("checkStreamingVideoPlayBackWithWidevine", 2) def testWVClassic_WVDemo_Menu_Interaction(self): self.winevine_main_test("checkVideoPlayBackWithClickButton", 1, ["volume_up"] * 4 + ["sleep"] + ["volume_down"] * 4) def testWVClassic_WVDemo_Volume_Adjustment_Paused(self): self.winevine_main_test("checkVideoPlayBackWithClickButton", 1, ["pause"] + ["volume_up"] * 10 + ["sleep"] + ["volume_down"] * 10 + ["play"] + ["volume_down"] * 10 + ["pause"]) def testWVClassic_Reboot_Multi_Times(self): self.checkVideoPlayBackWithWidevineWithReboot(20) def testWVClassic_Resume_S0i3(self): self.test_video_playback_with_check_S0I3() def testProvisionKeyBox_Reboot(self): self.checkProvision() def testWVClassic_Provision(self): self.checkProvision()
class MultiMediaScaleTestHelper: def __init__(self, host_path): self.logger = Logger.getlogger() self.host_path = host_path self.camera_helper = MultiMediaSwitchCameraHelper( skip_import_camera=True) self.target_folder = os.path.join(self.host_path, self.camera_helper.device, self.camera_helper.android_version) self.expect_folder = os.path.join(self.target_folder, "expect") self.actual_folder = os.path.join(self.target_folder, "actual") if not os.path.exists(self.expect_folder): os.makedirs(self.expect_folder) if not os.path.exists(self.actual_folder): os.makedirs(self.actual_folder) self.ffmpeg_cmd = "ffmpeg -i %s -ss 00:00.02 -y -q:v 2 -vframes 1 %s" self.movies_folder_device_path = "/sdcard/Movies/" self.scale_test_xml_value_dict = {1: 30, 2: 50, 3: 60} self.play_result = -1 self.get_cfg_file_helper = GetConfigFileHelper( "", "multimedia_scale_test_helper.conf") self.scale_test_cfg = self.get_cfg_file_helper.get_section("config") self.multimedia_setting = MultiMediaSetting( self.get_cfg_file_helper.cfg_file) self.generated_reference_library = int( self.scale_test_cfg.get("generated_reference_library")) self.reference_library_folder = self.scale_test_cfg.get( "reference_library_folder") self.reference_library_folder = os.path.join( self.reference_library_folder, self.camera_helper.device, self.camera_helper.android_version) self.xml_file_dst_path = self.scale_test_cfg.get("xml_file_dst_path") self.o_image_camera3_xml_file_dst_path = self.scale_test_cfg.get( "o_image_camera3_xml_file_dst_path") def __execute_command_with_popen(self, cmd, t_shell=False): self.logger.debug("__execute_command_with_popen cmd=%s" % cmd) if not t_shell: cmd = cmd.split() return subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=t_shell) def remount_device(self): if self.camera_helper.android_version == "o": from testlib.graphics.common import adb32 adb32.adb_disable_verity() else: from testlib.common.common import g_common_obj2 self.serial = g_common_obj2.getSerialNumber() os.system("adb -s %s root" % self.serial) os.system("adb -s %s root" % self.serial) os.system("adb -s %s disable-verity" % self.serial) os.system("adb -s %s reboot" % self.serial) time.sleep(60) os.system("adb -s %s root" % self.serial) time.sleep(30) os.system("adb -s %s root" % self.serial) result = 'remount succeeded' remount_result = os.popen("adb -s %s remount" % self.serial).read().strip() print "[Info] --- remount result is %s" % remount_result if result == remount_result: print "[Info] --- remount successfull" else: assert False, "[Info] --- remount fail" def backup_file(self, dst_path_string, backup_name_postfix="_backup"): dst_path = self.scale_test_cfg.get(dst_path_string) dst_path_root, dst_path_ext = os.path.splitext(dst_path) backup_dst_path = "%s%s%s" % (dst_path_root, backup_name_postfix, dst_path_ext) self.logger.debug("backup_file backup_dst_path=%s" % backup_dst_path) t_result = g_common_obj.adb_cmd_capture_msg("ls %s" % backup_dst_path) if backup_dst_path not in t_result: g_common_obj.adb_cmd_capture_msg("cp %s %s" % (dst_path, backup_dst_path)) t_result = g_common_obj.adb_cmd_capture_msg("ls %s" % backup_dst_path) assert backup_dst_path in t_result, "cp failed! t_result=%s" % t_result return (dst_path, backup_dst_path) def restore_file(self, dst_path_string, backup_name_postfix="_backup"): dst_path = self.scale_test_cfg.get(dst_path_string) dst_path_root, dst_path_ext = os.path.splitext(dst_path) backup_dst_path = "%s%s%s" % (dst_path_root, backup_name_postfix, dst_path_ext) t_result = g_common_obj.adb_cmd_capture_msg("ls %s" % backup_dst_path) if backup_dst_path in t_result: g_common_obj.adb_cmd_capture_msg("cp %s %s" % (backup_dst_path, dst_path)) t_result = g_common_obj.adb_cmd_capture_msg("ls %s" % dst_path) self.logger.debug("backup_file t_result=%s" % t_result) return True return False def replace_file(self, src_path_string, dst_path_string): src_path = self.scale_test_cfg.get(src_path_string) dst_path = self.scale_test_cfg.get(dst_path_string) g_common_obj.adb_cmd_capture_msg("rm -rf %s" % dst_path) t_result = g_common_obj.adb_cmd_capture_msg("ls %s" % dst_path) assert dst_path not in t_result, "rm failed! t_result=%s" % t_result dst_path = self.multimedia_setting.push_file_new(src_path, dst_path) t_result = g_common_obj.adb_cmd_capture_msg("ls %s" % dst_path) assert dst_path in t_result, "push failed! t_result=%s" % t_result return dst_path def scale_test_o_image_prepare(self): package_name, _ = self.multimedia_setting.get_package_and_activity_name( "for_o_image_camera_preview_test_apk") self.o_image_play_cmd = self.scale_test_cfg.get("o_image_play_cmd") result = verify_apps(package_name) self.remount_device() self.backup_file("o_image_media_xml_file_dst_path") self.o_image_media_xml_file_dst_path = self.replace_file( "o_image_media_xml_file_src_path", "o_image_media_xml_file_dst_path") self.backup_file("o_image_libcamhal_xml_file_dst_path") self.o_image_libcamhal_xml_file_dst_path = self.replace_file( "o_image_libcamhal_xml_file_src_path", "o_image_libcamhal_xml_file_dst_path") self.o_image_camera3_xml_file_dst_path = self.backup_file( "o_image_camera3_xml_file_dst_path")[0] self.restore_file("o_image_camera3_xml_file_dst_path", "_hdmi") if not result: self.multimedia_setting.install_apk( "for_o_image_camera_preview_test_apk") return True def scale_test_default_image_prepare(self, fps="60fps"): self.sh_file_src_path = self.scale_test_cfg.get("sh_file_src_path") self.sh_file_dst_path = self.scale_test_cfg.get("sh_file_dst_path") self.backup_file("xml_file_dst_path") package_name, _ = self.multimedia_setting.get_package_and_activity_name( "camera_preview_test_apk") result = verify_apps(package_name) if not result: self.remount_device() g_common_obj.adb_cmd_capture_msg("rm -rf %s" % self.sh_file_dst_path) t_result = g_common_obj.adb_cmd_capture_msg("ls %s" % self.sh_file_dst_path) assert "No such file or directory" in t_result, "rm failed! t_result=%s" % t_result self.sh_file_dst_path = self.multimedia_setting.push_file_new( self.sh_file_src_path, self.sh_file_dst_path) t_result = g_common_obj.adb_cmd_capture_msg("ls %s" % self.sh_file_dst_path) assert "No such file or directory" not in t_result, "push failed! t_result=%s" % t_result g_common_obj.adb_cmd_capture_msg("chmod 777 %s" % self.sh_file_dst_path) self.multimedia_setting.install_apk("camera_preview_test_apk") return not result def scale_test_prepare(self, fps="60fps"): self.logger.debug("scale_test_prepare") if self.camera_helper.android_version == "o": result = self.scale_test_o_image_prepare() else: result = self.scale_test_default_image_prepare(fps) return result def scale_test_o_image_teardown(self): self.remount_device() self.restore_file("o_image_media_xml_file_dst_path") self.restore_file("o_image_libcamhal_xml_file_dst_path") self.restore_file("o_image_camera3_xml_file_dst_path") return 1 def scale_test_teardown(self): self.logger.debug("scale_test_teardown") self.remount_device() if self.camera_helper.android_version == "o": self.restore_file("o_image_media_xml_file_dst_path") self.restore_file("o_image_libcamhal_xml_file_dst_path") self.restore_file("o_image_camera3_xml_file_dst_path") else: self.restore_file("xml_file_dst_path") return 1 def change_scale_test_xml(self, fps): fps = str(fps) self.logger.debug("change_scale_test_xml fps=%s" % fps) if "fps" not in fps and "default" not in fps: fps = fps + "fps" self.remount_device() xml_file_src_path = self.scale_test_cfg.get("%s_xml_file_src_path" % fps) xml_file_dst_path = self.scale_test_cfg.get("%s_xml_file_dst_path" % fps) g_common_obj.adb_cmd_capture_msg("rm -rf %s" % xml_file_dst_path) t_result = g_common_obj.adb_cmd_capture_msg("ls %s" % xml_file_dst_path) assert "No such file or directory" in t_result, "rm failed! t_result=%s" % t_result self.xml_file_dst_path = self.multimedia_setting.push_file_new( xml_file_src_path, xml_file_dst_path) t_result = g_common_obj.adb_cmd_capture_msg("ls %s" % self.xml_file_dst_path) assert self.xml_file_dst_path in t_result, "push failed! t_result=%s" % t_result def change_scale_test_xml_param_handle(self, param, str1, str2): return " -e 's#%s#%s#g' " % (param % str1, param % str2) def change_scale_test_xml_for_o_image(self, dst_path, case_name): self.logger.debug("change_scale_test_xml_for_o_image") field, input_size, input_format, deinterlace_mode = self.analyze_case_name( case_name) main_param = "" main_param += self.change_scale_test_xml_param_handle( "intel.sensorprop.field\ value=\\\"%s\\\"", ".*", field) main_param += self.change_scale_test_xml_param_handle( "intel.sensorprop.inputSize\ value=\\\"%s\\\"", ".*", input_size) main_param += self.change_scale_test_xml_param_handle( "intel.sensorprop.inputFormat\ value=\\\"%s\\\"", ".*", input_format) main_param += self.change_scale_test_xml_param_handle( "intel.sensorprop.deinterlaceMode\ value=\\\"%s\\\"", ".*", deinterlace_mode) cmd = "sed -i %s %s" % (main_param, dst_path) self.logger.debug("change_scale_test_xml_for_o_image cmd=%s" % cmd) g_common_obj.adb_cmd_capture_msg(cmd) def change_libcamhal_xml_for_o_image(self, dst_path, case_name): self.logger.debug("change_libcamhal_xml_for_o_image") actual_fps = self.check_string_with_regular_expression( case_name, r"_(\d*)[fps]{0,3}$", "")[1][0] for t_key in self.scale_test_xml_value_dict.keys(): if actual_fps == str(self.scale_test_xml_value_dict[t_key]): break main_param = "" main_param += self.change_scale_test_xml_param_handle( "ctrlId=\\\"V4L2_CID_TEST_PATTERN\\\"\ value=\\\"%s\\\"\ ctrlName=", ".*", str(t_key)) cmd = "sed -i %s %s" % (main_param, dst_path) self.logger.debug("change_libcamhal_xml_for_o_image cmd=%s" % cmd) g_common_obj.adb_cmd_capture_msg(cmd) def check_string_with_regular_expression(self, string, parttern, expect_value): get_value_parttern = re.compile(parttern) value_list = get_value_parttern.findall(string) assert len( value_list) != 0, "Can't find parttern(%s) in string!" % parttern actual_value = value_list[0] self.logger.debug( "check_string_with_regular_expression actual_value=%s, expect_value=%s" % (actual_value, expect_value)) result = 0 if actual_value == expect_value else -1 return (result, value_list) def analyze_case_name(self, case_name): field = "ANY" if "progressive" in case_name.lower() else "ALTERNATE" deinterlace_mode = "OFF" if "progressive" in case_name.lower( ) else "ON" input_size = self.check_string_with_regular_expression( case_name, r"_(\d*x\d*)", "")[1][0] input_size = input_size.replace("x", ",") input_format = "YUY2" if "YUYV" in case_name else "UYVY" self.logger.debug( "analyze_case_name field=%s, input_size=%s, input_format=%s, deinterlace_mode=%s" % (field, input_size, input_format, deinterlace_mode)) return field, input_size, input_format, deinterlace_mode def check_scale_test_xml_for_o_image(self, case_name): self.logger.debug("check_scale_test_xml_for_o_image case_name=%s" % case_name) field, input_size, input_format, deinterlace_mode = self.analyze_case_name( case_name) check_scale_test_xml_cmd = "cat %s" % self.o_image_camera3_xml_file_dst_path t_result = g_common_obj.adb_cmd_capture_msg(check_scale_test_xml_cmd) result = 0 result += self.check_string_with_regular_expression( t_result, r"<intel.sensorprop.field value=\"(.*)\" />", field)[0] result += self.check_string_with_regular_expression( t_result, r"<intel.sensorprop.inputSize value=\"(.*)\" />", input_size)[0] result += self.check_string_with_regular_expression( t_result, r"<intel.sensorprop.inputFormat value=\"(.*)\" />", input_format)[0] result += self.check_string_with_regular_expression( t_result, r"<intel.sensorprop.deinterlaceMode value=\"(.*)\" />", deinterlace_mode)[0] return True if result == 0 else False def check_libcamhal_xml_for_o_image(self, case_name): self.logger.debug("check_libcamhal_xml_for_o_image case_name=%s" % case_name) check_libcamhal_xml_cmd = "cat %s" % self.o_image_libcamhal_xml_file_dst_path t_result = g_common_obj.adb_cmd_capture_msg(check_libcamhal_xml_cmd) actual_fps = self.check_string_with_regular_expression( case_name, r"_(\d*)[fps]{0,3}$", "")[1][0] for t_key in self.scale_test_xml_value_dict.keys(): if actual_fps == str(self.scale_test_xml_value_dict[t_key]): break result = 0 result += self.check_string_with_regular_expression( t_result, r"ctrlId=\"V4L2_CID_TEST_PATTERN\" value=\"(.*)\" ctrlName=", str(t_key))[0] return True if result == 0 else False def check_scale_test_xml_for_default_image(self, expect_fps, special_str=""): expect_fps = str(expect_fps) if special_str != "": expect_fps = "default" check_scale_test_xml_cmd = "cat %s" % self.xml_file_dst_path t_result = g_common_obj.adb_cmd_capture_msg(check_scale_test_xml_cmd) get_scale_xml_fps_value_parttern = re.compile( r"<control name=\"adv7481-hdmi pixel array 0-00e0\".*value=\"(.)\".*/>" ) fps_value_result_list = get_scale_xml_fps_value_parttern.findall( t_result) self.logger.debug("check_scale_test_xml fps_value_result_list=%s" % fps_value_result_list) if len(fps_value_result_list) == 0: actual_fps = "default" else: fps_value_result = fps_value_result_list[0] self.logger.debug("check_scale_test_xml fps_value_result=%s" % fps_value_result) actual_fps = str(self.scale_test_xml_value_dict[int( fps_value_result[0])]) self.logger.debug("check_scale_test_xml actual_fps=%s, expect_fps=%s" % (actual_fps, expect_fps)) if actual_fps != expect_fps: self.change_scale_test_xml(expect_fps) return True else: return False def check_scale_test_xml(self, expect_fps, case_name=""): if self.camera_helper.android_version == "o": need_reboot = False if "AVM737" in case_name: need_reboot = True self.o_image_libcamhal_xml_file_dst_path = self.replace_file( "o_image_avm737_libcamhal_xml_file_src_path", "o_image_avm737_libcamhal_xml_file_dst_path") elif "fps" in case_name.lower(): result = self.check_libcamhal_xml_for_o_image(case_name) if not result: need_reboot = True self.change_libcamhal_xml_for_o_image( self.o_image_libcamhal_xml_file_dst_path, case_name) assert self.check_libcamhal_xml_for_o_image( case_name), "Fail change libcamhal xml!" result = self.check_scale_test_xml_for_o_image(case_name) if not result: need_reboot = True self.change_scale_test_xml_for_o_image( self.o_image_camera3_xml_file_dst_path, case_name) assert self.check_scale_test_xml_for_o_image( case_name), "Fail change scale test xml!" return need_reboot else: special_str = "AVM737" if "AVM737" in case_name else "" result = self.check_scale_test_xml_for_default_image( expect_fps, special_str) return result def download_reference_library_file(self, file_path): file_name = os.path.split(file_path)[1] t_file_path = self.multimedia_setting.download_file_to_host( os.path.join(self.reference_library_folder, file_name)) shutil.copyfile(t_file_path, file_path) return file_path def pull_video_file_to_host(self): movies_file_name = g_common_obj.adb_cmd_capture_msg( "ls %s" % self.movies_folder_device_path) self.logger.debug( "play_and_record_video_with_instrument movies_file_device_path=%s" % movies_file_name) g_common_obj.adb_cmd_common( "pull %s/%s %s/%s" % (self.movies_folder_device_path, movies_file_name, self.host_path, movies_file_name)) movies_file_host_path = os.path.join(self.host_path, movies_file_name) return movies_file_host_path def play_and_record_video_with_instrument(self, cmd_arguments, case_name): duration = 12 self.play_result = -1 if self.camera_helper.android_version == "o": self.logger.debug( "play_and_record_video_with_instrument case_name=%s" % case_name) if "fps" in case_name.lower(): cmd_arguments_list = cmd_arguments.split(" ") width, height = cmd_arguments_list[4], cmd_arguments_list[5] else: output_size = self.check_string_with_regular_expression( case_name, r"_(\d*x\d*)", "")[1][1] width, height = output_size.split("x") t_format = "NV21" if "NV21" in case_name else "NV21" #need extend cmd_result = g_common_obj.adb_cmd_capture_msg( self.o_image_play_cmd % (width, height, t_format, duration)) else: self.logger.debug( "play_and_record_video_with_instrument cmd=%s %s" % (self.sh_file_dst_path, cmd_arguments)) cmd_result = g_common_obj.adb_cmd_capture_msg( "%s %s" % (self.sh_file_dst_path, cmd_arguments)) self.logger.debug( "play_and_record_video_with_instrument cmd_result = %s" % cmd_result) if "OK" not in cmd_result: self.play_result = 0 else: self.play_result = 1 def get_jpg_from_video(self, video_file_path, output_file_name="output.jpg", output_folder=""): if output_folder == "": if self.generated_reference_library == 1: output_folder = self.expect_folder else: output_folder = self.actual_folder output_file_path = os.path.join(output_folder, output_file_name) t_ffmpeg_cmd = self.ffmpeg_cmd % (video_file_path, output_file_path) self.logger.debug("t_ffmpeg_cmd = %s" % t_ffmpeg_cmd) result = self.__execute_command_with_popen(t_ffmpeg_cmd).stdout.read() assert "Invalid" not in result and "error" not in result, "Generate jpg failed! result=%s" % result return output_file_path
class CameraBenchTest(CameraTestBase): """ @summary: This test used to test camera function """ def setUp(self): """ @summary: set up @return: None """ super(CameraBenchTest, self).setUp() self._test_name = __name__ print "[Setup]: %s" % self._test_name def tearDown(self): """ @summary: tearDown @return: None """ super(CameraBenchTest, self).tearDown() print "[Teardown]: %s" % self._test_name g_common_obj.stop_exp_handle() time.sleep(3) def appPrepare(self): self.camera = CameraCommon().switchPlatform(None, False, True, False, True) # self.camera = RefCam2Camera() self.common = CameraCommon() self.multimedia_setting = MultiMediaSetting( CameraCommon.DEFAULT_CONFIG_FILE) # self.camera = self.common.switchPlatform() self.checkImage = CheckImage() self.video = CheckVideo() # self.checkIQ = CheckIQ() self.host_path = self.common.getTmpDir() self.makefileTime = self.common.makefileTime self.camera_dir = self.common.camera_dir self.common.removeDeivceFile() self.common.removeFile(self.host_path + "/*") self.camera.cleanMediaFiles() # self.common.setOrientationToVertical() self.logger.debug("app prepare successfully") self.device = self.common.initDevice() self.common.resetDevice(self.device) def checkFileCorrupt(self, mediaFileCount=1): return self.common.checkFileCorrupt(mediaFileCount) def cameraExtendPanoramaRearLeft2RightAutoStopTest(self): try: self.appPrepare() # self.common.controlLightBox(1) # self.common.controlLightBox(6) # device = self.common.initDevice() self.camera.startCameraApp() self.camera.switchRearOrFront("Back") self.camera.setCaptureMode("Panorama") self.camera.capturePhoto(1, False) time.sleep(3) self.common.rotateDevice(self.device, -180) self.common.resetDevice(self.device) self.checkFileCorrupt() # self.common.controlLightBox(6) # self.common.controlLightBox(1) except Exception as e: self.common.resetDevice(self.device) self.common.checkCameraCrash() self.assertTrue(False, e) def cameraFaceTrackTurnOnAndOffTest(self, lens): try: self.appPrepare() self.camera.startCameraApp() self.camera.switchRearOrFront(lens) if lens == "Back": self.common.rotateDevice(self.device, -90) else: self.common.rotateDevice(self.device, 90) self.camera.faceDetectionOnAndOff() time.sleep(5) self.common.clickScreenCenter() self.common.getScreenshotAndPullToHost("sc_enable_ft1.png", self.host_path) self.camera.faceDetectionOnAndOff() time.sleep(5) self.common.clickScreenCenter() self.common.pressBack(2) self.camera.startCameraApp() self.common.getScreenshotAndPullToHost("sc_disable_ft2.png", self.host_path) self.camera.faceDetectionOnAndOff() time.sleep(5) self.common.clickScreenCenter() self.common.getScreenshotAndPullToHost("sc_enable_ft2.png", self.host_path) self.common.resetDevice(self.device) remotejarFile = self.multimedia_setting.download_file_to_host( "Multimedia_Camera/apk/IQCheck") print remotejarFile iqcheckDir = self.host_path + os.sep + "IQCheck" print iqcheckDir if os.path.exists(iqcheckDir) == False: os.system("cp " + remotejarFile + " " + iqcheckDir) os.system("chmod 777 " + iqcheckDir) checkIQ = CheckIQ("", self.host_path) l = self.camera.getFOVRegion() region = CheckIQ.Region(l[0], l[1], l[2], l[3], False) enable_number1 = checkIQ.detectRect( self.host_path + "/sc_enable_ft1.png", region) disable_number = checkIQ.detectRect( self.host_path + "/sc_disable_ft2.png", region) enable_number2 = checkIQ.detectRect( self.host_path + "/sc_enable_ft2.png", region) if enable_number1 > disable_number: self.logger.debug("face detect success") else: os.system("cp " + self.host_path + "/sc_enable_ft1.png " + g_common_obj.get_user_log_dir()) os.system("cp " + self.host_path + "/sc_disable_ft2.png " + g_common_obj.get_user_log_dir()) self.logger.debug("enable_number1=" + str(enable_number1)) self.logger.debug("disable_number=" + str(disable_number)) self.assertTrue(False, "face detect failure") if enable_number2 > disable_number: self.logger.debug("face detect success") else: os.system("cp " + self.host_path + "/sc_enable_ft1.png " + g_common_obj.get_user_log_dir()) os.system("cp " + self.host_path + "/sc_disable_ft2.png " + g_common_obj.get_user_log_dir()) self.logger.debug("enable_number2=" + str(enable_number2)) self.logger.debug("disable_number=" + str(disable_number)) self.assertTrue(False, "face detect failure") # print self.checkIQ.detectRect("/tmp/logs/sc_disable_ft2.png",self.checkIQ.Region(self.camera.getFOVRegion(),False)) # print self.checkIQ.detectRect("/tmp/logs/sc_enable_ft2.png", self.checkIQ.Region(self.camera.getFOVRegion(), False)) except Exception as e: self.common.resetDevice(self.device) self.common.checkCameraCrash() self.assertTrue(False, e) def cameraSceneDetectPortraitCaptureTest(self): try: self.appPrepare() self.camera.startCameraApp() self.camera.switchRearOrFront("Back") self.camera.capturePhoto() info = self.checkFileCorrupt()[0] value = info.get("Scene Capture Type") if None != value: if value != "Standard": self.assertTrue(False, "scene capture type is not standard") else: self.assertTrue(False, "scene capture type info is none") self.common.removeDeivceFile() self.camera.setCaptureMode("Smart") self.common.clickScreenCenter() self.camera.capturePhoto() info = self.checkFileCorrupt()[0] value = info.get("Scene Capture Type") if None != value: if value != "Portrait": self.assertTrue(False, "scene capture type is not portrait") else: self.logger.debug( "check scene capture type is portrait success") else: self.assertTrue(False, "scene capture type info is none") self.camera.switchRearOrFront("Front") self.camera.capturePhoto() info = self.checkFileCorrupt()[0] value = info.get("Scene Capture Type") if None != value: # print "=====================front value3=" + value if value != "Standard": self.assertTrue(False, "scene capture type is not standard") else: self.assertTrue(False, "scene capture type info is none") self.common.removeDeivceFile() self.camera.setCaptureMode("Smart") self.common.clickScreenCenter() self.camera.capturePhoto() info = self.checkFileCorrupt()[0] value = info.get("Scene Capture Type") if None != value: # print "====================front value4=" + value if value != "Portrait": self.assertTrue(False, "scene capture type is not portrait") else: self.logger.debug( "check scene capture type is portrait success") else: self.assertTrue(False, "scene capture type info is none") self.common.resetDevice(self.device) except Exception as e: self.common.resetDevice(self.device) self.common.checkCameraCrash() self.assertTrue(False, e) def cameraSmileShotSmileDetectTest(self, lens): try: self.appPrepare() self.camera.startCameraApp() self.camera.switchRearOrFront(lens) if lens == "Back": self.common.rotateDevice(self.device, -90) else: self.common.rotateDevice(self.device, 90) self.camera.setCaptureMode("Smile") time.sleep(10) if self.common.checkDeviceFile(): self.assertTrue(False, "file exists, check file failed") self.camera.capturePhoto() self.checkFileCorrupt() self.common.removeDeivceFile() if lens == "Back": self.common.rotateDevice(self.device, 90) else: self.common.rotateDevice(self.device, 90) if not self.common.checkDeviceFile(): self.assertTrue(False, "file not exists, check file failed") self.checkFileCorrupt() self.common.resetDevice(self.device) except Exception as e: self.common.resetDevice(self.device) self.common.checkCameraCrash() self.assertTrue(False, e) def test_Camera_ExtendPanorama_Rear_Left2Right_AutoStop(self): self.cameraExtendPanoramaRearLeft2RightAutoStopTest() def test_Camera_FaceTrack_Front_TurnOnAndOff(self): self.cameraFaceTrackTurnOnAndOffTest("Front") def test_Camera_FaceTrack_Rear_TurnOnAndOff(self): self.cameraFaceTrackTurnOnAndOffTest("Back") def test_Camera_SceneDetect_Portrait_Capture(self): self.cameraSceneDetectPortraitCaptureTest() def test_Camera_SmileShot_Front_SmileDetect(self): self.cameraSmileShotSmileDetectTest("Front") def test_Camera_SmileShot_Rear_SmileDetect(self): self.cameraSmileShotSmileDetectTest("Back")