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
28 #include <sys/select.h>
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)
51 #define X1(n) __asm __volatile ("" : : "r" (r##n));
52 X3(0) X3(1) X3(2) X3(3) X3(4)
68 error (EXIT_FAILURE
, errno
, "couldn't create pipe");
70 rc
= pthread_create (&th
, NULL
, tf
, NULL
);
72 error (EXIT_FAILURE
, rc
, "couldn't create thread");
74 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
77 error (0, rc
, "1st pthread_setcanceltype failed");
80 if (old
!= PTHREAD_CANCEL_DEFERRED
&& old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
82 error (0, 0, "1st pthread_setcanceltype returned invalid value %d",
87 clobber_lots_of_regs ();
90 rc
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
);
93 error (0, rc
, "pthread_setcanceltype after close failed");
96 if (old
!= PTHREAD_CANCEL_DEFERRED
)
98 error (0, 0, "pthread_setcanceltype after close returned invalid value %d",
103 clobber_lots_of_regs ();
106 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
109 error (0, rc
, "pthread_setcanceltype after 2nd close failed");
112 if (old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
114 error (0, 0, "pthread_setcanceltype after 2nd close returned invalid value %d",
119 struct sigaction sa
= { .sa_handler
= handler
, .sa_flags
= 0 };
120 sigemptyset (&sa
.sa_mask
);
121 sigaction (SIGALRM
, &sa
, NULL
);
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 ();
132 memset (&it
, 0, sizeof (it
));
133 setitimer (ITIMER_REAL
, &it
, NULL
);
135 rc
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
);
138 error (0, rc
, "pthread_setcanceltype after pause failed");
141 if (old
!= PTHREAD_CANCEL_DEFERRED
)
143 error (0, 0, "pthread_setcanceltype after pause returned invalid value %d",
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 ();
156 memset (&it
, 0, sizeof (it
));
157 setitimer (ITIMER_REAL
, &it
, NULL
);
159 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
162 error (0, rc
, "pthread_setcanceltype after 2nd pause failed");
165 if (old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
167 error (0, 0, "pthread_setcanceltype after 2nd pause returned invalid value %d",
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");
181 clobber_lots_of_regs ();
184 rc
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
);
187 error (0, rc
, "pthread_setcanceltype after creat failed");
190 if (old
!= PTHREAD_CANCEL_DEFERRED
)
192 error (0, 0, "pthread_setcanceltype after creat returned invalid value %d",
197 clobber_lots_of_regs ();
200 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
203 error (0, rc
, "pthread_setcanceltype after 2nd creat failed");
206 if (old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
208 error (0, 0, "pthread_setcanceltype after 2nd creat returned invalid value %d",
213 clobber_lots_of_regs ();
214 open (fname
, O_CREAT
, 0400);
216 rc
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
);
219 error (0, rc
, "pthread_setcanceltype after open failed");
222 if (old
!= PTHREAD_CANCEL_DEFERRED
)
224 error (0, 0, "pthread_setcanceltype after open returned invalid value %d",
229 clobber_lots_of_regs ();
230 open (fname
, O_CREAT
, 0400);
232 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
235 error (0, rc
, "pthread_setcanceltype after 2nd open failed");
238 if (old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
240 error (0, 0, "pthread_setcanceltype after 2nd open returned invalid value %d",
248 clobber_lots_of_regs ();
249 select (-1, NULL
, NULL
, NULL
, NULL
);
251 rc
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
);
254 error (0, rc
, "pthread_setcanceltype after select failed");
257 if (old
!= PTHREAD_CANCEL_DEFERRED
)
259 error (0, 0, "pthread_setcanceltype after select returned invalid value %d",
264 clobber_lots_of_regs ();
265 select (-1, NULL
, NULL
, NULL
, NULL
);
267 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
270 error (0, rc
, "pthread_setcanceltype after 2nd select failed");
273 if (old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
275 error (0, 0, "pthread_setcanceltype after 2nd select returned invalid value %d",
280 pthread_join (th
, NULL
);
286 #define TEST_FUNCTION do_test ()
287 #include "../test-skeleton.c"