tturney | 1bdf77d | 2015-12-28 17:46:13 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3.4 |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 2 | # |
tturney | 1bdf77d | 2015-12-28 17:46:13 -0800 | [diff] [blame] | 3 | # Copyright 2016 - Google |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 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 Flight check. |
| 18 | """ |
| 19 | |
Betty Zhou | d01485d | 2017-10-30 17:06:41 -0700 | [diff] [blame] | 20 | from acts import signals |
Betty Zhou | 92626a2 | 2017-12-12 20:07:12 -0800 | [diff] [blame] | 21 | from acts import utils |
Betty Zhou | dd9a9ea | 2018-04-04 13:23:56 -0700 | [diff] [blame] | 22 | |
Betty Zhou | d01485d | 2017-10-30 17:06:41 -0700 | [diff] [blame] | 23 | from acts.controllers.android_device import get_info |
| 24 | from acts.libs.ota import ota_updater |
Betty Zhou | 158c333 | 2017-06-02 17:08:09 -0700 | [diff] [blame] | 25 | from acts.test_decorators import test_tracker_info |
Xianyuan Jia | a4913cd | 2020-11-16 11:58:29 -0800 | [diff] [blame] | 26 | from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest |
| 27 | from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA |
| 28 | from acts.test_utils.tel.tel_defines import RAT_FAMILY_WLAN |
| 29 | from acts.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED |
| 30 | from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED |
| 31 | from acts.test_utils.tel.tel_test_utils import abort_all_tests |
| 32 | from acts.test_utils.tel.tel_test_utils import call_setup_teardown |
| 33 | from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state |
| 34 | from acts.test_utils.tel.tel_test_utils import ensure_phone_subscription |
| 35 | from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected |
| 36 | from acts.test_utils.tel.tel_test_utils import get_user_config_profile |
| 37 | from acts.test_utils.tel.tel_test_utils import is_sim_locked |
| 38 | from acts.test_utils.tel.tel_test_utils import multithread_func |
| 39 | from acts.test_utils.tel.tel_test_utils import unlock_sim |
| 40 | from acts.test_utils.tel.tel_test_utils import verify_internet_connection |
| 41 | from acts.test_utils.tel.tel_test_utils import wait_for_network_rat |
| 42 | from acts.test_utils.tel.tel_test_utils import wait_for_wfc_enabled |
| 43 | from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection |
| 44 | from acts.test_utils.tel.tel_test_utils import wifi_toggle_state |
| 45 | from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan |
| 46 | from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte |
| 47 | from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan |
| 48 | from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan_cellular_preferred |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 49 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 50 | |
Nathan Harold | 0f76cf2 | 2015-12-30 16:33:25 -0800 | [diff] [blame] | 51 | class TelLivePreflightTest(TelephonyBaseTest): |
Xianyuan Jia | 2a8522e | 2019-09-05 17:21:40 -0700 | [diff] [blame] | 52 | def setup_class(self): |
| 53 | super().setup_class() |
Betty Zhou | fd85e39 | 2018-03-27 21:15:10 -0700 | [diff] [blame] | 54 | self.user_params["telephony_auto_rerun"] = 0 |
Yang Liu | d772709 | 2016-05-24 14:38:36 -0700 | [diff] [blame] | 55 | |
Betty Zhou | dd9a9ea | 2018-04-04 13:23:56 -0700 | [diff] [blame] | 56 | def _check_wfc_enabled(self, ad): |
| 57 | if not wait_for_wifi_data_connection(self.log, ad, True): |
| 58 | ad.log.error("Failed to connect to WIFI") |
| 59 | return False |
| 60 | if not wait_for_wfc_enabled(self.log, ad): |
| 61 | ad.log.error("WFC is not enabled") |
| 62 | return False |
| 63 | if not wait_for_network_rat( |
| 64 | self.log, ad, RAT_FAMILY_WLAN, |
| 65 | voice_or_data=NETWORK_SERVICE_DATA): |
| 66 | ad.log.info("Data rat can not go to iwlan mode successfully") |
| 67 | return False |
| 68 | return True |
| 69 | |
| 70 | def _get_call_verification_function(self, ad): |
| 71 | user_profile = get_user_config_profile(ad) |
| 72 | if user_profile.get("WFC Enabled", False): |
| 73 | return is_phone_in_call_iwlan |
| 74 | if user_profile.get("VoLTE Enabled", False): |
| 75 | return is_phone_in_call_volte |
| 76 | return None |
| 77 | |
| 78 | def _set_user_profile_before_ota(self): |
| 79 | ad = self.android_devices[0] |
| 80 | if not phone_setup_iwlan_cellular_preferred( |
| 81 | self.log, ad, self.wifi_network_ssid, self.wifi_network_pass): |
| 82 | ad.log.error("Failed to setup WFC to %s.", |
| 83 | WFC_MODE_CELLULAR_PREFERRED) |
| 84 | if len(self.android_devices) > 1: |
| 85 | ad = self.android_devices[1] |
| 86 | if not phone_setup_iwlan( |
| 87 | self.log, ad, True, WFC_MODE_WIFI_PREFERRED, |
| 88 | self.wifi_network_ssid, self.wifi_network_pass): |
| 89 | ad.log.error("Failed to setup WFC to %s.", |
| 90 | WFC_MODE_WIFI_PREFERRED) |
| 91 | |
| 92 | if ad.droid.imsIsEnhanced4gLteModeSettingEnabledByPlatform(): |
| 93 | ad.droid.imsSetEnhanced4gMode(False) |
| 94 | state = ad.droid.imsIsEnhanced4gLteModeSettingEnabledByUser() |
| 95 | ad.log.info("Enhanced 4G LTE Setting is %s", "on" |
| 96 | if state else "off") |
| 97 | if state: |
| 98 | ad.log.error("Expecting Enhanced 4G LTE Setting off") |
| 99 | |
| 100 | def _ota_upgrade(self, ad): |
Betty Zhou | a36c435 | 2018-04-05 18:49:32 -0700 | [diff] [blame] | 101 | result = True |
Betty Zhou | dd9a9ea | 2018-04-04 13:23:56 -0700 | [diff] [blame] | 102 | self._set_user_profile_before_ota() |
| 103 | config_profile_before = get_user_config_profile(ad) |
| 104 | ad.log.info("Before OTA user config is: %s", config_profile_before) |
| 105 | try: |
| 106 | ota_updater.update(ad) |
| 107 | except Exception as e: |
| 108 | ad.log.error("OTA upgrade failed with %s", e) |
| 109 | raise |
| 110 | if is_sim_locked(ad): |
| 111 | ad.log.info("After OTA, SIM keeps the locked state") |
| 112 | elif getattr(ad, "is_sim_locked", False): |
| 113 | ad.log.error("After OTA, SIM loses the locked state") |
Betty Zhou | a36c435 | 2018-04-05 18:49:32 -0700 | [diff] [blame] | 114 | result = False |
Betty Zhou | dd9a9ea | 2018-04-04 13:23:56 -0700 | [diff] [blame] | 115 | if not unlock_sim(ad): |
| 116 | ad.log.error(ad.log, "unable to unlock SIM") |
Betty Zhou | a36c435 | 2018-04-05 18:49:32 -0700 | [diff] [blame] | 117 | if not ad.droid.connectivityCheckAirplaneMode(): |
| 118 | if not ensure_phone_subscription(self.log, ad): |
| 119 | ad.log.error("Subscription check failed") |
| 120 | result = False |
Betty Zhou | dd9a9ea | 2018-04-04 13:23:56 -0700 | [diff] [blame] | 121 | if config_profile_before.get("WFC Enabled", False): |
| 122 | self._check_wfc_enabled(ad) |
Betty Zhou | a36c435 | 2018-04-05 18:49:32 -0700 | [diff] [blame] | 123 | result = False |
Betty Zhou | dd9a9ea | 2018-04-04 13:23:56 -0700 | [diff] [blame] | 124 | config_profile_after = get_user_config_profile(ad) |
| 125 | ad.log.info("After OTA user config is: %s", config_profile_after) |
| 126 | if config_profile_before != config_profile_after: |
Betty Zhou | 2bb1168 | 2018-04-19 17:05:30 -0700 | [diff] [blame] | 127 | ad.log.error("Before: %s, After: %s", config_profile_before, |
| 128 | config_profile_after) |
Betty Zhou | dd9a9ea | 2018-04-04 13:23:56 -0700 | [diff] [blame] | 129 | ad.log.error("User config profile changed after OTA") |
Betty Zhou | a36c435 | 2018-04-05 18:49:32 -0700 | [diff] [blame] | 130 | result = False |
| 131 | return result |
Betty Zhou | 96b5bf4 | 2018-03-23 19:18:41 -0700 | [diff] [blame] | 132 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 133 | """ Tests Begin """ |
Nathan Harold | b1487af | 2016-07-19 16:05:37 -0700 | [diff] [blame] | 134 | |
Betty Zhou | d01485d | 2017-10-30 17:06:41 -0700 | [diff] [blame] | 135 | @test_tracker_info(uuid="cb897221-99e1-4697-927e-02d92d969440") |
| 136 | @TelephonyBaseTest.tel_test_wrap |
| 137 | def test_ota_upgrade(self): |
| 138 | ota_package = self.user_params.get("ota_package") |
| 139 | if isinstance(ota_package, list): |
| 140 | ota_package = ota_package[0] |
| 141 | if ota_package and "dev/null" not in ota_package: |
| 142 | self.log.info("Upgrade with ota_package %s", ota_package) |
| 143 | self.log.info("Before OTA upgrade: %s", |
| 144 | get_info(self.android_devices)) |
| 145 | else: |
| 146 | raise signals.TestSkip("No ota_package is defined") |
Betty Zhou | 4a516de | 2017-10-31 17:18:55 -0700 | [diff] [blame] | 147 | ota_util = self.user_params.get("ota_util") |
| 148 | if isinstance(ota_util, list): |
| 149 | ota_util = ota_util[0] |
| 150 | if ota_util: |
| 151 | if "update_engine_client.zip" in ota_util: |
| 152 | self.user_params["UpdateDeviceOtaTool"] = ota_util |
| 153 | self.user_params["ota_tool"] = "UpdateDeviceOtaTool" |
| 154 | else: |
| 155 | self.user_params["AdbSideloadOtaTool"] = ota_util |
| 156 | self.user_params["ota_tool"] = "AdbSideloadOtaTool" |
| 157 | self.log.info("OTA upgrade with %s by %s", ota_package, |
| 158 | self.user_params["ota_tool"]) |
Betty Zhou | d01485d | 2017-10-30 17:06:41 -0700 | [diff] [blame] | 159 | ota_updater.initialize(self.user_params, self.android_devices) |
Betty Zhou | dd9a9ea | 2018-04-04 13:23:56 -0700 | [diff] [blame] | 160 | tasks = [(self._ota_upgrade, [ad]) for ad in self.android_devices] |
Betty Zhou | d01485d | 2017-10-30 17:06:41 -0700 | [diff] [blame] | 161 | try: |
Betty Zhou | a36c435 | 2018-04-05 18:49:32 -0700 | [diff] [blame] | 162 | result = multithread_func(self.log, tasks) |
Betty Zhou | d01485d | 2017-10-30 17:06:41 -0700 | [diff] [blame] | 163 | except Exception as err: |
Betty Zhou | d38a47e | 2017-11-29 16:48:58 -0800 | [diff] [blame] | 164 | abort_all_tests(self.log, "Unable to do ota upgrade: %s" % err) |
Betty Zhou | d01485d | 2017-10-30 17:06:41 -0700 | [diff] [blame] | 165 | device_info = get_info(self.android_devices) |
| 166 | self.log.info("After OTA upgrade: %s", device_info) |
| 167 | self.results.add_controller_info("AndroidDevice", device_info) |
Betty Zhou | dd9a9ea | 2018-04-04 13:23:56 -0700 | [diff] [blame] | 168 | if len(self.android_devices) > 1: |
| 169 | caller = self.android_devices[0] |
| 170 | callee = self.android_devices[1] |
| 171 | return call_setup_teardown( |
| 172 | self.log, caller, callee, caller, |
| 173 | self._get_call_verification_function(caller), |
Betty Zhou | a36c435 | 2018-04-05 18:49:32 -0700 | [diff] [blame] | 174 | self._get_call_verification_function(callee)) and result |
| 175 | return result |
Betty Zhou | d01485d | 2017-10-30 17:06:41 -0700 | [diff] [blame] | 176 | |
Betty Zhou | 158c333 | 2017-06-02 17:08:09 -0700 | [diff] [blame] | 177 | @test_tracker_info(uuid="8390a2eb-a744-4cda-bade-f94a2cc83f02") |
Yang Liu | d772709 | 2016-05-24 14:38:36 -0700 | [diff] [blame] | 178 | @TelephonyBaseTest.tel_test_wrap |
| 179 | def test_check_environment(self): |
| 180 | ad = self.android_devices[0] |
| 181 | # Check WiFi environment. |
| 182 | # 1. Connect to WiFi. |
| 183 | # 2. Check WiFi have Internet access. |
Yang Liu | d772709 | 2016-05-24 14:38:36 -0700 | [diff] [blame] | 184 | try: |
| 185 | if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid, |
| 186 | self.wifi_network_pass): |
Betty Zhou | 5534e67 | 2017-03-07 13:47:10 -0800 | [diff] [blame] | 187 | abort_all_tests(ad.log, "WiFi connect fail") |
Betty Zhou | 3b2de07 | 2018-03-15 16:46:26 -0700 | [diff] [blame] | 188 | if (not wait_for_wifi_data_connection(self.log, ad, True) |
Betty Zhou | 96b5bf4 | 2018-03-23 19:18:41 -0700 | [diff] [blame] | 189 | or not verify_internet_connection(self.log, ad)): |
Betty Zhou | 5534e67 | 2017-03-07 13:47:10 -0800 | [diff] [blame] | 190 | abort_all_tests(ad.log, "Data not available on WiFi") |
Yang Liu | d772709 | 2016-05-24 14:38:36 -0700 | [diff] [blame] | 191 | finally: |
Betty Zhou | f987b8f | 2017-03-09 16:34:00 -0800 | [diff] [blame] | 192 | wifi_toggle_state(self.log, ad, False) |
Yang Liu | d772709 | 2016-05-24 14:38:36 -0700 | [diff] [blame] | 193 | # TODO: add more environment check here. |
| 194 | return True |
Nathan Harold | 0f76cf2 | 2015-12-30 16:33:25 -0800 | [diff] [blame] | 195 | |
Betty Zhou | 158c333 | 2017-06-02 17:08:09 -0700 | [diff] [blame] | 196 | @test_tracker_info(uuid="7bb23ac7-6b7b-4d5e-b8d6-9dd10032b9ad") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 197 | @TelephonyBaseTest.tel_test_wrap |
| 198 | def test_pre_flight_check(self): |
Betty Zhou | 96b5bf4 | 2018-03-23 19:18:41 -0700 | [diff] [blame] | 199 | return ensure_phones_default_state(self.log, self.android_devices) |
Nathan Harold | 0f76cf2 | 2015-12-30 16:33:25 -0800 | [diff] [blame] | 200 | |
Betty Zhou | 158c333 | 2017-06-02 17:08:09 -0700 | [diff] [blame] | 201 | @test_tracker_info(uuid="1070b160-902b-43bf-92a0-92cc2d05bb13") |
Betty Zhou | ec8378f | 2016-12-21 17:28:48 -0800 | [diff] [blame] | 202 | @TelephonyBaseTest.tel_test_wrap |
| 203 | def test_check_crash(self): |
Betty Zhou | 48a343e | 2017-08-31 17:39:13 -0700 | [diff] [blame] | 204 | result = True |
Jaineel | 30bc335 | 2017-10-18 17:10:01 -0700 | [diff] [blame] | 205 | begin_time = None |
Betty Zhou | ec8378f | 2016-12-21 17:28:48 -0800 | [diff] [blame] | 206 | for ad in self.android_devices: |
Betty Zhou | 92626a2 | 2017-12-12 20:07:12 -0800 | [diff] [blame] | 207 | output = ad.adb.shell("cat /proc/uptime") |
| 208 | epoch_up_time = utils.get_current_epoch_time() - 1000 * float( |
| 209 | output.split(" ")[0]) |
Betty Zhou | d01485d | 2017-10-30 17:06:41 -0700 | [diff] [blame] | 210 | ad.crash_report_preflight = ad.check_crash_report( |
Betty Zhou | 92626a2 | 2017-12-12 20:07:12 -0800 | [diff] [blame] | 211 | self.test_name, |
| 212 | begin_time=epoch_up_time, |
| 213 | log_crash_report=True) |
Betty Zhou | 7f45f55 | 2017-03-15 19:12:52 -0700 | [diff] [blame] | 214 | if ad.crash_report_preflight: |
| 215 | msg = "Find crash reports %s before test starts" % ( |
| 216 | ad.crash_report_preflight) |
| 217 | ad.log.warn(msg) |
Betty Zhou | 48a343e | 2017-08-31 17:39:13 -0700 | [diff] [blame] | 218 | result = False |
| 219 | return result |