tturney | 1bdf77d | 2015-12-28 17:46:13 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3.4 |
| 2 | # |
| 3 | # Copyright 2016 - The Android Open Source Project |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 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 | |
| 17 | import itertools |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 18 | import queue |
| 19 | import time |
| 20 | import traceback |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 21 | |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 22 | from acts import asserts |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 23 | from acts import base_test |
| 24 | from acts import utils |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 25 | from acts.test_decorators import test_tracker_info |
Bindu Mahadev | 04ce7b7 | 2016-12-13 12:14:36 -0800 | [diff] [blame] | 26 | from acts.test_utils.wifi import wifi_constants |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 27 | from acts.test_utils.wifi import wifi_test_utils as wutils |
Bindu Mahadev | d34835d | 2017-06-12 17:21:09 -0700 | [diff] [blame] | 28 | from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 29 | |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 30 | SCANTIME = 10000 #framework support only 10s as minimum scan interval |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 31 | NUMBSSIDPERSCAN = 8 |
| 32 | EVENT_TAG = "WifiScannerScan" |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 33 | SCAN_TIME_PASSIVE = 47 # dwell time plus 2ms |
| 34 | SCAN_TIME_ACTIVE = 32 # dwell time plus 2ms |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 35 | SHORT_TIMEOUT = 30 |
| 36 | NETWORK_ID_ERROR = "Network don't have ID" |
| 37 | NETWORK_ERROR = "Device is not connected to reference network" |
| 38 | INVALID_RESULT = "Test fail because scan result reported are not valid" |
| 39 | EMPTY_RESULT = "Test fail because empty scan result reported" |
| 40 | KEY_RET = "ResultElapsedRealtime" |
Bindu Mahadev | 06fb2e1 | 2017-06-06 15:45:34 -0700 | [diff] [blame] | 41 | ATTENUATOR = 0 |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 42 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 43 | class WifiScannerScanError(Exception): |
| 44 | pass |
| 45 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 46 | |
Bindu Mahadev | d34835d | 2017-06-12 17:21:09 -0700 | [diff] [blame] | 47 | class WifiScannerScanTest(WifiBaseTest): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 48 | def __init__(self, controllers): |
Bindu Mahadev | d34835d | 2017-06-12 17:21:09 -0700 | [diff] [blame] | 49 | WifiBaseTest.__init__(self, controllers) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 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. :( |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 53 | self.tests = ( |
Girish Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 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", |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 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", |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 64 | "test_single_scan_report_full_scan_for_channels_with_enumerated_params", |
| 65 | "test_single_scan_report_full_scan_for_band_with_enumerated_params", |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 66 | "test_single_scan_while_pno", |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 67 | "test_wifi_scanner_single_scan_in_isolated", |
xshu | aabcfeb | 2018-02-14 11:43:24 -0800 | [diff] [blame] | 68 | "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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 72 | |
| 73 | def setup_class(self): |
| 74 | self.dut = self.android_devices[0] |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 75 | wutils.wifi_test_device_init(self.dut) |
xshu | aabcfeb | 2018-02-14 11:43:24 -0800 | [diff] [blame] | 76 | req_params = ("run_extended_test", "ping_addr", "max_bugreports", "dbs_supported_models") |
Bindu Mahadev | d34835d | 2017-06-12 17:21:09 -0700 | [diff] [blame] | 77 | 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: |
lutina | 8b7333c | 2019-06-05 20:13:21 +0800 | [diff] [blame] | 82 | self.legacy_configure_ap_and_start(ap_count=2, mirror_ap=False) |
Bindu Mahadev | d34835d | 2017-06-12 17:21:09 -0700 | [diff] [blame] | 83 | |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 84 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 96 | self.log.debug("Run extended test: {}".format(self.run_extended_test)) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 97 | self.wifi_chs = wutils.WifiChannelUS(self.dut.model) |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 98 | asserts.assert_true(self.dut.droid.wifiIsScannerSupported(), |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 99 | "Device %s doesn't support WifiScanner, abort." % |
| 100 | self.dut.model) |
| 101 | self.attenuators = wutils.group_attenuators(self.attenuators) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 102 | self.attenuators[0].set_atten(0) |
| 103 | self.attenuators[1].set_atten(0) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 104 | |
| 105 | def teardown_test(self): |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 106 | base_test.BaseTestClass.teardown_test(self) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 107 | self.log.debug("Shut down all wifi scanner activities.") |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 108 | self.dut.droid.wifiScannerShutdown() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 109 | |
| 110 | def on_fail(self, test_name, begin_time): |
| 111 | if self.max_bugreports > 0: |
Ang Li | 20377aa | 2016-02-26 13:19:51 -0800 | [diff] [blame] | 112 | self.dut.take_bug_report(test_name, begin_time) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 113 | self.max_bugreports -= 1 |
Ang Li | 20377aa | 2016-02-26 13:19:51 -0800 | [diff] [blame] | 114 | self.dut.cat_adb_log(test_name, begin_time) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 115 | |
Bindu Mahadev | ccfe0cc | 2017-08-28 21:08:30 -0700 | [diff] [blame] | 116 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 121 | """ Helper Functions Begin """ |
| 122 | |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 123 | def wifi_generate_scanner_scan_settings(self, extended, scan_type, |
| 124 | report_result): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 125 | """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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 135 | base_scan_time = [SCANTIME * 2] |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 136 | if scan_type == "band": |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 137 | scan_types_setting = [wutils.WifiEnums.WIFI_BAND_BOTH] |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 138 | else: |
| 139 | scan_types_setting = [self.wifi_chs.MIX_CHANNEL_SCAN] |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 140 | num_of_bssid = [NUMBSSIDPERSCAN * 4] |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 141 | max_scan_cache = [0] |
| 142 | if extended: |
| 143 | base_scan_time.append(SCANTIME) |
| 144 | if scan_type == "band": |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 145 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 149 | else: |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 150 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 155 | max_scan_cache.append(5) |
| 156 | # Generate all the combinations of report types and scan types |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 157 | if report_result == wutils.WifiEnums.REPORT_EVENT_FULL_SCAN_RESULT: |
| 158 | report_types = {"reportEvents": report_result} |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 159 | 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 169 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 173 | # 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 208 | scan_time, scan_channels = wutils.get_scan_time_and_channels( |
| 209 | self.wifi_chs, scan_setting, self.stime_channel) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 210 | scan_time_mic = scan_time * 1000 |
| 211 | for i, batch in enumerate(scan_resutls, start=1): |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 212 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 218 | for result in batch["ScanResults"]: |
lutina | f02723f | 2020-03-24 19:22:47 +0800 | [diff] [blame] | 219 | # 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 224 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 233 | 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 Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 247 | events = self.dut.ed.pop_all(event_name) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 248 | for event in events: |
| 249 | results.append(event["data"]["Results"]) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 250 | except queue.Empty as error: |
| 251 | self.log.debug("Number of Full scan results %s", len(results)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 252 | 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 266 | data = wutils.start_wifi_single_scan(self.dut, scan_setting) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 267 | idx = data["Index"] |
| 268 | scan_rt = data["ScanElapsedRealtime"] |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 269 | self.log.info( |
| 270 | "Wifi single shot scan started index: %s at real time: %s", idx, |
| 271 | scan_rt) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 272 | results = [] |
| 273 | #generating event wait time from scan setting plus leeway |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 274 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 277 | validity = False |
| 278 | #track number of result received |
| 279 | result_received = 0 |
| 280 | try: |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 281 | for snumber in range(1, 3): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 282 | event_name = "{}{}onResults".format(EVENT_TAG, idx) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 283 | self.log.debug("Waiting for event: %s for time %s", event_name, |
| 284 | wait_time) |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 285 | event = self.dut.ed.pop_event(event_name, wait_time) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 286 | self.log.debug("Event received: %s", event) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 287 | results = event["data"]["Results"] |
| 288 | result_received += 1 |
| 289 | bssids, validity = self.proces_and_valid_batch_scan_result( |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 290 | 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 Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 295 | asserts.assert_true(bssids > 0, EMPTY_RESULT) |
| 296 | asserts.assert_true(validity, INVALID_RESULT) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 297 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 303 | finally: |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 304 | self.dut.droid.wifiScannerStopScan(idx) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 305 | #For single shot number of result received and length of result should be one |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 306 | asserts.assert_true( |
| 307 | result_received == 1, |
| 308 | "Test fail because received result {}".format(result_received)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 309 | |
| 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. |
xshu | aabcfeb | 2018-02-14 11:43:24 -0800 | [diff] [blame] | 318 | 5. If the scan type is included in scan_setting, verify that the |
| 319 | radioChainInfos length. |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 320 | |
| 321 | Args: |
| 322 | scan_setting: The parameters for the single scan. |
| 323 | """ |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 324 | self.dut.ed.clear_all_events() |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 325 | data = wutils.start_wifi_single_scan(self.dut, scan_setting) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 326 | idx = data["Index"] |
| 327 | scan_rt = data["ScanElapsedRealtime"] |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 328 | self.log.info("Wifi single shot scan started with index: %s", idx) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 329 | #generating event wait time from scan setting plus leeway |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 330 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 333 | results = [] |
| 334 | validity = False |
| 335 | try: |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 336 | event_name = "%s%sonResults" % (EVENT_TAG, idx) |
| 337 | self.log.debug("Waiting for event: %s for time %s", event_name, |
| 338 | wait_time) |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 339 | event = self.dut.ed.pop_event(event_name, wait_time) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 340 | self.log.info("Event received: %s", event) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 341 | bssids, validity = (self.proces_and_valid_batch_scan_result( |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 342 | event["data"]["Results"], scan_rt, event["data"][KEY_RET], |
| 343 | scan_setting)) |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 344 | asserts.assert_true(bssids > 0, EMPTY_RESULT) |
| 345 | asserts.assert_true(validity, INVALID_RESULT) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 346 | event_name = "{}{}onFullResult".format(EVENT_TAG, idx) |
| 347 | results = self.pop_scan_result_events(event_name) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 348 | asserts.assert_true( |
| 349 | len(results) >= bssids, |
| 350 | "Full single shot result don't match {}".format(len(results))) |
xshu | aabcfeb | 2018-02-14 11:43:24 -0800 | [diff] [blame] | 351 | if 'type' in scan_setting.keys(): |
| 352 | for item in results: |
| 353 | self.verify_radio_chain_length(scan_setting['type'], item) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 354 | except queue.Empty as error: |
| 355 | raise AssertionError( |
| 356 | "Event did not triggered for single shot {}".format(error)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 357 | finally: |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 358 | self.dut.droid.wifiScannerStopScan(idx) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 359 | |
xshu | aabcfeb | 2018-02-14 11:43:24 -0800 | [diff] [blame] | 360 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 372 | 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 Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 384 | self.dut.ed.clear_all_events() |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 385 | data = wutils.start_wifi_background_scan(self.dut, scan_setting) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 386 | idx = data["Index"] |
| 387 | scan_rt = data["ScanElapsedRealtime"] |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 388 | self.log.info("Wifi batch shot scan started with index: %s", idx) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 389 | #generating event wait time from scan setting plus leeway |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 390 | scan_time, scan_channels = wutils.get_scan_time_and_channels( |
| 391 | self.wifi_chs, scan_setting, self.stime_channel) |
Mitchell Wills | 301a196 | 2015-12-14 21:49:15 -0800 | [diff] [blame] | 392 | # multiply scan period by two to account for scheduler changing period |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 393 | scan_time += scan_setting[ |
| 394 | 'periodInMs'] * 2 #add scan period delay for next cycle |
Mitchell Wills | 301a196 | 2015-12-14 21:49:15 -0800 | [diff] [blame] | 395 | wait_time = scan_time / 1000 + self.leeway |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 396 | validity = False |
| 397 | try: |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 398 | for snumber in range(1, 3): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 399 | results = [] |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 400 | event_name = "%s%sonResults" % (EVENT_TAG, idx) |
| 401 | self.log.debug("Waiting for event: %s for time %s", event_name, |
| 402 | wait_time) |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 403 | event = self.dut.ed.pop_event(event_name, wait_time) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 404 | self.log.debug("Event received: %s", event) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 405 | bssids, validity = self.proces_and_valid_batch_scan_result( |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 406 | event["data"]["Results"], scan_rt, event["data"][KEY_RET], |
| 407 | scan_setting) |
| 408 | event_name = "%s%sonFullResult" % (EVENT_TAG, idx) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 409 | results = self.pop_scan_result_events(event_name) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 410 | asserts.assert_true( |
| 411 | len(results) >= bssids, |
| 412 | "Full single shot result don't match %s" % len(results)) |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 413 | asserts.assert_true(bssids > 0, EMPTY_RESULT) |
| 414 | asserts.assert_true(validity, INVALID_RESULT) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 415 | except queue.Empty as error: |
| 416 | raise AssertionError("Event did not triggered for batch scan %s" % |
| 417 | error) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 418 | finally: |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 419 | self.dut.droid.wifiScannerStopBackgroundScan(idx) |
| 420 | self.dut.ed.clear_all_events() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 421 | |
| 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 434 | data = wutils.start_wifi_background_scan(self.dut, scan_setting) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 435 | idx = data["Index"] |
| 436 | scan_rt = data["ScanElapsedRealtime"] |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 437 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 442 | #generating event wait time from scan setting plus leeway |
| 443 | time_cache = 0 |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 444 | number_bucket = 1 #bucket for Report result on each scan |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 445 | check_get_result = False |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 446 | if scan_setting[ |
| 447 | 'reportEvents'] == wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL: |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 448 | check_get_result = True |
| 449 | if ('maxScansToCache' in scan_setting and |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 450 | scan_setting['maxScansToCache'] != 0): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 451 | time_cache = (scan_setting['maxScansToCache'] * |
| 452 | scan_setting['periodInMs']) |
| 453 | number_bucket = scan_setting['maxScansToCache'] |
| 454 | else: |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 455 | time_cache = 10 * scan_setting['periodInMs' |
| 456 | ] #10 as default max scan cache |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 457 | number_bucket = 10 |
| 458 | else: |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 459 | time_cache = scan_setting[ |
| 460 | 'periodInMs' |
| 461 | ] #need while waiting for seconds resutls |
Mitchell Wills | 78aaeca | 2015-12-07 18:03:00 -0800 | [diff] [blame] | 462 | # multiply cache time by two to account for scheduler changing period |
| 463 | wait_time = (time_cache * 2 + scan_time) / 1000 + self.leeway |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 464 | validity = False |
| 465 | try: |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 466 | 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 Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 470 | event = self.dut.ed.pop_event(event_name, wait_time) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 471 | self.log.debug("Event received: %s", event) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 472 | results = event["data"]["Results"] |
| 473 | bssids, validity = (self.proces_and_valid_batch_scan_result( |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 474 | 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 Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 480 | asserts.assert_true(bssids >= 1, EMPTY_RESULT) |
| 481 | asserts.assert_true(validity, INVALID_RESULT) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 482 | if snumber % 2 == 1 and check_get_result: |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 483 | self.log.info("Get Scan result using GetScanResult API") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 484 | time.sleep(wait_time / number_bucket) |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 485 | if self.dut.droid.wifiScannerGetScanResults(): |
| 486 | event = self.dut.ed.pop_event(event_name, 1) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 487 | self.log.debug("Event onResults: %s", event) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 488 | results = event["data"]["Results"] |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 489 | 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 Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 494 | asserts.assert_true(bssids >= 1, EMPTY_RESULT) |
| 495 | asserts.assert_true(validity, INVALID_RESULT) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 496 | else: |
| 497 | self.log.error("Error while fetching the scan result") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 498 | except queue.Empty as error: |
| 499 | raise AssertionError("Event did not triggered for batch scan %s" % |
| 500 | error) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 501 | finally: |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 502 | self.dut.droid.wifiScannerStopBackgroundScan(idx) |
| 503 | self.dut.ed.clear_all_events() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 504 | |
| 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 Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 516 | idx = self.dut.droid.wifiScannerStartScan(scan_setting) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 517 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 522 | |
| 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 534 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 540 | |
| 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 Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 550 | r = self.dut.droid.wifiScannerGetAvailableChannels(band) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 551 | self.log.debug(band) |
| 552 | self.log.debug(r) |
| 553 | expected = self.wifi_chs.band_to_freq(band) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 554 | asserts.assert_equal(set(r), set(expected), "Band %s failed." % band) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 555 | |
| 556 | def connect_to_reference_network(self): |
| 557 | """Connect to reference network and make sure that connection happen""" |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 558 | self.dut.droid.wakeLockAcquireBright() |
| 559 | self.dut.droid.wakeUpNow() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 560 | try: |
Bindu Mahadev | 06fb2e1 | 2017-06-06 15:45:34 -0700 | [diff] [blame] | 561 | self.dut.droid.wifiConnectByConfig(self.reference_networks[0]["2g"]) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 562 | connect_result = self.dut.ed.pop_event( |
Bindu Mahadev | 04ce7b7 | 2016-12-13 12:14:36 -0800 | [diff] [blame] | 563 | wifi_constants.CONNECT_BY_CONFIG_SUCCESS, SHORT_TIMEOUT) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 564 | self.log.info(connect_result) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 565 | return wutils.track_connection(self.dut, |
Bindu Mahadev | 06fb2e1 | 2017-06-06 15:45:34 -0700 | [diff] [blame] | 566 | self.reference_networks[0]["2g"]["SSID"], 1) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 567 | except Exception as error: |
| 568 | self.log.exception(traceback.format_exc()) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 569 | self.log.error("Connection to network fail because %s", error) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 570 | return False |
| 571 | finally: |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 572 | self.dut.droid.wifiLockRelease() |
| 573 | self.dut.droid.goToSleepNow() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 574 | |
| 575 | """ Helper Functions End """ |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 576 | """ Tests Begin """ |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 577 | |
Girish Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 578 | # Test channels |
| 579 | """ Test available channels for different bands. |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 580 | |
Girish Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 581 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 607 | |
Girish Moturu | 5a509a3 | 2017-04-03 10:50:18 +0530 | [diff] [blame] | 608 | @test_tracker_info(uuid="95069244-b76c-4834-b3a6-96b0d8da98d8") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 609 | def test_single_scan_report_each_scan_for_channels_with_enumerated_params( |
| 610 | self): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 611 | """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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 618 | 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 Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 622 | self.wifi_scanner_single_scan(scan_settings[0]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 623 | |
Girish Moturu | 5a509a3 | 2017-04-03 10:50:18 +0530 | [diff] [blame] | 624 | @test_tracker_info(uuid="5595ebe5-6d91-4379-a606-be59967e5ec9") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 625 | def test_single_scan_report_each_scan_for_band_with_enumerated_params( |
| 626 | self): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 627 | """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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 634 | 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 Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 638 | self.wifi_scanner_single_scan(scan_settings[0]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 639 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 640 | @test_tracker_info(uuid="44989f93-e63b-4c2e-a90a-a483477303bb") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 641 | def test_batch_scan_report_buffer_full_for_channels_with_enumerated_params( |
| 642 | self): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 643 | """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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 651 | 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 Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 655 | self.wifi_scanner_batch_scan(scan_settings[0]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 656 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 657 | @test_tracker_info(uuid="63538df6-388a-4c16-964f-e9c19b750e07") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 658 | def test_batch_scan_report_buffer_full_for_band_with_enumerated_params( |
| 659 | self): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 660 | """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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 668 | 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 Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 672 | self.wifi_scanner_batch_scan(scan_settings[0]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 673 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 674 | @test_tracker_info(uuid="bd4e8c53-16c8-4ed6-b680-55c1ba688ad8") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 675 | def test_batch_scan_report_each_scan_for_channels_with_enumerated_params( |
| 676 | self): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 677 | """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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 685 | 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 Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 689 | self.wifi_scanner_batch_scan(scan_settings[0]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 690 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 691 | @test_tracker_info(uuid="d11e8c09-97d0-49c1-bf09-b9ec672c2fa6") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 692 | 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 701 | 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 Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 705 | self.wifi_scanner_batch_scan(scan_settings[0]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 706 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 707 | @test_tracker_info(uuid="7f967b0e-82fe-403e-9d74-0dee7f09a21d") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 708 | def test_single_scan_report_full_scan_for_channels_with_enumerated_params( |
| 709 | self): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 710 | """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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 718 | 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 Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 722 | self.wifi_scanner_single_scan_full(scan_settings[0]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 723 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 724 | @test_tracker_info(uuid="34d09f60-31bf-4952-8fb3-03fc93ec98fa") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 725 | def test_single_scan_report_full_scan_for_band_with_enumerated_params( |
| 726 | self): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 727 | """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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 735 | 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 Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 739 | self.wifi_scanner_single_scan_full(scan_settings[0]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 740 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 741 | @test_tracker_info(uuid="0ddccf2e-b518-45a7-ae75-96924070b841") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 742 | def test_batch_scan_report_full_scan_for_channels_with_enumerated_params( |
| 743 | self): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 744 | """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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 752 | 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 Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 756 | self.wifi_scanner_batch_scan_full(scan_settings[0]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 757 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 758 | @test_tracker_info(uuid="0685b667-8470-43a0-923d-dee71428f8ce") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 759 | 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 768 | 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 Moturu | cb5d252 | 2017-08-01 15:55:18 +0530 | [diff] [blame] | 772 | self.wifi_scanner_batch_scan_full(scan_settings[0]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 773 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 774 | @test_tracker_info(uuid="e9a7cfb5-21c4-4c40-8169-8d88b65a1dee") |
lutina | f02723f | 2020-03-24 19:22:47 +0800 | [diff] [blame] | 775 | @WifiBaseTest.wifi_test_wrap |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 776 | 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 Moturu | 147063d | 2019-08-18 11:46:55 -0700 | [diff] [blame] | 787 | 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 Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 794 | current_network = self.dut.droid.wifiGetConnectionInfo() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 795 | self.log.info("Current network: {}".format(current_network)) |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 796 | asserts.assert_true('network_id' in current_network, NETWORK_ID_ERROR) |
| 797 | asserts.assert_true(current_network['network_id'] >= 0, NETWORK_ERROR) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 798 | self.log.info("Kicking PNO for reference network") |
Bindu Mahadev | 06fb2e1 | 2017-06-06 15:45:34 -0700 | [diff] [blame] | 799 | self.attenuators[ATTENUATOR].set_atten(90) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 800 | time.sleep(10) #wait for PNO to be kicked |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 801 | self.log.info("Starting single scan while PNO") |
| 802 | self.wifi_scanner_single_scan(self.default_scan_setting) |
Bindu Mahadev | 06fb2e1 | 2017-06-06 15:45:34 -0700 | [diff] [blame] | 803 | self.attenuators[ATTENUATOR].set_atten(0) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 804 | self.log.info("Check connection through PNO for reference network") |
lutina | 8b7333c | 2019-06-05 20:13:21 +0800 | [diff] [blame] | 805 | time.sleep(60) #wait for connection through PNO |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 806 | current_network = self.dut.droid.wifiGetConnectionInfo() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 807 | self.log.info("Current network: {}".format(current_network)) |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 808 | asserts.assert_true('network_id' in current_network, NETWORK_ID_ERROR) |
| 809 | asserts.assert_true(current_network['network_id'] >= 0, NETWORK_ERROR) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 810 | time.sleep(10) #wait for IP to be assigned |
| 811 | asserts.assert_true( |
Bindu Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame] | 812 | wutils.validate_connection(self.dut, self.ping_addr), |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 813 | "Error, No internet connection for current network") |
Bindu Mahadev | 06fb2e1 | 2017-06-06 15:45:34 -0700 | [diff] [blame] | 814 | wutils.wifi_forget_network(self.dut, |
| 815 | self.reference_networks[0]["2g"]["SSID"]) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 816 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 817 | @test_tracker_info(uuid="fc18d947-0b5a-42b4-98f3-dd1f2b52a7af") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 818 | 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 Mahadev | 06fb2e1 | 2017-06-06 15:45:34 -0700 | [diff] [blame] | 835 | self.attenuators[ATTENUATOR].set_atten(0) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 836 | data = wutils.start_wifi_background_scan( |
| 837 | self.dut, self.default_batch_scan_setting) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 838 | idx = data["Index"] |
| 839 | scan_rt = data["ScanElapsedRealtime"] |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 840 | self.log.info( |
| 841 | "Wifi background scan started with index: {} rt {}".format( |
| 842 | idx, scan_rt)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 843 | #generating event wait time from scan setting plus leeway |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 844 | scan_time, scan_channels = wutils.get_scan_time_and_channels( |
| 845 | self.wifi_chs, self.default_batch_scan_setting, self.stime_channel) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 846 | #default number buckets |
| 847 | number_bucket = 10 |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 848 | time_cache = self.default_batch_scan_setting[ |
| 849 | 'periodInMs'] * number_bucket #default cache |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 850 | #add 2 seconds extra time for switch between the channel for connection scan |
Mitchell Wills | 78aaeca | 2015-12-07 18:03:00 -0800 | [diff] [blame] | 851 | #multiply cache time by two to account for scheduler changing period |
| 852 | wait_time = (time_cache * 2 + scan_time) / 1000 + self.leeway + 2 |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 853 | result_flag = 0 |
| 854 | try: |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 855 | 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 Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame] | 877 | wutils.validate_connection(self.dut, self.ping_addr), |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 878 | "Error, No internet connection for current network") |
| 879 | elif snumber == 3: |
| 880 | self.log.info("Kicking PNO for reference network") |
Bindu Mahadev | 06fb2e1 | 2017-06-06 15:45:34 -0700 | [diff] [blame] | 881 | self.attenuators[ATTENUATOR].set_atten(90) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 882 | 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 Mahadev | 06fb2e1 | 2017-06-06 15:45:34 -0700 | [diff] [blame] | 893 | self.attenuators[ATTENUATOR].set_atten(0) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 894 | 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 Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame] | 909 | wutils.validate_connection(self.dut, self.ping_addr), |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 910 | "Error, No internet connection for current network") |
| 911 | wutils.wifi_forget_network(self.dut, |
Bindu Mahadev | 06fb2e1 | 2017-06-06 15:45:34 -0700 | [diff] [blame] | 912 | self.reference_networks[0]["2g"]["SSID"]) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 913 | except queue.Empty as error: |
| 914 | raise AssertionError( |
| 915 | "Event did not triggered for batch scan {}".format(error)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 916 | finally: |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 917 | self.dut.droid.wifiScannerStopBackgroundScan(idx) |
| 918 | self.dut.ed.clear_all_events() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 919 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 920 | @test_tracker_info(uuid="7c25ce32-0fae-4a68-a7cb-fdf6d4d03caf") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 921 | 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 929 | scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN, |
| 930 | "periodInMs": SCANTIME, |
| 931 | "reportEvents": |
| 932 | wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN} |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 933 | self.wifi_scanner_single_scan(scan_setting) |
| 934 | |
xshu | aabcfeb | 2018-02-14 11:43:24 -0800 | [diff] [blame] | 935 | @test_tracker_info(uuid="7c8da0c4-dec7-4d04-abd4-f8ea467a5c6d") |
lutina | f02723f | 2020-03-24 19:22:47 +0800 | [diff] [blame] | 936 | @WifiBaseTest.wifi_test_wrap |
xshu | aabcfeb | 2018-02-14 11:43:24 -0800 | [diff] [blame] | 937 | 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") |
lutina | f02723f | 2020-03-24 19:22:47 +0800 | [diff] [blame] | 956 | @WifiBaseTest.wifi_test_wrap |
xshu | aabcfeb | 2018-02-14 11:43:24 -0800 | [diff] [blame] | 957 | 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") |
lutina | f02723f | 2020-03-24 19:22:47 +0800 | [diff] [blame] | 976 | @WifiBaseTest.wifi_test_wrap |
xshu | aabcfeb | 2018-02-14 11:43:24 -0800 | [diff] [blame] | 977 | 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 Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 995 | @test_tracker_info(uuid="e9f3aaad-4af3-4c54-9829-65dc1d6d4987") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 996 | 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1004 | scan_setting = {"channels": self.wifi_chs.MIX_CHANNEL_SCAN, |
| 1005 | "periodInMs": SCANTIME, |
| 1006 | "reportEvents": |
| 1007 | wutils.WifiEnums.REPORT_EVENT_AFTER_BUFFER_FULL} |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1008 | self.wifi_scanner_batch_scan(scan_setting) |
| 1009 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 1010 | @test_tracker_info(uuid="49ba245a-52e2-4c9b-90ad-a2fbc97e3d9f") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1011 | 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1016 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1021 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 1022 | @test_tracker_info(uuid="6fe45cd7-4fac-4ddd-a950-b9431e68f735") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1023 | 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1033 | data = wutils.start_wifi_single_scan(self.dut, |
| 1034 | self.default_scan_setting) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1035 | idx = data["Index"] |
| 1036 | scan_rt = data["ScanElapsedRealtime"] |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1037 | self.log.info("Wifi single shot scan started with index: {}".format( |
| 1038 | idx)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1039 | results = [] |
| 1040 | #generating event wait time from scan setting plus leeway |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1041 | 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 Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1044 | try: |
| 1045 | event_name = "{}{}onResults".format(EVENT_TAG, idx) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1046 | self.log.debug("Waiting for event: {} for time {}".format( |
| 1047 | event_name, wait_time)) |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 1048 | event = self.dut.ed.pop_event(event_name, wait_time) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1049 | self.log.debug("Event received: {}".format(event)) |
| 1050 | results = event["data"]["Results"] |
Mitchell Wills | fc4879e | 2016-05-02 15:50:54 -0700 | [diff] [blame] | 1051 | for batch in results: |
Ang Li | f6a397d | 2016-06-20 18:47:56 -0700 | [diff] [blame] | 1052 | asserts.assert_false(batch["ScanResults"], |
| 1053 | "Test fail because report scan " |
| 1054 | "results reported are not empty") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1055 | except queue.Empty as error: |
| 1056 | raise AssertionError( |
| 1057 | "Event did not triggered for in isolated environment {}".format( |
| 1058 | error)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1059 | finally: |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 1060 | self.dut.ed.clear_all_events() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1061 | self.attenuators[0].set_atten(0) |
| 1062 | self.attenuators[1].set_atten(0) |
| 1063 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 1064 | @test_tracker_info(uuid="46f817b9-97a3-455e-af2c-56f9aea64f7e") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1065 | 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1073 | wutils.wifi_toggle_state(self.dut, False) |
| 1074 | self.start_wifi_scanner_single_scan_expect_failure( |
| 1075 | self.default_scan_setting) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1076 | self.log.debug("Turning wifi back on.") |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1077 | wutils.wifi_toggle_state(self.dut, True) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1078 | |
Girish Moturu | 00304f8 | 2017-04-13 09:28:37 +0530 | [diff] [blame] | 1079 | @test_tracker_info(uuid="257ad734-c21f-49f4-b448-3986b70eba3d") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1080 | 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 Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1090 | "band": wutils.WifiEnums.WIFI_BAND_BOTH_WITH_DFS, |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1091 | "periodInMs": SCANTIME, |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1092 | "reportEvents": wutils.WifiEnums.REPORT_EVENT_AFTER_EACH_SCAN, |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1093 | 'numBssidsPerScan': 33 |
| 1094 | } |
| 1095 | self.wifi_scanner_single_scan(scan_setting) |
Ang Li | 2d3fe98 | 2016-06-08 10:00:43 -0700 | [diff] [blame] | 1096 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 1097 | """ Tests End """ |