[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Simplify log_test_helpers interface
commit deb294ff532d074a7d4094518c296fe69f819874
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu Sep 8 15:01:32 2016 -0400
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.
---
src/test/log_test_helpers.c | 27 +++++++----
src/test/log_test_helpers.h | 6 +--
src/test/test_address.c | 10 ++--
src/test/test_circuitlist.c | 9 ++--
src/test/test_compat_libevent.c | 4 +-
src/test/test_dir.c | 12 ++---
src/test/test_guardfraction.c | 9 ++--
src/test/test_link_handshake.c | 16 +++----
src/test/test_options.c | 104 ++++++++++++++++++++--------------------
src/test/test_rendcache.c | 18 +++----
src/test/test_tortls.c | 43 ++++++++---------
src/test/test_util.c | 19 ++++----
src/test/test_util_process.c | 8 ++--
13 files changed, 136 insertions(+), 149 deletions(-)
diff --git a/src/test/log_test_helpers.c b/src/test/log_test_helpers.c
index 7f7f1d1..3dc926d 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();
}
diff --git a/src/test/log_test_helpers.h b/src/test/log_test_helpers.h
index fd99084..4c020c7 100644
--- a/src/test/log_test_helpers.h
+++ b/src/test/log_test_helpers.h
@@ -18,9 +18,9 @@ typedef struct mock_saved_log_entry_t {
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);
+void setup_capture_of_logs(int new_level);
+void setup_full_capture_of_logs(int new_level);
+void teardown_capture_of_logs(void);
int mock_saved_log_has_message(const char *msg);
int mock_saved_log_has_message_containing(const char *msg);
diff --git a/src/test/test_address.c b/src/test/test_address.c
index 932dc38..0be4c54 100644
--- a/src/test/test_address.c
+++ b/src/test/test_address.c
@@ -795,7 +795,7 @@ test_address_get_if_addrs6_list_internal(void *arg)
(void)arg;
/* We might drop a log_err */
- int prev_level = setup_full_capture_of_logs(LOG_ERR);
+ setup_full_capture_of_logs(LOG_ERR);
results = get_interface_address6_list(LOG_ERR, AF_INET6, 1);
tt_int_op(smartlist_len(mock_saved_logs()), OP_LE, 1);
if (smartlist_len(mock_saved_logs()) == 1) {
@@ -803,7 +803,7 @@ test_address_get_if_addrs6_list_internal(void *arg)
"unable to create socket");
}
- teardown_capture_of_logs(prev_level);
+ teardown_capture_of_logs();
tt_assert(results != NULL);
/* Work even on systems without IPv6 interfaces */
@@ -822,6 +822,7 @@ test_address_get_if_addrs6_list_internal(void *arg)
done:
free_interface_address6_list(results);
+ teardown_capture_of_logs();
return;
}
@@ -833,7 +834,7 @@ test_address_get_if_addrs6_list_no_internal(void *arg)
(void)arg;
/* We might drop a log_err */
- int prev_level = setup_full_capture_of_logs(LOG_ERR);
+ setup_full_capture_of_logs(LOG_ERR);
results = get_interface_address6_list(LOG_ERR, AF_INET6, 0);
tt_int_op(smartlist_len(mock_saved_logs()), OP_LE, 1);
if (smartlist_len(mock_saved_logs()) == 1) {
@@ -841,7 +842,7 @@ test_address_get_if_addrs6_list_no_internal(void *arg)
"unable to create socket");
}
- teardown_capture_of_logs(prev_level);
+ teardown_capture_of_logs();
tt_assert(results != NULL);
/* Work even on systems without IPv6 interfaces */
@@ -859,6 +860,7 @@ test_address_get_if_addrs6_list_no_internal(void *arg)
}
done:
+ teardown_capture_of_logs();
free_interface_address6_list(results);
return;
}
diff --git a/src/test/test_circuitlist.c b/src/test/test_circuitlist.c
index 688515c..b233e99 100644
--- a/src/test/test_circuitlist.c
+++ b/src/test/test_circuitlist.c
@@ -285,7 +285,6 @@ test_pick_circid(void *arg)
circid_t circid;
int i;
(void) arg;
- int prev_level = 0;
MOCK(channel_dump_statistics, mock_channel_dump_statistics);
@@ -298,12 +297,11 @@ test_pick_circid(void *arg)
/* CIRC_ID_TYPE_NEITHER is supposed to create a warning. */
chan1->circ_id_type = CIRC_ID_TYPE_NEITHER;
- prev_level = setup_full_capture_of_logs(LOG_WARN);
+ setup_full_capture_of_logs(LOG_WARN);
tt_int_op(0, OP_EQ, get_unique_circ_id_by_chan(chan1));
expect_single_log_msg_containing("Trying to pick a circuit ID for a "
"connection from a client with no identity.");
- teardown_capture_of_logs(prev_level);
- prev_level = 0;
+ teardown_capture_of_logs();
/* Basic tests, with no collisions */
chan1->circ_id_type = CIRC_ID_TYPE_LOWER;
@@ -365,8 +363,7 @@ test_pick_circid(void *arg)
tor_free(chan2);
bitarray_free(ba);
circuit_free_all();
- if (prev_level)
- teardown_capture_of_logs(prev_level);
+ teardown_capture_of_logs();
UNMOCK(channel_dump_statistics);
}
diff --git a/src/test/test_compat_libevent.c b/src/test/test_compat_libevent.c
index 5e14be5..0443cc0 100644
--- a/src/test/test_compat_libevent.c
+++ b/src/test/test_compat_libevent.c
@@ -20,7 +20,7 @@ static void
test_compat_libevent_logging_callback(void *ignored)
{
(void)ignored;
- int previous_log = setup_full_capture_of_logs(LOG_DEBUG);
+ setup_full_capture_of_logs(LOG_DEBUG);
libevent_logging_callback(_EVENT_LOG_DEBUG, "hello world");
expect_log_msg("Message from libevent: hello world\n");
@@ -106,7 +106,7 @@ test_compat_libevent_logging_callback(void *ignored)
done:
suppress_libevent_log_msg(NULL);
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
}
static void
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 0afc0b7..4a6c5a9 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -3269,7 +3269,6 @@ static void
test_dir_fetch_type(void *arg)
{
(void)arg;
- int log_level = 0;
tt_int_op(dir_fetch_type(DIR_PURPOSE_FETCH_EXTRAINFO, ROUTER_PURPOSE_BRIDGE,
NULL), OP_EQ, EXTRAINFO_DIRINFO | BRIDGE_DIRINFO);
@@ -3298,13 +3297,12 @@ test_dir_fetch_type(void *arg)
/* This will give a warning, because this function isn't supposed to be
* used for HS descriptors. */
- log_level = setup_full_capture_of_logs(LOG_WARN);
+ setup_full_capture_of_logs(LOG_WARN);
tt_int_op(dir_fetch_type(DIR_PURPOSE_FETCH_RENDDESC_V2,
ROUTER_PURPOSE_GENERAL, NULL), OP_EQ, NO_DIRINFO);
expect_single_log_msg_containing("Unexpected purpose");
done:
- if (log_level)
- teardown_capture_of_logs(log_level);
+ teardown_capture_of_logs();
}
static void
@@ -3972,7 +3970,6 @@ static void
test_dir_conn_purpose_to_string(void *data)
{
(void)data;
- int log_level = 0;
#define EXPECT_CONN_PURPOSE(purpose, expected) \
tt_str_op(dir_conn_purpose_to_string(purpose), OP_EQ, expected);
@@ -3996,13 +3993,12 @@ test_dir_conn_purpose_to_string(void *data)
EXPECT_CONN_PURPOSE(DIR_PURPOSE_FETCH_MICRODESC, "microdescriptor fetch");
/* This will give a warning, because there is no purpose 1024. */
- log_level = setup_full_capture_of_logs(LOG_WARN);
+ setup_full_capture_of_logs(LOG_WARN);
EXPECT_CONN_PURPOSE(1024, "(unknown)");
expect_single_log_msg_containing("Called with unknown purpose 1024");
done:
- if (log_level)
- teardown_capture_of_logs(log_level);
+ teardown_capture_of_logs();
}
NS_DECL(int,
diff --git a/src/test/test_guardfraction.c b/src/test/test_guardfraction.c
index 3cc83f9..8173e44 100644
--- a/src/test/test_guardfraction.c
+++ b/src/test/test_guardfraction.c
@@ -281,7 +281,6 @@ test_parse_guardfraction_consensus(void *arg)
const char *guardfraction_str_bad2 = "GuardFraction=166"; /* no percentage */
routerstatus_t rs_bad2;
- int log_level = 0;
(void) arg;
/* GuardFraction use is currently disabled by default. So we need to
@@ -306,7 +305,7 @@ test_parse_guardfraction_consensus(void *arg)
memset(&rs_no_guard, 0, sizeof(routerstatus_t));
tt_assert(!rs_no_guard.is_possible_guard);
- log_level = setup_full_capture_of_logs(LOG_WARN);
+ setup_full_capture_of_logs(LOG_WARN);
retval = routerstatus_parse_guardfraction(guardfraction_str_good,
NULL, NULL,
&rs_no_guard);
@@ -314,8 +313,7 @@ test_parse_guardfraction_consensus(void *arg)
tt_assert(!rs_no_guard.has_guardfraction);
expect_single_log_msg_containing("Got GuardFraction for non-guard . "
"This is not supposed to happen.");
- teardown_capture_of_logs(log_level);
- log_level = 0;
+ teardown_capture_of_logs();
}
{ /* Bad GuardFraction. Function should fail and not apply. */
@@ -341,8 +339,7 @@ test_parse_guardfraction_consensus(void *arg)
}
done:
- if (log_level)
- teardown_capture_of_logs(log_level);
+ teardown_capture_of_logs();
}
/** Make sure that we use GuardFraction information when we should,
diff --git a/src/test/test_link_handshake.c b/src/test/test_link_handshake.c
index 1d60a49..6c05670 100644
--- a/src/test/test_link_handshake.c
+++ b/src/test/test_link_handshake.c
@@ -337,7 +337,7 @@ test_link_handshake_recv_certs_ok_server(void *arg)
{ \
certs_data_t *d = arg; \
const char *require_failure_message = NULL; \
- const int prev_level = setup_capture_of_logs(LOG_INFO); \
+ setup_capture_of_logs(LOG_INFO); \
{ code ; } \
channel_tls_process_certs_cell(d->cell, d->chan); \
tt_int_op(1, ==, mock_close_called); \
@@ -347,7 +347,7 @@ test_link_handshake_recv_certs_ok_server(void *arg)
expect_log_msg_containing(require_failure_message); \
} \
done: \
- teardown_capture_of_logs(prev_level); \
+ teardown_capture_of_logs(); \
}
CERTS_FAIL(badstate,
@@ -614,7 +614,7 @@ test_link_handshake_recv_authchallenge_ok_unrecognized(void *arg)
{ \
authchallenge_data_t *d = arg; \
const char *require_failure_message = NULL; \
- const int prev_level = setup_capture_of_logs(LOG_INFO); \
+ setup_capture_of_logs(LOG_INFO); \
{ code ; } \
channel_tls_process_auth_challenge_cell(d->cell, d->chan); \
tt_int_op(1, ==, mock_close_called); \
@@ -624,7 +624,7 @@ test_link_handshake_recv_authchallenge_ok_unrecognized(void *arg)
expect_log_msg_containing(require_failure_message); \
} \
done: \
- teardown_capture_of_logs(prev_level); \
+ teardown_capture_of_logs(); \
}
AUTHCHALLENGE_FAIL(badstate,
@@ -853,7 +853,7 @@ test_link_handshake_auth_cell(void *arg)
{ \
authenticate_data_t *d = arg; \
const char *require_failure_message = NULL; \
- const int prev_level = setup_capture_of_logs(LOG_INFO); \
+ setup_capture_of_logs(LOG_INFO); \
{ code ; } \
tt_int_op(d->c2->handshake_state->authenticated, ==, 0); \
channel_tls_process_authenticate_cell(d->cell, d->chan2); \
@@ -863,7 +863,7 @@ test_link_handshake_auth_cell(void *arg)
expect_log_msg_containing(require_failure_message); \
} \
done: \
- teardown_capture_of_logs(prev_level); \
+ teardown_capture_of_logs(); \
}
AUTHENTICATE_FAIL(badstate,
@@ -882,14 +882,14 @@ static void
test_link_handshake_auth_already_authenticated(void *arg)
{
authenticate_data_t *d = arg;
- const int prev_level = setup_capture_of_logs(LOG_INFO);
+ setup_capture_of_logs(LOG_INFO);
d->c2->handshake_state->authenticated = 1;
channel_tls_process_authenticate_cell(d->cell, d->chan2);
tt_int_op(mock_close_called, ==, 1);
tt_int_op(d->c2->handshake_state->authenticated, ==, 1);
expect_log_msg_containing("The peer is already authenticated");
done:
- teardown_capture_of_logs(prev_level);
+ teardown_capture_of_logs();
}
AUTHENTICATE_FAIL(nocerts,
diff --git a/src/test/test_options.c b/src/test/test_options.c
index 2748f42..0451b93 100644
--- a/src/test/test_options.c
+++ b/src/test/test_options.c
@@ -401,7 +401,7 @@ test_options_validate__uname_for_server(void *ignored)
char *msg;
options_test_data_t *tdata = get_options_test_data(
"ORListenAddress 127.0.0.1:5555");
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
MOCK(get_uname, fixed_get_uname);
fixed_get_uname_result = "Windows 95";
@@ -437,7 +437,7 @@ test_options_validate__uname_for_server(void *ignored)
UNMOCK(get_uname);
free_options_test_data(tdata);
tor_free(msg);
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
}
static void
@@ -535,7 +535,7 @@ test_options_validate__contactinfo(void *ignored)
char *msg;
options_test_data_t *tdata = get_options_test_data(
"ORListenAddress 127.0.0.1:5555\nORPort 955");
- int previous_log = setup_capture_of_logs(LOG_DEBUG);
+ setup_capture_of_logs(LOG_DEBUG);
tdata->opt->ContactInfo = NULL;
ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
@@ -559,7 +559,7 @@ test_options_validate__contactinfo(void *ignored)
tor_free(msg);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -647,7 +647,7 @@ test_options_validate__authdir(void *ignored)
(void)ignored;
int ret;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_INFO);
+ setup_capture_of_logs(LOG_INFO);
options_test_data_t *tdata = get_options_test_data(
"AuthoritativeDirectory 1\n"
"Address this.should.not_exist.example.org");
@@ -940,7 +940,7 @@ test_options_validate__authdir(void *ignored)
/* "but ClientOnly also set."); */
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
// sandbox_free_getaddrinfo_cache();
free_options_test_data(tdata);
tor_free(msg);
@@ -951,7 +951,7 @@ test_options_validate__relay_with_hidden_services(void *ignored)
{
(void)ignored;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_DEBUG);
+ setup_capture_of_logs(LOG_DEBUG);
options_test_data_t *tdata = get_options_test_data(
"ORListenAddress 127.0.0.1:5555\n"
"ORPort 955\n"
@@ -968,7 +968,7 @@ test_options_validate__relay_with_hidden_services(void *ignored)
"https://trac.torproject.org/8742\n");
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -981,7 +981,7 @@ test_options_validate__relay_with_hidden_services(void *ignored)
/* (void)ignored; */
/* int ret; */
/* char *msg; */
-/* int previous_log = setup_capture_of_logs(LOG_WARN); */
+/* setup_capture_of_logs(LOG_WARN); */
/* options_test_data_t *tdata = get_options_test_data(""); */
/* ret = options_validate(tdata->old_opt, tdata->opt, */
/* tdata->def_opt, 0, &msg); */
@@ -990,7 +990,7 @@ test_options_validate__relay_with_hidden_services(void *ignored)
/* "configured. " */
/* " Tor will still run, but probably won't do anything.\n"); */
/* done: */
-/* teardown_capture_of_logs(previous_log); */
+/* teardown_capture_of_logs(); */
/* free_options_test_data(tdata); */
/* tor_free(msg); */
/* } */
@@ -1131,7 +1131,7 @@ test_options_validate__exclude_nodes(void *ignored)
int ret;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
options_test_data_t *tdata = get_options_test_data(
"ExcludeExitNodes {us}\n");
@@ -1196,7 +1196,7 @@ test_options_validate__exclude_nodes(void *ignored)
done:
NS_UNMOCK(geoip_get_country);
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -1207,7 +1207,7 @@ test_options_validate__scheduler(void *ignored)
(void)ignored;
int ret;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_DEBUG);
+ setup_capture_of_logs(LOG_DEBUG);
options_test_data_t *tdata = get_options_test_data(
"SchedulerLowWaterMark__ 0\n");
@@ -1239,7 +1239,7 @@ test_options_validate__scheduler(void *ignored)
tor_free(msg);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -1302,7 +1302,7 @@ test_options_validate__tlsec(void *ignored)
(void)ignored;
int ret;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_DEBUG);
+ setup_capture_of_logs(LOG_DEBUG);
options_test_data_t *tdata = get_options_test_data(
"TLSECGroup ed25519\n"
"SchedulerHighWaterMark__ 42\n"
@@ -1339,7 +1339,7 @@ test_options_validate__tlsec(void *ignored)
tor_free(msg);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -1377,7 +1377,7 @@ test_options_validate__recommended_packages(void *ignored)
(void)ignored;
int ret;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
options_test_data_t *tdata = get_options_test_data(
"RecommendedPackages foo 1.2 http://foo.com sha1=123123123123\n"
"RecommendedPackages invalid-package-line\n"
@@ -1391,7 +1391,7 @@ test_options_validate__recommended_packages(void *ignored)
done:
escaped(NULL); // This will free the leaking memory from the previous escaped
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -1469,7 +1469,7 @@ test_options_validate__paths_needed(void *ignored)
(void)ignored;
int ret;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
options_test_data_t *tdata = get_options_test_data(
"PathsNeededToBuildCircuits 0.1\n"
"ConnLimit 1\n"
@@ -1514,7 +1514,7 @@ test_options_validate__paths_needed(void *ignored)
tor_free(msg);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -1651,7 +1651,7 @@ test_options_validate__reachable_addresses(void *ignored)
(void)ignored;
int ret;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_NOTICE);
+ setup_capture_of_logs(LOG_NOTICE);
options_test_data_t *tdata = get_options_test_data(
"FascistFirewall 1\n"
"MaxClientCircuitsPending 1\n"
@@ -1865,7 +1865,7 @@ test_options_validate__reachable_addresses(void *ignored)
tt_ptr_op(msg, OP_EQ, NULL);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -2115,7 +2115,7 @@ test_options_validate__publish_server_descriptor(void *ignored)
(void)ignored;
int ret;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
options_test_data_t *tdata = get_options_test_data(
"PublishServerDescriptor bridge\n" TEST_OPTIONS_DEFAULT_VALUES
);
@@ -2179,7 +2179,7 @@ test_options_validate__publish_server_descriptor(void *ignored)
tt_assert(!tdata->opt->DirPort_set);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
@@ -2266,7 +2266,7 @@ test_options_validate__hidserv(void *ignored)
(void)ignored;
int ret;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
options_test_data_t *tdata = get_options_test_data(
TEST_OPTIONS_DEFAULT_VALUES);
@@ -2301,7 +2301,7 @@ test_options_validate__hidserv(void *ignored)
tor_free(msg);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
@@ -2313,7 +2313,7 @@ test_options_validate__predicted_ports(void *ignored)
(void)ignored;
int ret;
char *msg;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
options_test_data_t *tdata = get_options_test_data(
"PredictedPortsRelevanceTime 100000000\n"
@@ -2325,7 +2325,7 @@ test_options_validate__predicted_ports(void *ignored)
tt_int_op(tdata->opt->PredictedPortsRelevanceTime, OP_EQ, 3600);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
@@ -2539,7 +2539,7 @@ test_options_validate__circuits(void *ignored)
(void)ignored;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -2616,7 +2616,7 @@ test_options_validate__circuits(void *ignored)
done:
policies_free_all();
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -2689,7 +2689,7 @@ test_options_validate__rend(void *ignored)
int ret;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -2744,7 +2744,7 @@ test_options_validate__rend(void *ignored)
done:
policies_free_all();
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -2756,7 +2756,7 @@ test_options_validate__accounting(void *ignored)
int ret;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -2861,7 +2861,7 @@ test_options_validate__accounting(void *ignored)
tor_free(msg);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
@@ -2875,7 +2875,7 @@ test_options_validate__proxy(void *ignored)
char *msg;
options_test_data_t *tdata = NULL;
sandbox_disable_getaddrinfo_cache();
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -3191,7 +3191,7 @@ test_options_validate__proxy(void *ignored)
tor_free(msg);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
policies_free_all();
// sandbox_free_getaddrinfo_cache();
@@ -3205,7 +3205,7 @@ test_options_validate__control(void *ignored)
int ret;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -3419,7 +3419,7 @@ test_options_validate__control(void *ignored)
tor_free(msg);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
@@ -3432,7 +3432,7 @@ test_options_validate__families(void *ignored)
int ret;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -3491,7 +3491,7 @@ test_options_validate__families(void *ignored)
tor_free(msg);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
@@ -3528,7 +3528,7 @@ test_options_validate__dir_auth(void *ignored)
int ret;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -3603,7 +3603,7 @@ test_options_validate__dir_auth(void *ignored)
done:
policies_free_all();
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -3615,7 +3615,7 @@ test_options_validate__transport(void *ignored)
int ret;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_NOTICE);
+ setup_capture_of_logs(LOG_NOTICE);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -3728,7 +3728,7 @@ test_options_validate__transport(void *ignored)
done:
escaped(NULL); // This will free the leaking memory from the previous escaped
policies_free_all();
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -3740,7 +3740,7 @@ test_options_validate__constrained_sockets(void *ignored)
int ret;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -3811,7 +3811,7 @@ test_options_validate__constrained_sockets(void *ignored)
done:
policies_free_all();
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -3823,7 +3823,7 @@ test_options_validate__v3_auth(void *ignored)
int ret;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -4030,7 +4030,7 @@ test_options_validate__v3_auth(void *ignored)
done:
policies_free_all();
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -4075,7 +4075,7 @@ test_options_validate__exits(void *ignored)
int ret;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
free_options_test_data(tdata);
tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
@@ -4105,7 +4105,7 @@ test_options_validate__exits(void *ignored)
done:
policies_free_all();
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
@@ -4117,7 +4117,7 @@ test_options_validate__testing_options(void *ignored)
int ret;
char *msg;
options_test_data_t *tdata = NULL;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
#define TEST_TESTING_OPTION(name, low_val, high_val, err_low) \
STMT_BEGIN \
@@ -4273,7 +4273,7 @@ test_options_validate__testing_options(void *ignored)
done:
policies_free_all();
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
free_options_test_data(tdata);
tor_free(msg);
}
diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c
index 17d86bc..a5d3f35 100644
--- a/src/test/test_rendcache.c
+++ b/src/test/test_rendcache.c
@@ -647,7 +647,6 @@ test_rend_cache_init(void *data)
static void
test_rend_cache_decrement_allocation(void *data)
{
- int log_level = 0;
(void)data;
// Test when the cache has enough allocations
@@ -657,27 +656,24 @@ test_rend_cache_decrement_allocation(void *data)
// Test when there are not enough allocations
rend_cache_total_allocation = 1;
- log_level = setup_full_capture_of_logs(LOG_WARN);
+ setup_full_capture_of_logs(LOG_WARN);
rend_cache_decrement_allocation(2);
tt_int_op(rend_cache_total_allocation, OP_EQ, 0);
expect_single_log_msg_containing(
"Underflow in rend_cache_decrement_allocation");
- teardown_capture_of_logs(log_level);
- log_level = 0;
+ teardown_capture_of_logs();
// And again
rend_cache_decrement_allocation(2);
tt_int_op(rend_cache_total_allocation, OP_EQ, 0);
done:
- if (log_level)
- teardown_capture_of_logs(log_level);
+ teardown_capture_of_logs();
}
static void
test_rend_cache_increment_allocation(void *data)
{
- int log_level = 0;
(void)data;
// Test when the cache is not overflowing
@@ -687,21 +683,19 @@ test_rend_cache_increment_allocation(void *data)
// Test when there are too many allocations
rend_cache_total_allocation = SIZE_MAX-1;
- log_level = setup_full_capture_of_logs(LOG_WARN);
+ setup_full_capture_of_logs(LOG_WARN);
rend_cache_increment_allocation(2);
tt_u64_op(rend_cache_total_allocation, OP_EQ, SIZE_MAX);
expect_single_log_msg_containing(
"Overflow in rend_cache_increment_allocation");
- teardown_capture_of_logs(log_level);
- log_level = 0;
+ teardown_capture_of_logs();
// And again
rend_cache_increment_allocation(2);
tt_u64_op(rend_cache_total_allocation, OP_EQ, SIZE_MAX);
done:
- if (log_level)
- teardown_capture_of_logs(log_level);
+ teardown_capture_of_logs();
}
static void
diff --git a/src/test/test_tortls.c b/src/test/test_tortls.c
index d2f256a..790c331 100644
--- a/src/test/test_tortls.c
+++ b/src/test/test_tortls.c
@@ -324,7 +324,7 @@ test_tortls_log_one_error(void *ignored)
ctx = SSL_CTX_new(SSLv23_method());
tls = tor_malloc_zero(sizeof(tor_tls_t));
- int previous_log = setup_capture_of_logs(LOG_INFO);
+ setup_capture_of_logs(LOG_INFO);
tor_tls_log_one_error(NULL, 0, LOG_WARN, 0, "something");
expect_log_msg("TLS error while something: "
@@ -393,7 +393,7 @@ test_tortls_log_one_error(void *ignored)
" (in (null):(null):" SSL_STATE_STR ")\n");
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
SSL_free(ssl);
SSL_CTX_free(ctx);
if (tls && tls->ssl)
@@ -416,7 +416,7 @@ test_tortls_get_error(void *ignored)
SSL_load_error_strings();
ctx = SSL_CTX_new(SSLv23_method());
- int previous_log = setup_capture_of_logs(LOG_INFO);
+ setup_capture_of_logs(LOG_INFO);
tls = tor_malloc_zero(sizeof(tor_tls_t));
tls->ssl = SSL_new(ctx);
SSL_set_bio(tls->ssl, BIO_new(BIO_s_mem()), NULL);
@@ -482,7 +482,7 @@ test_tortls_get_error(void *ignored)
"connect:before/accept initialization)\n");
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
SSL_free(tls->ssl);
tor_free(tls);
SSL_CTX_free(ctx);
@@ -1790,7 +1790,7 @@ test_tortls_debug_state_callback(void *ignored)
char *buf = tor_malloc_zero(1000);
int n;
- int previous_log = setup_capture_of_logs(LOG_DEBUG);
+ setup_capture_of_logs(LOG_DEBUG);
ssl = tor_malloc_zero(sizeof(SSL));
@@ -1803,7 +1803,7 @@ test_tortls_debug_state_callback(void *ignored)
expect_log_msg(buf);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
tor_free(buf);
tor_free(ssl);
}
@@ -1817,7 +1817,6 @@ test_tortls_server_info_callback(void *ignored)
tor_tls_t *tls;
SSL_CTX *ctx;
SSL *ssl;
- int previous_log = 0;
SSL_library_init();
SSL_load_error_strings();
@@ -1831,7 +1830,7 @@ test_tortls_server_info_callback(void *ignored)
tls->magic = TOR_TLS_MAGIC;
tls->ssl = ssl;
- previous_log = setup_full_capture_of_logs(LOG_WARN);
+ setup_full_capture_of_logs(LOG_WARN);
SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_A);
mock_clean_saved_logs();
tor_tls_server_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 0);
@@ -1846,8 +1845,7 @@ test_tortls_server_info_callback(void *ignored)
mock_clean_saved_logs();
tor_tls_server_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 0);
expect_no_log_entry();
- teardown_capture_of_logs(previous_log);
- previous_log = 0;
+ teardown_capture_of_logs();
SSL_set_ex_data(tls->ssl, tor_tls_object_ex_data_index, tls);
SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_B);
@@ -1868,8 +1866,7 @@ test_tortls_server_info_callback(void *ignored)
tt_int_op(tls->wasV2Handshake, OP_EQ, 0);
done:
- if (previous_log)
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
SSL_free(ssl);
SSL_CTX_free(ctx);
tor_free(tls);
@@ -1931,7 +1928,7 @@ test_tortls_shutdown(void *ignored)
int ret;
tor_tls_t *tls;
SSL_METHOD *method = give_me_a_test_method();
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
tls = tor_malloc_zero(sizeof(tor_tls_t));
tls->ssl = tor_malloc_zero(sizeof(SSL));
@@ -2014,7 +2011,7 @@ test_tortls_shutdown(void *ignored)
#endif
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
tor_free(method);
tor_free(tls->ssl);
tor_free(tls);
@@ -2038,7 +2035,7 @@ test_tortls_read(void *ignored)
tor_tls_t *tls;
char buf[100];
SSL_METHOD *method = give_me_a_test_method();
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
tls = tor_malloc_zero(sizeof(tor_tls_t));
tls->ssl = tor_malloc_zero(sizeof(SSL));
@@ -2086,7 +2083,7 @@ test_tortls_read(void *ignored)
// TODO: fill up
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
tor_free(tls->ssl);
tor_free(tls);
tor_free(method);
@@ -2111,7 +2108,7 @@ test_tortls_write(void *ignored)
tor_tls_t *tls;
SSL_METHOD *method = give_me_a_test_method();
char buf[100];
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
tls = tor_malloc_zero(sizeof(tor_tls_t));
tls->ssl = tor_malloc_zero(sizeof(SSL));
@@ -2151,7 +2148,7 @@ test_tortls_write(void *ignored)
tt_int_op(ret, OP_EQ, TOR_TLS_WANTWRITE);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
BIO_free(tls->ssl->rbio);
tor_free(tls->ssl);
tor_free(tls);
@@ -2196,7 +2193,7 @@ test_tortls_handshake(void *ignored)
tor_tls_t *tls;
SSL_CTX *ctx;
SSL_METHOD *method = give_me_a_test_method();
- int previous_log = setup_capture_of_logs(LOG_INFO);
+ setup_capture_of_logs(LOG_INFO);
SSL_library_init();
SSL_load_error_strings();
@@ -2259,7 +2256,7 @@ test_tortls_handshake(void *ignored)
expect_log_severity(LOG_WARN);
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
SSL_free(tls->ssl);
SSL_CTX_free(ctx);
tor_free(tls);
@@ -2294,13 +2291,13 @@ test_tortls_finish_handshake(void *ignored)
tls->isServer = 1;
tls->wasV2Handshake = 0;
- log_level = setup_full_capture_of_logs(LOG_WARN);
+ setup_full_capture_of_logs(LOG_WARN);
ret = tor_tls_finish_handshake(tls);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(tls->wasV2Handshake, OP_EQ, 1);
expect_single_log_msg_containing("For some reason, wasV2Handshake didn't "
"get set.");
- teardown_capture_of_logs(log_level);
+ teardown_capture_of_logs();
log_level = 0;
tls->wasV2Handshake = 1;
@@ -2341,7 +2338,7 @@ test_tortls_finish_handshake(void *ignored)
SSL_CTX_free(ctx);
tor_free(method);
if (log_level)
- teardown_capture_of_logs(log_level);
+ teardown_capture_of_logs();
}
#endif
diff --git a/src/test/test_util.c b/src/test/test_util.c
index e2e8c54..5949eb9 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -648,12 +648,12 @@ test_util_time(void *arg)
/* The below tests will all cause a BUG message, so we capture, suppress,
* and detect. */
#define CAPTURE() do { \
- old_log_level = setup_full_capture_of_logs(LOG_WARN); \
+ setup_full_capture_of_logs(LOG_WARN); \
} while (0)
#define CHECK_TIMEGM_WARNING(msg) do { \
expect_log_msg_containing(msg); \
tt_int_op(1, OP_EQ, smartlist_len(mock_saved_logs())); \
- teardown_capture_of_logs(old_log_level); \
+ teardown_capture_of_logs(); \
} while (0)
#define CHECK_TIMEGM_ARG_OUT_OF_RANGE(msg) \
@@ -1113,7 +1113,7 @@ test_util_time(void *arg)
done:
if (old_log_level)
- teardown_capture_of_logs(old_log_level);
+ teardown_capture_of_logs();
}
static void
@@ -2316,7 +2316,7 @@ test_util_gzip_compression_bomb(void *arg)
tor_zlib_state_t *state = NULL;
/* Make sure we can't produce a compression bomb */
- const int prev_level = setup_full_capture_of_logs(LOG_WARN);
+ setup_full_capture_of_logs(LOG_WARN);
tt_int_op(-1, OP_EQ, tor_gzip_compress(&result, &result_len,
one_mb, one_million,
ZLIB_METHOD));
@@ -2324,7 +2324,7 @@ test_util_gzip_compression_bomb(void *arg)
"We compressed something and got an insanely high "
"compression factor; other Tors would think this "
"was a zlib bomb.");
- teardown_capture_of_logs(prev_level);
+ teardown_capture_of_logs();
/* Here's a compression bomb that we made manually. */
const char compression_bomb[1039] =
@@ -5319,7 +5319,6 @@ test_util_pwdb(void *arg)
const struct passwd *me = NULL, *me2, *me3;
char *name = NULL;
char *dir = NULL;
- int prev_level = -100;
/* Uncached case. */
/* Let's assume that we exist. */
@@ -5360,13 +5359,12 @@ test_util_pwdb(void *arg)
tor_free(dir);
/* We should do a LOG_ERR */
- prev_level = setup_full_capture_of_logs(LOG_ERR);
+ setup_full_capture_of_logs(LOG_ERR);
dir = get_user_homedir(badname);
tt_assert(dir == NULL);
expect_log_msg_containing("not found");
tt_int_op(smartlist_len(mock_saved_logs()), OP_EQ, 1);
- teardown_capture_of_logs(prev_level);
- prev_level = -100;
+ teardown_capture_of_logs();
/* Now try to find a user that doesn't exist by ID. */
found = 0;
@@ -5383,8 +5381,7 @@ test_util_pwdb(void *arg)
done:
tor_free(name);
tor_free(dir);
- if (prev_level >= 0)
- teardown_capture_of_logs(prev_level);
+ teardown_capture_of_logs();
}
#endif
diff --git a/src/test/test_util_process.c b/src/test/test_util_process.c
index 6add374..4e75b97 100644
--- a/src/test/test_util_process.c
+++ b/src/test/test_util_process.c
@@ -26,7 +26,7 @@ test_util_process_set_waitpid_callback(void *ignored)
{
(void)ignored;
waitpid_callback_t *res1 = NULL, *res2 = NULL;
- int previous_log = setup_full_capture_of_logs(LOG_WARN);
+ setup_full_capture_of_logs(LOG_WARN);
pid_t pid = (pid_t)42;
res1 = set_waitpid_callback(pid, temp_callback, NULL);
@@ -39,7 +39,7 @@ test_util_process_set_waitpid_callback(void *ignored)
"impossible.\n");
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
clear_waitpid_callback(res1);
clear_waitpid_callback(res2);
}
@@ -49,7 +49,7 @@ test_util_process_clear_waitpid_callback(void *ignored)
{
(void)ignored;
waitpid_callback_t *res;
- int previous_log = setup_capture_of_logs(LOG_WARN);
+ setup_capture_of_logs(LOG_WARN);
pid_t pid = (pid_t)43;
clear_waitpid_callback(NULL);
@@ -65,7 +65,7 @@ test_util_process_clear_waitpid_callback(void *ignored)
#endif
done:
- teardown_capture_of_logs(previous_log);
+ teardown_capture_of_logs();
}
#endif /* _WIN32 */
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits