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.case_result = -1

        g_common_obj.root_on_device()
        g_common_obj.remount_device()
        self.camera_common = CameraCommon()
        self.multimedia_setting = MultiMediaSetting(self.camera_common.DEFAULT_CONFIG_FILE)

        self.host_path = self.camera_common.getTmpDir()
        self.multimedia_scale_test_helper = MultiMediaScaleTestHelper(self.host_path)
        self.multimedia_checkiq_helper = MultiMediaCheckiqHelper(self.host_path)
        self.android_version = MultiMediaSwitchCameraHelper(skip_import_camera=True).android_version.lower()

        self.multimedia_scale_test_helper.scale_test_prepare()

        self.camera_common.removeDeivceFile()
        self.camera_common.removeDeivceFile(self.multimedia_scale_test_helper.movies_folder_device_path + "*")
        self.camera_common.removeFile(self.host_path + "/*.mp4")

        self.camera_common.unlockScreen()
        self.d = g_common_obj.get_device()
        self.skipAccountLoginLyout()
        g_common_obj.back_home()
        if self.d(text="Got it").exists:
            self.d(text="Got it").click.wait()
    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.camera_common = CameraCommon()
        self.host_path = self.camera_common.getTmpDir()

        self.relay08_helper = Relay08Helper()
        self.multimedia_lightbox_helper = MultiMediaLightBoxHelper()
        self.multimedia_robot_helper = MultiMediaRobotHelper()
        self.multimedia_mplayer_helper = MultiMediaMplayerHelper()
        self.multimedia_checkiq_helper = MultiMediaCheckiqHelper(
            self.host_path)
        self.multimedia_high_speed_helper = MultiMediaHighSpeedCameraHelper()
        self.multimedia_high_speed_helper.clear_temp_dir()

        self.rvc_camera = ""
        self.aosp_camera = ""
        self.case_result = -1

        self.camera_common.removeDeivceFile()
        self.camera_common.removeFile(self.host_path + "/*")
        self.camera_common.unlockScreen()
        self.get_rvc_camera_class().skipAccountLoginLyout()
        self.get_rvc_camera_class().backHome()

        self.multimedia_high_speed_helper.connect()
Beispiel #3
0
    def test1(self):
        self.multimedia_mplayer_helper = MultiMediaMplayerHelper()
        self.multimedia_checkiq_helper = MultiMediaCheckiqHelper(
            self.host_path)

        self.multimedia_mplayer_helper.play_video(
            "/home/auto1/tmp/video_20s.avi")
        time.sleep(2)
        self.multimedia_mplayer_helper.control_video(
            ["pause", "pausing seek 0 2", "frame_step"])
        self.get_aosp_camera_class().startCameraApp()
        self.get_aosp_camera_class().selectMode("Video")
        self.multimedia_mplayer_helper.control_video(["pause"])
        self.get_aosp_camera_class().recordVideo(1, 5)
        self.multimedia_mplayer_helper.close_video()
        file_info, file_name = self.check_file_corrupt()
        self.multimedia_checkiq_helper.check_video_with_barcode(file_name)
Beispiel #4
0
 def __init__(self, cfg=None):
     super(IVICameraO, self).__init__(cfg)
     self.camera_common = CameraCommon()
     self.host_path = self.camera_common.getTmpDir()
     self.multimedia_canbox_helper = MultiMediaCanboxHelper()
     self.multimedia_checkiq_helper = MultiMediaCheckiqHelper(
         self.host_path)
     user_log_dir = g_common_obj.get_user_log_dir()
     self.before_screen_0_file_path = os.path.join(
         user_log_dir, "before_enter_camera_0_screenshot.png")
     self.after_screen_0_file_path = os.path.join(
         user_log_dir, "after_enter_camera_0_screenshot.png")
     self.before_screen_c_file_path = os.path.join(
         user_log_dir, "before_enter_camera_c_screenshot.png")
     self.after_screen_c_file_path = os.path.join(
         user_log_dir, "after_enter_camera_c_screenshot.png")
     self.now_camera_0_event = 0
     self.camera_0_event_array = [("GEAR_NEUTRAL", 0), ("GEAR_DRIVE", 0),
                                  ("GEAR_REVERSE", 1), ("GEAR_PARK", 2),
                                  ("GEAR_LOW", 0)]
     self.now_camera_c_event = 0
     self.camera_c_event_array = [("NONE", 0), ("EMERGENCY", 0),
                                  ("RIGHT", 1), ("LEFT", 1)]
     self.init_camera_with_canbox()
class CameraTest(CameraTestBase):
    """
    @summary: This test used to test camera function
    """
    config = TestConfig()

    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.case_result = -1

        g_common_obj.root_on_device()
        g_common_obj.remount_device()
        self.camera_common = CameraCommon()
        self.multimedia_setting = MultiMediaSetting(self.camera_common.DEFAULT_CONFIG_FILE)

        self.host_path = self.camera_common.getTmpDir()
        self.multimedia_scale_test_helper = MultiMediaScaleTestHelper(self.host_path)
        self.multimedia_checkiq_helper = MultiMediaCheckiqHelper(self.host_path)
        self.android_version = MultiMediaSwitchCameraHelper(skip_import_camera=True).android_version.lower()

        self.multimedia_scale_test_helper.scale_test_prepare()

        self.camera_common.removeDeivceFile()
        self.camera_common.removeDeivceFile(self.multimedia_scale_test_helper.movies_folder_device_path + "*")
        self.camera_common.removeFile(self.host_path + "/*.mp4")

        self.camera_common.unlockScreen()
        self.d = g_common_obj.get_device()
        self.skipAccountLoginLyout()
        g_common_obj.back_home()
        if self.d(text="Got it").exists:
            self.d(text="Got it").click.wait()

    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()

        self.camera_common.removeDeivceFile()
        self.camera_common.removeDeivceFile(self.multimedia_scale_test_helper.movies_folder_device_path + "*")
        if self.multimedia_scale_test_helper.scale_test_teardown() == 1 or self.case_result == 0:
            self.reboot_device()
        time.sleep(3)
        g_common_obj.back_home()

    def skipAccountLoginLyout(self):
        if self.d(textContains="Drive safely").exists:
            self.d(text="Owner").click()
            time.sleep(3)

    def reboot_device(self):
        adb32._adb_reboot()
#         self.skipAccountLoginLyout()
        time.sleep(15)

    def check_logcat_data(self, data_list, expect_fps):
        self.logger.debug("check_logcat_data data_list=%s" % data_list)
        if len(data_list) == 0:
            return False, -1
        i = 0
        for t_fps in data_list:
            i += 1
            t_fps = float(t_fps)
            if expect_fps * 0.95 > t_fps or t_fps > expect_fps * 1.05:
                if i <= 3:
                    continue
                return False, t_fps
        return True, 1

    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 check_scale_TP_with_fps(self, cmd_arguments_list):
        self.case_result = 0
        self.case_name = sys._getframe().f_back.f_code.co_name

#         assert "o" not in self.android_version, "Feature not merge in BxtP_O"

        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()

        g_common_obj.adb_cmd_capture_msg("setprop camera.hal.perf 3")

        t_percent_list = []
        if "o" in self.android_version:
            self.multimedia_logcat_helper = MultiMediaLogcatHelper("adb logcat Camera3HWI:D *:S")
        else:
            self.multimedia_logcat_helper = MultiMediaLogcatHelper("adb logcat CameraHardwareSoc:D *:S")
        for cmd_arguments in cmd_arguments_list:
            if "3840 2160" in cmd_arguments:
                continue
            self.multimedia_logcat_helper.get_logcat_data_start()

            self.multimedia_scale_test_helper.play_result = -1
            expect_fps = cmd_arguments.split(" ")[-1]
            cmd_arguments = cmd_arguments.replace(" " + expect_fps, " 0.0")
            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()

            while self.multimedia_scale_test_helper.play_result == -1:
                time.sleep(1)

            if "o" in self.android_version:
                result_list = self.multimedia_logcat_helper.get_logcat_data_end("FPS=(.*) buffcount")
            else:
                result_list = self.multimedia_logcat_helper.get_logcat_data_end("total fps is (.*),")
            if self.multimedia_scale_test_helper.play_result != 1:
                t_percent_list.append((0, "cmd=%s, play error!" % cmd_arguments, "play_result=%s" % self.multimedia_scale_test_helper.play_result))
            elif len(result_list) == 0:
                t_percent_list.append((-1, "find error!", "can't find fps in logcat! cmd_arguments=%s" % cmd_arguments))
            else:
                expect_fps = float(expect_fps)
                check_logcat_data_result, error_fps = self.check_logcat_data(result_list, expect_fps)
                if check_logcat_data_result:
                    t_percent_list.append((1, "cmd=%s, pass!" % cmd_arguments, "expect_fps=%s, result_list=%s" % (expect_fps, result_list)))
                else:
                    t_percent_list.append((-2, "cmd=%s, fps error!" % cmd_arguments, "error_fps=%s, expect_fps=%s, result_list=%s" % (error_fps, expect_fps, result_list)))
        self.logger.debug("check_scale_TP_with_fps t_percent_list=%s" % str(t_percent_list))
        pass_num = 0
        t_sum = 0
        for t_result, _, _ in t_percent_list:
            t_sum += 1
            if t_result == 1:
                pass_num += 1
        case_message_info = "check fps failed! pass_rate=%.2f%%, t_percent_list=%s" % (pass_num/(t_sum*1.0)*100, t_percent_list)
        assert pass_num == t_sum, case_message_info
        self.case_result = 1
Beispiel #6
0
class CameraTest(CameraTestBase):
    """
    @summary: This test used to test camera function
    """
    def setUp(self):
        """
        @summary: set up
        @return: None
        """
        super(CameraTest, self).setUp()
        self._test_name = __name__
        self.logger.debug("[Setup]: %s" % self._test_name)

        g_common_obj.root_on_device()
        self.camera_common = CameraCommon()

        self.host_path = self.camera_common.getTmpDir()

        self.rvc_camera = ""
        self.aosp_camera = ""
        self.ref_camera = ""
        self.case_result = -1

        self.camera_common.removeDeivceFile()
        self.camera_common.removeFile(self.host_path + "/*")
        self.get_rvc_camera_class().stopCameraApp()
        self.camera_common.unlockScreen()
        self.get_rvc_camera_class().skipAccountLoginLyout()
        self.get_rvc_camera_class().backHome()
        self.d = g_common_obj.get_device()
        if self.d(text="Got it").exists:
            self.d(text="Got it").click.wait()

    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()

        if self.rvc_camera != "":
            self.rvc_camera.stopCameraApp()
        if self.aosp_camera != "":
            self.aosp_camera.cleanMediaFiles()
        self.camera_common.removeDeivceFile()
        if self.case_result == 0:
            self.reboot_device()
#         self.camera_common.removeFile(self.host_path + "/*")
        time.sleep(3)
        self.get_rvc_camera_class().backHome()

    def appPrepare(self, ):
        self.logger.debug("app prepare successfully")

    def check_file_corrupt(self, mediaFileCount=1):
        return self.camera_common.checkFileCorrupt(mediaFileCount)

    def get_rvc_camera_class(self):
        if self.rvc_camera == "":
            self.rvc_camera = MultiMediaSwitchCameraHelper().camera
        return self.rvc_camera

    def get_aosp_camera_class(self):
        if self.aosp_camera == "":
            self.aosp_camera = AOSPCamera()
        return self.aosp_camera

    def get_ref_camera_class(self):
        if self.ref_camera == "":
            self.ref_camera = RefCamCamera()
        return self.ref_camera

    def reboot_device(self):
        self.get_rvc_camera_class().reboot_device()

    def check_home_or_lock_layout(self, check_exist=True):
        if self.d(text="Got it").exists:
            self.d(text="Got it").click.wait()
        self.get_rvc_camera_class().skipAccountLoginLyout()
        assert self.get_rvc_camera_class().isHomeLayoutExists(
        ) or self.get_rvc_camera_class().isLockLayoutExists(
        ), "Home or Lock layout not exist!"

    def start_stop_camera_test(self, wait_time=5, check_success=1):
        self.logger.debug("start_stop_camera_test start")
        self.get_rvc_camera_class().startCameraApp(check_success)
        time.sleep(wait_time)
        self.get_rvc_camera_class().stopCameraApp()
        time.sleep(2)

    def check_gps(self):
        self.multimedia_setting = MultiMediaSetting(
            self.camera_common.DEFAULT_CONFIG_FILE)
        self.multimedia_setting.install_apk("gps_apk")
        self.camera_common.launchGpsApp()
        network_longitude, network_latitude = self.camera_common.getGPSLocation(
        )
        return network_longitude, network_latitude

    def check_logcat_data(self, data_list, expect_lower_limit_fps,
                          expect_upper_limit_fps):
        self.logger.debug("check_logcat_data data_list=%s" % data_list)
        if len(data_list) == 0:
            return False, -1
        for t_fps in data_list:
            t_fps = float(t_fps)
            if expect_lower_limit_fps > t_fps or t_fps > expect_upper_limit_fps:
                return False, t_fps
        return True, 1

    def check_aosp_camera_exif_info(self, check_info_dict):
        self.case_result = 0
        self.get_aosp_camera_class().startCameraApp()
        self.get_aosp_camera_class().selectMode("Camera")
        self.get_aosp_camera_class().capturePhoto(1)
        file_info, file_name = self.check_file_corrupt()
        for check_info_key in check_info_dict.keys():
            assert check_info_key in file_info.keys(
            ), "\"%s\" not in exif info!" % check_info_key
            actual_info = file_info[check_info_key]
            expect_info_parttern = re.compile(check_info_dict[check_info_key])
            self.logger.debug(
                "actual_info = \"%s\", expect_info_parttern = \"%s\"" %
                (actual_info, check_info_dict[check_info_key]))
            result_list = expect_info_parttern.findall(actual_info)
            self.logger.debug(result_list)
            assert result_list != [], "actual_info = \"%s\", expect_info_parttern = \"%s\", result_list = \"%s\"" % (
                actual_info, check_info_dict[check_info_key], result_list)
        self.logger.debug("info:%s" % file_info)
        self.get_aosp_camera_class().stopCameraApp()
        self.get_aosp_camera_class().cleanMediaFiles()
        self.case_result = 1

    def check_ref_camera_preview_with_format(self,
                                             preview_format,
                                             duration=10):
        self.android_version = MultiMediaSwitchCameraHelper(
            skip_import_camera=True).android_version.lower()
        if "o" in self.android_version:
            self.multimedia_setting = MultiMediaSetting(
                self.camera_common.DEFAULT_CONFIG_FILE)
            self.multimedia_setting.install_apk(
                "for_o_image_camera_preview_test_apk")
            from testlib.multimedia.get_device_port_helper import GetConfigFileHelper
            self.scale_test_cfg = GetConfigFileHelper(
                "", "multimedia_scale_test_helper.conf").get_section("config")
            self.o_image_play_cmd = self.scale_test_cfg.get("o_image_play_cmd")
            check_size_list = ["720x480", "640x480", "320x240", "176x144"]
            from testlib.graphics.common import adb32
            adb32._adb_reboot()
            time.sleep(15)
            for size in check_size_list:
                width, height = size.split("x")
                result = g_common_obj.adb_cmd_capture_msg(
                    self.o_image_play_cmd %
                    (width, height, preview_format, duration))
                assert "OK" in result, "play error! result=%s" % result
                time.sleep(2)
        else:
            self.get_ref_camera_class().startCameraApp()
            self.get_ref_camera_class().selectMode("SingleShot")
            self.get_ref_camera_class().setSettingsButton(
                "Preview Format", preview_format)
            check_size_list = [
                "1920x1080", "1280x720", "720x480", "640x480", "320x240",
                "176x144"
            ]
            for size in check_size_list:
                self.logger.debug("capture photo, format: %s, size: %s" %
                                  (preview_format, size))
                self.get_ref_camera_class().setSettingsButton(
                    "Picture Size", size)
                self.get_ref_camera_class().capturePhoto()
            self.camera_common.checkFileCorrupt(len(check_size_list))

    def test_Camera_Launch_With_Press_Power(self):
        self.get_rvc_camera_class.reboot_device()
        self.logger.debug("---start sleep---")
        #         time.sleep(3)
        #         self.logger.debug("---start pressPowerKey---")
        #         self.camera.pressPowerKey(2)
        #         self.wait_boot_completed()
        time.sleep(5)
        self.start_stop_camera_test(10)
        time.sleep(10)
        self.start_stop_camera_test()

    def test_Camera_IVI_RVC_Preview_Horizontal(self):
        self.get_rvc_camera_class().startCameraApp()
        time.sleep(5)
        d = g_common_obj.get_device()
        x = d.info["displayWidth"]
        y = d.info["displayHeight"]
        self.logger.debug("display size--- x:%s, y:%s" % (str(x), str(y)))
        assert int(x) > int(y), "RVC FOV not display as horizontal"
        self.get_rvc_camera_class().stopCameraApp()

    def test_Camera_IVI_RVC_ColdBoot_Available_10Mins(self):  ######
        self.reboot_device()
        self.get_rvc_camera_class().startCameraApp()
        self.logger.debug("Wait 10mins...")
        time.sleep(600)
        self.get_rvc_camera_class().startCameraApp()
        self.get_rvc_camera_class().stopCameraApp()
        time.sleep(5)
        self.check_home_or_lock_layout()

    def test_Camera_IVI_RVC_ColdBoot_off_Available(self):  ######
        self.reboot_device()
        for _ in range(5):
            self.start_stop_camera_test()
        self.check_home_or_lock_layout()

    def test_Camera_IVI_RVC_ColdBoot_Switch_Repeatly(self):  ######
        self.reboot_device()
        for _ in range(5):
            self.start_stop_camera_test()
        self.check_home_or_lock_layout()

    def test_Camera_IVI_RVC_ColdBoot_Repeatly(self):  ######
        for i in range(10):
            self.logger.debug("------loop %s------" % str(i + 1))
            self.reboot_device()
            self.get_rvc_camera_class().stopCameraApp()
            time.sleep(5)
            self.get_rvc_camera_class().startCameraApp()
        time.sleep(5)
        self.get_rvc_camera_class().stopCameraApp()

    def test_Camera_IVI_RVC_ColdBoot_on_Available(self):
        self.reboot_device()
        self.get_rvc_camera_class().backHome()
        self.check_home_or_lock_layout()
        self.start_stop_camera_test()

    def test_Camera_IVI_RVC_RunTime_Available(self):
        self.reboot_device()
        self.get_rvc_camera_class().startCameraApp()
        time.sleep(5)
        self.get_rvc_camera_class().stopCameraApp()
        time.sleep(5)
        self.check_home_or_lock_layout()

    def test_Camera_IVI_RVC_RunTime_Available_10Mins(self):
        self.reboot_device()
        self.get_rvc_camera_class().startCameraApp()
        self.logger.debug("Wait 10mins...")
        time.sleep(600)
        self.get_rvc_camera_class().stopCameraApp()
        time.sleep(5)
        self.check_home_or_lock_layout()
        self.get_rvc_camera_class().startCameraApp()
        self.get_rvc_camera_class().stopCameraApp()
        time.sleep(5)
        self.check_home_or_lock_layout()

    def test_Camera_IVI_RVC_RunTime_On_Quickly(self):
        self.reboot_device()
        for i in range(1, 6):
            self.logger.debug("------loop %s------" % i)
            self.get_rvc_camera_class().startCameraApp()
            self.get_rvc_camera_class().stopCameraApp()
            time.sleep(3)

    def test_Camera_IVI_RVC_Switch_From_CameraAPP(self):
        self.check_home_or_lock_layout()
        self.get_aosp_camera_class().startCameraApp()
        for i in range(1, 6):
            self.logger.debug("------loop %s------" % i)
            self.get_rvc_camera_class().startCameraApp()
            self.get_rvc_camera_class().stopCameraApp()
            self.get_aosp_camera_class().checkCameraApp()
            time.sleep(3)

    def test_Camera_IVI_AOSPCamera_Launch_Repeat(self):
        self.check_home_or_lock_layout()
        count = 20
        for i in range(1, count + 1):
            self.logger.debug("------loop %s------" % i)
            self.get_aosp_camera_class().startCameraApp()
            self.get_aosp_camera_class().checkCameraApp()
            self.get_aosp_camera_class().stopCameraApp()
            time.sleep(3)

    def test_Camera_IVI_AOSP_Rear_Launch(self):
        self.check_home_or_lock_layout()
        self.get_aosp_camera_class().startCameraApp()
        self.get_aosp_camera_class().checkCameraApp()
        self.get_aosp_camera_class().stopCameraApp()

    def test_Camera_IVI_Rear_Preview_CVBS1(self):
        self.test_Camera_IVI_AOSP_Rear_Launch()

    def test_Camera_FIT_RVC_Lock_With_PW(self):
        try:
            #             self.multimedia_setting.install_apk("unlock_app")
            self.camera_common.setLockScreenWithPasswd()
            time.sleep(1)
            self.camera_common.pressPower()
            time.sleep(2)
            d = g_common_obj.get_device()
            d.wakeup()
            time.sleep(2)
            for i in range(1, 6):
                self.logger.debug("------loop %s------" % i)
                self.get_rvc_camera_class().startCameraApp()
                time.sleep(5)
                self.get_rvc_camera_class().stopCameraApp()
                time.sleep(3)
            self.camera_common.unlockScreen()
#             self.camera_common.launchUnlockAppToUnlockScreen()
        except Exception as e:
            self.assertTrue(False, e)
        finally:
            self.get_rvc_camera_class().stopCameraApp()
            self.camera_common.setLockScreenWithPasswd(False)

    def test_Camera_IVI_AOSP_Metadata_EXIF_CameraModelName(self):
        self.check_aosp_camera_exif_info(
            {"Camera Model Name": "AOSP on Intel Platform"})

    def test_Camera_IVI_AOSP_Metadata_EXIF_DateTime(self):
        self.check_aosp_camera_exif_info(
            {"Create Date": "\d{4}:\d{2}:\d{2} \d{2}:\d{2}:\d{2}"})

    def test_Camera_IVI_AOSP_Metadata_EXIF_GPSLocation(self):
        self.check_gps()
        self.check_aosp_camera_exif_info({"GPS Position": ".*N,.*E"})

    def test_Camera_IVI_AOSP_Metadata_EXIF_ImageDescription(self):
        self.check_aosp_camera_exif_info({"Image Description": "Jpeg"})

    def test_Camera_IVI_AOSP_Metadata_EXIF_Make(self):
        self.check_aosp_camera_exif_info({"Make": "Intel"})

    def test_Camera_IVI_AOSP_Metadata_EXIF_Resolution(self):
        self.check_aosp_camera_exif_info({"Image Size": "\d{3,4}x\d{3,4}"})

    def test_Camera_Rear_PreviewFormat_NV21(self):
        self.check_ref_camera_preview_with_format("NV21")

    def test_Camera_Rear_PreviewFormat_YV12(self):
        self.check_ref_camera_preview_with_format("YV12")

    def test_Camera_IVI_Preview_PictureFormat_NTSC(self):
        self.check_ref_camera_preview_with_format("NV21")
        self.check_ref_camera_preview_with_format("YV12")

    def test_Camera_Rear_PreviewFormat_RGB565(self):
        self.check_ref_camera_preview_with_format("RGB_565")

    def test_Camera_Rear_PreviewFormat_YUY2(self):
        self.check_ref_camera_preview_with_format("YUY2")

    def test_Camera_IVI_AVM737_Preview_FPS_Range(self):
        self.multimedia_logcat_helper = MultiMediaLogcatHelper(
            "adb logcat CameraHardwareSoc:D *:S")
        self.get_ref_camera_class().startCameraApp()
        self.get_ref_camera_class().selectMode("SingleShot")
        self.get_ref_camera_class().setSettingsButton("Preview FPS Range",
                                                      "30000-30000")
        self.multimedia_logcat_helper.get_logcat_data_start()
        time.sleep(5)
        result_list = self.multimedia_logcat_helper.get_logcat_data_end(
            "total fps is (.*),")
        check_logcat_data_result, error_fps = self.check_logcat_data(
            result_list, 29, 31)
        assert check_logcat_data_result, "fps error! error_fps=%s, expect_fps=%s, result_list=%s" % (
            error_fps, "30000-30000", result_list)
        self.get_ref_camera_class().capturePhoto()
        self.get_ref_camera_class().setSettingsButton("Preview FPS Range",
                                                      "30000-60000")
        self.multimedia_logcat_helper.get_logcat_data_start()
        time.sleep(5)
        result_list = self.multimedia_logcat_helper.get_logcat_data_end(
            "total fps is (.*),")
        check_logcat_data_result, error_fps = self.check_logcat_data(
            result_list, 30, 60)
        assert check_logcat_data_result, "fps error! error_fps=%s, expect_fps=%s, result_list=%s" % (
            error_fps, "30000-60000", result_list)
        self.get_ref_camera_class().capturePhoto()
        self.camera_common.checkFileCorrupt(2)

    def test_ref_camera_with_different_format(self, preview_format):
        assert 0, "Need OV10635 senser!"
        self.multimedia_setting = MultiMediaSetting(
            self.camera_common.DEFAULT_CONFIG_FILE)
        self.multimedia_setting.executeCommandWithPopen(
            "setprop camera.hal.perf 3")
        self.get_ref_camera_class().startCameraApp()
        self.get_ref_camera_class().selectMode("SingleShot")
        self.get_ref_camera_class().setSettingsButton("Preview Format",
                                                      preview_format)
        preview_size_list = ["1280x800", "1280x720", "640x480"]
        for preview_size in preview_size_list:
            self.get_ref_camera_class().setSettingsButton(
                "Picture Size", preview_size)
            self.get_ref_camera_class().capturePhoto()
        self.camera_common.checkFileCorrupt(len(preview_size_list))

    def test_Camera_IVI_OV10635_Preview_NV21_Available(self):
        self.test_ref_camera_with_different_format("NV21")

    def test_Camera_IVI_OV10635_Preview_RGB565_Available(self):
        self.test_ref_camera_with_different_format("RGB565")

    def test_Camera_IVI_OV10635_Preview_YUY2_Available(self):
        self.test_ref_camera_with_different_format("YUY2")

    def test_Camera_IVI_OV10635_Preview_YV12_Available(self):
        self.test_ref_camera_with_different_format("YV12")

    def test_ref_camera_check_fps(self, preview_format):
        assert 0, "Need OV10635 senser!"
        self.multimedia_setting = MultiMediaSetting(
            self.camera_common.DEFAULT_CONFIG_FILE)
        self.multimedia_setting.executeCommandWithPopen(
            "setprop camera.hal.perf 3")
        self.multimedia_logcat_helper = MultiMediaLogcatHelper(
            "adb logcat CameraHardwareSoc:D *:S")
        self.get_ref_camera_class().startCameraApp()
        self.get_ref_camera_class().selectMode("SingleShot")
        self.get_ref_camera_class().setSettingsButton("Preview Format",
                                                      preview_format)
        self.multimedia_logcat_helper.get_logcat_data_start()
        time.sleep(1 * 60)
        preview_size_list = ["1280x800", "1280x720", "640x480"]
        for preview_size in preview_size_list:
            self.get_ref_camera_class().setSettingsButton(
                "Picture Size", preview_size)
            self.get_ref_camera_class().capturePhoto()
        self.camera_common.checkFileCorrupt(len(preview_size_list))
        result_list = self.multimedia_logcat_helper.get_logcat_data_end(
            "total fps is (.*),")
        check_logcat_data_result, error_fps = self.check_logcat_data(
            result_list, 29, 31)
        assert check_logcat_data_result, "fps error! error_fps=%s, expect_fps=%s, result_list=%s" % (
            error_fps, "29-31", result_list)

    def test_Camera_IVI_OV10635_Preview_NV21_30fps(self):
        self.test_ref_camera_check_fps("NV21")

    def test_Camera_IVI_OV10635_Preview_RGB565_30fps(self):
        self.test_ref_camera_check_fps("RGB565")

    def test_Camera_IVI_OV10635_Preview_YUY2_30fps(self):
        self.test_ref_camera_check_fps("YUY2")

    def test_Camera_IVI_OV10635_Preview_YV12_30fps(self):
        self.test_ref_camera_check_fps("YV12")

    def test_Camera_IVI_OV10635_AOSPCamera_Launch_Repeat(self):
        assert 0, "Need OV10635 senser!"
        self.check_home_or_lock_layout()
        count = 20
        for i in range(1, count + 1):
            self.logger.debug("------loop %s------" % i)
            self.get_aosp_camera_class().startCameraApp()
            self.get_aosp_camera_class().checkCameraApp()
            self.get_aosp_camera_class().stopCameraApp()
            time.sleep(3)

    def test_Camera_IVI_S3_WakeUp_AOSPCamera(self):
        self.get_rvc_camera_class().pressPowerKey(2)
        wait_time = 5 * 60
        self.logger.debug("------Wait %s s------" % str(wait_time))
        time.sleep(wait_time)
        self.get_rvc_camera_class().pressPowerKey(2)
        time.sleep(10)
        self.get_aosp_camera_class().startCameraApp()
        self.get_aosp_camera_class().stopCameraApp()

    def test_Camera_IVI_AOSP_Camera_S3_Available(self):
        self.get_aosp_camera_class().startCameraApp()
        self.get_rvc_camera_class().pressPowerKey(2)
        wait_time = 5 * 60
        self.logger.debug("------Wait %s s------" % str(wait_time))
        time.sleep(wait_time)
        self.get_rvc_camera_class().pressPowerKey(2)
        time.sleep(10)
        self.get_aosp_camera_class().checkCameraApp()
        self.get_aosp_camera_class().stopCameraApp()

    def test_Camera_IVI_AOSP_S3_WakeUp_With_DifferentTime_Interval(self):
        wait_time_list = [5 * 60, 20, 30, 5 * 60, 10 * 60]
        for wait_time in wait_time_list:
            self.get_aosp_camera_class().startCameraApp()
            self.get_rvc_camera_class().pressPowerKey(2)
            self.logger.debug("------Wait %s s------" % str(wait_time))
            time.sleep(wait_time)
            self.get_rvc_camera_class().pressPowerKey(2)
            time.sleep(10)
            self.get_aosp_camera_class().checkCameraApp()
            self.get_aosp_camera_class().stopCameraApp()

    def test_Camera_IVI_RunTime_RVC_S3_Available(self):
        self.get_rvc_camera_class().startCameraApp()
        self.get_rvc_camera_class().pressPowerKey(2)
        wait_time = 5 * 60
        self.logger.debug("------Wait %s s------" % str(wait_time))
        time.sleep(wait_time)
        self.get_rvc_camera_class().pressPowerKey(2)
        time.sleep(10)
        self.get_rvc_camera_class().stopCameraApp()

    def test_Camera_IVI_S3_WakeUp_RVC(self):
        self.get_rvc_camera_class().pressPowerKey(2)
        wait_time = 5 * 60
        self.logger.debug("------Wait %s s------" % str(wait_time))
        time.sleep(wait_time)
        self.get_rvc_camera_class().pressPowerKey(2)
        time.sleep(10)
        self.get_rvc_camera_class().startCameraApp()
        self.get_rvc_camera_class().stopCameraApp()

    def test0(self):
        self.reboot_device()

    def test1(self):
        self.multimedia_mplayer_helper = MultiMediaMplayerHelper()
        self.multimedia_checkiq_helper = MultiMediaCheckiqHelper(
            self.host_path)

        self.multimedia_mplayer_helper.play_video(
            "/home/auto1/tmp/video_20s.avi")
        time.sleep(2)
        self.multimedia_mplayer_helper.control_video(
            ["pause", "pausing seek 0 2", "frame_step"])
        self.get_aosp_camera_class().startCameraApp()
        self.get_aosp_camera_class().selectMode("Video")
        self.multimedia_mplayer_helper.control_video(["pause"])
        self.get_aosp_camera_class().recordVideo(1, 5)
        self.multimedia_mplayer_helper.close_video()
        file_info, file_name = self.check_file_corrupt()
        self.multimedia_checkiq_helper.check_video_with_barcode(file_name)

    def test2(self):
        from testlib.multimedia.multimedia_canbox_helper import MultiMediaCanboxHelper
        self.multimedia_canbox_helper = MultiMediaCanboxHelper()
        self.multimedia_canbox_helper.candump_start()
        time.sleep(3)
        self.multimedia_canbox_helper.cansend("00A#01")
        time.sleep(5)
        self.multimedia_canbox_helper.cansend("00A#00")
        time.sleep(3)
        t_str = self.multimedia_canbox_helper.candump_end()
        self.logger.debug("str=%s" % t_str)

    def test3(self):
        from testlib.graphics.common import adb32
        adb32.adb_disable_verity()
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.camera_common = CameraCommon()
        self.host_path = self.camera_common.getTmpDir()

        self.relay08_helper = Relay08Helper()
        self.multimedia_lightbox_helper = MultiMediaLightBoxHelper()
        self.multimedia_robot_helper = MultiMediaRobotHelper()
        self.multimedia_mplayer_helper = MultiMediaMplayerHelper()
        self.multimedia_checkiq_helper = MultiMediaCheckiqHelper(
            self.host_path)
        self.multimedia_high_speed_helper = MultiMediaHighSpeedCameraHelper()
        self.multimedia_high_speed_helper.clear_temp_dir()

        self.rvc_camera = ""
        self.aosp_camera = ""
        self.case_result = -1

        self.camera_common.removeDeivceFile()
        self.camera_common.removeFile(self.host_path + "/*")
        self.camera_common.unlockScreen()
        self.get_rvc_camera_class().skipAccountLoginLyout()
        self.get_rvc_camera_class().backHome()

        self.multimedia_high_speed_helper.connect()

    def tearDown(self):
        """
        @summary: tearDown
        @return: None
        """
        super(CameraTest, self).tearDown()
        self.logger.debug("[Teardown]: %s" % self._test_name)
        self.multimedia_mplayer_helper.close_video()
        self.multimedia_high_speed_helper.disconnect()
        g_common_obj.stop_exp_handle()

        if self.rvc_camera != "":
            self.rvc_camera.stopCameraApp()
        if self.aosp_camera != "":
            self.aosp_camera.cleanMediaFiles()
        self.camera_common.removeDeivceFile()
        try:
            self.multimedia_robot_helper.reset()
        except:
            self.logger.debug("tearDown multimedia_robot_helper.reset error")
        try:
            self.multimedia_lightbox_helper.turn_off_all_light()
        except:
            self.logger.debug(
                "tearDown multimedia_lightbox_helper.turn_off_all_light error")
        if self.case_result == 0:
            self.get_rvc_camera_class().reboot_device()
        time.sleep(3)
        self.get_rvc_camera_class().backHome()

    def check_file_corrupt(self, mediaFileCount=1):
        return self.camera_common.checkFileCorrupt(mediaFileCount)

    def get_rvc_camera_class(self):
        if self.rvc_camera == "":
            self.rvc_camera = MultiMediaSwitchCameraHelper().switchplatform()
        return self.rvc_camera

    def get_aosp_camera_class(self):
        if self.aosp_camera == "":
            self.aosp_camera = AOSPCamera()
        return self.aosp_camera

    def set_lightbox_operation(self,
                               light_port_list=["Power", "UV"],
                               position=-1,
                               pause=0):
        self.multimedia_lightbox_helper.press_light_with_list(light_port_list)
        if pause == 1:
            my_input()
        self.multimedia_robot_helper.move_to_default_position(position)
        time.sleep(2)

    def set_scroll_operation(self, page_num=0):
        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 check_data(self, actual_result, expect_result, percent, log_str):
        actual_result = float(actual_result)
        expect_result = float(expect_result)
        min_expect_result = int(expect_result * (1 - percent))
        max_expect_result = int(expect_result * (1 + percent))
        if min_expect_result < actual_result and actual_result < max_expect_result:
            print "%s actual_result:%s in (%s, %s)" % (
                log_str, str(actual_result), str(min_expect_result),
                str(max_expect_result))
            return 0
        else:
            print "%s actual_result:%s not in (%s, %s)" % (
                log_str, str(actual_result), str(min_expect_result),
                str(max_expect_result))
            return -1

    def test_camera_0(self):
        self.case_result = 0
        self.set_lightbox_operation()
        self.case_result = 1

    def test_camera(self):
        self.case_result = 0
        self.set_lightbox_operation()
        self.multimedia_mplayer_helper.play_video(
            "/home/auto1/tmp/video_30s.avi")
        time.sleep(2)
        self.multimedia_mplayer_helper.control_video(
            ["pause", "pausing seek 0 2", "frame_step"])
        self.get_rvc_camera_class().startCameraApp()
        self.multimedia_mplayer_helper.control_video(["pause"])
        time.sleep(1)
        jpg_folder = self.multimedia_high_speed_helper.start_capture(20)
        self.multimedia_mplayer_helper.close_video()
        self.get_rvc_camera_class().stopCameraApp()
        jpg_name_list = self.multimedia_checkiq_helper.get_barcode_list(
            jpg_folder)
        barcode_list = self.multimedia_checkiq_helper.get_barcode_with_jpg_list(
            jpg_folder, jpg_name_list)
        pass_num, error_num, actual_barcode_num_list = self.multimedia_checkiq_helper.check_barcode_list(
            barcode_list)
        print pass_num, error_num, actual_barcode_num_list
        self.case_result = 1

    def test_camera_with_cold_boot(self):
        self.case_result = 0
        #raw_input("-------------prepare complete------------")
        self.set_lightbox_operation(light_port_list=["Power", "UV"])
        self.multimedia_mplayer_helper.play_video(
            "/home/auto1/tmp/video_30s.avi")
        time.sleep(2)
        self.get_rvc_camera_class().startCameraApp()
        self.multimedia_mplayer_helper.control_video(
            ["pause", "pausing seek 0 2", "frame_step"])
        my_input()
        self.rvc_camera.pressPowerKey(5)
        time.sleep(5)
        self.rvc_camera.pressPowerKey(2)
        self.multimedia_mplayer_helper.control_video(["pause"])
        time.sleep(4)
        jpg_folder = self.multimedia_high_speed_helper.start_capture(150)
        self.multimedia_mplayer_helper.close_video()
        #self.get_rvc_camera_class().stopCameraApp()
        jpg_name_list = self.multimedia_checkiq_helper.get_barcode_list(
            jpg_folder)
        barcode_list = self.multimedia_checkiq_helper.get_barcode_with_jpg_list(
            jpg_folder, jpg_name_list)
        pass_num, error_num, actual_barcode_num_list = self.multimedia_checkiq_helper.check_barcode_list(
            barcode_list)
        self.get_rvc_camera_class().stopCameraApp()
        if pass_num == 0:
            pass_num = 1
            error_num = 1
            actual_barcode_num_list = [-1, 157]
        print pass_num, error_num, actual_barcode_num_list
        assert pass_num > 0, "can't find barcode with cold boot device"
        print "==================Result==================="
        print "First find barcode picture: %d, about %.2fs" % (
            actual_barcode_num_list[1], actual_barcode_num_list[1] / 30.0)
        self.case_result = 1

    def test_camera_with_scroll(self):
        self.case_result = 1
        self.multimedia_scroll_helper = MultiMediaScrollHelper()
        time.sleep(1)
        self.multimedia_scroll_helper.reset()
        my_input()
        self.set_lightbox_operation(light_port_list=[
            "Power", "F", "D65", "TL84", "UV", "CWF", "TL83/U30", "F", "D65",
            "TL84", "UV", "TL83/U30"
        ],
                                    position=210,
                                    pause=1)
        self.multimedia_robot_helper.rotate(-180)
        my_input()
        self.multimedia_scroll_helper.goto_page(1)
        my_input()
        self.multimedia_scroll_helper.goto_page(0)
        my_input()
        self.get_aosp_camera_class().startCameraApp()
        self.get_aosp_camera_class().capturePhoto()
        t_file = self.camera_common.getMediaFilesFromDevice(0, 1)[0]
        fisheyecorrection_folder = "/home/auto1/tmp/fisheyecorrection/fisheyecorrection/"
        subprocess.Popen("./fisheye %s" % t_file,
                         cwd=fisheyecorrection_folder,
                         shell=True)
        dest_adjusted_file = "/home/auto1/tmp/logs/adjusted.jpg"
        os.system("cp %sadjusted.jpg %s" %
                  (fisheyecorrection_folder, dest_adjusted_file))
        dest_file = dest_adjusted_file if os.path.exists(
            dest_adjusted_file) else t_file
        ret = self.multimedia_checkiq_helper.check_IQ.detectRect(dest_file)
        ret = int(ret)
        self.logger.debug("detectRect ret=%s" % ret)
        ret = self.multimedia_checkiq_helper.check_IQ.getTemp(dest_file)
        #os.system("cp /home/auto1/tmp/checkiq_temp_dir/rects.jpg /home/auto1/tmp/logs/rects.jpg")
        print "==================Result==================="
        t_result = 0
        t_result += self.check_data(ret, 6200, 0.05, "check color temperature")
        ret = CheckImage().brightness(dest_file)
        t_result += self.check_data(ret, 130, 0.15, "check brightness")
        self.get_aosp_camera_class().stopCameraApp()
        self.multimedia_scroll_helper.reset()
        #         os.system("eog -s %s" % "/home/auto1/tmp/rects_adjusted.jpg")
        os.system("eog -s %s" % dest_file)
        assert t_result == 0, "check color temperature or check brightness failed! t_result=%s" % str(
            t_result)
        self.case_result = 1

    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_Test(self):
        self.lightbox_main_test("test_camera_test")
Beispiel #8
0
class IVICameraO(IVICamera):
    HOME_PACKAGE_NAME = "com.android.car.mapsplaceholder"
    HOME_ACTIVITY_NAME = ".MapsPlaceholderActivity"
    CAMERA_CANBOX_0_SENDID = "000"
    CAMERA_CANBOX_0_SENDMESSAGE = "%s#00" % CAMERA_CANBOX_0_SENDID
    CAMERA_CANBOX_C_SENDID = "00C"
    CAMERA_CANBOX_C_SENDMESSAGE = "%s#00" % CAMERA_CANBOX_C_SENDID

    def __init__(self, cfg=None):
        super(IVICameraO, self).__init__(cfg)
        self.camera_common = CameraCommon()
        self.host_path = self.camera_common.getTmpDir()
        self.multimedia_canbox_helper = MultiMediaCanboxHelper()
        self.multimedia_checkiq_helper = MultiMediaCheckiqHelper(
            self.host_path)
        user_log_dir = g_common_obj.get_user_log_dir()
        self.before_screen_0_file_path = os.path.join(
            user_log_dir, "before_enter_camera_0_screenshot.png")
        self.after_screen_0_file_path = os.path.join(
            user_log_dir, "after_enter_camera_0_screenshot.png")
        self.before_screen_c_file_path = os.path.join(
            user_log_dir, "before_enter_camera_c_screenshot.png")
        self.after_screen_c_file_path = os.path.join(
            user_log_dir, "after_enter_camera_c_screenshot.png")
        self.now_camera_0_event = 0
        self.camera_0_event_array = [("GEAR_NEUTRAL", 0), ("GEAR_DRIVE", 0),
                                     ("GEAR_REVERSE", 1), ("GEAR_PARK", 2),
                                     ("GEAR_LOW", 0)]
        self.now_camera_c_event = 0
        self.camera_c_event_array = [("NONE", 0), ("EMERGENCY", 0),
                                     ("RIGHT", 1), ("LEFT", 1)]
        self.init_camera_with_canbox()

    class IVICameraWidget:
        def __init__(self):
            self.d = g_common_obj.get_device()

        def homeLayout(self):
            '''
            layout capture
            '''
            return self.d(packageName="com.android.car.dialer")

        def homeLayout_2(self):
            '''
            layout capture
            '''
            return self.d(packageName="com.android.car.overview")

        def homeLayout_3(self):
            '''
            layout capture
            '''
            return self.d(packageName="com.android.car.mapsplaceholder")

        def lockLayout(self):
            '''
            layout capture
            '''
            return self.d(packageName="com.google.android.apps.maps")

        def cameraLayout(self):
            '''
            layout capture
            '''
            return self.d(packageName="com.intel.rvc")

    def isHomeLayoutExists(self):
        if self.d(text="Got it").exists:
            self.d(text="Got it").click.wait()
        self.skipAccountLoginLyout()
        t_result = self.camera_common.isWidgetExists(
            self.IVICameraWidget().homeLayout())
        if not t_result:
            t_result = self.camera_common.isWidgetExists(
                self.IVICameraWidget().homeLayout_2())
        if not t_result:
            t_result = self.camera_common.isWidgetExists(
                self.IVICameraWidget().homeLayout_3())
        return t_result

    def isLockLayoutExists(self):
        return self.camera_common.isWidgetExists(
            self.IVICameraWidget().lockLayout())

    def change_canbox_0_event(self):
        self.now_camera_0_event += 1
        if self.now_camera_0_event >= len(self.camera_0_event_array):
            self.now_camera_0_event = 0
        self.multimedia_canbox_helper.cansend(
            IVICameraO.CAMERA_CANBOX_0_SENDMESSAGE)

    def change_canbox_c_event(self):
        self.now_camera_c_event += 1
        if self.now_camera_c_event >= len(self.camera_c_event_array):
            self.now_camera_c_event = 0
        self.multimedia_canbox_helper.cansend(
            IVICameraO.CAMERA_CANBOX_C_SENDMESSAGE)

    def get_screenshot(self, file_path):
        time.sleep(1)
        file_folder, file_name = os.path.split(file_path)
        self.camera_common.getScreenshotAndPullToHost(file_name, file_folder)

    def get_screenshot_and_compare_picture_similarity(self,
                                                      expect_file_path,
                                                      actual_file_path,
                                                      expect_percent=0.8):
        self.get_screenshot(actual_file_path)
        t_percent = self.multimedia_checkiq_helper.compare_picture_similarity(
            expect_file_path, actual_file_path)
        self.logger.debug(
            "get_screenshot_and_compare_picture_similarity t_percent=%s" %
            str(t_percent))
        return t_percent > expect_percent

    def reboot_device(self):
        self.pressPowerKey(10)
        time.sleep(5)
        self.pressPowerKey(2)
        time.sleep(40)
        g_common_obj.root_on_device()
        g_common_obj.remount_device()
        os.system("adb shell uiautomator dump /data/local/tmp/uidump.xml"
                  )  #get layout, 20170822 has bug, can't find layout!
        g_common_obj.adb_cmd("setprop evs.state 0")
        self.backHome()
        self.check_home_or_lock_layout()

    def init_camera_with_canbox(self):
        self.logger.debug("init_camera_with_canbox start")
        self.reboot_device()
#         self.init_camera_c_with_canbox()
#         self.get_screenshot(self.before_screen_file_path)
#         self.camera_event_array[-1]
#         for i in range(self.camera_event_count):
#             self.change_canbox_0_event()
#             time.sleep(1)
#             t_result = self.get_screenshot_and_compare_picture_similarity(self.before_screen_file_path, self.after_screen_file_path)
#             self.camera_event_array[self.now_camera_event] = (0 if t_result else 1)
#         self.logger.debug("camera_event_array=%s" % str(self.camera_event_array))
#         if sum(self.camera_event_array) > self.camera_event_count / 2:
#             for i in range(self.camera_event_count):
#                 self.camera_event_array[i] = (0 if self.camera_event_array[i]==1 else 1)
#         self.logger.debug("camera_event_array=%s" % str(self.camera_event_array))
#         assert sum(self.camera_event_array) <= 2, "fail init_camera_with_canbox!"

    def init_camera_c_with_canbox(self):
        self.logger.debug("init_camera_c_with_canbox start")
        cmd_list = [
            "stop evs_app", "stop evs_manager", "stop evs-hal-1-0",
            "start evs-hal-1-0", "start evs_manager", "start evs_app"
        ]
        for cmd in cmd_list:
            g_common_obj.adb_cmd(cmd)
            time.sleep(0.5)

    def change_camera_0_status(self, need_camera_0_status, check_success=1):
        self.logger.debug("change_camera_0_status need_camera_0_status=%s" %
                          need_camera_0_status)
        if check_success == 1:
            before_screen_0_status = self.camera_0_event_array[
                self.now_camera_0_event][1]
            self.get_screenshot(self.before_screen_0_file_path)
        i = 0
        while need_camera_0_status != self.camera_0_event_array[
                self.now_camera_0_event][0]:
            i += 1
            if i >= len(self.camera_0_event_array):
                break
            self.change_canbox_0_event()
            time.sleep(1)
        if i == 0:
            self.logger.debug("skip change camera 0 status!")
        if check_success == 1:
            time.sleep(1)
            after_screen_0_status = self.camera_0_event_array[
                self.now_camera_0_event][1]
            need_status = 1 if before_screen_0_status == after_screen_0_status else 0
            t_result = self.get_screenshot_and_compare_picture_similarity(
                self.before_screen_0_file_path, self.after_screen_0_file_path)
            assert t_result == need_status, "change_camera_0_status failed!"

    def change_camera_c_status(self, need_camera_c_status, check_success=1):
        self.logger.debug("change_camera_c_status need_camera_c_status=%s" %
                          need_camera_c_status)
        if check_success == 1:
            before_screen_c_status = self.camera_c_event_array[
                self.now_camera_c_event][1]
            self.get_screenshot(self.before_screen_c_file_path)
        i = 0
        while need_camera_c_status != self.camera_c_event_array[
                self.now_camera_c_event][0]:
            i += 1
            if i >= len(self.camera_c_event_array):
                break
            self.change_canbox_c_event()
            time.sleep(1)
        if i == 0:
            self.logger.debug("skip change camera c status!")
        if check_success == 1:
            time.sleep(1)
            after_screen_c_status = self.camera_c_event_array[
                self.now_camera_c_event][1]
            need_status = 1 if before_screen_c_status == after_screen_c_status else 0
            t_result = self.get_screenshot_and_compare_picture_similarity(
                self.before_screen_c_file_path, self.after_screen_c_file_path)
            assert t_result == need_status, "change_camera_c_status failed!"

    def startCameraApp(self, check_success=1):
        """
        Used to start the camera application
        """
        self.logger.debug("launch ivi camera start")
        self.change_camera_0_status("GEAR_REVERSE", check_success)
        if check_success == 1:
            self.logger.debug("launch ivi camera successfully")
        else:
            self.logger.debug("launch ivi camera, skip check function")

    def stopCameraApp(self):
        """
        Used to stop the camera application
        """
        self.change_camera_0_status("GEAR_NEUTRAL")
        self.logger.debug("stop ivi camera app successfully")

    def skipAccountLoginLyout(self):
        if self.d(textContains="Drive safely").exists:
            self.d(text="Owner").click()
            time.sleep(3)

    def check_home_or_lock_layout(self, check_exist=True):
        assert self.isHomeLayoutExists() or self.isLockLayoutExists(
        ), "Home or Lock layout not exist!"