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 |
Cheng-Yi Chiang | 30609a7 | 2015-10-22 11:11:40 +0800 | [diff] [blame] | 6 | import os |
Cheng-Yi Chiang | 5187657 | 2015-05-22 15:12:02 +0800 | [diff] [blame] | 7 | |
| 8 | from autotest_lib.client.bin import utils |
| 9 | from autotest_lib.client.common_lib import error |
Cheng-Yi Chiang | 30609a7 | 2015-10-22 11:11:40 +0800 | [diff] [blame] | 10 | from autotest_lib.client.cros import constants |
Cheng-Yi Chiang | 5187657 | 2015-05-22 15:12:02 +0800 | [diff] [blame] | 11 | from autotest_lib.server import site_utils |
| 12 | from autotest_lib.server import test |
Cheng-Yi Chiang | 30609a7 | 2015-10-22 11:11:40 +0800 | [diff] [blame] | 13 | from autotest_lib.server.cros.multimedia import remote_facade_factory |
Cheng-Yi Chiang | 5187657 | 2015-05-22 15:12:02 +0800 | [diff] [blame] | 14 | from autotest_lib.site_utils import lxc |
| 15 | |
| 16 | |
| 17 | class AudioTest(test.test): |
| 18 | """Base class for audio tests. |
| 19 | |
| 20 | AudioTest provides a common warmup() function for the collection |
| 21 | of audio tests. |
| 22 | It is not mandatory to use this base class for audio tests, it is for |
| 23 | convenience only. |
| 24 | |
| 25 | """ |
| 26 | |
| 27 | def warmup(self): |
| 28 | """Warmup for the test before executing main logic of the test.""" |
| 29 | # test.test is an old-style class. |
| 30 | test.test.warmup(self) |
| 31 | self.install_sox() |
| 32 | self.check_sox_installed() |
| 33 | |
| 34 | |
| 35 | def install_sox(self): |
| 36 | """Install sox command on autotest drone.""" |
| 37 | try: |
| 38 | lxc.install_package('sox') |
| 39 | except error.ContainerError: |
| 40 | logging.info('Can not install sox outside of container.') |
| 41 | |
| 42 | |
| 43 | def check_sox_installed(self): |
| 44 | """Checks if sox is installed. |
| 45 | |
| 46 | @raises: error.TestError if sox is not installed. |
| 47 | |
| 48 | """ |
| 49 | try: |
| 50 | utils.run('sox --help') |
| 51 | logging.info('Found sox executable.') |
| 52 | except error.CmdError: |
| 53 | error_message = 'sox command is not installed.' |
| 54 | if site_utils.is_inside_chroot(): |
| 55 | error_message += ' sudo emerge sox to install sox in chroot' |
| 56 | raise error.TestError(error_message) |
Cheng-Yi Chiang | 30609a7 | 2015-10-22 11:11:40 +0800 | [diff] [blame] | 57 | |
| 58 | |
| 59 | def create_remote_facade_factory(self, host): |
| 60 | """Creates a remote facade factory to access multimedia server. |
| 61 | |
| 62 | @param host: A CrosHost object to access Cros device. |
| 63 | |
| 64 | @returns: A RemoteFacadeFactory object to create different facade for |
| 65 | different functionalities provided by multimedia server. |
| 66 | |
| 67 | """ |
| 68 | try: |
| 69 | factory = remote_facade_factory.RemoteFacadeFactory(host) |
| 70 | finally: |
| 71 | host.get_file( |
| 72 | constants.MULTIMEDIA_XMLRPC_SERVER_LOG_FILE, |
| 73 | os.path.join( |
| 74 | self.resultsdir, |
| 75 | 'multimedia_xmlrpc_server.log.init')) |
| 76 | return factory |