[Lldb-commits] [PATCH] D128041: [lldb] [test] Make AVX/MPX register tests more robust and fix on BSD

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 17 02:48:31 PDT 2022


mgorny created this revision.
mgorny added reviewers: emaste, labath, DavidSpickett, krytarowski.
Herald added a subscriber: arichardson.
Herald added a project: All.
mgorny requested review of this revision.

Make the AVX/MPX register tests more robust by checking for the presence
of actual registers rather than register sets.  Account for the option
that the respective registers are defined but not available, as is
the case on FreeBSD and NetBSD.  This fixes test regression on these
platforms.

Sponsored by: The FreeBSD Foundation


https://reviews.llvm.org/D128041

Files:
  lldb/test/API/commands/register/register/register_command/TestRegisters.py


Index: lldb/test/API/commands/register/register/register_command/TestRegisters.py
===================================================================
--- lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -395,31 +395,25 @@
                     st0regname +
                     ' = 0'])
 
-            has_avx = False
-            has_mpx = False
-            # Returns an SBValueList.
+            # Check if AVX/MPX registers are defined at all.
             registerSets = currentFrame.GetRegisters()
-            for registerSet in registerSets:
-                set_name = registerSet.GetName().lower()
-                if 'advanced vector extensions' in set_name:
-                    has_avx = True
-                # Darwin reports AVX registers as part of "Floating Point Registers"
-                elif self.platformIsDarwin() and 'floating point registers' in set_name:
-                    has_avx = registerSet.GetChildMemberWithName('ymm0').IsValid()
-
-                # FreeBSD/NetBSD reports missing register sets differently
-                # at the moment and triggers false positive here.
-                # TODO: remove FreeBSD/NetBSD exception when we make unsupported
-                # register groups correctly disappear.
-                if ('memory protection extension' in registerSet.GetName().lower()
-                        and self.getPlatform() not in ["freebsd", "netbsd"]):
-                    has_mpx = True
+            registers = frozenset(reg.GetName() for registerSet in registerSets
+                                  for reg in registerSet)
+            has_avx_regs = "ymm0" in registers
+            has_mpx_regs = "bnd0" in registers
+            # Check if they are actually present.
+            self.runCmd("register read -a")
+            output = self.res.GetOutput()
+            has_avx = "ymm0 =" in output
+            has_mpx = "bnd0 =" in output
 
             if has_avx:
                 new_value = "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x0d 0x0e 0x0f}"
                 self.write_and_read(currentFrame, "ymm0", new_value)
                 self.write_and_read(currentFrame, "ymm7", new_value)
                 self.expect("expr $ymm0", substrs=['vector_type'])
+            elif has_avx_regs:
+                self.expect("register read ymm0", substrs=["error: unavailable"])
             else:
                 self.expect("register read ymm0", substrs=["Invalid register name 'ymm0'"],
                             error=True)
@@ -436,6 +430,8 @@
                 new_value = "{0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08}"
                 self.write_and_read(currentFrame, "bndstatus", new_value)
                 self.expect("expr $bndstatus", substrs = ['vector_type'])
+            elif has_mpx_regs:
+                self.expect("register read bnd0", substrs=["error: unavailable"])
             else:
                 self.expect("register read bnd0", substrs=["Invalid register name 'bnd0'"],
                             error=True)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128041.437832.patch
Type: text/x-patch
Size: 3221 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220617/75a5b481/attachment-0001.bin>


More information about the lldb-commits mailing list