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