summaryrefslogtreecommitdiff
path: root/lib/msan/lit_tests/lit.cfg
blob: e220c38ff17b229ed83f8ab8388791ed3f8e9962 (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
# -*- Python -*-

import os

# Setup config name.
config.name = 'MemorySanitizer'

# Setup source root.
config.test_source_root = os.path.dirname(__file__)

def DisplayNoConfigMessage():
  lit.fatal("No site specific configuration available! " +
            "Try running your test from the build tree or running " +
            "make check-msan")

# Figure out LLVM source root.
llvm_src_root = getattr(config, 'llvm_src_root', None)
if llvm_src_root is None:
  # We probably haven't loaded the site-specific configuration: the user
  # is likely trying to run a test file directly, and the site configuration
  # wasn't created by the build system.
  msan_site_cfg = lit.params.get('msan_site_config', None)
  if (msan_site_cfg) and (os.path.exists(msan_site_cfg)):
    lit.load_config(config, msan_site_cfg)
    raise SystemExit

  # Try to guess the location of site-specific configuration using llvm-config
  # util that can point where the build tree is.
  llvm_config = lit.util.which("llvm-config", config.environment["PATH"])
  if not llvm_config:
    DisplayNoConfigMessage()

  # Validate that llvm-config points to the same source tree.
  llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip()
  msan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt",
                                    "lib", "msan", "lit_tests")
  if (os.path.realpath(msan_test_src_root) !=
      os.path.realpath(config.test_source_root)):
    DisplayNoConfigMessage()

  # Find out the presumed location of generated site config.
  llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
  msan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
                               "lib", "msan", "lit_tests", "lit.site.cfg")
  if (not msan_site_cfg) or (not os.path.exists(msan_site_cfg)):
    DisplayNoConfigMessage()

  lit.load_config(config, msan_site_cfg)
  raise SystemExit

# Setup attributes common for all compiler-rt projects.
compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt",
                                   "lib", "lit.common.cfg")
if (not compiler_rt_lit_cfg) or (not os.path.exists(compiler_rt_lit_cfg)):
  lit.fatal("Can't find common compiler-rt lit config at: %r"
            % compiler_rt_lit_cfg)
lit.load_config(config, compiler_rt_lit_cfg)

# Setup default compiler flags used with -fsanitize=memory option.
clang_msan_cflags = ["-fsanitize=memory",
                     "-mno-omit-leaf-frame-pointer",
                     "-fno-omit-frame-pointer",
                     "-fno-optimize-sibling-calls",
                     "-g"]
clang_msan_cxxflags = ["-ccc-cxx "] + clang_msan_cflags
config.substitutions.append( ("%clang_msan ",
                              " ".join([config.clang] + clang_msan_cflags) + 
                              " ") )
config.substitutions.append( ("%clangxx_msan ",
                              " ".join([config.clang] + clang_msan_cxxflags) + 
                              " ") )

# Setup path to external LLVM symbolizer to run MemorySanitizer output tests.
llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
if llvm_tools_dir:
  llvm_symbolizer_path = os.path.join(llvm_tools_dir, "llvm-symbolizer")
  config.environment['MSAN_SYMBOLIZER_PATH'] = llvm_symbolizer_path

# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']

# MemorySanitizer tests are currently supported on Linux only.
if config.host_os not in ['Linux']:
  config.unsupported = True