Commit 77d72e0c authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#4275 dont use malloc hook in newbrt tests closes[t:4275]

git-svn-id: file:///svn/toku/tokudb@38466 c7de825b-a66e-492c-adef-691d508d4ae1
parent 31969ce4
...@@ -27,25 +27,16 @@ static inline void test_mutex_unlock(void) { ...@@ -27,25 +27,16 @@ static inline void test_mutex_unlock(void) {
int r = toku_pthread_mutex_unlock(&test_mutex); assert(r == 0); int r = toku_pthread_mutex_unlock(&test_mutex); assert(r == 0);
} }
// hook my_malloc_always_fails into malloc to control malloc and verify static void *my_malloc_always_fails(size_t n UU()) {
// the correct recovery from malloc failures errno = ENOMEM;
#if defined(__linux__) return NULL;
#define DO_MALLOC_HOOK 1
#else
#define DO_MALLOC_HOOK 0
#endif
#if DO_MALLOC_HOOK
static void *my_malloc_always_fails(size_t n, const __malloc_ptr_t p) {
n = n; p = p;
return 0;
} }
#endif
// verify that cachetable creation and close works // verify that cachetable creation and close works
static void static void
test_cachetable_create(void) { test_cachetable_create(void) {
CACHETABLE ct = 0; CACHETABLE ct = NULL;
int r; int r;
r = toku_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); r = toku_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r == 0); assert(r == 0);
...@@ -54,21 +45,16 @@ test_cachetable_create(void) { ...@@ -54,21 +45,16 @@ test_cachetable_create(void) {
} }
// verify that cachetable create with no memory returns ENOMEM // verify that cachetable create with no memory returns ENOMEM
#if DO_MALLOC_HOOK
static void static void
test_cachetable_create_no_memory (void) { test_cachetable_create_no_memory (void) {
void *(*orig_malloc_hook)(size_t, const __malloc_ptr_t) = __malloc_hook; toku_set_func_malloc(my_malloc_always_fails);
__malloc_hook = my_malloc_always_fails; CACHETABLE ct = NULL;
CACHETABLE ct = 0;
int r; int r;
r = toku_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); r = toku_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER);
assert(r == ENOMEM); assert(r == ENOMEM);
__malloc_hook = orig_malloc_hook; toku_set_func_malloc(NULL);
} }
#endif
static const int test_object_size = 1; static const int test_object_size = 1;
struct item { struct item {
...@@ -715,12 +701,9 @@ static void test_size_flush(void) { ...@@ -715,12 +701,9 @@ static void test_size_flush(void) {
int int
test_main (int argc, const char *argv[]) { test_main (int argc, const char *argv[]) {
// defaults // defaults
#if defined(__linux__)
int do_malloc_fail = 0; int do_malloc_fail = 0;
#endif
// parse args // parse args
default_parse_args(argc, argv);
int i; int i;
for (i=1; i<argc; i++) { for (i=1; i<argc; i++) {
const char *arg = argv[i]; const char *arg = argv[i];
...@@ -728,12 +711,14 @@ test_main (int argc, const char *argv[]) { ...@@ -728,12 +711,14 @@ test_main (int argc, const char *argv[]) {
verbose++; verbose++;
continue; continue;
} }
#if defined(__linux__) if (strcmp(arg, "-q") == 0) {
if (verbose > 0) verbose--;
continue;
}
if (strcmp(arg, "-malloc-fail") == 0) { if (strcmp(arg, "-malloc-fail") == 0) {
do_malloc_fail = 1; do_malloc_fail = 1;
continue; continue;
} }
#endif
} }
test_mutex_init(); test_mutex_init();
...@@ -743,10 +728,8 @@ test_main (int argc, const char *argv[]) { ...@@ -743,10 +728,8 @@ test_main (int argc, const char *argv[]) {
test_multi_filehandles(); test_multi_filehandles();
#endif #endif
test_cachetable_create(); test_cachetable_create();
#if DO_MALLOC_HOOK
if (do_malloc_fail) if (do_malloc_fail)
test_cachetable_create_no_memory(); // fails with valgrind test_cachetable_create_no_memory(); // fails with valgrind
#endif
for (i=0; i<1; i++) { for (i=0; i<1; i++) {
test0(); test0();
test_nested_pin(); test_nested_pin();
......
...@@ -65,17 +65,10 @@ my_thread_f (void *arg) { ...@@ -65,17 +65,10 @@ my_thread_f (void *arg) {
return arg; return arg;
} }
#if defined(__linux__) static void *my_malloc_always_fails(size_t n UU()) {
#define DO_MALLOC_HOOK 1 errno = ENOMEM;
#else return NULL;
#define DO_MALLOC_HOOK 0
#endif
#if DO_MALLOC_HOOK
static void *my_malloc_always_fails(size_t n, const __malloc_ptr_t p) {
n = n; p = p;
return 0;
} }
#endif
static int static int
usage (void) { usage (void) {
...@@ -126,21 +119,17 @@ test_main (int argc, const char *argv[]) { ...@@ -126,21 +119,17 @@ test_main (int argc, const char *argv[]) {
assert(toku_thread_pool_get_current_threads(threadpool) == max_threads); assert(toku_thread_pool_get_current_threads(threadpool) == max_threads);
my_threadpool_destroy(&my_threadpool, max_threads); my_threadpool_destroy(&my_threadpool, max_threads);
#if DO_MALLOC_HOOK
if (do_malloc_fail) { if (do_malloc_fail) {
if (verbose) printf("test threadpool_create with malloc failure\n"); if (verbose) printf("test threadpool_create with malloc failure\n");
// test threadpool malloc fails causes ENOMEM // test threadpool malloc fails causes ENOMEM
// glibc supports this. see malloc.h
threadpool = 0;
void *(*orig_malloc_hook) (size_t, const __malloc_ptr_t) = __malloc_hook; toku_set_func_malloc(my_malloc_always_fails);
__malloc_hook = my_malloc_always_fails;
int r; int r;
threadpool = NULL;
r = toku_thread_pool_create(&threadpool, 0); assert(r == ENOMEM); r = toku_thread_pool_create(&threadpool, 0); assert(r == ENOMEM);
r = toku_thread_pool_create(&threadpool, 1); assert(r == ENOMEM); r = toku_thread_pool_create(&threadpool, 1); assert(r == ENOMEM);
__malloc_hook = orig_malloc_hook; toku_set_func_malloc(NULL);
} }
#endif
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment