[Lldb-commits] [lldb] [lldb][test] Make Linux cpuinfo check more robust (PR #160675)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 26 01:28:47 PDT 2025


https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/160675

>From af9d7abbc7883f6f2a39ae0a339b57c7b28dcb73 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Thu, 25 Sep 2025 09:37:33 +0000
Subject: [PATCH 1/3] [lldb][test] Make Linux cpuinfo check more robust

We were looking for any mention of the feature name in cpuinfo,
which could have hit anything including features with common
prefixes like sme, sme2, smefa64.

Luckily this was not a problem but I'm changing this to find the
features line and split the features into a list. Then we are
only looking for exact matches.

Here's the information for one core as an example:
```
processor	: 7
BogoMIPS	: 200.00
Features	: fp asimd evtstrm crc32 atomics fphp asimdhp cpuid <...>
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd0f
CPU revision	: 0
```
(and to avoid any doubt, this is from a CPU simulated in Arm's FVP, it's not real)

Note that the layout of the label, colon, values is sometimes aligned but
not always. So I trim whitespace a few times to normalise that.

This repeats once for each core so we only need to find one features line.
---
 lldb/packages/Python/lldbsuite/test/cpu_feature.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/cpu_feature.py b/lldb/packages/Python/lldbsuite/test/cpu_feature.py
index 3f43cbba130c0..9cdf46d688dd1 100644
--- a/lldb/packages/Python/lldbsuite/test/cpu_feature.py
+++ b/lldb/packages/Python/lldbsuite/test/cpu_feature.py
@@ -39,9 +39,16 @@ def _is_supported_linux(self, cmd_runner):
         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)
+        # Assume that every processor presents the same features.
+        # Look for the first "Features: ...." line.
+        for line in output.splitlines():
+            line = line.strip()
+            if line.startswith("Features"):
+                # Feature names are space separated.
+                features = line.split(":")[1].strip().split()
+                return None, (self.cpu_info_flag in features)
+
+        return f'No "Features:" line found in /proc/cpuinfo', False
 
     def _is_supported_darwin(self, cmd_runner):
         if not self.sysctl_key:

>From 455695253d7d58bac515397df0f2603332fecd1f Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 26 Sep 2025 08:27:40 +0000
Subject: [PATCH 2/3] use re.search

---
 lldb/packages/Python/lldbsuite/test/cpu_feature.py | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/cpu_feature.py b/lldb/packages/Python/lldbsuite/test/cpu_feature.py
index 9cdf46d688dd1..eface73ca8ac2 100644
--- a/lldb/packages/Python/lldbsuite/test/cpu_feature.py
+++ b/lldb/packages/Python/lldbsuite/test/cpu_feature.py
@@ -40,13 +40,10 @@ def _is_supported_linux(self, cmd_runner):
             return output, False
 
         # Assume that every processor presents the same features.
-        # Look for the first "Features: ...." line.
-        for line in output.splitlines():
-            line = line.strip()
-            if line.startswith("Features"):
-                # Feature names are space separated.
-                features = line.split(":")[1].strip().split()
-                return None, (self.cpu_info_flag in features)
+        # Look for the first "Features: ...." line. Features are space separated.
+        if m := re.search(r"Features\s*: (.*)\n", output):
+            features = m.group(1).split()
+            return None, (self.cpu_info_flag in features)
 
         return f'No "Features:" line found in /proc/cpuinfo', False
 

>From cbc37b59e547ef1ae5ce896f05e2ce62ff0eb7b3 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 26 Sep 2025 08:28:28 +0000
Subject: [PATCH 3/3] not needed

---
 lldb/packages/Python/lldbsuite/test/cpu_feature.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/packages/Python/lldbsuite/test/cpu_feature.py b/lldb/packages/Python/lldbsuite/test/cpu_feature.py
index eface73ca8ac2..b46a5acc596f0 100644
--- a/lldb/packages/Python/lldbsuite/test/cpu_feature.py
+++ b/lldb/packages/Python/lldbsuite/test/cpu_feature.py
@@ -45,7 +45,7 @@ def _is_supported_linux(self, cmd_runner):
             features = m.group(1).split()
             return None, (self.cpu_info_flag in features)
 
-        return f'No "Features:" line found in /proc/cpuinfo', False
+        return 'No "Features:" line found in /proc/cpuinfo', False
 
     def _is_supported_darwin(self, cmd_runner):
         if not self.sysctl_key:



More information about the lldb-commits mailing list