Skip to content

Commit 4b1639c

Browse files
committed
selftests: net: py: handle interrupt during cleanup
Following up on the old discussion [1]. Let the BaseExceptions out of defer()'ed cleanup. And handle it in the main loop. This allows us to exit the tests if user hit Ctrl-C during defer(). Link: https://lore.kernel.org/20251119063228.3adfd743@kernel.org # [1] Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Petr Machata <petrm@nvidia.com> Link: https://patch.msgid.link/20251128004846.2602687-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 40d5ce4 commit 4b1639c

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

  • tools/testing/selftests/net/lib/py

tools/testing/selftests/net/lib/py/ksft.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def ksft_flush_defer():
163163
entry = global_defer_queue.pop()
164164
try:
165165
entry.exec_only()
166-
except BaseException:
166+
except Exception:
167167
ksft_pr(f"Exception while handling defer / cleanup (callback {i} of {qlen_start})!")
168168
tb = traceback.format_exc()
169169
for line in tb.strip().split('\n'):
@@ -333,7 +333,21 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
333333
KSFT_RESULT = False
334334
cnt_key = 'fail'
335335

336-
ksft_flush_defer()
336+
try:
337+
ksft_flush_defer()
338+
except BaseException as e:
339+
tb = traceback.format_exc()
340+
for line in tb.strip().split('\n'):
341+
ksft_pr("Exception|", line)
342+
if isinstance(e, KeyboardInterrupt):
343+
ksft_pr()
344+
ksft_pr("WARN: defer() interrupted, cleanup may be incomplete.")
345+
ksft_pr(" Attempting to finish cleanup before exiting.")
346+
ksft_pr(" Interrupt again to exit immediately.")
347+
ksft_pr()
348+
stop = True
349+
# Flush was interrupted, try to finish the job best we can
350+
ksft_flush_defer()
337351

338352
if not cnt_key:
339353
cnt_key = 'pass' if KSFT_RESULT else 'fail'

0 commit comments

Comments
 (0)