selftests/net: convert so_txtime to drv-net
Subsystems (4)
Willem de Bruijn
maintainerPATCH v3 1/1 selftests/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.
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 in the "reverse_order" testcase.
----
v2 -> v3
- Makefile: move so_txtime from YNL_GEN_FILES to TEST_GEN_FILES
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 | 24 +++-
.../selftests/drivers/net/so_txtime.py | 88 ++++++++++++++
tools/testing/selftests/net/.gitignore | 1 -
tools/testing/selftests/net/Makefile | 2 -
tools/testing/selftests/net/so_txtime.sh | 110 ------------------
8 files changed, 112 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 := \
@@ -20,6 +21,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
@@ -7,4 +7,6 @@ CONFIG_NETCONSOLE=m CONFIG_NETCONSOLE_DYNAMIC=y CONFIG_NETCONSOLE_EXTENDED_LOG=y CONFIG_NETDEVSIM=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 +19 -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,11 @@ 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" ); + errors++;return ; + } err =usleep ((cfg_start_time_ns - now) /1000 );if (err)
@@ -513,5 +522,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 +88 -0
88 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
@@ -81,7 +81,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 \
@@ -154,7 +153,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.53.0.1213.gd9a14994de-goog
Jakub Kicinski
maintainerQuoted 7 lines · On Sun, 5 Apr 2026 22:49:22 -0400 Willem de Bruijn wrote:
+@ksft_variants(_test_variants_mono())
tools/testing/selftests/drivers/net/so_txtime.py new file +6
-0+def test_so_txtime_mono(cfg, ipver, args_tx, args_rx): + """Run all variants of monotonic (fq) tests.""" + cmd(f"tc qdisc replace dev {cfg.ifname} root fq") + test_so_txtime(cfg, "mono", ipver, args_tx, args_rx, False) + +
tools/testing/selftests/drivers/net/so_txtime.py line 60
Quoted 10 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +10
-0+def _test_variants_etf(): + for ipver in ["4", "6"]: + for testcase in [ + ["no_delay", "a,-1", "a,-1", True], + ["zero_delay", "a,0", "a,0", True], + ["one_pkt", "a,10", "a,10", False], + ["in_order", "a,10,b,20", "a,10,b,20", False], + ["reverse_order", "a,20,b,10", "b,10,a,20", False], + ]: + name = f"_v{ipver}_{testcase[0]}"
nit: looking at the results in NIPA:
https://netdev-ctrl.bots.linux.dev/logs/vmksft/net-drv/results/593442/5-so-txtime-py/stdout
the leading _ seems unnecessary?
Quoted 7 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +7
-0+ yield KsftNamedVariant( + name, ipver, testcase[1], testcase[2], testcase[3] + ) + + +@ksft_variants(_test_variants_etf()) +def test_so_txtime_etf(cfg, ipver, args_tx, args_rx, expect_fail):
tools/testing/selftests/drivers/net/so_txtime.py line 77
Quoted 10 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +10
-0+ """Run all variants of etf tests.""" + try: + # ETF does not support change, so remove and re-add it instead. + cmd_prefix = f"tc qdisc replace dev {cfg.ifname} root" + cmd(f"{cmd_prefix} pfifo_fast") + cmd(f"{cmd_prefix} etf clockid CLOCK_TAI delta 400000") + except Exception as e: + raise KsftSkipEx("tc does not support qdisc etf. skipping") from e + + test_so_txtime(cfg, "tai", ipver, args_tx, args_rx, expect_fail)
I _think_ we'll leave ETF installed on the device after the test? That seems not super great. As we discussed before rebuilding the whole hierarchy will be tedious but we could at least replace with mq on exit and let it put whatever the default qdisc is as its leaves?
Willem de Bruijn
maintainerQuoted 37 lines · Jakub Kicinski
Quoted 7 lines · On Sun, 5 Apr 2026 22:49:22 -0400 Willem de Bruijn wrote:
+@ksft_variants(_test_variants_mono())
tools/testing/selftests/drivers/net/so_txtime.py new file +6
-0+def test_so_txtime_mono(cfg, ipver, args_tx, args_rx): + """Run all variants of monotonic (fq) tests.""" + cmd(f"tc qdisc replace dev {cfg.ifname} root fq") + test_so_txtime(cfg, "mono", ipver, args_tx, args_rx, False) + +tools/testing/selftests/drivers/net/so_txtime.py line 60
Quoted 10 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +10
-0+def _test_variants_etf(): + for ipver in ["4", "6"]: + for testcase in [ + ["no_delay", "a,-1", "a,-1", True], + ["zero_delay", "a,0", "a,0", True], + ["one_pkt", "a,10", "a,10", False], + ["in_order", "a,10,b,20", "a,10,b,20", False], + ["reverse_order", "a,20,b,10", "b,10,a,20", False], + ]: + name = f"_v{ipver}_{testcase[0]}"nit: looking at the results in NIPA:
https://netdev-ctrl.bots.linux.dev/logs/vmksft/net-drv/results/593442/5-so-txtime-py/stdout
the leading _ seems unnecessary?Quoted 14 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +14
-0+ yield KsftNamedVariant( + name, ipver, testcase[1], testcase[2], testcase[3] + ) + + +@ksft_variants(_test_variants_etf()) +def test_so_txtime_etf(cfg, ipver, args_tx, args_rx, expect_fail): + """Run all variants of etf tests.""" + try: + # ETF does not support change, so remove and re-add it instead. + cmd_prefix = f"tc qdisc replace dev {cfg.ifname} root" + cmd(f"{cmd_prefix} pfifo_fast") + cmd(f"{cmd_prefix} etf clockid CLOCK_TAI delta 400000") + except Exception as e:
Quoted 8 lines
tools/testing/selftests/drivers/net/so_txtime.py line 77
Quoted 3 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +3
-0+ raise KsftSkipEx("tc does not support qdisc etf. skipping") from e + + test_so_txtime(cfg, "tai", ipver, args_tx, args_rx, expect_fail)I _think_ we'll leave ETF installed on the device after the test? That seems not super great. As we discussed before rebuilding the whole hierarchy will be tedious but we could at least replace with mq on exit and let it put whatever the default qdisc is as its leaves?
Good point. We can not set mq on netkit. It fails netif_is_multiqueue in mq_init_common. I'll do the following.
@@ -81,6 +81,8 @@ def main() -> None:
"""Boilerplate ksft main."""
with NetDrvEpEnv(__file__) as cfg:
ksft_run([test_so_txtime_mono, test_so_txtime_etf], args=(cfg,))
+ if not cfg._ns:
+ cmd(f"tc qdisc replace dev {cfg.ifname} root mq")
ksft_exit()
Alternatively could record the root qdisc at the start of the test and restore that.
Willem de Bruijn
maintainerQuoted 51 lines · Willem de Bruijn
Quoted 37 lines · Jakub Kicinski
Quoted 7 lines · On Sun, 5 Apr 2026 22:49:22 -0400 Willem de Bruijn wrote:
+@ksft_variants(_test_variants_mono())
tools/testing/selftests/drivers/net/so_txtime.py new file +6
-0+def test_so_txtime_mono(cfg, ipver, args_tx, args_rx): + """Run all variants of monotonic (fq) tests.""" + cmd(f"tc qdisc replace dev {cfg.ifname} root fq") + test_so_txtime(cfg, "mono", ipver, args_tx, args_rx, False) + +tools/testing/selftests/drivers/net/so_txtime.py line 60
Quoted 10 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +10
-0+def _test_variants_etf(): + for ipver in ["4", "6"]: + for testcase in [ + ["no_delay", "a,-1", "a,-1", True], + ["zero_delay", "a,0", "a,0", True], + ["one_pkt", "a,10", "a,10", False], + ["in_order", "a,10,b,20", "a,10,b,20", False], + ["reverse_order", "a,20,b,10", "b,10,a,20", False], + ]: + name = f"_v{ipver}_{testcase[0]}"nit: looking at the results in NIPA:
https://netdev-ctrl.bots.linux.dev/logs/vmksft/net-drv/results/593442/5-so-txtime-py/stdout
the leading _ seems unnecessary?Quoted 14 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +14
-0+ yield KsftNamedVariant( + name, ipver, testcase[1], testcase[2], testcase[3] + ) + + +@ksft_variants(_test_variants_etf()) +def test_so_txtime_etf(cfg, ipver, args_tx, args_rx, expect_fail): + """Run all variants of etf tests.""" + try: + # ETF does not support change, so remove and re-add it instead. + cmd_prefix = f"tc qdisc replace dev {cfg.ifname} root" + cmd(f"{cmd_prefix} pfifo_fast") + cmd(f"{cmd_prefix} etf clockid CLOCK_TAI delta 400000") + except Exception as e:Quoted 8 lines
tools/testing/selftests/drivers/net/so_txtime.py line 77
Quoted 3 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +3
-0+ raise KsftSkipEx("tc does not support qdisc etf. skipping") from e + + test_so_txtime(cfg, "tai", ipver, args_tx, args_rx, expect_fail)I _think_ we'll leave ETF installed on the device after the test? That seems not super great. As we discussed before rebuilding the whole hierarchy will be tedious but we could at least replace with mq on exit and let it put whatever the default qdisc is as its leaves?
Good point. We can not set mq on netkit. It fails
netif_is_multiqueueinmq_init_common. I'll do the following.
Review def main() -> None: · line 86
Quoted 6 lines
(quoted diff) +2
-0@@ -81,6 +81,8 @@ def main() -> None: """Boilerplate ksft main.""" with NetDrvEpEnv(__file__) as cfg: ksft_run([test_so_txtime_mono, test_so_txtime_etf], args=(cfg,)) + if not cfg._ns: + cmd(f"tc qdisc replace dev {cfg.ifname} root mq") ksft_exit()
Actually, looking at a private field is not a good idea.
Quoted 2 lines
Alternatively could record the root qdisc at the start of the test and restore that.
This should work:
def main() -> None:
"""Boilerplate ksft main."""
with NetDrvEpEnv(__file__) as cfg:
+ # Record original root qdisc
+ cmd_obj = cmd((f"tc -j qdisc show dev {cfg.ifname} root"))
+ qdisc_root = json.loads(cmd_obj.stdout)[0].get("kind", None)
+
ksft_run([test_so_txtime_mono, test_so_txtime_etf], args=(cfg,))
+
+ # Restore original root qdisc. If mq, populate with default_qdisc nodes
+ if (qdisc_root):
+ cmd(f"tc qdisc replace dev {cfg.ifname} root {qdisc_root}")
ksft_exit()
Do we want to add a tc command similar to ip, bpftool, etc.
Jakub Kicinski
maintainerQuoted 11 lines · On Thu, 09 Apr 2026 11:01:49 -0400 Willem de Bruijn wrote:
Quoted 2 lines
Alternatively could record the root qdisc at the start of the test and restore that.
This should work:
def
main()-> None:
"""Boilerplate ksft main."""
withNetDrvEpEnv(__file__)as cfg:
+ # Record original root qdisc
+cmd_obj=cmd((f"tc -j qdisc show dev {cfg.ifname} root"))
+qdisc_root= json.loads(cmd_obj.stdout)[0].get("kind", None)
I don't like doing setup in main() TBH. It can well fail and no KTAP will be produced. Breaking all the tracking and stability-based filtering. Not sure if it's still the case but for a very long time not all tc qdiscs supported JSON for example.
Quoted 9 lines
ksft_run([test_so_txtime_mono, test_so_txtime_etf], args=(cfg,))
+
+ # Restore original root qdisc. If mq, populate withdefault_qdiscnodes
+ if (qdisc_root):
+cmd(f"tc qdisc replace dev {cfg.ifname} root {qdisc_root}")
ksft_exit()Do we want to add a tc command similar to ip, bpftool, etc.
Yes, we can wrap it if it outputs json.