예제 #1
0
    def InitEnvironmnet(self):
        if 'KratosLite' in TestSuiteConfig.HardwareType:
            try:
                #self.PowerHandler = KratosLite()
                self.PowerHandler = PTTKratoslite()

                result = self.PowerHandler.SetConfigurationFile(
                    TestSuiteConfig.ChannelConfiguration)
                #                 if result.HasError():
                #                     return result
                result = self.PowerHandler.PowerOn()
                result = self.PowerHandler.UsbOn()
                result = Adb.IsDeviceDetected()
                if result.HasError():
                    logger.info("set usb on again")
                    QcUsbSwitch.SetUsbConnection('usb_on')
                    result = Adb.IsDeviceDetected()
                    logger.info("second time: " + str(result.IsSuccess()))
                else:
                    logger.info("first time: " + str(result.IsSuccess()))
                result = Adb.SetAdbRoot()
                if result.HasError():
                    return result
                result = Adb.SetAdbRemount()
                if result.HasError():
                    return result

            except Exception as e:
                return StatusResult.Error('Failed to initialize KRATOSLITE: ',
                                          str(e))
        elif 'Kratos' in TestSuiteConfig.HardwareType:
            logger.info("----------supply with Kratos--------------")
            try:
                #self.PowerHandler = Kratos()
                self.PowerHandler = PTTKratos()
                result = self.PowerHandler.SetConfigurationFile(
                    TestSuiteConfig.ChannelConfiguration)
                #                 if result.HasError():
                #                     return result
                result = self.PowerHandler.PowerOn()
                result = self.PowerHandler.UsbOn()
            except Exception as e:
                logger.info(str(e))
                return StatusResult.Error('Failed to initialize KRATOS: ',
                                          str(e))
        elif 'Monitor' in TestSuiteConfig.HardwareType:
            try:
                self.PowerHandler = PTTPowerMonitor()
            except Exception as e:
                logger.info(str(e))
                return StatusResult.Error(
                    'Failed to initialize PowerMonitor: ', str(e))
        else:
            logger.error(
                "Can't support hardware type, please check TestSuiteConfig.HardwareType"
            )
            return
        logger.info(TestSuiteConfig.HardwareType +
                    " : initialization successful.")
        logger.info("Waiting for device ...")
        result = Adb.WaitForDevice(30)
        logger.info("wait for device ready...")
        result = AdbSettings.ReMountDevice()
        if result.HasError():
            logger.error("Unable to set root & remount privileges")
        self.Wakelock()
        self.Discharging()
        logger.info("Disable charging & Enable wakelock")
예제 #2
0
        methodString = enable
        while (True):
            result = QcUsbSwitch.SendCommandAndGetResponse(methodString)
            if not result.Status.HasError():
                break
        return result

    @staticmethod
    def SendCommandAndGetResponse(methodStrings, timeout=30):
        executionString = CommonApplicationUtilities._ToolsPath + "QcUSBSwitchTool\\QcUSBSwitchTool.exe " + methodStrings

        logger.debug("Executing Command :" + executionString)
        result = CommandLine.RunCommand(executionString, timeout)
        if (result.Status.HasError()
                or (not 'Success' in result.CmdResult.Output)):
            logger.error(result.CmdResult.Output)
            result.Status.AddError(result.CmdResult.Output)

        return result


if __name__ == '__main__':
    for i in range(10):
        QcUsbSwitch.SetUsbConnection('usb_on')
        result = Adb.IsDeviceDetected()
        logger.info("first time: " + str(result.IsSuccess()))
        if result.HasError():
            logger.info("set usb on again")
            QcUsbSwitch.SetUsbConnection('usb_on')
            result = Adb.IsDeviceDetected()
            logger.info("second time: " + str(result.IsSuccess()))