blob: af0150eaa08e6d5f522af6f57344f2a48f77c1e8 [file] [log] [blame]
Bindu Mahadev9ef65492018-02-06 18:18:18 -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 pprint
18import time
19
20import acts.base_test
21import acts.test_utils.wifi.wifi_test_utils as wutils
22import acts.utils
23
24from acts import asserts
25from acts import signals
26from acts import utils
27from acts.test_decorators import test_tracker_info
28from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest
29WifiEnums = wutils.WifiEnums
30
31WAIT_FOR_AUTO_CONNECT = 40
32WAIT_BEFORE_CONNECTION = 30
33
34TIMEOUT = 1
Bindu Mahadevdb292d82018-06-01 18:32:00 -070035PING_ADDR = 'www.google.com'
Bindu Mahadev9ef65492018-02-06 18:18:18 -080036
37class WifiStressTest(WifiBaseTest):
38 """WiFi Stress test class.
39
40 Test Bed Requirement:
41 * Two Android device
42 * Several Wi-Fi networks visible to the device, including an open Wi-Fi
43 network.
44 """
45
46 def __init__(self, controllers):
47 WifiBaseTest.__init__(self, controllers)
48
49 def setup_class(self):
50 self.dut = self.android_devices[0]
51 self.dut_client = self.android_devices[1]
52 wutils.wifi_test_device_init(self.dut)
53 req_params = []
54 opt_param = [
55 "open_network", "reference_networks", "iperf_server_address",
56 "stress_count"]
57 self.unpack_userparams(
58 req_param_names=req_params, opt_param_names=opt_param)
59
60 if "AccessPoint" in self.user_params:
Bindu Mahadev6212a322018-05-10 22:05:57 -070061 self.legacy_configure_ap_and_start(ap_count=2)
Bindu Mahadev9ef65492018-02-06 18:18:18 -080062
63 asserts.assert_true(
64 len(self.reference_networks) > 0,
65 "Need at least one reference network with psk.")
66 self.wpa_2g = self.reference_networks[0]["2g"]
67 self.wpa_5g = self.reference_networks[0]["5g"]
68 self.open_2g = self.open_network[0]["2g"]
69 self.open_5g = self.open_network[0]["5g"]
70 self.networks = [self.wpa_2g, self.wpa_5g, self.open_2g, self.open_5g]
71 if "iperf_server_address" in self.user_params:
72 self.iperf_server = self.iperf_servers[0]
73 if hasattr(self, 'iperf_server'):
74 self.iperf_server.start()
75
76 def setup_test(self):
77 self.dut.droid.wakeLockAcquireBright()
78 self.dut.droid.wakeUpNow()
79
80 def teardown_test(self):
81 self.dut.droid.wakeLockRelease()
82 self.dut.droid.goToSleepNow()
Bindu Mahadev3f9db852018-05-22 19:39:49 -070083 wutils.reset_wifi(self.dut)
Bindu Mahadev9ef65492018-02-06 18:18:18 -080084
85 def on_fail(self, test_name, begin_time):
86 self.dut.take_bug_report(test_name, begin_time)
87 self.dut.cat_adb_log(test_name, begin_time)
88 pass
89
90 def teardown_class(self):
91 wutils.reset_wifi(self.dut)
92 if hasattr(self, 'iperf_server'):
93 self.iperf_server.stop()
94 if "AccessPoint" in self.user_params:
95 del self.user_params["reference_networks"]
96 del self.user_params["open_network"]
97
98 """Helper Functions"""
99
100 def scan_and_connect_by_ssid(self, network):
101 """Scan for network and connect using network information.
102
103 Args:
104 network: A dictionary representing the network to connect to.
105
106 """
107 ssid = network[WifiEnums.SSID_KEY]
108 wutils.start_wifi_connection_scan_and_ensure_network_found(self.dut,
109 ssid)
110 wutils.wifi_connect(self.dut, network, num_of_tries=3)
111
112 def scan_and_connect_by_id(self, network, net_id):
113 """Scan for network and connect using network id.
114
115 Args:
116 net_id: Integer specifying the network id of the network.
117
118 """
119 ssid = network[WifiEnums.SSID_KEY]
120 wutils.start_wifi_connection_scan_and_ensure_network_found(self.dut,
121 ssid)
122 wutils.wifi_connect_by_id(self.dut, net_id)
123
Bindu Mahadevdb292d82018-06-01 18:32:00 -0700124 def run_ping(self, sec):
125 """Run ping for given number of seconds.
126
127 Args:
128 sec: Time in seconds to run teh ping traffic.
129
130 """
131 self.log.info("Running ping for %d seconds" % sec)
132 result = self.dut.adb.shell("ping -w %d %s" %(sec, PING_ADDR))
133 self.log.debug("Ping Result = %s" % result)
134 if "100% packet loss" in result:
135 raise signals.TestFailure("100% packet loss during ping")
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800136
137 """Tests"""
138
Bindu Mahadev140431e2018-05-04 13:14:00 -0700139 @test_tracker_info(uuid="cd0016c6-58cf-4361-b551-821c0b8d2554")
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800140 def test_stress_toggle_wifi_state(self):
141 """Toggle WiFi state ON and OFF for N times."""
142 for count in range(self.stress_count):
143 """Test toggling wifi"""
144 self.log.debug("Going from on to off.")
145 wutils.wifi_toggle_state(self.dut, False)
146 self.log.debug("Going from off to on.")
147 startTime = time.time()
148 wutils.wifi_toggle_state(self.dut, True)
149 startup_time = time.time() - startTime
150 self.log.debug("WiFi was enabled on the device in %s s." % startup_time)
151
Bindu Mahadev140431e2018-05-04 13:14:00 -0700152 @test_tracker_info(uuid="49e3916a-9580-4bf7-a60d-a0f2545dcdde")
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800153 def test_stress_connect_traffic_disconnect_5g(self):
154 """Test to connect and disconnect from a network for N times.
155
156 Steps:
157 1. Scan and connect to a network.
158 2. Run IPerf to upload data for few seconds.
159 3. Disconnect.
160 4. Repeat 1-3.
161
162 """
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800163 for count in range(self.stress_count):
Bindu Mahadev4c6c23e2018-05-09 17:57:15 -0700164 net_id = self.dut.droid.wifiAddNetwork(self.wpa_5g)
165 asserts.assert_true(net_id != -1, "Add network %r failed" % self.wpa_5g)
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800166 self.scan_and_connect_by_id(self.wpa_5g, net_id)
167 # Start IPerf traffic from phone to server.
168 # Upload data for 10s.
169 args = "-p {} -t {}".format(self.iperf_server.port, 10)
170 self.log.info("Running iperf client {}".format(args))
171 result, data = self.dut.run_iperf_client(self.iperf_server_address, args)
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800172 if not result:
173 self.log.debug("Error occurred in iPerf traffic.")
Bindu Mahadevdb292d82018-06-01 18:32:00 -0700174 self.run_ping(10)
Bindu Mahadev4c6c23e2018-05-09 17:57:15 -0700175 wutils.wifi_forget_network(self.dut,self.wpa_5g[WifiEnums.SSID_KEY])
176 time.sleep(WAIT_BEFORE_CONNECTION)
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800177
Bindu Mahadev140431e2018-05-04 13:14:00 -0700178 @test_tracker_info(uuid="e9827dff-0755-43ec-8b50-1f9756958460")
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800179 def test_stress_connect_long_traffic_5g(self):
180 """Test to connect to network and hold connection for few hours.
181
182 Steps:
183 1. Scan and connect to a network.
184 2. Run IPerf to download data for few hours.
185 3. Verify no WiFi disconnects/data interruption.
186
187 """
188 self.scan_and_connect_by_ssid(self.wpa_5g)
189 # Start IPerf traffic from server to phone.
190 # Download data for 5 hours.
191 sec = 5*60*60
192 args = "-p {} -t {} -R".format(self.iperf_server.port, sec)
193 self.log.info("Running iperf client {}".format(args))
194 result, data = self.dut.run_iperf_client(self.iperf_server_address,
195 args, timeout=sec+1)
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800196 if not result:
197 self.log.debug("Error occurred in iPerf traffic.")
Bindu Mahadevdb292d82018-06-01 18:32:00 -0700198 self.run_ping(sec)
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800199
Bindu Mahadev140431e2018-05-04 13:14:00 -0700200 @test_tracker_info(uuid="d367c83e-5b00-4028-9ed8-f7b875997d13")
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800201 def test_stress_wifi_failover(self):
202 """This test does aggressive failover to several networks in list.
203
204 Steps:
205 1. Add and enable few networks.
206 2. Let device auto-connect.
207 3. Remove the connected network.
208 4. Repeat 2-3.
209 5. Device should connect to a network until all networks are
210 exhausted.
211
212 """
213 for count in range(self.stress_count):
214 ssids = list()
215 for network in self.networks:
216 ssids.append(network[WifiEnums.SSID_KEY])
217 ret = self.dut.droid.wifiAddNetwork(network)
218 asserts.assert_true(ret != -1, "Add network %r failed" % network)
219 self.dut.droid.wifiEnableNetwork(ret, 0)
220 time.sleep(WAIT_FOR_AUTO_CONNECT)
221 cur_network = self.dut.droid.wifiGetConnectionInfo()
222 cur_ssid = cur_network[WifiEnums.SSID_KEY]
Bindu Mahadev38a74442018-05-23 12:58:20 -0700223 self.log.info("Cur_ssid = %s" % cur_ssid)
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800224 for count in range(0,len(self.networks)):
225 self.log.debug("Forget network %s" % cur_ssid)
226 wutils.wifi_forget_network(self.dut, cur_ssid)
227 time.sleep(WAIT_FOR_AUTO_CONNECT)
228 cur_network = self.dut.droid.wifiGetConnectionInfo()
229 cur_ssid = cur_network[WifiEnums.SSID_KEY]
Bindu Mahadev38a74442018-05-23 12:58:20 -0700230 self.log.info("Cur_ssid = %s" % cur_ssid)
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800231 if count == len(self.networks) - 1:
232 break
233 if cur_ssid not in ssids:
234 raise signals.TestFailure("Device did not failover to the "
235 "expected network. SSID = %s" % cur_ssid)
236 network_config = self.dut.droid.wifiGetConfiguredNetworks()
Bindu Mahadev38a74442018-05-23 12:58:20 -0700237 self.log.info("Network Config = %s" % network_config)
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800238 if len(network_config):
239 raise signals.TestFailure("All the network configurations were not "
240 "removed. Configured networks = %s" % network_config)
241
Bindu Mahadev140431e2018-05-04 13:14:00 -0700242 @test_tracker_info(uuid="2c19e8d1-ac16-4d7e-b309-795144e6b956")
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800243 def test_stress_softAP_startup_and_stop_5g(self):
244 """Test to bring up softAP and down for N times.
245
246 Steps:
247 1. Bring up softAP on 5G.
248 2. Check for softAP on teh client device.
249 3. Turn ON WiFi.
250 4. Verify softAP is turned down and WiFi is up.
251
252 """
Bindu Mahadev05389762018-05-29 16:26:42 -0700253 # Set country code explicitly to "US".
254 self.dut.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US)
255 self.dut_client.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US)
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800256 ap_ssid = "softap_" + utils.rand_ascii_str(8)
257 ap_password = utils.rand_ascii_str(8)
258 self.dut.log.info("softap setup: %s %s", ap_ssid, ap_password)
259 config = {wutils.WifiEnums.SSID_KEY: ap_ssid}
260 config[wutils.WifiEnums.PWD_KEY] = ap_password
261 for count in range(self.stress_count):
262 initial_wifi_state = self.dut.droid.wifiCheckState()
263 wutils.start_wifi_tethering(self.dut,
264 ap_ssid,
265 ap_password,
266 WifiEnums.WIFI_CONFIG_APBAND_5G)
267 wutils.start_wifi_connection_scan_and_ensure_network_found(
268 self.dut_client, ap_ssid)
Bindu Mahadev1fbd51c2018-06-05 16:27:23 -0700269 wutils.stop_wifi_tethering(self.dut)
Bindu Mahadev9ef65492018-02-06 18:18:18 -0800270 asserts.assert_false(self.dut.droid.wifiIsApEnabled(),
271 "SoftAp failed to shutdown!")
272 time.sleep(TIMEOUT)
273 cur_wifi_state = self.dut.droid.wifiCheckState()
274 if initial_wifi_state != cur_wifi_state:
275 raise signals.TestFailure("Wifi state was %d before softAP and %d now!" %
276 (initial_wifi_state, cur_wifi_state))
Bindu Mahadev140431e2018-05-04 13:14:00 -0700277
278 @test_tracker_info(uuid="eb22e26b-95d1-4580-8c76-85dfe6a42a0f")
279 def test_stress_wifi_roaming(self):
280 AP1_network = self.reference_networks[0]["5g"]
281 AP2_network = self.reference_networks[1]["5g"]
282 wutils.set_attns(self.attenuators, "AP1_on_AP2_off")
Bindu Mahadev3f9db852018-05-22 19:39:49 -0700283 self.scan_and_connect_by_ssid(AP1_network)
Bindu Mahadev140431e2018-05-04 13:14:00 -0700284 # Reduce iteration to half because each iteration does two roams.
Bindu Mahadev38a74442018-05-23 12:58:20 -0700285 for count in range(int(self.stress_count/2)):
Bindu Mahadev140431e2018-05-04 13:14:00 -0700286 self.log.info("Roaming iteration %d, from %s to %s", count,
287 AP1_network, AP2_network)
288 wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
289 "AP1_off_AP2_on", AP2_network)
290 self.log.info("Roaming iteration %d, from %s to %s", count,
291 AP2_network, AP1_network)
292 wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
293 "AP1_on_AP2_off", AP1_network)
294