From: Karel Zak Date: Fri, 15 Apr 2016 12:10:23 +0000 (+0200) Subject: tests: make tests more portable due to mtab X-Git-Tag: v2.29-rc1~289 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=edeb6223fed8f5e5b4088d34007c3860c928906a;p=thirdparty%2Futil-linux.git tests: make tests more portable due to mtab Signed-off-by: Karel Zak --- diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 45276a0579..044e15415c 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -1100,7 +1100,9 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename, if (!is_mountinfo(tb)) return 0; +#ifdef USE_LIBMOUNT_SUPPORT_MTAB read_utab: +#endif DBG(TAB, ul_debugobj(tb, "mtab parse: #2 read utab")); if (mnt_table_get_nents(tb) == 0) diff --git a/tests/functions.sh b/tests/functions.sh index fe7ce6d7b0..19e8a46b8b 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -719,3 +719,13 @@ function ts_init_socket_to_file { ts_skip "socat socket stopped listening" fi } + +function ts_has_mtab_support { + grep -q '#define USE_LIBMOUNT_SUPPORT_MTAB' ${top_builddir}/config.h + if [ $? == 0 ]; then + echo "yes" + else + echo "no" + fi +} + diff --git a/tests/ts/libmount/context b/tests/ts/libmount/context index 2566ccb538..bcb9534e8d 100755 --- a/tests/ts/libmount/context +++ b/tests/ts/libmount/context @@ -36,8 +36,8 @@ ts_scsi_debug_init dev_size_mb=100 DEVNAME=$(basename $TS_DEVICE) MOUNTINFO_ONLY=yes -grep -q '#define USE_LIBMOUNT_SUPPORT_MTAB' ${top_builddir}/config.h -if [ $? == 0 ]; then +has_mtab=$( ts_has_mtab_support ) +if [ "$has_mtab" == "yes" ]; then MOUNTINFO_ONLY=no fi diff --git a/tests/ts/libmount/context-py b/tests/ts/libmount/context-py index 5188309be4..66b2eec52a 100755 --- a/tests/ts/libmount/context-py +++ b/tests/ts/libmount/context-py @@ -38,8 +38,8 @@ ts_scsi_debug_init dev_size_mb=100 DEVNAME=$(basename $TS_DEVICE) MOUNTINFO_ONLY=yes -grep -q '#define USE_LIBMOUNT_SUPPORT_MTAB' ${top_builddir}/config.h -if [ $? == 0 ]; then +has_mtab=$( ts_has_mtab_support ) +if [ "$has_mtab" == "yes" ]; then MOUNTINFO_ONLY=no fi diff --git a/tests/ts/libmount/update b/tests/ts/libmount/update index 89279ba262..1db16d99fe 100755 --- a/tests/ts/libmount/update +++ b/tests/ts/libmount/update @@ -21,41 +21,45 @@ TESTPROG="$TS_HELPER_LIBMOUNT_UPDATE" # # - all this test uses global $TS_OUTPUT.{mtab,mountinfo} - -# -# Traditional /etc/mtab -# export LIBMOUNT_MTAB=$TS_OUTPUT.mtab rm -f $LIBMOUNT_MTAB > $LIBMOUNT_MTAB -ts_init_subtest "mtab-mount" -ts_valgrind $TESTPROG --add /dev/sda1 /mnt/foo ext3 "rw,bbb,ccc,fff=FFF,ddd,noexec" -ts_valgrind $TESTPROG --add /dev/sdb1 /mnt/bar ext3 "gg=G,ffff=f,ro,noatime" -ts_valgrind $TESTPROG --add /dev/sda2 /mnt/bar ext3 "rw,noatime" -ts_valgrind $TESTPROG --add /dev/sda1 /mnt/gogo ext3 "rw,noatime,nosuid" -ts_valgrind $TESTPROG --add none /proc proc defaults -cp $LIBMOUNT_MTAB $TS_OUTPUT # save the mtab aside -ts_finalize_subtest # checks the mtab - -ts_init_subtest "mtab-move" -ts_valgrind $TESTPROG --move /mnt/foo /mnt/newfoo -ts_valgrind $TESTPROG --move /mnt/bar /mnt/newbar -cp $LIBMOUNT_MTAB $TS_OUTPUT # save the mtab aside -ts_finalize_subtest # checks the mtab - -ts_init_subtest "mtab-remount" -ts_valgrind $TESTPROG --remount /mnt/newfoo "ro,noatime" -ts_valgrind $TESTPROG --remount /mnt/bar "rw,atime,nosuid" -cp $LIBMOUNT_MTAB $TS_OUTPUT # save the mtab aside -ts_finalize_subtest # checks the mtab -ts_init_subtest "mtab-umount" -ts_valgrind $TESTPROG --remove /mnt/bar -ts_valgrind $TESTPROG --remove /mnt/gogo -ts_valgrind $TESTPROG --remove /proc -cp $LIBMOUNT_MTAB $TS_OUTPUT # save the mtab aside -ts_finalize_subtest # checks the mtab +# +# Traditional /etc/mtab +# +has_mtab=$( ts_has_mtab_support ) +if [ "$has_mtab" == "yes" ]; then + + ts_init_subtest "mtab-mount" + ts_valgrind $TESTPROG --add /dev/sda1 /mnt/foo ext3 "rw,bbb,ccc,fff=FFF,ddd,noexec" + ts_valgrind $TESTPROG --add /dev/sdb1 /mnt/bar ext3 "gg=G,ffff=f,ro,noatime" + ts_valgrind $TESTPROG --add /dev/sda2 /mnt/bar ext3 "rw,noatime" + ts_valgrind $TESTPROG --add /dev/sda1 /mnt/gogo ext3 "rw,noatime,nosuid" + ts_valgrind $TESTPROG --add none /proc proc defaults + cp $LIBMOUNT_MTAB $TS_OUTPUT # save the mtab aside + ts_finalize_subtest # checks the mtab + + ts_init_subtest "mtab-move" + ts_valgrind $TESTPROG --move /mnt/foo /mnt/newfoo + ts_valgrind $TESTPROG --move /mnt/bar /mnt/newbar + cp $LIBMOUNT_MTAB $TS_OUTPUT # save the mtab aside + ts_finalize_subtest # checks the mtab + + ts_init_subtest "mtab-remount" + ts_valgrind $TESTPROG --remount /mnt/newfoo "ro,noatime" + ts_valgrind $TESTPROG --remount /mnt/bar "rw,atime,nosuid" + cp $LIBMOUNT_MTAB $TS_OUTPUT # save the mtab aside + ts_finalize_subtest # checks the mtab + + ts_init_subtest "mtab-umount" + ts_valgrind $TESTPROG --remove /mnt/bar + ts_valgrind $TESTPROG --remove /mnt/gogo + ts_valgrind $TESTPROG --remove /proc + cp $LIBMOUNT_MTAB $TS_OUTPUT # save the mtab aside + ts_finalize_subtest # checks the mtab +fi # # utab diff --git a/tests/ts/mount/devname b/tests/ts/mount/devname index caa79f7bbc..65a1ba2176 100755 --- a/tests/ts/mount/devname +++ b/tests/ts/mount/devname @@ -32,6 +32,12 @@ ts_check_prog "mkfs.ext3" ts_device_init DEVICE=$TS_LODEV +MTAB_FILE="/proc/mounts" +has_mtab=$( ts_has_mtab_support ) +if [ "$has_mtab" == "yes" ]; then + MTAB_FILE="/etc/mtab" +fi + mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" ts_device_has "TYPE" "ext3" $DEVICE || ts_die "Cannot find ext3 on $DEVICE" @@ -42,13 +48,13 @@ $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1 ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts" -grep -q $DEVICE /etc/mtab || - echo "mount failed: cannot find $DEVICE in mtab" >> $TS_OUTPUT 2>&1 +grep -q $DEVICE $MTAB_FILE || + echo "mount failed: cannot find $DEVICE in $MTAB_FILE" >> $TS_OUTPUT 2>&1 $TS_CMD_UMOUNT $DEVICE || ts_die "Cannot umount $DEVICE" -grep -q $DEVICE /etc/mtab && - echo "umount failed: found $DEVICE in mtab" >> $TS_OUTPUT 2>&1 +grep -q $DEVICE $MTAB_FILE && + echo "umount failed: found $DEVICE in $MTAB_FILE" >> $TS_OUTPUT 2>&1 ts_log "Success" ts_finalize diff --git a/tests/ts/mount/remount b/tests/ts/mount/remount index 7176927529..38db9bf9f3 100755 --- a/tests/ts/mount/remount +++ b/tests/ts/mount/remount @@ -34,14 +34,20 @@ ts_check_prog "mkfs.ext2" ts_device_init DEVICE=$TS_LODEV +MTAB_FILE="/proc/mounts" +has_mtab=$( ts_has_mtab_support ) +if [ "$has_mtab" == "yes" ]; then + MTAB_FILE="/etc/mtab" +fi + mkfs.ext2 $DEVICE &> /dev/null || ts_die "Cannot make ext2 on $DEVICE" # mount read-write $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT || ts_die "Cannot mount $TS_MOUNTPOINT" # check the mount -egrep -q "^$DEVICE $TS_MOUNTPOINT" /etc/mtab \ - || ts_die "Cannot find $TS_MOUNTPOINT in /etc/mtab" +egrep -q "^$DEVICE $TS_MOUNTPOINT" $MTAB_FILE \ + || ts_die "Cannot find $TS_MOUNTPOINT in $MTAB_FILE" # remount $TS_CMD_MOUNT -o remount,ro $TS_MOUNTPOINT \ diff --git a/tests/ts/mount/rlimit b/tests/ts/mount/rlimit index d6a64ec75f..9564d7046a 100755 --- a/tests/ts/mount/rlimit +++ b/tests/ts/mount/rlimit @@ -37,6 +37,9 @@ ts_skip_nonroot ts_check_losetup ts_check_prog "mkfs.ext3" +has_mtab=$( ts_has_mtab_support ) +[ "$has_mtab" == "yes" ] || ts_skip "mtab unsupported" + [ -L /etc/mtab ] && ts_skip "mtab is symlink" [ "$(stat --format '%s' /etc/mtab)" -gt "1024" ] || ts_skip "mtab is too small" diff --git a/tests/ts/mount/umount-alltargets b/tests/ts/mount/umount-alltargets index 59c7e03949..53073023a6 100755 --- a/tests/ts/mount/umount-alltargets +++ b/tests/ts/mount/umount-alltargets @@ -18,7 +18,10 @@ ts_check_prog "mkfs.ext2" $TS_CMD_UMOUNT --help | grep -q all-targets [ $? -eq 1 ] && ts_skip "all-targets unsupported" -[ -L /etc/mtab ] || ts_skip "regular mtab" +has_mtab=$( ts_has_mtab_support ) +if [ "$has_mtab" == "yes" ]; then + [ -L /etc/mtab ] || ts_skip "regular mtab" +fi # set global variable TS_DEVICE ts_scsi_debug_init dev_size_mb=50