|
From: <sv...@va...> - 2011-02-09 11:29:20
|
Author: bart
Date: 2011-02-09 11:29:11 +0000 (Wed, 09 Feb 2011)
New Revision: 11526
Log:
DRD: added a test program that forks a process containing a detached thread.
Added:
trunk/drd/tests/threaded-fork.c
trunk/drd/tests/threaded-fork.stderr.exp
trunk/drd/tests/threaded-fork.vgtest
Modified:
trunk/drd/tests/Makefile.am
Modified: trunk/drd/tests/Makefile.am
===================================================================
--- trunk/drd/tests/Makefile.am 2011-02-09 10:34:00 UTC (rev 11525)
+++ trunk/drd/tests/Makefile.am 2011-02-09 11:29:11 UTC (rev 11526)
@@ -252,6 +252,8 @@
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 @@
sem_open \
sigalrm \
thread_name \
+ threaded-fork \
trylock \
unit_bitmap \
unit_vc
Added: trunk/drd/tests/threaded-fork.c
===================================================================
--- trunk/drd/tests/threaded-fork.c (rev 0)
+++ trunk/drd/tests/threaded-fork.c 2011-02-09 11:29:11 UTC (rev 11526)
@@ -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;
+}
Added: trunk/drd/tests/threaded-fork.stderr.exp
===================================================================
--- trunk/drd/tests/threaded-fork.stderr.exp (rev 0)
+++ trunk/drd/tests/threaded-fork.stderr.exp 2011-02-09 11:29:11 UTC (rev 11526)
@@ -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)
Added: trunk/drd/tests/threaded-fork.vgtest
===================================================================
--- trunk/drd/tests/threaded-fork.vgtest (rev 0)
+++ trunk/drd/tests/threaded-fork.vgtest 2011-02-09 11:29:11 UTC (rev 11526)
@@ -0,0 +1,2 @@
+prereq: ./supported_libpthread
+prog: threaded-fork
|