1# -*- Python -*-
2
3import os
4
5def get_required_attr(config, attr_name):
6  attr_value = getattr(config, attr_name, None)
7  if not attr_value:
8    lit.fatal("No attribute %r in test configuration! You may need to run "
9              "tests from your build directory or add this attribute "
10              "to lit.site.cfg " % attr_name)
11  return attr_value
12
13# Setup config name.
14config.name = 'UndefinedBehaviorSanitizer'
15
16# Setup source root.
17config.test_source_root = os.path.dirname(__file__)
18
19def DisplayNoConfigMessage():
20  lit.fatal("No site specific configuration available! " +
21            "Try running your test from the build tree or running " +
22            "make check-ubsan")
23
24# Figure out LLVM source root.
25llvm_src_root = getattr(config, 'llvm_src_root', None)
26if llvm_src_root is None:
27  # We probably haven't loaded the site-specific configuration: the user
28  # is likely trying to run a test file directly, and the site configuration
29  # wasn't created by the build system or we're performing an out-of-tree build.
30  ubsan_site_cfg = lit.params.get('ubsan_site_config', None)
31  if ubsan_site_cfg and os.path.exists(ubsan_site_cfg):
32    lit.load_config(config, ubsan_site_cfg)
33    raise SystemExit
34
35  # Try to guess the location of site-specific configuration using llvm-config
36  # util that can point where the build tree is.
37  llvm_config = lit.util.which("llvm-config", config.environment["PATH"])
38  if not llvm_config:
39    DisplayNoConfigMessage()
40
41  # Find out the presumed location of generated site config.
42  llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
43  ubsan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
44                                "lib", "ubsan", "lit_tests", "lit.site.cfg")
45  if not ubsan_site_cfg or not os.path.exists(ubsan_site_cfg):
46    DisplayNoConfigMessage()
47
48  lit.load_config(config, ubsan_site_cfg)
49  raise SystemExit
50
51# Define %clang substitution to use in test RUN lines.
52config.substitutions.append( ("%clang ", (" " + config.clang + " ")) )
53
54# Default test suffixes.
55config.suffixes = ['.c', '.cc', '.cpp']
56
57# UndefinedBehaviorSanitizer tests are currently supported on
58# Linux and Darwin only.
59if config.host_os not in ['Linux', 'Darwin']:
60  config.unsupported = True
61
62config.pipefail = False
63