[Cluster-devel] [PATCH] gfs2-utils: Add the beginnings of a test suite

Steven Whitehouse swhiteho at redhat.com
Thu Dec 13 10:58:56 UTC 2012


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 at 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;
> +}





More information about the Cluster-devel mailing list