This patch adds a test case to test SME register exposure to
a remote gdb debugging session. This test simply sets and
reads SME registers.

Signed-off-by: Vacha Bhavsar <vacha.bhav...@oss.qualcomm.com>
---
Changes since v6:
- added functionality to skip ZA quadword and doubleword
tile slice tests when the detected version of gdb does not
support SME tile slices
- added functionality to skip ZA quadword tile slice test
when the detected version of gdb does not support casting
gdb.Value to a 128bit python integer
- cleaned up testcase and made it more compact with additional
comments
---
 configure                             |  11 +++
 tests/tcg/aarch64/Makefile.target     |  51 +++++++++++
 tests/tcg/aarch64/gdbstub/test-sme.py | 125 ++++++++++++++++++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 tests/tcg/aarch64/gdbstub/test-sme.py

diff --git a/configure b/configure
index 274a778764..8de18e755f 100755
--- a/configure
+++ b/configure
@@ -1839,6 +1839,17 @@ for target in $target_list; do
           echo "GDB=$gdb_bin" >> $config_target_mak
       fi
 
+      if test "${gdb_arches#*$arch}" != "$gdb_arches" && version_ge 
$gdb_version 14.1; then
+          echo "GDB_HAS_SME_TILES=y" >> $config_target_mak
+          if version_ge $gdb_version 16.1; then
+            echo "GDB_HAS_128BIT_INT_CAST_SUPPORT=y" >> $config_target_mak
+          else
+            echo "GDB_HAS_128BIT_INT_CAST_SUPPORT=n" >> $config_target_mak
+          fi
+       else
+          echo "GDB_HAS_SME_TILES=n" >> $config_target_mak
+      fi
+
       if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge 
$gdb_version 15.1; then
           echo "GDB_HAS_MTE=y" >> $config_target_mak
       fi
diff --git a/tests/tcg/aarch64/Makefile.target 
b/tests/tcg/aarch64/Makefile.target
index 16ddcf4f88..954bc3139a 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -134,6 +134,57 @@ run-gdbstub-sve-ioctls: sve-ioctls
 
 EXTRA_RUNS += run-gdbstub-sysregs run-gdbstub-sve-ioctls
 
+ifneq ($(CROSS_AS_HAS_ARMV9_SME),)
+# SME gdbstub tests
+
+run-gdbstub-sysregs-sme: sysregs
+       $(call run-test, $@, $(GDB_SCRIPT) \
+               --gdb $(GDB) \
+               --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
+               --bin $< --test $(AARCH64_SRC)/gdbstub/test-sme.py \
+               -- test_sme --gdb_basic_za_test, \
+       basic gdbstub SME support)
+
+ifeq ($(GDB_HAS_SME_TILES),y)
+run-gdbstub-sysregs-sme-doubleword-tile-slice: sysregs
+       $(call run-test, $@, $(GDB_SCRIPT) \
+               --gdb $(GDB) \
+               --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
+               --bin $< --test $(AARCH64_SRC)/gdbstub/test-sme.py \
+               -- test_sme --gdb_doubleword_tile_slice_test, \
+       gdbstub SME ZA doubleword tile slice support)
+
+ifeq ($(GDB_HAS_128BIT_INT_CAST_SUPPORT),y)
+run-gdbstub-sysregs-sme-quadword-tile-slice: sysregs
+       $(call run-test, $@, $(GDB_SCRIPT) \
+               --gdb $(GDB) \
+               --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
+               --bin $< --test $(AARCH64_SRC)/gdbstub/test-sme.py \
+               -- test_sme --gdb_quadword_tile_slice_test, \
+       gdbstub SME ZA quadword tile slice support)     
+
+else
+run-gdbstub-sysregs-sme-quadword-tile-slice: sysregs
+       $(call skip-test,"gdbstub SME ZA quadword tile slice support", \
+       "selected gdb ($(GDB)) does not support casting gdb.Value into 128bit 
python integer")
+
+endif
+else
+run-gdbstub-sysregs-sme-doubleword-tile-slice: sysregs
+       $(call skip-test,"gdbstub SME ZA doubleword tile slice support", \
+       "selected gdb ($(GDB)) does not support SME ZA tile slices")
+
+run-gdbstub-sysregs-sme-quadword-tile-slice: sysregs
+       $(call skip-test,"gdbstub SME ZA quadword tile slice support", \
+       "selected gdb ($(GDB)) does not support SME ZA tile slices")
+
+endif
+
+EXTRA_RUNS += run-gdbstub-sysregs-sme 
run-gdbstub-sysregs-sme-doubleword-tile-slice \
+                         run-gdbstub-sysregs-sme-quadword-tile-slice
+                         
+endif
+
 ifeq ($(GDB_HAS_MTE),y)
 run-gdbstub-mte: mte-8
        $(call run-test, $@, $(GDB_SCRIPT) \
diff --git a/tests/tcg/aarch64/gdbstub/test-sme.py 
b/tests/tcg/aarch64/gdbstub/test-sme.py
new file mode 100644
index 0000000000..bad80f9925
--- /dev/null
+++ b/tests/tcg/aarch64/gdbstub/test-sme.py
@@ -0,0 +1,125 @@
+#
+# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from __future__ import print_function
+#
+# Test the SME registers are visible and changeable via gdbstub
+#
+# This is launched via tests/guest-debug/run-test.py
+#
+
+import argparse
+import gdb
+from test_gdbstub import main, report
+
+MAGIC = 0x01020304
+BASIC_ZA_TEST = 0
+DOUBLEWORD_TILE_SLICE_TEST = 0
+QUADWORD_TILE_SLICE_TEST = 0
+
+def run_test():
+    
+    # Run the requested test(s) for SME ZA gdbstub support
+
+    if BASIC_ZA_TEST:
+        run_basic_sme_za_gdbstub_support_test()
+    if DOUBLEWORD_TILE_SLICE_TEST or QUADWORD_TILE_SLICE_TEST:
+        run_basic_sme_za_tile_slice_gdbstub_support_test()
+
+def run_basic_sme_za_gdbstub_support_test():
+
+    # This test will check for gdbstub support for correctly reading
+    # and writing to the SME ZA register at the byte level.
+    
+    frame = gdb.selected_frame()
+    rname = "za"
+    za = frame.read_register(rname)
+    report(True, "Reading %s" % rname)
+
+    # Writing to the ZA register, byte by byte.
+    for i in range(0, 16):
+        for j in range(0, 16):
+            cmd = "set $za[%d][%d] = 0x01" % (i, j)
+            gdb.execute(cmd)
+            report(True, "%s" % cmd)
+
+    # Reading from the ZA register, byte by byte.
+    for i in range(0, 16):
+        for j in range(0, 16):
+            reg = "$za[%d][%d]" % (i, j)
+            v = gdb.parse_and_eval(reg)
+            report(str(v.type) == "uint8_t", "size of %s" % (reg))
+            report(int(v) == 0x1, "%s is 0x%x" % (reg, 0x1))
+
+def run_basic_sme_za_tile_slice_gdbstub_support_test():
+
+    # Test if SME ZA tile slices, both horizontal and vertical,
+    # can be correctly read and written to. The sizes to test
+    # depend on which tests are requested (QUADWORD_TILE_SLICE_TEST
+    # and/or DOUBLEWORD_TILE_SLICE_TEST).
+
+    sizes = {}
+    if QUADWORD_TILE_SLICE_TEST:
+        sizes["q"] = "uint128_t"
+    if DOUBLEWORD_TILE_SLICE_TEST:
+        sizes["d"] = "uint64_t"
+    
+    # Accessing requested sizes of elements of ZA
+    for size in sizes:
+
+        # Accessing various ZA tiles
+        for i in range(0, 4):
+
+            # Accessing various horizontal slices for each ZA tile
+            for j in range(0, 4):
+                # Writing to various elements in each tile slice
+                for k in range(0, 4):
+                    cmd = "set $za%dh%c%d[%d] = 0x%x" % (i, size, j, k, MAGIC)
+                    gdb.execute(cmd)
+                    report(True, "%s" % cmd)
+
+                # Reading from the written elements in each tile slice
+                for k in range(0, 4):
+                    reg = "$za%dh%c%d[%d]" % (i, size, j, k)
+                    v = gdb.parse_and_eval(reg)
+                    report(str(v.type) == sizes[size], "size of %s" % (reg))
+                    report(int(v) == MAGIC, "%s is 0x%x" % (reg, MAGIC))
+            
+            # Accessing various vertical slices for each ZA tile
+            for j in range(0, 4):
+                # Writing to various elements in each tile slice
+                for k in range(0, 4):
+                    cmd = "set $za%dv%c%d[%d] = 0x%x" % (i, size, j, k, MAGIC)
+                    gdb.execute(cmd)
+                    report(True, "%s" % cmd)
+
+                # Reading from the written elements in each tile slice
+                for k in range(0, 4):
+                    reg = "$za%dv%c%d[%d]" % (i, size, j, k)
+                    v = gdb.parse_and_eval(reg)
+                    report(str(v.type) == sizes[size], "size of %s" % (reg))
+                    report(int(v) == MAGIC, "%s is 0x%x" % (reg, MAGIC))
+
+
+parser = argparse.ArgumentParser(description="A gdbstub test for SME support")
+parser.add_argument("--gdb_basic_za_test",
+                           help="Enable test for basic SME ZA support",
+                    action="store_true")
+parser.add_argument("--gdb_doubleword_tile_slice_test",
+                           help="Enable test for ZA doubleword tile slice 
support",
+                    action="store_true")
+parser.add_argument("--gdb_quadword_tile_slice_test",
+                    help="Enable test for ZA quadword tile slice support",
+                    action="store_true")
+args = parser.parse_args()
+
+if args.gdb_basic_za_test:
+    BASIC_ZA_TEST = 1
+if args.gdb_doubleword_tile_slice_test:
+       DOUBLEWORD_TILE_SLICE_TEST = 1
+if args.gdb_quadword_tile_slice_test:
+       QUADWORD_TILE_SLICE_TEST = 1
+
+main(run_test, expected_arch="aarch64")
-- 
2.34.1


Reply via email to