Expose GETINFO download status statics for test suite and make things mockable

This commit is contained in:
Andrea Shepard 2016-06-28 21:30:57 +00:00
parent c692900728
commit 657eaee6ae
8 changed files with 71 additions and 42 deletions

View File

@ -2179,7 +2179,7 @@ download_status_to_string(const download_status_t *dl)
}
/** Handle the consensus download cases for getinfo_helper_downloads() */
static void
STATIC void
getinfo_helper_downloads_networkstatus(const char *flavor,
download_status_t **dl_to_emit,
const char **errmsg)
@ -2208,7 +2208,7 @@ getinfo_helper_downloads_networkstatus(const char *flavor,
}
/** Handle the cert download cases for getinfo_helper_downloads() */
static void
STATIC void
getinfo_helper_downloads_cert(const char *fp_sk_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
@ -2308,7 +2308,7 @@ getinfo_helper_downloads_cert(const char *fp_sk_req,
}
/** Handle the routerdesc download cases for getinfo_helper_downloads() */
static void
STATIC void
getinfo_helper_downloads_desc(const char *desc_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
@ -2354,7 +2354,7 @@ getinfo_helper_downloads_desc(const char *desc_req,
}
/** Handle the bridge download cases for getinfo_helper_downloads() */
static void
STATIC void
getinfo_helper_downloads_bridge(const char *bridge_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
@ -2397,7 +2397,7 @@ getinfo_helper_downloads_bridge(const char *bridge_req,
/** Implementation helper for GETINFO: knows the answers for questions about
* download status information. */
static int
STATIC int
getinfo_helper_downloads(control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg)

View File

@ -261,6 +261,31 @@ STATIC crypto_pk_t *add_onion_helper_keyarg(const char *arg, int discard_pk,
char **err_msg_out);
STATIC rend_authorized_client_t *
add_onion_helper_clientauth(const char *arg, int *created, char **err_msg_out);
STATIC void getinfo_helper_downloads_networkstatus(
const char *flavor,
download_status_t **dl_to_emit,
const char **errmsg);
STATIC void getinfo_helper_downloads_cert(
const char *fp_sk_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
const char **errmsg);
STATIC void getinfo_helper_downloads_desc(
const char *desc_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
const char **errmsg);
STATIC void getinfo_helper_downloads_bridge(
const char *bridge_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
const char **errmsg);
STATIC int getinfo_helper_downloads(
control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg);
#endif
#endif

View File

@ -2425,8 +2425,8 @@ num_bridges_usable(void)
}
/** Return a smartlist containing all bridge identity digests */
smartlist_t *
list_bridge_identities(void)
MOCK_IMPL(smartlist_t *,
list_bridge_identities, (void))
{
smartlist_t *result = NULL;
char *digest_tmp;
@ -2445,8 +2445,8 @@ list_bridge_identities(void)
}
/** Get the download status for a bridge descriptor given its identity */
download_status_t *
get_bridge_dl_status_by_id(const char *digest)
MOCK_IMPL(download_status_t *,
get_bridge_dl_status_by_id, (const char *digest))
{
download_status_t *dl = NULL;

View File

@ -179,8 +179,9 @@ guard_get_guardfraction_bandwidth(guardfraction_bandwidth_t *guardfraction_bw,
int orig_bandwidth,
uint32_t guardfraction_percentage);
smartlist_t * list_bridge_identities(void);
download_status_t * get_bridge_dl_status_by_id(const char *digest);
MOCK_DECL(smartlist_t *, list_bridge_identities, (void));
MOCK_DECL(download_status_t *, get_bridge_dl_status_by_id,
(const char *digest));
#endif

View File

@ -683,8 +683,8 @@ router_get_descriptor_digests_in_consensus(networkstatus_t *consensus)
/** Return a smartlist of all router descriptor digests in the current
* consensus */
smartlist_t *
router_get_descriptor_digests(void)
MOCK_IMPL(smartlist_t *,
router_get_descriptor_digests,(void))
{
smartlist_t *result = NULL;
@ -1219,8 +1219,8 @@ consensus_is_waiting_for_certs(void)
/** Look up the currently active (depending on bootstrap status) download
* status for this consensus flavor and return a pointer to it.
*/
download_status_t *
networkstatus_get_dl_status_by_flavor(consensus_flavor_t flavor)
MOCK_IMPL(download_status_t *,
networkstatus_get_dl_status_by_flavor,(consensus_flavor_t flavor))
{
download_status_t *dl = NULL;
const int we_are_bootstrapping =
@ -1236,8 +1236,8 @@ networkstatus_get_dl_status_by_flavor(consensus_flavor_t flavor)
/** Look up the bootstrap download status for this consensus flavor
* and return a pointer to it. */
download_status_t *
networkstatus_get_dl_status_by_flavor_bootstrap(consensus_flavor_t flavor)
MOCK_IMPL(download_status_t *,
networkstatus_get_dl_status_by_flavor_bootstrap,(consensus_flavor_t flavor))
{
download_status_t *dl = NULL;
@ -1250,8 +1250,8 @@ networkstatus_get_dl_status_by_flavor_bootstrap(consensus_flavor_t flavor)
/** Look up the running (non-bootstrap) download status for this consensus
* flavor and return a pointer to it. */
download_status_t *
networkstatus_get_dl_status_by_flavor_running(consensus_flavor_t flavor)
MOCK_IMPL(download_status_t *,
networkstatus_get_dl_status_by_flavor_running,(consensus_flavor_t flavor))
{
download_status_t *dl = NULL;

View File

@ -38,14 +38,17 @@ routerstatus_t *networkstatus_vote_find_mutable_entry(networkstatus_t *ns,
int networkstatus_vote_find_entry_idx(networkstatus_t *ns,
const char *digest, int *found_out);
download_status_t * networkstatus_get_dl_status_by_flavor(
consensus_flavor_t flavor);
download_status_t * networkstatus_get_dl_status_by_flavor_bootstrap(
consensus_flavor_t flavor);
download_status_t * networkstatus_get_dl_status_by_flavor_running(
consensus_flavor_t flavor);
MOCK_DECL(download_status_t *,
networkstatus_get_dl_status_by_flavor,
(consensus_flavor_t flavor));
MOCK_DECL(download_status_t *,
networkstatus_get_dl_status_by_flavor_bootstrap,
(consensus_flavor_t flavor));
MOCK_DECL(download_status_t *,
networkstatus_get_dl_status_by_flavor_running,
(consensus_flavor_t flavor));
smartlist_t * router_get_descriptor_digests(void);
MOCK_DECL(smartlist_t *, router_get_descriptor_digests, (void));
MOCK_DECL(download_status_t *,router_get_dl_status_by_descriptor_digest,
(const char *d));

View File

@ -257,8 +257,8 @@ get_cert_list(const char *id_digest)
* of download_status_t objects; used by controller GETINFO queries.
*/
smartlist_t *
list_authority_ids_with_downloads(void)
MOCK_IMPL(smartlist_t *,
list_authority_ids_with_downloads, (void))
{
smartlist_t *ids = smartlist_new();
digestmap_iter_t *i;
@ -288,8 +288,8 @@ list_authority_ids_with_downloads(void)
/** Given an authority ID digest, return a pointer to the default download
* status, or NULL if there is no such entry in trusted_dir_certs */
download_status_t *
id_only_download_status_for_authority_id(const char *digest)
MOCK_IMPL(download_status_t *,
id_only_download_status_for_authority_id, (const char *digest))
{
download_status_t *dl = NULL;
cert_list_t *cl;
@ -308,8 +308,8 @@ id_only_download_status_for_authority_id(const char *digest)
* for which download_status_t is potentially queryable, or NULL if no such
* authority ID digest is known. */
smartlist_t *
list_sk_digests_for_authority_id(const char *digest)
MOCK_IMPL(smartlist_t *,
list_sk_digests_for_authority_id, (const char *digest))
{
smartlist_t *sks = NULL;
cert_list_t *cl;
@ -342,9 +342,9 @@ list_sk_digests_for_authority_id(const char *digest)
/** Given an authority ID digest and a signing key digest, return the
* download_status_t or NULL if none exists. */
download_status_t *
download_status_for_authority_id_and_sk(const char *id_digest,
const char *sk_digest)
MOCK_IMPL(download_status_t *,
download_status_for_authority_id_and_sk,
(const char *id_digest, const char *sk_digest))
{
download_status_t *dl = NULL;
cert_list_t *cl = NULL;

View File

@ -104,13 +104,13 @@ void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old,
void routerlist_free_all(void);
void routerlist_reset_warnings(void);
smartlist_t * list_authority_ids_with_downloads(void);
download_status_t * id_only_download_status_for_authority_id(
const char *digest);
smartlist_t * list_sk_digests_for_authority_id(const char *digest);
download_status_t * download_status_for_authority_id_and_sk(
const char *id_digest,
const char *sk_digest);
MOCK_DECL(smartlist_t *, list_authority_ids_with_downloads, (void);)
MOCK_DECL(download_status_t *, id_only_download_status_for_authority_id,
(const char *digest));
MOCK_DECL(smartlist_t *, list_sk_digests_for_authority_id,
(const char *digest));
MOCK_DECL(download_status_t *, download_status_for_authority_id_and_sk,
(const char *id_digest, const char *sk_digest));
static int WRA_WAS_ADDED(was_router_added_t s);
static int WRA_WAS_OUTDATED(was_router_added_t s);