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