• 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_utils.tel.TelephonyBaseTest import TelephonyBaseTest
23from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
24from acts.test_utils.tel.tel_test_utils import call_setup_teardown
25from acts.test_utils.tel.tel_test_utils import ensure_phone_default_state
26from acts.test_utils.tel.tel_test_utils import ensure_phones_idle
27from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
28from acts.test_utils.tel.tel_test_utils import hangup_call
29from acts.test_utils.tel.tel_test_utils import set_wfc_mode
30from acts.test_utils.tel.tel_test_utils import sms_send_receive_verify
31from acts.test_utils.tel.tel_test_utils import verify_incall_state
32from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
33from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_2g
34from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb
35from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
36from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
37from acts.test_utils.tel.tel_voice_utils import phone_setup_csfb
38from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan
39from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_3g
40from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_2g
41from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
42from acts.utils import rand_ascii_str
43
44class TelLiveStressCallTest(TelephonyBaseTest):
45    def __init__(self, controllers):
46        TelephonyBaseTest.__init__(self, controllers)
47
48    def setup_class(self):
49        super().setup_class()
50        self.caller = self.android_devices[0]
51        self.callee = self.android_devices[1]
52        self.wifi_network_ssid = self.user_params.get(
53            "wifi_network_ssid") or self.user_params.get(
54                "wifi_network_ssid_2g")
55        self.wifi_network_pass = self.user_params.get(
56            "wifi_network_pass") or self.user_params.get(
57                "wifi_network_pass_2g")
58        self.phone_call_iteration = int(self.user_params.get(
59            "phone_call_iteration", 500))
60        self.phone_call_duration = int(self.user_params.get(
61            "phone_call_duration", 60))
62        self.sleep_time_between_test_iterations = int(self.user_params.get(
63            "sleep_time_between_test_iterations", 0))
64
65        return True
66
67    def _setup_wfc(self):
68        for ad in self.android_devices:
69            if not ensure_wifi_connected(
70                    ad.log,
71                    ad,
72                    self.wifi_network_ssid,
73                    self.wifi_network_pass,
74                    retry=3):
75                ad.log.error("Phone Wifi connection fails.")
76                return False
77            ad.log.info("Phone WIFI is connected successfully.")
78            if not set_wfc_mode(self.log, ad, WFC_MODE_WIFI_PREFERRED):
79                ad.log.error("Phone failed to enable Wifi-Calling.")
80                return False
81            ad.log.info("Phone is set in Wifi-Calling successfully.")
82            if not phone_idle_iwlan(self.log, self.ad):
83                ad.log.error("Phone is not in WFC enabled state.")
84                return False
85            ad.log.info("Phone is in WFC enabled state.")
86        return True
87
88    def _setup_lte_volte_enabled(self):
89        for ad in self.android_devices:
90            if not phone_setup_volte(self.log, ad):
91                ad.log.error("Phone failed to enable VoLTE.")
92                return False
93            ad.log.info("Phone VOLTE is enabled successfully.")
94        return True
95
96    def _setup_lte_volte_disabled(self):
97        for ad in self.android_devices:
98            if not phone_setup_csfb(self.log, ad):
99                ad.log.error("Phone failed to setup CSFB.")
100                return False
101            ad.log.info("Phone VOLTE is disabled successfully.")
102        return True
103
104    def _setup_3g(self):
105        for ad in self.android_devices:
106            if not phone_setup_voice_3g(self.log, ad):
107                ad.log.error("Phone failed to setup 3g.")
108                return False
109            ad.log.info("Phone RAT 3G is enabled successfully.")
110        return True
111
112    def _setup_2g(self):
113        for ad in self.android_devices:
114            if not phone_setup_voice_2g(self.log, ad):
115                ad.log.error("Phone failed to setup 2g.")
116                return False
117            ad.log.info("RAT 2G is enabled successfully.")
118        return True
119
120    def _setup_phone_call(self):
121        if not call_setup_teardown(
122                self.log, self.caller, self.callee, ad_hangup=None):
123            self.log.error("Setup Call failed.")
124            return False
125        self.log.info("Setup call successfully.")
126        return True
127
128    def _hangup_call(self):
129        for ad in self.android_devices:
130            hangup_call(self.log, ad)
131
132    def stress_test(self, setup_func=None, network_check_func=None, test_sms=False):
133        if setup_func and not setup_func():
134            self.log.error("Test setup %s failed", setup_func.__name__)
135            return False
136        fail_count = collections.defaultdict(int)
137        for i in range(1, self.phone_call_iteration + 1):
138            msg = "Stress Call Test %s Iteration: <%s> / <%s>" % (
139                self.test_name, i, self.phone_call_iteration)
140            self.log.info(msg)
141            iteration_result = True
142            ensure_phones_idle(self.log, self.android_devices)
143            if not self._setup_phone_call():
144                fail_count["dialing"] += 1
145                iteration_result = False
146                self.log.error("%s call dialing failure.", msg)
147
148            if network_check_func and not network_check_func(self.log,
149                                                             self.caller):
150                fail_count["caller_network_check"] += 1
151                iteration_result = False
152                self.log.error("%s network check %s failure.", msg,
153                               network_check_func.__name__)
154
155            if network_check_func and not network_check_func(self.log,
156                                                             self.callee):
157                fail_count["callee_network_check"] += 1
158                iteration_result = False
159                self.log.error("%s network check failure.", msg)
160
161            time.sleep(self.phone_call_duration)
162
163            if not verify_incall_state(self.log, [self.caller, self.callee],
164                                       True):
165                self.log.error("%s call dropped.", msg)
166                iteration_result = False
167                fail_count["drop"] += 1
168
169            self._hangup_call()
170
171            if test_sms and not sms_send_receive_verify(
172                    self.log, self.caller, self.callee, [rand_ascii_str(180)]):
173                fail_count["sms"] += 1
174
175            self.log.info("%s %s" % (msg, str(iteration_result)))
176            if not iteration_result:
177                self._take_bug_report("%s_%s" % (self.test_name, i), self.begin_time)
178
179            if self.sleep_time_between_test_iterations:
180                self.caller.droid.goToSleepNow()
181                self.callee.droid.goToSleepNow()
182                time.sleep(self.sleep_time_between_test_iterations)
183
184
185        test_result = True
186        for failure, count in fail_count.items():
187            if count:
188                self.log.error("%s: %s %s failures in %s iterations".format(
189                    self.test_name, count, failure, self.phone_call_iteration))
190                test_result = False
191        return test_result
192
193    """ Tests Begin """
194
195    @TelephonyBaseTest.tel_test_wrap
196    def test_call_default_stress(self):
197        """ Default state call stress test
198
199        Steps:
200        1. Make Sure PhoneA and PhoneB in default mode.
201        2. Call from PhoneA to PhoneB, hang up on PhoneA.
202        3, Repeat 2 around N times based on the config setup
203
204        Expected Results:
205        1, Verify phone is at IDLE state
206        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
207        3, Verify the phone is IDLE after hung up
208
209        Returns:
210            True if pass; False if fail.
211        """
212        return self.stress_test()
213
214    @TelephonyBaseTest.tel_test_wrap
215    def test_call_and_sms_longevity(self):
216        """ Default state call stress test
217
218        Steps:
219        1. Make Sure PhoneA and PhoneB in default mode.
220        2. Call from PhoneA to PhoneB, hang up on PhoneA.
221        3. Send a text message from PhoneA to PhoneB.
222        4. Bring phone to sleep for x seconds based on the config setup.
223        5, Repeat 2 around N times based on the config setup
224
225        Expected Results:
226        1. Phone calls and text messages are successfully made
227
228        Returns:
229            True if pass; False if fail.
230        """
231        return self.stress_test(test_sms=True)
232
233    @TelephonyBaseTest.tel_test_wrap
234    def test_call_volte_stress(self):
235        """ VoLTE call stress test
236
237        Steps:
238        1. Make Sure PhoneA and PhoneB in VoLTE mode.
239        2. Call from PhoneA to PhoneB, hang up on PhoneA.
240        3, Repeat 2 around N times based on the config setup
241
242        Expected Results:
243        1, Verify phone is at IDLE state
244        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
245        3, Verify the phone is IDLE after hung up
246
247        Returns:
248            True if pass; False if fail.
249        """
250        return self.stress_test(
251            setup_func=self._setup_lte_volte_enabled,
252            network_check_func=is_phone_in_call_volte)
253
254    @TelephonyBaseTest.tel_test_wrap
255    def test_call_lte_volte_disabled_stress(self):
256        """ LTE non-VoLTE call stress test
257
258        Steps:
259        1. Make Sure PhoneA and PhoneB in LTE mode.
260        2. Call from PhoneA to PhoneB, hang up on PhoneA.
261        3, Repeat 2 around N times based on the config setup
262
263        Expected Results:
264        1, Verify phone is at IDLE state
265        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
266        3, Verify the phone is IDLE after hung up
267
268        Returns:
269            True if pass; False if fail.
270        """
271        return self.stress_test(
272            setup_func=self._setup_lte_volte_disabled,
273            network_check_func=is_phone_in_call_csfb)
274
275    @TelephonyBaseTest.tel_test_wrap
276    def test_call_wifi_calling_stress(self):
277        """ Wifi calling call stress test
278
279        Steps:
280        1. Make Sure PhoneA and PhoneB in Wifi Calling mode.
281        2. Call from PhoneA to PhoneB, hang up on PhoneA.
282        3, Repeat 2 around N times based on the config setup
283
284        Expected Results:
285        1, Verify phone is at IDLE state
286        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
287        3, Verify the phone is IDLE after hung up
288
289        Returns:
290            True if pass; False if fail.
291        """
292        return self.stress_test(
293            setup_func=self._setup_wfc,
294            network_check_func=is_phone_in_call_iwlan)
295
296    @TelephonyBaseTest.tel_test_wrap
297    def test_call_3g_stress(self):
298        """ 3G call stress test
299
300        Steps:
301        1. Make Sure PhoneA and PhoneB in 3G mode.
302        2. Call from PhoneA to PhoneB, hang up on PhoneA.
303        3, Repeat 2 around N times based on the config setup
304
305        Expected Results:
306        1, Verify phone is at IDLE state
307        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
308        3, Verify the phone is IDLE after hung up
309
310        Returns:
311            True if pass; False if fail.
312        """
313        return self.stress_test(
314            setup_func=self._setup_3g, network_check_func=is_phone_in_call_3g)
315
316    @TelephonyBaseTest.tel_test_wrap
317    def test_call_2g_stress(self):
318        """ 2G call stress test
319
320        Steps:
321        1. Make Sure PhoneA and PhoneB in 3G mode.
322        2. Call from PhoneA to PhoneB, hang up on PhoneA.
323        3, Repeat 2 around N times based on the config setup
324
325        Expected Results:
326        1, Verify phone is at IDLE state
327        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
328        3, Verify the phone is IDLE after hung up
329
330        Returns:
331            True if pass; False if fail.
332        """
333        return self.stress_test(
334            setup_func=self._setup_2g, network_check_func=is_phone_in_call_2g)
335
336    """ Tests End """
337
338