Skip to content

Commit 0aa7b2d

Browse files
committed
alsa: Restore test settings after each test
Currently, some tests change ALSABAT settings during their execution, but do not restore them to their prior state. This causes tests that occur later in the execution order to intermittently fail. To remedy this, all tests that use ALSA now use a common save_alsa_state function, which shall save current ALSA state to a file and then restore that state on the bash script EXIT signal. Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
1 parent 20a47bc commit 0aa7b2d

34 files changed

+65
-6
lines changed

case-lib/hijack.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ function func_exit_handler()
185185
fi
186186
}
187187

188+
# Restore ALSA settings after execution if state file exists
189+
if [ -f "${SOF_TEST_ALSA_STATE_FILENAME}" ]; then
190+
restore_alsa_state
191+
fi
192+
188193
print_test_result_exit $exit_status
189194
}
190195

case-lib/lib.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ SCRIPT_HOME=$(cd "$SCRIPT_HOME/.." && pwd)
88
SCRIPT_NAME="$0" # get test-case script load name
99
# shellcheck disable=SC2034 # external script can use it
1010
SCRIPT_PRAM="$*" # get test-case parameter
11+
# shellcheck disable=SC2034 # external script can use it
12+
SOF_TEST_ALSA_STATE_FILENAME=/tmp/"${SCRIPT_NAME##*/}".$$.state
1113

1214
# Source from the relative path of current folder
1315
# shellcheck source=case-lib/config.sh
@@ -1187,3 +1189,27 @@ perf_analyze()
11871189
fi
11881190
}
11891191

1192+
# Restore the machine state from a file.
1193+
# Should be triggered at the end of
1194+
# every test touching ALSA.
1195+
# Couple with save_machine_state.
1196+
restore_alsa_state()
1197+
{
1198+
dlogi "restore_alsa_state called in ${SOF_TEST_ALSA_STATE_FILENAME}"
1199+
if [ -f "${SOF_TEST_ALSA_STATE_FILENAME}" ]; then
1200+
dlogi "restore_alsa_state found a relevant state file."
1201+
alsactl restore --file "${SOF_TEST_ALSA_STATE_FILENAME}" --pedantic --no-ucm --no-init-fallback || dlogi "alsactl state restoration failed!"
1202+
rm "${SOF_TEST_ALSA_STATE_FILENAME}" || dlogi "Old state file removal failed!"
1203+
fi
1204+
}
1205+
1206+
# Save the machine state to a file.
1207+
# Should be used at the start of
1208+
# every test touching ALSA.
1209+
# Coupled with restore_machine_state
1210+
# on an exit signal inside func_exit_handler.
1211+
save_alsa_state()
1212+
{
1213+
dlogi "save_alsa_state called in ${SOF_TEST_ALSA_STATE_FILENAME}"
1214+
alsactl store --file "${SOF_TEST_ALSA_STATE_FILENAME}" || dlogi "alsactl state storage failed!"
1215+
}

test-case/check-alsabat.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ sigmak=${OPT_VAL['k']}
7474
frames=${OPT_VAL['n']}
7575

7676
start_test
77+
save_alsa_state
7778

7879
if [ "$pcm_p" = "" ]||[ "$pcm_c" = "" ];
7980
then

test-case/check-audio-equalizer.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func_pipeline_export "$tplg" "eq:any"
4343
sofcard=${SOFCARD:-0}
4444

4545
start_test
46+
save_alsa_state
4647
setup_kernel_check_point
4748

4849
# Test equalizer

test-case/check-capture.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ out_dir=${OPT_VAL['o']}
5858
file_prefix=${OPT_VAL['f']}
5959

6060
start_test
61+
save_alsa_state
6162
logger_disabled || func_lib_start_log_collect
6263

6364
setup_kernel_check_point

test-case/check-fw-echo-reference.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ frames=${OPT_VAL['n']}
4141
frequency=${OPT_VAL['f']}
4242

4343
start_test
44+
save_alsa_state
4445
logger_disabled || func_lib_start_log_collect
4546

4647
func_pipeline_export "$tplg" "echo:any"

test-case/check-keyword-detection.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ preamble_time=${OPT_VAL['p']}
5454
duration=${OPT_VAL['d']}
5555

5656
start_test
57+
save_alsa_state
5758
logger_disabled || func_lib_start_log_collect
5859

5960
func_pipeline_export "$tplg" "kpb:any"

test-case/check-kmod-load-unload-after-playback.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ loop_cnt=${OPT_VAL['l']}
5555
pb_duration=${OPT_VAL['d']}
5656

5757
start_test
58+
save_alsa_state
5859

5960
func_pipeline_export "$tplg" "type:playback"
6061

test-case/check-kmod-load-unload.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func_opt_parse_option "$@"
3939
setup_kernel_check_point
4040

4141
start_test
42+
save_alsa_state
4243

4344
loop_cnt=${OPT_VAL['l']}
4445

test-case/check-pause-release-suspend-resume.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ test_mode=${OPT_VAL['m']}
9595
file_name=${OPT_VAL['F']}
9696

9797
start_test
98+
save_alsa_state
9899

99100
case $test_mode in
100101
"playback")

0 commit comments

Comments
 (0)