This is an automated email from the git hooks/post-receive script.
andyp pushed a change to branch master in repository gfs2-utils.
from 2b1e9b8 libgfs2: Don't define TRUE or FALSE in libgfs2.h new 0fa008e Reorganise unit tests new c9d55af Stub out unit tests for the main gfs2-utils new 724e23d Describe the unit tests in README.tests
The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
Summary of changes: .gitignore | 14 +++++--- doc/README.tests | 31 +++++++++++++++-- gfs2/convert/Makefile.am | 4 +++ gfs2/convert/check_convert.c | 27 +++++++++++++++ gfs2/convert/checks.am | 7 ++++ gfs2/convert/gfs2_convert.c | 2 ++ gfs2/edit/Makefile.am | 3 ++ gfs2/edit/check_edit.c | 27 +++++++++++++++ gfs2/edit/checks.am | 7 ++++ gfs2/edit/hexedit.c | 2 ++ gfs2/fsck/Makefile.am | 4 +++ gfs2/fsck/check_fsck.c | 27 +++++++++++++++ gfs2/fsck/checks.am | 7 ++++ gfs2/fsck/main.c | 2 ++ gfs2/libgfs2/Makefile.am | 21 ++++++----- gfs2/libgfs2/check_libgfs2.c | 21 +++++++++++ gfs2/libgfs2/check_meta.c | 21 +++++++++++ {tests => gfs2/libgfs2}/check_rgrp.c | 67 +++++++++++++++--------------------- gfs2/libgfs2/checks.am | 32 +++++++++++++++++ gfs2/mkfs/Makefile.am | 3 ++ gfs2/mkfs/check_grow.c | 27 +++++++++++++++ gfs2/mkfs/check_jadd.c | 27 +++++++++++++++ gfs2/mkfs/check_mkfs.c | 27 +++++++++++++++ gfs2/mkfs/checks.am | 17 +++++++++ gfs2/mkfs/main_grow.c | 2 ++ gfs2/mkfs/main_jadd.c | 2 ++ gfs2/mkfs/main_mkfs.c | 2 ++ gfs2/tune/Makefile.am | 4 +++ gfs2/tune/check_tune.c | 27 +++++++++++++++ gfs2/tune/checks.am | 7 ++++ gfs2/tune/main.c | 2 ++ tests/Makefile.am | 53 +++------------------------- tests/check_meta.c | 33 ------------------ tests/libgfs2.at | 9 ----- tests/testsuite.at | 1 - 35 files changed, 421 insertions(+), 148 deletions(-) create mode 100644 gfs2/convert/check_convert.c create mode 100644 gfs2/convert/checks.am create mode 100644 gfs2/edit/check_edit.c create mode 100644 gfs2/edit/checks.am create mode 100644 gfs2/fsck/check_fsck.c create mode 100644 gfs2/fsck/checks.am create mode 100644 gfs2/libgfs2/check_libgfs2.c create mode 100644 gfs2/libgfs2/check_meta.c rename {tests => gfs2/libgfs2}/check_rgrp.c (62%) create mode 100644 gfs2/libgfs2/checks.am create mode 100644 gfs2/mkfs/check_grow.c create mode 100644 gfs2/mkfs/check_jadd.c create mode 100644 gfs2/mkfs/check_mkfs.c create mode 100644 gfs2/mkfs/checks.am create mode 100644 gfs2/tune/check_tune.c create mode 100644 gfs2/tune/checks.am delete mode 100644 tests/check_meta.c delete mode 100644 tests/libgfs2.at
This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch master in repository gfs2-utils.
commit 0fa008e14b077ed37db467b8746a61a7fe6212a5 Author: Andrew Price anprice@redhat.com AuthorDate: Thu Sep 10 00:29:13 2020 +0100
Reorganise unit tests
Move the libgfs2 unit tests out of the main testsuite and into the libgfs2 directory. They are still run in 'make check' but the new organisation means we have the tests closer to the code that they're testing and the main testsuite script no longer needs exceptions for running outside of the source tree (e.g. for CI).
Also rework the libgfs2 unit tests so that they're built as several suites in one executable. This simplifies the build rules.
The setup and teardown code for the mocked structures in the rgrp.c unit tests is now implemented as libcheck 'fixtures' that are run for each test case.
The automake rules for building unit tests are now separated into a checks.am file that is included depending on whether libcheck is available.
Signed-off-by: Andrew Price anprice@redhat.com --- .gitignore | 7 ++-- gfs2/libgfs2/Makefile.am | 21 ++++++----- gfs2/libgfs2/check_libgfs2.c | 21 +++++++++++ gfs2/libgfs2/check_meta.c | 21 +++++++++++ {tests => gfs2/libgfs2}/check_rgrp.c | 67 +++++++++++++++--------------------- gfs2/libgfs2/checks.am | 32 +++++++++++++++++ tests/Makefile.am | 53 +++------------------------- tests/check_meta.c | 33 ------------------ tests/libgfs2.at | 9 ----- tests/testsuite.at | 1 - 10 files changed, 119 insertions(+), 146 deletions(-)
diff --git a/.gitignore b/.gitignore index eee6a6b..133e807 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,8 @@ cscope.out *.o *.la *.lo +*.trs +*.log gfs2/convert/gfs2_convert gfs2/edit/gfs2_edit gfs2/libgfs2/gfs2l @@ -38,6 +40,7 @@ gfs2/libgfs2/parser.c gfs2/libgfs2/parser.h gfs2/libgfs2/lexer.c gfs2/libgfs2/lexer.h +gfs2/libgfs2/check_libgfs2 gfs2/fsck/fsck.gfs2 gfs2/glocktop/glocktop gfs2/mkfs/mkfs.gfs2 @@ -46,13 +49,9 @@ gfs2/mkfs/gfs2_jadd gfs2/scripts/82-gfs2-withdraw.rules gfs2/tune/tunegfs2 test-driver -tests/check_meta -tests/check_rgrp tests/nukerg tests/testvol -tests/testsuite.log tests/testsuite.dir -tests/testsuite.trs tests/atconfig tests/atlocal tests/package.m4 diff --git a/gfs2/libgfs2/Makefile.am b/gfs2/libgfs2/Makefile.am index 03a955f..e614415 100644 --- a/gfs2/libgfs2/Makefile.am +++ b/gfs2/libgfs2/Makefile.am @@ -12,6 +12,12 @@ BUILT_SOURCES = \
AM_LFLAGS = --header-file=lexer.h AM_YFLAGS = -d +AM_CPPFLAGS = \ + -D_FILE_OFFSET_BITS=64 \ + -D_LARGEFILE64_SOURCE \ + -D_GNU_SOURCE \ + -I$(top_srcdir)/gfs2/include \ + $(uuid_CFLAGS)
noinst_HEADERS = \ libgfs2.h \ @@ -43,13 +49,6 @@ libgfs2_la_SOURCES = \ structures.c \ meta.c
-libgfs2_la_CPPFLAGS = \ - -D_FILE_OFFSET_BITS=64 \ - -D_LARGEFILE64_SOURCE \ - -D_GNU_SOURCE \ - -I$(top_srcdir)/gfs2/include \ - $(uuid_CFLAGS) - gfs2l_SOURCES = \ gfs2l.c \ lang.c \ @@ -58,11 +57,11 @@ gfs2l_SOURCES = \ gfs2l_LDADD = \ libgfs2.la \ $(uuid_LIBS) -gfs2l_CPPFLAGS = \ - -I$(top_srcdir)/gfs2/include \ - -D_FILE_OFFSET_BITS=64 \ - $(uuid_CFLAGS)
# Autotools can't handle header files output by flex so we have to generate it manually lexer.h: lexer.l $(LEX) -o lexer.c $(AM_LFLAGS) $^ + +if HAVE_CHECK +include checks.am +endif diff --git a/gfs2/libgfs2/check_libgfs2.c b/gfs2/libgfs2/check_libgfs2.c new file mode 100644 index 0000000..0cfe08f --- /dev/null +++ b/gfs2/libgfs2/check_libgfs2.c @@ -0,0 +1,21 @@ +#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, ...) {} + +extern Suite *suite_meta(void); +extern Suite *suite_rgrp(void); + +int main(void) +{ + int failures; + + SRunner *runner = srunner_create(suite_meta()); + srunner_add_suite(runner, suite_rgrp()); + + srunner_run_all(runner, CK_ENV); + failures = srunner_ntests_failed(runner); + srunner_free(runner); + return failures ? 1 : 0; +} diff --git a/gfs2/libgfs2/check_meta.c b/gfs2/libgfs2/check_meta.c new file mode 100644 index 0000000..4f4546f --- /dev/null +++ b/gfs2/libgfs2/check_meta.c @@ -0,0 +1,21 @@ +#include <check.h> +#include "libgfs2.h" + +Suite *suite_meta(void); + +START_TEST(test_lgfs2_meta) +{ + ck_assert(lgfs2_selfcheck() == 0); +} +END_TEST + +Suite *suite_meta(void) +{ + Suite *s = suite_create("meta.c"); + + TCase *tc_meta = tcase_create("Metadata description self-check"); + tcase_add_test(tc_meta, test_lgfs2_meta); + suite_add_tcase(s, tc_meta); + + return s; +} diff --git a/tests/check_rgrp.c b/gfs2/libgfs2/check_rgrp.c similarity index 62% rename from tests/check_rgrp.c rename to gfs2/libgfs2/check_rgrp.c index 3d8a5ed..4cf0175 100644 --- a/tests/check_rgrp.c +++ b/gfs2/libgfs2/check_rgrp.c @@ -1,19 +1,20 @@ #include <check.h> -#include <libgfs2.h> -#include <rgrp.h> /* Private header libgfs2/rgrp.h for convenience */ +#include "libgfs2.h" +#include "rgrp.h" /* Private header libgfs2/rgrp.h for convenience */
-// TODO: Remove this when the extern is removed from libgfs2 -void print_it(const char *label, const char *fmt, const char *fmt2, ...) {} +Suite *suite_rgrp(void);
-static lgfs2_rgrps_t mockup_rgrp(void) +lgfs2_rgrps_t tc_rgrps; + +static void mockup_rgrps(void) { struct gfs2_sbd *sdp; lgfs2_rgrps_t rgs; - unsigned i; uint64_t addr; struct gfs2_rindex ri = {0}; lgfs2_rgrp_t rg; uint32_t rgsize = (1024 << 20) / 4096; + int ret;
sdp = calloc(1, sizeof(*sdp)); ck_assert(sdp != NULL); @@ -34,25 +35,25 @@ static lgfs2_rgrps_t mockup_rgrp(void) rg = lgfs2_rgrps_append(rgs, &ri, 0); ck_assert(rg != NULL);
- for (i = 0; i < rg->ri.ri_length; i++) { - rg->bits[i].bi_data = calloc(1, sdp->bsize); - ck_assert(rg->bits[i].bi_data != NULL); - } - return rgs; + ret = lgfs2_rgrp_bitbuf_alloc(rg); + ck_assert(ret == 0); + ck_assert(rg->bits[0].bi_data != NULL); + + tc_rgrps = rgs; }
-START_TEST(test_mockup_rgrp) +static void teardown_rgrps(void) { - lgfs2_rgrps_t rgs = mockup_rgrp(); - ck_assert(rgs != NULL); + free(tc_rgrps->sdp); + lgfs2_rgrp_bitbuf_free(lgfs2_rgrp_first(tc_rgrps)); + lgfs2_rgrps_free(&tc_rgrps); } -END_TEST
START_TEST(test_rbm_find_good) { uint32_t minext; struct lgfs2_rbm rbm = {0}; - lgfs2_rgrps_t rgs = mockup_rgrp(); + lgfs2_rgrps_t rgs = tc_rgrps; rbm.rgd = lgfs2_rgrp_first(rgs);
/* Check that extent sizes up to the whole rg can be found */ @@ -76,7 +77,7 @@ START_TEST(test_rbm_find_bad) int err; uint32_t minext; struct lgfs2_rbm rbm = {0}; - lgfs2_rgrps_t rgs = mockup_rgrp(); + lgfs2_rgrps_t rgs = tc_rgrps;
rbm.rgd = lgfs2_rgrp_first(rgs); minext = rbm.rgd->ri.ri_data + 1; @@ -94,7 +95,7 @@ START_TEST(test_rbm_find_lastblock) uint32_t minext = 1; /* Only looking for one block */ struct lgfs2_rbm rbm = {0}; lgfs2_rgrp_t rg; - lgfs2_rgrps_t rgs = mockup_rgrp(); + lgfs2_rgrps_t rgs = tc_rgrps;
rbm.rgd = rg = lgfs2_rgrp_first(rgs);
@@ -114,30 +115,18 @@ START_TEST(test_rbm_find_lastblock) } END_TEST
-static Suite * libgfs2_suite(void) +Suite *suite_rgrp(void) {
- Suite *s = suite_create("libgfs2"); - - TCase *tc_rgrp = tcase_create("rgrp"); + Suite *s = suite_create("rgrp.c");
- tcase_add_test(tc_rgrp, test_mockup_rgrp); - tcase_add_test(tc_rgrp, test_rbm_find_good); - tcase_add_test(tc_rgrp, test_rbm_find_bad); - tcase_add_test(tc_rgrp, test_rbm_find_lastblock); - tcase_set_timeout(tc_rgrp, 0); - suite_add_tcase(s, tc_rgrp); + TCase *tc_rbm_find = tcase_create("rbm_find"); + tcase_add_checked_fixture(tc_rbm_find, mockup_rgrps, teardown_rgrps); + tcase_add_test(tc_rbm_find, test_rbm_find_good); + tcase_add_test(tc_rbm_find, test_rbm_find_bad); + tcase_add_test(tc_rbm_find, test_rbm_find_lastblock); + tcase_set_timeout(tc_rbm_find, 0); + suite_add_tcase(s, tc_rbm_find);
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; -} diff --git a/gfs2/libgfs2/checks.am b/gfs2/libgfs2/checks.am new file mode 100644 index 0000000..ff4b758 --- /dev/null +++ b/gfs2/libgfs2/checks.am @@ -0,0 +1,32 @@ +TESTS = check_libgfs2 +check_PROGRAMS = $(TESTS) + +check_libgfs2_SOURCES = \ + check_libgfs2.c \ + meta.c check_meta.c \ + rgrp.c check_rgrp.c \ + block_list.c \ + crc32c.c \ + fs_geometry.c \ + gfs2_disk_hash.c \ + ondisk.c \ + buf.c \ + device_geometry.c \ + fs_ops.c \ + structures.c \ + config.c \ + fs_bits.c \ + gfs1.c \ + misc.c \ + recovery.c \ + super.c + +check_libgfs2_CFLAGS = \ + -I$(top_srcdir)/gfs2/libgfs2 \ + -I$(top_srcdir)/gfs2/include \ + $(check_CFLAGS) \ + $(uuid_CFLAGS) + +check_libgfs2_LDADD = \ + $(check_LIBS) \ + $(uuid_LIBS) diff --git a/tests/Makefile.am b/tests/Makefile.am index f8ce374..11d848c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -30,45 +30,6 @@ nukerg_LDADD = \ $(top_builddir)/gfs2/libgfs2/libgfs2.la \ $(uuid_LIBS)
-if HAVE_CHECK -UNIT_TESTS = \ - check_meta \ - check_rgrp -UNIT_SOURCES = \ - $(top_srcdir)/gfs2/libgfs2/libgfs2.h -UNIT_CFLAGS = \ - -I$(top_srcdir)/gfs2/libgfs2 \ - -I$(top_srcdir)/gfs2/include \ - @check_CFLAGS@ -UNIT_LDADD = \ - $(top_builddir)/gfs2/libgfs2/libgfs2.la \ - @check_LIBS@ -UNIT_CPPFLAGS = \ - -D_FILE_OFFSET_BITS=64 \ - -D_LARGEFILE64_SOURCE \ - -D_GNU_SOURCE - -check_PROGRAMS = $(UNIT_TESTS) - -check_meta_SOURCES = \ - $(UNIT_SOURCES) \ - check_meta.c -check_meta_CFLAGS = $(UNIT_CFLAGS) -check_meta_LDADD = \ - $(UNIT_LDADD) \ - $(uuid_LIBS) -check_meta_CPPFLAGS = $(UNIT_CPPFLAGS) - -check_rgrp_SOURCES = \ - $(UNIT_SOURCES) \ - check_rgrp.c -check_rgrp_CFLAGS = $(UNIT_CFLAGS) -check_rgrp_LDADD = \ - $(UNIT_LDADD) \ - $(uuid_LIBS) -check_rgrp_CPPFLAGS = $(UNIT_CPPFLAGS) -endif - # The `:;' works around a Bash 3.2 bug when the output is not writable. package.m4: $(top_srcdir)/configure.ac :;{ \ @@ -91,21 +52,15 @@ TESTSUITE_AT = \ testsuite.at \ mkfs.at \ fsck.at \ - edit.at \ - libgfs2.at - -if HAVE_CHECK -ENABLE_UNIT=yes -endif + edit.at
TESTSUITE = testsuite
check-local: atconfig atlocal $(TESTSUITE) - $(SHELL) '$(TESTSUITE)' ENABLE_UNIT_TESTS=$(ENABLE_UNIT) $(TOPTS) + $(SHELL) '$(TESTSUITE)' $(TOPTS)
installcheck-local: atconfig atlocal $(TESTSUITE) - $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(sbindir):gfs2/libgfs2:tests' \ - ENABLE_UNIT_TESTS=$(ENABLE_UNIT) $(TOPTS) + $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(sbindir):gfs2/libgfs2:tests' $(TOPTS)
clean-local: test ! -f '$(TESTSUITE)' || $(SHELL) '$(TESTSUITE)' --clean @@ -117,6 +72,6 @@ atconfig: $(top_builddir)/config.status AUTOM4TE = $(SHELL) $(top_srcdir)/missing --run autom4te AUTOTEST = $(AUTOM4TE) --language=autotest
-$(TESTSUITE): $(TESTSUITE_AT) package.m4 $(UNIT_TESTS) +$(TESTSUITE): $(TESTSUITE_AT) package.m4 $(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at mv $@.tmp $@ diff --git a/tests/check_meta.c b/tests/check_meta.c deleted file mode 100644 index 8c7fab1..0000000 --- a/tests/check_meta.c +++ /dev/null @@ -1,33 +0,0 @@ -#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) -{ - ck_assert(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; -} diff --git a/tests/libgfs2.at b/tests/libgfs2.at deleted file mode 100644 index 3a5174a..0000000 --- a/tests/libgfs2.at +++ /dev/null @@ -1,9 +0,0 @@ -AT_BANNER([libgfs2 unit tests]) - -GFS_UNIT_TEST([meta.c],[libgfs2]) -AT_CHECK(GFS_RUN_OR_SKIP([check_meta]), 0, [ignore], [ignore]) -AT_CLEANUP - -GFS_UNIT_TEST([rgrp.c],[libgfs2]) -AT_CHECK(GFS_RUN_OR_SKIP([check_rgrp]), 0, [ignore], [ignore]) -AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index 80bfdda..9810218 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -51,4 +51,3 @@ AT_COLOR_TESTS m4_include([mkfs.at]) m4_include([fsck.at]) m4_include([edit.at]) -m4_include([libgfs2.at])
This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch master in repository gfs2-utils.
commit c9d55af7107f8ad8dec45028512ad3e1f837056b Author: Andrew Price anprice@redhat.com AuthorDate: Thu Sep 10 17:39:01 2020 +0100
Stub out unit tests for the main gfs2-utils
Create stub unit test infrastructure for mkfs.gfs2, gfs2_edit, gfs2_convert, tunegfs2, fsck.gfs2, gfs2_jadd and gfs2_grow.
The idea here is to make the effort needed to add unit tests when writing new code minimal, although with some effort and imagination it might be possible to make the existing code testable.
main() functions are currently #ifdef'd away when building unit tests as they clash with the main() function of the unit tests, but a different method could be used if we find it valuable to test the main() functions themselves.
Signed-off-by: Andrew Price anprice@redhat.com --- .gitignore | 7 +++++++ gfs2/convert/Makefile.am | 4 ++++ gfs2/convert/check_convert.c | 27 +++++++++++++++++++++++++++ gfs2/convert/checks.am | 7 +++++++ gfs2/convert/gfs2_convert.c | 2 ++ gfs2/edit/Makefile.am | 3 +++ gfs2/edit/check_edit.c | 27 +++++++++++++++++++++++++++ gfs2/edit/checks.am | 7 +++++++ gfs2/edit/hexedit.c | 2 ++ gfs2/fsck/Makefile.am | 4 ++++ gfs2/fsck/check_fsck.c | 27 +++++++++++++++++++++++++++ gfs2/fsck/checks.am | 7 +++++++ gfs2/fsck/main.c | 2 ++ gfs2/mkfs/Makefile.am | 3 +++ gfs2/mkfs/check_grow.c | 27 +++++++++++++++++++++++++++ gfs2/mkfs/check_jadd.c | 27 +++++++++++++++++++++++++++ gfs2/mkfs/check_mkfs.c | 27 +++++++++++++++++++++++++++ gfs2/mkfs/checks.am | 17 +++++++++++++++++ gfs2/mkfs/main_grow.c | 2 ++ gfs2/mkfs/main_jadd.c | 2 ++ gfs2/mkfs/main_mkfs.c | 2 ++ gfs2/tune/Makefile.am | 4 ++++ gfs2/tune/check_tune.c | 27 +++++++++++++++++++++++++++ gfs2/tune/checks.am | 7 +++++++ gfs2/tune/main.c | 2 ++ 25 files changed, 273 insertions(+)
diff --git a/.gitignore b/.gitignore index 133e807..74b14b9 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,9 @@ cscope.out *.trs *.log gfs2/convert/gfs2_convert +gfs2/convert/check_convert gfs2/edit/gfs2_edit +gfs2/edit/check_edit gfs2/libgfs2/gfs2l gfs2/libgfs2/parser.c gfs2/libgfs2/parser.h @@ -42,12 +44,17 @@ gfs2/libgfs2/lexer.c gfs2/libgfs2/lexer.h gfs2/libgfs2/check_libgfs2 gfs2/fsck/fsck.gfs2 +gfs2/fsck/check_fsck gfs2/glocktop/glocktop gfs2/mkfs/mkfs.gfs2 gfs2/mkfs/gfs2_grow gfs2/mkfs/gfs2_jadd +gfs2/mkfs/check_grow +gfs2/mkfs/check_jadd +gfs2/mkfs/check_mkfs gfs2/scripts/82-gfs2-withdraw.rules gfs2/tune/tunegfs2 +gfs2/tune/check_tune test-driver tests/nukerg tests/testvol diff --git a/gfs2/convert/Makefile.am b/gfs2/convert/Makefile.am index 2d61af7..2f54590 100644 --- a/gfs2/convert/Makefile.am +++ b/gfs2/convert/Makefile.am @@ -10,3 +10,7 @@ gfs2_convert_CPPFLAGS = \ gfs2_convert_LDADD = \ $(top_builddir)/gfs2/libgfs2/libgfs2.la \ $(uuid_LIBS) + +if HAVE_CHECK +include checks.am +endif diff --git a/gfs2/convert/check_convert.c b/gfs2/convert/check_convert.c new file mode 100644 index 0000000..230b9e3 --- /dev/null +++ b/gfs2/convert/check_convert.c @@ -0,0 +1,27 @@ +#include <check.h> + +START_TEST(test_convert_stub) +{ + ck_assert(1); +} +END_TEST + +static Suite *suite_convert(void) +{ + Suite *s = suite_create("gfs2_convert.c"); + TCase *tc_convert = tcase_create("gfs2_convert"); + tcase_add_test(tc_convert, test_convert_stub); + suite_add_tcase(s, tc_convert); + return s; +} + +int main(void) +{ + int failures; + + SRunner *runner = srunner_create(suite_convert()); + srunner_run_all(runner, CK_ENV); + failures = srunner_ntests_failed(runner); + srunner_free(runner); + return failures ? 1 : 0; +} diff --git a/gfs2/convert/checks.am b/gfs2/convert/checks.am new file mode 100644 index 0000000..06a7e3b --- /dev/null +++ b/gfs2/convert/checks.am @@ -0,0 +1,7 @@ +TESTS = check_convert +check_PROGRAMS = $(TESTS) + +check_convert_SOURCES = $(gfs2_convert_SOURCES) check_convert.c +check_convert_CPPFLAGS = $(gfs2_convert_CPPFLAGS) -DUNITTESTS +check_convert_CFLAGS = $(gfs2_convert_CFLAGS) $(check_CFLAGS) -Wno-unused-function +check_convert_LDADD = $(gfs2_convert_LDADD) $(check_LIBS) diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c index 99a9fad..dd94503 100644 --- a/gfs2/convert/gfs2_convert.c +++ b/gfs2/convert/gfs2_convert.c @@ -2160,6 +2160,7 @@ static int gfs2_query(struct gfs2_options *opts, const char *dev) return res; }
+#ifndef UNITTESTS int main(int argc, char **argv) { int error; @@ -2370,3 +2371,4 @@ int main(int argc, char **argv) free(sd_jindex); exit(0); } +#endif /* UNITTESTS */ diff --git a/gfs2/edit/Makefile.am b/gfs2/edit/Makefile.am index 53a7dea..cee327a 100644 --- a/gfs2/edit/Makefile.am +++ b/gfs2/edit/Makefile.am @@ -33,3 +33,6 @@ gfs2_edit_LDADD = \ $(bzip2_LIBS) \ $(uuid_LIBS)
+if HAVE_CHECK +include checks.am +endif diff --git a/gfs2/edit/check_edit.c b/gfs2/edit/check_edit.c new file mode 100644 index 0000000..1aa7009 --- /dev/null +++ b/gfs2/edit/check_edit.c @@ -0,0 +1,27 @@ +#include <check.h> + +START_TEST(test_edit_stub) +{ + ck_assert(1); +} +END_TEST + +static Suite *suite_edit(void) +{ + Suite *s = suite_create("hexedit.c"); + TCase *tc_edit = tcase_create("gfs2_edit"); + tcase_add_test(tc_edit, test_edit_stub); + suite_add_tcase(s, tc_edit); + return s; +} + +int main(void) +{ + int failures; + + SRunner *runner = srunner_create(suite_edit()); + srunner_run_all(runner, CK_ENV); + failures = srunner_ntests_failed(runner); + srunner_free(runner); + return failures ? 1 : 0; +} diff --git a/gfs2/edit/checks.am b/gfs2/edit/checks.am new file mode 100644 index 0000000..6d9282a --- /dev/null +++ b/gfs2/edit/checks.am @@ -0,0 +1,7 @@ +TESTS = check_edit +check_PROGRAMS = $(TESTS) + +check_edit_SOURCES = $(gfs2_edit_SOURCES) check_edit.c +check_edit_CPPFLAGS = $(gfs2_edit_CPPFLAGS) -DUNITTESTS +check_edit_CFLAGS = $(gfs2_edit_CFLAGS) $(check_CFLAGS) -Wno-unused-function +check_edit_LDADD = $(gfs2_edit_LDADD) $(check_LIBS) diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c index f8b6f67..91313e8 100644 --- a/gfs2/edit/hexedit.c +++ b/gfs2/edit/hexedit.c @@ -2570,6 +2570,7 @@ static void process_parameters(int argc, char *argv[], int pass) } /* for */ }/* process_parameters */
+#ifndef UNITTESTS int main(int argc, char *argv[]) { int i, j, fd; @@ -2650,3 +2651,4 @@ int main(int argc, char *argv[]) gfs2_rgrp_free(&sbd, &sbd.rgtree); exit(EXIT_SUCCESS); } +#endif /* UNITTESTS */ diff --git a/gfs2/fsck/Makefile.am b/gfs2/fsck/Makefile.am index 1c52805..9f0e203 100644 --- a/gfs2/fsck/Makefile.am +++ b/gfs2/fsck/Makefile.am @@ -38,3 +38,7 @@ fsck_gfs2_CPPFLAGS = \ fsck_gfs2_LDADD = \ $(top_builddir)/gfs2/libgfs2/libgfs2.la \ $(uuid_LIBS) + +if HAVE_CHECK +include checks.am +endif diff --git a/gfs2/fsck/check_fsck.c b/gfs2/fsck/check_fsck.c new file mode 100644 index 0000000..08aaee2 --- /dev/null +++ b/gfs2/fsck/check_fsck.c @@ -0,0 +1,27 @@ +#include <check.h> + +START_TEST(test_fsck_stub) +{ + ck_assert(1); +} +END_TEST + +static Suite *suite_fsck(void) +{ + Suite *s = suite_create("main.c"); + TCase *tc_fsck = tcase_create("fsck.gfs2"); + tcase_add_test(tc_fsck, test_fsck_stub); + suite_add_tcase(s, tc_fsck); + return s; +} + +int main(void) +{ + int failures; + + SRunner *runner = srunner_create(suite_fsck()); + srunner_run_all(runner, CK_ENV); + failures = srunner_ntests_failed(runner); + srunner_free(runner); + return failures ? 1 : 0; +} diff --git a/gfs2/fsck/checks.am b/gfs2/fsck/checks.am new file mode 100644 index 0000000..4e96858 --- /dev/null +++ b/gfs2/fsck/checks.am @@ -0,0 +1,7 @@ +TESTS = check_fsck +check_PROGRAMS = $(TESTS) + +check_fsck_SOURCES = $(fsck_gfs2_SOURCES) check_fsck.c +check_fsck_CPPFLAGS = $(fsck_gfs2_CPPFLAGS) -DUNITTESTS -Wno-unused-const-variable +check_fsck_CFLAGS = $(fsck_gfs2_CFLAGS) $(check_CFLAGS) -Wno-unused-function +check_fsck_LDADD = $(fsck_gfs2_LDADD) $(check_LIBS) diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c index 14cb7d9..a860f6e 100644 --- a/gfs2/fsck/main.c +++ b/gfs2/fsck/main.c @@ -306,6 +306,7 @@ static void startlog(int argc, char **argv) free(cmd); }
+#ifndef UNITTESTS int main(int argc, char **argv) { struct gfs2_sbd sb; @@ -383,3 +384,4 @@ int main(int argc, char **argv) } exit(error); } +#endif /* UNITTESTS */ diff --git a/gfs2/mkfs/Makefile.am b/gfs2/mkfs/Makefile.am index fd7145b..fd00fdd 100644 --- a/gfs2/mkfs/Makefile.am +++ b/gfs2/mkfs/Makefile.am @@ -50,3 +50,6 @@ gfs2_jadd_LDADD = \ $(top_builddir)/gfs2/libgfs2/libgfs2.la \ $(uuid_LIBS)
+if HAVE_CHECK +include checks.am +endif diff --git a/gfs2/mkfs/check_grow.c b/gfs2/mkfs/check_grow.c new file mode 100644 index 0000000..d90da2c --- /dev/null +++ b/gfs2/mkfs/check_grow.c @@ -0,0 +1,27 @@ +#include <check.h> + +START_TEST(test_grow_stub) +{ + ck_assert(1); +} +END_TEST + +static Suite *suite_grow(void) +{ + Suite *s = suite_create("main_grow.c"); + TCase *tc_grow = tcase_create("grow.gfs2"); + tcase_add_test(tc_grow, test_grow_stub); + suite_add_tcase(s, tc_grow); + return s; +} + +int main(void) +{ + int failures; + + SRunner *runner = srunner_create(suite_grow()); + srunner_run_all(runner, CK_ENV); + failures = srunner_ntests_failed(runner); + srunner_free(runner); + return failures ? 1 : 0; +} diff --git a/gfs2/mkfs/check_jadd.c b/gfs2/mkfs/check_jadd.c new file mode 100644 index 0000000..b692b5a --- /dev/null +++ b/gfs2/mkfs/check_jadd.c @@ -0,0 +1,27 @@ +#include <check.h> + +START_TEST(test_jadd_stub) +{ + ck_assert(1); +} +END_TEST + +static Suite *suite_jadd(void) +{ + Suite *s = suite_create("main_jadd.c"); + TCase *tc_jadd = tcase_create("jadd.gfs2"); + tcase_add_test(tc_jadd, test_jadd_stub); + suite_add_tcase(s, tc_jadd); + return s; +} + +int main(void) +{ + int failures; + + SRunner *runner = srunner_create(suite_jadd()); + srunner_run_all(runner, CK_ENV); + failures = srunner_ntests_failed(runner); + srunner_free(runner); + return failures ? 1 : 0; +} diff --git a/gfs2/mkfs/check_mkfs.c b/gfs2/mkfs/check_mkfs.c new file mode 100644 index 0000000..81d91b8 --- /dev/null +++ b/gfs2/mkfs/check_mkfs.c @@ -0,0 +1,27 @@ +#include <check.h> + +START_TEST(test_mkfs_stub) +{ + ck_assert(1); +} +END_TEST + +static Suite *suite_mkfs(void) +{ + Suite *s = suite_create("main_mkfs.c"); + TCase *tc_mkfs = tcase_create("mkfs.gfs2"); + tcase_add_test(tc_mkfs, test_mkfs_stub); + suite_add_tcase(s, tc_mkfs); + return s; +} + +int main(void) +{ + int failures; + + SRunner *runner = srunner_create(suite_mkfs()); + srunner_run_all(runner, CK_ENV); + failures = srunner_ntests_failed(runner); + srunner_free(runner); + return failures ? 1 : 0; +} diff --git a/gfs2/mkfs/checks.am b/gfs2/mkfs/checks.am new file mode 100644 index 0000000..beb03a9 --- /dev/null +++ b/gfs2/mkfs/checks.am @@ -0,0 +1,17 @@ +TESTS = check_grow check_jadd check_mkfs +check_PROGRAMS = $(TESTS) + +check_grow_SOURCES = $(gfs2_grow_SOURCES) check_grow.c +check_grow_CPPFLAGS = $(gfs2_grow_CPPFLAGS) -DUNITTESTS +check_grow_CFLAGS = $(gfs2_grow_CFLAGS) $(check_CFLAGS) -Wno-unused-function +check_grow_LDADD = $(gfs2_grow_LDADD) $(check_LIBS) + +check_jadd_SOURCES = $(gfs2_jadd_SOURCES) check_jadd.c +check_jadd_CPPFLAGS = $(gfs2_jadd_CPPFLAGS) -DUNITTESTS +check_jadd_CFLAGS = $(gfs2_jadd_CFLAGS) $(check_CFLAGS) -Wno-unused-function +check_jadd_LDADD = $(gfs2_jadd_LDADD) $(check_LIBS) + +check_mkfs_SOURCES = $(mkfs_gfs2_SOURCES) check_mkfs.c +check_mkfs_CPPFLAGS = $(mkfs_gfs2_CPPFLAGS) -DUNITTESTS +check_mkfs_CFLAGS = $(mkfs_gfs2_CFLAGS) $(check_CFLAGS) -Wno-unused-function +check_mkfs_LDADD = $(mkfs_gfs2_LDADD) $(check_LIBS) diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c index 8882ecd..f527cc8 100644 --- a/gfs2/mkfs/main_grow.c +++ b/gfs2/mkfs/main_grow.c @@ -349,6 +349,7 @@ static int open_rindex(char *metafs_path, int mode) return fd; }
+#ifndef UNITTESTS int main(int argc, char *argv[]) { struct gfs2_sbd sbd, *sdp = &sbd; @@ -483,3 +484,4 @@ int main(int argc, char *argv[]) log_notice( _("gfs2_grow complete.\n")); return error; } +#endif /* UNITTESTS */ diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c index b7e9a64..b8f1ad9 100644 --- a/gfs2/mkfs/main_jadd.c +++ b/gfs2/mkfs/main_jadd.c @@ -589,6 +589,7 @@ static int check_fit(struct gfs2_sbd *sdp, struct jadd_opts *opts) return 0; }
+#ifndef UNITTESTS int main(int argc, char *argv[]) { struct jadd_opts opts = {0}; @@ -682,3 +683,4 @@ out:
return ret; } +#endif /* UNITTESTS */ diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c index bb9a96d..0b77959 100644 --- a/gfs2/mkfs/main_mkfs.c +++ b/gfs2/mkfs/main_mkfs.c @@ -1038,6 +1038,7 @@ static void open_dev(struct mkfs_dev *dev, int withprobe) exit(1); }
+#ifndef UNITTESTS int main(int argc, char *argv[]) { struct gfs2_sbd sbd; @@ -1201,3 +1202,4 @@ int main(int argc, char *argv[]) } return 0; } +#endif /* UNITTESTS */ diff --git a/gfs2/tune/Makefile.am b/gfs2/tune/Makefile.am index 171377d..b03f609 100644 --- a/gfs2/tune/Makefile.am +++ b/gfs2/tune/Makefile.am @@ -15,3 +15,7 @@ tunegfs2_CFLAGS = \ $(uuid_CFLAGS) tunegfs2_LDADD = \ $(uuid_LIBS) + +if HAVE_CHECK +include checks.am +endif diff --git a/gfs2/tune/check_tune.c b/gfs2/tune/check_tune.c new file mode 100644 index 0000000..5bbe5da --- /dev/null +++ b/gfs2/tune/check_tune.c @@ -0,0 +1,27 @@ +#include <check.h> + +START_TEST(test_tune_stub) +{ + ck_assert(1); +} +END_TEST + +static Suite *suite_tune(void) +{ + Suite *s = suite_create("main.c"); + TCase *tc_tune = tcase_create("tunegfs2"); + tcase_add_test(tc_tune, test_tune_stub); + suite_add_tcase(s, tc_tune); + return s; +} + +int main(void) +{ + int failures; + + SRunner *runner = srunner_create(suite_tune()); + srunner_run_all(runner, CK_ENV); + failures = srunner_ntests_failed(runner); + srunner_free(runner); + return failures ? 1 : 0; +} diff --git a/gfs2/tune/checks.am b/gfs2/tune/checks.am new file mode 100644 index 0000000..bb644e8 --- /dev/null +++ b/gfs2/tune/checks.am @@ -0,0 +1,7 @@ +TESTS = check_tune +check_PROGRAMS = $(TESTS) + +check_tune_SOURCES = $(tunegfs2_SOURCES) check_tune.c +check_tune_CPPFLAGS = $(tunegfs2_CPPFLAGS) -DUNITTESTS +check_tune_CFLAGS = $(tunegfs2_CFLAGS) $(check_CFLAGS) -Wno-unused-function +check_tune_LDADD = $(tunegfs2_LDADD) $(check_LIBS) diff --git a/gfs2/tune/main.c b/gfs2/tune/main.c index c1be8bd..93f0f60 100644 --- a/gfs2/tune/main.c +++ b/gfs2/tune/main.c @@ -62,6 +62,7 @@ static void version(void) printf("tunegfs2 (%s %s)\n", __DATE__, __TIME__); }
+#ifndef UNITTESTS int main(int argc, char **argv) { int c, status; @@ -161,3 +162,4 @@ int main(int argc, char **argv) out: return status; } +#endif /* UNITTESTS */
This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch master in repository gfs2-utils.
commit 724e23d3ff39d27e15c2c21225858fcf732a0336 Author: Andrew Price anprice@redhat.com AuthorDate: Fri Sep 11 15:14:09 2020 +0100
Describe the unit tests in README.tests
Signed-off-by: Andrew Price anprice@redhat.com --- doc/README.tests | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/doc/README.tests b/doc/README.tests index 1b90a0c..292d2ae 100644 --- a/doc/README.tests +++ b/doc/README.tests @@ -23,8 +23,8 @@ tests can be re-run using make check TOPTS='--recheck' although it's better to re-run the entire suite after fixing tests as a fix for one test could break another.
-Writing tests -------------- +Smoke/regression tests +---------------------- 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 @@ -55,6 +55,33 @@ be found in the autoconf manual at:
http://www.gnu.org/software/autoconf/manual/index.html
+Unit tests +---------- +A unit test framework for each of the main utils and libgfs2 is included in its +source directory. These tests are based on the libcheck C unit test library and +are built and run by 'make check'. Generally, there should be one check "Suite" +defined for each source file of the util, named with a check_ prefix, +containing one or more test cases defined for each externally-visible function. +For example: + + check_libgfs2 (main file: check_libgfs2.c) + |--------Suite: rgrp.c (in check_rgrp.c) + | |---------- Test case: test_rbm_find_good + | |-----------Test case: test_rbm_find_bad + |--------Suite: meta.c (in check_meta.c) + | |-----------Test case: test_lgfs2_meta + etc. etc. + +The build rules for the unit tests are separated into a checks.am file in each +source directory. Documentation for writing libcheck unit tests can be found +at: + + https://libcheck.github.io/check/doc/check_html/index.html + +Autoconf's automatically generated test driver script only prints one line for +each unit test executable run instead of one line per test case. To view +details of unit test failures, see the generated .log and .trs files. + Generating coverage reports --------------------------- Test coverage instrumentation can be enabled using the --enable-gcov option at
cluster-commits@lists.stg.fedorahosted.org