From: Nicholas Piggin <[email protected]>

This adds a simple panic test for pseries that works with
TCG (unlike the s390x panic tests), making it easier to test
this part of the harness code.

Signed-off-by: Nicholas Piggin <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Signed-off-by: Chinmay Rath <[email protected]>
---
 lib/powerpc/asm/rtas.h |  1 +
 lib/powerpc/rtas.c     | 16 ++++++++++++++++
 powerpc/run            |  2 +-
 powerpc/selftest.c     | 17 ++++++++++++++++-
 powerpc/unittests.cfg  |  5 +++++
 5 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/lib/powerpc/asm/rtas.h b/lib/powerpc/asm/rtas.h
index 989b21bd..fdb3c544 100644
--- a/lib/powerpc/asm/rtas.h
+++ b/lib/powerpc/asm/rtas.h
@@ -26,6 +26,7 @@ extern int rtas_call(int token, int nargs, int nret, int 
*outputs, ...);
 extern int rtas_call_unlocked(struct rtas_args *args, int token, int nargs, 
int nret, int *outputs, ...);
 
 extern void rtas_power_off(void);
+extern void rtas_os_panic(void);
 extern void rtas_stop_self(void);
 #endif /* __ASSEMBLER__ */
 
diff --git a/lib/powerpc/rtas.c b/lib/powerpc/rtas.c
index 9c1e0aff..98eee24f 100644
--- a/lib/powerpc/rtas.c
+++ b/lib/powerpc/rtas.c
@@ -182,3 +182,19 @@ void rtas_power_off(void)
        ret = rtas_call_unlocked(&args, token, 2, 1, NULL, -1, -1);
        printf("RTAS power-off returned %d\n", ret);
 }
+
+void rtas_os_panic(void)
+{
+       struct rtas_args args;
+       uint32_t token;
+       int ret;
+
+       ret = rtas_token("ibm,os-term", &token);
+       if (ret) {
+               puts("RTAS ibm,os-term not available\n");
+               return;
+       }
+
+       ret = rtas_call_unlocked(&args, token, 1, 1, NULL, "rtas_os_panic");
+       printf("RTAS ibm,os-term returned %d\n", ret);
+}
diff --git a/powerpc/run b/powerpc/run
index 06657764..718f08cb 100755
--- a/powerpc/run
+++ b/powerpc/run
@@ -57,7 +57,7 @@ fi
 
 command="$qemu -nodefaults $A $M $B $D"
 command+=" -display none -serial stdio -kernel"
-command="$(migration_cmd) $(timeout_cmd) $command"
+command="$(panic_cmd) $(migration_cmd) $(timeout_cmd) $command"
 
 # powerpc tests currently exit with rtas-poweroff, which exits with 0.
 # run_test treats that as a failure exit and returns 1, so we need
diff --git a/powerpc/selftest.c b/powerpc/selftest.c
index 8d1a2c76..f6f24d6a 100644
--- a/powerpc/selftest.c
+++ b/powerpc/selftest.c
@@ -7,6 +7,7 @@
  */
 #include <libcflat.h>
 #include <util.h>
+#include <asm/rtas.h>
 #include <asm/setup.h>
 #include <asm/smp.h>
 
@@ -47,6 +48,17 @@ static void check_setup(int argc, char **argv)
                report_abort("missing input");
 }
 
+static void do_panic(void)
+{
+       if (machine_is_pseries()) {
+               rtas_os_panic();
+       } else {
+               /* Cause a checkstop with MSR[ME] disabled */
+               *((char *)0x10000000000) = 0;
+       }
+       report_fail("survived panic");
+}
+
 int main(int argc, char **argv)
 {
        report_prefix_push("selftest");
@@ -60,7 +72,10 @@ int main(int argc, char **argv)
 
                check_setup(argc-2, &argv[2]);
 
+       } else if (strcmp(argv[1], "panic") == 0) {
+               do_panic();
+       } else {
+               report_abort("unknown test %s", argv[1]);
        }
-
        return report_summary();
 }
diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg
index 168af206..d1395464 100644
--- a/powerpc/unittests.cfg
+++ b/powerpc/unittests.cfg
@@ -19,6 +19,11 @@ test_args = 'setup smp=2 mem=1024'
 qemu_params = -m 1g
 groups = selftest gitlab-ci
 
+[selftest-panic]
+file = selftest.elf
+extra_params = -append 'panic'
+groups = selftest panic gitlab-ci
+
 [selftest-migration]
 file = selftest-migration.elf
 machine = pseries
-- 
2.53.0


Reply via email to