Skip to content

Commit 6bbfa49

Browse files
committed
TinyAlsa: Add support for testing using tinycap, tinyplay.
The parameter has been added to the lib.sh library, allowing the selection of tinyalsa as the testing tool. Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
1 parent e7c456d commit 6bbfa49

5 files changed

Lines changed: 157 additions & 47 deletions

File tree

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ Usage: ./check-playback.sh [OPTION]
5353
...
5454
```
5555

56-
Some tests support SOF_ALSA_OPTS, SOF_APLAY_OPTS and SOF_ARECORD_OPTS,
57-
work in progress. Where supported, optional parameters in SOF_APLAY_OPTS
58-
and SOF_ARECORD_OPTS are passed to all aplay and arecord
59-
invocations. SOF_ALSA_OPTS parameters are passed to both aplay and
60-
arecord. Warning these environments variables do NOT support parameters
56+
Some tests support the use of environment variables:
57+
SOF_ALSA_TOOL, SOF_ALSA_OPTS, SOF_APLAY_OPTS and SOF_ARECORD_OPTS (work in progress)
58+
- SOF_ALSA_TOOL is used to select the audio tool for testing.
59+
Set this variable to 'alsa' or 'tinyalsa' to choose between the ALSA and TinyALSA toolsets.
60+
- SOF_ALSA_OPTS contains optional parameters passed to both aplay and arecord.
61+
- SOF_APLAY_OPTS and SOF_ARECORD_OPTS contain optional parameters passed specifically to aplay and arecord.
62+
These options aply to the selected tool (alsa or tinyalsa) based on the value of SOF_ALSA_TOOL
63+
64+
Warning these environments variables do NOT support parameters
6165
with whitespace or globbing characters, in other words this does NOT
6266
work:
6367

case-lib/lib.sh

Lines changed: 98 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -752,17 +752,83 @@ func_lib_check_pa()
752752
# However, 1. arrays would complicate the user interface 2. ALSA does not
753753
# seem to need arguments with whitespace or globbing characters.
754754

755+
# SOF_ALSA_TOOL:
756+
# This option is used for selecting tool for testing,
757+
# So far, supported tools are 'alsa' and 'tinyalsa'
758+
# To select appropriate tool, set SOF_ALSA_TOOL to one of above
759+
# before using 'aplay_opts' or 'arecord_opts' function.
760+
# Default is SOF_ALSA_TOOL='alsa'
761+
762+
763+
# Function to extract the card number and device number from $dev option (e.g., hw:0,10)
764+
parse_audio_device() {
765+
# Extract the card number (e.g., "0" from hw:0,10)
766+
card_nr=$(printf '%s' "$1" | cut -d ':' -f2 | cut -d ',' -f1)
767+
768+
# Extract the device number (e.g., "10" from hw:0,10)
769+
dev_nr=$(printf '%s' "$1" | cut -d ',' -f2)
770+
}
771+
772+
# Function to extract the numeric format value from the PCM sample formats
773+
# There is passes PCM sample format while using ALSA tool (arecord)
774+
# While using tiny asla (tinycap) we need to convert PCM sample fomrat to bites
775+
# suporrted by tiny alsa -b parameter.
776+
extract_format_number() {
777+
# (e.g., extracting '16' from 'S16_LE')
778+
format=$(printf '%s' "$1" | grep '[0-9]\+' -o)
779+
}
780+
781+
# Initialize the parameters using for audio testing.
782+
# shellcheck disable=SC2034
783+
initialize_audio_params()
784+
{
785+
local idx="$1"
786+
787+
channel=$(func_pipeline_parse_value "$idx" channel)
788+
rate=$(func_pipeline_parse_value "$idx" rate)
789+
fmts=$(func_pipeline_parse_value "$idx" fmt)
790+
dev=$(func_pipeline_parse_value "$idx" dev)
791+
pcm=$(func_pipeline_parse_value "$idx" pcm)
792+
type=$(func_pipeline_parse_value "$idx" type)
793+
snd=$(func_pipeline_parse_value "$idx" snd)
794+
795+
: "${SOF_ALSA_TOOL:="alsa"}"
796+
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
797+
parse_audio_device "$dev"
798+
fi
799+
}
800+
755801
aplay_opts()
756802
{
757-
dlogc "aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $*"
758-
# shellcheck disable=SC2086
759-
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
803+
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
804+
dlogc "tinyplay $*"
805+
# shellcheck disable=SC2154
806+
sox -n -r "$rate" -c "$channel" noise.wav synth "$duration" white
807+
tinyplay -D "$card_nr" -d "$dev_nr" -i wav noise.wav
808+
elif [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
809+
dlogc "aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $*"
810+
# shellcheck disable=SC2086
811+
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
812+
else
813+
printf '%s' "Unknown alsa tool: $SOF_ALSA_TOOL "
814+
fi
760815
}
816+
761817
arecord_opts()
762818
{
763-
dlogc "arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*"
764-
# shellcheck disable=SC2086
765-
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
819+
820+
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
821+
dlogc "tinycap $*"
822+
# shellcheck disable=SC2154
823+
extract_format_number "$fmt_elem"
824+
tinycap "$file" -D "$card_nr" -d "$dev_nr" -c "$channel" -t "$duration" -r "$rate" -b "$format"
825+
elif [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
826+
dlogc "arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*"
827+
# shellcheck disable=SC2086
828+
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
829+
else
830+
printf '%s' "Unknown alsa tool: $SOF_ALSA_TOOL "
831+
fi
766832
}
767833

768834
die()
@@ -952,7 +1018,7 @@ is_ipc4()
9521018
logger_disabled()
9531019
{
9541020
# Disable logging when available...
955-
if [ ${OPT_VAL['s']} -eq 0 ]; then
1021+
if [ "${OPT_VAL['s']}" -eq 0 ]; then
9561022
return 0
9571023
fi
9581024

@@ -1063,15 +1129,31 @@ set_alsa_settings()
10631129
reset_sof_volume()
10641130
{
10651131
# 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
1132+
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
1133+
amixer -Dhw:0 scontrols | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1134+
1135+
while read -r mixer_name
1136+
do
1137+
if is_ipc4; then
1138+
amixer -Dhw:0 -- sset "$mixer_name" 100%
1139+
else
1140+
amixer -Dhw:0 -- sset "$mixer_name" 0dB
1141+
fi
1142+
done
1143+
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
1144+
tinymix -D0 controls | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1145+
1146+
while read -r mixer_name
1147+
do
1148+
if is_ipc4; then
1149+
tinymix -D0 set "$mixer_name" 100%
1150+
else
1151+
tinymix -D0 set "$mixer_name" 0dB
1152+
fi
1153+
done
1154+
else
1155+
echo "Unknowns alsa tool $SOF_ALSA_TOOL"
1156+
fi
10751157
}
10761158

10771159
DO_PERF_ANALYSIS=0

test-case/check-capture.sh

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,38 +64,33 @@ setup_kernel_check_point
6464
func_lib_check_sudo
6565
func_pipeline_export "$tplg" "type:capture & ${OPT_VAL['S']}"
6666

67-
for round in $(seq 1 $round_cnt)
67+
for round in $(seq 1 "$round_cnt")
6868
do
6969
for idx in $(seq 0 $((PIPELINE_COUNT - 1)))
7070
do
71-
channel=$(func_pipeline_parse_value "$idx" channel)
72-
rate=$(func_pipeline_parse_value "$idx" rate)
73-
fmt=$(func_pipeline_parse_value "$idx" fmt)
74-
dev=$(func_pipeline_parse_value "$idx" dev)
75-
pcm=$(func_pipeline_parse_value "$idx" pcm)
76-
type=$(func_pipeline_parse_value "$idx" type)
77-
snd=$(func_pipeline_parse_value "$idx" snd)
78-
79-
if [ ${OPT_VAL['F']} = '1' ]; then
80-
fmt=$(func_pipeline_parse_value "$idx" fmts)
71+
72+
initialize_audio_params "$idx"
73+
74+
if [ "${OPT_VAL['F']}" = '1' ]; then
75+
fmts=$(func_pipeline_parse_value "$idx" fmts)
8176
fi
8277

83-
for fmt_elem in $fmt
78+
for fmt_elem in $fmts
8479
do
85-
for i in $(seq 1 $loop_cnt)
80+
for i in $(seq 1 "$loop_cnt")
8681
do
8782
dlogi "===== Testing: (Round: $round/$round_cnt) (PCM: $pcm [$dev]<$type>) (Loop: $i/$loop_cnt) ====="
8883
# get the output file
8984
if [[ -z $file_prefix ]]; then
9085
dlogi "no file prefix, use /dev/null as dummy capture output"
9186
file=/dev/null
9287
else
93-
mkdir -p $out_dir
88+
mkdir -p "$out_dir"
9489
file=$out_dir/${file_prefix}_${dev}_${i}.wav
9590
dlogi "using $file as capture output"
9691
fi
9792

98-
if ! arecord_opts -D"$dev" -r "$rate" -c "$channel" -f "$fmt_elem" -d $duration "$file" -v -q;
93+
if ! arecord_opts -D"$dev" -r "$rate" -c "$channel" -f "$fmt_elem" -d "$duration" "$file" -v -q;
9994
then
10095
func_lib_lsof_error_dump "$snd"
10196
die "arecord on PCM $dev failed at $i/$loop_cnt."

test-case/check-playback.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,20 @@ setup_kernel_check_point
7171
func_lib_check_sudo
7272
func_pipeline_export "$tplg" "type:playback & ${OPT_VAL['S']}"
7373

74-
for round in $(seq 1 $round_cnt)
74+
for round in $(seq 1 "$round_cnt")
7575
do
7676
for idx in $(seq 0 $((PIPELINE_COUNT - 1)))
7777
do
78-
channel=$(func_pipeline_parse_value "$idx" channel)
79-
rate=$(func_pipeline_parse_value "$idx" rate)
80-
fmts=$(func_pipeline_parse_value "$idx" fmt)
81-
dev=$(func_pipeline_parse_value "$idx" dev)
82-
pcm=$(func_pipeline_parse_value "$idx" pcm)
83-
type=$(func_pipeline_parse_value "$idx" type)
84-
snd=$(func_pipeline_parse_value "$idx" snd)
85-
86-
if [ ${OPT_VAL['F']} = '1' ]; then
78+
79+
initialize_audio_params "$idx"
80+
81+
if [ "${OPT_VAL['F']}" = '1' ]; then
8782
fmts=$(func_pipeline_parse_value "$idx" fmts)
8883
fi
8984

9085
for fmt_elem in $fmts
9186
do
92-
for i in $(seq 1 $loop_cnt)
87+
for i in $(seq 1 "$loop_cnt")
9388
do
9489
dlogi "===== Testing: (Round: $round/$round_cnt) (PCM: $pcm [$dev]<$type>) (Loop: $i/$loop_cnt) ====="
9590
aplay_opts -D"$dev" -r "$rate" -c "$channel" -f "$fmt_elem" \

test-case/check-tinyalsa.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# This script serves as a wrapper to execute a test case script using tinyalsa.
3+
# It expects the test case script file name (without path) as the first parameter,
4+
# followed by other parameters required for that test case.
5+
6+
set -e
7+
8+
# Function to check if a command is available
9+
check_command() {
10+
if command -v "$1" &> /dev/null; then
11+
echo "$1 is installed."
12+
else
13+
echo "$1 is not installed. Exiting..."
14+
exit 1
15+
fi
16+
}
17+
18+
# Preconditions: Check if tinyalsa executables are present on the DUT
19+
check_command "sox"
20+
check_command "tinycap"
21+
check_command "tinyplay"
22+
23+
# Ensure the test case script file name is provided
24+
if [ -z "$1" ]; then
25+
echo "Error: No test case script file name provided. Exiting..."
26+
exit 1
27+
fi
28+
29+
export SOF_ALSA_TOOL=tinyalsa
30+
31+
TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
32+
33+
# shellcheck disable=SC2145
34+
[ -x "$TESTDIR"/test-case/"$1" ] && exec "$TESTDIR"/test-case/"$@"

0 commit comments

Comments
 (0)