Skip to content

Commit 540abc9

Browse files
author
CKI Backport Bot
committed
selftests: net: exit cleanly on SIGTERM / timeout
JIRA: https://issues.redhat.com/browse/RHEL-115594 commit 8f0ae19 Author: Jakub Kicinski <kuba@kernel.org> Date: Fri May 2 18:18:56 2025 -0700 selftests: net: exit cleanly on SIGTERM / timeout ksft runner sends 2 SIGTERMs in a row if a test runs out of time. Handle this in a similar way we handle SIGINT - cleanup and stop running further tests. Because we get 2 signals we need a bit of logic to ignore the subsequent one, they come immediately one after the other (due to commit 9616cb3 ("kselftest/runner.sh: Propagate SIGTERM to runner child")). This change makes sure we run cleanup (scheduled defer()s) and also print a stack trace on SIGTERM, which doesn't happen by default. Tests occasionally hang in NIPA and it's impossible to tell what they are waiting from or doing. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Link: https://patch.msgid.link/20250503011856.46308-1-kuba@kernel.org Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
1 parent 008ae62 commit 540abc9

File tree

1 file changed

+23
-1
lines changed
  • tools/testing/selftests/net/lib/py

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import builtins
44
import functools
55
import inspect
6+
import signal
67
import sys
78
import time
89
import traceback
@@ -26,6 +27,10 @@ class KsftXfailEx(Exception):
2627
pass
2728

2829

30+
class KsftTerminate(KeyboardInterrupt):
31+
pass
32+
33+
2934
def ksft_pr(*objs, **kwargs):
3035
print("#", *objs, **kwargs)
3136

@@ -183,6 +188,17 @@ def get_bool(env, name):
183188
return env
184189

185190

191+
def _ksft_intr(signum, frame):
192+
# ksft runner.sh sends 2 SIGTERMs in a row on a timeout
193+
# if we don't ignore the second one it will stop us from handling cleanup
194+
global term_cnt
195+
term_cnt += 1
196+
if term_cnt == 1:
197+
raise KsftTerminate()
198+
else:
199+
ksft_pr(f"Ignoring SIGTERM (cnt: {term_cnt}), already exiting...")
200+
201+
186202
def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
187203
cases = cases or []
188204

@@ -195,6 +211,10 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
195211
cases.append(value)
196212
break
197213

214+
global term_cnt
215+
term_cnt = 0
216+
prev_sigterm = signal.signal(signal.SIGTERM, _ksft_intr)
217+
198218
totals = {"pass": 0, "fail": 0, "skip": 0, "xfail": 0}
199219

200220
print("TAP version 13")
@@ -223,7 +243,7 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
223243
for line in tb.strip().split('\n'):
224244
ksft_pr("Exception|", line)
225245
if stop:
226-
ksft_pr("Stopping tests due to KeyboardInterrupt.")
246+
ksft_pr(f"Stopping tests due to {type(e).__name__}.")
227247
KSFT_RESULT = False
228248
cnt_key = 'fail'
229249

@@ -238,6 +258,8 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
238258
if stop:
239259
break
240260

261+
signal.signal(signal.SIGTERM, prev_sigterm)
262+
241263
print(
242264
f"# Totals: pass:{totals['pass']} fail:{totals['fail']} xfail:{totals['xfail']} xpass:0 skip:{totals['skip']} error:0"
243265
)

0 commit comments

Comments
 (0)