[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / fuzzer / lit.cfg.py
blobf0140c8f3ba40063779f39af4e40647055fdb2bd
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 (sys.platform.startswith('darwin') or
31 sys.platform.startswith('freebsd') or
32 sys.platform.startswith('win')):
33 lit_config.note('lsan feature unavailable')
34 else:
35 lit_config.note('lsan feature available')
36 config.available_features.add('lsan')
38 # MemorySanitizer is not supported on OSX or Windows right now
39 if (sys.platform.startswith('darwin') or sys.platform.startswith('win') or
40 config.target_arch == 'i386'):
41 lit_config.note('msan feature unavailable')
42 assert 'msan' not in config.available_features
43 else:
44 lit_config.note('msan feature available')
45 config.available_features.add('msan')
47 if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
48 config.available_features.add('windows')
50 if sys.platform.startswith('darwin'):
51 config.available_features.add('darwin')
53 if sys.platform.startswith('linux'):
54 # Note the value of ``sys.platform`` is not consistent
55 # between python 2 and 3, hence the use of ``.startswith()``.
56 lit_config.note('linux feature available')
57 config.available_features.add('linux')
58 else:
59 lit_config.note('linux feature unavailable')
61 if config.arm_thumb:
62 config.available_features.add('thumb')
64 config.substitutions.append(('%build_dir', config.cmake_binary_dir))
65 libfuzzer_src_root = os.path.join(config.compiler_rt_src_root, "lib", "fuzzer")
66 config.substitutions.append(('%libfuzzer_src', libfuzzer_src_root))
68 config.substitutions.append(('%python', '"%s"' % (sys.executable)))
70 def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=False):
71 compiler_cmd = config.clang
72 extra_cmd = config.target_flags
74 if is_cpp:
75 std_cmd = '--driver-mode=g++'
76 else:
77 std_cmd = ''
79 if msan_enabled:
80 sanitizers = ['memory']
81 else:
82 sanitizers = ['address']
83 if fuzzer_enabled:
84 sanitizers.append('fuzzer')
85 sanitizers_cmd = ('-fsanitize=%s' % ','.join(sanitizers))
86 return " ".join([
87 compiler_cmd,
88 std_cmd,
89 "-O2 -gline-tables-only",
90 sanitizers_cmd,
91 "-I%s" % libfuzzer_src_root,
92 extra_cmd
95 config.substitutions.append(('%cpp_compiler',
96 generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True)
99 config.substitutions.append(('%c_compiler',
100 generate_compiler_cmd(is_cpp=False, fuzzer_enabled=True)
103 config.substitutions.append(('%no_fuzzer_cpp_compiler',
104 generate_compiler_cmd(is_cpp=True, fuzzer_enabled=False)
107 config.substitutions.append(('%no_fuzzer_c_compiler',
108 generate_compiler_cmd(is_cpp=False, fuzzer_enabled=False)
111 config.substitutions.append(('%msan_compiler',
112 generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=True)
115 default_asan_opts_str = ':'.join(config.default_sanitizer_opts)
116 if default_asan_opts_str:
117 config.environment['ASAN_OPTIONS'] = default_asan_opts_str
118 default_asan_opts_str += ':'
119 config.substitutions.append(('%env_asan_opts=',
120 'env ASAN_OPTIONS=' + default_asan_opts_str))
122 if not config.parallelism_group:
123 config.parallelism_group = 'shadow-memory'
125 if config.host_os == 'NetBSD':
126 config.substitutions.insert(0, ('%run', config.netbsd_noaslr_prefix))