diff options
author | Luis Pabon <lpabon@redhat.com> | 2014-04-23 16:18:57 -0400 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2014-07-18 10:55:51 -0700 |
commit | 13f644f78336c79850b332c35ad439fda8dac4fa (patch) | |
tree | 7c5fc94a89b7374272451dd9608d0c90fb678ea4 /xlators/cluster/dht | |
parent | c7f617dfe63fea23693c9ae74b8761349d17a986 (diff) |
build: Support for unit tests using Cmockery2
This patch will allow for developers to create unit tests for
their code. Documentation has been added to the patch and
is available here:
doc/hacker-guide/en-US/markdown/unittest.md
Also, unit tests are run when RPM is created.
This patch is a replacement for http://review.gluster.org/#/c/7281
which removed unit test infrastucture from the repo due to multiple
conflicts. Cmockery2 is now available in Fedora and EPEL, and soon
to be available in Debian and Ubuntu. For all other operating
systems, please install from the source:
https://github.com/lpabon/cmockery2
BUG: 1067059
Change-Id: I1b36cb1f56fd10916f9bf535e8ad080a3358289f
Signed-off-by: Luis Pabón <lpabon@redhat.com>
Reviewed-on: http://review.gluster.org/7538
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/cluster/dht')
-rw-r--r-- | xlators/cluster/dht/src/Makefile.am | 14 | ||||
-rw-r--r-- | xlators/cluster/dht/src/dht-layout.c | 19 | ||||
-rw-r--r-- | xlators/cluster/dht/src/unittest/dht_layout_mock.c | 14 |
3 files changed, 47 insertions, 0 deletions
diff --git a/xlators/cluster/dht/src/Makefile.am b/xlators/cluster/dht/src/Makefile.am index a180f9263ff..9b5d6897984 100644 --- a/xlators/cluster/dht/src/Makefile.am +++ b/xlators/cluster/dht/src/Makefile.am @@ -35,3 +35,17 @@ uninstall-local: install-data-hook: ln -sf dht.so $(DESTDIR)$(xlatordir)/distribute.so + +#### UNIT TESTS ##### +CLEANFILES += *.gcda *.gcno *_xunit.xml +noinst_PROGRAMS = +TESTS = + +dht_layout_unittest_CPPFLAGS = $(AM_CPPFLAGS) +dht_layout_unittest_SOURCES = unittest/dht_layout_unittest.c \ + unittest/dht_layout_mock.c \ + dht-layout.c +dht_layout_unittest_CFLAGS = $(UNITTEST_CFLAGS) +dht_layout_unittest_LDFLAGS = $(UNITTEST_LDFLAGS) +noinst_PROGRAMS += dht_layout_unittest +TESTS += dht_layout_unittest diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c index 34892983a55..f39f5c1877f 100644 --- a/xlators/cluster/dht/src/dht-layout.c +++ b/xlators/cluster/dht/src/dht-layout.c @@ -27,12 +27,27 @@ #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) { dht_layout_t *layout = NULL; dht_conf_t *conf = NULL; + REQUIRE(NULL != this); + REQUIRE(cnt >= 0); + conf = this->private; layout = GF_CALLOC (1, layout_size (cnt), @@ -51,6 +66,10 @@ dht_layout_new (xlator_t *this, int cnt) layout->ref = 1; + ENSURE(NULL != layout); + ENSURE(layout->type == DHT_HASH_TYPE_DM); + ENSURE(layout->cnt == cnt); + ENSURE(layout->ref == 1); out: return layout; } diff --git a/xlators/cluster/dht/src/unittest/dht_layout_mock.c b/xlators/cluster/dht/src/unittest/dht_layout_mock.c index aa19ddc575d..07c1e3249a8 100644 --- a/xlators/cluster/dht/src/unittest/dht_layout_mock.c +++ b/xlators/cluster/dht/src/unittest/dht_layout_mock.c @@ -61,3 +61,17 @@ int _gf_log_callingfn (const char *domain, const char *file, { return 0; } + +void uuid_unparse(const uuid_t uu, char *out) +{ + // could call a will-return function here + // to place the correct data in *out +} + +int +_gf_msg (const char *domain, const char *file, const char *function, + int32_t line, gf_loglevel_t level, int errnum, int trace, + uint64_t msgid, const char *fmt, ...) +{ + return 0; +}
\ No newline at end of file |