Skip to content

Commit ff5982a

Browse files
committed
[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 llvm-svn: 370394
1 parent 5a43fdd commit ff5982a

16 files changed

+86
-30
lines changed

lldb/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ add_subdirectory(docs)
7171

7272
option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
7373
if(LLDB_INCLUDE_TESTS)
74+
set(LLDB_TEST_BUILD_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lldb-test-build.noindex" CACHE PATH "The build root for building tests.")
7475

7576
# Set the path to the default lldb test executable.
7677
set(LLDB_DEFAULT_TEST_EXECUTABLE "${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb${CMAKE_EXECUTABLE_SUFFIX}")

lldb/lit/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ endif()
1515
get_property(LLDB_DOTEST_ARGS GLOBAL PROPERTY LLDB_DOTEST_ARGS_PROPERTY)
1616
set(dotest_args_replacement ${LLVM_BUILD_MODE})
1717

18+
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.")
19+
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.")
20+
1821
if(LLDB_BUILT_STANDALONE)
1922
# In paths to our build-tree, replace CMAKE_CFG_INTDIR with our configuration name placeholder.
2023
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} config_runtime_output_dir ${LLVM_RUNTIME_OUTPUT_INTDIR})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This is a sanity check that verifies that the module cache path is set
2+
# correctly and points inside the default test build directory.
3+
RUN: %lldb -o 'settings show symbols.clang-modules-cache-path' | FileCheck %s
4+
CHECK: lldb-test-build.noindex{{.*}}module-cache-lldb

lldb/lit/Suite/lit.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ if config.dotest_lit_args_str:
6969
if config.llvm_libs_dir:
7070
dotest_cmd += ['--env', 'LLVM_LIBS_DIR=' + config.llvm_libs_dir]
7171

72+
if config.lldb_build_directory:
73+
dotest_cmd += ['--build-dir', config.lldb_build_directory]
74+
75+
if config.lldb_module_cache:
76+
dotest_cmd += ['--module-cache-dir', config.lldb_module_cache]
77+
7278
# Load LLDB test format.
7379
sys.path.append(os.path.join(config.lldb_src_root, "lit", "Suite"))
7480
import lldbtest

lldb/lit/Suite/lit.site.cfg.in

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ config.host_os = "@HOST_OS@"
1515
config.host_triple = "@LLVM_HOST_TRIPLE@"
1616
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
1717
config.target_triple = "@TARGET_TRIPLE@"
18+
config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
19+
config.lldb_module_cache = "@LLDB_TEST_MODULE_CACHE_LLDB@"
20+
config.clang_module_cache = "@LLDB_TEST_MODULE_CACHE_CLANG@"
1821
config.python_executable = "@PYTHON_EXECUTABLE@"
1922
config.dotest_path = "@LLDB_SOURCE_DIR@/test/dotest.py"
2023
config.dotest_args_str = "@LLDB_DOTEST_ARGS@"

lldb/lit/helper/toolchain.py

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ def use_support_substitutions(config):
104104
flags += ['-L' + config.llvm_libs_dir,
105105
'-Wl,-rpath,' + config.llvm_libs_dir]
106106

107+
# The clang module cache is used for building inferiors.
108+
flags += ['-fmodules-cache-path={}'.format(config.clang_module_cache)]
109+
107110
additional_tool_dirs=[]
108111
if config.lldb_lit_tools_dir:
109112
additional_tool_dirs.append(config.lldb_lit_tools_dir)

lldb/lit/lit-lldb-init.in

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
settings set symbols.enable-external-lookup false
33
settings set plugin.process.gdb-remote.packet-timeout 60
44
settings set interpreter.echo-comment-commands false
5+
settings set symbols.clang-modules-cache-path "@LLDB_TEST_MODULE_CACHE_LLDB@"

lldb/lit/lit.cfg.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,10 @@ def calculate_arch_features(arch_string):
6464
('--targets-built', calculate_arch_features)
6565
])
6666

67-
# Clean the module caches in the test build directory. This is
68-
# necessary in an incremental build whenever clang changes underneath,
69-
# so doing it once per lit.py invocation is close enough.
70-
71-
for i in ['module-cache-clang', 'module-cache-lldb']:
72-
cachedir = os.path.join(config.lldb_libs_dir, '..',
73-
'lldb-test-build.noindex', i)
67+
# Clean the module caches in the test build directory. This is necessary in an
68+
# incremental build whenever clang changes underneath, so doing it once per
69+
# lit.py invocation is close enough.
70+
for cachedir in [config.clang_module_cache, config.lldb_module_cache]:
7471
if os.path.isdir(cachedir):
7572
print("Deleting module cache at %s."%cachedir)
7673
shutil.rmtree(cachedir)

lldb/lit/lit.site.cfg.py.in

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ config.have_zlib = @LLVM_ENABLE_ZLIB@
1818
config.host_triple = "@LLVM_HOST_TRIPLE@"
1919
config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
2020
config.lldb_disable_python = @LLDB_DISABLE_PYTHON@
21+
config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
22+
config.lldb_module_cache = "@LLDB_TEST_MODULE_CACHE_LLDB@"
23+
config.clang_module_cache = "@LLDB_TEST_MODULE_CACHE_CLANG@"
2124

2225
# Support substitution of the tools and libs dirs with user parameters. This is
2326
# used when we can't determine the tool dir at configuration time.

lldb/packages/Python/lldbsuite/test/configuration.py

+3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106
# The base directory in which the tests are being built.
107107
test_build_dir = None
108108

109+
# The clang module cache directory used by lldb.
110+
module_cache_dir = None
111+
109112
# The only directory to scan for tests. If multiple test directories are
110113
# specified, and an exclusive test subdirectory is specified, the latter option
111114
# takes precedence.

lldb/packages/Python/lldbsuite/test/dotest.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_dotest_invocation():
5555
def is_exe(fpath):
5656
"""Returns true if fpath is an executable."""
5757
if fpath == None:
58-
return False
58+
return False
5959
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
6060

6161

@@ -274,10 +274,10 @@ def parseOptionsAndInitTestdirs():
274274
break
275275

276276
if args.dsymutil:
277-
os.environ['DSYMUTIL'] = args.dsymutil
277+
os.environ['DSYMUTIL'] = args.dsymutil
278278
elif platform_system == 'Darwin':
279-
os.environ['DSYMUTIL'] = seven.get_command_output(
280-
'xcrun -find -toolchain default dsymutil')
279+
os.environ['DSYMUTIL'] = seven.get_command_output(
280+
'xcrun -find -toolchain default dsymutil')
281281

282282
if args.filecheck:
283283
# The lldb-dotest script produced by the CMake build passes in a path
@@ -426,6 +426,11 @@ def parseOptionsAndInitTestdirs():
426426
configuration.lldb_platform_working_dir = args.lldb_platform_working_dir
427427
if args.test_build_dir:
428428
configuration.test_build_dir = args.test_build_dir
429+
if args.module_cache_dir:
430+
configuration.module_cache_dir = args.module_cache_dir
431+
else:
432+
configuration.module_cache_dir = os.path.join(configuration.test_build_dir,
433+
'module-cache-lldb')
429434

430435
# Gather all the dirs passed on the command line.
431436
if len(args.args) > 0:
@@ -869,16 +874,16 @@ def canRunWatchpointTests():
869874

870875
platform = lldbplatformutil.getPlatform()
871876
if platform == "netbsd":
872-
if os.geteuid() == 0:
873-
return True, "root can always write dbregs"
874-
try:
875-
output = subprocess.check_output(["/sbin/sysctl", "-n",
876-
"security.models.extensions.user_set_dbregs"]).decode().strip()
877-
if output == "1":
878-
return True, "security.models.extensions.user_set_dbregs enabled"
879-
except subprocess.CalledProcessError:
880-
pass
881-
return False, "security.models.extensions.user_set_dbregs disabled"
877+
if os.geteuid() == 0:
878+
return True, "root can always write dbregs"
879+
try:
880+
output = subprocess.check_output(["/sbin/sysctl", "-n",
881+
"security.models.extensions.user_set_dbregs"]).decode().strip()
882+
if output == "1":
883+
return True, "security.models.extensions.user_set_dbregs enabled"
884+
except subprocess.CalledProcessError:
885+
pass
886+
return False, "security.models.extensions.user_set_dbregs disabled"
882887
return True, "watchpoint support available"
883888

884889
def checkWatchpointSupport():

lldb/packages/Python/lldbsuite/test/dotest_args.py

+5
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ def create_parser():
147147
metavar='Test build directory',
148148
default='lldb-test-build.noindex',
149149
help='The root build directory for the tests. It will be removed before running.')
150+
group.add_argument(
151+
'--module-cache-dir',
152+
dest='module_cache_dir',
153+
metavar='The clang module cache directory used by LLDB',
154+
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.')
150155

151156
# Configuration options
152157
group = parser.add_argument_group('Remote platform options')

lldb/packages/Python/lldbsuite/test/lldbtest.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1852,9 +1852,9 @@ def setUp(self):
18521852
Base.setUp(self)
18531853

18541854
# Set the clang modules cache path used by LLDB.
1855-
mod_cache = os.path.join(os.environ["LLDB_BUILD"], "module-cache-lldb")
1856-
self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
1857-
% mod_cache)
1855+
self.runCmd(
1856+
'settings set symbols.clang-modules-cache-path "{}"'.format(
1857+
configuration.module_cache_dir))
18581858

18591859
for s in self.setUpCommands():
18601860
self.runCmd(s)
@@ -2058,13 +2058,13 @@ def runCmd(self, cmd, msg=None, check=True, trace=False, inHistory=False):
20582058
if check:
20592059
output = ""
20602060
if self.res.GetOutput():
2061-
output += "\nCommand output:\n" + self.res.GetOutput()
2061+
output += "\nCommand output:\n" + self.res.GetOutput()
20622062
if self.res.GetError():
2063-
output += "\nError output:\n" + self.res.GetError()
2063+
output += "\nError output:\n" + self.res.GetError()
20642064
if msg:
2065-
msg += output
2065+
msg += output
20662066
if cmd:
2067-
cmd += output
2067+
cmd += output
20682068
self.assertTrue(self.res.Succeeded(),
20692069
msg if (msg) else CMD_MSG(cmd))
20702070

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
This is a sanity check that verifies that the module cache path is set
3+
correctly and points inside the default test build directory.
4+
"""
5+
6+
from __future__ import print_function
7+
8+
import lldb
9+
import lldbsuite.test.lldbutil as lldbutil
10+
from lldbsuite.test.lldbtest import *
11+
12+
13+
class ModuleCacheSanityTestCase(TestBase):
14+
15+
mydir = TestBase.compute_mydir(__file__)
16+
17+
NO_DEBUG_INFO_TESTCASE = True
18+
19+
def test(self):
20+
self.expect(
21+
'settings show symbols.clang-modules-cache-path',
22+
substrs=['lldb-test-build.noindex', 'module-cache-lldb'])

lldb/test/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ set(LLDB_TEST_COMMON_ARGS
3939
--arch=${LLDB_TEST_ARCH}
4040
-s
4141
${CMAKE_BINARY_DIR}/lldb-test-traces
42-
--build-dir
43-
${CMAKE_BINARY_DIR}/lldb-test-build.noindex
4442
-S nm
4543
-u CXXFLAGS
4644
-u CFLAGS

lldb/utils/lldb-dotest/lldb-dotest.in

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import subprocess
33
import sys
44

55
dotest_path = '@LLDB_SOURCE_DIR@/test/dotest.py'
6+
build_dir = '@LLDB_TEST_BUILD_DIRECTORY@'
67
dotest_args_str = '@LLDB_DOTEST_ARGS@'
78

89
if __name__ == '__main__':
@@ -11,6 +12,7 @@ if __name__ == '__main__':
1112
# Build dotest.py command.
1213
cmd = [sys.executable, dotest_path]
1314
cmd.extend(dotest_args)
15+
cmd.extend(['--build-dir', build_dir])
1416
cmd.extend(wrapper_args)
1517
# Invoke dotest.py and return exit code.
1618
print(' '.join(cmd))

0 commit comments

Comments
 (0)