summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/lib/librumpclient
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/librumpclient
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/librumpclient')
-rw-r--r--contrib/netbsd-tests/lib/librumpclient/h_exec.c132
-rw-r--r--contrib/netbsd-tests/lib/librumpclient/h_execthr.c187
-rwxr-xr-xcontrib/netbsd-tests/lib/librumpclient/t_exec.sh154
-rw-r--r--contrib/netbsd-tests/lib/librumpclient/t_fd.c146
4 files changed, 619 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/librumpclient/h_exec.c b/contrib/netbsd-tests/lib/librumpclient/h_exec.c
new file mode 100644
index 0000000..cf2526c
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumpclient/h_exec.c
@@ -0,0 +1,132 @@
+/* $NetBSD: h_exec.c,v 1.6 2011/02/16 17:57:44 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.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <rump/rumpclient.h>
+#include <rump/rump_syscalls.h>
+
+int
+main(int argc, char *argv[])
+{
+ struct sockaddr_in sin;
+ socklen_t slen;
+ int s1, s2;
+ char buf[12];
+ char *eargv[4];
+ char *ename;
+ extern char **environ;
+
+ if (rumpclient_init() == -1)
+ err(1, "init");
+
+ if (argc > 1) {
+ if (strcmp(argv[1], "_didexec") == 0) {
+ rumpclient_daemon(0, 0); /* detach-me-notnot */
+ s2 = atoi(argv[2]);
+ slen = sizeof(sin);
+ /* see below */
+ rump_sys_accept(s2, (struct sockaddr *)&sin, &slen);
+ }
+ }
+
+ /* open and listenize two TCP4 suckets */
+ if ((s1 = rump_sys_socket(PF_INET, SOCK_STREAM, 0)) == -1)
+ err(1, "socket 1");
+ if ((s2 = rump_sys_socket(PF_INET, SOCK_STREAM, 0)) == -1)
+ err(1, "socket 2");
+
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_len = sizeof(sin);
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(1234);
+
+ if (rump_sys_bind(s1, (struct sockaddr *)&sin, sizeof(sin)) == -1)
+ err(1, "bind1");
+ sin.sin_port = htons(2345);
+ if (rump_sys_bind(s2, (struct sockaddr *)&sin, sizeof(sin)) == -1)
+ err(1, "bind2");
+
+ if (rump_sys_listen(s1, 1) == -1)
+ err(1, "listen1");
+ if (rump_sys_listen(s2, 1) == -1)
+ err(1, "listen2");
+
+ if (argc == 1) {
+ rumpclient_daemon(0, 0);
+ slen = sizeof(sin);
+ /*
+ * "pause()", but conveniently gets rid of this helper
+ * since we were called with RUMPCLIENT_RETRYCONN_DIE set
+ */
+ rump_sys_accept(s2, (struct sockaddr *)&sin, &slen);
+ }
+
+ if (argc == 3 && strcmp(argv[2], "cloexec1") == 0) {
+ if (rump_sys_fcntl(s1, F_SETFD, FD_CLOEXEC) == -1) {
+ err(1, "cloexec failed");
+ }
+ }
+
+ sprintf(buf, "%d", s2);
+
+ if (argc == 3 && strcmp(argv[2], "vfork_please") == 0) {
+ switch (rumpclient_vfork()) {
+ case 0:
+ ename = __UNCONST("fourchette");
+ break;
+ case -1:
+ err(1, "vfork");
+ default:
+ ename = __UNCONST("h_ution");
+ break;
+ }
+ } else {
+ ename = __UNCONST("h_ution");
+ }
+
+ /* omstart! */
+ eargv[0] = ename;
+ eargv[1] = __UNCONST("_didexec");
+ eargv[2] = buf;
+ eargv[3] = NULL;
+ if (rumpclient_exec(argv[1], __UNCONST(eargv), environ) == -1)
+ err(1, "exec");
+}
diff --git a/contrib/netbsd-tests/lib/librumpclient/h_execthr.c b/contrib/netbsd-tests/lib/librumpclient/h_execthr.c
new file mode 100644
index 0000000..f653fe6
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumpclient/h_execthr.c
@@ -0,0 +1,187 @@
+/* $NetBSD: h_execthr.c,v 1.3 2014/08/13 00:03: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.
+ */
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <rump/rumpclient.h>
+#include <rump/rump_syscalls.h>
+
+static int canreturn = 0;
+
+/*
+ * Use a fairly large number of threads so that we have
+ * a better chance catching races. XXX: this is rumpuser's
+ * MAXWORKER-1.
+ */
+#define NTHR 63
+
+#define P1_0 3
+#define P1_1 4
+#define P2_0 5
+#define P2_1 6
+
+static void *
+wrk(void *arg)
+{
+ int fd = (uintptr_t)arg;
+
+ rump_sys_read(fd, &fd, sizeof(fd));
+ if (!canreturn)
+ errx(1, "should not have returned");
+ if (fd != 37)
+ errx(1, "got invalid magic");
+
+ return NULL;
+}
+
+static int
+getproc(pid_t mypid, struct kinfo_proc2 *p)
+{
+ int name[6];
+ size_t len = sizeof(*p);
+
+ name[0] = CTL_KERN;
+ name[1] = KERN_PROC2;
+ name[2] = KERN_PROC_PID;
+ name[3] = mypid;
+ name[4] = len;
+ name[5] = 1;
+
+ return rump_sys___sysctl(name, __arraycount(name), p, &len, NULL, 0);
+}
+
+int
+main(int argc, char *argv[], char *envp[])
+{
+ struct kinfo_proc2 p;
+ char *execarg[3];
+ int p1[2], p2[2];
+ pid_t mypid;
+ pthread_t pt;
+ ssize_t n;
+ int i, execd;
+ char nexec[16];
+
+ if (argc > 1)
+ execd = atoi(argv[1]);
+ else
+ execd = 0;
+ sprintf(nexec, "%d", execd+1);
+
+ if (rumpclient_init() == -1) {
+ if (execd)
+ err(1, "init execd");
+ else
+ err(1, "init");
+ }
+ mypid = rump_sys_getpid();
+
+ if (execd) {
+ canreturn = 1;
+ if (pthread_create(&pt, NULL,
+ wrk, (void *)(uintptr_t)P2_0) != 0)
+ errx(1, "exec pthread_create");
+
+ i = 37;
+ rump_sys_write(P2_1, &i, sizeof(i));
+ pthread_join(pt, NULL);
+
+ n = rump_sys_read(P1_0, &i, sizeof(i));
+ if (n != -1 || errno != EBADF)
+ errx(1, "post-exec cloexec works");
+
+ getproc(mypid, &p);
+ if (p.p_nlwps != 2)
+ errx(1, "invalid nlwps: %lld", (long long)p.p_nlwps);
+
+ /* we passed? */
+ if (execd > 10)
+ exit(0);
+
+ rump_sys_close(P2_0);
+ rump_sys_close(P2_1);
+ }
+
+ if (rump_sys_pipe(p1) == -1)
+ err(1, "pipe1");
+ if (p1[0] != P1_0 || p1[1] != P1_1)
+ errx(1, "p1 assumptions failed %d %d", p1[0], p1[1]);
+ if (rump_sys_pipe(p2) == -1)
+ err(1, "pipe1");
+ if (p2[0] != P2_0 || p2[1] != P2_1)
+ errx(1, "p2 assumptions failed");
+ if (rump_sys_fcntl(p1[0], F_SETFD, FD_CLOEXEC) == -1)
+ err(1, "cloexec");
+ if (rump_sys_fcntl(p1[1], F_SETFD, FD_CLOEXEC) == -1)
+ err(1, "cloexec");
+
+ for (i = 0; i < NTHR; i++)
+ if (pthread_create(&pt, NULL,
+ wrk, (void *)(uintptr_t)p1[0]) != 0)
+ errx(1, "pthread_create 1 %d", i);
+
+ for (i = 0; i < NTHR; i++)
+ if (pthread_create(&pt, NULL,
+ wrk, (void *)(uintptr_t)p2[0]) != 0)
+ errx(1, "pthread_create 2 %d", i);
+
+ /* wait for all the threads to be enjoying themselves */
+ for (;;) {
+ getproc(mypid, &p);
+ if (p.p_nlwps == 2*NTHR + 2)
+ break;
+ usleep(10000);
+ }
+
+ /*
+ * load up one more (big) set. these won't start executing, though,
+ * but we're interested in if they create blockage
+ */
+ for (i = 0; i < 3*NTHR; i++)
+ if (pthread_create(&pt, NULL,
+ wrk, (void *)(uintptr_t)p1[0]) != 0)
+ errx(1, "pthread_create 1 %d", i);
+
+ /* then, we exec! */
+ execarg[0] = argv[0];
+ execarg[1] = nexec;
+ execarg[2] = NULL;
+ if (rumpclient_exec(argv[0], execarg, envp) == -1)
+ err(1, "exec");
+}
diff --git a/contrib/netbsd-tests/lib/librumpclient/t_exec.sh b/contrib/netbsd-tests/lib/librumpclient/t_exec.sh
new file mode 100755
index 0000000..661a3b9
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumpclient/t_exec.sh
@@ -0,0 +1,154 @@
+# $NetBSD: t_exec.sh,v 1.8 2011/03/08 12:40:25 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 -lrumpnet -lrumpnet_net -lrumpnet_netinet'
+export RUMP_SERVER=unix://csock
+export RUMPHIJACK_RETRYCONNECT='die'
+
+atf_test_case noexec cleanup
+noexec_head()
+{
+ atf_set "descr" "check that we see what we expect without exec"
+}
+
+noexec_body()
+{
+
+ atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
+ atf_check -s exit:0 env $(atf_get_srcdir)/h_exec
+ atf_check -s exit:0 -o save:sstat.out rump.sockstat -n
+ atf_check -s exit:0 -o match:'^root.*h_exec.*tcp.*\*\.1234' \
+ sed -n 2p sstat.out
+ atf_check -s exit:0 -o match:'^root.*h_exec.*tcp.*\*\.2345' \
+ sed -n 3p sstat.out
+}
+
+noexec_cleanup()
+{
+ rump.halt
+}
+
+atf_test_case exec cleanup
+exec_head()
+{
+ atf_set "descr" "check that client names changes after exec"
+}
+
+exec_body()
+{
+
+ atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
+ atf_check -s exit:0 $(atf_get_srcdir)/h_exec $(atf_get_srcdir)/h_exec
+ atf_check -s exit:0 -o save:sstat.out rump.sockstat -n
+ atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.1234' \
+ sed -n 2p sstat.out
+ atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.2345' \
+ sed -n 3p sstat.out
+}
+
+exec_cleanup()
+{
+ rump.halt
+}
+
+atf_test_case cloexec cleanup
+cloexec_head()
+{
+ atf_set "descr" "check that FD_CLOEXEC works"
+}
+
+cloexec_body()
+{
+
+ atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
+ atf_check -s exit:0 \
+ $(atf_get_srcdir)/h_exec $(atf_get_srcdir)/h_exec cloexec1
+ atf_check -s exit:0 -o save:sstat.out rump.sockstat -n
+ atf_check -s exit:0 -o inline:'2\n' sed -n '$=' sstat.out
+ atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.2345' \
+ sed -n 2p sstat.out
+}
+
+cloexec_cleanup()
+{
+ rump.halt
+}
+
+atf_test_case vfork cleanup
+vfork_head()
+{
+ atf_set "descr" "test rumpclient_vfork()"
+}
+
+vfork_body()
+{
+
+ atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
+ atf_check -s exit:0 \
+ $(atf_get_srcdir)/h_exec $(atf_get_srcdir)/h_exec vfork_please
+ atf_check -s exit:0 -o save:sstat.out rump.sockstat -n
+ atf_check -s exit:0 -o inline:'5\n' sed -n '$=' sstat.out
+ atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.1234' \
+ cat sstat.out
+ atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.2345' \
+ cat sstat.out
+ atf_check -s exit:0 -o match:'^root.*fourchette.*tcp.*\*\.1234' \
+ cat sstat.out
+ atf_check -s exit:0 -o match:'^root.*fourchette.*tcp.*\*\.2345' \
+ cat sstat.out
+}
+
+vfork_cleanup()
+{
+ rump.halt
+}
+
+atf_test_case threxec cleanup
+threxec_head()
+{
+ atf_set "descr" "check that threads are killed before exec continues"
+}
+
+threxec_body()
+{
+ atf_check -s exit:0 rump_server ${RUMP_SERVER}
+ atf_check -s exit:0 $(atf_get_srcdir)/h_execthr
+}
+
+threxec_cleanup()
+{
+ rump.halt
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case noexec
+ atf_add_test_case exec
+ atf_add_test_case cloexec
+ atf_add_test_case vfork
+ atf_add_test_case threxec
+}
diff --git a/contrib/netbsd-tests/lib/librumpclient/t_fd.c b/contrib/netbsd-tests/lib/librumpclient/t_fd.c
new file mode 100644
index 0000000..aa0d1cc
--- /dev/null
+++ b/contrib/netbsd-tests/lib/librumpclient/t_fd.c
@@ -0,0 +1,146 @@
+/* $NetBSD: t_fd.c,v 1.4 2011/08/25 18:46:01 hannken 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 <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <rump/rumpclient.h>
+#include <rump/rump_syscalls.h>
+
+#include "../../h_macros.h"
+
+ATF_TC_WITH_CLEANUP(bigenough);
+ATF_TC_HEAD(bigenough, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check that rumpclient uses "
+ "fd > 2");
+}
+ATF_TC_WITH_CLEANUP(sigio);
+ATF_TC_HEAD(sigio, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check that rump client receives "
+ "SIGIO");
+}
+
+#define RUMPSERV "unix://sucket"
+
+ATF_TC_CLEANUP(bigenough, tc){system("env RUMP_SERVER=" RUMPSERV " rump.halt");}
+ATF_TC_CLEANUP(sigio, tc) { system("env RUMP_SERVER=" RUMPSERV " rump.halt"); }
+
+ATF_TC_BODY(bigenough, tc)
+{
+ struct stat sb;
+
+ RZ(system("rump_server " RUMPSERV));
+ RL(setenv("RUMP_SERVER", RUMPSERV, 1));
+
+ RL(dup2(0, 10));
+ RL(dup2(1, 11));
+ RL(dup2(2, 12));
+
+ RL(close(0));
+ RL(close(1));
+ RL(close(2));
+
+ RL(rumpclient_init());
+ RL(rump_sys_getpid());
+
+ ATF_REQUIRE_ERRNO(EBADF, fstat(0, &sb) == -1);
+ ATF_REQUIRE_ERRNO(EBADF, fstat(1, &sb) == -1);
+ ATF_REQUIRE_ERRNO(EBADF, fstat(2, &sb) == -1);
+
+ RL(rump_sys_getpid());
+
+ /* restore these. does it help? */
+ dup2(10, 0);
+ dup2(11, 1);
+ dup2(12, 2);
+}
+
+static volatile sig_atomic_t sigcnt;
+static void
+gotsig(int sig)
+{
+
+ sigcnt++;
+}
+
+ATF_TC_BODY(sigio, tc)
+{
+ struct sockaddr_in sin;
+ int ls;
+ int cs;
+ int fl;
+ int sc;
+
+ signal(SIGIO, gotsig);
+ RZ(system("rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet "
+ RUMPSERV));
+ RL(setenv("RUMP_SERVER", RUMPSERV, 1));
+
+ RL(rumpclient_init());
+ RL(ls = rump_sys_socket(PF_INET, SOCK_STREAM, 0));
+
+ RL(rump_sys_fcntl(ls, F_SETOWN, rump_sys_getpid()));
+ RL(fl = rump_sys_fcntl(ls, F_GETFL));
+ RL(rump_sys_fcntl(ls, F_SETFL, fl | O_ASYNC));
+
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_len = sizeof(sin);
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(12345);
+ RL(rump_sys_bind(ls, (struct sockaddr *)&sin, sizeof(sin)));
+ RL(rump_sys_listen(ls, 5));
+
+ RL(cs = rump_sys_socket(PF_INET, SOCK_STREAM, 0));
+ sin.sin_addr.s_addr = inet_addr("127.0.0.1");
+
+ ATF_REQUIRE_EQ(sigcnt, 0);
+ RL(rump_sys_connect(cs, (struct sockaddr *)&sin, sizeof(sin)));
+ sc = sigcnt;
+ printf("sigcnt after connect: %d\n", sc);
+ ATF_REQUIRE(sc >= 1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, bigenough);
+ ATF_TP_ADD_TC(tp, sigio);
+
+ return atf_no_error();
+}
OpenPOWER on IntegriCloud