summaryrefslogtreecommitdiff
path: root/src/test/test_hs_common.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-07-18 16:44:03 +0300
committerNick Mathewson <nickm@torproject.org>2017-08-08 20:29:34 -0400
commit2cd5f9a2fc2765539899b6e84ed4b1c9e02febad (patch)
tree9c0e51b065538d6dff2d977856f917b62f67b0c4 /src/test/test_hs_common.c
parent0b22b7fce3f1ce97a85f4022533b206f847b7307 (diff)
downloadtor-2cd5f9a2fc2765539899b6e84ed4b1c9e02febad.tar.gz
tor-2cd5f9a2fc2765539899b6e84ed4b1c9e02febad.zip
prop224: Compute start time of next time period.
Diffstat (limited to 'src/test/test_hs_common.c')
-rw-r--r--src/test/test_hs_common.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c
index 27bbab8d46..e41d68d42e 100644
--- a/src/test/test_hs_common.c
+++ b/src/test/test_hs_common.c
@@ -14,6 +14,7 @@
#include "hs_test_helpers.h"
#include "hs_common.h"
+#include "config.h"
static void
test_validate_address(void *arg)
@@ -132,6 +133,64 @@ test_time_period(void *arg)
;
}
+static void
+test_start_time_of_next_time_period(void *arg)
+{
+ (void) arg;
+ int retval;
+ time_t fake_time;
+ char tbuf[ISO_TIME_LEN + 1];
+ time_t next_tp_start_time;
+
+ /* Do some basic tests */
+ retval = parse_rfc1123_time("Wed, 13 Apr 2016 11:00:00 UTC",
+ &fake_time);
+ tt_int_op(retval, ==, 0);
+ next_tp_start_time = hs_get_start_time_of_next_time_period(fake_time);
+ /* Compare it with the correct result */
+ format_iso_time(tbuf, next_tp_start_time);
+ tt_str_op("2016-04-13 12:00:00", OP_EQ, tbuf);
+
+ /* Another test with an edge-case time (start of TP) */
+ retval = parse_rfc1123_time("Wed, 13 Apr 2016 12:00:00 UTC",
+ &fake_time);
+ tt_int_op(retval, ==, 0);
+ next_tp_start_time = hs_get_start_time_of_next_time_period(fake_time);
+ format_iso_time(tbuf, next_tp_start_time);
+ tt_str_op("2016-04-14 12:00:00", OP_EQ, tbuf);
+
+ {
+ /* Now pretend we are on a testing network and alter the voting schedule to
+ be every 10 seconds. This means that a time period has length 10*24
+ seconds (4 minutes). It also means that we apply a rotational offset of
+ 120 seconds to the time period, so that it starts at 00:02:00 instead of
+ 00:00:00. */
+ or_options_t *options = get_options_mutable();
+ options->TestingTorNetwork = 1;
+ options->V3AuthVotingInterval = 10;
+ options->TestingV3AuthInitialVotingInterval = 10;
+
+ retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:00:00 UTC",
+ &fake_time);
+ tt_int_op(retval, ==, 0);
+ next_tp_start_time = hs_get_start_time_of_next_time_period(fake_time);
+ /* Compare it with the correct result */
+ format_iso_time(tbuf, next_tp_start_time);
+ tt_str_op("2016-04-13 00:02:00", OP_EQ, tbuf);
+
+ retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:02:00 UTC",
+ &fake_time);
+ tt_int_op(retval, ==, 0);
+ next_tp_start_time = hs_get_start_time_of_next_time_period(fake_time);
+ /* Compare it with the correct result */
+ format_iso_time(tbuf, next_tp_start_time);
+ tt_str_op("2016-04-13 00:06:00", OP_EQ, tbuf);
+ }
+
+ done:
+ ;
+}
+
/** Test that our HS overlap period functions work properly. */
static void
test_desc_overlap_period(void *arg)
@@ -186,6 +245,8 @@ struct testcase_t hs_common_tests[] = {
NULL, NULL },
{ "time_period", test_time_period, TT_FORK,
NULL, NULL },
+ { "start_time_of_next_time_period", test_start_time_of_next_time_period,
+ TT_FORK, NULL, NULL },
{ "desc_overlap_period", test_desc_overlap_period, TT_FORK,
NULL, NULL },