Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/rump/rumpkern Some tests for rumpclient fork.
details: https://anonhg.NetBSD.org/src/rev/10ff4c93b8a7
branches: trunk
changeset: 760465:10ff4c93b8a7
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Jan 05 17:19:09 2011 +0000
description:
Some tests for rumpclient fork.
diffstat:
tests/rump/rumpkern/h_client/Makefile | 3 +-
tests/rump/rumpkern/h_client/h_forkcli.c | 169 +++++++++++++++++++++++++++++++
tests/rump/rumpkern/t_sp.sh | 65 +++++------
3 files changed, 202 insertions(+), 35 deletions(-)
diffs (290 lines):
diff -r ca2156764814 -r 10ff4c93b8a7 tests/rump/rumpkern/h_client/Makefile
--- a/tests/rump/rumpkern/h_client/Makefile Wed Jan 05 17:14:50 2011 +0000
+++ b/tests/rump/rumpkern/h_client/Makefile Wed Jan 05 17:19:09 2011 +0000
@@ -1,10 +1,11 @@
-# $NetBSD: Makefile,v 1.2 2010/12/12 12:53:35 pooka Exp $
+# $NetBSD: Makefile,v 1.3 2011/01/05 17:19:09 pooka Exp $
#
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/rump/rumpkern/h_client
+TESTS_C+= h_forkcli
TESTS_C+= h_simplecli
TESTS_C+= h_stresscli
diff -r ca2156764814 -r 10ff4c93b8a7 tests/rump/rumpkern/h_client/h_forkcli.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/rumpkern/h_client/h_forkcli.c Wed Jan 05 17:19:09 2011 +0000
@@ -0,0 +1,169 @@
+/* $NetBSD: h_forkcli.c,v 1.1 2011/01/05 17:19:09 pooka Exp $ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <rump/rump_syscalls.h>
+#include <rump/rumpclient.h>
+
+static void
+simple(void)
+{
+ struct rumpclient_fork *rf;
+ pid_t pid1, pid2;
+ int fd, status;
+
+ if ((pid1 = rump_sys_getpid()) < 2)
+ errx(1, "unexpected pid %d", pid1);
+
+ fd = rump_sys_open("/dev/null", O_CREAT | O_RDWR);
+ if (rump_sys_write(fd, &fd, sizeof(fd)) != sizeof(fd))
+ errx(1, "write newlyopened /dev/null");
+
+ if ((rf = rumpclient_prefork()) == NULL)
+ err(1, "prefork");
+
+ switch (fork()) {
+ case -1:
+ err(1, "fork");
+ break;
+ case 0:
+ if (rumpclient_fork_init(rf) == -1)
+ err(1, "postfork init failed");
+
+ if ((pid2 = rump_sys_getpid()) < 2)
+ errx(1, "unexpected pid %d", pid2);
+ if (pid1 == pid2)
+ errx(1, "child and parent pids are equal");
+
+ /* check that we can access the fd, the close it and exit */
+ if (rump_sys_write(fd, &fd, sizeof(fd)) != sizeof(fd))
+ errx(1, "write child /dev/null");
+ rump_sys_close(fd);
+ break;
+ default:
+ /*
+ * check that we can access the fd, wait for the child, and
+ * check we can still access the fd
+ */
+ if (rump_sys_write(fd, &fd, sizeof(fd)) != sizeof(fd))
+ errx(1, "write parent /dev/null");
+ if (wait(&status) == -1)
+ err(1, "wait failed");
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ errx(1, "child exited with status %d", status);
+ if (rump_sys_write(fd, &fd, sizeof(fd)) != sizeof(fd))
+ errx(1, "write parent /dev/null");
+ break;
+ }
+}
+
+static void
+cancel(void)
+{
+
+ /* XXX: not implemented in client / server !!! */
+}
+
+#define TESTSTR "i am your fatherrrrrrr"
+#define TESTSLEN (sizeof(TESTSTR)-1)
+static void
+pipecomm(void)
+{
+ struct rumpclient_fork *rf;
+ char buf[TESTSLEN+1];
+ int pipetti[2];
+ int status;
+
+ if (rump_sys_pipe(pipetti) == -1)
+ errx(1, "pipe");
+
+ if ((rf = rumpclient_prefork()) == NULL)
+ err(1, "prefork");
+
+ switch (fork()) {
+ case -1:
+ err(1, "fork");
+ break;
+ case 0:
+ if (rumpclient_fork_init(rf) == -1)
+ err(1, "postfork init failed");
+
+ memset(buf, 0, sizeof(buf));
+ if (rump_sys_read(pipetti[0], buf, TESTSLEN) != TESTSLEN)
+ err(1, "pipe read");
+ if (strcmp(TESTSTR, buf) != 0)
+ errx(1, "teststring doesn't match, got %s", buf);
+ break;
+ default:
+ if (rump_sys_write(pipetti[1], TESTSTR, TESTSLEN) != TESTSLEN)
+ err(1, "pipe write");
+ if (wait(&status) == -1)
+ err(1, "wait failed");
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ errx(1, "child exited with status %d", status);
+ break;
+ }
+}
+
+static void
+fakeauth(void)
+{
+ struct rumpclient_fork *rf;
+ uint32_t *auth;
+ int rv;
+
+ if ((rf = rumpclient_prefork()) == NULL)
+ err(1, "prefork");
+
+ /* XXX: we know the internal structure of rf */
+ auth = (void *)rf;
+ *(auth+3) = *(auth+3) ^ 0x1;
+
+ rv = rumpclient_fork_init(rf);
+ if (!(rv == -1 && errno == ESRCH))
+ exit(1);
+}
+
+struct parsa {
+ const char *arg; /* sp arg, el */
+ void (*spring)(void); /* spring into action */
+} paragus[] = {
+ { "simple", simple },
+ { "cancel", cancel },
+ { "pipecomm", pipecomm },
+ { "fakeauth", fakeauth },
+};
+
+int
+main(int argc, char *argv[])
+{
+ unsigned i;
+
+ if (argc != 2)
+ errx(1, "invalid usage");
+
+ if (rumpclient_init() == -1)
+ err(1, "rumpclient init");
+
+ for (i = 0; i < __arraycount(paragus); i++) {
+ if (strcmp(argv[1], paragus[i].arg) == 0) {
+ paragus[i].spring();
+ break;
+ }
+ }
+ if (i == __arraycount(paragus)) {
+ printf("invalid test %s\n", argv[1]);
+ exit(1);
+ }
+
+ exit(0);
+}
diff -r ca2156764814 -r 10ff4c93b8a7 tests/rump/rumpkern/t_sp.sh
--- a/tests/rump/rumpkern/t_sp.sh Wed Jan 05 17:14:50 2011 +0000
+++ b/tests/rump/rumpkern/t_sp.sh Wed Jan 05 17:19:09 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_sp.sh,v 1.3 2010/12/13 13:39:42 pooka Exp $
+# $NetBSD: t_sp.sh,v 1.4 2011/01/05 17:19:09 pooka Exp $
#
# Copyright (c) 2010 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -25,61 +25,58 @@
# POSSIBILITY OF SUCH DAMAGE.
#
-atf_test_case basic cleanup
-basic_head()
+test_case()
{
+ local name="${1}"; shift
+ local check_function="${1}"; shift
- atf_set "descr" "Check that basic remote server communication works"
+ atf_test_case "${name}" cleanup
+ eval "${name}_head() { }"
+ eval "${name}_body() { \
+ ${check_function} " "${@}" "; \
+ }"
+ eval "${name}_cleanup() { \
+ RUMP_SERVER=unix://commsock rump.halt
+ }"
}
-basic_body()
+test_case basic basic
+test_case stress_short stress 1
+test_case stress_long stress 10
+test_case fork_simple fork simple
+test_case fork_pipecomm fork pipecomm
+test_case fork_fakeauth fork fakeauth
+
+basic()
{
-
export RUMP_SERVER=unix://commsock
-
atf_check -s exit:0 rump_server ${RUMP_SERVER}
-
atf_check -s exit:0 $(atf_get_srcdir)/h_client/h_simplecli
}
-basic_cleanup()
-{
-
- docleanup
-}
-
-stresst=10
-atf_test_case stress cleanup
-stress_head()
-{
-
- atf_set "descr" "Stress/robustness test (~${stresst}s)"
-}
-
-stress_body()
+stress()
{
export RUMP_SERVER=unix://commsock
-
atf_check -s exit:0 rump_server ${RUMP_SERVER}
-
- atf_check -s exit:0 $(atf_get_srcdir)/h_client/h_stresscli ${stresst}
+ atf_check -s exit:0 $(atf_get_srcdir)/h_client/h_stresscli ${1}
}
-stress_cleanup()
+fork()
{
- docleanup
-}
-
-docleanup()
-{
- RUMP_SERVER=unix://commsock rump.halt
+ export RUMP_SERVER=unix://commsock
+ atf_check -s exit:0 rump_server -lrumpvfs ${RUMP_SERVER}
+ atf_check -s exit:0 $(atf_get_srcdir)/h_client/h_forkcli ${1}
}
atf_init_test_cases()
{
atf_add_test_case basic
- atf_add_test_case stress
+ atf_add_test_case stress_short
+ atf_add_test_case stress_long
+ atf_add_test_case fork_simple
+ atf_add_test_case fork_pipecomm
+ atf_add_test_case fork_fakeauth
}
Home |
Main Index |
Thread Index |
Old Index