diff options
author | Elliott Brossard <elliott.brossard@snowflake.com> | 2020-10-27 15:31:34 +0000 |
---|---|---|
committer | Elliott Brossard <elliott.brossard@snowflake.com> | 2020-10-27 15:31:34 +0000 |
commit | bd619dee05a69da10382042674f020ceee9b5ce3 (patch) | |
tree | 940e63651a39b60edd20c568f7328e2e3803234b /googletest/docs | |
parent | 3005672db1d05f2378f642b61faa96f85498befe (diff) | |
download | googletest-git-bd619dee05a69da10382042674f020ceee9b5ce3.tar.gz |
Add instructions for sanitizer integration
Diffstat (limited to 'googletest/docs')
-rw-r--r-- | googletest/docs/advanced.md | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index 755e461e..89aca1cf 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -2609,3 +2609,32 @@ to be handled by the debugger, such that you can examine the call stack when an exception is thrown. To achieve that, set the `GTEST_CATCH_EXCEPTIONS` environment variable to `0`, or use the `--gtest_catch_exceptions=0` flag when running the tests. + +### Sanitizer Integration + +The +[Undefined Behavior Sanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html), +[Address Sanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer), +and +[Thread Sanitizer](https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual) +all provide weak functions that you can override to trigger explicit failures +when they detect sanitizer errors, such as creating a reference from `nullptr`. +To override these functions, place definitions for them in a source file that +you compile as part of your main binary: + +``` +extern "C" { +void __ubsan_on_report() { + FAIL() << "Encountered an undefined behavior sanitizer error"; +} +void __asan_on_error() { + FAIL() << "Encountered an address sanitizer error"; +} +void __tsan_on_report() { + FAIL() << "Encountered a thread sanitizer error"; +} +} // extern "C" +``` + +After compiling your project with one of the sanitizers enabled, if a particular +test triggers a sanitizer error, googletest will report that it failed. |