diff mbox series

[net-next,5/5] selftests: drv-net: add a trivial ping test

Message ID 20240412233705.1066444-6-kuba@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series selftests: drv-net: support testing with a remote system | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 932 this patch: 932
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 938 this patch: 938
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 944 this patch: 944
netdev/checkpatch warning WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-04-13--15-00 (tests: 960)

Commit Message

Jakub Kicinski April 12, 2024, 11:37 p.m. UTC
Add a very simple test for testing with a remote system.
Both IPv4 and IPv6 connectivity is optional so tests
will XFail is env doesn't define an address for the given
family.

Using netdevsim:

 $ ./run_kselftest.sh -t drivers/net:ping.py
 TAP version 13
 1..1
 # timeout set to 45
 # selftests: drivers/net: ping.py
 # KTAP version 1
 # 1..2
 # ok 1 ping.ping_v4
 # ok 2 ping.ping_v6
 # # Totals: pass:2 fail:0 xfail:0 xpass:0 skip:0 error:0
 ok 1 selftests: drivers/net: ping.py

Command line SSH:

 $ NETIF=virbr0 EP_TYPE=ssh EP_ARGS=root@192.168.122.123 \
    LOCAL_V4=192.168.122.1 EP_V4=192.168.122.123 \
    ./tools/testing/selftests/drivers/net/ping.py
 KTAP version 1
 1..2
 ok 1 ping.ping_v4
 ok 2 ping.ping_v6 # XFAIL
 # Totals: pass:1 fail:0 xfail:1 xpass:0 skip:0 error:0

Existing devices placed in netns (and using net.config):

 $ cat drivers/net/net.config
 NETIF=veth0
 EP_TYPE=netns
 EP_ARGS=red
 LOCAL_V4="192.168.1.1"
 EP_V4="192.168.1.2"

 $ ./run_kselftest.sh -t drivers/net:ping.py
 TAP version 13
 1..1
 # timeout set to 45
 # selftests: drivers/net: ping.py
 # KTAP version 1
 # 1..2
 # ok 1 ping.ping_v4
 # ok 2 ping.ping_v6 # XFAIL
 # # Totals: pass:1 fail:0 xfail:1 xpass:0 skip:0 error:0

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/drivers/net/Makefile |  4 ++-
 tools/testing/selftests/drivers/net/ping.py  | 32 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/drivers/net/ping.py

Comments

Paolo Abeni April 15, 2024, 9:31 a.m. UTC | #1
On Fri, 2024-04-12 at 16:37 -0700, Jakub Kicinski wrote:
> +def ping_v4(cfg) -> None:
> +    if not cfg.v4:
> +        raise KsftXfailEx()
> +
> +    cmd(f"ping -c 1 -W0.5 {cfg.ep_v4}")
> +    cmd(f"ping -c 1 -W0.5 {cfg.v4}", host=cfg.endpoint)

Very minor nit, I personally find a bit more readable:

	cfg.endpoint.cmd()

Which is already supported by the current infra, right?

With both endpoint possibly remote could be:

	cfg.ep1.cmd()
	cfg.ep2.cmd()

Thanks!

Paolo
Jakub Kicinski April 15, 2024, 2:33 p.m. UTC | #2
On Mon, 15 Apr 2024 11:31:05 +0200 Paolo Abeni wrote:
> On Fri, 2024-04-12 at 16:37 -0700, Jakub Kicinski wrote:
> > +def ping_v4(cfg) -> None:
> > +    if not cfg.v4:
> > +        raise KsftXfailEx()
> > +
> > +    cmd(f"ping -c 1 -W0.5 {cfg.ep_v4}")
> > +    cmd(f"ping -c 1 -W0.5 {cfg.v4}", host=cfg.endpoint)  
> 
> Very minor nit, I personally find a bit more readable:
> 
> 	cfg.endpoint.cmd()
> 
> Which is already supported by the current infra, right?
> 
> With both endpoint possibly remote could be:
> 
> 	cfg.ep1.cmd()
> 	cfg.ep2.cmd()

As I said in the cover letter, I don't want to push us too much towards
classes. The argument format make local and local+remote tests look more
similar.

I could be wrong 
Paolo Abeni April 15, 2024, 4:09 p.m. UTC | #3
On Mon, 2024-04-15 at 07:33 -0700, Jakub Kicinski wrote:
> On Mon, 15 Apr 2024 11:31:05 +0200 Paolo Abeni wrote:
> > On Fri, 2024-04-12 at 16:37 -0700, Jakub Kicinski wrote:
> > > +def ping_v4(cfg) -> None:
> > > +    if not cfg.v4:
> > > +        raise KsftXfailEx()
> > > +
> > > +    cmd(f"ping -c 1 -W0.5 {cfg.ep_v4}")
> > > +    cmd(f"ping -c 1 -W0.5 {cfg.v4}", host=cfg.endpoint)  
> > 
> > Very minor nit, I personally find a bit more readable:
> > 
> > 	cfg.endpoint.cmd()
> > 
> > Which is already supported by the current infra, right?
> > 
> > With both endpoint possibly remote could be:
> > 
> > 	cfg.ep1.cmd()
> > 	cfg.ep2.cmd()
> 
> As I said in the cover letter, I don't want to push us too much towards
> classes. The argument format make local and local+remote tests look more
> similar.

I guess it's a matter of personal preferences. I know mine are usually
quite twisted ;)

I'm fine with either syntax.

Cheers,

Paolo
diff mbox series

Patch

diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile
index 379cdb1960a7..713ab251cea9 100644
--- a/tools/testing/selftests/drivers/net/Makefile
+++ b/tools/testing/selftests/drivers/net/Makefile
@@ -2,6 +2,8 @@ 
 
 TEST_INCLUDES := $(wildcard lib/py/*.py)
 
-TEST_PROGS := stats.py
+TEST_PROGS := \
+	ping.py \
+	stats.py \
 
 include ../../lib.mk
diff --git a/tools/testing/selftests/drivers/net/ping.py b/tools/testing/selftests/drivers/net/ping.py
new file mode 100755
index 000000000000..df746543f5c3
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/ping.py
@@ -0,0 +1,32 @@ 
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+from lib.py import ksft_run, KsftXfailEx
+from lib.py import NetDrvEpEnv
+from lib.py import cmd
+
+
+def ping_v4(cfg) -> None:
+    if not cfg.v4:
+        raise KsftXfailEx()
+
+    cmd(f"ping -c 1 -W0.5 {cfg.ep_v4}")
+    cmd(f"ping -c 1 -W0.5 {cfg.v4}", host=cfg.endpoint)
+
+
+def ping_v6(cfg) -> None:
+    if not cfg.v6:
+        raise KsftXfailEx()
+
+    cmd(f"ping -c 1 -W0.5 {cfg.ep_v6}")
+    cmd(f"ping -c 1 -W0.5 {cfg.v6}", host=cfg.endpoint)
+
+
+def main() -> None:
+    with NetDrvEpEnv(__file__) as cfg:
+        ksft_run([ping_v4, ping_v6],
+                 args=(cfg, ))
+
+
+if __name__ == "__main__":
+    main()