def run_incompat_service_then_aware(self, is_p2p):
        """Validate that if an Aware-incompatible service is already up then any
    Aware operation fails"""
        dut = self.android_devices[0]

        # start other service
        if is_p2p:
            dut.droid.wifiP2pInitialize()
        else:
            wutils.start_wifi_tethering(dut, self.TETHER_SSID, password=None)

        # expect an announcement about Aware non-availability
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)

        # try starting anyway (expect failure)
        dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)

        # stop other service
        if is_p2p:
            dut.droid.wifiP2pClose()
        else:
            wutils.stop_wifi_tethering(dut)

        # expect an announcement about Aware availability
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)

        # try starting Aware
        dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
    def run_aware_then_incompat_service(self, is_p2p):
        """Run test to validate that a running Aware session terminates when an
    Aware-incompatible service is started.

    Args:
      is_p2p: True for p2p, False for SoftAP
    """
        dut = self.android_devices[0]

        # start Aware
        id = dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)

        # start other service
        if is_p2p:
            dut.droid.wifiP2pInitialize()
        else:
            wutils.start_wifi_tethering(dut, self.TETHER_SSID, password=None)

        # expect an announcement about Aware non-availability
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)

        # local clean-up
        if not is_p2p:
            wutils.stop_wifi_tethering(dut)
Exemplo n.º 3
0
    def test_randomized_mac_used_during_connection(self):
        """Verify that the randomized MAC address and not the factory
        MAC address is used during connection by checking the softap logs.

        Steps:
        1. Set up softAP on dut_softap.
        2. Have dut connect to the softAp.
        3. Verify that only randomized MAC appears in softAp logs.
        """
        self.dut_softap.adb.shell(LOG_CLEAR)
        config = wutils.create_softap_config()
        wutils.start_wifi_tethering(self.dut_softap,
                                    config[wutils.WifiEnums.SSID_KEY],
                                    config[wutils.WifiEnums.PWD_KEY],
                                    WIFI_CONFIG_APBAND_2G)

        # Internet validation fails when dut_softap does not have a valid sim
        # supporting softap. Since this test is not checking for internet
        # validation, we suppress failure signals.
        wutils.connect_to_wifi_network(self.dut, config, assert_on_fail=False)
        mac = self.get_current_mac_address(self.dut)
        wutils.stop_wifi_tethering(self.dut_softap)

        self.is_valid_randomized_mac_address(mac)
        log = self.dut_softap.adb.shell(LOG_GREP.format(mac))
        asserts.assert_true(len(log) > 0, "Randomized MAC not in log.")
        log = self.dut_softap.adb.shell(LOG_GREP.format(self.dut_factory_mac))
        asserts.assert_true(len(log) == 0, "Factory MAC is in log.")
    def test_full_tether_startup(self):
        """Test full startup of wifi tethering

        1. Report current state.
        2. Switch to AP mode.
        3. verify SoftAP active.
        4. Shutdown wifi tethering.
        5. verify back to previous mode.
        """
        success = True
        initial_wifi_state = self.dut.droid.wifiCheckState()
        initial_cell_state = is_sim_ready(self.log, self.dut)
        self.log.info("current state: %s", initial_wifi_state)
        self.log.info("is sim ready? %s", initial_cell_state)

        if initial_cell_state:
            self.check_cell_data_and_enable()

        config = self.create_softap_config()

        success = wutils.start_wifi_tethering(self.dut,
                                              config[wutils.WifiEnums.SSID_KEY],
                                              config[wutils.WifiEnums.PWD_KEY])
        asserts.assert_true(success, "call to start_wifi_tethering returned false.  Check config")
        self.confirm_softap_in_scan_results(config[wutils.WifiEnums.SSID_KEY])
        wutils.stop_wifi_tethering(self.dut)
        asserts.assert_true(not self.dut.droid.wifiIsApEnabled(),
                            "SoftAp is still reported as running")
        if initial_wifi_state:
            self.verify_return_to_wifi_enabled()
        elif not self.dut.droid.wifiCheckState():
            asserts.fail("Wifi was disabled before softap and now it is enabled")
    def validate_ping_between_softap_and_client(self, config):
        """Test ping between softap and its client.

        Connect one android device to the wifi hotspot.
        Verify they can ping each other.

        Args:
            config: wifi network config with SSID, password
        """
        wutils.wifi_connect(self.dut_client, config, check_connectivity=False)

        dut_ip = self.dut.droid.connectivityGetIPv4Addresses(self.AP_IFACE)[0]
        dut_client_ip = self.dut_client.droid.connectivityGetIPv4Addresses(
            'wlan0')[0]

        self.dut.log.info("Try to ping %s" % dut_client_ip)
        asserts.assert_true(
            utils.adb_shell_ping(self.dut,
                                 count=10,
                                 dest_ip=dut_client_ip,
                                 timeout=20),
            "%s ping %s failed" % (self.dut.serial, dut_client_ip))

        self.dut_client.log.info("Try to ping %s" % dut_ip)
        asserts.assert_true(
            utils.adb_shell_ping(self.dut_client,
                                 count=10,
                                 dest_ip=dut_ip,
                                 timeout=20),
            "%s ping %s failed" % (self.dut_client.serial, dut_ip))

        wutils.stop_wifi_tethering(self.dut)
 def teardown_test(self):
     self.dut.log.debug("Toggling Airplane mode OFF.")
     asserts.assert_true(
         utils.force_airplane_mode(self.dut, False),
         "Can not turn off airplane mode: %s" % self.dut.serial)
     if self.dut.droid.wifiIsApEnabled():
         wutils.stop_wifi_tethering(self.dut)
    def test_tether_startup_while_connected_to_a_network(self):
        """Test full startup of wifi tethering in auto-band while the device
        is connected to a network.

        1. Connect to an open network.
        2. Turn on AP mode (in auto band).
        3. Verify SoftAP active.
        4. Make a client connect to the AP.
        5. Shutdown wifi tethering.
        6. Ensure that the client disconnected.
        """
        wutils.wifi_toggle_state(self.dut, True)
        wutils.wifi_connect(self.dut, self.open_network)
        config = self.create_softap_config()
        wutils.start_wifi_tethering(self.dut,
                                    config[wutils.WifiEnums.SSID_KEY],
                                    config[wutils.WifiEnums.PWD_KEY],
                                    WIFI_CONFIG_APBAND_AUTO)
        asserts.assert_true(self.dut.droid.wifiIsApEnabled(),
                            "SoftAp is not reported as running")
        # local hotspot may not have internet connectivity
        self.confirm_softap_in_scan_results(config[wutils.WifiEnums.SSID_KEY])
        wutils.wifi_connect(self.dut_client, config, check_connectivity=False)
        wutils.stop_wifi_tethering(self.dut)
        wutils.wait_for_disconnect(self.dut_client)
Exemplo n.º 8
0
    def test_wifi_tethering_open_network_5g_stress(self):
        """ Steps:

            1. Save wifi hotspot configuration with open network 5G band
               (Not allowed manually. b/72412729)
            2. Turn on wifi hotspot
            3. Connect tethered device and verify internet connectivity
            4. Turn off wifi hotspot
            5. Repeat steps 2 to 4
        """
        # save open network wifi ap configuration with 5G band
        config = {
            wutils.WifiEnums.SSID_KEY:
            self.open_network[wutils.WifiEnums.SSID_KEY]
        }
        config[wutils.WifiEnums.APBAND_KEY] = WIFI_CONFIG_APBAND_5G
        self._save_wifi_softap_configuration(self.hotspot_device, config)

        # turn on/off wifi hotspot, connect device
        for _ in range(9):
            self._turn_on_wifi_hotspot(self.hotspot_device)
            wutils.connect_to_wifi_network(self.tethered_devices[0],
                                           self.open_network)
            wutils.stop_wifi_tethering(self.hotspot_device)
            time.sleep(1)  # wait for some time before turning on hotspot
 def teardown_class(self):
     wutils.stop_wifi_tethering(self.dut)
     wutils.reset_wifi(self.dut)
     wutils.reset_wifi(self.dut_client)
     if "AccessPoint" in self.user_params:
         del self.user_params["reference_networks"]
         del self.user_params["open_network"]
Exemplo n.º 10
0
 def test_power_wifi_tethering_5ghz_no_devices_connected(self):
     """ Steps:
           1. Start wifi hotspot with 5Ghz band
           2. No devices connected to hotspot
           3. Measure power
     """
     self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
     self._measure_and_process_result()
     wutils.stop_wifi_tethering(self.hotspot_device)
 def teardown_test(self):
     if self.dut.droid.wifiIsApEnabled():
         wutils.stop_wifi_tethering(self.dut)
     self.dut.droid.wakeLockRelease()
     self.dut.droid.goToSleepNow()
     wutils.reset_wifi(self.dut)
     self.dut_client.droid.wakeLockRelease()
     self.dut_client.droid.goToSleepNow()
     wutils.reset_wifi(self.dut_client)
 def teardown_test(self):
     self.dut.droid.wakeLockRelease()
     self.dut.droid.goToSleepNow()
     wutils.stop_wifi_tethering(self.dut)
     wutils.reset_wifi(self.dut)
     wutils.reset_wifi(self.dut_client)
     self.access_points[0].close()
     del self.user_params["reference_networks"]
     del self.user_params["open_network"]
    def test_firmware_crash_softap_reconnect_stress(self):
        """Firmware crash stress test for softap mode

        1. Turn off dut's Wi-Fi
        2. Turn on dut's hotspot and connected by dut client
        3. Trigger firmware crash
        4. Check ssr happened
        5. Check the connectivity of hotspot's client
        6. Repeat step 3~5
        """
        wutils.wifi_toggle_state(self.dut, False)
        # Setup Soft AP
        sap_config = wutils.create_softap_config()
        wutils.start_wifi_tethering(self.dut,
                                    sap_config[wutils.WifiEnums.SSID_KEY],
                                    sap_config[wutils.WifiEnums.PWD_KEY],
                                    wutils.WifiEnums.WIFI_CONFIG_APBAND_2G)
        config = {
            "SSID": sap_config[wutils.WifiEnums.SSID_KEY],
            "password": sap_config[wutils.WifiEnums.PWD_KEY]
        }
        # DUT client connects to softap
        wutils.wifi_toggle_state(self.dut_client, True)
        wutils.connect_to_wifi_network(self.dut_client,
                                       config,
                                       check_connectivity=False)
        # Ping the DUT
        dut_addr = self.dut.droid.connectivityGetIPv4Addresses(
            self.ap_iface)[0]
        asserts.assert_true(
            utils.adb_shell_ping(self.dut_client,
                                 count=10,
                                 dest_ip=dut_addr,
                                 timeout=20),
            "%s ping %s failed" % (self.dut_client.serial, dut_addr))
        for count in range(self.stress_count):
            self.log.info(
                "%s: %d/%d" %
                (self.current_test_name, count + 1, self.stress_count))
            wutils.reset_wifi(self.dut_client)
            # Trigger firmware crash
            self.trigger_wifi_firmware_crash(self.dut)
            # Connect DUT to Network
            wutils.connect_to_wifi_network(self.dut_client,
                                           config,
                                           check_connectivity=False)
            # Ping the DUT
            server_addr = self.dut.droid.connectivityGetIPv4Addresses(
                self.ap_iface)[0]
            asserts.assert_true(
                utils.adb_shell_ping(self.dut_client,
                                     count=10,
                                     dest_ip=server_addr,
                                     timeout=20),
                "%s ping %s failed" % (self.dut_client.serial, server_addr))
        wutils.stop_wifi_tethering(self.dut)
Exemplo n.º 14
0
    def sap_rvr_test_func(self):
        """Main function to test Soft AP RvR.

        The function sets up the phones in the correct soft ap and client mode
        configuration and calls run_rvr to sweep attenuation and measure
        throughput

        Args:
            channel: Specifies AP's channel
            mode: Specifies AP's bandwidth/mode (11g, VHT20, VHT40, VHT80)
        Returns:
            rvr_result: dict containing rvr_results and meta data
        """
        #Initialize RvR test parameters
        num_atten_steps = int((self.test_params["rvr_atten_stop"] -
                               self.test_params["rvr_atten_start"]) /
                              self.test_params["rvr_atten_step"])
        self.rvr_atten_range = [
            self.test_params["rvr_atten_start"] +
            x * self.test_params["rvr_atten_step"]
            for x in range(0, num_atten_steps)
        ]
        rvr_result = {}
        # Reset WiFi on all devices
        for dev in self.android_devices:
            wutils.reset_wifi(dev)
            dev.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US)
        # Setup Soft AP
        sap_config = wutils.create_softap_config()
        wutils.start_wifi_tethering(self.android_devices[0],
                                    sap_config[wutils.WifiEnums.SSID_KEY],
                                    sap_config[wutils.WifiEnums.PWD_KEY],
                                    self.sap_band_enum)
        self.main_network = {
            "SSID": sap_config[wutils.WifiEnums.SSID_KEY],
            "password": sap_config[wutils.WifiEnums.PWD_KEY]
        }
        # Set attenuator to 0 dB
        [self.attenuators[i].set_atten(0) for i in range(self.num_atten)]
        # Connect DUT to Network
        wutils.wifi_connect(self.android_devices[1],
                            self.main_network,
                            num_of_tries=5,
                            assert_on_fail=False)
        connection_info = self.get_sap_connection_info()
        self.test_params["iperf_server_address"] = connection_info[
            "ap_ip_address"]
        # Run RvR and log result
        rvr_result["test_name"] = self.current_test_name
        rvr_result["attenuation"] = list(self.rvr_atten_range)
        rvr_result["fixed_attenuation"] = self.test_params[
            "fixed_attenuation"][str(connection_info["channel"])]
        rvr_result["throughput_receive"] = self.rvr_test()
        self.testclass_results.append(rvr_result)
        wutils.stop_wifi_tethering(self.android_devices[0])
        return rvr_result
Exemplo n.º 15
0
 def test_power_wifi_tethering_5ghz_connect_1device(self):
     """ Steps:
           1. Start wifi hotspot with 5GHz band
           2. Connect 1 device to hotspot
           3. Measure power
     """
     self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
     wutils.wifi_connect(self.tethered_devices[0], self.network)
     self._measure_and_process_result()
     wutils.stop_wifi_tethering(self.hotspot_device)
Exemplo n.º 16
0
 def test_power_wifi_tethering_5ghz_connect_1device_with_traffic(self):
     """ Steps:
           1. Start wifi hotspot with 5GHz band
           2. Connect 1 device to hotspot device
           3. Start traffic and measure power
     """
     self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
     wutils.wifi_connect(self.tethered_devices[0], self.network)
     self._start_traffic_measure_power(self.tethered_devices[0:1])
     wutils.stop_wifi_tethering(self.hotspot_device)
Exemplo n.º 17
0
 def test_power_wifi_tethering_2ghz_connect_5devices(self):
     """ Steps:
           1. Start wifi hotspot with 2GHz band
           2. Connect 5 devices to hotspot
           3. Measure power
     """
     self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
     for ad in self.tethered_devices:
         wutils.wifi_connect(ad, self.network)
     self._measure_and_process_result()
     wutils.stop_wifi_tethering(self.hotspot_device)
Exemplo n.º 18
0
    def test_wifi_tethering_5ghz_connect_disconnect_devices(self):
        """ Steps:

            1. Start wifi hotspot with 5ghz band
            2. Connect and disconnect multiple devices randomly
            3. Verify the correct functionality
        """
        wutils.toggle_wifi_off_and_on(self.hotspot_device)
        self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
        self._connect_disconnect_devices()
        wutils.stop_wifi_tethering(self.hotspot_device)
Exemplo n.º 19
0
 def test_power_wifi_tethering_5ghz_connect_5devices_with_traffic(self):
     """ Steps:
           1. Start wifi hotspot with 2GHz band
           2. Connect 5 devices to hotspot device
           3. Start traffic and measure power
     """
     self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
     for ad in self.tethered_devices:
         wutils.wifi_connect(ad, self.network)
     self._start_traffic_measure_power(self.tethered_devices)
     wutils.stop_wifi_tethering(self.hotspot_device)
Exemplo n.º 20
0
    def wifi_tethering_5ghz_traffic_between_2tethered_devices(self):
        """ Steps:

            1. Start wifi hotspot with 5ghz band
            2. Connect 2 tethered devices to the hotspot device
            3. Send traffic between the tethered devices
        """
        wutils.toggle_wifi_off_and_on(self.hotspot_device)
        self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
        self._test_traffic_between_two_tethered_devices(
            self.tethered_devices[0], self.arduino_wifi_dongles[0])
        wutils.stop_wifi_tethering(self.hotspot_device)
Exemplo n.º 21
0
 def verify_softap_full_on_off(self, network, softap_band):
     softap_config = self.start_softap_and_verify(softap_band)
     self.run_iperf_client((network, self.dut))
     self.run_iperf_client((softap_config, self.dut_client))
     if len(self.android_devices) > 2:
         self.log.info(
             "Testbed has extra android devices, do more validation")
         self.verify_traffic_between_softap_clients(self.dut_client,
                                                    self.android_devices[2])
     wutils.reset_wifi(self.dut_client)
     if len(self.android_devices) > 2:
         wutils.reset_wifi(self.android_devices[2])
     wutils.stop_wifi_tethering(self.dut)
Exemplo n.º 22
0
    def test_wifi_tethering_open_network_5g(self):
        """ Steps:

            1. Start wifi tethering with open network 5G band
               (Not allowed manually. b/72412729)
            2. Connect tethered device to the SSID
            3. Verify internet connectivity
        """
        wutils.start_wifi_tethering(
            self.hotspot_device, self.open_network[wutils.WifiEnums.SSID_KEY],
            None, WIFI_CONFIG_APBAND_5G)
        wutils.wifi_connect(self.tethered_devices[0], self.open_network)
        wutils.stop_wifi_tethering(self.hotspot_device)
    def validate_full_tether_startup(self,
                                     band=None,
                                     hidden=None,
                                     test_ping=False,
                                     test_clients=None):
        """Test full startup of wifi tethering

        1. Report current state.
        2. Switch to AP mode.
        3. verify SoftAP active.
        4. Shutdown wifi tethering.
        5. verify back to previous mode.
        """
        initial_wifi_state = self.dut.droid.wifiCheckState()
        initial_cell_state = tel_utils.is_sim_ready(self.log, self.dut)
        self.dut.log.info("current state: %s", initial_wifi_state)
        self.dut.log.info("is sim ready? %s", initial_cell_state)
        if initial_cell_state:
            self.check_cell_data_and_enable()
        config = self.create_softap_config()
        wutils.start_wifi_tethering(self.dut,
                                    config[wutils.WifiEnums.SSID_KEY],
                                    config[wutils.WifiEnums.PWD_KEY], band,
                                    hidden)
        if hidden:
            # First ensure it's not seen in scan results.
            self.confirm_softap_not_in_scan_results(
                config[wutils.WifiEnums.SSID_KEY])
            # If the network is hidden, it should be saved on the client to be
            # seen in scan results.
            config[wutils.WifiEnums.HIDDEN_KEY] = True
            ret = self.dut_client.droid.wifiAddNetwork(config)
            asserts.assert_true(ret != -1, "Add network %r failed" % config)
            self.dut_client.droid.wifiEnableNetwork(ret, 0)
        self.confirm_softap_in_scan_results(config[wutils.WifiEnums.SSID_KEY])
        if test_ping:
            self.validate_ping_between_softap_and_client(config)
        if test_clients:
            if hasattr(self, 'arduino_wifi_dongles'):
                self.validate_traffic_between_softap_clients(config)
            if len(self.android_devices) > 2:
                self.validate_ping_between_two_clients(config)
        wutils.stop_wifi_tethering(self.dut)
        asserts.assert_false(self.dut.droid.wifiIsApEnabled(),
                             "SoftAp is still reported as running")
        if initial_wifi_state:
            wutils.wait_for_wifi_state(self.dut, True)
        elif self.dut.droid.wifiCheckState():
            asserts.fail(
                "Wifi was disabled before softap and now it is enabled")
Exemplo n.º 24
0
    def test_wifi_tethering_2ghz_traffic_between_2tethered_devices(self):
        """ Steps:

            1. Start wifi hotspot with 2G band
            2. Connect 2 tethered devices to the hotspot device
            3. Ping interfaces between the tethered devices
        """
        asserts.skip_if(not hasattr(self, 'arduino_wifi_dongles'),
                        "No wifi dongles connected. Skipping test")
        wutils.toggle_wifi_off_and_on(self.hotspot_device)
        self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
        self._test_traffic_between_two_tethered_devices(
            self.tethered_devices[0], self.arduino_wifi_dongles[0])
        wutils.stop_wifi_tethering(self.hotspot_device)
Exemplo n.º 25
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
Exemplo n.º 26
0
 def teardown_test(self):
     # Prevent the stop wifi tethering failure to block ap close
     try:
         wutils.stop_wifi_tethering(self.dut)
     except signals.TestFailure:
         pass
     for ad in self.android_devices:
         ad.droid.wakeLockRelease()
         ad.droid.goToSleepNow()
         wutils.reset_wifi(ad)
     self.turn_location_on_and_scan_toggle_on()
     wutils.wifi_toggle_state(self.dut, True)
     self.access_points[0].close()
     del self.user_params["reference_networks"]
     del self.user_params["open_network"]
 def teardown_test(self):
     for ad in self.hs_enabled:
         try:
             wutils.stop_wifi_tethering(ad)
         except Exception as e:
           self.log.warn("Failed to stop wifi tethering: %s" % e)
     self.hs_enabled = []
     for i in range(len(self.android_devices)):
         ad = self.android_devices[i]
         stop_tcpdump(ad, self.tcpdumps[i], self.test_name)
         wutils.reset_wifi(ad)
         sub_id = str(ad.droid.telephonyGetSubscriberId())
         ad.droid.connectivityFactoryResetNetworkPolicies(sub_id)
         ad.droid.telephonyToggleDataConnection(True)
         ad.droid.wakeLockRelease()
         ad.droid.goToSleepNow()
     self.tcpdumps = []
Exemplo n.º 28
0
 def teardown_test(self):
     self.dut.droid.wakeLockRelease()
     self.dut.droid.goToSleepNow()
     wutils.stop_wifi_tethering(self.dut)
     wutils.reset_wifi(self.dut)
     wutils.reset_wifi(self.dut_client)
     wutils.stop_cnss_diags(self.android_devices)
     if hasattr(self, 'packet_capture') and self.pcap_procs:
         wutils.stop_pcap(self.packet_capture[0], self.pcap_procs, False)
         self.pcap_procs = None
     try:
         if "AccessPoint" in self.user_params:
             del self.user_params["reference_networks"]
             del self.user_params["open_network"]
     except:
         pass
     self.access_points[0].close()
Exemplo n.º 29
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
Exemplo n.º 30
0
    def test_stress_softAP_startup_and_stop_5g(self):
        """Test to bring up softAP and down for N times.

        Steps:
            1. Bring up softAP on 5G.
            2. Check for softAP on teh client device.
            3. Turn ON WiFi.
            4. Verify softAP is turned down and WiFi is up.

        """
        ap_ssid = "softap_" + utils.rand_ascii_str(8)
        ap_password = utils.rand_ascii_str(8)
        self.dut.log.info("softap setup: %s %s", ap_ssid, ap_password)
        config = {wutils.WifiEnums.SSID_KEY: ap_ssid}
        config[wutils.WifiEnums.PWD_KEY] = ap_password
        # Set country code explicitly to "US".
        wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)
        wutils.set_wifi_country_code(self.dut_client,
                                     wutils.WifiEnums.CountryCode.US)
        for count in range(self.stress_count):
            initial_wifi_state = self.dut.droid.wifiCheckState()
            wutils.start_wifi_tethering(self.dut, ap_ssid, ap_password,
                                        WifiEnums.WIFI_CONFIG_APBAND_5G)
            wutils.start_wifi_connection_scan_and_ensure_network_found(
                self.dut_client, ap_ssid)
            wutils.stop_wifi_tethering(self.dut)
            asserts.assert_false(self.dut.droid.wifiIsApEnabled(),
                                 "SoftAp failed to shutdown!")
            # Give some time for WiFi to come back to previous state.
            time.sleep(2)
            cur_wifi_state = self.dut.droid.wifiCheckState()
            if initial_wifi_state != cur_wifi_state:
                raise signals.TestFailure(
                    "Wifi state was %d before softAP and %d now!" %
                    (initial_wifi_state, cur_wifi_state),
                    extras={
                        "Iterations": "%d" % self.stress_count,
                        "Pass": "******" % count
                    })
        raise signals.TestPass(details="",
                               extras={
                                   "Iterations": "%d" % self.stress_count,
                                   "Pass": "******" % (count + 1)
                               })