1# -*- Python -*-
2
3# Setup source root.
4config.test_source_root = os.path.join(os.path.dirname(__file__), "TestCases")
5
6config.name = "SanitizerCommon-" + config.name_suffix
7
8default_tool_options = []
9collect_stack_traces = ""
10if config.tool_name == "asan":
11  tool_cflags = ["-fsanitize=address"]
12  tool_options = "ASAN_OPTIONS"
13elif config.tool_name == "tsan":
14  tool_cflags = ["-fsanitize=thread"]
15  tool_options = "TSAN_OPTIONS"
16elif config.tool_name == "msan":
17  tool_cflags = ["-fsanitize=memory"]
18  tool_options = "MSAN_OPTIONS"
19  collect_stack_traces = "-fsanitize-memory-track-origins"
20elif config.tool_name == "lsan":
21  tool_cflags = ["-fsanitize=leak"]
22  tool_options = "LSAN_OPTIONS"
23elif config.tool_name == "ubsan":
24  tool_cflags = ["-fsanitize=undefined"]
25  tool_options = "UBSAN_OPTIONS"
26else:
27  lit_config.fatal("Unknown tool for sanitizer_common tests: %r" % config.tool_name)
28
29config.available_features.add(config.tool_name)
30
31if config.host_os == 'Linux' and config.tool_name == "lsan" and config.target_arch == 'i386':
32  config.available_features.add("lsan-x86")
33
34if config.host_os == 'Darwin':
35  # On Darwin, we default to `abort_on_error=1`, which would make tests run
36  # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
37  default_tool_options += ['abort_on_error=0']
38  if config.tool_name == "tsan":
39    default_tool_options += ['ignore_interceptors_accesses=0']
40elif config.android:
41  # The same as on Darwin, we default to "abort_on_error=1" which slows down
42  # testing. Also, all existing tests are using "not" instead of "not --crash"
43  # which does not work for abort()-terminated programs.
44  default_tool_options += ['abort_on_error=0']
45
46default_tool_options_str = ':'.join(default_tool_options)
47if default_tool_options_str:
48  config.environment[tool_options] = default_tool_options_str
49  default_tool_options_str += ':'
50
51extra_link_flags = []
52
53if config.host_os in ['Linux']:
54  extra_link_flags += ["-ldl"]
55
56clang_cflags = config.debug_info_flags + tool_cflags + [config.target_cflags]
57clang_cflags += extra_link_flags
58clang_cxxflags = config.cxx_mode_flags + clang_cflags
59
60def build_invocation(compile_flags):
61  return " " + " ".join([config.clang] + compile_flags) + " "
62
63config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) )
64config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) )
65config.substitutions.append( ("%collect_stack_traces", collect_stack_traces) )
66config.substitutions.append( ("%tool_name", config.tool_name) )
67config.substitutions.append( ("%tool_options", tool_options) )
68config.substitutions.append( ('%env_tool_opts=',
69                              'env ' + tool_options + '=' + default_tool_options_str))
70
71config.suffixes = ['.c', '.cpp']
72
73if config.host_os not in ['Linux', 'Darwin', 'NetBSD', 'FreeBSD']:
74  config.unsupported = True
75
76if not config.parallelism_group:
77  config.parallelism_group = 'shadow-memory'
78
79if config.host_os == 'NetBSD':
80  config.substitutions.insert(0, ('%run', config.netbsd_noaslr_prefix))
81