blob: a04c113269f2990e2e3fa66cd6d14983d278b3e1 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001# -*- Python -*-
2
3# Common configuration for running leak detection tests under LSan/ASan.
4
5import os
6
7def get_required_attr(config, attr_name):
8 attr_value = getattr(config, attr_name, None)
9 if attr_value == None:
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
15
16# Setup source root.
17config.test_source_root = os.path.dirname(__file__)
18
19# Choose between standalone and LSan+ASan modes.
20lsan_lit_test_mode = get_required_attr(config, 'lsan_lit_test_mode')
21if lsan_lit_test_mode == "Standalone":
22 config.name = "LeakSanitizer-Standalone"
23 lsan_cflags = ["-fsanitize=leak"]
24elif lsan_lit_test_mode == "AddressSanitizer":
25 config.name = "LeakSanitizer-AddressSanitizer"
26 lsan_cflags = ["-fsanitize=address"]
27 config.available_features.add('asan')
Stephen Hines2d1fdb22014-05-28 23:58:16 -070028else:
29 lit_config.fatal("Unknown LSan test mode: %r" % lsan_lit_test_mode)
Pirama Arumuga Nainarc58a4362016-09-19 23:00:23 -070030config.name += config.name_suffix
Stephen Hines2d1fdb22014-05-28 23:58:16 -070031
Pirama Arumuga Nainarc58a4362016-09-19 23:00:23 -070032clang_cflags = ["-O0", config.target_cflags] + config.debug_info_flags
Stephen Hines2d1fdb22014-05-28 23:58:16 -070033clang_cxxflags = config.cxx_mode_flags + clang_cflags
34clang_lsan_cflags = clang_cflags + lsan_cflags
35clang_lsan_cxxflags = clang_cxxflags + lsan_cflags
36
37config.clang_cflags = clang_cflags
38config.clang_cxxflags = clang_cxxflags
39
40def build_invocation(compile_flags):
41 return " " + " ".join([config.clang] + compile_flags) + " "
42
43config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) )
44config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) )
45config.substitutions.append( ("%clang_lsan ", build_invocation(clang_lsan_cflags)) )
46config.substitutions.append( ("%clangxx_lsan ", build_invocation(clang_lsan_cxxflags)) )
47
Stephen Hines86277eb2015-03-23 12:06:32 -070048# LeakSanitizer tests are currently supported on x86-64 Linux and mips64 Linux only.
49if config.host_os not in ['Linux'] or config.host_arch not in ['x86_64', 'mips64']:
Stephen Hines2d1fdb22014-05-28 23:58:16 -070050 config.unsupported = True
51
52config.suffixes = ['.c', '.cc', '.cpp']