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