Skip to content
Open
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
5 changes: 5 additions & 0 deletions case-lib/hijack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ function func_exit_handler()
fi
}

# Restore ALSA settings after execution if state file exists
if [ -f "${SOF_TEST_ALSA_STATE_FILENAME}" ]; then
restore_alsa_state
fi

print_test_result_exit $exit_status
}

Expand Down
26 changes: 26 additions & 0 deletions case-lib/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ SCRIPT_HOME=$(cd "$SCRIPT_HOME/.." && pwd)
SCRIPT_NAME="$0" # get test-case script load name
# shellcheck disable=SC2034 # external script can use it
SCRIPT_PRAM="$*" # get test-case parameter
# shellcheck disable=SC2034 # external script can use it
SOF_TEST_ALSA_STATE_FILENAME=/tmp/"${SCRIPT_NAME##*/}".$$.state

# Source from the relative path of current folder
# shellcheck source=case-lib/config.sh
Expand Down Expand Up @@ -1187,3 +1189,27 @@ perf_analyze()
fi
}

# Restore the machine state from a file.
# Should be triggered at the end of
# every test touching ALSA.
# Couple with save_machine_state.
restore_alsa_state()
{
dlogi "restore_alsa_state called in ${SOF_TEST_ALSA_STATE_FILENAME}"
if [ -f "${SOF_TEST_ALSA_STATE_FILENAME}" ]; then
dlogi "restore_alsa_state found a relevant state file."
alsactl restore --file "${SOF_TEST_ALSA_STATE_FILENAME}" --pedantic --no-ucm --no-init-fallback || dlogi "alsactl state restoration failed!"
rm "${SOF_TEST_ALSA_STATE_FILENAME}" || dlogi "Old state file removal failed!"
fi
}

# Save the machine state to a file.
# Should be used at the start of
# every test touching ALSA.
# Coupled with restore_machine_state
# on an exit signal inside func_exit_handler.
save_alsa_state()
{
dlogi "save_alsa_state called in ${SOF_TEST_ALSA_STATE_FILENAME}"
alsactl store --file "${SOF_TEST_ALSA_STATE_FILENAME}" || dlogi "alsactl state storage failed!"
}
1 change: 1 addition & 0 deletions test-case/check-alsabat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ sigmak=${OPT_VAL['k']}
frames=${OPT_VAL['n']}

start_test
save_alsa_state

if [ "$pcm_p" = "" ]||[ "$pcm_c" = "" ];
then
Expand Down
1 change: 1 addition & 0 deletions test-case/check-audio-equalizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func_pipeline_export "$tplg" "eq:any"
sofcard=${SOFCARD:-0}

start_test
save_alsa_state
setup_kernel_check_point

# Test equalizer
Expand Down
1 change: 1 addition & 0 deletions test-case/check-capture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ out_dir=${OPT_VAL['o']}
file_prefix=${OPT_VAL['f']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

setup_kernel_check_point
Expand Down
1 change: 1 addition & 0 deletions test-case/check-fw-echo-reference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ frames=${OPT_VAL['n']}
frequency=${OPT_VAL['f']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

func_pipeline_export "$tplg" "echo:any"
Expand Down
1 change: 1 addition & 0 deletions test-case/check-keyword-detection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ preamble_time=${OPT_VAL['p']}
duration=${OPT_VAL['d']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

func_pipeline_export "$tplg" "kpb:any"
Expand Down
1 change: 1 addition & 0 deletions test-case/check-kmod-load-unload-after-playback.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ loop_cnt=${OPT_VAL['l']}
pb_duration=${OPT_VAL['d']}

start_test
save_alsa_state

func_pipeline_export "$tplg" "type:playback"

Expand Down
1 change: 1 addition & 0 deletions test-case/check-kmod-load-unload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func_opt_parse_option "$@"
setup_kernel_check_point

start_test
save_alsa_state

loop_cnt=${OPT_VAL['l']}

Expand Down
1 change: 1 addition & 0 deletions test-case/check-pause-release-suspend-resume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ test_mode=${OPT_VAL['m']}
file_name=${OPT_VAL['F']}

start_test
save_alsa_state

case $test_mode in
"playback")
Expand Down
1 change: 1 addition & 0 deletions test-case/check-pause-resume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ rnd_min=${OPT_VAL['i']}
rnd_max=${OPT_VAL['a']}

start_test
save_alsa_state

rnd_range=$(( rnd_max - rnd_min ))
[[ $rnd_range -le 0 ]] && dlogw "Error random range scope [ min:$rnd_min - max:$rnd_max ]" && exit 2
Expand Down
1 change: 1 addition & 0 deletions test-case/check-performance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tplg=${OPT_VAL['t']}
duration=${OPT_VAL['d']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

setup_kernel_check_point
Expand Down
1 change: 1 addition & 0 deletions test-case/check-playback.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ loop_cnt=${OPT_VAL['l']}
file=${OPT_VAL['f']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

# checking if source file exists
Expand Down
1 change: 1 addition & 0 deletions test-case/check-runtime-pm-double-active.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ tplg=${OPT_VAL['t']}
loop_count=${OPT_VAL['l']}

start_test
save_alsa_state

[[ -z $tplg ]] && dloge "Miss tplg file to run" && exit 2

Expand Down
1 change: 1 addition & 0 deletions test-case/check-runtime-pm-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ tplg=${OPT_VAL['t']}
loop_count=${OPT_VAL['l']}

start_test
save_alsa_state

[[ -z $tplg ]] && die "Miss tplg file to run"

Expand Down
1 change: 1 addition & 0 deletions test-case/check-signal-stop-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interval=${OPT_VAL['i']}
test_mode=${OPT_VAL['m']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

case $test_mode in
Expand Down
1 change: 1 addition & 0 deletions test-case/check-smart-amplifier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ loop_cnt=${OPT_VAL['l']}
tplg=${OPT_VAL['t']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

func_pipeline_export "$tplg" "smart_amp:any"
Expand Down
3 changes: 2 additions & 1 deletion test-case/check-sof-logger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ source "${TOPDIR}"/case-lib/lib.sh
func_opt_parse_option "$@"

start_test
save_alsa_state

# check sof-logger location
type -a sof-logger ||
Expand Down Expand Up @@ -72,7 +73,7 @@ sof_alsa_card_found()
# - /proc/asound/sofsoundwire/id
# - /proc/asound/sofhdadsp/id
# - https://github.com/thesofproject/sof-test/issues/1243
# Designed to support multiple SOF instances with SOF probes
# Designed to support multiple SOF instances with SOF probes
for i in /proc/asound/sof*/id; do
if test -e "$i"; then return 0; fi
done
Expand Down
2 changes: 1 addition & 1 deletion test-case/check-suspend-resume-with-audio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func_lib_check_sudo
tplg=${OPT_VAL['t']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

# overwrite the subscript: test-case LOG_ROOT environment
Expand Down Expand Up @@ -139,4 +140,3 @@ do
dlogi "Killing $cmd_args"
kill -9 $process_id || true
done

1 change: 1 addition & 0 deletions test-case/check-userspace-cardinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func_opt_parse_option "$@"
setup_kernel_check_point

start_test
save_alsa_state

# check pulseaudio runs properly or not
func_lib_check_pa || die "Please check whether pulseaudio runs correctly or not"
Expand Down
1 change: 1 addition & 0 deletions test-case/check-userspace-paplay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func_opt_parse_option "$@"
setup_kernel_check_point

start_test
save_alsa_state

round_cnt=${OPT_VAL['r']}
duration=${OPT_VAL['d']}
Expand Down
1 change: 1 addition & 0 deletions test-case/check-userspace-parecord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ rate=${OPT_VAL['R']}
channel=${OPT_VAL['C']}

start_test
save_alsa_state

[[ -e $file ]] || { dlogw "$file does not exist, use /dev/zero as dummy playback source" && file=/dev/null; }

Expand Down
1 change: 1 addition & 0 deletions test-case/check-volume-levels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ARECORD_WAV2=$(mktemp --suffix=.wav)
ARECORD_WAV3=$(mktemp --suffix=.wav)

start_test
save_alsa_state

#
# Main test procedure
Expand Down
1 change: 1 addition & 0 deletions test-case/check-xrun-injection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ count=${OPT_VAL['c']}
interval=${OPT_VAL['i']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

setup_kernel_check_point
Expand Down
1 change: 1 addition & 0 deletions test-case/latency-metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ main()
setup_kernel_check_point

start_test
save_alsa_state

logger_disabled || func_lib_start_log_collect

Expand Down
4 changes: 2 additions & 2 deletions test-case/multiple-pause-resume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ rnd_max=${OPT_VAL['a']}
rnd_range=$((rnd_max - rnd_min))

start_test
save_alsa_state

[[ $rnd_range -le 0 ]] && dlogw "Error random range scope [ min:$rnd_min - max:$rnd_max ]" && exit 2

Expand Down Expand Up @@ -140,7 +141,7 @@ func_pause_resume_pipeline()
}

# to prevent infinite loop, 5 second per a repeat is plenty
max_wait_time=$((5 * repeat_count))
max_wait_time=$((5 * repeat_count))

for i in $(seq 1 "$loop_count")
do
Expand Down Expand Up @@ -203,4 +204,3 @@ do
# check kernel log for each iteration to catch issues
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || die "Caught error in kernel log"
done

2 changes: 1 addition & 1 deletion test-case/multiple-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ tplg=${OPT_VAL['t']}
f_arg=${OPT_VAL['f']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

# skip the Echo Reference pipeline
Expand Down Expand Up @@ -222,4 +223,3 @@ do
# check kernel log for each iteration to catch issues
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || die "Caught error in kernel log"
done

2 changes: 1 addition & 1 deletion test-case/simultaneous-playback-capture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ wait_time=${OPT_VAL['w']}
loop_cnt=${OPT_VAL['l']}

start_test
save_alsa_state

# get 'both' pcm, it means pcm have same id with different type
declare -A tmp_id_lst
Expand Down Expand Up @@ -120,4 +121,3 @@ do
# check kernel log for each iteration to catch issues
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || die "Caught error in kernel log"
done

1 change: 1 addition & 0 deletions test-case/test-speaker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func_opt_parse_option "$@"
tplg=${OPT_VAL['t']}

start_test
save_alsa_state
logger_disabled || func_lib_start_log_collect

func_pipeline_export "$tplg" "type:playback"
Expand Down
1 change: 1 addition & 0 deletions test-case/verify-bootsequence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func_opt_parse_option "$@"
setup_kernel_check_point

start_test
save_alsa_state

main()
{
Expand Down
1 change: 1 addition & 0 deletions test-case/verify-pcm-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func_opt_parse_option "$@"
tplg=${OPT_VAL['t']}

start_test
save_alsa_state

tplg_path=$(func_lib_get_tplg_path "$tplg") ||
die "No available topology for this test case"
Expand Down
1 change: 1 addition & 0 deletions test-case/verify-sof-firmware-load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func_opt_parse_option "$@"
disable_kernel_check_point

start_test
save_alsa_state

cmd="journalctl_cmd"

Expand Down
1 change: 1 addition & 0 deletions test-case/verify-ucm-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func_opt_parse_option "$@"
setup_kernel_check_point

start_test
save_alsa_state

declare -A verb_array

Expand Down
1 change: 1 addition & 0 deletions test-case/volume-basic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ tplg=${OPT_VAL['t']}
maxloop=${OPT_VAL['l']}

start_test
save_alsa_state

func_error_exit()
{
Expand Down
Loading