Skip to content

Commit e0ee68a

Browse files
committed
selftests: net: ksft: interrupt cleanly on KeyboardInterrupt
It's very useful to be able to interrupt the tests during development. Detect KeyboardInterrupt, run the cleanups and exit. Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5483cbf commit e0ee68a

File tree

1 file changed

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

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
146146

147147
global KSFT_RESULT
148148
cnt = 0
149+
stop = False
149150
for case in cases:
150151
KSFT_RESULT = True
151152
cnt += 1
@@ -160,10 +161,13 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
160161
except KsftXfailEx as e:
161162
comment = "XFAIL " + str(e)
162163
cnt_key = 'xfail'
163-
except Exception as e:
164+
except BaseException as e:
165+
stop |= isinstance(e, KeyboardInterrupt)
164166
tb = traceback.format_exc()
165167
for line in tb.strip().split('\n'):
166168
ksft_pr("Exception|", line)
169+
if stop:
170+
ksft_pr("Stopping tests due to KeyboardInterrupt.")
167171
KSFT_RESULT = False
168172
cnt_key = 'fail'
169173

@@ -175,6 +179,9 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
175179
ktap_result(KSFT_RESULT, cnt, case, comment=comment)
176180
totals[cnt_key] += 1
177181

182+
if stop:
183+
break
184+
178185
print(
179186
f"# Totals: pass:{totals['pass']} fail:{totals['fail']} xfail:{totals['xfail']} xpass:0 skip:{totals['skip']} error:0"
180187
)

0 commit comments

Comments
 (0)