blob: 2e35b7ec3a52692da09cb00abd78e6cca693756f [file] [log] [blame]
Jason Evans1ff09532017-01-16 11:09:24 -08001#include "test/jemalloc_test.h"
2
3#ifdef JEMALLOC_PROF
4const char *malloc_conf = "prof:true,lg_prof_sample:0";
5#endif
6
Jason Evansc4c25922017-01-15 16:56:30 -08007TEST_BEGIN(test_prof_realloc) {
Jason Evans1ff09532017-01-16 11:09:24 -08008 tsdn_t *tsdn;
9 int flags;
10 void *p, *q;
11 extent_t *extent_p, *extent_q;
12 prof_tctx_t *tctx_p, *tctx_q;
13 uint64_t curobjs_0, curobjs_1, curobjs_2, curobjs_3;
14
15 test_skip_if(!config_prof);
16
17 tsdn = tsdn_fetch();
18 flags = MALLOCX_TCACHE_NONE;
19
20 prof_cnt_all(&curobjs_0, NULL, NULL, NULL);
21 p = mallocx(1024, flags);
22 assert_ptr_not_null(p, "Unexpected mallocx() failure");
23 extent_p = iealloc(tsdn, p);
24 assert_ptr_not_null(extent_p, "Unexpected iealloc() failure");
25 tctx_p = prof_tctx_get(tsdn, extent_p, p);
26 assert_ptr_ne(tctx_p, (prof_tctx_t *)(uintptr_t)1U,
27 "Expected valid tctx");
28 prof_cnt_all(&curobjs_1, NULL, NULL, NULL);
29 assert_u64_eq(curobjs_0 + 1, curobjs_1,
30 "Allocation should have increased sample size");
31
32 q = rallocx(p, 2048, flags);
33 assert_ptr_ne(p, q, "Expected move");
34 assert_ptr_not_null(p, "Unexpected rmallocx() failure");
35 extent_q = iealloc(tsdn, q);
36 assert_ptr_not_null(extent_q, "Unexpected iealloc() failure");
37 tctx_q = prof_tctx_get(tsdn, extent_q, q);
38 assert_ptr_ne(tctx_q, (prof_tctx_t *)(uintptr_t)1U,
39 "Expected valid tctx");
40 prof_cnt_all(&curobjs_2, NULL, NULL, NULL);
41 assert_u64_eq(curobjs_1, curobjs_2,
42 "Reallocation should not have changed sample size");
43
44 dallocx(q, flags);
45 prof_cnt_all(&curobjs_3, NULL, NULL, NULL);
46 assert_u64_eq(curobjs_0, curobjs_3,
47 "Sample size should have returned to base level");
48}
49TEST_END
50
51int
Jason Evansc4c25922017-01-15 16:56:30 -080052main(void) {
Jason Evans1ff09532017-01-16 11:09:24 -080053 return test(
54 test_prof_realloc);
55}