• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2020 - 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 Factory Data Reset In Sanity
18"""
19
20import collections
21import time
22
23from acts import signals
24from acts.test_decorators import test_tracker_info
25from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
26from acts_contrib.test_utils.tel.tel_data_utils import wifi_tethering_setup_teardown
27from acts_contrib.test_utils.tel.tel_defines import CAPABILITY_VOLTE
28from acts_contrib.test_utils.tel.tel_defines import CAPABILITY_OMADM
29from acts_contrib.test_utils.tel.tel_defines import MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK
30from acts_contrib.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA
31from acts_contrib.test_utils.tel.tel_defines import GEN_4G
32from acts_contrib.test_utils.tel.tel_defines import TETHERING_MODE_WIFI
33from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_AFTER_FDR
34from acts_contrib.test_utils.tel.tel_bootloader_utils import fastboot_wipe
35from acts_contrib.test_utils.tel.tel_message_utils import sms_send_receive_verify
36from acts_contrib.test_utils.tel.tel_message_utils import mms_send_receive_verify
37from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_idle_volte
38from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_voice_3g
39from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_csfb
40from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_volte
41from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phone_subscription
42from acts_contrib.test_utils.tel.tel_phone_setup_utils import wait_for_network_generation
43from acts_contrib.test_utils.tel.tel_test_utils import get_outgoing_voice_sub_id
44from acts_contrib.test_utils.tel.tel_test_utils import is_droid_in_network_generation
45from acts_contrib.test_utils.tel.tel_test_utils import verify_internet_connection
46from acts_contrib.test_utils.tel.tel_test_utils import wait_for_state
47from acts_contrib.test_utils.tel.tel_voice_utils import call_setup_teardown
48from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
49from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb
50from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
51
52from acts.utils import get_current_epoch_time
53from acts.utils import rand_ascii_str
54
55
56class TelLiveStressFdrTest(TelephonyBaseTest):
57    def setup_class(self):
58        TelephonyBaseTest.setup_class(self)
59
60        self.user_params["telephony_auto_rerun"] = 0
61        self.fdr_stress_cycle = int(
62            self.user_params.get("fdr_stress_cycle", 100))
63        self.skip_reset_between_cases = False
64
65        self.dut = self.android_devices[0]
66        if len(self.android_devices) > 1:
67            self.ad_reference = self.android_devices[1]
68        else:
69            raise signals.TestSkip("Single DUT is not supported")
70        self.user_params["check_crash"] = False
71        self.skip_reset_between_cases = False
72
73        # self.dut_capabilities = self.dut.telephony.get("capabilities", [])
74        sub_id = get_outgoing_voice_sub_id(self.dut)
75        self.dut_capabilities = self.dut.telephony["subscription"][sub_id].get("capabilities", [])
76        self.dut.log.info("dut_capabilitiese: %s", self.dut_capabilities)
77
78        self.dut_wfc_modes = self.dut.telephony.get("wfc_modes", [])
79        self.default_testing_func_names = []
80        for method in ("_check_volte", "_check_csfb",
81                       "_check_tethering", "_check_3g"):
82            func = getattr(self, method)
83            try:
84                check_result = func()
85            except Exception as e:
86                self.dut.log.error("%s failed with %s", method, e)
87                check_result = False
88            self.dut.log.info("%s is %s before tests start", method,
89                              check_result)
90            if check_result:
91                self.default_testing_func_names.append(method)
92        self.dut.log.info("To be tested: %s", self.default_testing_func_names)
93
94    def teardown_test(self):
95        self._set_volte_provisioning()
96
97    def feature_validator(self, *args):
98        failed_tests = []
99        for method in ("_check_subscription", "_check_data", "_check_mms_mt",
100                       "_check_sms_mt", "_check_call_setup_teardown",
101                       "_check_sms", "_check_mms"):
102            func = getattr(self, method)
103            if not func():
104                self.log.error("%s failed", method)
105                failed_tests.append(method)
106        for method in args:
107            func = getattr(self, method)
108            try:
109                func_result = func()
110            except Exception as e:
111                self.log.error("%s check failed with %s", method, e)
112                func_result = False
113            if not func_result:
114                self.log.error("%s failed", method)
115                failed_tests.append(method)
116            else:
117                self.log.info("%s succeeded", method)
118        if failed_tests:
119            self.log.error("%s failed", failed_tests)
120        return failed_tests
121
122    def _check_subscription(self):
123        if not ensure_phone_subscription(self.log, self.dut):
124            self.dut.log.error("Subscription check failed")
125            return False
126        else:
127            return True
128
129    def _check_volte_provisioning(self):
130        if CAPABILITY_OMADM in self.dut_capabilities:
131            if not wait_for_state(self.dut.droid.imsIsVolteProvisionedOnDevice,
132                                  True):
133                self.dut.log.error("VoLTE provisioning is disabled.")
134                return False
135            else:
136                self.dut.log.info("VoLTE provision is enabled")
137                return True
138        return True
139
140    def _set_volte_provisioning(self):
141        if CAPABILITY_OMADM in self.dut_capabilities:
142            provisioned = self.dut.droid.imsIsVolteProvisionedOnDevice()
143            if provisioned:
144                self.dut.log.info("Volte is provioned")
145                return
146            self.dut.log.info("VoLTE provisioning is not set, setting\
147                VoLTE provision")
148            self.dut.droid.imsSetVolteProvisioning(True)
149
150    def _check_call_setup_teardown(self):
151        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
152                                   self.dut):
153            self.log.error("Phone call test failed.")
154            return False
155        return True
156
157    def _check_sms(self):
158        if not sms_send_receive_verify(self.log, self.dut, self.ad_reference,
159                                       [rand_ascii_str(180)]):
160            self.log.error("SMS send test failed")
161            return False
162        else:
163            self.log.info("SMS send test passed")
164            return True
165
166    def _check_mms(self):
167        message_array = [("Test Message", rand_ascii_str(180), None)]
168        if not mms_send_receive_verify(self.log, self.dut, self.ad_reference,
169                                       message_array):
170            self.log.error("MMS test sendfailed")
171            return False
172        else:
173            self.log.info("MMS send test passed")
174            return True
175
176    def _check_sms_mt(self):
177        if not sms_send_receive_verify(self.log, self.ad_reference, self.dut,
178                                       [rand_ascii_str(180)]):
179            self.log.error("SMS receive test failed")
180            return False
181        else:
182            self.log.info("SMS receive test passed")
183            return True
184
185    def _check_mms_mt(self):
186        message_array = [("Test Message", rand_ascii_str(180), None)]
187        if not mms_send_receive_verify(self.log, self.ad_reference, self.dut,
188                                       message_array):
189            self.log.error("MMS receive test failed")
190            return False
191        else:
192            self.log.info("MMS receive test passed")
193            return True
194
195    def _check_data(self):
196        if not verify_internet_connection(self.log, self.dut):
197            self.dut.log.error("Data connection is not available.")
198            return False
199        return True
200
201    def _check_lte_data(self):
202        if not is_droid_in_network_generation(self.log, self.dut, GEN_4G,
203                                              NETWORK_SERVICE_DATA):
204            self.dut.log.error("Data is not on 4G network")
205            return False
206        if not verify_internet_connection(self.log, self.dut):
207            self.log.error("Data not available on cell.")
208            return False
209        return True
210
211    def _check_volte(self):
212        if CAPABILITY_VOLTE in self.dut_capabilities:
213            self._set_volte_provisioning()
214            if not self._check_volte_provisioning():
215                return False
216            self.log.info("Check VoLTE")
217            if not wait_for_state(self.dut.droid.imsIsVolteProvisionedOnDevice,
218                                  True):
219                self.dut.log.error("VoLTE provisioning is disabled.")
220                return False
221            if not phone_setup_volte(self.log, self.dut):
222                self.log.error("Failed to setup VoLTE.")
223                return False
224            time.sleep(5)
225            if not call_setup_teardown(self.log, self.dut, self.ad_reference,
226                                       self.dut, is_phone_in_call_volte):
227                self.log.error("VoLTE Call Failed.")
228                return False
229            if not self._check_lte_data():
230                return False
231        else:
232            self.dut.log.info("VoLTE is not supported")
233            return False
234        return True
235
236    def _check_csfb(self):
237        if not phone_setup_csfb(self.log, self.dut):
238            self.log.error("Failed to setup CSFB.")
239            return False
240        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
241                                   self.dut, is_phone_in_call_csfb):
242            self.dut.log.error("CSFB Call Failed.")
243            return False
244        if not wait_for_network_generation(
245                self.log, self.dut, GEN_4G,
246                voice_or_data=NETWORK_SERVICE_DATA):
247            self.dut.log.error("Data service failed to camp to 4G")
248            return False
249        if not verify_internet_connection(self.log, self.dut):
250            self.log.error("Data not available on cell.")
251            return False
252        return True
253
254    def _check_volte_enabled(self):
255        if phone_idle_volte(self.log, self.dut):
256            self.dut.log.info("VoLTE is enabled")
257        else:
258            self.dut.log.error("VoLTE is not enabled")
259            return False
260        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
261                                   self.dut, is_phone_in_call_volte):
262            self.log.error("VoLTE Call Failed.")
263            return False
264        if not self._check_lte_data():
265            return False
266        return True
267
268    def _check_csfb_enabled(self):
269        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
270                                   self.dut, is_phone_in_call_csfb):
271            self.log.error("CSFB Call Failed.")
272            return False
273        if not wait_for_network_generation(
274                self.log, self.dut, GEN_4G,
275                voice_or_data=NETWORK_SERVICE_DATA):
276            self.dut.log.error("Data service failed to camp to 4G")
277            return False
278        if not verify_internet_connection(self.log, self.dut):
279            self.log.error("Data not available on cell.")
280            return False
281        return True
282
283    def _check_3g(self):
284        self.log.info("Check 3G data and CS call")
285        if not phone_setup_voice_3g(self.log, self.dut):
286            self.log.error("Failed to setup 3G")
287            return False
288        if not verify_internet_connection(self.log, self.dut):
289            self.log.error("Data not available on cell.")
290            return False
291        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
292                                   self.dut, is_phone_in_call_3g):
293            self.log.error("WFC Call Failed.")
294            return False
295        if not sms_send_receive_verify(self.log, self.dut, self.ad_reference,
296                                       [rand_ascii_str(50)]):
297            self.log.error("SMS failed in 3G")
298            return False
299        return True
300
301    def _check_tethering(self):
302        self.log.info("Check tethering")
303        for retries in range(3):
304            try:
305                if not self.dut.droid.carrierConfigIsTetheringModeAllowed(
306                        TETHERING_MODE_WIFI,
307                        MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK):
308                    self.log.error("Tethering Entitlement check failed.")
309                    if retries == 2: return False
310                    time.sleep(10)
311            except Exception as e:
312                if retries == 2:
313                    self.dut.log.error(e)
314                    return False
315                time.sleep(10)
316        if not wifi_tethering_setup_teardown(
317                self.log,
318                self.dut, [self.ad_reference],
319                check_interval=5,
320                check_iteration=1):
321            self.log.error("Tethering check failed.")
322            return False
323        return True
324
325    def _fdr_stress_test(self, *args):
326        """Fdr Reliability Test
327
328        Arguments:
329            function_name: function to be checked
330
331        Expected Results:
332            No crash happens in stress test.
333
334        Returns:
335            True is pass, False if fail.
336        """
337        self.number_of_devices = 2
338        fail_count = collections.defaultdict(int)
339        test_result = True
340
341        for i in range(1, self.fdr_stress_cycle + 1):
342            begin_time = get_current_epoch_time()
343            test_name = "%s_iteration_%s" % (self.test_name, i)
344            log_msg = "[Test Case] %s" % test_name
345            self.log.info("%s begin", log_msg)
346            self.dut.droid.logI("%s begin" % log_msg)
347            test_msg = "FDR Stress Test %s Iteration <%s> / <%s>" % (
348                self.test_name, i, self.fdr_stress_cycle)
349            self.log.info(test_msg)
350            fastboot_wipe(self.dut)
351            self.log.info("%s wait %s secs for radio up.",
352                self.dut.serial, WAIT_TIME_AFTER_FDR)
353            time.sleep(WAIT_TIME_AFTER_FDR)
354            failed_tests = self.feature_validator(*args)
355            for test in failed_tests:
356                fail_count[test] += 1
357
358            crash_report = self.dut.check_crash_report(
359                "%s_%s" % (self.test_name, i),
360                begin_time,
361                log_crash_report=True)
362            if crash_report:
363                fail_count["crashes"] += 1
364            if failed_tests or crash_report:
365                self.log.error("%s FAIL with %s and crashes %s", test_msg,
366                               failed_tests, crash_report)
367                self._take_bug_report(test_name, begin_time)
368            else:
369                self.log.info("%s PASS", test_msg)
370            self.log.info("Total failure count: %s", dict(fail_count))
371            self.log.info("%s end", log_msg)
372            self.dut.droid.logI("%s end" % log_msg)
373
374        for failure, count in fail_count.items():
375            if count:
376                self.log.error("%s failure count = %s in total %s iterations",
377                               failure, count, self.fdr_stress_cycle)
378                test_result = False
379        return test_result
380
381
382    """ Tests Begin """
383
384
385    @test_tracker_info(uuid="a09a5d44-ffcc-4890-b0ba-a30a75e05fbd")
386    @TelephonyBaseTest.tel_test_wrap
387    def test_fdr_stress_volte(self):
388        """FDR with VoLTE Test
389
390        Steps:
391            1. Fdr DUT.
392            2. Wait for DUT to camp on LTE, Verify Data.
393            3. Check VoLTE is enabled by default, check IMS registration.
394               Wait for DUT report VoLTE enabled, make VoLTE call.
395               And verify VoLTE SMS. (if support VoLTE)
396            4. Check crashes.
397            5. Repeat Step 1~4 for N times.
398
399        Expected Results:
400            No crash happens in stress test.
401
402        Returns:
403            True is pass, False if fail.
404        """
405        if CAPABILITY_VOLTE not in self.dut_capabilities:
406            raise signals.TestSkip("VOLTE is not supported")
407        if not self._check_volte():
408            self.dut.log.error("VoLTE test failed before fdr test")
409            return False
410        func_names = ["_check_volte_enabled"]
411        return self._fdr_stress_test(*func_names)
412
413    """ Tests End """
414