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 test program for 3way select/poll colli...



details:   https://anonhg.NetBSD.org/src/rev/01387f97c091
branches:  trunk
changeset: 539979:01387f97c091
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sat Nov 30 09:31:31 2002 +0000

description:
add test program for 3way select/poll collision on descriptor, problem
described in kern/17517

diffstat:

 regress/sys/kern/Makefile      |   4 +-
 regress/sys/kern/poll/Makefile |  11 ++++
 regress/sys/kern/poll/poll3w.c |  95 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+), 2 deletions(-)

diffs (126 lines):

diff -r 1d4de1428996 -r 01387f97c091 regress/sys/kern/Makefile
--- a/regress/sys/kern/Makefile Sat Nov 30 07:06:40 2002 +0000
+++ b/regress/sys/kern/Makefile Sat Nov 30 09:31:31 2002 +0000
@@ -1,6 +1,6 @@
-#      $NetBSD: Makefile,v 1.19 2002/10/29 00:48:48 jdolecek Exp $
+#      $NetBSD: Makefile,v 1.20 2002/11/30 09:31:31 jdolecek Exp $
 
-SUBDIR+= execve extent getcwd ipf kqueue lock lockf pipe ras \
+SUBDIR+= execve extent getcwd ipf kqueue lock lockf pipe poll ras \
        sigtramp sysvmsg sysvsem sysvshm unfdpass writev
 
 .include <bsd.subdir.mk>
diff -r 1d4de1428996 -r 01387f97c091 regress/sys/kern/poll/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/sys/kern/poll/Makefile    Sat Nov 30 09:31:31 2002 +0000
@@ -0,0 +1,11 @@
+#      $NetBSD: Makefile,v 1.1 2002/11/30 09:31:32 jdolecek Exp $
+
+NOMAN=         # defined
+
+PROG=          poll3w
+WARNS=         2
+
+regress:
+       @./${PROG}
+
+.include <bsd.prog.mk>
diff -r 1d4de1428996 -r 01387f97c091 regress/sys/kern/poll/poll3w.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/sys/kern/poll/poll3w.c    Sat Nov 30 09:31:31 2002 +0000
@@ -0,0 +1,95 @@
+/*
+ * Check for 3-way collision for descriptor. First child comes
+ * and polls on descriptor, second child comes and polls, first
+ * child times out and exits, third child comes and polls.
+ * When the wakeup event happens, the two remaining children
+ * should both be awaken.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <poll.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int desc;
+
+static void
+child1(void)
+{
+       struct pollfd pfd;
+
+       pfd.fd = desc;
+       pfd.events = POLLIN | POLLHUP | POLLOUT;
+
+       (void) poll(&pfd, 1, 2000);
+       printf("child1 exit\n");
+}
+
+static void
+child2(void)
+{
+       struct pollfd pfd;
+
+       pfd.fd = desc;
+       pfd.events = POLLIN | POLLHUP | POLLOUT;
+
+       sleep(1);
+       (void) poll(&pfd, 1, INFTIM);
+       printf("child2 exit\n");
+}
+
+static void
+child3(void)
+{
+       struct pollfd pfd;
+
+       sleep(5);
+       pfd.fd = desc;
+       pfd.events = POLLIN | POLLHUP | POLLOUT;
+
+       (void) poll(&pfd, 1, INFTIM);
+       printf("child3 exit\n");
+}
+
+int main(void);
+
+int
+main(void)
+{
+       int pf[2];
+       int status, i;
+
+       pipe(pf);
+       desc = pf[0];
+
+       if (fork() == 0) {
+               close(pf[1]);
+               child1();
+               _exit(0);
+       }
+
+       if (fork() == 0) {
+               close(pf[1]);
+               child2();
+               _exit(0);
+       }
+
+       if (fork() == 0) {
+               close(pf[1]);
+               child3();
+               _exit(0);
+       }
+
+       sleep(10);
+
+       printf("parent write\n");
+       write(pf[1], "konec\n", 6);
+
+       for(i=0; i < 3; i++)
+               wait(&status);
+
+       printf("parent terminated\n");
+
+       return (0);
+}



Home | Main Index | Thread Index | Old Index