2017-01-17 03:09:24 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_prof_realloc) {
|
2019-11-23 03:42:01 +08:00
|
|
|
tsd_t *tsd;
|
2017-01-17 03:09:24 +08:00
|
|
|
int flags;
|
|
|
|
void *p, *q;
|
2019-11-20 08:24:57 +08:00
|
|
|
prof_info_t prof_info_p, prof_info_q;
|
2017-01-17 03:09:24 +08:00
|
|
|
uint64_t curobjs_0, curobjs_1, curobjs_2, curobjs_3;
|
|
|
|
|
|
|
|
test_skip_if(!config_prof);
|
|
|
|
|
2019-11-23 03:42:01 +08:00
|
|
|
tsd = tsd_fetch();
|
2017-01-17 03:09:24 +08:00
|
|
|
flags = MALLOCX_TCACHE_NONE;
|
|
|
|
|
|
|
|
prof_cnt_all(&curobjs_0, NULL, NULL, NULL);
|
|
|
|
p = mallocx(1024, flags);
|
|
|
|
assert_ptr_not_null(p, "Unexpected mallocx() failure");
|
2019-11-23 03:42:01 +08:00
|
|
|
prof_info_get(tsd, p, NULL, &prof_info_p);
|
2019-11-20 08:24:57 +08:00
|
|
|
assert_ptr_ne(prof_info_p.prof_tctx, (prof_tctx_t *)(uintptr_t)1U,
|
2017-01-17 03:09:24 +08:00
|
|
|
"Expected valid tctx");
|
|
|
|
prof_cnt_all(&curobjs_1, NULL, NULL, NULL);
|
|
|
|
assert_u64_eq(curobjs_0 + 1, curobjs_1,
|
|
|
|
"Allocation should have increased sample size");
|
|
|
|
|
|
|
|
q = rallocx(p, 2048, flags);
|
|
|
|
assert_ptr_ne(p, q, "Expected move");
|
|
|
|
assert_ptr_not_null(p, "Unexpected rmallocx() failure");
|
2019-11-23 03:42:01 +08:00
|
|
|
prof_info_get(tsd, q, NULL, &prof_info_q);
|
2019-11-20 08:24:57 +08:00
|
|
|
assert_ptr_ne(prof_info_q.prof_tctx, (prof_tctx_t *)(uintptr_t)1U,
|
2017-01-17 03:09:24 +08:00
|
|
|
"Expected valid tctx");
|
|
|
|
prof_cnt_all(&curobjs_2, NULL, NULL, NULL);
|
|
|
|
assert_u64_eq(curobjs_1, curobjs_2,
|
|
|
|
"Reallocation should not have changed sample size");
|
|
|
|
|
|
|
|
dallocx(q, flags);
|
|
|
|
prof_cnt_all(&curobjs_3, NULL, NULL, NULL);
|
|
|
|
assert_u64_eq(curobjs_0, curobjs_3,
|
|
|
|
"Sample size should have returned to base level");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
2017-01-16 08:56:30 +08:00
|
|
|
main(void) {
|
2017-03-29 08:30:54 +08:00
|
|
|
return test_no_reentrancy(
|
2017-01-17 03:09:24 +08:00
|
|
|
test_prof_realloc);
|
|
|
|
}
|