1# Copyright 2017 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"""This module provides the test utilities for audio spec.""" 5 6import collections 7 8_BOARD_TYPE_CHROMEBOX = 'CHROMEBOX' 9_BOARD_TYPE_CHROMEBIT = 'CHROMEBIT' 10_BOARD_WITHOUT_SOUND_CARD = ['gale', 'veyron_rialto'] 11 12 13def has_internal_speaker(board_type, board_name): 14 """Checks if a board has internal speaker. 15 16 @param board_type: board type string. E.g. CHROMEBOX, CHROMEBIT, and etc. 17 @param board_name: board name string. 18 19 @returns: True if the board has internal speaker. False otherwise. 20 21 """ 22 if (board_type == _BOARD_TYPE_CHROMEBOX 23 or board_type == _BOARD_TYPE_CHROMEBIT 24 or board_name in _BOARD_WITHOUT_SOUND_CARD): 25 return False 26 return True 27 28 29def has_internal_microphone(board_type): 30 """Checks if a board has internal microphone. 31 32 @param board_type: board type string. E.g. CHROMEBOX, CHROMEBIT, and etc. 33 34 @returns: True if the board has internal microphone. False otherwise. 35 36 """ 37 if (board_type == _BOARD_TYPE_CHROMEBOX 38 or board_type == _BOARD_TYPE_CHROMEBIT): 39 return False 40 return True 41 42 43def has_audio_jack(board_name, board_type): 44 """Checks if a board has a 3.5mm audio jack. 45 46 @param board_name: board name of the DUT. 47 @param board_type: board type string. E.g. CHROMEBOX, CHROMEBIT, and etc. 48 49 @returns: True if the board has headphone. False otherwise. 50 51 """ 52 if (board_name in ['nocturne'] or board_type == _BOARD_TYPE_CHROMEBIT): 53 return False 54 return True 55 56 57BORADS_WITH_HOTWORDING = [ 58 'atlas', 'coral', 'eve', 'kevin', 'nami', 'nocturne', 'pyro', 'rammus', 59 'samus' 60] 61 62 63def has_hotwording(board_name, model_name): 64 """Checks if a board has hotwording. 65 66 @param board_name: board name of the DUT. 67 @param model_name: model name of the DUT. 68 69 @returns: True if the board has hotwording. 70 71 """ 72 return board_name in BORADS_WITH_HOTWORDING 73 74def has_echo_reference(board_name): 75 """Checks if a board has echo reference. 76 77 @param board_name: board name of the DUT. 78 79 @returns: True if the board has echo reference. 80 81 """ 82 return board_name in ['nocturne', 'atlas'] 83 84 85BoardInfo = collections.namedtuple('BoardInfo', ['board', 'model', 'sku']) 86 87BORADS_WITH_TWO_INTERNAL_MICS = [ 88 BoardInfo('coral', 'nasher360', ''), 89 BoardInfo('octopus', 'bobba360', '9'), 90 BoardInfo('octopus', 'bobba360', '10'), 91 BoardInfo('snappy', 'snappy', '8'), 92] 93 94 95def get_num_internal_microphone(board, model, sku): 96 """Gets the number of internal microphones. 97 98 @param board: board name of the DUT. 99 @param model: model name of the DUT. 100 @param sku: sku number string of the DUT. 101 102 @returns: The number of internal microphones. 103 104 """ 105 if not has_internal_microphone(board): 106 return 0 107 108 for b in BORADS_WITH_TWO_INTERNAL_MICS: 109 if b.board == board and b.model == model: 110 if b.sku == '' or b.sku == sku: 111 return 2 112 113 return 1 114 115 116INTERNAL_MIC_NODE = { 117 ('nami', 'pantheon'): 'FRONT_MIC', 118 ('nami', 'sona'): 'FRONT_MIC', 119 ('nami', 'syndra'): 'FRONT_MIC', 120 ('nami', 'vayne'): 'FRONT_MIC', 121} 122 123 124def get_internal_mic_node(board, model, sku): 125 """Return the expected internal microphone node for given board name and 126 model name. 127 128 @param board: board name of the DUT. 129 @param model: model name of the DUT. 130 @param sku: sku number string of the DUT. 131 132 @returns: The name of the expected internal microphone nodes. 133 """ 134 if get_num_internal_microphone(board, model, sku) == 2: 135 return 'FRONT_MIC' 136 137 return INTERNAL_MIC_NODE.get((board, model), 'INTERNAL_MIC') 138 139 140INTERNAL_MIC_NODES = { 141 ('nami', 'vayne'): ['FRONT_MIC'], 142} 143 144 145def get_plugged_internal_mics(board, model, sku): 146 """Return a list of all the plugged internal microphone nodes for given 147 board name and model name. 148 149 @param board: board name of the DUT. 150 @param model: model name of the DUT. 151 @param sku: sku number string of the DUT. 152 153 @returns: A list of all the plugged internal microphone nodes. 154 """ 155 if get_num_internal_microphone(board, model, sku) == 2: 156 return ['FRONT_MIC', 'REAR_MIC'] 157 158 return INTERNAL_MIC_NODES.get((board, model), ['INTERNAL_MIC']) 159 160 161HEADPHONE_NODE = { 162 ('sarien'): 'LINEOUT', 163} 164 165 166def get_headphone_node(board): 167 """Return the expected headphone node for given board name. 168 169 @param board: board name of the DUT. 170 171 @returns: The name of the expected headphone node. 172 """ 173 return HEADPHONE_NODE.get((board), 'HEADPHONE') 174