blob: a99cee7065c727b02ecf9449105942bc3b256654 [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
20import time
Ang Li73697b32015-12-03 00:41:53 +000021from queue import Empty
Betty Zhou158c3332017-06-02 17:08:09 -070022
Betty Zhoud01485d2017-10-30 17:06:41 -070023from acts import signals
24from acts.controllers.android_device import get_info
25from acts.libs.ota import ota_updater
Betty Zhou158c3332017-06-02 17:08:09 -070026from acts.test_decorators import test_tracker_info
Yang Liu52cc0202015-12-28 14:08:52 -080027from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
Ang Li73697b32015-12-03 00:41:53 +000028from acts.test_utils.tel.tel_defines import AOSP_PREFIX
29from acts.test_utils.tel.tel_defines import CAPABILITY_PHONE
30from acts.test_utils.tel.tel_defines import CAPABILITY_VOLTE
31from acts.test_utils.tel.tel_defines import CAPABILITY_VT
32from acts.test_utils.tel.tel_defines import CAPABILITY_WFC
33from acts.test_utils.tel.tel_defines import CAPABILITY_MSIM
34from acts.test_utils.tel.tel_defines import CAPABILITY_OMADM
Nathan Harold05a6c272016-10-17 13:55:53 -070035from acts.test_utils.tel.tel_defines import INVALID_SUB_ID
Yang Liudf164e32016-01-07 16:49:32 -080036from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_NW_SELECTION
Ang Li73697b32015-12-03 00:41:53 +000037from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND
38from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND
39from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING
40from acts.test_utils.tel.tel_defines import WAIT_TIME_AFTER_REBOOT
Ang Li73697b32015-12-03 00:41:53 +000041from acts.test_utils.tel.tel_lookup_tables import device_capabilities
42from acts.test_utils.tel.tel_lookup_tables import operator_capabilities
Betty Zhou5534e672017-03-07 13:47:10 -080043from acts.test_utils.tel.tel_test_utils import abort_all_tests
Yang Liu52cc0202015-12-28 14:08:52 -080044from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state
Betty Zhou7f45f552017-03-15 19:12:52 -070045from acts.test_utils.tel.tel_test_utils import ensure_phone_subscription
Yang Liud7727092016-05-24 14:38:36 -070046from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
Yang Liu52cc0202015-12-28 14:08:52 -080047from acts.test_utils.tel.tel_test_utils import get_operator_name
Betty Zhoud01485d2017-10-30 17:06:41 -070048from acts.test_utils.tel.tel_test_utils import run_multithread_func
Yang Liu52cc0202015-12-28 14:08:52 -080049from acts.test_utils.tel.tel_test_utils import setup_droid_properties
50from acts.test_utils.tel.tel_test_utils import set_phone_screen_on
51from acts.test_utils.tel.tel_test_utils import set_phone_silent_mode
Betty Zhou5e7ac612017-10-10 11:54:45 -070052from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
Betty Zhoub9312fb2017-11-03 15:02:21 -070053from acts.test_utils.tel.tel_test_utils import unlock_sim
Yang Liud7727092016-05-24 14:38:36 -070054from acts.test_utils.tel.tel_test_utils import verify_http_connection
Yang Liu52cc0202015-12-28 14:08:52 -080055from acts.test_utils.tel.tel_test_utils import wait_for_voice_attach_for_subscription
Yang Liud7727092016-05-24 14:38:36 -070056from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
Betty Zhouf987b8f2017-03-09 16:34:00 -080057from acts.test_utils.tel.tel_test_utils import wifi_toggle_state
Yang Liu52cc0202015-12-28 14:08:52 -080058from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
Yang Liud7727092016-05-24 14:38:36 -070059from acts.asserts import abort_all
Betty Zhouec8378f2016-12-21 17:28:48 -080060from acts.asserts import fail
Ang Li73697b32015-12-03 00:41:53 +000061
Ang Li73697b32015-12-03 00:41:53 +000062
Nathan Harold0f76cf22015-12-30 16:33:25 -080063class TelLivePreflightTest(TelephonyBaseTest):
Ang Li73697b32015-12-03 00:41:53 +000064 def __init__(self, controllers):
65 TelephonyBaseTest.__init__(self, controllers)
Ang Li73697b32015-12-03 00:41:53 +000066
Betty Zhou061ae082016-12-01 15:26:24 -080067 self.wifi_network_ssid = self.user_params.get(
Betty Zhou5e7ac612017-10-10 11:54:45 -070068 "wifi_network_ssid") or self.user_params.get(
Betty Zhou550fd372017-10-16 17:22:47 -070069 "wifi_network_ssid_2g") or self.user_params.get(
70 "wifi_network_ssid_5g")
Betty Zhou061ae082016-12-01 15:26:24 -080071 self.wifi_network_pass = self.user_params.get(
Betty Zhou5e7ac612017-10-10 11:54:45 -070072 "wifi_network_pass") or self.user_params.get(
Betty Zhou550fd372017-10-16 17:22:47 -070073 "wifi_network_pass_2g") or self.user_params.get(
74 "wifi_network_ssid_5g")
Yang Liud7727092016-05-24 14:38:36 -070075
Betty Zhou31d1ca32017-07-21 16:48:09 -070076 def setup_class(self):
Betty Zhou5e7ac612017-10-10 11:54:45 -070077 for ad in self.android_devices:
78 toggle_airplane_mode_by_adb(self.log, ad, False)
79
80 def teardown_class(self):
81 pass
Betty Zhou31d1ca32017-07-21 16:48:09 -070082
83 def setup_test(self):
84 pass
85
Ang Li73697b32015-12-03 00:41:53 +000086 """ Tests Begin """
Nathan Haroldb1487af2016-07-19 16:05:37 -070087
Betty Zhoud01485d2017-10-30 17:06:41 -070088 @test_tracker_info(uuid="cb897221-99e1-4697-927e-02d92d969440")
89 @TelephonyBaseTest.tel_test_wrap
90 def test_ota_upgrade(self):
91 ota_package = self.user_params.get("ota_package")
92 if isinstance(ota_package, list):
93 ota_package = ota_package[0]
94 if ota_package and "dev/null" not in ota_package:
95 self.log.info("Upgrade with ota_package %s", ota_package)
96 self.log.info("Before OTA upgrade: %s",
97 get_info(self.android_devices))
98 else:
99 raise signals.TestSkip("No ota_package is defined")
Betty Zhou4a516de2017-10-31 17:18:55 -0700100 ota_util = self.user_params.get("ota_util")
101 if isinstance(ota_util, list):
102 ota_util = ota_util[0]
103 if ota_util:
104 if "update_engine_client.zip" in ota_util:
105 self.user_params["UpdateDeviceOtaTool"] = ota_util
106 self.user_params["ota_tool"] = "UpdateDeviceOtaTool"
107 else:
108 self.user_params["AdbSideloadOtaTool"] = ota_util
109 self.user_params["ota_tool"] = "AdbSideloadOtaTool"
110 self.log.info("OTA upgrade with %s by %s", ota_package,
111 self.user_params["ota_tool"])
Betty Zhoud01485d2017-10-30 17:06:41 -0700112 ota_updater.initialize(self.user_params, self.android_devices)
113 tasks = [(ota_updater.update, [ad]) for ad in self.android_devices]
114 try:
115 run_multithread_func(self.log, tasks)
116 except Exception as err:
Betty Zhoud38a47e2017-11-29 16:48:58 -0800117 abort_all_tests(self.log, "Unable to do ota upgrade: %s" % err)
Betty Zhoud01485d2017-10-30 17:06:41 -0700118 device_info = get_info(self.android_devices)
119 self.log.info("After OTA upgrade: %s", device_info)
120 self.results.add_controller_info("AndroidDevice", device_info)
Betty Zhoub9312fb2017-11-03 15:02:21 -0700121 for ad in self.android_devices:
122 if not unlock_sim(ad):
123 abort_all_tests(ad.log, "unable to unlock SIM")
Betty Zhoud01485d2017-10-30 17:06:41 -0700124 return True
125
Betty Zhou158c3332017-06-02 17:08:09 -0700126 @test_tracker_info(uuid="8390a2eb-a744-4cda-bade-f94a2cc83f02")
Yang Liud7727092016-05-24 14:38:36 -0700127 @TelephonyBaseTest.tel_test_wrap
128 def test_check_environment(self):
129 ad = self.android_devices[0]
130 # Check WiFi environment.
131 # 1. Connect to WiFi.
132 # 2. Check WiFi have Internet access.
Betty Zhou061ae082016-12-01 15:26:24 -0800133 toggle_airplane_mode(self.log, ad, False, strict_checking=False)
Yang Liud7727092016-05-24 14:38:36 -0700134 try:
135 if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
136 self.wifi_network_pass):
Betty Zhou5534e672017-03-07 13:47:10 -0800137 abort_all_tests(ad.log, "WiFi connect fail")
Yang Liud7727092016-05-24 14:38:36 -0700138 if (not wait_for_wifi_data_connection(self.log, ad, True) or
139 not verify_http_connection(self.log, ad)):
Betty Zhou5534e672017-03-07 13:47:10 -0800140 abort_all_tests(ad.log, "Data not available on WiFi")
Yang Liud7727092016-05-24 14:38:36 -0700141 finally:
Betty Zhouf987b8f2017-03-09 16:34:00 -0800142 wifi_toggle_state(self.log, ad, False)
Yang Liud7727092016-05-24 14:38:36 -0700143 # TODO: add more environment check here.
144 return True
Nathan Harold0f76cf22015-12-30 16:33:25 -0800145
Betty Zhou158c3332017-06-02 17:08:09 -0700146 @test_tracker_info(uuid="7bb23ac7-6b7b-4d5e-b8d6-9dd10032b9ad")
Ang Li73697b32015-12-03 00:41:53 +0000147 @TelephonyBaseTest.tel_test_wrap
148 def test_pre_flight_check(self):
Nathan Haroldb1487af2016-07-19 16:05:37 -0700149 for ad in self.android_devices:
Ang Li73697b32015-12-03 00:41:53 +0000150 #check for sim and service
Betty Zhou7f45f552017-03-15 19:12:52 -0700151 if not ensure_phone_subscription(self.log, ad):
152 abort_all_tests(ad.log, "Unable to find a valid subscription!")
Ang Li73697b32015-12-03 00:41:53 +0000153 return True
Nathan Harold0f76cf22015-12-30 16:33:25 -0800154
Betty Zhou158c3332017-06-02 17:08:09 -0700155 @test_tracker_info(uuid="1070b160-902b-43bf-92a0-92cc2d05bb13")
Betty Zhouec8378f2016-12-21 17:28:48 -0800156 @TelephonyBaseTest.tel_test_wrap
157 def test_check_crash(self):
Betty Zhou48a343e2017-08-31 17:39:13 -0700158 result = True
Jaineel30bc3352017-10-18 17:10:01 -0700159 begin_time = None
Betty Zhouec8378f2016-12-21 17:28:48 -0800160 for ad in self.android_devices:
Jaineel30bc3352017-10-18 17:10:01 -0700161 output = ad.search_logcat(
162 "processing action (sys.boot_completed=1)")
163 if output:
164 begin_time = output[-1]["time_stamp"][5:]
165 ad.log.debug("begin time is %s", begin_time)
Betty Zhoud01485d2017-10-30 17:06:41 -0700166 ad.crash_report_preflight = ad.check_crash_report(
167 self.test_name, begin_time, True)
Betty Zhou7f45f552017-03-15 19:12:52 -0700168 if ad.crash_report_preflight:
169 msg = "Find crash reports %s before test starts" % (
170 ad.crash_report_preflight)
171 ad.log.warn(msg)
Betty Zhou48a343e2017-08-31 17:39:13 -0700172 result = False
173 return result