blob: 18d6e1230e1a6664d7e0d2294ca91782a3bdec5c [file] [log] [blame]
Roland McGrathe1e57b22007-07-05 18:43:18 +00001/* Test handle_group_exit () handling of a thread leader still alive with its
2 * thread child calling exit_group () and proper passing of the process exit
3 * code to the process parent of this whole thread group.
Denys Vlasenkob1efe532008-12-23 16:14:42 +00004 *
Roland McGrathe1e57b22007-07-05 18:43:18 +00005 * gcc -o test/leaderkill test/leaderkill.c -Wall -ggdb2 -pthread;./test/leaderkill & pid=$!;sleep 1;strace -o x -q ./strace -f -p $pid
6 * It must print: write(1, "OK\n", ...
7 */
8
9#include <pthread.h>
10#include <assert.h>
11#include <unistd.h>
12#include <stdlib.h>
13#include <stdio.h>
14#include <sys/wait.h>
15
Roland McGratha2eed4f2007-08-03 10:02:02 +000016static void *start0 (void *arg)
Roland McGrathe1e57b22007-07-05 18:43:18 +000017{
18 sleep (1);
19
20 exit (42);
21}
22
Roland McGratha2eed4f2007-08-03 10:02:02 +000023static void *start1 (void *arg)
24{
25 pause ();
26 /* NOTREACHED */
27 assert (0);
28}
29
Roland McGrathe1e57b22007-07-05 18:43:18 +000030int main (void)
31{
Roland McGratha2eed4f2007-08-03 10:02:02 +000032 pthread_t thread0;
Roland McGrathe1e57b22007-07-05 18:43:18 +000033 pthread_t thread1;
34 int i;
35 pid_t child, got_pid;
36 int status;
37
38 sleep (2);
39
40 child = fork ();
41 switch (child)
42 {
43 case -1:
44 abort ();
45 case 0:
Roland McGratha2eed4f2007-08-03 10:02:02 +000046 i = pthread_create (&thread0, NULL, start0, NULL);
Roland McGrathe1e57b22007-07-05 18:43:18 +000047 assert (i == 0);
Roland McGratha2eed4f2007-08-03 10:02:02 +000048 i = pthread_create (&thread1, NULL, start1, NULL);
49 assert (i == 0);
Roland McGrathe1e57b22007-07-05 18:43:18 +000050 pause ();
Roland McGrathe1e57b22007-07-05 18:43:18 +000051 /* NOTREACHED */
Roland McGratha2eed4f2007-08-03 10:02:02 +000052 assert (0);
Roland McGrathe1e57b22007-07-05 18:43:18 +000053 break;
54 default:
55 got_pid = waitpid (child, &status, 0);
56 assert (got_pid == child);
57 assert (WIFEXITED (status));
58 assert (WEXITSTATUS (status) == 42);
59 puts ("OK");
60 exit (0);
61 }
62 /* NOTREACHED */
63 abort ();
64}