Add tests for assigining/deleting IP addresses

The tests help to find defects related to creation/deletion
of routes/llentries and assigning/deleting of IP addresses.
This commit is contained in:
ozaki-r 2015-10-07 05:24:41 +00:00
parent 4ace1867fc
commit 44c97db88f
3 changed files with 200 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.648 2015/09/25 09:55:49 martin Exp $
# $NetBSD: mi,v 1.649 2015/10/07 05:24:41 ozaki-r Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -3186,6 +3186,7 @@
./usr/tests/net/net/Atffile tests-net-tests compattestfile,atf
./usr/tests/net/net/Kyuafile tests-net-tests compattestfile,atf,kyua
./usr/tests/net/net/t_forwarding tests-net-tests atf,rump
./usr/tests/net/net/t_ipaddress tests-net-tests atf,rump
./usr/tests/net/net/t_ipv6_lifetime tests-net-tests atf,rump
./usr/tests/net/net/t_pktinfo tests-net-tests compattestfile,atf
./usr/tests/net/net/t_raw tests-net-tests atf,rump

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.12 2015/08/06 08:23:14 ozaki-r Exp $
# $NetBSD: Makefile,v 1.13 2015/10/07 05:24:41 ozaki-r Exp $
#
.include <bsd.own.mk>
@ -12,6 +12,7 @@ TESTS_C+= t_pktinfo
.if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
TESTS_C+= t_raw
TESTS_SH= t_forwarding
TESTS_SH+= t_ipaddress
TESTS_SH+= t_ipv6_lifetime
.endif

View File

@ -0,0 +1,196 @@
# $NetBSD: t_ipaddress.sh,v 1.1 2015/10/07 05:24:41 ozaki-r Exp $
#
# Copyright (c) 2015 Internet Initiative Japan 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.
#
SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
SERVER6="$SERVER -lrumpnet_netinet6"
SOCK_LOCAL=unix://commsock1
BUS=bus
DEBUG=false
check_entry()
{
local ip=$(echo $1 |sed 's/\./\\./g')
local word=$2
atf_check -s exit:0 -o match:"$word" -e ignore -x \
"rump.netstat -rn | grep ^'$ip'"
}
check_entry_fail()
{
local ip=$(echo $1 |sed 's/\./\\./g')
local flags=$2 # Not used currently
atf_check -s not-exit:0 -e ignore -x \
"rump.netstat -rn | grep ^'$ip'"
}
test_same_address()
{
local ip=10.0.0.1
local net=10.0.0/24
local macaddr=
atf_check -s exit:0 ${SERVER} ${SOCK_LOCAL}
export RUMP_SERVER=$SOCK_LOCAL
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip/24
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
atf_check -s exit:0 -o ignore rump.ifconfig -w 10
$DEBUG && rump.netstat -nr -f inet
macaddr=$(rump.ifconfig shmif0 |awk '/address/ {print $2}')
check_entry $ip UHLl
check_entry $ip lo0
check_entry $ip $macaddr
check_entry $net UC
check_entry $net shmif0
check_entry $net 'link#2'
# Delete the address
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip delete
$DEBUG && rump.netstat -nr -f inet
check_entry_fail $ip
check_entry_fail $net
# Assign the same address again
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip/24
atf_check -s exit:0 -o ignore rump.ifconfig -w 10
$DEBUG && rump.netstat -nr -f inet
check_entry $ip UHLl
check_entry $ip lo0
check_entry $ip $macaddr
check_entry $net UC
check_entry $net shmif0
check_entry $net 'link#2'
# Delete the address again
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip delete
$DEBUG && rump.netstat -nr -f inet
check_entry_fail $ip
check_entry_fail $net
}
test_same_address6()
{
local ip=fc00::1
local net=fc00::/64
local macaddr=
atf_check -s exit:0 ${SERVER6} ${SOCK_LOCAL}
export RUMP_SERVER=$SOCK_LOCAL
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
atf_check -s exit:0 -o ignore rump.ifconfig -w 10
$DEBUG && rump.netstat -nr -f inet6
macaddr=$(rump.ifconfig shmif0 |awk '/address/ {print $2}')
check_entry $ip UHLl
check_entry $ip lo0
check_entry $ip $macaddr
check_entry $net UC
check_entry $net shmif0
check_entry $net 'link#2'
# Delete the address
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip delete
$DEBUG && rump.netstat -nr -f inet6
check_entry_fail $ip
check_entry_fail $net
# Assign the same address again
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip
atf_check -s exit:0 -o ignore rump.ifconfig -w 10
$DEBUG && rump.netstat -nr -f inet6
check_entry $ip UHLl
check_entry $ip lo0
check_entry $ip $macaddr
check_entry $net UC
check_entry $net shmif0
check_entry $net 'link#2'
# Delete the address again
atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip delete
$DEBUG && rump.netstat -nr -f inet6
check_entry_fail $ip
check_entry_fail $net
}
cleanup()
{
$DEBUG && shmif_dumpbus -p - $BUS 2>/dev/null | tcpdump -n -e -r -
env RUMP_SERVER=$SOCK_LOCAL rump.halt
}
add_test()
{
local name=$1
local desc="$2"
atf_test_case "ipaddr_${name}" cleanup
eval "ipaddr_${name}_head() { \
atf_set \"descr\" \"${desc}\"; \
atf_set \"require.progs\" \"rump_server\"; \
}; \
ipaddr_${name}_body() { \
test_${name}; \
}; \
ipaddr_${name}_cleanup() { \
cleanup; \
}"
atf_add_test_case "ipaddr_${name}"
}
atf_init_test_cases()
{
add_test same_address "Assigning/deleting an IP address twice"
add_test same_address6 "Assigning/deleting an IPv6 address twice"
}