From c817c214033481fe59f9f44c325a9092dc337d07 Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Thu, 20 Feb 2014 13:50:19 -0500 Subject: 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 Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/7145 Tested-by: Gluster Build System Reviewed-by: Rajesh Joseph Reviewed-by: Justin Clift Tested-by: Justin Clift --- libglusterfs/src/mem-pool.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'libglusterfs/src/mem-pool.c') diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index b901dd7a8..96e049105 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 +#include + 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 -- cgit