blob: 71a700c6ac3b332a608f335610dd758848d69990 [file] [log] [blame]
Alexey Samsonov7274ff82012-07-31 15:43:11 +00001# -*- Python -*-
2
3import os
4
Daniel Dunbara1b15b42013-08-09 22:14:01 +00005import lit.util
6
Alexey Samsonov57434a32013-05-27 09:35:24 +00007def get_required_attr(config, attr_name):
8 attr_value = getattr(config, attr_name, None)
9 if not attr_value:
Daniel Dunbara1b15b42013-08-09 22:14:01 +000010 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)
Alexey Samsonov57434a32013-05-27 09:35:24 +000014 return attr_value
15
Alexey Samsonov7274ff82012-07-31 15:43:11 +000016# Setup config name.
Alexey Samsonov244a8e02013-08-07 09:31:28 +000017config.name = 'AddressSanitizer' + config.bits
Alexey Samsonov7274ff82012-07-31 15:43:11 +000018
19# Setup source root.
20config.test_source_root = os.path.dirname(__file__)
21
Alexey Samsonov4a78b1e2012-09-05 10:41:25 +000022def DisplayNoConfigMessage():
Daniel Dunbara1b15b42013-08-09 22:14:01 +000023 lit_config.fatal("No site specific configuration available! " +
24 "Try running your test from the build tree or running " +
25 "make check-asan")
Alexey Samsonov4a78b1e2012-09-05 10:41:25 +000026
27# Figure out LLVM source root.
28llvm_src_root = getattr(config, 'llvm_src_root', None)
29if 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.
Daniel Dunbara1b15b42013-08-09 22:14:01 +000033 asan_site_cfg = lit_config.params.get('asan_site_config', None)
Alexey Samsonov4a78b1e2012-09-05 10:41:25 +000034 if (asan_site_cfg) and (os.path.exists(asan_site_cfg)):
Daniel Dunbara1b15b42013-08-09 22:14:01 +000035 lit_config.load_config(config, asan_site_cfg)
Alexey Samsonov4a78b1e2012-09-05 10:41:25 +000036 raise SystemExit
37
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()
43
Alexey Samsonov4a78b1e2012-09-05 10:41:25 +000044 # 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()
50
Daniel Dunbara1b15b42013-08-09 22:14:01 +000051 lit_config.load_config(config, asan_site_cfg)
Alexey Samsonov4a78b1e2012-09-05 10:41:25 +000052 raise SystemExit
53
Richard Smithf10a79a2012-11-06 02:31:42 +000054# Setup default compiler flags used with -fsanitize=address option.
Alexey Samsonov7274ff82012-07-31 15:43:11 +000055# FIXME: Review the set of required flags and check if it can be reduced.
Alexey Samsonov6efa4d62013-06-07 09:38:55 +000056bits_cflag = " -m" + config.bits
57clang_asan_cflags = (" -fsanitize=address"
58 + " -mno-omit-leaf-frame-pointer"
59 + " -fno-omit-frame-pointer"
60 + " -fno-optimize-sibling-calls"
61 + " -g"
62 + bits_cflag)
Hans Wennborgf021f4f2013-07-18 20:48:50 +000063clang_asan_cxxflags = " --driver-mode=g++" + clang_asan_cflags
Alexey Samsonov6efa4d62013-06-07 09:38:55 +000064config.substitutions.append( ("%clang ", " " + config.clang + bits_cflag + " "))
Hans Wennborgf021f4f2013-07-18 20:48:50 +000065config.substitutions.append( ("%clangxx ", (" " + config.clang +
66 " --driver-mode=g++" +
Alexey Samsonov6efa4d62013-06-07 09:38:55 +000067 bits_cflag + " ")) )
68config.substitutions.append( ("%clang_asan ", (" " + config.clang + " " +
69 clang_asan_cflags + " ")) )
Alexey Samsonov589231c2012-08-15 08:54:14 +000070config.substitutions.append( ("%clangxx_asan ", (" " + config.clang + " " +
71 clang_asan_cxxflags + " ")) )
Alexey Samsonov7274ff82012-07-31 15:43:11 +000072
Alexey Samsonov997aede2013-07-01 09:15:19 +000073# Setup path to asan_symbolize.py script.
74asan_source_dir = get_required_attr(config, "asan_source_dir")
75asan_symbolize = os.path.join(asan_source_dir, "scripts", "asan_symbolize.py")
76if not os.path.exists(asan_symbolize):
Daniel Dunbara1b15b42013-08-09 22:14:01 +000077 lit_config.fatal("Can't find script on path %r" % asan_symbolize)
Will Dietz782cbdc2013-10-17 05:33:22 +000078python_exec = get_required_attr(config, "python_executable")
79config.substitutions.append( ("%asan_symbolize", python_exec + " " + asan_symbolize + " ") )
Alexey Samsonov997aede2013-07-01 09:15:19 +000080
Alexey Samsonov41f85b92012-08-15 08:29:17 +000081# Define CHECK-%os to check for OS-dependent output.
82config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
83
Alexey Samsonov6efa4d62013-06-07 09:38:55 +000084config.available_features.add("asan-" + config.bits + "-bits")
85
Alexey Samsonov1a249182013-09-08 13:23:29 +000086# Turn on leak detection on 64-bit Linux.
87if config.host_os == 'Linux' and config.bits == '64':
88 config.environment['ASAN_OPTIONS'] = 'detect_leaks=1'
89
Alexey Samsonov7274ff82012-07-31 15:43:11 +000090# Default test suffixes.
91config.suffixes = ['.c', '.cc', '.cpp']
Alexey Samsonov41f85b92012-08-15 08:29:17 +000092
93# AddressSanitizer tests are currently supported on Linux and Darwin only.
94if config.host_os not in ['Linux', 'Darwin']:
95 config.unsupported = True