summaryrefslogtreecommitdiffstats
path: root/tests/functions.sh
diff options
context:
space:
mode:
authorRuediger Meier2016-10-21 13:01:55 +0200
committerRuediger Meier2016-10-21 15:08:49 +0200
commit5c711ba9453d46815b3c0ec677893a4a6f34d3bd (patch)
treea93d43859df367d64f982b7930343236b74afcc0 /tests/functions.sh
parentgetopt: be sure that options array is terminated (diff)
downloadkernel-qcow2-util-linux-5c711ba9453d46815b3c0ec677893a4a6f34d3bd.tar.gz
kernel-qcow2-util-linux-5c711ba9453d46815b3c0ec677893a4a6f34d3bd.tar.xz
kernel-qcow2-util-linux-5c711ba9453d46815b3c0ec677893a4a6f34d3bd.zip
tests: consolidate rmmod scsi_debug
- auto cleanup on test exit - Add smart timeout: Newer openSUSE systems on OBS failed to rmmod almost always. udevadm settle does not seem to have any affect. - now tests will fail if rmmod fails Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'tests/functions.sh')
-rw-r--r--tests/functions.sh48
1 files changed, 43 insertions, 5 deletions
diff --git a/tests/functions.sh b/tests/functions.sh
index 609cedffd..fe3ff5751 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -463,6 +463,8 @@ function ts_cleanup_on_exit {
ts_device_deinit "$dev"
done
unset TS_LOOP_DEVS
+
+ ts_scsi_debug_rmmod
}
function ts_image_md5sum {
@@ -644,13 +646,10 @@ function ts_scsi_debug_init {
|| ts_skip "missing scsi_debug module (dry-run)"
# skip if still in use or removal of modules not supported at all
+ # We don't want a slow timeout here so we don't use ts_scsi_debug_rmmod!
modprobe -r scsi_debug &>/dev/null \
|| ts_skip "cannot remove scsi_debug module (rmmod)"
- # TODO validate that all devices are gone, add function ts_scsi_debug_rmmod
- # to be used by the tests too. Tests which produce non-removable scsi
- # devices should fail!
-
modprobe -b scsi_debug "$@" &>/dev/null \
|| ts_skip "cannot load scsi_debug module (modprobe)"
@@ -671,7 +670,46 @@ function ts_scsi_debug_init {
TS_DEVICE="/dev/${devname}"
# TODO validate that device is really up, for now just a warning on stderr
- test -b $TS_DEVICE || echo "warning: scsi_debug device is still down"
+ test -b $TS_DEVICE || echo "warning: scsi_debug device is still down" >&2
+}
+
+# automatically called once in ts_cleanup_on_exit()
+function ts_scsi_debug_rmmod {
+ local err=1
+ local t
+ local lastmsg
+
+ # Return early most importantly in case we are not root or the module does
+ # not exist at all.
+ [ $UID -eq 0 ] || return 0
+ [ -n "$TS_DEVICE" ] || return 0
+ lsmod | grep -q "^scsi_debug " || return 0
+
+ udevadm settle
+
+ # wait for successful rmmod if udevadm settle does not work
+ for t in 0 0.02 0.05 0.1 1; do
+ sleep $t
+ lastmsg="$(modprobe -r scsi_debug 2>&1)" && err=0 && break
+ done
+
+ if [ "$err" = "1" ]; then
+ ts_log "rmmod failed: '$lastmsg'"
+ ts_log "timeout removing scsi_debug module (rmmod)"
+ return 1
+ fi
+ if lsmod | grep -q "^scsi_debug "; then
+ ts_log "BUG! scsi_debug still loaded"
+ return 1
+ fi
+
+ # TODO Do we need to validate that all devices are gone?
+ udevadm settle
+ test -b "$TS_DEVICE" && echo "warning: scsi_debug device is still up" >&2
+
+ # TODO unset TS_DEVICE, check that nobody uses it later, e.g. ts_fdisk_clean
+
+ return 0
}
function ts_resolve_host {