2014-01-08 08:47:56 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
|
|
|
#ifdef JEMALLOC_FILL
|
|
|
|
const char *malloc_conf =
|
2016-04-06 09:18:15 +08:00
|
|
|
"abort:false,junk:false,zero:true";
|
2014-01-08 08:47:56 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_zero(size_t sz_min, size_t sz_max)
|
|
|
|
{
|
2016-04-05 07:55:19 +08:00
|
|
|
uint8_t *s;
|
2014-01-08 08:47:56 +08:00
|
|
|
size_t sz_prev, sz, i;
|
2016-04-05 07:55:19 +08:00
|
|
|
#define MAGIC ((uint8_t)0x61)
|
2014-01-08 08:47:56 +08:00
|
|
|
|
|
|
|
sz_prev = 0;
|
2016-04-05 07:55:19 +08:00
|
|
|
s = (uint8_t *)mallocx(sz_min, 0);
|
2014-01-08 08:47:56 +08:00
|
|
|
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) {
|
2016-04-05 07:55:19 +08:00
|
|
|
assert_u_eq(s[0], MAGIC,
|
2014-01-08 08:47:56 +08:00
|
|
|
"Previously allocated byte %zu/%zu is corrupted",
|
2014-03-31 02:21:09 +08:00
|
|
|
ZU(0), sz_prev);
|
2016-04-05 07:55:19 +08:00
|
|
|
assert_u_eq(s[sz_prev-1], MAGIC,
|
2014-01-08 08:47:56 +08:00
|
|
|
"Previously allocated byte %zu/%zu is corrupted",
|
|
|
|
sz_prev-1, sz_prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = sz_prev; i < sz; i++) {
|
2016-04-05 07:55:19 +08:00
|
|
|
assert_u_eq(s[i], 0x0,
|
2014-01-08 08:47:56 +08:00
|
|
|
"Newly allocated byte %zu/%zu isn't zero-filled",
|
|
|
|
i, sz);
|
2016-04-05 07:55:19 +08:00
|
|
|
s[i] = MAGIC;
|
2014-01-08 08:47:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (xallocx(s, sz+1, 0, 0) == sz) {
|
2016-04-05 07:55:19 +08:00
|
|
|
s = (uint8_t *)rallocx(s, sz+1, 0);
|
2014-01-08 08:47:56 +08:00
|
|
|
assert_ptr_not_null((void *)s,
|
|
|
|
"Unexpected rallocx() failure");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dallocx(s, 0);
|
2016-04-05 07:55:19 +08:00
|
|
|
#undef MAGIC
|
2014-01-08 08:47:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_BEGIN(test_zero_small)
|
|
|
|
{
|
|
|
|
|
|
|
|
test_skip_if(!config_fill);
|
|
|
|
test_zero(1, SMALL_MAXCLASS-1);
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2016-06-01 05:50:21 +08:00
|
|
|
TEST_BEGIN(test_zero_large)
|
2014-01-08 08:47:56 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
test_skip_if(!config_fill);
|
2016-10-13 02:49:19 +08:00
|
|
|
test_zero(SMALL_MAXCLASS+1, (1U << (LG_LARGE_MINCLASS+1)));
|
2014-01-08 08:47:56 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (test(
|
|
|
|
test_zero_small,
|
2016-06-01 05:50:21 +08:00
|
|
|
test_zero_large));
|
2014-01-08 08:47:56 +08:00
|
|
|
}
|