summaryrefslogtreecommitdiff
path: root/test/fuzzer/lit.cfg
blob: 608991c0764f508b0a63d096477ee025b53a91b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import lit.formats
import sys
import os

config.name = "libFuzzer" + config.name_suffix
config.test_format = lit.formats.ShTest(True)
config.suffixes = ['.test']
config.test_source_root = os.path.dirname(__file__)

# Choose between lit's internal shell pipeline runner and a real shell.  If
# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
if use_lit_shell:
    # 0 is external, "" is default, and everything else is internal.
    execute_external = (use_lit_shell == "0")
else:
    # Otherwise we default to internal on Windows and external elsewhere, as
    # bash on Windows is usually very slow.
    execute_external = (not sys.platform in ['win32'])

# testFormat: The test format to use to interpret tests.
#
# For now we require '&&' between commands, until they get globally killed and
# the test runner updated.
config.test_format = lit.formats.ShTest(execute_external)

# LeakSanitizer is not supported on OSX or Windows right now.
if (sys.platform.startswith('darwin') or
    sys.platform.startswith('freebsd') or
    sys.platform.startswith('netbsd') or
    sys.platform.startswith('win')):
  lit_config.note('lsan feature unavailable')
else:
  lit_config.note('lsan feature available')
  config.available_features.add('lsan')

# MemorySanitizer is not supported on OSX or Windows right now
if sys.platform.startswith('darwin') or sys.platform.startswith('win'):
  lit_config.note('msan feature unavailable')
  assert 'msan' not in config.available_features
else:
  lit_config.note('msan feature available')
  config.available_features.add('msan')

if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
  config.available_features.add('windows')

if sys.platform.startswith('darwin'):
  config.available_features.add('darwin')

if sys.platform.startswith('linux'):
  # Note the value of ``sys.platform`` is not consistent
  # between python 2 and 3, hence the use of ``.startswith()``.
  lit_config.note('linux feature available')
  config.available_features.add('linux')
else:
  lit_config.note('linux feature unavailable')

config.substitutions.append(('%build_dir', config.cmake_binary_dir))
libfuzzer_src_root = os.path.join(config.compiler_rt_src_root, "lib", "fuzzer")
config.substitutions.append(('%libfuzzer_src', libfuzzer_src_root))

def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=False):
  compiler_cmd = config.clang
  extra_cmd = config.target_flags
  if config.clang and config.stdlib == 'libc++':
    link_cmd = '-stdlib=libc++ -Wl,-rpath=%s' % config.runtime_library_dir
  elif config.clang and config.stdlib == 'static-libc++':
    link_cmd = '-stdlib=libc++ -lc++abi -static-libstdc++ -Wl,-rpath=%s' % (
        config.runtime_library_dir)
  elif any(x in config.target_triple for x in ('darwin', 'freebsd')):
    link_cmd = '-lc++'
  elif 'windows-msvc' in config.target_triple:
    link_cmd = ''
  else:
    link_cmd = '-lstdc++'

  if is_cpp and 'windows-msvc' in config.target_triple:
    std_cmd = '--driver-mode=cl'
  elif is_cpp:
    std_cmd = '--driver-mode=g++ -std=c++11'
  else:
    std_cmd = ''

  if msan_enabled:
    sanitizers = ['memory']
  else:
    sanitizers = ['address']
  if fuzzer_enabled:
    sanitizers.append('fuzzer')
  sanitizers_cmd = ('-fsanitize=%s' % ','.join(sanitizers))
  return " ".join([
    compiler_cmd,
    std_cmd,
    link_cmd,
    "-O2 -gline-tables-only",
    sanitizers_cmd,
    "-I%s" % libfuzzer_src_root,
    extra_cmd
  ])

config.substitutions.append(('%cpp_compiler',
      generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True)
      ))

config.substitutions.append(('%c_compiler',
      generate_compiler_cmd(is_cpp=False, fuzzer_enabled=True)
      ))

config.substitutions.append(('%no_fuzzer_cpp_compiler',
      generate_compiler_cmd(is_cpp=True, fuzzer_enabled=False)
      ))

config.substitutions.append(('%no_fuzzer_c_compiler',
      generate_compiler_cmd(is_cpp=False, fuzzer_enabled=False)
      ))

config.substitutions.append(('%msan_compiler',
      generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=True)
      ))

if config.host_os == 'Darwin':
  if config.target_arch in ["x86_64", "x86_64h"]:
    config.parallelism_group = "darwin-64bit-sanitizer"
  elif config.apple_platform != "osx" and not config.apple_platform.endswith("sim"):
    config.parallelism_group = "darwin-ios-device-sanitizer"