Move MSan lit-tests under test/msan

llvm-svn: 201412
This commit is contained in:
Alexey Samsonov 2014-02-14 13:02:58 +00:00
parent 0de2b9b1e2
commit 8434e60f7e
90 changed files with 82 additions and 130 deletions

View File

@ -233,6 +233,7 @@ filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
x86_64 i386 powerpc64 arm)
filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64)
filter_available_targets(LSAN_SUPPORTED_ARCH x86_64)
filter_available_targets(MSAN_SUPPORTED_ARCH x86_64)
filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386)
add_subdirectory(include)
@ -248,6 +249,13 @@ if (NOT ANDROID)
endif()
endif()
set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx)
if(EXISTS ${COMPILER_RT_LIBCXX_PATH}/)
set(COMPILER_RT_HAS_LIBCXX_SOURCES TRUE)
else()
set(COMPILER_RT_HAS_LIBCXX_SOURCES FALSE)
endif()
add_subdirectory(lib)
if(LLVM_INCLUDE_TESTS)

View File

@ -17,7 +17,7 @@ set(MSAN_RTL_CFLAGS
-ffreestanding)
# Static runtime library.
set(MSAN_RUNTIME_LIBRARIES)
add_custom_target(msan)
set(arch "x86_64")
if(CAN_TARGET_${arch})
add_compiler_rt_static_runtime(clang_rt.msan-${arch} ${arch}
@ -26,25 +26,16 @@ if(CAN_TARGET_${arch})
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
CFLAGS ${MSAN_RTL_CFLAGS})
list(APPEND MSAN_RUNTIME_LIBRARIES clang_rt.msan-${arch})
add_dependencies(msan clang_rt.msan-${arch})
if(UNIX)
add_sanitizer_rt_symbols(clang_rt.msan-${arch} msan.syms.extra)
list(APPEND MSAN_RUNTIME_LIBRARIES clang_rt.msan-${arch}-symbols)
add_dependencies(msan clang_rt.msan-${arch}-symbols)
endif()
endif()
add_compiler_rt_resource_file(msan_blacklist msan_blacklist.txt)
# We should only build MSan unit tests if we can build instrumented libcxx.
set(MSAN_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx)
if(EXISTS ${MSAN_LIBCXX_PATH}/)
set(MSAN_CAN_INSTRUMENT_LIBCXX TRUE)
else()
set(MSAN_CAN_INSTRUMENT_LIBCXX FALSE)
endif()
add_dependencies(msan msan_blacklist)
if(LLVM_INCLUDE_TESTS)
add_subdirectory(tests)
endif()
add_subdirectory(lit_tests)

View File

@ -1,31 +0,0 @@
set(MSAN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(MSAN_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/..)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
if(MSAN_CAN_INSTRUMENT_LIBCXX)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg)
endif()
if(COMPILER_RT_CAN_EXECUTE_TESTS AND CAN_TARGET_x86_64)
# Run MSan tests only if we're sure we may produce working binaries.
set(MSAN_TEST_DEPS
${SANITIZER_COMMON_LIT_TEST_DEPS}
${MSAN_RUNTIME_LIBRARIES}
msan_blacklist)
set(MSAN_TEST_PARAMS
msan_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
if(LLVM_INCLUDE_TESTS AND MSAN_CAN_INSTRUMENT_LIBCXX)
list(APPEND MSAN_TEST_DEPS MsanUnitTests)
endif()
add_lit_testsuite(check-msan "Running the MemorySanitizer tests"
${CMAKE_CURRENT_BINARY_DIR}
PARAMS ${MSAN_TEST_PARAMS}
DEPENDS ${MSAN_TEST_DEPS}
)
set_target_properties(check-msan PROPERTIES FOLDER "MSan tests")
endif()

View File

@ -1,74 +0,0 @@
# -*- Python -*-
import os
import lit.util
def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if not attr_value:
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
"to lit.site.cfg " % attr_name)
return attr_value
# Setup config name.
config.name = 'MemorySanitizer'
# Setup source root.
config.test_source_root = os.path.dirname(__file__)
def DisplayNoConfigMessage():
lit_config.fatal("No site specific configuration available! " +
"Try running your test from the build tree or running " +
"make check-msan")
# Figure out LLVM source root.
llvm_src_root = getattr(config, 'llvm_src_root', None)
if llvm_src_root is None:
# We probably haven't loaded the site-specific configuration: the user
# is likely trying to run a test file directly, and the site configuration
# wasn't created by the build system.
msan_site_cfg = lit_config.params.get('msan_site_config', None)
if (msan_site_cfg) and (os.path.exists(msan_site_cfg)):
lit_config.load_config(config, msan_site_cfg)
raise SystemExit
# Try to guess the location of site-specific configuration using llvm-config
# util that can point where the build tree is.
llvm_config = lit.util.which("llvm-config", config.environment["PATH"])
if not llvm_config:
DisplayNoConfigMessage()
# Find out the presumed location of generated site config.
llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
msan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
"lib", "msan", "lit_tests", "lit.site.cfg")
if (not msan_site_cfg) or (not os.path.exists(msan_site_cfg)):
DisplayNoConfigMessage()
lit_config.load_config(config, msan_site_cfg)
raise SystemExit
# Setup default compiler flags used with -fsanitize=memory option.
clang_msan_cflags = ["-fsanitize=memory",
"-mno-omit-leaf-frame-pointer",
"-fno-omit-frame-pointer",
"-fno-optimize-sibling-calls",
"-g",
"-m64"]
clang_msan_cxxflags = ["--driver-mode=g++ "] + clang_msan_cflags
config.substitutions.append( ("%clang_msan ",
" ".join([config.clang] + clang_msan_cflags) +
" ") )
config.substitutions.append( ("%clangxx_msan ",
" ".join([config.clang] + clang_msan_cxxflags) +
" ") )
# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']
# MemorySanitizer tests are currently supported on Linux only.
if config.host_os not in ['Linux']:
config.unsupported = True

View File

@ -6,9 +6,9 @@ include_directories(..)
include_directories(../..)
# Instrumented libcxx sources and build flags.
file(GLOB MSAN_LIBCXX_SOURCES ${MSAN_LIBCXX_PATH}/src/*.cpp)
file(GLOB MSAN_LIBCXX_SOURCES ${COMPILER_RT_LIBCXX_PATH}/src/*.cpp)
set(MSAN_LIBCXX_CFLAGS
-I${MSAN_LIBCXX_PATH}/include
-I${COMPILER_RT_LIBCXX_PATH}/include
-fsanitize=memory
-fsanitize-memory-track-origins
-fPIC
@ -39,7 +39,7 @@ set(MSAN_UNITTEST_HEADERS
)
set(MSANDR_UNITTEST_SOURCE msandr_test_so.cc)
set(MSAN_UNITTEST_COMMON_CFLAGS
-I${MSAN_LIBCXX_PATH}/include
-I${COMPILER_RT_LIBCXX_PATH}/include
${COMPILER_RT_GTEST_INCLUDE_CFLAGS}
-I${COMPILER_RT_SOURCE_DIR}/include
-I${COMPILER_RT_SOURCE_DIR}/lib
@ -78,7 +78,7 @@ macro(msan_compile obj_list source arch)
get_target_flags_for_arch(${arch} TARGET_CFLAGS)
clang_compile(${output_obj} ${source}
CFLAGS ${ARGN} ${TARGET_CFLAGS}
DEPS gtest ${MSAN_RUNTIME_LIBRARIES} ${MSAN_UNITTEST_HEADERS})
DEPS gtest msan ${MSAN_UNITTEST_HEADERS})
list(APPEND ${obj_list} ${output_obj})
endmacro()
@ -99,7 +99,7 @@ macro(add_msan_test test_suite test_name arch)
get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
add_compiler_rt_test(${test_suite} ${test_name}
OBJECTS ${ARGN}
DEPS ${MSAN_RUNTIME_LIBRARIES} ${ARGN}
DEPS msan ${ARGN}
${MSAN_LOADABLE_SO}
LINK_FLAGS ${MSAN_UNITTEST_LINK_FLAGS}
${TARGET_LINK_FLAGS}
@ -128,7 +128,7 @@ macro(add_msan_tests_for_arch arch)
msan_link_shared(MSAN_INST_LIBCXX "libcxx" ${arch}
OBJECTS ${MSAN_INST_LIBCXX_OBJECTS}
LINKFLAGS ${MSAN_LIBCXX_LINK_FLAGS}
DEPS ${MSAN_INST_LIBCXX_OBJECTS} ${MSAN_RUNTIME_LIBRARIES})
DEPS ${MSAN_INST_LIBCXX_OBJECTS} msan)
# Instrumented tests.
set(MSAN_INST_TEST_OBJECTS)
@ -151,13 +151,13 @@ macro(add_msan_tests_for_arch arch)
set(MSAN_LOADABLE_SO)
msan_link_shared(MSAN_LOADABLE_SO "libmsan_loadable" ${arch}
OBJECTS ${MSAN_INST_LOADABLE_OBJECTS}
DEPS ${MSAN_INST_LOADABLE_OBJECTS} ${MSAN_RUNTIME_LIBRARIES})
DEPS ${MSAN_INST_LOADABLE_OBJECTS} msan)
# Uninstrumented shared library tests.
set(MSANDR_TEST_SO)
msan_link_shared(MSANDR_TEST_SO "libmsandr_test" ${arch}
OBJECTS ${MSANDR_TEST_OBJECTS}
DEPS ${MSANDR_TEST_OBJECTS} ${MSAN_RUNTIME_LIBRARIES})
DEPS ${MSANDR_TEST_OBJECTS} msan)
# Link everything together.
add_msan_test(MsanUnitTests "Msan-${arch}-Test" ${arch}
@ -165,7 +165,8 @@ macro(add_msan_tests_for_arch arch)
${MSAN_INST_LIBCXX} ${MSANDR_TEST_SO})
endmacro()
if(COMPILER_RT_CAN_EXECUTE_TESTS AND MSAN_CAN_INSTRUMENT_LIBCXX)
# We should only build MSan unit tests if we can build instrumented libcxx.
if(COMPILER_RT_CAN_EXECUTE_TESTS AND COMPILER_RT_HAS_LIBCXX_SOURCES)
if(CAN_TARGET_x86_64)
add_msan_tests_for_arch(x86_64)
endif()

View File

@ -15,6 +15,9 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS)
if(LSAN_SUPPORTED_ARCH)
add_subdirectory(lsan)
endif()
if(MSAN_SUPPORTED_ARCH)
add_subdirectory(msan)
endif()
if(UBSAN_SUPPORTED_ARCH)
add_subdirectory(ubsan)
endif()

View File

@ -10,7 +10,7 @@ configure_lit_site_cfg(
${CMAKE_CURRENT_BINARY_DIR}/AsanConfig/lit.site.cfg
)
if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT APPLE AND NOT ANDROID)
if(NOT APPLE AND NOT ANDROID)
set(LSAN_TEST_DEPS
${SANITIZER_COMMON_LIT_TEST_DEPS}
lsan

View File

@ -0,0 +1,22 @@
set(MSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
set(MSAN_TEST_DEPS
${SANITIZER_COMMON_LIT_TEST_DEPS}
msan)
if(LLVM_INCLUDE_TESTS AND COMPILER_RT_HAS_LIBCXX_SOURCES)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg)
list(APPEND MSAN_TEST_DEPS MsanUnitTests)
endif()
add_lit_testsuite(check-msan "Running the MemorySanitizer tests"
${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${MSAN_TEST_DEPS}
)
set_target_properties(check-msan PROPERTIES FOLDER "MSan tests")

View File

@ -9,5 +9,6 @@ config.name = 'MemorySanitizer-Unit'
# Setup test source and exec root. For unit tests, we define
# it as build directory with MSan unit tests.
config.test_exec_root = "@MSAN_BINARY_DIR@/tests"
# FIXME: Don't use hardcoded path to MSan unit tests.
config.test_exec_root = "@COMPILER_RT_BINARY_DIR@/lib/msan/tests"
config.test_source_root = config.test_exec_root

View File

@ -0,0 +1,31 @@
# -*- Python -*-
import os
# Setup config name.
config.name = 'MemorySanitizer'
# Setup source root.
config.test_source_root = os.path.dirname(__file__)
# Setup default compiler flags used with -fsanitize=memory option.
clang_msan_cflags = ["-fsanitize=memory",
"-mno-omit-leaf-frame-pointer",
"-fno-omit-frame-pointer",
"-fno-optimize-sibling-calls",
"-g",
"-m64"]
clang_msan_cxxflags = ["--driver-mode=g++ "] + clang_msan_cflags
config.substitutions.append( ("%clang_msan ",
" ".join([config.clang] + clang_msan_cflags) +
" ") )
config.substitutions.append( ("%clangxx_msan ",
" ".join([config.clang] + clang_msan_cxxflags) +
" ") )
# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']
# MemorySanitizer tests are currently supported on Linux only.
if config.host_os not in ['Linux']:
config.unsupported = True

View File

@ -2,4 +2,4 @@
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
# Load tool-specific config that would do the real work.
lit_config.load_config(config, "@MSAN_SOURCE_DIR@/lit_tests/lit.cfg")
lit_config.load_config(config, "@MSAN_LIT_SOURCE_DIR@/lit.cfg")