2
0

prof_tctx.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "test/jemalloc_test.h"
  2. TEST_BEGIN(test_prof_realloc) {
  3. tsdn_t *tsdn;
  4. int flags;
  5. void *p, *q;
  6. prof_tctx_t *tctx_p, *tctx_q;
  7. uint64_t curobjs_0, curobjs_1, curobjs_2, curobjs_3;
  8. test_skip_if(!config_prof);
  9. tsdn = tsdn_fetch();
  10. flags = MALLOCX_TCACHE_NONE;
  11. prof_cnt_all(&curobjs_0, NULL, NULL, NULL);
  12. p = mallocx(1024, flags);
  13. assert_ptr_not_null(p, "Unexpected mallocx() failure");
  14. tctx_p = prof_tctx_get(tsdn, p, NULL);
  15. assert_ptr_ne(tctx_p, (prof_tctx_t *)(uintptr_t)1U,
  16. "Expected valid tctx");
  17. prof_cnt_all(&curobjs_1, NULL, NULL, NULL);
  18. assert_u64_eq(curobjs_0 + 1, curobjs_1,
  19. "Allocation should have increased sample size");
  20. q = rallocx(p, 2048, flags);
  21. assert_ptr_ne(p, q, "Expected move");
  22. assert_ptr_not_null(p, "Unexpected rmallocx() failure");
  23. tctx_q = prof_tctx_get(tsdn, q, NULL);
  24. assert_ptr_ne(tctx_q, (prof_tctx_t *)(uintptr_t)1U,
  25. "Expected valid tctx");
  26. prof_cnt_all(&curobjs_2, NULL, NULL, NULL);
  27. assert_u64_eq(curobjs_1, curobjs_2,
  28. "Reallocation should not have changed sample size");
  29. dallocx(q, flags);
  30. prof_cnt_all(&curobjs_3, NULL, NULL, NULL);
  31. assert_u64_eq(curobjs_0, curobjs_3,
  32. "Sample size should have returned to base level");
  33. }
  34. TEST_END
  35. int
  36. main(void) {
  37. return test_no_reentrancy(
  38. test_prof_realloc);
  39. }