summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/dht/src/dht-layout.c
diff options
context:
space:
mode:
authorLuis Pabon <lpabon@redhat.com>2014-02-20 13:50:19 -0500
committerVijay Bellur <vbellur@redhat.com>2014-03-06 04:10:46 -0800
commitc817c214033481fe59f9f44c325a9092dc337d07 (patch)
tree2259dd37b25b12fdd6a6db1738f0f2a73e71180d /xlators/cluster/dht/src/dht-layout.c
parenta193f2262b93a06bf1a299f423d4ebaaa171a539 (diff)
build: GlusterFS Unit Test Framework
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. BUG: 1067059 Change-Id: I95cf8bb0354d4ca4ed4476a0f2385436a17d2369 Signed-off-by: Vijay Bellur <vbellur@redhat.com> Signed-off-by: Luis Pabon <lpabon@redhat.com> Reviewed-on: http://review.gluster.org/7145 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Reviewed-by: Justin Clift <justin@gluster.org> Tested-by: Justin Clift <justin@gluster.org>
Diffstat (limited to 'xlators/cluster/dht/src/dht-layout.c')
-rw-r--r--xlators/cluster/dht/src/dht-layout.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c
index 31d85a5060b..deaa493f908 100644
--- a/xlators/cluster/dht/src/dht-layout.c
+++ b/xlators/cluster/dht/src/dht-layout.c
@@ -25,6 +25,19 @@
#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)
@@ -32,6 +45,8 @@ 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;
@@ -50,6 +65,11 @@ 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;
}