Skip to content

Commit 3337064

Browse files
committed
selftests: drv-net: add helper for path resolution
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>
1 parent 29604bc commit 3337064

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

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

103-
cfg.bin_local = path.abspath(path.dirname(__file__) + "/../../../net/lib/csum")
103+
cfg.bin_local = cfg.rpath("../../../net/lib/csum")
104104
cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
105105

106106
cases = []

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ def __init__(self, src_path):
1818
self.src_path = src_path
1919
self.env = self._load_env_file()
2020

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.
25+
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()
32+
2133
def _load_env_file(self):
2234
env = os.environ.copy()
2335

0 commit comments

Comments
 (0)