Skip to content

Commit

Permalink
Merge branch 'selftests-drv-net-replace-the-rpath-helper-with-path-ob…
Browse files Browse the repository at this point in the history
…jects'

Jakub Kicinski says:

====================
selftests: drv-net: replace the rpath helper with Path objects

Trying to change the env.rpath() helper during the development
cycle was causing a lot of conflicts between net and net-next.
Let's get it converted now that the trees are converged.

v2: https://lore.kernel.org/20250306171158.1836674-1-kuba@kernel.org
====================

Link: https://patch.msgid.link/20250327222315.1098596-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Mar 31, 2025
2 parents 7220e8f + 88dec03 commit 5c60528
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 58 deletions.
2 changes: 1 addition & 1 deletion tools/testing/selftests/drivers/net/hds.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _get_hds_mode(cfg, netnl) -> str:


def _xdp_onoff(cfg):
prog = cfg.rpath("../../net/lib/xdp_dummy.bpf.o")
prog = cfg.net_lib_dir / "xdp_dummy.bpf.o"
ip("link set dev %s xdp obj %s sec xdp" %
(cfg.ifname, prog))
ip("link set dev %s xdp off" % cfg.ifname)
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/drivers/net/hw/csum.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def main() -> None:
with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
check_nic_features(cfg)

cfg.bin_local = cfg.rpath("../../../net/lib/csum")
cfg.bin_local = cfg.net_lib_dir / "csum"
cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)

cases = []
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/drivers/net/hw/irq.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def reconfig(cfg) -> None:
def check_reconfig_xdp(cfg) -> None:
def reconfig(cfg) -> None:
ip(f"link set dev %s xdp obj %s sec xdp" %
(cfg.ifname, cfg.rpath("xdp_dummy.bpf.o")))
(cfg.ifname, cfg.net_lib_dir / "xdp_dummy.bpf.o"))
ip(f"link set dev %s xdp off" % cfg.ifname)

_check_reconfig(cfg, reconfig)
Expand Down
13 changes: 0 additions & 13 deletions tools/testing/selftests/drivers/net/hw/xdp_dummy.bpf.c

This file was deleted.

21 changes: 8 additions & 13 deletions tools/testing/selftests/drivers/net/lib/py/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,17 @@
class NetDrvEnvBase:
"""
Base class for a NIC / host envirnoments
Attributes:
test_dir: Path to the source directory of the test
net_lib_dir: Path to the net/lib directory
"""
def __init__(self, src_path):
self.src_path = src_path
self.env = self._load_env_file()

def rpath(self, path):
"""
Get an absolute path to a file based on a path relative to the directory
containing the test which constructed env.
self.src_path = Path(src_path)
self.test_dir = self.src_path.parent.resolve()
self.net_lib_dir = (Path(__file__).parent / "../../../../net/lib").resolve()

For example, if the test.py is in the same directory as
a binary (built from helper.c), the test can use env.rpath("helper")
to get the absolute path to the binary
"""
src_dir = Path(self.src_path).parent.resolve()
return (src_dir / path).as_posix()
self.env = self._load_env_file()

def _load_env_file(self):
env = os.environ.copy()
Expand Down
15 changes: 5 additions & 10 deletions tools/testing/selftests/drivers/net/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def _set_offload_checksum(cfg, netnl, on) -> None:
return

def _set_xdp_generic_sb_on(cfg) -> None:
test_dir = os.path.dirname(os.path.realpath(__file__))
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
prog = cfg.net_lib_dir / "xdp_dummy.bpf.o"
cmd(f"ip link set dev {remote_ifname} mtu 1500", shell=True, host=cfg.remote)
cmd(f"ip link set dev {cfg.ifname} mtu 1500 xdpgeneric obj {prog} sec xdp", shell=True)
defer(cmd, f"ip link set dev {cfg.ifname} xdpgeneric off")
Expand All @@ -66,8 +65,7 @@ def _set_xdp_generic_sb_on(cfg) -> None:
time.sleep(10)

def _set_xdp_generic_mb_on(cfg) -> None:
test_dir = os.path.dirname(os.path.realpath(__file__))
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
prog = cfg.net_lib_dir / "xdp_dummy.bpf.o"
cmd(f"ip link set dev {remote_ifname} mtu 9000", shell=True, host=cfg.remote)
defer(ip, f"link set dev {remote_ifname} mtu 1500", host=cfg.remote)
ip("link set dev %s mtu 9000 xdpgeneric obj %s sec xdp.frags" % (cfg.ifname, prog))
Expand All @@ -77,8 +75,7 @@ def _set_xdp_generic_mb_on(cfg) -> None:
time.sleep(10)

def _set_xdp_native_sb_on(cfg) -> None:
test_dir = os.path.dirname(os.path.realpath(__file__))
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
prog = cfg.net_lib_dir / "xdp_dummy.bpf.o"
cmd(f"ip link set dev {remote_ifname} mtu 1500", shell=True, host=cfg.remote)
cmd(f"ip -j link set dev {cfg.ifname} mtu 1500 xdp obj {prog} sec xdp", shell=True)
defer(ip, f"link set dev {cfg.ifname} mtu 1500 xdp off")
Expand All @@ -95,8 +92,7 @@ def _set_xdp_native_sb_on(cfg) -> None:
time.sleep(10)

def _set_xdp_native_mb_on(cfg) -> None:
test_dir = os.path.dirname(os.path.realpath(__file__))
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
prog = cfg.net_lib_dir / "xdp_dummy.bpf.o"
cmd(f"ip link set dev {remote_ifname} mtu 9000", shell=True, host=cfg.remote)
defer(ip, f"link set dev {remote_ifname} mtu 1500", host=cfg.remote)
try:
Expand All @@ -109,8 +105,7 @@ def _set_xdp_native_mb_on(cfg) -> None:
time.sleep(10)

def _set_xdp_offload_on(cfg) -> None:
test_dir = os.path.dirname(os.path.realpath(__file__))
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
prog = cfg.net_lib_dir / "xdp_dummy.bpf.o"
cmd(f"ip link set dev {cfg.ifname} mtu 1500", shell=True)
try:
cmd(f"ip link set dev {cfg.ifname} xdpoffload obj {prog} sec xdp", shell=True)
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/drivers/net/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def nl_get_queues(cfg, nl, qtype='rx'):

def check_xsk(cfg, nl, xdp_queue_id=0) -> None:
# Probe for support
xdp = cmd(cfg.rpath("xdp_helper") + ' - -', fail=False)
xdp = cmd(f'{cfg.test_dir / "xdp_helper"} - -', fail=False)
if xdp.ret == 255:
raise KsftSkipEx('AF_XDP unsupported')
elif xdp.ret > 0:
raise KsftFailEx('unable to create AF_XDP socket')

with bkg(f'{cfg.rpath("xdp_helper")} {cfg.ifindex} {xdp_queue_id}',
with bkg(f'{cfg.test_dir / "xdp_helper"} {cfg.ifindex} {xdp_queue_id}',
ksft_wait=3):

rx = tx = False
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/net/udpgro_bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source net_helper.sh

readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"

BPF_FILE="xdp_dummy.bpf.o"
BPF_FILE="lib/xdp_dummy.bpf.o"

cleanup() {
local -r jobs="$(jobs -p)"
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/net/udpgro_frglist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source net_helper.sh

readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"

BPF_FILE="xdp_dummy.bpf.o"
BPF_FILE="lib/xdp_dummy.bpf.o"

cleanup() {
local -r jobs="$(jobs -p)"
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/net/udpgro_fwd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

source net_helper.sh

BPF_FILE="xdp_dummy.bpf.o"
BPF_FILE="lib/xdp_dummy.bpf.o"
readonly BASE="ns-$(mktemp -u XXXXXX)"
readonly SRC=2
readonly DST=1
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/net/veth.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0

BPF_FILE="xdp_dummy.bpf.o"
BPF_FILE="lib/xdp_dummy.bpf.o"
readonly STATS="$(mktemp -p /tmp ns-XXXXXX)"
readonly BASE=`basename $STATS`
readonly SRC=2
Expand Down
13 changes: 0 additions & 13 deletions tools/testing/selftests/net/xdp_dummy.bpf.c

This file was deleted.

0 comments on commit 5c60528

Please sign in to comment.