• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 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.cros.chameleon import chameleon_audio_helper
10from autotest_lib.server import site_utils
11from autotest_lib.server import test
12from autotest_lib.server.cros.multimedia import remote_facade_factory
13from autotest_lib.site_utils import lxc
14
15
16class AudioTest(test.test):
17    """Base class for audio tests.
18
19    AudioTest provides basic initialization, setup and warmup check for the
20    collection of server side audio tests. It is assumed to be run with a
21    Chameleon audio boards. It is recommended to use this base class for server
22    side Chameleon audio tests to take advantage of the initialize, setup and
23    sanity check.
24    """
25
26    def initialize(self, host):
27        """Initialize audio test needed components and do some sanity checks"""
28        if host.chameleon is None:
29            raise error.TestError("host.chameleon is None."
30                                  "Please check the chameleon of this DUT.")
31
32        self.host = host
33        self.factory = remote_facade_factory.RemoteFacadeFactory(
34            host, results_dir=self.resultsdir)
35        self.widget_factory = chameleon_audio_helper.AudioWidgetFactory(
36            self.factory, self.host)
37        self.facade = self.factory.create_audio_facade()
38        host.chameleon.setup_and_reset(self.resultsdir)
39
40    def setup(self):
41        """Setup needed audio test requirement before executing main logic."""
42        super(AudioTest, self).setup()
43        audio_test_requirement()
44
45    def warmup(self):
46        """Warmup for the test before executing main logic of the test."""
47        # test.test is an old-style class.
48        test.test.warmup(self)
49
50
51def audio_test_requirement():
52    """Installs sox and checks it is installed correctly."""
53    install_sox()
54    check_sox_installed()
55
56
57def install_sox():
58    """Install sox command on autotest drone."""
59    try:
60        lxc.install_packages(packages=['sox'])
61    except error.ContainerError:
62        logging.info('Can not install sox outside of container.')
63
64
65def check_sox_installed():
66    """Checks if sox is installed.
67
68    @raises: error.TestError if sox is not installed.
69
70    """
71    try:
72        utils.run('sox --help')
73        logging.info('Found sox executable.')
74    except error.CmdError:
75        error_message = 'sox command is not installed.'
76        if site_utils.is_inside_chroot():
77            error_message += ' sudo emerge sox to install sox in chroot'
78        raise error.TestError(error_message)
79