Skip to content

Commit 2b11298

Browse files
committed
separate some code into functions
1 parent 9deef49 commit 2b11298

2 files changed

Lines changed: 40 additions & 13 deletions

File tree

case-lib/lib.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,18 @@ arecord_opts()
10001000
fi
10011001
}
10021002

1003+
# Get the ID for a given sink or source type, e.g. "Speaker" or "Headphones"
1004+
get_id_of_pipewire_endpoint()
1005+
{
1006+
# $ wpctl status returns list of all endpoints managed by wireplumber. We filter by given sink/source type, which returns something like this:
1007+
# │ * 48. sof-soundwire Headphones [vol: 0.40] (or without the * when it's not the current default)
1008+
# 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)
1009+
1010+
local object_name="$1"
1011+
object_id=$(wpctl status | grep -i "$object_name" | tr -d '*' | awk '{print $2}' | tr -d '.' | head -n 1)
1012+
echo $object_id
1013+
}
1014+
10031015
die()
10041016
{
10051017
dloge "$@"

test-case/check-performance.sh

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
set -e
2222

23+
PIPEWIRE_OUTPUTS=("Speaker" "Headphones" "HDMI")
24+
PIPEWIRE_INPUTS=("Digital Microphone" "Headset Microphone" "SoundWire microphones")
25+
2326
# It is pointless to perf component in HDMI pipeline, so filter out HDMI pipelines
2427
# shellcheck disable=SC2034
2528
NO_HDMI_MODE=true
@@ -51,14 +54,14 @@ func_pipeline_export "$tplg" "type:any"
5154
aplay_num=0
5255
arecord_num=0
5356

54-
if [ "$SOF_TEST_PIPEWIRE" == true ]; then
55-
56-
# aplay's for sinks
57-
pw_outputs_list=("Speaker" "Headphones" "HDMI")
57+
# run aplay for all sink types given as a parameter and save the number of started aplay processes
58+
run_aplays()
59+
{
60+
local sinks=("$@")
5861

59-
for sink_type in "${pw_outputs_list[@]}"
62+
for sink_type in "${sinks[@]}"
6063
do
61-
sink_id=$(wpctl status | grep -A6 "Sinks" | grep -A3 -i "$sink_type" | tr -d '*' | awk '{print $2}' | tr -d '.' | head -n 1)
64+
sink_id=$(get_id_of_pipewire_endpoint "$sink_type")
6265
if [ -z "$sink_id" ]; then
6366
dlogi "No $sink_type found, skipping to the next one"
6467
continue
@@ -68,25 +71,37 @@ if [ "$SOF_TEST_PIPEWIRE" == true ]; then
6871
aplay_opts -Ddefault /dev/zero -q &
6972
aplay_num=$((aplay_num+1))
7073
done
74+
}
7175

72-
# arecord's for sources
73-
pw_inputs_list=("Digital Microphone" "Headset Microphone" "SoundWire microphones")
76+
# run arecord for all source types given as a parameter and save the number of started arecord processes
77+
run_arecords()
78+
{
79+
local sources=("$@")
7480

75-
for source_type in "${pw_inputs_list[@]}"
81+
for source_type in "${sources[@]}"
7682
do
77-
source_id=$(wpctl status | grep -A6 "Sources" | grep -A3 -i "$source_type" | tr -d '*' | awk '{print $2}' | tr -d '.' | head -n 1)
83+
source_id=$(get_id_of_pipewire_endpoint "$source_type")
7884
if [ -z "$source_id" ]; then
7985
dlogi "No $source_type found, skipping to the next one"
80-
continue # skip if that device type isn't available
86+
continue
8187
fi
8288
dlogi "Setting default source to $source_id: $source_type"
8389
wpctl set-default "$source_id"
8490
arecord_opts -Ddefault /dev/zero -q &
8591
arecord_num=$((arecord_num+1))
8692
done
93+
}
94+
95+
if [ "$SOF_TEST_PIPEWIRE" == true ]; then
96+
97+
dlogi "Running aplays"
98+
run_aplays "${PIPEWIRE_OUTPUTS[@]}"
99+
dlogi "Running arecords"
100+
run_arecords "${PIPEWIRE_INPUTS[@]}"
101+
dlogi "Done"
87102

88-
if [ $aplay_num == 0 ] && [ $arecord_num == 0 ]; then
89-
skip_test "No sinks/sources to be tested found, exiting test"
103+
if [ "$aplay_num" == 0 ] && [ "$arecord_num" == 0 ]; then
104+
skip_test "No sinks/sources to be tested found, skipping test"
90105
fi
91106

92107
else

0 commit comments

Comments
 (0)