From 946c3c958326fabd4b5c373a04b5a30cf9b8d3de Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Mon, 20 May 2024 00:15:23 +0200 Subject: [PATCH] refactor: Introduce debian/tests/run-qemu The Ubuntu autopkgtest `qemu-net-dnsmasq` needs to call qemu with different parameters. Move calling qemu into the separate `run-qemu` script for better abstraction. --- debian/tests/run-qemu | 50 ++++++++++++++++++++++++++++++++++++++++ debian/tests/test-common | 40 ++++---------------------------- 2 files changed, 55 insertions(+), 35 deletions(-) create mode 100755 debian/tests/run-qemu diff --git a/debian/tests/run-qemu b/debian/tests/run-qemu new file mode 100755 index 0000000..d3c3e99 --- /dev/null +++ b/debian/tests/run-qemu @@ -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}" "$@" diff --git a/debian/tests/test-common b/debian/tests/test-common index deaa6a4..981aafe 100644 --- a/debian/tests/test-common +++ b/debian/tests/test-common @@ -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() {