def setup_test(self):
        required_params = ("lci_reference", "lcr_reference",
                           "rtt_reference_distance_mm",
                           "stress_test_min_iteration_count",
                           "stress_test_target_run_time_sec")
        self.unpack_userparams(required_params)

        # can be moved to JSON config file
        self.rtt_reference_distance_margin_mm = 2000
        self.rtt_max_failure_rate_two_sided_rtt_percentage = 20
        self.rtt_max_failure_rate_one_sided_rtt_percentage = 50
        self.rtt_max_margin_exceeded_rate_two_sided_rtt_percentage = 10
        self.rtt_max_margin_exceeded_rate_one_sided_rtt_percentage = 50
        self.rtt_min_expected_rssi_dbm = -100

        for ad in self.android_devices:
            utils.set_location_service(ad, True)
            asserts.skip_if(
                not ad.droid.doesDeviceSupportWifiRttFeature(),
                "Device under test does not support Wi-Fi RTT - skipping test")
            wutils.wifi_toggle_state(ad, True)
            rtt_avail = ad.droid.wifiIsRttAvailable()
            if not rtt_avail:
                self.log.info('RTT not available. Waiting ...')
                rutils.wait_for_event(ad, rconsts.BROADCAST_WIFI_RTT_AVAILABLE)
            ad.ed.clear_all_events()
            rutils.config_privilege_override(ad, False)
            wutils.set_wifi_country_code(ad, wutils.WifiEnums.CountryCode.US)
            ad.rtt_capabilities = rutils.get_rtt_capabilities(ad)
Esempio n. 2
0
    def setup_dut(self, testcase_params):
        """Sets up the DUT in the configuration required by the test.

        Args:
            testcase_params: dict containing AP and other test params
        """
        # 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()
        band = self.access_point.band_lookup_by_channel(
            testcase_params['channel'])
        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)
            wutils.set_wifi_country_code(self.dut,
                                         self.testclass_params['country_code'])
            self.main_network[band]['channel'] = testcase_params['channel']
            wutils.wifi_connect(self.dut,
                                testcase_params['test_network'],
                                num_of_tries=5,
                                check_connectivity=False)
        self.dut_ip = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0]
Esempio n. 3
0
    def setup_class(self):
        super().setup_class()

        self.dut = self.android_devices[0]
        self.dut_client = self.android_devices[1]
        wutils.wifi_test_device_init(self.dut)
        wutils.wifi_test_device_init(self.dut_client)
        utils.require_sl4a((self.dut, self.dut_client))
        utils.sync_device_time(self.dut)
        utils.sync_device_time(self.dut_client)
        # 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)
        # Enable verbose logging on the duts
        self.dut.droid.wifiEnableVerboseLogging(1)
        asserts.assert_equal(
            self.dut.droid.wifiGetVerboseLoggingLevel(), 1,
            "Failed to enable WiFi verbose logging on the softap dut.")
        self.dut_client.droid.wifiEnableVerboseLogging(1)
        asserts.assert_equal(
            self.dut_client.droid.wifiGetVerboseLoggingLevel(), 1,
            "Failed to enable WiFi verbose logging on the client dut.")
        req_params = []
        opt_param = [
            "iperf_server_address", "reference_networks", "iperf_server_port"
        ]
        self.unpack_userparams(req_param_names=req_params,
                               opt_param_names=opt_param)
        self.chan_map = {
            v: k
            for k, v in hostapd_constants.CHANNEL_MAP.items()
        }
        self.pcap_procs = None
    def setup_dut(self, testcase_params):
        """Sets up the DUT in the configuration required by the test.

        Args:
            testcase_params: dict containing AP and other test params
        """
        # Check battery level before test
        if not wputils.health_check(
                self.dut, 20) and testcase_params['traffic_direction'] == 'UL':
            asserts.skip('Overheating or Battery level 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.reset_wifi(self.dut)
            wutils.set_wifi_country_code(self.dut,
                                         self.testclass_params['country_code'])
            testcase_params['test_network']['channel'] = testcase_params[
                'channel']
            wutils.wifi_connect(self.dut,
                                testcase_params['test_network'],
                                num_of_tries=5,
                                check_connectivity=True)
        self.dut_ip = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0]
    def setup_test(self):
        required_params = ("aware_default_power_mode", )
        self.unpack_userparams(required_params)

        for ad in self.android_devices:
            asserts.skip_if(
                not ad.droid.doesDeviceSupportWifiAwareFeature(),
                "Device under test does not support Wi-Fi Aware - skipping test"
            )
            wutils.wifi_toggle_state(ad, True)
            ad.droid.wifiP2pClose()
            utils.set_location_service(ad, True)
            aware_avail = ad.droid.wifiIsAwareAvailable()
            if not aware_avail:
                self.log.info('Aware not available. Waiting ...')
                autils.wait_for_event(ad,
                                      aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)
            ad.ed.clear_all_events()
            ad.aware_capabilities = autils.get_aware_capabilities(ad)
            self.reset_device_parameters(ad)
            self.reset_device_statistics(ad)
            self.set_power_mode_parameters(ad)
            wutils.set_wifi_country_code(ad, wutils.WifiEnums.CountryCode.US)
            autils.configure_ndp_allow_any_override(ad, True)
            # set randomization interval to 0 (disable) to reduce likelihood of
            # interference in tests
            autils.configure_mac_random_interval(ad, 0)
    def setup_dut(self, testcase_params):
        """Sets up the DUT in the configuration required by the test.

        Args:
            testcase_params: dict containing AP and other test params
        """
        # Check battery level before test
        if not wputils.health_check(self.dut, 10):
            asserts.skip('Battery level too low. Skipping test.')
        wutils.reset_wifi(self.dut)
        wutils.set_wifi_country_code(self.dut,
                                     self.testclass_params['country_code'])
        (primary_net_id,
         primary_net_config) = next(net for net in self.main_network.items()
                                    if net[1]['roaming_label'] == 'primary')
        network = primary_net_config.copy()
        network.pop('BSSID', None)
        self.dut.droid.wifiSetEnableAutoJoinWhenAssociated(1)
        wutils.wifi_connect(self.dut,
                            network,
                            num_of_tries=5,
                            check_connectivity=False)
        self.dut.droid.wifiSetEnableAutoJoinWhenAssociated(1)
        self.dut_ip = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0]
        if testcase_params['screen_on']:
            self.dut.wakeup_screen()
            self.dut.droid.wakeLockAcquireBright()
        time.sleep(MED_SLEEP)
Esempio n. 7
0
    def setup_class(self):
        super().setup_class()

        self.dut = self.android_devices[0]
        self.dut_client = self.android_devices[1]

        # Do a simple version of init - mainly just sync the time and enable
        # verbose logging.  This test will fail if the DUT has a sim and cell
        # data is disabled.  We would also like to test with phones in less
        # constrained states (or add variations where we specifically
        # constrain).
        utils.require_sl4a(self.android_devices)

        for ad in self.android_devices:
            wutils.wifi_test_device_init(ad)
            utils.sync_device_time(ad)
            # Set country code explicitly to "US".
            wutils.set_wifi_country_code(ad, WifiEnums.CountryCode.US)
            # Enable verbose logging on the duts.
            ad.droid.wifiEnableVerboseLogging(1)

        req_params = [
            "dbs_supported_models", "iperf_server_address", "iperf_server_port"
        ]
        self.unpack_userparams(req_param_names=req_params, )
        asserts.abort_class_if(
            self.dut.model not in self.dbs_supported_models,
            "Device %s does not support dual interfaces." % self.dut.model)
    def setup_dut(self, testcase_params):
        """Sets up the DUT in the configuration required by the test.

        Args:
            testcase_params: dict containing AP and other test params
        """
        # Configure the right INI settings
        if testcase_params['chain_mask'] != self.current_chain_mask:
            self.log.info('Updating WiFi chain mask to: {}'.format(
                testcase_params['chain_mask']))
            self.current_chain_mask = testcase_params['chain_mask']
            if testcase_params['chain_mask'] in ['0', '1']:
                wputils.set_ini_single_chain_mode(
                    self.dut, int(testcase_params['chain_mask']))
            else:
                wputils.set_ini_two_chain_mode(self.dut)
        # 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.reset_wifi(self.dut)
            wutils.set_wifi_country_code(self.dut,
                                         self.testclass_params['country_code'])
            testcase_params['test_network']['channel'] = testcase_params[
                'channel']
            wutils.wifi_connect(self.dut,
                                testcase_params['test_network'],
                                num_of_tries=5,
                                check_connectivity=False)
        self.dut_ip = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0]
Esempio n. 9
0
    def test_mac_randomization_ap_sta(self):
        """Bring up STA and softAP and verify MAC randomization.

        Steps:
            1. Connect to a network and get randomized MAC.
            2. Bring up softAP on the DUT.
            3. Connect to softAP network on the client and get MAC.
            4. Verify AP and STA use different randomized MACs.
            5. Find the channel of the SoftAp network.
            6. Configure sniffer on that channel.
            7. Verify the factory MAC is not leaked.

        """
        wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)
        wutils.set_wifi_country_code(self.dut_client,
                                     wutils.WifiEnums.CountryCode.US)
        mac_sta = self.connect_to_network_and_verify_mac_randomization(
            self.wpapsk_2g)
        softap = wutils.start_softap_and_verify(self, WIFI_CONFIG_APBAND_2G)
        wutils.connect_to_wifi_network(self.dut_client, softap)
        softap_info = self.dut_client.droid.wifiGetConnectionInfo()
        mac_ap = softap_info['mac_address']
        if mac_sta == mac_ap:
            raise signals.TestFailure("Same MAC address was used for both "
                                      "AP and STA: %s" % mac_sta)

        # Verify SoftAp MAC is randomized
        softap_mac = self.get_soft_ap_mac_address()
        message = (
            'Randomized SoftAp MAC and Factory SoftAp MAC are the same. '
            'Randomized SoftAp MAC = %s, Factory SoftAp MAC = %s' %
            (softap_mac, self.soft_ap_factory_mac))
        asserts.assert_true(softap_mac != self.soft_ap_factory_mac, message)

        softap_channel = hostapd_constants.CHANNEL_MAP[
            softap_info['frequency']]
        self.log.info("softap_channel = %s\n" % (softap_channel))
        result = self.packet_capture.configure_monitor_mode(
            hostapd_constants.BAND_2G, softap_channel)
        if not result:
            raise ValueError("Failed to configure channel for 2G band")
        self.pcap_procs = wutils.start_pcap(self.packet_capture, 'dual',
                                            self.test_name)
        # re-connect to the softAp network after sniffer is started
        wutils.connect_to_wifi_network(self.dut_client, self.wpapsk_2g)
        wutils.connect_to_wifi_network(self.dut_client, softap)
        time.sleep(SHORT_TIMEOUT)
        wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
        pcap_fname = '%s_%s.pcap' % \
            (self.pcap_procs[hostapd_constants.BAND_2G][1],
             hostapd_constants.BAND_2G.upper())
        packets = rdpcap(pcap_fname)
        self.verify_mac_not_found_in_pcap(self.soft_ap_factory_mac, packets)
        self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
        self.verify_mac_is_found_in_pcap(softap_mac, packets)
        self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets)
    def setup_class(self):
        self.dut = self.android_devices[0]
        self.admin = 'admin' + str(random.randint(1000001, 12345678))
        wutils.wifi_test_device_init(self.dut)
        # Set country code explicitly to "US".
        wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)

        asserts.assert_true(
            self.lock_pcap(),
            "Could not lock a Packet Capture. Aborting Interop test.")

        wutils.wifi_toggle_state(self.dut, True)
Esempio n. 11
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']
Esempio n. 12
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)
                               })
    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)
Esempio n. 14
0
    def setup_class(self):
        """ Executed before the test class is started.

        Configures the Hotspot SSID
        """
        super().setup_class()

        # If an SSID and password are indicated in the configuration parameters,
        # use those. If not, use default parameters and warn the user.
        if hasattr(self, self.CONFIG_KEY_WIFI):

            self.network = getattr(self, self.CONFIG_KEY_WIFI)

            if not (wutils.WifiEnums.SSID_KEY in self.network
                    and wutils.WifiEnums.PWD_KEY in self.network):
                raise RuntimeError(
                    "The '{}' key in the configuration file needs"
                    " to contain the '{}' and '{}' fields.".format(
                        self.CONFIG_KEY_WIFI, wutils.WifiEnums.SSID_KEY,
                        wutils.WifiEnums.PWD_KEY))
        else:

            self.log.warning("The configuration file doesn't indicate an SSID "
                             "password for the hotspot. Using default values. "
                             "To configured the SSID and pwd include a the key"
                             " {} containing the '{}' and '{}' fields.".format(
                                 self.CONFIG_KEY_WIFI,
                                 wutils.WifiEnums.SSID_KEY,
                                 wutils.WifiEnums.PWD_KEY))

            self.network = {
                wutils.WifiEnums.SSID_KEY: 'Pixel_1030',
                wutils.WifiEnums.PWD_KEY: '1234567890'
            }

        # Both devices need to have a country code in order
        # to use the 5 GHz band.
        wutils.set_wifi_country_code(self.android_devices[0], 'US')
        wutils.set_wifi_country_code(self.android_devices[1], 'US')
    def setup_dut(self, testcase_params):
        """Sets up the DUT in the configuration required by the test.

        Args:
            testcase_params: dict containing AP and other test params
        """
        # 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.reset_wifi(self.dut)
            wutils.set_wifi_country_code(self.dut,
                                         self.testclass_params['country_code'])
            testcase_params['test_network']['channel'] = testcase_params[
                'channel']
            wutils.wifi_connect(self.dut,
                                testcase_params['test_network'],
                                num_of_tries=5,
                                check_connectivity=True)
        self.dut_ip = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0]
        if testcase_params['channel'] not in self.atten_dut_chain_map.keys():
            self.atten_dut_chain_map[testcase_params[
                'channel']] = wputils.get_current_atten_dut_chain_map(
                    self.attenuators, self.dut, self.ping_server)
        self.log.info("Current Attenuator-DUT Chain Map: {}".format(
            self.atten_dut_chain_map[testcase_params['channel']]))
        for idx, atten in enumerate(self.attenuators):
            if self.atten_dut_chain_map[testcase_params['channel']][
                    idx] == testcase_params['attenuated_chain']:
                atten.offset = atten.instrument.max_atten
            else:
                atten.offset = 0
Esempio n. 16
0
    def setup_class(self):
        self.dut = self.android_devices[0]
        self.dut_client = self.android_devices[1]
        wutils.wifi_test_device_init(self.dut)
        wutils.wifi_test_device_init(self.dut_client)
        # Do a simple version of init - mainly just sync the time and enable
        # verbose logging.  This test will fail if the DUT has a sim and cell
        # data is disabled.  We would also like to test with phones in less
        # constrained states (or add variations where we specifically
        # constrain).
        utils.require_sl4a((self.dut, self.dut_client))
        utils.sync_device_time(self.dut)
        utils.sync_device_time(self.dut_client)
        # 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)
        # Enable verbose logging on the duts
        self.dut.droid.wifiEnableVerboseLogging(1)
        asserts.assert_equal(
            self.dut.droid.wifiGetVerboseLoggingLevel(), 1,
            "Failed to enable WiFi verbose logging on the softap dut.")
        self.dut_client.droid.wifiEnableVerboseLogging(1)
        asserts.assert_equal(
            self.dut_client.droid.wifiGetVerboseLoggingLevel(), 1,
            "Failed to enable WiFi verbose logging on the client dut.")

        req_params = ["AccessPoint", "dbs_supported_models", "stress_count"]
        opt_param = ["iperf_server_address"]
        self.unpack_userparams(req_param_names=req_params,
                               opt_param_names=opt_param)

        if self.dut.model not in self.dbs_supported_models:
            asserts.skip(("Device %s does not support dual interfaces.") %
                         self.dut.model)

        if "iperf_server_address" in self.user_params:
            self.iperf_server = self.iperf_servers[0]
        if hasattr(self, 'iperf_server'):
            self.iperf_server.start()

        # Set the client wifi state to on before the test begins.
        wutils.wifi_toggle_state(self.dut_client, True)

        # Init extra devices
        if len(self.android_devices) > 2:
            wutils.wifi_test_device_init(self.android_devices[2])
            utils.sync_device_time(self.android_devices[2])
            wutils.set_wifi_country_code(self.android_devices[2],
                                         wutils.WifiEnums.CountryCode.US)
            self.android_devices[2].droid.wifiEnableVerboseLogging(1)
            asserts.assert_equal(
                self.android_devices[2].droid.wifiGetVerboseLoggingLevel(), 1,
                "Failed to enable WiFi verbose logging on the client dut.")
    def setup_class(self):
        """It will setup the required dependencies from config file and configure
           the devices for softap mode testing.

        Returns:
            True if successfully configured the requirements for testing.
        """
        self.dut = self.android_devices[0]
        self.dut_client = self.android_devices[1]
        req_params = ["dbs_supported_models"]
        opt_param = ["open_network"]
        self.unpack_userparams(req_param_names=req_params,
                               opt_param_names=opt_param)
        if "AccessPoint" in self.user_params:
            self.legacy_configure_ap_and_start()
        self.open_network = self.open_network[0]["2g"]
        # Do a simple version of init - mainly just sync the time and enable
        # verbose logging.  This test will fail if the DUT has a sim and cell
        # data is disabled.  We would also like to test with phones in less
        # constrained states (or add variations where we specifically
        # constrain).
        utils.require_sl4a((self.dut, self.dut_client))
        utils.sync_device_time(self.dut)
        utils.sync_device_time(self.dut_client)
        # 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)
        # Enable verbose logging on the duts
        self.dut.droid.wifiEnableVerboseLogging(1)
        asserts.assert_equal(
            self.dut.droid.wifiGetVerboseLoggingLevel(), 1,
            "Failed to enable WiFi verbose logging on the softap dut.")
        self.dut_client.droid.wifiEnableVerboseLogging(1)
        asserts.assert_equal(
            self.dut_client.droid.wifiGetVerboseLoggingLevel(), 1,
            "Failed to enable WiFi verbose logging on the client dut.")
        wutils.wifi_toggle_state(self.dut, True)
        wutils.wifi_toggle_state(self.dut_client, True)
        self.AP_IFACE = 'wlan0'
        if self.dut.model in self.dbs_supported_models:
            self.AP_IFACE = 'wlan1'
        if len(self.android_devices) > 2:
            utils.sync_device_time(self.android_devices[2])
            wutils.set_wifi_country_code(self.android_devices[2],
                                         wutils.WifiEnums.CountryCode.US)
            self.android_devices[2].droid.wifiEnableVerboseLogging(1)
            asserts.assert_equal(
                self.android_devices[2].droid.wifiGetVerboseLoggingLevel(), 1,
                "Failed to enable WiFi verbose logging on the client dut.")
    def setup_class(self):

        self.log = logging.getLogger()
        self.tests = self.get_existing_test_names()

        # Obtain test parameters from user_params
        TEST_PARAMS = self.TAG + '_params'
        self.test_params = self.user_params.get(TEST_PARAMS, {})
        if not self.test_params:
            self.log.warning(TEST_PARAMS + ' was not found in the user '
                             'parameters defined in the config file.')

        # Override user_param values with test parameters
        self.user_params.update(self.test_params)

        # Unpack user_params with default values. All the usages of user_params
        # as self attributes need to be included either as a required parameter
        # or as a parameter with a default value.
        req_params = ['custom_files', 'mon_duration']
        self.unpack_userparams(req_params,
                               mon_freq=DEFAULT_MONSOON_FREQUENCY,
                               mon_offset=0,
                               bug_report=False,
                               extra_wait=None,
                               iperf_duration=None,
                               pass_fail_tolerance=THRESHOLD_TOLERANCE_DEFAULT,
                               mon_voltage=PHONE_BATTERY_VOLTAGE_DEFAULT)

        # Setup the must have controllers, phone and monsoon
        self.dut = self.android_devices[0]
        self.mon_data_path = os.path.join(self.log_path, 'Monsoon')
        os.makedirs(self.mon_data_path, exist_ok=True)
        self.mon = self.monsoons[0]
        self.mon.set_max_current(8.0)
        self.mon.set_voltage(self.mon_voltage)
        self.mon.attach_device(self.dut)

        # Unpack the thresholds file or fail class setup if it can't be found
        for file in self.custom_files:
            if 'pass_fail_threshold_' + self.dut.model in file:
                self.threshold_file = file
                break
        else:
            raise RuntimeError('Required test pass/fail threshold file is '
                               'missing')

        # Unpack the rockbottom script or fail class setup if it can't be found
        for file in self.custom_files:
            if 'rockbottom_' + self.dut.model in file:
                self.rockbottom_script = file
                break
        else:
            raise RuntimeError('Required rockbottom script is missing.')

        # Unpack optional custom files
        for file in self.custom_files:
            if 'attenuator_setting' in file:
                self.attenuation_file = file
            elif 'network_config' in file:
                self.network_file = file

        if hasattr(self, 'attenuators'):
            self.num_atten = self.attenuators[0].instrument.num_atten
            self.atten_level = self.unpack_custom_file(self.attenuation_file)
        self.threshold = self.unpack_custom_file(self.threshold_file)
        self.mon_info = self.create_monsoon_info()

        # Sync device time, timezone and country code
        utils.require_sl4a((self.dut, ))
        utils.sync_device_time(self.dut)
        wutils.set_wifi_country_code(self.dut, 'US')

        screen_on_img = self.user_params.get('screen_on_img', [])
        if screen_on_img:
            img_src = screen_on_img[0]
            img_dest = '/sdcard/Pictures/'
            success = self.dut.push_system_file(img_src, img_dest)
            if success:
                self.img_name = os.path.basename(img_src)