xref: /kvm-unit-tests/powerpc/run (revision 3c7d322e87043aaad022e1999844c82d7b373aa9)
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
11
12if [ -c /dev/kvm ]; then
13	if [ "$HOST" = "ppc64" ] && [ "$ARCH" = "ppc64" ]; 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="${QEMU:-qemu-system-$ARCH_NAME}"
32qpath=$(which $qemu 2>/dev/null)
33
34if [ -z "$qpath" ]; then
35	echo $qemu not found.
36	exit 2
37fi
38
39if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then
40	echo "$qpath doesn't support pSeries ('-machine pseries'). Exiting."
41	exit 2
42fi
43
44M='-machine pseries'
45M+=",accel=$ACCEL"
46command="$qemu -nodefaults $M -bios $FIRMWARE"
47[ -f "$ENV" ] && command+=" -initrd $ENV"
48command+=" -display none -serial stdio -kernel"
49command="$(timeout_cmd) $command"
50echo $command "$@"
51
52# powerpc tests currently exit with rtas-poweroff, which exits with 0.
53# run_qemu treats that as a failure exit and returns 1, so we need
54# to fixup the fixup below by parsing the true exit code from the output.
55# The second fixup is also a FIXME, because once we add chr-testdev
56# support for powerpc, we won't need the second fixup.
57lines=$(run_qemu $command "$@")
58ret=$?
59echo "$lines"
60if [ $ret -eq 1 ]; then
61	testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
62	if [ "$testret" ]; then
63		if [ $testret -eq 1 ]; then
64			ret=0
65		else
66			ret=$testret
67		fi
68	fi
69fi
70exit $ret
71