[autotest] Handle the test where we need to know the plugged node type
In some tests, we need to know whether it is a 'HEADPHONE' or 'LINEOUT'
detected since it will affect which node to be selected through
chrome.audio API.
BUG=chromium:710903
TEST=run the tests
Change-Id: I1924db7dfe28565b24a98864ea010c3fb9dc2b68
Reviewed-on: https://chromium-review.googlesource.com/487786
Commit-Ready: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Kalin Stoyanov <kalin@chromium.org>
diff --git a/client/cros/chameleon/audio_test_utils.py b/client/cros/chameleon/audio_test_utils.py
index abead82..01dd4fc 100644
--- a/client/cros/chameleon/audio_test_utils.py
+++ b/client/cros/chameleon/audio_test_utils.py
@@ -713,3 +713,25 @@
raise error.TestError(
'Target input type %s not present' % input_type)
audio_facade.set_chrome_active_node_type(output_type, input_type)
+
+
+def check_hp_or_lineout_plugged(audio_facade):
+ """Checks whether line-out or headphone is plugged.
+
+ @param audio_facade: A RemoteAudioFacade to access audio functions on
+ Cros device.
+
+ @returns: 'LINEOUT' if line-out node is plugged.
+ 'HEADPHONE' if headphone node is plugged.
+
+ @raises: error.TestFail if the plugged nodes does not contain one of
+ 'LINEOUT' and 'HEADPHONE'.
+
+ """
+ # Checks whether line-out or headphone is detected.
+ output_nodes, _ = audio_facade.get_plugged_node_types()
+ if 'LINEOUT' in output_nodes:
+ return 'LINEOUT'
+ if 'HEADPHONE' in output_nodes:
+ return 'HEADPHONE'
+ raise error.TestFail('Can not detect line-out or headphone')
diff --git a/server/site_tests/audio_AudioNodeSwitch/audio_AudioNodeSwitch.py b/server/site_tests/audio_AudioNodeSwitch/audio_AudioNodeSwitch.py
index 1058f2d..5a2481a 100644
--- a/server/site_tests/audio_AudioNodeSwitch/audio_AudioNodeSwitch.py
+++ b/server/site_tests/audio_AudioNodeSwitch/audio_AudioNodeSwitch.py
@@ -31,6 +31,7 @@
_PLUG_DELAY = 5
_VOLUMES = {'INTERNAL_SPEAKER': 100,
'HEADPHONE': 80,
+ 'LINEOUT': 80,
'HDMI': 60,
'USB': 40,}
@@ -128,11 +129,17 @@
time.sleep(self._PLUG_DELAY)
audio_test_utils.dump_cros_audio_logs(host, self.audio_facade,
self.resultsdir)
- audio_test_utils.check_audio_nodes(self.audio_facade,
- (['HEADPHONE'], ['MIC']))
- self.set_active_volume_to_node_volume('HEADPHONE')
- nodes.append('HEADPHONE')
+ # Checks whether line-out or headphone is detected.
+ hp_jack_node_type = audio_test_utils.check_hp_or_lineout_plugged(
+ self.audio_facade)
+
+ audio_test_utils.check_audio_nodes(self.audio_facade,
+ (None, ['MIC']))
+
+ self.set_active_volume_to_node_volume(hp_jack_node_type)
+
+ nodes.append(hp_jack_node_type)
self.switch_nodes_and_check_volume(nodes)
if usb_node:
@@ -159,10 +166,10 @@
if jack_node:
if usb_node:
audio_test_utils.check_audio_nodes(self.audio_facade,
- (['HEADPHONE'], ['MIC']))
+ ([hp_jack_node_type], ['MIC']))
jack_plugger.unplug()
time.sleep(self._PLUG_DELAY)
- nodes.remove('HEADPHONE')
+ nodes.remove(hp_jack_node_type)
self.switch_nodes_and_check_volume(nodes)
if hdmi_node:
diff --git a/server/site_tests/audio_AudioWebRTCLoopback/audio_AudioWebRTCLoopback.py b/server/site_tests/audio_AudioWebRTCLoopback/audio_AudioWebRTCLoopback.py
index 213be45..a65e32e 100644
--- a/server/site_tests/audio_AudioWebRTCLoopback/audio_AudioWebRTCLoopback.py
+++ b/server/site_tests/audio_AudioWebRTCLoopback/audio_AudioWebRTCLoopback.py
@@ -97,12 +97,16 @@
audio_test_utils.dump_cros_audio_logs(
host, audio_facade, self.resultsdir, 'after_binding')
+ # Checks whether line-out or headphone is detected.
+ hp_jack_node_type = audio_test_utils.check_hp_or_lineout_plugged(
+ audio_facade)
+
# Checks headphone and USB nodes are plugged.
# Let Chrome select the proper I/O nodes.
# Input is USB, output is headphone.
audio_test_utils.check_and_set_chrome_active_node_types(
audio_facade=audio_facade,
- output_type='HEADPHONE',
+ output_type=hp_jack_node_type,
input_type='USB')
logging.info('Setting playback data on Chameleon')
diff --git a/server/site_tests/audio_InternalCardNodes/audio_InternalCardNodes.py b/server/site_tests/audio_InternalCardNodes/audio_InternalCardNodes.py
index 6093bf6..046b994 100644
--- a/server/site_tests/audio_InternalCardNodes/audio_InternalCardNodes.py
+++ b/server/site_tests/audio_InternalCardNodes/audio_InternalCardNodes.py
@@ -37,8 +37,10 @@
['POST_DSP_LOOPBACK',
'POST_MIX_LOOPBACK'])
+ # 'Headphone' or 'LINEOUT' will be added to expected list after jack
+ # is plugged.
expected_plugged_nodes_with_audio_jack = (
- ['HEADPHONE'],
+ [],
['MIC', 'POST_DSP_LOOPBACK',
'POST_MIX_LOOPBACK'])
@@ -75,6 +77,11 @@
audio_test_utils.dump_cros_audio_logs(
host, audio_facade, self.resultsdir)
+ # Checks whether line-out or headphone is detected.
+ hp_jack_node_type = audio_test_utils.check_hp_or_lineout_plugged(
+ audio_facade)
+ expected_plugged_nodes_with_audio_jack[0].append(hp_jack_node_type)
+
audio_test_utils.check_plugged_nodes(
audio_facade, expected_plugged_nodes_with_audio_jack)