Skip to content
Snippets Groups Projects
Commit 3c309cdf authored by Dominik Loidolt's avatar Dominik Loidolt
Browse files

Fix mock of malloc function in test_cmp_max_used_bits_list.c

parent dac800fc
No related branches found
No related tags found
1 merge request!30Enhanced Error Handling in Chunk Compression Functions
...@@ -17,22 +17,28 @@ ...@@ -17,22 +17,28 @@
*/ */
#if !defined(__sparc__) && !defined(_WIN32) && !defined(_WIN64)
# define MAKE_MALLOC_FAIL_TEST
# define _GNU_SOURCE
# include <dlfcn.h>
# include <stdlib.h>
#endif
#include <string.h> #include <string.h>
#include <unity.h> #include <unity.h>
#include <cmp_max_used_bits_list.h> #include <cmp_max_used_bits_list.h>
#ifndef __sparc__ #ifdef MAKE_MALLOC_FAIL_TEST
/* if set the mock malloc will fail (return NULL) */ /* if set the mock malloc will fail (return NULL) */
static int malloc_fail; static int malloc_fail;
/* /*
* mock of the malloc function; can controlled with the global malloc_fail variable * mock of the malloc function; can controlled with the global malloc_fail variable
* see:https://jayconrod.com/posts/23/tutorial--function-interposition-in-linux * see: https://jayconrod.com/posts/23/tutorial--function-interposition-in-linux
*/ */
#include <dlfcn.h>
void* malloc(size_t size) void* malloc(size_t size)
{ {
...@@ -47,7 +53,6 @@ void* malloc(size_t size) ...@@ -47,7 +53,6 @@ void* malloc(size_t size)
TEST_ASSERT_NOT_NULL(real_malloc); TEST_ASSERT_NOT_NULL(real_malloc);
} }
fprintf(stderr, "malloc(%zu)\n", size);
return real_malloc(size); return real_malloc(size);
} }
#endif #endif
...@@ -181,7 +186,7 @@ void test_cmp_max_used_bits_list(void) ...@@ -181,7 +186,7 @@ void test_cmp_max_used_bits_list(void)
cmp_max_used_bits_list_empty(); cmp_max_used_bits_list_empty();
/* error case */ /* error case */
#ifndef __sparc__ #ifdef MAKE_MALLOC_FAIL_TEST
malloc_fail = 1; malloc_fail = 1;
return_val = cmp_max_used_bits_list_add(&i_36); return_val = cmp_max_used_bits_list_add(&i_36);
TEST_ASSERT_EQUAL_INT(return_val, -1); TEST_ASSERT_EQUAL_INT(return_val, -1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment