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) |
Cheng-Yi Chiang | bee353f | 2015-12-18 17:50:52 +0800 | [diff] [blame^] | 31 | audio_test_requirement() |
Cheng-Yi Chiang | 30609a7 | 2015-10-22 11:11:40 +0800 | [diff] [blame] | 32 | |
| 33 | |
| 34 | def create_remote_facade_factory(self, host): |
| 35 | """Creates a remote facade factory to access multimedia server. |
| 36 | |
| 37 | @param host: A CrosHost object to access Cros device. |
| 38 | |
| 39 | @returns: A RemoteFacadeFactory object to create different facade for |
| 40 | different functionalities provided by multimedia server. |
| 41 | |
| 42 | """ |
Cheng-Yi Chiang | bee353f | 2015-12-18 17:50:52 +0800 | [diff] [blame^] | 43 | return create_remote_facade_factory(host, self.resultsdir) |
| 44 | |
| 45 | |
| 46 | def create_remote_facade_factory(host, result_dir): |
| 47 | """Creates a remote facade factory to access multimedia server. |
| 48 | |
| 49 | @param host: A CrosHost object to access Cros device. |
| 50 | @param result_dir: A directory to store multimedia server init log. |
| 51 | |
| 52 | @returns: A RemoteFacadeFactory object to create different facade for |
| 53 | different functionalities provided by multimedia server. |
| 54 | |
| 55 | """ |
| 56 | try: |
| 57 | factory = remote_facade_factory.RemoteFacadeFactory(host) |
| 58 | finally: |
| 59 | host.get_file( |
| 60 | constants.MULTIMEDIA_XMLRPC_SERVER_LOG_FILE, |
| 61 | os.path.join( |
| 62 | result_dir, |
| 63 | 'multimedia_xmlrpc_server.log.init')) |
| 64 | return factory |
| 65 | |
| 66 | |
| 67 | def audio_test_requirement(): |
| 68 | """Installs sox and checks it is installed correctly.""" |
| 69 | install_sox() |
| 70 | check_sox_installed() |
| 71 | |
| 72 | |
| 73 | def install_sox(): |
| 74 | """Install sox command on autotest drone.""" |
| 75 | try: |
| 76 | lxc.install_package('sox') |
| 77 | except error.ContainerError: |
| 78 | logging.info('Can not install sox outside of container.') |
| 79 | |
| 80 | |
| 81 | def check_sox_installed(): |
| 82 | """Checks if sox is installed. |
| 83 | |
| 84 | @raises: error.TestError if sox is not installed. |
| 85 | |
| 86 | """ |
| 87 | try: |
| 88 | utils.run('sox --help') |
| 89 | logging.info('Found sox executable.') |
| 90 | except error.CmdError: |
| 91 | error_message = 'sox command is not installed.' |
| 92 | if site_utils.is_inside_chroot(): |
| 93 | error_message += ' sudo emerge sox to install sox in chroot' |
| 94 | raise error.TestError(error_message) |