diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-09-08 13:27:30 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-09-08 13:27:30 -0400 |
commit | 3269307dafafa8c7c2c3e0be5d5c3cb5e7df3153 (patch) | |
tree | c44e2b743f72efa5eca1009675d0aac047310c7e /src/common/util_bug.c | |
parent | 6a1454aa462c7a1ef8d84fe703d4f28e727ca1c0 (diff) | |
download | tor-3269307dafafa8c7c2c3e0be5d5c3cb5e7df3153.tar.gz tor-3269307dafafa8c7c2c3e0be5d5c3cb5e7df3153.zip |
Treat all nonfatal assertion failures as unit test failures.
Part of 19999.
Diffstat (limited to 'src/common/util_bug.c')
-rw-r--r-- | src/common/util_bug.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/util_bug.c b/src/common/util_bug.c index f1cd33642e..08aba47974 100644 --- a/src/common/util_bug.c +++ b/src/common/util_bug.c @@ -14,6 +14,7 @@ #include "container.h" #ifdef TOR_UNIT_TESTS +static void (*failed_assertion_cb)(void) = NULL; static int n_bugs_to_capture = 0; static smartlist_t *bug_messages = NULL; #define capturing_bugs() (bug_messages != NULL && n_bugs_to_capture) @@ -45,6 +46,15 @@ add_captured_bug(const char *s) --n_bugs_to_capture; smartlist_add(bug_messages, tor_strdup(s)); } +/** Set a callback to be invoked when we get any tor_bug_occurred_ + * invocation. We use this in the unit tests so that a nonfatal + * assertion failure can also count as a test failure. + */ +void +tor_set_failed_assertion_callback(void (*fn)(void)) +{ + failed_assertion_cb = fn; +} #else #define capturing_bugs() (0) #define add_captured_bug(s) do { } while (0) @@ -95,5 +105,11 @@ tor_bug_occurred_(const char *fname, unsigned int line, expr, func, fname, line); } log_backtrace(LOG_WARN, LD_BUG, buf); + +#ifdef TOR_UNIT_TESTS + if (failed_assertion_cb) { + failed_assertion_cb(); + } +#endif } |