From c235cb62beefd03087e7cfc7f7f55f0c7c6601c9 Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 1 Aug 2026 00:00:00 +0000 Subject: Enter vmm A QEMU/KVM virtual machine manager in one POSIX shell script. Each VM is a directory of plain files under $VMMDIR, configured by a hand-edited KEY=VALUE file that is parsed rather than sourced, so nothing in it can inject a raw QEMU argument. Control is a QMP FIFO pair inside that directory, guarded by its permissions alone; nothing binds a TCP port. The tests are TAP without a framework and boot real guests where the host allows. --- tests/arch | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 tests/arch (limited to 'tests/arch') diff --git a/tests/arch b/tests/arch new file mode 100644 index 0000000..2f60451 --- /dev/null +++ b/tests/arch @@ -0,0 +1,143 @@ +# ARCH picks the qemu binary, the machine type and the display device. +# Nothing here needs /dev/kvm: another architecture is emulated. + +"$VMM" create ar1 64M >/dev/null 2>&1 +FW=/usr/share/qemu/edk2-aarch64-code.fd +[ -f "$FW" ] || FW=/usr/share/AAVMF/AAVMF_CODE.fd + +cfg ar1 < "$VMMDIR/ar1/config" +outputs 'accel=kvm' "the host architecture gets kvm" dryrun ar1 +outputs "-cpu 'host'" "the host architecture gets the host cpu" dryrun ar1 + +# A host with no /dev/kvm can still run its own architecture, slowly. +cfg ar1 < "$VMMDIR/ar1/config" +out=$(PATH=$NOQEMU "$VMM" start ar1 2>&1) && got=0 || got=$? +if [ "$got" != 0 ] && printf '%s' "$out" | grep -q 'qemu-system-.* is not on PATH'; then + ok "a qemu that is not installed is named at once" +else + notok "a qemu that is not installed is named at once" "exit $got: $out" +fi + +# Emulated end to end: the firmware really runs and really talks to the +# serial console, which is the whole point of passing -bios. +if [ -f "$FW" ] && command -v qemu-system-aarch64 >/dev/null 2>&1; then + cfg ar1 </dev/null 2>&1 || : +else + skip 3 "no qemu-system-aarch64 or no aarch64 firmware" +fi + +# Failure after spawn must reap only that child and remove every runtime +# object it may have created. +if command -v "qemu-system-$(uname -m)" >/dev/null 2>&1; then + "$VMM" create ar2 64M >/dev/null 2>&1 + printf 'not a qcow2 image\n' > "$VMMDIR/ar2/disk.qcow2" + cfg ar2 < "$FAKE" <<'EOF' +#!/bin/sh +sleep 5 +EOF +chmod +x "$FAKE" +"$VMM" create ar3 64M >/dev/null 2>&1 +out=$(PATH=$FAKEBIN:$PATH MONITOR_TIMEOUT=1 "$VMM" start ar3 2>&1) && got=0 || got=$? +if [ "$got" = 1 ]; then + ok "a start whose monitor never answers fails" +else + notok "a start whose monitor never answers fails" "exit $got: $out" +fi +left= +for cmdline in /proc/[0-9]*/cmdline; do + line= + IFS= read -r line 2>/dev/null < "$cmdline" || : + case $line in + *"-pidfile$VMMDIR/ar3/pid") + p=${cmdline#/proc/} + left="$left ${p%/cmdline}" + ;; + esac +done +if [ -z "$left" ]; then + ok "and kills the child it spawned" +else + notok "and kills the child it spawned" "still running:$left" + # shellcheck disable=SC2086 # a list of pids this loop collected + kill -9 $left 2>/dev/null || : +fi -- cgit v1.2.3