1 /* Copyright (C) 2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
38 pthread_mutexattr_t ma;
39 if (pthread_mutexattr_init (&ma))
41 puts ("mutexattr_init failed");
44 if (pthread_mutexattr_setprotocol (&ma, PTHREAD_PRIO_PROTECT))
46 puts ("mutexattr_setprotocol failed");
51 if (pthread_mutexattr_getprioceiling (&ma, &prioceiling))
53 puts ("mutexattr_getprioceiling failed");
57 if (prioceiling < fifo_min || prioceiling > fifo_max)
59 printf ("prioceiling %d not in %d..%d range\n",
60 prioceiling, fifo_min, fifo_max);
64 if (fifo_max < INT_MAX
65 && pthread_mutexattr_setprioceiling (&ma, fifo_max + 1) != EINVAL)
67 printf ("mutexattr_setprioceiling %d did not fail with EINVAL\n",
73 && pthread_mutexattr_setprioceiling (&ma, fifo_min - 1) != EINVAL)
75 printf ("mutexattr_setprioceiling %d did not fail with EINVAL\n",
80 if (pthread_mutexattr_setprioceiling (&ma, fifo_min))
82 puts ("mutexattr_setprioceiling failed");
86 if (pthread_mutexattr_setprioceiling (&ma, fifo_max))
88 puts ("mutexattr_setprioceiling failed");
92 if (pthread_mutexattr_setprioceiling (&ma, 6))
94 puts ("mutexattr_setprioceiling failed");
98 if (pthread_mutexattr_getprioceiling (&ma, &prioceiling))
100 puts ("mutexattr_getprioceiling failed");
104 if (prioceiling != 6)
106 printf ("mutexattr_getprioceiling returned %d != 6\n",
111 pthread_mutex_t m1, m2, m3;
112 int e = pthread_mutex_init (&m1, &ma);
115 puts ("cannot support selected type of mutexes");
120 puts ("mutex_init failed");
124 if (pthread_mutexattr_setprioceiling (&ma, 8))
126 puts ("mutexattr_setprioceiling failed");
130 if (pthread_mutex_init (&m2, &ma))
132 puts ("mutex_init failed");
136 if (pthread_mutexattr_setprioceiling (&ma, 5))
138 puts ("mutexattr_setprioceiling failed");
142 if (pthread_mutex_init (&m3, &ma))
144 puts ("mutex_init failed");
148 CHECK_TPP_PRIORITY (4, 4);
150 if (pthread_mutex_lock (&m1) != 0)
152 puts ("mutex_lock failed");
156 CHECK_TPP_PRIORITY (4, 6);
158 if (pthread_mutex_trylock (&m2) != 0)
160 puts ("mutex_lock failed");
164 CHECK_TPP_PRIORITY (4, 8);
166 if (pthread_mutex_lock (&m3) != 0)
168 puts ("mutex_lock failed");
172 CHECK_TPP_PRIORITY (4, 8);
174 if (pthread_mutex_unlock (&m2) != 0)
176 puts ("mutex_unlock failed");
180 CHECK_TPP_PRIORITY (4, 6);
182 if (pthread_mutex_unlock (&m1) != 0)
184 puts ("mutex_unlock failed");
188 CHECK_TPP_PRIORITY (4, 5);
190 if (pthread_mutex_lock (&m2) != 0)
192 puts ("mutex_lock failed");
196 CHECK_TPP_PRIORITY (4, 8);
198 if (pthread_mutex_unlock (&m2) != 0)
200 puts ("mutex_unlock failed");
204 CHECK_TPP_PRIORITY (4, 5);
206 if (pthread_mutex_getprioceiling (&m1, &prioceiling))
208 puts ("mutex_getprioceiling m1 failed");
211 else if (prioceiling != 6)
213 printf ("unexpected m1 prioceiling %d != 6\n", prioceiling);
217 if (pthread_mutex_getprioceiling (&m2, &prioceiling))
219 puts ("mutex_getprioceiling m2 failed");
222 else if (prioceiling != 8)
224 printf ("unexpected m2 prioceiling %d != 8\n", prioceiling);
228 if (pthread_mutex_getprioceiling (&m3, &prioceiling))
230 puts ("mutex_getprioceiling m3 failed");
233 else if (prioceiling != 5)
235 printf ("unexpected m3 prioceiling %d != 5\n", prioceiling);
239 if (pthread_mutex_setprioceiling (&m1, 7, &prioceiling))
241 printf ("mutex_setprioceiling failed");
244 else if (prioceiling != 6)
246 printf ("unexpected m1 old prioceiling %d != 6\n", prioceiling);
250 if (pthread_mutex_getprioceiling (&m1, &prioceiling))
252 puts ("mutex_getprioceiling m1 failed");
255 else if (prioceiling != 7)
257 printf ("unexpected m1 prioceiling %d != 7\n", prioceiling);
261 CHECK_TPP_PRIORITY (4, 5);
263 if (pthread_mutex_unlock (&m3) != 0)
265 puts ("mutex_unlock failed");
269 CHECK_TPP_PRIORITY (4, 4);
271 if (pthread_mutex_trylock (&m1) != 0)
273 puts ("mutex_lock failed");
277 CHECK_TPP_PRIORITY (4, 7);
279 struct sched_param sp;
280 memset (&sp, 0, sizeof (sp));
281 sp.sched_priority = 8;
282 if (pthread_setschedparam (pthread_self (), SCHED_FIFO, &sp))
284 puts ("cannot set scheduling params");
288 CHECK_TPP_PRIORITY (8, 8);
290 if (pthread_mutex_unlock (&m1) != 0)
292 puts ("mutex_unlock failed");
296 CHECK_TPP_PRIORITY (8, 8);
298 if (pthread_mutex_lock (&m3) != EINVAL)
300 puts ("pthread_mutex_lock didn't fail with EINVAL");
304 CHECK_TPP_PRIORITY (8, 8);
306 if (pthread_mutex_destroy (&m1) != 0)
308 puts ("mutex_destroy failed");
312 if (pthread_mutex_destroy (&m2) != 0)
314 puts ("mutex_destroy failed");
318 if (pthread_mutex_destroy (&m3) != 0)
320 puts ("mutex_destroy failed");
324 if (pthread_mutexattr_destroy (&ma) != 0)
326 puts ("mutexattr_destroy failed");
333 #define TEST_FUNCTION do_test ()
334 #include "../test-skeleton.c"