tests/sys/netgraph/ng_macfilter_test: Fix invalid TAP output

This should allow the test to pass in Jenkins. Testing it locally now
reports "passed" instead of "invalid TAP data".

While touching this file also fix some shellcheck warnings that were
pointed out by my IDE.

Reviewed By:	lwhsu, afedorov
Differential Revision: https://reviews.freebsd.org/D29054
This commit is contained in:
Alex Richardson 2021-03-12 17:35:24 +00:00
parent fe525d3f91
commit 65f4ff4e68

View File

@ -45,7 +45,7 @@ find_iface () {
loaded_modules=''
load_modules () {
for kmod in $*; do
for kmod in "$@"; do
if ! kldstat -q -m $kmod; then
test_comment "Loading $kmod..."
kldload $kmod
@ -96,16 +96,16 @@ TSTNR=0
TSTFAILS=0
TSTSUCCS=0
_test_next () { TSTNR=$(($TSTNR + 1)); }
_test_succ () { TSTSUCCS=$(($TSTSUCCS + 1)); }
_test_fail () { TSTFAILS=$(($TSTFAILS + 1)); }
_test_next () { TSTNR=$((TSTNR + 1)); }
_test_succ () { TSTSUCCS=$((TSTSUCCS + 1)); }
_test_fail () { TSTFAILS=$((TSTFAILS + 1)); }
test_cnt () { echo "1..${1:-$TSTNR}"; }
test_title () {
local msg="$1"
printf '### %s ' "$msg"
printf '#%.0s' `seq $((80 - ${#msg} - 5))`
printf '#%.0s' $(seq $((80 - ${#msg} - 5)))
printf "\n"
}
test_comment () { echo "# $1"; }
@ -229,7 +229,8 @@ trap 'cleanup' EXIT
created_hooks=$(gethooks)
rc=0
test_cnt
# Update this number when adding new tests
test_cnt 46
################################################################################
@ -244,12 +245,12 @@ test_failure "duplicate connect of default hook"
################################################################################
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: xxx2 many$(($HOOKS + 2))
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))"
ngctl connect MF: O2M: xxx1 many$((HOOKS + 1))
test_success "connect MF:xxx1 to O2M:many$((HOOKS + 1))"
ngctl connect MF: O2M: xxx2 many$((HOOKS + 2))
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)
test_eq $created_hooks:xxx1:xxx2:xxx3 $hooks 'hooks after adding xxx1-3'
@ -273,7 +274,7 @@ test_title "Test: Add many hooks"
added_hooks=""
for i in $(seq 10 1 $HOOKSADD); do
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
hooks=$(gethooks)
test_eq $created_hooks$added_hooks $hooks 'hooks after adding many hooks'
@ -291,21 +292,21 @@ test_bail_on_fail
test_title "Test: Adding many MACs..."
I=1
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
test $i = 2 && edge='out2' || edge='out1'
ether=$(genmac $j $i)
ngctl msg MF: 'direct' "{ hookname=\"$edge\" ether=$ether }"
done
I=$(($I + 1))
I=$((I + 1))
done
n=$(countmacs out1)
n2=$(( ( $ITERATIONS - 1 ) * ( $SUBITERATIONS + 1 ) ))
n2=$(( ( ITERATIONS - 1 ) * ( SUBITERATIONS + 1 ) ))
test_eq $n $n2 'MACs in table for out1'
n=$(countmacs out2)
n2=$(( 1 * ( $SUBITERATIONS + 1 ) ))
n2=$(( 1 * ( SUBITERATIONS + 1 ) ))
test_eq $n $n2 'MACs in table for out2'
n=$(countmacs out3)
n2=0
@ -324,10 +325,10 @@ for i in $(seq $ITERATIONS); do
done
n=$(countmacs out1)
n2=$(( ( $ITERATIONS - 1 ) * ( $SUBITERATIONS + 1 - 1 ) ))
n2=$(( ( ITERATIONS - 1 ) * ( SUBITERATIONS + 1 - 1 ) ))
test_eq $n $n2 'MACs in table for out1'
n=$(countmacs out2)
n2=$(( 1 * ( $SUBITERATIONS + 1 - 1 ) ))
n2=$(( 1 * ( SUBITERATIONS + 1 - 1 ) ))
test_eq $n $n2 'MACs in table for out2'
n=$(countmacs out3)
n2=$ITERATIONS
@ -340,7 +341,7 @@ test_bail_on_fail
test_title "Test: Removing all MACs one by one..."
I=1
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
edge="default"
ether=$(genmac $j $i)
@ -360,7 +361,7 @@ test_bail_on_fail
test_title "Test: Randomly adding MACs on random hooks..."
rm -f $entries_lst
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
edge=$(randomedge)
ether=$(genmac $j $i)
@ -390,7 +391,7 @@ test_bail_on_fail
test_title "Test: Randomly changing MAC assignments..."
rm -f $entries2_lst
for i in $(seq $ITERATIONS); do
test_comment "Iteration $i/$iterations..."
test_comment "Iteration $i/$ITERATIONS..."
cat $entries_lst | while read ether edge; do
edge2=$(randomedge)
@ -425,6 +426,5 @@ test_bail_on_fail
################################################################################
test_cnt
exit 0