From e83446da1a3f626920d5e65d4f78651581765b61 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 4 Jan 2007 14:23:48 +0100 Subject: [PATCH] tests: add basic infrastructure for regression tests 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 --- Makefile.am | 3 ++- configure.ac | 2 ++ tests/Makefile.am | 10 +++++++++ tests/README | 16 +++++++++++++ tests/commands.sh.in | 8 +++++++ tests/expected/ts-mount-paths | 7 ++++++ tests/functions.sh | 42 +++++++++++++++++++++++++++++++++++ tests/run.sh | 25 +++++++++++++++++++++ tests/ts-mount-paths | 14 ++++++++++++ 9 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 tests/Makefile.am create mode 100644 tests/README create mode 100644 tests/commands.sh.in create mode 100644 tests/expected/ts-mount-paths create mode 100644 tests/functions.sh create mode 100755 tests/run.sh create mode 100755 tests/ts-mount-paths diff --git a/Makefile.am b/Makefile.am index 5f69f448..b5293e2f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,7 +13,8 @@ SUBDIRS = lib \ po \ schedutils \ sys-utils \ - text-utils + text-utils \ + tests ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 5a0d44ea..b4cbf2ef 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 00000000..65cd57a5 --- /dev/null +++ b/tests/Makefile.am @@ -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 index 00000000..bcade3d7 --- /dev/null +++ b/tests/README @@ -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--.sh + diff --git a/tests/commands.sh.in b/tests/commands.sh.in new file mode 100644 index 00000000..ecdb9b94 --- /dev/null +++ b/tests/commands.sh.in @@ -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 index 00000000..d6f798ae --- /dev/null +++ b/tests/expected/ts-mount-paths @@ -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 index 00000000..64392e4d --- /dev/null +++ b/tests/functions.sh @@ -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 index 00000000..b4ca51b5 --- /dev/null +++ b/tests/run.sh @@ -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 index 00000000..137aade3 --- /dev/null +++ b/tests/ts-mount-paths @@ -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 + -- 2.39.5