summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/drivers/net/lib/py/env.py
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2025-03-27 15:23:13 -0700
committerJakub Kicinski <kuba@kernel.org>2025-03-31 16:44:25 -0700
commite514d77334a63f1dcb9a3b47d5aee8f51d66cb1d (patch)
tree4cba27bfdfddac445d386ca459df3c039788252b /tools/testing/selftests/drivers/net/lib/py/env.py
parent7220e8f4d4eec0b2f682eef45e2d36c092738413 (diff)
downloadlinux-e514d77334a63f1dcb9a3b47d5aee8f51d66cb1d.tar.gz
linux-e514d77334a63f1dcb9a3b47d5aee8f51d66cb1d.tar.bz2
linux-e514d77334a63f1dcb9a3b47d5aee8f51d66cb1d.zip
selftests: drv-net: replace the rpath helper with Path objects
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>
Diffstat (limited to 'tools/testing/selftests/drivers/net/lib/py/env.py')
-rw-r--r--tools/testing/selftests/drivers/net/lib/py/env.py21
1 files changed, 8 insertions, 13 deletions
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index fd4d674e6c72..ad5ff645183a 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -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()