Skip to content

Commit 8c122e5

Browse files
[lldb][test] Make Linux cpuinfo check more robust (#160675)
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.
1 parent 9de1bc0 commit 8c122e5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lldb/packages/Python/lldbsuite/test/cpu_feature.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ def _is_supported_linux(self, cmd_runner):
3939
if err.Fail() or retcode != 0:
4040
return output, False
4141

42-
# FIXME: simple substring match, e.g., test for 'sme' will be true if
43-
# 'sme2' or 'smefa64' is present
44-
return None, (self.cpu_info_flag in output)
42+
# Assume that every processor presents the same features.
43+
# Look for the first "Features: ...." line. Features are space separated.
44+
if m := re.search(r"Features\s*: (.*)\n", output):
45+
features = m.group(1).split()
46+
return None, (self.cpu_info_flag in features)
47+
48+
return 'No "Features:" line found in /proc/cpuinfo', False
4549

4650
def _is_supported_darwin(self, cmd_runner):
4751
if not self.sysctl_key:

0 commit comments

Comments
 (0)