hanchenye-llvm-project/lldb/test/CMakeLists.txt

139 lines
4.6 KiB
CMake
Raw Normal View History

function(add_python_test_target name test_script args comment)
set(PYTHON_TEST_COMMAND
${PYTHON_EXECUTABLE}
${test_script}
${args}
)
add_custom_target(${name}
COMMAND ${PYTHON_TEST_COMMAND} ${ARG_DEFAULT_ARGS}
COMMENT "${comment}"
DEPENDS ${LLDB_TEST_DEPS}
USES_TERMINAL
)
endfunction()
# The default architecture with which to compile test executables is the default LLVM target
# architecture, which itself defaults to the host architecture.
string(TOLOWER "${LLVM_TARGET_ARCH}" LLDB_DEFAULT_TEST_ARCH)
if( LLDB_DEFAULT_TEST_ARCH STREQUAL "host" )
string(REGEX MATCH "^[^-]*" LLDB_DEFAULT_TEST_ARCH ${LLVM_HOST_TRIPLE})
endif ()
# Allow the user to override the default by setting LLDB_TEST_ARCH
set(LLDB_TEST_ARCH
${LLDB_DEFAULT_TEST_ARCH}
CACHE STRING "Specify the architecture to run LLDB tests as (x86|x64). Determines whether tests are compiled with -m32 or -m64")
# Users can override LLDB_TEST_USER_ARGS to specify arbitrary arguments to pass to the script
set(LLDB_TEST_USER_ARGS
""
CACHE STRING "Specify additional arguments to pass to test runner. For example: '-C gcc -C clang -A i386 -A x86_64'")
2018-08-28 05:46:18 +08:00
# The .noindex suffix is a marker for Spotlight to never index the
# build directory. LLDB queries Spotlight to locate .dSYM bundles
# based on the UUID embedded in a binary, and because the UUID is a
# hash of filename and .text section, there *will* be conflicts inside
# the build directory.
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
)
list(APPEND LLDB_TEST_COMMON_ARGS
--executable ${LLDB_TEST_EXECUTABLE}
--dsymutil ${LLDB_TEST_DSYMUTIL}
--filecheck ${LLDB_TEST_FILECHECK}
-C ${LLDB_TEST_C_COMPILER}
)
if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
# All tests are currently flaky on Windows, so rerun them all once when they fail.
set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --rerun-all-issues)
set(LLDB_TEST_DEBUG_TEST_CRASHES
0
CACHE BOOL "(Windows only) Enables debugging of tests in the test suite by showing the crash dialog when lldb crashes")
set(LLDB_TEST_HIDE_CONSOLE_WINDOWS
1
CACHE BOOL "(Windows only) Hides the console window for an inferior when it is launched through the test suite")
if (LLDB_TEST_DEBUG_TEST_CRASHES)
set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --enable-crash-dialog)
endif()
if (NOT LLDB_TEST_HIDE_CONSOLE_WINDOWS)
set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --show-inferior-console)
endif()
endif()
if(LLDB_CODESIGN_IDENTITY)
list(APPEND LLDB_TEST_COMMON_ARGS --codesign-identity "${LLDB_CODESIGN_IDENTITY}")
endif()
if(LLDB_BUILD_FRAMEWORK)
list(APPEND LLDB_TEST_COMMON_ARGS --framework ${LLDB_FRAMEWORK_DIR}/LLDB.framework)
endif()
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows|Darwin")
list(APPEND LLDB_TEST_COMMON_ARGS
--env ARCHIVER=${CMAKE_AR} --env OBJCOPY=${CMAKE_OBJCOPY})
endif()
Fix some issues with LLDB's lit configuration files. Recently I tried to port LLDB's lit configuration files over to use a on the surface, but broke some cases that weren't broken before and also exposed some additional problems with the old approach that we were just getting lucky with. When we set up a lit environment, the goal is to make it as hermetic as possible. We should not be relying on PATH and enabling the use of arbitrary shell commands. Instead, only whitelisted commands should be allowed. These are, generally speaking, the lit builtins such as echo, cd, etc, as well as anything for which substitutions have been explicitly set up for. These substitutions should map to the build output directory, but in some cases it's useful to be able to override this (for example to point to an installed tools directory). This is, of course, how it's supposed to work. What was actually happening is that we were bringing in PATH and LD_LIBRARY_PATH and then just running the given run line as a shell command. This led to problems such as finding the wrong version of clang-cl on PATH since it wasn't even a substitution, and flakiness / non-determinism since the environment the tests were running in would change per-machine. On the other hand, it also made other things possible. For example, we had some tests that were explicitly running cl.exe and link.exe instead of clang-cl and lld-link and the only reason it worked at all is because it was finding them on PATH. Unfortunately we can't entirely get rid of these tests, because they support a few things in debug info that clang-cl and lld-link don't (notably, the LF_UDT_MOD_SRC_LINE record which makes some of the tests fail. The high level changes introduced in this patch are: 1. Removal of functionality - The lit test suite no longer respects LLDB_TEST_C_COMPILER and LLDB_TEST_CXX_COMPILER. This means there is no more support for gcc, but nobody was using this anyway (note: The functionality is still there for the dotest suite, just not the lit test suite). There is no longer a single substitution %cxx and %cc which maps to <arbitrary-compiler>, you now explicitly specify the compiler with a substitution like %clang or %clangxx or %clang_cl. We can revisit this in the future when someone needs gcc. 2. Introduction of the LLDB_LIT_TOOLS_DIR directory. This does in spirit what LLDB_TEST_C_COMPILER and LLDB_TEST_CXX_COMPILER used to do, but now more friendly. If this is not specified, all tools are expected to be the just-built tools. If it is specified, the tools which are not themselves being tested but are being used to construct and run checks (e.g. clang, FileCheck, llvm-mc, etc) will be searched for in this directory first, then the build output directory. 3. Changes to core llvm lit files. The use_lld() and use_clang() functions were introduced long ago in anticipation of using them in lldb, but since they were never actually used anywhere but their respective problems, there were some issues to be resolved regarding generality and ability to use them outside their project. 4. Changes to .test files - These are all just replacing things like clang-cl with %clang_cl and %cxx with %clangxx, etc. 5. Changes to lit.cfg.py - Previously we would load up some system environment variables and then add some new things to them. Then do a bunch of work building out our own substitutions. First, we delete the system environment variable code, making the environment hermetic. Then, we refactor the substitution logic into two separate helper functions, one which sets up substitutions for the tools we want to test (which must come from the build output directory), and another which sets up substitutions for support tools (like compilers, etc). 6. New substitutions for MSVC -- Previously we relied on location of MSVC by bringing in the entire parent's PATH and letting subprocess.Popen just run the command line. Now we set up real substitutions that should have the same effect. We use PATH to find them, and then look for INCLUDE and LIB to construct a substitution command line with appropriate /I and /LIBPATH: arguments. The nice thing about this is that it opens the door to having separate %msvc-cl32 and %msvc-cl64 substitutions, rather than only requiring the user to run vcvars first. Because we can deduce the path to 32-bit libraries from 64-bit library directories, and vice versa. Without these substitutions this would have been impossible. Differential Revision: https://reviews.llvm.org/D54567 llvm-svn: 347216
2018-11-19 23:12:34 +08:00
if (NOT "${LLDB_LIT_TOOLS_DIR}" STREQUAL "")
if (NOT EXISTS "${LLDB_LIT_TOOLS_DIR}")
message(WARNING "LLDB_LIT_TOOLS_DIR ${LLDB_LIT_TOOLS_DIR} does not exist.")
endif()
endif()
if(CMAKE_HOST_APPLE AND DEBUGSERVER_PATH)
list(APPEND LLDB_TEST_COMMON_ARGS --server ${DEBUGSERVER_PATH})
endif()
if(SKIP_TEST_DEBUGSERVER)
list(APPEND LLDB_TEST_COMMON_ARGS --out-of-tree-debugserver)
endif()
set(LLDB_DOTEST_ARGS ${LLDB_TEST_COMMON_ARGS};${LLDB_TEST_USER_ARGS})
set_property(GLOBAL PROPERTY LLDB_DOTEST_ARGS_PROPERTY ${LLDB_DOTEST_ARGS})
add_python_test_target(check-lldb-single
${LLDB_SOURCE_DIR}/test/dotest.py
"--no-multiprocess;${LLDB_DOTEST_ARGS}"
"Testing LLDB with args: ${LLDB_DOTEST_ARGS}"
)
# If tests crash cause LLDB to crash, or things are otherwise unstable, or if machine-parsable
# output is desired (i.e. in continuous integration contexts) check-lldb-single is a better target.
add_custom_target(check-lldb)
# If we're building with an in-tree clang, then list clang as a dependency
# to run tests.
if (TARGET clang)
add_dependencies(check-lldb clang)
endif()
# LLD is required to link test executables on Windows.
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
if (TARGET lld)
add_dependencies(check-lldb lld)
else ()
message(WARNING "lld required to test LLDB on Windows")
endif ()
endif ()
# Run the lit-style tests and the unittests as part of the check-lldb target.
add_dependencies(check-lldb check-lldb-lit)
add_custom_target(lldb-test-depends DEPENDS ${LLDB_TEST_DEPENDS})
2018-11-17 00:19:08 +08:00
# This will add LLDB's test dependencies to the dependencies for check-all and
# include them in the test-depends target.
set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS})