Module Name:    src
Committed By:   pooka
Date:           Tue Feb 15 15:16:46 UTC 2011

Modified Files:
        src/tests/lib/librumpclient: Makefile
Added Files:
        src/tests/lib/librumpclient: Atffile h_exec.c t_exec.sh

Log Message:
add some exec() tests


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/lib/librumpclient/Atffile \
    src/tests/lib/librumpclient/h_exec.c \
    src/tests/lib/librumpclient/t_exec.sh
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/librumpclient/Makefile

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

Modified files:

Index: src/tests/lib/librumpclient/Makefile
diff -u src/tests/lib/librumpclient/Makefile:1.1 src/tests/lib/librumpclient/Makefile:1.2
--- src/tests/lib/librumpclient/Makefile:1.1	Wed Feb  9 14:32:45 2011
+++ src/tests/lib/librumpclient/Makefile	Tue Feb 15 15:16:46 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.1 2011/02/09 14:32:45 pooka Exp $
+#	$NetBSD: Makefile,v 1.2 2011/02/15 15:16:46 pooka Exp $
 #
 
 .include <bsd.own.mk>
@@ -6,6 +6,14 @@
 TESTSDIR=	${TESTSBASE}/lib/librumpclient
 
 TESTS_C=	t_fd
+TESTS_C+=	h_exec
+
+TESTS_SH=	t_exec
+
+# what do you mean I missed?
+LINKS+=		${TESTSDIR}/h_exec ${TESTSDIR}/h_ution
+
+ATFFILE=	yes
 
 LDADD+= -lrumpclient
 

Added files:

Index: src/tests/lib/librumpclient/Atffile
diff -u /dev/null src/tests/lib/librumpclient/Atffile:1.1
--- /dev/null	Tue Feb 15 15:16:46 2011
+++ src/tests/lib/librumpclient/Atffile	Tue Feb 15 15:16:46 2011
@@ -0,0 +1,6 @@
+Content-Type: application/X-atf-atffile; version="1"
+X-NetBSD-Id: "$NetBSD: Atffile,v 1.1 2011/02/15 15:16:46 pooka Exp $"
+
+prop: test-suite = "NetBSD"
+
+tp-glob: t_*
Index: src/tests/lib/librumpclient/h_exec.c
diff -u /dev/null src/tests/lib/librumpclient/h_exec.c:1.1
--- /dev/null	Tue Feb 15 15:16:46 2011
+++ src/tests/lib/librumpclient/h_exec.c	Tue Feb 15 15:16:46 2011
@@ -0,0 +1,102 @@
+/*	$NetBSD: h_exec.c,v 1.1 2011/02/15 15:16:46 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>
+
+/*
+ * Uses rumphijack because it's convenient with exec.  XXX: fixme to
+ * have sensible exec support in rumpclient.
+ */
+
+int
+main(int argc, char *argv[])
+{
+	struct sockaddr_in sin;
+	socklen_t slen;
+	int s1, s2;
+	char buf[12];
+
+	if (argc > 1) {
+		if (strcmp(argv[1], "_didexec") == 0) {
+			daemon(0, 0); /* detach-me-notnot ergo detach */
+			s1 = atoi(argv[2]);
+			slen = sizeof(sin);
+			/* see below */
+			accept(s1, (struct sockaddr *)&sin, &slen);
+		}
+	}
+
+	/* open and listenize two TCP4 suckets */
+	if ((s1 = socket(PF_INET, SOCK_STREAM, 0)) == -1)
+		err(1, "socket 1");
+	if ((s2 = 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 (bind(s1, (struct sockaddr *)&sin, sizeof(sin)) == -1)
+		err(1, "bind1");
+	sin.sin_port = htons(2345);
+	if (bind(s2, (struct sockaddr *)&sin, sizeof(sin)) == -1)
+		err(1, "bind2");
+
+	if (listen(s1, 1) == -1)
+		err(1, "listen1");
+	if (listen(s2, 1) == -1)
+		err(1, "listen2");
+
+	if (argc == 1) {
+		daemon(0, 0);
+		slen = sizeof(sin);
+		/*
+		 * "pause()", but conveniently gets rid of this helper
+		 * since we were called with RUMPCLIENT_RETRYCONN_DIE set
+		 */
+		accept(s1, (struct sockaddr *)&sin, &slen);
+	}
+
+	/* omstart! */
+	sprintf(buf, "%d", s1);
+	if (execl(argv[1], "h_ution", "_didexec", buf, NULL) == -1)
+		err(1, "exec");
+}
Index: src/tests/lib/librumpclient/t_exec.sh
diff -u /dev/null src/tests/lib/librumpclient/t_exec.sh:1.1
--- /dev/null	Tue Feb 15 15:16:46 2011
+++ src/tests/lib/librumpclient/t_exec.sh	Tue Feb 15 15:16:46 2011
@@ -0,0 +1,85 @@
+#       $NetBSD: t_exec.sh,v 1.1 2011/02/15 15:16:46 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_RETRY='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 LD_PRELOAD=/usr/lib/librumphijack.so \
+	    $(atf_get_srcdir)/h_exec
+	atf_check -s exit:0 -o save:sstat.out rump.sockstat
+	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 env LD_PRELOAD=/usr/lib/librumphijack.so \
+	    $(atf_get_srcdir)/h_exec $(atf_get_srcdir)/h_ution
+	atf_check -s exit:0 -o save:sstat.out rump.sockstat
+	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_init_test_cases()
+{
+	atf_add_test_case noexec
+	atf_add_test_case exec
+}

Reply via email to