From 618ec053fe2d1353eb1c15ebf98c1f4ef9b08ed1 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 12 Apr 2013 16:36:33 +0200 Subject: tests: consolidate scsi_debug usage Signed-off-by: Karel Zak --- tests/functions.sh | 27 ++++++++++++++++++++++++++- tests/ts/blkid/md-raid0-whole | 1 + tests/ts/blkid/md-raid1-part | 17 ++--------------- tests/ts/eject/umount | 16 +--------------- tests/ts/fdisk/align-512-4K | 17 +++-------------- tests/ts/fdisk/align-512-4K-63 | 17 +++-------------- tests/ts/fdisk/align-512-4K-md | 18 +++--------------- tests/ts/fdisk/align-512-512-topology | 16 +++------------- tests/ts/libmount/context | 30 +++++++++++++----------------- tests/ts/libmount/context-utab | 28 +++++++++++----------------- tests/ts/libmount/tabfiles-tags | 17 +---------------- tests/ts/mount/umount-alltargets | 16 +--------------- tests/ts/mount/umount-recursive | 15 +-------------- 13 files changed, 69 insertions(+), 166 deletions(-) diff --git a/tests/functions.sh b/tests/functions.sh index 8293539d2..2ca98f8ca 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -461,10 +461,35 @@ s/# //; } function ts_fdisk_clean { + local DEVNAME=$(basename "$1") + # remove non comparable parts of fdisk output - [ x"${DEVNAME}" != x"" ] && sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT + if [ x"${DEVNAME}" != x"" ]; then + sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT + fi + sed -i -e 's/Disk identifier:.*//g' \ -e 's/Building a new.*//g' \ -e 's/Welcome to fdisk.*//g' \ $TS_OUTPUT } + +function ts_scsi_debug_init { + + modprobe --dry-run --quiet scsi_debug + [ "$?" == 0 ] || ts_skip "missing scsi_debug module" + + rmmod scsi_debug &> /dev/null + modprobe scsi_debug $* + [ "$?" == 0 ] || ts_die "Cannot init device" + + DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') + [ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" + + DEVICE="/dev/${DEVNAME}" + + sleep 1 + udevadm settle + + echo $DEVICE +} diff --git a/tests/ts/blkid/md-raid0-whole b/tests/ts/blkid/md-raid0-whole index b1faf3f1a..45c5bb0ec 100755 --- a/tests/ts/blkid/md-raid0-whole +++ b/tests/ts/blkid/md-raid0-whole @@ -79,6 +79,7 @@ ts_device_deinit $DEVICE1 ts_device_deinit $DEVICE2 ts_fdisk_clean + # remove generated UUIDs sed -i -e 's/ID_FS_UUID.*//g' $TS_OUTPUT diff --git a/tests/ts/blkid/md-raid1-part b/tests/ts/blkid/md-raid1-part index f627217f8..46bde0ec8 100755 --- a/tests/ts/blkid/md-raid1-part +++ b/tests/ts/blkid/md-raid1-part @@ -23,20 +23,7 @@ TS_DESC="MD raid1 (last partition)" ts_init "$*" ts_skip_nonroot -modprobe --dry-run --quiet scsi_debug -[ "$?" == 0 ] || ts_skip "missing scsi_debug module" -[ -x /sbin/mdadm ] || ts_skip "missing mdadm" - -rmmod scsi_debug &> /dev/null -modprobe scsi_debug dev_size_mb=51 sector_size=512 -[ "$?" == 0 ] || ts_die "Cannot init device" - -sleep 3 - -DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') -[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - -DEVICE="/dev/${DEVNAME}" +DEVICE=$(ts_scsi_debug_init dev_size_mb=51 sector_size=512) ts_log "Create partitions" $TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <&1 | sort >> $TS_OUTPUT udevadm settle rmmod scsi_debug -ts_fdisk_clean +ts_fdisk_clean $DEVICE # substitue UUIDs and major/minor number before comparison sed -i \ -e 's/^\(ID_FS_UUID\)=.*/\1=__ts_uuid__/' \ diff --git a/tests/ts/eject/umount b/tests/ts/eject/umount index 20f4e1238..3c1f84edf 100755 --- a/tests/ts/eject/umount +++ b/tests/ts/eject/umount @@ -12,22 +12,8 @@ ts_skip_nonroot # not removable device. # -modprobe --dry-run --quiet scsi_debug -[ "$?" == 0 ] || ts_skip "missing scsi_debug module" - -rmmod scsi_debug &> /dev/null - function init_device { - modprobe scsi_debug dev_size_mb=100 - [ "$?" == 0 ] || ts_die "Cannot init device" - - sleep 3 - - DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') - [ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - - echo "/dev/${DEVNAME}" - + ts_scsi_debug_init dev_size_mb=100 } function init_partitions { diff --git a/tests/ts/fdisk/align-512-4K b/tests/ts/fdisk/align-512-4K index d72c96c1a..c5ea72e7a 100755 --- a/tests/ts/fdisk/align-512-4K +++ b/tests/ts/fdisk/align-512-4K @@ -27,19 +27,8 @@ TS_DESC="align 512/4K" ts_init "$*" ts_skip_nonroot -modprobe --dry-run --quiet scsi_debug -[ "$?" == 0 ] || ts_skip "missing scsi_debug module" - -rmmod scsi_debug &> /dev/null -modprobe scsi_debug dev_size_mb=50 sector_size=512 physblk_exp=3 -[ "$?" == 0 ] || ts_die "Cannot init device" - -sleep 3 - -DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') -[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - -DEVICE="/dev/${DEVNAME}" +DEVICE=$(ts_scsi_debug_init dev_size_mb=50 sector_size=512 physblk_exp=3) +DEVNAME=$(basename $DEVICE) ts_log "Create partitions" $TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <> $TS_OUTP rmmod scsi_debug -ts_fdisk_clean +ts_fdisk_clean $DEVICE ts_finalize diff --git a/tests/ts/fdisk/align-512-4K-63 b/tests/ts/fdisk/align-512-4K-63 index e1b03fda4..4ec81982f 100755 --- a/tests/ts/fdisk/align-512-4K-63 +++ b/tests/ts/fdisk/align-512-4K-63 @@ -27,19 +27,8 @@ TS_DESC="align 512/4K +alignment_offset" ts_init "$*" ts_skip_nonroot -modprobe --dry-run --quiet scsi_debug -[ "$?" == 0 ] || ts_skip "missing scsi_debug module" - -rmmod scsi_debug &> /dev/null -modprobe scsi_debug dev_size_mb=50 sector_size=512 physblk_exp=3 lowest_aligned=7 -[ "$?" == 0 ] || ts_die "Cannot init device" - -sleep 3 - -DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') -[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - -DEVICE="/dev/${DEVNAME}" +DEVICE=$(ts_scsi_debug_init dev_size_mb=50 sector_size=512 physblk_exp=3 lowest_aligned=7) +DEVNAME=$(basename $DEVICE) ts_log "Create partitions" $TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <> $TS_OUTP rmmod scsi_debug -ts_fdisk_clean +ts_fdisk_clean $DEVICE ts_finalize diff --git a/tests/ts/fdisk/align-512-4K-md b/tests/ts/fdisk/align-512-4K-md index bd7bb0f0c..09947ff9e 100755 --- a/tests/ts/fdisk/align-512-4K-md +++ b/tests/ts/fdisk/align-512-4K-md @@ -27,20 +27,8 @@ TS_DESC="align 512/4K +MD" ts_init "$*" ts_skip_nonroot -modprobe --dry-run --quiet scsi_debug -[ "$?" == 0 ] || ts_skip "missing scsi_debug module" -[ -x /sbin/mdadm ] || ts_skip "missing mdadm" - -rmmod scsi_debug &> /dev/null -modprobe scsi_debug dev_size_mb=50 sector_size=512 physblk_exp=3 -[ "$?" == 0 ] || ts_die "Cannot init device" - -sleep 3 - -DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') -[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - -DEVICE="/dev/${DEVNAME}" +DEVICE=$(ts_scsi_debug_init dev_size_mb=50 sector_size=512 physblk_exp=3) +DEVNAME=$(basename $DEVICE) ts_log "Create partitions" $TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <> $TS_OUTPUT udevadm settle rmmod scsi_debug -ts_fdisk_clean +ts_fdisk_clean $DEVICE ts_finalize diff --git a/tests/ts/fdisk/align-512-512-topology b/tests/ts/fdisk/align-512-512-topology index 2a83e0839..9354e45c7 100755 --- a/tests/ts/fdisk/align-512-512-topology +++ b/tests/ts/fdisk/align-512-512-topology @@ -27,19 +27,9 @@ TS_DESC="align 512/512 +topology" ts_init "$*" ts_skip_nonroot -modprobe --dry-run --quiet scsi_debug -[ "$?" == 0 ] || ts_skip "missing scsi_debug module" -rmmod scsi_debug &> /dev/null -modprobe scsi_debug dev_size_mb=50 sector_size=512 -[ "$?" == 0 ] || ts_die "Cannot init device" - -sleep 3 - -DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') -[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - -DEVICE="/dev/${DEVNAME}" +DEVICE=$(ts_scsi_debug_init dev_size_mb=50 sector_size=512) +DEVNAME=$(basename $DEVICE) ts_log "Create partitions" $TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <> $TS_OUTP rmmod scsi_debug -ts_fdisk_clean +ts_fdisk_clean $DEVICE ts_finalize diff --git a/tests/ts/libmount/context b/tests/ts/libmount/context index c1c1fb74b..0c3bce986 100755 --- a/tests/ts/libmount/context +++ b/tests/ts/libmount/context @@ -16,29 +16,16 @@ MOUNTPOINT="$TS_MOUNTPOINT" TS_NOEXIST="$TS_OUTDIR/${TS_TESTNAME}-${TS_SUBNAME}-noex" [ -d $TS_NOEXIST ] && rmdir $TS_NOEXIST -#set -x - [ -x $TESTPROG ] || ts_skip "test not compiled" -modprobe --dry-run --quiet scsi_debug -[ "$?" == 0 ] || ts_skip "missing scsi_debug module" - ts_log "Init device" umount $MOUNTPOINT &> /dev/null -rmmod scsi_debug &> /dev/null -modprobe scsi_debug dev_size_mb=100 -[ "$?" == 0 ] || ts_die "Cannot init device" -sleep 3 - -DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') -[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - -DEVICE="/dev/${DEVNAME}" -udevadm settle +DEVICE=$(ts_scsi_debug_init dev_size_mb=100) +DEVNAME=$(basename $DEVICE) ts_log "Create partitions" -$TS_CMD_FDISK ${DEVICE} >> /dev/null 2>&1 < /dev/null < /dev/null @@ -60,6 +55,7 @@ export LIBMOUNT_MTAB=$TS_OUTPUT.mtab > $LIBMOUNT_MTAB udevadm settle +ts_device_has "TYPE" "ext4" $DEVICE || ts_die "Cannot find ext3 on $DEVICE" $DEVICE ts_init_subtest "mount-by-devname" mkdir -p $MOUNTPOINT &> /dev/null diff --git a/tests/ts/libmount/context-utab b/tests/ts/libmount/context-utab index 3d3f5c6c0..35851628d 100755 --- a/tests/ts/libmount/context-utab +++ b/tests/ts/libmount/context-utab @@ -16,24 +16,11 @@ MOUNTPOINT="$TS_MOUNTPOINT" [ -x $TESTPROG ] || ts_skip "test not compiled" -modprobe --dry-run --quiet scsi_debug -[ "$?" == 0 ] || ts_skip "missing scsi_debug module" - -ts_log "Init device" -rmmod scsi_debug &> /dev/null -modprobe scsi_debug dev_size_mb=260 -[ "$?" == 0 ] || ts_die "Cannot init device" - -sleep 3 - -DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') -[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - -DEVICE="/dev/${DEVNAME}" -udevadm settle +DEVICE=$(ts_scsi_debug_init dev_size_mb=100) +DEVNAME=$(basename $DEVICE) ts_log "Create partitions" -$TS_CMD_FDISK ${DEVICE} >> /dev/null 2>&1 < /dev/null < /dev/null diff --git a/tests/ts/libmount/tabfiles-tags b/tests/ts/libmount/tabfiles-tags index 799149a7c..f52c4047c 100755 --- a/tests/ts/libmount/tabfiles-tags +++ b/tests/ts/libmount/tabfiles-tags @@ -11,22 +11,7 @@ TESTPROG="$TS_HELPER_LIBMOUNT_TAB" [ -x $TESTPROG ] || ts_skip "test not compiled" -# -# Init device -# -modprobe --dry-run --quiet scsi_debug -[ "$?" == 0 ] || ts_skip "missing scsi_debug module" - -rmmod scsi_debug &> /dev/null -modprobe scsi_debug dev_size_mb=50 sector_size=512 -[ "$?" == 0 ] || ts_die "Cannot init device" - -sleep 3 - -DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') -[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - -DEVICE="/dev/${DEVNAME}" +DEVICE=$(ts_scsi_debug_init dev_size_mb=50 sector_size=512) LABEL="testLibmount" UUID="de1bc6e9-34ab-4151-a1d7-900042eee8d9" diff --git a/tests/ts/mount/umount-alltargets b/tests/ts/mount/umount-alltargets index 3c5731af0..1b09112d4 100755 --- a/tests/ts/mount/umount-alltargets +++ b/tests/ts/mount/umount-alltargets @@ -9,21 +9,7 @@ TS_DESC="umount-all-targets" ts_init "$*" ts_skip_nonroot -modprobe --dry-run --quiet scsi_debug -[ "$?" == 0 ] || ts_skip "missing scsi_debug module" - -ts_log "Init device" -$TS_CMD_UMOUNT --recursive $MOUNTPOINT &> /dev/null -rmmod scsi_debug &> /dev/null -modprobe scsi_debug dev_size_mb=50 -[ "$?" == 0 ] || ts_die "Cannot init device" - -sleep 3 - -DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') -[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - -DEVICE="/dev/${DEVNAME}" +DEVICE=$(ts_scsi_debug_init dev_size_mb=50) ts_log "Create partitions" $TS_CMD_FDISK ${DEVICE} &> /dev/null < /dev/null -rmmod scsi_debug &> /dev/null -modprobe scsi_debug dev_size_mb=50 -[ "$?" == 0 ] || ts_die "Cannot init device" - -sleep 3 - -DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}') -[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device" - -DEVICE="/dev/${DEVNAME}" +DEVICE=$(ts_scsi_debug_init dev_size_mb=50) ts_log "Create partitions" $TS_CMD_FDISK ${DEVICE} &> /dev/null <