diff options
author | Jason Evans <jasone@canonware.com> | 2014-01-22 19:11:22 (GMT) |
---|---|---|
committer | Jason Evans <jasone@canonware.com> | 2014-01-22 19:11:22 (GMT) |
commit | cc47dde16203a6ae7eb685b53e1ae501f3869bc6 (patch) | |
tree | 74e81d65651b2ca7e294a857797dda6635177454 /test/unit/zero.c | |
parent | 0135fb806e4137dc9cdf152541926a2bc95e33f0 (diff) | |
parent | 798a48103014aabf8afb3d7efff90399a466dd8c (diff) | |
download | jemalloc-cc47dde16203a6ae7eb685b53e1ae501f3869bc6.zip jemalloc-cc47dde16203a6ae7eb685b53e1ae501f3869bc6.tar.gz jemalloc-cc47dde16203a6ae7eb685b53e1ae501f3869bc6.tar.bz2 |
Merge branch 'dev'3.5.0
Diffstat (limited to 'test/unit/zero.c')
-rw-r--r-- | test/unit/zero.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/unit/zero.c b/test/unit/zero.c new file mode 100644 index 0000000..2fdae2f --- /dev/null +++ b/test/unit/zero.c @@ -0,0 +1,78 @@ +#include "test/jemalloc_test.h" + +#ifdef JEMALLOC_FILL +const char *malloc_conf = + "abort:false,junk:false,zero:true,redzone:false,quarantine:0"; +#endif + +static void +test_zero(size_t sz_min, size_t sz_max) +{ + char *s; + size_t sz_prev, sz, i; + + sz_prev = 0; + s = (char *)mallocx(sz_min, 0); + assert_ptr_not_null((void *)s, "Unexpected mallocx() failure"); + + for (sz = sallocx(s, 0); sz <= sz_max; + sz_prev = sz, sz = sallocx(s, 0)) { + if (sz_prev > 0) { + assert_c_eq(s[0], 'a', + "Previously allocated byte %zu/%zu is corrupted", + 0, sz_prev); + assert_c_eq(s[sz_prev-1], 'a', + "Previously allocated byte %zu/%zu is corrupted", + sz_prev-1, sz_prev); + } + + for (i = sz_prev; i < sz; i++) { + assert_c_eq(s[i], 0x0, + "Newly allocated byte %zu/%zu isn't zero-filled", + i, sz); + s[i] = 'a'; + } + + if (xallocx(s, sz+1, 0, 0) == sz) { + s = (char *)rallocx(s, sz+1, 0); + assert_ptr_not_null((void *)s, + "Unexpected rallocx() failure"); + } + } + + dallocx(s, 0); +} + +TEST_BEGIN(test_zero_small) +{ + + test_skip_if(!config_fill); + test_zero(1, SMALL_MAXCLASS-1); +} +TEST_END + +TEST_BEGIN(test_zero_large) +{ + + test_skip_if(!config_fill); + test_zero(SMALL_MAXCLASS+1, arena_maxclass); +} +TEST_END + +TEST_BEGIN(test_zero_huge) +{ + + test_skip_if(!config_fill); + test_zero(arena_maxclass+1, chunksize*2); +} +TEST_END + +int +main(void) +{ + + return (test( + test_zero_small, + test_zero_large, + test_zero_huge)); +} |