Skip to contentSkip to conversation

selftests: net: fix cmd.process() timeout handling

PATCH Applied Gal Pressman 2 participants 4 messages Mar 10 – Mar 12

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

v3 cover selftests: net: fix cmd.process() timeout handling

Pass the timeout argument correctly in cmd.process(). As Jakub noted, fixing the timeout broke the bpftrace() command in netpoll_basic.py, so fix it first.

Changelog:
v2->v3: https://lore.kernel.org/all/[email protected]/
* Resubmit to net-next.

v1->v2: https://lore.kernel.org/all/[email protected]/
* Add patch #1.

Gal Pressman (2):
selftests: net: pass bpftrace timeout to cmd()
selftests: net: fix timeout passed as positional argument to
communicate()

 tools/testing/selftests/net/lib/py/utils.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH v3 1/2 selftests: net: pass bpftrace timeout to cmd()

The bpftrace() helper configures an interval based exit timer but does not propagate the timeout to the cmd object, which defaults to 5 seconds. Since the default BPFTRACE_TIMEOUT is 10 seconds, cmd.process() always raises a TimeoutExpired exception before bpftrace has a chance to exit gracefully.

Pass timeout+5 to cmd() to allow bpftrace to complete gracefully.

Note: this issue is masked by a bug in the way cmd() passes timeout, this is fixed in the next commit.

Fixes 3c561c547c39 ("selftests: drv-net: add helper/wrapper for bpftrace")
---
 tools/testing/selftests/net/lib/py/utils.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/net/lib/py/utils.py +2 -1
index 5ffd9fb2a8ce..a6d7fe15e6e4 100644
@@ -258,8 +258,9 @@ def bpftrace(expr, json=None, ns=None, host=None, timeout=None):
         cmd_arr += ['-f', 'json', '-q']
     if timeout:
         expr += ' interval:s:' + str(timeout) + ' { exit(); }'
+        timeout += 5
     cmd_arr += ['-e', expr]
-    cmd_obj = cmd(cmd_arr, ns=ns, host=host, shell=False)
+    cmd_obj = cmd(cmd_arr, ns=ns, host=host, shell=False, timeout=timeout)
     if json:
         # bpftrace prints objects as lines
         ret = {}
Signature · 1 line
2.52.0
#2 lore raw

PATCH v3 2/2 selftests: net: fix timeout passed as positional argument to communicate()

In reply to Gal Pressman

The cited commit refactored the hardcoded timeout=5 into a parameter, but dropped the keyword from the communicate() call.
Since Popen.communicate()'s first positional argument is 'input' (not 'timeout'), the timeout value is silently treated as stdin input and the call never enforces a timeout.

Pass timeout as a keyword argument to restore the intended behavior.

Fixes 1cf270424218 ("net: selftest: add test for netdev netlink queue-get API")
---
 tools/testing/selftests/net/lib/py/utils.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/lib/py/utils.py +1 -1
index a6d7fe15e6e4..17adc2b67ee0 100644
@@ -93,7 +93,7 @@ class cmd:
     def _process_terminate(self, terminate, timeout):
         if terminate:
             self.proc.terminate()
-        stdout, stderr = self.proc.communicate(timeout)
+        stdout, stderr = self.proc.communicate(timeout=timeout)
         self.stdout = stdout.decode("utf-8")
         self.stderr = stderr.decode("utf-8")
         self.proc.stdout.close()
Signature · 1 line
2.52.0
#3 lore raw
In reply to Gal Pressman
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 Tue, 10 Mar 2026 13:58:01 +0200 you wrote:

Pass the timeout argument correctly in cmd.process(). As Jakub noted, fixing the timeout broke the bpftrace() command in netpoll_basic.py, so fix it first.

Changelog:
v2->v3: https://lore.kernel.org/all/[email protected]/
* Resubmit to net-next.

[...]

Here is the summary with links:
- [net-next,v3,1/2] selftests: net: pass bpftrace timeout to cmd()

    https://git.kernel.org/netdev/net-next/c/82562972b854
  - [net-next,v3,2/2] selftests: net: fix timeout passed as positional argument to communicate()
    https://git.kernel.org/netdev/net-next/c/f0bd19316663

You are awesome, thank you!

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