151876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang# Copyright 2015 The Chromium OS Authors. All rights reserved. 251876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang# Use of this source code is governed by a BSD-style license that can be 351876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang# found in the LICENSE file. 451876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang 551876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiangimport logging 651876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang 751876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiangfrom autotest_lib.client.bin import utils 851876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiangfrom autotest_lib.client.common_lib import error 951876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiangfrom autotest_lib.server import site_utils 1051876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiangfrom autotest_lib.server import test 1151876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiangfrom autotest_lib.site_utils import lxc 1251876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang 1351876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang 1451876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiangclass AudioTest(test.test): 1551876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang """Base class for audio tests. 1651876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang 1751876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang AudioTest provides a common warmup() function for the collection 1851876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang of audio tests. 1951876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang It is not mandatory to use this base class for audio tests, it is for 2051876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang convenience only. 2151876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang 2251876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang """ 2351876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang 2451876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang def warmup(self): 2551876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang """Warmup for the test before executing main logic of the test.""" 2651876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang # test.test is an old-style class. 2751876573ba85aedf3bf6c7f8f94388f7fb12f4d2Cheng-Yi Chiang test.test.warmup(self) 28bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang audio_test_requirement() 2930609a79716dbc5de161aa04f0d0007e1f3fcd33Cheng-Yi Chiang 3030609a79716dbc5de161aa04f0d0007e1f3fcd33Cheng-Yi Chiang 31bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiangdef audio_test_requirement(): 32bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang """Installs sox and checks it is installed correctly.""" 33bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang install_sox() 34bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang check_sox_installed() 35bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang 36bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang 37bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiangdef install_sox(): 38bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang """Install sox command on autotest drone.""" 39bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang try: 40bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang lxc.install_package('sox') 41bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang except error.ContainerError: 42bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang logging.info('Can not install sox outside of container.') 43bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang 44bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang 45bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiangdef check_sox_installed(): 46bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang """Checks if sox is installed. 47bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang 48bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang @raises: error.TestError if sox is not installed. 49bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang 50bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang """ 51bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang try: 52bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang utils.run('sox --help') 53bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang logging.info('Found sox executable.') 54bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang except error.CmdError: 55bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang error_message = 'sox command is not installed.' 56bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang if site_utils.is_inside_chroot(): 57bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang error_message += ' sudo emerge sox to install sox in chroot' 58bee353f263dd75dd330e1c857115bf78354c35bcCheng-Yi Chiang raise error.TestError(error_message) 59