blob: 05945dcbc33d68def1ed9482d70f763d4cee6c82 [file] [log] [blame]
tturney1bdf77d2015-12-28 17:46:13 -08001#!/usr/bin/env python3.4
2#
3# Copyright 2016 - The Android Open Source Project
Ang Li73697b32015-12-03 00:41:53 +00004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import itertools
Ang Li2d3fe982016-06-08 10:00:43 -070018import queue
19import time
20import traceback
Ang Li73697b32015-12-03 00:41:53 +000021
Ang Lic2d45212016-03-10 18:38:53 -080022from acts import asserts
Ang Li2d3fe982016-06-08 10:00:43 -070023from acts import base_test
24from acts import utils
Girish Moturu00304f82017-04-13 09:28:37 +053025from acts.test_decorators import test_tracker_info
Bindu Mahadev04ce7b72016-12-13 12:14:36 -080026from acts.test_utils.wifi import wifi_constants
Ang Li2d3fe982016-06-08 10:00:43 -070027from acts.test_utils.wifi import wifi_test_utils as wutils
Bindu Mahadevd34835d2017-06-12 17:21:09 -070028from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest
Ang Li73697b32015-12-03 00:41:53 +000029
Ang Li2d3fe982016-06-08 10:00:43 -070030SCANTIME = 10000 #framework support only 10s as minimum scan interval
Ang Li73697b32015-12-03 00:41:53 +000031NUMBSSIDPERSCAN = 8
32EVENT_TAG = "WifiScannerScan"
Ang Li2d3fe982016-06-08 10:00:43 -070033SCAN_TIME_PASSIVE = 47 # dwell time plus 2ms
34SCAN_TIME_ACTIVE = 32 # dwell time plus 2ms
Ang Li73697b32015-12-03 00:41:53 +000035SHORT_TIMEOUT = 30
36NETWORK_ID_ERROR = "Network don't have ID"
37NETWORK_ERROR = "Device is not connected to reference network"
38INVALID_RESULT = "Test fail because scan result reported are not valid"
39EMPTY_RESULT = "Test fail because empty scan result reported"
40KEY_RET = "ResultElapsedRealtime"
Bindu Mahadev06fb2e12017-06-06 15:45:34 -070041ATTENUATOR = 0
Ang Li2d3fe982016-06-08 10:00:43 -070042
Ang Li73697b32015-12-03 00:41:53 +000043class WifiScannerScanError(Exception):
44 pass
45
Ang Li73697b32015-12-03 00:41:53 +000046
Bindu Mahadevd34835d2017-06-12 17:21:09 -070047class WifiScannerScanTest(WifiBaseTest):
Ang Li73697b32015-12-03 00:41:53 +000048 def __init__(self, controllers):
Bindu Mahadevd34835d2017-06-12 17:21:09 -070049 WifiBaseTest.__init__(self, controllers)
Ang Li2d3fe982016-06-08 10:00:43 -070050 # TODO(angli): Remove this list.
51 # There are order dependencies among these tests so we'll have to leave
52 # it here for now. :(
Ang Li73697b32015-12-03 00:41:53 +000053 self.tests = (
Girish Moturucb5d2522017-08-01 15:55:18 +053054 "test_available_channels_band_1",
55 "test_available_channels_band_2",
56 "test_available_channels_band_3",
57 "test_available_channels_band_4",
58 "test_available_channels_band_6",
59 "test_available_channels_band_7",
Ang Li73697b32015-12-03 00:41:53 +000060 "test_wifi_scanner_single_scan_channel_sanity",
61 "test_wifi_scanner_with_wifi_off",
62 "test_single_scan_report_each_scan_for_channels_with_enumerated_params",
63 "test_single_scan_report_each_scan_for_band_with_enumerated_params",
Ang Li73697b32015-12-03 00:41:53 +000064 "test_single_scan_report_full_scan_for_channels_with_enumerated_params",
65 "test_single_scan_report_full_scan_for_band_with_enumerated_params",
Ang Li73697b32015-12-03 00:41:53 +000066 "test_single_scan_while_pno",
Ang Li73697b32015-12-03 00:41:53 +000067 "test_wifi_scanner_single_scan_in_isolated",
xshuaabcfeb2018-02-14 11:43:24 -080068 "test_wifi_scanner_with_invalid_numBssidsPerScan",
69 "test_wifi_scanner_dual_radio_low_latency",
70 "test_wifi_scanner_dual_radio_low_power",
71 "test_wifi_scanner_dual_radio_high_accuracy")
Ang Li73697b32015-12-03 00:41:53 +000072
73 def setup_class(self):
74 self.dut = self.android_devices[0]
Ang Li2d3fe982016-06-08 10:00:43 -070075 wutils.wifi_test_device_init(self.dut)
xshuaabcfeb2018-02-14 11:43:24 -080076 req_params = ("run_extended_test", "ping_addr", "max_bugreports", "dbs_supported_models")
Bindu Mahadevd34835d2017-06-12 17:21:09 -070077 opt_param = ["reference_networks"]
78 self.unpack_userparams(
79 req_param_names=req_params, opt_param_names=opt_param)
80
81 if "AccessPoint" in self.user_params:
lutina8b7333c2019-06-05 20:13:21 +080082 self.legacy_configure_ap_and_start(ap_count=2, mirror_ap=False)
Bindu Mahadevd34835d2017-06-12 17:21:09 -070083
Ang Li2d3fe982016-06-08 10:00:43 -070084 self.leeway = 10
85 self.stime_channel = SCAN_TIME_PASSIVE
86 self.default_scan_setting = {
87 "band": wutils.WifiEnums.WIFI_BAND_BOTH,
88 "periodInMs": SCANTIME,
89 "reportEvents": wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN
90 }
91 self.default_batch_scan_setting = {
92 "band": wutils.WifiEnums.WIFI_BAND_BOTH,
93 "periodInMs": SCANTIME,
94 "reportEvents": wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL
95 }
Ang Li73697b32015-12-03 00:41:53 +000096 self.log.debug("Run extended test: {}".format(self.run_extended_test))
Ang Li2d3fe982016-06-08 10:00:43 -070097 self.wifi_chs = wutils.WifiChannelUS(self.dut.model)
Ang Lic2d45212016-03-10 18:38:53 -080098 asserts.assert_true(self.dut.droid.wifiIsScannerSupported(),
Ang Li2d3fe982016-06-08 10:00:43 -070099 "Device %s doesn't support WifiScanner, abort." %
100 self.dut.model)
101 self.attenuators = wutils.group_attenuators(self.attenuators)
Ang Li73697b32015-12-03 00:41:53 +0000102 self.attenuators[0].set_atten(0)
103 self.attenuators[1].set_atten(0)
Ang Li73697b32015-12-03 00:41:53 +0000104
105 def teardown_test(self):
Ang Li2d3fe982016-06-08 10:00:43 -0700106 base_test.BaseTestClass.teardown_test(self)
Ang Li73697b32015-12-03 00:41:53 +0000107 self.log.debug("Shut down all wifi scanner activities.")
Ang Lia9d188f2016-02-17 18:03:01 -0800108 self.dut.droid.wifiScannerShutdown()
Ang Li73697b32015-12-03 00:41:53 +0000109
110 def on_fail(self, test_name, begin_time):
111 if self.max_bugreports > 0:
Ang Li20377aa2016-02-26 13:19:51 -0800112 self.dut.take_bug_report(test_name, begin_time)
Ang Li73697b32015-12-03 00:41:53 +0000113 self.max_bugreports -= 1
Ang Li20377aa2016-02-26 13:19:51 -0800114 self.dut.cat_adb_log(test_name, begin_time)
Ang Li73697b32015-12-03 00:41:53 +0000115
Bindu Mahadevccfe0cc2017-08-28 21:08:30 -0700116 def teardown_class(self):
117 if "AccessPoint" in self.user_params:
118 del self.user_params["reference_networks"]
119 del self.user_params["open_network"]
120
Ang Li73697b32015-12-03 00:41:53 +0000121 """ Helper Functions Begin """
122
Ang Li2d3fe982016-06-08 10:00:43 -0700123 def wifi_generate_scanner_scan_settings(self, extended, scan_type,
124 report_result):
Ang Li73697b32015-12-03 00:41:53 +0000125 """Generates all the combinations of different scan setting parameters.
126
127 Args:
128 extended: True for extended setting
129 scan_type: key for type of scan
130 report_result: event type of report scan results
131
132 Returns:
133 A list of dictionaries each representing a set of scan settings.
134 """
Ang Li2d3fe982016-06-08 10:00:43 -0700135 base_scan_time = [SCANTIME * 2]
Ang Li73697b32015-12-03 00:41:53 +0000136 if scan_type == "band":
Ang Li2d3fe982016-06-08 10:00:43 -0700137 scan_types_setting = [wutils.WifiEnums.WIFI_BAND_BOTH]
Ang Li73697b32015-12-03 00:41:53 +0000138 else:
139 scan_types_setting = [self.wifi_chs.MIX_CHANNEL_SCAN]
Ang Li2d3fe982016-06-08 10:00:43 -0700140 num_of_bssid = [NUMBSSIDPERSCAN * 4]
Ang Li73697b32015-12-03 00:41:53 +0000141 max_scan_cache = [0]
142 if extended:
143 base_scan_time.append(SCANTIME)
144 if scan_type == "band":
Ang Li2d3fe982016-06-08 10:00:43 -0700145 scan_types_setting.extend(
146 [wutils.WifiEnums.WIFI_BAND_24_GHZ,
147 wutils.WifiEnums.WIFI_BAND_5_GHZ_WITH_DFS,
148 wutils.WifiEnums.WIFI_BAND_BOTH_WITH_DFS])
Ang Li73697b32015-12-03 00:41:53 +0000149 else:
Ang Li2d3fe982016-06-08 10:00:43 -0700150 scan_types_setting.extend(
151 [self.wifi_chs.NONE_DFS_5G_FREQUENCIES, self.wifi_chs.
152 ALL_2G_FREQUENCIES, self.wifi_chs.DFS_5G_FREQUENCIES,
153 self.wifi_chs.ALL_5G_FREQUENCIES])
154 num_of_bssid.append(NUMBSSIDPERSCAN * 3)
Ang Li73697b32015-12-03 00:41:53 +0000155 max_scan_cache.append(5)
156 # Generate all the combinations of report types and scan types
Ang Li2d3fe982016-06-08 10:00:43 -0700157 if report_result == wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT:
158 report_types = {"reportEvents": report_result}
Ang Li73697b32015-12-03 00:41:53 +0000159 setting_combinations = list(itertools.product(scan_types_setting,
160 base_scan_time))
161 # Create scan setting strings based on the combinations
162 scan_settings = []
163 for combo in setting_combinations:
164 s = dict(report_types)
165 s[scan_type] = combo[0]
166 s["periodInMs"] = combo[1]
167 scan_settings.append(s)
168 else:
Ang Li2d3fe982016-06-08 10:00:43 -0700169 report_types = {"reportEvents": report_result}
170 setting_combinations = list(
171 itertools.product(scan_types_setting, base_scan_time,
172 num_of_bssid, max_scan_cache))
Ang Li73697b32015-12-03 00:41:53 +0000173 # Create scan setting strings based on the combinations
174 scan_settings = []
175 for combo in setting_combinations:
176 s = dict(report_types)
177 s[scan_type] = combo[0]
178 s["periodInMs"] = combo[1]
179 s["numBssidsPerScan"] = combo[2]
180 s["maxScansToCache"] = combo[3]
181 scan_settings.append(s)
182 return scan_settings
183
184 def proces_and_valid_batch_scan_result(self, scan_resutls, scan_rt,
185 result_rt, scan_setting):
186 """This function process scan results and validate against settings used
187 while starting the scan.
188
189 There are two steps for the verification. First it checks that all the
190 wifi networks in results are of the correct frequencies set by scan setting
191 params. Then it checks that the delta between the batch of scan results less
192 than the time required for scanning channel set by scan setting params.
193
194 Args:
195 scan_results: scan results reported.
196 scan_rt: Elapsed real time on start scan.
197 result_rt: Elapsed ral time on results reported.
198 scan_setting: The params for the single scan.
199
200 Returns:
201 bssids: total number of bssids scan result have
202 validity: True if the all scan result are valid.
203 """
204 bssids = 0
205 validity = True
206 scan_time_mic = 0
207 scan_channels = []
Ang Li2d3fe982016-06-08 10:00:43 -0700208 scan_time, scan_channels = wutils.get_scan_time_and_channels(
209 self.wifi_chs, scan_setting, self.stime_channel)
Ang Li73697b32015-12-03 00:41:53 +0000210 scan_time_mic = scan_time * 1000
211 for i, batch in enumerate(scan_resutls, start=1):
Ang Li2d3fe982016-06-08 10:00:43 -0700212 asserts.assert_true(
213 batch["ScanResults"],
214 "At least one scan result is required to validate")
215 max_scan_interval = batch["ScanResults"][0][
216 "timestamp"] + scan_time_mic
217 self.log.debug("max_scan_interval: %s", max_scan_interval)
Ang Li73697b32015-12-03 00:41:53 +0000218 for result in batch["ScanResults"]:
lutinaf02723f2020-03-24 19:22:47 +0800219 # Though the tests are run in shield box, there are leakes
220 # from outside environment. This would ignore any such SSIDs
221 ssid = result["SSID"]
222 if not ssid.startswith("2g_") or not ssid.startswith("5g_"):
223 continue
Ang Li2d3fe982016-06-08 10:00:43 -0700224 if (result["frequency"] not in scan_channels or
225 result["timestamp"] > max_scan_interval or
226 result["timestamp"] < scan_rt * 1000 or
227 result["timestamp"] > result_rt * 1000):
228 self.log.error("Result didn't match requirement: %s",
229 result)
230 validity = False
231 self.log.info("Number of scan result in batch %s: %s", i,
232 len(batch["ScanResults"]))
Ang Li73697b32015-12-03 00:41:53 +0000233 bssids += len(batch["ScanResults"])
234 return bssids, validity
235
236 def pop_scan_result_events(self, event_name):
237 """Function to pop all the scan result events.
238
239 Args:
240 event_name: event name.
241
242 Returns:
243 results: list of scan result reported in events
244 """
245 results = []
246 try:
Ang Lia9d188f2016-02-17 18:03:01 -0800247 events = self.dut.ed.pop_all(event_name)
Ang Li73697b32015-12-03 00:41:53 +0000248 for event in events:
249 results.append(event["data"]["Results"])
Ang Li2d3fe982016-06-08 10:00:43 -0700250 except queue.Empty as error:
251 self.log.debug("Number of Full scan results %s", len(results))
Ang Li73697b32015-12-03 00:41:53 +0000252 return results
253
254 def wifi_scanner_single_scan(self, scan_setting):
255 """Common logic for an enumerated wifi scanner single scan test case.
256
257 1. Start WifiScanner single scan for scan_setting.
258 2. Wait for the scan result event, wait time depend on scan settings
259 parameter.
260 3. Verify that scan results match with scan settings parameters.
261 4. Also verify that only one scan result event trigger.
262
263 Args:
264 scan_setting: The params for the single scan.
265 """
Ang Li2d3fe982016-06-08 10:00:43 -0700266 data = wutils.start_wifi_single_scan(self.dut, scan_setting)
Ang Li73697b32015-12-03 00:41:53 +0000267 idx = data["Index"]
268 scan_rt = data["ScanElapsedRealtime"]
Ang Li2d3fe982016-06-08 10:00:43 -0700269 self.log.info(
270 "Wifi single shot scan started index: %s at real time: %s", idx,
271 scan_rt)
Ang Li73697b32015-12-03 00:41:53 +0000272 results = []
273 #generating event wait time from scan setting plus leeway
Ang Li2d3fe982016-06-08 10:00:43 -0700274 scan_time, scan_channels = wutils.get_scan_time_and_channels(
275 self.wifi_chs, scan_setting, self.stime_channel)
276 wait_time = int(scan_time / 1000) + self.leeway
Ang Li73697b32015-12-03 00:41:53 +0000277 validity = False
278 #track number of result received
279 result_received = 0
280 try:
Ang Li2d3fe982016-06-08 10:00:43 -0700281 for snumber in range(1, 3):
Ang Li73697b32015-12-03 00:41:53 +0000282 event_name = "{}{}onResults".format(EVENT_TAG, idx)
Ang Li2d3fe982016-06-08 10:00:43 -0700283 self.log.debug("Waiting for event: %s for time %s", event_name,
284 wait_time)
Ang Lia9d188f2016-02-17 18:03:01 -0800285 event = self.dut.ed.pop_event(event_name, wait_time)
Ang Li2d3fe982016-06-08 10:00:43 -0700286 self.log.debug("Event received: %s", event)
Ang Li73697b32015-12-03 00:41:53 +0000287 results = event["data"]["Results"]
288 result_received += 1
289 bssids, validity = self.proces_and_valid_batch_scan_result(
Ang Li2d3fe982016-06-08 10:00:43 -0700290 results, scan_rt, event["data"][KEY_RET], scan_setting)
291 asserts.assert_equal(
292 len(results), 1,
293 "Test fail because number of scan result %s" %
294 len(results))
Ang Lic2d45212016-03-10 18:38:53 -0800295 asserts.assert_true(bssids > 0, EMPTY_RESULT)
296 asserts.assert_true(validity, INVALID_RESULT)
Ang Li2d3fe982016-06-08 10:00:43 -0700297 self.log.info("Scan number Buckets: %s\nTotal BSSID: %s",
298 len(results), bssids)
299 except queue.Empty as error:
300 asserts.assert_true(
301 result_received >= 1,
302 "Event did not triggered for single shot {}".format(error))
Ang Li73697b32015-12-03 00:41:53 +0000303 finally:
Ang Lia9d188f2016-02-17 18:03:01 -0800304 self.dut.droid.wifiScannerStopScan(idx)
Ang Li73697b32015-12-03 00:41:53 +0000305 #For single shot number of result received and length of result should be one
Ang Li2d3fe982016-06-08 10:00:43 -0700306 asserts.assert_true(
307 result_received == 1,
308 "Test fail because received result {}".format(result_received))
Ang Li73697b32015-12-03 00:41:53 +0000309
310 def wifi_scanner_single_scan_full(self, scan_setting):
311 """Common logic for single scan test case for full scan result.
312
313 1. Start WifiScanner single scan with scan_setting for full scan result.
314 2. Wait for the scan result event, wait time depend on scan settings
315 parameter.
316 3. Pop all full scan result events occurred earlier.
317 4. Verify that full scan results match with normal scan results.
xshuaabcfeb2018-02-14 11:43:24 -0800318 5. If the scan type is included in scan_setting, verify that the
319 radioChainInfos length.
Ang Li73697b32015-12-03 00:41:53 +0000320
321 Args:
322 scan_setting: The parameters for the single scan.
323 """
Ang Lia9d188f2016-02-17 18:03:01 -0800324 self.dut.ed.clear_all_events()
Ang Li2d3fe982016-06-08 10:00:43 -0700325 data = wutils.start_wifi_single_scan(self.dut, scan_setting)
Ang Li73697b32015-12-03 00:41:53 +0000326 idx = data["Index"]
327 scan_rt = data["ScanElapsedRealtime"]
Ang Li2d3fe982016-06-08 10:00:43 -0700328 self.log.info("Wifi single shot scan started with index: %s", idx)
Ang Li73697b32015-12-03 00:41:53 +0000329 #generating event wait time from scan setting plus leeway
Ang Li2d3fe982016-06-08 10:00:43 -0700330 scan_time, scan_channels = wutils.get_scan_time_and_channels(
331 self.wifi_chs, scan_setting, self.stime_channel)
332 wait_time = int(scan_time / 1000) + self.leeway
Ang Li73697b32015-12-03 00:41:53 +0000333 results = []
334 validity = False
335 try:
Ang Li2d3fe982016-06-08 10:00:43 -0700336 event_name = "%s%sonResults" % (EVENT_TAG, idx)
337 self.log.debug("Waiting for event: %s for time %s", event_name,
338 wait_time)
Ang Lia9d188f2016-02-17 18:03:01 -0800339 event = self.dut.ed.pop_event(event_name, wait_time)
Ang Li2d3fe982016-06-08 10:00:43 -0700340 self.log.info("Event received: %s", event)
Ang Li73697b32015-12-03 00:41:53 +0000341 bssids, validity = (self.proces_and_valid_batch_scan_result(
Ang Li2d3fe982016-06-08 10:00:43 -0700342 event["data"]["Results"], scan_rt, event["data"][KEY_RET],
343 scan_setting))
Ang Lic2d45212016-03-10 18:38:53 -0800344 asserts.assert_true(bssids > 0, EMPTY_RESULT)
345 asserts.assert_true(validity, INVALID_RESULT)
Ang Li73697b32015-12-03 00:41:53 +0000346 event_name = "{}{}onFullResult".format(EVENT_TAG, idx)
347 results = self.pop_scan_result_events(event_name)
Ang Li2d3fe982016-06-08 10:00:43 -0700348 asserts.assert_true(
349 len(results) >= bssids,
350 "Full single shot result don't match {}".format(len(results)))
xshuaabcfeb2018-02-14 11:43:24 -0800351 if 'type' in scan_setting.keys():
352 for item in results:
353 self.verify_radio_chain_length(scan_setting['type'], item)
Ang Li2d3fe982016-06-08 10:00:43 -0700354 except queue.Empty as error:
355 raise AssertionError(
356 "Event did not triggered for single shot {}".format(error))
Ang Li73697b32015-12-03 00:41:53 +0000357 finally:
Ang Lia9d188f2016-02-17 18:03:01 -0800358 self.dut.droid.wifiScannerStopScan(idx)
Ang Li73697b32015-12-03 00:41:53 +0000359
xshuaabcfeb2018-02-14 11:43:24 -0800360 def verify_radio_chain_length(self, scan_setting_type, scan_result):
361 llen = len(scan_result[0]["radioChainInfos"])
362 if scan_setting_type == wutils.WifiEnums.SCAN_TYPE_LOW_LATENCY \
363 or scan_setting_type == wutils.WifiEnums.SCAN_TYPE_LOW_POWER:
364 asserts.assert_true(llen == 1,
365 "radioChainInfos len expected:{} "
366 "actual:{}".format(1, llen))
367 else:
368 asserts.assert_true(llen == 2,
369 "radioChainInfos len expected:{} "
370 "actual:{}".format(2, llen))
371
Ang Li73697b32015-12-03 00:41:53 +0000372 def wifi_scanner_batch_scan_full(self, scan_setting):
373 """Common logic for batch scan test case for full scan result.
374
375 1. Start WifiScanner batch scan with scan_setting for full scan result.
376 2. Wait for the scan result event, wait time depend on scan settings
377 parameter.
378 3. Pop all full scan result events occurred earlier.
379 4. Verify that full scan results match with scan results.
380
381 Args:
382 scan_setting: The params for the batch scan.
383 """
Ang Lia9d188f2016-02-17 18:03:01 -0800384 self.dut.ed.clear_all_events()
Ang Li2d3fe982016-06-08 10:00:43 -0700385 data = wutils.start_wifi_background_scan(self.dut, scan_setting)
Ang Li73697b32015-12-03 00:41:53 +0000386 idx = data["Index"]
387 scan_rt = data["ScanElapsedRealtime"]
Ang Li2d3fe982016-06-08 10:00:43 -0700388 self.log.info("Wifi batch shot scan started with index: %s", idx)
Ang Li73697b32015-12-03 00:41:53 +0000389 #generating event wait time from scan setting plus leeway
Ang Li2d3fe982016-06-08 10:00:43 -0700390 scan_time, scan_channels = wutils.get_scan_time_and_channels(
391 self.wifi_chs, scan_setting, self.stime_channel)
Mitchell Wills301a1962015-12-14 21:49:15 -0800392 # multiply scan period by two to account for scheduler changing period
Ang Li2d3fe982016-06-08 10:00:43 -0700393 scan_time += scan_setting[
394 'periodInMs'] * 2 #add scan period delay for next cycle
Mitchell Wills301a1962015-12-14 21:49:15 -0800395 wait_time = scan_time / 1000 + self.leeway
Ang Li73697b32015-12-03 00:41:53 +0000396 validity = False
397 try:
Ang Li2d3fe982016-06-08 10:00:43 -0700398 for snumber in range(1, 3):
Ang Li73697b32015-12-03 00:41:53 +0000399 results = []
Ang Li2d3fe982016-06-08 10:00:43 -0700400 event_name = "%s%sonResults" % (EVENT_TAG, idx)
401 self.log.debug("Waiting for event: %s for time %s", event_name,
402 wait_time)
Ang Lia9d188f2016-02-17 18:03:01 -0800403 event = self.dut.ed.pop_event(event_name, wait_time)
Ang Li2d3fe982016-06-08 10:00:43 -0700404 self.log.debug("Event received: %s", event)
Ang Li73697b32015-12-03 00:41:53 +0000405 bssids, validity = self.proces_and_valid_batch_scan_result(
Ang Li2d3fe982016-06-08 10:00:43 -0700406 event["data"]["Results"], scan_rt, event["data"][KEY_RET],
407 scan_setting)
408 event_name = "%s%sonFullResult" % (EVENT_TAG, idx)
Ang Li73697b32015-12-03 00:41:53 +0000409 results = self.pop_scan_result_events(event_name)
Ang Li2d3fe982016-06-08 10:00:43 -0700410 asserts.assert_true(
411 len(results) >= bssids,
412 "Full single shot result don't match %s" % len(results))
Ang Lic2d45212016-03-10 18:38:53 -0800413 asserts.assert_true(bssids > 0, EMPTY_RESULT)
414 asserts.assert_true(validity, INVALID_RESULT)
Ang Li2d3fe982016-06-08 10:00:43 -0700415 except queue.Empty as error:
416 raise AssertionError("Event did not triggered for batch scan %s" %
417 error)
Ang Li73697b32015-12-03 00:41:53 +0000418 finally:
Ang Lia9d188f2016-02-17 18:03:01 -0800419 self.dut.droid.wifiScannerStopBackgroundScan(idx)
420 self.dut.ed.clear_all_events()
Ang Li73697b32015-12-03 00:41:53 +0000421
422 def wifi_scanner_batch_scan(self, scan_setting):
423 """Common logic for an enumerated wifi scanner batch scan test case.
424
425 1. Start WifiScanner batch scan for given scan_setting.
426 2. Wait for the scan result event, wait time depend on scan settings
427 parameter.
428 3. Verify that scan results match with scan settings parameters.
429 4. Also verify that multiple scan result events trigger.
430
431 Args:
432 scan_setting: The parameters for the batch scan.
433 """
Ang Li2d3fe982016-06-08 10:00:43 -0700434 data = wutils.start_wifi_background_scan(self.dut, scan_setting)
Ang Li73697b32015-12-03 00:41:53 +0000435 idx = data["Index"]
436 scan_rt = data["ScanElapsedRealtime"]
Ang Li2d3fe982016-06-08 10:00:43 -0700437 self.log.info(
438 "Wifi background scan started with index: %s real time %s", idx,
439 scan_rt)
440 scan_time, scan_channels = wutils.get_scan_time_and_channels(
441 self.wifi_chs, scan_setting, self.stime_channel)
Ang Li73697b32015-12-03 00:41:53 +0000442 #generating event wait time from scan setting plus leeway
443 time_cache = 0
Ang Li2d3fe982016-06-08 10:00:43 -0700444 number_bucket = 1 #bucket for Report result on each scan
Ang Li73697b32015-12-03 00:41:53 +0000445 check_get_result = False
Ang Li2d3fe982016-06-08 10:00:43 -0700446 if scan_setting[
447 'reportEvents'] == wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL:
Ang Li73697b32015-12-03 00:41:53 +0000448 check_get_result = True
449 if ('maxScansToCache' in scan_setting and
Ang Li2d3fe982016-06-08 10:00:43 -0700450 scan_setting['maxScansToCache'] != 0):
Ang Li73697b32015-12-03 00:41:53 +0000451 time_cache = (scan_setting['maxScansToCache'] *
452 scan_setting['periodInMs'])
453 number_bucket = scan_setting['maxScansToCache']
454 else:
Ang Li2d3fe982016-06-08 10:00:43 -0700455 time_cache = 10 * scan_setting['periodInMs'
456 ] #10 as default max scan cache
Ang Li73697b32015-12-03 00:41:53 +0000457 number_bucket = 10
458 else:
Ang Li2d3fe982016-06-08 10:00:43 -0700459 time_cache = scan_setting[
460 'periodInMs'
461 ] #need while waiting for seconds resutls
Mitchell Wills78aaeca2015-12-07 18:03:00 -0800462 # multiply cache time by two to account for scheduler changing period
463 wait_time = (time_cache * 2 + scan_time) / 1000 + self.leeway
Ang Li73697b32015-12-03 00:41:53 +0000464 validity = False
465 try:
Ang Li2d3fe982016-06-08 10:00:43 -0700466 for snumber in range(1, 3):
467 event_name = "%s%sonResults" % (EVENT_TAG, idx)
468 self.log.info("Waiting for event: %s for time %s", event_name,
469 wait_time)
Ang Lia9d188f2016-02-17 18:03:01 -0800470 event = self.dut.ed.pop_event(event_name, wait_time)
Ang Li2d3fe982016-06-08 10:00:43 -0700471 self.log.debug("Event received: %s", event)
Ang Li73697b32015-12-03 00:41:53 +0000472 results = event["data"]["Results"]
473 bssids, validity = (self.proces_and_valid_batch_scan_result(
Ang Li2d3fe982016-06-08 10:00:43 -0700474 results, scan_rt, event["data"][KEY_RET], scan_setting))
475 self.log.info("Scan number: %s\n Buckets: %s\n BSSID: %s",
476 snumber, len(results), bssids)
477 asserts.assert_equal(
478 len(results), number_bucket,
479 "Test fail because number_bucket %s" % len(results))
Ang Lic2d45212016-03-10 18:38:53 -0800480 asserts.assert_true(bssids >= 1, EMPTY_RESULT)
481 asserts.assert_true(validity, INVALID_RESULT)
Ang Li2d3fe982016-06-08 10:00:43 -0700482 if snumber % 2 == 1 and check_get_result:
Ang Li73697b32015-12-03 00:41:53 +0000483 self.log.info("Get Scan result using GetScanResult API")
Ang Li2d3fe982016-06-08 10:00:43 -0700484 time.sleep(wait_time / number_bucket)
Ang Lia9d188f2016-02-17 18:03:01 -0800485 if self.dut.droid.wifiScannerGetScanResults():
486 event = self.dut.ed.pop_event(event_name, 1)
Ang Li2d3fe982016-06-08 10:00:43 -0700487 self.log.debug("Event onResults: %s", event)
Ang Li73697b32015-12-03 00:41:53 +0000488 results = event["data"]["Results"]
Ang Li2d3fe982016-06-08 10:00:43 -0700489 bssids, validity = self.proces_and_valid_batch_scan_result(
490 results, scan_rt, event["data"][KEY_RET],
491 scan_setting)
492 self.log.info("Got Scan result number: %s BSSID: %s",
493 snumber, bssids)
Ang Lic2d45212016-03-10 18:38:53 -0800494 asserts.assert_true(bssids >= 1, EMPTY_RESULT)
495 asserts.assert_true(validity, INVALID_RESULT)
Ang Li73697b32015-12-03 00:41:53 +0000496 else:
497 self.log.error("Error while fetching the scan result")
Ang Li2d3fe982016-06-08 10:00:43 -0700498 except queue.Empty as error:
499 raise AssertionError("Event did not triggered for batch scan %s" %
500 error)
Ang Li73697b32015-12-03 00:41:53 +0000501 finally:
Ang Lia9d188f2016-02-17 18:03:01 -0800502 self.dut.droid.wifiScannerStopBackgroundScan(idx)
503 self.dut.ed.clear_all_events()
Ang Li73697b32015-12-03 00:41:53 +0000504
505 def start_wifi_scanner_single_scan_expect_failure(self, scan_setting):
506 """Common logic to test wif scanner single scan with invalid settings
507 or environment
508
509 1. Start WifiScanner batch scan for setting parameters.
510 2. Verify that scan is not started.
511
512 Args:
513 scan_setting: The params for the single scan.
514 """
515 try:
Ang Lia9d188f2016-02-17 18:03:01 -0800516 idx = self.dut.droid.wifiScannerStartScan(scan_setting)
Ang Li2d3fe982016-06-08 10:00:43 -0700517 event = self.dut.ed.pop_event(
518 "{}{}onFailure".format(EVENT_TAG, idx), SHORT_TIMEOUT)
519 except queue.Empty as error:
520 raise AssertionError("Did not get expected onFailure {}".format(
521 error))
Ang Li73697b32015-12-03 00:41:53 +0000522
523 def start_wifi_scanner_background_scan_expect_failure(self, scan_setting):
524 """Common logic to test wif scanner batch scan with invalid settings
525 or environment
526
527 1. Start WifiScanner batch scan for setting parameters.
528 2. Verify that scan is not started.
529
530 Args:
531 scan_setting: The params for the single scan.
532 """
533 try:
Ang Li2d3fe982016-06-08 10:00:43 -0700534 idx = self.dut.droid.wifiScannerStartBackgroundScan(scan_setting)
535 event = self.dut.ed.pop_event(
536 "{}{}onFailure".format(EVENT_TAG, idx), SHORT_TIMEOUT)
537 except queue.Empty as error:
538 raise AssertionError("Did not get expected onFailure {}".format(
539 error))
Ang Li73697b32015-12-03 00:41:53 +0000540
541 def check_get_available_channels_with_one_band(self, band):
542 """Common logic to check available channels for a band.
543
544 1. Get available channels for band.
545 2. Verify that channels match with supported channels for band.
546
547 Args:
548 band: wifi band."""
549
Ang Lia9d188f2016-02-17 18:03:01 -0800550 r = self.dut.droid.wifiScannerGetAvailableChannels(band)
Ang Li73697b32015-12-03 00:41:53 +0000551 self.log.debug(band)
552 self.log.debug(r)
553 expected = self.wifi_chs.band_to_freq(band)
Ang Li2d3fe982016-06-08 10:00:43 -0700554 asserts.assert_equal(set(r), set(expected), "Band %s failed." % band)
Ang Li73697b32015-12-03 00:41:53 +0000555
556 def connect_to_reference_network(self):
557 """Connect to reference network and make sure that connection happen"""
Ang Lia9d188f2016-02-17 18:03:01 -0800558 self.dut.droid.wakeLockAcquireBright()
559 self.dut.droid.wakeUpNow()
Ang Li73697b32015-12-03 00:41:53 +0000560 try:
Bindu Mahadev06fb2e12017-06-06 15:45:34 -0700561 self.dut.droid.wifiConnectByConfig(self.reference_networks[0]["2g"])
Ang Li2d3fe982016-06-08 10:00:43 -0700562 connect_result = self.dut.ed.pop_event(
Bindu Mahadev04ce7b72016-12-13 12:14:36 -0800563 wifi_constants.CONNECT_BY_CONFIG_SUCCESS, SHORT_TIMEOUT)
Ang Li73697b32015-12-03 00:41:53 +0000564 self.log.info(connect_result)
Ang Li2d3fe982016-06-08 10:00:43 -0700565 return wutils.track_connection(self.dut,
Bindu Mahadev06fb2e12017-06-06 15:45:34 -0700566 self.reference_networks[0]["2g"]["SSID"], 1)
Ang Li73697b32015-12-03 00:41:53 +0000567 except Exception as error:
568 self.log.exception(traceback.format_exc())
Ang Li2d3fe982016-06-08 10:00:43 -0700569 self.log.error("Connection to network fail because %s", error)
Ang Li73697b32015-12-03 00:41:53 +0000570 return False
571 finally:
Ang Lia9d188f2016-02-17 18:03:01 -0800572 self.dut.droid.wifiLockRelease()
573 self.dut.droid.goToSleepNow()
Ang Li73697b32015-12-03 00:41:53 +0000574
575 """ Helper Functions End """
Ang Li73697b32015-12-03 00:41:53 +0000576 """ Tests Begin """
Ang Li2d3fe982016-06-08 10:00:43 -0700577
Girish Moturucb5d2522017-08-01 15:55:18 +0530578 # Test channels
579 """ Test available channels for different bands.
Ang Li73697b32015-12-03 00:41:53 +0000580
Girish Moturucb5d2522017-08-01 15:55:18 +0530581 1. Get available channels for different bands.
582 2. Verify that channels match with supported channels for respective band.
583 """
584 @test_tracker_info(uuid="7cca8142-529f-4951-ab6f-cd03b359b3cc")
585 def test_available_channels_band_1(self):
586 self.check_get_available_channels_with_one_band(1)
587
588 @test_tracker_info(uuid="612afda1-0d74-4d2f-bc37-72ef2b98310a")
589 def test_available_channels_band_2(self):
590 self.check_get_available_channels_with_one_band(2)
591
592 @test_tracker_info(uuid="a9275bb9-afa7-4dd4-b2e0-60296ffd33bb")
593 def test_available_channels_band_3(self):
594 self.check_get_available_channels_with_one_band(3)
595
596 @test_tracker_info(uuid="5413632e-ce72-4ecc-bf9b-33ac9e4bf3fc")
597 def test_available_channels_band_4(self):
598 self.check_get_available_channels_with_one_band(4)
599
600 @test_tracker_info(uuid="a8f40b4f-d79d-4d2f-bed8-3b139a082f6c")
601 def test_available_channels_band_6(self):
602 self.check_get_available_channels_with_one_band(6)
603
604 @test_tracker_info(uuid="84cdfc25-8e64-42c7-b7f9-0a04e45d78b6")
605 def test_available_channels_band_7(self):
606 self.check_get_available_channels_with_one_band(7)
Ang Li73697b32015-12-03 00:41:53 +0000607
Girish Moturu5a509a32017-04-03 10:50:18 +0530608 @test_tracker_info(uuid="95069244-b76c-4834-b3a6-96b0d8da98d8")
Ang Li2d3fe982016-06-08 10:00:43 -0700609 def test_single_scan_report_each_scan_for_channels_with_enumerated_params(
610 self):
Ang Li73697b32015-12-03 00:41:53 +0000611 """Test WiFi scanner single scan for channels with enumerated settings.
612
613 1. Start WifiScanner single scan for different channels with enumerated
614 scan settings.
615 2. Verify that scan results match with respective scan settings.
616 """
617 scan_settings = self.wifi_generate_scanner_scan_settings(
Ang Li2d3fe982016-06-08 10:00:43 -0700618 self.run_extended_test, "channels",
619 wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN)
620 self.log.debug("Scan settings: %s\n%s", len(scan_settings),
621 scan_settings)
Girish Moturucb5d2522017-08-01 15:55:18 +0530622 self.wifi_scanner_single_scan(scan_settings[0])
Ang Li73697b32015-12-03 00:41:53 +0000623
Girish Moturu5a509a32017-04-03 10:50:18 +0530624 @test_tracker_info(uuid="5595ebe5-6d91-4379-a606-be59967e5ec9")
Ang Li2d3fe982016-06-08 10:00:43 -0700625 def test_single_scan_report_each_scan_for_band_with_enumerated_params(
626 self):
Ang Li73697b32015-12-03 00:41:53 +0000627 """Test WiFi scanner single scan for bands with enumerated settings.
628
629 1. Start WifiScanner single scan for different bands with enumerated
630 scan settings.
631 2. Verify that scan results match with respective scan settings.
632 """
633 scan_settings = self.wifi_generate_scanner_scan_settings(
Ang Li2d3fe982016-06-08 10:00:43 -0700634 self.run_extended_test, "band",
635 wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN)
636 self.log.debug("Scan settings:%s\n%s", len(scan_settings),
637 scan_settings)
Girish Moturucb5d2522017-08-01 15:55:18 +0530638 self.wifi_scanner_single_scan(scan_settings[0])
Ang Li73697b32015-12-03 00:41:53 +0000639
Girish Moturu00304f82017-04-13 09:28:37 +0530640 @test_tracker_info(uuid="44989f93-e63b-4c2e-a90a-a483477303bb")
Ang Li2d3fe982016-06-08 10:00:43 -0700641 def test_batch_scan_report_buffer_full_for_channels_with_enumerated_params(
642 self):
Ang Li73697b32015-12-03 00:41:53 +0000643 """Test WiFi scanner batch scan using channels with enumerated settings
644 to report buffer full scan results.
645
646 1. Start WifiScanner batch scan using different channels with enumerated
647 scan settings to report buffer full scan results.
648 2. Verify that scan results match with respective scan settings.
649 """
650 scan_settings = self.wifi_generate_scanner_scan_settings(
Ang Li2d3fe982016-06-08 10:00:43 -0700651 self.run_extended_test, "channels",
652 wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL)
653 self.log.debug("Scan settings:%s\n%s", len(scan_settings),
654 scan_settings)
Girish Moturucb5d2522017-08-01 15:55:18 +0530655 self.wifi_scanner_batch_scan(scan_settings[0])
Ang Li73697b32015-12-03 00:41:53 +0000656
Girish Moturu00304f82017-04-13 09:28:37 +0530657 @test_tracker_info(uuid="63538df6-388a-4c16-964f-e9c19b750e07")
Ang Li2d3fe982016-06-08 10:00:43 -0700658 def test_batch_scan_report_buffer_full_for_band_with_enumerated_params(
659 self):
Ang Li73697b32015-12-03 00:41:53 +0000660 """Test WiFi scanner batch scan using band with enumerated settings
661 to report buffer full scan results.
662
663 1. Start WifiScanner batch scan using different bands with enumerated
664 scan settings to report buffer full scan results.
665 2. Verify that scan results match with respective scan settings.
666 """
667 scan_settings = self.wifi_generate_scanner_scan_settings(
Ang Li2d3fe982016-06-08 10:00:43 -0700668 self.run_extended_test, "band",
669 wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL)
670 self.log.debug("Scan settings:{}\n{}".format(
671 len(scan_settings), scan_settings))
Girish Moturucb5d2522017-08-01 15:55:18 +0530672 self.wifi_scanner_batch_scan(scan_settings[0])
Ang Li73697b32015-12-03 00:41:53 +0000673
Girish Moturu00304f82017-04-13 09:28:37 +0530674 @test_tracker_info(uuid="bd4e8c53-16c8-4ed6-b680-55c1ba688ad8")
Ang Li2d3fe982016-06-08 10:00:43 -0700675 def test_batch_scan_report_each_scan_for_channels_with_enumerated_params(
676 self):
Ang Li73697b32015-12-03 00:41:53 +0000677 """Test WiFi scanner batch scan using channels with enumerated settings
678 to report each scan results.
679
680 1. Start WifiScanner batch scan using different channels with enumerated
681 scan settings to report each scan results.
682 2. Verify that scan results match with respective scan settings.
683 """
684 scan_settings = self.wifi_generate_scanner_scan_settings(
Ang Li2d3fe982016-06-08 10:00:43 -0700685 self.run_extended_test, "channels",
686 wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN)
687 self.log.debug("Scan settings:{}\n{}".format(
688 len(scan_settings), scan_settings))
Girish Moturucb5d2522017-08-01 15:55:18 +0530689 self.wifi_scanner_batch_scan(scan_settings[0])
Ang Li73697b32015-12-03 00:41:53 +0000690
Girish Moturu00304f82017-04-13 09:28:37 +0530691 @test_tracker_info(uuid="d11e8c09-97d0-49c1-bf09-b9ec672c2fa6")
Ang Li73697b32015-12-03 00:41:53 +0000692 def test_batch_scan_report_each_scan_for_band_with_enumerated_params(self):
693 """Test WiFi scanner batch scan using band with enumerated settings
694 to report each scan results.
695
696 1. Start WifiScanner batch scan using different bands with enumerated
697 scan settings to report each scan results.
698 2. Verify that scan results match with respective scan settings.
699 """
700 scan_settings = self.wifi_generate_scanner_scan_settings(
Ang Li2d3fe982016-06-08 10:00:43 -0700701 self.run_extended_test, "band",
702 wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN)
703 self.log.debug("Scan settings:{}\n{}".format(
704 len(scan_settings), scan_settings))
Girish Moturucb5d2522017-08-01 15:55:18 +0530705 self.wifi_scanner_batch_scan(scan_settings[0])
Ang Li73697b32015-12-03 00:41:53 +0000706
Girish Moturu00304f82017-04-13 09:28:37 +0530707 @test_tracker_info(uuid="7f967b0e-82fe-403e-9d74-0dee7f09a21d")
Ang Li2d3fe982016-06-08 10:00:43 -0700708 def test_single_scan_report_full_scan_for_channels_with_enumerated_params(
709 self):
Ang Li73697b32015-12-03 00:41:53 +0000710 """Test WiFi scanner single scan using channels with enumerated settings
711 to report full scan results.
712
713 1. Start WifiScanner single scan using different channels with enumerated
714 scan settings to report full scan results.
715 2. Verify that scan results match with respective scan settings.
716 """
717 scan_settings = self.wifi_generate_scanner_scan_settings(
Ang Li2d3fe982016-06-08 10:00:43 -0700718 self.run_extended_test, "channels",
719 wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT)
720 self.log.debug("Full Scan settings:{}\n{}".format(
721 len(scan_settings), scan_settings))
Girish Moturucb5d2522017-08-01 15:55:18 +0530722 self.wifi_scanner_single_scan_full(scan_settings[0])
Ang Li73697b32015-12-03 00:41:53 +0000723
Girish Moturu00304f82017-04-13 09:28:37 +0530724 @test_tracker_info(uuid="34d09f60-31bf-4952-8fb3-03fc93ec98fa")
Ang Li2d3fe982016-06-08 10:00:43 -0700725 def test_single_scan_report_full_scan_for_band_with_enumerated_params(
726 self):
Ang Li73697b32015-12-03 00:41:53 +0000727 """Test WiFi scanner single scan using band with enumerated settings
728 to report full scan results.
729
730 1. Start WifiScanner single scan using different bands with enumerated
731 scan settings to report full scan results.
732 2. Verify that scan results match with respective scan settings.
733 """
734 scan_settings = self.wifi_generate_scanner_scan_settings(
Ang Li2d3fe982016-06-08 10:00:43 -0700735 self.run_extended_test, "band",
736 wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT)
737 self.log.debug("Full Scan settings:{}\n{}".format(
738 len(scan_settings), scan_settings))
Girish Moturucb5d2522017-08-01 15:55:18 +0530739 self.wifi_scanner_single_scan_full(scan_settings[0])
Ang Li73697b32015-12-03 00:41:53 +0000740
Girish Moturu00304f82017-04-13 09:28:37 +0530741 @test_tracker_info(uuid="0ddccf2e-b518-45a7-ae75-96924070b841")
Ang Li2d3fe982016-06-08 10:00:43 -0700742 def test_batch_scan_report_full_scan_for_channels_with_enumerated_params(
743 self):
Ang Li73697b32015-12-03 00:41:53 +0000744 """Test WiFi scanner batch scan using channels with enumerated settings
745 to report full scan results.
746
747 1. Start WifiScanner batch scan using different channels with enumerated
748 scan settings to report full scan results.
749 2. Verify that scan results match with respective scan settings.
750 """
751 scan_settings = self.wifi_generate_scanner_scan_settings(
Ang Li2d3fe982016-06-08 10:00:43 -0700752 self.run_extended_test, "channels",
753 wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT)
754 self.log.debug("Full Scan settings:{}\n{}".format(
755 len(scan_settings), scan_settings))
Girish Moturucb5d2522017-08-01 15:55:18 +0530756 self.wifi_scanner_batch_scan_full(scan_settings[0])
Ang Li73697b32015-12-03 00:41:53 +0000757
Girish Moturu00304f82017-04-13 09:28:37 +0530758 @test_tracker_info(uuid="0685b667-8470-43a0-923d-dee71428f8ce")
Ang Li73697b32015-12-03 00:41:53 +0000759 def test_batch_scan_report_full_scan_for_band_with_enumerated_params(self):
760 """Test WiFi scanner batch scan using channels with enumerated settings
761 to report full scan results.
762
763 1. Start WifiScanner batch scan using different channels with enumerated
764 scan settings to report full scan results.
765 2. Verify that scan results match with respective scan settings.
766 """
767 scan_settings = self.wifi_generate_scanner_scan_settings(
Ang Li2d3fe982016-06-08 10:00:43 -0700768 self.run_extended_test, "band",
769 wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT)
770 self.log.debug("Full Scan settings:{}\n{}".format(
771 len(scan_settings), scan_settings))
Girish Moturucb5d2522017-08-01 15:55:18 +0530772 self.wifi_scanner_batch_scan_full(scan_settings[0])
Ang Li73697b32015-12-03 00:41:53 +0000773
Girish Moturu00304f82017-04-13 09:28:37 +0530774 @test_tracker_info(uuid="e9a7cfb5-21c4-4c40-8169-8d88b65a1dee")
lutinaf02723f2020-03-24 19:22:47 +0800775 @WifiBaseTest.wifi_test_wrap
Ang Li73697b32015-12-03 00:41:53 +0000776 def test_single_scan_while_pno(self):
777 """Test wifi scanner single scan parallel to PNO connection.
778
779 1. Check device have a saved network.
780 2. Trigger PNO by attenuate the signal to move out of range.
781 3. Start WifiScanner single scan for both band with default scan settings.
782 4. Verify that scanner report single scan results.
783 5. Attenuate the signal to move in range.
784 6. Verify connection occurred through PNO.
785 """
786 self.log.info("Check connection through PNO for reference network")
Girish Moturu147063d2019-08-18 11:46:55 -0700787 self.attenuators[ATTENUATOR].set_atten(0)
788 asserts.assert_true(self.connect_to_reference_network(), NETWORK_ERROR)
789 time.sleep(10) #wait for connection to be active
790 asserts.assert_true(
791 wutils.validate_connection(self.dut, self.ping_addr),
792 "Error, No internet connection for current network")
793
Ang Lia9d188f2016-02-17 18:03:01 -0800794 current_network = self.dut.droid.wifiGetConnectionInfo()
Ang Li73697b32015-12-03 00:41:53 +0000795 self.log.info("Current network: {}".format(current_network))
Ang Lic2d45212016-03-10 18:38:53 -0800796 asserts.assert_true('network_id' in current_network, NETWORK_ID_ERROR)
797 asserts.assert_true(current_network['network_id'] >= 0, NETWORK_ERROR)
Ang Li73697b32015-12-03 00:41:53 +0000798 self.log.info("Kicking PNO for reference network")
Bindu Mahadev06fb2e12017-06-06 15:45:34 -0700799 self.attenuators[ATTENUATOR].set_atten(90)
Ang Li2d3fe982016-06-08 10:00:43 -0700800 time.sleep(10) #wait for PNO to be kicked
Ang Li73697b32015-12-03 00:41:53 +0000801 self.log.info("Starting single scan while PNO")
802 self.wifi_scanner_single_scan(self.default_scan_setting)
Bindu Mahadev06fb2e12017-06-06 15:45:34 -0700803 self.attenuators[ATTENUATOR].set_atten(0)
Ang Li73697b32015-12-03 00:41:53 +0000804 self.log.info("Check connection through PNO for reference network")
lutina8b7333c2019-06-05 20:13:21 +0800805 time.sleep(60) #wait for connection through PNO
Ang Lia9d188f2016-02-17 18:03:01 -0800806 current_network = self.dut.droid.wifiGetConnectionInfo()
Ang Li73697b32015-12-03 00:41:53 +0000807 self.log.info("Current network: {}".format(current_network))
Ang Lic2d45212016-03-10 18:38:53 -0800808 asserts.assert_true('network_id' in current_network, NETWORK_ID_ERROR)
809 asserts.assert_true(current_network['network_id'] >= 0, NETWORK_ERROR)
Ang Li2d3fe982016-06-08 10:00:43 -0700810 time.sleep(10) #wait for IP to be assigned
811 asserts.assert_true(
Bindu Mahadev50374df2017-01-04 11:03:32 -0800812 wutils.validate_connection(self.dut, self.ping_addr),
Ang Li2d3fe982016-06-08 10:00:43 -0700813 "Error, No internet connection for current network")
Bindu Mahadev06fb2e12017-06-06 15:45:34 -0700814 wutils.wifi_forget_network(self.dut,
815 self.reference_networks[0]["2g"]["SSID"])
Ang Li73697b32015-12-03 00:41:53 +0000816
Girish Moturu00304f82017-04-13 09:28:37 +0530817 @test_tracker_info(uuid="fc18d947-0b5a-42b4-98f3-dd1f2b52a7af")
Ang Li73697b32015-12-03 00:41:53 +0000818 def test_wifi_connection_and_pno_while_batch_scan(self):
819 """Test configuring a connection and PNO connection parallel to wifi
820 scanner batch scan.
821
822 1. Start WifiScanner batch scan with default batch scan settings.
823 2. Wait for scan result event for a time depend on scan settings.
824 3. Verify reported batch scan results.
825 4. Configure a connection to reference network.
826 5. Verify that connection to reference network occurred.
827 6. Wait for scan result event for a time depend on scan settings.
828 7. Verify reported batch scan results.
829 8. Trigger PNO by attenuate the signal to move out of range.
830 9. Wait for scan result event for a time depend on scan settings.
831 10. Verify reported batch scan results.
832 11. Attenuate the signal to move in range.
833 12. Verify connection occurred through PNO.
834 """
Bindu Mahadev06fb2e12017-06-06 15:45:34 -0700835 self.attenuators[ATTENUATOR].set_atten(0)
Ang Li2d3fe982016-06-08 10:00:43 -0700836 data = wutils.start_wifi_background_scan(
837 self.dut, self.default_batch_scan_setting)
Ang Li73697b32015-12-03 00:41:53 +0000838 idx = data["Index"]
839 scan_rt = data["ScanElapsedRealtime"]
Ang Li2d3fe982016-06-08 10:00:43 -0700840 self.log.info(
841 "Wifi background scan started with index: {} rt {}".format(
842 idx, scan_rt))
Ang Li73697b32015-12-03 00:41:53 +0000843 #generating event wait time from scan setting plus leeway
Ang Li2d3fe982016-06-08 10:00:43 -0700844 scan_time, scan_channels = wutils.get_scan_time_and_channels(
845 self.wifi_chs, self.default_batch_scan_setting, self.stime_channel)
Ang Li73697b32015-12-03 00:41:53 +0000846 #default number buckets
847 number_bucket = 10
Ang Li2d3fe982016-06-08 10:00:43 -0700848 time_cache = self.default_batch_scan_setting[
849 'periodInMs'] * number_bucket #default cache
Ang Li73697b32015-12-03 00:41:53 +0000850 #add 2 seconds extra time for switch between the channel for connection scan
Mitchell Wills78aaeca2015-12-07 18:03:00 -0800851 #multiply cache time by two to account for scheduler changing period
852 wait_time = (time_cache * 2 + scan_time) / 1000 + self.leeway + 2
Ang Li73697b32015-12-03 00:41:53 +0000853 result_flag = 0
854 try:
Ang Li2d3fe982016-06-08 10:00:43 -0700855 for snumber in range(1, 7):
856 event_name = "{}{}onResults".format(EVENT_TAG, idx)
857 self.log.info("Waiting for event: {}".format(event_name))
858 event = self.dut.ed.pop_event(event_name, wait_time)
859 self.log.debug("Event onResults: {}".format(event))
860 results = event["data"]["Results"]
861 bssids, validity = self.proces_and_valid_batch_scan_result(
862 results, scan_rt, event["data"][KEY_RET],
863 self.default_batch_scan_setting)
864 self.log.info(
865 "Scan number: {}\n Buckets: {}\n BSSID: {}".format(
866 snumber, len(results), bssids))
867 asserts.assert_true(bssids >= 1,
868 "Not able to fetch scan result")
869 if snumber == 1:
870 self.log.info(
871 "Try to connect AP while waiting for event: {}".format(
872 event_name))
873 asserts.assert_true(self.connect_to_reference_network(),
874 NETWORK_ERROR)
875 time.sleep(10) #wait for connection to be active
876 asserts.assert_true(
Bindu Mahadev50374df2017-01-04 11:03:32 -0800877 wutils.validate_connection(self.dut, self.ping_addr),
Ang Li2d3fe982016-06-08 10:00:43 -0700878 "Error, No internet connection for current network")
879 elif snumber == 3:
880 self.log.info("Kicking PNO for reference network")
Bindu Mahadev06fb2e12017-06-06 15:45:34 -0700881 self.attenuators[ATTENUATOR].set_atten(90)
Ang Li2d3fe982016-06-08 10:00:43 -0700882 elif snumber == 4:
883 self.log.info("Bring back device for PNO connection")
884 current_network = self.dut.droid.wifiGetConnectionInfo()
885 self.log.info("Current network: {}".format(
886 current_network))
887 asserts.assert_true('network_id' in current_network,
888 NETWORK_ID_ERROR)
889 asserts.assert_true(
890 current_network['network_id'] == -1,
891 "Device is still connected to network {}".format(
892 current_network[wutils.WifiEnums.SSID_KEY]))
Bindu Mahadev06fb2e12017-06-06 15:45:34 -0700893 self.attenuators[ATTENUATOR].set_atten(0)
Ang Li2d3fe982016-06-08 10:00:43 -0700894 time.sleep(
895 10
896 ) #wait for connection to take place before waiting for scan result
897 elif snumber == 6:
898 self.log.info(
899 "Check connection through PNO for reference network")
900 current_network = self.dut.droid.wifiGetConnectionInfo()
901 self.log.info("Current network: {}".format(
902 current_network))
903 asserts.assert_true('network_id' in current_network,
904 NETWORK_ID_ERROR)
905 asserts.assert_true(current_network['network_id'] >= 0,
906 NETWORK_ERROR)
907 time.sleep(10) #wait for connection to be active
908 asserts.assert_true(
Bindu Mahadev50374df2017-01-04 11:03:32 -0800909 wutils.validate_connection(self.dut, self.ping_addr),
Ang Li2d3fe982016-06-08 10:00:43 -0700910 "Error, No internet connection for current network")
911 wutils.wifi_forget_network(self.dut,
Bindu Mahadev06fb2e12017-06-06 15:45:34 -0700912 self.reference_networks[0]["2g"]["SSID"])
Ang Li2d3fe982016-06-08 10:00:43 -0700913 except queue.Empty as error:
914 raise AssertionError(
915 "Event did not triggered for batch scan {}".format(error))
Ang Li73697b32015-12-03 00:41:53 +0000916 finally:
Ang Lia9d188f2016-02-17 18:03:01 -0800917 self.dut.droid.wifiScannerStopBackgroundScan(idx)
918 self.dut.ed.clear_all_events()
Ang Li73697b32015-12-03 00:41:53 +0000919
Girish Moturu00304f82017-04-13 09:28:37 +0530920 @test_tracker_info(uuid="7c25ce32-0fae-4a68-a7cb-fdf6d4d03caf")
Ang Li73697b32015-12-03 00:41:53 +0000921 def test_wifi_scanner_single_scan_channel_sanity(self):
922 """Test WiFi scanner single scan for mix channel with default setting
923 parameters.
924
925 1. Start WifiScanner single scan for mix channels with default setting
926 parameters.
927 2. Verify that scan results match with respective scan settings.
928 """
Ang Li2d3fe982016-06-08 10:00:43 -0700929 scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN,
930 "periodInMs": SCANTIME,
931 "reportEvents":
932 wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN}
Ang Li73697b32015-12-03 00:41:53 +0000933 self.wifi_scanner_single_scan(scan_setting)
934
xshuaabcfeb2018-02-14 11:43:24 -0800935 @test_tracker_info(uuid="7c8da0c4-dec7-4d04-abd4-f8ea467a5c6d")
lutinaf02723f2020-03-24 19:22:47 +0800936 @WifiBaseTest.wifi_test_wrap
xshuaabcfeb2018-02-14 11:43:24 -0800937 def test_wifi_scanner_dual_radio_low_latency(self):
938 """Test WiFi scanner single scan for mix channel with default setting
939 parameters.
940
941 1. Start WifiScanner single scan for type = SCAN_TYPE_LOW_LATENCY.
942 2. Verify that scan results match with respective scan settings.
943 """
944 if self.dut.model not in self.dbs_supported_models:
945 asserts.skip(
946 ("Device %s does not support dual radio scanning.")
947 % self.dut.model)
948 scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN,
949 "periodInMs": SCANTIME,
950 "reportEvents":
951 wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT,
952 "type": wutils.WifiEnums.SCAN_TYPE_LOW_LATENCY}
953 self.wifi_scanner_single_scan_full(scan_setting)
954
955 @test_tracker_info(uuid="58b49b01-851b-4e45-b218-9fd27c0be921")
lutinaf02723f2020-03-24 19:22:47 +0800956 @WifiBaseTest.wifi_test_wrap
xshuaabcfeb2018-02-14 11:43:24 -0800957 def test_wifi_scanner_dual_radio_low_power(self):
958 """Test WiFi scanner single scan for mix channel with default setting
959 parameters.
960
961 1. Start WifiScanner single scan for type = SCAN_TYPE_LOW_POWER.
962 2. Verify that scan results match with respective scan settings.
963 """
964 if self.dut.model not in self.dbs_supported_models:
965 asserts.skip(
966 ("Device %s does not support dual radio scanning.")
967 % self.dut.model)
968 scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN,
969 "periodInMs": SCANTIME,
970 "reportEvents":
971 wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT,
972 "type": wutils.WifiEnums.SCAN_TYPE_LOW_POWER}
973 self.wifi_scanner_single_scan_full(scan_setting)
974
975 @test_tracker_info(uuid="3e7288bc-45e4-497c-bf3a-977eec4e896e")
lutinaf02723f2020-03-24 19:22:47 +0800976 @WifiBaseTest.wifi_test_wrap
xshuaabcfeb2018-02-14 11:43:24 -0800977 def test_wifi_scanner_dual_radio_high_accuracy(self):
978 """Test WiFi scanner single scan for mix channel with default setting
979 parameters.
980
981 1. Start WifiScanner single scan for type = SCAN_TYPE_HIGH_ACCURACY.
982 2. Verify that scan results match with respective scan settings.
983 """
984 if self.dut.model not in self.dbs_supported_models:
985 asserts.skip(
986 ("Device %s does not support dual radio scanning.")
987 % self.dut.model)
988 scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN,
989 "periodInMs": SCANTIME,
990 "reportEvents":
991 wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT,
992 "type": wutils.WifiEnums.SCAN_TYPE_HIGH_ACCURACY}
993 self.wifi_scanner_single_scan_full(scan_setting)
994
Girish Moturu00304f82017-04-13 09:28:37 +0530995 @test_tracker_info(uuid="e9f3aaad-4af3-4c54-9829-65dc1d6d4987")
Ang Li73697b32015-12-03 00:41:53 +0000996 def test_wifi_scanner_batch_scan_channel_sanity(self):
997 """Test WiFi scanner batch scan for mix channel with default setting
998 parameters to report the result on buffer full.
999
1000 1. Start WifiScanner batch scan for mix channels with default setting
1001 parameters.
1002 2. Verify that scan results match with respective scan settings.
1003 """
Ang Li2d3fe982016-06-08 10:00:43 -07001004 scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN,
1005 "periodInMs": SCANTIME,
1006 "reportEvents":
1007 wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL}
Ang Li73697b32015-12-03 00:41:53 +00001008 self.wifi_scanner_batch_scan(scan_setting)
1009
Girish Moturu00304f82017-04-13 09:28:37 +05301010 @test_tracker_info(uuid="49ba245a-52e2-4c9b-90ad-a2fbc97e3d9f")
Ang Li73697b32015-12-03 00:41:53 +00001011 def test_wifi_scanner_batch_scan_period_too_short(self):
1012 """Test WiFi scanner batch scan for band with too short period time.
1013
1014 1. Start WifiScanner batch scan for both band with interval period as 5s.
1015 2. Verify that scan is not started."""
Ang Li2d3fe982016-06-08 10:00:43 -07001016 scan_setting = {"band": wutils.WifiEnums.WIFI_BAND_BOTH_WITH_DFS,
1017 "periodInMs": 5000,
1018 "reportEvents":
1019 wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL}
1020 self.start_wifi_scanner_background_scan_expect_failure(scan_setting)
Ang Li73697b32015-12-03 00:41:53 +00001021
Girish Moturu00304f82017-04-13 09:28:37 +05301022 @test_tracker_info(uuid="6fe45cd7-4fac-4ddd-a950-b9431e68f735")
Ang Li73697b32015-12-03 00:41:53 +00001023 def test_wifi_scanner_single_scan_in_isolated(self):
1024 """Test WiFi scanner in isolated environment with default scan settings.
1025
1026 1. Created isolated environment by attenuating the single by 90db
1027 2. Start WifiScanner single scan for mix channels with default setting
1028 parameters.
1029 3. Verify that empty scan results reported.
1030 """
1031 self.attenuators[0].set_atten(90)
1032 self.attenuators[1].set_atten(90)
Ang Li2d3fe982016-06-08 10:00:43 -07001033 data = wutils.start_wifi_single_scan(self.dut,
1034 self.default_scan_setting)
Ang Li73697b32015-12-03 00:41:53 +00001035 idx = data["Index"]
1036 scan_rt = data["ScanElapsedRealtime"]
Ang Li2d3fe982016-06-08 10:00:43 -07001037 self.log.info("Wifi single shot scan started with index: {}".format(
1038 idx))
Ang Li73697b32015-12-03 00:41:53 +00001039 results = []
1040 #generating event wait time from scan setting plus leeway
Ang Li2d3fe982016-06-08 10:00:43 -07001041 scan_time, scan_channels = wutils.get_scan_time_and_channels(
1042 self.wifi_chs, self.default_scan_setting, self.stime_channel)
1043 wait_time = int(scan_time / 1000) + self.leeway
Ang Li73697b32015-12-03 00:41:53 +00001044 try:
1045 event_name = "{}{}onResults".format(EVENT_TAG, idx)
Ang Li2d3fe982016-06-08 10:00:43 -07001046 self.log.debug("Waiting for event: {} for time {}".format(
1047 event_name, wait_time))
Ang Lia9d188f2016-02-17 18:03:01 -08001048 event = self.dut.ed.pop_event(event_name, wait_time)
Ang Li73697b32015-12-03 00:41:53 +00001049 self.log.debug("Event received: {}".format(event))
1050 results = event["data"]["Results"]
Mitchell Willsfc4879e2016-05-02 15:50:54 -07001051 for batch in results:
Ang Lif6a397d2016-06-20 18:47:56 -07001052 asserts.assert_false(batch["ScanResults"],
1053 "Test fail because report scan "
1054 "results reported are not empty")
Ang Li2d3fe982016-06-08 10:00:43 -07001055 except queue.Empty as error:
1056 raise AssertionError(
1057 "Event did not triggered for in isolated environment {}".format(
1058 error))
Ang Li73697b32015-12-03 00:41:53 +00001059 finally:
Ang Lia9d188f2016-02-17 18:03:01 -08001060 self.dut.ed.clear_all_events()
Ang Li73697b32015-12-03 00:41:53 +00001061 self.attenuators[0].set_atten(0)
1062 self.attenuators[1].set_atten(0)
1063
Girish Moturu00304f82017-04-13 09:28:37 +05301064 @test_tracker_info(uuid="46f817b9-97a3-455e-af2c-56f9aea64f7e")
Ang Li73697b32015-12-03 00:41:53 +00001065 def test_wifi_scanner_with_wifi_off(self):
1066 """Test WiFi scanner single scan when wifi is off.
1067
1068 1. Toggle wifi state to off.
1069 2. Start WifiScanner single scan for both band with default scan settings.
1070 3. Verify that scan is not started.
1071 """
1072 self.log.debug("Make sure wifi is off.")
Ang Li2d3fe982016-06-08 10:00:43 -07001073 wutils.wifi_toggle_state(self.dut, False)
1074 self.start_wifi_scanner_single_scan_expect_failure(
1075 self.default_scan_setting)
Ang Li73697b32015-12-03 00:41:53 +00001076 self.log.debug("Turning wifi back on.")
Ang Li2d3fe982016-06-08 10:00:43 -07001077 wutils.wifi_toggle_state(self.dut, True)
Ang Li73697b32015-12-03 00:41:53 +00001078
Girish Moturu00304f82017-04-13 09:28:37 +05301079 @test_tracker_info(uuid="257ad734-c21f-49f4-b448-3986b70eba3d")
Ang Li73697b32015-12-03 00:41:53 +00001080 def test_wifi_scanner_with_invalid_numBssidsPerScan(self):
1081 """Test WiFi scanner single scan with invalid number of bssids reported
1082 per scan.
1083
1084 1. Start WifiScanner single scan with invalid number of bssids reported
1085 per scan.
1086 2. Verify that scan results triggered for default supported number of
1087 bssids per scan.
1088 """
1089 scan_setting = {
Ang Li2d3fe982016-06-08 10:00:43 -07001090 "band": wutils.WifiEnums.WIFI_BAND_BOTH_WITH_DFS,
Ang Li73697b32015-12-03 00:41:53 +00001091 "periodInMs": SCANTIME,
Ang Li2d3fe982016-06-08 10:00:43 -07001092 "reportEvents": wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN,
Ang Li73697b32015-12-03 00:41:53 +00001093 'numBssidsPerScan': 33
1094 }
1095 self.wifi_scanner_single_scan(scan_setting)
Ang Li2d3fe982016-06-08 10:00:43 -07001096
Ang Li73697b32015-12-03 00:41:53 +00001097 """ Tests End """