All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
Subject: [PATCH 2/2] tests/qtest: Execute Xtensa external register instructions
Date: Fri, 20 Nov 2026 00:02:05 +0100	[thread overview]
Message-ID: <20261119230205.4744-3-philmd@oss.qualcomm.com> (raw)
In-Reply-To: <20261119230205.4744-1-philmd@oss.qualcomm.com>

Run a minimal dc233c ELF that executes RER and WER on an unmapped
external register and then writes a RAM marker. Require the marker
while checking that QEMU stays alive.

The embedded guest covers the missing-operand translation crash
without requiring a cross assembler at test runtime.

AI-used-for: Regression tests
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 tests/qtest/xtensa-extreg-test.c | 81 ++++++++++++++++++++++++++++++++
 tests/qtest/meson.build          |  2 +
 2 files changed, 83 insertions(+)
 create mode 100644 tests/qtest/xtensa-extreg-test.c

diff --git a/tests/qtest/xtensa-extreg-test.c b/tests/qtest/xtensa-extreg-test.c
new file mode 100644
index 000000000000..10fde7461384
--- /dev/null
+++ b/tests/qtest/xtensa-extreg-test.c
@@ -0,0 +1,81 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * QTest for the RER/WER (external register) instructions of the dc233c core.
+ *
+ * The core's ISA tables used to describe RER and WER without operands, so
+ * translating them read uninitialised operands and crashed QEMU.  The guest
+ * executes RER then WER on an unmapped external register address, then
+ * writes a marker to RAM, which the test polls.
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+
+#define MARKER_ADDR 0x100
+#define MARKER_VAL  0x123
+
+/*
+ * Guest ELF, assembled with xtensa-dc233c-elf-gcc (whose assembler has the
+ * same operand-less RER/WER, hence the raw bytes) at the reset vector
+ * 0xfe000000, then reduced to one PT_LOAD segment:
+ *
+ *   _start:
+ *     movi.n a2, 0x40
+ *     .byte 0x30, 0x62, 0x40      # rer a3, a2
+ *     .byte 0x30, 0x72, 0x40      # wer a3, a2
+ *     movi   a4, 0x100
+ *     movi   a5, 0x123
+ *     s32i.n a5, a4, 0
+ *   1: j 1b
+ */
+static const uint8_t xtensa_guest[] = {
+    0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x5e, 0x00, 0x01, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0xfe, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x14, 0x00, 0x00, 0x00,
+    0x14, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
+    0x4c, 0x02, 0x30, 0x62, 0x40, 0x30, 0x72, 0x40, 0x42, 0xa1, 0x00, 0x52,
+    0xa1, 0x23, 0x59, 0x04, 0x06, 0xff, 0xff, 0x00,
+};
+
+static void test_extreg(void)
+{
+    g_autofree char *elf = NULL;
+    QTestState *qts;
+    int fd;
+
+    fd = g_file_open_tmp("qtest-xtensa-extreg-XXXXXX", &elf, NULL);
+    g_assert(fd != -1);
+    g_assert_cmpint(write(fd, xtensa_guest, sizeof(xtensa_guest)), ==,
+                    sizeof(xtensa_guest));
+    close(fd);
+
+    qts = qtest_initf("-M sim -cpu dc233c -accel tcg -no-shutdown "
+                      "-kernel %s", elf);
+    unlink(elf);
+
+    /* The harness enforces a timeout; stop if QEMU died */
+    while (qtest_readl(qts, MARKER_ADDR) != MARKER_VAL
+           && qtest_probe_child(qts)) {
+        g_usleep(10000);
+    }
+    g_assert_cmpint(qtest_readl(qts, MARKER_ADDR), ==, MARKER_VAL);
+
+    qtest_quit(qts);
+}
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+
+    if (!qtest_has_accel("tcg")) {
+        g_test_skip("TCG not available");
+        return g_test_run();
+    }
+    qtest_add_func("xtensa/extreg", test_extreg);
+
+    return g_test_run();
+}
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 6e2938d913ef..c0de1df2530f 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -328,6 +328,8 @@ qtests_riscv64 = ['riscv-csr-test'] + \
    ['k230-ddr-test', 'k230-wdt-test', 'k230-gsdma-test', 'k230-decomp-gzip-test'] : []) + \
    ['milkv-duo-test']
 
+qtests_xtensa = ['xtensa-extreg-test']
+
 qtests_hexagon = ['boot-serial-test', 'hexagon-config-test', 'l2vic-test',
                   'qcom-dsp-test',
                   'qct-qtimer-test']
-- 
2.55.0



      parent reply	other threads:[~2026-11-19 23:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 23:02 [PATCH 0/2] target/xtensa: Describe RER and WER register operands Philippe Mathieu-Daudé
2026-11-19 23:02 ` [PATCH 1/2] " Philippe Mathieu-Daudé
2026-11-19 23:02 ` Philippe Mathieu-Daudé [this message]

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=20261119230205.4744-3-philmd@oss.qualcomm.com \
    --to=philmd@oss.qualcomm.com \
    --cc=farosas@suse.de \
    --cc=jcmvbkbc@gmail.com \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.