"Fossies" - the Fresh Open Source Software Archive

Member "redis-5.0.7/deps/jemalloc/test/unit/ticker.c" (19 Nov 2019, 2042 Bytes) of package /linux/misc/redis-5.0.7.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include "test/jemalloc_test.h"
    2 
    3 #include "jemalloc/internal/ticker.h"
    4 
    5 TEST_BEGIN(test_ticker_tick) {
    6 #define NREPS 2
    7 #define NTICKS 3
    8     ticker_t ticker;
    9     int32_t i, j;
   10 
   11     ticker_init(&ticker, NTICKS);
   12     for (i = 0; i < NREPS; i++) {
   13         for (j = 0; j < NTICKS; j++) {
   14             assert_u_eq(ticker_read(&ticker), NTICKS - j,
   15                 "Unexpected ticker value (i=%d, j=%d)", i, j);
   16             assert_false(ticker_tick(&ticker),
   17                 "Unexpected ticker fire (i=%d, j=%d)", i, j);
   18         }
   19         assert_u32_eq(ticker_read(&ticker), 0,
   20             "Expected ticker depletion");
   21         assert_true(ticker_tick(&ticker),
   22             "Expected ticker fire (i=%d)", i);
   23         assert_u32_eq(ticker_read(&ticker), NTICKS,
   24             "Expected ticker reset");
   25     }
   26 #undef NTICKS
   27 }
   28 TEST_END
   29 
   30 TEST_BEGIN(test_ticker_ticks) {
   31 #define NTICKS 3
   32     ticker_t ticker;
   33 
   34     ticker_init(&ticker, NTICKS);
   35 
   36     assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
   37     assert_false(ticker_ticks(&ticker, NTICKS), "Unexpected ticker fire");
   38     assert_u_eq(ticker_read(&ticker), 0, "Unexpected ticker value");
   39     assert_true(ticker_ticks(&ticker, NTICKS), "Expected ticker fire");
   40     assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
   41 
   42     assert_true(ticker_ticks(&ticker, NTICKS + 1), "Expected ticker fire");
   43     assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
   44 #undef NTICKS
   45 }
   46 TEST_END
   47 
   48 TEST_BEGIN(test_ticker_copy) {
   49 #define NTICKS 3
   50     ticker_t ta, tb;
   51 
   52     ticker_init(&ta, NTICKS);
   53     ticker_copy(&tb, &ta);
   54     assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
   55     assert_true(ticker_ticks(&tb, NTICKS + 1), "Expected ticker fire");
   56     assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
   57 
   58     ticker_tick(&ta);
   59     ticker_copy(&tb, &ta);
   60     assert_u_eq(ticker_read(&tb), NTICKS - 1, "Unexpected ticker value");
   61     assert_true(ticker_ticks(&tb, NTICKS), "Expected ticker fire");
   62     assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
   63 #undef NTICKS
   64 }
   65 TEST_END
   66 
   67 int
   68 main(void) {
   69     return test(
   70         test_ticker_tick,
   71         test_ticker_ticks,
   72         test_ticker_copy);
   73 }