marking gtest runs as failed when errors by sanitizers are found


as in the topic. Currently when errors by clang sanitizers are found the tests is still marked as passed which complicates our CI because we’d need to implement parsing of console output. Is there a way to make gtest fail in such situation?



What specific sanitizer do you refer to? They behave differently - e.g. ASan and MSan by default crash the process after the fist bug is found. TSan prints all the error reports, and tries to crash the process with non-zero exitcode at the end, if at least one issue was found. UBSan by default doesn’t crash the process, but can be instructed to do so by adding -fno-sanitize-recover=all to your compile flags.


the problem I’m getting that doesn’t cause any of the desired effects you described is this:

runtime error: unsigned integer overflow: 1 - 32 cannot be represented in type ‘unsigned int’
SUMMARY: AddressSanitizer: undefined-behavior

Maybe it’s the only issue that doesn’t crash the process


You can try either of the following:
a) compile your code with -fno-sanitize-recover=all. Then all UBSan errors should be fatal.
b) run your executable with setting up the environment variable UBSAN_OPTIONS=halt_on_error=1
(like this: UBSAN_OPTIONS=halt_on_error=1 ./path/to/your/executable, setenv() in program will not work).

Let me know if it helps.

it helps. Thanks!