Skip to contentSkip to conversation

selftests/net: convert so_txtime to drv-net

PATCH Superseded Willem de Bruijn 2 participants 4 messages Apr 3

Subsystems (4)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Willem de Bruijn

author maintainer
#0 lore raw

PATCH 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 move so_txtime.c to lib so that it is easily accessible for the new drv-net test, similar to gro.c in commit 8888bf4fb980 ("selftests:
net: move gro to lib for HW vs SW reuse").

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.

---
 tools/testing/selftests/drivers/net/Makefile  |   1 +
 tools/testing/selftests/drivers/net/config    |   2 +
 .../selftests/drivers/net/so_txtime.py        |  87 ++++++++++++++
 tools/testing/selftests/net/.gitignore        |   1 -
 tools/testing/selftests/net/Makefile          |   2 -
 tools/testing/selftests/net/lib/.gitignore    |   1 +
 tools/testing/selftests/net/lib/Makefile      |   1 +
 .../selftests/net/{ => lib}/so_txtime.c       |  25 +++-
 tools/testing/selftests/net/so_txtime.sh      | 110 ------------------
 9 files changed, 111 insertions(+), 119 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/so_txtime.py
 rename tools/testing/selftests/net/{ => lib}/so_txtime.c (97%)
 delete mode 100755 tools/testing/selftests/net/so_txtime.sh
tools/testing/selftests/drivers/net/Makefile +1 -0
index 7c7fa75b80c2..bfa72e07ca89 100644
@@ -20,6 +20,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
index 77ccf83d87e0..a3301d4da540 100644
@@ -3,6 +3,8 @@ CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_BTF_MODULES=n
 CONFIG_INET_PSP=y
 CONFIG_IPV6=y
+CONFIG_NET_SCH_ETF=m
+CONFIG_NET_SCH_FQ=m
 CONFIG_NETCONSOLE=m
 CONFIG_NETCONSOLE_DYNAMIC=y
 CONFIG_NETCONSOLE_EXTENDED_LOG=y
tools/testing/selftests/drivers/net/so_txtime.py new file +87 -0

87 lines not on this page · raw message

tools/testing/selftests/net/.gitignore +0 -1
index 97ad4d551d44..02ad4c99a2b4 100644
@@ -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
index 6bced3ed798b..b7f51e8f190f 100644
@@ -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/lib/.gitignore +1 -0
index 6cd2b762af5d..c57d22e72c75 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 csum
 gro
+so_txtime
 xdp_helper
tools/testing/selftests/net/lib/Makefile +1 -0
index ff83603397d0..8c50b6631524 100644
@@ -15,6 +15,7 @@ TEST_GEN_FILES := \
 	$(patsubst %.c,%.o,$(wildcard *.bpf.c)) \
 	csum \
 	gro \
+	so_txtime \
 	xdp_helper \
 # end of TEST_GEN_FILES
 
tools/testing/selftests/net/lib/so_txtime.c renamed from tools/testing/selftests/net/so_txtime.c +19 -6
similarity index 97%
rename from tools/testing/selftests/net/so_txtime.c
rename to tools/testing/selftests/net/lib/so_txtime.c
index b76df1efc2ef..6583e1a83758 100644
@@ -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", 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,10 @@ static void start_time_wait(void)
 		return;
 
 	now = gettime_ns(CLOCK_REALTIME);
-	if (cfg_start_time_ns < now)
-		return;
+	if (cfg_start_time_ns < now) {
+		fprintf(stderr, "FAIL: start time already passed\n");
+		errors++;
+	}
 
 	err = usleep((cfg_start_time_ns - now) / 1000);
 	if (err)
@@ -513,5 +521,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/net/so_txtime.sh deleted +0 -110

110 lines not on this page · raw message

Signature · 1 line
2.53.0.1213.gd9a14994de-goog
author maintainer
#1 lore raw
Quoted 10 lines · Willem de Bruijn

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 move so_txtime.c to lib so that it is easily accessible for the new drv-net test, similar to gro.c in commit 8888bf4fb980 ("selftests:
net: move gro to lib for HW vs SW reuse").

Quoted 6 lines

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.

Sashiko already has a few correct comments (below). Will fix in v2.

Also, indentation incorrectly uses 2 instead of 4 spaces.

Quoted 6 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +6 -0
+def test_so_txtime(cfg, clockid, ipver, args_tx, args_rx, expect_fail):
+  bin_path = cfg.net_lib_dir / "so_txtime"
+
+  tstart = time.time_ns() + 100_000_000
+
+  cmd_addr = f"-S {cfg.addr_v[ipver]} -D {cfg.remote_addr_v[ipver]}"

tools/testing/selftests/drivers/net/so_txtime.py line 31

Quoted 10 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +10 -0
+  cmd_base = f"{bin_path} -{ipver} -c {clockid} -t {tstart} {cmd_addr}"
+  cmd_rx = f"{cmd_base} {args_rx} -r"
+  cmd_tx = f"{cmd_base} {args_tx}"
+
+  try:
+    with bkg(cmd_rx, host=cfg.remote, exit_wait=True):
+      cmd(cmd_tx)
+  except:
+    if not expect_fail:
+      raise

Also test against a test succeeding when failure is expected. Will add an else: clause.

tools/testing/selftests/net/lib/so_txtime.c static void do_recv_one(int fdr, struct timed_send *ts) · line 139

Quoted 8 lines
tools/testing/selftests/net/lib/so_txtime.c renamed from tools/testing/selftests/net/so_txtime.c +2 -2
@@ -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", ts->data);

Add \n when converting from error to fprintf

tools/testing/selftests/net/lib/so_txtime.c static void start_time_wait(void) · line 269

Quoted 12 lines
tools/testing/selftests/net/lib/so_txtime.c renamed from tools/testing/selftests/net/so_txtime.c +4 -2
@@ -255,8 +261,10 @@ static void start_time_wait(void)
 		return;
 
 	now = gettime_ns(CLOCK_REALTIME);
-	if (cfg_start_time_ns < now)
-		return;
+	if (cfg_start_time_ns < now) {
+		fprintf(stderr, "FAIL: start time already passed\n");
+		errors++;
+	}
 
 	err = usleep((cfg_start_time_ns - now) / 1000);

Do not call usleep when already late: uint64_t will have negative overflow. Also, waiting makes no sense when late. Add return to the error branch.

maintainer
#2 lore raw
In reply to Willem de Bruijn
Quoted 20 lines · On Fri, 3 Apr 2026 13:50:12 -0400 Willem de Bruijn wrote:

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 move so_txtime.c to lib so that it is easily accessible for the new drv-net test, similar to gro.c in commit 8888bf4fb980 ("selftests:
net: move gro to lib for HW vs SW reuse").

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.

tools/testing/selftests/drivers/net/config +0 -0
index 77ccf83d87e0..a3301d4da540 100644

tools/testing/selftests/drivers/net/config CONFIG_DEBUG_INFO_BTF=y · line 7

Quoted 5 lines
tools/testing/selftests/drivers/net/config +2 -0
@@ -3,6 +3,8 @@ CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_BTF_MODULES=n
 CONFIG_INET_PSP=y
 CONFIG_IPV6=y
+CONFIG_NET_SCH_ETF=m
+CONFIG_NET_SCH_FQ=m

I think our sort order puts _ after characters

Quoted 30 lines
tools/testing/selftests/drivers/net/config +0 -0
 CONFIG_NETCONSOLE=m
 CONFIG_NETCONSOLE_DYNAMIC=y
 CONFIG_NETCONSOLE_EXTENDED_LOG=y
tools/testing/selftests/drivers/net/so_txtime.py new file +20 -0
new file mode 100755
index 000000000000..565cecf307dd
@@ -0,0 +1,87 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""Regression tests for the SO_TXTIME interface.
+
+Test delivery time in FQ and ETF qdiscs.
+"""
 
+import time
+
+from lib.py import ksft_exit, ksft_run
+from lib.py import KsftNamedVariant, KsftSkipEx, ksft_variants
+from lib.py import NetDrvEpEnv, bkg, cmd
+
+
+def test_so_txtime(cfg, clockid, ipver, args_tx, args_rx, expect_fail):
+  bin_path = cfg.net_lib_dir / "so_txtime"
+
+  tstart = time.time_ns() + 100_000_000
+
+  cmd_addr = f"-S {cfg.addr_v[ipver]} -D {cfg.remote_addr_v[ipver]}"

tools/testing/selftests/drivers/net/so_txtime.py line 31

Quoted 10 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +10 -0
+  cmd_base = f"{bin_path} -{ipver} -c {clockid} -t {tstart} {cmd_addr}"
+  cmd_rx = f"{cmd_base} {args_rx} -r"
+  cmd_tx = f"{cmd_base} {args_tx}"
+
+  try:
+    with bkg(cmd_rx, host=cfg.remote, exit_wait=True):
+      cmd(cmd_tx)
+  except:
+    if not expect_fail:
+      raise

ruff check says:
tools/testing/selftests/drivers/net/so_txtime.py:29: [E722] Do not use bare except

Why not pass fail=(not expect_fail) to bkg ?

Quoted 1 line

+def main() -> None:

pylint --disable=R should be clean, please
I usually add something like:

"""Boilerplate ksft main"""

tools/testing/selftests/drivers/net/so_txtime.py line 82

Quoted 3 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +3 -0
+  with NetDrvEpEnv(__file__) as cfg:
+    ksft_run([test_so_txtime_mono], args=(cfg,))
+    ksft_run([test_so_txtime_etf], args=(cfg,))

ksft_run() is not supposed to be called multiple times, it will break KTAP format

tools/testing/selftests/net/lib/Makefile TEST_GEN_FILES := \ · line 18

Quoted 9 lines
tools/testing/selftests/net/lib/Makefile +1 -0
index ff83603397d0..8c50b6631524 100644
@@ -15,6 +15,7 @@ TEST_GEN_FILES := \
 	$(patsubst %.c,%.o,$(wildcard *.bpf.c)) \
 	csum \
 	gro \
+	so_txtime \

is there a reason for the binary to be in lib?
gro is used by drivers/net and drivers/net/hw
if the C helper / binary is only used by a single target it should live in the same dir as the python code

author maintainer
#3 lore raw
Quoted 73 lines · Jakub Kicinski
Quoted 20 lines · On Fri, 3 Apr 2026 13:50:12 -0400 Willem de Bruijn wrote:

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 move so_txtime.c to lib so that it is easily accessible for the new drv-net test, similar to gro.c in commit 8888bf4fb980 ("selftests:
net: move gro to lib for HW vs SW reuse").

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.

tools/testing/selftests/drivers/net/config +0 -0
index 77ccf83d87e0..a3301d4da540 100644

tools/testing/selftests/drivers/net/config CONFIG_DEBUG_INFO_BTF=y · line 7

Quoted 5 lines
tools/testing/selftests/drivers/net/config +2 -0
@@ -3,6 +3,8 @@ CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_BTF_MODULES=n
 CONFIG_INET_PSP=y
 CONFIG_IPV6=y
+CONFIG_NET_SCH_ETF=m
+CONFIG_NET_SCH_FQ=m

I think our sort order puts _ after characters

Quoted 30 lines
tools/testing/selftests/drivers/net/config +0 -0
 CONFIG_NETCONSOLE=m
 CONFIG_NETCONSOLE_DYNAMIC=y
 CONFIG_NETCONSOLE_EXTENDED_LOG=y
tools/testing/selftests/drivers/net/so_txtime.py new file +20 -0
new file mode 100755
index 000000000000..565cecf307dd
@@ -0,0 +1,87 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""Regression tests for the SO_TXTIME interface.
+
+Test delivery time in FQ and ETF qdiscs.
+"""
 
+import time
+
+from lib.py import ksft_exit, ksft_run
+from lib.py import KsftNamedVariant, KsftSkipEx, ksft_variants
+from lib.py import NetDrvEpEnv, bkg, cmd
+
+
+def test_so_txtime(cfg, clockid, ipver, args_tx, args_rx, expect_fail):
+  bin_path = cfg.net_lib_dir / "so_txtime"
+
+  tstart = time.time_ns() + 100_000_000
+
+  cmd_addr = f"-S {cfg.addr_v[ipver]} -D {cfg.remote_addr_v[ipver]}"

tools/testing/selftests/drivers/net/so_txtime.py line 31

Quoted 10 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +10 -0
+  cmd_base = f"{bin_path} -{ipver} -c {clockid} -t {tstart} {cmd_addr}"
+  cmd_rx = f"{cmd_base} {args_rx} -r"
+  cmd_tx = f"{cmd_base} {args_tx}"
+
+  try:
+    with bkg(cmd_rx, host=cfg.remote, exit_wait=True):
+      cmd(cmd_tx)
+  except:
+    if not expect_fail:
+      raise

ruff check says:
tools/testing/selftests/drivers/net/so_txtime.py:29: [E722] Do not use bare except

Quoted 1 line

Why not pass fail=(not expect_fail) to bkg ?

That's indeed a lot simpler.

Thanks for the feedback! Will include all these changes in v2.