Module Name: src
Committed By: jruoho
Date: Sat Oct 15 06:17:02 UTC 2011
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/kernel: Makefile
src/tests/lib/libc/sys: Makefile
Added Files:
src/tests/lib/libc/sys: t_pipe.c
Removed Files:
src/tests/kernel: t_pipe.c
Log Message:
Move the pipe(2) test to the right place.
To generate a diff of this commit:
cvs rdiff -u -r1.402 -r1.403 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.14 -r1.15 src/tests/kernel/Makefile
cvs rdiff -u -r1.1 -r0 src/tests/kernel/t_pipe.c
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_pipe.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.402 src/distrib/sets/lists/tests/mi:1.403
--- src/distrib/sets/lists/tests/mi:1.402 Sat Oct 15 06:10:26 2011
+++ src/distrib/sets/lists/tests/mi Sat Oct 15 06:17:02 2011
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.402 2011/10/15 06:10:26 jruoho Exp $
+# $NetBSD: mi,v 1.403 2011/10/15 06:17:02 jruoho Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -325,7 +325,7 @@
./usr/libdata/debug/usr/tests/kernel/t_lock.debug tests-kernel-tests debug,atf
./usr/libdata/debug/usr/tests/kernel/t_lwpctl.debug tests-kernel-tests debug,atf
./usr/libdata/debug/usr/tests/kernel/t_mkdir.debug tests-kernel-tests debug,atf
-./usr/libdata/debug/usr/tests/kernel/t_pipe.debug tests-kernel-tests debug,atf
+./usr/libdata/debug/usr/tests/kernel/t_pipe.debug tests-obsolete obsolete
./usr/libdata/debug/usr/tests/kernel/t_poll3w.debug tests-kernel-tests debug,atf
./usr/libdata/debug/usr/tests/kernel/t_pollts.debug tests-obsolete obsolete
./usr/libdata/debug/usr/tests/kernel/t_posix_fadvise.debug tests-obsolete obsolete
@@ -510,6 +510,7 @@
./usr/libdata/debug/usr/tests/lib/libc/sys/t_mprotect.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/sys/t_msync.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/sys/t_nanosleep.debug tests-lib-debug debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_pipe.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/sys/t_poll.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/sys/t_posix_fadvise.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/sys/t_revoke.debug tests-lib-debug debug,atf
@@ -1849,7 +1850,7 @@
./usr/tests/kernel/t_lock tests-kernel-tests atf
./usr/tests/kernel/t_lwpctl tests-kernel-tests atf
./usr/tests/kernel/t_mkdir tests-kernel-tests atf
-./usr/tests/kernel/t_pipe tests-kernel-tests atf
+./usr/tests/kernel/t_pipe tests-obsolete obsolete
./usr/tests/kernel/t_poll3w tests-kernel-tests atf
./usr/tests/kernel/t_pollts tests-obsolete obsolete
./usr/tests/kernel/t_posix_fadvise tests-obsolete obsolete
@@ -2123,6 +2124,7 @@
./usr/tests/lib/libc/sys/t_mprotect tests-lib-tests atf
./usr/tests/lib/libc/sys/t_msync tests-lib-tests atf
./usr/tests/lib/libc/sys/t_nanosleep tests-lib-tests atf
+./usr/tests/lib/libc/sys/t_pipe tests-lib-tests atf
./usr/tests/lib/libc/sys/t_poll tests-lib-tests atf
./usr/tests/lib/libc/sys/t_posix_fadvise tests-lib-tests atf
./usr/tests/lib/libc/sys/t_revoke tests-lib-tests atf
Index: src/tests/kernel/Makefile
diff -u src/tests/kernel/Makefile:1.14 src/tests/kernel/Makefile:1.15
--- src/tests/kernel/Makefile:1.14 Sat Oct 15 06:10:26 2011
+++ src/tests/kernel/Makefile Sat Oct 15 06:17:02 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.14 2011/10/15 06:10:26 jruoho Exp $
+# $NetBSD: Makefile,v 1.15 2011/10/15 06:17:02 jruoho Exp $
NOMAN= # defined
@@ -11,7 +11,6 @@ TESTS_SUBDIRS= kqueue tty
TESTS_C= t_lock
TESTS_C+= t_lwpctl
TESTS_C+= t_mkdir
-TESTS_C+= t_pipe
TESTS_C+= t_poll3w
TESTS_C+= t_pty
TESTS_C+= t_rnd
Index: src/tests/lib/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.10 src/tests/lib/libc/sys/Makefile:1.11
--- src/tests/lib/libc/sys/Makefile:1.10 Sat Oct 15 06:10:26 2011
+++ src/tests/lib/libc/sys/Makefile Sat Oct 15 06:17:02 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.10 2011/10/15 06:10:26 jruoho Exp $
+# $NetBSD: Makefile,v 1.11 2011/10/15 06:17:02 jruoho Exp $
MKMAN= no
@@ -31,6 +31,7 @@ TESTS_C+= t_mmap
TESTS_C+= t_mprotect
TESTS_C+= t_msync
TESTS_C+= t_nanosleep
+TESTS_C+= t_pipe
TESTS_C+= t_posix_fadvise
TESTS_C+= t_poll
TESTS_C+= t_revoke
Added files:
Index: src/tests/lib/libc/sys/t_pipe.c
diff -u /dev/null src/tests/lib/libc/sys/t_pipe.c:1.1
--- /dev/null Sat Oct 15 06:17:02 2011
+++ src/tests/lib/libc/sys/t_pipe.c Sat Oct 15 06:17:02 2011
@@ -0,0 +1,162 @@
+/* $NetBSD: t_pipe.c,v 1.1 2011/10/15 06:17:02 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_pipe.c,v 1.1 2011/10/15 06:17:02 jruoho Exp $");
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <errno.h>
+#include <poll.h>
+#include <sched.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "../../../h_macros.h"
+
+static pid_t pid;
+static int nsiginfo = 0;
+
+/*
+ * This is used for both parent and child. Handle parent's SIGALRM,
+ * the childs SIGINFO doesn't need anything.
+ */
+static void
+sighand(int sig)
+{
+ if (sig == SIGALRM) {
+ kill(pid, SIGINFO);
+ }
+ if (sig == SIGINFO) {
+ nsiginfo++;
+ }
+}
+
+ATF_TC(pipe_restart);
+ATF_TC_HEAD(pipe_restart, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks that writing to pipe "
+ "works correctly after being interrupted and restarted "
+ "(kern/14087)");
+}
+
+ATF_TC_BODY(pipe_restart, tc)
+{
+ int pp[2], st;
+ ssize_t sz, todo, done;
+ char *f;
+ sigset_t asigset, osigset, emptysigset;
+
+ /* Initialise signal masks */
+ RL(sigemptyset(&emptysigset));
+ RL(sigemptyset(&asigset));
+ RL(sigaddset(&asigset, SIGINFO));
+
+ /* Register signal handlers for both read and writer */
+ REQUIRE_LIBC(signal(SIGINFO, sighand), SIG_ERR);
+ REQUIRE_LIBC(signal(SIGALRM, sighand), SIG_ERR);
+
+ todo = 2 * 1024 * 1024;
+ REQUIRE_LIBC(f = malloc(todo), NULL);
+
+ RL(pipe(pp));
+
+ RL(pid = fork());
+ if (pid == 0) {
+ /* child */
+ RL(close(pp[1]));
+
+ /* Do inital write. This should succeed, make
+ * the other side do partial write and wait for us to pick
+ * rest up.
+ */
+ RL(done = read(pp[0], f, 128 * 1024));
+
+ /* Wait until parent is alarmed and awakens us */
+ RL(sigprocmask(SIG_BLOCK, &asigset, &osigset));
+ while (nsiginfo == 0) {
+ if (sigsuspend(&emptysigset) != -1 || errno != EINTR)
+ atf_tc_fail("sigsuspend(&emptysigset): %s",
+ strerror(errno));
+ }
+ RL(sigprocmask(SIG_SETMASK, &osigset, NULL));
+
+ /* 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
+ */
+ printf("Read: %#zx\n", (size_t)done);
+ printf("Expected: %#zx\n", (size_t)todo);
+
+ exit(done != todo);
+
+ /* NOTREACHED */
+ } else {
+ RL(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.
+ */
+ (void)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 */
+ RL(close(pp[1]));
+
+ /* And pickup child's exit status */
+ RL(waitpid(pid, &st, 0));
+
+ ATF_REQUIRE_EQ(WEXITSTATUS(st), 0);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, pipe_restart);
+
+ return atf_no_error();
+}