[Skiboot] [PATCH v2] test/sreset_world: Kind of like Hello World, but from the SRESET vector.

Stewart Smith stewart at linux.vnet.ibm.com
Tue Mar 7 15:19:24 AEDT 2017


A regression test for the mambo implementation of OPAL_SIGNAL_SYSTEM_RESET.

Signed-off-by: Stewart Smith <stewart at linux.vnet.ibm.com>
---
changes in v2:
 - work with a wider variety of toolchains
 - fix typos in expect scripts
---
 test/sreset_world/Makefile.check                 |  38 ++++++++
 test/sreset_world/run_mambo_p9_sreset.sh         |  71 ++++++++++++++
 test/sreset_world/run_mambo_sreset.sh            |  72 +++++++++++++++
 test/sreset_world/run_sreset_world.tcl           |   6 ++
 test/sreset_world/sreset_kernel/sreset_kernel.S  | 112 +++++++++++++++++++++++
 test/sreset_world/sreset_kernel/sreset_kernel.ld |  29 ++++++
 6 files changed, 328 insertions(+)
 create mode 100644 test/sreset_world/Makefile.check
 create mode 100755 test/sreset_world/run_mambo_p9_sreset.sh
 create mode 100755 test/sreset_world/run_mambo_sreset.sh
 create mode 100644 test/sreset_world/run_sreset_world.tcl
 create mode 100644 test/sreset_world/sreset_kernel/sreset_kernel.S
 create mode 100644 test/sreset_world/sreset_kernel/sreset_kernel.ld

diff --git a/test/sreset_world/Makefile.check b/test/sreset_world/Makefile.check
new file mode 100644
index 000000000000..0bd76a734234
--- /dev/null
+++ b/test/sreset_world/Makefile.check
@@ -0,0 +1,38 @@
+SRESET_WORLD_TEST := test/sreset_world/sreset_kernel/sreset_kernel
+
+.PHONY: sreset_world-tests
+sreset_world-tests: $(SRESET_WORLD_TEST:%=%-check-smt-mambo)
+sreset_world-tests: $(SRESET_WORLD_TEST:%=%-check-smt-p9-mambo)
+sreset_world-tests: $(SRESET_WORLD_TEST:%=%-check-mambo)
+sreset_world-tests: $(SRESET_WORLD_TEST:%=%-check-p9-mambo)
+
+boot-tests: sreset_world-tests
+check: sreset_world-tests
+
+$(SRESET_WORLD_TEST:%=%-check-smt-mambo): %-check-smt-mambo: % skiboot.lid
+	$(call Q , BOOT TEST , THREADS=2 ./test/sreset_world/run_mambo_sreset.sh , $@)
+
+$(SRESET_WORLD_TEST:%=%-check-smt-p9-mambo): %-check-smt-p9-mambo: % skiboot.lid
+	$(call Q , BOOT TEST , THREADS=2 ./test/sreset_world/run_mambo_p9_sreset.sh , $@)
+
+$(SRESET_WORLD_TEST:%=%-check-mambo): %-check-mambo: % skiboot.lid
+	$(call Q , BOOT TEST , ./test/sreset_world/run_mambo_sreset.sh, $@)
+
+$(SRESET_WORLD_TEST:%=%-check-p9-mambo): %-check-p9-mambo: % skiboot.lid
+	$(call Q , BOOT TEST , ./test/sreset_world/run_mambo_p9_sreset.sh, $@)
+
+test/sreset_world/sreset_kernel/sreset_kernel.o: test/sreset_world/sreset_kernel/sreset_kernel.S test/sreset_world/sreset_kernel/sreset_kernel.ld
+	$(call Q,CC, $(CC) -mbig-endian -m64 -c -MMD -o $@ $< ,$@)
+
+sreset_kernel_LDFLAGS=-m64 -Wl,--build-id=none -T test/sreset_world/sreset_kernel/sreset_kernel.ld -ffreestanding -nostdlib -Ttext=0x0 -mbig-endian
+
+-include $(wildcard test/sreset_world/sreset_kernel/*.d)
+
+test/sreset_world/sreset_kernel/sreset_kernel: test/sreset_world/sreset_kernel/sreset_kernel.o
+	$(call Q,LD, $(CC) $(sreset_kernel_LDFLAGS) -o $@ $^ , $@)
+
+clean: sreset_world-test-clean
+
+sreset_world-test-clean:
+	$(RM) -f test/sreset_world/sreset_kernel/sreset_kernel
+	$(RM) -f test/sreset_world/sreset_kernel/sreset_kernel.[od]
diff --git a/test/sreset_world/run_mambo_p9_sreset.sh b/test/sreset_world/run_mambo_p9_sreset.sh
new file mode 100755
index 000000000000..471e0ee69a1d
--- /dev/null
+++ b/test/sreset_world/run_mambo_p9_sreset.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+
+if [ -z "$P9MAMBO_PATH" ]; then
+    P9MAMBO_PATH=/opt/ibm/systemsim-p9/
+fi
+
+if [ -z "$P9MAMBO_BINARY" ]; then
+    P9MAMBO_BINARY="/run/p9/power9"
+fi
+
+if [ ! -x "$P9MAMBO_PATH/$P9MAMBO_BINARY" ]; then
+    echo "Could not find executable P9MAMBO_BINARY ($P9MAMBO_PATH/$MAMBO_BINARY). Skipping sreset_world test";
+    exit 0;
+fi
+
+if [ -n "$KERNEL" ]; then
+    echo 'Please rebuild skiboot without KERNEL set. Skipping sreset_world test';
+    exit 0;
+fi
+
+if [ ! `command -v expect` ]; then
+    echo 'Could not find expect binary. Skipping sreset_world test';
+    exit 0;
+fi
+
+export SKIBOOT_ZIMAGE=`pwd`/test/sreset_world/sreset_kernel/sreset_kernel
+
+# Currently getting some core dumps from mambo, so disable them!
+OLD_ULIMIT_C=`ulimit -c`
+ulimit -c 0
+
+t=$(mktemp) || exit 1
+
+trap "rm -f -- '$t'" EXIT
+
+( cd external/mambo; 
+cat <<EOF | expect
+set timeout 30
+spawn $P9MAMBO_PATH/$P9MAMBO_BINARY -n -f ../../test/sreset_world/run_sreset_world.tcl
+expect {
+timeout { send_user "\nTimeout waiting for hello world\n"; exit 1 }
+eof { send_user "\nUnexpected EOF\n"; exit 1 }
+"Hello World!"
+}
+expect {
+timeout { send_user "\nTimeout waiting for Hello SRESET\n"; exit 1 }
+eof { send_user "\nUnexpected EOF\n"; exit 1 }
+"Hello SRESET!"
+}
+expect {
+timeout { send_user "\nTimeout waiting for shutdown\n"; exit 1}
+eof { send_user "\nUnexpected EOF\n"; exit 1}
+"Execution stopped: Sim Support exit requested stop"
+}
+wait
+exit 0
+EOF
+) 2>&1 > $t
+cat $t
+
+r=$?
+if [ $r != 0 ]; then
+    cat $t
+    exit $r
+fi
+
+ulimit -c $OLD_ULIMIT_C
+
+rm -f -- "$t"
+trap - EXIT
+exit 0;
diff --git a/test/sreset_world/run_mambo_sreset.sh b/test/sreset_world/run_mambo_sreset.sh
new file mode 100755
index 000000000000..1733c65878eb
--- /dev/null
+++ b/test/sreset_world/run_mambo_sreset.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+
+if [ -z "$MAMBO_PATH" ]; then
+    MAMBO_PATH=/opt/ibm/systemsim-p8/
+fi
+
+if [ -z "$MAMBO_BINARY" ]; then
+    MAMBO_BINARY="/run/pegasus/power8"
+fi
+
+if [ ! -x "$MAMBO_PATH/$MAMBO_BINARY" ]; then
+    echo "Could not find executable MAMBO_BINARY ($MAMBO_PATH/$MAMBO_BINARY). Skipping sreset_world test";
+    exit 0;
+fi
+
+if [ -n "$KERNEL" ]; then
+    echo 'Please rebuild skiboot without KERNEL set. Skipping sreset_world test';
+    exit 0;
+fi
+
+if [ ! `command -v expect` ]; then
+    echo 'Could not find expect binary. Skipping sreset_world test';
+    exit 0;
+fi
+
+
+export SKIBOOT_ZIMAGE=`pwd`/test/sreset_world/sreset_kernel/sreset_kernel
+
+# Currently getting some core dumps from mambo, so disable them!
+OLD_ULIMIT_C=`ulimit -c`
+ulimit -c 0
+
+t=$(mktemp) || exit 1
+
+trap "rm -f -- '$t'" EXIT
+
+( cd external/mambo; 
+cat <<EOF | expect
+set timeout 30
+spawn $MAMBO_PATH/$MAMBO_BINARY -n -f ../../test/sreset_world/run_sreset_world.tcl
+expect {
+timeout { send_user "\nTimeout waiting for hello world\n"; exit 1 }
+eof { send_user "\nUnexpected EOF\n"; exit 1 }
+"Hello World!"
+}
+expect {
+timeout { send_user "\nTimeout waiting for Hello SRESET\n"; exit 1 }
+eof { send_user "\nUnexpected EOF\n"; exit 1 }
+"Hello SRESET!"
+}
+expect {
+timeout { send_user "\nTimeout waiting for shutdown\n"; exit 1}
+eof { send_user "\nUnexpected EOF\n"; exit 1}
+"Execution stopped: Sim Support exit requested stop"
+}
+wait
+exit 0
+EOF
+) 2>&1 > $t
+
+r=$?
+if [ $r != 0 ]; then
+    cat $t
+    exit $r
+fi
+
+ulimit -c $OLD_ULIMIT_C
+
+rm -f -- "$t"
+trap - EXIT
+exit 0;
diff --git a/test/sreset_world/run_sreset_world.tcl b/test/sreset_world/run_sreset_world.tcl
new file mode 100644
index 000000000000..d399a0dafaba
--- /dev/null
+++ b/test/sreset_world/run_sreset_world.tcl
@@ -0,0 +1,6 @@
+source ../../external/mambo/skiboot.tcl
+source ../../external/mambo/mambo_utils.tcl
+
+mysim go
+mysim memory fwrite 0x30000000 0x300000 skiboot-sreset_world.dump
+exit
diff --git a/test/sreset_world/sreset_kernel/sreset_kernel.S b/test/sreset_world/sreset_kernel/sreset_kernel.S
new file mode 100644
index 000000000000..33ad8110837d
--- /dev/null
+++ b/test/sreset_world/sreset_kernel/sreset_kernel.S
@@ -0,0 +1,112 @@
+/* Copyright 2013-2017 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+	Test the SRESET OPAL call in Mambo by
+	having a bit of fun printing 'Hello World' from the SRESET vector.
+*/
+
+	. = 0x0
+	.globl _start
+_start:
+/*
+ * Save some values passed in from skiboot into registers that are
+ * non-volatile over OPAL calls.
+ *   r8 is the OPAL base
+ *   r9 is the OPAL entry point point
+ */
+	mr	%r13, %r8
+	mr	%r14, %r9
+
+	bl	here
+here:	mflr	%r8 /* work out where we are running */
+	subi	%r8, %r8, here - _start
+	/* Stash OPAL base and entry point somewhere SRESET can find it */
+	li	%r6, 0xe0
+	std	%r13, 0(%r6)
+	std	%r14, 8(%r6)
+	std	%r8, 16(%r6)
+	addi	%r6, %r8, sreset_code_end - _start
+	addi	%r7, %r8, sreset_code - _start
+	li	%r10, 0x100
+c:
+	lwa	%r9, 0(%r7)
+	stw	%r9, 0(%r10)
+	addi	%r7,%r7,4
+	addi	%r10,%r10,4
+	cmpd	%r7,%r6
+	bne	c
+	sync
+	icbi	0,%r0
+	sync
+	isync
+	
+	li	%r0, 1 /* OPAL_CONSOLE_WRITE */
+	li	%r3, 0 /* terminal 0 */
+	addi	%r4, %r8, len - _start /* ptr to length of string */
+	addi	%r5, %r8, str - _start /* ptr to string start */
+	mr	%r2, %r13
+	mtctr	%r14
+	bctrl
+
+	li	%r0, 145 /* OPAL_SIGNAL_SYSTEM_RESET */
+	li	%r3, -1 /* All CPUs */
+	mr	%r2, %r13
+	mtctr	%r14
+	bctrl
+
+	/* We shouldn't get here but if we do, just wait here */
+	b	.
+
+sreset_code:
+	li	%r6, 0xe0
+	ld	%r13, 0(%r6)
+	ld	%r14, 8(%r6)
+	ld	%r8, 16(%r6) /* "here" */
+        li      %r0, 1 /* OPAL_CONSOLE_WRITE */
+        li      %r3, 0 /* terminal 0 */
+	li	%r4, len2 - _start
+	li	%r5, str2 - _start
+        add     %r4, %r8, %r4
+        add     %r5, %r8, %r5
+        mr      %r2, %r13
+        mtctr   %r14
+        bctrl
+	li	%r0, 5 /* OPAL_CEC_POWER_DOWN */
+	li	%r3, 0 /* normal shutdown */
+	mr	%r2, %r13
+	mtctr	%r14
+	bctrl
+
+	/* We shouldn't get here but if we do, just wait here */
+	b	.
+
+sreset_code_end:
+
+len:
+	.long 0x00
+	.long (strend - str)
+str:
+	.string "Hello World!\n"
+strend:
+
+len2:
+	.long 0x00
+	.long (str2end - str2)
+str2:
+	.string "Hello SRESET!\n"
+str2end:
+
diff --git a/test/sreset_world/sreset_kernel/sreset_kernel.ld b/test/sreset_world/sreset_kernel/sreset_kernel.ld
new file mode 100644
index 000000000000..d9bbc92857b2
--- /dev/null
+++ b/test/sreset_world/sreset_kernel/sreset_kernel.ld
@@ -0,0 +1,29 @@
+ENTRY(_start)
+SECTIONS
+{
+	.text :
+	{
+		_start = .;
+		*(.text)
+	}
+
+	. = ALIGN(4096);
+	.data :
+	{
+		*(.rodata*)
+		*(.data*)
+		*(.sdata*)
+		*(.got2)
+	}
+
+	. = ALIGN(4096);
+	.bss :
+	{
+		_edata  =  .;
+		__bss_start = .;
+		*(.sbss)
+		*(.bss)
+		*(COMMON)
+		_end = . ;
+	}
+}
-- 
2.9.3



More information about the Skiboot mailing list