Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/net/if_tap tap(4): update the test so that we can open...
details: https://anonhg.NetBSD.org/src/rev/e544459012cc
branches: trunk
changeset: 940016:e544459012cc
user: roy <roy%NetBSD.org@localhost>
date: Wed Sep 30 14:43:15 2020 +0000
description:
tap(4): update the test so that we can open the tap to ping across a bridge
ping with tap closed to ensure it fails
ping with tap open to ensure it works
diffstat:
tests/net/if_tap/Makefile | 7 +++-
tests/net/if_tap/rump_open_tap.c | 79 ++++++++++++++++++++++++++++++++++++++++
tests/net/if_tap/t_tap.sh | 28 ++++++++++++--
3 files changed, 109 insertions(+), 5 deletions(-)
diffs (180 lines):
diff -r 8ff45bf1ee98 -r e544459012cc tests/net/if_tap/Makefile
--- a/tests/net/if_tap/Makefile Wed Sep 30 08:43:47 2020 +0000
+++ b/tests/net/if_tap/Makefile Wed Sep 30 14:43:15 2020 +0000
@@ -1,8 +1,13 @@
-# $NetBSD: Makefile,v 1.2 2016/11/25 08:51:16 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.3 2020/09/30 14:43:15 roy Exp $
#
.include <bsd.own.mk>
+PROG= rump_open_tap
+MAN=
+DPADD= ${LIBRUMPRES}
+LDADD= -lrumpres
+
TESTSDIR= ${TESTSBASE}/net/if_tap
.for name in tap
diff -r 8ff45bf1ee98 -r e544459012cc tests/net/if_tap/rump_open_tap.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/if_tap/rump_open_tap.c Wed Sep 30 14:43:15 2020 +0000
@@ -0,0 +1,79 @@
+/* $NetBSD: rump_open_tap.c,v 1.1 2020/09/30 14:43:15 roy Exp $ */
+
+/*
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roy Marples.
+ *
+ * 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 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/cdefs.h>
+__RCSID("$NetBSD: rump_open_tap.c,v 1.1 2020/09/30 14:43:15 roy Exp $");
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <rump/rump_syscalls.h>
+#include <rump/rumpclient.h>
+
+int
+main(int argc, char **argv)
+{
+ int fd;
+
+ if (argc < 2)
+ errx(EXIT_FAILURE, "No path specified");
+
+ rumpclient_init();
+
+ fd = rump_sys_open(argv[1], O_RDWR);
+ if (fd == -1)
+ err(EXIT_FAILURE, "open: %s", argv[1]);
+
+ if (argc > 2) {
+ FILE *fp;
+ pid_t pid;
+
+ fp = fopen(argv[2], "w");
+ if (fp == NULL)
+ err(EXIT_FAILURE, "fopen: %s", argv[2]);
+
+ pid = fork();
+ switch (pid) {
+ case -1:
+ err(EXIT_FAILURE, "fork");
+ case 0:
+ break;
+ default:
+ fprintf(fp, "%d\n", pid);
+ exit(EXIT_SUCCESS);
+ }
+ }
+
+ /* Spin with the fd open */
+ for (;;)
+ sleep(100);
+}
diff -r 8ff45bf1ee98 -r e544459012cc tests/net/if_tap/t_tap.sh
--- a/tests/net/if_tap/t_tap.sh Wed Sep 30 08:43:47 2020 +0000
+++ b/tests/net/if_tap/t_tap.sh Wed Sep 30 14:43:15 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_tap.sh,v 1.10 2019/08/19 03:22:05 ozaki-r Exp $
+# $NetBSD: t_tap.sh,v 1.11 2020/09/30 14:43:15 roy Exp $
#
# Copyright (c) 2016 Internet Initiative Japan Inc.
# All rights reserved.
@@ -34,6 +34,7 @@
IP6_LOCAL=fc00::1
IP6_TAP=fc00::2
IP6_REMOTE=fc00::3
+TAP_PID=./.__tap.pid
DEBUG=${DEBUG:-false}
TIMEOUT=1
@@ -130,6 +131,7 @@
tap_bridged_body()
{
+ local src="$(atf_get_srcdir)"
rump_server_fs_start $SOCK_LOCAL netinet6 tap bridge
rump_server_fs_start $SOCK_REMOTE netinet6 tap
@@ -146,7 +148,6 @@
atf_check -s exit:0 rump.ifconfig tap0 $IP4_TAP
atf_check -s exit:0 rump.ifconfig tap0 inet6 $IP6_TAP
atf_check -s exit:0 rump.ifconfig tap0 up
- atf_check -s exit:0 rump.ifconfig -w 10
rump_server_add_iface $SOCK_LOCAL bridge0
atf_check -s exit:0 rump.ifconfig bridge0 up
@@ -155,6 +156,8 @@
atf_check -s exit:0 brconfig bridge0 add tap0
unset LD_PRELOAD
+ atf_check -s exit:0 rump.ifconfig -w 10
+
export RUMP_SERVER=${SOCK_REMOTE}
atf_check -s exit:0 rump.ifconfig shmif0 $IP4_REMOTE
@@ -162,10 +165,22 @@
atf_check -s exit:0 rump.ifconfig shmif0 up
atf_check -s exit:0 rump.ifconfig -w 10
+ # shmif0 on the server bridge is active, we expect this to work
atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_LOCAL
+ atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_LOCAL
+
+ # The tap is not open, we expect this to fail
+ atf_check -s not-exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_TAP
+ atf_check -s not-exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_TAP
+
+ # Open the tap on the server
+ export RUMP_SERVER=${SOCK_LOCAL}
+ atf_check -s exit:0 "$src"/rump_open_tap /dev/tap0 $TAP_PID
+ atf_check -s exit:0 rump.ifconfig -w 10
+
+ # Now we can ping the tap address
+ export RUMP_SERVER=${SOCK_LOCAL}
atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_TAP
-
- atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_LOCAL
atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_TAP
rump_server_destroy_ifaces
@@ -174,6 +189,11 @@
tap_bridged_cleanup()
{
+ if [ -f $TAP_PID ]; then
+ kill -9 $(cat $TAP_PID)
+ rm -f $TAP_PID
+ sleep 1
+ fi
$DEBUG && dump
cleanup
}
Home |
Main Index |
Thread Index |
Old Index