Skip to content

Commit a1fb70d

Browse files
committed
test: fix skipping: test-mic-privacy
Fix skip if no module named: usbrelay. Add skip if no relays hardware are detected. Add the new parameter to test: relay-settle-sleep by default = 1s Add loop to run more then 1 iteration. Signed-off-by: Artur Wilczak <arturx.wilczak@intel.com>
1 parent e6bff18 commit a1fb70d

File tree

2 files changed

+111
-79
lines changed

2 files changed

+111
-79
lines changed

case-lib/control_state.awk

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,42 @@
66
BEGIN {
77
IGNORECASE = 1
88
found = 0
9+
10+
# If show_capture_controls is set, use capture control display mode
11+
if (show_capture_controls) {
12+
capture_mode = 1
13+
} else {
14+
capture_mode = 0
15+
}
916
}
1017

11-
# Detect the line with the control name
12-
/name='/ {
18+
# Original functionality: Extract control state by name
19+
!capture_mode && /name='/ {
1320
if (tolower($0) ~ tolower(name)) found = 1
1421
else found = 0
1522
}
1623

17-
# When in a matching section, extract the "values" field
18-
found && /: values=/ {
24+
!capture_mode && found && /: values=/ {
1925
sub(/^.*: values=/, "", $0)
2026
print $0
2127
found = 0
2228
}
29+
30+
# New functionality: Show capture controls
31+
capture_mode && /^numid=/ {
32+
n=$0
33+
show = tolower($0) ~ /capture/
34+
capture_found = 0
35+
}
36+
37+
capture_mode && /type=BOOLEAN/ {
38+
t = $0
39+
if (show) capture_found = 1
40+
}
41+
42+
capture_mode && /: values=/ && capture_found {
43+
print n
44+
print t
45+
print $0
46+
capture_found = 0
47+
}

test-case/test-mic-privacy.sh

Lines changed: 82 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -41,37 +41,43 @@ source "${TESTLIB}/relay.sh"
4141
ALSABAT_WAV_FILES="/tmp/mc.wav.*"
4242
rm -f "$ALSABAT_WAV_FILES"
4343

44-
DSP_SETTLE_TIME=2
44+
OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
45+
OPT_HAS_ARG['l']=1 OPT_VAL['l']=1
4546

46-
OPT_NAME['p']='pcm_p' OPT_DESC['p']='pcm for playback. Example: hw:0,0'
47-
OPT_HAS_ARG['p']=1 OPT_VAL['p']='hw:0,0'
47+
OPT_NAME['p']='pcm_p' OPT_DESC['p']='pcm for playback. Example: hw:0,0'
48+
OPT_HAS_ARG['p']=1 OPT_VAL['p']='hw:0,0'
4849

49-
OPT_NAME['N']='channel_p' OPT_DESC['N']='channel number for playback.'
50-
OPT_HAS_ARG['N']=1 OPT_VAL['N']='2'
50+
OPT_NAME['N']='channel_p' OPT_DESC['N']='channel number for playback.'
51+
OPT_HAS_ARG['N']=1 OPT_VAL['N']='2'
5152

52-
OPT_NAME['c']='pcm_c' OPT_DESC['c']='pcm for capture. Example: hw:0,1'
53-
OPT_HAS_ARG['c']=1 OPT_VAL['c']='hw:0,1'
53+
OPT_NAME['c']='pcm_c' OPT_DESC['c']='pcm for capture. Example: hw:0,1'
54+
OPT_HAS_ARG['c']=1 OPT_VAL['c']='hw:0,1'
5455

55-
OPT_NAME['C']='channel_c' OPT_DESC['C']='channel number for capture.'
56-
OPT_HAS_ARG['C']=1 OPT_VAL['C']='2'
56+
OPT_NAME['C']='channel_c' OPT_DESC['C']='channel number for capture.'
57+
OPT_HAS_ARG['C']=1 OPT_VAL['C']='2'
5758

58-
OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
59-
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
59+
OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
60+
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
6061

61-
OPT_NAME['r']='rate' OPT_DESC['r']='sample rate'
62-
OPT_HAS_ARG['r']=1 OPT_VAL['r']=48000
62+
OPT_NAME['d']='relay-settle-sleep' OPT_DESC['d']="waiting time to stabilize after relay change state"
63+
OPT_HAS_ARG['d']=1 OPT_VAL['d']=1
6364

64-
OPT_NAME['u']='relay' OPT_DESC['u']='name of usbrelay switch, default value is HURTM_1'
65-
OPT_HAS_ARG['u']=1 OPT_VAL['u']='HURTM_1'
65+
OPT_NAME['r']='rate' OPT_DESC['r']='sample rate'
66+
OPT_HAS_ARG['r']=1 OPT_VAL['r']=48000
67+
68+
OPT_NAME['u']='relay' OPT_DESC['u']='name of usbrelay switch, default value is HURTM_1'
69+
OPT_HAS_ARG['u']=1 OPT_VAL['u']='HURTM_1'
6670

6771
func_opt_parse_option "$@"
6872

73+
loop_cnt=${OPT_VAL['l']}
6974
pcm_p=${OPT_VAL['p']}
7075
pcm_c=${OPT_VAL['c']}
7176
channel_c=${OPT_VAL['C']}
7277
channel_p=${OPT_VAL['N']}
7378
rate=${OPT_VAL['r']}
7479
relay=${OPT_VAL['u']}
80+
relay_settle_time=${OPT_VAL['d']}
7581

7682
dlogi "Params: pcm_p=$pcm_p, pcm_c=$pcm_c, channel_c=$channel_c, channel_p=$channel_p, rate=$rate, LOG_ROOT=$LOG_ROOT"
7783

@@ -88,13 +94,21 @@ __upload_wav_files()
8894

8995
check_playback_capture()
9096
{
97+
local expected_control_state
98+
expected_control_state=$1
99+
91100
# check if capture and playback work
92101
dlogc "alsabat -P$pcm_p -C$pcm_c -c 2 -r $rate"
93-
alsabat -P"$pcm_p" -C"$pcm_c" -c 2 -r "$rate" || {
94-
# upload failed wav file
95-
__upload_wav_files
96-
die "check_playback_capture() failed - check if a loopback is connected."
102+
alsabat_output=$(mktemp)
103+
alsabat_status=0
104+
alsabat -P"$pcm_p" -C"$pcm_c" -c 2 -r "$rate" > "$alsabat_output" 2>&1 || {
105+
alsabat_status=$?
97106
}
107+
108+
if [ "$alsabat_status" -ne "$expected_control_state" ]; then
109+
__upload_wav_files
110+
die "check_playback_capture() failed: expected alsabat status $expected_control_state, got $alsabat_status. See $alsabat_output for details."
111+
fi
98112
}
99113

100114
handle_alsabat_result()
@@ -125,23 +139,11 @@ handle_alsabat_result()
125139

126140
show_control_state()
127141
{
128-
dlogi "Current state of the mic privacy control:"
129-
amixer -c 0 contents | awk '
130-
/^numid=/ {
131-
n=$0
132-
show = tolower($0) ~ /capture/
133-
found = 0
134-
}
135-
/type=BOOLEAN/ {
136-
t = $0
137-
if (show) found = 1
138-
}
139-
/: values=/ && found {
140-
print n
141-
print t
142-
print $0
143-
found = 0
144-
}'
142+
local card=$1
143+
144+
dlogi "Current state of the capture switch controls:"
145+
amixer -c "$card" contents | \
146+
gawk -v name="" -v show_capture_controls=1 -f "${TESTLIB}/control_state.awk"
145147
}
146148

147149
main()
@@ -150,79 +152,84 @@ main()
150152

151153
start_test
152154

153-
logger_disabled || func_lib_start_log_collect
155+
dlogi "Checking usbrelay availability..."
156+
command -v usbrelay || {
157+
# If usbrelay package is not installed
158+
skip_test "usbrelay command not found."
159+
}
160+
161+
# display current status of relays
162+
usbrelay_switch --debug || {
163+
skip_test "Failed to initialize usbrelay hardware."
164+
}
154165

155166
if [ -z "$pcm_p" ] || [ -z "$pcm_c" ]; then
156167
skip_test "No playback or capture PCM is specified. Skip the $0 test."
157168
fi
158169

159-
# check if usbrelay tool is installed
160-
command -v usbrelay || {
161-
skip_test "usbrelay command not found. Please install usbrelay to control the mic privacy switch."
162-
}
163-
164170
dlogi "Current DSP status is $(sof-dump-status.py --dsp_status 0)" || {
165171
skip_test "platform doesn't support runtime pm, skip test case"
166172
}
167173

168-
dlogi "Starting preconditions check"
169-
170-
# display current status of relays
171-
usbrelay "--debug"
172-
173-
check_locale_for_alsabat
174+
logger_disabled || func_lib_start_log_collect
174175

175176
set_alsa
176177

177-
dlogi "Reset - Turn off the mic privacy"
178+
dlogi "Reset USB Relay - plug in audio jack."
178179
usbrelay_switch "$relay" 0
179180

180-
show_control_state
181-
182181
# wait for the switch to settle
183-
sleep "$DSP_SETTLE_TIME"
182+
sleep "$relay_settle_time"
184183

185184
# check the PCMs before mic privacy test
186-
dlogi "Check playback/capture before mic privacy test"
187-
check_playback_capture
185+
dlogi "Check playback/capture before audio privacy test"
186+
check_playback_capture 0
188187

189188
# select the first card
189+
local first_card_name
190190
first_card_name=$(aplay -l | awk '/^card ([0-9]+)/ {print $3; exit}')
191+
192+
show_control_state "$first_card_name"
193+
191194
# dump amixer contents always.
192195
# good case amixer settings is for reference, bad case for debugging.
193196
amixer -c "${first_card_name}" contents > "$LOG_ROOT"/amixer_settings.txt
194197

195-
check_playback_capture
198+
check_playback_capture 0
196199

197-
dlogi "Preconditions are met, starting mic privacy test"
200+
dlogi "Preconditions are met, starting audio privacy test"
198201

199-
sleep "$DSP_SETTLE_TIME"
202+
for i in $(seq 1 "$loop_cnt")
203+
do
204+
dlogi "===== Testing: Audio privacy (Round: $i/$loop_cnt) ====="
200205

201-
dlogi "===== Testing: MIC privacy ====="
202-
dlogi "Turn on the mic privacy switch"
203-
usbrelay_switch "$relay" 1
206+
dlogi "Turn ON the audio privacy switch"
207+
usbrelay_switch "$relay" 1
204208

205-
# wait for the switch to settle
206-
sleep "$DSP_SETTLE_TIME"
209+
# wait for the switch to settle
210+
dlogi "Wait for ${relay_settle_time}s to ensure audio privacy is enabled"
211+
sleep "$relay_settle_time"
207212

208-
alsabat_output=$(mktemp)
209-
dlogc "alsabat -P$pcm_p -C$pcm_c -c 2 -r $rate"
210-
# run alsabat and capture both output and exit status
211-
alsabat_status=0
212-
alsabat -P"$pcm_p" -C"$pcm_c" -c 2 -r "$rate" > "$alsabat_output" 2>&1 || {
213-
alsabat_status=$?
214-
}
213+
alsabat_output=$(mktemp)
214+
dlogc "alsabat -P$pcm_p -C$pcm_c -c 2 -r $rate"
215+
# run alsabat and capture both output and exit status
216+
alsabat_status=0
217+
alsabat -P"$pcm_p" -C"$pcm_c" -c 2 -r "$rate" > "$alsabat_output" 2>&1 || {
218+
alsabat_status=$?
219+
}
215220

216-
handle_alsabat_result
221+
handle_alsabat_result
217222

218-
dlogi "Turn off the mic privacy switch."
219-
usbrelay_switch "$relay" 0
223+
dlogi "Turn OFF the audio privacy switch."
224+
usbrelay_switch "$relay" 0
220225

221-
check_playback_capture
226+
dlogi "Wait for ${relay_settle_time}s to ensure audio privacy is disabled"
227+
sleep "$relay_settle_time"
222228

223-
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT"
229+
check_playback_capture 0
224230

225-
dlogi "===== Test completed successfully. ====="
231+
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT"
232+
done
226233

227234
rm -rf "$alsabat_output"
228235
}

0 commit comments

Comments
 (0)