Skip to content

Commit dba4f4a

Browse files
committed
test-case: add new test case for check mic privacy
Add new test case to check hardware mic privacy mode enablement feature. For switching mic privacy state is using a USB relay. https://github.com/darrylb123/usbrelay Signed-off-by: Artur Wilczak <arturx.wilczak@intel.com>
1 parent 20a47bc commit dba4f4a

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed

test-case/test-mic-privacy.sh

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

0 commit comments

Comments
 (0)