qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Wainer dos Santos Moschetta" <wainersm@redhat.com>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"David Hildenbrand" <david@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	qemu-s390x@nongnu.org, "Beraldo Leal" <bleal@redhat.com>,
	qemu-arm@nongnu.org, devel@lists.libvirt.org,
	qemu-ppc@nongnu.org,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Marek Vasut" <marex@denx.de>, "Thomas Huth" <thuth@redhat.com>,
	"Chris Wulff" <crwulff@gmail.com>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Luis Machado" <luis.machado@arm.com>
Subject: [PATCH v2 14/14] tests/tcg: finesse the registers check for "hidden" regs
Date: Mon, 20 Nov 2023 15:08:33 +0000	[thread overview]
Message-ID: <20231120150833.2552739-15-alex.bennee@linaro.org> (raw)
In-Reply-To: <20231120150833.2552739-1-alex.bennee@linaro.org>

The reason the ppc64 and s390x test where failing was because gdb
hides them although they are still accessible via regnum. We can
re-arrange the test a little bit and include these two arches in our
test.

We still don't explicitly fail for registers that just disappear like
in the ARM case:

  xml-tdesc has 228 registers
  remote-registers has 219 registers
  of which 0 are hidden
  {'name': 'CNTP_CVAL', 'regnum': 96} wasn't seen in remote-registers
  {'name': 'CNTV_CVAL', 'regnum': 101} wasn't seen in remote-registers
  {'name': 'PAR', 'regnum': 113} wasn't seen in remote-registers
  {'name': 'CPUACTLR', 'regnum': 114} wasn't seen in remote-registers
  {'name': 'CPUECTLR', 'regnum': 127} wasn't seen in remote-registers
  {'name': 'CPUMERRSR', 'regnum': 140} wasn't seen in remote-registers
  {'name': 'TTBR1', 'regnum': 148} wasn't seen in remote-registers
  {'name': 'L2MERRSR', 'regnum': 161} wasn't seen in remote-registers
  {'name': 'TTBR0', 'regnum': 168} wasn't seen in remote-registers

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: qemu-s390x@nongnu.org
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Daniel Henrique Barboza <danielhb413@gmail.com>
Cc: qemu-ppc@nongnu.org
Cc: Luis Machado <luis.machado@arm.com>

---
v2
  - skip if check for total_regs != total_r_regs and always dump what
    is elided/missed
---
 tests/tcg/multiarch/gdbstub/registers.py | 87 +++++++++++++++++-------
 tests/tcg/ppc64/Makefile.target          |  7 --
 tests/tcg/s390x/Makefile.target          |  4 --
 3 files changed, 64 insertions(+), 34 deletions(-)

diff --git a/tests/tcg/multiarch/gdbstub/registers.py b/tests/tcg/multiarch/gdbstub/registers.py
index ff6076b09e..8ba14099b5 100644
--- a/tests/tcg/multiarch/gdbstub/registers.py
+++ b/tests/tcg/multiarch/gdbstub/registers.py
@@ -44,7 +44,6 @@ def fetch_xml_regmap():
 
     total_regs = 0
     reg_map = {}
-    frame = gdb.selected_frame()
 
     tree = ET.fromstring(xml)
     for f in tree.findall("feature"):
@@ -61,12 +60,8 @@ def fetch_xml_regmap():
         for r in regs:
             name = r.attrib["name"]
             regnum = int(r.attrib["regnum"])
-            try:
-                value = frame.read_register(name)
-            except ValueError:
-                report(False, f"failed to read reg: {name}")
 
-            entry = { "name": name, "initial": value, "regnum": regnum }
+            entry = { "name": name, "regnum": regnum }
 
             if name in reg_map:
                 report(False, f"duplicate register {entry} vs {reg_map[name]}")
@@ -80,6 +75,15 @@ def fetch_xml_regmap():
 
     return reg_map
 
+def get_register_by_regnum(reg_map, regnum):
+    """
+    Helper to find a register from the map via its XML regnum
+    """
+    for regname, entry in reg_map.items():
+        if entry['regnum'] == regnum:
+            return entry
+    return None
+
 def crosscheck_remote_xml(reg_map):
     """
     Cross-check the list of remote-registers with the XML info.
@@ -90,6 +94,7 @@ def crosscheck_remote_xml(reg_map):
 
     total_regs = len(reg_map.keys())
     total_r_regs = 0
+    total_r_elided_regs = 0
 
     for r in r_regs:
         fields = r.split()
@@ -100,6 +105,15 @@ def crosscheck_remote_xml(reg_map):
             r_name = fields[0]
             r_regnum = int(fields[6])
 
+            # Some registers are "hidden" so don't have a name
+            # although they still should have a register number
+            if r_name == "''":
+                total_r_elided_regs += 1
+                x_reg = get_register_by_regnum(reg_map, r_regnum)
+                if x_reg is not None:
+                    x_reg["hidden"] = True
+                continue
+
             # check in the XML
             try:
                 x_reg = reg_map[r_name]
@@ -117,14 +131,39 @@ def crosscheck_remote_xml(reg_map):
     # Just print a mismatch in totals as gdb will filter out 64 bit
     # registers on a 32 bit machine. Also print what is missing to
     # help with debug.
-    if total_regs != total_r_regs:
-        print(f"xml-tdesc has ({total_regs}) registers")
-        print(f"remote-registers has ({total_r_regs}) registers")
+    print(f"xml-tdesc has {total_regs} registers")
+    print(f"remote-registers has {total_r_regs} registers")
+    print(f"of which {total_r_elided_regs} are hidden")
+
+    for x_key in reg_map.keys():
+        x_reg = reg_map[x_key]
+        if "hidden" in x_reg:
+            print(f"{x_reg} elided by gdb")
+        elif "seen" not in x_reg:
+            print(f"{x_reg} wasn't seen in remote-registers")
+
+def initial_register_read(reg_map):
+    """
+    Do an initial read of all registers that we know gdb cares about
+    (so ignore the elided ones).
+    """
+    frame = gdb.selected_frame()
+
+    for e in reg_map.values():
+        name = e["name"]
+        regnum = e["regnum"]
+
+        try:
+            if "hidden" in e:
+                value = frame.read_register(regnum)
+                e["initial"] = value
+            elif "seen" in e:
+                value = frame.read_register(name)
+                e["initial"] = value
+
+        except ValueError:
+                report(False, f"failed to read reg: {name}")
 
-        for x_key in reg_map.keys():
-            x_reg = reg_map[x_key]
-            if "seen" not in x_reg:
-                print(f"{x_reg} wasn't seen in remote-registers")
 
 def complete_and_diff(reg_map):
     """
@@ -144,18 +183,19 @@ def complete_and_diff(reg_map):
     changed = 0
 
     for e in reg_map.values():
-        name = e["name"]
-        old_val = e["initial"]
+        if "initial" in e and "hidden" not in e:
+            name = e["name"]
+            old_val = e["initial"]
 
-        try:
-            new_val = frame.read_register(name)
-        except:
-            report(False, f"failed to read {name} at end of run")
-            continue
+            try:
+                new_val = frame.read_register(name)
+            except ValueError:
+                report(False, f"failed to read {name} at end of run")
+                continue
 
-        if new_val != old_val:
-            print(f"{name} changes from {old_val} to {new_val}")
-            changed += 1
+            if new_val != old_val:
+                print(f"{name} changes from {old_val} to {new_val}")
+                changed += 1
 
     # as long as something changed we can be confident its working
     report(changed > 0, f"{changed} registers were changed")
@@ -168,6 +208,7 @@ def run_test():
 
     if reg_map is not None:
         crosscheck_remote_xml(reg_map)
+        initial_register_read(reg_map)
         complete_and_diff(reg_map)
 
 
diff --git a/tests/tcg/ppc64/Makefile.target b/tests/tcg/ppc64/Makefile.target
index 1d08076756..5721c159f2 100644
--- a/tests/tcg/ppc64/Makefile.target
+++ b/tests/tcg/ppc64/Makefile.target
@@ -38,11 +38,4 @@ PPC64_TESTS += signal_save_restore_xer
 PPC64_TESTS += xxspltw
 PPC64_TESTS += test-aes
 
-ifneq ($(GDB),)
-# Skip for now until vsx registers sorted out
-run-gdbstub-registers:
-	$(call skip-test, $<, "BROKEN reading VSX registers")
-endif
-
-
 TESTS += $(PPC64_TESTS)
diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 46544fecd4..0e670f3f8b 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -103,10 +103,6 @@ run-gdbstub-svc: hello-s390x-asm
 		--bin $< --test $(S390X_SRC)/gdbstub/test-svc.py, \
 	single-stepping svc)
 
-# Skip for now until vx registers sorted out
-run-gdbstub-registers:
-	$(call skip-test, $<, "BROKEN reading VX registers")
-
 EXTRA_RUNS += run-gdbstub-signals-s390x run-gdbstub-svc
 endif
 
-- 
2.39.2



      parent reply	other threads:[~2023-11-20 15:11 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-20 15:08 [PATCH v2 00/14] random fixes for 8.2 pre-PR (tests, plugins, docs, semihosting) Alex Bennée
2023-11-20 15:08 ` [PATCH v2 01/14] tests/docker: replace fedora-i386 with debian-i686 Alex Bennée
2023-11-20 15:08 ` [PATCH v2 02/14] .gitlab-ci.d/cirrus: Upgrade macOS to 13 (Ventura) Alex Bennée
2023-11-20 15:08 ` [PATCH v2 03/14] tests/docker: merge debian-native with debian-amd64 Alex Bennée
2023-11-20 15:08 ` [PATCH v2 04/14] plugins: fix win plugin tests on cross compile Alex Bennée
2023-11-20 15:08 ` [PATCH v2 05/14] target/nios2: Deprecate the Nios II architecture Alex Bennée
2023-11-20 15:08 ` [PATCH v2 06/14] tests/tcg: fixup Aarch64 semiconsole test Alex Bennée
2023-11-20 15:08 ` [PATCH v2 07/14] docs/emulation: expand warning about semihosting Alex Bennée
2023-11-20 16:15   ` Richard Henderson
2023-11-20 15:08 ` [PATCH v2 08/14] docs/system: clarify limits of using gdbstub in system emulation Alex Bennée
2023-11-20 16:15   ` Richard Henderson
2023-11-20 17:20   ` Philippe Mathieu-Daudé
2023-11-20 17:26   ` Peter Maydell
2023-11-20 15:08 ` [PATCH v2 09/14] hw/core: skip loading debug on all failures Alex Bennée
2023-11-20 15:08 ` [PATCH v2 10/14] testing: move arm system tests into their own folder Alex Bennée
2023-11-20 15:08 ` [PATCH v2 11/14] tests/tcg: enable arm softmmu tests Alex Bennée
2023-11-20 16:32   ` Richard Henderson
2023-11-20 17:25   ` Peter Maydell
2023-11-20 15:08 ` [PATCH v2 12/14] tests/tcg: enable semiconsole test for Arm Alex Bennée
2023-11-20 15:08 ` [PATCH v2 13/14] configure: don't try a "native" cross for linux-user Alex Bennée
2023-11-20 15:08 ` Alex Bennée [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=20231120150833.2552739-15-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=bleal@redhat.com \
    --cc=clg@kaod.org \
    --cc=crwulff@gmail.com \
    --cc=danielhb413@gmail.com \
    --cc=david@redhat.com \
    --cc=devel@lists.libvirt.org \
    --cc=erdnaxe@crans.org \
    --cc=iii@linux.ibm.com \
    --cc=luis.machado@arm.com \
    --cc=ma.mandourr@gmail.com \
    --cc=marex@denx.de \
    --cc=npiggin@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    --cc=wainersm@redhat.com \
    /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).