Skip to content

Commit 4103f2f

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 fdd7ae4 commit 4103f2f

2 files changed

Lines changed: 96 additions & 24 deletions

File tree

case-lib/lib.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,85 @@ 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" controls
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
@@ -1133,6 +1212,8 @@ set_alsa_settings()
11331212

11341213
reset_sof_volume()
11351214
{
1215+
get_sof_controls "0"
1216+
11361217
# set all PGA* volume to 0dB
11371218
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
11381219
amixer -Dhw:0 scontrols | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |

test-case/volume-basic-test.sh

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,33 @@ 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 &"
60-
# 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 &
48+
# Duration of playing white noise while testing under tinyalsa
49+
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
50+
duration=50
51+
fi
6252

53+
initialize_audio_params "0"
54+
# play into background, this will wake up DSP and IPC. Need to clean after the test
55+
aplay_opts -D "$dev" -c "$channel" -r "$rate" -f "$fmts" -d "$duration" /dev/zero >/dev/null &
6356
sleep 1
64-
[[ ! $(pidof aplay) ]] && die "aplay process is terminated too early"
65-
57+
check_alsa_tool_process
6658
sofcard=${SOFCARD:-0}
6759

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

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

76-
for i in $(seq 1 $maxloop)
68+
for i in $(seq 1 "$maxloop")
7769
do
7870
setup_kernel_check_point
7971
dlogi "===== Round($i/$maxloop) ====="
@@ -83,21 +75,20 @@ do
8375
dlogi "$volctrl"
8476

8577
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"
78+
set_sof_volume "$sofcard" "$volctrl" "$vol" ||
79+
kill_playrecord_die "mixer return error, test failed"
8980
done
9081
done
9182

9283
sleep 1
9384

9485
dlogi "check dmesg for error"
9586
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" ||
96-
func_error_exit "dmesg has errors!"
87+
kill_playrecord_die "dmesg has errors!"
9788
done
9889

99-
#clean up background aplay
100-
pkill -9 aplay || true
90+
#clean up background play record
91+
kill_play_record || true
10192

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

0 commit comments

Comments
 (0)