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

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

The single letter + "path" helpers do not have many fans (see Link).
Use a Path object with a better name. test_dir is the replacement
for rpath(), net_lib_dir is a new path of the $ksft/net/lib directory.

The Path() class overloads the "/" operator and can be cast to string
automatically, so to get a path to a file tests can do:

path = env.test_dir / "binary"

Link: https://lore.kernel.org/CA+FuTSemTNVZ5MxXkq8T9P=DYm=nSXcJnL7CJBPZNAT_9UFisQ@mail.gmail.com
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20250327222315.1098596-2-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+13 -18
+1 -1
tools/testing/selftests/drivers/net/hds.py
··· 20 20 21 21 22 22 def _xdp_onoff(cfg): 23 - prog = cfg.rpath("../../net/lib/xdp_dummy.bpf.o") 23 + prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" 24 24 ip("link set dev %s xdp obj %s sec xdp" % 25 25 (cfg.ifname, prog)) 26 26 ip("link set dev %s xdp off" % cfg.ifname)
+1 -1
tools/testing/selftests/drivers/net/hw/csum.py
··· 88 88 with NetDrvEpEnv(__file__, nsim_test=False) as cfg: 89 89 check_nic_features(cfg) 90 90 91 - cfg.bin_local = cfg.rpath("../../../net/lib/csum") 91 + cfg.bin_local = cfg.net_lib_dir / "csum" 92 92 cfg.bin_remote = cfg.remote.deploy(cfg.bin_local) 93 93 94 94 cases = []
+1 -1
tools/testing/selftests/drivers/net/hw/irq.py
··· 69 69 def check_reconfig_xdp(cfg) -> None: 70 70 def reconfig(cfg) -> None: 71 71 ip(f"link set dev %s xdp obj %s sec xdp" % 72 - (cfg.ifname, cfg.rpath("xdp_dummy.bpf.o"))) 72 + (cfg.ifname, cfg.test_dir / "xdp_dummy.bpf.o")) 73 73 ip(f"link set dev %s xdp off" % cfg.ifname) 74 74 75 75 _check_reconfig(cfg, reconfig)
+8 -13
tools/testing/selftests/drivers/net/lib/py/env.py
··· 13 13 class NetDrvEnvBase: 14 14 """ 15 15 Base class for a NIC / host envirnoments 16 + 17 + Attributes: 18 + test_dir: Path to the source directory of the test 19 + net_lib_dir: Path to the net/lib directory 16 20 """ 17 21 def __init__(self, src_path): 18 - self.src_path = src_path 22 + self.src_path = Path(src_path) 23 + self.test_dir = self.src_path.parent.resolve() 24 + self.net_lib_dir = (Path(__file__).parent / "../../../../net/lib").resolve() 25 + 19 26 self.env = self._load_env_file() 20 - 21 - def rpath(self, path): 22 - """ 23 - Get an absolute path to a file based on a path relative to the directory 24 - containing the test which constructed env. 25 - 26 - For example, if the test.py is in the same directory as 27 - a binary (built from helper.c), the test can use env.rpath("helper") 28 - to get the absolute path to the binary 29 - """ 30 - src_dir = Path(self.src_path).parent.resolve() 31 - return (src_dir / path).as_posix() 32 27 33 28 def _load_env_file(self): 34 29 env = os.environ.copy()
+2 -2
tools/testing/selftests/drivers/net/queues.py
··· 26 26 27 27 def check_xsk(cfg, nl, xdp_queue_id=0) -> None: 28 28 # Probe for support 29 - xdp = cmd(cfg.rpath("xdp_helper") + ' - -', fail=False) 29 + xdp = cmd(f'{cfg.test_dir / "xdp_helper"} - -', fail=False) 30 30 if xdp.ret == 255: 31 31 raise KsftSkipEx('AF_XDP unsupported') 32 32 elif xdp.ret > 0: 33 33 raise KsftFailEx('unable to create AF_XDP socket') 34 34 35 - with bkg(f'{cfg.rpath("xdp_helper")} {cfg.ifindex} {xdp_queue_id}', 35 + with bkg(f'{cfg.test_dir / "xdp_helper"} {cfg.ifindex} {xdp_queue_id}', 36 36 ksft_wait=3): 37 37 38 38 rx = tx = False