Skip to content

Commit

Permalink
Merge pull request #3086 from sfc-gh-ebrossard:master
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 340226421
  • Loading branch information
suertreus committed Nov 3, 2020
2 parents 2828773 + bd619de commit ee2c62a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions googletest/docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit ee2c62a

Please sign in to comment.