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