From: Laszlo Gombos Date: Fri, 3 May 2024 13:29:59 +0000 (-0400) Subject: test: execute test-init.sh at the end of each test case boot X-Git-Tag: 102~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ffb3d6ed01b38bc72ce99e08286b1f4591375f81;p=thirdparty%2Fdracut-ng.git test: execute test-init.sh at the end of each test case boot --- diff --git a/modules.d/80test-root/module-setup.sh b/modules.d/80test-root/module-setup.sh index 088113596..cec28ee92 100755 --- a/modules.d/80test-root/module-setup.sh +++ b/modules.d/80test-root/module-setup.sh @@ -26,5 +26,7 @@ install() { inst_script "${dracutbasedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh" inst_script "${dracutbasedir}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh" + inst_script "$moddir/test-init.sh" "/test-init.sh" + inst_multiple -o plymouth } diff --git a/modules.d/80test-root/test-init.sh b/modules.d/80test-root/test-init.sh new file mode 100755 index 000000000..0f2fedd3b --- /dev/null +++ b/modules.d/80test-root/test-init.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +export PATH=/usr/sbin:/usr/bin:/sbin:/bin + +[ -e /proc/self/mounts ] \ + || (mkdir -p /proc && mount -t proc -o nosuid,noexec,nodev proc /proc) + +grep -q '^sysfs /sys sysfs' /proc/self/mounts \ + || (mkdir -p /sys && mount -t sysfs -o nosuid,noexec,nodev sysfs /sys) + +grep -q '^devtmpfs /dev devtmpfs' /proc/self/mounts \ + || (mkdir -p /dev && mount -t devtmpfs -o mode=755,noexec,nosuid,strictatime devtmpfs /dev) + +grep -q '^tmpfs /run tmpfs' /proc/self/mounts \ + || (mkdir -p /run && mount -t tmpfs -o mode=755,noexec,nosuid,strictatime tmpfs /run) + +: > /dev/watchdog + +exec > /dev/console 2>&1 + +if [ -s /failed ]; then + echo "**************************FAILED**************************" + cat /failed + echo "**************************FAILED**************************" +else + echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_marker + echo "All OK" +fi + +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!" + +. /lib/dracut-lib.sh + +if getargbool 0 rd.shell; then + strstr "$(setsid --help)" "control" && CTTY="-c" + # shellcheck disable=SC2086 + setsid $CTTY sh -i +fi + +echo "Powering down." +mount -n -o remount,ro / +if [ -d /run/initramfs/etc ]; then + echo " rd.debug=0 " >> /run/initramfs/etc/cmdline +fi +poweroff -f diff --git a/test/TEST-01-BASIC/test-init.sh b/test/TEST-01-BASIC/test-init.sh index ba42fc2d8..c418b8bce 100755 --- a/test/TEST-01-BASIC/test-init.sh +++ b/test/TEST-01-BASIC/test-init.sh @@ -1,24 +1,3 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_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 +. /test-init.sh diff --git a/test/TEST-02-SYSTEMD/test-init.sh b/test/TEST-02-SYSTEMD/test-init.sh index ba42fc2d8..c418b8bce 100755 --- a/test/TEST-02-SYSTEMD/test-init.sh +++ b/test/TEST-02-SYSTEMD/test-init.sh @@ -1,24 +1,3 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_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 +. /test-init.sh diff --git a/test/TEST-03-USR-MOUNT/test-init.sh b/test/TEST-03-USR-MOUNT/test-init.sh index ba42fc2d8..c418b8bce 100755 --- a/test/TEST-03-USR-MOUNT/test-init.sh +++ b/test/TEST-03-USR-MOUNT/test-init.sh @@ -1,24 +1,3 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_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 +. /test-init.sh diff --git a/test/TEST-04-FULL-SYSTEMD/test-init.sh b/test/TEST-04-FULL-SYSTEMD/test-init.sh index 19e466c4e..83508d876 100755 --- a/test/TEST-04-FULL-SYSTEMD/test-init.sh +++ b/test/TEST-04-FULL-SYSTEMD/test-init.sh @@ -1,40 +1,21 @@ #!/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 systemctl --failed --no-legend --no-pager > /failed +ismounted() { + findmnt "$1" > /dev/null 2>&1 +} + if ! ismounted /usr; then echo "**************************FAILED**************************" echo "/usr not mounted!!" - cat /proc/mounts + cat /proc/mounts >> /failed echo "**************************FAILED**************************" -else - if [ -s /failed ]; then - echo "**************************FAILED**************************" - cat /failed - echo "**************************FAILED**************************" - - else - echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_marker - echo "All OK" - fi fi -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." -poweroff -f +. /test-init.sh diff --git a/test/TEST-04-FULL-SYSTEMD/test.sh b/test/TEST-04-FULL-SYSTEMD/test.sh index e2302c036..9183937ea 100755 --- a/test/TEST-04-FULL-SYSTEMD/test.sh +++ b/test/TEST-04-FULL-SYSTEMD/test.sh @@ -54,6 +54,7 @@ test_setup() { "$DRACUT" -l --keep --tmpdir "$TESTDIR" \ -m "test-root systemd" \ -i ./test-init.sh /sbin/test-init \ + -I "findmnt" \ -i ./fstab /etc/fstab \ --no-hostonly --no-hostonly-cmdline --nomdadmconf --nohardlink \ -f "$TESTDIR"/initramfs.root "$KVERSION" || return 1 diff --git a/test/TEST-10-RAID/test-init.sh b/test/TEST-10-RAID/test-init.sh index ba42fc2d8..c418b8bce 100755 --- a/test/TEST-10-RAID/test-init.sh +++ b/test/TEST-10-RAID/test-init.sh @@ -1,24 +1,3 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_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 +. /test-init.sh diff --git a/test/TEST-11-LVM/test-init.sh b/test/TEST-11-LVM/test-init.sh index ba42fc2d8..c418b8bce 100755 --- a/test/TEST-11-LVM/test-init.sh +++ b/test/TEST-11-LVM/test-init.sh @@ -1,24 +1,3 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_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 +. /test-init.sh diff --git a/test/TEST-12-RAID-DEG/test-init.sh b/test/TEST-12-RAID-DEG/test-init.sh index 71685fb14..c418b8bce 100755 --- a/test/TEST-12-RAID-DEG/test-init.sh +++ b/test/TEST-12-RAID-DEG/test-init.sh @@ -1,27 +1,3 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_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 / -if [ -d /run/initramfs/etc ]; then - echo " rd.debug=0 " >> /run/initramfs/etc/cmdline -fi -poweroff -f +. /test-init.sh diff --git a/test/TEST-13-ENC-RAID-LVM/test-init.sh b/test/TEST-13-ENC-RAID-LVM/test-init.sh index 71685fb14..c418b8bce 100755 --- a/test/TEST-13-ENC-RAID-LVM/test-init.sh +++ b/test/TEST-13-ENC-RAID-LVM/test-init.sh @@ -1,27 +1,3 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_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 / -if [ -d /run/initramfs/etc ]; then - echo " rd.debug=0 " >> /run/initramfs/etc/cmdline -fi -poweroff -f +. /test-init.sh diff --git a/test/TEST-14-IMSM/test-init.sh b/test/TEST-14-IMSM/test-init.sh index 71685fb14..c418b8bce 100755 --- a/test/TEST-14-IMSM/test-init.sh +++ b/test/TEST-14-IMSM/test-init.sh @@ -1,27 +1,3 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_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 / -if [ -d /run/initramfs/etc ]; then - echo " rd.debug=0 " >> /run/initramfs/etc/cmdline -fi -poweroff -f +. /test-init.sh diff --git a/test/TEST-15-BTRFSRAID/test-init.sh b/test/TEST-15-BTRFSRAID/test-init.sh index 668b87120..c418b8bce 100755 --- a/test/TEST-15-BTRFSRAID/test-init.sh +++ b/test/TEST-15-BTRFSRAID/test-init.sh @@ -1,25 +1,3 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_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 +. /test-init.sh diff --git a/test/TEST-16-DMSQUASH/test-init.sh b/test/TEST-16-DMSQUASH/test-init.sh index d23fcef3e..13c88aaf5 100755 --- a/test/TEST-16-DMSQUASH/test-init.sh +++ b/test/TEST-16-DMSQUASH/test-init.sh @@ -1,13 +1,4 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_marker if grep -qF ' rd.live.overlay=LABEL=persist ' /proc/cmdline; then # Writing to a file in the root filesystem lets test_run() verify that the autooverlay module successfully created @@ -15,17 +6,4 @@ if grep -qF ' rd.live.overlay=LABEL=persist ' /proc/cmdline; then echo "dracut-autooverlay-success" > /overlay-marker fi -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 +. /test-init.sh diff --git a/test/TEST-17-LVM-THIN/test-init.sh b/test/TEST-17-LVM-THIN/test-init.sh index ba42fc2d8..c418b8bce 100755 --- a/test/TEST-17-LVM-THIN/test-init.sh +++ b/test/TEST-17-LVM-THIN/test-init.sh @@ -1,24 +1,3 @@ #!/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/scsi-0QEMU_QEMU_HARDDISK_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 +. /test-init.sh diff --git a/test/TEST-18-UEFI/test-init.sh b/test/TEST-18-UEFI/test-init.sh index 0000e15df..c418b8bce 100755 --- a/test/TEST-18-UEFI/test-init.sh +++ b/test/TEST-18-UEFI/test-init.sh @@ -1,23 +1,3 @@ #!/bin/sh -export PATH=/usr/sbin:/usr/bin:/sbin:/bin - -[ -e /proc/self/mounts ] \ - || (mkdir -p /proc && mount -t proc -o nosuid,noexec,nodev proc /proc) - -grep -q '^sysfs /sys sysfs' /proc/self/mounts \ - || (mkdir -p /sys && mount -t sysfs -o nosuid,noexec,nodev sysfs /sys) - -grep -q '^devtmpfs /dev devtmpfs' /proc/self/mounts \ - || (mkdir -p /dev && mount -t devtmpfs -o mode=755,noexec,nosuid,strictatime devtmpfs /dev) - -grep -q '^tmpfs /run tmpfs' /proc/self/mounts \ - || (mkdir -p /run && mount -t tmpfs -o mode=755,noexec,nosuid,strictatime tmpfs /run) - -: > /dev/watchdog - -exec > /dev/console 2>&1 - -echo "made it to the rootfs! Powering down." -echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_marker -poweroff -f +. /test-init.sh