def press_key_combo(self, keycombo_list, raise_exception=False, push_delay=RELAY_PUSH_DELAY, release_delay=RELAY_RELEASE_DELAY): """ Forward call to equipment to press key combo :type keycombo_list: str :param keycombo_list: list of button to press on :type raise_exception: bool :param raise_exception: raise exception if equipment is not defined for this function :type push_delay: float :param push_delay: delay between button push :type release_delay: float :param release_delay: delay between button release """ io_card = self.__get_iocard(raise_exception) keyboard_emulator = self.__get_keyboard_emulator(raise_exception) keycombo_list = split_and_strip(keycombo_list, ';') for keycombo in keycombo_list: # Button list shall be defined as follow: 'BUTTON1+BUTTON2,PRESS_DURATION' press_duration = "" if len(keycombo.split(',')) > 1: # button_list = BUTTON1+BUTTON2 # press_duration = PRESS_DURATION button_list, press_duration = split_and_strip(keycombo, ',') else: # If NO PRESS_DURATION ,set a default duration button_list = keycombo press_duration = float(press_duration) if press_duration else 1.0 # In case button list contains keyboard input : 'KEYBOARD:fffff,1' if "KEYBOARD:" in button_list: if keyboard_emulator: keyboard_input = button_list.replace("KEYBOARD:", "") for char in keyboard_input: keyboard_emulator.write_keys(char) time.sleep(press_duration) else: # In other case button list can be : 'POWER_BUTTON+VOLUME_UP,5' or 'VOLUME_DOWN,1' if io_card: io_card.press_key_combo(split_and_strip(button_list, '+'), press_duration, push_delay=push_delay, release_delay=release_delay) # WARNING ! Keyboard input and button cannot be mixed as follow: KEYBOARD:f+VOLUME_UP+POWER_BUTTON,5 # In this case you should separate commands: KEYBOARD:f,0.2;VOLUME_UP+POWER_BUTTON,5 return True
def run(self, context): """ Runs the test step @type context: TestStepContext @param context: test case context """ BtBase.run(self, context) if not isinstance(self._pars.timeout, int): msg = "Error parameter TIMEOUT is not integer : %s" % str( type(self._pars.timeout)) self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) button_list = split_and_strip(self._pars.buttons, ",") for key in button_list: if key not in ["PLAY", "PAUSE", "STOP", "FORWARD", "BACKWARD"]: msg = "Error parameter BUTTONS contains invalid value : %s" % key self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) full_path = posixpath.join(self._device.multimedia_path, \ self._pars.filename) self._api.avrcp_expect_buttons(self._pars.buttons, \ self._pars.timeout, \ full_path)
def run(self, context): """ Runs the test step :type context: TestStepContext :param context: test case context """ BtBase.run(self, context) multimedia_path = self._device.multimedia_path address = self._pars.bdaddr # Split the file names and strip each of them file_list = split_and_strip(self._pars.files, Constants.FILE_NAME_SEPARATOR) fullpath_filenames, file_size = self._process_files( multimedia_path, file_list, False) self._api.bt_opp_clean_notification_list() self._save_file_size_if_needed(file_size, context) self._save_file_chksum_if_needed(multimedia_path, file_list, context) # Request for the First transfer to be registered self._api.bt_opp_send_file(fullpath_filenames, address)
def run(self, context): """ Runs the test step @type context: TestStepContext @param context: test case context """ WifiBase.run(self, context) # get timeout if any timeout = self._pars.timeout if timeout: self._timeout = timeout self._logger.info( "Timeout set to {0} for setting wifi power".format(timeout)) # Get the power sequence (it might just be one single operation) power = str(self._pars.power).lower() power_sequence = split_and_strip(power, self.STR_SEPARATOR) for current in power_sequence: assert current.lower() in [TestConst.STR_ON, TestConst.STR_OFF], \ "passed value (%s) is invalid at this stage" % current self._logger.info("Powering %s the Wifi interface" % current) self._api.set_wifi_power(current) self._wait_until_state_is_reached(current)
def run(self, context): """ Runs the test step :type context: TestStepContext :param context: test case context """ BtBase.run(self, context) power = str(self._pars.power).lower() # # Get the power sequence (it might just be one single operation) power_sequence = split_and_strip(power, self.STR_SEPARATOR) for current in power_sequence: assert current in [TestConst.STR_ON, TestConst.STR_OFF], \ "passed value (%s) is invalid at this stage" % current self._logger.info("Power %s the Bluetooth tethering" % current) self._api.set_bt_tethering_power(current) if current == TestConst.STR_ON and self._api.get_bt_tethering_power( ) != True: self._raise_device_exception("set BT tethering ON failure") if current == TestConst.STR_OFF and self._api.get_bt_tethering_power( ) != False: self._raise_device_exception("set BT tethering OFF failure")
def run(self, context): """ Runs the test step :type context: TestStepContext :param context: test case context """ BtBase.run(self, context) power = str(self._pars.power).lower() # # Get the power sequence (it might just be one single operation) power_sequence = split_and_strip(power, self.STR_SEPARATOR) for current in power_sequence: assert current in [TestConst.STR_ON, TestConst.STR_OFF], \ "passed value (%s) is invalid at this stage" % current self._logger.info("Power %s the Bluetooth adapters" % current) self._api.set_bt_power(current) state_bt = self._api.get_bt_power_status() if (current == TestConst.STR_ON) and (state_bt != str( BT_STATE.STATE_ON)): self._raise_device_exception("set BT ON failure") if (current == TestConst.STR_OFF) and (state_bt != str( BT_STATE.STATE_OFF)): self._raise_device_exception("set BT OFF failure")
def run(self, context): """ Runs the test step @type context: TestStepContext @param context: test case context """ NFCBase.run(self, context) # Get the power sequence (it might just be one single operation) power = str(self._pars.power).lower() power_sequence = split_and_strip(power, self.STR_SEPARATOR) for current in power_sequence: assert current.lower() in [self.STR_NFC_ON, self.STR_NFC_OFF], \ "passed value (%s) is invalid at this stage" % current self._logger.info("Powering %s the NFC interface" % current) if current == self.STR_NFC_ON: self._api.nfc_enable() else: self._api.nfc_disable() self._wait_until_state_is_reached(str(current).upper())
def _remove_files_if_needed(self): """ Remove files from the storage if files attribute exists """ if self._pars.remove_files: file_list = split_and_strip(self._pars.files, Constants.FILE_NAME_SEPARATOR) for file_name in file_list: self._api.bt_opp_init(file_name)
def set_info(self, key, info): """ Set an info associated to key. If key doesn't exist in the collection a new item gets created. Otherwise the object associated to key gets updated :type key: str :param key: the context info ID (it can be a complex key such as "key:subkey") """ keys = split_and_strip(key, self.KEY_SEPARATOR) self.set_nested_info(keys, info)
def get_info(self, key): """ Returns the context info associated to key :type key: str :param key: the context info ID (it can be a complex key such as "key:subkey") :rtype: object :return: the data associated to key """ keys = split_and_strip(key, self.KEY_SEPARATOR) return self.get_nested_info(keys)
def run(self, context): """ Execute the test step @see BtHeadSetBase """ HeadSetBase.run(self, context) assert self._pars.state, "STATE parameter should have been checked by the framework and be valid at this point" for state in split_and_strip(self._pars.state.lower(), self.STR_SEPARATOR): self._do_set_power(state)
def run(self, context): """ Runs the test step :type context: TestStepContext :param context: test case context """ BtBase.run(self, context) if self._pars.timeout is not None: timeout = self._pars.timeout else: timeout = self.DEFAULT_TIMEOUT # Split the file names and strip each of them file_list = split_and_strip(self._pars.files, Constants.FILE_NAME_SEPARATOR) self._api.bt_opp_cancel_send()
def run(self, context): """ Runs the test step @type context: TestStepContext @param context: test case context """ CellularBase.run(self, context) # Get the power sequence (it might just be one single operation) power = str(self._pars.power).lower() power_sequence = split_and_strip(power, self.STR_SEPARATOR) for current in power_sequence: assert current.lower() in [TestConst.STR_ON, TestConst.STR_OFF], \ "passed value (%s) is invalid at this stage" % current self._logger.info("Powering %s the Cellular interface" % current) self._modem_api.set_modem_power(current) self._wait_until_state_is_reached(current)
def run(self, context): """ Runs the test step :type context: TestStepContext :param context: test case context """ BtBase.run(self, context) if self._pars.timeout is not None: timeout = self._pars.timeout else: timeout = self.DEFAULT_TIMEOUT # Split the file names and strip each of them file_list = split_and_strip(self._pars.files, Constants.FILE_NAME_SEPARATOR) if self._pars.expected_state == self._STATUS_ACCEPTED: if not opp_accept_file(self._api, file_list[0], timeout): msg = "remote device has not accepted the file on time" raise DeviceException(DeviceException.OPERATION_FAILED, msg) elif self._pars.expected_state == self._STATUS_CANCELED: if not opp_check_file_cancelled(self._api, file_list[0], timeout): msg = "remote device has not canceled the file on time" raise DeviceException(DeviceException.OPERATION_FAILED, msg) elif self._pars.expected_state == self._STATUS_WAITING_ACCEPT: if not opp_check_file_waiting_accept(self._api, file_list[0], timeout): if not opp_accept_file(self._api, file_list[0], timeout): msg = "remote device has not initiated the transfer on time" raise DeviceException(DeviceException.OPERATION_FAILED, msg) elif self._pars.expected_state == self._STATUS_NONE: if not opp_check_status_none(self._api, timeout): msg = "remote device has a status different than none for a type it should not consider" raise DeviceException(DeviceException.OPERATION_FAILED, msg)
def run(self, context): """ Runs the test step. The Accept command is implicitly included in the bt_opp_check_service command :type context: TestStepContext :param context: test case context """ BtBase.run(self, context) if self._pars.timeout is not None: timeout = self._pars.timeout else: timeout = self.DEFAULT_TIMEOUT # Split the file names and strip each of them file_list = split_and_strip(self._pars.files, Constants.FILE_NAME_SEPARATOR) if not opp_accept_file(self._api, file_list[0], timeout): msg = "remote device has not accepted the file on time" raise DeviceException(DeviceException.OPERATION_FAILED, msg)
def run(self, context): """ Runs the test step :type context: TestStepContext :param context: test case context """ BtBase.run(self, context) if self._pars.timeout is not None: timeout = self._pars.timeout else: timeout = self.DEFAULT_TIMEOUT # Split the file names and strip each of them file_list = split_and_strip(self._pars.files, Constants.FILE_NAME_SEPARATOR) self._api.bt_opp_reject_file() if not opp_check_file_cancelled(self._api, file_list[0], timeout): msg = "remote device has not rejected the file on time" raise DeviceException(DeviceException.OPERATION_FAILED, msg)
def _do_run(self, context): """ Executes the run logic """ BtBase.run(self, context) self._setup_timeout_value() self._logger.info( "File transfer is supposed to complete in %d seconds" % self._time_out) file_names = split_and_strip(self._pars.files, Constants.FILE_NAME_SEPARATOR) self._num_expected_files = len(file_names) self._logger.info("Expect to receive %d files" % self._num_expected_files) self._reach_expected_state() self._save_file_size_if_needed(context) self._save_file_chksum_if_needed(None, file_names, context) self._validate_throughput_if_needed()
def run(self, context): """ Runs the test step @type context: TestStepContext @param context: test case context """ WifiBase.run(self, context) # # Get the check sequence (it might just be one single operation) state_sequence = split_and_strip(self._pars.state, self.STR_SEPARATOR) msg = "All parameters checked :" self._initial_time = time.time() while not (self._time_out_reached() or self._all_parameters_checked): msg = "All parameters checked :" self._all_parameters_checked = True for current_state in state_sequence: if current_state == "CONNECTED": ssids = self._api.list_ssids("wifi", "connected") if self._pars.ssid not in ssids: self._all_parameters_checked = False elif current_state == "NOT_CONNECTED": ssids = self._api.list_ssids("wifi", "connected") if self._pars.ssid in ssids: self._all_parameters_checked = False elif current_state == "REMEMBERED": ssids = self._api.list_ssids("wifi", "remembered") if self._pars.ssid not in ssids: self._all_parameters_checked = False elif current_state == "NOT_REMEMBERED": ssids = self._api.list_ssids("wifi", "remembered") if self._pars.ssid in ssids: self._all_parameters_checked = False elif current_state == "VISIBLE": ssids = self._api.list_ssids("wifi", "visible") if self._pars.ssid not in ssids: self._all_parameters_checked = False elif current_state == "NOT_VISIBLE": ssids = self._api.list_ssids("wifi", "visible") if self._pars.ssid in ssids: self._all_parameters_checked = False elif current_state == "ALL": ssids = self._api.list_ssids("wifi", "all") if self._pars.ssid not in ssids: self._all_parameters_checked = False else: msg = "Invalid parameter state : %s" % current_state self._logger.error(msg) raise AcsConfigException( AcsConfigException.INVALID_PARAMETER, msg) # Compile verdict message msg += " - %s" % current_state time.sleep(self._wait_for) if self._time_out_reached() and not self._all_parameters_checked: self._raise_device_exception( "Expected SSID State fail : %s - Timeout reached after %ss" % (self._pars.state, self._pars.timeout)) self._logger.debug(msg) self.ts_verdict_msg = msg
def run(self, context): """ Runs the test step @type context: TestStepContext @param context: test case context """ WifiBase.run(self, context) msg = "All parameters checked :" # # Get the check sequence (it might just be one single operation) state_sequence = split_and_strip(self._pars.state, self.STR_SEPARATOR) for current_state in state_sequence: if current_state == "CONNECTED": ssids = self._api.list_ssids("wifi", "connected") if self._pars.ssid not in ssids: msg = "SSID %s is not connected" % self._pars.ssid self._logger.error(msg) raise DeviceException(DeviceException.OPERATION_FAILED, msg) elif current_state == "NOT_CONNECTED": ssids = self._api.list_ssids("wifi", "connected") if self._pars.ssid in ssids: msg = "SSID %s is connected" % self._pars.ssid self._logger.error(msg) raise DeviceException(DeviceException.OPERATION_FAILED, msg) elif current_state == "REMEMBERED": ssids = self._api.list_ssids("wifi", "remembered") if self._pars.ssid not in ssids: msg = "SSID %s is not in remembered WiFi AP list" % self._pars.ssid self._logger.error(msg) raise DeviceException(DeviceException.OPERATION_FAILED, msg) elif current_state == "NOT_REMEMBERED": ssids = self._api.list_ssids("wifi", "remembered") if self._pars.ssid in ssids: msg = "SSID %s is in remembered WiFi AP list" % self._pars.ssid self._logger.error(msg) raise DeviceException(DeviceException.OPERATION_FAILED, msg) elif current_state == "VISIBLE": ssids = self._api.list_ssids("wifi", "visible") if self._pars.ssid not in ssids: msg = "SSID %s is not visible !" % self._pars.ssid self._logger.error(msg) raise DeviceException(DeviceException.OPERATION_FAILED, msg) elif current_state == "NOT_VISIBLE": ssids = self._api.list_ssids("wifi", "visible") if self._pars.ssid in ssids: msg = "SSID %s is visible !" % self._pars.ssid self._logger.error(msg) raise DeviceException(DeviceException.OPERATION_FAILED, msg) elif current_state == "ALL": ssids = self._api.list_ssids("wifi", "all") if self._pars.ssid not in ssids: msg = "SSID %s is not known - visible or remembered" % self._pars.ssid self._logger.error(msg) raise DeviceException(DeviceException.OPERATION_FAILED, msg) else: msg = "Invalid parameter state : %s" % current_state self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) # Compile verdict message msg += " - %s" % current_state self._logger.debug(msg) self.ts_verdict_msg = msg