mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-23 20:03:31 +01:00
Merge remote-tracking branch 'tor-github/pr/1447'
This commit is contained in:
commit
20606b8a15
9
changes/ticket31705
Normal file
9
changes/ticket31705
Normal 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
9
scripts/coccinelle/apply.sh
Executable 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 "$@"
|
@ -1,4 +1,17 @@
|
||||
#!/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#^ *\* #;
|
||||
|
||||
|
@ -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 CHECK_PRINTF(a, b)
|
||||
#define CHECK_SCANF(a, b)
|
||||
#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
29
scripts/coccinelle/try_parse.sh
Executable 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"
|
@ -186,8 +186,12 @@ static const char unix_q_socket_prefix[] = "unix:\"";
|
||||
|
||||
/** macro to help with the bulk rename of *DownloadSchedule to
|
||||
* *DowloadInitialDelay . */
|
||||
#ifndef COCCI
|
||||
#define DOWNLOAD_SCHEDULE(name) \
|
||||
{ #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
|
||||
* 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 */
|
||||
static const char *default_authorities[] = {
|
||||
#ifndef COCCI
|
||||
#include "auth_dirs.inc"
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -773,7 +779,9 @@ static const char *default_authorities[] = {
|
||||
* relays that meet certain stability criteria.
|
||||
*/
|
||||
static const char *default_fallbacks[] = {
|
||||
#ifndef COCCI
|
||||
#include "fallback_dirs.inc"
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -783,7 +791,9 @@ static const struct {
|
||||
const char *k;
|
||||
const char *v;
|
||||
} testing_tor_network_defaults[] = {
|
||||
#ifndef COCCI
|
||||
#include "testnet.inc"
|
||||
#endif
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
@ -1349,9 +1349,11 @@ get_signewnym_epoch(void)
|
||||
static int periodic_events_initialized = 0;
|
||||
|
||||
/* Declare all the timer callback functions... */
|
||||
#ifndef COCCI
|
||||
#undef CALLBACK
|
||||
#define CALLBACK(name) \
|
||||
static int name ## _callback(time_t, const or_options_t *)
|
||||
|
||||
CALLBACK(add_entropy);
|
||||
CALLBACK(check_expired_networkstatus);
|
||||
CALLBACK(clean_caches);
|
||||
@ -1374,9 +1376,10 @@ CALLBACK(second_elapsed);
|
||||
#undef CALLBACK
|
||||
|
||||
/* 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)
|
||||
#define FL(name) (PERIODIC_EVENT_FLAG_ ## name)
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
STATIC periodic_event_item_t mainloop_periodic_events[] = {
|
||||
|
||||
@ -1427,8 +1430,10 @@ STATIC periodic_event_item_t mainloop_periodic_events[] = {
|
||||
|
||||
END_OF_PERIODIC_EVENTS
|
||||
};
|
||||
#ifndef COCCI
|
||||
#undef CALLBACK
|
||||
#undef FL
|
||||
#endif
|
||||
|
||||
/* These are pointers to members of periodic_events[] that are used to
|
||||
* 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. */
|
||||
|
||||
#ifndef COCCI
|
||||
#define NAMED_CALLBACK(name) \
|
||||
STMT_BEGIN name ## _event = periodic_events_find( #name ); STMT_END
|
||||
#endif
|
||||
|
||||
NAMED_CALLBACK(prune_old_routers);
|
||||
NAMED_CALLBACK(fetch_networkstatus);
|
||||
|
@ -71,8 +71,10 @@ typedef struct periodic_event_item_t {
|
||||
} periodic_event_item_t;
|
||||
|
||||
/** 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 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
|
||||
* scheduled. */
|
||||
|
@ -116,6 +116,7 @@ STATIC smartlist_t *origin_padding_machines = NULL;
|
||||
* runtime and as long as circuits are alive. */
|
||||
STATIC smartlist_t *relay_padding_machines = NULL;
|
||||
|
||||
#ifndef COCCI
|
||||
/** Loop over the current padding state machines using <b>loop_var</b> as the
|
||||
* loop variable. */
|
||||
#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]) \
|
||||
continue;
|
||||
#define FOR_EACH_ACTIVE_CIRCUIT_MACHINE_END } STMT_END ;
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
/**
|
||||
* Free the machineinfo at an index
|
||||
|
@ -20,11 +20,13 @@
|
||||
|
||||
#include "feature/relay/routermode.h"
|
||||
|
||||
#ifndef COCCI
|
||||
#define DECLARE_EVENT(name, roles, flags) \
|
||||
static periodic_event_item_t name ## _event = \
|
||||
PERIODIC_EVENT(name, \
|
||||
PERIODIC_EVENT_ROLE_##roles, \
|
||||
flags)
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
#define FL(name) (PERIODIC_EVENT_FLAG_ ## name)
|
||||
|
||||
|
@ -14,4 +14,4 @@
|
||||
|
||||
int proxy_mode(const or_options_t *options);
|
||||
|
||||
#endif
|
||||
#endif /* !defined(TOR_PROXYMODE_H) */
|
||||
|
@ -2248,6 +2248,7 @@ typedef struct control_cmd_def_t {
|
||||
*/
|
||||
#define CMD_FL_WIPE (1u<<0)
|
||||
|
||||
#ifndef COCCI
|
||||
/** Macro: declare a command with a one-line argument, a given set of flags,
|
||||
* and a syntax definition.
|
||||
**/
|
||||
@ -2280,6 +2281,7 @@ typedef struct control_cmd_def_t {
|
||||
0, \
|
||||
&obsolete_syntax, \
|
||||
}
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
/**
|
||||
* An array defining all the recognized controller commands.
|
||||
|
@ -1663,6 +1663,7 @@ control_event_status(int type, int severity, const char *format, va_list args)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define CONTROL_EVENT_STATUS_BODY(event, sev) \
|
||||
int r; \
|
||||
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); \
|
||||
va_end(ap); \
|
||||
} while (0)
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
/** Format and send an EVENT_STATUS_GENERAL event whose main text is obtained
|
||||
* by formatting the arguments using the printf-style <b>format</b>. */
|
||||
|
@ -18,11 +18,13 @@
|
||||
|
||||
#include "core/mainloop/periodic.h"
|
||||
|
||||
#ifndef COCCI
|
||||
#define DECLARE_EVENT(name, roles, flags) \
|
||||
static periodic_event_item_t name ## _event = \
|
||||
PERIODIC_EVENT(name, \
|
||||
PERIODIC_EVENT_ROLE_##roles, \
|
||||
flags)
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
#define FL(name) (PERIODIC_EVENT_FLAG_##name)
|
||||
|
||||
|
@ -530,10 +530,12 @@ typedef struct router_id_iterator_t {
|
||||
cdline_t hash;
|
||||
} router_id_iterator_t;
|
||||
|
||||
#ifndef COCCI
|
||||
/**
|
||||
* Initializer for a router_id_iterator_t.
|
||||
*/
|
||||
#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
|
||||
* the index to the next router line ("r ...") in the consensus, or to
|
||||
|
@ -26,4 +26,4 @@
|
||||
NO_ARGS, NEED_OBJ),\
|
||||
T01("dir-address", K_DIR_ADDRESS, GE(1), NO_OBJ)
|
||||
|
||||
#endif
|
||||
#endif /* !defined(TOR_AUTHCERT_MEMBERS_H) */
|
||||
|
@ -67,6 +67,7 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef COCCI
|
||||
/** Helper macro. Iterate over every service in the global map. The var is the
|
||||
* name of the service pointer. */
|
||||
#define FOR_EACH_SERVICE_BEGIN(var) \
|
||||
@ -88,6 +89,7 @@
|
||||
(var = service->desc_next); \
|
||||
if (var == NULL) continue;
|
||||
#define FOR_EACH_DESCRIPTOR_END } STMT_END ;
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
/* Onion service directory file names. */
|
||||
static const char fname_keyfile_prefix[] = "hs_ed25519";
|
||||
|
@ -31,11 +31,13 @@
|
||||
#include "feature/nodelist/routerinfo_st.h"
|
||||
#include "feature/control/control_events.h"
|
||||
|
||||
#ifndef COCCI
|
||||
#define DECLARE_EVENT(name, roles, flags) \
|
||||
static periodic_event_item_t name ## _event = \
|
||||
PERIODIC_EVENT(name, \
|
||||
PERIODIC_EVENT_ROLE_##roles, \
|
||||
flags)
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
#define FL(name) (PERIODIC_EVENT_FLAG_##name)
|
||||
|
||||
|
@ -386,7 +386,7 @@ get_server_identity_key,(void))
|
||||
return server_identitykey;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* defined(HAVE_MODULE_RELAY) */
|
||||
|
||||
/** Return true iff we are a server and the server identity key
|
||||
* has been set. */
|
||||
|
@ -25,7 +25,7 @@ void set_server_advertised(int s);
|
||||
/** Is the relay module enabled? */
|
||||
#define have_module_relay() (1)
|
||||
|
||||
#else
|
||||
#else /* !defined(HAVE_MODULE_RELAY) */
|
||||
|
||||
#define dir_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)
|
||||
|
||||
#endif
|
||||
#endif /* defined(HAVE_MODULE_RELAY) */
|
||||
|
||||
#endif /* !defined(TOR_ROUTERMODE_H) */
|
||||
|
@ -99,6 +99,7 @@
|
||||
#define DBG_S(s) (void)0
|
||||
#endif
|
||||
|
||||
#ifndef COCCI
|
||||
#ifdef DISABLE_MEMORY_SENTINELS
|
||||
#define CHUNK_SET_SENTINEL(chunk, alloclen) STMT_NIL
|
||||
#else
|
||||
@ -109,6 +110,7 @@
|
||||
memset(a,0,SENTINEL_LEN); \
|
||||
} while (0)
|
||||
#endif /* defined(DISABLE_MEMORY_SENTINELS) */
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
/** Move all bytes stored in <b>chunk</b> to the front of <b>chunk</b>->mem,
|
||||
* to free up space at the end. */
|
||||
|
@ -46,7 +46,7 @@
|
||||
|
||||
#define CTASSERT_EXPN(x, a, b) 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 */
|
||||
|
||||
|
@ -15,11 +15,13 @@
|
||||
#include "orconfig.h"
|
||||
#include "lib/conf/conftesting.h"
|
||||
|
||||
#ifndef COCCI
|
||||
/**
|
||||
* Used to indicate the end of an array of configuration variables.
|
||||
**/
|
||||
#define END_OF_CONFIG_VARS \
|
||||
{ .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
|
||||
|
@ -12,7 +12,9 @@
|
||||
#ifndef TOR_LIB_CONF_CONFTESTING_H
|
||||
#define TOR_LIB_CONF_CONFTESTING_H
|
||||
|
||||
#ifndef COCCI
|
||||
#ifdef TOR_UNIT_TESTS
|
||||
#define USE_CONF_TESTING
|
||||
/**
|
||||
* 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
|
||||
@ -41,12 +43,10 @@ typedef union {
|
||||
// XXXX this doesn't belong at this level of abstraction.
|
||||
struct routerset_t **ROUTERSET;
|
||||
} confparse_dummy_values_t;
|
||||
#endif /* defined(TOR_UNIT_TESTS) */
|
||||
|
||||
/* Macros to define extra members inside config_var_t fields, and at the
|
||||
* end of a list of them.
|
||||
*/
|
||||
#ifdef TOR_UNIT_TESTS
|
||||
/* This is a somewhat magic type-checking macro for users of confparse.c.
|
||||
* It initializes a union member "confparse_dummy_values_t.conftype" with
|
||||
* 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_TYPECHECK_INSTANCE(tp) \
|
||||
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)
|
||||
/* Repeatedly declarable incomplete struct to absorb redundant semicolons */
|
||||
#define DUMMY_TYPECHECK_INSTANCE(tp) \
|
||||
struct tor_semicolon_eater
|
||||
#define DUMMY_CONF_TEST_MEMBERS
|
||||
|
||||
#endif /* defined(TOR_UNIT_TESTS) */
|
||||
#endif /* !defined(USE_CONF_TESTING) */
|
||||
|
||||
#endif /* !defined(TOR_LIB_CONF_CONFTESTING_H) */
|
||||
|
@ -28,7 +28,9 @@ struct namemap_t {
|
||||
struct smartlist_t *names;
|
||||
};
|
||||
|
||||
#ifndef COCCI
|
||||
/** Macro to initialize a namemap. */
|
||||
#define NAMEMAP_INIT() { HT_INITIALIZER(), NULL }
|
||||
#endif
|
||||
|
||||
#endif /* !defined(NAMEMAP_ST_H) */
|
||||
|
@ -92,6 +92,7 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
|
||||
size_t join_len, int terminate, size_t *len_out)
|
||||
ATTR_MALLOC;
|
||||
|
||||
#ifndef COCCI
|
||||
/* 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
|
||||
* 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) \
|
||||
} \
|
||||
STMT_END
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
#endif /* !defined(TOR_SMARTLIST_H) */
|
||||
|
@ -121,10 +121,12 @@ crypto_openssl_get_header_version_str(void)
|
||||
return crypto_openssl_header_version_str;
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#ifndef OPENSSL_THREADS
|
||||
#error OpenSSL has been built without thread support. Tor requires an \
|
||||
OpenSSL library with thread support enabled.
|
||||
#error "OpenSSL has been built without thread support. Tor requires an \
|
||||
OpenSSL library with thread support enabled."
|
||||
#endif
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
#ifndef NEW_THREAD_API
|
||||
/** Helper: OpenSSL uses this callback to manipulate mutexes. */
|
||||
|
@ -33,6 +33,7 @@ dispatch_naming_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
/* Helper macro: declare functions to map IDs to and from names for a given
|
||||
* type in a namemap_t.
|
||||
*/
|
||||
@ -56,6 +57,7 @@ dispatch_naming_init(void)
|
||||
return namemap_get_size(&type##_id_map); \
|
||||
} \
|
||||
EAT_SEMICOLON
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
DECLARE_ID_MAP_FNS(message);
|
||||
DECLARE_ID_MAP_FNS(channel);
|
||||
|
@ -56,13 +56,15 @@ struct timeout_cb {
|
||||
/*
|
||||
* 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. */
|
||||
#define TIMEOUT_PUBLIC __attribute__((__unused__)) static
|
||||
#else
|
||||
/* We're not exposing any of the functions outside this file. */
|
||||
#define TIMEOUT_PUBLIC static
|
||||
#endif /* defined(__GNUC__) */
|
||||
#endif /* defined(COCCI) || ... */
|
||||
/* We're not using periodic events. */
|
||||
#define TIMEOUT_DISABLE_INTERVALS
|
||||
/* We always know the global_timeouts object, so we don't need each timeout
|
||||
|
@ -19,8 +19,11 @@ typedef struct tor_weak_rng_t {
|
||||
uint32_t state;
|
||||
} tor_weak_rng_t;
|
||||
|
||||
#ifndef COCCI
|
||||
#define TOR_WEAK_RNG_INIT {383745623}
|
||||
#endif
|
||||
#define TOR_WEAK_RANDOM_MAX (INT_MAX)
|
||||
|
||||
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_range(tor_weak_rng_t *rng, int32_t top);
|
||||
|
@ -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.
|
||||
* Regrettably, they call their maximum line length MAXLINE. */
|
||||
#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
|
||||
char *m = msg_after_prefix;
|
||||
if (msg_len >= MAXLINE)
|
||||
|
@ -23,9 +23,11 @@
|
||||
#include <syslog.h>
|
||||
#define LOG_WARN LOG_WARNING
|
||||
#if LOG_DEBUG < LOG_ERR
|
||||
#ifndef COCCI
|
||||
#error "Your syslog.h thinks high numbers are more important. " \
|
||||
"We aren't prepared to deal with that."
|
||||
#endif
|
||||
#endif /* LOG_DEBUG < LOG_ERR */
|
||||
#else /* !defined(HAVE_SYSLOG_H) */
|
||||
/* 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
|
||||
@ -308,7 +310,7 @@ MOCK_DECL(STATIC void, logv, (int severity, log_domain_mask_t domain,
|
||||
va_list ap) CHECK_PRINTF(5,0));
|
||||
MOCK_DECL(STATIC void, add_stream_log_impl,(
|
||||
const log_severity_list_t *severity, const char *name, int fd));
|
||||
#endif
|
||||
#endif /* defined(LOG_PRIVATE) */
|
||||
|
||||
#if defined(LOG_PRIVATE) || defined(TOR_UNIT_TESTS)
|
||||
/** Given a severity, yields an index into log_severity_list_t.masks to use
|
||||
|
@ -45,7 +45,9 @@ typedef struct ratelim_t {
|
||||
int n_calls_since_last_time;
|
||||
} ratelim_t;
|
||||
|
||||
#ifndef COCCI
|
||||
#define RATELIM_INIT(r) { (r), 0, 0 }
|
||||
#endif
|
||||
#define RATELIM_TOOMANY (16*1000*1000)
|
||||
|
||||
char *rate_limit_log(ratelim_t *lim, time_t now);
|
||||
|
@ -131,7 +131,9 @@
|
||||
#undef BUG
|
||||
// Coverity defines this in global headers; let's override it. This is a
|
||||
// magic coverity-only preprocessor thing.
|
||||
#ifndef COCCI
|
||||
#nodef BUG(x) (x)
|
||||
#endif
|
||||
#endif /* defined(__COVERITY__) */
|
||||
|
||||
#if defined(__COVERITY__) || defined(__clang_analyzer__)
|
||||
@ -200,6 +202,7 @@
|
||||
: 0)
|
||||
#endif /* defined(ALL_BUGS_ARE_FATAL) || ... */
|
||||
|
||||
#ifndef COCCI
|
||||
#ifdef __GNUC__
|
||||
#define IF_BUG_ONCE__(cond,var) \
|
||||
if (( { \
|
||||
@ -208,7 +211,7 @@
|
||||
if (bool_result && !var) { \
|
||||
var = 1; \
|
||||
tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, \
|
||||
"!("#cond")", 1, NULL); \
|
||||
("!("#cond")"), 1, NULL); \
|
||||
} \
|
||||
bool_result; } ))
|
||||
#else /* !defined(__GNUC__) */
|
||||
@ -218,10 +221,12 @@
|
||||
(var ? 1 : \
|
||||
(var=1, \
|
||||
tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, \
|
||||
"!("#cond")", 1, NULL), \
|
||||
("!("#cond")"), 1, NULL), \
|
||||
1)) \
|
||||
: 0)
|
||||
#endif /* defined(__GNUC__) */
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
#define IF_BUG_ONCE_VARNAME_(a) \
|
||||
warning_logged_on_ ## a ## __
|
||||
#define IF_BUG_ONCE_VARNAME__(a) \
|
||||
|
@ -78,8 +78,8 @@
|
||||
#endif /* defined(HAVE_MINHERIT) || ... */
|
||||
|
||||
#if defined(HAVE_MINHERIT) && !defined(FLAG_ZERO) && !defined(FLAG_NOINHERIT)
|
||||
#warn "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 "minherit() is defined, but we couldn't find the right flag for it."
|
||||
#warning "This is probably a bug in Tor's support for this platform."
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -1392,7 +1392,7 @@ get_interface_addresses_win32(int severity, sa_family_t family)
|
||||
|
||||
/* This is defined on Mac OS X */
|
||||
#ifndef _SIZEOF_ADDR_IFREQ
|
||||
#define _SIZEOF_ADDR_IFREQ sizeof
|
||||
#define _SIZEOF_ADDR_IFREQ(x) sizeof(x)
|
||||
#endif
|
||||
|
||||
/* Free ifc->ifc_buf safely. */
|
||||
|
@ -9,6 +9,7 @@
|
||||
**/
|
||||
|
||||
#include "lib/string/parse_int.h"
|
||||
#include "lib/cc/compat_compiler.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
@ -17,6 +18,7 @@
|
||||
/* Helper: common code to check whether the result of a strtol or strtoul or
|
||||
* strtoll is correct. */
|
||||
#define CHECK_STRTOX_RESULT() \
|
||||
STMT_BEGIN \
|
||||
/* Did an overflow occur? */ \
|
||||
if (errno == ERANGE) \
|
||||
goto err; \
|
||||
@ -38,7 +40,8 @@
|
||||
err: \
|
||||
if (ok) *ok = 0; \
|
||||
if (next) *next = endptr; \
|
||||
return 0
|
||||
return 0; \
|
||||
STMT_END
|
||||
|
||||
/** 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,
|
||||
|
@ -106,7 +106,9 @@ void tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value);
|
||||
typedef struct atomic_counter_t {
|
||||
atomic_size_t val;
|
||||
} atomic_counter_t;
|
||||
#ifndef COCCI
|
||||
#define ATOMIC_LINKAGE static
|
||||
#endif
|
||||
#else /* !defined(HAVE_WORKING_STDATOMIC) */
|
||||
typedef struct atomic_counter_t {
|
||||
tor_mutex_t mutex;
|
||||
|
@ -464,7 +464,9 @@ static const char UNRESTRICTED_SERVER_CIPHER_LIST[] =
|
||||
/** List of ciphers that clients should advertise, omitting items that
|
||||
* our OpenSSL doesn't know about. */
|
||||
static const char CLIENT_CIPHER_LIST[] =
|
||||
#ifndef COCCI
|
||||
#include "lib/tls/ciphers.inc"
|
||||
#endif
|
||||
/* Tell it not to use SSLv2 ciphers, so that it can select an SSLv3 version
|
||||
* of any cipher we say. */
|
||||
"!SSLv2"
|
||||
|
@ -11,14 +11,18 @@
|
||||
* src/core/include.am, and is usually right.
|
||||
*/
|
||||
const char tor_git_revision[] =
|
||||
#ifndef COCCI
|
||||
#ifndef _MSC_VER
|
||||
#include "micro-revision.i"
|
||||
#endif
|
||||
#endif
|
||||
"";
|
||||
|
||||
const char tor_bug_suffix[] = " (on Tor " VERSION
|
||||
#ifndef COCCI
|
||||
#ifndef _MSC_VER
|
||||
" "
|
||||
#include "micro-revision.i"
|
||||
#endif
|
||||
#endif /* !defined(COCCI) */
|
||||
")";
|
||||
|
@ -69,6 +69,7 @@
|
||||
} while (0)
|
||||
#endif /* !defined(timersub) */
|
||||
|
||||
#ifndef COCCI
|
||||
#ifndef timercmp
|
||||
/** Replacement for timercmp on platforms that do not have it: returns 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_sec op (tv2)->tv_sec))
|
||||
#endif /* !defined(timercmp) */
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
#endif /* !defined(TOR_TIMEVAL_H) */
|
||||
|
@ -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);
|
||||
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,
|
||||
&auth_kp.pubkey, now,
|
||||
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();
|
||||
tt_assert(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(
|
||||
&signing_kp->pubkey, ip->legacy.key,
|
||||
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;
|
||||
|
||||
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,
|
||||
&curve25519_kp);
|
||||
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. */
|
||||
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,
|
||||
&auth_ephemeral_kp.pubkey,
|
||||
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,
|
||||
desc2->plaintext_data.blinded_pubkey.pubkey,
|
||||
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);
|
||||
|
||||
/* 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(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));
|
||||
for (int i=0;
|
||||
i < smartlist_len(desc1->superencrypted_data.clients);
|
||||
@ -259,15 +259,15 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1,
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
if (desc1->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));
|
||||
for (int i = 0;
|
||||
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(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));
|
||||
for (int i=0; i < smartlist_len(desc1->encrypted_data.intro_points); i++) {
|
||||
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_int_op(smartlist_len(ip1->link_specifiers), ==,
|
||||
tt_int_op(smartlist_len(ip1->link_specifiers), OP_EQ,
|
||||
smartlist_len(ip2->link_specifiers));
|
||||
for (int j = 0; j < smartlist_len(ip1->link_specifiers); j++) {
|
||||
link_specifier_t *ls1 = smartlist_get(ip1->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));
|
||||
switch (link_specifier_get_ls_type(ls1)) {
|
||||
case LS_IPV4:
|
||||
@ -311,7 +311,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1,
|
||||
tt_int_op(addr1, OP_EQ, addr2);
|
||||
uint16_t port1 = link_specifier_get_un_ipv4_port(ls1);
|
||||
uint16_t port2 = link_specifier_get_un_ipv4_port(ls2);
|
||||
tt_int_op(port1, ==, port2);
|
||||
tt_int_op(port1, OP_EQ, port2);
|
||||
}
|
||||
break;
|
||||
case LS_IPV6:
|
||||
@ -326,7 +326,7 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1,
|
||||
link_specifier_getlen_un_ipv6_addr(ls1));
|
||||
uint16_t port1 = link_specifier_get_un_ipv6_port(ls1);
|
||||
uint16_t port2 = link_specifier_get_un_ipv6_port(ls2);
|
||||
tt_int_op(port1, ==, port2);
|
||||
tt_int_op(port1, OP_EQ, port2);
|
||||
}
|
||||
break;
|
||||
case LS_LEGACY_ID:
|
||||
|
@ -37,6 +37,7 @@
|
||||
|
||||
#define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, OP_EQ, hex)
|
||||
|
||||
#ifndef COCCI
|
||||
#define tt_double_op(a,op,b) \
|
||||
tt_assert_test_type(a,b,#a" "#op" "#b,double,(val1_ op val2_),"%g", \
|
||||
TT_EXIT_TEST_FUNCTION)
|
||||
@ -64,6 +65,7 @@
|
||||
tt_assert_test_fmt_type(a,b,#a" "#op" "#b,int64_t,(val1_ op val2_), \
|
||||
int64_t, "%"PRId64, \
|
||||
{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.
|
||||
@ -145,6 +147,7 @@ void free_pregenerated_keys(void);
|
||||
#define NAME_TEST_(name) #name
|
||||
#define NAME_TEST(name) NAME_TEST_(name)
|
||||
#define ASPECT(test_module, test_name) US2_CONCAT_2__(test_module, test_name)
|
||||
#ifndef COCCI
|
||||
#define TEST_CASE(function) \
|
||||
{ \
|
||||
NAME_TEST(function), \
|
||||
@ -161,15 +164,18 @@ void free_pregenerated_keys(void);
|
||||
NULL, \
|
||||
NULL, \
|
||||
}
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
#define NS(name) US_CONCAT_3_(NS_MODULE, NS_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)
|
||||
#ifndef COCCI
|
||||
#define NS_DECL(retval, mock_fn, args) \
|
||||
extern int CALLED(mock_fn); \
|
||||
static retval NS(mock_fn) args; int CALLED(mock_fn) = 0
|
||||
#define NS_MOCK(name) MOCK(name, NS(name))
|
||||
#endif /* !defined(COCCI) */
|
||||
#define NS_UNMOCK(name) UNMOCK(name)
|
||||
|
||||
extern const struct testcase_setup_t passthrough_setup;
|
||||
|
@ -52,6 +52,7 @@ test_addr_basic(void *arg)
|
||||
;
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define test_op_ip6_(a,op,b,e1,e2) \
|
||||
STMT_BEGIN \
|
||||
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 \
|
||||
); \
|
||||
STMT_END
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
/** Helper: Assert that two strings both decode as IPv6 addresses with
|
||||
* 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)); \
|
||||
STMT_END
|
||||
|
||||
#ifndef COCCI
|
||||
/** 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
|
||||
* <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", \
|
||||
a, b, m, #op)); \
|
||||
STMT_END
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
/** 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
|
||||
@ -1649,8 +1653,10 @@ test_addr_rfc6598(void *arg)
|
||||
;
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define ADDR_LEGACY(name) \
|
||||
{ #name, test_addr_ ## name , 0, NULL, NULL }
|
||||
#endif
|
||||
|
||||
struct testcase_t addr_tests[] = {
|
||||
ADDR_LEGACY(basic),
|
||||
|
@ -3813,7 +3813,9 @@ static void
|
||||
test_config_default_fallback_dirs(void *arg)
|
||||
{
|
||||
const char *fallback[] = {
|
||||
#ifndef COCCI
|
||||
#include "app/config/fallback_dirs.inc"
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -1034,12 +1034,14 @@ test_confparse_find_option_name(void *arg)
|
||||
config_mgr_free(mgr);
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define CONFPARSE_TEST(name, flags) \
|
||||
{ #name, test_confparse_ ## name, flags, NULL, NULL }
|
||||
|
||||
#define BADVAL_TEST(name) \
|
||||
{ "badval_" #name, test_confparse_assign_badval, 0, \
|
||||
&passthrough_setup, (void*)&bv_ ## name }
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
struct testcase_t confparse_tests[] = {
|
||||
CONFPARSE_TEST(init, 0),
|
||||
|
@ -881,12 +881,14 @@ test_failed_orconn_tracker(void *arg)
|
||||
;
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define CONNECTION_TESTCASE(name, fork, setup) \
|
||||
{ #name, test_conn_##name, fork, &setup, NULL }
|
||||
|
||||
/* where arg is an expression (constant, variable, compound expression) */
|
||||
#define CONNECTION_TESTCASE_ARG(name, fork, setup, arg) \
|
||||
{ #name "_" #arg, test_conn_##name, fork, &setup, (void *)arg }
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
struct testcase_t connection_tests[] = {
|
||||
CONNECTION_TESTCASE(get_basic, TT_FORK, test_conn_get_basic_st),
|
||||
|
@ -120,6 +120,7 @@ test_controller_parse_cmd(void *arg)
|
||||
control_cmd_args_free(result);
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define OK(inp, out) \
|
||||
{ inp "\r\n", out, NULL }
|
||||
#define ERR(inp, err) \
|
||||
@ -129,6 +130,7 @@ test_controller_parse_cmd(void *arg)
|
||||
{ &syntax, \
|
||||
ARRAY_LENGTH(array), \
|
||||
array }
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
static const parser_testcase_t one_to_three_tests[] = {
|
||||
ERR("", "Need at least 1 argument(s)"),
|
||||
@ -1953,9 +1955,11 @@ test_getinfo_md_all(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define PARSER_TEST(type) \
|
||||
{ "parse/" #type, test_controller_parse_cmd, 0, &passthrough_setup, \
|
||||
(void*)&parse_ ## type ## _params }
|
||||
#endif
|
||||
|
||||
struct testcase_t controller_tests[] = {
|
||||
PARSER_TEST(one_to_three),
|
||||
|
@ -2971,6 +2971,7 @@ test_crypto_failure_modes(void *arg)
|
||||
;
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define CRYPTO_LEGACY(name) \
|
||||
{ #name, test_crypto_ ## name , 0, NULL, NULL }
|
||||
|
||||
@ -2981,6 +2982,7 @@ test_crypto_failure_modes(void *arg)
|
||||
#define ED25519_TEST(name, fl) \
|
||||
ED25519_TEST_ONE(name, (fl), "donna"), \
|
||||
ED25519_TEST_ONE(name, (fl), "ref10")
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
struct testcase_t crypto_tests[] = {
|
||||
CRYPTO_LEGACY(formats),
|
||||
|
@ -584,6 +584,7 @@ test_crypto_ed25519_fuzz_donna(void *arg)
|
||||
;
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define CRYPTO_LEGACY(name) \
|
||||
{ #name, test_crypto_ ## name , 0, NULL, NULL }
|
||||
|
||||
@ -594,6 +595,7 @@ test_crypto_ed25519_fuzz_donna(void *arg)
|
||||
#define ED25519_TEST(name, fl) \
|
||||
ED25519_TEST_ONE(name, (fl), "donna"), \
|
||||
ED25519_TEST_ONE(name, (fl), "ref10")
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
struct testcase_t slow_crypto_tests[] = {
|
||||
CRYPTO_LEGACY(s2k_rfc2440),
|
||||
|
@ -7209,6 +7209,7 @@ test_dir_format_versions_list(void *arg)
|
||||
teardown_capture_of_logs();
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define DIR_LEGACY(name) \
|
||||
{ #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 */
|
||||
#define DIR_ARG(name,flags,arg) \
|
||||
{ #name "_" arg, test_dir_##name, (flags), &passthrough_setup, (void*) arg }
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
struct testcase_t dir_tests[] = {
|
||||
DIR_LEGACY(nicknames),
|
||||
|
@ -3039,6 +3039,7 @@ static const struct testcase_setup_t upgrade_circuits = {
|
||||
upgrade_circuits_setup, upgrade_circuits_cleanup
|
||||
};
|
||||
|
||||
#ifndef COCCI
|
||||
#define NO_PREFIX_TEST(name) \
|
||||
{ #name, test_ ## name, 0, NULL, NULL }
|
||||
|
||||
@ -3061,6 +3062,7 @@ static const struct testcase_setup_t upgrade_circuits = {
|
||||
&upgrade_circuits, (void*)(arg REASONABLY_FUTURE) }, \
|
||||
{ #name "_reasonably_past", test_entry_guard_ ## name, TT_FORK, \
|
||||
&upgrade_circuits, (void*)(arg REASONABLY_PAST) }
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
struct testcase_t entrynodes_tests[] = {
|
||||
NO_PREFIX_TEST(node_preferred_orport),
|
||||
|
@ -1492,6 +1492,7 @@ AUTHENTICATE_FAIL(missing_ed_auth,
|
||||
"authentication certificate";
|
||||
})
|
||||
|
||||
#ifndef COCCI
|
||||
#define TEST_RSA(name, flags) \
|
||||
{ #name , test_link_handshake_ ## name, (flags), \
|
||||
&passthrough_setup, (void*)"RSA" }
|
||||
@ -1527,6 +1528,7 @@ AUTHENTICATE_FAIL(missing_ed_auth,
|
||||
#define TEST_AUTHENTICATE_ED(name) \
|
||||
{ "authenticate/" #name "_ed25519" , test_link_handshake_auth_ ## name, \
|
||||
TT_FORK, &setup_authenticate, (void*)3 }
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
struct testcase_t link_handshake_tests[] = {
|
||||
TEST_RSA(certs_ok, TT_FORK),
|
||||
|
@ -678,7 +678,7 @@ test_options_validate__logs(void *ignored)
|
||||
tt_int_op(ret, OP_EQ, -1);
|
||||
#else
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
#endif
|
||||
#endif /* defined(_WIN32) */
|
||||
|
||||
free_options_test_data(tdata);
|
||||
tdata = get_options_test_data("");
|
||||
@ -4049,8 +4049,10 @@ test_options_init_logs_quiet(void *arg)
|
||||
UNMOCK(add_file_log);
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define LOCAL_VALIDATE_TEST(name) \
|
||||
{ "validate__" #name, test_options_validate__ ## name, TT_FORK, NULL, NULL }
|
||||
#endif
|
||||
|
||||
struct testcase_t options_tests[] = {
|
||||
{ "validate", test_options_validate, TT_FORK, NULL, NULL },
|
||||
|
@ -92,13 +92,13 @@ test_router_dump_router_to_string_no_bridge_distribution_method(void *arg)
|
||||
options->BridgeRelay = 1;
|
||||
|
||||
/* 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, ==, ed25519_keypair_generate(&signing_keypair, 0));
|
||||
tt_int_op(0, OP_EQ, curve25519_keypair_generate(&ntor_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
|
||||
* assertions in router_dump_router_to_string(). */
|
||||
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
|
||||
* 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,
|
||||
&signing_keypair);
|
||||
crypto_pk_free(onion_pkey);
|
||||
tt_ptr_op(desc, !=, NULL);
|
||||
tt_ptr_op(desc, OP_NE, NULL);
|
||||
found = strstr(desc, needle);
|
||||
tt_ptr_op(found, !=, NULL);
|
||||
tt_ptr_op(found, OP_NE, NULL);
|
||||
|
||||
done:
|
||||
NS_UNMOCK(router_get_my_routerinfo);
|
||||
|
@ -848,8 +848,8 @@ test_scheduler_initfree(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
tt_ptr_op(channels_pending, ==, NULL);
|
||||
tt_ptr_op(run_sched_ev, ==, NULL);
|
||||
tt_ptr_op(channels_pending, OP_EQ, NULL);
|
||||
tt_ptr_op(run_sched_ev, OP_EQ, NULL);
|
||||
|
||||
MOCK(get_options, mock_get_options);
|
||||
set_scheduler_options(SCHEDULER_KIST);
|
||||
@ -858,17 +858,17 @@ test_scheduler_initfree(void *arg)
|
||||
|
||||
scheduler_init();
|
||||
|
||||
tt_ptr_op(channels_pending, !=, NULL);
|
||||
tt_ptr_op(run_sched_ev, !=, NULL);
|
||||
tt_ptr_op(channels_pending, OP_NE, NULL);
|
||||
tt_ptr_op(run_sched_ev, OP_NE, NULL);
|
||||
/* We have specified nothing in the torrc and there's no consensus so the
|
||||
* KIST scheduler is what should be in use */
|
||||
tt_ptr_op(the_scheduler, ==, get_kist_scheduler());
|
||||
tt_int_op(sched_run_interval, ==, 10);
|
||||
tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler());
|
||||
tt_int_op(sched_run_interval, OP_EQ, 10);
|
||||
|
||||
scheduler_free_all();
|
||||
|
||||
tt_ptr_op(channels_pending, ==, NULL);
|
||||
tt_ptr_op(run_sched_ev, ==, NULL);
|
||||
tt_ptr_op(channels_pending, OP_EQ, NULL);
|
||||
tt_ptr_op(run_sched_ev, OP_EQ, NULL);
|
||||
|
||||
done:
|
||||
UNMOCK(get_options);
|
||||
@ -890,11 +890,11 @@ test_scheduler_can_use_kist(void *arg)
|
||||
res_should = scheduler_can_use_kist();
|
||||
res_freq = kist_scheduler_run_interval();
|
||||
#ifdef HAVE_KIST_SUPPORT
|
||||
tt_int_op(res_should, ==, 1);
|
||||
tt_int_op(res_should, OP_EQ, 1);
|
||||
#else /* HAVE_KIST_SUPPORT */
|
||||
tt_int_op(res_should, ==, 0);
|
||||
tt_int_op(res_should, OP_EQ, 0);
|
||||
#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 */
|
||||
clear_options();
|
||||
@ -902,11 +902,11 @@ test_scheduler_can_use_kist(void *arg)
|
||||
res_should = scheduler_can_use_kist();
|
||||
res_freq = kist_scheduler_run_interval();
|
||||
#ifdef HAVE_KIST_SUPPORT
|
||||
tt_int_op(res_should, ==, 1);
|
||||
tt_int_op(res_should, OP_EQ, 1);
|
||||
#else /* HAVE_KIST_SUPPORT */
|
||||
tt_int_op(res_should, ==, 0);
|
||||
tt_int_op(res_should, OP_EQ, 0);
|
||||
#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 */
|
||||
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_freq = kist_scheduler_run_interval();
|
||||
#ifdef HAVE_KIST_SUPPORT
|
||||
tt_int_op(res_should, ==, 1);
|
||||
tt_int_op(res_should, OP_EQ, 1);
|
||||
#else /* HAVE_KIST_SUPPORT */
|
||||
tt_int_op(res_should, ==, 0);
|
||||
tt_int_op(res_should, OP_EQ, 0);
|
||||
#endif /* HAVE_KIST_SUPPORT */
|
||||
tt_int_op(res_freq, ==, 12);
|
||||
tt_int_op(res_freq, OP_EQ, 12);
|
||||
UNMOCK(networkstatus_get_param);
|
||||
|
||||
/* Test defer to consensus, and vanilla consensus available */
|
||||
@ -928,8 +928,8 @@ test_scheduler_can_use_kist(void *arg)
|
||||
mocked_options.KISTSchedRunInterval = 0;
|
||||
res_should = scheduler_can_use_kist();
|
||||
res_freq = kist_scheduler_run_interval();
|
||||
tt_int_op(res_should, ==, 0);
|
||||
tt_int_op(res_freq, ==, 0);
|
||||
tt_int_op(res_should, OP_EQ, 0);
|
||||
tt_int_op(res_freq, OP_EQ, 0);
|
||||
UNMOCK(networkstatus_get_param);
|
||||
|
||||
done:
|
||||
@ -956,7 +956,7 @@ test_scheduler_ns_changed(void *arg)
|
||||
set_scheduler_options(SCHEDULER_KIST);
|
||||
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 */
|
||||
the_scheduler = get_vanilla_scheduler();
|
||||
@ -964,9 +964,9 @@ test_scheduler_ns_changed(void *arg)
|
||||
scheduler_notify_networkstatus_changed();
|
||||
UNMOCK(networkstatus_get_param);
|
||||
#ifdef HAVE_KIST_SUPPORT
|
||||
tt_ptr_op(the_scheduler, ==, get_kist_scheduler());
|
||||
tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler());
|
||||
#else
|
||||
tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler());
|
||||
tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler());
|
||||
#endif
|
||||
|
||||
/* 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);
|
||||
scheduler_notify_networkstatus_changed();
|
||||
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 */
|
||||
the_scheduler = get_kist_scheduler();
|
||||
@ -982,9 +982,9 @@ test_scheduler_ns_changed(void *arg)
|
||||
scheduler_notify_networkstatus_changed();
|
||||
UNMOCK(networkstatus_get_param);
|
||||
#ifdef HAVE_KIST_SUPPORT
|
||||
tt_ptr_op(the_scheduler, ==, get_kist_scheduler());
|
||||
tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler());
|
||||
#else
|
||||
tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler());
|
||||
tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler());
|
||||
#endif
|
||||
|
||||
/* 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);
|
||||
scheduler_notify_networkstatus_changed();
|
||||
UNMOCK(networkstatus_get_param);
|
||||
tt_ptr_op(the_scheduler, ==, get_vanilla_scheduler());
|
||||
tt_ptr_op(the_scheduler, OP_EQ, get_vanilla_scheduler());
|
||||
|
||||
done:
|
||||
UNMOCK(get_options);
|
||||
|
@ -304,6 +304,7 @@ test_util_write_chunks_to_file(void *arg)
|
||||
tor_free(temp_str);
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#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
|
||||
* 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_sec ); \
|
||||
TT_STMT_END
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
static void
|
||||
test_util_time(void *arg)
|
||||
@ -6257,6 +6259,7 @@ test_util_map_anon_nofork(void *arg)
|
||||
#endif /* defined(_WIN32) */
|
||||
}
|
||||
|
||||
#ifndef COCCI
|
||||
#define UTIL_LEGACY(name) \
|
||||
{ #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_setup, \
|
||||
(char*)(identifier) }
|
||||
#endif /* !defined(COCCI) */
|
||||
|
||||
#ifdef _WIN32
|
||||
#define UTIL_TEST_NO_WIN(n, f) { #n, NULL, TT_SKIP, NULL, NULL }
|
||||
|
Loading…
Reference in New Issue
Block a user