• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CELLULAR_PREFERRED
25from acts_contrib.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
26from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL
27from acts_contrib.test_utils.tel.tel_ims_utils import set_wfc_mode
28from acts_contrib.test_utils.tel.tel_logging_utils import start_qxdm_loggers
29from acts_contrib.test_utils.tel.tel_logging_utils import start_sdm_loggers
30from acts_contrib.test_utils.tel.tel_message_utils import sms_send_receive_verify
31from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_csfb
32from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_voice_3g
33from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_voice_2g
34from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_volte
35from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_idle_iwlan
36from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phone_subscription
37from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phones_idle
38from acts_contrib.test_utils.tel.tel_test_utils import verify_incall_state
39from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode
40from acts_contrib.test_utils.tel.tel_video_utils import phone_setup_video
41from acts_contrib.test_utils.tel.tel_video_utils import video_call_setup
42from acts_contrib.test_utils.tel.tel_video_utils import is_phone_in_call_video_bidirectional
43from acts_contrib.test_utils.tel.tel_voice_utils import call_setup_teardown
44from acts_contrib.test_utils.tel.tel_voice_utils import hangup_call
45from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
46from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_2g
47from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb
48from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
49from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
50from acts_contrib.test_utils.tel.tel_voice_utils import last_call_drop_reason
51from acts_contrib.test_utils.tel.tel_wifi_utils import ensure_wifi_connected
52from acts.utils import get_current_epoch_time
53from acts.utils import rand_ascii_str
54from acts.libs.utils.multithread import multithread_func
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"] = 0
64        self.phone_call_iteration = int(
65            self.user_params.get("phone_call_iteration", 500))
66        self.phone_call_duration = int(
67            self.user_params.get("phone_call_duration", 60))
68        self.sleep_time_between_test_iterations = int(
69            self.user_params.get("sleep_time_between_test_iterations", 0))
70
71        return True
72
73    def on_fail(self, test_name, begin_time):
74        pass
75
76    def _setup_wfc(self, wfc_mode):
77        for ad in self.android_devices:
78            if not ensure_wifi_connected(
79                    ad.log,
80                    ad,
81                    self.wifi_network_ssid,
82                    self.wifi_network_pass,
83                    retries=3):
84                ad.log.error("Phone Wifi connection fails.")
85                return False
86            ad.log.info("Phone WIFI is connected successfully.")
87            if not set_wfc_mode(self.log, ad, wfc_mode):
88                ad.log.error("Phone failed to enable Wifi-Calling.")
89                return False
90            ad.log.info("Phone is set in Wifi-Calling successfully.")
91            if not phone_idle_iwlan(self.log, ad):
92                ad.log.error("Phone is not in WFC enabled state.")
93                return False
94            ad.log.info("Phone is in WFC enabled state.")
95        return True
96
97    def _setup_wfc_apm(self, wfc_mode):
98        for ad in self.android_devices:
99            if not ensure_wifi_connected(
100                    ad.log,
101                    ad,
102                    self.wifi_network_ssid,
103                    self.wifi_network_pass,
104                    retries=3,
105                    apm=True):
106                ad.log.error("Phone Wifi connection fails.")
107                return False
108            ad.log.info("Phone WIFI is connected successfully.")
109            if not set_wfc_mode(self.log, ad, wfc_mode):
110                ad.log.error("Phone failed to enable Wifi-Calling.")
111                return False
112            ad.log.info("Phone is set in Wifi-Calling successfully.")
113            if not phone_idle_iwlan(self.log, ad):
114                ad.log.error("Phone is not in WFC enabled state.")
115                return False
116            ad.log.info("Phone is in WFC enabled state.")
117        return True
118
119    def _setup_vt(self, *args):
120        del args
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, *args):
130        del args
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, *args):
139        del args
140        for ad in self.android_devices:
141            if not phone_setup_csfb(self.log, ad):
142                ad.log.error("Phone failed to setup CSFB.")
143                return False
144            ad.log.info("Phone VOLTE is disabled successfully.")
145        return True
146
147    def _setup_3g(self, *args):
148        del args
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, *args):
157        del args
158        for ad in self.android_devices:
159            if not phone_setup_voice_2g(self.log, ad):
160                ad.log.error("Phone failed to setup 2g.")
161                return False
162            ad.log.info("RAT 2G is enabled successfully.")
163        return True
164
165    def _setup_phone_call(self, test_video, phone_call_duration=WAIT_TIME_IN_CALL):
166        if test_video:
167            if not video_call_setup(
168                    self.log,
169                    self.android_devices[0],
170                    self.android_devices[1],
171            ):
172                self.log.error("Failed to setup Video call")
173                return False
174        else:
175            if not call_setup_teardown(
176                    self.log, self.caller, self.callee, ad_hangup=None, wait_time_in_call=phone_call_duration):
177                self.log.error("Setup Call failed.")
178                return False
179        self.log.info("Setup call successfully.")
180        return True
181
182    def _hangup_call(self):
183        for ad in self.android_devices:
184            hangup_call(self.log, ad)
185
186    def stress_test(self,
187                    setup_func=None,
188                    setup_arg=WFC_MODE_WIFI_PREFERRED,
189                    network_check_func=None,
190                    test_sms=False,
191                    test_video=False):
192        for ad in self.android_devices:
193            #check for sim and service
194            ensure_phone_subscription(self.log, ad)
195
196        setup_begin_time = get_current_epoch_time()
197        if setup_func and not setup_func(setup_arg):
198            self.log.error("Test setup %s failed", setup_func.__name__)
199            self._take_bug_report(
200                "%s_%s" % (self.test_name, setup_func.__name__),
201                setup_begin_time)
202            return False
203        fail_count = collections.defaultdict(int)
204        for i in range(1, self.phone_call_iteration + 1):
205            msg = "Stress Call Test %s Iteration: <%s> / <%s>" % (
206                self.test_name, i, self.phone_call_iteration)
207            begin_time = get_current_epoch_time()
208            self.log.info(msg)
209            iteration_result = True
210            ensure_phones_idle(self.log, self.android_devices)
211
212            if not self._setup_phone_call(test_video, phone_call_duration=self.phone_call_duration):
213                fail_count["dialing"] += 1
214                iteration_result = False
215                self.log.error("%s call dialing failure.", msg)
216            else:
217                if network_check_func and not network_check_func(
218                        self.log, self.caller):
219                    fail_count["caller_network_check"] += 1
220                    last_call_drop_reason(self.caller, begin_time)
221                    iteration_result = False
222                    self.log.error("%s network check %s failure.", msg,
223                                   network_check_func.__name__)
224
225                if network_check_func and not network_check_func(
226                        self.log, self.callee):
227                    fail_count["callee_network_check"] += 1
228                    last_call_drop_reason(self.callee, begin_time)
229                    iteration_result = False
230                    self.log.error("%s network check failure.", msg)
231
232                if not verify_incall_state(self.log,
233                                           [self.caller, self.callee], True):
234                    self.log.error("%s call dropped.", msg)
235                    iteration_result = False
236                    fail_count["drop"] += 1
237
238                self._hangup_call()
239
240            if test_sms and not sms_send_receive_verify(
241                    self.log, self.caller, self.callee, [rand_ascii_str(180)]):
242                fail_count["sms"] += 1
243
244            self.log.info("%s %s", msg, iteration_result)
245            if not iteration_result:
246                self._take_bug_report("%s_CallNo_%s" % (self.test_name, i),
247                                      begin_time)
248                if self.sdm_log:
249                    start_sdm_loggers(self.log, self.android_devices)
250                else:
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_wifi_preferred_stress_apm(self):
378        """ Wifi calling in AirPlaneMode call stress test
379
380        Steps:
381        1. Make Sure PhoneA and PhoneB in WFC On(wifi preferred) +
382            APM ON + Wifi Connected
383        2. Call from PhoneA to PhoneB, hang up on PhoneA.
384        3, Repeat 2 around N times based on the config setup
385
386        Expected Results:
387        1, Verify phone is at IDLE state
388        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
389        3, Verify the phone is IDLE after hung up
390
391        Returns:
392            True if pass; False if fail.
393        """
394        return self.stress_test(
395            setup_func=self._setup_wfc_apm,
396            network_check_func=is_phone_in_call_iwlan)
397
398    @test_tracker_info(uuid="d0e52109-b359-4efa-bbaa-ca758428b654")
399    @TelephonyBaseTest.tel_test_wrap
400    def test_call_wifi_calling_cellular_preferred_stress_apm(self):
401        """ Wifi calling in AirPlaneMode call stress test
402
403        Steps:
404        1. Make Sure PhoneA and PhoneB in WFC On(cellular preferred) +
405            APM ON + Wifi Connected
406        2. Call from PhoneA to PhoneB, hang up on PhoneA.
407        3, Repeat 2 around N times based on the config setup
408
409        Expected Results:
410        1, Verify phone is at IDLE state
411        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
412        3, Verify the phone is IDLE after hung up
413
414        Returns:
415            True if pass; False if fail.
416        """
417        return self.stress_test(
418            setup_func=self._setup_wfc_apm,
419            setup_arg=WFC_MODE_CELLULAR_PREFERRED,
420            network_check_func=is_phone_in_call_iwlan)
421
422    @test_tracker_info(uuid="8af0454b-b4db-46d8-b5cc-e13ec5bc59ab")
423    @TelephonyBaseTest.tel_test_wrap
424    def test_call_3g_stress(self):
425        """ 3G call stress test
426
427        Steps:
428        1. Make Sure PhoneA and PhoneB in 3G mode.
429        2. Call from PhoneA to PhoneB, hang up on PhoneA.
430        3, Repeat 2 around N times based on the config setup
431
432        Expected Results:
433        1, Verify phone is at IDLE state
434        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
435        3, Verify the phone is IDLE after hung up
436
437        Returns:
438            True if pass; False if fail.
439        """
440        return self.stress_test(
441            setup_func=self._setup_3g, network_check_func=is_phone_in_call_3g)
442
443    @test_tracker_info(uuid="12380823-2e7f-4c41-95c0-5f8c483f9510")
444    @TelephonyBaseTest.tel_test_wrap
445    def test_call_2g_stress(self):
446        """ 2G call stress test
447
448        Steps:
449        1. Make Sure PhoneA and PhoneB in 3G mode.
450        2. Call from PhoneA to PhoneB, hang up on PhoneA.
451        3, Repeat 2 around N times based on the config setup
452
453        Expected Results:
454        1, Verify phone is at IDLE state
455        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
456        3, Verify the phone is IDLE after hung up
457
458        Returns:
459            True if pass; False if fail.
460        """
461        return self.stress_test(
462            setup_func=self._setup_2g, network_check_func=is_phone_in_call_2g)
463
464    @test_tracker_info(uuid="28a88b44-f239-4b77-b01f-e9068373d749")
465    @TelephonyBaseTest.tel_test_wrap
466    def test_call_video_stress(self):
467        """ VT call stress test
468
469        Steps:
470        1. Make Sure PhoneA and PhoneB in VoLTE mode (ViLTE provisioned).
471        2. Call from PhoneA to PhoneB, hang up on PhoneA.
472        3, Repeat 2 around N times based on the config setup
473
474        Expected Results:
475        1, Verify phone is at IDLE state
476        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
477        3, Verify the phone is IDLE after hung up
478
479        Returns:
480            True if pass; False if fail.
481        """
482        return self.stress_test(
483            setup_func=self._setup_vt,
484            network_check_func=is_phone_in_call_video_bidirectional,
485            test_video=True)
486
487    """ Tests End """
488