• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5import logging
6
7from autotest_lib.client.bin import utils
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.common_lib import utils
10from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
11from autotest_lib.client.cros import constants
12from autotest_lib.server import test
13from autotest_lib.site_utils import lxc
14from autotest_lib.server.cros.network import wifi_test_context_manager
15
16class WiFiCellTestBase(test.test):
17    """An abstract base class for autotests in WiFi cells.
18
19    WiFiCell tests refer to participants in the test as client, router, and
20    server.  The client is just the DUT and the router is a nearby AP which we
21    configure in various ways to test the ability of the client to connect.
22    There is a third entity called a server which is distinct from the autotest
23    server.  In WiFiTests, the server is a host which the client can only talk
24    to over the WiFi network.
25
26    WiFiTests have a notion of the control network vs the WiFi network.  The
27    control network refers to the network between the machine running the
28    autotest server and the various machines involved in the test.  The WiFi
29    network is the subnet(s) formed by WiFi routers between the server and the
30    client.
31
32    """
33
34    def initialize(self, host):
35        if utils.host_could_be_in_afe(host.hostname):
36            # There are some DUTs that have different types of wifi modules.
37            # In order to generate separate performance graphs, a variant
38            # name is needed.  Writing this key will generate results with
39            # the name of <board>-<variant>.
40            info = host.host_info_store.get()
41            variant_name = info.get_label_value('variant')
42            if variant_name:
43                self.write_test_keyval({constants.VARIANT_KEY: variant_name})
44
45    @property
46    def context(self):
47        """@return the WiFi context for this test."""
48        return self._wifi_context
49
50
51    def parse_additional_arguments(self, commandline_args, additional_params):
52        """Parse additional arguments for use in test.
53
54        Subclasses should override this method do any other commandline parsing
55        and setting grabbing that they need to do.  For test clarity, do not
56        parse additional settings in the body of run_once.
57
58        @param commandline_args dict of argument key, value pairs.
59        @param additional_params object defined by test control file.
60
61        """
62        pass
63
64
65    def warmup(self, host, raw_cmdline_args, additional_params=None):
66        """
67        Use the additional_params argument to pass in custom test data from
68        control file to reuse test logic.  This object will be passed down via
69        parse_additional_arguments.
70
71        @param host host object representing the client DUT.
72        @param raw_cmdline_args raw input from autotest.
73        @param additional_params object passed in from control file.
74
75        """
76        cmdline_args = utils.args_to_dict(raw_cmdline_args)
77        logging.info('Running wifi test with commandline arguments: %r',
78                     cmdline_args)
79        self._wifi_context = wifi_test_context_manager.WiFiTestContextManager(
80                self.__class__.__name__,
81                host,
82                cmdline_args,
83                self.debugdir)
84
85        self._wifi_context.setup()
86        self.parse_additional_arguments(cmdline_args, additional_params)
87
88        msg = '======= WiFi autotest setup complete. Starting test... ======='
89        self._wifi_context.client.shill_debug_log(msg)
90
91
92    def cleanup(self):
93        msg = '======= WiFi autotest complete. Cleaning up... ======='
94        self._wifi_context.client.shill_debug_log(msg)
95        # If we fail during initialization, we might not have a context.
96        if hasattr(self, '_wifi_context'):
97            self._wifi_context.teardown()
98
99
100    def configure_and_connect_to_ap(self, configuration_parameters):
101        """
102        Configure the router as an AP with the given parameters and connect
103        the DUT to it.
104
105        @param configuration_parameters HostapConfig object.
106
107        @return name of the configured AP
108        """
109        self.context.configure(configuration_parameters)
110        ap_ssid = self.context.router.get_ssid()
111        assoc_params = xmlrpc_datatypes.AssociationParameters(ssid=ap_ssid)
112        self.context.assert_connect_wifi(assoc_params)
113        return ap_ssid
114