blob: d43a0b9c0cce0bd8d8f093b7df9f4b5a021a9af9 [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
24import acts.test_utils.wifi.wifi_test_utils as wutils
25import acts.utils
26
27from acts import asserts
28from acts.test_decorators import test_tracker_info
29from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest
30
31WifiEnums = wutils.WifiEnums
32# Default timeout used for reboot, toggle WiFi and Airplane mode,
33# for the system to settle down after the operation.
34DEFAULT_TIMEOUT = 10
35WIFICOND_KILL_SHELL_COMMAND = "killall wificond"
Roshan Pius7a554fe2019-04-03 12:27:27 -070036WIFI_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 -080037SUPPLICANT_KILL_SHELL_COMMAND = "killall wpa_supplicant"
38
39class WifiCrashTest(WifiBaseTest):
40 """Crash Tests for wifi stack.
41
42 Test Bed Requirement:
43 * One Android device
44 * One Wi-Fi network visible to the device.
45 """
46
Roshan Piusbf7e3982018-02-15 12:37:41 -080047 def setup_class(self):
Xianyuan Jia168103b2019-09-06 12:22:52 -070048 super().setup_class()
49
Roshan Piusbf7e3982018-02-15 12:37:41 -080050 self.dut = self.android_devices[0]
51 wutils.wifi_test_device_init(self.dut)
52 req_params = []
53 opt_param = ["reference_networks"]
54 self.unpack_userparams(
55 req_param_names=req_params, opt_param_names=opt_param)
56
57 if "AccessPoint" in self.user_params:
58 self.legacy_configure_ap_and_start()
59
60 asserts.assert_true(
61 len(self.reference_networks) > 0,
62 "Need at least one reference network with psk.")
63 self.network = self.reference_networks[0]["2g"]
64
65 def setup_test(self):
66 self.dut.droid.wakeLockAcquireBright()
67 self.dut.droid.wakeUpNow()
68 wutils.wifi_toggle_state(self.dut, True)
69
70 def teardown_test(self):
71 self.dut.droid.wakeLockRelease()
72 self.dut.droid.goToSleepNow()
73 wutils.reset_wifi(self.dut)
74
75 def on_fail(self, test_name, begin_time):
76 self.dut.take_bug_report(test_name, begin_time)
77 self.dut.cat_adb_log(test_name, begin_time)
78
79 def teardown_class(self):
80 if "AccessPoint" in self.user_params:
81 del self.user_params["reference_networks"]
82
83 """Helper Functions"""
84
85 """Tests"""
Roshan Piusb5eed232018-05-09 16:18:40 -070086 @test_tracker_info(uuid="b87fd23f-9bfc-406b-a5b2-17ce6be6c780")
Roshan Piusbf7e3982018-02-15 12:37:41 -080087 def test_wifi_framework_crash_reconnect(self):
88 """Connect to a network, crash framework, then ensure
89 we connect back to the previously connected network.
90
91 Steps:
92 1. Connect to a network.
93 2. Restart framework.
94 3. Reconnect to the previous network.
95
96 """
97 wutils.wifi_connect(self.dut, self.network, num_of_tries=3)
98 # Restart framework
99 self.log.info("Crashing framework")
100 self.dut.restart_runtime()
101 # We won't get the disconnect broadcast because framework crashed.
102 # wutils.wait_for_disconnect(self.dut)
103 time.sleep(DEFAULT_TIMEOUT)
104 wifi_info = self.dut.droid.wifiGetConnectionInfo()
105 if wifi_info[WifiEnums.SSID_KEY] != self.network[WifiEnums.SSID_KEY]:
106 raise signals.TestFailure("Device did not connect to the"
107 " network after crashing framework.")
108
Roshan Piusb5eed232018-05-09 16:18:40 -0700109 @test_tracker_info(uuid="33f9e4f6-29b8-4116-8f9b-5b13d93b4bcb")
Roshan Piusbf7e3982018-02-15 12:37:41 -0800110 def test_wifi_cond_crash_reconnect(self):
111 """Connect to a network, crash wificond, then ensure
112 we connect back to the previously connected network.
113
114 Steps:
115 1. Connect to a network.
116 2. Crash wificond.
117 3. Ensure we get a disconnect.
118 4. Ensure we reconnect to the previous network.
119
120 """
121 wutils.wifi_connect(self.dut, self.network, num_of_tries=3)
122 # Restart wificond
123 self.log.info("Crashing wificond")
124 self.dut.adb.shell(WIFICOND_KILL_SHELL_COMMAND)
125 wutils.wait_for_disconnect(self.dut)
126 time.sleep(DEFAULT_TIMEOUT)
127 wifi_info = self.dut.droid.wifiGetConnectionInfo()
128 if wifi_info[WifiEnums.SSID_KEY] != self.network[WifiEnums.SSID_KEY]:
129 raise signals.TestFailure("Device did not connect to the"
130 " network after crashing wificond.")
131
Roshan Piusb5eed232018-05-09 16:18:40 -0700132 @test_tracker_info(uuid="463e3d7b-b0b7-4843-b83b-5613a71ae2ac")
Roshan Piusbf7e3982018-02-15 12:37:41 -0800133 def test_wifi_vendorhal_crash_reconnect(self):
134 """Connect to a network, crash wifi HAL, then ensure
135 we connect back to the previously connected network.
136
137 Steps:
138 1. Connect to a network.
139 2. Crash wifi HAL.
140 3. Ensure we get a disconnect.
141 4. Ensure we reconnect to the previous network.
142
143 """
144 wutils.wifi_connect(self.dut, self.network, num_of_tries=3)
145 # Restart wificond
146 self.log.info("Crashing wifi HAL")
147 self.dut.adb.shell(WIFI_VENDOR_HAL_KILL_SHELL_COMMAND)
148 wutils.wait_for_disconnect(self.dut)
149 time.sleep(DEFAULT_TIMEOUT)
150 wifi_info = self.dut.droid.wifiGetConnectionInfo()
151 if wifi_info[WifiEnums.SSID_KEY] != self.network[WifiEnums.SSID_KEY]:
152 raise signals.TestFailure("Device did not connect to the"
153 " network after crashing wifi HAL.")
154
Roshan Piusb5eed232018-05-09 16:18:40 -0700155 @test_tracker_info(uuid="7c5cd1fc-8f8d-494c-beaf-4eb61b48917b")
Roshan Piusbf7e3982018-02-15 12:37:41 -0800156 def test_wpa_supplicant_crash_reconnect(self):
157 """Connect to a network, crash wpa_supplicant, then ensure
158 we connect back to the previously connected network.
159
160 Steps:
161 1. Connect to a network.
162 2. Crash wpa_supplicant.
163 3. Ensure we get a disconnect.
164 4. Ensure we reconnect to the previous network.
165
166 """
167 wutils.wifi_connect(self.dut, self.network, num_of_tries=3)
168 # Restart wificond
169 self.log.info("Crashing wpa_supplicant")
170 self.dut.adb.shell(SUPPLICANT_KILL_SHELL_COMMAND)
171 wutils.wait_for_disconnect(self.dut)
172 time.sleep(DEFAULT_TIMEOUT)
173 wifi_info = self.dut.droid.wifiGetConnectionInfo()
174 if wifi_info[WifiEnums.SSID_KEY] != self.network[WifiEnums.SSID_KEY]:
175 raise signals.TestFailure("Device did not connect to the"
176 " network after crashing wpa_supplicant.")