blob: 3402c6a433622551a592c8f09795b43f9b33d48f [file] [log] [blame]
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
from autotest_lib.client.bin import utils
from autotest_lib.client.common_lib import utils
from autotest_lib.client.cros import constants
from autotest_lib.server import frontend
from autotest_lib.server import site_utils
from autotest_lib.server import test
from autotest_lib.server.cros.network import wifi_test_context_manager
class WiFiCellTestBase(test.test):
"""An abstract base class for autotests in WiFi cells.
WiFiCell tests refer to participants in the test as client, router, and
server. The client is just the DUT and the router is a nearby AP which we
configure in various ways to test the ability of the client to connect.
There is a third entity called a server which is distinct from the autotest
server. In WiFiTests, the server is a host which the client can only talk
to over the WiFi network.
WiFiTests have a notion of the control network vs the WiFi network. The
control network refers to the network between the machine running the
autotest server and the various machines involved in the test. The WiFi
network is the subnet(s) formed by WiFi routers between the server and the
client.
"""
def initialize(self, host):
if utils.host_could_be_in_afe(host.hostname):
# There are some DUTs that have different types of wifi modules.
# In order to generate separate performance graphs, a variant
# name is needed. Writing this key will generate results with
# the name of <board>-<variant>.
afe = frontend.AFE(debug=True)
variant_name = site_utils.get_label_from_afe(host.hostname,
'variant:',
afe)
if variant_name:
self.write_test_keyval({constants.VARIANT_KEY: variant_name})
@property
def context(self):
"""@return the WiFi context for this test."""
return self._wifi_context
def parse_additional_arguments(self, commandline_args, additional_params):
"""Parse additional arguments for use in test.
Subclasses should override this method do any other commandline parsing
and setting grabbing that they need to do. For test clarity, do not
parse additional settings in the body of run_once.
@param commandline_args dict of argument key, value pairs.
@param additional_params object defined by test control file.
"""
pass
def warmup(self, host, raw_cmdline_args, additional_params=None):
"""
Use the additional_params argument to pass in custom test data from
control file to reuse test logic. This object will be passed down via
parse_additional_arguments.
@param host host object representing the client DUT.
@param raw_cmdline_args raw input from autotest.
@param additional_params object passed in from control file.
"""
cmdline_args = utils.args_to_dict(raw_cmdline_args)
logging.info('Running wifi test with commandline arguments: %r',
cmdline_args)
self._wifi_context = wifi_test_context_manager.WiFiTestContextManager(
self.__class__.__name__,
host,
cmdline_args,
self.debugdir)
self._wifi_context.setup()
self.parse_additional_arguments(cmdline_args, additional_params)
def cleanup(self):
# If we fail during initialization, we might not have a context.
if hasattr(self, '_wifi_context'):
self._wifi_context.teardown()