mirror of
https://github.com/MariaDB/server.git
synced 2025-01-23 15:24:16 +01:00
Addresses #288
Exercise buffer increase and decrease. git-svn-id: file:///svn/tokudb@1910 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
460b31fd67
commit
136b3161bb
1 changed files with 76 additions and 0 deletions
76
src/range_tree/tests/test_00025_memalloc.c
Normal file
76
src/range_tree/tests/test_00025_memalloc.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* We are going to test whether we can manage memory once we do lots of
|
||||
insert and delete. */
|
||||
|
||||
#include "test.h"
|
||||
|
||||
unsigned malloc_cnt;
|
||||
unsigned malloc_cntl;
|
||||
|
||||
/* Controllable malloc failure: it fails only the ith time it is invoked */
|
||||
static void* malloc_fail(size_t size) {
|
||||
if (malloc_cntl == ++malloc_cnt) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
} else
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int i, j;
|
||||
int r;
|
||||
toku_range_tree *tree;
|
||||
toku_range range;
|
||||
int nums[1024];
|
||||
char letters[2] = {'A','B'};
|
||||
|
||||
for (i = 0; i < 1024; i++)
|
||||
nums[i] = i;
|
||||
|
||||
parse_args(argc, argv);
|
||||
|
||||
/* Insert and delete lots of ranges to force memory increase and decrease */
|
||||
|
||||
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE, malloc, free, realloc);
|
||||
CKERR(r);
|
||||
|
||||
/* Insert lots of ranges */
|
||||
for (i = 0; i < 512; i++) {
|
||||
j = i + i;
|
||||
range.left = &nums[j];
|
||||
range.right = &nums[j+1];
|
||||
range.data = &letters[0];
|
||||
r = toku_rt_insert(tree, &range); CKERR(r);
|
||||
}
|
||||
|
||||
/* Decrease lots of ranges */
|
||||
for (i = 0; i < 512; i++) {
|
||||
j = i + i;
|
||||
range.left = &nums[j];
|
||||
range.right = &nums[j+1];
|
||||
range.data = &letters[0];
|
||||
r = toku_rt_delete(tree, &range); CKERR(r);
|
||||
}
|
||||
|
||||
r = toku_rt_close(tree); CKERR(r);
|
||||
|
||||
tree = NULL;
|
||||
|
||||
|
||||
/* Force malloc to fail */
|
||||
|
||||
/* Failure when allocating the tree */
|
||||
malloc_cnt = 0;
|
||||
malloc_cntl = 1;
|
||||
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE, malloc_fail, free,
|
||||
realloc);
|
||||
CKERR2(r, ENOMEM);
|
||||
|
||||
/* Failure when allocating the tree ranges */
|
||||
malloc_cnt = 0;
|
||||
malloc_cntl = 2;
|
||||
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE, malloc_fail, free,
|
||||
realloc);
|
||||
CKERR2(r, ENOMEM);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue