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