Skip to content

Commit 9e44b14

Browse files
committed
alsa: Move trap to func_exit_handler
Squash before merging. Instead of passing a script name, the $SCRIPT_NAME variable is used. restore_ trap removed and call moved to the func_exit_handler Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
1 parent 0edd342 commit 9e44b14

34 files changed

Lines changed: 46 additions & 53 deletions

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 /var/tmp/"${SCRIPT_NAME}".state ]; then
190+
restore_alsa_state
191+
fi
192+
188193
print_test_result_exit $exit_status
189194
}
190195

case-lib/lib.sh

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,35 +1191,23 @@ perf_analyze()
11911191
# Should be triggered at the end of
11921192
# every test touching ALSA.
11931193
# Couple with save_machine_state.
1194-
# Passes through the status of the previous command
1195-
# so as to not interefere with the func_exit_handler
1196-
# param1: file name
11971194
restore_alsa_state()
11981195
{
1199-
status=$?
1200-
dlogi "restore_alsa_state called with ${1}"
1201-
if [ -f "$1" ]; then
1202-
dlogi "restore_alsa_state found relevant state file."
1203-
alsactl restore --file /var/tmp/"$1" --pedantic --no-ucm --no-init-fallback || dlogi "alsactl state restoration failed!"
1204-
rm /var/tmp/"$1" || dlogi "Old state file removal failed!"
1196+
dlogi "restore_alsa_state called in ${SCRIPT_NAME}"
1197+
if [ -f /var/tmp/"${SCRIPT_NAME}".state ]; then
1198+
dlogi "restore_alsa_state found a relevant state file."
1199+
alsactl restore --file /var/tmp/"${SCRIPT_NAME}".state --pedantic --no-ucm --no-init-fallback || dlogi "alsactl state restoration failed!"
1200+
rm /var/tmp/"${SCRIPT_NAME}".state || dlogi "Old state file removal failed!"
12051201
fi
1206-
return "$status"
12071202
}
12081203

12091204
# Save the machine state to a file.
12101205
# Should be used at the start of
12111206
# every test touching ALSA.
1212-
# Coupled with restore_machine_state on an exit signal.
1213-
# param1: file name
1207+
# Coupled with restore_machine_state
1208+
# on an exit signal inside func_exit_handler.
12141209
save_alsa_state()
12151210
{
1216-
dlogi "save_alsa_state called with ${1}"
1217-
# Prepend the restore_alsa_state to the preexisting EXIT trap.
1218-
cur_exit_trap_code=$(trap -p EXIT | awk -F\' '{print $2}')
1219-
if [[ -z "${cur_exit_trap_code// }" ]]; then
1220-
trap "restore_alsa_state ${1}" EXIT
1221-
else
1222-
trap "restore_alsa_state ${1}; ${cur_exit_trap_code}" EXIT
1223-
fi
1224-
alsactl store --file /var/tmp/"$1" || dlogi "alsactl state storage failed!"
1211+
dlogi "save_alsa_state called in ${SCRIPT_NAME}"
1212+
alsactl store --file /var/tmp/"${SCRIPT_NAME}".state || dlogi "alsactl state storage failed!"
12251213
}

test-case/check-alsabat.sh

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

7676
start_test
77-
save_alsa_state "${0##*/}".state
77+
save_alsa_state
7878

7979
if [ "$pcm_p" = "" ]||[ "$pcm_c" = "" ];
8080
then

test-case/check-audio-equalizer.sh

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

4545
start_test
46-
save_alsa_state "${0##*/}".state
46+
save_alsa_state
4747
setup_kernel_check_point
4848

4949
# Test equalizer

test-case/check-capture.sh

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

6060
start_test
61-
save_alsa_state "${0##*/}".state
61+
save_alsa_state
6262
logger_disabled || func_lib_start_log_collect
6363

6464
setup_kernel_check_point

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

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

4343
start_test
44-
save_alsa_state "${0##*/}".state
44+
save_alsa_state
4545
logger_disabled || func_lib_start_log_collect
4646

4747
func_pipeline_export "$tplg" "echo:any"

test-case/check-keyword-detection.sh

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

5656
start_test
57-
save_alsa_state "${0##*/}".state
57+
save_alsa_state
5858
logger_disabled || func_lib_start_log_collect
5959

6060
func_pipeline_export "$tplg" "kpb:any"

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

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

5757
start_test
58-
save_alsa_state "${0##*/}".state
58+
save_alsa_state
5959

6060
func_pipeline_export "$tplg" "type:playback"
6161

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

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

4141
start_test
42-
save_alsa_state "${0##*/}".state
42+
save_alsa_state
4343

4444
loop_cnt=${OPT_VAL['l']}
4545

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

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

9797
start_test
98-
save_alsa_state "${0##*/}".state
98+
save_alsa_state
9999

100100
case $test_mode in
101101
"playback")

0 commit comments

Comments
 (0)