summaryrefslogtreecommitdiff
path: root/src/test/test_shared_random.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-07-17 14:45:14 +0300
committerNick Mathewson <nickm@torproject.org>2017-08-08 20:29:34 -0400
commit2af254096f68f0cefadb5cb06b010d19edd2e6e1 (patch)
tree03a839b50a812bd17edf04f42f2ff8cc6ae6b450 /src/test/test_shared_random.c
parent85c80adf4a75e1f44250379a4806796a26e861e3 (diff)
downloadtor-2af254096f68f0cefadb5cb06b010d19edd2e6e1.tar.gz
tor-2af254096f68f0cefadb5cb06b010d19edd2e6e1.zip
SR: Compute the start time of the current protocol run.
This function will be used to make the HS desc overlap function be independent of absolute times.
Diffstat (limited to 'src/test/test_shared_random.c')
-rw-r--r--src/test/test_shared_random.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c
index 026a0f3825..3eb47dfbc3 100644
--- a/src/test/test_shared_random.c
+++ b/src/test/test_shared_random.c
@@ -189,6 +189,77 @@ test_get_state_valid_until_time(void *arg)
;
}
+/** Test the function that calculates the start time of the current SRV
+ * protocol run. */
+static void
+test_get_start_time_of_current_run(void *arg)
+{
+ int retval;
+ char tbuf[ISO_TIME_LEN + 1];
+ time_t current_time, run_start_time;
+
+ (void) arg;
+
+ {
+ /* Get start time if called at 00:00:01 */
+ retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:01 UTC",
+ &current_time);
+ tt_int_op(retval, ==, 0);
+ run_start_time =
+ sr_state_get_start_time_of_current_protocol_run(current_time);
+
+ /* Compare it with the correct result */
+ format_iso_time(tbuf, run_start_time);
+ tt_str_op("2015-04-20 00:00:00", OP_EQ, tbuf);
+ }
+
+ {
+ retval = parse_rfc1123_time("Mon, 20 Apr 2015 23:59:59 UTC",
+ &current_time);
+ tt_int_op(retval, ==, 0);
+ run_start_time =
+ sr_state_get_start_time_of_current_protocol_run(current_time);
+
+ /* Compare it with the correct result */
+ format_iso_time(tbuf, run_start_time);
+ tt_str_op("2015-04-20 00:00:00", OP_EQ, tbuf);
+ }
+
+ {
+ retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:00 UTC",
+ &current_time);
+ tt_int_op(retval, ==, 0);
+ run_start_time =
+ sr_state_get_start_time_of_current_protocol_run(current_time);
+
+ /* Compare it with the correct result */
+ format_iso_time(tbuf, run_start_time);
+ tt_str_op("2015-04-20 00:00:00", OP_EQ, tbuf);
+ }
+
+ /* Now let's alter the voting schedule and check the correctness of the
+ * function. Voting interval of 10 seconds, means that an SRV protocol run
+ * takes 10 seconds * 24 rounds = 4 mins */
+ {
+ or_options_t *options = get_options_mutable();
+ options->V3AuthVotingInterval = 10;
+ options->TestingV3AuthInitialVotingInterval = 10;
+ retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:15:32 UTC",
+ &current_time);
+
+ tt_int_op(retval, ==, 0);
+ run_start_time =
+ sr_state_get_start_time_of_current_protocol_run(current_time);
+
+ /* Compare it with the correct result */
+ format_iso_time(tbuf, run_start_time);
+ tt_str_op("2015-04-20 00:12:00", OP_EQ, tbuf);
+ }
+
+ done:
+ ;
+}
+
/* Mock function to immediately return our local 'mock_consensus'. */
static networkstatus_t *
mock_networkstatus_get_live_consensus(time_t now)
@@ -1272,6 +1343,8 @@ struct testcase_t sr_tests[] = {
NULL, NULL },
{ "get_next_valid_after_time", test_get_next_valid_after_time, TT_FORK,
NULL, NULL },
+ { "get_start_time_of_current_run", test_get_start_time_of_current_run,
+ TT_FORK, NULL, NULL },
{ "get_state_valid_until_time", test_get_state_valid_until_time, TT_FORK,
NULL, NULL },
{ "vote", test_vote, TT_FORK,