5
* --------------------------------------------------------------------------
7
* Pthreads-win32 - POSIX Threads Library for Win32
8
* Copyright(C) 1998 John E. Bossom
9
* Copyright(C) 1999,2005 Pthreads-win32 contributors
11
* Contact Email: rpj@callisto.canberra.edu.au
13
* The current list of contributors is contained
14
* in the file CONTRIBUTORS included with the source
15
* code distribution. The list can also be seen at the
16
* following World Wide Web location:
17
* http://sources.redhat.com/pthreads-win32/contributors.html
19
* This library is free software; you can redistribute it and/or
20
* modify it under the terms of the GNU Lesser General Public
21
* License as published by the Free Software Foundation; either
22
* version 2 of the License, or (at your option) any later version.
24
* This library is distributed in the hope that it will be useful,
25
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
* Lesser General Public License for more details.
29
* You should have received a copy of the GNU Lesser General Public
30
* License along with this library in the file COPYING.LIB;
31
* if not, write to the Free Software Foundation, Inc.,
32
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
34
* --------------------------------------------------------------------------
37
* - Test thread priority inheritance.
39
* Test Method (Validation or Falsification):
42
* Requirements Tested:
61
* - File name, Line number, and failed expression on failure.
62
* - No output on success.
68
* - Process returns zero exit status.
71
* - Process returns non-zero exit status.
77
PTW32TEST_THREAD_INIT_PRIO = 0,
78
PTW32TEST_MAXPRIORITIES = 512
83
int validPriorities[PTW32TEST_MAXPRIORITIES];
86
void * func(void * arg)
89
struct sched_param param;
91
assert(pthread_getschedparam(pthread_self(), &policy, ¶m) == 0);
92
return (void *) param.sched_priority;
97
getValidPriorities(void * arg)
100
pthread_t thread = pthread_self();
101
HANDLE threadH = pthread_getw32threadhandle_np(thread);
102
struct sched_param param;
104
for (prioSet = minPrio;
109
* If prioSet is invalid then the threads priority is unchanged
110
* from the previous value. Make the previous value a known
111
* one so that we can check later.
113
param.sched_priority = prioSet;
114
assert(pthread_setschedparam(thread, SCHED_OTHER, ¶m) == 0);
115
validPriorities[prioSet+(PTW32TEST_MAXPRIORITIES/2)] = GetThreadPriority(threadH);
126
pthread_t mainThread = pthread_self();
128
void * result = NULL;
129
struct sched_param param;
130
struct sched_param mainParam;
133
int inheritsched = -1;
134
pthread_t threadID = pthread_self();
135
HANDLE threadH = pthread_getw32threadhandle_np(threadID);
137
assert((maxPrio = sched_get_priority_max(SCHED_OTHER)) != -1);
138
assert((minPrio = sched_get_priority_min(SCHED_OTHER)) != -1);
140
assert(pthread_create(&t, NULL, getValidPriorities, NULL) == 0);
141
assert(pthread_join(t, &result) == 0);
143
assert(pthread_attr_init(&attr) == 0);
144
assert(pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED) == 0);
145
assert(pthread_attr_getinheritsched(&attr, &inheritsched) == 0);
146
assert(inheritsched == PTHREAD_INHERIT_SCHED);
148
for (prio = minPrio; prio <= maxPrio; prio++)
150
mainParam.sched_priority = prio;
152
/* Set the thread's priority to a known initial value. */
153
SetThreadPriority(threadH, PTW32TEST_THREAD_INIT_PRIO);
155
/* Change the main thread priority */
156
assert(pthread_setschedparam(mainThread, SCHED_OTHER, &mainParam) == 0);
157
assert(pthread_getschedparam(mainThread, &policy, &mainParam) == 0);
158
assert(policy == SCHED_OTHER);
159
/* Priority returned below should be the level set by pthread_setschedparam(). */
160
assert(mainParam.sched_priority == prio);
161
assert(GetThreadPriority(threadH) ==
162
validPriorities[prio+(PTW32TEST_MAXPRIORITIES/2)]);
164
for (param.sched_priority = prio;
165
param.sched_priority <= maxPrio;
166
param.sched_priority++)
168
/* The new thread create should ignore this new priority */
169
assert(pthread_attr_setschedparam(&attr, ¶m) == 0);
170
assert(pthread_create(&t, &attr, func, NULL) == 0);
171
pthread_join(t, &result);
172
assert((int) result == mainParam.sched_priority);