blob: f6767bc90c0a4ad8edd9cdfe41d1a07b92f65e50 [file] [log] [blame]
Roshan Piusbf7e3982018-02-15 12:37:41 -08001#!/usr/bin/env python3.4
2#
3# Copyright 2018 - The Android Open Source Project
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
17import itertools
18import pprint
19import queue
20import time
21
22import acts.base_test
23import acts.signals as signals
Xianyuan Jia63751fb2020-11-17 00:07:40 +000024import acts_contrib.test_utils.wifi.wifi_test_utils as wutils
Roshan Piusbf7e3982018-02-15 12:37:41 -080025import acts.utils
26
27from acts import asserts
28from acts.test_decorators import test_tracker_info
Xianyuan Jia63751fb2020-11-17 00:07:40 +000029from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
Roshan Piusbf7e3982018-02-15 12:37:41 -080030
31WifiEnums = wutils.WifiEnums
Roshan Piusdb259d42020-04-30 10:02:50 -070032# Timeout used for crash recovery.
33RECOVERY_TIMEOUT = 15
Roshan Piusbf7e3982018-02-15 12:37:41 -080034WIFICOND_KILL_SHELL_COMMAND = "killall wificond"
Roshan Pius7a554fe2019-04-03 12:27:27 -070035WIFI_VENDOR_HAL_KILL_SHELL_COMMAND = "killall android.hardware.wifi@1.0-service vendor.google.wifi_ext@1.0-service-vendor"
Roshan Piusbf7e3982018-02-15 12:37:41 -080036SUPPLICANT_KILL_SHELL_COMMAND = "killall wpa_supplicant"
37
38class WifiCrashTest(WifiBaseTest):
39 """Crash Tests for wifi stack.
40
41 Test Bed Requirement:
42 * One Android device
43 * One Wi-Fi network visible to the device.
44 """
Xianyuan Jia97a865e2020-11-10 02:09:40 +000045 def __init__(self, configs):
46 super().__init__(configs)
47 self.enable_packet_log = True
Roshan Piusbf7e3982018-02-15 12:37:41 -080048
Roshan Piusbf7e3982018-02-15 12:37:41 -080049 def setup_class(self):
Xianyuan Jia168103b2019-09-06 12:22:52 -070050 super().setup_class()
51
Roshan Piusbf7e3982018-02-15 12:37:41 -080052 self.dut = self.android_devices[0]
53 wutils.wifi_test_device_init(self.dut)
54 req_params = []
55 opt_param = ["reference_networks"]
56 self.unpack_userparams(
57 req_param_names=req_params, opt_param_names=opt_param)
58
59 if "AccessPoint" in self.user_params:
60 self.legacy_configure_ap_and_start()
Xianyuan Jia97a865e2020-11-10 02:09:40 +000061 elif "OpenWrtAP" in self.user_params:
62 self.configure_openwrt_ap_and_start(wpa_network=True)
Roshan Piusbf7e3982018-02-15 12:37:41 -080063
64 asserts.assert_true(
65 len(self.reference_networks) > 0,
66 "Need at least one reference network with psk.")
67 self.network = self.reference_networks[0]["2g"]
68
69 def setup_test(self):
Xianyuan Jia97a865e2020-11-10 02:09:40 +000070 super().setup_test()
Roshan Piusbf7e3982018-02-15 12:37:41 -080071 self.dut.droid.wakeLockAcquireBright()
72 self.dut.droid.wakeUpNow()
73 wutils.wifi_toggle_state(self.dut, True)
74
75 def teardown_test(self):
Xianyuan Jia97a865e2020-11-10 02:09:40 +000076 super().teardown_test()
Roshan Piusbf7e3982018-02-15 12:37:41 -080077 self.dut.droid.wakeLockRelease()
78 self.dut.droid.goToSleepNow()
79 wutils.reset_wifi(self.dut)
80
Roshan Piusbf7e3982018-02-15 12:37:41 -080081 def teardown_class(self):
82 if "AccessPoint" in self.user_params:
83 del self.user_params["reference_networks"]
84
85 """Helper Functions"""
86
87 """Tests"""
Roshan Piusb5eed232018-05-09 16:18:40 -070088 @test_tracker_info(uuid="b87fd23f-9bfc-406b-a5b2-17ce6be6c780")
Roshan Piusbf7e3982018-02-15 12:37:41 -080089 def test_wifi_framework_crash_reconnect(self):
90 """Connect to a network, crash framework, then ensure
91 we connect back to the previously connected network.
92
93 Steps:
94 1. Connect to a network.
95 2. Restart framework.
96 3. Reconnect to the previous network.
97
98 """
99 wutils.wifi_connect(self.dut, self.network, num_of_tries=3)
100 # Restart framework
101 self.log.info("Crashing framework")
102 self.dut.restart_runtime()
103 # We won't get the disconnect broadcast because framework crashed.
104 # wutils.wait_for_disconnect(self.dut)
Roshan Piusdb259d42020-04-30 10:02:50 -0700105 time.sleep(RECOVERY_TIMEOUT)
Roshan Piusbf7e3982018-02-15 12:37:41 -0800106 wifi_info = self.dut.droid.wifiGetConnectionInfo()
107 if wifi_info[WifiEnums.SSID_KEY] != self.network[WifiEnums.SSID_KEY]:
108 raise signals.TestFailure("Device did not connect to the"
109 " network after crashing framework.")
110
Roshan Piusb5eed232018-05-09 16:18:40 -0700111 @test_tracker_info(uuid="33f9e4f6-29b8-4116-8f9b-5b13d93b4bcb")
Roshan Piusbf7e3982018-02-15 12:37:41 -0800112 def test_wifi_cond_crash_reconnect(self):
113 """Connect to a network, crash wificond, then ensure
114 we connect back to the previously connected network.
115
116 Steps:
117 1. Connect to a network.
118 2. Crash wificond.
119 3. Ensure we get a disconnect.
120 4. Ensure we reconnect to the previous network.
121
122 """
123 wutils.wifi_connect(self.dut, self.network, num_of_tries=3)
124 # Restart wificond
125 self.log.info("Crashing wificond")
126 self.dut.adb.shell(WIFICOND_KILL_SHELL_COMMAND)
127 wutils.wait_for_disconnect(self.dut)
Roshan Piusdb259d42020-04-30 10:02:50 -0700128 time.sleep(RECOVERY_TIMEOUT)
Roshan Piusbf7e3982018-02-15 12:37:41 -0800129 wifi_info = self.dut.droid.wifiGetConnectionInfo()
130 if wifi_info[WifiEnums.SSID_KEY] != self.network[WifiEnums.SSID_KEY]:
131 raise signals.TestFailure("Device did not connect to the"
132 " network after crashing wificond.")
133
Roshan Piusb5eed232018-05-09 16:18:40 -0700134 @test_tracker_info(uuid="463e3d7b-b0b7-4843-b83b-5613a71ae2ac")
Roshan Piusbf7e3982018-02-15 12:37:41 -0800135 def test_wifi_vendorhal_crash_reconnect(self):
136 """Connect to a network, crash wifi HAL, then ensure
137 we connect back to the previously connected network.
138
139 Steps:
140 1. Connect to a network.
141 2. Crash wifi HAL.
142 3. Ensure we get a disconnect.
143 4. Ensure we reconnect to the previous network.
144
145 """
146 wutils.wifi_connect(self.dut, self.network, num_of_tries=3)
147 # Restart wificond
148 self.log.info("Crashing wifi HAL")
149 self.dut.adb.shell(WIFI_VENDOR_HAL_KILL_SHELL_COMMAND)
150 wutils.wait_for_disconnect(self.dut)
Roshan Piusdb259d42020-04-30 10:02:50 -0700151 time.sleep(RECOVERY_TIMEOUT)
Roshan Piusbf7e3982018-02-15 12:37:41 -0800152 wifi_info = self.dut.droid.wifiGetConnectionInfo()
153 if wifi_info[WifiEnums.SSID_KEY] != self.network[WifiEnums.SSID_KEY]:
154 raise signals.TestFailure("Device did not connect to the"
155 " network after crashing wifi HAL.")
156
Roshan Piusb5eed232018-05-09 16:18:40 -0700157 @test_tracker_info(uuid="7c5cd1fc-8f8d-494c-beaf-4eb61b48917b")
Roshan Piusbf7e3982018-02-15 12:37:41 -0800158 def test_wpa_supplicant_crash_reconnect(self):
159 """Connect to a network, crash wpa_supplicant, then ensure
160 we connect back to the previously connected network.
161
162 Steps:
163 1. Connect to a network.
164 2. Crash wpa_supplicant.
165 3. Ensure we get a disconnect.
166 4. Ensure we reconnect to the previous network.
167
168 """
169 wutils.wifi_connect(self.dut, self.network, num_of_tries=3)
170 # Restart wificond
171 self.log.info("Crashing wpa_supplicant")
172 self.dut.adb.shell(SUPPLICANT_KILL_SHELL_COMMAND)
173 wutils.wait_for_disconnect(self.dut)
Roshan Piusdb259d42020-04-30 10:02:50 -0700174 time.sleep(RECOVERY_TIMEOUT)
Roshan Piusbf7e3982018-02-15 12:37:41 -0800175 wifi_info = self.dut.droid.wifiGetConnectionInfo()
176 if wifi_info[WifiEnums.SSID_KEY] != self.network[WifiEnums.SSID_KEY]:
177 raise signals.TestFailure("Device did not connect to the"
178 " network after crashing wpa_supplicant.")