]> err.no Git - util-linux/commitdiff
tests: add basic infrastructure for regression tests
authorKarel Zak <kzak@redhat.com>
Thu, 4 Jan 2007 13:23:48 +0000 (14:23 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 4 Jan 2007 13:23:48 +0000 (14:23 +0100)
The patch adds tests/ directory with simple regression tests infrastructure.

Also, it adds the "ts-mount-paths" test that testing if all defined paths
(fstab, mtab, locks) are still same.

Signed-off-by: Karel Zak <kzak@redhat.com>
Makefile.am
configure.ac
tests/Makefile.am [new file with mode: 0644]
tests/README [new file with mode: 0644]
tests/commands.sh.in [new file with mode: 0644]
tests/expected/ts-mount-paths [new file with mode: 0644]
tests/functions.sh [new file with mode: 0644]
tests/run.sh [new file with mode: 0755]
tests/ts-mount-paths [new file with mode: 0755]

index 5f69f4488beecfdbdc4f15d0edec053565787757..b5293e2f9269300b6b820f0bd9fafa8f345daa0f 100644 (file)
@@ -13,7 +13,8 @@ SUBDIRS = lib \
        po \
        schedutils \
        sys-utils \
-       text-utils
+       text-utils \
+       tests
 
 ACLOCAL_AMFLAGS = -I m4
 
index 5a0d44eaa5f65888edf67a7812eae4e9a8d75c5f..b4cbf2ef4e85cf4297ece3d599ea5f968be42450 100644 (file)
@@ -408,6 +408,8 @@ po/Makefile.in
 schedutils/Makefile
 sys-utils/Makefile
 text-utils/Makefile
+tests/Makefile
+tests/commands.sh
 ])
 
 AC_OUTPUT
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..65cd57a
--- /dev/null
@@ -0,0 +1,10 @@
+include $(top_srcdir)/config/include-Makefile.am
+
+EXTRA_DIST =   commands.sh.in \
+               functions.sh \
+               ts-mount-paths \
+               expected/ts-mount-paths
+
+distclean-local:
+       rm -rf output diff
+
diff --git a/tests/README b/tests/README
new file mode 100644 (file)
index 0000000..bcade3d
--- /dev/null
@@ -0,0 +1,16 @@
+
+ util-linux regression tests
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ It's expected that for each invasive change or important bugfix you will
+ include a test to your patch.
+
+
+ Run all tests:
+
+       ./run.sh
+
+ Run one tests:
+
+       ./ts-<component_name>-<test_name>.sh
+
diff --git a/tests/commands.sh.in b/tests/commands.sh.in
new file mode 100644 (file)
index 0000000..ecdb9b9
--- /dev/null
@@ -0,0 +1,8 @@
+TOPDIR=@top_srcdir@
+TS_TOPDIR=$TOPDIR/tests
+
+# paths to commands
+TS_CMD_MOUNT=${TS_CMD_MOUNT:-"$TOPDIR/mount/mount"}
+TS_CMD_UMOUNT=${TS_CMD_MOUNT:-"$TOPDIR/mount/umount"}
+TS_CMD_SWAPON=${TS_CMD_MOUNT:-"$TOPDIR/mount/swapon"}
+TS_CMD_SWAPOFF=${TS_CMD_MOUNT:-"$TOPDIR/mount/swapoff"}
diff --git a/tests/expected/ts-mount-paths b/tests/expected/ts-mount-paths
new file mode 100644 (file)
index 0000000..d6f798a
--- /dev/null
@@ -0,0 +1,7 @@
+DEBUG: fstab path: "/etc/fstab"
+DEBUG: lock path:  "/etc/mtab~"
+DEBUG: temp path:  "/etc/mtab.tmp"
+DEBUG: spec:  "/dev/dummy"
+DEBUG: node:  "/mnt"
+DEBUG: types: "(null)"
+DEBUG: opts:  "(null)"
diff --git a/tests/functions.sh b/tests/functions.sh
new file mode 100644 (file)
index 0000000..64392e4
--- /dev/null
@@ -0,0 +1,42 @@
+
+TS_OUTDIR="$TS_TOPDIR/output"
+TS_DIFFDIR="$TS_TOPDIR/diff"
+TS_EXPECTEDDIR="$TS_TOPDIR/expected"
+
+function ts_init {
+       TS_NAME=$(basename $0)
+       if [ ! -d $TS_OUTDIR ]; then
+               mkdir -p $TS_OUTDIR
+       fi
+       if [ ! -d $TS_DIFFDIR ]; then
+               mkdir -p $TS_DIFFDIR
+       fi
+       TS_OUTPUT="$TS_OUTDIR/$TS_NAME"
+       TS_DIFF="$TS_DIFFDIR/$TS_NAME"
+       TS_EXPECTED="$TS_EXPECTEDDIR/$TS_NAME"
+
+       printf "%15s: %-25s ..." "$TS_COMPONENT" "$TS_DESC"
+}
+
+function ts_finalize {
+       local res=0
+
+       if [ -s $TS_EXPECTED ]; then
+               if [ -s $TS_OUTPUT ]; then
+                       diff -u $TS_EXPECTED $TS_OUTPUT > $TS_DIFF
+                       if [ -s $TS_DIFF ]; then
+                               res=1
+                       fi
+               else
+                       res=0
+               fi
+       fi
+       if [ $res -eq 0 ]; then
+               echo " OK"
+               exit 0
+       else
+               echo " FAILED ($TS_NAME)"
+               exit 1
+       fi
+}
+
diff --git a/tests/run.sh b/tests/run.sh
new file mode 100755 (executable)
index 0000000..b4ca51b
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+. commands.sh
+
+echo
+echo "------------------ Utils-linux-ng regression tests ------------------"
+echo
+
+res=0
+count=0
+for ts in `ls ts-*`; do
+       $TS_TOPDIR/$ts
+       res=$(( $res + $? ))
+       count=$(( $count + 1 ))
+done
+
+echo
+echo "---------------------------------------------------------------------"
+if [ $res -eq 0 ]; then
+       echo "  All $count tests PASSED"
+else
+       echo "  $res tests of $count FAILED"
+fi
+echo "---------------------------------------------------------------------"
+
diff --git a/tests/ts-mount-paths b/tests/ts-mount-paths
new file mode 100755 (executable)
index 0000000..137aade
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+. commands.sh
+. functions.sh
+
+TS_COMPONENT="mount"
+TS_DESC="basic paths"
+
+ts_init
+
+$TS_CMD_MOUNT -n -f --debug=2 /dev/dummy /mnt &> $TS_OUTPUT
+
+ts_finalize
+