From: Andrew Price Date: Fri, 11 Sep 2020 15:42:41 +0100 Subject: [Cluster-devel] [PATCH 1/3] Reorganise unit tests In-Reply-To: <20200911144243.667554-1-anprice@redhat.com> References: <20200911144243.667554-1-anprice@redhat.com> Message-ID: <20200911144243.667554-2-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 --- .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(-) 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 delete mode 100644 tests/check_meta.c delete mode 100644 tests/libgfs2.at diff --git a/.gitignore b/.gitignore index eee6a6bc..133e8071 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 03a955f2..e614415e 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 00000000..0cfe08f2 --- /dev/null +++ b/gfs2/libgfs2/check_libgfs2.c @@ -0,0 +1,21 @@ +#include +#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 00000000..4f4546f2 --- /dev/null +++ b/gfs2/libgfs2/check_meta.c @@ -0,0 +1,21 @@ +#include +#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 3d8a5ed0..4cf01754 100644 --- a/tests/check_rgrp.c +++ b/gfs2/libgfs2/check_rgrp.c @@ -1,19 +1,20 @@ #include -#include -#include /* 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 00000000..ff4b7583 --- /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 f8ce3740..11d848cd 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 8c7fab1f..00000000 --- a/tests/check_meta.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#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 3a5174a5..00000000 --- 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 80bfdda7..98102183 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]) -- 2.26.2