summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2016-10-24 02:52:03 +0000
committerYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2016-10-24 02:52:03 +0000
commitd823c55d6e4b52be771013a1d80d120f6c90f5c4 (patch)
tree26b245659ce0b113ecb0dc4951b22f0dd6e03d6d /regress
parente6308991a5ebc996f3bc57e838d133e702b0a7cb (diff)
Add regress tests for carp(4).
Diffstat (limited to 'regress')
-rw-r--r--regress/sys/netinet/carp/Makefile15
-rw-r--r--regress/sys/netinet/carp/README4
-rw-r--r--regress/sys/netinet/carp/carp_1.sh90
-rw-r--r--regress/sys/netinet/carp/carp_2.sh93
-rw-r--r--regress/sys/netinet/carp/carp_3.sh90
-rw-r--r--regress/sys/netinet/carp/carp_4.sh93
-rw-r--r--regress/sys/netinet/carp/carp_subr79
7 files changed, 464 insertions, 0 deletions
diff --git a/regress/sys/netinet/carp/Makefile b/regress/sys/netinet/carp/Makefile
new file mode 100644
index 00000000000..b9747ec1bd7
--- /dev/null
+++ b/regress/sys/netinet/carp/Makefile
@@ -0,0 +1,15 @@
+# $OpenBSD: Makefile,v 1.1 2016/10/24 02:52:02 yasuoka Exp $
+
+REGRESS_TARGETS= carp_1 carp_2 carp_3 carp_4
+REGRESS_ROOT_TARGETS= carp_1 carp_2 carp_3 carp_4
+
+RDOMAINS= 11 12
+IFACE_NUMS= 11 12
+
+#TESTOPTS= -v
+
+carp_1 carp_2 carp_3 carp_4:
+ ${SUDO} ksh ${.CURDIR}/$@.sh -R "${RDOMAINS}" -I "${IFACE_NUMS}" \
+ ${TESTOPTS}
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/netinet/carp/README b/regress/sys/netinet/carp/README
new file mode 100644
index 00000000000..f8cdcaadfff
--- /dev/null
+++ b/regress/sys/netinet/carp/README
@@ -0,0 +1,4 @@
+carp_1: simplest. becoming master properly. demote.
+carp_2: carp_1 + without virtual mac.
+carp_3: carp_1 + carp peer
+carp_4: carp_1 + without virtual mac + carp peer
diff --git a/regress/sys/netinet/carp/carp_1.sh b/regress/sys/netinet/carp/carp_1.sh
new file mode 100644
index 00000000000..8aab39a6d6d
--- /dev/null
+++ b/regress/sys/netinet/carp/carp_1.sh
@@ -0,0 +1,90 @@
+#!/bin/ksh
+# $OpenBSD: carp_1.sh,v 1.1 2016/10/24 02:52:02 yasuoka Exp $
+
+
+cleanup()
+{
+ for if in $ALL_IFS; do
+ ifconfig $if destroy 2>/dev/null
+ done
+}
+
+CURDIR=$(cd $(dirname $0); pwd)
+
+. ${CURDIR}/carp_subr
+
+# rdomains
+set -- $RDOMAINS
+if [ $# -lt 2 ]; then
+ echo "2 rdomain(-R option) is required" >&2
+ exit 64
+fi
+RD1=$1
+RD2=$2
+IFGPREFIX=$(printf "regress%04x" $$)
+
+# 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="carp$IFNO1 carp$IFNO2 pair$IFNO1 pair$IFNO2"
+
+[ $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 192.168.0.2/24
+ifconfig pair$IFNO2 rdomain $RD2 192.168.0.3/24 patch pair$IFNO1
+
+#
+# Test config
+#
+ifconfig carp$IFNO1 rdomain $RD1 192.168.0.1/24 \
+ vhid 251 carpdev pair$IFNO1 -group carp group ${IFGPREFIX}a \
+ || abort_test
+ifconfig carp$IFNO2 rdomain $RD2 192.168.0.1/24 \
+ vhid 251 carpdev pair$IFNO2 -group carp group ${IFGPREFIX}b advskew 100 \
+ || abort_test
+
+#
+# Test behavior
+#
+
+# IFNO1 must become master
+sleep 3.1 # need 3 seconds to become master
+test sh -c "ifconfig carp$IFNO1 | grep -q 'status: master'"
+test sh -c "ifconfig carp$IFNO2 | grep -q 'status: backup'"
+
+# carpdemote must work
+ifconfig -g ${IFGPREFIX}a carpdemote
+sleep 0.1
+test sh -c "ifconfig carp$IFNO1 | grep -q 'status: backup'"
+test sh -c "ifconfig carp$IFNO2 | grep -q 'status: master'"
+
+# Done
+cleanup
+exit $FAILS
diff --git a/regress/sys/netinet/carp/carp_2.sh b/regress/sys/netinet/carp/carp_2.sh
new file mode 100644
index 00000000000..6b607e5f9a6
--- /dev/null
+++ b/regress/sys/netinet/carp/carp_2.sh
@@ -0,0 +1,93 @@
+#!/bin/ksh
+# $OpenBSD: carp_2.sh,v 1.1 2016/10/24 02:52:02 yasuoka Exp $
+
+
+cleanup()
+{
+ for if in $ALL_IFS; do
+ ifconfig $if destroy 2>/dev/null
+ done
+}
+
+CURDIR=$(cd $(dirname $0); pwd)
+
+. ${CURDIR}/carp_subr
+
+# rdomains
+set -- $RDOMAINS
+if [ $# -lt 2 ]; then
+ echo "2 rdomain(-R option) is required" >&2
+ exit 64
+fi
+RD1=$1
+RD2=$2
+IFGPREFIX=$(printf "regress%04x" $$)
+
+# 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="carp$IFNO1 carp$IFNO2 pair$IFNO1 pair$IFNO2"
+
+[ $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 192.168.0.2/24
+ifconfig pair$IFNO2 rdomain $RD2 192.168.0.3/24 patch pair$IFNO1
+
+lladdr1=$(ifconfig pair$IFNO1 | sed -n '/^.*lladdr \(.*\)/s//\1/p')
+lladdr2=$(ifconfig pair$IFNO2 | sed -n '/^.*lladdr \(.*\)/s//\1/p')
+
+#
+# Test config
+#
+ifconfig carp$IFNO1 rdomain $RD1 lladdr $lladdr1 192.168.0.1/24 \
+ vhid 251 carpdev pair$IFNO1 -group carp group ${IFGPREFIX}a \
+ || abort_test
+ifconfig carp$IFNO2 rdomain $RD2 lladdr $lladdr2 192.168.0.1/24 \
+ vhid 251 carpdev pair$IFNO2 -group carp group ${IFGPREFIX}b \
+ advskew 100 || abort_test
+
+#
+# Test behavior
+#
+
+# IFNO1 must become master
+sleep 3.1 # need 3 seconds to become master
+test sh -c "ifconfig carp$IFNO1 | grep -q 'status: master'"
+test sh -c "ifconfig carp$IFNO2 | grep -q 'status: backup'"
+
+# carpdemote must work
+ifconfig -g ${IFGPREFIX}a carpdemote
+sleep 0.1
+test sh -c "ifconfig carp$IFNO1 | grep -q 'status: backup'"
+test sh -c "ifconfig carp$IFNO2 | grep -q 'status: master'"
+
+# Done
+cleanup
+exit $FAILS
diff --git a/regress/sys/netinet/carp/carp_3.sh b/regress/sys/netinet/carp/carp_3.sh
new file mode 100644
index 00000000000..949b5fdf45e
--- /dev/null
+++ b/regress/sys/netinet/carp/carp_3.sh
@@ -0,0 +1,90 @@
+#!/bin/ksh
+# $OpenBSD: carp_3.sh,v 1.1 2016/10/24 02:52:02 yasuoka Exp $
+
+
+cleanup()
+{
+ for if in $ALL_IFS; do
+ ifconfig $if destroy 2>/dev/null
+ done
+}
+
+CURDIR=$(cd $(dirname $0); pwd)
+
+. ${CURDIR}/carp_subr
+
+# rdomains
+set -- $RDOMAINS
+if [ $# -lt 2 ]; then
+ echo "2 rdomain(-R option) is required" >&2
+ exit 64
+fi
+RD1=$1
+RD2=$2
+IFGPREFIX=$(printf "regress%04x" $$)
+
+# 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="carp$IFNO1 carp$IFNO2 pair$IFNO1 pair$IFNO2"
+
+[ $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 192.168.0.2/24
+ifconfig pair$IFNO2 rdomain $RD2 192.168.0.3/24 patch pair$IFNO1
+
+#
+# Test config
+#
+ifconfig carp$IFNO1 rdomain $RD1 192.168.0.1/24 \
+ vhid 251 carpdev pair$IFNO1 -group carp group ${IFGPREFIX}a \
+ carppeer 192.168.0.3 || abort_test
+ifconfig carp$IFNO2 rdomain $RD2 192.168.0.1/24 \
+ vhid 251 carpdev pair$IFNO2 -group carp group ${IFGPREFIX}b \
+ advskew 100 carppeer 192.168.0.2 || abort_test
+
+#
+# Test behavior
+#
+
+# IFNO1 must become master
+sleep 3.1 # need 3 seconds to become master
+test sh -c "ifconfig carp$IFNO1 | grep -q 'status: master'"
+test sh -c "ifconfig carp$IFNO2 | grep -q 'status: backup'"
+
+# carpdemote must work
+ifconfig -g ${IFGPREFIX}a carpdemote
+sleep 0.1
+test sh -c "ifconfig carp$IFNO1 | grep -q 'status: backup'"
+test sh -c "ifconfig carp$IFNO2 | grep -q 'status: master'"
+
+# Done
+cleanup
+exit $FAILS
diff --git a/regress/sys/netinet/carp/carp_4.sh b/regress/sys/netinet/carp/carp_4.sh
new file mode 100644
index 00000000000..059d787a427
--- /dev/null
+++ b/regress/sys/netinet/carp/carp_4.sh
@@ -0,0 +1,93 @@
+#!/bin/ksh
+# $OpenBSD: carp_4.sh,v 1.1 2016/10/24 02:52:02 yasuoka Exp $
+
+
+cleanup()
+{
+ for if in $ALL_IFS; do
+ ifconfig $if destroy 2>/dev/null
+ done
+}
+
+CURDIR=$(cd $(dirname $0); pwd)
+
+. ${CURDIR}/carp_subr
+
+# rdomains
+set -- $RDOMAINS
+if [ $# -lt 2 ]; then
+ echo "2 rdomain(-R option) is required" >&2
+ exit 64
+fi
+RD1=$1
+RD2=$2
+IFGPREFIX=$(printf "regress%04x" $$)
+
+# 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="carp$IFNO1 carp$IFNO2 pair$IFNO1 pair$IFNO2"
+
+[ $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 192.168.0.2/24
+ifconfig pair$IFNO2 rdomain $RD2 192.168.0.3/24 patch pair$IFNO1
+
+lladdr1=$(ifconfig pair$IFNO1 | sed -n '/^.*lladdr \(.*\)/s//\1/p')
+lladdr2=$(ifconfig pair$IFNO2 | sed -n '/^.*lladdr \(.*\)/s//\1/p')
+
+#
+# Test config
+#
+ifconfig carp$IFNO1 rdomain $RD1 lladdr $lladdr1 192.168.0.1/24 \
+ vhid 251 carpdev pair$IFNO1 -group carp group ${IFGPREFIX}a \
+ carppeer 192.168.0.3 || abort_test
+ifconfig carp$IFNO2 rdomain $RD2 lladdr $lladdr2 192.168.0.1/24 \
+ vhid 251 carpdev pair$IFNO2 -group carp group ${IFGPREFIX}b \
+ advskew 100 carppeer 192.168.0.2 || abort_test
+
+#
+# Test behavior
+#
+
+# IFNO1 must become master
+sleep 3.1 # need 3 seconds to become master
+test sh -c "ifconfig carp$IFNO1 | grep -q 'status: master'"
+test sh -c "ifconfig carp$IFNO2 | grep -q 'status: backup'"
+
+# carpdemote must work
+ifconfig -g ${IFGPREFIX}a carpdemote
+sleep 0.1
+test sh -c "ifconfig carp$IFNO1 | grep -q 'status: backup'"
+test sh -c "ifconfig carp$IFNO2 | grep -q 'status: master'"
+
+# Done
+cleanup
+exit $FAILS
diff --git a/regress/sys/netinet/carp/carp_subr b/regress/sys/netinet/carp/carp_subr
new file mode 100644
index 00000000000..a45d2535f4a
--- /dev/null
+++ b/regress/sys/netinet/carp/carp_subr
@@ -0,0 +1,79 @@
+#
+# Copyright (c) 2015 Vincent Gross <vgross@openbsd.org>
+#
+# 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