Skip to content

Commit f8f4d8f

Browse files
committed
[lldb] Improve CPUInfo test predicate
Use a with block for reading the cpuinfo file. When loading the file fails (or we're not on Linux) return an empty string. Since all the callers are going to do "x in self.getCPUInfo()". Reviewed By: omjavaid Differential Revision: https://reviews.llvm.org/D99729
1 parent 638d70b commit f8f4d8f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ def getCPUInfo(self):
12741274

12751275
# TODO other platforms, please implement this function
12761276
if not re.match(".*-.*-linux", triple):
1277-
return False
1277+
return ""
12781278

12791279
# Need to do something different for non-Linux/Android targets
12801280
cpuinfo_path = self.getBuildArtifact("cpuinfo")
@@ -1284,11 +1284,10 @@ def getCPUInfo(self):
12841284
cpuinfo_path = "/proc/cpuinfo"
12851285

12861286
try:
1287-
f = open(cpuinfo_path, 'r')
1288-
cpuinfo = f.read()
1289-
f.close()
1287+
with open(cpuinfo_path, 'r') as f:
1288+
cpuinfo = f.read()
12901289
except:
1291-
return False
1290+
return ""
12921291

12931292
return cpuinfo
12941293

0 commit comments

Comments
 (0)