Skip to content

Commit b4ed875

Browse files
committed
check-alsabat: add option to test with pipewire
1 parent a9f04af commit b4ed875

File tree

3 files changed

+146
-47
lines changed

3 files changed

+146
-47
lines changed

case-lib/lib.sh

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ func_lib_enable_pipewire()
588588
systemctl --user start wireplumber.service
589589

590590
systemctl --user daemon-reload
591+
sleep 1
591592

592593
systemctl is-active --user --quiet pipewire{,-pulse}.{socket,service} && dlogi "Pipewire started"
593594
systemctl is-active --user --quiet wireplumber.service && dlogi "Wireplumber started"
@@ -951,15 +952,9 @@ aplay_opts()
951952
# shellcheck disable=SC2086
952953
tinyplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS -D "$card_nr" -d "$dev_nr" -i wav noise.wav
953954
elif [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
954-
if [[ "$SOF_TEST_PIPEWIRE" == true ]]; then
955-
dlogc "timeout -k $duration $duration aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $*" # option -d doesn't work with pipewire so we need timeout
956-
# shellcheck disable=SC2086
957-
timeout -k "$duration" "$duration" aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
958-
else
959-
dlogc "aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $*"
960-
# shellcheck disable=SC2086
961-
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
962-
fi
955+
dlogc "aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $*"
956+
# shellcheck disable=SC2086
957+
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
963958
else
964959
die "Unknown ALSA tool: ${SOF_ALSA_TOOL}"
965960
fi
@@ -976,20 +971,33 @@ arecord_opts()
976971
# shellcheck disable=SC2086
977972
tinycap $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$file" -D "$card_nr" -d "$dev_nr" -c "$channel" -t "$duration" -r "$rate" -b "$format"
978973
elif [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
979-
if [[ "$SOF_TEST_PIPEWIRE" == true ]]; then
980-
dlogc "timeout -k $duration $duration arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*" # option -d doesn't work with pipewire so we need timeout
981-
# shellcheck disable=SC2086
982-
timeout -k "$duration" "$duration" arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
983-
else
984-
dlogc "arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*"
985-
# shellcheck disable=SC2086
986-
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
987-
fi
974+
dlogc "arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*"
975+
# shellcheck disable=SC2086
976+
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
988977
else
989978
die "Unknown ALSA tool: ${SOF_ALSA_TOOL}"
990979
fi
991980
}
992981

982+
# Get the ID of the first source of a given type, e.g. "Microphone" or "Audio codec". Print an empty line if ID not found.
983+
get_id_of_pipewire_source()
984+
{
985+
# $ wpctl status returns list of all endpoints managed by wireplumber. We use grep to get only lines after "Sources".
986+
# Then we filter by given sink/source type, which returns something like this:
987+
# │ * 48. sof-soundwire Microphone [vol: 0.40] (or without the * when it's not the current default)
988+
# We filter out everything but ID, and only take the first line of the output (if there's more that one object of that type we ignore the rest)
989+
990+
local object_name="$1"
991+
object_id=$(wpctl status | grep "Sources" -A 10 | awk -v name="$object_name" 'tolower($0) ~ tolower(name) { sub(/\*/,""); sub(/\./,"",$2); print $2; exit }')
992+
993+
# Check if object_id is a number
994+
re='^[0-9]+$'
995+
if [[ "$object_id" =~ $re ]] ; then
996+
printf '%s' "$object_id"
997+
fi
998+
999+
}
1000+
9931001
# Get the ID of the first sink/source of a given type, e.g. "Speaker" or "Headphones". Print an empty line if ID not found.
9941002
get_id_of_pipewire_endpoint()
9951003
{

test-case/check-alsabat.sh

Lines changed: 118 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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 Stereo"
108+
source="sof-nocodec Stereo"
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+
}

test-case/check-performance.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ run_aplays()
5959
fi
6060
dlogi "Setting default sink to $sink_id: $sink_type"
6161
wpctl set-default "$sink_id"
62-
aplay_opts -D pipewire /dev/zero -q &
62+
aplay_opts -D pipewire /dev/zero -d "$duration" -q &
6363
aplay_num=$((aplay_num+1))
6464
done
6565
}
@@ -78,7 +78,7 @@ run_arecords()
7878
fi
7979
dlogi "Setting default source to $source_id: $source_type"
8080
wpctl set-default "$source_id"
81-
arecord_opts -D pipewire /dev/null -q &
81+
arecord_opts -D pipewire /dev/null -d "$duration" -q &
8282
arecord_num=$((arecord_num+1))
8383
done
8484
}

0 commit comments

Comments
 (0)