Files
kubesolo-os/test/qemu/test-boot.sh
Adolfo Delorenzo 6c15ba7776
Some checks failed
CI / Go Tests (push) Has been cancelled
CI / Build Go Binaries (amd64, linux, linux-amd64) (push) Has been cancelled
CI / Build Go Binaries (arm64, linux, linux-arm64) (push) Has been cancelled
CI / Shellcheck (push) Has been cancelled
fix: kernel AppArmor 2-pass olddefconfig and QEMU test direct kernel boot
The stock TinyCore kernel config has "# CONFIG_SECURITY is not set" which
caused make olddefconfig to silently revert all security configs in a single
pass. Fix by applying security configs (AppArmor, Audit, LSM) after the
first olddefconfig resolves base dependencies, then running a second pass.
Added mandatory verification that exits on missing critical configs.

All QEMU test scripts converted from broken -cdrom + -append pattern to
direct kernel boot (-kernel + -initrd) via shared test/lib/qemu-helpers.sh
helper library. The -append flag only works with -kernel, not -cdrom.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 14:11:38 -06:00

83 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# test-boot.sh — Automated boot test: verify KubeSolo OS boots in QEMU
# Usage: ./test/qemu/test-boot.sh <iso-path>
# Exit 0 = PASS, Exit 1 = FAIL
set -euo pipefail
ISO="${1:?Usage: $0 <path-to-iso>}"
TIMEOUT_BOOT=${TIMEOUT_BOOT:-120} # seconds to wait for boot success marker
SERIAL_LOG=$(mktemp /tmp/kubesolo-boot-test-XXXXXX.log)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
. "$SCRIPT_DIR/../lib/qemu-helpers.sh"
# Temp data disk
DATA_DISK=$(mktemp /tmp/kubesolo-data-XXXXXX.img)
dd if=/dev/zero of="$DATA_DISK" bs=1M count=512 2>/dev/null
mkfs.ext4 -q -L KSOLODATA "$DATA_DISK" 2>/dev/null
QEMU_PID=""
EXTRACT_DIR=""
cleanup() {
[ -n "$QEMU_PID" ] && kill "$QEMU_PID" 2>/dev/null || true
rm -f "$DATA_DISK" "$SERIAL_LOG"
[ -n "$EXTRACT_DIR" ] && rm -rf "$EXTRACT_DIR"
}
trap cleanup EXIT
echo "==> Boot test: $ISO"
echo " Timeout: ${TIMEOUT_BOOT}s"
echo " Serial log: $SERIAL_LOG"
# Extract kernel from ISO
EXTRACT_DIR="$(mktemp -d /tmp/kubesolo-extract-XXXXXX)"
extract_kernel_from_iso "$ISO" "$EXTRACT_DIR"
KVM_FLAG=$(detect_kvm)
[ -n "$KVM_FLAG" ] && echo " KVM acceleration: enabled"
# Launch QEMU in background with direct kernel boot
# shellcheck disable=SC2086
qemu-system-x86_64 \
-m 2048 -smp 2 \
-nographic \
$KVM_FLAG \
-kernel "$VMLINUZ" \
-initrd "$INITRAMFS" \
-drive "file=$DATA_DISK,format=raw,if=virtio" \
-net "nic,model=virtio" \
-net user \
-serial "file:$SERIAL_LOG" \
-append "console=ttyS0,115200n8 kubesolo.data=/dev/vda kubesolo.debug" \
&
QEMU_PID=$!
# Wait for boot success marker in serial log
echo " Waiting for boot..."
ELAPSED=0
while [ "$ELAPSED" -lt "$TIMEOUT_BOOT" ]; do
if grep -q "\[kubesolo-init\] \[OK\] KubeSolo is running" "$SERIAL_LOG" 2>/dev/null; then
echo ""
echo "==> PASS: KubeSolo OS booted successfully in ${ELAPSED}s"
exit 0
fi
if ! kill -0 "$QEMU_PID" 2>/dev/null; then
echo ""
echo "==> FAIL: QEMU exited prematurely"
echo " Last 20 lines of serial log:"
tail -20 "$SERIAL_LOG" 2>/dev/null
exit 1
fi
sleep 1
ELAPSED=$((ELAPSED + 1))
printf "\r Elapsed: %ds / %ds" "$ELAPSED" "$TIMEOUT_BOOT"
done
echo ""
echo "==> FAIL: Boot did not complete within ${TIMEOUT_BOOT}s"
echo " Last 30 lines of serial log:"
tail -30 "$SERIAL_LOG" 2>/dev/null
exit 1