[Lldb-commits] [lldb] 9ecbad5 - [lldb] lldbinline and lldbtest gardening (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 14 10:41:51 PDT 2020


Author: Jonas Devlieghere
Date: 2020-07-14T10:41:45-07:00
New Revision: 9ecbad54c2f02e3ef44077d1f542eaa8b3dd6d44

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

LOG: [lldb] lldbinline and lldbtest gardening (NFC)

 - Make the open more Pythonic.
 - Remove the unused `cleanup` Make target.
 - Remove commented-out/obvious/low-value comments.
 - Cleanup the forked process PID list.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbinline.py b/lldb/packages/Python/lldbsuite/test/lldbinline.py
index 29a708440c2a..0d1cb24a54df 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbinline.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbinline.py
@@ -82,20 +82,16 @@ def handle_breakpoint(self, test, breakpoint_id):
 
 
 class InlineTest(TestBase):
-    # Overrides
 
     def getBuildDirBasename(self):
         return self.__class__.__name__ + "." + self.testMethodName
 
-    # Internal implementation
-
     def BuildMakefile(self):
         makefilePath = self.getBuildArtifact("Makefile")
         if os.path.exists(makefilePath):
             return
 
         categories = {}
-
         for f in os.listdir(self.getSourceDir()):
             t = source_type(f)
             if t:
@@ -104,24 +100,20 @@ def BuildMakefile(self):
                 else:
                     categories[t] = [f]
 
-        makefile = open(makefilePath, 'w+')
+        with open(makefilePath, 'w+') as makefile:
+            for t in list(categories.keys()):
+                line = t + " := " + " ".join(categories[t])
+                makefile.write(line + "\n")
 
-        for t in list(categories.keys()):
-            line = t + " := " + " ".join(categories[t])
-            makefile.write(line + "\n")
+            if ('OBJCXX_SOURCES' in list(categories.keys())) or \
+               ('OBJC_SOURCES' in list(categories.keys())):
+                makefile.write(
+                    "LDFLAGS = $(CFLAGS) -lobjc -framework Foundation\n")
 
-        if ('OBJCXX_SOURCES' in list(categories.keys())) or (
-                'OBJC_SOURCES' in list(categories.keys())):
-            makefile.write(
-                "LDFLAGS = $(CFLAGS) -lobjc -framework Foundation\n")
+            if ('CXX_SOURCES' in list(categories.keys())):
+                makefile.write("CXXFLAGS += -std=c++11\n")
 
-        if ('CXX_SOURCES' in list(categories.keys())):
-            makefile.write("CXXFLAGS += -std=c++11\n")
-
-        makefile.write("include Makefile.rules\n")
-        makefile.write("\ncleanup:\n\trm -f Makefile *.d\n\n")
-        makefile.flush()
-        makefile.close()
+            makefile.write("include Makefile.rules\n")
 
     def _test(self):
         self.BuildMakefile()
@@ -168,8 +160,6 @@ def do_test(self):
                                                lldb.eStateExited],
                         PROCESS_EXITED)
 
-    # Utilities for testcases
-
     def check_expression(self, expression, expected_result, use_summary=True):
         value = self.frame().EvaluateExpression(expression)
         self.assertTrue(value.IsValid(), expression + "returned a valid value")

diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index ebef896d12b6..13afcb944aa5 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -891,13 +891,14 @@ def cleanupSubprocesses(self):
         for p in self.subprocesses:
             p.terminate()
             del p
-        del self.subprocesses[:]
+        self.subprocesses.clear()
         # Ensure any forked processes are cleaned up
         for pid in self.forkedProcessPids:
             try:
                 os.kill(pid, signal.SIGTERM)
             except OSError:
                 pass
+        self.forkedProcessPids.clear()
 
     def spawnSubprocess(self, executable, args=[], install_remote=True):
         """ Creates a subprocess.Popen object with the specified executable and arguments,
@@ -1877,9 +1878,6 @@ def generateSource(self, source):
         self.addTearDownHook(lambda: os.remove(src))
 
     def setUp(self):
-        #import traceback
-        # traceback.print_stack()
-
         # Works with the test driver to conditionally skip tests via
         # decorators.
         Base.setUp(self)
@@ -1998,9 +1996,6 @@ def get_process_working_directory(self):
             return self.getBuildDir()
 
     def tearDown(self):
-        #import traceback
-        # traceback.print_stack()
-
         # Ensure all the references to SB objects have gone away so that we can
         # be sure that all test-specific resources have been freed before we
         # attempt to delete the targets.


        


More information about the lldb-commits mailing list