[tor-commits] [tor/master] Fail any unit test that causes an unhandled LD_BUG or LOG_ERR

dgoulet at torproject.org dgoulet at torproject.org
Wed Feb 13 16:06:57 UTC 2019


commit f684cd800577144a48e112951eaf4ddc602ad26a
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Jan 16 15:47:33 2019 -0500

    Fail any unit test that causes an unhandled LD_BUG or LOG_ERR
    
    Closes ticket 28668.
---
 changes/ticket28668       |  3 +++
 src/test/testing_common.c | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/changes/ticket28668 b/changes/ticket28668
new file mode 100644
index 000000000..6386e0051
--- /dev/null
+++ b/changes/ticket28668
@@ -0,0 +1,3 @@
+  o Minor features (testing):
+    - Treat all unexpected ERR and BUG messages as test failures.
+      Closes ticket 28668.
diff --git a/src/test/testing_common.c b/src/test/testing_common.c
index 60015f3c2..62d40a42f 100644
--- a/src/test/testing_common.c
+++ b/src/test/testing_common.c
@@ -239,6 +239,15 @@ tinytest_postfork(void)
   init_pregenerated_keys();
 }
 
+static void
+log_callback_failure(int severity, uint32_t domain, const char *msg)
+{
+  (void)msg;
+  if (severity == LOG_ERR || (domain & LD_BUG)) {
+    tinytest_set_test_failed_();
+  }
+}
+
 /** Main entry point for unit test code: parse the command line, and run
  * some unit tests. */
 int
@@ -287,6 +296,7 @@ main(int c, const char **v)
   c = i_out;
 
   {
+    /* setup logs to stdout */
     log_severity_list_t s;
     memset(&s, 0, sizeof(s));
     set_log_severity_config(loglevel, LOG_ERR, &s);
@@ -294,6 +304,14 @@ main(int c, const char **v)
     s.masks[LOG_WARN-LOG_ERR] |= LD_BUG;
     add_stream_log(&s, "", fileno(stdout));
   }
+  {
+    /* Setup logs that cause failure. */
+    log_severity_list_t s;
+    memset(&s, 0, sizeof(s));
+    set_log_severity_config(LOG_ERR, LOG_ERR, &s);
+    s.masks[LOG_WARN-LOG_ERR] |= LD_BUG;
+    add_callback_log(&s, log_callback_failure);
+  }
   init_protocol_warning_severity_level();
 
   options->command = CMD_RUN_UNITTESTS;





More information about the tor-commits mailing list