]> granicus.if.org Git - strace/blob - test/leaderkill.c
2007-07-05 Jan Kratochvil <jan.kratochvil@redhat.com>
[strace] / test / leaderkill.c
1 /* 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.
4  * 
5  * 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
16 static void *start (void *arg)
17 {
18   sleep (1);
19
20   exit (42);
21 }
22
23 int main (void)
24 {
25   pthread_t thread1;
26   int i;
27   pid_t child, got_pid;
28   int status;
29
30   sleep (2);
31
32   child = fork ();
33   switch (child)
34     {
35       case -1:
36         abort ();
37       case 0:
38         i = pthread_create (&thread1, NULL, start, NULL);
39         assert (i == 0);
40 /* Two possible testcases; the second one passed even in the older versions.  */
41 #if 1
42         pause ();
43 #else
44         pthread_exit (NULL);
45 #endif
46         /* NOTREACHED */
47         abort ();
48         break;
49       default:
50         got_pid = waitpid (child, &status, 0);
51         assert (got_pid == child);
52         assert (WIFEXITED (status));
53         assert (WEXITSTATUS (status) == 42);
54         puts ("OK");
55         exit (0);
56     }
57   /* NOTREACHED */
58   abort ();
59 }