2019-09-24 08:56:19 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
|
|
|
static uint64_t
|
2023-07-06 04:33:34 +08:00
|
|
|
allocated(void) {
|
2019-09-24 08:56:19 +08:00
|
|
|
if (!config_stats) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
uint64_t allocated;
|
|
|
|
size_t sz = sizeof(allocated);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(mallctl("thread.allocated", (void *)&allocated, &sz, NULL,
|
2019-09-24 08:56:19 +08:00
|
|
|
0), 0, "Unexpected mallctl failure");
|
|
|
|
return allocated;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
2023-07-06 04:33:34 +08:00
|
|
|
deallocated(void) {
|
2019-09-24 08:56:19 +08:00
|
|
|
if (!config_stats) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
uint64_t deallocated;
|
|
|
|
size_t sz = sizeof(deallocated);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(mallctl("thread.deallocated", (void *)&deallocated, &sz,
|
2019-09-24 08:56:19 +08:00
|
|
|
NULL, 0), 0, "Unexpected mallctl failure");
|
|
|
|
return deallocated;
|
|
|
|
}
|
|
|
|
|
2022-04-16 03:17:59 +08:00
|
|
|
TEST_BEGIN(test_realloc_alloc) {
|
2019-09-24 08:56:19 +08:00
|
|
|
void *ptr = mallocx(1, 0);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(ptr, "Unexpected mallocx error");
|
2019-09-24 08:56:19 +08:00
|
|
|
uint64_t allocated_before = allocated();
|
|
|
|
uint64_t deallocated_before = deallocated();
|
|
|
|
ptr = realloc(ptr, 0);
|
|
|
|
uint64_t allocated_after = allocated();
|
|
|
|
uint64_t deallocated_after = deallocated();
|
|
|
|
if (config_stats) {
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_u64_lt(allocated_before, allocated_after,
|
2019-09-24 08:56:19 +08:00
|
|
|
"Unexpected stats change");
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_u64_lt(deallocated_before, deallocated_after,
|
2019-09-24 08:56:19 +08:00
|
|
|
"Unexpected stats change");
|
|
|
|
}
|
|
|
|
dallocx(ptr, 0);
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
return test(
|
2022-04-16 03:17:59 +08:00
|
|
|
test_realloc_alloc);
|
2019-09-24 08:56:19 +08:00
|
|
|
}
|