1 #include "test/jemalloc_test.h" 2 3 static uint64_t 4 allocated() { 5 if (!config_stats) { 6 return 0; 7 } 8 uint64_t allocated; 9 size_t sz = sizeof(allocated); 10 expect_d_eq(mallctl("thread.allocated", (void *)&allocated, &sz, NULL, 11 0), 0, "Unexpected mallctl failure"); 12 return allocated; 13 } 14 15 static uint64_t 16 deallocated() { 17 if (!config_stats) { 18 return 0; 19 } 20 uint64_t deallocated; 21 size_t sz = sizeof(deallocated); 22 expect_d_eq(mallctl("thread.deallocated", (void *)&deallocated, &sz, 23 NULL, 0), 0, "Unexpected mallctl failure"); 24 return deallocated; 25 } 26 27 TEST_BEGIN(test_realloc_alloc) { 28 void *ptr = mallocx(1, 0); 29 expect_ptr_not_null(ptr, "Unexpected mallocx error"); 30 uint64_t allocated_before = allocated(); 31 uint64_t deallocated_before = deallocated(); 32 ptr = realloc(ptr, 0); 33 uint64_t allocated_after = allocated(); 34 uint64_t deallocated_after = deallocated(); 35 if (config_stats) { 36 expect_u64_lt(allocated_before, allocated_after, 37 "Unexpected stats change"); 38 expect_u64_lt(deallocated_before, deallocated_after, 39 "Unexpected stats change"); 40 } 41 dallocx(ptr, 0); 42 } 43 TEST_END 44 int 45 main(void) { 46 return test( 47 test_realloc_alloc); 48 } 49