diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/t_fdstate.c | 12 |
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 | ||
| 105 | static _Atomic long stress_claims, stress_recycles, stress_violations, stress_attempts; | 107 | static _Atomic long stress_claims, stress_recycles, stress_violations, stress_attempts; |
| 106 | static _Atomic int stress_lives[STRESS_SLOTS]; | 108 | static _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. */ | ||
| 119 | static int stress_running(void) { | 125 | static 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 | ||
| 123 | static void *stress_worker(void *arg) { | 131 | static 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); |
