diff options
author | Jakub Kicinski <kuba@kernel.org> | 2025-02-07 21:41:40 +0300 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2025-02-11 06:10:10 +0300 |
commit | 3337064f4204572a97f701b936436336e37b99d9 (patch) | |
tree | 7e95a8be1416da5dfcf017482bda29cb9ff80aa7 /tools/testing/selftests/drivers/net/lib/py/env.py | |
parent | 29604bc2aaed5a8f5264018b29d73cb4a7a34960 (diff) | |
download | linux-3337064f4204572a97f701b936436336e37b99d9.tar.xz |
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>
Diffstat (limited to 'tools/testing/selftests/drivers/net/lib/py/env.py')
-rw-r--r-- | tools/testing/selftests/drivers/net/lib/py/env.py | 12 |
1 files changed, 12 insertions, 0 deletions
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 @@ 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() |