]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: Shut down tests on crash
authorRichard Maw <richard.maw@codethink.co.uk>
Tue, 23 Apr 2024 13:13:22 +0000 (14:13 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Apr 2024 09:01:45 +0000 (11:01 +0200)
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.

test/integration-test-wrapper.py

index b89975d13db96086b734873cd6a1cedddf6a3888..eb7b5b3fc5902afaaf93af779d3782363be48696 100755 (executable)
@@ -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: