]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: net: add helper for checking if nettest is available
authorJakub Kicinski <kuba@kernel.org>
Wed, 21 Aug 2024 01:22:27 +0000 (18:22 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 22 Aug 2024 10:55:47 +0000 (12:55 +0200)
A few tests check if nettest exists in the $PATH before adding
$PWD to $PATH and re-checking. They don't discard stderr on
the first check (and nettest is built as part of selftests,
so it's pretty normal for it to not be available in system $PATH).
This leads to output noise:

  which: no nettest in (/home/virtme/tools/fs/bin:/home/virtme/tools/fs/sbin:/home/virtme/tools/fs/usr/bin:/home/virtme/tools/fs/usr/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin)

Add a common helper for the check which does silence stderr.

There is another small functional change hiding here, because pmtu.sh
and fib_rule_tests.sh used to return from the test case rather than
completely exit. Building nettest is not hard, there should be no need
to maintain the ability to selectively skip cases in its absence.

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>
Link: https://patch.msgid.link/20240821012227.1398769-1-kuba@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
tools/testing/selftests/net/fcnal-test.sh
tools/testing/selftests/net/fib_rule_tests.sh
tools/testing/selftests/net/lib.sh
tools/testing/selftests/net/pmtu.sh
tools/testing/selftests/net/unicast_extensions.sh
tools/testing/selftests/net/vrf_route_leaking.sh

index 386ebd829df584ecd7a5ab1906b5f06f4c753fde..899dbad0104bf10d106f08517534fac886e6787c 100755 (executable)
@@ -4304,14 +4304,7 @@ elif [ "$TESTS" = "ipv6" ]; then
        TESTS="$TESTS_IPV6"
 fi
 
-# nettest can be run from PATH or from same directory as this selftest
-if ! which nettest >/dev/null; then
-       PATH=$PWD:$PATH
-       if ! which nettest >/dev/null; then
-               echo "'nettest' command not found; skipping tests"
-               exit $ksft_skip
-       fi
-fi
+check_gen_prog "nettest"
 
 declare -i nfail=0
 declare -i nsuccess=0
index 89034c5b69dc6a07b88598cbf076694e3eae24f4..53c5c1ad437e2e1a8a3a6c5694d5326a218eb263 100755 (executable)
@@ -51,31 +51,6 @@ log_test()
        fi
 }
 
-check_nettest()
-{
-       if which nettest > /dev/null 2>&1; then
-               return 0
-       fi
-
-       # Add the selftest directory to PATH if not already done
-       if [ "${SELFTEST_PATH}" = "" ]; then
-               SELFTEST_PATH="$(dirname $0)"
-               PATH="${PATH}:${SELFTEST_PATH}"
-
-               # Now retry with the new path
-               if which nettest > /dev/null 2>&1; then
-                       return 0
-               fi
-
-               if [ "${ret}" -eq 0 ]; then
-                       ret="${ksft_skip}"
-               fi
-               echo "nettest not found (try 'make -C ${SELFTEST_PATH} nettest')"
-       fi
-
-       return 1
-}
-
 setup()
 {
        set -e
@@ -317,11 +292,6 @@ fib_rule6_connect_test()
        echo
        echo "IPv6 FIB rule connect tests"
 
-       if ! check_nettest; then
-               echo "SKIP: Could not run test without nettest tool"
-               return
-       fi
-
        setup_peer
        $IP -6 rule add dsfield 0x04 table $RTABLE_PEER
 
@@ -516,11 +486,6 @@ fib_rule4_connect_test()
        echo
        echo "IPv4 FIB rule connect tests"
 
-       if ! check_nettest; then
-               echo "SKIP: Could not run test without nettest tool"
-               return
-       fi
-
        setup_peer
        $IP -4 rule add dsfield 0x04 table $RTABLE_PEER
 
@@ -584,6 +549,8 @@ if [ ! -x "$(command -v ip)" ]; then
        exit $ksft_skip
 fi
 
+check_gen_prog "nettest"
+
 # start clean
 cleanup &> /dev/null
 setup
index 8ee4489238ca4b19bcf6608a71256ba89472148f..be8707bfb46e5f45723b009e7cfb881ab9b5afba 100644 (file)
@@ -125,6 +125,21 @@ slowwait_for_counter()
        slowwait "$timeout" until_counter_is ">= $((base + delta))" "$@"
 }
 
+# Check for existence of tools which are built as part of selftests
+# but may also already exist in $PATH
+check_gen_prog()
+{
+       local prog_name=$1; shift
+
+       if ! which $prog_name >/dev/null 2>/dev/null; then
+               PATH=$PWD:$PATH
+               if ! which $prog_name >/dev/null; then
+                       echo "'$prog_name' command not found; skipping tests"
+                       exit $ksft_skip
+               fi
+       fi
+}
+
 remove_ns_list()
 {
        local item=$1
index 24a50622406c25f79c27c6f819b6cbc1af05246f..569bce8b6383eea71290aa15e5bb1c050b2bbfc1 100755 (executable)
@@ -681,13 +681,7 @@ setup_xfrm() {
 }
 
 setup_nettest_xfrm() {
-       if ! which nettest >/dev/null; then
-               PATH=$PWD:$PATH
-               if ! which nettest >/dev/null; then
-                       echo "'nettest' command not found; skipping tests"
-                       return 1
-               fi
-       fi
+       check_gen_prog "nettest"
 
        [ ${1} -eq 6 ] && proto="-6" || proto=""
        port=${2}
index f52aa5f7da524098b3314a38b1a9b48117f5cd83..3e751234ccfe830b3fb6495a06551cfde5fbbd52 100755 (executable)
 
 source lib.sh
 
-# nettest can be run from PATH or from same directory as this selftest
-if ! which nettest >/dev/null; then
-       PATH=$PWD:$PATH
-       if ! which nettest >/dev/null; then
-               echo "'nettest' command not found; skipping tests"
-               exit $ksft_skip
-       fi
-fi
+check_gen_prog "nettest"
 
 result=0
 
index 152171fb1fc8c3eb3788bdd36ac70567ad79a979..e9c2f71da20720db770bd78a27b13a2b48b8c2cd 100755 (executable)
@@ -59,7 +59,6 @@
 # while it is forwarded between different vrfs.
 
 source lib.sh
-PATH=$PWD:$PWD/tools/testing/selftests/net:$PATH
 VERBOSE=0
 PAUSE_ON_FAIL=no
 DEFAULT_TTYPE=sym
@@ -636,6 +635,8 @@ EOF
 # Some systems don't have a ping6 binary anymore
 command -v ping6 > /dev/null 2>&1 && ping6=$(command -v ping6) || ping6=$(command -v ping)
 
+check_gen_prog "nettest"
+
 TESTS_IPV4="ipv4_ping_ttl ipv4_traceroute ipv4_ping_frag ipv4_ping_local ipv4_tcp_local
 ipv4_udp_local ipv4_ping_ttl_asym ipv4_traceroute_asym"
 TESTS_IPV6="ipv6_ping_ttl ipv6_traceroute ipv6_ping_local ipv6_tcp_local ipv6_udp_local