[Lldb-commits] [lldb] r370394 - [test] Fix various module cache bugs and inconsistencies

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 29 11:37:05 PDT 2019


Author: jdevlieghere
Date: Thu Aug 29 11:37:05 2019
New Revision: 370394

URL: http://llvm.org/viewvc/llvm-project?rev=370394&view=rev
Log:
[test] Fix various module cache bugs and inconsistencies

Currently, lit tests don't set neither the module cache for building
inferiors nor the module cache used by lldb when running tests.
Furthermore, we have several places where we rely on the path to the
module cache being always the same, rather than passing the correct
value around. This makes it hard to specify a different module cache
path when debugging a a test.

This patch reworks how we determine and pass around the module cache
paths and fixes the omission on the lit side. It also adds a sanity
check to the lit and dotest suites.

Differential revision: https://reviews.llvm.org/D66966

Added:
    lldb/trunk/lit/Settings/TestModuleCacheSanity.test
    lldb/trunk/packages/Python/lldbsuite/test/sanity/
    lldb/trunk/packages/Python/lldbsuite/test/sanity/TestModuleCacheSanity.py
Modified:
    lldb/trunk/CMakeLists.txt
    lldb/trunk/lit/CMakeLists.txt
    lldb/trunk/lit/Suite/lit.cfg
    lldb/trunk/lit/Suite/lit.site.cfg.in
    lldb/trunk/lit/helper/toolchain.py
    lldb/trunk/lit/lit-lldb-init.in
    lldb/trunk/lit/lit.cfg.py
    lldb/trunk/lit/lit.site.cfg.py.in
    lldb/trunk/packages/Python/lldbsuite/test/configuration.py
    lldb/trunk/packages/Python/lldbsuite/test/dotest.py
    lldb/trunk/packages/Python/lldbsuite/test/dotest_args.py
    lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
    lldb/trunk/test/CMakeLists.txt
    lldb/trunk/utils/lldb-dotest/lldb-dotest.in

Modified: lldb/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/CMakeLists.txt?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/CMakeLists.txt (original)
+++ lldb/trunk/CMakeLists.txt Thu Aug 29 11:37:05 2019
@@ -71,6 +71,7 @@ add_subdirectory(docs)
 
 option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
 if(LLDB_INCLUDE_TESTS)
+  set(LLDB_TEST_BUILD_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lldb-test-build.noindex" CACHE PATH "The build root for building tests.")
 
   # Set the path to the default lldb test executable.
   set(LLDB_DEFAULT_TEST_EXECUTABLE "${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb${CMAKE_EXECUTABLE_SUFFIX}")

Modified: lldb/trunk/lit/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/CMakeLists.txt?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/lit/CMakeLists.txt (original)
+++ lldb/trunk/lit/CMakeLists.txt Thu Aug 29 11:37:05 2019
@@ -15,6 +15,9 @@ endif()
 get_property(LLDB_DOTEST_ARGS GLOBAL PROPERTY LLDB_DOTEST_ARGS_PROPERTY)
 set(dotest_args_replacement ${LLVM_BUILD_MODE})
 
+set(LLDB_TEST_MODULE_CACHE_LLDB "${LLDB_TEST_BUILD_DIRECTORY}/module-cache-lldb" CACHE PATH "The Clang module cache used by the Clang embedded in LLDB while running tests.")
+set(LLDB_TEST_MODULE_CACHE_CLANG "${LLDB_TEST_BUILD_DIRECTORY}/module-cache-clang" CACHE PATH "The Clang module cache used by the Clang while building tests.")
+
 if(LLDB_BUILT_STANDALONE)
   # In paths to our build-tree, replace CMAKE_CFG_INTDIR with our configuration name placeholder.
   string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} config_runtime_output_dir ${LLVM_RUNTIME_OUTPUT_INTDIR})

Added: lldb/trunk/lit/Settings/TestModuleCacheSanity.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Settings/TestModuleCacheSanity.test?rev=370394&view=auto
==============================================================================
--- lldb/trunk/lit/Settings/TestModuleCacheSanity.test (added)
+++ lldb/trunk/lit/Settings/TestModuleCacheSanity.test Thu Aug 29 11:37:05 2019
@@ -0,0 +1,4 @@
+# This is a sanity check that verifies that the module cache path is set
+# correctly and points inside the default test build directory.
+RUN: %lldb -o 'settings show symbols.clang-modules-cache-path' | FileCheck  %s
+CHECK: lldb-test-build.noindex{{.*}}module-cache-lldb

Modified: lldb/trunk/lit/Suite/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Suite/lit.cfg?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/lit/Suite/lit.cfg (original)
+++ lldb/trunk/lit/Suite/lit.cfg Thu Aug 29 11:37:05 2019
@@ -69,6 +69,12 @@ if config.dotest_lit_args_str:
 if config.llvm_libs_dir:
   dotest_cmd += ['--env', 'LLVM_LIBS_DIR=' + config.llvm_libs_dir]
 
+if config.lldb_build_directory:
+  dotest_cmd += ['--build-dir', config.lldb_build_directory]
+
+if config.lldb_module_cache:
+  dotest_cmd += ['--module-cache-dir', config.lldb_module_cache]
+
 # Load LLDB test format.
 sys.path.append(os.path.join(config.lldb_src_root, "lit", "Suite"))
 import lldbtest

Modified: lldb/trunk/lit/Suite/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Suite/lit.site.cfg.in?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/lit/Suite/lit.site.cfg.in (original)
+++ lldb/trunk/lit/Suite/lit.site.cfg.in Thu Aug 29 11:37:05 2019
@@ -15,6 +15,9 @@ config.host_os = "@HOST_OS@"
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.target_triple = "@TARGET_TRIPLE@"
+config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
+config.lldb_module_cache = "@LLDB_TEST_MODULE_CACHE_LLDB@"
+config.clang_module_cache = "@LLDB_TEST_MODULE_CACHE_CLANG@"
 config.python_executable = "@PYTHON_EXECUTABLE@"
 config.dotest_path = "@LLDB_SOURCE_DIR@/test/dotest.py"
 config.dotest_args_str = "@LLDB_DOTEST_ARGS@"

Modified: lldb/trunk/lit/helper/toolchain.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/helper/toolchain.py?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/lit/helper/toolchain.py (original)
+++ lldb/trunk/lit/helper/toolchain.py Thu Aug 29 11:37:05 2019
@@ -104,6 +104,9 @@ def use_support_substitutions(config):
         flags += ['-L' + config.llvm_libs_dir,
                   '-Wl,-rpath,' + config.llvm_libs_dir]
 
+    # The clang module cache is used for building inferiors.
+    flags += ['-fmodules-cache-path={}'.format(config.clang_module_cache)]
+
     additional_tool_dirs=[]
     if config.lldb_lit_tools_dir:
         additional_tool_dirs.append(config.lldb_lit_tools_dir)

Modified: lldb/trunk/lit/lit-lldb-init.in
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/lit-lldb-init.in?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/lit/lit-lldb-init.in (original)
+++ lldb/trunk/lit/lit-lldb-init.in Thu Aug 29 11:37:05 2019
@@ -2,3 +2,4 @@
 settings set symbols.enable-external-lookup false
 settings set plugin.process.gdb-remote.packet-timeout 60
 settings set interpreter.echo-comment-commands false
+settings set symbols.clang-modules-cache-path "@LLDB_TEST_MODULE_CACHE_LLDB@"

Modified: lldb/trunk/lit/lit.cfg.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/lit.cfg.py?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/lit/lit.cfg.py (original)
+++ lldb/trunk/lit/lit.cfg.py Thu Aug 29 11:37:05 2019
@@ -64,13 +64,10 @@ llvm_config.feature_config(
      ('--targets-built', calculate_arch_features)
      ])
 
-# Clean the module caches in the test build directory.  This is
-# necessary in an incremental build whenever clang changes underneath,
-# so doing it once per lit.py invocation is close enough.
-
-for i in ['module-cache-clang', 'module-cache-lldb']:
-    cachedir = os.path.join(config.lldb_libs_dir, '..',
-                            'lldb-test-build.noindex', i)
+# Clean the module caches in the test build directory. This is necessary in an
+# incremental build whenever clang changes underneath, so doing it once per
+# lit.py invocation is close enough.
+for cachedir in [config.clang_module_cache, config.lldb_module_cache]:
     if os.path.isdir(cachedir):
         print("Deleting module cache at %s."%cachedir)
         shutil.rmtree(cachedir)

Modified: lldb/trunk/lit/lit.site.cfg.py.in
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/lit.site.cfg.py.in?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/lit/lit.site.cfg.py.in (original)
+++ lldb/trunk/lit/lit.site.cfg.py.in Thu Aug 29 11:37:05 2019
@@ -18,6 +18,9 @@ config.have_zlib = @LLVM_ENABLE_ZLIB@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
 config.lldb_disable_python = @LLDB_DISABLE_PYTHON@
+config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
+config.lldb_module_cache = "@LLDB_TEST_MODULE_CACHE_LLDB@"
+config.clang_module_cache = "@LLDB_TEST_MODULE_CACHE_CLANG@"
 
 # Support substitution of the tools and libs dirs with user parameters. This is
 # used when we can't determine the tool dir at configuration time.

Modified: lldb/trunk/packages/Python/lldbsuite/test/configuration.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/configuration.py?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/configuration.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/configuration.py Thu Aug 29 11:37:05 2019
@@ -106,6 +106,9 @@ lldb_platform_working_dir = None
 # The base directory in which the tests are being built.
 test_build_dir = None
 
+# The clang module cache directory used by lldb.
+module_cache_dir = None
+
 # The only directory to scan for tests. If multiple test directories are
 # specified, and an exclusive test subdirectory is specified, the latter option
 # takes precedence.

Modified: lldb/trunk/packages/Python/lldbsuite/test/dotest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/dotest.py?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/dotest.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/dotest.py Thu Aug 29 11:37:05 2019
@@ -55,7 +55,7 @@ def get_dotest_invocation():
 def is_exe(fpath):
     """Returns true if fpath is an executable."""
     if fpath == None:
-      return False
+        return False
     return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
 
 
@@ -274,10 +274,10 @@ def parseOptionsAndInitTestdirs():
                     break
 
     if args.dsymutil:
-      os.environ['DSYMUTIL'] = args.dsymutil
+        os.environ['DSYMUTIL'] = args.dsymutil
     elif platform_system == 'Darwin':
-      os.environ['DSYMUTIL'] = seven.get_command_output(
-          'xcrun -find -toolchain default dsymutil')
+        os.environ['DSYMUTIL'] = seven.get_command_output(
+            'xcrun -find -toolchain default dsymutil')
 
     if args.filecheck:
         # The lldb-dotest script produced by the CMake build passes in a path
@@ -426,6 +426,11 @@ def parseOptionsAndInitTestdirs():
         configuration.lldb_platform_working_dir = args.lldb_platform_working_dir
     if args.test_build_dir:
         configuration.test_build_dir = args.test_build_dir
+    if args.module_cache_dir:
+        configuration.module_cache_dir = args.module_cache_dir
+    else:
+        configuration.module_cache_dir = os.path.join(configuration.test_build_dir,
+                                                      'module-cache-lldb')
 
     # Gather all the dirs passed on the command line.
     if len(args.args) > 0:
@@ -869,16 +874,16 @@ def canRunWatchpointTests():
 
     platform = lldbplatformutil.getPlatform()
     if platform == "netbsd":
-      if os.geteuid() == 0:
-        return True, "root can always write dbregs"
-      try:
-        output = subprocess.check_output(["/sbin/sysctl", "-n",
-          "security.models.extensions.user_set_dbregs"]).decode().strip()
-        if output == "1":
-          return True, "security.models.extensions.user_set_dbregs enabled"
-      except subprocess.CalledProcessError:
-        pass
-      return False, "security.models.extensions.user_set_dbregs disabled"
+        if os.geteuid() == 0:
+            return True, "root can always write dbregs"
+        try:
+            output = subprocess.check_output(["/sbin/sysctl", "-n",
+              "security.models.extensions.user_set_dbregs"]).decode().strip()
+            if output == "1":
+                return True, "security.models.extensions.user_set_dbregs enabled"
+        except subprocess.CalledProcessError:
+            pass
+        return False, "security.models.extensions.user_set_dbregs disabled"
     return True, "watchpoint support available"
 
 def checkWatchpointSupport():

Modified: lldb/trunk/packages/Python/lldbsuite/test/dotest_args.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/dotest_args.py?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/dotest_args.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/dotest_args.py Thu Aug 29 11:37:05 2019
@@ -147,6 +147,11 @@ def create_parser():
         metavar='Test build directory',
         default='lldb-test-build.noindex',
         help='The root build directory for the tests. It will be removed before running.')
+    group.add_argument(
+        '--module-cache-dir',
+        dest='module_cache_dir',
+        metavar='The clang module cache directory used by LLDB',
+        help='The clang module cache directory used by LLDB. This is not the one used by the makefiles. Defaults to <test build directory>/module-cache-lldb.')
 
     # Configuration options
     group = parser.add_argument_group('Remote platform options')

Modified: lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py Thu Aug 29 11:37:05 2019
@@ -1852,9 +1852,9 @@ class TestBase(Base):
         Base.setUp(self)
 
         # Set the clang modules cache path used by LLDB.
-        mod_cache = os.path.join(os.environ["LLDB_BUILD"], "module-cache-lldb")
-        self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
-                    % mod_cache)
+        self.runCmd(
+            'settings set symbols.clang-modules-cache-path "{}"'.format(
+                configuration.module_cache_dir))
 
         for s in self.setUpCommands():
             self.runCmd(s)
@@ -2058,13 +2058,13 @@ class TestBase(Base):
         if check:
             output = ""
             if self.res.GetOutput():
-              output += "\nCommand output:\n" + self.res.GetOutput()
+                output += "\nCommand output:\n" + self.res.GetOutput()
             if self.res.GetError():
-              output += "\nError output:\n" + self.res.GetError()
+                output += "\nError output:\n" + self.res.GetError()
             if msg:
-              msg += output
+                msg += output
             if cmd:
-              cmd += output
+                cmd += output
             self.assertTrue(self.res.Succeeded(),
                             msg if (msg) else CMD_MSG(cmd))
 

Added: lldb/trunk/packages/Python/lldbsuite/test/sanity/TestModuleCacheSanity.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/sanity/TestModuleCacheSanity.py?rev=370394&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/sanity/TestModuleCacheSanity.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/sanity/TestModuleCacheSanity.py Thu Aug 29 11:37:05 2019
@@ -0,0 +1,22 @@
+"""
+This is a sanity check that verifies that the module cache path is set
+correctly and points inside the default test build directory.
+"""
+
+from __future__ import print_function
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+class ModuleCacheSanityTestCase(TestBase):
+
+  mydir = TestBase.compute_mydir(__file__)
+
+  NO_DEBUG_INFO_TESTCASE = True
+
+  def test(self):
+    self.expect(
+        'settings show symbols.clang-modules-cache-path',
+        substrs=['lldb-test-build.noindex', 'module-cache-lldb'])

Modified: lldb/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/CMakeLists.txt?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/test/CMakeLists.txt (original)
+++ lldb/trunk/test/CMakeLists.txt Thu Aug 29 11:37:05 2019
@@ -39,8 +39,6 @@ set(LLDB_TEST_COMMON_ARGS
   --arch=${LLDB_TEST_ARCH}
   -s
   ${CMAKE_BINARY_DIR}/lldb-test-traces
-  --build-dir
-  ${CMAKE_BINARY_DIR}/lldb-test-build.noindex
   -S nm
   -u CXXFLAGS
   -u CFLAGS

Modified: lldb/trunk/utils/lldb-dotest/lldb-dotest.in
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/lldb-dotest/lldb-dotest.in?rev=370394&r1=370393&r2=370394&view=diff
==============================================================================
--- lldb/trunk/utils/lldb-dotest/lldb-dotest.in (original)
+++ lldb/trunk/utils/lldb-dotest/lldb-dotest.in Thu Aug 29 11:37:05 2019
@@ -3,6 +3,7 @@ import subprocess
 import sys
 
 dotest_path = '@LLDB_SOURCE_DIR@/test/dotest.py'
+build_dir = '@LLDB_TEST_BUILD_DIRECTORY@'
 dotest_args_str = '@LLDB_DOTEST_ARGS@'
 
 if __name__ == '__main__':
@@ -11,6 +12,7 @@ if __name__ == '__main__':
     # Build dotest.py command.
     cmd = [sys.executable, dotest_path]
     cmd.extend(dotest_args)
+    cmd.extend(['--build-dir', build_dir])
     cmd.extend(wrapper_args)
     # Invoke dotest.py and return exit code.
     print(' '.join(cmd))




More information about the lldb-commits mailing list