Re: [PATCH net-next v2 4/4] selftests: net: add netpoll basic functionality test

From: Willem de Bruijn
Date: Thu Jun 26 2025 - 12:31:54 EST


Breno Leitao wrote:
> 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.
>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>

> +def bpftrace_call() -> None:
> + """Call bpftrace to find how many times netpoll_poll_dev() is called.
> + Output is saved in the global variable `maps`"""
> +
> + # This is going to update the global variable, that will be seen by the
> + # main function
> + global MAPS # pylint: disable=W0603
> +
> + # This will be passed to bpftrace as in bpftrace -e "expr"
> + expr = "BEGIN{ @hits = 0;} kprobe:netpoll_poll_dev { @hits += 1; }"

Is that BEGIN statement needed? I generally just use count().

> +
> + MAPS = bpftrace(expr, timeout=BPFTRACE_TIMEOUT, json=True)
> + logging.debug("BPFtrace output: %s", MAPS)
> +
> +
> +def bpftrace_start():
> + """Start a thread to call `call_bpf` in parallel for 2 seconds."""

Stale comment? BPFTRACE_TIMEOUT is set to 15.

> + global BPF_THREAD # pylint: disable=W0603
> +
> + BPF_THREAD = threading.Thread(target=bpftrace_call)
> + BPF_THREAD.start()
> + if not BPF_THREAD.is_alive():
> + raise KsftSkipEx("BPFtrace thread is not alive. Skipping test")
> +
> +