示例#1
0
class LiveDsdsFtMms(UseCaseBase):
    """
    Use Case Live SMS loopback class.
    """
    def __init__(self, tc_name, global_config):

        UseCaseBase.__init__(self, tc_name, global_config)

        self.awake = False
        self._test_timeout = 10
        self._call_setup_time = 15
        self.d = Device(self._device.retrieve_serial_number())
        self._registration_timeout = \
            int(self._dut_config.get("registrationTimeout"))

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

        self._repeat_count = 0
        repeat_count = self._tc_parameters.get_param_value("REPEAT_COUNT", "0")
        if repeat_count and repeat_count.isdigit():
            self._repeat_count = int(repeat_count)

        self._destination_number = \
            str(self._tc_parameters.get_param_value("DESTINATION_NUMBER"))
        # Retrieve the mms_type parameters.
        self._mms_type = self._tc_parameters.get_param_value("MMS_TYPE")

        # Retrieve the MMS subject.
        self._mms_subject = self._tc_parameters.get_param_value("MMS_SUBJECT")

        if self._mms_type == "text":
            self._attachment_file = None
        else:
            self._multimedia_path = self._device.multimedia_path
            # Retrieve the path of the MMS attachment.
            self._attachment_file = os.path.join(
                self._multimedia_path,
                self._tc_parameters.get_param_value("ATTACHED_FILE"))

        # Retrieve the time that the test should wait to receive the MMS.
        self._send_mms_timeout = \
            int(self._tc_parameters.get_param_value("SENT_MMS_TIMEOUT"))
        self._message=\
            str(self._tc_parameters.get_param_value("MESSAGE_CONTENT", ""))

        self._received_mms_timeout = \
            int(self._tc_parameters.get_param_value("RECEIVED_MMS_TIMEOUT"))
        self._test_timeout = 10
        self._phone = DeviceManager().get_device("PHONE1")

        self._phone2 = DeviceManager().get_device("PHONE2")

        self._phone_number2 = str(self._phone2.get_phone_number())
        self._default_sim = self._tc_parameters.get_param_value("DEFAULT_SIM")

        self._network_pref = self._tc_parameters.get_param_value(
            "PREFERRED_NETWORK_TYPE", None)
        if self._network_pref:
            self._network_pref = self._network_pref.upper()
        self._initial_pref_network = None
        #Parameter to download or upload
        self._direction = self._tc_parameters.get_param_value("DIRECTION")
        self._server_name = \
            self._tc_parameters.get_param_value("SERVER_NAME",
                                                "LAB_SERVER")
        self._callduration = \
             int(self._tc_parameters.get_param_value("CALL_DURATION"))

        # Get FTP server parameters
        self._server = \
            global_config.benchConfig.get_parameters(self._server_name)
        self._server_ip_address = self._server.get_param_value("IP")
        self._username = self._server.get_param_value("username")
        self._password = self._server.get_param_value("password")
        if self._server.has_parameter("ftp_path"):
            self._ftp_path = self._server.get_param_value("ftp_path")
        else:
            self._ftp_path = ""

        #The file need to download
        self._dlfilename = os.path.join(
            self._ftp_path, self._tc_parameters.get_param_value("DL_FILE", ""))
        #Max time for file transfer
        self._xfer_timeout = \
            int(self._tc_parameters.get_param_value("XFER_TIMEOUT"))

        # The base name of the file we download
        self._ftp_file_basename = self._tc_parameters.get_param_value(
            "BASENAME")
        self._system_api = self._device.get_uecmd("System")
        self._sms_api = self._device.get_uecmd("SmsMessaging")
        self._sms_api2 = self._phone2.get_uecmd("SmsMessaging")
        self._mms_api = self._device.get_uecmd("MmsMessaging")
        self._mms_api2 = self._phone2.get_uecmd("MmsMessaging")
        self._sms_api2 = self._phone2.get_uecmd("SmsMessaging")

        #self._voice_call_api2 = self._phone2.get_uecmd("VoiceCall")
        self._networking_api = self._device.get_uecmd("Networking")
        self._phone_system_api = self._device.get_uecmd("PhoneSystem")
        #self._phone_system_api2 = self._phone2.get_uecmd("PhoneSystem")
        self._ftp_api = self._device.get_uecmd("Ftp")
        self._modem_api = self._device.get_uecmd("Modem")
        self._phonesystem_api = self._device.get_uecmd("PhoneSystem")
        #self._phone_system_api2 = self._phone2.get_uecmd("PhoneSystem")

        self._networking_api = self._device.get_uecmd("Networking")
        #self._voice_call_api2 = self._phone2.get_uecmd("VoiceCall")
        #self._networking_api2 = self._phone2.get_uecmd("Networking")
        self._voicecall_api = self._phone.get_uecmd("VoiceCall")

        if self._phone2 is not None:
            self._voice_call_api2 = self._phone2.get_uecmd("VoiceCall")
            self._networking_api2 = self._phone2.get_uecmd("Networking")
            self._phone_system_api2 = self._phone2.get_uecmd("PhoneSystem")
#--------------------------------------------------------------------------------------

    def set_up(self):
        """
        Setup for the test case
        """

        # Call set_up of use case base
        UseCaseBase.set_up(self)

        # Check if we have the second phone available
        if self._phone2 is None:
            # We are using this multi UC with only one phone
            error_msg = \
                "This use case requires two phones to be executed !"
            self._logger.error(error_msg)
            raise AcsConfigException(AcsConfigException.INVALID_BENCH_CONFIG,
                                     error_msg)

        # Boot the other phone (the DUT is already booted)
        if not self._phone2.is_available():
            DeviceManager().boot_device("PHONE2")
        if self._default_sim == "SIM2":
            #Setting the sim to Default
            (verdict, msg) = self._setDefaultSecondSim()
        else:
            (verdict, msg) = self._setDefaultSim()

        time.sleep(10)
        self._absolute_path_on_dut = "".join(
            [self._device.multimedia_path, self._ftp_file_basename])

        # Delete the FTP download file on the DUT
        self._delete_file_if_exists(self._absolute_path_on_dut)

        # Disable flight mode
        self._networking_api.set_flight_mode("off")
        time.sleep(self._wait_btwn_cmd)

        if self._mms_type.lower() == "picture":
            # Checks if the attachment file exist.
            self._phonesystem_api.check_file_exist(self._attachment_file)

        # Kill the messaging application.
        self._kill_messaging_app()

        time.sleep(self._wait_btwn_cmd)

        # There is a preferred network to set, backup initial, then set configured one
        if self._network_pref is not None:
            self._initial_pref_network = self._dut_config.get(
                "defaultPreferredNetwork")
            time.sleep(self._wait_btwn_cmd)

            if self._networking_api.is_preferred_network_type_valid(
                    self._network_pref):
                # Setting the DUT preferred network type to the one specified
                # in the TC.
                self._networking_api.set_preferred_network_type(
                    self._network_pref)
                time.sleep(self._wait_btwn_cmd)

                # Check the DUT is camped on a compatible network with the selected
                # preferred network.
                self._modem_api.check_rat_with_pref_network(
                    self._network_pref, self._registration_timeout)
                time.sleep(self._wait_btwn_cmd)
            else:
                raise AcsConfigException(
                    AcsConfigException.INVALID_PARAMETER,
                    "Unknown network type: %s" % self._network_pref)

        return verdict, msg
#--------------------------------------------------------------------------------------

    def run_test(self):
        """
        Execute the test
        """
        #Call UseCase base run function
        UseCaseBase.run_test(self)

        queue = Queue.Queue()
        #creating empty list to append the threads
        threads = []
        #creating empty list to append the return value from the threads
        result = []
        try:
            #creating thread object to trigger to the _ftpdownloads method
            thread_ftp = Thread(target=self._ftpdownload, args=[queue])
            thread_ftp.setName("Thread1")
            #to start the thread object
            thread_ftp.start()
            time.sleep(10)
            #creating thread object to trigger to the _smssendreceive method
            thread_mms = Thread(target=self._sendmms, args=[queue])
            thread_mms.setName("Thread2")
            #to start the thread object
            thread_mms.start()
        except Exception as inst:
            self._logger.info(inst)
            raise AcsConfigException(AcsConfigException.OPERATION_FAILED,
                                     "Exception: %s" % inst)
            return Global.FAILURE, "Error"

        #appending the thread object into the empty list
        threads.append(thread_ftp)
        #appending the thread object into the empty list
        threads.append(thread_mms)
        for thread_id in threads:
            #to make the thread wait for the other thread does not complete
            thread_id.join()
            #appending the return value to the list
            result.append(queue.get())
        #checking the return value is SUCCESS
        if (result[0] or result[1]) == Global.SUCCESS:
            return Global.SUCCESS, "SUCCESSFULL"
        else:
            return Global.FAILURE, "Error"

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

    def _ftpdownload(self, queue):
        """
        Execute the web browsing
        """
        #creating the lock
        lock = threading.Lock()
        lock.acquire()
        try:
            self._logger.info("inside _ftpdownload function")
            #Thread no
            self._logger.info(current_thread())
            #checking the pdp status
            pdp_context_status = self._networking_api._get_pdp_context_status()
            if pdp_context_status in ("0", "2"):
                self._networking_api.activate_pdp_context()
            time.sleep(self._wait_btwn_cmd)
            if self._direction == "DL":
                self._logger.info("FTP transfer " + str(self._direction) +
                                  " for " + str(self._dlfilename) + "...")
                # Uecmd to do ftp and storing the result
                result = self._networking_api.\
                    ftp_xfer(self._uecmd_types.XFER_DIRECTIONS.DL,  # pylint: disable=E1101
                             self._server_ip_address,
                             self._username,
                             self._password,
                             self._dlfilename,
                             self._xfer_timeout,
                             self._device.multimedia_path)
            else:
                self._error.Code = Global.FAILURE
                self._error.Msg = "%s is not a known xfer direction" % self._direction
                self._logger.info(self._error.Msg)
                queue.put(self._error.Code)
        except Exception as inst:
            self._error.Code = Global.FAILURE
            queue.put(self._error.Code)
            self._logger.info(inst)
            raise AcsConfigException(AcsConfigException.OPERATION_FAILED,
                                     "Exception : %s" % inst)
        finally:
            #lock is released
            lock.release()
            self.awake = True
        #giving the return value into queue
        queue.put(Global.SUCCESS)
#---------------------------------------------------------------------------------------------

    def _sendmms(self, queue):

        lock = threading.Lock()
        lock.acquire()
        try:
            time_to_receive_mms = None
            time_to_send_mms = None
            time_waited = 0

            # Max number of iteration done while waiting for the screen to turn off.
            # Used to prevent endless loops.
            max_time_waited = 200

            # Clear all SMS and MMS.
            self._mms_api.delete_all_messages()

            # Wait for the screen to turn off.
            while self._phonesystem_api.get_screen_status() \
                and time_waited < max_time_waited:
                time.sleep(5)
                time_waited += 5
            self._logger.info("Waited %s seconds for the screen to turn off." %
                              time_waited)
            # Checks if the screen turned off before a fixed timeout.
            if time_waited >= max_time_waited:
                raise DeviceException(
                    DeviceException.TIMEOUT_REACHED,
                    "The screen did not turned off in %s." % max_time_waited)

            # Wake up the phone screen.
            time.sleep(self._wait_btwn_cmd)
            self._logger.info("Turning the screen on.")
            self._phonesystem_api.set_phone_lock("off")
            self._phonesystem_api.wake_screen()
            self._phonesystem_api.set_phone_lock(0)

            # register on intent to receive incoming mms
            self._mms_api2.register_for_mms_reception()

            # Build the MMS.
            time.sleep(self._wait_btwn_cmd)
            self._mms_api.send_mms(self._mms_type, self._destination_number,
                                   self._mms_subject, self._message,
                                   self._attachment_file, self._repeat_count)

            time.sleep(self._wait_btwn_cmd)

            # Waiting for the MMS to be send.
            sent_time = self._mms_api.check_mms_sent(self._destination_number,
                                                     self._send_mms_timeout)

            # Waiting on incoming message.
            reception_date = self._mms_api2.wait_for_incoming_mms(
                self._received_mms_timeout, self._destination_number)

            # Logging the time taken to receive the MMS.
            time_to_receive_mms = float(reception_date) - float(sent_time)

            self._logger.info("The MMS has been received in %s seconds." %
                              time_to_receive_mms)

            # Compare the sent and received MMS.
            self._mms_api.request_remote_send_received_mms_compare(
                self._mms_type)
        except Exception as inst:
            self._error.Code = Global.FAILURE
            queue.put(self._error.Code)
            self._logger.info(inst)
            raise AcsConfigException(AcsConfigException.OPERATION_FAILED,
                                     "Exception : %s" % inst)
        finally:
            #lock is released
            lock.release()
            print("the awake for ftp")
            print(self.awake)

        queue.put(Global.SUCCESS)
#--------------------------------------------------------------------------------------------------

    def _setDefaultSim(self):

        self._device.run_cmd("adb shell input keyevent 82",
                             self._test_timeout,
                             force_execution=True)
        time.sleep(8)
        #To pop up the dialog box for selecting the sim
        statusintent = self._voicecall_api.get_sim_select(dialog=3, sim=0)
        self._logger.info(statusintent)
        #To check dailog is reached or not
        if statusintent == {}:
            err_msg = " The option dialog is not reached"
            raise DeviceException(DeviceException.OPERATION_SET_ERROR, err_msg)
            return Global.FAILURE, err_msg
        #Waiting for the dailog box
        if self.d(resourceId='android:id/title_template').wait.exists(
                timeout=5000):
            #clicking the default sim
            self.d(resourceId='android:id/button1').click()
            self._logger.info("Default sim is selected")
            return Global.SUCCESS, "Default sim is selected"
        else:
            err_msg = "Dialog is not opening"
            raise DeviceException(DeviceException.OPERATION_SET_ERROR, err_msg)
            return Global.FAILURE, err_msg

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

    def _setDefaultSecondSim(self):

        self._device.run_cmd("adb shell input keyevent 82",
                             self._test_timeout,
                             force_execution=True)
        time.sleep(8)
        #To pop up the dialog box for selecting the sim
        statusintent = self._voicecall_api.get_sim_select(dialog=3, sim=1)
        self._logger.info(statusintent)
        #To check dailog is reached or not
        if statusintent == {}:
            err_msg = " The option dialog is not reached"
            raise DeviceException(DeviceException.OPERATION_SET_ERROR, err_msg)
            return Global.FAILURE, err_msg
        #Waiting for the dailog box
        if self.d(resourceId='android:id/title_template').wait.exists(
                timeout=5000):
            #clicking the default sim
            self.d(resourceId='android:id/button1').click()
            self._logger.info("Default sim is selected")
            return Global.SUCCESS, "Default sim is selected"
        else:
            err_msg = "Dialog is not opening"
            raise DeviceException(DeviceException.OPERATION_SET_ERROR, err_msg)
            return Global.FAILURE, err_msg

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

    def _delete_file_if_exists(self, file_path, fail_on_error=True):
        """
        Deletes the given file on DUT if it exists.

        :type file_path: str
        :param file_path: the absolute path of the file to delete.

        :type fail_on_error: bool
        :param fail_on_error: [optional] a boolean indicating whether
            we want to raise an exception on error or not.
            Defaults to C{True}.
        """
        # Force file path to a str value
        file_path = str(file_path)
        rm_cmd = "adb shell rm %s" % file_path
        # We go on only if the file exists on the DUT
        if not self._phone_system_api.check_file_exist_from_shell(file_path):
            self._logger.debug("No such file to delete.")
            return
        # We try to delete the file
        try:
            # Run the command to remove the file, we give it 10 seconds to run
            self._logger.debug("Deleting file %s." % file_path)
            (exit_status, _output) = internal_shell_exec(rm_cmd, 10)
        except (KeyboardInterrupt, SystemExit):
            raise
        # We want to trap any kind of error/exception so
        # we use an empty exception clause and disable the
        # corresponding Pylint warning.
        # pylint: disable=W0702
        except:
            exit_status = Global.FAILURE
            traceback.print_exc()

        # Check the status of the command execution
        if exit_status != Global.SUCCESS:
            # Build an error message
            error_message = "Command execution failed (command: '%s')." % rm_cmd
            # Handle the error case as expected
            if fail_on_error:
                # If we have to fail, raise an exception
                raise DeviceException(DeviceException.OPERATION_FAILED,
                                      error_message)
            else:
                # Otherwise simply log a warning
                self._logger.warning(error_message)

        # We double-check that the file has been deleted
        if self._phone_system_api.check_file_exist_from_shell(file_path):
            # Build an error message
            error_message = "File deletion failed (file: '%s')." % file_path
            # Handle the error case as expected
            if fail_on_error:
                # If we have to fail, raise an exception
                raise DeviceException(DeviceException.OPERATION_FAILED,
                                      error_message)
            else:
                # Otherwise simply log a warning
                self._logger.warning(error_message)
        else:
            self._logger.info("File %s deleted successfully." % file_path)

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

    def _kill_messaging_app(self):
        """
        Kills the MMS application if it was running and makes sure it has been
        killed successfully
        """
        # Get the pid of the MMS application
        pid = self._system_api.pid_of("com.android.mms")
        # Killing the MMS application, if running
        if pid != "":
            self._mms_api.kill_mms_app()
            # Checking if the MMS application as really been killed.
            new_pid = self._system_api.pid_of("com.android.mms")
            if new_pid == pid:
                raise DeviceException(
                    DeviceException.OPERATION_FAILED,
                    "The stock messaging application"
                    " should not be running.")
        else:
            self._logger.info("The MMS application was not running.")
class LiveDualPhoneSms(UseCaseBase):
    """
    Live Dual Phone SMS test.
    """
    def __init__(self, tc_name, global_config):
        """
        Constructor
        """
        UseCaseBase.__init__(self, tc_name, global_config)

        # Get TC Parameters
        self._service_center_addr = \
            self._tc_parameters.get_param_value("SERVICE_CENTER_ADDRESS")
        self._destination = \
            str(self._tc_parameters.get_param_value("DESTINATION_NUMBER"))
        self._message = self._tc_parameters.get_param_value("MESSAGE_CONTENT")
        self._data_coding_sheme = \
            self._tc_parameters.get_param_value("DATA_CODING_SCHEME")
        self._sms_transfer_timeout = \
            int(self._tc_parameters.get_param_value("SMS_TRANSFER_TIMEOUT"))

        dcs = DataCodingScheme(self._data_coding_sheme)
        dcs.decode()

        # Get number of bits per character setted in DCS
        self._nb_bits_per_char = dcs.compute_character_size()

        character_set = dcs.get_character_set()

        if character_set == "7BITS":
            self._content_type = "CTEX"
        else:
            self._content_type = "CDAT"

        # Phone1 & 2 : Get ue command for Phone
        self._msg_api = self._device.get_uecmd("SmsMessaging")
        self._networking_api = self._device.get_uecmd("Networking")
        self._phone2 = DeviceManager().get_device("PHONE2")
        if self._phone2 is not None:
            self._msg_api2 = self._phone2.get_uecmd("SmsMessaging")
            self._networking_api2 = self._phone2.get_uecmd("Networking")
            if self._destination.upper() == "[PHONE_NUMBER]":
                self._destination = str(self._phone2.get_phone_number())

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

    def set_up(self):
        """
        Initialize the test
        """
        UseCaseBase.set_up(self)

        # 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)
        DeviceManager().boot_device("PHONE2")

        # Disable flight mode on Phone 1 & 2
        self._networking_api.set_flight_mode("off")
        self._networking_api2.set_flight_mode("off")

        self._msg_api.set_service_center_address(self._service_center_addr)

        return Global.SUCCESS, "No errors"

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

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

        # Clear old SMS (Non blocking for this test if function isn't
        # implemented on CDK)
        time.sleep(self._wait_btwn_cmd)
        self._logger.info("Clearing all sms...")
        self._msg_api2.delete_all_sms()

        # Calculate how many SMS will be sent to equipment
        time.sleep(self._wait_btwn_cmd)
        self._logger.info("Computing sms segments...")
        nb_segments = \
            compute_sms_segments(self._message,
                                 self._nb_bits_per_char)

        # Phone2 : Wait for the sms
        # retrieve instance in order to get sent messages
        time.sleep(self._wait_btwn_cmd)
        # register on intent to receive incoming sms
        self._msg_api2.register_for_sms_reception()

        # Phone1: Check SMS delivery status OK before timeout using
        # SMS_TRANSFER_TIMEOUT value and number of SMS to be received
        # (Non blocking for this test if function isn't implemented on CDK)
        time.sleep(self._wait_btwn_cmd)
        self._logger.info("Sending sms from DUT...")
        self._msg_api.send_sms(self._destination, self._message)

        # Phone2: get sms received
        time.sleep(self._wait_btwn_cmd)
        self._logger.info("Assembling received sms...")
        sms_received = self._msg_api2.wait_for_incoming_sms(
            self._sms_transfer_timeout)

        if sms_received.message == self._message:
            result_code = Global.SUCCESS
            result_message = "Sms text received and sms text sent are equal"
            result_message += " (sent:{%s}, received:{%s})." % (str(
                self._message), str(sms_received.message))
            self._logger.info(result_message)
        else:
            result_code = Global.FAILURE
            result_message = "Sms text received and sms text sent aren't equal"
            result_message += " (sent:{%s}, received:{%s})." % (str(
                self._message), str(sms_received.message))
            self._logger.error(result_message)

        return result_code, result_message

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

    def tear_down(self):
        """
        End and dispose the test
        """
        UseCaseBase.tear_down(self)

        # Phone2: Switch off the phone
        self._phone2.switch_off()

        return Global.SUCCESS, "No errors"
class LabAudioGlitchDetectionSwapCall(UseCaseBase):
    """
    AudioComms Audio Swap Call class.
    """
    def __compute_test_verdict__(self, audio_analyzer_result):

        if audio_analyzer_result == 0 and self._audio_analyzer_result_save == 0:
            self._result_verdict = Global.SUCCESS
        elif audio_analyzer_result == 1:
            # Update audio_analyser_result => error code 1 lower priority than error code 2
            if self._audio_analyzer_result_save == 0 or self._audio_analyzer_result_save == 3:
                self._audio_analyzer_result_save = 1
            # Save failed transition
            self._failed_transition_audio_pb = self._failed_transition_audio_pb + ", " + \
                self._previous_call_type_save + " => " + self._call_type_save
            self._result_verdict = Global.FAILURE
        elif audio_analyzer_result == 2:
            self._audio_analyzer_result_save = 2
            self._failed_transition_no_audio = self._failed_transition_no_audio + ", " + \
                self._previous_call_type_save + " => " + self._call_type_save
            self._result_verdict = Global.FAILURE
        elif audio_analyzer_result == 3:
            self._audio_analyzer_result_save = 3
            self._result_verdict = Global.FAILURE
            self._failed_transition_no_audio = self._failed_transition_no_audio + ", " + \
                self._previous_call_type_save + " => " + self._call_type_save
        else:
            if self._audio_analyzer_result_save == 0:
                self._audio_analyzer_result_save = 4
            self._result_verdict = Global.FAILURE

    def __init__(self, tc_name, global_config):
        """
        Constructor
        """

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

        # Create Audio Analyser
        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 = "glitchdetectiononswap"

        # Initialization of test result
        self._result_verdict = Global.FAILURE

        # Initialization of the verdict comment
        self._verdict_comment = "Audio Quality test fail"

        # Initialization of _dut_bt_address
        self._dut_bt_address = "None"

        # Initialization of audio_analyser_result saved
        self._audio_analyzer_result_save = 0
        self._audio_analyzer_result_ul = 0
        self._audio_analyzer_result_dl = 0

        # delta volume for voip
        self._delta_voip_volume = 10

        # Initialization of failed transition saved
        self._failed_transition_audio_pb = ""
        self._failed_transition_no_audio = ""
        self._previous_call_type_save = ""
        self._call_type_save = ""

        self._phone_calling_list = []
        self._phone_receiving_list = []
        self._phone_releasing_list = []
        self._ui_api_phone_list = []
        self._calling_phone_number = []
        # List Saving
        self._saved_call_list = []
        self._saved_call_end_type_list = []
        self._saved_call_origin_type_list = []
        self._call_type_list_audio_analyser_run = []

        # Instantiate the instances for phone caller, receiver and releaser
        self._phone_calling = None
        self._phone_receiving = None

        # 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 wifi parameters from bench config xml file (int)
        self._wifirouter = global_config.benchConfig.\
            get_parameters("WIFI_ACCESS_POINT")
        self._ssid = self._wifirouter.get_param_value("SSID")

        # Read accessories type from test case xml file (str)
        self._acc_type = \
            str(self._tc_parameters.get_param_value("ACC_TYPE"))

        # Read call type list from test case xml file (str)
        self._call_seq = str(
            self._tc_parameters.get_param_value("CALL_SEQUENCE"))
        # Split the call type list, call separated by ','
        self._call_seq = self._call_seq.strip('[] ')
        self._call_list = self._call_seq.split(',')
        self._call_list.reverse()

        # Read call origin list from test case xml file (str)
        self._call_origin_type = \
            str(self._tc_parameters.get_param_value("CALL_ORIGIN_TYPE_SEQUENCE"))
        # Split the call origin type list, call origin type separated by ','
        self._call_origin_type = self._call_origin_type.strip('[] ')
        self._call_origin_type_list = self._call_origin_type.split(',')
        self._call_origin_type_list.reverse()

        # Read call end type list from test case xml file (str)
        self._call_end_type = \
            str(self._tc_parameters.get_param_value("CALL_END_TYPE_SEQUENCE"))
        # Split the call end type list, call end type separated by ','
        self._call_end_type = self._call_end_type.strip('[] ')
        self._call_end_type_list = self._call_end_type.split(',')
        self._call_end_type_list.reverse()

        # Read call type from test case xml file (str)
        self._call_type = str(self._tc_parameters.get_param_value("CALL_TYPE"))

        # Call Stream Volume in percent
        self._call_stream_volume_dut = \
            int(self._tc_parameters.get_param_value("CALL_VOLUME_DUT"))

        # Call Stream Volume in percent
        self._call_stream_volume_ref = \
            int(self._tc_parameters.get_param_value("CALL_VOLUME_REF"))

        # 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 number of swap from test case xml file (int)
        self._number_of_swap = int(
            self._tc_parameters.get_param_value("SWAP_REPETITION"))

        # Read dut sip address from test case xml file (str)
        self._dut_sip_address = \
            str(self._tc_parameters.get_param_value("DUT_SIP_ADDRESS"))

        # Read ref phone sip address from test case xml file (str)
        self._peer_sip_address = \
            str(self._tc_parameters.get_param_value("PEER_SIP_ADDRESS"))

        # Read dut sip profile name from test case xml file (str)
        self._dut_sip_profile = \
            str(self._tc_parameters.get_param_value("DUT_SIP_PROFILE"))

        # Read ref phone sip profile name from test case xml file (str)
        self._peer_sip_profile = \
            str(self._tc_parameters.get_param_value("PEER_SIP_PROFILE"))

        # Read test call direction type from test case xml file (str)
        self._signal_tested_direction = \
            str(self._tc_parameters.get_param_value("SIGNAL_TESTED_DIRECTION"))

        # Read Audio Analyzer parameters from bench config xml file (str)
        self._audio_analyser = global_config.benchConfig.\
            get_parameters("AudioAnalyzer")
        self._bt_remote_addr = self._audio_analyser.get_param_value(
            "Bt_mac_addr")

        # Instantiate generic UECmd for voiceCall Ucs
        self._voice_call_api = self._device.get_uecmd("VoiceCall")
        self._phonesystem_api = self._device.get_uecmd("PhoneSystem")
        self._sip_call_api = self._device.get_uecmd("SipCall")
        self._phonemodem_api = self._device.get_uecmd("Modem")
        self._system_api = self._device.get_uecmd("System")
        self._networking_api = self._device.get_uecmd("Networking")
        self._ui_api = self._device.get_uecmd("Ui")
        self._ui_api.set_global_config(global_config)

        # Read Audio Analyzer parameters from bench config xml file (str)
        self._audio_analyser = global_config.benchConfig.get_parameters(
            "AudioAnalyzer")

        if self._acc_type.find("BLUETOOTH") != -1:
            # Get UECmdLayer
            self._bt_api = self._device.get_uecmd("LocalConnectivity")
            self._bt_remote_addr = self._audio_analyser.get_param_value(
                "Bt_mac_addr")

        # Load instance of the PHONE2
        self._phone2 = DeviceManager().get_device("PHONE2")
        # Instantiate system UECmd for Phone2
        self._system_api2 = None

        # Initialize UI object
        self._ui_api.init()

        # Connect the board
        self._device.connect_board()

        if self._phone2 is not None:
            if not self._phone2.is_available():
                self._phone2.switch_on(simple_switch_mode=True)
            self._voice_call_api2 = self._phone2.get_uecmd("VoiceCall")
            self._sip_call_api2 = self._phone2.get_uecmd("SipCall")
            self._ui_api2 = self._phone2.get_uecmd("Ui")
            self._ui_api2.set_global_config(global_config)
            self._system_api2 = self._phone2.get_uecmd("System")
            self._networking_api2 = self._phone2.get_uecmd("Networking")
            self._phonesystem_api2 = self._phone2.get_uecmd("PhoneSystem")
            self._ui_api2.init()
        else:
            error_msg = \
                "This test case requires two phones to be executed !"
            self._logger.error(error_msg)
            raise AcsConfigException(AcsConfigException.INVALID_BENCH_CONFIG,
                                     error_msg)

    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 None:
            # 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)

        self._phonesystem_api.wake_screen()
        # 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)

        # List Saving
        self._saved_call_list = list(self._call_list)
        self._saved_call_end_type_list = list(self._call_end_type_list)
        self._saved_call_origin_type_list = list(self._call_origin_type_list)

        # make list for call test type for audio_analyser
        l_temp_call_list = list(self._call_list)
        l_temp_call_list.reverse()
        self._call_type_list_audio_analyser_run = list(l_temp_call_list)
        num_of_swap_unpair = self._number_of_swap % 2
        i = self._number_of_swap
        while i > 1:
            self._call_type_list_audio_analyser_run += list(l_temp_call_list)
            i -= 1
        if num_of_swap_unpair > 0:
            # Grep last element of call list and insert at the top
            self._call_type_list_audio_analyser_run.insert(
                0, l_temp_call_list.pop())
        i = 1
        # Initialization of list for calling, receiving and releasing calls
        while len(self._saved_call_list) > 0:
            call_type = self._saved_call_list.pop()
            call_origin = self._saved_call_origin_type_list.pop()
            call_end = self._saved_call_end_type_list.pop()
            if call_origin == "MO":
                self._phone_calling_list.insert(i, self._voice_call_api)
                self._phone_receiving_list.insert(i, self._voice_call_api2)
                self._ui_api_phone_list.insert(i, self._ui_api2)
                if call_type == "2G" or call_type == "3G":
                    self._calling_phone_number.insert(
                        i, self._phone2.get_phone_number())
                elif call_type == "VOIP":
                    self._calling_phone_number.insert(i,
                                                      self._peer_sip_address)
                else:
                    error_msg = "This test case requires call type to be executed !"
                    self._logger.error(error_msg)
                    raise AcsConfigException(
                        AcsConfigException.INVALID_PARAMETER, error_msg)
            elif call_origin == "MT":
                self._phone_calling_list.insert(i, self._voice_call_api2)
                self._phone_receiving_list.insert(i, self._voice_call_api)
                self._ui_api_phone_list.insert(i, self._ui_api)
                if call_type == "2G" or call_type == "3G":
                    self._calling_phone_number.insert(
                        i, self._device.get_phone_number())
                elif call_type == "VOIP":
                    self._calling_phone_number.insert(i, self._dut_sip_address)
                else:
                    error_msg = "This test case requires call type to be executed !"
                    self._logger.error(error_msg)
                    raise AcsConfigException(
                        AcsConfigException.INVALID_PARAMETER, error_msg)
            else:
                error_msg = \
                    "This test case requires call originated type to be executed !"
                self._logger.error(error_msg)
                raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                         error_msg)

            if call_end == "NR":
                self._phone_releasing_list.insert(i, self._voice_call_api2)
            elif call_end == "MR":
                self._phone_releasing_list.insert(i, self._voice_call_api)
            else:
                error_msg = \
                    "This test case requires call end type to be executed !"
                self._logger.error(error_msg)
                raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                         error_msg)
            i += 1

        self._activate_wifi = False
        while len(self._saved_call_list) > 0:
            call_type = self._saved_call_list.pop()
            if call_type == "VOIP":
                self._activate_wifi = True
        if self._activate_wifi == True:
            if self._networking_api.get_wifi_power_status() == 0:
                # Turn Wifi interface ON
                self._networking_api.set_wifi_power("off")
                self._networking_api.set_wifi_power("on")
                # Configure the DUT
                self._networking_api.clean_all_data_connections()
                time.sleep(self._wait_btwn_cmd)
                # Connect to wifi using SSID parameter value for DUT
                self._networking_api.wifi_connect(self._ssid)
                time.sleep(self._wait_btwn_cmd)
            if self._networking_api2.get_wifi_power_status() == 0:
                self._networking_api2.set_wifi_power("off")
                self._networking_api2.set_wifi_power("on")
                self._networking_api2.clean_all_data_connections()
                time.sleep(self._wait_btwn_cmd)
                # Connect to wifi using SSID parameter value for Ref phone
                self._networking_api2.wifi_connect(self._ssid)
                time.sleep(self._wait_btwn_cmd)

        self._phonesystem_api.set_screen_timeout(900)
        self._phonesystem_api2.set_screen_timeout(900)

        # Audio Analyser Initialization
        if self._audio_analyzer.initialization(self._device.get_phone_model(),
                                               self._test_type) != 0:
            error_msg = "Audio Analyser Initialization Failed !"
            self._logger.error(error_msg)
            raise TestEquipmentException(
                TestEquipmentException.OPERATION_FAILED, error_msg)

        if self._acc_type.find("BLUETOOTH") != -1:
            self._dut_bt_address = self._bt_api.get_bt_adapter_address()

        self._sip_call_api.set_profile_sip_phone_app(self._dut_sip_profile)
        self._sip_call_api2.set_profile_sip_phone_app(self._peer_sip_profile)

        self._phone_calling_list.reverse()
        self._phone_receiving_list.reverse()
        self._phone_releasing_list.reverse()
        # self._calling_phone_number_list.reverse()
        self._ui_api_phone_list.reverse()
        self._calling_phone_number.reverse()

        # Release any previous call (Robustness)
        self._voice_call_api.release()
        self._voice_call_api2.release()

        return Global.SUCCESS, "No errors"

    def run_test(self):
        """
        Execute the test
        """
        # Call UseCaseBase run_test function
        UseCaseBase.run_test(self)

        if self._acc_type == "HEADSET":
            if self._use_io_card:
                self._wired_headset.unplug_headphone()
                self._wired_headset.plug_whs()
        elif self._acc_type == "HEADPHONE":
            if self._use_io_card:
                self._wired_headset.unplug_whs()
                self._wired_headset.plug_headphone()

        # Connect Bluetooth device
        if self._acc_type.find("BLUETOOTH") != -1:
            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)

        self._phonesystem_api.display_off()
        self._phonesystem_api2.display_off()
        self._phonesystem_api.display_on()
        self._phonesystem_api2.display_on()
        # Unlock phones
        self._ui_api2.run_operation_set("phone_unlock")
        self._ui_api.run_operation_set("phone_unlock")

        l_audio_analyzer_result = 3
        l_call_type = self._call_list.pop()
        l_phone_calling = self._phone_calling_list.pop()
        l_phone_receiving = self._phone_receiving_list.pop()
        l_phone_ui = self._ui_api_phone_list.pop()
        self._call_type_save = l_call_type

        # Dial using PHONE_NUMBER parameter
        l_phone_calling.dial(self._calling_phone_number.pop(), False)
        time.sleep(self._wait_btwn_cmd)

        if l_call_type == "2G" or l_call_type == "3G":
            # Wait for state "active" before callSetupTimeout seconds
            l_phone_receiving.wait_for_state(
                self._uecmd_types.VOICE_CALL_STATE.INCOMING,
                self._call_setup_time)
            # Answer call
            l_phone_receiving.answer()

            # Phone1 & 2 : Check voice call is active
            l_phone_calling.wait_for_state(
                self._uecmd_types.VOICE_CALL_STATE.ACTIVE,
                self._call_setup_time)
            l_phone_receiving.wait_for_state(
                self._uecmd_types.VOICE_CALL_STATE.ACTIVE,
                self._call_setup_time)

        elif l_call_type == "VOIP":
            # Wait for state "active" before callSetupTimeout seconds
            l_phone_receiving.wait_for_audio_state(
                self._uecmd_types.AUDIO_STATE.RINGTONE, self._call_setup_time)
            # Answer call
            l_phone_ui.run_operation_set("call_answer")

            # Phone1 & 2 : Check voice call is active
            l_phone_calling.wait_for_audio_state(
                self._uecmd_types.AUDIO_STATE.IN_COMMUNICATION,
                self._call_setup_time)
            l_phone_receiving.wait_for_audio_state(
                self._uecmd_types.AUDIO_STATE.IN_COMMUNICATION,
                self._call_setup_time)

        # Configure Audio output to acc_type given with the test_case
        if self._acc_type == "EARPIECE":
            if self._use_io_card:
                self._wired_headset.unplug_headphone()
                self._wired_headset.unplug_whs()
        elif self._acc_type == "SPEAKER":
            # Switch to Speaker, nothing to do in Earpiece
            # Bluetooth already done with connect Bluetooth function above
            self._phonesystem_api.switch_audio_output(self._acc_type.lower())
            time.sleep(self._wait_btwn_cmd)

        # Voice call volume settings
        if self._acc_type.find("BLUETOOTH") == -1:
            # Set Voice Call Volume
            self._system_api.adjust_specified_stream_volume(
                "VoiceCall", self._call_stream_volume_dut)
        else:
            # Set Voice Call Volume
            self._system_api.adjust_specified_stream_volume(
                "Bluetooth", self._call_stream_volume_dut)

        self._system_api2.adjust_specified_stream_volume(
            "VoiceCall", self._call_stream_volume_ref)

        # WAIT FOR CALL DURATION
        self._logger.info("Wait for call duration: %s s..." %
                          str(self._call_duration))

        l_call_type = self._call_list.pop()
        l_phone_calling = self._phone_calling_list.pop()
        l_phone_receiving = self._phone_receiving_list.pop()
        l_phone_ui = self._ui_api_phone_list.pop()
        self._previous_call_type_save = self._call_type_save
        self._call_type_save = l_call_type
        # Dial using PHONE_NUMBER parameter
        l_phone_calling.dial(self._calling_phone_number.pop(), False)
        time.sleep(self._wait_btwn_cmd)

        if l_call_type == "2G" or l_call_type == "3G":
            # Wait for state "active" before callSetupTimeout seconds
            l_phone_receiving.wait_for_state(
                self._uecmd_types.VOICE_CALL_STATE.INCOMING,
                self._call_setup_time)
            # Answer call
            l_phone_receiving.answer()
            # Phone1 & 2 : Check voice call is active
            l_phone_calling.wait_for_state(
                self._uecmd_types.VOICE_CALL_STATE.ACTIVE,
                self._call_setup_time)
            l_phone_receiving.wait_for_state(
                self._uecmd_types.VOICE_CALL_STATE.ACTIVE,
                self._call_setup_time)
        else:
            # Answer call
            time.sleep(5)
            l_phone_ui.run_operation_set("call_answer")

            # Phone1 & 2 : Check voice call is active
            l_phone_calling.wait_for_audio_state(
                self._uecmd_types.AUDIO_STATE.IN_COMMUNICATION,
                self._call_setup_time)
            l_phone_receiving.wait_for_audio_state(
                self._uecmd_types.AUDIO_STATE.IN_COMMUNICATION,
                self._call_setup_time)

        self._call_type_list_audio_analyser_run.pop()

        while self._number_of_swap > 0:

            self._phonesystem_api2.wake_screen()
            time.sleep(self._wait_btwn_cmd)
            self._ui_api2.run_operation_set("swap_call")

            call_type_audio_analyzer = self._call_type_list_audio_analyser_run.pop(
            )
            if call_type_audio_analyzer == "VOIP":
                self._system_api2.adjust_specified_stream_volume(
                    "VoiceCall",
                    (self._call_stream_volume_ref + self._delta_voip_volume))
            else:
                self._system_api2.adjust_specified_stream_volume(
                    "VoiceCall", self._call_stream_volume_ref)

            self._phonesystem_api.wake_screen()
            time.sleep(self._wait_btwn_cmd)

            # Launch audio_quality test
            l_audio_analyzer_ready, l_audio_analyzer_process = self._audio_analyzer.glitch_detection_before_switch(
                self._test_type, self._device.get_phone_model(),
                call_type_audio_analyzer, self._acc_type,
                self._signal_tested_direction)

            if l_audio_analyzer_ready == 0:
                self._ui_api.run_operation_set("swap_call")

                l_audio_analyzer_result = self._audio_analyzer.glitch_detection_after_switch(
                    l_audio_analyzer_process)

            # Compute test verdict
            self.__compute_test_verdict__(l_audio_analyzer_result)

            self._previous_call_type_save = self._call_type_save
            self._call_type_save = call_type_audio_analyzer
            self._number_of_swap -= 1

        l_phone_releasing = self._phone_releasing_list.pop()
        # Hang up call
        l_phone_releasing.release(False)
        time.sleep(self._wait_btwn_cmd)

        l_phone_releasing = self._phone_releasing_list.pop()
        # Hang up call
        l_phone_releasing.release()

        # Phone1 & 2 : Check call is idle
        l_phone_calling.wait_for_state(
            self._uecmd_types.VOICE_CALL_STATE.NOCALL, self._call_setup_time)
        l_phone_receiving.wait_for_state(
            self._uecmd_types.VOICE_CALL_STATE.NOCALL, self._call_setup_time)

        if self._audio_analyzer_result_save == 0:
            self._verdict_comment = (
                "Audio Glitch detection test success with %s call sequence" %
                (str(self._tc_parameters.get_param_value("CALL_SEQUENCE"))))
        elif self._audio_analyzer_result_save == 1:
            self._verdict_comment = (
                "Audio Glitch detection test fail: Glitch "
                "problems detected in %s with "
                "%s call sequence" % (self._signal_tested_direction,
                                      self._failed_transition_audio_pb))
        elif self._audio_analyzer_result_save == 2:
            self._verdict_comment = (
                "Audio Glitch detection test fail: No audio signal in %s with "
                "%s call sequence" % (self._signal_tested_direction,
                                      self._failed_transition_no_audio))
        elif self._audio_analyzer_result_save == 3:
            self._verdict_comment = (
                "Audio Glitch detection test fail: Exception in executable "
                "in %s with %s call sequence" %
                (self._signal_tested_direction,
                 self._failed_transition_no_audio))
        else:
            self._verdict_comment = (
                "Audio Glitch detection test fail: Unknown problems detected "
                "with a %s call sequence" %
                (str(self._tc_parameters.get_param_value("CALL_SEQUENCE"))))

        return self._result_verdict, self._verdict_comment

    def tear_down(self):
        """
        End and dispose the test
        """

        # Call UseCaseBase tear_down function
        UseCaseBase.tear_down(self)

        if self._acc_type == "HEADSET":
            if self._use_io_card:
                self._wired_headset.unplug_whs()
        elif self._acc_type == "HEADPHONE":
            if self._use_io_card:
                self._wired_headset.unplug_headphone()

        # Release any previous call (Robustness)
        if self._voice_call_api is not None:
            self._voice_call_api.release(False)
        if self._voice_call_api2 is not None:
            self._voice_call_api2.release(False)

        self._sip_call_api.delete_profile_sip_phone_app()
        self._sip_call_api2.delete_profile_sip_phone_app()

        # Reset Voice Call Volume at 70%
        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)

        # Disable Wifi connections
        if self._result_verdict != Global.SUCCESS:
            if self._networking_api is not None:
                self._networking_api.clean_all_data_connections()
                time.sleep(self._wait_btwn_cmd)
                self._networking_api.set_wifi_power("off")
            if self._networking_api2 is not None:
                self._networking_api2.clean_all_data_connections()
                time.sleep(self._wait_btwn_cmd)
                self._networking_api2.set_wifi_power("off")

        return Global.SUCCESS, "No errors"
示例#4
0
class LabAudioAPxCalibrationCSV(UseCaseBase):
    """
    AudioComms calibration APx class.
    """
    def __init__(self, tc_name, global_config):
        """
        Constructor
        """

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

        # Create APx
        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 = "calibration"

        # Initialization of test result in uplink
        self._result_verdict_ul = Global.FAILURE
        # Initialization of test result in downlink
        self._result_verdict_dl = Global.FAILURE
        # Initialization of test result
        self._result_verdict_final = Global.FAILURE

        # Call Stream Volume
        self._call_stream_volume = 70

        # Initialization of the verdict comment
        self._verdict_comment = "APx Calibration 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 accessories type from test case xml file (str)
        self._acc_type = str(self._tc_parameters.get_param_value("ACC_TYPE"))

        # Call Stream Volume in percent
        self._call_stream_volume_dut = \
            int(self._tc_parameters.get_param_value("CALL_VOLUME_DUT"))

        # Call Stream Volume in percent
        self._call_stream_volume_ref = \
            int(self._tc_parameters.get_param_value("CALL_VOLUME_REF"))

        # Read Audio Analyzer parameters from bench config xml file (str)
        self._audio_analyser = global_config.benchConfig.\
            get_parameters("AudioAnalyzer")
        self._bt_remote_addr = self._audio_analyser.get_param_value(
            "Bt_mac_addr")

        # Instantiate generic UECmd for voiceCall Ucs
        self._voice_call_api = self._device.get_uecmd("VoiceCall")
        self._phonesystem_api = self._device.get_uecmd("PhoneSystem")
        self._phonemodem_api = self._device.get_uecmd("Modem")
        self._system_api = self._device.get_uecmd("System")

        if self._acc_type.find("BLUETOOTH") != -1:
            # Get UECmdLayer
            self._bt_api = self._device.get_uecmd("LocalConnectivity")
            # Get dut bt address
            self._dut_bt_address = self._bt_api.get_bt_adapter_address()
        else:
            self._dut_bt_address = "None"

        # Load instance of the PHONE2
        self._phone2 = DeviceManager().get_device("PHONE2")

        if self._phone2 is not None:
            if not self._phone2.is_available():
                self._phone2.switch_on(simple_switch_mode=True)
            self._voice_call_api2 = self._phone2.get_uecmd("VoiceCall")
            self._system_api2 = self._phone2.get_uecmd("System")

        else:
            self._voice_call_api2 = None
            self._system_api2 = None

        # Setup phone type ( calling, receiving, releasing phone)
        self._phone_calling = self._voice_call_api
        self._phone_receiving = self._voice_call_api2
        self._calling_phone_number = self._phone2.get_phone_number()
        self._phone_releasing = self._voice_call_api2

    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 None:
            # 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)

        # APx Initialization
        if self._audio_analyzer.initialization(self._device.get_phone_model(),
                                               self._test_type) != 0:
            error_msg = \
                "APX Initialization Failed !"
            self._logger.error(error_msg)
            raise TestEquipmentException(
                TestEquipmentException.OPERATION_FAILED, error_msg)

        # Release any previous call (Robustness)
        self._voice_call_api.release()
        self._voice_call_api2.release()

        return Global.SUCCESS, "No errors"

    def run_test(self):
        """
        Execute the test
        """
        # Call UseCaseBase run_test function
        UseCaseBase.run_test(self)

        if self._acc_type == "HEADSET":
            if self._use_io_card:
                self._wired_headset.unplug_headphone()
                self._wired_headset.plug_whs()
        elif self._acc_type == "HEADPHONE":
            if self._use_io_card:
                self._wired_headset.unplug_whs()
                self._wired_headset.plug_headphone()

        # Dial using PHONE_NUMBER parameter
        self._phone_calling.dial(self._calling_phone_number)
        time.sleep(self._wait_btwn_cmd)

        # Wait for state "active" before callSetupTimeout seconds
        self._phone_receiving.wait_for_state(
            self._uecmd_types.VOICE_CALL_STATE.INCOMING, self._call_setup_time)

        # Answer call
        self._phone_receiving.answer()

        # Phone1 & 2 : Check voice call is active
        self._phone_calling.wait_for_state(
            self._uecmd_types.VOICE_CALL_STATE.ACTIVE, self._call_setup_time)
        self._phone_receiving.wait_for_state(
            self._uecmd_types.VOICE_CALL_STATE.ACTIVE, self._call_setup_time)

        # Configure Audio output to acc_type given with the test_case
        if self._acc_type == "EARPIECE":
            if self._use_io_card:
                self._wired_headset.unplug_whs()
                self._wired_headset.unplug_headphone()
        elif self._acc_type == "SPEAKER":
            # Switch to Speaker, nothing to do in Earpiece
            # Bluetooth already done with connect Bluetooth function above
            self._phonesystem_api.switch_audio_output(self._acc_type.lower())
            time.sleep(self._wait_btwn_cmd)
        elif self._acc_type.find("BLUETOOTH") != -1:
            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)

        if self._acc_type.find("BLUETOOTH") == -1:
            # Set Voice Call Volume
            self._system_api.adjust_specified_stream_volume(
                "VoiceCall", self._call_stream_volume_dut)
        else:
            # Set Voice Call Volume
            self._system_api.adjust_specified_stream_volume(
                "Bluetooth", self._call_stream_volume_dut)

        self._system_api2.adjust_specified_stream_volume(
            "VoiceCall", self._call_stream_volume_ref)
        # Launch Apx Calibration test on Uplink
        apx_result = self._audio_analyzer.calibration(
            self._device.get_phone_model(), "3G", self._acc_type, "UL",
            self._dut_bt_address)

        if apx_result == 0:
            self._result_verdict_ul = Global.SUCCESS
            self._verdict_comment = "APx Calibration success in UL"
        else:
            self._result_verdict_ul = Global.FAILURE
            self._verdict_comment = "APx Calibration fail in UL"

        # Launch Apx Calibration test on Downlink
        apx_result = self._audio_analyzer.calibration(
            self._device.get_phone_model(), "3G", self._acc_type, "DL",
            self._dut_bt_address)

        if apx_result == 0:
            self._result_verdict_dl = Global.SUCCESS
            self._verdict_comment += " and APx Calibration success in DL"
        else:
            self._result_verdict_dl = Global.FAILURE
            self._verdict_comment += " and APx Calibration fail in DL"

        # Compute final verdict
        if self._result_verdict_ul == Global.FAILURE or \
           self._result_verdict_dl == Global.FAILURE:
            self._result_verdict_final = Global.FAILURE
        else:
            self._result_verdict_final = Global.SUCCESS

        # RELEASE THE CALL
        # Phone1 & 2 : Check call is still active
        self._phone_calling.check_state(
            self._uecmd_types.VOICE_CALL_STATE.ACTIVE)
        self._phone_receiving.check_state(
            self._uecmd_types.VOICE_CALL_STATE.ACTIVE)

        # Hang up call
        self._phone_releasing.release()

        # Phone1 & 2 : Check call is idle
        self._phone_calling.wait_for_state(
            self._uecmd_types.VOICE_CALL_STATE.NOCALL, self._call_setup_time)
        self._phone_receiving.wait_for_state(
            self._uecmd_types.VOICE_CALL_STATE.NOCALL, self._call_setup_time)

        return self._result_verdict_final, self._verdict_comment

    def tear_down(self):
        """
        End and dispose the test
        """
        # Call UseCaseBase tear_down function
        UseCaseBase.tear_down(self)

        if self._acc_type == "HEADSET":
            if self._use_io_card:
                self._wired_headset.unplug_whs()
        elif self._acc_type == "HEADPHONE":
            if self._use_io_card:
                self._wired_headset.unplug_headphone()

        # Release any previous call (Robustness)
        self._voice_call_api.release()
        self._voice_call_api2.release()

        # Reset Voice Call Volume at 70%
        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"