prof_tctx.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "test/jemalloc_test.h"
  2. #include "jemalloc/internal/prof_data.h"
  3. TEST_BEGIN(test_prof_realloc) {
  4. tsd_t *tsd;
  5. int flags;
  6. void *p, *q;
  7. prof_info_t prof_info_p, prof_info_q;
  8. prof_cnt_t cnt_0, cnt_1, cnt_2, cnt_3;
  9. test_skip_if(!config_prof);
  10. tsd = tsd_fetch();
  11. flags = MALLOCX_TCACHE_NONE;
  12. prof_cnt_all(&cnt_0);
  13. p = mallocx(1024, flags);
  14. expect_ptr_not_null(p, "Unexpected mallocx() failure");
  15. prof_info_get(tsd, p, NULL, &prof_info_p);
  16. expect_ptr_ne(prof_info_p.alloc_tctx, (prof_tctx_t *)(uintptr_t)1U,
  17. "Expected valid tctx");
  18. prof_cnt_all(&cnt_1);
  19. expect_u64_eq(cnt_0.curobjs + 1, cnt_1.curobjs,
  20. "Allocation should have increased sample size");
  21. q = rallocx(p, 2048, flags);
  22. expect_ptr_ne(p, q, "Expected move");
  23. expect_ptr_not_null(p, "Unexpected rmallocx() failure");
  24. prof_info_get(tsd, q, NULL, &prof_info_q);
  25. expect_ptr_ne(prof_info_q.alloc_tctx, (prof_tctx_t *)(uintptr_t)1U,
  26. "Expected valid tctx");
  27. prof_cnt_all(&cnt_2);
  28. expect_u64_eq(cnt_1.curobjs, cnt_2.curobjs,
  29. "Reallocation should not have changed sample size");
  30. dallocx(q, flags);
  31. prof_cnt_all(&cnt_3);
  32. expect_u64_eq(cnt_0.curobjs, cnt_3.curobjs,
  33. "Sample size should have returned to base level");
  34. }
  35. TEST_END
  36. int
  37. main(void) {
  38. return test_no_reentrancy(
  39. test_prof_realloc);
  40. }