blob: 7875281b1f2f9a6781905ca69fdb40b1c3d502b9 [file] [log] [blame]
# -*- Python -*-
import os
# Setup config name. = 'AddressSanitizer'
# 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-asan")
# 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.
asan_site_cfg = lit.params.get('asan_site_config', None)
if (asan_site_cfg) and (os.path.exists(asan_site_cfg)):
lit.load_config(config, asan_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:
# Validate that llvm-config points to the same source tree.
llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip()
asan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt",
"lib", "asan", "lit_tests")
if (os.path.realpath(asan_test_src_root) !=
# Find out the presumed location of generated site config.
llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
asan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
"lib", "asan", "lit_tests", "")
if (not asan_site_cfg) or (not os.path.exists(asan_site_cfg)):
lit.load_config(config, asan_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=address option.
# FIXME: Review the set of required flags and check if it can be reduced.
clang_asan_cxxflags = ("-ccc-cxx "
+ "-fsanitize=address "
+ "-mno-omit-leaf-frame-pointer "
+ "-fno-omit-frame-pointer "
+ "-fno-optimize-sibling-calls "
+ "-g")
config.substitutions.append( ("%clangxx_asan ", (" " + config.clang + " " +
clang_asan_cxxflags + " ")) )
# Setup path to external LLVM symbolizer to run AddressSanitizer output tests.
llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
if llvm_tools_dir:
config.environment['LLVM_SYMBOLIZER_PATH'] = os.path.join(
llvm_tools_dir, "llvm-symbolizer")
# Setup path to symbolizer script.
# FIXME: Instead we should copy this script to the build tree and point
# at it there.
asan_source_dir = os.path.join(config.test_source_root, "..")
symbolizer = os.path.join(asan_source_dir,
'scripts', '')
if not os.path.exists(symbolizer):
lit.fatal("Can't find symbolizer script on path %r" % symbolizer)
# Define %symbolize substitution that filters output through
# symbolizer and c++filt (for demangling).
config.substitutions.append( ("%symbolize ", (" " + symbolizer +
" | c++filt " )))
# Define CHECK-%os to check for OS-dependent output.
config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']
# AddressSanitizer tests are currently supported on Linux and Darwin only.
if config.host_os not in ['Linux', 'Darwin']:
config.unsupported = True