diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:54:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:54:25 +0000 |
commit | 9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a (patch) | |
tree | 2efb72864cc69e174c9c5ee33efb88a5f1553b48 /test/TEST-02-SYSTEMD | |
parent | Initial commit. (diff) | |
download | dracut-9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a.tar.xz dracut-9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a.zip |
Adding upstream version 060+5.upstream/060+5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/TEST-02-SYSTEMD')
-rw-r--r-- | test/TEST-02-SYSTEMD/Makefile | 1 | ||||
-rwxr-xr-x | test/TEST-02-SYSTEMD/create-root.sh | 21 | ||||
-rwxr-xr-x | test/TEST-02-SYSTEMD/systemd-analyze.sh | 15 | ||||
-rwxr-xr-x | test/TEST-02-SYSTEMD/test-init.sh | 24 | ||||
-rwxr-xr-x | test/TEST-02-SYSTEMD/test.sh | 76 |
5 files changed, 137 insertions, 0 deletions
diff --git a/test/TEST-02-SYSTEMD/Makefile b/test/TEST-02-SYSTEMD/Makefile new file mode 100644 index 0000000..2dcab81 --- /dev/null +++ b/test/TEST-02-SYSTEMD/Makefile @@ -0,0 +1 @@ +-include ../Makefile.testdir diff --git a/test/TEST-02-SYSTEMD/create-root.sh b/test/TEST-02-SYSTEMD/create-root.sh new file mode 100755 index 0000000..c1fbe76 --- /dev/null +++ b/test/TEST-02-SYSTEMD/create-root.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +trap 'poweroff -f' EXIT + +# don't let udev and this script step on eachother's toes +for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do + : > "/etc/udev/rules.d/$x" +done +rm -f -- /etc/lvm/lvm.conf +udevadm control --reload +set -e + +udevadm settle +mkfs.ext4 -L dracut /dev/disk/by-id/ata-disk_root +mkdir -p /root +mount -t ext4 /dev/disk/by-id/ata-disk_root /root +cp -a -t /root /source/* +mkdir -p /root/run +umount /root +echo "dracut-root-block-created" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker +poweroff -f diff --git a/test/TEST-02-SYSTEMD/systemd-analyze.sh b/test/TEST-02-SYSTEMD/systemd-analyze.sh new file mode 100755 index 0000000..55f8728 --- /dev/null +++ b/test/TEST-02-SYSTEMD/systemd-analyze.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +for i in \ + sysinit.target \ + basic.target \ + initrd-fs.target \ + initrd.target \ + initrd-switch-root.target \ + emergency.target \ + shutdown.target; do + if ! systemd-analyze verify "$i"; then + warn "systemd-analyze verify $i failed" + poweroff + fi +done diff --git a/test/TEST-02-SYSTEMD/test-init.sh b/test/TEST-02-SYSTEMD/test-init.sh new file mode 100755 index 0000000..108e626 --- /dev/null +++ b/test/TEST-02-SYSTEMD/test-init.sh @@ -0,0 +1,24 @@ +#!/bin/sh +: > /dev/watchdog + +. /lib/dracut-lib.sh + +export PATH=/usr/sbin:/usr/bin:/sbin:/bin +command -v plymouth > /dev/null 2>&1 && plymouth --quit +exec > /dev/console 2>&1 + +echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker + +export TERM=linux +export PS1='initramfs-test:\w\$ ' +[ -f /etc/mtab ] || ln -sfn /proc/mounts /etc/mtab +[ -f /etc/fstab ] || ln -sfn /proc/mounts /etc/fstab +stty sane +echo "made it to the rootfs!" +if getargbool 0 rd.shell; then + strstr "$(setsid --help)" "control" && CTTY="-c" + setsid $CTTY sh -i +fi +echo "Powering down." +mount -n -o remount,ro / +poweroff -f diff --git a/test/TEST-02-SYSTEMD/test.sh b/test/TEST-02-SYSTEMD/test.sh new file mode 100755 index 0000000..40d1b3e --- /dev/null +++ b/test/TEST-02-SYSTEMD/test.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# shellcheck disable=SC2034 +TEST_DESCRIPTION="root filesystem on a ext4 filesystem" + +test_check() { + command -v systemctl &> /dev/null +} + +# Uncomment this to debug failures +#DEBUGFAIL="rd.shell=1 rd.break=pre-mount" +test_run() { + declare -a disk_args=() + declare -i disk_index=0 + qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker + qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root + + test_marker_reset + "$testdir"/run-qemu \ + "${disk_args[@]}" \ + -append "panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot root=LABEL=dracut rw loglevel=77 systemd.log_level=debug systemd.log_target=console rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 init=/sbin/init rd.shell=0 $DEBUGFAIL" \ + -initrd "$TESTDIR"/initramfs.testing || return 1 + + test_marker_check || return 1 +} + +test_setup() { + # Create what will eventually be our root filesystem onto an overlay + "$DRACUT" -l --keep --tmpdir "$TESTDIR" \ + -m "test-root" \ + -i ./test-init.sh /sbin/init \ + -i "${PKGLIBDIR}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh" \ + -i "${PKGLIBDIR}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh" \ + --no-hostonly --no-hostonly-cmdline --nomdadmconf --nohardlink \ + -f "$TESTDIR"/initramfs.root "$KVERSION" || return 1 + mkdir -p "$TESTDIR"/overlay/source && mv "$TESTDIR"/dracut.*/initramfs/* "$TESTDIR"/overlay/source && rm -rf "$TESTDIR"/dracut.* + + # second, install the files needed to make the root filesystem + # create an initramfs that will create the target root filesystem. + # We do it this way so that we do not risk trashing the host mdraid + # devices, volume groups, encrypted partitions, etc. + "$DRACUT" -l -i "$TESTDIR"/overlay / \ + -m "test-makeroot" \ + -I "mkfs.ext4" \ + -i ./create-root.sh /lib/dracut/hooks/initqueue/01-create-root.sh \ + --nomdadmconf \ + --no-hostonly-cmdline -N \ + -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1 + rm -rf -- "$TESTDIR"/overlay + + declare -a disk_args=() + declare -i disk_index=0 + qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker 1 + qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root 80 + + # Invoke KVM and/or QEMU to actually create the target filesystem. + "$testdir"/run-qemu \ + "${disk_args[@]}" \ + -append "root=/dev/fakeroot rw rootfstype=ext4 quiet console=ttyS0,115200n81 selinux=0" \ + -initrd "$TESTDIR"/initramfs.makeroot || return 1 + test_marker_check dracut-root-block-created || return 1 + rm -- "$TESTDIR"/marker.img + + # systemd-analyze.sh calls man indirectly + # make the man command succeed always + "$DRACUT" -l -i "$TESTDIR"/overlay / \ + -a "test systemd" \ + -o "network kernel-network-modules" \ + -d "piix ide-gd_mod ata_piix ext4 sd_mod" \ + -i ./systemd-analyze.sh /lib/dracut/hooks/pre-pivot/00-systemd-analyze.sh \ + -i "/bin/true" "/usr/bin/man" \ + --no-hostonly-cmdline -N \ + -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1 +} + +# shellcheck disable=SC1090 +. "$testdir"/test-functions |