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

import os

def get_required_attr(config, attr_name):
  attr_value = getattr(config, attr_name, None)
  if not attr_value:
    lit_config.fatal(
      "No attribute %r in test configuration! You may need to run "
      "tests from your build directory or add this attribute "
      "to lit.site.cfg " % attr_name)
  return attr_value

# Setup config name.
config.name = 'UndefinedBehaviorSanitizer'

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

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

# 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 or we're performing an out-of-tree build.
  ubsan_site_cfg = lit_config.params.get('ubsan_site_config', None)
  if ubsan_site_cfg and os.path.exists(ubsan_site_cfg):
    lit_config.load_config(config, ubsan_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()

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

  lit_config.load_config(config, ubsan_site_cfg)
  raise SystemExit

# Define %clang and %clangxx substitutions to use in test RUN lines.
config.substitutions.append( ("%clang ", (" " + config.clang + " ")) )
config.substitutions.append( ("%clangxx ", (" " + config.clang +
                                            " --driver-mode=g++ ")) )

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

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

config.pipefail = False