@@ -100,32 +100,123 @@ function __upload_wav_file
100100 done
101101}
102102
103- # check the PCMs before alsabat test
104- dlogi " check the PCMs before alsabat test"
105- aplay " -Dplug${pcm_p} " -d 1 /dev/zero -q || die " Failed to play on PCM: ${pcm_p} "
106- arecord " -Dplug${pcm_c} " -d 1 /dev/null -q || die " Failed to capture on PCM: ${pcm_c} "
107-
108- # alsabat test
109- # BT offload PCMs also support mono playback.
110- dlogc " alsabat -P$pcm_p --standalone -n $frames -r $rate -c $channel_p -f $format -F $frequency -k $sigmak "
111- alsabat " -P${pcm_p} " --standalone -n " ${frames} " -c " ${channel_p} " -r " ${rate} " -f " ${format} " -F " ${frequency} " -k " ${sigmak} " & playPID=$!
112-
113- # playback may have low latency, add one second delay to aviod recording zero at beginning.
114- sleep 1
115-
116- # Select the first card
117- first_card_name=$( aplay -l | awk ' /^card ([0-9]+)/ {print $3; exit}' )
118- # dump amixer contents always.
119- # Good case amixer settings is for reference, bad case for debugging.
120- amixer -c " ${first_card_name} " contents > " $LOG_ROOT " /amixer_settings.txt
121-
122- # We use different USB sound cards in CI, part of them only support 1 channel for capture,
123- # so make the channel as an option and config it in alsabat-playback.csv
124- dlogc " alsabat -C$pcm_c -c $channel_c -r $rate -f $format -F $frequency -k $sigmak "
125- alsabat " -C${pcm_c} " -c " ${channel_c} " -r " ${rate} " -f " ${format} " -F " ${frequency} " -k " ${sigmak} " || {
126- # upload failed wav file
127- __upload_wav_file
128- exit 1
103+ # Set default pipewire sink and source
104+ set_pcms_in_pipewire ()
105+ {
106+ if [[ " $TPLG " == * " nocodec" * ]]; then
107+ sink=" sof-nocodec"
108+ source=" sof-nocodec"
109+ elif [[ " $TPLG " == * " hda" * ]]; then
110+ sink=" Headphones" # confirm that
111+ source=" Audio Codec Analog"
112+ elif [[ " $TPLG " == * " sdw" * ]]; then
113+ sink=" Headphones" # confirm that
114+ source=" Audio Codec Analog"
115+ else
116+ skip_test " Test not supported for this configuration"
117+ fi
118+
119+ # Set default sink
120+ sink_id=$( get_id_of_pipewire_endpoint " $sink " )
121+ if [ -z " $sink_id " ]; then
122+ die " Expected pipewire sink not found"
123+ fi
124+ dlogi " Setting default pipewire sink to $sink_id : $sink "
125+ wpctl set-default $sink_id
126+
127+ # Set default source
128+ source_id=$( get_id_of_pipewire_source " $source " )
129+ if [ -z " $source_id " ]; then
130+ die " Expected pipewire source not found"
131+ fi
132+ dlogi " Setting default pipewire source to $source_id : $source "
133+ wpctl set-default $source_id
134+ }
135+
136+ check_the_pcms ()
137+ {
138+ aplay " -Dplug${pcm_p} " -d 1 /dev/zero -q || die " Failed to play on PCM: ${pcm_p} "
139+ arecord " -Dplug${pcm_c} " -d 1 /dev/null -q || die " Failed to capture on PCM: ${pcm_c} "
140+ }
141+
142+ check_the_pcms_with_pipewire ()
143+ {
144+ aplay -D pipewire -d 1 /dev/zero -q || die " Failed to play on pipewire"
145+ arecord -D pipewire -d 1 /dev/null -q || die " Failed to capture on pipewire"
146+ }
147+
148+ run_test_on_pipewire ()
149+ {
150+ # Set correct sink and source in pipewire
151+ set_pcms_in_pipewire
152+
153+ # check the PCMs before alsabat test
154+ check_the_pcms_with_pipewire
155+
156+ # alsabat test
157+ # when ran without specified PCM, alsabat does playback and capture in one command
158+ dlogc " alsabat -n $frames -r $rate -c $channel_p -f $format -F $frequency -k $sigmak "
159+ alsabat -n " ${frames} " -c " ${channel_p} " -r " ${rate} " -f " ${format} " -F " ${frequency} " -k " ${sigmak} " || {
160+ # upload failed wav file
161+ __upload_wav_file
162+ exit 1
163+ }
129164}
130165
131- wait $playPID
166+ run_test_on_alsa_direct_mode ()
167+ {
168+ # check the PCMs before alsabat test
169+ check_the_pcms
170+
171+ # alsabat test
172+ # BT offload PCMs also support mono playback.
173+ dlogc " alsabat -P$pcm_p --standalone -n $frames -r $rate -c $channel_p -f $format -F $frequency -k $sigmak "
174+ alsabat " -P${pcm_p} " --standalone -n " ${frames} " -c " ${channel_p} " -r " ${rate} " -f " ${format} " -F " ${frequency} " -k " ${sigmak} " & playPID=$!
175+
176+ # playback may have low latency, add one second delay to aviod recording zero at beginning.
177+ sleep 1
178+
179+ # Select the first card
180+ first_card_name=$( aplay -l | awk ' /^card ([0-9]+)/ {print $3; exit}' )
181+ # dump amixer contents always.
182+ # Good case amixer settings is for reference, bad case for debugging.
183+ amixer -c " ${first_card_name} " contents > " $LOG_ROOT " /amixer_settings.txt
184+
185+ # We use different USB sound cards in CI, part of them only support 1 channel for capture,
186+ # so make the channel as an option and config it in alsabat-playback.csv
187+ dlogc " alsabat -C$pcm_c -c $channel_c -r $rate -f $format -F $frequency -k $sigmak "
188+ alsabat " -C${pcm_c} " -c " ${channel_c} " -r " ${rate} " -f " ${format} " -F " ${frequency} " -k " ${sigmak} " || {
189+ # upload failed wav file
190+ __upload_wav_file
191+ exit 1
192+ }
193+
194+ wait $playPID
195+ }
196+
197+ main ()
198+ {
199+ start_test
200+
201+ if [ " $pcm_p " = " " ]|| [ " $pcm_c " = " " ];
202+ then
203+ dloge " No playback or capture PCM is specified. Skip the alsabat test"
204+ exit 2
205+ fi
206+
207+ check_locale_for_alsabat
208+
209+ logger_disabled || func_lib_start_log_collect
210+
211+ set_alsa
212+
213+ if [ " $SOF_TEST_PIPEWIRE " == true ]; then
214+ run_test_on_pipewire
215+ else
216+ run_test_on_alsa_direct_mode
217+ fi
218+ }
219+
220+ {
221+ main " $@ " ; exit " $? "
222+ }
0 commit comments