selftests: net: fix cmd.process() timeout handling
Subsystems (3)
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
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.
--- 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
@@ -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
PATCH v2 2/2 selftests: net: fix timeout passed as positional argument to communicate()
In reply to Gal PressmanThe 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.
--- 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
@@ -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
Jakub Kicinski
maintainerQuoted 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 thebpftrace()command innetpoll_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?
Jakub Kicinski
maintainerRe: [PATCH net v2 1/2] selftests: net: pass bpftrace timeout to cmd()
In reply to Gal Pressmantools/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
-1cmd_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.
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 += 5it 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
-1cmd_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
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 thebpftrace()command innetpoll_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.