summaryrefslogtreecommitdiffstats
path: root/tests/functions.sh
diff options
context:
space:
mode:
authorRuediger Meier2015-03-31 14:19:40 +0200
committerRuediger Meier2015-04-14 13:18:42 +0200
commitcbae7931c85d232269d45ec6766b293c40cbdb09 (patch)
treeb87f66967928f66a9ab8787a5b13c526a5d53024 /tests/functions.sh
parenttests: introduce ts_cleanup_on_exit() (diff)
downloadkernel-qcow2-util-linux-cbae7931c85d232269d45ec6766b293c40cbdb09.tar.gz
kernel-qcow2-util-linux-cbae7931c85d232269d45ec6766b293c40cbdb09.tar.xz
kernel-qcow2-util-linux-cbae7931c85d232269d45ec6766b293c40cbdb09.zip
tests: introduce TS_LOOP_DEVS for cleanup
We are maintaining an array TS_LOOP_DEVS to de-initialize devices always on exit. Until now there was no cleanup in ts_skip(). The downside is that we can't execute ts_device_init() in a subshell anymore. The device is returned via global variable TS_LODEV, similar like we do already in ts_scsi_debug_init(). Tests which don't use ts_device_init() to create loop devices may use ts_register_loop_device() to get them cleaned up later. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'tests/functions.sh')
-rw-r--r--tests/functions.sh26
1 files changed, 18 insertions, 8 deletions
diff --git a/tests/functions.sh b/tests/functions.sh
index 77cc65b07..2679a3fb0 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -86,9 +86,7 @@ function ts_skip_subtest {
function ts_skip {
ts_skip_subtest "$1"
- if [ -n "$2" -a -b "$2" ]; then
- ts_device_deinit "$2"
- fi
+
ts_cleanup_on_exit
exit 0
}
@@ -254,6 +252,7 @@ function ts_init_env {
declare -a TS_SUID_PROGS
declare -a TS_SUID_USER
declare -a TS_SUID_GROUP
+ declare -a TS_LOOP_DEVS
if [ -f $TS_TOPDIR/commands.sh ]; then
. $TS_TOPDIR/commands.sh
@@ -436,10 +435,6 @@ function ts_finalize {
function ts_die {
ts_log "$1"
- if [ -n "$2" ] && [ -b "$2" ]; then
- ts_device_deinit "$2"
- ts_fstab_clean # for sure...
- fi
ts_finalize
}
@@ -450,6 +445,11 @@ function ts_cleanup_on_exit {
chmod a-s $PROG &> /dev/null
chown ${TS_SUID_USER[$idx]}.${TS_SUID_GROUP[$idx]} $PROG &> /dev/null
done
+
+ for dev in "${TS_LOOP_DEVS[@]}"; do
+ ts_device_deinit "$dev"
+ done
+ unset TS_LOOP_DEVS
}
function ts_image_md5sum {
@@ -466,16 +466,26 @@ function ts_image_init {
return 0
}
+function ts_register_loop_device {
+ local ct=${#TS_LOOP_DEVS[*]}
+ TS_LOOP_DEVS[$ct]=$1
+}
+
function ts_device_init {
local img
local dev
img=$(ts_image_init $1 $2)
dev=$($TS_CMD_LOSETUP --show -f "$img")
+ if [ "$?" != "0" -o "$dev" = "" ]; then
+ ts_die "Cannot init device"
+ fi
- echo $dev
+ ts_register_loop_device "$dev"
+ TS_LODEV=$dev
}
+# call from ts_cleanup_on_exit() only because of TS_LOOP_DEVS maintenance
function ts_device_deinit {
local DEV="$1"