Message ID | 20240729204536.3637577-1-kuba@kernel.org (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net-next] selftests: net: ksft: print more of the stack for checks | expand |
On 07/29, Jakub Kicinski wrote: > Print more stack frames and the failing line when check fails. > This helps when tests use helpers to do the checks. > > Before: > > # At ./ksft/drivers/net/hw/rss_ctx.py line 92: > # Check failed 1037698 >= 396893.0 traffic on other queues:[344612, 462380, 233020, 449174, 342298] > not ok 8 rss_ctx.test_rss_context_queue_reconfigure > > After: > > # Check| At ./ksft/drivers/net/hw/rss_ctx.py, line 387, in test_rss_context_queue_reconfigure: > # Check| test_rss_queue_reconfigure(cfg, main_ctx=False) > # Check| At ./ksft/drivers/net/hw/rss_ctx.py, line 230, in test_rss_queue_reconfigure: > # Check| _send_traffic_check(cfg, port, ctx_ref, { 'target': (0, 3), > # Check| At ./ksft/drivers/net/hw/rss_ctx.py, line 92, in _send_traffic_check: > # Check| ksft_lt(sum(cnts[i] for i in params['noise']), directed / 2, > # Check failed 1045235 >= 405823.5 traffic on other queues (context 1)':[460068, 351995, 565970, 351579, 127270] > not ok 8 rss_ctx.test_rss_context_queue_reconfigure > > Signed-off-by: Jakub Kicinski <kuba@kernel.org> Acked-by: Stanislav Fomichev <sdf@fomichev.me> > --- > CC: shuah@kernel.org > CC: petrm@nvidia.com > --- > tools/testing/selftests/net/lib/py/ksft.py | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py > index f26c20df9db4..c2356e07c34c 100644 > --- a/tools/testing/selftests/net/lib/py/ksft.py > +++ b/tools/testing/selftests/net/lib/py/ksft.py > @@ -32,8 +32,16 @@ KSFT_RESULT_ALL = True > global KSFT_RESULT > KSFT_RESULT = False > > - frame = inspect.stack()[2] > - ksft_pr("At " + frame.filename + " line " + str(frame.lineno) + ":") > + stack = inspect.stack() > + started = False [..] > + for i in reversed(range(2, len(stack))): > + frame = stack[i] optional more python-y way might be: for frame in reversed(stack[2:]): xxx
diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py index f26c20df9db4..c2356e07c34c 100644 --- a/tools/testing/selftests/net/lib/py/ksft.py +++ b/tools/testing/selftests/net/lib/py/ksft.py @@ -32,8 +32,16 @@ KSFT_RESULT_ALL = True global KSFT_RESULT KSFT_RESULT = False - frame = inspect.stack()[2] - ksft_pr("At " + frame.filename + " line " + str(frame.lineno) + ":") + stack = inspect.stack() + started = False + for i in reversed(range(2, len(stack))): + frame = stack[i] + if not started: + started |= frame.function == 'ksft_run' + continue + ksft_pr("Check| At " + frame.filename + ", line " + str(frame.lineno) + + ", in " + frame.function + ":") + ksft_pr("Check| " + frame.code_context[0].strip()) ksft_pr(*args)
Print more stack frames and the failing line when check fails. This helps when tests use helpers to do the checks. Before: # At ./ksft/drivers/net/hw/rss_ctx.py line 92: # Check failed 1037698 >= 396893.0 traffic on other queues:[344612, 462380, 233020, 449174, 342298] not ok 8 rss_ctx.test_rss_context_queue_reconfigure After: # Check| At ./ksft/drivers/net/hw/rss_ctx.py, line 387, in test_rss_context_queue_reconfigure: # Check| test_rss_queue_reconfigure(cfg, main_ctx=False) # Check| At ./ksft/drivers/net/hw/rss_ctx.py, line 230, in test_rss_queue_reconfigure: # Check| _send_traffic_check(cfg, port, ctx_ref, { 'target': (0, 3), # Check| At ./ksft/drivers/net/hw/rss_ctx.py, line 92, in _send_traffic_check: # Check| ksft_lt(sum(cnts[i] for i in params['noise']), directed / 2, # Check failed 1045235 >= 405823.5 traffic on other queues (context 1)':[460068, 351995, 565970, 351579, 127270] not ok 8 rss_ctx.test_rss_context_queue_reconfigure Signed-off-by: Jakub Kicinski <kuba@kernel.org> --- CC: shuah@kernel.org CC: petrm@nvidia.com --- tools/testing/selftests/net/lib/py/ksft.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)