Skip to content

Commit e514d77

Browse files
committed
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7220e8f commit e514d77

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

tools/testing/selftests/drivers/net/hds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _get_hds_mode(cfg, netnl) -> str:
2020

2121

2222
def _xdp_onoff(cfg):
23-
prog = cfg.rpath("../../net/lib/xdp_dummy.bpf.o")
23+
prog = cfg.net_lib_dir / "xdp_dummy.bpf.o"
2424
ip("link set dev %s xdp obj %s sec xdp" %
2525
(cfg.ifname, prog))
2626
ip("link set dev %s xdp off" % cfg.ifname)

tools/testing/selftests/drivers/net/hw/csum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def main() -> None:
8888
with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
8989
check_nic_features(cfg)
9090

91-
cfg.bin_local = cfg.rpath("../../../net/lib/csum")
91+
cfg.bin_local = cfg.net_lib_dir / "csum"
9292
cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
9393

9494
cases = []

tools/testing/selftests/drivers/net/hw/irq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def reconfig(cfg) -> None:
6969
def check_reconfig_xdp(cfg) -> None:
7070
def reconfig(cfg) -> None:
7171
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"))
7373
ip(f"link set dev %s xdp off" % cfg.ifname)
7474

7575
_check_reconfig(cfg, reconfig)

tools/testing/selftests/drivers/net/lib/py/env.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,17 @@
1313
class NetDrvEnvBase:
1414
"""
1515
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
1620
"""
1721
def __init__(self, src_path):
18-
self.src_path = src_path
19-
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.
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()
2525

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()
26+
self.env = self._load_env_file()
3227

3328
def _load_env_file(self):
3429
env = os.environ.copy()

tools/testing/selftests/drivers/net/queues.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def nl_get_queues(cfg, nl, qtype='rx'):
2626

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

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}',
3636
ksft_wait=3):
3737

3838
rx = tx = False

0 commit comments

Comments
 (0)