]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/tst-rwlock14.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / nptl / tst-rwlock14.c
CommitLineData
04277e02 1/* Copyright (C) 2004-2019 Free Software Foundation, Inc.
46f4c578
UD
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
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
46f4c578
UD
18
19#include <errno.h>
20#include <pthread.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <time.h>
495514ee
MC
24#include <support/check.h>
25#include <support/xthread.h>
26#include <support/xtime.h>
46f4c578
UD
27
28
29static pthread_barrier_t b;
30static pthread_rwlock_t r = PTHREAD_RWLOCK_INITIALIZER;
31
32
33static void *
34tf (void *arg)
35{
36 /* Lock the read-write lock. */
495514ee 37 TEST_COMPARE (pthread_rwlock_wrlock (&r), 0);
46f4c578 38
3cabdafa 39 pthread_t mt = *(pthread_t *) arg;
46f4c578 40
495514ee 41 xpthread_barrier_wait (&b);
46f4c578
UD
42
43 /* This call will never return. */
495514ee 44 xpthread_join (mt);
46f4c578
UD
45
46 return NULL;
47}
48
49
50static int
51do_test (void)
52{
46f4c578
UD
53 struct timespec ts;
54
495514ee
MC
55 xclock_gettime (CLOCK_REALTIME, &ts);
56 xpthread_barrier_init (&b, NULL, 2);
46f4c578
UD
57
58 pthread_t me = pthread_self ();
495514ee 59 xpthread_create (NULL, tf, &me);
46f4c578
UD
60
61 /* Wait until the rwlock is locked. */
495514ee 62 xpthread_barrier_wait (&b);
46f4c578
UD
63
64 ts.tv_nsec = -1;
65
495514ee 66 TEST_COMPARE (pthread_rwlock_timedrdlock (&r, &ts), EINVAL);
e996fa72
MC
67 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_REALTIME, &ts), EINVAL);
68 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
495514ee 69 TEST_COMPARE (pthread_rwlock_timedwrlock (&r, &ts), EINVAL);
e996fa72
MC
70 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_REALTIME, &ts), EINVAL);
71 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
46f4c578 72
38205402 73 ts.tv_nsec = 1000000000;
46f4c578 74
495514ee 75 TEST_COMPARE (pthread_rwlock_timedrdlock (&r, &ts), EINVAL);
e996fa72
MC
76 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_REALTIME, &ts), EINVAL);
77 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
495514ee 78 TEST_COMPARE (pthread_rwlock_timedwrlock (&r, &ts), EINVAL);
e996fa72
MC
79 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_REALTIME, &ts), EINVAL);
80 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
46f4c578 81
1475e201
UD
82 ts.tv_nsec = (__typeof (ts.tv_nsec)) 0x100001000LL;
83 if ((__typeof (ts.tv_nsec)) 0x100001000LL != 0x100001000LL)
38205402
UD
84 ts.tv_nsec = 2000000000;
85
495514ee 86 TEST_COMPARE (pthread_rwlock_timedrdlock (&r, &ts), EINVAL);
e996fa72
MC
87 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_REALTIME, &ts), EINVAL);
88 TEST_COMPARE (pthread_rwlock_clockrdlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
495514ee 89 TEST_COMPARE (pthread_rwlock_timedwrlock (&r, &ts), EINVAL);
e996fa72
MC
90 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_REALTIME, &ts), EINVAL);
91 TEST_COMPARE (pthread_rwlock_clockwrlock (&r, CLOCK_MONOTONIC, &ts), EINVAL);
46f4c578 92
495514ee
MC
93 return 0;
94}
46f4c578 95
495514ee 96#include <support/test-driver.c>