selftests: drv-net: convert so_txtime to drv-net
Subsystems (4)
Willem de Bruijn
maintainerv5 cover selftests: drv-net: convert so_txtime to drv-net
From: Willem de Bruijn <[email protected]>
In preparation for extending to pacing hardware offload, convert the so_txtime.sh test to a drv-net test that can be run against netdevsim and real hardware.
Two preparatory patches
1. support negative tests, where tests are expected to fail
2. add a tc helper
See individual patches for details.
Willem de Bruijn (3):
selftests: net: py: support cmd verifying expected failure
selftests: net: py: add tc utility
selftests: drv-net: convert so_txtime to drv-net
.../testing/selftests/drivers/net/.gitignore | 1 +
tools/testing/selftests/drivers/net/Makefile | 2 +
tools/testing/selftests/drivers/net/config | 2 +
.../selftests/drivers/net/lib/py/__init__.py | 5 +-
.../selftests/{ => drivers}/net/so_txtime.c | 25 +++-
.../selftests/drivers/net/so_txtime.py | 95 +++++++++++++++
tools/testing/selftests/net/.gitignore | 1 -
tools/testing/selftests/net/Makefile | 2 -
.../testing/selftests/net/lib/py/__init__.py | 4 +-
tools/testing/selftests/net/lib/py/utils.py | 18 ++-
tools/testing/selftests/net/so_txtime.sh | 110 ------------------
11 files changed, 141 insertions(+), 124 deletions(-)
rename tools/testing/selftests/{ => drivers}/net/so_txtime.c (96%)
create mode 100755 tools/testing/selftests/drivers/net/so_txtime.py
delete mode 100755 tools/testing/selftests/net/so_txtime.shSignature · 1 line
2.54.0.545.g6539524ca2-goog
Willem de Bruijn
maintainerPATCH v5 1/3 selftests: net: py: support cmd verifying expected failure
From: Willem de Bruijn <[email protected]>
Support negative tests, where cmd raises an exception if the command succeeded.
Existing fail values are
- True: Pass if returncode == 0, raise Exception otherwise - False: Pass unconditionally - None: True iff not terminated explicitly
Introduce a variant of True that inverses the condition:
- 'verify_failed': Pass if returncode != 0, raise Exception otherwise
We cannot reuse False for this, because existing tests rely on current behavior to pass unconditionally.
Only suppress regular test failure. Python subprocess may set a negative return code on process crash or timeout. Those are not anticipated failures.
--- tools/testing/selftests/net/lib/py/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/testing/selftests/net/lib/py/utils.py +5 -1
@@ -111,10 +111,14 @@ class cmd: stdout, stderr = self._process_terminate(terminate=terminate, timeout=timeout) - if self.proc.returncode != 0 and fail: + + if (self.proc.returncode != 0 and fail and + (self.proc.returncode < 0 or fail != 'verify_failed')): if len(stderr) > 0 and stderr[-1] == "\n": stderr = stderr[:-1] raise CmdExitFailure("Command failed", self) + elif self.proc.returncode == 0 and fail == 'verify_failed': + raise CmdExitFailure("Command succeeded while should fail", self) def __repr__(self): def str_fmt(name, s):
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Willem de Bruijn
maintainerPATCH v5 2/3 selftests: net: py: add tc utility
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
Add a wrapper similar to existing ip, ethtool, ... commands.
Tc takes a slightly different syntax. Account for that.
The first user is the next patch in this series, converting so_txtime to drv-net. Pacing offload is supported by selected qdiscs only.
--- .../testing/selftests/drivers/net/lib/py/__init__.py | 5 +++-- tools/testing/selftests/net/lib/py/__init__.py | 4 ++-- tools/testing/selftests/net/lib/py/utils.py | 12 +++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-)
tools/testing/selftests/drivers/net/lib/py/__init__.py +3 -2
@@ -23,7 +23,8 @@ try: NlError, RtnlFamily, DevlinkFamily, PSPFamily, Netlink from net.lib.py import CmdExitFailure from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \ - fd_read_timeout, ip, rand_port, rand_ports, wait_port_listen, wait_file + fd_read_timeout, ip, rand_port, rand_ports, tc, wait_port_listen, \ + wait_file from net.lib.py import bpf_map_set, bpf_map_dump, bpf_prog_map_ids from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
@@ -36,7 +37,7 @@ try: "NlError", "RtnlFamily", "DevlinkFamily", "PSPFamily", "Netlink", "CmdExitFailure", "bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool", - "fd_read_timeout", "ip", "rand_port", "rand_ports", + "fd_read_timeout", "ip", "rand_port", "rand_ports", "tc", "wait_port_listen", "wait_file", "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids", "KsftSkipEx", "KsftFailEx", "KsftXfailEx",
tools/testing/selftests/net/lib/py/__init__.py +2 -2
@@ -14,7 +14,7 @@ from .netns import NetNS, NetNSEnter from .nsim import NetdevSim, NetdevSimDev from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \ bpftool, ip, ethtool, bpftrace, rand_port, rand_ports, wait_port_listen, \ - wait_file, tool + wait_file, tool, tc from .bpf import bpf_map_set, bpf_map_dump, bpf_prog_map_ids from .ynl import NlError, NlctrlFamily, YnlFamily, \ EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily
@@ -29,7 +29,7 @@ __all__ = ["KSRC", "NetNS", "NetNSEnter", "CmdExitFailure", "fd_read_timeout", "cmd", "bkg", "defer", "bpftool", "ip", "ethtool", "bpftrace", "rand_port", "rand_ports", - "wait_port_listen", "wait_file", "tool", + "wait_port_listen", "wait_file", "tool", "tc", "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids", "NetdevSim", "NetdevSimDev", "NetshaperFamily", "DevlinkFamily", "PSPFamily", "NlError",
tools/testing/selftests/net/lib/py/utils.py +11 -1
@@ -224,7 +224,10 @@ class defer: def tool(name, args, json=None, ns=None, host=None): cmd_str = name + ' ' if json: - cmd_str += '--json ' + if name == 'tc': + cmd_str += '-json ' + else: + cmd_str += '--json ' cmd_str += args cmd_obj = cmd(cmd_str, ns=ns, host=host) if json:
@@ -242,6 +245,13 @@ def ip(args, json=None, ns=None, host=None): return tool('ip', args, json=json, host=host) +def tc(args, json=None, ns=None, host=None): + """ Helper to call tc with standard set of optional args. """ + if ns: + args = f'-netns {ns} ' + args + return tool('tc', args, json=json, host=host) + + def ethtool(args, json=None, ns=None, host=None): return tool('ethtool', args, json=json, ns=ns, host=host)
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Willem de Bruijn
maintainerPATCH v5 3/3 selftests: drv-net: convert so_txtime to drv-net
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
In preparation for extending to pacing hardware offload, convert the so_txtime.sh test to a drv-net test that can be run against netdevsim and real hardware.
Also update so_txtime.c to not exit on first failure, but run to completion and report exit code there. This helps with debugging unexpected results, especially when processing multiple packets, as happens in the "reverse_order" testcase.
----
v4 -> v5
- move qdisc setup/restore into each test
- add tc to utils.py (separate patch)
- test expected failure (separate patch)
- fix pylint
- convert fail to pass for timing errors if KSFT_MACHINE_SLOW (cmd does not special case KSFT_SKIP process returncode yet)
Responses to sashiko review
- The test converts per packet failure to errors, to continue testing other packets, but other error() cases are not in scope.
- The test starts sender and receiver at an absolute future time, like the original test. This assumes ~msec scale sync'ed clocks.
- The tc qdisc replace command works fine with noqueue. Tested manually.
v4: https://lore.kernel.org/netdev/[email protected]/
v3 -> v4
- restore original qdisc after test
- drop unnecessary underscore in tap test names
v3: https://lore.kernel.org/netdev/[email protected]/
v2 -> v3
- Makefile: so_txtime from YNL_GEN_FILES to TEST_GEN_FILES (Sashiko, NIPA)
v2: https://lore.kernel.org/netdev/[email protected]/
v1 -> v2
- move so_txtime.c for net/lib to drivers/net (Jakub)
- fix drivers/net/config order (Jakub)
- detect passing when failure is expected (Jakub, Sashiko)
- pass pylint --disable=R (Jakub)
- only call ksft_run once (Jakub)
- do not sleep if waiting time is negative (Sashiko)
- add \n when converting error() to fprintf() (Sashiko)
- 4 space indentation, instead of 2 space
- increase sync delay from 100 to 200ms, to fix rare vng flakes
v1: https://lore.kernel.org/netdev/[email protected]/
---
.../testing/selftests/drivers/net/.gitignore | 1 +
tools/testing/selftests/drivers/net/Makefile | 2 +
tools/testing/selftests/drivers/net/config | 2 +
.../selftests/{ => drivers}/net/so_txtime.c | 25 +++-
.../selftests/drivers/net/so_txtime.py | 95 +++++++++++++++
tools/testing/selftests/net/.gitignore | 1 -
tools/testing/selftests/net/Makefile | 2 -
tools/testing/selftests/net/so_txtime.sh | 110 ------------------
8 files changed, 120 insertions(+), 118 deletions(-)
rename tools/testing/selftests/{ => drivers}/net/so_txtime.c (96%)
create mode 100755 tools/testing/selftests/drivers/net/so_txtime.py
delete mode 100755 tools/testing/selftests/net/so_txtime.shtools/testing/selftests/drivers/net/.gitignore +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only napi_id_helper psp_responder +so_txtime
tools/testing/selftests/drivers/net/Makefile +2 -0
@@ -7,6 +7,7 @@ TEST_INCLUDES := $(wildcard lib/py/*.py) \ TEST_GEN_FILES := \ napi_id_helper \ + so_txtime \ # end of TEST_GEN_FILES TEST_PROGS := \
@@ -21,6 +22,7 @@ TEST_PROGS := \ queues.py \ ring_reconfig.py \ shaper.py \ + so_txtime.py \ stats.py \ xdp.py \ # end of TEST_PROGS
tools/testing/selftests/drivers/net/config +2 -0
@@ -9,4 +9,6 @@ CONFIG_NETCONSOLE_DYNAMIC=y CONFIG_NETCONSOLE_EXTENDED_LOG=y CONFIG_NETDEVSIM=m CONFIG_VLAN_8021Q=m +CONFIG_NET_SCH_ETF=m +CONFIG_NET_SCH_FQ=m CONFIG_XDP_SOCKETS=y
tools/testing/selftests/drivers/net/so_txtime.c renamed from tools/testing/selftests/net/so_txtime.c +20 -5
@@ -33,6 +33,8 @@#include <unistd.h> #include <poll.h> +#include "kselftest.h" +static int cfg_clockid =CLOCK_TAI ;static uint16_t cfg_port =8000 ;static int cfg_variance_us =4000 ;
@@ -43,6 +45,8 @@ static bool cfg_rx;static uint64_t glob_tstart;static uint64_t tdeliver_max; +static int errors; +/* encode one timed transmission (of a 1B payload) */ struct timed_send {char data;
@@ -131,13 +135,15 @@ static void do_recv_one(int fdr, struct timed_send *ts)fprintf (stderr,"payload:%c delay:%lld expected:%lld (us)\n" , rbuf[0 ], (long long )tstop, (long long )texpect); -if (rbuf[0 ] != ts->data) -error (1 ,0 ,"payload mismatch. expected %c" , ts->data); +if (rbuf[0 ] != ts->data) { +fprintf (stderr,"payload mismatch. expected %c\n" , ts->data); + errors++; + }if (llabs (tstop - texpect) > cfg_variance_us) {fprintf (stderr,"exceeds variance (%d us)\n" , cfg_variance_us);if (!getenv ("KSFT_MACHINE_SLOW" )) -exit (1 ); + errors++; } }
@@ -255,8 +261,12 @@ static void start_time_wait(void)return ; now =gettime_ns (CLOCK_REALTIME ); -if (cfg_start_time_ns < now) +if (cfg_start_time_ns < now) { +fprintf (stderr,"FAIL: start time already passed\n" ); +if (!getenv ("KSFT_MACHINE_SLOW" )) + errors++;return ; + } err =usleep ((cfg_start_time_ns - now) /1000 );if (err)
@@ -513,5 +523,10 @@ int main(int argc, char **argv)else do_test_tx ((void *)&cfg_src_addr, cfg_alen); -return 0 ; +if (errors) { +fprintf (stderr,"FAIL: %d errors\n" , errors); +return KSFT_FAIL ; + } + +return KSFT_PASS ; }
tools/testing/selftests/drivers/net/so_txtime.py new file +95 -0
95 lines not on this page · raw message
tools/testing/selftests/net/.gitignore +0 -1
@@ -40,7 +40,6 @@ skf_net_off socket so_incoming_cpu so_netns_cookie -so_txtime so_rcv_listener stress_reuseport_listen tap
tools/testing/selftests/net/Makefile +0 -2
@@ -83,7 +83,6 @@ TEST_PROGS := \ rxtimestamp.sh \ sctp_vrf.sh \ skf_net_off.sh \ - so_txtime.sh \ srv6_end_dt46_l3vpn_test.sh \ srv6_end_dt4_l3vpn_test.sh \ srv6_end_dt6_l3vpn_test.sh \
@@ -157,7 +156,6 @@ TEST_GEN_FILES := \ skf_net_off \ so_netns_cookie \ so_rcv_listener \ - so_txtime \ socket \ stress_reuseport_listen \ tcp_fastopen_backup_key \
tools/testing/selftests/net/so_txtime.sh deleted +0 -110
110 lines not on this page · raw message
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Jakub Kicinski
maintainerQuoted 1 line · On Mon, 27 Apr 2026 16:14:32 -0400 Willem de Bruijn wrote:
Subject: [PATCH net-next v5 0/3] selftests: drv-net: convert
so_txtimeto drv-net
net-next wasn't open yet, when you posted.
Please resubmit in a couple of days.
Signature · 1 line
pw-bot: defer