2009-09-21 20:23:13 +02:00
|
|
|
/* Copyright (c) 2001-2003, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2020-01-09 00:39:17 +01:00
|
|
|
* Copyright (c) 2007-2020, The Tor Project, Inc. */
|
2009-09-21 20:23:13 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_TEST_H
|
|
|
|
#define TOR_TEST_H
|
2009-09-21 20:23:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \file test.h
|
2009-09-22 19:06:47 +02:00
|
|
|
* \brief Macros and functions used by unit tests.
|
2009-09-21 20:23:13 +02:00
|
|
|
*/
|
|
|
|
|
2018-06-03 13:33:31 +02:00
|
|
|
#define DEBUG_SMARTLIST 1
|
|
|
|
|
2009-09-21 20:23:13 +02:00
|
|
|
#include "tinytest.h"
|
|
|
|
#define TT_EXIT_TEST_FUNCTION STMT_BEGIN goto done; STMT_END
|
|
|
|
#include "tinytest_macros.h"
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define PRETTY_FUNCTION __PRETTY_FUNCTION__
|
|
|
|
#else
|
|
|
|
#define PRETTY_FUNCTION ""
|
|
|
|
#endif
|
|
|
|
|
2009-09-27 18:07:33 +02:00
|
|
|
/* As test_mem_op, but decodes 'hex' before comparing. There must be a
|
|
|
|
* local char* variable called mem_op_hex_tmp for this to work. */
|
2009-09-21 20:23:13 +02:00
|
|
|
#define test_mem_op_hex(expr1, op, hex) \
|
|
|
|
STMT_BEGIN \
|
|
|
|
size_t length = strlen(hex); \
|
2009-09-27 18:07:33 +02:00
|
|
|
tor_free(mem_op_hex_tmp); \
|
|
|
|
mem_op_hex_tmp = tor_malloc(length/2); \
|
2009-09-21 20:23:13 +02:00
|
|
|
tor_assert((length&1)==0); \
|
2009-09-27 18:07:33 +02:00
|
|
|
base16_decode(mem_op_hex_tmp, length/2, hex, length); \
|
2014-09-16 03:27:23 +02:00
|
|
|
tt_mem_op(expr1, op, mem_op_hex_tmp, length/2); \
|
2009-09-21 20:23:13 +02:00
|
|
|
STMT_END
|
|
|
|
|
2014-11-12 19:28:07 +01:00
|
|
|
#define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, OP_EQ, hex)
|
2009-09-21 20:23:13 +02:00
|
|
|
|
2019-10-09 19:22:34 +02:00
|
|
|
#ifndef COCCI
|
2012-08-09 19:47:42 +02:00
|
|
|
#define tt_double_op(a,op,b) \
|
2015-02-24 16:05:34 +01:00
|
|
|
tt_assert_test_type(a,b,#a" "#op" "#b,double,(val1_ op val2_),"%g", \
|
2012-08-09 19:47:42 +02:00
|
|
|
TT_EXIT_TEST_FUNCTION)
|
|
|
|
|
2015-08-14 14:48:26 +02:00
|
|
|
/* Declare "double equal" in a sneaky way, so compiler won't complain about
|
|
|
|
* comparing floats with == or !=. Of course, only do this if you know what
|
|
|
|
* you're doing. */
|
|
|
|
#define tt_double_eq(a,b) \
|
|
|
|
STMT_BEGIN \
|
2017-06-05 16:23:02 +02:00
|
|
|
tt_double_op((a), OP_GE, (b)); \
|
|
|
|
tt_double_op((a), OP_LE, (b)); \
|
2015-08-14 14:48:26 +02:00
|
|
|
STMT_END
|
|
|
|
|
2014-05-08 20:01:17 +02:00
|
|
|
#define tt_size_op(a,op,b) \
|
|
|
|
tt_assert_test_fmt_type(a,b,#a" "#op" "#b,size_t,(val1_ op val2_), \
|
2018-07-03 16:26:06 +02:00
|
|
|
size_t, "%"TOR_PRIuSZ, \
|
|
|
|
{print_ = (size_t) value_;}, {}, TT_EXIT_TEST_FUNCTION)
|
2014-05-08 20:01:17 +02:00
|
|
|
|
|
|
|
#define tt_u64_op(a,op,b) \
|
|
|
|
tt_assert_test_fmt_type(a,b,#a" "#op" "#b,uint64_t,(val1_ op val2_), \
|
2018-07-03 16:26:06 +02:00
|
|
|
uint64_t, "%"PRIu64, \
|
|
|
|
{print_ = (uint64_t) value_;}, {}, TT_EXIT_TEST_FUNCTION)
|
2014-05-08 20:01:17 +02:00
|
|
|
|
|
|
|
#define tt_i64_op(a,op,b) \
|
2018-07-03 16:26:06 +02:00
|
|
|
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)
|
2019-10-22 15:40:31 +02:00
|
|
|
#endif /* !defined(COCCI) */
|
2014-05-08 20:01:17 +02:00
|
|
|
|
2018-03-30 01:27:42 +02:00
|
|
|
/**
|
|
|
|
* Declare that the test is done, even though no tt___op() calls were made.
|
|
|
|
*
|
|
|
|
* For use when you only want to test calling something, but not check
|
|
|
|
* any values/pointers/etc afterwards.
|
|
|
|
*/
|
|
|
|
#define tt_finished() TT_EXIT_TEST_FUNCTION
|
|
|
|
|
2009-09-22 19:06:47 +02:00
|
|
|
const char *get_fname(const char *name);
|
2016-11-02 04:14:19 +01:00
|
|
|
const char *get_fname_rnd(const char *name);
|
2016-02-12 00:34:29 +01:00
|
|
|
struct crypto_pk_t *pk_generate(int idx);
|
2016-09-11 18:36:09 +02:00
|
|
|
void init_pregenerated_keys(void);
|
|
|
|
void free_pregenerated_keys(void);
|
2009-09-22 19:06:47 +02:00
|
|
|
|
2013-09-28 05:15:53 +02:00
|
|
|
extern const struct testcase_setup_t passthrough_setup;
|
2016-09-09 16:20:34 +02:00
|
|
|
extern const struct testcase_setup_t ed25519_test_setup;
|
2013-09-28 05:15:53 +02:00
|
|
|
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t accounting_tests[];
|
|
|
|
extern struct testcase_t addr_tests[];
|
2018-02-08 20:35:22 +01:00
|
|
|
extern struct testcase_t address_set_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t address_tests[];
|
2018-03-05 21:43:26 +01:00
|
|
|
extern struct testcase_t bridges_tests[];
|
2018-12-20 16:21:16 +01:00
|
|
|
extern struct testcase_t btrack_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t buffer_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t bwmgt_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t cell_format_tests[];
|
|
|
|
extern struct testcase_t cell_queue_tests[];
|
|
|
|
extern struct testcase_t channel_tests[];
|
2016-09-06 20:35:53 +02:00
|
|
|
extern struct testcase_t channelpadding_tests[];
|
2019-01-02 14:19:12 +01:00
|
|
|
extern struct testcase_t circuitpadding_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t channeltls_tests[];
|
|
|
|
extern struct testcase_t checkdir_tests[];
|
2017-03-28 23:34:54 +02:00
|
|
|
extern struct testcase_t circuitbuild_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t circuitlist_tests[];
|
|
|
|
extern struct testcase_t circuitmux_tests[];
|
2019-10-28 18:15:56 +01:00
|
|
|
extern struct testcase_t circuitmux_ewma_tests[];
|
2017-09-20 22:24:59 +02:00
|
|
|
extern struct testcase_t circuitstats_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t circuituse_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t compat_libevent_tests[];
|
|
|
|
extern struct testcase_t config_tests[];
|
2019-08-27 15:44:30 +02:00
|
|
|
extern struct testcase_t confmgr_tests[];
|
2019-06-15 17:24:43 +02:00
|
|
|
extern struct testcase_t confparse_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t connection_tests[];
|
2017-04-04 19:51:34 +02:00
|
|
|
extern struct testcase_t conscache_tests[];
|
2017-03-07 15:58:30 +01:00
|
|
|
extern struct testcase_t consdiff_tests[];
|
2017-04-14 18:35:02 +02:00
|
|
|
extern struct testcase_t consdiffmgr_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t container_tests[];
|
|
|
|
extern struct testcase_t controller_event_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t controller_tests[];
|
2018-05-10 14:46:36 +02:00
|
|
|
extern struct testcase_t crypto_ope_tests[];
|
2017-03-25 12:04:11 +01:00
|
|
|
extern struct testcase_t crypto_openssl_tests[];
|
2019-02-06 18:28:05 +01:00
|
|
|
extern struct testcase_t crypto_rng_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t crypto_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t dir_handle_get_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t dir_tests[];
|
2019-01-12 02:17:04 +01:00
|
|
|
extern struct testcase_t dispatch_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t dns_tests[];
|
2018-01-30 15:33:12 +01:00
|
|
|
extern struct testcase_t dos_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t entryconn_tests[];
|
|
|
|
extern struct testcase_t entrynodes_tests[];
|
|
|
|
extern struct testcase_t extorport_tests[];
|
2018-03-15 14:47:01 +01:00
|
|
|
extern struct testcase_t geoip_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t guardfraction_tests[];
|
|
|
|
extern struct testcase_t handle_tests[];
|
2016-08-10 22:40:06 +02:00
|
|
|
extern struct testcase_t hs_cache[];
|
2017-04-20 15:58:21 +02:00
|
|
|
extern struct testcase_t hs_cell_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t hs_client_tests[];
|
2017-04-20 17:20:02 +02:00
|
|
|
extern struct testcase_t hs_common_tests[];
|
2017-01-13 17:20:31 +01:00
|
|
|
extern struct testcase_t hs_config_tests[];
|
2017-11-20 18:10:07 +01:00
|
|
|
extern struct testcase_t hs_control_tests[];
|
2016-03-15 19:18:03 +01:00
|
|
|
extern struct testcase_t hs_descriptor[];
|
2019-05-30 14:55:40 +02:00
|
|
|
extern struct testcase_t hs_dos_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t hs_intropoint_tests[];
|
2017-04-20 16:04:28 +02:00
|
|
|
extern struct testcase_t hs_ntor_tests[];
|
2016-09-05 18:03:30 +02:00
|
|
|
extern struct testcase_t hs_service_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t hs_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t introduce_tests[];
|
|
|
|
extern struct testcase_t keypin_tests[];
|
|
|
|
extern struct testcase_t link_handshake_tests[];
|
|
|
|
extern struct testcase_t logging_tests[];
|
2018-05-03 16:53:19 +02:00
|
|
|
extern struct testcase_t mainloop_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t microdesc_tests[];
|
2018-10-25 18:04:19 +02:00
|
|
|
extern struct testcase_t namemap_tests[];
|
2018-12-18 10:58:40 +01:00
|
|
|
extern struct testcase_t netinfo_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t nodelist_tests[];
|
|
|
|
extern struct testcase_t oom_tests[];
|
2016-07-02 06:39:45 +02:00
|
|
|
extern struct testcase_t oos_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t options_tests[];
|
2019-11-19 17:52:10 +01:00
|
|
|
extern struct testcase_t options_act_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t parsecommon_tests[];
|
2018-07-19 21:47:48 +02:00
|
|
|
extern struct testcase_t pem_tests[];
|
2018-04-18 20:50:07 +02:00
|
|
|
extern struct testcase_t periodic_event_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t policy_tests[];
|
2018-11-27 00:56:23 +01:00
|
|
|
extern struct testcase_t prob_distr_tests[];
|
|
|
|
extern struct testcase_t slow_stochastic_prob_distr_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t procmon_tests[];
|
2018-11-22 04:25:11 +01:00
|
|
|
extern struct testcase_t process_tests[];
|
2019-08-29 17:45:41 +02:00
|
|
|
extern struct testcase_t process_descs_tests[];
|
2019-09-10 09:32:08 +02:00
|
|
|
extern struct testcase_t proto_haproxy_tests[];
|
2017-09-28 03:45:55 +02:00
|
|
|
extern struct testcase_t proto_http_tests[];
|
2017-09-27 15:09:00 +02:00
|
|
|
extern struct testcase_t proto_misc_tests[];
|
2016-08-10 01:11:47 +02:00
|
|
|
extern struct testcase_t protover_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t pt_tests[];
|
2019-01-14 17:29:21 +01:00
|
|
|
extern struct testcase_t pubsub_build_tests[];
|
2019-01-15 15:01:20 +01:00
|
|
|
extern struct testcase_t pubsub_msg_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t relay_tests[];
|
|
|
|
extern struct testcase_t relaycell_tests[];
|
2018-03-17 16:23:05 +01:00
|
|
|
extern struct testcase_t relaycrypt_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t rend_cache_tests[];
|
|
|
|
extern struct testcase_t replaycache_tests[];
|
|
|
|
extern struct testcase_t router_tests[];
|
|
|
|
extern struct testcase_t routerkeys_tests[];
|
|
|
|
extern struct testcase_t routerlist_tests[];
|
|
|
|
extern struct testcase_t routerset_tests[];
|
|
|
|
extern struct testcase_t scheduler_tests[];
|
2019-02-19 20:49:38 +01:00
|
|
|
extern struct testcase_t sendme_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t socks_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t sr_tests[];
|
2019-10-31 06:56:50 +01:00
|
|
|
extern struct testcase_t stats_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t status_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t storagedir_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t thread_tests[];
|
2019-05-29 17:34:07 +02:00
|
|
|
extern struct testcase_t token_bucket_tests[];
|
2018-08-12 22:04:12 +02:00
|
|
|
extern struct testcase_t tortls_openssl_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t tortls_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
extern struct testcase_t util_format_tests[];
|
|
|
|
extern struct testcase_t util_process_tests[];
|
2018-10-24 15:09:40 +02:00
|
|
|
extern struct testcase_t util_tests[];
|
2018-12-03 19:22:23 +01:00
|
|
|
extern struct testcase_t voting_flags_tests[];
|
2018-05-07 02:42:18 +02:00
|
|
|
extern struct testcase_t voting_schedule_tests[];
|
2018-08-23 20:03:00 +02:00
|
|
|
extern struct testcase_t x509_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
|
|
|
|
extern struct testcase_t slow_crypto_tests[];
|
2018-11-26 02:18:04 +01:00
|
|
|
extern struct testcase_t slow_process_tests[];
|
2019-02-25 18:07:47 +01:00
|
|
|
extern struct testcase_t slow_ptr_tests[];
|
2016-06-02 15:46:12 +02:00
|
|
|
|
|
|
|
extern struct testgroup_t testgroups[];
|
|
|
|
|
|
|
|
extern const char AUTHORITY_CERT_1[];
|
|
|
|
extern const char AUTHORITY_SIGNKEY_1[];
|
|
|
|
extern const char AUTHORITY_SIGNKEY_A_DIGEST[];
|
|
|
|
extern const char AUTHORITY_SIGNKEY_A_DIGEST256[];
|
|
|
|
extern const char AUTHORITY_CERT_2[];
|
|
|
|
extern const char AUTHORITY_SIGNKEY_2[];
|
|
|
|
extern const char AUTHORITY_SIGNKEY_B_DIGEST[];
|
|
|
|
extern const char AUTHORITY_SIGNKEY_B_DIGEST256[];
|
|
|
|
extern const char AUTHORITY_CERT_3[];
|
|
|
|
extern const char AUTHORITY_SIGNKEY_3[];
|
|
|
|
extern const char AUTHORITY_SIGNKEY_C_DIGEST[];
|
|
|
|
extern const char AUTHORITY_SIGNKEY_C_DIGEST256[];
|
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_TEST_H) */
|