This patch renames run.sh to rds_run.sh, and then adds two wrapper scripts, rds_rdma_run.sh and rds_tcp_run.sh which run rds_run.sh with the corresponding transport option, rdma or tcp respectively. These wrapper scripts are added to TEST_PROGS in place of run.sh so that they run and report as a separate test results on the netdev CI dashboard. Listing the wrappers in TEST_PROGS also gives the framework a self-describing name for each test. The underlying rds_run.sh remains directly usable with the full set of options. Suggested-by: Matthieu Baerts Signed-off-by: Allison Henderson --- tools/testing/selftests/net/rds/Makefile | 6 +++++- tools/testing/selftests/net/rds/README.txt | 13 +++++++++---- tools/testing/selftests/net/rds/rds_rdma_run.sh | 11 +++++++++++ .../selftests/net/rds/{run.sh => rds_run.sh} | 4 ++-- tools/testing/selftests/net/rds/rds_tcp_run.sh | 11 +++++++++++ 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/net/rds/Makefile b/tools/testing/selftests/net/rds/Makefile index fe363be8e3586..b176e637fc55b 100644 --- a/tools/testing/selftests/net/rds/Makefile +++ b/tools/testing/selftests/net/rds/Makefile @@ -3,9 +3,13 @@ all: @echo mk_build_dir="$(shell pwd)" > include.sh -TEST_PROGS := run.sh +TEST_PROGS := \ + rds_tcp_run.sh \ + rds_rdma_run.sh \ +# end of TEST_PROGS TEST_FILES := \ + rds_run.sh \ include.sh \ settings \ test.py \ diff --git a/tools/testing/selftests/net/rds/README.txt b/tools/testing/selftests/net/rds/README.txt index bac6f15a80d52..2296568c39444 100644 --- a/tools/testing/selftests/net/rds/README.txt +++ b/tools/testing/selftests/net/rds/README.txt @@ -13,10 +13,15 @@ with the necessary gcov options; pass -r to also enable the kernel configs required for the RDMA transport. The kernel may optionally be configured to omit the coverage report as well. +The test framework runs the rds_tcp_run.sh and rds_rdma_run.sh wrappers, +which invoke rds_run.sh with the matching transport so that the tcp and +rdma results are reported independently. rds_run.sh may also be run +directly with the options below. + USAGE: - run.sh [-d logdir] [-l packet_loss] [-c packet_corruption] - [-u packet_duplicate] [-t timeout] - [-T tcp|rdma|tcp,rdma] + rds_run.sh [-d logdir] [-l packet_loss] [-c packet_corruption] + [-u packet_duplicate] [-t timeout] + [-T tcp|rdma|tcp,rdma] OPTIONS: -d Log directory. If set, logs will be stored in the @@ -73,5 +78,5 @@ EXAMPLE: "export PYTHONPATH=tools/testing/selftests/net/; \ export SUDO_USER=example_user; \ export RDS_LOG_DIR=tools/testing/selftests/net/rds/rds_logs; \ - tools/testing/selftests/net/rds/run.sh -T tcp,rdma" + tools/testing/selftests/net/rds/rds_run.sh -T tcp,rdma" diff --git a/tools/testing/selftests/net/rds/rds_rdma_run.sh b/tools/testing/selftests/net/rds/rds_rdma_run.sh new file mode 100755 index 0000000000000..eddd389431573 --- /dev/null +++ b/tools/testing/selftests/net/rds/rds_rdma_run.sh @@ -0,0 +1,11 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Runs the RDS selftest over the RDMA (RoCE/RXE) transport. +# +# This is a wrapper script for rds_run.sh to run and report results when using +# the -T rdma option +# +# Exits with the kselftest SKIP code if rds RDMA prerequisites are not met + +exec "$(dirname "$0")/rds_run.sh" -T rdma "$@" diff --git a/tools/testing/selftests/net/rds/run.sh b/tools/testing/selftests/net/rds/rds_run.sh similarity index 98% rename from tools/testing/selftests/net/rds/run.sh rename to tools/testing/selftests/net/rds/rds_run.sh index 07af2f927a2a7..ef16039be1ae5 100755 --- a/tools/testing/selftests/net/rds/run.sh +++ b/tools/testing/selftests/net/rds/rds_run.sh @@ -209,7 +209,7 @@ while getopts "d:l:c:u:t:T:" opt; do TRANSPORT=${OPTARG} ;; :) - echo "USAGE: run.sh [-d logdir] [-l packet_loss] [-c packet_corruption]" \ + echo "USAGE: rds_run.sh [-d logdir] [-l packet_loss] [-c packet_corruption]" \ "[-u packet_duplicate] [-t timeout] [-T tcp|rdma|tcp,rdma]" exit 1 ;; @@ -224,7 +224,7 @@ done IFS=',' read -ra transports <<< "$TRANSPORT" for t in "${transports[@]}"; do if [ "$t" != "tcp" ] && [ "$t" != "rdma" ]; then - echo "run.sh: unknown transport '$t' (expected tcp or rdma)" + echo "rds_run.sh: unknown transport '$t' (expected tcp or rdma)" exit 1 fi done diff --git a/tools/testing/selftests/net/rds/rds_tcp_run.sh b/tools/testing/selftests/net/rds/rds_tcp_run.sh new file mode 100755 index 0000000000000..fad4d047aac61 --- /dev/null +++ b/tools/testing/selftests/net/rds/rds_tcp_run.sh @@ -0,0 +1,11 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Runs the RDS selftest over the TCP transport. +# +# This is a wrapper script for rds_run.sh to run and report results when using +# the -T tcp option +# +# Exits with the kselftest SKIP code if rds TCP prerequisites are not met + +exec "$(dirname "$0")/rds_run.sh" -T tcp "$@" -- 2.25.1 The RDS selftests create AF_RDS sockets but never selects a transport, so the transport is chosen implicitly based on network topology when the socket is bound. If underlying connection establishment fails, RDS can fall back to another transport (e.g. loopback) and the test still passes, silently bypassing the intended datapath it is meant to exercise. Set SO_RDS_TRANSPORT to the proper RDS_TRANS_IB or RDS_TRANS_TCP before they are bound, so the test fails loudly if the intended transport is unavailable rather than passing on a different path. Signed-off-by: Allison Henderson --- tools/testing/selftests/net/rds/test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/testing/selftests/net/rds/test.py b/tools/testing/selftests/net/rds/test.py index 08f2a846a8ab5..9e4df01cb0d4b 100755 --- a/tools/testing/selftests/net/rds/test.py +++ b/tools/testing/selftests/net/rds/test.py @@ -59,6 +59,14 @@ rdma_addrs = [ OP_FLAG_TCP = 0x1 OP_FLAG_RDMA = 0x2 +# from include/uapi/linux/rds.h: SO_RDS_TRANSPORT pins a socket to a +# specific RDS transport so connection setup cannot silently fall back +# to another (e.g. loopback) transport. +SOL_RDS = 276 +SO_RDS_TRANSPORT = 8 +RDS_TRANS_TCP = 2 +RDS_TRANS_IB = 0 + signal_handler_label = "" tap_idx = 0 @@ -214,11 +222,21 @@ def snd_rcv_packets(env): netns_socket(netns_list[0], socket.AF_RDS, socket.SOCK_SEQPACKET), netns_socket(netns_list[1], socket.AF_RDS, socket.SOCK_SEQPACKET), ] + + # Pin the sockets to the TCP transport so it doesn't fail over to a + # different transport during this test + for s in sockets: + s.setsockopt(SOL_RDS, SO_RDS_TRANSPORT, RDS_TRANS_TCP) elif flags & OP_FLAG_RDMA: sockets = [ socket.socket(socket.AF_RDS, socket.SOCK_SEQPACKET), socket.socket(socket.AF_RDS, socket.SOCK_SEQPACKET), ] + + # Pin the sockets to the RDMA transport so it doesn't fail over to a + # different transport during this test + for s in sockets: + s.setsockopt(SOL_RDS, SO_RDS_TRANSPORT, RDS_TRANS_IB) else: raise RuntimeError(f"Invalid transport flag sets no transports: {flags}") -- 2.25.1 Commit 92cc6708f4a2 ("selftests: rds: config: disable modules") set CONFIG_MODULES=n since run.sh required this kconfig. But disabling modules also forces every =m option to =n rather than =y, which can silently drop unrelated features. This patch removes CONFIG_MODULES=n from the rds selftest config and updates the check_*conf_enabled() routines to accept a config as either built-in (=y) or modular (=m). A new probe_module() function is added to load the backing module when a component is set to be modular (=m). rds.ko itself is auto-loaded on socket creation, and rds_rdma.ko is auto-loaded when SO_RDS_TRANSPORT is set with RDS_TRANS_IB, but the TCP transport (rds_tcp.ko) is not auto-loaded on the bind path, so the backing modules are loaded explicitly here. Signed-off-by: Allison Henderson --- tools/testing/selftests/net/rds/config | 1 - tools/testing/selftests/net/rds/rds_run.sh | 59 ++++++++++++++-------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/net/rds/config b/tools/testing/selftests/net/rds/config index 3d62d0c750a80..97db7ecb892aa 100644 --- a/tools/testing/selftests/net/rds/config +++ b/tools/testing/selftests/net/rds/config @@ -1,4 +1,3 @@ -CONFIG_MODULES=n CONFIG_NET_NS=y CONFIG_NET_SCH_NETEM=y CONFIG_RDS=y diff --git a/tools/testing/selftests/net/rds/rds_run.sh b/tools/testing/selftests/net/rds/rds_run.sh index ef16039be1ae5..ff11cc7cc9773 100755 --- a/tools/testing/selftests/net/rds/rds_run.sh +++ b/tools/testing/selftests/net/rds/rds_run.sh @@ -93,38 +93,57 @@ check_gcov_conf() fi } +# Checks if a kconfig is enabled (set to =y or =m) +# $1: kconfig symbol to check +# $2: (optional) module name backing $1 +# Ex: check_conf_enabled CONFIG_RDS_TCP rds_tcp +# Modules for configs set to =m will be probed +# If omitted, only a built-in (=y) config is accepted. +# Returns on success. exits 4 on failure # Kselftest framework requirement - SKIP code is 4. check_conf_enabled() { - if ! grep -x "$1=y" "$kconfig" > /dev/null 2>&1; then - echo "selftests: [SKIP] This test requires $1 enabled" - echo "Please run tools/testing/selftests/net/rds/config.sh and rebuild the kernel" - exit 4 + if grep -x "$1=y" "$kconfig" > /dev/null 2>&1; then + return fi + if [ -n "${2:-}" ] && grep -x "$1=m" "$kconfig" > /dev/null 2>&1; then + probe_module "$2" + return + fi + echo "selftests: [SKIP] This test requires $1 enabled" + echo "Please run tools/testing/selftests/net/rds/config.sh and rebuild the kernel" + exit 4 } check_rdma_conf_enabled() { - if ! grep -x "$1=y" "$kconfig" > /dev/null 2>&1; then - echo "selftests: [SKIP] rdma transport requires $1 enabled" - echo "To enable, run " \ - "tools/testing/selftests/net/rds/config.sh -r and rebuild" - exit 4 + if grep -x "$1=y" "$kconfig" > /dev/null 2>&1; then + return + fi + if [ -n "${2:-}" ] && grep -x "$1=m" "$kconfig" > /dev/null 2>&1; then + probe_module "$2" + return fi + echo "selftests: [SKIP] rdma transport requires $1 enabled" + echo "To enable, run " \ + "tools/testing/selftests/net/rds/config.sh -r and rebuild" + exit 4 } -check_conf_disabled() { - if grep -x "$1=y" "$kconfig" > /dev/null 2>&1; then - echo "selftests: [SKIP] This test requires $1 disabled" - echo "Please run tools/testing/selftests/net/rds/config.sh and rebuild the kernel" +# Load the module backing a config that is built as a loadable module +# (=m). Built-in (=y) configs are already available and don't reach +# here. Exits with the SKIP code if a required module cannot be loaded. +probe_module() { + if ! modprobe -q "$1"; then + echo "selftests: [SKIP] could not load required module $1" exit 4 fi } + check_conf() { - check_conf_enabled CONFIG_NET_SCH_NETEM - check_conf_enabled CONFIG_VETH + check_conf_enabled CONFIG_NET_SCH_NETEM sch_netem + check_conf_enabled CONFIG_VETH veth check_conf_enabled CONFIG_NET_NS - check_conf_enabled CONFIG_RDS_TCP - check_conf_enabled CONFIG_RDS - check_conf_disabled CONFIG_MODULES + check_conf_enabled CONFIG_RDS_TCP rds_tcp + check_conf_enabled CONFIG_RDS rds } # Check kernel config and host environment for RDS-RDMA support. @@ -139,8 +158,8 @@ check_rdma_conf() # Kconfig will enforce CONFIG_INFINIBAND_* as dependencies # of CONFIG_RDMA_RXE - check_rdma_conf_enabled CONFIG_RDMA_RXE - check_rdma_conf_enabled CONFIG_RDS_RDMA + check_rdma_conf_enabled CONFIG_RDMA_RXE rdma_rxe + check_rdma_conf_enabled CONFIG_RDS_RDMA rds_rdma if ! which rdma > /dev/null 2>&1; then echo "selftests: [SKIP] rdma transport requires the 'rdma'" \ -- 2.25.1