Fix up log format, wrap a long line.
[glibc.git] / nptl / tst-rwlock14.c
blob0768a42b5b07a5e80050bad45186c05f639395d2
1 /* Copyright (C) 2004-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
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 <pthread.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <time.h>
26 static pthread_barrier_t b;
27 static pthread_rwlock_t r = PTHREAD_RWLOCK_INITIALIZER;
30 static void *
31 tf (void *arg)
33 /* Lock the read-write lock. */
34 if (pthread_rwlock_wrlock (&r) != 0)
36 puts ("tf: cannot lock rwlock");
37 exit (EXIT_FAILURE);
40 pthread_t mt = *(pthread_t *) arg;
42 pthread_barrier_wait (&b);
44 /* This call will never return. */
45 pthread_join (mt, NULL);
47 return NULL;
51 static int
52 do_test (void)
54 int result = 0;
55 struct timespec ts;
57 if (clock_gettime (CLOCK_REALTIME, &ts) != 0)
59 puts ("clock_gettime failed");
60 return 1;
63 if (pthread_barrier_init (&b, NULL, 2) != 0)
65 puts ("barrier_init failed");
66 return 1;
69 pthread_t me = pthread_self ();
70 pthread_t th;
71 if (pthread_create (&th, NULL, tf, &me) != 0)
73 puts ("create failed");
74 return 1;
77 /* Wait until the rwlock is locked. */
78 pthread_barrier_wait (&b);
80 ts.tv_nsec = -1;
82 int e = pthread_rwlock_timedrdlock (&r, &ts);
83 if (e == 0)
85 puts ("first rwlock_timedrdlock did not fail");
86 result = 1;
88 else if (e != EINVAL)
90 puts ("first rwlock_timedrdlock did not return EINVAL");
91 result = 1;
94 e = pthread_rwlock_timedwrlock (&r, &ts);
95 if (e == 0)
97 puts ("first rwlock_timedwrlock did not fail");
98 result = 1;
100 else if (e != EINVAL)
102 puts ("first rwlock_timedwrlock did not return EINVAL");
103 result = 1;
106 ts.tv_nsec = 1000000000;
108 e = pthread_rwlock_timedrdlock (&r, &ts);
109 if (e == 0)
111 puts ("second rwlock_timedrdlock did not fail");
112 result = 1;
114 else if (e != EINVAL)
116 puts ("second rwlock_timedrdlock did not return EINVAL");
117 result = 1;
120 e = pthread_rwlock_timedrdlock (&r, &ts);
121 if (e == 0)
123 puts ("second rwlock_timedrdlock did not fail");
124 result = 1;
126 else if (e != EINVAL)
128 puts ("second rwlock_timedrdlock did not return EINVAL");
129 result = 1;
132 ts.tv_nsec = (__typeof (ts.tv_nsec)) 0x100001000LL;
133 if ((__typeof (ts.tv_nsec)) 0x100001000LL != 0x100001000LL)
134 ts.tv_nsec = 2000000000;
136 e = pthread_rwlock_timedrdlock (&r, &ts);
137 if (e == 0)
139 puts ("third rwlock_timedrdlock did not fail");
140 result = 1;
142 else if (e != EINVAL)
144 puts ("third rwlock_timedrdlock did not return EINVAL");
145 result = 1;
148 e = pthread_rwlock_timedrdlock (&r, &ts);
149 if (e == 0)
151 puts ("third rwlock_timedrdlock did not fail");
152 result = 1;
154 else if (e != EINVAL)
156 puts ("third rwlock_timedrdlock did not return EINVAL");
157 result = 1;
160 if (result == 0)
161 puts ("no bugs");
163 return result;
167 #define TEST_FUNCTION do_test ()
168 #include "../test-skeleton.c"