Skip to content

Commit 9675aae

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 9675aae

1 file changed

Lines changed: 165 additions & 0 deletions

File tree

test-case/test-mic-privacy.sh

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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" = "" ];
64+
then
65+
dloge "No playback or capture PCM is specified. Skip the alsabat test"
66+
exit 2
67+
fi
68+
69+
# check if usbrelay tool is installed
70+
if ! command -v usbrelay >/dev/null 2>&1; then
71+
dloge "usbrelay command not found. Please install usbrelay to control the mic privacy switch."
72+
exit 2
73+
fi
74+
75+
check_locale_for_alsabat
76+
77+
# reset sof volume to 0dB
78+
reset_sof_volume
79+
80+
# If MODEL is defined, set proper gain for the platform
81+
if [ -z "$MODEL" ]; then
82+
# treat as warning only
83+
dlogw "NO MODEL is defined. Please define MODEL to run alsa_settings/MODEL.sh"
84+
else
85+
dlogi "apply alsa settings for alsa_settings/MODEL.sh"
86+
set_alsa_settings "$MODEL"
87+
fi
88+
89+
logger_disabled || func_lib_start_log_collect
90+
91+
function __upload_wav_file
92+
{
93+
# upload the alsabat wav file
94+
for file in /tmp/mc.wav.*; do
95+
# alsabat has a bug where it creates an empty record in playback mode
96+
if test -s "$file"; then
97+
cp "$file" "$LOG_ROOT/"
98+
fi
99+
done
100+
}
101+
102+
# check if usbrelay works and relays hardware is connected
103+
usbrelay_output=$(usbrelay 2>/dev/null)
104+
if [ $? -ne 0 ] || [ -z "$usbrelay_output" ]; then
105+
dloge "usbrelay is not responding or no relays detected. Check hardware connection."
106+
exit 1
107+
fi
108+
109+
dlogi "Turn off the mic privacy switch"
110+
usbrelay HURTM_1=0
111+
# wait for the mic privacy switch to be off
112+
sleep 0.5
113+
114+
# check the PCMs before mic privacy test
115+
dlogi "check the PCMs before mic privacy test"
116+
aplay -Dplug$pcm_p -d 1 /dev/zero -q || die "Failed to play on PCM: $pcm_p"
117+
arecord -Dplug$pcm_c -d 1 /dev/null -q || die "Failed to capture on PCM: $pcm_c"
118+
119+
# Select the first card
120+
first_card_name=$(aplay -l | awk '/^card ([0-9]+)/ {print $3; exit}')
121+
# dump amixer contents always.
122+
# Good case amixer settings is for reference, bad case for debugging.
123+
amixer -c "${first_card_name}" contents > "$LOG_ROOT"/amixer_settings.txt
124+
125+
# check if capture and playback work
126+
# BT offload PCMs also support mono playback.
127+
dlogc "alsabat -P$pcm_p -C$pcm_c -c 2 -r $rate"
128+
alsabat -P$pcm_p -C$pcm_c -c 2 -r $rate || {
129+
# upload failed wav file
130+
__upload_wav_file
131+
exit 1
132+
}
133+
134+
dlogi "Turn on the mic privacy switch"
135+
usbrelay HURTM_1=1
136+
# wait for the mic privacy switch to be on
137+
sleep 1
138+
139+
alsabat_output=$(mktemp)
140+
dlogc "alsabat -P$pcm_p -C$pcm_c -c 2 -r $rate"
141+
alsabat -P$pcm_p -C$pcm_c -c 2 -r $rate >"$alsabat_output" 2>&1
142+
alsabat_status=$?
143+
144+
dlogi "Turn off the mic privacy switch."
145+
usbrelay HURTM_1=0
146+
147+
if [ $alsabat_status -ne 0 ]; then
148+
if grep -q -e "Amplitude: 0.0; Percentage: \[0\]" -e "Return value is -1001" "$alsabat_output"
149+
then
150+
# Do nothing if signal is zero, this is expected
151+
# Return value is -1001
152+
dlogi "Alsabat output indicates zero signal as expected."
153+
:
154+
else
155+
dloge "alsabat failed with status $alsabat_status, but signal is not zero."
156+
__upload_wav_file
157+
dloge "alsabat output: $(cat "$alsabat_output")."
158+
exit 1
159+
fi
160+
else
161+
dloge "alsabat passed, upload the wav files."
162+
dloge "alsabat output: $(cat "$alsabat_output")"
163+
exit 1
164+
fi
165+
rm -f "$alsabat_output"

0 commit comments

Comments
 (0)