Merge remote-tracking branch 'tor-github/pr/1447'

This commit is contained in:
teor 2019-10-24 10:00:47 +10:00
commit 20606b8a15
No known key found for this signature in database
GPG Key ID: 10FEAA0E7075672A
57 changed files with 303 additions and 70 deletions

9
changes/ticket31705 Normal file
View File

@ -0,0 +1,9 @@
o Minor features (developer tools):
- Add some scripts in "scripts/coccinelle" to invoke the Coccinelle
semantic patching tool with the correct flags. These flags are fairly
easy to forget, and these scripts should help us use Coccinelle more
effectively in the future. Closes ticket 31705.
o Code simplification and refactoring:
- Fix some parts of our code that were difficult for Coccinelle to parse.
Related to ticket 31705.

9
scripts/coccinelle/apply.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
# apply.sh:
# run spatch with appropriate includes and builtins for the Tor source code
top="$(dirname "$0")/../.."
spatch -macro_file_builtins "$top"/scripts/coccinelle/tor-coccinelle.h \
-I "$top" -I "$top"/src -I "$top"/ext --defined COCCI "$@"

View File

@ -1,4 +1,17 @@
#!/usr/bin/perl -w -p -i #!/usr/bin/perl -w -p -i
#
# Copyright (c) 2001 Matej Pfajfar.
# Copyright (c) 2001-2004, Roger Dingledine.
# Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
# Copyright (c) 2007-2019, The Tor Project, Inc.
# See LICENSE for licensing information
# This script looks for instances of C comparison operators as macro arguments,
# and replaces them with our OP_* equivalents.
#
# Some macros that take operators are our tt_int_op() testing macro, and the
# standard timercmp() macro. Coccinelle can't handle their syntax, however,
# unless we give them their operators as a macro too.
next if m#^ */\*# or m#^ *\* #; next if m#^ */\*# or m#^ *\* #;

View File

@ -1,3 +1,63 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2019, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/*
* This file looks like a C header, but its purpose is a bit different.
*
* We never include it from our real C files; we only tell Coccinelle
* about it in apply.sh.
*
* It tells the Coccinelle semantic patching tool how to understand
* things that would otherwise not be good C syntax, or which would
* otherwise not make sense to it as C. It doesn't need to produce
* semantically equivalent C, or even correct C: it only has to produce
* syntactically valid C.
*/
#define MOCK_DECL(a, b, c) a b c
#define MOCK_IMPL(a, b, c) a b c #define MOCK_IMPL(a, b, c) a b c
#define CHECK_PRINTF(a, b) #define CHECK_PRINTF(a, b)
#define CHECK_SCANF(a, b)
#define STATIC static #define STATIC static
#define EXTERN(a,b) extern a b;
#define STMT_BEGIN do {
#define STMT_END } while (0)
#define BUG(x) (x)
#define IF_BUG_ONCE(x) if (x)
#define ATTR_NORETURN
#define ATTR_UNUSED
#define ATTR_CONST
#define ATTR_MALLOC
#define ATTR_WUR
#define DISABLE_GCC_WARNING(x)
#define ENABLE_GCC_WARNING(x)
#define HANDLE_DECL(a,b,c)
#define HANDLE_IMPL(a,b,c)
#define HT_ENTRY(x) void *
#define HT_HEAD(a,b) struct ht_head
#define HT_INITIALIZER() { }
#define X509 struct x509_st
#define STACK_OF(x) struct foo_stack_t
#define TOR_TAILQ_HEAD(a,b) struct tailq_head
#define TOR_TAILQ_ENTRY(a) struct tailq_entry
#define TOR_SIMPLEQ_HEAD(a,b) struct simpleq_entry
#define TOR_SIMPLEQ_ENTRY(a) struct simpleq_entry
#define TOR_LIST_HEAD(a,b) struct list_head
#define TOR_LIST_ENTRY(a) struct list_entry
#define TOR_SLIST_HEAD(a,b) struct slist_head
#define TOR_SLIST_ENTRY(a) struct slist_entry
#define NS_DECL(a, b, c) a b c
#define NS(a) a
#define CONF_TEST_MEMBERS(a,b,c)
#define DUMMY_CONF_TEST_MEMBERS
#define EAT_SEMICOLON extern int dummy__;

29
scripts/coccinelle/try_parse.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
# Echo the name of every argument of this script that is not "perfect"
# according to coccinelle's --parse-c.
top="$(dirname "$0")/../.."
exitcode=0
for fn in "$@"; do
if spatch -macro_file_builtins "$top"/scripts/coccinelle/tor-coccinelle.h \
-I "$top" -I "$top"/src -I "$top"/ext --defined COCCI \
--parse-c "$fn" \
2>/dev/null | grep "perfect = 1" > /dev/null; then
: # it's perfect
else
echo "$fn"
if test "${VERBOSE}" != ""; then
spatch -macro_file_builtins "$top"/scripts/coccinelle/tor-coccinelle.h \
-I "$top" -I "$top"/src -I "$top"/ext --defined COCCI \
--parse-c "$fn"
fi
exitcode=1
fi
done
exit "$exitcode"

View File

@ -186,8 +186,12 @@ static const char unix_q_socket_prefix[] = "unix:\"";
/** macro to help with the bulk rename of *DownloadSchedule to /** macro to help with the bulk rename of *DownloadSchedule to
* *DowloadInitialDelay . */ * *DowloadInitialDelay . */
#ifndef COCCI
#define DOWNLOAD_SCHEDULE(name) \ #define DOWNLOAD_SCHEDULE(name) \
{ #name "DownloadSchedule", #name "DownloadInitialDelay", 0, 1 } { #name "DownloadSchedule", #name "DownloadInitialDelay", 0, 1 }
#else
#define DOWNLOAD_SCHEDULE(name) { NULL, NULL, 0, 1 }
#endif /* !defined(COCCI) */
/** A list of abbreviations and aliases to map command-line options, obsolete /** A list of abbreviations and aliases to map command-line options, obsolete
* option names, or alternative option names, to their current values. */ * option names, or alternative option names, to their current values. */
@ -765,7 +769,9 @@ static const config_var_t option_vars_[] = {
/** List of default directory authorities */ /** List of default directory authorities */
static const char *default_authorities[] = { static const char *default_authorities[] = {
#ifndef COCCI
#include "auth_dirs.inc" #include "auth_dirs.inc"
#endif
NULL NULL
}; };
@ -773,7 +779,9 @@ static const char *default_authorities[] = {
* relays that meet certain stability criteria. * relays that meet certain stability criteria.
*/ */
static const char *default_fallbacks[] = { static const char *default_fallbacks[] = {
#ifndef COCCI
#include "fallback_dirs.inc" #include "fallback_dirs.inc"
#endif
NULL NULL
}; };
@ -783,7 +791,9 @@ static const struct {
const char *k; const char *k;
const char *v; const char *v;
} testing_tor_network_defaults[] = { } testing_tor_network_defaults[] = {
#ifndef COCCI
#include "testnet.inc" #include "testnet.inc"
#endif
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -1349,9 +1349,11 @@ get_signewnym_epoch(void)
static int periodic_events_initialized = 0; static int periodic_events_initialized = 0;
/* Declare all the timer callback functions... */ /* Declare all the timer callback functions... */
#ifndef COCCI
#undef CALLBACK #undef CALLBACK
#define CALLBACK(name) \ #define CALLBACK(name) \
static int name ## _callback(time_t, const or_options_t *) static int name ## _callback(time_t, const or_options_t *)
CALLBACK(add_entropy); CALLBACK(add_entropy);
CALLBACK(check_expired_networkstatus); CALLBACK(check_expired_networkstatus);
CALLBACK(clean_caches); CALLBACK(clean_caches);
@ -1374,9 +1376,10 @@ CALLBACK(second_elapsed);
#undef CALLBACK #undef CALLBACK
/* Now we declare an array of periodic_event_item_t for each periodic event */ /* Now we declare an array of periodic_event_item_t for each periodic event */
#define CALLBACK(name, r, f) \ #define CALLBACK(name, r, f) \
PERIODIC_EVENT(name, PERIODIC_EVENT_ROLE_ ## r, f) PERIODIC_EVENT(name, PERIODIC_EVENT_ROLE_ ## r, f)
#define FL(name) (PERIODIC_EVENT_FLAG_ ## name) #define FL(name) (PERIODIC_EVENT_FLAG_ ## name)
#endif /* !defined(COCCI) */
STATIC periodic_event_item_t mainloop_periodic_events[] = { STATIC periodic_event_item_t mainloop_periodic_events[] = {
@ -1427,8 +1430,10 @@ STATIC periodic_event_item_t mainloop_periodic_events[] = {
END_OF_PERIODIC_EVENTS END_OF_PERIODIC_EVENTS
}; };
#ifndef COCCI
#undef CALLBACK #undef CALLBACK
#undef FL #undef FL
#endif
/* These are pointers to members of periodic_events[] that are used to /* These are pointers to members of periodic_events[] that are used to
* implement particular callbacks. We keep them separate here so that we * implement particular callbacks. We keep them separate here so that we
@ -1527,8 +1532,10 @@ initialize_periodic_events(void)
/* Set up all periodic events. We'll launch them by roles. */ /* Set up all periodic events. We'll launch them by roles. */
#ifndef COCCI
#define NAMED_CALLBACK(name) \ #define NAMED_CALLBACK(name) \
STMT_BEGIN name ## _event = periodic_events_find( #name ); STMT_END STMT_BEGIN name ## _event = periodic_events_find( #name ); STMT_END
#endif
NAMED_CALLBACK(prune_old_routers); NAMED_CALLBACK(prune_old_routers);
NAMED_CALLBACK(fetch_networkstatus); NAMED_CALLBACK(fetch_networkstatus);

View File

@ -71,8 +71,10 @@ typedef struct periodic_event_item_t {
} periodic_event_item_t; } periodic_event_item_t;
/** events will get their interval from first execution */ /** events will get their interval from first execution */
#ifndef COCCI
#define PERIODIC_EVENT(fn, r, f) { fn##_callback, 0, NULL, #fn, r, f, 0 } #define PERIODIC_EVENT(fn, r, f) { fn##_callback, 0, NULL, #fn, r, f, 0 }
#define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL, 0, 0, 0 } #define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL, 0, 0, 0 }
#endif
/* Return true iff the given event was setup before thus is enabled to be /* Return true iff the given event was setup before thus is enabled to be
* scheduled. */ * scheduled. */

View File

@ -116,6 +116,7 @@ STATIC smartlist_t *origin_padding_machines = NULL;
* runtime and as long as circuits are alive. */ * runtime and as long as circuits are alive. */
STATIC smartlist_t *relay_padding_machines = NULL; STATIC smartlist_t *relay_padding_machines = NULL;
#ifndef COCCI
/** Loop over the current padding state machines using <b>loop_var</b> as the /** Loop over the current padding state machines using <b>loop_var</b> as the
* loop variable. */ * loop variable. */
#define FOR_EACH_CIRCUIT_MACHINE_BEGIN(loop_var) \ #define FOR_EACH_CIRCUIT_MACHINE_BEGIN(loop_var) \
@ -130,6 +131,7 @@ STATIC smartlist_t *relay_padding_machines = NULL;
if (!(circ)->padding_info[loop_var]) \ if (!(circ)->padding_info[loop_var]) \
continue; continue;
#define FOR_EACH_ACTIVE_CIRCUIT_MACHINE_END } STMT_END ; #define FOR_EACH_ACTIVE_CIRCUIT_MACHINE_END } STMT_END ;
#endif /* !defined(COCCI) */
/** /**
* Free the machineinfo at an index * Free the machineinfo at an index

View File

@ -20,11 +20,13 @@
#include "feature/relay/routermode.h" #include "feature/relay/routermode.h"
#ifndef COCCI
#define DECLARE_EVENT(name, roles, flags) \ #define DECLARE_EVENT(name, roles, flags) \
static periodic_event_item_t name ## _event = \ static periodic_event_item_t name ## _event = \
PERIODIC_EVENT(name, \ PERIODIC_EVENT(name, \
PERIODIC_EVENT_ROLE_##roles, \ PERIODIC_EVENT_ROLE_##roles, \
flags) flags)
#endif /* !defined(COCCI) */
#define FL(name) (PERIODIC_EVENT_FLAG_ ## name) #define FL(name) (PERIODIC_EVENT_FLAG_ ## name)

View File

@ -14,4 +14,4 @@
int proxy_mode(const or_options_t *options); int proxy_mode(const or_options_t *options);
#endif #endif /* !defined(TOR_PROXYMODE_H) */

View File

@ -2248,6 +2248,7 @@ typedef struct control_cmd_def_t {
*/ */
#define CMD_FL_WIPE (1u<<0) #define CMD_FL_WIPE (1u<<0)
#ifndef COCCI
/** Macro: declare a command with a one-line argument, a given set of flags, /** Macro: declare a command with a one-line argument, a given set of flags,
* and a syntax definition. * and a syntax definition.
**/ **/
@ -2280,6 +2281,7 @@ typedef struct control_cmd_def_t {
0, \ 0, \
&obsolete_syntax, \ &obsolete_syntax, \
} }
#endif /* !defined(COCCI) */
/** /**
* An array defining all the recognized controller commands. * An array defining all the recognized controller commands.

View File

@ -1663,6 +1663,7 @@ control_event_status(int type, int severity, const char *format, va_list args)
return 0; return 0;
} }
#ifndef COCCI
#define CONTROL_EVENT_STATUS_BODY(event, sev) \ #define CONTROL_EVENT_STATUS_BODY(event, sev) \
int r; \ int r; \
do { \ do { \
@ -1674,6 +1675,7 @@ control_event_status(int type, int severity, const char *format, va_list args)
r = control_event_status((event), (sev), format, ap); \ r = control_event_status((event), (sev), format, ap); \
va_end(ap); \ va_end(ap); \
} while (0) } while (0)
#endif /* !defined(COCCI) */
/** Format and send an EVENT_STATUS_GENERAL event whose main text is obtained /** Format and send an EVENT_STATUS_GENERAL event whose main text is obtained
* by formatting the arguments using the printf-style <b>format</b>. */ * by formatting the arguments using the printf-style <b>format</b>. */

View File

@ -18,11 +18,13 @@
#include "core/mainloop/periodic.h" #include "core/mainloop/periodic.h"
#ifndef COCCI
#define DECLARE_EVENT(name, roles, flags) \ #define DECLARE_EVENT(name, roles, flags) \
static periodic_event_item_t name ## _event = \ static periodic_event_item_t name ## _event = \
PERIODIC_EVENT(name, \ PERIODIC_EVENT(name, \
PERIODIC_EVENT_ROLE_##roles, \ PERIODIC_EVENT_ROLE_##roles, \
flags) flags)
#endif /* !defined(COCCI) */
#define FL(name) (PERIODIC_EVENT_FLAG_##name) #define FL(name) (PERIODIC_EVENT_FLAG_##name)

View File

@ -530,10 +530,12 @@ typedef struct router_id_iterator_t {
cdline_t hash; cdline_t hash;
} router_id_iterator_t; } router_id_iterator_t;
#ifndef COCCI
/** /**
* Initializer for a router_id_iterator_t. * Initializer for a router_id_iterator_t.
*/ */
#define ROUTER_ID_ITERATOR_INIT { { NULL, 0 }, { NULL, 0 } } #define ROUTER_ID_ITERATOR_INIT { { NULL, 0 }, { NULL, 0 } }
#endif /* !defined(COCCI) */
/** Given an index *<b>idxp</b> into the consensus at <b>cons</b>, advance /** Given an index *<b>idxp</b> into the consensus at <b>cons</b>, advance
* the index to the next router line ("r ...") in the consensus, or to * the index to the next router line ("r ...") in the consensus, or to

View File

@ -26,4 +26,4 @@
NO_ARGS, NEED_OBJ),\ NO_ARGS, NEED_OBJ),\
T01("dir-address", K_DIR_ADDRESS, GE(1), NO_OBJ) T01("dir-address", K_DIR_ADDRESS, GE(1), NO_OBJ)
#endif #endif /* !defined(TOR_AUTHCERT_MEMBERS_H) */

View File

@ -67,6 +67,7 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifndef COCCI
/** Helper macro. Iterate over every service in the global map. The var is the /** Helper macro. Iterate over every service in the global map. The var is the
* name of the service pointer. */ * name of the service pointer. */
#define FOR_EACH_SERVICE_BEGIN(var) \ #define FOR_EACH_SERVICE_BEGIN(var) \
@ -88,6 +89,7 @@
(var = service->desc_next); \ (var = service->desc_next); \
if (var == NULL) continue; if (var == NULL) continue;
#define FOR_EACH_DESCRIPTOR_END } STMT_END ; #define FOR_EACH_DESCRIPTOR_END } STMT_END ;
#endif /* !defined(COCCI) */
/* Onion service directory file names. */ /* Onion service directory file names. */
static const char fname_keyfile_prefix[] = "hs_ed25519"; static const char fname_keyfile_prefix[] = "hs_ed25519";

View File

@ -31,11 +31,13 @@
#include "feature/nodelist/routerinfo_st.h" #include "feature/nodelist/routerinfo_st.h"
#include "feature/control/control_events.h" #include "feature/control/control_events.h"
#ifndef COCCI
#define DECLARE_EVENT(name, roles, flags) \ #define DECLARE_EVENT(name, roles, flags) \
static periodic_event_item_t name ## _event = \ static periodic_event_item_t name ## _event = \
PERIODIC_EVENT(name, \ PERIODIC_EVENT(name, \
PERIODIC_EVENT_ROLE_##roles, \ PERIODIC_EVENT_ROLE_##roles, \
flags) flags)
#endif /* !defined(COCCI) */
#define FL(name) (PERIODIC_EVENT_FLAG_##name) #define FL(name) (PERIODIC_EVENT_FLAG_##name)

View File

@ -386,7 +386,7 @@ get_server_identity_key,(void))
return server_identitykey; return server_identitykey;
} }
#endif #endif /* defined(HAVE_MODULE_RELAY) */
/** Return true iff we are a server and the server identity key /** Return true iff we are a server and the server identity key
* has been set. */ * has been set. */

View File

@ -25,7 +25,7 @@ void set_server_advertised(int s);
/** Is the relay module enabled? */ /** Is the relay module enabled? */
#define have_module_relay() (1) #define have_module_relay() (1)
#else #else /* !defined(HAVE_MODULE_RELAY) */
#define dir_server_mode(options) (((void)(options)),0) #define dir_server_mode(options) (((void)(options)),0)
#define server_mode(options) (((void)(options)),0) #define server_mode(options) (((void)(options)),0)
@ -37,6 +37,6 @@ void set_server_advertised(int s);
#define have_module_relay() (0) #define have_module_relay() (0)
#endif #endif /* defined(HAVE_MODULE_RELAY) */
#endif /* !defined(TOR_ROUTERMODE_H) */ #endif /* !defined(TOR_ROUTERMODE_H) */

View File

@ -99,6 +99,7 @@
#define DBG_S(s) (void)0 #define DBG_S(s) (void)0
#endif #endif
#ifndef COCCI
#ifdef DISABLE_MEMORY_SENTINELS #ifdef DISABLE_MEMORY_SENTINELS
#define CHUNK_SET_SENTINEL(chunk, alloclen) STMT_NIL #define CHUNK_SET_SENTINEL(chunk, alloclen) STMT_NIL
#else #else
@ -109,6 +110,7 @@
memset(a,0,SENTINEL_LEN); \ memset(a,0,SENTINEL_LEN); \
} while (0) } while (0)
#endif /* defined(DISABLE_MEMORY_SENTINELS) */ #endif /* defined(DISABLE_MEMORY_SENTINELS) */
#endif /* !defined(COCCI) */
/** Move all bytes stored in <b>chunk</b> to the front of <b>chunk</b>->mem, /** Move all bytes stored in <b>chunk</b> to the front of <b>chunk</b>->mem,
* to free up space at the end. */ * to free up space at the end. */

View File

@ -46,7 +46,7 @@
#define CTASSERT_EXPN(x, a, b) CTASSERT_DECL(x, a, b) #define CTASSERT_EXPN(x, a, b) CTASSERT_DECL(x, a, b)
#define CTASSERT_DECL(x, a, b) \ #define CTASSERT_DECL(x, a, b) \
typedef char tor_ctassert_##a##_##b[(x) ? 1 : -1] ATTR_UNUSED typedef char tor_ctassert_##a##_##b[(x) ? 1 : -1] ATTR_UNUSED; EAT_SEMICOLON
#endif /* __STDC_VERSION__ >= 201112L */ #endif /* __STDC_VERSION__ >= 201112L */

View File

@ -15,11 +15,13 @@
#include "orconfig.h" #include "orconfig.h"
#include "lib/conf/conftesting.h" #include "lib/conf/conftesting.h"
#ifndef COCCI
/** /**
* Used to indicate the end of an array of configuration variables. * Used to indicate the end of an array of configuration variables.
**/ **/
#define END_OF_CONFIG_VARS \ #define END_OF_CONFIG_VARS \
{ .member = { .name = NULL } DUMMY_CONF_TEST_MEMBERS } { .member = { .name = NULL } DUMMY_CONF_TEST_MEMBERS }
#endif /* !defined(COCCI) */
/** /**
* Declare a config_var_t as a member named <b>membername</b> of the structure * Declare a config_var_t as a member named <b>membername</b> of the structure

View File

@ -12,7 +12,9 @@
#ifndef TOR_LIB_CONF_CONFTESTING_H #ifndef TOR_LIB_CONF_CONFTESTING_H
#define TOR_LIB_CONF_CONFTESTING_H #define TOR_LIB_CONF_CONFTESTING_H
#ifndef COCCI
#ifdef TOR_UNIT_TESTS #ifdef TOR_UNIT_TESTS
#define USE_CONF_TESTING
/** /**
* Union used when building in test mode typechecking the members of a type * Union used when building in test mode typechecking the members of a type
* used with confparse.c. See CONF_CHECK_VAR_TYPE for a description of how * used with confparse.c. See CONF_CHECK_VAR_TYPE for a description of how
@ -41,12 +43,10 @@ typedef union {
// XXXX this doesn't belong at this level of abstraction. // XXXX this doesn't belong at this level of abstraction.
struct routerset_t **ROUTERSET; struct routerset_t **ROUTERSET;
} confparse_dummy_values_t; } confparse_dummy_values_t;
#endif /* defined(TOR_UNIT_TESTS) */
/* Macros to define extra members inside config_var_t fields, and at the /* Macros to define extra members inside config_var_t fields, and at the
* end of a list of them. * end of a list of them.
*/ */
#ifdef TOR_UNIT_TESTS
/* This is a somewhat magic type-checking macro for users of confparse.c. /* This is a somewhat magic type-checking macro for users of confparse.c.
* It initializes a union member "confparse_dummy_values_t.conftype" with * It initializes a union member "confparse_dummy_values_t.conftype" with
* the address of a static member "tp_dummy.member". This * the address of a static member "tp_dummy.member". This
@ -72,15 +72,16 @@ typedef union {
#define DUMMY_CONF_TEST_MEMBERS , .var_ptr_dummy={ .INT=NULL } #define DUMMY_CONF_TEST_MEMBERS , .var_ptr_dummy={ .INT=NULL }
#define DUMMY_TYPECHECK_INSTANCE(tp) \ #define DUMMY_TYPECHECK_INSTANCE(tp) \
static tp tp ## _dummy static tp tp ## _dummy
#endif /* defined(TOR_UNIT_TESTS) */
#endif /* !defined(COCCI) */
#else /* !defined(TOR_UNIT_TESTS) */ #ifndef USE_CONF_TESTING
#define CONF_TEST_MEMBERS(tp, conftype, member) #define CONF_TEST_MEMBERS(tp, conftype, member)
/* Repeatedly declarable incomplete struct to absorb redundant semicolons */ /* Repeatedly declarable incomplete struct to absorb redundant semicolons */
#define DUMMY_TYPECHECK_INSTANCE(tp) \ #define DUMMY_TYPECHECK_INSTANCE(tp) \
struct tor_semicolon_eater struct tor_semicolon_eater
#define DUMMY_CONF_TEST_MEMBERS #define DUMMY_CONF_TEST_MEMBERS
#endif /* defined(TOR_UNIT_TESTS) */ #endif /* !defined(USE_CONF_TESTING) */
#endif /* !defined(TOR_LIB_CONF_CONFTESTING_H) */ #endif /* !defined(TOR_LIB_CONF_CONFTESTING_H) */

View File

@ -28,7 +28,9 @@ struct namemap_t {
struct smartlist_t *names; struct smartlist_t *names;
}; };
#ifndef COCCI
/** Macro to initialize a namemap. */ /** Macro to initialize a namemap. */
#define NAMEMAP_INIT() { HT_INITIALIZER(), NULL } #define NAMEMAP_INIT() { HT_INITIALIZER(), NULL }
#endif
#endif /* !defined(NAMEMAP_ST_H) */ #endif /* !defined(NAMEMAP_ST_H) */

View File

@ -92,6 +92,7 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
size_t join_len, int terminate, size_t *len_out) size_t join_len, int terminate, size_t *len_out)
ATTR_MALLOC; ATTR_MALLOC;
#ifndef COCCI
/* Helper: Given two lists of items, possibly of different types, such that /* Helper: Given two lists of items, possibly of different types, such that
* both lists are sorted on some common field (as determined by a comparison * both lists are sorted on some common field (as determined by a comparison
* expression <b>cmpexpr</b>), and such that one list (<b>sl1</b>) has no * expression <b>cmpexpr</b>), and such that one list (<b>sl1</b>) has no
@ -165,5 +166,6 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
#define SMARTLIST_FOREACH_JOIN_END(var1, var2) \ #define SMARTLIST_FOREACH_JOIN_END(var1, var2) \
} \ } \
STMT_END STMT_END
#endif /* !defined(COCCI) */
#endif /* !defined(TOR_SMARTLIST_H) */ #endif /* !defined(TOR_SMARTLIST_H) */

View File

@ -121,10 +121,12 @@ crypto_openssl_get_header_version_str(void)
return crypto_openssl_header_version_str; return crypto_openssl_header_version_str;
} }
#ifndef COCCI
#ifndef OPENSSL_THREADS #ifndef OPENSSL_THREADS
#error OpenSSL has been built without thread support. Tor requires an \ #error "OpenSSL has been built without thread support. Tor requires an \
OpenSSL library with thread support enabled. OpenSSL library with thread support enabled."
#endif #endif
#endif /* !defined(COCCI) */
#ifndef NEW_THREAD_API #ifndef NEW_THREAD_API
/** Helper: OpenSSL uses this callback to manipulate mutexes. */ /** Helper: OpenSSL uses this callback to manipulate mutexes. */

View File

@ -33,6 +33,7 @@ dispatch_naming_init(void)
{ {
} }
#ifndef COCCI
/* Helper macro: declare functions to map IDs to and from names for a given /* Helper macro: declare functions to map IDs to and from names for a given
* type in a namemap_t. * type in a namemap_t.
*/ */
@ -56,6 +57,7 @@ dispatch_naming_init(void)
return namemap_get_size(&type##_id_map); \ return namemap_get_size(&type##_id_map); \
} \ } \
EAT_SEMICOLON EAT_SEMICOLON
#endif /* !defined(COCCI) */
DECLARE_ID_MAP_FNS(message); DECLARE_ID_MAP_FNS(message);
DECLARE_ID_MAP_FNS(channel); DECLARE_ID_MAP_FNS(channel);

View File

@ -56,13 +56,15 @@ struct timeout_cb {
/* /*
* These definitions are for timeouts.c and timeouts.h. * These definitions are for timeouts.c and timeouts.h.
*/ */
#ifdef __GNUC__ #ifdef COCCI
#define TIMEOUT_PUBLIC
#elif defined(__GNUC__)
/* We're not exposing any of the functions outside this file. */ /* We're not exposing any of the functions outside this file. */
#define TIMEOUT_PUBLIC __attribute__((__unused__)) static #define TIMEOUT_PUBLIC __attribute__((__unused__)) static
#else #else
/* We're not exposing any of the functions outside this file. */ /* We're not exposing any of the functions outside this file. */
#define TIMEOUT_PUBLIC static #define TIMEOUT_PUBLIC static
#endif /* defined(__GNUC__) */ #endif /* defined(COCCI) || ... */
/* We're not using periodic events. */ /* We're not using periodic events. */
#define TIMEOUT_DISABLE_INTERVALS #define TIMEOUT_DISABLE_INTERVALS
/* We always know the global_timeouts object, so we don't need each timeout /* We always know the global_timeouts object, so we don't need each timeout

View File

@ -19,8 +19,11 @@ typedef struct tor_weak_rng_t {
uint32_t state; uint32_t state;
} tor_weak_rng_t; } tor_weak_rng_t;
#ifndef COCCI
#define TOR_WEAK_RNG_INIT {383745623} #define TOR_WEAK_RNG_INIT {383745623}
#endif
#define TOR_WEAK_RANDOM_MAX (INT_MAX) #define TOR_WEAK_RANDOM_MAX (INT_MAX)
void tor_init_weak_random(tor_weak_rng_t *weak_rng, unsigned seed); void tor_init_weak_random(tor_weak_rng_t *weak_rng, unsigned seed);
int32_t tor_weak_random(tor_weak_rng_t *weak_rng); int32_t tor_weak_random(tor_weak_rng_t *weak_rng);
int32_t tor_weak_random_range(tor_weak_rng_t *rng, int32_t top); int32_t tor_weak_random_range(tor_weak_rng_t *rng, int32_t top);

View File

@ -523,7 +523,7 @@ logfile_deliver(logfile_t *lf, const char *buf, size_t msg_len,
* pass them, and some very old ones do not detect overflow so well. * pass them, and some very old ones do not detect overflow so well.
* Regrettably, they call their maximum line length MAXLINE. */ * Regrettably, they call their maximum line length MAXLINE. */
#if MAXLINE < 64 #if MAXLINE < 64
#warn "MAXLINE is a very low number; it might not be from syslog.h after all" #warning "MAXLINE is a very low number; it might not be from syslog.h."
#endif #endif
char *m = msg_after_prefix; char *m = msg_after_prefix;
if (msg_len >= MAXLINE) if (msg_len >= MAXLINE)

View File

@ -23,9 +23,11 @@
#include <syslog.h> #include <syslog.h>
#define LOG_WARN LOG_WARNING #define LOG_WARN LOG_WARNING
#if LOG_DEBUG < LOG_ERR #if LOG_DEBUG < LOG_ERR
#ifndef COCCI
#error "Your syslog.h thinks high numbers are more important. " \ #error "Your syslog.h thinks high numbers are more important. " \
"We aren't prepared to deal with that." "We aren't prepared to deal with that."
#endif #endif
#endif /* LOG_DEBUG < LOG_ERR */
#else /* !defined(HAVE_SYSLOG_H) */ #else /* !defined(HAVE_SYSLOG_H) */
/* Note: Syslog's logging code refers to priorities, with 0 being the most /* Note: Syslog's logging code refers to priorities, with 0 being the most
* important. Thus, all our comparisons needed to be reversed when we added * important. Thus, all our comparisons needed to be reversed when we added
@ -308,7 +310,7 @@ MOCK_DECL(STATIC void, logv, (int severity, log_domain_mask_t domain,
va_list ap) CHECK_PRINTF(5,0)); va_list ap) CHECK_PRINTF(5,0));
MOCK_DECL(STATIC void, add_stream_log_impl,( MOCK_DECL(STATIC void, add_stream_log_impl,(
const log_severity_list_t *severity, const char *name, int fd)); const log_severity_list_t *severity, const char *name, int fd));
#endif #endif /* defined(LOG_PRIVATE) */
#if defined(LOG_PRIVATE) || defined(TOR_UNIT_TESTS) #if defined(LOG_PRIVATE) || defined(TOR_UNIT_TESTS)
/** Given a severity, yields an index into log_severity_list_t.masks to use /** Given a severity, yields an index into log_severity_list_t.masks to use

View File

@ -45,7 +45,9 @@ typedef struct ratelim_t {
int n_calls_since_last_time; int n_calls_since_last_time;
} ratelim_t; } ratelim_t;
#ifndef COCCI
#define RATELIM_INIT(r) { (r), 0, 0 } #define RATELIM_INIT(r) { (r), 0, 0 }
#endif
#define RATELIM_TOOMANY (16*1000*1000) #define RATELIM_TOOMANY (16*1000*1000)
char *rate_limit_log(ratelim_t *lim, time_t now); char *rate_limit_log(ratelim_t *lim, time_t now);

View File

@ -131,7 +131,9 @@
#undef BUG #undef BUG
// Coverity defines this in global headers; let's override it. This is a // Coverity defines this in global headers; let's override it. This is a
// magic coverity-only preprocessor thing. // magic coverity-only preprocessor thing.
#ifndef COCCI
#nodef BUG(x) (x) #nodef BUG(x) (x)
#endif
#endif /* defined(__COVERITY__) */ #endif /* defined(__COVERITY__) */
#if defined(__COVERITY__) || defined(__clang_analyzer__) #if defined(__COVERITY__) || defined(__clang_analyzer__)
@ -200,6 +202,7 @@
: 0) : 0)
#endif /* defined(ALL_BUGS_ARE_FATAL) || ... */ #endif /* defined(ALL_BUGS_ARE_FATAL) || ... */
#ifndef COCCI
#ifdef __GNUC__ #ifdef __GNUC__
#define IF_BUG_ONCE__(cond,var) \ #define IF_BUG_ONCE__(cond,var) \
if (( { \ if (( { \
@ -208,7 +211,7 @@
if (bool_result && !var) { \ if (bool_result && !var) { \
var = 1; \ var = 1; \
tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, \ tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, \
"!("#cond")", 1, NULL); \ ("!("#cond")"), 1, NULL); \
} \ } \
bool_result; } )) bool_result; } ))
#else /* !defined(__GNUC__) */ #else /* !defined(__GNUC__) */
@ -218,10 +221,12 @@
(var ? 1 : \ (var ? 1 : \
(var=1, \ (var=1, \
tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, \ tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, \
"!("#cond")", 1, NULL), \ ("!("#cond")"), 1, NULL), \
1)) \ 1)) \
: 0) : 0)
#endif /* defined(__GNUC__) */ #endif /* defined(__GNUC__) */
#endif /* !defined(COCCI) */
#define IF_BUG_ONCE_VARNAME_(a) \ #define IF_BUG_ONCE_VARNAME_(a) \
warning_logged_on_ ## a ## __ warning_logged_on_ ## a ## __
#define IF_BUG_ONCE_VARNAME__(a) \ #define IF_BUG_ONCE_VARNAME__(a) \

View File

@ -78,8 +78,8 @@
#endif /* defined(HAVE_MINHERIT) || ... */ #endif /* defined(HAVE_MINHERIT) || ... */
#if defined(HAVE_MINHERIT) && !defined(FLAG_ZERO) && !defined(FLAG_NOINHERIT) #if defined(HAVE_MINHERIT) && !defined(FLAG_ZERO) && !defined(FLAG_NOINHERIT)
#warn "minherit() is defined, but we couldn't find the right flag for it." #warning "minherit() is defined, but we couldn't find the right flag for it."
#warn "This is probably a bug in Tor's support for this platform." #warning "This is probably a bug in Tor's support for this platform."
#endif #endif
/** /**

View File

@ -1392,7 +1392,7 @@ get_interface_addresses_win32(int severity, sa_family_t family)
/* This is defined on Mac OS X */ /* This is defined on Mac OS X */
#ifndef _SIZEOF_ADDR_IFREQ #ifndef _SIZEOF_ADDR_IFREQ
#define _SIZEOF_ADDR_IFREQ sizeof #define _SIZEOF_ADDR_IFREQ(x) sizeof(x)
#endif #endif
/* Free ifc->ifc_buf safely. */ /* Free ifc->ifc_buf safely. */

View File

@ -9,6 +9,7 @@
**/ **/
#include "lib/string/parse_int.h" #include "lib/string/parse_int.h"
#include "lib/cc/compat_compiler.h"
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
@ -17,6 +18,7 @@
/* Helper: common code to check whether the result of a strtol or strtoul or /* Helper: common code to check whether the result of a strtol or strtoul or
* strtoll is correct. */ * strtoll is correct. */
#define CHECK_STRTOX_RESULT() \ #define CHECK_STRTOX_RESULT() \
STMT_BEGIN \
/* Did an overflow occur? */ \ /* Did an overflow occur? */ \
if (errno == ERANGE) \ if (errno == ERANGE) \
goto err; \ goto err; \
@ -38,7 +40,8 @@
err: \ err: \
if (ok) *ok = 0; \ if (ok) *ok = 0; \
if (next) *next = endptr; \ if (next) *next = endptr; \
return 0 return 0; \
STMT_END
/** Extract a long from the start of <b>s</b>, in the given numeric /** Extract a long from the start of <b>s</b>, in the given numeric
* <b>base</b>. If <b>base</b> is 0, <b>s</b> is parsed as a decimal, * <b>base</b>. If <b>base</b> is 0, <b>s</b> is parsed as a decimal,

View File

@ -106,7 +106,9 @@ void tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value);
typedef struct atomic_counter_t { typedef struct atomic_counter_t {
atomic_size_t val; atomic_size_t val;
} atomic_counter_t; } atomic_counter_t;
#ifndef COCCI
#define ATOMIC_LINKAGE static #define ATOMIC_LINKAGE static
#endif
#else /* !defined(HAVE_WORKING_STDATOMIC) */ #else /* !defined(HAVE_WORKING_STDATOMIC) */
typedef struct atomic_counter_t { typedef struct atomic_counter_t {
tor_mutex_t mutex; tor_mutex_t mutex;

View File

@ -464,7 +464,9 @@ static const char UNRESTRICTED_SERVER_CIPHER_LIST[] =
/** List of ciphers that clients should advertise, omitting items that /** List of ciphers that clients should advertise, omitting items that
* our OpenSSL doesn't know about. */ * our OpenSSL doesn't know about. */
static const char CLIENT_CIPHER_LIST[] = static const char CLIENT_CIPHER_LIST[] =
#ifndef COCCI
#include "lib/tls/ciphers.inc" #include "lib/tls/ciphers.inc"
#endif
/* Tell it not to use SSLv2 ciphers, so that it can select an SSLv3 version /* Tell it not to use SSLv2 ciphers, so that it can select an SSLv3 version
* of any cipher we say. */ * of any cipher we say. */
"!SSLv2" "!SSLv2"

View File

@ -11,14 +11,18 @@
* src/core/include.am, and is usually right. * src/core/include.am, and is usually right.
*/ */
const char tor_git_revision[] = const char tor_git_revision[] =
#ifndef COCCI
#ifndef _MSC_VER #ifndef _MSC_VER
#include "micro-revision.i" #include "micro-revision.i"
#endif
#endif #endif
""; "";
const char tor_bug_suffix[] = " (on Tor " VERSION const char tor_bug_suffix[] = " (on Tor " VERSION
#ifndef COCCI
#ifndef _MSC_VER #ifndef _MSC_VER
" " " "
#include "micro-revision.i" #include "micro-revision.i"
#endif #endif
#endif /* !defined(COCCI) */
")"; ")";

View File

@ -69,6 +69,7 @@
} while (0) } while (0)
#endif /* !defined(timersub) */ #endif /* !defined(timersub) */
#ifndef COCCI
#ifndef timercmp #ifndef timercmp
/** Replacement for timercmp on platforms that do not have it: returns true /** Replacement for timercmp on platforms that do not have it: returns true
* iff the relational operator "op" makes the expression tv1 op tv2 true. * iff the relational operator "op" makes the expression tv1 op tv2 true.
@ -82,5 +83,6 @@
((tv1)->tv_usec op (tv2)->tv_usec) : \ ((tv1)->tv_usec op (tv2)->tv_usec) : \
((tv1)->tv_sec op (tv2)->tv_sec)) ((tv1)->tv_sec op (tv2)->tv_sec))
#endif /* !defined(timercmp) */ #endif /* !defined(timercmp) */
#endif /* !defined(COCCI) */
#endif /* !defined(TOR_TIMEVAL_H) */ #endif /* !defined(TOR_TIMEVAL_H) */

View File

@ -53,7 +53,7 @@ hs_helper_build_intro_point(const ed25519_keypair_t *signing_kp, time_t now,
} }
ret = ed25519_keypair_generate(&auth_kp, 0); ret = ed25519_keypair_generate(&auth_kp, 0);
tt_int_op(ret, ==, 0); tt_int_op(ret, OP_EQ, 0);
ip->auth_key_cert = tor_cert_create(signing_kp, CERT_TYPE_AUTH_HS_IP_KEY, ip->auth_key_cert = tor_cert_create(signing_kp, CERT_TYPE_AUTH_HS_IP_KEY,
&auth_kp.pubkey, now, &auth_kp.pubkey, now,
HS_DESC_CERT_LIFETIME, HS_DESC_CERT_LIFETIME,
@ -64,7 +64,7 @@ hs_helper_build_intro_point(const ed25519_keypair_t *signing_kp, time_t now,
ip->legacy.key = crypto_pk_new(); ip->legacy.key = crypto_pk_new();
tt_assert(ip->legacy.key); tt_assert(ip->legacy.key);
ret = crypto_pk_generate_key(ip->legacy.key); ret = crypto_pk_generate_key(ip->legacy.key);
tt_int_op(ret, ==, 0); tt_int_op(ret, OP_EQ, 0);
ssize_t cert_len = tor_make_rsa_ed25519_crosscert( ssize_t cert_len = tor_make_rsa_ed25519_crosscert(
&signing_kp->pubkey, ip->legacy.key, &signing_kp->pubkey, ip->legacy.key,
now + HS_DESC_CERT_LIFETIME, now + HS_DESC_CERT_LIFETIME,
@ -82,7 +82,7 @@ hs_helper_build_intro_point(const ed25519_keypair_t *signing_kp, time_t now,
tor_cert_t *cross_cert; tor_cert_t *cross_cert;
ret = curve25519_keypair_generate(&curve25519_kp, 0); ret = curve25519_keypair_generate(&curve25519_kp, 0);
tt_int_op(ret, ==, 0); tt_int_op(ret, OP_EQ, 0);
ed25519_keypair_from_curve25519_keypair(&ed25519_kp, &signbit, ed25519_keypair_from_curve25519_keypair(&ed25519_kp, &signbit,
&curve25519_kp); &curve25519_kp);
cross_cert = tor_cert_create(signing_kp, CERT_TYPE_CROSS_HS_IP_KEYS, cross_cert = tor_cert_create(signing_kp, CERT_TYPE_CROSS_HS_IP_KEYS,
@ -140,7 +140,7 @@ hs_helper_build_hs_desc_impl(unsigned int no_ip,
/* Setup superencrypted data section. */ /* Setup superencrypted data section. */
ret = curve25519_keypair_generate(&auth_ephemeral_kp, 0); ret = curve25519_keypair_generate(&auth_ephemeral_kp, 0);
tt_int_op(ret, ==, 0); tt_int_op(ret, OP_EQ, 0);
memcpy(&desc->superencrypted_data.auth_ephemeral_pubkey, memcpy(&desc->superencrypted_data.auth_ephemeral_pubkey,
&auth_ephemeral_kp.pubkey, &auth_ephemeral_kp.pubkey,
sizeof(curve25519_public_key_t)); sizeof(curve25519_public_key_t));
@ -224,7 +224,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1,
tt_mem_op(desc1->plaintext_data.blinded_pubkey.pubkey, OP_EQ, tt_mem_op(desc1->plaintext_data.blinded_pubkey.pubkey, OP_EQ,
desc2->plaintext_data.blinded_pubkey.pubkey, desc2->plaintext_data.blinded_pubkey.pubkey,
ED25519_PUBKEY_LEN); ED25519_PUBKEY_LEN);
tt_u64_op(desc1->plaintext_data.revision_counter, ==, tt_u64_op(desc1->plaintext_data.revision_counter, OP_EQ,
desc2->plaintext_data.revision_counter); desc2->plaintext_data.revision_counter);
/* NOTE: We can't compare the encrypted blob because when encoding the /* NOTE: We can't compare the encrypted blob because when encoding the
@ -241,7 +241,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1,
{ {
tt_assert(desc1->superencrypted_data.clients); tt_assert(desc1->superencrypted_data.clients);
tt_assert(desc2->superencrypted_data.clients); tt_assert(desc2->superencrypted_data.clients);
tt_int_op(smartlist_len(desc1->superencrypted_data.clients), ==, tt_int_op(smartlist_len(desc1->superencrypted_data.clients), OP_EQ,
smartlist_len(desc2->superencrypted_data.clients)); smartlist_len(desc2->superencrypted_data.clients));
for (int i=0; for (int i=0;
i < smartlist_len(desc1->superencrypted_data.clients); i < smartlist_len(desc1->superencrypted_data.clients);
@ -259,15 +259,15 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1,
} }
/* Encrypted data section. */ /* Encrypted data section. */
tt_uint_op(desc1->encrypted_data.create2_ntor, ==, tt_uint_op(desc1->encrypted_data.create2_ntor, OP_EQ,
desc2->encrypted_data.create2_ntor); desc2->encrypted_data.create2_ntor);
/* Authentication type. */ /* Authentication type. */
tt_int_op(!!desc1->encrypted_data.intro_auth_types, ==, tt_int_op(!!desc1->encrypted_data.intro_auth_types, OP_EQ,
!!desc2->encrypted_data.intro_auth_types); !!desc2->encrypted_data.intro_auth_types);
if (desc1->encrypted_data.intro_auth_types && if (desc1->encrypted_data.intro_auth_types &&
desc2->encrypted_data.intro_auth_types) { desc2->encrypted_data.intro_auth_types) {
tt_int_op(smartlist_len(desc1->encrypted_data.intro_auth_types), ==, tt_int_op(smartlist_len(desc1->encrypted_data.intro_auth_types), OP_EQ,
smartlist_len(desc2->encrypted_data.intro_auth_types)); smartlist_len(desc2->encrypted_data.intro_auth_types));
for (int i = 0; for (int i = 0;
i < smartlist_len(desc1->encrypted_data.intro_auth_types); i < smartlist_len(desc1->encrypted_data.intro_auth_types);
@ -281,7 +281,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1,
{ {
tt_assert(desc1->encrypted_data.intro_points); tt_assert(desc1->encrypted_data.intro_points);
tt_assert(desc2->encrypted_data.intro_points); tt_assert(desc2->encrypted_data.intro_points);
tt_int_op(smartlist_len(desc1->encrypted_data.intro_points), ==, tt_int_op(smartlist_len(desc1->encrypted_data.intro_points), OP_EQ,
smartlist_len(desc2->encrypted_data.intro_points)); smartlist_len(desc2->encrypted_data.intro_points));
for (int i=0; i < smartlist_len(desc1->encrypted_data.intro_points); i++) { for (int i=0; i < smartlist_len(desc1->encrypted_data.intro_points); i++) {
hs_desc_intro_point_t *ip1 = smartlist_get(desc1->encrypted_data hs_desc_intro_point_t *ip1 = smartlist_get(desc1->encrypted_data
@ -296,12 +296,12 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1,
tt_mem_op(&ip1->enc_key, OP_EQ, &ip2->enc_key, CURVE25519_PUBKEY_LEN); tt_mem_op(&ip1->enc_key, OP_EQ, &ip2->enc_key, CURVE25519_PUBKEY_LEN);
} }
tt_int_op(smartlist_len(ip1->link_specifiers), ==, tt_int_op(smartlist_len(ip1->link_specifiers), OP_EQ,
smartlist_len(ip2->link_specifiers)); smartlist_len(ip2->link_specifiers));
for (int j = 0; j < smartlist_len(ip1->link_specifiers); j++) { for (int j = 0; j < smartlist_len(ip1->link_specifiers); j++) {
link_specifier_t *ls1 = smartlist_get(ip1->link_specifiers, j), link_specifier_t *ls1 = smartlist_get(ip1->link_specifiers, j),
*ls2 = smartlist_get(ip2->link_specifiers, j); *ls2 = smartlist_get(ip2->link_specifiers, j);
tt_int_op(link_specifier_get_ls_type(ls1), ==, tt_int_op(link_specifier_get_ls_type(ls1), OP_EQ,
link_specifier_get_ls_type(ls2)); link_specifier_get_ls_type(ls2));
switch (link_specifier_get_ls_type(ls1)) { switch (link_specifier_get_ls_type(ls1)) {
case LS_IPV4: case LS_IPV4:
@ -311,7 +311,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1,
tt_int_op(addr1, OP_EQ, addr2); tt_int_op(addr1, OP_EQ, addr2);
uint16_t port1 = link_specifier_get_un_ipv4_port(ls1); uint16_t port1 = link_specifier_get_un_ipv4_port(ls1);
uint16_t port2 = link_specifier_get_un_ipv4_port(ls2); uint16_t port2 = link_specifier_get_un_ipv4_port(ls2);
tt_int_op(port1, ==, port2); tt_int_op(port1, OP_EQ, port2);
} }
break; break;
case LS_IPV6: case LS_IPV6:
@ -326,7 +326,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1,
link_specifier_getlen_un_ipv6_addr(ls1)); link_specifier_getlen_un_ipv6_addr(ls1));
uint16_t port1 = link_specifier_get_un_ipv6_port(ls1); uint16_t port1 = link_specifier_get_un_ipv6_port(ls1);
uint16_t port2 = link_specifier_get_un_ipv6_port(ls2); uint16_t port2 = link_specifier_get_un_ipv6_port(ls2);
tt_int_op(port1, ==, port2); tt_int_op(port1, OP_EQ, port2);
} }
break; break;
case LS_LEGACY_ID: case LS_LEGACY_ID:

View File

@ -37,6 +37,7 @@
#define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, OP_EQ, hex) #define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, OP_EQ, hex)
#ifndef COCCI
#define tt_double_op(a,op,b) \ #define tt_double_op(a,op,b) \
tt_assert_test_type(a,b,#a" "#op" "#b,double,(val1_ op val2_),"%g", \ tt_assert_test_type(a,b,#a" "#op" "#b,double,(val1_ op val2_),"%g", \
TT_EXIT_TEST_FUNCTION) TT_EXIT_TEST_FUNCTION)
@ -64,6 +65,7 @@
tt_assert_test_fmt_type(a,b,#a" "#op" "#b,int64_t,(val1_ op val2_), \ tt_assert_test_fmt_type(a,b,#a" "#op" "#b,int64_t,(val1_ op val2_), \
int64_t, "%"PRId64, \ int64_t, "%"PRId64, \
{print_ = (int64_t) value_;}, {}, TT_EXIT_TEST_FUNCTION) {print_ = (int64_t) value_;}, {}, TT_EXIT_TEST_FUNCTION)
#endif /* !defined(COCCI) */
/** /**
* Declare that the test is done, even though no tt___op() calls were made. * Declare that the test is done, even though no tt___op() calls were made.
@ -145,6 +147,7 @@ void free_pregenerated_keys(void);
#define NAME_TEST_(name) #name #define NAME_TEST_(name) #name
#define NAME_TEST(name) NAME_TEST_(name) #define NAME_TEST(name) NAME_TEST_(name)
#define ASPECT(test_module, test_name) US2_CONCAT_2__(test_module, test_name) #define ASPECT(test_module, test_name) US2_CONCAT_2__(test_module, test_name)
#ifndef COCCI
#define TEST_CASE(function) \ #define TEST_CASE(function) \
{ \ { \
NAME_TEST(function), \ NAME_TEST(function), \
@ -161,15 +164,18 @@ void free_pregenerated_keys(void);
NULL, \ NULL, \
NULL, \ NULL, \
} }
#endif /* !defined(COCCI) */
#define NS(name) US_CONCAT_3_(NS_MODULE, NS_SUBMODULE, name) #define NS(name) US_CONCAT_3_(NS_MODULE, NS_SUBMODULE, name)
#define NS_FULL(module, submodule, name) US_CONCAT_3_(module, submodule, name) #define NS_FULL(module, submodule, name) US_CONCAT_3_(module, submodule, name)
#define CALLED(mock_name) US_CONCAT_2_(NS(mock_name), called) #define CALLED(mock_name) US_CONCAT_2_(NS(mock_name), called)
#ifndef COCCI
#define NS_DECL(retval, mock_fn, args) \ #define NS_DECL(retval, mock_fn, args) \
extern int CALLED(mock_fn); \ extern int CALLED(mock_fn); \
static retval NS(mock_fn) args; int CALLED(mock_fn) = 0 static retval NS(mock_fn) args; int CALLED(mock_fn) = 0
#define NS_MOCK(name) MOCK(name, NS(name)) #define NS_MOCK(name) MOCK(name, NS(name))
#endif /* !defined(COCCI) */
#define NS_UNMOCK(name) UNMOCK(name) #define NS_UNMOCK(name) UNMOCK(name)
extern const struct testcase_setup_t passthrough_setup; extern const struct testcase_setup_t passthrough_setup;

View File

@ -52,6 +52,7 @@ test_addr_basic(void *arg)
; ;
} }
#ifndef COCCI
#define test_op_ip6_(a,op,b,e1,e2) \ #define test_op_ip6_(a,op,b,e1,e2) \
STMT_BEGIN \ STMT_BEGIN \
tt_assert_test_fmt_type(a,b,e1" "#op" "e2,struct in6_addr*, \ tt_assert_test_fmt_type(a,b,e1" "#op" "e2,struct in6_addr*, \
@ -69,6 +70,7 @@ test_addr_basic(void *arg)
TT_EXIT_TEST_FUNCTION \ TT_EXIT_TEST_FUNCTION \
); \ ); \
STMT_END STMT_END
#endif /* !defined(COCCI) */
/** Helper: Assert that two strings both decode as IPv6 addresses with /** Helper: Assert that two strings both decode as IPv6 addresses with
* tor_inet_pton(), and both decode to the same address. */ * tor_inet_pton(), and both decode to the same address. */
@ -111,6 +113,7 @@ test_addr_basic(void *arg)
TT_DIE(("%s was not internal", a)); \ TT_DIE(("%s was not internal", a)); \
STMT_END STMT_END
#ifndef COCCI
/** Helper: Assert that <b>a</b> and <b>b</b>, when parsed by /** Helper: Assert that <b>a</b> and <b>b</b>, when parsed by
* tor_inet_pton(), give addresses that compare in the order defined by * tor_inet_pton(), give addresses that compare in the order defined by
* <b>op</b> with tor_addr_compare(). */ * <b>op</b> with tor_addr_compare(). */
@ -135,6 +138,7 @@ test_addr_basic(void *arg)
TT_DIE(("Failed: tor_addr_compare_masked(%s,%s,%d) %s 0", \ TT_DIE(("Failed: tor_addr_compare_masked(%s,%s,%d) %s 0", \
a, b, m, #op)); \ a, b, m, #op)); \
STMT_END STMT_END
#endif /* !defined(COCCI) */
/** Helper: assert that <b>xx</b> is parseable as a masked IPv6 address with /** Helper: assert that <b>xx</b> is parseable as a masked IPv6 address with
* ports by tor_parse_mask_addr_ports(), with family <b>f</b>, IP address * ports by tor_parse_mask_addr_ports(), with family <b>f</b>, IP address
@ -1649,8 +1653,10 @@ test_addr_rfc6598(void *arg)
; ;
} }
#ifndef COCCI
#define ADDR_LEGACY(name) \ #define ADDR_LEGACY(name) \
{ #name, test_addr_ ## name , 0, NULL, NULL } { #name, test_addr_ ## name , 0, NULL, NULL }
#endif
struct testcase_t addr_tests[] = { struct testcase_t addr_tests[] = {
ADDR_LEGACY(basic), ADDR_LEGACY(basic),

View File

@ -3813,7 +3813,9 @@ static void
test_config_default_fallback_dirs(void *arg) test_config_default_fallback_dirs(void *arg)
{ {
const char *fallback[] = { const char *fallback[] = {
#ifndef COCCI
#include "app/config/fallback_dirs.inc" #include "app/config/fallback_dirs.inc"
#endif
NULL NULL
}; };

View File

@ -1034,12 +1034,14 @@ test_confparse_find_option_name(void *arg)
config_mgr_free(mgr); config_mgr_free(mgr);
} }
#ifndef COCCI
#define CONFPARSE_TEST(name, flags) \ #define CONFPARSE_TEST(name, flags) \
{ #name, test_confparse_ ## name, flags, NULL, NULL } { #name, test_confparse_ ## name, flags, NULL, NULL }
#define BADVAL_TEST(name) \ #define BADVAL_TEST(name) \
{ "badval_" #name, test_confparse_assign_badval, 0, \ { "badval_" #name, test_confparse_assign_badval, 0, \
&passthrough_setup, (void*)&bv_ ## name } &passthrough_setup, (void*)&bv_ ## name }
#endif /* !defined(COCCI) */
struct testcase_t confparse_tests[] = { struct testcase_t confparse_tests[] = {
CONFPARSE_TEST(init, 0), CONFPARSE_TEST(init, 0),

View File

@ -881,12 +881,14 @@ test_failed_orconn_tracker(void *arg)
; ;
} }
#ifndef COCCI
#define CONNECTION_TESTCASE(name, fork, setup) \ #define CONNECTION_TESTCASE(name, fork, setup) \
{ #name, test_conn_##name, fork, &setup, NULL } { #name, test_conn_##name, fork, &setup, NULL }
/* where arg is an expression (constant, variable, compound expression) */ /* where arg is an expression (constant, variable, compound expression) */
#define CONNECTION_TESTCASE_ARG(name, fork, setup, arg) \ #define CONNECTION_TESTCASE_ARG(name, fork, setup, arg) \
{ #name "_" #arg, test_conn_##name, fork, &setup, (void *)arg } { #name "_" #arg, test_conn_##name, fork, &setup, (void *)arg }
#endif /* !defined(COCCI) */
struct testcase_t connection_tests[] = { struct testcase_t connection_tests[] = {
CONNECTION_TESTCASE(get_basic, TT_FORK, test_conn_get_basic_st), CONNECTION_TESTCASE(get_basic, TT_FORK, test_conn_get_basic_st),

View File

@ -120,6 +120,7 @@ test_controller_parse_cmd(void *arg)
control_cmd_args_free(result); control_cmd_args_free(result);
} }
#ifndef COCCI
#define OK(inp, out) \ #define OK(inp, out) \
{ inp "\r\n", out, NULL } { inp "\r\n", out, NULL }
#define ERR(inp, err) \ #define ERR(inp, err) \
@ -129,6 +130,7 @@ test_controller_parse_cmd(void *arg)
{ &syntax, \ { &syntax, \
ARRAY_LENGTH(array), \ ARRAY_LENGTH(array), \
array } array }
#endif /* !defined(COCCI) */
static const parser_testcase_t one_to_three_tests[] = { static const parser_testcase_t one_to_three_tests[] = {
ERR("", "Need at least 1 argument(s)"), ERR("", "Need at least 1 argument(s)"),
@ -1953,9 +1955,11 @@ test_getinfo_md_all(void *arg)
return; return;
} }
#ifndef COCCI
#define PARSER_TEST(type) \ #define PARSER_TEST(type) \
{ "parse/" #type, test_controller_parse_cmd, 0, &passthrough_setup, \ { "parse/" #type, test_controller_parse_cmd, 0, &passthrough_setup, \
(void*)&parse_ ## type ## _params } (void*)&parse_ ## type ## _params }
#endif
struct testcase_t controller_tests[] = { struct testcase_t controller_tests[] = {
PARSER_TEST(one_to_three), PARSER_TEST(one_to_three),

View File

@ -2971,6 +2971,7 @@ test_crypto_failure_modes(void *arg)
; ;
} }
#ifndef COCCI
#define CRYPTO_LEGACY(name) \ #define CRYPTO_LEGACY(name) \
{ #name, test_crypto_ ## name , 0, NULL, NULL } { #name, test_crypto_ ## name , 0, NULL, NULL }
@ -2981,6 +2982,7 @@ test_crypto_failure_modes(void *arg)
#define ED25519_TEST(name, fl) \ #define ED25519_TEST(name, fl) \
ED25519_TEST_ONE(name, (fl), "donna"), \ ED25519_TEST_ONE(name, (fl), "donna"), \
ED25519_TEST_ONE(name, (fl), "ref10") ED25519_TEST_ONE(name, (fl), "ref10")
#endif /* !defined(COCCI) */
struct testcase_t crypto_tests[] = { struct testcase_t crypto_tests[] = {
CRYPTO_LEGACY(formats), CRYPTO_LEGACY(formats),

View File

@ -584,6 +584,7 @@ test_crypto_ed25519_fuzz_donna(void *arg)
; ;
} }
#ifndef COCCI
#define CRYPTO_LEGACY(name) \ #define CRYPTO_LEGACY(name) \
{ #name, test_crypto_ ## name , 0, NULL, NULL } { #name, test_crypto_ ## name , 0, NULL, NULL }
@ -594,6 +595,7 @@ test_crypto_ed25519_fuzz_donna(void *arg)
#define ED25519_TEST(name, fl) \ #define ED25519_TEST(name, fl) \
ED25519_TEST_ONE(name, (fl), "donna"), \ ED25519_TEST_ONE(name, (fl), "donna"), \
ED25519_TEST_ONE(name, (fl), "ref10") ED25519_TEST_ONE(name, (fl), "ref10")
#endif /* !defined(COCCI) */
struct testcase_t slow_crypto_tests[] = { struct testcase_t slow_crypto_tests[] = {
CRYPTO_LEGACY(s2k_rfc2440), CRYPTO_LEGACY(s2k_rfc2440),

View File

@ -7209,6 +7209,7 @@ test_dir_format_versions_list(void *arg)
teardown_capture_of_logs(); teardown_capture_of_logs();
} }
#ifndef COCCI
#define DIR_LEGACY(name) \ #define DIR_LEGACY(name) \
{ #name, test_dir_ ## name , TT_FORK, NULL, NULL } { #name, test_dir_ ## name , TT_FORK, NULL, NULL }
@ -7218,6 +7219,7 @@ test_dir_format_versions_list(void *arg)
/* where arg is a string constant */ /* where arg is a string constant */
#define DIR_ARG(name,flags,arg) \ #define DIR_ARG(name,flags,arg) \
{ #name "_" arg, test_dir_##name, (flags), &passthrough_setup, (void*) arg } { #name "_" arg, test_dir_##name, (flags), &passthrough_setup, (void*) arg }
#endif /* !defined(COCCI) */
struct testcase_t dir_tests[] = { struct testcase_t dir_tests[] = {
DIR_LEGACY(nicknames), DIR_LEGACY(nicknames),

View File

@ -3039,6 +3039,7 @@ static const struct testcase_setup_t upgrade_circuits = {
upgrade_circuits_setup, upgrade_circuits_cleanup upgrade_circuits_setup, upgrade_circuits_cleanup
}; };
#ifndef COCCI
#define NO_PREFIX_TEST(name) \ #define NO_PREFIX_TEST(name) \
{ #name, test_ ## name, 0, NULL, NULL } { #name, test_ ## name, 0, NULL, NULL }
@ -3061,6 +3062,7 @@ static const struct testcase_setup_t upgrade_circuits = {
&upgrade_circuits, (void*)(arg REASONABLY_FUTURE) }, \ &upgrade_circuits, (void*)(arg REASONABLY_FUTURE) }, \
{ #name "_reasonably_past", test_entry_guard_ ## name, TT_FORK, \ { #name "_reasonably_past", test_entry_guard_ ## name, TT_FORK, \
&upgrade_circuits, (void*)(arg REASONABLY_PAST) } &upgrade_circuits, (void*)(arg REASONABLY_PAST) }
#endif /* !defined(COCCI) */
struct testcase_t entrynodes_tests[] = { struct testcase_t entrynodes_tests[] = {
NO_PREFIX_TEST(node_preferred_orport), NO_PREFIX_TEST(node_preferred_orport),

View File

@ -1492,6 +1492,7 @@ AUTHENTICATE_FAIL(missing_ed_auth,
"authentication certificate"; "authentication certificate";
}) })
#ifndef COCCI
#define TEST_RSA(name, flags) \ #define TEST_RSA(name, flags) \
{ #name , test_link_handshake_ ## name, (flags), \ { #name , test_link_handshake_ ## name, (flags), \
&passthrough_setup, (void*)"RSA" } &passthrough_setup, (void*)"RSA" }
@ -1527,6 +1528,7 @@ AUTHENTICATE_FAIL(missing_ed_auth,
#define TEST_AUTHENTICATE_ED(name) \ #define TEST_AUTHENTICATE_ED(name) \
{ "authenticate/" #name "_ed25519" , test_link_handshake_auth_ ## name, \ { "authenticate/" #name "_ed25519" , test_link_handshake_auth_ ## name, \
TT_FORK, &setup_authenticate, (void*)3 } TT_FORK, &setup_authenticate, (void*)3 }
#endif /* !defined(COCCI) */
struct testcase_t link_handshake_tests[] = { struct testcase_t link_handshake_tests[] = {
TEST_RSA(certs_ok, TT_FORK), TEST_RSA(certs_ok, TT_FORK),

View File

@ -678,7 +678,7 @@ test_options_validate__logs(void *ignored)
tt_int_op(ret, OP_EQ, -1); tt_int_op(ret, OP_EQ, -1);
#else #else
tt_int_op(ret, OP_EQ, 0); tt_int_op(ret, OP_EQ, 0);
#endif #endif /* defined(_WIN32) */
free_options_test_data(tdata); free_options_test_data(tdata);
tdata = get_options_test_data(""); tdata = get_options_test_data("");
@ -4049,8 +4049,10 @@ test_options_init_logs_quiet(void *arg)
UNMOCK(add_file_log); UNMOCK(add_file_log);
} }
#ifndef COCCI
#define LOCAL_VALIDATE_TEST(name) \ #define LOCAL_VALIDATE_TEST(name) \
{ "validate__" #name, test_options_validate__ ## name, TT_FORK, NULL, NULL } { "validate__" #name, test_options_validate__ ## name, TT_FORK, NULL, NULL }
#endif
struct testcase_t options_tests[] = { struct testcase_t options_tests[] = {
{ "validate", test_options_validate, TT_FORK, NULL, NULL }, { "validate", test_options_validate, TT_FORK, NULL, NULL },

View File

@ -92,13 +92,13 @@ test_router_dump_router_to_string_no_bridge_distribution_method(void *arg)
options->BridgeRelay = 1; options->BridgeRelay = 1;
/* Generate keys which router_dump_router_to_string() expects to exist. */ /* Generate keys which router_dump_router_to_string() expects to exist. */
tt_int_op(0, ==, curve25519_keypair_generate(&ntor_keypair, 0)); tt_int_op(0, OP_EQ, curve25519_keypair_generate(&ntor_keypair, 0));
tt_int_op(0, ==, ed25519_keypair_generate(&signing_keypair, 0)); tt_int_op(0, OP_EQ, ed25519_keypair_generate(&signing_keypair, 0));
/* Set up part of our routerinfo_t so that we don't trigger any other /* Set up part of our routerinfo_t so that we don't trigger any other
* assertions in router_dump_router_to_string(). */ * assertions in router_dump_router_to_string(). */
router = (routerinfo_t*)router_get_my_routerinfo(); router = (routerinfo_t*)router_get_my_routerinfo();
tt_ptr_op(router, !=, NULL); tt_ptr_op(router, OP_NE, NULL);
/* The real router_get_my_routerinfo() looks up onion_curve25519_pkey using /* The real router_get_my_routerinfo() looks up onion_curve25519_pkey using
* get_current_curve25519_keypair(), but we don't initialise static data in * get_current_curve25519_keypair(), but we don't initialise static data in
@ -115,9 +115,9 @@ test_router_dump_router_to_string_no_bridge_distribution_method(void *arg)
&ntor_keypair, &ntor_keypair,
&signing_keypair); &signing_keypair);
crypto_pk_free(onion_pkey); crypto_pk_free(onion_pkey);
tt_ptr_op(desc, !=, NULL); tt_ptr_op(desc, OP_NE, NULL);
found = strstr(desc, needle); found = strstr(desc, needle);
tt_ptr_op(found, !=, NULL); tt_ptr_op(found, OP_NE, NULL);
done: done:
NS_UNMOCK(router_get_my_routerinfo); NS_UNMOCK(router_get_my_routerinfo);

View File

@ -848,8 +848,8 @@ test_scheduler_initfree(void *arg)
{ {
(void)arg; (void)arg;
tt_ptr_op(channels_pending, ==, NULL); tt_ptr_op(channels_pending, OP_EQ, NULL);
tt_ptr_op(run_sched_ev, ==, NULL); tt_ptr_op(run_sched_ev, OP_EQ, NULL);
MOCK(get_options, mock_get_options); MOCK(get_options, mock_get_options);
set_scheduler_options(SCHEDULER_KIST); set_scheduler_options(SCHEDULER_KIST);
@ -858,17 +858,17 @@ test_scheduler_initfree(void *arg)
scheduler_init(); scheduler_init();
tt_ptr_op(channels_pending, !=, NULL); tt_ptr_op(channels_pending, OP_NE, NULL);
tt_ptr_op(run_sched_ev, !=, NULL); tt_ptr_op(run_sched_ev, OP_NE, NULL);
/* We have specified nothing in the torrc and there's no consensus so the /* We have specified nothing in the torrc and there's no consensus so the
* KIST scheduler is what should be in use */ * KIST scheduler is what should be in use */
tt_ptr_op(the_scheduler, ==, get_kist_scheduler()); tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler());
tt_int_op(sched_run_interval, ==, 10); tt_int_op(sched_run_interval, OP_EQ, 10);
scheduler_free_all(); scheduler_free_all();
tt_ptr_op(channels_pending, ==, NULL); tt_ptr_op(channels_pending, OP_EQ, NULL);
tt_ptr_op(run_sched_ev, ==, NULL); tt_ptr_op(run_sched_ev, OP_EQ, NULL);
done: done:
UNMOCK(get_options); UNMOCK(get_options);
@ -890,11 +890,11 @@ test_scheduler_can_use_kist(void *arg)
res_should = scheduler_can_use_kist(); res_should = scheduler_can_use_kist();
res_freq = kist_scheduler_run_interval(); res_freq = kist_scheduler_run_interval();
#ifdef HAVE_KIST_SUPPORT #ifdef HAVE_KIST_SUPPORT
tt_int_op(res_should, ==, 1); tt_int_op(res_should, OP_EQ, 1);
#else /* HAVE_KIST_SUPPORT */ #else /* HAVE_KIST_SUPPORT */
tt_int_op(res_should, ==, 0); tt_int_op(res_should, OP_EQ, 0);
#endif /* HAVE_KIST_SUPPORT */ #endif /* HAVE_KIST_SUPPORT */
tt_int_op(res_freq, ==, 1234); tt_int_op(res_freq, OP_EQ, 1234);
/* Test defer to consensus, but no consensus available */ /* Test defer to consensus, but no consensus available */
clear_options(); clear_options();
@ -902,11 +902,11 @@ test_scheduler_can_use_kist(void *arg)
res_should = scheduler_can_use_kist(); res_should = scheduler_can_use_kist();
res_freq = kist_scheduler_run_interval(); res_freq = kist_scheduler_run_interval();
#ifdef HAVE_KIST_SUPPORT #ifdef HAVE_KIST_SUPPORT
tt_int_op(res_should, ==, 1); tt_int_op(res_should, OP_EQ, 1);
#else /* HAVE_KIST_SUPPORT */ #else /* HAVE_KIST_SUPPORT */
tt_int_op(res_should, ==, 0); tt_int_op(res_should, OP_EQ, 0);
#endif /* HAVE_KIST_SUPPORT */ #endif /* HAVE_KIST_SUPPORT */
tt_int_op(res_freq, ==, 10); tt_int_op(res_freq, OP_EQ, 10);
/* Test defer to consensus, and kist consensus available */ /* Test defer to consensus, and kist consensus available */
MOCK(networkstatus_get_param, mock_kist_networkstatus_get_param); MOCK(networkstatus_get_param, mock_kist_networkstatus_get_param);
@ -915,11 +915,11 @@ test_scheduler_can_use_kist(void *arg)
res_should = scheduler_can_use_kist(); res_should = scheduler_can_use_kist();
res_freq = kist_scheduler_run_interval(); res_freq = kist_scheduler_run_interval();
#ifdef HAVE_KIST_SUPPORT #ifdef HAVE_KIST_SUPPORT
tt_int_op(res_should, ==, 1); tt_int_op(res_should, OP_EQ, 1);
#else /* HAVE_KIST_SUPPORT */ #else /* HAVE_KIST_SUPPORT */
tt_int_op(res_should, ==, 0); tt_int_op(res_should, OP_EQ, 0);
#endif /* HAVE_KIST_SUPPORT */ #endif /* HAVE_KIST_SUPPORT */
tt_int_op(res_freq, ==, 12); tt_int_op(res_freq, OP_EQ, 12);
UNMOCK(networkstatus_get_param); UNMOCK(networkstatus_get_param);
/* Test defer to consensus, and vanilla consensus available */ /* Test defer to consensus, and vanilla consensus available */
@ -928,8 +928,8 @@ test_scheduler_can_use_kist(void *arg)
mocked_options.KISTSchedRunInterval = 0; mocked_options.KISTSchedRunInterval = 0;
res_should = scheduler_can_use_kist(); res_should = scheduler_can_use_kist();
res_freq = kist_scheduler_run_interval(); res_freq = kist_scheduler_run_interval();
tt_int_op(res_should, ==, 0); tt_int_op(res_should, OP_EQ, 0);
tt_int_op(res_freq, ==, 0); tt_int_op(res_freq, OP_EQ, 0);
UNMOCK(networkstatus_get_param); UNMOCK(networkstatus_get_param);
done: done:
@ -956,7 +956,7 @@ test_scheduler_ns_changed(void *arg)
set_scheduler_options(SCHEDULER_KIST); set_scheduler_options(SCHEDULER_KIST);
set_scheduler_options(SCHEDULER_VANILLA); set_scheduler_options(SCHEDULER_VANILLA);
tt_ptr_op(the_scheduler, ==, NULL); tt_ptr_op(the_scheduler, OP_EQ, NULL);
/* Change from vanilla to kist via consensus */ /* Change from vanilla to kist via consensus */
the_scheduler = get_vanilla_scheduler(); the_scheduler = get_vanilla_scheduler();
@ -964,9 +964,9 @@ test_scheduler_ns_changed(void *arg)
scheduler_notify_networkstatus_changed(); scheduler_notify_networkstatus_changed();
UNMOCK(networkstatus_get_param); UNMOCK(networkstatus_get_param);
#ifdef HAVE_KIST_SUPPORT #ifdef HAVE_KIST_SUPPORT
tt_ptr_op(the_scheduler, ==, get_kist_scheduler()); tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler());
#else #else
tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler()); tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler());
#endif #endif
/* Change from kist to vanilla via consensus */ /* Change from kist to vanilla via consensus */
@ -974,7 +974,7 @@ test_scheduler_ns_changed(void *arg)
MOCK(networkstatus_get_param, mock_vanilla_networkstatus_get_param); MOCK(networkstatus_get_param, mock_vanilla_networkstatus_get_param);
scheduler_notify_networkstatus_changed(); scheduler_notify_networkstatus_changed();
UNMOCK(networkstatus_get_param); UNMOCK(networkstatus_get_param);
tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler()); tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler());
/* Doesn't change when using KIST */ /* Doesn't change when using KIST */
the_scheduler = get_kist_scheduler(); the_scheduler = get_kist_scheduler();
@ -982,9 +982,9 @@ test_scheduler_ns_changed(void *arg)
scheduler_notify_networkstatus_changed(); scheduler_notify_networkstatus_changed();
UNMOCK(networkstatus_get_param); UNMOCK(networkstatus_get_param);
#ifdef HAVE_KIST_SUPPORT #ifdef HAVE_KIST_SUPPORT
tt_ptr_op(the_scheduler, ==, get_kist_scheduler()); tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler());
#else #else
tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler()); tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler());
#endif #endif
/* Doesn't change when using vanilla */ /* Doesn't change when using vanilla */
@ -992,7 +992,7 @@ test_scheduler_ns_changed(void *arg)
MOCK(networkstatus_get_param, mock_vanilla_networkstatus_get_param); MOCK(networkstatus_get_param, mock_vanilla_networkstatus_get_param);
scheduler_notify_networkstatus_changed(); scheduler_notify_networkstatus_changed();
UNMOCK(networkstatus_get_param); UNMOCK(networkstatus_get_param);
tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler()); tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler());
done: done:
UNMOCK(get_options); UNMOCK(get_options);

View File

@ -304,6 +304,7 @@ test_util_write_chunks_to_file(void *arg)
tor_free(temp_str); tor_free(temp_str);
} }
#ifndef COCCI
#define _TFE(a, b, f) tt_int_op((a).f, OP_EQ, (b).f) #define _TFE(a, b, f) tt_int_op((a).f, OP_EQ, (b).f)
/** test the minimum set of struct tm fields needed for a unique epoch value /** test the minimum set of struct tm fields needed for a unique epoch value
* this is also the set we use to test tor_timegm */ * this is also the set we use to test tor_timegm */
@ -316,6 +317,7 @@ test_util_write_chunks_to_file(void *arg)
_TFE(a, b, tm_min ); \ _TFE(a, b, tm_min ); \
_TFE(a, b, tm_sec ); \ _TFE(a, b, tm_sec ); \
TT_STMT_END TT_STMT_END
#endif /* !defined(COCCI) */
static void static void
test_util_time(void *arg) test_util_time(void *arg)
@ -6257,6 +6259,7 @@ test_util_map_anon_nofork(void *arg)
#endif /* defined(_WIN32) */ #endif /* defined(_WIN32) */
} }
#ifndef COCCI
#define UTIL_LEGACY(name) \ #define UTIL_LEGACY(name) \
{ #name, test_util_ ## name , 0, NULL, NULL } { #name, test_util_ ## name , 0, NULL, NULL }
@ -6281,6 +6284,7 @@ test_util_map_anon_nofork(void *arg)
{ "compress_dos/" #name, test_util_decompress_dos, 0, \ { "compress_dos/" #name, test_util_decompress_dos, 0, \
&compress_setup, \ &compress_setup, \
(char*)(identifier) } (char*)(identifier) }
#endif /* !defined(COCCI) */
#ifdef _WIN32 #ifdef _WIN32
#define UTIL_TEST_NO_WIN(n, f) { #n, NULL, TT_SKIP, NULL, NULL } #define UTIL_TEST_NO_WIN(n, f) { #n, NULL, TT_SKIP, NULL, NULL }