netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] selftests: net: py: handle interrupt during cleanup
@ 2025-11-28  0:48 Jakub Kicinski
  2025-11-29 17:30 ` Simon Horman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2025-11-28  0:48 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, andrew+netdev, horms, Jakub Kicinski,
	shuah, willemb, petrm, linux-kselftest

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]
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: shuah@kernel.org
CC: willemb@google.com
CC: petrm@nvidia.com
CC: linux-kselftest@vger.kernel.org
---
 tools/testing/selftests/net/lib/py/ksft.py | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
index ebd82940ee50..531e7fa1b3ea 100644
--- a/tools/testing/selftests/net/lib/py/ksft.py
+++ b/tools/testing/selftests/net/lib/py/ksft.py
@@ -163,7 +163,7 @@ KSFT_DISRUPTIVE = True
         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,7 +333,21 @@ KsftCaseFunction = namedtuple("KsftCaseFunction",
             KSFT_RESULT = False
             cnt_key = 'fail'
 
-        ksft_flush_defer()
+        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:
             cnt_key = 'pass' if KSFT_RESULT else 'fail'
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] selftests: net: py: handle interrupt during cleanup
  2025-11-28  0:48 [PATCH net-next] selftests: net: py: handle interrupt during cleanup Jakub Kicinski
@ 2025-11-29 17:30 ` Simon Horman
  2025-12-01  7:57 ` Petr Machata
  2025-12-01 21:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2025-11-29 17:30 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, shuah, willemb,
	petrm, linux-kselftest

On Thu, Nov 27, 2025 at 04:48:46PM -0800, Jakub Kicinski wrote:
> 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]
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] selftests: net: py: handle interrupt during cleanup
  2025-11-28  0:48 [PATCH net-next] selftests: net: py: handle interrupt during cleanup Jakub Kicinski
  2025-11-29 17:30 ` Simon Horman
@ 2025-12-01  7:57 ` Petr Machata
  2025-12-01 21:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Petr Machata @ 2025-12-01  7:57 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, shuah,
	willemb, petrm, linux-kselftest


Jakub Kicinski <kuba@kernel.org> writes:

> 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]
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> CC: shuah@kernel.org
> CC: willemb@google.com
> CC: petrm@nvidia.com
> CC: linux-kselftest@vger.kernel.org
> ---
>  tools/testing/selftests/net/lib/py/ksft.py | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
> index ebd82940ee50..531e7fa1b3ea 100644
> --- a/tools/testing/selftests/net/lib/py/ksft.py
> +++ b/tools/testing/selftests/net/lib/py/ksft.py
> @@ -163,7 +163,7 @@ KSFT_DISRUPTIVE = True
>          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,7 +333,21 @@ KsftCaseFunction = namedtuple("KsftCaseFunction",
>              KSFT_RESULT = False
>              cnt_key = 'fail'
>  
> -        ksft_flush_defer()
> +        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:
>              cnt_key = 'pass' if KSFT_RESULT else 'fail'

Nice.

Reviewed-by: Petr Machata <petrm@nvidia.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] selftests: net: py: handle interrupt during cleanup
  2025-11-28  0:48 [PATCH net-next] selftests: net: py: handle interrupt during cleanup Jakub Kicinski
  2025-11-29 17:30 ` Simon Horman
  2025-12-01  7:57 ` Petr Machata
@ 2025-12-01 21:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-12-01 21:10 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, shuah,
	willemb, petrm, linux-kselftest

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 27 Nov 2025 16:48:46 -0800 you wrote:
> 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]
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> 
> [...]

Here is the summary with links:
  - [net-next] selftests: net: py: handle interrupt during cleanup
    https://git.kernel.org/netdev/net-next/c/4b1639cac04c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-12-01 21:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-28  0:48 [PATCH net-next] selftests: net: py: handle interrupt during cleanup Jakub Kicinski
2025-11-29 17:30 ` Simon Horman
2025-12-01  7:57 ` Petr Machata
2025-12-01 21:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).