class LabNfcDualPhoneBeamTransfert(LabNfcBase):

    # the name of ref phone is the name in BENCH_CONFIG file
    REF_PHONE = "PHONE2"

    def __init__(self, tc_name, global_config):
        LabNfcBase.__init__(self, tc_name, global_config)

        # second phone init
        self._phone_ref = DeviceManager().get_device(
            LabNfcDualPhoneBeamTransfert.REF_PHONE)
        self._phone_ref.connect_board()

        # Check if we have the ref phone available
        if self._phone_ref is not None:
            if not self._phone_ref.is_available():
                DeviceManager().boot_device(
                    LabNfcDualPhoneBeamTransfert.REF_PHONE)
            self._nfc_api_phone_ref = self._phone_ref.get_uecmd(
                "LocalConnectivity")

        # get PhoneSystem uecmd instance for the ref phone
        self._phonesystem_api_dut = self._device.get_uecmd("PhoneSystem")
        self._phonesystem_api_ref = self._phone_ref.get_uecmd("PhoneSystem")

        self._appmgmt_api = self._phone_ref.get_uecmd("AppMgmt")
        # get file uecmd instance
        self._file_api_dut = self._device.get_uecmd("File")
        self._file_api_ref = self._phone_ref.get_uecmd("File")

        # Get NFC Tags application package name
        self._tag_app = str(self._dut_config.get("TagsAppPackageName"))
        # Get Browsers application package name (need to disable in order to be able to read URI tags)
        self._browser_app = str(self._dut_config.get("BrowserAppPackageName"))
        self._chrome_app = str(self._dut_config.get("ChromeAppPackageName"))

        # force phone 2 state unlock and display on
        # for the DUT this is made in LiveNfcBase class
        self._phonesystem_api_ref.display_on()
        self._phonesystem_api_ref.set_phone_lock(0)
        self._nfc_api_phone_ref.force_nfc_state(1)

        # BE careful here we have to be sure that the file is here (setup embbeded)
        self.__file_to_share = str(
            self._tc_parameters.get_param_value("FILE_TO_SHARE"))

        self.__beam_duration = int(
            self._tc_parameters.get_param_value("BEAM_DURATION"))
        self.__direction = str(
            self._tc_parameters.get_param_value("DIRECTION")).upper()

        self._nfc_robot_param = global_config.benchConfig.get_parameters(
            "NFC_ROBOT1")
        self._beam_path = self._tc_parameters.get_param_value("BEAM_PATH")

        # get ref phone position
        self.__ref_phone_position = self._tc_parameters.get_param_value(
            "REF_PHONE_POSITION")

        self._tag_up = self._nfc_robot_param.get_param_value(
            self.__ref_phone_position + "Up")
        self._tag_down = self._nfc_robot_param.get_param_value(
            self.__ref_phone_position + "Down")
        self._tag_X = self._nfc_robot_param.get_param_value(
            self.__ref_phone_position + "X")
        # get the antenna position
        antenna_position = self._device.get_config("NfcAntennaPosition")
        self._tag_Y = str(
            int(
                self._nfc_robot_param.get_param_value(
                    self.__ref_phone_position + "Y")) +
            int(antenna_position.split(",")[1]))

    # ----------------------------------------------------------------------------------------------

    def set_up(self):

        LabNfcBase.set_up(self)
        # dont need to check if BEAM activated because of the parameters
        # self._Device is DUT
        # self._phone_ref is the reference phone
        # disable "Tags" and browsers built-in apps

        # In DUT
        self._appmgmt_api.app_enable_disable(self._tag_app, False)
        self._appmgmt_api.app_enable_disable(self._browser_app, False)
        self._appmgmt_api.app_enable_disable(self._chrome_app, False)
        # in phone ref
        self._appmgmt_api.app_enable_disable(self._tag_app, False)
        self._appmgmt_api.app_enable_disable(self._browser_app, False)
        self._appmgmt_api.app_enable_disable(self._chrome_app, False)
        self.__size_of_file = 0
        # file have to be in both device, and get its size
        file_exist, result = self._file_api_dut.exist(
            posixpath.join(self._device.multimedia_path, self.__file_to_share))
        if file_exist:
            size = self._file_api_dut.size(
                posixpath.join(self._device.multimedia_path,
                               self.__file_to_share))
            self.__size_of_file = size
        else:
            msg = "File to transfert missing on DUT "
            raise AcsConfigException(AcsConfigException.FILE_NOT_FOUND, msg)
        size = 0
        file_exist, result = self._file_api_ref.exist(
            posixpath.join(self._device.multimedia_path, self.__file_to_share))
        if file_exist:
            size = self._file_api_ref.size(
                posixpath.join(self._device.multimedia_path,
                               self.__file_to_share))
            if size != self.__size_of_file:
                msg = "File to share are different size on DUT and reference phone"
                raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                         msg)
        else:
            msg = "File to transfert missing on reference phone "
            raise AcsConfigException(AcsConfigException.FILE_NOT_FOUND, msg)

        return Global.SUCCESS, "No errors"

    # ----------------------------------------------------------------------------------------------

    def run_test(self):

        msg = "No errors"

        # move robot to start position
        self._robot_positioning(self._tag_X, self._tag_Y, self._tag_up, 'null')

        # do the DUT to ref phone transfert
        if "SEND" or "FULL" in self.__direction:
            # starting beam sequence with DUT
            self.__beam_sequence(self._device)
            if not self.__is_transfert_ok(self._file_api_ref):
                msg = "Error : send BEAM failed on %s sequence" % self.__direction
        # clear beamed files
        self.__clear_beam_sequence()
        time.sleep(5)
        # do the ref phone to DUT transfert
        if "RECEIVE" or "FULL" in self.__direction:
            # starting beam sequence with phone ref
            self.__beam_sequence(self._phone_ref)
            if not self.__is_transfert_ok(self._file_api_dut):
                msg += "Error : receive BEAM failed on %s sequence" % self.__direction
        # clear beamed files
        self.__clear_beam_sequence()

        if msg != "No errors":
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        return Global.SUCCESS, msg

    # ----------------------------------------------------------------------------------------------

    def tear_down(self):
        # move robot to start position
        self._robot_positioning(self._tag_X, self._tag_Y, self._tag_up, 'null')
        LabNfcBase.tear_down(self)

        return Global.SUCCESS, "No errors"

    # ----------------------------------------------------------------------------------------------

    def __is_transfert_ok(self, device_system_api):
        file_exist, result = device_system_api.exist(
            posixpath.join(self._beam_path, self.__file_to_share))
        if file_exist:
            size = device_system_api.size(
                posixpath.join(self._beam_path, self.__file_to_share))
            if size == self.__size_of_file:
                return True
            else:
                return False

    # ----------------------------------------------------------------------------------------------

    def __clear_beam_sequence(self):
        # clear beamed files on both devices
        self._file_api_dut.delete(
            posixpath.join(self._beam_path, self.__file_to_share))
        self._file_api_ref.delete(
            posixpath.join(self._beam_path, self.__file_to_share))
        return True

    # ----------------------------------------------------------------------------------------------

    def __open_image(self, device, file_to_open):
        cmd = "adb shell am start -d file:%s -t image/* -a android.intent.action.VIEW -n com.google.android.gallery3d/com.android.gallery3d.app.GalleryActivity" % str(
            file_to_open)
        device.run_cmd(cmd, 10)
        return True

    # ----------------------------------------------------------------------------------------------

    def __close_image(self, device):
        # close image
        cmd = "adb shell pm clear com.google.android.gallery3d"
        device.run_cmd(cmd, 10)
        time.sleep(1)
        return True

    # ----------------------------------------------------------------------------------------------

    def __beam_sequence(self, beamer):
        # first open photo on the beamer
        # DEBUG try to use an uecmd instead like start_display_image
        self._logger.info("Start to BEAM")
        self.__open_image(
            beamer, posixpath.join(beamer.multimedia_path,
                                   self.__file_to_share))
        # move nfc bot
        self._robot_positioning('null', 'null', self._tag_down, 'null')
        # wait a while
        time.sleep(2)

        if beamer.get_config("device_name") == "PHONE1":
            res = self._phonesystem_api_dut.get_screen_resolution().split("x")
            mres = "%dx%d" % (int(res[0]) / 2, int(res[1]) / 2)
            self._nfc_api.nfc_touch_to_beam(mres, 1)
        else:
            res = self._phonesystem_api_ref.get_screen_resolution().split("x")
            mres = "%dx%d" % (int(res[0]) / 2, int(res[1]) / 2)
            self._nfc_api_phone_ref.nfc_touch_to_beam(mres, 1)
        time.sleep(2)
        self._robot_positioning('null', 'null', self._tag_up, 'null')
        time.sleep(self.__beam_duration)
        # close gallery application
        self.__close_image(beamer)
Пример #2
0
class AndroidUiTestVcMt(AndroidUiTest):
    """
    Android UI test mobile terminated voice call class.
    This use case will permit to launch UI test on DUT.
    The PHONE2 will be used in application framework level to make a voice call.
    """
    def __init__(self, tc_name, global_config):
        """
        Constructor
        """

        # Call Android UI test use case base Init function
        AndroidUiTest.__init__(self, tc_name, global_config)

        #
        self._phone_number = \
            str(self._device.get_phone_number())

        # Read callSetupTimeout from Device_Catalog.xml
        self._call_setup_time = \
            int(self._dut_config.get("callSetupTimeout"))

        # Get UECmdLayer
        self._phone2 = DeviceManager().get_device("PHONE2")
        if self._phone2 is not None:
            self._voice_call_api2 = self._phone2.get_uecmd("VoiceCall")

    def set_up(self):
        """
        Set up the test configuration
        """
        # Call Android UI test use case base Setup function
        verdict, msg = AndroidUiTest.set_up(self)
        if verdict != Global.SUCCESS:
            return verdict, msg

        # Check if we have the second phone available
        if self._phone2 is None:
            # We are using this multi UC with only one phone
            return Global.FAILURE, "Cannot run that use case with only one phone configured."

        # Boot the other phone (the DUT is already booted)

        if self._phone2.get_state() != "alive":
            # We are using this multi UC with an phone2 is not available
            return Global.FAILURE, "Ref phone not available (power off ?), please check your bench."

        if not self._phone2.is_available():
            self._phone2.connect_board()

        return Global.SUCCESS, "No error"

    def run_test(self):
        """
        Execute the test
        """
        self._logger.info("")
        self._logger.info("%s: RunTest", self._name)
        self._logger.info("")

        # Phone 2 : Release any previous call (Robustness)
        time.sleep(self._wait_btwn_cmd)
        self._voice_call_api2.release()

        # Phone2 : Dial without checking call state (Non Blocking)
        time.sleep(self._wait_btwn_cmd)
        self._voice_call_api2.dial(self._phone_number, False)

        # Phone1 : Call AndroidUiTest run test
        return AndroidUiTest.run_test(self)
class LiveSystemSleepResidencyMeasurement(SystemSleepBase):
    """
    Sleep mode residency measurement class.
    """
    def __init__(self, tc_name, global_config):
        """
        Constructor

        :type tc_name: BaseConf
        :param tc_name: Configuration of the usecase

        :type global_config: Dictionary
        :param global_config: Global configuration of the campaign
        """

        # Call UseCase base constructor
        self._device = DeviceManager().get_device("PHONE1")

        self.__adbConnectionTimeout = self._device.get_config(
            "adbConnectTimeout", 30, float)
        self._device_uptime_begin = None
        self._sleep_duration = None

        # If the device was disconnected before due to an error
        # we must reconnect it explicitly at the beginning of the test
        # else some commands will not be executed and the test will be blocked
        self._system_api = self._device.get_uecmd("System")
        return_code = self._system_api.wait_for_device(
            self.__adbConnectionTimeout)
        if not return_code:
            time.sleep(30)

        if not self._device.is_available():
            self._device.connect_board()

        # Call SystemSleepBase base Init function
        SystemSleepBase.__init__(self, tc_name, global_config)

        self._report_tree = global_config.campaignConfig.get(
            "campaignReportTree")
        self._sysdebug_apis = self._device.get_uecmd("SysDebug")

        self._tc_name = os.path.basename(self.get_name())
        self._tc_date = ""
        attributes = {"id": self._tc_name, "date": self._tc_date}

        self.__results = PnPResults(self._report_tree,
                                    self._dut_config.get("Name"),
                                    self._failure_file, None, attributes)

    def run_test(self):
        """
        Execute the test
        """

        sysdbg_modules_config = self._tc_parameters.get_param_value(
            "SYSDEBUG_MODULES")
        self._sysdebug_apis.init(sysdbg_modules_config)

        sleep_parameter = self._tc_parameters.get_param_value("SLEEP_DURATION")
        if sleep_parameter is not None and sleep_parameter != "" and sleep_parameter.isdigit(
        ):
            self._sleep_duration = int(sleep_parameter)

        # Call live sleep use case base
        SystemSleepBase.run_test(self)

        self._tc_date = time.strftime("%Y-%m-%d %H:%M:%S")
        self.__results.update({"date": self._tc_date})

        while not self._sysdebug_apis.synchronize():
            time.sleep(10)

        adbConnectTimeout = self._device.get_config("adbConnectTimeout", 10,
                                                    float)
        usbReplugRetries = self._device.get_config("usbReplugRetries", 1, int)

        if self._io_card is not None:
            self._device.disconnect_board()
            self._sysdebug_apis.reset()  # will clear mid_pmu_states
            self._residency_api.clear(
                self._sleep_duration)  # will also clear mid_pmu_states
            # but this is needed to do the fetch on this instance
            self._io_card.usb_host_pc_connector(False)
            # Unplug wall charger only if it is AC_CHGR
            if self._device.get_default_wall_charger(
            ) == self._io_card.AC_CHGR:
                self._io_card.wall_charger_connector(False)

        # Update device uptime
        updated, self._device_uptime_begin = self._device._update_device_up_state(
            0)
        if not updated:
            self._device_uptime_begin = None

        if self._sleep_duration:
            self._logger.info(
                "Wait for %s s before measurement (sleep duration before %s)" %
                (str(self._sleep_duration), self._sleep_mode))
            time.sleep(self._sleep_duration)

        self._sysdebug_apis.start()
        self._logger.info("Wait for %s s to enter in %s" %
                          (str(self._duration), self._sleep_mode))
        time.sleep(self._duration)
        self._sysdebug_apis.stop()

        residency_spent = 0
        ret_code = None

        if self._io_card is not None:
            for cnt in range(0, usbReplugRetries + 1):
                self._logger.debug("Loop Iteration: %d" % cnt)
                # plug wall charger only if it is AC_CHGR
                if self._device.get_default_wall_charger(
                ) == self._io_card.AC_CHGR:
                    self._io_card.wall_charger_connector(True)
                self._io_card.usb_host_pc_connector(True)

                self._logger.debug("Wait for device %s seconds" %
                                   self.__adbConnectionTimeout)
                ret_code = self._system_api.wait_for_device(
                    self.__adbConnectionTimeout)
                self._logger.debug("Wait for device return code: %s" %
                                   ret_code)
                if not ret_code:
                    if cnt < usbReplugRetries:
                        self._logger.warning(
                            "timeout on wait-for-device, trying to unplug/replug (try %s/%s)"
                            % (str(cnt + 1), str(usbReplugRetries)))
                        self._io_card.usb_host_pc_connector(False)
                        # Unplug wall charger only if it is AC_CHGR
                        if self._device.get_default_wall_charger(
                        ) == self._io_card.AC_CHGR:
                            self._io_card.wall_charger_connector(False)
                        time.sleep(10)
                    continue

                residency_spent = self._residency_api.get_value(
                    "residency", self._sleep_mode_api.get_sleep_mode())
                self._sysdebug_apis.fetch()
                self._device.connect_board()
                self._logger.debug("device retrieved after %s tries" %
                                   str(cnt + 1))
                break

            if not ret_code:
                raise DeviceException(
                    DeviceException.OPERATION_FAILED,
                    "Could not retrieve the device after %s plug/unplug cycles"
                    % str(usbReplugRetries))

        if residency_spent is None:
            raise DeviceException(
                DeviceException.INVALID_PARAMETER,
                "There is no %s sleep mode for this device model" %
                self._sleep_mode_api.get_sleep_mode())

        # Get device uptime and raise an exception if the device rebooted
        if self._device_uptime_begin:
            updated, uptime = self._device._update_device_up_state(
                self._device_uptime_begin)
            if updated and not self._device.is_up:
                self._logger.warning(
                    "the device uptime was %s before the measurement, %s now !"
                    % (str(self._device_uptime_begin), str(uptime)))
                raise DeviceException(
                    DeviceException.OPERATION_FAILED,
                    "Device rebooted during the measurement")

        sysreport = self._sysdebug_apis.report()
        self.__results.append(sysreport)
        self.__results.write()

        return self._residency_verdict(residency_spent)