summaryrefslogtreecommitdiffstats
path: root/tests/functions.sh
diff options
context:
space:
mode:
authorRuediger Meier2018-03-07 17:51:35 +0100
committerRuediger Meier2018-03-07 19:11:36 +0100
commitb0d9114a6160b23a65c545a4cd65cfba45c493ff (patch)
tree3c071729a4f012a814cc6c202284c36559483932 /tests/functions.sh
parenttests: don't lock fd 1 (stdout), don't use /proc/$$/fd (diff)
downloadkernel-qcow2-util-linux-b0d9114a6160b23a65c545a4cd65cfba45c493ff.tar.gz
kernel-qcow2-util-linux-b0d9114a6160b23a65c545a4cd65cfba45c493ff.tar.xz
kernel-qcow2-util-linux-b0d9114a6160b23a65c545a4cd65cfba45c493ff.zip
tests: don't use unlocked resources
The test-suite did not survive when flock timeouts after 30s because then ts_cleanup_on_exit() may use resources (e.g. rmmod scsi_debug) while not having the lock. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'tests/functions.sh')
-rw-r--r--tests/functions.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/functions.sh b/tests/functions.sh
index 02f9a94f7..004ef0f3c 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -512,6 +512,12 @@ function ts_cleanup_on_exit {
done
unset TS_LOOP_DEVS
+ # just informative warnings, currently not seen
+ for resource in "${!TS_LOCKFILE_FD[@]}"; do
+ test -n "${TS_LOCKFILE_FD["resource"]}" || continue
+ echo "[$$ $TS_TESTNAME] warning: found unlocked $resource"
+ done
+
ts_scsi_debug_rmmod
}
@@ -660,6 +666,7 @@ function ts_fstab_add {
}
function ts_fstab_clean {
+ ts_have_lock "fstab" || return 0
sed --in-place "
/# <!-- util-linux/!b
:a
@@ -710,6 +717,14 @@ function ts_find_free_fd()
return 1
}
+function ts_have_lock {
+ local resource=$1
+
+ test "$TS_NOLOCKS" = "yes" && return 0
+ test -n "${TS_LOCKFILE_FD["$resource"]}" && return 0
+ return 1
+}
+
function ts_lock {
local resource="$1"
local lockfile="${TS_LOCKDIR}/${resource}.lock"
@@ -749,6 +764,8 @@ function ts_unlock {
eval "exec $fd<&-"
TS_LOCKFILE_FD["$resource"]=""
###echo "[$$ $TS_TESTNAME] Unlocked $resource"
+ else
+ echo "[$$ $TS_TESTNAME] ${resource} unlocking unlocked $resource!?"
fi
}
@@ -800,6 +817,9 @@ function ts_scsi_debug_rmmod {
local t
local lastmsg
+ # We must not run if we don't have the lock
+ ts_have_lock "scsi_debug" || return 0
+
# Return early most importantly in case we are not root or the module does
# not exist at all.
[ $UID -eq 0 ] || return 0