================
@@ -0,0 +1,58 @@
+"""
+Platform-agnostic helper to query for CPU features.
+"""
+
+import re
+
+
+class CPUFeature:
+    def __init__(self, linux_cpu_info_flag: str, darwin_sysctl_key: str):
+        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):
+        cmd = "cat /proc/cpuinfo"
+        err, retcode, output = cmd_runner(cmd)
+        if err.Fail() or retcode != 0:
+            err_msg = f"cat /proc/cpuinfo failed: {output}"
+            return err_msg, False
+
+        return None, (self.cpu_info_flag in output)
+
+    def _is_supported_darwin(self, cmd_runner):
+        cmd = f"sysctl -n {self.sysctl_key}"
+        err, retcode, output = cmd_runner(cmd)
+        if err.Fail() or retcode != 0:
+            return output, False
+
+        return None, (output.strip() == "1")
+
+
+# List of CPU features
+FPMR = CPUFeature("fpmr", "???")
----------------
yln wrote:

I meant `???` as a placeholder here.  Most of the Linux `cpuinfo` flags should 
have a `sysctl` analog and I wanted to make it obvious for there person who 
wrote the first, e.g., FPMR Linux-Darwin compatible test that they still have 
to fill in the `fpmr` sysctl key analog.

I will change this to use `None` as you suggested.  It should still be simple 
enough to figure out why tests aren't running on Darwin.

https://github.com/llvm/llvm-project/pull/153914
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to