2014-01-08 08:47:56 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
TEST_BEGIN(test_zero_large)
|
|
|
|
{
|
|
|
|
|
|
|
|
test_skip_if(!config_fill);
|
2015-09-12 11:50:20 +08:00
|
|
|
test_zero(SMALL_MAXCLASS+1, large_maxclass);
|
2014-01-08 08:47:56 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
TEST_BEGIN(test_zero_huge)
|
|
|
|
{
|
|
|
|
|
|
|
|
test_skip_if(!config_fill);
|
2015-09-12 11:50:20 +08:00
|
|
|
test_zero(large_maxclass+1, chunksize*2);
|
2014-01-08 08:47:56 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (test(
|
|
|
|
test_zero_small,
|
|
|
|
test_zero_large,
|
|
|
|
test_zero_huge));
|
|
|
|
}
|