Gitweb:
http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=882b2853...
Commit: 882b2853f1d9545f86e942e6ad5cf0160413530c
Parent: b3ca8fbbf8f1ea9120988254ccc94b2197b0d493
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Dec 14 13:11:22 2012 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Fri Dec 14 14:48:55 2012 +0000
gfs2-utils tests: Add a script to exercise the utils
Add a test script to make it easy to run gfs2 utils with various options
and check their exit codes in sequence. The script is plugged into the
test suite and is run with 'make check'.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
tests/Makefile.am | 4 ++-
tests/tool_tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 1 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 71c1e08..d8aa8f2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,6 @@
-TESTS = check_libgfs2
+TESTS_ENVIRONMENT = TOPBUILDDIR=$(top_builddir)
+TESTS = check_libgfs2 tool_tests.sh
+EXTRA_DIST = tool_tests.sh
check_PROGRAMS = check_libgfs2
check_libgfs2_SOURCES = check_meta.c \
$(top_srcdir)/gfs2/libgfs2/libgfs2.h
diff --git a/tests/tool_tests.sh b/tests/tool_tests.sh
new file mode 100755
index 0000000..791b071
--- /dev/null
+++ b/tests/tool_tests.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# This script runs gfs2 utils with various options, checking exit codes against
+# expected values. If any test fails to exit with an expected code, the exit code
+# of the whole script will be non-zero but the tests will continue to be run. The
+# sparse file which is used as the target of the tests can be configured by
+# setting the environment variables TEST_TARGET (the filename) and TEST_TARGET_SZ
+# (its apparent size in gigabytes). Defaults to "test_sparse" and 10GB.
+
+MKFS="${TOPBUILDDIR}/gfs2/mkfs/mkfs.gfs2 -qO"
+FSCK="${TOPBUILDDIR}/gfs2/fsck/fsck.gfs2 -qn"
+
+# Name of the sparse file we'll use for testing
+TEST_TARGET=${TEST_TARGET:-test_sparse}
+# Size, in GB, of the sparse file we'll create to run the tests
+TEST_TARGET_SZ=${TEST_TARGET_SZ:-10}
+[ $TEST_TARGET_SZ -gt 0 ] || { echo "Target size (in GB) must be greater than
0" >&2; exit 1; }
+# Overall success (so we can keep going if one test fails)
+TEST_RET=0
+
+fn_test()
+{
+ local expected="$1"
+ local cmd="$2"
+ echo -n "Running '$cmd' - (Exp: $expected Got: "
+ $cmd &> /dev/null;
+ local ret=$?
+ echo -n "$ret) "
+ if [ "$ret" != "$expected" ];
+ then
+ echo "FAIL"
+ TEST_RET=1
+ TEST_GRP_RET=1
+ else
+ echo "PASS"
+ fi
+}
+
+fn_rm_target()
+{
+ fn_test 0 "rm -f $TEST_TARGET"
+}
+
+fn_recreate_target()
+{
+ fn_rm_target
+ fn_test 0 "dd if=/dev/null of=$TEST_TARGET bs=1 count=0
seek=${TEST_TARGET_SZ}G"
+}
+
+
+# Tests start here
+fn_recreate_target
+fn_test 0 "$MKFS -p lock_nolock $TEST_TARGET"
+fn_test 0 "$MKFS -p lock_dlm -t foo:bar $TEST_TARGET"
+fn_test 255 "$MKFS -p badprotocol $TEST_TARGET"
+fn_test 0 "$FSCK $TEST_TARGET"
+
+# Tests end here
+
+# Clean up
+fn_test 0 "rm -f $TEST_TARGET"
+exit $TEST_RET