Skip to contentSkip to conversation

selftest: net: Add selftest for netpoll

PATCH Applied Breno Leitao 2 participants 5 messages Jul 14, 2025 – Jul 17, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v7 cover selftest: net: Add selftest for netpoll

I am submitting a new selftest for the netpoll subsystem specifically targeting the case where the RX is polling in the TX path, which is a case that we don't have any test in the tree today. This is done when netpoll_poll_dev() called, and this test creates a scenario when that is probably.

The test does the following:

1) Configuring a single RX/TX queue to increase contention on the interface.
2) Generating background traffic to saturate the network, mimicking real-world congestion.
3) Sending netconsole messages to trigger netpoll polling and monitor its behavior.
4) Using dynamic netconsole targets via configfs, with the ability to delete and recreate targets during the test.
5) Running bpftrace in parallel to verify that netpoll_poll_dev() is called when expected. If it is called, then the test passes, otherwise the test is marked as skipped.

In order to achieve it, I stole Jakub's bpftrace helper from [1], and did some small changes that I found useful to use the helper.

So, this patchset basically contains:

1) The code stolen from Jakub
2) Improvements on bpftrace() helper
3) The selftest itself

---
Changes in v7:
- Rebased on top of net-next
- Using ethtool -l json option instead of parsing it manually.
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- Remove the network toggled (Jakub)
- Set ringsize and queue size (Jakub)
- Some other general improvements (Jakub)
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Rebased on top of net-next.
- Calling bpftrace_stop using the defer helper. (Willem)
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Make the test XFail if it doesn't hit the function we are looking for
- Toggle the interface while the traffic is flowing.
- Bumped the number of messages from 10 to 40 per iterations.
* This is hitting ~15 times per run on my vng test.
- Decreased the time from 15 seconds to 10 seconds, given that if
it didn't hit the function in 10 seconds, 5 seconds extra will not
help.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Make pylint happy (Simon)
- Remove the unnecessary patch in bpftrace to raise an exception when it fails. (Jakub)
- Improved the bpftrace code (Willem)
- Stop sending messages if bpftrace is not alive anymore.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Stole Jakub's helper to run bpftrace
- Removed the DEBUG option and moved logs to logging
- Change the code to have a higher chance of calling netpoll_poll_dev().
In my current configuration, it is hitting multiple times during the test.
- Save and restore TX/RX queue size (Jakub)
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Breno Leitao (2):
selftests: drv-net: Strip '@' prefix from bpftrace map keys
selftests: net: add netpoll basic functionality test

Jakub Kicinski (1):
selftests: drv-net: add helper/wrapper for bpftrace

 tools/testing/selftests/drivers/net/Makefile       |   1 +
 .../selftests/drivers/net/lib/py/__init__.py       |   4 +-
 .../testing/selftests/drivers/net/netpoll_basic.py | 396 +++++++++++++++++++++
 tools/testing/selftests/net/lib/py/utils.py        |  35 ++
 4 files changed, 434 insertions(+), 2 deletions(-)

---
base-commit: b06c4311711c57c5e558bd29824b08f0a6e2a155
change-id: 20250612-netpoll_test-a1324d2057c8

Best regards,

Signature · 1 line
Breno Leitao <[email protected]>
#1 lore raw

PATCH v7 1/3 selftests: drv-net: add helper/wrapper for bpftrace

From: Jakub Kicinski <[email protected]>

bpftrace is very useful for low level driver testing. perf or trace-cmd would also do for collecting data from tracepoints, but they require much more post-processing.

Add a wrapper for running bpftrace and sanitizing its output. bpftrace has JSON output, which is great, but it prints loose objects and in a slightly inconvenient format. We have to read the objects line by line, and while at it return them indexed by the map name.

---
 .../selftests/drivers/net/lib/py/__init__.py       |  4 +--
 tools/testing/selftests/net/lib/py/utils.py        | 33 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)
tools/testing/selftests/drivers/net/lib/py/__init__.py +2 -2
index 39968bc3df43e..8711c67ad658a 100644
@@ -14,8 +14,8 @@ try:
     from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \
         NlError, RtnlFamily, DevlinkFamily
     from net.lib.py import CmdExitFailure
-    from net.lib.py import bkg, cmd, defer, ethtool, fd_read_timeout, ip, \
-        rand_port, tool, wait_port_listen, bpftool
+    from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \
+        fd_read_timeout, ip, rand_port, tool, wait_port_listen
     from net.lib.py import fd_read_timeout
     from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
     from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
tools/testing/selftests/net/lib/py/utils.py +33 -0
index acf0e2c386144..5950a643a5336 100644
@@ -189,6 +189,39 @@ def ethtool(args, json=None, ns=None, host=None):
     return tool('ethtool', args, json=json, ns=ns, host=host)
 
 
+def bpftrace(expr, json=None, ns=None, host=None, timeout=None):
+    """
+    Run bpftrace and return map data (if json=True).
+    The output of bpftrace is inconvenient, so the helper converts
+    to a dict indexed by map name, e.g.:
+     {
+       "@":     { ... },
+       "@map2": { ... },
+     }
+    """
+    cmd_arr = ['bpftrace']
+    # Throw in --quiet if json, otherwise the output has two objects
+    if json:
+        cmd_arr += ['-f', 'json', '-q']
+    if timeout:
+        expr += ' interval:s:' + str(timeout) + ' { exit(); }'
+    cmd_arr += ['-e', expr]
+    cmd_obj = cmd(cmd_arr, ns=ns, host=host, shell=False)
+    if json:
+        # bpftrace prints objects as lines
+        ret = {}
+        for l in cmd_obj.stdout.split('\n'):
+            if not l.strip():
+                continue
+            one = _json.loads(l)
+            if one.get('type') != 'map':
+                continue
+            for k, v in one["data"].items():
+                ret[k] = v
+        return ret
+    return cmd_obj
+
+
 def rand_port(type=socket.SOCK_STREAM):
     """
     Get a random unprivileged port.
Signature · 1 line
2.47.1
#2 lore raw

PATCH v7 2/3 selftests: drv-net: Strip '@' prefix from bpftrace map keys

In reply to Breno Leitao

The '@' prefix in bpftrace map keys is specific to bpftrace and can be safely removed when processing results. This patch modifies the bpftrace utility to strip the '@' from map keys before storing them in the result dictionary, making the keys more consistent with Python conventions.

---
 tools/testing/selftests/net/lib/py/utils.py | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/net/lib/py/utils.py +2 -0
index 5950a643a5336..f395c90fb0f19 100644
@@ -217,6 +217,8 @@ def bpftrace(expr, json=None, ns=None, host=None, timeout=None):
             if one.get('type') != 'map':
                 continue
             for k, v in one["data"].items():
+                if k.startswith('@'):
+                    k = k.lstrip('@')
                 ret[k] = v
         return ret
     return cmd_obj
Signature · 1 line
2.47.1
#3 lore raw

PATCH v7 3/3 selftests: net: add netpoll basic functionality test

In reply to Breno Leitao

Add a basic selftest for the netpoll polling mechanism, specifically targeting the netpoll poll() side.

The test creates a scenario where network transmission is running at maximum speed, and netpoll needs to poll the NIC. This is achieved by:

1. Configuring a single RX/TX queue to create contention
2. Generating background traffic to saturate the interface
3. Sending netconsole messages to trigger netpoll polling
4. Using dynamic netconsole targets via configfs
5. Delete and create new netconsole targets after some messages
6. Start a bpftrace in parallel to make sure netpoll_poll_dev() is called
7. If bpftrace exists and netpoll_poll_dev() was called, stop.

The test validates a critical netpoll code path by monitoring traffic flow and ensuring netpoll_poll_dev() is called when the normal TX path is blocked.

This addresses a gap in netpoll test coverage for a path that is tricky for the network stack.

---
 tools/testing/selftests/drivers/net/Makefile       |   1 +
 .../testing/selftests/drivers/net/netpoll_basic.py | 396 +++++++++++++++++++++
 2 files changed, 397 insertions(+)
tools/testing/selftests/drivers/net/Makefile +1 -0
index bd309b2d39095..9bd84d6b542e5 100644
@@ -16,6 +16,7 @@ TEST_PROGS := \
 	netcons_fragmented_msg.sh \
 	netcons_overflow.sh \
 	netcons_sysdata.sh \
+	netpoll_basic.py \
 	ping.py \
 	queues.py \
 	stats.py \
tools/testing/selftests/drivers/net/netpoll_basic.py new file +396 -0

396 lines not on this page · raw message

Signature · 1 line
2.47.1
#4 lore raw
In reply to Breno Leitao
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Mon, 14 Jul 2025 02:56:47 -0700 you wrote:

I am submitting a new selftest for the netpoll subsystem specifically targeting the case where the RX is polling in the TX path, which is a case that we don't have any test in the tree today. This is done when netpoll_poll_dev() called, and this test creates a scenario when that is probably.

The test does the following:

[...]

Here is the summary with links:
- [net-next,v7,1/3] selftests: drv-net: add helper/wrapper for bpftrace

    https://git.kernel.org/netdev/net-next/c/3c561c547c39
  - [net-next,v7,2/3] selftests: drv-net: Strip '@' prefix from bpftrace map keys
    https://git.kernel.org/netdev/net-next/c/fd2aadcefbac
  - [net-next,v7,3/3] selftests: net: add netpoll basic functionality test
    https://git.kernel.org/netdev/net-next/c/b3019343e4bd

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html