class LabAudioQualityAccessoriesChangeBase(UseCaseBase): """ AudioComms Audio CSV Call Accessories Change class. """ def __init__(self, tc_name, global_config): """ Constructor """ # Call UseCaseBase Init function UseCaseBase.__init__(self, tc_name, global_config) # Create Audio Analyzer self._audio_analyzer = self._em.get_audio_analyzer("AudioAnalyzer") # Check if IO card is used self._use_io_card = str_to_bool( global_config.campaignConfig.get("isIoCardUsed")) # Create Whs if self._use_io_card: self._wired_headset = self._em.get_wired_headset("WiredHeadset") # Initialization of the test type self._test_type = "audioquality" # Initialization of accessories type self._acc_type = "None" self._previous_acc_type = "None" # Initialization of audio_analyzer_result saved self._audio_analyzer_result_save = 0 self._audio_analyzer_result_ul = 0 self._audio_analyzer_result_dl = 0 # Initialization of failed transition saved self._failed_transition_audio_pb = "" self._failed_transition_no_audio = "" # Initialization of _dut_bt_address self._dut_bt_address = "None" # Initialization of test result self._result_verdict = Global.SUCCESS # Initialization of the verdict comment self._verdict_comment = "Audio Quality test fail" # Read registrationTimeout from Device_Catalog.xml self._registration_timeout = \ int(self._dut_config.get("registrationTimeout")) # Read callSetupTimeout from Device_Catalog.xml self._call_setup_time = \ int(self._dut_config.get("callSetupTimeout")) # Read call origin type from test case xml file (str) self._call_origin_type = str( self._tc_parameters.get_param_value("CALL_ORIGIN_TYPE")) # Read accessories list from test case xml file (str) self._acc_list = str(self._tc_parameters.get_param_value("ACC_LIST")) # Split the accessories list, accessories separated by ',' self._acc_list = self._acc_list.strip('[] ') self._acc_list_split = self._acc_list.split(',') self._acc_list_split.reverse() # Read accessories active list from test case xml file (str) self._acc_active_list = str( self._tc_parameters.get_param_value("ACC_ACTIVE_LIST")) # Split the accessories active list, accessories separated by ',' self._acc_active_list = self._acc_active_list.strip('[] ') self._acc_active_list_split = self._acc_active_list.split(',') self._acc_active_list_split.reverse() # Call Stream Volume in percent self._call_stream_volume_dut_list = \ str(self._tc_parameters.get_param_value("CALL_VOLUME_DUT_LIST")) # Split the accessories list, accessories separated by ',' self._call_stream_volume_dut_list = self._call_stream_volume_dut_list.strip( '[] ') self._call_volume_dut_list_split = self._call_stream_volume_dut_list.split( ',') self._call_volume_dut_list_split.reverse() # Call Stream Volume in percent self._call_stream_volume_ref_list = \ str(self._tc_parameters.get_param_value("CALL_VOLUME_REF_LIST")) # Split the accessories list, accessories separated by ',' self._call_stream_volume_ref_list = self._call_stream_volume_ref_list.strip( '[] ') self._call_volume_ref_list_split = self._call_stream_volume_ref_list.split( ',') self._call_volume_ref_list_split.reverse() # Read call end type from test case xml file (str) self._call_end_type = str( self._tc_parameters.get_param_value("CALL_END_TYPE")) # Read call type from test case xml file (str) self._call_type = str(self._tc_parameters.get_param_value("CALL_TYPE")) # Read test call direction type from test case xml file (s tring) self._signal_tested_direction = \ str(self._tc_parameters.get_param_value("SIGNAL_TESTED_DIRECTION")) # Read duration type from test case xml file (int) if self._tc_parameters.get_param_value("DURATION"): self._call_duration = int( self._tc_parameters.get_param_value("DURATION")) else: # Call duration by default self._call_duration = 5 # Read Audio Analyzer parameters from bench config xml file (str) self._audio_analyzer_node = global_config.benchConfig.\ get_parameters("AudioAnalyzer") self._bt_remote_addr = self._audio_analyzer_node.get_param_value( "Bt_mac_addr") # Instantiate generic UECmd for voiceCall Ucs self._system_api = self._device.get_uecmd("System") self._networking_api = self._device.get_uecmd("Networking") # Bluetooth present in the list accessories if self._acc_list.count("BLUETOOTH") > 0: # Get UECmdLayer self._bt_api = self._device.get_uecmd("LocalConnectivity") # Load instance of the PHONE2 self._phone2 = DeviceManager().get_device("PHONE2") self._system_api2 = None self._acc_swap_type = self._tc_parameters.get_param_value( "ACC_SWAP_TYPE", 'Default') # Copy of accessories list self._temp_acc_list_split = None # Copy of volume list / active accessory list self._temp_call_volume_dut_list_split = None self._temp_call_volume_ref_list_split = None self._temp_acc_active_list_split = None def set_up(self): """ Set up the test configuration """ # Call UseCaseBase Setup function UseCaseBase.set_up(self) # Check if we have the second phone available if self._phone2 is not None: if not self._phone2.is_available(): self._phone2.switch_on(simple_switch_mode=True) self._system_api2 = self._phone2.get_uecmd("System") else: # We are using this multi UC with only one phone error_msg = \ "This test case requires two phones to be executed !" self._logger.error(error_msg) raise AcsConfigException(AcsConfigException.INVALID_BENCH_CONFIG, error_msg) # Swap 2G 3G or 4G. if self._call_type == "2G": self._networking_api.set_preferred_network_type( PreferredNetwork.GSM_ONLY) elif self._call_type == "3G": self._networking_api.set_preferred_network_type( PreferredNetwork.WCDMA_ONLY) elif self._call_type == "4G": self._networking_api.set_preferred_network_type( PreferredNetwork.LTE_ONLY) else: if self._call_type not in "VOIP": msg = "wrong value of parameter CALL TYPE" self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) # Audio Analyzer Initialization if self._audio_analyzer.initialization(self._device.get_phone_model(), self._test_type) != 0: error_msg = \ "Audio Analyzer Initialization Failed !" self._logger.error(error_msg) raise TestEquipmentException( TestEquipmentException.OPERATION_FAILED, error_msg) if self._acc_list.count("BLUETOOTH") > 0: # Get dut bt address self._dut_bt_address = self._bt_api.get_bt_adapter_address() # Push the first Bluetooth accessories in first l_bluetooth_acc_position = 0 for i in self._acc_list_split: if i.find("BLUETOOTH") != -1: # Initialization of _acc_type with the bluetooth accessories self._acc_type = i self._acc_list_split.insert(len(self._acc_list_split), i) self._acc_active_list_split.insert( len(self._acc_active_list_split), self._acc_active_list_split[l_bluetooth_acc_position]) self._call_volume_ref_list_split.insert( len(self._call_volume_ref_list_split), self. _call_volume_ref_list_split[l_bluetooth_acc_position]) self._call_volume_dut_list_split.insert( len(self._call_volume_dut_list_split), self. _call_volume_dut_list_split[l_bluetooth_acc_position]) break l_bluetooth_acc_position += 1 # Connect Bluetooth device if self._audio_analyzer.connect_bt(self._acc_type, self._dut_bt_address) != 0: error_msg = \ "Connect Bluetooth failed !" self._logger.error(error_msg) raise DeviceException(DeviceException.OPERATION_FAILED, error_msg) return Global.SUCCESS, "No errors" def tear_down(self): """ End and dispose the test """ # Call UseCaseBase tear_down function UseCaseBase.tear_down(self) # Reset Voice Call Volume at 50% if self._system_api is not None: self._system_api.adjust_specified_stream_volume("VoiceCall", 70) if self._system_api2 is not None: self._system_api2.adjust_specified_stream_volume("VoiceCall", 70) return Global.SUCCESS, "No errors" def _compute_test_verdict_(self, audio_analyzer_result_ul, audio_analyzer_result_dl): """ Computes the test verdict for audio accessory change :type audio_analyzer_result_dl: int :param audio_analyzer_result_dl: result value for the DL audio test given by the audio analyzer :type audio_analyzer_result_ul: int :param audio_analyzer_result_ul: result value for the UL audio test given by the audio analyzer :return: None """ if self._audio_analyzer_result_save == 3: self._result_verdict = Global.BLOCKED elif self._audio_analyzer_result_save == 2: if (audio_analyzer_result_ul == 3) or (audio_analyzer_result_dl == 3): self._result_verdict = Global.BLOCKED self._failed_transition_no_audio = self._failed_transition_no_audio + ", " + \ self._previous_acc_type + " => " + self._acc_type self._audio_analyzer_result_save = 3 elif (audio_analyzer_result_ul == 2) or (audio_analyzer_result_dl == 2): self._result_verdict = Global.FAILURE self._failed_transition_no_audio = self._failed_transition_no_audio + ", " + \ self._previous_acc_type + " => " + self._acc_type self._audio_analyzer_result_save = 2 elif self._audio_analyzer_result_save == 1: if (audio_analyzer_result_ul == 3) or (audio_analyzer_result_dl == 3): self._result_verdict = Global.BLOCKED self._failed_transition_no_audio = self._failed_transition_no_audio + ", " + \ self._previous_acc_type + " => " + self._acc_type self._audio_analyzer_result_save = 3 elif (audio_analyzer_result_ul == 2) or (audio_analyzer_result_dl == 2): self._result_verdict = Global.FAILURE self._failed_transition_no_audio = self._failed_transition_no_audio + ", " + \ self._previous_acc_type + " => " + self._acc_type self._audio_analyzer_result_save = 2 elif (audio_analyzer_result_ul == 1) or (audio_analyzer_result_dl == 1): self._result_verdict = Global.FAILURE self._failed_transition_audio_pb = self._failed_transition_audio_pb + ", " + \ self._previous_acc_type + " => " + self._acc_type elif self._audio_analyzer_result_save == 0: if (audio_analyzer_result_ul == 3) or (audio_analyzer_result_dl == 3): self._result_verdict = Global.BLOCKED self._failed_transition_no_audio = self._failed_transition_no_audio + ", " + \ self._previous_acc_type + " => " + self._acc_type self._audio_analyzer_result_save = 3 elif (audio_analyzer_result_ul == 2) or (audio_analyzer_result_dl == 2): self._result_verdict = Global.FAILURE self._failed_transition_no_audio = self._failed_transition_no_audio + ", " + \ self._previous_acc_type + " => " + self._acc_type self._audio_analyzer_result_save = 2 elif (audio_analyzer_result_ul == 1) or (audio_analyzer_result_dl == 1): self._result_verdict = Global.FAILURE self._failed_transition_audio_pb = self._failed_transition_audio_pb + ", " + \ self._previous_acc_type + " => " + self._acc_type self._audio_analyzer_result_save = 1 else: self._audio_analyzer_result_save = 0 self._result_verdict = Global.SUCCESS # Now, the verdict comment will be updated, according to the outcome of the audio test if self._audio_analyzer_result_save == 0: self._verdict_comment = ( "Audio Quality test success: in %s with " "a %s call with %s accessories sequence" % (self._signal_tested_direction, self._call_type, str(self._tc_parameters.get_param_value("ACC_LIST")))) elif self._audio_analyzer_result_save == 1: self._verdict_comment = ( "Audio Quality test fail: Audio Analyzer quality audio " "problems detected in %s with a %s call with " "%s accessories sequence" % (self._signal_tested_direction, self._call_type, self._failed_transition_audio_pb)) elif self._audio_analyzer_result_save == 2: self._verdict_comment = ( "Audio Quality test fail: No audio signal in %s with " "a %s call with %s accessories sequence" % (self._signal_tested_direction, self._call_type, self._failed_transition_no_audio)) elif self._audio_analyzer_result_save == 3: self._verdict_comment = ( "Audio Quality test fail: Exception in executable in %s with " "a %s call with %s accessories sequence" % (self._signal_tested_direction, self._call_type, self._failed_transition_no_audio)) else: self._verdict_comment = ( "Audio Quality test fail: Audio Analyzer problems detected " "in %s with a %s call" % (self._signal_tested_direction, self._call_type))
def __init__(self, tc_name, global_config): """ Constructor """ # Call UseCaseBase Init function UseCaseBase.__init__(self, tc_name, global_config) # Create Audio Analyzer self._audio_analyzer = self._em.get_audio_analyzer("AudioAnalyzer") # Check if IO card is used self._use_io_card = str_to_bool( global_config.campaignConfig.get("isIoCardUsed")) # Create Whs if self._use_io_card: self._wired_headset = self._em.get_wired_headset("WiredHeadset") # Initialization of the test type self._test_type = "audioquality" # Initialization of accessories type self._acc_type = "None" self._previous_acc_type = "None" # Initialization of audio_analyzer_result saved self._audio_analyzer_result_save = 0 self._audio_analyzer_result_ul = 0 self._audio_analyzer_result_dl = 0 # Initialization of failed transition saved self._failed_transition_audio_pb = "" self._failed_transition_no_audio = "" # Initialization of _dut_bt_address self._dut_bt_address = "None" # Initialization of test result self._result_verdict = Global.SUCCESS # Initialization of the verdict comment self._verdict_comment = "Audio Quality test fail" # Read registrationTimeout from Device_Catalog.xml self._registration_timeout = \ int(self._dut_config.get("registrationTimeout")) # Read callSetupTimeout from Device_Catalog.xml self._call_setup_time = \ int(self._dut_config.get("callSetupTimeout")) # Read call origin type from test case xml file (str) self._call_origin_type = str( self._tc_parameters.get_param_value("CALL_ORIGIN_TYPE")) # Read accessories list from test case xml file (str) self._acc_list = str(self._tc_parameters.get_param_value("ACC_LIST")) # Split the accessories list, accessories separated by ',' self._acc_list = self._acc_list.strip('[] ') self._acc_list_split = self._acc_list.split(',') self._acc_list_split.reverse() # Read accessories active list from test case xml file (str) self._acc_active_list = str( self._tc_parameters.get_param_value("ACC_ACTIVE_LIST")) # Split the accessories active list, accessories separated by ',' self._acc_active_list = self._acc_active_list.strip('[] ') self._acc_active_list_split = self._acc_active_list.split(',') self._acc_active_list_split.reverse() # Call Stream Volume in percent self._call_stream_volume_dut_list = \ str(self._tc_parameters.get_param_value("CALL_VOLUME_DUT_LIST")) # Split the accessories list, accessories separated by ',' self._call_stream_volume_dut_list = self._call_stream_volume_dut_list.strip( '[] ') self._call_volume_dut_list_split = self._call_stream_volume_dut_list.split( ',') self._call_volume_dut_list_split.reverse() # Call Stream Volume in percent self._call_stream_volume_ref_list = \ str(self._tc_parameters.get_param_value("CALL_VOLUME_REF_LIST")) # Split the accessories list, accessories separated by ',' self._call_stream_volume_ref_list = self._call_stream_volume_ref_list.strip( '[] ') self._call_volume_ref_list_split = self._call_stream_volume_ref_list.split( ',') self._call_volume_ref_list_split.reverse() # Read call end type from test case xml file (str) self._call_end_type = str( self._tc_parameters.get_param_value("CALL_END_TYPE")) # Read call type from test case xml file (str) self._call_type = str(self._tc_parameters.get_param_value("CALL_TYPE")) # Read test call direction type from test case xml file (s tring) self._signal_tested_direction = \ str(self._tc_parameters.get_param_value("SIGNAL_TESTED_DIRECTION")) # Read duration type from test case xml file (int) if self._tc_parameters.get_param_value("DURATION"): self._call_duration = int( self._tc_parameters.get_param_value("DURATION")) else: # Call duration by default self._call_duration = 5 # Read Audio Analyzer parameters from bench config xml file (str) self._audio_analyzer_node = global_config.benchConfig.\ get_parameters("AudioAnalyzer") self._bt_remote_addr = self._audio_analyzer_node.get_param_value( "Bt_mac_addr") # Instantiate generic UECmd for voiceCall Ucs self._system_api = self._device.get_uecmd("System") self._networking_api = self._device.get_uecmd("Networking") # Bluetooth present in the list accessories if self._acc_list.count("BLUETOOTH") > 0: # Get UECmdLayer self._bt_api = self._device.get_uecmd("LocalConnectivity") # Load instance of the PHONE2 self._phone2 = DeviceManager().get_device("PHONE2") self._system_api2 = None self._acc_swap_type = self._tc_parameters.get_param_value( "ACC_SWAP_TYPE", 'Default') # Copy of accessories list self._temp_acc_list_split = None # Copy of volume list / active accessory list self._temp_call_volume_dut_list_split = None self._temp_call_volume_ref_list_split = None self._temp_acc_active_list_split = None
class RunVideoCallSkype(DeviceTestStepBase): """ Run Skype video call """ def run(self, context): """ Runs the test step :type context: TestStepContext :param context: test case context """ DeviceTestStepBase.run(self, context) self._logger.debug("START OF RUN_VIDEOCALL_SKYPE") # Get device manager object self._device_manager = DeviceManager() self._caller_device = self._device_manager.get_device(self._pars.caller_device) self._receiver_device = self._device self._caller_device_logger = self._caller_device.get_device_logger() self._receiver_device_logger = self._receiver_device.get_device_logger() self._caller_skype_api = self._caller_device.get_uecmd("VideoCallSkype") self._receiver_skype_api = self._receiver_device.get_uecmd("VideoCallSkype") #Create a wake lock to prevent device from sleep mode. If a device in sleep mode, the Skype video call will fail adbCmd = "adb shell echo 'skype' >> /sys/power/wake_lock" self._caller_device.run_cmd(cmd=adbCmd, timeout=120) self._receiver_device.run_cmd(cmd=adbCmd, timeout=120) # Set up logcat triggering for each platform self.triglogStartMsg = self._caller_skype_api.get_logcat_trigger_message('Start') self.triglogChatMsg = self._caller_skype_api.get_logcat_trigger_message('Chat') self.triglogPrecallMsg = self._caller_skype_api.get_logcat_trigger_message('Precall') self.triglogCallMsg = self._caller_skype_api.get_logcat_trigger_message('Call') self.triglogReleaseMsg = self._caller_skype_api.get_logcat_trigger_message('Release') # Add triglogs for Skype start conditions self._caller_device_logger.add_trigger_message(self.triglogStartMsg) self._receiver_device_logger.add_trigger_message(self.triglogStartMsg) self._caller_device_logger.add_trigger_message(self.triglogChatMsg) self._receiver_device_logger.add_trigger_message(self.triglogChatMsg) self._caller_device_logger.add_trigger_message(self.triglogPrecallMsg) self._receiver_device_logger.add_trigger_message(self.triglogPrecallMsg) self._caller_device_logger.add_trigger_message(self.triglogCallMsg) self._receiver_device_logger.add_trigger_message(self.triglogCallMsg) self._caller_device_logger.add_trigger_message(self.triglogReleaseMsg) self._receiver_device_logger.add_trigger_message(self.triglogReleaseMsg) iteration_number = 0 result = 0 chat_duration = self._pars.chat_duration * 60 time_between_chats = self._pars.time_between_chats * 60 disconnect_threshold = self._pars.disconnect_threshold # Get Parameters test_duration = self._pars.duration * 60 start_time = time.time() if test_duration < chat_duration + 10: error_msg = "Test duration {0} seconds is set to smaller than chat duration {1} seconds".format(str(test_duration), str(chat_duration)) self._logger.error(error_msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, error_msg) else: self._logger.debug("Test duration is {0} seconds".format(str(test_duration))) #Start checking loop while time.time()-start_time < test_duration: iteration_number += 1 self._logger.info("[Skype Iteration {0}] Started".format(iteration_number)) if result > disconnect_threshold: break self._caller_skype_api.stop_skype_app() self._receiver_skype_api.stop_skype_app() time.sleep(5) (verdict, msg) = self.start_skype_app(self._caller_device) if verdict == Global.FAILURE: self._logger.error("[Skype Iteration {0} Failure] {1}".format(iteration_number, msg)) result += 1 continue time.sleep(5) (verdict, msg) = self.start_skype_app(self._receiver_device) if verdict == Global.FAILURE: self._logger.error("[Skype Iteration {0} Failure] {1}".format(iteration_number, msg)) result += 1 continue time.sleep(5) (verdict, msg) = self.start_videocall_session() if verdict == Global.FAILURE: self._logger.error("[Skype Iteration {0} Failure] {1}".format(iteration_number, msg)) result += 1 continue self._logger.info("[Skype Iteration {0}] Skype video chat session started. Wait for chat duration: {1} seconds".format(iteration_number, chat_duration)) time.sleep(chat_duration) (verdict, msg) = self.stop_videocall_session(self._caller_device, self._caller_device_logger) self._logger.info("[Skype Iteration {0}] Passed {1} seconds (Total {2} seconds)".format(iteration_number, time.time()-start_time, test_duration)) self._logger.info("[Skype Iteration {0}] {1} disconnections so far. TC threshold is {2}".format(iteration_number, result, disconnect_threshold)) if verdict == Global.FAILURE: self._logger.error("[Skype Iteration {0} Failure] {1}".format(iteration_number, msg)) result += 1 continue else: self._logger.info("[Skype Iteration {0} Success] Skype session was finished, VERDICT={1}".format(iteration_number, verdict)) #wait to start the next call estimated_time_after_next_iteration = (time.time() - start_time) + time_between_chats + chat_duration + 30 if estimated_time_after_next_iteration < test_duration : self._logger.debug("Wait for next chat Time: {0} seconds".format(time_between_chats)) time.sleep(time_between_chats) else: time_to_stay = test_duration - (time.time() - start_time) + 10 self._logger.debug("Wait for {0} seconds for test completion".format(time_to_stay)) time.sleep(time_to_stay) self._logger.info("Skype video chat completed {0} sessions in {1} seconds".format(iteration_number, test_duration)) #Remove the wake lock before exit. adbCmd = "adb shell echo 'skype' >> /sys/power/wake_unlock" self._caller_device.run_cmd(cmd=adbCmd, timeout=120) self._receiver_device.run_cmd(cmd=adbCmd, timeout=120) if result > disconnect_threshold: msg = "Video chat FAILED" self._logger.info(msg) raise DeviceException(DeviceException.OPERATION_FAILED, msg) else: msg = "Video chat PASSED" self._logger.info(msg) def start_skype_app(self, device_obj): """ Dials a voice call. :type device_obj: str :param device_obj: number to call (MSISDN) :return: None """ device_obj_skype_api = device_obj.get_uecmd("VideoCallSkype") device_obj_logger = device_obj.get_device_logger() # Kick start Google Skype on a phone device_obj_skype_api.start_skype_app() time.sleep(10) startMsg = device_obj_logger.get_message_triggered_status(self.triglogStartMsg) if len(startMsg) == 0: verdict = Global.FAILURE msg = "Skype app failed to start properly on " + device_obj._device_name else: verdict = Global.SUCCESS msg = "Skype app started on " + device_obj._device_name device_obj_logger.reset_trigger_message(self.triglogStartMsg) return (verdict, msg) def start_videocall_session(self): """ Start a video call skype session. :return: verdict and message """ # Select Contact on Phone 1: Assume commercial banner on screen self._caller_skype_api.select_1st_contact_banner() time.sleep(10) messages = self._caller_device_logger.get_message_triggered_status(self.triglogChatMsg) if len(messages) == 0: # Select Contact on Phone 1: No commercial banner on screen self._caller_skype_api.select_1st_contact_nobanner() # Wait until PHONE1 has a chat screen chat_screen = 0 while chat_screen == 0: messages = self._caller_device_logger.get_message_triggered_status(self.triglogChatMsg) if len(messages) > 0: self._logger.debug(self._caller_device._device_name + " has a chat screen") chat_screen = 1 self._caller_device_logger.reset_trigger_message(self.triglogChatMsg) # Start Video Chat between Phone 1 and Phone 2 self._caller_skype_api.start_call() # Wait until PHONE2 receive a incoming call incoming_call = 0 while incoming_call == 0: messages = self._receiver_device_logger.get_message_triggered_status(self.triglogPrecallMsg) if len(messages) > 0: self._logger.debug(self._receiver_device._device_name + " has a incoming Skype video call") incoming_call = 1 self._receiver_device_logger.reset_trigger_message(self.triglogPrecallMsg) time.sleep(5) # Have Phone 2 accept video chat between Phone 1 and Phone 2 by swiping Phone 2 from center to right self._receiver_skype_api.accept_call() time.sleep(5) messages2 = self._receiver_device_logger.get_message_triggered_status(self.triglogCallMsg) if len(messages2) == 0: verdict = Global.FAILURE msg = "Failed to start Skype session between " + self._caller_device._device_name + " and " + self._receiver_device._device_name + "\n" else: verdict = Global.SUCCESS msg = "Started Skype session between " + self._caller_device._device_name + " and " + self._receiver_device._device_name + "\n" self._logger.debug(msg) self._receiver_device_logger.reset_trigger_message(self.triglogCallMsg) return (verdict, msg) def stop_videocall_session(self, device_obj, phone_logger): """ Stop a video call skype session. :type device_obj: Device :param device_obj: Device to use :type phone_logger: logger :param phone_logger: Logger to use :return: verdict and message """ self._caller_skype_api.reveal_buttons() time.sleep(2) self._caller_skype_api.disconnect_call() time.sleep(3) releaseMsg = phone_logger.get_message_triggered_status(self.triglogReleaseMsg) if len(releaseMsg) == 0: verdict = Global.FAILURE msg = "Skype stopped on " + device_obj._device_name + "\n" else: verdict = Global.SUCCESS msg = "Skype stopped on " + device_obj._device_name + "\n" self._logger.debug(msg) phone_logger.reset_trigger_message(self.triglogReleaseMsg) return (verdict, msg)
def run(self, context): """ Runs the test step :type context: TestStepContext :param context: test case context """ DeviceTestStepBase.run(self, context) self._logger.debug("START OF RUN_VIDEOCALL_SKYPE") # Get device manager object self._device_manager = DeviceManager() self._caller_device = self._device_manager.get_device(self._pars.caller_device) self._receiver_device = self._device self._caller_device_logger = self._caller_device.get_device_logger() self._receiver_device_logger = self._receiver_device.get_device_logger() self._caller_skype_api = self._caller_device.get_uecmd("VideoCallSkype") self._receiver_skype_api = self._receiver_device.get_uecmd("VideoCallSkype") #Create a wake lock to prevent device from sleep mode. If a device in sleep mode, the Skype video call will fail adbCmd = "adb shell echo 'skype' >> /sys/power/wake_lock" self._caller_device.run_cmd(cmd=adbCmd, timeout=120) self._receiver_device.run_cmd(cmd=adbCmd, timeout=120) # Set up logcat triggering for each platform self.triglogStartMsg = self._caller_skype_api.get_logcat_trigger_message('Start') self.triglogChatMsg = self._caller_skype_api.get_logcat_trigger_message('Chat') self.triglogPrecallMsg = self._caller_skype_api.get_logcat_trigger_message('Precall') self.triglogCallMsg = self._caller_skype_api.get_logcat_trigger_message('Call') self.triglogReleaseMsg = self._caller_skype_api.get_logcat_trigger_message('Release') # Add triglogs for Skype start conditions self._caller_device_logger.add_trigger_message(self.triglogStartMsg) self._receiver_device_logger.add_trigger_message(self.triglogStartMsg) self._caller_device_logger.add_trigger_message(self.triglogChatMsg) self._receiver_device_logger.add_trigger_message(self.triglogChatMsg) self._caller_device_logger.add_trigger_message(self.triglogPrecallMsg) self._receiver_device_logger.add_trigger_message(self.triglogPrecallMsg) self._caller_device_logger.add_trigger_message(self.triglogCallMsg) self._receiver_device_logger.add_trigger_message(self.triglogCallMsg) self._caller_device_logger.add_trigger_message(self.triglogReleaseMsg) self._receiver_device_logger.add_trigger_message(self.triglogReleaseMsg) iteration_number = 0 result = 0 chat_duration = self._pars.chat_duration * 60 time_between_chats = self._pars.time_between_chats * 60 disconnect_threshold = self._pars.disconnect_threshold # Get Parameters test_duration = self._pars.duration * 60 start_time = time.time() if test_duration < chat_duration + 10: error_msg = "Test duration {0} seconds is set to smaller than chat duration {1} seconds".format(str(test_duration), str(chat_duration)) self._logger.error(error_msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, error_msg) else: self._logger.debug("Test duration is {0} seconds".format(str(test_duration))) #Start checking loop while time.time()-start_time < test_duration: iteration_number += 1 self._logger.info("[Skype Iteration {0}] Started".format(iteration_number)) if result > disconnect_threshold: break self._caller_skype_api.stop_skype_app() self._receiver_skype_api.stop_skype_app() time.sleep(5) (verdict, msg) = self.start_skype_app(self._caller_device) if verdict == Global.FAILURE: self._logger.error("[Skype Iteration {0} Failure] {1}".format(iteration_number, msg)) result += 1 continue time.sleep(5) (verdict, msg) = self.start_skype_app(self._receiver_device) if verdict == Global.FAILURE: self._logger.error("[Skype Iteration {0} Failure] {1}".format(iteration_number, msg)) result += 1 continue time.sleep(5) (verdict, msg) = self.start_videocall_session() if verdict == Global.FAILURE: self._logger.error("[Skype Iteration {0} Failure] {1}".format(iteration_number, msg)) result += 1 continue self._logger.info("[Skype Iteration {0}] Skype video chat session started. Wait for chat duration: {1} seconds".format(iteration_number, chat_duration)) time.sleep(chat_duration) (verdict, msg) = self.stop_videocall_session(self._caller_device, self._caller_device_logger) self._logger.info("[Skype Iteration {0}] Passed {1} seconds (Total {2} seconds)".format(iteration_number, time.time()-start_time, test_duration)) self._logger.info("[Skype Iteration {0}] {1} disconnections so far. TC threshold is {2}".format(iteration_number, result, disconnect_threshold)) if verdict == Global.FAILURE: self._logger.error("[Skype Iteration {0} Failure] {1}".format(iteration_number, msg)) result += 1 continue else: self._logger.info("[Skype Iteration {0} Success] Skype session was finished, VERDICT={1}".format(iteration_number, verdict)) #wait to start the next call estimated_time_after_next_iteration = (time.time() - start_time) + time_between_chats + chat_duration + 30 if estimated_time_after_next_iteration < test_duration : self._logger.debug("Wait for next chat Time: {0} seconds".format(time_between_chats)) time.sleep(time_between_chats) else: time_to_stay = test_duration - (time.time() - start_time) + 10 self._logger.debug("Wait for {0} seconds for test completion".format(time_to_stay)) time.sleep(time_to_stay) self._logger.info("Skype video chat completed {0} sessions in {1} seconds".format(iteration_number, test_duration)) #Remove the wake lock before exit. adbCmd = "adb shell echo 'skype' >> /sys/power/wake_unlock" self._caller_device.run_cmd(cmd=adbCmd, timeout=120) self._receiver_device.run_cmd(cmd=adbCmd, timeout=120) if result > disconnect_threshold: msg = "Video chat FAILED" self._logger.info(msg) raise DeviceException(DeviceException.OPERATION_FAILED, msg) else: msg = "Video chat PASSED" self._logger.info(msg)
class BatteryChecker(DeviceTestStepBase): def __init__(self, tc_conf, global_conf, ts_conf, factory): DeviceTestStepBase.__init__(self, tc_conf, global_conf, ts_conf, factory) self._device_manager = DeviceManager() self._low_threshold = int(self._pars.get_attr("low_threshold")) self._required_level = int(self._pars.get_attr("required_level")) self._battery_infos = dict() def update_battery_infos(self): cmd_user = "******" status, logcat_output = self._device.run_cmd(cmd_user, self._device.get_uecmd_timeout(), force_execution=True, wait_for_response=True, silent_mode=True) for match in re.finditer(r'^\s+(.*?):\s*(.+)$', logcat_output, re.MULTILINE): self._battery_infos[match.group(1)] = match.group(2) def get_current_battery_level(self): self.update_battery_infos() if 'level' in self._battery_infos and 'scale' in self._battery_infos: return 100 * int(self._battery_infos['level']) / int(self._battery_infos['scale']) else: raise DeviceException(DeviceException.CRITICAL_FAILURE, "Unable to read battery service information.") def run(self, context): """ Runs the test step @type context: TestStepContext @param context: test case context """ DeviceTestStepBase.run(self, context) self._logger.info("Getting the current battery capacity...") device_plug = self._device_manager.get_device_config(self._pars.device).get("OnBattery", "False") self._logger.info("device plugged on battery: %s" % device_plug) if device_plug is not None and not str_to_bool(device_plug): self._logger.warning("Device plugged on Power Supply and in Low battery mode, can't wait charging") return current_level = self.get_current_battery_level() if current_level < self._low_threshold: self._logger.info("Low battery level detected... ({}%)".format(current_level)) if 'status' in self._battery_infos and int(self._battery_infos['status']) == 2: self._logger.info("Battery is charging...") while current_level < self._required_level: if 'status' in self._battery_infos and int(self._battery_infos['status']) == 2: self._logger.info("Waiting for required ({0}%) battery level... ({1}% reached)" .format(self._required_level, current_level)) time.sleep(60) current_level = self.get_current_battery_level() else: raise DeviceException(DeviceException.INVALID_DEVICE_STATE, "Battery isn't charging or battery service unreachable.") cmd_user = "******" status, output = self._device.run_cmd(cmd_user, self._device.get_uecmd_timeout(), force_execution=True, wait_for_response=True, silent_mode=True) # if the device started with battlow, we have reboot to flush this state: if "battlow" in output: self._device.reboot() else: raise DeviceException(DeviceException.INVALID_DEVICE_STATE, "Battery isn't charging or battery service unreachable.") self._logger.debug(self.ts_verdict_msg)
def _create_sut(self, test_step_pars=None): self._sut = GetWifiDirectThroughputTargets(None, None, test_step_pars, mock.Mock()) DeviceManager().get_device = self._return_device return self._sut
class LabWifiDirectBase(UseCaseBase): """ Lab Wifi Direct class. """ DEFAULT_REGULATORY_DOMAIN = "US" def __init__(self, tc_name, global_config): """ Constructor """ UseCaseBase.__init__(self, tc_name, global_config) self._device1_name = self._tc_parameters.get_param_value( "DEVICE1_NAME", "") self._device2_name = self._tc_parameters.get_param_value( "DEVICE2_NAME", "") # Get P2p interface name self._device1_p2pinterface = str(self._dut_config.get("p2pInterface")) self._device1_supplicant = None self._device1_client = None self._device1_mac = None self._device2_supplicant = None self._device2_client = None self._device2_mac = None self._phone2 = None self._networking2_api = None self._device2_p2pinterface = None if self._device2_name.startswith("PHONE"): self.dut_config2 = DeviceManager().get_device_config("PHONE2") self._device2_p2pinterface = str( self.dut_config2.get("p2pInterface")) # Get Device 2 Instance self._phone2 = DeviceManager().get_device(self._device2_name) self._networking2_api = self._phone2.get_uecmd("Networking") self._networking_api = self._device.get_uecmd("Networking") self._dut1_wlan_iface = str(self._dut_config.get("wlanInterface")) self._dut2_wlan_iface = str(self.dut_config2.get("wlanInterface")) def set_up(self): """ Initialize the test """ UseCaseBase.set_up(self) self.__check_tc_parameters() if self._phone2 is not None and not self._phone2.is_available(): DeviceManager().boot_device(self._device2_name) # set wifi On on the DUT to allow regulatory domain to change self._networking_api.set_wifi_power("on") if self._networking2_api is not None: self._networking2_api.set_wifi_power("on") # set the regulatory domain self._networking_api.set_regulatorydomain( LabWifiDirectBase.DEFAULT_REGULATORY_DOMAIN, self._dut1_wlan_iface) if self._networking2_api is not None: self._networking2_api.set_regulatorydomain( LabWifiDirectBase.DEFAULT_REGULATORY_DOMAIN, self._dut2_wlan_iface) # set wifi Off on the DUT self._networking_api.set_wifi_power("off") if self._networking2_api is not None: self._networking2_api.set_wifi_power("off") return Global.SUCCESS, "No error" #------------------------------------------------------------------------------ def _get_supplicant_instance(self, device_name): """ Get the p2p supplicant instance for the device :rtype: UECmd Object or Equipement Object :return: The p2p supplicant instance for the device """ device_instance = self.__get_device_instance(device_name) if device_name.startswith("PHONE"): return device_instance.get_uecmd("P2PSupplicantCLI") if device_name.startswith("COMPUTER"): return device_instance.get_p2p("P2pSupplicant") msg = "device not found " + device_name self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) def _get_client_instance(self, device_name): """ return the p2p client instance for the device """ device_instance = self.__get_device_instance(device_name) if device_name.startswith("PHONE"): return device_instance.get_uecmd("P2PClientCLI") if device_name.startswith("COMPUTER"): return device_instance.get_p2p("P2pClient") msg = "device not found " + device_name self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) def __get_device_instance(self, device_name): """ retrieve the device instance """ if device_name.startswith("COMPUTER"): return self._em if device_name == "PHONE1": return self._device if device_name.startswith("PHONE"): if not self._phone2.is_available(): DeviceManager().boot_device(device_name) return self._phone2 msg = "device not found " + device_name self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) def __check_tc_parameters(self): """ Checks all TC parameters """ if not self._device1_name: msg = "undefined device name 1." self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg) if not self._device2_name: msg = "undefined device name 2." self._logger.error(msg) raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)
def run(self, context): """ Runs the test step @type context: TestStepContext @param context: test case context """ DeviceTestStepBase.run(self, context) self._logger.info(self._pars.id + ": Test step starting.") # App signature to use with gui focus lock file appSignature = 'take_pictures_loop' try: # Delete any focus-lock file that may not have been released during the previous test run. osbv_utils.cleanup_focus_lock(appSignature) except: raise DeviceException(DeviceException.OPERATION_FAILED, self._pars.id + ": Issue trying to remove previous focus lock file.") loop = 1 numPicsTaken = 0 num_pics_to_take = 2 # Number of consecutive retries in loop before it would fail due to too many. max_retries = 50 retry = max_retries self.pic_file_type = "jpg" self._dut_os = self._device.get_device_os_path() # Set report path self._device_manager = DeviceManager() self.report_path = self._device_manager.get_global_config().campaignConfig.get("campaignReportTree").create_subfolder('take_pictures_loop') # Following call creates directory to store files created from TS that will generally not be needed unless an error is hit. self.temp_dir = osbv_utils.test_step_temp_dir(self) # Create folder under temp_dir to put pictures from device into. self.host_save_folder = os.path.join(self.temp_dir, 'saved_pics') # Timeout value to use that determines amount of time to wait on gui focus lock file to be removed. self.gui_lock_wait_time = self._pars.gui_lock_wait_time if not os.path.exists(self.host_save_folder): os.makedirs(self.host_save_folder) # Get UECmdLayer self._camera_api = self._device.get_uecmd("Camera") self._file_api = self._device.get_uecmd("File") self._camera_app = self._camera_api.get_camera_version(self._pars.camera_app) # Set camera application to image capture mode self._camera_api.camera_app_setup(self._camera_app, 'camera') start_time = float(time.time()) end_time = start_time + (float(self._pars.duration)) * 60 errorCount = { 'camConnectionErr':0, 'camStopped' :0, 'camNotResponding':0, 'unclassifiedFail':0 } try: # Following calls will remove all files in the save directory(ies). for directory in self._camera_api.device_save_directory: try: self._device.get_uecmd("PhoneSystem").delete(directory + self._dut_os.sep + '*.*') except DeviceException: self._logger.info(self._pars.id + ": Directory {0} was already empty.".format(directory)) # Verify which camera app is used and run the below commands only if Intel camera is used. if self._camera_app in ("Android_Intel_Camera_v2.2", "Android_Intel_Refcam2_v0.9", "Android_Google_Camera_v2.4", "Android_Intel_RefCam_v1.0"): #Open the camera app to check the initial camera used(Front or Back) self._camera_api.launch_system_camera_application(checkTriglogMsg = True, reset = True) # Wait for 4 second to load the camera app. the first launch takes longer due to driver initialization time.sleep(4) # Check camera in use and if it is not what user has chosen to be used, change it. stat = self._camera_api.get_camera_in_use() if stat != self._pars.camera_to_use: # We need to switch the camera in use. if stat == "BACK": self._camera_api.change_camera("front") elif stat == "FRONT": self._camera_api.change_camera("back") else: raise DeviceException(DeviceException.INVALID_DEVICE_STATE, self._pars.id + ": Camera used is " + stat + ", failing test.") # Wait for 2 second to switch camera time.sleep(2) # Verify whether the camera is changed or not. check_f = self._camera_api.get_camera_in_use() if self._pars.camera_to_use == check_f: self._logger.info("{0}: {1} camera is now selected.".format(self._pars.id, self._pars.camera_to_use)) else: self._logger.error("{0}: Camera is not changed".format(self._pars.id)) raise DeviceException(DeviceException.INVALID_DEVICE_STATE, "{0}: Camera in use should be {1} but is still {2}.".format(self._pars.id, self._pars.camera_to_use, check_f)) while (time.time() < end_time): self._logger.info(self._pars.id + ": Starting loop {0}".format(loop)) time_start1 = float(time.time()) self._logger.info(self._pars.id + ": Start image capturing:") if not osbv_utils.set_focus_lock(appSignature, timeout_sec=self.gui_lock_wait_time): # Could not set the focus-lock raise DeviceException(DeviceException.OPERATION_FAILED, self._pars.id + ": Failed to set focus lock.") if self._pars.restart_app: # Stops and starts app. self._camera_api.launch_system_camera_application(checkTriglogMsg = True, reset = True) else: # Displays app if not started. self._camera_api.launch_system_camera_application(checkTriglogMsg = True) # Wait for 1 second to re-load the camera app time.sleep(1) if self._camera_app in ("Android_Intel_Refcam2_v0.9", "Android_Intel_RefCam_v1.0"): # take picture if self._pars.camera_mode == "BURST": #Settings for selecting burst mode self._camera_api.toggle_burst_mode() self._camera_api.camera_refcam_take_picture(1) else: self._camera_api.camera_refcam_take_picture(num_pics_to_take) else : # Sleeps default of 5 seconds between each picture for a non-burst mode. self._camera_api.camera_application_take_picture(num_pics_to_take) if not osbv_utils.release_focus_lock(appSignature): # Could not release the focus-lock raise DeviceException(DeviceException.OPERATION_FAILED, self._pars.id + ": Failed to release focus lock.") retVal = int(self._camera_api.move_files_to_backup_dir(self._camera_api.device_save_directory)) if (retVal - numPicsTaken) == 0: # Check the error type and increment errorCount appropriately errorCode = self._camera_api.check_for_camera_issues(errorCount) # Reset the retry counter if this is a known issue if errorCode != 'unclassifiedFail': retry = max_retries if retry < 1: # The test failed self.fail_test_cleanup(numPicsTaken, errorCount) self.ts_verdict_msg = self._pars.id + ": Too many loop retries, test has failed." raise DeviceException(DeviceException.OPERATION_FAILED, self._pars.id + ": Failed to execute correctly.") self._logger.info(self._pars.id + ": This iteration of image capture failed. Allowing %d more attempts..."%(retry-1)) retry -= 1 continue elif retry < max_retries: # image_capture recovered, so reset the retry counter retry = max_retries numPicsTaken = retVal # Count iteration time self.delta(time_start1,1, loop) loop += 1 if ((loop % 20) == 0): self._logger.info(self._pars.id + ': Copy newly captured images to host dir: {0}'.format(self.host_save_folder)) time_start2 = float(time.time()) #Pull pics to host every 20 iterations of loop. self._camera_api.upload_output_files(False, self.host_save_folder) self.delta(time_start2, 2, loop) # Sleep at random interval between min and max before moving towards next loop iteration. time.sleep(random.randint(self._pars.picture_interval_min, self._pars.picture_interval_max)) self._logger.info(self._pars.id + ": Number of pictures taken = %d"%numPicsTaken) # Times up! The test passed if it made it this far without encountering a failure and we've taken pictures. time_start2= float(time.time()) self.delta(time_start2,2, loop) # The test passed unless 0 pictures were taken. if numPicsTaken < 1: self._logger.info(self._pars.id + ' is at the end of the test but has {0} pictures were taken... faling test.'.format(numPicsTaken)) self.fail_test_cleanup(numPicsTaken, errorCount) self.ts_verdict_msg = self._pars.id + ": Finished loop without any pictures taken!" raise DeviceException(DeviceException.OPERATION_FAILED, self._pars.id + ": Failed to execute correctly.") else: self.pass_test_cleanup(numPicsTaken, errorCount) except OSError as e: self._logger.error(self._pars.id + ": OS Error({0}): {1}".format(e.errno, e.strerror)) raise except: import traceback self._logger.error(self._pars.id + ": Unexpected exception -> " + str(sys.exc_info()[0])) self._logger.error(traceback.format_exc()) self.ts_verdict_msg = self._pars.id + ": Unexpected exception being raised" raise finally: # Check if focus lock still exists with video capture's appSignature and remove if so. if appSignature == osbv_utils.get_lock_signature(): if not osbv_utils.release_focus_lock(appSignature): # Unable to release the focus-lock raise DeviceException(DeviceException.OPERATION_FAILED, self._pars.id + ": Failed to release focus lock.") self._logger.info(self._pars.id + ": Test step finished.") #Close the camera after the test is completed. self._camera_api.stop_system_camera_application()
def _create_sut(self, test_step_pars=None): self._sut = GetWifiConnectionTarget(None, None, test_step_pars, mock.Mock()) DeviceManager().get_device = self._return_device return self._sut