xref: /kvm-unit-tests/arm/run (revision db9c4e1c8c2ab14af6a61d62604b7754b808833f)
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	qemu_cpu="$TARGET_CPU"
18
19	if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
20	   [ "$HOST" = "aarch64" ] && [ "$ARCH" = "arm" ] &&
21	   [ "$(basename $QEMU)" = "qemu-system-arm" ]; then
22		ACCEL="tcg"
23	fi
24
25	set_qemu_accelerator || exit $?
26	if [ "$ACCEL" = "kvm" ]; then
27		QEMU_ARCH=$HOST
28	fi
29
30	qemu=$(search_qemu_binary) ||
31		exit $?
32
33	if ! $qemu -machine '?' | grep -q 'ARM Virtual Machine'; then
34		echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting."
35		exit 2
36	fi
37
38	M='-machine virt'
39
40	if [ "$ACCEL" = "kvm" ]; then
41		if $qemu $M,\? | grep -q gic-version; then
42			M+=',gic-version=host'
43		fi
44	fi
45
46	if [ -z "$qemu_cpu" ]; then
47		if ( [ "$ACCEL" = "kvm" ] || [ "$ACCEL" = "hvf" ] ) &&
48		   ( [ "$HOST" = "aarch64" ] || [ "$HOST" = "arm" ] ); then
49			qemu_cpu="host"
50			if [ "$ARCH" = "arm" ] && [ "$HOST" = "aarch64" ]; then
51				qemu_cpu+=",aarch64=off"
52			fi
53		else
54			qemu_cpu="$DEFAULT_QEMU_CPU"
55		fi
56	fi
57
58	if [ "$ARCH" = "arm" ]; then
59		M+=",highmem=off"
60	fi
61
62	if ! $qemu $M -device '?' | grep -q virtconsole; then
63		echo "$qemu doesn't support virtio-console for chr-testdev. Exiting."
64		exit 2
65	fi
66
67	if ! $qemu $M -chardev '?' | grep -q testdev; then
68		echo "$qemu doesn't support chr-testdev. Exiting."
69		exit 2
70	fi
71
72	if [ "$UEFI_SHELL_RUN" != "y" ] && [ "$EFI_USE_ACPI" != "y" ]; then
73		chr_testdev='-device virtio-serial-device'
74		chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
75	fi
76
77	pci_testdev=
78	if $qemu $M -device '?' | grep -q pci-testdev; then
79		pci_testdev="-device pci-testdev"
80	fi
81
82	A="-accel $ACCEL$ACCEL_PROPS"
83	command="$qemu -nodefaults $M $A -cpu $qemu_cpu $chr_testdev $pci_testdev"
84	command+=" -display none -serial stdio"
85	command="$(migration_cmd) $(timeout_cmd) $command"
86
87	if [ "$UEFI_SHELL_RUN" = "y" ]; then
88		ENVIRON_DEFAULT=n run_test_status $command "$@"
89	elif [ "$EFI_USE_ACPI" = "y" ]; then
90		run_test_status $command -kernel "$@"
91	else
92		run_test $command -kernel "$@"
93	fi
94}
95
96function arch_run_kvmtool()
97{
98	local command
99
100	kvmtool=$(search_kvmtool_binary) ||
101		exit $?
102
103	if [ "$ACCEL" ] && [ "$ACCEL" != "kvm" ]; then
104		echo "kvmtool does not support $ACCEL" >&2
105		exit 2
106	fi
107
108	if ! kvm_available; then
109		echo "kvmtool requires KVM but not available on the host" >&2
110		exit 2
111	fi
112
113	command="$(timeout_cmd) $kvmtool run"
114	if [ "$HOST" = "aarch64" ] && [ "$ARCH" = "arm" ]; then
115		run_test_status $command --kernel "$@" --aarch32
116	else
117		run_test_status $command --kernel "$@"
118	fi
119}
120
121case $(vmm_get_target) in
122qemu)
123	arch_run_qemu "$@"
124	;;
125kvmtool)
126	arch_run_kvmtool "$@"
127	;;
128esac
129