mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
Remove all usage of the NS*() macros in test*.c
This is an automatically generated commit, made with the following kludgey perl script. It results in a number of wide lines, which I'll clean up in a subsequent commit. #/usr/bin/perl -w -i $mod = "NS_MODULE"; $submod = "NS_SUBMODULE"; $last_was_empty = 0; while (<>) { s/\bASPECT\(\s*(\w+)\s*,\s*(\w+)\s*\)/$1_$2/; if (/# *define +NS_MODULE +(\w+)/) { $mod = $1; next; } elsif (/# *define +NS_SUBMODULE +(\w+)/) { $submod = $1; next; } next if (/#undef NS_(SUB)?MODULE/); s/NS\(\s*test_main\s*\)/test_${mod}_${submod}/; s/NS\(\s*(\w+)\s*\)/${mod}_${submod}_$1/g; s/NS_FULL\(\\s*(\w+)\s*,\s*(\w+),\s*(\w+)\s*\)/$1_$2_$3/; s/^(\s*)NS_MOCK\(\s*(\w+)\s*\)/$1MOCK($2,\n$1 ${mod}_${submod}_$2)/; s/NS_UNMOCK\(\s*(\w+)\s*\)/UNMOCK($1)/; s/TEST_CASE\(\s*(\w+)\s*\)/{ "$1", test_${mod}_$1, TT_FORK, NULL, NULL }/; s/TEST_CASE_ASPECT\(\s*(\w+)\s*,\s*(\w+)\s*\)/{ "$1_$2", test_${mod}_$1_$2, TT_FORK, NULL, NULL }/; s/NS_DECL\(\s*([^,]+)\s*,\s*([^,]+)\s*,\s*(\(.*)\);/static $1 ${mod}_${submod}_$2$3;\nATTR_UNUSED static int ${mod}_${submod}_$2_called = 0;/; s/\bCALLED\(\s*(\w+)\s*\)/${mod}_${submod}_$1_called/; if (/^$/) { print if (! $last_was_empty); $last_was_empty = 1; } else { $last_was_empty = 0; print; } if (eof) { $mod = "NS_MODULE"; $submod = "NS_SUBMODULE"; $last_was_empty = 0; } } # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Thu Jan 9 10:26:10 2020 -0500 # # On branch disable_ns_macro # Changes to be committed: # modified: src/test/test_accounting.c # modified: src/test/test_compat_libevent.c # modified: src/test/test_dir.c # modified: src/test/test_dir_handle_get.c # modified: src/test/test_dns.c # modified: src/test/test_options.c # modified: src/test/test_procmon.c # modified: src/test/test_rendcache.c # modified: src/test/test_router.c # modified: src/test/test_routerset.c # modified: src/test/test_status.c # modified: src/test/test_tortls.c # modified: src/test/test_tortls_openssl.c # modified: src/test/test_util_format.c # modified: src/test/test_util_process.c # # Untracked files: # experiments/ # locate_options.sh # un_ns.pl # # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Thu Jan 9 10:26:10 2020 -0500 # # On branch disable_ns_macro # Changes to be committed: # modified: src/test/test_accounting.c # modified: src/test/test_compat_libevent.c # modified: src/test/test_dir.c # modified: src/test/test_dir_handle_get.c # modified: src/test/test_dns.c # modified: src/test/test_options.c # modified: src/test/test_procmon.c # modified: src/test/test_rendcache.c # modified: src/test/test_router.c # modified: src/test/test_routerset.c # modified: src/test/test_status.c # modified: src/test/test_tortls.c # modified: src/test/test_tortls_openssl.c # modified: src/test/test_util_format.c # modified: src/test/test_util_process.c # # Untracked files: # experiments/ # locate_options.sh # un_ns.pl #
This commit is contained in:
parent
c9855f23c1
commit
23c77f79fd
@ -11,19 +11,16 @@
|
||||
|
||||
#include "app/config/or_state_st.h"
|
||||
|
||||
#define NS_MODULE acct
|
||||
|
||||
#define NS_SUBMODULE limits
|
||||
|
||||
/*
|
||||
* Test to make sure accounting triggers hibernation
|
||||
* correctly with both sum or max rules set
|
||||
*/
|
||||
|
||||
static or_state_t *or_state;
|
||||
NS_DECL(or_state_t *, get_or_state, (void));
|
||||
static or_state_t * acct_limits_get_or_state(void);
|
||||
ATTR_UNUSED static int acct_limits_get_or_state_called = 0;
|
||||
static or_state_t *
|
||||
NS(get_or_state)(void)
|
||||
acct_limits_get_or_state(void)
|
||||
{
|
||||
return or_state;
|
||||
}
|
||||
@ -35,7 +32,8 @@ test_accounting_limits(void *arg)
|
||||
time_t fake_time = time(NULL);
|
||||
(void) arg;
|
||||
|
||||
NS_MOCK(get_or_state);
|
||||
MOCK(get_or_state,
|
||||
acct_limits_get_or_state);
|
||||
or_state = or_state_new();
|
||||
|
||||
options->AccountingMax = 100;
|
||||
@ -94,12 +92,10 @@ test_accounting_limits(void *arg)
|
||||
|
||||
goto done;
|
||||
done:
|
||||
NS_UNMOCK(get_or_state);
|
||||
UNMOCK(get_or_state);
|
||||
or_state_free(or_state);
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
struct testcase_t accounting_tests[] = {
|
||||
{ "bwlimits", test_accounting_limits, TT_FORK, NULL, NULL },
|
||||
END_OF_TESTCASES
|
||||
|
@ -13,8 +13,6 @@
|
||||
|
||||
#include "test/log_test_helpers.h"
|
||||
|
||||
#define NS_MODULE le
|
||||
|
||||
static void
|
||||
test_compat_libevent_logging_callback(void *ignored)
|
||||
{
|
||||
|
@ -94,9 +94,6 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define NS_MODULE dir
|
||||
#define NS_SUBMODULE tests
|
||||
|
||||
static networkstatus_t *
|
||||
networkstatus_parse_vote_from_string_(const char *s,
|
||||
const char **eos_out,
|
||||
@ -5473,14 +5470,15 @@ test_dir_conn_purpose_to_string(void *data)
|
||||
teardown_capture_of_logs();
|
||||
}
|
||||
|
||||
NS_DECL(int, public_server_mode, (const or_options_t *options));
|
||||
static int dir_tests_public_server_mode(const or_options_t *options);
|
||||
ATTR_UNUSED static int dir_tests_public_server_mode_called = 0;
|
||||
|
||||
static int
|
||||
NS(public_server_mode)(const or_options_t *options)
|
||||
dir_tests_public_server_mode(const or_options_t *options)
|
||||
{
|
||||
(void)options;
|
||||
|
||||
if (CALLED(public_server_mode)++ == 0) {
|
||||
if (dir_tests_public_server_mode_called++ == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -5494,13 +5492,14 @@ test_dir_should_use_directory_guards(void *data)
|
||||
char *errmsg = NULL;
|
||||
(void)data;
|
||||
|
||||
NS_MOCK(public_server_mode);
|
||||
MOCK(public_server_mode,
|
||||
dir_tests_public_server_mode);
|
||||
|
||||
options = options_new();
|
||||
options_init(options);
|
||||
|
||||
tt_int_op(should_use_directory_guards(options), OP_EQ, 0);
|
||||
tt_int_op(CALLED(public_server_mode), OP_EQ, 1);
|
||||
tt_int_op(dir_tests_public_server_mode_called, OP_EQ, 1);
|
||||
|
||||
options->UseEntryGuards = 1;
|
||||
options->DownloadExtraInfo = 0;
|
||||
@ -5508,40 +5507,41 @@ test_dir_should_use_directory_guards(void *data)
|
||||
options->FetchDirInfoExtraEarly = 0;
|
||||
options->FetchUselessDescriptors = 0;
|
||||
tt_int_op(should_use_directory_guards(options), OP_EQ, 1);
|
||||
tt_int_op(CALLED(public_server_mode), OP_EQ, 2);
|
||||
tt_int_op(dir_tests_public_server_mode_called, OP_EQ, 2);
|
||||
|
||||
options->UseEntryGuards = 0;
|
||||
tt_int_op(should_use_directory_guards(options), OP_EQ, 0);
|
||||
tt_int_op(CALLED(public_server_mode), OP_EQ, 3);
|
||||
tt_int_op(dir_tests_public_server_mode_called, OP_EQ, 3);
|
||||
options->UseEntryGuards = 1;
|
||||
|
||||
options->DownloadExtraInfo = 1;
|
||||
tt_int_op(should_use_directory_guards(options), OP_EQ, 0);
|
||||
tt_int_op(CALLED(public_server_mode), OP_EQ, 4);
|
||||
tt_int_op(dir_tests_public_server_mode_called, OP_EQ, 4);
|
||||
options->DownloadExtraInfo = 0;
|
||||
|
||||
options->FetchDirInfoEarly = 1;
|
||||
tt_int_op(should_use_directory_guards(options), OP_EQ, 0);
|
||||
tt_int_op(CALLED(public_server_mode), OP_EQ, 5);
|
||||
tt_int_op(dir_tests_public_server_mode_called, OP_EQ, 5);
|
||||
options->FetchDirInfoEarly = 0;
|
||||
|
||||
options->FetchDirInfoExtraEarly = 1;
|
||||
tt_int_op(should_use_directory_guards(options), OP_EQ, 0);
|
||||
tt_int_op(CALLED(public_server_mode), OP_EQ, 6);
|
||||
tt_int_op(dir_tests_public_server_mode_called, OP_EQ, 6);
|
||||
options->FetchDirInfoExtraEarly = 0;
|
||||
|
||||
options->FetchUselessDescriptors = 1;
|
||||
tt_int_op(should_use_directory_guards(options), OP_EQ, 0);
|
||||
tt_int_op(CALLED(public_server_mode), OP_EQ, 7);
|
||||
tt_int_op(dir_tests_public_server_mode_called, OP_EQ, 7);
|
||||
options->FetchUselessDescriptors = 0;
|
||||
|
||||
done:
|
||||
NS_UNMOCK(public_server_mode);
|
||||
UNMOCK(public_server_mode);
|
||||
or_options_free(options);
|
||||
tor_free(errmsg);
|
||||
}
|
||||
|
||||
NS_DECL(void, directory_initiate_request, (directory_request_t *req));
|
||||
static void dir_tests_directory_initiate_request(directory_request_t *req);
|
||||
ATTR_UNUSED static int dir_tests_directory_initiate_request_called = 0;
|
||||
|
||||
static void
|
||||
test_dir_should_not_init_request_to_ourselves(void *data)
|
||||
@ -5551,7 +5551,8 @@ test_dir_should_not_init_request_to_ourselves(void *data)
|
||||
crypto_pk_t *key = pk_generate(2);
|
||||
(void) data;
|
||||
|
||||
NS_MOCK(directory_initiate_request);
|
||||
MOCK(directory_initiate_request,
|
||||
dir_tests_directory_initiate_request);
|
||||
|
||||
clear_dir_servers();
|
||||
routerlist_free_all();
|
||||
@ -5566,15 +5567,15 @@ test_dir_should_not_init_request_to_ourselves(void *data)
|
||||
dir_server_add(ourself);
|
||||
|
||||
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_STATUS_VOTE, 0, NULL);
|
||||
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 0);
|
||||
tt_int_op(dir_tests_directory_initiate_request_called, OP_EQ, 0);
|
||||
|
||||
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, 0,
|
||||
NULL);
|
||||
|
||||
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 0);
|
||||
tt_int_op(dir_tests_directory_initiate_request_called, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(directory_initiate_request);
|
||||
UNMOCK(directory_initiate_request);
|
||||
clear_dir_servers();
|
||||
routerlist_free_all();
|
||||
crypto_pk_free(key);
|
||||
@ -5588,7 +5589,8 @@ test_dir_should_not_init_request_to_dir_auths_without_v3_info(void *data)
|
||||
| MICRODESC_DIRINFO;
|
||||
(void) data;
|
||||
|
||||
NS_MOCK(directory_initiate_request);
|
||||
MOCK(directory_initiate_request,
|
||||
dir_tests_directory_initiate_request);
|
||||
|
||||
clear_dir_servers();
|
||||
routerlist_free_all();
|
||||
@ -5599,14 +5601,14 @@ test_dir_should_not_init_request_to_dir_auths_without_v3_info(void *data)
|
||||
dir_server_add(ds);
|
||||
|
||||
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_STATUS_VOTE, 0, NULL);
|
||||
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 0);
|
||||
tt_int_op(dir_tests_directory_initiate_request_called, OP_EQ, 0);
|
||||
|
||||
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, 0,
|
||||
NULL);
|
||||
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 0);
|
||||
tt_int_op(dir_tests_directory_initiate_request_called, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(directory_initiate_request);
|
||||
UNMOCK(directory_initiate_request);
|
||||
clear_dir_servers();
|
||||
routerlist_free_all();
|
||||
}
|
||||
@ -5617,7 +5619,8 @@ test_dir_should_init_request_to_dir_auths(void *data)
|
||||
dir_server_t *ds = NULL;
|
||||
(void) data;
|
||||
|
||||
NS_MOCK(directory_initiate_request);
|
||||
MOCK(directory_initiate_request,
|
||||
dir_tests_directory_initiate_request);
|
||||
|
||||
clear_dir_servers();
|
||||
routerlist_free_all();
|
||||
@ -5628,23 +5631,23 @@ test_dir_should_init_request_to_dir_auths(void *data)
|
||||
dir_server_add(ds);
|
||||
|
||||
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_STATUS_VOTE, 0, NULL);
|
||||
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 1);
|
||||
tt_int_op(dir_tests_directory_initiate_request_called, OP_EQ, 1);
|
||||
|
||||
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, 0,
|
||||
NULL);
|
||||
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 2);
|
||||
tt_int_op(dir_tests_directory_initiate_request_called, OP_EQ, 2);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(directory_initiate_request);
|
||||
UNMOCK(directory_initiate_request);
|
||||
clear_dir_servers();
|
||||
routerlist_free_all();
|
||||
}
|
||||
|
||||
void
|
||||
NS(directory_initiate_request)(directory_request_t *req)
|
||||
dir_tests_directory_initiate_request(directory_request_t *req)
|
||||
{
|
||||
(void)req;
|
||||
CALLED(directory_initiate_request)++;
|
||||
dir_tests_directory_initiate_request_called++;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -64,9 +64,6 @@ DISABLE_GCC_WARNING("-Woverlength-strings")
|
||||
ENABLE_GCC_WARNING("-Woverlength-strings")
|
||||
#endif
|
||||
|
||||
#define NS_MODULE dhg
|
||||
#define NS_SUBMODULE tests
|
||||
|
||||
#define NOT_FOUND "HTTP/1.0 404 Not found\r\n\r\n"
|
||||
#define BAD_REQUEST "HTTP/1.0 400 Bad request\r\n\r\n"
|
||||
#define SERVER_BUSY "HTTP/1.0 503 Directory busy, try again later\r\n\r\n"
|
||||
@ -365,12 +362,13 @@ test_dir_handle_get_rendezvous2_not_found(void *data)
|
||||
rend_cache_free_all();
|
||||
}
|
||||
|
||||
NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
|
||||
static const routerinfo_t * dhg_tests_router_get_my_routerinfo(void);
|
||||
ATTR_UNUSED static int dhg_tests_router_get_my_routerinfo_called = 0;
|
||||
|
||||
static routerinfo_t *mock_routerinfo;
|
||||
|
||||
static const routerinfo_t *
|
||||
NS(router_get_my_routerinfo)(void)
|
||||
dhg_tests_router_get_my_routerinfo(void)
|
||||
{
|
||||
if (!mock_routerinfo) {
|
||||
mock_routerinfo = tor_malloc_zero(sizeof(routerinfo_t));
|
||||
@ -395,7 +393,8 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
|
||||
(void) data;
|
||||
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
MOCK(router_get_my_routerinfo,
|
||||
dhg_tests_router_get_my_routerinfo);
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
@ -438,7 +437,7 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
|
||||
|
||||
done:
|
||||
UNMOCK(connection_write_to_buf_impl_);
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(router_get_my_routerinfo);
|
||||
|
||||
connection_free_minimal(TO_CONN(conn));
|
||||
tor_free(header);
|
||||
@ -770,7 +769,8 @@ test_dir_handle_get_server_descriptors_all(void* data)
|
||||
helper_setup_fake_routerlist();
|
||||
|
||||
//TODO: change to router_get_my_extrainfo when testing "extra" path
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
MOCK(router_get_my_routerinfo,
|
||||
dhg_tests_router_get_my_routerinfo);
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
|
||||
// We are one of the routers
|
||||
@ -812,7 +812,7 @@ test_dir_handle_get_server_descriptors_all(void* data)
|
||||
tt_ptr_op(conn->spool, OP_EQ, NULL);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(connection_write_to_buf_impl_);
|
||||
connection_free_minimal(TO_CONN(conn));
|
||||
tor_free(header);
|
||||
@ -869,7 +869,8 @@ test_dir_handle_get_server_descriptors_authority(void* data)
|
||||
crypto_pk_t *identity_pkey = pk_generate(0);
|
||||
(void) data;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
MOCK(router_get_my_routerinfo,
|
||||
dhg_tests_router_get_my_routerinfo);
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
|
||||
/* init mock */
|
||||
@ -914,7 +915,7 @@ test_dir_handle_get_server_descriptors_authority(void* data)
|
||||
tt_ptr_op(conn->spool, OP_EQ, NULL);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(connection_write_to_buf_impl_);
|
||||
tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
|
||||
tor_free(mock_routerinfo);
|
||||
@ -934,7 +935,8 @@ test_dir_handle_get_server_descriptors_fp(void* data)
|
||||
crypto_pk_t *identity_pkey = pk_generate(0);
|
||||
(void) data;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
MOCK(router_get_my_routerinfo,
|
||||
dhg_tests_router_get_my_routerinfo);
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
|
||||
/* init mock */
|
||||
@ -986,7 +988,7 @@ test_dir_handle_get_server_descriptors_fp(void* data)
|
||||
tt_ptr_op(conn->spool, OP_EQ, NULL);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(connection_write_to_buf_impl_);
|
||||
tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
|
||||
tor_free(mock_routerinfo);
|
||||
@ -1790,13 +1792,14 @@ test_dir_handle_get_status_vote_current_consensus_too_old(void *data)
|
||||
or_options_free(mock_options); mock_options = NULL;
|
||||
}
|
||||
|
||||
NS_DECL(int, geoip_get_country_by_addr, (const tor_addr_t *addr));
|
||||
static int dhg_tests_geoip_get_country_by_addr(const tor_addr_t *addr);
|
||||
ATTR_UNUSED static int dhg_tests_geoip_get_country_by_addr_called = 0;
|
||||
|
||||
int
|
||||
NS(geoip_get_country_by_addr)(const tor_addr_t *addr)
|
||||
dhg_tests_geoip_get_country_by_addr(const tor_addr_t *addr)
|
||||
{
|
||||
(void)addr;
|
||||
CALLED(geoip_get_country_by_addr)++;
|
||||
dhg_tests_geoip_get_country_by_addr_called++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1860,7 +1863,8 @@ test_dir_handle_get_status_vote_current_consensus_ns(void* data)
|
||||
dirserv_free_all();
|
||||
clear_geoip_db();
|
||||
|
||||
NS_MOCK(geoip_get_country_by_addr);
|
||||
MOCK(geoip_get_country_by_addr,
|
||||
dhg_tests_geoip_get_country_by_addr);
|
||||
MOCK(get_options, mock_get_options);
|
||||
|
||||
init_mock_options();
|
||||
@ -1897,7 +1901,7 @@ test_dir_handle_get_status_vote_current_consensus_ns(void* data)
|
||||
tt_str_op("ab=8", OP_EQ, hist);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(geoip_get_country_by_addr);
|
||||
UNMOCK(geoip_get_country_by_addr);
|
||||
UNMOCK(get_options);
|
||||
tor_free(header);
|
||||
tor_free(comp_body);
|
||||
@ -2249,10 +2253,11 @@ test_dir_handle_get_status_vote_next_bandwidth_not_found(void* data)
|
||||
tor_free(header);
|
||||
}
|
||||
|
||||
NS_DECL(const char*, dirvote_get_pending_consensus, (consensus_flavor_t flav));
|
||||
static const char* dhg_tests_dirvote_get_pending_consensus(consensus_flavor_t flav);
|
||||
ATTR_UNUSED static int dhg_tests_dirvote_get_pending_consensus_called = 0;
|
||||
|
||||
const char*
|
||||
NS(dirvote_get_pending_consensus)(consensus_flavor_t flav)
|
||||
dhg_tests_dirvote_get_pending_consensus(consensus_flavor_t flav)
|
||||
{
|
||||
(void)flav;
|
||||
return "pending consensus";
|
||||
@ -2265,7 +2270,8 @@ test_dir_handle_get_status_vote_next_consensus(void* data)
|
||||
size_t body_used = 0;
|
||||
(void) data;
|
||||
|
||||
NS_MOCK(dirvote_get_pending_consensus);
|
||||
MOCK(dirvote_get_pending_consensus,
|
||||
dhg_tests_dirvote_get_pending_consensus);
|
||||
|
||||
status_vote_next_consensus_test(&header, &body, &body_used);
|
||||
tt_assert(header);
|
||||
@ -2278,7 +2284,7 @@ test_dir_handle_get_status_vote_next_consensus(void* data)
|
||||
tt_str_op("pending consensus", OP_EQ, body);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(dirvote_get_pending_consensus);
|
||||
UNMOCK(dirvote_get_pending_consensus);
|
||||
tor_free(header);
|
||||
tor_free(body);
|
||||
}
|
||||
@ -2291,7 +2297,8 @@ test_dir_handle_get_status_vote_next_consensus_busy(void* data)
|
||||
(void) data;
|
||||
|
||||
MOCK(get_options, mock_get_options);
|
||||
NS_MOCK(dirvote_get_pending_consensus);
|
||||
MOCK(dirvote_get_pending_consensus,
|
||||
dhg_tests_dirvote_get_pending_consensus);
|
||||
|
||||
//Make it busy
|
||||
init_mock_options();
|
||||
@ -2303,7 +2310,7 @@ test_dir_handle_get_status_vote_next_consensus_busy(void* data)
|
||||
tt_str_op(SERVER_BUSY, OP_EQ, header);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(dirvote_get_pending_consensus);
|
||||
UNMOCK(dirvote_get_pending_consensus);
|
||||
UNMOCK(get_options);
|
||||
tor_free(header);
|
||||
tor_free(body);
|
||||
@ -2347,10 +2354,11 @@ test_dir_handle_get_status_vote_next_consensus_signatures_not_found(void* data)
|
||||
tor_free(body);
|
||||
}
|
||||
|
||||
NS_DECL(const char*, dirvote_get_pending_detached_signatures, (void));
|
||||
static const char* dhg_tests_dirvote_get_pending_detached_signatures(void);
|
||||
ATTR_UNUSED static int dhg_tests_dirvote_get_pending_detached_signatures_called = 0;
|
||||
|
||||
const char*
|
||||
NS(dirvote_get_pending_detached_signatures)(void)
|
||||
dhg_tests_dirvote_get_pending_detached_signatures(void)
|
||||
{
|
||||
return "pending detached sigs";
|
||||
}
|
||||
@ -2362,7 +2370,8 @@ test_dir_handle_get_status_vote_next_consensus_signatures(void* data)
|
||||
size_t body_used = 0;
|
||||
(void) data;
|
||||
|
||||
NS_MOCK(dirvote_get_pending_detached_signatures);
|
||||
MOCK(dirvote_get_pending_detached_signatures,
|
||||
dhg_tests_dirvote_get_pending_detached_signatures);
|
||||
|
||||
status_vote_next_consensus_signatures_test(&header, &body, &body_used);
|
||||
tt_assert(header);
|
||||
@ -2375,7 +2384,7 @@ test_dir_handle_get_status_vote_next_consensus_signatures(void* data)
|
||||
tt_str_op("pending detached sigs", OP_EQ, body);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(dirvote_get_pending_detached_signatures);
|
||||
UNMOCK(dirvote_get_pending_detached_signatures);
|
||||
tor_free(header);
|
||||
tor_free(body);
|
||||
}
|
||||
@ -2387,7 +2396,8 @@ test_dir_handle_get_status_vote_next_consensus_signatures_busy(void* data)
|
||||
size_t body_used;
|
||||
(void) data;
|
||||
|
||||
NS_MOCK(dirvote_get_pending_detached_signatures);
|
||||
MOCK(dirvote_get_pending_detached_signatures,
|
||||
dhg_tests_dirvote_get_pending_detached_signatures);
|
||||
MOCK(get_options, mock_get_options);
|
||||
|
||||
//Make it busy
|
||||
@ -2401,7 +2411,7 @@ test_dir_handle_get_status_vote_next_consensus_signatures_busy(void* data)
|
||||
|
||||
done:
|
||||
UNMOCK(get_options);
|
||||
NS_UNMOCK(dirvote_get_pending_detached_signatures);
|
||||
UNMOCK(dirvote_get_pending_detached_signatures);
|
||||
tor_free(header);
|
||||
tor_free(body);
|
||||
or_options_free(mock_options); mock_options = NULL;
|
||||
|
@ -20,10 +20,7 @@
|
||||
#include <event2/event.h>
|
||||
#include <event2/dns.h>
|
||||
|
||||
#define NS_MODULE dns
|
||||
|
||||
#ifdef HAVE_EVDNS_BASE_GET_NAMESERVER_ADDR
|
||||
#define NS_SUBMODULE configure_ns_fallback
|
||||
|
||||
static or_options_t options = {
|
||||
.ORPort_set = 1,
|
||||
@ -36,7 +33,7 @@ mock_get_options(void)
|
||||
}
|
||||
|
||||
static void
|
||||
NS(test_main)(void *arg)
|
||||
test_dns_configure_ns_fallback(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
tor_addr_t *nameserver_addr = NULL;
|
||||
@ -76,13 +73,10 @@ NS(test_main)(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
#endif /* defined(HAVE_EVDNS_BASE_GET_NAMESERVER_ADDR) */
|
||||
|
||||
#define NS_SUBMODULE clip_ttl
|
||||
|
||||
static void
|
||||
NS(test_main)(void *arg)
|
||||
test_dns_clip_ttl(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
@ -96,10 +90,6 @@ NS(test_main)(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
#define NS_SUBMODULE resolve
|
||||
|
||||
static int resolve_retval = 0;
|
||||
static int resolve_made_conn_pending = 0;
|
||||
static char *resolved_name = NULL;
|
||||
@ -107,7 +97,8 @@ static cached_resolve_t *cache_entry_mock = NULL;
|
||||
|
||||
static int n_fake_impl = 0;
|
||||
|
||||
NS_DECL(int, dns_resolve_impl, (edge_connection_t *exitconn, int is_resolve, or_circuit_t *oncirc, char **hostname_out, int *made_connection_pending_out, cached_resolve_t **resolve_out));
|
||||
static int dns_resolve_dns_resolve_impl(edge_connection_t *exitconn, int is_resolve, or_circuit_t *oncirc, char **hostname_out, int *made_connection_pending_out, cached_resolve_t **resolve_out);
|
||||
ATTR_UNUSED static int dns_resolve_dns_resolve_impl_called = 0;
|
||||
|
||||
/** This will be our configurable substitute for <b>dns_resolve_impl</b> in
|
||||
* dns.c. It will return <b>resolve_retval</b>,
|
||||
@ -118,7 +109,7 @@ NS_DECL(int, dns_resolve_impl, (edge_connection_t *exitconn, int is_resolve, or_
|
||||
* 1.
|
||||
*/
|
||||
static int
|
||||
NS(dns_resolve_impl)(edge_connection_t *exitconn, int is_resolve,
|
||||
dns_resolve_dns_resolve_impl(edge_connection_t *exitconn, int is_resolve,
|
||||
or_circuit_t *oncirc, char **hostname_out,
|
||||
int *made_connection_pending_out,
|
||||
cached_resolve_t **resolve_out)
|
||||
@ -148,7 +139,7 @@ static uint8_t last_answer_type = 0;
|
||||
static cached_resolve_t *last_resolved;
|
||||
|
||||
static void
|
||||
NS(send_resolved_cell)(edge_connection_t *conn, uint8_t answer_type,
|
||||
dns_resolve_send_resolved_cell(edge_connection_t *conn, uint8_t answer_type,
|
||||
const cached_resolve_t *resolved)
|
||||
{
|
||||
conn_for_resolved_cell = conn;
|
||||
@ -164,7 +155,7 @@ static int n_send_resolved_hostname_cell_replacement = 0;
|
||||
static char *last_resolved_hostname = NULL;
|
||||
|
||||
static void
|
||||
NS(send_resolved_hostname_cell)(edge_connection_t *conn,
|
||||
dns_resolve_send_resolved_hostname_cell(edge_connection_t *conn,
|
||||
const char *hostname)
|
||||
{
|
||||
conn_for_resolved_cell = conn;
|
||||
@ -178,7 +169,7 @@ NS(send_resolved_hostname_cell)(edge_connection_t *conn,
|
||||
static int n_dns_cancel_pending_resolve_replacement = 0;
|
||||
|
||||
static void
|
||||
NS(dns_cancel_pending_resolve)(const char *address)
|
||||
dns_resolve_dns_cancel_pending_resolve(const char *address)
|
||||
{
|
||||
(void) address;
|
||||
n_dns_cancel_pending_resolve_replacement++;
|
||||
@ -188,7 +179,7 @@ static int n_connection_free = 0;
|
||||
static connection_t *last_freed_conn = NULL;
|
||||
|
||||
static void
|
||||
NS(connection_free_)(connection_t *conn)
|
||||
dns_resolve_connection_free_(connection_t *conn)
|
||||
{
|
||||
n_connection_free++;
|
||||
|
||||
@ -196,7 +187,7 @@ NS(connection_free_)(connection_t *conn)
|
||||
}
|
||||
|
||||
static void
|
||||
NS(test_main)(void *arg)
|
||||
test_dns_resolve(void *arg)
|
||||
{
|
||||
(void) arg;
|
||||
int retval;
|
||||
@ -215,9 +206,12 @@ NS(test_main)(void *arg)
|
||||
memset(exitconn,0,sizeof(edge_connection_t));
|
||||
memset(nextconn,0,sizeof(edge_connection_t));
|
||||
|
||||
NS_MOCK(dns_resolve_impl);
|
||||
NS_MOCK(send_resolved_cell);
|
||||
NS_MOCK(send_resolved_hostname_cell);
|
||||
MOCK(dns_resolve_impl,
|
||||
dns_resolve_dns_resolve_impl);
|
||||
MOCK(send_resolved_cell,
|
||||
dns_resolve_send_resolved_cell);
|
||||
MOCK(send_resolved_hostname_cell,
|
||||
dns_resolve_send_resolved_hostname_cell);
|
||||
|
||||
/*
|
||||
* CASE 1: dns_resolve_impl returns 1 and sets a hostname. purpose is
|
||||
@ -330,8 +324,10 @@ NS(test_main)(void *arg)
|
||||
* on exitconn with type being RESOLVED_TYPE_ERROR.
|
||||
*/
|
||||
|
||||
NS_MOCK(dns_cancel_pending_resolve);
|
||||
NS_MOCK(connection_free_);
|
||||
MOCK(dns_cancel_pending_resolve,
|
||||
dns_resolve_dns_cancel_pending_resolve);
|
||||
MOCK(connection_free_,
|
||||
dns_resolve_connection_free_);
|
||||
|
||||
exitconn->on_circuit = &(on_circuit->base_);
|
||||
exitconn->base_.purpose = EXIT_PURPOSE_RESOLVE;
|
||||
@ -354,11 +350,11 @@ NS(test_main)(void *arg)
|
||||
tt_assert(last_freed_conn == TO_CONN(exitconn));
|
||||
|
||||
done:
|
||||
NS_UNMOCK(dns_resolve_impl);
|
||||
NS_UNMOCK(send_resolved_cell);
|
||||
NS_UNMOCK(send_resolved_hostname_cell);
|
||||
NS_UNMOCK(dns_cancel_pending_resolve);
|
||||
NS_UNMOCK(connection_free_);
|
||||
UNMOCK(dns_resolve_impl);
|
||||
UNMOCK(send_resolved_cell);
|
||||
UNMOCK(send_resolved_hostname_cell);
|
||||
UNMOCK(dns_cancel_pending_resolve);
|
||||
UNMOCK(connection_free_);
|
||||
tor_free(on_circuit);
|
||||
tor_free(exitconn);
|
||||
tor_free(nextconn);
|
||||
@ -368,8 +364,6 @@ NS(test_main)(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
/** Create an <b>edge_connection_t</b> instance that is considered a
|
||||
* valid exit connection by asserts in dns_resolve_impl.
|
||||
*/
|
||||
@ -386,8 +380,6 @@ create_valid_exitconn(void)
|
||||
return exitconn;
|
||||
}
|
||||
|
||||
#define NS_SUBMODULE ASPECT(impl, addr_is_ip)
|
||||
|
||||
/*
|
||||
* Given that <b>exitconn->base_.address</b> is IP address string, we
|
||||
* want dns_resolve_impl() to parse it and store in
|
||||
@ -396,7 +388,7 @@ create_valid_exitconn(void)
|
||||
*/
|
||||
|
||||
static void
|
||||
NS(test_main)(void *arg)
|
||||
test_dns_impl_addr_is_ip(void *arg)
|
||||
{
|
||||
int retval;
|
||||
int made_pending;
|
||||
@ -429,21 +421,17 @@ NS(test_main)(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
#define NS_SUBMODULE ASPECT(impl, non_exit)
|
||||
|
||||
/** Given that Tor instance is not configured as an exit node, we want
|
||||
* dns_resolve_impl() to fail with return value -1.
|
||||
*/
|
||||
static int
|
||||
NS(router_my_exit_policy_is_reject_star)(void)
|
||||
dns_impl_non_exit_router_my_exit_policy_is_reject_star(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
NS(test_main)(void *arg)
|
||||
test_dns_impl_non_exit(void *arg)
|
||||
{
|
||||
int retval;
|
||||
int made_pending;
|
||||
@ -455,7 +443,8 @@ NS(test_main)(void *arg)
|
||||
|
||||
TO_CONN(exitconn)->address = tor_strdup("torproject.org");
|
||||
|
||||
NS_MOCK(router_my_exit_policy_is_reject_star);
|
||||
MOCK(router_my_exit_policy_is_reject_star,
|
||||
dns_impl_non_exit_router_my_exit_policy_is_reject_star);
|
||||
|
||||
retval = dns_resolve_impl(exitconn, 1, on_circ, NULL, &made_pending,
|
||||
NULL);
|
||||
@ -466,27 +455,23 @@ NS(test_main)(void *arg)
|
||||
tor_free(TO_CONN(exitconn)->address);
|
||||
tor_free(exitconn);
|
||||
tor_free(on_circ);
|
||||
NS_UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
return;
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
#define NS_SUBMODULE ASPECT(impl, addr_is_invalid_dest)
|
||||
|
||||
/** Given that address is not a valid destination (as judged by
|
||||
* address_is_invalid_destination() function), we want dns_resolve_impl()
|
||||
* function to fail with return value -1.
|
||||
*/
|
||||
|
||||
static int
|
||||
NS(router_my_exit_policy_is_reject_star)(void)
|
||||
dns_impl_addr_is_invalid_dest_router_my_exit_policy_is_reject_star(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
NS(test_main)(void *arg)
|
||||
test_dns_impl_addr_is_invalid_dest(void *arg)
|
||||
{
|
||||
int retval;
|
||||
int made_pending;
|
||||
@ -496,7 +481,8 @@ NS(test_main)(void *arg)
|
||||
|
||||
(void)arg;
|
||||
|
||||
NS_MOCK(router_my_exit_policy_is_reject_star);
|
||||
MOCK(router_my_exit_policy_is_reject_star,
|
||||
dns_impl_addr_is_invalid_dest_router_my_exit_policy_is_reject_star);
|
||||
|
||||
TO_CONN(exitconn)->address = tor_strdup("invalid#@!.org");
|
||||
|
||||
@ -506,29 +492,25 @@ NS(test_main)(void *arg)
|
||||
tt_int_op(retval,OP_EQ,-1);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
tor_free(TO_CONN(exitconn)->address);
|
||||
tor_free(exitconn);
|
||||
tor_free(on_circ);
|
||||
return;
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
#define NS_SUBMODULE ASPECT(impl, malformed_ptr)
|
||||
|
||||
/** Given that address is a malformed PTR name, we want dns_resolve_impl to
|
||||
* fail.
|
||||
*/
|
||||
|
||||
static int
|
||||
NS(router_my_exit_policy_is_reject_star)(void)
|
||||
dns_impl_malformed_ptr_router_my_exit_policy_is_reject_star(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
NS(test_main)(void *arg)
|
||||
test_dns_impl_malformed_ptr(void *arg)
|
||||
{
|
||||
int retval;
|
||||
int made_pending;
|
||||
@ -540,7 +522,8 @@ NS(test_main)(void *arg)
|
||||
|
||||
TO_CONN(exitconn)->address = tor_strdup("1.0.0.127.in-addr.arpa");
|
||||
|
||||
NS_MOCK(router_my_exit_policy_is_reject_star);
|
||||
MOCK(router_my_exit_policy_is_reject_star,
|
||||
dns_impl_malformed_ptr_router_my_exit_policy_is_reject_star);
|
||||
|
||||
retval = dns_resolve_impl(exitconn, 1, on_circ, NULL, &made_pending,
|
||||
NULL);
|
||||
@ -558,30 +541,26 @@ NS(test_main)(void *arg)
|
||||
tt_int_op(retval,OP_EQ,-1);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
tor_free(TO_CONN(exitconn)->address);
|
||||
tor_free(exitconn);
|
||||
tor_free(on_circ);
|
||||
return;
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
#define NS_SUBMODULE ASPECT(impl, cache_hit_pending)
|
||||
|
||||
/* Given that there is already a pending resolve for the given address,
|
||||
* we want dns_resolve_impl to append our exit connection to list
|
||||
* of pending connections for the pending DNS request and return 0.
|
||||
*/
|
||||
|
||||
static int
|
||||
NS(router_my_exit_policy_is_reject_star)(void)
|
||||
dns_impl_cache_hit_pending_router_my_exit_policy_is_reject_star(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
NS(test_main)(void *arg)
|
||||
test_dns_impl_cache_hit_pending(void *arg)
|
||||
{
|
||||
int retval;
|
||||
int made_pending = 0;
|
||||
@ -604,7 +583,8 @@ NS(test_main)(void *arg)
|
||||
strlcpy(cache_entry->address, TO_CONN(exitconn)->address,
|
||||
sizeof(cache_entry->address));
|
||||
|
||||
NS_MOCK(router_my_exit_policy_is_reject_star);
|
||||
MOCK(router_my_exit_policy_is_reject_star,
|
||||
dns_impl_cache_hit_pending_router_my_exit_policy_is_reject_star);
|
||||
|
||||
dns_init();
|
||||
|
||||
@ -622,7 +602,7 @@ NS(test_main)(void *arg)
|
||||
tt_assert(pending_conn->conn == exitconn);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
tor_free(on_circ);
|
||||
tor_free(TO_CONN(exitconn)->address);
|
||||
tor_free(cache_entry->pending_connections);
|
||||
@ -631,16 +611,12 @@ NS(test_main)(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
#define NS_SUBMODULE ASPECT(impl, cache_hit_cached)
|
||||
|
||||
/* Given that a finished DNS resolve is available in our cache, we want
|
||||
* dns_resolve_impl() return it to called via resolve_out and pass the
|
||||
* handling to set_exitconn_info_from_resolve function.
|
||||
*/
|
||||
static int
|
||||
NS(router_my_exit_policy_is_reject_star)(void)
|
||||
dns_impl_cache_hit_cached_router_my_exit_policy_is_reject_star(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -649,7 +625,7 @@ static edge_connection_t *last_exitconn = NULL;
|
||||
static cached_resolve_t *last_resolve = NULL;
|
||||
|
||||
static int
|
||||
NS(set_exitconn_info_from_resolve)(edge_connection_t *exitconn,
|
||||
dns_impl_cache_hit_cached_set_exitconn_info_from_resolve(edge_connection_t *exitconn,
|
||||
const cached_resolve_t *resolve,
|
||||
char **hostname_out)
|
||||
{
|
||||
@ -662,7 +638,7 @@ NS(set_exitconn_info_from_resolve)(edge_connection_t *exitconn,
|
||||
}
|
||||
|
||||
static void
|
||||
NS(test_main)(void *arg)
|
||||
test_dns_impl_cache_hit_cached(void *arg)
|
||||
{
|
||||
int retval;
|
||||
int made_pending = 0;
|
||||
@ -685,8 +661,10 @@ NS(test_main)(void *arg)
|
||||
strlcpy(cache_entry->address, TO_CONN(exitconn)->address,
|
||||
sizeof(cache_entry->address));
|
||||
|
||||
NS_MOCK(router_my_exit_policy_is_reject_star);
|
||||
NS_MOCK(set_exitconn_info_from_resolve);
|
||||
MOCK(router_my_exit_policy_is_reject_star,
|
||||
dns_impl_cache_hit_cached_router_my_exit_policy_is_reject_star);
|
||||
MOCK(set_exitconn_info_from_resolve,
|
||||
dns_impl_cache_hit_cached_set_exitconn_info_from_resolve);
|
||||
|
||||
dns_init();
|
||||
|
||||
@ -703,8 +681,8 @@ NS(test_main)(void *arg)
|
||||
tt_assert(last_resolve == cache_entry);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
NS_UNMOCK(set_exitconn_info_from_resolve);
|
||||
UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
UNMOCK(set_exitconn_info_from_resolve);
|
||||
tor_free(on_circ);
|
||||
tor_free(TO_CONN(exitconn)->address);
|
||||
tor_free(cache_entry->pending_connections);
|
||||
@ -712,10 +690,6 @@ NS(test_main)(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
#define NS_SUBMODULE ASPECT(impl, cache_miss)
|
||||
|
||||
/* Given that there are neither pending nor pre-cached resolve for a given
|
||||
* address, we want dns_resolve_impl() to create a new cached_resolve_t
|
||||
* object, mark it as pending, insert it into the cache, attach the exit
|
||||
@ -723,7 +697,7 @@ NS(test_main)(void *arg)
|
||||
* with the cached_resolve_t object it created.
|
||||
*/
|
||||
static int
|
||||
NS(router_my_exit_policy_is_reject_star)(void)
|
||||
dns_impl_cache_miss_router_my_exit_policy_is_reject_star(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -731,7 +705,7 @@ NS(router_my_exit_policy_is_reject_star)(void)
|
||||
static cached_resolve_t *last_launched_resolve = NULL;
|
||||
|
||||
static int
|
||||
NS(launch_resolve)(cached_resolve_t *resolve)
|
||||
dns_impl_cache_miss_launch_resolve(cached_resolve_t *resolve)
|
||||
{
|
||||
last_launched_resolve = resolve;
|
||||
|
||||
@ -739,7 +713,7 @@ NS(launch_resolve)(cached_resolve_t *resolve)
|
||||
}
|
||||
|
||||
static void
|
||||
NS(test_main)(void *arg)
|
||||
test_dns_impl_cache_miss(void *arg)
|
||||
{
|
||||
int retval;
|
||||
int made_pending = 0;
|
||||
@ -758,8 +732,10 @@ NS(test_main)(void *arg)
|
||||
|
||||
strlcpy(query.address, TO_CONN(exitconn)->address, sizeof(query.address));
|
||||
|
||||
NS_MOCK(router_my_exit_policy_is_reject_star);
|
||||
NS_MOCK(launch_resolve);
|
||||
MOCK(router_my_exit_policy_is_reject_star,
|
||||
dns_impl_cache_miss_router_my_exit_policy_is_reject_star);
|
||||
MOCK(launch_resolve,
|
||||
dns_impl_cache_miss_launch_resolve);
|
||||
|
||||
dns_init();
|
||||
|
||||
@ -782,8 +758,8 @@ NS(test_main)(void *arg)
|
||||
tt_str_op(cache_entry->address,OP_EQ,TO_CONN(exitconn)->address);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
NS_UNMOCK(launch_resolve);
|
||||
UNMOCK(router_my_exit_policy_is_reject_star);
|
||||
UNMOCK(launch_resolve);
|
||||
tor_free(on_circ);
|
||||
tor_free(TO_CONN(exitconn)->address);
|
||||
if (cache_entry)
|
||||
@ -793,22 +769,19 @@ NS(test_main)(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
struct testcase_t dns_tests[] = {
|
||||
#ifdef HAVE_EVDNS_BASE_GET_NAMESERVER_ADDR
|
||||
TEST_CASE(configure_ns_fallback),
|
||||
{ "configure_ns_fallback", test_dns_configure_ns_fallback, TT_FORK, NULL, NULL },
|
||||
#endif
|
||||
TEST_CASE(clip_ttl),
|
||||
TEST_CASE(resolve),
|
||||
TEST_CASE_ASPECT(impl, addr_is_ip),
|
||||
TEST_CASE_ASPECT(impl, non_exit),
|
||||
TEST_CASE_ASPECT(impl, addr_is_invalid_dest),
|
||||
TEST_CASE_ASPECT(impl, malformed_ptr),
|
||||
TEST_CASE_ASPECT(impl, cache_hit_pending),
|
||||
TEST_CASE_ASPECT(impl, cache_hit_cached),
|
||||
TEST_CASE_ASPECT(impl, cache_miss),
|
||||
{ "clip_ttl", test_dns_clip_ttl, TT_FORK, NULL, NULL },
|
||||
{ "resolve", test_dns_resolve, TT_FORK, NULL, NULL },
|
||||
{ "impl_addr_is_ip", test_dns_impl_addr_is_ip, TT_FORK, NULL, NULL },
|
||||
{ "impl_non_exit", test_dns_impl_non_exit, TT_FORK, NULL, NULL },
|
||||
{ "impl_addr_is_invalid_dest", test_dns_impl_addr_is_invalid_dest, TT_FORK, NULL, NULL },
|
||||
{ "impl_malformed_ptr", test_dns_impl_malformed_ptr, TT_FORK, NULL, NULL },
|
||||
{ "impl_cache_hit_pending", test_dns_impl_cache_hit_pending, TT_FORK, NULL, NULL },
|
||||
{ "impl_cache_hit_cached", test_dns_impl_cache_hit_cached, TT_FORK, NULL, NULL },
|
||||
{ "impl_cache_miss", test_dns_impl_cache_miss, TT_FORK, NULL, NULL },
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
||||
#undef NS_MODULE
|
||||
|
@ -35,9 +35,6 @@
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#define NS_MODULE opt
|
||||
#define NS_SUBMODULE tests
|
||||
|
||||
typedef struct {
|
||||
int severity;
|
||||
log_domain_mask_t domain;
|
||||
@ -1167,13 +1164,14 @@ test_options_validate__transproxy(void *ignored)
|
||||
tor_free(msg);
|
||||
}
|
||||
|
||||
NS_DECL(country_t, geoip_get_country, (const char *country));
|
||||
static country_t opt_tests_geoip_get_country(const char *country);
|
||||
ATTR_UNUSED static int opt_tests_geoip_get_country_called = 0;
|
||||
|
||||
static country_t
|
||||
NS(geoip_get_country)(const char *countrycode)
|
||||
opt_tests_geoip_get_country(const char *countrycode)
|
||||
{
|
||||
(void)countrycode;
|
||||
CALLED(geoip_get_country)++;
|
||||
opt_tests_geoip_get_country_called++;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1183,7 +1181,8 @@ test_options_validate__exclude_nodes(void *ignored)
|
||||
{
|
||||
(void)ignored;
|
||||
|
||||
NS_MOCK(geoip_get_country);
|
||||
MOCK(geoip_get_country,
|
||||
opt_tests_geoip_get_country);
|
||||
|
||||
int ret;
|
||||
char *msg;
|
||||
@ -1247,7 +1246,7 @@ test_options_validate__exclude_nodes(void *ignored)
|
||||
tor_free(msg);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(geoip_get_country);
|
||||
UNMOCK(geoip_get_country);
|
||||
teardown_capture_of_logs();
|
||||
free_options_test_data(tdata);
|
||||
tor_free(msg);
|
||||
@ -1752,7 +1751,8 @@ test_options_validate__use_bridges(void *ignored)
|
||||
" the Internet, so they must not set UseBridges.");
|
||||
tor_free(msg);
|
||||
|
||||
NS_MOCK(geoip_get_country);
|
||||
MOCK(geoip_get_country,
|
||||
opt_tests_geoip_get_country);
|
||||
free_options_test_data(tdata);
|
||||
tdata = get_options_test_data("UseBridges 1\n"
|
||||
"EntryNodes {cn}\n");
|
||||
@ -1795,7 +1795,7 @@ test_options_validate__use_bridges(void *ignored)
|
||||
tor_free(msg);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(geoip_get_country);
|
||||
UNMOCK(geoip_get_country);
|
||||
policies_free_all();
|
||||
free_options_test_data(tdata);
|
||||
tor_free(msg);
|
||||
@ -1807,7 +1807,8 @@ test_options_validate__entry_nodes(void *ignored)
|
||||
(void)ignored;
|
||||
int ret;
|
||||
char *msg;
|
||||
NS_MOCK(geoip_get_country);
|
||||
MOCK(geoip_get_country,
|
||||
opt_tests_geoip_get_country);
|
||||
options_test_data_t *tdata = get_options_test_data(
|
||||
"EntryNodes {cn}\n"
|
||||
"UseEntryGuards 0\n");
|
||||
@ -1827,7 +1828,7 @@ test_options_validate__entry_nodes(void *ignored)
|
||||
tor_free(msg);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(geoip_get_country);
|
||||
UNMOCK(geoip_get_country);
|
||||
free_options_test_data(tdata);
|
||||
tor_free(msg);
|
||||
}
|
||||
|
@ -9,8 +9,6 @@
|
||||
|
||||
#include "test/log_test_helpers.h"
|
||||
|
||||
#define NS_MODULE procmon
|
||||
|
||||
struct event_base;
|
||||
|
||||
static void
|
||||
|
@ -21,8 +21,6 @@
|
||||
#include "test/rend_test_helpers.h"
|
||||
#include "test/log_test_helpers.h"
|
||||
|
||||
#define NS_MODULE rcache
|
||||
|
||||
static const int RECENT_TIME = -10;
|
||||
static const int TIME_IN_THE_PAST = -(REND_CACHE_MAX_AGE + \
|
||||
REND_CACHE_MAX_SKEW + 60);
|
||||
@ -369,13 +367,13 @@ test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
|
||||
rend_data_free(mock_rend_query);
|
||||
}
|
||||
|
||||
#define NS_SUBMODULE lookup_v2_desc_as_dir
|
||||
NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
|
||||
static const routerinfo_t * rcache_lookup_v2_desc_as_dir_router_get_my_routerinfo(void);
|
||||
ATTR_UNUSED static int rcache_lookup_v2_desc_as_dir_router_get_my_routerinfo_called = 0;
|
||||
|
||||
static routerinfo_t *mock_routerinfo;
|
||||
|
||||
static const routerinfo_t *
|
||||
NS(router_get_my_routerinfo)(void)
|
||||
rcache_lookup_v2_desc_as_dir_router_get_my_routerinfo(void)
|
||||
{
|
||||
if (!mock_routerinfo) {
|
||||
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
|
||||
@ -395,7 +393,8 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
|
||||
|
||||
(void)data;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
MOCK(router_get_my_routerinfo,
|
||||
rcache_lookup_v2_desc_as_dir_router_get_my_routerinfo);
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
@ -418,20 +417,18 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
|
||||
tt_assert(ret_desc);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(router_get_my_routerinfo);
|
||||
tor_free(mock_routerinfo);
|
||||
rend_cache_free_all();
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||
tor_free(service_id);
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
#define NS_SUBMODULE store_v2_desc_as_dir
|
||||
NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
|
||||
static const routerinfo_t * rcache_store_v2_desc_as_dir_router_get_my_routerinfo(void);
|
||||
ATTR_UNUSED static int rcache_store_v2_desc_as_dir_router_get_my_routerinfo_called = 0;
|
||||
|
||||
static const routerinfo_t *
|
||||
NS(router_get_my_routerinfo)(void)
|
||||
rcache_store_v2_desc_as_dir_router_get_my_routerinfo(void)
|
||||
{
|
||||
return mock_routerinfo;
|
||||
}
|
||||
@ -444,7 +441,8 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
|
||||
rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
|
||||
char *service_id = NULL;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
MOCK(router_get_my_routerinfo,
|
||||
rcache_store_v2_desc_as_dir_router_get_my_routerinfo);
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
@ -485,7 +483,7 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(router_get_my_routerinfo);
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||
tor_free(service_id);
|
||||
rend_cache_free_all();
|
||||
@ -505,7 +503,8 @@ test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
|
||||
rend_encoded_v2_service_descriptor_t *desc_holder_newer;
|
||||
rend_encoded_v2_service_descriptor_t *desc_holder_older;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
MOCK(router_get_my_routerinfo,
|
||||
rcache_store_v2_desc_as_dir_router_get_my_routerinfo);
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
@ -543,7 +542,7 @@ test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(router_get_my_routerinfo);
|
||||
rend_cache_free_all();
|
||||
rend_service_descriptor_free(generated);
|
||||
tor_free(service_id);
|
||||
@ -568,7 +567,8 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
|
||||
rend_encoded_v2_service_descriptor_t *desc_holder_one = NULL;
|
||||
rend_encoded_v2_service_descriptor_t *desc_holder_two = NULL;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
MOCK(router_get_my_routerinfo,
|
||||
rcache_store_v2_desc_as_dir_router_get_my_routerinfo);
|
||||
|
||||
rend_cache_init();
|
||||
|
||||
@ -602,7 +602,7 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(router_get_my_routerinfo);
|
||||
rend_cache_free_all();
|
||||
rend_service_descriptor_free(generated);
|
||||
tor_free(service_id);
|
||||
@ -613,8 +613,6 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
|
||||
rend_encoded_v2_service_descriptor_free(desc_holder_two);
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
static void
|
||||
test_rend_cache_init(void *data)
|
||||
{
|
||||
@ -1074,8 +1072,6 @@ test_rend_cache_intro_failure_note(void *data)
|
||||
rend_cache_free_all();
|
||||
}
|
||||
|
||||
#define NS_SUBMODULE clean_v2_descs_as_dir
|
||||
|
||||
static void
|
||||
test_rend_cache_clean_v2_descs_as_dir(void *data)
|
||||
{
|
||||
@ -1116,8 +1112,6 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
|
||||
rend_cache_free_all();
|
||||
}
|
||||
|
||||
#undef NS_SUBMODULE
|
||||
|
||||
static void
|
||||
test_rend_cache_entry_allocation(void *data)
|
||||
{
|
||||
|
@ -31,15 +31,13 @@
|
||||
#include "test/test.h"
|
||||
#include "test/log_test_helpers.h"
|
||||
|
||||
#define NS_MODULE rtr
|
||||
#define NS_SUBMODULE tests
|
||||
|
||||
NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
|
||||
static const routerinfo_t * rtr_tests_router_get_my_routerinfo(void);
|
||||
ATTR_UNUSED static int rtr_tests_router_get_my_routerinfo_called = 0;
|
||||
|
||||
static routerinfo_t* mock_routerinfo;
|
||||
|
||||
static const routerinfo_t*
|
||||
NS(router_get_my_routerinfo)(void)
|
||||
rtr_tests_router_get_my_routerinfo(void)
|
||||
{
|
||||
crypto_pk_t* ident_key;
|
||||
crypto_pk_t* tap_key;
|
||||
@ -89,7 +87,8 @@ test_router_dump_router_to_string_no_bridge_distribution_method(void *arg)
|
||||
char* found = NULL;
|
||||
(void)arg;
|
||||
|
||||
NS_MOCK(router_get_my_routerinfo);
|
||||
MOCK(router_get_my_routerinfo,
|
||||
rtr_tests_router_get_my_routerinfo);
|
||||
|
||||
options->ORPort_set = 1;
|
||||
options->BridgeRelay = 1;
|
||||
@ -123,7 +122,7 @@ test_router_dump_router_to_string_no_bridge_distribution_method(void *arg)
|
||||
tt_ptr_op(found, OP_NE, NULL);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
UNMOCK(router_get_my_routerinfo);
|
||||
|
||||
tor_free(desc);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -214,7 +214,7 @@ test_tortls_tor_tls_get_error(void *data)
|
||||
|
||||
done:
|
||||
UNMOCK(tor_tls_cert_matches_key);
|
||||
NS_UNMOCK(logv);
|
||||
UNMOCK(logv);
|
||||
crypto_pk_free(key1);
|
||||
crypto_pk_free(key2);
|
||||
tor_tls_free(tls);
|
||||
|
@ -46,8 +46,6 @@ ENABLE_GCC_WARNING("-Wredundant-decls")
|
||||
#include "test/log_test_helpers.h"
|
||||
#include "test/test_tortls.h"
|
||||
|
||||
#define NS_MODULE tortls
|
||||
|
||||
#ifndef HAVE_SSL_STATE
|
||||
#define OPENSSL_OPAQUE
|
||||
#endif
|
||||
@ -123,8 +121,6 @@ test_tortls_tor_tls_new(void *data)
|
||||
tor_tls_free_all();
|
||||
}
|
||||
|
||||
#define NS_MODULE tortls
|
||||
|
||||
static void
|
||||
library_init(void)
|
||||
{
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include "lib/crypt_ops/crypto_rand.h"
|
||||
#include "lib/encoding/binascii.h"
|
||||
|
||||
#define NS_MODULE util_format
|
||||
|
||||
static void
|
||||
test_util_format_unaligned_accessors(void *ignored)
|
||||
{
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "test/log_test_helpers.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#define NS_MODULE util_process
|
||||
|
||||
static void
|
||||
temp_callback(int r, void *s)
|
||||
|
Loading…
Reference in New Issue
Block a user