summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/lib/librumphijack
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2014-10-02 23:26:49 +0000
committerngie <ngie@FreeBSD.org>2014-10-02 23:26:49 +0000
commit3f09b8d0af642c2aeb96a4d667cefb7fe3bce443 (patch)
tree544932e2a2c5a5a202b752beefba0b3e327b3858 /contrib/netbsd-tests/lib/librumphijack
parentb941fec92da62b0eab650295f4e8a381dbbc04b4 (diff)
parente1f2d32c0e0678782c353c48364cddedfae58b0a (diff)
downloadFreeBSD-src-3f09b8d0af642c2aeb96a4d667cefb7fe3bce443.zip
FreeBSD-src-3f09b8d0af642c2aeb96a4d667cefb7fe3bce443.tar.gz
Import the NetBSD test suite from ^/vendor/NetBSD/tests/09.30.2014_20.45 ,
minus the vendor Makefiles Provide directions for how to bootstrap the vendor sources in FREEBSD-upgrade MFC after 2 weeks Discussed with: rpaulo Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'contrib/netbsd-tests/lib/librumphijack')
-rw-r--r--contrib/netbsd-tests/lib/librumphijack/h_client.c138
-rw-r--r--contrib/netbsd-tests/lib/librumphijack/h_cwd.c168
-rw-r--r--contrib/netbsd-tests/lib/librumphijack/h_netget.c101
-rw-r--r--contrib/netbsd-tests/lib/librumphijack/index.html5
-rw-r--r--contrib/netbsd-tests/lib/librumphijack/netstat.expout6
-rw-r--r--contrib/netbsd-tests/lib/librumphijack/ssh_config.in14
-rw-r--r--contrib/netbsd-tests/lib/librumphijack/ssh_host_key15
-rw-r--r--contrib/netbsd-tests/lib/librumphijack/ssh_host_key.pub1
-rw-r--r--contrib/netbsd-tests/lib/librumphijack/sshd_config.in39
-rwxr-xr-xcontrib/netbsd-tests/lib/librumphijack/t_asyncio.sh94
-rwxr-xr-xcontrib/netbsd-tests/lib/librumphijack/t_config.sh54
-rwxr-xr-xcontrib/netbsd-tests/lib/librumphijack/t_cwd.sh72
-rwxr-xr-xcontrib/netbsd-tests/lib/librumphijack/t_sh.sh91
-rwxr-xr-xcontrib/netbsd-tests/lib/librumphijack/t_tcpip.sh268
-rwxr-xr-xcontrib/netbsd-tests/lib/librumphijack/t_vfs.sh223
15 files changed, 1289 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/librumphijack/h_client.c b/contrib/netbsd-tests/lib/librumphijack/h_client.c
new file mode 100644
index 0000000..20add73
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/h_client.c
@@ -0,0 +1,138 @@
+/* $NetBSD: h_client.c,v 1.8 2012/04/20 05:15:11 jruoho Exp $ */
+
+/*
+ * Copyright (c) 2011 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/types.h>
+#include <sys/poll.h>
+#include <sys/select.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main(int argc, char *argv[])
+{
+
+ if (argc != 2) {
+ errx(1, "need testname as param");
+ }
+
+ if (strcmp(argv[1], "select_timeout") == 0) {
+ fd_set rfds;
+ struct timeval tv;
+ int pipefd[2];
+ int rv;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 1;
+
+ if (pipe(pipefd) == -1)
+ err(EXIT_FAILURE, "pipe");
+ FD_ZERO(&rfds);
+ FD_SET(pipefd[0], &rfds);
+
+ rv = select(pipefd[0]+1, &rfds, NULL, NULL, &tv);
+ if (rv == -1)
+ err(EXIT_FAILURE, "select");
+ if (rv != 0)
+ errx(EXIT_FAILURE, "select succesful");
+
+ if (FD_ISSET(pipefd[0], &rfds))
+ errx(EXIT_FAILURE, "stdin fileno is still set");
+ return EXIT_SUCCESS;
+ } else if (strcmp(argv[1], "select_allunset") == 0) {
+ fd_set fds;
+ struct timeval tv;
+ int rv;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 1;
+
+ FD_ZERO(&fds);
+
+ rv = select(100, &fds, &fds, &fds, &tv);
+ if (rv == -1)
+ err(EXIT_FAILURE, "select");
+ if (rv != 0)
+ errx(EXIT_FAILURE, "select succesful");
+
+ rv = select(0, NULL, NULL, NULL, &tv);
+ if (rv == -1)
+ err(EXIT_FAILURE, "select2");
+ if (rv != 0)
+ errx(EXIT_FAILURE, "select2 succesful");
+
+ return EXIT_SUCCESS;
+ } else if (strcmp(argv[1], "invafd") == 0) {
+ struct pollfd pfd[2];
+ int fd, rv;
+
+ fd = open("/rump/dev/null", O_RDWR);
+ if (fd == -1)
+ err(EXIT_FAILURE, "open");
+ close(fd);
+
+ pfd[0].fd = STDIN_FILENO;
+ pfd[0].events = POLLIN;
+ pfd[1].fd = fd;
+ pfd[1].events = POLLIN;
+
+ if ((rv = poll(pfd, 2, INFTIM)) != 1)
+ errx(EXIT_FAILURE, "poll unexpected rv %d (%d)",
+ rv, errno);
+ if (pfd[1].revents != POLLNVAL || pfd[0].revents != 0)
+ errx(EXIT_FAILURE, "poll unexpected revents");
+
+ return EXIT_SUCCESS;
+ } else if (strcmp(argv[1], "fdoff8") == 0) {
+
+ (void)closefrom(0);
+
+ int fd;
+
+ do {
+ if ((fd = open("/dev/null", O_RDWR)) == -1)
+ err(EXIT_FAILURE, "open1");
+ } while (fd < 7);
+ fd = open("/dev/null", O_RDWR);
+ if (fd != -1 || errno != ENFILE)
+ errx(EXIT_FAILURE, "unexpected fd8 %d %d", fd, errno);
+ if (fcntl(0, F_MAXFD) != 7)
+ errx(EXIT_FAILURE, "fd leak?");
+ if ((fd = open("/rump/dev/null", O_RDWR)) != 8)
+ errx(EXIT_FAILURE, "rump open %d %d", fd, errno);
+ return EXIT_SUCCESS;
+ } else {
+ return ENOTSUP;
+ }
+}
diff --git a/contrib/netbsd-tests/lib/librumphijack/h_cwd.c b/contrib/netbsd-tests/lib/librumphijack/h_cwd.c
new file mode 100644
index 0000000..dfc509d
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/h_cwd.c
@@ -0,0 +1,168 @@
+/* $NetBSD: h_cwd.c,v 1.3 2012/04/17 09:23:21 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 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/types.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static const char *prefix;
+static size_t prefixlen;
+static char buf[1024];
+static char pwd[1024];
+
+static const char *
+makepath(const char *tail)
+{
+
+ strcpy(buf, prefix);
+ if (prefix[prefixlen-1] != '/')
+ strcat(buf, "/");
+ strcat(buf, tail);
+
+ return buf;
+}
+
+static void
+dochdir(const char *path, const char *errmsg)
+{
+
+ if (chdir(path) == -1)
+ err(EXIT_FAILURE, "%s", errmsg);
+}
+
+static void
+dofchdir(const char *path, const char *errmsg)
+{
+ int fd;
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ err(EXIT_FAILURE, "open %s", errmsg);
+ if (fchdir(fd) == -1)
+ err(EXIT_FAILURE, "fchdir %s", errmsg);
+ close(fd);
+}
+static void (*thechdir)(const char *, const char *);
+
+static void
+simple(void)
+{
+
+ thechdir(prefix, "chdir1");
+ if (getcwd(pwd, sizeof(pwd)) == NULL)
+ err(EXIT_FAILURE, "getcwd1");
+ if (strcmp(pwd, prefix) != 0)
+ errx(EXIT_FAILURE, "strcmp1");
+
+ if (mkdir("dir", 0777) == -1)
+ err(EXIT_FAILURE, "mkdir2");
+ thechdir("dir", "chdir2");
+ if (getcwd(pwd, sizeof(pwd)) == NULL)
+ err(EXIT_FAILURE, "getcwd2");
+ if (strcmp(pwd, makepath("dir")) != 0)
+ errx(EXIT_FAILURE, "strcmp2");
+
+ if (mkdir("dir", 0777) == -1)
+ err(EXIT_FAILURE, "mkdir3");
+ thechdir("dir", "chdir3");
+ if (getcwd(pwd, sizeof(pwd)) == NULL)
+ err(EXIT_FAILURE, "getcwd3");
+ if (strcmp(pwd, makepath("dir/dir")) != 0)
+ errx(EXIT_FAILURE, "strcmp3");
+
+ thechdir("..", "chdir4");
+ if (getcwd(pwd, sizeof(pwd)) == NULL)
+ err(EXIT_FAILURE, "getcwd4");
+ if (strcmp(pwd, makepath("dir")) != 0)
+ errx(EXIT_FAILURE, "strcmp4");
+
+
+ thechdir("../../../../../../..", "chdir5");
+ if (getcwd(pwd, sizeof(pwd)) == NULL)
+ err(EXIT_FAILURE, "getcwd5");
+ if (strcmp(pwd, prefix) != 0)
+ errx(EXIT_FAILURE, "strcmp5");
+
+ thechdir("/", "chdir6");
+ if (getcwd(pwd, sizeof(pwd)) == NULL)
+ err(EXIT_FAILURE, "getcwd6");
+ if (strcmp(pwd, "/") != 0)
+ errx(EXIT_FAILURE, "strcmp6");
+}
+
+static void
+symlinktest(void)
+{
+
+ thechdir(prefix, "chdir1");
+ if (mkdir("adir", 0777) == -1)
+ err(EXIT_FAILURE, "mkdir1");
+ if (mkdir("anotherdir", 0777) == -1)
+ err(EXIT_FAILURE, "mkdir2");
+
+ if (symlink("/adir", "anotherdir/lincthesink") == -1)
+ err(EXIT_FAILURE, "symlink");
+
+ thechdir("anotherdir/lincthesink", "chdir2");
+ if (getcwd(pwd, sizeof(pwd)) == NULL)
+ err(EXIT_FAILURE, "getcwd");
+ if (strcmp(pwd, makepath("adir")) != 0)
+ errx(EXIT_FAILURE, "strcmp");
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ if (argc != 4)
+ errx(1, "usage");
+
+ prefix = argv[1];
+ prefixlen = strlen(argv[1]);
+
+ if (strcmp(argv[3], "chdir") == 0)
+ thechdir = dochdir;
+ else if (strcmp(argv[3], "fchdir") == 0)
+ thechdir = dofchdir;
+ else
+ errx(EXIT_FAILURE, "invalid chdir type");
+
+ if (strcmp(argv[2], "simple") == 0)
+ simple();
+ if (strcmp(argv[2], "symlink") == 0)
+ symlinktest();
+
+ return EXIT_SUCCESS;
+}
diff --git a/contrib/netbsd-tests/lib/librumphijack/h_netget.c b/contrib/netbsd-tests/lib/librumphijack/h_netget.c
new file mode 100644
index 0000000..4d8b408
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/h_netget.c
@@ -0,0 +1,101 @@
+/* $NetBSD: h_netget.c,v 1.2 2012/04/17 09:23:21 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 Antti Kantee. 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 ``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.
+ */
+
+/*
+ * simple utility to fetch a webpage. we wouldn't need this
+ * if we had something like netcat in base
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: h_netget.c,v 1.2 2012/04/17 09:23:21 jruoho Exp $");
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <arpa/inet.h>
+
+#include <netinet/in.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define GETSTR "GET / HTTP/1.0\n\n"
+
+int
+main(int argc, char *argv[])
+{
+ char buf[8192];
+ struct sockaddr_in sin;
+ ssize_t n;
+ int s, fd;
+
+ setprogname(argv[0]);
+ if (argc != 4) {
+ fprintf(stderr, "usage: %s address port savefile\n",
+ getprogname());
+ return EXIT_FAILURE;
+ }
+
+ s = socket(PF_INET, SOCK_STREAM, 0);
+ if (s == -1)
+ err(EXIT_FAILURE, "socket");
+
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_len = sizeof(sin);
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(atoi(argv[2]));
+ sin.sin_addr.s_addr = inet_addr(argv[1]);
+
+ fd = open(argv[3], O_CREAT | O_RDWR, 0644);
+ if (fd == -1)
+ err(EXIT_FAILURE, "open");
+ if (ftruncate(fd, 0) == -1)
+ err(EXIT_FAILURE, "ftruncate savefile");
+
+ if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) == -1)
+ err(EXIT_FAILURE, "connect");
+
+ if (write(s, GETSTR, strlen(GETSTR)) != strlen(GETSTR))
+ err(EXIT_FAILURE, "socket write");
+
+ for (;;) {
+ n = read(s, buf, sizeof(buf));
+ if (n == 0)
+ break;
+ if (n == -1)
+ err(EXIT_FAILURE, "socket read");
+
+ if (write(fd, buf, n) != n)
+ err(EXIT_FAILURE, "write file");
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/contrib/netbsd-tests/lib/librumphijack/index.html b/contrib/netbsd-tests/lib/librumphijack/index.html
new file mode 100644
index 0000000..1d8679c
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/index.html
@@ -0,0 +1,5 @@
+<html><head>
+<title>test page</title>
+</head><body>
+i am a test, how do you do?
+</body></html>
diff --git a/contrib/netbsd-tests/lib/librumphijack/netstat.expout b/contrib/netbsd-tests/lib/librumphijack/netstat.expout
new file mode 100644
index 0000000..1a9a2a1
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/netstat.expout
@@ -0,0 +1,6 @@
+Active Internet connections (including servers)
+Proto Recv-Q Send-Q Local Address Foreign Address State
+tcp 0 0 *.http *.* LISTEN
+Active Internet6 connections (including servers)
+Proto Recv-Q Send-Q Local Address Foreign Address (state)
+tcp6 0 0 *.http *.* LISTEN
diff --git a/contrib/netbsd-tests/lib/librumphijack/ssh_config.in b/contrib/netbsd-tests/lib/librumphijack/ssh_config.in
new file mode 100644
index 0000000..73b83c8
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/ssh_config.in
@@ -0,0 +1,14 @@
+# $NetBSD: ssh_config.in,v 1.1 2011/02/14 15:14:00 pooka Exp $
+
+# Basic settings.
+Port 22
+Protocol 2
+
+# The temporary key used for login.
+IdentityFile @WORKDIR@/ssh_user_key
+
+# Prevent the client from complaining about unknown host keys.
+GlobalKnownHostsFile @WORKDIR@/known_hosts
+
+# Do not attempt password authentication in case keys fail.
+IdentitiesOnly yes
diff --git a/contrib/netbsd-tests/lib/librumphijack/ssh_host_key b/contrib/netbsd-tests/lib/librumphijack/ssh_host_key
new file mode 100644
index 0000000..ebdbc8b
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/ssh_host_key
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICWwIBAAKBgQDJnMpSG1lGmApk8F7ZH7TGtjjP/WUs+vqHyFsyS2lilJzereen
+a/ME6S0d0HTOeCdKldjbtDpfNXbh+XnJMlJMEgEs4Mg1jluuEV0GOJoMt7cGzku2
+gAYGx++2+wqYw6Y+M8Tb1M4AO+PcxD/3BkdUyIKO63v6STl2VQn1BzsTQwIBIwKB
+gAuFTWPHDGpvFols0jhK9GMgWwSSIwnidLdNRwowMehgQ3pwVmFWoCwqlN0h2sn4
+PMJu9nL0WxtiJAzprzARgQuPI25t9LiKTF7scC/cNUiHPplUjvoDXA9ccY1eIf4R
+e6wwZz1jfCWen0eRsvMyoYvFmEH8hILAk1bY9heymOGLAkEA/WhC49n+gtloVMow
+iKQOO6+u3ouxTOTQ3sV2wCaLaO2pEbHP2//5SlUJLp6QrjC7bg9Kr+f56+zT2he9
+f6GCwwJBAMus3XizmZdJyJLnkCJRiT0/3Kf57fhWKRdnFkuRLyjET9MEWavRdJmr
+bx/lxmILi1iKwXiFEDM6MqYfmNImJYECQQCtw9YYlXtSaTGZOi/oqwJyEhGCqO6b
+II85q/moVPHhjQY4BOZNttbT4on0FPV+wlSjPa+OkHDcSp/mAaaDZ2+bAkEAujel
+6rLVkaKLfv+ZuPoXE22WivMityo0Mqdk12ArHfVQS+a4YpOdzlOYzLTSosi56o19
+sAShGOTAl+Jf1hQ/iwJAKpPviX5w292H/m5T0m4l0NRdQ3pRujOLMSVmY+/HFZTW
+GJMYLr1eBKNfLsKzJgB88GzuF2O/O8hNi3XSiOP+9w==
+-----END RSA PRIVATE KEY-----
diff --git a/contrib/netbsd-tests/lib/librumphijack/ssh_host_key.pub b/contrib/netbsd-tests/lib/librumphijack/ssh_host_key.pub
new file mode 100644
index 0000000..8d08795
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/ssh_host_key.pub
@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAyZzKUhtZRpgKZPBe2R+0xrY4z/1lLPr6h8hbMktpYpSc3q3np2vzBOktHdB0zngnSpXY27Q6XzV24fl5yTJSTBIBLODINY5brhFdBjiaDLe3Bs5LtoAGBsfvtvsKmMOmPjPE29TOADvj3MQ/9wZHVMiCjut7+kk5dlUJ9Qc7E0M= test@test.example.net
diff --git a/contrib/netbsd-tests/lib/librumphijack/sshd_config.in b/contrib/netbsd-tests/lib/librumphijack/sshd_config.in
new file mode 100644
index 0000000..9ffc47f
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/sshd_config.in
@@ -0,0 +1,39 @@
+# $NetBSD: sshd_config.in,v 1.1 2011/02/14 15:14:00 pooka Exp $
+
+# Basic settings.
+Port 22
+Protocol 2
+
+# Provide information to the user in case something goes wrong.
+LogLevel DEBUG1
+
+# The host key. It lives in the work directory because we need to set
+# very strict permissions on it and cannot modify the copy on the source
+# directory.
+HostKey @WORKDIR@/ssh_host_key
+
+# The authorized keys file we set up during the test to allow the client
+# to safely log in. We need to disable strict modes because ATF_WORKDIR
+# usually lives in /tmp, which has 1777 permissions and are not liked by
+# sshd.
+AuthorizedKeysFile @WORKDIR@/authorized_keys
+StrictModes no
+
+# Some settings to allow user runs of sshd.
+PidFile @WORKDIR@/sshd.pid
+UsePam no
+UsePrivilegeSeparation no
+
+# The root user should also be able to run the tests.
+PermitRootLogin yes
+
+# Be restrictive about access to the temporary server. Only allow key-based
+# authentication.
+ChallengeResponseAuthentication no
+GSSAPIAuthentication no
+HostbasedAuthentication no
+KerberosAuthentication no
+MaxAuthTries 1
+MaxStartups 1
+PasswordAuthentication no
+PubkeyAuthentication yes
diff --git a/contrib/netbsd-tests/lib/librumphijack/t_asyncio.sh b/contrib/netbsd-tests/lib/librumphijack/t_asyncio.sh
new file mode 100755
index 0000000..d5d703c
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/t_asyncio.sh
@@ -0,0 +1,94 @@
+# $NetBSD: t_asyncio.sh,v 1.4 2014/08/27 13:32:16 gson Exp $
+#
+# Copyright (c) 2011 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.
+#
+
+rumpsrv='rump_server'
+export RUMP_SERVER=unix://csock
+
+atf_test_case select_timeout cleanup
+select_timeout_head()
+{
+ atf_set "descr" "select() with timeout returns no fds set"
+}
+
+select_timeout_body()
+{
+
+ atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
+ atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
+ $(atf_get_srcdir)/h_client select_timeout
+}
+
+select_timeout_cleanup()
+{
+ rump.halt
+}
+
+atf_test_case select_allunset cleanup
+select_allunset_head()
+{
+ atf_set "descr" "select() with no set fds in fd_set should not crash"
+}
+
+select_allunset_body()
+{
+
+ atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
+ atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
+ $(atf_get_srcdir)/h_client select_allunset
+}
+
+select_allunset_cleanup()
+{
+ rump.halt
+}
+
+atf_test_case invafd cleanup
+invafd_head()
+{
+ atf_set "descr" "poll on invalid rump fd"
+ atf_set "timeout" "10"
+}
+
+invafd_body()
+{
+
+ atf_check -s exit:0 rump_server -lrumpvfs ${RUMP_SERVER}
+ atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
+ $(atf_get_srcdir)/h_client invafd
+}
+
+invafd_cleanup()
+{
+ rump.halt
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case select_timeout
+ atf_add_test_case select_allunset
+ atf_add_test_case invafd
+}
diff --git a/contrib/netbsd-tests/lib/librumphijack/t_config.sh b/contrib/netbsd-tests/lib/librumphijack/t_config.sh
new file mode 100755
index 0000000..014bb0f
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/t_config.sh
@@ -0,0 +1,54 @@
+# $NetBSD: t_config.sh,v 1.1 2011/03/14 15:56:40 pooka Exp $
+#
+# Copyright (c) 2011 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.
+#
+
+rumpsrv='rump_server -lrumpvfs'
+export RUMP_SERVER=unix://csock
+
+atf_test_case fdoff cleanup
+fdoff_head()
+{
+ atf_set "descr" "RUMPHIJACK fdoff=8"
+}
+
+fdoff_body()
+{
+
+ atf_check -s exit:0 rump_server -lrumpvfs ${RUMP_SERVER}
+ export RUMPHIJACK=path=/rump,fdoff=8
+ atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
+ $(atf_get_srcdir)/h_client fdoff8
+}
+
+fdoff_cleanup()
+{
+ rump.halt
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case fdoff
+}
diff --git a/contrib/netbsd-tests/lib/librumphijack/t_cwd.sh b/contrib/netbsd-tests/lib/librumphijack/t_cwd.sh
new file mode 100755
index 0000000..3f2a50b
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/t_cwd.sh
@@ -0,0 +1,72 @@
+# $NetBSD: t_cwd.sh,v 1.2 2011/02/19 19:57:28 pooka Exp $
+#
+# Copyright (c) 2011 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.
+#
+
+rumpsrv='rump_server -lrumpvfs'
+export RUMP_SERVER=unix://csock
+
+test_case()
+{
+ local name="${1}"; shift
+
+ atf_test_case "${name}" cleanup
+ eval "${name}_head() { }"
+ eval "${name}_body() { \
+ export RUMPHIJACK="path=${1}" ; \
+ atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER} ; \
+ testbody " "${@}" "; \
+ }"
+ eval "${name}_cleanup() { \
+ rump.halt
+ }"
+}
+
+test_case basic_chdir /rump simple chdir
+test_case basic_fchdir /rump simple fchdir
+test_case slash_chdir // simple chdir
+test_case slash_fchdir // simple fchdir
+test_case symlink_chdir /rump symlink chdir
+test_case symlink_fchdir /rump symlink fchdir
+test_case symlink_slash_chdir // symlink chdir
+test_case symlink_slash_fchdir // symlink fchdir
+
+testbody()
+{
+ atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
+ $(atf_get_srcdir)/h_cwd $*
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case basic_chdir
+ atf_add_test_case basic_fchdir
+ atf_add_test_case slash_chdir
+ atf_add_test_case slash_fchdir
+ atf_add_test_case symlink_chdir
+ atf_add_test_case symlink_fchdir
+ atf_add_test_case symlink_slash_chdir
+ atf_add_test_case symlink_slash_fchdir
+}
diff --git a/contrib/netbsd-tests/lib/librumphijack/t_sh.sh b/contrib/netbsd-tests/lib/librumphijack/t_sh.sh
new file mode 100755
index 0000000..c01c729
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/t_sh.sh
@@ -0,0 +1,91 @@
+# $NetBSD: t_sh.sh,v 1.1 2011/03/03 11:54:12 pooka Exp $
+#
+# Copyright (c) 2011 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.
+#
+
+#
+# Test various /bin/sh descriptor games.
+#
+# Note that there is an extra level of trickery here, since
+# we need to run an extra level of shell to "catch" LD_PRELOAD.
+#
+
+rumpsrv='rump_server -lrumpvfs'
+export RUMP_SERVER=unix://csock
+exout="this is the output you are looking for"
+
+atf_test_case runscript cleanup
+runscript_head()
+{
+ atf_set "descr" "can run /bin/sh scripts from rumpfs"
+}
+
+runscript_body()
+{
+ atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
+
+ export LD_PRELOAD=/usr/lib/librumphijack.so
+ echo "echo $exout" > thescript
+ atf_check -s exit:0 mv thescript /rump
+ atf_check -s exit:0 -o inline:"${exout}\n" -x sh /rump/thescript
+}
+
+runscript_cleanup()
+{
+ rump.halt
+}
+
+atf_test_case redirect cleanup
+redirect_head()
+{
+ atf_set "descr" "input/output redirection works with rumphijack"
+}
+
+redirect_body()
+{
+ atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
+ export LD_PRELOAD=/usr/lib/librumphijack.so
+
+ echo "echo $exout > /rump/thefile" > thescript
+ atf_check -s exit:0 -x sh thescript
+
+ # read it without input redirection
+ atf_check -s exit:0 -o inline:"${exout}\n" cat /rump/thefile
+
+ # read it with input redirection (note, need an exec'd shell again)
+ echo "cat < /rump/thefile" > thescript
+ atf_check -s exit:0 -o inline:"${exout}\n" -x sh thescript
+}
+
+redirect_cleanup()
+{
+ rump.halt
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case runscript
+ atf_add_test_case redirect
+}
diff --git a/contrib/netbsd-tests/lib/librumphijack/t_tcpip.sh b/contrib/netbsd-tests/lib/librumphijack/t_tcpip.sh
new file mode 100755
index 0000000..d6a16fa
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/t_tcpip.sh
@@ -0,0 +1,268 @@
+# $NetBSD: t_tcpip.sh,v 1.13 2014/01/03 13:18:00 pooka Exp $
+#
+# Copyright (c) 2011 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.
+#
+
+rumpnetsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet'
+export RUMP_SERVER=unix://csock
+
+atf_test_case http cleanup
+http_head()
+{
+ atf_set "descr" "Start hijacked httpd and get webpage from it"
+}
+
+http_body()
+{
+
+ atf_check -s exit:0 ${rumpnetsrv} -lrumpnet_netinet6 ${RUMP_SERVER}
+
+ # start bozo in daemon mode
+ atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
+ /usr/libexec/httpd -P ./httpd.pid -b -s $(atf_get_srcdir)
+
+ atf_check -s exit:0 -o file:"$(atf_get_srcdir)/netstat.expout" \
+ rump.netstat -a
+
+ # get the webpage
+ atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
+ $(atf_get_srcdir)/h_netget 127.0.0.1 80 webfile
+
+ # check that we got what we wanted
+ atf_check -o match:'HTTP/1.0 200 OK' cat webfile
+ atf_check -o match:'Content-Length: 95' cat webfile
+ atf_check -o file:"$(atf_get_srcdir)/index.html" \
+ sed -n '1,/^$/!p' webfile
+}
+
+http_cleanup()
+{
+ if [ -f httpd.pid ]; then
+ kill -9 "$(cat httpd.pid)"
+ rm -f httpd.pid
+ fi
+
+ rump.halt
+}
+
+#
+# Starts a SSH server and sets up the client to access it.
+# Authentication is allowed and done using an RSA key exclusively, which
+# is generated on the fly as part of the test case.
+# XXX: Ideally, all the tests in this test program should be able to share
+# the generated key, because creating it can be a very slow process on some
+# machines.
+#
+# XXX2: copypasted from jmmv's sshd thingamob in the psshfs test.
+# ideally code (and keys, like jmmv notes above) could be shared
+#
+start_sshd() {
+ echo "Setting up SSH server configuration"
+ sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
+ $(atf_get_srcdir)/sshd_config.in >sshd_config || \
+ atf_fail "Failed to create sshd_config"
+ atf_check -s ignore -o empty -e ignore \
+ cp $(atf_get_srcdir)/ssh_host_key .
+ atf_check -s ignore -o empty -e ignore \
+ cp $(atf_get_srcdir)/ssh_host_key.pub .
+ atf_check -s eq:0 -o empty -e empty chmod 400 ssh_host_key
+ atf_check -s eq:0 -o empty -e empty chmod 444 ssh_host_key.pub
+
+ env LD_PRELOAD=/usr/lib/librumphijack.so \
+ /usr/sbin/sshd -e -f ./sshd_config
+ while [ ! -f sshd.pid ]; do
+ sleep 0.01
+ done
+ echo "SSH server started (pid $(cat sshd.pid))"
+
+ echo "Setting up SSH client configuration"
+ atf_check -s eq:0 -o empty -e empty \
+ ssh-keygen -f ssh_user_key -t rsa -b 1024 -N "" -q
+ atf_check -s eq:0 -o empty -e empty \
+ cp ssh_user_key.pub authorized_keys
+ echo "127.0.0.1,localhost,::1 " \
+ "$(cat $(atf_get_srcdir)/ssh_host_key.pub)" >known_hosts || \
+ atf_fail "Failed to create known_hosts"
+ atf_check -s eq:0 -o empty -e empty chmod 600 authorized_keys
+ sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
+ $(atf_get_srcdir)/ssh_config.in >ssh_config || \
+ atf_fail "Failed to create ssh_config"
+
+ echo "sshd running"
+}
+
+atf_test_case ssh cleanup
+ssh_head()
+{
+ atf_set "descr" "Test that hijacked ssh/sshd works"
+}
+
+ssh_body()
+{
+
+ atf_check -s exit:0 ${rumpnetsrv} ${RUMP_SERVER}
+ # make sure clients die after we nuke the server
+ export RUMPHIJACK_RETRYCONNECT='die'
+
+ start_sshd
+
+ # create some sort of directory for us to "ls"
+ mkdir testdir
+ cd testdir
+ jot 11 | xargs touch
+ jot 11 12 | xargs mkdir
+ cd ..
+
+ atf_check -s exit:0 -o save:ssh.out \
+ env LD_PRELOAD=/usr/lib/librumphijack.so \
+ ssh -T -F ssh_config 127.0.0.1 env BLOCKSIZE=512 \
+ ls -li $(pwd)/testdir
+ atf_check -s exit:0 -o file:ssh.out env BLOCKSIZE=512 \
+ ls -li $(pwd)/testdir
+}
+
+ssh_cleanup()
+{
+ rump.halt
+ # sshd dies due to RUMPHIJACK_RETRYCONNECT=1d6
+}
+
+test_nfs()
+{
+
+ magicstr='wind in my hair'
+ # create ffs file system we'll be serving from
+ atf_check -s exit:0 -o ignore newfs -F -s 10000 ffs.img
+
+ # start nfs kernel server. this is a mouthful
+ export RUMP_SERVER=unix://serversock
+ atf_check -s exit:0 rump_server $* ${RUMP_SERVER}
+
+ atf_check -s exit:0 rump.ifconfig shmif0 create
+ atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
+ atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.1
+
+ export RUMPHIJACK_RETRYCONNECT=die
+ export LD_PRELOAD=/usr/lib/librumphijack.so
+
+ atf_check -s exit:0 mkdir -p /rump/var/run
+ atf_check -s exit:0 mkdir -p /rump/var/db
+ atf_check -s exit:0 touch /rump/var/db/mountdtab
+ atf_check -s exit:0 mkdir /rump/etc
+ atf_check -s exit:0 mkdir /rump/export
+
+ atf_check -s exit:0 -x \
+ 'echo "/export -noresvport -noresvmnt 10.1.1.100" | \
+ dd of=/rump/etc/exports 2> /dev/null'
+
+ atf_check -s exit:0 -e ignore mount_ffs /dk /rump/export
+ atf_check -s exit:0 -x "echo ${magicstr} > /rump/export/im_alive"
+
+ # start rpcbind. we want /var/run/rpcbind.sock
+ export RUMPHIJACK='blanket=/var/run,socket=all'
+ atf_check -s exit:0 rpcbind
+
+ # ok, then we want mountd in the similar fashion
+ export RUMPHIJACK='blanket=/var/run:/var/db:/export,socket=all,path=/rump,vfs=all'
+ atf_check -s exit:0 mountd /rump/etc/exports
+
+ # finally, le nfschuck
+ export RUMPHIJACK='blanket=/var/run,socket=all,vfs=all'
+ atf_check -s exit:0 nfsd
+
+ #
+ # now, time for the client server and associated madness.
+ #
+
+ export RUMP_SERVER=unix://clientsock
+ unset RUMPHIJACK
+ unset LD_PRELOAD
+
+ # at least the kernel server is easier
+ atf_check -s exit:0 rump_server -lrumpvfs -lrumpnet \
+ -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpfs_nfs\
+ ${RUMP_SERVER}
+
+ atf_check -s exit:0 rump.ifconfig shmif0 create
+ atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
+ atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.100
+
+ export LD_PRELOAD=/usr/lib/librumphijack.so
+
+ atf_check -s exit:0 mkdir /rump/mnt
+ atf_check -s exit:0 mount_nfs 10.1.1.1:/export /rump/mnt
+
+ atf_check -s exit:0 -o inline:"${magicstr}\n" cat /rump/mnt/im_alive
+ atf_check -s exit:0 -o match:'.*im_alive$' ls -l /rump/mnt/im_alive
+}
+
+
+atf_test_case nfs cleanup
+nfs_head()
+{
+ atf_set "descr" "Test hijacked nfsd and mount_nfs"
+}
+
+nfs_body()
+{
+ test_nfs -lrumpvfs -lrumpdev -lrumpnet -lrumpnet_net \
+ -lrumpnet_netinet -lrumpnet_local -lrumpnet_shmif \
+ -lrumpdev_disk -lrumpfs_ffs -lrumpfs_nfs -lrumpfs_nfsserver \
+ -d key=/dk,hostpath=ffs.img,size=host
+}
+
+nfs_cleanup()
+{
+ RUMP_SERVER=unix://serversock rump.halt 2> /dev/null
+ RUMP_SERVER=unix://clientsock rump.halt 2> /dev/null
+ :
+}
+
+atf_test_case nfs_autoload cleanup
+nfs_autoload_head()
+{
+ atf_set "descr" "Test hijacked nfsd with autoload from /stand"
+}
+
+nfs_autoload_body()
+{
+ [ `uname -m` = "i386" ] || atf_skip "test currently valid only on i386"
+ test_nfs -lrumpvfs -lrumpdev -lrumpnet -lrumpnet_net \
+ -lrumpnet_netinet -lrumpnet_local -lrumpnet_shmif \
+ -lrumpdev_disk -d key=/dk,hostpath=ffs.img,size=host
+}
+
+nfs_autoload_cleanup()
+{
+ nfs_cleanup
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case http
+ atf_add_test_case ssh
+ atf_add_test_case nfs
+ atf_add_test_case nfs_autoload
+}
diff --git a/contrib/netbsd-tests/lib/librumphijack/t_vfs.sh b/contrib/netbsd-tests/lib/librumphijack/t_vfs.sh
new file mode 100755
index 0000000..c803e2a
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumphijack/t_vfs.sh
@@ -0,0 +1,223 @@
+# $NetBSD: t_vfs.sh,v 1.6 2012/08/04 03:56:47 riastradh Exp $
+#
+# Copyright (c) 2011 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.
+#
+
+img=ffs.img
+rumpsrv_ffs=\
+"rump_server -lrumpvfs -lrumpfs_ffs -lrumpdev_disk -d key=/img,hostpath=${img},size=host"
+export RUMP_SERVER=unix://csock
+
+domount()
+{
+
+ mntdir=$1
+ [ $# -eq 0 ] && mntdir=/rump/mnt
+ atf_check -s exit:0 -e ignore mount_ffs /img ${mntdir}
+}
+
+dounmount()
+{
+
+ atf_check -s exit:0 umount -R ${mntdir}
+}
+
+remount()
+{
+
+ dounmount
+ domount /rump/mnt2
+}
+
+simpletest()
+{
+ local name="${1}"; shift
+
+ atf_test_case "${name}" cleanup
+ eval "${name}_head() { }"
+ eval "${name}_body() { \
+ atf_check -s exit:0 rump_server -lrumpvfs ${RUMP_SERVER} ; \
+ export LD_PRELOAD=/usr/lib/librumphijack.so ; \
+ ${name} " "${@}" "; \
+ }"
+ eval "${name}_cleanup() { \
+ rump.halt
+ }"
+}
+
+test_case()
+{
+ local name="${1}"; shift
+
+ atf_test_case "${name}" cleanup
+ eval "${name}_head() { }"
+ eval "${name}_body() { \
+ atf_check -s exit:0 -o ignore newfs -F -s 20000 ${img} ; \
+ atf_check -s exit:0 ${rumpsrv_ffs} ${RUMP_SERVER} ; \
+ export LD_PRELOAD=/usr/lib/librumphijack.so ; \
+ mkdir /rump/mnt /rump/mnt2 ; \
+ domount ; \
+ ${name} " "${@}" "; \
+ dounmount ${mntdir}
+ }"
+ eval "${name}_cleanup() { \
+ rump.halt
+ }"
+}
+
+test_case paxcopy
+test_case cpcopy
+test_case mv_nox
+test_case ln_nox
+
+#
+# use rumphijack to cp/pax stuff onto an image, unmount it, remount it
+# at a different location, and check that we have an identical copy
+# (we make a local copy to avoid the minor possibility that someone
+# modifies the source dir data while the test is running)
+#
+paxcopy()
+{
+ parent=$(dirname $(atf_get_srcdir))
+ thedir=$(basename $(atf_get_srcdir))
+ atf_check -s exit:0 pax -rw -s,${parent},, $(atf_get_srcdir) .
+ atf_check -s exit:0 pax -rw ${thedir} /rump/mnt
+ remount
+ atf_check -s exit:0 diff -ru ${thedir} /rump/mnt2/${thedir}
+}
+
+cpcopy()
+{
+ thedir=$(basename $(atf_get_srcdir))
+ atf_check -s exit:0 cp -Rp $(atf_get_srcdir) .
+ atf_check -s exit:0 cp -Rp ${thedir} /rump/mnt
+ remount
+ atf_check -s exit:0 diff -ru ${thedir} /rump/mnt2/${thedir}
+}
+
+#
+# non-crosskernel mv (non-simple test since this uses rename(2)
+# which is not supported by rumpfs)
+#
+
+mv_nox()
+{
+ # stat default format sans changetime and filename
+ statstr='%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf'
+
+ atf_check -s exit:0 touch /rump/mnt/filename
+ atf_check -s exit:0 -o save:stat.out \
+ stat -f "${statstr}" /rump/mnt/filename
+ atf_check -s exit:0 mkdir /rump/mnt/dir
+ atf_check -s exit:0 mv /rump/mnt/filename /rump/mnt/dir/same
+ atf_check -s exit:0 -o file:stat.out \
+ stat -f "${statstr}" /rump/mnt/dir/same
+}
+
+ln_nox()
+{
+ # Omit st_nlink too, since it will increase.
+ statstr='%d %i %Sp %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf'
+
+ atf_check -s exit:0 touch /rump/mnt/filename
+ atf_check -s exit:0 -o save:stat.out \
+ stat -f "${statstr}" /rump/mnt/filename
+ atf_check -s exit:0 mkdir /rump/mnt/dir
+ atf_check -s exit:0 ln /rump/mnt/filename /rump/mnt/dir/same
+ atf_check -s exit:0 -o file:stat.out \
+ stat -f "${statstr}" /rump/mnt/filename
+ atf_check -s exit:0 -o file:stat.out \
+ stat -f "${statstr}" /rump/mnt/dir/same
+}
+
+simpletest mv_x
+simpletest ln_x
+simpletest runonprefix
+simpletest blanket
+simpletest doubleblanket
+
+#
+# do a cross-kernel mv
+#
+mv_x()
+{
+ thedir=$(basename $(atf_get_srcdir))
+ atf_check -s exit:0 cp -Rp $(atf_get_srcdir) .
+ atf_check -s exit:0 cp -Rp ${thedir} ${thedir}.2
+ atf_check -s exit:0 mv ${thedir} /rump
+ atf_check -s exit:0 diff -ru ${thedir}.2 /rump/${thedir}
+}
+
+#
+# Fail to make a cross-kernel hard link.
+#
+ln_x()
+{
+ atf_check -s exit:0 touch ./loser
+ atf_check -s not-exit:0 -e ignore ln ./loser /rump/.
+}
+
+runonprefix()
+{
+ atf_check -s exit:0 -o ignore stat /rump/dev
+ atf_check -s exit:1 -e ignore stat /rumpdev
+}
+
+blanket()
+{
+ export RUMPHIJACK='blanket=/dev,path=/rump'
+ atf_check -s exit:0 -o save:stat.out \
+ stat -f "${statstr}" /rump/dev/null
+ atf_check -s exit:0 -o file:stat.out \
+ stat -f "${statstr}" /dev/null
+}
+
+doubleblanket()
+{
+ atf_check -s exit:0 mkdir /rump/dir
+ atf_check -s exit:0 ln -s dir /rump/dirtoo
+
+ export RUMPHIJACK='blanket=/dirtoo:/dir'
+ atf_check -s exit:0 touch /dir/file
+
+ atf_check -s exit:0 -o save:stat.out \
+ stat -f "${statstr}" /dir/file
+ atf_check -s exit:0 -o file:stat.out \
+ stat -f "${statstr}" /dirtoo/file
+}
+
+atf_init_test_cases()
+{
+
+ atf_add_test_case paxcopy
+ atf_add_test_case cpcopy
+ atf_add_test_case mv_x
+ atf_add_test_case ln_x
+ atf_add_test_case mv_nox
+ atf_add_test_case ln_nox
+ atf_add_test_case runonprefix
+ atf_add_test_case blanket
+ atf_add_test_case doubleblanket
+}
OpenPOWER on IntegriCloud