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