All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 2/3] Stub out unit tests for the main gfs2-utils
Date: Fri, 11 Sep 2020 15:42:42 +0100	[thread overview]
Message-ID: <20200911144243.667554-3-anprice@redhat.com> (raw)
In-Reply-To: <20200911144243.667554-1-anprice@redhat.com>

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(+)
 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/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

diff --git a/.gitignore b/.gitignore
index 133e8071..74b14b9f 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 2d61af74..2f545909 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 00000000..230b9e37
--- /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 00000000..06a7e3b5
--- /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 99a9fad8..dd945032 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 53a7dea6..cee327a9 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 00000000..1aa7009b
--- /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 00000000..6d9282a3
--- /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 f8b6f67c..91313e81 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 1c528051..9f0e2035 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 00000000..08aaee2c
--- /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 00000000..4e968587
--- /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 14cb7d9b..a860f6eb 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 fd7145b8..fd00fdd5 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 00000000..d90da2c7
--- /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 00000000..b692b5a1
--- /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 00000000..81d91b88
--- /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 00000000..beb03a9b
--- /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 8882ecd3..f527cc82 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 b7e9a644..b8f1ad90 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 bb9a96d6..0b779593 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 171377d0..b03f609a 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 00000000..5bbe5da6
--- /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 00000000..bb644e82
--- /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 c1be8bd4..93f0f60c 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 */
-- 
2.26.2



  parent reply	other threads:[~2020-09-11 14:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-11 14:42 [Cluster-devel] [PATCH 0/3] gfs2-utils: Unit test framework improvements Andrew Price
2020-09-11 14:42 ` [Cluster-devel] [PATCH 1/3] Reorganise unit tests Andrew Price
2020-09-11 14:42 ` Andrew Price [this message]
2020-09-11 14:42 ` [Cluster-devel] [PATCH 3/3] Describe the unit tests in README.tests Andrew Price

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=20200911144243.667554-3-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 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.