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
|
2017-04-11 22:58:26 +08:00
|
|
|
import re
|
2013-05-23 20:58:56 +08:00
|
|
|
|
2017-02-08 16:43:44 +08:00
|
|
|
import lit.util
|
|
|
|
|
2013-05-23 20:58:56 +08:00
|
|
|
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
|
|
|
|
2017-04-19 04:56:56 +08:00
|
|
|
# Platform-specific default LSAN_OPTIONS for lit tests.
|
2017-04-21 05:00:02 +08:00
|
|
|
default_lsan_opts = 'detect_leaks=1'
|
2017-04-19 04:56:59 +08:00
|
|
|
if config.host_os == 'Darwin':
|
|
|
|
# On Darwin, we default to `abort_on_error=1`, which would make tests run
|
|
|
|
# much slower. Let's override this and run lit tests with 'abort_on_error=0'.
|
|
|
|
# Also, make sure we do not overwhelm the syslog while testing.
|
2017-04-21 05:00:02 +08:00
|
|
|
default_lsan_opts += ':abort_on_error=0'
|
2017-04-19 04:56:59 +08:00
|
|
|
default_lsan_opts += ':log_to_syslog=0'
|
|
|
|
|
2017-04-19 04:56:56 +08:00
|
|
|
if default_lsan_opts:
|
|
|
|
config.environment['LSAN_OPTIONS'] = default_lsan_opts
|
|
|
|
default_lsan_opts += ':'
|
|
|
|
config.substitutions.append(('%env_lsan_opts=',
|
|
|
|
'env LSAN_OPTIONS=' + default_lsan_opts))
|
|
|
|
|
2017-02-08 16:43:44 +08:00
|
|
|
if lit.util.which('strace'):
|
|
|
|
config.available_features.add('strace')
|
|
|
|
|
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
|
2016-11-14 19:40:56 +08:00
|
|
|
lsan_incdir = config.test_source_root + "/../"
|
|
|
|
clang_lsan_cflags = clang_cflags + lsan_cflags + ["-I%s" % lsan_incdir]
|
|
|
|
clang_lsan_cxxflags = clang_cxxflags + lsan_cflags + ["-I%s" % lsan_incdir]
|
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
|
|
|
|
2017-05-12 23:10:05 +08:00
|
|
|
# LeakSanitizer tests are currently supported on x86-64 Linux, PowerPC64 Linux, arm Linux, mips64 Linux, and x86_64 Darwin.
|
2017-10-27 04:59:04 +08:00
|
|
|
supported_linux = config.host_os is 'Linux' and config.host_arch in ['x86_64', 'ppc64', 'ppc64le', 'mips64', 'arm', 'armhf', 'armv7l']
|
2017-05-12 23:10:05 +08:00
|
|
|
supported_darwin = config.host_os is 'Darwin' and config.target_arch is 'x86_64'
|
|
|
|
if not (supported_linux or supported_darwin):
|
2017-04-11 22:58:26 +08:00
|
|
|
config.unsupported = True
|
|
|
|
|
|
|
|
# Don't support Thumb due to broken fast unwinder
|
2017-04-13 20:00:56 +08:00
|
|
|
if re.search('mthumb', config.target_cflags) is not None:
|
2013-05-23 20:58:56 +08:00
|
|
|
config.unsupported = True
|
2013-05-31 21:13:55 +08:00
|
|
|
|
2017-06-20 03:21:31 +08:00
|
|
|
config.suffixes = ['.c', '.cc', '.cpp', '.mm']
|