xref: /llvm-project/compiler-rt/test/rtsan/lit.cfg.py (revision aa43f3abe0e9a7199a8df3f71364d7084f968825)
1import os
2
3# Setup config name.
4config.name = "RTSAN" + config.name_suffix
5
6
7default_rtsan_opts = "atexit_sleep_ms=0"
8
9if config.host_os == "Darwin":
10    # On Darwin, we default to `abort_on_error=1`, which would make tests run
11    # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
12    default_rtsan_opts += ":abort_on_error=0"
13
14if default_rtsan_opts:
15    config.environment["RTSAN_OPTIONS"] = default_rtsan_opts
16    default_rtsan_opts += ":"
17
18config.substitutions.append(
19    ("%env_rtsan_opts=", "env RTSAN_OPTIONS=" + default_rtsan_opts)
20)
21
22# Setup source root.
23config.test_source_root = os.path.dirname(__file__)
24
25# Setup default compiler flags use with -frtsan-instrument option.
26clang_rtsan_cflags = ["-frtsan-instrument", config.target_cflags]
27
28clang_rtsan_cxxflags = config.cxx_mode_flags + clang_rtsan_cflags
29
30
31def build_invocation(compile_flags):
32    return " " + " ".join([config.clang] + compile_flags) + " "
33
34
35# Assume that llvm-rtsan is in the config.llvm_tools_dir.
36llvm_rtsan = os.path.join(config.llvm_tools_dir, "llvm-rtsan")
37
38# Setup substitutions.
39if config.host_os == "Linux":
40    libdl_flag = "-ldl"
41else:
42    libdl_flag = ""
43
44config.substitutions.append(("%clang ", build_invocation([config.target_cflags])))
45config.substitutions.append(
46    ("%clangxx ", build_invocation(config.cxx_mode_flags + [config.target_cflags]))
47)
48config.substitutions.append(("%clang_rtsan ", build_invocation(clang_rtsan_cflags)))
49config.substitutions.append(("%clangxx_rtsan", build_invocation(clang_rtsan_cxxflags)))
50config.substitutions.append(("%llvm_rtsan", llvm_rtsan))
51
52# Default test suffixes.
53config.suffixes = [".c", ".cpp"]
54
55if config.host_os not in ["Darwin", "FreeBSD", "Linux", "NetBSD", "OpenBSD"]:
56    config.unsupported = True
57elif "64" not in config.host_arch:
58    if "arm" in config.host_arch:
59        if "-mthumb" in config.target_cflags:
60            config.unsupported = True
61    else:
62        config.unsupported = True
63
64if config.host_os == "NetBSD":
65    config.substitutions.insert(0, ("%run", config.netbsd_nomprotect_prefix))
66