Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / fuzzer / lit.cfg.py
blob7db3bd9340b04e657355bf3d564089799e6d5fe3
1 import lit.formats
2 import sys
3 import os
5 config.name = "libFuzzer" + config.name_suffix
6 config.test_format = lit.formats.ShTest(True)
7 config.suffixes = [".test"]
8 config.test_source_root = os.path.dirname(__file__)
9 config.available_features.add(config.target_arch)
10 lit_config.note(f'arch feature "{config.target_arch}" available')
12 # Choose between lit's internal shell pipeline runner and a real shell. If
13 # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
14 use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
15 if use_lit_shell:
16 # 0 is external, "" is default, and everything else is internal.
17 execute_external = use_lit_shell == "0"
18 else:
19 # Otherwise we default to internal on Windows and external elsewhere, as
20 # bash on Windows is usually very slow.
21 execute_external = not sys.platform in ["win32"]
23 # testFormat: The test format to use to interpret tests.
25 # For now we require '&&' between commands, until they get globally killed and
26 # the test runner updated.
27 config.test_format = lit.formats.ShTest(execute_external)
29 # LeakSanitizer is not supported on OSX or Windows right now.
30 if (
31 sys.platform.startswith("darwin")
32 or sys.platform.startswith("freebsd")
33 or sys.platform.startswith("win")
35 lit_config.note("lsan feature unavailable")
36 else:
37 lit_config.note("lsan feature available")
38 config.available_features.add("lsan")
40 # MemorySanitizer is not supported on OSX or Windows right now
41 if (
42 sys.platform.startswith("darwin")
43 or sys.platform.startswith("win")
44 or config.target_arch == "i386"
46 lit_config.note("msan feature unavailable")
47 assert "msan" not in config.available_features
48 else:
49 lit_config.note("msan feature available")
50 config.available_features.add("msan")
52 if sys.platform.startswith("win") or sys.platform.startswith("cygwin"):
53 config.available_features.add("windows")
55 if sys.platform.startswith("darwin"):
56 config.available_features.add("darwin")
58 if sys.platform.startswith("linux"):
59 # Note the value of ``sys.platform`` is not consistent
60 # between python 2 and 3, hence the use of ``.startswith()``.
61 lit_config.note("linux feature available")
62 config.available_features.add("linux")
63 else:
64 lit_config.note("linux feature unavailable")
66 if config.arm_thumb:
67 config.available_features.add("thumb")
69 config.substitutions.append(("%build_dir", config.cmake_binary_dir))
70 libfuzzer_src_root = os.path.join(config.compiler_rt_src_root, "lib", "fuzzer")
71 config.substitutions.append(("%libfuzzer_src", libfuzzer_src_root))
73 config.substitutions.append(("%python", '"%s"' % (sys.executable)))
76 def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=False):
77 compiler_cmd = config.clang
78 extra_cmd = config.target_flags
80 if is_cpp:
81 std_cmd = "--driver-mode=g++"
82 else:
83 std_cmd = ""
85 if msan_enabled:
86 sanitizers = ["memory"]
87 else:
88 sanitizers = ["address"]
89 if fuzzer_enabled:
90 sanitizers.append("fuzzer")
91 sanitizers_cmd = "-fsanitize=%s" % ",".join(sanitizers)
92 return " ".join(
94 compiler_cmd,
95 std_cmd,
96 "-O2 -gline-tables-only",
97 sanitizers_cmd,
98 "-I%s" % libfuzzer_src_root,
99 extra_cmd,
104 config.substitutions.append(
105 ("%cpp_compiler", generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True))
108 config.substitutions.append(
109 ("%c_compiler", generate_compiler_cmd(is_cpp=False, fuzzer_enabled=True))
112 config.substitutions.append(
114 "%no_fuzzer_cpp_compiler",
115 generate_compiler_cmd(is_cpp=True, fuzzer_enabled=False),
119 config.substitutions.append(
120 ("%no_fuzzer_c_compiler", generate_compiler_cmd(is_cpp=False, fuzzer_enabled=False))
123 config.substitutions.append(
125 "%msan_compiler",
126 generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=True),
130 default_asan_opts_str = ":".join(config.default_sanitizer_opts)
131 if default_asan_opts_str:
132 config.environment["ASAN_OPTIONS"] = default_asan_opts_str
133 default_asan_opts_str += ":"
134 config.substitutions.append(
135 ("%env_asan_opts=", "env ASAN_OPTIONS=" + default_asan_opts_str)
138 if not config.parallelism_group:
139 config.parallelism_group = "shadow-memory"
141 if config.host_os == "NetBSD":
142 config.substitutions.insert(0, ("%run", config.netbsd_noaslr_prefix))