• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 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
5"""This is a server side test to check nodes created for internal card."""
6
7import time
8
9from autotest_lib.client.common_lib import error
10from autotest_lib.client.cros.chameleon import audio_test_utils
11from autotest_lib.server.cros.audio import audio_test
12from autotest_lib.client.cros.audio import cras_configs
13from autotest_lib.client.cros.audio import audio_spec
14from autotest_lib.server.cros.multimedia import remote_facade_factory
15
16
17class audio_InternalCardNodes(audio_test.AudioTest):
18    """Server side test to check audio nodes for internal card.
19
20    This test talks to a Chameleon board and a Cros device to verify
21    audio nodes created for internal cards are correct.
22
23    """
24    version = 1
25    DELAY_AFTER_PLUGGING = 2
26    DELAY_AFTER_UNPLUGGING = 2
27
28    def run_once(self, host):
29        chameleon_board = host.chameleon
30        factory = remote_facade_factory.RemoteFacadeFactory(
31                host, results_dir=self.resultsdir)
32        audio_facade = factory.create_audio_facade()
33
34        chameleon_board.setup_and_reset(self.outputdir)
35
36        jack_plugger = chameleon_board.get_audio_board().get_jack_plugger()
37
38        expected_plugged_nodes_without_audio_jack = (
39                [],
40                ['POST_DSP_LOOPBACK',
41                 'POST_MIX_LOOPBACK'])
42
43        # 'Headphone' or 'LINEOUT' will be added to expected list after jack
44        # is plugged.
45        expected_plugged_nodes_with_audio_jack = (
46                [],
47                ['MIC', 'POST_DSP_LOOPBACK',
48                 'POST_MIX_LOOPBACK'])
49
50        # Modify expected nodes for special boards.
51        board_name = host.get_board().split(':')[1]
52        model_name = host.get_platform()
53
54        if audio_test_utils.has_internal_speaker(host):
55            expected_plugged_nodes_without_audio_jack[0].append(
56                    'INTERNAL_SPEAKER')
57            expected_plugged_nodes_with_audio_jack[0].append(
58                    'INTERNAL_SPEAKER')
59
60        if audio_test_utils.has_internal_microphone(host):
61            expected_internal_mics = cras_configs.get_plugged_internal_mics(
62                    board_name, model_name)
63            expected_plugged_nodes_without_audio_jack[1].extend(
64                    expected_internal_mics)
65            expected_plugged_nodes_with_audio_jack[1].extend(
66                    expected_internal_mics)
67
68        if board_name == 'link':
69            expected_plugged_nodes_without_audio_jack[1].append('KEYBOARD_MIC')
70            expected_plugged_nodes_with_audio_jack[1].append('KEYBOARD_MIC')
71
72        if audio_spec.has_hotwording(board_name, model_name):
73            expected_plugged_nodes_without_audio_jack[1].append('HOTWORD')
74            expected_plugged_nodes_with_audio_jack[1].append('HOTWORD')
75
76        # If there is no jack plugger, check the nodes without plugging.
77        host_info = host.host_info_store.get()
78        if jack_plugger is None:
79            if 'audio_box' in host_info.labels:
80                raise error.TestError("Failed to detect jack plugger.")
81            hp_jack_node_type = audio_test_utils.check_hp_or_lineout_plugged(
82                    audio_facade)
83            expected_plugged_nodes_with_audio_jack[0].append(hp_jack_node_type)
84
85            audio_test_utils.check_plugged_nodes(
86                    audio_facade, expected_plugged_nodes_with_audio_jack)
87            return
88
89        audio_test_utils.check_plugged_nodes(
90                audio_facade, expected_plugged_nodes_without_audio_jack)
91
92        try:
93            jack_plugger.plug()
94            time.sleep(self.DELAY_AFTER_PLUGGING)
95
96            audio_test_utils.dump_cros_audio_logs(
97                    host, audio_facade, self.resultsdir)
98
99            # Checks whether line-out or headphone is detected.
100            hp_jack_node_type = audio_test_utils.check_hp_or_lineout_plugged(
101                    audio_facade)
102            expected_plugged_nodes_with_audio_jack[0].append(hp_jack_node_type)
103
104            audio_test_utils.check_plugged_nodes(
105                    audio_facade, expected_plugged_nodes_with_audio_jack)
106
107        finally:
108            jack_plugger.unplug()
109            time.sleep(self.DELAY_AFTER_UNPLUGGING)
110
111        audio_test_utils.check_plugged_nodes(
112                audio_facade, expected_plugged_nodes_without_audio_jack)
113