Skip to contentSkip to conversation

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

PATCH Superseded Gal Pressman 2 participants 7 messages Mar 8 – Mar 10

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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:
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 v2 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 85884f3e827b..ce4fa4aabebe 100644
@@ -240,8 +240,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
maintainer
#2 lore raw

Re: [PATCH net v2 1/2] selftests: net: pass bpftrace timeout to cmd()

tools/testing/selftests/net/lib/py/utils.py def bpftrace(expr, json=None, ns=None, host=None, timeout=None): · line 243

Quoted 5 lines · On Sun, 8 Mar 2026 21:21:25 +0200 Gal Pressman wrote:
tools/testing/selftests/net/lib/py/utils.py +1 -0
@@ -240,8 +240,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

it may be easy to miss that input arg is modified so..

tools/testing/selftests/net/lib/py/utils.py def bpftrace(expr, json=None, ns=None, host=None, timeout=None): · line 245

Quoted 3 lines
tools/testing/selftests/net/lib/py/utils.py +1 -1
     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)

timeout=(timeout + 5)

here instead could potentially be cleaner, but up to you.

#3 lore raw

Re: [PATCH net v2 1/2] selftests: net: pass bpftrace timeout to cmd()

Quoted 9 lines · Jakub Kicinski

tools/testing/selftests/net/lib/py/utils.py def bpftrace(expr, json=None, ns=None, host=None, timeout=None): · line 243

Quoted 5 lines · On Sun, 8 Mar 2026 21:21:25 +0200 Gal Pressman wrote:
tools/testing/selftests/net/lib/py/utils.py +1 -0
@@ -240,8 +240,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

it may be easy to miss that input arg is modified so..

Quoted 7 lines

tools/testing/selftests/net/lib/py/utils.py def bpftrace(expr, json=None, ns=None, host=None, timeout=None): · line 245

Quoted 3 lines
tools/testing/selftests/net/lib/py/utils.py +1 -1
     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)

timeout=(timeout + 5)

here instead could potentially be cleaner, but up to you.

timeout is None by default, so I figured my version looks better than:
timeout=(timeout + 5) if timeout else None

#4 lore raw

PATCH v2 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 ce4fa4aabebe..4c98ddafdeab 100644
@@ -88,7 +88,7 @@ class cmd:
             os.write(self.ksft_term_fd, b"1")
         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
maintainer
#5 lore raw
In reply to Gal Pressman
Quoted 3 lines · On Sun, 8 Mar 2026 21:21:24 +0200 Gal Pressman 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.

patchwork says this didn't get selftest-ed which usually means there's going to be a conflict with net-next. Can you respin this against net-next?

#6 lore raw
Quoted 8 lines · Jakub Kicinski
Quoted 3 lines · On Sun, 8 Mar 2026 21:21:24 +0200 Gal Pressman 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.

patchwork says this didn't get selftest-ed which usually means there's going to be a conflict with net-next. Can you respin this against net-next?

I'm not seeing any conflicts, but sure, will resubmit to net-next.