[autotest] audio_AudioBasicHDMI: do extra plug/unplug to detect HDMI

For boards using exynos HDMI driver, it has problem detecing HDMI audio.
The workaround is to plug/unplug several times.

BUG=chromium:450101
TEST=run audio_AudioBasicHDMI test on peach_pit

Change-Id: I4c1d9c97be565cbd409dd97a3a3dce3cb8056814
Reviewed-on: https://chromium-review.googlesource.com/324678
Commit-Ready: Cheng-Yi Chiang <[email protected]>
Tested-by: Cheng-Yi Chiang <[email protected]>
Reviewed-by: Cheng-Yi Chiang <[email protected]>
diff --git a/client/cros/chameleon/audio_test_utils.py b/client/cros/chameleon/audio_test_utils.py
index 8fbf93a..8a06da5 100644
--- a/client/cros/chameleon/audio_test_utils.py
+++ b/client/cros/chameleon/audio_test_utils.py
@@ -10,6 +10,7 @@
 import logging
 import multiprocessing
 import os
+import time
 from contextlib import contextmanager
 
 from autotest_lib.client.common_lib import error
@@ -90,6 +91,29 @@
     return host.get_board().split(':')[1]
 
 
+def correction_plug_unplug_for_audio(host, port):
+    """Plugs/unplugs several times for Cros device to detect audio.
+
+    For issue crbug.com/450101, Exynos HDMI driver has problem recognizing
+    HDMI audio, while display can be detected. Do several plug/unplug and wait
+    as a workaround. Note that port will be in unplugged state in the end if
+    extra plug/unplug is needed.
+
+    @param host: A CrosHost object.
+    @param port: A ChameleonVideoInput object.
+
+    """
+    board = _get_board_name(host)
+    if board in ['peach_pit', 'peach_pi', 'daisy', 'daisy_spring',
+                 'daisy_skate']:
+        logging.info('Need extra plug/unplug on board %s', board)
+        for _ in xrange(3):
+            port.plug()
+            time.sleep(3)
+            port.unplug()
+            time.sleep(3)
+
+
 def has_internal_speaker(host):
     """Checks if the Cros device has speaker.
 
diff --git a/server/site_tests/audio_AudioBasicHDMI/audio_AudioBasicHDMI.py b/server/site_tests/audio_AudioBasicHDMI/audio_AudioBasicHDMI.py
index 54cd8d6..6d547af 100644
--- a/server/site_tests/audio_AudioBasicHDMI/audio_AudioBasicHDMI.py
+++ b/server/site_tests/audio_AudioBasicHDMI/audio_AudioBasicHDMI.py
@@ -73,6 +73,10 @@
             raise error.TestFail(
                     'Can not find HDMI port, perhaps HDMI is not connected?')
         with hdmi_port.use_edid_file(edid_path):
+
+            # TODO(cychiang) remove this when issue crbug.com/450101 is fixed.
+            audio_test_utils.correction_plug_unplug_for_audio(host, hdmi_port)
+
             with chameleon_audio_helper.bind_widgets(binder):
                 audio_facade = factory.create_audio_facade()