peak.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "test/jemalloc_test.h"
  2. #include "jemalloc/internal/peak.h"
  3. TEST_BEGIN(test_peak) {
  4. peak_t peak = PEAK_INITIALIZER;
  5. expect_u64_eq(0, peak_max(&peak),
  6. "Peak should be zero at initialization");
  7. peak_update(&peak, 100, 50);
  8. expect_u64_eq(50, peak_max(&peak),
  9. "Missed update");
  10. peak_update(&peak, 100, 100);
  11. expect_u64_eq(50, peak_max(&peak), "Dallocs shouldn't change peak");
  12. peak_update(&peak, 100, 200);
  13. expect_u64_eq(50, peak_max(&peak), "Dallocs shouldn't change peak");
  14. peak_update(&peak, 200, 200);
  15. expect_u64_eq(50, peak_max(&peak), "Haven't reached peak again");
  16. peak_update(&peak, 300, 200);
  17. expect_u64_eq(100, peak_max(&peak), "Missed an update.");
  18. peak_set_zero(&peak, 300, 200);
  19. expect_u64_eq(0, peak_max(&peak), "No effect from zeroing");
  20. peak_update(&peak, 300, 300);
  21. expect_u64_eq(0, peak_max(&peak), "Dalloc shouldn't change peak");
  22. peak_update(&peak, 400, 300);
  23. expect_u64_eq(0, peak_max(&peak), "Should still be net negative");
  24. peak_update(&peak, 500, 300);
  25. expect_u64_eq(100, peak_max(&peak), "Missed an update.");
  26. /*
  27. * Above, we set to zero while a net allocator; let's try as a
  28. * net-deallocator.
  29. */
  30. peak_set_zero(&peak, 600, 700);
  31. expect_u64_eq(0, peak_max(&peak), "No effect from zeroing.");
  32. peak_update(&peak, 600, 800);
  33. expect_u64_eq(0, peak_max(&peak), "Dalloc shouldn't change peak.");
  34. peak_update(&peak, 700, 800);
  35. expect_u64_eq(0, peak_max(&peak), "Should still be net negative.");
  36. peak_update(&peak, 800, 800);
  37. expect_u64_eq(100, peak_max(&peak), "Missed an update.");
  38. }
  39. TEST_END
  40. int
  41. main(void) {
  42. return test_no_reentrancy(
  43. test_peak);
  44. }