blob: dd19904b00d9e3d053ef1143f844db504bac1f2e [file] [log] [blame]
Hayden Nix3f2eebf2020-01-14 10:39:21 -08001#!/usr/bin/env python3
2#
3# Copyright 2020 - 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
Hayden Nixc8a02bf2020-04-14 19:12:34 +000017import json
18import os
19import time
Hayden Nix3f2eebf2020-01-14 10:39:21 -080020
Hayden Nixc8a02bf2020-04-14 19:12:34 +000021from statistics import pstdev
22
23from bokeh.models import FixedTicker
24from bokeh.plotting import ColumnDataSource
25from bokeh.plotting import figure
26from bokeh.plotting import output_file
27from bokeh.plotting import save
28
29from acts import asserts
30from acts import context
Hayden Nix3f2eebf2020-01-14 10:39:21 -080031from acts import utils
Hayden Nixfe643052020-12-09 00:50:05 +000032from acts.controllers.access_point import setup_ap
Hayden Nix3f2eebf2020-01-14 10:39:21 -080033from acts.controllers.ap_lib import hostapd_config
Hayden Nixc8a02bf2020-04-14 19:12:34 +000034from acts.controllers.ap_lib import hostapd_constants
35from acts.controllers.ap_lib.hostapd_security import Security
36from acts.controllers.iperf_server import IPerfResult
Xianyuan Jia24299b72020-10-21 13:52:47 -070037from acts_contrib.test_utils.abstract_devices.wlan_device import create_wlan_device
38from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
Hayden Nix3f2eebf2020-01-14 10:39:21 -080039
40N_CAPABILITIES_DEFAULT = [
41 hostapd_constants.N_CAPABILITY_LDPC, hostapd_constants.N_CAPABILITY_SGI20,
42 hostapd_constants.N_CAPABILITY_SGI40,
43 hostapd_constants.N_CAPABILITY_TX_STBC,
44 hostapd_constants.N_CAPABILITY_RX_STBC1
45]
46
47AC_CAPABILITIES_DEFAULT = [
48 hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454,
49 hostapd_constants.AC_CAPABILITY_RXLDPC,
50 hostapd_constants.AC_CAPABILITY_SHORT_GI_80,
51 hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1,
52 hostapd_constants.AC_CAPABILITY_RX_STBC_1,
53 hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7,
54 hostapd_constants.AC_CAPABILITY_RX_ANTENNA_PATTERN,
55 hostapd_constants.AC_CAPABILITY_TX_ANTENNA_PATTERN
56]
57
Hayden Nixc8a02bf2020-04-14 19:12:34 +000058DEFAULT_MIN_THROUGHPUT = 0
59DEFAULT_MAX_STD_DEV = 1
Hayden Nix3f2eebf2020-01-14 10:39:21 -080060
Hayden Nixc8a02bf2020-04-14 19:12:34 +000061DEFAULT_TIME_TO_WAIT_FOR_IP_ADDR = 30
62GRAPH_CIRCLE_SIZE = 10
63IPERF_NO_THROUGHPUT_VALUE = 0
64MAX_2_4_CHANNEL = 14
65TIME_TO_SLEEP_BETWEEN_RETRIES = 1
Hayden Nix484f48c2020-04-14 20:54:17 +000066TIME_TO_WAIT_FOR_COUNTRY_CODE = 10
Hayden Nixc8a02bf2020-04-14 19:12:34 +000067WEP_HEX_STRING_LENGTH = 10
Hayden Nix3f2eebf2020-01-14 10:39:21 -080068
Hayden Nix7a69a4d2020-08-05 18:42:27 +000069MEGABITS_PER_SECOND = 'Mbps'
70
Hayden Nix3f2eebf2020-01-14 10:39:21 -080071
Hayden Nixc8a02bf2020-04-14 19:12:34 +000072def get_test_name(settings):
73 """Retrieves the test_name value from test_settings"""
74 return settings.get('test_name')
Hayden Nix3f2eebf2020-01-14 10:39:21 -080075
76
77class ChannelSweepTest(WifiBaseTest):
Hayden Nix484f48c2020-04-14 20:54:17 +000078 """Tests channel performance and regulatory compliance..
Hayden Nix3f2eebf2020-01-14 10:39:21 -080079
80 Testbed Requirement:
81 * One ACTS compatible device (dut)
82 * One Access Point
Hayden Nixc8a02bf2020-04-14 19:12:34 +000083 * One Linux Machine used as IPerfServer if running performance tests
84 Note: Performance tests should be done in isolated testbed.
Hayden Nix3f2eebf2020-01-14 10:39:21 -080085 """
86 def __init__(self, controllers):
87 WifiBaseTest.__init__(self, controllers)
Hayden Nixc8a02bf2020-04-14 19:12:34 +000088 if 'channel_sweep_test_params' in self.user_params:
89 self.time_to_wait_for_ip_addr = self.user_params[
90 'channel_sweep_test_params'].get(
91 'time_to_wait_for_ip_addr',
92 DEFAULT_TIME_TO_WAIT_FOR_IP_ADDR)
93 else:
94 self.time_to_wait_for_ip_addr = DEFAULT_TIME_TO_WAIT_FOR_IP_ADDR
Hayden Nix3f2eebf2020-01-14 10:39:21 -080095
96 def setup_class(self):
97 super().setup_class()
98 if 'dut' in self.user_params:
99 if self.user_params['dut'] == 'fuchsia_devices':
100 self.dut = create_wlan_device(self.fuchsia_devices[0])
101 elif self.user_params['dut'] == 'android_devices':
102 self.dut = create_wlan_device(self.android_devices[0])
103 else:
104 raise ValueError('Invalid DUT specified in config. (%s)' %
105 self.user_params['dut'])
106 else:
107 # Default is an android device, just like the other tests
108 self.dut = create_wlan_device(self.android_devices[0])
109
110 self.android_devices = getattr(self, 'android_devices', [])
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000111
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800112 self.access_point = self.access_points[0]
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000113 self.iperf_server = self.iperf_servers[0]
114 self.iperf_server.start()
115 self.iperf_client = self.iperf_clients[0]
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800116 self.access_point.stop_all_aps()
117
118 def setup_test(self):
Hayden Nix484f48c2020-04-14 20:54:17 +0000119 # TODO(fxb/46417): Uncomment when wlanClearCountry is implemented up any
120 # country code changes.
121 # for fd in self.fuchsia_devices:
122 # phy_ids_response = fd.wlan_lib.wlanPhyIdList()
123 # if phy_ids_response.get('error'):
124 # raise ConnectionError(
125 # 'Failed to retrieve phy ids from FuchsiaDevice (%s). '
126 # 'Error: %s' % (fd.ip, phy_ids_response['error']))
127 # for id in phy_ids_response['result']:
128 # clear_country_response = fd.wlan_lib.wlanClearCountry(id)
129 # if clear_country_response.get('error'):
130 # raise EnvironmentError(
131 # 'Failed to reset country code on FuchsiaDevice (%s). '
132 # 'Error: %s' % (fd.ip, clear_country_response['error'])
133 # )
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000134 self.access_point.stop_all_aps()
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800135 for ad in self.android_devices:
136 ad.droid.wakeLockAcquireBright()
137 ad.droid.wakeUpNow()
138 self.dut.wifi_toggle_state(True)
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000139 self.dut.disconnect()
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800140
141 def teardown_test(self):
142 for ad in self.android_devices:
143 ad.droid.wakeLockRelease()
144 ad.droid.goToSleepNow()
145 self.dut.turn_location_off_and_scan_toggle_off()
146 self.dut.disconnect()
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800147 self.access_point.stop_all_aps()
148
149 def on_fail(self, test_name, begin_time):
150 self.dut.take_bug_report(test_name, begin_time)
151 self.dut.get_log(test_name, begin_time)
152
Hayden Nix484f48c2020-04-14 20:54:17 +0000153 def set_dut_country_code(self, country_code):
154 """Set the country code on the DUT. Then verify that the country
155 code was set successfully
156
157 Args:
158 country_code: string, the 2 character country code to set
159 """
160 self.log.info('Setting DUT country code to %s' % country_code)
161 country_code_response = self.dut.device.regulatory_region_lib.setRegion(
162 country_code)
163 if country_code_response.get('error'):
164 raise EnvironmentError(
165 'Failed to set country code (%s) on DUT. Error: %s' %
166 (country_code, country_code_response['error']))
167
168 self.log.info('Verifying DUT country code was correctly set to %s.' %
169 country_code)
170 phy_ids_response = self.dut.device.wlan_lib.wlanPhyIdList()
171 if phy_ids_response.get('error'):
172 raise ConnectionError('Failed to get phy ids from DUT. Error: %s' %
173 (country_code, phy_ids_response['error']))
174
175 end_time = time.time() + TIME_TO_WAIT_FOR_COUNTRY_CODE
176 while time.time() < end_time:
177 for id in phy_ids_response['result']:
178 get_country_response = self.dut.device.wlan_lib.wlanGetCountry(
179 id)
180 if get_country_response.get('error'):
181 raise ConnectionError(
182 'Failed to query PHY ID (%s) for country. Error: %s' %
183 (id, get_country_response['error']))
184
185 set_code = ''.join([
186 chr(ascii_char)
187 for ascii_char in get_country_response['result']
188 ])
189 if set_code != country_code:
190 self.log.debug(
191 'PHY (id: %s) has incorrect country code set. '
192 'Expected: %s, Got: %s' % (id, country_code, set_code))
193 break
194 else:
195 self.log.info('All PHYs have expected country code (%s)' %
196 country_code)
197 break
198 time.sleep(TIME_TO_SLEEP_BETWEEN_RETRIES)
199 else:
200 raise EnvironmentError('Failed to set DUT country code to %s.' %
201 country_code)
202
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000203 def setup_ap(self, channel, channel_bandwidth, security_profile=None):
204 """Start network on AP with basic configuration.
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800205
206 Args:
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000207 channel: int, channel to use for network
208 channel_bandwidth: int, channel bandwidth in mhz to use for network,
209 security_profile: Security object, or None if open
210
211 Returns:
212 string, ssid of network running
213
214 Raises:
215 ConnectionError if network is not started successfully.
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800216 """
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000217 if channel > MAX_2_4_CHANNEL:
218 vht_bandwidth = channel_bandwidth
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800219 else:
220 vht_bandwidth = None
221
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000222 if channel_bandwidth == hostapd_constants.CHANNEL_BANDWIDTH_20MHZ:
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800223 n_capabilities = N_CAPABILITIES_DEFAULT + [
224 hostapd_constants.N_CAPABILITY_HT20
225 ]
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000226 elif (channel_bandwidth == hostapd_constants.CHANNEL_BANDWIDTH_40MHZ or
227 channel_bandwidth == hostapd_constants.CHANNEL_BANDWIDTH_80MHZ):
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800228 if hostapd_config.ht40_plus_allowed(channel):
229 extended_channel = [hostapd_constants.N_CAPABILITY_HT40_PLUS]
230 elif hostapd_config.ht40_minus_allowed(channel):
231 extended_channel = [hostapd_constants.N_CAPABILITY_HT40_MINUS]
232 else:
233 raise ValueError('Invalid Channel: %s' % channel)
234 n_capabilities = N_CAPABILITIES_DEFAULT + extended_channel
235 else:
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000236 raise ValueError('Invalid Bandwidth: %s' % channel_bandwidth)
237 ssid = utils.rand_ascii_str(hostapd_constants.AP_SSID_LENGTH_2G)
238 try:
Hayden Nixfe643052020-12-09 00:50:05 +0000239 setup_ap(access_point=self.access_point,
240 profile_name='whirlwind',
241 channel=channel,
242 security=security_profile,
243 n_capabilities=n_capabilities,
244 ac_capabilities=None,
245 force_wmm=True,
246 ssid=ssid,
247 vht_bandwidth=vht_bandwidth,
248 setup_bridge=True)
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000249 except Exception as err:
250 raise ConnectionError(
251 'Failed to setup ap on channel: %s, channel bandwidth: %smhz. '
252 'Error: %s' % (channel, channel_bandwidth, err))
253 else:
254 self.log.info(
255 'Network (ssid: %s) up on channel %s w/ channel bandwidth %smhz'
256 % (ssid, channel, channel_bandwidth))
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800257
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000258 return ssid
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800259
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000260 def get_and_verify_iperf_address(self, channel, device, interface=None):
261 """Get ip address from a devices interface and verify it belongs to
262 expected subnet based on APs DHCP config.
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800263
264 Args:
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000265 channel: int, channel network is running on, to determine subnet
266 device: device to get ip address for
267 interface (default: None): interface on device to get ip address.
268 If None, uses device.test_interface.
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800269
270 Returns:
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000271 String, ip address of device on given interface (or test_interface)
272
273 Raises:
274 ConnectionError, if device does not have a valid ip address after
275 all retries.
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800276 """
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000277 if channel <= MAX_2_4_CHANNEL:
278 subnet = self.access_point._AP_2G_SUBNET_STR
279 else:
280 subnet = self.access_point._AP_5G_SUBNET_STR
281 end_time = time.time() + self.time_to_wait_for_ip_addr
282 while time.time() < end_time:
283 if interface:
284 device_addresses = device.get_interface_ip_addresses(interface)
285 else:
286 device_addresses = device.get_interface_ip_addresses(
287 device.test_interface)
288
289 if device_addresses['ipv4_private']:
290 for ip_addr in device_addresses['ipv4_private']:
291 if utils.ip_in_subnet(ip_addr, subnet):
292 return ip_addr
293 else:
294 self.log.debug(
295 'Device has an ip address (%s), but it is not in '
296 'subnet %s' % (ip_addr, subnet))
297 else:
298 self.log.debug(
299 'Device does not have a valid ip address. Retrying.')
300 time.sleep(TIME_TO_SLEEP_BETWEEN_RETRIES)
301 raise ConnectionError('Device failed to get an ip address.')
302
303 def get_iperf_throughput(self,
304 iperf_server_address,
305 iperf_client_address,
306 reverse=False):
307 """Run iperf between client and server and get the throughput.
308
309 Args:
310 iperf_server_address: string, ip address of running iperf server
311 iperf_client_address: string, ip address of iperf client (dut)
312 reverse (default: False): If True, run traffic in reverse direction,
313 from server to client.
314
315 Returns:
316 int, iperf throughput OR IPERF_NO_THROUGHPUT_VALUE, if iperf fails
317 """
318 if reverse:
319 self.log.info(
320 'Running IPerf traffic from server (%s) to dut (%s).' %
321 (iperf_server_address, iperf_client_address))
322 iperf_results_file = self.iperf_client.start(
323 iperf_server_address, '-i 1 -t 10 -R -J', 'channel_sweep_rx')
324 else:
325 self.log.info(
326 'Running IPerf traffic from dut (%s) to server (%s).' %
327 (iperf_client_address, iperf_server_address))
328 iperf_results_file = self.iperf_client.start(
329 iperf_server_address, '-i 1 -t 10 -J', 'channel_sweep_tx')
330 if iperf_results_file:
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000331 iperf_results = IPerfResult(
332 iperf_results_file, reporting_speed_units=MEGABITS_PER_SECOND)
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000333 return iperf_results.avg_send_rate
334 else:
335 return IPERF_NO_THROUGHPUT_VALUE
336
337 def log_to_file_and_throughput_data(self, channel, channel_bandwidth,
338 tx_throughput, rx_throughput):
339 """Write performance info to csv file and to throughput data.
340
341 Args:
342 channel: int, channel that test was run on
343 channel_bandwidth: int, channel bandwidth the test used
344 tx_throughput: float, throughput value from dut to iperf server
345 rx_throughput: float, throughput value from iperf server to dut
346 """
347 test_name = self.throughput_data['test']
348 output_path = context.get_current_context().get_base_output_path()
349 log_path = '%s/ChannelSweepTest/%s' % (output_path, test_name)
350 if not os.path.exists(log_path):
351 os.makedirs(log_path)
352 log_file = '%s/%s_%smhz.csv' % (log_path, test_name, channel_bandwidth)
353 self.log.info('Writing IPerf results for %s to %s' %
354 (test_name, log_file))
355 with open(log_file, 'a') as csv_file:
356 csv_file.write('%s,%s,%s\n' %
357 (channel, tx_throughput, rx_throughput))
358 self.throughput_data['results'][str(channel)] = {
359 'tx_throughput': tx_throughput,
360 'rx_throughput': rx_throughput
361 }
362
363 def write_graph(self):
364 """Create graph html files from throughput data, plotting channel vs
365 tx_throughput and channel vs rx_throughput.
366 """
367 output_path = context.get_current_context().get_base_output_path()
368 test_name = self.throughput_data['test']
369 channel_bandwidth = self.throughput_data['channel_bandwidth']
370 output_file_name = '%s/ChannelSweepTest/%s/%s_%smhz.html' % (
371 output_path, test_name, test_name, channel_bandwidth)
372 output_file(output_file_name)
373 channels = []
374 tx_throughputs = []
375 rx_throughputs = []
376 for channel in self.throughput_data['results']:
377 channels.append(str(channel))
378 tx_throughputs.append(
379 self.throughput_data['results'][channel]['tx_throughput'])
380 rx_throughputs.append(
381 self.throughput_data['results'][channel]['rx_throughput'])
382 channel_vs_throughput_data = ColumnDataSource(
383 data=dict(channels=channels,
384 tx_throughput=tx_throughputs,
385 rx_throughput=rx_throughputs))
386 TOOLTIPS = [('Channel', '@channels'),
387 ('TX_Throughput', '@tx_throughput'),
388 ('RX_Throughput', '@rx_throughput')]
389 channel_vs_throughput_graph = figure(title='Channels vs. Throughput',
390 x_axis_label='Channels',
391 x_range=channels,
392 y_axis_label='Throughput',
393 tooltips=TOOLTIPS)
394 channel_vs_throughput_graph.sizing_mode = 'stretch_both'
395 channel_vs_throughput_graph.title.align = 'center'
396 channel_vs_throughput_graph.line('channels',
397 'tx_throughput',
398 source=channel_vs_throughput_data,
399 line_width=2,
400 line_color='blue',
401 legend_label='TX_Throughput')
402 channel_vs_throughput_graph.circle('channels',
403 'tx_throughput',
404 source=channel_vs_throughput_data,
405 size=GRAPH_CIRCLE_SIZE,
406 color='blue')
407 channel_vs_throughput_graph.line('channels',
408 'rx_throughput',
409 source=channel_vs_throughput_data,
410 line_width=2,
411 line_color='red',
412 legend_label='RX_Throughput')
413 channel_vs_throughput_graph.circle('channels',
414 'rx_throughput',
415 source=channel_vs_throughput_data,
416 size=GRAPH_CIRCLE_SIZE,
417 color='red')
418
419 channel_vs_throughput_graph.legend.location = "top_left"
420 graph_file = save([channel_vs_throughput_graph])
421 self.log.info('Saved graph to %s' % graph_file)
422
423 def verify_standard_deviation(self, max_std_dev):
424 """Verifies the standard deviation of the throughput across the channels
425 does not exceed the max_std_dev value.
426
427 Args:
428 max_std_dev: float, max standard deviation of throughput for a test
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000429 to pass (in Mb/s)
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000430
431 Raises:
432 TestFailure, if standard deviation of throughput exceeds max_std_dev
433 """
434 self.log.info('Verifying standard deviation across channels does not '
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000435 'exceed max standard deviation of %s Mb/s' % max_std_dev)
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000436 tx_values = []
437 rx_values = []
438 for channel in self.throughput_data['results']:
439 if self.throughput_data['results'][channel][
440 'tx_throughput'] is not None:
441 tx_values.append(
442 self.throughput_data['results'][channel]['tx_throughput'])
443 if self.throughput_data['results'][channel][
444 'rx_throughput'] is not None:
445 rx_values.append(
446 self.throughput_data['results'][channel]['rx_throughput'])
447 tx_std_dev = pstdev(tx_values)
448 rx_std_dev = pstdev(rx_values)
449 if tx_std_dev > max_std_dev or rx_std_dev > max_std_dev:
450 asserts.fail(
451 'With %smhz channel bandwidth, throughput standard '
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000452 'deviation (tx: %s Mb/s, rx: %s Mb/s) exceeds max standard '
453 'deviation (%s Mb/s).' %
Hayden Nix484f48c2020-04-14 20:54:17 +0000454 (self.throughput_data['channel_bandwidth'], tx_std_dev,
455 rx_std_dev, max_std_dev))
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000456 else:
457 asserts.explicit_pass(
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000458 'Throughput standard deviation (tx: %s Mb/s, rx: %s Mb/s) '
459 'with %smhz channel bandwidth does not exceed maximum (%s Mb/s).'
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000460 % (tx_std_dev, rx_std_dev,
461 self.throughput_data['channel_bandwidth'], max_std_dev))
462
463 def run_channel_performance_tests(self, settings):
464 """Test function for running channel performance tests. Used by both
465 explicit test cases and debug test cases from config. Runs a performance
466 test for each channel in test_channels with test_channel_bandwidth, then
467 writes a graph and csv file of the channel vs throughput.
468
469 Args:
470 settings: dict, containing the following test settings
471 test_channels: list of channels to test.
472 test_channel_bandwidth: int, channel bandwidth to use for test.
473 test_security (optional): string, security type to use for test.
474 min_tx_throughput (optional, default: 0): float, minimum tx
475 throughput threshold to pass individual channel tests
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000476 (in Mb/s).
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000477 min_rx_throughput (optional, default: 0): float, minimum rx
478 throughput threshold to pass individual channel tests
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000479 (in Mb/s).
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000480 max_std_dev (optional, default: 1): float, maximum standard
481 deviation of throughput across all test channels to pass
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000482 test (in Mb/s).
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000483 base_test_name (optional): string, test name prefix to use with
484 generated subtests.
Hayden Nix484f48c2020-04-14 20:54:17 +0000485 country_name (optional): string, country name from
486 hostapd_constants to set on device.
487 country_code (optional): string, two-char country code to set on
488 the DUT. Takes priority over country_name.
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000489 test_name (debug tests only): string, the test name for this
490 parent test case from the config file. In explicit tests,
491 this is not necessary.
492
493 Writes:
494 CSV file: channel, tx_throughput, rx_throughput
495 for every test channel.
496 Graph: channel vs tx_throughput & channel vs rx_throughput
497
498 Raises:
499 TestFailure, if throughput standard deviation across channels
500 exceeds max_std_dev
501
502 Example Explicit Test (see EOF for debug JSON example):
503 def test_us_2g_20mhz_wpa2(self):
504 self.run_channel_performance_tests(
505 dict(
506 test_channels=hostapd_constants.US_CHANNELS_2G,
507 test_channel_bandwidth=20,
508 test_security=hostapd_constants.WPA2_STRING,
509 min_tx_throughput=2,
510 min_rx_throughput=4,
511 max_std_dev=0.75,
Hayden Nix484f48c2020-04-14 20:54:17 +0000512 country_code='US',
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000513 base_test_name='test_us'))
514 """
515 test_channels = settings['test_channels']
516 test_channel_bandwidth = settings['test_channel_bandwidth']
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000517 test_security = settings.get('test_security', None)
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000518 test_name = settings.get('test_name', self.test_name)
519 base_test_name = settings.get('base_test_name', 'test')
520 min_tx_throughput = settings.get('min_tx_throughput',
521 DEFAULT_MIN_THROUGHPUT)
522 min_rx_throughput = settings.get('min_rx_throughput',
523 DEFAULT_MIN_THROUGHPUT)
524 max_std_dev = settings.get('max_std_dev', DEFAULT_MAX_STD_DEV)
Hayden Nix484f48c2020-04-14 20:54:17 +0000525 country_code = settings.get('country_code')
526 country_name = settings.get('country_name')
527 country_label = None
528
529 if country_code:
530 country_label = country_code
531 self.set_dut_country_code(country_code)
532 elif country_name:
533 country_label = country_name
534 code = hostapd_constants.COUNTRY_CODE[country_name]['country_code']
535 self.set_dut_country_code(code)
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000536
537 self.throughput_data = {
538 'test': test_name,
539 'channel_bandwidth': test_channel_bandwidth,
540 'results': {}
541 }
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800542 test_list = []
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000543 for channel in test_channels:
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000544 sub_test_name = 'test_%schannel_%s_%smhz_%s_performance' % (
Hayden Nix484f48c2020-04-14 20:54:17 +0000545 '%s_' % country_label if country_label else '', channel,
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000546 test_channel_bandwidth,
547 test_security if test_security else 'open')
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000548 test_list.append({
549 'test_name': sub_test_name,
550 'channel': int(channel),
551 'channel_bandwidth': int(test_channel_bandwidth),
552 'security': test_security,
553 'min_tx_throughput': min_tx_throughput,
554 'min_rx_throughput': min_rx_throughput
555 })
556 self.run_generated_testcases(self.get_channel_performance,
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800557 settings=test_list,
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000558 name_func=get_test_name)
559 self.log.info('Channel tests completed.')
560 self.write_graph()
561 self.verify_standard_deviation(max_std_dev)
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800562
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000563 def get_channel_performance(self, settings):
564 """Run a single channel performance test and logs results to csv file
565 and throughput data. Run with generated sub test cases in
566 run_channel_performance_tests.
567
568 1. Sets up network with test settings
569 2. Associates DUT
570 3. Runs traffic between DUT and iperf server (both directions)
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000571 4. Logs channel, tx_throughput (Mb/s), and rx_throughput (Mb/s) to
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000572 log file and throughput data.
573 5. Checks throughput values against minimum throughput thresholds.
574
575 Args:
576 settings: see run_channel_performance_tests
577
578 Raises:
579 TestFailure, if throughput (either direction) is less than
580 the directions given minimum throughput threshold.
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800581 """
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000582 channel = settings['channel']
583 channel_bandwidth = settings['channel_bandwidth']
584 security = settings['security']
585 test_name = settings['test_name']
586 min_tx_throughput = settings['min_tx_throughput']
587 min_rx_throughput = settings['min_rx_throughput']
588 if security:
589 if security == hostapd_constants.WEP_STRING:
590 password = utils.rand_hex_str(WEP_HEX_STRING_LENGTH)
591 else:
592 password = utils.rand_ascii_str(
593 hostapd_constants.MIN_WPA_PSK_LENGTH)
594 security_profile = Security(security_mode=security,
595 password=password)
Hayden Nix6977b1f2021-02-04 19:00:46 +0000596 target_security = hostapd_constants.SECURITY_STRING_TO_DEFAULT_TARGET_SECURITY.get(
597 security)
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000598 else:
599 password = None
600 security_profile = None
Hayden Nix6977b1f2021-02-04 19:00:46 +0000601 target_security = None
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000602 ssid = self.setup_ap(channel, channel_bandwidth, security_profile)
Hayden Nix6977b1f2021-02-04 19:00:46 +0000603 associated = self.dut.associate(ssid,
604 target_pwd=password,
605 target_security=target_security)
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000606 if not associated:
607 self.log_to_file_and_throughput_data(channel, channel_bandwidth,
608 None, None)
609 asserts.fail('Device failed to associate with network %s' % ssid)
610 self.log.info('DUT (%s) connected to network %s.' %
611 (self.dut.device.ip, ssid))
612 self.iperf_server.renew_test_interface_ip_address()
613 self.log.info(
614 'Getting ip address for iperf server. Will retry for %s seconds.' %
615 self.time_to_wait_for_ip_addr)
616 iperf_server_address = self.get_and_verify_iperf_address(
617 channel, self.iperf_server)
618 self.log.info(
619 'Getting ip address for DUT. Will retry for %s seconds.' %
620 self.time_to_wait_for_ip_addr)
621 iperf_client_address = self.get_and_verify_iperf_address(
622 channel, self.dut, self.iperf_client.test_interface)
623 tx_throughput = self.get_iperf_throughput(iperf_server_address,
624 iperf_client_address)
625 rx_throughput = self.get_iperf_throughput(iperf_server_address,
626 iperf_client_address,
627 reverse=True)
628 self.log_to_file_and_throughput_data(channel, channel_bandwidth,
629 tx_throughput, rx_throughput)
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000630 self.log.info('Throughput (tx, rx): (%s Mb/s, %s Mb/s), '
631 'Minimum threshold (tx, rx): (%s Mb/s, %s Mb/s)' %
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000632 (tx_throughput, rx_throughput, min_tx_throughput,
633 min_rx_throughput))
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000634 base_message = (
635 'Actual throughput (on channel: %s, channel bandwidth: '
636 '%s, security: %s)' % (channel, channel_bandwidth, security))
Hayden Nix484f48c2020-04-14 20:54:17 +0000637 if (tx_throughput < min_tx_throughput
638 or rx_throughput < min_rx_throughput):
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000639 asserts.fail('%s below the minimum threshold.' % base_message)
640 asserts.explicit_pass('%s above the minimum threshold.' % base_message)
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800641
Hayden Nix484f48c2020-04-14 20:54:17 +0000642 def verify_regulatory_compliance(self, settings):
643 """Test function for regulatory compliance tests. Verify device complies
644 with provided regulatory requirements.
645
646 Args:
647 settings: dict, containing the following test settings
648 test_channels: dict, mapping channels to a set of the channel
649 bandwidths to test (see example for using JSON). Defaults
650 to hostapd_constants.ALL_CHANNELS.
651 country_code: string, two-char country code to set on device
652 (prioritized over country_name)
653 country_name: string, country name from hostapd_constants to set
654 on device.
655 base_test_name (optional): string, test name prefix to use with
656 generatedsubtests.
657 test_name: string, the test name for this
658 parent test case from the config file. In explicit tests,
659 this is not necessary.
660 """
661 country_name = settings.get('country_name')
662 country_code = settings.get('country_code')
663 if not (country_code or country_name):
664 raise ValueError('No country code or name provided.')
665
666 test_channels = settings.get('test_channels',
667 hostapd_constants.ALL_CHANNELS)
668 allowed_channels = settings['allowed_channels']
669
670 base_test_name = settings.get('base_test_name', 'test_compliance')
671
672 if country_code:
673 code = country_code
674 else:
675 code = hostapd_constants.COUNTRY_CODE[country_name]['country_code']
676
677 self.set_dut_country_code(code)
678
679 test_list = []
680 for channel in test_channels:
681 for channel_bandwidth in test_channels[channel]:
682 sub_test_name = '%s_channel_%s_%smhz' % (
683 base_test_name, channel, channel_bandwidth)
Hayden Nix7a69a4d2020-08-05 18:42:27 +0000684 should_associate = (channel in allowed_channels
685 and channel_bandwidth
686 in allowed_channels[channel])
Hayden Nix484f48c2020-04-14 20:54:17 +0000687 # Note: these int conversions because when these tests are
688 # imported via JSON, they may be strings since the channels
689 # will be keys. This makes the json/list test_channels param
690 # behave exactly like the in code dict/set test_channels.
691 test_list.append({
692 'country_code': code,
693 'channel': int(channel),
694 'channel_bandwidth': int(channel_bandwidth),
695 'should_associate': should_associate,
696 'test_name': sub_test_name
697 })
698 self.run_generated_testcases(test_func=self.verify_channel_compliance,
699 settings=test_list,
700 name_func=get_test_name)
701
702 def verify_channel_compliance(self, settings):
703 """Verify device complies with provided regulatory requirements for a
704 specific channel and channel bandwidth. Run with generated test cases
705 in the verify_regulatory_compliance parent test.
706_
707 Args:
708 settings: see verify_regulatory_compliance`
709 """
710 channel = settings['channel']
711 channel_bandwidth = settings['channel_bandwidth']
712 code = settings['country_code']
713 should_associate = settings['should_associate']
714
715 ssid = self.setup_ap(channel, channel_bandwidth)
716
717 self.log.info(
718 'Attempting to associate with network (%s) on channel %s @ %smhz. '
719 'Expected behavior: %s' %
720 (ssid, channel, channel_bandwidth, 'Device should associate'
721 if should_associate else 'Device should NOT associate.'))
722
Hayden Nixfe643052020-12-09 00:50:05 +0000723 associated = self.dut.associate(ssid)
Hayden Nix484f48c2020-04-14 20:54:17 +0000724 if associated == should_associate:
725 asserts.explicit_pass(
726 'Device complied with %s regulatory requirement for channel %s '
727 ' with channel bandwidth %smhz. %s' %
728 (code, channel, channel_bandwidth,
729 'Associated.' if associated else 'Refused to associate.'))
730 else:
731 asserts.fail(
732 'Device failed compliance with regulatory domain %s for '
733 'channel %s with channel bandwidth %smhz. Expected: %s, Got: %s'
734 % (code, channel, channel_bandwidth, 'Should associate'
735 if should_associate else 'Should not associate',
736 'Associated' if associated else 'Did not associate'))
737
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000738 # Helper functions to allow explicit tests throughput and standard deviation
739 # thresholds to be passed in via config.
740 def _get_min_tx_throughput(self, test_name):
741 return self.user_params.get('channel_sweep_test_params',
742 {}).get(test_name,
743 {}).get('min_tx_throughput',
744 DEFAULT_MIN_THROUGHPUT)
Hayden Nix3f2eebf2020-01-14 10:39:21 -0800745
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000746 def _get_min_rx_throughput(self, test_name):
747 return self.user_params.get('channel_sweep_test_params',
748 {}).get(test_name,
749 {}).get('min_rx_throughput',
750 DEFAULT_MIN_THROUGHPUT)
751
752 def _get_max_std_dev(self, test_name):
753 return self.user_params.get('channel_sweep_test_params',
754 {}).get(test_name,
755 {}).get('min_std_dev',
756 DEFAULT_MAX_STD_DEV)
757
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000758 # Channel Performance of US Channels: 570 Test Cases
759 # 36 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000760 def test_us_20mhz_open_channel_performance(self):
761 self.run_channel_performance_tests(
762 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
763 hostapd_constants.US_CHANNELS_5G,
764 test_channel_bandwidth=hostapd_constants.
765 CHANNEL_BANDWIDTH_20MHZ,
766 base_test_name=self.test_name,
767 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
768 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
769 max_std_dev=self._get_max_std_dev(self.test_name)))
770
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000771 # 35 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000772 def test_us_40mhz_open_channel_performance(self):
773 self.run_channel_performance_tests(
774 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
775 hostapd_constants.US_CHANNELS_5G[:-1],
776 test_channel_bandwidth=hostapd_constants.
777 CHANNEL_BANDWIDTH_40MHZ,
778 base_test_name=self.test_name,
779 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
780 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
781 max_std_dev=self._get_max_std_dev(self.test_name)))
782
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000783 # 24 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000784 def test_us_80mhz_open_channel_performance(self):
785 self.run_channel_performance_tests(
786 dict(test_channels=hostapd_constants.US_CHANNELS_5G[:-1],
787 test_channel_bandwidth=hostapd_constants.
788 CHANNEL_BANDWIDTH_80MHZ,
789 base_test_name=self.test_name,
790 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
791 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
792 max_std_dev=self._get_max_std_dev(self.test_name)))
793
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000794 # 36 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000795 def test_us_20mhz_wep_channel_performance(self):
796 self.run_channel_performance_tests(
797 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
798 hostapd_constants.US_CHANNELS_5G,
799 test_channel_bandwidth=hostapd_constants.
800 CHANNEL_BANDWIDTH_20MHZ,
801 test_security=hostapd_constants.WEP_STRING,
802 base_test_name=self.test_name,
803 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
804 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
805 max_std_dev=self._get_max_std_dev(self.test_name)))
806
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000807 # 35 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000808 def test_us_40mhz_wep_channel_performance(self):
809 self.run_channel_performance_tests(
810 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
811 hostapd_constants.US_CHANNELS_5G[:-1],
812 test_channel_bandwidth=hostapd_constants.
813 CHANNEL_BANDWIDTH_40MHZ,
814 test_security=hostapd_constants.WEP_STRING,
815 base_test_name=self.test_name,
816 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
817 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
818 max_std_dev=self._get_max_std_dev(self.test_name)))
819
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000820 # 24 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000821 def test_us_80mhz_wep_channel_performance(self):
822 self.run_channel_performance_tests(
823 dict(test_channels=hostapd_constants.US_CHANNELS_5G[:-1],
824 test_channel_bandwidth=hostapd_constants.
825 CHANNEL_BANDWIDTH_80MHZ,
826 test_security=hostapd_constants.WEP_STRING,
827 base_test_name=self.test_name,
828 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
829 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
830 max_std_dev=self._get_max_std_dev(self.test_name)))
831
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000832 # 36 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000833 def test_us_20mhz_wpa_channel_performance(self):
834 self.run_channel_performance_tests(
835 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
836 hostapd_constants.US_CHANNELS_5G,
837 test_channel_bandwidth=hostapd_constants.
838 CHANNEL_BANDWIDTH_20MHZ,
839 test_security=hostapd_constants.WPA_STRING,
840 base_test_name=self.test_name,
841 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
842 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
843 max_std_dev=self._get_max_std_dev(self.test_name)))
844
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000845 # 35 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000846 def test_us_40mhz_wpa_channel_performance(self):
847 self.run_channel_performance_tests(
848 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
849 hostapd_constants.US_CHANNELS_5G[:-1],
850 test_channel_bandwidth=hostapd_constants.
851 CHANNEL_BANDWIDTH_40MHZ,
852 test_security=hostapd_constants.WPA_STRING,
853 base_test_name=self.test_name,
854 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
855 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
856 max_std_dev=self._get_max_std_dev(self.test_name)))
857
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000858 # 24 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000859 def test_us_80mhz_wpa_channel_performance(self):
860 self.run_channel_performance_tests(
861 dict(test_channels=hostapd_constants.US_CHANNELS_5G[:-1],
862 test_channel_bandwidth=hostapd_constants.
863 CHANNEL_BANDWIDTH_80MHZ,
864 test_security=hostapd_constants.WPA_STRING,
865 base_test_name=self.test_name,
866 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
867 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
868 max_std_dev=self._get_max_std_dev(self.test_name)))
869
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000870 # 36 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000871 def test_us_20mhz_wpa2_channel_performance(self):
872 self.run_channel_performance_tests(
873 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
874 hostapd_constants.US_CHANNELS_5G,
875 test_channel_bandwidth=hostapd_constants.
876 CHANNEL_BANDWIDTH_20MHZ,
877 test_security=hostapd_constants.WPA2_STRING,
878 base_test_name=self.test_name,
879 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
880 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
881 max_std_dev=self._get_max_std_dev(self.test_name)))
882
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000883 # 35 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000884 def test_us_40mhz_wpa2_channel_performance(self):
885 self.run_channel_performance_tests(
886 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
887 hostapd_constants.US_CHANNELS_5G[:-1],
888 test_channel_bandwidth=hostapd_constants.
889 CHANNEL_BANDWIDTH_40MHZ,
890 test_security=hostapd_constants.WPA2_STRING,
891 base_test_name=self.test_name,
892 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
893 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
894 max_std_dev=self._get_max_std_dev(self.test_name)))
895
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000896 # 24 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000897 def test_us_80mhz_wpa2_channel_performance(self):
898 self.run_channel_performance_tests(
899 dict(test_channels=hostapd_constants.US_CHANNELS_5G[:-1],
900 test_channel_bandwidth=hostapd_constants.
901 CHANNEL_BANDWIDTH_80MHZ,
902 test_security=hostapd_constants.WPA2_STRING,
903 base_test_name=self.test_name,
904 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
905 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
906 max_std_dev=self._get_max_std_dev(self.test_name)))
907
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000908 # 36 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000909 def test_us_20mhz_wpa_wpa2_channel_performance(self):
910 self.run_channel_performance_tests(
911 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
912 hostapd_constants.US_CHANNELS_5G,
913 test_channel_bandwidth=hostapd_constants.
914 CHANNEL_BANDWIDTH_20MHZ,
915 test_security=hostapd_constants.WPA_MIXED_STRING,
916 base_test_name=self.test_name,
917 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
918 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
919 max_std_dev=self._get_max_std_dev(self.test_name)))
920
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000921 # 35 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000922 def test_us_40mhz_wpa_wpa2_channel_performance(self):
923 self.run_channel_performance_tests(
924 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
925 hostapd_constants.US_CHANNELS_5G[:-1],
926 test_channel_bandwidth=hostapd_constants.
927 CHANNEL_BANDWIDTH_40MHZ,
928 test_security=hostapd_constants.WPA_MIXED_STRING,
929 base_test_name=self.test_name,
930 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
931 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
932 max_std_dev=self._get_max_std_dev(self.test_name)))
933
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000934 # 24 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000935 def test_us_80mhz_wpa_wpa2_channel_performance(self):
936 self.run_channel_performance_tests(
937 dict(test_channels=hostapd_constants.US_CHANNELS_5G[:-1],
938 test_channel_bandwidth=hostapd_constants.
939 CHANNEL_BANDWIDTH_80MHZ,
940 test_security=hostapd_constants.WPA_MIXED_STRING,
941 base_test_name=self.test_name,
942 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
943 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
944 max_std_dev=self._get_max_std_dev(self.test_name)))
945
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000946 # 36 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000947 def test_us_20mhz_wpa3_channel_performance(self):
948 self.run_channel_performance_tests(
949 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
950 hostapd_constants.US_CHANNELS_5G,
951 test_channel_bandwidth=hostapd_constants.
952 CHANNEL_BANDWIDTH_20MHZ,
953 test_security=hostapd_constants.WPA3_STRING,
954 base_test_name=self.test_name,
955 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
956 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
957 max_std_dev=self._get_max_std_dev(self.test_name)))
958
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000959 # 35 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000960 def test_us_40mhz_wpa3_channel_performance(self):
961 self.run_channel_performance_tests(
962 dict(test_channels=hostapd_constants.US_CHANNELS_2G +
963 hostapd_constants.US_CHANNELS_5G[:-1],
964 test_channel_bandwidth=hostapd_constants.
965 CHANNEL_BANDWIDTH_40MHZ,
966 test_security=hostapd_constants.WPA3_STRING,
967 base_test_name=self.test_name,
968 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
969 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
970 max_std_dev=self._get_max_std_dev(self.test_name)))
971
Hayden Nix6f3d71c2020-05-20 00:10:39 +0000972 # 24 Test Cases
Hayden Nixc8a02bf2020-04-14 19:12:34 +0000973 def test_us_80mhz_wpa3_channel_performance(self):
974 self.run_channel_performance_tests(
975 dict(test_channels=hostapd_constants.US_CHANNELS_5G[:-1],
976 test_channel_bandwidth=hostapd_constants.
977 CHANNEL_BANDWIDTH_80MHZ,
978 test_security=hostapd_constants.WPA3_STRING,
979 base_test_name=self.test_name,
980 min_tx_throughput=self._get_min_tx_throughput(self.test_name),
981 min_rx_throughput=self._get_min_rx_throughput(self.test_name),
982 max_std_dev=self._get_max_std_dev(self.test_name)))
983
984 def test_channel_performance_debug(self):
985 """Run channel performance test cases from the ACTS config file.
986
987 Example:
988 "channel_sweep_test_params": {
989 "debug_channel_performance_tests": [
990 {
991 "test_name": "test_123_20mhz_wpa2_performance"
992 "test_channels": [1, 2, 3],
993 "test_channel_bandwidth": 20,
994 "test_security": "wpa2",
995 "base_test_name": "test_123_perf",
996 "min_tx_throughput": 1.1,
997 "min_rx_throughput": 3,
998 "max_std_dev": 0.5
999 },
1000 ...
1001 ]
1002 }
1003
Hayden Nix3f2eebf2020-01-14 10:39:21 -08001004 """
Hayden Nixc8a02bf2020-04-14 19:12:34 +00001005 asserts.skip_if(
Hayden Nix7a69a4d2020-08-05 18:42:27 +00001006 'debug_channel_performance_tests'
1007 not in self.user_params.get('channel_sweep_test_params', {}),
Hayden Nixc8a02bf2020-04-14 19:12:34 +00001008 'No custom channel performance tests provided in config.')
1009 base_tests = self.user_params['channel_sweep_test_params'][
1010 'debug_channel_performance_tests']
1011 self.run_generated_testcases(self.run_channel_performance_tests,
1012 settings=base_tests,
1013 name_func=get_test_name)
Hayden Nix484f48c2020-04-14 20:54:17 +00001014
1015 def test_regulatory_compliance(self):
1016 """Run regulatory compliance test case from the ACTS config file.
1017 Note: only one country_name OR country_code is required.
1018
1019 Example:
1020 "channel_sweep_test_params": {
1021 "regulatory_compliance_tests": [
1022 {
1023 "test_name": "test_japan_compliance_1_13_36"
1024 "country_name": "JAPAN",
1025 "country_code": "JP",
1026 "test_channels": {
1027 "1": [20, 40], "13": [40], "36": [20, 40, 80]
1028 },
1029 "allowed_channels": {
1030 "1": [20, 40], "36": [20, 40, 80]
1031 },
1032 "base_test_name": "test_japan"
1033 },
1034 ...
1035 ]
1036 }
1037 """
1038 asserts.skip_if(
Hayden Nix7a69a4d2020-08-05 18:42:27 +00001039 'regulatory_compliance_tests'
1040 not in self.user_params.get('channel_sweep_test_params', {}),
Hayden Nix484f48c2020-04-14 20:54:17 +00001041 'No custom regulatory compliance tests provided in config.')
1042 base_tests = self.user_params['channel_sweep_test_params'][
1043 'regulatory_compliance_tests']
1044 self.run_generated_testcases(self.verify_regulatory_compliance,
1045 settings=base_tests,
1046 name_func=get_test_name)