Commit 4aafc479 authored by Jonas Devlieghere's avatar Jonas Devlieghere
Browse files

[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
parent 0257ba58
Loading
Loading
Loading
Loading
+5 −15
Original line number Diff line number Diff line
@@ -891,23 +891,18 @@ class Base(unittest2.TestCase):
        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 @@ class Base(unittest2.TestCase):

    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 @@ class Base(unittest2.TestCase):

    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 @@ class Base(unittest2.TestCase):
                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)
+0 −1
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ class ProcessListTestCase(TestBase):

        # Spawn a new process
        popen = self.spawnSubprocess(exe, args=["arg1", "--arg2", "arg3"])
        self.addTearDownHook(self.cleanupSubprocesses)

        substrs = [str(popen.pid), "TestProcess arg1 --arg2 arg3"]

+0 −1
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ class AttachResumeTestCase(TestBase):
        exe = self.getBuildArtifact(exe_name)

        popen = self.spawnSubprocess(exe)
        self.addTearDownHook(self.cleanupSubprocesses)

        self.runCmd("process attach -p " + str(popen.pid))

+0 −3
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ class ProcessAttachTestCase(TestBase):

        # Spawn a new process
        popen = self.spawnSubprocess(exe)
        self.addTearDownHook(self.cleanupSubprocesses)

        self.runCmd("process attach -p " + str(popen.pid))

@@ -55,7 +54,6 @@ class ProcessAttachTestCase(TestBase):

        # 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 @@ class ProcessAttachTestCase(TestBase):

        # Spawn a new process
        popen = self.spawnSubprocess(exe)
        self.addTearDownHook(self.cleanupSubprocesses)

        self.runCmd("process attach -n " + exe_name)

+0 −1
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ class AttachDeniedTestCase(TestBase):

        # 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)

Loading