#!/bin/bash # Boots IMAGE headless and waits for the self-test (init's SMP checks, then # spawntest) to report; the machine halts itself when done. Exit 0 only on # "SMPTEST PASS". set -uo pipefail IMAGE="${1:?usage: test-qemu.sh IMAGE}" SMP="${SMP:-4}" KERNEL="target/riscv64gc-unknown-none-elf/release/adapter-riscv" LOG="$(mktemp -t kos-test-qemu.XXXXXX)" timeout ${QT:-120} qemu-system-riscv64 -machine virt -smp "${SMP}" -bios default \ -kernel "${KERNEL}" \ -drive "file=${IMAGE},if=none,format=raw,id=hd0" -device virtio-blk-device,drive=hd0 \ -device virtio-gpu-device -device virtio-keyboard-device \ -display none -serial "file:${LOG}" -monitor none status=$? grep -a "smptest:\|spawntest:\|Hello\|SMPTEST" "${LOG}" # What k-os wrote must be ext4 that the real tools accept. disk_ok=1 if command -v e2fsck >/dev/null && command -v debugfs >/dev/null; then if ! e2fsck -fn "${IMAGE}" >"${LOG}.fsck" 2>&1; then echo "test-qemu: e2fsck rejects the disk:"; cat "${LOG}.fsck"; disk_ok=0 elif [ "$(debugfs -R 'cat /selftest.txt' "${IMAGE}" 2>/dev/null)" != "written by k-os on ext4" ]; then echo "test-qemu: /selftest.txt is not on the disk"; disk_ok=0 else echo "test-qemu: e2fsck clean, file on disk" fi rm -f "${LOG}.fsck" fi if [ "${disk_ok}" -eq 1 ] && grep -aq "SMPTEST PASS" "${LOG}"; then echo "test-qemu: pass (${SMP} harts)" rm -f "${LOG}" exit 0 fi [ "${status}" -eq 124 ] && echo "test-qemu: timed out" echo "test-qemu: FAIL, last serial output (${LOG}):" tail -20 "${LOG}" exit 1