iconv: Suppress array out of bounds warning.
[platform/upstream/glibc.git] / nptl / tst-rwlock2.c
1 /* Copyright (C) 2002-2015 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   pthread_rwlockattr_t at;
29   int e;
30
31   if (pthread_rwlockattr_init (&at) != 0)
32     {
33       puts ("rwlockattr_init failed");
34       return 1;
35     }
36   puts ("rwlockattr_init succeeded");
37
38 #ifndef TYPE
39 # define TYPE PTHREAD_RWLOCK_PREFER_READER_NP
40 #endif
41
42   if (pthread_rwlockattr_setkind_np (&at, TYPE) != 0)
43     {
44       puts ("rwlockattr_setkind failed");
45       return 1;
46     }
47   puts ("rwlockattr_setkind succeeded");
48
49   if (pthread_rwlock_init (&r, &at) != 0)
50     {
51       puts ("rwlock_init failed");
52       return 1;
53     }
54   puts ("rwlock_init succeeded");
55
56   if (pthread_rwlockattr_destroy (&at) != 0)
57     {
58       puts ("rwlockattr_destroy failed");
59       return 1;
60     }
61   puts ("rwlockattr_destroy succeeded");
62
63   if (pthread_rwlock_wrlock (&r) != 0)
64     {
65       puts ("1st rwlock_wrlock failed");
66       return 1;
67     }
68   puts ("1st rwlock_wrlock succeeded");
69
70   e = pthread_rwlock_tryrdlock (&r);
71   if (e == 0)
72     {
73       puts ("rwlock_tryrdlock on rwlock with writer succeeded");
74       return 1;
75     }
76   if (e != EBUSY)
77     {
78       puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
79       return 1;
80     }
81   puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
82
83   e = pthread_rwlock_trywrlock (&r);
84   if (e == 0)
85     {
86       puts ("rwlock_trywrlock on rwlock with writer succeeded");
87       return 1;
88     }
89   if (e != EBUSY)
90     {
91       puts ("rwlock_trywrlock on rwlock with writer return value != EBUSY");
92       return 1;
93     }
94   puts ("rwlock_trywrlock on rwlock with writer failed with EBUSY");
95
96   if (pthread_rwlock_unlock (&r) != 0)
97     {
98       puts ("1st rwlock_unlock failed");
99       return 1;
100     }
101   puts ("1st rwlock_unlock succeeded");
102
103   if (pthread_rwlock_tryrdlock (&r) != 0)
104     {
105       puts ("rwlock_tryrdlock on unlocked rwlock failed");
106       return 1;
107     }
108   puts ("rwlock_tryrdlock on unlocked rwlock succeeded");
109
110   e = pthread_rwlock_trywrlock (&r);
111   if (e == 0)
112     {
113       puts ("rwlock_trywrlock on rwlock with reader succeeded");
114       return 1;
115     }
116   if (e != EBUSY)
117     {
118       puts ("rwlock_trywrlock on rwlock with reader return value != EBUSY");
119       return 1;
120     }
121   puts ("rwlock_trywrlock on rwlock with reader failed with EBUSY");
122
123   if (pthread_rwlock_unlock (&r) != 0)
124     {
125       puts ("2nd rwlock_unlock failed");
126       return 1;
127     }
128   puts ("2nd rwlock_unlock succeeded");
129
130   if (pthread_rwlock_trywrlock (&r) != 0)
131     {
132       puts ("rwlock_trywrlock on unlocked rwlock failed");
133       return 1;
134     }
135   puts ("rwlock_trywrlock on unlocked rwlock succeeded");
136
137   e = pthread_rwlock_tryrdlock (&r);
138   if (e == 0)
139     {
140       puts ("rwlock_tryrdlock on rwlock with writer succeeded");
141       return 1;
142     }
143   if (e != EBUSY)
144     {
145       puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
146       return 1;
147     }
148   puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
149
150   if (pthread_rwlock_unlock (&r) != 0)
151     {
152       puts ("3rd rwlock_unlock failed");
153       return 1;
154     }
155   puts ("3rd rwlock_unlock succeeded");
156
157   if (pthread_rwlock_destroy (&r) != 0)
158     {
159       puts ("rwlock_destroy failed");
160       return 1;
161     }
162   puts ("rwlock_destroy succeeded");
163
164   return 0;
165 }
166
167 #define TEST_FUNCTION do_test ()
168 #include "../test-skeleton.c"