• 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.server import site_utils
10from autotest_lib.server import test
11from autotest_lib.site_utils import lxc
12
13
14class AudioTest(test.test):
15    """Base class for audio tests.
16
17    AudioTest provides a common warmup() function for the collection
18    of audio tests.
19    It is not mandatory to use this base class for audio tests, it is for
20    convenience only.
21
22    """
23
24    def warmup(self):
25        """Warmup for the test before executing main logic of the test."""
26        # test.test is an old-style class.
27        test.test.warmup(self)
28        audio_test_requirement()
29
30
31def audio_test_requirement():
32    """Installs sox and checks it is installed correctly."""
33    install_sox()
34    check_sox_installed()
35
36
37def install_sox():
38    """Install sox command on autotest drone."""
39    try:
40        lxc.install_package('sox')
41    except error.ContainerError:
42        logging.info('Can not install sox outside of container.')
43
44
45def check_sox_installed():
46    """Checks if sox is installed.
47
48    @raises: error.TestError if sox is not installed.
49
50    """
51    try:
52        utils.run('sox --help')
53        logging.info('Found sox executable.')
54    except error.CmdError:
55        error_message = 'sox command is not installed.'
56        if site_utils.is_inside_chroot():
57            error_message += ' sudo emerge sox to install sox in chroot'
58        raise error.TestError(error_message)
59