All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me,
	willemdebruijn.kernel@gmail.com, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net v3 1/3] selftests: drv-net: replace the rpath helper with Path objects
Date: Thu, 27 Mar 2025 15:23:13 -0700	[thread overview]
Message-ID: <20250327222315.1098596-2-kuba@kernel.org> (raw)
In-Reply-To: <20250327222315.1098596-1-kuba@kernel.org>

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
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v3:
 - change the approach to use Path
v2: https://lore.kernel.org/20250306171158.1836674-1-kuba@kernel.org
---
 tools/testing/selftests/drivers/net/hds.py    |  2 +-
 .../testing/selftests/drivers/net/hw/csum.py  |  2 +-
 tools/testing/selftests/drivers/net/hw/irq.py |  2 +-
 .../selftests/drivers/net/lib/py/env.py       | 21 +++++++------------
 tools/testing/selftests/drivers/net/queues.py |  4 ++--
 5 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/tools/testing/selftests/drivers/net/hds.py b/tools/testing/selftests/drivers/net/hds.py
index 7cc74faed743..8b7f6acad15f 100755
--- a/tools/testing/selftests/drivers/net/hds.py
+++ b/tools/testing/selftests/drivers/net/hds.py
@@ -20,7 +20,7 @@ from lib.py import defer, ethtool, ip
 
 
 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)
diff --git a/tools/testing/selftests/drivers/net/hw/csum.py b/tools/testing/selftests/drivers/net/hw/csum.py
index 701aca1361e0..cd23af875317 100755
--- a/tools/testing/selftests/drivers/net/hw/csum.py
+++ b/tools/testing/selftests/drivers/net/hw/csum.py
@@ -88,7 +88,7 @@ from lib.py import bkg, cmd, wait_port_listen
     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 = []
diff --git a/tools/testing/selftests/drivers/net/hw/irq.py b/tools/testing/selftests/drivers/net/hw/irq.py
index 42ab98370245..d772a18d8a1b 100755
--- a/tools/testing/selftests/drivers/net/hw/irq.py
+++ b/tools/testing/selftests/drivers/net/hw/irq.py
@@ -69,7 +69,7 @@ from lib.py import cmd, ip, defer
 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.test_dir / "xdp_dummy.bpf.o"))
         ip(f"link set dev %s xdp off" % cfg.ifname)
 
     _check_reconfig(cfg, reconfig)
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index fd4d674e6c72..ad5ff645183a 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -13,23 +13,18 @@ from .remote import Remote
 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.src_path = Path(src_path)
+        self.test_dir = self.src_path.parent.resolve()
+        self.net_lib_dir = (Path(__file__).parent / "../../../../net/lib").resolve()
+
         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.
-
-        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()
-
     def _load_env_file(self):
         env = os.environ.copy()
 
diff --git a/tools/testing/selftests/drivers/net/queues.py b/tools/testing/selftests/drivers/net/queues.py
index cae923f84f69..06abd3f233e1 100755
--- a/tools/testing/selftests/drivers/net/queues.py
+++ b/tools/testing/selftests/drivers/net/queues.py
@@ -26,13 +26,13 @@ import struct
 
 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
-- 
2.49.0


  reply	other threads:[~2025-03-27 22:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-27 22:23 [PATCH net v3 0/3] selftests: drv-net: replace the rpath helper with Path objects Jakub Kicinski
2025-03-27 22:23 ` Jakub Kicinski [this message]
2025-03-28  0:40   ` [PATCH net v3 1/3] " Willem de Bruijn
2025-03-27 22:23 ` [PATCH net v3 2/3] selftests: net: use the dummy bpf from net/lib Jakub Kicinski
2025-03-28  0:40   ` Willem de Bruijn
2025-03-27 22:23 ` [PATCH net v3 3/3] selftests: net: use Path helpers in ping Jakub Kicinski
2025-03-28  0:41   ` Willem de Bruijn
2025-04-01  0:10 ` [PATCH net v3 0/3] selftests: drv-net: replace the rpath helper with Path objects patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250327222315.1098596-2-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.