Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'selftests-fixes-for-kernel-ci'

Petr Machata says:

====================
selftests: Fixes for kernel CI

As discussed on the bi-weekly call on Jan 30, and in mailing around
kernel CI effort, some changes are desirable in the suite of forwarding
selftests the better to work with the CI tooling. Namely:

- The forwarding selftests use a configuration file where names of
interfaces are defined and various variables can be overridden. There
is also forwarding.config.sample that users can use as a template to
refer to when creating the config file. What happens a fair bit is
that users either do not know about this at all, or simply forget, and
are confused by cryptic failures about interfaces that cannot be
created.

In patches #1 - #3 have lib.sh just be the single source of truth with
regards to which variables exist. That includes the topology variables
which were previously only in the sample file, and any "tweak
variables", such as what tools to use, sleep times, etc.

forwarding.config.sample then becomes just a placeholder with a couple
examples. Unless specific HW should be exercised, or specific tools
used, the defaults are usually just fine.

- Several net/forwarding/ selftests (and one net/ one) cannot be run on
veth pairs, they need an actual HW interface to run on. They are
generic in the sense that any capable HW should pass them, which is
why they have been put to net/forwarding/ as opposed to drivers/net/,
but they do not generalize to veth. The fact that these tests are in
net/forwarding/, but still complaining when run, is confusing.

In patches #4 - #6 move these tests to a new directory
drivers/net/hw.

- The following patches extend the codebase to handle well test results
other than pass and fail.

Patch #7 is preparatory. It converts several log_test_skip to XFAIL,
so that tests do not spuriously end up returning non-0 when they
are not supposed to.

In patches #8 - #10, introduce some missing ksft constants, then support
having those constants in RET, and then finally in EXIT_STATUS.

- The traffic scheduler tests generate a large amount of network traffic
to test the behavior of the scheduler. This demands a relatively
high-performance computer. On slow machines, such as with a debugging
kernel, the test would spuriously fail.

It can still be useful to "go through the motions" though, to possibly
catch bugs in setup of the scheduler graph and passing packets around.
Thus we still want to run the tests, just with lowered demands.

To that end, in patches #11 - #12, introduce an environment variable
KSFT_MACHINE_SLOW, with obvious meaning. Tests can then make checks
more lenient, such as mark failures as XFAIL. A helper, xfail_on_slow,
is provided to mark performance-sensitive parts of the selftest.

- In patch #13, use a similar mechanism to mark a NH group stats
selftest to XFAIL HW stats tests when run on VETH pairs.

- All these changes complicate the hitherto straightforward logging and
checking logic, so in patch #14, add a selftest that checks this
functionality in lib.sh.

v1 (vs. an RFC circulated through linux-kselftest):
- Patch #9:
- Clarify intended usage by s/set_ret/ret_set_ksft_status/,
s/nret/ksft_status/
====================

Link: https://lore.kernel.org/r/cover.1711464583.git.petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+565 -171
+25
tools/testing/selftests/drivers/net/hw/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0+ OR MIT 2 + 3 + TEST_PROGS = \ 4 + devlink_port_split.py \ 5 + ethtool.sh \ 6 + ethtool_extended_state.sh \ 7 + ethtool_mm.sh \ 8 + ethtool_rmon.sh \ 9 + hw_stats_l3.sh \ 10 + hw_stats_l3_gre.sh \ 11 + loopback.sh \ 12 + # 13 + 14 + TEST_FILES := \ 15 + ethtool_lib.sh \ 16 + # 17 + 18 + TEST_INCLUDES := \ 19 + ../../../net/lib.sh \ 20 + ../../../net/forwarding/lib.sh \ 21 + ../../../net/forwarding/ipip_lib.sh \ 22 + ../../../net/forwarding/tc_common.sh \ 23 + # 24 + 25 + include ../../../lib.mk
+1
tools/testing/selftests/drivers/net/hw/settings
··· 1 + timeout=0
+1 -1
tools/testing/selftests/drivers/net/mlxsw/mlxsw_lib.sh
··· 42 42 local src=$1; shift 43 43 44 44 if ! mlxsw_on_spectrum "$rev"; then 45 - log_test_skip $src:$caller "(Spectrum-$rev only)" 45 + log_test_xfail $src:$caller "(Spectrum-$rev only)" 46 46 return 1 47 47 fi 48 48 }
-1
tools/testing/selftests/drivers/net/mlxsw/spectrum-2/resource_scale.sh
··· 47 47 RET=0 48 48 target=$(${current_test}_get_target "$should_fail") 49 49 if ((target == 0)); then 50 - log_test_skip "'$current_test' should_fail=$should_fail test" 51 50 continue 52 51 fi 53 52
-1
tools/testing/selftests/drivers/net/mlxsw/spectrum/resource_scale.sh
··· 52 52 RET=0 53 53 target=$(${current_test}_get_target "$should_fail") 54 54 if ((target == 0)); then 55 - log_test_skip "'$current_test' [$profile] should_fail=$should_fail test" 56 55 continue 57 56 fi 58 57 ${current_test}_setup_prepare
-1
tools/testing/selftests/net/Makefile
··· 20 20 TEST_PROGS += txtimestamp.sh 21 21 TEST_PROGS += vrf-xfrm-tests.sh 22 22 TEST_PROGS += rxtimestamp.sh 23 - TEST_PROGS += devlink_port_split.py 24 23 TEST_PROGS += drop_monitor_tests.sh 25 24 TEST_PROGS += vrf_route_leaking.sh 26 25 TEST_PROGS += bareudp.sh
+1 -8
tools/testing/selftests/net/forwarding/Makefile
··· 15 15 bridge_vlan_unaware.sh \ 16 16 custom_multipath_hash.sh \ 17 17 dual_vxlan_bridge.sh \ 18 - ethtool_extended_state.sh \ 19 - ethtool_mm.sh \ 20 - ethtool_rmon.sh \ 21 - ethtool.sh \ 22 18 gre_custom_multipath_hash.sh \ 23 19 gre_inner_v4_multipath.sh \ 24 20 gre_inner_v6_multipath.sh \ 25 21 gre_multipath_nh_res.sh \ 26 22 gre_multipath_nh.sh \ 27 23 gre_multipath.sh \ 28 - hw_stats_l3.sh \ 29 - hw_stats_l3_gre.sh \ 30 24 ip6_forward_instats_vrf.sh \ 31 25 ip6gre_custom_multipath_hash.sh \ 32 26 ip6gre_flat_key.sh \ ··· 37 43 ipip_hier_gre_key.sh \ 38 44 ipip_hier_gre_keys.sh \ 39 45 ipip_hier_gre.sh \ 46 + lib_sh_test.sh \ 40 47 local_termination.sh \ 41 - loopback.sh \ 42 48 mirror_gre_bound.sh \ 43 49 mirror_gre_bridge_1d.sh \ 44 50 mirror_gre_bridge_1d_vlan.sh \ ··· 107 113 vxlan_symmetric.sh 108 114 109 115 TEST_FILES := devlink_lib.sh \ 110 - ethtool_lib.sh \ 111 116 fib_offload_lib.sh \ 112 117 forwarding.config.sample \ 113 118 ip6gre_lib.sh \
+33
tools/testing/selftests/net/forwarding/README
··· 56 56 o Code shall be checked using ShellCheck [1] prior to submission. 57 57 58 58 1. https://www.shellcheck.net/ 59 + 60 + Customization 61 + ============= 62 + 63 + The forwarding selftests framework uses a number of variables that 64 + influence its behavior and tools it invokes, and how it invokes them, in 65 + various ways. A number of these variables can be overridden. The way these 66 + overridable variables are specified is typically one of the following two 67 + syntaxes: 68 + 69 + : "${VARIABLE:=default_value}" 70 + VARIABLE=${VARIABLE:=default_value} 71 + 72 + Any of these variables can be overridden. Notably net/forwarding/lib.sh and 73 + net/lib.sh contain a number of overridable variables. 74 + 75 + One way of overriding these variables is through the environment: 76 + 77 + PAUSE_ON_FAIL=yes ./some_test.sh 78 + 79 + The variable NETIFS is special. Since it is an array variable, there is no 80 + way to pass it through the environment. Its value can instead be given as 81 + consecutive arguments to the selftest: 82 + 83 + ./some_test.sh swp{1..8} 84 + 85 + A way to customize variables in a persistent fashion is to create a file 86 + named forwarding.config in this directory. lib.sh sources the file if 87 + present, so it can contain any shell code. Typically it will contain 88 + assignments of variables whose value should be overridden. 89 + 90 + forwarding.config.sample is available in the directory as an example of 91 + how forwarding.config might look.
+2 -3
tools/testing/selftests/net/forwarding/ethtool.sh tools/testing/selftests/drivers/net/hw/ethtool.sh
··· 10 10 different_speeds_autoneg_on 11 11 " 12 12 NUM_NETIFS=2 13 - source lib.sh 13 + lib_dir=$(dirname "$0") 14 + source "$lib_dir"/../../../net/forwarding/lib.sh 14 15 source ethtool_lib.sh 15 16 16 17 h1_create() ··· 286 285 ethtool -s $h2 autoneg on 287 286 ethtool -s $h1 autoneg on 288 287 } 289 - 290 - skip_on_veth 291 288 292 289 trap cleanup EXIT 293 290
+2 -3
tools/testing/selftests/net/forwarding/ethtool_extended_state.sh tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh
··· 8 8 " 9 9 10 10 NUM_NETIFS=2 11 - source lib.sh 11 + lib_dir=$(dirname "$0") 12 + source "$lib_dir"/../../../net/forwarding/lib.sh 12 13 source ethtool_lib.sh 13 14 14 15 TIMEOUT=$((WAIT_TIMEOUT * 1000)) # ms ··· 108 107 109 108 ip link set dev $swp3 down 110 109 } 111 - 112 - skip_on_veth 113 110 114 111 setup_prepare 115 112
tools/testing/selftests/net/forwarding/ethtool_lib.sh tools/testing/selftests/drivers/net/hw/ethtool_lib.sh
+2 -1
tools/testing/selftests/net/forwarding/ethtool_mm.sh tools/testing/selftests/drivers/net/hw/ethtool_mm.sh
··· 14 14 NUM_NETIFS=2 15 15 REQUIRE_MZ=no 16 16 PREEMPTIBLE_PRIO=0 17 - source lib.sh 17 + lib_dir=$(dirname "$0") 18 + source "$lib_dir"/../../../net/forwarding/lib.sh 18 19 19 20 traffic_test() 20 21 {
+4 -3
tools/testing/selftests/net/forwarding/ethtool_rmon.sh tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh
··· 7 7 " 8 8 9 9 NUM_NETIFS=2 10 - source lib.sh 10 + lib_dir=$(dirname "$0") 11 + source "$lib_dir"/../../../net/forwarding/lib.sh 11 12 12 13 ETH_FCS_LEN=4 13 14 ETH_HLEN=$((6+6+2)) ··· 79 78 80 79 for if in $iface $neigh; do 81 80 if ! ensure_mtu $if ${bucket[0]}; then 82 - log_test_skip "$if does not support the required MTU for $step" 81 + log_test_xfail "$if does not support the required MTU for $step" 83 82 return 84 83 fi 85 84 done ··· 94 93 jq -r ".[0].rmon[\"${set}-pktsNtoM\"][]|[.low, .high]|@tsv" 2>/dev/null) 95 94 96 95 if [ $nbuckets -eq 0 ]; then 97 - log_test_skip "$iface does not support $set histogram counters" 96 + log_test_xfail "$iface does not support $set histogram counters" 98 97 return 99 98 fi 100 99 }
+15 -38
tools/testing/selftests/net/forwarding/forwarding.config.sample
··· 3 3 4 4 ############################################################################## 5 5 # Topology description. p1 looped back to p2, p3 to p4 and so on. 6 - declare -A NETIFS 7 6 8 - NETIFS[p1]=veth0 9 - NETIFS[p2]=veth1 10 - NETIFS[p3]=veth2 11 - NETIFS[p4]=veth3 12 - NETIFS[p5]=veth4 13 - NETIFS[p6]=veth5 14 - NETIFS[p7]=veth6 15 - NETIFS[p8]=veth7 16 - NETIFS[p9]=veth8 17 - NETIFS[p10]=veth9 7 + NETIFS=( 8 + [p1]=veth0 9 + [p2]=veth1 10 + [p3]=veth2 11 + [p4]=veth3 12 + [p5]=veth4 13 + [p6]=veth5 14 + [p7]=veth6 15 + [p8]=veth7 16 + [p9]=veth8 17 + [p10]=veth9 18 + ) 18 19 19 20 # Port that does not have a cable connected. 20 21 NETIF_NO_CABLE=eth8 21 22 22 23 ############################################################################## 23 - # Defines 24 + # In addition to the topology-related variables, it is also possible to override 25 + # in this file other variables that net/lib.sh, net/forwarding/lib.sh or other 26 + # libraries or selftests use. E.g.: 24 27 25 - # IPv4 ping utility name 26 - PING=ping 27 - # IPv6 ping utility name. Some distributions use 'ping' for IPv6. 28 28 PING6=ping6 29 - # Packet generator. Some distributions use 'mz'. 30 29 MZ=mausezahn 31 - # mausezahn delay between transmissions in microseconds. 32 - MZ_DELAY=0 33 - # Time to wait after interfaces participating in the test are all UP 34 30 WAIT_TIME=5 35 - # Whether to pause on failure or not. 36 - PAUSE_ON_FAIL=no 37 - # Whether to pause on cleanup or not. 38 - PAUSE_ON_CLEANUP=no 39 - # Type of network interface to create 40 - NETIF_TYPE=veth 41 - # Whether to create virtual interfaces (veth) or not 42 - NETIF_CREATE=yes 43 - # Timeout (in seconds) before ping exits regardless of how many packets have 44 - # been sent or received 45 - PING_TIMEOUT=5 46 - # Minimum ageing_time (in centiseconds) supported by hardware 47 - LOW_AGEING_TIME=1000 48 - # Flag for tc match, supposed to be skip_sw/skip_hw which means do not process 49 - # filter by software/hardware 50 - TC_FLAG=skip_hw 51 - # IPv6 traceroute utility name. 52 - TROUTE6=traceroute6 53 -
+6 -13
tools/testing/selftests/net/forwarding/hw_stats_l3.sh tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh
··· 48 48 test_double_enable 49 49 " 50 50 NUM_NETIFS=4 51 - source lib.sh 51 + lib_dir=$(dirname "$0") 52 + source "$lib_dir"/../../../net/forwarding/lib.sh 52 53 53 54 h1_create() 54 55 { ··· 325 324 326 325 used=$(ip -j stats show dev $rp1.200 group offload subgroup hw_stats_info | 327 326 jq '.[].info.l3_stats.used') 328 - kind=$(ip -j -d link show dev $rp1 | 329 - jq -r '.[].linkinfo.info_kind') 330 - if [[ $used != true ]]; then 331 - if [[ $kind == veth ]]; then 332 - log_test_skip "l3_stats not offloaded on veth interface" 333 - EXIT_STATUS=$ksft_skip 334 - else 335 - RET=1 log_test "l3_stats not offloaded" 336 - fi 337 - else 338 - tests_run 339 - fi 327 + [[ $used = true ]] 328 + check_err $? "hw_stats_info.used=$used" 329 + log_test "l3_stats offloaded" 330 + tests_run 340 331 341 332 exit $EXIT_STATUS
+3 -4
tools/testing/selftests/net/forwarding/hw_stats_l3_gre.sh tools/testing/selftests/drivers/net/hw/hw_stats_l3_gre.sh
··· 12 12 test_stats_tx 13 13 " 14 14 NUM_NETIFS=6 15 - source lib.sh 16 - source ipip_lib.sh 15 + lib_dir=$(dirname "$0") 16 + source "$lib_dir"/../../../net/forwarding/lib.sh 17 + source "$lib_dir"/../../../net/forwarding/ipip_lib.sh 17 18 18 19 setup_prepare() 19 20 { ··· 99 98 { 100 99 test_stats g2a rx 101 100 } 102 - 103 - skip_on_veth 104 101 105 102 trap cleanup EXIT 106 103
-1
tools/testing/selftests/net/forwarding/ipip_lib.sh
··· 141 141 # | $h2 + | 142 142 # | 192.0.2.18/28 | 143 143 # +---------------------------+ 144 - source lib.sh 145 144 146 145 h1_create() 147 146 {
+194 -61
tools/testing/selftests/net/forwarding/lib.sh
··· 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 4 ############################################################################## 5 + # Topology description. p1 looped back to p2, p3 to p4 and so on. 6 + 7 + declare -A NETIFS=( 8 + [p1]=veth0 9 + [p2]=veth1 10 + [p3]=veth2 11 + [p4]=veth3 12 + [p5]=veth4 13 + [p6]=veth5 14 + [p7]=veth6 15 + [p8]=veth7 16 + [p9]=veth8 17 + [p10]=veth9 18 + ) 19 + 20 + # Port that does not have a cable connected. 21 + : "${NETIF_NO_CABLE:=eth8}" 22 + 23 + ############################################################################## 5 24 # Defines 6 25 7 - # Can be overridden by the configuration file. 8 - PING=${PING:=ping} 9 - PING6=${PING6:=ping6} 10 - MZ=${MZ:=mausezahn} 11 - MZ_DELAY=${MZ_DELAY:=0} 12 - ARPING=${ARPING:=arping} 13 - TEAMD=${TEAMD:=teamd} 14 - WAIT_TIME=${WAIT_TIME:=5} 15 - PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} 16 - PAUSE_ON_CLEANUP=${PAUSE_ON_CLEANUP:=no} 17 - NETIF_TYPE=${NETIF_TYPE:=veth} 18 - NETIF_CREATE=${NETIF_CREATE:=yes} 19 - MCD=${MCD:=smcrouted} 20 - MC_CLI=${MC_CLI:=smcroutectl} 21 - PING_COUNT=${PING_COUNT:=10} 22 - PING_TIMEOUT=${PING_TIMEOUT:=5} 23 - WAIT_TIMEOUT=${WAIT_TIMEOUT:=20} 24 - INTERFACE_TIMEOUT=${INTERFACE_TIMEOUT:=600} 25 - LOW_AGEING_TIME=${LOW_AGEING_TIME:=1000} 26 - REQUIRE_JQ=${REQUIRE_JQ:=yes} 27 - REQUIRE_MZ=${REQUIRE_MZ:=yes} 28 - REQUIRE_MTOOLS=${REQUIRE_MTOOLS:=no} 29 - STABLE_MAC_ADDRS=${STABLE_MAC_ADDRS:=no} 30 - TCPDUMP_EXTRA_FLAGS=${TCPDUMP_EXTRA_FLAGS:=} 31 - TROUTE6=${TROUTE6:=traceroute6} 26 + # Networking utilities. 27 + : "${PING:=ping}" 28 + : "${PING6:=ping6}" # Some distros just use ping. 29 + : "${ARPING:=arping}" 30 + : "${TROUTE6:=traceroute6}" 31 + 32 + # Packet generator. 33 + : "${MZ:=mausezahn}" # Some distributions use 'mz'. 34 + : "${MZ_DELAY:=0}" 35 + 36 + # Host configuration tools. 37 + : "${TEAMD:=teamd}" 38 + : "${MCD:=smcrouted}" 39 + : "${MC_CLI:=smcroutectl}" 40 + 41 + # Constants for netdevice bring-up: 42 + # Default time in seconds to wait for an interface to come up before giving up 43 + # and bailing out. Used during initial setup. 44 + : "${INTERFACE_TIMEOUT:=600}" 45 + # Like INTERFACE_TIMEOUT, but default for ad-hoc waiting in testing scripts. 46 + : "${WAIT_TIMEOUT:=20}" 47 + # Time to wait after interfaces participating in the test are all UP. 48 + : "${WAIT_TIME:=5}" 49 + 50 + # Whether to pause on, respectively, after a failure and before cleanup. 51 + : "${PAUSE_ON_FAIL:=no}" 52 + : "${PAUSE_ON_CLEANUP:=no}" 53 + 54 + # Whether to create virtual interfaces, and what netdevice type they should be. 55 + : "${NETIF_CREATE:=yes}" 56 + : "${NETIF_TYPE:=veth}" 57 + 58 + # Constants for ping tests: 59 + # How many packets should be sent. 60 + : "${PING_COUNT:=10}" 61 + # Timeout (in seconds) before ping exits regardless of how many packets have 62 + # been sent or received 63 + : "${PING_TIMEOUT:=5}" 64 + 65 + # Minimum ageing_time (in centiseconds) supported by hardware 66 + : "${LOW_AGEING_TIME:=1000}" 67 + 68 + # Whether to check for availability of certain tools. 69 + : "${REQUIRE_JQ:=yes}" 70 + : "${REQUIRE_MZ:=yes}" 71 + : "${REQUIRE_MTOOLS:=no}" 72 + 73 + # Whether to override MAC addresses on interfaces participating in the test. 74 + : "${STABLE_MAC_ADDRS:=no}" 75 + 76 + # Flags for tcpdump 77 + : "${TCPDUMP_EXTRA_FLAGS:=}" 78 + 79 + # Flags for TC filters. 80 + : "${TC_FLAG:=skip_hw}" 81 + 82 + # Whether the machine is "slow" -- i.e. might be incapable of running tests 83 + # involving heavy traffic. This might be the case on a debug kernel, a VM, or 84 + # e.g. a low-power board. 85 + : "${KSFT_MACHINE_SLOW:=no}" 32 86 33 87 net_forwarding_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") 34 88 ··· 259 205 fi 260 206 } 261 207 262 - skip_on_veth() 263 - { 264 - local kind=$(ip -j -d link show dev ${NETIFS[p1]} | 265 - jq -r '.[].linkinfo.info_kind') 266 - 267 - if [[ $kind == veth ]]; then 268 - echo "SKIP: Test cannot be run with veth pairs" 269 - exit $ksft_skip 270 - fi 271 - } 272 - 273 208 if [[ "$(id -u)" -ne 0 ]]; then 274 209 echo "SKIP: need root privileges" 275 210 exit $ksft_skip ··· 401 358 # Per-test return value. Clear at the beginning of each test. 402 359 RET=0 403 360 361 + ret_set_ksft_status() 362 + { 363 + local ksft_status=$1; shift 364 + local msg=$1; shift 365 + 366 + RET=$(ksft_status_merge $RET $ksft_status) 367 + if (( $? )); then 368 + retmsg=$msg 369 + fi 370 + } 371 + 372 + # Whether FAILs should be interpreted as XFAILs. Internal. 373 + FAIL_TO_XFAIL= 374 + 404 375 check_err() 405 376 { 406 377 local err=$1 407 378 local msg=$2 408 379 409 - if [[ $RET -eq 0 && $err -ne 0 ]]; then 410 - RET=$err 411 - retmsg=$msg 380 + if ((err)); then 381 + if [[ $FAIL_TO_XFAIL = yes ]]; then 382 + ret_set_ksft_status $ksft_xfail "$msg" 383 + else 384 + ret_set_ksft_status $ksft_fail "$msg" 385 + fi 412 386 fi 413 387 } 414 388 ··· 434 374 local err=$1 435 375 local msg=$2 436 376 437 - if [[ $RET -eq 0 && $err -eq 0 ]]; then 438 - RET=1 439 - retmsg=$msg 440 - fi 377 + check_err $((!err)) "$msg" 441 378 } 442 379 443 380 check_err_fail() ··· 450 393 fi 451 394 } 452 395 396 + xfail_on_slow() 397 + { 398 + if [[ $KSFT_MACHINE_SLOW = yes ]]; then 399 + FAIL_TO_XFAIL=yes "$@" 400 + else 401 + "$@" 402 + fi 403 + } 404 + 405 + xfail_on_veth() 406 + { 407 + local dev=$1; shift 408 + local kind 409 + 410 + kind=$(ip -j -d link show dev $dev | 411 + jq -r '.[].linkinfo.info_kind') 412 + if [[ $kind = veth ]]; then 413 + FAIL_TO_XFAIL=yes "$@" 414 + else 415 + "$@" 416 + fi 417 + } 418 + 419 + log_test_result() 420 + { 421 + local test_name=$1; shift 422 + local opt_str=$1; shift 423 + local result=$1; shift 424 + local retmsg=$1; shift 425 + 426 + printf "TEST: %-60s [%s]\n" "$test_name $opt_str" "$result" 427 + if [[ $retmsg ]]; then 428 + printf "\t%s\n" "$retmsg" 429 + fi 430 + } 431 + 432 + pause_on_fail() 433 + { 434 + if [[ $PAUSE_ON_FAIL == yes ]]; then 435 + echo "Hit enter to continue, 'q' to quit" 436 + read a 437 + [[ $a == q ]] && exit 1 438 + fi 439 + } 440 + 441 + handle_test_result_pass() 442 + { 443 + local test_name=$1; shift 444 + local opt_str=$1; shift 445 + 446 + log_test_result "$test_name" "$opt_str" " OK " 447 + } 448 + 449 + handle_test_result_fail() 450 + { 451 + local test_name=$1; shift 452 + local opt_str=$1; shift 453 + 454 + log_test_result "$test_name" "$opt_str" FAIL "$retmsg" 455 + pause_on_fail 456 + } 457 + 458 + handle_test_result_xfail() 459 + { 460 + local test_name=$1; shift 461 + local opt_str=$1; shift 462 + 463 + log_test_result "$test_name" "$opt_str" XFAIL "$retmsg" 464 + pause_on_fail 465 + } 466 + 467 + handle_test_result_skip() 468 + { 469 + local test_name=$1; shift 470 + local opt_str=$1; shift 471 + 472 + log_test_result "$test_name" "$opt_str" SKIP "$retmsg" 473 + } 474 + 453 475 log_test() 454 476 { 455 477 local test_name=$1 ··· 538 402 opt_str="($opt_str)" 539 403 fi 540 404 541 - if [[ $RET -ne 0 ]]; then 542 - EXIT_STATUS=1 543 - printf "TEST: %-60s [FAIL]\n" "$test_name $opt_str" 544 - if [[ ! -z "$retmsg" ]]; then 545 - printf "\t%s\n" "$retmsg" 546 - fi 547 - if [ "${PAUSE_ON_FAIL}" = "yes" ]; then 548 - echo "Hit enter to continue, 'q' to quit" 549 - read a 550 - [ "$a" = "q" ] && exit 1 551 - fi 552 - return 1 405 + if ((RET == ksft_pass)); then 406 + handle_test_result_pass "$test_name" "$opt_str" 407 + elif ((RET == ksft_xfail)); then 408 + handle_test_result_xfail "$test_name" "$opt_str" 409 + elif ((RET == ksft_skip)); then 410 + handle_test_result_skip "$test_name" "$opt_str" 411 + else 412 + handle_test_result_fail "$test_name" "$opt_str" 553 413 fi 554 414 555 - printf "TEST: %-60s [ OK ]\n" "$test_name $opt_str" 556 - return 0 415 + EXIT_STATUS=$(ksft_exit_status_merge $EXIT_STATUS $RET) 416 + return $RET 557 417 } 558 418 559 419 log_test_skip() 560 420 { 561 - local test_name=$1 562 - local opt_str=$2 421 + RET=$ksft_skip retmsg= log_test "$@" 422 + } 563 423 564 - printf "TEST: %-60s [SKIP]\n" "$test_name $opt_str" 565 - return 0 424 + log_test_xfail() 425 + { 426 + RET=$ksft_xfail retmsg= log_test "$@" 566 427 } 567 428 568 429 log_info()
+208
tools/testing/selftests/net/forwarding/lib_sh_test.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # This tests the operation of lib.sh itself. 5 + 6 + ALL_TESTS=" 7 + test_ret 8 + test_exit_status 9 + " 10 + NUM_NETIFS=0 11 + source lib.sh 12 + 13 + # Simulated checks. 14 + 15 + do_test() 16 + { 17 + local msg=$1; shift 18 + 19 + "$@" 20 + check_err $? "$msg" 21 + } 22 + 23 + tpass() 24 + { 25 + do_test "tpass" true 26 + } 27 + 28 + tfail() 29 + { 30 + do_test "tfail" false 31 + } 32 + 33 + txfail() 34 + { 35 + FAIL_TO_XFAIL=yes do_test "txfail" false 36 + } 37 + 38 + # Simulated tests. 39 + 40 + pass() 41 + { 42 + RET=0 43 + do_test "true" true 44 + log_test "true" 45 + } 46 + 47 + fail() 48 + { 49 + RET=0 50 + do_test "false" false 51 + log_test "false" 52 + } 53 + 54 + xfail() 55 + { 56 + RET=0 57 + FAIL_TO_XFAIL=yes do_test "xfalse" false 58 + log_test "xfalse" 59 + } 60 + 61 + skip() 62 + { 63 + RET=0 64 + log_test_skip "skip" 65 + } 66 + 67 + slow_xfail() 68 + { 69 + RET=0 70 + xfail_on_slow do_test "slow_false" false 71 + log_test "slow_false" 72 + } 73 + 74 + # lib.sh tests. 75 + 76 + ret_tests_run() 77 + { 78 + local t 79 + 80 + RET=0 81 + retmsg= 82 + for t in "$@"; do 83 + $t 84 + done 85 + echo "$retmsg" 86 + return $RET 87 + } 88 + 89 + ret_subtest() 90 + { 91 + local expect_ret=$1; shift 92 + local expect_retmsg=$1; shift 93 + local -a tests=( "$@" ) 94 + 95 + local status_names=(pass fail xfail xpass skip) 96 + local ret 97 + local out 98 + 99 + RET=0 100 + 101 + # Run this in a subshell, so that our environment is intact. 102 + out=$(ret_tests_run "${tests[@]}") 103 + ret=$? 104 + 105 + (( ret == expect_ret )) 106 + check_err $? "RET=$ret expected $expect_ret" 107 + 108 + [[ $out == $expect_retmsg ]] 109 + check_err $? "retmsg=$out expected $expect_retmsg" 110 + 111 + log_test "RET $(echo ${tests[@]}) -> ${status_names[$ret]}" 112 + } 113 + 114 + test_ret() 115 + { 116 + ret_subtest $ksft_pass "" 117 + 118 + ret_subtest $ksft_pass "" tpass 119 + ret_subtest $ksft_fail "tfail" tfail 120 + ret_subtest $ksft_xfail "txfail" txfail 121 + 122 + ret_subtest $ksft_pass "" tpass tpass 123 + ret_subtest $ksft_fail "tfail" tpass tfail 124 + ret_subtest $ksft_xfail "txfail" tpass txfail 125 + 126 + ret_subtest $ksft_fail "tfail" tfail tpass 127 + ret_subtest $ksft_xfail "txfail" txfail tpass 128 + 129 + ret_subtest $ksft_fail "tfail" tfail tfail 130 + ret_subtest $ksft_fail "tfail" tfail txfail 131 + 132 + ret_subtest $ksft_fail "tfail" txfail tfail 133 + 134 + ret_subtest $ksft_xfail "txfail" txfail txfail 135 + } 136 + 137 + exit_status_tests_run() 138 + { 139 + EXIT_STATUS=0 140 + tests_run > /dev/null 141 + return $EXIT_STATUS 142 + } 143 + 144 + exit_status_subtest() 145 + { 146 + local expect_exit_status=$1; shift 147 + local tests=$1; shift 148 + local what=$1; shift 149 + 150 + local status_names=(pass fail xfail xpass skip) 151 + local exit_status 152 + local out 153 + 154 + RET=0 155 + 156 + # Run this in a subshell, so that our environment is intact. 157 + out=$(TESTS="$tests" exit_status_tests_run) 158 + exit_status=$? 159 + 160 + (( exit_status == expect_exit_status )) 161 + check_err $? "EXIT_STATUS=$exit_status, expected $expect_exit_status" 162 + 163 + log_test "EXIT_STATUS $tests$what -> ${status_names[$exit_status]}" 164 + } 165 + 166 + test_exit_status() 167 + { 168 + exit_status_subtest $ksft_pass ":" 169 + 170 + exit_status_subtest $ksft_pass "pass" 171 + exit_status_subtest $ksft_fail "fail" 172 + exit_status_subtest $ksft_pass "xfail" 173 + exit_status_subtest $ksft_skip "skip" 174 + 175 + exit_status_subtest $ksft_pass "pass pass" 176 + exit_status_subtest $ksft_fail "pass fail" 177 + exit_status_subtest $ksft_pass "pass xfail" 178 + exit_status_subtest $ksft_skip "pass skip" 179 + 180 + exit_status_subtest $ksft_fail "fail pass" 181 + exit_status_subtest $ksft_pass "xfail pass" 182 + exit_status_subtest $ksft_skip "skip pass" 183 + 184 + exit_status_subtest $ksft_fail "fail fail" 185 + exit_status_subtest $ksft_fail "fail xfail" 186 + exit_status_subtest $ksft_fail "fail skip" 187 + 188 + exit_status_subtest $ksft_fail "xfail fail" 189 + exit_status_subtest $ksft_fail "skip fail" 190 + 191 + exit_status_subtest $ksft_pass "xfail xfail" 192 + exit_status_subtest $ksft_skip "xfail skip" 193 + exit_status_subtest $ksft_skip "skip xfail" 194 + 195 + exit_status_subtest $ksft_skip "skip skip" 196 + 197 + KSFT_MACHINE_SLOW=yes \ 198 + exit_status_subtest $ksft_pass "slow_xfail" ": slow" 199 + 200 + KSFT_MACHINE_SLOW=no \ 201 + exit_status_subtest $ksft_fail "slow_xfail" ": fast" 202 + } 203 + 204 + trap pre_cleanup EXIT 205 + 206 + tests_run 207 + 208 + exit $EXIT_STATUS
+3 -2
tools/testing/selftests/net/forwarding/loopback.sh tools/testing/selftests/drivers/net/hw/loopback.sh
··· 6 6 7 7 ALL_TESTS="loopback_test" 8 8 NUM_NETIFS=2 9 - source tc_common.sh 10 - source lib.sh 9 + lib_dir=$(dirname "$0") 10 + source "$lib_dir"/../../../net/forwarding/tc_common.sh 11 + source "$lib_dir"/../../../net/forwarding/lib.sh 11 12 12 13 h1_create() 13 14 {
+1 -11
tools/testing/selftests/net/forwarding/router_mpath_nh_lib.sh
··· 56 56 local group_id=$1; shift 57 57 local mz="$@" 58 58 59 - local used 60 - 61 59 nh_stats_do_test "$what" "$nh1_id" "$nh2_id" "$group_id" \ 62 60 nh_stats_get "${mz[@]}" 63 61 64 - used=$(ip -s -j -d nexthop show id $group_id | 65 - jq '.[].hw_stats.used') 66 - kind=$(ip -j -d link show dev $rp11 | 67 - jq -r '.[].linkinfo.info_kind') 68 - if [[ $used == true ]]; then 62 + xfail_on_veth $rp11 \ 69 63 nh_stats_do_test "HW $what" "$nh1_id" "$nh2_id" "$group_id" \ 70 64 nh_stats_get_hw "${mz[@]}" 71 - elif [[ $kind == veth ]]; then 72 - log_test_skip "HW stats not offloaded on veth topology" 73 - fi 74 65 } 75 66 76 67 nh_stats_test_dispatch() ··· 74 83 local mz="$@" 75 84 76 85 local enabled 77 - local kind 78 86 79 87 if ! ip nexthop help 2>&1 | grep -q hw_stats; then 80 88 log_test_skip "NH stats test: ip doesn't support HW stats"
+11 -8
tools/testing/selftests/net/forwarding/sch_ets_tests.sh
··· 199 199 ets_test_strict() 200 200 { 201 201 ets_set_strict 202 - ets_dwrr_test_01 203 - ets_dwrr_test_12 202 + xfail_on_slow ets_dwrr_test_01 203 + xfail_on_slow ets_dwrr_test_12 204 204 } 205 205 206 206 ets_test_mixed() 207 207 { 208 208 ets_set_mixed 209 - ets_dwrr_test_01 210 - ets_dwrr_test_12 209 + xfail_on_slow ets_dwrr_test_01 210 + xfail_on_slow ets_dwrr_test_12 211 211 } 212 212 213 213 ets_test_dwrr() 214 214 { 215 215 ets_set_dwrr_uniform 216 - ets_dwrr_test_012 216 + xfail_on_slow ets_dwrr_test_012 217 + 217 218 ets_set_dwrr_varying 218 - ets_dwrr_test_012 219 + xfail_on_slow ets_dwrr_test_012 220 + 219 221 ets_change_quantum 220 - ets_dwrr_test_012 222 + xfail_on_slow ets_dwrr_test_012 223 + 221 224 ets_set_dwrr_two_bands 222 - ets_dwrr_test_01 225 + xfail_on_slow ets_dwrr_test_01 223 226 }
+5 -5
tools/testing/selftests/net/forwarding/sch_red.sh
··· 451 451 ecn_test() 452 452 { 453 453 install_qdisc ecn 454 - do_ecn_test $BACKLOG 454 + xfail_on_slow do_ecn_test $BACKLOG 455 455 uninstall_qdisc 456 456 } 457 457 458 458 ecn_nodrop_test() 459 459 { 460 460 install_qdisc ecn nodrop 461 - do_ecn_nodrop_test $BACKLOG 461 + xfail_on_slow do_ecn_nodrop_test $BACKLOG 462 462 uninstall_qdisc 463 463 } 464 464 465 465 red_test() 466 466 { 467 467 install_qdisc 468 - do_red_test $BACKLOG 468 + xfail_on_slow do_red_test $BACKLOG 469 469 uninstall_qdisc 470 470 } 471 471 472 472 red_qevent_test() 473 473 { 474 474 install_qdisc qevent early_drop block 10 475 - do_red_qevent_test $BACKLOG 475 + xfail_on_slow do_red_qevent_test $BACKLOG 476 476 uninstall_qdisc 477 477 } 478 478 479 479 ecn_qevent_test() 480 480 { 481 481 install_qdisc ecn qevent mark block 10 482 - do_ecn_qevent_test $BACKLOG 482 + xfail_on_slow do_ecn_qevent_test $BACKLOG 483 483 uninstall_qdisc 484 484 } 485 485
+1 -1
tools/testing/selftests/net/forwarding/sch_tbf_core.sh
··· 227 227 local nr=$(rate $t2 $t3 10) 228 228 local nr_pct=$((100 * (nr - er) / er)) 229 229 ((-5 <= nr_pct && nr_pct <= 5)) 230 - check_err $? "Expected rate $(humanize $er), got $(humanize $nr), which is $nr_pct% off. Required accuracy is +-5%." 230 + xfail_on_slow check_err $? "Expected rate $(humanize $er), got $(humanize $nr), which is $nr_pct% off. Required accuracy is +-5%." 231 231 232 232 log_test "TC $((vlan - 10)): TBF rate ${mbit}Mbit" 233 233 }
+1 -1
tools/testing/selftests/net/forwarding/tc_common.sh
··· 4 4 CHECK_TC="yes" 5 5 6 6 # Can be overridden by the configuration file. See lib.sh 7 - TC_HIT_TIMEOUT=${TC_HIT_TIMEOUT:=1000} # ms 7 + : "${TC_HIT_TIMEOUT:=1000}" # ms 8 8 9 9 tc_check_packets() 10 10 {
-2
tools/testing/selftests/net/forwarding/tc_tunnel_key.sh
··· 1 1 #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 - # Kselftest framework requirement - SKIP code is 4. 4 - ksft_skip=4 5 3 6 4 ALL_TESTS="tunnel_key_nofrag_test" 7 5
+46 -2
tools/testing/selftests/net/lib.sh
··· 4 4 ############################################################################## 5 5 # Defines 6 6 7 - WAIT_TIMEOUT=${WAIT_TIMEOUT:=20} 7 + : "${WAIT_TIMEOUT:=20}" 8 + 8 9 BUSYWAIT_TIMEOUT=$((WAIT_TIMEOUT * 1000)) # ms 9 10 10 - # Kselftest framework requirement - SKIP code is 4. 11 + # Kselftest framework constants. 12 + ksft_pass=0 13 + ksft_fail=1 14 + ksft_xfail=2 11 15 ksft_skip=4 16 + 12 17 # namespace list created by setup_ns 13 18 NS_LIST="" 14 19 15 20 ############################################################################## 16 21 # Helpers 22 + 23 + __ksft_status_merge() 24 + { 25 + local a=$1; shift 26 + local b=$1; shift 27 + local -A weights 28 + local weight=0 29 + 30 + for i in "$@"; do 31 + weights[$i]=$((weight++)) 32 + done 33 + 34 + if [[ ${weights[$a]} > ${weights[$b]} ]]; then 35 + echo "$a" 36 + return 0 37 + else 38 + echo "$b" 39 + return 1 40 + fi 41 + } 42 + 43 + ksft_status_merge() 44 + { 45 + local a=$1; shift 46 + local b=$1; shift 47 + 48 + __ksft_status_merge "$a" "$b" \ 49 + $ksft_pass $ksft_xfail $ksft_skip $ksft_fail 50 + } 51 + 52 + ksft_exit_status_merge() 53 + { 54 + local a=$1; shift 55 + local b=$1; shift 56 + 57 + __ksft_status_merge "$a" "$b" \ 58 + $ksft_xfail $ksft_pass $ksft_skip $ksft_fail 59 + } 60 + 17 61 busywait() 18 62 { 19 63 local timeout=$1; shift