|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# SPDX-License-Identifier: BSD-3-Clause |
| 4 | +# Copyright(c) 2025 Intel Corporation. All rights reserved. |
| 5 | + |
| 6 | +## |
| 7 | +## Case Name: test-mic-privacy |
| 8 | +## |
| 9 | +## Preconditions: |
| 10 | +## HW managed mode (Only for DMIC PCH and SNDW interfaces). |
| 11 | +## This test case requires physical loopback between playback and capture. |
| 12 | +## playback <=====> capture |
| 13 | +## USB relay switch is connected. The usbrelay app is installed. |
| 14 | +## Instruction: https://github.com/darrylb123/usbrelay |
| 15 | +## |
| 16 | +## Description: |
| 17 | +## Run alsabat process perform both playback and capture. |
| 18 | +## Enable MIC privacy. |
| 19 | +## Run alsabat process perform both playback and capture again. |
| 20 | +## |
| 21 | +## Case step: |
| 22 | +## 1. Specify the pcm IDs for playback and capture |
| 23 | +## 2. Check if usbrelay is installed and connected properly. |
| 24 | +## 3. Run alsabat process perform both playback and capture. |
| 25 | +## 4. Switch relay 1 to enable MIC privacy. |
| 26 | +## 5. Run alsabat process perform both playback and capture. |
| 27 | +## |
| 28 | +## Expect result: |
| 29 | +## After step 3 the return value is 0. |
| 30 | +## After step 5 the return value is -1001 (no peak be detected). |
| 31 | + |
| 32 | +# remove the existing alsabat wav files |
| 33 | +rm -f /tmp/mc.wav.* |
| 34 | + |
| 35 | +# shellcheck source=case-lib/lib.sh |
| 36 | +source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh |
| 37 | + |
| 38 | +OPT_NAME['p']='pcm_p' OPT_DESC['p']='pcm for playback. Example: hw:0,0' |
| 39 | +OPT_HAS_ARG['p']=1 OPT_VAL['p']='hw:0,0' |
| 40 | + |
| 41 | +OPT_NAME['N']='channel_p' OPT_DESC['N']='channel number for playback.' |
| 42 | +OPT_HAS_ARG['N']=1 OPT_VAL['N']='2' |
| 43 | + |
| 44 | +OPT_NAME['c']='pcm_c' OPT_DESC['c']='pcm for capture. Example: hw:0,1' |
| 45 | +OPT_HAS_ARG['c']=1 OPT_VAL['c']='hw:0,1' |
| 46 | + |
| 47 | +OPT_NAME['C']='channel_c' OPT_DESC['C']='channel number for capture.' |
| 48 | +OPT_HAS_ARG['C']=1 OPT_VAL['C']='2' |
| 49 | + |
| 50 | +OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT" |
| 51 | +OPT_HAS_ARG['s']=0 OPT_VAL['s']=1 |
| 52 | + |
| 53 | +OPT_NAME['r']='relay' OPT_DESC['r']='name of usbrelay switch, default value is HURTM_1' |
| 54 | +OPT_HAS_ARG['r']=1 OPT_VAL['r']="HURTM_1" |
| 55 | + |
| 56 | +func_opt_parse_option "$@" |
| 57 | + |
| 58 | +pcm_p=${OPT_VAL['p']} |
| 59 | +pcm_c=${OPT_VAL['c']} |
| 60 | +channel_c=${OPT_VAL['C']} |
| 61 | +channel_p=${OPT_VAL['N']} |
| 62 | +relay=${OPT_VAL['r']} |
| 63 | +rate=48000 |
| 64 | + |
| 65 | +dlogi "Params: pcm_p=$pcm_p, pcm_c=$pcm_c, channel_c=$channel_c, channel_p=$channel_p, rate=$rate, LOG_ROOT=$LOG_ROOT" |
| 66 | + |
| 67 | +function __upload_wav_files |
| 68 | +{ |
| 69 | + # upload the alsabat wav file |
| 70 | + for file in /tmp/mc.wav.*; do |
| 71 | + # alsabat has a bug where it creates an empty record in playback mode |
| 72 | + if test -s "$file"; then |
| 73 | + cp "$file" "$LOG_ROOT/" |
| 74 | + fi |
| 75 | + done |
| 76 | +} |
| 77 | + |
| 78 | +function check_playback_capture |
| 79 | +{ |
| 80 | + # check if capture and playback work |
| 81 | + dlogc "alsabat -P$pcm_p -C$pcm_c -c 2 -r $rate" |
| 82 | + alsabat -P"$pcm_p" -C"$pcm_c" -c 2 -r $rate || { |
| 83 | + # upload failed wav file |
| 84 | + __upload_wav_files |
| 85 | + dle "alsabat failed" |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +main() |
| 90 | +{ |
| 91 | + setup_kernel_check_point |
| 92 | + |
| 93 | + start_test |
| 94 | + |
| 95 | + if [ "$pcm_p" = "" ]||[ "$pcm_c" = "" ]; then |
| 96 | + dloge "No playback or capture PCM is specified. Skip the alsabat test." |
| 97 | + exit 2 |
| 98 | + fi |
| 99 | + |
| 100 | + # check if usbrelay tool is installed |
| 101 | + if ! command -v usbrelay >/dev/null 2>&1; then |
| 102 | + skip_test "usbrelay command not found. Please install usbrelay to control the mic privacy switch." |
| 103 | + fi |
| 104 | + |
| 105 | + check_locale_for_alsabat |
| 106 | + |
| 107 | + # reset sof volume to 0dB |
| 108 | + reset_sof_volume |
| 109 | + |
| 110 | + # If MODEL is defined, set proper gain for the platform |
| 111 | + if [ -z "$MODEL" ]; then |
| 112 | + # treat as warning only |
| 113 | + dlogw "NO MODEL is defined. Please define MODEL to run alsa_settings/MODEL.sh" |
| 114 | + else |
| 115 | + dlogi "apply alsa settings for alsa_settings/MODEL.sh" |
| 116 | + set_alsa_settings "$MODEL" |
| 117 | + fi |
| 118 | + |
| 119 | + logger_disabled || func_lib_start_log_collect |
| 120 | + |
| 121 | + dlogi "Turn off the mic privacy switch" |
| 122 | + usbrelay_switch "$relay" 0 |
| 123 | + |
| 124 | + # check the PCMs before mic privacy test |
| 125 | + dlogi "check the PCMs before mic privacy test" |
| 126 | + aplay -Dplug"$pcm_p" -d 1 /dev/zero -q || die "Failed to play on PCM: $pcm_p" |
| 127 | + arecord -Dplug"$pcm_c" -d 1 /dev/null -q || die "Failed to capture on PCM: $pcm_c" |
| 128 | + |
| 129 | + # Select the first card |
| 130 | + first_card_name=$(aplay -l | awk '/^card ([0-9]+)/ {print $3; exit}') |
| 131 | + # dump amixer contents always. |
| 132 | + # Good case amixer settings is for reference, bad case for debugging. |
| 133 | + amixer -c "${first_card_name}" contents > "$LOG_ROOT"/amixer_settings.txt |
| 134 | + |
| 135 | + check_playback_capture |
| 136 | + |
| 137 | + dlogi "Turn on the mic privacy switch" |
| 138 | + usbrelay_switch "$relay" 1 |
| 139 | + |
| 140 | + alsabat_output=$(mktemp) |
| 141 | + dlogc "alsabat -P$pcm_p -C$pcm_c -c 2 -r $rate" |
| 142 | + alsabat -P"$pcm_p" -C"$pcm_c" -c 2 -r $rate >"$alsabat_output" 2>&1 |
| 143 | + alsabat_status=$? |
| 144 | + |
| 145 | + if [ $alsabat_status -ne 0 ]; then |
| 146 | + if grep -q -e "Amplitude: 0.0; Percentage: \[0\]" -e "Return value is -1001" "$alsabat_output" |
| 147 | + then |
| 148 | + # Do nothing if signal is zero, this is expected |
| 149 | + # Return value is -1001 |
| 150 | + dlogi "Alsabat output indicates zero signal as expected." |
| 151 | + : |
| 152 | + else |
| 153 | + dloge "alsabat failed with status $alsabat_status, but signal is not zero." |
| 154 | + __upload_wav_files |
| 155 | + dle "alsabat failed with: $(cat "$alsabat_output")." |
| 156 | + fi |
| 157 | + else |
| 158 | + dloge "alsabat passed unexpectedly, upload the wav files." |
| 159 | + __upload_wav_files |
| 160 | + dle "MIC privacy doesn't work. alsabat output: $(cat "$alsabat_output")" |
| 161 | + fi |
| 162 | + |
| 163 | + dlogi "Turn off the mic privacy switch." |
| 164 | + usbrelay_switch "$relay" 0 |
| 165 | + |
| 166 | + check_playback_capture |
| 167 | + |
| 168 | + rm -f "$alsabat_output" |
| 169 | +} |
| 170 | + |
| 171 | +{ |
| 172 | + main "$@"; exit "$?" |
| 173 | +} |
0 commit comments