[Lldb-commits] [lldb] 4aafc47 - [lldb/Test] Always set the cleanupSubprocesses tear down hook

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 14 14:06:02 PDT 2020


Author: Jonas Devlieghere
Date: 2020-07-14T14:05:56-07:00
New Revision: 4aafc479f28ce1ad952f66ac3758f69060c77a08

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

LOG: [lldb/Test] Always set the cleanupSubprocesses tear down hook

Always clean up subprocesses on tear down instead of relying on the
caller to do so. This is not only less error prone but also means the
tests can be more concise.

Differential revision: https://reviews.llvm.org/D83787

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/lldbtest.py
    lldb/test/API/commands/platform/process/list/TestProcessList.py
    lldb/test/API/commands/process/attach-resume/TestAttachResume.py
    lldb/test/API/commands/process/attach/TestProcessAttach.py
    lldb/test/API/commands/process/attach/attach_denied/TestAttachDenied.py
    lldb/test/API/commands/register/register/register_command/TestRegisters.py
    lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
    lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py
    lldb/test/API/functionalities/process_group/TestChangeProcessGroup.py
    lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py
    lldb/test/API/functionalities/thread/create_after_attach/TestCreateAfterAttach.py
    lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py
    lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py
    lldb/test/API/macosx/function-starts/TestFunctionStarts.py
    lldb/test/API/macosx/universal/TestUniversal.py
    lldb/test/API/python_api/hello_world/TestHelloWorld.py
    lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
    lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 13afcb944aa5..9c32bdb42e28 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -891,23 +891,18 @@ def cleanupSubprocesses(self):
         for p in self.subprocesses:
             p.terminate()
             del p
-        self.subprocesses.clear()
+        del self.subprocesses[:]
         # Ensure any forked processes are cleaned up
         for pid in self.forkedProcessPids:
             try:
                 os.kill(pid, signal.SIGTERM)
             except OSError:
                 pass
-        self.forkedProcessPids.clear()
+        del self.forkedProcessPids[:]
 
     def spawnSubprocess(self, executable, args=[], install_remote=True):
         """ Creates a subprocess.Popen object with the specified executable and arguments,
             saves it in self.subprocesses, and returns the object.
-            NOTE: if using this function, ensure you also call:
-
-              self.addTearDownHook(self.cleanupSubprocesses)
-
-            otherwise the test suite will leak processes.
         """
         proc = _RemoteProcess(
             install_remote) if lldb.remote_platform else _LocalProcess(self.TraceOn())
@@ -917,11 +912,6 @@ def spawnSubprocess(self, executable, args=[], install_remote=True):
 
     def forkSubprocess(self, executable, args=[]):
         """ Fork a subprocess with its own group ID.
-            NOTE: if using this function, ensure you also call:
-
-              self.addTearDownHook(self.cleanupSubprocesses)
-
-            otherwise the test suite will leak processes.
         """
         child_pid = os.fork()
         if child_pid == 0:
@@ -1025,9 +1015,6 @@ def deletePexpectChild(self):
 
     def tearDown(self):
         """Fixture for unittest test case teardown."""
-        #import traceback
-        # traceback.print_stack()
-
         self.deletePexpectChild()
 
         # Check and run any hook functions.
@@ -1054,6 +1041,9 @@ def tearDown(self):
                 for dict in reversed(self.dicts):
                     self.cleanup(dictionary=dict)
 
+        # Remove subprocesses created by the test.
+        self.cleanupSubprocesses()
+
         # This must be the last statement, otherwise teardown hooks or other
         # lines might depend on this still being active.
         lldb.SBDebugger.Destroy(self.dbg)

diff  --git a/lldb/test/API/commands/platform/process/list/TestProcessList.py b/lldb/test/API/commands/platform/process/list/TestProcessList.py
index ba0193ab1a68..9fc84d4f26e0 100644
--- a/lldb/test/API/commands/platform/process/list/TestProcessList.py
+++ b/lldb/test/API/commands/platform/process/list/TestProcessList.py
@@ -25,7 +25,6 @@ def test_process_list_with_args(self):
 
         # Spawn a new process
         popen = self.spawnSubprocess(exe, args=["arg1", "--arg2", "arg3"])
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         substrs = [str(popen.pid), "TestProcess arg1 --arg2 arg3"]
 

diff  --git a/lldb/test/API/commands/process/attach-resume/TestAttachResume.py b/lldb/test/API/commands/process/attach-resume/TestAttachResume.py
index 48a281e096a9..ff1bb8c6921d 100644
--- a/lldb/test/API/commands/process/attach-resume/TestAttachResume.py
+++ b/lldb/test/API/commands/process/attach-resume/TestAttachResume.py
@@ -33,7 +33,6 @@ def process_attach_continue_interrupt_detach(self):
         exe = self.getBuildArtifact(exe_name)
 
         popen = self.spawnSubprocess(exe)
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         self.runCmd("process attach -p " + str(popen.pid))
 

diff  --git a/lldb/test/API/commands/process/attach/TestProcessAttach.py b/lldb/test/API/commands/process/attach/TestProcessAttach.py
index f9b273309956..4e61675c6fc5 100644
--- a/lldb/test/API/commands/process/attach/TestProcessAttach.py
+++ b/lldb/test/API/commands/process/attach/TestProcessAttach.py
@@ -29,7 +29,6 @@ def test_attach_to_process_by_id(self):
 
         # Spawn a new process
         popen = self.spawnSubprocess(exe)
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         self.runCmd("process attach -p " + str(popen.pid))
 
@@ -55,7 +54,6 @@ def test_attach_to_process_from_
diff erent_dir_by_id(self):
 
         # Spawn a new process
         popen = self.spawnSubprocess(exe)
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         os.chdir(newdir)
         self.addTearDownHook(lambda: os.chdir(testdir))
@@ -74,7 +72,6 @@ def test_attach_to_process_by_name(self):
 
         # Spawn a new process
         popen = self.spawnSubprocess(exe)
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         self.runCmd("process attach -n " + exe_name)
 

diff  --git a/lldb/test/API/commands/process/attach/attach_denied/TestAttachDenied.py b/lldb/test/API/commands/process/attach/attach_denied/TestAttachDenied.py
index a7565ccfeb75..4a2b0b7cf817 100644
--- a/lldb/test/API/commands/process/attach/attach_denied/TestAttachDenied.py
+++ b/lldb/test/API/commands/process/attach/attach_denied/TestAttachDenied.py
@@ -37,7 +37,6 @@ def test_attach_to_process_by_id_denied(self):
 
         # Spawn a new process
         popen = self.spawnSubprocess(exe, [pid_file_path])
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
 

diff  --git a/lldb/test/API/commands/register/register/register_command/TestRegisters.py b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
index b0931a7d6977..9441483816c5 100644
--- a/lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -457,7 +457,6 @@ def convenience_registers_with_process_attach(self, test_16bit_regs):
 
         # Spawn a new process
         pid = self.spawnSubprocess(exe, ['wait_for_attach']).pid
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         if self.TraceOn():
             print("pid of spawned process: %d" % pid)

diff  --git a/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py b/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
index ae5822750d69..8ab84bd3203e 100644
--- a/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
+++ b/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
@@ -48,7 +48,6 @@ def test_target_auto_install_main_executable(self):
             self.debug_monitor_exe,
             commandline_args,
             install_remote=False)
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         # Wait for the new process gets ready.
         time.sleep(0.1)

diff  --git a/lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py b/lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py
index 78f3feae6ff6..c6ab4150a6bf 100644
--- a/lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py
+++ b/lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py
@@ -35,7 +35,6 @@ def test(self):
 
         # Spawn a new process
         popen = self.spawnSubprocess(exe, [pid_file_path])
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         # Wait until process has fully started up.
         pid = lldbutil.wait_for_file_on_target(self, pid_file_path)

diff  --git a/lldb/test/API/functionalities/process_group/TestChangeProcessGroup.py b/lldb/test/API/functionalities/process_group/TestChangeProcessGroup.py
index 124d13ed97a4..51c0ae75c1a3 100644
--- a/lldb/test/API/functionalities/process_group/TestChangeProcessGroup.py
+++ b/lldb/test/API/functionalities/process_group/TestChangeProcessGroup.py
@@ -38,7 +38,6 @@ def test_setpgid(self):
                 (pid_file_path)))
 
         popen = self.spawnSubprocess(exe, [pid_file_path])
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
 

diff  --git a/lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py b/lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py
index b02b170a7e3f..e6bb9c6a1672 100644
--- a/lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py
+++ b/lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py
@@ -37,7 +37,6 @@ def test_reproducer_attach(self):
                 pass
 
         self.build(dictionary={'EXE': exe})
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         inferior = self.spawnSubprocess(self.getBuildArtifact(exe), [token])
         pid = inferior.pid

diff  --git a/lldb/test/API/functionalities/thread/create_after_attach/TestCreateAfterAttach.py b/lldb/test/API/functionalities/thread/create_after_attach/TestCreateAfterAttach.py
index 59fb3b6fd399..19c02c12a894 100644
--- a/lldb/test/API/functionalities/thread/create_after_attach/TestCreateAfterAttach.py
+++ b/lldb/test/API/functionalities/thread/create_after_attach/TestCreateAfterAttach.py
@@ -56,7 +56,6 @@ def create_after_attach(self, use_fork):
         else:
             popen = self.spawnSubprocess(exe)
             pid = popen.pid
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         # Attach to the spawned process
         self.runCmd("process attach -p " + str(pid))

diff  --git a/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py b/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py
index 793551259f9a..2572600a1829 100644
--- a/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py
+++ b/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py
@@ -38,7 +38,6 @@ def test_attach_and_check_dsyms(self):
         self.build()
         os.chdir(self.getBuildDir());
         popen = self.spawnSubprocess(exe)
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         # Give the inferior time to start up, dlopen a bundle, remove the bundle it linked in
         sleep(5)

diff  --git a/lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py b/lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py
index 379ff5d0a7ae..a486c5159f01 100644
--- a/lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py
+++ b/lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py
@@ -36,7 +36,6 @@ def test_attach_and_check_dsyms(self):
         exe = self.getBuildArtifact(exe_name)
         self.build()
         popen = self.spawnSubprocess(exe, [self.getBuildDir()])
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         # Give the inferior time to start up, dlopen a bundle, remove the bundle it linked in
         sleep(5)

diff  --git a/lldb/test/API/macosx/function-starts/TestFunctionStarts.py b/lldb/test/API/macosx/function-starts/TestFunctionStarts.py
index 141f4e70930a..0a983436462a 100644
--- a/lldb/test/API/macosx/function-starts/TestFunctionStarts.py
+++ b/lldb/test/API/macosx/function-starts/TestFunctionStarts.py
@@ -53,7 +53,6 @@ def do_function_starts(self, in_memory):
                 (pid_file_path)))
 
         popen = self.spawnSubprocess(exe, [pid_file_path])
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         # Wait until process has fully started up.
         pid = lldbutil.wait_for_file_on_target(self, pid_file_path)

diff  --git a/lldb/test/API/macosx/universal/TestUniversal.py b/lldb/test/API/macosx/universal/TestUniversal.py
index 9982edcc77f0..94a056762a2c 100644
--- a/lldb/test/API/macosx/universal/TestUniversal.py
+++ b/lldb/test/API/macosx/universal/TestUniversal.py
@@ -137,7 +137,6 @@ def test_process_attach_with_wrong_arch(self):
             "Our main breakpoint has locations.")
 
         popen = self.spawnSubprocess(exe, ["keep_waiting"])
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         error = lldb.SBError()
         empty_listener = lldb.SBListener()

diff  --git a/lldb/test/API/python_api/hello_world/TestHelloWorld.py b/lldb/test/API/python_api/hello_world/TestHelloWorld.py
index c1155cf29814..d52b0087a8e6 100644
--- a/lldb/test/API/python_api/hello_world/TestHelloWorld.py
+++ b/lldb/test/API/python_api/hello_world/TestHelloWorld.py
@@ -91,7 +91,6 @@ def test_with_attach_to_process_with_id_api(self):
             if os.path.exists(token):
                 os.remove(token)
         popen = self.spawnSubprocess(self.getBuildArtifact(exe), [token])
-        self.addTearDownHook(self.cleanupSubprocesses)
         lldbutil.wait_for_file_on_target(self, token)
 
         listener = lldb.SBListener("my.attach.listener")
@@ -126,7 +125,6 @@ def test_with_attach_to_process_with_name_api(self):
             if os.path.exists(token):
                 os.remove(token)
         popen = self.spawnSubprocess(self.getBuildArtifact(exe), [token])
-        self.addTearDownHook(self.cleanupSubprocesses)
         lldbutil.wait_for_file_on_target(self, token)
 
         listener = lldb.SBListener("my.attach.listener")

diff  --git a/lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py b/lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
index a9847c66ca12..c9331e7d09a5 100644
--- a/lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
+++ b/lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
@@ -54,7 +54,6 @@ def test_platform_process_connect(self):
             self.debug_monitor_exe,
             commandline_args,
             install_remote=False)
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         socket_id = lldbutil.wait_for_file_on_target(self, port_file)
 

diff  --git a/lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py b/lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py
index e49c9267d971..7955b6a97b04 100644
--- a/lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py
+++ b/lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py
@@ -90,7 +90,6 @@ def cleanup():
         self.addTearDownHook(cleanup)
 
         popen = self.spawnSubprocess(program, [pid_file_path])
-        self.addTearDownHook(self.cleanupSubprocesses)
 
         pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
 


        


More information about the lldb-commits mailing list