Home | History | Annotate | Download | only in audio_AudioBasicHDMI
      1 # Copyright 2014 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 HDMI audio test using the Chameleon board."""
      6 
      7 import logging
      8 import os
      9 import threading
     10 import time
     11 
     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_helper
     15 from autotest_lib.client.cros.chameleon import chameleon_audio_ids
     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_AudioBasicHDMI(audio_test.AudioTest):
     21     """Server side HDMI audio test.
     22 
     23     This test talks to a Chameleon board and a Cros device to verify
     24     HDMI audio function of the Cros device.
     25 
     26     """
     27     version = 2
     28     DELAY_BEFORE_PLAYBACK = 2
     29     DELAY_AFTER_PLAYBACK = 2
     30     CONNECT_TIMEOUT_SEC = 30
     31     SUSPEND_SEC = 15
     32     WAIT_TO_REBIND_SEC = 15
     33     WEB_PLAYBACK_SEC = 15
     34 
     35     def cleanup(self):
     36         """Restore the CPU scaling governor mode."""
     37         self._system_facade.set_scaling_governor_mode(0, self._original_mode)
     38         logging.debug('Set CPU0 mode to %s', self._original_mode)
     39 
     40 
     41     def set_high_performance_mode(self):
     42         """Set the CPU scaling governor mode to performance mode."""
     43         self._original_mode = self._system_facade.set_scaling_governor_mode(
     44                 0, 'performance')
     45         logging.debug('Set CPU0 scaling governor mode to performance, '
     46                       'original_mode: %s', self._original_mode)
     47 
     48 
     49     def playback_and_suspend(self, audio_facade, while_playback):
     50         """ Does playback and suspend-resume.
     51 
     52         @param audio_facade: audio facade to check nodes.
     53         @param while_playback: whether to play when suspending.
     54         """
     55         if while_playback:
     56             logging.info('Playing audio served on the web...')
     57             web_file = audio_test_data.HEADPHONE_10MIN_TEST_FILE
     58             file_url = getattr(web_file, 'url', None)
     59             browser_facade = self.factory.create_browser_facade()
     60             tab_descriptor = browser_facade.new_tab(file_url)
     61             time.sleep(self.WEB_PLAYBACK_SEC)
     62         logging.info('Suspending...')
     63         boot_id = self.host.get_boot_id()
     64         self.host.suspend(suspend_time=self.SUSPEND_SEC)
     65         self.host.test_wait_for_resume(boot_id, self.CONNECT_TIMEOUT_SEC)
     66         logging.info('Resumed and back online.')
     67         time.sleep(self.WAIT_TO_REBIND_SEC)
     68 
     69         # Stop audio playback by closing the browser tab.
     70         if while_playback:
     71             browser_facade.close_tab(tab_descriptor)
     72         audio_test_utils.check_audio_nodes(audio_facade,
     73                                         (['HDMI'], None))
     74 
     75 
     76     def run_once(self, host, suspend=False, while_playback=False):
     77         """Running basic HDMI audio tests.
     78 
     79         @param host: device under test host
     80         @param suspend: whether to suspend
     81         @param while_playback: whether to suspend while audio playback
     82 
     83         """
     84         golden_file = audio_test_data.SWEEP_TEST_FILE
     85         self.host = host
     86 
     87         # Dump audio diagnostics data for debugging.
     88         chameleon_board = host.chameleon
     89         self.factory = remote_facade_factory.RemoteFacadeFactory(
     90                 host, results_dir=self.resultsdir)
     91 
     92         # For DUTs with permanently connected audio jack cable
     93         # connecting HDMI won't switch automatically the node. Adding
     94         # audio_jack_plugged flag to select HDMI node after binding.
     95         audio_facade = self.factory.create_audio_facade()
     96         output_nodes, _ = audio_facade.get_selected_node_types()
     97         audio_jack_plugged = False
     98         if output_nodes == ['HEADPHONE']:
     99             audio_jack_plugged = True
    100             logging.debug('Found audio jack plugged!')
    101 
    102         self._system_facade = self.factory.create_system_facade()
    103         self.set_high_performance_mode()
    104 
    105         chameleon_board.setup_and_reset(self.outputdir)
    106 
    107         widget_factory = chameleon_audio_helper.AudioWidgetFactory(
    108                 self.factory, host)
    109 
    110         source = widget_factory.create_widget(
    111             chameleon_audio_ids.CrosIds.HDMI)
    112         recorder = widget_factory.create_widget(
    113             chameleon_audio_ids.ChameleonIds.HDMI)
    114         binder = widget_factory.create_binder(source, recorder)
    115 
    116         with chameleon_audio_helper.bind_widgets(binder):
    117             audio_test_utils.dump_cros_audio_logs(
    118                     host, audio_facade, self.resultsdir, 'after_binding')
    119 
    120             # HDMI node needs to be selected, when audio jack is plugged
    121             if audio_jack_plugged:
    122                 audio_facade.set_chrome_active_node_type('HDMI', None)
    123             audio_test_utils.check_audio_nodes(audio_facade,
    124                                                (['HDMI'], None))
    125 
    126             # Suspend after playing audio (if directed) and resume
    127             # before the HDMI audio test.
    128             if suspend:
    129                 self.playback_and_suspend(audio_facade, while_playback)
    130 
    131             source.set_playback_data(golden_file)
    132 
    133             logging.info('Start recording from Chameleon.')
    134             recorder.start_recording()
    135 
    136             time.sleep(self.DELAY_BEFORE_PLAYBACK)
    137 
    138             logging.info('Start playing %s on Cros device',
    139                          golden_file.path)
    140             source.start_playback(blocking=True)
    141 
    142             logging.info('Stopped playing %s on Cros device',
    143                          golden_file.path)
    144             time.sleep(self.DELAY_AFTER_PLAYBACK)
    145 
    146             audio_test_utils.dump_cros_audio_logs(
    147                     host, audio_facade, self.resultsdir, 'after_recording')
    148 
    149             recorder.stop_recording()
    150             logging.info('Stopped recording from Chameleon.')
    151             recorder.read_recorded_binary()
    152 
    153             recorded_file = os.path.join(self.resultsdir, "recorded.raw")
    154             logging.info('Saving recorded data to %s', recorded_file)
    155             recorder.save_file(recorded_file)
    156 
    157             audio_test_utils.compare_recorded_correlation(golden_file, recorder)
    158