• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2016 - The Android Open Source Project
4#
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
18import queue
19import time
20import traceback
21
22from acts import asserts
23from acts import base_test
24from acts import utils
25from acts.test_decorators import test_tracker_info
26from acts.test_utils.wifi import wifi_constants
27from acts.test_utils.wifi import wifi_test_utils as wutils
28from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest
29
30SCANTIME = 10000  #framework support only 10s as minimum scan interval
31NUMBSSIDPERSCAN = 8
32EVENT_TAG = "WifiScannerScan"
33SCAN_TIME_PASSIVE = 47  # dwell time plus 2ms
34SCAN_TIME_ACTIVE = 32  # dwell time plus 2ms
35SHORT_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"
41ATTENUATOR = 0
42
43class WifiScannerScanError(Exception):
44    pass
45
46
47class WifiScannerScanTest(WifiBaseTest):
48    def __init__(self, controllers):
49        WifiBaseTest.__init__(self, controllers)
50        # TODO(angli): Remove this list.
51        # There are order dependencies among these tests so we'll have to leave
52        # it here for now. :(
53        self.tests = (
54            "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",
60            "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",
64            "test_wifi_scanner_batch_scan_channel_sanity",
65            "test_wifi_scanner_batch_scan_period_too_short",
66            "test_batch_scan_report_buffer_full_for_channels_with_enumerated_params",
67            "test_batch_scan_report_buffer_full_for_band_with_enumerated_params",
68            "test_batch_scan_report_each_scan_for_channels_with_enumerated_params",
69            "test_batch_scan_report_each_scan_for_band_with_enumerated_params",
70            "test_single_scan_report_full_scan_for_channels_with_enumerated_params",
71            "test_single_scan_report_full_scan_for_band_with_enumerated_params",
72            "test_batch_scan_report_full_scan_for_channels_with_enumerated_params",
73            "test_batch_scan_report_full_scan_for_band_with_enumerated_params",
74            "test_wifi_connection_while_single_scan",
75            "test_single_scan_while_pno",
76            "test_wifi_connection_and_pno_while_batch_scan",
77            "test_wifi_scanner_single_scan_in_isolated",
78            "test_wifi_scanner_with_invalid_numBssidsPerScan",
79            "test_wifi_scanner_dual_radio_low_latency",
80            "test_wifi_scanner_dual_radio_low_power",
81            "test_wifi_scanner_dual_radio_high_accuracy")
82
83    def setup_class(self):
84        self.dut = self.android_devices[0]
85        wutils.wifi_test_device_init(self.dut)
86        req_params = ("run_extended_test", "ping_addr", "max_bugreports", "dbs_supported_models")
87        opt_param = ["reference_networks"]
88        self.unpack_userparams(
89            req_param_names=req_params, opt_param_names=opt_param)
90
91        if "AccessPoint" in self.user_params:
92            self.legacy_configure_ap_and_start(ap_count=2, mirror_ap=False)
93
94        self.leeway = 10
95        self.stime_channel = SCAN_TIME_PASSIVE
96        self.default_scan_setting = {
97            "band": wutils.WifiEnums.WIFI_BAND_BOTH,
98            "periodInMs": SCANTIME,
99            "reportEvents": wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN
100        }
101        self.default_batch_scan_setting = {
102            "band": wutils.WifiEnums.WIFI_BAND_BOTH,
103            "periodInMs": SCANTIME,
104            "reportEvents": wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL
105        }
106        self.log.debug("Run extended test: {}".format(self.run_extended_test))
107        self.wifi_chs = wutils.WifiChannelUS(self.dut.model)
108        asserts.assert_true(self.dut.droid.wifiIsScannerSupported(),
109                            "Device %s doesn't support WifiScanner, abort." %
110                            self.dut.model)
111        self.attenuators = wutils.group_attenuators(self.attenuators)
112        self.attenuators[0].set_atten(0)
113        self.attenuators[1].set_atten(0)
114
115    def teardown_test(self):
116        base_test.BaseTestClass.teardown_test(self)
117        self.log.debug("Shut down all wifi scanner activities.")
118        self.dut.droid.wifiScannerShutdown()
119
120    def on_fail(self, test_name, begin_time):
121        if self.max_bugreports > 0:
122            self.dut.take_bug_report(test_name, begin_time)
123            self.max_bugreports -= 1
124        self.dut.cat_adb_log(test_name, begin_time)
125
126    def teardown_class(self):
127        if "AccessPoint" in self.user_params:
128            del self.user_params["reference_networks"]
129            del self.user_params["open_network"]
130
131    """ Helper Functions Begin """
132
133    def wifi_generate_scanner_scan_settings(self, extended, scan_type,
134                                            report_result):
135        """Generates all the combinations of different scan setting parameters.
136
137        Args:
138          extended: True for extended setting
139          scan_type: key for type of scan
140          report_result: event type of report scan results
141
142        Returns:
143          A list of dictionaries each representing a set of scan settings.
144        """
145        base_scan_time = [SCANTIME * 2]
146        if scan_type == "band":
147            scan_types_setting = [wutils.WifiEnums.WIFI_BAND_BOTH]
148        else:
149            scan_types_setting = [self.wifi_chs.MIX_CHANNEL_SCAN]
150        num_of_bssid = [NUMBSSIDPERSCAN * 4]
151        max_scan_cache = [0]
152        if extended:
153            base_scan_time.append(SCANTIME)
154            if scan_type == "band":
155                scan_types_setting.extend(
156                    [wutils.WifiEnums.WIFI_BAND_24_GHZ,
157                     wutils.WifiEnums.WIFI_BAND_5_GHZ_WITH_DFS,
158                     wutils.WifiEnums.WIFI_BAND_BOTH_WITH_DFS])
159            else:
160                scan_types_setting.extend(
161                    [self.wifi_chs.NONE_DFS_5G_FREQUENCIES, self.wifi_chs.
162                     ALL_2G_FREQUENCIES, self.wifi_chs.DFS_5G_FREQUENCIES,
163                     self.wifi_chs.ALL_5G_FREQUENCIES])
164            num_of_bssid.append(NUMBSSIDPERSCAN * 3)
165            max_scan_cache.append(5)
166            # Generate all the combinations of report types and scan types
167        if report_result == wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT:
168            report_types = {"reportEvents": report_result}
169            setting_combinations = list(itertools.product(scan_types_setting,
170                                                          base_scan_time))
171            # Create scan setting strings based on the combinations
172            scan_settings = []
173            for combo in setting_combinations:
174                s = dict(report_types)
175                s[scan_type] = combo[0]
176                s["periodInMs"] = combo[1]
177                scan_settings.append(s)
178        else:
179            report_types = {"reportEvents": report_result}
180            setting_combinations = list(
181                itertools.product(scan_types_setting, base_scan_time,
182                                  num_of_bssid, max_scan_cache))
183            # Create scan setting strings based on the combinations
184            scan_settings = []
185            for combo in setting_combinations:
186                s = dict(report_types)
187                s[scan_type] = combo[0]
188                s["periodInMs"] = combo[1]
189                s["numBssidsPerScan"] = combo[2]
190                s["maxScansToCache"] = combo[3]
191                scan_settings.append(s)
192        return scan_settings
193
194    def proces_and_valid_batch_scan_result(self, scan_resutls, scan_rt,
195                                           result_rt, scan_setting):
196        """This function process scan results and validate against settings used
197        while starting the scan.
198
199        There are two steps for the verification. First it checks that all the
200        wifi networks in results are of the correct frequencies set by scan setting
201        params. Then it checks that the delta between the batch of scan results less
202        than the time required for scanning channel set by scan setting params.
203
204        Args:
205            scan_results: scan results reported.
206            scan_rt: Elapsed real time on start scan.
207            result_rt: Elapsed ral time on results reported.
208            scan_setting: The params for the single scan.
209
210        Returns:
211            bssids: total number of bssids scan result have
212            validity: True if the all scan result are valid.
213        """
214        bssids = 0
215        validity = True
216        scan_time_mic = 0
217        scan_channels = []
218        scan_time, scan_channels = wutils.get_scan_time_and_channels(
219            self.wifi_chs, scan_setting, self.stime_channel)
220        scan_time_mic = scan_time * 1000
221        for i, batch in enumerate(scan_resutls, start=1):
222            asserts.assert_true(
223                batch["ScanResults"],
224                "At least one scan result is required to validate")
225            max_scan_interval = batch["ScanResults"][0][
226                "timestamp"] + scan_time_mic
227            self.log.debug("max_scan_interval: %s", max_scan_interval)
228            for result in batch["ScanResults"]:
229                if (result["frequency"] not in scan_channels or
230                        result["timestamp"] > max_scan_interval or
231                        result["timestamp"] < scan_rt * 1000 or
232                        result["timestamp"] > result_rt * 1000):
233                    self.log.error("Result didn't match requirement: %s",
234                                   result)
235                    validity = False
236            self.log.info("Number of scan result in batch %s: %s", i,
237                          len(batch["ScanResults"]))
238            bssids += len(batch["ScanResults"])
239        return bssids, validity
240
241    def pop_scan_result_events(self, event_name):
242        """Function to pop all the scan result events.
243
244        Args:
245            event_name: event name.
246
247        Returns:
248            results: list  of scan result reported in events
249        """
250        results = []
251        try:
252            events = self.dut.ed.pop_all(event_name)
253            for event in events:
254                results.append(event["data"]["Results"])
255        except queue.Empty as error:
256            self.log.debug("Number of Full scan results %s", len(results))
257        return results
258
259    def wifi_scanner_single_scan(self, scan_setting):
260        """Common logic for an enumerated wifi scanner single scan test case.
261
262         1. Start WifiScanner single scan for scan_setting.
263         2. Wait for the scan result event, wait time depend on scan settings
264            parameter.
265         3. Verify that scan results match with scan settings parameters.
266         4. Also verify that only one scan result event trigger.
267
268        Args:
269            scan_setting: The params for the single scan.
270        """
271        data = wutils.start_wifi_single_scan(self.dut, scan_setting)
272        idx = data["Index"]
273        scan_rt = data["ScanElapsedRealtime"]
274        self.log.info(
275            "Wifi single shot scan started index: %s at real time: %s", idx,
276            scan_rt)
277        results = []
278        #generating event wait time from scan setting plus leeway
279        scan_time, scan_channels = wutils.get_scan_time_and_channels(
280            self.wifi_chs, scan_setting, self.stime_channel)
281        wait_time = int(scan_time / 1000) + self.leeway
282        validity = False
283        #track number of result received
284        result_received = 0
285        try:
286            for snumber in range(1, 3):
287                event_name = "{}{}onResults".format(EVENT_TAG, idx)
288                self.log.debug("Waiting for event: %s for time %s", event_name,
289                               wait_time)
290                event = self.dut.ed.pop_event(event_name, wait_time)
291                self.log.debug("Event received: %s", event)
292                results = event["data"]["Results"]
293                result_received += 1
294                bssids, validity = self.proces_and_valid_batch_scan_result(
295                    results, scan_rt, event["data"][KEY_RET], scan_setting)
296                asserts.assert_equal(
297                    len(results), 1,
298                    "Test fail because number of scan result %s" %
299                    len(results))
300                asserts.assert_true(bssids > 0, EMPTY_RESULT)
301                asserts.assert_true(validity, INVALID_RESULT)
302                self.log.info("Scan number Buckets: %s\nTotal BSSID: %s",
303                              len(results), bssids)
304        except queue.Empty as error:
305            asserts.assert_true(
306                result_received >= 1,
307                "Event did not triggered for single shot {}".format(error))
308        finally:
309            self.dut.droid.wifiScannerStopScan(idx)
310            #For single shot number of result received and length of result should be one
311            asserts.assert_true(
312                result_received == 1,
313                "Test fail because received result {}".format(result_received))
314
315    def wifi_scanner_single_scan_full(self, scan_setting):
316        """Common logic for single scan test case for full scan result.
317
318        1. Start WifiScanner single scan with scan_setting for full scan result.
319        2. Wait for the scan result event, wait time depend on scan settings
320           parameter.
321        3. Pop all full scan result events occurred earlier.
322        4. Verify that full scan results match with normal scan results.
323        5. If the scan type is included in scan_setting, verify that the
324           radioChainInfos length.
325
326        Args:
327            scan_setting: The parameters for the single scan.
328        """
329        self.dut.ed.clear_all_events()
330        data = wutils.start_wifi_single_scan(self.dut, scan_setting)
331        idx = data["Index"]
332        scan_rt = data["ScanElapsedRealtime"]
333        self.log.info("Wifi single shot scan started with index: %s", idx)
334        #generating event wait time from scan setting plus leeway
335        scan_time, scan_channels = wutils.get_scan_time_and_channels(
336            self.wifi_chs, scan_setting, self.stime_channel)
337        wait_time = int(scan_time / 1000) + self.leeway
338        results = []
339        validity = False
340        try:
341            event_name = "%s%sonResults" % (EVENT_TAG, idx)
342            self.log.debug("Waiting for event: %s for time %s", event_name,
343                           wait_time)
344            event = self.dut.ed.pop_event(event_name, wait_time)
345            self.log.info("Event received: %s", event)
346            bssids, validity = (self.proces_and_valid_batch_scan_result(
347                event["data"]["Results"], scan_rt, event["data"][KEY_RET],
348                scan_setting))
349            asserts.assert_true(bssids > 0, EMPTY_RESULT)
350            asserts.assert_true(validity, INVALID_RESULT)
351            event_name = "{}{}onFullResult".format(EVENT_TAG, idx)
352            results = self.pop_scan_result_events(event_name)
353            asserts.assert_true(
354                len(results) >= bssids,
355                "Full single shot result don't match {}".format(len(results)))
356            if 'type' in scan_setting.keys():
357                for item in results:
358                    self.verify_radio_chain_length(scan_setting['type'], item)
359        except queue.Empty as error:
360            raise AssertionError(
361                "Event did not triggered for single shot {}".format(error))
362        finally:
363            self.dut.droid.wifiScannerStopScan(idx)
364
365    def verify_radio_chain_length(self, scan_setting_type, scan_result):
366        llen = len(scan_result[0]["radioChainInfos"])
367        if scan_setting_type == wutils.WifiEnums.SCAN_TYPE_LOW_LATENCY \
368            or scan_setting_type == wutils.WifiEnums.SCAN_TYPE_LOW_POWER:
369            asserts.assert_true(llen == 1,
370                                "radioChainInfos len expected:{} "
371                                "actual:{}".format(1, llen))
372        else:
373            asserts.assert_true(llen == 2,
374                                "radioChainInfos len expected:{} "
375                                "actual:{}".format(2, llen))
376
377    def wifi_scanner_batch_scan_full(self, scan_setting):
378        """Common logic for batch scan test case for full scan result.
379
380        1. Start WifiScanner batch scan with scan_setting for full scan result.
381        2. Wait for the scan result event, wait time depend on scan settings
382           parameter.
383        3. Pop all full scan result events occurred earlier.
384        4. Verify that full scan results match with scan results.
385
386        Args:
387            scan_setting: The params for the batch scan.
388        """
389        self.dut.ed.clear_all_events()
390        data = wutils.start_wifi_background_scan(self.dut, scan_setting)
391        idx = data["Index"]
392        scan_rt = data["ScanElapsedRealtime"]
393        self.log.info("Wifi batch shot scan started with index: %s", idx)
394        #generating event wait time from scan setting plus leeway
395        scan_time, scan_channels = wutils.get_scan_time_and_channels(
396            self.wifi_chs, scan_setting, self.stime_channel)
397        # multiply scan period by two to account for scheduler changing period
398        scan_time += scan_setting[
399            'periodInMs'] * 2  #add scan period delay for next cycle
400        wait_time = scan_time / 1000 + self.leeway
401        validity = False
402        try:
403            for snumber in range(1, 3):
404                results = []
405                event_name = "%s%sonResults" % (EVENT_TAG, idx)
406                self.log.debug("Waiting for event: %s for time %s", event_name,
407                               wait_time)
408                event = self.dut.ed.pop_event(event_name, wait_time)
409                self.log.debug("Event received: %s", event)
410                bssids, validity = self.proces_and_valid_batch_scan_result(
411                    event["data"]["Results"], scan_rt, event["data"][KEY_RET],
412                    scan_setting)
413                event_name = "%s%sonFullResult" % (EVENT_TAG, idx)
414                results = self.pop_scan_result_events(event_name)
415                asserts.assert_true(
416                    len(results) >= bssids,
417                    "Full single shot result don't match %s" % len(results))
418                asserts.assert_true(bssids > 0, EMPTY_RESULT)
419                asserts.assert_true(validity, INVALID_RESULT)
420        except queue.Empty as error:
421            raise AssertionError("Event did not triggered for batch scan %s" %
422                                 error)
423        finally:
424            self.dut.droid.wifiScannerStopBackgroundScan(idx)
425            self.dut.ed.clear_all_events()
426
427    def wifi_scanner_batch_scan(self, scan_setting):
428        """Common logic for an enumerated wifi scanner batch scan test case.
429
430        1. Start WifiScanner batch scan for given scan_setting.
431        2. Wait for the scan result event, wait time depend on scan settings
432           parameter.
433        3. Verify that scan results match with scan settings parameters.
434        4. Also verify that multiple scan result events trigger.
435
436        Args:
437            scan_setting: The parameters for the batch scan.
438        """
439        data = wutils.start_wifi_background_scan(self.dut, scan_setting)
440        idx = data["Index"]
441        scan_rt = data["ScanElapsedRealtime"]
442        self.log.info(
443            "Wifi background scan started with index: %s real time %s", idx,
444            scan_rt)
445        scan_time, scan_channels = wutils.get_scan_time_and_channels(
446            self.wifi_chs, scan_setting, self.stime_channel)
447        #generating event wait time from scan setting plus leeway
448        time_cache = 0
449        number_bucket = 1  #bucket for Report result on each scan
450        check_get_result = False
451        if scan_setting[
452                'reportEvents'] == wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL:
453            check_get_result = True
454            if ('maxScansToCache' in scan_setting and
455                    scan_setting['maxScansToCache'] != 0):
456                time_cache = (scan_setting['maxScansToCache'] *
457                              scan_setting['periodInMs'])
458                number_bucket = scan_setting['maxScansToCache']
459            else:
460                time_cache = 10 * scan_setting['periodInMs'
461                                               ]  #10 as default max scan cache
462                number_bucket = 10
463        else:
464            time_cache = scan_setting[
465                'periodInMs'
466            ]  #need while waiting for seconds resutls
467        # multiply cache time by two to account for scheduler changing period
468        wait_time = (time_cache * 2 + scan_time) / 1000 + self.leeway
469        validity = False
470        try:
471            for snumber in range(1, 3):
472                event_name = "%s%sonResults" % (EVENT_TAG, idx)
473                self.log.info("Waiting for event: %s for time %s", event_name,
474                              wait_time)
475                event = self.dut.ed.pop_event(event_name, wait_time)
476                self.log.debug("Event received: %s", event)
477                results = event["data"]["Results"]
478                bssids, validity = (self.proces_and_valid_batch_scan_result(
479                    results, scan_rt, event["data"][KEY_RET], scan_setting))
480                self.log.info("Scan number: %s\n Buckets: %s\n  BSSID: %s",
481                              snumber, len(results), bssids)
482                asserts.assert_equal(
483                    len(results), number_bucket,
484                    "Test fail because number_bucket %s" % len(results))
485                asserts.assert_true(bssids >= 1, EMPTY_RESULT)
486                asserts.assert_true(validity, INVALID_RESULT)
487                if snumber % 2 == 1 and check_get_result:
488                    self.log.info("Get Scan result using GetScanResult API")
489                    time.sleep(wait_time / number_bucket)
490                    if self.dut.droid.wifiScannerGetScanResults():
491                        event = self.dut.ed.pop_event(event_name, 1)
492                        self.log.debug("Event onResults: %s", event)
493                        results = event["data"]["Results"]
494                        bssids, validity = self.proces_and_valid_batch_scan_result(
495                            results, scan_rt, event["data"][KEY_RET],
496                            scan_setting)
497                        self.log.info("Got Scan result number: %s BSSID: %s",
498                                      snumber, bssids)
499                        asserts.assert_true(bssids >= 1, EMPTY_RESULT)
500                        asserts.assert_true(validity, INVALID_RESULT)
501                    else:
502                        self.log.error("Error while fetching the scan result")
503        except queue.Empty as error:
504            raise AssertionError("Event did not triggered for batch scan %s" %
505                                 error)
506        finally:
507            self.dut.droid.wifiScannerStopBackgroundScan(idx)
508            self.dut.ed.clear_all_events()
509
510    def start_wifi_scanner_single_scan_expect_failure(self, scan_setting):
511        """Common logic to test wif scanner single scan with invalid settings
512           or environment
513
514         1. Start WifiScanner batch scan for setting parameters.
515         2. Verify that scan is not started.
516
517         Args:
518            scan_setting: The params for the single scan.
519        """
520        try:
521            idx = self.dut.droid.wifiScannerStartScan(scan_setting)
522            event = self.dut.ed.pop_event(
523                "{}{}onFailure".format(EVENT_TAG, idx), SHORT_TIMEOUT)
524        except queue.Empty as error:
525            raise AssertionError("Did not get expected onFailure {}".format(
526                error))
527
528    def start_wifi_scanner_background_scan_expect_failure(self, scan_setting):
529        """Common logic to test wif scanner batch scan with invalid settings
530           or environment
531
532         1. Start WifiScanner batch scan for setting parameters.
533         2. Verify that scan is not started.
534
535         Args:
536          scan_setting: The params for the single scan.
537        """
538        try:
539            idx = self.dut.droid.wifiScannerStartBackgroundScan(scan_setting)
540            event = self.dut.ed.pop_event(
541                "{}{}onFailure".format(EVENT_TAG, idx), SHORT_TIMEOUT)
542        except queue.Empty as error:
543            raise AssertionError("Did not get expected onFailure {}".format(
544                error))
545
546    def check_get_available_channels_with_one_band(self, band):
547        """Common logic to check available channels for a band.
548
549         1. Get available channels for band.
550         2. Verify that channels match with supported channels for band.
551
552         Args:
553            band: wifi band."""
554
555        r = self.dut.droid.wifiScannerGetAvailableChannels(band)
556        self.log.debug(band)
557        self.log.debug(r)
558        expected = self.wifi_chs.band_to_freq(band)
559        asserts.assert_equal(set(r), set(expected), "Band %s failed." % band)
560
561    def connect_to_reference_network(self):
562        """Connect to reference network and make sure that connection happen"""
563        self.dut.droid.wakeLockAcquireBright()
564        self.dut.droid.wakeUpNow()
565        try:
566            self.dut.droid.wifiConnectByConfig(self.reference_networks[0]["2g"])
567            connect_result = self.dut.ed.pop_event(
568                wifi_constants.CONNECT_BY_CONFIG_SUCCESS, SHORT_TIMEOUT)
569            self.log.info(connect_result)
570            return wutils.track_connection(self.dut,
571                self.reference_networks[0]["2g"]["SSID"], 1)
572        except Exception as error:
573            self.log.exception(traceback.format_exc())
574            self.log.error("Connection to network fail because %s", error)
575            return False
576        finally:
577            self.dut.droid.wifiLockRelease()
578            self.dut.droid.goToSleepNow()
579
580    """ Helper Functions End """
581    """ Tests Begin """
582
583    # Test channels
584    """ Test available channels for different bands.
585
586        1. Get available channels for different bands.
587        2. Verify that channels match with supported channels for respective band.
588    """
589    @test_tracker_info(uuid="7cca8142-529f-4951-ab6f-cd03b359b3cc")
590    def test_available_channels_band_1(self):
591        self.check_get_available_channels_with_one_band(1)
592
593    @test_tracker_info(uuid="612afda1-0d74-4d2f-bc37-72ef2b98310a")
594    def test_available_channels_band_2(self):
595        self.check_get_available_channels_with_one_band(2)
596
597    @test_tracker_info(uuid="a9275bb9-afa7-4dd4-b2e0-60296ffd33bb")
598    def test_available_channels_band_3(self):
599        self.check_get_available_channels_with_one_band(3)
600
601    @test_tracker_info(uuid="5413632e-ce72-4ecc-bf9b-33ac9e4bf3fc")
602    def test_available_channels_band_4(self):
603        self.check_get_available_channels_with_one_band(4)
604
605    @test_tracker_info(uuid="a8f40b4f-d79d-4d2f-bed8-3b139a082f6c")
606    def test_available_channels_band_6(self):
607        self.check_get_available_channels_with_one_band(6)
608
609    @test_tracker_info(uuid="84cdfc25-8e64-42c7-b7f9-0a04e45d78b6")
610    def test_available_channels_band_7(self):
611        self.check_get_available_channels_with_one_band(7)
612
613    @test_tracker_info(uuid="95069244-b76c-4834-b3a6-96b0d8da98d8")
614    def test_single_scan_report_each_scan_for_channels_with_enumerated_params(
615            self):
616        """Test WiFi scanner single scan for channels with enumerated settings.
617
618         1. Start WifiScanner single scan for different channels with enumerated
619            scan settings.
620         2. Verify that scan results match with respective scan settings.
621        """
622        scan_settings = self.wifi_generate_scanner_scan_settings(
623            self.run_extended_test, "channels",
624            wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN)
625        self.log.debug("Scan settings: %s\n%s", len(scan_settings),
626                       scan_settings)
627        self.wifi_scanner_single_scan(scan_settings[0])
628
629    @test_tracker_info(uuid="5595ebe5-6d91-4379-a606-be59967e5ec9")
630    def test_single_scan_report_each_scan_for_band_with_enumerated_params(
631            self):
632        """Test WiFi scanner single scan for bands with enumerated settings.
633
634         1. Start WifiScanner single scan for different bands with enumerated
635            scan settings.
636         2. Verify that scan results match with respective scan settings.
637        """
638        scan_settings = self.wifi_generate_scanner_scan_settings(
639            self.run_extended_test, "band",
640            wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN)
641        self.log.debug("Scan settings:%s\n%s", len(scan_settings),
642                       scan_settings)
643        self.wifi_scanner_single_scan(scan_settings[0])
644
645    @test_tracker_info(uuid="44989f93-e63b-4c2e-a90a-a483477303bb")
646    def test_batch_scan_report_buffer_full_for_channels_with_enumerated_params(
647            self):
648        """Test WiFi scanner batch scan using channels with enumerated settings
649           to report buffer full scan results.
650
651         1. Start WifiScanner batch scan using different channels with enumerated
652            scan settings to report buffer full scan results.
653         2. Verify that scan results match with respective scan settings.
654        """
655        scan_settings = self.wifi_generate_scanner_scan_settings(
656            self.run_extended_test, "channels",
657            wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL)
658        self.log.debug("Scan settings:%s\n%s", len(scan_settings),
659                       scan_settings)
660        self.wifi_scanner_batch_scan(scan_settings[0])
661
662    @test_tracker_info(uuid="63538df6-388a-4c16-964f-e9c19b750e07")
663    def test_batch_scan_report_buffer_full_for_band_with_enumerated_params(
664            self):
665        """Test WiFi scanner batch scan using band with enumerated settings
666           to report buffer full scan results.
667
668         1. Start WifiScanner batch scan using different bands with enumerated
669            scan settings to report buffer full scan results.
670         2. Verify that scan results match with respective scan settings.
671        """
672        scan_settings = self.wifi_generate_scanner_scan_settings(
673            self.run_extended_test, "band",
674            wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL)
675        self.log.debug("Scan settings:{}\n{}".format(
676            len(scan_settings), scan_settings))
677        self.wifi_scanner_batch_scan(scan_settings[0])
678
679    @test_tracker_info(uuid="bd4e8c53-16c8-4ed6-b680-55c1ba688ad8")
680    def test_batch_scan_report_each_scan_for_channels_with_enumerated_params(
681            self):
682        """Test WiFi scanner batch scan using channels with enumerated settings
683           to report each scan results.
684
685         1. Start WifiScanner batch scan using different channels with enumerated
686            scan settings to report each scan results.
687         2. Verify that scan results match with respective scan settings.
688        """
689        scan_settings = self.wifi_generate_scanner_scan_settings(
690            self.run_extended_test, "channels",
691            wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN)
692        self.log.debug("Scan settings:{}\n{}".format(
693            len(scan_settings), scan_settings))
694        self.wifi_scanner_batch_scan(scan_settings[0])
695
696    @test_tracker_info(uuid="d11e8c09-97d0-49c1-bf09-b9ec672c2fa6")
697    def test_batch_scan_report_each_scan_for_band_with_enumerated_params(self):
698        """Test WiFi scanner batch scan using band with enumerated settings
699           to report each scan results.
700
701         1. Start WifiScanner batch scan using different bands with enumerated
702            scan settings to report each scan results.
703         2. Verify that scan results match with respective scan settings.
704        """
705        scan_settings = self.wifi_generate_scanner_scan_settings(
706            self.run_extended_test, "band",
707            wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN)
708        self.log.debug("Scan settings:{}\n{}".format(
709            len(scan_settings), scan_settings))
710        self.wifi_scanner_batch_scan(scan_settings[0])
711
712    @test_tracker_info(uuid="7f967b0e-82fe-403e-9d74-0dee7f09a21d")
713    def test_single_scan_report_full_scan_for_channels_with_enumerated_params(
714            self):
715        """Test WiFi scanner single scan using channels with enumerated settings
716           to report full scan results.
717
718         1. Start WifiScanner single scan using different channels with enumerated
719            scan settings to report full scan results.
720         2. Verify that scan results match with respective scan settings.
721        """
722        scan_settings = self.wifi_generate_scanner_scan_settings(
723            self.run_extended_test, "channels",
724            wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT)
725        self.log.debug("Full Scan settings:{}\n{}".format(
726            len(scan_settings), scan_settings))
727        self.wifi_scanner_single_scan_full(scan_settings[0])
728
729    @test_tracker_info(uuid="34d09f60-31bf-4952-8fb3-03fc93ec98fa")
730    def test_single_scan_report_full_scan_for_band_with_enumerated_params(
731            self):
732        """Test WiFi scanner single scan using band with enumerated settings
733           to report full scan results.
734
735         1. Start WifiScanner single scan using different bands with enumerated
736            scan settings to report full scan results.
737         2. Verify that scan results match with respective scan settings.
738        """
739        scan_settings = self.wifi_generate_scanner_scan_settings(
740            self.run_extended_test, "band",
741            wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT)
742        self.log.debug("Full Scan settings:{}\n{}".format(
743            len(scan_settings), scan_settings))
744        self.wifi_scanner_single_scan_full(scan_settings[0])
745
746    @test_tracker_info(uuid="0ddccf2e-b518-45a7-ae75-96924070b841")
747    def test_batch_scan_report_full_scan_for_channels_with_enumerated_params(
748            self):
749        """Test WiFi scanner batch scan using channels with enumerated settings
750           to report full scan results.
751
752         1. Start WifiScanner batch scan using different channels with enumerated
753            scan settings to report full scan results.
754         2. Verify that scan results match with respective scan settings.
755        """
756        scan_settings = self.wifi_generate_scanner_scan_settings(
757            self.run_extended_test, "channels",
758            wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT)
759        self.log.debug("Full Scan settings:{}\n{}".format(
760            len(scan_settings), scan_settings))
761        self.wifi_scanner_batch_scan_full(scan_settings[0])
762
763    @test_tracker_info(uuid="0685b667-8470-43a0-923d-dee71428f8ce")
764    def test_batch_scan_report_full_scan_for_band_with_enumerated_params(self):
765        """Test WiFi scanner batch scan using channels with enumerated settings
766           to report full scan results.
767
768         1. Start WifiScanner batch scan using different channels with enumerated
769            scan settings to report full scan results.
770         2. Verify that scan results match with respective scan settings.
771        """
772        scan_settings = self.wifi_generate_scanner_scan_settings(
773            self.run_extended_test, "band",
774            wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT)
775        self.log.debug("Full Scan settings:{}\n{}".format(
776            len(scan_settings), scan_settings))
777        self.wifi_scanner_batch_scan_full(scan_settings[0])
778
779    @test_tracker_info(uuid="740e1c18-911a-43d2-9317-3827ecf71d3b")
780    def test_wifi_connection_while_single_scan(self):
781        """Test configuring a connection parallel to wifi scanner single scan.
782
783         1. Start WifiScanner single scan for both band with default scan settings.
784         2. Configure a connection to reference network.
785         3. Verify that connection to reference network occurred.
786         2. Verify that scanner report single scan results.
787        """
788        self.attenuators[ATTENUATOR].set_atten(0)
789        data = wutils.start_wifi_single_scan(self.dut,
790                                             self.default_scan_setting)
791        idx = data["Index"]
792        scan_rt = data["ScanElapsedRealtime"]
793        self.log.info("Wifi single shot scan started with index: {}".format(
794            idx))
795        asserts.assert_true(self.connect_to_reference_network(), NETWORK_ERROR)
796        time.sleep(10)  #wait for connection to be active
797        asserts.assert_true(
798            wutils.validate_connection(self.dut, self.ping_addr),
799            "Error, No internet connection for current network")
800        #generating event wait time from scan setting plus leeway
801        scan_time, scan_channels = wutils.get_scan_time_and_channels(
802            self.wifi_chs, self.default_scan_setting, self.stime_channel)
803        wait_time = int(scan_time / 1000) + self.leeway
804        validity = False
805        try:
806            event_name = "{}{}onResults".format(EVENT_TAG, idx)
807            self.log.debug("Waiting for event: {} for time {}".format(
808                event_name, wait_time))
809            event = self.dut.ed.pop_event(event_name, wait_time)
810            self.log.debug("Event received: {}".format(event))
811            results = event["data"]["Results"]
812            bssids, validity = self.proces_and_valid_batch_scan_result(
813                results, scan_rt, event["data"][KEY_RET],
814                self.default_scan_setting)
815            self.log.info("Scan number Buckets: {}\nTotal BSSID: {}".format(
816                len(results), bssids))
817            asserts.assert_true(
818                len(results) == 1 and bssids >= 1, EMPTY_RESULT)
819        except queue.Empty as error:
820            raise AssertionError(
821                "Event did not triggered for single scan {}".format(error))
822
823    @test_tracker_info(uuid="e9a7cfb5-21c4-4c40-8169-8d88b65a1dee")
824    def test_single_scan_while_pno(self):
825        """Test wifi scanner single scan parallel to PNO connection.
826
827         1. Check device have a saved network.
828         2. Trigger PNO by attenuate the signal to move out of range.
829         3. Start WifiScanner single scan for both band with default scan settings.
830         4. Verify that scanner report single scan results.
831         5. Attenuate the signal to move in range.
832         6. Verify connection occurred through PNO.
833        """
834        self.log.info("Check connection through PNO for reference network")
835        current_network = self.dut.droid.wifiGetConnectionInfo()
836        self.log.info("Current network: {}".format(current_network))
837        asserts.assert_true('network_id' in current_network, NETWORK_ID_ERROR)
838        asserts.assert_true(current_network['network_id'] >= 0, NETWORK_ERROR)
839        self.log.info("Kicking PNO for reference network")
840        self.attenuators[ATTENUATOR].set_atten(90)
841        time.sleep(10)  #wait for PNO to be kicked
842        self.log.info("Starting single scan while PNO")
843        self.wifi_scanner_single_scan(self.default_scan_setting)
844        self.attenuators[ATTENUATOR].set_atten(0)
845        self.log.info("Check connection through PNO for reference network")
846        time.sleep(60)  #wait for connection through PNO
847        current_network = self.dut.droid.wifiGetConnectionInfo()
848        self.log.info("Current network: {}".format(current_network))
849        asserts.assert_true('network_id' in current_network, NETWORK_ID_ERROR)
850        asserts.assert_true(current_network['network_id'] >= 0, NETWORK_ERROR)
851        time.sleep(10)  #wait for IP to be assigned
852        asserts.assert_true(
853            wutils.validate_connection(self.dut, self.ping_addr),
854            "Error, No internet connection for current network")
855        wutils.wifi_forget_network(self.dut,
856            self.reference_networks[0]["2g"]["SSID"])
857
858    @test_tracker_info(uuid="fc18d947-0b5a-42b4-98f3-dd1f2b52a7af")
859    def test_wifi_connection_and_pno_while_batch_scan(self):
860        """Test configuring a connection and PNO connection parallel to wifi
861           scanner batch scan.
862
863         1. Start WifiScanner batch scan with default batch scan settings.
864         2. Wait for scan result event for a time depend on scan settings.
865         3. Verify reported batch scan results.
866         4. Configure a connection to reference network.
867         5. Verify that connection to reference network occurred.
868         6. Wait for scan result event for a time depend on scan settings.
869         7. Verify reported batch scan results.
870         8. Trigger PNO by attenuate the signal to move out of range.
871         9. Wait for scan result event for a time depend on scan settings.
872         10. Verify reported batch scan results.
873         11. Attenuate the signal to move in range.
874         12. Verify connection occurred through PNO.
875        """
876        self.attenuators[ATTENUATOR].set_atten(0)
877        data = wutils.start_wifi_background_scan(
878            self.dut, self.default_batch_scan_setting)
879        idx = data["Index"]
880        scan_rt = data["ScanElapsedRealtime"]
881        self.log.info(
882            "Wifi background scan started with index: {} rt {}".format(
883                idx, scan_rt))
884        #generating event wait time from scan setting plus leeway
885        scan_time, scan_channels = wutils.get_scan_time_and_channels(
886            self.wifi_chs, self.default_batch_scan_setting, self.stime_channel)
887        #default number buckets
888        number_bucket = 10
889        time_cache = self.default_batch_scan_setting[
890            'periodInMs'] * number_bucket  #default cache
891        #add 2 seconds extra time for switch between the channel for connection scan
892        #multiply cache time by two to account for scheduler changing period
893        wait_time = (time_cache * 2 + scan_time) / 1000 + self.leeway + 2
894        result_flag = 0
895        try:
896            for snumber in range(1, 7):
897                event_name = "{}{}onResults".format(EVENT_TAG, idx)
898                self.log.info("Waiting for event: {}".format(event_name))
899                event = self.dut.ed.pop_event(event_name, wait_time)
900                self.log.debug("Event onResults: {}".format(event))
901                results = event["data"]["Results"]
902                bssids, validity = self.proces_and_valid_batch_scan_result(
903                    results, scan_rt, event["data"][KEY_RET],
904                    self.default_batch_scan_setting)
905                self.log.info(
906                    "Scan number: {}\n Buckets: {}\n BSSID: {}".format(
907                        snumber, len(results), bssids))
908                asserts.assert_true(bssids >= 1,
909                                    "Not able to fetch scan result")
910                if snumber == 1:
911                    self.log.info(
912                        "Try to connect AP while waiting for event: {}".format(
913                            event_name))
914                    asserts.assert_true(self.connect_to_reference_network(),
915                                        NETWORK_ERROR)
916                    time.sleep(10)  #wait for connection to be active
917                    asserts.assert_true(
918                        wutils.validate_connection(self.dut, self.ping_addr),
919                        "Error, No internet connection for current network")
920                elif snumber == 3:
921                    self.log.info("Kicking PNO for reference network")
922                    self.attenuators[ATTENUATOR].set_atten(90)
923                elif snumber == 4:
924                    self.log.info("Bring back device for PNO connection")
925                    current_network = self.dut.droid.wifiGetConnectionInfo()
926                    self.log.info("Current network: {}".format(
927                        current_network))
928                    asserts.assert_true('network_id' in current_network,
929                                        NETWORK_ID_ERROR)
930                    asserts.assert_true(
931                        current_network['network_id'] == -1,
932                        "Device is still connected to network  {}".format(
933                            current_network[wutils.WifiEnums.SSID_KEY]))
934                    self.attenuators[ATTENUATOR].set_atten(0)
935                    time.sleep(
936                        10
937                    )  #wait for connection to take place before waiting for scan result
938                elif snumber == 6:
939                    self.log.info(
940                        "Check connection through PNO for reference network")
941                    current_network = self.dut.droid.wifiGetConnectionInfo()
942                    self.log.info("Current network: {}".format(
943                        current_network))
944                    asserts.assert_true('network_id' in current_network,
945                                        NETWORK_ID_ERROR)
946                    asserts.assert_true(current_network['network_id'] >= 0,
947                                        NETWORK_ERROR)
948                    time.sleep(10)  #wait for connection to be active
949                    asserts.assert_true(
950                        wutils.validate_connection(self.dut, self.ping_addr),
951                        "Error, No internet connection for current network")
952                    wutils.wifi_forget_network(self.dut,
953                        self.reference_networks[0]["2g"]["SSID"])
954        except queue.Empty as error:
955            raise AssertionError(
956                "Event did not triggered for batch scan {}".format(error))
957        finally:
958            self.dut.droid.wifiScannerStopBackgroundScan(idx)
959            self.dut.ed.clear_all_events()
960
961    @test_tracker_info(uuid="7c25ce32-0fae-4a68-a7cb-fdf6d4d03caf")
962    def test_wifi_scanner_single_scan_channel_sanity(self):
963        """Test WiFi scanner single scan for mix channel with default setting
964           parameters.
965
966         1. Start WifiScanner single scan for mix channels with default setting
967            parameters.
968         2. Verify that scan results match with respective scan settings.
969        """
970        scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN,
971                        "periodInMs": SCANTIME,
972                        "reportEvents":
973                        wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN}
974        self.wifi_scanner_single_scan(scan_setting)
975
976    @test_tracker_info(uuid="7c8da0c4-dec7-4d04-abd4-f8ea467a5c6d")
977    def test_wifi_scanner_dual_radio_low_latency(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_LOW_LATENCY.
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_LOW_LATENCY}
993        self.wifi_scanner_single_scan_full(scan_setting)
994
995    @test_tracker_info(uuid="58b49b01-851b-4e45-b218-9fd27c0be921")
996    def test_wifi_scanner_dual_radio_low_power(self):
997        """Test WiFi scanner single scan for mix channel with default setting
998           parameters.
999
1000         1. Start WifiScanner single scan for type = SCAN_TYPE_LOW_POWER.
1001         2. Verify that scan results match with respective scan settings.
1002        """
1003        if self.dut.model not in self.dbs_supported_models:
1004            asserts.skip(
1005                ("Device %s does not support dual radio scanning.")
1006                % self.dut.model)
1007        scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN,
1008                        "periodInMs": SCANTIME,
1009                        "reportEvents":
1010                            wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT,
1011                        "type": wutils.WifiEnums.SCAN_TYPE_LOW_POWER}
1012        self.wifi_scanner_single_scan_full(scan_setting)
1013
1014    @test_tracker_info(uuid="3e7288bc-45e4-497c-bf3a-977eec4e896e")
1015    def test_wifi_scanner_dual_radio_high_accuracy(self):
1016        """Test WiFi scanner single scan for mix channel with default setting
1017           parameters.
1018
1019         1. Start WifiScanner single scan for type = SCAN_TYPE_HIGH_ACCURACY.
1020         2. Verify that scan results match with respective scan settings.
1021        """
1022        if self.dut.model not in self.dbs_supported_models:
1023            asserts.skip(
1024                ("Device %s does not support dual radio scanning.")
1025                % self.dut.model)
1026        scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN,
1027                        "periodInMs": SCANTIME,
1028                        "reportEvents":
1029                            wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT,
1030                        "type": wutils.WifiEnums.SCAN_TYPE_HIGH_ACCURACY}
1031        self.wifi_scanner_single_scan_full(scan_setting)
1032
1033    @test_tracker_info(uuid="e9f3aaad-4af3-4c54-9829-65dc1d6d4987")
1034    def test_wifi_scanner_batch_scan_channel_sanity(self):
1035        """Test WiFi scanner batch scan for mix channel with default setting
1036           parameters to report the result on buffer full.
1037
1038         1. Start WifiScanner batch scan for mix channels with default setting
1039            parameters.
1040         2. Verify that scan results match with respective scan settings.
1041        """
1042        scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN,
1043                        "periodInMs": SCANTIME,
1044                        "reportEvents":
1045                        wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL}
1046        self.wifi_scanner_batch_scan(scan_setting)
1047
1048    @test_tracker_info(uuid="49ba245a-52e2-4c9b-90ad-a2fbc97e3d9f")
1049    def test_wifi_scanner_batch_scan_period_too_short(self):
1050        """Test WiFi scanner batch scan for band with too short period time.
1051
1052         1. Start WifiScanner batch scan for both band with interval period as 5s.
1053         2. Verify that scan is not started."""
1054        scan_setting = {"band": wutils.WifiEnums.WIFI_BAND_BOTH_WITH_DFS,
1055                        "periodInMs": 5000,
1056                        "reportEvents":
1057                        wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL}
1058        self.start_wifi_scanner_background_scan_expect_failure(scan_setting)
1059
1060    @test_tracker_info(uuid="6fe45cd7-4fac-4ddd-a950-b9431e68f735")
1061    def test_wifi_scanner_single_scan_in_isolated(self):
1062        """Test WiFi scanner in isolated environment with default scan settings.
1063
1064         1. Created isolated environment by attenuating the single by 90db
1065         2. Start WifiScanner single scan for mix channels with default setting
1066            parameters.
1067         3. Verify that empty scan results reported.
1068        """
1069        self.attenuators[0].set_atten(90)
1070        self.attenuators[1].set_atten(90)
1071        data = wutils.start_wifi_single_scan(self.dut,
1072                                             self.default_scan_setting)
1073        idx = data["Index"]
1074        scan_rt = data["ScanElapsedRealtime"]
1075        self.log.info("Wifi single shot scan started with index: {}".format(
1076            idx))
1077        results = []
1078        #generating event wait time from scan setting plus leeway
1079        scan_time, scan_channels = wutils.get_scan_time_and_channels(
1080            self.wifi_chs, self.default_scan_setting, self.stime_channel)
1081        wait_time = int(scan_time / 1000) + self.leeway
1082        try:
1083            event_name = "{}{}onResults".format(EVENT_TAG, idx)
1084            self.log.debug("Waiting for event: {} for time {}".format(
1085                event_name, wait_time))
1086            event = self.dut.ed.pop_event(event_name, wait_time)
1087            self.log.debug("Event received: {}".format(event))
1088            results = event["data"]["Results"]
1089            for batch in results:
1090                asserts.assert_false(batch["ScanResults"],
1091                                     "Test fail because report scan "
1092                                     "results reported are not empty")
1093        except queue.Empty as error:
1094            raise AssertionError(
1095                "Event did not triggered for in isolated environment {}".format(
1096                    error))
1097        finally:
1098            self.dut.ed.clear_all_events()
1099            self.attenuators[0].set_atten(0)
1100            self.attenuators[1].set_atten(0)
1101
1102    @test_tracker_info(uuid="46f817b9-97a3-455e-af2c-56f9aea64f7e")
1103    def test_wifi_scanner_with_wifi_off(self):
1104        """Test WiFi scanner single scan when wifi is off.
1105
1106         1. Toggle wifi state to off.
1107         2. Start WifiScanner single scan for both band with default scan settings.
1108         3. Verify that scan is not started.
1109        """
1110        self.log.debug("Make sure wifi is off.")
1111        wutils.wifi_toggle_state(self.dut, False)
1112        self.start_wifi_scanner_single_scan_expect_failure(
1113            self.default_scan_setting)
1114        self.log.debug("Turning wifi back on.")
1115        wutils.wifi_toggle_state(self.dut, True)
1116
1117    @test_tracker_info(uuid="257ad734-c21f-49f4-b448-3986b70eba3d")
1118    def test_wifi_scanner_with_invalid_numBssidsPerScan(self):
1119        """Test WiFi scanner single scan with invalid number of bssids reported
1120           per scan.
1121
1122         1. Start WifiScanner single scan with invalid number of bssids reported
1123            per scan.
1124         2. Verify that scan results triggered for default supported number of
1125            bssids per scan.
1126        """
1127        scan_setting = {
1128            "band": wutils.WifiEnums.WIFI_BAND_BOTH_WITH_DFS,
1129            "periodInMs": SCANTIME,
1130            "reportEvents": wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN,
1131            'numBssidsPerScan': 33
1132        }
1133        self.wifi_scanner_single_scan(scan_setting)
1134
1135    """ Tests End """
1136