diff options
| author | tv <tv@krebsco.de> | 2026-11-21 16:17:35 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-25 22:53:22 +0100 |
| commit | 595f6e3f69702aa50f17d37eb49d9050257307a0 (patch) | |
| tree | fdd2a8ffe357e7dd425a564193c024d7abb089ec /tests/qemu/firecracker.sh | |
| parent | fe46f7703e6145af9d3c9eb43d6ded19b316c83c (diff) | |
tests: the run script in qemu, and a NixOS VM test of modules/host
Both were only in the sandbox the project was developed in so far.
tests/qemu builds the run script with a qemu stand-in for Firecracker
(same kernel, initrd, drives, vsock via vhost-device-vsock; network via
qemu's user networking, the guest's port 22 on 127.0.0.1:2222) and a
test layer running a script at the end of boot, its output on the
console. The run script still takes a tap, so it needs modules/host
where it runs.
tests/vm-host.nix is a NixOS VM test of modules/host, with network
namespaces on veths in place of taps as guests: a VM's static address
by name, tcp:// rules over IPv4 and IPv6 and by name, DNS, anti-spoofing,
POST /check, the path units and the timer.
Diffstat (limited to 'tests/qemu/firecracker.sh')
| -rw-r--r-- | tests/qemu/firecracker.sh | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/qemu/firecracker.sh b/tests/qemu/firecracker.sh new file mode 100644 index 0000000..08f766d --- /dev/null +++ b/tests/qemu/firecracker.sh @@ -0,0 +1,27 @@ +# A stand-in for firecracker --no-api --config-file FILE, for testing the +# run script where there's no Firecracker: boots the same kernel, initrd, +# drives, vsock (vhost-device-vsock does the same uds_path_PORT +# convention) and network interface (qemu's user networking; guest port 22 +# forwarded to 127.0.0.1:${FC_TEST_SSH_PORT:-2222}) in qemu, with +# virtio-pci instead of virtio-mmio (see debug.nix). +set -efu +config=$3 +get() { jq -r "$1" "$config"; } +uds=$(get .vsock.uds_path) +vhost=$uds.vhost +vhost-device-vsock --guest-cid 3 --socket "$vhost" --uds-path "$uds" > "$uds.vhost.log" 2>&1 & +vhost_pid=$! +trap 'kill $vhost_pid 2> /dev/null || :' EXIT +while ! test -S "$vhost"; do sleep 0.1; done +mem=$(get '."machine-config".mem_size_mib') +args=$(get '."boot-source".boot_args') +# shellcheck disable=SC2046 +qemu-system-x86_64 -machine accel=kvm:tcg -nographic -no-reboot \ + -m "$mem" -smp "$(get '."machine-config".vcpu_count')" \ + -object memory-backend-memfd,id=mem,size="$mem"M,share=on -numa node,memdev=mem \ + -kernel "$(printf %s "$args" | sed -n 's|.*init=\([^ ]*\)/init.*|\1|p')/kernel" \ + -initrd "$(get '."boot-source".initrd_path')" -append "$args" \ + -chardev socket,id=vs,path="$vhost" -device vhost-user-vsock-pci,chardev=vs \ + $(jq -r '.drives[] | "-drive file=\(.path_on_host),if=virtio,format=raw" + (if .is_read_only then ",readonly=on" else "" end)' "$config") \ + -netdev user,id=n,hostfwd=tcp:127.0.0.1:"${FC_TEST_SSH_PORT:-2222}"-:22 \ + -device virtio-net-pci,netdev=n,mac="$(get '."network-interfaces"[0].guest_mac')" |
