1 /* Copyright (C) 2003-2015 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, see
17 <http://www.gnu.org/licenses/>. */
29 static pthread_barrier_t b
;
30 volatile int in_sh_body
;
31 unsigned long cleanups
;
36 cleanups
= (cleanups
<< 4) | (long) arg
;
40 static void __attribute__((noinline
))
45 pthread_cleanup_push (cl
, (void *) 1L);
48 if (read (fd
[2], &c
, 1) == 1)
50 puts ("read succeeded");
54 pthread_cleanup_pop (0);
61 pthread_cleanup_push (cl
, (void *) 2L);
65 pthread_cleanup_pop (0);
69 static void __attribute__((noinline
))
74 pthread_cleanup_push (cl
, (void *) 3L);
76 int r
= pthread_barrier_wait (&b
);
77 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
79 puts ("child thread: barrier_wait failed");
83 if (read (fd
[0], &c
, 1) == 1)
85 puts ("read succeeded");
91 pthread_cleanup_pop (0);
98 pthread_t th
= (pthread_t
) arg
;
100 int r
= pthread_barrier_wait (&b
);
101 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
103 puts ("parent thread: barrier_wait failed");
109 r
= pthread_kill (th
, SIGHUP
);
113 printf ("pthread_kill failed %m\n");
117 while (in_sh_body
== 0)
120 if (pthread_cancel (th
) != 0)
122 puts ("cancel failed");
126 /* This will cause the read in the initial thread to return. */
133 if (pthread_join (th
, &ret
) != 0)
135 puts ("join failed");
139 if (ret
!= PTHREAD_CANCELED
)
141 puts ("result is wrong");
145 if (cleanups
!= 0x1234L
)
147 printf ("called cleanups %lx\n", cleanups
);
151 if (pthread_barrier_destroy (&b
))
153 puts ("barrier destroy failed");
170 printf ("fork failed: %m\n");
177 if (waitpid (pid
, &status
, 0) < 0)
179 printf ("waitpid failed %m\n");
183 return !WIFEXITED (status
) || WEXITSTATUS (status
);
186 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
188 puts ("barrier_init failed");
193 if (pipe (fd
) != 0 || pipe (fd
+ 2) != 0)
195 puts ("pipe failed");
200 if (pthread_create (&th
, NULL
, tf
, (void *) pthread_self ()) != 0)
202 puts ("create failed");
206 pthread_cleanup_push (cl
, (void *) 4L);
208 pthread_cleanup_pop (0);
217 ss
.ss_sp
= malloc (2 * SIGSTKSZ
);
218 if (ss
.ss_sp
== NULL
)
220 puts ("failed to allocate alternate stack");
224 ss
.ss_size
= 2 * SIGSTKSZ
;
225 if (sigaltstack (&ss
, NULL
) < 0)
227 printf ("sigaltstack failed %m\n");
233 sigemptyset (&sa
.sa_mask
);
236 if (sigaction (SIGHUP
, &sa
, NULL
) != 0)
238 puts ("sigaction failed");
242 puts ("sa_flags = 0 test");
247 sigemptyset (&sa
.sa_mask
);
248 sa
.sa_flags
= SA_ONSTACK
;
250 if (sigaction (SIGHUP
, &sa
, NULL
) != 0)
252 puts ("sigaction failed");
256 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");
294 #define TEST_FUNCTION do_test ()
295 #include "../test-skeleton.c"