Home | History | Annotate | Download | only in audio_AudioBasicUSBPlayback
      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 """This is a server side USB playback audio test using the Chameleon board."""
      6 
      7 import logging
      8 import os
      9 import time
     10 
     11 from autotest_lib.client.bin import utils
     12 from autotest_lib.client.cros.audio import audio_test_data
     13 from autotest_lib.client.cros.chameleon import audio_test_utils
     14 from autotest_lib.client.cros.chameleon import chameleon_audio_ids
     15 from autotest_lib.client.cros.chameleon import chameleon_audio_helper
     16 from autotest_lib.server.cros.audio import audio_test
     17 from autotest_lib.server.cros.multimedia import remote_facade_factory
     18 
     19 
     20 class audio_AudioBasicUSBPlayback(audio_test.AudioTest):
     21     """Server side USB playback audio test.
     22 
     23     This test talks to a Chameleon board and a Cros device to verify
     24     USB audio playback function of the Cros device.
     25 
     26     """
     27     version = 1
     28     RECORD_SECONDS = 5
     29     SUSPEND_SECONDS = 30
     30     RPC_RECONNECT_TIMEOUT = 60
     31 
     32     def run_once(self, host, suspend=False):
     33         golden_file = audio_test_data.SWEEP_TEST_FILE
     34 
     35         chameleon_board = host.chameleon
     36         factory = remote_facade_factory.RemoteFacadeFactory(
     37                 host, results_dir=self.resultsdir)
     38 
     39         chameleon_board.setup_and_reset(self.outputdir)
     40 
     41         widget_factory = chameleon_audio_helper.AudioWidgetFactory(
     42                 factory, host)
     43 
     44         source = widget_factory.create_widget(
     45             chameleon_audio_ids.CrosIds.USBOUT)
     46         recorder = widget_factory.create_widget(
     47             chameleon_audio_ids.ChameleonIds.USBIN)
     48         binder = widget_factory.create_binder(source, recorder)
     49 
     50         with chameleon_audio_helper.bind_widgets(binder):
     51             # Checks the node selected by cras is correct.
     52             audio_facade = factory.create_audio_facade()
     53 
     54             audio_test_utils.dump_cros_audio_logs(
     55                     host, audio_facade, self.resultsdir, 'after_binding')
     56 
     57             audio_test_utils.check_audio_nodes(audio_facade, (['USB'], None))
     58 
     59             logging.info('Setting playback data on Cros device')
     60 
     61             audio_facade.set_selected_output_volume(70)
     62 
     63             source.set_playback_data(golden_file)
     64 
     65             if suspend:
     66                 audio_test_utils.suspend_resume(host, self.SUSPEND_SECONDS)
     67                 utils.poll_for_condition(condition=factory.ready,
     68                                          timeout=self.RPC_RECONNECT_TIMEOUT,
     69                                          desc='multimedia server reconnect')
     70                 audio_test_utils.check_audio_nodes(audio_facade,
     71                                                    (['USB'], None))
     72 
     73             # Starts recording from Chameleon, waits for some time, and then
     74             # starts playing from Cros device.
     75             logging.info('Start recording from Chameleon.')
     76             recorder.start_recording()
     77 
     78             logging.info('Start playing %s on Cros device',
     79                          golden_file.path)
     80             source.start_playback()
     81 
     82             time.sleep(self.RECORD_SECONDS)
     83 
     84             recorder.stop_recording()
     85             logging.info('Stopped recording from Chameleon.')
     86 
     87             audio_test_utils.dump_cros_audio_logs(
     88                     host, audio_facade, self.resultsdir, 'after_recording')
     89 
     90             recorder.read_recorded_binary()
     91             logging.info('Read recorded binary from Chameleon.')
     92 
     93         recorded_file = os.path.join(self.resultsdir, "recorded.raw")
     94         logging.info('Saving recorded data to %s', recorded_file)
     95         recorder.save_file(recorded_file)
     96 
     97         audio_test_utils.compare_recorded_correlation(golden_file, recorder)
     98