Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Move the uvm "loan" test to tests(7).
details: https://anonhg.NetBSD.org/src/rev/52fc85bad3a9
branches: trunk
changeset: 767283:52fc85bad3a9
user: jruoho <jruoho%NetBSD.org@localhost>
date: Thu Jul 14 11:08:44 2011 +0000
description:
Move the uvm "loan" test to tests(7).
diffstat:
regress/sys/uvm/Makefile | 4 +-
regress/sys/uvm/loan1/Makefile | 23 ------
regress/sys/uvm/loan1/loan1.c | 149 -----------------------------------------
tests/lib/libc/sys/t_mmap.c | 142 +++++++++++++++++++++++++++++++++++++-
4 files changed, 139 insertions(+), 179 deletions(-)
diffs (truncated from 389 to 300 lines):
diff -r 034026349f66 -r 52fc85bad3a9 regress/sys/uvm/Makefile
--- a/regress/sys/uvm/Makefile Thu Jul 14 10:43:55 2011 +0000
+++ b/regress/sys/uvm/Makefile Thu Jul 14 11:08:44 2011 +0000
@@ -1,9 +1,7 @@
-# $NetBSD: Makefile,v 1.9 2011/07/14 10:27:36 jruoho Exp $
+# $NetBSD: Makefile,v 1.10 2011/07/14 11:08:44 jruoho Exp $
.include <bsd.own.mk>
-SUBDIR+= loan1
-
.if !empty(SUPPORTED_CC:Mgcc)
SUBDIR+= stack_exec
.endif
diff -r 034026349f66 -r 52fc85bad3a9 regress/sys/uvm/loan1/Makefile
--- a/regress/sys/uvm/loan1/Makefile Thu Jul 14 10:43:55 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-# $NetBSD: Makefile,v 1.2 2006/10/14 20:57:10 bjh21 Exp $
-
-NOMAN= # defined
-
-PROG= loan1
-TESTFILE= XXX
-DEVZERO= /dev/zero
-CLEANFILES+= ${TESTFILE}
-
-regress: ${PROG}
- @dd if=/dev/zero of=${TESTFILE} bs=1024 seek=256 count=1
- @if ./loan1 ${TESTFILE}; then \
- echo "PASSED1"; \
- else \
- echo "FAILED1"; \
- fi
- @if ./loan1 ${DEVZERO}; then \
- echo "PASSED2"; \
- else \
- echo "FAILED2"; \
- fi
-
-.include <bsd.prog.mk>
diff -r 034026349f66 -r 52fc85bad3a9 regress/sys/uvm/loan1/loan1.c
--- a/regress/sys/uvm/loan1/loan1.c Thu Jul 14 10:43:55 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-/* $Id: loan1.c,v 1.5 2006/05/10 19:07:22 mrg Exp $ */
-
-/*-
- * Copyright (c)2004 YAMAMOTO Takashi,
- * 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 AUTHOR 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 AUTHOR 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/mman.h>
-#include <sys/socket.h>
-
-#include <err.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#define BUFSIZE (32 * 1024) /* enough size to trigger sosend_loan */
-
-int pgsize;
-
-void testloan(void *, void *, char, int);
-int main(int, char *[]);
-
-void
-testloan(void *vp, void *vp2, char pat, int docheck)
-{
- char buf[BUFSIZE];
- char backup[BUFSIZE];
-
- int fds[2];
- int val;
- ssize_t nwritten;
- ssize_t nread;
-
- if (docheck)
- memcpy(backup, vp, BUFSIZE);
-
- if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, fds))
- err(EXIT_FAILURE, "socketpair");
-
- val = BUFSIZE;
- if (setsockopt(fds[1], SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)))
- err(EXIT_FAILURE, "SO_RCVBUF");
-
- val = BUFSIZE;
- if (setsockopt(fds[0], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)))
- err(EXIT_FAILURE, "SO_SNDBUF");
-
- if (fcntl(fds[0], F_SETFL, O_NONBLOCK))
- err(EXIT_FAILURE, "fcntl");
-
- nwritten = write(fds[0], vp + pgsize, BUFSIZE - pgsize);
- if (nwritten == (ssize_t)-1)
- err(EXIT_FAILURE, "write");
-
- /* break loan */
- memset(vp2, pat, BUFSIZE);
-
- nread = read(fds[1], buf + pgsize, BUFSIZE - pgsize);
- if (nread == (ssize_t)-1)
- err(EXIT_FAILURE, "read");
-
- if (nread != nwritten)
- errx(EXIT_FAILURE, "short read");
-
- if (docheck && memcmp(backup, buf + pgsize, nread))
- errx(EXIT_FAILURE, "data mismatch");
-
- if (close(fds[0]) || close(fds[1]))
- err(EXIT_FAILURE, "close");
-}
-
-int
-main(int argc, char *argv[])
-{
- void *vp;
- void *vp2;
- int fd;
-
- pgsize = sysconf(_SC_PAGESIZE);
- if (pgsize == -1)
- err(EXIT_FAILURE, "_SC_PAGESIZE");
-
- fd = open(argv[1], O_RDWR);
- if (fd == -1)
- err(EXIT_FAILURE, "open");
-
- vp = mmap(NULL, BUFSIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_PRIVATE,
- fd, 0);
- if (vp == MAP_FAILED)
- err(EXIT_FAILURE, "mmap");
- vp2 = vp;
-
- testloan(vp, vp2, 'A', 0);
- testloan(vp, vp2, 'B', 1);
-
- if (munmap(vp, BUFSIZE))
- err(EXIT_FAILURE, "munmap");
-
- vp = mmap(NULL, BUFSIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED,
- fd, 0);
- if (vp == MAP_FAILED)
- err(EXIT_FAILURE, "mmap");
- vp2 = vp;
-
- testloan(vp, vp2, 'C', 0);
- testloan(vp, vp2, 'D', 1);
-
- if (munmap(vp, BUFSIZE))
- err(EXIT_FAILURE, "munmap");
-
- vp = mmap(NULL, BUFSIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED,
- fd, 0);
- if (vp == MAP_FAILED)
- err(EXIT_FAILURE, "mmap");
- vp2 = mmap(NULL, BUFSIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED,
- fd, 0);
- if (vp2 == MAP_FAILED)
- err(EXIT_FAILURE, "mmap");
-
- testloan(vp, vp2, 'E', 1);
-
- if (munmap(vp, BUFSIZE))
- err(EXIT_FAILURE, "munmap");
-
- exit(EXIT_SUCCESS);
-}
diff -r 034026349f66 -r 52fc85bad3a9 tests/lib/libc/sys/t_mmap.c
--- a/tests/lib/libc/sys/t_mmap.c Thu Jul 14 10:43:55 2011 +0000
+++ b/tests/lib/libc/sys/t_mmap.c Thu Jul 14 11:08:44 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.1 2011/07/07 06:57:54 jruoho Exp $ */
+/* $NetBSD: t_mmap.c,v 1.2 2011/07/14 11:08:45 jruoho Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -28,14 +28,42 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
+
+/*-
+ * Copyright (c)2004 YAMAMOTO Takashi,
+ * 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 AUTHOR 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 AUTHOR 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>
-__RCSID("$NetBSD: t_mmap.c,v 1.1 2011/07/07 06:57:54 jruoho Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.2 2011/07/14 11:08:45 jruoho Exp $");
#include <sys/param.h>
#include <sys/mman.h>
+#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/wait.h>
+#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
@@ -43,12 +71,13 @@
#include <string.h>
#include <unistd.h>
-#include <atf-c.h>
-
static long page = 0;
static char path[] = "mmap";
static void map_check(void *, int);
static void map_sighandler(int);
+static void testloan(void *, void *, char, int);
+
+#define BUFSIZE (32 * 1024) /* enough size to trigger sosend_loan */
static void
map_check(void *map, int flag)
@@ -63,6 +92,60 @@
ATF_REQUIRE(munmap(map, page) == 0);
}
+void
+testloan(void *vp, void *vp2, char pat, int docheck)
+{
+ char buf[BUFSIZE];
+ char backup[BUFSIZE];
+ ssize_t nwritten;
+ ssize_t nread;
+ int fds[2];
+ int val;
+
+ val = BUFSIZE;
+
+ if (docheck != 0)
+ (void)memcpy(backup, vp, BUFSIZE);
+
+ if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, fds) != 0)
+ atf_tc_fail("socketpair() failed");
+
+ val = BUFSIZE;
+
+ if (setsockopt(fds[1], SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)) != 0)
+ atf_tc_fail("setsockopt() failed, SO_RCVBUF");
+
+ val = BUFSIZE;
+
+ if (setsockopt(fds[0], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)) != 0)
+ atf_tc_fail("setsockopt() failed, SO_SNDBUF");
+
+ if (fcntl(fds[0], F_SETFL, O_NONBLOCK) != 0)
+ atf_tc_fail("fcntl() failed");
+
+ nwritten = write(fds[0], (char *)vp + page, BUFSIZE - page);
+
Home |
Main Index |
Thread Index |
Old Index