diff options
author | Ruediger Meier | 2018-03-08 11:45:30 +0100 |
---|---|---|
committer | Ruediger Meier | 2018-03-08 12:04:44 +0100 |
commit | 539b0b09ea4c7d7dabd6a467866565134126a608 (patch) | |
tree | 764cef1e54411a1b7ba34763c0b96344a2ed415e /tests/functions.sh | |
parent | docs: add remount-all idea to TODO (diff) | |
download | kernel-qcow2-util-linux-539b0b09ea4c7d7dabd6a467866565134126a608.tar.gz kernel-qcow2-util-linux-539b0b09ea4c7d7dabd6a467866565134126a608.tar.xz kernel-qcow2-util-linux-539b0b09ea4c7d7dabd6a467866565134126a608.zip |
tests: re-introduce bash 3 compatibility (OSX)
Bash 4 is now almost 10 years old and it seemed to be fine in 613a337e
to use associative arrays. Unfortunately OSX will probably never update
to 4 because of GPLv3. We don't want to lose our travis OSX build and
use plain arrays again.
BTW remove that "informative warnings" about unlocked resources. They
were only silent so far because of a bug. Any system where scsi_debug
is broken would print a lot of these warnings. This also tells us that
we could even stop calling ts_unlock() explicitly. Just exiting the
tests would be good enough.
Note that currently flock(1) is not available on our OSX build anyways.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'tests/functions.sh')
-rw-r--r-- | tests/functions.sh | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/tests/functions.sh b/tests/functions.sh index 376e78929..fc8f86377 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -15,11 +15,6 @@ # -# Global array to remember all issued lock FDs. It does not seem possible to -# declare this within a function (ts_init_env). -declare -A TS_LOCKFILE_FD - - function ts_abspath { cd $1 pwd @@ -307,6 +302,7 @@ function ts_init_env { declare -a TS_SUID_USER declare -a TS_SUID_GROUP declare -a TS_LOOP_DEVS + declare -a TS_LOCKFILE_FD if [ -f $TS_TOPDIR/commands.sh ]; then . $TS_TOPDIR/commands.sh @@ -512,12 +508,6 @@ 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 } @@ -717,11 +707,24 @@ function ts_find_free_fd() return 1 } +function ts_get_lock_fd { + local resource=$1 + local fd + + for fd in "${!TS_LOCKFILE_FD[@]}"; do + if [ "${TS_LOCKFILE_FD["$fd"]}" = "$resource" ]; then + echo "$fd" + return 0 + fi + done + return 1 +} + function ts_have_lock { local resource=$1 test "$TS_NOLOCKS" = "yes" && return 0 - test -n "${TS_LOCKFILE_FD["$resource"]}" && return 0 + ts_get_lock_fd "$resource" >/dev/null && return 0 return 1 } @@ -735,7 +738,7 @@ function ts_lock { fi # Don't lock again - fd=${TS_LOCKFILE_FD["$resource"]} + fd=$(ts_get_lock_fd "$resource") if [ -n "$fd" ]; then echo "[$$ $TS_TESTNAME] ${resource} already locked!" return 0 @@ -745,8 +748,8 @@ function ts_lock { eval "exec $fd>$lockfile" flock --exclusive "$fd" || ts_skip "failed to lock $resource" - TS_LOCKFILE_FD["$resource"]="$fd" + TS_LOCKFILE_FD["$fd"]="$resource" ###echo "[$$ $TS_TESTNAME] Locked $resource" } @@ -759,13 +762,13 @@ function ts_unlock { return 0 fi - fd=${TS_LOCKFILE_FD["$resource"]} + fd=$(ts_get_lock_fd "$resource") if [ -n "$fd" ]; then eval "exec $fd<&-" - TS_LOCKFILE_FD["$resource"]="" + TS_LOCKFILE_FD["$fd"]="" ###echo "[$$ $TS_TESTNAME] Unlocked $resource" else - echo "[$$ $TS_TESTNAME] ${resource} unlocking unlocked $resource!?" + echo "[$$ $TS_TESTNAME] unlocking unlocked $resource!?" fi } |