All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH] gfs2-utils: Add the beginnings of a test suite
@ 2012-12-12 16:09 Andrew Price
  2012-12-13 10:58 ` Steven Whitehouse
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Price @ 2012-12-12 16:09 UTC (permalink / raw)
  To: cluster-devel.redhat.com

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.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 .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

diff --git a/.gitignore b/.gitignore
index 0627928..24344c2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/Makefile.am b/Makefile.am
index 0af3e04..3cd0b85 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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)
diff --git a/README.build b/README.build
index 27e022a..7832e2b 100644
--- a/README.build
+++ b/README.build
@@ -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.
diff --git a/configure.ac b/configure.ac
index 3cb378a..80670a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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
 		 ])
 
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 6f5f5af..931b3c3 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -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.");
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..71c1e08
--- /dev/null
+++ b/tests/Makefile.am
@@ -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@
diff --git a/tests/check_meta.c b/tests/check_meta.c
new file mode 100644
index 0000000..689a5cc
--- /dev/null
+++ b/tests/check_meta.c
@@ -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;
+}
-- 
1.7.11.7



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Cluster-devel] [PATCH] gfs2-utils: Add the beginnings of a test suite
  2012-12-12 16:09 [Cluster-devel] [PATCH] gfs2-utils: Add the beginnings of a test suite Andrew Price
@ 2012-12-13 10:58 ` Steven Whitehouse
  2012-12-14 13:21   ` [Cluster-devel] [PATCH] gfs2-utils tests: Add a script to exercise the utils Andrew Price
  0 siblings, 1 reply; 6+ messages in thread
From: Steven Whitehouse @ 2012-12-13 10:58 UTC (permalink / raw)
  To: cluster-devel.redhat.com

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.

On Wed, 2012-12-12 at 16:09 +0000, Andrew Price wrote:
> 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.
> 
> Signed-off-by: Andrew Price <anprice@redhat.com>
> ---
>  .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
> 
> diff --git a/.gitignore b/.gitignore
> index 0627928..24344c2 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -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
> diff --git a/Makefile.am b/Makefile.am
> index 0af3e04..3cd0b85 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -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)
> diff --git a/README.build b/README.build
> index 27e022a..7832e2b 100644
> --- a/README.build
> +++ b/README.build
> @@ -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.
> diff --git a/configure.ac b/configure.ac
> index 3cb378a..80670a4 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -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
>  		 ])
>  
> diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
> index 6f5f5af..931b3c3 100644
> --- a/gfs2/edit/hexedit.c
> +++ b/gfs2/edit/hexedit.c
> @@ -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.");
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> new file mode 100644
> index 0000000..71c1e08
> --- /dev/null
> +++ b/tests/Makefile.am
> @@ -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@
> diff --git a/tests/check_meta.c b/tests/check_meta.c
> new file mode 100644
> index 0000000..689a5cc
> --- /dev/null
> +++ b/tests/check_meta.c
> @@ -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;
> +}




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Cluster-devel] [PATCH] gfs2-utils tests: Add a script to exercise the utils
  2012-12-13 10:58 ` Steven Whitehouse
@ 2012-12-14 13:21   ` Andrew Price
  2012-12-14 13:33     ` Steven Whitehouse
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Price @ 2012-12-14 13:21 UTC (permalink / raw)
  To: cluster-devel.redhat.com

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@redhat.com>
---
 tests/Makefile.am   |  4 +++-
 tests/tool_tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100755 tests/tool_tests.sh

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
-- 
1.7.11.7



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Cluster-devel] [PATCH] gfs2-utils tests: Add a script to exercise the utils
  2012-12-14 13:21   ` [Cluster-devel] [PATCH] gfs2-utils tests: Add a script to exercise the utils Andrew Price
@ 2012-12-14 13:33     ` Steven Whitehouse
  2012-12-14 13:44       ` Andrew Price
  0 siblings, 1 reply; 6+ messages in thread
From: Steven Whitehouse @ 2012-12-14 13:33 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Hi,

On Fri, 2012-12-14 at 13:21 +0000, Andrew Price wrote:
> 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@redhat.com>
> ---
>  tests/Makefile.am   |  4 +++-
>  tests/tool_tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 65 insertions(+), 1 deletion(-)
>  create mode 100755 tests/tool_tests.sh
> 
> 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"

This doesn't look very sparse, shouldn't we be creating it with truncate
rather than dd?

Steve.


> +}
> +
> +
> +# 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




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Cluster-devel] [PATCH] gfs2-utils tests: Add a script to exercise the utils
  2012-12-14 13:33     ` Steven Whitehouse
@ 2012-12-14 13:44       ` Andrew Price
  2012-12-14 13:45         ` Steven Whitehouse
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Price @ 2012-12-14 13:44 UTC (permalink / raw)
  To: cluster-devel.redhat.com

On 14/12/12 13:33, Steven Whitehouse wrote:
> Hi,
>
> On Fri, 2012-12-14 at 13:21 +0000, Andrew Price wrote:
>> 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@redhat.com>
>> ---
>>   tests/Makefile.am   |  4 +++-
>>   tests/tool_tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>>   2 files changed, 65 insertions(+), 1 deletion(-)
>>   create mode 100755 tests/tool_tests.sh
>>
>> 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"
>
> 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

>
> Steve.
>
>
>> +}
>> +
>> +
>> +# 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
>
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Cluster-devel] [PATCH] gfs2-utils tests: Add a script to exercise the utils
  2012-12-14 13:44       ` Andrew Price
@ 2012-12-14 13:45         ` Steven Whitehouse
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Whitehouse @ 2012-12-14 13:45 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Hi,

On Fri, 2012-12-14 at 13:44 +0000, Andrew Price wrote:
> On 14/12/12 13:33, Steven Whitehouse wrote:
> > Hi,
> >
> > On Fri, 2012-12-14 at 13:21 +0000, Andrew Price wrote:
> >> 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@redhat.com>
> >> ---
> >>   tests/Makefile.am   |  4 +++-
> >>   tests/tool_tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >>   2 files changed, 65 insertions(+), 1 deletion(-)
> >>   create mode 100755 tests/tool_tests.sh
> >>
> >> 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"
> >
> > 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
> 
Ah, sorry. I missed the seek= the first time. Yes, that should be ok,

Steve.

> >
> > Steve.
> >
> >
> >> +}
> >> +
> >> +
> >> +# 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
> >
> >
> 




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-12-14 13:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-12 16:09 [Cluster-devel] [PATCH] gfs2-utils: Add the beginnings of a test suite Andrew Price
2012-12-13 10:58 ` Steven Whitehouse
2012-12-14 13:21   ` [Cluster-devel] [PATCH] gfs2-utils tests: Add a script to exercise the utils Andrew Price
2012-12-14 13:33     ` Steven Whitehouse
2012-12-14 13:44       ` Andrew Price
2012-12-14 13:45         ` Steven Whitehouse

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.