blob: 5f3b9b9b1d920ec5bad754abb5d7f59f6e297a22 [file] [log] [blame]
Christopher Wileye740d582013-05-08 09:33:31 -07001# 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
Eric Caruso16a21dd2014-12-17 14:42:14 -08005import logging
6
7from autotest_lib.client.common_lib import utils
Samuel Tan80afd242015-06-25 12:31:39 -07008from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
Eric Caruso16a21dd2014-12-17 14:42:14 -08009from autotest_lib.server import test
Christopher Wileye4e8d992013-07-09 16:11:29 -070010from autotest_lib.server.cros.network import wifi_test_context_manager
Christopher Wileye740d582013-05-08 09:33:31 -070011
Eric Caruso16a21dd2014-12-17 14:42:14 -080012class WiFiCellTestBase(test.test):
Christopher Wileye740d582013-05-08 09:33:31 -070013 """An abstract base class for autotests in WiFi cells.
14
15 WiFiCell tests refer to participants in the test as client, router, and
16 server. The client is just the DUT and the router is a nearby AP which we
17 configure in various ways to test the ability of the client to connect.
18 There is a third entity called a server which is distinct from the autotest
19 server. In WiFiTests, the server is a host which the client can only talk
20 to over the WiFi network.
21
22 WiFiTests have a notion of the control network vs the WiFi network. The
23 control network refers to the network between the machine running the
24 autotest server and the various machines involved in the test. The WiFi
25 network is the subnet(s) formed by WiFi routers between the server and the
26 client.
27
28 """
29
Eric Caruso16a21dd2014-12-17 14:42:14 -080030 @property
31 def context(self):
32 """@return the WiFi context for this test."""
33 return self._wifi_context
Christopher Wileye740d582013-05-08 09:33:31 -070034
Eric Caruso16a21dd2014-12-17 14:42:14 -080035
36 def parse_additional_arguments(self, commandline_args, additional_params):
37 """Parse additional arguments for use in test.
38
39 Subclasses should override this method do any other commandline parsing
40 and setting grabbing that they need to do. For test clarity, do not
41 parse additional settings in the body of run_once.
42
43 @param commandline_args dict of argument key, value pairs.
44 @param additional_params object defined by test control file.
Christopher Wileye740d582013-05-08 09:33:31 -070045
46 """
Eric Caruso16a21dd2014-12-17 14:42:14 -080047 pass
48
49
50 def warmup(self, host, raw_cmdline_args, additional_params=None):
51 """
52 Use the additional_params argument to pass in custom test data from
53 control file to reuse test logic. This object will be passed down via
54 parse_additional_arguments.
55
56 @param host host object representing the client DUT.
57 @param raw_cmdline_args raw input from autotest.
58 @param additional_params object passed in from control file.
59
60 """
61 cmdline_args = utils.args_to_dict(raw_cmdline_args)
62 logging.info('Running wifi test with commandline arguments: %r',
63 cmdline_args)
64 self._wifi_context = wifi_test_context_manager.WiFiTestContextManager(
Christopher Wileye740d582013-05-08 09:33:31 -070065 self.__class__.__name__,
66 host,
67 cmdline_args,
68 self.debugdir)
Eric Caruso16a21dd2014-12-17 14:42:14 -080069
70 self._wifi_context.setup()
71 self.parse_additional_arguments(cmdline_args, additional_params)
72
Filipe Brandenburgera9367ad2015-08-27 12:34:32 -070073 msg = '======= WiFi autotest setup complete. Starting test... ======='
74 self._wifi_context.client.shill_debug_log(msg)
Samuel Tan37dcc882015-06-12 01:38:28 -070075
Eric Caruso16a21dd2014-12-17 14:42:14 -080076
77 def cleanup(self):
Filipe Brandenburgera9367ad2015-08-27 12:34:32 -070078 msg = '======= WiFi autotest complete. Cleaning up... ======='
79 self._wifi_context.client.shill_debug_log(msg)
Eric Caruso16a21dd2014-12-17 14:42:14 -080080 # If we fail during initialization, we might not have a context.
81 if hasattr(self, '_wifi_context'):
82 self._wifi_context.teardown()
Samuel Tan80afd242015-06-25 12:31:39 -070083
84
Kirtika Ruchandania4b1a6b2018-05-17 11:41:44 -070085 def configure_and_connect_to_ap(self, ap_config):
Samuel Tan80afd242015-06-25 12:31:39 -070086 """
Kirtika Ruchandania4b1a6b2018-05-17 11:41:44 -070087 Configure the router as an AP with the given config and connect
Samuel Tan80afd242015-06-25 12:31:39 -070088 the DUT to it.
89
Kirtika Ruchandania4b1a6b2018-05-17 11:41:44 -070090 @param ap_config HostapConfig object.
Samuel Tan80afd242015-06-25 12:31:39 -070091
92 @return name of the configured AP
93 """
Kirtika Ruchandania4b1a6b2018-05-17 11:41:44 -070094 self.context.configure(ap_config)
Samuel Tan80afd242015-06-25 12:31:39 -070095 ap_ssid = self.context.router.get_ssid()
96 assoc_params = xmlrpc_datatypes.AssociationParameters(ssid=ap_ssid)
97 self.context.assert_connect_wifi(assoc_params)
98 return ap_ssid