diff mbox series

[net-next,2/2] selftests: drv-net: add helper for path resolution

Message ID 20250207184140.1730466-2-kuba@kernel.org (mailing list archive)
State Accepted
Commit 3337064f4204572a97f701b936436336e37b99d9
Delegated to: Netdev Maintainers
Headers show
Series [net-next,1/2] selftests: drv-net: factor out a DrvEnv base class | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success Errors and warnings before: 26 (+1) this patch: 26 (+1)
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: 'Refering' may be misspelled - perhaps 'Referring'?
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-08--03-00 (tests: 889)

Commit Message

Jakub Kicinski Feb. 7, 2025, 6:41 p.m. UTC
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.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/drivers/net/hw/csum.py    |  2 +-
 tools/testing/selftests/drivers/net/lib/py/env.py | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

Comments

Petr Machata Feb. 10, 2025, 2:24 p.m. UTC | #1
Jakub Kicinski <kuba@kernel.org> writes:

> 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.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Petr Machata <petrm@nvidia.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/drivers/net/hw/csum.py b/tools/testing/selftests/drivers/net/hw/csum.py
index cb40497faee4..cd477f3440ca 100755
--- a/tools/testing/selftests/drivers/net/hw/csum.py
+++ b/tools/testing/selftests/drivers/net/hw/csum.py
@@ -100,7 +100,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 = 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 = []
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index 2f17880e411d..886b4904613c 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -18,6 +18,18 @@  from .remote import Remote
         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()