xref: /kvm-unit-tests/arm/run (revision f0ca153cc2d1e6a670b3571a8ac24c2ef7042594)
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
34if [ "$HOST" = "aarch64" ] && [ "$ACCEL" = "kvm" ]; then
35	processor="host"
36	if [ "$ARCH" = "arm" ]; then
37		processor+=",aarch64=off"
38	fi
39fi
40
41qemu="${QEMU:-qemu-system-$ARCH_NAME}"
42qpath=$(which $qemu 2>/dev/null)
43
44if [ -z "$qpath" ]; then
45	echo $qemu not found.
46	exit 2
47fi
48
49if ! $qemu -machine '?' 2>&1 | grep 'ARM Virtual Machine' > /dev/null; then
50	echo "$qpath doesn't support mach-virt ('-machine virt'). Exiting."
51	exit 2
52fi
53
54M='-machine virt'
55
56if ! $qemu $M -device '?' 2>&1 | grep virtconsole > /dev/null; then
57	echo "$qpath doesn't support virtio-console for chr-testdev. Exiting."
58	exit 2
59fi
60
61if $qemu $M -chardev testdev,id=id -initrd . 2>&1 \
62		| grep backend > /dev/null; then
63	echo "$qpath doesn't support chr-testdev. Exiting."
64	exit 2
65fi
66
67chr_testdev='-device virtio-serial-device'
68chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
69
70pci_testdev=
71if $qemu $M -device '?' 2>&1 | grep pci-testdev > /dev/null; then
72	pci_testdev="-device pci-testdev"
73fi
74
75M+=",accel=$ACCEL"
76command="$qemu $M -cpu $processor $chr_testdev $pci_testdev"
77command+=" -display none -serial stdio -kernel"
78command="$(timeout_cmd) $command"
79echo $command "$@"
80
81run_qemu $command "$@"
82