blob: 72d7d3cc9b32ca6c94f405c421de3ad79a8a9ce0 [file] [log] [blame]
# Copyright 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""This is a server side HDMI audio test using the Chameleon board."""
import logging
import os
import time
from import audio_test_data
from autotest_lib.client.cros.chameleon import audio_test_utils
from autotest_lib.client.cros.chameleon import chameleon_audio_helper
from autotest_lib.client.cros.chameleon import chameleon_audio_ids
from import audio_test
class audio_AudioBasicHDMI(audio_test.AudioTest):
"""Server side HDMI audio test.
This test talks to a Chameleon board and a Cros device to verify
HDMI audio function of the Cros device.
version = 2
def cleanup(self):
"""Restore the CPU scaling governor mode."""
self._system_facade.set_scaling_governor_mode(0, self._original_mode)
logging.debug('Set CPU0 mode to %s', self._original_mode)
def set_high_performance_mode(self):
"""Set the CPU scaling governor mode to performance mode."""
self._original_mode = self._system_facade.set_scaling_governor_mode(
0, 'performance')
'Set CPU0 scaling governor mode to performance, '
'original_mode: %s', self._original_mode)
def playback_and_suspend(self, audio_facade, while_playback):
""" Does playback and suspend-resume.
@param audio_facade: audio facade to check nodes.
@param while_playback: whether to play when suspending.
if while_playback:'Playing audio served on the web...')
web_file = audio_test_data.HEADPHONE_10MIN_TEST_FILE
file_url = getattr(web_file, 'url', None)
browser_facade = self.factory.create_browser_facade()
tab_descriptor = browser_facade.new_tab(file_url)
audio_test_utils.suspend_resume_and_verify(, self.factory)
# Stop audio playback by closing the browser tab.
if while_playback:
# Explicitly select the node as there is a known issue
# that the selected node might change after a suspension.
# We should remove this after the issue is addressed(crbug:987529).
audio_facade.set_selected_node_types(['HDMI'], None)
audio_test_utils.check_audio_nodes(audio_facade, (['HDMI'], None))
def run_once(self,
"""Running basic HDMI audio tests.
@param host: device under test host
@param suspend: whether to suspend
@param while_playback: whether to suspend while audio playback
@param check_quality: True to check quality.
golden_file = audio_test_data.GenerateAudioTestData(
path=os.path.join(self.bindir, 'fix_2k_1k_16.raw'),
frequencies=[2000, 1000])
# For DUTs with permanently connected audio jack cable
# connecting HDMI won't switch automatically the node. Adding
# audio_jack_plugged flag to select HDMI node after binding.
output_nodes, _ = self.facade.get_selected_node_types()
audio_jack_plugged = False
if output_nodes == ['HEADPHONE'] or output_nodes == ['LINEOUT']:
audio_jack_plugged = True
logging.debug('Found audio jack plugged!')
self._system_facade = self.factory.create_system_facade()
source = self.widget_factory.create_widget(
recorder = self.widget_factory.create_widget(
binder = self.widget_factory.create_binder(source, recorder)
with chameleon_audio_helper.bind_widgets(binder):
audio_test_utils.dump_cros_audio_logs(, self.facade, self.resultsdir, 'after_binding')
# HDMI node needs to be selected, when audio jack is plugged
if audio_jack_plugged:
self.facade.set_chrome_active_node_type('HDMI', None)
audio_test_utils.check_audio_nodes(self.facade, (['HDMI'], None))
# Suspend after playing audio (if directed) and resume
# before the HDMI audio test.
if suspend:
self.playback_and_suspend(self.facade, while_playback)
# There is a known issue that if we reopen the HDMI device,
# chameleon will interrupt recording ( However,
# if there is another stream playing earlier, CRAS may need to
# reopen the device during recording. To fix it, we should move
# playback before the recording of chameleon.'Start playing %s on Cros device', golden_file.path)
source.start_playback()'Start recording from Chameleon.')
audio_test_utils.dump_cros_audio_logs(, self.facade, self.resultsdir, 'after_recording')
recorder.stop_recording()'Stopped recording from Chameleon.')
recorded_file = os.path.join(self.resultsdir, "recorded.raw")'Saving recorded data to %s', recorded_file)
golden_file, recorder, check_artifacts=check_quality)