2013-11-14 20:30:09 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
def get_required_attr(config, attr_name):
|
|
|
|
attr_value = getattr(config, attr_name, None)
|
2014-05-01 05:32:30 +08:00
|
|
|
if attr_value == None:
|
2013-11-14 20:30:09 +08:00
|
|
|
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.
|
2014-02-18 16:56:49 +08:00
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
# Choose between standalone and UBSan+ASan modes.
|
|
|
|
ubsan_lit_test_mode = get_required_attr(config, 'ubsan_lit_test_mode')
|
|
|
|
if ubsan_lit_test_mode == "Standalone":
|
2015-02-27 03:19:44 +08:00
|
|
|
config.name = 'UBSan-Standalone-' + config.target_arch
|
2014-09-20 02:33:45 +08:00
|
|
|
config.available_features.add("ubsan-standalone")
|
2014-02-18 16:56:49 +08:00
|
|
|
clang_ubsan_cflags = []
|
|
|
|
elif ubsan_lit_test_mode == "AddressSanitizer":
|
2015-02-27 03:19:44 +08:00
|
|
|
config.name = 'UBSan-ASan-' + config.target_arch
|
2014-09-20 02:33:45 +08:00
|
|
|
config.available_features.add("ubsan-asan")
|
2014-02-18 16:56:49 +08:00
|
|
|
clang_ubsan_cflags = ["-fsanitize=address"]
|
2014-07-29 08:30:01 +08:00
|
|
|
config.environment['ASAN_OPTIONS'] = 'detect_leaks=0'
|
2015-07-28 23:35:04 +08:00
|
|
|
|
|
|
|
# Platform-specific default ASAN_OPTIONS for lit tests.
|
|
|
|
if config.host_os == 'Darwin':
|
|
|
|
# On Darwin, we default to `abort_on_error=1`, which would make tests run
|
|
|
|
# much slower. Let's override this and run lit tests with 'abort_on_error=0'.
|
|
|
|
config.environment['ASAN_OPTIONS'] = 'abort_on_error=0'
|
2015-04-28 08:56:48 +08:00
|
|
|
elif ubsan_lit_test_mode == "MemorySanitizer":
|
|
|
|
config.name = 'UBSan-MSan-' + config.target_arch
|
|
|
|
config.available_features.add("ubsan-msan")
|
|
|
|
clang_ubsan_cflags = ["-fsanitize=memory"]
|
|
|
|
elif ubsan_lit_test_mode == "ThreadSanitizer":
|
|
|
|
config.name = 'UBSan-TSan-' + config.target_arch
|
|
|
|
config.available_features.add("ubsan-tsan")
|
|
|
|
clang_ubsan_cflags = ["-fsanitize=thread"]
|
2014-02-18 16:56:49 +08:00
|
|
|
else:
|
|
|
|
lit_config.fatal("Unknown UBSan test mode: %r" % ubsan_lit_test_mode)
|
|
|
|
|
|
|
|
def build_invocation(compile_flags):
|
|
|
|
return " " + " ".join([config.clang] + compile_flags) + " "
|
|
|
|
|
2014-05-14 08:46:01 +08:00
|
|
|
target_cflags = [get_required_attr(config, "target_cflags")]
|
|
|
|
clang_ubsan_cflags += target_cflags
|
2014-02-19 23:13:14 +08:00
|
|
|
clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags
|
2014-02-18 16:56:49 +08:00
|
|
|
|
|
|
|
# Define %clang and %clangxx substitutions to use in test RUN lines.
|
|
|
|
config.substitutions.append( ("%clang ", build_invocation(clang_ubsan_cflags)) )
|
|
|
|
config.substitutions.append( ("%clangxx ", build_invocation(clang_ubsan_cxxflags)) )
|
2013-11-14 20:30:09 +08:00
|
|
|
|
|
|
|
# Default test suffixes.
|
|
|
|
config.suffixes = ['.c', '.cc', '.cpp']
|
|
|
|
|
2014-11-10 23:31:56 +08:00
|
|
|
# Check that the host supports UndefinedBehaviorSanitizer tests
|
2015-07-03 06:08:38 +08:00
|
|
|
if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows']:
|
2013-11-14 20:30:09 +08:00
|
|
|
config.unsupported = True
|
2014-10-16 15:48:27 +08:00
|
|
|
|
2015-07-09 06:10:34 +08:00
|
|
|
if config.host_os == 'Windows':
|
|
|
|
# We do not currently support enough of the Microsoft ABI for UBSan to work on
|
|
|
|
# Windows.
|
|
|
|
config.available_features.remove('cxxabi')
|