diff options
author | Ruediger Meier <ruediger.meier@ga-group.nl> | 2016-10-21 13:01:55 +0200 |
---|---|---|
committer | Ruediger Meier <ruediger.meier@ga-group.nl> | 2016-10-21 15:08:49 +0200 |
commit | 5c711ba9453d46815b3c0ec677893a4a6f34d3bd (patch) | |
tree | a93d43859df367d64f982b7930343236b74afcc0 | |
parent | e1164591f7927402af8d73d340e75dbfeb06a288 (diff) | |
download | util-linux-5c711ba9453d46815b3c0ec677893a4a6f34d3bd.tar.gz |
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>
-rw-r--r-- | tests/functions.sh | 48 | ||||
-rwxr-xr-x | tests/ts/blkid/mbr-wholedisk | 1 | ||||
-rwxr-xr-x | tests/ts/blkid/md-raid1-part | 2 | ||||
-rwxr-xr-x | tests/ts/eject/umount | 3 | ||||
-rwxr-xr-x | tests/ts/fdisk/align-512-4K | 2 | ||||
-rwxr-xr-x | tests/ts/fdisk/align-512-4K-63 | 1 | ||||
-rwxr-xr-x | tests/ts/fdisk/align-512-4K-md | 3 | ||||
-rwxr-xr-x | tests/ts/fdisk/align-512-512-topology | 2 | ||||
-rwxr-xr-x | tests/ts/libmount/context | 2 | ||||
-rwxr-xr-x | tests/ts/libmount/context-py | 2 | ||||
-rwxr-xr-x | tests/ts/libmount/context-utab | 2 | ||||
-rwxr-xr-x | tests/ts/libmount/context-utab-py | 2 | ||||
-rwxr-xr-x | tests/ts/libmount/tabfiles-tags | 2 | ||||
-rwxr-xr-x | tests/ts/libmount/tabfiles-tags-py | 2 | ||||
-rwxr-xr-x | tests/ts/losetup/losetup-blkdev | 4 | ||||
-rwxr-xr-x | tests/ts/minix/mkfs | 2 | ||||
-rwxr-xr-x | tests/ts/mount/umount-alltargets | 4 | ||||
-rwxr-xr-x | tests/ts/mount/umount-recursive | 4 | ||||
-rwxr-xr-x | tests/ts/partx/partx | 5 | ||||
-rwxr-xr-x | tests/ts/sfdisk/dos | 2 | ||||
-rwxr-xr-x | tests/ts/sfdisk/gpt | 1 | ||||
-rwxr-xr-x | tests/ts/sfdisk/movedata | 1 | ||||
-rwxr-xr-x | tests/ts/sfdisk/resize | 1 | ||||
-rwxr-xr-x | tests/ts/wipefs/wipefs | 1 |
24 files changed, 45 insertions, 54 deletions
diff --git a/tests/functions.sh b/tests/functions.sh index 609cedffde..fe3ff5751e 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 { diff --git a/tests/ts/blkid/mbr-wholedisk b/tests/ts/blkid/mbr-wholedisk index 98c9df1b51..239592e56a 100755 --- a/tests/ts/blkid/mbr-wholedisk +++ b/tests/ts/blkid/mbr-wholedisk @@ -39,5 +39,4 @@ udevadm settle $TS_CMD_BLKID -p -o udev ${TS_DEVICE} >> $TS_OUTPUT ts_finalize_subtest -rmmod scsi_debug ts_finalize diff --git a/tests/ts/blkid/md-raid1-part b/tests/ts/blkid/md-raid1-part index ce3a687c73..9f1276186c 100755 --- a/tests/ts/blkid/md-raid1-part +++ b/tests/ts/blkid/md-raid1-part @@ -79,8 +79,6 @@ $TS_CMD_BLKID -p -o udev ${TS_DEVICE}2 2>&1 | sort >> $TS_OUTPUT mdadm -q -S ${MD_DEVICE} >> $TS_OUTPUT 2>&1 -udevadm settle -rmmod scsi_debug ts_fdisk_clean $TS_DEVICE # substitue UUIDs and major/minor number before comparison diff --git a/tests/ts/eject/umount b/tests/ts/eject/umount index a6e3acff3b..9faab27e61 100755 --- a/tests/ts/eject/umount +++ b/tests/ts/eject/umount @@ -55,8 +55,7 @@ EOF } function deinit_device { - udevadm settle - rmmod scsi_debug + ts_scsi_debug_rmmod } diff --git a/tests/ts/fdisk/align-512-4K b/tests/ts/fdisk/align-512-4K index bdfb5cecac..c312e34f14 100755 --- a/tests/ts/fdisk/align-512-4K +++ b/tests/ts/fdisk/align-512-4K @@ -73,8 +73,6 @@ udevadm settle ts_log "Alignment offsets:" cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTPUT 2>&1 -rmmod scsi_debug - ts_fdisk_clean $TS_DEVICE ts_finalize diff --git a/tests/ts/fdisk/align-512-4K-63 b/tests/ts/fdisk/align-512-4K-63 index e259b5a0a7..b84780bda6 100755 --- a/tests/ts/fdisk/align-512-4K-63 +++ b/tests/ts/fdisk/align-512-4K-63 @@ -73,7 +73,6 @@ udevadm settle ts_log "Alignment offsets:" cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTPUT 2>&1 -rmmod scsi_debug ts_fdisk_clean $TS_DEVICE diff --git a/tests/ts/fdisk/align-512-4K-md b/tests/ts/fdisk/align-512-4K-md index 11a67699bf..04c3df68ec 100755 --- a/tests/ts/fdisk/align-512-4K-md +++ b/tests/ts/fdisk/align-512-4K-md @@ -87,9 +87,6 @@ cat /sys/block/${MD_DEVNAME}/${MD_DEVNAME}p{1,2}/alignment_offset >> $TS_OUTPUT mdadm -q -S ${MD_DEVICE} >> $TS_OUTPUT 2>&1 -udevadm settle -rmmod scsi_debug - ts_fdisk_clean $TS_DEVICE ts_fdisk_clean $MD_DEVICE diff --git a/tests/ts/fdisk/align-512-512-topology b/tests/ts/fdisk/align-512-512-topology index d291e2f978..802ea61c2b 100755 --- a/tests/ts/fdisk/align-512-512-topology +++ b/tests/ts/fdisk/align-512-512-topology @@ -73,8 +73,6 @@ udevadm settle ts_log "Alignment offsets:" cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTPUT 2>&1 -rmmod scsi_debug - ts_fdisk_clean $TS_DEVICE ts_finalize diff --git a/tests/ts/libmount/context b/tests/ts/libmount/context index bcb9534e8d..ebb2441102 100755 --- a/tests/ts/libmount/context +++ b/tests/ts/libmount/context @@ -58,7 +58,6 @@ udevadm settle grep -q $DEVNAME /proc/partitions if [ $? -ne 0 ]; then - rmmod scsi_debug ts_skip "no partition!" fi @@ -157,5 +156,4 @@ $TS_CMD_UMOUNT $TS_NOEXIST rmdir $TS_NOEXIST ts_log "...done." -rmmod scsi_debug ts_finalize diff --git a/tests/ts/libmount/context-py b/tests/ts/libmount/context-py index 66b2eec52a..b4e22b4000 100755 --- a/tests/ts/libmount/context-py +++ b/tests/ts/libmount/context-py @@ -60,7 +60,6 @@ udevadm settle grep -q $DEVNAME /proc/partitions if [ $? -ne 0 ]; then - rmmod scsi_debug ts_skip "no partition!" fi @@ -159,5 +158,4 @@ $TS_CMD_UMOUNT $TS_NOEXIST rmdir $TS_NOEXIST ts_log "...done." -rmmod scsi_debug ts_finalize diff --git a/tests/ts/libmount/context-utab b/tests/ts/libmount/context-utab index a50cf67b2f..e9b1cdf9a4 100755 --- a/tests/ts/libmount/context-utab +++ b/tests/ts/libmount/context-utab @@ -46,7 +46,6 @@ udevadm settle grep -q $DEVNAME /proc/partitions if [ $? -ne 0 ]; then - rmmod scsi_debug ts_skip "no partition!" fi @@ -130,5 +129,4 @@ if type "mkfs.btrfs" &>/dev/null && mkfs.btrfs --version &>/dev/null; then fi ts_log "...done." -rmmod scsi_debug ts_finalize diff --git a/tests/ts/libmount/context-utab-py b/tests/ts/libmount/context-utab-py index 7994f4fc12..94c957d915 100755 --- a/tests/ts/libmount/context-utab-py +++ b/tests/ts/libmount/context-utab-py @@ -47,7 +47,6 @@ udevadm settle grep -q $DEVNAME /proc/partitions if [ $? -ne 0 ]; then - rmmod scsi_debug ts_skip "no partition!" fi @@ -131,5 +130,4 @@ if type "mkfs.btrfs" &>/dev/null && mkfs.btrfs --version &>/dev/null; then fi ts_log "...done." -rmmod scsi_debug ts_finalize diff --git a/tests/ts/libmount/tabfiles-tags b/tests/ts/libmount/tabfiles-tags index 598b11cf62..f986dbc371 100755 --- a/tests/ts/libmount/tabfiles-tags +++ b/tests/ts/libmount/tabfiles-tags @@ -83,6 +83,4 @@ sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT sed -i -e 's/source: .*//g' $TS_OUTPUT # devname is generated, remove it ts_finalize_subtest -udevadm settle -rmmod scsi_debug ts_finalize diff --git a/tests/ts/libmount/tabfiles-tags-py b/tests/ts/libmount/tabfiles-tags-py index 4fd2a2695c..c1ad596bfd 100755 --- a/tests/ts/libmount/tabfiles-tags-py +++ b/tests/ts/libmount/tabfiles-tags-py @@ -87,6 +87,4 @@ sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT sed -i -e 's/source: .*//g' $TS_OUTPUT # devname is generated, remove it ts_finalize_subtest -udevadm settle -rmmod scsi_debug ts_finalize diff --git a/tests/ts/losetup/losetup-blkdev b/tests/ts/losetup/losetup-blkdev index 4e0f95de2d..54693beb99 100755 --- a/tests/ts/losetup/losetup-blkdev +++ b/tests/ts/losetup/losetup-blkdev @@ -78,8 +78,4 @@ udevadm settle $TS_CMD_LOSETUP -d $LODEV ts_finalize_subtest -udevadm settle - -rmmod scsi_debug - ts_finalize diff --git a/tests/ts/minix/mkfs b/tests/ts/minix/mkfs index 9d213328d3..4fc6ad3e03 100755 --- a/tests/ts/minix/mkfs +++ b/tests/ts/minix/mkfs @@ -51,7 +51,5 @@ mkfs_and_mount_minix 'v2c14' '-2 -n 14' mkfs_and_mount_minix 'v2c30' '-2 -n 30' mkfs_and_mount_minix 'v3c60' '-3 -n 60' -udevadm settle -rmmod scsi_debug &>/dev/null ts_finalize diff --git a/tests/ts/mount/umount-alltargets b/tests/ts/mount/umount-alltargets index 53073023a6..687229a879 100755 --- a/tests/ts/mount/umount-alltargets +++ b/tests/ts/mount/umount-alltargets @@ -118,9 +118,5 @@ $TS_CMD_UMOUNT --recursive --all-targets ${TS_DEVICE}1 >> $TS_OUTPUT 2>&1 [ $? == 0 ] || ts_log "umount failed" ts_finalize_subtest -udevadm settle -rmmod scsi_debug >> $TS_OUTPUT 2>&1 -[ $? == 0 ] || ts_die "device busy (umount failed?)" - ts_log "Success" ts_finalize diff --git a/tests/ts/mount/umount-recursive b/tests/ts/mount/umount-recursive index 29669a88d0..85708554fb 100755 --- a/tests/ts/mount/umount-recursive +++ b/tests/ts/mount/umount-recursive @@ -90,10 +90,6 @@ $TS_CMD_MOUNT --bind $TS_MOUNTPOINT/mntB/mntC $TS_MOUNTPOINT/bindC $TS_CMD_UMOUNT --recursive $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1 [ $? == 0 ] || ts_die "umount failed" -udevadm settle -rmmod scsi_debug >> $TS_OUTPUT 2>&1 -[ $? == 0 ] || ts_die "device busy (umount failed?)" - ts_log "Success" ts_finalize diff --git a/tests/ts/partx/partx b/tests/ts/partx/partx index 37990d8be1..5b84afe243 100755 --- a/tests/ts/partx/partx +++ b/tests/ts/partx/partx @@ -59,8 +59,7 @@ $TS_CMD_DELPART ${TS_DEVICE} 1 [ "$?" == 0 ] && echo OK >> $TS_OUTPUT 2>&1 || ts_die "Unable to remove partition" >> $TS_OUTPUT 2>&1 ts_finalize_subtest -udevadm settle -rmmod scsi_debug &> /dev/null +ts_scsi_debug_rmmod # set global variable TS_DEVICE ts_scsi_debug_init dev_size_mb=50 num_parts=$PARTS @@ -135,6 +134,4 @@ $TS_CMD_PARTX -a --nr 0 $TS_DEVICE [ $(ls -d /sys/block/${DEVNAME}/${DEVNAME}* 2>/dev/null | wc -l) -eq $PARTS ] && echo "partitions added" >> $TS_OUTPUT 2>&1 || echo "Failed to add $TS_DEVICE partitions" >> $TS_OUTPUT 2>&1 ts_finalize_subtest -udevadm settle -rmmod scsi_debug ts_finalize diff --git a/tests/ts/sfdisk/dos b/tests/ts/sfdisk/dos index 592d6e4119..692a717250 100755 --- a/tests/ts/sfdisk/dos +++ b/tests/ts/sfdisk/dos @@ -151,6 +151,4 @@ ts_fdisk_clean $TS_DEVICE udevadm settle ts_finalize_subtest - -rmmod scsi_debug ts_finalize diff --git a/tests/ts/sfdisk/gpt b/tests/ts/sfdisk/gpt index 9656bf9642..b1f36a881b 100755 --- a/tests/ts/sfdisk/gpt +++ b/tests/ts/sfdisk/gpt @@ -165,5 +165,4 @@ udevadm settle ts_finalize_subtest -rmmod scsi_debug ts_finalize diff --git a/tests/ts/sfdisk/movedata b/tests/ts/sfdisk/movedata index 64c7371a4c..299d6cce80 100755 --- a/tests/ts/sfdisk/movedata +++ b/tests/ts/sfdisk/movedata @@ -72,5 +72,4 @@ checksum ${TS_DEVICE}1 ts_finalize_subtest -rmmod scsi_debug ts_finalize diff --git a/tests/ts/sfdisk/resize b/tests/ts/sfdisk/resize index 8bc3484da5..ff58e2de9b 100755 --- a/tests/ts/sfdisk/resize +++ b/tests/ts/sfdisk/resize @@ -122,5 +122,4 @@ test_label_resize dos # GPT test_label_resize gpt -rmmod scsi_debug ts_finalize diff --git a/tests/ts/wipefs/wipefs b/tests/ts/wipefs/wipefs index 2a296df78d..6916362997 100755 --- a/tests/ts/wipefs/wipefs +++ b/tests/ts/wipefs/wipefs @@ -30,5 +30,4 @@ $TS_CMD_WIPEFS -a ${TS_DEVICE} > $TS_OUTDIR/out 2>/dev/null # check for output [ -s $TS_OUTDIR/out ] && echo "OK" &> $TS_OUTPUT || exit 1 -rmmod scsi_debug &>/dev/null ts_finalize |