blob: 3115c1806f35aaf5114e8f2adad736320ac860d5 [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
Yang Liu52cc0202015-12-28 14:08:52 -080026from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
Betty Zhoudd9a9ea2018-04-04 13:23:56 -070027from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA
28from acts.test_utils.tel.tel_defines import RAT_FAMILY_WLAN
29from acts.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED
30from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
Betty Zhou5534e672017-03-07 13:47:10 -080031from acts.test_utils.tel.tel_test_utils import abort_all_tests
Betty Zhoudd9a9ea2018-04-04 13:23:56 -070032from acts.test_utils.tel.tel_test_utils import call_setup_teardown
Yang Liu52cc0202015-12-28 14:08:52 -080033from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state
Betty Zhoua36c4352018-04-05 18:49:32 -070034from acts.test_utils.tel.tel_test_utils import ensure_phone_subscription
Yang Liud7727092016-05-24 14:38:36 -070035from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
Betty Zhoudd9a9ea2018-04-04 13:23:56 -070036from acts.test_utils.tel.tel_test_utils import get_user_config_profile
Betty Zhoue66efb42018-01-31 19:45:56 -080037from acts.test_utils.tel.tel_test_utils import is_sim_locked
Betty Zhoua36c4352018-04-05 18:49:32 -070038from acts.test_utils.tel.tel_test_utils import multithread_func
Betty Zhoub9312fb2017-11-03 15:02:21 -070039from acts.test_utils.tel.tel_test_utils import unlock_sim
Betty Zhou96b5bf42018-03-23 19:18:41 -070040from acts.test_utils.tel.tel_test_utils import verify_internet_connection
Betty Zhoudd9a9ea2018-04-04 13:23:56 -070041from acts.test_utils.tel.tel_test_utils import wait_for_network_rat
42from acts.test_utils.tel.tel_test_utils import wait_for_wfc_enabled
Yang Liud7727092016-05-24 14:38:36 -070043from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
Betty Zhouf987b8f2017-03-09 16:34:00 -080044from acts.test_utils.tel.tel_test_utils import wifi_toggle_state
Betty Zhoudd9a9ea2018-04-04 13:23:56 -070045from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
46from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
47from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan
48from acts.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):
Ang Li73697b32015-12-03 00:41:53 +000052 def __init__(self, controllers):
53 TelephonyBaseTest.__init__(self, controllers)
Ang Li73697b32015-12-03 00:41:53 +000054
Betty Zhou061ae082016-12-01 15:26:24 -080055 self.wifi_network_ssid = self.user_params.get(
Betty Zhou5e7ac612017-10-10 11:54:45 -070056 "wifi_network_ssid") or self.user_params.get(
Betty Zhou550fd372017-10-16 17:22:47 -070057 "wifi_network_ssid_2g") or self.user_params.get(
58 "wifi_network_ssid_5g")
Betty Zhou061ae082016-12-01 15:26:24 -080059 self.wifi_network_pass = self.user_params.get(
Betty Zhou5e7ac612017-10-10 11:54:45 -070060 "wifi_network_pass") or self.user_params.get(
Betty Zhou550fd372017-10-16 17:22:47 -070061 "wifi_network_pass_2g") or self.user_params.get(
62 "wifi_network_ssid_5g")
Betty Zhoufd85e392018-03-27 21:15:10 -070063 self.user_params["telephony_auto_rerun"] = 0
Yang Liud7727092016-05-24 14:38:36 -070064
Betty Zhoudd9a9ea2018-04-04 13:23:56 -070065 def _check_wfc_enabled(self, ad):
66 if not wait_for_wifi_data_connection(self.log, ad, True):
67 ad.log.error("Failed to connect to WIFI")
68 return False
69 if not wait_for_wfc_enabled(self.log, ad):
70 ad.log.error("WFC is not enabled")
71 return False
72 if not wait_for_network_rat(
73 self.log, ad, RAT_FAMILY_WLAN,
74 voice_or_data=NETWORK_SERVICE_DATA):
75 ad.log.info("Data rat can not go to iwlan mode successfully")
76 return False
77 return True
78
79 def _get_call_verification_function(self, ad):
80 user_profile = get_user_config_profile(ad)
81 if user_profile.get("WFC Enabled", False):
82 return is_phone_in_call_iwlan
83 if user_profile.get("VoLTE Enabled", False):
84 return is_phone_in_call_volte
85 return None
86
87 def _set_user_profile_before_ota(self):
88 ad = self.android_devices[0]
89 if not phone_setup_iwlan_cellular_preferred(
90 self.log, ad, self.wifi_network_ssid, self.wifi_network_pass):
91 ad.log.error("Failed to setup WFC to %s.",
92 WFC_MODE_CELLULAR_PREFERRED)
93 if len(self.android_devices) > 1:
94 ad = self.android_devices[1]
95 if not phone_setup_iwlan(
96 self.log, ad, True, WFC_MODE_WIFI_PREFERRED,
97 self.wifi_network_ssid, self.wifi_network_pass):
98 ad.log.error("Failed to setup WFC to %s.",
99 WFC_MODE_WIFI_PREFERRED)
100
101 if ad.droid.imsIsEnhanced4gLteModeSettingEnabledByPlatform():
102 ad.droid.imsSetEnhanced4gMode(False)
103 state = ad.droid.imsIsEnhanced4gLteModeSettingEnabledByUser()
104 ad.log.info("Enhanced 4G LTE Setting is %s", "on"
105 if state else "off")
106 if state:
107 ad.log.error("Expecting Enhanced 4G LTE Setting off")
108
109 def _ota_upgrade(self, ad):
Betty Zhoua36c4352018-04-05 18:49:32 -0700110 result = True
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700111 self._set_user_profile_before_ota()
112 config_profile_before = get_user_config_profile(ad)
113 ad.log.info("Before OTA user config is: %s", config_profile_before)
114 try:
115 ota_updater.update(ad)
116 except Exception as e:
117 ad.log.error("OTA upgrade failed with %s", e)
118 raise
119 if is_sim_locked(ad):
120 ad.log.info("After OTA, SIM keeps the locked state")
121 elif getattr(ad, "is_sim_locked", False):
122 ad.log.error("After OTA, SIM loses the locked state")
Betty Zhoua36c4352018-04-05 18:49:32 -0700123 result = False
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700124 if not unlock_sim(ad):
125 ad.log.error(ad.log, "unable to unlock SIM")
Betty Zhoua36c4352018-04-05 18:49:32 -0700126 if not ad.droid.connectivityCheckAirplaneMode():
127 if not ensure_phone_subscription(self.log, ad):
128 ad.log.error("Subscription check failed")
129 result = False
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700130 if config_profile_before.get("WFC Enabled", False):
131 self._check_wfc_enabled(ad)
Betty Zhoua36c4352018-04-05 18:49:32 -0700132 result = False
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700133 config_profile_after = get_user_config_profile(ad)
134 ad.log.info("After OTA user config is: %s", config_profile_after)
135 if config_profile_before != config_profile_after:
136 ad.log.error("User config profile changed after OTA")
Betty Zhoua36c4352018-04-05 18:49:32 -0700137 result = False
138 return result
Betty Zhou96b5bf42018-03-23 19:18:41 -0700139
Ang Li73697b32015-12-03 00:41:53 +0000140 """ Tests Begin """
Nathan Haroldb1487af2016-07-19 16:05:37 -0700141
Betty Zhoud01485d2017-10-30 17:06:41 -0700142 @test_tracker_info(uuid="cb897221-99e1-4697-927e-02d92d969440")
143 @TelephonyBaseTest.tel_test_wrap
144 def test_ota_upgrade(self):
145 ota_package = self.user_params.get("ota_package")
146 if isinstance(ota_package, list):
147 ota_package = ota_package[0]
148 if ota_package and "dev/null" not in ota_package:
149 self.log.info("Upgrade with ota_package %s", ota_package)
150 self.log.info("Before OTA upgrade: %s",
151 get_info(self.android_devices))
152 else:
153 raise signals.TestSkip("No ota_package is defined")
Betty Zhou4a516de2017-10-31 17:18:55 -0700154 ota_util = self.user_params.get("ota_util")
155 if isinstance(ota_util, list):
156 ota_util = ota_util[0]
157 if ota_util:
158 if "update_engine_client.zip" in ota_util:
159 self.user_params["UpdateDeviceOtaTool"] = ota_util
160 self.user_params["ota_tool"] = "UpdateDeviceOtaTool"
161 else:
162 self.user_params["AdbSideloadOtaTool"] = ota_util
163 self.user_params["ota_tool"] = "AdbSideloadOtaTool"
164 self.log.info("OTA upgrade with %s by %s", ota_package,
165 self.user_params["ota_tool"])
Betty Zhoud01485d2017-10-30 17:06:41 -0700166 ota_updater.initialize(self.user_params, self.android_devices)
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700167 tasks = [(self._ota_upgrade, [ad]) for ad in self.android_devices]
Betty Zhoud01485d2017-10-30 17:06:41 -0700168 try:
Betty Zhoua36c4352018-04-05 18:49:32 -0700169 result = multithread_func(self.log, tasks)
Betty Zhoud01485d2017-10-30 17:06:41 -0700170 except Exception as err:
Betty Zhoud38a47e2017-11-29 16:48:58 -0800171 abort_all_tests(self.log, "Unable to do ota upgrade: %s" % err)
Betty Zhoud01485d2017-10-30 17:06:41 -0700172 device_info = get_info(self.android_devices)
173 self.log.info("After OTA upgrade: %s", device_info)
174 self.results.add_controller_info("AndroidDevice", device_info)
Betty Zhoudd9a9ea2018-04-04 13:23:56 -0700175 if len(self.android_devices) > 1:
176 caller = self.android_devices[0]
177 callee = self.android_devices[1]
178 return call_setup_teardown(
179 self.log, caller, callee, caller,
180 self._get_call_verification_function(caller),
Betty Zhoua36c4352018-04-05 18:49:32 -0700181 self._get_call_verification_function(callee)) and result
182 return result
Betty Zhoud01485d2017-10-30 17:06:41 -0700183
Betty Zhou158c3332017-06-02 17:08:09 -0700184 @test_tracker_info(uuid="8390a2eb-a744-4cda-bade-f94a2cc83f02")
Yang Liud7727092016-05-24 14:38:36 -0700185 @TelephonyBaseTest.tel_test_wrap
186 def test_check_environment(self):
187 ad = self.android_devices[0]
188 # Check WiFi environment.
189 # 1. Connect to WiFi.
190 # 2. Check WiFi have Internet access.
Betty Zhou061ae082016-12-01 15:26:24 -0800191 toggle_airplane_mode(self.log, ad, False, strict_checking=False)
Yang Liud7727092016-05-24 14:38:36 -0700192 try:
193 if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
194 self.wifi_network_pass):
Betty Zhou5534e672017-03-07 13:47:10 -0800195 abort_all_tests(ad.log, "WiFi connect fail")
Betty Zhou3b2de072018-03-15 16:46:26 -0700196 if (not wait_for_wifi_data_connection(self.log, ad, True)
Betty Zhou96b5bf42018-03-23 19:18:41 -0700197 or not verify_internet_connection(self.log, ad)):
Betty Zhou5534e672017-03-07 13:47:10 -0800198 abort_all_tests(ad.log, "Data not available on WiFi")
Yang Liud7727092016-05-24 14:38:36 -0700199 finally:
Betty Zhouf987b8f2017-03-09 16:34:00 -0800200 wifi_toggle_state(self.log, ad, False)
Yang Liud7727092016-05-24 14:38:36 -0700201 # TODO: add more environment check here.
202 return True
Nathan Harold0f76cf22015-12-30 16:33:25 -0800203
Betty Zhou158c3332017-06-02 17:08:09 -0700204 @test_tracker_info(uuid="7bb23ac7-6b7b-4d5e-b8d6-9dd10032b9ad")
Ang Li73697b32015-12-03 00:41:53 +0000205 @TelephonyBaseTest.tel_test_wrap
206 def test_pre_flight_check(self):
Betty Zhou96b5bf42018-03-23 19:18:41 -0700207 return ensure_phones_default_state(self.log, self.android_devices)
Nathan Harold0f76cf22015-12-30 16:33:25 -0800208
Betty Zhou158c3332017-06-02 17:08:09 -0700209 @test_tracker_info(uuid="1070b160-902b-43bf-92a0-92cc2d05bb13")
Betty Zhouec8378f2016-12-21 17:28:48 -0800210 @TelephonyBaseTest.tel_test_wrap
211 def test_check_crash(self):
Betty Zhou48a343e2017-08-31 17:39:13 -0700212 result = True
Jaineel30bc3352017-10-18 17:10:01 -0700213 begin_time = None
Betty Zhouec8378f2016-12-21 17:28:48 -0800214 for ad in self.android_devices:
Betty Zhou92626a22017-12-12 20:07:12 -0800215 output = ad.adb.shell("cat /proc/uptime")
216 epoch_up_time = utils.get_current_epoch_time() - 1000 * float(
217 output.split(" ")[0])
Betty Zhoud01485d2017-10-30 17:06:41 -0700218 ad.crash_report_preflight = ad.check_crash_report(
Betty Zhou92626a22017-12-12 20:07:12 -0800219 self.test_name,
220 begin_time=epoch_up_time,
221 log_crash_report=True)
Betty Zhou7f45f552017-03-15 19:12:52 -0700222 if ad.crash_report_preflight:
223 msg = "Find crash reports %s before test starts" % (
224 ad.crash_report_preflight)
225 ad.log.warn(msg)
Betty Zhou48a343e2017-08-31 17:39:13 -0700226 result = False
227 return result