Move MSan lit-tests under test/msan
[blocksruntime.git] / lib / asan / lit_tests / lit.cfg
blobde18cd66977041d41bb94c2a45aa58d92468df91
1 # -*- Python -*-
3 import os
5 import lit.util
7 def get_required_attr(config, attr_name):
8   attr_value = getattr(config, attr_name, None)
9   if not attr_value:
10     lit_config.fatal(
11       "No attribute %r in test configuration! You may need to run "
12       "tests from your build directory or add this attribute "
13       "to lit.site.cfg " % attr_name)
14   return attr_value
16 # Setup config name.
17 config.name = 'AddressSanitizer' + config.name_suffix
19 # Setup source root.
20 config.test_source_root = os.path.dirname(__file__)
22 def DisplayNoConfigMessage():
23   lit_config.fatal("No site specific configuration available! " +
24                    "Try running your test from the build tree or running " +
25                    "make check-asan")
27 # Figure out LLVM source root.
28 llvm_src_root = getattr(config, 'llvm_src_root', None)
29 if llvm_src_root is None:
30   # We probably haven't loaded the site-specific configuration: the user
31   # is likely trying to run a test file directly, and the site configuration
32   # wasn't created by the build system.
33   asan_site_cfg = lit_config.params.get('asan_site_config', None)
34   if (asan_site_cfg) and (os.path.exists(asan_site_cfg)):
35     lit_config.load_config(config, asan_site_cfg)
36     raise SystemExit
38   # Try to guess the location of site-specific configuration using llvm-config
39   # util that can point where the build tree is.
40   llvm_config = lit.util.which("llvm-config", config.environment["PATH"])
41   if not llvm_config:
42     DisplayNoConfigMessage()
44   # Find out the presumed location of generated site config.
45   llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
46   asan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
47                                "lib", "asan", "lit_tests", "lit.site.cfg")
48   if (not asan_site_cfg) or (not os.path.exists(asan_site_cfg)):
49     DisplayNoConfigMessage()
51   lit_config.load_config(config, asan_site_cfg)
52   raise SystemExit
54 # Setup default compiler flags used with -fsanitize=address option.
55 # FIXME: Review the set of required flags and check if it can be reduced.
56 target_cflags = " " + config.target_cflags
57 clang_asan_cflags = (" -fsanitize=address"
58                    + " -mno-omit-leaf-frame-pointer"
59                    + " -fno-omit-frame-pointer"
60                    + " -fno-optimize-sibling-calls"
61                    + " -g"
62                    + target_cflags)
63 clang_asan_cxxflags = " --driver-mode=g++" + clang_asan_cflags
65 if config.android == "TRUE":
66   config.available_features.add('android')
67   clang_wrapper = os.path.join(config.asan_source_dir, "lit_tests",
68                                "android_commands", "android_compile.py") + " "
69 else:
70   clang_wrapper = ""
72 config.substitutions.append( ("%clang ", " " + clang_wrapper + config.clang + target_cflags + " "))
73 config.substitutions.append( ("%clangxx ", (" " + clang_wrapper + config.clang +
74                                             " --driver-mode=g++" +
75                                             target_cflags + " ")) )
76 config.substitutions.append( ("%clang_asan ", (" " + clang_wrapper + config.clang + " " +
77                                               clang_asan_cflags + " ")) )
78 config.substitutions.append( ("%clangxx_asan ", (" " + clang_wrapper + config.clang + " " +
79                                                 clang_asan_cxxflags + " ")) )
82 # Setup path to asan_symbolize.py script.
83 asan_source_dir = get_required_attr(config, "asan_source_dir")
84 asan_symbolize = os.path.join(asan_source_dir, "scripts", "asan_symbolize.py")
85 if not os.path.exists(asan_symbolize):
86   lit_config.fatal("Can't find script on path %r" % asan_symbolize)
87 python_exec = get_required_attr(config, "python_executable")
88 config.substitutions.append( ("%asan_symbolize", python_exec + " " + asan_symbolize + " ") )
90 # Define CHECK-%os to check for OS-dependent output.
91 config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
93 config.available_features.add("asan-" + config.bits + "-bits")
95 # Turn on leak detection on 64-bit Linux.
96 if config.host_os == 'Linux' and config.bits == '64':
97   config.environment['ASAN_OPTIONS'] = 'detect_leaks=1'
99 # Default test suffixes.
100 config.suffixes = ['.c', '.cc', '.cpp']
102 # AddressSanitizer tests are currently supported on Linux and Darwin only.
103 if config.host_os not in ['Linux', 'Darwin']:
104   config.unsupported = True