diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:29:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:29:49 +0000 |
commit | 67c56c3a28638e52dcb16c58f910682579367093 (patch) | |
tree | 4e18c10d4dc8f987a1ea77be8aebf2075ac4930c /debian/tests | |
parent | Adding upstream version 0.140. (diff) | |
download | initramfs-tools-debian.tar.xz initramfs-tools-debian.zip |
Adding debian version 0.140.debian/0.140debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/tests')
-rwxr-xr-x | debian/tests/amd64-ata-only | 22 | ||||
-rwxr-xr-x | debian/tests/amd64-busybox | 19 | ||||
-rwxr-xr-x | debian/tests/amd64-klibc | 19 | ||||
-rwxr-xr-x | debian/tests/amd64-panic-shell | 32 | ||||
-rwxr-xr-x | debian/tests/amd64-separate-usr | 36 | ||||
-rwxr-xr-x | debian/tests/amd64-virtio-only | 22 | ||||
-rw-r--r-- | debian/tests/control | 27 | ||||
-rwxr-xr-x | debian/tests/shellcheck | 25 | ||||
-rw-r--r-- | debian/tests/test-common | 100 |
9 files changed, 302 insertions, 0 deletions
diff --git a/debian/tests/amd64-ata-only b/debian/tests/amd64-ata-only new file mode 100755 index 0000000..b91601e --- /dev/null +++ b/debian/tests/amd64-ata-only @@ -0,0 +1,22 @@ +#!/bin/sh -e + +SUPPORTED_FLAVOURS='amd64 generic' +ROOTDISK_QEMU_IF=ide +ROOTDISK_LINUX_NAME=sda +. debian/tests/test-common + +cat >>"${CONFDIR}/initramfs.conf" <<EOF +MODULES=list +BUSYBOX=n +FSTYPE=ext2 +EOF +cat >"${CONFDIR}/modules" <<EOF +ext2 +ata_piix +sd_mod +EOF +build_initramfs + +build_rootfs_ext2 + +run_qemu_amd64 diff --git a/debian/tests/amd64-busybox b/debian/tests/amd64-busybox new file mode 100755 index 0000000..3b6094c --- /dev/null +++ b/debian/tests/amd64-busybox @@ -0,0 +1,19 @@ +#!/bin/sh -e + +SUPPORTED_FLAVOURS='amd64 generic' +. debian/tests/test-common + +cat >>"${CONFDIR}/initramfs.conf" <<EOF +MODULES=most +BUSYBOX=y +FSTYPE=ext2 +EOF +build_initramfs +lsinitramfs "${INITRAMFS}" | grep -qw busybox + +build_rootfs_ext2 + +run_qemu_amd64 + +# Check that fsck ran +grep -q "^/dev/${ROOTDISK_LINUX_NAME}: clean," "${OUTPUT}" diff --git a/debian/tests/amd64-klibc b/debian/tests/amd64-klibc new file mode 100755 index 0000000..281f995 --- /dev/null +++ b/debian/tests/amd64-klibc @@ -0,0 +1,19 @@ +#!/bin/sh -e + +SUPPORTED_FLAVOURS='amd64 generic' +. debian/tests/test-common + +cat >>"${CONFDIR}/initramfs.conf" <<EOF +MODULES=most +BUSYBOX=n +FSTYPE=ext2 +EOF +build_initramfs +! lsinitramfs "${INITRAMFS}" | grep -qw busybox + +build_rootfs_ext2 + +run_qemu_amd64 + +# Check that fsck ran +grep -q "^/dev/${ROOTDISK_LINUX_NAME}: clean," "${OUTPUT}" diff --git a/debian/tests/amd64-panic-shell b/debian/tests/amd64-panic-shell new file mode 100755 index 0000000..ad42f8f --- /dev/null +++ b/debian/tests/amd64-panic-shell @@ -0,0 +1,32 @@ +#!/bin/sh -e + +SUPPORTED_FLAVOURS='amd64 generic' +ROOTDISK_QEMU_IF=virtio +ROOTDISK_LINUX_NAME=nonexistent +. debian/tests/test-common + +cat >>"${CONFDIR}/initramfs.conf" <<EOF +MODULES=list +BUSYBOX=n +FSTYPE=ext2 +EOF +cat >"${CONFDIR}/modules" <<EOF +ext2 +virtio_pci +virtio_blk +EOF +build_initramfs + +build_rootfs_ext2 + +run_qemu_nocheck_amd64 +grep -qF "ALERT! /dev/nonexistent does not exist. Dropping to a shell!" "${OUTPUT}" +grep -qF "(initramfs) " "${OUTPUT}" + +run_qemu_nocheck_amd64 "panic=-1" +grep -qF "Rebooting automatically due to panic= boot argument" "${OUTPUT}" +! grep -qF "(initramfs) " "${OUTPUT}" + +run_qemu_nocheck_amd64 "panic=0" +grep -qF "Halting automatically due to panic= boot argument" "${OUTPUT}" +! grep -qF "(initramfs) " "${OUTPUT}" diff --git a/debian/tests/amd64-separate-usr b/debian/tests/amd64-separate-usr new file mode 100755 index 0000000..1a30152 --- /dev/null +++ b/debian/tests/amd64-separate-usr @@ -0,0 +1,36 @@ +#!/bin/sh -e + +SUPPORTED_FLAVOURS='amd64 generic' +ROOTDISK_QEMU_IF=virtio +ROOTDISK_LINUX_NAME=vda +USRDISK="$(mktemp)" +USRDISK_QEMU_IF=virtio +USRDISK_LINUX_NAME=vdb +. debian/tests/test-common + +cat >>"${CONFDIR}/initramfs.conf" <<EOF +MODULES=list +BUSYBOX=n +FSTYPE=ext2 +EOF +cat >"${CONFDIR}/modules" <<EOF +ext2 +virtio_pci +virtio_blk +EOF +build_initramfs + +# Set up /usr filesystem and fstab entry for it +mkdir -p "${ROOTDIR}/etc" +echo > "${ROOTDIR}/etc/fstab" "/dev/${USRDISK_LINUX_NAME} /usr ext2 defaults 0 2" +USRDIR="$(mktemp -d)" +mv "${ROOTDIR}/usr/"* "${USRDIR}" + +build_rootfs_ext2 +build_fs_ext2 "${USRDIR}" "${USRDISK}" + +run_qemu_amd64 + +# Check that fsck ran on both devices +grep -q "^/dev/${ROOTDISK_LINUX_NAME}: clean," "${OUTPUT}" +grep -q "^/dev/${USRDISK_LINUX_NAME}: clean," "${OUTPUT}" diff --git a/debian/tests/amd64-virtio-only b/debian/tests/amd64-virtio-only new file mode 100755 index 0000000..5cca6da --- /dev/null +++ b/debian/tests/amd64-virtio-only @@ -0,0 +1,22 @@ +#!/bin/sh -e + +SUPPORTED_FLAVOURS='amd64 generic' +ROOTDISK_QEMU_IF=virtio +ROOTDISK_LINUX_NAME=vda +. debian/tests/test-common + +cat >>"${CONFDIR}/initramfs.conf" <<EOF +MODULES=list +BUSYBOX=n +FSTYPE=ext2 +EOF +cat >"${CONFDIR}/modules" <<EOF +ext2 +virtio_pci +virtio_blk +EOF +build_initramfs + +build_rootfs_ext2 + +run_qemu_amd64 diff --git a/debian/tests/control b/debian/tests/control new file mode 100644 index 0000000..b3efe72 --- /dev/null +++ b/debian/tests/control @@ -0,0 +1,27 @@ +Tests: shellcheck +Depends: @, shellcheck +Restrictions: superficial + +Tests: amd64-klibc +Depends: @, qemu-system-x86, linux-image-amd64 | linux-image-generic:amd64, klibc-utils, genext2fs +Restrictions: skip-not-installable + +Tests: amd64-busybox +Depends: @, qemu-system-x86, linux-image-amd64 | linux-image-generic:amd64, klibc-utils, busybox | busybox-initramfs, genext2fs +Restrictions: skip-not-installable + +Tests: amd64-ata-only +Depends: @, qemu-system-x86, linux-image-amd64 | linux-image-generic:amd64, klibc-utils, genext2fs +Restrictions: skip-not-installable + +Tests: amd64-virtio-only +Depends: @, qemu-system-x86, linux-image-amd64 | linux-image-generic:amd64, klibc-utils, genext2fs +Restrictions: skip-not-installable + +Tests: amd64-separate-usr +Depends: @, qemu-system-x86, linux-image-amd64 | linux-image-generic:amd64, klibc-utils, genext2fs +Restrictions: skip-not-installable + +Tests: amd64-panic-shell +Depends: @, qemu-system-x86, linux-image-amd64 | linux-image-generic:amd64, klibc-utils, genext2fs +Restrictions: skip-not-installable diff --git a/debian/tests/shellcheck b/debian/tests/shellcheck new file mode 100755 index 0000000..37765a2 --- /dev/null +++ b/debian/tests/shellcheck @@ -0,0 +1,25 @@ +#!/bin/sh -eu + +export LC_COLLATE=C.UTF-8 +unset LC_ALL + +# The packages that install hook/boot scripts +dpkg -S /usr/share/initramfs-tools/hooks /usr/share/initramfs-tools/scripts \ + | sed 's/: .*//; s/, /\n/g' \ + | sort -u \ + > "$AUTOPKGTEST_TMP/installed-packages" + +# The packages that we're prepared to test +echo "initramfs-tools initramfs-tools-core klibc-utils kmod udev" \ + | sed 's/ /\n/g' \ + | sort -u \ + > "$AUTOPKGTEST_TMP/tested-packages" + +# Installed hook/boot scripts that we're prepared to test +join "$AUTOPKGTEST_TMP/installed-packages" "$AUTOPKGTEST_TMP/tested-packages" \ + | xargs dpkg -L \ + | grep -E '^/usr/share/initramfs-tools/(hooks|scripts)/' \ + | while read file; do test -f "$file" && printf '%s\n' "$file"; done \ + > "$AUTOPKGTEST_TMP/hook-boot-scripts" + +shellcheck -e SC1090,SC1091 -s dash /usr/bin/lsinitramfs /usr/sbin/mkinitramfs /usr/bin/unmkinitramfs /usr/share/initramfs-tools/hook-functions /usr/share/initramfs-tools/init /etc/kernel/postinst.d/initramfs-tools /etc/kernel/postrm.d/initramfs-tools /usr/sbin/update-initramfs $(cat "$AUTOPKGTEST_TMP/hook-boot-scripts") diff --git a/debian/tests/test-common b/debian/tests/test-common new file mode 100644 index 0000000..d1bf671 --- /dev/null +++ b/debian/tests/test-common @@ -0,0 +1,100 @@ +# -*- mode: sh -*- + +# Find kernel flavour and release +KVER= +for flavour in $SUPPORTED_FLAVOURS; do + KVER="$(dpkg-query -Wf '${Depends}' "linux-image-${flavour}" 2>/dev/null | tr ',' '\n' | sed -n 's/^ *linux-image-\([-a-z0-9+.]*\).*/\1/p')" + if [ "$KVER" ]; then + break + fi +done +if [ -z "$KVER" ]; then + echo >&2 "E: Test must set SUPPORTED_FLAVOURS and depend on those flavours" + exit 2 +fi + +if [ -n "${AUTOPKGTEST_TMP}" ]; then + export TMPDIR="${AUTOPKGTEST_TMP}" +fi + +# Skeleton configuration directory +CONFDIR="$(mktemp -d)" +cp conf/initramfs.conf "${CONFDIR}/initramfs.conf" +echo "RESUME=none" >>"${CONFDIR}/initramfs.conf" +touch "${CONFDIR}/modules" +mkdir "${CONFDIR}/scripts" + +# initramfs image file +INITRAMFS="$(mktemp)" + +# root disk image file +ROOTDISK="$(mktemp)" + +# root disk interface type (for qemu) and device name (for Linux) +test -n "${ROOTDISK_QEMU_IF}" || ROOTDISK_QEMU_IF=virtio +test -n "${ROOTDISK_LINUX_NAME}" || ROOTDISK_LINUX_NAME=vda + +# Create a root fs with a trivial userspace +ROOTDIR="$(mktemp -d)" +INIT_MESSAGE='root fs init system started successfully' +for subdir in bin dev lib proc run sbin sys usr usr/bin; do + mkdir "${ROOTDIR}/${subdir}" +done +cat >"${ROOTDIR}/sbin/init" <<EOF +#!/bin/sh -e +test -b /dev/${ROOTDISK_LINUX_NAME} +test -d /proc/1 +test -d /run/initramfs +test -d /sys/class +test -d /usr/bin +echo '${INIT_MESSAGE}' +poweroff +EOF +chmod a+x "${ROOTDIR}/sbin/init" +cp /usr/lib/klibc/bin/sh "${ROOTDIR}/bin/sh" +cp /usr/lib/klibc/bin/poweroff "${ROOTDIR}/bin/poweroff" +cp "$(dpkg -L libklibc | grep '^/lib/klibc.*\.so$')" "${ROOTDIR}/lib/" + +# VM output file +OUTPUT="$(mktemp)" + +build_initramfs() { + /usr/sbin/mkinitramfs -d "${CONFDIR}" -o "${INITRAMFS}" "${KVER}" +} + +build_fs_ext2() { + local dir="${1}" + local disk="${2}" + + # Get directory size + local blocks="$(du --summarize "${dir}" | cut -f 1)" + local inodes="$(du --summarize --inodes "${dir}" | cut -f 1)" + + # Add fudge factor + blocks="$((blocks + 20 + blocks / 4))" + inodes="$((inodes + 10))" + + # genext2fs writes status messages to stderr; hide that from + # autopkgtest + genext2fs 2>&1 -b "${blocks}" -N "${inodes}" -U -d "${dir}" "${disk}" +} + +build_rootfs_ext2() { + build_fs_ext2 "${ROOTDIR}" "${ROOTDISK}" +} + +_run_qemu_amd64() { + local extra_params="$*" + + timeout --foreground 60 qemu-system-x86_64 -m 1G -drive "file=${ROOTDISK},if=${ROOTDISK_QEMU_IF},media=disk,format=raw" ${USRDISK:+-drive "file=${USRDISK},if=${USRDISK_QEMU_IF},media=disk,format=raw"} -nographic -no-reboot -kernel "/boot/vmlinuz-${KVER}" -initrd "${INITRAMFS}" -append "root=/dev/${ROOTDISK_LINUX_NAME} ro console=ttyS0,115200 ${extra_params}" | tee "${OUTPUT}" +} + +run_qemu_nocheck_amd64() { + # hide error messages from autopkgtest + _run_qemu_amd64 2>&1 "$@" +} + +run_qemu_amd64() { + _run_qemu_amd64 "panic=-1" + grep -qF "${INIT_MESSAGE}" "${OUTPUT}" +} |