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 board_name = strip_kernelnext_suffix(board_name) 23 if (board_type == _BOARD_TYPE_CHROMEBOX 24 or board_type == _BOARD_TYPE_CHROMEBIT 25 or board_name in _BOARD_WITHOUT_SOUND_CARD): 26 return False 27 return True 28 29 30def has_internal_microphone(board_type): 31 """Checks if a board has internal microphone. 32 33 @param board_type: board type string. E.g. CHROMEBOX, CHROMEBIT, and etc. 34 35 @returns: True if the board has internal microphone. False otherwise. 36 37 """ 38 if (board_type == _BOARD_TYPE_CHROMEBOX 39 or board_type == _BOARD_TYPE_CHROMEBIT): 40 return False 41 return True 42 43 44def has_audio_jack(board_name, board_type): 45 """Checks if a board has a 3.5mm audio jack. 46 47 @param board_name: board name of the DUT. 48 @param board_type: board type string. E.g. CHROMEBOX, CHROMEBIT, and etc. 49 50 @returns: True if the board has headphone. False otherwise. 51 52 """ 53 board_name = strip_kernelnext_suffix(board_name) 54 if (board_name in ['nocturne'] or board_type == _BOARD_TYPE_CHROMEBIT): 55 return False 56 return True 57 58def strip_kernelnext_suffix(board_name): 59 """Removes the '-kernelnext' suffix from board_name if present. 60 61 @param board_name: board name of the DUT. 62 63 @returns: board_name without '-kernelnext' suffix. 64 65 """ 66 if board_name.endswith("-kernelnext"): 67 return board_name[:-len("-kernelnext")] 68 69 return board_name 70 71BOARDS_WITH_HOTWORDING = [ 72 'atlas', 'coral', 'eve', 'kevin', 'nami', 'nocturne', 'pyro', 'rammus', 73 'samus' 74] 75 76 77def has_hotwording(board_name, model_name): 78 """Checks if a board has hotwording. 79 80 @param board_name: board name of the DUT. 81 @param model_name: model name of the DUT. 82 83 @returns: True if the board has hotwording. 84 85 """ 86 board_name = strip_kernelnext_suffix(board_name) 87 return (board_name in BOARDS_WITH_HOTWORDING) 88 89def has_echo_reference(board_name): 90 """Checks if a board has echo reference. 91 92 @param board_name: board name of the DUT. 93 94 @returns: True if the board has echo reference. 95 96 """ 97 board_name = strip_kernelnext_suffix(board_name) 98 return board_name in ['nocturne', 'atlas'] 99 100 101BoardInfo = collections.namedtuple('BoardInfo', ['board', 'model', 'sku']) 102 103BOARDS_WITH_TWO_INTERNAL_MICS = [ 104 BoardInfo('coral', 'babytiger', ''), 105 BoardInfo('coral', 'nasher360', ''), 106 BoardInfo('coral', 'rabbid', ''), 107 BoardInfo('coral', 'robo360', ''), 108 BoardInfo('grunt', 'treeya360', '175'), 109 BoardInfo('hatch', 'kohaku', ''), 110 BoardInfo('octopus', 'ampton', ''), 111 BoardInfo('octopus', 'bobba360', '9'), 112 BoardInfo('octopus', 'bobba360', '10'), 113 BoardInfo('octopus', 'dood', ''), 114 BoardInfo('octopus', 'foob360', ''), 115 BoardInfo('octopus', 'grabbiter', ''), 116 BoardInfo('octopus', 'phaser360', '3'), 117 BoardInfo('octopus', 'sparky', ''), 118 BoardInfo('octopus', 'sparky360', ''), 119 BoardInfo('octopus', 'vortininja', ''), 120 BoardInfo('snappy', 'snappy', '8'), 121 BoardInfo('zork', 'dalboz', ''), 122 BoardInfo('zork', 'ezkinil', ''), 123 BoardInfo('zork', 'morphius', ''), 124 BoardInfo('zork', 'vilboz360', '1518534658'), 125 BoardInfo('zork', 'vilboz360', '1518534660'), 126 BoardInfo('zork', 'vilboz360', '1518534661'), 127 BoardInfo('zork', 'vilboz360', '1518534662'), 128] 129 130 131def get_num_internal_microphone(board_type, board, model, sku): 132 """Gets the number of internal microphones. 133 134 @param board_type: board type string. E.g. CHROMEBOX, CHROMEBIT, and etc. 135 @param board: board name of the DUT. 136 @param model: model name of the DUT. 137 @param sku: sku number string of the DUT. 138 139 @returns: The number of internal microphones. 140 141 """ 142 if not has_internal_microphone(board_type): 143 return 0 144 145 board = strip_kernelnext_suffix(board) 146 for b in BOARDS_WITH_TWO_INTERNAL_MICS: 147 if b.board == board and b.model == model: 148 if b.sku == '' or b.sku == sku: 149 return 2 150 151 return 1 152 153 154INTERNAL_MIC_NODE = { 155 ('nami', 'pantheon'): 'FRONT_MIC', 156 ('nami', 'sona'): 'FRONT_MIC', 157 ('nami', 'syndra'): 'FRONT_MIC', 158 ('nami', 'vayne'): 'FRONT_MIC', 159} 160 161 162def get_internal_mic_node(board_type, board, model, sku): 163 """Return the expected internal microphone node for given board name and 164 model name. 165 166 @param board_type: board type string. E.g. CHROMEBOX, CHROMEBIT, and etc. 167 @param board: board name of the DUT. 168 @param model: model name of the DUT. 169 @param sku: sku number string of the DUT. 170 171 @returns: The name of the expected internal microphone nodes. 172 """ 173 board = strip_kernelnext_suffix(board) 174 if get_num_internal_microphone(board_type, board, model, sku) == 2: 175 return 'FRONT_MIC' 176 177 return INTERNAL_MIC_NODE.get((board, model), 'INTERNAL_MIC') 178 179 180INTERNAL_MIC_NODES = { 181 ('nami', 'vayne'): ['FRONT_MIC'], 182} 183 184 185def get_plugged_internal_mics(board_type, board, model, sku): 186 """Return a list of all the plugged internal microphone nodes for given 187 board name and model name. 188 189 @param board_type: board type string. E.g. CHROMEBOX, CHROMEBIT, and etc. 190 @param board: board name of the DUT. 191 @param model: model name of the DUT. 192 @param sku: sku number string of the DUT. 193 194 @returns: A list of all the plugged internal microphone nodes. 195 """ 196 board = strip_kernelnext_suffix(board) 197 if get_num_internal_microphone(board_type, board, model, sku) == 2: 198 return ['FRONT_MIC', 'REAR_MIC'] 199 200 return INTERNAL_MIC_NODES.get((board, model), ['INTERNAL_MIC']) 201 202 203HEADPHONE_NODE = { 204 ('sarien'): 'LINEOUT', 205 ('drallion'): 'LINEOUT', 206} 207 208 209def get_headphone_node(board): 210 """Return the expected headphone node for given board name. 211 212 @param board: board name of the DUT. 213 214 @returns: The name of the expected headphone node. 215 """ 216 board = strip_kernelnext_suffix(board) 217 return HEADPHONE_NODE.get((board), 'HEADPHONE') 218