Blame SOURCES/bz1000066-gfs2_utils_tests_Switch_to_autotest.patch

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