el_CY, el_GR: Add alternative month names (bug 10871).
[glibc.git] / nptl / tst-mutexpp10.c
blob1e8ba5bb1b5b01fad47f00e78d21485cdc087497
1 /* Copyright (C) 2006-2018 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/>. */
19 #include <errno.h>
20 #include <limits.h>
21 #include <pthread.h>
22 #include <sched.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
28 #include "tst-tpp.h"
30 static int
31 do_test (void)
33 int ret = 0;
35 init_tpp_test ();
37 pthread_mutexattr_t ma;
38 if (pthread_mutexattr_init (&ma))
40 puts ("mutexattr_init failed");
41 return 1;
43 if (pthread_mutexattr_setprotocol (&ma, PTHREAD_PRIO_PROTECT))
45 puts ("mutexattr_setprotocol failed");
46 return 1;
49 int prioceiling;
50 if (pthread_mutexattr_getprioceiling (&ma, &prioceiling))
52 puts ("mutexattr_getprioceiling failed");
53 return 1;
56 if (prioceiling < fifo_min || prioceiling > fifo_max)
58 printf ("prioceiling %d not in %d..%d range\n",
59 prioceiling, fifo_min, fifo_max);
60 return 1;
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",
67 fifo_max + 1);
68 return 1;
71 if (fifo_min > 0
72 && pthread_mutexattr_setprioceiling (&ma, fifo_min - 1) != EINVAL)
74 printf ("mutexattr_setprioceiling %d did not fail with EINVAL\n",
75 fifo_min - 1);
76 return 1;
79 if (pthread_mutexattr_setprioceiling (&ma, fifo_min))
81 puts ("mutexattr_setprioceiling failed");
82 return 1;
85 if (pthread_mutexattr_setprioceiling (&ma, fifo_max))
87 puts ("mutexattr_setprioceiling failed");
88 return 1;
91 if (pthread_mutexattr_setprioceiling (&ma, 6))
93 puts ("mutexattr_setprioceiling failed");
94 return 1;
97 if (pthread_mutexattr_getprioceiling (&ma, &prioceiling))
99 puts ("mutexattr_getprioceiling failed");
100 return 1;
103 if (prioceiling != 6)
105 printf ("mutexattr_getprioceiling returned %d != 6\n",
106 prioceiling);
107 return 1;
110 pthread_mutex_t m1, m2, m3;
111 int e = pthread_mutex_init (&m1, &ma);
112 if (e == ENOTSUP)
114 puts ("cannot support selected type of mutexes");
115 return 0;
117 else if (e != 0)
119 puts ("mutex_init failed");
120 return 1;
123 if (pthread_mutexattr_setprioceiling (&ma, 8))
125 puts ("mutexattr_setprioceiling failed");
126 return 1;
129 if (pthread_mutex_init (&m2, &ma))
131 puts ("mutex_init failed");
132 return 1;
135 if (pthread_mutexattr_setprioceiling (&ma, 5))
137 puts ("mutexattr_setprioceiling failed");
138 return 1;
141 if (pthread_mutex_init (&m3, &ma))
143 puts ("mutex_init failed");
144 return 1;
147 CHECK_TPP_PRIORITY (4, 4);
149 if (pthread_mutex_lock (&m1) != 0)
151 puts ("mutex_lock failed");
152 return 1;
155 CHECK_TPP_PRIORITY (4, 6);
157 if (pthread_mutex_trylock (&m2) != 0)
159 puts ("mutex_lock failed");
160 return 1;
163 CHECK_TPP_PRIORITY (4, 8);
165 if (pthread_mutex_lock (&m3) != 0)
167 puts ("mutex_lock failed");
168 return 1;
171 CHECK_TPP_PRIORITY (4, 8);
173 if (pthread_mutex_unlock (&m2) != 0)
175 puts ("mutex_unlock failed");
176 return 1;
179 CHECK_TPP_PRIORITY (4, 6);
181 if (pthread_mutex_unlock (&m1) != 0)
183 puts ("mutex_unlock failed");
184 return 1;
187 CHECK_TPP_PRIORITY (4, 5);
189 if (pthread_mutex_lock (&m2) != 0)
191 puts ("mutex_lock failed");
192 return 1;
195 CHECK_TPP_PRIORITY (4, 8);
197 if (pthread_mutex_unlock (&m2) != 0)
199 puts ("mutex_unlock failed");
200 return 1;
203 CHECK_TPP_PRIORITY (4, 5);
205 if (pthread_mutex_getprioceiling (&m1, &prioceiling))
207 puts ("mutex_getprioceiling m1 failed");
208 return 1;
210 else if (prioceiling != 6)
212 printf ("unexpected m1 prioceiling %d != 6\n", prioceiling);
213 return 1;
216 if (pthread_mutex_getprioceiling (&m2, &prioceiling))
218 puts ("mutex_getprioceiling m2 failed");
219 return 1;
221 else if (prioceiling != 8)
223 printf ("unexpected m2 prioceiling %d != 8\n", prioceiling);
224 return 1;
227 if (pthread_mutex_getprioceiling (&m3, &prioceiling))
229 puts ("mutex_getprioceiling m3 failed");
230 return 1;
232 else if (prioceiling != 5)
234 printf ("unexpected m3 prioceiling %d != 5\n", prioceiling);
235 return 1;
238 if (pthread_mutex_setprioceiling (&m1, 7, &prioceiling))
240 printf ("mutex_setprioceiling failed");
241 return 1;
243 else if (prioceiling != 6)
245 printf ("unexpected m1 old prioceiling %d != 6\n", prioceiling);
246 return 1;
249 if (pthread_mutex_getprioceiling (&m1, &prioceiling))
251 puts ("mutex_getprioceiling m1 failed");
252 return 1;
254 else if (prioceiling != 7)
256 printf ("unexpected m1 prioceiling %d != 7\n", prioceiling);
257 return 1;
260 CHECK_TPP_PRIORITY (4, 5);
262 if (pthread_mutex_unlock (&m3) != 0)
264 puts ("mutex_unlock failed");
265 return 1;
268 CHECK_TPP_PRIORITY (4, 4);
270 if (pthread_mutex_trylock (&m1) != 0)
272 puts ("mutex_lock failed");
273 return 1;
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");
284 return 1;
287 CHECK_TPP_PRIORITY (8, 8);
289 if (pthread_mutex_unlock (&m1) != 0)
291 puts ("mutex_unlock failed");
292 return 1;
295 CHECK_TPP_PRIORITY (8, 8);
297 if (pthread_mutex_lock (&m3) != EINVAL)
299 puts ("pthread_mutex_lock didn't fail with EINVAL");
300 return 1;
303 CHECK_TPP_PRIORITY (8, 8);
305 if (pthread_mutex_destroy (&m1) != 0)
307 puts ("mutex_destroy failed");
308 return 1;
311 if (pthread_mutex_destroy (&m2) != 0)
313 puts ("mutex_destroy failed");
314 return 1;
317 if (pthread_mutex_destroy (&m3) != 0)
319 puts ("mutex_destroy failed");
320 return 1;
323 if (pthread_mutexattr_destroy (&ma) != 0)
325 puts ("mutexattr_destroy failed");
326 return 1;
329 return ret;
332 #define TEST_FUNCTION do_test ()
333 #include "../test-skeleton.c"