[Lldb-commits] [lldb] f8f4d8f - [lldb] Improve CPUInfo test predicate

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 6 02:46:53 PDT 2021


Author: David Spickett
Date: 2021-04-06T10:46:47+01:00
New Revision: f8f4d8f87ba4c1fbb18a4e7f4a5ea03a8b8ec061

URL: https://github.com/llvm/llvm-project/commit/f8f4d8f87ba4c1fbb18a4e7f4a5ea03a8b8ec061
DIFF: https://github.com/llvm/llvm-project/commit/f8f4d8f87ba4c1fbb18a4e7f4a5ea03a8b8ec061.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index a9928af677a6..d94f8e9c28b9 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1274,7 +1274,7 @@ def getCPUInfo(self):
 
         # TODO other platforms, please implement this function
         if not re.match(".*-.*-linux", triple):
-            return False
+            return ""
 
         # Need to do something 
diff erent for non-Linux/Android targets
         cpuinfo_path = self.getBuildArtifact("cpuinfo")
@@ -1284,11 +1284,10 @@ def getCPUInfo(self):
             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
 


        


More information about the lldb-commits mailing list