1 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import logging 6 import time 7 8 from autotest_lib.client.common_lib import error 9 from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes 10 from autotest_lib.server.cros.network import netperf_runner 11 from autotest_lib.server.cros.network import netperf_session 12 from autotest_lib.server.cros.network import wifi_cell_test_base 13 14 15 class network_WiFi_Perf(wifi_cell_test_base.WiFiCellTestBase): 16 """Test maximal achievable bandwidth on several channels per band. 17 18 Conducts a performance test for a set of specified router configurations 19 and reports results as keyval pairs. 20 21 """ 22 23 version = 1 24 25 NETPERF_CONFIGS = [ 26 netperf_runner.NetperfConfig( 27 netperf_runner.NetperfConfig.TEST_TYPE_TCP_STREAM), 28 netperf_runner.NetperfConfig( 29 netperf_runner.NetperfConfig.TEST_TYPE_TCP_MAERTS), 30 netperf_runner.NetperfConfig( 31 netperf_runner.NetperfConfig.TEST_TYPE_UDP_STREAM), 32 netperf_runner.NetperfConfig( 33 netperf_runner.NetperfConfig.TEST_TYPE_UDP_MAERTS), 34 ] 35 36 37 def parse_additional_arguments(self, commandline_args, additional_params): 38 """Hook into super class to take control files parameters. 39 40 @param commandline_args dict of parsed parameters from the autotest. 41 @param additional_params list of HostapConfig objects. 42 43 """ 44 self._ap_configs = additional_params 45 46 47 def do_run(self, ap_config, session, power_save): 48 """Run a single set of perf tests, for a given AP and DUT config. 49 50 @param ap_config: the AP configuration that is being used 51 @param session: a netperf session instance 52 @param power_save: whether or not to use power-save mode on the DUT 53 (boolean) 54 55 """ 56 self.context.client.powersave_switch(power_save) 57 session.warmup_stations() 58 ps_tag = 'PS%s' % ('on' if power_save else 'off') 59 ap_config_tag = '_'.join([ap_config.perf_loggable_description, 60 ps_tag]) 61 signal_level = self.context.client.wifi_signal_level 62 signal_description = '_'.join([ap_config_tag, 'signal']) 63 self.write_perf_keyval({signal_description: signal_level}) 64 for config in self.NETPERF_CONFIGS: 65 results = session.run(config) 66 if not results: 67 logging.error('Failed to take measurement for %s', 68 config.tag) 69 continue 70 values = [result.throughput for result in results] 71 self.output_perf_value(config.tag, values, units='Mbps', 72 higher_is_better=True, 73 graph=ap_config_tag) 74 result = netperf_runner.NetperfResult.from_samples(results) 75 self.write_perf_keyval(result.get_keyval( 76 prefix='_'.join([ap_config_tag, config.tag]))) 77 78 79 def run_once(self): 80 """Test body.""" 81 start_time = time.time() 82 for ap_config in self._ap_configs: 83 # Set up the router and associate the client with it. 84 self.context.configure(ap_config) 85 if ap_config.is_11ac and not self.context.client.is_vht_supported(): 86 raise error.TestNAError('Client does not have AC support') 87 assoc_params = xmlrpc_datatypes.AssociationParameters( 88 ssid=self.context.router.get_ssid(), 89 security_config=ap_config.security_config) 90 self.context.assert_connect_wifi(assoc_params) 91 session = netperf_session.NetperfSession(self.context.client, 92 self.context.router) 93 94 # Flag a test error if we disconnect for any reason. 95 with self.context.client.assert_no_disconnects(): 96 # Conduct the performance tests while toggling powersave mode. 97 for power_save in (True, False): 98 self.do_run(ap_config, session, power_save) 99 100 # Clean up router and client state for the next run. 101 self.context.client.shill.disconnect(self.context.router.get_ssid()) 102 self.context.router.deconfig() 103 end_time = time.time() 104 logging.info('Running time %0.1f seconds.', end_time - start_time) 105