1#!/usr/bin/env python3.4 2# 3# Copyright 2016 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import itertools 18import pprint 19import queue 20import time 21 22import acts.base_test 23import acts.signals as signals 24import acts.test_utils.wifi.wifi_test_utils as wutils 25import acts.utils 26 27from acts import asserts 28from acts.test_decorators import test_tracker_info 29from acts.test_utils.bt.bt_test_utils import enable_bluetooth 30from acts.test_utils.bt.bt_test_utils import disable_bluetooth 31from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest 32 33WifiEnums = wutils.WifiEnums 34# Default timeout used for reboot, toggle WiFi and Airplane mode, 35# for the system to settle down after the operation. 36DEFAULT_TIMEOUT = 10 37BAND_2GHZ = 0 38BAND_5GHZ = 1 39 40 41class WifiManagerTest(WifiBaseTest): 42 """Tests for APIs in Android's WifiManager class. 43 44 Test Bed Requirement: 45 * Two Android device 46 * Several Wi-Fi networks visible to the device, including an open Wi-Fi 47 network. 48 """ 49 50 def __init__(self, controllers): 51 WifiBaseTest.__init__(self, controllers) 52 53 def setup_class(self): 54 self.dut = self.android_devices[0] 55 self.dut_client = self.android_devices[1] 56 wutils.wifi_test_device_init(self.dut) 57 wutils.wifi_test_device_init(self.dut_client) 58 req_params = [] 59 opt_param = [ 60 "open_network", "reference_networks", "iperf_server_address", 61 "wpa_networks", "wep_networks" 62 ] 63 self.unpack_userparams( 64 req_param_names=req_params, opt_param_names=opt_param) 65 66 if "AccessPoint" in self.user_params: 67 self.legacy_configure_ap_and_start(wpa_network=True, wep_network=True) 68 69 asserts.assert_true( 70 len(self.reference_networks) > 0, 71 "Need at least one reference network with psk.") 72 wutils.wifi_toggle_state(self.dut, True) 73 wutils.wifi_toggle_state(self.dut_client, True) 74 if "iperf_server_address" in self.user_params: 75 self.iperf_server = self.iperf_servers[0] 76 self.wpapsk_2g = self.reference_networks[0]["2g"] 77 self.wpapsk_5g = self.reference_networks[0]["5g"] 78 self.open_network_2g = self.open_network[0]["2g"] 79 self.open_network_5g = self.open_network[0]["5g"] 80 if hasattr(self, 'iperf_server'): 81 self.iperf_server.start() 82 83 def setup_test(self): 84 for ad in self.android_devices: 85 ad.droid.wakeLockAcquireBright() 86 ad.droid.wakeUpNow() 87 wutils.wifi_toggle_state(self.dut, True) 88 89 def teardown_test(self): 90 for ad in self.android_devices: 91 ad.droid.wakeLockRelease() 92 ad.droid.goToSleepNow() 93 self.turn_location_off_and_scan_toggle_off() 94 wutils.reset_wifi(self.dut) 95 wutils.reset_wifi(self.dut_client) 96 97 def teardown_class(self): 98 if hasattr(self, 'iperf_server'): 99 self.iperf_server.stop() 100 101 def on_fail(self, test_name, begin_time): 102 self.dut.take_bug_report(test_name, begin_time) 103 self.dut.cat_adb_log(test_name, begin_time) 104 105 def teardown_class(self): 106 if "AccessPoint" in self.user_params: 107 del self.user_params["reference_networks"] 108 del self.user_params["open_network"] 109 110 """Helper Functions""" 111 112 def connect_to_wifi_network(self, params): 113 """Connection logic for open and psk wifi networks. 114 115 Args: 116 params: A tuple of network info and AndroidDevice object. 117 """ 118 network, ad = params 119 droid = ad.droid 120 ed = ad.ed 121 SSID = network[WifiEnums.SSID_KEY] 122 wutils.start_wifi_connection_scan_and_ensure_network_found( 123 ad, SSID); 124 wutils.wifi_connect(ad, network, num_of_tries=3) 125 126 def get_connection_data(self, dut, network): 127 """Get network id and ssid info from connection data. 128 129 Args: 130 dut: The Android device object under test. 131 network: dict representing the network to connect to. 132 133 Returns: 134 A convenience dict with the connected network's ID and SSID. 135 136 """ 137 params = (network, dut) 138 self.connect_to_wifi_network(params) 139 connect_data = dut.droid.wifiGetConnectionInfo() 140 ssid_id_dict = dict() 141 ssid_id_dict[WifiEnums.NETID_KEY] = connect_data[WifiEnums.NETID_KEY] 142 ssid_id_dict[WifiEnums.SSID_KEY] = connect_data[WifiEnums.SSID_KEY] 143 return ssid_id_dict 144 145 def connect_multiple_networks(self, dut): 146 """Connect to one 2.4GHz and one 5Ghz network. 147 148 Args: 149 dut: The Android device object under test. 150 151 Returns: 152 A list with the connection details for the 2GHz and 5GHz networks. 153 154 """ 155 network_list = list() 156 connect_2g_data = self.get_connection_data(dut, self.wpapsk_2g) 157 network_list.append(connect_2g_data) 158 connect_5g_data = self.get_connection_data(dut, self.wpapsk_5g) 159 network_list.append(connect_5g_data) 160 return network_list 161 162 def get_enabled_network(self, network1, network2): 163 """Check network status and return currently unconnected network. 164 165 Args: 166 network1: dict representing a network. 167 network2: dict representing a network. 168 169 Return: 170 Network dict of the unconnected network. 171 172 """ 173 wifi_info = self.dut.droid.wifiGetConnectionInfo() 174 enabled = network1 175 if wifi_info[WifiEnums.SSID_KEY] == network1[WifiEnums.SSID_KEY]: 176 enabled = network2 177 return enabled 178 179 def check_configstore_networks(self, networks): 180 """Verify that all previously configured networks are presistent after 181 reboot. 182 183 Args: 184 networks: List of network dicts. 185 186 Return: 187 None. Raises TestFailure. 188 189 """ 190 network_info = self.dut.droid.wifiGetConfiguredNetworks() 191 if len(network_info) != len(networks): 192 msg = ( 193 "Length of configured networks before and after reboot don't" 194 " match. \nBefore reboot = %s \n After reboot = %s" % 195 (networks, network_info)) 196 raise signals.TestFailure(msg) 197 current_count = 0 198 # For each network, check if it exists in configured list after reboot 199 for network in networks: 200 exists = wutils.match_networks({ 201 WifiEnums.SSID_KEY: network[WifiEnums.SSID_KEY] 202 }, network_info) 203 if not len(exists): 204 raise signals.TestFailure("%s network is not present in the" 205 " configured list after reboot" % 206 network[WifiEnums.SSID_KEY]) 207 # Get the new network id for each network after reboot. 208 network[WifiEnums.NETID_KEY] = exists[0]['networkId'] 209 if exists[0]['status'] == 'CURRENT': 210 current_count += 1 211 # At any given point, there can only be one currently active 212 # network, defined with 'status':'CURRENT' 213 if current_count > 1: 214 raise signals.TestFailure("More than one network showing" 215 "as 'CURRENT' after reboot") 216 217 def connect_to_wifi_network_with_id(self, network_id, network_ssid): 218 """Connect to the given network using network id and verify SSID. 219 220 Args: 221 network_id: int Network Id of the network. 222 network_ssid: string SSID of the network. 223 224 Returns: True if connect using network id was successful; 225 False otherwise. 226 227 """ 228 wutils.start_wifi_connection_scan_and_ensure_network_found( 229 self.dut, network_ssid); 230 wutils.wifi_connect_by_id(self.dut, network_id) 231 connect_data = self.dut.droid.wifiGetConnectionInfo() 232 connect_ssid = connect_data[WifiEnums.SSID_KEY] 233 self.log.debug("Expected SSID = %s Connected SSID = %s" % 234 (network_ssid, connect_ssid)) 235 if connect_ssid != network_ssid: 236 return False 237 return True 238 239 def run_iperf_client(self, params): 240 """Run iperf traffic after connection. 241 242 Args: 243 params: A tuple of network info and AndroidDevice object. 244 """ 245 if "iperf_server_address" in self.user_params: 246 wait_time = 5 247 network, ad = params 248 SSID = network[WifiEnums.SSID_KEY] 249 self.log.info("Starting iperf traffic through {}".format(SSID)) 250 time.sleep(wait_time) 251 port_arg = "-p {}".format(self.iperf_server.port) 252 success, data = ad.run_iperf_client(self.iperf_server_address, 253 port_arg) 254 self.log.debug(pprint.pformat(data)) 255 asserts.assert_true(success, "Error occurred in iPerf traffic.") 256 257 def connect_to_wifi_network_toggle_wifi_and_run_iperf(self, params): 258 """ Connect to the provided network and then toggle wifi mode and wait 259 for reconnection to the provided network. 260 261 Logic steps are 262 1. Connect to the network. 263 2. Turn wifi off. 264 3. Turn wifi on. 265 4. Wait for connection to the network. 266 5. Run iperf traffic. 267 268 Args: 269 params: A tuple of network info and AndroidDevice object. 270 """ 271 network, ad = params 272 self.connect_to_wifi_network(params) 273 wutils.toggle_wifi_and_wait_for_reconnection( 274 ad, network, num_of_tries=5) 275 self.run_iperf_client(params) 276 277 def run_iperf(self, iperf_args): 278 if "iperf_server_address" not in self.user_params: 279 self.log.error(("Missing iperf_server_address. " 280 "Provide one in config.")) 281 else: 282 iperf_addr = self.user_params["iperf_server_address"] 283 self.log.info("Running iperf client.") 284 result, data = self.dut.run_iperf_client(iperf_addr, iperf_args) 285 self.log.debug(data) 286 287 def run_iperf_rx_tx(self, time, omit=10): 288 args = "-p {} -t {} -O 10".format(self.iperf_server.port, time, omit) 289 self.log.info("Running iperf client {}".format(args)) 290 self.run_iperf(args) 291 args = "-p {} -t {} -O 10 -R".format(self.iperf_server.port, time, 292 omit) 293 self.log.info("Running iperf client {}".format(args)) 294 self.run_iperf(args) 295 296 def get_energy_info(self): 297 """ Steps: 298 1. Check that the WiFi energy info reporting support on this device 299 is as expected (support or not). 300 2. If the device does not support energy info reporting as 301 expected, skip the test. 302 3. Call API to get WiFi energy info. 303 4. Verify the values of "ControllerEnergyUsed" and 304 "ControllerIdleTimeMillis" in energy info don't decrease. 305 5. Repeat from Step 3 for 10 times. 306 """ 307 # Check if dut supports energy info reporting. 308 actual_support = self.dut.droid.wifiIsEnhancedPowerReportingSupported() 309 model = self.dut.model 310 if not actual_support: 311 asserts.skip( 312 ("Device %s does not support energy info reporting as " 313 "expected.") % model) 314 # Verify reported values don't decrease. 315 self.log.info(("Device %s supports energy info reporting, verify that " 316 "the reported values don't decrease.") % model) 317 energy = 0 318 idle_time = 0 319 for i in range(10): 320 info = self.dut.droid.wifiGetControllerActivityEnergyInfo() 321 self.log.debug("Iteration %d, got energy info: %s" % (i, info)) 322 new_energy = info["ControllerEnergyUsed"] 323 new_idle_time = info["ControllerIdleTimeMillis"] 324 asserts.assert_true(new_energy >= energy, 325 "Energy value decreased: previous %d, now %d" % 326 (energy, new_energy)) 327 energy = new_energy 328 asserts.assert_true(new_idle_time >= idle_time, 329 "Idle time decreased: previous %d, now %d" % ( 330 idle_time, new_idle_time)) 331 idle_time = new_idle_time 332 wutils.start_wifi_connection_scan(self.dut) 333 334 def turn_location_on_and_scan_toggle_on(self): 335 """ Turns on wifi location scans. 336 """ 337 acts.utils.set_location_service(self.dut, True) 338 self.dut.droid.wifiScannerToggleAlwaysAvailable(True) 339 msg = "Failed to turn on location service's scan." 340 asserts.assert_true(self.dut.droid.wifiScannerIsAlwaysAvailable(), msg) 341 342 def turn_location_off_and_scan_toggle_off(self): 343 """ Turns off wifi location scans. 344 """ 345 acts.utils.set_location_service(self.dut, False) 346 self.dut.droid.wifiScannerToggleAlwaysAvailable(False) 347 msg = "Failed to turn off location service's scan." 348 asserts.assert_true(not self.dut.droid.wifiScannerIsAlwaysAvailable(), msg) 349 350 def turn_location_on_and_scan_toggle_off(self): 351 """ Turns off wifi location scans, but keeps location on. 352 """ 353 acts.utils.set_location_service(self.dut, True) 354 self.dut.droid.wifiScannerToggleAlwaysAvailable(False) 355 msg = "Failed to turn off location service's scan." 356 asserts.assert_true(not self.dut.droid.wifiScannerIsAlwaysAvailable(), msg) 357 358 def helper_reconnect_toggle_wifi(self): 359 """Connect to multiple networks, turn off/on wifi, then reconnect to 360 a previously connected network. 361 362 Steps: 363 1. Connect to a 2GHz network. 364 2. Connect to a 5GHz network. 365 3. Turn WiFi OFF/ON. 366 4. Reconnect to the non-current network. 367 368 """ 369 connect_2g_data = self.get_connection_data(self.dut, self.wpapsk_2g) 370 connect_5g_data = self.get_connection_data(self.dut, self.wpapsk_5g) 371 wutils.toggle_wifi_off_and_on(self.dut) 372 reconnect_to = self.get_enabled_network(connect_2g_data, 373 connect_5g_data) 374 reconnect = self.connect_to_wifi_network_with_id( 375 reconnect_to[WifiEnums.NETID_KEY], 376 reconnect_to[WifiEnums.SSID_KEY]) 377 if not reconnect: 378 raise signals.TestFailure("Device did not connect to the correct" 379 " network after toggling WiFi.") 380 381 def helper_reconnect_toggle_airplane(self): 382 """Connect to multiple networks, turn on/off Airplane moce, then 383 reconnect a previously connected network. 384 385 Steps: 386 1. Connect to a 2GHz network. 387 2. Connect to a 5GHz network. 388 3. Turn ON/OFF Airplane mode. 389 4. Reconnect to the non-current network. 390 391 """ 392 connect_2g_data = self.get_connection_data(self.dut, self.wpapsk_2g) 393 connect_5g_data = self.get_connection_data(self.dut, self.wpapsk_5g) 394 wutils.toggle_airplane_mode_on_and_off(self.dut) 395 reconnect_to = self.get_enabled_network(connect_2g_data, 396 connect_5g_data) 397 reconnect = self.connect_to_wifi_network_with_id( 398 reconnect_to[WifiEnums.NETID_KEY], 399 reconnect_to[WifiEnums.SSID_KEY]) 400 if not reconnect: 401 raise signals.TestFailure("Device did not connect to the correct" 402 " network after toggling Airplane mode.") 403 404 def helper_reboot_configstore_reconnect(self): 405 """Connect to multiple networks, reboot then reconnect to previously 406 connected network. 407 408 Steps: 409 1. Connect to a 2GHz network. 410 2. Connect to a 5GHz network. 411 3. Reboot device. 412 4. Verify all networks are persistent after reboot. 413 5. Reconnect to the non-current network. 414 415 """ 416 network_list = self.connect_multiple_networks(self.dut) 417 self.dut.reboot() 418 time.sleep(DEFAULT_TIMEOUT) 419 self.check_configstore_networks(network_list) 420 421 reconnect_to = self.get_enabled_network(network_list[BAND_2GHZ], 422 network_list[BAND_5GHZ]) 423 424 reconnect = self.connect_to_wifi_network_with_id( 425 reconnect_to[WifiEnums.NETID_KEY], 426 reconnect_to[WifiEnums.SSID_KEY]) 427 if not reconnect: 428 raise signals.TestFailure( 429 "Device failed to reconnect to the correct" 430 " network after reboot.") 431 432 def helper_toggle_wifi_reboot_configstore_reconnect(self): 433 """Connect to multiple networks, disable WiFi, reboot, then 434 reconnect to previously connected network. 435 436 Steps: 437 1. Connect to a 2GHz network. 438 2. Connect to a 5GHz network. 439 3. Turn WiFi OFF. 440 4. Reboot device. 441 5. Turn WiFi ON. 442 4. Verify all networks are persistent after reboot. 443 5. Reconnect to the non-current network. 444 445 """ 446 network_list = self.connect_multiple_networks(self.dut) 447 self.log.debug("Toggling wifi OFF") 448 wutils.wifi_toggle_state(self.dut, False) 449 time.sleep(DEFAULT_TIMEOUT) 450 self.dut.reboot() 451 time.sleep(DEFAULT_TIMEOUT) 452 self.log.debug("Toggling wifi ON") 453 wutils.wifi_toggle_state(self.dut, True) 454 time.sleep(DEFAULT_TIMEOUT) 455 self.check_configstore_networks(network_list) 456 reconnect_to = self.get_enabled_network(network_list[BAND_2GHZ], 457 network_list[BAND_5GHZ]) 458 reconnect = self.connect_to_wifi_network_with_id( 459 reconnect_to[WifiEnums.NETID_KEY], 460 reconnect_to[WifiEnums.SSID_KEY]) 461 if not reconnect: 462 msg = ("Device failed to reconnect to the correct network after" 463 " toggling WiFi and rebooting.") 464 raise signals.TestFailure(msg) 465 466 def helper_toggle_airplane_reboot_configstore_reconnect(self): 467 """Connect to multiple networks, enable Airplane mode, reboot, then 468 reconnect to previously connected network. 469 470 Steps: 471 1. Connect to a 2GHz network. 472 2. Connect to a 5GHz network. 473 3. Toggle Airplane mode ON. 474 4. Reboot device. 475 5. Toggle Airplane mode OFF. 476 4. Verify all networks are persistent after reboot. 477 5. Reconnect to the non-current network. 478 479 """ 480 network_list = self.connect_multiple_networks(self.dut) 481 self.log.debug("Toggling Airplane mode ON") 482 asserts.assert_true( 483 acts.utils.force_airplane_mode(self.dut, True), 484 "Can not turn on airplane mode on: %s" % self.dut.serial) 485 time.sleep(DEFAULT_TIMEOUT) 486 self.dut.reboot() 487 time.sleep(DEFAULT_TIMEOUT) 488 self.log.debug("Toggling Airplane mode OFF") 489 asserts.assert_true( 490 acts.utils.force_airplane_mode(self.dut, False), 491 "Can not turn on airplane mode on: %s" % self.dut.serial) 492 time.sleep(DEFAULT_TIMEOUT) 493 self.check_configstore_networks(network_list) 494 reconnect_to = self.get_enabled_network(network_list[BAND_2GHZ], 495 network_list[BAND_5GHZ]) 496 reconnect = self.connect_to_wifi_network_with_id( 497 reconnect_to[WifiEnums.NETID_KEY], 498 reconnect_to[WifiEnums.SSID_KEY]) 499 if not reconnect: 500 msg = ("Device failed to reconnect to the correct network after" 501 " toggling Airplane mode and rebooting.") 502 raise signals.TestFailure(msg) 503 504 """Tests""" 505 506 @test_tracker_info(uuid="525fc5e3-afba-4bfd-9a02-5834119e3c66") 507 def test_toggle_wifi_state_and_get_startupTime(self): 508 """Test toggling wifi""" 509 self.log.debug("Going from on to off.") 510 wutils.wifi_toggle_state(self.dut, False) 511 self.log.debug("Going from off to on.") 512 startTime = time.time() 513 wutils.wifi_toggle_state(self.dut, True) 514 startup_time = time.time() - startTime 515 self.log.debug("WiFi was enabled on the device in %s s." % startup_time) 516 517 @test_tracker_info(uuid="e9d11563-2bbe-4c96-87eb-ec919b51435b") 518 def test_toggle_with_screen(self): 519 """Test toggling wifi with screen on/off""" 520 wait_time = 5 521 self.log.debug("Screen from off to on.") 522 self.dut.droid.wakeLockAcquireBright() 523 self.dut.droid.wakeUpNow() 524 time.sleep(wait_time) 525 self.log.debug("Going from on to off.") 526 try: 527 wutils.wifi_toggle_state(self.dut, False) 528 time.sleep(wait_time) 529 self.log.debug("Going from off to on.") 530 wutils.wifi_toggle_state(self.dut, True) 531 finally: 532 self.dut.droid.wakeLockRelease() 533 time.sleep(wait_time) 534 self.dut.droid.goToSleepNow() 535 536 @test_tracker_info(uuid="71556e06-7fb1-4e2b-9338-b01f1f8e286e") 537 def test_scan(self): 538 """Test wifi connection scan can start and find expected networks.""" 539 ssid = self.open_network_2g[WifiEnums.SSID_KEY] 540 wutils.start_wifi_connection_scan_and_ensure_network_found( 541 self.dut, ssid) 542 ssid = self.open_network_5g[WifiEnums.SSID_KEY] 543 wutils.start_wifi_connection_scan_and_ensure_network_found( 544 self.dut, ssid) 545 546 @test_tracker_info(uuid="3ea09efb-6921-429e-afb1-705ef5a09afa") 547 def test_scan_with_wifi_off_and_location_scan_on(self): 548 """Put wifi in scan only mode""" 549 self.turn_location_on_and_scan_toggle_on() 550 wutils.wifi_toggle_state(self.dut, False) 551 552 """Test wifi connection scan can start and find expected networks.""" 553 ssid = self.open_network_2g[WifiEnums.SSID_KEY] 554 wutils.start_wifi_connection_scan_and_ensure_network_found( 555 self.dut, ssid) 556 ssid = self.open_network_5g[WifiEnums.SSID_KEY] 557 wutils.start_wifi_connection_scan_and_ensure_network_found( 558 self.dut, ssid) 559 560 @test_tracker_info(uuid="770caebe-bcb1-43ac-95b6-5dd52dd90e80") 561 def test_scan_with_wifi_off_and_location_scan_off(self): 562 """Turn off wifi and location scan""" 563 self.turn_location_on_and_scan_toggle_off() 564 wutils.wifi_toggle_state(self.dut, False) 565 566 """Test wifi connection scan should fail.""" 567 self.dut.droid.wifiStartScan() 568 try: 569 self.dut.ed.pop_event("WifiManagerScanResultsAvailable", 60) 570 except queue.Empty: 571 self.log.debug("Wifi scan results not received.") 572 else: 573 asserts.fail("Wi-Fi scan results received") 574 575 @test_tracker_info(uuid="a4ad9930-a8fa-4868-81ed-a79c7483e502") 576 def test_add_network(self): 577 """Test wifi connection scan.""" 578 ssid = self.open_network_2g[WifiEnums.SSID_KEY] 579 nId = self.dut.droid.wifiAddNetwork(self.open_network_2g) 580 asserts.assert_true(nId > -1, "Failed to add network.") 581 configured_networks = self.dut.droid.wifiGetConfiguredNetworks() 582 self.log.debug( 583 ("Configured networks after adding: %s" % configured_networks)) 584 wutils.assert_network_in_list({ 585 WifiEnums.SSID_KEY: ssid 586 }, configured_networks) 587 588 @test_tracker_info(uuid="aca85551-10ba-4007-90d9-08bcdeb16a60") 589 def test_forget_network(self): 590 ssid = self.open_network_2g[WifiEnums.SSID_KEY] 591 nId = self.dut.droid.wifiAddNetwork(self.open_network_2g) 592 asserts.assert_true(nId > -1, "Failed to add network.") 593 configured_networks = self.dut.droid.wifiGetConfiguredNetworks() 594 self.log.debug( 595 ("Configured networks after adding: %s" % configured_networks)) 596 wutils.assert_network_in_list({ 597 WifiEnums.SSID_KEY: ssid 598 }, configured_networks) 599 wutils.wifi_forget_network(self.dut, ssid) 600 configured_networks = self.dut.droid.wifiGetConfiguredNetworks() 601 for nw in configured_networks: 602 asserts.assert_true( 603 nw[WifiEnums.BSSID_KEY] != ssid, 604 "Found forgotten network %s in configured networks." % ssid) 605 606 @test_tracker_info(uuid="b306d65c-6df3-4eb5-a178-6278bdc76c3e") 607 def test_reconnect_to_connected_network(self): 608 """Connect to a network and immediately issue reconnect. 609 610 Steps: 611 1. Connect to a 2GHz network. 612 2. Reconnect to the network using its network id. 613 3. Connect to a 5GHz network. 614 4. Reconnect to the network using its network id. 615 616 """ 617 connect_2g_data = self.get_connection_data(self.dut, self.wpapsk_2g) 618 reconnect_2g = self.connect_to_wifi_network_with_id( 619 connect_2g_data[WifiEnums.NETID_KEY], 620 connect_2g_data[WifiEnums.SSID_KEY]) 621 if not reconnect_2g: 622 raise signals.TestFailure("Device did not connect to the correct" 623 " 2GHz network.") 624 connect_5g_data = self.get_connection_data(self.dut, self.wpapsk_5g) 625 reconnect_5g = self.connect_to_wifi_network_with_id( 626 connect_5g_data[WifiEnums.NETID_KEY], 627 connect_5g_data[WifiEnums.SSID_KEY]) 628 if not reconnect_5g: 629 raise signals.TestFailure("Device did not connect to the correct" 630 " 5GHz network.") 631 632 @test_tracker_info(uuid="3cff17f6-b684-4a95-a438-8272c2ad441d") 633 def test_reconnect_to_previously_connected(self): 634 """Connect to multiple networks and reconnect to the previous network. 635 636 Steps: 637 1. Connect to a 2GHz network. 638 2. Connect to a 5GHz network. 639 3. Reconnect to the 2GHz network using its network id. 640 4. Reconnect to the 5GHz network using its network id. 641 642 """ 643 connect_2g_data = self.get_connection_data(self.dut, self.wpapsk_2g) 644 connect_5g_data = self.get_connection_data(self.dut, self.wpapsk_5g) 645 reconnect_2g = self.connect_to_wifi_network_with_id( 646 connect_2g_data[WifiEnums.NETID_KEY], 647 connect_2g_data[WifiEnums.SSID_KEY]) 648 if not reconnect_2g: 649 raise signals.TestFailure("Device did not connect to the correct" 650 " 2GHz network.") 651 reconnect_5g = self.connect_to_wifi_network_with_id( 652 connect_5g_data[WifiEnums.NETID_KEY], 653 connect_5g_data[WifiEnums.SSID_KEY]) 654 if not reconnect_5g: 655 raise signals.TestFailure("Device did not connect to the correct" 656 " 5GHz network.") 657 658 @test_tracker_info(uuid="334175c3-d26a-4c87-a8ab-8eb220b2d80f") 659 def test_reconnect_toggle_wifi(self): 660 """Connect to multiple networks, turn off/on wifi, then reconnect to 661 a previously connected network. 662 663 Steps: 664 1. Connect to a 2GHz network. 665 2. Connect to a 5GHz network. 666 3. Turn WiFi OFF/ON. 667 4. Reconnect to the non-current network. 668 669 """ 670 self.helper_reconnect_toggle_wifi() 671 672 @test_tracker_info(uuid="bd2cec9e-7f17-44ef-8a0c-4da92a9b55ae") 673 def test_reconnect_toggle_wifi_with_location_scan_on(self): 674 """Connect to multiple networks, turn off/on wifi, then reconnect to 675 a previously connected network. 676 677 Steps: 678 1. Turn on location scans. 679 2. Connect to a 2GHz network. 680 3. Connect to a 5GHz network. 681 4. Turn WiFi OFF/ON. 682 5. Reconnect to the non-current network. 683 684 """ 685 self.turn_location_on_and_scan_toggle_on() 686 self.helper_reconnect_toggle_wifi() 687 688 @test_tracker_info(uuid="8e6e6c21-fefb-4fe8-9fb1-f09b1182b76d") 689 def test_reconnect_toggle_airplane(self): 690 """Connect to multiple networks, turn on/off Airplane moce, then 691 reconnect a previously connected network. 692 693 Steps: 694 1. Connect to a 2GHz network. 695 2. Connect to a 5GHz network. 696 3. Turn ON/OFF Airplane mode. 697 4. Reconnect to the non-current network. 698 699 """ 700 self.helper_reconnect_toggle_airplane() 701 702 @test_tracker_info(uuid="28562f13-8a0a-492e-932c-e587560db5f2") 703 def test_reconnect_toggle_airplane_with_location_scan_on(self): 704 """Connect to multiple networks, turn on/off Airplane moce, then 705 reconnect a previously connected network. 706 707 Steps: 708 1. Turn on location scans. 709 2. Connect to a 2GHz network. 710 3. Connect to a 5GHz network. 711 4. Turn ON/OFF Airplane mode. 712 5. Reconnect to the non-current network. 713 714 """ 715 self.turn_location_on_and_scan_toggle_on() 716 self.helper_reconnect_toggle_airplane() 717 718 @test_tracker_info(uuid="3d041c12-05e2-46a7-ab9b-e3f60cc735db") 719 def test_reboot_configstore_reconnect(self): 720 """Connect to multiple networks, reboot then reconnect to previously 721 connected network. 722 723 Steps: 724 1. Connect to a 2GHz network. 725 2. Connect to a 5GHz network. 726 3. Reboot device. 727 4. Verify all networks are persistent after reboot. 728 5. Reconnect to the non-current network. 729 730 """ 731 self.helper_reboot_configstore_reconnect() 732 733 @test_tracker_info(uuid="a70d5853-67b5-4d48-bdf7-08ee51fafd21") 734 def test_reboot_configstore_reconnect_with_location_scan_on(self): 735 """Connect to multiple networks, reboot then reconnect to previously 736 connected network. 737 738 Steps: 739 1. Turn on location scans. 740 2. Connect to a 2GHz network. 741 3. Connect to a 5GHz network. 742 4. Reboot device. 743 5. Verify all networks are persistent after reboot. 744 6. Reconnect to the non-current network. 745 746 """ 747 self.turn_location_on_and_scan_toggle_on() 748 self.helper_reboot_configstore_reconnect() 749 750 @test_tracker_info(uuid="26d94dfa-1349-4c8b-aea0-475eb73bb521") 751 def test_toggle_wifi_reboot_configstore_reconnect(self): 752 """Connect to multiple networks, disable WiFi, reboot, then 753 reconnect to previously connected network. 754 755 Steps: 756 1. Connect to a 2GHz network. 757 2. Connect to a 5GHz network. 758 3. Turn WiFi OFF. 759 4. Reboot device. 760 5. Turn WiFi ON. 761 4. Verify all networks are persistent after reboot. 762 5. Reconnect to the non-current network. 763 764 """ 765 self.helper_toggle_wifi_reboot_configstore_reconnect() 766 767 @test_tracker_info(uuid="7c004a3b-c1c6-4371-9124-0f34650be915") 768 def test_toggle_wifi_reboot_configstore_reconnect_with_location_scan_on(self): 769 """Connect to multiple networks, disable WiFi, reboot, then 770 reconnect to previously connected network. 771 772 Steps: 773 1. Turn on location scans. 774 2. Connect to a 2GHz network. 775 3. Connect to a 5GHz network. 776 4. Turn WiFi OFF. 777 5. Reboot device. 778 6. Turn WiFi ON. 779 7. Verify all networks are persistent after reboot. 780 8. Reconnect to the non-current network. 781 782 """ 783 self.turn_location_on_and_scan_toggle_on() 784 self.helper_toggle_wifi_reboot_configstore_reconnect() 785 786 @test_tracker_info(uuid="4fce017b-b443-40dc-a598-51d59d3bb38f") 787 def test_toggle_airplane_reboot_configstore_reconnect(self): 788 """Connect to multiple networks, enable Airplane mode, reboot, then 789 reconnect to previously connected network. 790 791 Steps: 792 1. Connect to a 2GHz network. 793 2. Connect to a 5GHz network. 794 3. Toggle Airplane mode ON. 795 4. Reboot device. 796 5. Toggle Airplane mode OFF. 797 4. Verify all networks are persistent after reboot. 798 5. Reconnect to the non-current network. 799 800 """ 801 self.helper_toggle_airplane_reboot_configstore_reconnect() 802 803 @test_tracker_info(uuid="7f0810f9-2338-4158-95f5-057f5a1905b6") 804 def test_toggle_airplane_reboot_configstore_reconnect_with_location_scan_on(self): 805 """Connect to multiple networks, enable Airplane mode, reboot, then 806 reconnect to previously connected network. 807 808 Steps: 809 1. Turn on location scans. 810 2. Connect to a 2GHz network. 811 3. Connect to a 5GHz network. 812 4. Toggle Airplane mode ON. 813 5. Reboot device. 814 6. Toggle Airplane mode OFF. 815 7. Verify all networks are persistent after reboot. 816 8. Reconnect to the non-current network. 817 818 """ 819 self.turn_location_on_and_scan_toggle_on() 820 self.helper_toggle_airplane_reboot_configstore_reconnect() 821 822 @test_tracker_info(uuid="81eb7527-4c92-4422-897a-6b5f6445e84a") 823 def test_config_store_with_wpapsk_2g(self): 824 self.connect_to_wifi_network_toggle_wifi_and_run_iperf( 825 (self.wpapsk_2g, self.dut)) 826 827 @test_tracker_info(uuid="8457903d-cb7e-4c89-bcea-7f59585ea6e0") 828 def test_config_store_with_wpapsk_5g(self): 829 self.connect_to_wifi_network_toggle_wifi_and_run_iperf( 830 (self.wpapsk_5g, self.dut)) 831 832 @test_tracker_info(uuid="b9fbc13a-47b4-4f64-bd2c-e5a3cb24ab2f") 833 def test_tdls_supported(self): 834 model = self.dut.model 835 self.log.debug("Model is %s" % model) 836 if not model.startswith("volantis"): 837 asserts.assert_true(self.dut.droid.wifiIsTdlsSupported(), ( 838 "TDLS should be supported on %s, but device is " 839 "reporting not supported.") % model) 840 else: 841 asserts.assert_false(self.dut.droid.wifiIsTdlsSupported(), ( 842 "TDLS should not be supported on %s, but device " 843 "is reporting supported.") % model) 844 845 @test_tracker_info(uuid="50637d40-ea59-4f4b-9fc1-e6641d64074c") 846 def test_energy_info(self): 847 """Verify the WiFi energy info reporting feature """ 848 self.get_energy_info() 849 850 @test_tracker_info(uuid="1f1cf549-53eb-4f36-9f33-ce06c9158efc") 851 def test_energy_info_connected(self): 852 """Verify the WiFi energy info reporting feature when connected. 853 854 Connect to a wifi network, then the same as test_energy_info. 855 """ 856 wutils.wifi_connect(self.dut, self.open_network_2g) 857 self.get_energy_info() 858 859 @test_tracker_info(uuid="2622c253-defc-4a35-93a6-ca9d29a8238c") 860 def test_connect_to_wep_2g(self): 861 """Verify DUT can connect to 2GHz WEP network 862 863 Steps: 864 1. Ensure the 2GHz WEP network is visible in scan result. 865 2. Connect to the network and validate internet connection. 866 """ 867 wutils.connect_to_wifi_network(self.dut, self.wep_networks[0]["2g"]) 868 869 @test_tracker_info(uuid="1f2d17a2-e92d-43af-966b-3421c0db8620") 870 def test_connect_to_wep_5g(self): 871 """Verify DUT can connect to 5GHz WEP network 872 873 Steps: 874 1. Ensure the 5GHz WEP network is visible in scan result. 875 2. Connect to the network and validate internet connection. 876 """ 877 wutils.connect_to_wifi_network(self.dut, self.wep_networks[0]["5g"]) 878 879 @test_tracker_info(uuid="4a957952-289d-4657-9882-e1475274a7ff") 880 def test_connect_to_wpa_2g(self): 881 """Verify DUT can connect to 2GHz WPA-PSK network 882 883 Steps: 884 1. Ensure the 2GHz WPA-PSK network is visible in scan result. 885 2. Connect to the network and validate internet connection. 886 """ 887 wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0]["2g"]) 888 889 @test_tracker_info(uuid="612c3c31-a4c5-4014-9a2d-3f4bcc20c0d7") 890 def test_connect_to_wpa_5g(self): 891 """Verify DUT can connect to 5GHz WPA-PSK network 892 893 Steps: 894 1. Ensure the 5GHz WPA-PSK network is visible in scan result. 895 2. Connect to the network and validate internet connection. 896 """ 897 wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0]["5g"]) 898 899 @test_tracker_info(uuid="2a617fb4-1d8e-44e9-a500-a5456e1df83f") 900 def test_connect_to_2g_can_be_pinged(self): 901 """Verify DUT can be pinged by another device when it connects to 2GHz AP 902 903 Steps: 904 1. Ensure the 2GHz WPA-PSK network is visible in scan result. 905 2. Connect to the network and validate internet connection. 906 3. Check DUT can be pinged by another device 907 """ 908 wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0]["2g"]) 909 wutils.connect_to_wifi_network(self.dut_client, self.wpa_networks[0]["2g"]) 910 dut_address = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0] 911 asserts.assert_true( 912 acts.utils.adb_shell_ping(self.dut_client, count=10, dest_ip=dut_address, timeout=20), 913 "%s ping %s failed" % (self.dut_client.serial, dut_address)) 914 915 @test_tracker_info(uuid="94bdd657-649b-4a2c-89c3-3ec6ba18e08e") 916 def test_connect_to_5g_can_be_pinged(self): 917 """Verify DUT can be pinged by another device when it connects to 5GHz AP 918 919 Steps: 920 1. Ensure the 5GHz WPA-PSK network is visible in scan result. 921 2. Connect to the network and validate internet connection. 922 3. Check DUT can be pinged by another device 923 """ 924 wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0]["5g"]) 925 wutils.connect_to_wifi_network(self.dut_client, self.wpa_networks[0]["5g"]) 926 dut_address = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0] 927 asserts.assert_true( 928 acts.utils.adb_shell_ping(self.dut_client, count=10, dest_ip=dut_address, timeout=20), 929 "%s ping %s failed" % (self.dut_client.serial, dut_address)) 930 931 @test_tracker_info(uuid="d87359aa-c4da-4554-b5de-8e3fa852a6b0") 932 def test_sta_turn_off_screen_can_be_pinged(self): 933 """Verify DUT can be pinged by another device after idle for a while 934 935 Steps: 936 1. Ensure the 2GHz WPA-PSK network is visible in scan result. 937 2. DUT and DUT_Client connect to the network and validate internet connection. 938 3. Let DUT sleep for 5 minutes 939 4. Check DUT can be pinged by DUT_Client 940 """ 941 # DUT connect to AP 942 wutils.connect_to_wifi_network(self.dut, self.wpa_networks[0]["2g"]) 943 wutils.connect_to_wifi_network(self.dut_client, self.wpa_networks[0]["2g"]) 944 # Check DUT and DUT_Client can ping each other successfully 945 dut_address = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0] 946 dut_client_address = self.dut_client.droid.connectivityGetIPv4Addresses('wlan0')[0] 947 asserts.assert_true( 948 acts.utils.adb_shell_ping(self.dut, count=10, dest_ip=dut_client_address, timeout=20), 949 "ping DUT %s failed" % dut_client_address) 950 asserts.assert_true( 951 acts.utils.adb_shell_ping(self.dut_client, count=10, dest_ip=dut_address, timeout=20), 952 "ping DUT %s failed" % dut_address) 953 # DUT turn off screen and go sleep for 5 mins 954 self.dut.droid.wakeLockRelease() 955 self.dut.droid.goToSleepNow() 956 # TODO(hsiuchangchen): find a way to check system already suspended 957 # instead of waiting 5 mins 958 self.log.info("Sleep for 5 minutes") 959 time.sleep(300) 960 # Verify DUT_Client can ping DUT when DUT sleeps 961 asserts.assert_true( 962 acts.utils.adb_shell_ping(self.dut_client, count=10, dest_ip=dut_address, timeout=20), 963 "ping DUT %s failed" % dut_address) 964 self.dut.droid.wakeLockAcquireBright() 965 self.dut.droid.wakeUpNow() 966 967 @test_tracker_info(uuid="402cfaa8-297f-4865-9e27-6bab6adca756") 968 def test_reboot_wifi_and_bluetooth_on(self): 969 """Toggle WiFi and bluetooth ON then reboot """ 970 wutils.wifi_toggle_state(self.dut, True) 971 enable_bluetooth(self.dut.droid, self.dut.ed) 972 973 self.dut.reboot() 974 time.sleep(DEFAULT_TIMEOUT) 975 976 asserts.assert_true(self.dut.droid.bluetoothCheckState(), 977 "bluetooth state changed after reboot") 978 asserts.assert_true(self.dut.droid.wifiCheckState(), 979 "wifi state changed after reboot") 980 981 disable_bluetooth(self.dut.droid) 982