diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2023-07-15 19:57:43 +0300 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2023-07-18 18:45:25 +0300 |
commit | 938475f6de03942146c1c5220a60bd5a7a4b4ab4 (patch) | |
tree | e793168087e3190826837d2884fcf5984d3780e3 /winsup/testsuite | |
parent | 89e80d414b9d4ec71c6d43503704f7b3da3a2407 (diff) |
Cygwin: testsuite: Make cancel3 and cancel5 more robust
Despite our efforts, sometimes the async cancellation gets deferred.
Notice this by calling pthread_testcancel(), and then try to work out if
async cancellation was ever successful by checking if all threads ran
for the full expected time, or if some were stopped early.
Also, increase the time we allow for the async cancellation to get
delivered to 30 seconds.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Diffstat (limited to 'winsup/testsuite')
-rw-r--r-- | winsup/testsuite/winsup.api/pthread/cancel3.c | 18 | ||||
-rw-r--r-- | winsup/testsuite/winsup.api/pthread/cancel5.c | 18 |
2 files changed, 32 insertions, 4 deletions
diff --git a/winsup/testsuite/winsup.api/pthread/cancel3.c b/winsup/testsuite/winsup.api/pthread/cancel3.c index 07feb7c9b..8ed7d529b 100644 --- a/winsup/testsuite/winsup.api/pthread/cancel3.c +++ b/winsup/testsuite/winsup.api/pthread/cancel3.c @@ -75,9 +75,9 @@ mythread(void * arg) assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0); /* - * We wait up to 10 seconds for a cancelation to be applied to us. + * We wait up to 30 seconds for a cancelation to be applied to us. */ - for (bag->count = 0; bag->count < 10; bag->count++) + for (bag->count = 0; bag->count < 30; bag->count++) { /* Busy wait to avoid Sleep(), since we can't asynchronous cancel inside a kernel function. (This is still somewhat fragile as if the async cancel @@ -92,6 +92,9 @@ mythread(void * arg) } } + /* Notice if asynchronous cancel got deferred */ + pthread_testcancel(); + return result; } @@ -101,6 +104,7 @@ main() int failed = 0; int i; pthread_t t[NUMTHREADS + 1]; + int ran_to_completion = 0; assert((t[0] = pthread_self()) != NULL); @@ -166,9 +170,19 @@ main() threadbag[i].count, result); } + + if (threadbag[i].count >= 30) + ran_to_completion++; + failed = (failed || fail); } + if (ran_to_completion >= 10) + { + fprintf(stderr, "All threads ran to completion, async cancellation never happened\n"); + failed = 1; + } + assert(!failed); /* diff --git a/winsup/testsuite/winsup.api/pthread/cancel5.c b/winsup/testsuite/winsup.api/pthread/cancel5.c index 999b3c95c..dd5be7bea 100644 --- a/winsup/testsuite/winsup.api/pthread/cancel5.c +++ b/winsup/testsuite/winsup.api/pthread/cancel5.c @@ -76,9 +76,9 @@ mythread(void * arg) assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
/*
- * We wait up to 10 seconds for a cancelation to be applied to us.
+ * We wait up to 30 seconds for a cancelation to be applied to us.
*/
- for (bag->count = 0; bag->count < 10; bag->count++)
+ for (bag->count = 0; bag->count < 30; bag->count++)
{
/* Busy wait to avoid Sleep(), since we can't asynchronous cancel inside a
kernel function. (This is still somewhat fragile as if the async cancel
@@ -93,6 +93,9 @@ mythread(void * arg) }
}
+ /* Notice if asynchronous cancel got deferred */
+ pthread_testcancel();
+
return result;
}
@@ -102,6 +105,7 @@ main() int failed = 0;
int i;
pthread_t t[NUMTHREADS + 1];
+ int ran_to_completion = 0;
for (i = 1; i <= NUMTHREADS; i++)
{
@@ -165,9 +169,19 @@ main() threadbag[i].count,
result);
}
+
+ if (threadbag[i].count >= 30)
+ ran_to_completion++;
+
failed = (failed || fail);
}
+ if (ran_to_completion >= 10)
+ {
+ fprintf(stderr, "All threads ran to completion, async cancellation never happened\n");
+ failed = TRUE;
+ }
+
assert(!failed);
/*
|