OSDN Git Service

Replace FSF snail mail address with URLs
[uclinux-h8/uClibc.git] / test / nptl / tst-rwlock2.c
1 /* Copyright (C) 2002 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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    <http://www.gnu.org/licenses/>.  */
18
19 #include <errno.h>
20 #include <pthread.h>
21 #include <stdio.h>
22
23
24 static int
25 do_test (void)
26 {
27   pthread_rwlock_t r;
28   int e;
29
30   if (pthread_rwlock_init (&r, NULL) != 0)
31     {
32       puts ("rwlock_init failed");
33       return 1;
34     }
35   puts ("rwlock_init succeeded");
36
37   if (pthread_rwlock_wrlock (&r) != 0)
38     {
39       puts ("1st rwlock_wrlock failed");
40       return 1;
41     }
42   puts ("1st rwlock_wrlock succeeded");
43
44   e = pthread_rwlock_tryrdlock (&r);
45   if (e == 0)
46     {
47       puts ("rwlock_tryrdlock on rwlock with writer succeeded");
48       return 1;
49     }
50   if (e != EBUSY)
51     {
52       puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
53       return 1;
54     }
55   puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
56
57   e = pthread_rwlock_trywrlock (&r);
58   if (e == 0)
59     {
60       puts ("rwlock_trywrlock on rwlock with writer succeeded");
61       return 1;
62     }
63   if (e != EBUSY)
64     {
65       puts ("rwlock_trywrlock on rwlock with writer return value != EBUSY");
66       return 1;
67     }
68   puts ("rwlock_trywrlock on rwlock with writer failed with EBUSY");
69
70   if (pthread_rwlock_unlock (&r) != 0)
71     {
72       puts ("1st rwlock_unlock failed");
73       return 1;
74     }
75   puts ("1st rwlock_unlock succeeded");
76
77   if (pthread_rwlock_tryrdlock (&r) != 0)
78     {
79       puts ("rwlock_tryrdlock on unlocked rwlock failed");
80       return 1;
81     }
82   puts ("rwlock_tryrdlock on unlocked rwlock succeeded");
83
84   e = pthread_rwlock_trywrlock (&r);
85   if (e == 0)
86     {
87       puts ("rwlock_trywrlock on rwlock with reader succeeded");
88       return 1;
89     }
90   if (e != EBUSY)
91     {
92       puts ("rwlock_trywrlock on rwlock with reader return value != EBUSY");
93       return 1;
94     }
95   puts ("rwlock_trywrlock on rwlock with reader failed with EBUSY");
96
97   if (pthread_rwlock_unlock (&r) != 0)
98     {
99       puts ("2nd rwlock_unlock failed");
100       return 1;
101     }
102   puts ("2nd rwlock_unlock succeeded");
103
104   if (pthread_rwlock_trywrlock (&r) != 0)
105     {
106       puts ("rwlock_trywrlock on unlocked rwlock failed");
107       return 1;
108     }
109   puts ("rwlock_trywrlock on unlocked rwlock succeeded");
110
111   e = pthread_rwlock_tryrdlock (&r);
112   if (e == 0)
113     {
114       puts ("rwlock_tryrdlock on rwlock with writer succeeded");
115       return 1;
116     }
117   if (e != EBUSY)
118     {
119       puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
120       return 1;
121     }
122   puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
123
124   if (pthread_rwlock_unlock (&r) != 0)
125     {
126       puts ("3rd rwlock_unlock failed");
127       return 1;
128     }
129   puts ("3rd rwlock_unlock succeeded");
130
131   if (pthread_rwlock_destroy (&r) != 0)
132     {
133       puts ("rwlock_destroy failed");
134       return 1;
135     }
136   puts ("rwlock_destroy succeeded");
137
138   return 0;
139 }
140
141 #define TEST_FUNCTION do_test ()
142 #include "../test-skeleton.c"