def start_scan_and_validate_environment(self, scan_setting, bssid_settings): """Validate environment for test using current scan result for provided settings. This function start the scan for given setting and verify that interested Bssids are in scan result or not. Args: scan_setting: Setting used for starting the scan. bssid_settings: list of bssid settings. Returns: True, if bssid not found in scan result. """ try: data = wutils.start_wifi_background_scan(self.dut, scan_setting) self.scan_idx = data["Index"] results = self.fetch_scan_result(self.scan_idx, scan_setting) self.log.debug("scan result %s.", results) asserts.assert_true( results, "Device is not able to fetch the scan results") for result in results: for bssid_setting in bssid_settings: if bssid_setting[wutils.WifiEnums.BSSID_KEY] == result[ wutils.WifiEnums.BSSID_KEY]: asserts.fail( ("Test environment is not valid: Bssid %s" "already exist in current scan results") % result[wutils.WifiEnums.BSSID_KEY]) except queue.Empty as error: self.dut.droid.wifiScannerStopBackgroundScan(self.scan_idx) raise AssertionError( "OnResult event did not triggered for scanner\n%s" % error)
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
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()
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()