From: Ruediger Meier Date: Tue, 31 Mar 2015 08:54:56 +0000 (+0200) Subject: tests: introduce ts_cleanup_on_exit() X-Git-Tag: v2.27-rc1~258^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=caf31605dda3d19c356b538d68c1572123053aac;p=thirdparty%2Futil-linux.git tests: introduce ts_cleanup_on_exit() ts_cleanup_on_exit() is always called on exit, e.g. after ts_skip, ts_die, ts_finalize ... A first usage example is the cleanup of TS_SUID_PROGS which is now also done on ts_skip. Later we want to fix some left loop devices. Signed-off-by: Ruediger Meier --- diff --git a/tests/functions.sh b/tests/functions.sh index 55b92738c6..77cc65b07e 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -89,6 +89,7 @@ function ts_skip { if [ -n "$2" -a -b "$2" ]; then ts_device_deinit "$2" fi + ts_cleanup_on_exit exit 0 } @@ -411,11 +412,7 @@ function ts_finalize_subtest { } function ts_finalize { - for idx in $(seq 0 $((${#TS_SUID_PROGS[*]} - 1))); do - PROG=${TS_SUID_PROGS[$idx]} - chmod a-s $PROG &> /dev/null - chown ${TS_SUID_USER[$idx]}.${TS_SUID_GROUP[$idx]} $PROG &> /dev/null - done + ts_cleanup_on_exit if [ $TS_NSUBTESTS -ne 0 ]; then printf "%11s..." @@ -446,6 +443,15 @@ function ts_die { ts_finalize } +function ts_cleanup_on_exit { + + for idx in $(seq 0 $((${#TS_SUID_PROGS[*]} - 1))); do + PROG=${TS_SUID_PROGS[$idx]} + chmod a-s $PROG &> /dev/null + chown ${TS_SUID_USER[$idx]}.${TS_SUID_GROUP[$idx]} $PROG &> /dev/null + done +} + function ts_image_md5sum { local img=${1:-"$TS_OUTDIR/${TS_TESTNAME}.img"} echo $(md5sum "$img" | awk '{printf $1}') $(basename "$img")