Skip to content

Commit 90caf71

Browse files
committed
volume_basic_test: add tinymix support and refactor to use lib.sh
Refactor the volume_basic_test to use lib.sh instead of calling ALSA commands directly, and add support for the tinymix command from TinyALSA. Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
1 parent fdd7ae4 commit 90caf71

File tree

2 files changed

+104
-50
lines changed

2 files changed

+104
-50
lines changed

case-lib/lib.sh

Lines changed: 94 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,90 @@ initialize_audio_params()
797797
fi
798798
}
799799

800+
set_sof_volume()
801+
{
802+
local device=$1
803+
local control_name=$2
804+
local value=$3
805+
806+
case "$SOF_ALSA_TOOL" in
807+
'alsa')
808+
dlogc "amixer -c$device' cset 'name=$control_name' '$value'"
809+
amixer -c"$device" cset name="$control_name" "$value"
810+
;;
811+
'tinyalsa')
812+
dlogc "tinymix -D'$device' set '$control_name' '$value'"
813+
tinymix -D"$device" set "$control_name" "$value"
814+
;;
815+
*)
816+
die "Unknown alsa tool $SOF_ALSA_TOOL"
817+
;;
818+
esac
819+
}
820+
821+
get_sof_controls()
822+
{
823+
local sofcard=$1
824+
825+
case "$SOF_ALSA_TOOL" in
826+
'alsa')
827+
amixer -c"$sofcard" scontrols
828+
;;
829+
'tinyalsa')
830+
tinymix --card "$sofcard" controls
831+
;;
832+
*)
833+
die "Unknown alsa tool $SOF_ALSA_TOOL"
834+
;;
835+
esac
836+
}
837+
838+
kill_play_record()
839+
{
840+
dloge "$*"
841+
case "$SOF_ALSA_TOOL" in
842+
'alsa')
843+
pkill -9 aplay
844+
;;
845+
'tinyalsa')
846+
pkill -9 tinyplay
847+
;;
848+
*)
849+
die "Unknown alsa tool $SOF_ALSA_TOOL"
850+
;;
851+
esac
852+
}
853+
854+
kill_playrecord_die()
855+
{
856+
kill_play_record "&@"
857+
die "$1"
858+
}
859+
860+
check_alsa_tool_process()
861+
{
862+
case "$SOF_ALSA_TOOL" in
863+
"alsa")
864+
# Check if the aplay process is running
865+
pidof -q aplay ||
866+
die "aplay process is terminated too early"
867+
;;
868+
"tinyalsa")
869+
# Check if the tinyplay process is running
870+
pidof -q tinyplay ||
871+
die "tinyplay process is terminated too early"
872+
;;
873+
*)
874+
die "Unknown alsa tool $SOF_ALSA_TOOL"
875+
;;
876+
esac
877+
}
878+
800879
aplay_opts()
801880
{
802881
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
882+
# Duration of playing white noise while testing under tinyalsa
883+
duration=50
803884
# shellcheck disable=SC2154
804885
if ! sox -n -r "$rate" -c "$channel" noise.wav synth "$duration" white; then
805886
printf 'Error: sox command failed.\n' >&2
@@ -1133,34 +1214,21 @@ set_alsa_settings()
11331214

11341215
reset_sof_volume()
11351216
{
1217+
level_db=$(if is_ipc4; then echo "100%"; else echo "0dB"; fi)
11361218
# set all PGA* volume to 0dB
1137-
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
1138-
amixer -Dhw:0 scontrols | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1139-
1140-
while read -r mixer_name
1141-
do
1142-
if is_ipc4; then
1143-
amixer -Dhw:0 -- sset "$mixer_name" 100%
1144-
else
1145-
amixer -Dhw:0 -- sset "$mixer_name" 0dB
1146-
fi
1147-
done
1148-
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
1149-
tinymix -D0 controls | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1150-
1151-
while read -r mixer_name
1152-
do
1153-
if is_ipc4; then
1154-
tinymix -D0 set "$mixer_name" 100%
1155-
else
1156-
tinymix -D0 set "$mixer_name" 0dB
1157-
fi
1158-
done
1159-
else
1160-
echo "Unknown alsa tool $SOF_ALSA_TOOL"
1161-
fi
1219+
get_sof_controls "0" | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1220+
while read -r mixer_name
1221+
do
1222+
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
1223+
amixer -Dhw:0 -- sset "$mixer_name" "$level_db"
1224+
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
1225+
tinymix -D0 set "$mixer_name" "$level_db"
1226+
else
1227+
echo "Unknown alsa tool $SOF_ALSA_TOOL"
1228+
break
1229+
fi
1230+
done
11621231
}
1163-
11641232
DO_PERF_ANALYSIS=0
11651233

11661234
perf_analyze()

test-case/volume-basic-test.sh

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,28 @@ maxloop=${OPT_VAL['l']}
3939

4040
start_test
4141

42-
func_error_exit()
43-
{
44-
dloge "$*"
45-
pkill -9 aplay
46-
exit 1
47-
}
48-
4942
[[ -z $tplg ]] && die "Missing tplg file needed to run"
5043
func_pipeline_export "$tplg" "type:playback"
5144
logger_disabled || func_lib_start_log_collect
5245

5346
[[ $PIPELINE_COUNT -eq 0 ]] && die "Missing playback pipeline for aplay to run"
54-
channel=$(func_pipeline_parse_value 0 channel)
55-
rate=$(func_pipeline_parse_value 0 rate)
56-
fmt=$(func_pipeline_parse_value 0 fmt)
57-
dev=$(func_pipeline_parse_value 0 dev)
5847

59-
dlogc "aplay -D $dev -c $channel -r $rate -f $fmt /dev/zero &"
48+
initialize_audio_params "0"
6049
# play into background, this will wake up DSP and IPC. Need to clean after the test
61-
aplay -D "$dev" -c "$channel" -r "$rate" -f "$fmt" /dev/zero &
62-
50+
aplay_opts -D "$dev" -c "$channel" -r "$rate" -f "$fmts" /dev/zero &
6351
sleep 1
64-
[[ ! $(pidof aplay) ]] && die "aplay process is terminated too early"
65-
52+
check_alsa_tool_process
6653
sofcard=${SOFCARD:-0}
6754

6855
# https://mywiki.wooledge.org/BashFAQ/024 why cant I pipe data to read?
6956
readarray -t pgalist < <("$TOPDIR"/tools/topo_vol_kcontrols.py "$tplg")
7057

7158
# This (1) provides some logging (2) avoids skip_test if amixer fails
72-
amixer -c"$sofcard" controls
59+
get_sof_controls "$sofcard"
7360
dlogi "pgalist number = ${#pgalist[@]}"
7461
[[ ${#pgalist[@]} -ne 0 ]] || skip_test "No PGA control is available"
7562

76-
for i in $(seq 1 $maxloop)
63+
for i in $(seq 1 "$maxloop")
7764
do
7865
setup_kernel_check_point
7966
dlogi "===== Round($i/$maxloop) ====="
@@ -83,21 +70,20 @@ do
8370
dlogi "$volctrl"
8471

8572
for vol in "${volume_array[@]}"; do
86-
dlogc "amixer -c$sofcard cset name='$volctrl' $vol"
87-
amixer -c"$sofcard" cset name="$volctrl" "$vol" > /dev/null ||
88-
func_error_exit "amixer return error, test failed"
73+
set_sof_volume "$sofcard" "$volctrl" "$vol" ||
74+
kill_playrecord_die "mixer return error, test failed"
8975
done
9076
done
9177

9278
sleep 1
9379

9480
dlogi "check dmesg for error"
9581
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" ||
96-
func_error_exit "dmesg has errors!"
82+
kill_playrecord_die "dmesg has errors!"
9783
done
9884

99-
#clean up background aplay
100-
pkill -9 aplay || true
85+
#clean up background play record
86+
kill_play_record || true
10187

10288
dlogi "Reset all PGA volume to 0dB"
10389
reset_sof_volume || die "Failed to reset some PGA volume to 0dB."

0 commit comments

Comments
 (0)