Module Name:    src
Committed By:   pooka
Date:           Wed Jan  5 17:19:09 UTC 2011

Modified Files:
        src/tests/rump/rumpkern: t_sp.sh
        src/tests/rump/rumpkern/h_client: Makefile
Added Files:
        src/tests/rump/rumpkern/h_client: h_forkcli.c

Log Message:
Some tests for rumpclient fork.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/rump/rumpkern/t_sp.sh
cvs rdiff -u -r1.2 -r1.3 src/tests/rump/rumpkern/h_client/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/rump/rumpkern/h_client/h_forkcli.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/rump/rumpkern/t_sp.sh
diff -u src/tests/rump/rumpkern/t_sp.sh:1.3 src/tests/rump/rumpkern/t_sp.sh:1.4
--- src/tests/rump/rumpkern/t_sp.sh:1.3	Mon Dec 13 13:39:42 2010
+++ src/tests/rump/rumpkern/t_sp.sh	Wed Jan  5 17:19:09 2011
@@ -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
+        }"
+}
+
+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_body()
+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
 }

Index: src/tests/rump/rumpkern/h_client/Makefile
diff -u src/tests/rump/rumpkern/h_client/Makefile:1.2 src/tests/rump/rumpkern/h_client/Makefile:1.3
--- src/tests/rump/rumpkern/h_client/Makefile:1.2	Sun Dec 12 12:53:35 2010
+++ src/tests/rump/rumpkern/h_client/Makefile	Wed Jan  5 17:19:09 2011
@@ -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
 

Added files:

Index: src/tests/rump/rumpkern/h_client/h_forkcli.c
diff -u /dev/null src/tests/rump/rumpkern/h_client/h_forkcli.c:1.1
--- /dev/null	Wed Jan  5 17:19:10 2011
+++ src/tests/rump/rumpkern/h_client/h_forkcli.c	Wed Jan  5 17:19:09 2011
@@ -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);
+}

Reply via email to