blob: 903937eedb012686b424b7571a7d179a1bcf1ca4 [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
Betty Zhou92626a22017-12-12 20:07:12 -080024from acts import utils
Betty Zhoud01485d2017-10-30 17:06:41 -070025from acts.controllers.android_device import get_info
26from acts.libs.ota import ota_updater
Betty Zhou158c3332017-06-02 17:08:09 -070027from acts.test_decorators import test_tracker_info
Yang Liu52cc0202015-12-28 14:08:52 -080028from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
Ang Li73697b32015-12-03 00:41:53 +000029from acts.test_utils.tel.tel_defines import AOSP_PREFIX
30from acts.test_utils.tel.tel_defines import CAPABILITY_PHONE
31from acts.test_utils.tel.tel_defines import CAPABILITY_VOLTE
32from acts.test_utils.tel.tel_defines import CAPABILITY_VT
33from acts.test_utils.tel.tel_defines import CAPABILITY_WFC
34from acts.test_utils.tel.tel_defines import CAPABILITY_MSIM
35from acts.test_utils.tel.tel_defines import CAPABILITY_OMADM
Nathan Harold05a6c272016-10-17 13:55:53 -070036from acts.test_utils.tel.tel_defines import INVALID_SUB_ID
Yang Liudf164e32016-01-07 16:49:32 -080037from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_NW_SELECTION
Ang Li73697b32015-12-03 00:41:53 +000038from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND
39from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND
40from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING
41from acts.test_utils.tel.tel_defines import WAIT_TIME_AFTER_REBOOT
Ang Li73697b32015-12-03 00:41:53 +000042from acts.test_utils.tel.tel_lookup_tables import device_capabilities
43from acts.test_utils.tel.tel_lookup_tables import operator_capabilities
Betty Zhou5534e672017-03-07 13:47:10 -080044from acts.test_utils.tel.tel_test_utils import abort_all_tests
Yang Liu52cc0202015-12-28 14:08:52 -080045from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state
Betty Zhou7f45f552017-03-15 19:12:52 -070046from acts.test_utils.tel.tel_test_utils import ensure_phone_subscription
Yang Liud7727092016-05-24 14:38:36 -070047from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
Yang Liu52cc0202015-12-28 14:08:52 -080048from acts.test_utils.tel.tel_test_utils import get_operator_name
Betty Zhoue66efb42018-01-31 19:45:56 -080049from acts.test_utils.tel.tel_test_utils import is_sim_locked
Betty Zhoud01485d2017-10-30 17:06:41 -070050from acts.test_utils.tel.tel_test_utils import run_multithread_func
Yang Liu52cc0202015-12-28 14:08:52 -080051from acts.test_utils.tel.tel_test_utils import setup_droid_properties
52from acts.test_utils.tel.tel_test_utils import set_phone_screen_on
53from acts.test_utils.tel.tel_test_utils import set_phone_silent_mode
Betty Zhou5e7ac612017-10-10 11:54:45 -070054from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
Betty Zhoub9312fb2017-11-03 15:02:21 -070055from acts.test_utils.tel.tel_test_utils import unlock_sim
Yang Liud7727092016-05-24 14:38:36 -070056from acts.test_utils.tel.tel_test_utils import verify_http_connection
Yang Liu52cc0202015-12-28 14:08:52 -080057from acts.test_utils.tel.tel_test_utils import wait_for_voice_attach_for_subscription
Yang Liud7727092016-05-24 14:38:36 -070058from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
Betty Zhouf987b8f2017-03-09 16:34:00 -080059from acts.test_utils.tel.tel_test_utils import wifi_toggle_state
Yang Liu52cc0202015-12-28 14:08:52 -080060from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
Yang Liud7727092016-05-24 14:38:36 -070061from acts.asserts import abort_all
Betty Zhouec8378f2016-12-21 17:28:48 -080062from acts.asserts import fail
Ang Li73697b32015-12-03 00:41:53 +000063
Ang Li73697b32015-12-03 00:41:53 +000064
Nathan Harold0f76cf22015-12-30 16:33:25 -080065class TelLivePreflightTest(TelephonyBaseTest):
Ang Li73697b32015-12-03 00:41:53 +000066 def __init__(self, controllers):
67 TelephonyBaseTest.__init__(self, controllers)
Ang Li73697b32015-12-03 00:41:53 +000068
Betty Zhou061ae082016-12-01 15:26:24 -080069 self.wifi_network_ssid = self.user_params.get(
Betty Zhou5e7ac612017-10-10 11:54:45 -070070 "wifi_network_ssid") or self.user_params.get(
Betty Zhou550fd372017-10-16 17:22:47 -070071 "wifi_network_ssid_2g") or self.user_params.get(
72 "wifi_network_ssid_5g")
Betty Zhou061ae082016-12-01 15:26:24 -080073 self.wifi_network_pass = self.user_params.get(
Betty Zhou5e7ac612017-10-10 11:54:45 -070074 "wifi_network_pass") or self.user_params.get(
Betty Zhou550fd372017-10-16 17:22:47 -070075 "wifi_network_pass_2g") or self.user_params.get(
76 "wifi_network_ssid_5g")
Yang Liud7727092016-05-24 14:38:36 -070077
Ang Li73697b32015-12-03 00:41:53 +000078 """ Tests Begin """
Nathan Haroldb1487af2016-07-19 16:05:37 -070079
Betty Zhoud01485d2017-10-30 17:06:41 -070080 @test_tracker_info(uuid="cb897221-99e1-4697-927e-02d92d969440")
81 @TelephonyBaseTest.tel_test_wrap
82 def test_ota_upgrade(self):
83 ota_package = self.user_params.get("ota_package")
84 if isinstance(ota_package, list):
85 ota_package = ota_package[0]
86 if ota_package and "dev/null" not in ota_package:
87 self.log.info("Upgrade with ota_package %s", ota_package)
88 self.log.info("Before OTA upgrade: %s",
89 get_info(self.android_devices))
90 else:
91 raise signals.TestSkip("No ota_package is defined")
Betty Zhou4a516de2017-10-31 17:18:55 -070092 ota_util = self.user_params.get("ota_util")
93 if isinstance(ota_util, list):
94 ota_util = ota_util[0]
95 if ota_util:
96 if "update_engine_client.zip" in ota_util:
97 self.user_params["UpdateDeviceOtaTool"] = ota_util
98 self.user_params["ota_tool"] = "UpdateDeviceOtaTool"
99 else:
100 self.user_params["AdbSideloadOtaTool"] = ota_util
101 self.user_params["ota_tool"] = "AdbSideloadOtaTool"
102 self.log.info("OTA upgrade with %s by %s", ota_package,
103 self.user_params["ota_tool"])
Betty Zhoud01485d2017-10-30 17:06:41 -0700104 ota_updater.initialize(self.user_params, self.android_devices)
105 tasks = [(ota_updater.update, [ad]) for ad in self.android_devices]
106 try:
107 run_multithread_func(self.log, tasks)
108 except Exception as err:
Betty Zhoud38a47e2017-11-29 16:48:58 -0800109 abort_all_tests(self.log, "Unable to do ota upgrade: %s" % err)
Betty Zhoud01485d2017-10-30 17:06:41 -0700110 device_info = get_info(self.android_devices)
111 self.log.info("After OTA upgrade: %s", device_info)
112 self.results.add_controller_info("AndroidDevice", device_info)
Betty Zhoub9312fb2017-11-03 15:02:21 -0700113 for ad in self.android_devices:
Betty Zhoue66efb42018-01-31 19:45:56 -0800114 if is_sim_locked(ad):
115 ad.log.info("After OTA, SIM keeps the locked state")
116 elif getattr(ad, "is_sim_locked", False):
117 ad.log.error("After OTA, SIM loses the locked state")
Betty Zhoub9312fb2017-11-03 15:02:21 -0700118 if not unlock_sim(ad):
119 abort_all_tests(ad.log, "unable to unlock SIM")
Betty Zhoud01485d2017-10-30 17:06:41 -0700120 return True
121
Betty Zhou158c3332017-06-02 17:08:09 -0700122 @test_tracker_info(uuid="8390a2eb-a744-4cda-bade-f94a2cc83f02")
Yang Liud7727092016-05-24 14:38:36 -0700123 @TelephonyBaseTest.tel_test_wrap
124 def test_check_environment(self):
125 ad = self.android_devices[0]
126 # Check WiFi environment.
127 # 1. Connect to WiFi.
128 # 2. Check WiFi have Internet access.
Betty Zhou061ae082016-12-01 15:26:24 -0800129 toggle_airplane_mode(self.log, ad, False, strict_checking=False)
Yang Liud7727092016-05-24 14:38:36 -0700130 try:
131 if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
132 self.wifi_network_pass):
Betty Zhou5534e672017-03-07 13:47:10 -0800133 abort_all_tests(ad.log, "WiFi connect fail")
Betty Zhou3b2de072018-03-15 16:46:26 -0700134 if (not wait_for_wifi_data_connection(self.log, ad, True)
135 or not verify_http_connection(self.log, ad)):
Betty Zhou5534e672017-03-07 13:47:10 -0800136 abort_all_tests(ad.log, "Data not available on WiFi")
Yang Liud7727092016-05-24 14:38:36 -0700137 finally:
Betty Zhouf987b8f2017-03-09 16:34:00 -0800138 wifi_toggle_state(self.log, ad, False)
Yang Liud7727092016-05-24 14:38:36 -0700139 # TODO: add more environment check here.
140 return True
Nathan Harold0f76cf22015-12-30 16:33:25 -0800141
Betty Zhou158c3332017-06-02 17:08:09 -0700142 @test_tracker_info(uuid="7bb23ac7-6b7b-4d5e-b8d6-9dd10032b9ad")
Ang Li73697b32015-12-03 00:41:53 +0000143 @TelephonyBaseTest.tel_test_wrap
144 def test_pre_flight_check(self):
Nathan Haroldb1487af2016-07-19 16:05:37 -0700145 for ad in self.android_devices:
Ang Li73697b32015-12-03 00:41:53 +0000146 #check for sim and service
Betty Zhou7f45f552017-03-15 19:12:52 -0700147 if not ensure_phone_subscription(self.log, ad):
148 abort_all_tests(ad.log, "Unable to find a valid subscription!")
Ang Li73697b32015-12-03 00:41:53 +0000149 return True
Nathan Harold0f76cf22015-12-30 16:33:25 -0800150
Betty Zhou158c3332017-06-02 17:08:09 -0700151 @test_tracker_info(uuid="1070b160-902b-43bf-92a0-92cc2d05bb13")
Betty Zhouec8378f2016-12-21 17:28:48 -0800152 @TelephonyBaseTest.tel_test_wrap
153 def test_check_crash(self):
Betty Zhou48a343e2017-08-31 17:39:13 -0700154 result = True
Jaineel30bc3352017-10-18 17:10:01 -0700155 begin_time = None
Betty Zhouec8378f2016-12-21 17:28:48 -0800156 for ad in self.android_devices:
Betty Zhou92626a22017-12-12 20:07:12 -0800157 output = ad.adb.shell("cat /proc/uptime")
158 epoch_up_time = utils.get_current_epoch_time() - 1000 * float(
159 output.split(" ")[0])
Betty Zhoud01485d2017-10-30 17:06:41 -0700160 ad.crash_report_preflight = ad.check_crash_report(
Betty Zhou92626a22017-12-12 20:07:12 -0800161 self.test_name,
162 begin_time=epoch_up_time,
163 log_crash_report=True)
Betty Zhou7f45f552017-03-15 19:12:52 -0700164 if ad.crash_report_preflight:
165 msg = "Find crash reports %s before test starts" % (
166 ad.crash_report_preflight)
167 ad.log.warn(msg)
Betty Zhou48a343e2017-08-31 17:39:13 -0700168 result = False
169 return result