arm-linux-user had no big-endian test coverage. Build the
non-libc hello world with -mbig-endian (BE8 by default) and
again with -mbe32 for legacy BE32 code/data ordering. The
volatile length forces a data load, checking the CPU data
byte order. Plumb both tests with the meson machinery.

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
 tests/tcg/arm/hello-arm-be.c   | 34 ++++++++++++++++++++++++++++++++++
 tests/tcg/arm/hello-arm-be32.c |  4 ++++
 tests/tcg/arm/hello-arm.ref    |  1 +
 tests/tcg/arm/meson.build      | 11 +++++++++++
 4 files changed, 50 insertions(+)
 create mode 100644 tests/tcg/arm/hello-arm-be.c
 create mode 100644 tests/tcg/arm/hello-arm-be32.c
 create mode 100644 tests/tcg/arm/hello-arm.ref

diff --git a/tests/tcg/arm/hello-arm-be.c b/tests/tcg/arm/hello-arm-be.c
new file mode 100644
index 000000000000..6c2aa6637b93
--- /dev/null
+++ b/tests/tcg/arm/hello-arm-be.c
@@ -0,0 +1,34 @@
+/*
+ * Non-libc syscall hello world to exercise big-endian ARM Linux-user.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#define __NR_exit 1
+#define __NR_write 4
+
+static const char hello[] = "Hello World\n";
+/* Volatile forces a data load to check the CPU data byte order. */
+static volatile int len = sizeof(hello) - 1;
+
+static inline int write(int fd, const char *buf, int len)
+{
+    register int r0 __asm__("r0") = fd;
+    register const char *r1 __asm__("r1") = buf;
+    register int r2 __asm__("r2") = len;
+    register int r7 __asm__("r7") = __NR_write;
+
+    __asm__ volatile("svc 0" : "+r"(r0) : "r"(r1), "r"(r2), "r"(r7)
+                     : "memory");
+
+    return r0;
+}
+
+void _start(void)
+{
+    register int r0 __asm__("r0") = write(1, hello, len) != len;
+    register int r7 __asm__("r7") = __NR_exit;
+
+    __asm__ volatile("svc 0" : : "r"(r0), "r"(r7) : "memory");
+    __builtin_unreachable();
+}
diff --git a/tests/tcg/arm/hello-arm-be32.c b/tests/tcg/arm/hello-arm-be32.c
new file mode 100644
index 000000000000..f639332a1aa2
--- /dev/null
+++ b/tests/tcg/arm/hello-arm-be32.c
@@ -0,0 +1,4 @@
+/* Rebuild the big-endian hello test with legacy BE32 code/data ordering. */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "hello-arm-be.c"
diff --git a/tests/tcg/arm/hello-arm.ref b/tests/tcg/arm/hello-arm.ref
new file mode 100644
index 000000000000..557db03de997
--- /dev/null
+++ b/tests/tcg/arm/hello-arm.ref
@@ -0,0 +1 @@
+Hello World
diff --git a/tests/tcg/arm/meson.build b/tests/tcg/arm/meson.build
index 6e498232f0d4..818447ae84d7 100644
--- a/tests/tcg/arm/meson.build
+++ b/tests/tcg/arm/meson.build
@@ -30,6 +30,17 @@ tests += {
   'hello-arm.c': {
     'cflags': ['-marm', '-nostdlib', '-ffreestanding', '-fno-stack-protector'],
   },
+  # The cross compiler emits BE8 for -mbig-endian; test legacy BE32 too.
+  'hello-arm-be.c': {
+    'cflags': ['-marm', '-mbig-endian', '-nostdlib', '-static', 
'-ffreestanding',
+               '-fno-stack-protector'],
+    'expected_output': 'hello-arm.ref',
+  },
+  'hello-arm-be32.c': {
+    'cflags': ['-marm', '-mbig-endian', '-mbe32', '-nostdlib', '-static',
+               '-ffreestanding', '-fno-stack-protector'],
+    'expected_output': 'hello-arm.ref',
+  },
   'fcvt.c': {
     'cflags': ['-lm', '-march=armv8.2-a+fp16', '-mfpu=neon-fp-armv8'],
     'expected_output': 'fcvt.ref',
-- 
2.55.0

Reply via email to