diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-08-31 12:51:22 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-08-31 12:51:22 -0400 |
commit | f74916a98f97c7e80e46400e921d54466285d1fb (patch) | |
tree | dc1859cd46e31bdc36289f6b7a0f2207e90d6d2e /src | |
parent | 1f7dc823c5077101e4b0760ded1d7259d57d7506 (diff) | |
download | tor-f74916a98f97c7e80e46400e921d54466285d1fb.tar.gz tor-f74916a98f97c7e80e46400e921d54466285d1fb.zip |
setup_capture_of_logs: no longer suppress log messages
Previously setup_capture_of_logs would prevent log messages from
going to the console entirely. That's a problem, since sometimes
log messages are bugs! Now setup_capture_of_logs() acts sensibly.
If you really do need to keep a message from going to the console
entirely, there is setup_full_capture_of_logs(). But only use that
if you're prepared to make sure that there are no extraneous
messages generated at all.
Diffstat (limited to 'src')
-rw-r--r-- | src/common/log.c | 5 | ||||
-rw-r--r-- | src/common/torlog.h | 5 | ||||
-rw-r--r-- | src/test/log_test_helpers.c | 16 | ||||
-rw-r--r-- | src/test/log_test_helpers.h | 5 |
4 files changed, 30 insertions, 1 deletions
diff --git a/src/common/log.c b/src/common/log.c index cb62a37e52..71b67906b7 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -534,6 +534,11 @@ tor_log(int severity, log_domain_mask_t domain, const char *format, ...) if (severity > log_global_min_severity_) return; va_start(ap,format); +#ifdef TOR_UNIT_TESTS + if (domain & LD_NO_MOCK) + logv__real(severity, domain, NULL, NULL, format, ap); + else +#endif logv(severity, domain, NULL, NULL, format, ap); va_end(ap); } diff --git a/src/common/torlog.h b/src/common/torlog.h index 80f37e0e48..6732a42741 100644 --- a/src/common/torlog.h +++ b/src/common/torlog.h @@ -109,6 +109,11 @@ * would. Used as a flag, not a log domain. */ #define LD_NOFUNCNAME (1u<<30) +#ifdef TOR_UNIT_TESTS +/** This log message should not be intercepted by mock_saving_logv */ +#define LD_NO_MOCK (1u<<29) +#endif + /** Mask of zero or more log domains, OR'd together. */ typedef uint32_t log_domain_mask_t; diff --git a/src/test/log_test_helpers.c b/src/test/log_test_helpers.c index 1828689d1d..8b67c39bca 100644 --- a/src/test/log_test_helpers.c +++ b/src/test/log_test_helpers.c @@ -6,6 +6,16 @@ static smartlist_t *saved_logs = NULL; +static int echo_to_real_logs = 1; + +int +setup_full_capture_of_logs(int new_level) +{ + int result = setup_capture_of_logs(new_level); + echo_to_real_logs = 0; + return result; +} + int setup_capture_of_logs(int new_level) { @@ -14,6 +24,7 @@ setup_capture_of_logs(int new_level) mock_clean_saved_logs(); saved_logs = smartlist_new(); MOCK(logv, mock_saving_logv); + echo_to_real_logs = 1; return previous_log; } @@ -108,7 +119,6 @@ mock_saving_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap) { - (void)domain; char *buf = tor_malloc_zero(10240); int n; n = tor_vsnprintf(buf,10240,format,ap); @@ -127,5 +137,9 @@ mock_saving_logv(int severity, log_domain_mask_t domain, if (!saved_logs) saved_logs = smartlist_new(); smartlist_add(saved_logs, e); + + if (echo_to_real_logs) { + tor_log(severity, domain|LD_NO_MOCK, "%s", e->generated_msg); + } } diff --git a/src/test/log_test_helpers.h b/src/test/log_test_helpers.h index d767453a6e..2cb76b2767 100644 --- a/src/test/log_test_helpers.h +++ b/src/test/log_test_helpers.h @@ -22,6 +22,7 @@ void mock_saving_logv(int severity, log_domain_mask_t domain, void mock_clean_saved_logs(void); const smartlist_t *mock_saved_logs(void); int setup_capture_of_logs(int new_level); +int setup_full_capture_of_logs(int new_level); void teardown_capture_of_logs(int prev); int mock_saved_log_has_message(const char *msg); @@ -33,6 +34,10 @@ int mock_saved_log_has_entry(void); tt_assert_msg(mock_saved_log_has_message(str), \ "expected log to contain " # str); +#define expect_log_msg_containing(str) \ + tt_assert_msg(mock_saved_log_has_message_containing(str), \ + "expected log to contain " # str); + #define expect_no_log_msg(str) \ tt_assert_msg(!mock_saved_log_has_message(str), \ "expected log to not contain " # str); |