commit 23c77f79fd6e05b4eba83c5e1fced571bb2a362a Author: Nick Mathewson nickm@torproject.org Date: Thu Jan 9 10:26:10 2020 -0500
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 # --- src/test/test_accounting.c | 16 +- src/test/test_compat_libevent.c | 2 - src/test/test_dir.c | 63 +-- src/test/test_dir_handle_get.c | 70 +-- src/test/test_dns.c | 175 ++++---- src/test/test_options.c | 25 +- src/test/test_procmon.c | 2 - src/test/test_rendcache.c | 42 +- src/test/test_router.c | 13 +- src/test/test_routerset.c | 937 ++++++++++++++++++---------------------- src/test/test_status.c | 604 ++++++++++++++------------ src/test/test_tortls.c | 2 +- src/test/test_tortls_openssl.c | 4 - src/test/test_util_format.c | 2 - src/test/test_util_process.c | 1 - 15 files changed, 946 insertions(+), 1012 deletions(-)
diff --git a/src/test/test_accounting.c b/src/test/test_accounting.c index 58a1dbf81..7933df5e3 100644 --- a/src/test/test_accounting.c +++ b/src/test/test_accounting.c @@ -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 diff --git a/src/test/test_compat_libevent.c b/src/test/test_compat_libevent.c index 4e675c66f..5376e08fb 100644 --- a/src/test/test_compat_libevent.c +++ b/src/test/test_compat_libevent.c @@ -13,8 +13,6 @@
#include "test/log_test_helpers.h"
-#define NS_MODULE le - static void test_compat_libevent_logging_callback(void *ignored) { diff --git a/src/test/test_dir.c b/src/test/test_dir.c index 88a099695..a0f854cf7 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -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 diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c index 308675ba5..86e6edd44 100644 --- a/src/test/test_dir_handle_get.c +++ b/src/test/test_dir_handle_get.c @@ -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; diff --git a/src/test/test_dns.c b/src/test/test_dns.c index 6ca858224..443538326 100644 --- a/src/test/test_dns.c +++ b/src/test/test_dns.c @@ -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 diff --git a/src/test/test_options.c b/src/test/test_options.c index a363eca67..fb12821ae 100644 --- a/src/test/test_options.c +++ b/src/test/test_options.c @@ -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); } diff --git a/src/test/test_procmon.c b/src/test/test_procmon.c index 6893fe8b6..1752008f6 100644 --- a/src/test/test_procmon.c +++ b/src/test/test_procmon.c @@ -9,8 +9,6 @@
#include "test/log_test_helpers.h"
-#define NS_MODULE procmon - struct event_base;
static void diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c index 5771ca1d2..d0cb4378a 100644 --- a/src/test/test_rendcache.c +++ b/src/test/test_rendcache.c @@ -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) { diff --git a/src/test/test_router.c b/src/test/test_router.c index a1ea2967f..572ddceaa 100644 --- a/src/test/test_router.c +++ b/src/test/test_router.c @@ -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); } diff --git a/src/test/test_routerset.c b/src/test/test_routerset.c index c5a453d0a..a64f7c1d1 100644 --- a/src/test/test_routerset.c +++ b/src/test/test_routerset.c @@ -18,17 +18,13 @@
#include "test/test.h"
-#define NS_MODULE rset - -#define NS_SUBMODULE new - /* * Functional (blackbox) test to determine that each member of the routerset * is non-NULL */
static void -NS(test_main)(void *arg) +test_rset_new(void *arg) { routerset_t *rs; (void)arg; @@ -46,15 +42,12 @@ NS(test_main)(void *arg) routerset_free(rs); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE get_countryname - /* * Functional test to strip the braces from a "{xx}" country code string. */
static void -NS(test_main)(void *arg) +test_rset_get_countryname(void *arg) { const char *input; char *name; @@ -91,257 +84,264 @@ NS(test_main)(void *arg) tor_free(name); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(refresh, geoip_not_loaded) - /* * Structural (whitebox) test for routerset_refresh_counties, when the GeoIP DB * is not loaded. */
-NS_DECL(int, geoip_is_loaded, (sa_family_t family)); -NS_DECL(int, geoip_get_n_countries, (void)); +static int rset_refresh_geoip_not_loaded_geoip_is_loaded(sa_family_t family); +ATTR_UNUSED static int rset_refresh_geoip_not_loaded_geoip_is_loaded_called = 0; +static int rset_refresh_geoip_not_loaded_geoip_get_n_countries(void); +ATTR_UNUSED static int rset_refresh_geoip_not_loaded_geoip_get_n_countries_called = 0;
static void -NS(test_main)(void *arg) +test_rset_refresh_geoip_not_loaded(void *arg) { routerset_t *set = routerset_new(); (void)arg;
- NS_MOCK(geoip_is_loaded); - NS_MOCK(geoip_get_n_countries); + MOCK(geoip_is_loaded, + rset_refresh_geoip_not_loaded_geoip_is_loaded); + MOCK(geoip_get_n_countries, + rset_refresh_geoip_not_loaded_geoip_get_n_countries);
routerset_refresh_countries(set);
tt_ptr_op(set->countries, OP_EQ, NULL); tt_int_op(set->n_countries, OP_EQ, 0); - tt_int_op(CALLED(geoip_is_loaded), OP_EQ, 1); - tt_int_op(CALLED(geoip_get_n_countries), OP_EQ, 0); + tt_int_op(rset_refresh_geoip_not_loaded_geoip_is_loaded_called, OP_EQ, 1); + tt_int_op(rset_refresh_geoip_not_loaded_geoip_get_n_countries_called, OP_EQ, 0);
done: - NS_UNMOCK(geoip_is_loaded); - NS_UNMOCK(geoip_get_n_countries); + UNMOCK(geoip_is_loaded); + UNMOCK(geoip_get_n_countries); routerset_free(set); }
static int -NS(geoip_is_loaded)(sa_family_t family) +rset_refresh_geoip_not_loaded_geoip_is_loaded(sa_family_t family) { (void)family; - CALLED(geoip_is_loaded)++; + rset_refresh_geoip_not_loaded_geoip_is_loaded_called++;
return 0; }
static int -NS(geoip_get_n_countries)(void) +rset_refresh_geoip_not_loaded_geoip_get_n_countries(void) { - CALLED(geoip_get_n_countries)++; + rset_refresh_geoip_not_loaded_geoip_get_n_countries_called++;
return 0; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(refresh, no_countries) - /* * Structural test for routerset_refresh_counties, when there are no countries. */
-NS_DECL(int, geoip_is_loaded, (sa_family_t family)); -NS_DECL(int, geoip_get_n_countries, (void)); -NS_DECL(country_t, geoip_get_country, (const char *country)); +static int rset_refresh_no_countries_geoip_is_loaded(sa_family_t family); +ATTR_UNUSED static int rset_refresh_no_countries_geoip_is_loaded_called = 0; +static int rset_refresh_no_countries_geoip_get_n_countries(void); +ATTR_UNUSED static int rset_refresh_no_countries_geoip_get_n_countries_called = 0; +static country_t rset_refresh_no_countries_geoip_get_country(const char *country); +ATTR_UNUSED static int rset_refresh_no_countries_geoip_get_country_called = 0;
static void -NS(test_main)(void *arg) +test_rset_refresh_no_countries(void *arg) { routerset_t *set = routerset_new(); (void)arg;
- NS_MOCK(geoip_is_loaded); - NS_MOCK(geoip_get_n_countries); - NS_MOCK(geoip_get_country); + MOCK(geoip_is_loaded, + rset_refresh_no_countries_geoip_is_loaded); + MOCK(geoip_get_n_countries, + rset_refresh_no_countries_geoip_get_n_countries); + MOCK(geoip_get_country, + rset_refresh_no_countries_geoip_get_country);
routerset_refresh_countries(set);
tt_ptr_op(set->countries, OP_NE, NULL); tt_int_op(set->n_countries, OP_EQ, 1); tt_int_op((unsigned int)(*set->countries), OP_EQ, 0); - tt_int_op(CALLED(geoip_is_loaded), OP_EQ, 1); - tt_int_op(CALLED(geoip_get_n_countries), OP_EQ, 1); - tt_int_op(CALLED(geoip_get_country), OP_EQ, 0); + tt_int_op(rset_refresh_no_countries_geoip_is_loaded_called, OP_EQ, 1); + tt_int_op(rset_refresh_no_countries_geoip_get_n_countries_called, OP_EQ, 1); + tt_int_op(rset_refresh_no_countries_geoip_get_country_called, OP_EQ, 0);
done: - NS_UNMOCK(geoip_is_loaded); - NS_UNMOCK(geoip_get_n_countries); - NS_UNMOCK(geoip_get_country); + UNMOCK(geoip_is_loaded); + UNMOCK(geoip_get_n_countries); + UNMOCK(geoip_get_country); routerset_free(set); }
static int -NS(geoip_is_loaded)(sa_family_t family) +rset_refresh_no_countries_geoip_is_loaded(sa_family_t family) { (void)family; - CALLED(geoip_is_loaded)++; + rset_refresh_no_countries_geoip_is_loaded_called++;
return 1; }
static int -NS(geoip_get_n_countries)(void) +rset_refresh_no_countries_geoip_get_n_countries(void) { - CALLED(geoip_get_n_countries)++; + rset_refresh_no_countries_geoip_get_n_countries_called++;
return 1; }
static country_t -NS(geoip_get_country)(const char *countrycode) +rset_refresh_no_countries_geoip_get_country(const char *countrycode) { (void)countrycode; - CALLED(geoip_get_country)++; + rset_refresh_no_countries_geoip_get_country_called++;
return 1; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(refresh, one_valid_country) - /* * Structural test for routerset_refresh_counties, with one valid country. */
-NS_DECL(int, geoip_is_loaded, (sa_family_t family)); -NS_DECL(int, geoip_get_n_countries, (void)); -NS_DECL(country_t, geoip_get_country, (const char *country)); +static int rset_refresh_one_valid_country_geoip_is_loaded(sa_family_t family); +ATTR_UNUSED static int rset_refresh_one_valid_country_geoip_is_loaded_called = 0; +static int rset_refresh_one_valid_country_geoip_get_n_countries(void); +ATTR_UNUSED static int rset_refresh_one_valid_country_geoip_get_n_countries_called = 0; +static country_t rset_refresh_one_valid_country_geoip_get_country(const char *country); +ATTR_UNUSED static int rset_refresh_one_valid_country_geoip_get_country_called = 0;
static void -NS(test_main)(void *arg) +test_rset_refresh_one_valid_country(void *arg) { routerset_t *set = routerset_new(); (void)arg;
- NS_MOCK(geoip_is_loaded); - NS_MOCK(geoip_get_n_countries); - NS_MOCK(geoip_get_country); + MOCK(geoip_is_loaded, + rset_refresh_one_valid_country_geoip_is_loaded); + MOCK(geoip_get_n_countries, + rset_refresh_one_valid_country_geoip_get_n_countries); + MOCK(geoip_get_country, + rset_refresh_one_valid_country_geoip_get_country); smartlist_add(set->country_names, tor_strndup("foo", 3));
routerset_refresh_countries(set);
tt_ptr_op(set->countries, OP_NE, NULL); tt_int_op(set->n_countries, OP_EQ, 2); - tt_int_op(CALLED(geoip_is_loaded), OP_EQ, 1); - tt_int_op(CALLED(geoip_get_n_countries), OP_EQ, 1); - tt_int_op(CALLED(geoip_get_country), OP_EQ, 1); + tt_int_op(rset_refresh_one_valid_country_geoip_is_loaded_called, OP_EQ, 1); + tt_int_op(rset_refresh_one_valid_country_geoip_get_n_countries_called, OP_EQ, 1); + tt_int_op(rset_refresh_one_valid_country_geoip_get_country_called, OP_EQ, 1); tt_int_op((unsigned int)(*set->countries), OP_NE, 0);
done: - NS_UNMOCK(geoip_is_loaded); - NS_UNMOCK(geoip_get_n_countries); - NS_UNMOCK(geoip_get_country); + UNMOCK(geoip_is_loaded); + UNMOCK(geoip_get_n_countries); + UNMOCK(geoip_get_country); routerset_free(set); }
static int -NS(geoip_is_loaded)(sa_family_t family) +rset_refresh_one_valid_country_geoip_is_loaded(sa_family_t family) { (void)family; - CALLED(geoip_is_loaded)++; + rset_refresh_one_valid_country_geoip_is_loaded_called++;
return 1; }
static int -NS(geoip_get_n_countries)(void) +rset_refresh_one_valid_country_geoip_get_n_countries(void) { - CALLED(geoip_get_n_countries)++; + rset_refresh_one_valid_country_geoip_get_n_countries_called++;
return 2; }
static country_t -NS(geoip_get_country)(const char *countrycode) +rset_refresh_one_valid_country_geoip_get_country(const char *countrycode) { (void)countrycode; - CALLED(geoip_get_country)++; + rset_refresh_one_valid_country_geoip_get_country_called++;
return 1; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(refresh, one_invalid_country) - /* * Structural test for routerset_refresh_counties, with one invalid * country code.. */
-NS_DECL(int, geoip_is_loaded, (sa_family_t family)); -NS_DECL(int, geoip_get_n_countries, (void)); -NS_DECL(country_t, geoip_get_country, (const char *country)); +static int rset_refresh_one_invalid_country_geoip_is_loaded(sa_family_t family); +ATTR_UNUSED static int rset_refresh_one_invalid_country_geoip_is_loaded_called = 0; +static int rset_refresh_one_invalid_country_geoip_get_n_countries(void); +ATTR_UNUSED static int rset_refresh_one_invalid_country_geoip_get_n_countries_called = 0; +static country_t rset_refresh_one_invalid_country_geoip_get_country(const char *country); +ATTR_UNUSED static int rset_refresh_one_invalid_country_geoip_get_country_called = 0;
static void -NS(test_main)(void *arg) +test_rset_refresh_one_invalid_country(void *arg) { routerset_t *set = routerset_new(); (void)arg;
- NS_MOCK(geoip_is_loaded); - NS_MOCK(geoip_get_n_countries); - NS_MOCK(geoip_get_country); + MOCK(geoip_is_loaded, + rset_refresh_one_invalid_country_geoip_is_loaded); + MOCK(geoip_get_n_countries, + rset_refresh_one_invalid_country_geoip_get_n_countries); + MOCK(geoip_get_country, + rset_refresh_one_invalid_country_geoip_get_country); smartlist_add(set->country_names, tor_strndup("foo", 3));
routerset_refresh_countries(set);
tt_ptr_op(set->countries, OP_NE, NULL); tt_int_op(set->n_countries, OP_EQ, 2); - tt_int_op(CALLED(geoip_is_loaded), OP_EQ, 1); - tt_int_op(CALLED(geoip_get_n_countries), OP_EQ, 1); - tt_int_op(CALLED(geoip_get_country), OP_EQ, 1); + tt_int_op(rset_refresh_one_invalid_country_geoip_is_loaded_called, OP_EQ, 1); + tt_int_op(rset_refresh_one_invalid_country_geoip_get_n_countries_called, OP_EQ, 1); + tt_int_op(rset_refresh_one_invalid_country_geoip_get_country_called, OP_EQ, 1); tt_int_op((unsigned int)(*set->countries), OP_EQ, 0);
done: - NS_UNMOCK(geoip_is_loaded); - NS_UNMOCK(geoip_get_n_countries); - NS_UNMOCK(geoip_get_country); + UNMOCK(geoip_is_loaded); + UNMOCK(geoip_get_n_countries); + UNMOCK(geoip_get_country); routerset_free(set); }
static int -NS(geoip_is_loaded)(sa_family_t family) +rset_refresh_one_invalid_country_geoip_is_loaded(sa_family_t family) { (void)family; - CALLED(geoip_is_loaded)++; + rset_refresh_one_invalid_country_geoip_is_loaded_called++;
return 1; }
static int -NS(geoip_get_n_countries)(void) +rset_refresh_one_invalid_country_geoip_get_n_countries(void) { - CALLED(geoip_get_n_countries)++; + rset_refresh_one_invalid_country_geoip_get_n_countries_called++;
return 2; }
static country_t -NS(geoip_get_country)(const char *countrycode) +rset_refresh_one_invalid_country_geoip_get_country(const char *countrycode) { (void)countrycode; - CALLED(geoip_get_country)++; + rset_refresh_one_invalid_country_geoip_get_country_called++;
return -1; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(parse, malformed) - /* * Functional test, with a malformed string to parse. */
static void -NS(test_main)(void *arg) +test_rset_parse_malformed(void *arg) { routerset_t *set = routerset_new(); const char *s = "_"; @@ -356,16 +356,13 @@ NS(test_main)(void *arg) routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(parse, valid_hexdigest) - /* * Functional test for routerset_parse, that routerset_parse returns 0 * on a valid hexdigest entry. */
static void -NS(test_main)(void *arg) +test_rset_parse_valid_hexdigest(void *arg) { routerset_t *set; const char *s; @@ -382,15 +379,12 @@ NS(test_main)(void *arg) routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(parse, valid_nickname) - /* * Functional test for routerset_parse, when given a valid nickname as input. */
static void -NS(test_main)(void *arg) +test_rset_parse_valid_nickname(void *arg) { routerset_t *set; const char *s; @@ -407,15 +401,12 @@ NS(test_main)(void *arg) routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(parse, get_countryname) - /* * Functional test for routerset_parse, when given a valid countryname. */
static void -NS(test_main)(void *arg) +test_rset_parse_get_countryname(void *arg) { routerset_t *set; const char *s; @@ -432,155 +423,150 @@ NS(test_main)(void *arg) routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(parse, policy_wildcard) - /* * Structural test for routerset_parse, when given a valid wildcard policy. */
-NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string, (const char *s, int assume_action, int *malformed_list)); +static addr_policy_t * rset_parse_policy_wildcard_router_parse_addr_policy_item_from_string(const char *s, int assume_action, int *malformed_list); +ATTR_UNUSED static int rset_parse_policy_wildcard_router_parse_addr_policy_item_from_string_called = 0;
-static addr_policy_t *NS(mock_addr_policy); +static addr_policy_t *rset_parse_policy_wildcard_mock_addr_policy;
static void -NS(test_main)(void *arg) +test_rset_parse_policy_wildcard(void *arg) { routerset_t *set; const char *s; int r; (void)arg;
- NS_MOCK(router_parse_addr_policy_item_from_string); - NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t)); + MOCK(router_parse_addr_policy_item_from_string, + rset_parse_policy_wildcard_router_parse_addr_policy_item_from_string); + rset_parse_policy_wildcard_mock_addr_policy = tor_malloc_zero(sizeof(addr_policy_t));
set = routerset_new(); s = "*"; r = routerset_parse(set, s, ""); tt_int_op(r, OP_EQ, 0); tt_int_op(smartlist_len(set->policies), OP_NE, 0); - tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1); + tt_int_op(rset_parse_policy_wildcard_router_parse_addr_policy_item_from_string_called, OP_EQ, 1);
done: routerset_free(set); }
addr_policy_t * -NS(router_parse_addr_policy_item_from_string)(const char *s, +rset_parse_policy_wildcard_router_parse_addr_policy_item_from_string(const char *s, int assume_action, int *malformed_list) { (void)s; (void)assume_action; (void)malformed_list; - CALLED(router_parse_addr_policy_item_from_string)++; + rset_parse_policy_wildcard_router_parse_addr_policy_item_from_string_called++;
- return NS(mock_addr_policy); + return rset_parse_policy_wildcard_mock_addr_policy; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(parse, policy_ipv4) - /* * Structural test for routerset_parse, when given a valid IPv4 address * literal policy. */
-NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string, (const char *s, int assume_action, int *bogus)); +static addr_policy_t * rset_parse_policy_ipv4_router_parse_addr_policy_item_from_string(const char *s, int assume_action, int *bogus); +ATTR_UNUSED static int rset_parse_policy_ipv4_router_parse_addr_policy_item_from_string_called = 0;
-static addr_policy_t *NS(mock_addr_policy); +static addr_policy_t *rset_parse_policy_ipv4_mock_addr_policy;
static void -NS(test_main)(void *arg) +test_rset_parse_policy_ipv4(void *arg) { routerset_t *set; const char *s; int r; (void)arg;
- NS_MOCK(router_parse_addr_policy_item_from_string); - NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t)); + MOCK(router_parse_addr_policy_item_from_string, + rset_parse_policy_ipv4_router_parse_addr_policy_item_from_string); + rset_parse_policy_ipv4_mock_addr_policy = tor_malloc_zero(sizeof(addr_policy_t));
set = routerset_new(); s = "127.0.0.1"; r = routerset_parse(set, s, ""); tt_int_op(r, OP_EQ, 0); tt_int_op(smartlist_len(set->policies), OP_NE, 0); - tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1); + tt_int_op(rset_parse_policy_ipv4_router_parse_addr_policy_item_from_string_called, OP_EQ, 1);
done: routerset_free(set); }
addr_policy_t * -NS(router_parse_addr_policy_item_from_string)(const char *s, int assume_action, +rset_parse_policy_ipv4_router_parse_addr_policy_item_from_string(const char *s, int assume_action, int *bogus) { (void)s; (void)assume_action; - CALLED(router_parse_addr_policy_item_from_string)++; + rset_parse_policy_ipv4_router_parse_addr_policy_item_from_string_called++; *bogus = 0;
- return NS(mock_addr_policy); + return rset_parse_policy_ipv4_mock_addr_policy; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(parse, policy_ipv6) - /* * Structural test for routerset_parse, when given a valid IPv6 address * literal policy. */
-NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string, (const char *s, int assume_action, int *bad)); +static addr_policy_t * rset_parse_policy_ipv6_router_parse_addr_policy_item_from_string(const char *s, int assume_action, int *bad); +ATTR_UNUSED static int rset_parse_policy_ipv6_router_parse_addr_policy_item_from_string_called = 0;
-static addr_policy_t *NS(mock_addr_policy); +static addr_policy_t *rset_parse_policy_ipv6_mock_addr_policy;
static void -NS(test_main)(void *arg) +test_rset_parse_policy_ipv6(void *arg) { routerset_t *set; const char *s; int r; (void)arg;
- NS_MOCK(router_parse_addr_policy_item_from_string); - NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t)); + MOCK(router_parse_addr_policy_item_from_string, + rset_parse_policy_ipv6_router_parse_addr_policy_item_from_string); + rset_parse_policy_ipv6_mock_addr_policy = tor_malloc_zero(sizeof(addr_policy_t));
set = routerset_new(); s = "::1"; r = routerset_parse(set, s, ""); tt_int_op(r, OP_EQ, 0); tt_int_op(smartlist_len(set->policies), OP_NE, 0); - tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1); + tt_int_op(rset_parse_policy_ipv6_router_parse_addr_policy_item_from_string_called, OP_EQ, 1);
done: routerset_free(set); }
addr_policy_t * -NS(router_parse_addr_policy_item_from_string)(const char *s, +rset_parse_policy_ipv6_router_parse_addr_policy_item_from_string(const char *s, int assume_action, int *bad) { (void)s; (void)assume_action; - CALLED(router_parse_addr_policy_item_from_string)++; + rset_parse_policy_ipv6_router_parse_addr_policy_item_from_string_called++; *bad = 0;
- return NS(mock_addr_policy); + return rset_parse_policy_ipv6_mock_addr_policy; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(union, source_bad) - /* * Structural test for routerset_union, when given a bad source argument. */
-NS_DECL(smartlist_t *, smartlist_new, (void)); +static smartlist_t * rset_union_source_bad_smartlist_new(void); +ATTR_UNUSED static int rset_union_source_bad_smartlist_new_called = 0;
static void -NS(test_main)(void *arg) +test_rset_union_source_bad(void *arg) { routerset_t *set, *bad_set; (void)arg; @@ -590,16 +576,17 @@ NS(test_main)(void *arg) smartlist_free(bad_set->list); bad_set->list = NULL;
- NS_MOCK(smartlist_new); + MOCK(smartlist_new, + rset_union_source_bad_smartlist_new);
routerset_union(set, NULL); - tt_int_op(CALLED(smartlist_new), OP_EQ, 0); + tt_int_op(rset_union_source_bad_smartlist_new_called, OP_EQ, 0);
routerset_union(set, bad_set); - tt_int_op(CALLED(smartlist_new), OP_EQ, 0); + tt_int_op(rset_union_source_bad_smartlist_new_called, OP_EQ, 0);
done: - NS_UNMOCK(smartlist_new); + UNMOCK(smartlist_new); routerset_free(set);
/* Just recreate list, so we can simply use routerset_free. */ @@ -608,22 +595,19 @@ NS(test_main)(void *arg) }
static smartlist_t * -NS(smartlist_new)(void) +rset_union_source_bad_smartlist_new(void) { - CALLED(smartlist_new)++; + rset_union_source_bad_smartlist_new_called++;
return NULL; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(union, one) - /* * Functional test for routerset_union. */
static void -NS(test_main)(void *arg) +test_rset_union_one(void *arg) { routerset_t *src = routerset_new(); routerset_t *tgt; @@ -640,15 +624,12 @@ NS(test_main)(void *arg) routerset_free(tgt); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE is_list - /* * Functional tests for routerset_is_list. */
static void -NS(test_main)(void *arg) +test_rset_is_list(void *arg) { routerset_t *set; addr_policy_t *policy; @@ -693,15 +674,12 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE needs_geoip - /* * Functional tests for routerset_needs_geoip. */
static void -NS(test_main)(void *arg) +test_rset_needs_geoip(void *arg) { routerset_t *set; int needs_geoip; @@ -728,15 +706,12 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE is_empty - /* * Functional tests for routerset_is_empty. */
static void -NS(test_main)(void *arg) +test_rset_is_empty(void *arg) { routerset_t *set = NULL; int is_empty; @@ -762,16 +737,13 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, null_set_or_list) - /* * Functional test for routerset_contains, when given a NULL set or the * set has a NULL list. */
static void -NS(test_main)(void *arg) +test_rset_contains_null_set_or_list(void *arg) { routerset_t *set = NULL; int contains; @@ -791,16 +763,13 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, null_nickname) - /* * Functional test for routerset_contains, when given a valid routerset but a * NULL nickname. */
static void -NS(test_main)(void *arg) +test_rset_contains_null_nickname(void *arg) { routerset_t *set = routerset_new(); char *nickname = NULL; @@ -816,16 +785,13 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, nickname) - /* * Functional test for routerset_contains, when given a valid routerset * and the nickname is in the routerset. */
static void -NS(test_main)(void *arg) +test_rset_contains_nickname(void *arg) { routerset_t *set = routerset_new(); const char *nickname; @@ -842,16 +808,13 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, no_nickname) - /* * Functional test for routerset_contains, when given a valid routerset * and the nickname is not in the routerset. */
static void -NS(test_main)(void *arg) +test_rset_contains_no_nickname(void *arg) { routerset_t *set = routerset_new(); int contains; @@ -866,16 +829,13 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, digest) - /* * Functional test for routerset_contains, when given a valid routerset * and the digest is contained in the routerset. */
static void -NS(test_main)(void *arg) +test_rset_contains_digest(void *arg) { routerset_t *set = routerset_new(); int contains; @@ -891,16 +851,13 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, no_digest) - /* * Functional test for routerset_contains, when given a valid routerset * and the digest is not contained in the routerset. */
static void -NS(test_main)(void *arg) +test_rset_contains_no_digest(void *arg) { routerset_t *set = routerset_new(); int contains; @@ -917,16 +874,13 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, null_digest) - /* * Functional test for routerset_contains, when given a valid routerset * and the digest is NULL. */
static void -NS(test_main)(void *arg) +test_rset_contains_null_digest(void *arg) { routerset_t *set = routerset_new(); int contains; @@ -942,33 +896,32 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, addr) - /* * Structural test for routerset_contains, when given a valid routerset * and the address is rejected by policy. */
-NS_DECL(addr_policy_result_t, compare_tor_addr_to_addr_policy, (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy)); +static addr_policy_result_t rset_contains_addr_compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy); +ATTR_UNUSED static int rset_contains_addr_compare_tor_addr_to_addr_policy_called = 0;
static tor_addr_t MOCK_TOR_ADDR; #define MOCK_TOR_ADDR_PTR (&MOCK_TOR_ADDR)
static void -NS(test_main)(void *arg) +test_rset_contains_addr(void *arg) { routerset_t *set = routerset_new(); tor_addr_t *addr = MOCK_TOR_ADDR_PTR; int contains; (void)arg;
- NS_MOCK(compare_tor_addr_to_addr_policy); + MOCK(compare_tor_addr_to_addr_policy, + rset_contains_addr_compare_tor_addr_to_addr_policy);
contains = routerset_contains(set, addr, 0, NULL, NULL, 0); routerset_free(set);
- tt_int_op(CALLED(compare_tor_addr_to_addr_policy), OP_EQ, 1); + tt_int_op(rset_contains_addr_compare_tor_addr_to_addr_policy_called, OP_EQ, 1); tt_int_op(contains, OP_EQ, 3);
done: @@ -976,12 +929,12 @@ NS(test_main)(void *arg) }
addr_policy_result_t -NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port, +rset_contains_addr_compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy) { (void)port; (void)policy; - CALLED(compare_tor_addr_to_addr_policy)++; + rset_contains_addr_compare_tor_addr_to_addr_policy_called++; tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR); return ADDR_POLICY_REJECTED;
@@ -989,30 +942,29 @@ NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port, return 0; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, no_addr) - /* * Structural test for routerset_contains, when given a valid routerset * and the address is not rejected by policy. */
-NS_DECL(addr_policy_result_t, compare_tor_addr_to_addr_policy, (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy)); +static addr_policy_result_t rset_contains_no_addr_compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy); +ATTR_UNUSED static int rset_contains_no_addr_compare_tor_addr_to_addr_policy_called = 0;
static void -NS(test_main)(void *arg) +test_rset_contains_no_addr(void *arg) { routerset_t *set = routerset_new(); tor_addr_t *addr = MOCK_TOR_ADDR_PTR; int contains; (void)arg;
- NS_MOCK(compare_tor_addr_to_addr_policy); + MOCK(compare_tor_addr_to_addr_policy, + rset_contains_no_addr_compare_tor_addr_to_addr_policy);
contains = routerset_contains(set, addr, 0, NULL, NULL, 0); routerset_free(set);
- tt_int_op(CALLED(compare_tor_addr_to_addr_policy), OP_EQ, 1); + tt_int_op(rset_contains_no_addr_compare_tor_addr_to_addr_policy_called, OP_EQ, 1); tt_int_op(contains, OP_EQ, 0);
done: @@ -1020,12 +972,12 @@ NS(test_main)(void *arg) }
addr_policy_result_t -NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port, +rset_contains_no_addr_compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy) { (void)port; (void)policy; - CALLED(compare_tor_addr_to_addr_policy)++; + rset_contains_no_addr_compare_tor_addr_to_addr_policy_called++; tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
return ADDR_POLICY_ACCEPTED; @@ -1034,24 +986,23 @@ NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port, return 0; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, null_addr) - /* * Structural test for routerset_contains, when given a valid routerset * and the address is NULL. */
-NS_DECL(addr_policy_result_t, compare_tor_addr_to_addr_policy, (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy)); +static addr_policy_result_t rset_contains_null_addr_compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy); +ATTR_UNUSED static int rset_contains_null_addr_compare_tor_addr_to_addr_policy_called = 0;
static void -NS(test_main)(void *arg) +test_rset_contains_null_addr(void *arg) { routerset_t *set = routerset_new(); int contains; (void)arg;
- NS_MOCK(compare_tor_addr_to_addr_policy); + MOCK(compare_tor_addr_to_addr_policy, + rset_contains_null_addr_compare_tor_addr_to_addr_policy);
contains = routerset_contains(set, NULL, 0, NULL, NULL, 0); routerset_free(set); @@ -1063,12 +1014,12 @@ NS(test_main)(void *arg) }
addr_policy_result_t -NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port, +rset_contains_null_addr_compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy) { (void)port; (void)policy; - CALLED(compare_tor_addr_to_addr_policy)++; + rset_contains_null_addr_compare_tor_addr_to_addr_policy_called++; tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
return ADDR_POLICY_ACCEPTED; @@ -1077,26 +1028,27 @@ NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port, return 0; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, countries_no_geoip) - /* * Structural test for routerset_contains, when there is no matching country * for the address. */
-NS_DECL(addr_policy_result_t, compare_tor_addr_to_addr_policy, (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy)); -NS_DECL(int, geoip_get_country_by_addr, (const tor_addr_t *addr)); +static addr_policy_result_t rset_contains_countries_no_geoip_compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy); +ATTR_UNUSED static int rset_contains_countries_no_geoip_compare_tor_addr_to_addr_policy_called = 0; +static int rset_contains_countries_no_geoip_geoip_get_country_by_addr(const tor_addr_t *addr); +ATTR_UNUSED static int rset_contains_countries_no_geoip_geoip_get_country_by_addr_called = 0;
static void -NS(test_main)(void *arg) +test_rset_contains_countries_no_geoip(void *arg) { routerset_t *set = routerset_new(); int contains = 1; (void)arg;
- NS_MOCK(compare_tor_addr_to_addr_policy); - NS_MOCK(geoip_get_country_by_addr); + MOCK(compare_tor_addr_to_addr_policy, + rset_contains_countries_no_geoip_compare_tor_addr_to_addr_policy); + MOCK(geoip_get_country_by_addr, + rset_contains_countries_no_geoip_geoip_get_country_by_addr);
set->countries = bitarray_init_zero(1); bitarray_set(set->countries, 1); @@ -1104,20 +1056,20 @@ NS(test_main)(void *arg) routerset_free(set);
tt_int_op(contains, OP_EQ, 0); - tt_int_op(CALLED(compare_tor_addr_to_addr_policy), OP_EQ, 1); - tt_int_op(CALLED(geoip_get_country_by_addr), OP_EQ, 1); + tt_int_op(rset_contains_countries_no_geoip_compare_tor_addr_to_addr_policy_called, OP_EQ, 1); + tt_int_op(rset_contains_countries_no_geoip_geoip_get_country_by_addr_called, OP_EQ, 1);
done: ; }
addr_policy_result_t -NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port, +rset_contains_countries_no_geoip_compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy) { (void)port; (void)policy; - CALLED(compare_tor_addr_to_addr_policy)++; + rset_contains_countries_no_geoip_compare_tor_addr_to_addr_policy_called++; tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
done: @@ -1125,35 +1077,36 @@ NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port, }
int -NS(geoip_get_country_by_addr)(const tor_addr_t *addr) +rset_contains_countries_no_geoip_geoip_get_country_by_addr(const tor_addr_t *addr) { - CALLED(geoip_get_country_by_addr)++; + rset_contains_countries_no_geoip_geoip_get_country_by_addr_called++; tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
done: return -1; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, countries_geoip) - /* * Structural test for routerset_contains, when there a matching country * for the address. */
-NS_DECL(addr_policy_result_t, compare_tor_addr_to_addr_policy, (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy)); -NS_DECL(int, geoip_get_country_by_addr, (const tor_addr_t *addr)); +static addr_policy_result_t rset_contains_countries_geoip_compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy); +ATTR_UNUSED static int rset_contains_countries_geoip_compare_tor_addr_to_addr_policy_called = 0; +static int rset_contains_countries_geoip_geoip_get_country_by_addr(const tor_addr_t *addr); +ATTR_UNUSED static int rset_contains_countries_geoip_geoip_get_country_by_addr_called = 0;
static void -NS(test_main)(void *arg) +test_rset_contains_countries_geoip(void *arg) { routerset_t *set = routerset_new(); int contains = 1; (void)arg;
- NS_MOCK(compare_tor_addr_to_addr_policy); - NS_MOCK(geoip_get_country_by_addr); + MOCK(compare_tor_addr_to_addr_policy, + rset_contains_countries_geoip_compare_tor_addr_to_addr_policy); + MOCK(geoip_get_country_by_addr, + rset_contains_countries_geoip_geoip_get_country_by_addr);
set->n_countries = 2; set->countries = bitarray_init_zero(1); @@ -1162,20 +1115,20 @@ NS(test_main)(void *arg) routerset_free(set);
tt_int_op(contains, OP_EQ, 2); - tt_int_op(CALLED(compare_tor_addr_to_addr_policy), OP_EQ, 1); - tt_int_op(CALLED(geoip_get_country_by_addr), OP_EQ, 1); + tt_int_op(rset_contains_countries_geoip_compare_tor_addr_to_addr_policy_called, OP_EQ, 1); + tt_int_op(rset_contains_countries_geoip_geoip_get_country_by_addr_called, OP_EQ, 1);
done: ; }
addr_policy_result_t -NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port, +rset_contains_countries_geoip_compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy) { (void)port; (void)policy; - CALLED(compare_tor_addr_to_addr_policy)++; + rset_contains_countries_geoip_compare_tor_addr_to_addr_policy_called++; tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
done: @@ -1183,25 +1136,22 @@ NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port, }
int -NS(geoip_get_country_by_addr)(const tor_addr_t *addr) +rset_contains_countries_geoip_geoip_get_country_by_addr(const tor_addr_t *addr) { - CALLED(geoip_get_country_by_addr)++; + rset_contains_countries_geoip_geoip_get_country_by_addr_called++; tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
done: return 1; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(add_unknown_ccs, only_flag) - /* * Functional test for routerset_add_unknown_ccs, where only_if_some_cc_set * is set and there are no country names. */
static void -NS(test_main)(void *arg) +test_rset_add_unknown_ccs_only_flag(void *arg) { routerset_t *set = routerset_new(); routerset_t **setp = &set; @@ -1216,26 +1166,25 @@ NS(test_main)(void *arg) routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(add_unknown_ccs, creates_set) - /* * Functional test for routerset_add_unknown_ccs, where the set argument * is created if passed in as NULL. */
/* The mock is only used to stop the test from asserting erroneously. */ -NS_DECL(country_t, geoip_get_country, (const char *country)); +static country_t rset_add_unknown_ccs_creates_set_geoip_get_country(const char *country); +ATTR_UNUSED static int rset_add_unknown_ccs_creates_set_geoip_get_country_called = 0;
static void -NS(test_main)(void *arg) +test_rset_add_unknown_ccs_creates_set(void *arg) { routerset_t *set = NULL; routerset_t **setp = &set; int r; (void)arg;
- NS_MOCK(geoip_get_country); + MOCK(geoip_get_country, + rset_add_unknown_ccs_creates_set_geoip_get_country);
r = routerset_add_unknown_ccs(setp, 0);
@@ -1248,35 +1197,36 @@ NS(test_main)(void *arg) }
country_t -NS(geoip_get_country)(const char *country) +rset_add_unknown_ccs_creates_set_geoip_get_country(const char *country) { (void)country; - CALLED(geoip_get_country)++; + rset_add_unknown_ccs_creates_set_geoip_get_country_called++;
return -1; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(add_unknown_ccs, add_unknown) - /* * Structural test for routerset_add_unknown_ccs, that the "{??}" * country code is added to the list. */
-NS_DECL(country_t, geoip_get_country, (const char *country)); -NS_DECL(int, geoip_is_loaded, (sa_family_t family)); +static country_t rset_add_unknown_ccs_add_unknown_geoip_get_country(const char *country); +ATTR_UNUSED static int rset_add_unknown_ccs_add_unknown_geoip_get_country_called = 0; +static int rset_add_unknown_ccs_add_unknown_geoip_is_loaded(sa_family_t family); +ATTR_UNUSED static int rset_add_unknown_ccs_add_unknown_geoip_is_loaded_called = 0;
static void -NS(test_main)(void *arg) +test_rset_add_unknown_ccs_add_unknown(void *arg) { routerset_t *set = routerset_new(); routerset_t **setp = &set; int r; (void)arg;
- NS_MOCK(geoip_get_country); - NS_MOCK(geoip_is_loaded); + MOCK(geoip_get_country, + rset_add_unknown_ccs_add_unknown_geoip_get_country); + MOCK(geoip_is_loaded, + rset_add_unknown_ccs_add_unknown_geoip_is_loaded);
r = routerset_add_unknown_ccs(setp, 0);
@@ -1290,11 +1240,11 @@ NS(test_main)(void *arg) }
country_t -NS(geoip_get_country)(const char *country) +rset_add_unknown_ccs_add_unknown_geoip_get_country(const char *country) { int arg_is_qq, arg_is_a1;
- CALLED(geoip_get_country)++; + rset_add_unknown_ccs_add_unknown_geoip_get_country_called++;
arg_is_qq = !strcmp(country, "??"); arg_is_a1 = !strcmp(country, "A1"); @@ -1309,9 +1259,9 @@ NS(geoip_get_country)(const char *country) }
int -NS(geoip_is_loaded)(sa_family_t family) +rset_add_unknown_ccs_add_unknown_geoip_is_loaded(sa_family_t family) { - CALLED(geoip_is_loaded)++; + rset_add_unknown_ccs_add_unknown_geoip_is_loaded_called++;
tt_int_op(family, OP_EQ, AF_INET);
@@ -1319,27 +1269,28 @@ NS(geoip_is_loaded)(sa_family_t family) return 0; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(add_unknown_ccs, add_a1) - /* * Structural test for routerset_add_unknown_ccs, that the "{a1}" * country code is added to the list. */
-NS_DECL(country_t, geoip_get_country, (const char *country)); -NS_DECL(int, geoip_is_loaded, (sa_family_t family)); +static country_t rset_add_unknown_ccs_add_a1_geoip_get_country(const char *country); +ATTR_UNUSED static int rset_add_unknown_ccs_add_a1_geoip_get_country_called = 0; +static int rset_add_unknown_ccs_add_a1_geoip_is_loaded(sa_family_t family); +ATTR_UNUSED static int rset_add_unknown_ccs_add_a1_geoip_is_loaded_called = 0;
static void -NS(test_main)(void *arg) +test_rset_add_unknown_ccs_add_a1(void *arg) { routerset_t *set = routerset_new(); routerset_t **setp = &set; int r; (void)arg;
- NS_MOCK(geoip_get_country); - NS_MOCK(geoip_is_loaded); + MOCK(geoip_get_country, + rset_add_unknown_ccs_add_a1_geoip_get_country); + MOCK(geoip_is_loaded, + rset_add_unknown_ccs_add_a1_geoip_is_loaded);
r = routerset_add_unknown_ccs(setp, 0);
@@ -1353,11 +1304,11 @@ NS(test_main)(void *arg) }
country_t -NS(geoip_get_country)(const char *country) +rset_add_unknown_ccs_add_a1_geoip_get_country(const char *country) { int arg_is_qq, arg_is_a1;
- CALLED(geoip_get_country)++; + rset_add_unknown_ccs_add_a1_geoip_get_country_called++;
arg_is_qq = !strcmp(country, "??"); arg_is_a1 = !strcmp(country, "A1"); @@ -1372,9 +1323,9 @@ NS(geoip_get_country)(const char *country) }
int -NS(geoip_is_loaded)(sa_family_t family) +rset_add_unknown_ccs_add_a1_geoip_is_loaded(sa_family_t family) { - CALLED(geoip_is_loaded)++; + rset_add_unknown_ccs_add_a1_geoip_is_loaded_called++;
tt_int_op(family, OP_EQ, AF_INET);
@@ -1382,15 +1333,12 @@ NS(geoip_is_loaded)(sa_family_t family) return 0; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE contains_extendinfo - /* * Functional test for routerset_contains_extendinfo. */
static void -NS(test_main)(void *arg) +test_rset_contains_extendinfo(void *arg) { routerset_t *set = routerset_new(); extend_info_t ei; @@ -1410,15 +1358,12 @@ NS(test_main)(void *arg) routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE contains_router - /* * Functional test for routerset_contains_router. */
static void -NS(test_main)(void *arg) +test_rset_contains_router(void *arg) { routerset_t *set = routerset_new(); routerinfo_t ri; @@ -1438,9 +1383,6 @@ NS(test_main)(void *arg) routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE contains_routerstatus - /* * Functional test for routerset_contains_routerstatus. */ @@ -1450,7 +1392,7 @@ NS(test_main)(void *arg) // a bit more or test a bit more.
static void -NS(test_main)(void *arg) +test_rset_contains_routerstatus(void *arg) { routerset_t *set = routerset_new(); routerstatus_t rs; @@ -1471,46 +1413,40 @@ NS(test_main)(void *arg) routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, none) - /* * Functional test for routerset_contains_node, when the node has no * routerset or routerinfo. */
-static node_t NS(mock_node); +static node_t rset_contains_none_mock_node;
static void -NS(test_main)(void *arg) +test_rset_contains_none(void *arg) { routerset_t *set = routerset_new(); int r; (void)arg;
- memset(&NS(mock_node), 0, sizeof(NS(mock_node))); - NS(mock_node).ri = NULL; - NS(mock_node).rs = NULL; + memset(&rset_contains_none_mock_node, 0, sizeof(rset_contains_none_mock_node)); + rset_contains_none_mock_node.ri = NULL; + rset_contains_none_mock_node.rs = NULL;
- r = routerset_contains_node(set, &NS(mock_node)); + r = routerset_contains_node(set, &rset_contains_none_mock_node); tt_int_op(r, OP_EQ, 0);
done: routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, rs) - /* * Functional test for routerset_contains_node, when the node has a * routerset and no routerinfo. */
-static node_t NS(mock_node); +static node_t rset_contains_rs_mock_node;
static void -NS(test_main)(void *arg) +test_rset_contains_rs(void *arg) { routerset_t *set = routerset_new(); int r; @@ -1522,27 +1458,24 @@ NS(test_main)(void *arg)
strncpy(rs.nickname, nickname, sizeof(rs.nickname) - 1); rs.nickname[sizeof(rs.nickname) - 1] = '\0'; - memset(&NS(mock_node), 0, sizeof(NS(mock_node))); - NS(mock_node).ri = NULL; - NS(mock_node).rs = &rs; + memset(&rset_contains_rs_mock_node, 0, sizeof(rset_contains_rs_mock_node)); + rset_contains_rs_mock_node.ri = NULL; + rset_contains_rs_mock_node.rs = &rs;
- r = routerset_contains_node(set, &NS(mock_node)); + r = routerset_contains_node(set, &rset_contains_rs_mock_node);
tt_int_op(r, OP_EQ, 4); done: routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(contains, routerinfo) - /* * Functional test for routerset_contains_node, when the node has no * routerset and a routerinfo. */
static void -NS(test_main)(void *arg) +test_rset_contains_routerinfo(void *arg) { routerset_t *set = routerset_new(); int r; @@ -1565,16 +1498,13 @@ NS(test_main)(void *arg) routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(get_all, no_routerset) - /* * Functional test for routerset_get_all_nodes, when routerset is NULL or * the routerset list is NULL. */
static void -NS(test_main)(void *arg) +test_rset_get_all_no_routerset(void *arg) { smartlist_t *out = smartlist_new(); routerset_t *set = NULL; @@ -1598,29 +1528,28 @@ NS(test_main)(void *arg) smartlist_free(out); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(get_all, l_no_nodes) - /* * Structural test for routerset_get_all_nodes, when the routerset list * is empty. */
-NS_DECL(const node_t *, node_get_by_nickname, (const char *nickname, unsigned flags)); -static const char *NS(mock_nickname); +static const node_t * rset_get_all_l_no_nodes_node_get_by_nickname(const char *nickname, unsigned flags); +ATTR_UNUSED static int rset_get_all_l_no_nodes_node_get_by_nickname_called = 0; +static const char *rset_get_all_l_no_nodes_mock_nickname;
static void -NS(test_main)(void *arg) +test_rset_get_all_l_no_nodes(void *arg) { smartlist_t *out = smartlist_new(); routerset_t *set = routerset_new(); int out_len; (void)arg;
- NS_MOCK(node_get_by_nickname); + MOCK(node_get_by_nickname, + rset_get_all_l_no_nodes_node_get_by_nickname);
- NS(mock_nickname) = "foo"; - smartlist_add_strdup(set->list, NS(mock_nickname)); + rset_get_all_l_no_nodes_mock_nickname = "foo"; + smartlist_add_strdup(set->list, rset_get_all_l_no_nodes_mock_nickname);
routerset_get_all_nodes(out, set, NULL, 0); out_len = smartlist_len(out); @@ -1629,48 +1558,47 @@ NS(test_main)(void *arg) routerset_free(set);
tt_int_op(out_len, OP_EQ, 0); - tt_int_op(CALLED(node_get_by_nickname), OP_EQ, 1); + tt_int_op(rset_get_all_l_no_nodes_node_get_by_nickname_called, OP_EQ, 1);
done: ; }
const node_t * -NS(node_get_by_nickname)(const char *nickname, unsigned flags) +rset_get_all_l_no_nodes_node_get_by_nickname(const char *nickname, unsigned flags) { - CALLED(node_get_by_nickname)++; - tt_str_op(nickname, OP_EQ, NS(mock_nickname)); + rset_get_all_l_no_nodes_node_get_by_nickname_called++; + tt_str_op(nickname, OP_EQ, rset_get_all_l_no_nodes_mock_nickname); tt_uint_op(flags, OP_EQ, 0);
done: return NULL; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(get_all, l_not_running) - /* * Structural test for routerset_get_all_nodes, with the running_only flag * is set but the nodes are not running. */
-NS_DECL(const node_t *, node_get_by_nickname, (const char *nickname, unsigned flags)); -static const char *NS(mock_nickname); -static node_t NS(mock_node); +static const node_t * rset_get_all_l_not_running_node_get_by_nickname(const char *nickname, unsigned flags); +ATTR_UNUSED static int rset_get_all_l_not_running_node_get_by_nickname_called = 0; +static const char *rset_get_all_l_not_running_mock_nickname; +static node_t rset_get_all_l_not_running_mock_node;
static void -NS(test_main)(void *arg) +test_rset_get_all_l_not_running(void *arg) { smartlist_t *out = smartlist_new(); routerset_t *set = routerset_new(); int out_len; (void)arg;
- NS_MOCK(node_get_by_nickname); + MOCK(node_get_by_nickname, + rset_get_all_l_not_running_node_get_by_nickname);
- NS(mock_node).is_running = 0; - NS(mock_nickname) = "foo"; - smartlist_add_strdup(set->list, NS(mock_nickname)); + rset_get_all_l_not_running_mock_node.is_running = 0; + rset_get_all_l_not_running_mock_nickname = "foo"; + smartlist_add_strdup(set->list, rset_get_all_l_not_running_mock_nickname);
routerset_get_all_nodes(out, set, NULL, 1); out_len = smartlist_len(out); @@ -1679,36 +1607,34 @@ NS(test_main)(void *arg) routerset_free(set);
tt_int_op(out_len, OP_EQ, 0); - tt_int_op(CALLED(node_get_by_nickname), OP_EQ, 1); + tt_int_op(rset_get_all_l_not_running_node_get_by_nickname_called, OP_EQ, 1);
done: ; }
const node_t * -NS(node_get_by_nickname)(const char *nickname, unsigned flags) +rset_get_all_l_not_running_node_get_by_nickname(const char *nickname, unsigned flags) { - CALLED(node_get_by_nickname)++; - tt_str_op(nickname, OP_EQ, NS(mock_nickname)); + rset_get_all_l_not_running_node_get_by_nickname_called++; + tt_str_op(nickname, OP_EQ, rset_get_all_l_not_running_mock_nickname); tt_int_op(flags, OP_EQ, 0);
done: - return &NS(mock_node); + return &rset_get_all_l_not_running_mock_node; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(get_all, list) - /* * Structural test for routerset_get_all_nodes. */
-NS_DECL(const node_t *, node_get_by_nickname, (const char *nickname, unsigned flags)); -static char *NS(mock_nickname); -static node_t NS(mock_node); +static const node_t * rset_get_all_list_node_get_by_nickname(const char *nickname, unsigned flags); +ATTR_UNUSED static int rset_get_all_list_node_get_by_nickname_called = 0; +static char *rset_get_all_list_mock_nickname; +static node_t rset_get_all_list_mock_node;
static void -NS(test_main)(void *arg) +test_rset_get_all_list(void *arg) { smartlist_t *out = smartlist_new(); routerset_t *set = routerset_new(); @@ -1716,10 +1642,11 @@ NS(test_main)(void *arg) node_t *ent; (void)arg;
- NS_MOCK(node_get_by_nickname); + MOCK(node_get_by_nickname, + rset_get_all_list_node_get_by_nickname);
- NS(mock_nickname) = tor_strdup("foo"); - smartlist_add(set->list, NS(mock_nickname)); + rset_get_all_list_mock_nickname = tor_strdup("foo"); + smartlist_add(set->list, rset_get_all_list_mock_nickname);
routerset_get_all_nodes(out, set, NULL, 0); out_len = smartlist_len(out); @@ -1729,126 +1656,121 @@ NS(test_main)(void *arg) routerset_free(set);
tt_int_op(out_len, OP_EQ, 1); - tt_ptr_op(ent, OP_EQ, &NS(mock_node)); - tt_int_op(CALLED(node_get_by_nickname), OP_EQ, 1); + tt_ptr_op(ent, OP_EQ, &rset_get_all_list_mock_node); + tt_int_op(rset_get_all_list_node_get_by_nickname_called, OP_EQ, 1);
done: ; }
const node_t * -NS(node_get_by_nickname)(const char *nickname, unsigned flags) +rset_get_all_list_node_get_by_nickname(const char *nickname, unsigned flags) { - CALLED(node_get_by_nickname)++; - tt_str_op(nickname, OP_EQ, NS(mock_nickname)); + rset_get_all_list_node_get_by_nickname_called++; + tt_str_op(nickname, OP_EQ, rset_get_all_list_mock_nickname); tt_int_op(flags, OP_EQ, 0);
done: - return &NS(mock_node); + return &rset_get_all_list_mock_node; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(get_all, n_no_nodes) - /* * Structural test for routerset_get_all_nodes, when the nodelist has no nodes. */
-NS_DECL(const smartlist_t *, nodelist_get_list, (void)); +static const smartlist_t * rset_get_all_n_no_nodes_nodelist_get_list(void); +ATTR_UNUSED static int rset_get_all_n_no_nodes_nodelist_get_list_called = 0;
-static smartlist_t *NS(mock_smartlist); +static smartlist_t *rset_get_all_n_no_nodes_mock_smartlist; static void -NS(test_main)(void *arg) +test_rset_get_all_n_no_nodes(void *arg) { routerset_t *set = routerset_new(); smartlist_t *out = smartlist_new(); int r; (void)arg;
- NS_MOCK(nodelist_get_list); + MOCK(nodelist_get_list, + rset_get_all_n_no_nodes_nodelist_get_list);
smartlist_add_strdup(set->country_names, "{xx}"); - NS(mock_smartlist) = smartlist_new(); + rset_get_all_n_no_nodes_mock_smartlist = smartlist_new();
routerset_get_all_nodes(out, set, NULL, 1); r = smartlist_len(out); routerset_free(set); smartlist_free(out); - smartlist_free(NS(mock_smartlist)); + smartlist_free(rset_get_all_n_no_nodes_mock_smartlist);
tt_int_op(r, OP_EQ, 0); - tt_int_op(CALLED(nodelist_get_list), OP_EQ, 1); + tt_int_op(rset_get_all_n_no_nodes_nodelist_get_list_called, OP_EQ, 1);
done: ; }
const smartlist_t * -NS(nodelist_get_list)(void) +rset_get_all_n_no_nodes_nodelist_get_list(void) { - CALLED(nodelist_get_list)++; + rset_get_all_n_no_nodes_nodelist_get_list_called++;
- return NS(mock_smartlist); + return rset_get_all_n_no_nodes_mock_smartlist; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(get_all, n_not_running) - /* * Structural test for routerset_get_all_nodes, with a non-list routerset * the running_only flag is set, but the nodes are not running. */
-NS_DECL(const smartlist_t *, nodelist_get_list, (void)); +static const smartlist_t * rset_get_all_n_not_running_nodelist_get_list(void); +ATTR_UNUSED static int rset_get_all_n_not_running_nodelist_get_list_called = 0;
-static smartlist_t *NS(mock_smartlist); -static node_t NS(mock_node); +static smartlist_t *rset_get_all_n_not_running_mock_smartlist; +static node_t rset_get_all_n_not_running_mock_node;
static void -NS(test_main)(void *arg) +test_rset_get_all_n_not_running(void *arg) { routerset_t *set = routerset_new(); smartlist_t *out = smartlist_new(); int r; (void)arg;
- NS_MOCK(nodelist_get_list); + MOCK(nodelist_get_list, + rset_get_all_n_not_running_nodelist_get_list);
smartlist_add_strdup(set->country_names, "{xx}"); - NS(mock_smartlist) = smartlist_new(); - NS(mock_node).is_running = 0; - smartlist_add(NS(mock_smartlist), (void *)&NS(mock_node)); + rset_get_all_n_not_running_mock_smartlist = smartlist_new(); + rset_get_all_n_not_running_mock_node.is_running = 0; + smartlist_add(rset_get_all_n_not_running_mock_smartlist, (void *)&rset_get_all_n_not_running_mock_node);
routerset_get_all_nodes(out, set, NULL, 1); r = smartlist_len(out); routerset_free(set); smartlist_free(out); - smartlist_free(NS(mock_smartlist)); + smartlist_free(rset_get_all_n_not_running_mock_smartlist);
tt_int_op(r, OP_EQ, 0); - tt_int_op(CALLED(nodelist_get_list), OP_EQ, 1); + tt_int_op(rset_get_all_n_not_running_nodelist_get_list_called, OP_EQ, 1);
done: ; }
const smartlist_t * -NS(nodelist_get_list)(void) +rset_get_all_n_not_running_nodelist_get_list(void) { - CALLED(nodelist_get_list)++; + rset_get_all_n_not_running_nodelist_get_list_called++;
- return NS(mock_smartlist); + return rset_get_all_n_not_running_mock_smartlist; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE subtract_nodes - /* * Functional test for routerset_subtract_nodes. */
static void -NS(test_main)(void *arg) +test_rset_subtract_nodes(void *arg) { routerset_t *set = routerset_new(); smartlist_t *list = smartlist_new(); @@ -1873,15 +1795,12 @@ NS(test_main)(void *arg) smartlist_free(list); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(subtract_nodes, null_routerset) - /* * Functional test for routerset_subtract_nodes, with a NULL routerset. */
static void -NS(test_main)(void *arg) +test_rset_subtract_nodes_null_routerset(void *arg) { routerset_t *set = NULL; smartlist_t *list = smartlist_new(); @@ -1903,15 +1822,12 @@ NS(test_main)(void *arg) smartlist_free(list); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE to_string - /* * Functional test for routerset_to_string. */
static void -NS(test_main)(void *arg) +test_rset_to_string(void *arg) { routerset_t *set = NULL; char *s = NULL; @@ -1948,15 +1864,12 @@ NS(test_main)(void *arg) routerset_free(set); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(equal, empty_empty) - /* * Functional test for routerset_equal, with both routersets empty. */
static void -NS(test_main)(void *arg) +test_rset_equal_empty_empty(void *arg) { routerset_t *a = routerset_new(), *b = routerset_new(); int r; @@ -1972,15 +1885,12 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(equal, empty_not_empty) - /* * Functional test for routerset_equal, with one routersets empty. */
static void -NS(test_main)(void *arg) +test_rset_equal_empty_not_empty(void *arg) { routerset_t *a = routerset_new(), *b = routerset_new(); int r; @@ -1996,16 +1906,13 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(equal, differing_lengths) - /* * Functional test for routerset_equal, with the routersets having * differing lengths. */
static void -NS(test_main)(void *arg) +test_rset_equal_differing_lengths(void *arg) { routerset_t *a = routerset_new(), *b = routerset_new(); int r; @@ -2023,16 +1930,13 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(equal, unequal) - /* * Functional test for routerset_equal, with the routersets being * different. */
static void -NS(test_main)(void *arg) +test_rset_equal_unequal(void *arg) { routerset_t *a = routerset_new(), *b = routerset_new(); int r; @@ -2049,16 +1953,13 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(equal, equal) - /* * Functional test for routerset_equal, with the routersets being * equal. */
static void -NS(test_main)(void *arg) +test_rset_equal_equal(void *arg) { routerset_t *a = routerset_new(), *b = routerset_new(); int r; @@ -2075,147 +1976,147 @@ NS(test_main)(void *arg) ; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(free, null_routerset) - /* * Structural test for routerset_free, where the routerset is NULL. */
-NS_DECL(void, smartlist_free_, (smartlist_t *sl)); +static void rset_free_null_routerset_smartlist_free_(smartlist_t *sl); +ATTR_UNUSED static int rset_free_null_routerset_smartlist_free__called = 0;
static void -NS(test_main)(void *arg) +test_rset_free_null_routerset(void *arg) { (void)arg;
- NS_MOCK(smartlist_free_); + MOCK(smartlist_free_, + rset_free_null_routerset_smartlist_free_);
routerset_free_(NULL);
- tt_int_op(CALLED(smartlist_free_), OP_EQ, 0); + tt_int_op(rset_free_null_routerset_smartlist_free__called, OP_EQ, 0);
done: ; }
void -NS(smartlist_free_)(smartlist_t *s) +rset_free_null_routerset_smartlist_free_(smartlist_t *s) { (void)s; - CALLED(smartlist_free_)++; + rset_free_null_routerset_smartlist_free__called++; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE free - /* * Structural test for routerset_free. */
-NS_DECL(void, smartlist_free_, (smartlist_t *sl)); -NS_DECL(void, strmap_free_,(strmap_t *map, void (*free_val)(void*))); -NS_DECL(void, digestmap_free_, (digestmap_t *map, void (*free_val)(void*))); +static void rset_free_smartlist_free_(smartlist_t *sl); +ATTR_UNUSED static int rset_free_smartlist_free__called = 0; +static void rset_free_strmap_free_(strmap_t *map, void (*free_val)(void*)); +ATTR_UNUSED static int rset_free_strmap_free__called = 0; +static void rset_free_digestmap_free_(digestmap_t *map, void (*free_val)(void*)); +ATTR_UNUSED static int rset_free_digestmap_free__called = 0;
static void -NS(test_main)(void *arg) +test_rset_free(void *arg) { routerset_t *routerset = routerset_new(); (void)arg;
- NS_MOCK(smartlist_free_); - NS_MOCK(strmap_free_); - NS_MOCK(digestmap_free_); + MOCK(smartlist_free_, + rset_free_smartlist_free_); + MOCK(strmap_free_, + rset_free_strmap_free_); + MOCK(digestmap_free_, + rset_free_digestmap_free_);
routerset_free(routerset);
- tt_int_op(CALLED(smartlist_free_), OP_NE, 0); - tt_int_op(CALLED(strmap_free_), OP_NE, 0); - tt_int_op(CALLED(digestmap_free_), OP_NE, 0); + tt_int_op(rset_free_smartlist_free__called, OP_NE, 0); + tt_int_op(rset_free_strmap_free__called, OP_NE, 0); + tt_int_op(rset_free_digestmap_free__called, OP_NE, 0);
done: ; }
void -NS(smartlist_free_)(smartlist_t *s) +rset_free_smartlist_free_(smartlist_t *s) { - CALLED(smartlist_free_)++; + rset_free_smartlist_free__called++; smartlist_free___real(s); }
void -NS(strmap_free_)(strmap_t *map, void (*free_val)(void*)) +rset_free_strmap_free_(strmap_t *map, void (*free_val)(void*)) { - CALLED(strmap_free_)++; + rset_free_strmap_free__called++; strmap_free___real(map, free_val); }
void -NS(digestmap_free_)(digestmap_t *map, void (*free_val)(void*)) +rset_free_digestmap_free_(digestmap_t *map, void (*free_val)(void*)) { - CALLED(digestmap_free_)++; + rset_free_digestmap_free__called++; digestmap_free___real(map, free_val); }
-#undef NS_SUBMODULE - struct testcase_t routerset_tests[] = { - TEST_CASE(new), - TEST_CASE(get_countryname), - TEST_CASE(is_list), - TEST_CASE(needs_geoip), - TEST_CASE(is_empty), - TEST_CASE_ASPECT(contains, null_set_or_list), - TEST_CASE_ASPECT(contains, nickname), - TEST_CASE_ASPECT(contains, null_nickname), - TEST_CASE_ASPECT(contains, no_nickname), - TEST_CASE_ASPECT(contains, digest), - TEST_CASE_ASPECT(contains, no_digest), - TEST_CASE_ASPECT(contains, null_digest), - TEST_CASE_ASPECT(contains, addr), - TEST_CASE_ASPECT(contains, no_addr), - TEST_CASE_ASPECT(contains, null_addr), - TEST_CASE_ASPECT(contains, countries_no_geoip), - TEST_CASE_ASPECT(contains, countries_geoip), - TEST_CASE_ASPECT(add_unknown_ccs, only_flag), - TEST_CASE_ASPECT(add_unknown_ccs, creates_set), - TEST_CASE_ASPECT(add_unknown_ccs, add_unknown), - TEST_CASE_ASPECT(add_unknown_ccs, add_a1), - TEST_CASE(contains_extendinfo), - TEST_CASE(contains_router), - TEST_CASE(contains_routerstatus), - TEST_CASE_ASPECT(contains, none), - TEST_CASE_ASPECT(contains, routerinfo), - TEST_CASE_ASPECT(contains, rs), - TEST_CASE_ASPECT(get_all, no_routerset), - TEST_CASE_ASPECT(get_all, l_no_nodes), - TEST_CASE_ASPECT(get_all, l_not_running), - TEST_CASE_ASPECT(get_all, list), - TEST_CASE_ASPECT(get_all, n_no_nodes), - TEST_CASE_ASPECT(get_all, n_not_running), - TEST_CASE_ASPECT(refresh, geoip_not_loaded), - TEST_CASE_ASPECT(refresh, no_countries), - TEST_CASE_ASPECT(refresh, one_valid_country), - TEST_CASE_ASPECT(refresh, one_invalid_country), - TEST_CASE_ASPECT(union, source_bad), - TEST_CASE_ASPECT(union, one), - TEST_CASE_ASPECT(parse, malformed), - TEST_CASE_ASPECT(parse, valid_hexdigest), - TEST_CASE_ASPECT(parse, valid_nickname), - TEST_CASE_ASPECT(parse, get_countryname), - TEST_CASE_ASPECT(parse, policy_wildcard), - TEST_CASE_ASPECT(parse, policy_ipv4), - TEST_CASE_ASPECT(parse, policy_ipv6), - TEST_CASE(subtract_nodes), - TEST_CASE_ASPECT(subtract_nodes, null_routerset), - TEST_CASE(to_string), - TEST_CASE_ASPECT(equal, empty_empty), - TEST_CASE_ASPECT(equal, empty_not_empty), - TEST_CASE_ASPECT(equal, differing_lengths), - TEST_CASE_ASPECT(equal, unequal), - TEST_CASE_ASPECT(equal, equal), - TEST_CASE_ASPECT(free, null_routerset), - TEST_CASE(free), + { "new", test_rset_new, TT_FORK, NULL, NULL }, + { "get_countryname", test_rset_get_countryname, TT_FORK, NULL, NULL }, + { "is_list", test_rset_is_list, TT_FORK, NULL, NULL }, + { "needs_geoip", test_rset_needs_geoip, TT_FORK, NULL, NULL }, + { "is_empty", test_rset_is_empty, TT_FORK, NULL, NULL }, + { "contains_null_set_or_list", test_rset_contains_null_set_or_list, TT_FORK, NULL, NULL }, + { "contains_nickname", test_rset_contains_nickname, TT_FORK, NULL, NULL }, + { "contains_null_nickname", test_rset_contains_null_nickname, TT_FORK, NULL, NULL }, + { "contains_no_nickname", test_rset_contains_no_nickname, TT_FORK, NULL, NULL }, + { "contains_digest", test_rset_contains_digest, TT_FORK, NULL, NULL }, + { "contains_no_digest", test_rset_contains_no_digest, TT_FORK, NULL, NULL }, + { "contains_null_digest", test_rset_contains_null_digest, TT_FORK, NULL, NULL }, + { "contains_addr", test_rset_contains_addr, TT_FORK, NULL, NULL }, + { "contains_no_addr", test_rset_contains_no_addr, TT_FORK, NULL, NULL }, + { "contains_null_addr", test_rset_contains_null_addr, TT_FORK, NULL, NULL }, + { "contains_countries_no_geoip", test_rset_contains_countries_no_geoip, TT_FORK, NULL, NULL }, + { "contains_countries_geoip", test_rset_contains_countries_geoip, TT_FORK, NULL, NULL }, + { "add_unknown_ccs_only_flag", test_rset_add_unknown_ccs_only_flag, TT_FORK, NULL, NULL }, + { "add_unknown_ccs_creates_set", test_rset_add_unknown_ccs_creates_set, TT_FORK, NULL, NULL }, + { "add_unknown_ccs_add_unknown", test_rset_add_unknown_ccs_add_unknown, TT_FORK, NULL, NULL }, + { "add_unknown_ccs_add_a1", test_rset_add_unknown_ccs_add_a1, TT_FORK, NULL, NULL }, + { "contains_extendinfo", test_rset_contains_extendinfo, TT_FORK, NULL, NULL }, + { "contains_router", test_rset_contains_router, TT_FORK, NULL, NULL }, + { "contains_routerstatus", test_rset_contains_routerstatus, TT_FORK, NULL, NULL }, + { "contains_none", test_rset_contains_none, TT_FORK, NULL, NULL }, + { "contains_routerinfo", test_rset_contains_routerinfo, TT_FORK, NULL, NULL }, + { "contains_rs", test_rset_contains_rs, TT_FORK, NULL, NULL }, + { "get_all_no_routerset", test_rset_get_all_no_routerset, TT_FORK, NULL, NULL }, + { "get_all_l_no_nodes", test_rset_get_all_l_no_nodes, TT_FORK, NULL, NULL }, + { "get_all_l_not_running", test_rset_get_all_l_not_running, TT_FORK, NULL, NULL }, + { "get_all_list", test_rset_get_all_list, TT_FORK, NULL, NULL }, + { "get_all_n_no_nodes", test_rset_get_all_n_no_nodes, TT_FORK, NULL, NULL }, + { "get_all_n_not_running", test_rset_get_all_n_not_running, TT_FORK, NULL, NULL }, + { "refresh_geoip_not_loaded", test_rset_refresh_geoip_not_loaded, TT_FORK, NULL, NULL }, + { "refresh_no_countries", test_rset_refresh_no_countries, TT_FORK, NULL, NULL }, + { "refresh_one_valid_country", test_rset_refresh_one_valid_country, TT_FORK, NULL, NULL }, + { "refresh_one_invalid_country", test_rset_refresh_one_invalid_country, TT_FORK, NULL, NULL }, + { "union_source_bad", test_rset_union_source_bad, TT_FORK, NULL, NULL }, + { "union_one", test_rset_union_one, TT_FORK, NULL, NULL }, + { "parse_malformed", test_rset_parse_malformed, TT_FORK, NULL, NULL }, + { "parse_valid_hexdigest", test_rset_parse_valid_hexdigest, TT_FORK, NULL, NULL }, + { "parse_valid_nickname", test_rset_parse_valid_nickname, TT_FORK, NULL, NULL }, + { "parse_get_countryname", test_rset_parse_get_countryname, TT_FORK, NULL, NULL }, + { "parse_policy_wildcard", test_rset_parse_policy_wildcard, TT_FORK, NULL, NULL }, + { "parse_policy_ipv4", test_rset_parse_policy_ipv4, TT_FORK, NULL, NULL }, + { "parse_policy_ipv6", test_rset_parse_policy_ipv6, TT_FORK, NULL, NULL }, + { "subtract_nodes", test_rset_subtract_nodes, TT_FORK, NULL, NULL }, + { "subtract_nodes_null_routerset", test_rset_subtract_nodes_null_routerset, TT_FORK, NULL, NULL }, + { "to_string", test_rset_to_string, TT_FORK, NULL, NULL }, + { "equal_empty_empty", test_rset_equal_empty_empty, TT_FORK, NULL, NULL }, + { "equal_empty_not_empty", test_rset_equal_empty_not_empty, TT_FORK, NULL, NULL }, + { "equal_differing_lengths", test_rset_equal_differing_lengths, TT_FORK, NULL, NULL }, + { "equal_unequal", test_rset_equal_unequal, TT_FORK, NULL, NULL }, + { "equal_equal", test_rset_equal_equal, TT_FORK, NULL, NULL }, + { "free_null_routerset", test_rset_free_null_routerset, TT_FORK, NULL, NULL }, + { "free", test_rset_free, TT_FORK, NULL, NULL }, END_OF_TESTCASES }; diff --git a/src/test/test_status.c b/src/test/test_status.c index 88053a34f..ffce848db 100644 --- a/src/test/test_status.c +++ b/src/test/test_status.c @@ -33,10 +33,6 @@
#include "test/test.h"
-#define NS_MODULE status - -#define NS_SUBMODULE count_circuits - /* * Test that count_circuits() is correctly counting the number of * global circuits. @@ -44,10 +40,11 @@
static smartlist_t * mock_global_circuitlist = NULL;
-NS_DECL(smartlist_t *, circuit_get_global_list, (void)); +static smartlist_t * status_count_circuits_circuit_get_global_list(void); +ATTR_UNUSED static int status_count_circuits_circuit_get_global_list_called = 0;
static void -NS(test_main)(void *arg) +test_status_count_circuits(void *arg) { /* Choose origin_circuit_t wlog. */ origin_circuit_t *mock_circuit1, *mock_circuit2; @@ -61,7 +58,8 @@ NS(test_main)(void *arg) smartlist_add(mock_global_circuitlist, TO_CIRCUIT(mock_circuit1)); smartlist_add(mock_global_circuitlist, TO_CIRCUIT(mock_circuit2));
- NS_MOCK(circuit_get_global_list); + MOCK(circuit_get_global_list, + status_count_circuits_circuit_get_global_list);
actual_circuits = count_circuits();
@@ -72,25 +70,22 @@ NS(test_main)(void *arg) tor_free(mock_circuit2); smartlist_free(mock_global_circuitlist); mock_global_circuitlist = NULL; - NS_UNMOCK(circuit_get_global_list); + UNMOCK(circuit_get_global_list); }
static smartlist_t * -NS(circuit_get_global_list)(void) +status_count_circuits_circuit_get_global_list(void) { return mock_global_circuitlist; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE secs_to_uptime - /* * Test that secs_to_uptime() is converting the number of seconds that * Tor is up for into the appropriate string form containing hours and minutes. */
static void -NS(test_main)(void *arg) +test_status_secs_to_uptime(void *arg) { const char *expected; char *actual; @@ -161,9 +156,6 @@ NS(test_main)(void *arg) tor_free(actual); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE bytes_to_usage - /* * Test that bytes_to_usage() is correctly converting the number of bytes that * Tor has read/written into the appropriate string form containing kilobytes, @@ -171,7 +163,7 @@ NS(test_main)(void *arg) */
static void -NS(test_main)(void *arg) +test_status_bytes_to_usage(void *arg) { const char *expected; char *actual; @@ -242,29 +234,34 @@ NS(test_main)(void *arg) tor_free(actual); }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(hb, fails) - /* * Tests that log_heartbeat() fails when in the public server mode, * not hibernating, and we couldn't get the current routerinfo. */
-NS_DECL(double, tls_get_write_overhead_ratio, (void)); -NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(int, public_server_mode, (const or_options_t *options)); -NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void)); +static double status_hb_fails_tls_get_write_overhead_ratio(void); +ATTR_UNUSED static int status_hb_fails_tls_get_write_overhead_ratio_called = 0; +static int status_hb_fails_we_are_hibernating(void); +ATTR_UNUSED static int status_hb_fails_we_are_hibernating_called = 0; +static int status_hb_fails_public_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_fails_public_server_mode_called = 0; +static const routerinfo_t * status_hb_fails_router_get_my_routerinfo(void); +ATTR_UNUSED static int status_hb_fails_router_get_my_routerinfo_called = 0;
static void -NS(test_main)(void *arg) +test_status_hb_fails(void *arg) { int expected, actual; (void)arg;
- NS_MOCK(tls_get_write_overhead_ratio); - NS_MOCK(we_are_hibernating); - NS_MOCK(public_server_mode); - NS_MOCK(router_get_my_routerinfo); + MOCK(tls_get_write_overhead_ratio, + status_hb_fails_tls_get_write_overhead_ratio); + MOCK(we_are_hibernating, + status_hb_fails_we_are_hibernating); + MOCK(public_server_mode, + status_hb_fails_public_server_mode); + MOCK(router_get_my_routerinfo, + status_hb_fails_router_get_my_routerinfo);
expected = -1; actual = log_heartbeat(0); @@ -272,26 +269,26 @@ NS(test_main)(void *arg) tt_int_op(actual, OP_EQ, expected);
done: - NS_UNMOCK(tls_get_write_overhead_ratio); - NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(public_server_mode); - NS_UNMOCK(router_get_my_routerinfo); + UNMOCK(tls_get_write_overhead_ratio); + UNMOCK(we_are_hibernating); + UNMOCK(public_server_mode); + UNMOCK(router_get_my_routerinfo); }
static double -NS(tls_get_write_overhead_ratio)(void) +status_hb_fails_tls_get_write_overhead_ratio(void) { return 2.0; }
static int -NS(we_are_hibernating)(void) +status_hb_fails_we_are_hibernating(void) { return 0; }
static int -NS(public_server_mode)(const or_options_t *options) +status_hb_fails_public_server_mode(const or_options_t *options) { (void)options;
@@ -299,42 +296,53 @@ NS(public_server_mode)(const or_options_t *options) }
static const routerinfo_t * -NS(router_get_my_routerinfo)(void) +status_hb_fails_router_get_my_routerinfo(void) { return NULL; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(hb, not_in_consensus) - /* * Tests that log_heartbeat() logs appropriately if we are not in the cached * consensus. */
-NS_DECL(double, tls_get_write_overhead_ratio, (void)); -NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(int, public_server_mode, (const or_options_t *options)); -NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void)); -NS_DECL(const node_t *, node_get_by_id, (const char *identity_digest)); -NS_DECL(void, logv, (int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap)); -NS_DECL(int, server_mode, (const or_options_t *options)); +static double status_hb_not_in_consensus_tls_get_write_overhead_ratio(void); +ATTR_UNUSED static int status_hb_not_in_consensus_tls_get_write_overhead_ratio_called = 0; +static int status_hb_not_in_consensus_we_are_hibernating(void); +ATTR_UNUSED static int status_hb_not_in_consensus_we_are_hibernating_called = 0; +static int status_hb_not_in_consensus_public_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_not_in_consensus_public_server_mode_called = 0; +static const routerinfo_t * status_hb_not_in_consensus_router_get_my_routerinfo(void); +ATTR_UNUSED static int status_hb_not_in_consensus_router_get_my_routerinfo_called = 0; +static const node_t * status_hb_not_in_consensus_node_get_by_id(const char *identity_digest); +ATTR_UNUSED static int status_hb_not_in_consensus_node_get_by_id_called = 0; +static void status_hb_not_in_consensus_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap); +ATTR_UNUSED static int status_hb_not_in_consensus_logv_called = 0; +static int status_hb_not_in_consensus_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_not_in_consensus_server_mode_called = 0;
static routerinfo_t *mock_routerinfo;
static void -NS(test_main)(void *arg) +test_status_hb_not_in_consensus(void *arg) { int expected, actual; (void)arg;
- NS_MOCK(tls_get_write_overhead_ratio); - NS_MOCK(we_are_hibernating); - NS_MOCK(public_server_mode); - NS_MOCK(router_get_my_routerinfo); - NS_MOCK(node_get_by_id); - NS_MOCK(logv); - NS_MOCK(server_mode); + MOCK(tls_get_write_overhead_ratio, + status_hb_not_in_consensus_tls_get_write_overhead_ratio); + MOCK(we_are_hibernating, + status_hb_not_in_consensus_we_are_hibernating); + MOCK(public_server_mode, + status_hb_not_in_consensus_public_server_mode); + MOCK(router_get_my_routerinfo, + status_hb_not_in_consensus_router_get_my_routerinfo); + MOCK(node_get_by_id, + status_hb_not_in_consensus_node_get_by_id); + MOCK(logv, + status_hb_not_in_consensus_logv); + MOCK(server_mode, + status_hb_not_in_consensus_server_mode);
log_global_min_severity_ = LOG_DEBUG; onion_handshakes_requested[ONION_HANDSHAKE_TYPE_TAP] = 1; @@ -346,33 +354,33 @@ NS(test_main)(void *arg) actual = log_heartbeat(0);
tt_int_op(actual, OP_EQ, expected); - tt_int_op(CALLED(logv), OP_EQ, 6); + tt_int_op(status_hb_not_in_consensus_logv_called, OP_EQ, 6);
done: - NS_UNMOCK(tls_get_write_overhead_ratio); - NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(public_server_mode); - NS_UNMOCK(router_get_my_routerinfo); - NS_UNMOCK(node_get_by_id); - NS_UNMOCK(logv); - NS_UNMOCK(server_mode); + UNMOCK(tls_get_write_overhead_ratio); + UNMOCK(we_are_hibernating); + UNMOCK(public_server_mode); + UNMOCK(router_get_my_routerinfo); + UNMOCK(node_get_by_id); + UNMOCK(logv); + UNMOCK(server_mode); tor_free(mock_routerinfo); }
static double -NS(tls_get_write_overhead_ratio)(void) +status_hb_not_in_consensus_tls_get_write_overhead_ratio(void) { return 1.0; }
static int -NS(we_are_hibernating)(void) +status_hb_not_in_consensus_we_are_hibernating(void) { return 0; }
static int -NS(public_server_mode)(const or_options_t *options) +status_hb_not_in_consensus_public_server_mode(const or_options_t *options) { (void)options;
@@ -380,7 +388,7 @@ NS(public_server_mode)(const or_options_t *options) }
static const routerinfo_t * -NS(router_get_my_routerinfo)(void) +status_hb_not_in_consensus_router_get_my_routerinfo(void) { mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
@@ -388,7 +396,7 @@ NS(router_get_my_routerinfo)(void) }
static const node_t * -NS(node_get_by_id)(const char *identity_digest) +status_hb_not_in_consensus_node_get_by_id(const char *identity_digest) { (void)identity_digest;
@@ -396,10 +404,10 @@ NS(node_get_by_id)(const char *identity_digest) }
static void -NS(logv)(int severity, log_domain_mask_t domain, +status_hb_not_in_consensus_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap) { - switch (CALLED(logv)) + switch (status_hb_not_in_consensus_logv_called) { case 0: tt_int_op(severity, OP_EQ, LOG_NOTICE); @@ -462,50 +470,63 @@ NS(logv)(int severity, log_domain_mask_t domain, }
done: - CALLED(logv)++; + status_hb_not_in_consensus_logv_called++; }
static int -NS(server_mode)(const or_options_t *options) +status_hb_not_in_consensus_server_mode(const or_options_t *options) { (void)options;
return 0; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(hb, simple) - /* * Tests that log_heartbeat() correctly logs heartbeat information * normally. */
-NS_DECL(double, tls_get_write_overhead_ratio, (void)); -NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(int, public_server_mode, (const or_options_t *options)); -NS_DECL(long, get_uptime, (void)); -NS_DECL(uint64_t, get_bytes_read, (void)); -NS_DECL(uint64_t, get_bytes_written, (void)); -NS_DECL(void, logv, (int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap)); -NS_DECL(int, server_mode, (const or_options_t *options)); - -static int NS(n_msgs) = 0; +static double status_hb_simple_tls_get_write_overhead_ratio(void); +ATTR_UNUSED static int status_hb_simple_tls_get_write_overhead_ratio_called = 0; +static int status_hb_simple_we_are_hibernating(void); +ATTR_UNUSED static int status_hb_simple_we_are_hibernating_called = 0; +static int status_hb_simple_public_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_simple_public_server_mode_called = 0; +static long status_hb_simple_get_uptime(void); +ATTR_UNUSED static int status_hb_simple_get_uptime_called = 0; +static uint64_t status_hb_simple_get_bytes_read(void); +ATTR_UNUSED static int status_hb_simple_get_bytes_read_called = 0; +static uint64_t status_hb_simple_get_bytes_written(void); +ATTR_UNUSED static int status_hb_simple_get_bytes_written_called = 0; +static void status_hb_simple_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap); +ATTR_UNUSED static int status_hb_simple_logv_called = 0; +static int status_hb_simple_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_simple_server_mode_called = 0; + +static int status_hb_simple_n_msgs = 0;
static void -NS(test_main)(void *arg) +test_status_hb_simple(void *arg) { int expected, actual; (void)arg;
- NS_MOCK(tls_get_write_overhead_ratio); - NS_MOCK(we_are_hibernating); - NS_MOCK(public_server_mode); - NS_MOCK(get_uptime); - NS_MOCK(get_bytes_read); - NS_MOCK(get_bytes_written); - NS_MOCK(logv); - NS_MOCK(server_mode); + MOCK(tls_get_write_overhead_ratio, + status_hb_simple_tls_get_write_overhead_ratio); + MOCK(we_are_hibernating, + status_hb_simple_we_are_hibernating); + MOCK(public_server_mode, + status_hb_simple_public_server_mode); + MOCK(get_uptime, + status_hb_simple_get_uptime); + MOCK(get_bytes_read, + status_hb_simple_get_bytes_read); + MOCK(get_bytes_written, + status_hb_simple_get_bytes_written); + MOCK(logv, + status_hb_simple_logv); + MOCK(server_mode, + status_hb_simple_server_mode);
log_global_min_severity_ = LOG_DEBUG;
@@ -513,33 +534,33 @@ NS(test_main)(void *arg) actual = log_heartbeat(0);
tt_int_op(actual, OP_EQ, expected); - tt_int_op(NS(n_msgs), OP_EQ, 1); + tt_int_op(status_hb_simple_n_msgs, OP_EQ, 1);
done: - NS_UNMOCK(tls_get_write_overhead_ratio); - NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(public_server_mode); - NS_UNMOCK(get_uptime); - NS_UNMOCK(get_bytes_read); - NS_UNMOCK(get_bytes_written); - NS_UNMOCK(logv); - NS_UNMOCK(server_mode); + UNMOCK(tls_get_write_overhead_ratio); + UNMOCK(we_are_hibernating); + UNMOCK(public_server_mode); + UNMOCK(get_uptime); + UNMOCK(get_bytes_read); + UNMOCK(get_bytes_written); + UNMOCK(logv); + UNMOCK(server_mode); }
static double -NS(tls_get_write_overhead_ratio)(void) +status_hb_simple_tls_get_write_overhead_ratio(void) { return 1.0; }
static int -NS(we_are_hibernating)(void) +status_hb_simple_we_are_hibernating(void) { return 1; }
static int -NS(public_server_mode)(const or_options_t *options) +status_hb_simple_public_server_mode(const or_options_t *options) { (void)options;
@@ -547,30 +568,30 @@ NS(public_server_mode)(const or_options_t *options) }
static long -NS(get_uptime)(void) +status_hb_simple_get_uptime(void) { return 0; }
static uint64_t -NS(get_bytes_read)(void) +status_hb_simple_get_bytes_read(void) { return 0; }
static uint64_t -NS(get_bytes_written)(void) +status_hb_simple_get_bytes_written(void) { return 0; }
static void -NS(logv)(int severity, log_domain_mask_t domain, const char *funcname, +status_hb_simple_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap) { if (severity == LOG_INFO) return; - ++NS(n_msgs); + ++status_hb_simple_n_msgs;
tt_int_op(severity, OP_EQ, LOG_NOTICE); tt_u64_op(domain, OP_EQ, LD_HEARTBEAT); @@ -590,53 +611,72 @@ NS(logv)(int severity, log_domain_mask_t domain, const char *funcname, }
static int -NS(server_mode)(const or_options_t *options) +status_hb_simple_server_mode(const or_options_t *options) { (void)options;
return 0; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(hb, calls_log_accounting) - /* * Tests that log_heartbeat() correctly logs heartbeat information * and accounting information when configured. */
-NS_DECL(double, tls_get_write_overhead_ratio, (void)); -NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(int, public_server_mode, (const or_options_t *options)); -NS_DECL(long, get_uptime, (void)); -NS_DECL(uint64_t, get_bytes_read, (void)); -NS_DECL(uint64_t, get_bytes_written, (void)); -NS_DECL(void, logv, (int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap)); -NS_DECL(int, server_mode, (const or_options_t *options)); -NS_DECL(or_state_t *, get_or_state, (void)); -NS_DECL(int, accounting_is_enabled, (const or_options_t *options)); -NS_DECL(time_t, accounting_get_end_time, (void)); - -static or_state_t * NS(mock_state) = NULL; -static or_options_t * NS(mock_options) = NULL; +static double status_hb_calls_log_accounting_tls_get_write_overhead_ratio(void); +ATTR_UNUSED static int status_hb_calls_log_accounting_tls_get_write_overhead_ratio_called = 0; +static int status_hb_calls_log_accounting_we_are_hibernating(void); +ATTR_UNUSED static int status_hb_calls_log_accounting_we_are_hibernating_called = 0; +static int status_hb_calls_log_accounting_public_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_calls_log_accounting_public_server_mode_called = 0; +static long status_hb_calls_log_accounting_get_uptime(void); +ATTR_UNUSED static int status_hb_calls_log_accounting_get_uptime_called = 0; +static uint64_t status_hb_calls_log_accounting_get_bytes_read(void); +ATTR_UNUSED static int status_hb_calls_log_accounting_get_bytes_read_called = 0; +static uint64_t status_hb_calls_log_accounting_get_bytes_written(void); +ATTR_UNUSED static int status_hb_calls_log_accounting_get_bytes_written_called = 0; +static void status_hb_calls_log_accounting_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap); +ATTR_UNUSED static int status_hb_calls_log_accounting_logv_called = 0; +static int status_hb_calls_log_accounting_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_calls_log_accounting_server_mode_called = 0; +static or_state_t * status_hb_calls_log_accounting_get_or_state(void); +ATTR_UNUSED static int status_hb_calls_log_accounting_get_or_state_called = 0; +static int status_hb_calls_log_accounting_accounting_is_enabled(const or_options_t *options); +ATTR_UNUSED static int status_hb_calls_log_accounting_accounting_is_enabled_called = 0; +static time_t status_hb_calls_log_accounting_accounting_get_end_time(void); +ATTR_UNUSED static int status_hb_calls_log_accounting_accounting_get_end_time_called = 0; + +static or_state_t * status_hb_calls_log_accounting_mock_state = NULL; +static or_options_t * status_hb_calls_log_accounting_mock_options = NULL;
static void -NS(test_main)(void *arg) +test_status_hb_calls_log_accounting(void *arg) { int expected, actual; (void)arg;
- NS_MOCK(tls_get_write_overhead_ratio); - NS_MOCK(we_are_hibernating); - NS_MOCK(public_server_mode); - NS_MOCK(get_uptime); - NS_MOCK(get_bytes_read); - NS_MOCK(get_bytes_written); - NS_MOCK(logv); - NS_MOCK(server_mode); - NS_MOCK(get_or_state); - NS_MOCK(accounting_is_enabled); - NS_MOCK(accounting_get_end_time); + MOCK(tls_get_write_overhead_ratio, + status_hb_calls_log_accounting_tls_get_write_overhead_ratio); + MOCK(we_are_hibernating, + status_hb_calls_log_accounting_we_are_hibernating); + MOCK(public_server_mode, + status_hb_calls_log_accounting_public_server_mode); + MOCK(get_uptime, + status_hb_calls_log_accounting_get_uptime); + MOCK(get_bytes_read, + status_hb_calls_log_accounting_get_bytes_read); + MOCK(get_bytes_written, + status_hb_calls_log_accounting_get_bytes_written); + MOCK(logv, + status_hb_calls_log_accounting_logv); + MOCK(server_mode, + status_hb_calls_log_accounting_server_mode); + MOCK(get_or_state, + status_hb_calls_log_accounting_get_or_state); + MOCK(accounting_is_enabled, + status_hb_calls_log_accounting_accounting_is_enabled); + MOCK(accounting_get_end_time, + status_hb_calls_log_accounting_accounting_get_end_time);
log_global_min_severity_ = LOG_DEBUG;
@@ -644,37 +684,37 @@ NS(test_main)(void *arg) actual = log_heartbeat(0);
tt_int_op(actual, OP_EQ, expected); - tt_int_op(CALLED(logv), OP_EQ, 3); + tt_int_op(status_hb_calls_log_accounting_logv_called, OP_EQ, 3);
done: - NS_UNMOCK(tls_get_write_overhead_ratio); - NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(public_server_mode); - NS_UNMOCK(get_uptime); - NS_UNMOCK(get_bytes_read); - NS_UNMOCK(get_bytes_written); - NS_UNMOCK(logv); - NS_UNMOCK(server_mode); - NS_UNMOCK(accounting_is_enabled); - NS_UNMOCK(accounting_get_end_time); - tor_free_(NS(mock_state)); - tor_free_(NS(mock_options)); + UNMOCK(tls_get_write_overhead_ratio); + UNMOCK(we_are_hibernating); + UNMOCK(public_server_mode); + UNMOCK(get_uptime); + UNMOCK(get_bytes_read); + UNMOCK(get_bytes_written); + UNMOCK(logv); + UNMOCK(server_mode); + UNMOCK(accounting_is_enabled); + UNMOCK(accounting_get_end_time); + tor_free_(status_hb_calls_log_accounting_mock_state); + tor_free_(status_hb_calls_log_accounting_mock_options); }
static double -NS(tls_get_write_overhead_ratio)(void) +status_hb_calls_log_accounting_tls_get_write_overhead_ratio(void) { return 1.0; }
static int -NS(we_are_hibernating)(void) +status_hb_calls_log_accounting_we_are_hibernating(void) { return 0; }
static int -NS(public_server_mode)(const or_options_t *options) +status_hb_calls_log_accounting_public_server_mode(const or_options_t *options) { (void)options;
@@ -682,28 +722,28 @@ NS(public_server_mode)(const or_options_t *options) }
static long -NS(get_uptime)(void) +status_hb_calls_log_accounting_get_uptime(void) { return 0; }
static uint64_t -NS(get_bytes_read)(void) +status_hb_calls_log_accounting_get_bytes_read(void) { return 0; }
static uint64_t -NS(get_bytes_written)(void) +status_hb_calls_log_accounting_get_bytes_written(void) { return 0; }
static void -NS(logv)(int severity, log_domain_mask_t domain, +status_hb_calls_log_accounting_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap) { - switch (CALLED(logv)) + switch (status_hb_calls_log_accounting_logv_called) { case 0: tt_int_op(severity, OP_EQ, LOG_NOTICE); @@ -748,11 +788,11 @@ NS(logv)(int severity, log_domain_mask_t domain, }
done: - CALLED(logv)++; + status_hb_calls_log_accounting_logv_called++; }
static int -NS(server_mode)(const or_options_t *options) +status_hb_calls_log_accounting_server_mode(const or_options_t *options) { (void)options;
@@ -760,7 +800,7 @@ NS(server_mode)(const or_options_t *options) }
static int -NS(accounting_is_enabled)(const or_options_t *options) +status_hb_calls_log_accounting_accounting_is_enabled(const or_options_t *options) { (void)options;
@@ -768,54 +808,69 @@ NS(accounting_is_enabled)(const or_options_t *options) }
static time_t -NS(accounting_get_end_time)(void) +status_hb_calls_log_accounting_accounting_get_end_time(void) { return 60; }
static or_state_t * -NS(get_or_state)(void) +status_hb_calls_log_accounting_get_or_state(void) { - NS(mock_state) = tor_malloc_zero(sizeof(or_state_t)); - NS(mock_state)->AccountingBytesReadInInterval = 0; - NS(mock_state)->AccountingBytesWrittenInInterval = 0; + status_hb_calls_log_accounting_mock_state = tor_malloc_zero(sizeof(or_state_t)); + status_hb_calls_log_accounting_mock_state->AccountingBytesReadInInterval = 0; + status_hb_calls_log_accounting_mock_state->AccountingBytesWrittenInInterval = 0;
- return NS(mock_state); + return status_hb_calls_log_accounting_mock_state; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(hb, packaged_cell_fullness) - /* * Tests that log_heartbeat() correctly logs packaged cell * fullness information. */
-NS_DECL(double, tls_get_write_overhead_ratio, (void)); -NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(int, public_server_mode, (const or_options_t *options)); -NS_DECL(long, get_uptime, (void)); -NS_DECL(uint64_t, get_bytes_read, (void)); -NS_DECL(uint64_t, get_bytes_written, (void)); -NS_DECL(void, logv, (int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap)); -NS_DECL(int, server_mode, (const or_options_t *options)); -NS_DECL(int, accounting_is_enabled, (const or_options_t *options)); +static double status_hb_packaged_cell_fullness_tls_get_write_overhead_ratio(void); +ATTR_UNUSED static int status_hb_packaged_cell_fullness_tls_get_write_overhead_ratio_called = 0; +static int status_hb_packaged_cell_fullness_we_are_hibernating(void); +ATTR_UNUSED static int status_hb_packaged_cell_fullness_we_are_hibernating_called = 0; +static int status_hb_packaged_cell_fullness_public_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_packaged_cell_fullness_public_server_mode_called = 0; +static long status_hb_packaged_cell_fullness_get_uptime(void); +ATTR_UNUSED static int status_hb_packaged_cell_fullness_get_uptime_called = 0; +static uint64_t status_hb_packaged_cell_fullness_get_bytes_read(void); +ATTR_UNUSED static int status_hb_packaged_cell_fullness_get_bytes_read_called = 0; +static uint64_t status_hb_packaged_cell_fullness_get_bytes_written(void); +ATTR_UNUSED static int status_hb_packaged_cell_fullness_get_bytes_written_called = 0; +static void status_hb_packaged_cell_fullness_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap); +ATTR_UNUSED static int status_hb_packaged_cell_fullness_logv_called = 0; +static int status_hb_packaged_cell_fullness_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_packaged_cell_fullness_server_mode_called = 0; +static int status_hb_packaged_cell_fullness_accounting_is_enabled(const or_options_t *options); +ATTR_UNUSED static int status_hb_packaged_cell_fullness_accounting_is_enabled_called = 0;
static void -NS(test_main)(void *arg) +test_status_hb_packaged_cell_fullness(void *arg) { int expected, actual; (void)arg;
- NS_MOCK(tls_get_write_overhead_ratio); - NS_MOCK(we_are_hibernating); - NS_MOCK(public_server_mode); - NS_MOCK(get_uptime); - NS_MOCK(get_bytes_read); - NS_MOCK(get_bytes_written); - NS_MOCK(logv); - NS_MOCK(server_mode); - NS_MOCK(accounting_is_enabled); + MOCK(tls_get_write_overhead_ratio, + status_hb_packaged_cell_fullness_tls_get_write_overhead_ratio); + MOCK(we_are_hibernating, + status_hb_packaged_cell_fullness_we_are_hibernating); + MOCK(public_server_mode, + status_hb_packaged_cell_fullness_public_server_mode); + MOCK(get_uptime, + status_hb_packaged_cell_fullness_get_uptime); + MOCK(get_bytes_read, + status_hb_packaged_cell_fullness_get_bytes_read); + MOCK(get_bytes_written, + status_hb_packaged_cell_fullness_get_bytes_written); + MOCK(logv, + status_hb_packaged_cell_fullness_logv); + MOCK(server_mode, + status_hb_packaged_cell_fullness_server_mode); + MOCK(accounting_is_enabled, + status_hb_packaged_cell_fullness_accounting_is_enabled); log_global_min_severity_ = LOG_DEBUG;
stats_n_data_bytes_packaged = RELAY_PAYLOAD_SIZE; @@ -824,36 +879,36 @@ NS(test_main)(void *arg) actual = log_heartbeat(0);
tt_int_op(actual, OP_EQ, expected); - tt_int_op(CALLED(logv), OP_EQ, 2); + tt_int_op(status_hb_packaged_cell_fullness_logv_called, OP_EQ, 2);
done: stats_n_data_bytes_packaged = 0; stats_n_data_cells_packaged = 0; - NS_UNMOCK(tls_get_write_overhead_ratio); - NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(public_server_mode); - NS_UNMOCK(get_uptime); - NS_UNMOCK(get_bytes_read); - NS_UNMOCK(get_bytes_written); - NS_UNMOCK(logv); - NS_UNMOCK(server_mode); - NS_UNMOCK(accounting_is_enabled); + UNMOCK(tls_get_write_overhead_ratio); + UNMOCK(we_are_hibernating); + UNMOCK(public_server_mode); + UNMOCK(get_uptime); + UNMOCK(get_bytes_read); + UNMOCK(get_bytes_written); + UNMOCK(logv); + UNMOCK(server_mode); + UNMOCK(accounting_is_enabled); }
static double -NS(tls_get_write_overhead_ratio)(void) +status_hb_packaged_cell_fullness_tls_get_write_overhead_ratio(void) { return 1.0; }
static int -NS(we_are_hibernating)(void) +status_hb_packaged_cell_fullness_we_are_hibernating(void) { return 0; }
static int -NS(public_server_mode)(const or_options_t *options) +status_hb_packaged_cell_fullness_public_server_mode(const or_options_t *options) { (void)options;
@@ -861,28 +916,28 @@ NS(public_server_mode)(const or_options_t *options) }
static long -NS(get_uptime)(void) +status_hb_packaged_cell_fullness_get_uptime(void) { return 0; }
static uint64_t -NS(get_bytes_read)(void) +status_hb_packaged_cell_fullness_get_bytes_read(void) { return 0; }
static uint64_t -NS(get_bytes_written)(void) +status_hb_packaged_cell_fullness_get_bytes_written(void) { return 0; }
static void -NS(logv)(int severity, log_domain_mask_t domain, const char *funcname, +status_hb_packaged_cell_fullness_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap) { - switch (CALLED(logv)) + switch (status_hb_packaged_cell_fullness_logv_called) { case 0: tt_int_op(severity, OP_EQ, LOG_NOTICE); @@ -915,11 +970,11 @@ NS(logv)(int severity, log_domain_mask_t domain, const char *funcname, }
done: - CALLED(logv)++; + status_hb_packaged_cell_fullness_logv_called++; }
static int -NS(server_mode)(const or_options_t *options) +status_hb_packaged_cell_fullness_server_mode(const or_options_t *options) { (void)options;
@@ -927,46 +982,61 @@ NS(server_mode)(const or_options_t *options) }
static int -NS(accounting_is_enabled)(const or_options_t *options) +status_hb_packaged_cell_fullness_accounting_is_enabled(const or_options_t *options) { (void)options;
return 0; }
-#undef NS_SUBMODULE -#define NS_SUBMODULE ASPECT(hb, tls_write_overhead) - /* * Tests that log_heartbeat() correctly logs the TLS write overhead information * when the TLS write overhead ratio exceeds 1. */
-NS_DECL(double, tls_get_write_overhead_ratio, (void)); -NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(int, public_server_mode, (const or_options_t *options)); -NS_DECL(long, get_uptime, (void)); -NS_DECL(uint64_t, get_bytes_read, (void)); -NS_DECL(uint64_t, get_bytes_written, (void)); -NS_DECL(void, logv, (int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap)); -NS_DECL(int, server_mode, (const or_options_t *options)); -NS_DECL(int, accounting_is_enabled, (const or_options_t *options)); +static double status_hb_tls_write_overhead_tls_get_write_overhead_ratio(void); +ATTR_UNUSED static int status_hb_tls_write_overhead_tls_get_write_overhead_ratio_called = 0; +static int status_hb_tls_write_overhead_we_are_hibernating(void); +ATTR_UNUSED static int status_hb_tls_write_overhead_we_are_hibernating_called = 0; +static int status_hb_tls_write_overhead_public_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_tls_write_overhead_public_server_mode_called = 0; +static long status_hb_tls_write_overhead_get_uptime(void); +ATTR_UNUSED static int status_hb_tls_write_overhead_get_uptime_called = 0; +static uint64_t status_hb_tls_write_overhead_get_bytes_read(void); +ATTR_UNUSED static int status_hb_tls_write_overhead_get_bytes_read_called = 0; +static uint64_t status_hb_tls_write_overhead_get_bytes_written(void); +ATTR_UNUSED static int status_hb_tls_write_overhead_get_bytes_written_called = 0; +static void status_hb_tls_write_overhead_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap); +ATTR_UNUSED static int status_hb_tls_write_overhead_logv_called = 0; +static int status_hb_tls_write_overhead_server_mode(const or_options_t *options); +ATTR_UNUSED static int status_hb_tls_write_overhead_server_mode_called = 0; +static int status_hb_tls_write_overhead_accounting_is_enabled(const or_options_t *options); +ATTR_UNUSED static int status_hb_tls_write_overhead_accounting_is_enabled_called = 0;
static void -NS(test_main)(void *arg) +test_status_hb_tls_write_overhead(void *arg) { int expected, actual; (void)arg;
- NS_MOCK(tls_get_write_overhead_ratio); - NS_MOCK(we_are_hibernating); - NS_MOCK(public_server_mode); - NS_MOCK(get_uptime); - NS_MOCK(get_bytes_read); - NS_MOCK(get_bytes_written); - NS_MOCK(logv); - NS_MOCK(server_mode); - NS_MOCK(accounting_is_enabled); + MOCK(tls_get_write_overhead_ratio, + status_hb_tls_write_overhead_tls_get_write_overhead_ratio); + MOCK(we_are_hibernating, + status_hb_tls_write_overhead_we_are_hibernating); + MOCK(public_server_mode, + status_hb_tls_write_overhead_public_server_mode); + MOCK(get_uptime, + status_hb_tls_write_overhead_get_uptime); + MOCK(get_bytes_read, + status_hb_tls_write_overhead_get_bytes_read); + MOCK(get_bytes_written, + status_hb_tls_write_overhead_get_bytes_written); + MOCK(logv, + status_hb_tls_write_overhead_logv); + MOCK(server_mode, + status_hb_tls_write_overhead_server_mode); + MOCK(accounting_is_enabled, + status_hb_tls_write_overhead_accounting_is_enabled); stats_n_data_cells_packaged = 0; log_global_min_severity_ = LOG_DEBUG;
@@ -974,34 +1044,34 @@ NS(test_main)(void *arg) actual = log_heartbeat(0);
tt_int_op(actual, OP_EQ, expected); - tt_int_op(CALLED(logv), OP_EQ, 2); + tt_int_op(status_hb_tls_write_overhead_logv_called, OP_EQ, 2);
done: - NS_UNMOCK(tls_get_write_overhead_ratio); - NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(public_server_mode); - NS_UNMOCK(get_uptime); - NS_UNMOCK(get_bytes_read); - NS_UNMOCK(get_bytes_written); - NS_UNMOCK(logv); - NS_UNMOCK(server_mode); - NS_UNMOCK(accounting_is_enabled); + UNMOCK(tls_get_write_overhead_ratio); + UNMOCK(we_are_hibernating); + UNMOCK(public_server_mode); + UNMOCK(get_uptime); + UNMOCK(get_bytes_read); + UNMOCK(get_bytes_written); + UNMOCK(logv); + UNMOCK(server_mode); + UNMOCK(accounting_is_enabled); }
static double -NS(tls_get_write_overhead_ratio)(void) +status_hb_tls_write_overhead_tls_get_write_overhead_ratio(void) { return 2.0; }
static int -NS(we_are_hibernating)(void) +status_hb_tls_write_overhead_we_are_hibernating(void) { return 0; }
static int -NS(public_server_mode)(const or_options_t *options) +status_hb_tls_write_overhead_public_server_mode(const or_options_t *options) { (void)options;
@@ -1009,28 +1079,28 @@ NS(public_server_mode)(const or_options_t *options) }
static long -NS(get_uptime)(void) +status_hb_tls_write_overhead_get_uptime(void) { return 0; }
static uint64_t -NS(get_bytes_read)(void) +status_hb_tls_write_overhead_get_bytes_read(void) { return 0; }
static uint64_t -NS(get_bytes_written)(void) +status_hb_tls_write_overhead_get_bytes_written(void) { return 0; }
static void -NS(logv)(int severity, log_domain_mask_t domain, +status_hb_tls_write_overhead_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap) { - switch (CALLED(logv)) + switch (status_hb_tls_write_overhead_logv_called) { case 0: tt_int_op(severity, OP_EQ, LOG_NOTICE); @@ -1063,11 +1133,11 @@ NS(logv)(int severity, log_domain_mask_t domain, }
done: - CALLED(logv)++; + status_hb_tls_write_overhead_logv_called++; }
static int -NS(server_mode)(const or_options_t *options) +status_hb_tls_write_overhead_server_mode(const or_options_t *options) { (void)options;
@@ -1075,24 +1145,22 @@ NS(server_mode)(const or_options_t *options) }
static int -NS(accounting_is_enabled)(const or_options_t *options) +status_hb_tls_write_overhead_accounting_is_enabled(const or_options_t *options) { (void)options;
return 0; }
-#undef NS_SUBMODULE - struct testcase_t status_tests[] = { - TEST_CASE(count_circuits), - TEST_CASE(secs_to_uptime), - TEST_CASE(bytes_to_usage), - TEST_CASE_ASPECT(hb, fails), - TEST_CASE_ASPECT(hb, simple), - TEST_CASE_ASPECT(hb, not_in_consensus), - TEST_CASE_ASPECT(hb, calls_log_accounting), - TEST_CASE_ASPECT(hb, packaged_cell_fullness), - TEST_CASE_ASPECT(hb, tls_write_overhead), + { "count_circuits", test_status_count_circuits, TT_FORK, NULL, NULL }, + { "secs_to_uptime", test_status_secs_to_uptime, TT_FORK, NULL, NULL }, + { "bytes_to_usage", test_status_bytes_to_usage, TT_FORK, NULL, NULL }, + { "hb_fails", test_status_hb_fails, TT_FORK, NULL, NULL }, + { "hb_simple", test_status_hb_simple, TT_FORK, NULL, NULL }, + { "hb_not_in_consensus", test_status_hb_not_in_consensus, TT_FORK, NULL, NULL }, + { "hb_calls_log_accounting", test_status_hb_calls_log_accounting, TT_FORK, NULL, NULL }, + { "hb_packaged_cell_fullness", test_status_hb_packaged_cell_fullness, TT_FORK, NULL, NULL }, + { "hb_tls_write_overhead", test_status_hb_tls_write_overhead, TT_FORK, NULL, NULL }, END_OF_TESTCASES }; diff --git a/src/test/test_tortls.c b/src/test/test_tortls.c index 5f6de6cd1..a822bc5ad 100644 --- a/src/test/test_tortls.c +++ b/src/test/test_tortls.c @@ -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); diff --git a/src/test/test_tortls_openssl.c b/src/test/test_tortls_openssl.c index 8ccad20bb..4318f7f1e 100644 --- a/src/test/test_tortls_openssl.c +++ b/src/test/test_tortls_openssl.c @@ -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) { diff --git a/src/test/test_util_format.c b/src/test/test_util_format.c index bbbf365f1..726e8e742 100644 --- a/src/test/test_util_format.c +++ b/src/test/test_util_format.c @@ -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) { diff --git a/src/test/test_util_process.c b/src/test/test_util_process.c index 5de729dd6..0e17e009f 100644 --- a/src/test/test_util_process.c +++ b/src/test/test_util_process.c @@ -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)
tor-commits@lists.torproject.org