Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 96 additions & 26 deletions case-lib/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,92 @@ initialize_audio_params()
fi
}

set_sof_volume()
{
local device=$1
local control_name=$2
local value=$3

case "$SOF_ALSA_TOOL" in
'alsa')
dlogc "amixer -c$device' cset 'name=$control_name' '$value'"
amixer -c"$device" cset name="$control_name" "$value"
;;
'tinyalsa')
dlogc "tinymix -D'$device' set '$control_name' '$value'"
tinymix -D"$device" set "$control_name" "$value"
;;
*)
die "Unknown alsa tool $SOF_ALSA_TOOL"
;;
esac
}

get_sof_controls()
{
local sofcard=$1

case "$SOF_ALSA_TOOL" in
'alsa')
# Used `scontrols` instead of `controls`.
# Using `controls` causes issues on some platforms when trying to access unavailable controls during setting.
amixer -c"$sofcard" scontrols
;;
'tinyalsa')
tinymix --card "$sofcard" controls
;;
*)
die "Unknown alsa tool $SOF_ALSA_TOOL"
;;
esac
}

kill_play_record()
{
dloge "$*"
case "$SOF_ALSA_TOOL" in
'alsa')
pkill -9 aplay
;;
'tinyalsa')
pkill -9 tinyplay
;;
*)
die "Unknown alsa tool $SOF_ALSA_TOOL"
;;
esac
}

kill_playrecord_die()
{
kill_play_record "&@"
die "$1"
}

check_alsa_tool_process()
{
case "$SOF_ALSA_TOOL" in
"alsa")
# Check if the aplay process is running
pidof -q aplay ||
die "aplay process is terminated too early"
;;
"tinyalsa")
# Check if the tinyplay process is running
pidof -q tinyplay ||
die "tinyplay process is terminated too early"
;;
*)
die "Unknown alsa tool $SOF_ALSA_TOOL"
;;
esac
}

aplay_opts()
{
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
# Duration of playing white noise while testing under tinyalsa
duration=50
# shellcheck disable=SC2154
if ! sox -n -r "$rate" -c "$channel" noise.wav synth "$duration" white; then
printf 'Error: sox command failed.\n' >&2
Expand Down Expand Up @@ -1133,34 +1216,21 @@ set_alsa_settings()

reset_sof_volume()
{
level_db=$(if is_ipc4; then echo "100%"; else echo "0dB"; fi)
# set all PGA* volume to 0dB
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
amixer -Dhw:0 scontrols | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |

while read -r mixer_name
do
if is_ipc4; then
amixer -Dhw:0 -- sset "$mixer_name" 100%
else
amixer -Dhw:0 -- sset "$mixer_name" 0dB
fi
done
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
tinymix -D0 controls | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |

while read -r mixer_name
do
if is_ipc4; then
tinymix -D0 set "$mixer_name" 100%
else
tinymix -D0 set "$mixer_name" 0dB
fi
done
else
echo "Unknown alsa tool $SOF_ALSA_TOOL"
fi
get_sof_controls "0" | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
while read -r mixer_name
do
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
amixer -Dhw:0 -- sset "$mixer_name" "$level_db"
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
tinymix -D0 set "$mixer_name" "$level_db"
else
echo "Unknown alsa tool $SOF_ALSA_TOOL"
break
fi
done
}

DO_PERF_ANALYSIS=0

perf_analyze()
Expand Down
34 changes: 10 additions & 24 deletions test-case/volume-basic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,28 @@ maxloop=${OPT_VAL['l']}

start_test

func_error_exit()
{
dloge "$*"
pkill -9 aplay
exit 1
}

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

[[ $PIPELINE_COUNT -eq 0 ]] && die "Missing playback pipeline for aplay to run"
channel=$(func_pipeline_parse_value 0 channel)
rate=$(func_pipeline_parse_value 0 rate)
fmt=$(func_pipeline_parse_value 0 fmt)
dev=$(func_pipeline_parse_value 0 dev)

dlogc "aplay -D $dev -c $channel -r $rate -f $fmt /dev/zero &"
initialize_audio_params "0"
# play into background, this will wake up DSP and IPC. Need to clean after the test
aplay -D "$dev" -c "$channel" -r "$rate" -f "$fmt" /dev/zero &

aplay_opts -D "$dev" -c "$channel" -r "$rate" -f "$fmts" /dev/zero &
sleep 1
[[ ! $(pidof aplay) ]] && die "aplay process is terminated too early"

check_alsa_tool_process
sofcard=${SOFCARD:-0}

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

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

for i in $(seq 1 $maxloop)
for i in $(seq 1 "$maxloop")
do
setup_kernel_check_point
dlogi "===== Round($i/$maxloop) ====="
Expand All @@ -83,21 +70,20 @@ do
dlogi "$volctrl"

for vol in "${volume_array[@]}"; do
dlogc "amixer -c$sofcard cset name='$volctrl' $vol"
amixer -c"$sofcard" cset name="$volctrl" "$vol" > /dev/null ||
func_error_exit "amixer return error, test failed"
set_sof_volume "$sofcard" "$volctrl" "$vol" ||
kill_playrecord_die "mixer return error, test failed"
done
done

sleep 1

dlogi "check dmesg for error"
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" ||
func_error_exit "dmesg has errors!"
kill_playrecord_die "dmesg has errors!"
done

#clean up background aplay
pkill -9 aplay || true
#clean up background play record
kill_play_record || true

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