Commit 4b1639ca authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

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: default avatarSimon Horman <horms@kernel.org>
Reviewed-by: default avatarPetr Machata <petrm@nvidia.com>
Link: https://patch.msgid.link/20251128004846.2602687-1-kuba@kernel.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 40d5ce4a
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@ def ksft_flush_defer():
        entry = global_defer_queue.pop()
        try:
            entry.exec_only()
        except BaseException:
        except Exception:
            ksft_pr(f"Exception while handling defer / cleanup (callback {i} of {qlen_start})!")
            tb = traceback.format_exc()
            for line in tb.strip().split('\n'):
@@ -333,6 +333,20 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
            KSFT_RESULT = False
            cnt_key = 'fail'

        try:
            ksft_flush_defer()
        except BaseException as e:
            tb = traceback.format_exc()
            for line in tb.strip().split('\n'):
                ksft_pr("Exception|", line)
            if isinstance(e, KeyboardInterrupt):
                ksft_pr()
                ksft_pr("WARN: defer() interrupted, cleanup may be incomplete.")
                ksft_pr("      Attempting to finish cleanup before exiting.")
                ksft_pr("      Interrupt again to exit immediately.")
                ksft_pr()
                stop = True
            # Flush was interrupted, try to finish the job best we can
            ksft_flush_defer()

        if not cnt_key: