Skip to content

Commit b5fb40c

Browse files
committed
TinyAlsa: Add support for tinymix command
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 e7c456d commit b5fb40c

2 files changed

Lines changed: 99 additions & 33 deletions

File tree

case-lib/lib.sh

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ is_ipc4()
952952
logger_disabled()
953953
{
954954
# Disable logging when available...
955-
if [ ${OPT_VAL['s']} -eq 0 ]; then
955+
if [ "${OPT_VAL['s']}" -eq 0 ]; then
956956
return 0
957957
fi
958958

@@ -1060,18 +1060,63 @@ set_alsa_settings()
10601060
esac
10611061
}
10621062

1063+
set_sof_volume()
1064+
{
1065+
local device=$1
1066+
local control_name=$2
1067+
local value=$3
1068+
1069+
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
1070+
dlogc "amixer -c$device' -- cset 'name=$control_name' '$value'"
1071+
amixer -c"$device" cset name="$control_name" "$value" > /dev/null
1072+
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
1073+
dlogc "tinymix -D'$device' set '$control_name' '$value'"
1074+
tinymix -D"$device" set "$control_name" "$value" > /dev/null
1075+
else
1076+
echo "Unknown alsa tool $SOF_ALSA_TOOL"
1077+
fi
1078+
}
1079+
1080+
get_sof_controls()
1081+
{
1082+
local sofcard=$1
1083+
1084+
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
1085+
amixer -c"$sofcard" controls
1086+
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
1087+
tinymix --card "$sofcard" controls
1088+
else
1089+
echo "Unknown alsa tool $SOF_ALSA_TOOL"
1090+
fi
1091+
1092+
}
1093+
10631094
reset_sof_volume()
10641095
{
10651096
# set all PGA* volume to 0dB
1066-
amixer -Dhw:0 scontrols | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1067-
while read -r mixer_name
1068-
do
1069-
if is_ipc4; then
1070-
amixer -Dhw:0 -- sset "$mixer_name" 100%
1071-
else
1072-
amixer -Dhw:0 -- sset "$mixer_name" 0dB
1073-
fi
1074-
done
1097+
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
1098+
amixer -Dhw:0 scontrols | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1099+
while read -r mixer_name
1100+
do
1101+
if is_ipc4; then
1102+
amixer -Dhw:0 -- sset "$mixer_name" 100%
1103+
else
1104+
amixer -Dhw:0 -- sset "$mixer_name" 0dB
1105+
fi
1106+
done
1107+
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
1108+
tinymix -D 0 contorls | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1109+
while read -r mixer_name
1110+
do
1111+
if is_ipc4; then
1112+
tinymix -D 0 set "$mixer_name" 100%
1113+
else
1114+
tinymix -D 0 set "$mixer_name" 0dB
1115+
fi
1116+
done
1117+
else
1118+
echo "Unknown alsa tool $SOF_ALSA_TOOL"
1119+
fi
10751120
}
10761121

10771122
DO_PERF_ANALYSIS=0

test-case/volume-basic-test.sh

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

4040
start_test
4141

42-
func_error_exit()
42+
check_alsa_tool_process()
4343
{
44-
dloge "$*"
45-
pkill -9 aplay
46-
exit 1
44+
sleep 1
45+
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
46+
# Check if the aplay process is running
47+
if [[ ! $(pidof aplay) ]]; then
48+
die "aplay process is terminated too early"
49+
fi
50+
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
51+
# Check if the tinyplay process is running
52+
if [[ ! $(pidof tinyplay) ]]; then
53+
die "tinyplay process is terminated too early"
54+
fi
55+
else
56+
echo "Unknown alsa tool $SOF_ALSA_TOOL"
57+
fi
58+
}
59+
60+
func_exit()
61+
{
62+
63+
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
64+
pkill -9 aplay
65+
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
66+
pkill -9 tinyplay
67+
else
68+
echo "Unknown alsa tool $SOF_ALSA_TOOL"
69+
fi
70+
71+
if [[ "$1" -eq 1 ]]; then
72+
dloge "$*"
73+
exit 1 # error
74+
fi
4775
}
4876

4977
[[ -z $tplg ]] && die "Missing tplg file needed to run"
5078
func_pipeline_export "$tplg" "type:playback"
5179
logger_disabled || func_lib_start_log_collect
5280

5381
[[ $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)
58-
59-
dlogc "aplay -D $dev -c $channel -r $rate -f $fmt /dev/zero &"
82+
duration=50 # Duration of playing white noise while testing under tinyalsa
83+
initialize_audio_params "0"
6084
# 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-
63-
sleep 1
64-
[[ ! $(pidof aplay) ]] && die "aplay process is terminated too early"
65-
85+
# shellcheck disable=SC2154
86+
aplay_opts -D "$dev" -c "$channel" -r "$rate" -f "$fmts" -d "$duration" /dev/zero >/dev/null &
87+
check_alsa_tool_process
6688
sofcard=${SOFCARD:-0}
6789

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

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

76-
for i in $(seq 1 $maxloop)
98+
for i in $(seq 1 "$maxloop")
7799
do
78100
setup_kernel_check_point
79101
dlogi "===== Round($i/$maxloop) ====="
@@ -83,10 +105,9 @@ do
83105
dlogi "$volctrl"
84106

85107
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"
89-
done
108+
set_sof_volume "$sofcard" "$volctrl" "$vol" ||
109+
func_exit 1 "amixer return error, test failed"
110+
done
90111
done
91112

92113
sleep 1
@@ -96,8 +117,8 @@ do
96117
func_error_exit "dmesg has errors!"
97118
done
98119

99-
#clean up background aplay
100-
pkill -9 aplay || true
120+
#clean up background aplay/tinyplay
121+
func_exit 0
101122

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

0 commit comments

Comments
 (0)