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 17import time 18import acts.signals as signals 19import acts_contrib.test_utils.wifi.wifi_test_utils as wutils 20from acts import asserts 21from acts import utils 22from acts.test_decorators import test_tracker_info 23from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest 24from acts_contrib.test_utils.tel.tel_logging_utils import disable_qxdm_logger 25 26WifiEnums = wutils.WifiEnums 27 28class WifiCrashStressTest(WifiBaseTest): 29 """Crash Tests for wifi stack. 30 31 Test Bed Requirement: 32 * Two Android device 33 * One Wi-Fi network visible to the device. 34 """ 35 36 def __init__(self, configs): 37 super().__init__(configs) 38 self.enable_packet_log = True 39 40 def setup_class(self): 41 super().setup_class() 42 43 self.dut = self.android_devices[0] 44 self.dut_client = self.android_devices[1] 45 wutils.wifi_test_device_init(self.dut) 46 wutils.wifi_test_device_init(self.dut_client) 47 req_params = ["sta_sta_supported_models", "dbs_supported_models", "stress_count"] 48 opt_param = ["reference_networks"] 49 self.unpack_userparams( 50 req_param_names=req_params, opt_param_names=opt_param) 51 52 if "AccessPoint" in self.user_params: 53 self.legacy_configure_ap_and_start() 54 elif "OpenWrtAP" in self.user_params: 55 self.configure_openwrt_ap_and_start(wpa_network=True) 56 57 asserts.assert_true( 58 len(self.reference_networks) > 0, 59 "Need at least one reference network with psk.") 60 self.network = self.reference_networks[0]["2g"] 61 self.ap_iface = 'wlan0' 62 if self.dut.model in self.dbs_supported_models: 63 self.ap_iface = 'wlan1' 64 if self.dut.model in self.sta_sta_supported_models: 65 self.ap_iface = 'wlan2' 66 67 def setup_test(self): 68 super().setup_test() 69 self.dut.droid.wakeLockAcquireBright() 70 self.dut.droid.wakeUpNow() 71 wutils.wifi_toggle_state(self.dut, True) 72 self.dut_client.droid.wakeLockAcquireBright() 73 self.dut_client.droid.wakeUpNow() 74 wutils.wifi_toggle_state(self.dut_client, True) 75 76 def teardown_test(self): 77 super().teardown_test() 78 if self.dut.droid.wifiIsApEnabled(): 79 wutils.stop_wifi_tethering(self.dut) 80 self.dut.droid.wakeLockRelease() 81 self.dut.droid.goToSleepNow() 82 wutils.reset_wifi(self.dut) 83 self.dut_client.droid.wakeLockRelease() 84 self.dut_client.droid.goToSleepNow() 85 wutils.reset_wifi(self.dut_client) 86 87 def teardown_class(self): 88 if "AccessPoint" in self.user_params: 89 del self.user_params["reference_networks"] 90 91 """Helper Functions""" 92 def trigger_wifi_firmware_crash(self, ad, timeout=15): 93 pre_timestamp = ad.adb.getprop("vendor.debug.ssrdump.timestamp") 94 disable_qxdm_logger(ad) 95 cmd = ('wlanSSR') 96 ad.log.info("Crash wifi firmware by %s", cmd) 97 ad.adb.shell(cmd, ignore_status=True) 98 time.sleep(timeout) # sleep time for firmware restart 99 subsystem = ad.adb.getprop("vendor.debug.ssrdump.subsys") 100 timestamp = ad.adb.getprop("vendor.debug.ssrdump.timestamp") 101 asserts.assert_true(timestamp != pre_timestamp, 102 "SSR didn't happened %s %s" % (subsystem, timestamp)) 103 104 """Tests""" 105 @test_tracker_info(uuid="b5a982ef-10ef-4f36-a1b5-1e5d1fec06a4") 106 def test_firmware_crash_wifi_reconnect_stress(self): 107 """Firmware crash stress test for station mode 108 109 1. Turn on Wi-Fi and connect to access point 110 2. Trigger firmware crash 111 3. Check ssr happened 112 4. Check dut can connect to access point 113 5. Repeat step 2~4 114 """ 115 wutils.wifi_toggle_state(self.dut, True) 116 wutils.connect_to_wifi_network(self.dut, self.network) 117 for count in range(self.stress_count): 118 self.log.info("%s: %d/%d" % 119 (self.current_test_name, count + 1, self.stress_count)) 120 wutils.reset_wifi(self.dut) 121 self.trigger_wifi_firmware_crash(self.dut) 122 wutils.connect_to_wifi_network(self.dut, self.network) 123 124 @test_tracker_info(uuid="204a921b-b0de-47f7-9b70-9384317051c8") 125 def test_firmware_crash_softap_reconnect_stress(self): 126 """Firmware crash stress test for softap mode 127 128 1. Turn off dut's Wi-Fi 129 2. Turn on dut's hotspot and connected by dut client 130 3. Trigger firmware crash 131 4. Check ssr happened 132 5. Check the connectivity of hotspot's client 133 6. Repeat step 3~5 134 """ 135 wutils.wifi_toggle_state(self.dut, False) 136 # Setup Soft AP 137 sap_config = wutils.create_softap_config() 138 wutils.start_wifi_tethering( 139 self.dut, sap_config[wutils.WifiEnums.SSID_KEY], 140 sap_config[wutils.WifiEnums.PWD_KEY], wutils.WifiEnums.WIFI_CONFIG_APBAND_2G) 141 config = { 142 "SSID": sap_config[wutils.WifiEnums.SSID_KEY], 143 "password": sap_config[wutils.WifiEnums.PWD_KEY] 144 } 145 # DUT client connects to softap 146 wutils.wifi_toggle_state(self.dut_client, True) 147 wutils.connect_to_wifi_network(self.dut_client, config, check_connectivity=False) 148 # Ping the DUT 149 dut_addr = self.dut.droid.connectivityGetIPv4Addresses( 150 self.ap_iface)[0] 151 asserts.assert_true( 152 utils.adb_shell_ping(self.dut_client, count=10, dest_ip=dut_addr, timeout=20), 153 "%s ping %s failed" % (self.dut_client.serial, dut_addr)) 154 for count in range(self.stress_count): 155 self.log.info("%s: %d/%d" % 156 (self.current_test_name, count + 1, self.stress_count)) 157 wutils.reset_wifi(self.dut_client) 158 # Trigger firmware crash 159 self.trigger_wifi_firmware_crash(self.dut) 160 # Connect DUT to Network 161 wutils.connect_to_wifi_network(self.dut_client, config, check_connectivity=False) 162 # Ping the DUT 163 server_addr = self.dut.droid.connectivityGetIPv4Addresses( 164 self.ap_iface)[0] 165 asserts.assert_true( 166 utils.adb_shell_ping( 167 self.dut_client, 168 count=10, 169 dest_ip=server_addr, 170 timeout=20), 171 "%s ping %s failed" % (self.dut_client.serial, server_addr)) 172 wutils.stop_wifi_tethering(self.dut) 173 174 @test_tracker_info(uuid="4b7f2d89-82be-41de-9277-e938cc1c318b") 175 def test_firmware_crash_concurrent_reconnect_stress(self): 176 """Firmware crash stress test for concurrent mode 177 178 1. Turn on dut's Wi-Fi and connect to access point 179 2. Turn on dut's hotspot and connected by dut client 180 3. Trigger firmware crash 181 4. Check ssr happened 182 5. Check dut can connect to access point 183 6. Check the connectivity of hotspot's client 184 7. Repeat step 3~6 185 """ 186 if self.dut.model not in self.dbs_supported_models: 187 raise signals.TestSkip("%s does not support dual interfaces" % self.dut.model) 188 189 # Connect DUT to Network 190 wutils.wifi_toggle_state(self.dut, True) 191 wutils.connect_to_wifi_network(self.dut, self.network) 192 # Setup Soft AP 193 sap_config = wutils.create_softap_config() 194 wutils.start_wifi_tethering( 195 self.dut, sap_config[wutils.WifiEnums.SSID_KEY], 196 sap_config[wutils.WifiEnums.PWD_KEY], wutils.WifiEnums.WIFI_CONFIG_APBAND_2G) 197 config = { 198 "SSID": sap_config[wutils.WifiEnums.SSID_KEY], 199 "password": sap_config[wutils.WifiEnums.PWD_KEY] 200 } 201 # Client connects to Softap 202 wutils.wifi_toggle_state(self.dut_client, True) 203 wutils.connect_to_wifi_network(self.dut_client, config) 204 for count in range(self.stress_count): 205 self.log.info("%s: %d/%d" % 206 (self.current_test_name, count + 1, self.stress_count)) 207 wutils.reset_wifi(self.dut_client) 208 wutils.reset_wifi(self.dut) 209 # Trigger firmware crash 210 self.trigger_wifi_firmware_crash(self.dut) 211 wutils.connect_to_wifi_network(self.dut, self.network) 212 wutils.connect_to_wifi_network(self.dut_client, config) 213 wutils.stop_wifi_tethering(self.dut) 214