xref: /haiku/src/tests/qemu-boot-test (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
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	echo "=============================================="
26	FILE=$1
27	echo -n "    Haiku kernel loaded: "
28	# First output from kernel on boot
29	if grep -q "Welcome to kernel debugger output" $FILE; then
30		echo "YES"
31	else
32		echo "NO"
33	fi
34	# Checking for a KDL
35	echo -n "    Potential KDL Detected: "
36	if grep -q "kdebug>" $FILE; then
37		echo "YES"
38	else
39		echo "NO"
40	fi
41	echo "=============================================="
42	echo "    Summary of issues in logs:"
43	grep -E -i "FATAL|ERROR|FAIL|GDB" $FILE | grep -vi " No error" | cut -d':' -f1 | sort | uniq -c | sort -nr
44	echo "=============================================="
45	echo "    Potential issues in logs:"
46	grep -E -i "FATAL|ERROR|FAIL|GDB" $FILE | grep -vi " No error"
47	echo "=============================================="
48}
49
50case "$PLATFORM" in
51bios)
52	EXTRAS="$EXTRAS"
53	;;
54efi)
55	eval BIOS="${EFI_BIOS}:-/usr/share/edk2/ovmf/OVMF_CODE.fd"
56	EXTRAS="$EXTRAS -bios $QEMU_BIOS"
57	;;
58bios:*)
59	eval BIOS=$(echo "$PLATFORM" | cut -d":" -f2)
60	EXTRAS="$EXTRAS -bios $BIOS"
61	;;
62kernel:*)
63	eval BIOS=$(echo "$PLATFORM" | cut -d":" -f2)
64	EXTRAS="$EXTRAS -kernel $BIOS"
65	;;
66*)
67	EXTRAS="$EXTRAS"
68	;;
69esac
70
71echo "We're going to step through the potential boot options for $ARCH under qemu"
72echo ""
73echo -n "Press enter to begin..."
74read
75
76TEST_SERIALLOG="/tmp/test-$ARCH-serial.mon"
77EXTRAS="$EXTRAS -chardev vc,id=serial,logfile=$TEST_SERIALLOG,signal=off -serial chardev:serial"
78> $TEST_SERIALLOG
79
80case "$ARCH" in
81"x86" | "x86_64")
82	MEMORY=2048
83	TEST_FILE="/tmp/test-$ARCH.iso"
84	EMULATOR="$EMULATOR --enable-kvm -m $MEMORY $EXTRAS"
85	rm -f $TEST_FILE
86
87	echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
88	echo "+++ Testing $PLATFORM CDROM boot..."
89	cp $IMAGE $TEST_FILE
90	$EMULATOR -cdrom $TEST_FILE
91	check_logs $TEST_SERIALLOG
92	rm -f $TEST_FILE $TEST_SERIALLOG
93
94	echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
95	echo "+++ Testing $PLATFORM IDE boot..."
96	cp $IMAGE $TEST_FILE
97	$EMULATOR -drive file=$TEST_FILE,format=raw,if=ide
98	check_logs $TEST_SERIALLOG
99	rm -f $TEST_FILE $TEST_SERIALLOG
100
101	echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
102	echo "+++ Testing $PLATFORM USB boot..."
103	cp $IMAGE $TEST_FILE
104	$EMULATOR -drive if=none,id=stick,file=$TEST_FILE,format=raw -device qemu-xhci,id=xhci -device usb-storage,bus=xhci.0,drive=stick
105	check_logs $TEST_SERIALLOG
106	rm -f $TEST_FILE $TEST_SERIALLOG
107    ;;
108"riscv64")
109	MEMORY=2048
110	TEST_FILE="/tmp/test-$ARCH.mmu"
111	EMULATOR="$EMULATOR -m $MEMORY -M virt $EXTRAS"
112	rm -f $TEST_FILE $TEST_SERIALLOG
113
114	echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
115	echo "+++ Testing $PLATFORM boot..."
116	cp $IMAGE $TEST_FILE
117	$EMULATOR -device ati-vga \
118		-global virtio-mmio.force-legacy=false \
119		-device virtio-tablet-device,bus=virtio-mmio-bus.0 \
120		-device virtio-keyboard-device,bus=virtio-mmio-bus.1 \
121		-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.2 \
122		-device virtio-net-device,netdev=usernet,bus=virtio-mmio-bus.3 \
123		-drive file=$TEST_FILE,format=raw,if=none,id=x0 \
124		-netdev user,id=usernet
125	check_logs $TEST_SERIALLOG
126	rm -f $TEST_FILE $TEST_SERIALLOG
127	;;
128*)
129	echo "Error: Unknown architecture!"
130    ;;
131esac
132