xref: /kvm-unit-tests/powerpc/run (revision b2a2aa5d6a5feed114ab730721f02b3b9e09b814)
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 "skip $TESTNAME (kvm only)"
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 $M -bios $FIRMWARE"
47command+=" -display none -serial stdio -kernel"
48echo $command "$@"
49
50# powerpc tests currently exit with rtas-poweroff, which exits with 0.
51# run_qemu treats that as a failure exit and returns 1, so we need
52# to fixup the fixup below by parsing the true exit code from the output.
53# The second fixup is also a FIXME, because once we add chr-testdev
54# support for powerpc, we won't need the second fixup.
55lines=$(run_qemu $command "$@")
56ret=$?
57echo "$lines"
58if [ $ret -eq 1 ]; then
59	testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
60	if [ "$testret" ]; then
61		if [ $testret -eq 1 ]; then
62			ret=0
63		else
64			ret=$testret
65		fi
66	fi
67fi
68exit $ret
69