Skip to content

Commit 4a5a1d9

Browse files
gbarkadiuszgolowanow
authored andcommitted
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 a16ce69 commit 4a5a1d9

File tree

2 files changed

+106
-50
lines changed

2 files changed

+106
-50
lines changed

case-lib/lib.sh

Lines changed: 96 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,92 @@ 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+
# Used `scontrols` instead of `controls`.
828+
# Using `controls` causes issues on some platforms when trying to access unavailable controls during setting.
829+
amixer -c"$sofcard" scontrols
830+
;;
831+
'tinyalsa')
832+
tinymix --card "$sofcard" controls
833+
;;
834+
*)
835+
die "Unknown alsa tool $SOF_ALSA_TOOL"
836+
;;
837+
esac
838+
}
839+
840+
kill_play_record()
841+
{
842+
dloge "$*"
843+
case "$SOF_ALSA_TOOL" in
844+
'alsa')
845+
pkill -9 aplay
846+
;;
847+
'tinyalsa')
848+
pkill -9 tinyplay
849+
;;
850+
*)
851+
die "Unknown alsa tool $SOF_ALSA_TOOL"
852+
;;
853+
esac
854+
}
855+
856+
kill_playrecord_die()
857+
{
858+
kill_play_record "&@"
859+
die "$1"
860+
}
861+
862+
check_alsa_tool_process()
863+
{
864+
case "$SOF_ALSA_TOOL" in
865+
"alsa")
866+
# Check if the aplay process is running
867+
pidof -q aplay ||
868+
die "aplay process is terminated too early"
869+
;;
870+
"tinyalsa")
871+
# Check if the tinyplay process is running
872+
pidof -q tinyplay ||
873+
die "tinyplay process is terminated too early"
874+
;;
875+
*)
876+
die "Unknown alsa tool $SOF_ALSA_TOOL"
877+
;;
878+
esac
879+
}
880+
800881
aplay_opts()
801882
{
802883
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
884+
# Duration of playing white noise while testing under tinyalsa
885+
duration=50
803886
# shellcheck disable=SC2154
804887
if ! sox -n -r "$rate" -c "$channel" noise.wav synth "$duration" white; then
805888
printf 'Error: sox command failed.\n' >&2
@@ -1133,34 +1216,21 @@ set_alsa_settings()
11331216

11341217
reset_sof_volume()
11351218
{
1219+
level_db=$(if is_ipc4; then echo "100%"; else echo "0dB"; fi)
11361220
# 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
1221+
get_sof_controls "0" | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1222+
while read -r mixer_name
1223+
do
1224+
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
1225+
amixer -Dhw:0 -- sset "$mixer_name" "$level_db"
1226+
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
1227+
tinymix -D0 set "$mixer_name" "$level_db"
1228+
else
1229+
echo "Unknown alsa tool $SOF_ALSA_TOOL"
1230+
break
1231+
fi
1232+
done
11621233
}
1163-
11641234
DO_PERF_ANALYSIS=0
11651235

11661236
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)