1 #!/usr/bin/env python3.4 2 # 3 # Copyright 2018 - 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 pprint 19 import queue 20 import time 21 22 import acts.base_test 23 import acts.signals as signals 24 from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G 25 from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G 26 import acts.test_utils.wifi.wifi_test_utils as wutils 27 import acts.utils as utils 28 29 from acts import asserts 30 from acts.test_decorators import test_tracker_info 31 from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest 32 33 WifiEnums = wutils.WifiEnums 34 35 # Channels to configure the AP for various test scenarios. 36 WIFI_NETWORK_AP_CHANNEL_2G = 1 37 WIFI_NETWORK_AP_CHANNEL_5G = 36 38 WIFI_NETWORK_AP_CHANNEL_5G_DFS = 132 39 40 class WifiStaApConcurrencyTest(WifiBaseTest): 41 """Tests for STA + AP concurrency scenarions. 42 43 Test Bed Requirement: 44 * Two Android devices (For AP) 45 * One Wi-Fi network visible to the device (for STA). 46 """ 47 48 def __init__(self, controllers): 49 WifiBaseTest.__init__(self, controllers) 50 51 def setup_class(self): 52 self.dut = self.android_devices[0] 53 self.dut_client = self.android_devices[1] 54 wutils.wifi_test_device_init(self.dut) 55 wutils.wifi_test_device_init(self.dut_client) 56 # Do a simple version of init - mainly just sync the time and enable 57 # verbose logging. This test will fail if the DUT has a sim and cell 58 # data is disabled. We would also like to test with phones in less 59 # constrained states (or add variations where we specifically 60 # constrain). 61 utils.require_sl4a((self.dut, self.dut_client)) 62 utils.sync_device_time(self.dut) 63 utils.sync_device_time(self.dut_client) 64 # Set country code explicitly to "US". 65 self.dut.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US) 66 self.dut_client.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US) 67 # Enable verbose logging on the duts 68 self.dut.droid.wifiEnableVerboseLogging(1) 69 asserts.assert_equal(self.dut.droid.wifiGetVerboseLoggingLevel(), 1, 70 "Failed to enable WiFi verbose logging on the softap dut.") 71 self.dut_client.droid.wifiEnableVerboseLogging(1) 72 asserts.assert_equal(self.dut_client.droid.wifiGetVerboseLoggingLevel(), 1, 73 "Failed to enable WiFi verbose logging on the client dut.") 74 75 req_params = ["AccessPoint", "dbs_supported_models"] 76 opt_param = ["iperf_server_address"] 77 self.unpack_userparams( 78 req_param_names=req_params, opt_param_names=opt_param) 79 80 if self.dut.model not in self.dbs_supported_models: 81 asserts.skip( 82 ("Device %s does not support dual interfaces.") 83 % self.dut.model) 84 85 if "iperf_server_address" in self.user_params: 86 self.iperf_server = self.iperf_servers[0] 87 if hasattr(self, 'iperf_server'): 88 self.iperf_server.start() 89 90 # Set the client wifi state to on before the test begins. 91 wutils.wifi_toggle_state(self.dut_client, True) 92 93 def setup_test(self): 94 self.dut.droid.wakeLockAcquireBright() 95 self.dut.droid.wakeUpNow() 96 self.turn_location_off_and_scan_toggle_off() 97 wutils.wifi_toggle_state(self.dut, False) 98 99 def teardown_test(self): 100 self.dut.droid.wakeLockRelease() 101 self.dut.droid.goToSleepNow() 102 wutils.stop_wifi_tethering(self.dut) 103 wutils.reset_wifi(self.dut) 104 wutils.reset_wifi(self.dut_client) 105 self.access_points[0].close() 106 del self.user_params["reference_networks"] 107 del self.user_params["open_network"] 108 109 def teardown_class(self): 110 if hasattr(self, 'iperf_server'): 111 self.iperf_server.stop() 112 113 def on_fail(self, test_name, begin_time): 114 self.dut.take_bug_report(test_name, begin_time) 115 self.dut.cat_adb_log(test_name, begin_time) 116 117 """Helper Functions""" 118 def configure_ap(self, channel_2g=None, channel_5g=None): 119 """Configure and bring up AP on required channel. 120 121 Args: 122 channel_2g: The channel number to use for 2GHz network. 123 channel_5g: The channel number to use for 5GHz network. 124 125 """ 126 if not channel_2g: 127 self.legacy_configure_ap_and_start(channel_5g=channel_5g) 128 elif not channel_5g: 129 self.legacy_configure_ap_and_start(channel_2g=channel_2g) 130 else: 131 self.legacy_configure_ap_and_start(channel_2g=channel_2g, 132 channel_5g=chanel_5g) 133 self.wpapsk_2g = self.reference_networks[0]["2g"] 134 self.wpapsk_5g = self.reference_networks[0]["5g"] 135 136 def turn_location_on_and_scan_toggle_on(self): 137 """ Turns on wifi location scans. 138 """ 139 acts.utils.set_location_service(self.dut, True) 140 self.dut.droid.wifiScannerToggleAlwaysAvailable(True) 141 msg = "Failed to turn on location service's scan." 142 asserts.assert_true(self.dut.droid.wifiScannerIsAlwaysAvailable(), msg) 143 144 def turn_location_off_and_scan_toggle_off(self): 145 """ Turns off wifi location scans. 146 """ 147 acts.utils.set_location_service(self.dut, False) 148 self.dut.droid.wifiScannerToggleAlwaysAvailable(False) 149 msg = "Failed to turn off location service's scan." 150 asserts.assert_true(not self.dut.droid.wifiScannerIsAlwaysAvailable(), msg) 151 152 def run_iperf_client(self, params): 153 """Run iperf traffic after connection. 154 155 Args: 156 params: A tuple of network info and AndroidDevice object. 157 """ 158 if "iperf_server_address" in self.user_params: 159 wait_time = 5 160 network, ad = params 161 SSID = network[WifiEnums.SSID_KEY] 162 self.log.info("Starting iperf traffic through {}".format(SSID)) 163 time.sleep(wait_time) 164 port_arg = "-p {}".format(self.iperf_server.port) 165 success, data = ad.run_iperf_client(self.iperf_server_address, 166 port_arg) 167 self.log.debug(pprint.pformat(data)) 168 asserts.assert_true(success, "Error occurred in iPerf traffic.") 169 170 def connect_to_wifi_network_and_verify(self, params): 171 """Connection logic for open and psk wifi networks. 172 173 Args: 174 params: A tuple of network info and AndroidDevice object. 175 """ 176 network, ad = params 177 droid = ad.droid 178 ed = ad.ed 179 SSID = network[WifiEnums.SSID_KEY] 180 wutils.start_wifi_connection_scan_and_ensure_network_found( 181 ad, SSID); 182 wutils.wifi_connect(ad, network, num_of_tries=3) 183 184 def confirm_softap_in_scan_results(self, ap_ssid): 185 """Confirm the ap started by wifi tethering is seen in scan results. 186 187 Args: 188 ap_ssid: SSID of the ap we are looking for. 189 """ 190 wutils.start_wifi_connection_scan_and_ensure_network_found( 191 self.dut_client, ap_ssid); 192 193 def create_softap_config(self): 194 """Create a softap config with ssid and password.""" 195 ap_ssid = "softap_" + utils.rand_ascii_str(8) 196 ap_password = utils.rand_ascii_str(8) 197 self.dut.log.info("softap setup: %s %s", ap_ssid, ap_password) 198 config = {wutils.WifiEnums.SSID_KEY: ap_ssid} 199 config[wutils.WifiEnums.PWD_KEY] = ap_password 200 return config 201 202 def start_softap_and_verify(self, band): 203 """Test startup of softap 204 205 1. Brinup AP mode. 206 2. Verify SoftAP active using the client device. 207 """ 208 config = self.create_softap_config() 209 wutils.start_wifi_tethering(self.dut, 210 config[wutils.WifiEnums.SSID_KEY], 211 config[wutils.WifiEnums.PWD_KEY], band) 212 self.confirm_softap_in_scan_results(config[wutils.WifiEnums.SSID_KEY]) 213 214 def connect_to_wifi_network_and_start_softap(self, nw_params, softap_band): 215 """Test concurrenct wifi connection and softap. 216 This helper method first makes a wifi conenction and then starts SoftAp. 217 218 Args: 219 nw_params: Params for network STA connection. 220 softap_band: Band for the AP. 221 222 1. Bring up wifi. 223 2. Establish connection to a network. 224 3. Bring up softap and verify AP is seen on a client device. 225 4. Run iperf on the wifi connection to the network. 226 """ 227 wutils.wifi_toggle_state(self.dut, True) 228 self.connect_to_wifi_network_and_verify((nw_params, self.dut)) 229 self.start_softap_and_verify(softap_band) 230 self.run_iperf_client((nw_params, self.dut)) 231 # Verify that both softap & wifi is enabled concurrently. 232 self.verify_wifi_and_softap_enabled() 233 234 def start_softap_and_connect_to_wifi_network(self, nw_params, softap_band): 235 """Test concurrenct wifi connection and softap. 236 This helper method first starts SoftAp and then makes a wifi conenction. 237 238 Args: 239 nw_params: Params for network STA connection. 240 softap_band: Band for the AP. 241 242 1. Bring up softap and verify AP is seen on a client device. 243 2. Bring up wifi. 244 3. Establish connection to a network. 245 4. Run iperf on the wifi connection to the network. 246 """ 247 self.start_softap_and_verify(softap_band) 248 wutils.wifi_toggle_state(self.dut, True) 249 self.connect_to_wifi_network_and_verify((nw_params, self.dut)) 250 self.run_iperf_client((nw_params, self.dut)) 251 # Verify that both softap & wifi is enabled concurrently. 252 self.verify_wifi_and_softap_enabled() 253 254 def verify_wifi_and_softap_enabled(self): 255 """Helper to verify both wifi and softap is enabled 256 """ 257 asserts.assert_true(self.dut.droid.wifiCheckState(), 258 "Wifi is not reported as running"); 259 asserts.assert_true(self.dut.droid.wifiIsApEnabled(), 260 "SoftAp is not reported as running") 261 262 """Tests""" 263 @test_tracker_info(uuid="c396e7ac-cf22-4736-a623-aa6d3c50193a") 264 def test_wifi_connection_2G_softap_2G(self): 265 """Tests connection to 2G network followed by bringing up SoftAp on 2G. 266 """ 267 self.configure_ap(channel_2g=WIFI_NETWORK_AP_CHANNEL_2G) 268 self.connect_to_wifi_network_and_start_softap( 269 self.wpapsk_2g, WIFI_CONFIG_APBAND_2G) 270 271 @test_tracker_info(uuid="1cd6120d-3db4-4624-9bae-55c976533a48") 272 def test_wifi_connection_5G_softap_5G(self): 273 """Tests connection to 5G network followed by bringing up SoftAp on 5G. 274 """ 275 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G) 276 self.connect_to_wifi_network_and_start_softap( 277 self.wpapsk_5g, WIFI_CONFIG_APBAND_5G) 278 279 @test_tracker_info(uuid="5f980007-3490-413e-b94e-7700ffab8534") 280 def test_wifi_connection_5G_DFS_softap_5G(self): 281 """Tests connection to 5G DFS network followed by bringing up SoftAp on 5G. 282 """ 283 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G_DFS) 284 self.connect_to_wifi_network_and_start_softap( 285 self.wpapsk_5g, WIFI_CONFIG_APBAND_5G) 286 287 @test_tracker_info(uuid="d05d5d44-c738-4372-9f01-ce2a640a2f25") 288 def test_wifi_connection_5G_softap_2G(self): 289 """Tests connection to 5G network followed by bringing up SoftAp on 2G. 290 """ 291 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G) 292 self.connect_to_wifi_network_and_start_softap( 293 self.wpapsk_5g, WIFI_CONFIG_APBAND_2G) 294 295 @test_tracker_info(uuid="909ac713-1ad3-4dad-9be3-ad60f00ed25e") 296 def test_wifi_connection_5G_DFS_softap_2G(self): 297 """Tests connection to 5G DFS network followed by bringing up SoftAp on 2G. 298 """ 299 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G_DFS) 300 self.connect_to_wifi_network_and_start_softap( 301 self.wpapsk_5g, WIFI_CONFIG_APBAND_2G) 302 303 @test_tracker_info(uuid="e8de724a-25d3-4801-94cc-22e9e0ecc8d1") 304 def test_wifi_connection_2G_softap_5G(self): 305 """Tests connection to 2G network followed by bringing up SoftAp on 5G. 306 """ 307 self.configure_ap(channel_2g=WIFI_NETWORK_AP_CHANNEL_2G) 308 self.connect_to_wifi_network_and_start_softap( 309 self.wpapsk_2g, WIFI_CONFIG_APBAND_5G) 310 311 @test_tracker_info(uuid="647f4e17-5c7a-4249-98af-f791d163a39f") 312 def test_wifi_connection_5G_softap_2G_with_location_scan_on(self): 313 """Tests connection to 5G network followed by bringing up SoftAp on 2G 314 with location scans turned on. 315 """ 316 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G) 317 self.turn_location_on_and_scan_toggle_on() 318 self.connect_to_wifi_network_and_start_softap( 319 self.wpapsk_5g, WIFI_CONFIG_APBAND_2G) 320 321 @test_tracker_info(uuid="4aa56c11-e5bc-480b-bd61-4b4ee577a5da") 322 def test_softap_2G_wifi_connection_2G(self): 323 """Tests bringing up SoftAp on 2G followed by connection to 2G network. 324 """ 325 self.configure_ap(channel_2g=WIFI_NETWORK_AP_CHANNEL_2G) 326 self.start_softap_and_connect_to_wifi_network( 327 self.wpapsk_2g, WIFI_CONFIG_APBAND_2G) 328 329 @test_tracker_info(uuid="5f954957-ad20-4de1-b20c-6c97d0463bdd") 330 def test_softap_5G_wifi_connection_5G(self): 331 """Tests bringing up SoftAp on 5G followed by connection to 5G network. 332 """ 333 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G) 334 self.start_softap_and_connect_to_wifi_network( 335 self.wpapsk_5g, WIFI_CONFIG_APBAND_5G) 336 337 @test_tracker_info(uuid="1306aafc-a07e-4654-ba78-674f90cf748e") 338 def test_softap_5G_wifi_connection_5G_DFS(self): 339 """Tests bringing up SoftAp on 5G followed by connection to 5G DFS network. 340 """ 341 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G_DFS) 342 self.start_softap_and_connect_to_wifi_network( 343 self.wpapsk_5g, WIFI_CONFIG_APBAND_5G) 344 345 @test_tracker_info(uuid="5e28e8b5-3faa-4cff-a782-13a796d7f572") 346 def test_softap_5G_wifi_connection_2G(self): 347 """Tests bringing up SoftAp on 5G followed by connection to 2G network. 348 """ 349 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G) 350 self.start_softap_and_connect_to_wifi_network( 351 self.wpapsk_5g, WIFI_CONFIG_APBAND_2G) 352 353 @test_tracker_info(uuid="a2c62bc6-9ccd-4bc4-8a23-9a1b5d0b4b5c") 354 def test_softap_2G_wifi_connection_5G(self): 355 """Tests bringing up SoftAp on 2G followed by connection to 5G network. 356 """ 357 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G) 358 self.start_softap_and_connect_to_wifi_network( 359 self.wpapsk_5g, WIFI_CONFIG_APBAND_5G) 360 361 @test_tracker_info(uuid="a2c62bc6-9ccd-4bc4-8a23-9a1b5d0b4b5c") 362 def test_softap_2G_wifi_connection_5G_DFS(self): 363 """Tests bringing up SoftAp on 2G followed by connection to 5G DFS network. 364 """ 365 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G_DFS) 366 self.start_softap_and_connect_to_wifi_network( 367 self.wpapsk_5g, WIFI_CONFIG_APBAND_5G) 368 369 @test_tracker_info(uuid="aa23a3fc-31a1-4d5c-8cf5-2eb9fdf9e7ce") 370 def test_softap_5G_wifi_connection_2G_with_location_scan_on(self): 371 """Tests bringing up SoftAp on 5G followed by connection to 2G network 372 with location scans turned on. 373 """ 374 self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G) 375 self.turn_location_on_and_scan_toggle_on() 376 self.start_softap_and_connect_to_wifi_network( 377 self.wpapsk_5g, WIFI_CONFIG_APBAND_2G) 378