selftests: drv: net: fix `ping.py` test failure
Subsystems (3)
v4 cover selftests: drv: net: fix `ping.py` test failure
Fix ping.py test failure on an ipv6 system, and appropriately handle the cases where either one of the two address families (ipv4, ipv6) is not present.
Mohsin Bashir (3):
selftests: drv: net: fix test failure on ipv6 sys
selftests: drv: net: avoid skipping tests
selftests: drv: net: add version indicator
tools/testing/selftests/drivers/net/ping.py | 45 ++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-)
Signature · 1 line
2.47.1
PATCH v4 1/3 selftests: drv: net: fix test failure on ipv6 sys
The get_interface_info call has ip version hard-coded which leads to failures on an IPV6 system. The NetDrvEnv class already gathers information about remote interface, so instead of fixing the local implementation switch to using cfg.remote_ifname.
Before:./drivers/net/ping.py
Traceback (most recent call last):
File "/new_tests/./drivers/net/ping.py", line 217, in <module>
main()
File "/new_tests/./drivers/net/ping.py", line 204, in main
get_interface_info(cfg)
File "/new_tests/./drivers/net/ping.py", line 128, in get_interface_info
raise KsftFailEx('Can not get remote interface')
net.lib.py.ksft.KsftFailEx: Can not get remote interface
After:./drivers/net/ping.py
TAP version 13
1..6
ok 1 ping.test_default # SKIP Test requires IPv4 connectivity ok 2 ping.test_xdp_generic_sb # SKIP Test requires IPv4 connectivity ok 3 ping.test_xdp_generic_mb # SKIP Test requires IPv4 connectivity ok 4 ping.test_xdp_native_sb # SKIP Test requires IPv4 connectivity ok 5 ping.test_xdp_native_mb # SKIP Test requires IPv4 connectivity ok 6 ping.test_xdp_offload # SKIP device does not support offloaded XDP
Totals: pass:0 fail:0 xfail:0 xpass:0 skip:6 error:0
--- tools/testing/selftests/drivers/net/ping.py | 22 +++++++++------------ 1 file changed, 9 insertions(+), 13 deletions(-)
tools/testing/selftests/drivers/net/ping.py +9 -13
@@ -9,7 +9,6 @@ from lib.py import EthtoolFamily, NetDrvEpEnv from lib.py import bkg, cmd, wait_port_listen, rand_port from lib.py import defer, ethtool, ip -remote_ifname="" no_sleep=False def _test_v4(cfg) -> None:
@@ -57,7 +56,7 @@ def _set_offload_checksum(cfg, netnl, on) -> None: def _set_xdp_generic_sb_on(cfg) -> None: prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" - cmd(f"ip link set dev {remote_ifname} mtu 1500", shell=True, host=cfg.remote) + cmd(f"ip link set dev {cfg.remote_ifname} mtu 1500", shell=True, host=cfg.remote) cmd(f"ip link set dev {cfg.ifname} mtu 1500 xdpgeneric obj {prog} sec xdp", shell=True) defer(cmd, f"ip link set dev {cfg.ifname} xdpgeneric off")
@@ -66,8 +65,8 @@ def _set_xdp_generic_sb_on(cfg) -> None: def _set_xdp_generic_mb_on(cfg) -> None: prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" - cmd(f"ip link set dev {remote_ifname} mtu 9000", shell=True, host=cfg.remote) - defer(ip, f"link set dev {remote_ifname} mtu 1500", host=cfg.remote) + cmd(f"ip link set dev {cfg.remote_ifname} mtu 9000", shell=True, host=cfg.remote) + defer(ip, f"link set dev {cfg.remote_ifname} mtu 1500", host=cfg.remote) ip("link set dev %s mtu 9000 xdpgeneric obj %s sec xdp.frags" % (cfg.ifname, prog)) defer(ip, f"link set dev {cfg.ifname} mtu 1500 xdpgeneric off")
@@ -76,7 +75,7 @@ def _set_xdp_generic_mb_on(cfg) -> None: def _set_xdp_native_sb_on(cfg) -> None: prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" - cmd(f"ip link set dev {remote_ifname} mtu 1500", shell=True, host=cfg.remote) + cmd(f"ip link set dev {cfg.remote_ifname} mtu 1500", shell=True, host=cfg.remote) cmd(f"ip -j link set dev {cfg.ifname} mtu 1500 xdp obj {prog} sec xdp", shell=True) defer(ip, f"link set dev {cfg.ifname} mtu 1500 xdp off") xdp_info = ip("-d link show %s" % (cfg.ifname), json=True)[0]
@@ -93,8 +92,8 @@ def _set_xdp_native_sb_on(cfg) -> None: def _set_xdp_native_mb_on(cfg) -> None: prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" - cmd(f"ip link set dev {remote_ifname} mtu 9000", shell=True, host=cfg.remote) - defer(ip, f"link set dev {remote_ifname} mtu 1500", host=cfg.remote) + cmd(f"ip link set dev {cfg.remote_ifname} mtu 9000", shell=True, host=cfg.remote) + defer(ip, f"link set dev {cfg.remote_ifname} mtu 1500", host=cfg.remote) try: cmd(f"ip link set dev {cfg.ifname} mtu 9000 xdp obj {prog} sec xdp.frags", shell=True) defer(ip, f"link set dev {cfg.ifname} mtu 1500 xdp off")
@@ -112,18 +111,15 @@ def _set_xdp_offload_on(cfg) -> None: except Exception as e: raise KsftSkipEx('device does not support offloaded XDP') defer(ip, f"link set dev {cfg.ifname} xdpoffload off") - cmd(f"ip link set dev {remote_ifname} mtu 1500", shell=True, host=cfg.remote) + cmd(f"ip link set dev {cfg.remote_ifname} mtu 1500", shell=True, host=cfg.remote) if no_sleep != True: time.sleep(10) def get_interface_info(cfg) -> None: - global remote_ifname global no_sleep - remote_info = cmd(f"ip -4 -o addr show to {cfg.remote_addr_v['4']} | awk '{{print $2}}'", shell=True, host=cfg.remote).stdout - remote_ifname = remote_info.rstrip('\n') - if remote_ifname == "": + if cfg.remote_ifname == "": raise KsftFailEx('Can not get remote interface') local_info = ip("-d link show %s" % (cfg.ifname), json=True)[0] if 'parentbus' in local_info and local_info['parentbus'] == "netdevsim":
@@ -136,7 +132,7 @@ def set_interface_init(cfg) -> None: cmd(f"ip link set dev {cfg.ifname} xdp off ", shell=True) cmd(f"ip link set dev {cfg.ifname} xdpgeneric off ", shell=True) cmd(f"ip link set dev {cfg.ifname} xdpoffload off", shell=True) - cmd(f"ip link set dev {remote_ifname} mtu 1500", shell=True, host=cfg.remote) + cmd(f"ip link set dev {cfg.remote_ifname} mtu 1500", shell=True, host=cfg.remote) def test_default(cfg, netnl) -> None: _set_offload_checksum(cfg, netnl, "off")
Signature · 1 line
2.47.1
PATCH v4 2/3 selftests: drv: net: avoid skipping tests
In reply to Mohsin BashirOn a system with either of the ipv4 or ipv6 information missing, tests are currently skipped. Ideally, the test should run as long as at least one address family is present. This patch make test run whenever possible.
Before:./drivers/net/ping.py
TAP version 13
1..6
ok 1 ping.test_default # SKIP Test requires IPv4 connectivity ok 2 ping.test_xdp_generic_sb # SKIP Test requires IPv4 connectivity ok 3 ping.test_xdp_generic_mb # SKIP Test requires IPv4 connectivity ok 4 ping.test_xdp_native_sb # SKIP Test requires IPv4 connectivity ok 5 ping.test_xdp_native_mb # SKIP Test requires IPv4 connectivity ok 6 ping.test_xdp_offload # SKIP device does not support offloaded XDP
Totals: pass:0 fail:0 xfail:0 xpass:0 skip:6 error:0
After:./drivers/net/ping.py
TAP version 13
1..6
ok 1 ping.test_default
ok 2 ping.test_xdp_generic_sb
ok 3 ping.test_xdp_generic_mb
ok 4 ping.test_xdp_native_sb
ok 5 ping.test_xdp_native_mb
ok 6 ping.test_xdp_offload # SKIP device does not support offloaded XDP
Totals: pass:5 fail:0 xfail:0 xpass:0 skip:1 error:0
--- tools/testing/selftests/drivers/net/ping.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/drivers/net/ping.py +4 -2
@@ -12,7 +12,8 @@ from lib.py import defer, ethtool, ip no_sleep=False def _test_v4(cfg) -> None: - cfg.require_ipver("4") + if not cfg.addr_v["4"]: + return cmd("ping -c 1 -W0.5 " + cfg.remote_addr_v["4"]) cmd("ping -c 1 -W0.5 " + cfg.addr_v["4"], host=cfg.remote)
@@ -20,7 +21,8 @@ def _test_v4(cfg) -> None: cmd("ping -s 65000 -c 1 -W0.5 " + cfg.addr_v["4"], host=cfg.remote) def _test_v6(cfg) -> None: - cfg.require_ipver("6") + if not cfg.addr_v["6"]: + return cmd("ping -c 1 -W5 " + cfg.remote_addr_v["6"]) cmd("ping -c 1 -W5 " + cfg.addr_v["6"], host=cfg.remote)
Signature · 1 line
2.47.1
PATCH v4 3/3 selftests: drv: net: add version indicator
In reply to Mohsin BashirCurrently, the test result does not differentiate between the cases when either one of the address families are configured or if both the address families are configured. Ideally, the result should report if a particular case was skipped.
./drivers/net/ping.py
TAP version 13
1..7
ok 1 ping.test_default_v4 # SKIP Test requires IPv4 connectivity ok 2 ping.test_default_v6
ok 3 ping.test_xdp_generic_sb
ok 4 ping.test_xdp_generic_mb
ok 5 ping.test_xdp_native_sb
ok 6 ping.test_xdp_native_mb
ok 7 ping.test_xdp_offload # SKIP device does not support offloaded XDP
Totals: pass:5 fail:0 xfail:0 xpass:0 skip:2 error:0
--- tools/testing/selftests/drivers/net/ping.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
tools/testing/selftests/drivers/net/ping.py +14 -3
@@ -136,13 +136,23 @@ def set_interface_init(cfg) -> None: cmd(f"ip link set dev {cfg.ifname} xdpoffload off", shell=True) cmd(f"ip link set dev {cfg.remote_ifname} mtu 1500", shell=True, host=cfg.remote) -def test_default(cfg, netnl) -> None: +def test_default_v4(cfg, netnl) -> None: + cfg.require_ipver("4") + _set_offload_checksum(cfg, netnl, "off") _test_v4(cfg) - _test_v6(cfg) _test_tcp(cfg) _set_offload_checksum(cfg, netnl, "on") _test_v4(cfg) + _test_tcp(cfg) + +def test_default_v6(cfg, netnl) -> None: + cfg.require_ipver("6") + + _set_offload_checksum(cfg, netnl, "off") + _test_v6(cfg) + _test_tcp(cfg) + _set_offload_checksum(cfg, netnl, "on") _test_v6(cfg) _test_tcp(cfg)
@@ -200,7 +210,8 @@ def main() -> None: with NetDrvEpEnv(__file__) as cfg: get_interface_info(cfg) set_interface_init(cfg) - ksft_run([test_default, + ksft_run([test_default_v4, + test_default_v6, test_xdp_generic_sb, test_xdp_generic_mb, test_xdp_native_sb,
Signature · 1 line
2.47.1
Re: [PATCH net 1/3] selftests: drv: net: fix test failure on ipv6 sys
In reply to Mohsin BashirQuoted 28 lines · Mohsin Bashir
The
get_interface_infocall has ip version hard-coded which leads to failures on an IPV6 system. The NetDrvEnv class already gathers information about remote interface, so instead of fixing the local implementation switch to using cfg.remote_ifname.Before:
./drivers/net/ping.py
Traceback (most recent call last):File "/new_tests/./drivers/net/ping.py", line 217, in <module> main() File "/new_tests/./drivers/net/ping.py", line 204, in main get_interface_info(cfg) File "/new_tests/./drivers/net/ping.py", line 128, in get_interface_info raise KsftFailEx('Can not get remote interface')net.lib.py.ksft.KsftFailEx: Can not get remote interface
After:
./drivers/net/ping.py
TAP version 13
1..6
ok 1 ping.test_default # SKIP Test requires IPv4 connectivity ok 2 ping.test_xdp_generic_sb # SKIP Test requires IPv4 connectivity ok 3 ping.test_xdp_generic_mb # SKIP Test requires IPv4 connectivity ok 4 ping.test_xdp_native_sb # SKIP Test requires IPv4 connectivity ok 5 ping.test_xdp_native_mb # SKIP Test requires IPv4 connectivity ok 6 ping.test_xdp_offload # SKIP device does not support offloaded XDP
Totals: pass:0 fail:0 xfail:0 xpass:0 skip:6 error:0
Quoted 2 lines
Fixes 75cc19c8ff89 ("selftests: drv-net: add xdp cases for ping.py")Signed-off-by Mohsin Bashir <[email protected]>
Unrelated to this patch, but there is an ip() helper already. Can it be used instead of cmd() with shell=True?
Re: [PATCH net 2/3] selftests: drv: net: avoid skipping tests
In reply to Mohsin BashirQuoted 40 lines · Mohsin Bashir
On a system with either of the ipv4 or ipv6 information missing, tests are currently skipped. Ideally, the test should run as long as at least one address family is present. This patch make test run whenever possible.
Before:
./drivers/net/ping.py
TAP version 13
1..6
ok 1 ping.test_default # SKIP Test requires IPv4 connectivity ok 2 ping.test_xdp_generic_sb # SKIP Test requires IPv4 connectivity ok 3 ping.test_xdp_generic_mb # SKIP Test requires IPv4 connectivity ok 4 ping.test_xdp_native_sb # SKIP Test requires IPv4 connectivity ok 5 ping.test_xdp_native_mb # SKIP Test requires IPv4 connectivity ok 6 ping.test_xdp_offload # SKIP device does not support offloaded XDP
Totals: pass:0 fail:0 xfail:0 xpass:0 skip:6 error:0After:
./drivers/net/ping.py
TAP version 13
1..6
ok 1 ping.test_default
ok 2 ping.test_xdp_generic_sb
ok 3 ping.test_xdp_generic_mb
ok 4 ping.test_xdp_native_sb
ok 5 ping.test_xdp_native_mb
ok 6 ping.test_xdp_offload # SKIP device does not support offloaded XDP
Totals: pass:5 fail:0 xfail:0 xpass:0 skip:1 error:0Fixes 75cc19c8ff89 ("selftests: drv-net: add xdp cases for ping.py")Signed-off-by Mohsin Bashir <[email protected]>--- tools/testing/selftests/drivers/net/ping.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)tools/testing/selftests/drivers/net/ping.py +0
-0
tools/testing/selftests/drivers/net/ping.py from lib.py import defer, ethtool, ip · line 16
Quoted 6 lines
tools/testing/selftests/drivers/net/ping.py +2
-1@@ -12,7 +12,8 @@ from lib.py import defer, ethtool, ip no_sleep=False def _test_v4(cfg) -> None: - cfg.require_ipver("4") + if not cfg.addr_v["4"]: + return
What if cfg.remote_addr_v['4'] doesn't exist?
Quoted 13 lines
tools/testing/selftests/drivers/net/ping.py +2
-1cmd("ping -c 1 -W0.5 " + cfg.remote_addr_v["4"]) cmd("ping -c 1 -W0.5 " + cfg.addr_v["4"], host=cfg.remote)@@ -20,7 +21,8 @@ def _test_v4(cfg) -> None: cmd("ping -s 65000 -c 1 -W0.5 " + cfg.addr_v["4"], host=cfg.remote) def _test_v6(cfg) -> None: - cfg.require_ipver("6") + if not cfg.addr_v["6"]: + return cmd("ping -c 1 -W5 " + cfg.remote_addr_v["6"]) cmd("ping -c 1 -W5 " + cfg.addr_v["6"], host=cfg.remote)
Re: [PATCH net 3/3] selftests: drv: net: add version indicator
In reply to Mohsin BashirQuoted 28 lines · Mohsin Bashir
Currently, the test result does not differentiate between the cases when either one of the address families are configured or if both the address families are configured. Ideally, the result should report if a particular case was skipped.
./drivers/net/ping.py
TAP version 13
1..7
ok 1 ping.test_default_v4 # SKIP Test requires IPv4 connectivity ok 2 ping.test_default_v6
ok 3 ping.test_xdp_generic_sb
ok 4 ping.test_xdp_generic_mb
ok 5 ping.test_xdp_native_sb
ok 6 ping.test_xdp_native_mb
ok 7 ping.test_xdp_offload # SKIP device does not support offloaded XDP
Totals: pass:5 fail:0 xfail:0 xpass:0 skip:2 error:0Fixes 75cc19c8ff89 ("selftests: drv-net: add xdp cases for ping.py")Signed-off-by Mohsin Bashir <[email protected]>--- tools/testing/selftests/drivers/net/ping.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)tools/testing/selftests/drivers/net/ping.py +0
-0
tools/testing/selftests/drivers/net/ping.py def set_interface_init(cfg) -> None: · line 140
Quoted 6 lines
tools/testing/selftests/drivers/net/ping.py +2
-1@@ -136,13 +136,23 @@ def set_interface_init(cfg) -> None: cmd(f"ip link set dev {cfg.ifname} xdpoffload off", shell=True) cmd(f"ip link set dev {cfg.remote_ifname} mtu 1500", shell=True, host=cfg.remote) -def test_default(cfg, netnl) -> None: +def test_default_v4(cfg, netnl) -> None: + cfg.require_ipver("4")
With this patch, is the previous patch and this hunk still needed? I think you can drop patch 2/3 or both.
Jakub Kicinski
maintainerRe: [PATCH net 1/3] selftests: drv: net: fix test failure on ipv6 sys
In reply to David WeiQuoted 2 lines · On Fri, 2 May 2025 21:49:46 -0700 David Wei wrote:
Unrelated to this patch, but there is an
ip()helper already. Can it be used instead ofcmd()with shell=True?
The wrappers are mostly useful for JSON, parsing the JSON output is a few lines. For running a simple command we don't have strong guidance.
Jakub Kicinski
maintainerRe: [PATCH net 2/3] selftests: drv: net: avoid skipping tests
In reply to David WeiQuoted 6 lines · On Fri, 2 May 2025 21:54:11 -0700 David Wei wrote:
tools/testing/selftests/drivers/net/ping.py from lib.py import defer, ethtool, ip · line 16
Quoted 4 lines
def
_test_v4(cfg)-> None:tools/testing/selftests/drivers/net/ping.py +2
-1- cfg.require_ipver("4") + if not cfg.addr_v["4"]: + returnWhat if cfg.remote_addr_v['4'] doesn't exist?
Not sure if its super pythonic but it's set to None in the lib if user doesn't provide the config.
Jakub Kicinski
maintainerRe: [PATCH net 3/3] selftests: drv: net: add version indicator
In reply to David WeiQuoted 6 lines · On Fri, 2 May 2025 22:02:43 -0700 David Wei wrote:
tools/testing/selftests/drivers/net/ping.py def set_interface_init(cfg) -> None: · line 140
Quoted 3 lines
tools/testing/selftests/drivers/net/ping.py +2
-1-def test_default(cfg, netnl) -> None: +def test_default_v4(cfg, netnl) -> None: + cfg.require_ipver("4")With this patch, is the previous patch and this hunk still needed? I think you can drop patch 2/3 or both.
The previous patch makes the more "meaty" tests run when either ipver is available. But we still want an indication if both versions are supported by env but reporting *a* skip. Historically this is what the ping test was for, TBH, pretty much a sanity check for the env. But it ended up accumulating random XDP test cases :( Perhaps something to address in net-next..
Re: [PATCH net 2/3] selftests: drv: net: avoid skipping tests
In reply to Jakub KicinskiQuoted 10 lines · Jakub Kicinski
Quoted 6 lines · On Fri, 2 May 2025 21:54:11 -0700 David Wei wrote:
tools/testing/selftests/drivers/net/ping.py from lib.py import defer, ethtool, ip · line 16
Quoted 4 lines
def _test_v4(cfg) -> None:tools/testing/selftests/drivers/net/ping.py +2
-1- cfg.require_ipver("4") + if not cfg.addr_v["4"]: + returnWhat if cfg.remote_addr_v['4'] doesn't exist?
Not sure if its super pythonic but it's set to None in the lib if user doesn't provide the config.
Ah okay. I'm concerned about the next line:
Quoted 1 line
cmd("ping -c 1 -W0.5 " + cfg.remote_addr_v["4"]) If cfg.remote_addr_v["4"] is None by default then Python will complain:
Quoted 1 line
Quoted 1 line
Quoted 1 line
a = "foo test bar" + None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "NoneType") to str
Re: [PATCH net 2/3] selftests: drv: net: avoid skipping tests
Quoted 14 lines · David Wei
Quoted 10 lines · Jakub Kicinski
Quoted 6 lines · On Fri, 2 May 2025 21:54:11 -0700 David Wei wrote:
Quoted 4 lines
def
_test_v4(cfg)-> None:
-cfg.require_ipver("4")
+ if not cfg.addr_v["4"]:
+ returnWhat if cfg.remote_addr_v['4'] doesn't exist?
Not sure if its super pythonic but it's set to None in the lib if user doesn't provide the config.
Ah okay. I'm concerned about the next line:
Quoted 8 lines
Quoted 1 line
cmd("ping -c 1 -W0.5 " + cfg.remote_addr_v["4"])If cfg.remote_addr_v["4"] is None by default then Python will complain:
>>> a = "foo test bar" + None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "NoneType") to str
NVM, it's obviously checked for.
David Wei
Reviewed-byRe: [PATCH net 3/3] selftests: drv: net: add version indicator
In reply to Jakub KicinskiQuoted 8 lines · Jakub Kicinski
Quoted 6 lines · On Fri, 2 May 2025 22:02:43 -0700 David Wei wrote:
tools/testing/selftests/drivers/net/ping.py def set_interface_init(cfg) -> None: · line 140
Quoted 3 lines
tools/testing/selftests/drivers/net/ping.py +2
-1-def test_default(cfg, netnl) -> None: +def test_default_v4(cfg, netnl) -> None: + cfg.require_ipver("4")With this patch, is the previous patch and this hunk still needed? I think you can drop patch 2/3 or both.
Quoted 6 lines
The previous patch makes the more "meaty" tests run when either ipver is available. But we still want an indication if both versions are supported by env but reporting *a* skip. Historically this is what the ping test was for, TBH, pretty much a sanity check for the env. But it ended up accumulating random XDP test cases :( Perhaps something to address in net-next..
I see, makes sense.
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Fri, 2 May 2025 18:35:15 -0700 you wrote:
Fix
ping.pytest failure on an ipv6 system, and appropriately handle the cases where either one of the two address families (ipv4, ipv6) is not present.Mohsin Bashir (3):
selftests: drv: net: fix test failure on ipv6 sys
selftests: drv: net: avoid skipping tests
selftests: drv: net: add version indicator[...]
Here is the summary with links:
- [net,1/3] selftests: drv: net: fix test failure on ipv6 sys
https://git.kernel.org/netdev/net/c/b344a48cbe5f - [net,2/3] selftests: drv: net: avoid skipping tests https://git.kernel.org/netdev/net/c/8bb7d8e5cf7f - [net,3/3] selftests: drv: net: add version indicator https://git.kernel.org/netdev/net/c/4a9d494ca24b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html