def _connect_disconnect_android_device(self, dut_id, wifi_state):
        """ Connect or disconnect wifi on android device depending on the
            current wifi state

        Args:
            1. dut_id: tethered device to change the wifi state
            2. wifi_state: current wifi state
        """
        ad = self.tethered_devices[dut_id]
        if wifi_state:
            self.log.info("Disconnecting wifi on android device")
            wutils.wifi_forget_network(ad, self.network["SSID"])
        else:
            self.log.info("Connecting to wifi on android device")
            wutils.wifi_connect(ad, self.network)
Example #2
0
 def test_stress_wifi_roaming(self):
     AP1_network = self.reference_networks[0]["5g"]
     AP2_network = self.reference_networks[1]["5g"]
     wutils.set_attns(self.attenuators, "AP1_on_AP2_off")
     wutils.wifi_connect(self.dut, AP1_network)
     # Reduce iteration to half because each iteration does two roams.
     for count in range(self.stress_count / 2):
         self.log.info("Roaming iteration %d, from %s to %s", count,
                       AP1_network, AP2_network)
         wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
                                             "AP1_off_AP2_on", AP2_network)
         self.log.info("Roaming iteration %d, from %s to %s", count,
                       AP2_network, AP1_network)
         wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
                                             "AP1_on_AP2_off", AP1_network)
 def _connect_disconnect_devices(self):
     """ Randomly connect and disconnect devices from the
         self.tethered_devices list to hotspot device
     """
     device_connected = [False] * len(self.tethered_devices)
     for _ in range(50):
         dut_id = random.randint(0, len(self.tethered_devices) - 1)
         dut = self.tethered_devices[dut_id]
         # wait for 1 sec between connect & disconnect stress test
         time.sleep(1)
         if device_connected[dut_id]:
             wutils.wifi_forget_network(dut, self.network["SSID"])
         else:
             wutils.wifi_connect(dut, self.network)
         device_connected[dut_id] = not device_connected[dut_id]
Example #4
0
    def test_wifi_tethering_5ghz_ping_hotspot_interfaces(self):
        """ Steps:

            1. Start wifi hotspot with 5ghz band
            2. Connect tethered device to hotspot device
            3. Ping 'wlan0' and 'rmnet_data' interface's IPv4
               and IPv6 interfaces on hotspot device from tethered device
        """
        wutils.toggle_wifi_off_and_on(self.hotspot_device)
        self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
        wutils.wifi_connect(self.tethered_devices[0], self.network)
        result = self._ping_hotspot_interfaces_from_tethered_device(
            self.tethered_devices[0])
        wutils.stop_wifi_tethering(self.hotspot_device)
        return result
Example #5
0
    def test_multipath_preference_data_download(self):
        """ Verify multipath preference when large file is downloaded

        Steps:
            1. DUT has WiFi and LTE data
            2. WiFi is active network
            3. Download large file over cell network
            4. Verify multipath preference on cell network is 0
        """
        # set vars
        ad = self.android_devices[1]
        self.dut = ad
        self._clear_netstats(ad)
        utils.sync_device_time(ad)
        self.tcpdump_pid = nutils.start_tcpdump(ad, self.test_name)

        cell_network = ad.droid.connectivityGetActiveNetwork()
        self.log.info("cell network %s" % cell_network)
        wutils.wifi_connect(ad, self.wifi_network)
        wifi_network = ad.droid.connectivityGetActiveNetwork()
        self.log.info("wifi network %s" % wifi_network)

        # verify multipath preference for wifi and cell networks
        self._verify_multipath_preferences(ad, RELIABLE, RELIABLE,
                                           wifi_network, cell_network)

        # download file with cell network
        ad.droid.connectivityNetworkOpenConnection(cell_network,
                                                   self.download_file)
        file_folder, file_name = _generate_file_directory_and_file_name(
            self.download_file, DOWNLOAD_PATH)
        file_path = os.path.join(file_folder, file_name)
        self.log.info("File path: %s" % file_path)
        if _check_file_existance(ad, file_path):
            self.log.info("File exists. Removing file %s" % file_name)
            ad.adb.shell("rm -rf %s%s" % (DOWNLOAD_PATH, file_name))

        #  verify multipath preference values
        curr_time = time.time()
        while time.time() < curr_time + TIMEOUT:
            try:
                self._verify_multipath_preferences(ad, RELIABLE, NONE,
                                                   wifi_network, cell_network)
                return True
            except signals.TestFailure as e:
                self.log.debug("%s" % e)
            time.sleep(1)
        return False
Example #6
0
    def test_private_dns_mode_strict_invalid_hostnames(self):
        """ Verify that invalid hostnames are not saved for strict mode

        Steps:
            1. Set private DNS to strict mode with invalid hostname
            2. Verify that invalid hostname is not saved
        """
        invalid_hostnames = ["!%@&!*", "12093478129", "9.9.9.9", "sdkfjhasdf"]
        for hostname in invalid_hostnames:
            self.dut.droid.setPrivateDnsMode(True, hostname)
            mode = self.dut.droid.getPrivateDnsMode()
            specifier = self.dut.droid.getPrivateDnsSpecifier()
            wutils.wifi_connect(self.dut, self.wifi_network_no_dns_tls)
            asserts.assert_true(
                mode == PRIVATE_DNS_MODE_STRICT and specifier != hostname,
                "Able to set invalid private DNS strict mode")
Example #7
0
    def connect_to_wifi(self, ad, network):
        """Connection logic for open and psk wifi networks.

        Args:
            ad: Android device object.
            network: A JSON dict of the WiFi network configuration.

        """
        ad.ed.clear_all_events()
        wifi_utils.start_wifi_connection_scan(ad)
        scan_results = ad.droid.wifiGetScanResults()
        wifi_utils.assert_network_in_list(
            {WifiEnums.SSID_KEY: self.wifi_network_ssid}, scan_results)
        wifi_utils.wifi_connect(ad, network)
        self.log.debug("Connected to %s network on %s device" %
                       (network[WifiEnums.SSID_KEY], ad.serial))
Example #8
0
    def setup_sap_rvr_test(self, testcase_params):
        """Function that gets devices ready for the test.

        Args:
            testcase_params: dict containing test-specific parameters
        """
        for dev in self.android_devices:
            if not wputils.health_check(dev, 20):
                asserts.skip('DUT health check failed. Skipping test.')
        # Reset WiFi on all devices
        for dev in self.android_devices:
            self.dut.go_to_sleep()
            wutils.reset_wifi(dev)
            wutils.set_wifi_country_code(dev, wutils.WifiEnums.CountryCode.US)

        # Setup Soft AP
        sap_config = wutils.create_softap_config()
        self.log.info('SoftAP Config: {}'.format(sap_config))
        wutils.start_wifi_tethering(self.android_devices[0],
                                    sap_config[wutils.WifiEnums.SSID_KEY],
                                    sap_config[wutils.WifiEnums.PWD_KEY],
                                    testcase_params['sap_band_enum'])
        # Set attenuator to 0 dB
        for attenuator in self.attenuators:
            attenuator.set_atten(0, strict=False)
        # Connect DUT to Network
        testcase_params['test_network'] = {
            'SSID': sap_config[wutils.WifiEnums.SSID_KEY],
            'password': sap_config[wutils.WifiEnums.PWD_KEY]
        }
        wutils.wifi_connect(self.android_devices[1],
                            testcase_params['test_network'],
                            num_of_tries=5,
                            check_connectivity=False)
        # Compile meta data
        self.access_point = AccessPointTuple(sap_config)
        testcase_params['connection_info'] = self.get_sap_connection_info()
        testcase_params['channel'] = testcase_params['connection_info'][
            'channel']
        testcase_params['test_network']['channel'] = testcase_params[
            'connection_info']['channel']
        if testcase_params['channel'] < 13:
            testcase_params['mode'] = 'VHT20'
        else:
            testcase_params['mode'] = 'VHT80'
        testcase_params['iperf_server_address'] = testcase_params[
            'connection_info']['ap_ip_address']
Example #9
0
    def test_multipath_preference_low_data_limit(self):
        """ Verify multipath preference when mobile data limit is low

        Steps:
            1. DUT has WiFi and LTE data
            2. Set mobile data usage limit to low value
            3. Verify that multipath preference is 0 for cell network
        """
        # set vars
        ad = self.android_devices[0]
        self.dut = ad
        self._clear_netstats(ad)
        utils.sync_device_time(ad)
        self.tcpdump_pid = nutils.start_tcpdump(ad, self.test_name)

        sub_id = str(ad.droid.telephonyGetSubscriberId())
        cell_network = ad.droid.connectivityGetActiveNetwork()
        self.log.info("cell network %s" % cell_network)
        wutils.wifi_connect(ad, self.wifi_network)
        wifi_network = ad.droid.connectivityGetActiveNetwork()
        self.log.info("wifi network %s" % wifi_network)

        # verify mulipath preference values
        self._verify_multipath_preferences(ad, RELIABLE, RELIABLE,
                                           wifi_network, cell_network)

        # set low data limit on mobile data
        total_pre = self._get_total_data_usage_for_device(ad, 0, sub_id)
        self.log.info("Setting data usage limit to %sMB" % (total_pre + 5))
        ad.droid.connectivitySetDataUsageLimit(
            sub_id, int((total_pre + 5) * 1000.0 * 1000.0))
        self.log.info("Setting data warning limit to %sMB" % (total_pre + 5))
        ad.droid.connectivitySetDataWarningLimit(
            sub_id, int((total_pre + 5) * 1000.0 * 1000.0))

        # verify multipath preference values
        curr_time = time.time()
        while time.time() < curr_time + TIMEOUT:
            try:
                self._verify_multipath_preferences(ad, RELIABLE, NONE,
                                                   wifi_network, cell_network)
                return True
            except signals.TestFailure as e:
                self.log.debug("%s" % e)
            time.sleep(1)
        return False
Example #10
0
    def setup_class(self):
        super().setup_class()
        self.pri_ad = self.android_devices[0]
        if len(self.android_devices) == 2:
            self.sec_ad = self.android_devices[1]
        elif len(self.android_devices) == 3:
            self.third_ad = self.android_devices[2]
        self.ssh_config = None

        self.counter = 0
        self.thread_list = []
        if not setup_multiple_devices_for_bt_test(self.android_devices):
            self.log.error('Failed to setup devices for bluetooth test')
            return False
        req_params = ['network', 'iperf']
        opt_params = [
            'AccessPoint', 'RetailAccessPoints', 'RelayDevice',
            'required_devices'
        ]
        self.unpack_userparams(req_params, opt_params)

        self.iperf_server = self.iperf_servers[0]
        self.iperf_client = self.iperf_clients[0]

        if hasattr(self, 'RelayDevice'):
            self.audio_receiver = self.relay_devices[0]
            self.audio_receiver.power_on()
            self.headset_mac_address = self.audio_receiver.mac_address
        else:
            self.log.warning('Missing Relay config file.')

        if hasattr(self, 'AccessPoint'):
            self.ap = self.access_points[0]
            configure_and_start_ap(self.ap, self.network)
        elif hasattr(self, 'RetailAccessPoints'):
            self.retail_access_points = retail_ap.create(
                self.RetailAccessPoints)
            self.retail_access_point = self.retail_access_points[0]
            band = self.retail_access_point.band_lookup_by_channel(
                self.network['channel'])
            self.retail_access_point.set_channel(band, self.network['channel'])
        else:
            self.log.warning('config file have no access point information')

        wifi_test_device_init(self.pri_ad)
        wifi_connect(self.pri_ad, self.network, num_of_tries=5)
Example #11
0
    def test_dns_server_link_properties_strict_mode(self):
        """ Verify DNS server in the link properties when set in strict mode

        Steps:
            1. Set DNS server hostname in Private DNS settings (stict mode)
            2. Verify that DNS server set in settings is in link properties
            3. Verify for WiFi as well as LTE
        """
        # start tcpdump on device
        self._start_tcp_dump(self.dut)

        # set private DNS to strict mode
        cutils.set_private_dns(
            self.dut, cconst.PRIVATE_DNS_MODE_STRICT, cconst.DNS_GOOGLE)

        # connect DUT to wifi network
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut, self.ipv4_ipv6_network[SSID])
        wutils.wifi_connect(self.dut, self.ipv4_ipv6_network)
        for host in self.ping_hosts:
            wutils.validate_connection(self.dut, host)

        # DNS server in link properties for wifi network
        link_prop = self.dut.droid.connectivityGetActiveLinkProperties()
        wifi_dns_servers = link_prop['PrivateDnsServerName']
        self.log.info("Link prop: %s" % wifi_dns_servers)

        # DUT is on LTE data
        wutils.reset_wifi(self.dut)
        time.sleep(1) # wait till lte network becomes active
        for host in self.ping_hosts:
            wutils.validate_connection(self.dut, host)

        # DNS server in link properties for cell network
        link_prop = self.dut.droid.connectivityGetActiveLinkProperties()
        lte_dns_servers = link_prop['PrivateDnsServerName']
        self.log.info("Link prop: %s" % lte_dns_servers)

        # stop tcpdump on device
        pcap_file = self._stop_tcp_dump(self.dut)

        # Verify DNS server in link properties
        asserts.assert_true(cconst.DNS_GOOGLE in wifi_dns_servers,
                            "Hostname not in link properties - wifi network")
        asserts.assert_true(cconst.DNS_GOOGLE in lte_dns_servers,
                            "Hostname not in link properites - cell network")
Example #12
0
    def setup_ap_connection(self, network, bandwidth=80, connect=True):
        """Setup AP and connect DUT to it.

        Args:
            network: the network config for the AP to be setup
            bandwidth: bandwidth of the WiFi network to be setup
            connect: indicator of if connect dut to the network after setup
        Returns:
            self.brconfigs: dict for bridge interface configs
        """
        wutils.wifi_toggle_state(self.dut, True)
        self.brconfigs = wputils.ap_setup(self.access_point,
                                          network,
                                          bandwidth=bandwidth)
        if connect:
            wutils.wifi_connect(self.dut, network)
        return self.brconfigs
Example #13
0
    def test_wifi_tethering_data_usage_limit_downlink(self):
        """ Verify connectivity when data usage limit reached

        Steps:
            1. Set the data usage limit to current data usage + 10MB
            2. Start wifi tethering and connect a dut to the SSID
            3. Download 20MB data on tethered device
            4. File download stops and data limit reached
            5. Verify data usage limit
        """
        # connect device to wifi hotspot
        ad = self.tethered_devices[0]
        wutils.toggle_wifi_off_and_on(self.dut)
        wutils.start_wifi_tethering(self.dut,
                                    self.network[wutils.WifiEnums.SSID_KEY],
                                    self.network[wutils.WifiEnums.PWD_KEY],
                                    ttutils.WIFI_CONFIG_APBAND_2G)
        wutils.wifi_connect(ad, self.network)

        # get pre mobile data usage
        total_pre = self._get_total_data_usage_for_device(cconst.TYPE_MOBILE)

        # set data usage limit to current usage limit + 10MB
        self.log.info("Setting data usage limit to %sMB" %
                      (total_pre + INC_DATA))
        self.dut.droid.connectivitySetDataUsageLimit(
            self.sub_id, str(int((total_pre + INC_DATA) * BYTE_TO_MB_ANDROID)))

        # download file from tethered device
        http_file_download_by_chrome(ad,
                                     self.download_file,
                                     self.file_size,
                                     timeout=120)
        total_pst = self._get_total_data_usage_for_device(cconst.TYPE_MOBILE)

        # verify data usage
        connectivity_status = wutils.validate_connection(ad)
        self.dut.droid.connectivityFactoryResetNetworkPolicies(self.sub_id)
        wutils.stop_wifi_tethering(self.dut)
        self.log.info("Expected data usage: %s" % (total_pre + INC_DATA))
        self.log.info("Actual data usage: %s" % total_pst)
        asserts.assert_true(
            not connectivity_status,
            "Device has internet connectivity after reaching data limit")
        return total_pst - total_pre - INC_DATA < DATA_USG_ERR
    def _test_traffic_between_two_tethered_devices(self, ad, wd):
        """ Verify pinging interfaces of one DUT from another

        Args:
            1. ad - android device
            2. wd - wifi dongle
        """
        wutils.wifi_connect(ad, self.network)
        dutils.connect_wifi(wd, self.network)
        local_ip = ad.droid.connectivityGetIPv4Addresses('wlan0')[0]
        remote_ip = wd.ip_address()
        port = 8888

        time.sleep(6)  # wait until UDP packets method is invoked
        socket = sutils.open_datagram_socket(ad, local_ip, port)
        sutils.send_recv_data_datagram_sockets(ad, ad, socket, socket,
                                               remote_ip, port)
        sutils.close_datagram_socket(ad, socket)
 def test_reconnect_wifi_move_back_in_range(self):
     """
     Tests that Wifi Wake re-enables Wifi if the device moves out of range of
     the AP then came back.
     """
     wutils.wifi_connect(self.dut, self.ap_a, num_of_tries=5)
     wutils.wifi_toggle_state(self.dut, new_state=False)
     time.sleep(PRESCAN_DELAY_SEC)
     # init Wakeup Lock with AP A
     self.do_location_scan(CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT + 2)
     self.ap_a_off()
     # evict AP A from Wakeup Lock
     self.do_location_scan(CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT + 2)
     self.ap_a_on()
     self.do_location_scan()
     asserts.assert_true(
         self.dut.droid.wifiCheckState(),
         "Expect Wifi Wake to enable Wifi, but Wifi is disabled.")
 def test_reconnect_if_both_ap_evicted_from_wakeup_lock(self):
     """
     2 APs in Wakeup Lock, user moves out of range of both APs, should
     reconnect when user moves back in range of either AP.
     """
     wutils.wifi_connect(self.dut, self.ap_a, num_of_tries=5)
     wutils.wifi_connect(self.dut, self.ap_b, num_of_tries=5)
     wutils.wifi_toggle_state(self.dut, new_state=False)
     time.sleep(PRESCAN_DELAY_SEC)
     self.do_location_scan(CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT + 2)
     self.ap_a_off()
     self.ap_b_off()
     self.do_location_scan(CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT + 2)
     self.ap_a_on()
     self.do_location_scan()
     asserts.assert_true(
         self.dut.droid.wifiCheckState(),
         "Expect Wifi Wake to enable Wifi, but Wifi is disabled.")
    def eap_connect_toggle_wifi(self, config, *args):
        """Connects to an enterprise network, toggles wifi state and ensures
        that the device reconnects.

        This logic expect the enterprise network to have Internet access.

        Args:
            config: A dict representing a wifi enterprise configuration.
            args: args to be passed to |wutils.eap_connect|.

        Returns:
            True if the connection is successful and Internet access works.
        """
        ad = args[0]
        wutils.wifi_connect(ad, config)
        wutils.toggle_wifi_and_wait_for_reconnection(ad,
                                                     config,
                                                     num_of_tries=5)
Example #18
0
def connect_wlan_profile(pri_ad, network):
    """Disconnect and Connect to AP.

    Args:
        pri_ad: An android device.
        network: Network to which AP to be connected.

    Returns:
        True if successful, False otherwise.
    """
    reset_wifi(pri_ad)
    wifi_toggle_state(pri_ad, False)
    wifi_test_device_init(pri_ad)
    wifi_connect(pri_ad, network)
    if not wifi_connection_check(pri_ad, network["SSID"]):
        pri_ad.log.error("Wifi connection does not exist.")
        return False
    return True
 def test_no_reconnect_if_exists_ap_in_wakeup_lock(self):
     """
     2 APs in Wakeup Lock, user moves out of range of one AP but stays in
     range of the other, should not reconnect when user moves back in range
     of both.
     """
     wutils.wifi_connect(self.dut, self.ap_a, num_of_tries=5)
     wutils.wifi_connect(self.dut, self.ap_b, num_of_tries=5)
     wutils.wifi_toggle_state(self.dut, new_state=False)
     time.sleep(PRESCAN_DELAY_SEC)
     self.do_location_scan(CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT + 2)
     self.ap_b_off()
     self.do_location_scan(CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT + 2)
     self.ap_b_on()
     self.do_location_scan(CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT + 2)
     asserts.assert_false(
         self.dut.droid.wifiCheckState(),
         "Expect Wifi Wake to not enable Wifi, but Wifi was enabled.")
    def power_tel_tethering_test(self):
        """ Measure power and throughput during data transmission.

        Starts WiFi tethering in the DUT and connects a second device. Then
        the iPerf client is hosted in the second android device.

        """
        # Country Code set to 00 after toggling airplane mode.
        # We need to set this right before we setup a hotspot
        # Set country codes on both devices to US to connect to 5GHz
        country_code = "US"
        hotspot_dut = self.dut
        slave_dut = self.android_devices[1]
        for dut in [hotspot_dut, slave_dut]:
            self.log.info("Setting Country Code to %s for SN:%s" %
                          (country_code, dut.serial))
            wutils.set_wifi_country_code(dut, country_code)

        # Setup tethering
        wutils.start_wifi_tethering(self.dut,
                                    self.network[wutils.WifiEnums.SSID_KEY],
                                    self.network[wutils.WifiEnums.PWD_KEY],
                                    self.wifi_band)

        wutils.wifi_connect(self.android_devices[1],
                            self.network,
                            check_connectivity=False)

        # Start data traffic
        iperf_helpers = self.start_tel_traffic(self.android_devices[1])

        # Measure power
        result = self.collect_power_data()

        # Wait for iPerf to finish
        time.sleep(self.IPERF_MARGIN + 2)

        # Collect throughput measurement
        self.iperf_results = self.get_iperf_results(self.android_devices[1],
                                                    iperf_helpers)

        # Checks if power is below the required threshold.
        self.pass_fail_check(result.average_current)
Example #21
0
    def setup_hotspot(self, connect_client=False):
        """Configure Hotspot and connects client device.

        Args:
            connect_client: Connects (or not) the client device to the Hotspot
        """
        try:
            if self.test_configs.band == self.PARAM_2G_BAND:
                wifi_band_id = WIFI_CONFIG_APBAND_2G
            elif self.test_configs.band == self.PARAM_5G_BAND:
                wifi_band_id = WIFI_CONFIG_APBAND_5G
            else:
                raise ValueError()
        except ValueError:
            self.log.error(
                "The test name has to include parameter {} followed by "
                "either {} or {}.".format(self.PARAM_WIFI_BAND,
                                          self.PARAM_2G_BAND,
                                          self.PARAM_5G_BAND))
            return False

        # Turn WiFi ON for DUT (hotspot) and connect to AP (WiFiSharing)
        # Hotspot needs airplane mode OFF
        self.dut.droid.connectivityToggleAirplaneMode(False)
        time.sleep(2)
        if self.test_configs.wifi_sharing == 'OFF':
            wutils.wifi_toggle_state(self.dut, True)
            time.sleep(2)
        else:
            self.setup_ap_connection(
                self.main_network[self.test_configs.wifi_sharing])

        # Setup tethering on dut
        wutils.start_wifi_tethering(self.dut,
                                    self.network[wutils.WifiEnums.SSID_KEY],
                                    self.network[wutils.WifiEnums.PWD_KEY],
                                    wifi_band_id)

        # Connect client device to Hotspot
        if connect_client:
            wutils.wifi_connect(self.android_devices[1],
                                self.network,
                                check_connectivity=False)
    def roaming_from_AP1_and_AP2(self, AP1_network, AP2_network):
        """Test roaming between two APs.

        Args:
            AP1_network: AP-1's network information.
            AP2_network: AP-2's network information.

        Steps:
        1. Make AP1 visible, AP2 not visible.
        2. Connect to AP1's ssid.
        3. Make AP1 not visible, AP2 visible.
        4. Expect DUT to roam to AP2.
        5. Validate connection information and ping.
        """
        wutils.set_attns(self.attenuators, "AP1_on_AP2_off")
        wutils.wifi_connect(self.dut, AP1_network)
        self.log.info("Roaming from %s to %s", AP1_network, AP2_network)
        wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
            "AP1_off_AP2_on", AP2_network)
 def test_reconnect_wifi_disabled_after_disconnecting(self):
     """
     Tests that Wifi Wake reconnects to a network if Wifi was disabled long
     after disconnecting from a network.
     """
     wutils.wifi_connect(self.dut, self.ap_a, num_of_tries=5)
     self.dut.ed.clear_all_events()
     self.ap_a_off()
     wutils.wait_for_disconnect(self.dut)
     self.log.info("Wifi Disconnected")
     time.sleep(LAST_DISCONNECT_TIMEOUT_SEC * 1.2)
     wutils.wifi_toggle_state(self.dut, new_state=False)
     time.sleep(PRESCAN_DELAY_SEC)
     self.do_location_scan(CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT + 2)
     self.ap_a_on()
     self.do_location_scan()
     asserts.assert_true(
         self.dut.droid.wifiCheckState(),
         "Expect Wifi Wake to enable Wifi, but Wifi is disabled.")
 def test_no_reconnect_to_flaky_ap(self):
     """
     Tests that Wifi Wake does not reconnect to flaky networks.
     If a network sporadically connects and disconnects, and the user turns
     off Wifi even during the disconnected phase, Wifi Wake should not
     re-enable Wifi for that network.
     """
     wutils.wifi_connect(self.dut, self.ap_a, num_of_tries=5)
     self.ap_a_off()
     time.sleep(LAST_DISCONNECT_TIMEOUT_SEC * 0.4)
     wutils.wifi_toggle_state(self.dut, new_state=False)
     time.sleep(PRESCAN_DELAY_SEC)
     self.do_location_scan(CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT + 2)
     self.ap_a_on()
     self.do_location_scan(2 * CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT +
                           2)
     asserts.assert_false(
         self.dut.droid.wifiCheckState(),
         "Expect Wifi Wake to not enable Wifi, but Wifi was enabled.")
Example #25
0
    def test_wifi_tethering_mobile_data_usage_downlink(self):
        """ Verify mobile data usage with tethered device

        Steps:
            1. Start wifi hotspot and connect tethered device to it
            2. Get the data usage on hotspot device
            3. Download data on tethered device
            4. Get the new data usage on hotspot device
            5. Verify that hotspot device's data usage increased by downloaded file size
        """
        # connect device to wifi hotspot
        ad = self.tethered_devices[0]
        wutils.start_wifi_tethering(self.dut,
                                    self.network[wutils.WifiEnums.SSID_KEY],
                                    self.network[wutils.WifiEnums.PWD_KEY],
                                    ttutils.WIFI_CONFIG_APBAND_2G)
        wutils.wifi_connect(ad, self.network)

        # get pre mobile data usage
        (aos_pre, app_pre,
         total_pre) = self._get_data_usage(self.dut, cconst.TYPE_MOBILE)

        # download file through app
        self._download_data_through_app(ad)

        # get new mobile data usage
        (aos_pst, app_pst,
         total_pst) = self._get_data_usage(self.dut, cconst.TYPE_MOBILE)

        # stop wifi hotspot
        wutils.stop_wifi_tethering(self.dut)

        # verify data usage
        aos_diff = aos_pst - aos_pre
        app_diff = app_pst - app_pre
        total_diff = total_pst - total_pre
        self.log.info("Data usage of Android os increased by %s" % aos_diff)
        self.log.info("Data usage of ConnUID app increased by %s" % app_diff)
        self.log.info("Data usage on the device increased by %s" % total_diff)
        return (aos_diff < DATA_ERR) and (app_diff < DATA_ERR) and \
            (self.file_size < total_diff < self.file_size + DATA_USG_ERR)
Example #26
0
 def setup_dut(self, testcase_params):
     """Sets up the DUT in the configuration required by the test."""
     # Check battery level before test
     if not wputils.health_check(self.dut, 10):
         asserts.skip('Battery level too low. Skipping test.')
     # Turn screen off to preserve battery
     self.dut.go_to_sleep()
     if wputils.validate_network(self.dut,
                                 testcase_params['test_network']['SSID']):
         self.log.info('Already connected to desired network')
     else:
         wutils.wifi_toggle_state(self.dut, True)
         wutils.reset_wifi(self.dut)
         self.main_network[testcase_params['band']][
             'channel'] = testcase_params['channel']
         wutils.set_wifi_country_code(self.dut,
                                      self.testclass_params['country_code'])
         wutils.wifi_connect(self.dut,
                             self.main_network[testcase_params['band']],
                             num_of_tries=5)
     self.dut_ip = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0]
Example #27
0
    def test_wifi_framework_crash_reconnect(self):
        """Connect to a network, crash framework, then ensure
        we connect back to the previously connected network.

        Steps:
        1. Connect to a network.
        2. Restart framework.
        3. Reconnect to the previous network.

        """
        wutils.wifi_connect(self.dut, self.network, num_of_tries=3)
        # Restart framework
        self.log.info("Crashing framework")
        self.dut.restart_runtime()
        # We won't get the disconnect broadcast because framework crashed.
        # wutils.wait_for_disconnect(self.dut)
        time.sleep(DEFAULT_TIMEOUT)
        wifi_info = self.dut.droid.wifiGetConnectionInfo()
        if wifi_info[WifiEnums.SSID_KEY] != self.network[WifiEnums.SSID_KEY]:
            raise signals.TestFailure("Device did not connect to the"
                                      " network after crashing framework.")
Example #28
0
    def test_wpa_supplicant_crash_reconnect(self):
        """Connect to a network, crash wpa_supplicant, then ensure
        we connect back to the previously connected network.

        Steps:
        1. Connect to a network.
        2. Crash wpa_supplicant.
        3. Ensure we get a disconnect.
        4. Ensure we reconnect to the previous network.

        """
        wutils.wifi_connect(self.dut, self.network, num_of_tries=3)
        # Restart wificond
        self.log.info("Crashing wpa_supplicant")
        self.dut.adb.shell(SUPPLICANT_KILL_SHELL_COMMAND)
        wutils.wait_for_disconnect(self.dut)
        time.sleep(DEFAULT_TIMEOUT)
        wifi_info = self.dut.droid.wifiGetConnectionInfo()
        if wifi_info[WifiEnums.SSID_KEY] != self.network[WifiEnums.SSID_KEY]:
            raise signals.TestFailure("Device did not connect to the"
                                      " network after crashing wpa_supplicant.")
    def test_change_wifi_hotspot_ssid_when_hotspot_enabled(self):
        """ Steps:

            1. Start wifi tethering
            2. Verify wifi Ap configuration
            3. Change the SSID of the wifi hotspot while hotspot is on
            4. Verify the new SSID in wifi ap configuration
            5. Restart tethering and verify that the tethered device is able
               to connect to the new SSID
        """
        wutils.toggle_wifi_off_and_on(self.hotspot_device)
        dut = self.hotspot_device

        # start tethering and verify the wifi ap configuration settings
        self._start_wifi_tethering()
        wifi_ap = dut.droid.wifiGetApConfiguration()
        asserts.assert_true(
            wifi_ap[wutils.WifiEnums.SSID_KEY] == \
                self.network[wutils.WifiEnums.SSID_KEY],
            "Configured wifi hotspot SSID did not match with the expected SSID")
        wutils.wifi_connect(self.tethered_devices[0], self.network)

        # update the wifi ap configuration with new ssid
        config = {wutils.WifiEnums.SSID_KEY: self.new_ssid}
        config[wutils.WifiEnums.PWD_KEY] = self.network[
            wutils.WifiEnums.PWD_KEY]
        config[wutils.WifiEnums.APBAND_KEY] = WIFI_CONFIG_APBAND_2G
        self._save_wifi_softap_configuration(dut, config)

        # start wifi tethering with new wifi ap configuration
        wutils.stop_wifi_tethering(dut)
        self._turn_on_wifi_hotspot(dut)

        # verify dut can connect to new wifi ap configuration
        new_network = {wutils.WifiEnums.SSID_KEY: self.new_ssid,
                       wutils.WifiEnums.PWD_KEY: \
                       self.network[wutils.WifiEnums.PWD_KEY]}
        wutils.wifi_connect(self.tethered_devices[0], new_network)
        wutils.stop_wifi_tethering(self.hotspot_device)
    def eap_negative_connect_logic(self, config, ad):
        """Tries to connect to an enterprise network with invalid credentials
        and expect a failure.

        Args:
            config: A dict representing an invalid EAP credential.

        Returns:
            True if connection failed as expected, False otherwise.
        """
        with asserts.assert_raises(signals.TestFailure, extras=config):
            verdict = wutils.wifi_connect(ad, config)
        asserts.explicit_pass("Connection failed as expected.")