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