Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib Add a simple test for the purpose of making sure r...



details:   https://anonhg.NetBSD.org/src/rev/a266d5eb7345
branches:  trunk
changeset: 761742:a266d5eb7345
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sun Feb 06 18:44:29 2011 +0000

description:
Add a simple test for the purpose of making sure rumphijack works
on -current in addition to 5.x.  The test serves a simple index.html
on a hijacked bozohttpd and checks the file can be retrieved.

diffstat:

 tests/lib/Makefile                     |    4 +-
 tests/lib/librumphijack/Atffile        |    6 +
 tests/lib/librumphijack/Makefile       |   16 +++++
 tests/lib/librumphijack/h_netget.c     |  101 +++++++++++++++++++++++++++++++++
 tests/lib/librumphijack/index.html     |    5 +
 tests/lib/librumphijack/netstat.expout |    6 +
 tests/lib/librumphijack/t_tcpip.sh     |   70 ++++++++++++++++++++++
 7 files changed, 206 insertions(+), 2 deletions(-)

diffs (244 lines):

diff -r 4473b3f9e0ba -r a266d5eb7345 tests/lib/Makefile
--- a/tests/lib/Makefile        Sun Feb 06 18:40:55 2011 +0000
+++ b/tests/lib/Makefile        Sun Feb 06 18:44:29 2011 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.10 2010/12/20 23:47:23 pgoyette Exp $
+# $NetBSD: Makefile,v 1.11 2011/02/06 18:44:29 pooka Exp $
 
 .include <bsd.own.mk>
 
 TESTS_SUBDIRS= csu libc libm libevent libobjc libposix libprop librt \
-               libpthread libutil semaphore
+               libpthread librumphijack libutil semaphore
 
 .if ${MKCRYPTO} != "no"
 TESTS_SUBDIRS+= libdes
diff -r 4473b3f9e0ba -r a266d5eb7345 tests/lib/librumphijack/Atffile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumphijack/Atffile   Sun Feb 06 18:44:29 2011 +0000
@@ -0,0 +1,6 @@
+Content-Type: application/X-atf-atffile; version="1"
+X-NetBSD-Id: "$NetBSD: Atffile,v 1.1 2011/02/06 18:44:29 pooka Exp $"
+
+prop: test-suite = "NetBSD"
+
+tp-glob: t_*
diff -r 4473b3f9e0ba -r a266d5eb7345 tests/lib/librumphijack/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumphijack/Makefile  Sun Feb 06 18:44:29 2011 +0000
@@ -0,0 +1,16 @@
+#      $NetBSD: Makefile,v 1.1 2011/02/06 18:44:29 pooka Exp $
+#
+
+.include <bsd.own.mk>
+
+TESTSDIR=      ${TESTSBASE}/lib/librumphijack
+
+TESTS_SH=      t_tcpip
+TESTS_C=       h_netget
+
+FILES=         netstat.expout index.html
+FILESDIR=      ${TESTSDIR}
+
+ATFFILE=       yes
+
+.include <bsd.test.mk>
diff -r 4473b3f9e0ba -r a266d5eb7345 tests/lib/librumphijack/h_netget.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumphijack/h_netget.c        Sun Feb 06 18:44:29 2011 +0000
@@ -0,0 +1,101 @@
+/*      $NetBSD: h_netget.c,v 1.1 2011/02/06 18:44:29 pooka Exp $      */
+
+/*-
+ * Copyright (c) 2011 Antti Kantee.  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 AUTHOR ``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 AUTHOR 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.
+ */
+
+/*
+ * simple utility to fetch a webpage.  we wouldn't need this
+ * if we had something like netcat in base
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: h_netget.c,v 1.1 2011/02/06 18:44:29 pooka Exp $");
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <arpa/inet.h>
+
+#include <netinet/in.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define GETSTR "GET / HTTP/1.0\n\n"
+
+int
+main(int argc, char *argv[])
+{
+       char buf[8192];
+       struct sockaddr_in sin;
+       ssize_t n;
+       int s, fd;
+
+       setprogname(argv[0]);
+       if (argc != 4) {
+               fprintf(stderr, "usage: %s address port savefile\n",
+                   getprogname());
+               exit(1);
+       }
+
+       s = socket(PF_INET, SOCK_STREAM, 0);
+       if (s == -1)
+               err(1, "socket");
+
+       memset(&sin, 0, sizeof(sin));
+       sin.sin_len = sizeof(sin);
+       sin.sin_family = AF_INET;
+       sin.sin_port = htons(atoi(argv[2]));
+       sin.sin_addr.s_addr = inet_addr(argv[1]);
+
+       fd = open(argv[3], O_CREAT | O_RDWR, 0644);
+       if (fd == -1)
+               err(1, "open");
+       if (ftruncate(fd, 0) == -1)
+               err(1, "ftruncate savefile");
+
+       if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) == -1)
+               err(1, "connect");
+
+       if (write(s, GETSTR, strlen(GETSTR)) != strlen(GETSTR))
+               err(1, "socket write");
+
+       for (;;) {
+               n = read(s, buf, sizeof(buf));
+               if (n == 0)
+                       break;
+               if (n == -1)
+                       err(1, "socket read");
+
+               if (write(fd, buf, n) != n)
+                       err(1, "write file");
+       }
+
+       exit(0);
+}
diff -r 4473b3f9e0ba -r a266d5eb7345 tests/lib/librumphijack/index.html
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumphijack/index.html        Sun Feb 06 18:44:29 2011 +0000
@@ -0,0 +1,5 @@
+<html><head>
+<title>test page</title>
+</head><body>
+i am a test, how do you do?
+</body></html>
diff -r 4473b3f9e0ba -r a266d5eb7345 tests/lib/librumphijack/netstat.expout
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumphijack/netstat.expout    Sun Feb 06 18:44:29 2011 +0000
@@ -0,0 +1,6 @@
+Active Internet connections (including servers)
+Proto Recv-Q Send-Q  Local Address          Foreign Address        State
+tcp        0      0  *.http                 *.*                    LISTEN
+Active Internet6 connections (including servers)
+Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
+tcp6       0      0  *.http                 *.*                    LISTEN
diff -r 4473b3f9e0ba -r a266d5eb7345 tests/lib/librumphijack/t_tcpip.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumphijack/t_tcpip.sh        Sun Feb 06 18:44:29 2011 +0000
@@ -0,0 +1,70 @@
+#       $NetBSD: t_tcpip.sh,v 1.1 2011/02/06 18:44:30 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.
+#
+
+rumpnetsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet'
+export RUMP_SERVER=unix://csock
+
+atf_test_case http cleanup
+http_head()
+{
+        atf_set "descr" "Start hijacked httpd and get webpage from it"
+}
+
+http_body()
+{
+
+       atf_check -s exit:0 ${rumpnetsrv} ${RUMP_SERVER}
+       # make sure clients die after we nuke the server
+       export RUMPHIJACK_RETRY='die'
+
+       # start bozo in daemon mode
+       atf_check -s exit:0 -e ignore env LD_PRELOAD=/usr/lib/librumphijack.so \
+           /usr/libexec/httpd -b -s $(atf_get_srcdir)
+
+       atf_check -s exit:0 -o file:"$(atf_get_srcdir)/netstat.expout" \
+           rump.netstat -a
+
+       # get the webpage
+       atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so    \
+           $(atf_get_srcdir)/h_netget 127.0.0.1 80 webfile
+
+       # check that we got what we wanted
+       atf_check -o match:'HTTP/1.0 200 OK' cat webfile
+       atf_check -o match:'Content-Length: 95' cat webfile
+       atf_check -o file:"$(atf_get_srcdir)/index.html" \
+           sed -n '1,/^
$/!p' webfile
+}
+
+http_cleanup()
+{
+       rump.halt
+}
+
+atf_init_test_cases()
+{
+       atf_add_test_case http
+}



Home | Main Index | Thread Index | Old Index