• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import common
6from autotest_lib.client.common_lib import error
7
8
9_AVAILABLE_AUDIO_CLIENTS = set(('loop', 'interactive'))
10
11
12def _get_client(fb_client_name, available_clients, test_name, machine,
13                args_str):
14    """Instantiates a feedback client.
15
16    @param fb_client_name: Name of the desired client.
17    @param available_clients: Set of available client names to choose from.
18    @param test_name: The name of the test.
19    @param machine: A dictionary describing the test host and DUT.
20    @param args_str: String containing comma-separate, implementation-specific
21                     arguments.
22
23    @return An instance of client.common_lib.feedback.client.Client.
24
25    @raise error.TestError: Requested client is invalid/unavailable/unknown.
26    """
27    if not fb_client_name:
28        raise error.TestError('Feedback client name is empty')
29    if fb_client_name not in available_clients:
30        raise error.TestError(
31                'Feedback client (%s) is unknown or unavailble for this test' %
32                fb_client_name)
33
34    dut_name = '%s-%s' % (machine['hostname'],
35                          machine['host_attributes']['serials'])
36    args = args_str.split(',') if args_str else []
37
38    if fb_client_name == 'loop':
39        from autotest_lib.server.brillo.feedback import closed_loop_audio_client
40        return closed_loop_audio_client.Client(*args)
41    elif fb_client_name == 'interactive':
42        from autotest_lib.client.common_lib.feedback import tester_feedback_client
43        return tester_feedback_client.Client(test_name, dut_name, *args)
44    else:
45        raise error.TestError(
46                'Feedback client (%s) unknown despite being listed as '
47                'available for this test' % fb_client_name)
48
49
50def get_audio_client(fb_client_name, test_name, machine, args_str):
51    """Instantiates an audio feedback client."""
52    return _get_client(fb_client_name, _AVAILABLE_AUDIO_CLIENTS, test_name,
53                       machine, args_str)
54