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