gfs2-utils: master - gfs2-utils tests: Switch to autotest

Andrew Price andyp at fedoraproject.org
Thu Aug 22 13:21:08 UTC 2013


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=e0ddfd458b736f4cf9738fefba411edc29a3a6a9
Commit:        e0ddfd458b736f4cf9738fefba411edc29a3a6a9
Parent:        535739c13a88a17f7ccf2b3623904b8f7f3fd208
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Mon Aug 19 12:59:58 2013 +0100
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Thu Aug 22 14:16:55 2013 +0100

gfs2-utils tests: Switch to autotest

Replaces the custom tool_tests.sh test harness with the Autotest
framework provided by Autoconf. See doc/README.tests for details.

This is just a straight rework of the existing tests as Autotest test
groups.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 .gitignore          |    8 ++++-
 configure.ac        |    2 +
 doc/README.tests    |   42 +++++++++++++++++++++++
 tests/Makefile.am   |   71 ++++++++++++++++++++++++++++++++------
 tests/atlocal.in    |    7 ++++
 tests/libgfs2.at    |    5 +++
 tests/mkfs.at       |   64 ++++++++++++++++++++++++++++++++++
 tests/testsuite.at  |   16 +++++++++
 tests/tool_tests.sh |   94 ---------------------------------------------------
 9 files changed, 203 insertions(+), 106 deletions(-)

diff --git a/.gitignore b/.gitignore
index 26d89d0..ae72f2b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,7 +44,13 @@ gfs2/tune/tunegfs2
 test-driver
 tests/check_libgfs2
 tests/testvol
-tests/tests.log
+tests/testsuite.log
+tests/testsuite.dir
+tests/testsuite.trs
+tests/atconfig
+tests/atlocal
+tests/package.m4
+tests/testsuite
 ABOUT-NLS
 po/Makevars.template
 po/POTFILES
diff --git a/configure.ac b/configure.ac
index 911dd88..628d85e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -203,6 +203,7 @@ CPPFLAGS="-I\$(top_builddir)/make -I\$(top_srcdir)/make \
 	  -I. $ENV_CPPFLAGS"
 LDFLAGS="$ENV_LDFLAGS"
 
+AC_CONFIG_TESTDIR([tests], [gfs2/libgfs2:gfs2/mkfs:gfs2/fsck:gfs2/edit:gfs2/convert:gfs2/tune:tests])
 AC_CONFIG_FILES([Makefile
 		 gfs2/Makefile
 		 gfs2/include/Makefile
@@ -216,6 +217,7 @@ AC_CONFIG_FILES([Makefile
 		 gfs2/scripts/Makefile
 		 doc/Makefile
 		 tests/Makefile
+		 tests/atlocal
 		 po/Makefile.in
 		 ])
 
diff --git a/doc/README.tests b/doc/README.tests
new file mode 100644
index 0000000..fa35803
--- /dev/null
+++ b/doc/README.tests
@@ -0,0 +1,42 @@
+Working with the gfs2-utils test suite
+--------------------------------------
+
+The test suite in the tests directory of the gfs2-utils source tree is based on
+the Autotest framework provided by Autoconf. The basic idea is that the
+testsuite.at file is the main source file for the tests, written in m4 and
+generating a bourne shell script called testsuite.
+
+When run, either using 'make check' or directly from within the tests
+directory, the testsuite script sources atconfig and atlocal for configuration
+and then runs the whole testsuite or a specified set of tests (see ./testsuite
+-h for help).
+
+A number of GFS2-specific convenience macros have been defined in testsuite.at
+to make defining new tests quick and easy. Also, some variables have been
+defined in atlocal.in so that full paths to programs do not have to be included
+in each test. Configuration should be specified in atlocal.in as atconfig is
+generated by the configure script and atlocal is generated from atlocal.in at
+build time.
+
+To keep the test suite organised, the testsuite.at file sources the actual
+tests from other files, e.g. mkfs.at.
+
+A single test, specified as a test group in Autotest terms, follows the form
+
+    AT_SETUP([Test title])
+    ...test goes here...
+    AT_CLEANUP
+
+so, when adding tests, this is generally all that is required unless the tests
+do not fit into an existing category, in which case AT_BANNER can be used to
+group them, and they can be organised into a new .at file and sourced from
+testsuite.at.
+
+Since the tests can be run individually (e.g. ./testsuite 15) any new tests
+which require the dummy volume $GFS_TGT to be present should call GFS_TGT_REGEN
+before attempting to use it.
+
+Documentation for Autotest, including the AT_* macros used to define tests, can
+be found in the autoconf manual at:
+
+    http://www.gnu.org/software/autoconf/manual/index.html
diff --git a/tests/Makefile.am b/tests/Makefile.am
index af01c49..3336304 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,15 +1,64 @@
-TESTS_ENVIRONMENT	= TOPBUILDDIR=$(top_builddir)
-EXTRA_DIST		= tool_tests.sh
-CLEANFILES		= tests.log
+EXTRA_DIST = $(TESTSUITE_AT) package.m4 $(TESTSUITE) atlocal atconfig
+DISTCLEANFILES = atlocal atconfig
+CLEANFILES = testvol
 
 if BUILD_TESTS
-check_PROGRAMS		= check_libgfs2
-check_libgfs2_SOURCES	= check_meta.c \
-			  $(top_srcdir)/gfs2/libgfs2/libgfs2.h
-check_libgfs2_CFLAGS	= -I$(top_srcdir)/gfs2/libgfs2 \
-			  -I$(top_srcdir)/gfs2/include \
-			  @check_CFLAGS@
-check_libgfs2_LDADD	= $(top_builddir)/gfs2/libgfs2/libgfs2.la @check_LIBS@
+check_PROGRAMS = check_libgfs2
+
+check_libgfs2_SOURCES = \
+	check_meta.c \
+	$(top_srcdir)/gfs2/libgfs2/libgfs2.h
+
+check_libgfs2_CFLAGS = \
+	-I$(top_srcdir)/gfs2/libgfs2 \
+        -I$(top_srcdir)/gfs2/include \
+	@check_CFLAGS@
+
+check_libgfs2_LDADD = \
+	$(top_builddir)/gfs2/libgfs2/libgfs2.la \
+	@check_LIBS@
 endif
 
-TESTS			= $(check_PROGRAMS) tool_tests.sh
+# The `:;' works around a Bash 3.2 bug when the output is not writable.
+$(srcdir)/package.m4: $(top_srcdir)/configure.ac
+	:;{ \
+		echo '# Signature of the current package.' && \
+		echo 'm4_define([AT_PACKAGE_NAME],' && \
+		echo '  [$(PACKAGE_NAME)])' && \
+		echo 'm4_define([AT_PACKAGE_TARNAME],' && \
+		echo '  [$(PACKAGE_TARNAME)])' && \
+		echo 'm4_define([AT_PACKAGE_VERSION],' && \
+		echo '  [$(PACKAGE_VERSION)])' && \
+		echo 'm4_define([AT_PACKAGE_STRING],' && \
+		echo '  [$(PACKAGE_STRING)])' && \
+		echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \
+		echo '  [$(PACKAGE_BUGREPORT)])'; \
+		echo 'm4_define([AT_PACKAGE_URL],' && \
+		echo '  [$(PACKAGE_URL)])'; \
+	} >'$(srcdir)/package.m4'
+
+TESTSUITE_AT = \
+	testsuite.at \
+	mkfs.at \
+	libgfs2.at
+
+TESTSUITE = $(srcdir)/testsuite
+
+check-local: atconfig atlocal $(TESTSUITE)
+	$(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
+
+installcheck-local: atconfig atlocal $(TESTSUITE)
+	$(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(sbindir):tests' $(TESTSUITEFLAGS)
+
+clean-local:
+	test ! -f '$(TESTSUITE)' || $(SHELL) '$(TESTSUITE)' --clean
+
+atconfig: $(top_builddir)/config.status
+	cd $(top_builddir) && ./config.status tests/$@
+
+AUTOM4TE = $(SHELL) $(top_srcdir)/missing --run autom4te
+AUTOTEST = $(AUTOM4TE) --language=autotest
+
+$(TESTSUITE): $(TESTSUITE_AT) package.m4
+	$(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at
+	mv $@.tmp $@
diff --git a/tests/atlocal.in b/tests/atlocal.in
new file mode 100644
index 0000000..660c87a
--- /dev/null
+++ b/tests/atlocal.in
@@ -0,0 +1,7 @@
+GFS_TGT="$abs_builddir/testvol"
+GFS_TGT_SZ=10
+
+gfs_max_blocks()
+{
+	printf $((GFS_TGT_SZ*1073741824/$1))
+}
diff --git a/tests/libgfs2.at b/tests/libgfs2.at
new file mode 100644
index 0000000..a6b478a
--- /dev/null
+++ b/tests/libgfs2.at
@@ -0,0 +1,5 @@
+AT_BANNER([libgfs2 unit tests])
+
+AT_SETUP([Metadata check])
+AT_CHECK([check_libgfs2], 0, [ignore], [ignore])
+AT_CLEANUP
diff --git a/tests/mkfs.at b/tests/mkfs.at
new file mode 100644
index 0000000..aff6a0d
--- /dev/null
+++ b/tests/mkfs.at
@@ -0,0 +1,64 @@
+AT_TESTED([mkfs.gfs2])
+AT_BANNER([mkfs.gfs2 tests])
+
+AT_SETUP([Locking protocol validation])
+AT_CHECK([mkfs.gfs2 -O -p badprotocol $GFS_TGT], 255, [ignore], [ignore])
+AT_CLEANUP
+
+AT_SETUP([Resource group size validation])
+AT_CHECK([mkfs.gfs2 -O -p lock_nolock -r 31 $GFS_TGT], 255, [ignore], [ignore])
+AT_CHECK([mkfs.gfs2 -O -p lock_nolock -r 2049 $GFS_TGT], 255, [ignore], [ignore])
+AT_CLEANUP
+
+AT_SETUP([Journal size validation])
+AT_CHECK([mkfs.gfs2 -O -p lock_nolock -J 7 $GFS_TGT], 255, [ignore], [ignore])
+AT_CHECK([mkfs.gfs2 -O -p lock_nolock -J 1025 $GFS_TGT], 255, [ignore], [ignore])
+AT_CLEANUP
+
+AT_SETUP([Block count validation])
+GFS_TGT_REGEN
+AT_CHECK([mkfs.gfs2 -O -p lock_nolock -b 512 $GFS_TGT $(($(gfs_max_blocks 512)+1))], 255, [ignore], [ignore])
+AT_CHECK([mkfs.gfs2 -O -p lock_nolock -b 4096 $GFS_TGT $(($(gfs_max_blocks 4096)+1))], 255, [ignore], [ignore])
+AT_CLEANUP
+
+AT_SETUP([Quota change file size validation])
+AT_CHECK([mkfs.gfs2 -O -p lock_nolock -c 0 $GFS_TGT], 255, [ignore], [ignore])
+AT_CHECK([mkfs.gfs2 -O -p lock_nolock -c 65 $GFS_TGT], 255, [ignore], [ignore])
+AT_CLEANUP
+
+AT_SETUP([Locking protocols])
+GFS_FSCK_CHECK([mkfs.gfs2 -O -p lock_nolock $GFS_TGT])
+GFS_FSCK_CHECK([mkfs.gfs2 -O -p lock_dlm -t foo:bar $GFS_TGT])
+AT_CLEANUP
+
+AT_SETUP([Max. blocks, min. block size])
+GFS_FSCK_CHECK([mkfs.gfs2 -O -p lock_nolock -b 512 $GFS_TGT $(gfs_max_blocks 512)])
+AT_CLEANUP
+
+AT_SETUP([Max. blocks, max. block size])
+GFS_FSCK_CHECK([mkfs.gfs2 -O -p lock_nolock -b 4096 $GFS_TGT $(util_max_blocks 4096)])
+AT_CLEANUP
+
+AT_SETUP([Max. resource group size])
+GFS_FSCK_CHECK([mkfs.gfs2 -O -p lock_nolock -r 2048 $GFS_TGT])
+AT_CLEANUP
+
+AT_SETUP([Min. resource group size])
+GFS_FSCK_CHECK([mkfs.gfs2 -O -p lock_nolock -r 32 $GFS_TGT])
+AT_CLEANUP
+
+AT_SETUP([Max. journal size])
+GFS_FSCK_CHECK([mkfs.gfs2 -O -p lock_nolock -J 1024 $GFS_TGT])
+AT_CLEANUP
+
+AT_SETUP([Min. journal size])
+GFS_FSCK_CHECK([mkfs.gfs2 -O -p lock_nolock -J 8 $GFS_TGT])
+AT_CLEANUP
+
+AT_SETUP([Max. quota change file size])
+GFS_FSCK_CHECK([mkfs.gfs2 -O -p lock_nolock -c 64 $GFS_TGT])
+AT_CLEANUP
+
+AT_SETUP([Min. quota change file size])
+GFS_FSCK_CHECK([mkfs.gfs2 -O -p lock_nolock -c 1 $GFS_TGT])
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
new file mode 100644
index 0000000..2c74985
--- /dev/null
+++ b/tests/testsuite.at
@@ -0,0 +1,16 @@
+# Regenerate the sparse file used for testing and skip the test if it fails
+m4_define([GFS_TGT_REGEN],
+[AT_CHECK([rm -f $GFS_TGT && truncate -s ${GFS_TGT_SZ}G ${GFS_TGT}], [ignore], [ignore], [ignore])
+AT_SKIP_IF([test ! -f ${GFS_TGT}])])
+
+# Regenerate, check, fsck is used a lot so combine it into one macro
+m4_define([GFS_FSCK_CHECK],
+[GFS_TGT_REGEN
+AT_CHECK($1, 0, [ignore], [ignore])
+AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])])
+
+AT_INIT([])
+AT_COLOR_TESTS
+
+m4_include([mkfs.at])
+m4_include([libgfs2.at])
diff --git a/tests/tool_tests.sh b/tests/tool_tests.sh
deleted file mode 100755
index 7b9a5c3..0000000
--- a/tests/tool_tests.sh
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/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 "testvol" and 10GB.
-
-MKFS="${TOPBUILDDIR}/gfs2/mkfs/mkfs.gfs2 -O"
-FSCK="${TOPBUILDDIR}/gfs2/fsck/fsck.gfs2 -n"
-
-# Name of the sparse file we'll use for testing
-TEST_TARGET=${TEST_TARGET:-testvol}
-# Log of test output
-TEST_LOG=${TEST_LOG:-tests.log}
-truncate -cs0 "${TEST_LOG}"
-# 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 "** Test '$cmd'" | tee -a "${TEST_LOG}"
-	$cmd &>> "${TEST_LOG}";
-	local ret=$?
-	echo -n " (exp: $expected got: $ret) " | tee -a "${TEST_LOG}"
-	if [ "$ret" != "$expected" ];
-	then
-		echo "FAIL" | tee -a "${TEST_LOG}"
-		TEST_RET=1
-		TEST_GRP_RET=1
-	else
-		echo "PASS" | tee -a "${TEST_LOG}"
-	fi
-}
-
-fn_rm_target()
-{
-	fn_test 0 "rm -f $TEST_TARGET"
-}
-
-fn_recreate_target()
-{
-	fn_rm_target
-	fn_test 0 "truncate -s ${TEST_TARGET_SZ}G ${TEST_TARGET}"
-}
-
-util_max_blocks()
-{
-	printf $((TEST_TARGET_SZ*1073741824/$1))
-}
-
-# 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 0 "$FSCK $TEST_TARGET"
-fn_test 255 "$MKFS -p badprotocol $TEST_TARGET"
-fn_test 255 "$MKFS -p lock_nolock -r 31 $TEST_TARGET"
-fn_test 255 "$MKFS -p lock_nolock -r 2049 $TEST_TARGET"
-fn_test 0 "$MKFS -p lock_nolock -r 32 $TEST_TARGET"
-fn_test 0 "$FSCK $TEST_TARGET"
-fn_test 0 "$MKFS -p lock_nolock -r 2048 $TEST_TARGET"
-fn_test 0 "$FSCK $TEST_TARGET"
-fn_test 255 "$MKFS -p lock_nolock -b 512 $TEST_TARGET $(($(util_max_blocks 512)+1))"
-fn_test 255 "$MKFS -p lock_nolock -b 4096 $TEST_TARGET $(($(util_max_blocks 4096)+1))"
-fn_test 0 "$MKFS -p lock_nolock -b 512 $TEST_TARGET $(util_max_blocks 512)"
-fn_test 0 "$FSCK $TEST_TARGET"
-fn_test 0 "$MKFS -p lock_nolock -b 4096 $TEST_TARGET $(util_max_blocks 4096)"
-fn_test 0 "$FSCK $TEST_TARGET"
-fn_test 255 "$MKFS -p lock_nolock -J 7 $TEST_TARGET"
-fn_test 255 "$MKFS -p lock_nolock -J 1025 $TEST_TARGET"
-fn_test 0 "$MKFS -p lock_nolock -J 1024 $TEST_TARGET"
-fn_test 0 "$FSCK $TEST_TARGET"
-fn_test 0 "$MKFS -p lock_nolock -J 8 $TEST_TARGET"
-fn_test 0 "$FSCK $TEST_TARGET"
-fn_test 255 "$MKFS -p lock_nolock -c 0 $TEST_TARGET"
-fn_test 255 "$MKFS -p lock_nolock -c 65 $TEST_TARGET"
-fn_test 0 "$MKFS -p lock_nolock -c 1 $TEST_TARGET"
-fn_test 0 "$FSCK $TEST_TARGET"
-fn_test 0 "$MKFS -p lock_nolock -c 64 $TEST_TARGET"
-fn_test 0 "$FSCK $TEST_TARGET"
-
-# Tests end here
-
-# Only remove the test file on success
-[ "$TEST_RET" = "0" ] && fn_test 0 "rm -f $TEST_TARGET"
-echo "Tool test output written to ${TEST_LOG}"
-exit $TEST_RET


More information about the cluster-commits mailing list