]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/ubsan/lit.common.cfg
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / test / ubsan / lit.common.cfg
1 # -*- Python -*-
2
3 import os
4
5 def 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.
15 config.test_source_root = os.path.dirname(__file__)
16
17 default_ubsan_opts = []
18 # Choose between standalone and UBSan+ASan modes.
19 ubsan_lit_test_mode = get_required_attr(config, 'ubsan_lit_test_mode')
20 if ubsan_lit_test_mode == "Standalone":
21 config.name = 'UBSan-Standalone-' + config.target_arch
22 config.available_features.add("ubsan-standalone")
23 clang_ubsan_cflags = []
24 elif ubsan_lit_test_mode == "AddressSanitizer":
25 config.name = 'UBSan-ASan-' + config.target_arch
26 config.available_features.add("ubsan-asan")
27 clang_ubsan_cflags = ["-fsanitize=address"]
28 default_ubsan_opts += ['detect_leaks=0']
29 elif 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"]
33 elif 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"]
37 else:
38 lit_config.fatal("Unknown UBSan test mode: %r" % ubsan_lit_test_mode)
39
40 # Platform-specific default for lit tests.
41 if 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_str = ':'.join(default_ubsan_opts)
46 if default_ubsan_opts_str:
47 config.environment['UBSAN_OPTIONS'] = default_ubsan_opts_str
48 default_ubsan_opts_str += ':'
49 # Substitution to setup UBSAN_OPTIONS in portable way.
50 config.substitutions.append(('%env_ubsan_opts=',
51 'env UBSAN_OPTIONS=' + default_ubsan_opts_str))
52
53 def build_invocation(compile_flags):
54 return " " + " ".join([config.clang] + compile_flags) + " "
55
56 target_cflags = [get_required_attr(config, "target_cflags")]
57 clang_ubsan_cflags += target_cflags
58 clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags
59
60 # Define %clang and %clangxx substitutions to use in test RUN lines.
61 config.substitutions.append( ("%clang ", build_invocation(clang_ubsan_cflags)) )
62 config.substitutions.append( ("%clangxx ", build_invocation(clang_ubsan_cxxflags)) )
63
64 # Default test suffixes.
65 config.suffixes = ['.c', '.cc', '.cpp']
66
67 # Check that the host supports UndefinedBehaviorSanitizer tests
68 if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows']:
69 config.unsupported = True
70
71 if config.host_os == 'Windows':
72 # We do not currently support enough of the Microsoft ABI for UBSan to work on
73 # Windows.
74 config.available_features.remove('cxxabi')
75
76 # Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL
77 # because the test hangs or fails on one configuration and not the other.
78 if config.target_arch.startswith('arm') == False and config.target_arch != 'aarch64':
79 config.available_features.add('stable-runtime')