Skip to content

Commit 72aa384

Browse files
committed
TinyAlsa: Add support for testing using tinycap and 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 72aa384

File tree

6 files changed

+99
-24
lines changed

6 files changed

+99
-24
lines changed

README.md

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

56-
Some tests support SOF_ALSA_OPTS, SOF_APLAY_OPTS and SOF_ARECORD_OPTS,
56+
Some tests support SOF_ALSA_TOOL, SOF_ALSA_OPTS, SOF_APLAY_OPTS and SOF_ARECORD_OPTS,
5757
work in progress. Where supported, optional parameters in SOF_APLAY_OPTS
5858
and SOF_ARECORD_OPTS are passed to all aplay and arecord
5959
invocations. SOF_ALSA_OPTS parameters are passed to both aplay and
60-
arecord. Warning these environments variables do NOT support parameters
60+
arecord. SOF_ALSA_TOOL is used to select tool for testing.
61+
Set SOF_ALSA_TOOL to 'alsa' or 'tinyalsa' to select tool.
62+
Warning these environments variables do NOT support parameters
6163
with whitespace or globbing characters, in other words this does NOT
6264
work:
6365

case-lib/lib.sh

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,17 +752,80 @@ 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+
# (e.g., 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 $fmt_elem option
773+
extract_format_number() {
774+
# (e.g., extracting '16' from 'S16_LE')
775+
format=$(printf '%s' "$1" | grep '[0-9]\+' -o)
776+
}
777+
778+
# Initialize the parameters using for audio testing.
779+
# shellcheck disable=SC2034
780+
initialize_audio_params()
781+
{
782+
local idx="$1"
783+
784+
channel=$(func_pipeline_parse_value "$idx" channel)
785+
rate=$(func_pipeline_parse_value "$idx" rate)
786+
fmts=$(func_pipeline_parse_value "$idx" fmt)
787+
dev=$(func_pipeline_parse_value "$idx" dev)
788+
pcm=$(func_pipeline_parse_value "$idx" pcm)
789+
type=$(func_pipeline_parse_value "$idx" type)
790+
snd=$(func_pipeline_parse_value "$idx" snd)
791+
792+
: "${SOF_ALSA_TOOL:="alsa"}"
793+
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
794+
parse_audio_device "$dev"
795+
fi
796+
}
797+
755798
aplay_opts()
756799
{
757-
dlogc "aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $*"
758-
# shellcheck disable=SC2086
759-
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
800+
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
801+
dlogc "tinyplay $*"
802+
# shellcheck disable=SC2154
803+
sox -n -r "$rate" -c "$channel" noise.wav synth "$duration" white
804+
tinyplay -D "$card_nr" -d "$dev_nr" -i wav noise.wav
805+
elif [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
806+
dlogc "aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $*"
807+
# shellcheck disable=SC2086
808+
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
809+
else
810+
printf '%s' "Unknown alsa tool: $SOF_ALSA_TOOL "
811+
fi
760812
}
813+
761814
arecord_opts()
762815
{
763-
dlogc "arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*"
764-
# shellcheck disable=SC2086
765-
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
816+
817+
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
818+
dlogc "tinycap $*"
819+
# shellcheck disable=SC2154
820+
extract_format_number "$fmt_elem"
821+
tinycap "$file" -D "$card_nr" -d "$dev_nr" -c "$channel" -t "$duration" -r "$rate" -b "$format"
822+
elif [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
823+
dlogc "arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*"
824+
# shellcheck disable=SC2086
825+
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
826+
else
827+
printf '%s' "Unknown alsa tool: $SOF_ALSA_TOOL "
828+
fi
766829
}
767830

768831
die()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
export SOF_ALSA_TOOL=tinyalsa
6+
7+
TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
8+
9+
# Need "exec" otherwise it believes to be a Sub-Test
10+
exec "$TESTDIR"/test-case/check-capture.sh "$@"

test-case/check-capture.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,14 @@ 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)
71+
72+
initialize_audio_params "$idx"
7873

7974
if [ ${OPT_VAL['F']} = '1' ]; then
80-
fmt=$(func_pipeline_parse_value "$idx" fmts)
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
8580
for i in $(seq 1 $loop_cnt)
8681
do
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
export SOF_ALSA_TOOL=tinyalsa
6+
7+
TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
8+
9+
# Need "exec" otherwise it believes to be a Sub-Test
10+
exec "$TESTDIR"/test-case/check-playback.sh "$@"

test-case/check-playback.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,8 @@ 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)
78+
79+
initialize_audio_params "$idx"
8580

8681
if [ ${OPT_VAL['F']} = '1' ]; then
8782
fmts=$(func_pipeline_parse_value "$idx" fmts)

0 commit comments

Comments
 (0)