Skip to contentSkip to conversation

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

PATCH Superseded Jakub Kicinski 2 participants 20 messages Nov 17, 2025 – Nov 18, 2025

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

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.

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       |   3 +-
 .../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, 631 insertions(+), 578 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 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
author maintainer
#2 lore raw

PATCH 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
author maintainer
#3 lore raw

PATCH 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
author maintainer
#4 lore raw

PATCH 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
#5 lore raw

PATCH 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.

---
 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          | 3 ++-
 .../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, 18 insertions(+), 16 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 +2 -1
index 6942bf575497..8feb7493b3ed 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 iou-zcrx
-ncdevmem
+ncdevmme
+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 439101b518ee..0b7a3e64db00 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
author maintainer
#7 lore raw

PATCH 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
author maintainer
#8 lore raw

PATCH 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
author maintainer
#9 lore raw

PATCH 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 (comapred to veth).

---
 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
#11 lore raw

PATCH 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).

---
 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
author maintainer
#13 lore raw

PATCH 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 configure, and set RPS up as part of the test.

---
 .../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
author maintainer
#15 lore raw

PATCH 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
#16 lore raw

PATCH 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
#6 lore raw

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

In reply to Jakub Kicinski
Quoted 18 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.

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.

tools/testing/selftests/drivers/net/hw/.gitignore +0 -0
index 6942bf575497..8feb7493b3ed 100644

tools/testing/selftests/drivers/net/hw/.gitignore line 3

Quoted 4 lines
tools/testing/selftests/drivers/net/hw/.gitignore +1 -1
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 iou-zcrx
-ncdevmem
+ncdevmme

modified neighboring line

Quoted 1 line
tools/testing/selftests/drivers/net/hw/.gitignore +1 -0
+toeplitz
#12 lore raw

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

In reply to Jakub Kicinski
Quoted 76 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).

---
 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 +20 -0
new file mode 100755
index 000000000000..a27f8106eb63
@@ -0,0 +1,161 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""
+GRO (Generic Receive Offload) conformance tests.
+
+Validates that GRO coalescing works correctly by running the gro
+binary in different configurations and checking for correct packet
+coalescing behavior.
+
+Test cases:
+  - data: Data packets with same size/headers and correct seq numbers coalesce
+  - ack: Pure ACK packets do not coalesce
+  - flags: Packets with PSH, SYN, URG, RST flags do not coalesce
+  - tcp: Packets with incorrect checksum, non-consecutive seqno don't coalesce
+  - ip: Packets with different ECN, TTL, TOS, or IP options don't coalesce
+  - large: Packets larger than GRO_MAX_SIZE don't coalesce
+"""
+
+import os

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

Quoted 10 lines
tools/testing/selftests/drivers/net/gro.py new file +10 -0
+from lib.py import ksft_run, ksft_exit, ksft_pr
+from lib.py import NetDrvEpEnv, KsftXfailEx
+from lib.py import cmd, defer, bkg, ip
+from lib.py import ksft_variants
+
+
+def _resolve_dmac(cfg, ipver):
+    """
+    Find the destination MAC address remote host should use to send packets
+    towards the local host. I may be a router / gateway address.

I -> It

Quoted 23 lines
tools/testing/selftests/drivers/net/gro.py new file +23 -0
+    """
+
+    attr = "dmac" + ipver
+    # Cache the response across test cases
+    if hasattr(cfg, attr):
+        return getattr(cfg, attr)
+
+    route = ip(f"-{ipver} route get {cfg.addr_v[ipver]}",
+               json=True, host=cfg.remote)[0]
+    gw = route.get("gateway")
+    # Local L2 segment, address directly
+    if not gw:
+        setattr(cfg, attr, cfg.dev['address'])
+        return getattr(cfg, attr)
+
+    # ping to make sure neighbor is resolved,
+    # bind to an interface, for v6 the GW is likely link local
+    cmd(f"ping -c1 -W0 -I{cfg.remote_ifname} {gw}", host=cfg.remote)
+
+    neigh = ip(f"neigh get {gw} dev {cfg.remote_ifname}",
+               json=True, host=cfg.remote)[0]
+    setattr(cfg, attr, neigh['lladdr'])
+    return getattr(cfg, attr)
#14 lore raw

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

In reply to Jakub Kicinski
Quoted 4 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 configure, and set RPS up as part of

configure -> configured

Quoted 3 lines

the test.

#17 lore raw
In reply to Jakub Kicinski
Quoted 17 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).

Quoted 8 lines

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.

You observed the same failures with the old and new tests? Are they deterministic failures or flakes.

Quoted 16 lines

This series is not making any real functional changes to the tests, it is limited to improving the "test harness" scripts.

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

Thanks for converting these tests!

No significant actionable comments, just a few trivial typos.

author maintainer
#18 lore raw
Quoted 5 lines · On Mon, 17 Nov 2025 21:11:31 -0500 Willem de Bruijn wrote:
Quoted 2 lines

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.

You observed the same failures with the old and new tests? Are they deterministic failures or flakes.

Deterministic for Toeplitz - all NICs I have calculate the Rx hash the same as the test for at least one of traffic types. But none of them exactly as the test is expecting.
One IIRC also uses non-standard RSS indir table pattern by default. The indirection table will be a trivial fix.

For HW-GRO I investigated less closely I mostly focused on making sure netdevsim is solid as a replacement for veth. There was more flakiness on HW (admittedly I was running inter-dc-building). But the failures looked rather sus - the test was reporting that packets which were not supposed to be coalesced got coalesced.

BTW it's slightly inconvenient that we disable HW-GRO when normal GRO is disabled :( Makes it quite hard to run the test to check device behavior. My current plan is to rely on device counters to check whether traffic is getting coalesced but better ideas most welcome :(

Quoted 4 lines
Quoted 2 lines

This series is not making any real functional changes to the tests, it is limited to improving the "test harness" scripts.

No significant actionable comments, just a few trivial typos.

Thanks!

#19 lore raw
Quoted 4 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 17 Nov 2025 21:11:31 -0500 Willem de Bruijn wrote:
Quoted 2 lines

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.

Quoted 8 lines
Quoted 2 lines

You observed the same failures with the old and new tests? Are they deterministic failures or flakes.

Deterministic for Toeplitz - all NICs I have calculate the Rx hash the same as the test for at least one of traffic types. But none of them exactly as the test is expecting.
One IIRC also uses non-standard RSS indir table pattern by default. The indirection table will be a trivial fix.

Ugh yes we've had a bug open for ages internally to add indirection table parsing to the test:

The (upstream) RSS test is too simplistic: it calculates

queue_id = hash % num_queues

Real RSS uses an indirection table:

queue_id = indir_table[hash % indir_table_len]

Quoted 5 lines

For HW-GRO I investigated less closely I mostly focused on making sure netdevsim is solid as a replacement for veth. There was more flakiness on HW (admittedly I was running inter-dc-building). But the failures looked rather sus - the test was reporting that packets which were not supposed to be coalesced got coalesced.

The reverse is a known cause of flakiness, due to the context closure timer firing. But unexpected coalescing definitely seems suspicious.

Quoted 4 lines

BTW it's slightly inconvenient that we disable HW-GRO when normal GRO is disabled :( Makes it quite hard to run the test to check device behavior. My current plan is to rely on device counters to check whether traffic is getting coalesced but better ideas most welcome :(

We probably have to maintain this behavior, but could add an override to enable only HW-GRO.

Alternatively, just for measurement, a bpf fentry program. But that is a lot more complex than reading the counters, which is sufficient signal.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This series is not making any real functional changes to the tests, it is limited to improving the "test harness" scripts.

No significant actionable comments, just a few trivial typos.

Thanks!