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, see
17 <http://www.gnu.org/licenses/>. */
37 pthread_mutexattr_t ma;
38 if (pthread_mutexattr_init (&ma))
40 puts ("mutexattr_init failed");
43 if (pthread_mutexattr_setprotocol (&ma, PTHREAD_PRIO_PROTECT))
45 puts ("mutexattr_setprotocol failed");
50 if (pthread_mutexattr_getprioceiling (&ma, &prioceiling))
52 puts ("mutexattr_getprioceiling failed");
56 if (prioceiling < fifo_min || prioceiling > fifo_max)
58 printf ("prioceiling %d not in %d..%d range\n",
59 prioceiling, fifo_min, fifo_max);
63 if (fifo_max < INT_MAX
64 && pthread_mutexattr_setprioceiling (&ma, fifo_max + 1) != EINVAL)
66 printf ("mutexattr_setprioceiling %d did not fail with EINVAL\n",
72 && pthread_mutexattr_setprioceiling (&ma, fifo_min - 1) != EINVAL)
74 printf ("mutexattr_setprioceiling %d did not fail with EINVAL\n",
79 if (pthread_mutexattr_setprioceiling (&ma, fifo_min))
81 puts ("mutexattr_setprioceiling failed");
85 if (pthread_mutexattr_setprioceiling (&ma, fifo_max))
87 puts ("mutexattr_setprioceiling failed");
91 if (pthread_mutexattr_setprioceiling (&ma, 6))
93 puts ("mutexattr_setprioceiling failed");
97 if (pthread_mutexattr_getprioceiling (&ma, &prioceiling))
99 puts ("mutexattr_getprioceiling failed");
103 if (prioceiling != 6)
105 printf ("mutexattr_getprioceiling returned %d != 6\n",
110 pthread_mutex_t m1, m2, m3;
111 int e = pthread_mutex_init (&m1, &ma);
114 puts ("cannot support selected type of mutexes");
119 puts ("mutex_init failed");
123 if (pthread_mutexattr_setprioceiling (&ma, 8))
125 puts ("mutexattr_setprioceiling failed");
129 if (pthread_mutex_init (&m2, &ma))
131 puts ("mutex_init failed");
135 if (pthread_mutexattr_setprioceiling (&ma, 5))
137 puts ("mutexattr_setprioceiling failed");
141 if (pthread_mutex_init (&m3, &ma))
143 puts ("mutex_init failed");
147 CHECK_TPP_PRIORITY (4, 4);
149 if (pthread_mutex_lock (&m1) != 0)
151 puts ("mutex_lock failed");
155 CHECK_TPP_PRIORITY (4, 6);
157 if (pthread_mutex_trylock (&m2) != 0)
159 puts ("mutex_lock failed");
163 CHECK_TPP_PRIORITY (4, 8);
165 if (pthread_mutex_lock (&m3) != 0)
167 puts ("mutex_lock failed");
171 CHECK_TPP_PRIORITY (4, 8);
173 if (pthread_mutex_unlock (&m2) != 0)
175 puts ("mutex_unlock failed");
179 CHECK_TPP_PRIORITY (4, 6);
181 if (pthread_mutex_unlock (&m1) != 0)
183 puts ("mutex_unlock failed");
187 CHECK_TPP_PRIORITY (4, 5);
189 if (pthread_mutex_lock (&m2) != 0)
191 puts ("mutex_lock failed");
195 CHECK_TPP_PRIORITY (4, 8);
197 if (pthread_mutex_unlock (&m2) != 0)
199 puts ("mutex_unlock failed");
203 CHECK_TPP_PRIORITY (4, 5);
205 if (pthread_mutex_getprioceiling (&m1, &prioceiling))
207 puts ("mutex_getprioceiling m1 failed");
210 else if (prioceiling != 6)
212 printf ("unexpected m1 prioceiling %d != 6\n", prioceiling);
216 if (pthread_mutex_getprioceiling (&m2, &prioceiling))
218 puts ("mutex_getprioceiling m2 failed");
221 else if (prioceiling != 8)
223 printf ("unexpected m2 prioceiling %d != 8\n", prioceiling);
227 if (pthread_mutex_getprioceiling (&m3, &prioceiling))
229 puts ("mutex_getprioceiling m3 failed");
232 else if (prioceiling != 5)
234 printf ("unexpected m3 prioceiling %d != 5\n", prioceiling);
238 if (pthread_mutex_setprioceiling (&m1, 7, &prioceiling))
240 printf ("mutex_setprioceiling failed");
243 else if (prioceiling != 6)
245 printf ("unexpected m1 old prioceiling %d != 6\n", prioceiling);
249 if (pthread_mutex_getprioceiling (&m1, &prioceiling))
251 puts ("mutex_getprioceiling m1 failed");
254 else if (prioceiling != 7)
256 printf ("unexpected m1 prioceiling %d != 7\n", prioceiling);
260 CHECK_TPP_PRIORITY (4, 5);
262 if (pthread_mutex_unlock (&m3) != 0)
264 puts ("mutex_unlock failed");
268 CHECK_TPP_PRIORITY (4, 4);
270 if (pthread_mutex_trylock (&m1) != 0)
272 puts ("mutex_lock failed");
276 CHECK_TPP_PRIORITY (4, 7);
278 struct sched_param sp;
279 memset (&sp, 0, sizeof (sp));
280 sp.sched_priority = 8;
281 if (pthread_setschedparam (pthread_self (), SCHED_FIFO, &sp))
283 puts ("cannot set scheduling params");
287 CHECK_TPP_PRIORITY (8, 8);
289 if (pthread_mutex_unlock (&m1) != 0)
291 puts ("mutex_unlock failed");
295 CHECK_TPP_PRIORITY (8, 8);
297 if (pthread_mutex_lock (&m3) != EINVAL)
299 puts ("pthread_mutex_lock didn't fail with EINVAL");
303 CHECK_TPP_PRIORITY (8, 8);
305 if (pthread_mutex_destroy (&m1) != 0)
307 puts ("mutex_destroy failed");
311 if (pthread_mutex_destroy (&m2) != 0)
313 puts ("mutex_destroy failed");
317 if (pthread_mutex_destroy (&m3) != 0)
319 puts ("mutex_destroy failed");
323 if (pthread_mutexattr_destroy (&ma) != 0)
325 puts ("mutexattr_destroy failed");
332 #define TEST_FUNCTION do_test ()
333 #include "../test-skeleton.c"