From 2812a6795149f68226e940212c511b7c625c81d5 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Wed, 28 Oct 2026 23:35:55 +0100 Subject: Fix a test that would over-report success rate when losing the race for cycles to the test target --- tests/t_fdstate.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/t_fdstate.c b/tests/t_fdstate.c index bf8724a..421f076 100644 --- a/tests/t_fdstate.c +++ b/tests/t_fdstate.c @@ -101,6 +101,8 @@ static void case_out_of_range(void) { #define RECYCLE_AFTER 32 #define STRESS_CLAIMS 200000 #define STRESS_GIVEUP (STRESS_CLAIMS * 100) +/* What the run has to reach for its result to mean anything */ +#define STRESS_CYCLES (STRESS_CLAIMS / (RECYCLE_AFTER * 4)) static _Atomic long stress_claims, stress_recycles, stress_violations, stress_attempts; static _Atomic int stress_lives[STRESS_SLOTS]; @@ -116,8 +118,14 @@ static _Atomic uint64_t stress_next_cookie; #define STRESS_CONN_COOKIE(w) ((void *)(uintptr_t)((w) >> 32)) #define STRESS_CONN_GEN(w) ((uint32_t)(w)) +/* The workers reach their claim target on their own, but the recycles that + make the run worth anything are the keeper's, and on a loaded machine the + keeper is the thread that loses. So the run goes on until both targets are + met rather than until the faster of the two is. */ static int stress_running(void) { - return atomic_load(&stress_claims) < STRESS_CLAIMS && atomic_load(&stress_attempts) < STRESS_GIVEUP; + if (atomic_load(&stress_attempts) >= STRESS_GIVEUP) + return 0; + return atomic_load(&stress_claims) < STRESS_CLAIMS || atomic_load(&stress_recycles) <= STRESS_CYCLES; } static void *stress_worker(void *arg) { @@ -203,7 +211,7 @@ static void case_recycling_under_load(void) { test_case("and the run actually recycled descriptors, or it proved nothing"); CHECK(atomic_load(&stress_claims) >= STRESS_CLAIMS); - CHECK(atomic_load(&stress_recycles) > STRESS_CLAIMS / (RECYCLE_AFTER * 4)); + CHECK(atomic_load(&stress_recycles) > STRESS_CYCLES); for (i = 0; i < STRESS_SLOTS; ++i) fdstate_close((int)i); -- cgit v1.3