3

Is it possible to set some sort of a callback, which will be called when clang sanitizers find an error? I need to print some useful information, such as - test name.

P.S. Tests are kept/stored as XML files, not in C++, that is why stack trace won't tell me the failed test name.

willir
  • 599
  • 1
  • 4
  • 15

1 Answers1

3

There are __sanitizer_set_death_callback and __asan_set_error_report_callback (declared in asan_interface.h).

Also as pointed by willir, it may be enough to just run with ASAN_OPTIONS=abort_on_error=1. This will cause Asan to call abort on error and many unit testing frameworks can then skip failing test and continue execution.

yugr
  • 19,769
  • 3
  • 51
  • 96
  • 1
    Thanks for your response. I'd like to add that it seems, in many cases just `ASAN_OPTIONS=abort_on_error` environment variable is enough. It makes sanitizer call `abort` instead of `_exit` and so you can handle it. Most test frameworks already handle `abort`. – willir Jan 07 '18 at 17:40