diff options
author | Luis Pabon <lpabon@redhat.com> | 2014-02-20 13:50:19 -0500 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2014-03-06 04:10:46 -0800 |
commit | c817c214033481fe59f9f44c325a9092dc337d07 (patch) | |
tree | 2259dd37b25b12fdd6a6db1738f0f2a73e71180d /libglusterfs/src/mem-pool.c | |
parent | a193f2262b93a06bf1a299f423d4ebaaa171a539 (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 'libglusterfs/src/mem-pool.c')
-rw-r--r-- | libglusterfs/src/mem-pool.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index b901dd7a862..96e04910513 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -22,29 +22,30 @@ #define is_mem_chunk_in_use(ptr) (*ptr == 1) #define mem_pool_from_ptr(ptr) ((ptr) + GF_MEM_POOL_LIST_BOUNDARY) -#define GF_MEM_HEADER_SIZE (4 + sizeof (size_t) + sizeof (xlator_t *) + 4 + 8) -#define GF_MEM_TRAILER_SIZE 8 - -#define GF_MEM_HEADER_MAGIC 0xCAFEBABE -#define GF_MEM_TRAILER_MAGIC 0xBAADF00D - #define GLUSTERFS_ENV_MEM_ACCT_STR "GLUSTERFS_DISABLE_MEM_ACCT" +#include <cmockery/pbc.h> +#include <cmockery/cmockery_override.h> + void gf_mem_acct_enable_set (void *data) { glusterfs_ctx_t *ctx = NULL; + REQUIRE(data != NULL); + ctx = data; - GF_ASSERT (ctx); + GF_ASSERT (ctx != NULL); ctx->mem_acct_enable = 1; + ENSURE(1 == ctx->mem_acct_enable); + return; } -void +int gf_mem_set_acct_info (xlator_t *xl, char **alloc_ptr, size_t size, uint32_t type) { @@ -52,7 +53,7 @@ gf_mem_set_acct_info (xlator_t *xl, char **alloc_ptr, char *ptr = NULL; if (!alloc_ptr) - return; + return -1; ptr = (char *) (*alloc_ptr); @@ -88,7 +89,7 @@ gf_mem_set_acct_info (xlator_t *xl, char **alloc_ptr, *(uint32_t *) (ptr + size) = GF_MEM_TRAILER_MAGIC; *alloc_ptr = (void *)ptr; - return; + return 0; } @@ -150,10 +151,13 @@ __gf_realloc (void *ptr, size_t size) char *orig_ptr = NULL; xlator_t *xl = NULL; uint32_t type = 0; + char *new_ptr; if (!THIS->ctx->mem_acct_enable) return REALLOC (ptr, size); + REQUIRE(NULL != ptr); + tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE; orig_ptr = (char *)ptr - 8 - 4; @@ -166,15 +170,22 @@ __gf_realloc (void *ptr, size_t size) orig_ptr = (char *)ptr - GF_MEM_HEADER_SIZE; type = *(uint32_t *)orig_ptr; - ptr = realloc (orig_ptr, tot_size); - if (!ptr) { + new_ptr = realloc (orig_ptr, tot_size); + if (!new_ptr) { gf_log_nomem ("", GF_LOG_ALERT, tot_size); return NULL; } - gf_mem_set_acct_info (xl, (char **)&ptr, size, type); + /* + * We used to pass (char **)&ptr as the second + * argument after the value of realloc was saved + * in ptr, but the compiler warnings complained + * about the casting to and forth from void ** to + * char **. + */ + gf_mem_set_acct_info (xl, &new_ptr, size, type); - return (void *)ptr; + return (void *)new_ptr; } int |