Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/librumpclient add some exec() tests
details: https://anonhg.NetBSD.org/src/rev/fd9e0368641e
branches: trunk
changeset: 762094:fd9e0368641e
user: pooka <pooka%NetBSD.org@localhost>
date: Tue Feb 15 15:16:46 2011 +0000
description:
add some exec() tests
diffstat:
tests/lib/librumpclient/Atffile | 6 ++
tests/lib/librumpclient/Makefile | 10 +++-
tests/lib/librumpclient/h_exec.c | 102 ++++++++++++++++++++++++++++++++++++++
tests/lib/librumpclient/t_exec.sh | 85 +++++++++++++++++++++++++++++++
4 files changed, 202 insertions(+), 1 deletions(-)
diffs (229 lines):
diff -r 928e53059ce2 -r fd9e0368641e tests/lib/librumpclient/Atffile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumpclient/Atffile Tue Feb 15 15:16:46 2011 +0000
@@ -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_*
diff -r 928e53059ce2 -r fd9e0368641e tests/lib/librumpclient/Makefile
--- a/tests/lib/librumpclient/Makefile Tue Feb 15 14:24:23 2011 +0000
+++ b/tests/lib/librumpclient/Makefile Tue Feb 15 15:16:46 2011 +0000
@@ -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
diff -r 928e53059ce2 -r fd9e0368641e tests/lib/librumpclient/h_exec.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumpclient/h_exec.c Tue Feb 15 15:16:46 2011 +0000
@@ -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");
+}
diff -r 928e53059ce2 -r fd9e0368641e tests/lib/librumpclient/t_exec.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumpclient/t_exec.sh Tue Feb 15 15:16:46 2011 +0000
@@ -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
+}
Home |
Main Index |
Thread Index |
Old Index