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 Stress Call Test 18""" 19 20import collections 21import time 22from acts.test_decorators import test_tracker_info 23from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest 24from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED 25from acts.test_utils.tel.tel_defines import VT_STATE_BIDIRECTIONAL 26from acts.test_utils.tel.tel_test_utils import call_setup_teardown 27from acts.test_utils.tel.tel_test_utils import ensure_phone_subscription 28from acts.test_utils.tel.tel_test_utils import ensure_phones_idle 29from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected 30from acts.test_utils.tel.tel_test_utils import hangup_call 31from acts.test_utils.tel.tel_test_utils import set_wfc_mode 32from acts.test_utils.tel.tel_test_utils import sms_send_receive_verify 33from acts.test_utils.tel.tel_test_utils import start_qxdm_loggers 34from acts.test_utils.tel.tel_test_utils import verify_incall_state 35from acts.test_utils.tel.tel_test_utils import multithread_func 36from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode 37from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_3g 38from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_2g 39from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb 40from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan 41from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte 42from acts.test_utils.tel.tel_voice_utils import phone_setup_csfb 43from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan 44from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_3g 45from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_2g 46from acts.test_utils.tel.tel_voice_utils import phone_setup_volte 47from acts.test_utils.tel.tel_voice_utils import phone_idle_iwlan 48from acts.test_utils.tel.tel_video_utils import phone_setup_video 49from acts.test_utils.tel.tel_video_utils import video_call_setup 50from acts.test_utils.tel.tel_video_utils import \ 51 is_phone_in_call_video_bidirectional 52from acts.logger import epoch_to_log_line_timestamp 53from acts.utils import get_current_epoch_time 54from acts.utils import rand_ascii_str 55 56 57class TelLiveStressCallTest(TelephonyBaseTest): 58 def setup_class(self): 59 super(TelLiveStressCallTest, self).setup_class() 60 self.caller = self.android_devices[0] 61 self.callee = self.android_devices[1] 62 self.number_of_devices = 2 63 self.user_params["telephony_auto_rerun"] = False 64 self.wifi_network_ssid = self.user_params.get( 65 "wifi_network_ssid") or self.user_params.get("wifi_network_ssid_2g") 66 self.wifi_network_pass = self.user_params.get( 67 "wifi_network_pass") or self.user_params.get("wifi_network_pass_2g") 68 self.phone_call_iteration = int( 69 self.user_params.get("phone_call_iteration", 500)) 70 self.phone_call_duration = int( 71 self.user_params.get("phone_call_duration", 60)) 72 self.sleep_time_between_test_iterations = int( 73 self.user_params.get("sleep_time_between_test_iterations", 0)) 74 75 return True 76 77 def on_fail(self, test_name, begin_time): 78 pass 79 80 def _setup_wfc(self): 81 for ad in self.android_devices: 82 if not ensure_wifi_connected( 83 ad.log, 84 ad, 85 self.wifi_network_ssid, 86 self.wifi_network_pass, 87 retries=3): 88 ad.log.error("Phone Wifi connection fails.") 89 return False 90 ad.log.info("Phone WIFI is connected successfully.") 91 if not set_wfc_mode(self.log, ad, WFC_MODE_WIFI_PREFERRED): 92 ad.log.error("Phone failed to enable Wifi-Calling.") 93 return False 94 ad.log.info("Phone is set in Wifi-Calling successfully.") 95 if not phone_idle_iwlan(self.log, ad): 96 ad.log.error("Phone is not in WFC enabled state.") 97 return False 98 ad.log.info("Phone is in WFC enabled state.") 99 return True 100 101 def _setup_wfc_apm(self): 102 for ad in self.android_devices: 103 toggle_airplane_mode(ad.log, ad, True) 104 if not ensure_wifi_connected( 105 ad.log, 106 ad, 107 self.wifi_network_ssid, 108 self.wifi_network_pass, 109 retries=3): 110 ad.log.error("Phone Wifi connection fails.") 111 return False 112 ad.log.info("Phone WIFI is connected successfully.") 113 if not set_wfc_mode(self.log, ad, WFC_MODE_WIFI_PREFERRED): 114 ad.log.error("Phone failed to enable Wifi-Calling.") 115 return False 116 ad.log.info("Phone is set in Wifi-Calling successfully.") 117 if not phone_idle_iwlan(self.log, ad): 118 ad.log.error("Phone is not in WFC enabled state.") 119 return False 120 ad.log.info("Phone is in WFC enabled state.") 121 return True 122 123 def _setup_vt(self): 124 ads = self.android_devices 125 tasks = [(phone_setup_video, (self.log, ads[0])), (phone_setup_video, 126 (self.log, ads[1]))] 127 if not multithread_func(self.log, tasks): 128 self.log.error("Phone Failed to Set Up Properly.") 129 return False 130 return True 131 132 def _setup_lte_volte_enabled(self): 133 for ad in self.android_devices: 134 if not phone_setup_volte(self.log, ad): 135 ad.log.error("Phone failed to enable VoLTE.") 136 return False 137 ad.log.info("Phone VOLTE is enabled successfully.") 138 return True 139 140 def _setup_lte_volte_disabled(self): 141 for ad in self.android_devices: 142 if not phone_setup_csfb(self.log, ad): 143 ad.log.error("Phone failed to setup CSFB.") 144 return False 145 ad.log.info("Phone VOLTE is disabled successfully.") 146 return True 147 148 def _setup_3g(self): 149 for ad in self.android_devices: 150 if not phone_setup_voice_3g(self.log, ad): 151 ad.log.error("Phone failed to setup 3g.") 152 return False 153 ad.log.info("Phone RAT 3G is enabled successfully.") 154 return True 155 156 def _setup_2g(self): 157 for ad in self.android_devices: 158 if not phone_setup_voice_2g(self.log, ad): 159 ad.log.error("Phone failed to setup 2g.") 160 return False 161 ad.log.info("RAT 2G is enabled successfully.") 162 return True 163 164 def _setup_phone_call(self, test_video): 165 if test_video: 166 if not video_call_setup( 167 self.log, 168 self.android_devices[0], 169 self.android_devices[1], ): 170 self.log.error("Failed to setup Video call") 171 return False 172 else: 173 if not call_setup_teardown( 174 self.log, self.caller, self.callee, ad_hangup=None): 175 self.log.error("Setup Call failed.") 176 return False 177 self.log.info("Setup call successfully.") 178 return True 179 180 def _hangup_call(self): 181 for ad in self.android_devices: 182 hangup_call(self.log, ad) 183 184 def stress_test(self, 185 setup_func=None, 186 network_check_func=None, 187 test_sms=False, 188 test_video=False): 189 for ad in self.android_devices: 190 #check for sim and service 191 ensure_phone_subscription(self.log, ad) 192 193 if setup_func and not setup_func(): 194 self.log.error("Test setup %s failed", setup_func.__name__) 195 return False 196 fail_count = collections.defaultdict(int) 197 for i in range(1, self.phone_call_iteration + 1): 198 msg = "Stress Call Test %s Iteration: <%s> / <%s>" % ( 199 self.test_name, i, self.phone_call_iteration) 200 begin_time = get_current_epoch_time() 201 self.log.info(msg) 202 iteration_result = True 203 ensure_phones_idle(self.log, self.android_devices) 204 205 if not self._setup_phone_call(test_video): 206 fail_count["dialing"] += 1 207 iteration_result = False 208 self.log.error("%s call dialing failure.", msg) 209 else: 210 if network_check_func and not network_check_func( 211 self.log, self.caller): 212 fail_count["caller_network_check"] += 1 213 reasons = self.caller.search_logcat( 214 "qcril_qmi_voice_map_qmi_to_ril_last_call_failure_cause", 215 begin_time) 216 if reasons: 217 self.caller.log.info(reasons[-1]["log_message"]) 218 iteration_result = False 219 self.log.error("%s network check %s failure.", msg, 220 network_check_func.__name__) 221 222 if network_check_func and not network_check_func( 223 self.log, self.callee): 224 fail_count["callee_network_check"] += 1 225 reasons = self.callee.search_logcat( 226 "qcril_qmi_voice_map_qmi_to_ril_last_call_failure_cause", 227 begin_time) 228 if reasons: 229 self.callee.log.info(reasons[-1]["log_message"]) 230 iteration_result = False 231 self.log.error("%s network check failure.", msg) 232 233 time.sleep(self.phone_call_duration) 234 235 if not verify_incall_state(self.log, 236 [self.caller, self.callee], True): 237 self.log.error("%s call dropped.", msg) 238 iteration_result = False 239 fail_count["drop"] += 1 240 241 self._hangup_call() 242 243 if test_sms and not sms_send_receive_verify( 244 self.log, self.caller, self.callee, [rand_ascii_str(180)]): 245 fail_count["sms"] += 1 246 247 self.log.info("%s %s", msg, iteration_result) 248 if not iteration_result: 249 self._take_bug_report("%s_CallNo_%s" % (self.test_name, i), 250 begin_time) 251 start_qxdm_loggers(self.log, self.android_devices) 252 253 if self.sleep_time_between_test_iterations: 254 self.caller.droid.goToSleepNow() 255 self.callee.droid.goToSleepNow() 256 time.sleep(self.sleep_time_between_test_iterations) 257 258 test_result = True 259 for failure, count in fail_count.items(): 260 if count: 261 self.log.error("%s: %s %s failures in %s iterations", 262 self.test_name, count, failure, 263 self.phone_call_iteration) 264 test_result = False 265 return test_result 266 267 """ Tests Begin """ 268 269 @test_tracker_info(uuid="3c3daa08-e66a-451a-a772-634ec522c965") 270 @TelephonyBaseTest.tel_test_wrap 271 def test_call_default_stress(self): 272 """ Default state call stress test 273 274 Steps: 275 1. Make Sure PhoneA and PhoneB in default mode. 276 2. Call from PhoneA to PhoneB, hang up on PhoneA. 277 3, Repeat 2 around N times based on the config setup 278 279 Expected Results: 280 1, Verify phone is at IDLE state 281 2, Verify the phone is at ACTIVE, if it is in dialing, then we retry 282 3, Verify the phone is IDLE after hung up 283 284 Returns: 285 True if pass; False if fail. 286 """ 287 return self.stress_test() 288 289 @test_tracker_info(uuid="b7fd730a-d4c7-444c-9e36-12389679b430") 290 @TelephonyBaseTest.tel_test_wrap 291 def test_call_and_sms_longevity(self): 292 """ Default state call stress test 293 294 Steps: 295 1. Make Sure PhoneA and PhoneB in default mode. 296 2. Call from PhoneA to PhoneB, hang up on PhoneA. 297 3. Send a text message from PhoneA to PhoneB. 298 4. Bring phone to sleep for x seconds based on the config setup. 299 5, Repeat 2 around N times based on the config setup 300 301 Expected Results: 302 1. Phone calls and text messages are successfully made 303 304 Returns: 305 True if pass; False if fail. 306 """ 307 return self.stress_test(test_sms=True) 308 309 @test_tracker_info(uuid="3b711843-de27-4b0a-a163-8c439c901e24") 310 @TelephonyBaseTest.tel_test_wrap 311 def test_call_volte_stress(self): 312 """ VoLTE call stress test 313 314 Steps: 315 1. Make Sure PhoneA and PhoneB in VoLTE mode. 316 2. Call from PhoneA to PhoneB, hang up on PhoneA. 317 3, Repeat 2 around N times based on the config setup 318 319 Expected Results: 320 1, Verify phone is at IDLE state 321 2, Verify the phone is at ACTIVE, if it is in dialing, then we retry 322 3, Verify the phone is IDLE after hung up 323 324 Returns: 325 True if pass; False if fail. 326 """ 327 return self.stress_test( 328 setup_func=self._setup_lte_volte_enabled, 329 network_check_func=is_phone_in_call_volte) 330 331 @test_tracker_info(uuid="518516ea-1c0a-494d-ad44-272f21075d39") 332 @TelephonyBaseTest.tel_test_wrap 333 def test_call_csfb_stress(self): 334 """ LTE CSFB call stress test 335 336 Steps: 337 1. Make Sure PhoneA in LTE CSFB mode. 338 2. Call from PhoneA to PhoneB, hang up on PhoneA. 339 3, Repeat 2 around N times based on the config setup 340 341 Expected Results: 342 1, Verify phone is at IDLE state 343 2, Verify the phone is at ACTIVE, if it is in dialing, then we retry 344 3, Verify the phone is IDLE after hung up 345 346 Returns: 347 True if pass; False if fail. 348 """ 349 return self.stress_test( 350 setup_func=self._setup_lte_volte_disabled, 351 network_check_func=is_phone_in_call_csfb) 352 353 @test_tracker_info(uuid="887608cb-e5c6-4b19-b02b-3461c1e78f2d") 354 @TelephonyBaseTest.tel_test_wrap 355 def test_call_wifi_calling_stress(self): 356 """ Wifi calling call stress test 357 358 Steps: 359 1. Make Sure PhoneA and PhoneB in WFC On + Wifi Connected 360 2. Call from PhoneA to PhoneB, hang up on PhoneA. 361 3, Repeat 2 around N times based on the config setup 362 363 Expected Results: 364 1, Verify phone is at IDLE state 365 2, Verify the phone is at ACTIVE, if it is in dialing, then we retry 366 3, Verify the phone is IDLE after hung up 367 368 Returns: 369 True if pass; False if fail. 370 """ 371 return self.stress_test( 372 setup_func=self._setup_wfc, 373 network_check_func=is_phone_in_call_iwlan) 374 375 @test_tracker_info(uuid="be45c620-b45b-4a06-8424-b17d744d0735") 376 @TelephonyBaseTest.tel_test_wrap 377 def test_call_wifi_calling_stress_apm(self): 378 """ Wifi calling in AirPlaneMode call stress test 379 380 Steps: 381 1. Make Sure PhoneA and PhoneB in WFC On + APM ON + Wifi Connected 382 2. Call from PhoneA to PhoneB, hang up on PhoneA. 383 3, Repeat 2 around N times based on the config setup 384 385 Expected Results: 386 1, Verify phone is at IDLE state 387 2, Verify the phone is at ACTIVE, if it is in dialing, then we retry 388 3, Verify the phone is IDLE after hung up 389 390 Returns: 391 True if pass; False if fail. 392 """ 393 return self.stress_test( 394 setup_func=self._setup_wfc_apm, 395 network_check_func=is_phone_in_call_iwlan) 396 397 @test_tracker_info(uuid="8af0454b-b4db-46d8-b5cc-e13ec5bc59ab") 398 @TelephonyBaseTest.tel_test_wrap 399 def test_call_3g_stress(self): 400 """ 3G call stress test 401 402 Steps: 403 1. Make Sure PhoneA and PhoneB in 3G mode. 404 2. Call from PhoneA to PhoneB, hang up on PhoneA. 405 3, Repeat 2 around N times based on the config setup 406 407 Expected Results: 408 1, Verify phone is at IDLE state 409 2, Verify the phone is at ACTIVE, if it is in dialing, then we retry 410 3, Verify the phone is IDLE after hung up 411 412 Returns: 413 True if pass; False if fail. 414 """ 415 return self.stress_test( 416 setup_func=self._setup_3g, network_check_func=is_phone_in_call_3g) 417 418 @test_tracker_info(uuid="12380823-2e7f-4c41-95c0-5f8c483f9510") 419 @TelephonyBaseTest.tel_test_wrap 420 def test_call_2g_stress(self): 421 """ 2G call stress test 422 423 Steps: 424 1. Make Sure PhoneA and PhoneB in 3G mode. 425 2. Call from PhoneA to PhoneB, hang up on PhoneA. 426 3, Repeat 2 around N times based on the config setup 427 428 Expected Results: 429 1, Verify phone is at IDLE state 430 2, Verify the phone is at ACTIVE, if it is in dialing, then we retry 431 3, Verify the phone is IDLE after hung up 432 433 Returns: 434 True if pass; False if fail. 435 """ 436 return self.stress_test( 437 setup_func=self._setup_2g, network_check_func=is_phone_in_call_2g) 438 439 @test_tracker_info(uuid="28a88b44-f239-4b77-b01f-e9068373d749") 440 @TelephonyBaseTest.tel_test_wrap 441 def test_call_video_stress(self): 442 """ VT call stress test 443 444 Steps: 445 1. Make Sure PhoneA and PhoneB in VoLTE mode (ViLTE provisioned). 446 2. Call from PhoneA to PhoneB, hang up on PhoneA. 447 3, Repeat 2 around N times based on the config setup 448 449 Expected Results: 450 1, Verify phone is at IDLE state 451 2, Verify the phone is at ACTIVE, if it is in dialing, then we retry 452 3, Verify the phone is IDLE after hung up 453 454 Returns: 455 True if pass; False if fail. 456 """ 457 return self.stress_test( 458 setup_func=self._setup_vt, 459 network_check_func=is_phone_in_call_video_bidirectional, 460 test_video=True) 461 462 """ Tests End """ 463