[Lldb-commits] [PATCH] D99729: [lldb] Improve CPUInfo test predicate

David Spickett via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 1 07:31:50 PDT 2021


DavidSpickett created this revision.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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()".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99729

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


Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1274,7 +1274,7 @@
 
         # TODO other platforms, please implement this function
         if not re.match(".*-.*-linux", triple):
-            return False
+            return ""
 
         # Need to do something different for non-Linux/Android targets
         cpuinfo_path = self.getBuildArtifact("cpuinfo")
@@ -1284,11 +1284,10 @@
             cpuinfo_path = "/proc/cpuinfo"
 
         try:
-            f = open(cpuinfo_path, 'r')
-            cpuinfo = f.read()
-            f.close()
+            with open(cpuinfo_path, 'r') as f:
+                cpuinfo = f.read()
         except:
-            return False
+            return ""
 
         return cpuinfo
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99729.334685.patch
Type: text/x-patch
Size: 902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210401/59f48cbd/attachment-0001.bin>


More information about the lldb-commits mailing list