[Lldb-commits] [lldb] [lldb][test] Unify and extend test infrastructure for checking CPU features (PR #153914)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 24 05:06:47 PDT 2025


================
@@ -0,0 +1,68 @@
+"""
+Platform-agnostic helper to query for CPU features.
+"""
+
+import re
+
+
+class CPUFeature:
+    def __init__(self, linux_cpu_info_flag: str = None, darwin_sysctl_key: str = None):
+        self.cpu_info_flag = linux_cpu_info_flag
+        self.sysctl_key = darwin_sysctl_key
+
+    def __str__(self):
+        return self.cpu_info_flag
+
+    def is_supported(self, triple, cmd_runner):
+        if re.match(".*-.*-linux", triple):
+            err_msg, res = self._is_supported_linux(cmd_runner)
+        elif re.match(".*-apple-.*", triple):
+            err_msg, res = self._is_supported_darwin(cmd_runner)
+        else:
+            err_msg, res = None, False
+
+        if err_msg:
+            print(f"CPU feature check failed: {err_msg}")
+
+        return res
+
+    def _is_supported_linux(self, cmd_runner):
+        if not self.cpu_info_flag:
+            return "Unspecified cpuinfo flag", False
+
+        cmd = "cat /proc/cpuinfo"
+        err, retcode, output = cmd_runner(cmd)
+        if err.Fail() or retcode != 0:
+            return output, False
+
+        # FIXME: simple substring match, e.g., test for 'sme' will be true if
+        # 'sme2' or 'smefa64' is present
+        return None, (self.cpu_info_flag in output)
+
+    def _is_supported_darwin(self, cmd_runner):
+        if not self.sysctl_key:
+            return "Unspecified sysctl key", False
----------------
DavidSpickett wrote:

Again find a way to include the class name here.

https://github.com/llvm/llvm-project/pull/153914


More information about the lldb-commits mailing list