Some kselftests rely on teamd to create LAG devices. If the kernel is built without CONFIG_NET_TEAM, the teamd command fails with: Failed: Operation not supported Currently, the exit code of teamd is not properly checked, causing the test to proceed and eventually fail instead of being skipped. Add a check for the teamd exit code, mark the test as skipped to avoid self-positive failures. Signed-off-by: Aleksei Oladko --- tools/testing/selftests/net/forwarding/lib.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index a9034f0bb58b..0a474b02371d 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -771,9 +771,21 @@ team_create() { local if_name=$1; shift local mode=$1; shift + local output + local status require_command $TEAMD - $TEAMD -t $if_name -d -c '{"runner": {"name": "'$mode'"}}' + output=$($TEAMD -t $if_name -d -c '{"runner": {"name": "'$mode'"}}' 2>&1) + status=$? + + if [ $status -ne 0 ]; then + if echo "$output" | grep -q "Operation not supported"; then + exit $ksft_skip + else + exit 1 + fi + fi + for slave in "$@"; do ip link set dev $slave down ip link set dev $slave master $if_name -- 2.43.0 The sch_ets.sh test requires the cls_basic kernel module to function properly. If the kernel is compiled without CONFIG_NET_CLS_BASIC, the test fails instead of being gracefully skipped. Add a check to attempt loading the cls_basic module. If modprobe fails, the test will be skipped. Signed-off-by: Aleksei Oladko --- tools/testing/selftests/net/forwarding/sch_ets_core.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/net/forwarding/sch_ets_core.sh b/tools/testing/selftests/net/forwarding/sch_ets_core.sh index 0453210271dc..ff3ac3e43c33 100644 --- a/tools/testing/selftests/net/forwarding/sch_ets_core.sh +++ b/tools/testing/selftests/net/forwarding/sch_ets_core.sh @@ -98,6 +98,7 @@ classifier_mode() { echo "Running in classifier mode" ets_delete_qdisc + modprobe cls_basic || exit $ksft_skip ETS_CHANGE_QDISC=ets_change_qdisc_classifier } -- 2.43.0 In some forwarding tests, it is necessary to check for features or specific keywords in command output before proceeding. Introduce the run_cmd_grep helper in lib.sh. This helper executes a command and searches for a specific pattern in its output. Signed-off-by: Aleksei Oladko --- tools/testing/selftests/net/forwarding/lib.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 0a474b02371d..dcf17c19ad77 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -2163,3 +2163,22 @@ has_unicast_flt() [[ $promisc == 1 ]] && echo "no" || echo "yes" } + +run_cmd_grep_common() +{ + local find="$1"; shift + local cmd="$*" + + if [ "$VERBOSE" = "1" ]; then + echo "COMMAND: ${cmd} 2>&1 | grep -q '${find}'" + fi + $cmd 2>&1 | grep -q "${find}" + return $? +} + +run_cmd_grep() { + run_cmd_grep_common "$@" + rc=$? + check_err $rc + return $rc +} -- 2.43.0 The tc_flower_cfm.sh selftest assume the presence of iproute2 support for the `cfm` keyword in `tc filter` commands. These assumptions can cause test failures. This patch improves test robustness by skipping the test if tc filter help does not mention CFM Signed-off-by: Aleksei Oladko --- tools/testing/selftests/net/forwarding/tc_flower_cfm.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/tc_flower_cfm.sh b/tools/testing/selftests/net/forwarding/tc_flower_cfm.sh index 3ca20df952eb..65f95fe88b38 100755 --- a/tools/testing/selftests/net/forwarding/tc_flower_cfm.sh +++ b/tools/testing/selftests/net/forwarding/tc_flower_cfm.sh @@ -196,6 +196,8 @@ cleanup() vrf_cleanup } +run_cmd_grep 'CFM' tc filter add dev lo ingress flower help || exit $ksft_skip + trap cleanup EXIT setup_prepare -- 2.43.0 The tc_flower_l2_miss.sh selftest assume the presence of iproute2 support for the `l2_miss` keyword in `tc filter` commands. These assumptions can cause test failures. This patch improves test robustness by skipping the test if tc filter help does not mention l2 miss Signed-off-by: Aleksei Oladko --- tools/testing/selftests/net/forwarding/tc_flower_l2_miss.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/tc_flower_l2_miss.sh b/tools/testing/selftests/net/forwarding/tc_flower_l2_miss.sh index c2420bb72c12..c28569b8948f 100755 --- a/tools/testing/selftests/net/forwarding/tc_flower_l2_miss.sh +++ b/tools/testing/selftests/net/forwarding/tc_flower_l2_miss.sh @@ -347,6 +347,8 @@ cleanup() vrf_cleanup } +run_cmd_grep 'l2_miss' tc filter add dev lo ingress flower help || exit $ksft_skip + trap cleanup EXIT setup_prepare -- 2.43.0 The router_mpath_seed.sh selftest assume the presence of iproute2 support for the `hw_stats` keyword in `ip nexthop` commands. These assumptions can cause test failures. This patch improves test robustness by skipping the test if ip nexthop add help does not mention hw_stats Signed-off-by: Aleksei Oladko --- tools/testing/selftests/net/forwarding/router_mpath_seed.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/router_mpath_seed.sh b/tools/testing/selftests/net/forwarding/router_mpath_seed.sh index 314cb906c1eb..d9dc5d3a10d5 100755 --- a/tools/testing/selftests/net/forwarding/router_mpath_seed.sh +++ b/tools/testing/selftests/net/forwarding/router_mpath_seed.sh @@ -322,6 +322,8 @@ test_mpath_seed_stability_ipv6() -p 64 -d 0 -c 10 -t udp } +run_cmd_grep 'hw_stats' ip nexthop add help || exit $ksft_skip + trap cleanup EXIT setup_prepare -- 2.43.0