Merge branch 'introduce-run-qemu' into 'master'

refactor: Introduce debian/tests/run-qemu

See merge request kernel-team/initramfs-tools!103
This commit is contained in:
Ben Hutchings 2024-06-01 20:51:25 +00:00
commit 334920871a
2 changed files with 55 additions and 35 deletions

50
debian/tests/run-qemu vendored Executable file
View File

@ -0,0 +1,50 @@
#!/bin/sh
set -eu
# Run qemu-system for the system architecture
if test "$#" -lt 3; then
echo "${0##*/}: Error: Not enough parameters." >&2
echo "Usage: ${0##*/} kernel initrd append [extra_args]" >&2
exit 1
fi
kernel="$1"
initrd="$2"
append="$3"
shift 3
ARCHITECTURE=$(dpkg --print-architecture)
case "$ARCHITECTURE" in
arm64)
machine="virt,gic-version=max"
cpu="max,pauth-impdef=on"
efi_code=/usr/share/AAVMF/AAVMF_CODE.fd
efi_vars=/usr/share/AAVMF/AAVMF_VARS.fd
;;
armhf)
machine="virt"
efi_code=/usr/share/AAVMF/AAVMF32_CODE.fd
efi_vars=/usr/share/AAVMF/AAVMF32_VARS.fd
console=ttyAMA0
;;
ppc64el)
machine="cap-ccf-assist=off,cap-cfpc=broken,cap-ibs=broken,cap-sbbc=broken"
console=hvc0
;;
esac
if test -f "${efi_vars-}"; then
efi_vars_copy="$(mktemp -t "${efi_vars##*/}.XXXXXXXXXX")"
cp "$efi_vars" "$efi_vars_copy"
fi
set -- ${machine:+-machine "${machine}"} -cpu "${cpu-max}" -m 1G \
${efi_code:+-drive "file=${efi_code},if=pflash,format=raw,read-only=on"} \
${efi_vars:+-drive "file=${efi_vars_copy},if=pflash,format=raw"} \
-device virtio-rng-pci,rng=rng0 -object rng-random,filename=/dev/urandom,id=rng0 \
-nodefaults -no-reboot -kernel "${kernel}" -initrd "${initrd}" "$@" \
-append "console=${console:-ttyS0},115200 ro ${append}"
echo "${0##*/}: qemu-system-${ARCHITECTURE} $*"
exec "qemu-system-${ARCHITECTURE}" "$@"

View File

@ -13,8 +13,7 @@ if [ -z "$KVER" ]; then
exit 2
fi
ARCHITECTURE=$(dpkg --print-architecture)
case "$ARCHITECTURE" in
case "$(dpkg --print-architecture)" in
arm64)
# The Ubuntu arm64 autopkgtest runs rarely into the 1200 seconds timeout.
QEMU_TIMEOUT=1800
@ -160,47 +159,18 @@ build_rootfs_ext2() {
_run_qemu() {
local extra_params="$*"
local console cpu efi_code efi_vars efi_vars_copy machine
case "$ARCHITECTURE" in
arm64)
machine="virt,gic-version=max"
cpu="max,pauth-impdef=on"
efi_code=/usr/share/AAVMF/AAVMF_CODE.fd
efi_vars=/usr/share/AAVMF/AAVMF_VARS.fd
;;
armhf)
machine="virt"
efi_code=/usr/share/AAVMF/AAVMF32_CODE.fd
efi_vars=/usr/share/AAVMF/AAVMF32_VARS.fd
console=ttyAMA0
;;
ppc64el)
machine="cap-ccf-assist=off,cap-cfpc=broken,cap-ibs=broken,cap-sbbc=broken"
console=hvc0
;;
esac
if test -f "${efi_vars-}"; then
efi_vars_copy="${BASEDIR}/${efi_vars##*/}"
cp "$efi_vars" "$efi_vars_copy"
fi
echo "I: Running qemu-system-${ARCHITECTURE} (with a timeout of $QEMU_TIMEOUT seconds)..."
echo "I: Running qemu (with a timeout of $QEMU_TIMEOUT seconds)..."
timeout --foreground "$QEMU_TIMEOUT" \
"qemu-system-${ARCHITECTURE}" ${machine:+-machine "${machine}"} -cpu "${cpu-max}" -m 1G \
debian/tests/run-qemu /boot/vmlinu*-"${KVER}" "${INITRAMFS}" \
"root=/dev/${ROOTDISK_LINUX_NAME} ${extra_params}" -nographic \
-drive "file=${ROOTDISK},if=${ROOTDISK_QEMU_IF},media=disk,format=raw" \
${efi_code:+-drive "file=${efi_code},if=pflash,format=raw,read-only=on"} \
${efi_vars:+-drive "file=${efi_vars_copy},if=pflash,format=raw"} \
${USRDISK:+-drive "file=${USRDISK},if=${USRDISK_QEMU_IF},media=disk,format=raw"} \
-device virtio-rng-pci,rng=rng0 -object rng-random,filename=/dev/urandom,id=rng0 \
-nographic -no-reboot -kernel /boot/vmlinu*-"${KVER}" -initrd "${INITRAMFS}" \
-nodefaults -chardev stdio,id=char0 -serial chardev:char0 \
-device "virtio-net-pci,netdev=lan0,mac=52:54:00:65:43:21" \
-netdev "user,id=lan0,net=10.0.3.0/24,ipv6-net=fec7::/48,hostname=pizza,dnssearch=test,domainname=example.com,bootfile=/path/to/bootfile2" \
-device "virtio-net-pci,netdev=lan1,mac=52:54:00:12:34:56" \
-netdev "user,id=lan1,hostname=goulash,dnssearch=example,dnssearch=example.net,domainname=test,bootfile=/path/to/bootfile" \
-append "root=/dev/${ROOTDISK_LINUX_NAME} ro console=${console:-ttyS0},115200 ${extra_params}" | tee "${OUTPUT}"
-chardev stdio,id=char0 -serial chardev:char0 | tee "${OUTPUT}"
}
run_qemu_nocheck() {