]> granicus.if.org Git - strace/blob - test/leaderkill.c
Fix preadv/pwritev offset decoding
[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 *start0(void *arg)
17 {
18         sleep(1);
19         exit(42);
20 }
21
22 static void *start1(void *arg)
23 {
24         pause();
25         /* NOTREACHED */
26         assert(0);
27 }
28
29 int main(int argc, char *argv[])
30 {
31         pthread_t thread0;
32         pthread_t thread1;
33         pid_t child, got_pid;
34         int status;
35         int i;
36
37         sleep(2);
38
39         child = fork();
40
41         switch (child) {
42         case -1:
43                 abort();
44         case 0:
45                 i = pthread_create(&thread0, NULL, start0, NULL);
46                 assert(i == 0);
47                 i = pthread_create(&thread1, NULL, start1, NULL);
48                 assert(i == 0);
49                 pause();
50                 /* NOTREACHED */
51                 assert(0);
52                 break;
53         default:
54                 got_pid = waitpid(child, &status, 0);
55                 assert(got_pid == child);
56                 assert(WIFEXITED(status));
57                 assert(WEXITSTATUS(status) == 42);
58                 puts("OK");
59                 exit(0);
60         }
61
62         /* NOTREACHED */
63         abort();
64 }