xref: /llvm-project/compiler-rt/test/sanitizer_common/lit.common.cfg.py (revision ca95bee649724a6092989076322daa501a0a6594)
18007ff1aSReid Kleckner# -*- Python -*-
28007ff1aSReid Kleckner
38007ff1aSReid Kleckner# Setup source root.
48007ff1aSReid Klecknerconfig.test_source_root = os.path.join(os.path.dirname(__file__), "TestCases")
58007ff1aSReid Kleckner
68007ff1aSReid Klecknerconfig.name = "SanitizerCommon-" + config.name_suffix
78007ff1aSReid Kleckner
88007ff1aSReid Klecknerdefault_tool_options = []
98007ff1aSReid Klecknercollect_stack_traces = ""
108007ff1aSReid Klecknerif config.tool_name == "asan":
118007ff1aSReid Kleckner    tool_cflags = ["-fsanitize=address"]
128007ff1aSReid Kleckner    tool_options = "ASAN_OPTIONS"
131f2d945fSVitaly Bukaelif config.tool_name == "hwasan":
141f2d945fSVitaly Buka    tool_cflags = ["-fsanitize=hwaddress", "-fuse-ld=lld"]
151f2d945fSVitaly Buka    if config.target_arch == "x86_64":
161f2d945fSVitaly Buka        tool_cflags += ["-fsanitize-hwaddress-experimental-aliasing"]
1779e76211SVitaly Buka        config.available_features.add("hwasan-aliasing")
181f2d945fSVitaly Buka    tool_options = "HWASAN_OPTIONS"
19e37fce3dSVitaly Buka    if not config.has_lld:
20e37fce3dSVitaly Buka        config.unsupported = True
21*ca95bee6SChris Appleelif config.tool_name == "rtsan":
22*ca95bee6SChris Apple    tool_cflags = ["-fsanitize=realtime"]
23*ca95bee6SChris Apple    tool_options = "RTSAN_OPTIONS"
248007ff1aSReid Klecknerelif config.tool_name == "tsan":
258007ff1aSReid Kleckner    tool_cflags = ["-fsanitize=thread"]
268007ff1aSReid Kleckner    tool_options = "TSAN_OPTIONS"
278007ff1aSReid Klecknerelif config.tool_name == "msan":
288007ff1aSReid Kleckner    tool_cflags = ["-fsanitize=memory"]
298007ff1aSReid Kleckner    tool_options = "MSAN_OPTIONS"
308007ff1aSReid Kleckner    collect_stack_traces = "-fsanitize-memory-track-origins"
318007ff1aSReid Klecknerelif config.tool_name == "lsan":
328007ff1aSReid Kleckner    tool_cflags = ["-fsanitize=leak"]
338007ff1aSReid Kleckner    tool_options = "LSAN_OPTIONS"
348007ff1aSReid Klecknerelif config.tool_name == "ubsan":
358007ff1aSReid Kleckner    tool_cflags = ["-fsanitize=undefined"]
368007ff1aSReid Kleckner    tool_options = "UBSAN_OPTIONS"
378007ff1aSReid Klecknerelse:
388007ff1aSReid Kleckner    lit_config.fatal("Unknown tool for sanitizer_common tests: %r" % config.tool_name)
398007ff1aSReid Kleckner
408007ff1aSReid Klecknerconfig.available_features.add(config.tool_name)
418007ff1aSReid Kleckner
42f98ee40fSTobias Hietaif (
43f98ee40fSTobias Hieta    config.host_os == "Linux"
44f98ee40fSTobias Hieta    and config.tool_name == "lsan"
45f98ee40fSTobias Hieta    and config.target_arch == "i386"
46f98ee40fSTobias Hieta):
478007ff1aSReid Kleckner    config.available_features.add("lsan-x86")
488007ff1aSReid Kleckner
4911ad9e31SDavid Spickettif config.arm_thumb:
50f98ee40fSTobias Hieta    config.available_features.add("thumb")
5111ad9e31SDavid Spickett
52f98ee40fSTobias Hietaif config.host_os == "Darwin":
538007ff1aSReid Kleckner    # On Darwin, we default to `abort_on_error=1`, which would make tests run
548007ff1aSReid Kleckner    # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
55f98ee40fSTobias Hieta    default_tool_options += ["abort_on_error=0"]
56e47c0ef0SJulian Lettner    if config.tool_name == "tsan":
57f98ee40fSTobias Hieta        default_tool_options += ["ignore_interceptors_accesses=0"]
588007ff1aSReid Klecknerelif config.android:
598007ff1aSReid Kleckner    # The same as on Darwin, we default to "abort_on_error=1" which slows down
608007ff1aSReid Kleckner    # testing. Also, all existing tests are using "not" instead of "not --crash"
618007ff1aSReid Kleckner    # which does not work for abort()-terminated programs.
62f98ee40fSTobias Hieta    default_tool_options += ["abort_on_error=0"]
638007ff1aSReid Kleckner
64f98ee40fSTobias Hietadefault_tool_options_str = ":".join(default_tool_options)
658007ff1aSReid Klecknerif default_tool_options_str:
668007ff1aSReid Kleckner    config.environment[tool_options] = default_tool_options_str
67f98ee40fSTobias Hieta    default_tool_options_str += ":"
688007ff1aSReid Kleckner
698007ff1aSReid Klecknerextra_link_flags = []
708007ff1aSReid Kleckner
71f98ee40fSTobias Hietaif config.host_os in ["Linux"]:
72f3ae951cSVitaly Buka    extra_link_flags += ["-ldl"]
73f3ae951cSVitaly Buka
748007ff1aSReid Klecknerclang_cflags = config.debug_info_flags + tool_cflags + [config.target_cflags]
75f67fc3acSVitaly Bukaclang_cflags += ["-I%s" % os.path.dirname(os.path.dirname(__file__))]
768007ff1aSReid Klecknerclang_cflags += extra_link_flags
778007ff1aSReid Klecknerclang_cxxflags = config.cxx_mode_flags + clang_cflags
788007ff1aSReid Kleckner
79f98ee40fSTobias Hieta
808007ff1aSReid Klecknerdef build_invocation(compile_flags):
818007ff1aSReid Kleckner    return " " + " ".join([config.clang] + compile_flags) + " "
828007ff1aSReid Kleckner
83f98ee40fSTobias Hieta
848007ff1aSReid Klecknerconfig.substitutions.append(("%clang ", build_invocation(clang_cflags)))
858007ff1aSReid Klecknerconfig.substitutions.append(("%clangxx ", build_invocation(clang_cxxflags)))
868007ff1aSReid Klecknerconfig.substitutions.append(("%collect_stack_traces", collect_stack_traces))
878007ff1aSReid Klecknerconfig.substitutions.append(("%tool_name", config.tool_name))
888007ff1aSReid Klecknerconfig.substitutions.append(("%tool_options", tool_options))
89f98ee40fSTobias Hietaconfig.substitutions.append(
90f98ee40fSTobias Hieta    ("%env_tool_opts=", "env " + tool_options + "=" + default_tool_options_str)
91f98ee40fSTobias Hieta)
928007ff1aSReid Kleckner
93f98ee40fSTobias Hietaconfig.suffixes = [".c", ".cpp"]
948007ff1aSReid Kleckner
95f98ee40fSTobias Hietaif config.host_os not in ["Linux", "Darwin", "NetBSD", "FreeBSD", "SunOS"]:
968007ff1aSReid Kleckner    config.unsupported = True
978007ff1aSReid Kleckner
988007ff1aSReid Klecknerif not config.parallelism_group:
99f98ee40fSTobias Hieta    config.parallelism_group = "shadow-memory"
1006c2b2b9eSMichał Górny
101f98ee40fSTobias Hietaif config.host_os == "NetBSD":
102f98ee40fSTobias Hieta    config.substitutions.insert(0, ("%run", config.netbsd_noaslr_prefix))
103