ncdevmem supports both ipv4 and ipv6, but the ksft is currently
ipv6-only. Propagate the ipv4 support to the ksft, so that folks that
are limited to these networks can also test.
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
.../selftests/drivers/net/hw/devmem.py | 33 ++++++++++++-------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/devmem.py b/tools/testing/selftests/drivers/net/hw/devmem.py
index f5d7809400ea..850381e14d9e 100755
--- a/tools/testing/selftests/drivers/net/hw/devmem.py
+++ b/tools/testing/selftests/drivers/net/hw/devmem.py
@@ -18,30 +18,36 @@ def require_devmem(cfg):
raise KsftSkipEx("Test requires devmem support")
-def check_rx(cfg) -> None:
- cfg.require_ipver("6")
+def check_rx(cfg, ipver) -> None:
require_devmem(cfg)
+ addr = cfg.addr_v[ipver]
+ if ipver == "6":
+ addr = "[" + addr + "]"
+
+ socat = f"socat -u - TCP{ipver}:{addr}:{port}"
+
port = rand_port()
listen_cmd = f"{cfg.bin_local} -l -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port}"
- with bkg(listen_cmd) as socat:
+ with bkg(listen_cmd) as ncdevmem:
wait_port_listen(port)
- cmd(f"echo -e \"hello\\nworld\"| socat -u - TCP6:[{cfg.addr_v['6']}]:{port}", host=cfg.remote, shell=True)
+ cmd(f"echo -e \"hello\\nworld\"| {socat}", host=cfg.remote, shell=True)
- ksft_eq(socat.stdout.strip(), "hello\nworld")
+ ksft_eq(ncdevmem.stdout.strip(), "hello\nworld")
-def check_tx(cfg) -> None:
- cfg.require_ipver("6")
+def check_tx(cfg, ipver) -> None:
require_devmem(cfg)
port = rand_port()
- listen_cmd = f"socat -U - TCP6-LISTEN:{port}"
+ listen_cmd = f"socat -U - TCP{ipver}-LISTEN:{port}"
- with bkg(listen_cmd, exit_wait=True) as socat:
+ addr = cfg.addr_v[ipver]
+
+ with bkg(listen_cmd) as socat:
wait_port_listen(port)
- cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port}", host=cfg.remote, shell=True)
+ cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {addr} -p {port}", host=cfg.remote, shell=True)
ksft_eq(socat.stdout.strip(), "hello\nworld")
@@ -51,8 +57,13 @@ def main() -> None:
cfg.bin_local = path.abspath(path.dirname(__file__) + "/ncdevmem")
cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
+ if "4" in cfg.addr_v:
+ ipver = "4"
+ else:
+ ipver = "6"
+
ksft_run([check_rx, check_tx],
- args=(cfg, ))
+ args=(cfg, ipver))
ksft_exit()
--
2.49.0.1101.gccaa498523-goog
On Mon, 19 May 2025 02:35:13 +0000 Mina Almasry wrote: > + addr = cfg.addr_v[ipver] > + if ipver == "6": > + addr = "[" + addr + "]" You want baddr ? https://web.git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/tools/testing/selftests/drivers/net/lib/py/env.py#n155 In general you should use cfg.addr, cfg.addr_remote and self.addr_ipver if you don't care about what IP version env provides. If you want to test specifically v4 or v6 they should be separate test cases (doesn't sound like that's your intention here tho)
On 05/19, Mina Almasry wrote:
> ncdevmem supports both ipv4 and ipv6, but the ksft is currently
> ipv6-only. Propagate the ipv4 support to the ksft, so that folks that
> are limited to these networks can also test.
>
> Signed-off-by: Mina Almasry <almasrymina@google.com>
>
> ---
> .../selftests/drivers/net/hw/devmem.py | 33 ++++++++++++-------
> 1 file changed, 22 insertions(+), 11 deletions(-)
>
> diff --git a/tools/testing/selftests/drivers/net/hw/devmem.py b/tools/testing/selftests/drivers/net/hw/devmem.py
> index f5d7809400ea..850381e14d9e 100755
> --- a/tools/testing/selftests/drivers/net/hw/devmem.py
> +++ b/tools/testing/selftests/drivers/net/hw/devmem.py
> @@ -18,30 +18,36 @@ def require_devmem(cfg):
> raise KsftSkipEx("Test requires devmem support")
>
>
> -def check_rx(cfg) -> None:
> - cfg.require_ipver("6")
> +def check_rx(cfg, ipver) -> None:
> require_devmem(cfg)
>
> + addr = cfg.addr_v[ipver]
> + if ipver == "6":
> + addr = "[" + addr + "]"
I think you can add [] unconditionally, no need to special case v6.
> +
> + socat = f"socat -u - TCP{ipver}:{addr}:{port}"
> +
> port = rand_port()
> listen_cmd = f"{cfg.bin_local} -l -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port}"
>
> - with bkg(listen_cmd) as socat:
> + with bkg(listen_cmd) as ncdevmem:
> wait_port_listen(port)
> - cmd(f"echo -e \"hello\\nworld\"| socat -u - TCP6:[{cfg.addr_v['6']}]:{port}", host=cfg.remote, shell=True)
> + cmd(f"echo -e \"hello\\nworld\"| {socat}", host=cfg.remote, shell=True)
>
> - ksft_eq(socat.stdout.strip(), "hello\nworld")
> + ksft_eq(ncdevmem.stdout.strip(), "hello\nworld")
>
>
> -def check_tx(cfg) -> None:
> - cfg.require_ipver("6")
> +def check_tx(cfg, ipver) -> None:
> require_devmem(cfg)
>
> port = rand_port()
> - listen_cmd = f"socat -U - TCP6-LISTEN:{port}"
> + listen_cmd = f"socat -U - TCP{ipver}-LISTEN:{port}"
>
> - with bkg(listen_cmd, exit_wait=True) as socat:
> + addr = cfg.addr_v[ipver]
> +
> + with bkg(listen_cmd) as socat:
> wait_port_listen(port)
> - cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port}", host=cfg.remote, shell=True)
> + cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {addr} -p {port}", host=cfg.remote, shell=True)
>
> ksft_eq(socat.stdout.strip(), "hello\nworld")
>
> @@ -51,8 +57,13 @@ def main() -> None:
> cfg.bin_local = path.abspath(path.dirname(__file__) + "/ncdevmem")
> cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
>
> + if "4" in cfg.addr_v:
> + ipver = "4"
> + else:
> + ipver = "6"
If we have both, we prefer v4, can we do the opposite?
On Mon, May 19, 2025 at 8:32 AM Stanislav Fomichev <stfomichev@gmail.com> wrote:
>
> On 05/19, Mina Almasry wrote:
> > ncdevmem supports both ipv4 and ipv6, but the ksft is currently
> > ipv6-only. Propagate the ipv4 support to the ksft, so that folks that
> > are limited to these networks can also test.
> >
> > Signed-off-by: Mina Almasry <almasrymina@google.com>
> >
> > ---
> > .../selftests/drivers/net/hw/devmem.py | 33 ++++++++++++-------
> > 1 file changed, 22 insertions(+), 11 deletions(-)
> >
> > diff --git a/tools/testing/selftests/drivers/net/hw/devmem.py b/tools/testing/selftests/drivers/net/hw/devmem.py
> > index f5d7809400ea..850381e14d9e 100755
> > --- a/tools/testing/selftests/drivers/net/hw/devmem.py
> > +++ b/tools/testing/selftests/drivers/net/hw/devmem.py
> > @@ -18,30 +18,36 @@ def require_devmem(cfg):
> > raise KsftSkipEx("Test requires devmem support")
> >
> >
> > -def check_rx(cfg) -> None:
> > - cfg.require_ipver("6")
> > +def check_rx(cfg, ipver) -> None:
> > require_devmem(cfg)
> >
> > + addr = cfg.addr_v[ipver]
> > + if ipver == "6":
> > + addr = "[" + addr + "]"
>
> I think you can add [] unconditionally, no need to special case v6.
>
I'll double check, but IIRC the [] were v6-only.
> > +
> > + socat = f"socat -u - TCP{ipver}:{addr}:{port}"
> > +
> > port = rand_port()
> > listen_cmd = f"{cfg.bin_local} -l -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port}"
> >
> > - with bkg(listen_cmd) as socat:
> > + with bkg(listen_cmd) as ncdevmem:
> > wait_port_listen(port)
> > - cmd(f"echo -e \"hello\\nworld\"| socat -u - TCP6:[{cfg.addr_v['6']}]:{port}", host=cfg.remote, shell=True)
> > + cmd(f"echo -e \"hello\\nworld\"| {socat}", host=cfg.remote, shell=True)
> >
> > - ksft_eq(socat.stdout.strip(), "hello\nworld")
> > + ksft_eq(ncdevmem.stdout.strip(), "hello\nworld")
> >
> >
> > -def check_tx(cfg) -> None:
> > - cfg.require_ipver("6")
> > +def check_tx(cfg, ipver) -> None:
> > require_devmem(cfg)
> >
> > port = rand_port()
> > - listen_cmd = f"socat -U - TCP6-LISTEN:{port}"
> > + listen_cmd = f"socat -U - TCP{ipver}-LISTEN:{port}"
> >
> > - with bkg(listen_cmd, exit_wait=True) as socat:
> > + addr = cfg.addr_v[ipver]
> > +
> > + with bkg(listen_cmd) as socat:
> > wait_port_listen(port)
> > - cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port}", host=cfg.remote, shell=True)
> > + cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {addr} -p {port}", host=cfg.remote, shell=True)
> >
> > ksft_eq(socat.stdout.strip(), "hello\nworld")
> >
> > @@ -51,8 +57,13 @@ def main() -> None:
> > cfg.bin_local = path.abspath(path.dirname(__file__) + "/ncdevmem")
> > cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
> >
> > + if "4" in cfg.addr_v:
> > + ipver = "4"
> > + else:
> > + ipver = "6"
>
> If we have both, we prefer v4, can we do the opposite?
Sure, but why? Just curious.
--
Thanks,
Mina
On 05/19, Mina Almasry wrote:
> On Mon, May 19, 2025 at 8:32 AM Stanislav Fomichev <stfomichev@gmail.com> wrote:
> >
> > On 05/19, Mina Almasry wrote:
> > > ncdevmem supports both ipv4 and ipv6, but the ksft is currently
> > > ipv6-only. Propagate the ipv4 support to the ksft, so that folks that
> > > are limited to these networks can also test.
> > >
> > > Signed-off-by: Mina Almasry <almasrymina@google.com>
> > >
> > > ---
> > > .../selftests/drivers/net/hw/devmem.py | 33 ++++++++++++-------
> > > 1 file changed, 22 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/tools/testing/selftests/drivers/net/hw/devmem.py b/tools/testing/selftests/drivers/net/hw/devmem.py
> > > index f5d7809400ea..850381e14d9e 100755
> > > --- a/tools/testing/selftests/drivers/net/hw/devmem.py
> > > +++ b/tools/testing/selftests/drivers/net/hw/devmem.py
> > > @@ -18,30 +18,36 @@ def require_devmem(cfg):
> > > raise KsftSkipEx("Test requires devmem support")
> > >
> > >
> > > -def check_rx(cfg) -> None:
> > > - cfg.require_ipver("6")
> > > +def check_rx(cfg, ipver) -> None:
> > > require_devmem(cfg)
> > >
> > > + addr = cfg.addr_v[ipver]
> > > + if ipver == "6":
> > > + addr = "[" + addr + "]"
> >
> > I think you can add [] unconditionally, no need to special case v6.
> >
>
> I'll double check, but IIRC the [] were v6-only.
>
> > > +
> > > + socat = f"socat -u - TCP{ipver}:{addr}:{port}"
> > > +
> > > port = rand_port()
> > > listen_cmd = f"{cfg.bin_local} -l -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port}"
> > >
> > > - with bkg(listen_cmd) as socat:
> > > + with bkg(listen_cmd) as ncdevmem:
> > > wait_port_listen(port)
> > > - cmd(f"echo -e \"hello\\nworld\"| socat -u - TCP6:[{cfg.addr_v['6']}]:{port}", host=cfg.remote, shell=True)
> > > + cmd(f"echo -e \"hello\\nworld\"| {socat}", host=cfg.remote, shell=True)
> > >
> > > - ksft_eq(socat.stdout.strip(), "hello\nworld")
> > > + ksft_eq(ncdevmem.stdout.strip(), "hello\nworld")
> > >
> > >
> > > -def check_tx(cfg) -> None:
> > > - cfg.require_ipver("6")
> > > +def check_tx(cfg, ipver) -> None:
> > > require_devmem(cfg)
> > >
> > > port = rand_port()
> > > - listen_cmd = f"socat -U - TCP6-LISTEN:{port}"
> > > + listen_cmd = f"socat -U - TCP{ipver}-LISTEN:{port}"
> > >
> > > - with bkg(listen_cmd, exit_wait=True) as socat:
> > > + addr = cfg.addr_v[ipver]
> > > +
> > > + with bkg(listen_cmd) as socat:
> > > wait_port_listen(port)
> > > - cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port}", host=cfg.remote, shell=True)
> > > + cmd(f"echo -e \"hello\\nworld\"| {cfg.bin_remote} -f {cfg.ifname} -s {addr} -p {port}", host=cfg.remote, shell=True)
> > >
> > > ksft_eq(socat.stdout.strip(), "hello\nworld")
> > >
> > > @@ -51,8 +57,13 @@ def main() -> None:
> > > cfg.bin_local = path.abspath(path.dirname(__file__) + "/ncdevmem")
> > > cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
> > >
> > > + if "4" in cfg.addr_v:
> > > + ipver = "4"
> > > + else:
> > > + ipver = "6"
> >
> > If we have both, we prefer v4, can we do the opposite?
>
> Sure, but why? Just curious.
We want to be in the v6-only world at some point (unlikely to get there
though), and having dualstack deployments prefer v6 is the way to go.
© 2016 - 2025 Red Hat, Inc.