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