1#!/usr/bin/env python3 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 setup_class(self): 74 super().setup_class() 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.md8475_version = self.user_params.get("md8475", "A") 81 self.wait_time_between_reg_and_msg = self.user_params.get( 82 "wait_time_between_reg_and_msg", WAIT_TIME_BETWEEN_REG_AND_MSG) 83 84 try: 85 self.anritsu = MD8475A(self.md8475a_ip_address, self.wlan_option, 86 self.md8475_version) 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 def test_carrier_tmobile(self): 200 """ Sets the Carrier to TMO. 201 Returns: None 202 """ 203 setattr(self.ad, "sim_card", "FiTMO") 204 205 def test_carrier_sprint(self): 206 """ Sets the Carrier to SPR. 207 Returns: None 208 """ 209 setattr(self.ad, "sim_card", "FiSPR") 210 211 def test_carrier_uscc(self): 212 """ Sets the Carrier to USCC. 213 Returns: None 214 """ 215 setattr(self.ad, "sim_card", "FiUSCC") 216 217 """ Tests Begin """ 218 219 @test_tracker_info(uuid="e5ddf562-e94b-4b58-bc7d-6635c01f290e") 220 @TelephonyBaseTest.tel_test_wrap 221 def test_cmas_presidential_alert_lte(self): 222 """CMAS Presidential alert message reception on LTE 223 224 Tests the capability of device to receive and inform the user 225 about the CMAS presedential alert message when camped on LTE newtork 226 227 Steps: 228 1. Make Sure Phone is camped on LTE network 229 2. Send CMAS Presidential message from Anritsu 230 231 Expected Result: 232 Phone receives CMAS Presidential alert message 233 234 Returns: 235 True if pass; False if fail 236 """ 237 return self._send_receive_cmas_message(set_system_model_lte, RAT_LTE, 238 CMAS_MESSAGE_PRESIDENTIAL_ALERT, 239 "LTE CMAS Presidential Alert") 240 241 @test_tracker_info(uuid="33be2aaa-e8a6-4832-afea-8bd7e5555cc7") 242 @TelephonyBaseTest.tel_test_wrap 243 def test_cmas_extreme_immediate_likely_lte(self): 244 """CMAS Extreme immediate likely message reception on LTE 245 246 Tests the capability of device to receive and inform the user 247 about the Extreme immediate likely message when camped on LTE newtork 248 249 1. Make Sure Phone is camped on LTE network 250 2. Send CMAS Extreme immediate likely message from Anritsu 251 252 Expected Result: 253 Phone receives CMAS Extreme immediate likely message 254 255 Returns: 256 True if pass; False if fail 257 """ 258 return self._send_receive_cmas_message( 259 set_system_model_lte, RAT_LTE, 260 CMAS_MESSAGE_EXTREME_IMMEDIATE_LIKELY, 261 "LTE CMAS Extreme Immediate Likely") 262 263 @test_tracker_info(uuid="111d3b0b-020a-4818-9681-e46d1d4d61fd") 264 @TelephonyBaseTest.tel_test_wrap 265 def test_cmas_child_abduction_emergency_lte(self): 266 """CMAS Child abduction emergency message reception on LTE 267 268 Tests the capability of device to receive and inform the user 269 about the CMAS Child abduction emergency message when camped on LTE newtork 270 271 1. Make Sure Phone is camped on LTE network 272 2. Send CMAS Child abduction emergency message from Anritsu 273 274 Expected Result: 275 Phone receives CMAS Child abduction emergency message 276 277 Returns: 278 True if pass; False if fail 279 """ 280 return self._send_receive_cmas_message( 281 set_system_model_lte, RAT_LTE, 282 CMAS_MESSAGE_CHILD_ABDUCTION_EMERGENCY, 283 "LTE CMAS Child abduction Alert") 284 285 @test_tracker_info(uuid="df5676b2-cfab-4d64-8c51-ed2b95642dce") 286 @TelephonyBaseTest.tel_test_wrap 287 def test_cmas_presidential_alert_wcdma(self): 288 """CMAS Presidential alert message reception on WCDMA 289 290 Tests the capability of device to receive and inform the user 291 about the CMAS presedential alert message when camped on WCDMA newtork 292 293 Steps: 294 1. Make Sure Phone is camped on WCDMA network 295 2. Send CMAS Presidential message from Anritsu 296 297 Expected Result: 298 Phone receives CMAS Presidential alert message 299 300 Returns: 301 True if pass; False if fail 302 """ 303 return self._send_receive_cmas_message( 304 set_system_model_wcdma, RAT_WCDMA, CMAS_MESSAGE_PRESIDENTIAL_ALERT, 305 "WCDMA CMAS Presidential Alert") 306 307 @test_tracker_info(uuid="954544cc-75e8-408b-a5a5-4d820d0e0b3d") 308 @TelephonyBaseTest.tel_test_wrap 309 def test_cmas_extreme_immediate_likely_wcdma(self): 310 """CMAS Extreme immediate likely message reception on WCDMA 311 312 Tests the capability of device to receive and inform the user 313 about the Extreme immediate likely message when camped on WCDMA newtork 314 315 1. Make Sure Phone is camped on WCDMA network 316 2. Send CMAS Extreme immediate likely message from Anritsu 317 318 Expected Result: 319 Phone receives CMAS Extreme immediate likely message 320 321 Returns: 322 True if pass; False if fail 323 """ 324 return self._send_receive_cmas_message( 325 set_system_model_wcdma, RAT_WCDMA, 326 CMAS_MESSAGE_EXTREME_IMMEDIATE_LIKELY, 327 "WCDMA CMAS Extreme Immediate Likely") 328 329 @test_tracker_info(uuid="8c681524-b217-422b-9b45-0dea9b30deed") 330 @TelephonyBaseTest.tel_test_wrap 331 def test_cmas_child_abduction_emergency_wcdma(self): 332 """CMAS Child abduction emergency message reception on WCDMA 333 334 Tests the capability of device to receive and inform the user 335 about the CMAS Child abduction emergency message when camped on WCDMA newtork 336 337 1. Make Sure Phone is camped on WCDMA network 338 2. Send CMAS Child abduction emergency message from Anritsu 339 340 Expected Result: 341 Phone receives CMAS Child abduction emergency message 342 343 Returns: 344 True if pass; False if fail 345 """ 346 return self._send_receive_cmas_message( 347 set_system_model_wcdma, RAT_WCDMA, 348 CMAS_MESSAGE_CHILD_ABDUCTION_EMERGENCY, 349 "WCDMA CMAS Child abduction Alert") 350 351 @test_tracker_info(uuid="44b0c8c5-b5f4-4fe0-b62f-6586bd37c728") 352 @TelephonyBaseTest.tel_test_wrap 353 def test_cmas_presidential_alert_1x(self): 354 """CMAS Presidential alert message reception on 1x 355 356 Tests the capability of device to receive and inform the user 357 about the CMAS presedential alert message when camped on 1x newtork 358 359 Steps: 360 1. Make Sure Phone is camped on 1x network 361 2. Send CMAS Presidential message from Anritsu 362 363 Expected Result: 364 Phone receives CMAS Presidential alert message 365 366 Returns: 367 True if pass; False if fail 368 """ 369 return self._send_receive_cmas_message(set_system_model_1x, RAT_1XRTT, 370 CMAS_C2K_CATEGORY_PRESIDENTIAL, 371 "1X CMAS Presidential Alert") 372 373 @test_tracker_info(uuid="67cccd46-4cce-47b2-9cba-a24abe7aedc5") 374 @TelephonyBaseTest.tel_test_wrap 375 def test_cmas_extreme_immediate_likely_1x(self): 376 """CMAS Extreme immediate likely message reception on 1x 377 378 Tests the capability of device to receive and inform the user 379 about the Extreme immediate likely message when camped on 1x newtork 380 381 1. Make Sure Phone is camped on 1x network 382 2. Send CMAS Extreme immediate likely message from Anritsu 383 384 Expected Result: 385 Phone receives CMAS Extreme immediate likely message 386 387 Returns: 388 True if pass; False if fail 389 """ 390 return self._send_receive_cmas_message( 391 set_system_model_1x, RAT_1XRTT, CMAS_C2K_CATEGORY_EXTREME, 392 "1X CMAS Extreme Immediate Likely", CMAS_C2K_RESPONSETYPE_EVACUATE, 393 CMAS_C2K_SEVERITY_EXTREME, CMAS_C2K_URGENCY_IMMEDIATE, 394 CMAS_C2K_CERTIANTY_LIKELY) 395 396 @test_tracker_info(uuid="4053c54b-cda8-456a-8bce-5483732c9aee") 397 @TelephonyBaseTest.tel_test_wrap 398 def test_cmas_child_abduction_emergency_1x(self): 399 """CMAS Child abduction emergency message reception on 1x 400 401 Tests the capability of device to receive and inform the user 402 about the CMAS Child abduction emergency message when camped on 1x newtork 403 404 1. Make Sure Phone is camped on 1x network 405 2. Send CMAS Child abduction emergency message from Anritsu 406 407 Expected Result: 408 Phone receives CMAS Child abduction emergency message 409 410 Returns: 411 True if pass; False if fail 412 """ 413 return self._send_receive_cmas_message( 414 set_system_model_1x, RAT_1XRTT, CMAS_C2K_CATEGORY_AMBER, 415 "1X CMAS Child abduction Alert", CMAS_C2K_RESPONSETYPE_MONITOR, 416 CMAS_C2K_SEVERITY_EXTREME, CMAS_C2K_URGENCY_IMMEDIATE, 417 CMAS_C2K_CERTIANTY_OBSERVED) 418 419 @test_tracker_info(uuid="95e4643b-3387-41ce-ac24-8db3a8f96557") 420 @TelephonyBaseTest.tel_test_wrap 421 def test_cmas_presidential_alert_1x_evdo(self): 422 """CMAS Presidential alert message reception on 1x with EVDO 423 424 Tests the capability of device to receive and inform the user 425 about the CMAS presedential alert message when camped on 1x newtork 426 427 Steps: 428 1. Make Sure Phone is camped on 1x network with EVDO 429 2. Send CMAS Presidential message from Anritsu 430 431 Expected Result: 432 Phone receives CMAS Presidential alert message 433 434 Returns: 435 True if pass; False if fail 436 """ 437 return self._send_receive_cmas_message( 438 set_system_model_1x_evdo, RAT_1XRTT, 439 CMAS_C2K_CATEGORY_PRESIDENTIAL, "1X CMAS Presidential Alert") 440 441 @test_tracker_info(uuid="d1283544-81d0-4852-9387-c94826794896") 442 @TelephonyBaseTest.tel_test_wrap 443 def test_cmas_extreme_immediate_likely_1x_evdo(self): 444 """CMAS Extreme immediate likely message reception on 1x with EVDO 445 446 Tests the capability of device to receive and inform the user 447 about the Extreme immediate likely message when camped on 1x newtork 448 449 1. Make Sure Phone is camped on 1x network with EVDO 450 2. Send CMAS Extreme immediate likely message from Anritsu 451 452 Expected Result: 453 Phone receives CMAS Extreme immediate likely message 454 455 Returns: 456 True if pass; False if fail 457 """ 458 return self._send_receive_cmas_message( 459 set_system_model_1x_evdo, RAT_1XRTT, CMAS_C2K_CATEGORY_EXTREME, 460 "1X CMAS Extreme Immediate Likely", CMAS_C2K_RESPONSETYPE_EVACUATE, 461 CMAS_C2K_SEVERITY_EXTREME, CMAS_C2K_URGENCY_IMMEDIATE, 462 CMAS_C2K_CERTIANTY_LIKELY) 463 464 @test_tracker_info(uuid="8ae7027e-77ec-4c9b-88e5-c20caef007a5") 465 @TelephonyBaseTest.tel_test_wrap 466 def test_cmas_child_abduction_emergency_1x_evdo(self): 467 """CMAS Child abduction emergency message reception on 1x with EVDO 468 469 Tests the capability of device to receive and inform the user 470 about the CMAS Child abduction emergency message when camped on 1x newtork 471 472 1. Make Sure Phone is camped on 1x network 473 2. Send CMAS Child abduction emergency message from Anritsu 474 475 Expected Result: 476 Phone receives CMAS Child abduction emergency message 477 478 Returns: 479 True if pass; False if fail 480 """ 481 return self._send_receive_cmas_message( 482 set_system_model_1x_evdo, RAT_1XRTT, CMAS_C2K_CATEGORY_AMBER, 483 "1X CMAS Child abduction Alert", CMAS_C2K_RESPONSETYPE_MONITOR, 484 CMAS_C2K_SEVERITY_EXTREME, CMAS_C2K_URGENCY_IMMEDIATE, 485 CMAS_C2K_CERTIANTY_OBSERVED) 486 487 @test_tracker_info(uuid="7e4ab36b-4e9b-4bdf-bdb8-8356103a3e79") 488 @TelephonyBaseTest.tel_test_wrap 489 def test_cmas_presidential_alert_gsm(self): 490 """CMAS Presidential alert message reception on GSM 491 492 Tests the capability of device to receive and inform the user 493 about the CMAS presedential alert message when camped on GSM newtork 494 495 Steps: 496 1. Make Sure Phone is camped on GSM network 497 2. Send CMAS Presidential message from Anritsu 498 499 Expected Result: 500 Phone receives CMAS Presidential alert message 501 502 Returns: 503 True if pass; False if fail 504 """ 505 return self._send_receive_cmas_message(set_system_model_gsm, RAT_GSM, 506 CMAS_MESSAGE_PRESIDENTIAL_ALERT, 507 "GSM CMAS Presidential Alert") 508 509 @test_tracker_info(uuid="c6d6b57b-c915-46e3-acbe-4d7f8cd6e52e") 510 @TelephonyBaseTest.tel_test_wrap 511 def test_cmas_extreme_immediate_likely_gsm(self): 512 """CMAS Extreme immediate likely message reception on GSM 513 514 Tests the capability of device to receive and inform the user 515 about the Extreme immediate likely message when camped on GSM newtork 516 517 1. Make Sure Phone is camped on GSM network 518 2. Send CMAS Extreme immediate likely message from Anritsu 519 520 Expected Result: 521 Phone receives CMAS Extreme immediate likely message 522 523 Returns: 524 True if pass; False if fail 525 """ 526 return self._send_receive_cmas_message( 527 set_system_model_gsm, RAT_GSM, 528 CMAS_MESSAGE_EXTREME_IMMEDIATE_LIKELY, 529 "GSM CMAS Extreme Immediate Likely") 530 531 @test_tracker_info(uuid="eb0a51de-f5fa-4b66-b0c2-21320fca44ca") 532 @TelephonyBaseTest.tel_test_wrap 533 def test_cmas_child_abduction_emergency_gsm(self): 534 """CMAS Child abduction emergency message reception on GSM 535 536 Tests the capability of device to receive and inform the user 537 about the CMAS Child abduction emergency message when camped on GSM newtork 538 539 1. Make Sure Phone is camped on GSM network 540 2. Send CMAS Child abduction emergency message from Anritsu 541 542 Expected Result: 543 Phone receives CMAS Child abduction emergency message 544 545 Returns: 546 True if pass; False if fail 547 """ 548 return self._send_receive_cmas_message( 549 set_system_model_gsm, RAT_GSM, 550 CMAS_MESSAGE_CHILD_ABDUCTION_EMERGENCY, 551 "GSM CMAS Child abduction Alert") 552 553 """ Tests End """ 554