]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: Enable TEST-08-INITRD on mkosi 32835/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 15 May 2024 08:09:53 +0000 (10:09 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 15 May 2024 08:09:53 +0000 (10:09 +0200)
mkosi.images/exitrd/mkosi.conf [new file with mode: 0644]
mkosi.images/exitrd/mkosi.conf.d/10-arch.conf [new file with mode: 0644]
mkosi.images/exitrd/mkosi.conf.d/10-centos-fedora.conf [new file with mode: 0644]
mkosi.images/exitrd/mkosi.conf.d/10-debian-ubuntu.conf [new file with mode: 0644]
mkosi.images/exitrd/mkosi.conf.d/10-opensuse.conf [new file with mode: 0644]
mkosi.images/exitrd/mkosi.extra/shutdown [new file with mode: 0755]
mkosi.images/system/initrd/mkosi.extra/usr/lib/systemd/system/initrd-run-mount.service [new file with mode: 0644]
mkosi.images/system/mkosi.conf
test/TEST-08-INITRD/meson.build
test/integration-test-wrapper.py
test/meson.build

diff --git a/mkosi.images/exitrd/mkosi.conf b/mkosi.images/exitrd/mkosi.conf
new file mode 100644 (file)
index 0000000..2e867cb
--- /dev/null
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Config]
+ConfigureScripts=
+
+[Output]
+Format=directory
+
+[Content]
+Bootable=no
+@Locale=C.UTF-8
+WithDocs=no
+CleanPackageMetadata=yes
+MakeInitrd=yes
+
+BuildSources=
+Packages=
+BuildPackages=
+VolatilePackages=
+
+Packages=
+        bash
diff --git a/mkosi.images/exitrd/mkosi.conf.d/10-arch.conf b/mkosi.images/exitrd/mkosi.conf.d/10-arch.conf
new file mode 100644 (file)
index 0000000..25d2088
--- /dev/null
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=arch
+
+[Content]
+Packages=
+        systemd
+
+RemoveFiles=
+        # Arch Linux doesn't split their gcc-libs package so we manually remove
+        # unneeded stuff here to make sure it doesn't end up in the image.
+        /usr/lib/libgfortran.so*
+        /usr/lib/libgo.so*
+        /usr/lib/libgomp.so*
+        /usr/lib/libgphobos.so*
+        /usr/lib/libobjc.so*
+        /usr/lib/libasan.so*
+        /usr/lib/libtsan.so*
+        /usr/lib/liblsan.so*
+        /usr/lib/libubsan.so*
+        /usr/lib/libstdc++.so*
+        /usr/lib/libgdruntime.so*
+
+        # Remove all files that are only required for development.
+        /usr/lib/*.a
+        /usr/include/*
+
+        /usr/share/i18n/*
+        /usr/share/hwdata/*
+        /usr/share/iana-etc/*
+        /usr/share/locale/*
+        /usr/share/terminfo/*
+        /usr/share/zoneinfo/*
diff --git a/mkosi.images/exitrd/mkosi.conf.d/10-centos-fedora.conf b/mkosi.images/exitrd/mkosi.conf.d/10-centos-fedora.conf
new file mode 100644 (file)
index 0000000..8458dee
--- /dev/null
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=|centos
+Distribution=|fedora
+
+[Content]
+Packages=
+        systemd-standalone-shutdown
diff --git a/mkosi.images/exitrd/mkosi.conf.d/10-debian-ubuntu.conf b/mkosi.images/exitrd/mkosi.conf.d/10-debian-ubuntu.conf
new file mode 100644 (file)
index 0000000..babde60
--- /dev/null
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=|debian
+Distribution=|ubuntu
+
+[Content]
+Packages=
+        systemd
diff --git a/mkosi.images/exitrd/mkosi.conf.d/10-opensuse.conf b/mkosi.images/exitrd/mkosi.conf.d/10-opensuse.conf
new file mode 100644 (file)
index 0000000..3f6df21
--- /dev/null
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=opensuse
+
+[Content]
+Packages=
+        systemd
diff --git a/mkosi.images/exitrd/mkosi.extra/shutdown b/mkosi.images/exitrd/mkosi.extra/shutdown
new file mode 100755 (executable)
index 0000000..e4c6087
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+
+EXIT_CODE=()
+
+# Translate a successful exit code to 124 so that we can detect that the exitrd was actually used.
+if [[ "$*" == *"--exit-code=123"* ]]; then
+    EXIT_CODE+=("--exit-code=124")
+fi
+
+exec /usr/lib/systemd/systemd-shutdown "$@" "${EXIT_CODE[@]}"
diff --git a/mkosi.images/system/initrd/mkosi.extra/usr/lib/systemd/system/initrd-run-mount.service b/mkosi.images/system/initrd/mkosi.extra/usr/lib/systemd/system/initrd-run-mount.service
new file mode 100644 (file)
index 0000000..845ac57
--- /dev/null
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Unit]
+Description=Create a mount in /run that should survive the transition from initrd
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=mkdir /run/initrd-mount-source /run/initrd-mount-target
+ExecStart=mount -v --bind /run/initrd-mount-source /run/initrd-mount-target
+ExecStart=cp -v /etc/initrd-release /run/initrd-mount-target/hello-world
index 65e5de379fe7d14e8645250b61a1346bcac569df..f18ad022addad5a4bea21a699408808a303a0ea9 100644 (file)
@@ -2,6 +2,7 @@
 
 [Config]
 Dependencies=
+        exitrd
         minimal-base
         minimal-0
         minimal-1
@@ -24,6 +25,7 @@ ExtraTrees=
         %O/minimal-1.root-%a-verity.raw:/usr/share/minimal_1.verity
         %O/minimal-1.root-%a-verity-sig.raw:/usr/share/minimal_1.verity.sig
         %O/minimal-base:/usr/share/TEST-13-NSPAWN-container-template
+        %O/exitrd:/exitrd
 
 Packages=
         acl
index d53dbe562c5bc84ce37286a9d2b3536d48ecb428..34edec0d355217f311e0c004083c23eefd750132 100644 (file)
@@ -3,6 +3,9 @@
 integration_tests += [
         integration_test_template + {
                 'name' : fs.name(meson.current_source_dir()),
-                'enabled' : false,
+                'cmdline' : integration_test_template['cmdline'] + [
+                        'rd.systemd.wants=initrd-run-mount.service',
+                ],
+                'exit-code' : 124,
         },
 ]
index 55ea4ff0d8f637e38646da8dc6f82c9575592cf9..55a45307e278e3e1c5a7c14c691871eecea4fb3d 100755 (executable)
@@ -47,6 +47,7 @@ def main():
     parser.add_argument('--storage', required=True)
     parser.add_argument('--firmware', required=True)
     parser.add_argument('--slow', action=argparse.BooleanOptionalAction)
+    parser.add_argument('--exit-code', required=True, type=int)
     parser.add_argument('mkosi_args', nargs="*")
     args = parser.parse_args()
 
@@ -148,13 +149,12 @@ def main():
 
     result = subprocess.run(cmd)
 
-    # Return code 123 is the expected success code
-    if result.returncode in (123, 77):
+    if result.returncode in (args.exit_code, 77):
         # Do not keep journal files for tests that don't fail.
         if journal_file:
             journal_file.unlink(missing_ok=True)
 
-        exit(0 if result.returncode == 123 else 77)
+        exit(0 if result.returncode == args.exit_code else 77)
 
     if journal_file:
         ops = []
index 1026be67cbeb15f27ce775f4d8d59f35ce5456ac..bb91ec8875ff9591c9e56d280a2e7a331e488e3b 100644 (file)
@@ -292,6 +292,7 @@ integration_test_template = {
         'cmdline' : [],
         'credentials' : [],
         'qemu-args' : [],
+        'exit-code' : 123,
 }
 testdata_subdirs = [
         'auxv',
@@ -384,6 +385,7 @@ foreach integration_test : integration_tests
                 '--name', integration_test['name'],
                 '--storage', integration_test['storage'],
                 '--firmware', integration_test['firmware'],
+                '--exit-code', integration_test['exit-code'].to_string(),
         ]
 
         if 'unit' in integration_test