Skip to contentSkip to conversation

tests/tcg/s390x: Enable the multiarch system tests

PATCH Superseded Ilya Leoshkevich 3 participants 5 messages Apr 22, 2023

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover tests/tcg/s390x: Enable the multiarch system tests

Hi,

I noticed that Alex added "undefine MULTIARCH_TESTS" to tests/tcg/s390x/Makefile.softmmu-target in the plugin patch, and thought that it may better to just enable them, which this series does.

Patch 1 fixes an endianness issue in the memory test.

Patch 2 enables the multiarch system test. The main difficulty is outputting characters via SCLP, which is sidestepped by reusing the pc-bios/s390-ccw implementation.

Best regards,
Ilya

Ilya Leoshkevich (2):
tests/tcg/multiarch: Make the system memory test work on big-endian tests/tcg/s390x: Enable the multiarch system tests

 tests/tcg/multiarch/system/memory.c     | 24 ++++++++++++++++
 tests/tcg/s390x/Makefile.softmmu-target | 37 +++++++++++++++++--------
 tests/tcg/s390x/console.c               | 12 ++++++++
 tests/tcg/s390x/head64.S                | 31 +++++++++++++++++++++
 4 files changed, 93 insertions(+), 11 deletions(-)
 create mode 100644 tests/tcg/s390x/console.c
 create mode 100644 tests/tcg/s390x/head64.S
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/2 tests/tcg/multiarch: Make the system memory test work on big-endian

Make sure values are stored in memory as little-endian regardless of the host endianness.

---
 tests/tcg/multiarch/system/memory.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
tests/tcg/multiarch/system/memory.c +24 -0
index 214f7d4f54b..8ef6666b440 100644
@@ -121,6 +121,9 @@ static void init_test_data_u16(int offset)
     for (i = 0; i < max; i++) {
         uint8_t low = count++, high = count++;
         word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0);
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        word = __builtin_bswap16(word);
+#endif
         *ptr++ = word;
         pdot(i);
     }
@@ -142,6 +145,9 @@ static void init_test_data_u32(int offset)
         uint8_t b4 = count++, b3 = count++;
         uint8_t b2 = count++, b1 = count++;
         word = BYTE_SHIFT(b1, 3) | BYTE_SHIFT(b2, 2) | BYTE_SHIFT(b3, 1) | b4;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        word = __builtin_bswap32(word);
+#endif
         *ptr++ = word;
         pdot(i);
     }
@@ -167,6 +173,9 @@ static void init_test_data_u64(int offset)
         word = BYTE_SHIFT(b1, 7) | BYTE_SHIFT(b2, 6) | BYTE_SHIFT(b3, 5) |
                BYTE_SHIFT(b4, 4) | BYTE_SHIFT(b5, 3) | BYTE_SHIFT(b6, 2) |
                BYTE_SHIFT(b7, 1) | b8;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        word = __builtin_bswap64(word);
+#endif
         *ptr++ = word;
         pdot(i);
     }
@@ -184,6 +193,9 @@ static bool read_test_data_u16(int offset)
     for (i = 0; i < max; i++) {
         uint8_t high, low;
         word = *ptr++;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        word = __builtin_bswap16(word);
+#endif
         high = (word >> 8) & 0xff;
         low = word & 0xff;
         if (high < low && high != 0) {
@@ -210,6 +222,9 @@ static bool read_test_data_u32(int offset)
         uint8_t b1, b2, b3, b4;
         int zeros = 0;
         word = *ptr++;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        word = __builtin_bswap32(word);
+#endif
 
         b1 = word >> 24 & 0xff;
         b2 = word >> 16 & 0xff;
@@ -251,6 +266,9 @@ static bool read_test_data_u64(int offset)
         uint8_t b1, b2, b3, b4, b5, b6, b7, b8;
         int zeros = 0;
         word = *ptr++;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        word = __builtin_bswap64(word);
+#endif
 
         b1 = ((uint64_t) (word >> 56)) & 0xff;
         b2 = ((uint64_t) (word >> 48)) & 0xff;
@@ -376,6 +394,9 @@ static bool read_test_data_s16(int offset, bool neg_first)
 
     for (i = 0; i < max; i++) {
         int32_t data = *ptr++;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        data = __builtin_bswap16(data);
+#endif
 
         if (neg_first && data < 0) {
             pdot(i);
@@ -401,6 +422,9 @@ static bool read_test_data_s32(int offset, bool neg_first)
 
     for (i = 0; i < max; i++) {
         int64_t data = *ptr++;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        data = __builtin_bswap32(data);
+#endif
 
         if (neg_first && data < 0) {
             pdot(i);
Signature · 1 line
2.39.2
#4 lore raw

PATCH 2/2 tests/tcg/s390x: Enable the multiarch system tests

In reply to Ilya Leoshkevich

Multiarch tests are written in C and need support for printing characters. Instead of implementing the runtime from scratch, just reuse the pc-bios/s390-ccw one.

Run tests with -nographic in order to enable SCLP (enable this for the existing tests as well, since it does not hurt).

Use the default linker script for the new tests.

---
 tests/tcg/s390x/Makefile.softmmu-target | 37 +++++++++++++++++--------
 tests/tcg/s390x/console.c               | 12 ++++++++
 tests/tcg/s390x/head64.S                | 31 +++++++++++++++++++++
 3 files changed, 69 insertions(+), 11 deletions(-)
 create mode 100644 tests/tcg/s390x/console.c
 create mode 100644 tests/tcg/s390x/head64.S
tests/tcg/s390x/Makefile.softmmu-target +26 -11
index 3e7f72abcdc..2c42526e9cd 100644
@@ -1,25 +1,40 @@
 S390X_SRC=$(SRC_PATH)/tests/tcg/s390x
 VPATH+=$(S390X_SRC)
-QEMU_OPTS=-action panic=exit-failure -kernel
+QEMU_OPTS=-action panic=exit-failure -nographic -kernel
 LINK_SCRIPT=$(S390X_SRC)/softmmu.ld
-LDFLAGS=-nostdlib -static -Wl,-T$(LINK_SCRIPT) -Wl,--build-id=none
+CFLAGS+=-ggdb -O0
+LDFLAGS=-nostdlib -static
 
 %.o: %.S
 	$(CC) -march=z13 -m64 -c $< -o $@
 
+%.o: %.c
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -march=z13 -m64 -c $< -o $@
+
 %: %.o $(LINK_SCRIPT)
 	$(CC) $< -o $@ $(LDFLAGS)
 
-TESTS += unaligned-lowcore
-TESTS += bal
-TESTS += sam
-TESTS += lpsw
-TESTS += lpswe-early
-TESTS += ssm-early
-TESTS += stosm-early
-TESTS += exrl-ssm-early
+ASM_TESTS =                                                                    \
+    bal                                                                        \
+    exrl-ssm-early                                                             \
+    sam                                                                        \
+    lpsw                                                                       \
+    lpswe-early                                                                \
+    ssm-early                                                                  \
+    stosm-early                                                                \
+    unaligned-lowcore
 
 include $(S390X_SRC)/pgm-specification.mak
 $(PGM_SPECIFICATION_TESTS): pgm-specification-softmmu.o
 $(PGM_SPECIFICATION_TESTS): LDFLAGS+=pgm-specification-softmmu.o
-TESTS += $(PGM_SPECIFICATION_TESTS)
+ASM_TESTS += $(PGM_SPECIFICATION_TESTS)
+
+$(ASM_TESTS): LDFLAGS += -Wl,-T$(LINK_SCRIPT) -Wl,--build-id=none
+TESTS += $(ASM_TESTS)
+
+S390X_MULTIARCH_RUNTIME_OBJS = head64.o console.o $(MINILIB_OBJS)
+$(MULTIARCH_TESTS): $(S390X_MULTIARCH_RUNTIME_OBJS)
+$(MULTIARCH_TESTS): LDFLAGS += $(S390X_MULTIARCH_RUNTIME_OBJS)
+$(MULTIARCH_TESTS): CFLAGS += $(MINILIB_INC)
+memory: CFLAGS += -DCHECK_UNALIGNED=0
+TESTS += $(MULTIARCH_TESTS)
tests/tcg/s390x/console.c new file +12 -0
new file mode 100644
index 00000000000..d43ce3f44b4
@@ -0,0 +1,12 @@
+/*
+ * Console code for multiarch tests.
+ * Reuses the pc-bios/s390-ccw implementation.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "../../../pc-bios/s390-ccw/sclp.c"
+
+void __sys_outc(char c)
+{
+    write(1, &c, sizeof(c));
+}
tests/tcg/s390x/head64.S new file +31 -0
new file mode 100644
index 00000000000..c6f36dfea4b
@@ -0,0 +1,31 @@
+/*
+ * Startup code for multiarch tests.
+ * Reuses the pc-bios/s390-ccw implementation.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#define main main_pre
+#include "../../../pc-bios/s390-ccw/start.S"
+#undef main
+
+main_pre:
+    aghi %r15,-160                     /* reserve stack for C code */
+    brasl %r14,sclp_setup
+    brasl %r14,main
+    larl %r1,success_psw               /* check main() return code */
+    ltgr %r2,%r2
+    je 0f
+    larl %r1,failure_psw
+0:
+    lpswe 0(%r1)
+
+    .align 8
+success_psw:
+    .quad 0x2000180000000,0xfff        /* see is_special_wait_psw() */
+failure_psw:
+    .quad 0x2000180000000,0            /* disabled wait */
+
+    .section .bss
+    .align 0x1000
+stack:
+    .skip 0x8000
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH 1/2] tests/tcg/multiarch: Make the system memory test work on big-endian

In reply to Ilya Leoshkevich
Quoted 13 lines · Ilya Leoshkevich

Make sure values are stored in memory as little-endian regardless of the host endianness.

---
 tests/tcg/multiarch/system/memory.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
tests/tcg/multiarch/system/memory.c +0 -0
index 214f7d4f54b..8ef6666b440 100644

tests/tcg/multiarch/system/memory.c static void init_test_data_u16(int offset) · line 126

Quoted 6 lines
tests/tcg/multiarch/system/memory.c +3 -0
@@ -121,6 +121,9 @@ static void init_test_data_u16(int offset)
     for (i = 0; i < max; i++) {
         uint8_t low = count++, high = count++;
         word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0);
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        word = __builtin_bswap16(word);
+#endif

These looks like a usecase for cpu_to_le16() and friends.

Quoted 14 lines
tests/tcg/multiarch/system/memory.c +3 -0
         *ptr++ = word;
         pdot(i);
     }
@@ -142,6 +145,9 @@ static void init_test_data_u32(int offset)
         uint8_t b4 = count++, b3 = count++;
         uint8_t b2 = count++, b1 = count++;
         word = BYTE_SHIFT(b1, 3) | BYTE_SHIFT(b2, 2) | BYTE_SHIFT(b3, 1) | b4;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        word = __builtin_bswap32(word);
+#endif
         *ptr++ = word;
         pdot(i);
     }
[..]
#3 lore raw

Re: [PATCH 1/2] tests/tcg/multiarch: Make the system memory test work on big-endian

Quoted 10 lines · Thomas Weißschuh
Quoted 8 lines · Ilya Leoshkevich

Make sure values are stored in memory as little-endian regardless of the host endianness.

---
 tests/tcg/multiarch/system/memory.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Quoted 13 lines

tests/tcg/multiarch/system/memory.c static void init_test_data_u16(int offset) · line 126

Quoted 11 lines
tests/tcg/multiarch/system/memory.c +3 -0
index 214f7d4f54b..8ef6666b440 100644
@@ -121,6 +121,9 @@ static void init_test_data_u16(int offset)
     for (i = 0; i < max; i++) {
         uint8_t low = count++, high = count++;
         word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0);
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        word = __builtin_bswap16(word);
+#endif

These looks like a usecase for cpu_to_le16() and friends.

I'm not sure this test code has direct access to those, but the general principle is right.

It is particularly odd that we carefully manually put together a word by shifting-and-ORing together the various bytes in it, and then separately do a byteswap.

thanks
-- PMM