Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/netgraph/ng_macfilter_test.sh
Show All 39 Lines | |||||
find_iface () { | find_iface () { | ||||
# Figure out the first ethernet interface | # Figure out the first ethernet interface | ||||
ifconfig -u -l ether | awk '{print $1}' | ifconfig -u -l ether | awk '{print $1}' | ||||
} | } | ||||
loaded_modules='' | loaded_modules='' | ||||
load_modules () { | load_modules () { | ||||
for kmod in $*; do | for kmod in "$@"; do | ||||
if ! kldstat -q -m $kmod; then | if ! kldstat -q -m $kmod; then | ||||
test_comment "Loading $kmod..." | test_comment "Loading $kmod..." | ||||
kldload $kmod | kldload $kmod | ||||
loaded_modules="$loaded_modules $kmod" | loaded_modules="$loaded_modules $kmod" | ||||
fi | fi | ||||
done | done | ||||
} | } | ||||
unload_modules () { | unload_modules () { | ||||
Show All 34 Lines | cleanup () { | ||||
rm -f $entries_lst $entries2_lst | rm -f $entries_lst $entries2_lst | ||||
} | } | ||||
TSTNR=0 | TSTNR=0 | ||||
TSTFAILS=0 | TSTFAILS=0 | ||||
TSTSUCCS=0 | TSTSUCCS=0 | ||||
_test_next () { TSTNR=$(($TSTNR + 1)); } | _test_next () { TSTNR=$((TSTNR + 1)); } | ||||
_test_succ () { TSTSUCCS=$(($TSTSUCCS + 1)); } | _test_succ () { TSTSUCCS=$((TSTSUCCS + 1)); } | ||||
_test_fail () { TSTFAILS=$(($TSTFAILS + 1)); } | _test_fail () { TSTFAILS=$((TSTFAILS + 1)); } | ||||
test_cnt () { echo "1..${1:-$TSTNR}"; } | test_cnt () { echo "1..${1:-$TSTNR}"; } | ||||
test_title () { | test_title () { | ||||
local msg="$1" | local msg="$1" | ||||
printf '### %s ' "$msg" | printf '### %s ' "$msg" | ||||
printf '#%.0s' `seq $((80 - ${#msg} - 5))` | printf '#%.0s' $(seq $((80 - ${#msg} - 5))) | ||||
printf "\n" | printf "\n" | ||||
} | } | ||||
test_comment () { echo "# $1"; } | test_comment () { echo "# $1"; } | ||||
test_bailout () { echo "Bail out!${1+:- $1}"; exit 1; } | test_bailout () { echo "Bail out!${1+:- $1}"; exit 1; } | ||||
test_bail_on_fail () { test $TSTFAILS -eq 0 || test_bailout $1; } | test_bail_on_fail () { test $TSTFAILS -eq 0 || test_bailout $1; } | ||||
test_ok () { | test_ok () { | ||||
local msg="$1" | local msg="$1" | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | |||||
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 | ||||
test_cnt | # Update this number when adding new tests | ||||
test_cnt 46 | |||||
lwhsu: I feel this is easy to be forgot, but also not easy to change. The better approach might be… | |||||
################################################################################ | ################################################################################ | ||||
### Tests ###################################################################### | ### Tests ###################################################################### | ||||
################################################################################ | ################################################################################ | ||||
################################################################################ | ################################################################################ | ||||
test_title "Test: Duplicate default hook" | test_title "Test: Duplicate default hook" | ||||
ngctl connect MF: O2M: default many99 2>/dev/null | ngctl connect MF: O2M: default many99 2>/dev/null | ||||
test_failure "duplicate connect of default hook" | 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)) | ngctl connect MF: O2M: xxx1 many$((HOOKS + 1)) | ||||
test_success "connect MF:xxx1 to O2M:many$(($HOOKS + 1))" | test_success "connect MF:xxx1 to O2M:many$((HOOKS + 1))" | ||||
ngctl connect MF: O2M: xxx2 many$(($HOOKS + 2)) | ngctl connect MF: O2M: xxx2 many$((HOOKS + 2)) | ||||
test_success "connect MF:xxx2 to O2M:many$(($HOOKS + 2))" | test_success "connect MF:xxx2 to O2M:many$((HOOKS + 2))" | ||||
ngctl connect MF: O2M: xxx3 many$(($HOOKS + 3)) | ngctl connect MF: O2M: xxx3 many$((HOOKS + 3)) | ||||
test_success "connect MF:xxx3 to O2M: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 | ngctl rmhook MF: xxx1 | ||||
test_success "rmhook MF:xxx$i" | 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 | ngctl rmhook MF: xxx2 | ||||
test_success "rmhook MF:xxx$i" | 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 | ngctl rmhook MF: xxx3 | ||||
test_success "rmhook MF:xxx$i" | 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="" | ||||
for i in $(seq 10 1 $HOOKSADD); do | for i in $(seq 10 1 $HOOKSADD); do | ||||
added_hooks="$added_hooks:xxx$i" | added_hooks="$added_hooks:xxx$i" | ||||
ngctl connect MF: O2M: xxx$i many$(($HOOKS + $i)) | ngctl connect MF: O2M: xxx$i many$((HOOKS + i)) | ||||
done | done | ||||
hooks=$(gethooks) | hooks=$(gethooks) | ||||
test_eq $created_hooks$added_hooks $hooks 'hooks after adding many hooks' | test_eq $created_hooks$added_hooks $hooks 'hooks after adding many hooks' | ||||
for h in $(echo $added_hooks | perl -ne 'chomp; %h=map { $_=>1 } split /:/; print "$_\n" for grep {$_} keys %h'); do | for h in $(echo $added_hooks | perl -ne 'chomp; %h=map { $_=>1 } split /:/; print "$_\n" for grep {$_} keys %h'); do | ||||
ngctl rmhook MF: $h | ngctl rmhook MF: $h | ||||
done | done | ||||
hooks=$(gethooks) | hooks=$(gethooks) | ||||
test_eq $created_hooks $hooks 'hooks after adding many hooks' | test_eq $created_hooks $hooks 'hooks after adding many hooks' | ||||
test_bail_on_fail | test_bail_on_fail | ||||
################################################################################ | ################################################################################ | ||||
test_title "Test: Adding many MACs..." | test_title "Test: Adding many MACs..." | ||||
I=1 | I=1 | ||||
for i in $(seq $ITERATIONS | sort -R); do | for i in $(seq $ITERATIONS | sort -R); do | ||||
test_comment "Iteration $I/$iterations..." | test_comment "Iteration $I/$ITERATIONS..." | ||||
for j in $(seq 0 1 $SUBITERATIONS); do | for j in $(seq 0 1 $SUBITERATIONS); do | ||||
test $i = 2 && edge='out2' || edge='out1' | test $i = 2 && edge='out2' || edge='out1' | ||||
ether=$(genmac $j $i) | ether=$(genmac $j $i) | ||||
ngctl msg MF: 'direct' "{ hookname=\"$edge\" ether=$ether }" | ngctl msg MF: 'direct' "{ hookname=\"$edge\" ether=$ether }" | ||||
done | done | ||||
I=$(($I + 1)) | I=$((I + 1)) | ||||
done | done | ||||
n=$(countmacs out1) | n=$(countmacs out1) | ||||
n2=$(( ( $ITERATIONS - 1 ) * ( $SUBITERATIONS + 1 ) )) | n2=$(( ( ITERATIONS - 1 ) * ( SUBITERATIONS + 1 ) )) | ||||
test_eq $n $n2 'MACs in table for out1' | test_eq $n $n2 'MACs in table for out1' | ||||
n=$(countmacs out2) | n=$(countmacs out2) | ||||
n2=$(( 1 * ( $SUBITERATIONS + 1 ) )) | n2=$(( 1 * ( SUBITERATIONS + 1 ) )) | ||||
test_eq $n $n2 'MACs in table for out2' | test_eq $n $n2 'MACs in table for out2' | ||||
n=$(countmacs out3) | n=$(countmacs out3) | ||||
n2=0 | n2=0 | ||||
test_eq $n $n2 'MACs in table for out3' | test_eq $n $n2 'MACs in table for out3' | ||||
test_bail_on_fail | test_bail_on_fail | ||||
################################################################################ | ################################################################################ | ||||
test_title "Test: Changing hooks for MACs..." | test_title "Test: Changing hooks for MACs..." | ||||
for i in $(seq $ITERATIONS); do | for i in $(seq $ITERATIONS); do | ||||
edge='out3' | edge='out3' | ||||
ether=$(genmac 0 $i) | ether=$(genmac 0 $i) | ||||
ngctl msg MF: 'direct' "{ hookname=\"$edge\" ether=$ether }" | ngctl msg MF: 'direct' "{ hookname=\"$edge\" ether=$ether }" | ||||
done | done | ||||
n=$(countmacs out1) | n=$(countmacs out1) | ||||
n2=$(( ( $ITERATIONS - 1 ) * ( $SUBITERATIONS + 1 - 1 ) )) | n2=$(( ( ITERATIONS - 1 ) * ( SUBITERATIONS + 1 - 1 ) )) | ||||
test_eq $n $n2 'MACs in table for out1' | test_eq $n $n2 'MACs in table for out1' | ||||
n=$(countmacs out2) | n=$(countmacs out2) | ||||
n2=$(( 1 * ( $SUBITERATIONS + 1 - 1 ) )) | n2=$(( 1 * ( SUBITERATIONS + 1 - 1 ) )) | ||||
test_eq $n $n2 'MACs in table for out2' | test_eq $n $n2 'MACs in table for out2' | ||||
n=$(countmacs out3) | n=$(countmacs out3) | ||||
n2=$ITERATIONS | n2=$ITERATIONS | ||||
test_eq $n $n2 'MACs in table for out3' | test_eq $n $n2 'MACs in table for out3' | ||||
test_bail_on_fail | test_bail_on_fail | ||||
################################################################################ | ################################################################################ | ||||
test_title "Test: Removing all MACs one by one..." | test_title "Test: Removing all MACs one by one..." | ||||
I=1 | I=1 | ||||
for i in $(seq $ITERATIONS | sort -R); do | for i in $(seq $ITERATIONS | sort -R); do | ||||
test_comment "Iteration $I/$iterations..." | test_comment "Iteration $I/$ITERATIONS..." | ||||
for j in $(seq 0 1 $SUBITERATIONS | sort -R); do | for j in $(seq 0 1 $SUBITERATIONS | sort -R); do | ||||
edge="default" | edge="default" | ||||
ether=$(genmac $j $i) | ether=$(genmac $j $i) | ||||
ngctl msg MF: 'direct' "{ hookname=\"$edge\" ether=$ether }" | ngctl msg MF: 'direct' "{ hookname=\"$edge\" ether=$ether }" | ||||
done | done | ||||
I=$(($I + 1)) | I=$(($I + 1)) | ||||
done | done | ||||
n=$(countmacs) | n=$(countmacs) | ||||
n2=0 | n2=0 | ||||
test_eq $n $n2 'MACs in table' | test_eq $n $n2 'MACs in table' | ||||
test_bail_on_fail | test_bail_on_fail | ||||
################################################################################ | ################################################################################ | ||||
test_title "Test: Randomly adding MACs on random hooks..." | test_title "Test: Randomly adding MACs on random hooks..." | ||||
rm -f $entries_lst | rm -f $entries_lst | ||||
for i in $(seq $ITERATIONS); do | for i in $(seq $ITERATIONS); do | ||||
test_comment "Iteration $i/$iterations..." | test_comment "Iteration $i/$ITERATIONS..." | ||||
for j in $(seq 0 1 $SUBITERATIONS | sort -R); do | for j in $(seq 0 1 $SUBITERATIONS | sort -R); do | ||||
edge=$(randomedge) | edge=$(randomedge) | ||||
ether=$(genmac $j $i) | ether=$(genmac $j $i) | ||||
ngctl msg MF: 'direct' "{ hookname=\"$edge\" ether=$ether }" | ngctl msg MF: 'direct' "{ hookname=\"$edge\" ether=$ether }" | ||||
echo $ether $edge >> $entries_lst | echo $ether $edge >> $entries_lst | ||||
done | done | ||||
Show All 13 Lines | |||||
test_bail_on_fail | test_bail_on_fail | ||||
################################################################################ | ################################################################################ | ||||
test_title "Test: Randomly changing MAC assignments..." | test_title "Test: Randomly changing MAC assignments..." | ||||
rm -f $entries2_lst | rm -f $entries2_lst | ||||
for i in $(seq $ITERATIONS); do | for i in $(seq $ITERATIONS); do | ||||
test_comment "Iteration $i/$iterations..." | test_comment "Iteration $i/$ITERATIONS..." | ||||
cat $entries_lst | while read ether edge; do | cat $entries_lst | while read ether edge; do | ||||
edge2=$(randomedge) | edge2=$(randomedge) | ||||
ngctl msg MF: 'direct' "{ hookname=\"$edge2\" ether=$ether }" | ngctl msg MF: 'direct' "{ hookname=\"$edge2\" ether=$ether }" | ||||
echo $ether $edge2 >> $entries2_lst | echo $ether $edge2 >> $entries2_lst | ||||
done | done | ||||
Show All 18 Lines | |||||
ngctl msg MF: reset | ngctl msg MF: reset | ||||
test_success "**** reset failed" | 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 | ||||
################################################################################ | ################################################################################ | ||||
test_cnt | |||||
exit 0 | exit 0 |
I feel this is easy to be forgot, but also not easy to change. The better approach might be migrating the test cases to use atf-sh.