]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: consolidate scsi_debug usage
authorKarel Zak <kzak@redhat.com>
Fri, 12 Apr 2013 14:36:33 +0000 (16:36 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 12 Apr 2013 14:36:33 +0000 (16:36 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
13 files changed:
tests/functions.sh
tests/ts/blkid/md-raid0-whole
tests/ts/blkid/md-raid1-part
tests/ts/eject/umount
tests/ts/fdisk/align-512-4K
tests/ts/fdisk/align-512-4K-63
tests/ts/fdisk/align-512-4K-md
tests/ts/fdisk/align-512-512-topology
tests/ts/libmount/context
tests/ts/libmount/context-utab
tests/ts/libmount/tabfiles-tags
tests/ts/mount/umount-alltargets
tests/ts/mount/umount-recursive

index 8293539d24dfe477627eeb70455724d4eb2cfb6f..2ca98f8ca56f5cc26d75db5203f97cc86522a7f1 100644 (file)
@@ -461,10 +461,35 @@ s/# <!-- util-linux.*-->//;
 }
 
 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
+}
index b1faf3f1a5d41825002cce3f21d74cdc076e2418..45c5bb0ec5d5556be83dd6551afd126de59d39c2 100755 (executable)
@@ -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
 
index f627217f8ca6a290449c21519990461e2d80d8a6..46bde0ec840d3553bef16bce2240411569ff98b9 100755 (executable)
@@ -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 <<EOF
@@ -79,7 +66,7 @@ $TS_CMD_BLKID -p -o udev ${DEVICE}2 2>&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__/' \
index 20f4e1238a71f3028b1330d460169aec06cf0887..3c1f84edfb68b93188bdd89c332b76940aa157e4 100755 (executable)
@@ -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 {
index d72c96c1a054161ca801004a2c55179c7a6fd656..c5ea72e7a18071b6fed764c40520ae4fd72559ff 100755 (executable)
@@ -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 <<EOF
@@ -82,6 +71,6 @@ cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTP
 
 rmmod scsi_debug
 
-ts_fdisk_clean
+ts_fdisk_clean $DEVICE
 
 ts_finalize
index e1b03fda4cb8ea3cf7a7837b53147f761072b97e..4ec81982facf0f9c904f607fac4838f15bc8ae08 100755 (executable)
@@ -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 <<EOF
@@ -82,6 +71,6 @@ cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTP
 
 rmmod scsi_debug
 
-ts_fdisk_clean
+ts_fdisk_clean $DEVICE
 
 ts_finalize
index bd7bb0f0c9e55ef4ea9622466a6e55cc7dfebf85..09947ff9e43eceea299b5454ae3e97787fd9baca 100755 (executable)
@@ -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 <<EOF
@@ -97,6 +85,6 @@ cat /sys/block/${MD_DEVNAME}/${MD_DEVNAME}p{1,2}/alignment_offset >> $TS_OUTPUT
 udevadm settle
 rmmod scsi_debug
 
-ts_fdisk_clean
+ts_fdisk_clean $DEVICE
 
 ts_finalize
index 2a83e0839fe271840bb83f849ba6698d4a9d51df..9354e45c769e042a1434212a8252ce29cf39f77f 100755 (executable)
@@ -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 <<EOF
@@ -82,6 +72,6 @@ cat /sys/block/${DEVNAME}/${DEVNAME}{1,2,3,4,5,6,7}/alignment_offset >> $TS_OUTP
 
 rmmod scsi_debug
 
-ts_fdisk_clean
+ts_fdisk_clean $DEVICE
 
 ts_finalize
index c1c1fb74b94c86889871baccc271c396bdfff0af..0c3bce986d7b2fd439cc49b58c54a6be01a53c56 100755 (executable)
@@ -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 <<EOF
+$TS_CMD_FDISK ${DEVICE} &> /dev/null <<EOF
 n
 p
 1
@@ -48,9 +35,17 @@ w
 q
 EOF
 
-DEVICE="/dev/${DEVNAME}1"
+DEVICE="${DEVICE}1"
+
+sleep 1
 udevadm settle
 
+grep -q $DEVNAME /proc/partitions
+if [ $? -ne 0 ]; then
+       rmmod scsi_debug
+       ts_skip "no partition!"
+fi
+
 ts_log "Create filesystem"
 mkfs.ext4 -L "$LABEL" -U "$UUID" $DEVICE &> /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
index 3d3f5c6c0c8d500dfa5415590a16c3a505c838d2..35851628d82c280017508571ce747ba31f4233d0 100755 (executable)
@@ -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 <<EOF
+$TS_CMD_FDISK ${DEVICE} &> /dev/null <<EOF
 n
 p
 1
@@ -43,10 +30,17 @@ w
 q
 EOF
 
-DEVICE="/dev/${DEVNAME}1"
+DEVICE="${DEVICE}1"
 
+sleep 1
 udevadm settle
 
+grep -q $DEVNAME /proc/partitions
+if [ $? -ne 0 ]; then
+       rmmod scsi_debug
+       ts_skip "no partition!"
+fi
+
 ts_log "Create filesystem"
 mkfs.ext4 -L "$LABEL" -U "$UUID" $DEVICE &> /dev/null
 
index 799149a7c59d98cdb88e3ccef4e241c024e03662..f52c4047c6747787890b4ef7568246e340173471 100755 (executable)
@@ -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"
 
index 3c5731af078c1cfce490bee81146daf934421050..1b09112d42b4e361962c7b949376fc90400eaf28 100755 (executable)
@@ -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 <<EOF
index 13a075f676db2863ffe8bf943f0d595bcb35ab2a..128df885a6c587818576b847396dccf9d9bea798 100755 (executable)
@@ -9,21 +9,8 @@ TS_DESC="umount-recursive"
 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 <<EOF