1 /* Copyright (C) 2003, 2004 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
30 static pthread_barrier_t b
;
31 volatile int in_sh_body
;
32 unsigned long cleanups
;
37 cleanups
= (cleanups
<< 4) | (long) arg
;
41 static void __attribute__((noinline
))
46 pthread_cleanup_push (cl
, (void *) 1L);
49 if (read (fd
[2], &c
, 1) == 1)
51 puts ("read succeeded");
55 pthread_cleanup_pop (0);
62 pthread_cleanup_push (cl
, (void *) 2L);
66 pthread_cleanup_pop (0);
70 static void __attribute__((noinline
))
75 pthread_cleanup_push (cl
, (void *) 3L);
77 int r
= pthread_barrier_wait (&b
);
78 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
80 puts ("child thread: barrier_wait failed");
84 if (read (fd
[0], &c
, 1) == 1)
86 puts ("read succeeded");
92 pthread_cleanup_pop (0);
99 pthread_t th
= (pthread_t
) arg
;
101 int r
= pthread_barrier_wait (&b
);
102 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
104 puts ("parent thread: barrier_wait failed");
110 r
= pthread_kill (th
, SIGHUP
);
114 printf ("pthread_kill failed %m\n");
118 while (in_sh_body
== 0)
121 if (pthread_cancel (th
) != 0)
123 puts ("cancel failed");
127 /* This will cause the read in the initial thread to return. */
134 if (pthread_join (th
, &ret
) != 0)
136 puts ("join failed");
140 if (ret
!= PTHREAD_CANCELED
)
142 puts ("result is wrong");
146 if (cleanups
!= 0x1234L
)
148 printf ("called cleanups %lx\n", cleanups
);
152 if (pthread_barrier_destroy (&b
))
154 puts ("barrier destroy failed");
171 printf ("fork failed: %m\n");
178 if (waitpid (pid
, &status
, 0) < 0)
180 printf ("waitpid failed %m\n");
184 return !WIFEXITED (status
) || WEXITSTATUS (status
);
187 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
189 puts ("barrier_init failed");
194 if (pipe (fd
) != 0 || pipe (fd
+ 2) != 0)
196 puts ("pipe failed");
201 if (pthread_create (&th
, NULL
, tf
, (void *) pthread_self ()) != 0)
203 puts ("create failed");
207 pthread_cleanup_push (cl
, (void *) 4L);
209 pthread_cleanup_pop (0);
218 ss
.ss_sp
= malloc (2 * SIGSTKSZ
);
219 if (ss
.ss_sp
== NULL
)
221 puts ("failed to allocate alternate stack");
225 ss
.ss_size
= 2 * SIGSTKSZ
;
226 if (sigaltstack (&ss
, NULL
) < 0)
228 printf ("sigaltstack failed %m\n");
234 sigemptyset (&sa
.sa_mask
);
237 if (sigaction (SIGHUP
, &sa
, NULL
) != 0)
239 puts ("sigaction failed");
243 puts ("sa_flags = 0 test");
248 sigemptyset (&sa
.sa_mask
);
249 sa
.sa_flags
= SA_ONSTACK
;
251 if (sigaction (SIGHUP
, &sa
, NULL
) != 0)
253 puts ("sigaction failed");
257 puts ("sa_flags = SA_ONSTACK test");
261 sa
.sa_sigaction
= (void (*)(int, siginfo_t
*, void *)) sh
;
262 sigemptyset (&sa
.sa_mask
);
263 sa
.sa_flags
= SA_SIGINFO
;
265 if (sigaction (SIGHUP
, &sa
, NULL
) != 0)
267 puts ("sigaction failed");
271 puts ("sa_flags = SA_SIGINFO test");
275 sa
.sa_sigaction
= (void (*)(int, siginfo_t
*, void *)) sh
;
276 sigemptyset (&sa
.sa_mask
);
277 sa
.sa_flags
= SA_SIGINFO
| SA_ONSTACK
;
279 if (sigaction (SIGHUP
, &sa
, NULL
) != 0)
281 puts ("sigaction failed");
285 puts ("sa_flags = SA_SIGINFO|SA_ONSTACK test");
293 #define TEST_FUNCTION do_test ()
294 #include "../test-skeleton.c"