def benchTest(self): self.appPrepare() localPath = CameraCommon().getTmpDir() self.camera.startCameraApp() self.camera.selectMode("Camera") checkIQ = CheckIQ("", localPath) """ change to the CWF light """ self.light_port="6" self.deviceControl.pressLightBoxButton("1") self.deviceControl.pressLightBoxButton(self.light_port) """ change the test object """ self.test_object=0 self.deviceControl.selectTestObject(0) """ initialize robot """ from testaid.robot import Robot deviceName = self.deviceControl.getRobotDeviceName() robot = Robot(deviceName) robot.reset() """ Adjust FOV content """ l = self.camera.getFOVRegion() region = CheckIQ.Region(l[0], l[1], l[2], l[3], False) self.deviceControl.adjustFOV(localPath, region, robot) """ Main test code, capture picture """ CameraCommon().clickScreenCenter() self.camera.capturePhoto() time.sleep(2) files = CameraCommon().getMediaFilesFromDevice(self.file_index, 1) self.file_index += len(files) #CameraCommon().moveFilesFromCameraFolder() errMsg = "" for f in files: ret = checkIQ.checkCorrupt(f) if ret!="": errMsg += "file:"+f+" is abnormal! "+ret #CameraCommon().recoverFilesFromCameraTemp() robot.reset() self.assertTrue(errMsg=="", errMsg)
def setUp(self): """ @summary: set up @return: None """ super(CameraTest, self).setUp() self._test_name = __name__ self.logger.debug("[Setup]: %s" % self._test_name) self.multimedia_lightbox_helper = MultiMediaLightBoxHelper() self.multimedia_scroll_helper = MultiMediaScrollHelper() self.multimedia_robot_helper = MultiMediaRobotHelper() self.camera_common = CameraCommon() localPath = self.camera_common.getTmpDir() self.checkIQ = CheckIQ( "/home/auto1/code/camera/git_CheckIQ/iqcheck/IQCheck", localPath) self.change_page_flag = 0
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 benchTest1(self): self.appPrepare() localPath = CameraCommon().getTmpDir() self.camera.startCameraApp() self.camera.selectMode("Camera") checkIQ = CheckIQ("", localPath) CameraCommon().clickScreenCenter() self.camera.capturePhoto() time.sleep(2) files = CameraCommon().getMediaFilesFromDevice(self.file_index, 1) self.file_index += len(files) CameraCommon().moveFilesFromCameraFolder() errMsg = "" #for f in files: # ret = checkIQ.checkCorrupt(f) # if ret!="": CameraCommon().clickScreenCenter() self.camera.capturePhoto() time.sleep(2) files = CameraCommon().getMediaFilesFromDevice(self.file_index, 1) self.file_index += len(files) CameraCommon().recoverFilesFromCameraTemp() self.assertTrue(errMsg=="", errMsg)
class CameraTest(CameraTestBase): """ @summary: This test used to test camera function """ @classmethod def setUpClass(cls): print "[setUpClass]: %s" % cls.__name__ super(CameraTest, cls).setUpClass() cls.d = g_common_obj.get_device() g_common_obj.root_on_device() g_common_obj.remount_device() def setUp(self): """ @summary: set up @return: None """ super(CameraTest, self).setUp() self._test_name = __name__ self.logger.debug("[Setup]: %s" % self._test_name) self.multimedia_lightbox_helper = MultiMediaLightBoxHelper() self.multimedia_scroll_helper = MultiMediaScrollHelper() self.multimedia_robot_helper = MultiMediaRobotHelper() self.camera_common = CameraCommon() localPath = self.camera_common.getTmpDir() self.checkIQ = CheckIQ( "/home/auto1/code/camera/git_CheckIQ/iqcheck/IQCheck", localPath) self.change_page_flag = 0 def tearDown(self): """ @summary: tearDown @return: None """ super(CameraTest, self).tearDown() self.logger.debug("[Teardown]: %s" % self._test_name) g_common_obj.stop_exp_handle() time.sleep(3) self.camera_common.removeDeivceFile() self.multimedia_scroll_helper.reset() self.multimedia_robot_helper.reset() #self.multimedia_robot_helper.move_to_default_position() self.multimedia_lightbox_helper.turn_off_all_light() if self.change_page_flag == 1: self.multimedia_scroll_helper.move(50, -50) self.multimedia_scroll_helper.set_position(0, 0) #time.sleep(3) #self.multimedia_scroll_helper.goto_page(2) def appPrepare(self): self.camera = self.camera_common.switchPlatform() self.host_path = self.camera_common.getTmpDir() self.camera_dir = self.camera_common.camera_dir self.camera_common.removeDeivceFile() self.camera_common.removeFile(self.host_path + "/*") self.camera.cleanMediaFiles() #self.camera_common.setOrientationToVertical() self.logger.debug("app prepare successfully") def test_camera_with_lightbox_operation(self, light_port_list=["Power", "CWF"], page_num=0, position=-1): self.multimedia_robot_helper.move_to_default_position(position) self.multimedia_lightbox_helper.press_light_with_list(light_port_list) self.multimedia_scroll_helper.reset() if page_num != 0: self.change_page_flag = 1 self.multimedia_scroll_helper.goto_page(page_num) time.sleep(2) def test_camera_with_prepare_scroll(self, position=-1): self.test_camera_with_lightbox_operation(position=position) self.camera.startCameraApp() self.camera.selectMode("Camera") t_step = 800 t_increment = 0 find_border_flag = 0 self.multimedia_scroll_helper.move(100, -100) for i in range(10): self.camera.capturePhoto() t_file = self.camera_common.getMediaFilesFromDevice(0, 1)[0] ret = self.checkIQ.detectRect(t_file) ret = int(ret) self.logger.debug("detectRect ret=%s" % ret) if i == 0 and ret >= 20: break elif find_border_flag == 0 and ret >= 20: find_border_flag = 1 elif find_border_flag == 1 and ret >= 20: t_increment += t_step elif find_border_flag == 1 and ret < 20: t_increment = 0 - t_increment / 2 - t_step break self.camera_common.removeDeivceFile() self.multimedia_scroll_helper.move(t_step, t_step / 2) self.multimedia_scroll_helper.move(t_increment, t_increment / 2) self.multimedia_scroll_helper.move(100, -100) self.multimedia_scroll_helper.set_position(0, 0) def test_camera_with_color_checker(self, size=-1, position=-1): if size == 2: position = 0 self.test_camera_with_lightbox_operation(position=position) self.camera.startCameraApp() self.camera.selectMode("Camera") if size != -1: size = self.camera.getAllPhotoResolutions("Back")[size] self.logger.debug("size=%s" % size) self.camera.setPhotoResolution(size, "Back") self.camera.capturePhoto() t_file = self.camera_common.getMediaFilesFromDevice(0, 1)[0] ret = self.checkIQ.checkCorrupt(t_file) assert ret == "", "checkCorrupt ret=%s" % ret def test_camera_with_border(self, position=-1): self.test_camera_with_lightbox_operation(page_num=2, position=position) self.camera.startCameraApp() self.camera.selectMode("Camera") self.camera.capturePhoto() t_file = self.camera_common.getMediaFilesFromDevice(0, 1)[0] ret = self.checkIQ.findBorder(t_file) assert ret == "yes", "findBorder ret=%s" % ret def test_camera_with_move_test(self, position=-1): self.test_camera_with_lightbox_operation(page_num=0, position=position) self.multimedia_robot_helper.rotate(-100) self.multimedia_robot_helper.rotate(100) self.camera.startCameraApp() self.camera.selectMode("Camera") self.camera.capturePhoto() t_file = self.camera_common.getMediaFilesFromDevice(0, 1)[0] #ret = self.checkIQ.findBorder(t_file) ret = self.checkIQ.checkCorrupt(t_file) #assert ret == "yes", "findBorder ret=%s" % ret assert ret == "", "checkCorrupt ret=%s" % ret def lightbox_main_test(self, sub_func_name="", *arg, **keywords): """ This test used to test Camera app The test case spec is following: 1. appPrepare() 2. do sub_func() """ self.case_name = sys._getframe().f_back.f_code.co_name if sub_func_name == "": sub_func_name = "%s_sub_func" % self.case_name self.logger.debug("case_name=%s" % self.case_name) self.logger.debug("netflix_main_test---sub_func_name=%s" % sub_func_name) self.appPrepare() self.logger.debug("Arbitrary parameter is %s" % str(arg)) self.logger.debug("keywords parameter is %s" % str(keywords)) getattr(self, sub_func_name)(*arg, **keywords) self.logger.debug("Case %s is pass!" % self.case_name) def test_Camera_prepare_scroll(self): self.lightbox_main_test("test_camera_with_prepare_scroll") def test_Camera_BenchTest(self): self.lightbox_main_test("test_camera_with_color_checker", 2) def test_Camera_BenchTest_with_low_resolutions(self): self.lightbox_main_test("test_camera_with_color_checker", 2) def test_Camera_BenchTest_with_high_resolutions(self): self.lightbox_main_test("test_camera_with_color_checker", 1) def test_Camera_BorderTest(self): self.lightbox_main_test("test_camera_with_border") def test_Camera_MoveTest(self): self.lightbox_main_test("test_camera_with_move_test")
def check_scale_TP_with_similarity(self, cmd_arguments_list, expect_percent=1, generated_jpg_file_rule="screenshot"): self.case_result = 0 self.case_name = sys._getframe().f_back.f_code.co_name expect_fps = cmd_arguments_list[0].split(" ")[-1] self.multimedia_scale_test_helper.check_scale_test_xml(expect_fps, case_name=self.case_name) self.reboot_device() if len(cmd_arguments_list) == 1: cmd_arguments_list *= 4 t_actual_num = 0 t_expect_num = 0 prev_cmd_arguments = "" t_percent_list = [] for cmd_arguments in cmd_arguments_list: t_actual_num += 1 expect_fps = cmd_arguments.split(" ")[-1] # cmd_arguments = cmd_arguments.replace(" " + expect_fps, " 0.0") self.logger.debug("------loop %s------%s" % (str(t_actual_num), cmd_arguments)) if prev_cmd_arguments == cmd_arguments and self.multimedia_scale_test_helper.generated_reference_library == 1: continue if prev_cmd_arguments != cmd_arguments: t_expect_num += 1 prev_cmd_arguments = cmd_arguments if self.multimedia_scale_test_helper.generated_reference_library != 1: jpg_file_name = "%s_%d.jpg" % (self.case_name, t_actual_num) else: jpg_file_name = "%s_%d.jpg" % (self.case_name, t_expect_num) expect_jpg_file_name = "%s_%d.jpg" % (self.case_name, t_expect_num) if self.multimedia_scale_test_helper.generated_reference_library != 1: generated_jpg_file_folder = self.multimedia_scale_test_helper.actual_folder else: generated_jpg_file_folder = self.multimedia_scale_test_helper.expect_folder thread_1 = threading.Thread(target=self.multimedia_scale_test_helper.play_and_record_video_with_instrument, args=(cmd_arguments, self.case_name)) thread_1.start() #self.multimedia_scale_test_helper.play_and_record_video_with_instrument(cmd_arguments) if generated_jpg_file_rule == "screenshot": time.sleep(8) jpg_file_name = jpg_file_name.replace(".jpg", ".png") expect_jpg_file_name = expect_jpg_file_name.replace(".jpg", ".png") self.camera_common.getScreenshotAndPullToHost(jpg_file_name, generated_jpg_file_folder) generated_jpg_file_path = os.path.join(generated_jpg_file_folder, jpg_file_name) while self.multimedia_scale_test_helper.play_result == -1: time.sleep(1) if self.multimedia_scale_test_helper.play_result != 1: t_percent_list.append((0, generated_jpg_file_path, "play error! play_result=%s" % self.multimedia_scale_test_helper.play_result)) continue else: thread_1.join() if self.multimedia_scale_test_helper.play_result != 1: t_percent_list.append((0, "play error!", "play_result=%s" % self.multimedia_scale_test_helper.play_result)) continue movies_file_host_path = self.multimedia_scale_test_helper.pull_video_file_to_host() generated_jpg_file_path = self.multimedia_scale_test_helper.get_jpg_from_video(movies_file_host_path, jpg_file_name) self.multimedia_scale_test_helper.play_result = -1 self.logger.debug("check_scale_TP_with_similarity jpg_file_path=%s" % generated_jpg_file_path) if self.multimedia_scale_test_helper.generated_reference_library != 1: if "AVM737" in self.case_name: t_percent_list.append((1, generated_jpg_file_path, "AVM737 playback no crash!")) continue if "o" in self.android_version: t_region=CheckIQ.Region(0, 0, 1900, 1024) else: t_region=CheckIQ.Region(max=True) expect_jpg_file_path = os.path.join(self.multimedia_scale_test_helper.expect_folder, expect_jpg_file_name) if not os.path.exists(expect_jpg_file_path): self.multimedia_scale_test_helper.download_reference_library_file(expect_jpg_file_path) assert os.path.exists(expect_jpg_file_path), "Can't find reference library(%s)! please check it." % expect_jpg_file_path t_percent = self.multimedia_checkiq_helper.compare_picture_similarity(generated_jpg_file_path, expect_jpg_file_path, t_region) t_percent_list.append((t_percent, generated_jpg_file_path, expect_jpg_file_path)) if self.multimedia_scale_test_helper.generated_reference_library != 1: self.logger.debug("check_scale_TP_with_similarity t_percent_list=%s" % str(t_percent_list)) pass_num = 0 t_sum = 0 user_log_dir = g_common_obj.get_user_log_dir() self.logger.debug("check_scale_TP_with_similarity user_log_dir=%s" % str(user_log_dir)) for t_actual_percent, generated_jpg_file_path, _ in t_percent_list: t_sum += 1 if t_actual_percent >= expect_percent: pass_num += 1 elif "!" not in generated_jpg_file_path: shutil.copy(generated_jpg_file_path, user_log_dir) case_message_info = "Similarity failed! pass_rate=%.2f%%, t_percent_list=%s" % (pass_num/(t_sum*1.0)*100, t_percent_list) if "640x480_Progressive" in self.case_name or "720x576_Progressive" in self.case_name:#OAM issue don't need fixed,so ignore it.(sync with sunxue) pass_num = t_sum if pass_num >= 1 else pass_num assert pass_num == t_sum, case_message_info else: self.logger.debug("case_name generated reference library complete!") self.case_result = 1
def compare_picture_similarity(self, file_1, file_2, region=CheckIQ.Region(max=True)): result = self.check_IQ.cmpHist(file_1, file_2, region) return result
class MultiMediaCheckiqHelper: 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 __execute_command_with_popen(self, cmd): logger.debug("cmd=%s" % cmd) return subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) def compare_picture_similarity(self, file_1, file_2, region=CheckIQ.Region(max=True)): result = self.check_IQ.cmpHist(file_1, file_2, region) return result def convert_video_to_jpg(self, video_file_name): video_file_path = "%s/%s" % (self.host_path, video_file_name) jpg_folder = "%s/%s_jpg_folder" % (self.host_path, video_file_name) logger.debug("convert_video_to_jpg video_file_path=%s, jpg_folder=%s" % (video_file_path, jpg_folder)) os.makedirs(jpg_folder) cmd = "ffmpeg -i %s %s" % ( video_file_path, jpg_folder) + "/1m%04d.jpg -vcodec mjpeg -ss 0:0:0 -t 0:0:10" self.fdp = self.__execute_command_with_popen(cmd) self.fdp.wait() return video_file_path, jpg_folder def get_barcode_list(self, jpg_folder): jpg_name_list = os.listdir(jpg_folder) jpg_name_list.sort() return jpg_name_list def cut_picture(self, jpg_folder, jpg_name_list): from PIL import Image cut_temp_dir = os.path.join(self.home_path, "tmp/high_speed_temp_dir_p/") if not os.path.exists(cut_temp_dir): os.makedirs(cut_temp_dir) cut_tuple = (100, 90, 860, 510) for jpg_name in jpg_name_list: im = Image.open(os.path.join(jpg_folder, jpg_name)) region = im.crop(cut_tuple) region.save(os.path.join(cut_temp_dir, jpg_name)) def get_barcode_with_jpg_list(self, jpg_folder, jpg_name_list): barcode_list = [] i = 1 t_sum = len(jpg_name_list) print "==========analyze barcode==========" for jpg_name in jpg_name_list: jpg_path = os.path.join(jpg_folder, jpg_name) barcode = self.check_IQ.getBarcode(jpg_path, self.zxing_jar_file_path) barcode_list.append((jpg_name, barcode)) if self.analyze_barcode(barcode[0]) != -1: break t_percent = int(i * 100.0 / t_sum) progress(50, (t_percent)) i += 1 progress(50, (100)) print self.cut_picture(jpg_folder, jpg_name_list) return barcode_list def bit_sum(self, num): sum = 0 while num > 0: sum += num % 10 num = num / 10 return sum def analyze_barcode(self, barcode): if len(barcode) > 5 or len(barcode) < 4: return -1 barcode_num = barcode[:-1] if not barcode_num.isdigit(): return -1 barcode_num = int(barcode_num) if self.num_list[self.bit_sum(barcode_num)] != barcode[-1]: # print self.num_list[self.bit_sum(barcode_num)], "=========", barcode[-1] return -1 return barcode_num def check_barcode_list(self, barcode_list): t_barcode_num = self.analyze_barcode(barcode_list[0]) actual_barcode_num_list = [t_barcode_num] pass_num = 0 error_num = 0 for jpg_name, (barcode, _) in barcode_list: # print jpg_name, barcode barcode_num = self.analyze_barcode(barcode) if barcode_num == -1: continue elif barcode_num == t_barcode_num: continue elif barcode_num == t_barcode_num + 1: pass_num += 1 actual_barcode_num_list.append(barcode_num) t_barcode_num = barcode_num else: pass_num += 1 error_num += 1 # actual_barcode_num_list.append("error!") actual_barcode_num_list.append(barcode_num) t_barcode_num = barcode_num return pass_num, error_num, actual_barcode_num_list def check_video_with_barcode(self, video_file_name): video_file_path, jpg_folder = self.convert_video_to_jpg( video_file_name) jpg_name_list = self.get_barcode_list(jpg_folder) barcode_list = self.get_barcode_with_jpg_list(jpg_folder, jpg_name_list) self.check_barcode_list(barcode_list)
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)