blob: 5d3e78eec76b09ebc9342f17c5b7319ecab1a855 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001# -*- Python -*-
2
3import os
4
5def get_required_attr(config, attr_name):
6 attr_value = getattr(config, attr_name, None)
7 if attr_value == None:
8 lit_config.fatal(
9 "No attribute %r in test configuration! You may need to run "
10 "tests from your build directory or add this attribute "
11 "to lit.site.cfg " % attr_name)
12 return attr_value
13
14# Setup source root.
15config.test_source_root = os.path.dirname(__file__)
16
17# Choose between standalone and UBSan+ASan modes.
18ubsan_lit_test_mode = get_required_attr(config, 'ubsan_lit_test_mode')
19if ubsan_lit_test_mode == "Standalone":
Stephen Hines86277eb2015-03-23 12:06:32 -070020 config.name = 'UBSan-Standalone-' + config.target_arch
Stephen Hines6d186232014-11-26 17:56:19 -080021 config.available_features.add("ubsan-standalone")
Stephen Hines2d1fdb22014-05-28 23:58:16 -070022 clang_ubsan_cflags = []
23elif ubsan_lit_test_mode == "AddressSanitizer":
Stephen Hines86277eb2015-03-23 12:06:32 -070024 config.name = 'UBSan-ASan-' + config.target_arch
Stephen Hines6d186232014-11-26 17:56:19 -080025 config.available_features.add("ubsan-asan")
Stephen Hines2d1fdb22014-05-28 23:58:16 -070026 clang_ubsan_cflags = ["-fsanitize=address"]
Stephen Hines6d186232014-11-26 17:56:19 -080027 config.environment['ASAN_OPTIONS'] = 'detect_leaks=0'
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070028elif ubsan_lit_test_mode == "MemorySanitizer":
29 config.name = 'UBSan-MSan-' + config.target_arch
30 config.available_features.add("ubsan-msan")
31 clang_ubsan_cflags = ["-fsanitize=memory"]
32elif ubsan_lit_test_mode == "ThreadSanitizer":
33 config.name = 'UBSan-TSan-' + config.target_arch
34 config.available_features.add("ubsan-tsan")
35 clang_ubsan_cflags = ["-fsanitize=thread"]
Stephen Hines2d1fdb22014-05-28 23:58:16 -070036else:
37 lit_config.fatal("Unknown UBSan test mode: %r" % ubsan_lit_test_mode)
38
39def build_invocation(compile_flags):
40 return " " + " ".join([config.clang] + compile_flags) + " "
41
42target_cflags = [get_required_attr(config, "target_cflags")]
43clang_ubsan_cflags += target_cflags
44clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags
45
46# Define %clang and %clangxx substitutions to use in test RUN lines.
47config.substitutions.append( ("%clang ", build_invocation(clang_ubsan_cflags)) )
48config.substitutions.append( ("%clangxx ", build_invocation(clang_ubsan_cxxflags)) )
49
50# Default test suffixes.
51config.suffixes = ['.c', '.cc', '.cpp']
52
Stephen Hines6d186232014-11-26 17:56:19 -080053# Check that the host supports UndefinedBehaviorSanitizer tests
54if config.host_os not in ['Linux', 'Darwin', 'FreeBSD']:
Stephen Hines2d1fdb22014-05-28 23:58:16 -070055 config.unsupported = True
56
Stephen Hines6d186232014-11-26 17:56:19 -080057# Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL
58# because the test hangs or fails on one configuration and not the other.
59if config.target_arch.startswith('arm') == False:
60 config.available_features.add('stable-runtime')