[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Treat all nonfatal assertion failures as unit test failures.
commit 3269307dafafa8c7c2c3e0be5d5c3cb5e7df3153
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu Sep 8 13:27:30 2016 -0400
Treat all nonfatal assertion failures as unit test failures.
Part of 19999.
---
changes/bug19999_prep | 2 ++
src/common/util_bug.c | 16 ++++++++++++++++
src/common/util_bug.h | 1 +
src/test/testing_common.c | 7 +++++++
4 files changed, 26 insertions(+)
diff --git a/changes/bug19999_prep b/changes/bug19999_prep
index e8bb4a5..769c870 100644
--- a/changes/bug19999_prep
+++ b/changes/bug19999_prep
@@ -12,6 +12,8 @@
- Our link-handshake unit tests now check, that when invalid
handshakes fail, they fail with the error messages we
expected.
+ - The unit tests now treat any failure of a "tor_assert_nonfatal()"
+ assertion as a test failure.
o Minor bugfixes (unit tests):
- The tor_tls_server_info_callback unit test no longer crashes when
diff --git a/src/common/util_bug.c b/src/common/util_bug.c
index f1cd336..08aba47 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
}
diff --git a/src/common/util_bug.h b/src/common/util_bug.h
index 049ca1a..8b69a47 100644
--- a/src/common/util_bug.h
+++ b/src/common/util_bug.h
@@ -153,6 +153,7 @@ void tor_bug_occurred_(const char *fname, unsigned int line,
void tor_capture_bugs_(int n);
void tor_end_capture_bugs_(void);
const struct smartlist_t *tor_get_captured_bug_log_(void);
+void tor_set_failed_assertion_callback(void (*fn)(void));
#endif
#endif
diff --git a/src/test/testing_common.c b/src/test/testing_common.c
index 6460713..29f36a3 100644
--- a/src/test/testing_common.c
+++ b/src/test/testing_common.c
@@ -217,6 +217,12 @@ const struct testcase_setup_t passthrough_setup = {
passthrough_test_setup, passthrough_test_cleanup
};
+static void
+an_assertion_failed(void)
+{
+ tinytest_set_test_failed_();
+}
+
/** Main entry point for unit test code: parse the command line, and run
* some unit tests. */
int
@@ -299,6 +305,7 @@ main(int c, const char **v)
tor_free(errmsg);
return 1;
}
+ tor_set_failed_assertion_callback(an_assertion_failed);
atexit(remove_directory);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits