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