gfs2-utils: Add the beginnings of a test suite
PATCH 1/1 gfs2-utils: Add the beginnings of a test suite
This adds a skeleton test suite based on the Check testing framework. The tests are only enabled when the check(-devel) package is present and the suite is run with `make check'.
The Check framework <http://check.sourceforge.net/> is very straightforward and conceptually consists of test suites containing test cases containing tests. To define tests we write functions which exercise our code and make assertions with functions provided by Check, such as fail_unless().
To begin with there is only one test and it simply calls lgfs2_selfcheck, which used to be called in the gfs2_edit code.
--- .gitignore | 1 + Makefile.am | 6 +++++- README.build | 41 +++++++++++++++++++++-------------------- configure.ac | 7 +++++++ gfs2/edit/hexedit.c | 3 --- tests/Makefile.am | 8 ++++++++ tests/check_meta.c | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 tests/Makefile.am create mode 100644 tests/check_meta.c
.gitignore +1 -0
@@ -40,6 +40,7 @@ gfs2/libgfs2/lexer.h gfs2/fsck/fsck.gfs2 gfs2/mkfs/mkfs.gfs2 gfs2/tune/tunegfs2 +tests/check_libgfs2 group/gfs_control/gfs_control group/gfs_controld/gfs_controld ABOUT-NLS
Makefile.am +5 -1
@@ -16,7 +16,11 @@ if BUILD_GFS_CONTROLD DIR_GROUP = group endif -SUBDIRS = po $(DIR_GROUP) gfs2 doc +if BUILD_TESTS +DIR_TESTS = tests +endif + +SUBDIRS = po $(DIR_GROUP) gfs2 doc $(DIR_TESTS) install-exec-local: $(INSTALL) -d $(DESTDIR)/$(LOGDIR)
README.build +21 -20
56 lines not on this page · raw message
configure.ac +7 -0
@@ -117,6 +117,12 @@ AS_IF([test "x$enable_gfs_controld" = "xyes"], [ PKG_CHECK_MODULES([quorum],[libquorum]) ]) +# We use the Check framework for unit tests +PKG_CHECK_MODULES([check], [check >= 0.9.8], + [have_check=yes], + [have_check=no]) +AM_CONDITIONAL([BUILD_TESTS], [test "x$have_check" = "xyes"]) + PKG_CHECK_MODULES([zlib],[zlib]) # old versions of ncurses don't ship pkg-config files
@@ -263,6 +269,7 @@ AC_CONFIG_FILES([Makefile gfs2/man/Makefile gfs2/lockcapture/Makefile doc/Makefile + tests/Makefile po/Makefile.in ])
gfs2/edit/hexedit.c +0 -3
@@ -3105,9 +3105,6 @@ int main(int argc, char *argv[]) {int i, j, fd; -if (lgfs2_selfcheck ()) -return EXIT_FAILURE ; - indirect =malloc (sizeof (struct iinfo ));if (!indirect)die ("Out of memory." );
tests/Makefile.am new file +8 -0
@@ -0,0 +1,8 @@ +TESTS = check_libgfs2 +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@
tests/check_meta.c new file +33 -0
@@ -0,0 +1,33 @@ +#include <check.h> +#include "libgfs2.h" + +// TODO: Remove this when the extern is removed from libgfs2 +void print_it (const char *label,const char *fmt,const char *fmt2, ...) {} + +START_TEST (test_lgfs2_meta) +{ +fail_unless (lgfs2_selfcheck () ==0 ); +} +END_TEST + +static Suite * libgfs2_suite(void) +{ +Suite *s =suite_create ("libgfs2" ); + +TCase *tc_meta =tcase_create ("Meta" ); +tcase_add_test (tc_meta, test_lgfs2_meta); +suite_add_tcase (s, tc_meta); + +return s; +} + +int main (void ) +{ +int failures; +Suite *s =libgfs2_suite (); +SRunner *sr =srunner_create (s); +srunner_run_all (sr,CK_NORMAL ); + failures =srunner_ntests_failed (sr); +srunner_free (sr); +return failures ?EXIT_FAILURE :EXIT_SUCCESS ; +}
Signature · 1 line
1.7.11.7
PATCH 1/1 gfs2-utils: Add the beginnings of a test suite
Hi,
Looks good to me. Would also be nice to add a test which creates a variety of different filesystems in a sparse file and then runs fsck over them to check that they are clean. That should also be quite easy to do,
Steve.
Quoted 208 lines · Andrew Price
This adds a skeleton test suite based on the Check testing framework. The tests are only enabled when the check(-devel) package is present and the suite is run with `make check'.
The Check framework <http://check.sourceforge.net/> is very straightforward and conceptually consists of test suites containing test cases containing tests. To define tests we write functions which exercise our code and make assertions with functions provided by Check, such as
fail_unless().To begin with there is only one test and it simply calls
lgfs2_selfcheck, which used to be called in thegfs2_editcode.Signed-off-by Andrew Price <[email protected]>--- .gitignore | 1 + Makefile.am | 6 +++++- README.build | 41 +++++++++++++++++++++-------------------- configure.ac | 7 +++++++ gfs2/edit/hexedit.c | 3 --- tests/Makefile.am | 8 ++++++++ tests/check_meta.c | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 tests/Makefile.am create mode 100644 tests/check_meta.c.gitignore +1
-0@@ -40,6 +40,7 @@ gfs2/libgfs2/lexer.h gfs2/fsck/fsck.gfs2 gfs2/mkfs/mkfs.gfs2 gfs2/tune/tunegfs2 +tests/check_libgfs2 group/gfs_control/gfs_control group/gfs_controld/gfs_controld ABOUT-NLSMakefile.am +5
-1@@ -16,7 +16,11 @@ if BUILD_GFS_CONTROLD DIR_GROUP = group endif -SUBDIRS = po $(DIR_GROUP) gfs2 doc +if BUILD_TESTS +DIR_TESTS = tests +endif + +SUBDIRS = po $(DIR_GROUP) gfs2 doc $(DIR_TESTS) install-exec-local: $(INSTALL) -d $(DESTDIR)/$(LOGDIR)README.build +21
-20@@ -7,35 +7,36 @@ To build this source tree, you will need: Plus the following libraries: - - ncurses (for gfs2_edit) - - clusterlib (for gfs_controld) - - libccs - - libcman - - libdlmcontrol - - liblogthread - - libfenced - - pthread (for gfs_controld) - - corosynclib (for gfs_controld) - - libquorum - - libcpg - - libcfg - - openaislib + ncurses (for gfs2_edit) + gettext + bison + flex + zlib + check (optional, enables the test suite) By default gfs_controld is not built as it is not required in Fedora 17 and later and cannot build on it. To re-enable it for older systems, use --enable-gfs_controld when running the configure script (see below). The library dependencies for gfs_controld are only required when this option is -given. +given. The extra libraries upon which gfs_controld depends are: -Run the following commands: + clusterlib + corosynclib + openaislib -./autogen.sh -./configure -make +To build gfs2-utils, run the following commands: -and optionally: + ./autogen.sh + ./configure + make -make install +To run the test suite: + + make check + +To install gfs2-utils, run: + + make install There is also an alternative (experimental, but eventually will take over from the current build system) build system which requires only GNU make.configure.ac +7
-0@@ -117,6 +117,12 @@ AS_IF([test "x$enable_gfs_controld" = "xyes"], [ PKG_CHECK_MODULES([quorum],[libquorum]) ]) +# We use the Check framework for unit tests +PKG_CHECK_MODULES([check], [check >= 0.9.8], + [have_check=yes], + [have_check=no]) +AM_CONDITIONAL([BUILD_TESTS], [test "x$have_check" = "xyes"]) + PKG_CHECK_MODULES([zlib],[zlib]) # old versions of ncurses don't ship pkg-config files@@ -263,6 +269,7 @@ AC_CONFIG_FILES([Makefile gfs2/man/Makefile gfs2/lockcapture/Makefile doc/Makefile + tests/Makefile po/Makefile.in ])gfs2/edit/hexedit.c +0
-3@@ -3105,9 +3105,6 @@ int main(int argc, char *argv[]) {int i, j, fd; -if (lgfs2_selfcheck ()) -return EXIT_FAILURE ; - indirect =malloc (sizeof (struct iinfo ));if (!indirect)die ("Out of memory." );tests/Makefile.am new file +8
-0@@ -0,0 +1,8 @@ +TESTS = check_libgfs2 +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@tests/check_meta.c new file +33
-0@@ -0,0 +1,33 @@ +#include <check.h> +#include "libgfs2.h" + +// TODO: Remove this when the extern is removed from libgfs2 +void print_it (const char *label,const char *fmt,const char *fmt2, ...) {} + +START_TEST (test_lgfs2_meta) +{ +fail_unless (lgfs2_selfcheck () ==0 ); +} +END_TEST + +static Suite * libgfs2_suite(void) +{ +Suite *s =suite_create ("libgfs2" ); + +TCase *tc_meta =tcase_create ("Meta" ); +tcase_add_test (tc_meta, test_lgfs2_meta); +suite_add_tcase (s, tc_meta); + +return s; +} + +int main (void ) +{ +int failures; +Suite *s =libgfs2_suite (); +SRunner *sr =srunner_create (s); +srunner_run_all (sr,CK_NORMAL ); + failures =srunner_ntests_failed (sr); +srunner_free (sr); +return failures ?EXIT_FAILURE :EXIT_SUCCESS ; +}
PATCH 1/1 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'.
--- tests/Makefile.am | 4 +++- tests/tool_tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100755 tests/tool_tests.sh
tests/Makefile.am +3 -1
@@ -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
tests/tool_tests.sh new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 1/1 gfs2-utils tests: Add a script to exercise the utils
Hi,
Quoted 66 lines · Andrew Price
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 <[email protected]>--- tests/Makefile.am | 4 +++- tests/tool_tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100755 tests/tool_tests.shtests/Makefile.am +3
-1@@ -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.htests/tool_tests.sh new file +37
-0@@ -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 +}
tests/tool_tests.sh line 47
Quoted 10 lines
tests/tool_tests.sh new file +10
-0+ +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"
This doesn't look very sparse, shouldn't we be creating it with truncate rather than dd?
Steve.
Quoted 15 lines
tests/tool_tests.sh new file +15
-0+} + + +# 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
PATCH 1/1 gfs2-utils tests: Add a script to exercise the utils
Quoted 74 lines · Steven Whitehouse
Hi,
Quoted 71 lines · Andrew Price
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 <[email protected]>--- tests/Makefile.am | 4 +++- tests/tool_tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-)create mode 100755
tests/tool_tests.shtests/Makefile.am +3
-1@@ -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.htests/tool_tests.sh new file +42
-0@@ -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" +}
Quoted 8 lines
tests/tool_tests.sh line 47
Quoted 5 lines
tests/tool_tests.sh new file +5
-0+ +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"This doesn't look very sparse, shouldn't we be creating it with truncate rather than dd?
Looks sparse to me:
$ dd if=/dev/null of=test_sparse bs=1 count=0 seek=10G 0+0 records in 0+0 records out 0 bytes (0 B) copied, 1.4466e-05 s, 0.0 kB/s $ du test_sparse 0 test_sparse $ du --apparent-size test_sparse 10485760 test_sparse
Truncate would work too but unless there's a hidden problem with the above I'll need more convincing to change it :)
Andy
Quoted 21 lines
Steve.
Quoted 15 lines
tests/tool_tests.sh new file +15
-0+} + + +# 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
PATCH 1/1 gfs2-utils tests: Add a script to exercise the utils
Hi,
Quoted 95 lines · Andrew Price
Quoted 74 lines · Steven Whitehouse
Hi,
Quoted 71 lines · Andrew Price
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 <[email protected]>--- tests/Makefile.am | 4 +++- tests/tool_tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-)create mode 100755
tests/tool_tests.shtests/Makefile.am +3
-1@@ -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.htests/tool_tests.sh new file +42
-0@@ -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" +}Quoted 8 lines
tests/tool_tests.sh line 47
Quoted 5 lines
tests/tool_tests.sh new file +5
-0+ +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"This doesn't look very sparse, shouldn't we be creating it with truncate rather than dd?
Looks sparse to me:
$ dd if=/dev/null of=test_sparse bs=1 count=0 seek=10G 0+0 records in 0+0 records out 0 bytes (0 B) copied, 1.4466e-05 s, 0.0 kB/s $ du test_sparse 0 test_sparse $ du --apparent-size test_sparse 10485760 test_sparse
Quoted 5 lines
Truncate would work too but unless there's a hidden problem with the above I'll need more convincing to change it :)
Andy
Ah, sorry. I missed the seek= the first time. Yes, that should be ok,
Steve.
Quoted 22 lines
Quoted 21 lines
Steve.
Quoted 15 lines
tests/tool_tests.sh new file +15
-0+} + + +# 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