From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2201) id 90E6B385AF8C; Tue, 18 Jul 2023 15:47:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90E6B385AF8C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689695256; bh=brDzivxm1F4/Hi4J1NlKCwGsDGQ173OlFqDPhOI2qQo=; h=From:To:Subject:Date:From; b=P8wjbNsYz/JeT116GTR1+hVw+YOVWRbTO20djJdJYoICkvZiTzs6kBvKyFx0fXUAA HZRguus3GJk4JGjMg1ZD6ttE0W45pELYBy696cW+T1kXXYPGSnU/0Vk8gzciA/VKDI wjB3VtS0cjM7DsNjN80YRz7NHXAo8ctsQPcXyGsw= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jon Turney To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: testsuite: Make cancel3 and cancel5 more robust X-Act-Checkin: newlib-cygwin X-Git-Author: Jon Turney X-Git-Refname: refs/heads/master X-Git-Oldrev: 89e80d414b9d4ec71c6d43503704f7b3da3a2407 X-Git-Newrev: 938475f6de03942146c1c5220a60bd5a7a4b4ab4 Message-Id: <20230718154736.90E6B385AF8C@sourceware.org> Date: Tue, 18 Jul 2023 15:47:36 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D938475f6de0= 3942146c1c5220a60bd5a7a4b4ab4 commit 938475f6de03942146c1c5220a60bd5a7a4b4ab4 Author: Jon Turney Date: Sat Jul 15 17:57:43 2023 +0100 Cygwin: testsuite: Make cancel3 and cancel5 more robust =20 Despite our efforts, sometimes the async cancellation gets deferred. =20 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. =20 Also, increase the time we allow for the async cancellation to get delivered to 30 seconds. =20 Signed-off-by: Jon Turney 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/testsui= te/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) =3D=3D 0= ); =20 /* - * 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 =3D 0; bag->count < 10; bag->count++) + for (bag->count =3D 0; bag->count < 30; bag->count++) { /* Busy wait to avoid Sleep(), since we can't asynchronous cancel in= side a kernel function. (This is still somewhat fragile as if the async cancel @@ -92,6 +92,9 @@ mythread(void * arg) } } =20 + /* Notice if asynchronous cancel got deferred */ + pthread_testcancel(); + return result; } =20 @@ -101,6 +104,7 @@ main() int failed =3D 0; int i; pthread_t t[NUMTHREADS + 1]; + int ran_to_completion =3D 0; =20 assert((t[0] =3D pthread_self()) !=3D NULL); =20 @@ -166,9 +170,19 @@ main() threadbag[i].count, result); } + + if (threadbag[i].count >=3D 30) + ran_to_completion++; + failed =3D (failed || fail); } =20 + if (ran_to_completion >=3D 10) + { + fprintf(stderr, "All threads ran to completion, async cancellation n= ever happened\n"); + failed =3D 1; + } + assert(!failed); =20 /* diff --git a/winsup/testsuite/winsup.api/pthread/cancel5.c b/winsup/testsui= te/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) =3D=3D 0= ); =20 /* - * 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 =3D 0; bag->count < 10; bag->count++) + for (bag->count =3D 0; bag->count < 30; bag->count++) { /* Busy wait to avoid Sleep(), since we can't asynchronous cancel in= side a kernel function. (This is still somewhat fragile as if the async cancel @@ -93,6 +93,9 @@ mythread(void * arg) } } =20 + /* Notice if asynchronous cancel got deferred */ + pthread_testcancel(); + return result; } =20 @@ -102,6 +105,7 @@ main() int failed =3D 0; int i; pthread_t t[NUMTHREADS + 1]; + int ran_to_completion =3D 0; =20 for (i =3D 1; i <=3D NUMTHREADS; i++) { @@ -165,9 +169,19 @@ main() threadbag[i].count, result); } + + if (threadbag[i].count >=3D 30) + ran_to_completion++; + failed =3D (failed || fail); } =20 + if (ran_to_completion >=3D 10) + { + fprintf(stderr, "All threads ran to completion, async cancellation n= ever happened\n"); + failed =3D TRUE; + } + assert(!failed); =20 /*