1# 2# Copyright 2017 - The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import pprint 17import random 18import time 19 20from acts import asserts 21from acts import base_test 22from acts import signals 23from acts.test_decorators import test_tracker_info 24from acts.test_utils.wifi import wifi_test_utils as wutils 25from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest 26 27WifiEnums = wutils.WifiEnums 28 29class WifiRoamingTest(WifiBaseTest): 30 31 def setup_class(self): 32 """Setup required dependencies from config file and configure 33 the required networks for testing roaming. 34 35 Returns: 36 True if successfully configured the requirements for testing. 37 """ 38 super().setup_class() 39 40 self.dut = self.android_devices[0] 41 wutils.wifi_test_device_init(self.dut) 42 req_params = ["roaming_attn", "roam_interval", "ping_addr", 43 "max_bugreports"] 44 opt_param = ["open_network", "reference_networks",] 45 self.unpack_userparams( 46 req_param_names=req_params, opt_param_names=opt_param) 47 48 if "AccessPoint" in self.user_params: 49 self.legacy_configure_ap_and_start(ap_count=2) 50 51 asserts.assert_true( 52 len(self.reference_networks) > 1, 53 "Need at least two psk networks for roaming.") 54 asserts.assert_true( 55 len(self.open_network) > 1, 56 "Need at least two open networks for roaming") 57 wutils.wifi_toggle_state(self.dut, True) 58 59 def teardown_class(self): 60 self.dut.ed.clear_all_events() 61 if "AccessPoint" in self.user_params: 62 del self.user_params["reference_networks"] 63 del self.user_params["open_network"] 64 65 def setup_test(self): 66 self.dut.ed.clear_all_events() 67 self.dut.droid.wakeLockAcquireBright() 68 self.dut.droid.wakeUpNow() 69 70 def teardown_test(self): 71 self.dut.droid.wakeLockRelease() 72 self.dut.droid.goToSleepNow() 73 wutils.reset_wifi(self.dut) 74 75 def on_fail(self, test_name, begin_time): 76 self.dut.cat_adb_log(test_name, begin_time) 77 self.dut.take_bug_report(test_name, begin_time) 78 79 def roaming_from_AP1_and_AP2(self, AP1_network, AP2_network): 80 """Test roaming between two APs. 81 82 Args: 83 AP1_network: AP-1's network information. 84 AP2_network: AP-2's network information. 85 86 Steps: 87 1. Make AP1 visible, AP2 not visible. 88 2. Connect to AP1's ssid. 89 3. Make AP1 not visible, AP2 visible. 90 4. Expect DUT to roam to AP2. 91 5. Validate connection information and ping. 92 """ 93 wutils.set_attns(self.attenuators, "AP1_on_AP2_off") 94 wutils.wifi_connect(self.dut, AP1_network) 95 self.log.info("Roaming from %s to %s", AP1_network, AP2_network) 96 wutils.trigger_roaming_and_validate(self.dut, self.attenuators, 97 "AP1_off_AP2_on", AP2_network) 98 99 """ Tests Begin. 100 101 The following tests are designed to test inter-SSID Roaming only. 102 103 """ 104 @test_tracker_info(uuid="db8a46f9-713f-4b98-8d9f-d36319905b0a") 105 def test_roaming_between_AP1_to_AP2_open_2g(self): 106 AP1_network = self.open_network[0]["2g"] 107 AP2_network = self.open_network[1]["2g"] 108 self.roaming_from_AP1_and_AP2(AP1_network, AP2_network) 109 110 @test_tracker_info(uuid="0db67d9b-6ea9-4f40-acf2-155c4ecf9dc5") 111 def test_roaming_between_AP1_to_AP2_open_5g(self): 112 AP1_network = self.open_network[0]["5g"] 113 AP2_network = self.open_network[1]["5g"] 114 self.roaming_from_AP1_and_AP2(AP1_network, AP2_network) 115 116 @test_tracker_info(uuid="eabc7319-d962-4bef-b679-725e9ff00420") 117 def test_roaming_between_AP1_to_AP2_psk_2g(self): 118 AP1_network = self.reference_networks[0]["2g"] 119 AP2_network = self.reference_networks[1]["2g"] 120 self.roaming_from_AP1_and_AP2(AP1_network, AP2_network) 121 122 @test_tracker_info(uuid="1cf9c681-4ff0-45c1-9719-f01629f6a7f7") 123 def test_roaming_between_AP1_to_AP2_psk_5g(self): 124 AP1_network = self.reference_networks[0]["5g"] 125 AP2_network = self.reference_networks[1]["5g"] 126 self.roaming_from_AP1_and_AP2(AP1_network, AP2_network) 127 128 @test_tracker_info(uuid="3114d625-5cdd-4205-bb46-5a9d057dc80d") 129 def test_roaming_fail_psk_2g(self): 130 network = {'SSID':'test_roaming_fail', 'password':'roam123456@'} 131 # AP2 network with incorrect password. 132 network_fail = {'SSID':'test_roaming_fail', 'password':'roam123456@#$%^'} 133 # Setup AP1 with the correct password. 134 wutils.ap_setup(self, 0, self.access_points[0], network) 135 network_bssid = self.access_points[0].get_bssid_from_ssid( 136 network["SSID"], '2g') 137 # Setup AP2 with the incorrect password. 138 wutils.ap_setup(self, 1, self.access_points[1], network_fail) 139 network_fail_bssid = self.access_points[1].get_bssid_from_ssid( 140 network_fail["SSID"], '2g') 141 network['bssid'] = network_bssid 142 network_fail['bssid'] = network_fail_bssid 143 try: 144 # Initiate roaming with AP2 configured with incorrect password. 145 self.roaming_from_AP1_and_AP2(network, network_fail) 146 except: 147 self.log.info("Roaming failed to AP2 with incorrect password.") 148 # Re-configure AP2 after roaming failed, with correct password. 149 self.log.info("Re-configuring AP2 with correct password.") 150 wutils.ap_setup(self, 1, self.access_points[1], network) 151 self.roaming_from_AP1_and_AP2(network, network_fail) 152 153 """ Tests End """ 154