コード例 #1
0
ファイル: demo.py プロジェクト: zenghui0-0/tempfile
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.light_port = "0"
        self.file_index = 0
        self.test_object = 0
        print "[Setup]: %s" % self._test_name

    def tearDown(self):
        """
        @summary: tearDown
        @return: None
        """
        if self.light_port!="0":
            self.deviceControl.pressLightBoxButton(self.light_port)
            self.deviceControl.pressLightBoxButton("1")
        if self.test_object!=0:
            #return to the first picture
            pass
        super(CameraTest, self).tearDown()
        print "[Teardown]: %s" % self._test_name
        g_common_obj.stop_exp_handle()
        time.sleep(3)

    def appPrepare(self,):
#         cfg_file = os.path.join(os.environ.get('TEST_DATA_ROOT', ''), \
#             'tests.testplan.camera.conf')
#         current_platform = CameraCommon().getPlatform()
#         self.camera = GMSCamera(self.config.read(cfg_file, "multimedia_camera"))
        #self.camera = ArcSoftCamera(self.config.read(cfg_file, "multimedia_camera"))
        self.camera = CameraCommon().switchPlatform()
        self.multimedia_setting = MultiMediaSetting(CameraCommon().DEFAULT_CONFIG_FILE)
        self.video = CheckVideo()
        self.checkImage = CheckImage()
        self.deviceControl = DeviceControl()
        self.host_path = CameraCommon().getTmpDir()
        self.makefileTime = CameraCommon().makefileTime
        self.camera_dir = CameraCommon().camera_dir
        CameraCommon().removeDeivceFile()
        CameraCommon().removeFile(self.host_path + "/*")
        self.camera.cleanMediaFiles()
        #CameraCommon().setOrientationToVertical()
        self.logger.debug("app prepare successfully")

#     def switchplatform(self, platform, cfg_file):
#         platform_list1 = self.camera.cfg.get("platform1").split(';')
#         platform_list2 = self.camera.cfg.get("platform2").split(';')
#         if platform in platform_list1:
#             self.camera = ArcSoftCamera(self.config.read(cfg_file, "multimedia_camera"))
#             self.logger.debug("the platform is %s" % platform)
#             self.multimedia_setting = MultiMediaSetting(cfg_file)
#             self.multimedia_setting.install_apk("quickpic_apk")
#         if platform in platform_list2:
#             self.camera = AOSPCamera(self.config.read(cfg_file, "multimedia_camera"))
#             self.logger.debug("the platform is %s" % platform)
#         self.multimedia_setting.install_apk("alarm_apk")
#         self.multimedia_setting.install_apk("gps_apk")

    def checkFileCorrupt(self, mediaFileCount=1, checkSim=False):
        file_name_list = CameraCommon().pullFileAndCheckFileNumber(self.camera_dir, self.host_path, mediaFileCount)
        for i in range(len(file_name_list)):
            self.path = self.host_path + "/" + file_name_list[i]
            for j in range(10):
                if not CameraCommon().checkFile(self.path):
                    CameraCommon().adbPullFile(self.camera_dir + file_name_list[i], self.host_path)
                    time.sleep(2)
                else:
                    self.logger.debug(str(file_name_list[i]) + " exists")
                    break
                time.sleep(2)
            self.path = self.host_path + "/" + file_name_list[i]
            os.system("cp "+self.path+" "+g_common_obj.get_user_log_dir())
            self.logger.debug("===picture path="+g_common_obj.get_user_log_dir()+"/"+file_name_list[i]+"===")
            if checkSim:
                panaFile = g_common_obj.get_user_log_dir()+"/"+file_name_list[i]
                self.logger.debug("===compare "+panaFile+" with the pano1.jpg====")
                #os.environ['LD_LIBRARY_PATH'] = "/lib:/usr/lib:/usr/local/lib"
                #os.putenv('LD_LIBRARY_PATH', "/lib:/usr/lib:/usr/local/lib")
                #currentDir = os.path.abspath(os.path.dirname(__file__))
                #cmd = currentDir+os.sep+"GASServer "+currentDir+"/pano1.jpg "+panaFile
                #import subprocess
                #output=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).communicate()
                #self.logger.debug(output[0][:-1])
                #s=output[0][:-1].split("\n")[2]
                #percent=int(s.split(" ")[2].split("%")[0])
                #if percent < 30:
                #    assert False, "similar checking result < 30% Fail! "+panaFile+" is not similar with pano1.jpg"
                #else:
                #    self.logger.debug("similar checking result > 30% Pass!")
            str_name = file_name_list[i].split('.')
            suffix = str_name[1]
            if not suffix:
                assert False, "file name without the suffix"
            if suffix == "jpg":
                errMsg = self.checkImage.check_image_corrupt(self.path)
                if errMsg != "":
                    assert False, errMsg
                else:
                    self.info = CameraCommon().getExifInfo(file_name_list[i], self.host_path + "/")
                    self.logger.debug("picture validation successful")
                continue
            elif suffix == "mp4" or suffix == "3gp":
                if self.video.check_video_corrupt(self.path):
                    self.info = CameraCommon().getExifInfo(file_name_list[i], self.host_path + "/")
                    self.logger.debug("video validation successful")
                else:
                    self.logger.debug("video validation fails")
#             self.removeFile(self.host_path + "/*")
#         self.removeDeivceFile()
        return self.info, file_name_list[0]

    def flashTest(self):
        try:
            self.appPrepare()
            self.camera.startCameraApp()
            self.camera.selectMode("Camera")
            self.camera.switchRearOrFront("Back")
            self.camera.setFlash("on")
            #If light box is ready, here should set flash to auto and set dark light first and then set bright light
            self.camera.capturePhoto(1)
            time.sleep(1)
            ret = self.checkFileCorrupt(1)
            fileName = ret[1]
            flashInfo = ret[0].get("Flash")
            self.logger.info("===fileName=%s, flashInfo=%s" %(fileName, flashInfo))
            CameraCommon().moveFilesFromCameraFolder()
            self.camera.setFlash("off")
            self.camera.capturePhoto(1)
            time.sleep(1)
            ret=self.checkFileCorrupt(1)
            fileName = ret[1]
            flashInfo = ret[0].get("Flash")
            self.logger.info("===fileName=%s, flashInfo=%s" %(fileName, flashInfo))
            CameraCommon().recoverFilesFromCameraTemp()
        except Exception as e:
            CameraCommon().checkCameraCrash()
            self.assertTrue(False, e)

    def panoramaTest(self):
        try:
            self.appPrepare()
            self.camera.startCameraApp()
            self.camera.selectMode("Panorama")
            self.camera.capturePanorama()
            self.checkFileCorrupt(1, True)
        except Exception as e:
            CameraCommon().checkCameraCrash()
            self.assertTrue(False, e)
            
    def zoomDemo(self):
        #print CameraCommon().getTestEntryName()
        #return 
        self.appPrepare()
        mlist = self.deviceControl.getZoomCommands()
        
        self.camera.startCameraApp()
        self.camera.selectMode("Camera")
        CameraCommon().clickScreenCenter()
        self.camera.capturePhoto()
        time.sleep(2)
        ori_name = self.checkFileCorrupt()[1]
        CameraCommon().removeDeivceFile()
        print ori_name, mlist[0], mlist[1]
        ori_name = self.host_path + "/" + ori_name
        zoom_name = CameraCommon().zoomInOrOut(self.camera, mlist[0])[0]
        print ori_name,zoom_name
#         file1 = "/data/debug/zoom/zoom/3gr/IMG_20160323_125326.jpg"
#         file2 = "/data/debug/zoom/zoom/3gr/IMG_20160323_125403.jpg"
        checkZoom = CheckZoom()
#         self.assertTrue(checkZoom.checkZoomEffect(file1, file2), "Zoom effect is not correct")
        self.assertTrue(checkZoom.checkZoomEffect(ori_name, zoom_name), "Zoom effect is not correct")

    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 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) 
    
    def testPanorama(self):
        self.panoramaTest()

    def testFlash(self):
        #self.zoomDemo() 
        self.flashTest()

    def test_Camera_Zoom(self):
        #self.appPrepare()
        #localPath = CameraCommon().getTmpDir()
        #checkIQ = CheckIQ("", localPath)
        #self.benchTest1()
        self.zoomDemo()
コード例 #2
0
ファイル: cameraBench.py プロジェクト: zenghui0-0/tempfile
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")