Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/netgraph/ng_macfilter_test.sh
Show All 23 Lines | |||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | # 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 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
# SUCH DAMAGE. | # SUCH DAMAGE. | ||||
# | # | ||||
# $FreeBSD$ | # $FreeBSD$ | ||||
set -e | |||||
progname="$(basename $0 .sh)" | progname="$(basename $0 .sh)" | ||||
entries_lst="/tmp/$progname.entries.lst" | entries_lst="/tmp/$progname.entries.lst" | ||||
entries2_lst="/tmp/$progname.entries2.lst" | entries2_lst="/tmp/$progname.entries2.lst" | ||||
HOOKS=3 | HOOKS=3 | ||||
HOOKSADD=42 | HOOKSADD=42 | ||||
ITERATIONS=7 | ITERATIONS=7 | ||||
SUBITERATIONS=71 | SUBITERATIONS=71 | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | test_ok () { | ||||
echo "ok $TSTNR - $msg" | echo "ok $TSTNR - $msg" | ||||
return 0 | return 0 | ||||
} | } | ||||
test_not_ok () { | test_not_ok () { | ||||
local msg="$1" | local msg="$1" | ||||
_test_next | _test_next | ||||
_test_fails | _test_fail | ||||
echo "not ok $TSTNR - $msg" | echo "not ok $TSTNR - $msg" | ||||
return 1 | return 1 | ||||
} | } | ||||
test_eq () { | test_eq () { | ||||
local v1="$1" v2="$2" msg="$3" | local v1="$1" v2="$2" msg="$3" | ||||
if [ "$v1" = "$v2" ]; then | if [ "$v1" = "$v2" ]; then | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | test_ge () { | ||||
local v1=$1 v2=$2 msg="$3" | local v1=$1 v2=$2 msg="$3" | ||||
if [ "$v1" -ge "$v2" ]; then | if [ "$v1" -ge "$v2" ]; then | ||||
test_ok "$v1 $msg" | test_ok "$v1 $msg" | ||||
else | else | ||||
test_not_ok "$v1 <= $v2 $msg" | test_not_ok "$v1 <= $v2 $msg" | ||||
fi | fi | ||||
} | } | ||||
test_rc () { test_eq $? $1 "$2"; } | test_failure () { | ||||
test_failure () { test_ne $? 0 "$1"; } | msg=$1 | ||||
test_success () { test_eq $? 0 "$1"; } | shift | ||||
if ! "$@"; then | |||||
test_ok "$msg - \"$@\" failed as expected" | |||||
else | |||||
test_not_ok "$msg - expected \"$@\" to fail but succeeded" | |||||
fi | |||||
} | |||||
test_success () { | |||||
msg=$1 | |||||
shift | |||||
if ! "$@"; then | |||||
test_not_ok "$msg - \"$@\" failed unexpectedly" | |||||
else | |||||
test_ok "$msg - \"$@\" succeeded" | |||||
fi | |||||
} | |||||
gethooks () { | gethooks () { | ||||
ngctl msg MF: 'gethooks' \ | ngctl msg MF: 'gethooks' \ | ||||
| perl -ne '$h{$1}=1 while s/hookname="(.*?)"//; sub END {print join(":", sort keys %h)."\n"}' | | perl -ne '$h{$1}=1 while s/hookname="(.*?)"//; sub END {print join(":", sort keys %h)."\n"}' | ||||
} | } | ||||
countmacs () { | countmacs () { | ||||
local hookname=${1:-'[^"]*'} | local hookname=${1:-'[^"]*'} | ||||
Show All 15 Lines | |||||
################################################################################ | ################################################################################ | ||||
### Start ###################################################################### | ### Start ###################################################################### | ||||
################################################################################ | ################################################################################ | ||||
test_title "Setting up system..." | test_title "Setting up system..." | ||||
load_modules netgraph ng_socket ng_ether ng_macfilter ng_one2many | load_modules netgraph ng_socket ng_ether ng_macfilter ng_one2many | ||||
eth=$(find_iface) | eth=$(find_iface) | ||||
if [ -z "$eth" ]; then | |||||
echo "1..1" | |||||
echo "not ok 1 - Could not find a valid interface" | |||||
echo "Available interfaces:" | |||||
ifconfig | |||||
exit 1 | |||||
fi | |||||
test_comment "Using $eth..." | test_comment "Using $eth..." | ||||
test_title "Configuring netgraph nodes..." | test_title "Configuring netgraph nodes..." | ||||
configure_nodes | configure_nodes | ||||
trap 'exit 99' 1 2 3 13 14 15 | trap 'exit 99' 1 2 3 13 14 15 | ||||
trap 'cleanup' EXIT | trap 'cleanup' EXIT | ||||
created_hooks=$(gethooks) | created_hooks=$(gethooks) | ||||
rc=0 | rc=0 | ||||
# Update this number when adding new tests | # Update this number when adding new tests | ||||
test_cnt 46 | test_cnt 46 | ||||
################################################################################ | ################################################################################ | ||||
### Tests ###################################################################### | ### Tests ###################################################################### | ||||
################################################################################ | ################################################################################ | ||||
################################################################################ | ################################################################################ | ||||
test_title "Test: Duplicate default hook" | test_title "Test: Duplicate default hook" | ||||
ngctl connect MF: O2M: default many99 2>/dev/null | test_failure "duplicate connect of default hook" ngctl connect MF: O2M: default many99 | ||||
test_failure "duplicate connect of default hook" | |||||
################################################################################ | ################################################################################ | ||||
test_title "Test: Add and remove hooks" | test_title "Test: Add and remove hooks" | ||||
ngctl connect MF: O2M: xxx1 many$((HOOKS + 1)) | test_success "connect MF:xxx1 to O2M:many$((HOOKS + 1))" ngctl connect MF: O2M: xxx1 many$((HOOKS + 1)) | ||||
test_success "connect MF:xxx1 to O2M:many$((HOOKS + 1))" | test_success "connect MF:xxx2 to O2M:many$((HOOKS + 2))" ngctl connect MF: O2M: xxx2 many$((HOOKS + 2)) | ||||
ngctl connect MF: O2M: xxx2 many$((HOOKS + 2)) | test_success "connect MF:xxx3 to O2M:many$((HOOKS + 3))" ngctl connect MF: O2M: xxx3 many$((HOOKS + 3)) | ||||
test_success "connect MF:xxx2 to O2M:many$((HOOKS + 2))" | |||||
ngctl connect MF: O2M: xxx3 many$((HOOKS + 3)) | |||||
test_success "connect MF:xxx3 to O2M:many$((HOOKS + 3))" | |||||
hooks=$(gethooks) | hooks=$(gethooks) | ||||
test_eq $created_hooks:xxx1:xxx2:xxx3 $hooks 'hooks after adding xxx1-3' | test_eq $created_hooks:xxx1:xxx2:xxx3 $hooks 'hooks after adding xxx1-3' | ||||
ngctl rmhook MF: xxx1 | test_success "rmhook MF:xxx$i" ngctl rmhook MF: xxx1 | ||||
test_success "rmhook MF:xxx$i" | |||||
hooks=$(gethooks) | hooks=$(gethooks) | ||||
test_eq $created_hooks:xxx2:xxx3 $hooks 'hooks after removing xxx1' | test_eq $created_hooks:xxx2:xxx3 $hooks 'hooks after removing xxx1' | ||||
ngctl rmhook MF: xxx2 | test_success "rmhook MF:xxx$i" ngctl rmhook MF: xxx2 | ||||
test_success "rmhook MF:xxx$i" | |||||
hooks=$(gethooks) | hooks=$(gethooks) | ||||
test_eq $created_hooks:xxx3 $hooks 'hooks after removing xxx2' | test_eq $created_hooks:xxx3 $hooks 'hooks after removing xxx2' | ||||
ngctl rmhook MF: xxx3 | test_success "rmhook MF:xxx$i" ngctl rmhook MF: xxx3 | ||||
test_success "rmhook MF:xxx$i" | |||||
hooks=$(gethooks) | hooks=$(gethooks) | ||||
test_eq $created_hooks $hooks 'hooks after removing xxx3' | test_eq $created_hooks $hooks 'hooks after removing xxx3' | ||||
test_bail_on_fail | test_bail_on_fail | ||||
################################################################################ | ################################################################################ | ||||
test_title "Test: Add many hooks" | test_title "Test: Add many hooks" | ||||
added_hooks="" | added_hooks="" | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | for i in $(seq $ITERATIONS); do | ||||
test_bail_on_fail | test_bail_on_fail | ||||
mv $entries2_lst $entries_lst | mv $entries2_lst $entries_lst | ||||
done | done | ||||
################################################################################ | ################################################################################ | ||||
test_title "Test: Resetting macfilter..." | test_title "Test: Resetting macfilter..." | ||||
ngctl msg MF: reset | test_success "**** reset failed" ngctl msg MF: reset | ||||
test_success "**** reset failed" | |||||
test_eq $(countmacs) 0 'MACs in table' | test_eq $(countmacs) 0 'MACs in table' | ||||
test_bail_on_fail | test_bail_on_fail | ||||
################################################################################ | ################################################################################ | ||||
exit 0 | exit 0 |