xref: /kvm-unit-tests/arm/run (revision f1071c6d5fc454957e2501934fea6d9e592da8a5)
1#!/bin/bash
2
3if [ -z "$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
11processor="$PROCESSOR"
12
13if [ -c /dev/kvm ]; then
14	if [ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]; then
15		kvm_available=yes
16	elif [ "$HOST" = "aarch64" ]; then
17		kvm_available=yes
18	fi
19fi
20
21if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
22	echo "KVM is needed, but not available on this host"
23	exit 2
24fi
25
26if [ -z "$ACCEL" ]; then
27	if [ "$kvm_available" = "yes" ]; then
28		ACCEL="kvm"
29	else
30		ACCEL="tcg"
31	fi
32fi
33
34qemu="${QEMU:-qemu-system-$ARCH_NAME}"
35qpath=$(which $qemu 2>/dev/null)
36
37if [ -z "$qpath" ]; then
38	echo $qemu not found.
39	exit 2
40fi
41
42if ! $qemu -machine '?' 2>&1 | grep 'ARM Virtual Machine' > /dev/null; then
43	echo "$qpath doesn't support mach-virt ('-machine virt'). Exiting."
44	exit 2
45fi
46
47M='-machine virt'
48
49if [ "$ACCEL" = "kvm" ]; then
50	if $qemu $M,\? 2>&1 | grep gic-version > /dev/null; then
51		M+=',gic-version=host'
52	fi
53	if [ "$HOST" = "aarch64" ]; then
54		processor="host"
55		if [ "$ARCH" = "arm" ]; then
56			processor+=",aarch64=off"
57		fi
58	fi
59fi
60
61if ! $qemu $M -device '?' 2>&1 | grep virtconsole > /dev/null; then
62	echo "$qpath doesn't support virtio-console for chr-testdev. Exiting."
63	exit 2
64fi
65
66if $qemu $M -chardev testdev,id=id -initrd . 2>&1 \
67		| grep backend > /dev/null; then
68	echo "$qpath doesn't support chr-testdev. Exiting."
69	exit 2
70fi
71
72chr_testdev='-device virtio-serial-device'
73chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
74
75pci_testdev=
76if $qemu $M -device '?' 2>&1 | grep pci-testdev > /dev/null; then
77	pci_testdev="-device pci-testdev"
78fi
79
80M+=",accel=$ACCEL"
81command="$qemu -nodefaults $M -cpu $processor $chr_testdev $pci_testdev"
82command+=" -display none -serial stdio -kernel"
83command="$(timeout_cmd) $command"
84echo $command "$@"
85
86run_qemu $command "$@"
87