selftests: drv-net: convert GRO and Toeplitz tests to work for drivers in NIPA
Subsystems (5)
Jakub Kicinski
maintainerv3 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.
v3:
[patch 1] Exception -> BaseException [patch 3] use named tuple instead of attaching attrs directly to a func [patch 9] restore the comment about retries in GRO test
[patch 10] use open() instead of echo
[patch 10] move MTU changes to _setup() to handle all the config related
stuff in that function
v2: https://lore.kernel.org/[email protected]
[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 | 164 ++++++++++++++
.../selftests/drivers/net/hw/.gitignore | 1 +
.../drivers/net/hw/lib/py/__init__.py | 4 +-
.../selftests/drivers/net/hw/toeplitz.py | 209 ++++++++++++++++++
.../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 | 91 ++++++--
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, 632 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.shSignature · 1 line
2.51.1
Jakub Kicinski
maintainerPATCH v3 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
We need to use BaseException when handling defer(), as Petr points out. This retains the old behavior of ignoring SIGTERM while running cleanups.
---
v3:
- Exception -> BaseException
v2: https://lore.kernel.org/[email protected]
--- 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
@@ -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 BaseException: 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
Re: [PATCH net-next v3 01/12] selftests: net: py: coding style improvements
Quoted 11 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 importWe need to use BaseException when handling
defer(), as Petr points out. This retains the old behavior of ignoring SIGTERM while running cleanups.Reviewed-by Willem de Bruijn <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
Jakub Kicinski
maintainerPATCH v3 2/12 selftests: net: py: extract the case generation logic
In reply to Jakub KicinskiIn 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
@@ -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
Jakub Kicinski
maintainerPATCH v3 3/12 selftests: net: py: add test variants
In reply to Jakub KicinskiThere'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.
---
v3:
- use named tuple instead of attaching attrs directly to a func
v2: https://lore.kernel.org/[email protected]
--- .../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 | 55 ++++++++++++++++++- 4 files changed, 61 insertions(+), 7 deletions(-)
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +2 -2
@@ -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
@@ -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
@@ -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 +54 -1
79 lines not on this page · raw message
Signature · 1 line
2.51.1
Re: [PATCH net-next v3 03/12] selftests: net: py: add test variants
Quoted 30 lines · 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.hand a lot of other frameworks. Variants can be added as decorator to test functions:@ksft_variants([(1, 2, 3), ('a', 'b', 'c')])
defcase(x, y, z):...
ksft_run()will auto-generate case names:
case.1_2_3
case.a_b_cBecause 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.
Quoted 5 lines
Note that ksft_run's args are still supported.
ksft_runsplices args and variant params together.Reviewed-by Willem de Bruijn <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
Jakub Kicinski
maintainerPATCH v3 4/12 selftests: drv-net: xdp: use variants for qstat tests
In reply to Jakub KicinskiUse just-added ksft variants for XDP qstat tests.
While at it correct the number of packets, we're sending 1000 packets now.
---
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
--- tools/testing/selftests/drivers/net/xdp.py | 42 ++++++++-------------- 1 file changed, 14 insertions(+), 28 deletions(-)
tools/testing/selftests/drivers/net/xdp.py +14 -28
@@ -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
Jakub Kicinski
maintainerPATCH v3 5/12 selftests: net: relocate gro and toeplitz tests to drivers/net
In reply to Jakub KicinskiThe 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.
---
cc: [email protected]
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
tools/testing/selftests/net/.gitignore +0 -2
@@ -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
tools/testing/selftests/net/lib/setup_veth.sh renamed from tools/testing/selftests/net/setup_veth.sh +0 -0
Signature · 1 line
2.51.1
Jakub Kicinski
maintainerPATCH v3 6/12 selftests: net: py: support ksft ready without wait
In reply to Jakub KicinskiThere'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.
---
cc: [email protected]
--- 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
@@ -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
Re: [PATCH net-next v3 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
commit71477137994f("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 usingksft_readywithout using the second fd for exit.
Quoted 6 lines
This is useful for programs which wait for a specific number of packets to rx so
exit_waitis a good match, but we still need to wait for init.Reviewed-by Petr Machata <[email protected]>Reviewed-by Willem de Bruijn <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
Jakub Kicinski
maintainerPATCH v3 7/12 selftests: net: py: read ip link info about remote dev
In reply to Jakub KicinskiWe'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
@@ -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
@@ -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
Jakub Kicinski
maintainerPATCH v3 8/12 netdevsim: pass packets thru GRO on Rx
In reply to Jakub KicinskiTo 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
@@ -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
Jakub Kicinski
maintainerPATCH v3 9/12 selftests: drv-net: add a Python version of the GRO test
In reply to Jakub KicinskiRewrite 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).
---
v3:
- restore the comment about retries
- move MTU changes to _setup() to handle all the config related stuff in that function
v2: https://lore.kernel.org/[email protected]
- 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 | 164 +++++++++++++++++++ tools/testing/selftests/drivers/net/gro.sh | 105 ------------ 4 files changed, 168 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
@@ -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
@@ -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 +164 -0
164 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
Jakub Kicinski
maintainerPATCH v3 10/12 selftests: drv-net: hw: convert the Toeplitz test to Python
In reply to Jakub KicinskiRewrite 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.
---
v3:
- use open() instead of echo
v2: https://lore.kernel.org/[email protected]
- 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 | 209 ++++++++++++++++++ .../selftests/drivers/net/hw/toeplitz.sh | 199 ----------------- .../drivers/net/hw/toeplitz_client.sh | 28 --- 5 files changed, 215 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
@@ -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
@@ -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 +209 -0
209 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
@@ -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
Jakub Kicinski
maintainerPATCH v3 11/12 netdevsim: add loopback support
In reply to Jakub KicinskiSupport 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
@@ -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
Jakub Kicinski
maintainerPATCH v3 12/12 selftests: net: remove old setup_* scripts
In reply to Jakub Kicinskigro.sh and toeplitz.sh used to source in one of 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
@@ -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
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 12 lines · On Wed, 19 Nov 2025 18:10:12 -0800 you wrote:
Main objective of this series is to convert the
gro.shandtoeplitz.shtests 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.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v3,01/12] selftests: net: py: coding style improvements
https://git.kernel.org/netdev/net-next/c/5cb7b71b76f1 - [net-next,v3,02/12] selftests: net: py: extract the case generation logic https://git.kernel.org/netdev/net-next/c/80970e0fc07e - [net-next,v3,03/12] selftests: net: py: add test variants https://git.kernel.org/netdev/net-next/c/6ae67f115986 - [net-next,v3,04/12] selftests: drv-net: xdp: use variants for qstat tests https://git.kernel.org/netdev/net-next/c/173227d7d6c4 - [net-next,v3,05/12] selftests: net: relocate gro and toeplitz tests to drivers/net https://git.kernel.org/netdev/net-next/c/89268f7dbca1 - [net-next,v3,06/12] selftests: net: py: support ksft ready without wait https://git.kernel.org/netdev/net-next/c/e02b52ecef5b - [net-next,v3,07/12] selftests: net: py: read ip link info about remote dev https://git.kernel.org/netdev/net-next/c/15011a57d0ec - [net-next,v3,08/12] netdevsim: pass packets thru GRO on Rx https://git.kernel.org/netdev/net-next/c/40dd789bc5a7 - [net-next,v3,09/12] selftests: drv-net: add a Python version of the GRO test https://git.kernel.org/netdev/net-next/c/fdb0267d565a - [net-next,v3,10/12] selftests: drv-net: hw: convert the Toeplitz test to Python https://git.kernel.org/netdev/net-next/c/9cf9aa77a1f6 - [net-next,v3,11/12] netdevsim: add loopback support https://git.kernel.org/netdev/net-next/c/358008f41d9b - [net-next,v3,12/12] selftests: net: remove old setup_* scripts https://git.kernel.org/netdev/net-next/c/bd28e5bddc1a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html