[UBSan] Make sure ASan and UBSan interact properly by running each test from UBSan test suite with and without ASan

llvm-svn: 194698
This commit is contained in:
Alexey Samsonov 2013-11-14 12:30:09 +00:00
parent 585813e33d
commit 164841036d
33 changed files with 105 additions and 80 deletions

View File

@ -0,0 +1,25 @@
# -*- Python -*-
import os
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
ubsan_lit_tests_dir = get_required_attr(config, "ubsan_lit_tests_dir")
ubsan_lit_cfg = os.path.join(ubsan_lit_tests_dir, "lit.common.cfg")
lit_config.load_config(config, ubsan_lit_cfg)
config.name = 'UndefinedBehaviorSanitizer-AddressSanitizer'
# Define %clang and %clangxx substitutions to use in test RUN lines.
config.substitutions.append( ("%clang ", (" " + config.clang +
" -fsanitize=address ")) )
config.substitutions.append( ("%clangxx ", (" " + config.clang +
" -fsanitize=address" +
" --driver-mode=g++ ")) )

View File

@ -0,0 +1,9 @@
# Load common config for all compiler-rt lit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/lib/lit.common.configured")
# Tool-specific config options.
config.ubsan_lit_tests_dir = "@UBSAN_LIT_TESTS_DIR@"
# Load tool-specific config that would do the real work.
print config.ubsan_lit_tests_dir
lit_config.load_config(config, "@UBSAN_LIT_TESTS_DIR@/AsanConfig/lit.cfg")

View File

@ -1,21 +1,23 @@
set(UBSAN_LIT_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
configure_lit_site_cfg( configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in ${CMAKE_CURRENT_SOURCE_DIR}/UbsanConfig/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg ${CMAKE_CURRENT_BINARY_DIR}/UbsanConfig/lit.site.cfg)
)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/AsanConfig/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/AsanConfig/lit.site.cfg)
if(COMPILER_RT_CAN_EXECUTE_TESTS) if(COMPILER_RT_CAN_EXECUTE_TESTS)
# Run UBSan output tests only if we're sure that clang would produce # Run UBSan output tests only if we're sure that clang would produce
# working binaries. # working binaries.
set(UBSAN_TEST_DEPS set(UBSAN_TEST_DEPS
${SANITIZER_COMMON_LIT_TEST_DEPS} ${SANITIZER_COMMON_LIT_TEST_DEPS}
${UBSAN_RUNTIME_LIBRARIES}) ${UBSAN_RUNTIME_LIBRARIES}
set(UBSAN_TEST_PARAMS asan_runtime_libraries)
ubsan_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
)
add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests" add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/UbsanConfig
PARAMS ${UBSAN_TEST_PARAMS} ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig
DEPENDS ${UBSAN_TEST_DEPS} DEPENDS ${UBSAN_TEST_DEPS})
)
set_target_properties(check-ubsan PROPERTIES FOLDER "UBSan unittests") set_target_properties(check-ubsan PROPERTIES FOLDER "UBSan unittests")
endif() endif()

View File

@ -0,0 +1,23 @@
# -*- Python -*-
import os
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
ubsan_lit_tests_dir = get_required_attr(config, "ubsan_lit_tests_dir")
ubsan_lit_cfg = os.path.join(ubsan_lit_tests_dir, "lit.common.cfg")
lit_config.load_config(config, ubsan_lit_cfg)
config.name = 'UndefinedBehaviorSanitizer-Standalone'
# Define %clang and %clangxx substitutions to use in test RUN lines.
config.substitutions.append( ("%clang ", (" " + config.clang + " ")) )
config.substitutions.append( ("%clangxx ", (" " + config.clang +
" --driver-mode=g++ ")) )

View File

@ -1,8 +1,8 @@
## Autogenerated by LLVM/Clang configuration.
# Do not edit!
# Load common config for all compiler-rt lit tests. # Load common config for all compiler-rt lit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/lib/lit.common.configured") lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/lib/lit.common.configured")
# Tool-specific config options.
config.ubsan_lit_tests_dir = "@UBSAN_LIT_TESTS_DIR@"
# Load tool-specific config that would do the real work. # Load tool-specific config that would do the real work.
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg") lit_config.load_config(config, "@UBSAN_LIT_TESTS_DIR@/UbsanConfig/lit.cfg")

View File

@ -1,65 +0,0 @@
# -*- Python -*-
import os
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 = 'UndefinedBehaviorSanitizer'
# 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-ubsan")
# 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 or we're performing an out-of-tree build.
ubsan_site_cfg = lit_config.params.get('ubsan_site_config', None)
if ubsan_site_cfg and os.path.exists(ubsan_site_cfg):
lit_config.load_config(config, ubsan_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()
ubsan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
"lib", "ubsan", "lit_tests", "lit.site.cfg")
if not ubsan_site_cfg or not os.path.exists(ubsan_site_cfg):
DisplayNoConfigMessage()
lit_config.load_config(config, ubsan_site_cfg)
raise SystemExit
# Define %clang and %clangxx substitutions to use in test RUN lines.
config.substitutions.append( ("%clang ", (" " + config.clang + " ")) )
config.substitutions.append( ("%clangxx ", (" " + config.clang +
" --driver-mode=g++ ")) )
# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']
# UndefinedBehaviorSanitizer tests are currently supported on
# Linux and Darwin only.
if config.host_os not in ['Linux', 'Darwin']:
config.unsupported = True
config.pipefail = False

View File

@ -0,0 +1,31 @@
# -*- Python -*-
import os
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 source root.
ubsan_lit_tests_dir = get_required_attr(config, 'ubsan_lit_tests_dir')
config.test_source_root = os.path.join(ubsan_lit_tests_dir, 'TestCases')
def DisplayNoConfigMessage():
lit_config.fatal("No site specific configuration available! " +
"Try running your test from the build tree or running " +
"make check-ubsan")
# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']
# UndefinedBehaviorSanitizer tests are currently supported on
# Linux and Darwin only.
if config.host_os not in ['Linux', 'Darwin']:
config.unsupported = True
config.pipefail = False