From bc2e58a436002e1627a225663bc7b11dddc1172f Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 18 Feb 2015 14:47:01 +0100 Subject: testing: Switch to cmocka the successor of cmockery2 This uses https://cmocka.org/ as the unit testing framework. With this change, unit testing is made optional as well. We assume there is no cmocka available while building. cmocka will be enabled by default later on. For now, to build with cmocka run: $ ./configure --enable-cmocka This change is based on the work of Andreas (replacing cmockery2 with cmocka) and Kaleb (make cmockery2 an optional build dependency). The only modifications I made, are additional #defines in unittest.h for making sure the unit tests function as expected. Change-Id: Iea4cbcdaf09996b49ffcf3680c76731459cb197e BUG: 1067059 Merged-change: http://review.gluster.org/9762/ Signed-off-by: Andreas Schneider Signed-off-by: Kaleb S. KEITHLEY Signed-off-by: Niels de Vos Change-Id: Ia2e955481c102d5dce17695a9205395a6030e985 Reviewed-on: http://review.gluster.org/9738 Tested-by: Gluster Build System --- xlators/cluster/dht/src/Makefile.am | 3 ++- xlators/cluster/dht/src/dht-layout.c | 13 +------------ xlators/cluster/dht/src/unittest/dht_layout_unittest.c | 10 +++++----- 3 files changed, 8 insertions(+), 18 deletions(-) (limited to 'xlators/cluster/dht/src') diff --git a/xlators/cluster/dht/src/Makefile.am b/xlators/cluster/dht/src/Makefile.am index ab58affe2b4..8d02749f4d9 100644 --- a/xlators/cluster/dht/src/Makefile.am +++ b/xlators/cluster/dht/src/Makefile.am @@ -36,7 +36,7 @@ uninstall-local: install-data-hook: ln -sf dht.so $(DESTDIR)$(xlatordir)/distribute.so -#### UNIT TESTS ##### +if UNITTEST CLEANFILES += *.gcda *.gcno *_xunit.xml noinst_PROGRAMS = TESTS = @@ -49,3 +49,4 @@ dht_layout_unittest_CFLAGS = $(AM_CFLAGS) $(UNITTEST_CFLAGS) dht_layout_unittest_LDFLAGS = $(UNITTEST_LDFLAGS) noinst_PROGRAMS += dht_layout_unittest TESTS += dht_layout_unittest +endif diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c index fa29b6bfa28..757ec731d26 100644 --- a/xlators/cluster/dht/src/dht-layout.c +++ b/xlators/cluster/dht/src/dht-layout.c @@ -19,6 +19,7 @@ #include "dht-common.h" #include "byte-order.h" #include "dht-messages.h" +#include "unittest/unittest.h" #define layout_base_size (sizeof (dht_layout_t)) @@ -27,18 +28,6 @@ #define layout_size(cnt) (layout_base_size + (cnt * layout_entry_size)) -#include -#include - -// Change GF_CALLOC and GF_FREE to use -// cmockery2 memory allocation versions -#ifdef UNIT_TESTING -#undef GF_CALLOC -#define GF_CALLOC(n, s, t) test_calloc(n, s) -#undef GF_FREE -#define GF_FREE test_free -#endif - dht_layout_t * dht_layout_new (xlator_t *this, int cnt) { diff --git a/xlators/cluster/dht/src/unittest/dht_layout_unittest.c b/xlators/cluster/dht/src/unittest/dht_layout_unittest.c index b5233d235d0..3702af366f9 100644 --- a/xlators/cluster/dht/src/unittest/dht_layout_unittest.c +++ b/xlators/cluster/dht/src/unittest/dht_layout_unittest.c @@ -12,12 +12,12 @@ #include "logging.h" #include "xlator.h" +#include #include #include #include -#include -#include -#include +#include +#include /* * Helper functions @@ -116,9 +116,9 @@ test_dht_layout_new(void **state) } int main(void) { - const UnitTest tests[] = { + const struct CMUnitTest xlator_dht_layout_tests[] = { unit_test(test_dht_layout_new), }; - return run_tests(tests, "xlator_dht_layout"); + return cmocka_run_group_tests(xlator_dht_layout_tests, NULL, NULL); } -- cgit