2012-10-17 22:04:57 +08:00
|
|
|
//===-- asan_test_main.cc -------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "asan_test_utils.h"
|
2015-07-28 22:34:13 +08:00
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
2012-10-17 22:04:57 +08:00
|
|
|
|
2017-04-20 04:39:09 +08:00
|
|
|
// Default ASAN_OPTIONS for the unit tests.
|
2015-07-20 23:03:39 +08:00
|
|
|
extern "C" const char* __asan_default_options() {
|
2015-07-28 22:34:13 +08:00
|
|
|
#if SANITIZER_MAC
|
|
|
|
// On Darwin, we default to `abort_on_error=1`, which would make tests run
|
2017-04-20 04:39:09 +08:00
|
|
|
// much slower. Let's override this and run lit tests with 'abort_on_error=0'
|
|
|
|
// and make sure we do not overwhelm the syslog while testing. Also, let's
|
|
|
|
// turn symbolization off to speed up testing, especially when not running
|
|
|
|
// with llvm-symbolizer but with atos.
|
Reapply: [asan] On OS X, log reports to syslog and os_trace
When ASan currently detects a bug, by default it will only print out the text
of the report to stderr. This patch changes this behavior and writes the full
text of the report to syslog before we terminate the process. It also calls
os_trace (Activity Tracing available on OS X and iOS) with a message saying
that the report is available in syslog. This is useful, because this message
will be shown in the crash log.
For this to work, the patch makes sure we store the full report into
error_message_buffer unconditionally, and it also strips out ANSI escape
sequences from the report (they are used when producing colored reports).
I've initially tried to log to syslog during printing, which is done on Android
right now. The advantage is that if we crash during error reporting or the
produced error does not go through ScopedInErrorReport, we would still get a
(partial) message in the syslog. However, that solution is very problematic on
OS X. One issue is that the logging routine uses GCD, which may spawn a new
thread on its behalf. In many cases, the reporting logic locks threadRegistry,
which leads to deadlocks.
Reviewed at http://reviews.llvm.org/D13452
(In addition, add sanitizer_common_libcdep.cc to buildgo.sh to avoid
build failures on Linux.)
llvm-svn: 253688
2015-11-21 02:41:44 +08:00
|
|
|
return "symbolize=false:abort_on_error=0:log_to_syslog=0";
|
2017-04-21 04:54:19 +08:00
|
|
|
#elif SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT
|
2017-04-20 04:39:09 +08:00
|
|
|
// On PowerPC and ARM Thumb, a couple tests involving pthread_exit fail due to
|
2017-04-21 04:54:19 +08:00
|
|
|
// leaks detected by LSan. Symbolized leak report is required to apply a
|
|
|
|
// suppression for this known problem.
|
2017-04-20 04:39:09 +08:00
|
|
|
return "";
|
2015-07-28 22:34:13 +08:00
|
|
|
#else
|
2017-04-20 04:39:09 +08:00
|
|
|
// Let's turn symbolization off to speed up testing (more than 3 times speedup
|
|
|
|
// observed).
|
2015-07-20 23:03:39 +08:00
|
|
|
return "symbolize=false";
|
2015-07-28 22:34:13 +08:00
|
|
|
#endif
|
2015-07-20 23:03:39 +08:00
|
|
|
}
|
|
|
|
|
[sanitizer] On OS X, verify that interceptors work and abort if not, take 2
On OS X 10.11+, we have "automatic interceptors", so we don't need to use DYLD_INSERT_LIBRARIES when launching instrumented programs. However, non-instrumented programs that load TSan late (e.g. via dlopen) are currently broken, as TSan will still try to initialize, but the program will crash/hang at random places (because the interceptors don't work). This patch adds an explicit check that interceptors are working, and if not, it aborts and prints out an error message suggesting to explicitly use DYLD_INSERT_LIBRARIES.
TSan unit tests run with a statically linked runtime, where interceptors don't work. To avoid aborting the process in this case, the patch replaces `DisableReexec()` with a weak `ReexecDisabled()` function which is defined to return true in unit tests.
Differential Revision: http://reviews.llvm.org/D18212
llvm-svn: 263695
2016-03-17 16:37:25 +08:00
|
|
|
namespace __sanitizer {
|
|
|
|
bool ReexecDisabled() {
|
2016-11-30 08:46:04 +08:00
|
|
|
#if __has_feature(address_sanitizer) && SANITIZER_MAC
|
|
|
|
// Allow re-exec in instrumented unit tests on Darwin. Technically, we only
|
|
|
|
// need this for 10.10 and below, where re-exec is required for the
|
|
|
|
// interceptors to work, but to avoid duplicating the version detection logic,
|
|
|
|
// let's just allow re-exec for all Darwin versions. On newer OS versions,
|
|
|
|
// returning 'false' doesn't do anything anyway, because we don't re-exec.
|
|
|
|
return false;
|
|
|
|
#else
|
[sanitizer] On OS X, verify that interceptors work and abort if not, take 2
On OS X 10.11+, we have "automatic interceptors", so we don't need to use DYLD_INSERT_LIBRARIES when launching instrumented programs. However, non-instrumented programs that load TSan late (e.g. via dlopen) are currently broken, as TSan will still try to initialize, but the program will crash/hang at random places (because the interceptors don't work). This patch adds an explicit check that interceptors are working, and if not, it aborts and prints out an error message suggesting to explicitly use DYLD_INSERT_LIBRARIES.
TSan unit tests run with a statically linked runtime, where interceptors don't work. To avoid aborting the process in this case, the patch replaces `DisableReexec()` with a weak `ReexecDisabled()` function which is defined to return true in unit tests.
Differential Revision: http://reviews.llvm.org/D18212
llvm-svn: 263695
2016-03-17 16:37:25 +08:00
|
|
|
return true;
|
2016-11-30 08:46:04 +08:00
|
|
|
#endif
|
[sanitizer] On OS X, verify that interceptors work and abort if not, take 2
On OS X 10.11+, we have "automatic interceptors", so we don't need to use DYLD_INSERT_LIBRARIES when launching instrumented programs. However, non-instrumented programs that load TSan late (e.g. via dlopen) are currently broken, as TSan will still try to initialize, but the program will crash/hang at random places (because the interceptors don't work). This patch adds an explicit check that interceptors are working, and if not, it aborts and prints out an error message suggesting to explicitly use DYLD_INSERT_LIBRARIES.
TSan unit tests run with a statically linked runtime, where interceptors don't work. To avoid aborting the process in this case, the patch replaces `DisableReexec()` with a weak `ReexecDisabled()` function which is defined to return true in unit tests.
Differential Revision: http://reviews.llvm.org/D18212
llvm-svn: 263695
2016-03-17 16:37:25 +08:00
|
|
|
}
|
2016-11-30 08:46:04 +08:00
|
|
|
} // namespace __sanitizer
|
[sanitizer] On OS X, verify that interceptors work and abort if not, take 2
On OS X 10.11+, we have "automatic interceptors", so we don't need to use DYLD_INSERT_LIBRARIES when launching instrumented programs. However, non-instrumented programs that load TSan late (e.g. via dlopen) are currently broken, as TSan will still try to initialize, but the program will crash/hang at random places (because the interceptors don't work). This patch adds an explicit check that interceptors are working, and if not, it aborts and prints out an error message suggesting to explicitly use DYLD_INSERT_LIBRARIES.
TSan unit tests run with a statically linked runtime, where interceptors don't work. To avoid aborting the process in this case, the patch replaces `DisableReexec()` with a weak `ReexecDisabled()` function which is defined to return true in unit tests.
Differential Revision: http://reviews.llvm.org/D18212
llvm-svn: 263695
2016-03-17 16:37:25 +08:00
|
|
|
|
2012-10-17 22:04:57 +08:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
testing::GTEST_FLAG(death_test_style) = "threadsafe";
|
|
|
|
testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|