[PATCH net-next 01/11] selftests: drv-net: Iperf3Runner: Support UDP and server side results
From: Mohsin Bashir
Date: Thu Dec 03 2026 - 19:05:40 EST
From: Mohsin Bashir <hmohsin@xxxxxxxx>
Iperf3Runner only runs TCP and reports results on the client. Tests that
rate limit traffic on the receive side need to send UDP at a given rate
and read the per-interval results on the server. Add a json option to
start_server() and udp_mbit, length and omit options to start_client().
The defaults keep the current command lines, so existing users are not
affected. start_server() now also stops the server if it does not start
listening in time.
Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
Signed-off-by: Mohsin Bashir <hmohsin@xxxxxxxx>
---
.../selftests/drivers/net/lib/py/load.py | 49 ++++++++++++++-----
1 file changed, 36 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/lib/py/load.py b/tools/testing/selftests/drivers/net/lib/py/load.py
index f337b576c4b4..97d91f55e11f 100644
--- a/tools/testing/selftests/drivers/net/lib/py/load.py
+++ b/tools/testing/selftests/drivers/net/lib/py/load.py
@@ -2,7 +2,7 @@
import re
import time
-import json
+import json as _json
from dataclasses import dataclass
from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
@@ -26,39 +26,62 @@ class Iperf3Runner:
self.server_ip = server_ip
self.client_ip = client_ip
- def _build_server(self):
+ def _build_server(self, json):
cmdline = f"iperf3 -s -1 -p {self.port}"
if self.server_ip:
cmdline += f" -B {self.server_ip}"
+ if json:
+ cmdline += " -J"
return cmdline
- def _build_client(self, streams, duration, reverse):
+ def _build_client(self, streams, duration, reverse, udp_mbit, length,
+ omit):
host = self.env.addr if self.server_ip is None else self.server_ip
cmdline = f"iperf3 -c {host} -p {self.port} -P {streams} -t {duration} -J"
if self.client_ip:
cmdline += f" -B {self.client_ip}"
if reverse:
cmdline += " --reverse"
+ if udp_mbit is not None:
+ cmdline += f" -u -b {udp_mbit}M"
+ if length is not None:
+ cmdline += f" -l {length}"
+ if omit:
+ cmdline += f" -O {omit}"
return cmdline
- def start_server(self):
+ def start_server(self, json=None):
"""
- Starts an iperf3 server with optional bind IP.
+ Starts an iperf3 server with optional bind IP. With @json the
+ server prints its results as JSON when the client is done,
+ including the bytes it received in each interval, or sent if the
+ client runs with @reverse.
"""
- cmdline = self._build_server()
+ cmdline = self._build_server(json)
proc = cmd(cmdline, background=True)
- wait_port_listen(self.port)
+ try:
+ wait_port_listen(self.port)
+ except Exception:
+ # Do not leave a server behind that waits for a client
+ proc.process(terminate=True, fail=False)
+ raise
time.sleep(0.1)
return proc
- def start_client(self, background=False, streams=1, duration=10, reverse=False):
+ def start_client(self, background=False, streams=1, duration=10, reverse=False,
+ udp_mbit=None, length=None, omit=0):
"""
- Starts the iperf3 client with the configured options.
+ Starts the iperf3 client with the configured options. TCP is used
+ unless @udp_mbit gives the UDP rate to send at, in Mbit/s. The
+ rate applies to each of the @streams. @length is the read/write
+ buffer size (the UDP payload size) and @omit the number of seconds
+ to run before measuring.
"""
- cmdline = self._build_client(streams, duration, reverse)
+ cmdline = self._build_client(streams, duration, reverse, udp_mbit,
+ length, omit)
kwargs = {"background": background, "host": self.env.remote}
if not background:
- kwargs["timeout"] = duration + 5
+ kwargs["timeout"] = duration + omit + 5
return cmd(cmdline, **kwargs)
def measure(self, reverse=False):
@@ -73,8 +96,8 @@ class Iperf3Runner:
if result.ret != 0:
raise RuntimeError("iperf3 failed to run successfully")
try:
- out = json.loads(result.stdout)
- except json.JSONDecodeError as exc:
+ out = _json.loads(result.stdout)
+ except _json.JSONDecodeError as exc:
raise ValueError("Failed to parse iperf3 JSON output") from exc
intervals = out.get("intervals", [])
--
2.53.1-Meta