Skip to content

Commit bb26ebb

Browse files
[lldb] Fix dotest argument order
When running LLDB API tests, a user can override test arguments with LLDB_TEST_USER_ARGS. However, these flags used to be concatenated with a CMake-derived variable LLDB_TEST_COMMON_ARGS, as below: ``` set(LLDB_DOTEST_ARGS ${LLDB_TEST_COMMON_ARGS};${LLDB_TEST_USER_ARGS} CACHE INTERNAL STRING) ``` This is problematic, because LLDB_TEST_COMMON_ARGS must be processed first, while LLDB_TEST_USER_ARGS args must be processed last, so that user overrides are respected. Currently, if a user attempts to override one of the "inferred" flags, the user's request is ignored. This is the case, for example, with `--libcxx-include-dir` and `--libcxx-library-dir`. Both flags are needed by the greendragon bots. This commit removes the concatenation above, keeping the two original variables throughout the entire flow, processing the user's flag last. The variable LLDB_TEST_COMMON_ARGS needs to be a CACHE property, but it is modified throughout the CMake file with `set` or `list` or `string` commands, which don't work with properties. As such, a temporary variable `LLDB_TEST_COMMON_ARGS_VAR` is created. This was tested locally by invoking CMake with: -DLLDB_TEST_USER_ARGS="--libcxx-include-dir=blah --libcxx-library-dir=blah2" and checking that tests failed appropriately. Differential Revision: https://reviews.llvm.org/D132642
1 parent 88c7b16 commit bb26ebb

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

lldb/test/API/CMakeLists.txt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ set(LLDB_TEST_USER_ARGS
3737
""
3838
CACHE STRING "Specify additional arguments to pass to test runner. For example: '-C gcc -C clang -A i386 -A x86_64'")
3939

40-
set(LLDB_TEST_COMMON_ARGS
40+
set(LLDB_TEST_COMMON_ARGS_VAR
4141
-u CXXFLAGS
4242
-u CFLAGS
4343
)
@@ -71,16 +71,16 @@ if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
7171
CACHE BOOL "(Windows only) Hides the console window for an inferior when it is launched through the test suite")
7272

7373
if (LLDB_TEST_DEBUG_TEST_CRASHES)
74-
set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --enable-crash-dialog)
74+
set(LLDB_TEST_COMMON_ARGS_VAR ${LLDB_TEST_COMMON_ARGS_VAR} --enable-crash-dialog)
7575
endif()
7676

7777
if (NOT LLDB_TEST_HIDE_CONSOLE_WINDOWS)
78-
set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --show-inferior-console)
78+
set(LLDB_TEST_COMMON_ARGS_VAR ${LLDB_TEST_COMMON_ARGS_VAR} --show-inferior-console)
7979
endif()
8080
endif()
8181

8282
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows|Darwin")
83-
list(APPEND LLDB_TEST_COMMON_ARGS
83+
list(APPEND LLDB_TEST_COMMON_ARGS_VAR
8484
--env ARCHIVER=${CMAKE_AR} --env OBJCOPY=${CMAKE_OBJCOPY})
8585
endif()
8686

@@ -98,7 +98,7 @@ if(CMAKE_HOST_APPLE)
9898
# Use the same identity for testing
9999
get_property(code_sign_identity_used GLOBAL PROPERTY LLDB_DEBUGSERVER_CODESIGN_IDENTITY)
100100
if(code_sign_identity_used)
101-
list(APPEND LLDB_TEST_COMMON_ARGS --codesign-identity "${code_sign_identity_used}")
101+
list(APPEND LLDB_TEST_COMMON_ARGS_VAR --codesign-identity "${code_sign_identity_used}")
102102
endif()
103103

104104
if(LLDB_USE_SYSTEM_DEBUGSERVER)
@@ -115,20 +115,20 @@ if(CMAKE_HOST_APPLE)
115115
COMMENT "Copying the system debugserver to LLDB's binaries directory for testing.")
116116
endif()
117117
message(STATUS "LLDB tests use out-of-tree debugserver: ${system_debugserver_path}")
118-
list(APPEND LLDB_TEST_COMMON_ARGS --out-of-tree-debugserver)
118+
list(APPEND LLDB_TEST_COMMON_ARGS_VAR --out-of-tree-debugserver)
119119
add_lldb_test_dependency(debugserver)
120120
else()
121121
message(STATUS "LLDB tests use just-built debug server")
122122
endif()
123123
endif()
124124

125-
set(LLDB_DOTEST_ARGS ${LLDB_TEST_COMMON_ARGS};${LLDB_TEST_USER_ARGS} CACHE INTERNAL STRING)
126125
set(dotest_args_replacement ${LLVM_BUILD_MODE})
127126

128127
if(LLDB_BUILT_STANDALONE)
129128
# In paths to our build-tree, replace CMAKE_CFG_INTDIR with our configuration name placeholder.
130129
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} config_runtime_output_dir ${LLVM_RUNTIME_OUTPUT_INTDIR})
131-
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}")
130+
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_COMMON_ARGS_VAR "${LLDB_TEST_COMMON_ARGS_VAR}")
131+
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_USER_ARGS "${LLDB_TEST_USER_ARGS}")
132132
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_SOURCE_DIR "${LLDB_SOURCE_DIR}")
133133
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_FRAMEWORK_DIR "${LLDB_FRAMEWORK_DIR}")
134134
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_BUILD_DIRECTORY "${LLDB_TEST_BUILD_DIRECTORY}")
@@ -155,13 +155,16 @@ if(LLDB_BUILT_STANDALONE)
155155
endif()
156156
endif()
157157

158-
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}")
158+
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_COMMON_ARGS_VAR "${LLDB_TEST_COMMON_ARGS_VAR}")
159+
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_USER_ARGS "${LLDB_TEST_USER_ARGS}")
159160
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_SOURCE_DIR "${LLDB_SOURCE_DIR}")
160161
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_BUILD_DIRECTORY "${LLDB_TEST_BUILD_DIRECTORY}")
161162
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}")
162163
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}")
163164
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}")
164165

166+
set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS_VAR} CACHE INTERNAL STRING)
167+
165168
configure_lit_site_cfg(
166169
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
167170
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py

lldb/test/API/lit.cfg.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def delete_module_cache(path):
155155
# Build dotest command.
156156
dotest_cmd = [os.path.join(config.lldb_src_root, 'test', 'API', 'dotest.py')]
157157

158-
if is_configured('dotest_args_str'):
159-
dotest_cmd.extend(config.dotest_args_str.split(';'))
158+
if is_configured('dotest_common_args_str'):
159+
dotest_cmd.extend(config.dotest_common_args_str.split(';'))
160160

161161
# Library path may be needed to locate just-built clang and libcxx.
162162
if is_configured('llvm_libs_dir'):
@@ -235,6 +235,20 @@ def delete_module_cache(path):
235235
for plugin in config.enabled_plugins:
236236
dotest_cmd += ['--enable-plugin', plugin]
237237

238+
# `dotest` args come from three different sources:
239+
# 1. Derived by CMake based on its configs (LLDB_TEST_COMMON_ARGS), which end
240+
# up in `dotest_common_args_str`.
241+
# 2. CMake user parameters (LLDB_TEST_USER_ARGS), which end up in
242+
# `dotest_user_args_str`.
243+
# 3. With `llvm-lit "--param=dotest-args=..."`, which end up in
244+
# `dotest_lit_args_str`.
245+
# Check them in this order, so that more specific overrides are visited last.
246+
# In particular, (1) is visited at the top of the file, since the script
247+
# derives other information from it.
248+
249+
if is_configured('dotest_user_args_str'):
250+
dotest_cmd.extend(config.dotest_user_args_str.split(';'))
251+
238252
if is_configured('dotest_lit_args_str'):
239253
# We don't want to force users passing arguments to lit to use `;` as a
240254
# separator. We use Python's simple lexical analyzer to turn the args into a

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
2222
config.python_executable = "@Python3_EXECUTABLE@"
2323
config.lua_executable = "@Lua_EXECUTABLE@"
2424
config.lua_test_entry = "TestLuaAPI.py"
25-
config.dotest_args_str = lit_config.substitute("@LLDB_DOTEST_ARGS@")
25+
config.dotest_common_args_str = lit_config.substitute("@LLDB_TEST_COMMON_ARGS@")
26+
config.dotest_user_args_str = lit_config.substitute("@LLDB_TEST_USER_ARGS@")
2627
config.lldb_enable_python = @LLDB_ENABLE_PYTHON@
2728
config.dotest_lit_args_str = None
2829
config.enabled_plugins = []

lldb/utils/lldb-dotest/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ add_custom_target(lldb-dotest)
33
add_dependencies(lldb-dotest lldb-test-depends)
44
set_target_properties(lldb-dotest PROPERTIES FOLDER "lldb utils")
55

6-
get_property(LLDB_DOTEST_ARGS GLOBAL PROPERTY LLDB_DOTEST_ARGS_PROPERTY)
6+
get_property(LLDB_TEST_USER_ARGS GLOBAL PROPERTY LLDB_TEST_USER_ARGS_PROPERTY)
7+
get_property(LLDB_TEST_COMMON_ARGS GLOBAL PROPERTY LLDB_TEST_COMMON_ARGS_PROPERTY)
78
set(LLDB_LIBS_DIR "${LLVM_LIBRARY_OUTPUT_INTDIR}")
89

910
llvm_canonicalize_cmake_booleans(
@@ -12,7 +13,8 @@ llvm_canonicalize_cmake_booleans(
1213

1314
set(LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}")
1415
set(vars
15-
LLDB_DOTEST_ARGS
16+
LLDB_TEST_COMMON_ARGS
17+
LLDB_TEST_USER_ARGS
1618
LLDB_SOURCE_DIR
1719
LLDB_FRAMEWORK_DIR
1820
LLDB_TEST_BUILD_DIRECTORY

0 commit comments

Comments
 (0)