1# Lint as: python2, python3 2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import logging 7 8from autotest_lib.client.common_lib import utils 9from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes 10from autotest_lib.server import test 11from autotest_lib.server.cros.network import wifi_test_context_manager 12 13class WiFiCellTestBase(test.test): 14 """An abstract base class for autotests in WiFi cells. 15 16 WiFiCell tests refer to participants in the test as client, router, and 17 server. The client is just the DUT and the router is a nearby AP which we 18 configure in various ways to test the ability of the client to connect. 19 There is a third entity called a server which is distinct from the autotest 20 server. In WiFiTests, the server is a host which the client can only talk 21 to over the WiFi network. 22 23 WiFiTests have a notion of the control network vs the WiFi network. The 24 control network refers to the network between the machine running the 25 autotest server and the various machines involved in the test. The WiFi 26 network is the subnet(s) formed by WiFi routers between the server and the 27 client. 28 29 """ 30 31 @property 32 def context(self): 33 """@return the WiFi context for this test.""" 34 return self._wifi_context 35 36 37 def parse_additional_arguments(self, commandline_args, additional_params): 38 """Parse additional arguments for use in test. 39 40 Subclasses should override this method do any other commandline parsing 41 and setting grabbing that they need to do. For test clarity, do not 42 parse additional settings in the body of run_once. 43 44 @param commandline_args dict of argument key, value pairs. 45 @param additional_params object defined by test control file. 46 47 """ 48 pass 49 50 51 def warmup(self, host, raw_cmdline_args, additional_params=None, 52 pcap_as_router=False): 53 """ 54 Use the additional_params argument to pass in custom test data from 55 control file to reuse test logic. This object will be passed down via 56 parse_additional_arguments. 57 58 @param host host object representing the client DUT. 59 @param raw_cmdline_args raw input from autotest. 60 @param additional_params object passed in from control file. 61 @param pcap_as_router True if the test requires the pcap to be 62 configured as a router. 63 64 """ 65 cmdline_args = utils.args_to_dict(raw_cmdline_args) 66 logging.info('Running wifi test with commandline arguments: %r', 67 cmdline_args) 68 self._wifi_context = wifi_test_context_manager.WiFiTestContextManager( 69 self.__class__.__name__, 70 host, 71 cmdline_args, 72 self.debugdir) 73 74 self._wifi_context.setup(pcap_as_router=pcap_as_router) 75 self._verify_additional_setup_requirements() 76 self.parse_additional_arguments(cmdline_args, additional_params) 77 78 msg = '======= WiFi autotest setup complete. Starting test... =======' 79 self._wifi_context.client.shill_debug_log(msg) 80 81 82 def cleanup(self): 83 msg = '======= WiFi autotest complete. Cleaning up... =======' 84 self._wifi_context.client.shill_debug_log(msg) 85 # If we fail during initialization, we might not have a context. 86 if hasattr(self, '_wifi_context'): 87 self._wifi_context.teardown() 88 89 90 def configure_and_connect_to_ap(self, ap_config): 91 """ 92 Configure the router as an AP with the given config and connect 93 the DUT to it. 94 95 @param ap_config HostapConfig object. 96 97 @return name of the configured AP 98 """ 99 self.context.configure(ap_config) 100 ap_ssid = self.context.router.get_ssid() 101 assoc_params = xmlrpc_datatypes.AssociationParameters( 102 ssid=ap_ssid, security_config=ap_config.security_config) 103 self.context.assert_connect_wifi(assoc_params) 104 return ap_ssid 105 106 def _verify_additional_setup_requirements(self): 107 """Subclasses can override this method to do any additional checking 108 of the physical testing setup that they require. 109 """ 110 pass 111