audiovideo_CRASFormatConversion - Ensures the playing order of the two test tones.

Ensure the following order in the loopback test:

1. Play the first sine tone
2. Play the second sine tone
3. Start recording

Also reduce the time needed for this test by

1. Generate the noise profile once.
2. Loopback only once and analyze the recorded audio for both channels

BUG=None
TEST=Run the test on parrot

Change-Id: I8e61c07141f5d6e6ae4c4c0cfb8926bcf7e2a2fe
Reviewed-on: https://chromium-review.googlesource.com/178392
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Owen Lin <owenlin@chromium.org>
Tested-by: Owen Lin <owenlin@chromium.org>
diff --git a/client/cros/audio/cmd_utils.py b/client/cros/audio/cmd_utils.py
index 03c0c14..d4b9ba4 100644
--- a/client/cros/audio/cmd_utils.py
+++ b/client/cros/audio/cmd_utils.py
@@ -11,16 +11,35 @@
 _popen_lock = threading.Lock()
 
 
+def kill_silently(*popens):
+    '''Kill all the processes of the given Popens without rasie any exceptions
+    in any cases.
+
+    @param poopens: The Popens to be killed.
+    '''
+    for p in popens:
+        if p and p.pid:
+            try:
+                p.kill()
+            except:
+                logging.exception('failed to kill %d', p.pid)
+
+
 def wait_and_check_returncode(*popens):
     '''Wait for all the Popens and check the return code is 0.
 
     If the return code is not 0, it raises an RuntimeError.
+
+    @param popens: The Popens to be checked.
     '''
+    error_message = None
     for p in popens:
         if p.wait() != 0:
-            raise RuntimeError(
-                    'Command failed(%d, %d): %s' %
-                    (p.pid, p.returncode, p.command))
+            error_message = ('Command failed(%d, %d): %s' %
+                             (p.pid, p.returncode, p.command))
+            logging.error(error_message)
+    if error_message:
+        raise RuntimeError(error_message)
 
 
 def execute(args, stdin=None, stdout=None):