Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/regress/lib/libpthread/fork Check that child process doesn't...



details:   https://anonhg.NetBSD.org/src/rev/dcca71cdf528
branches:  trunk
changeset: 545543:dcca71cdf528
user:      lha <lha%NetBSD.org@localhost>
date:      Thu Apr 10 18:50:05 2003 +0000

description:
Check that child process doesn't get threads, also make sure sleep
works in child. ok by nathanw

diffstat:

 regress/lib/libpthread/fork/Makefile |  14 ++++++
 regress/lib/libpthread/fork/fork.c   |  76 ++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+), 0 deletions(-)

diffs (98 lines):

diff -r f5b670905ffb -r dcca71cdf528 regress/lib/libpthread/fork/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libpthread/fork/Makefile      Thu Apr 10 18:50:05 2003 +0000
@@ -0,0 +1,14 @@
+#      $NetBSD: Makefile,v 1.1 2003/04/10 18:50:05 lha Exp $
+
+WARNS=1
+
+PROG=   fork
+
+LDADD= -lpthread
+
+NOMAN=
+
+regress:
+       ./fork
+
+.include <bsd.prog.mk>
diff -r f5b670905ffb -r dcca71cdf528 regress/lib/libpthread/fork/fork.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libpthread/fork/fork.c        Thu Apr 10 18:50:05 2003 +0000
@@ -0,0 +1,76 @@
+/*     $NetBSD: fork.c,v 1.1 2003/04/10 18:50:05 lha Exp $     */
+
+/*
+ * Regression test for sigsuspend in libpthread when pthread lib isn't
+ * initialized.
+ *
+ * Written by Love Hörnquist Åstrand <lha%netbsd.org@localhost>, March 2003.
+ * Public domain.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <pthread.h>
+#include <unistd.h>
+
+static pid_t parent;
+static int thread_survived = 0;
+
+static void *
+print_pid(void *arg)
+{
+       sleep(3);
+
+       thread_survived = 1;
+       if (parent != getpid()) {
+               kill(parent, SIGKILL);
+               errx(1, "child thread running");
+       }
+       return NULL;
+}
+
+int
+main(int argc, char **argv)
+{
+       pthread_t p;
+       pid_t fork_pid;
+       int ret;
+       
+       parent = getpid();
+       
+       pthread_create(&p, NULL, print_pid, NULL);
+
+       fork_pid = fork();
+       if (fork_pid == -1)
+               err(1, "fork failed");
+    
+       if (fork_pid) {
+               ret = pthread_join(p, NULL);
+               if (ret && fork_pid != 0)
+                       errx(1, "join failed in parent");
+
+               if (!thread_survived)
+                       errx(1, "child_thread did NOT survive");
+
+               if (fork_pid != 0) {
+                       int status;
+                       waitpid(fork_pid, &status, 0);
+                       if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+                               errx(1, "child died wrongly");
+               }
+       } else {
+               sleep(5);
+
+               if (thread_survived) {
+                       kill(parent, SIGKILL);
+                       errx(1, "child_thread survived");
+               }
+       }
+
+       return 0;
+}



Home | Main Index | Thread Index | Old Index