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 |
Xianyuan Jia | a4913cd | 2020-11-16 11:58:29 -0800 | [diff] [blame] | 24 | import acts.test_utils.wifi.wifi_test_utils as wutils |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 25 | import acts.utils |
| 26 | |
| 27 | from acts import asserts |
| 28 | from acts.test_decorators import test_tracker_info |
Xianyuan Jia | a4913cd | 2020-11-16 11:58:29 -0800 | [diff] [blame] | 29 | from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 30 | |
| 31 | WifiEnums = wutils.WifiEnums |
Roshan Pius | db259d4 | 2020-04-30 10:02:50 -0700 | [diff] [blame] | 32 | # Timeout used for crash recovery. |
| 33 | RECOVERY_TIMEOUT = 15 |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 34 | WIFICOND_KILL_SHELL_COMMAND = "killall wificond" |
Roshan Pius | 7a554fe | 2019-04-03 12:27:27 -0700 | [diff] [blame] | 35 | 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] | 36 | SUPPLICANT_KILL_SHELL_COMMAND = "killall wpa_supplicant" |
| 37 | |
| 38 | class 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 Jia | 97a865e | 2020-11-10 02:09:40 +0000 | [diff] [blame] | 45 | def __init__(self, configs): |
| 46 | super().__init__(configs) |
| 47 | self.enable_packet_log = True |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 48 | |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 49 | def setup_class(self): |
Xianyuan Jia | 168103b | 2019-09-06 12:22:52 -0700 | [diff] [blame] | 50 | super().setup_class() |
| 51 | |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 52 | 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 Jia | 97a865e | 2020-11-10 02:09:40 +0000 | [diff] [blame] | 61 | elif "OpenWrtAP" in self.user_params: |
| 62 | self.configure_openwrt_ap_and_start(wpa_network=True) |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 63 | |
| 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 Jia | 97a865e | 2020-11-10 02:09:40 +0000 | [diff] [blame] | 70 | super().setup_test() |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 71 | self.dut.droid.wakeLockAcquireBright() |
| 72 | self.dut.droid.wakeUpNow() |
| 73 | wutils.wifi_toggle_state(self.dut, True) |
| 74 | |
| 75 | def teardown_test(self): |
Xianyuan Jia | 97a865e | 2020-11-10 02:09:40 +0000 | [diff] [blame] | 76 | super().teardown_test() |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 77 | self.dut.droid.wakeLockRelease() |
| 78 | self.dut.droid.goToSleepNow() |
| 79 | wutils.reset_wifi(self.dut) |
| 80 | |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 81 | 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 Pius | b5eed23 | 2018-05-09 16:18:40 -0700 | [diff] [blame] | 88 | @test_tracker_info(uuid="b87fd23f-9bfc-406b-a5b2-17ce6be6c780") |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 89 | 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 Pius | db259d4 | 2020-04-30 10:02:50 -0700 | [diff] [blame] | 105 | time.sleep(RECOVERY_TIMEOUT) |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 106 | 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 Pius | b5eed23 | 2018-05-09 16:18:40 -0700 | [diff] [blame] | 111 | @test_tracker_info(uuid="33f9e4f6-29b8-4116-8f9b-5b13d93b4bcb") |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 112 | 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 Pius | db259d4 | 2020-04-30 10:02:50 -0700 | [diff] [blame] | 128 | time.sleep(RECOVERY_TIMEOUT) |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 129 | 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 Pius | b5eed23 | 2018-05-09 16:18:40 -0700 | [diff] [blame] | 134 | @test_tracker_info(uuid="463e3d7b-b0b7-4843-b83b-5613a71ae2ac") |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 135 | 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 Pius | db259d4 | 2020-04-30 10:02:50 -0700 | [diff] [blame] | 151 | time.sleep(RECOVERY_TIMEOUT) |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 152 | 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 Pius | b5eed23 | 2018-05-09 16:18:40 -0700 | [diff] [blame] | 157 | @test_tracker_info(uuid="7c5cd1fc-8f8d-494c-beaf-4eb61b48917b") |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 158 | 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 Pius | db259d4 | 2020-04-30 10:02:50 -0700 | [diff] [blame] | 174 | time.sleep(RECOVERY_TIMEOUT) |
Roshan Pius | bf7e398 | 2018-02-15 12:37:41 -0800 | [diff] [blame] | 175 | 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.") |