[kvm-unit-tests,v5,18/18] powerpc/ppc64: make a fake debug-exit
diff mbox

Message ID 1455734459-31902-19-git-send-email-drjones@redhat.com
State Superseded
Headers show

Commit Message

Andrew Jones Feb. 17, 2016, 6:40 p.m. UTC
We should use a QEMU debug-exit device like chr-testdev, but for
now we just fake things by outputting the exit code (which we
parse later) and quitting with RTAS (which always exits with zero).

(When we've got a real debug-exit working, then this patch can
 be reverted.)

Signed-off-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Tested-by: Laurent Vivier <lvivier@redhat.com>
---
 lib/powerpc/io.c | 4 ++++
 powerpc/run      | 7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

Comments

David Gibson Feb. 19, 2016, 4:12 a.m. UTC | #1
On Wed, Feb 17, 2016 at 07:40:59PM +0100, Andrew Jones wrote:
> We should use a QEMU debug-exit device like chr-testdev, but for
> now we just fake things by outputting the exit code (which we
> parse later) and quitting with RTAS (which always exits with zero).
> 
> (When we've got a real debug-exit working, then this patch can
>  be reverted.)
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Tested-by: Laurent Vivier <lvivier@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  lib/powerpc/io.c | 4 ++++
>  powerpc/run      | 7 +++++--
>  2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/powerpc/io.c b/lib/powerpc/io.c
> index c4c61ea8ac1cf..6a94bcc4f76d4 100644
> --- a/lib/powerpc/io.c
> +++ b/lib/powerpc/io.c
> @@ -29,5 +29,9 @@ void puts(const char *s)
>  
>  void exit(int code)
>  {
> +// FIXME: change this print-exit/rtas-poweroff to chr_testdev_exit(),
> +//        maybe by plugging chr-testdev into a spapr-vty.
> +	printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
> +	rtas_power_off();
>  	halt(code);
>  }
> diff --git a/powerpc/run b/powerpc/run
> index c5108100fc5e0..45492a1cb8afc 100755
> --- a/powerpc/run
> +++ b/powerpc/run
> @@ -46,7 +46,10 @@ command="$qemu $M -bios $FIRMWARE"
>  command+=" -display none -serial stdio -kernel"
>  echo $command "$@"
>  
> -$command "$@"
> -ret=$?
> +#FIXME: rtas-poweroff always exits with zero, so we have to parse
> +#       the true exit code from the output.
> +lines=$($command "$@")
> +echo "$lines"
> +ret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
>  echo Return value from qemu: $ret
>  exit $ret

Patch
diff mbox

diff --git a/lib/powerpc/io.c b/lib/powerpc/io.c
index c4c61ea8ac1cf..6a94bcc4f76d4 100644
--- a/lib/powerpc/io.c
+++ b/lib/powerpc/io.c
@@ -29,5 +29,9 @@  void puts(const char *s)
 
 void exit(int code)
 {
+// FIXME: change this print-exit/rtas-poweroff to chr_testdev_exit(),
+//        maybe by plugging chr-testdev into a spapr-vty.
+	printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
+	rtas_power_off();
 	halt(code);
 }
diff --git a/powerpc/run b/powerpc/run
index c5108100fc5e0..45492a1cb8afc 100755
--- a/powerpc/run
+++ b/powerpc/run
@@ -46,7 +46,10 @@  command="$qemu $M -bios $FIRMWARE"
 command+=" -display none -serial stdio -kernel"
 echo $command "$@"
 
-$command "$@"
-ret=$?
+#FIXME: rtas-poweroff always exits with zero, so we have to parse
+#       the true exit code from the output.
+lines=$($command "$@")
+echo "$lines"
+ret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
 echo Return value from qemu: $ret
 exit $ret