2013-05-23 20:58:56 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
2013-05-31 21:13:55 +08:00
|
|
|
# Common configuration for running leak detection tests under LSan/ASan.
|
|
|
|
|
2013-05-23 20:58:56 +08:00
|
|
|
import os
|
|
|
|
|
|
|
|
def get_required_attr(config, attr_name):
|
|
|
|
attr_value = getattr(config, attr_name, None)
|
2014-05-01 05:32:30 +08:00
|
|
|
if attr_value == None:
|
2013-08-10 06:14:01 +08:00
|
|
|
lit_config.fatal(
|
|
|
|
"No attribute %r in test configuration! You may need to run "
|
|
|
|
"tests from your build directory or add this attribute "
|
|
|
|
"to lit.site.cfg " % attr_name)
|
2013-05-23 20:58:56 +08:00
|
|
|
return attr_value
|
|
|
|
|
|
|
|
# Setup source root.
|
2014-02-18 16:56:49 +08:00
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
# Choose between standalone and LSan+ASan modes.
|
|
|
|
lsan_lit_test_mode = get_required_attr(config, 'lsan_lit_test_mode')
|
|
|
|
if lsan_lit_test_mode == "Standalone":
|
|
|
|
config.name = "LeakSanitizer-Standalone"
|
|
|
|
lsan_cflags = ["-fsanitize=leak"]
|
|
|
|
elif lsan_lit_test_mode == "AddressSanitizer":
|
|
|
|
config.name = "LeakSanitizer-AddressSanitizer"
|
|
|
|
lsan_cflags = ["-fsanitize=address"]
|
|
|
|
config.available_features.add('asan')
|
|
|
|
else:
|
|
|
|
lit_config.fatal("Unknown LSan test mode: %r" % lsan_lit_test_mode)
|
2016-02-10 00:22:39 +08:00
|
|
|
config.name += config.name_suffix
|
2013-05-23 20:58:56 +08:00
|
|
|
|
2016-02-10 00:22:39 +08:00
|
|
|
clang_cflags = ["-O0", config.target_cflags] + config.debug_info_flags
|
2014-02-19 23:13:14 +08:00
|
|
|
clang_cxxflags = config.cxx_mode_flags + clang_cflags
|
2014-02-18 16:56:49 +08:00
|
|
|
clang_lsan_cflags = clang_cflags + lsan_cflags
|
|
|
|
clang_lsan_cxxflags = clang_cxxflags + lsan_cflags
|
2013-08-22 22:48:44 +08:00
|
|
|
|
2014-02-17 21:08:10 +08:00
|
|
|
config.clang_cflags = clang_cflags
|
2013-05-31 21:13:55 +08:00
|
|
|
config.clang_cxxflags = clang_cxxflags
|
2013-05-27 19:41:46 +08:00
|
|
|
|
2014-02-17 21:08:10 +08:00
|
|
|
def build_invocation(compile_flags):
|
|
|
|
return " " + " ".join([config.clang] + compile_flags) + " "
|
2013-08-22 22:48:44 +08:00
|
|
|
|
2014-02-17 21:08:10 +08:00
|
|
|
config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) )
|
|
|
|
config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) )
|
2014-02-18 16:56:49 +08:00
|
|
|
config.substitutions.append( ("%clang_lsan ", build_invocation(clang_lsan_cflags)) )
|
|
|
|
config.substitutions.append( ("%clangxx_lsan ", build_invocation(clang_lsan_cxxflags)) )
|
2013-08-22 22:48:44 +08:00
|
|
|
|
2015-02-19 17:14:43 +08:00
|
|
|
# LeakSanitizer tests are currently supported on x86-64 Linux and mips64 Linux only.
|
|
|
|
if config.host_os not in ['Linux'] or config.host_arch not in ['x86_64', 'mips64']:
|
2013-05-23 20:58:56 +08:00
|
|
|
config.unsupported = True
|
2013-05-31 21:13:55 +08:00
|
|
|
|
|
|
|
config.suffixes = ['.c', '.cc', '.cpp']
|