From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 07/19] tests: Add unit tests for the new extent search functions
Date: Tue, 2 Sep 2014 13:07:24 +0100 [thread overview]
Message-ID: <1409659656-23051-8-git-send-email-anprice@redhat.com> (raw)
In-Reply-To: <1409659656-23051-1-git-send-email-anprice@redhat.com>
The rbm search functions added by the previous commit added a certain
amount of complexity. These unit tests go a long way to making sure
they're doing what they're meant to do, and also demonstrate how the new
rgrp functions work without any i/o required.
The unit test sources have also been reorganised to match the names of
the libgfs2 source files they test.
Signed-off-by: Andrew Price <anprice@redhat.com>
---
.gitignore | 3 +-
tests/Makefile.am | 33 ++++++++-----
tests/check_rgrp.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/libgfs2.at | 8 ++-
4 files changed, 173 insertions(+), 14 deletions(-)
create mode 100644 tests/check_rgrp.c
diff --git a/.gitignore b/.gitignore
index ae72f2b..4ffdb71 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,7 +42,8 @@ gfs2/fsck/fsck.gfs2
gfs2/mkfs/mkfs.gfs2
gfs2/tune/tunegfs2
test-driver
-tests/check_libgfs2
+tests/check_meta
+tests/check_rgrp
tests/testvol
tests/testsuite.log
tests/testsuite.dir
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5f02d3a..70e77ef 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -3,20 +3,28 @@ DISTCLEANFILES = atlocal atconfig
CLEANFILES = testvol
if BUILD_TESTS
-check_PROGRAMS = check_libgfs2
-
-check_libgfs2_SOURCES = \
- check_meta.c \
+UNIT_TESTS = \
+ check_meta \
+ check_rgrp
+UNIT_SOURCES = \
$(top_srcdir)/gfs2/libgfs2/libgfs2.h
-
-check_libgfs2_CFLAGS = \
+UNIT_CFLAGS = \
-I$(top_srcdir)/gfs2/libgfs2 \
-I$(top_srcdir)/gfs2/include \
@check_CFLAGS@
-
-check_libgfs2_LDADD = \
+UNIT_LDADD = \
$(top_builddir)/gfs2/libgfs2/libgfs2.la \
@check_LIBS@
+
+check_PROGRAMS = $(UNIT_TESTS)
+
+check_meta_SOURCES = $(UNIT_SOURCES) check_meta.c
+check_meta_CFLAGS = $(UNIT_CFLAGS)
+check_meta_LDADD = $(UNIT_LDADD)
+
+check_rgrp_SOURCES = $(UNIT_SOURCES) check_rgrp.c
+check_rgrp_CFLAGS = $(UNIT_CFLAGS)
+check_rgrp_LDADD = $(UNIT_LDADD)
endif
# The `:;' works around a Bash 3.2 bug when the output is not writable.
@@ -41,8 +49,11 @@ TESTSUITE_AT = \
testsuite.at \
mkfs.at \
fsck.at \
- edit.at \
- libgfs2.at
+ edit.at
+
+if BUILD_TESTS
+TESTSUITE_AT += libgfs2.at
+endif
TESTSUITE = $(srcdir)/testsuite
@@ -61,6 +72,6 @@ atconfig: $(top_builddir)/config.status
AUTOM4TE = $(SHELL) $(top_srcdir)/missing --run autom4te
AUTOTEST = $(AUTOM4TE) --language=autotest
-$(TESTSUITE): $(TESTSUITE_AT) package.m4
+$(TESTSUITE): $(TESTSUITE_AT) package.m4 $(UNIT_TESTS)
$(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at
mv $@.tmp $@
diff --git a/tests/check_rgrp.c b/tests/check_rgrp.c
new file mode 100644
index 0000000..d113846
--- /dev/null
+++ b/tests/check_rgrp.c
@@ -0,0 +1,143 @@
+#include <check.h>
+#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, ...) {}
+
+static lgfs2_rgrps_t mockup_rgrp(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;
+
+ sdp = calloc(1, sizeof(*sdp));
+ ck_assert_ptr_ne(sdp, NULL);
+
+ sdp->device.length = rgsize + 20;
+ sdp->device_fd = -1;
+ sdp->bsize = sdp->sd_sb.sb_bsize = 4096;
+ compute_constants(sdp);
+
+ rgs = lgfs2_rgrps_init(sdp, 0, 0);
+ ck_assert_ptr_ne(rgs, NULL);
+
+ lgfs2_rgrps_plan(rgs, sdp->device.length - 16, rgsize);
+
+ addr = lgfs2_rindex_entry_new(rgs, &ri, 16, rgsize);
+ ck_assert(addr != 0);
+
+ rg = lgfs2_rgrps_append(rgs, &ri);
+ ck_assert_ptr_ne(rg, NULL);
+
+ for (i = 0; i < rg->ri.ri_length; i++) {
+ rg->bits[i].bi_bh = bget(sdp, rg->ri.ri_addr + i);
+ ck_assert_ptr_ne(rg->bits[i].bi_bh, NULL);
+ }
+ return rgs;
+}
+
+START_TEST(test_mockup_rgrp)
+{
+ lgfs2_rgrps_t rgs = mockup_rgrp();
+ ck_assert_ptr_ne(rgs, NULL);
+}
+END_TEST
+
+START_TEST(test_rbm_find_good)
+{
+ uint32_t minext;
+ struct lgfs2_rbm rbm = {0};
+ lgfs2_rgrps_t rgs = mockup_rgrp();
+ rbm.rgd = lgfs2_rgrp_first(rgs);
+
+ /* Check that extent sizes up to the whole rg can be found */
+ for (minext = 1; minext <= rbm.rgd->ri.ri_data; minext++) {
+ int err;
+ uint64_t addr;
+
+ rbm.offset = rbm.bii = 0;
+
+ err = lgfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &minext);
+ ck_assert_int_eq(err, 0);
+
+ addr = lgfs2_rbm_to_block(&rbm);
+ ck_assert_uint_eq(addr, rbm.rgd->ri.ri_data0);
+ }
+}
+END_TEST
+
+START_TEST(test_rbm_find_bad)
+{
+ int err;
+ uint32_t minext;
+ struct lgfs2_rbm rbm = {0};
+ lgfs2_rgrps_t rgs = mockup_rgrp();
+
+ rbm.rgd = lgfs2_rgrp_first(rgs);
+ minext = rbm.rgd->ri.ri_data + 1;
+
+ err = lgfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &minext);
+ ck_assert_int_eq(err, 1);
+}
+END_TEST
+
+START_TEST(test_rbm_find_lastblock)
+{
+ int err;
+ unsigned i;
+ uint64_t addr;
+ uint32_t minext = 1; /* Only looking for one block */
+ struct lgfs2_rbm rbm = {0};
+ lgfs2_rgrp_t rg;
+ lgfs2_rgrps_t rgs = mockup_rgrp();
+
+ rbm.rgd = rg = lgfs2_rgrp_first(rgs);
+
+ /* Flag all blocks as allocated... */
+ for (i = 0; i < rg->ri.ri_length; i++)
+ memset(rg->bits[i].bi_bh->b_data, 0xff, rgs->sdp->bsize);
+
+ /* ...except the final one */
+ err = gfs2_set_bitmap(rg, rg->ri.ri_data0 + rg->ri.ri_data - 1, GFS2_BLKST_FREE);
+ ck_assert_int_eq(err, 0);
+
+ err = lgfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &minext);
+ ck_assert_int_eq(err, 0);
+
+ addr = lgfs2_rbm_to_block(&rbm);
+ ck_assert_uint_eq(addr, rg->ri.ri_data0 + rg->ri.ri_data - 1);
+}
+END_TEST
+
+static Suite * libgfs2_suite(void)
+{
+
+ Suite *s = suite_create("libgfs2");
+
+ TCase *tc_rgrp = tcase_create("rgrp");
+
+ 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, 60);
+ suite_add_tcase(s, tc_rgrp);
+
+ 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
index a6b478a..8c44cdd 100644
--- a/tests/libgfs2.at
+++ b/tests/libgfs2.at
@@ -1,5 +1,9 @@
AT_BANNER([libgfs2 unit tests])
-AT_SETUP([Metadata check])
-AT_CHECK([check_libgfs2], 0, [ignore], [ignore])
+AT_SETUP([meta.c])
+AT_CHECK([check_meta], 0, [ignore], [ignore])
+AT_CLEANUP
+
+AT_SETUP([rgrp.c])
+AT_CHECK([check_rgrp], 0, [ignore], [ignore])
AT_CLEANUP
--
1.9.3
next prev parent reply other threads:[~2014-09-02 12:07 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-02 12:07 [Cluster-devel] [PATCH 00/19] gfs2-utils: Introduce extent allocation and speed up journal creation Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 01/19] libgfs2: Keep a pointer to the sbd in lgfs2_rgrps_t Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 02/19] libgfs2: Move bitmap buffers inside struct gfs2_bitmap Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 03/19] libgfs2: Fix an impossible loop condition in gfs2_rgrp_read Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 04/19] libgfs2: Introduce struct lgfs2_rbm Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 05/19] libgfs2: Move struct _lgfs2_rgrps into rgrp.h Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 06/19] libgfs2: Add functions for finding free extents Andrew Price
2014-09-03 10:17 ` Steven Whitehouse
2014-09-03 12:13 ` Andrew Price
2014-09-03 12:24 ` Steven Whitehouse
2014-09-02 12:07 ` Andrew Price [this message]
2014-09-02 12:07 ` [Cluster-devel] [PATCH 08/19] libgfs2: Ignore an empty rgrp plan if a length is specified Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 09/19] libgfs2: Add back-pointer to rgrps in lgfs2_rgrp_t Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 10/19] libgfs2: Const-ify the parameters of print functions Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 11/19] libgfs2: Allow init_dinode to accept a preallocated bh Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 12/19] libgfs2: Add extent allocation functions Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 13/19] libgfs2: Add support for allocating entire rgrp headers Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 14/19] libgfs2: Write file metadata sequentially Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 15/19] libgfs2: Fix alignment in lgfs2_rgsize_for_data Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 16/19] libgfs2: Handle non-zero bitmaps in lgfs2_rgrp_write Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 17/19] libgfs2: Add a speedier journal data block writing function Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 18/19] libgfs2: Create jindex directory separately from journals Andrew Price
2014-09-02 12:07 ` [Cluster-devel] [PATCH 19/19] mkfs.gfs2: Improve journal creation performance Andrew Price
2014-09-02 14:06 ` [Cluster-devel] [PATCH 00/19] gfs2-utils: Introduce extent allocation and speed up journal creation Bob Peterson
2014-09-03 10:20 ` Steven Whitehouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1409659656-23051-8-git-send-email-anprice@redhat.com \
--to=anprice@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).