예제 #1
0
class BtFindDeviceBypass(BtBase):
    """
    Implements the test step to scan device with another device
    Attributes:
        DEVICE: @see BtTestStepBase
        DEVICE_TO_FIND (string): the BT name or address of the device to find
        MUST_FIND (string): the BT device should be find or not
    """
    STR_LOCAL_CONN = "LocalConnectivity"
    STR_PHONE2 = "PHONE2"

    def run(self, context):
        """
        Runs the test step

        @type context: TestStepContext
        @param context: test case context
        """
        BtBase.run(self, context)
        self._bt_obj = BluetoothConnectivity(self._device, 15)
        self._phone2 = DeviceManager().get_device(
            BtFindDeviceBypass.STR_PHONE2)
        self._bt_api2 = self._phone2.get_uecmd(
            BtFindDeviceBypass.STR_LOCAL_CONN)
        assert self._pars.must_find in [True, False], \
            "MUST_FIND (%s) value should have been checked by the framework" % self._pars.must_find
        self._bt_obj.search_for_device_until_found(self._api, self._bt_api2,
                                                   self._pars.device_to_find,
                                                   self._pars.must_find)
예제 #2
0
    def __init__(self, tc_name, global_config):
        """
        Constructor
        """
        LiveDualPhoneBTBase.__init__(self, tc_name, global_config)

        #Get TC parameters
        #wifi activity is set to WIFI_WEB_BROWSING for all PAN/NAP/PANU tests
        self._wifi_activity = str(self._tc_parameters.get_param_value("WIFI_ACTIVITY")).upper()
        if self._wifi_activity == "WIFI_WEB_BROWSING":
            self._wifi_url = str(self._tc_parameters.get_param_value("URL_TO_BROWSE"))
        self._thread_wifi_activity = None

        self._wifi_access_point = str(self._tc_parameters.get_param_value("WIFI_ACCESS_POINT", ""))

        # Read DUT_STATE from test case xml file: server or client
        self._dut_state = str(self._tc_parameters.get_param_value("DUT_STATE")).upper()
        # Read OPP_LOCAL_FILE from test case xml file
        self._opp_local_file = str(self._tc_parameters.get_param_value("OPP_LOCAL_FILE"))

        self._nap_or_pan_test = str(self._tc_parameters.get_param_value("NAP_OR_PAN_TEST")).upper()
        self._connection_to_share = str(self._tc_parameters.get_param_value("CONNECTION_TO_SHARE")).upper()
        self._pairing_initiator = str(self._tc_parameters.get_param_value("PAIRING_INITIATOR")).upper()
        self._bt_tethering_deactivation_test = \
            str(self._tc_parameters.get_param_value("ENABLE_BT_TETHERING_DEACTIVATION_TEST", default_value=False))
        self._who_disconnect = str(self._tc_parameters.get_param_value("WHO_DISCONNECT", default_value="NAP")).upper()
        self._fail_if = self._tc_parameters.get_param_value("PAIRING_CHECK_FAIL_IF", default_value="disconnected")

        self._interleave_search = self._tc_parameters.get_param_value("IS_INTERLEAVE_SEARCH", default_value=False)

        self._browse_retries = 2

        # Initialize data
        self._thread_opp_transfer = None
        self._thread_scan_bt = None
        self._thread_scan_wifi = None
        self._thread_connect_to_nap = None

        self._nap_api = None
        self._panu_api = None
        self._nap_addr = None
        self._panu_addr = None
        self._wifi_api = None
        self._panu_net_api = None
        self._paired_api = None
        self._pair_requester_api = None

        self._queue = Queue.Queue()
        self.__global_config = global_config
        self._wait_btwn_cmd = 5.0
        self._duration = 60
        self._replyval = True
        self._accept_connection = True
        self._must_find = True
        self._status = None
        self._sleep_time = self._SLEEP_TIME_SECS
        self._start_time = None
        self._timeout = self._DEFAULT_TIMEOUT_SECS

        self._bluetooth_connectivity_obj = BluetoothConnectivity(self._device, self._wait_btwn_cmd)
예제 #3
0
    def __init__(self, tc_name, global_config):
        """
        Constructor
        """
        LiveBTBase.__init__(self, tc_name, global_config)

        #Get TC parameters
        self._wifi_access_point = str(self._tc_parameters.get_param_value("WIFI_ACCESS_POINT", ""))
        self._connection_to_share = "WIFI"
        self.__global_config = global_config
        # Initialize data
        self._wait_btwn_cmd = 5.0
        self._bluetooth_connectivity_obj = BluetoothConnectivity(self._device, self._wait_btwn_cmd)
예제 #4
0
    def run(self, context):
        """
        Runs the test step

        @type context: TestStepContext
        @param context: test case context
        """
        BtBase.run(self, context)
        self._bt_obj = BluetoothConnectivity(self._device, 15)
        self._phone2 = DeviceManager().get_device(
            BtFindDeviceBypass.STR_PHONE2)
        self._bt_api2 = self._phone2.get_uecmd(
            BtFindDeviceBypass.STR_LOCAL_CONN)
        assert self._pars.must_find in [True, False], \
            "MUST_FIND (%s) value should have been checked by the framework" % self._pars.must_find
        self._bt_obj.search_for_device_until_found(self._api, self._bt_api2,
                                                   self._pars.device_to_find,
                                                   self._pars.must_find)
예제 #5
0
class BluetoothPanUNapPing(LiveDualPhoneBTBase):
    """
    Bluetooth PAN Usecase class
    """
    _SLEEP_TIME_SECS = 1
    _DEFAULT_TIMEOUT_SECS = 5

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

        #Get TC parameters
        #wifi activity is set to WIFI_WEB_BROWSING for all PAN/NAP/PANU tests
        self._wifi_access_point = str(self._tc_parameters.get_param_value("WIFI_ACCESS_POINT", ""))

        # Read DUT_STATE from test case xml file: server or client
        self._dut_state = str(self._tc_parameters.get_param_value("DUT_STATE")).upper()

        self._nap_or_pan_test = str(self._tc_parameters.get_param_value("NAP_OR_PAN_TEST")).upper()
        self._connection_to_share = str(self._tc_parameters.get_param_value("CONNECTION_TO_SHARE")).upper()
        self._pairing_initiator = str(self._tc_parameters.get_param_value("PAIRING_INITIATOR")).upper()
        self._bt_tethering_deactivation_test = \
            str(self._tc_parameters.get_param_value("ENABLE_BT_TETHERING_DEACTIVATION_TEST", default_value=False))
        self._who_disconnect = str(self._tc_parameters.get_param_value("WHO_DISCONNECT", default_value="NAP")).upper()
        self._fail_if = self._tc_parameters.get_param_value("PAIRING_CHECK_FAIL_IF", default_value="disconnected")

        self._packet_count = \
            str(self._tc_parameters.get_param_value("PACKET_COUNT"))
        self._packet_size = \
            str(self._tc_parameters.get_param_value("PACKET_SIZE"))
        self._target_packet_loss_rate = \
            str(self._tc_parameters.get_param_value("TARGET_PACKET_LOSS_RATE"))

        self._interleave_search = self._tc_parameters.get_param_value("IS_INTERLEAVE_SEARCH", default_value=False)

        self._browse_retries = 2

        # Initialize data
        self._nap_api = None
        self._panu_api = None
        self._nap_addr = None
        self._panu_addr = None
        self._wifi_api = None
        self._panu_net_api = None
        self._paired_api = None
        self._pair_requester_api = None

        self._queue = Queue.Queue()
        self.__global_config = global_config
        self._wait_btwn_cmd = 5.0
        self._duration = 60
        self._replyval = True
        self._accept_connection = True
        self._must_find = True
        self._status = None
        self._sleep_time = self._SLEEP_TIME_SECS
        self._start_time = None
        self._timeout = self._DEFAULT_TIMEOUT_SECS

        self._bluetooth_connectivity_obj = BluetoothConnectivity(self._device, self._wait_btwn_cmd)


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

        LiveDualPhoneBTBase.set_up(self)

        if self._dut_state not in ["DUT_CLIENT", "DUT_SERVER"]:
            msg = "DUT state configuration unknown - DUT should be client or server"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # defines NAP / PAN-User roles
        if self._nap_or_pan_test == "NAP":
            self._nap_api = self._bt_api
            self._nap_addr = self._phone1_addr
            self._panu_api = self._bt_api2
            self._panu_addr = self._phone2_addr
            self._wifi_api = self._networking_api
            self._panu_net_api = self._networking_api2
        elif self._nap_or_pan_test == "PAN":
            self._nap_api = self._bt_api2
            self._nap_addr = self._phone2_addr
            self._panu_api = self._bt_api
            self._panu_addr = self._phone1_addr
            self._wifi_api = self._networking_api2
            self._panu_net_api = self._networking_api
        else:
            raise AcsConfigException(AcsConfigException.INVALID_TEST_CASE_FILE, "You did not provide a valid value for the NAP_OR_PAN_TEST parameter. It must pe NAP or PAN.")

        # Handle External connection (WIFI or CELLULAR)
        self._bluetooth_connectivity_obj.handle_external_connection(self._connection_to_share, self._wifi_api, self.__global_config, self._wifi_access_point)
        time.sleep(self._wait_btwn_cmd)

        #initialize phone for PAN
        if self._interleave_search is False:
            self._bluetooth_connectivity_obj.search_for_device_until_found(self._panu_api, self._nap_api, self._nap_addr, self._must_find)
        elif self._interleave_search is True:
            self._bluetooth_connectivity_obj.search_for_device_interleave(self._panu_api, self._nap_api, self._nap_addr, self._must_find)

         # Pair the DUT with the device
        self._bluetooth_connectivity_obj.try_until_paired(self._panu_api, self._nap_api, self._panu_addr, self._nap_addr, self._replyval, self._accept_connection)
        # # 4) Set tethering power to on, PAN connect
        # PAN connect the devices
        # Enable BT tethering
        #check devices are truly paired
        self._bluetooth_connectivity_obj.check_paired(self._panu_api, self._nap_addr)
        self._nap_api.set_bt_tethering_power("on")
        time.sleep(self._wait_btwn_cmd)
        #connect PAN way
        self._panu_api.connect_bt_device(self._nap_addr, BtProfile.PAN)
        time.sleep(self._wait_btwn_cmd)
        #check profiles are connected
        keep_going = True
        self._start_time = time.time()
        while keep_going:
            self._status = self._panu_api.get_bt_connection_state(self._nap_addr, BtProfile.PAN)
            keep_going = self._bluetooth_connectivity_obj._keep_going(self._status, self._start_time, self._timeout)
        self._bluetooth_connectivity_obj._raise_error_if_fail_when_profiles_not_connected(self._status, self._fail_if)

        result, output = Global.SUCCESS, ""
        return result, output

    def run_test(self):
        """
        As of right now, at the beginning of the RUN part, we have connected the 2 phones in
        a PAN-NAP way and we are also connected to the internet.
        """
        LiveDualPhoneBTBase.run_test(self)

        wifi_router = self.__global_config.benchConfig.get_parameters(self._wifi_access_point)
        server_to_ping = wifi_router.get_param_value("IP")
        #ping the AP
        packet_loss = self._panu_net_api.ping(server_to_ping,
                                          self._packet_size,
                                          self._packet_count)

        msg = "Measured Packet Loss: {0} {1} (Target: {2} {3})".format(packet_loss.value, packet_loss.units,
               self._target_packet_loss_rate, packet_loss.units)
        self._logger.info(msg)

        if packet_loss.value > self._target_packet_loss_rate:
            msg = "Ping packet loss is not acceptable [%s]" \
                % str(packet_loss.value)
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        return (Global.SUCCESS,
                "BT Tethering ping %s OK" % str(server_to_ping))

    def tear_down(self):

        #disconnect tethering
        self._bluetooth_connectivity_obj.disconnect_bt_tethering_and_pan(self._bt_tethering_deactivation_test, self._nap_api, self._who_disconnect, self._panu_api, self._nap_addr, self._panu_addr)
        # Bluetooth unpairing
        self._logger.info("Unpair both devices")
        paired = False
        list_paired_devices = self._panu_api.list_paired_device()
        for element in list_paired_devices:
            if str(element.address).upper() == str(self._phone2_addr).upper():
                paired = True
        if paired:
            self._bt_api.unpair_bt_device(self._phone2_addr)
            self._bt_api2.unpair_bt_device(self._phone1_addr)
        else:
            pass
        # Disconnect and clear WiFi networks
        if self._connection_to_share == "WIFI":
            self._wifi_api.wifi_remove_config("all")
            self._wifi_api.set_wifi_power("off")

        LiveDualPhoneBTBase.tear_down(self)

        result, output = Global.SUCCESS, ""
        return result, output
예제 #6
0
class BluetoothPanNapOpp(LiveDualPhoneBTBase):
    """
    Bluetooth PAN Usecase class
    """
    _SLEEP_TIME_SECS = 1
    _DEFAULT_TIMEOUT_SECS = 5

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

        #Get TC parameters
        #wifi activity is set to WIFI_WEB_BROWSING for all PAN/NAP/PANU tests
        self._wifi_activity = str(self._tc_parameters.get_param_value("WIFI_ACTIVITY")).upper()
        if self._wifi_activity == "WIFI_WEB_BROWSING":
            self._wifi_url = str(self._tc_parameters.get_param_value("URL_TO_BROWSE"))
        self._thread_wifi_activity = None

        self._wifi_access_point = str(self._tc_parameters.get_param_value("WIFI_ACCESS_POINT", ""))

        # Read DUT_STATE from test case xml file: server or client
        self._dut_state = str(self._tc_parameters.get_param_value("DUT_STATE")).upper()
        # Read OPP_LOCAL_FILE from test case xml file
        self._opp_local_file = str(self._tc_parameters.get_param_value("OPP_LOCAL_FILE"))

        self._nap_or_pan_test = str(self._tc_parameters.get_param_value("NAP_OR_PAN_TEST")).upper()
        self._connection_to_share = str(self._tc_parameters.get_param_value("CONNECTION_TO_SHARE")).upper()
        self._pairing_initiator = str(self._tc_parameters.get_param_value("PAIRING_INITIATOR")).upper()
        self._bt_tethering_deactivation_test = \
            str(self._tc_parameters.get_param_value("ENABLE_BT_TETHERING_DEACTIVATION_TEST", default_value=False))
        self._who_disconnect = str(self._tc_parameters.get_param_value("WHO_DISCONNECT", default_value="NAP")).upper()
        self._fail_if = self._tc_parameters.get_param_value("PAIRING_CHECK_FAIL_IF", default_value="disconnected")

        self._interleave_search = self._tc_parameters.get_param_value("IS_INTERLEAVE_SEARCH", default_value=False)

        self._browse_retries = 2

        # Initialize data
        self._thread_opp_transfer = None
        self._thread_scan_bt = None
        self._thread_scan_wifi = None
        self._thread_connect_to_nap = None

        self._nap_api = None
        self._panu_api = None
        self._nap_addr = None
        self._panu_addr = None
        self._wifi_api = None
        self._panu_net_api = None
        self._paired_api = None
        self._pair_requester_api = None

        self._queue = Queue.Queue()
        self.__global_config = global_config
        self._wait_btwn_cmd = 5.0
        self._duration = 60
        self._replyval = True
        self._accept_connection = True
        self._must_find = True
        self._status = None
        self._sleep_time = self._SLEEP_TIME_SECS
        self._start_time = None
        self._timeout = self._DEFAULT_TIMEOUT_SECS

        self._bluetooth_connectivity_obj = BluetoothConnectivity(self._device, self._wait_btwn_cmd)


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

        LiveDualPhoneBTBase.set_up(self)

        if self._dut_state not in ["DUT_CLIENT", "DUT_SERVER"]:
            msg = "DUT state configuration unknown - DUT should be client or server"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # defines NAP / PAN-User roles
        if self._nap_or_pan_test == "NAP":
            self._nap_api = self._bt_api
            self._nap_addr = self._phone1_addr
            self._panu_api = self._bt_api2
            self._panu_addr = self._phone2_addr
            self._wifi_api = self._networking_api
            self._panu_net_api = self._networking_api2
        elif self._nap_or_pan_test == "PAN":
            self._nap_api = self._bt_api2
            self._nap_addr = self._phone2_addr
            self._panu_api = self._bt_api
            self._panu_addr = self._phone1_addr
            self._wifi_api = self._networking_api2
            self._panu_net_api = self._networking_api
        else:
            raise AcsConfigException(AcsConfigException.INVALID_TEST_CASE_FILE, "You did not provide a valid value for the NAP_OR_PAN_TEST parameter. It must pe NAP or PAN.")

        # Handle External connection (WIFI or CELLULAR)
        self._bluetooth_connectivity_obj.handle_external_connection(self._connection_to_share, self._wifi_api, self.__global_config, self._wifi_access_point)
        time.sleep(self._wait_btwn_cmd)

        #initialize phone for PAN
        if self._interleave_search is False:
            self._bluetooth_connectivity_obj.search_for_device_until_found(self._panu_api, self._nap_api, self._nap_addr, self._must_find)
        elif self._interleave_search is True:
            self._bluetooth_connectivity_obj.search_for_device_interleave(self._panu_api, self._nap_api, self._nap_addr, self._must_find)

        # Pair the DUT with the device
        self._bluetooth_connectivity_obj.try_until_paired(self._panu_api, self._nap_api, self._panu_addr, self._nap_addr, self._replyval, self._accept_connection)
        # # 4) Set tethering power to on, PAN connect
        # PAN connect the devices
        # Enable BT tethering
        #check devices are truly paired
        self._bluetooth_connectivity_obj.check_paired(self._panu_api, self._nap_addr)
        self._nap_api.set_bt_tethering_power("on")
        time.sleep(self._wait_btwn_cmd)
        #connect PAN way
        self._panu_api.connect_bt_device(self._nap_addr, BtProfile.PAN)
        #check profiles are connected
        keep_going = True
        self._start_time = time.time()
        while keep_going:
            self._status = self._panu_api.get_bt_connection_state(self._nap_addr, BtProfile.PAN)
            keep_going = self._bluetooth_connectivity_obj._keep_going(self._status, self._start_time, self._timeout)
        self._bluetooth_connectivity_obj._raise_error_if_fail_when_profiles_not_connected(self._status, self._fail_if)

        result, output = Global.SUCCESS, ""
        return result, output

    def run_test(self):
        """
        As of right now, at the beginning of the RUN part, we have connected the 2 phones in
        a PAN-NAP way and we are also connected to the internet.
        """
        LiveDualPhoneBTBase.run_test(self)

         # Configure Wifi Browse threads
        if self._wifi_activity == "WIFI_WEB_BROWSING":
            self._thread_wifi_activity = ThreadBrowseWifiChrome(self._queue, self._panu_net_api, self._duration, self._browse_retries, self._wifi_url)
        else:
            msg = "Unknown WIFI_ACTIVITY : %s" % self._wifi_activity
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Configure BT OPP Transfer
        if self._dut_state == "DUT_SERVER":
            self._thread_opp_transfer = ThreadOPPTransferFile(self._queue, self._device, self._phone2,
                                                              self._opp_local_file, self._device.multimedia_path, initialize=True)
        elif self._dut_state == "DUT_CLIENT":
            self._thread_opp_transfer = ThreadOPPTransferFile(self._queue, self._phone2, self._device,
                                                              self._opp_local_file, self._phone2.multimedia_path)

        self._thread_opp_transfer.start()
        time.sleep(20)
        self._thread_wifi_activity.start()
        time.sleep(self._wait_btwn_cmd)
        self._thread_opp_transfer.join()
        # This function waits all threads are dead or timeout is over before finish
        self._exception_reader(self._queue, [self._thread_wifi_activity, self._thread_opp_transfer])

        result, output = Global.SUCCESS, ""
        return result, output

    def tear_down(self):

        #disconnect tethering
        self._bluetooth_connectivity_obj.disconnect_bt_tethering_and_pan(self._bt_tethering_deactivation_test, self._nap_api, self._who_disconnect, self._panu_api, self._nap_addr, self._panu_addr)
        # Bluetooth unpairing
        self._logger.info("Unpair both devices")
        paired = False
        list_paired_devices = self._panu_api.list_paired_device()
        for element in list_paired_devices:
            if str(element.address).upper() == str(self._phone2_addr).upper():
                paired = True
        if paired:
            self._bt_api.unpair_bt_device(self._phone2_addr)
            self._bt_api2.unpair_bt_device(self._phone1_addr)
        else:
            pass
        # Disconnect and clear WiFi networks
        if self._connection_to_share == "WIFI":
            self._wifi_api.wifi_remove_config("all")
            self._wifi_api.set_wifi_power("off")

        LiveDualPhoneBTBase.tear_down(self)

        result, output = Global.SUCCESS, ""
        return result, output
예제 #7
0
class BluetoothPanNapAirplane(LiveDualPhoneBTBase):
    """
    Bluetooth PAN Usecase class
    """
    _SLEEP_TIME_SECS = 1
    _DEFAULT_TIMEOUT_SECS = 10
    WAIT_TIME_IN_FLIGHT_MODE = 5.0

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

        #Get TC parameters

         #wifi activity is set to WIFI_WEB_BROWSING for all PAN/NAP/PANU tests
        self._wifi_activity = str(self._tc_parameters.get_param_value("WIFI_ACTIVITY")).upper()
        if self._wifi_activity == "WIFI_WEB_BROWSING":
            self._wifi_url = str(self._tc_parameters.get_param_value("URL_TO_BROWSE"))
        self._thread_wifi_activity = None
        self._connection_to_share = str(self._tc_parameters.get_param_value("CONNECTION_TO_SHARE")).upper()
        self._wifi_access_point = str(self._tc_parameters.get_param_value("WIFI_ACCESS_POINT", ""))
        self._nap_or_pan_test = str(self._tc_parameters.get_param_value("NAP_OR_PAN_TEST")).upper()
        self._pairing_initiator = str(self._tc_parameters.get_param_value("PAIRING_INITIATOR")).upper()
        self._bt_tethering_deactivation_test = \
            str(self._tc_parameters.get_param_value("ENABLE_BT_TETHERING_DEACTIVATION_TEST", default_value=False))
        self._who_disconnect = str(self._tc_parameters.get_param_value("WHO_DISCONNECT", default_value="NAP")).upper()
        self._fail_if = self._tc_parameters.get_param_value("PAIRING_CHECK_FAIL_IF", default_value="disconnected")

        self._interleave_search = self._tc_parameters.get_param_value("IS_INTERLEAVE_SEARCH", default_value=False)

        # Initialize data
        self._nap_api = None
        self._panu_api = None
        self._nap_addr = None
        self._panu_addr = None
        self._wifi_api = None
        self._panu_net_api = None
        self._paired_api = None
        self._pair_requester_api = None

        self._queue = Queue.Queue()
        self.__global_config = global_config
        self._wait_btwn_cmd = 5.0
        self._duration = 60
        self._replyval = True
        self._accept_connection = True
        self._must_find = True
        self._status = None
        self._sleep_time = self._SLEEP_TIME_SECS
        self._start_time = None
        self._timeout = self._DEFAULT_TIMEOUT_SECS
        self._browse_retries = 2

        self._bluetooth_connectivity_obj = BluetoothConnectivity(self._device, self._wait_btwn_cmd)


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

        LiveDualPhoneBTBase.set_up(self)

        # defines NAP / PAN-User roles
        if self._nap_or_pan_test == "NAP":
            self._nap_api = self._bt_api
            self._nap_addr = self._phone1_addr
            self._panu_api = self._bt_api2
            self._panu_addr = self._phone2_addr
            self._wifi_api = self._networking_api
            self._panu_net_api = self._networking_api2
        elif self._nap_or_pan_test == "PAN":
            self._nap_api = self._bt_api2
            self._nap_addr = self._phone2_addr
            self._panu_api = self._bt_api
            self._panu_addr = self._phone1_addr
            self._wifi_api = self._networking_api2
            self._panu_net_api = self._networking_api
        else:
            raise AcsConfigException(AcsConfigException.INVALID_TEST_CASE_FILE, "You did not provide a valid value for the NAP_OR_PAN_TEST parameter. It must pe NAP or PAN.")

        # Handle External connection (WIFI or CELLULAR)
        self._bluetooth_connectivity_obj.handle_external_connection(self._connection_to_share, self._wifi_api, self.__global_config, self._wifi_access_point)
        time.sleep(self._wait_btwn_cmd)

        #initialize phone for PAN
        if self._interleave_search is False:
            self._bluetooth_connectivity_obj.search_for_device_until_found(self._panu_api, self._nap_api, self._nap_addr, self._must_find)
        elif self._interleave_search is True:
            self._bluetooth_connectivity_obj.search_for_device_interleave(self._panu_api, self._nap_api, self._nap_addr, self._must_find)

         # Pair the DUT with the device
        self._bluetooth_connectivity_obj.try_until_paired(self._panu_api, self._nap_api, self._panu_addr, self._nap_addr, self._replyval, self._accept_connection)
        # # 4) Set tethering power to on, PAN connect
        # PAN connect the devices
        # Enable BT tethering
        #check devices are truly paired
        self._bluetooth_connectivity_obj.check_paired(self._panu_api, self._nap_addr)
        self._nap_api.set_bt_tethering_power("on")
        time.sleep(self._wait_btwn_cmd)
        #connect PAN way
        self._panu_api.connect_bt_device(self._nap_addr, BtProfile.PAN)
        #check profiles are connected
        keep_going = True
        self._start_time = time.time()
        while keep_going:
            self._status = self._panu_api.get_bt_connection_state(self._nap_addr, BtProfile.PAN)
            keep_going = self._bluetooth_connectivity_obj._keep_going(self._status, self._start_time, self._timeout)
        self._bluetooth_connectivity_obj._raise_error_if_fail_when_profiles_not_connected(self._status, self._fail_if)

        result, output = Global.SUCCESS, ""
        return result, output

    def run_test(self):
        """
        As of right now, at the beginning of the RUN part, we have connected the 2 phones in
        a PAN-NAP way and we are also connected to the internet.
        """
        LiveDualPhoneBTBase.run_test(self)

          # Configure Wifi Browse threads
        if self._wifi_activity == "WIFI_WEB_BROWSING":
            self._thread_wifi_activity = ThreadBrowseWifiChrome(self._queue, self._panu_net_api, self._duration, self._browse_retries, self._wifi_url)
        else:
            msg = "Unknown WIFI_ACTIVITY : %s" % self._wifi_activity
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # search for the interface on the reference device, must be present
        netcfg_cmd_up = "adb shell netcfg | grep bt-pan"
        ifconfig_cmd_up = "adb shell ifconfig | grep -A8 bt-pan"
        time.sleep(self._wait_btwn_cmd)
        result_up, output_up = self._phone2.run_cmd(netcfg_cmd_up, self._wait_btwn_cmd)
        return_result = Global.SUCCESS
        return_output = "The bt-pan interface is in the correct state"
        if not output_up or "not found" in output_up:
            result_up, output_up = self._device.run_cmd(ifconfig_cmd_up, self._wait_btwn_cmd)
        if not output_up:
            msg = "The bt-pan interface is not present, it was not instantiated after first connection."
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        elif "UP" not in output_up:
            msg = "The bt-pan interface is present, but it is down after first connection.. Output of grep command" \
                  " is: \n" + str(output_up)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        elif "0.0.0.0/0" in output_up:
            msg = "The bt-pan interface is present, but no IP was assigned after first connection.. Output of grep command" \
                  " is: \n" + str(output_up)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        else:
            return_output = "The bt-pan interface is present and UP"

        #browse for a page
        self._thread_wifi_activity.start()
        time.sleep(self._wait_btwn_cmd)
         # This function waits all threads are dead or timeout is over before finish
        self._exception_reader(self._queue, [self._thread_wifi_activity])

        #turn airplane mode ON
        self._wifi_api.set_flight_mode(1)
        time.sleep(BluetoothPanNapAirplane.WAIT_TIME_IN_FLIGHT_MODE)

        #check BT, BT Tethering and Wifi are deactivated
        #check BT status is OFF
        time.sleep(self._wait_btwn_cmd)
        bt_power_air_on = self._nap_api.get_bt_power_status()
        if bt_power_air_on != str(BT_STATE.STATE_OFF):
            msg = "After setting Airplane mode to ON, Bluetooth is still ON. Expected state is OFF." \
                  "the actual state is: " + bt_power_air_on
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        #check BT tethering is turned off
        if self._nap_api.get_bt_tethering_power_status() != str(BT_STATE.STATE_OFF):
            msg = "After setting Airplane mode to ON, Bluetooth TETHERING is still ON. Expected state is OFF."
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        #check Wifi status is OFF
        if self._wifi_api.get_wifi_power_status == 1:
            msg = "After setting Airplane mode to ON, WIFI is still ON. Expected state is OFF."
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        #turn ON BT and Wifi on DUT
        self._nap_api.set_bt_power("on")
        self._wifi_api.set_wifi_power("on")

        self._nap_api.set_bt_tethering_power("on")

        #check BT, BT Tethering and Wifi are reactivated. BT Tethering should be automatically re-activated
        #check BT status is ON
        time.sleep(self._wait_btwn_cmd)
        bt_power_air_off = self._nap_api.get_bt_power_status()
        if bt_power_air_off != str(BT_STATE.STATE_ON):
            msg = "After setting Airplane mode to OFF, Bluetooth is still OFF. Expected state is ON." \
                  "the actual state is: " + bt_power_air_off
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        #check BT tethering is turned ON
        if self._nap_api.get_bt_tethering_power_status() != str(BT_STATE.STATE_ON):
            msg = "After setting Airplane mode to OFF, Bluetooth TETHERING is still OFF. Expected state is ON."
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        #check Wifi status is ON
        if self._wifi_api.get_wifi_power_status == 1:
            msg = "After setting Airplane mode to OFF, WIFI is still OFF. Expected state is ON."
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        #PAN-reconnect the devices
        self._panu_api.connect_bt_device(self._nap_addr, BtProfile.PAN)

        # search for the interface on the device, must not be present
        netcfg_cmd_up = "adb shell netcfg | grep bt-pan"
        ifconfig_cmd_up = "adb shell ifconfig | grep -A8 bt-pan"
        time.sleep(self._wait_btwn_cmd)
        result_up, output_up = self._phone2.run_cmd(netcfg_cmd_up, self._wait_btwn_cmd)
        return_result = Global.SUCCESS
        return_output = "The bt-pan interface is in the correct state"
        if not output_up or "not found" in output_up:
            result_up, output_up = self._device.run_cmd(ifconfig_cmd_up, self._wait_btwn_cmd)
        if not output_up:
            msg = "The bt-pan interface is not present, it was not instantiated after PAN-reconnecting. Message is: "+ str(output_up)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        elif "UP" not in output_up:
            msg = "The bt-pan interface is present, but it is down after PAN-reconnecting. Output of grep command" \
                  " is: \n" + str(output_up)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        elif "0.0.0.0/0" in output_up:
            msg = "The bt-pan interface is present, but no IP was assigned after PAN-reconnecting. Output of grep command" \
                  " is: \n" + str(output_up)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        else:
            return_output = "The bt-pan interface is present and UP"

        #turn airplane mode OFF
        self._wifi_api.set_flight_mode(0)
        time.sleep(BluetoothPanNapAirplane.WAIT_TIME_IN_FLIGHT_MODE)

        #check internet service was not stopped
        # search for the interface on the reference device, must be present
        netcfg_cmd_up = "adb shell netcfg | grep bt-pan"
        time.sleep(self._wait_btwn_cmd)
        result_up, output_up = self._phone2.run_cmd(netcfg_cmd_up, self._wait_btwn_cmd)
        return_result = Global.SUCCESS
        return_output = "The bt-pan interface is in the correct state"
        if not output_up or "not found" in output_up:
            result_up, output_up = self._device.run_cmd(ifconfig_cmd_up, self._wait_btwn_cmd)
        if not output_up:
            msg = "The bt-pan interface is not present, it was not instantiated after Airplane mode OFF"
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        elif "UP" not in output_up:
            msg = "The bt-pan interface is present, but it is down after Airplane mode OFF. Output of grep command" \
                  " is: \n" + str(output_up)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        elif "0.0.0.0/0" in output_up:
            msg = "The bt-pan interface is present, but no IP was assigned after Airplane mode OFF. Output of grep command" \
                  " is: \n" + str(output_up)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        else:
            return_output = "The bt-pan interface is present and UP after Airplane mode OFF, the usecase fully passed."

        return Global.SUCCESS, return_output


    def tear_down(self):

        #disconnect tethering
        self._bluetooth_connectivity_obj.disconnect_bt_tethering_and_pan(self._bt_tethering_deactivation_test, self._nap_api, self._who_disconnect, self._panu_api, self._nap_addr, self._panu_addr)
        # Bluetooth unpairing
        self._logger.info("Unpair both devices")
        paired = False
        list_paired_devices = self._panu_api.list_paired_device()
        for element in list_paired_devices:
            if str(element.address).upper() == str(self._phone2_addr).upper():
                paired = True
        if paired:
            self._bt_api.unpair_bt_device(self._phone2_addr)
            self._bt_api2.unpair_bt_device(self._phone1_addr)
        else:
            pass
        # Disconnect and clear WiFi networks
        if self._connection_to_share == "WIFI":
            self._wifi_api.wifi_remove_config("all")
            self._wifi_api.set_wifi_power("off")

        LiveDualPhoneBTBase.tear_down(self)

        result, output = Global.SUCCESS, "The test was successfully tore down"
        return result, output
예제 #8
0
class BluetoothPanAirplane(LiveBTBase):
    """
    Bluetooth PAN Usecase class
    """
    _SLEEP_TIME_SECS = 1
    _DEFAULT_TIMEOUT_SECS = 5
    WAIT_TIME_IN_FLIGHT_MODE = 5.0

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

        #Get TC parameters
        self._wifi_access_point = str(self._tc_parameters.get_param_value("WIFI_ACCESS_POINT", ""))
        self._connection_to_share = "WIFI"
        self.__global_config = global_config
        # Initialize data
        self._wait_btwn_cmd = 5.0
        self._bluetooth_connectivity_obj = BluetoothConnectivity(self._device, self._wait_btwn_cmd)


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

        LiveBTBase.set_up(self)

        #locally initialize phone for PAN - turn tethering ON
        self._bt_api.set_bt_tethering_power("on")
        result, output = Global.SUCCESS, ""
        return result, output

    def run_test(self):
        """
        As of right now, at the beginning of the RUN part, we have connected the 2 phones in
        a PAN-NAP way and we are also connected to the internet.
        """
        LiveBTBase.run_test(self)

        # Handle External connection (WIFI or CELLULAR)
        self._bluetooth_connectivity_obj.handle_external_connection(self._connection_to_share, self._networking_api, self.__global_config, self._wifi_access_point)
        time.sleep(self._wait_btwn_cmd)

        #turn airplane mode ON
        self._networking_api.set_flight_mode(1)
        time.sleep(BluetoothPanAirplane.WAIT_TIME_IN_FLIGHT_MODE)

        #check BT, BT Tethering and Wifi are deactivated
        #check BT status is OFF
        time.sleep(self._wait_btwn_cmd)
        bt_power_air_on = self._bt_api.get_bt_power_status()
        if bt_power_air_on != str(BT_STATE.STATE_OFF):
            msg = "After setting Airplane mode to ON, Bluetooth is still ON. Expected state is OFF." \
                  "the actual state is: " + bt_power_air_on
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        #check BT tethering is turned off
        if self._bt_api.get_bt_tethering_power_status() != str(BT_STATE.STATE_OFF):
            msg = "After setting Airplane mode to ON, Bluetooth TETHERING is still ON. Expected state is OFF."
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        #check Wifi status is OFF
        if self._networking_api.get_wifi_power_status == 1:
            msg = "After setting Airplane mode to ON, WIFI is still ON. Expected state is OFF."
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        #turn airplane mode OFF
        self._networking_api.set_flight_mode(0)
        time.sleep(BluetoothPanAirplane.WAIT_TIME_IN_FLIGHT_MODE)

        #check BT, BT Tethering and Wifi are reactivated
        #check BT status is ON
        time.sleep(self._wait_btwn_cmd)
         #locally initialize phone for PAN - turn tethering ON
        self._bt_api.set_bt_tethering_power("on")

        bt_power_air_off = self._bt_api.get_bt_power_status()
        if bt_power_air_off != str(BT_STATE.STATE_ON):
            msg = "After setting Airplane mode to OFF, Bluetooth is still OFF. Expected state is ON." \
                  "the actual state is: " + bt_power_air_off
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        #check BT tethering is turned ON
        if self._bt_api.get_bt_tethering_power_status() != str(BT_STATE.STATE_ON):
            msg = "After setting Airplane mode to OFF, Bluetooth TETHERING is still OFF. Expected state is ON."
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        #check Wifi status is ON
        if self._networking_api.get_wifi_power_status == 1:
            msg = "After setting Airplane mode to OFF, WIFI is still OFF. Expected state is ON."
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        return Global.SUCCESS, "Usecase successful"


    def tear_down(self):

        # Disconnect and clear WiFi networks
        if self._connection_to_share == "WIFI":
            self._networking_api.wifi_remove_config("all")
            self._networking_api.set_wifi_power("off")

        LiveBTBase.tear_down(self)

        result, output = Global.SUCCESS, ""
        return result, output