Skip to contentSkip to conversation

selftests: drv-net: convert GRO and Toeplitz tests to work for drivers in NIPA

PATCH Superseded Jakub Kicinski 3 participants 30 messages Nov 18, 2025 – Nov 19, 2025

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

v2 cover selftests: drv-net: convert GRO and Toeplitz tests to work for drivers in NIPA

Main objective of this series is to convert the gro.sh and toeplitz.sh tests to be "NIPA-compatible" - meaning make use of the Python env, which lets us run the tests against either netdevsim or a real device.

The tests seem to have been written with a different flow in mind. Namely they source different bash "setup" scripts depending on arguments passed to the test. While I have nothing against the use of bash and the overall architecture - the existing code needs quite a bit of work (don't assume MAC/IP addresses, support remote endpoint over SSH). If I'm the one fixing it, I'd rather convert them to our "simplistic" Python.

This series rewrites the tests in Python while addressing their shortcomings. The functionality of running the test over loopback on a real device is retained but with a different method of invocation (see the last patch).

Once again we are dealing with a script which run over a variety of protocols (combination of [ipv4, ipv6, ipip] x [tcp, udp]). The first 4 patches add support for test variants to our scripts. We use the term "variant" in the same sense as the C kselftest_harness.h - variant is just a set of static input arguments.

Note that neither GRO nor the Toeplitz test fully passes for me on any HW I have access to. But this is unrelated to the conversion. This series is not making any real functional changes to the tests, it is limited to improving the "test harness" scripts.

v2:

 [patch  5] fix accidental modification of gitignore
 [patch  8] fix typo in "compared"
 [patch  9] fix typo I -> It

[patch 10] fix typoe configure -> configured
v1: https://lore.kernel.org/[email protected]

Jakub Kicinski (12):
selftests: net: py: coding style improvements
selftests: net: py: extract the case generation logic
selftests: net: py: add test variants
selftests: drv-net: xdp: use variants for qstat tests
selftests: net: relocate gro and toeplitz tests to drivers/net
selftests: net: py: support ksft ready without wait
selftests: net: py: read ip link info about remote dev
netdevsim: pass packets thru GRO on Rx
selftests: drv-net: add a Python version of the GRO test
selftests: drv-net: hw: convert the Toeplitz test to Python
netdevsim: add loopback support
selftests: net: remove old setup_* scripts

 tools/testing/selftests/drivers/net/Makefile  |   2 +
 .../testing/selftests/drivers/net/hw/Makefile |   6 +-
 tools/testing/selftests/net/Makefile          |   7 -
 tools/testing/selftests/net/lib/Makefile      |   1 +
 drivers/net/netdevsim/netdev.c                |  26 ++-
 .../testing/selftests/{ => drivers}/net/gro.c |   5 +-
 .../{net => drivers/net/hw}/toeplitz.c        |   7 +-
 .../testing/selftests/drivers/net/.gitignore  |   1 +
 tools/testing/selftests/drivers/net/gro.py    | 161 ++++++++++++++
 .../selftests/drivers/net/hw/.gitignore       |   1 +
 .../drivers/net/hw/lib/py/__init__.py         |   4 +-
 .../selftests/drivers/net/hw/toeplitz.py      | 208 ++++++++++++++++++
 .../selftests/drivers/net/lib/py/__init__.py  |   4 +-
 .../selftests/drivers/net/lib/py/env.py       |   2 +
 tools/testing/selftests/drivers/net/xdp.py    |  42 ++--
 tools/testing/selftests/net/.gitignore        |   2 -
 tools/testing/selftests/net/gro.sh            | 105 ---------
 .../selftests/net/lib/ksft_setup_loopback.sh  | 111 ++++++++++
 .../testing/selftests/net/lib/py/__init__.py  |   5 +-
 tools/testing/selftests/net/lib/py/ksft.py    |  93 ++++++--
 tools/testing/selftests/net/lib/py/nsim.py    |   2 +-
 tools/testing/selftests/net/lib/py/utils.py   |  20 +-
 tools/testing/selftests/net/setup_loopback.sh | 120 ----------
 tools/testing/selftests/net/setup_veth.sh     |  45 ----
 tools/testing/selftests/net/toeplitz.sh       | 199 -----------------
 .../testing/selftests/net/toeplitz_client.sh  |  28 ---
 26 files changed, 630 insertions(+), 577 deletions(-)
 rename tools/testing/selftests/{ => drivers}/net/gro.c (99%)
 rename tools/testing/selftests/{net => drivers/net/hw}/toeplitz.c (99%)
 create mode 100755 tools/testing/selftests/drivers/net/gro.py
 create mode 100755 tools/testing/selftests/drivers/net/hw/toeplitz.py
 delete mode 100755 tools/testing/selftests/net/gro.sh
 create mode 100755 tools/testing/selftests/net/lib/ksft_setup_loopback.sh
 delete mode 100644 tools/testing/selftests/net/setup_loopback.sh
 delete mode 100644 tools/testing/selftests/net/setup_veth.sh
 delete mode 100755 tools/testing/selftests/net/toeplitz.sh
 delete mode 100755 tools/testing/selftests/net/toeplitz_client.sh
Signature · 1 line
2.51.1
author maintainer
#1 lore raw

PATCH v2 1/12 selftests: net: py: coding style improvements

We're about to add more features here and finding new issues with old ones in place is hard. Address ruff checks:
- bare exceptions
- f-string with no params
- unused import

---
 tools/testing/selftests/net/lib/py/ksft.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tools/testing/selftests/net/lib/py/ksft.py +3 -4
index 83b1574f7719..56dd9bd060cd 100644
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 
-import builtins
 import functools
 import inspect
 import signal
@@ -163,7 +162,7 @@ KSFT_DISRUPTIVE = True
         entry = global_defer_queue.pop()
         try:
             entry.exec_only()
-        except:
+        except Exception:
             ksft_pr(f"Exception while handling defer / cleanup (callback {i} of {qlen_start})!")
             tb = traceback.format_exc()
             for line in tb.strip().split('\n'):
@@ -181,7 +180,7 @@ KSFT_DISRUPTIVE = True
     @functools.wraps(func)
     def wrapper(*args, **kwargs):
         if not KSFT_DISRUPTIVE:
-            raise KsftSkipEx(f"marked as disruptive")
+            raise KsftSkipEx("marked as disruptive")
         return func(*args, **kwargs)
     return wrapper
 
@@ -199,7 +198,7 @@ KSFT_DISRUPTIVE = True
             return False
         try:
             return bool(int(value))
-        except:
+        except Exception:
             raise Exception(f"failed to parse {name}")
 
     if "DISRUPTIVE" in env:
Signature · 1 line
2.51.1
#2 lore raw

Re: [PATCH net-next v2 01/12] selftests: net: py: coding style improvements

Quoted 23 lines · Jakub Kicinski

We're about to add more features here and finding new issues with old ones in place is hard. Address ruff checks:
- bare exceptions
- f-string with no params
- unused import

---
 tools/testing/selftests/net/lib/py/ksft.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tools/testing/selftests/net/lib/py/ksft.py +0 -1
index 83b1574f7719..56dd9bd060cd 100644
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 
-import builtins
 import functools
 import inspect
 import signal

tools/testing/selftests/net/lib/py/ksft.py KSFT_DISRUPTIVE = True · line 165

Quoted 5 lines
tools/testing/selftests/net/lib/py/ksft.py +1 -1
@@ -163,7 +162,7 @@ KSFT_DISRUPTIVE = True
         entry = global_defer_queue.pop()
         try:
             entry.exec_only()
-        except:
+        except Exception:

This used to catch KsftTerminate, which we use for SIGTERM handling, now it doesn't anymore. I think it could legitimately appear in that context if SIGTERM si delivered while exec_only() is running.

IMHO it should catch BaseException, like ksft_run() already does.

Quoted 14 lines
tools/testing/selftests/net/lib/py/ksft.py +1 -1
             ksft_pr(f"Exception while handling defer / cleanup (callback {i} of {qlen_start})!")
             tb = traceback.format_exc()
             for line in tb.strip().split('\n'):
@@ -181,7 +180,7 @@ KSFT_DISRUPTIVE = True
     @functools.wraps(func)
     def wrapper(*args, **kwargs):
         if not KSFT_DISRUPTIVE:
-            raise KsftSkipEx(f"marked as disruptive")
+            raise KsftSkipEx("marked as disruptive")
         return func(*args, **kwargs)
     return wrapper
 

tools/testing/selftests/net/lib/py/ksft.py KSFT_DISRUPTIVE = True · line 202

Quoted 6 lines
tools/testing/selftests/net/lib/py/ksft.py +1 -1
@@ -199,7 +198,7 @@ KSFT_DISRUPTIVE = True
             return False
         try:
             return bool(int(value))
-        except:
+        except Exception:
             raise Exception(f"failed to parse {name}")

I think this will end up being called from inside the try/except in ksft_run() and therefore should be OK like this. It's actually more correct like this, SIGTERM shouldn't cause "failed to parse" errors.

Quoted 2 lines
tools/testing/selftests/net/lib/py/ksft.py +0 -0
     if "DISRUPTIVE" in env:
author maintainer
#3 lore raw

Re: [PATCH net-next v2 01/12] selftests: net: py: coding style improvements

Quoted 11 lines · On Wed, 19 Nov 2025 14:40:41 +0100 Petr Machata wrote:

Review KSFT_DISRUPTIVE = True · line 165

Quoted 6 lines
(quoted diff) +1 -1
@@ -163,7 +162,7 @@ KSFT_DISRUPTIVE = True
         entry = global_defer_queue.pop()
         try:
             entry.exec_only()
-        except:
+        except Exception:  

This used to catch KsftTerminate, which we use for SIGTERM handling, now it doesn't anymore. I think it could legitimately appear in that context if SIGTERM si delivered while exec_only() is running.

Quoted 1 line

IMHO it should catch BaseException, like ksft_run() already does.

TBH I haven't thought of this. Are you thinking that we shouldn't interrupt the execution of deferred cleanups when SIGTERM arrives? Fair point, but I think we'd need more code to handle that properly 🤔️ Right now we ignore SIGTERM which isn't great. After this patch we'll no longer ignore it and have the whole test exit. Neither actually catches the exception and sets stop=True in ksft_run()..

WDYT about leaving this patch as is and doing this on top:

tools/testing/selftests/net/lib/py/ksft.py +6 -1
index 83b1574f7719..5a667ad22ef4 100644
@@ -268,7 +268,12 @@ KSFT_DISRUPTIVE = True
             KSFT_RESULT = False
             cnt_key = 'fail'
 
-        ksft_flush_defer()
+        try:
+            ksft_flush_defer()
+        except BaseException as e:
+            stop |= isinstance(e, KeyboardInterrupt)
+            # Flush was interrupted, try to finish the job best we can
+            ksft_flush_defer()
 
         if not cnt_key:
             cnt_key = 'pass' if KSFT_RESULT else 'fail'
#4 lore raw

Re: [PATCH net-next v2 01/12] selftests: net: py: coding style improvements

Quoted 12 lines · Jakub Kicinski
Quoted 11 lines · On Wed, 19 Nov 2025 14:40:41 +0100 Petr Machata wrote:

Review KSFT_DISRUPTIVE = True · line 165

Quoted 6 lines
(quoted diff) +1 -1
@@ -163,7 +162,7 @@ KSFT_DISRUPTIVE = True
         entry = global_defer_queue.pop()
         try:
             entry.exec_only()
-        except:
+        except Exception:  

This used to catch KsftTerminate, which we use for SIGTERM handling, now it doesn't anymore. I think it could legitimately appear in that context if SIGTERM si delivered while exec_only() is running.

Quoted 8 lines
Quoted 1 line

IMHO it should catch BaseException, like ksft_run() already does.

TBH I haven't thought of this. Are you thinking that we shouldn't interrupt the execution of deferred cleanups when SIGTERM arrives? Fair point, but I think we'd need more code to handle that properly 🤔️ Right now we ignore SIGTERM which isn't great. After this patch we'll no longer ignore it and have the whole test exit. Neither actually catches the exception and sets stop=True in ksft_run()..

Well, previously at least the rest of the defer queue would be run, now it's skipped. Which -- OK, likely if you SIGTERM in the middle of a cleanup, chances are the cleanup is stuck and the sigterm then skips it, which is what you want.

It's a pick your poison. Ignore C-c or ignore deferred cleanups :)

Given this is supposed to be a cleanup patch, it would make sense to just s/bare except/except BaseException/ and leave the behavior broken. The commit message indicates it's a NOP make-linter-happy patch, but then it's not really.

Quoted 1 line

WDYT about leaving this patch as is and doing this on top:

It's a good stop-gap.

Quoted 18 lines
tools/testing/selftests/net/lib/py/ksft.py +6 -1
index 83b1574f7719..5a667ad22ef4 100644
@@ -268,7 +268,12 @@ KSFT_DISRUPTIVE = True
             KSFT_RESULT = False
             cnt_key = 'fail'
 
-        ksft_flush_defer()
+        try:
+            ksft_flush_defer()
+        except BaseException as e:
+            stop |= isinstance(e, KeyboardInterrupt)
+            # Flush was interrupted, try to finish the job best we can
+            ksft_flush_defer()
 
         if not cnt_key:
             cnt_key = 'pass' if KSFT_RESULT else 'fail'
author maintainer
#5 lore raw

PATCH v2 2/12 selftests: net: py: extract the case generation logic

In reply to Jakub Kicinski

In preparation for adding test variants move the test case collection logic to a dedicated function. New helper returns

(function, args, name, )

tuples. The main test loop can simply run them, not much logic or discernment needed.

---
 tools/testing/selftests/net/lib/py/ksft.py | 31 +++++++++++++++-------
 1 file changed, 22 insertions(+), 9 deletions(-)
tools/testing/selftests/net/lib/py/ksft.py +22 -9
index 56dd9bd060cd..52c42c313cf2 100644
@@ -135,7 +135,7 @@ KSFT_DISRUPTIVE = True
         time.sleep(sleep)
 
 
-def ktap_result(ok, cnt=1, case="", comment=""):
+def ktap_result(ok, cnt=1, case_name="", comment=""):
     global KSFT_RESULT_ALL
     KSFT_RESULT_ALL = KSFT_RESULT_ALL and ok
 
@@ -145,8 +145,8 @@ KSFT_DISRUPTIVE = True
     res += "ok "
     res += str(cnt) + " "
     res += KSFT_MAIN_NAME
-    if case:
-        res += "." + str(case.__name__)
+    if case_name:
+        res += "." + case_name
     if comment:
         res += " # " + comment
     print(res, flush=True)
@@ -219,9 +219,13 @@ KSFT_DISRUPTIVE = True
         ksft_pr(f"Ignoring SIGTERM (cnt: {term_cnt}), already exiting...")
 
 
-def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
-    cases = cases or []
+def _ksft_generate_test_cases(cases, globs, case_pfx, args):
+    """Generate a flat list of (func, args, name) tuples"""
 
+    cases = cases or []
+    test_cases = []
+
+    # If using the globs method find all relevant functions
     if globs and case_pfx:
         for key, value in globs.items():
             if not callable(value):
@@ -231,6 +235,15 @@ KSFT_DISRUPTIVE = True
                     cases.append(value)
                     break
 
+    for func in cases:
+        test_cases.append((func, args, func.__name__))
+
+    return test_cases
+
+
+def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
+    test_cases = _ksft_generate_test_cases(cases, globs, case_pfx, args)
+
     global term_cnt
     term_cnt = 0
     prev_sigterm = signal.signal(signal.SIGTERM, _ksft_intr)
@@ -238,19 +251,19 @@ KSFT_DISRUPTIVE = True
     totals = {"pass": 0, "fail": 0, "skip": 0, "xfail": 0}
 
     print("TAP version 13", flush=True)
-    print("1.." + str(len(cases)), flush=True)
+    print("1.." + str(len(test_cases)), flush=True)
 
     global KSFT_RESULT
     cnt = 0
     stop = False
-    for case in cases:
+    for func, args, name in test_cases:
         KSFT_RESULT = True
         cnt += 1
         comment = ""
         cnt_key = ""
 
         try:
-            case(*args)
+            func(*args)
         except KsftSkipEx as e:
             comment = "SKIP " + str(e)
             cnt_key = 'skip'
@@ -272,7 +285,7 @@ KSFT_DISRUPTIVE = True
         if not cnt_key:
             cnt_key = 'pass' if KSFT_RESULT else 'fail'
 
-        ktap_result(KSFT_RESULT, cnt, case, comment=comment)
+        ktap_result(KSFT_RESULT, cnt, name, comment=comment)
         totals[cnt_key] += 1
 
         if stop:
Signature · 1 line
2.51.1
Reviewed-by on v2 2/12
#6 lore raw

Re: [PATCH net-next v2 02/12] selftests: net: py: extract the case generation logic

Quoted 9 lines · Jakub Kicinski

In preparation for adding test variants move the test case collection logic to a dedicated function. New helper returns

(function, args, name, )

tuples. The main test loop can simply run them, not much logic or discernment needed.

author maintainer
#7 lore raw

PATCH v2 3/12 selftests: net: py: add test variants

In reply to Jakub Kicinski

There's a lot of cases where we try to re-run the same code with different parameters. We currently need to either use a generator method or create a "main" case implementation which then gets called by trivial case functions:

def _test(x, y, z):

     ...

def case_int():

     _test(1, 2, 3)

def case_str():

     _test('a', 'b', 'c')

Add support for variants, similar to kselftests_harness.h and a lot of other frameworks. Variants can be added as decorator to test functions:

@ksft_variants([(1, 2, 3), ('a', 'b', 'c')])
def case(x, y, z):

     ...

ksft_run() will auto-generate case names:
case.1_2_3
case.a_b_c

Because the names may not always be pretty (and to avoid forcing classes to implement case-friendly __str__()) add a wrapper class KsftNamedVariant which lets the user specify the name for the variant.

Note that ksft_run's args are still supported. ksft_run splices args and variant params together.

---
 .../drivers/net/hw/lib/py/__init__.py         |  4 +-
 .../selftests/drivers/net/lib/py/__init__.py  |  4 +-
 .../testing/selftests/net/lib/py/__init__.py  |  5 +-
 tools/testing/selftests/net/lib/py/ksft.py    | 57 ++++++++++++++++++-
 4 files changed, 63 insertions(+), 7 deletions(-)
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +2 -2
index fb010a48a5a1..0c61debf86fb 100644
@@ -25,7 +25,7 @@ KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
         fd_read_timeout, ip, rand_port, wait_port_listen, wait_file
     from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
     from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
-        ksft_setup
+        ksft_setup, ksft_variants, KsftNamedVariant
     from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \
         ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none
     from drivers.net.lib.py import GenerateTraffic, Remote
@@ -40,7 +40,7 @@ KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
                "wait_port_listen", "wait_file",
                "KsftSkipEx", "KsftFailEx", "KsftXfailEx",
                "ksft_disruptive", "ksft_exit", "ksft_pr", "ksft_run",
-               "ksft_setup",
+               "ksft_setup", "ksft_variants", "KsftNamedVariant",
                "ksft_eq", "ksft_ge", "ksft_in", "ksft_is", "ksft_lt",
                "ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt",
                "ksft_not_none", "ksft_not_none",
tools/testing/selftests/drivers/net/lib/py/__init__.py +2 -2
index b0c6300150fb..d9d035634a31 100644
@@ -25,7 +25,7 @@ KSFT_DIR = (Path(__file__).parent / "../../../..").resolve()
         fd_read_timeout, ip, rand_port, wait_port_listen, wait_file
     from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
     from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
-        ksft_setup
+        ksft_setup, ksft_variants, KsftNamedVariant
     from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \
         ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none
 
@@ -38,7 +38,7 @@ KSFT_DIR = (Path(__file__).parent / "../../../..").resolve()
                "wait_port_listen", "wait_file",
                "KsftSkipEx", "KsftFailEx", "KsftXfailEx",
                "ksft_disruptive", "ksft_exit", "ksft_pr", "ksft_run",
-               "ksft_setup",
+               "ksft_setup", "ksft_variants", "KsftNamedVariant",
                "ksft_eq", "ksft_ge", "ksft_in", "ksft_is", "ksft_lt",
                "ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt",
                "ksft_not_none", "ksft_not_none"]
tools/testing/selftests/net/lib/py/__init__.py +3 -2
index 97b7cf2b20eb..40f9ce307dd1 100644
@@ -8,7 +8,8 @@ from .consts import KSRC
 from .ksft import KsftFailEx, KsftSkipEx, KsftXfailEx, ksft_pr, ksft_eq, \
     ksft_ne, ksft_true, ksft_not_none, ksft_in, ksft_not_in, ksft_is, \
     ksft_ge, ksft_gt, ksft_lt, ksft_raises, ksft_busy_wait, \
-    ktap_result, ksft_disruptive, ksft_setup, ksft_run, ksft_exit
+    ktap_result, ksft_disruptive, ksft_setup, ksft_run, ksft_exit, \
+    ksft_variants, KsftNamedVariant
 from .netns import NetNS, NetNSEnter
 from .nsim import NetdevSim, NetdevSimDev
 from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \
@@ -21,7 +22,7 @@ __all__ = ["KSRC",
            "ksft_ne", "ksft_true", "ksft_not_none", "ksft_in", "ksft_not_in",
            "ksft_is", "ksft_ge", "ksft_gt", "ksft_lt", "ksft_raises",
            "ksft_busy_wait", "ktap_result", "ksft_disruptive", "ksft_setup",
-           "ksft_run", "ksft_exit",
+           "ksft_run", "ksft_exit", "ksft_variants", "KsftNamedVariant",
            "NetNS", "NetNSEnter",
            "CmdExitFailure", "fd_read_timeout", "cmd", "bkg", "defer",
            "bpftool", "ip", "ethtool", "bpftrace", "rand_port",
tools/testing/selftests/net/lib/py/ksft.py +56 -1

69 lines not on this page · raw message

Signature · 1 line
2.51.1
#8 lore raw

Re: [PATCH net-next v2 03/12] selftests: net: py: add test variants

Quoted 39 lines · Jakub Kicinski
tools/testing/selftests/net/lib/py/ksft.py +31 -0
index 52c42c313cf2..47e0af210bee 100644
@@ -185,6 +185,49 @@ KSFT_DISRUPTIVE = True
     return wrapper
 
 
+class KsftNamedVariant:
+    """ Named string name + argument list tuple for @ksft_variants """
+
+    def __init__(self, name, *params):
+        self.params = params
+        self.name = name or "_".join([str(x) for x in self.params])
+
+
+def ksft_variants(params):
+    """
+    Decorator defining the sets of inputs for a test.
+    The parameters will be included in the name of the resulting sub-case.
+    Parameters can be either single object, tuple or a KsftNamedVariant.
+    The argument can be a list or a generator.
+
+    Example:
+
+    @ksft_variants([
+        (1, "a"),
+        (2, "b"),
+        KsftNamedVariant("three", 3, "c"),
+    ])
+    def my_case(cfg, a, b):
+        pass # ...
+
+    ksft_run(cases=[my_case], args=(cfg, ))
+
+    Will generate cases:
+        my_case.1_a
+        my_case.2_b
+        my_case.three

tools/testing/selftests/net/lib/py/ksft.py KSFT_DISRUPTIVE = True · line 228

Quoted 10 lines
tools/testing/selftests/net/lib/py/ksft.py +10 -0
+    """
+
+    def decorator(func):
+        @functools.wraps(func)
+        def wrapper():
+            return func
+        wrapper.ksft_variants = params
+        wrapper.original_func = func
+        return wrapper
+    return decorator

This uses the wrapper() merely as a vessel to carry the three attributes. I think the idea would be better expressed as a namedtupple

from collections import namedtuple

KsftCaseFunction = namedtuple("KsftCaseFunction",
['name', 'original_func', 'variants'])

def ksft_variants(params):
return lambda func: KsftCaseFunction(func.__name__, func, params)

tools/testing/selftests/net/lib/py/ksft.py KSFT_DISRUPTIVE = True · line 282

Quoted 11 lines
tools/testing/selftests/net/lib/py/ksft.py +3 -1
+
+
 def ksft_setup(env):
     """
     Setup test framework global state from the environment.
@@ -236,7 +279,19 @@ KSFT_DISRUPTIVE = True
                     break
 
     for func in cases:
-        test_cases.append((func, args, func.__name__))
+        if hasattr(func, 'ksft_variants'):

Then this could just be if callable(func) just call it, else the complex processing.

I'm not married to the namedtuple idea, but I consider using a function as essentially a struct wrong. It should be a general object.

Quoted 14 lines
tools/testing/selftests/net/lib/py/ksft.py +12 -0
+            # Parametrized test - create case for each param
+            for param in func.ksft_variants:
+                if not isinstance(param, KsftNamedVariant):
+                    if not isinstance(param, tuple):
+                        param = (param, )
+                    param = KsftNamedVariant(None, *param)
+
+                test_cases.append((func.original_func,
+                                   (*args, *param.params),
+                                   func.__name__ + "." + param.name))
+        else:
+            test_cases.append((func, args, func.__name__))
 
     return test_cases
author maintainer
#9 lore raw

PATCH v2 4/12 selftests: drv-net: xdp: use variants for qstat tests

In reply to Jakub Kicinski

Use just-added ksft variants for XDP qstat tests.

While at it correct the number of packets, we're sending 1000 packets now.

---
 tools/testing/selftests/drivers/net/xdp.py | 42 ++++++++--------------
 1 file changed, 14 insertions(+), 28 deletions(-)
tools/testing/selftests/drivers/net/xdp.py +14 -28
index 834a37ae7d0d..e54df158dfe9 100755
@@ -12,6 +12,7 @@ from dataclasses import dataclass
 from enum import Enum
 
 from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_ge, ksft_ne, ksft_pr
+from lib.py import KsftNamedVariant, ksft_variants
 from lib.py import KsftFailEx, NetDrvEpEnv
 from lib.py import EthtoolFamily, NetdevFamily, NlError
 from lib.py import bkg, cmd, rand_port, wait_port_listen
@@ -672,7 +673,18 @@ from lib.py import ip, bpftool, defer
     _validate_res(res, offset_lst, pkt_sz_lst)
 
 
-def _test_xdp_native_ifc_stats(cfg, act):
+@ksft_variants([
+    KsftNamedVariant("pass", XDPAction.PASS),
+    KsftNamedVariant("drop", XDPAction.DROP),
+    KsftNamedVariant("tx", XDPAction.TX),
+])
+def test_xdp_native_qstats(cfg, act):
+    """
+    Send 1000 messages. Expect XDP action specified in @act.
+    Make sure the packets were counted to interface level qstats
+    (Rx, and Tx if act is TX).
+    """
+
     cfg.require_cmd("socat")
 
     bpf_info = BPFProgInfo("xdp_prog", "xdp_native.bpf.o", "xdp", 1500)
@@ -733,30 +745,6 @@ from lib.py import ip, bpftool, defer
             ksft_ge(after['tx-packets'], before['tx-packets'])
 
 
-def test_xdp_native_qstats_pass(cfg):
-    """
-    Send 2000 messages, expect XDP_PASS, make sure the packets were counted
-    to interface level qstats (Rx).
-    """
-    _test_xdp_native_ifc_stats(cfg, XDPAction.PASS)
-
-
-def test_xdp_native_qstats_drop(cfg):
-    """
-    Send 2000 messages, expect XDP_DROP, make sure the packets were counted
-    to interface level qstats (Rx).
-    """
-    _test_xdp_native_ifc_stats(cfg, XDPAction.DROP)
-
-
-def test_xdp_native_qstats_tx(cfg):
-    """
-    Send 2000 messages, expect XDP_TX, make sure the packets were counted
-    to interface level qstats (Rx and Tx)
-    """
-    _test_xdp_native_ifc_stats(cfg, XDPAction.TX)
-
-
 def main():
     """
     Main function to execute the XDP tests.
@@ -781,9 +769,7 @@ from lib.py import ip, bpftool, defer
                 test_xdp_native_adjst_tail_shrnk_data,
                 test_xdp_native_adjst_head_grow_data,
                 test_xdp_native_adjst_head_shrnk_data,
-                test_xdp_native_qstats_pass,
-                test_xdp_native_qstats_drop,
-                test_xdp_native_qstats_tx,
+                test_xdp_native_qstats,
             ],
             args=(cfg,))
     ksft_exit()
Signature · 1 line
2.51.1
author maintainer
#11 lore raw

PATCH v2 5/12 selftests: net: relocate gro and toeplitz tests to drivers/net

In reply to Jakub Kicinski

The GRO test can run on a real device or a veth.
The Toeplitz hash test can only run on a real device.
Move them from net/ to drivers/net/ and drivers/net/hw/ respectively.

There are two scripts which set up the environment for these tests setup_loopback.sh and setup_veth.sh. Move those scripts to net/lib. The paths to the setup files are a little ugly but they will be deleted shortly.

toeplitz_client.sh is not a test in itself, but rather a helper to send traffic, so add it to TEST_FILES rather than TEST_PROGS.

---
v2:
- fix accidental modification of gitignore
v1: https://lore.kernel.org/[email protected]

---
 tools/testing/selftests/drivers/net/Makefile               | 2 ++
 tools/testing/selftests/drivers/net/hw/Makefile            | 7 ++++++-
 tools/testing/selftests/net/Makefile                       | 7 -------
 tools/testing/selftests/net/lib/Makefile                   | 2 ++
 tools/testing/selftests/{ => drivers}/net/gro.c            | 2 +-
 tools/testing/selftests/{net => drivers/net/hw}/toeplitz.c | 2 +-
 tools/testing/selftests/drivers/net/.gitignore             | 1 +
 tools/testing/selftests/{ => drivers}/net/gro.sh           | 4 ++--
 tools/testing/selftests/drivers/net/hw/.gitignore          | 1 +
 .../testing/selftests/{net => drivers/net/hw}/toeplitz.sh  | 2 +-
 .../selftests/{net => drivers/net/hw}/toeplitz_client.sh   | 0
 tools/testing/selftests/net/.gitignore                     | 2 --
 tools/testing/selftests/net/{ => lib}/setup_loopback.sh    | 0
 tools/testing/selftests/net/{ => lib}/setup_veth.sh        | 0
 14 files changed, 17 insertions(+), 15 deletions(-)
 rename tools/testing/selftests/{ => drivers}/net/gro.c (99%)
 rename tools/testing/selftests/{net => drivers/net/hw}/toeplitz.c (99%)
 rename tools/testing/selftests/{ => drivers}/net/gro.sh (95%)
 rename tools/testing/selftests/{net => drivers/net/hw}/toeplitz.sh (98%)
 rename tools/testing/selftests/{net => drivers/net/hw}/toeplitz_client.sh (100%)
 rename tools/testing/selftests/net/{ => lib}/setup_loopback.sh (100%)
 rename tools/testing/selftests/net/{ => lib}/setup_veth.sh (100%)
tools/testing/selftests/drivers/net/Makefile +2 -0
index 33f4816216ec..7083a8707c4e 100644
@@ -6,10 +6,12 @@ TEST_INCLUDES := $(wildcard lib/py/*.py) \
 		 ../../net/lib.sh \
 
 TEST_GEN_FILES := \
+	gro \
 	napi_id_helper \
 # end of TEST_GEN_FILES
 
 TEST_PROGS := \
+	gro.sh \
 	hds.py \
 	napi_id.py \
 	napi_threaded.py \
tools/testing/selftests/drivers/net/hw/Makefile +6 -1
index 8133d1a0051c..c9dced8c934a 100644
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0+ OR MIT
 
-TEST_GEN_FILES = iou-zcrx
+TEST_GEN_FILES := \
+	iou-zcrx \
+	toeplitz \
+# end of TEST_GEN_FILES
 
 TEST_PROGS = \
 	csum.py \
@@ -21,12 +24,14 @@ TEST_PROGS = \
 	rss_ctx.py \
 	rss_flow_label.py \
 	rss_input_xfrm.py \
+	toeplitz.sh \
 	tso.py \
 	xsk_reconfig.py \
 	#
 
 TEST_FILES := \
 	ethtool_lib.sh \
+	toeplitz_client.sh \
 	#
 
 TEST_INCLUDES := \
tools/testing/selftests/net/Makefile +0 -7
index b5127e968108..b66ba04f19d9 100644
@@ -38,7 +38,6 @@ TEST_PROGS := \
 	fq_band_pktlimit.sh \
 	gre_gso.sh \
 	gre_ipv6_lladdr.sh \
-	gro.sh \
 	icmp.sh \
 	icmp_redirect.sh \
 	io_uring_zerocopy_tx.sh \
@@ -121,8 +120,6 @@ TEST_PROGS := \
 # end of TEST_PROGS
 
 TEST_PROGS_EXTENDED := \
-	toeplitz.sh \
-	toeplitz_client.sh \
 	xfrm_policy_add_speed.sh \
 # end of TEST_PROGS_EXTENDED
 
@@ -130,7 +127,6 @@ TEST_GEN_FILES := \
 	bind_bhash \
 	cmsg_sender \
 	fin_ack_lat \
-	gro \
 	hwtstamp_config \
 	io_uring_zerocopy_tx \
 	ioam6_parser \
@@ -159,7 +155,6 @@ TEST_GEN_FILES := \
 	tcp_mmap \
 	tfo \
 	timestamping \
-	toeplitz \
 	txring_overwrite \
 	txtimestamp \
 	udpgso \
@@ -193,8 +188,6 @@ TEST_FILES := \
 	in_netns.sh \
 	lib.sh \
 	settings \
-	setup_loopback.sh \
-	setup_veth.sh \
 # end of TEST_FILES
 
 # YNL files, must be before "include ..lib.mk"
tools/testing/selftests/net/lib/Makefile +2 -0
index ce795bc0a1af..c10796933d42 100644
@@ -8,6 +8,8 @@ CFLAGS += -I../../
 TEST_FILES := \
 	../../../../net/ynl \
 	../../../../../Documentation/netlink/specs \
+	setup_loopback.sh \
+	setup_veth.sh \
 # end of TEST_FILES
 
 TEST_GEN_FILES := \
tools/testing/selftests/drivers/net/gro.c renamed from tools/testing/selftests/net/gro.c +1 -1
similarity index 99%
rename from tools/testing/selftests/net/gro.c
rename to tools/testing/selftests/drivers/net/gro.c
index cfc39f70635d..9b9be0cf8f7f 100644
@@ -57,7 +57,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "../kselftest.h"
+#include "../../kselftest.h"
 
 #define DPORT 8000
 #define SPORT 1500
tools/testing/selftests/drivers/net/hw/toeplitz.c renamed from tools/testing/selftests/net/toeplitz.c +1 -1
similarity index 99%
rename from tools/testing/selftests/net/toeplitz.c
rename to tools/testing/selftests/drivers/net/hw/toeplitz.c
index 9ba03164d73a..bf74aa25345d 100644
@@ -52,7 +52,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "../kselftest.h"
+#include "../../../kselftest.h"
 
 #define TOEPLITZ_KEY_MIN_LEN	40
 #define TOEPLITZ_KEY_MAX_LEN	60
tools/testing/selftests/drivers/net/.gitignore +1 -0
index 585ecb4d5dc4..3633c7a3ed65 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
+gro
 napi_id_helper
 psp_responder
tools/testing/selftests/drivers/net/gro.sh renamed from tools/testing/selftests/net/gro.sh +2 -2
similarity index 95%
rename from tools/testing/selftests/net/gro.sh
rename to tools/testing/selftests/drivers/net/gro.sh
index 4c5144c6f652..bd3cf6d02eda 100755
@@ -90,9 +90,9 @@ while getopts "i:t:p:" opt; do
 done
 
 if [ -n "$dev" ]; then
-	source setup_loopback.sh
+	source $(dirname $0)/../../net/lib/setup_loopback.sh
 else
-	source setup_veth.sh
+	source $(dirname $0)/../../net/lib/setup_veth.sh
 fi
 
 setup
tools/testing/selftests/drivers/net/hw/.gitignore +1 -0
index 6942bf575497..46540468a775 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 iou-zcrx
 ncdevmem
+toeplitz
tools/testing/selftests/drivers/net/hw/toeplitz.sh renamed from tools/testing/selftests/net/toeplitz.sh +1 -1
similarity index 98%
rename from tools/testing/selftests/net/toeplitz.sh
rename to tools/testing/selftests/drivers/net/hw/toeplitz.sh
index 8ff172f7bb1b..d236b666dd3b 100755
@@ -11,7 +11,7 @@
 # invoke as ./toeplitz.sh (-i <iface>) -u|-t -4|-6 \
 # [(-rss -irq_prefix <irq-pattern-prefix>)|(-rps <rps_map>)]
 
-source setup_loopback.sh
+source $(dirname $0)/../../../net/lib/setup_loopback.sh
 readonly SERVER_IP4="192.168.1.200/24"
 readonly SERVER_IP6="fda8::1/64"
 readonly SERVER_MAC="aa:00:00:00:00:02"
tools/testing/selftests/drivers/net/hw/toeplitz_client.sh renamed from tools/testing/selftests/net/toeplitz_client.sh +0 -0
similarity index 100%
rename from tools/testing/selftests/net/toeplitz_client.sh
rename to tools/testing/selftests/drivers/net/hw/toeplitz_client.sh
tools/testing/selftests/net/.gitignore +0 -2
index e89a60581a13..e139b7186c6c 100644
@@ -7,7 +7,6 @@ cmsg_sender
 diag_uid
 epoll_busy_poll
 fin_ack_lat
-gro
 hwtstamp_config
 io_uring_zerocopy_tx
 ioam6_parser
@@ -56,7 +55,6 @@ tcp_port_share
 tfo
 timestamping
 tls
-toeplitz
 tools
 tun
 txring_overwrite
tools/testing/selftests/net/lib/setup_loopback.sh renamed from tools/testing/selftests/net/setup_loopback.sh +0 -0
similarity index 100%
rename from tools/testing/selftests/net/setup_loopback.sh
rename to tools/testing/selftests/net/lib/setup_loopback.sh
tools/testing/selftests/net/lib/setup_veth.sh renamed from tools/testing/selftests/net/setup_veth.sh +0 -0
similarity index 100%
rename from tools/testing/selftests/net/setup_veth.sh
rename to tools/testing/selftests/net/lib/setup_veth.sh
Signature · 1 line
2.51.1
Reviewed-by on v2 5/12
#12 lore raw

Re: [PATCH net-next v2 05/12] selftests: net: relocate gro and toeplitz tests to drivers/net

Quoted 9 lines · Jakub Kicinski

The GRO test can run on a real device or a veth.
The Toeplitz hash test can only run on a real device.
Move them from net/ to drivers/net/ and drivers/net/hw/ respectively.

There are two scripts which set up the environment for these tests setup_loopback.sh and setup_veth.sh. Move those scripts to net/lib. The paths to the setup files are a little ugly but they will be deleted shortly.

Quoted 4 lines

toeplitz_client.sh is not a test in itself, but rather a helper to send traffic, so add it to TEST_FILES rather than TEST_PROGS.

author maintainer
#13 lore raw

PATCH v2 6/12 selftests: net: py: support ksft ready without wait

In reply to Jakub Kicinski

There's a common synchronization problem when a script (Python test) uses a C program to set up some state (usually start a receiving process for traffic). The script needs to know when the process has fully initialized. The inverse of the problem exists for shutting the process down - we need a reliable way to tell the process to exit.

We added helpers to do this safely in
commit 71477137994f ("selftests: drv-net: add a way to wait for a local process") unfortunately the two operations (wait for init, and shutdown) are controlled by a single parameter (ksft_wait). Add support for using ksft_ready without using the second fd for exit.

This is useful for programs which wait for a specific number of packets to rx so exit_wait is a good match, but we still need to wait for init.

---
 tools/testing/selftests/net/lib/py/utils.py | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
tools/testing/selftests/net/lib/py/utils.py +12 -8
index cb40ecef9456..106ee1f2df86 100644
@@ -32,7 +32,7 @@ import time
     Use bkg() instead to run a command in the background.
     """
     def __init__(self, comm, shell=None, fail=True, ns=None, background=False,
-                 host=None, timeout=5, ksft_wait=None):
+                 host=None, timeout=5, ksft_ready=None, ksft_wait=None):
         if ns:
             comm = f'ip netns exec {ns} ' + comm
 
@@ -52,21 +52,25 @@ import time
             # ksft_wait lets us wait for the background process to fully start,
             # we pass an FD to the child process, and wait for it to write back.
             # Similarly term_fd tells child it's time to exit.
-            pass_fds = ()
+            pass_fds = []
             env = os.environ.copy()
             if ksft_wait is not None:
-                rfd, ready_fd = os.pipe()
                 wait_fd, self.ksft_term_fd = os.pipe()
-                pass_fds = (ready_fd, wait_fd, )
-                env["KSFT_READY_FD"] = str(ready_fd)
+                pass_fds.append(wait_fd)
                 env["KSFT_WAIT_FD"]  = str(wait_fd)
+                ksft_ready = True  # ksft_wait implies ready
+            if ksft_ready is not None:
+                rfd, ready_fd = os.pipe()
+                pass_fds.append(ready_fd)
+                env["KSFT_READY_FD"] = str(ready_fd)
 
             self.proc = subprocess.Popen(comm, shell=shell, stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE, pass_fds=pass_fds,
                                          env=env)
             if ksft_wait is not None:
-                os.close(ready_fd)
                 os.close(wait_fd)
+            if ksft_ready is not None:
+                os.close(ready_fd)
                 msg = fd_read_timeout(rfd, ksft_wait)
                 os.close(rfd)
                 if not msg:
@@ -116,10 +120,10 @@ import time
         with bkg("my_binary", ksft_wait=5):
     """
     def __init__(self, comm, shell=None, fail=None, ns=None, host=None,
-                 exit_wait=False, ksft_wait=None):
+                 exit_wait=False, ksft_ready=None, ksft_wait=None):
         super().__init__(comm, background=True,
                          shell=shell, fail=fail, ns=ns, host=host,
-                         ksft_wait=ksft_wait)
+                         ksft_ready=ksft_ready, ksft_wait=ksft_wait)
         self.terminate = not exit_wait and not ksft_wait
         self._exit_wait = exit_wait
         self.check_fail = fail
Signature · 1 line
2.51.1
Reviewed-by on v2 6/12
#14 lore raw

Re: [PATCH net-next v2 06/12] selftests: net: py: support ksft ready without wait

Quoted 12 lines · Jakub Kicinski

There's a common synchronization problem when a script (Python test) uses a C program to set up some state (usually start a receiving process for traffic). The script needs to know when the process has fully initialized. The inverse of the problem exists for shutting the process down - we need a reliable way to tell the process to exit.

We added helpers to do this safely in
commit 71477137994f ("selftests: drv-net: add a way to wait for a local process") unfortunately the two operations (wait for init, and shutdown) are controlled by a single parameter (ksft_wait). Add support for using ksft_ready without using the second fd for exit.

Quoted 4 lines

This is useful for programs which wait for a specific number of packets to rx so exit_wait is a good match, but we still need to wait for init.

author maintainer
#15 lore raw

PATCH v2 7/12 selftests: net: py: read ip link info about remote dev

In reply to Jakub Kicinski

We're already saving the info about the local dev in env.dev for the tests, save remote dev as well. This is more symmetric, env generally provides the same info for local and remote end.

While at it make sure that we reliably get the detailed info about the local dev. nsim used to read the dev info without -d.

---
 tools/testing/selftests/drivers/net/lib/py/env.py | 2 ++
 tools/testing/selftests/net/lib/py/nsim.py        | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/lib/py/env.py +2 -0
index 01be3d9b9720..8b644fd84ff2 100644
@@ -168,6 +168,8 @@ from .remote import Remote
 
         # resolve remote interface name
         self.remote_ifname = self.resolve_remote_ifc()
+        self.remote_dev = ip("-d link show dev " + self.remote_ifname,
+                             host=self.remote, json=True)[0]
 
         self._required_cmd = {}
 
tools/testing/selftests/net/lib/py/nsim.py +1 -1
index 1a8cbe9acc48..7c640ed64c0b 100644
@@ -27,7 +27,7 @@ from .utils import cmd, ip
         self.port_index = port_index
         self.ns = ns
         self.dfs_dir = "%s/ports/%u/" % (nsimdev.dfs_dir, port_index)
-        ret = ip("-j link show dev %s" % ifname, ns=ns)
+        ret = ip("-d -j link show dev %s" % ifname, ns=ns)
         self.dev = json.loads(ret.stdout)[0]
         self.ifindex = self.dev["ifindex"]
 
Signature · 1 line
2.51.1
Reviewed-by on v2 7/12
#16 lore raw

Re: [PATCH net-next v2 07/12] selftests: net: py: read ip link info about remote dev

Quoted 8 lines · Jakub Kicinski

We're already saving the info about the local dev in env.dev for the tests, save remote dev as well. This is more symmetric, env generally provides the same info for local and remote end.

While at it make sure that we reliably get the detailed info about the local dev. nsim used to read the dev info without -d.

author maintainer
#17 lore raw

PATCH v2 8/12 netdevsim: pass packets thru GRO on Rx

In reply to Jakub Kicinski

To replace veth in software GRO testing with netdevsim we need GRO support in netdevsim. Luckily we already have NAPI support so this change is trivial (compared to veth).

---
v2:
- fix typo "compared"
v1: https://lore.kernel.org/[email protected]

---
 drivers/net/netdevsim/netdev.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/net/netdevsim/netdev.c +2 -7
index fa1d97885caa..2b713db16cd0 100644
@@ -433,13 +433,8 @@ static int nsim_rcv(struct nsim_rq *rq, int budget)
 		}
 
 		/* skb might be discard at netif_receive_skb, save the len */
-		skblen = skb->len;
-		skb_mark_napi_id(skb, &rq->napi);
-		ret = netif_receive_skb(skb);
-		if (ret == NET_RX_SUCCESS)
-			dev_dstats_rx_add(dev, skblen);
-		else
-			dev_dstats_rx_dropped(dev);
+		dev_dstats_rx_add(dev, skb->len);
+		napi_gro_receive(&rq->napi, skb);
 	}
 
 	nsim_start_peer_tx_queue(dev, rq);
Signature · 1 line
2.51.1
author maintainer
#19 lore raw

PATCH v2 9/12 selftests: drv-net: add a Python version of the GRO test

In reply to Jakub Kicinski

Rewrite the existing gro.sh test in Python. The conversion not exact, the changes are related to integrating the test with our "remote endpoint" paradigm. The test now reads the IP addresses from the user config. It resolves the MAC address (including running over Layer 3 networks).

---
v2:
- fix typo I -> It
v1: https://lore.kernel.org/[email protected]

---
 tools/testing/selftests/drivers/net/Makefile |   2 +-
 tools/testing/selftests/drivers/net/gro.c    |   3 +
 tools/testing/selftests/drivers/net/gro.py   | 161 +++++++++++++++++++
 tools/testing/selftests/drivers/net/gro.sh   | 105 ------------
 4 files changed, 165 insertions(+), 106 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/gro.py
 delete mode 100755 tools/testing/selftests/drivers/net/gro.sh
tools/testing/selftests/drivers/net/Makefile +1 -1
index 7083a8707c4e..f5c71d993750 100644
@@ -11,7 +11,7 @@ TEST_GEN_FILES := \
 # end of TEST_GEN_FILES
 
 TEST_PROGS := \
-	gro.sh \
+	gro.py \
 	hds.py \
 	napi_id.py \
 	napi_threaded.py \
tools/testing/selftests/drivers/net/gro.c +3 -0
index 9b9be0cf8f7f..995b492f5bcb 100644
@@ -58,6 +58,7 @@
 #include <unistd.h>
 
 #include "../../kselftest.h"
+#include "../../net/lib/ksft.h"
 
 #define DPORT 8000
 #define SPORT 1500
@@ -1127,6 +1128,8 @@ static void gro_receiver(void)
 	set_timeout(rxfd);
 	bind_packetsocket(rxfd);
 
+	ksft_ready();
+
 	memset(correct_payload, 0, sizeof(correct_payload));
 
 	if (strcmp(testname, "data") == 0) {
tools/testing/selftests/drivers/net/gro.py new file +161 -0

161 lines not on this page · raw message

tools/testing/selftests/drivers/net/gro.sh deleted +0 -105

105 lines not on this page · raw message

Signature · 1 line
2.51.1
Reviewed-by on v2 9/12
#20 lore raw

Re: [PATCH net-next v2 09/12] selftests: drv-net: add a Python version of the GRO test

Quoted 7 lines · Jakub Kicinski

Rewrite the existing gro.sh test in Python. The conversion not exact, the changes are related to integrating the test with our "remote endpoint" paradigm. The test now reads the IP addresses from the user config. It resolves the MAC address (including running over Layer 3 networks).

However:

Quoted 4 lines
tools/testing/selftests/drivers/net/gro.py new file +4 -0
+    base_cmd_args = [
+        f"--{protocol}",
+        f"--dmac {_resolve_dmac(cfg, ipver)}",
+        f"--smac {cfg.remote_dev['address']}",

tools/testing/selftests/drivers/net/gro.py line 129

Quoted 10 lines
tools/testing/selftests/drivers/net/gro.py new file +9 -0
+        f"--daddr {cfg.addr_v[ipver]}",
+        f"--saddr {cfg.remote_addr_v[ipver]}",
+        f"--test {test_name}",
+        "--verbose"
+    ]
+    base_args = " ".join(base_cmd_args)
+
 
+    max_retries = 6
+    for attempt in range(max_retries):

The original had a comment about flakiness which was IMHO useful. The "retry failures" paradigm on its own is transparent enough, but the comment explained why the flakiness comes up.

2c

author maintainer
#21 lore raw

PATCH v2 10/12 selftests: drv-net: hw: convert the Toeplitz test to Python

In reply to Jakub Kicinski

Rewrite the existing toeplitz.sh test in Python. The conversion is a lot less exact than the GRO one. We use Netlink APIs to get the device RSS and IRQ information. We expect that the device has neither RPS nor RFS configured, and set RPS up as part of the test.

---
v2:
- fix typo configure -> configured
v1: https://lore.kernel.org/[email protected]

---
 .../testing/selftests/drivers/net/hw/Makefile |   3 +-
 .../selftests/drivers/net/hw/toeplitz.c       |   5 +
 .../selftests/drivers/net/hw/toeplitz.py      | 208 ++++++++++++++++++
 .../selftests/drivers/net/hw/toeplitz.sh      | 199 -----------------
 .../drivers/net/hw/toeplitz_client.sh         |  28 ---
 5 files changed, 214 insertions(+), 229 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/hw/toeplitz.py
 delete mode 100755 tools/testing/selftests/drivers/net/hw/toeplitz.sh
 delete mode 100755 tools/testing/selftests/drivers/net/hw/toeplitz_client.sh
tools/testing/selftests/drivers/net/hw/Makefile +1 -2
index c9dced8c934a..1760238e9d4f 100644
@@ -24,14 +24,13 @@ TEST_PROGS = \
 	rss_ctx.py \
 	rss_flow_label.py \
 	rss_input_xfrm.py \
-	toeplitz.sh \
+	toeplitz.py \
 	tso.py \
 	xsk_reconfig.py \
 	#
 
 TEST_FILES := \
 	ethtool_lib.sh \
-	toeplitz_client.sh \
 	#
 
 TEST_INCLUDES := \
tools/testing/selftests/drivers/net/hw/toeplitz.c +5 -0
index bf74aa25345d..afc5f910b006 100644
@@ -53,6 +53,7 @@
 #include <unistd.h>
 
 #include "../../../kselftest.h"
+#include "../../../net/lib/ksft.h"
 
 #define TOEPLITZ_KEY_MIN_LEN	40
 #define TOEPLITZ_KEY_MAX_LEN	60
@@ -576,6 +577,10 @@ int main(int argc, char **argv)
 		fd_sink = setup_sink();
 
 	setup_rings();
+
+	/* Signal to test framework that we're ready to receive */
+	ksft_ready();
+
 	process_rings();
 	cleanup_rings();
 
tools/testing/selftests/drivers/net/hw/toeplitz.py new file +208 -0

208 lines not on this page · raw message

tools/testing/selftests/drivers/net/hw/toeplitz.sh deleted +0 -199

199 lines not on this page · raw message

tools/testing/selftests/drivers/net/hw/toeplitz_client.sh deleted +0 -28
deleted file mode 100755
index 2fef34f4aba1..000000000000
@@ -1,28 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: GPL-2.0
-#
-# A simple program for generating traffic for the toeplitz test.
-#
-# This program sends packets periodically for, conservatively, 20 seconds. The
-# intent is for the calling program to kill this program once it is no longer
-# needed, rather than waiting for the 20 second expiration.
-
-send_traffic() {
-	expiration=$((SECONDS+20))
-	while [[ "${SECONDS}" -lt "${expiration}" ]]
-	do
-		if [[ "${PROTO}" == "-u" ]]; then
-			echo "msg $i" | nc "${IPVER}" -u -w 0 "${ADDR}" "${PORT}"
-		else
-			echo "msg $i" | nc "${IPVER}" -w 0 "${ADDR}" "${PORT}"
-		fi
-		sleep 0.001
-	done
-}
-
-PROTO=$1
-IPVER=$2
-ADDR=$3
-PORT=$4
-
-send_traffic
Signature · 1 line
2.51.1
Reviewed-by on v2 10/12
#22 lore raw

Re: [PATCH net-next v2 10/12] selftests: drv-net: hw: convert the Toeplitz test to Python

Quoted 7 lines · Jakub Kicinski

Rewrite the existing toeplitz.sh test in Python. The conversion is a lot less exact than the GRO one. We use Netlink APIs to get the device RSS and IRQ information. We expect that the device has neither RPS nor RFS configured, and set RPS up as part of the test.

tools/testing/selftests/drivers/net/hw/toeplitz.py line 108

Quoted 3 lines
tools/testing/selftests/drivers/net/hw/toeplitz.py new file +3 -0
+    # Set RPS bitmap for all rx queues
+    for rps_file in glob.glob(f"/sys/class/net/{cfg.ifname}/queues/rx-*/rps_cpus"):
+        cmd(f"echo {mask} > {rps_file}", shell=True)

A bit odd to use echo like this, the other test does this through open / write. Unless I'm missing something and this actually runs remotely...?

Anyway, not important. Just that maybe eventually some helpers that support this sysfs-based configuration might be handy.

Quoted 12 lines
tools/testing/selftests/drivers/net/hw/toeplitz.py new file +12 -0
+    return mask
+
+
+def _send_traffic(cfg, proto_flag, ipver, port):
+    """Send 20 packets of requested type."""
+
+    # Determine protocol and IP version for socat
+    if proto_flag == "-u":
+        proto = "UDP"
+    else:
+        proto = "TCP"
+

tools/testing/selftests/drivers/net/hw/toeplitz.py line 131

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/toeplitz.py new file +10 -0
+    baddr = f"[{cfg.addr_v['6']}]" if ipver == "6" else cfg.addr_v["4"]
+
+    # Run socat in a loop to send traffic periodically
+    # Use sh -c with a loop similar to toeplitz_client.sh
+    socat_cmd = f"""
+    for i in `seq 20`; do
+        echo "msg $i" | socat -{ipver} -t 0.1 - {proto}:{baddr}:{port};
+        sleep 0.001;
+    done
+    """

Yeah, what with the remote execution, this probably makes sense.

Quoted 1 line

+ cmd(socat_cmd, shell=True, host=cfg.remote)

author maintainer
#23 lore raw

PATCH v2 11/12 netdevsim: add loopback support

In reply to Jakub Kicinski

Support device loopback. Apparently this mode has been historically supported by the toeplitz test and I don't have any HW which lets me test the conversion..

---
 drivers/net/netdevsim/netdev.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/net/netdevsim/netdev.c +12 -5
index 2b713db16cd0..6927c1962277 100644
@@ -133,15 +133,21 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	if (!nsim_ipsec_tx(ns, skb))
 		goto out_drop_any;
 
-	peer_ns = rcu_dereference(ns->peer);
-	if (!peer_ns)
-		goto out_drop_any;
+	/* Check if loopback mode is enabled */
+	if (dev->features & NETIF_F_LOOPBACK) {
+		peer_ns = ns;
+		peer_dev = dev;
+	} else {
+		peer_ns = rcu_dereference(ns->peer);
+		if (!peer_ns)
+			goto out_drop_any;
+		peer_dev = peer_ns->netdev;
+	}
 
 	dr = nsim_do_psp(skb, ns, peer_ns, &psp_ext);
 	if (dr)
 		goto out_drop_free;
 
-	peer_dev = peer_ns->netdev;
 	rxq = skb_get_queue_mapping(skb);
 	if (rxq >= peer_dev->num_rx_queues)
 		rxq = rxq % peer_dev->num_rx_queues;
@@ -976,7 +982,8 @@ static void nsim_setup(struct net_device *dev)
 			    NETIF_F_FRAGLIST |
 			    NETIF_F_HW_CSUM |
 			    NETIF_F_LRO |
-			    NETIF_F_TSO;
+			    NETIF_F_TSO |
+			    NETIF_F_LOOPBACK;
 	dev->pcpu_stat_type = NETDEV_PCPU_STAT_DSTATS;
 	dev->max_mtu = ETH_MAX_MTU;
 	dev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_HW_OFFLOAD;
Signature · 1 line
2.51.1
author maintainer
#25 lore raw

PATCH v2 12/12 selftests: net: remove old setup_* scripts

In reply to Jakub Kicinski

gro.sh and toeplitz.sh used to source in two setup scripts depending on whether the test was expected to be run against veth or a real device. veth testing is replaced by netdevsim and existing "remote endpoint" support in our Python tests. Add a script which sets up loopback mode.

The usage is a little bit more complicated than running the scripts used to be. Testing used to work like this:

./../gro.sh -i eth0 ...

now the "setup script" has to be run explicitly:

NETIF=eth0 ./../ksft_setup_loopback.sh ./../gro.sh

But the functionality itself is retained.

---
 tools/testing/selftests/net/lib/Makefile      |   3 +-
 .../selftests/net/lib/ksft_setup_loopback.sh  | 111 ++++++++++++++++
 .../selftests/net/lib/setup_loopback.sh       | 120 ------------------
 tools/testing/selftests/net/lib/setup_veth.sh |  45 -------
 4 files changed, 112 insertions(+), 167 deletions(-)
 create mode 100755 tools/testing/selftests/net/lib/ksft_setup_loopback.sh
 delete mode 100644 tools/testing/selftests/net/lib/setup_loopback.sh
 delete mode 100644 tools/testing/selftests/net/lib/setup_veth.sh
tools/testing/selftests/net/lib/Makefile +1 -2
index c10796933d42..5339f56329e1 100644
@@ -8,8 +8,7 @@ CFLAGS += -I../../
 TEST_FILES := \
 	../../../../net/ynl \
 	../../../../../Documentation/netlink/specs \
-	setup_loopback.sh \
-	setup_veth.sh \
+	ksft_setup_loopback.sh \
 # end of TEST_FILES
 
 TEST_GEN_FILES := \
tools/testing/selftests/net/lib/ksft_setup_loopback.sh new file +111 -0

111 lines not on this page · raw message

tools/testing/selftests/net/lib/setup_loopback.sh deleted +0 -120

120 lines not on this page · raw message

tools/testing/selftests/net/lib/setup_veth.sh deleted +0 -45

45 lines not on this page · raw message

Signature · 1 line
2.51.1
Reviewed-by on v2 12/12
#26 lore raw

Re: [PATCH net-next v2 12/12] selftests: net: remove old setup_* scripts

Quoted 11 lines · Jakub Kicinski

gro.sh and toeplitz.sh used to source in two setup scripts depending on whether the test was expected to be run against veth or a real device. veth testing is replaced by netdevsim and existing "remote endpoint" support in our Python tests. Add a script which sets up loopback mode.

The usage is a little bit more complicated than running the scripts used to be. Testing used to work like this:

./../gro.sh -i eth0 ...

Quoted 7 lines

now the "setup script" has to be run explicitly:

NETIF=eth0 ./../ksft_setup_loopback.sh ./../gro.sh

But the functionality itself is retained.

Reviewed-by on the v2 series
#27 lore raw
In reply to Jakub Kicinski
Quoted 35 lines · Jakub Kicinski

Main objective of this series is to convert the gro.sh and toeplitz.sh tests to be "NIPA-compatible" - meaning make use of the Python env, which lets us run the tests against either netdevsim or a real device.

The tests seem to have been written with a different flow in mind. Namely they source different bash "setup" scripts depending on arguments passed to the test. While I have nothing against the use of bash and the overall architecture - the existing code needs quite a bit of work (don't assume MAC/IP addresses, support remote endpoint over SSH). If I'm the one fixing it, I'd rather convert them to our "simplistic" Python.

This series rewrites the tests in Python while addressing their shortcomings. The functionality of running the test over loopback on a real device is retained but with a different method of invocation (see the last patch).

Once again we are dealing with a script which run over a variety of protocols (combination of [ipv4, ipv6, ipip] x [tcp, udp]). The first 4 patches add support for test variants to our scripts. We use the term "variant" in the same sense as the C kselftest_harness.h - variant is just a set of static input arguments.

Note that neither GRO nor the Toeplitz test fully passes for me on any HW I have access to. But this is unrelated to the conversion. This series is not making any real functional changes to the tests, it is limited to improving the "test harness" scripts.

v2:

 [patch  5] fix accidental modification of gitignore
 [patch  8] fix typo in "compared"
 [patch  9] fix typo I -> It

[patch 10] fix typoe configure -> configured
v1: https://lore.kernel.org/[email protected]

Quoted 13 lines

Jakub Kicinski (12):
selftests: net: py: coding style improvements
selftests: net: py: extract the case generation logic
selftests: net: py: add test variants
selftests: drv-net: xdp: use variants for qstat tests
selftests: net: relocate gro and toeplitz tests to drivers/net
selftests: net: py: support ksft ready without wait
selftests: net: py: read ip link info about remote dev
netdevsim: pass packets thru GRO on Rx
selftests: drv-net: add a Python version of the GRO test
selftests: drv-net: hw: convert the Toeplitz test to Python
netdevsim: add loopback support
selftests: net: remove old setup_* scripts

For the series:

author maintainer
#28 lore raw
Quoted 3 lines · On Tue, 18 Nov 2025 17:31:50 -0500 Willem de Bruijn wrote:

For the series:

Thanks! FWIW did some more digging just now, with the indirection table read from the device and disabling symmetric hash for the test (mlx5 defaults to having it enabled) - the Toeplitz test passes on all the NICs I have access to (with the caveat that I'm not able to test IPv4). I'll look closer at the GRO tomorrow.

#29 lore raw
Quoted 10 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 18 Nov 2025 17:31:50 -0500 Willem de Bruijn wrote:

For the series:

Thanks! FWIW did some more digging just now, with the indirection table read from the device and disabling symmetric hash for the test (mlx5 defaults to having it enabled) - the Toeplitz test passes on all the NICs I have access to (with the caveat that I'm not able to test IPv4). I'll look closer at the GRO tomorrow.

Excellent. Symmetric keys makes sense. Though I would have expected the RSS rules would be the canonical format. Another issue on IPv6 can be whether the flowlabel is included (which it shouldn't by default).