Message ID | 20250306171158.1836674-1-kuba@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [net-next,v2,1/2] selftests: drv-net: add path helper for net/lib | expand |
On Thu, Mar 6, 2025 at 12:12 PM Jakub Kicinski <kuba@kernel.org> wrote: > > Looks like a lot of users of recently added env.rpath() actually > want to access stuff under net/lib. Add another helper. > > Signed-off-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Willem de Bruijn <willemb@google.com> > diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py > index fd4d674e6c72..2a1f8bd0ec19 100644 > --- a/tools/testing/selftests/drivers/net/lib/py/env.py > +++ b/tools/testing/selftests/drivers/net/lib/py/env.py > @@ -30,6 +30,13 @@ from .remote import Remote > src_dir = Path(self.src_path).parent.resolve() > return (src_dir / path).as_posix() > > + def lpath(self, path): > + """ > + Similar to rpath, but for files in net/lib TARGET. > + """ > + lib_dir = (Path(__file__).parent / "../../../../net/lib").resolve() > + return (lib_dir / path).as_posix() > + small nit that one letter acronyms are not the most self describing ;) I would initially read this as local path
On Thu, 6 Mar 2025 17:22:47 -0500 Willem de Bruijn wrote: > > + def lpath(self, path): > > + """ > > + Similar to rpath, but for files in net/lib TARGET. > > + """ > > + lib_dir = (Path(__file__).parent / "../../../../net/lib").resolve() > > + return (lib_dir / path).as_posix() > > + > > small nit that one letter acronyms are not the most self describing ;) > I would initially read this as local path The other option that came to mind was to have one helper called path() and pass rel=CONST to it. For example: prog = cfg.path("xdp_dummy.bpf.o", rel=cfg.NET_LIB) Thinking about it now we could also store dir directly, which is probably most "Pythonic"? prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" Thoughts?
Jakub Kicinski wrote: > On Thu, 6 Mar 2025 17:22:47 -0500 Willem de Bruijn wrote: > > > + def lpath(self, path): > > > + """ > > > + Similar to rpath, but for files in net/lib TARGET. > > > + """ > > > + lib_dir = (Path(__file__).parent / "../../../../net/lib").resolve() > > > + return (lib_dir / path).as_posix() > > > + > > > > small nit that one letter acronyms are not the most self describing ;) > > I would initially read this as local path > > The other option that came to mind was to have one helper called path() > and pass rel=CONST to it. For example: > > prog = cfg.path("xdp_dummy.bpf.o", rel=cfg.NET_LIB) > > Thinking about it now we could also store dir directly, which is > probably most "Pythonic"? > > prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" > > Thoughts? The pythonic approach is nice. No function indirection, so self explanatory. But they all are reasonable, of course.
diff --git a/tools/testing/selftests/drivers/net/hds.py b/tools/testing/selftests/drivers/net/hds.py index 7cc74faed743..def44c10349a 100755 --- a/tools/testing/selftests/drivers/net/hds.py +++ b/tools/testing/selftests/drivers/net/hds.py @@ -20,7 +20,7 @@ from lib.py import defer, ethtool, ip def _xdp_onoff(cfg): - prog = cfg.rpath("../../net/lib/xdp_dummy.bpf.o") + prog = cfg.lpath("xdp_dummy.bpf.o") ip("link set dev %s xdp obj %s sec xdp" % (cfg.ifname, prog)) ip("link set dev %s xdp off" % cfg.ifname) diff --git a/tools/testing/selftests/drivers/net/hw/csum.py b/tools/testing/selftests/drivers/net/hw/csum.py index 701aca1361e0..49ec98aef579 100755 --- a/tools/testing/selftests/drivers/net/hw/csum.py +++ b/tools/testing/selftests/drivers/net/hw/csum.py @@ -88,7 +88,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 = cfg.rpath("../../../net/lib/csum") + cfg.bin_local = cfg.lpath("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 fd4d674e6c72..2a1f8bd0ec19 100644 --- a/tools/testing/selftests/drivers/net/lib/py/env.py +++ b/tools/testing/selftests/drivers/net/lib/py/env.py @@ -30,6 +30,13 @@ from .remote import Remote src_dir = Path(self.src_path).parent.resolve() return (src_dir / path).as_posix() + def lpath(self, path): + """ + Similar to rpath, but for files in net/lib TARGET. + """ + lib_dir = (Path(__file__).parent / "../../../../net/lib").resolve() + return (lib_dir / path).as_posix() + def _load_env_file(self): env = os.environ.copy()
Looks like a lot of users of recently added env.rpath() actually want to access stuff under net/lib. Add another helper. Signed-off-by: Jakub Kicinski <kuba@kernel.org> --- tools/testing/selftests/drivers/net/hds.py | 2 +- tools/testing/selftests/drivers/net/hw/csum.py | 2 +- tools/testing/selftests/drivers/net/lib/py/env.py | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-)