# Copyright 2016 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.

from autotest_lib.client.cros.audio import audio_test_data
from autotest_lib.client.cros.chameleon import chameleon_audio_ids
from autotest_lib.server import utils

AUTHOR = "chromeos-chameleon"
NAME = "audio_AudioAfterSuspend.external_mic.unplug"
PURPOSE = "Remotely controlled external_mic AFTER SUSPEND audio test."
CRITERIA = "This test will fail if the captured audio does not match original file."
TIME = "SHORT"
TEST_CATEGORY = "Functional"
TEST_CLASS = "audio"
TEST_TYPE = "server"
ATTRIBUTES = "suite:chameleon_audio_nightly, suite:chameleon_audio"
DEPENDENCIES = "chameleon, audio_board, audio_box"
JOB_RETRIES = 2

DOC = """
This test remotely tests external_mic audio function against DUT after suspend.
"""

# Plug unplug sequnce
# (plugged_before_suspend, plugged_after_suspend, plugged_before_resume,
# plugged_after_resume)
plug_status = [(True,False,False,True),
               (True,False,True,True),
               (False,True,True,True),
               (False,True,False,True),]

args_dict = utils.args_to_dict(args)
chameleon_args = hosts.CrosHost.get_chameleon_arguments(args_dict)

def run(machine):
    host = hosts.create_host(machine, chameleon_args=chameleon_args)
    job.run_test("audio_AudioAfterSuspend", host=host,
                 golden_data=(audio_test_data.SIMPLE_FREQUENCY_TEST_FILE, 2000),
                 bind_from=chameleon_audio_ids.ChameleonIds.LINEOUT,
                 bind_to=chameleon_audio_ids.CrosIds.EXTERNAL_MIC,
                 audio_nodes=(['HEADPHONE'], ['MIC']),
                 plug_status=plug_status, tag = "external_mic.unplug")

parallel_simple(run, machines)