* [PATCH v3 0/2] tests/tcg/s390x: Enable the multiarch system tests
@ 2023-04-25 22:48 Ilya Leoshkevich
2023-04-25 22:48 ` [PATCH v3 1/2] tests/tcg/multiarch: Make the system memory test work on big-endian Ilya Leoshkevich
2023-04-25 22:48 ` [PATCH v3 2/2] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
0 siblings, 2 replies; 5+ messages in thread
From: Ilya Leoshkevich @ 2023-04-25 22:48 UTC (permalink / raw)
To: Alex Bennée, Richard Henderson, David Hildenbrand
Cc: qemu-devel, qemu-s390x, Thomas Weißschuh, Peter Maydell,
Ilya Leoshkevich
v2: https://lists.gnu.org/archive/html/qemu-devel/2023-04/msg04154.html
v2 -> v3: The idea with sharing the QEMU headers with the tests seems
to be controversial. Just rework the test to work without
the explicit byte swaps.
v1: https://lists.gnu.org/archive/html/qemu-devel/2023-04/msg03746.html
v1 -> v2: Use cpu_to_le16() and friends (Thomas).
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 | 64 ++++++++++++++++---------
tests/tcg/s390x/Makefile.softmmu-target | 40 +++++++++++-----
tests/tcg/s390x/console.c | 12 +++++
tests/tcg/s390x/head64.S | 31 ++++++++++++
4 files changed, 113 insertions(+), 34 deletions(-)
create mode 100644 tests/tcg/s390x/console.c
create mode 100644 tests/tcg/s390x/head64.S
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/2] tests/tcg/multiarch: Make the system memory test work on big-endian
2023-04-25 22:48 [PATCH v3 0/2] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
@ 2023-04-25 22:48 ` Ilya Leoshkevich
2023-05-11 11:20 ` Alex Bennée
2023-04-25 22:48 ` [PATCH v3 2/2] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
1 sibling, 1 reply; 5+ messages in thread
From: Ilya Leoshkevich @ 2023-04-25 22:48 UTC (permalink / raw)
To: Alex Bennée, Richard Henderson, David Hildenbrand
Cc: qemu-devel, qemu-s390x, Thomas Weißschuh, Peter Maydell,
Ilya Leoshkevich
Store the bytes in descending order on big-endian.
Invert the logic in the multi-byte signed tests on big-endian.
Make the checks in the multi-byte signed tests stricter.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
tests/tcg/multiarch/system/memory.c | 64 +++++++++++++++++++----------
1 file changed, 42 insertions(+), 22 deletions(-)
diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/memory.c
index 214f7d4f54b..eaae6929cb3 100644
--- a/tests/tcg/multiarch/system/memory.c
+++ b/tests/tcg/multiarch/system/memory.c
@@ -40,18 +40,21 @@ static void pdot(int count)
}
/*
- * Helper macros for shift/extract so we can keep our endian handling
- * in one place.
+ * Helper macros for endian handling.
*/
-#define BYTE_SHIFT(b, pos) ((uint64_t)b << (pos * 8))
-#define BYTE_EXTRACT(b, pos) ((b >> (pos * 8)) & 0xff)
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define BYTE_SHIFT(b, pos) (b << (pos * 8))
+#define BYTE_NEXT(b) ((b)++)
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define BYTE_SHIFT(b, pos) (b << ((sizeof(b) - 1 - (pos)) * 8))
+#define BYTE_NEXT(b) ((b)--)
+#else
+#error Unsupported __BYTE_ORDER__
+#endif
/*
- * Fill the data with ascending value bytes.
- *
- * Currently we only support Little Endian machines so write in
- * ascending address order. When we read higher address bytes should
- * either be zero or higher than the lower bytes.
+ * Fill the data with ascending (for little-endian) or descending (for
+ * big-endian) value bytes.
*/
static void init_test_data_u8(int unused_offset)
@@ -62,14 +65,14 @@ static void init_test_data_u8(int unused_offset)
ml_printf("Filling test area with u8:");
for (i = 0; i < TEST_SIZE; i++) {
- *ptr++ = count++;
+ *ptr++ = BYTE_NEXT(count);
pdot(i);
}
ml_printf("done\n");
}
/*
- * Full the data with alternating positive and negative bytes. This
+ * Fill the data with alternating positive and negative bytes. This
* should mean for reads larger than a byte all subsequent reads will
* stay either negative or positive. We never write 0.
*/
@@ -119,7 +122,7 @@ static void init_test_data_u16(int offset)
reset_start_data(offset);
for (i = 0; i < max; i++) {
- uint8_t low = count++, high = count++;
+ uint16_t low = BYTE_NEXT(count), high = BYTE_NEXT(count);
word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0);
*ptr++ = word;
pdot(i);
@@ -139,9 +142,10 @@ static void init_test_data_u32(int offset)
reset_start_data(offset);
for (i = 0; i < max; i++) {
- 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;
+ uint32_t b4 = BYTE_NEXT(count), b3 = BYTE_NEXT(count);
+ uint32_t b2 = BYTE_NEXT(count), b1 = BYTE_NEXT(count);
+ word = BYTE_SHIFT(b1, 3) | BYTE_SHIFT(b2, 2) | BYTE_SHIFT(b3, 1) |
+ BYTE_SHIFT(b4, 0);
*ptr++ = word;
pdot(i);
}
@@ -160,13 +164,13 @@ static void init_test_data_u64(int offset)
reset_start_data(offset);
for (i = 0; i < max; i++) {
- uint8_t b8 = count++, b7 = count++;
- uint8_t b6 = count++, b5 = count++;
- uint8_t b4 = count++, b3 = count++;
- uint8_t b2 = count++, b1 = count++;
+ uint64_t b8 = BYTE_NEXT(count), b7 = BYTE_NEXT(count);
+ uint64_t b6 = BYTE_NEXT(count), b5 = BYTE_NEXT(count);
+ uint64_t b4 = BYTE_NEXT(count), b3 = BYTE_NEXT(count);
+ uint64_t b2 = BYTE_NEXT(count), b1 = BYTE_NEXT(count);
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;
+ BYTE_SHIFT(b7, 1) | BYTE_SHIFT(b8, 0);
*ptr++ = word;
pdot(i);
}
@@ -374,12 +378,20 @@ static bool read_test_data_s16(int offset, bool neg_first)
ml_printf("Reading s16 from %#lx (offset %d, %s):", ptr,
offset, neg_first ? "neg" : "pos");
+ /*
+ * If the first byte is negative, then the last byte is positive.
+ * Therefore the logic below must be flipped for big-endian.
+ */
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ neg_first = !neg_first;
+#endif
+
for (i = 0; i < max; i++) {
int32_t data = *ptr++;
if (neg_first && data < 0) {
pdot(i);
- } else if (data > 0) {
+ } else if (!neg_first && data > 0) {
pdot(i);
} else {
ml_printf("Error %d %c 0\n", data, neg_first ? '<' : '>');
@@ -399,12 +411,20 @@ static bool read_test_data_s32(int offset, bool neg_first)
ml_printf("Reading s32 from %#lx (offset %d, %s):",
ptr, offset, neg_first ? "neg" : "pos");
+ /*
+ * If the first byte is negative, then the last byte is positive.
+ * Therefore the logic below must be flipped for big-endian.
+ */
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ neg_first = !neg_first;
+#endif
+
for (i = 0; i < max; i++) {
int64_t data = *ptr++;
if (neg_first && data < 0) {
pdot(i);
- } else if (data > 0) {
+ } else if (!neg_first && data > 0) {
pdot(i);
} else {
ml_printf("Error %d %c 0\n", data, neg_first ? '<' : '>');
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] tests/tcg/s390x: Enable the multiarch system tests
2023-04-25 22:48 [PATCH v3 0/2] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
2023-04-25 22:48 ` [PATCH v3 1/2] tests/tcg/multiarch: Make the system memory test work on big-endian Ilya Leoshkevich
@ 2023-04-25 22:48 ` Ilya Leoshkevich
2023-04-26 15:18 ` Richard Henderson
1 sibling, 1 reply; 5+ messages in thread
From: Ilya Leoshkevich @ 2023-04-25 22:48 UTC (permalink / raw)
To: Alex Bennée, Richard Henderson, David Hildenbrand
Cc: qemu-devel, qemu-s390x, Thomas Weißschuh, Peter Maydell,
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.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
tests/tcg/s390x/Makefile.softmmu-target | 40 +++++++++++++++++--------
tests/tcg/s390x/console.c | 12 ++++++++
tests/tcg/s390x/head64.S | 31 +++++++++++++++++++
3 files changed, 71 insertions(+), 12 deletions(-)
create mode 100644 tests/tcg/s390x/console.c
create mode 100644 tests/tcg/s390x/head64.S
diff --git a/tests/tcg/s390x/Makefile.softmmu-target b/tests/tcg/s390x/Makefile.softmmu-target
index 3e7f72abcdc..e22df5e1c58 100644
--- a/tests/tcg/s390x/Makefile.softmmu-target
+++ b/tests/tcg/s390x/Makefile.softmmu-target
@@ -1,25 +1,41 @@
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 $(LINK_SCRIPT)
+%.o: %.c
+ $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -march=z13 -m64 -c $< -o $@
+
+%: %.o
$(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
+$(ASM_TESTS): $(LINK_SCRIPT)
+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)
diff --git a/tests/tcg/s390x/console.c b/tests/tcg/s390x/console.c
new file mode 100644
index 00000000000..d43ce3f44b4
--- /dev/null
+++ b/tests/tcg/s390x/console.c
@@ -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));
+}
diff --git a/tests/tcg/s390x/head64.S b/tests/tcg/s390x/head64.S
new file mode 100644
index 00000000000..c6f36dfea4b
--- /dev/null
+++ b/tests/tcg/s390x/head64.S
@@ -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
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] tests/tcg/s390x: Enable the multiarch system tests
2023-04-25 22:48 ` [PATCH v3 2/2] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
@ 2023-04-26 15:18 ` Richard Henderson
0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2023-04-26 15:18 UTC (permalink / raw)
To: Ilya Leoshkevich, Alex Bennée, David Hildenbrand
Cc: qemu-devel, qemu-s390x, Thomas Weißschuh, Peter Maydell
On 4/25/23 23:48, Ilya Leoshkevich wrote:
> 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.
>
> Signed-off-by: Ilya Leoshkevich<iii@linux.ibm.com>
> ---
> tests/tcg/s390x/Makefile.softmmu-target | 40 +++++++++++++++++--------
> tests/tcg/s390x/console.c | 12 ++++++++
> tests/tcg/s390x/head64.S | 31 +++++++++++++++++++
> 3 files changed, 71 insertions(+), 12 deletions(-)
> create mode 100644 tests/tcg/s390x/console.c
> create mode 100644 tests/tcg/s390x/head64.S
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] tests/tcg/multiarch: Make the system memory test work on big-endian
2023-04-25 22:48 ` [PATCH v3 1/2] tests/tcg/multiarch: Make the system memory test work on big-endian Ilya Leoshkevich
@ 2023-05-11 11:20 ` Alex Bennée
0 siblings, 0 replies; 5+ messages in thread
From: Alex Bennée @ 2023-05-11 11:20 UTC (permalink / raw)
To: Ilya Leoshkevich
Cc: Richard Henderson, David Hildenbrand, qemu-devel, qemu-s390x,
Thomas Weißschuh, Peter Maydell
Ilya Leoshkevich <iii@linux.ibm.com> writes:
> Store the bytes in descending order on big-endian.
> Invert the logic in the multi-byte signed tests on big-endian.
> Make the checks in the multi-byte signed tests stricter.
>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
> tests/tcg/multiarch/system/memory.c | 64 +++++++++++++++++++----------
> 1 file changed, 42 insertions(+), 22 deletions(-)
>
> diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/memory.c
> index 214f7d4f54b..eaae6929cb3 100644
> --- a/tests/tcg/multiarch/system/memory.c
> +++ b/tests/tcg/multiarch/system/memory.c
> @@ -40,18 +40,21 @@ static void pdot(int count)
> }
>
> /*
> - * Helper macros for shift/extract so we can keep our endian handling
> - * in one place.
> + * Helper macros for endian handling.
> */
> -#define BYTE_SHIFT(b, pos) ((uint64_t)b << (pos * 8))
> -#define BYTE_EXTRACT(b, pos) ((b >> (pos * 8)) & 0xff)
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> +#define BYTE_SHIFT(b, pos) (b << (pos * 8))
> +#define BYTE_NEXT(b) ((b)++)
> +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> +#define BYTE_SHIFT(b, pos) (b << ((sizeof(b) - 1 - (pos)) * 8))
> +#define BYTE_NEXT(b) ((b)--)
I guess we don't want to start count high so we'll see:
255, 254, 253
instead of
0, 255, 254, 253?
> +#else
> +#error Unsupported __BYTE_ORDER__
> +#endif
>
> /*
> - * Fill the data with ascending value bytes.
> - *
> - * Currently we only support Little Endian machines so write in
> - * ascending address order. When we read higher address bytes should
> - * either be zero or higher than the lower bytes.
> + * Fill the data with ascending (for little-endian) or descending (for
> + * big-endian) value bytes.
> */
There is also a comment later on that needs fixing:
/*
* Read the test data and verify at various offsets
*
* For everything except bytes all our reads should be either positive
* or negative depending on what offset we are reading from. Currently
* we only handle LE systems.
*/
Otherwise:
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Would you be able to re-base and respin v3 so I can pull it cleanly?
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-05-11 11:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-25 22:48 [PATCH v3 0/2] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
2023-04-25 22:48 ` [PATCH v3 1/2] tests/tcg/multiarch: Make the system memory test work on big-endian Ilya Leoshkevich
2023-05-11 11:20 ` Alex Bennée
2023-04-25 22:48 ` [PATCH v3 2/2] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
2023-04-26 15:18 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).