• 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.cros.chameleon import audio_test_utils
10from autotest_lib.server.cros.audio import audio_test
11from autotest_lib.server.cros.multimedia import remote_facade_factory
12
13
14class audio_InternalCardNodes(audio_test.AudioTest):
15    """Server side test to check audio nodes for internal card.
16
17    This test talks to a Chameleon board and a Cros device to verify
18    audio nodes created for internal cards are correct.
19
20    """
21    version = 1
22    DELAY_AFTER_PLUGGING = 2
23    DELAY_AFTER_UNPLUGGING = 2
24
25    def run_once(self, host):
26        chameleon_board = host.chameleon
27        factory = remote_facade_factory.RemoteFacadeFactory(
28                host, results_dir=self.resultsdir)
29        audio_facade = factory.create_audio_facade()
30
31        chameleon_board.setup_and_reset(self.outputdir)
32
33        jack_plugger = chameleon_board.get_audio_board().get_jack_plugger()
34
35        expected_plugged_nodes_without_audio_jack = (
36                [],
37                ['POST_DSP_LOOPBACK',
38                 'POST_MIX_LOOPBACK'])
39
40        # 'Headphone' or 'LINEOUT' will be added to expected list after jack
41        # is plugged.
42        expected_plugged_nodes_with_audio_jack = (
43                [],
44                ['MIC', 'POST_DSP_LOOPBACK',
45                 'POST_MIX_LOOPBACK'])
46
47        if audio_test_utils.has_internal_speaker(host):
48            expected_plugged_nodes_without_audio_jack[0].append(
49                    'INTERNAL_SPEAKER')
50            expected_plugged_nodes_with_audio_jack[0].append(
51                    'INTERNAL_SPEAKER')
52
53        if audio_test_utils.has_internal_microphone(host):
54            expected_plugged_nodes_without_audio_jack[1].append(
55                    'INTERNAL_MIC')
56            expected_plugged_nodes_with_audio_jack[1].append(
57                    'INTERNAL_MIC')
58
59        # Modify expected nodes for special boards.
60        board_name = host.get_board().split(':')[1]
61
62        if board_name == 'link':
63            expected_plugged_nodes_without_audio_jack[1].append('KEYBOARD_MIC')
64            expected_plugged_nodes_with_audio_jack[1].append('KEYBOARD_MIC')
65
66        if board_name in ['samus', 'kevin']:
67            expected_plugged_nodes_without_audio_jack[1].append('HOTWORD')
68            expected_plugged_nodes_with_audio_jack[1].append('HOTWORD')
69
70        audio_test_utils.check_plugged_nodes(
71                audio_facade, expected_plugged_nodes_without_audio_jack)
72
73        try:
74            jack_plugger.plug()
75            time.sleep(self.DELAY_AFTER_PLUGGING)
76
77            audio_test_utils.dump_cros_audio_logs(
78                    host, audio_facade, self.resultsdir)
79
80            # Checks whether line-out or headphone is detected.
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
88        finally:
89            jack_plugger.unplug()
90            time.sleep(self.DELAY_AFTER_UNPLUGGING)
91
92        audio_test_utils.check_plugged_nodes(
93                audio_facade, expected_plugged_nodes_without_audio_jack)
94