From: Richard Maw Date: Tue, 23 Apr 2024 13:13:22 +0000 (+0100) Subject: test: Shut down tests on crash X-Git-Tag: v256-rc1~33^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2fd849016b7368f64f591833a2be752e68cd5052;p=thirdparty%2Fsystemd.git test: Shut down tests on crash If an assert in systemd fails it can't shut down normally. By default it freezes. For interactive runs we want the crash shell to enable further debugging, but during test runs we want it to exit without having to wait for the test timeout. By deactivating the crash shell, enabling reboot, and configuring qemu so that it shuts down instead of rebooting we can shut down instead. Because by default UEFI will enroll keys and then reboot we also have to set --qemu-firmware-variables=custom so it doesn't need to auto-enroll. Because mkosi has to handle not receiving an EXIT_STATUS notification it falls back to the exit code of qemu, which in the case of reboot would be 0, we also override the success exit status to 123 and check that we got that as an exit code from mkosi. --- diff --git a/test/integration-test-wrapper.py b/test/integration-test-wrapper.py index b89975d13db..eb7b5b3fc59 100755 --- a/test/integration-test-wrapper.py +++ b/test/integration-test-wrapper.py @@ -64,6 +64,7 @@ def main(): """ [Unit] SuccessAction=exit + SuccessActionExitStatus=123 FailureAction=exit """ ) @@ -87,7 +88,9 @@ def main(): f"systemd.extra-unit.emergency-exit.service={shlex.quote(EMERGENCY_EXIT_SERVICE)}", '--credential', f"systemd.unit-dropin.emergency.target={shlex.quote(EMERGENCY_EXIT_DROPIN)}", - '--kernel-command-line-extra=systemd.mask=serial-getty@.service', + '--kernel-command-line-extra=systemd.mask=serial-getty@.service systemd.show_status=no systemd.crash_shell=0 systemd.crash_reboot', + # Custom firmware variables allow bypassing the EFI auto-enrollment reboot so we only reboot on crash + '--qemu-firmware-variables=custom', ] if not sys.stderr.isatty() else [] @@ -103,12 +106,13 @@ def main(): ]), *args.mkosi_args, 'qemu', + *(['-no-reboot'] if not sys.stderr.isatty() else []) ] - try: - subprocess.run(cmd, check=True) - except subprocess.CalledProcessError as e: - if e.returncode != 77 and journal_file: + result = subprocess.run(cmd) + # Return code 123 is the expected success code + if result.returncode != (0 if sys.stderr.isatty() else 123): + if result.returncode != 77 and journal_file: cmd = [ 'journalctl', '--no-hostname', @@ -119,7 +123,7 @@ def main(): ] print("Test failed, relevant logs can be viewed with: \n\n" f"{shlex.join(str(a) for a in cmd)}\n", file=sys.stderr) - exit(e.returncode) + exit(result.returncode or 1) # Do not keep journal files for tests that don't fail. if journal_file: