xref: /kvm-unit-tests/s390x/run (revision 4da0bc9a24a78cf61f046898b24c45577b645492)
1#!/usr/bin/env 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
11
12if [ -c /dev/kvm ]; then
13	if [ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]; then
14		kvm_available=yes
15	fi
16fi
17
18if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
19	echo "KVM is needed, but not available on this host"
20	exit 2
21fi
22
23if [ -z "$ACCEL" ]; then
24	if [ "$kvm_available" = "yes" ]; then
25		ACCEL="kvm"
26	else
27		ACCEL="tcg"
28	fi
29fi
30
31qemu=$(search_qemu_binary)
32
33M='-machine s390-ccw-virtio'
34M+=",accel=$ACCEL"
35command="$qemu -nodefaults -nographic $M"
36command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0"
37[ -f "$ENV" ] && command+=" -initrd $ENV"
38command+=" -kernel"
39command="$(timeout_cmd) $command"
40echo $command "$@"
41
42# We return the exit code via stdout, not via the QEMU return code
43lines=$(run_qemu $command "$@")
44ret=$?
45echo "$lines"
46if [ $ret -eq 1 ]; then
47	testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
48	if [ "$testret" ]; then
49		if [ $testret -eq 1 ]; then
50			ret=0
51		else
52			ret=$testret
53		fi
54	fi
55fi
56exit $ret
57