aboutsummaryrefslogtreecommitdiff
path: root/test/unit/ticker.c
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2025-02-05 23:20:13 +0000
committerWarner Losh <imp@FreeBSD.org>2025-02-05 23:20:13 +0000
commit48ec896efb0b78141df004eaa21288b84590c9da (patch)
tree33799792fd95c266d472ab1ae51d50ab4f942eb3 /test/unit/ticker.c
parentd28d7fbede216494aa3942af042cc084fcd6098a (diff)
Import jemalloc 5.3.0. This import changes how manage the jemalloc vendor branch (which was just started anyway). Starting with 5.3.0, we import a clean tree from the upstream github, removing all the old files that are no longer upstream, or that we've kept around for some reason. We do this because we merge from this raw version of jemalloc into the FreeBSD contrib/jemalloc, then we run autogen stuff, generate all the generated .h files with gmake, then finally remove much of the generated files in contrib/jemalloc using an update script. Sponsored by: Netflix
Diffstat (limited to 'test/unit/ticker.c')
-rw-r--r--test/unit/ticker.c65
1 files changed, 46 insertions, 19 deletions
diff --git a/test/unit/ticker.c b/test/unit/ticker.c
index e5790a31630e..0dd778619e87 100644
--- a/test/unit/ticker.c
+++ b/test/unit/ticker.c
@@ -11,16 +11,16 @@ TEST_BEGIN(test_ticker_tick) {
ticker_init(&ticker, NTICKS);
for (i = 0; i < NREPS; i++) {
for (j = 0; j < NTICKS; j++) {
- assert_u_eq(ticker_read(&ticker), NTICKS - j,
+ expect_u_eq(ticker_read(&ticker), NTICKS - j,
"Unexpected ticker value (i=%d, j=%d)", i, j);
- assert_false(ticker_tick(&ticker),
+ expect_false(ticker_tick(&ticker),
"Unexpected ticker fire (i=%d, j=%d)", i, j);
}
- assert_u32_eq(ticker_read(&ticker), 0,
+ expect_u32_eq(ticker_read(&ticker), 0,
"Expected ticker depletion");
- assert_true(ticker_tick(&ticker),
+ expect_true(ticker_tick(&ticker),
"Expected ticker fire (i=%d)", i);
- assert_u32_eq(ticker_read(&ticker), NTICKS,
+ expect_u32_eq(ticker_read(&ticker), NTICKS,
"Expected ticker reset");
}
#undef NTICKS
@@ -33,14 +33,14 @@ TEST_BEGIN(test_ticker_ticks) {
ticker_init(&ticker, NTICKS);
- assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
- assert_false(ticker_ticks(&ticker, NTICKS), "Unexpected ticker fire");
- assert_u_eq(ticker_read(&ticker), 0, "Unexpected ticker value");
- assert_true(ticker_ticks(&ticker, NTICKS), "Expected ticker fire");
- assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
+ expect_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
+ expect_false(ticker_ticks(&ticker, NTICKS), "Unexpected ticker fire");
+ expect_u_eq(ticker_read(&ticker), 0, "Unexpected ticker value");
+ expect_true(ticker_ticks(&ticker, NTICKS), "Expected ticker fire");
+ expect_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
- assert_true(ticker_ticks(&ticker, NTICKS + 1), "Expected ticker fire");
- assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
+ expect_true(ticker_ticks(&ticker, NTICKS + 1), "Expected ticker fire");
+ expect_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
#undef NTICKS
}
TEST_END
@@ -51,23 +51,50 @@ TEST_BEGIN(test_ticker_copy) {
ticker_init(&ta, NTICKS);
ticker_copy(&tb, &ta);
- assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
- assert_true(ticker_ticks(&tb, NTICKS + 1), "Expected ticker fire");
- assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
+ expect_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
+ expect_true(ticker_ticks(&tb, NTICKS + 1), "Expected ticker fire");
+ expect_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
ticker_tick(&ta);
ticker_copy(&tb, &ta);
- assert_u_eq(ticker_read(&tb), NTICKS - 1, "Unexpected ticker value");
- assert_true(ticker_ticks(&tb, NTICKS), "Expected ticker fire");
- assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
+ expect_u_eq(ticker_read(&tb), NTICKS - 1, "Unexpected ticker value");
+ expect_true(ticker_ticks(&tb, NTICKS), "Expected ticker fire");
+ expect_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
#undef NTICKS
}
TEST_END
+TEST_BEGIN(test_ticker_geom) {
+ const int32_t ticks = 100;
+ const uint64_t niters = 100 * 1000;
+
+ ticker_geom_t ticker;
+ ticker_geom_init(&ticker, ticks);
+ uint64_t total_ticks = 0;
+ /* Just some random constant. */
+ uint64_t prng_state = 0x343219f93496db9fULL;
+ for (uint64_t i = 0; i < niters; i++) {
+ while(!ticker_geom_tick(&ticker, &prng_state)) {
+ total_ticks++;
+ }
+ }
+ /*
+ * In fact, with this choice of random seed and the PRNG implementation
+ * used at the time this was tested, total_ticks is 95.1% of the
+ * expected ticks.
+ */
+ expect_u64_ge(total_ticks , niters * ticks * 9 / 10,
+ "Mean off by > 10%%");
+ expect_u64_le(total_ticks , niters * ticks * 11 / 10,
+ "Mean off by > 10%%");
+}
+TEST_END
+
int
main(void) {
return test(
test_ticker_tick,
test_ticker_ticks,
- test_ticker_copy);
+ test_ticker_copy,
+ test_ticker_geom);
}