• 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 Pre Check In Sanity
18"""
19
20import collections
21import time
22from acts.controllers.sl4a_types import Sl4aNetworkInfo
23from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
24from acts.test_utils.tel.tel_data_utils import wifi_tethering_setup_teardown
25from acts.test_utils.tel.tel_defines import AOSP_PREFIX
26from acts.test_utils.tel.tel_defines import CAPABILITY_VOLTE
27from acts.test_utils.tel.tel_defines import CAPABILITY_WFC
28from acts.test_utils.tel.tel_defines import CAPABILITY_OMADM
29from acts.test_utils.tel.tel_defines import DATA_STATE_CONNECTED
30from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_PROVISIONING
31from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK
32from acts.test_utils.tel.tel_defines import TETHERING_MODE_WIFI
33from acts.test_utils.tel.tel_defines import WAIT_TIME_AFTER_REBOOT
34from acts.test_utils.tel.tel_defines import WAIT_TIME_ANDROID_STATE_SETTLING
35from acts.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL
36from acts.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL_FOR_IMS
37from acts.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED
38from acts.test_utils.tel.tel_defines import WFC_MODE_DISABLED
39from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_ONLY
40from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
41from acts.test_utils.tel.tel_lookup_tables import device_capabilities
42from acts.test_utils.tel.tel_lookup_tables import operator_capabilities
43from acts.test_utils.tel.tel_test_utils import call_setup_teardown
44from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
45from acts.test_utils.tel.tel_test_utils import get_model_name
46from acts.test_utils.tel.tel_test_utils import get_operator_name
47from acts.test_utils.tel.tel_test_utils import multithread_func
48from acts.test_utils.tel.tel_test_utils import sms_send_receive_verify
49from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
50from acts.test_utils.tel.tel_test_utils import wait_for_cell_data_connection
51from acts.test_utils.tel.tel_test_utils import verify_http_connection
52from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
53from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb
54from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
55from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
56from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_3g
57from acts.test_utils.tel.tel_voice_utils import phone_setup_csfb
58from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan
59from acts.test_utils.tel.tel_voice_utils import \
60    phone_setup_iwlan_cellular_preferred
61from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_general
62from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
63from acts.test_utils.tel.tel_voice_utils import phone_idle_3g
64from acts.test_utils.tel.tel_voice_utils import phone_idle_csfb
65from acts.test_utils.tel.tel_voice_utils import phone_idle_iwlan
66from acts.test_utils.tel.tel_voice_utils import phone_idle_volte
67
68from acts.utils import rand_ascii_str
69
70
71class TelLiveRebootStressTest(TelephonyBaseTest):
72    def __init__(self, controllers):
73        TelephonyBaseTest.__init__(self, controllers)
74
75        self.stress_test_number = self.get_stress_test_number()
76        self.wifi_network_ssid = self.user_params["wifi_network_ssid"]
77
78        try:
79            self.wifi_network_pass = self.user_params["wifi_network_pass"]
80        except KeyError:
81            self.wifi_network_pass = None
82
83        self.dut = self.android_devices[0]
84        self.ad_reference = self.android_devices[1] if len(
85            self.android_devices) > 1 else None
86        self.dut_model = get_model_name(self.dut)
87        self.dut_operator = get_operator_name(self.log, self.dut)
88
89    def _check_provisioning(self):
90        if (CAPABILITY_OMADM in device_capabilities[self.dut_model] and
91                CAPABILITY_OMADM in operator_capabilities[self.dut_operator]):
92            self.log.info("Check Provisioning bit")
93            if not self.dut.droid.imsIsVolteProvisionedOnDevice():
94                self.log.error("{}: VoLTE Not Provisioned on the Platform".
95                               format(self.dut.serial))
96                return False
97        return True
98
99    def _check_provision(self):
100        elapsed_time = 0
101        while (elapsed_time < MAX_WAIT_TIME_PROVISIONING):
102            if self._check_provisioning(self.dut):
103                return True
104            else:
105                time.sleep(CHECK_INTERVAL)
106                elapsed_time += CHECK_INTERVAL
107        self.log.error("Provisioning fail.")
108        return False
109
110    def _clear_provisioning(self):
111        if (CAPABILITY_OMADM in device_capabilities[self.dut_model] and
112                CAPABILITY_OMADM in operator_capabilities[self.dut_operator]):
113            self.log.info("Clear Provisioning bit")
114            self.dut.droid.imsSetVolteProvisioning(False)
115        return True
116
117    def _check_call_setup_teardown(self):
118        if not call_setup_teardown(self.log, self.dut, self.ad_reference):
119            self.log.error("Phone Call Failed.")
120            return False
121        return True
122
123    def _check_lte_data(self):
124        self.log.info("Check LTE data.")
125        if not phone_setup_csfb(self.log, self.dut):
126            self.log.error("Failed to setup LTE data.")
127            return False
128        if not verify_http_connection(self.log, self.dut):
129            self.log.error("Data not available on cell.")
130            return False
131        return True
132
133    def _check_volte(self):
134        if (CAPABILITY_VOLTE in device_capabilities[self.dut_model] and
135                CAPABILITY_VOLTE in operator_capabilities[self.dut_operator]):
136            self.log.info("Check VoLTE")
137            if not phone_setup_volte(self.log, self.dut):
138                self.log.error("Failed to setup VoLTE.")
139                return False
140            if not call_setup_teardown(self.log, self.dut, self.ad_reference,
141                                       self.dut, is_phone_in_call_volte):
142                self.log.error("VoLTE Call Failed.")
143                return False
144            if not sms_send_receive_verify(self.log, self.dut,
145                                           self.ad_reference,
146                                           [rand_ascii_str(50)]):
147                self.log.error("SMS failed")
148                return False
149        return True
150
151    def _check_wfc(self):
152        if (CAPABILITY_WFC in device_capabilities[self.dut_model] and
153                CAPABILITY_WFC in operator_capabilities[self.dut_operator]):
154            self.log.info("Check WFC")
155            if not phone_setup_iwlan(
156                    self.log, self.dut, True, WFC_MODE_WIFI_PREFERRED,
157                    self.wifi_network_ssid, self.wifi_network_pass):
158                self.log.error("Failed to setup WFC.")
159                return False
160            if not call_setup_teardown(self.log, self.dut, self.ad_reference,
161                                       self.dut, is_phone_in_call_iwlan):
162                self.log.error("WFC Call Failed.")
163                return False
164            if not sms_send_receive_verify(self.log, self.dut,
165                                           self.ad_reference,
166                                           [rand_ascii_str(50)]):
167                self.log.error("SMS failed")
168                return False
169        return True
170
171    def _check_3g(self):
172        self.log.info("Check 3G data and CS call")
173        if not phone_setup_voice_3g(self.log, self.dut):
174            self.log.error("Failed to setup 3G")
175            return False
176        if not verify_http_connection(self.log, self.dut):
177            self.log.error("Data not available on cell.")
178            return False
179        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
180                                   self.dut, is_phone_in_call_3g):
181            self.log.error("WFC Call Failed.")
182            return False
183        if not sms_send_receive_verify(self.log, self.dut, self.ad_reference,
184                                       [rand_ascii_str(50)]):
185            self.log.error("SMS failed")
186            return False
187        return True
188
189    def _check_tethering(self):
190        self.log.info("Check tethering")
191        if not self.dut.droid.carrierConfigIsTetheringModeAllowed(
192                TETHERING_MODE_WIFI,
193                MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK):
194            self.log.error("Tethering Entitlement check failed.")
195            return False
196        if not wifi_tethering_setup_teardown(
197                self.log,
198                self.dut, [self.ad_reference],
199                check_interval=5,
200                check_iteration=1):
201            self.log.error("Tethering Failed.")
202            return False
203        return True
204
205    def _check_data_roaming_status(self):
206        if not self.dut.droid.telephonyIsDataEnabled():
207            self.log.info("Enabling Cellular Data")
208            telephonyToggleDataConnection(True)
209        else:
210            self.log.info("Cell Data is Enabled")
211        self.log.info("Waiting for cellular data to be connected")
212        if not wait_for_cell_data_connection(self.log, self.dut, state=True):
213            self.log.error("Failed to enable cell data")
214            return False
215        self.log.info("Cellular data connected, checking NetworkInfos")
216        roaming_state = self.dut.droid.telephonyCheckNetworkRoaming()
217        for network_info in self.dut.droid.connectivityNetworkGetAllInfo():
218            sl4a_network_info = Sl4aNetworkInfo.from_dict(network_info)
219            if sl4a_network_info.isRoaming:
220                self.log.warning("We don't expect to be roaming")
221            if sl4a_network_info.isRoaming != roaming_state:
222                self.log.error(
223                    "Mismatched Roaming Status Information Telephony: {}, NetworkInfo {}".
224                    format(roaming_state, sl4a_network_info.isRoaming))
225                self.log.error(network_info)
226                return False
227        return True
228
229    def _reboot_stress_test(self, **kwargs):
230        """Reboot Reliability Test
231
232        Arguments:
233            check_provision: whether to check provisioning after reboot.
234            check_call_setup_teardown: whether to check setup and teardown a call.
235            check_lte_data: whether to check the LTE data.
236            check_volte: whether to check Voice over LTE.
237            check_wfc: whether to check Wifi Calling.
238            check_3g: whether to check 3G.
239            check_tethering: whether to check Tethering.
240            check_data_roaming: whether to check Data Roaming.
241            clear_provision: whether to clear provisioning before reboot.
242
243        Expected Results:
244            No crash happens in stress test.
245
246        Returns:
247            True is pass, False if fail.
248        """
249        CHECK_INTERVAL = 10
250
251        toggle_airplane_mode(self.log, self.dut, False)
252        phone_setup_voice_general(self.log, self.ad_reference)
253        fail_count = collections.defaultdict(int)
254        test_result = True
255        test_method_mapping = {
256            "check_provision": self._check_provision,
257            "check_call_setup_teardown": self._check_call_setup_teardown,
258            "check_lte_data": self._check_lte_data,
259            "check_volte": self._check_volte,
260            "check_wfc": self._check_wfc,
261            "check_3g": self._check_3g,
262            "check_tethering": self._check_tethering,
263            "check_data_roaming": self._check_data_roaming_status,
264            "clear_provision": self._clear_provisioning
265        }
266        for kwarg in kwargs:
267            if kwarg not in test_method_mapping:
268                self.log.error("method %s is not supported" % method)
269
270        required_methods = []
271        for method in ("check_provistion", "check_call_setup_teardown",
272                       "check_lte_data", "check_volte", "check_wfc",
273                       "check_3g", "check_tethering", "check_data_roaming",
274                       "clear_provion"):
275            if method in kwargs: required_methods.append(method)
276
277        for i in range(1, self.stress_test_number + 1):
278            self.log.info("Reboot Stress Test {} Iteration: <{}> / <{}>".format(
279                self.test_name, i, self.stress_test_number))
280
281            self.log.info("{} reboot!".format(self.dut.serial))
282            self.dut.reboot()
283            self.log.info("{} wait {}s for radio up.".format(
284                self.dut.serial, WAIT_TIME_AFTER_REBOOT))
285            time.sleep(WAIT_TIME_AFTER_REBOOT)
286            iteration_result = "pass"
287            for check in required_methods:
288                if not test_method_mapping[check]():
289                    fail_count[check] += 1
290                    iteration_result = "fail"
291            self.log.info("Reboot Stress Test {} Iteration: <{}> / <{}> {}".format(
292                self.test_name, i, self.stress_test_number, iteration_result))
293
294            # TODO: Check if crash happens.
295
296        for failure, count in fail_count.items():
297            if count:
298                self.log.error("{} {} failures in {} iterations".format(
299                    count, failure, self.stress_test_number))
300                test_result = False
301        return test_result
302
303    """ Tests Begin """
304
305    @TelephonyBaseTest.tel_test_wrap
306    def test_reboot_stress(self):
307        """Reboot Reliability Test
308
309        Steps:
310            1. Reboot DUT.
311            2. Check Provisioning bit (if support provisioning)
312            3. Wait for DUT to camp on LTE, Verify Data.
313            4. Enable VoLTE, check IMS registration. Wait for DUT report VoLTE
314                enabled, make VoLTE call. And verify VoLTE SMS.
315                (if support VoLTE)
316            5. Connect WiFi, enable WiFi Calling, wait for DUT report WiFi
317                Calling enabled and make a WFC call and verify SMS.
318                Disconnect WiFi. (if support WFC)
319            6. Wait for DUT to camp on 3G, Verify Data.
320            7. Make CS call and verify SMS.
321            8. Verify Tethering Entitlement Check and Verify WiFi Tethering.
322            9. Check crashes.
323            10. Repeat Step 1~9 for N times. (before reboot, clear Provisioning
324                bit if provisioning is supported)
325
326        Expected Results:
327            No crash happens in stress test.
328
329        Returns:
330            True is pass, False if fail.
331        """
332        return self._reboot_stress_test(
333            check_provision=True,
334            check_call_setup_teardown=True,
335            check_lte_data=True,
336            check_volte=True,
337            check_wfc=True,
338            check_3g=True,
339            check_tethering=True,
340            check_data_roaming=False,
341            clear_provision=True)
342
343    @TelephonyBaseTest.tel_test_wrap
344    def test_reboot_stress_without_clear_provisioning(self):
345        """Reboot Reliability Test without Clear Provisioning
346
347        Steps:
348            1. Reboot DUT.
349            2. Check Provisioning bit (if support provisioning)
350            3. Wait for DUT to camp on LTE, Verify Data.
351            4. Enable VoLTE, check IMS registration. Wait for DUT report VoLTE
352                enabled, make VoLTE call. And verify VoLTE SMS.
353                (if support VoLTE)
354            5. Connect WiFi, enable WiFi Calling, wait for DUT report WiFi
355                Calling enabled and make a WFC call and verify SMS.
356                Disconnect WiFi. (if support WFC)
357            6. Wait for DUT to camp on 3G, Verify Data.
358            7. Make CS call and verify SMS.
359            8. Verify Tethering Entitlement Check and Verify WiFi Tethering.
360            9. Check crashes.
361            10. Repeat Step 1~9 for N times.
362
363        Expected Results:
364            No crash happens in stress test.
365
366        Returns:
367            True is pass, False if fail.
368        """
369        return self._reboot_stress_test(
370            check_provision=True,
371            check_call_setup_teardown=True,
372            check_lte_data=True,
373            check_volte=True,
374            check_wfc=True,
375            check_3g=True,
376            check_tethering=True,
377            check_data_roaming=False,
378            clear_provision=False)
379
380    @TelephonyBaseTest.tel_test_wrap
381    def test_reboot_stress_check_phone_call_only(self):
382        """Reboot Reliability Test
383
384        Steps:
385            1. Reboot DUT.
386            2. Check phone call .
387            3. Check crashes.
388            4. Repeat Step 1~9 for N times. (before reboot, clear Provisioning
389                bit if provisioning is supported)
390
391        Expected Results:
392            No crash happens in stress test.
393
394        Returns:
395            True is pass, False if fail.
396        """
397        return self._stress_test(check_provision=True, check_call_setup_teardown=True)
398
399    @TelephonyBaseTest.tel_test_wrap
400    def test_reboot_stress_data_roaming(self):
401        """Reboot Reliability Test
402
403        Steps:
404            1. Reboot DUT.
405            8. Check the data connection
406            9. Check crashes.
407            10. Repeat Step 1~9 for N times. (before reboot, clear Provisioning
408                bit if provisioning is supported)
409
410        Expected Results:
411            No crash happens in stress test.
412
413        Returns:
414            True is pass, False if fail.
415        """
416        return self._reboot_stress_test(check_data_roaming=True)
417
418
419""" Tests End """
420
421