diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -891,23 +891,18 @@ 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 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 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 @@ 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 --- a/lldb/test/API/commands/platform/process/list/TestProcessList.py +++ b/lldb/test/API/commands/platform/process/list/TestProcessList.py @@ -25,7 +25,6 @@ # 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 --- a/lldb/test/API/commands/process/attach-resume/TestAttachResume.py +++ b/lldb/test/API/commands/process/attach-resume/TestAttachResume.py @@ -33,7 +33,6 @@ 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 --- a/lldb/test/API/commands/process/attach/TestProcessAttach.py +++ b/lldb/test/API/commands/process/attach/TestProcessAttach.py @@ -29,7 +29,6 @@ # Spawn a new process popen = self.spawnSubprocess(exe) - self.addTearDownHook(self.cleanupSubprocesses) self.runCmd("process attach -p " + str(popen.pid)) @@ -55,7 +54,6 @@ # 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 @@ # 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 --- 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 @@ # 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 --- 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 @@ # 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 --- 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 @@ 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 --- a/lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py +++ b/lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py @@ -35,7 +35,6 @@ # 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 --- a/lldb/test/API/functionalities/process_group/TestChangeProcessGroup.py +++ b/lldb/test/API/functionalities/process_group/TestChangeProcessGroup.py @@ -38,7 +38,6 @@ (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 --- a/lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py +++ b/lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py @@ -37,7 +37,6 @@ 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 --- 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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 --- a/lldb/test/API/macosx/function-starts/TestFunctionStarts.py +++ b/lldb/test/API/macosx/function-starts/TestFunctionStarts.py @@ -53,7 +53,6 @@ (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 --- a/lldb/test/API/macosx/universal/TestUniversal.py +++ b/lldb/test/API/macosx/universal/TestUniversal.py @@ -137,7 +137,6 @@ "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 --- a/lldb/test/API/python_api/hello_world/TestHelloWorld.py +++ b/lldb/test/API/python_api/hello_world/TestHelloWorld.py @@ -91,7 +91,6 @@ 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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)