]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: drv-net: add helper for path resolution
authorJakub Kicinski <kuba@kernel.org>
Fri, 7 Feb 2025 18:41:40 +0000 (10:41 -0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 11 Feb 2025 03:10:10 +0000 (19:10 -0800)
Refering to C binaries from Python code is going to be a common
need. Add a helper to convert from path in relation to the test.
Meaning, if the test is in the same directory as the binary, the
call would be simply: cfg.rpath("binary").

The helper name "rpath" is not great. I can't think of a better
name that would be accurate yet concise.

Reviewed-by: Petr Machata <petrm@nvidia.com>
Link: https://patch.msgid.link/20250207184140.1730466-2-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/drivers/net/hw/csum.py
tools/testing/selftests/drivers/net/lib/py/env.py

index cb40497faee441fbc621a29ed02a3b978b9c0872..cd477f3440caf76ee6047cb40ace7689f15fd179 100755 (executable)
@@ -100,7 +100,7 @@ def main() -> None:
     with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
         check_nic_features(cfg)
 
-        cfg.bin_local = path.abspath(path.dirname(__file__) + "/../../../net/lib/csum")
+        cfg.bin_local = cfg.rpath("../../../net/lib/csum")
         cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
 
         cases = []
index 2f17880e411d65d62911f7db51db49381aa74c24..886b4904613c3e57bdb34faa26da2e2b2e812905 100644 (file)
@@ -18,6 +18,18 @@ class NetDrvEnvBase:
         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.
+
+        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()