]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: don't use unlocked resources
authorRuediger Meier <ruediger.meier@ga-group.nl>
Wed, 7 Mar 2018 16:51:35 +0000 (17:51 +0100)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Wed, 7 Mar 2018 18:11:36 +0000 (19:11 +0100)
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>
tests/functions.sh

index 02f9a94f7e9ce69e27f8be691579e29a82983873..004ef0f3c45ec817d7a447ed33c8f4cd688c57b6 100644 (file)
@@ -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