]> www.infradead.org Git - users/hch/misc.git/commitdiff
selftests: drv-net: replace the rpath helper with Path objects
authorJakub Kicinski <kuba@kernel.org>
Thu, 27 Mar 2025 22:23:13 +0000 (15:23 -0700)
committerJakub Kicinski <kuba@kernel.org>
Mon, 31 Mar 2025 23:44:25 +0000 (16:44 -0700)
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>
tools/testing/selftests/drivers/net/hds.py
tools/testing/selftests/drivers/net/hw/csum.py
tools/testing/selftests/drivers/net/hw/irq.py
tools/testing/selftests/drivers/net/lib/py/env.py
tools/testing/selftests/drivers/net/queues.py

index 7cc74faed7430d16bd05f5ddb74a4c4a95e2073c..8b7f6acad15f13053f3d9cf20e787b95930e474d 100755 (executable)
@@ -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)
index 701aca1361e0e60a95371c8911358e5ee86c09ad..cd23af87531708331ccdda00928e5aa6add0a0a1 100755 (executable)
@@ -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 = []
index 42ab9837024585d9ecf3a69904e23be9d3c8d2aa..d772a18d8a1b48c89ac555885736d9c656eff840 100755 (executable)
@@ -69,7 +69,7 @@ def check_reconfig_queues(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.test_dir / "xdp_dummy.bpf.o"))
         ip(f"link set dev %s xdp off" % cfg.ifname)
 
     _check_reconfig(cfg, reconfig)
index fd4d674e6c72e29ef260e41fa0034ba4dfdec329..ad5ff645183acdb5dd224a6fa495d0012147d5da 100644 (file)
@@ -13,22 +13,17 @@ 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.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()
index cae923f84f699b24d2a3609d0884892158fc9b04..06abd3f233e1ff3ef30836b7865a8d73b793eb3a 100755 (executable)
@@ -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