Add mnw language code [BZ #25139]
[glibc.git] / nptl / tst-rwlock14.c
blob93523f64630bf7a9d5cf9aa51341af00d69a1e88
1 /* Copyright (C) 2004-2019 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 <https://www.gnu.org/licenses/>. */
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>
29 static pthread_barrier_t b;
30 static pthread_rwlock_t r = PTHREAD_RWLOCK_INITIALIZER;
33 static void *
34 tf (void *arg)
36 /* Lock the read-write lock. */
37 TEST_COMPARE (pthread_rwlock_wrlock (&r), 0);
39 pthread_t mt = *(pthread_t *) arg;
41 xpthread_barrier_wait (&b);
43 /* This call will never return. */
44 xpthread_join (mt);
46 return NULL;
50 static int
51 do_test (void)
53 struct timespec ts;
55 xclock_gettime (CLOCK_REALTIME, &ts);
56 xpthread_barrier_init (&b, NULL, 2);
58 pthread_t me = pthread_self ();
59 xpthread_create (NULL, tf, &me);
61 /* Wait until the rwlock is locked. */
62 xpthread_barrier_wait (&b);
64 ts.tv_nsec = -1;
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);
73 ts.tv_nsec = 1000000000;
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);
82 ts.tv_nsec = (__typeof (ts.tv_nsec)) 0x100001000LL;
83 if ((__typeof (ts.tv_nsec)) 0x100001000LL != 0x100001000LL)
84 ts.tv_nsec = 2000000000;
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);
93 return 0;
96 #include <support/test-driver.c>