JDevlieghere created this revision.
JDevlieghere added reviewers: labath, teemperor.
Always set the cleanupSubprocesses tear down hook when using spawnSubprocess or
forkSubprocess 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.
Repository:
rLLDB LLDB
https://reviews.llvm.org/D83787
Files:
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
Index: lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py
===================================================================
--- lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py
+++ 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)
Index: lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
===================================================================
--- lldb/test/API/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
+++ 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)
Index: lldb/test/API/python_api/hello_world/TestHelloWorld.py
===================================================================
--- lldb/test/API/python_api/hello_world/TestHelloWorld.py
+++ 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")
Index: lldb/test/API/macosx/universal/TestUniversal.py
===================================================================
--- lldb/test/API/macosx/universal/TestUniversal.py
+++ 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()
Index: lldb/test/API/macosx/function-starts/TestFunctionStarts.py
===================================================================
--- lldb/test/API/macosx/function-starts/TestFunctionStarts.py
+++ 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)
Index: lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py
===================================================================
--- lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py
+++ 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)
Index: lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py
===================================================================
--- lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py
+++ 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)
Index: lldb/test/API/functionalities/thread/create_after_attach/TestCreateAfterAttach.py
===================================================================
--- lldb/test/API/functionalities/thread/create_after_attach/TestCreateAfterAttach.py
+++ 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))
Index: lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py
===================================================================
--- lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py
+++ 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
Index: lldb/test/API/functionalities/process_group/TestChangeProcessGroup.py
===================================================================
--- lldb/test/API/functionalities/process_group/TestChangeProcessGroup.py
+++ 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)
Index: lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py
===================================================================
--- lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py
+++ 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)
Index: lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
===================================================================
--- lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
+++ 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)
Index: lldb/test/API/commands/register/register/register_command/TestRegisters.py
===================================================================
--- lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ 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)
Index: lldb/test/API/commands/process/attach/attach_denied/TestAttachDenied.py
===================================================================
--- lldb/test/API/commands/process/attach/attach_denied/TestAttachDenied.py
+++ 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)
Index: lldb/test/API/commands/process/attach/TestProcessAttach.py
===================================================================
--- lldb/test/API/commands/process/attach/TestProcessAttach.py
+++ 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)
Index: lldb/test/API/commands/process/attach-resume/TestAttachResume.py
===================================================================
--- lldb/test/API/commands/process/attach-resume/TestAttachResume.py
+++ 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))
Index: lldb/test/API/commands/platform/process/list/TestProcessList.py
===================================================================
--- lldb/test/API/commands/platform/process/list/TestProcessList.py
+++ 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"]
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -902,25 +902,16 @@
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())
proc.launch(executable, args)
self.subprocesses.append(proc)
+ self.addTearDownHook(self.cleanupSubprocesses)
return proc
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:
@@ -934,6 +925,7 @@
# Give the child time to get through the execvp() call
time.sleep(0.1)
self.forkedProcessPids.append(child_pid)
+ self.addTearDownHook(self.cleanupSubprocesses)
return child_pid
def HideStdout(self):
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits