From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2201) id B9BE63857C4F; Sun, 9 Jul 2023 16:01:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9BE63857C4F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688918504; bh=OOk+VxV3loJRdQfpQ6EkwLAaSKopDFxFbIChIS00f08=; h=From:To:Subject:Date:From; b=vVNOU2KeQDkubUHOGupzIP8EEgePDcKQJSeIIYoifYUfkwx530eMWJqUIXHb5yzEt Tf1vSrjbU/SLPDDf8RP3vV6WT7IiK6JHIHA0ZwClURWsttZT3dCL7a0/FgiuDlhIlR LgtxKmMQcTaUH9WlMr7E6JQA0fmxiw855mE3n8j8= 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: Fix for limited thread priority values X-Act-Checkin: newlib-cygwin X-Git-Author: Jon Turney X-Git-Refname: refs/heads/master X-Git-Oldrev: 062e62638c71c228fe56aa1228d8bbfeaa8ec140 X-Git-Newrev: 7fcb2cd4a17bd5e07e104f8c82e403c25847c053 Message-Id: <20230709160144.B9BE63857C4F@sourceware.org> Date: Sun, 9 Jul 2023 16:01:44 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D7fcb2cd4a17= bd5e07e104f8c82e403c25847c053 commit 7fcb2cd4a17bd5e07e104f8c82e403c25847c053 Author: Jon Turney Date: Thu Sep 1 12:13:50 2022 +0100 Cygwin: testsuite: Fix for limited thread priority values =20 Windows only supports 7 thread priority levels, which we map onto the 32 required by POSIX. So, only a subset of values will be returned exactly by by +pthread_getschedparam() after pthread_setschedparam(). =20 Adjust tests priority1, priority2 and inherit1 so the only check for round-tripping priority values which can be exactly represented. =20 Future work: Check we provide the 32 levels required by POSIX. Diff: --- winsup/testsuite/winsup.api/pthread/inherit1.c | 12 +++++++++++- winsup/testsuite/winsup.api/pthread/priority1.c | 16 ++++++++++++++-- winsup/testsuite/winsup.api/pthread/priority2.c | 16 ++++++++++++++-- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/winsup/testsuite/winsup.api/pthread/inherit1.c b/winsup/testsu= ite/winsup.api/pthread/inherit1.c index 16c3f534b..e77483e89 100644 --- a/winsup/testsuite/winsup.api/pthread/inherit1.c +++ b/winsup/testsuite/winsup.api/pthread/inherit1.c @@ -50,6 +50,15 @@ void * func(void * arg) return (void *) (size_t)param.sched_priority; } =20 +// Windows only supports 7 thread priority levels, which we map onto the 32 +// required by POSIX. So only a subset of values will be returned exactly= by by +// pthread_getschedparam() after pthread_setschedparam(). +int doable_pri(int pri) +{ + return (pri =3D=3D 2) || (pri =3D=3D 12) || (pri =3D=3D 14) || (pri =3D= =3D 16) || (pri =3D=3D 18) + || (pri =3D=3D 20) || (pri =3D=3D 30); +} + int main() { @@ -81,7 +90,8 @@ main() assert(pthread_setschedparam(mainThread, SCHED_FIFO, &mainParam) =3D= =3D 0); assert(pthread_getschedparam(mainThread, &policy, &mainParam) =3D=3D= 0); assert(policy =3D=3D SCHED_FIFO); - assert(mainParam.sched_priority =3D=3D prio); + if (doable_pri(prio)) + assert(mainParam.sched_priority =3D=3D prio); =20 for (param.sched_priority =3D prio; param.sched_priority <=3D maxPrio; diff --git a/winsup/testsuite/winsup.api/pthread/priority1.c b/winsup/tests= uite/winsup.api/pthread/priority1.c index a1e8d051d..4ce3e389c 100644 --- a/winsup/testsuite/winsup.api/pthread/priority1.c +++ b/winsup/testsuite/winsup.api/pthread/priority1.c @@ -50,7 +50,16 @@ void * func(void * arg) assert(policy =3D=3D SCHED_FIFO); return (void *)(size_t)param.sched_priority; } -=20 + +// Windows only supports 7 thread priority levels, which we map onto the 32 +// required by POSIX. So only a subset of values will be returned exactly= by by +// pthread_getschedparam() after pthread_setschedparam(). +int doable_pri(int pri) +{ + return (pri =3D=3D 2) || (pri =3D=3D 12) || (pri =3D=3D 14) || (pri =3D= =3D 16) || (pri =3D=3D 18) + || (pri =3D=3D 20) || (pri =3D=3D 30); +} + int main() { @@ -61,6 +70,8 @@ main() int maxPrio =3D sched_get_priority_max(SCHED_FIFO); int minPrio =3D sched_get_priority_min(SCHED_FIFO); =20 + // assert((maxPrio - minPrio) >=3D 32); + assert(pthread_attr_init(&attr) =3D=3D 0); assert(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) =3D= =3D 0); =20 @@ -71,7 +82,8 @@ main() assert(pthread_attr_setschedparam(&attr, ¶m) =3D=3D 0); assert(pthread_create(&t, &attr, func, NULL) =3D=3D 0); pthread_join(t, &result); - assert((int)(size_t) result =3D=3D param.sched_priority); + if (doable_pri(param.sched_priority)) + assert((int)(size_t) result =3D=3D param.sched_priority); } =20 return 0; diff --git a/winsup/testsuite/winsup.api/pthread/priority2.c b/winsup/tests= uite/winsup.api/pthread/priority2.c index 0534e7ba1..dec2827f8 100644 --- a/winsup/testsuite/winsup.api/pthread/priority2.c +++ b/winsup/testsuite/winsup.api/pthread/priority2.c @@ -54,7 +54,16 @@ void * func(void * arg) assert(policy =3D=3D SCHED_FIFO); return (void *) (size_t)param.sched_priority; } -=20 + +// Windows only supports 7 thread priority levels, which we map onto the 32 +// required by POSIX. So only a subset of values will be returned exactly= by by +// pthread_getschedparam() after pthread_setschedparam(). +int doable_pri(int pri) +{ + return (pri =3D=3D 2) || (pri =3D=3D 12) || (pri =3D=3D 14) || (pri =3D= =3D 16) || (pri =3D=3D 18) + || (pri =3D=3D 20) || (pri =3D=3D 30); +} + int main() { @@ -64,6 +73,8 @@ main() int maxPrio =3D sched_get_priority_max(SCHED_FIFO); int minPrio =3D sched_get_priority_min(SCHED_FIFO); =20 + // assert((maxPrio - minPrio) >=3D 32); + for (param.sched_priority =3D minPrio; param.sched_priority <=3D maxPrio; param.sched_priority++) @@ -73,7 +84,8 @@ main() assert(pthread_setschedparam(t, SCHED_FIFO, ¶m) =3D=3D 0); assert(pthread_mutex_unlock(&startMx) =3D=3D 0); pthread_join(t, &result); - assert((int)(size_t)result =3D=3D param.sched_priority); + if (doable_pri(param.sched_priority)) + assert((int)(size_t)result =3D=3D param.sched_priority); } =20 return 0;