[tor-commits] [tor/master] prop224 tests: Improve SRV protocol tests.

nickm at torproject.org nickm at torproject.org
Wed Aug 9 00:36:38 UTC 2017


commit 4a1b57e9b00c8474ada28dd052a2de73a1e9c641
Author: George Kadianakis <desnacked at riseup.net>
Date:   Sat Aug 5 23:11:37 2017 +0300

    prop224 tests: Improve SRV protocol tests.
---
 src/or/shared_random_state.c  |  2 +-
 src/or/shared_random_state.h  |  1 +
 src/test/test_shared_random.c | 26 ++++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/or/shared_random_state.c b/src/or/shared_random_state.c
index 7f8094daf..cbf58e95f 100644
--- a/src/or/shared_random_state.c
+++ b/src/or/shared_random_state.c
@@ -133,7 +133,7 @@ get_voting_interval(void)
 /* Given the time <b>now</b>, return the start time of the current round of
  * the SR protocol. For example, if it's 23:47:08, the current round thus
  * started at 23:47:00 for a voting interval of 10 seconds. */
-static time_t
+STATIC time_t
 get_start_time_of_current_round(time_t now)
 {
   const or_options_t *options = get_options();
diff --git a/src/or/shared_random_state.h b/src/or/shared_random_state.h
index 03dd5eb37..837fa7539 100644
--- a/src/or/shared_random_state.h
+++ b/src/or/shared_random_state.h
@@ -130,6 +130,7 @@ unsigned int sr_state_get_protocol_run_duration(void);
 STATIC int disk_state_load_from_disk_impl(const char *fname);
 
 STATIC sr_phase_t get_sr_protocol_phase(time_t valid_after);
+STATIC time_t get_start_time_of_current_round(time_t now);
 
 STATIC time_t get_state_valid_until_time(time_t now);
 STATIC const char *get_phase_str(sr_phase_t phase);
diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c
index ea037d417..bee0ea0a3 100644
--- a/src/test/test_shared_random.c
+++ b/src/test/test_shared_random.c
@@ -260,6 +260,30 @@ test_get_start_time_of_current_run(void *arg)
   ;
 }
 
+/** Do some rudimentary consistency checks between the functions that
+ *  understand the shared random protocol schedule */
+static void
+test_get_start_time_functions(void *arg)
+{
+  (void) arg;
+  time_t now = approx_time();
+
+  time_t start_time_of_protocol_run =
+    sr_state_get_start_time_of_current_protocol_run(now);
+  tt_assert(start_time_of_protocol_run);
+
+  /* Check that the round start time of the beginning of the run, is itself */
+  tt_int_op(get_start_time_of_current_round(start_time_of_protocol_run), OP_EQ,
+            start_time_of_protocol_run);
+
+  /* Check that even if we increment the start time, we still get the start
+     time of the run as the beginning of the round. */
+  tt_int_op(get_start_time_of_current_round(start_time_of_protocol_run+1),
+            OP_EQ, start_time_of_protocol_run);
+
+ done: ;
+}
+
 static void
 test_get_sr_protocol_duration(void *arg)
 {
@@ -1364,6 +1388,8 @@ struct testcase_t sr_tests[] = {
     NULL, NULL },
   { "get_start_time_of_current_run", test_get_start_time_of_current_run,
     TT_FORK, NULL, NULL },
+  { "get_start_time_functions", test_get_start_time_functions,
+    TT_FORK, NULL, NULL },
   { "get_sr_protocol_duration", test_get_sr_protocol_duration, TT_FORK,
     NULL, NULL },
   { "get_state_valid_until_time", test_get_state_valid_until_time, TT_FORK,





More information about the tor-commits mailing list