Remove invalid iconv aliases.
[glibc.git] / nptl / tst-cancel19.c
blob7c248ae0f6e353b1306cd6776018ecb5c257eaea
1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <error.h>
22 #include <fcntl.h>
23 #include <pthread.h>
24 #include <signal.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/select.h>
29 #include <sys/time.h>
30 #include <unistd.h>
32 static void *
33 tf (void *arg)
35 return NULL;
38 static void
39 handler (int sig)
43 static void __attribute__ ((noinline))
44 clobber_lots_of_regs (void)
46 #define X1(n) long r##n = 10##n; __asm __volatile ("" : "+r" (r##n));
47 #define X2(n) X1(n##0) X1(n##1) X1(n##2) X1(n##3) X1(n##4)
48 #define X3(n) X2(n##0) X2(n##1) X2(n##2) X2(n##3) X2(n##4)
49 X3(0) X3(1) X3(2) X3(3) X3(4)
50 #undef X1
51 #define X1(n) __asm __volatile ("" : : "r" (r##n));
52 X3(0) X3(1) X3(2) X3(3) X3(4)
53 #undef X1
54 #undef X2
55 #undef X3
58 static int
59 do_test (void)
61 pthread_t th;
62 int old, rc;
63 int ret = 0;
64 int fd[2];
66 rc = pipe (fd);
67 if (rc < 0)
68 error (EXIT_FAILURE, errno, "couldn't create pipe");
70 rc = pthread_create (&th, NULL, tf, NULL);
71 if (rc)
72 error (EXIT_FAILURE, rc, "couldn't create thread");
74 rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
75 if (rc)
77 error (0, rc, "1st pthread_setcanceltype failed");
78 ret = 1;
80 if (old != PTHREAD_CANCEL_DEFERRED && old != PTHREAD_CANCEL_ASYNCHRONOUS)
82 error (0, 0, "1st pthread_setcanceltype returned invalid value %d",
83 old);
84 ret = 1;
87 clobber_lots_of_regs ();
88 close (fd[0]);
90 rc = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old);
91 if (rc)
93 error (0, rc, "pthread_setcanceltype after close failed");
94 ret = 1;
96 if (old != PTHREAD_CANCEL_DEFERRED)
98 error (0, 0, "pthread_setcanceltype after close returned invalid value %d",
99 old);
100 ret = 1;
103 clobber_lots_of_regs ();
104 close (fd[1]);
106 rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
107 if (rc)
109 error (0, rc, "pthread_setcanceltype after 2nd close failed");
110 ret = 1;
112 if (old != PTHREAD_CANCEL_ASYNCHRONOUS)
114 error (0, 0, "pthread_setcanceltype after 2nd close returned invalid value %d",
115 old);
116 ret = 1;
119 struct sigaction sa = { .sa_handler = handler, .sa_flags = 0 };
120 sigemptyset (&sa.sa_mask);
121 sigaction (SIGALRM, &sa, NULL);
123 struct itimerval it;
124 it.it_value.tv_sec = 1;
125 it.it_value.tv_usec = 0;
126 it.it_interval = it.it_value;
127 setitimer (ITIMER_REAL, &it, NULL);
129 clobber_lots_of_regs ();
130 pause ();
132 memset (&it, 0, sizeof (it));
133 setitimer (ITIMER_REAL, &it, NULL);
135 rc = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old);
136 if (rc)
138 error (0, rc, "pthread_setcanceltype after pause failed");
139 ret = 1;
141 if (old != PTHREAD_CANCEL_DEFERRED)
143 error (0, 0, "pthread_setcanceltype after pause returned invalid value %d",
144 old);
145 ret = 1;
148 it.it_value.tv_sec = 1;
149 it.it_value.tv_usec = 0;
150 it.it_interval = it.it_value;
151 setitimer (ITIMER_REAL, &it, NULL);
153 clobber_lots_of_regs ();
154 pause ();
156 memset (&it, 0, sizeof (it));
157 setitimer (ITIMER_REAL, &it, NULL);
159 rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
160 if (rc)
162 error (0, rc, "pthread_setcanceltype after 2nd pause failed");
163 ret = 1;
165 if (old != PTHREAD_CANCEL_ASYNCHRONOUS)
167 error (0, 0, "pthread_setcanceltype after 2nd pause returned invalid value %d",
168 old);
169 ret = 1;
172 char fname[] = "/tmp/tst-cancel19-dir-XXXXXX\0foo/bar";
173 char *enddir = strchr (fname, '\0');
174 if (mkdtemp (fname) == NULL)
176 error (0, errno, "mkdtemp failed");
177 ret = 1;
179 *enddir = '/';
181 clobber_lots_of_regs ();
182 creat (fname, 0400);
184 rc = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old);
185 if (rc)
187 error (0, rc, "pthread_setcanceltype after creat failed");
188 ret = 1;
190 if (old != PTHREAD_CANCEL_DEFERRED)
192 error (0, 0, "pthread_setcanceltype after creat returned invalid value %d",
193 old);
194 ret = 1;
197 clobber_lots_of_regs ();
198 creat (fname, 0400);
200 rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
201 if (rc)
203 error (0, rc, "pthread_setcanceltype after 2nd creat failed");
204 ret = 1;
206 if (old != PTHREAD_CANCEL_ASYNCHRONOUS)
208 error (0, 0, "pthread_setcanceltype after 2nd creat returned invalid value %d",
209 old);
210 ret = 1;
213 clobber_lots_of_regs ();
214 open (fname, O_CREAT, 0400);
216 rc = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old);
217 if (rc)
219 error (0, rc, "pthread_setcanceltype after open failed");
220 ret = 1;
222 if (old != PTHREAD_CANCEL_DEFERRED)
224 error (0, 0, "pthread_setcanceltype after open returned invalid value %d",
225 old);
226 ret = 1;
229 clobber_lots_of_regs ();
230 open (fname, O_CREAT, 0400);
232 rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
233 if (rc)
235 error (0, rc, "pthread_setcanceltype after 2nd open failed");
236 ret = 1;
238 if (old != PTHREAD_CANCEL_ASYNCHRONOUS)
240 error (0, 0, "pthread_setcanceltype after 2nd open returned invalid value %d",
241 old);
242 ret = 1;
245 *enddir = '\0';
246 rmdir (fname);
248 clobber_lots_of_regs ();
249 select (-1, NULL, NULL, NULL, NULL);
251 rc = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old);
252 if (rc)
254 error (0, rc, "pthread_setcanceltype after select failed");
255 ret = 1;
257 if (old != PTHREAD_CANCEL_DEFERRED)
259 error (0, 0, "pthread_setcanceltype after select returned invalid value %d",
260 old);
261 ret = 1;
264 clobber_lots_of_regs ();
265 select (-1, NULL, NULL, NULL, NULL);
267 rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
268 if (rc)
270 error (0, rc, "pthread_setcanceltype after 2nd select failed");
271 ret = 1;
273 if (old != PTHREAD_CANCEL_ASYNCHRONOUS)
275 error (0, 0, "pthread_setcanceltype after 2nd select returned invalid value %d",
276 old);
277 ret = 1;
280 pthread_join (th, NULL);
282 return ret;
285 #define TIMEOUT 20
286 #define TEST_FUNCTION do_test ()
287 #include "../test-skeleton.c"