1#!/usr/bin/env python3.4 2 3import queue 4import time 5 6import acts.base_test 7import acts_contrib.test_utils.wifi.wifi_test_utils as wifi_utils 8import acts_contrib.test_utils.tel.tel_test_utils as tele_utils 9import acts.utils 10 11from acts import asserts 12from acts import signals 13from acts.test_decorators import test_tracker_info 14from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest 15from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_voice_general 16from acts_contrib.test_utils.tel.tel_voice_utils import two_phone_call_short_seq 17from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan 18from acts_contrib.test_utils.tel.tel_voice_utils import phone_idle_iwlan 19from acts_contrib.test_utils.tel.tel_defines import DIRECTION_MOBILE_ORIGINATED 20from acts_contrib.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED 21from acts_contrib.test_utils.tel.tel_defines import GEN_4G 22from acts_contrib.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA 23from acts_contrib.test_utils.net import net_test_utils as nutil 24 25WifiEnums = wifi_utils.WifiEnums 26 27ATTENUATORS = "attenuators" 28WIFI_SSID = "wifi_network_ssid" 29WIFI_PWD = "wifi_network_pass" 30STRESS_COUNT = "stress_iteration" 31 32class WifiTeleCoexTest(TelephonyBaseTest): 33 """Tests for WiFi, Celular Co-existance.""" 34 35 36 def setup_class(self): 37 TelephonyBaseTest.setup_class(self) 38 39 self.dut = self.android_devices[0] 40 wifi_utils.wifi_test_device_init(self.dut) 41 # Set attenuation to 0 on all channels. 42 if getattr(self, ATTENUATORS, []): 43 for a in self.attenuators: 44 a.set_atten(0) 45 self.ads = self.android_devices 46 self.dut = self.android_devices[0] 47 self.wifi_network_ssid = self.user_params.get(WIFI_SSID) 48 self.wifi_network_pass = self.user_params.get(WIFI_PWD) 49 self.network = { WifiEnums.SSID_KEY : self.wifi_network_ssid, 50 WifiEnums.PWD_KEY : self.wifi_network_pass 51 } 52 self.stress_count = self.user_params.get(STRESS_COUNT) 53 54 55 def setup_test(self): 56 """ Setup test make sure the DUT is wake and screen unlock""" 57 for ad in self.android_devices: 58 ad.droid.wakeLockAcquireBright() 59 ad.droid.wakeUpNow() 60 wifi_utils.wifi_toggle_state(self.dut, True) 61 62 63 def teardown_test(self): 64 """ End test make sure the DUT return idle""" 65 for ad in self.android_devices: 66 wifi_utils.reset_wifi(ad) 67 tele_utils.ensure_phones_idle(self.log, self.android_devices) 68 69 70 """Helper Functions""" 71 72 73 def connect_to_wifi(self, ad, network): 74 """Connection logic for open and psk wifi networks. 75 76 Args: 77 ad: Android device object. 78 network: A JSON dict of the WiFi network configuration. 79 80 """ 81 ad.ed.clear_all_events() 82 wifi_utils.start_wifi_connection_scan(ad) 83 scan_results = ad.droid.wifiGetScanResults() 84 wifi_utils.assert_network_in_list({WifiEnums.SSID_KEY: 85 self.wifi_network_ssid}, scan_results) 86 wifi_utils.wifi_connect(ad, network) 87 self.log.debug("Connected to %s network on %s device" % ( 88 network[WifiEnums.SSID_KEY], ad.serial)) 89 90 91 def stress_toggle_wifi(self, stress_count): 92 """Toggle WiFi in a loop. 93 94 Args: 95 stress_count: Number of times to toggle WiFi OFF and ON. 96 97 """ 98 for count in range(stress_count): 99 self.log.debug("stress_toggle_wifi: Iteration %d" % count) 100 wifi_utils.toggle_wifi_off_and_on(self.dut) 101 102 if not self.dut.droid.wifiGetisWifiEnabled(): 103 raise signals.TestFailure("WiFi did not turn on after toggling it" 104 " %d times" % self.stress_count) 105 106 107 def stress_toggle_airplane(self, stress_count): 108 """Toggle Airplane mode in a loop. 109 110 Args: 111 stress_count: Number of times to toggle Airplane mode OFF and ON. 112 113 """ 114 for count in range(stress_count): 115 self.log.debug("stress_toggle_airplane: Iteration %d" % count) 116 wifi_utils.toggle_airplane_mode_on_and_off(self.dut) 117 118 if not self.dut.droid.wifiGetisWifiEnabled(): 119 raise signals.TestFailure("WiFi did not turn on after toggling it" 120 " %d times" % self.stress_count) 121 122 123 def stress_toggle_airplane_and_wifi(self, stress_count): 124 """Toggle Airplane and WiFi modes in a loop. 125 126 Args: 127 stress_count: Number of times to perform Airplane mode ON, WiFi ON, 128 Airplane mode OFF, in a sequence. 129 130 """ 131 for count in range(stress_count): 132 self.log.debug("stress_toggle_airplane_and_wifi: Iteration %d" % count) 133 self.log.debug("Toggling Airplane mode ON") 134 asserts.assert_true( 135 acts.utils.force_airplane_mode(self.dut, True), 136 "Can not turn on airplane mode on: %s" % self.dut.serial) 137 # Sleep for atleast 500ms so that, call to enable wifi is not deferred. 138 time.sleep(1) 139 self.log.debug("Toggling wifi ON") 140 wifi_utils.wifi_toggle_state(self.dut, True) 141 # Sleep for 1s before getting new WiFi state. 142 time.sleep(1) 143 if not self.dut.droid.wifiGetisWifiEnabled(): 144 raise signals.TestFailure("WiFi did not turn on after turning ON" 145 " Airplane mode") 146 asserts.assert_true( 147 acts.utils.force_airplane_mode(self.dut, False), 148 "Can not turn on airplane mode on: %s" % self.dut.serial) 149 150 if not self.dut.droid.wifiGetisWifiEnabled(): 151 raise signals.TestFailure("WiFi did not turn on after toggling it" 152 " %d times" % self.stress_count) 153 154 155 def setup_cellular_voice_calling(self): 156 """Setup phone for voice general calling and make sure phone is 157 attached to voice.""" 158 # Make sure Phone A and B are attached to voice network. 159 for ad in self.ads: 160 if not phone_setup_voice_general(self.log, ad): 161 raise signals.TestFailure("Phone failed to setup for voice" 162 " calling serial:%s" % ad.serial) 163 self.log.debug("Finished setting up phones for voice calling") 164 165 166 def validate_cellular_and_wifi(self): 167 """Validate WiFi, make some cellular calls. 168 169 Steps: 170 1. Check if device is still connected to the WiFi network. 171 2. If WiFi looks good, check if deivce is attached to voice. 172 3. Make a short sequence voice call between Phone A and B. 173 174 """ 175 # Sleep for 30s before getting new WiFi state. 176 time.sleep(30) 177 wifi_info = self.dut.droid.wifiGetConnectionInfo() 178 if wifi_info[WifiEnums.SSID_KEY] != self.wifi_network_ssid: 179 raise signals.TestFailure("Phone failed to connect to %s network on" 180 " %s" % (self.wifi_network_ssid, 181 self.dut.serial)) 182 183 # Make short call sequence between Phone A and Phone B. 184 two_phone_call_short_seq(self.log, self.ads[0], None, None, self.ads[1], 185 None, None) 186 187 def _phone_idle_iwlan(self): 188 return phone_idle_iwlan(self.log, self.android_devices[0]) 189 190 def _wfc_phone_setup_apm_wifi_preferred(self): 191 return self._wfc_phone_setup(True, WFC_MODE_WIFI_PREFERRED) 192 193 def _wfc_phone_setup(self, is_airplane_mode, wfc_mode, volte_mode=True): 194 """Enables WiFi calling by turning off Airplane Mode and setting up volte 195 196 Args: 197 is_airplane_mode: boolean, True/False to turn on/off Airplane Mode. 198 wfc_mode: str, String stating what WFC Mode is used. 199 volte_mode: boolean, True/False to turn on/off VoLTE Mode. 200 201 Returns: 202 False, when 4G fails or wrong wfc_mode or WiFi does not connect, 203 (failure is logged) True otherwise. 204 205 """ 206 tele_utils.toggle_airplane_mode(self.log, self.android_devices[0], False) 207 tele_utils.toggle_volte(self.log, self.android_devices[0], volte_mode) 208 if not tele_utils.ensure_network_generation( 209 self.log, 210 self.android_devices[0], 211 GEN_4G, 212 voice_or_data=NETWORK_SERVICE_DATA): 213 return False 214 if not tele_utils.set_wfc_mode(self.log, self.android_devices[0], wfc_mode): 215 self.log.error("{} set WFC mode failed.".format( 216 self.android_devices[0].serial)) 217 return False 218 tele_utils.toggle_airplane_mode(self.log, self.android_devices[0], 219 is_airplane_mode) 220 if not tele_utils.ensure_wifi_connected(self.log, self.android_devices[0], 221 self.wifi_network_ssid, 222 self.wifi_network_pass): 223 self.log.error("{} connect WiFI failed".format( 224 self.android_devices[0].serial)) 225 return False 226 return True 227 228 229 """Tests""" 230 231 232 @test_tracker_info(uuid="8b9b6fb9-964b-43e7-b75f-675774ee346f") 233 @TelephonyBaseTest.tel_test_wrap 234 def test_toggle_wifi_call(self): 235 """Test to toggle WiFi and then perform WiFi connection and 236 cellular calls. 237 238 Steps: 239 1. Attach device to voice subscription network. 240 2. Connect to a WiFi network. 241 3. Toggle WiFi OFF and ON. 242 4. Verify device auto-connects to the WiFi network. 243 5. Verify device is attached to voice network. 244 6. Make short sequence voice calls. 245 246 """ 247 self.setup_cellular_voice_calling() 248 self.connect_to_wifi(self.dut, self.network) 249 wifi_utils.toggle_wifi_off_and_on(self.dut) 250 self.validate_cellular_and_wifi() 251 return True 252 253 254 @test_tracker_info(uuid="caf22447-6354-4a2e-99e5-0ff235fc8f20") 255 @TelephonyBaseTest.tel_test_wrap 256 def test_toggle_airplane_call(self): 257 """Test to toggle Airplane mode and perform WiFi connection and 258 cellular calls. 259 260 Steps: 261 1. Attach device to voice subscription network. 262 2. Connect to a WiFi network. 263 3. Toggle Airplane mode OFF and ON. 264 4. Verify device auto-connects to the WiFi network. 265 5. Verify device is attached to voice network. 266 6. Make short sequence voice calls. 267 268 """ 269 self.setup_cellular_voice_calling() 270 self.connect_to_wifi(self.dut, self.network) 271 wifi_utils.toggle_airplane_mode_on_and_off(self.dut) 272 self.validate_cellular_and_wifi() 273 return True 274 275 276 @test_tracker_info(uuid="dd888b35-f820-409a-89af-4b0f6551e4d6") 277 @TelephonyBaseTest.tel_test_wrap 278 def test_toggle_airplane_and_wifi_call(self): 279 """Test to toggle WiFi in a loop and perform WiFi connection and 280 cellular calls. 281 282 Steps: 283 1. Attach device to voice subscription network. 284 2. Connect to a WiFi network. 285 3. Toggle Airplane mode ON. 286 4. Turn WiFi ON. 287 5. Toggle Airplane mode OFF. 288 3. Verify device auto-connects to the WiFi network. 289 4. Verify device is attached to voice network. 290 5. Make short sequence voice calls. 291 292 """ 293 self.setup_cellular_voice_calling() 294 self.connect_to_wifi(self.dut, self.network) 295 self.stress_toggle_airplane_and_wifi(1) 296 self.validate_cellular_and_wifi() 297 return True 298 299 300 @test_tracker_info(uuid="15db5b7e-827e-4bc8-8e77-7fcce343a323") 301 @TelephonyBaseTest.tel_test_wrap 302 def test_stress_toggle_wifi_call(self): 303 """Stress test to toggle WiFi in a loop, then perform WiFi connection 304 and cellular calls. 305 306 Steps: 307 1. Attach device to voice subscription network. 308 2. Connect to a WiFi network. 309 3. Toggle WiFi OFF and ON in a loop. 310 4. Verify device auto-connects to the WiFi network. 311 5. Verify device is attached to voice network. 312 6. Make short sequence voice calls. 313 314 """ 315 self.setup_cellular_voice_calling() 316 self.connect_to_wifi(self.dut, self.network) 317 self.stress_toggle_wifi(self.stress_count) 318 self.validate_cellular_and_wifi() 319 return True 320 321 322 @test_tracker_info(uuid="80a2f1bf-5e41-453a-9b8e-be3b41d4d313") 323 @TelephonyBaseTest.tel_test_wrap 324 def test_stress_toggle_airplane_call(self): 325 """Stress test to toggle Airplane mode in a loop, then perform WiFi and 326 cellular calls. 327 328 Steps: 329 1. Attach device to voice subscription network. 330 2. Connect to a WiFi network. 331 3. Toggle Airplane mode OFF and ON in a loop. 332 4. Verify device auto-connects to the WiFi network. 333 5. Verify device is attached to voice network. 334 6. Make short sequence voice calls. 335 336 """ 337 self.setup_cellular_voice_calling() 338 self.connect_to_wifi(self.dut, self.network) 339 self.stress_toggle_airplane(self.stress_count) 340 self.validate_cellular_and_wifi() 341 return True 342 343 344 @test_tracker_info(uuid="b88ad3e7-6462-4280-ad57-22d0ac91fdd8") 345 @TelephonyBaseTest.tel_test_wrap 346 def test_stress_toggle_airplane_and_wifi_call(self): 347 """Stress test to toggle Airplane and WiFi mode in a loop, then perform 348 WiFi connection and cellular calls. 349 350 Steps: 351 1. Attach device to voice subscription network. 352 2. Connect to a WiFi network. 353 3. Toggle Airplane mode ON. 354 4. Turn WiFi ON. 355 5. Toggle Airplane mode OFF. 356 6. Repeat 3, 4 & 5, in a loop. 357 7. Verify device auto-connects to the WiFi network. 358 8. Verify device is attached to voice network. 359 9. Make short sequence voice calls. 360 361 """ 362 self.setup_cellular_voice_calling() 363 self.connect_to_wifi(self.dut, self.network) 364 self.stress_toggle_airplane_and_wifi(self.stress_count) 365 self.validate_cellular_and_wifi() 366 return True 367 368 @test_tracker_info(uuid="7cd9698c-7cde-4c99-b73a-67a2246ca4ec") 369 @TelephonyBaseTest.tel_test_wrap 370 def test_toggle_WFC_call(self): 371 372 """Test to toggle WiFi and then perform WiFi connection and 373 cellular calls. 374 375 Raises: 376 signals.TestFailure:The Wifi calling test is failed. 377 378 Steps: 379 1. Attach device to voice subscription network. 380 2. Connect to a WiFi network. 381 3. Turn on airplane mode 382 4. Toggle WiFi OFF and ON. 383 5. Make WiFi calling 384 6. Verify device is in WiFi calling 385 5. Hang up the call 386 387 Verification: 388 The device is using WiFi calling to call out. 389 390 """ 391 mo_mt=[] 392 if mo_mt == DIRECTION_MOBILE_ORIGINATED: 393 ad_caller = self.ads[0] 394 ad_callee = self.ads[1] 395 else: 396 ad_caller = self.ads[1] 397 ad_callee = self.ads[0] 398 caller_number = tele_utils.get_phone_number(self.log, ad_caller) 399 callee_number = tele_utils.get_phone_number(self.log, ad_callee) 400 self._wfc_phone_setup_apm_wifi_preferred() 401 402 self.connect_to_wifi(self.dut, self.network) 403 asserts.assert_true( 404 acts.utils.force_airplane_mode(self.dut, True), 405 "Can not turn on airplane mode on: %s" % self.dut.serial) 406 time.sleep(1) 407 self.log.info("Toggling wifi ON") 408 wifi_utils.wifi_toggle_state(self.dut, True) 409 time.sleep(10) 410 tele_utils.initiate_call(self.log, ad_caller, callee_number) 411 tele_utils.wait_and_answer_call(self.log, ad_callee, caller_number) 412 if not self._phone_idle_iwlan(): 413 self.log.error("no in wifi calling") 414 raise signals.TestFailure("The Wifi calling test is failed." 415 "WiFi State = %d" %self.dut.droid.wifiCheckState()) 416 tele_utils.hangup_call(self.log, self.ads[0]) 417 418 @test_tracker_info(uuid="c1f0e0a7-b651-4d6c-a4a5-f946cabf56ef") 419 @TelephonyBaseTest.tel_test_wrap 420 def test_back_to_back_of_the_modem_restart(self): 421 422 """Make sure DUT can connect to AP after modem restart 423 424 Raises: 425 signals.TestFailure: The Wifi connect failed after modem restart. 426 427 From b/171275893: 428 b/170702695 has modem back to back restart, 429 it causes WIFi failure and only reboot device can recover. 430 Currently modem team has this test case but they only check modem status. 431 Therefore, we need to add the same test case and the criteria is to check 432 if WiFi works well after back to back modem restart. 433 For the interval setting between 2 restarts, we suggest to use 20s. 434 We can change to different interval if necessary. 435 436 Steps: 437 1.Restart the modem once 438 2.Waiting for 20s 439 3.Restart the modem again 440 4.Go to Settings ->Network & internet ->Wi-Fi 441 5.To check the DUT can find WiFi AP then connect it 442 Verification: 443 DUT can connect to AP successfully 444 DUT can access the Internet after connect to AP. 445 446 """ 447 self.dut = self.android_devices[0] 448 try: 449 tele_utils.trigger_modem_crash_by_modem(self.dut) 450 time.sleep(20) 451 tele_utils.trigger_modem_crash_by_modem(self.dut) 452 time.sleep(20) 453 self.connect_to_wifi(self.dut, self.network) 454 except: 455 raise signals.TestFailure("The Wifi connect failed after modem restart." 456 "WiFi State = %d" %self.dut.droid.wifiCheckState())