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