summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorNiels de Vos <ndevos@redhat.com>2015-02-18 14:47:01 +0100
committerKaleb KEITHLEY <kkeithle@redhat.com>2015-03-05 13:51:37 -0800
commitbc2e58a436002e1627a225663bc7b11dddc1172f (patch)
treef586bcf41d82dcbb6979741ca299ff1291f9a8f7 /xlators
parent0bef7717d3100734c6c5a4ba85de7a39e76774db (diff)
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 <asn@samba.org> Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com> Signed-off-by: Niels de Vos <ndevos@redhat.com> Change-Id: Ia2e955481c102d5dce17695a9205395a6030e985 Reviewed-on: http://review.gluster.org/9738 Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'xlators')
-rw-r--r--xlators/cluster/dht/src/Makefile.am3
-rw-r--r--xlators/cluster/dht/src/dht-layout.c13
-rw-r--r--xlators/cluster/dht/src/unittest/dht_layout_unittest.c10
3 files changed, 8 insertions, 18 deletions
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 <cmockery/pbc.h>
-#include <cmockery/cmockery_override.h>
-
-// 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 <inttypes.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
-#include <inttypes.h>
-#include <cmockery/pbc.h>
-#include <cmockery/cmockery.h>
+#include <cmocka_pbc.h>
+#include <cmocka.h>
/*
* 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);
}