From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Richard Henderson <richard.henderson@linaro.org>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PULL 21/21] tests/tcg/s390x: Test EXECUTE of relative branches
Date: Mon, 15 May 2023 15:02:33 +0200 [thread overview]
Message-ID: <20230515130233.418183-22-thuth@redhat.com> (raw)
In-Reply-To: <20230515130233.418183-1-thuth@redhat.com>
From: Ilya Leoshkevich <iii@linux.ibm.com>
Add a small test to prevent regressions.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Acked-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230426235813.198183-3-iii@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/tcg/s390x/ex-branch.c | 158 ++++++++++++++++++++++++++++++++
tests/tcg/s390x/Makefile.target | 1 +
2 files changed, 159 insertions(+)
create mode 100644 tests/tcg/s390x/ex-branch.c
diff --git a/tests/tcg/s390x/ex-branch.c b/tests/tcg/s390x/ex-branch.c
new file mode 100644
index 0000000000..c606719152
--- /dev/null
+++ b/tests/tcg/s390x/ex-branch.c
@@ -0,0 +1,158 @@
+/* Check EXECUTE with relative branch instructions as targets. */
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct test {
+ const char *name;
+ void (*func)(long *link, long *magic);
+ long exp_link;
+};
+
+/* Branch instructions and their expected effects. */
+#define LINK_64(test) ((long)test ## _exp_link)
+#define LINK_NONE(test) -1L
+#define FOR_EACH_INSN(F) \
+ F(bras, "%[link]", LINK_64) \
+ F(brasl, "%[link]", LINK_64) \
+ F(brc, "0x8", LINK_NONE) \
+ F(brcl, "0x8", LINK_NONE) \
+ F(brct, "%%r0", LINK_NONE) \
+ F(brctg, "%%r0", LINK_NONE) \
+ F(brxh, "%%r2,%%r0", LINK_NONE) \
+ F(brxhg, "%%r2,%%r0", LINK_NONE) \
+ F(brxle, "%%r0,%%r1", LINK_NONE) \
+ F(brxlg, "%%r0,%%r1", LINK_NONE) \
+ F(crj, "%%r0,%%r0,8", LINK_NONE) \
+ F(cgrj, "%%r0,%%r0,8", LINK_NONE) \
+ F(cij, "%%r0,0,8", LINK_NONE) \
+ F(cgij, "%%r0,0,8", LINK_NONE) \
+ F(clrj, "%%r0,%%r0,8", LINK_NONE) \
+ F(clgrj, "%%r0,%%r0,8", LINK_NONE) \
+ F(clij, "%%r0,0,8", LINK_NONE) \
+ F(clgij, "%%r0,0,8", LINK_NONE)
+
+#define INIT_TEST \
+ "xgr %%r0,%%r0\n" /* %r0 = 0; %cc = 0 */ \
+ "lghi %%r1,1\n" /* %r1 = 1 */ \
+ "lghi %%r2,2\n" /* %r2 = 2 */
+
+#define CLOBBERS_TEST "cc", "0", "1", "2"
+
+#define DEFINE_TEST(insn, args, exp_link) \
+ extern char insn ## _exp_link[]; \
+ static void test_ ## insn(long *link, long *magic) \
+ { \
+ asm(INIT_TEST \
+ #insn " " args ",0f\n" \
+ ".globl " #insn "_exp_link\n" \
+ #insn "_exp_link:\n" \
+ ".org . + 90\n" \
+ "0: lgfi %[magic],0x12345678\n" \
+ : [link] "+r" (*link) \
+ , [magic] "+r" (*magic) \
+ : : CLOBBERS_TEST); \
+ } \
+ extern char ex_ ## insn ## _exp_link[]; \
+ static void test_ex_ ## insn(long *link, long *magic) \
+ { \
+ unsigned long target; \
+ \
+ asm(INIT_TEST \
+ "larl %[target],0f\n" \
+ "ex %%r0,0(%[target])\n" \
+ ".globl ex_" #insn "_exp_link\n" \
+ "ex_" #insn "_exp_link:\n" \
+ ".org . + 60\n" \
+ "0: " #insn " " args ",1f\n" \
+ ".org . + 120\n" \
+ "1: lgfi %[magic],0x12345678\n" \
+ : [target] "=r" (target) \
+ , [link] "+r" (*link) \
+ , [magic] "+r" (*magic) \
+ : : CLOBBERS_TEST); \
+ } \
+ extern char exrl_ ## insn ## _exp_link[]; \
+ static void test_exrl_ ## insn(long *link, long *magic) \
+ { \
+ asm(INIT_TEST \
+ "exrl %%r0,0f\n" \
+ ".globl exrl_" #insn "_exp_link\n" \
+ "exrl_" #insn "_exp_link:\n" \
+ ".org . + 60\n" \
+ "0: " #insn " " args ",1f\n" \
+ ".org . + 120\n" \
+ "1: lgfi %[magic],0x12345678\n" \
+ : [link] "+r" (*link) \
+ , [magic] "+r" (*magic) \
+ : : CLOBBERS_TEST); \
+ }
+
+/* Test functions. */
+FOR_EACH_INSN(DEFINE_TEST)
+
+/* Test definitions. */
+#define REGISTER_TEST(insn, args, _exp_link) \
+ { \
+ .name = #insn, \
+ .func = test_ ## insn, \
+ .exp_link = (_exp_link(insn)), \
+ }, \
+ { \
+ .name = "ex " #insn, \
+ .func = test_ex_ ## insn, \
+ .exp_link = (_exp_link(ex_ ## insn)), \
+ }, \
+ { \
+ .name = "exrl " #insn, \
+ .func = test_exrl_ ## insn, \
+ .exp_link = (_exp_link(exrl_ ## insn)), \
+ },
+
+static const struct test tests[] = {
+ FOR_EACH_INSN(REGISTER_TEST)
+};
+
+int main(int argc, char **argv)
+{
+ const struct test *test;
+ int ret = EXIT_SUCCESS;
+ bool verbose = false;
+ long link, magic;
+ size_t i;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-v") == 0) {
+ verbose = true;
+ }
+ }
+
+ for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
+ test = &tests[i];
+ if (verbose) {
+ fprintf(stderr, "[ RUN ] %s\n", test->name);
+ }
+ link = -1;
+ magic = -1;
+ test->func(&link, &magic);
+#define ASSERT_EQ(expected, actual) do { \
+ if (expected != actual) { \
+ fprintf(stderr, "%s: " #expected " (0x%lx) != " #actual " (0x%lx)\n", \
+ test->name, expected, actual); \
+ ret = EXIT_FAILURE; \
+ } \
+} while (0)
+ ASSERT_EQ(test->exp_link, link);
+ ASSERT_EQ(0x12345678L, magic);
+#undef ASSERT_EQ
+ }
+
+ if (verbose) {
+ fprintf(stderr, ret == EXIT_SUCCESS ? "[ PASSED ]\n" :
+ "[ FAILED ]\n");
+ }
+
+ return ret;
+}
diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 0031868b13..23dc8b6a63 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -34,6 +34,7 @@ TESTS+=cdsg
TESTS+=chrl
TESTS+=rxsbg
TESTS+=ex-relative-long
+TESTS+=ex-branch
cdsg: CFLAGS+=-pthread
cdsg: LDFLAGS+=-pthread
--
2.31.1
next prev parent reply other threads:[~2023-05-15 13:16 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-15 13:02 [PULL 00/21] Tests, docs, s390x and misc patches Thomas Huth
2023-05-15 13:02 ` [PULL 01/21] tests/avocado/virtio-gpu: Fix the URLs of the test_virtio_vga_virgl test Thomas Huth
2023-05-15 13:02 ` [PULL 02/21] sysemu/kvm: Remove unused headers Thomas Huth
2023-05-15 13:02 ` [PULL 03/21] net: stream: test reconnect option with an unix socket Thomas Huth
2023-05-15 13:02 ` [PULL 04/21] tests/qtest: replace qmp_discard_response with qtest_qmp_assert_success Thomas Huth
2023-05-15 13:02 ` [PULL 05/21] hw/pci-bridge: Fix release ordering by embedding PCIBridgeWindows within PCIBridge Thomas Huth
2023-05-15 13:02 ` [PULL 06/21] Add information how to fix common build error on Windows in symlink-install-tree Thomas Huth
2023-05-15 13:02 ` [PULL 07/21] tests: libvirt-ci: Update to commit 'c8971e90ac' to pull in mformat and xorriso Thomas Huth
2023-05-15 13:02 ` [PULL 08/21] tests/lcitool: Add mtools and xorriso and remove genisoimage as dependencies Thomas Huth
2023-05-15 13:02 ` [PULL 09/21] util/async-teardown: wire up query-command-line-options Thomas Huth
2023-05-15 13:02 ` [PULL 10/21] s390x/pv: Fix spurious warning with asynchronous teardown Thomas Huth
2023-05-15 13:02 ` [PULL 11/21] docs/devel: remind developers to run CI container pipeline when updating images Thomas Huth
2023-05-15 13:02 ` [PULL 12/21] docs/about/emulation: fix typo Thomas Huth
2023-05-15 13:02 ` [PULL 13/21] hw/core: Use a callback for target specific query-cpus-fast information Thomas Huth
2023-05-15 13:02 ` [PULL 14/21] cpu: Introduce a wrapper for being able to use TARGET_NAME in common code Thomas Huth
2023-05-15 13:02 ` [PULL 15/21] hw/core: Move machine-qmp-cmds.c into the target independent source set Thomas Huth
2023-05-15 13:02 ` [PULL 16/21] hw/net: Move xilinx_ethlite.c to the target-independent " Thomas Huth
2023-05-15 13:02 ` [PULL 17/21] s390x/tcg: Fix LDER instruction format Thomas Huth
2023-05-15 13:02 ` [PULL 18/21] tests/tcg/multiarch: Make the system memory test work on big-endian Thomas Huth
2023-05-15 13:02 ` [PULL 19/21] tests/tcg/s390x: Enable the multiarch system tests Thomas Huth
2023-05-15 13:02 ` [PULL 20/21] target/s390x: Fix EXECUTE of relative branches Thomas Huth
2023-05-15 13:02 ` Thomas Huth [this message]
2023-05-15 20:53 ` [PULL 00/21] Tests, docs, s390x and misc patches Richard Henderson
2023-05-16 7:11 ` Thomas Huth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230515130233.418183-22-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=iii@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).