selftests: net: move log_test to lib file and remove duplicate code
Subsystems (5)
PATCH v2 1/1 selftests: net: move log_test to lib file and remove duplicate code
From: Hangbin Liu <[email protected]>
Many test scripts under tools/testing/selftests/net/ each define their own log_test() function with near-identical logic for comparing a return code against an expected value and printing OK/FAIL. Add a shared log_test_expected() to lib.sh and replace each local definition with a thin wrapper that delegates to it.
The function is named log_test_expected() rather than log_test() because lib.sh already exports log_test() with a different signature used by the forwarding tests.
Two tests required special handling:
- icmp_redirect.sh passed a fourth "xfail" argument to log_test(). The underlying issue has been fixed and the argument is always absent now, so it is simply dropped.
- fib_nexthops.sh checked for ksft_skip (exit code 4) inside log_test(), but no test in the file produces that code. The check is removed, callers that need to report a skip should use log_test_skip() instead. Two callers compared against exit code 2 are left as-is since code 2 correctly counts as a failure in the previous log_test().
---
Changes in v2:
- Remove skip/xfail checking in lib.sh, as any command can exits with 2 or 4 (sashiko)
- Remove nskip counter in fib_nexthops.sh
- Link to v1: https://lore.kernel.org/r/[email protected]
--- tools/testing/selftests/net/drop_monitor_tests.sh | 13 +------ tools/testing/selftests/net/fcnal-test.sh | 29 +------------- tools/testing/selftests/net/fdb_flush.sh | 35 +---------------- tools/testing/selftests/net/fib-onlink-tests.sh | 18 +-------- .../selftests/net/fib_nexthop_multiprefix.sh | 21 +---------- tools/testing/selftests/net/fib_nexthop_nongw.sh | 21 +---------- tools/testing/selftests/net/fib_nexthops.sh | 44 ++-------------------- tools/testing/selftests/net/fib_rule_tests.sh | 19 +--------- tools/testing/selftests/net/fib_tests.sh | 26 +------------ tools/testing/selftests/net/gre_gso.sh | 26 +------------ tools/testing/selftests/net/icmp_redirect.sh | 28 ++------------ tools/testing/selftests/net/l2tp.sh | 19 +--------- tools/testing/selftests/net/lib.sh | 31 +++++++++++++++ .../selftests/net/ndisc_unsolicited_na_test.sh | 26 +------------ .../selftests/net/srv6_encap_lookup_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dt46_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dt4_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dt6_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dx4_netfilter_test.sh | 23 ++--------- .../selftests/net/srv6_end_dx6_netfilter_test.sh | 23 ++--------- .../testing/selftests/net/srv6_end_flavors_test.sh | 23 ++--------- .../selftests/net/srv6_end_next_csid_l3vpn_test.sh | 19 +--------- .../net/srv6_end_x_next_csid_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_hencap_red_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_hl2encap_red_l2vpn_test.sh | 19 +--------- .../selftests/net/test_bridge_backup_port.sh | 32 +--------------- .../selftests/net/test_bridge_neigh_suppress.sh | 33 +--------------- tools/testing/selftests/net/test_vxlan_mdb.sh | 32 +--------------- .../selftests/net/test_vxlan_nolocalbypass.sh | 32 +--------------- .../selftests/net/test_vxlan_vnifiltering.sh | 26 +------------ tools/testing/selftests/net/vrf-xfrm-tests.sh | 19 +--------- tools/testing/selftests/net/vrf_route_leaking.sh | 19 +--------- .../testing/selftests/net/vrf_strict_mode_test.sh | 19 +--------- 33 files changed, 73 insertions(+), 716 deletions(-)
tools/testing/selftests/net/drop_monitor_tests.sh +1 -12
@@ -18,18 +18,7 @@ DEVLINK_DEV=netdevsim/${DEV} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf " TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - fi + log_test_expected "$1" "$2" "$3" } setup()
tools/testing/selftests/net/fcnal-test.sh +1 -28
@@ -97,34 +97,7 @@ fi log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - local ans - - [ "${VERBOSE}" = "1" ] && echo - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "TEST: %-70s [ OK ]\n" "${msg}" - else - nfail=$((nfail+1)) - printf "TEST: %-70s [FAIL]\n" "${msg}" - echo " expected rc $expected; actual rc $rc" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read ans - [ "$ans" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read ans - [ "$ans" = "q" ] && exit 1 - fi + log_test_expected "$1" "$2" "$3" kill_procs }
tools/testing/selftests/net/fdb_flush.sh +1 -34
@@ -67,40 +67,7 @@ run_cmd() log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - local nsuccess - local nfail - local ret - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "$VERBOSE" = "1" ]; then - echo " rc=$rc, expected $expected" - fi - - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } MAC_POOL_1="
tools/testing/selftests/net/fib-onlink-tests.sh +1 -17
@@ -85,23 +85,7 @@ PBR_TABLE=101 log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf " TEST: %-50s [ OK ]\n" "${msg}" - else - nfail=$((nfail+1)) - printf " TEST: %-50s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } log_section()
tools/testing/selftests/net/fib_nexthop_multiprefix.sh +1 -20
@@ -23,26 +23,7 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } run_cmd()
tools/testing/selftests/net/fib_nexthop_nongw.sh +1 -20
@@ -18,26 +18,7 @@ ret=0 log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } run_cmd()
tools/testing/selftests/net/fib_nexthops.sh +3 -41
68 lines not on this page · raw message
tools/testing/selftests/net/fib_rule_tests.sh +1 -18
@@ -31,24 +31,7 @@ SELFTEST_PATH="" log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf " TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } setup()
tools/testing/selftests/net/fib_tests.sh +1 -25
@@ -24,31 +24,7 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf " TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi + log_test_expected "$1" "$2" "$3" } setup()
tools/testing/selftests/net/gre_gso.sh +1 -25
@@ -16,31 +16,7 @@ PID= log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf " TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi + log_test_expected "$1" "$2" "$3" } setup()
tools/testing/selftests/net/icmp_redirect.sh +3 -25
@@ -61,28 +61,7 @@ log_section() log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - local xfail=$4 - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - elif [ ${rc} -eq ${xfail} ]; then - printf "TEST: %-60s [XFAIL]\n" "${msg}" - nxfail=$((nxfail+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } log_debug()
@@ -303,7 +282,7 @@ check_exception() ip -netns $h1 ro get ${H1_VRF_ARG} ${H2_N2_IP} | \ grep -E -v 'mtu|redirected' | grep -q "cache" fi - log_test $? 0 "IPv4: ${desc}" 0 + log_test $? 0 "IPv4: ${desc}" # No PMTU info for test "redirect" and "mtu exception plus redirect" if [ "$with_redirect" = "yes" ] && [ "$desc" != "redirect exception plus mtu" ]; then
@@ -319,7 +298,7 @@ check_exception() ip -netns $h1 -6 ro get ${H1_VRF_ARG} ${H2_N2_IP6} | \ grep -v "mtu" | grep -q "${R1_LLADDR}" fi - log_test $? 0 "IPv6: ${desc}" 1 + log_test $? 0 "IPv6: ${desc}" } run_ping()
@@ -530,6 +509,5 @@ fi printf "\nTests passed: %3d\n" ${nsuccess} printf "Tests failed: %3d\n" ${nfail} -printf "Tests xfailed: %3d\n" ${nxfail} exit $ret
tools/testing/selftests/net/l2tp.sh +1 -18
@@ -23,24 +23,7 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) # log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } run_cmd()
tools/testing/selftests/net/lib.sh +31 -0
@@ -454,6 +454,37 @@ log_test_xfail() RET=$ksft_xfail retmsg= log_test "$@" } +# Log test result with expected return value +log_test_expected() +{ + local rc=$1 + local expected=$2 + local msg="$3" + + if [ "${rc}" -eq "${expected}" ]; then + nsuccess=$((nsuccess+1)) + printf "TEST: %-60s [ OK ]\n" "${msg}" + else + ret=$(ksft_exit_status_merge "$ret" "$ksft_fail") + nfail=$((nfail+1)) + printf "TEST: %-60s [FAIL]\n" "${msg}" + if [ "$VERBOSE" = "1" ]; then + echo " rc=$rc, expected $expected" + fi + + pause_on_fail + fi + + if [ "${PAUSE}" = "yes" ]; then + echo + echo "hit enter to continue, 'q' to quit" + read -r a + [ "$a" = "q" ] && exit 1 + fi + + [ "$VERBOSE" = "1" ] && echo +} + log_info() { local msg=$1
tools/testing/selftests/net/ndisc_unsolicited_na_test.sh +1 -25
@@ -30,31 +30,7 @@ tcpdump_stderr= log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf " TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi + log_test_expected "$1" "$2" "$3" } setup()
tools/testing/selftests/net/srv6_encap_lookup_l3vpn_test.sh +1 -18
@@ -202,24 +202,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read -r a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/srv6_end_dt46_l3vpn_test.sh +1 -18
@@ -208,24 +208,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/srv6_end_dt4_l3vpn_test.sh +1 -18
@@ -177,24 +177,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh +1 -18
@@ -178,24 +178,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh +3 -20
@@ -111,8 +111,8 @@ # +---------------------------------------------------+ # -# Kselftest framework requirement - SKIP code is 4. -ksft_skip=4 +# shellcheck source=lib.sh +source lib.sh readonly IPv6_RT_NETWORK=2001:11 readonly IPv4_HS_NETWORK=10.0.0
@@ -126,24 +126,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/srv6_end_dx6_netfilter_test.sh +3 -20
@@ -111,8 +111,8 @@ # +---------------------------------------------------+ # -# Kselftest framework requirement - SKIP code is 4. -ksft_skip=4 +# shellcheck source=lib.sh +source lib.sh readonly IPv6_RT_NETWORK=2001:11 readonly IPv6_HS_NETWORK=cafe
@@ -126,24 +126,7 @@ PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/srv6_end_flavors_test.sh +3 -20
@@ -194,8 +194,8 @@ # after the IPv6 header. At this point, the packet with IPv6 DA=cafe::1 is sent # to the destination, i.e. hs-1. -# Kselftest framework requirement - SKIP code is 4. -readonly ksft_skip=4 +# shellcheck source=lib.sh +source lib.sh readonly RDMSUFF="$(mktemp -u XXXXXXXX)" readonly DUMMY_DEVNAME="dum0"
@@ -224,24 +224,7 @@ nfail=0 log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/srv6_end_next_csid_l3vpn_test.sh +1 -18
@@ -323,24 +323,7 @@ nfail=0 log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/srv6_end_x_next_csid_l3vpn_test.sh +1 -18
@@ -368,24 +368,7 @@ nfail=0 log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/srv6_hencap_red_l3vpn_test.sh +1 -18
@@ -197,24 +197,7 @@ HAS_TUNSRC=false log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/srv6_hl2encap_red_l2vpn_test.sh +1 -18
@@ -146,24 +146,7 @@ nfail=0 log_test() { - local rc="$1" - local expected="$2" - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
tools/testing/selftests/net/test_bridge_backup_port.sh +1 -31
@@ -56,37 +56,7 @@ PING_TIMEOUT=5 log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "$VERBOSE" = "1" ]; then - echo " rc=$rc, expected $expected" - fi - - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } run_cmd()
tools/testing/selftests/net/test_bridge_neigh_suppress.sh +1 -32
@@ -72,38 +72,7 @@ PAUSE=no log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - # shellcheck disable=SC2154 - ret=$(ksft_exit_status_merge "$ret" "$ksft_fail") - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "$VERBOSE" = "1" ]; then - echo " rc=$rc, expected $expected" - fi - - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" return 0 }
tools/testing/selftests/net/test_vxlan_mdb.sh +1 -31
@@ -133,37 +133,7 @@ PAUSE=no log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "$VERBOSE" = "1" ]; then - echo " rc=$rc, expected $expected" - fi - - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } run_cmd()
tools/testing/selftests/net/test_vxlan_nolocalbypass.sh +1 -31
@@ -24,37 +24,7 @@ PAUSE=no log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "$VERBOSE" = "1" ]; then - echo " rc=$rc, expected $expected" - fi - - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - - [ "$VERBOSE" = "1" ] && echo + log_test_expected "$1" "$2" "$3" } run_cmd()
tools/testing/selftests/net/test_vxlan_vnifiltering.sh +1 -25
@@ -98,31 +98,7 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf " TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf " TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi - - if [ "${PAUSE}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi + log_test_expected "$1" "$2" "$3" } run_cmd()
tools/testing/selftests/net/vrf-xfrm-tests.sh +1 -18
@@ -35,24 +35,7 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) # log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } run_cmd_host1()
tools/testing/selftests/net/vrf_route_leaking.sh +1 -18
@@ -99,24 +99,7 @@ log_section() log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ "${rc}" -eq "${expected}" ]; then - printf "TEST: %-60s [ OK ]\n" "${msg}" - nsuccess=$((nsuccess+1)) - else - ret=1 - nfail=$((nfail+1)) - printf "TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read -r a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } run_cmd()
tools/testing/selftests/net/vrf_strict_mode_test.sh +1 -18
@@ -16,24 +16,7 @@ TESTS="init testns mix" log_test() { - local rc=$1 - local expected=$2 - local msg="$3" - - if [ ${rc} -eq ${expected} ]; then - nsuccess=$((nsuccess+1)) - printf "\n TEST: %-60s [ OK ]\n" "${msg}" - else - ret=1 - nfail=$((nfail+1)) - printf "\n TEST: %-60s [FAIL]\n" "${msg}" - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then - echo - echo "hit enter to continue, 'q' to quit" - read a - [ "$a" = "q" ] && exit 1 - fi - fi + log_test_expected "$1" "$2" "$3" } print_log_test_results()
---
base-commit: 1bb784eb6e38fd73143f021608e4ef3095d0c0d7
change-id: 20260812-self_log_test-b76eaf73e23f
Best regards,
Signature · 1 line
Hangbin Liu <[email protected]>
Jakub Kicinski
maintainerQuoted 16 lines · On Mon, 31 Aug 2026 17:21:28 +0800 Hangbin Liu wrote:
Many test scripts under
tools/testing/selftests/net/each define their ownlog_test()function with near-identical logic for comparing a return code against an expected value and printing OK/FAIL. Add a sharedlog_test_expected()tolib.shand replace each local definition with a thin wrapper that delegates to it.The function is named
log_test_expected()rather thanlog_test()becauselib.shalready exportslog_test()with a different signature used by the forwarding tests.Two tests required special handling:
-
icmp_redirect.shpassed a fourth "xfail" argument tolog_test(). The underlying issue has been fixed and the argument is always absent now, so it is simply dropped.
Quoted 5 lines
-
fib_nexthops.shchecked forksft_skip(exit code 4) insidelog_test(), but no test in the file produces that code. The check is removed, callers that need to report a skip should uselog_test_skip()instead. Two callers compared against exit code 2 are left as-is since code 2 correctly counts as a failure in the previouslog_test().
still breaks fib_tests.sh
Quoted 17 lines · Jakub Kicinski
Quoted 16 lines · On Mon, 31 Aug 2026 17:21:28 +0800 Hangbin Liu wrote:
Many test scripts under
tools/testing/selftests/net/each define their ownlog_test()function with near-identical logic for comparing a return code against an expected value and printing OK/FAIL. Add a sharedlog_test_expected()tolib.shand replace each local definition with a thin wrapper that delegates to it.The function is named
log_test_expected()rather thanlog_test()becauselib.shalready exportslog_test()with a different signature used by the forwarding tests.Two tests required special handling:
-
icmp_redirect.shpassed a fourth "xfail" argument tolog_test(). The underlying issue has been fixed and the argument is always absent now, so it is simply dropped.
Quoted 7 lines
Quoted 5 lines
-
fib_nexthops.shchecked forksft_skip(exit code 4) insidelog_test(), but no test in the file produces that code. The check is removed, callers that need to report a skip should uselog_test_skip()instead. Two callers compared against exit code 2 are left as-is since code 2 correctly counts as a failure in the previouslog_test().still breaks
fib_tests.sh
Oh... This patch touches too much tests. I only fixed the [ "$VERBOSE" = "1" ] checking and return 1 issue in test_bridge_neigh_suppress.sh. I didn't notice one of fib_test.sh "set -e" and also breaks here.
I think there is no test would expect return 1 for log_test. So I will fix it by return 0 in the lib function directly.
Thanks
Hangbin
Quoted 57 lines · Hangbin Liu
From: Hangbin Liu <[email protected]>
Many test scripts under
tools/testing/selftests/net/each define their ownlog_test()function with near-identical logic for comparing a return code against an expected value and printing OK/FAIL. Add a sharedlog_test_expected()tolib.shand replace each local definition with a thin wrapper that delegates to it.The function is named
log_test_expected()rather thanlog_test()becauselib.shalready exportslog_test()with a different signature used by the forwarding tests.Two tests required special handling:
-
icmp_redirect.shpassed a fourth "xfail" argument tolog_test(). The underlying issue has been fixed and the argument is always absent now, so it is simply dropped.-
fib_nexthops.shchecked forksft_skip(exit code 4) insidelog_test(), but no test in the file produces that code. The check is removed, callers that need to report a skip should uselog_test_skip()instead. Two callers compared against exit code 2 are left as-is since code 2 correctly counts as a failure in the previouslog_test().Signed-off-by Hangbin Liu <[email protected]>---
Changes in v2:
- Remove skip/xfail checking inlib.sh, as any command can exits with 2 or 4 (sashiko)
- Remove nskip counter infib_nexthops.sh
- Link to v1: https://lore.kernel.org/r/[email protected]--- tools/testing/selftests/net/drop_monitor_tests.sh | 13 +------ tools/testing/selftests/net/fcnal-test.sh | 29 +------------- tools/testing/selftests/net/fdb_flush.sh | 35 +---------------- tools/testing/selftests/net/fib-onlink-tests.sh | 18 +-------- .../selftests/net/fib_nexthop_multiprefix.sh | 21 +---------- tools/testing/selftests/net/fib_nexthop_nongw.sh | 21 +---------- tools/testing/selftests/net/fib_nexthops.sh | 44 ++-------------------- tools/testing/selftests/net/fib_rule_tests.sh | 19 +--------- tools/testing/selftests/net/fib_tests.sh | 26 +------------ tools/testing/selftests/net/gre_gso.sh | 26 +------------ tools/testing/selftests/net/icmp_redirect.sh | 28 ++------------ tools/testing/selftests/net/l2tp.sh | 19 +--------- tools/testing/selftests/net/lib.sh | 31 +++++++++++++++ .../selftests/net/ndisc_unsolicited_na_test.sh | 26 +------------ .../selftests/net/srv6_encap_lookup_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dt46_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dt4_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dt6_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_end_dx4_netfilter_test.sh | 23 ++--------- .../selftests/net/srv6_end_dx6_netfilter_test.sh | 23 ++--------- .../testing/selftests/net/srv6_end_flavors_test.sh | 23 ++--------- .../selftests/net/srv6_end_next_csid_l3vpn_test.sh | 19 +--------- .../net/srv6_end_x_next_csid_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_hencap_red_l3vpn_test.sh | 19 +--------- .../selftests/net/srv6_hl2encap_red_l2vpn_test.sh | 19 +--------- .../selftests/net/test_bridge_backup_port.sh | 32 +---------------
Quoted 8 lines
.../selftests/net/test_bridge_neigh_suppress.sh | 33 +--------------- tools/testing/selftests/net/test_vxlan_mdb.sh | 32 +--------------- .../selftests/net/test_vxlan_nolocalbypass.sh | 32 +--------------- .../selftests/net/test_vxlan_vnifiltering.sh | 26 +------------ tools/testing/selftests/net/vrf-xfrm-tests.sh | 19 +--------- tools/testing/selftests/net/vrf_route_leaking.sh | 19 +--------- .../testing/selftests/net/vrf_strict_mode_test.sh | 19 +--------- 33 files changed, 73 insertions(+), 716 deletions(-)
Hi everyone,
This patch is a bit too long for review, and maybe cause conflicts for stable backports. I plan to split it into small frags. But there are 2 ways to split it.
1. Split based on the test name. e.g. srv6 part, fib part, test_* part, and others.
2. Split based on the changes. e.g. group the tests that using exactly same log_test functions into one patch.
Does anyone has any suggestion?
Thanks
Hangbin
Jakub Kicinski
maintainerQuoted 6 lines · On Fri, 11 Sep 2026 11:31:55 +0800 Hangbin Liu wrote:
Hi everyone,
This patch is a bit too long for review, and maybe cause conflicts for stable backports. I plan to split it into small frags. But there are 2 ways to split it.
Quoted 6 lines
1. Split based on the test name. e.g. srv6 part, fib part, test_* part, and others.
2. Split based on the changes. e.g. group the tests that using exactly samelog_testfunctions into one patch.Does anyone has any suggestion?
I don't think it makes sense to split this.
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Fri, 11 Sep 2026 11:31:55 +0800 Hangbin Liu wrote:
Hi everyone,
This patch is a bit too long for review, and maybe cause conflicts for stable backports. I plan to split it into small frags. But there are 2 ways to split it.
Quoted 8 lines
Quoted 6 lines
1. Split based on the test name. e.g. srv6 part, fib part, test_* part, and others.
2. Split based on the changes. e.g. group the tests that using exactly samelog_testfunctions into one patch.Does anyone has any suggestion?
I don't think it makes sense to split this.
Thanks for the feedback. Then I will keep the changes in same patch.
Regards
Hangbin