diff mbox series

[net,2/3] selftests: drv: net: avoid skipping tests

Message ID 20250503013518.1722913-3-mohsin.bashr@gmail.com
State New
Headers show
Series selftests: drv: net: fix `ping.py` test failure | expand

Commit Message

Mohsin Bashir May 3, 2025, 1:35 a.m. UTC
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: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

Fixes: 75cc19c8ff89 ("selftests: drv-net: add xdp cases for ping.py")
Signed-off-by: Mohsin Bashir <mohsin.bashr@gmail.com>
---
 tools/testing/selftests/drivers/net/ping.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Jakub Kicinski May 5, 2025, 5:47 p.m. UTC | #1
On Fri, 2 May 2025 21:54:11 -0700 David Wei wrote:
> >   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?

Not sure if its super pythonic but it's set to None in the lib
if user doesn't provide the config.
David Wei May 5, 2025, 6:12 p.m. UTC | #2
On 5/5/25 10:47, Jakub Kicinski wrote:
> On Fri, 2 May 2025 21:54:11 -0700 David Wei wrote:
>>>    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?
> 
> 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:

>         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
David Wei May 5, 2025, 6:19 p.m. UTC | #3
On 5/5/25 11:12, David Wei wrote:
> On 5/5/25 10:47, Jakub Kicinski wrote:
>> On Fri, 2 May 2025 21:54:11 -0700 David Wei wrote:
>>>>    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?
>>
>> 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:
> 
>>         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.
diff mbox series

Patch

diff --git a/tools/testing/selftests/drivers/net/ping.py b/tools/testing/selftests/drivers/net/ping.py
index 5272e8b3536d..16b7d3ab0fc8 100755
--- a/tools/testing/selftests/drivers/net/ping.py
+++ b/tools/testing/selftests/drivers/net/ping.py
@@ -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)