summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/ubsan/lit.common.cfg
blob: e165e72ed79ba9d1c3baeb47137311970b50315e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- Python -*-

import os

def get_required_attr(config, attr_name):
  attr_value = getattr(config, attr_name, None)
  if attr_value == None:
    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.
config.test_source_root = os.path.dirname(__file__)

default_ubsan_opts = []
# 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":
  config.name = 'UBSan-Standalone-' + config.target_arch
  config.available_features.add("ubsan-standalone")
  clang_ubsan_cflags = []
elif ubsan_lit_test_mode == "AddressSanitizer":
  config.name = 'UBSan-ASan-' + config.target_arch
  config.available_features.add("ubsan-asan")
  clang_ubsan_cflags = ["-fsanitize=address"]
  default_ubsan_opts += ['detect_leaks=0']
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"]
else:
  lit_config.fatal("Unknown UBSan test mode: %r" % ubsan_lit_test_mode)

# Platform-specific default for lit tests.
if config.target_arch == 's390x':
  # On SystemZ we need -mbackchain to make the fast unwinder work.
  clang_ubsan_cflags.append("-mbackchain")
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'.
  default_ubsan_opts += ['abort_on_error=0']
  default_ubsan_opts += ['log_to_syslog=0']
default_ubsan_opts_str = ':'.join(default_ubsan_opts)
if default_ubsan_opts_str:
  config.environment['UBSAN_OPTIONS'] = default_ubsan_opts_str
  default_ubsan_opts_str += ':'
# Substitution to setup UBSAN_OPTIONS in portable way.
config.substitutions.append(('%env_ubsan_opts=',
                             'env UBSAN_OPTIONS=' + default_ubsan_opts_str))

def build_invocation(compile_flags):
  return " " + " ".join([config.clang] + compile_flags) + " "

target_cflags = [get_required_attr(config, "target_cflags")]
clang_ubsan_cflags += target_cflags
clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags

# 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)) )
config.substitutions.append( ("%gmlt ", " ".join(config.debug_info_flags) + " ") )

# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']

# Check that the host supports UndefinedBehaviorSanitizer tests
if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows', 'NetBSD']:
  config.unsupported = True

# Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL
# because the test hangs or fails on one configuration and not the other.
if config.target_arch.startswith('arm') == False and config.target_arch != 'aarch64':
  config.available_features.add('stable-runtime')

config.available_features.add('arch=' + config.target_arch)
OpenPOWER on IntegriCloud