2014-05-06 06:16:56 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
|
|
|
chunk_alloc_t *old_alloc;
|
2014-05-16 13:22:27 +08:00
|
|
|
chunk_dalloc_t *old_dalloc;
|
2014-05-06 06:16:56 +08:00
|
|
|
|
|
|
|
bool
|
2014-05-16 13:22:27 +08:00
|
|
|
chunk_dalloc(void *chunk, size_t size, unsigned arena_ind)
|
2014-05-06 06:16:56 +08:00
|
|
|
{
|
|
|
|
|
2014-05-16 13:22:27 +08:00
|
|
|
return (old_dalloc(chunk, size, arena_ind));
|
2014-05-06 06:16:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
chunk_alloc(size_t size, size_t alignment, bool *zero, unsigned arena_ind)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (old_alloc(size, alignment, zero, arena_ind));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_BEGIN(test_chunk)
|
|
|
|
{
|
|
|
|
void *p;
|
|
|
|
chunk_alloc_t *new_alloc;
|
2014-05-16 13:22:27 +08:00
|
|
|
chunk_dalloc_t *new_dalloc;
|
2014-05-06 06:16:56 +08:00
|
|
|
size_t old_size, new_size;
|
|
|
|
|
|
|
|
new_alloc = chunk_alloc;
|
2014-05-16 13:22:27 +08:00
|
|
|
new_dalloc = chunk_dalloc;
|
2014-05-06 06:16:56 +08:00
|
|
|
old_size = sizeof(chunk_alloc_t *);
|
|
|
|
new_size = sizeof(chunk_alloc_t *);
|
|
|
|
|
|
|
|
assert_d_eq(mallctl("arena.0.chunk.alloc", &old_alloc,
|
|
|
|
&old_size, &new_alloc, new_size), 0,
|
|
|
|
"Unexpected alloc error");
|
|
|
|
assert_ptr_ne(old_alloc, new_alloc,
|
|
|
|
"Unexpected alloc error");
|
2014-05-16 13:22:27 +08:00
|
|
|
assert_d_eq(mallctl("arena.0.chunk.dalloc", &old_dalloc, &old_size,
|
|
|
|
&new_dalloc, new_size), 0, "Unexpected dalloc error");
|
|
|
|
assert_ptr_ne(old_dalloc, new_dalloc, "Unexpected dalloc error");
|
2014-05-06 06:16:56 +08:00
|
|
|
|
|
|
|
p = mallocx(42, 0);
|
|
|
|
assert_ptr_ne(p, NULL, "Unexpected alloc error");
|
|
|
|
free(p);
|
|
|
|
|
|
|
|
assert_d_eq(mallctl("arena.0.chunk.alloc", NULL,
|
|
|
|
NULL, &old_alloc, old_size), 0,
|
|
|
|
"Unexpected alloc error");
|
2014-05-16 13:22:27 +08:00
|
|
|
assert_d_eq(mallctl("arena.0.chunk.dalloc", NULL, NULL, &old_dalloc,
|
|
|
|
old_size), 0, "Unexpected dalloc error");
|
2014-05-06 06:16:56 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (test(test_chunk));
|
|
|
|
}
|