[lldb/Test] Remove custom tearDownHooks from GDB Remote tests
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 15 Jul 2020 16:59:54 +0000 (09:59 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 15 Jul 2020 20:18:06 +0000 (13:18 -0700)
Remove custom tearDownHooks from GDB Remote tests as we now cleanup
subprocesses unconditionally. This also changes the termination order to
be the reverse of the creation order. I don't think anything is relying
on that right now, but it better fits the setup/teardown paradigm.

lldb/packages/Python/lldbsuite/test/lldbtest.py
lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py

index b1add79..2580572 100644 (file)
@@ -884,8 +884,8 @@ class Base(unittest2.TestCase):
         self.addTearDownHook(lambda: self.dbg.SetAsync(old_async))
 
     def cleanupSubprocesses(self):
-        # Ensure any subprocesses are cleaned up
-        for p in self.subprocesses:
+        # Terminate subprocesses in reverse order from how they were created.
+        for p in reversed(self.subprocesses):
             p.terminate()
             del p
         del self.subprocesses[:]
index ac611bc..0b81912 100644 (file)
@@ -402,7 +402,6 @@ class GdbRemoteTestCaseBase(TestBase):
             self.debug_monitor_exe,
             commandline_args,
             install_remote=False)
-        self.addTearDownHook(self.cleanupSubprocesses)
         self.assertIsNotNone(server)
 
         # If we're receiving the stub's listening port from the named pipe, do
@@ -418,15 +417,6 @@ class GdbRemoteTestCaseBase(TestBase):
             server = self.launch_debug_monitor(attach_pid=attach_pid)
             self.assertIsNotNone(server)
 
-            def shutdown_debug_monitor():
-                try:
-                    server.terminate()
-                except:
-                    logger.warning(
-                        "failed to terminate server for debug monitor: {}; ignoring".format(
-                            sys.exc_info()[0]))
-            self.addTearDownHook(shutdown_debug_monitor)
-
             # Schedule debug monitor to be shut down during teardown.
             logger = self.logger
 
@@ -445,15 +435,6 @@ class GdbRemoteTestCaseBase(TestBase):
             # Schedule debug monitor to be shut down during teardown.
             logger = self.logger
 
-            def shutdown_debug_monitor():
-                try:
-                    server.terminate()
-                except:
-                    logger.warning(
-                        "failed to terminate server for debug monitor: {}; ignoring".format(
-                            sys.exc_info()[0]))
-            self.addTearDownHook(shutdown_debug_monitor)
-
             connect_attemps = 0
             MAX_CONNECT_ATTEMPTS = 10
 
@@ -506,17 +487,7 @@ class GdbRemoteTestCaseBase(TestBase):
         if sleep_seconds:
             args.append("sleep:%d" % sleep_seconds)
 
-        inferior = self.spawnSubprocess(exe_path, args)
-
-        def shutdown_process_for_attach():
-            try:
-                inferior.terminate()
-            except:
-                logger.warning(
-                    "failed to terminate inferior process for attach: {}; ignoring".format(
-                        sys.exc_info()[0]))
-        self.addTearDownHook(shutdown_process_for_attach)
-        return inferior
+        return self.spawnSubprocess(exe_path, args)
 
     def prep_debug_monitor_and_inferior(
             self,