blob: fd20e264b178992635d789fc1d74ad735a2f1278 [file] [log] [blame]
# 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.
import common
from autotest_lib.client.common_lib import error
from autotest_lib.server import site_utils
_AVAILABLE_AUDIO_CLIENTS = set(('loop', 'interactive'))
def _get_client(fb_client_name, available_clients, test_name, machine,
"""Instantiates a feedback client.
@param fb_client_name: Name of the desired client.
@param available_clients: Set of available client names to choose from.
@param test_name: The name of the test.
@param machine: A dictionary describing the test host and DUT.
@param args_str: String containing comma-separate, implementation-specific
@return An instance of
@raise error.TestError: Requested client is invalid/unavailable/unknown.
if not fb_client_name:
raise error.TestError('Feedback client name is empty')
if fb_client_name not in available_clients:
raise error.TestError(
'Feedback client (%s) is unknown or unavailble for this test' %
hostname = site_utils.get_hostname_from_machine(machine)
afe_host = site_utils.get_afe_host_from_machine(machine)
serials = afe_host.attributes.get('serials')
dut_name = '%s-%s' % (hostname, serials)
args = args_str.split(',') if args_str else []
if fb_client_name == 'loop':
from import closed_loop_audio_client
return closed_loop_audio_client.Client(*args)
elif fb_client_name == 'interactive':
from import tester_feedback_client
return tester_feedback_client.Client(test_name, dut_name, *args)
raise error.TestError(
'Feedback client (%s) unknown despite being listed as '
'available for this test' % fb_client_name)
def get_audio_client(fb_client_name, test_name, machine, args_str):
"""Instantiates an audio feedback client."""
return _get_client(fb_client_name, _AVAILABLE_AUDIO_CLIENTS, test_name,
machine, args_str)