예제 #1
0
    def wifi_scanner_batch_scan_full(self, scan_setting):
        """Common logic for batch scan test case for full scan result.

        1. Start WifiScanner batch scan with scan_setting for full scan result.
        2. Wait for the scan result event, wait time depend on scan settings
           parameter.
        3. Pop all full scan result events occurred earlier.
        4. Verify that full scan results match with scan results.

        Args:
            scan_setting: The params for the batch scan.
        """
        self.dut.ed.clear_all_events()
        data = wutils.start_wifi_background_scan(self.dut, scan_setting)
        idx = data["Index"]
        scan_rt = data["ScanElapsedRealtime"]
        self.log.info("Wifi batch shot scan started with index: %s", idx)
        #generating event wait time from scan setting plus leeway
        scan_time, scan_channels = wutils.get_scan_time_and_channels(
            self.wifi_chs, scan_setting, self.stime_channel)
        # multiply scan period by two to account for scheduler changing period
        scan_time += scan_setting[
            'periodInMs'] * 2  #add scan period delay for next cycle
        wait_time = scan_time / 1000 + self.leeway
        validity = False
        try:
            for snumber in range(1, 3):
                results = []
                event_name = "%s%sonResults" % (EVENT_TAG, idx)
                self.log.debug("Waiting for event: %s for time %s", event_name,
                               wait_time)
                event = self.dut.ed.pop_event(event_name, wait_time)
                self.log.debug("Event received: %s", event)
                bssids, validity = self.proces_and_valid_batch_scan_result(
                    event["data"]["Results"], scan_rt, event["data"][KEY_RET],
                    scan_setting)
                event_name = "%s%sonFullResult" % (EVENT_TAG, idx)
                results = self.pop_scan_result_events(event_name)
                asserts.assert_true(
                    len(results) >= bssids,
                    "Full single shot result don't match %s" % len(results))
                asserts.assert_true(bssids > 0, EMPTY_RESULT)
                asserts.assert_true(validity, INVALID_RESULT)
        except queue.Empty as error:
            raise AssertionError("Event did not triggered for batch scan %s" %
                                 error)
        finally:
            self.dut.droid.wifiScannerStopBackgroundScan(idx)
            self.dut.ed.clear_all_events()
 def start_scan(self, scan_setting):
     data = wutils.start_wifi_background_scan(self.dut, scan_setting)
     idx = data["Index"]
     # Calculate event wait time from scan setting plus leeway
     scan_time, scan_channels = wutils.get_scan_time_and_channels(
         self.wifi_chs, scan_setting, self.stime_channel)
     scan_period = scan_setting['periodInMs']
     report_type = scan_setting['reportEvents']
     if report_type & WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN:
         scan_time += scan_period
     else:
         max_scan = scan_setting['maxScansToCache']
         scan_time += max_scan * scan_period
     wait_time = scan_time / 1000 + self.leeway
     return idx, wait_time, scan_channels
예제 #3
0
    def proces_and_valid_batch_scan_result(self, scan_resutls, scan_rt,
                                           result_rt, scan_setting):
        """This function process scan results and validate against settings used
        while starting the scan.

        There are two steps for the verification. First it checks that all the
        wifi networks in results are of the correct frequencies set by scan setting
        params. Then it checks that the delta between the batch of scan results less
        than the time required for scanning channel set by scan setting params.

        Args:
            scan_results: scan results reported.
            scan_rt: Elapsed real time on start scan.
            result_rt: Elapsed ral time on results reported.
            scan_setting: The params for the single scan.

        Returns:
            bssids: total number of bssids scan result have
            validity: True if the all scan result are valid.
        """
        bssids = 0
        validity = True
        scan_time_mic = 0
        scan_channels = []
        scan_time, scan_channels = wutils.get_scan_time_and_channels(
            self.wifi_chs, scan_setting, self.stime_channel)
        scan_time_mic = scan_time * 1000
        for i, batch in enumerate(scan_resutls, start=1):
            asserts.assert_true(
                batch["ScanResults"],
                "At least one scan result is required to validate")
            max_scan_interval = batch["ScanResults"][0][
                "timestamp"] + scan_time_mic
            self.log.debug("max_scan_interval: %s", max_scan_interval)
            for result in batch["ScanResults"]:
                if (result["frequency"] not in scan_channels
                        or result["timestamp"] > max_scan_interval
                        or result["timestamp"] < scan_rt * 1000
                        or result["timestamp"] > result_rt * 1000):
                    self.log.error("Result didn't match requirement: %s",
                                   result)
                    validity = False
            self.log.info("Number of scan result in batch %s: %s", i,
                          len(batch["ScanResults"]))
            bssids += len(batch["ScanResults"])
        return bssids, validity
    def do_location_scan(self, num_times=1):
        scan_settings = {
            "band": wutils.WifiEnums.WIFI_BAND_BOTH,
            "periodInMs": 0,
            "reportEvents": wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN
        }

        wifi_chs = wutils.WifiChannelUS(self.dut.model)
        stime_channel = 47  # dwell time plus 2ms
        leeway = 10

        for i in range(num_times):
            self.log.info("Scan count: {}".format(i))
            data = wutils.start_wifi_single_scan(self.dut, scan_settings)
            idx = data["Index"]
            scan_rt = data["ScanElapsedRealtime"]
            self.log.debug(
                "Wifi single shot scan started index: %s at real time: %s",
                idx, scan_rt)
            # generating event wait time from scan setting plus leeway
            scan_time, scan_channels = wutils.get_scan_time_and_channels(
                wifi_chs, scan_settings, stime_channel)
            wait_time = int(scan_time / 1000) + leeway
            # track number of result received
            result_received = 0
            try:
                for _ in range(1, 3):
                    event_name = "{}{}onResults".format("WifiScannerScan", idx)
                    self.log.debug("Waiting for event: %s for time %s",
                                   event_name, wait_time)
                    event = self.dut.ed.pop_event(event_name, wait_time)
                    self.log.debug("Event received: %s", event)
                    result_received += 1
            except queue.Empty as error:
                asserts.assert_true(
                    result_received >= 1,
                    "Event did not triggered for single shot {}".format(error))
            finally:
                self.dut.droid.wifiScannerStopScan(idx)
                # For single shot number of result received and length of result
                # should be one
                asserts.assert_true(
                    result_received == 1,
                    "Test fail because received result {}".format(
                        result_received))
예제 #5
0
    def wifi_scanner_single_scan_full(self, scan_setting):
        """Common logic for single scan test case for full scan result.

        1. Start WifiScanner single scan with scan_setting for full scan result.
        2. Wait for the scan result event, wait time depend on scan settings
           parameter.
        3. Pop all full scan result events occurred earlier.
        4. Verify that full scan results match with normal scan results.

        Args:
            scan_setting: The parameters for the single scan.
        """
        self.dut.ed.clear_all_events()
        data = wutils.start_wifi_single_scan(self.dut, scan_setting)
        idx = data["Index"]
        scan_rt = data["ScanElapsedRealtime"]
        self.log.info("Wifi single shot scan started with index: %s", idx)
        #generating event wait time from scan setting plus leeway
        scan_time, scan_channels = wutils.get_scan_time_and_channels(
            self.wifi_chs, scan_setting, self.stime_channel)
        wait_time = int(scan_time / 1000) + self.leeway
        results = []
        validity = False
        try:
            event_name = "%s%sonResults" % (EVENT_TAG, idx)
            self.log.debug("Waiting for event: %s for time %s", event_name,
                           wait_time)
            event = self.dut.ed.pop_event(event_name, wait_time)
            self.log.info("Event received: %s", event)
            bssids, validity = (self.proces_and_valid_batch_scan_result(
                event["data"]["Results"], scan_rt, event["data"][KEY_RET],
                scan_setting))
            asserts.assert_true(bssids > 0, EMPTY_RESULT)
            asserts.assert_true(validity, INVALID_RESULT)
            event_name = "{}{}onFullResult".format(EVENT_TAG, idx)
            results = self.pop_scan_result_events(event_name)
            asserts.assert_true(
                len(results) >= bssids,
                "Full single shot result don't match {}".format(len(results)))
        except queue.Empty as error:
            raise AssertionError(
                "Event did not triggered for single shot {}".format(error))
        finally:
            self.dut.droid.wifiScannerStopScan(idx)
예제 #6
0
    def test_wifi_connection_while_single_scan(self):
        """Test configuring a connection parallel to wifi scanner single scan.

         1. Start WifiScanner single scan for both band with default scan settings.
         2. Configure a connection to reference network.
         3. Verify that connection to reference network occurred.
         2. Verify that scanner report single scan results.
        """
        self.attenuators[ATTENUATOR].set_atten(0)
        data = wutils.start_wifi_single_scan(self.dut,
                                             self.default_scan_setting)
        idx = data["Index"]
        scan_rt = data["ScanElapsedRealtime"]
        self.log.info(
            "Wifi single shot scan started with index: {}".format(idx))
        asserts.assert_true(self.connect_to_reference_network(), NETWORK_ERROR)
        time.sleep(10)  #wait for connection to be active
        asserts.assert_true(
            wutils.validate_connection(self.dut, self.ping_addr),
            "Error, No internet connection for current network")
        #generating event wait time from scan setting plus leeway
        scan_time, scan_channels = wutils.get_scan_time_and_channels(
            self.wifi_chs, self.default_scan_setting, self.stime_channel)
        wait_time = int(scan_time / 1000) + self.leeway
        validity = False
        try:
            event_name = "{}{}onResults".format(EVENT_TAG, idx)
            self.log.debug("Waiting for event: {} for time {}".format(
                event_name, wait_time))
            event = self.dut.ed.pop_event(event_name, wait_time)
            self.log.debug("Event received: {}".format(event))
            results = event["data"]["Results"]
            bssids, validity = self.proces_and_valid_batch_scan_result(
                results, scan_rt, event["data"][KEY_RET],
                self.default_scan_setting)
            self.log.info("Scan number Buckets: {}\nTotal BSSID: {}".format(
                len(results), bssids))
            asserts.assert_true(
                len(results) == 1 and bssids >= 1, EMPTY_RESULT)
        except queue.Empty as error:
            raise AssertionError(
                "Event did not triggered for single scan {}".format(error))
예제 #7
0
    def test_wifi_scanner_single_scan_in_isolated(self):
        """Test WiFi scanner in isolated environment with default scan settings.

         1. Created isolated environment by attenuating the single by 90db
         2. Start WifiScanner single scan for mix channels with default setting
            parameters.
         3. Verify that empty scan results reported.
        """
        self.attenuators[0].set_atten(90)
        self.attenuators[1].set_atten(90)
        data = wutils.start_wifi_single_scan(self.dut,
                                             self.default_scan_setting)
        idx = data["Index"]
        scan_rt = data["ScanElapsedRealtime"]
        self.log.info(
            "Wifi single shot scan started with index: {}".format(idx))
        results = []
        #generating event wait time from scan setting plus leeway
        scan_time, scan_channels = wutils.get_scan_time_and_channels(
            self.wifi_chs, self.default_scan_setting, self.stime_channel)
        wait_time = int(scan_time / 1000) + self.leeway
        try:
            event_name = "{}{}onResults".format(EVENT_TAG, idx)
            self.log.debug("Waiting for event: {} for time {}".format(
                event_name, wait_time))
            event = self.dut.ed.pop_event(event_name, wait_time)
            self.log.debug("Event received: {}".format(event))
            results = event["data"]["Results"]
            for batch in results:
                asserts.assert_false(
                    batch["ScanResults"], "Test fail because report scan "
                    "results reported are not empty")
        except queue.Empty as error:
            raise AssertionError(
                "Event did not triggered for in isolated environment {}".
                format(error))
        finally:
            self.dut.ed.clear_all_events()
            self.attenuators[0].set_atten(0)
            self.attenuators[1].set_atten(0)
예제 #8
0
    def test_wifi_connection_and_pno_while_batch_scan(self):
        """Test configuring a connection and PNO connection parallel to wifi
           scanner batch scan.

         1. Start WifiScanner batch scan with default batch scan settings.
         2. Wait for scan result event for a time depend on scan settings.
         3. Verify reported batch scan results.
         4. Configure a connection to reference network.
         5. Verify that connection to reference network occurred.
         6. Wait for scan result event for a time depend on scan settings.
         7. Verify reported batch scan results.
         8. Trigger PNO by attenuate the signal to move out of range.
         9. Wait for scan result event for a time depend on scan settings.
         10. Verify reported batch scan results.
         11. Attenuate the signal to move in range.
         12. Verify connection occurred through PNO.
        """
        self.attenuators[ATTENUATOR].set_atten(0)
        data = wutils.start_wifi_background_scan(
            self.dut, self.default_batch_scan_setting)
        idx = data["Index"]
        scan_rt = data["ScanElapsedRealtime"]
        self.log.info(
            "Wifi background scan started with index: {} rt {}".format(
                idx, scan_rt))
        #generating event wait time from scan setting plus leeway
        scan_time, scan_channels = wutils.get_scan_time_and_channels(
            self.wifi_chs, self.default_batch_scan_setting, self.stime_channel)
        #default number buckets
        number_bucket = 10
        time_cache = self.default_batch_scan_setting[
            'periodInMs'] * number_bucket  #default cache
        #add 2 seconds extra time for switch between the channel for connection scan
        #multiply cache time by two to account for scheduler changing period
        wait_time = (time_cache * 2 + scan_time) / 1000 + self.leeway + 2
        result_flag = 0
        try:
            for snumber in range(1, 7):
                event_name = "{}{}onResults".format(EVENT_TAG, idx)
                self.log.info("Waiting for event: {}".format(event_name))
                event = self.dut.ed.pop_event(event_name, wait_time)
                self.log.debug("Event onResults: {}".format(event))
                results = event["data"]["Results"]
                bssids, validity = self.proces_and_valid_batch_scan_result(
                    results, scan_rt, event["data"][KEY_RET],
                    self.default_batch_scan_setting)
                self.log.info(
                    "Scan number: {}\n Buckets: {}\n BSSID: {}".format(
                        snumber, len(results), bssids))
                asserts.assert_true(bssids >= 1,
                                    "Not able to fetch scan result")
                if snumber == 1:
                    self.log.info(
                        "Try to connect AP while waiting for event: {}".format(
                            event_name))
                    asserts.assert_true(self.connect_to_reference_network(),
                                        NETWORK_ERROR)
                    time.sleep(10)  #wait for connection to be active
                    asserts.assert_true(
                        wutils.validate_connection(self.dut, self.ping_addr),
                        "Error, No internet connection for current network")
                elif snumber == 3:
                    self.log.info("Kicking PNO for reference network")
                    self.attenuators[ATTENUATOR].set_atten(90)
                elif snumber == 4:
                    self.log.info("Bring back device for PNO connection")
                    current_network = self.dut.droid.wifiGetConnectionInfo()
                    self.log.info(
                        "Current network: {}".format(current_network))
                    asserts.assert_true('network_id' in current_network,
                                        NETWORK_ID_ERROR)
                    asserts.assert_true(
                        current_network['network_id'] == -1,
                        "Device is still connected to network  {}".format(
                            current_network[wutils.WifiEnums.SSID_KEY]))
                    self.attenuators[ATTENUATOR].set_atten(0)
                    time.sleep(
                        10
                    )  #wait for connection to take place before waiting for scan result
                elif snumber == 6:
                    self.log.info(
                        "Check connection through PNO for reference network")
                    current_network = self.dut.droid.wifiGetConnectionInfo()
                    self.log.info(
                        "Current network: {}".format(current_network))
                    asserts.assert_true('network_id' in current_network,
                                        NETWORK_ID_ERROR)
                    asserts.assert_true(current_network['network_id'] >= 0,
                                        NETWORK_ERROR)
                    time.sleep(10)  #wait for connection to be active
                    asserts.assert_true(
                        wutils.validate_connection(self.dut, self.ping_addr),
                        "Error, No internet connection for current network")
                    wutils.wifi_forget_network(
                        self.dut, self.reference_networks[0]["2g"]["SSID"])
        except queue.Empty as error:
            raise AssertionError(
                "Event did not triggered for batch scan {}".format(error))
        finally:
            self.dut.droid.wifiScannerStopBackgroundScan(idx)
            self.dut.ed.clear_all_events()
예제 #9
0
    def wifi_scanner_batch_scan(self, scan_setting):
        """Common logic for an enumerated wifi scanner batch scan test case.

        1. Start WifiScanner batch scan for given scan_setting.
        2. Wait for the scan result event, wait time depend on scan settings
           parameter.
        3. Verify that scan results match with scan settings parameters.
        4. Also verify that multiple scan result events trigger.

        Args:
            scan_setting: The parameters for the batch scan.
        """
        data = wutils.start_wifi_background_scan(self.dut, scan_setting)
        idx = data["Index"]
        scan_rt = data["ScanElapsedRealtime"]
        self.log.info(
            "Wifi background scan started with index: %s real time %s", idx,
            scan_rt)
        scan_time, scan_channels = wutils.get_scan_time_and_channels(
            self.wifi_chs, scan_setting, self.stime_channel)
        #generating event wait time from scan setting plus leeway
        time_cache = 0
        number_bucket = 1  #bucket for Report result on each scan
        check_get_result = False
        if scan_setting[
                'reportEvents'] == wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL:
            check_get_result = True
            if ('maxScansToCache' in scan_setting
                    and scan_setting['maxScansToCache'] != 0):
                time_cache = (scan_setting['maxScansToCache'] *
                              scan_setting['periodInMs'])
                number_bucket = scan_setting['maxScansToCache']
            else:
                time_cache = 10 * scan_setting[
                    'periodInMs']  #10 as default max scan cache
                number_bucket = 10
        else:
            time_cache = scan_setting[
                'periodInMs']  #need while waiting for seconds resutls
        # multiply cache time by two to account for scheduler changing period
        wait_time = (time_cache * 2 + scan_time) / 1000 + self.leeway
        validity = False
        try:
            for snumber in range(1, 3):
                event_name = "%s%sonResults" % (EVENT_TAG, idx)
                self.log.info("Waiting for event: %s for time %s", event_name,
                              wait_time)
                event = self.dut.ed.pop_event(event_name, wait_time)
                self.log.debug("Event received: %s", event)
                results = event["data"]["Results"]
                bssids, validity = (self.proces_and_valid_batch_scan_result(
                    results, scan_rt, event["data"][KEY_RET], scan_setting))
                self.log.info("Scan number: %s\n Buckets: %s\n  BSSID: %s",
                              snumber, len(results), bssids)
                asserts.assert_equal(
                    len(results), number_bucket,
                    "Test fail because number_bucket %s" % len(results))
                asserts.assert_true(bssids >= 1, EMPTY_RESULT)
                asserts.assert_true(validity, INVALID_RESULT)
                if snumber % 2 == 1 and check_get_result:
                    self.log.info("Get Scan result using GetScanResult API")
                    time.sleep(wait_time / number_bucket)
                    if self.dut.droid.wifiScannerGetScanResults():
                        event = self.dut.ed.pop_event(event_name, 1)
                        self.log.debug("Event onResults: %s", event)
                        results = event["data"]["Results"]
                        bssids, validity = self.proces_and_valid_batch_scan_result(
                            results, scan_rt, event["data"][KEY_RET],
                            scan_setting)
                        self.log.info("Got Scan result number: %s BSSID: %s",
                                      snumber, bssids)
                        asserts.assert_true(bssids >= 1, EMPTY_RESULT)
                        asserts.assert_true(validity, INVALID_RESULT)
                    else:
                        self.log.error("Error while fetching the scan result")
        except queue.Empty as error:
            raise AssertionError("Event did not triggered for batch scan %s" %
                                 error)
        finally:
            self.dut.droid.wifiScannerStopBackgroundScan(idx)
            self.dut.ed.clear_all_events()