blob: 134255e18dd117961ed7b37b4e197c998065f2b4 [file] [log] [blame]
tturney1bdf77d2015-12-28 17:46:13 -08001#!/usr/bin/env python3.4
Ang Li73697b32015-12-03 00:41:53 +00002#
tturney1bdf77d2015-12-28 17:46:13 -08003# Copyright 2016 - Google
Ang Li73697b32015-12-03 00:41:53 +00004#
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 Zhoud01485d2017-10-30 17:06:41 -070020from acts import signals
Betty Zhou92626a22017-12-12 20:07:12 -080021from acts import utils
Betty Zhoudd9a9ea2018-04-04 13:23:56 -070022
Betty Zhoud01485d2017-10-30 17:06:41 -070023from acts.controllers.android_device import get_info
24from acts.libs.ota import ota_updater
Betty Zhou158c3332017-06-02 17:08:09 -070025from acts.test_decorators import test_tracker_info
Xianyuan Jia63751fb2020-11-17 00:07:40 +000026from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
27from acts_contrib.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA
28from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_WLAN
29from acts_contrib.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED
30from acts_contrib.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
31from acts_contrib.test_utils.tel.tel_test_utils import abort_all_tests
32from acts_contrib.test_utils.tel.tel_test_utils import call_setup_teardown
33from acts_contrib.test_utils.tel.tel_test_utils import ensure_phones_default_state
34from acts_contrib.test_utils.tel.tel_test_utils import ensure_phone_subscription
35from acts_contrib.test_utils.tel.tel_test_utils import ensure_wifi_connected
36from acts_contrib.test_utils.tel.tel_test_utils import get_user_config_profile
37from acts_contrib.test_utils.tel.tel_test_utils import is_sim_locked
38from acts_contrib.test_utils.tel.tel_test_utils import multithread_func
39from acts_contrib.test_utils.tel.tel_test_utils import unlock_sim
40from acts_contrib.test_utils.tel.tel_test_utils import verify_internet_connection
41from acts_contrib.test_utils.tel.tel_test_utils import wait_for_network_rat
42from acts_contrib.test_utils.tel.tel_test_utils import wait_for_wfc_enabled
43from acts_contrib.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
44from acts_contrib.test_utils.tel.tel_test_utils import wifi_toggle_state
45from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
46from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
47from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_iwlan
48from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_iwlan_cellular_preferred
Ang Li73697b32015-12-03 00:41:53 +000049
Ang Li73697b32015-12-03 00:41:53 +000050
Nathan Harold0f76cf22015-12-30 16:33:25 -080051class TelLivePreflightTest(TelephonyBaseTest):
Xianyuan Jia2a8522e2019-09-05 17:21:40 -070052 def setup_class(self):
53 super().setup_class()
Betty Zhoufd85e392018-03-27 21:15:10 -070054 self.user_params["telephony_auto_rerun"] = 0
Yang Liud7727092016-05-24 14:38:36 -070055
Betty Zhoudd9a9ea2018-04-04 13:23:56 -070056 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 Zhoua36c4352018-04-05 18:49:32 -0700101 result = True
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700102 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 Zhoua36c4352018-04-05 18:49:32 -0700114 result = False
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700115 if not unlock_sim(ad):
116 ad.log.error(ad.log, "unable to unlock SIM")
Betty Zhoua36c4352018-04-05 18:49:32 -0700117 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 Zhoudd9a9ea2018-04-04 13:23:56 -0700121 if config_profile_before.get("WFC Enabled", False):
122 self._check_wfc_enabled(ad)
Betty Zhoua36c4352018-04-05 18:49:32 -0700123 result = False
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700124 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 Zhou2bb11682018-04-19 17:05:30 -0700127 ad.log.error("Before: %s, After: %s", config_profile_before,
128 config_profile_after)
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700129 ad.log.error("User config profile changed after OTA")
Betty Zhoua36c4352018-04-05 18:49:32 -0700130 result = False
131 return result
Betty Zhou96b5bf42018-03-23 19:18:41 -0700132
Ang Li73697b32015-12-03 00:41:53 +0000133 """ Tests Begin """
Nathan Haroldb1487af2016-07-19 16:05:37 -0700134
Betty Zhoud01485d2017-10-30 17:06:41 -0700135 @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 Zhou4a516de2017-10-31 17:18:55 -0700147 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 Zhoud01485d2017-10-30 17:06:41 -0700159 ota_updater.initialize(self.user_params, self.android_devices)
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700160 tasks = [(self._ota_upgrade, [ad]) for ad in self.android_devices]
Betty Zhoud01485d2017-10-30 17:06:41 -0700161 try:
Betty Zhoua36c4352018-04-05 18:49:32 -0700162 result = multithread_func(self.log, tasks)
Betty Zhoud01485d2017-10-30 17:06:41 -0700163 except Exception as err:
Betty Zhoud38a47e2017-11-29 16:48:58 -0800164 abort_all_tests(self.log, "Unable to do ota upgrade: %s" % err)
Betty Zhoud01485d2017-10-30 17:06:41 -0700165 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 Zhoudd9a9ea2018-04-04 13:23:56 -0700168 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 Zhoua36c4352018-04-05 18:49:32 -0700174 self._get_call_verification_function(callee)) and result
175 return result
Betty Zhoud01485d2017-10-30 17:06:41 -0700176
Betty Zhou158c3332017-06-02 17:08:09 -0700177 @test_tracker_info(uuid="8390a2eb-a744-4cda-bade-f94a2cc83f02")
Yang Liud7727092016-05-24 14:38:36 -0700178 @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 Liud7727092016-05-24 14:38:36 -0700184 try:
185 if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
186 self.wifi_network_pass):
Betty Zhou5534e672017-03-07 13:47:10 -0800187 abort_all_tests(ad.log, "WiFi connect fail")
Betty Zhou3b2de072018-03-15 16:46:26 -0700188 if (not wait_for_wifi_data_connection(self.log, ad, True)
Betty Zhou96b5bf42018-03-23 19:18:41 -0700189 or not verify_internet_connection(self.log, ad)):
Betty Zhou5534e672017-03-07 13:47:10 -0800190 abort_all_tests(ad.log, "Data not available on WiFi")
Yang Liud7727092016-05-24 14:38:36 -0700191 finally:
Betty Zhouf987b8f2017-03-09 16:34:00 -0800192 wifi_toggle_state(self.log, ad, False)
Yang Liud7727092016-05-24 14:38:36 -0700193 # TODO: add more environment check here.
194 return True
Nathan Harold0f76cf22015-12-30 16:33:25 -0800195
Betty Zhou158c3332017-06-02 17:08:09 -0700196 @test_tracker_info(uuid="7bb23ac7-6b7b-4d5e-b8d6-9dd10032b9ad")
Ang Li73697b32015-12-03 00:41:53 +0000197 @TelephonyBaseTest.tel_test_wrap
198 def test_pre_flight_check(self):
Betty Zhou96b5bf42018-03-23 19:18:41 -0700199 return ensure_phones_default_state(self.log, self.android_devices)
Nathan Harold0f76cf22015-12-30 16:33:25 -0800200
Betty Zhou158c3332017-06-02 17:08:09 -0700201 @test_tracker_info(uuid="1070b160-902b-43bf-92a0-92cc2d05bb13")
Betty Zhouec8378f2016-12-21 17:28:48 -0800202 @TelephonyBaseTest.tel_test_wrap
203 def test_check_crash(self):
Betty Zhou48a343e2017-08-31 17:39:13 -0700204 result = True
Jaineel30bc3352017-10-18 17:10:01 -0700205 begin_time = None
Betty Zhouec8378f2016-12-21 17:28:48 -0800206 for ad in self.android_devices:
Betty Zhou92626a22017-12-12 20:07:12 -0800207 output = ad.adb.shell("cat /proc/uptime")
208 epoch_up_time = utils.get_current_epoch_time() - 1000 * float(
209 output.split(" ")[0])
Betty Zhoud01485d2017-10-30 17:06:41 -0700210 ad.crash_report_preflight = ad.check_crash_report(
Betty Zhou92626a22017-12-12 20:07:12 -0800211 self.test_name,
212 begin_time=epoch_up_time,
213 log_crash_report=True)
Betty Zhou7f45f552017-03-15 19:12:52 -0700214 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 Zhou48a343e2017-08-31 17:39:13 -0700218 result = False
219 return result