summaryrefslogtreecommitdiff
path: root/tests/t_fdstate.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-28 23:35:55 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-28 23:35:55 +0100
commit2812a6795149f68226e940212c511b7c625c81d5 (patch)
tree4a8be645324a8d111705d35f775864df097f41a4 /tests/t_fdstate.c
parent58f76d9e91c8c29404d7990a1a876a8d61ce9448 (diff)
Fix a test that would over-report success rate when losing the race for cycles to the test target
Diffstat (limited to 'tests/t_fdstate.c')
-rw-r--r--tests/t_fdstate.c12
1 files changed, 10 insertions, 2 deletions
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) {
101#define RECYCLE_AFTER 32 101#define RECYCLE_AFTER 32
102#define STRESS_CLAIMS 200000 102#define STRESS_CLAIMS 200000
103#define STRESS_GIVEUP (STRESS_CLAIMS * 100) 103#define STRESS_GIVEUP (STRESS_CLAIMS * 100)
104/* What the run has to reach for its result to mean anything */
105#define STRESS_CYCLES (STRESS_CLAIMS / (RECYCLE_AFTER * 4))
104 106
105static _Atomic long stress_claims, stress_recycles, stress_violations, stress_attempts; 107static _Atomic long stress_claims, stress_recycles, stress_violations, stress_attempts;
106static _Atomic int stress_lives[STRESS_SLOTS]; 108static _Atomic int stress_lives[STRESS_SLOTS];
@@ -116,8 +118,14 @@ static _Atomic uint64_t stress_next_cookie;
116#define STRESS_CONN_COOKIE(w) ((void *)(uintptr_t)((w) >> 32)) 118#define STRESS_CONN_COOKIE(w) ((void *)(uintptr_t)((w) >> 32))
117#define STRESS_CONN_GEN(w) ((uint32_t)(w)) 119#define STRESS_CONN_GEN(w) ((uint32_t)(w))
118 120
121/* The workers reach their claim target on their own, but the recycles that
122 make the run worth anything are the keeper's, and on a loaded machine the
123 keeper is the thread that loses. So the run goes on until both targets are
124 met rather than until the faster of the two is. */
119static int stress_running(void) { 125static int stress_running(void) {
120 return atomic_load(&stress_claims) < STRESS_CLAIMS && atomic_load(&stress_attempts) < STRESS_GIVEUP; 126 if (atomic_load(&stress_attempts) >= STRESS_GIVEUP)
127 return 0;
128 return atomic_load(&stress_claims) < STRESS_CLAIMS || atomic_load(&stress_recycles) <= STRESS_CYCLES;
121} 129}
122 130
123static void *stress_worker(void *arg) { 131static void *stress_worker(void *arg) {
@@ -203,7 +211,7 @@ static void case_recycling_under_load(void) {
203 211
204 test_case("and the run actually recycled descriptors, or it proved nothing"); 212 test_case("and the run actually recycled descriptors, or it proved nothing");
205 CHECK(atomic_load(&stress_claims) >= STRESS_CLAIMS); 213 CHECK(atomic_load(&stress_claims) >= STRESS_CLAIMS);
206 CHECK(atomic_load(&stress_recycles) > STRESS_CLAIMS / (RECYCLE_AFTER * 4)); 214 CHECK(atomic_load(&stress_recycles) > STRESS_CYCLES);
207 215
208 for (i = 0; i < STRESS_SLOTS; ++i) 216 for (i = 0; i < STRESS_SLOTS; ++i)
209 fdstate_close((int)i); 217 fdstate_close((int)i);