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