]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
DRD: added a test program that forks a process containing a detached thread.
authorBart Van Assche <bvanassche@acm.org>
Wed, 9 Feb 2011 11:29:11 +0000 (11:29 +0000)
committerBart Van Assche <bvanassche@acm.org>
Wed, 9 Feb 2011 11:29:11 +0000 (11:29 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11526

drd/tests/Makefile.am
drd/tests/threaded-fork.c [new file with mode: 0644]
drd/tests/threaded-fork.stderr.exp [new file with mode: 0644]
drd/tests/threaded-fork.vgtest [new file with mode: 0644]

index ea2813209a48e7d7ee556316353bb9555d1abd6e..695841ef0d1f3d03b2e97f8f399bb2ce254c50b3 100644 (file)
@@ -252,6 +252,8 @@ EXTRA_DIST =                                        \
        tc24_nonzero_sem.vgtest                     \
        thread_name.stderr.exp                      \
        thread_name.vgtest                          \
+       threaded-fork.stderr.exp                    \
+       threaded-fork.vgtest                        \
        trylock.stderr.exp                          \
        trylock.vgtest                              \
        unit_bitmap.stderr.exp                      \
@@ -294,6 +296,7 @@ check_PROGRAMS =      \
   sem_open            \
   sigalrm             \
   thread_name         \
+  threaded-fork       \
   trylock             \
   unit_bitmap         \
   unit_vc
diff --git a/drd/tests/threaded-fork.c b/drd/tests/threaded-fork.c
new file mode 100644 (file)
index 0000000..a83bf35
--- /dev/null
@@ -0,0 +1,55 @@
+/* fork a process that has created a detached thread. */
+
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <pthread.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <signal.h>
+
+static void *threadmain(void *dummy)
+{
+       sleep((unsigned long)dummy);
+       return NULL;
+}
+
+int main(int argc, char **argv)
+{
+        int ctr;
+       pid_t childpid;
+       pthread_t childthread;
+       void *res;
+       int status;
+
+       pthread_create(&childthread, NULL, threadmain, (void *)2);
+       pthread_detach(childthread);
+
+       childpid = fork();
+       switch (childpid) {
+       case 0:
+               pthread_create(&childthread, NULL, threadmain, 0);
+               pthread_join(childthread, &res);
+               exit(0);
+               break;
+       case -1:
+               perror("FAILED: fork failed\n");
+               break;
+       default:
+               break;
+       }
+
+       ctr = 0;
+       while (waitpid(childpid, &status, 0) != childpid) {
+               sleep(1);
+               ctr++;
+               if (ctr >= 10) {
+                 fprintf(stderr, "FAILED - timeout waiting for child\n");
+                 return 0;
+               }
+       }
+
+       fprintf(stderr, "PASS\n");
+
+       return 0;
+}
diff --git a/drd/tests/threaded-fork.stderr.exp b/drd/tests/threaded-fork.stderr.exp
new file mode 100644 (file)
index 0000000..79bbd8e
--- /dev/null
@@ -0,0 +1,6 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
+PASS
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/drd/tests/threaded-fork.vgtest b/drd/tests/threaded-fork.vgtest
new file mode 100644 (file)
index 0000000..9449729
--- /dev/null
@@ -0,0 +1,2 @@
+prereq: ./supported_libpthread
+prog: threaded-fork