1#!/usr/bin/env bash 2 3if [ -z "$KUT_STANDALONE" ]; then 4 if [ ! -f config.mak ]; then 5 echo "run ./configure && make first. See ./configure -h" 6 exit 2 7 fi 8 source config.mak 9 source scripts/arch-run.bash 10 source scripts/vmm.bash 11fi 12 13vmm_check_supported 14 15function arch_run_qemu() 16{ 17 # Allow user overrides of some config.mak variables 18 mach=$MACHINE_OVERRIDE 19 qemu_cpu=$TARGET_CPU_OVERRIDE 20 firmware=$FIRMWARE_OVERRIDE 21 22 : "${mach:=virt}" 23 : "${qemu_cpu:=$TARGET_CPU}" 24 : "${qemu_cpu:=$DEFAULT_QEMU_CPU}" 25 : "${firmware:=$FIRMWARE}" 26 [ "$firmware" ] && firmware="-bios $firmware" 27 28 set_qemu_accelerator || exit $? 29 [ "$ACCEL" = "kvm" ] && QEMU_ARCH=$HOST 30 acc="-accel $ACCEL$ACCEL_PROPS" 31 32 qemu=$(search_qemu_binary) || exit $? 33 if [ "$mach" = 'virt' ] && ! $qemu -machine '?' | grep -q 'RISC-V VirtIO board'; then 34 echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting." 35 exit 2 36 fi 37 mach="-machine $mach" 38 39 command="$qemu -nodefaults -nographic -serial mon:stdio" 40 command+=" $mach $acc $firmware -cpu $qemu_cpu " 41 command="$(migration_cmd) $(timeout_cmd) $command" 42 43 if [ "$UEFI_SHELL_RUN" = "y" ]; then 44 ENVIRON_DEFAULT=n run_test_status $command "$@" 45 else 46 # We return the exit code via stdout, not via the QEMU return code 47 run_test_status $command -kernel "$@" 48 fi 49} 50 51function arch_run_kvmtool() 52{ 53 local command 54 55 if [ "$HOST" != "riscv32" ] && [ "$HOST" != "riscv64" ]; then 56 echo "kvmtool requires KVM but the host ('$HOST') is not riscv" >&2 57 exit 2 58 fi 59 60 kvmtool=$(search_kvmtool_binary) || 61 exit $? 62 63 if [ "$ACCEL" ] && [ "$ACCEL" != "kvm" ]; then 64 echo "kvmtool does not support $ACCEL" >&2 65 exit 2 66 fi 67 68 if ! kvm_available; then 69 echo "kvmtool requires KVM but not available on the host" >&2 70 exit 2 71 fi 72 73 command="$(timeout_cmd) $kvmtool run" 74 if ( [ "$HOST" = "riscv64" ] && [ "$ARCH" = "riscv32" ] ) || 75 ( [ "$HOST" = "riscv32" ] && [ "$ARCH" = "riscv64" ] ); then 76 echo "Cannot run guests with a different xlen than the host" >&2 77 exit 2 78 else 79 run_test_status $command --kernel "$@" 80 fi 81} 82 83case $(vmm_get_target) in 84qemu) 85 arch_run_qemu "$@" 86 ;; 87kvmtool) 88 arch_run_kvmtool "$@" 89 ;; 90esac 91