1#/usr/bin/env python3.4
2#
3#   Copyright 2016 - 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"""
17Sanity tests for voice tests in telephony
18"""
19import time
20
21from acts.controllers.anritsu_lib._anritsu_utils import AnritsuError
22from acts.controllers.anritsu_lib.md8475a import CBCHSetup
23from acts.controllers.anritsu_lib.md8475a import CTCHSetup
24from acts.controllers.anritsu_lib.md8475a import MD8475A
25from acts.test_utils.tel.anritsu_utils import CMAS_C2K_CATEGORY_AMBER
26from acts.test_utils.tel.anritsu_utils import CMAS_C2K_CATEGORY_EXTREME
27from acts.test_utils.tel.anritsu_utils import CMAS_C2K_CATEGORY_PRESIDENTIAL
28from acts.test_utils.tel.anritsu_utils import CMAS_C2K_CERTIANTY_LIKELY
29from acts.test_utils.tel.anritsu_utils import CMAS_C2K_RESPONSETYPE_EVACUATE
30from acts.test_utils.tel.anritsu_utils import CMAS_C2K_RESPONSETYPE_MONITOR
31from acts.test_utils.tel.anritsu_utils import CMAS_C2K_RESPONSETYPE_SHELTER
32from acts.test_utils.tel.anritsu_utils import CMAS_C2K_SEVERITY_EXTREME
33from acts.test_utils.tel.anritsu_utils import CMAS_C2K_URGENCY_IMMEDIATE
34from acts.test_utils.tel.anritsu_utils import CMAS_C2K_CERTIANTY_OBSERVED
35from acts.test_utils.tel.anritsu_utils import CMAS_MESSAGE_CHILD_ABDUCTION_EMERGENCY
36from acts.test_utils.tel.anritsu_utils import CMAS_MESSAGE_EXTREME_IMMEDIATE_LIKELY
37from acts.test_utils.tel.anritsu_utils import CMAS_MESSAGE_PRESIDENTIAL_ALERT
38from acts.test_utils.tel.anritsu_utils import cb_serial_number
39from acts.test_utils.tel.anritsu_utils import cmas_receive_verify_message_cdma1x
40from acts.test_utils.tel.anritsu_utils import cmas_receive_verify_message_lte_wcdma
41from acts.test_utils.tel.anritsu_utils import set_system_model_1x
42from acts.test_utils.tel.anritsu_utils import set_system_model_1x_evdo
43from acts.test_utils.tel.anritsu_utils import set_system_model_lte
44from acts.test_utils.tel.anritsu_utils import set_system_model_gsm
45from acts.test_utils.tel.anritsu_utils import set_system_model_wcdma
46from acts.test_utils.tel.anritsu_utils import set_usim_parameters
47from acts.test_utils.tel.anritsu_utils import set_post_sim_params
48from acts.test_utils.tel.tel_defines import NETWORK_MODE_CDMA
49from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_ONLY
50from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_UMTS
51from acts.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA
52from acts.test_utils.tel.tel_defines import RAT_1XRTT
53from acts.test_utils.tel.tel_defines import RAT_LTE
54from acts.test_utils.tel.tel_defines import RAT_GSM
55from acts.test_utils.tel.tel_defines import RAT_WCDMA
56from acts.test_utils.tel.tel_defines import RAT_FAMILY_CDMA2000
57from acts.test_utils.tel.tel_defines import RAT_FAMILY_GSM
58from acts.test_utils.tel.tel_defines import RAT_FAMILY_LTE
59from acts.test_utils.tel.tel_defines import RAT_FAMILY_UMTS
60from acts.test_utils.tel.tel_test_utils import ensure_network_rat
61from acts.test_utils.tel.tel_test_utils import ensure_phones_idle
62from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
63from acts.test_utils.tel.tel_test_utils import start_qxdm_loggers
64from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
65from acts.test_decorators import test_tracker_info
66
67WAIT_TIME_BETWEEN_REG_AND_MSG = 15  # default 15 sec
68
69
70class TelLabCmasTest(TelephonyBaseTest):
71    SERIAL_NO = cb_serial_number()
72
73    def __init__(self, controllers):
74        TelephonyBaseTest.__init__(self, controllers)
75        self.ad = self.android_devices[0]
76        self.ad.sim_card = getattr(self.ad, "sim_card", None)
77        self.md8475a_ip_address = self.user_params[
78            "anritsu_md8475a_ip_address"]
79        self.wlan_option = self.user_params.get("anritsu_wlan_option", False)
80        self.wait_time_between_reg_and_msg = self.user_params.get(
81            "wait_time_between_reg_and_msg", WAIT_TIME_BETWEEN_REG_AND_MSG)
82
83    def setup_class(self):
84        try:
85            self.anritsu = MD8475A(self.md8475a_ip_address, self.log,
86                                   self.wlan_option)
87        except AnritsuError:
88            self.log.error("Error in connecting to Anritsu Simulator")
89            return False
90        return True
91
92    def setup_test(self):
93        if getattr(self, "qxdm_log", True):
94            start_qxdm_loggers(self.log, self.android_devices)
95        ensure_phones_idle(self.log, self.android_devices)
96        toggle_airplane_mode(self.log, self.ad, True)
97        self.ad.adb.shell("logcat -c -b all", ignore_status=True)
98        return True
99
100    def teardown_test(self):
101        self.log.info("Stopping Simulation")
102        self.anritsu.stop_simulation()
103        toggle_airplane_mode(self.log, self.ad, True)
104        return True
105
106    def teardown_class(self):
107        self.anritsu.disconnect()
108        return True
109
110    def _send_receive_cmas_message(
111            self,
112            set_simulation_func,
113            rat,
114            message_id,
115            warning_message,
116            c2k_response_type=CMAS_C2K_RESPONSETYPE_SHELTER,
117            c2k_severity=CMAS_C2K_SEVERITY_EXTREME,
118            c2k_urgency=CMAS_C2K_URGENCY_IMMEDIATE,
119            c2k_certainty=CMAS_C2K_CERTIANTY_OBSERVED):
120        try:
121            [self.bts1] = set_simulation_func(self.anritsu, self.user_params,
122                                              self.ad.sim_card)
123            set_usim_parameters(self.anritsu, self.ad.sim_card)
124            if rat == RAT_LTE:
125                set_post_sim_params(self.anritsu, self.user_params,
126                                    self.ad.sim_card)
127            self.anritsu.start_simulation()
128
129            if rat == RAT_LTE:
130                preferred_network_setting = NETWORK_MODE_LTE_GSM_WCDMA
131                rat_family = RAT_FAMILY_LTE
132            elif rat == RAT_WCDMA:
133                self.bts1.wcdma_ctch = CTCHSetup.CTCH_ENABLE
134                self.ad.droid.telephonyToggleDataConnection(False)
135                preferred_network_setting = NETWORK_MODE_GSM_UMTS
136                rat_family = RAT_FAMILY_UMTS
137            elif rat == RAT_GSM:
138                self.bts1.gsm_cbch = CBCHSetup.CBCH_ENABLE
139                self.ad.droid.telephonyToggleDataConnection(False)
140                preferred_network_setting = NETWORK_MODE_GSM_ONLY
141                rat_family = RAT_FAMILY_GSM
142            elif rat == RAT_1XRTT:
143                self.ad.droid.telephonyToggleDataConnection(False)
144                preferred_network_setting = NETWORK_MODE_CDMA
145                rat_family = RAT_FAMILY_CDMA2000
146            else:
147                self.log.error("No valid RAT provided for CMAS test.")
148                return False
149
150            if not ensure_network_rat(
151                    self.log,
152                    self.ad,
153                    preferred_network_setting,
154                    rat_family,
155                    toggle_apm_after_setting=True):
156                self.log.error(
157                    "Failed to set rat family {}, preferred network:{}".format(
158                        rat_family, preferred_network_setting))
159                return False
160
161            self.anritsu.wait_for_registration_state()
162            if rat != RAT_1XRTT:
163                if not cmas_receive_verify_message_lte_wcdma(
164                        self.log, self.ad, self.anritsu,
165                        next(TelLabCmasTest.SERIAL_NO), message_id,
166                        warning_message):
167                    self.log.warning("Phone {} Failed to receive CMAS message"
168                                     .format(self.ad.serial))
169                    # Another check of logcat before confirming failure
170                    if self.ad.search_logcat(warning_message):
171                        self.ad.log.info(
172                            "Confirmed from Logcat - User received %s",
173                            warning_message)
174                        return True
175                    return False
176            else:
177                if not cmas_receive_verify_message_cdma1x(
178                        self.log, self.ad, self.anritsu,
179                        next(TelLabCmasTest.SERIAL_NO), message_id,
180                        warning_message, c2k_response_type, c2k_severity,
181                        c2k_urgency, c2k_certainty):
182                    self.log.warning("Phone {} Failed to receive CMAS message"
183                                     .format(self.ad.serial))
184                    if self.ad.search_logcat(warning_message):
185                        self.ad.log.info(
186                            "Confirmed from Logcat - User received %s",
187                            warning_message)
188                        return True
189                    return False
190        except AnritsuError as e:
191            self.log.error("Error in connection with Anritsu Simulator: " +
192                           str(e))
193            return False
194        except Exception as e:
195            self.log.error("Exception during CMAS send/receive: " + str(e))
196            return False
197        return True
198
199    """ Tests Begin """
200
201    @test_tracker_info(uuid="e5ddf562-e94b-4b58-bc7d-6635c01f290e")
202    @TelephonyBaseTest.tel_test_wrap
203    def test_cmas_presidential_alert_lte(self):
204        """CMAS Presidential alert message reception on LTE
205
206        Tests the capability of device to receive and inform the user
207        about the CMAS presedential alert message when camped on LTE newtork
208
209        Steps:
210        1. Make Sure Phone is camped on LTE network
211        2. Send CMAS Presidential message from Anritsu
212
213        Expected Result:
214        Phone receives CMAS Presidential alert message
215
216        Returns:
217            True if pass; False if fail
218        """
219        return self._send_receive_cmas_message(set_system_model_lte, RAT_LTE,
220                                               CMAS_MESSAGE_PRESIDENTIAL_ALERT,
221                                               "LTE CMAS Presidential Alert")
222
223    @test_tracker_info(uuid="33be2aaa-e8a6-4832-afea-8bd7e5555cc7")
224    @TelephonyBaseTest.tel_test_wrap
225    def test_cmas_extreme_immediate_likely_lte(self):
226        """CMAS Extreme immediate likely message reception on LTE
227
228        Tests the capability of device to receive and inform the user
229        about the Extreme immediate likely message when camped on LTE newtork
230
231        1. Make Sure Phone is camped on LTE network
232        2. Send CMAS Extreme immediate likely message from Anritsu
233
234        Expected Result:
235        Phone receives CMAS Extreme immediate likely message
236
237        Returns:
238            True if pass; False if fail
239        """
240        return self._send_receive_cmas_message(
241            set_system_model_lte, RAT_LTE,
242            CMAS_MESSAGE_EXTREME_IMMEDIATE_LIKELY,
243            "LTE CMAS Extreme Immediate Likely")
244
245    @test_tracker_info(uuid="111d3b0b-020a-4818-9681-e46d1d4d61fd")
246    @TelephonyBaseTest.tel_test_wrap
247    def test_cmas_child_abduction_emergency_lte(self):
248        """CMAS Child abduction emergency message reception on LTE
249
250        Tests the capability of device to receive and inform the user
251        about the CMAS Child abduction emergency message when camped on LTE newtork
252
253        1. Make Sure Phone is camped on LTE network
254        2. Send CMAS Child abduction emergency message from Anritsu
255
256        Expected Result:
257        Phone receives CMAS Child abduction emergency message
258
259        Returns:
260            True if pass; False if fail
261        """
262        return self._send_receive_cmas_message(
263            set_system_model_lte, RAT_LTE,
264            CMAS_MESSAGE_CHILD_ABDUCTION_EMERGENCY,
265            "LTE CMAS Child abduction Alert")
266
267    @test_tracker_info(uuid="df5676b2-cfab-4d64-8c51-ed2b95642dce")
268    @TelephonyBaseTest.tel_test_wrap
269    def test_cmas_presidential_alert_wcdma(self):
270        """CMAS Presidential alert message reception on WCDMA
271
272        Tests the capability of device to receive and inform the user
273        about the CMAS presedential alert message when camped on WCDMA newtork
274
275        Steps:
276        1. Make Sure Phone is camped on WCDMA network
277        2. Send CMAS Presidential message from Anritsu
278
279        Expected Result:
280        Phone receives CMAS Presidential alert message
281
282        Returns:
283            True if pass; False if fail
284        """
285        return self._send_receive_cmas_message(
286            set_system_model_wcdma, RAT_WCDMA, CMAS_MESSAGE_PRESIDENTIAL_ALERT,
287            "WCDMA CMAS Presidential Alert")
288
289    @test_tracker_info(uuid="954544cc-75e8-408b-a5a5-4d820d0e0b3d")
290    @TelephonyBaseTest.tel_test_wrap
291    def test_cmas_extreme_immediate_likely_wcdma(self):
292        """CMAS Extreme immediate likely message reception on WCDMA
293
294        Tests the capability of device to receive and inform the user
295        about the Extreme immediate likely message when camped on WCDMA newtork
296
297        1. Make Sure Phone is camped on WCDMA network
298        2. Send CMAS Extreme immediate likely message from Anritsu
299
300        Expected Result:
301        Phone receives CMAS Extreme immediate likely message
302
303        Returns:
304            True if pass; False if fail
305        """
306        return self._send_receive_cmas_message(
307            set_system_model_wcdma, RAT_WCDMA,
308            CMAS_MESSAGE_EXTREME_IMMEDIATE_LIKELY,
309            "WCDMA CMAS Extreme Immediate Likely")
310
311    @test_tracker_info(uuid="8c681524-b217-422b-9b45-0dea9b30deed")
312    @TelephonyBaseTest.tel_test_wrap
313    def test_cmas_child_abduction_emergency_wcdma(self):
314        """CMAS Child abduction emergency message reception on WCDMA
315
316        Tests the capability of device to receive and inform the user
317        about the CMAS Child abduction emergency message when camped on WCDMA newtork
318
319        1. Make Sure Phone is camped on WCDMA network
320        2. Send CMAS Child abduction emergency message from Anritsu
321
322        Expected Result:
323        Phone receives CMAS Child abduction emergency message
324
325        Returns:
326            True if pass; False if fail
327        """
328        return self._send_receive_cmas_message(
329            set_system_model_wcdma, RAT_WCDMA,
330            CMAS_MESSAGE_CHILD_ABDUCTION_EMERGENCY,
331            "WCDMA CMAS Child abduction Alert")
332
333    @test_tracker_info(uuid="44b0c8c5-b5f4-4fe0-b62f-6586bd37c728")
334    @TelephonyBaseTest.tel_test_wrap
335    def test_cmas_presidential_alert_1x(self):
336        """CMAS Presidential alert message reception on 1x
337
338        Tests the capability of device to receive and inform the user
339        about the CMAS presedential alert message when camped on 1x newtork
340
341        Steps:
342        1. Make Sure Phone is camped on 1x network
343        2. Send CMAS Presidential message from Anritsu
344
345        Expected Result:
346        Phone receives CMAS Presidential alert message
347
348        Returns:
349            True if pass; False if fail
350        """
351        return self._send_receive_cmas_message(set_system_model_1x, RAT_1XRTT,
352                                               CMAS_C2K_CATEGORY_PRESIDENTIAL,
353                                               "1X CMAS Presidential Alert")
354
355    @test_tracker_info(uuid="67cccd46-4cce-47b2-9cba-a24abe7aedc5")
356    @TelephonyBaseTest.tel_test_wrap
357    def test_cmas_extreme_immediate_likely_1x(self):
358        """CMAS Extreme immediate likely message reception on 1x
359
360        Tests the capability of device to receive and inform the user
361        about the Extreme immediate likely message when camped on 1x newtork
362
363        1. Make Sure Phone is camped on 1x network
364        2. Send CMAS Extreme immediate likely message from Anritsu
365
366        Expected Result:
367        Phone receives CMAS Extreme immediate likely message
368
369        Returns:
370            True if pass; False if fail
371        """
372        return self._send_receive_cmas_message(
373            set_system_model_1x, RAT_1XRTT, CMAS_C2K_CATEGORY_EXTREME,
374            "1X CMAS Extreme Immediate Likely", CMAS_C2K_RESPONSETYPE_EVACUATE,
375            CMAS_C2K_SEVERITY_EXTREME, CMAS_C2K_URGENCY_IMMEDIATE,
376            CMAS_C2K_CERTIANTY_LIKELY)
377
378    @test_tracker_info(uuid="4053c54b-cda8-456a-8bce-5483732c9aee")
379    @TelephonyBaseTest.tel_test_wrap
380    def test_cmas_child_abduction_emergency_1x(self):
381        """CMAS Child abduction emergency message reception on 1x
382
383        Tests the capability of device to receive and inform the user
384        about the CMAS Child abduction emergency message when camped on 1x newtork
385
386        1. Make Sure Phone is camped on 1x network
387        2. Send CMAS Child abduction emergency message from Anritsu
388
389        Expected Result:
390        Phone receives CMAS Child abduction emergency message
391
392        Returns:
393            True if pass; False if fail
394        """
395        return self._send_receive_cmas_message(
396            set_system_model_1x, RAT_1XRTT, CMAS_C2K_CATEGORY_AMBER,
397            "1X CMAS Child abduction Alert", CMAS_C2K_RESPONSETYPE_MONITOR,
398            CMAS_C2K_SEVERITY_EXTREME, CMAS_C2K_URGENCY_IMMEDIATE,
399            CMAS_C2K_CERTIANTY_OBSERVED)
400
401    @test_tracker_info(uuid="95e4643b-3387-41ce-ac24-8db3a8f96557")
402    @TelephonyBaseTest.tel_test_wrap
403    def test_cmas_presidential_alert_1x_evdo(self):
404        """CMAS Presidential alert message reception on 1x with EVDO
405
406        Tests the capability of device to receive and inform the user
407        about the CMAS presedential alert message when camped on 1x newtork
408
409        Steps:
410        1. Make Sure Phone is camped on 1x network with EVDO
411        2. Send CMAS Presidential message from Anritsu
412
413        Expected Result:
414        Phone receives CMAS Presidential alert message
415
416        Returns:
417            True if pass; False if fail
418        """
419        return self._send_receive_cmas_message(
420            set_system_model_1x_evdo, RAT_1XRTT,
421            CMAS_C2K_CATEGORY_PRESIDENTIAL, "1X CMAS Presidential Alert")
422
423    @test_tracker_info(uuid="d1283544-81d0-4852-9387-c94826794896")
424    @TelephonyBaseTest.tel_test_wrap
425    def test_cmas_extreme_immediate_likely_1x_evdo(self):
426        """CMAS Extreme immediate likely message reception on 1x with EVDO
427
428        Tests the capability of device to receive and inform the user
429        about the Extreme immediate likely message when camped on 1x newtork
430
431        1. Make Sure Phone is camped on 1x network with EVDO
432        2. Send CMAS Extreme immediate likely message from Anritsu
433
434        Expected Result:
435        Phone receives CMAS Extreme immediate likely message
436
437        Returns:
438            True if pass; False if fail
439        """
440        return self._send_receive_cmas_message(
441            set_system_model_1x_evdo, RAT_1XRTT, CMAS_C2K_CATEGORY_EXTREME,
442            "1X CMAS Extreme Immediate Likely", CMAS_C2K_RESPONSETYPE_EVACUATE,
443            CMAS_C2K_SEVERITY_EXTREME, CMAS_C2K_URGENCY_IMMEDIATE,
444            CMAS_C2K_CERTIANTY_LIKELY)
445
446    @test_tracker_info(uuid="8ae7027e-77ec-4c9b-88e5-c20caef007a5")
447    @TelephonyBaseTest.tel_test_wrap
448    def test_cmas_child_abduction_emergency_1x_evdo(self):
449        """CMAS Child abduction emergency message reception on 1x with EVDO
450
451        Tests the capability of device to receive and inform the user
452        about the CMAS Child abduction emergency message when camped on 1x newtork
453
454        1. Make Sure Phone is camped on 1x network
455        2. Send CMAS Child abduction emergency message from Anritsu
456
457        Expected Result:
458        Phone receives CMAS Child abduction emergency message
459
460        Returns:
461            True if pass; False if fail
462        """
463        return self._send_receive_cmas_message(
464            set_system_model_1x_evdo, RAT_1XRTT, CMAS_C2K_CATEGORY_AMBER,
465            "1X CMAS Child abduction Alert", CMAS_C2K_RESPONSETYPE_MONITOR,
466            CMAS_C2K_SEVERITY_EXTREME, CMAS_C2K_URGENCY_IMMEDIATE,
467            CMAS_C2K_CERTIANTY_OBSERVED)
468
469    @test_tracker_info(uuid="7e4ab36b-4e9b-4bdf-bdb8-8356103a3e79")
470    @TelephonyBaseTest.tel_test_wrap
471    def test_cmas_presidential_alert_gsm(self):
472        """CMAS Presidential alert message reception on GSM
473
474        Tests the capability of device to receive and inform the user
475        about the CMAS presedential alert message when camped on GSM newtork
476
477        Steps:
478        1. Make Sure Phone is camped on GSM network
479        2. Send CMAS Presidential message from Anritsu
480
481        Expected Result:
482        Phone receives CMAS Presidential alert message
483
484        Returns:
485            True if pass; False if fail
486        """
487        return self._send_receive_cmas_message(set_system_model_gsm, RAT_GSM,
488                                               CMAS_MESSAGE_PRESIDENTIAL_ALERT,
489                                               "GSM CMAS Presidential Alert")
490
491    @test_tracker_info(uuid="c6d6b57b-c915-46e3-acbe-4d7f8cd6e52e")
492    @TelephonyBaseTest.tel_test_wrap
493    def test_cmas_extreme_immediate_likely_gsm(self):
494        """CMAS Extreme immediate likely message reception on GSM
495
496        Tests the capability of device to receive and inform the user
497        about the Extreme immediate likely message when camped on GSM newtork
498
499        1. Make Sure Phone is camped on GSM network
500        2. Send CMAS Extreme immediate likely message from Anritsu
501
502        Expected Result:
503        Phone receives CMAS Extreme immediate likely message
504
505        Returns:
506            True if pass; False if fail
507        """
508        return self._send_receive_cmas_message(
509            set_system_model_gsm, RAT_GSM,
510            CMAS_MESSAGE_EXTREME_IMMEDIATE_LIKELY,
511            "GSM CMAS Extreme Immediate Likely")
512
513    @test_tracker_info(uuid="eb0a51de-f5fa-4b66-b0c2-21320fca44ca")
514    @TelephonyBaseTest.tel_test_wrap
515    def test_cmas_child_abduction_emergency_gsm(self):
516        """CMAS Child abduction emergency message reception on GSM
517
518        Tests the capability of device to receive and inform the user
519        about the CMAS Child abduction emergency message when camped on GSM newtork
520
521        1. Make Sure Phone is camped on GSM network
522        2. Send CMAS Child abduction emergency message from Anritsu
523
524        Expected Result:
525        Phone receives CMAS Child abduction emergency message
526
527        Returns:
528            True if pass; False if fail
529        """
530        return self._send_receive_cmas_message(
531            set_system_model_gsm, RAT_GSM,
532            CMAS_MESSAGE_CHILD_ABDUCTION_EMERGENCY,
533            "GSM CMAS Child abduction Alert")
534
535    """ Tests End """
536