1 # Copyright 2015 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 9 from autotest_lib.client.common_lib import error 10 from autotest_lib.client.common_lib.cros.network import ping_runner 11 from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes 12 from autotest_lib.server.cros.network import netperf_runner 13 from autotest_lib.server.cros.network import netperf_session 14 from autotest_lib.server.cros.network import wifi_cell_test_base 15 from autotest_lib.server.cros.bluetooth import bluetooth_device 16 17 18 class network_WiFi_BluetoothScanPerf(wifi_cell_test_base.WiFiCellTestBase): 19 """Test the effect of bluetooth scanning on wifi performance. 20 21 Conducts a performance test for a set of specified router configurations 22 while scanning for bluetooth devices and reports results as keyval pairs. 23 24 """ 25 26 version = 1 27 28 NETPERF_CONFIGS = [ 29 netperf_runner.NetperfConfig( 30 netperf_runner.NetperfConfig.TEST_TYPE_TCP_STREAM), 31 netperf_runner.NetperfConfig( 32 netperf_runner.NetperfConfig.TEST_TYPE_TCP_MAERTS), 33 netperf_runner.NetperfConfig( 34 netperf_runner.NetperfConfig.TEST_TYPE_UDP_STREAM), 35 netperf_runner.NetperfConfig( 36 netperf_runner.NetperfConfig.TEST_TYPE_UDP_MAERTS), 37 ] 38 39 40 def parse_additional_arguments(self, commandline_args, additional_params): 41 """Hook into super class to take control files parameters. 42 43 @param commandline_args dict of parsed parameters from the autotest. 44 @param additional_params list of HostapConfig objects. 45 46 """ 47 self._ap_configs = additional_params 48 49 50 def test_one(self, session, config, ap_config_tag, bt_tag): 51 """Run one iteration of wifi testing. 52 53 @param session NetperfSession session 54 @param config NetperfConfig config 55 @param ap_config_tag string for AP configuration 56 @param bt_tag string for BT operation 57 58 """ 59 get_ping_config = lambda period: ping_runner.PingConfig( 60 self.context.get_wifi_addr(), interval=1, count=period) 61 62 logging.info('testing config %s, ap_config %s, BT:%s', 63 config.tag, ap_config_tag, bt_tag) 64 test_str = '_'.join([ap_config_tag, bt_tag]) 65 time.sleep(1) 66 67 signal_level = self.context.client.wifi_signal_level 68 signal_description = '_'.join(['signal', test_str]) 69 self.write_perf_keyval({signal_description: signal_level}) 70 71 results = session.run(config) 72 if not results: 73 logging.error('Failed to take measurement for %s', 74 config.tag) 75 return 76 values = [result.throughput for result in results] 77 self.output_perf_value(config.tag + ' ' + bt_tag, values, units='Mbps', 78 higher_is_better=True, 79 graph=ap_config_tag) 80 result = netperf_runner.NetperfResult.from_samples(results) 81 self.write_perf_keyval(result.get_keyval( 82 prefix='_'.join([config.tag, test_str]))) 83 84 # Test latency with ping. 85 result_ping = self.context.client.ping(get_ping_config(3)) 86 self.write_perf_keyval( 87 { '_'.join(['ping', test_str]): result_ping.avg_latency }) 88 logging.info('Ping statistics with %s: %r', bt_tag, result_ping) 89 90 91 92 def run_once(self, host): 93 """Test body.""" 94 start_time = time.time() 95 96 # Prepare Bluetooth to scan, but do not start yet. 97 bt_device = bluetooth_device.BluetoothDevice(host) 98 if not bt_device.reset_on(): 99 raise error.TestFail('DUT could not be reset to initial state') 100 101 for ap_config in self._ap_configs: 102 # Set up the router and associate the client with it. 103 self.context.configure(ap_config) 104 if ap_config.is_11ac and not self.context.client.is_vht_supported(): 105 raise error.TestNAError('Client does not have AC support') 106 assoc_params = xmlrpc_datatypes.AssociationParameters( 107 ssid=self.context.router.get_ssid(), 108 security_config=ap_config.security_config) 109 self.context.assert_connect_wifi(assoc_params) 110 session = netperf_session.NetperfSession(self.context.client, 111 self.context.router) 112 113 # Warmup the wifi path and measure signal. 114 session.warmup_stations() 115 ap_config_tag = ap_config.perf_loggable_description 116 117 for config in self.NETPERF_CONFIGS: 118 self.test_one(session, config, ap_config_tag, 'BT_quiet') 119 if not bt_device.start_discovery(): 120 raise error.TestFail('Could not start discovery on DUT') 121 try: 122 self.test_one(session, config, ap_config_tag, 'BT_scanning') 123 finally: 124 if not bt_device.stop_discovery(): 125 logging.warning('Failed to stop discovery on DUT') 126 self.test_one(session, config, ap_config_tag, 'BT_quiet_again') 127 128 # Clean up router and client state for the next run. 129 self.context.client.shill.disconnect(self.context.router.get_ssid()) 130 self.context.router.deconfig() 131 132 end_time = time.time() 133 logging.info('Running time %0.1f seconds.', end_time - start_time) 134 135