From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2201) id CF00B3858C78; Fri, 14 Jul 2023 15:28:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF00B3858C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689348503; bh=J0W5hVABR6wQUFxf1+3vzMBRf0C88TG7swdMCJIFSdA=; h=From:To:Subject:Date:From; b=RznEexaSJ2kgjVkv5y26dmU25WBWd4dupcuoG/OnNE7Nmz5qBMXH7oDlwg30o5BVe rGTXZnxSwf6Va1TNpYb4FMZItLfXpSw2XuaXagEWnJrkcVH+KgJIxlPbDtbvHb8f1z GeAc5Nq+tM/v1WJOmoj6Cykpf3AjaUw38DSln7K8= 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: 79a9288434aaa15407727474f26504214b027306 X-Git-Newrev: 7d50e65a8442546a6bdce7636d67ad65f154de46 Message-Id: <20230714152823.CF00B3858C78@sourceware.org> Date: Fri, 14 Jul 2023 15:28:23 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D7d50e65a844= 2546a6bdce7636d67ad65f154de46 commit 7d50e65a8442546a6bdce7636d67ad65f154de46 Author: Jon Turney Date: Thu Sep 1 12:13:50 2022 +0100 Cygwin: testsuite: Fix for limited thread priority values =20 Since commit 4b51e4c1, we return the actual thread priority, not what we originally stored in the thread attributes. =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 they only check for round-tripping priority values which can be exactly represented. =20 For CI, this needs to handle process priority class "below normal priority" as well. =20 Also check that the range of priority values is at least 32, as required by POSIX. =20 Signed-off-by: Jon Turney Diff: --- winsup/testsuite/winsup.api/pthread/inherit1.c | 21 ++++++++++++++++++++- winsup/testsuite/winsup.api/pthread/priority1.c | 24 +++++++++++++++++++++= +-- winsup/testsuite/winsup.api/pthread/priority2.c | 22 ++++++++++++++++++++-- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/winsup/testsuite/winsup.api/pthread/inherit1.c b/winsup/testsu= ite/winsup.api/pthread/inherit1.c index 16c3f534b..f036462aa 100644 --- a/winsup/testsuite/winsup.api/pthread/inherit1.c +++ b/winsup/testsuite/winsup.api/pthread/inherit1.c @@ -50,6 +50,23 @@ 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. The exact mapping also depends on the overall proce= ss +// priority class. So only a subset of values will be returned exactly by +// pthread_getschedparam() after pthread_setschedparam(). +int doable_pri(int pri) +{ + switch (GetPriorityClass(GetCurrentProcess())) + { + case BELOW_NORMAL_PRIORITY_CLASS: + return (pri =3D=3D 2) || (pri =3D=3D 8) || (pri =3D=3D 10) || (pri = =3D=3D 12) || (pri =3D=3D 14) || (pri =3D=3D 16) || (pri =3D=3D 30); + case NORMAL_PRIORITY_CLASS: + 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); + } + + return TRUE; +} + int main() { @@ -81,7 +98,9 @@ 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..135f77d76 100644 --- a/winsup/testsuite/winsup.api/pthread/priority1.c +++ b/winsup/testsuite/winsup.api/pthread/priority1.c @@ -50,7 +50,24 @@ 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. The exact mapping also depends on the overall proce= ss +// priority class. So only a subset of values will be returned exactly by +// pthread_getschedparam() after pthread_setschedparam(). +int doable_pri(int pri) +{ + switch (GetPriorityClass(GetCurrentProcess())) + { + case BELOW_NORMAL_PRIORITY_CLASS: + return (pri =3D=3D 2) || (pri =3D=3D 8) || (pri =3D=3D 10) || (pri = =3D=3D 12) || (pri =3D=3D 14) || (pri =3D=3D 16) || (pri =3D=3D 30); + case NORMAL_PRIORITY_CLASS: + 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); + } + + return TRUE; +} + int main() { @@ -61,6 +78,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 31); + assert(pthread_attr_init(&attr) =3D=3D 0); assert(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) =3D= =3D 0); =20 @@ -71,7 +90,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..f084efadf 100644 --- a/winsup/testsuite/winsup.api/pthread/priority2.c +++ b/winsup/testsuite/winsup.api/pthread/priority2.c @@ -54,7 +54,24 @@ 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. The exact mapping also depends on the overall proce= ss +// priority class. So only a subset of values will be returned exactly by +// pthread_getschedparam() after pthread_setschedparam(). +int doable_pri(int pri) +{ + switch (GetPriorityClass(GetCurrentProcess())) + { + case BELOW_NORMAL_PRIORITY_CLASS: + return (pri =3D=3D 2) || (pri =3D=3D 8) || (pri =3D=3D 10) || (pri = =3D=3D 12) || (pri =3D=3D 14) || (pri =3D=3D 16) || (pri =3D=3D 30); + case NORMAL_PRIORITY_CLASS: + 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); + } + + return TRUE; +} + int main() { @@ -73,7 +90,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;