Skip to content

Commit f53b3ce

Browse files
committed
test: Add custom signal handlers to integration test wrapper script
meson will send SIGTERM if the test gets stuck and hits the timeout, in which case we still want to do log saving and analysis, so let's add some signal handlers which allow us to do that. This won't be very useful until mesonbuild/meson#14513 lands, since we only get half a second from meson to handle SIGTERM before it sends SIGKILL, but let's land this already so we immediately start taking advantage of the meson fix once it lands.
1 parent 1059476 commit f53b3ce

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

test/integration-tests/integration-test-wrapper.py

+33-11
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
import re
1313
import shlex
1414
import shutil
15+
import signal
1516
import subprocess
1617
import sys
1718
import tempfile
1819
import textwrap
1920
from pathlib import Path
21+
from types import FrameType
22+
from typing import Optional
2023

2124
EMERGENCY_EXIT_DROPIN = """\
2225
[Unit]
@@ -359,7 +362,23 @@ def statfs(path: Path) -> str:
359362
).stdout.strip()
360363

361364

365+
INTERRUPTED = False
366+
367+
368+
def onsignal(signal: int, frame: Optional[FrameType]) -> None:
369+
global INTERRUPTED
370+
if INTERRUPTED:
371+
return
372+
373+
INTERRUPTED = True
374+
raise KeyboardInterrupt()
375+
376+
362377
def main() -> None:
378+
signal.signal(signal.SIGINT, onsignal)
379+
signal.signal(signal.SIGTERM, onsignal)
380+
signal.signal(signal.SIGHUP, onsignal)
381+
363382
parser = argparse.ArgumentParser(description=__doc__)
364383
parser.add_argument('--mkosi', default=None)
365384
parser.add_argument('--meson-source-dir', required=True, type=Path)
@@ -592,19 +611,22 @@ def main() -> None:
592611
'vm' if args.vm or os.getuid() != 0 or os.getenv('TEST_PREFER_QEMU', '0') == '1' else 'boot',
593612
] # fmt: skip
594613

595-
result = subprocess.run(cmd)
596-
597-
# On Debian/Ubuntu we get a lot of random QEMU crashes. Retry once, and then skip if it fails again.
598-
if args.vm and result.returncode == 247 and args.exit_code != 247:
599-
if journal_file:
600-
journal_file.unlink(missing_ok=True)
614+
try:
601615
result = subprocess.run(cmd)
616+
617+
# On Debian/Ubuntu we get a lot of random QEMU crashes. Retry once, and then skip if it fails again.
602618
if args.vm and result.returncode == 247 and args.exit_code != 247:
603-
print(
604-
f'Test {args.name} failed due to QEMU crash (error 247), ignoring',
605-
file=sys.stderr,
606-
)
607-
exit(77)
619+
if journal_file:
620+
journal_file.unlink(missing_ok=True)
621+
result = subprocess.run(cmd)
622+
if args.vm and result.returncode == 247 and args.exit_code != 247:
623+
print(
624+
f'Test {args.name} failed due to QEMU crash (error 247), ignoring',
625+
file=sys.stderr,
626+
)
627+
exit(77)
628+
except KeyboardInterrupt:
629+
result = subprocess.CompletedProcess(args=cmd, returncode=-signal.SIGINT)
608630

609631
coredumps = process_coredumps(args, journal_file)
610632

0 commit comments

Comments
 (0)