2014-01-08 08:47:56 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
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;
|
2017-01-20 13:41:41 +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);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null((void *)s, "Unexpected mallocx() failure");
|
2014-01-08 08:47:56 +08:00
|
|
|
|
|
|
|
for (sz = sallocx(s, 0); sz <= sz_max;
|
|
|
|
sz_prev = sz, sz = sallocx(s, 0)) {
|
|
|
|
if (sz_prev > 0) {
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_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);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_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++) {
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_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);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null((void *)s,
|
2014-01-08 08:47:56 +08:00
|
|
|
"Unexpected rallocx() failure");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dallocx(s, 0);
|
2016-04-05 07:55:19 +08:00
|
|
|
#undef MAGIC
|
2014-01-08 08:47:56 +08:00
|
|
|
}
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_zero_small) {
|
2014-01-08 08:47:56 +08:00
|
|
|
test_skip_if(!config_fill);
|
2018-07-12 07:05:58 +08:00
|
|
|
test_zero(1, SC_SMALL_MAXCLASS - 1);
|
2014-01-08 08:47:56 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_zero_large) {
|
2014-01-08 08:47:56 +08:00
|
|
|
test_skip_if(!config_fill);
|
2018-07-20 08:08:10 +08:00
|
|
|
test_zero(SC_SMALL_MAXCLASS + 1, 1U << (SC_LG_LARGE_MINCLASS + 1));
|
2014-01-08 08:47:56 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
2017-01-16 08:56:30 +08:00
|
|
|
main(void) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return test(
|
2014-01-08 08:47:56 +08:00
|
|
|
test_zero_small,
|
2017-01-20 10:15:45 +08:00
|
|
|
test_zero_large);
|
2014-01-08 08:47:56 +08:00
|
|
|
}
|