1#!/usr/bin/env python3.4
2#
3#   Copyright 2016 - Google
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    Test Script for Telephony Smoke Test
18"""
19
20import time
21from acts.keys import Config
22from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
23from acts.test_utils.tel.tel_data_utils import airplane_mode_test
24from acts.test_utils.tel.tel_data_utils import wifi_cell_switching
25from acts.test_utils.tel.tel_data_utils import wifi_tethering_setup_teardown
26from acts.test_utils.tel.tel_defines import GEN_4G
27from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK
28from acts.test_utils.tel.tel_defines import TETHERING_MODE_WIFI
29from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_VOICE
30from acts.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL_FOR_IMS
31from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
32from acts.test_utils.tel.tel_lookup_tables import is_rat_svd_capable
33from acts.test_utils.tel.tel_test_utils import stop_wifi_tethering
34from acts.test_utils.tel.tel_test_utils import call_setup_teardown
35from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state
36from acts.test_utils.tel.tel_test_utils import get_network_rat
37from acts.test_utils.tel.tel_test_utils import hangup_call
38from acts.test_utils.tel.tel_test_utils import multithread_func
39from acts.test_utils.tel.tel_test_utils import sms_send_receive_verify
40from acts.test_utils.tel.tel_test_utils import verify_http_connection
41from acts.test_utils.tel.tel_test_utils import wait_for_cell_data_connection
42from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G
43from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
44from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb
45from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
46from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
47from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_3g
48from acts.test_utils.tel.tel_voice_utils import phone_setup_csfb
49from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan
50from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
51from acts.utils import rand_ascii_str
52
53SKIP = 'Skip'
54
55
56class TelLiveSmokeTest(TelephonyBaseTest):
57    def setup_class(self):
58        super().setup_class()
59
60        self.wifi_network_ssid = self.user_params["wifi_network_ssid"]
61        try:
62            self.wifi_network_pass = self.user_params["wifi_network_pass"]
63        except KeyError:
64            self.wifi_network_pass = None
65
66    """ Tests Begin """
67
68    @TelephonyBaseTest.tel_test_wrap
69    def test_smoke_volte_call_data_sms(self):
70        try:
71            ads = self.android_devices
72            sms_idle_result = False
73            sms_incall_result = False
74            data_idle_result = False
75            data_incall_result = False
76            call_result = False
77
78            self.log.info(
79                "--------start test_smoke_volte_call_data_sms--------")
80            ensure_phones_default_state(self.log, ads)
81            tasks = [(phone_setup_volte, (self.log, ads[0])),
82                     (phone_setup_volte, (self.log, ads[1]))]
83            if not multithread_func(self.log, tasks):
84                self.log.error("Phone Failed to Set Up VoLTE.")
85                return False
86
87            # This is to reduce call fail in VoLTE mode.
88            # TODO: b/26338170 remove sleep, use proper API to check DUT status.
89            time.sleep(10)
90
91            self.log.info("1. SMS in LTE idle.")
92            sms_idle_result = sms_send_receive_verify(self.log, ads[0], ads[1],
93                                                      [rand_ascii_str(50)])
94
95            self.log.info("2. Data in LTE idle.")
96            if (wait_for_cell_data_connection(self.log, ads[0], True) and
97                    verify_http_connection(self.log, ads[0])):
98                data_idle_result = True
99
100            self.log.info("3. Setup VoLTE Call.")
101            if not call_setup_teardown(
102                    self.log,
103                    ads[0],
104                    ads[1],
105                    ad_hangup=None,
106                    verify_caller_func=is_phone_in_call_volte,
107                    verify_callee_func=is_phone_in_call_volte,
108                    wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS):
109                self.log.error("Setup VoLTE Call Failed.")
110                return False
111
112            self.log.info("4. Verify SMS in call.")
113            sms_incall_result = sms_send_receive_verify(
114                self.log, ads[0], ads[1], [rand_ascii_str(51)])
115
116            self.log.info("5. Verify Data in call.")
117            if (wait_for_cell_data_connection(self.log, ads[0], True) and
118                    verify_http_connection(self.log, ads[0])):
119                data_incall_result = True
120
121            self.log.info("6. Verify Call not drop and hangup.")
122            if (is_phone_in_call_volte(self.log, ads[0]) and
123                    is_phone_in_call_volte(self.log, ads[1]) and
124                    hangup_call(self.log, ads[0])):
125                call_result = True
126
127            return (sms_idle_result and data_idle_result and call_result and
128                    sms_incall_result and data_incall_result)
129        finally:
130            self.log.info(
131                "Summary for test run. Testbed:<{}>. <VoLTE> SMS idle: {}, "
132                "Data idle: {}, SMS in call: {}, Data in call: {}, "
133                "Voice Call: {}".format(
134                    getattr(self, Config.ikey_testbed_name.value),
135                    sms_idle_result, data_idle_result, sms_incall_result,
136                    data_incall_result, call_result))
137
138    @TelephonyBaseTest.tel_test_wrap
139    def test_smoke_csfb_3g_call_data_sms(self):
140        try:
141            ads = self.android_devices
142            sms_idle_result = False
143            sms_incall_result = False
144            data_idle_result = False
145            data_incall_result = False
146            call_result = False
147
148            self.log.info(
149                "--------start test_smoke_csfb_3g_call_data_sms--------")
150            ensure_phones_default_state(self.log, ads)
151            tasks = [(phone_setup_csfb, (self.log, ads[0])),
152                     (phone_setup_csfb, (self.log, ads[1]))]
153            if not multithread_func(self.log, tasks):
154                self.log.error("Phone Failed to Set Up CSFB_3G.")
155                return False
156
157            # This is to reduce SMS send failure in CSFB mode.
158            # TODO: b/26338170 remove sleep, use proper API to check DUT status.
159            time.sleep(10)
160
161            self.log.info("1. SMS in LTE idle (no IMS).")
162            sms_idle_result = sms_send_receive_verify(self.log, ads[0], ads[1],
163                                                      [rand_ascii_str(50)])
164
165            self.log.info("2. Data in LTE idle (no IMS).")
166            if (wait_for_cell_data_connection(self.log, ads[0], True) and
167                    verify_http_connection(self.log, ads[0])):
168                data_idle_result = True
169
170            self.log.info("3. Setup CSFB_3G Call.")
171            if not call_setup_teardown(
172                    self.log,
173                    ads[0],
174                    ads[1],
175                    ad_hangup=None,
176                    verify_caller_func=is_phone_in_call_csfb,
177                    verify_callee_func=is_phone_in_call_csfb):
178                self.log.error("Setup CSFB_3G Call Failed.")
179                return False
180
181            self.log.info("4. Verify SMS in call.")
182            sms_incall_result = sms_send_receive_verify(
183                self.log, ads[0], ads[1], [rand_ascii_str(51)])
184
185            self.log.info("5. Verify Data in call.")
186            if is_rat_svd_capable(
187                    get_network_rat(self.log, ads[0], NETWORK_SERVICE_VOICE)):
188                if (wait_for_cell_data_connection(self.log, ads[0], True) and
189                        verify_http_connection(self.log, ads[0])):
190                    data_incall_result = True
191            else:
192                self.log.info("Data in call not supported on current RAT."
193                              "Skip Data verification.")
194                data_incall_result = SKIP
195
196            self.log.info("6. Verify Call not drop and hangup.")
197            if (is_phone_in_call_csfb(self.log, ads[0]) and
198                    is_phone_in_call_csfb(self.log, ads[1]) and
199                    hangup_call(self.log, ads[0])):
200                call_result = True
201
202            return (sms_idle_result and data_idle_result and call_result and
203                    sms_incall_result and ((data_incall_result is True) or
204                                           (data_incall_result == SKIP)))
205        finally:
206            self.log.info(
207                "Summary for test run. Testbed:<{}>. <3G+CSFB> SMS idle: {}, "
208                "Data idle: {}, SMS in call: {}, Data in call: {}, "
209                "Voice Call: {}".format(
210                    getattr(self, Config.ikey_testbed_name.value),
211                    sms_idle_result, data_idle_result, sms_incall_result,
212                    data_incall_result, call_result))
213
214    @TelephonyBaseTest.tel_test_wrap
215    def test_smoke_3g_call_data_sms(self):
216        try:
217            ads = self.android_devices
218            sms_idle_result = False
219            sms_incall_result = False
220            data_idle_result = False
221            data_incall_result = False
222            call_result = False
223
224            self.log.info("--------start test_smoke_3g_call_data_sms--------")
225            ensure_phones_default_state(self.log, ads)
226            tasks = [(phone_setup_voice_3g, (self.log, ads[0])),
227                     (phone_setup_voice_3g, (self.log, ads[1]))]
228            if not multithread_func(self.log, tasks):
229                self.log.error("Phone Failed to Set Up 3G.")
230                return False
231            self.log.info("1. SMS in 3G idle.")
232            sms_idle_result = sms_send_receive_verify(self.log, ads[0], ads[1],
233                                                      [rand_ascii_str(50)])
234
235            self.log.info("2. Data in 3G idle.")
236            if (wait_for_cell_data_connection(self.log, ads[0], True) and
237                    verify_http_connection(self.log, ads[0])):
238                data_idle_result = True
239
240            self.log.info("3. Setup 3G Call.")
241            if not call_setup_teardown(
242                    self.log,
243                    ads[0],
244                    ads[1],
245                    ad_hangup=None,
246                    verify_caller_func=is_phone_in_call_3g,
247                    verify_callee_func=is_phone_in_call_3g):
248                self.log.error("Setup 3G Call Failed.")
249                return False
250
251            self.log.info("4. Verify SMS in call.")
252            sms_incall_result = sms_send_receive_verify(
253                self.log, ads[0], ads[1], [rand_ascii_str(51)])
254
255            self.log.info("5. Verify Data in call.")
256            if is_rat_svd_capable(
257                    get_network_rat(self.log, ads[0], NETWORK_SERVICE_VOICE)):
258                if (wait_for_cell_data_connection(self.log, ads[0], True) and
259                        verify_http_connection(self.log, ads[0])):
260                    data_incall_result = True
261            else:
262                self.log.info("Data in call not supported on current RAT."
263                              "Skip Data verification.")
264                data_incall_result = SKIP
265
266            self.log.info("6. Verify Call not drop and hangup.")
267            if (is_phone_in_call_3g(self.log, ads[0]) and
268                    is_phone_in_call_3g(self.log, ads[1]) and
269                    hangup_call(self.log, ads[0])):
270                call_result = True
271
272            return (sms_idle_result and data_idle_result and call_result and
273                    sms_incall_result and ((data_incall_result is True) or
274                                           (data_incall_result == SKIP)))
275        finally:
276            self.log.info(
277                "Summary for test run. Testbed:<{}>. <3G> SMS idle: {}, "
278                "Data idle: {}, SMS in call: {}, Data in call: {}, "
279                "Voice Call: {}".format(
280                    getattr(self, Config.ikey_testbed_name.value),
281                    sms_idle_result, data_idle_result, sms_incall_result,
282                    data_incall_result, call_result))
283
284    @TelephonyBaseTest.tel_test_wrap
285    def test_smoke_wfc_call_sms(self):
286        ads = self.android_devices
287        sms_idle_result = False
288        sms_incall_result = False
289        call_result = False
290
291        self.log.info("--------start test_smoke_wfc_call_sms--------")
292        for ad in [ads[0], ads[1]]:
293            if not ad.droid.imsIsWfcEnabledByPlatform():
294                self.log.info("WFC not supported by platform.")
295                return True
296        try:
297            ensure_phones_default_state(self.log, ads)
298            tasks = [(phone_setup_iwlan,
299                      (self.log, ads[0], True, WFC_MODE_WIFI_PREFERRED,
300                       self.wifi_network_ssid, self.wifi_network_pass)),
301                     (phone_setup_iwlan,
302                      (self.log, ads[1], True, WFC_MODE_WIFI_PREFERRED,
303                       self.wifi_network_ssid, self.wifi_network_pass))]
304            if not multithread_func(self.log, tasks):
305                self.log.error("Phone Failed to Set Up WiFI Calling.")
306                return False
307
308            self.log.info("1. Verify SMS in idle.")
309            if sms_send_receive_verify(self.log, ads[0], ads[1],
310                                       [rand_ascii_str(50)]):
311                sms_idle_result = True
312
313            self.log.info("2. Setup WiFi Call.")
314            if not call_setup_teardown(
315                    self.log,
316                    ads[0],
317                    ads[1],
318                    ad_hangup=None,
319                    verify_caller_func=is_phone_in_call_iwlan,
320                    verify_callee_func=is_phone_in_call_iwlan):
321                self.log.error("Setup WiFi Call Failed.")
322                self.log.info("sms_idle_result:{}".format(sms_idle_result))
323                return False
324
325            self.log.info("3. Verify SMS in call.")
326            if sms_send_receive_verify(self.log, ads[0], ads[1],
327                                       [rand_ascii_str(51)]):
328                sms_incall_result = True
329
330            self.log.info("4. Verify Call not drop and hangup.")
331            if (is_phone_in_call_iwlan(self.log, ads[0]) and
332                    is_phone_in_call_iwlan(self.log, ads[1]) and
333                    hangup_call(self.log, ads[0])):
334                call_result = True
335
336            return (call_result and sms_idle_result and sms_incall_result)
337        finally:
338            self.log.info(
339                "Summary for test run. Testbed:<{}>. <WFC> SMS idle: {}, "
340                "SMS in call: {}, Voice Call: {}".format(
341                    getattr(self, Config.ikey_testbed_name.value),
342                    sms_idle_result, sms_incall_result, call_result))
343
344    @TelephonyBaseTest.tel_test_wrap
345    def test_smoke_data_airplane_mode_network_switch_tethering(self):
346        try:
347            ads = self.android_devices
348            apm_result = False
349            nw_switch_result = False
350            tethering_result = False
351
352            self.log.info("--------start test_smoke_data_airplane_mode_network"
353                          "_switch_tethering--------")
354            ensure_phones_default_state(self.log, ads)
355            self.log.info("1. Verify toggle airplane mode.")
356            apm_result = airplane_mode_test(self.log, ads[0])
357            self.log.info("2. Verify LTE-WiFi network switch.")
358            nw_switch_result = wifi_cell_switching(
359                self.log, ads[0], self.wifi_network_ssid,
360                self.wifi_network_pass, GEN_4G)
361            if ads[0].droid.carrierConfigIsTetheringModeAllowed(
362                    TETHERING_MODE_WIFI,
363                    MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK):
364                self.log.info("3. Verify WiFi Tethering.")
365                if ads[0].droid.wifiIsApEnabled():
366                    stop_wifi_tethering(self.log, ads[0])
367                tethering_result = wifi_tethering_setup_teardown(
368                    self.log,
369                    ads[0], [ads[1]],
370                    ap_band=WIFI_CONFIG_APBAND_2G,
371                    check_interval=10,
372                    check_iteration=4)
373                # check_interval=10, check_iteration=4: in this Smoke test,
374                # check tethering connection for 4 times, each time delay 10s,
375                # to provide a reasonable check_time (10*4=40s) and also reduce test
376                # execution time. In regular test, check_iteration is set to 10.
377            else:
378                self.log.info("3. Skip WiFi Tethering."
379                              "Tethering not allowed on SIM.")
380                tethering_result = SKIP
381
382            return (apm_result and nw_switch_result and (
383                (tethering_result is True) or (tethering_result == SKIP)))
384        finally:
385            self.log.info(
386                "Summary for test run. Testbed:<{}>. <Data> Airplane Mode: {}, "
387                "WiFi-Cell Network Switch: {}, Tethering: {}".format(
388                    getattr(self, Config.ikey_testbed_name.value), apm_result,
389                    nw_switch_result, tethering_result))
390
391    """ Tests End """
392