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" 77NETWORK="-netdev user,id=testnet,net=192.168.76.0/24,dhcpstart=192.168.76.9,hostfwd=tcp::5555-:22" 78#NETWORK="-netdev tap,id=testnet,ifname=Ethernet" 79EXTRAS="$EXTRAS $NETWORK -chardev vc,id=serial,logfile=$TEST_SERIALLOG,signal=off -serial chardev:serial" 80> $TEST_SERIALLOG 81 82case "$ARCH" in 83"x86" | "x86_64") 84 MEMORY=2048 85 TEST_FILE="/tmp/test-$ARCH.iso" 86 EMULATOR="$EMULATOR --enable-kvm -m $MEMORY $EXTRAS" 87 rm -f $TEST_FILE 88 89 echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 90 echo "+++ Testing $PLATFORM CDROM boot..." 91 cp $IMAGE $TEST_FILE 92 $EMULATOR -cdrom $TEST_FILE 93 check_logs $TEST_SERIALLOG 94 rm -f $TEST_FILE $TEST_SERIALLOG 95 96 echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 97 echo "+++ Testing $PLATFORM IDE boot..." 98 cp $IMAGE $TEST_FILE 99 $EMULATOR -drive file=$TEST_FILE,format=raw,if=ide 100 check_logs $TEST_SERIALLOG 101 rm -f $TEST_FILE $TEST_SERIALLOG 102 103 echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 104 echo "+++ Testing $PLATFORM USB boot..." 105 cp $IMAGE $TEST_FILE 106 $EMULATOR -drive if=none,id=stick,file=$TEST_FILE,format=raw -device qemu-xhci,id=xhci -device usb-storage,bus=xhci.0,drive=stick 107 check_logs $TEST_SERIALLOG 108 rm -f $TEST_FILE $TEST_SERIALLOG 109 ;; 110"arm64") 111 EMULATOR=qemu-system-aarch64 112 MEMORY=2048 113 TEST_FILE="/tmp/test-$ARCH.mmu" 114 EMULATOR="$EMULATOR -m $MEMORY -M virt $EXTRAS" 115 rm -f $TEST_FILE $TEST_SERIALLOG 116 117 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 118 echo "+++ Testing $PLATFORM boot..." 119 cp $IMAGE $TEST_FILE 120 $EMULATOR \ 121 -cpu max \ 122 -global virtio-mmio.force-legacy=false \ 123 -device qemu-xhci -device usb-tablet -device usb-kbd \ 124 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \ 125 -device virtio-net-device,netdev=testnet,bus=virtio-mmio-bus.1 \ 126 -drive file=$TEST_FILE,format=raw,if=none,id=x0 127 check_logs $TEST_SERIALLOG 128 rm -f $TEST_FILE $TEST_SERIALLOG 129 ;; 130"riscv64") 131 MEMORY=2048 132 TEST_FILE="/tmp/test-$ARCH.mmu" 133 EMULATOR="$EMULATOR -m $MEMORY -M virt $EXTRAS" 134 rm -f $TEST_FILE $TEST_SERIALLOG 135 136 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 137 echo "+++ Testing $PLATFORM boot..." 138 cp $IMAGE $TEST_FILE 139 # virtio broken currently for input: 140 # -device virtio-tablet-device,bus=virtio-mmio-bus.2 141 # -device virtio-keyboard-device,bus=virtio-mmio-bus.3 142 # Network communication doesn't work: 143 # -device virtio-net-device,netdev=testnet,bus=virtio-mmio-bus.1 \ 144 $EMULATOR -device ati-vga \ 145 -global virtio-mmio.force-legacy=false \ 146 -device qemu-xhci -device usb-tablet -device usb-kbd \ 147 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \ 148 -device usb-net,netdev=testnet \ 149 -drive file=$TEST_FILE,format=raw,if=none,id=x0 150 check_logs $TEST_SERIALLOG 151 rm -f $TEST_FILE $TEST_SERIALLOG 152 ;; 153*) 154 echo "Error: Unknown architecture!" 155 ;; 156esac 157