[Lldb-commits] [lldb] 7df4eaa - [lldb/test] Automatically find debug servers to test

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 11 05:44:10 PST 2021


Author: Pavel Labath
Date: 2021-02-11T14:43:53+01:00
New Revision: 7df4eaaa937332c0617aa665080533966e2c98a0

URL: https://github.com/llvm/llvm-project/commit/7df4eaaa937332c0617aa665080533966e2c98a0
DIFF: https://github.com/llvm/llvm-project/commit/7df4eaaa937332c0617aa665080533966e2c98a0.diff

LOG: [lldb/test] Automatically find debug servers to test

Our test configuration logic assumes that the tests can be run either
with debugserver or with lldb-server. This is not entirely correct,
since lldb server has two "personalities" (platform server and debug
server) and debugserver is only a replacement for the latter.

A consequence of this is that it's not possible to test the platform
behavior of lldb-server on macos, as it is not possible to get a hold of
the lldb-server binary.

One solution to that would be to duplicate the server configuration
logic to be able to specify both executables. However, that seems
excessively redundant.

A well-behaved lldb should be able to find the debug server on its own,
and testing lldb with a different (lldb-|debug)server does not seem very
useful (even in the out-of-tree debugserver setup, we copy the server
into the build tree to make it appear "real").

Therefore, this patch deletes the configuration altogether and changes
the low-level server retrieval functions to be able to both lldb-server
and debugserver paths. They do this by consulting the "support
executable" directory of the lldb under test.

Differential Revision: https://reviews.llvm.org/D96202

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/dotest.py
    lldb/packages/Python/lldbsuite/test/dotest_args.py
    lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
    lldb/test/API/CMakeLists.txt
    lldb/test/API/commands/platform/sdk/TestPlatformSDK.py
    lldb/test/API/lit.site.cfg.py.in
    lldb/utils/lldb-dotest/CMakeLists.txt
    lldb/utils/lldb-dotest/lldb-dotest.in

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index 62508a144972..945b3f0c20a4 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -366,12 +366,6 @@ def parseOptionsAndInitTestdirs():
                     args.executable)
             sys.exit(-1)
 
-    if args.server and args.out_of_tree_debugserver:
-        logging.warning('Both --server and --out-of-tree-debugserver are set')
-
-    if args.server and not args.out_of_tree_debugserver:
-        os.environ['LLDB_DEBUGSERVER_PATH'] = args.server
-
     if args.excluded:
         for excl_file in args.excluded:
             parseExclusion(excl_file)

diff  --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index 4774ce352fc2..af45205ae3ed 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -100,10 +100,6 @@ def create_parser():
         '--executable',
         metavar='executable-path',
         help='The path to the lldb executable')
-    group.add_argument(
-        '--server',
-        metavar='server-path',
-        help='The path to the debug server executable to use')
     group.add_argument(
         '--out-of-tree-debugserver',
         dest='out_of_tree_debugserver',

diff  --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
index 07136108b2a4..eba6f322db9b 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
@@ -15,54 +15,12 @@
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import configuration
 from textwrap import dedent
+import shutil
 
-def _get_debug_monitor_from_lldb(lldb_exe, debug_monitor_basename):
-    """Return the debug monitor exe path given the lldb exe path.
+def _get_support_exe(basename):
+    support_dir = lldb.SBHostOS.GetLLDBPath(lldb.ePathTypeSupportExecutableDir)
 
-    This method attempts to construct a valid debug monitor exe name
-    from a given lldb exe name.  It will return None if the synthesized
-    debug monitor name is not found to exist.
-
-    The debug monitor exe path is synthesized by taking the directory
-    of the lldb exe, and replacing the portion of the base name that
-    matches "lldb" (case insensitive) and replacing with the value of
-    debug_monitor_basename.
-
-    Args:
-        lldb_exe: the path to an lldb executable.
-
-        debug_monitor_basename: the base name portion of the debug monitor
-            that will replace 'lldb'.
-
-    Returns:
-        A path to the debug monitor exe if it is found to exist; otherwise,
-        returns None.
-
-    """
-    if not lldb_exe:
-        return None
-
-    exe_dir = os.path.dirname(lldb_exe)
-    exe_base = os.path.basename(lldb_exe)
-
-    # we'll rebuild the filename by replacing lldb with
-    # the debug monitor basename, keeping any prefix or suffix in place.
-    regex = re.compile(r"lldb", re.IGNORECASE)
-    new_base = regex.sub(debug_monitor_basename, exe_base)
-
-    debug_monitor_exe = os.path.join(exe_dir, new_base)
-    if os.path.exists(debug_monitor_exe):
-        return debug_monitor_exe
-
-    new_base = regex.sub(
-        'LLDB.framework/Versions/A/Resources/' +
-        debug_monitor_basename,
-        exe_base)
-    debug_monitor_exe = os.path.join(exe_dir, new_base)
-    if os.path.exists(debug_monitor_exe):
-        return debug_monitor_exe
-
-    return None
+    return shutil.which(basename, path=support_dir.GetDirectory())
 
 
 def get_lldb_server_exe():
@@ -72,11 +30,8 @@ def get_lldb_server_exe():
         A path to the lldb-server exe if it is found to exist; otherwise,
         returns None.
     """
-    if "LLDB_DEBUGSERVER_PATH" in os.environ:
-        return os.environ["LLDB_DEBUGSERVER_PATH"]
 
-    return _get_debug_monitor_from_lldb(
-        lldbtest_config.lldbExec, "lldb-server")
+    return _get_support_exe("lldb-server")
 
 
 def get_debugserver_exe():
@@ -86,15 +41,11 @@ def get_debugserver_exe():
         A path to the debugserver exe if it is found to exist; otherwise,
         returns None.
     """
-    if "LLDB_DEBUGSERVER_PATH" in os.environ:
-        return os.environ["LLDB_DEBUGSERVER_PATH"]
-
     if configuration.arch and configuration.arch == "x86_64" and \
        platform.machine().startswith("arm64"):
         return '/Library/Apple/usr/libexec/oah/debugserver'
 
-    return _get_debug_monitor_from_lldb(
-        lldbtest_config.lldbExec, "debugserver")
+    return _get_support_exe("debugserver")
 
 _LOG_LINE_REGEX = re.compile(r'^(lldb-server|debugserver)\s+<\s*(\d+)>' +
                              '\s+(read|send)\s+packet:\s+(.+)$')

diff  --git a/lldb/test/API/CMakeLists.txt b/lldb/test/API/CMakeLists.txt
index 9d39a7cc21ee..001712fcfbce 100644
--- a/lldb/test/API/CMakeLists.txt
+++ b/lldb/test/API/CMakeLists.txt
@@ -108,18 +108,8 @@ if(CMAKE_HOST_APPLE)
     message(STATUS "LLDB tests use out-of-tree debugserver: ${system_debugserver_path}")
     list(APPEND LLDB_TEST_COMMON_ARGS --out-of-tree-debugserver)
     add_lldb_test_dependency(debugserver)
-  elseif(TARGET debugserver)
-    set(debugserver_path ${LLVM_RUNTIME_OUTPUT_INTDIR}/debugserver)
-    message(STATUS "LLDB Tests use just-built debugserver: ${debugserver_path}")
-    set(LLDB_TEST_SERVER ${debugserver_path})
-    add_lldb_test_dependency(debugserver)
-  elseif(TARGET lldb-server)
-    set(lldb_server_path ${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb-server)
-    message(STATUS "LLDB Tests use just-built lldb-server: ${lldb_server_path}")
-    set(LLDB_TEST_SERVER ${lldb_server_path})
-    add_lldb_test_dependency(lldb-server)
   else()
-    message(WARNING "LLDB Tests enabled, but no server available")
+    message(STATUS "LLDB Tests use just-built debug server")
   endif()
 endif()
 
@@ -136,7 +126,6 @@ if(LLDB_BUILT_STANDALONE)
   string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}")
   string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}")
   string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}")
-  string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_SERVER "${LLDB_TEST_SERVER}")
 
   # Remaining ones must be paths to the provided LLVM build-tree.
   if(LLVM_CONFIGURATION_TYPES)
@@ -163,7 +152,6 @@ string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_BUILD_DI
 string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}")
 string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}")
 string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}")
-string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_SERVER "${LLDB_TEST_SERVER}")
 
 # Configure the API test suite.
 configure_lit_site_cfg(

diff  --git a/lldb/test/API/commands/platform/sdk/TestPlatformSDK.py b/lldb/test/API/commands/platform/sdk/TestPlatformSDK.py
index 28e79209f0cd..8bf950a1bd3c 100644
--- a/lldb/test/API/commands/platform/sdk/TestPlatformSDK.py
+++ b/lldb/test/API/commands/platform/sdk/TestPlatformSDK.py
@@ -3,6 +3,7 @@
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
+from lldbgdbserverutils import get_debugserver_exe
 
 import os
 import platform
@@ -28,7 +29,7 @@ class PlatformSDKTestCase(TestBase):
     TIMEOUT = 2
 
     def no_debugserver(self):
-        if os.getenv('LLDB_DEBUGSERVER_PATH') is None:
+        if get_debugserver_exe() is None:
             return 'no debugserver'
         return None
 
@@ -88,7 +89,7 @@ def cleanup():
         shutil.move(exe, exe_sdk_path)
 
         # Attach to it with debugserver.
-        debugserver = os.getenv('LLDB_DEBUGSERVER_PATH')
+        debugserver = get_debugserver_exe()
         debugserver_args = [
             'localhost:{}'.format(self.PORT), '--attach={}'.format(pid)
         ]

diff  --git a/lldb/test/API/lit.site.cfg.py.in b/lldb/test/API/lit.site.cfg.py.in
index 5c014b52d3fa..b66935040fbe 100644
--- a/lldb/test/API/lit.site.cfg.py.in
+++ b/lldb/test/API/lit.site.cfg.py.in
@@ -29,7 +29,6 @@ config.lldb_executable = '@LLDB_TEST_EXECUTABLE@'
 config.test_arch = '@LLDB_TEST_ARCH@'
 config.test_compiler = '@LLDB_TEST_COMPILER@'
 config.dsymutil = '@LLDB_TEST_DSYMUTIL@'
-config.server = '@LLDB_TEST_SERVER@'
 # The API tests use their own module caches.
 config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-api")
 config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-api")
@@ -55,7 +54,6 @@ try:
     config.lldb_executable = config.lldb_executable % lit_config.params
     config.lldb_libs_dir = config.lldb_libs_dir % lit_config.params
     config.test_compiler = config.test_compiler % lit_config.params
-    config.server = config.server % lit_config.params
     config.lldb_framework_dir = config.lldb_framework_dir % lit_config.params
     config.dotest_args_str = config.dotest_args_str % lit_config.params
 except KeyError as e:

diff  --git a/lldb/utils/lldb-dotest/CMakeLists.txt b/lldb/utils/lldb-dotest/CMakeLists.txt
index 979722efd298..5b7522835acd 100644
--- a/lldb/utils/lldb-dotest/CMakeLists.txt
+++ b/lldb/utils/lldb-dotest/CMakeLists.txt
@@ -19,7 +19,6 @@ set(vars
   LLDB_TEST_EXECUTABLE
   LLDB_TEST_COMPILER
   LLDB_TEST_DSYMUTIL
-  LLDB_TEST_SERVER
   LLDB_LIBS_DIR
   LLVM_TOOLS_DIR
   )

diff  --git a/lldb/utils/lldb-dotest/lldb-dotest.in b/lldb/utils/lldb-dotest/lldb-dotest.in
index 580b97af2a23..f6b5e0d01dcf 100755
--- a/lldb/utils/lldb-dotest/lldb-dotest.in
+++ b/lldb/utils/lldb-dotest/lldb-dotest.in
@@ -8,7 +8,6 @@ arch = '@LLDB_TEST_ARCH@'
 executable = '@LLDB_TEST_EXECUTABLE_CONFIGURED@'
 compiler = '@LLDB_TEST_COMPILER_CONFIGURED@'
 dsymutil = '@LLDB_TEST_DSYMUTIL_CONFIGURED@'
-server = '@LLDB_TEST_SERVER_CONFIGURED@'
 lldb_build_dir = '@LLDB_TEST_BUILD_DIRECTORY_CONFIGURED@'
 lldb_build_intel_pt = "@LLDB_BUILD_INTEL_PT@"
 lldb_framework_dir = "@LLDB_FRAMEWORK_DIR_CONFIGURED@"
@@ -28,8 +27,6 @@ if __name__ == '__main__':
     cmd.extend(['--dsymutil', dsymutil])
     cmd.extend(['--lldb-libs-dir', lldb_libs_dir])
     cmd.extend(['--llvm-tools-dir', llvm_tools_dir])
-    if server:
-        cmd.extend(['--server', server])
     if lldb_framework_dir:
         cmd.extend(['--framework', lldb_framework_dir])
     if lldb_build_intel_pt == "1":


        


More information about the lldb-commits mailing list