[lldb/test] Change base class of lldb-server tests
authorPavel Labath <pavel@labath.sk>
Thu, 10 Dec 2020 14:25:55 +0000 (15:25 +0100)
committerPavel Labath <pavel@labath.sk>
Thu, 10 Dec 2020 15:21:28 +0000 (16:21 +0100)
lldb-server tests are a very special subclass of "api" tests. As they
communicate with lldb-server directly, they don't actually need most of
facilities provided by our TestBase class. In particular, they don't
need the ability to fork debug info flavours of tests (but they could
use debug server flavours).

This makes them inherit from "Base" instead. This avoids the need to
explicitly mark these tests as NO_DEBUG_INFO_TEST_CASE. Two additional
necessary tweaks were:
- move run_platform_command to the base (Base) class. This is used in
  one test, and can be generally useful when running tests remotely.
- add a "build" method, forwarding to buildDefault. This is to avoid
  updating each test case to use buildDefault (also, "build" sounds
  better). It might be interesting to refactor the (Test)Base classes so
  that all debug info flavour handling happens in TestBase, and the Base
  class provides a simple build method automatically.

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

index 1f3bc77..d240050 100644 (file)
@@ -1785,6 +1785,12 @@ class Base(unittest2.TestCase):
         else:
             return ['libc++.1.dylib', 'libc++abi.']
 
+    def run_platform_command(self, cmd):
+        platform = self.dbg.GetSelectedPlatform()
+        shell_command = lldb.SBPlatformShellCommand(cmd)
+        err = platform.Run(shell_command)
+        return (err, shell_command.GetStatus(), shell_command.GetOutput())
+
 # Metaclass for TestBase to change the list of test metods when a new TestCase is loaded.
 # We change the test methods to create a new test method for each test for each debug info we are
 # testing. The name of the new test method will be '<original-name>_<debug-info>' and with adding
@@ -2656,12 +2662,6 @@ FileCheck output:
         else:
             self.fail("Can't build for debug info: %s" % self.getDebugInfo())
 
-    def run_platform_command(self, cmd):
-        platform = self.dbg.GetSelectedPlatform()
-        shell_command = lldb.SBPlatformShellCommand(cmd)
-        err = platform.Run(shell_command)
-        return (err, shell_command.GetStatus(), shell_command.GetOutput())
-
     """Assert that an lldb.SBError is in the "success" state."""
     def assertSuccess(self, obj, msg=None):
         if not obj.Success():
index 2908ca2..b578aae 100644 (file)
@@ -27,9 +27,7 @@ class _ConnectionRefused(IOError):
     pass
 
 
-class GdbRemoteTestCaseBase(TestBase):
-
-    NO_DEBUG_INFO_TESTCASE = True
+class GdbRemoteTestCaseBase(Base):
 
     # Default time out in seconds. The timeout is increased tenfold under Asan.
     DEFAULT_TIMEOUT =  20 * (10 if ('ASAN_OPTIONS' in os.environ) else 1)
@@ -83,7 +81,7 @@ class GdbRemoteTestCaseBase(TestBase):
                    for channel in lldbtest_config.channels)
 
     def setUp(self):
-        TestBase.setUp(self)
+        super(GdbRemoteTestCaseBase, self).setUp()
 
         self.setUpBaseLogging()
         self.debug_monitor_extra_args = []
@@ -121,6 +119,9 @@ class GdbRemoteTestCaseBase(TestBase):
         self._verbose_log_handler = None
         TestBase.tearDown(self)
 
+    def build(self, *args, **kwargs):
+        self.buildDefault(*args, **kwargs)
+
     def getLocalServerLogFile(self):
         return self.log_basename + "-server.log"