[PATCH net-next v2 2/4] selftests: drv-net: Improve bpftrace utility error handling

Breno Leitao posted 4 patches 3 months, 2 weeks ago
There is a newer version of this series
[PATCH net-next v2 2/4] selftests: drv-net: Improve bpftrace utility error handling
Posted by Breno Leitao 3 months, 2 weeks ago
Enhance the bpftrace function to raise an exception if the underlying
bpftrace command returns a non-zero exit code. This helps detect and
surface errors from bpftrace execution in test scripts, improving
robustness and debugging capabilities.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 tools/testing/selftests/net/lib/py/utils.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index 760ccf6fccccc..c4e26567ee6fb 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -203,6 +203,9 @@ def bpftrace(expr, json=None, ns=None, host=None, timeout=None):
         expr += ' interval:s:' + str(timeout) + ' { exit(); }'
     cmd_arr += ['-e', expr]
     cmd_obj = cmd(cmd_arr, ns=ns, host=host, shell=False)
+    if cmd_obj.ret != 0:
+        raise Exception("Warning: bpftrace command returned a non-zero exit code.")
+
     if json:
         # bpftrace prints objects as lines
         ret = {}

-- 
2.47.1
Re: [PATCH net-next v2 2/4] selftests: drv-net: Improve bpftrace utility error handling
Posted by Jakub Kicinski 3 months, 2 weeks ago
On Wed, 25 Jun 2025 04:39:47 -0700 Breno Leitao wrote:
>      cmd_obj = cmd(cmd_arr, ns=ns, host=host, shell=False)
> +    if cmd_obj.ret != 0:
> +        raise Exception("Warning: bpftrace command returned a non-zero exit code.")

cmd should already raise CmdExitFailure, unless fail=False / fail=None
is specified.
Re: [PATCH net-next v2 2/4] selftests: drv-net: Improve bpftrace utility error handling
Posted by Breno Leitao 3 months, 2 weeks ago
On Wed, Jun 25, 2025 at 02:48:16PM -0700, Jakub Kicinski wrote:
> On Wed, 25 Jun 2025 04:39:47 -0700 Breno Leitao wrote:
> >      cmd_obj = cmd(cmd_arr, ns=ns, host=host, shell=False)
> > +    if cmd_obj.ret != 0:
> > +        raise Exception("Warning: bpftrace command returned a non-zero exit code.")
> 
> cmd should already raise CmdExitFailure, unless fail=False / fail=None
> is specified.

Oh yea, even easier. I found the code, and it is much easier to just set
fail=True for this case. This will avoid hidden errors.