From 64a2331f6d03fd483820ddacd8c62336b2e7df5c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 23 Nov 2010 13:06:46 +0100 Subject: [PATCH] tests: improve libmount context mount and umount test Signed-off-by: Karel Zak --- shlibs/mount/src/context.c | 4 + tests/commands.sh.in | 2 + tests/expected/libmount/{mount => context} | 0 .../libmount/context-mount-by-devname | 1 + .../expected/libmount/context-mount-by-label | 1 + tests/expected/libmount/context-mount-by-uuid | 2 + tests/expected/libmount/context-mount-flags | 3 + .../libmount/context-umount-by-devname | 1 + .../libmount/context-umount-by-mountpoint | 1 + tests/functions.sh | 7 +- tests/ts/libmount/context | 111 ++++++++++++++++++ tests/ts/libmount/mount | 83 ------------- 12 files changed, 130 insertions(+), 86 deletions(-) rename tests/expected/libmount/{mount => context} (100%) create mode 100644 tests/expected/libmount/context-mount-by-devname create mode 100644 tests/expected/libmount/context-mount-by-label create mode 100644 tests/expected/libmount/context-mount-by-uuid create mode 100644 tests/expected/libmount/context-mount-flags create mode 100644 tests/expected/libmount/context-umount-by-devname create mode 100644 tests/expected/libmount/context-umount-by-mountpoint create mode 100755 tests/ts/libmount/context delete mode 100755 tests/ts/libmount/mount diff --git a/shlibs/mount/src/context.c b/shlibs/mount/src/context.c index 923d7191..2cc76a0a 100644 --- a/shlibs/mount/src/context.c +++ b/shlibs/mount/src/context.c @@ -1318,6 +1318,8 @@ int test_mount(struct mtest *ts, int argc, char *argv[]) rc = mnt_context_do_mount(cxt); if (rc) printf("failed to mount %s\n", strerror(errno)); + else + printf("successfully mounted\n"); mnt_free_context(cxt); return rc; @@ -1370,6 +1372,8 @@ int test_umount(struct mtest *ts, int argc, char *argv[]) rc = mnt_context_do_umount(cxt); if (rc) printf("failed to umount\n"); + else + printf("successfully umounted\n"); err: mnt_free_context(cxt); return rc; diff --git a/tests/commands.sh.in b/tests/commands.sh.in index 9e568106..19193922 100644 --- a/tests/commands.sh.in +++ b/tests/commands.sh.in @@ -60,5 +60,7 @@ TS_CMD_LSCPU=${TS_CMD_LSCPU-"$top_builddir/sys-utils/lscpu"} TS_CMD_BLKID=${TS_CMD_BLKID-"$top_builddir/misc-utils/blkid"} TS_CMD_PARTX=${TS_CMD_PARTX-"$top_builddir/partx/partx"} +TS_CMD_FINDMNT=${TS_CMD_FINDMNT-"$top_builddir/misc-utils/findmnt"} + TS_CMD_FDISK=${TS_CMD_FDISK-"$top_builddir/fdisk/fdisk"} diff --git a/tests/expected/libmount/mount b/tests/expected/libmount/context similarity index 100% rename from tests/expected/libmount/mount rename to tests/expected/libmount/context diff --git a/tests/expected/libmount/context-mount-by-devname b/tests/expected/libmount/context-mount-by-devname new file mode 100644 index 00000000..7504a7e8 --- /dev/null +++ b/tests/expected/libmount/context-mount-by-devname @@ -0,0 +1 @@ +successfully mounted diff --git a/tests/expected/libmount/context-mount-by-label b/tests/expected/libmount/context-mount-by-label new file mode 100644 index 00000000..7504a7e8 --- /dev/null +++ b/tests/expected/libmount/context-mount-by-label @@ -0,0 +1 @@ +successfully mounted diff --git a/tests/expected/libmount/context-mount-by-uuid b/tests/expected/libmount/context-mount-by-uuid new file mode 100644 index 00000000..2f44fc47 --- /dev/null +++ b/tests/expected/libmount/context-mount-by-uuid @@ -0,0 +1,2 @@ +successfully mounted +successfully umounted diff --git a/tests/expected/libmount/context-mount-flags b/tests/expected/libmount/context-mount-flags new file mode 100644 index 00000000..fc73affb --- /dev/null +++ b/tests/expected/libmount/context-mount-flags @@ -0,0 +1,3 @@ +successfully mounted +ro,nosuid,noexec +successfully umounted diff --git a/tests/expected/libmount/context-umount-by-devname b/tests/expected/libmount/context-umount-by-devname new file mode 100644 index 00000000..319236f1 --- /dev/null +++ b/tests/expected/libmount/context-umount-by-devname @@ -0,0 +1 @@ +successfully umounted diff --git a/tests/expected/libmount/context-umount-by-mountpoint b/tests/expected/libmount/context-umount-by-mountpoint new file mode 100644 index 00000000..319236f1 --- /dev/null +++ b/tests/expected/libmount/context-umount-by-mountpoint @@ -0,0 +1 @@ +successfully umounted diff --git a/tests/functions.sh b/tests/functions.sh index 7c74b016..70bd45a2 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -86,9 +86,10 @@ function ts_init_core_env { function ts_init_core_subtest_env { TS_NS="$TS_COMPONENT/$TS_TESTNAME-$TS_SUBNAME" TS_OUTPUT="$TS_OUTDIR/$TS_TESTNAME-$TS_SUBNAME" + > $TS_OUTPUT TS_DIFF="$TS_DIFFDIR/$TS_TESTNAME-$TS_SUBNAME" TS_EXPECTED="$TS_TOPDIR/expected/$TS_NS" - TS_MOUNTPOINT="$TS_OUTDIR/${TS_TESTNAME-$TS_SUBNAME}-mnt" + TS_MOUNTPOINT="$TS_OUTDIR/${TS_TESTNAME}-${TS_SUBNAME}-mnt" } function ts_init_env { @@ -191,7 +192,7 @@ function ts_init_suid { function ts_gen_diff { local res=0 - if [ -s $TS_OUTPUT ]; then + if [ -s "$TS_OUTPUT" ]; then diff -u $TS_EXPECTED $TS_OUTPUT > $TS_DIFF [ -s $TS_DIFF ] && res=1 else @@ -203,7 +204,7 @@ function ts_gen_diff { function ts_finalize_subtest { local res=0 - if [ -s $TS_EXPECTED ]; then + if [ -s "$TS_EXPECTED" ]; then ts_gen_diff if [ $? -eq 1 ]; then ts_failed_subtest "$1" diff --git a/tests/ts/libmount/context b/tests/ts/libmount/context new file mode 100755 index 00000000..66e2dab0 --- /dev/null +++ b/tests/ts/libmount/context @@ -0,0 +1,111 @@ +#!/bin/bash + +# Copyright (C) 2010 Karel Zak + +TS_TOPDIR="$(dirname $0)/../.." +TS_DESC="context" + +. $TS_TOPDIR/functions.sh +ts_init "$*" +ts_skip_nonroot + +TESTPROG="$TS_HELPER_LIBMOUNT_CONTEXT" +LABEL=libmount-test +UUID=$(uuidgen) +MOUNTPOINT="$TS_MOUNTPOINT" + +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=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 found device" + +DEVICE="/dev/${DEVNAME}" + +ts_log "Create partitions" +$TS_CMD_FDISK ${DEVICE} >> /dev/null 2>&1 < /dev/null + +ts_log "Do tests..." + +export LIBMOUNT_MTAB=$TS_OUTPUT.mtab +> $LIBMOUNT_MTAB + + +ts_init_subtest "mount-by-devname" +mkdir -p $MOUNTPOINT &> /dev/null +$TESTPROG --mount $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>&1 +grep -q $DEVICE $LIBMOUNT_MTAB || \ + echo "(by device) cannot found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1 +ts_finalize_subtest + + +ts_init_subtest "umount-by-devname" +$TESTPROG --umount $DEVICE >> $TS_OUTPUT 2>&1 +grep -q $DEVICE $LIBMOUNT_MTAB && + echo "umount (device) failed: found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1 +ts_finalize_subtest + + +ts_init_subtest "mount-by-label" +mkdir -p $MOUNTPOINT &> /dev/null +$TESTPROG --mount LABEL="$LABEL" $MOUNTPOINT >> $TS_OUTPUT 2>&1 +grep -q $DEVICE $LIBMOUNT_MTAB || \ + echo "(by label) cannot found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1 +ts_finalize_subtest + + +ts_init_subtest "umount-by-mountpoint" +$TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1 +grep -q $DEVICE $LIBMOUNT_MTAB && \ + echo "umount (mountpoint) failed: found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1 +ts_finalize_subtest + + +ts_init_subtest "mount-by-uuid" +mkdir -p $MOUNTPOINT &> /dev/null +$TESTPROG --mount UUID="$UUID" $MOUNTPOINT >> $TS_OUTPUT 2>&1 +grep -q $DEVICE $LIBMOUNT_MTAB || \ + echo "(by uuid) cannot found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1 +$TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1 +grep -q $DEVICE $LIBMOUNT_MTAB && + echo "umount failed: found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1 +ts_finalize_subtest + + +ts_init_subtest "mount-flags" +mkdir -p $MOUNTPOINT &> /dev/null +$TESTPROG --mount -o ro,noexec,nosuid,strictatime $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>&1 +$TS_CMD_FINDMNT --kernel $MOUNTPOINT -o VFS-OPTIONS -n >> $TS_OUTPUT 2>&1 +grep -q $DEVICE $LIBMOUNT_MTAB || \ + echo "cannot found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1 +$TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1 +grep -q $DEVICE $LIBMOUNT_MTAB && + echo "umount failed: found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1 +ts_finalize_subtest + + +ts_log "...done." +rmmod scsi_debug +ts_finalize diff --git a/tests/ts/libmount/mount b/tests/ts/libmount/mount deleted file mode 100755 index 75fcd0a7..00000000 --- a/tests/ts/libmount/mount +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2010 Karel Zak - -TS_TOPDIR="$(dirname $0)/../.." -TS_DESC="mount" - -. $TS_TOPDIR/functions.sh -ts_init "$*" -ts_skip_nonroot - -TESTPROG="$TS_HELPER_LIBMOUNT_CONTEXT" -LABEL=libmount-test -UUID=$(uuidgen) - -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=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 found device" - -DEVICE="/dev/${DEVNAME}" - -ts_log "Create partitions" -$TS_CMD_FDISK ${DEVICE} >> /dev/null 2>&1 < /dev/null - -ts_log "Do tests..." - -export LIBMOUNT_MTAB=$TS_OUTPUT.mtab -> $LIBMOUNT_MTAB - - -ts_init_subtest "by-devname" -mkdir -p $TS_MOUNTPOINT &> /dev/null -$TESTPROG --mount $DEVICE $TS_MOUNTPOINT &> $TS_OUTPUT -grep -q $DEVICE $LIBMOUNT_MTAB || \ - echo "(by device) cannot found $DEVICE in $LIBMOUNT_MTAB" &> $TS_OUTPUT -umount $TS_MOUNTPOINT -ts_finalize_subtest - - -ts_init_subtest "by-label" -mkdir -p $TS_MOUNTPOINT &> /dev/null -$TESTPROG --mount LABEL="$LABEL" $TS_MOUNTPOINT &> $TS_OUTPUT -grep -q $DEVICE $LIBMOUNT_MTAB || \ - echo "(by label) cannot found $DEVICE in $LIBMOUNT_MTAB" &> $TS_OUTPUT -umount $TS_MOUNTPOINT -ts_finalize_subtest - - -ts_init_subtest "by-uuid" -mkdir -p $TS_MOUNTPOINT &> /dev/null -$TESTPROG --mount UUID="$UUID" $TS_MOUNTPOINT &> $TS_OUTPUT -grep -q $DEVICE $LIBMOUNT_MTAB || \ - echo "(by uuid) cannot found $DEVICE in $LIBMOUNT_MTAB" &> $TS_OUTPUT -umount $TS_MOUNTPOINT -ts_finalize_subtest - -ts_log "...done." -rmmod scsi_debug -ts_finalize -- 2.39.5