Compare commits

...

3 Commits

Author SHA1 Message Date
Daan De Meyer ab71a23423
Merge b927c5b352 into c946b13575 2024-11-22 23:07:25 +01:00
Daan De Meyer b927c5b352 test: Dump coredumps from journal in the integration test wrapper
Fixes #35277
2024-11-22 23:06:34 +01:00
Daan De Meyer 62e7ef976a integration-test-wrapper: Remove unneeded format strings 2024-11-22 22:37:34 +01:00
1 changed files with 83 additions and 33 deletions

View File

@ -11,6 +11,7 @@ import shlex
import subprocess
import sys
import textwrap
import re
from pathlib import Path
@ -34,6 +35,55 @@ ExecStart=false
"""
def dump_coredumps(args: argparse.Namespace, journal_file: Path) -> bool:
# Collect executable paths of all coredumps and filter out the expected ones.
# The following are excluded:
# sleep/bash - intentional SIGABRT caused by TEST-57
# systemd-notify - intermittent (and intentional) SIGABRT caused by TEST-59
# test-execute - intentional coredump in TEST-02
# test(-usr)?-dump - intentional coredumps from systemd-coredump tests in TEST-74
exclude_regex = re.compile("/(bash|sleep|systemd-notify|test-execute|test(-usr)?-dump)")
coredumps = json.loads(
subprocess.run(
[
args.mkosi,
"--directory", os.fspath(args.meson_source_dir),
"--forward-journal", journal_file,
"coredumpctl",
"--json=short",
],
check=True,
stdout=subprocess.PIPE,
text=True,
).stdout
)
coredumps = [coredump for coredump in coredumps if not exclude_regex.search(coredump["exe"])]
if not coredumps:
return False
for coredump in coredumps:
print()
subprocess.run(
[
args.mkosi,
"--directory", os.fspath(args.meson_source_dir),
"--forward-journal", journal_file,
"coredumpctl",
"info",
coredump["exe"],
],
check=True,
)
print()
return True
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--mkosi', required=True)
@ -70,7 +120,7 @@ def main():
shell = bool(int(os.getenv("TEST_SHELL", "0")))
if shell and not sys.stderr.isatty():
print(f"--interactive must be passed to meson test to use TEST_SHELL=1", file=sys.stderr)
print("--interactive must be passed to meson test to use TEST_SHELL=1", file=sys.stderr)
exit(1)
name = args.name + (f"-{i}" if (i := os.getenv("MESON_TEST_ITERATION")) else "")
@ -84,7 +134,7 @@ def main():
if not shell:
dropin += textwrap.dedent(
f"""
"""
[Unit]
SuccessAction=exit
SuccessActionExitStatus=123
@ -107,7 +157,9 @@ def main():
"""
)
journal_file = None
journal_file = (args.meson_build_dir / (f"test/journal/{name}.journal")).absolute()
journal_file.unlink(missing_ok=True)
if not sys.stderr.isatty():
dropin += textwrap.dedent(
"""
@ -115,9 +167,6 @@ def main():
FailureAction=exit
"""
)
journal_file = (args.meson_build_dir / (f"test/journal/{name}.journal")).absolute()
journal_file.unlink(missing_ok=True)
elif not shell:
dropin += textwrap.dedent(
"""
@ -183,13 +232,14 @@ def main():
print(f"Test {args.name} failed due to QEMU crash (error 247), ignoring", file=sys.stderr)
exit(77)
if journal_file and (keep_journal == "0" or (result.returncode in (args.exit_code, 77) and keep_journal == "fail")):
coredumps = dump_coredumps(args, journal_file)
if keep_journal == "0" or (keep_journal == "fail" and result.returncode in (args.exit_code, 77) and not coredumps):
journal_file.unlink(missing_ok=True)
if shell or result.returncode in (args.exit_code, 77):
if shell or (result.returncode in (args.exit_code, 77) and not coredumps):
exit(0 if shell or result.returncode == args.exit_code else 77)
if journal_file:
ops = []
if os.getenv("GITHUB_ACTIONS"):