1 #include "test/jemalloc_test.h" 2 3 #include "jemalloc/internal/prof_data.h" 4 5 TEST_BEGIN(test_prof_realloc) { 6 tsd_t *tsd; 7 int flags; 8 void *p, *q; 9 prof_info_t prof_info_p, prof_info_q; 10 prof_cnt_t cnt_0, cnt_1, cnt_2, cnt_3; 11 12 test_skip_if(!config_prof); 13 14 tsd = tsd_fetch(); 15 flags = MALLOCX_TCACHE_NONE; 16 17 prof_cnt_all(&cnt_0); 18 p = mallocx(1024, flags); 19 expect_ptr_not_null(p, "Unexpected mallocx() failure"); 20 prof_info_get(tsd, p, NULL, &prof_info_p); 21 expect_ptr_ne(prof_info_p.alloc_tctx, (prof_tctx_t *)(uintptr_t)1U, 22 "Expected valid tctx"); 23 prof_cnt_all(&cnt_1); 24 expect_u64_eq(cnt_0.curobjs + 1, cnt_1.curobjs, 25 "Allocation should have increased sample size"); 26 27 q = rallocx(p, 2048, flags); 28 expect_ptr_ne(p, q, "Expected move"); 29 expect_ptr_not_null(p, "Unexpected rmallocx() failure"); 30 prof_info_get(tsd, q, NULL, &prof_info_q); 31 expect_ptr_ne(prof_info_q.alloc_tctx, (prof_tctx_t *)(uintptr_t)1U, 32 "Expected valid tctx"); 33 prof_cnt_all(&cnt_2); 34 expect_u64_eq(cnt_1.curobjs, cnt_2.curobjs, 35 "Reallocation should not have changed sample size"); 36 37 dallocx(q, flags); 38 prof_cnt_all(&cnt_3); 39 expect_u64_eq(cnt_0.curobjs, cnt_3.curobjs, 40 "Sample size should have returned to base level"); 41 } 42 TEST_END 43 44 int 45 main(void) { 46 return test_no_reentrancy( 47 test_prof_realloc); 48 } 49