Source-Changes-HG archive

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

[src/trunk]: src Add tests for ARP



details:   https://anonhg.NetBSD.org/src/rev/73542eced9e9
branches:  trunk
changeset: 809717:73542eced9e9
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Jul 29 06:10:09 2015 +0000

description:
Add tests for ARP

diffstat:

 distrib/sets/lists/tests/mi |    6 +-
 etc/mtree/NetBSD.dist.tests |    3 +-
 tests/net/arp/Makefile      |   10 +
 tests/net/arp/t_arp.sh      |  238 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 255 insertions(+), 2 deletions(-)

diffs (293 lines):

diff -r a47945748675 -r 73542eced9e9 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Wed Jul 29 06:07:35 2015 +0000
+++ b/distrib/sets/lists/tests/mi       Wed Jul 29 06:10:09 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.633 2015/07/28 18:08:37 christos Exp $
+# $NetBSD: mi,v 1.634 2015/07/29 06:10:09 ozaki-r Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3098,6 +3098,10 @@
 ./usr/tests/net                                        tests-net-tests         compattestfile,atf
 ./usr/tests/net/Atffile                                tests-net-tests         compattestfile,atf
 ./usr/tests/net/Kyuafile                       tests-net-tests         compattestfile,atf,kyua
+./usr/tests/net/arp                            tests-net-tests         compattestfile,atf
+./usr/tests/net/arp/Atffile                    tests-net-tests         atf,rump
+./usr/tests/net/arp/Kyuafile                   tests-net-tests         atf,rump,kyua
+./usr/tests/net/arp/t_arp                      tests-net-tests         atf,rump
 ./usr/tests/net/bpf                            tests-net-tests         compattestfile,atf
 ./usr/tests/net/bpf/Atffile                    tests-net-tests         atf,rump
 ./usr/tests/net/bpf/Kyuafile                   tests-net-tests         atf,rump,kyua
diff -r a47945748675 -r 73542eced9e9 etc/mtree/NetBSD.dist.tests
--- a/etc/mtree/NetBSD.dist.tests       Wed Jul 29 06:07:35 2015 +0000
+++ b/etc/mtree/NetBSD.dist.tests       Wed Jul 29 06:10:09 2015 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: NetBSD.dist.tests,v 1.116 2015/01/06 03:26:05 christos Exp $
+#      $NetBSD: NetBSD.dist.tests,v 1.117 2015/07/29 06:10:10 ozaki-r Exp $
 
 ./usr/libdata/debug/usr/tests
 ./usr/libdata/debug/usr/tests/atf
@@ -307,6 +307,7 @@
 ./usr/tests/libexec/ld.elf_so/h_helper_symver_dso2
 ./usr/tests/modules
 ./usr/tests/net
+./usr/tests/net/arp
 ./usr/tests/net/bpf
 ./usr/tests/net/bpfilter
 ./usr/tests/net/bpfjit
diff -r a47945748675 -r 73542eced9e9 tests/net/arp/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/arp/Makefile    Wed Jul 29 06:10:09 2015 +0000
@@ -0,0 +1,10 @@
+# $NetBSD: Makefile,v 1.1 2015/07/29 06:10:10 ozaki-r Exp $
+#
+
+.include <bsd.own.mk>
+
+TESTSDIR=      ${TESTSBASE}/net/arp
+
+TESTS_SH=      t_arp
+
+.include <bsd.test.mk>
diff -r a47945748675 -r 73542eced9e9 tests/net/arp/t_arp.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/arp/t_arp.sh    Wed Jul 29 06:10:09 2015 +0000
@@ -0,0 +1,238 @@
+#      $NetBSD: t_arp.sh,v 1.1 2015/07/29 06:10:10 ozaki-r Exp $
+#
+# Copyright (c) 2015 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.
+#
+
+inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
+HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
+
+SOCKSRC=unix://commsock1
+SOCKDST=unix://commsock2
+IP4SRC=10.0.1.1
+IP4DST=10.0.1.2
+
+DEBUG=false
+TIMEOUT=1
+
+atf_test_case cache_expiration_5s cleanup
+atf_test_case cache_expiration_10s cleanup
+atf_test_case command cleanup
+
+cache_expiration_5s_head()
+{
+       atf_set "descr" "Tests for ARP cache expiration (5s)"
+       atf_set "require.progs" "rump_server"
+}
+
+cache_expiration_10s_head()
+{
+       atf_set "descr" "Tests for ARP cache expiration (10s)"
+       atf_set "require.progs" "rump_server"
+}
+
+command_head()
+{
+       atf_set "descr" "Tests for commands of arp(8)"
+       atf_set "require.progs" "rump_server"
+}
+
+setup_dst_server()
+{
+       export RUMP_SERVER=$SOCKDST
+       atf_check -s exit:0 rump.ifconfig shmif0 create
+       atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
+       atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4DST/24
+       atf_check -s exit:0 rump.ifconfig shmif0 up
+       atf_check -s exit:0 rump.ifconfig -w 10
+
+       $DEBUG && rump.ifconfig shmif0
+       $DEBUG && rump.arp -n -a
+}
+
+setup_src_server()
+{
+       local prune=$1
+       local keep=$2
+
+       export RUMP_SERVER=$SOCKSRC
+
+       # Adjust ARP parameters
+       atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.arp.prune=$prune
+       atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.arp.keep=$keep
+       # Don't refresh to test expiration easily
+       atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.arp.refresh=0
+
+       # Setup an interface
+       atf_check -s exit:0 rump.ifconfig shmif0 create
+       atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
+       atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4SRC/24
+       atf_check -s exit:0 rump.ifconfig shmif0 up
+       atf_check -s exit:0 rump.ifconfig -w 10
+
+       # Sanity check
+       $DEBUG && rump.ifconfig shmif0
+       $DEBUG && rump.arp -n -a
+       atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
+       atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
+}
+
+test_cache_expiration()
+{
+       local arp_prune=1
+       local arp_keep=$1
+       local bonus=2
+
+       atf_check -s exit:0 ${inetserver} $SOCKSRC
+       atf_check -s exit:0 ${inetserver} $SOCKDST
+
+       setup_dst_server
+       setup_src_server $arp_prune $arp_keep
+
+       #
+       # Check if a cache is expired expectedly
+       #
+       export RUMP_SERVER=$SOCKSRC
+       atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
+
+       $DEBUG && rump.arp -n -a
+       atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
+       # Should be cached
+       atf_check -s exit:0 -o ignore rump.arp -n $IP4DST
+
+       atf_check -s exit:0 sleep $(($arp_keep + $arp_prune + $bonus))
+
+       $DEBUG && rump.arp -n -a
+       atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
+       # Should be expired
+       #atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
+       atf_check -s exit:0 -o match:'incomplete' rump.arp -n $IP4DST
+}
+
+cache_expiration_5s_body()
+{
+       test_cache_expiration 5
+}
+
+cache_expiration_10s_body()
+{
+       test_cache_expiration 10
+}
+
+command_body()
+{
+       local arp_prune=1
+       local arp_keep=5
+       local bonus=2
+
+       atf_check -s exit:0 ${inetserver} $SOCKSRC
+       atf_check -s exit:0 ${inetserver} $SOCKDST
+
+       setup_dst_server
+       setup_src_server $arp_prune $arp_keep
+
+       export RUMP_SERVER=$SOCKSRC
+
+       # Add and delete a static entry
+       $DEBUG && rump.arp -n -a
+       atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10
+       $DEBUG && rump.arp -n -a
+       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.10
+       atf_check -s exit:0 -o ignore rump.arp -d 10.0.1.10
+       $DEBUG && rump.arp -n -a
+       atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
+
+       # Add multiple entries via a file
+       cat - > ./list <<-EOF
+       10.0.1.11 b2:a0:20:00:00:11
+       10.0.1.12 b2:a0:20:00:00:12
+       10.0.1.13 b2:a0:20:00:00:13
+       10.0.1.14 b2:a0:20:00:00:14
+       10.0.1.15 b2:a0:20:00:00:15
+       EOF
+       $DEBUG && rump.arp -n -a
+       atf_check -s exit:0 -o ignore rump.arp -f ./list
+       $DEBUG && rump.arp -n -a
+       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.11
+       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.12
+       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.13
+       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.14
+       atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.15
+
+       # Flush all entries
+       $DEBUG && rump.arp -n -a
+       atf_check -s exit:0 -o ignore rump.arp -d -a
+       atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.11
+       atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12
+       atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.13
+       atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.14
+       atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.15
+       atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.1
+}
+
+cleanup()
+{
+       env RUMP_SERVER=$SOCKSRC rump.halt
+       env RUMP_SERVER=$SOCKDST rump.halt
+}
+
+dump()
+{
+       export RUMP_SERVER=$SOCKSRC
+       rump.netstat -nr
+       rump.arp -n -a
+       $HIJACKING dmesg
+
+       export RUMP_SERVER=$SOCKDST
+       rump.netstat -nr
+       rump.arp -n -a
+       $HIJACKING dmesg
+
+       shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
+}
+
+cache_expiration_5s_cleanup()
+{
+       $DEBUG && dump
+       cleanup
+}
+
+cache_expiration_10s_cleanup()
+{
+       $DEBUG && dump
+       cleanup
+}
+
+command_cleanup()
+{
+       $DEBUG && dump
+       cleanup
+}
+
+atf_init_test_cases()
+{
+       atf_add_test_case cache_expiration_5s
+       atf_add_test_case cache_expiration_10s
+       atf_add_test_case command
+}



Home | Main Index | Thread Index | Old Index