public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jon Turney <jturney@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: testsuite: Make cancel3 and cancel5 more robust
Date: Tue, 18 Jul 2023 15:47:36 +0000 (GMT)	[thread overview]
Message-ID: <20230718154736.90E6B385AF8C@sourceware.org> (raw)

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);
 
   /*

                 reply	other threads:[~2023-07-18 15:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230718154736.90E6B385AF8C@sourceware.org \
    --to=jturney@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).