xref: /haiku/src/tests/qemu-boot-test (revision 4c8e85b316c35a9161f5a1c50ad70bc91c83a76f)
1#!/bin/bash
2#
3# A quick standard test of Haiku booting under qemu in various configurations
4#
5# Example usages:
6#   x86_64 bios
7#     ../src/tests/qemu-boot-test x86_64 bios haiku-nightly-anyboot.iso
8#   x86_64 efi
9#     ../src/tests/qemu-boot-test x86_64 efi haiku-nightly-anyboot.iso
10#   riscv64 opensbi  w/u-boot payload
11#     ../src/tests/qemu-boot-test riscv64 kernel:~/Code/firmware/u-boot/riscv64/qemu/u-boot.bin haiku-mmc.image
12
13if [ $# -lt 3 ]; then
14	echo "Usage: $0 <arch> <bios|efi|bios:(file)|kernel:(file)> <image>"
15	exit 1;
16fi
17
18ARCH=$1
19PLATFORM=$2
20IMAGE=$3
21EMULATOR=qemu-system-$ARCH
22EXTRAS="-parallel none"
23
24function check_logs {
25	FILE=$1
26	echo -n "    Haiku kernel loaded: "
27	# First output from kernel on boot
28	if grep -q "Welcome to kernel debugger output" $FILE; then
29		echo "YES"
30	else
31		echo "NO"
32	fi
33	# Checking for a KDL
34	echo -n "    Potential KDL Detected: "
35	if grep -q "kdebug>" $FILE; then
36		echo "YES"
37	else
38		echo "NO"
39	fi
40	echo "    Potential issues in logs:"
41	egrep -i "FATAL|ERROR|FAIL|GDB" $FILE | grep -vi " No error"
42}
43
44case "$PLATFORM" in
45bios)
46	EXTRAS="$EXTRAS"
47	;;
48efi)
49	eval BIOS="${EFI_BIOS}:-/usr/share/edk2/ovmf/OVMF_CODE.fd"
50	EXTRAS="$EXTRAS -bios $QEMU_BIOS"
51	;;
52bios:*)
53	eval BIOS=$(echo "$PLATFORM" | cut -d":" -f2)
54	EXTRAS="$EXTRAS -bios $BIOS"
55	;;
56kernel:*)
57	eval BIOS=$(echo "$PLATFORM" | cut -d":" -f2)
58	EXTRAS="$EXTRAS -kernel $BIOS"
59	;;
60*)
61	EXTRAS="$EXTRAS"
62	;;
63esac
64
65echo "We're going to step through the potential boot options for $ARCH under qemu"
66echo ""
67echo -n "Press enter to begin..."
68read
69
70TEST_SERIALLOG="/tmp/test-$ARCH-serial.mon"
71EXTRAS="$EXTRAS -chardev vc,id=serial,logfile=$TEST_SERIALLOG,signal=off -serial chardev:serial"
72> $TEST_SERIALLOG
73
74case "$ARCH" in
75"x86" | "x86_64")
76	MEMORY=2048
77	TEST_FILE="/tmp/test-$ARCH.iso"
78	EMULATOR="$EMULATOR --enable-kvm -m $MEMORY $EXTRAS"
79	rm -f $TEST_FILE
80
81	echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
82	echo "+++ Testing $PLATFORM CDROM boot..."
83	cp $IMAGE $TEST_FILE
84	$EMULATOR -cdrom $TEST_FILE
85	check_logs $TEST_SERIALLOG
86	rm -f $TEST_FILE $TEST_SERIALLOG
87
88	echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
89	echo "+++ Testing $PLATFORM IDE boot..."
90	cp $IMAGE $TEST_FILE
91	$EMULATOR -drive file=$TEST_FILE,format=raw,if=ide
92	check_logs $TEST_SERIALLOG
93	rm -f $TEST_FILE $TEST_SERIALLOG
94
95	echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
96	echo "+++ Testing $PLATFORM USB boot..."
97	cp $IMAGE $TEST_FILE
98	$EMULATOR -drive if=none,id=stick,file=$TEST_FILE,format=raw -device qemu-xhci,id=xhci -device usb-storage,bus=xhci.0,drive=stick
99	check_logs $TEST_SERIALLOG
100	rm -f $TEST_FILE $TEST_SERIALLOG
101    ;;
102"riscv64")
103	MEMORY=2048
104	TEST_FILE="/tmp/test-$ARCH.mmu"
105	EMULATOR="$EMULATOR -m $MEMORY -M virt $EXTRAS"
106	rm -f $TEST_FILE $TEST_SERIALLOG
107
108	echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
109	echo "+++ Testing $PLATFORM boot..."
110	cp $IMAGE $TEST_FILE
111	$EMULATOR -device ati-vga -drive file=$TEST_FILE,format=raw,if=virtio
112	check_logs $TEST_SERIALLOG
113	rm -f $TEST_FILE $TEST_SERIALLOG
114	;;
115*)
116	echo "Error: Unknown architecture!"
117    ;;
118esac
119