diff options
author | rpj <rpj> | 2001-10-25 23:51:53 +0000 |
---|---|---|
committer | rpj <rpj> | 2001-10-25 23:51:53 +0000 |
commit | 820ca4b34c23ef8d91edade437f0f9fd781f8b89 (patch) | |
tree | 0cf9a2f78eea742c19761b071479d94644278195 /tests/priority1.c | |
parent | 222a76c37c89ee37eebecd53dd32fd481245e6fa (diff) |
* GNUmakefile (libwsock32): Add to linker flags for
WSAGetLastError() and WSASetLastError().
* Makefile (wsock32.lib): Likewise.
* create.c: Minor mostly inert changes.
* implement.h (PTW32_MAX): Move into here and renamed
from sched.h.
(PTW32_MIN): Likewise.
* GNUmakefile (TEST_ICE): Define if testing internal
implementation of InterlockedCompareExchange.
* Makefile (TEST_ICE): Likewise.
* private.c (TEST_ICE): Likewise.
Diffstat (limited to 'tests/priority1.c')
-rw-r--r-- | tests/priority1.c | 63 |
1 files changed, 54 insertions, 9 deletions
diff --git a/tests/priority1.c b/tests/priority1.c index a311028..1ec9f4d 100644 --- a/tests/priority1.c +++ b/tests/priority1.c @@ -41,16 +41,52 @@ #include "test.h" -void * func(void * arg) +enum { + PTW32TEST_THREAD_INIT_PRIO = 0, + PTW32TEST_MAXPRIORITIES = 512 +}; + +int minPrio; +int maxPrio; +int validPriorities[PTW32TEST_MAXPRIORITIES]; + +void * +func(void * arg) { int policy; struct sched_param param; + pthread_t threadID = pthread_self(); - assert(pthread_getschedparam(pthread_self(), &policy, ¶m) == 0); + assert(pthread_getschedparam(threadID, &policy, ¶m) == 0); assert(policy == SCHED_OTHER); - return (void *) param.sched_priority; + return (void *) (param.sched_priority); +} + +void * +getValidPriorities(void * arg) +{ + int prioSet; + pthread_t threadID = pthread_self(); + HANDLE threadH = pthread_getw32threadhandle_np(threadID); + + for (prioSet = minPrio; + prioSet <= maxPrio; + prioSet++) + { + /* + * If prioSet is invalid then the threads priority is unchanged + * from the previous value. Make the previous value a known + * one so that we can check later. + */ + SetThreadPriority(threadH, PTW32TEST_THREAD_INIT_PRIO); + SetThreadPriority(threadH, prioSet); + validPriorities[prioSet+(PTW32TEST_MAXPRIORITIES/2)] = GetThreadPriority(threadH); + } + + return (void *) 0; } - + + int main() { @@ -58,20 +94,29 @@ main() pthread_attr_t attr; void * result = NULL; struct sched_param param; - int maxPrio = sched_get_priority_max(SCHED_OTHER); - int minPrio = sched_get_priority_min(SCHED_OTHER); + + assert((maxPrio = sched_get_priority_max(SCHED_OTHER)) != -1); + assert((minPrio = sched_get_priority_min(SCHED_OTHER)) != -1); + + assert(pthread_create(&t, NULL, getValidPriorities, NULL) == 0); + assert(pthread_join(t, &result) == 0); assert(pthread_attr_init(&attr) == 0); assert(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0); + /* Set the thread's priority to a known initial value. */ + SetThreadPriority(pthread_getw32threadhandle_np(pthread_self()), + PTW32TEST_THREAD_INIT_PRIO); + for (param.sched_priority = minPrio; param.sched_priority <= maxPrio; param.sched_priority++) { assert(pthread_attr_setschedparam(&attr, ¶m) == 0); - assert(pthread_create(&t, &attr, func, NULL) == 0); - pthread_join(t, &result); - assert((int) result == param.sched_priority); + assert(pthread_create(&t, &attr, func, (void *) &attr) == 0); + assert(pthread_join(t, &result) == 0); + assert((int) result == + validPriorities[param.sched_priority+(PTW32TEST_MAXPRIORITIES/2)]); } return 0; |