aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2019-03-18 11:12:25 +1000
committerteor <teor@torproject.org>2019-03-18 11:12:25 +1000
commitc44ad396f89e755f5a639b382e0a55ed1cbcc177 (patch)
tree9c8aaaaf3d75d7b024198c3cb2deb02f9c0f66cd
parent9400da9b5e44bfce0684a3b36edb37465be514d6 (diff)
downloadtor-c44ad396f89e755f5a639b382e0a55ed1cbcc177.tar.gz
tor-c44ad396f89e755f5a639b382e0a55ed1cbcc177.zip
test/sr: Clear SRVs after init, and before setup
Already merged to 0.4.0 and later in tor-github/pr/776. Backported to 0.2.9 and later with minor comment changes. Part of 29706.
-rw-r--r--src/test/test_shared_random.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c
index 0a3c2e119b..526fb09b67 100644
--- a/src/test/test_shared_random.c
+++ b/src/test/test_shared_random.c
@@ -54,6 +54,9 @@ init_authority_state(void)
* the phase we are currently in which uses "now" as the starting
* timestamp. Delete it before we do any testing below. */
sr_state_delete_commits();
+ /* It's also possible that a current SRV has been generated, if we are at
+ * state transition time. But let's just forget about that SRV. */
+ sr_state_clean_srvs();
done:
UNMOCK(get_my_v3_authority_cert);
@@ -449,20 +452,26 @@ test_encoding(void *arg)
;
}
-/** Setup some SRVs in our SR state. If <b>also_current</b> is set, then set
- * both current and previous SRVs.
- * Helper of test_vote() and test_sr_compute_srv(). */
+/** Setup some SRVs in our SR state.
+ * If <b>also_current</b> is set, then set both current and previous SRVs.
+ * Otherwise, just set the previous SRV. (And clear the current SRV.)
+ *
+ * You must call sr_state_free() to free the state at the end of each test
+ * function (on pass or fail). */
static void
test_sr_setup_srv(int also_current)
{
+ /* Clear both SRVs before starting.
+ * In 0.3.5 and earlier, sr_state_set_previous_srv() and
+ * sr_state_set_current_srv() do not free() the old srvs. */
+ sr_state_clean_srvs();
+
sr_srv_t *srv = tor_malloc_zero(sizeof(sr_srv_t));
srv->num_reveals = 42;
memcpy(srv->value,
"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",
sizeof(srv->value));
- /* sr_state_set_previous_srv() does not free() the old previous srv. */
- state_del_previous_srv();
sr_state_set_previous_srv(srv);
if (also_current) {
@@ -472,8 +481,6 @@ test_sr_setup_srv(int also_current)
"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
sizeof(srv->value));
- /* sr_state_set_previous_srv() does not free() the old current srv. */
- state_del_current_srv();
sr_state_set_current_srv(srv);
}
}