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 from autotest_lib.client.common_lib import error 6 from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes 7 from autotest_lib.server.cros import stress 8 from autotest_lib.server.cros.network import wifi_cell_test_base 9 10 _DELAY = 10 11 _START_TIMEOUT_SECONDS = 20 12 13 14 class network_WiFi_SuspendStress(wifi_cell_test_base.WiFiCellTestBase): 15 """Test suspend and resume with powerd_dbus_suspend command and assert wifi 16 connectivity to router. 17 """ 18 version = 1 19 20 21 def parse_additional_arguments(self, commandline_args, additional_params): 22 """Hook into super class to take control files parameters. 23 24 @param commandline_args dict of parsed parameters from the autotest. 25 @param additional_params list of tuple(HostapConfig, 26 AssociationParameters). 27 """ 28 self._configurations = additional_params 29 30 31 def stress_wifi_suspend(self): 32 """ Perform the suspend stress.""" 33 34 boot_id = self._host.get_boot_id() 35 self.context.client.do_suspend(_DELAY) 36 self._host.test_wait_for_resume(boot_id) 37 state_info = self.context.wait_for_connection( 38 self.context.router.get_ssid()) 39 self._timings.append(state_info.time) 40 41 42 def run_once(self, suspends=5): 43 """Run suspend stress test. 44 45 @param suspends: Number of suspend iterations 46 47 """ 48 self._host = self.context.client.host 49 50 for router_conf, client_conf in self._configurations: 51 self.context.configure(ap_config=router_conf) 52 assoc_params = xmlrpc_datatypes.AssociationParameters( 53 is_hidden=client_conf.is_hidden, 54 security_config=client_conf.security_config, 55 ssid=self.context.router.get_ssid()) 56 self.context.assert_connect_wifi(assoc_params) 57 self._timings = list() 58 59 stressor = stress.CountedStressor(self.stress_wifi_suspend) 60 61 stressor.start(suspends) 62 stressor.wait() 63 64 perf_dict = {'fastest': max(self._timings), 65 'slowest': min(self._timings), 66 'average': (float(sum(self._timings)) / 67 len(self._timings))} 68 for key in perf_dict: 69 self.output_perf_value(description=key, 70 value=perf_dict[key], 71 units='seconds', 72 higher_is_better=False, 73 graph=router_conf.perf_loggable_description) 74 75 # Explicitly disconnect and clear the shill profile, in case 76 # we're running another configuration after this. Especially on 77 # Hidden tests, the DUT may still think it can connect to 78 # previously-discovered networks, causing extra connection failures 79 # and delays along the way. 80 self.context.client.shill.disconnect(client_conf.ssid) 81 if not self.context.client.shill.init_test_network_state(): 82 raise error.TestError('Failed to set up shill profile.') 83