1 #include "test/jemalloc_test.h"
2
TEST_BEGIN(test_prof_realloc)3 TEST_BEGIN(test_prof_realloc) {
4 tsdn_t *tsdn;
5 int flags;
6 void *p, *q;
7 prof_tctx_t *tctx_p, *tctx_q;
8 uint64_t curobjs_0, curobjs_1, curobjs_2, curobjs_3;
9
10 test_skip_if(!config_prof);
11
12 tsdn = tsdn_fetch();
13 flags = MALLOCX_TCACHE_NONE;
14
15 prof_cnt_all(&curobjs_0, NULL, NULL, NULL);
16 p = mallocx(1024, flags);
17 assert_ptr_not_null(p, "Unexpected mallocx() failure");
18 tctx_p = prof_tctx_get(tsdn, p, NULL);
19 assert_ptr_ne(tctx_p, (prof_tctx_t *)(uintptr_t)1U,
20 "Expected valid tctx");
21 prof_cnt_all(&curobjs_1, NULL, NULL, NULL);
22 assert_u64_eq(curobjs_0 + 1, curobjs_1,
23 "Allocation should have increased sample size");
24
25 q = rallocx(p, 2048, flags);
26 assert_ptr_ne(p, q, "Expected move");
27 assert_ptr_not_null(p, "Unexpected rmallocx() failure");
28 tctx_q = prof_tctx_get(tsdn, q, NULL);
29 assert_ptr_ne(tctx_q, (prof_tctx_t *)(uintptr_t)1U,
30 "Expected valid tctx");
31 prof_cnt_all(&curobjs_2, NULL, NULL, NULL);
32 assert_u64_eq(curobjs_1, curobjs_2,
33 "Reallocation should not have changed sample size");
34
35 dallocx(q, flags);
36 prof_cnt_all(&curobjs_3, NULL, NULL, NULL);
37 assert_u64_eq(curobjs_0, curobjs_3,
38 "Sample size should have returned to base level");
39 }
40 TEST_END
41
42 int
main(void)43 main(void) {
44 return test_no_reentrancy(
45 test_prof_realloc);
46 }
47