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