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 MD8475A 23from acts.controllers.anritsu_lib.md8475a import CBCHSetup 24from acts.controllers.anritsu_lib.md8475a import CTCHSetup 25from acts.test_utils.tel.anritsu_utils import ETWS_WARNING_EARTHQUAKETSUNAMI 26from acts.test_utils.tel.anritsu_utils import ETWS_WARNING_OTHER_EMERGENCY 27from acts.test_utils.tel.anritsu_utils import cb_serial_number 28from acts.test_utils.tel.anritsu_utils import etws_receive_verify_message_lte_wcdma 29from acts.test_utils.tel.anritsu_utils import set_system_model_gsm 30from acts.test_utils.tel.anritsu_utils import set_system_model_lte 31from acts.test_utils.tel.anritsu_utils import set_system_model_wcdma 32from acts.test_utils.tel.anritsu_utils import set_usim_parameters 33from acts.test_utils.tel.anritsu_utils import set_post_sim_params 34from acts.test_utils.tel.tel_defines import NETWORK_MODE_CDMA 35from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_ONLY 36from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_UMTS 37from acts.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA 38from acts.test_utils.tel.tel_defines import RAT_1XRTT 39from acts.test_utils.tel.tel_defines import RAT_GSM 40from acts.test_utils.tel.tel_defines import RAT_LTE 41from acts.test_utils.tel.tel_defines import RAT_WCDMA 42from acts.test_utils.tel.tel_defines import RAT_FAMILY_CDMA2000 43from acts.test_utils.tel.tel_defines import RAT_FAMILY_GSM 44from acts.test_utils.tel.tel_defines import RAT_FAMILY_LTE 45from acts.test_utils.tel.tel_defines import RAT_FAMILY_UMTS 46from acts.test_utils.tel.tel_test_utils import ensure_network_rat 47from acts.test_utils.tel.tel_test_utils import ensure_phones_idle 48from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode 49from acts.test_utils.tel.tel_test_utils import start_qxdm_loggers 50from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest 51from acts.test_decorators import test_tracker_info 52 53WAIT_TIME_BETWEEN_REG_AND_MSG = 15 # default 15 sec 54 55 56class TelLabEtwsTest(TelephonyBaseTest): 57 SERIAL_NO = cb_serial_number() 58 59 def __init__(self, controllers): 60 TelephonyBaseTest.__init__(self, controllers) 61 self.ad = self.android_devices[0] 62 self.ad.sim_card = getattr(self.ad, "sim_card", None) 63 self.md8475a_ip_address = self.user_params[ 64 "anritsu_md8475a_ip_address"] 65 self.wlan_option = self.user_params.get("anritsu_wlan_option", False) 66 self.md8475_version = self.user_params.get("md8475", "A") 67 self.ad.adb.shell("settings put secure cmas_additional_broadcast_pkg " 68 "com.googlecode.android_scripting") 69 self.wait_time_between_reg_and_msg = self.user_params.get( 70 "wait_time_between_reg_and_msg", WAIT_TIME_BETWEEN_REG_AND_MSG) 71 72 def setup_class(self): 73 try: 74 self.anritsu = MD8475A(self.md8475a_ip_address, self.log, 75 self.wlan_option, self.md8475_version) 76 except AnritsuError: 77 self.log.error("Error in connecting to Anritsu Simulator") 78 return False 79 return True 80 81 def setup_test(self): 82 if getattr(self, "qxdm_log", True): 83 start_qxdm_loggers(self.log, self.android_devices) 84 ensure_phones_idle(self.log, self.android_devices) 85 toggle_airplane_mode(self.log, self.ad, True) 86 return True 87 88 def teardown_test(self): 89 self.log.info("Stopping Simulation") 90 self.anritsu.stop_simulation() 91 toggle_airplane_mode(self.log, self.ad, True) 92 93 def teardown_class(self): 94 self.anritsu.disconnect() 95 return True 96 97 def _send_receive_etws_message(self, set_simulation_func, rat, message_id, 98 warning_message): 99 try: 100 [self.bts1] = set_simulation_func(self.anritsu, self.user_params, 101 self.ad.sim_card) 102 set_usim_parameters(self.anritsu, self.ad.sim_card) 103 if rat == RAT_LTE: 104 set_post_sim_params(self.anritsu, self.user_params, 105 self.ad.sim_card) 106 self.anritsu.start_simulation() 107 108 if rat == RAT_LTE: 109 preferred_network_setting = NETWORK_MODE_LTE_GSM_WCDMA 110 rat_family = RAT_FAMILY_LTE 111 elif rat == RAT_WCDMA: 112 self.bts1.wcdma_ctch = CTCHSetup.CTCH_ENABLE 113 self.ad.droid.telephonyToggleDataConnection(False) 114 preferred_network_setting = NETWORK_MODE_GSM_UMTS 115 rat_family = RAT_FAMILY_UMTS 116 elif rat == RAT_GSM: 117 self.bts1.gsm_cbch = CBCHSetup.CBCH_ENABLE 118 self.ad.droid.telephonyToggleDataConnection(False) 119 preferred_network_setting = NETWORK_MODE_GSM_ONLY 120 rat_family = RAT_FAMILY_GSM 121 elif rat == RAT_1XRTT: 122 preferred_network_setting = NETWORK_MODE_CDMA 123 rat_family = RAT_FAMILY_CDMA2000 124 else: 125 self.log.error("No valid RAT provided for ETWS test.") 126 return False 127 128 if not ensure_network_rat( 129 self.log, 130 self.ad, 131 preferred_network_setting, 132 rat_family, 133 toggle_apm_after_setting=True): 134 self.log.error( 135 "Failed to set rat family {}, preferred network:{}".format( 136 rat_family, preferred_network_setting)) 137 return False 138 139 self.anritsu.wait_for_registration_state() 140 if not etws_receive_verify_message_lte_wcdma( 141 self.log, self.ad, self.anritsu, 142 next(TelLabEtwsTest.SERIAL_NO), message_id, 143 warning_message): 144 self.log.error("Phone {} Failed to receive ETWS message" 145 .format(self.ad.serial)) 146 return False 147 except AnritsuError as e: 148 self.log.error("Error in connection with Anritsu Simulator: " + 149 str(e)) 150 return False 151 except Exception as e: 152 self.log.error("Exception during ETWS send/receive: " + str(e)) 153 return False 154 return True 155 156 def test_carrier_tmobile(self): 157 """ Sets the Carrier to TMO. 158 Returns: None 159 """ 160 setattr(self.ad, "sim_card", "FiTMO") 161 162 def test_carrier_sprint(self): 163 """ Sets the Carrier to SPR. 164 Returns: None 165 """ 166 setattr(self.ad, "sim_card", "FiSPR") 167 168 def test_carrier_uscc(self): 169 """ Sets the Carrier to USCC. 170 Returns: None 171 """ 172 setattr(self.ad, "sim_card", "FiUSCC") 173 174 """ Tests Begin """ 175 176 @test_tracker_info(uuid="af4a00d0-9a91-45d5-9f65-9541e64a57f2") 177 @TelephonyBaseTest.tel_test_wrap 178 def test_etws_earthquake_tsunami_lte(self): 179 """ETWS Earthquake and Tsunami warning message reception on LTE 180 181 Tests the capability of device to receive and inform the user 182 about the ETWS Earthquake and Tsunami warning message when camped on 183 LTE newtork 184 185 Steps: 186 1. Make Sure Phone is camped on LTE network 187 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 188 189 Expected Result: 190 Phone receives ETWS Earthquake and Tsunami warning message 191 192 Returns: 193 True if pass; False if fail 194 """ 195 return self._send_receive_etws_message(set_system_model_lte, RAT_LTE, 196 ETWS_WARNING_EARTHQUAKETSUNAMI, 197 "LTE Earthquake and Tsunami") 198 199 @test_tracker_info(uuid="03785878-0319-413c-9190-d4e08f0edc33") 200 @TelephonyBaseTest.tel_test_wrap 201 def test_etws_other_emergency_lte(self): 202 """ETWS Other emergency warning message reception on LTE 203 204 Tests the capability of device to receive and inform the user 205 about the ETWS Other emergency warning message when camped on 206 LTE newtork 207 208 Steps: 209 1. Make Sure Phone is camped on LTE network 210 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 211 212 Expected Result: 213 Phone receives ETWS Earthquake and Tsunami warning message 214 215 Returns: 216 True if pass; False if fail 217 """ 218 return self._send_receive_etws_message(set_system_model_lte, RAT_LTE, 219 ETWS_WARNING_OTHER_EMERGENCY, 220 "LTE ETWS Other Emergency") 221 222 @test_tracker_info(uuid="1ef4a5d7-9ceb-49eb-8ec7-5538625c8bd4") 223 @TelephonyBaseTest.tel_test_wrap 224 def test_etws_earthquake_tsunami_wcdma(self): 225 """ETWS Earthquake and Tsunami warning message reception on WCDMA 226 227 Tests the capability of device to receive and inform the user 228 about the ETWS Earthquake and Tsunami warning message when camped on 229 WCDMA newtork 230 231 Steps: 232 1. Make Sure Phone is camped on WCDMA network 233 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 234 235 Expected Result: 236 Phone receives ETWS Earthquake and Tsunami warning message 237 238 Returns: 239 True if pass; False if fail 240 """ 241 return self._send_receive_etws_message( 242 set_system_model_wcdma, RAT_WCDMA, ETWS_WARNING_EARTHQUAKETSUNAMI, 243 "WCDMA Earthquake and Tsunami") 244 245 @test_tracker_info(uuid="71dc9650-d00a-4533-99f5-5cc301c21334") 246 @TelephonyBaseTest.tel_test_wrap 247 def test_etws_other_emergency_wcdma(self): 248 """ETWS Other emergency warning message reception on WCDMA 249 250 Tests the capability of device to receive and inform the user 251 about the ETWS Other emergency warning message when camped on 252 WCDMA newtork 253 254 Steps: 255 1. Make Sure Phone is camped on WCDMA network 256 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 257 258 Expected Result: 259 Phone receives ETWS Earthquake and Tsunami warning message 260 261 Returns: 262 True if pass; False if fail 263 """ 264 return self._send_receive_etws_message( 265 set_system_model_wcdma, RAT_WCDMA, ETWS_WARNING_OTHER_EMERGENCY, 266 "WCDMA ETWS Other Emergency") 267 268 @test_tracker_info(uuid="a9fd9c0e-21bf-41d1-81d2-c34679052fe0") 269 @TelephonyBaseTest.tel_test_wrap 270 def test_etws_earthquake_tsunami_gsm(self): 271 """ETWS Earthquake and Tsunami warning message reception on GSM 272 273 Tests the capability of device to receive and inform the user 274 about the ETWS Earthquake and Tsunami warning message when camped on 275 GSM newtork 276 277 Steps: 278 1. Make Sure Phone is camped on GSM network 279 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 280 281 Expected Result: 282 Phone receives ETWS Earthquake and Tsunami warning message 283 284 Returns: 285 True if pass; False if fail 286 """ 287 return self._send_receive_etws_message(set_system_model_gsm, RAT_GSM, 288 ETWS_WARNING_EARTHQUAKETSUNAMI, 289 "GSM Earthquake and Tsunami") 290 291 @test_tracker_info(uuid="0ae42f8d-1720-449c-9200-e88f7f1d2cbe") 292 @TelephonyBaseTest.tel_test_wrap 293 def test_etws_other_emergency_gsm(self): 294 """ETWS Other emergency warning message reception on GSM 295 296 Tests the capability of device to receive and inform the user 297 about the ETWS Other emergency warning message when camped on 298 GSM newtork 299 300 Steps: 301 1. Make Sure Phone is camped on GSM network 302 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 303 304 Expected Result: 305 Phone receives ETWS Earthquake and Tsunami warning message 306 307 Returns: 308 True if pass; False if fail 309 """ 310 return self._send_receive_etws_message(set_system_model_gsm, RAT_GSM, 311 ETWS_WARNING_OTHER_EMERGENCY, 312 "GSM ETWS Other Emergency") 313 314 """ Tests End """ 315