Commit 39be8af7 authored by David Goulet's avatar David Goulet 🐼
Browse files

prop250: Add unit tests

parent 727d419a
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -1191,8 +1191,8 @@ consensus_is_waiting_for_certs(void)

/** Return the most recent consensus that we have downloaded, or NULL if we
 * don't have one. */
networkstatus_t *
networkstatus_get_latest_consensus(void)
MOCK_IMPL(networkstatus_t *,
networkstatus_get_latest_consensus,(void))
{
  return current_consensus;
}
@@ -1214,8 +1214,8 @@ networkstatus_get_latest_consensus_by_flavor,(consensus_flavor_t f))

/** Return the most recent consensus that we have downloaded, or NULL if it is
 * no longer live. */
networkstatus_t *
networkstatus_get_live_consensus(time_t now)
MOCK_IMPL(networkstatus_t *,
networkstatus_get_live_consensus,(time_t now))
{
  if (current_consensus &&
      current_consensus->valid_after <= now &&
+2 −2
Original line number Diff line number Diff line
@@ -64,10 +64,10 @@ void update_certificate_downloads(time_t now);
int consensus_is_waiting_for_certs(void);
int client_would_use_router(const routerstatus_t *rs, time_t now,
                            const or_options_t *options);
networkstatus_t *networkstatus_get_latest_consensus(void);
MOCK_DECL(networkstatus_t *,networkstatus_get_latest_consensus,(void));
MOCK_DECL(networkstatus_t *,networkstatus_get_latest_consensus_by_flavor,
          (consensus_flavor_t f));
networkstatus_t *networkstatus_get_live_consensus(time_t now);
MOCK_DECL(networkstatus_t *, networkstatus_get_live_consensus,(time_t now));
networkstatus_t *networkstatus_get_reasonably_live_consensus(time_t now,
                                                             int flavor);
MOCK_DECL(int, networkstatus_consensus_is_bootstrapping,(time_t now));
+19 −0
Original line number Diff line number Diff line
@@ -1291,3 +1291,22 @@ sr_state_init(int save_to_disk, int read_from_disk)
 error:
  return -1;
}

#ifdef TOR_UNIT_TESTS

/* Set the current phase of the protocol. Used only by unit tests. */
void
set_sr_phase(sr_phase_t phase)
{
  tor_assert(sr_state);
  sr_state->phase = phase;
}

/* Get the SR state. Used only by unit tests */
sr_state_t *
get_sr_state(void)
{
  return sr_state;
}

#endif /* TOR_UNIT_TESTS */
+7 −0
Original line number Diff line number Diff line
@@ -135,4 +135,11 @@ STATIC int is_phase_transition(sr_phase_t next_phase);

#endif /* SHARED_RANDOM_STATE_PRIVATE */

#ifdef TOR_UNIT_TESTS

STATIC void set_sr_phase(sr_phase_t phase);
STATIC sr_state_t *get_sr_state(void);

#endif /* TOR_UNIT_TESTS */

#endif /* TOR_SHARED_RANDOM_STATE_H */
+1 −0
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ src_test_test_SOURCES = \
	src/test/test_routerlist.c \
	src/test/test_routerset.c \
	src/test/test_scheduler.c \
	src/test/test_shared_random.c \
	src/test/test_socks.c \
	src/test/test_status.c \
	src/test/test_threads.c \
Loading