summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>2007-07-05 18:43:18 +0000
committerRoland McGrath <roland@redhat.com>2007-07-05 18:43:18 +0000
commite1e57b28407f808962bb4481d678ec03ec5838dd (patch)
tree8024dbd6919bfe02202d63105bbce4d2ed12a568 /test
parent0a463880341945df08b6dc79134dc78cc38dc283 (diff)
downloadstrace-e1e57b28407f808962bb4481d678ec03ec5838dd.tar.gz
strace-e1e57b28407f808962bb4481d678ec03ec5838dd.tar.bz2
strace-e1e57b28407f808962bb4481d678ec03ec5838dd.tar.xz
2007-07-05 Jan Kratochvil <jan.kratochvil@redhat.com>
* test/leaderkill.c: New file. * test/.cvsignore, test/Makefile: Add it.
Diffstat (limited to 'test')
-rw-r--r--test/.cvsignore1
-rw-r--r--test/Makefile6
-rw-r--r--test/leaderkill.c59
3 files changed, 64 insertions, 2 deletions
diff --git a/test/.cvsignore b/test/.cvsignore
index c054dba..c415255 100644
--- a/test/.cvsignore
+++ b/test/.cvsignore
@@ -3,3 +3,4 @@ sig
skodic
vfork
clone
+leaderkill
diff --git a/test/Makefile b/test/Makefile
index cc7c011..2879c08 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -2,8 +2,10 @@
# $Id$
#
-all: vfork fork sig skodic clone
+all: vfork fork sig skodic clone leaderkill
+
+leaderkill: LDFLAGS += -pthread
clean distclean:
- rm -f clone vfork fork sig *.o core
+ rm -f clone vfork fork sig leaderkill *.o core
diff --git a/test/leaderkill.c b/test/leaderkill.c
new file mode 100644
index 0000000..51f0c6c
--- /dev/null
+++ b/test/leaderkill.c
@@ -0,0 +1,59 @@
+/* Test handle_group_exit () handling of a thread leader still alive with its
+ * thread child calling exit_group () and proper passing of the process exit
+ * code to the process parent of this whole thread group.
+ *
+ * gcc -o test/leaderkill test/leaderkill.c -Wall -ggdb2 -pthread;./test/leaderkill & pid=$!;sleep 1;strace -o x -q ./strace -f -p $pid
+ * It must print: write(1, "OK\n", ...
+ */
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/wait.h>
+
+static void *start (void *arg)
+{
+ sleep (1);
+
+ exit (42);
+}
+
+int main (void)
+{
+ pthread_t thread1;
+ int i;
+ pid_t child, got_pid;
+ int status;
+
+ sleep (2);
+
+ child = fork ();
+ switch (child)
+ {
+ case -1:
+ abort ();
+ case 0:
+ i = pthread_create (&thread1, NULL, start, NULL);
+ assert (i == 0);
+/* Two possible testcases; the second one passed even in the older versions. */
+#if 1
+ pause ();
+#else
+ pthread_exit (NULL);
+#endif
+ /* NOTREACHED */
+ abort ();
+ break;
+ default:
+ got_pid = waitpid (child, &status, 0);
+ assert (got_pid == child);
+ assert (WIFEXITED (status));
+ assert (WEXITSTATUS (status) == 42);
+ puts ("OK");
+ exit (0);
+ }
+ /* NOTREACHED */
+ abort ();
+}