blob: c24a9f04a7281f33ea66c81a97dcaa840ba895f1 [file] [log] [blame]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001/* 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
Roland McGrathe1e57b22007-07-05 18:43:18 +00003 * code to the process parent of this whole thread group.
Dmitry V. Levin414fe7d2009-07-08 11:21:17 +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
Denys Vlasenko8ed57272009-02-25 14:24:02 +000016static void *start0(void *arg)
Roland McGrathe1e57b22007-07-05 18:43:18 +000017{
Denys Vlasenko8ed57272009-02-25 14:24:02 +000018 sleep(1);
19 exit(42);
Roland McGrathe1e57b22007-07-05 18:43:18 +000020}
21
Denys Vlasenko8ed57272009-02-25 14:24:02 +000022static void *start1(void *arg)
Roland McGratha2eed4f2007-08-03 10:02:02 +000023{
Denys Vlasenko8ed57272009-02-25 14:24:02 +000024 pause();
Roland McGrathe1e57b22007-07-05 18:43:18 +000025 /* NOTREACHED */
Denys Vlasenko8ed57272009-02-25 14:24:02 +000026 assert(0);
27}
28
29int 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
Denys Vlasenkob63256e2011-06-07 12:13:24 +020041 switch (child) {
Denys Vlasenko8ed57272009-02-25 14:24:02 +000042 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();
Roland McGrathe1e57b22007-07-05 18:43:18 +000064}