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