selftests/net: convert so_txtime to drv-net
Subsystems (4)
Willem de Bruijn
maintainerPATCH v4 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.
----
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 | 24 +++-
.../selftests/drivers/net/so_txtime.py | 97 +++++++++++++++
tools/testing/selftests/net/.gitignore | 1 -
tools/testing/selftests/net/Makefile | 2 -
tools/testing/selftests/net/so_txtime.sh | 110 ------------------
8 files changed, 121 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 +97 -0
97 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
Willem de Bruijn
maintainerQuoted 14 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
In preparation for extending to pacing hardware offload, convert the
so_txtime.shtest to a drv-net test that can be run against netdevsim and real hardware.Also update
so_txtime.cto 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.Signed-off-by Willem de Bruijn <[email protected]>tools/testing/selftests/drivers/net/so_txtime.py new file +1
-0+def main() -> None:
tools/testing/selftests/drivers/net/so_txtime.py line 91
Quoted 10 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +10
-0+ """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):
I evidently couldn't resist a touch up after running through pylint.
Unnecessary parentheses. Only a warn. But I can resubmit irrespective of other concerns.
Again, could add a tc helper (in a separate patch) to hide some of the open coded ugliness too.
Quoted 2 lines
tools/testing/selftests/drivers/net/so_txtime.py new file +2
-0+ cmd(f"tc qdisc replace dev {cfg.ifname} root {qdisc_root}") + ksft_exit()