public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: testsuite: Make cancel3 and cancel5 more robust
@ 2023-07-18 15:47 Jon Turney
0 siblings, 0 replies; only message in thread
From: Jon Turney @ 2023-07-18 15:47 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=938475f6de03942146c1c5220a60bd5a7a4b4ab4
commit 938475f6de03942146c1c5220a60bd5a7a4b4ab4
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date: Sat Jul 15 17:57:43 2023 +0100
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>
Diff:
---
winsup/testsuite/winsup.api/pthread/cancel3.c | 18 ++++++++++++++++--
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);
/*
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-18 15:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 15:47 [newlib-cygwin] Cygwin: testsuite: Make cancel3 and cancel5 more robust Jon Turney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).