• 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
22
23from acts import signals
24from acts.test_decorators import test_tracker_info
25from acts.controllers.sl4a_lib.sl4a_types import Sl4aNetworkInfo
26from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
27from acts.test_utils.tel.tel_data_utils import wifi_tethering_setup_teardown
28from acts.test_utils.tel.tel_defines import CAPABILITY_VOLTE
29from acts.test_utils.tel.tel_defines import CAPABILITY_VT
30from acts.test_utils.tel.tel_defines import CAPABILITY_WFC
31from acts.test_utils.tel.tel_defines import CAPABILITY_OMADM
32from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK
33from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA
34from acts.test_utils.tel.tel_defines import GEN_4G
35from acts.test_utils.tel.tel_defines import RAT_FAMILY_WLAN
36from acts.test_utils.tel.tel_defines import TETHERING_MODE_WIFI
37from acts.test_utils.tel.tel_defines import WAIT_TIME_AFTER_REBOOT
38from acts.test_utils.tel.tel_defines import WAIT_TIME_AFTER_CRASH
39from acts.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED
40from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
41from acts.test_utils.tel.tel_defines import VT_STATE_BIDIRECTIONAL
42from acts.test_utils.tel.tel_test_utils import call_setup_teardown
43from acts.test_utils.tel.tel_test_utils import ensure_phone_subscription
44from acts.test_utils.tel.tel_test_utils import get_model_name
45from acts.test_utils.tel.tel_test_utils import get_outgoing_voice_sub_id
46from acts.test_utils.tel.tel_test_utils import get_slot_index_from_subid
47from acts.test_utils.tel.tel_test_utils import is_droid_in_network_generation
48from acts.test_utils.tel.tel_test_utils import is_sim_locked
49from acts.test_utils.tel.tel_test_utils import mms_send_receive_verify
50from acts.test_utils.tel.tel_test_utils import power_off_sim
51from acts.test_utils.tel.tel_test_utils import power_on_sim
52from acts.test_utils.tel.tel_test_utils import reboot_device
53from acts.test_utils.tel.tel_test_utils import sms_send_receive_verify
54from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
55from acts.test_utils.tel.tel_test_utils import trigger_modem_crash
56from acts.test_utils.tel.tel_test_utils import trigger_modem_crash_by_modem
57from acts.test_utils.tel.tel_test_utils import unlock_sim
58from acts.test_utils.tel.tel_test_utils import wait_for_wfc_enabled
59from acts.test_utils.tel.tel_test_utils import wait_for_cell_data_connection
60from acts.test_utils.tel.tel_test_utils import wait_for_network_generation
61from acts.test_utils.tel.tel_test_utils import wait_for_network_rat
62from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
63from acts.test_utils.tel.tel_test_utils import verify_internet_connection
64from acts.test_utils.tel.tel_test_utils import wait_for_state
65from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
66from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_csfb
67from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
68from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
69from acts.test_utils.tel.tel_voice_utils import phone_idle_volte
70from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_3g
71from acts.test_utils.tel.tel_voice_utils import phone_setup_csfb
72from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan
73from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
74from acts.test_utils.tel.tel_video_utils import video_call_setup_teardown
75from acts.test_utils.tel.tel_video_utils import phone_setup_video
76from acts.test_utils.tel.tel_video_utils import \
77    is_phone_in_call_video_bidirectional
78
79from acts.utils import get_current_epoch_time
80from acts.utils import rand_ascii_str
81
82
83class TelLiveRebootStressTest(TelephonyBaseTest):
84    def __init__(self, controllers):
85        TelephonyBaseTest.__init__(self, controllers)
86
87        self.stress_test_number = int(
88            self.user_params.get("stress_test_number", 10))
89        self.skip_reset_between_cases = False
90
91        self.dut = self.android_devices[0]
92        self.ad_reference = self.android_devices[1] if len(
93            self.android_devices) > 1 else None
94        self.dut_model = get_model_name(self.dut)
95        self.user_params["check_crash"] = False
96        self.skip_reset_between_cases = False
97
98    def setup_class(self):
99        TelephonyBaseTest.setup_class(self)
100        self.dut_capabilities = self.dut.telephony.get("capabilities", [])
101        self.dut_wfc_modes = self.dut.telephony.get("wfc_modes", [])
102        self.default_testing_func_names = []
103        for method in ("_check_volte", "_check_vt", "_check_csfb",
104                       "_check_tethering", "_check_wfc_apm",
105                       "_check_wfc_nonapm", "_check_3g"):
106            func = getattr(self, method)
107            try:
108                check_result = func()
109            except Exception as e:
110                self.dut.log.error("%s failed with %s", method, e)
111                check_result = False
112            self.dut.log.info("%s is %s before tests start", method,
113                              check_result)
114            if check_result:
115                self.default_testing_func_names.append(method)
116        self.dut.log.info("To be tested: %s", self.default_testing_func_names)
117
118    def teardown_test(self):
119        self._set_volte_provisioning()
120
121    def feature_validator(self, *args):
122        failed_tests = []
123        for method in ("_check_subscription", "_check_data", "_check_mms_mt",
124                       "_check_sms_mt", "_check_call_setup_teardown",
125                       "_check_sms", "_check_mms"):
126            func = getattr(self, method)
127            if not func():
128                self.log.error("%s failed", method)
129                failed_tests.append(method)
130        for method in args:
131            func = getattr(self, method)
132            try:
133                func_result = func()
134            except Exception as e:
135                self.log.error("%s check failed with %s", method, e)
136                func_result = False
137            if not func_result:
138                self.log.error("%s failed", method)
139                failed_tests.append(method)
140            else:
141                self.log.info("%s succeeded", method)
142        if failed_tests:
143            self.log.error("%s failed", failed_tests)
144        return failed_tests
145
146    def _check_subscription(self):
147        if not ensure_phone_subscription(self.log, self.dut):
148            self.dut.log.error("Subscription check failed")
149            return False
150        else:
151            return True
152
153    def _check_volte_provisioning(self):
154        if CAPABILITY_OMADM in self.dut_capabilities:
155            if not wait_for_state(self.dut.droid.imsIsVolteProvisionedOnDevice,
156                                  True):
157                self.dut.log.error("VoLTE provisioning is disabled.")
158                return False
159            else:
160                self.dut.log.info("VoLTE provision is enabled")
161                return True
162        return True
163
164    def _check_volte_provisioning_disabled(self):
165        if CAPABILITY_OMADM in self.dut_capabilities:
166            if not wait_for_state(self.dut.droid.imsIsVolteProvisionedOnDevice,
167                                  False):
168                self.dut.log.error("VoLTE provisioning is not disabled.")
169                return False
170            else:
171                self.dut.log.info("VoLTE provision is disabled")
172                return True
173        return True
174
175    def _set_volte_provisioning(self):
176        if CAPABILITY_OMADM in self.dut_capabilities:
177            provisioned = self.dut.droid.imsIsVolteProvisionedOnDevice()
178            if provisioned:
179                self.dut.log.info("Volte is provioned")
180                return
181            self.dut.log.info("Volte is not provisioned")
182            self.dut.log.info("Set VoLTE Provisioning bit")
183            self.dut.droid.imsSetVolteProvisioning(True)
184
185    def _clear_volte_provisioning(self):
186        if CAPABILITY_OMADM in self.dut_capabilities:
187            self.dut.log.info("Clear VoLTE Provisioning bit")
188            self.dut.droid.imsSetVolteProvisioning(False)
189            if self.dut.droid.imsIsVolteProvisionedOnDevice():
190                self.dut.log.error("VoLTE is still provisioned")
191                return False
192            else:
193                self.dut.log.info("VoLTE provisioning is disabled")
194        return True
195
196    def _check_call_setup_teardown(self):
197        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
198                                   self.dut):
199            self.log.error("Phone call test failed.")
200            return False
201        return True
202
203    def _check_sms(self):
204        if not sms_send_receive_verify(self.log, self.dut, self.ad_reference,
205                                       [rand_ascii_str(180)]):
206            self.log.error("SMS send test failed")
207            return False
208        else:
209            self.log.info("SMS send test passed")
210            return True
211
212    def _check_mms(self):
213        message_array = [("Test Message", rand_ascii_str(180), None)]
214        if not mms_send_receive_verify(self.log, self.dut, self.ad_reference,
215                                       message_array):
216            self.log.error("MMS test sendfailed")
217            return False
218        else:
219            self.log.info("MMS send test passed")
220            return True
221
222    def _check_sms_mt(self):
223        if not sms_send_receive_verify(self.log, self.ad_reference, self.dut,
224                                       [rand_ascii_str(180)]):
225            self.log.error("SMS receive test failed")
226            return False
227        else:
228            self.log.info("SMS receive test passed")
229            return True
230
231    def _check_mms_mt(self):
232        message_array = [("Test Message", rand_ascii_str(180), None)]
233        if not mms_send_receive_verify(self.log, self.ad_reference, self.dut,
234                                       message_array):
235            self.log.error("MMS receive test failed")
236            return False
237        else:
238            self.log.info("MMS receive test passed")
239            return True
240
241    def _check_data(self):
242        if not verify_internet_connection(self.log, self.dut):
243            self.dut.log.error("Data connection is not available.")
244            return False
245        return True
246
247    def _get_list_average(self, input_list):
248        total_sum = float(sum(input_list))
249        total_count = float(len(input_list))
250        if input_list == []:
251            return False
252        return float(total_sum / total_count)
253
254    def _check_lte_data(self):
255        if not is_droid_in_network_generation(self.log, self.dut, GEN_4G,
256                                              NETWORK_SERVICE_DATA):
257            self.dut.log.error("Data is not on 4G network")
258            return False
259        if not verify_internet_connection(self.log, self.dut):
260            self.log.error("Data not available on cell.")
261            return False
262        return True
263
264    def _check_volte(self):
265        if CAPABILITY_VOLTE in self.dut_capabilities:
266            self._set_volte_provisioning()
267            if not self._check_volte_provisioning():
268                return False
269            self.log.info("Check VoLTE")
270            if not wait_for_state(self.dut.droid.imsIsVolteProvisionedOnDevice,
271                                  True):
272                self.dut.log.error("VoLTE provisioning is disabled.")
273                return False
274            if not phone_setup_volte(self.log, self.dut):
275                self.log.error("Failed to setup VoLTE.")
276                return False
277            time.sleep(5)
278            if not call_setup_teardown(self.log, self.dut, self.ad_reference,
279                                       self.dut, is_phone_in_call_volte):
280                self.log.error("VoLTE Call Failed.")
281                return False
282            if not self._check_lte_data():
283                return False
284        else:
285            self.dut.log.info("VoLTE is not supported")
286            return False
287        return True
288
289    def _check_csfb(self):
290        if not phone_setup_csfb(self.log, self.dut):
291            self.log.error("Failed to setup CSFB.")
292            return False
293        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
294                                   self.dut, is_phone_in_call_csfb):
295            self.dut.log.error("CSFB Call Failed.")
296            return False
297        if not wait_for_network_generation(
298                self.log, self.dut, GEN_4G,
299                voice_or_data=NETWORK_SERVICE_DATA):
300            self.dut.log.error("Data service failed to camp to 4G")
301            return False
302        if not verify_internet_connection(self.log, self.dut):
303            self.log.error("Data not available on cell.")
304            return False
305        return True
306
307    def _check_volte_enabled(self):
308        if phone_idle_volte(self.log, self.dut):
309            self.dut.log.info("VoLTE is enabled")
310        else:
311            self.dut.log.error("VoLTE is not enabled")
312            return False
313        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
314                                   self.dut, is_phone_in_call_volte):
315            self.log.error("VoLTE Call Failed.")
316            return False
317        if not self._check_lte_data():
318            return False
319        return True
320
321    def _check_csfb_enabled(self):
322        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
323                                   self.dut, is_phone_in_call_csfb):
324            self.log.error("CSFB Call Failed.")
325            return False
326        if not wait_for_network_generation(
327                self.log, self.dut, GEN_4G,
328                voice_or_data=NETWORK_SERVICE_DATA):
329            self.dut.log.error("Data service failed to camp to 4G")
330            return False
331        if not verify_internet_connection(self.log, self.dut):
332            self.log.error("Data not available on cell.")
333            return False
334        return True
335
336    def _check_vt(self):
337        if CAPABILITY_VT in self.dut_capabilities:
338            self.log.info("Check VT")
339            for ad in (self.dut, self.ad_reference):
340                if not phone_setup_video(self.log, ad):
341                    ad.log.error("Failed to setup VT.")
342                    return False
343            time.sleep(5)
344            if not video_call_setup_teardown(
345                    self.log,
346                    self.dut,
347                    self.ad_reference,
348                    self.dut,
349                    video_state=VT_STATE_BIDIRECTIONAL,
350                    verify_caller_func=is_phone_in_call_video_bidirectional,
351                    verify_callee_func=is_phone_in_call_video_bidirectional):
352                self.log.error("VT Call Failed.")
353                return False
354            else:
355                return True
356        return False
357
358    def _check_vt_enabled(self):
359        if not video_call_setup_teardown(
360                self.log,
361                self.dut,
362                self.ad_reference,
363                self.dut,
364                video_state=VT_STATE_BIDIRECTIONAL,
365                verify_caller_func=is_phone_in_call_video_bidirectional,
366                verify_callee_func=is_phone_in_call_video_bidirectional):
367            self.log.error("VT Call Failed.")
368            return False
369        return True
370
371    def _check_wfc_apm(self):
372        if CAPABILITY_WFC in self.dut_capabilities:
373            self.log.info("Check WFC in APM")
374            if not phone_setup_iwlan(
375                    self.log, self.dut, True, WFC_MODE_CELLULAR_PREFERRED,
376                    self.wifi_network_ssid, self.wifi_network_pass):
377                self.log.error("Failed to setup WFC.")
378                return False
379            if not call_setup_teardown(self.log, self.dut, self.ad_reference,
380                                       self.dut, is_phone_in_call_iwlan):
381                self.log.error("WFC Call Failed.")
382                return False
383            else:
384                return True
385        return False
386
387    def _check_wfc_nonapm(self):
388        if CAPABILITY_WFC not in self.dut_capabilities and (
389                WFC_MODE_WIFI_PREFERRED not in self.dut_wfc_modes):
390            return False
391        self.log.info("Check WFC in NonAPM")
392        if not phone_setup_iwlan(
393                self.log, self.dut, False, WFC_MODE_WIFI_PREFERRED,
394                self.wifi_network_ssid, self.wifi_network_pass):
395            self.log.error("Failed to setup WFC.")
396            return False
397        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
398                                   self.dut, is_phone_in_call_iwlan):
399            self.log.error("WFC Call Failed.")
400            return False
401        else:
402            return True
403
404    def _check_wfc_enabled(self):
405        if not wait_for_wifi_data_connection(self.log, self.dut, True):
406            self.dut.log.error("Failed to connect to WIFI")
407            return False
408        if not wait_for_wfc_enabled(self.log, self.dut):
409            self.dut.log.error("WFC is not enabled")
410            return False
411        if not wait_for_network_rat(
412                self.log,
413                self.dut,
414                RAT_FAMILY_WLAN,
415                voice_or_data=NETWORK_SERVICE_DATA):
416            ad.log.info("Data rat can not go to iwlan mode successfully")
417            return False
418        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
419                                   self.dut, is_phone_in_call_iwlan):
420            self.log.error("WFC Call Failed.")
421            return False
422        return True
423
424    def _check_3g(self):
425        self.log.info("Check 3G data and CS call")
426        if not phone_setup_voice_3g(self.log, self.dut):
427            self.log.error("Failed to setup 3G")
428            return False
429        if not verify_internet_connection(self.log, self.dut):
430            self.log.error("Data not available on cell.")
431            return False
432        if not call_setup_teardown(self.log, self.dut, self.ad_reference,
433                                   self.dut, is_phone_in_call_3g):
434            self.log.error("WFC Call Failed.")
435            return False
436        if not sms_send_receive_verify(self.log, self.dut, self.ad_reference,
437                                       [rand_ascii_str(50)]):
438            self.log.error("SMS failed in 3G")
439            return False
440        return True
441
442    def _check_tethering(self):
443        self.log.info("Check tethering")
444        for i in range(3):
445            try:
446                if not self.dut.droid.carrierConfigIsTetheringModeAllowed(
447                        TETHERING_MODE_WIFI,
448                        MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK):
449                    self.log.error("Tethering Entitlement check failed.")
450                    if i == 2: return False
451                    time.sleep(10)
452            except Exception as e:
453                if i == 2:
454                    self.dut.log.error(e)
455                    return False
456                time.sleep(10)
457        if not wifi_tethering_setup_teardown(
458                self.log,
459                self.dut, [self.ad_reference],
460                check_interval=5,
461                check_iteration=1):
462            self.log.error("Tethering check failed.")
463            return False
464        return True
465
466    def _check_data_roaming_status(self):
467        if not self.dut.droid.telephonyIsDataEnabled():
468            self.log.info("Enabling Cellular Data")
469            telephonyToggleDataConnection(True)
470        else:
471            self.log.info("Cell Data is Enabled")
472        self.log.info("Waiting for cellular data to be connected")
473        if not wait_for_cell_data_connection(self.log, self.dut, state=True):
474            self.log.error("Failed to enable cell data")
475            return False
476        self.log.info("Cellular data connected, checking NetworkInfos")
477        roaming_state = self.dut.droid.telephonyCheckNetworkRoaming()
478        for network_info in self.dut.droid.connectivityNetworkGetAllInfo():
479            sl4a_network_info = Sl4aNetworkInfo.from_dict(network_info)
480            if sl4a_network_info.isRoaming:
481                self.log.warning("We don't expect to be roaming")
482            if sl4a_network_info.isRoaming != roaming_state:
483                self.log.error(
484                    "Mismatched Roaming Status Information Telephony: {}, NetworkInfo {}".
485                    format(roaming_state, sl4a_network_info.isRoaming))
486                self.log.error(network_info)
487                return False
488        return True
489
490    def _reboot_stress_test(self, *args):
491        """Reboot Reliability Test
492
493        Arguments:
494            function_name: function to be checked
495
496        Expected Results:
497            No crash happens in stress test.
498
499        Returns:
500            True is pass, False if fail.
501        """
502        self.number_of_devices = 2
503        fail_count = collections.defaultdict(int)
504        test_result = True
505
506        for i in range(1, self.stress_test_number + 1):
507            begin_time = get_current_epoch_time()
508            test_name = "%s_iteration_%s" % (self.test_name, i)
509            log_msg = "[Test Case] %s" % test_name
510            self.log.info("%s begin", log_msg)
511            self.dut.droid.logI("%s begin" % log_msg)
512            test_msg = "Reboot Stress Test %s Iteration <%s> / <%s>" % (
513                self.test_name, i, self.stress_test_number)
514            self.log.info(test_msg)
515            reboot_device(self.dut)
516            self.log.info("{} wait {}s for radio up.".format(
517                self.dut.serial, WAIT_TIME_AFTER_REBOOT))
518            time.sleep(WAIT_TIME_AFTER_REBOOT)
519            failed_tests = self.feature_validator(*args)
520            for test in failed_tests:
521                fail_count[test] += 1
522
523            crash_report = self.dut.check_crash_report(
524                "%s_%s" % (self.test_name, i),
525                begin_time,
526                log_crash_report=True)
527            if crash_report:
528                fail_count["crashes"] += 1
529            if failed_tests or crash_report:
530                self.log.error("%s FAIL with %s and crashes %s", test_msg,
531                               failed_tests, crash_report)
532                self._take_bug_report(test_name, begin_time)
533            else:
534                self.log.info("%s PASS", test_msg)
535            self.log.info("Total failure count: %s", dict(fail_count))
536            self.log.info("%s end", log_msg)
537            self.dut.droid.logI("%s end" % log_msg)
538
539        for failure, count in fail_count.items():
540            if count:
541                self.log.error("%s failure count = %s in total %s iterations",
542                               failure, count, self.stress_test_number)
543                test_result = False
544        return test_result
545
546    def _crash_recovery_test(self, process, *args):
547        """Crash Recovery Test
548
549        Arguments:
550            process: the process to be killed. For example:
551                "rild", "netmgrd", "com.android.phone", "imsqmidaemon",
552                "imsdatadaemon", "ims_rtp_daemon",
553                "com.android.ims.rcsservice", "system_server", "cnd",
554                "modem"
555
556        Expected Results:
557            All Features should work as intended post crash recovery
558
559        Returns:
560            True is pass, False if fail.
561        """
562        self.number_of_devices = 2
563
564        try:
565            self.dut.droid.logI("======== Trigger %s crash ========" % process)
566        except:
567            pass
568        if process == "modem":
569            self.user_params["check_crash"] = False
570            self.dut.log.info("======== Crash modem from kernal ========")
571            trigger_modem_crash(self.dut)
572        elif process == "modem-crash":
573            self.user_params["check_crash"] = False
574            self.dut.log.info("======== Crash modem from modem ========")
575            trigger_modem_crash_by_modem(self.dut)
576        elif process == "sim":
577            self.dut.log.info("======== Power cycle SIM slot ========")
578            self.user_params["check_crash"] = True
579            sub_id = get_outgoing_voice_sub_id(self.dut)
580            slot_index = get_slot_index_from_subid(self.log, self.dut, sub_id)
581            if not power_off_sim(self.dut, slot_index):
582                self.dut.log.warning("Fail to power off SIM")
583                raise signals.TestSkip("Power cycle SIM not working")
584            if not power_on_sim(self.dut, slot_index):
585                self.dut.log.error("Fail to power on SIM slot")
586                setattr(self.dut, "reboot_to_recover", True)
587                return False
588        else:
589            if process == "rild":
590                if int(self.dut.adb.getprop(
591                        "ro.product.first_api_level")) >= 28:
592                    process = "qcrild"
593            self.dut.log.info("======== Killing process <%s> ========",
594                              process)
595            process_pid = self.dut.adb.shell("pidof %s" % process)
596            self.dut.log.info("Pid of %s is %s", process, process_pid)
597            if not process_pid:
598                self.dut.log.error("Process %s not running", process)
599                return False
600            if process in ("netd", "system_server"):
601                self.dut.stop_services()
602            self.dut.adb.shell("kill -9 %s" % process_pid, ignore_status=True)
603            self.dut.log.info("Wait %s sec for process %s come up.",
604                              WAIT_TIME_AFTER_CRASH, process)
605            time.sleep(WAIT_TIME_AFTER_CRASH)
606            if process in ("netd", "system_server"):
607                self.dut.ensure_screen_on()
608                try:
609                    self.dut.start_services()
610                except Exception as e:
611                    self.dut.log.warning(e)
612            process_pid_new = self.dut.adb.shell("pidof %s" % process)
613            if process_pid == process_pid_new:
614                self.dut.log.error(
615                    "Process %s has the same pid: old:%s new:%s", process,
616                    process_pid, process_pid_new)
617        try:
618            self.dut.droid.logI(
619                "======== Start testing after triggering %s crash ========" %
620                process)
621        except Exception:
622            self.dut.ensure_screen_on()
623            self.dut.start_services()
624            if is_sim_locked(self.dut):
625                unlock_sim(self.dut)
626
627        if process == "ims_rtp_daemon":
628            if not self._check_wfc_enabled:
629                failed_tests = ["_check_wfc_enabled"]
630            else:
631                failed_tests = []
632        else:
633            failed_tests = []
634
635        begin_time = get_current_epoch_time()
636        failed_tests.extend(self.feature_validator(*args))
637        crash_report = self.dut.check_crash_report(
638            self.test_name, begin_time, log_crash_report=True)
639        if failed_tests or crash_report:
640            if failed_tests:
641                self.dut.log.error("%s failed after %s restart", failed_tests,
642                                   process)
643                setattr(self.dut, "reboot_to_recover", True)
644            if crash_report:
645                self.dut.log.error("Crash %s found after %s restart",
646                                   crash_report, process)
647            return False
648        else:
649            return True
650
651    """ Tests Begin """
652
653    @test_tracker_info(uuid="4d9b425b-f804-45f4-8f47-0ba3f01a426b")
654    @TelephonyBaseTest.tel_test_wrap
655    def test_reboot_stress(self):
656        """Reboot with VoLTE Test
657
658        Steps:
659            1. Reboot DUT.
660            2. Wait for DUT to camp
661            3. Verify Subscription, Call, Data, Messaging, Tethering
662            4. Check crashes.
663            5. Repeat Step 1~4 for N times. (before reboot, clear Provisioning
664                bit if provisioning is supported)
665
666        Expected Results:
667            No crash happens in stress test.
668
669        Returns:
670            True is pass, False if fail.
671        """
672        return self._reboot_stress_test(*self.default_testing_func_names)
673
674    @test_tracker_info(uuid="8b0e2c06-02bf-40fd-a374-08860e482757")
675    @TelephonyBaseTest.tel_test_wrap
676    def test_reboot_stress_check_phone_call_only(self):
677        """Reboot with VoLTE Test
678
679        Steps:
680            1. Reboot DUT with volte enabled.
681            2. Wait for DUT to camp on LTE, Verify Data.
682            3. Check VoLTE is enabled by default, check IMS registration.
683               Wait for DUT report VoLTE enabled, make VoLTE call.
684               And verify VoLTE SMS. (if support VoLTE)
685            4. Check crashes.
686            5. Repeat Step 1~4 for N times. (before reboot, clear Provisioning
687                bit if provisioning is supported)
688
689        Expected Results:
690            No crash happens in stress test.
691
692        Returns:
693            True is pass, False if fail.
694        """
695        if not self._check_call_setup_teardown():
696            self.dut.log.error("Call setup test failed before reboot test")
697            return False
698        func_names = [
699            "_check_subscription", "_check_data", "_check_call_setup_teardown"
700        ]
701        return self._reboot_stress_test(*func_names)
702
703    @test_tracker_info(uuid="39a822e5-0360-44ce-97c7-f75468eba8d7")
704    @TelephonyBaseTest.tel_test_wrap
705    def test_reboot_stress_volte_enabled(self):
706        """Reboot with VoLTE Test
707
708        Steps:
709            1. Reboot DUT with volte enabled.
710            2. Wait for DUT to camp on LTE, Verify Data.
711            3. Check VoLTE is enabled by default, check IMS registration.
712               Wait for DUT report VoLTE enabled, make VoLTE call.
713               And verify VoLTE SMS. (if support VoLTE)
714            4. Check crashes.
715            5. Repeat Step 1~4 for N times. (before reboot, clear Provisioning
716                bit if provisioning is supported)
717
718        Expected Results:
719            No crash happens in stress test.
720
721        Returns:
722            True is pass, False if fail.
723        """
724        if CAPABILITY_VOLTE not in self.dut_capabilities:
725            raise signals.TestSkip("VOLTE is not supported")
726        if not self._check_volte():
727            self.dut.log.error("VoLTE test failed before reboot test")
728            return False
729        func_names = ["_check_volte_enabled"]
730        if "_check_vt" in self.default_testing_func_names:
731            func_names.append("_check_vt_enabled")
732        return self._reboot_stress_test(*func_names)
733
734    @test_tracker_info(uuid="3dace255-01a6-46ba-87e0-35396d406c95")
735    @TelephonyBaseTest.tel_test_wrap
736    def test_reboot_stress_csfb(self):
737        """Reboot with VoLTE Test
738
739        Steps:
740            1. Reboot DUT with CSFB.
741            2. Wait for DUT to camp on LTE, Verify Data.
742            3. Check call in CSFB after rebooting.
743            4. Check crashes.
744            5. Repeat Step 1~4 for N times. (before reboot, clear Provisioning
745                bit if provisioning is supported)
746
747        Expected Results:
748            No crash happens in stress test.
749
750        Returns:
751            True is pass, False if fail.
752        """
753        if not self._check_csfb():
754            self.dut.log.error("CSFB test failed before reboot test")
755            return False
756        func_names = ["_check_csfb_enabled"]
757        return self._reboot_stress_test(*func_names)
758
759    @test_tracker_info(uuid="326f5ba4-8819-49bc-af87-6b3c07532de3")
760    @TelephonyBaseTest.tel_test_wrap
761    def test_reboot_stress_volte_provisioning_disabled(self):
762        """Reboot with VoLTE Test
763
764        Steps:
765            1. Reboot DUT with volte provisioning disabled.
766            2. Wait for DUT to camp on LTE, Verify Data.
767            3. Check VoLTE is disabled after rebooting.
768            4. Check crashes.
769            5. Repeat Step 1~4 for N times. (before reboot, clear Provisioning
770                bit if provisioning is supported)
771
772        Expected Results:
773            No crash happens in stress test.
774
775        Returns:
776            True is pass, False if fail.
777        """
778        if CAPABILITY_OMADM not in self.dut_capabilities:
779            raise signals.TestSkip("OMADM is not supported")
780        self._clear_volte_provisioning()
781        if not self._check_csfb():
782            self.dut.log.error("CSFB test failed before reboot test")
783            return False
784        func_names = [
785            "_check_volte_provisioning_disabled", "_check_csfb_enabled"
786        ]
787        return self._reboot_stress_test(*func_names)
788
789    @test_tracker_info(uuid="6c243b53-379a-4cda-9848-84fcec4019bd")
790    @TelephonyBaseTest.tel_test_wrap
791    def test_reboot_stress_wfc_apm(self):
792        """Reboot with WFC in APM Test
793
794        Steps:
795            1. Reboot DUT with wfc in apm mode.
796            2. Check phone call.
797            3. Check crashes.
798            4. Repeat Step 1~4 for N times. (before reboot, clear Provisioning
799                bit if provisioning is supported)
800
801        Expected Results:
802            No crash happens in stress test.
803
804        Returns:
805            True is pass, False if fail.
806        """
807        if CAPABILITY_WFC not in self.dut_capabilities:
808            raise signals.TestSkip("WFC is not supported")
809        if "_check_wfc_apm" not in self.default_testing_func_names:
810            raise signals.TestSkip("WFC in airplane mode is not supported")
811        func_names = ["_check_data", "_check_wfc_enabled"]
812        if "_check_vt" in self.default_testing_func_names:
813            func_names.append("_check_vt_enabled")
814        if not self._check_wfc_apm():
815            self.dut.log.error("WFC in APM test failed before reboot test")
816            return False
817        return self._reboot_stress_test(*func_names)
818
819    @test_tracker_info(uuid="d0439c53-98fa-4303-b097-12ba2462295d")
820    @TelephonyBaseTest.tel_test_wrap
821    def test_reboot_stress_wfc_nonapm(self):
822        """Reboot with WFC in APM Test
823
824        Steps:
825            1. Reboot DUT with wfc in apm mode.
826            2. Check phone call .
827            3. Check crashes.
828            4. Repeat Step 1~4 for N times. (before reboot, clear Provisioning
829                bit if provisioning is supported)
830
831        Expected Results:
832            No crash happens in stress test.
833
834        Returns:
835            True is pass, False if fail.
836        """
837        if CAPABILITY_WFC not in self.dut_capabilities and (
838                WFC_MODE_WIFI_PREFERRED not in self.dut_wfc_modes):
839            raise signals.TestSkip("WFC_NONAPM is not supported")
840        if "_check_wfc_nonapm" not in self.default_testing_func_names:
841            raise signals.TestSkip("WFC in non-airplane mode is not working")
842        func_names = ["_check_wfc_enabled"]
843        if "_check_vt" in self.default_testing_func_names:
844            func_names.append("_check_vt_enabled")
845        if not self._check_wfc_nonapm():
846            self.dut.log.error("WFC test failed before reboot test")
847            return False
848        return self._reboot_stress_test(*func_names)
849
850    @test_tracker_info(uuid="08752fac-dbdb-4d5b-91f6-4ffc3a3ac6d6")
851    @TelephonyBaseTest.tel_test_wrap
852    def test_crash_recovery_modem(self):
853        """Crash Recovery Test
854
855        Steps:
856            1. Crash modem
857            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
858
859        Expected Results:
860            No crash happens in functional test, features work fine.
861
862        Returns:
863            True is pass, False if fail.
864        """
865        return self._crash_recovery_test("modem",
866                                         *self.default_testing_func_names)
867
868    @test_tracker_info(uuid="ce5f4d63-7f3d-48b7-831d-2c1d5db60733")
869    @TelephonyBaseTest.tel_test_wrap
870    def test_crash_recovery_crash_modem_from_modem(self):
871        """Crash Recovery Test
872
873        Steps:
874            1. Crash modem
875            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
876
877        Expected Results:
878            No crash happens in functional test, features work fine.
879
880        Returns:
881            True is pass, False if fail.
882        """
883        if (not self.dut.is_apk_installed("com.google.mdstest")) or (
884                self.dut.adb.getprop("ro.build.version.release")[0] in
885            ("8", "O", "7", "N")) or self.dut.model in ("angler", "bullhead",
886                                                        "sailfish", "marlin"):
887            raise signals.TestSkip(
888                "com.google.mdstest not installed or supported")
889        return self._crash_recovery_test("modem-crash",
890                                         *self.default_testing_func_names)
891
892    @test_tracker_info(uuid="489284e8-77c9-4961-97c8-b6f1a833ff90")
893    @TelephonyBaseTest.tel_test_wrap
894    def test_crash_recovery_rild(self):
895        """Crash Recovery Test
896
897        Steps:
898            1. Crash rild
899            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
900
901        Expected Results:
902            No crash happens in functional test, features work fine.
903
904        Returns:
905            True is pass, False if fail.
906        """
907        return self._crash_recovery_test("rild",
908                                         *self.default_testing_func_names)
909
910    @test_tracker_info(uuid="e1b34b2c-99e6-4966-a11c-88cedc953b47")
911    @TelephonyBaseTest.tel_test_wrap
912    def test_crash_recovery_netmgrd(self):
913        """Crash Recovery Test
914
915        Steps:
916            1. Crash netmgrd
917            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
918
919        Expected Results:
920            No crash happens in functional test, features work fine.
921
922        Returns:
923            True is pass, False if fail.
924        """
925        return self._crash_recovery_test("netmgrd",
926                                         *self.default_testing_func_names)
927
928    @test_tracker_info(uuid="fa34f994-bc49-4444-9187-87691c94b4f4")
929    @TelephonyBaseTest.tel_test_wrap
930    def test_crash_recovery_phone(self):
931        """Crash Recovery Test
932
933        Steps:
934            1. Crash com.android.phone
935            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
936
937        Expected Results:
938            No crash happens in functional test, features work fine.
939
940        Returns:
941            True is pass, False if fail.
942        """
943        return self._crash_recovery_test("com.android.phone",
944                                         *self.default_testing_func_names)
945
946    @test_tracker_info(uuid="6f5a24bb-3cf3-4362-9675-36a6be90282f")
947    @TelephonyBaseTest.tel_test_wrap
948    def test_crash_recovery_imsqmidaemon(self):
949        """Crash Recovery Test
950
951        Steps:
952            1. Crash imsqmidaemon
953            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
954
955        Expected Results:
956            No crash happens in functional test, features work fine.
957
958        Returns:
959            True is pass, False if fail.
960        """
961        return self._crash_recovery_test("imsqmidaemon",
962                                         *self.default_testing_func_names)
963
964    @test_tracker_info(uuid="7a8dc971-054b-47e7-9e57-3bb7b39937d3")
965    @TelephonyBaseTest.tel_test_wrap
966    def test_crash_recovery_imsdatadaemon(self):
967        """Crash Recovery Test
968
969        Steps:
970            1. Crash imsdatadaemon
971            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
972
973        Expected Results:
974            No crash happens in functional test, features work fine.
975
976        Returns:
977            True is pass, False if fail.
978        """
979        return self._crash_recovery_test("imsdatadaemon",
980                                         *self.default_testing_func_names)
981
982    @test_tracker_info(uuid="350ca58c-01f2-4a61-baff-530b8b24f1f6")
983    @TelephonyBaseTest.tel_test_wrap
984    def test_crash_recovery_ims_rtp_daemon(self):
985        """Crash Recovery Test
986
987        Steps:
988            1. Crash imsdatadaemon
989            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
990
991        Expected Results:
992            No crash happens in functional test, features work fine.
993
994        Returns:
995            True is pass, False if fail.
996        """
997        if CAPABILITY_WFC not in self.dut_capabilities:
998            raise signals.TestSkip("WFC is not supported")
999        if WFC_MODE_WIFI_PREFERRED in self.dut_wfc_modes:
1000            self._check_wfc_nonapm()
1001        else:
1002            self._check_wfc_apm()
1003        return self._crash_recovery_test("ims_rtp_daemon",
1004                                         *self.default_testing_func_names)
1005
1006    @test_tracker_info(uuid="af78f33a-2b50-4c55-a302-3701b655c557")
1007    @TelephonyBaseTest.tel_test_wrap
1008    def test_crash_recovery_ims_rcsservice(self):
1009        """Crash Recovery Test
1010
1011        Steps:
1012            1. Crash imsdatadaemon
1013            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
1014
1015        Expected Results:
1016            No crash happens in functional test, features work fine.
1017
1018        Returns:
1019            True is pass, False if fail.
1020        """
1021        return self._crash_recovery_test("com.android.ims.rcsservice",
1022                                         *self.default_testing_func_names)
1023
1024    @test_tracker_info(uuid="8119aeef-84ba-415c-88ea-6eba35bd91fd")
1025    @TelephonyBaseTest.tel_test_wrap
1026    def test_crash_recovery_system_server(self):
1027        """Crash Recovery Test
1028
1029        Steps:
1030            1. Crash system_server
1031            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
1032
1033        Expected Results:
1034            No crash happens in functional test, features work fine.
1035
1036        Returns:
1037            True is pass, False if fail.
1038        """
1039        return self._crash_recovery_test("system_server",
1040                                         *self.default_testing_func_names)
1041
1042    @test_tracker_info(uuid="c3891aca-9e1a-4e37-9f2f-23f12ef0a86f")
1043    @TelephonyBaseTest.tel_test_wrap
1044    def test_crash_recovery_cnd(self):
1045        """Crash Recovery Test
1046
1047        Steps:
1048            1. Crash cnd
1049            2. Post crash recovery, verify Voice, Data, SMS, VoLTE, VT
1050
1051        Expected Results:
1052            No crash happens in functional test, features work fine.
1053
1054        Returns:
1055            True is pass, False if fail.
1056        """
1057        return self._crash_recovery_test("cnd",
1058                                         *self.default_testing_func_names)
1059
1060    @test_tracker_info(uuid="c1b661b9-d5cf-4a22-90a9-3fd55ddc2f3f")
1061    @TelephonyBaseTest.tel_test_wrap
1062    def test_sim_slot_power_cycle(self):
1063        """SIM slot power cycle Test
1064
1065        Steps:
1066            1. Power cycle SIM slot to simulate SIM resit
1067            2. Post power cycle SIM, verify Voice, Data, SMS, VoLTE, VT
1068
1069        Expected Results:
1070            No crash happens in functional test, features work fine.
1071
1072        Returns:
1073            True is pass, False if fail.
1074        """
1075        if self.dut.adb.getprop("ro.build.version.release")[0] in (
1076                "8", "O", "7", "N") or self.dut.model in ("angler", "bullhead",
1077                                                          "marlin",
1078                                                          "sailfish"):
1079            raise signals.TestSkip("Power off SIM is not supported")
1080        return self._crash_recovery_test("sim",
1081                                         *self.default_testing_func_names)
1082
1083
1084""" Tests End """
1085