git: 7dd1f932c1f5 - main - tests/sys/netgraph: Further CI fixes

Alex Richardson arichardson at FreeBSD.org
Fri Mar 19 18:39:49 UTC 2021


The branch main has been updated by arichardson:

URL: https://cgit.FreeBSD.org/src/commit/?id=7dd1f932c1f51bfe10da7bc8875879cdcdd40821

commit 7dd1f932c1f51bfe10da7bc8875879cdcdd40821
Author:     Alex Richardson <arichardson at FreeBSD.org>
AuthorDate: 2021-03-19 18:34:29 +0000
Commit:     Alex Richardson <arichardson at FreeBSD.org>
CommitDate: 2021-03-19 18:34:30 +0000

    tests/sys/netgraph: Further CI fixes
    
    I was trying to debug why this test is working locally but failing in CI.
    While doing so I made some small changes to allow running it with set -e.
    
    It turns out the problem is that find_iface does not return anything in
    Jenkins, so all following tests fail with obscure error messages.
    To handle this case exit early if $eth is empty.
    
    Reviewed By:    lwhsu
    Differential Revision: https://reviews.freebsd.org/D29340
---
 tests/sys/netgraph/ng_macfilter_test.sh | 57 +++++++++++++++++++++------------
 1 file changed, 36 insertions(+), 21 deletions(-)

diff --git a/tests/sys/netgraph/ng_macfilter_test.sh b/tests/sys/netgraph/ng_macfilter_test.sh
index 269de3e130aa..482f32e5d335 100755
--- a/tests/sys/netgraph/ng_macfilter_test.sh
+++ b/tests/sys/netgraph/ng_macfilter_test.sh
@@ -29,6 +29,8 @@
 #
 # $FreeBSD$
 
+set -e
+
 progname="$(basename $0 .sh)"
 entries_lst="/tmp/$progname.entries.lst"
 entries2_lst="/tmp/$progname.entries2.lst"
@@ -124,7 +126,7 @@ test_not_ok () {
 	local msg="$1"
 
 	_test_next
-	_test_fails
+	_test_fail
 	echo "not ok $TSTNR - $msg"
 
 	return 1
@@ -183,9 +185,24 @@ test_ge () {
 		test_not_ok "$v1 <= $v2 $msg"
 	fi
 }
-test_rc ()      { test_eq $? $1 "$2"; }
-test_failure () { test_ne $? 0 "$1"; }
-test_success () { test_eq $? 0 "$1"; }
+test_failure () {
+	msg=$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 () {
 	ngctl msg MF: 'gethooks' \
@@ -217,6 +234,13 @@ genmac () {
 test_title "Setting up system..."
 load_modules netgraph ng_socket ng_ether ng_macfilter ng_one2many
 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..."
 
 
@@ -239,31 +263,23 @@ test_cnt 46
 
 ################################################################################
 test_title "Test: Duplicate default hook"
-ngctl connect MF: O2M: default many99 2>/dev/null
-test_failure "duplicate connect of default hook"
-
+test_failure "duplicate connect of default hook" ngctl connect MF: O2M: default many99
 
 ################################################################################
 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))"
+test_success "connect MF:xxx1 to O2M:many$((HOOKS + 1))" ngctl connect MF: O2M: xxx1 many$((HOOKS + 1))
+test_success "connect MF:xxx2 to O2M: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))
 hooks=$(gethooks)
 test_eq $created_hooks:xxx1:xxx2:xxx3 $hooks 'hooks after adding xxx1-3'
 
-ngctl rmhook MF: xxx1
-test_success "rmhook MF:xxx$i"
+test_success "rmhook MF:xxx$i" ngctl rmhook MF: xxx1
 hooks=$(gethooks)
 test_eq $created_hooks:xxx2:xxx3 $hooks 'hooks after removing xxx1'
-ngctl rmhook MF: xxx2
-test_success "rmhook MF:xxx$i"
+test_success "rmhook MF:xxx$i" ngctl rmhook MF: xxx2
 hooks=$(gethooks)
 test_eq $created_hooks:xxx3 $hooks 'hooks after removing xxx2'
-ngctl rmhook MF: xxx3
-test_success "rmhook MF:xxx$i"
+test_success "rmhook MF:xxx$i" ngctl rmhook MF: xxx3
 hooks=$(gethooks)
 test_eq $created_hooks $hooks 'hooks after removing xxx3'
 
@@ -418,8 +434,7 @@ done
 
 ################################################################################
 test_title "Test: Resetting macfilter..."
-ngctl msg MF: reset
-test_success "**** reset failed"
+test_success "**** reset failed" ngctl msg MF: reset
 test_eq $(countmacs) 0 'MACs in table'
 
 test_bail_on_fail


More information about the dev-commits-src-all mailing list