Commit 7844ec21 authored by Po-Hsu Lin's avatar Po-Hsu Lin Committed by Jakub Kicinski

selftests/net: Use kselftest skip code for skipped tests

There are several test cases in the net directory are still using
exit 0 or exit 1 when they need to be skipped. Use kselftest
framework skip code instead so it can help us to distinguish the
return status.

Criterion to filter out what should be fixed in net directory:
  grep -r "exit [01]" -B1 | grep -i skip

This change might cause some false-positives if people are running
these test scripts directly and only checking their return codes,
which will change from 0 to 4. However I think the impact should be
small as most of our scripts here are already using this skip code.
And there will be no such issue if running them with the kselftest
framework.
Signed-off-by: default avatarPo-Hsu Lin <po-hsu.lin@canonical.com>
Reviewed-by: default avatarIdo Schimmel <idosch@nvidia.com>
Tested-by: default avatarIdo Schimmel <idosch@nvidia.com>
Link: https://lore.kernel.org/r/20210823085854.40216-1-po-hsu.lin@canonical.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 3a62c333
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
# #
# server / client nomenclature relative to ns-A # server / client nomenclature relative to ns-A
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
VERBOSE=0 VERBOSE=0
NSA_DEV=eth1 NSA_DEV=eth1
...@@ -3974,7 +3977,7 @@ fi ...@@ -3974,7 +3977,7 @@ fi
which nettest >/dev/null which nettest >/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "'nettest' command not found; skipping tests" echo "'nettest' command not found; skipping tests"
exit 0 exit $ksft_skip
fi fi
declare -i nfail=0 declare -i nfail=0
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
# This test is for checking IPv4 and IPv6 FIB rules API # This test is for checking IPv4 and IPv6 FIB rules API
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
ret=0 ret=0
PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
...@@ -238,12 +241,12 @@ run_fibrule_tests() ...@@ -238,12 +241,12 @@ run_fibrule_tests()
if [ "$(id -u)" -ne 0 ];then if [ "$(id -u)" -ne 0 ];then
echo "SKIP: Need root privileges" echo "SKIP: Need root privileges"
exit 0 exit $ksft_skip
fi fi
if [ ! -x "$(command -v ip)" ]; then if [ ! -x "$(command -v ip)" ]; then
echo "SKIP: Could not run test without ip tool" echo "SKIP: Could not run test without ip tool"
exit 0 exit $ksft_skip
fi fi
# start clean # start clean
......
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
############################################################################## ##############################################################################
# Defines # Defines
...@@ -9,11 +12,11 @@ if [[ ! -v DEVLINK_DEV ]]; then ...@@ -9,11 +12,11 @@ if [[ ! -v DEVLINK_DEV ]]; then
| jq -r '.port | keys[]' | cut -d/ -f-2) | jq -r '.port | keys[]' | cut -d/ -f-2)
if [ -z "$DEVLINK_DEV" ]; then if [ -z "$DEVLINK_DEV" ]; then
echo "SKIP: ${NETIFS[p1]} has no devlink device registered for it" echo "SKIP: ${NETIFS[p1]} has no devlink device registered for it"
exit 1 exit $ksft_skip
fi fi
if [[ "$(echo $DEVLINK_DEV | grep -c pci)" -eq 0 ]]; then if [[ "$(echo $DEVLINK_DEV | grep -c pci)" -eq 0 ]]; then
echo "SKIP: devlink device's bus is not PCI" echo "SKIP: devlink device's bus is not PCI"
exit 1 exit $ksft_skip
fi fi
DEVLINK_VIDDID=$(lspci -s $(echo $DEVLINK_DEV | cut -d"/" -f2) \ DEVLINK_VIDDID=$(lspci -s $(echo $DEVLINK_DEV | cut -d"/" -f2) \
...@@ -22,7 +25,7 @@ elif [[ ! -z "$DEVLINK_DEV" ]]; then ...@@ -22,7 +25,7 @@ elif [[ ! -z "$DEVLINK_DEV" ]]; then
devlink dev show $DEVLINK_DEV &> /dev/null devlink dev show $DEVLINK_DEV &> /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "SKIP: devlink device \"$DEVLINK_DEV\" not found" echo "SKIP: devlink device \"$DEVLINK_DEV\" not found"
exit 1 exit $ksft_skip
fi fi
fi fi
...@@ -32,19 +35,19 @@ fi ...@@ -32,19 +35,19 @@ fi
devlink help 2>&1 | grep resource &> /dev/null devlink help 2>&1 | grep resource &> /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "SKIP: iproute2 too old, missing devlink resource support" echo "SKIP: iproute2 too old, missing devlink resource support"
exit 1 exit $ksft_skip
fi fi
devlink help 2>&1 | grep trap &> /dev/null devlink help 2>&1 | grep trap &> /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "SKIP: iproute2 too old, missing devlink trap support" echo "SKIP: iproute2 too old, missing devlink trap support"
exit 1 exit $ksft_skip
fi fi
devlink dev help 2>&1 | grep info &> /dev/null devlink dev help 2>&1 | grep info &> /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "SKIP: iproute2 too old, missing devlink dev info support" echo "SKIP: iproute2 too old, missing devlink dev info support"
exit 1 exit $ksft_skip
fi fi
############################################################################## ##############################################################################
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
############################################################################## ##############################################################################
# Defines # Defines
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
# Can be overridden by the configuration file. # Can be overridden by the configuration file.
PING=${PING:=ping} PING=${PING:=ping}
PING6=${PING6:=ping6} PING6=${PING6:=ping6}
...@@ -38,7 +41,7 @@ check_tc_version() ...@@ -38,7 +41,7 @@ check_tc_version()
tc -j &> /dev/null tc -j &> /dev/null
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "SKIP: iproute2 too old; tc is missing JSON support" echo "SKIP: iproute2 too old; tc is missing JSON support"
exit 1 exit $ksft_skip
fi fi
} }
...@@ -51,7 +54,7 @@ check_tc_mpls_support() ...@@ -51,7 +54,7 @@ check_tc_mpls_support()
matchall action pipe &> /dev/null matchall action pipe &> /dev/null
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "SKIP: iproute2 too old; tc is missing MPLS support" echo "SKIP: iproute2 too old; tc is missing MPLS support"
return 1 return $ksft_skip
fi fi
tc filter del dev $dev ingress protocol mpls_uc pref 1 handle 1 \ tc filter del dev $dev ingress protocol mpls_uc pref 1 handle 1 \
matchall matchall
...@@ -69,7 +72,7 @@ check_tc_mpls_lse_stats() ...@@ -69,7 +72,7 @@ check_tc_mpls_lse_stats()
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "SKIP: iproute2 too old; tc-flower is missing extended MPLS support" echo "SKIP: iproute2 too old; tc-flower is missing extended MPLS support"
return 1 return $ksft_skip
fi fi
tc -j filter show dev $dev ingress protocol mpls_uc | jq . &> /dev/null tc -j filter show dev $dev ingress protocol mpls_uc | jq . &> /dev/null
...@@ -79,7 +82,7 @@ check_tc_mpls_lse_stats() ...@@ -79,7 +82,7 @@ check_tc_mpls_lse_stats()
if [[ $ret -ne 0 ]]; then if [[ $ret -ne 0 ]]; then
echo "SKIP: iproute2 too old; tc-flower produces invalid json output for extended MPLS filters" echo "SKIP: iproute2 too old; tc-flower produces invalid json output for extended MPLS filters"
return 1 return $ksft_skip
fi fi
} }
...@@ -88,7 +91,7 @@ check_tc_shblock_support() ...@@ -88,7 +91,7 @@ check_tc_shblock_support()
tc filter help 2>&1 | grep block &> /dev/null tc filter help 2>&1 | grep block &> /dev/null
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "SKIP: iproute2 too old; tc is missing shared block support" echo "SKIP: iproute2 too old; tc is missing shared block support"
exit 1 exit $ksft_skip
fi fi
} }
...@@ -97,7 +100,7 @@ check_tc_chain_support() ...@@ -97,7 +100,7 @@ check_tc_chain_support()
tc help 2>&1|grep chain &> /dev/null tc help 2>&1|grep chain &> /dev/null
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "SKIP: iproute2 too old; tc is missing chain support" echo "SKIP: iproute2 too old; tc is missing chain support"
exit 1 exit $ksft_skip
fi fi
} }
...@@ -106,7 +109,7 @@ check_tc_action_hw_stats_support() ...@@ -106,7 +109,7 @@ check_tc_action_hw_stats_support()
tc actions help 2>&1 | grep -q hw_stats tc actions help 2>&1 | grep -q hw_stats
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "SKIP: iproute2 too old; tc is missing action hw_stats support" echo "SKIP: iproute2 too old; tc is missing action hw_stats support"
exit 1 exit $ksft_skip
fi fi
} }
...@@ -115,13 +118,13 @@ check_ethtool_lanes_support() ...@@ -115,13 +118,13 @@ check_ethtool_lanes_support()
ethtool --help 2>&1| grep lanes &> /dev/null ethtool --help 2>&1| grep lanes &> /dev/null
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "SKIP: ethtool too old; it is missing lanes support" echo "SKIP: ethtool too old; it is missing lanes support"
exit 1 exit $ksft_skip
fi fi
} }
if [[ "$(id -u)" -ne 0 ]]; then if [[ "$(id -u)" -ne 0 ]]; then
echo "SKIP: need root privileges" echo "SKIP: need root privileges"
exit 0 exit $ksft_skip
fi fi
if [[ "$CHECK_TC" = "yes" ]]; then if [[ "$CHECK_TC" = "yes" ]]; then
...@@ -134,7 +137,7 @@ require_command() ...@@ -134,7 +137,7 @@ require_command()
if [[ ! -x "$(command -v "$cmd")" ]]; then if [[ ! -x "$(command -v "$cmd")" ]]; then
echo "SKIP: $cmd not installed" echo "SKIP: $cmd not installed"
exit 1 exit $ksft_skip
fi fi
} }
...@@ -143,7 +146,7 @@ require_command $MZ ...@@ -143,7 +146,7 @@ require_command $MZ
if [[ ! -v NUM_NETIFS ]]; then if [[ ! -v NUM_NETIFS ]]; then
echo "SKIP: importer does not define \"NUM_NETIFS\"" echo "SKIP: importer does not define \"NUM_NETIFS\""
exit 1 exit $ksft_skip
fi fi
############################################################################## ##############################################################################
...@@ -203,7 +206,7 @@ for ((i = 1; i <= NUM_NETIFS; ++i)); do ...@@ -203,7 +206,7 @@ for ((i = 1; i <= NUM_NETIFS; ++i)); do
ip link show dev ${NETIFS[p$i]} &> /dev/null ip link show dev ${NETIFS[p$i]} &> /dev/null
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "SKIP: could not find all required interfaces" echo "SKIP: could not find all required interfaces"
exit 1 exit $ksft_skip
fi fi
done done
......
...@@ -411,7 +411,7 @@ ping_ipv6() ...@@ -411,7 +411,7 @@ ping_ipv6()
ip nexthop ls >/dev/null 2>&1 ip nexthop ls >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Nexthop objects not supported; skipping tests" echo "Nexthop objects not supported; skipping tests"
exit 0 exit $ksft_skip
fi fi
trap cleanup EXIT trap cleanup EXIT
......
...@@ -386,7 +386,7 @@ ping_ipv6() ...@@ -386,7 +386,7 @@ ping_ipv6()
ip nexthop ls >/dev/null 2>&1 ip nexthop ls >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Nexthop objects not supported; skipping tests" echo "Nexthop objects not supported; skipping tests"
exit 0 exit $ksft_skip
fi fi
trap cleanup EXIT trap cleanup EXIT
......
#!/bin/sh #!/bin/sh
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
if [ $(id -u) != 0 ]; then if [ $(id -u) != 0 ]; then
echo $msg must be run as root >&2 echo $msg must be run as root >&2
exit 0 exit $ksft_skip
fi fi
ret=0 ret=0
......
...@@ -193,6 +193,9 @@ ...@@ -193,6 +193,9 @@
# +---------------------------------------------------+ # +---------------------------------------------------+
# #
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
readonly LOCALSID_TABLE_ID=90 readonly LOCALSID_TABLE_ID=90
readonly IPv6_RT_NETWORK=fd00 readonly IPv6_RT_NETWORK=fd00
readonly IPv6_HS_NETWORK=cafe readonly IPv6_HS_NETWORK=cafe
...@@ -543,18 +546,18 @@ host_vpn_isolation_tests() ...@@ -543,18 +546,18 @@ host_vpn_isolation_tests()
if [ "$(id -u)" -ne 0 ];then if [ "$(id -u)" -ne 0 ];then
echo "SKIP: Need root privileges" echo "SKIP: Need root privileges"
exit 0 exit $ksft_skip
fi fi
if [ ! -x "$(command -v ip)" ]; then if [ ! -x "$(command -v ip)" ]; then
echo "SKIP: Could not run test without ip tool" echo "SKIP: Could not run test without ip tool"
exit 0 exit $ksft_skip
fi fi
modprobe vrf &>/dev/null modprobe vrf &>/dev/null
if [ ! -e /proc/sys/net/vrf/strict_mode ]; then if [ ! -e /proc/sys/net/vrf/strict_mode ]; then
echo "SKIP: vrf sysctl does not exist" echo "SKIP: vrf sysctl does not exist"
exit 0 exit $ksft_skip
fi fi
cleanup &>/dev/null cleanup &>/dev/null
......
...@@ -163,6 +163,9 @@ ...@@ -163,6 +163,9 @@
# +---------------------------------------------------+ # +---------------------------------------------------+
# #
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
readonly LOCALSID_TABLE_ID=90 readonly LOCALSID_TABLE_ID=90
readonly IPv6_RT_NETWORK=fd00 readonly IPv6_RT_NETWORK=fd00
readonly IPv4_HS_NETWORK=10.0.0 readonly IPv4_HS_NETWORK=10.0.0
...@@ -464,18 +467,18 @@ host_vpn_isolation_tests() ...@@ -464,18 +467,18 @@ host_vpn_isolation_tests()
if [ "$(id -u)" -ne 0 ];then if [ "$(id -u)" -ne 0 ];then
echo "SKIP: Need root privileges" echo "SKIP: Need root privileges"
exit 0 exit $ksft_skip
fi fi
if [ ! -x "$(command -v ip)" ]; then if [ ! -x "$(command -v ip)" ]; then
echo "SKIP: Could not run test without ip tool" echo "SKIP: Could not run test without ip tool"
exit 0 exit $ksft_skip
fi fi
modprobe vrf &>/dev/null modprobe vrf &>/dev/null
if [ ! -e /proc/sys/net/vrf/strict_mode ]; then if [ ! -e /proc/sys/net/vrf/strict_mode ]; then
echo "SKIP: vrf sysctl does not exist" echo "SKIP: vrf sysctl does not exist"
exit 0 exit $ksft_skip
fi fi
cleanup &>/dev/null cleanup &>/dev/null
......
...@@ -164,6 +164,9 @@ ...@@ -164,6 +164,9 @@
# +---------------------------------------------------+ # +---------------------------------------------------+
# #
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
readonly LOCALSID_TABLE_ID=90 readonly LOCALSID_TABLE_ID=90
readonly IPv6_RT_NETWORK=fd00 readonly IPv6_RT_NETWORK=fd00
readonly IPv6_HS_NETWORK=cafe readonly IPv6_HS_NETWORK=cafe
...@@ -472,18 +475,18 @@ host_vpn_isolation_tests() ...@@ -472,18 +475,18 @@ host_vpn_isolation_tests()
if [ "$(id -u)" -ne 0 ];then if [ "$(id -u)" -ne 0 ];then
echo "SKIP: Need root privileges" echo "SKIP: Need root privileges"
exit 0 exit $ksft_skip
fi fi
if [ ! -x "$(command -v ip)" ]; then if [ ! -x "$(command -v ip)" ]; then
echo "SKIP: Could not run test without ip tool" echo "SKIP: Could not run test without ip tool"
exit 0 exit $ksft_skip
fi fi
modprobe vrf &>/dev/null modprobe vrf &>/dev/null
if [ ! -e /proc/sys/net/vrf/strict_mode ]; then if [ ! -e /proc/sys/net/vrf/strict_mode ]; then
echo "SKIP: vrf sysctl does not exist" echo "SKIP: vrf sysctl does not exist"
exit 0 exit $ksft_skip
fi fi
cleanup &>/dev/null cleanup &>/dev/null
......
...@@ -28,12 +28,15 @@ ...@@ -28,12 +28,15 @@
# These tests provide an easy way to flip the expected result of any # These tests provide an easy way to flip the expected result of any
# of these behaviors for testing kernel patches that change them. # of these behaviors for testing kernel patches that change them.
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
# nettest can be run from PATH or from same directory as this selftest # nettest can be run from PATH or from same directory as this selftest
if ! which nettest >/dev/null; then if ! which nettest >/dev/null; then
PATH=$PWD:$PATH PATH=$PWD:$PATH
if ! which nettest >/dev/null; then if ! which nettest >/dev/null; then
echo "'nettest' command not found; skipping tests" echo "'nettest' command not found; skipping tests"
exit 0 exit $ksft_skip
fi fi
fi fi
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
# This test is designed for testing the new VRF strict_mode functionality. # This test is designed for testing the new VRF strict_mode functionality.
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
ret=0 ret=0
# identifies the "init" network namespace which is often called root network # identifies the "init" network namespace which is often called root network
...@@ -371,18 +374,18 @@ vrf_strict_mode_check_support() ...@@ -371,18 +374,18 @@ vrf_strict_mode_check_support()
if [ "$(id -u)" -ne 0 ];then if [ "$(id -u)" -ne 0 ];then
echo "SKIP: Need root privileges" echo "SKIP: Need root privileges"
exit 0 exit $ksft_skip
fi fi
if [ ! -x "$(command -v ip)" ]; then if [ ! -x "$(command -v ip)" ]; then
echo "SKIP: Could not run test without ip tool" echo "SKIP: Could not run test without ip tool"
exit 0 exit $ksft_skip
fi fi
modprobe vrf &>/dev/null modprobe vrf &>/dev/null
if [ ! -e /proc/sys/net/vrf/strict_mode ]; then if [ ! -e /proc/sys/net/vrf/strict_mode ]; then
echo "SKIP: vrf sysctl does not exist" echo "SKIP: vrf sysctl does not exist"
exit 0 exit $ksft_skip
fi fi
cleanup &> /dev/null cleanup &> /dev/null
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment