]> git.ipfire.org Git - thirdparty/glibc.git/blob - nptl/tst-rwlock14.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / nptl / tst-rwlock14.c
1 /* Copyright (C) 2004-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
4
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.
9
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.
14
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 <https://www.gnu.org/licenses/>. */
18
19 #include <errno.h>
20 #include <pthread.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <time.h>
24 #include <support/check.h>
25 #include <support/xthread.h>
26 #include <support/xtime.h>
27
28
29 static pthread_barrier_t b;
30 static pthread_rwlock_t r = PTHREAD_RWLOCK_INITIALIZER;
31
32
33 static void *
34 tf (void *arg)
35 {
36 /* Lock the read-write lock. */
37 TEST_COMPARE (pthread_rwlock_wrlock (&r), 0);
38
39 pthread_t mt = *(pthread_t *) arg;
40
41 xpthread_barrier_wait (&b);
42
43 /* This call will never return. */
44 xpthread_join (mt);
45
46 return NULL;
47 }
48
49
50 static int
51 do_test (void)
52 {
53 struct timespec ts;
54
55 xclock_gettime (CLOCK_REALTIME, &ts);
56 xpthread_barrier_init (&b, NULL, 2);
57
58 pthread_t me = pthread_self ();
59 xpthread_create (NULL, tf, &me);
60
61 /* Wait until the rwlock is locked. */
62 xpthread_barrier_wait (&b);
63
64 ts.tv_nsec = -1;
65
66 TEST_COMPARE (pthread_rwlock_timedrdlock (&r, &ts), EINVAL);
67 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_REALTIME, &ts), EINVAL);
68 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
69 TEST_COMPARE (pthread_rwlock_timedwrlock (&r, &ts), EINVAL);
70 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_REALTIME, &ts), EINVAL);
71 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
72
73 ts.tv_nsec = 1000000000;
74
75 TEST_COMPARE (pthread_rwlock_timedrdlock (&r, &ts), EINVAL);
76 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_REALTIME, &ts), EINVAL);
77 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
78 TEST_COMPARE (pthread_rwlock_timedwrlock (&r, &ts), EINVAL);
79 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_REALTIME, &ts), EINVAL);
80 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
81
82 ts.tv_nsec = (__typeof (ts.tv_nsec)) 0x100001000LL;
83 if ((__typeof (ts.tv_nsec)) 0x100001000LL != 0x100001000LL)
84 ts.tv_nsec = 2000000000;
85
86 TEST_COMPARE (pthread_rwlock_timedrdlock (&r, &ts), EINVAL);
87 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_REALTIME, &ts), EINVAL);
88 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
89 TEST_COMPARE (pthread_rwlock_timedwrlock (&r, &ts), EINVAL);
90 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_REALTIME, &ts), EINVAL);
91 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
92
93 return 0;
94 }
95
96 #include <support/test-driver.c>