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