blob: 7ff67691f2ab6c8b9973f6fd998d59cb0081a46a [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
7import acts.test_utils.wifi.wifi_test_utils as wifi_utils
8import acts.test_utils.tel.tel_test_utils as tele_utils
9import acts.utils
10
11from acts import asserts
12from acts import signals
13from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
14from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_general
15from acts.test_utils.tel.tel_voice_utils import two_phone_call_short_seq
16
17WifiEnums = wifi_utils.WifiEnums
18
19ATTENUATORS = "attenuators"
20WIFI_SSID = "wifi_network_ssid"
21WIFI_PWD = "wifi_network_pass"
22STRESS_COUNT = "stress_iteration"
23
24class WifiTeleCoexTest(TelephonyBaseTest):
25 """Tests for WiFi, Celular Co-existance."""
26
27
28 def __init__(self, controllers):
29 TelephonyBaseTest.__init__(self, controllers)
30
31
32 def setup_class(self):
33 TelephonyBaseTest.setup_class(self)
34 self.dut = self.android_devices[0]
35 wifi_utils.wifi_test_device_init(self.dut)
36 # Set attenuation to 0 on all channels.
37 if getattr(self, ATTENUATORS, []):
38 for a in self.attenuators:
39 a.set_atten(0)
40 self.ads = self.android_devices
41 self.dut = self.android_devices[0]
42 self.wifi_network_ssid = self.user_params.get(WIFI_SSID)
43 self.wifi_network_pass = self.user_params.get(WIFI_PWD)
44 self.network = { WifiEnums.SSID_KEY : self.wifi_network_ssid,
45 WifiEnums.PWD_KEY : self.wifi_network_pass
46 }
47 self.stress_count = self.user_params.get(STRESS_COUNT)
48
49
50 def setup_test(self):
51 wifi_utils.wifi_toggle_state(self.dut, True)
52
53
54 def teardown_test(self):
55 wifi_utils.reset_wifi(self.dut)
56
57
58 """Helper Functions"""
59
60
61 def connect_to_wifi(self, ad, network):
62 """Connection logic for open and psk wifi networks.
63
64 Args:
65 ad: Android device object.
66 network: A JSON dict of the WiFi network configuration.
67
68 """
69 ad.ed.clear_all_events()
70 wifi_utils.start_wifi_connection_scan(ad)
71 scan_results = ad.droid.wifiGetScanResults()
72 wifi_utils.assert_network_in_list({WifiEnums.SSID_KEY:
73 self.wifi_network_ssid}, scan_results)
74 wifi_utils.wifi_connect(ad, network)
75 self.log.debug("Connected to %s network on %s device" % (
76 network[WifiEnums.SSID_KEY], ad.serial))
77
78
79 def stress_toggle_wifi(self, stress_count):
80 """Toggle WiFi in a loop.
81
82 Args:
83 stress_count: Number of times to toggle WiFi OFF and ON.
84
85 """
86 for count in range(stress_count):
87 self.log.debug("stress_toggle_wifi: Iteration %d" % count)
88 wifi_utils.toggle_wifi_off_and_on(self.dut)
89
90 if not self.dut.droid.wifiGetisWifiEnabled():
91 raise signals.TestFailure("WiFi did not turn on after toggling it"
92 " %d times" % self.stress_count)
93
94
95 def stress_toggle_airplane(self, stress_count):
96 """Toggle Airplane mode in a loop.
97
98 Args:
99 stress_count: Number of times to toggle Airplane mode OFF and ON.
100
101 """
102 for count in range(stress_count):
103 self.log.debug("stress_toggle_airplane: Iteration %d" % count)
104 wifi_utils.toggle_airplane_mode_on_and_off(self.dut)
105
106 if not self.dut.droid.wifiGetisWifiEnabled():
107 raise signals.TestFailure("WiFi did not turn on after toggling it"
108 " %d times" % self.stress_count)
109
110
111 def stress_toggle_airplane_and_wifi(self, stress_count):
112 """Toggle Airplane and WiFi modes in a loop.
113
114 Args:
115 stress_count: Number of times to perform Airplane mode ON, WiFi ON,
116 Airplane mode OFF, in a sequence.
117
118 """
119 self.log.debug("Toggling Airplane mode ON")
120 asserts.assert_true(
121 acts.utils.force_airplane_mode(self.dut, True),
122 "Can not turn on airplane mode on: %s" % self.dut.serial)
123 self.log.debug("Toggling wifi ON")
124 wifi_utils.wifi_toggle_state(self.dut, True)
125 asserts.assert_true(
126 acts.utils.force_airplane_mode(self.dut, False),
127 "Can not turn on airplane mode on: %s" % self.dut.serial)
128
129 if not self.dut.droid.wifiGetisWifiEnabled():
130 raise signals.TestFailure("WiFi did not turn on after toggling it"
131 " %d times" % self.stress_count)
132
133
134 def setup_cellular_voice_calling(self):
135 """Setup phone for voice general calling and make sure phone is
136 attached to voice."""
137 # Make sure Phone A and B are attached to voice network.
138 for ad in self.ads:
139 if not phone_setup_voice_general(self.log, ad):
140 raise signals.TestFailure("Phone failed to setup for voice"
141 " calling serial:%s" % ad.serial)
142 self.log.debug("Finished setting up phones for voice calling")
143
144
145 def validate_cellular_and_wifi(self):
146 """Validate WiFi, make some cellular calls.
147
148 Steps:
149 1. Check if device is still connected to the WiFi network.
150 2. If WiFi looks good, check if deivce is attached to voice.
151 3. Make a short sequence voice call between Phone A and B.
152
153 """
154 wifi_info = self.dut.droid.wifiGetConnectionInfo()
155 if wifi_info[WifiEnums.SSID_KEY] != self.wifi_network_ssid:
156 raise signals.TestFailure("Phone failed to connect to %s network on"
157 " %s" % (self.wifi_network_ssid,
158 self.dut.serial))
159
160 # Make short call sequence between Phone A and Phone B.
161 two_phone_call_short_seq(self.log, self.ads[0], None, None, self.ads[1],
162 None, None)
163
164 """Tests"""
165
166
167 @TelephonyBaseTest.tel_test_wrap
168 def test_toggle_wifi_call(self):
169 """Test to toggle WiFi and then perform WiFi connection and
170 cellular calls.
171
172 Steps:
173 1. Attach device to voice subscription network.
174 2. Connect to a WiFi network.
175 3. Toggle WiFi OFF and ON.
176 4. Verify device auto-connects to the WiFi network.
177 5. Verify device is attached to voice network.
178 6. Make short sequence voice calls.
179
180 """
181 self.setup_cellular_voice_calling()
182 self.connect_to_wifi(self.dut, self.network)
183 wifi_utils.toggle_wifi_off_and_on(self.dut)
184 self.validate_cellular_and_wifi()
185
186
187 @TelephonyBaseTest.tel_test_wrap
188 def test_toggle_airplane_call(self):
189 """Test to toggle Airplane mode and perform WiFi connection and
190 cellular calls.
191
192 Steps:
193 1. Attach device to voice subscription network.
194 2. Connect to a WiFi network.
195 3. Toggle Airplane mode OFF and ON.
196 4. Verify device auto-connects to the WiFi network.
197 5. Verify device is attached to voice network.
198 6. Make short sequence voice calls.
199
200 """
201 self.setup_cellular_voice_calling()
202 self.connect_to_wifi(self.dut, self.network)
203 wifi_utils.toggle_airplane_mode_on_and_off(self.dut)
204 self.validate_cellular_and_wifi()
205
206
207 @TelephonyBaseTest.tel_test_wrap
208 def test_toggle_airplane_and_wifi_call(self):
209 """Test to toggle WiFi in a loop and perform WiFi connection and
210 cellular calls.
211
212 Steps:
213 1. Attach device to voice subscription network.
214 2. Connect to a WiFi network.
215 3. Toggle Airplane mode ON.
216 4. Turn WiFi ON.
217 5. Toggle Airplane mode OFF.
218 3. Verify device auto-connects to the WiFi network.
219 4. Verify device is attached to voice network.
220 5. Make short sequence voice calls.
221
222 """
223 self.setup_cellular_voice_calling()
224 self.connect_to_wifi(self.dut, self.network)
225 self.stress_toggle_airplane_and_wifi(1)
226 self.validate_cellular_and_wifi()
227
228
229 @TelephonyBaseTest.tel_test_wrap
230 def test_stress_toggle_wifi_call(self):
231 """Stress test to toggle WiFi in a loop, then perform WiFi connection
232 and cellular calls.
233
234 Steps:
235 1. Attach device to voice subscription network.
236 2. Connect to a WiFi network.
237 3. Toggle WiFi OFF and ON in a loop.
238 4. Verify device auto-connects to the WiFi network.
239 5. Verify device is attached to voice network.
240 6. Make short sequence voice calls.
241
242 """
243 self.setup_cellular_voice_calling()
244 self.connect_to_wifi(self.dut, self.network)
245 self.stress_toggle_wifi(self.stress_count)
246 self.validate_cellular_and_wifi()
247
248
249 @TelephonyBaseTest.tel_test_wrap
250 def test_stress_toggle_airplane_call(self):
251 """Stress test to toggle Airplane mode in a loop, then perform WiFi and
252 cellular calls.
253
254 Steps:
255 1. Attach device to voice subscription network.
256 2. Connect to a WiFi network.
257 3. Toggle Airplane mode OFF and ON in a loop.
258 4. Verify device auto-connects to the WiFi network.
259 5. Verify device is attached to voice network.
260 6. Make short sequence voice calls.
261
262 """
263 self.setup_cellular_voice_calling()
264 self.connect_to_wifi(self.dut, self.network)
265 self.stress_toggle_airplane(self.stress_count)
266 self.validate_cellular_and_wifi()
267
268
269 @TelephonyBaseTest.tel_test_wrap
270 def test_stress_toggle_airplane_and_wifi_call(self):
271 """Stress test to toggle Airplane and WiFi mode in a loop, then perform
272 WiFi connection and cellular calls.
273
274 Steps:
275 1. Attach device to voice subscription network.
276 2. Connect to a WiFi network.
277 3. Toggle Airplane mode ON.
278 4. Turn WiFi ON.
279 5. Toggle Airplane mode OFF.
280 6. Repeat 3, 4 & 5, in a loop.
281 7. Verify device auto-connects to the WiFi network.
282 8. Verify device is attached to voice network.
283 9. Make short sequence voice calls.
284
285 """
286 self.setup_cellular_voice_calling()
287 self.connect_to_wifi(self.dut, self.network)
Bindu Mahadev65d547e2017-05-19 23:58:32 +0000288 self.stress_toggle_airplane_and_wifi(self.stress_count)
Bindu Mahadevae923812017-04-12 22:57:49 +0000289 self.validate_cellular_and_wifi()