Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/regress/sys/kern add regression test for the recently found&...
details: https://anonhg.NetBSD.org/src/rev/ded95b8744b6
branches: trunk
changeset: 515595:ded95b8744b6
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Sat Sep 29 13:54:19 2001 +0000
description:
add regression test for the recently found&fixed NEW_PIPE problem
diffstat:
regress/sys/kern/Makefile | 5 +-
regress/sys/kern/pipe/Makefile | 11 ++++
regress/sys/kern/pipe/pipe1.c | 99 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 113 insertions(+), 2 deletions(-)
diffs (130 lines):
diff -r 88cee7d382cf -r ded95b8744b6 regress/sys/kern/Makefile
--- a/regress/sys/kern/Makefile Sat Sep 29 13:48:11 2001 +0000
+++ b/regress/sys/kern/Makefile Sat Sep 29 13:54:19 2001 +0000
@@ -1,5 +1,6 @@
-# $NetBSD: Makefile,v 1.10 2000/06/12 14:42:02 sommerfeld Exp $
+# $NetBSD: Makefile,v 1.11 2001/09/29 13:54:19 jdolecek Exp $
-SUBDIR+= execve extent getcwd lockf sigtramp sysvmsg sysvsem sysvshm unfdpass
+SUBDIR+= execve extent getcwd lockf pipe sigtramp sysvmsg sysvsem sysvshm \
+ unfdpass
.include <bsd.subdir.mk>
diff -r 88cee7d382cf -r ded95b8744b6 regress/sys/kern/pipe/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/sys/kern/pipe/Makefile Sat Sep 29 13:54:19 2001 +0000
@@ -0,0 +1,11 @@
+# $NetBSD: Makefile,v 1.1 2001/09/29 13:54:20 jdolecek Exp $
+
+PROG= pipe1
+MKMAN= no
+
+all: ${PROG}
+
+regress: ${PROG}
+ @${.OBJDIR}/${PROG} || ( echo 'pipe write restart test failed' && exit 1 )
+
+.include <bsd.prog.mk>
diff -r 88cee7d382cf -r ded95b8744b6 regress/sys/kern/pipe/pipe1.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/sys/kern/pipe/pipe1.c Sat Sep 29 13:54:19 2001 +0000
@@ -0,0 +1,99 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <poll.h>
+#include <sched.h>
+#include <signal.h>
+#include <sys/wait.h>
+
+/*
+ * Test sanity ws. interrupted & restarted write(2) calls.
+ */
+
+pid_t pid;
+
+/*
+ * This is used for both parent and child. Handle parent's SIGALRM,
+ * the childs SIGINFO doesn't need anything.
+ */
+void
+sighand(int sig)
+{
+ if (sig == SIGALRM)
+ kill(pid, SIGINFO);
+}
+
+int
+main()
+{
+ int pp[2], st;
+ ssize_t sz, todo, done;
+ char *f;
+
+ todo = 2 * 1024 * 1024;
+ f = (char *) malloc(todo);
+
+ pipe(pp);
+
+ switch((pid = fork())) {
+ case 0: /* child */
+ close(pp[1]);
+ signal(SIGINFO, sighand);
+
+ /* Do inital write. This should succeed, make
+ * the other side do partial write and wait for us to pick
+ * rest up.
+ */
+ done = read(pp[0], f, 128 * 1024);
+
+ /* Wait until parent is alarmed and awakens us */
+ pause();
+
+ /* Read all what parent wants to give us */
+ while((sz = read(pp[0], f, 1024 * 1024)) > 0)
+ done += sz;
+
+ /*
+ * Exit with 1 if number of bytes read doesn't match
+ * number of expected bytes
+ */
+ exit(done != todo);
+
+ break;
+
+ case -1: /* error */
+ perror("fork");
+ _exit(1);
+ /* NOTREACHED */
+
+ default:
+ signal(SIGALRM, sighand);
+ close(pp[0]);
+
+ /*
+ * Arrange for alarm after two seconds. Since we have
+ * handler setup for SIGARLM, the write(2) call should
+ * be restarted internally by kernel.
+ */
+ alarm(2);
+
+ /* We write exactly 'todo' bytes. The very first write(2)
+ * should partially succeed, block and eventually
+ * be restarted by kernel
+ */
+ while(todo > 0 && ((sz = write(pp[1], f, todo)) > 0))
+ todo -= sz;
+
+ /* Close the pipe, so that child would stop reading */
+ close(pp[1]);
+
+ /* And pickup child's exit status */
+ waitpid(pid, &st, 0);
+
+ exit(WEXITSTATUS(st) != 0);
+ /* NOTREACHED */
+ }
+
+ return (2);
+}
Home |
Main Index |
Thread Index |
Old Index