Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 9616cb34b08e ("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>

authored by

Jakub Kicinski and committed by
Paolo Abeni
8f0ae193 90131a9b

+23 -1
+23 -1
tools/testing/selftests/net/lib/py/ksft.py
··· 3 3 import builtins 4 4 import functools 5 5 import inspect 6 + import signal 6 7 import sys 7 8 import time 8 9 import traceback ··· 24 23 25 24 26 25 class KsftXfailEx(Exception): 26 + pass 27 + 28 + 29 + class KsftTerminate(KeyboardInterrupt): 27 30 pass 28 31 29 32 ··· 198 193 return env 199 194 200 195 196 + def _ksft_intr(signum, frame): 197 + # ksft runner.sh sends 2 SIGTERMs in a row on a timeout 198 + # if we don't ignore the second one it will stop us from handling cleanup 199 + global term_cnt 200 + term_cnt += 1 201 + if term_cnt == 1: 202 + raise KsftTerminate() 203 + else: 204 + ksft_pr(f"Ignoring SIGTERM (cnt: {term_cnt}), already exiting...") 205 + 206 + 201 207 def ksft_run(cases=None, globs=None, case_pfx=None, args=()): 202 208 cases = cases or [] 203 209 ··· 220 204 if key.startswith(prefix): 221 205 cases.append(value) 222 206 break 207 + 208 + global term_cnt 209 + term_cnt = 0 210 + prev_sigterm = signal.signal(signal.SIGTERM, _ksft_intr) 223 211 224 212 totals = {"pass": 0, "fail": 0, "skip": 0, "xfail": 0} 225 213 ··· 253 233 for line in tb.strip().split('\n'): 254 234 ksft_pr("Exception|", line) 255 235 if stop: 256 - ksft_pr("Stopping tests due to KeyboardInterrupt.") 236 + ksft_pr(f"Stopping tests due to {type(e).__name__}.") 257 237 KSFT_RESULT = False 258 238 cnt_key = 'fail' 259 239 ··· 267 247 268 248 if stop: 269 249 break 250 + 251 + signal.signal(signal.SIGTERM, prev_sigterm) 270 252 271 253 print( 272 254 f"# Totals: pass:{totals['pass']} fail:{totals['fail']} xfail:{totals['xfail']} xpass:0 skip:{totals['skip']} error:0"