xref: /kvm-unit-tests/arm/run (revision abdc5d02a7796a55802509ac9bb704c721f2a5f6)
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
10fi
11qemu_cpu="$TARGET_CPU"
12
13if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
14   [ "$HOST" = "aarch64" ] && [ "$ARCH" = "arm" ] &&
15   [ "$(basename $QEMU)" = "qemu-system-arm" ]; then
16	ACCEL="tcg"
17fi
18
19set_qemu_accelerator || exit $?
20if [ "$ACCEL" = "kvm" ]; then
21	QEMU_ARCH=$HOST
22fi
23
24qemu=$(search_qemu_binary) ||
25	exit $?
26
27if ! $qemu -machine '?' | grep -q 'ARM Virtual Machine'; then
28	echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting."
29	exit 2
30fi
31
32M='-machine virt'
33
34if [ "$ACCEL" = "kvm" ]; then
35	if $qemu $M,\? | grep -q gic-version; then
36		M+=',gic-version=host'
37	fi
38fi
39
40if [ -z "$qemu_cpu" ]; then
41	if ( [ "$ACCEL" = "kvm" ] || [ "$ACCEL" = "hvf" ] ) &&
42	   ( [ "$HOST" = "aarch64" ] || [ "$HOST" = "arm" ] ); then
43		qemu_cpu="host"
44		if [ "$ARCH" = "arm" ] && [ "$HOST" = "aarch64" ]; then
45			qemu_cpu+=",aarch64=off"
46		fi
47	else
48		qemu_cpu="$DEFAULT_QEMU_CPU"
49	fi
50fi
51
52if [ "$ARCH" = "arm" ]; then
53	M+=",highmem=off"
54fi
55
56if ! $qemu $M -device '?' | grep -q virtconsole; then
57	echo "$qemu doesn't support virtio-console for chr-testdev. Exiting."
58	exit 2
59fi
60
61if ! $qemu $M -chardev '?' | grep -q testdev; then
62	echo "$qemu doesn't support chr-testdev. Exiting."
63	exit 2
64fi
65
66if [ "$UEFI_SHELL_RUN" != "y" ] && [ "$EFI_USE_ACPI" != "y" ]; then
67	chr_testdev='-device virtio-serial-device'
68	chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
69fi
70
71pci_testdev=
72if $qemu $M -device '?' | grep -q pci-testdev; then
73	pci_testdev="-device pci-testdev"
74fi
75
76A="-accel $ACCEL$ACCEL_PROPS"
77command="$qemu -nodefaults $M $A -cpu $qemu_cpu $chr_testdev $pci_testdev"
78command+=" -display none -serial stdio"
79command="$(migration_cmd) $(timeout_cmd) $command"
80
81if [ "$UEFI_SHELL_RUN" = "y" ]; then
82	ENVIRON_DEFAULT=n run_qemu_status $command "$@"
83elif [ "$EFI_USE_ACPI" = "y" ]; then
84	run_qemu_status $command -kernel "$@"
85else
86	run_qemu $command -kernel "$@"
87fi
88