diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-09-08 15:01:32 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-09-08 15:03:11 -0400 |
commit | deb294ff532d074a7d4094518c296fe69f819874 (patch) | |
tree | 3a49b6c30ab041807a025fa463ff57ca328165db /src/test/log_test_helpers.c | |
parent | b0a9e54705d16d08ae7aff272492832dbb35646d (diff) | |
download | tor-deb294ff532d074a7d4094518c296fe69f819874.tar.gz tor-deb294ff532d074a7d4094518c296fe69f819874.zip |
Simplify log_test_helpers interface
Previously, you needed to store the previous log severity in a local
variable, and it wasn't clear if you were allowed to call these
functions more than once.
Diffstat (limited to 'src/test/log_test_helpers.c')
-rw-r--r-- | src/test/log_test_helpers.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/test/log_test_helpers.c b/src/test/log_test_helpers.c index 7f7f1d1d42..3dc926dd3f 100644 --- a/src/test/log_test_helpers.c +++ b/src/test/log_test_helpers.c @@ -26,6 +26,8 @@ static int echo_to_real_logs = 1; /** Record logs at this level or more severe */ static int record_logs_at_level = LOG_ERR; +static int saved_log_level = 0; + /** * As setup_capture_of_logs, but do not relay log messages into the main * logging system. @@ -33,26 +35,28 @@ static int record_logs_at_level = LOG_ERR; * Avoid using this function; use setup_capture_of_logs() instead if you * can. If you must use this function, then make sure you detect any * unexpected log messages, and treat them as test failures. */ -int +void setup_full_capture_of_logs(int new_level) { - int result = setup_capture_of_logs(new_level); + setup_capture_of_logs(new_level); echo_to_real_logs = 0; - return result; } /** * Temporarily capture all the messages logged at severity <b>new_level</b> or - * higher. Return the previous log level; you'll need to pass it into - * teardown_capture_of_logs(). + * higher. * * This function does not prevent messages from being sent to the main * logging system. */ -int +void setup_capture_of_logs(int new_level) { - int previous_log = log_global_min_severity_; + if (saved_log_level == 0) { + saved_log_level = log_global_min_severity_; + } else { + tor_assert(0); + } /* Only change the log_global_min_severity_ if we're making things _more_ * verbose. Otherwise we could prevent real log messages that the test- @@ -66,17 +70,20 @@ setup_capture_of_logs(int new_level) saved_logs = smartlist_new(); MOCK(logv, mock_saving_logv); echo_to_real_logs = 1; - return previous_log; } /** * Undo setup_capture_of_logs(). + * + * This function is safe to call more than once. */ void -teardown_capture_of_logs(int prev) +teardown_capture_of_logs(void) { UNMOCK(logv); - log_global_min_severity_ = prev; + if (saved_log_level) + log_global_min_severity_ = saved_log_level; + saved_log_level = 0; mock_clean_saved_logs(); } |