On Wed, 5 Oct 2016 15:31:39 +0200
Alexander Bluhm <[email protected]> wrote:
> On Wed, Oct 05, 2016 at 04:48:55PM +0900, YASUOKA Masahiko wrote:
>> The diff add regress scripts for vxlan(4) and etherip(4).
>>
>> This will be my first commit to regress/. ok?
>
> I does not run with an obj directory.
>
> root@ot1:.../etherip# make obj
> /usr/src/regress/sys/net/etherip/obj -> /usr/obj/regress/sys/net/etherip
> root@ot1:.../etherip# make
> ksh etherip_1.sh
> ksh: etherip_1.sh: No such file or directory
> *** Error 1 in . (Makefile:7 'etherip_1')
> FAILED
> *** Error 1 in target 'regress' (ignored)
>
>> +# rdomains
>> +RD1=11
>> +RD2=12
>> +
>> +# interface minor numbers
>> +IFNO1=11
>> +IFNO2=12
>
> I would prefer to see these variables in the Makefile. There you
> should tune the test resources. And a little longer names perhaps.
>
>> +if [ $VAL -eq 0 ]; then
>> + echo "Aborted. Disabled etherip by sysctl net.inet.etherip.allow" >&2
>> + exit 255
>> +fi
>
> Could you print SKIPPED here. My test framework checks for this
> to find tests that cannot run in the current environment.
Thanks.
Fixed the scripts according to your comments.
ok?
diff --git a/regress/sys/net/Makefile b/regress/sys/net/Makefile
index 40f49cc..f46c3dd 100644
--- a/regress/sys/net/Makefile
+++ b/regress/sys/net/Makefile
@@ -1,5 +1,6 @@
# $OpenBSD: Makefile,v 1.9 2016/09/21 10:40:39 mpi Exp $
-SUBDIR += pf_divert pf_forward pf_fragment pf_print rdomains rtable
+SUBDIR += etherip pf_divert pf_forward pf_fragment pf_print rdomains
+SUBDIR += rtable
.include <bsd.subdir.mk>
diff --git a/regress/sys/net/etherip/Makefile b/regress/sys/net/etherip/Makefile
new file mode 100644
index 0000000..2b611ae
--- /dev/null
+++ b/regress/sys/net/etherip/Makefile
@@ -0,0 +1,15 @@
+# $OpenBSD$
+
+REGRESS_TARGETS= etherip_1
+REGRESS_ROOT_TARGETS= etherip_1
+
+RDOMAINS= 11 12
+IFACE_NUMS= 11 12
+
+test_config:
+ touch $@
+
+etherip_1: test_config
+ ${SUDO} ksh ${.CURDIR}/[email protected] -R "${RDOMAINS}" -I "${IFACE_NUMS}"
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/net/etherip/etherip_1.sh
b/regress/sys/net/etherip/etherip_1.sh
new file mode 100644
index 0000000..7ab80b2
--- /dev/null
+++ b/regress/sys/net/etherip/etherip_1.sh
@@ -0,0 +1,91 @@
+#!/bin/ksh
+# $OpenBSD$
+
+
+cleanup()
+{
+ for if in $ALL_IFS; do
+ ifconfig $if destroy 2>/dev/null
+ done
+}
+
+CURDIR=$(cd $(dirname $0); pwd)
+
+. ${CURDIR}/etherip_subr
+
+# rdomains
+set -- $RDOMAINS
+if [ $# -lt 2 ]; then
+ echo "2 rdomain(-R option) is required" >&2
+ exit 64
+fi
+RD1=$1
+RD2=$2
+
+# interface minor numbers
+set -- $IFACE_NUMS
+if [ $# -lt 2 ]; then
+ echo "2 interface numbers(-I option) is required" >&2
+ exit 64
+fi
+IFNO1=$1
+IFNO2=$2
+
+ALL_IFS="bridge$IFNO2 bridge$IFNO1 vether$IFNO2 vether$IFNO1 etherip$IFNO2
+ etherip$IFNO1 pair$IFNO2 pair$IFNO1"
+
+[ $CLEANUP -gt 0 ] && cleanup
+#
+# Check pre-conditions
+#
+# etherip is enabled by sysctl?
+VAL=$(sysctl -n net.inet.etherip.allow)
+VAL=${VAL:-0}
+if [ $VAL -eq 0 ]; then
+ echo "SKIPPED Disabled etherip by sysctl net.inet.etherip.allow" >&2
+ exit 255
+fi
+# interfaces are busy?
+for if in $ALL_IFS; do
+ if iface_exists $if; then
+ echo "Aborted. interface \`$if' is used already." >&2
+ exit 255
+ fi
+done
+# rdomains are busy?
+for rt in $RD1 $RD2; do
+ if ! rdomain_is_used $rt; then
+ echo "Aborted. rdomain \`$rt' is used already." >&2
+ exit 255
+ fi
+done
+
+#
+# Prepeare the test
+#
+[ $VERBOSE -gt 0 ] && set -x
+ifconfig pair$IFNO1 rdomain $RD1 172.31.0.1/24
+ifconfig pair$IFNO2 rdomain $RD2 172.31.0.2/24 patch pair$IFNO1
+ifconfig vether$IFNO1 rdomain $RD1 192.168.0.1
+ifconfig vether$IFNO2 rdomain $RD2 192.168.0.2
+ifconfig etherip$IFNO1 rdomain $RD1 tunneldomain $RD1 || abort_test
+ifconfig etherip$IFNO2 rdomain $RD2 tunneldomain $RD2 || abort_test
+ifconfig bridge$IFNO1 rdomain $RD1 add vether$IFNO1 add etherip$IFNO1 up
+ifconfig bridge$IFNO2 rdomain $RD2 add vether$IFNO2 add etherip$IFNO2 up
+
+#
+# Test config
+#
+ifconfig etherip$IFNO1 tunnel 172.31.0.1 172.31.0.2 up || abort_test
+ifconfig etherip$IFNO2 tunnel 172.31.0.2 172.31.0.1 up || abort_test
+
+#
+# Test behavior
+#
+test ping -w 1 -c 1 -V $RD1 192.168.0.2
+test ping -w 1 -c 1 -V $RD2 192.168.0.1
+set +x
+
+# Done
+cleanup
+exit $FAILS
diff --git a/regress/sys/net/etherip/etherip_subr
b/regress/sys/net/etherip/etherip_subr
new file mode 100644
index 0000000..a45d253
--- /dev/null
+++ b/regress/sys/net/etherip/etherip_subr
@@ -0,0 +1,79 @@
+#
+# Copyright (c) 2015 Vincent Gross <[email protected]>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+CLEANUP=0
+VERBOSE=0
+FAILS=0
+
+iface_exists()
+{
+ ifconfig_out=`ifconfig "$1" 2>&1`
+ [ "${ifconfig_out}" != "$1: no such interface" ]
+}
+
+rdomain_is_used()
+{
+ _rdomains=$(ifconfig | sed -n '/^[a-z].* rdomain \([0-9]*\).*/s//\1/p' \
+ | sort | uniq)
+ for _r in $_rdomains; do
+ if [ $_r = $1 ]; then
+ return 1
+ fi
+ done
+ return 0
+}
+
+abort_test()
+{
+ echo "** Aborted" >&2
+ [ $# -ge 0 ] && echo "$1" >&2
+ cleanup
+ exit 1
+}
+
+test()
+{
+ if [ $VERBOSE -gt 0 ]; then
+ "$@"
+ else
+ "$@" > /dev/null 2>&1
+ fi
+ if [ $? -ne 0 ]; then
+ FAILS=$((FAILS + 1))
+ fi
+}
+
+RDOMAINS=""
+IFACE_NUMS=""
+while getopts 'cvR:I:' ch "$@"; do
+ case $ch in
+ c)
+ CLEANUP=1
+ ;;
+ v)
+ VERBOSE=$((VERBOSE + 1))
+ ;;
+ R)
+ RDOMAINS="$RDOMAINS $OPTARG"
+ ;;
+ I)
+ IFACE_NUMS="$IFACE_NUMS $OPTARG"
+ ;;
+ *)
+ echo "usage: $(basename $0) [-cv][-R rodmains][-I iface_nums]"
+ exit 64
+ ;;
+ esac
+done
diff --git a/regress/sys/net/vxlan/Makefile b/regress/sys/net/vxlan/Makefile
new file mode 100644
index 0000000..3c900ff
--- /dev/null
+++ b/regress/sys/net/vxlan/Makefile
@@ -0,0 +1,15 @@
+# $OpenBSD$
+
+REGRESS_TARGETS= vxlan_1
+REGRESS_ROOT_TARGETS= vxlan_1
+
+RDOMAINS= 11 12
+IFACE_NUMS= 11 12
+
+test_config:
+ touch $@
+
+vxlan_1: test_config
+ ${SUDO} ksh ${.CURDIR}/[email protected] -R "${RDOMAINS}" -I "${IFACE_NUMS}"
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/net/vxlan/vxlan_1.sh b/regress/sys/net/vxlan/vxlan_1.sh
new file mode 100644
index 0000000..b064ba9
--- /dev/null
+++ b/regress/sys/net/vxlan/vxlan_1.sh
@@ -0,0 +1,84 @@
+#!/bin/ksh
+# $OpenBSD$
+
+
+cleanup()
+{
+ for if in $ALL_IFS; do
+ ifconfig $if destroy 2>/dev/null
+ done
+}
+
+CURDIR=$(cd $(dirname $0); pwd)
+
+. ${CURDIR}/vxlan_subr
+
+# rdomains
+set -- $RDOMAINS
+if [ $# -lt 2 ]; then
+ echo "2 rdomain(-R option) is required" >&2
+ exit 64
+fi
+RD1=$1
+RD2=$2
+
+# interface minor numbers
+set -- $IFACE_NUMS
+if [ $# -lt 2 ]; then
+ echo "2 interface numbers(-I option) is required" >&2
+ exit 64
+fi
+IFNO1=$1
+IFNO2=$2
+
+ALL_IFS="bridge$IFNO2 bridge$IFNO1 vether$IFNO2 vether$IFNO1 vxlan$IFNO2
+ vxlan$IFNO1 pair$IFNO2 pair$IFNO1"
+
+[ $CLEANUP -gt 0 ] && cleanup
+#
+# Check pre-conditions
+#
+# interfaces are busy?
+for if in $ALL_IFS; do
+ if iface_exists $if; then
+ echo "Aborted. interface \`$if' is used already." >&2
+ exit 255
+ fi
+done
+# rdomains are busy?
+for rt in $RD1 $RD2; do
+ if ! rdomain_is_used $rt; then
+ echo "Aborted. rdomain \`$rt' is used already." >&2
+ exit 255
+ fi
+done
+
+#
+# Prepeare the test
+#
+[ $VERBOSE -gt 0 ] && set -x
+ifconfig pair$IFNO1 rdomain $RD1 172.31.0.1/24
+ifconfig pair$IFNO2 rdomain $RD2 172.31.0.2/24 patch pair$IFNO1
+ifconfig vether$IFNO1 rdomain $RD1 192.168.0.1
+ifconfig vether$IFNO2 rdomain $RD2 192.168.0.2
+ifconfig vxlan$IFNO1 rdomain $RD1 tunneldomain $RD1 || abort_test
+ifconfig vxlan$IFNO2 rdomain $RD2 tunneldomain $RD2 || abort_test
+ifconfig bridge$IFNO1 rdomain $RD1 add vether$IFNO1 add vxlan$IFNO1 up
+ifconfig bridge$IFNO2 rdomain $RD2 add vether$IFNO2 add vxlan$IFNO2 up
+
+#
+# Test config
+#
+ifconfig vxlan$IFNO1 tunnel 172.31.0.1 172.31.0.2 vnetid 100 up || abort_test
+ifconfig vxlan$IFNO2 tunnel 172.31.0.2 172.31.0.1 vnetid 100 up || abort_test
+
+#
+# Test behavior
+#
+test ping -w 1 -c 1 -V $RD1 192.168.0.2
+test ping -w 1 -c 1 -V $RD2 192.168.0.1
+set +x
+
+# Done
+cleanup
+exit $FAILS
diff --git a/regress/sys/net/vxlan/vxlan_subr b/regress/sys/net/vxlan/vxlan_subr
new file mode 100644
index 0000000..a45d253
--- /dev/null
+++ b/regress/sys/net/vxlan/vxlan_subr
@@ -0,0 +1,79 @@
+#
+# Copyright (c) 2015 Vincent Gross <[email protected]>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+CLEANUP=0
+VERBOSE=0
+FAILS=0
+
+iface_exists()
+{
+ ifconfig_out=`ifconfig "$1" 2>&1`
+ [ "${ifconfig_out}" != "$1: no such interface" ]
+}
+
+rdomain_is_used()
+{
+ _rdomains=$(ifconfig | sed -n '/^[a-z].* rdomain \([0-9]*\).*/s//\1/p' \
+ | sort | uniq)
+ for _r in $_rdomains; do
+ if [ $_r = $1 ]; then
+ return 1
+ fi
+ done
+ return 0
+}
+
+abort_test()
+{
+ echo "** Aborted" >&2
+ [ $# -ge 0 ] && echo "$1" >&2
+ cleanup
+ exit 1
+}
+
+test()
+{
+ if [ $VERBOSE -gt 0 ]; then
+ "$@"
+ else
+ "$@" > /dev/null 2>&1
+ fi
+ if [ $? -ne 0 ]; then
+ FAILS=$((FAILS + 1))
+ fi
+}
+
+RDOMAINS=""
+IFACE_NUMS=""
+while getopts 'cvR:I:' ch "$@"; do
+ case $ch in
+ c)
+ CLEANUP=1
+ ;;
+ v)
+ VERBOSE=$((VERBOSE + 1))
+ ;;
+ R)
+ RDOMAINS="$RDOMAINS $OPTARG"
+ ;;
+ I)
+ IFACE_NUMS="$IFACE_NUMS $OPTARG"
+ ;;
+ *)
+ echo "usage: $(basename $0) [-cv][-R rodmains][-I iface_nums]"
+ exit 64
+ ;;
+ esac
+done