Christopher Wiley | e740d58 | 2013-05-08 09:33:31 -0700 | [diff] [blame] | 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 | |
Eric Caruso | 16a21dd | 2014-12-17 14:42:14 -0800 | [diff] [blame] | 5 | import logging |
| 6 | |
| 7 | from autotest_lib.client.common_lib import utils |
Samuel Tan | 80afd24 | 2015-06-25 12:31:39 -0700 | [diff] [blame] | 8 | from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes |
Eric Caruso | 16a21dd | 2014-12-17 14:42:14 -0800 | [diff] [blame] | 9 | from autotest_lib.server import test |
Christopher Wiley | e4e8d99 | 2013-07-09 16:11:29 -0700 | [diff] [blame] | 10 | from autotest_lib.server.cros.network import wifi_test_context_manager |
Christopher Wiley | e740d58 | 2013-05-08 09:33:31 -0700 | [diff] [blame] | 11 | |
Eric Caruso | 16a21dd | 2014-12-17 14:42:14 -0800 | [diff] [blame] | 12 | class WiFiCellTestBase(test.test): |
Christopher Wiley | e740d58 | 2013-05-08 09:33:31 -0700 | [diff] [blame] | 13 | """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 Caruso | 16a21dd | 2014-12-17 14:42:14 -0800 | [diff] [blame] | 30 | @property |
| 31 | def context(self): |
| 32 | """@return the WiFi context for this test.""" |
| 33 | return self._wifi_context |
Christopher Wiley | e740d58 | 2013-05-08 09:33:31 -0700 | [diff] [blame] | 34 | |
Eric Caruso | 16a21dd | 2014-12-17 14:42:14 -0800 | [diff] [blame] | 35 | |
| 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 Wiley | e740d58 | 2013-05-08 09:33:31 -0700 | [diff] [blame] | 45 | |
| 46 | """ |
Eric Caruso | 16a21dd | 2014-12-17 14:42:14 -0800 | [diff] [blame] | 47 | 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 Wiley | e740d58 | 2013-05-08 09:33:31 -0700 | [diff] [blame] | 65 | self.__class__.__name__, |
| 66 | host, |
| 67 | cmdline_args, |
| 68 | self.debugdir) |
Eric Caruso | 16a21dd | 2014-12-17 14:42:14 -0800 | [diff] [blame] | 69 | |
| 70 | self._wifi_context.setup() |
| 71 | self.parse_additional_arguments(cmdline_args, additional_params) |
| 72 | |
Filipe Brandenburger | a9367ad | 2015-08-27 12:34:32 -0700 | [diff] [blame] | 73 | msg = '======= WiFi autotest setup complete. Starting test... =======' |
| 74 | self._wifi_context.client.shill_debug_log(msg) |
Samuel Tan | 37dcc88 | 2015-06-12 01:38:28 -0700 | [diff] [blame] | 75 | |
Eric Caruso | 16a21dd | 2014-12-17 14:42:14 -0800 | [diff] [blame] | 76 | |
| 77 | def cleanup(self): |
Filipe Brandenburger | a9367ad | 2015-08-27 12:34:32 -0700 | [diff] [blame] | 78 | msg = '======= WiFi autotest complete. Cleaning up... =======' |
| 79 | self._wifi_context.client.shill_debug_log(msg) |
Eric Caruso | 16a21dd | 2014-12-17 14:42:14 -0800 | [diff] [blame] | 80 | # If we fail during initialization, we might not have a context. |
| 81 | if hasattr(self, '_wifi_context'): |
| 82 | self._wifi_context.teardown() |
Samuel Tan | 80afd24 | 2015-06-25 12:31:39 -0700 | [diff] [blame] | 83 | |
| 84 | |
Kirtika Ruchandani | a4b1a6b | 2018-05-17 11:41:44 -0700 | [diff] [blame] | 85 | def configure_and_connect_to_ap(self, ap_config): |
Samuel Tan | 80afd24 | 2015-06-25 12:31:39 -0700 | [diff] [blame] | 86 | """ |
Kirtika Ruchandani | a4b1a6b | 2018-05-17 11:41:44 -0700 | [diff] [blame] | 87 | Configure the router as an AP with the given config and connect |
Samuel Tan | 80afd24 | 2015-06-25 12:31:39 -0700 | [diff] [blame] | 88 | the DUT to it. |
| 89 | |
Kirtika Ruchandani | a4b1a6b | 2018-05-17 11:41:44 -0700 | [diff] [blame] | 90 | @param ap_config HostapConfig object. |
Samuel Tan | 80afd24 | 2015-06-25 12:31:39 -0700 | [diff] [blame] | 91 | |
| 92 | @return name of the configured AP |
| 93 | """ |
Kirtika Ruchandani | a4b1a6b | 2018-05-17 11:41:44 -0700 | [diff] [blame] | 94 | self.context.configure(ap_config) |
Samuel Tan | 80afd24 | 2015-06-25 12:31:39 -0700 | [diff] [blame] | 95 | 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 |