@@ -41,37 +41,43 @@ source "${TESTLIB}/relay.sh"
4141ALSABAT_WAV_FILES=" /tmp/mc.wav.*"
4242rm -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 stable 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
6771func_opt_parse_option " $@ "
6872
73+ loop_cnt=${OPT_VAL['l']}
6974pcm_p=${OPT_VAL['p']}
7075pcm_c=${OPT_VAL['c']}
7176channel_c=${OPT_VAL['C']}
7277channel_p=${OPT_VAL['N']}
7378rate=${OPT_VAL['r']}
7479relay=${OPT_VAL['u']}
80+ relay_settle_time=${OPT_VAL['d']}
7581
7682dlogi " Params: pcm_p=$pcm_p , pcm_c=$pcm_c , channel_c=$channel_c , channel_p=$channel_p , rate=$rate , LOG_ROOT=$LOG_ROOT "
7783
@@ -150,37 +156,38 @@ main()
150156
151157 start_test
152158
153- logger_disabled || func_lib_start_log_collect
159+ dlogi " Checking usbrelay availability..."
160+ command -v usbrelay || {
161+ # If usbrelay package is not installed
162+ skip_test " usbrelay command not found."
163+ }
164+
165+ # display current status of relays
166+ usbrelay_switch --debug || {
167+ skip_test " Failed to initialize usbrelay hardware."
168+ }
154169
155170 if [ -z " $pcm_p " ] || [ -z " $pcm_c " ]; then
156171 skip_test " No playback or capture PCM is specified. Skip the $0 test."
157172 fi
158173
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-
164174 dlogi " Current DSP status is $( sof-dump-status.py --dsp_status 0) " || {
165175 skip_test " platform doesn't support runtime pm, skip test case"
166176 }
167177
168- dlogi " Starting preconditions check"
169-
170- # display current status of relays
171- usbrelay " --debug"
178+ logger_disabled || func_lib_start_log_collect
172179
173180 check_locale_for_alsabat
174181
175182 set_alsa
176183
177- dlogi " Reset - Turn off the mic privacy "
184+ dlogi " Reset USB Relay - plug jack audio. "
178185 usbrelay_switch " $relay " 0
179186
180187 show_control_state
181188
182189 # wait for the switch to settle
183- sleep " $DSP_SETTLE_TIME "
190+ sleep " $relay_settle_time "
184191
185192 # check the PCMs before mic privacy test
186193 dlogi " Check playback/capture before mic privacy test"
@@ -196,33 +203,37 @@ main()
196203
197204 dlogi " Preconditions are met, starting mic privacy test"
198205
199- sleep " $DSP_SETTLE_TIME "
206+ for i in $( seq 1 " $loop_cnt " )
207+ do
208+ dlogi " ===== Testing: MIC privacy (Round: $i /$loop_cnt ) ====="
200209
201- dlogi " ===== Testing: MIC privacy ====="
202- dlogi " Turn on the mic privacy switch"
203- usbrelay_switch " $relay " 1
210+ dlogi " Turn on the mic privacy switch"
211+ usbrelay_switch " $relay " 1
204212
205- # wait for the switch to settle
206- sleep " $DSP_SETTLE_TIME "
213+ # wait for the switch to settle
214+ dlogi " Wait for ${relay_settle_time} s to ensure mic privacy is enabled"
215+ sleep " $relay_settle_time "
207216
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- }
217+ alsabat_output=$( mktemp)
218+ dlogc " alsabat -P$pcm_p -C$pcm_c -c 2 -r $rate "
219+ # run alsabat and capture both output and exit status
220+ alsabat_status=0
221+ alsabat -P" $pcm_p " -C" $pcm_c " -c 2 -r " $rate " > " $alsabat_output " 2>&1 || {
222+ alsabat_status=$?
223+ }
215224
216- handle_alsabat_result
225+ handle_alsabat_result
217226
218- dlogi " Turn off the mic privacy switch."
219- usbrelay_switch " $relay " 0
227+ dlogi " Turn off the mic privacy switch."
228+ usbrelay_switch " $relay " 0
220229
221- check_playback_capture
230+ dlogi " Wait for ${relay_settle_time} s to ensure mic privacy is disabled"
231+ sleep " $relay_settle_time "
222232
223- sof-kernel-log-check.sh " $KERNEL_CHECKPOINT "
233+ check_playback_capture 0
224234
225- dlogi " ===== Test completed successfully. ====="
235+ sof-kernel-log-check.sh " $KERNEL_CHECKPOINT "
236+ done
226237
227238 rm -rf " $alsabat_output "
228239}
0 commit comments