blob: e50862983d62c8593e477f1698b38e79ec918021 [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
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080017default_ubsan_opts = []
Stephen Hines2d1fdb22014-05-28 23:58:16 -070018# Choose between standalone and UBSan+ASan modes.
19ubsan_lit_test_mode = get_required_attr(config, 'ubsan_lit_test_mode')
20if ubsan_lit_test_mode == "Standalone":
Stephen Hines86277eb2015-03-23 12:06:32 -070021 config.name = 'UBSan-Standalone-' + config.target_arch
Stephen Hines6d186232014-11-26 17:56:19 -080022 config.available_features.add("ubsan-standalone")
Stephen Hines2d1fdb22014-05-28 23:58:16 -070023 clang_ubsan_cflags = []
24elif ubsan_lit_test_mode == "AddressSanitizer":
Stephen Hines86277eb2015-03-23 12:06:32 -070025 config.name = 'UBSan-ASan-' + config.target_arch
Stephen Hines6d186232014-11-26 17:56:19 -080026 config.available_features.add("ubsan-asan")
Stephen Hines2d1fdb22014-05-28 23:58:16 -070027 clang_ubsan_cflags = ["-fsanitize=address"]
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080028 default_ubsan_opts += ['detect_leaks=0']
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070029elif ubsan_lit_test_mode == "MemorySanitizer":
30 config.name = 'UBSan-MSan-' + config.target_arch
31 config.available_features.add("ubsan-msan")
32 clang_ubsan_cflags = ["-fsanitize=memory"]
33elif ubsan_lit_test_mode == "ThreadSanitizer":
34 config.name = 'UBSan-TSan-' + config.target_arch
35 config.available_features.add("ubsan-tsan")
36 clang_ubsan_cflags = ["-fsanitize=thread"]
Stephen Hines2d1fdb22014-05-28 23:58:16 -070037else:
38 lit_config.fatal("Unknown UBSan test mode: %r" % ubsan_lit_test_mode)
39
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080040# Platform-specific default for lit tests.
41if config.host_os == 'Darwin':
42 # On Darwin, we default to `abort_on_error=1`, which would make tests run
43 # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
44 default_ubsan_opts += ['abort_on_error=0']
45 default_ubsan_opts += ['log_to_syslog=0']
46default_ubsan_opts_str = ':'.join(default_ubsan_opts)
47if default_ubsan_opts_str:
48 config.environment['UBSAN_OPTIONS'] = default_ubsan_opts_str
49 default_ubsan_opts_str += ':'
50# Substitution to setup UBSAN_OPTIONS in portable way.
51config.substitutions.append(('%env_ubsan_opts=',
52 'env UBSAN_OPTIONS=' + default_ubsan_opts_str))
53
Stephen Hines2d1fdb22014-05-28 23:58:16 -070054def build_invocation(compile_flags):
55 return " " + " ".join([config.clang] + compile_flags) + " "
56
57target_cflags = [get_required_attr(config, "target_cflags")]
58clang_ubsan_cflags += target_cflags
59clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags
60
61# Define %clang and %clangxx substitutions to use in test RUN lines.
62config.substitutions.append( ("%clang ", build_invocation(clang_ubsan_cflags)) )
63config.substitutions.append( ("%clangxx ", build_invocation(clang_ubsan_cxxflags)) )
64
65# Default test suffixes.
66config.suffixes = ['.c', '.cc', '.cpp']
67
Stephen Hines6d186232014-11-26 17:56:19 -080068# Check that the host supports UndefinedBehaviorSanitizer tests
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080069if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows']:
Stephen Hines2d1fdb22014-05-28 23:58:16 -070070 config.unsupported = True
71
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080072if config.host_os == 'Windows':
73 # We do not currently support enough of the Microsoft ABI for UBSan to work on
74 # Windows.
75 config.available_features.remove('cxxabi')
76
Stephen Hines6d186232014-11-26 17:56:19 -080077# Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL
78# because the test hangs or fails on one configuration and not the other.
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080079if config.target_arch.startswith('arm') == False and config.target_arch != 'aarch64':
Stephen Hines6d186232014-11-26 17:56:19 -080080 config.available_features.add('stable-runtime')