Cheng-Yi Chiang | 5187657 | 2015-05-22 15:12:02 +0800 | [diff] [blame^] | 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 | |
| 5 | import logging |
| 6 | |
| 7 | from autotest_lib.client.bin import utils |
| 8 | from autotest_lib.client.common_lib import error |
| 9 | from autotest_lib.server import site_utils |
| 10 | from autotest_lib.server import test |
| 11 | from autotest_lib.site_utils import lxc |
| 12 | |
| 13 | |
| 14 | class 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 | self.install_sox() |
| 29 | self.check_sox_installed() |
| 30 | |
| 31 | |
| 32 | def install_sox(self): |
| 33 | """Install sox command on autotest drone.""" |
| 34 | try: |
| 35 | lxc.install_package('sox') |
| 36 | except error.ContainerError: |
| 37 | logging.info('Can not install sox outside of container.') |
| 38 | |
| 39 | |
| 40 | def check_sox_installed(self): |
| 41 | """Checks if sox is installed. |
| 42 | |
| 43 | @raises: error.TestError if sox is not installed. |
| 44 | |
| 45 | """ |
| 46 | try: |
| 47 | utils.run('sox --help') |
| 48 | logging.info('Found sox executable.') |
| 49 | except error.CmdError: |
| 50 | error_message = 'sox command is not installed.' |
| 51 | if site_utils.is_inside_chroot(): |
| 52 | error_message += ' sudo emerge sox to install sox in chroot' |
| 53 | raise error.TestError(error_message) |