Merge branch 'maint-0.4.5' into release-0.4.5
[tor.git] / src / test / test.h
blob56037648d348adfdcdfee16bfc7b08925860411a
1 /* Copyright (c) 2001-2003, Roger Dingledine.
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2020, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 #ifndef TOR_TEST_H
7 #define TOR_TEST_H
9 /**
10 * \file test.h
11 * \brief Macros and functions used by unit tests.
14 #define DEBUG_SMARTLIST 1
16 #include "tinytest.h"
17 #define TT_EXIT_TEST_FUNCTION STMT_BEGIN goto done; STMT_END
18 #include "tinytest_macros.h"
20 #ifdef __GNUC__
21 #define PRETTY_FUNCTION __PRETTY_FUNCTION__
22 #else
23 #define PRETTY_FUNCTION ""
24 #endif
26 /* As test_mem_op, but decodes 'hex' before comparing. There must be a
27 * local char* variable called mem_op_hex_tmp for this to work. */
28 #define test_mem_op_hex(expr1, op, hex) \
29 STMT_BEGIN \
30 size_t length = strlen(hex); \
31 tor_free(mem_op_hex_tmp); \
32 mem_op_hex_tmp = tor_malloc(length/2); \
33 tor_assert((length&1)==0); \
34 base16_decode(mem_op_hex_tmp, length/2, hex, length); \
35 tt_mem_op(expr1, op, mem_op_hex_tmp, length/2); \
36 STMT_END
38 #define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, OP_EQ, hex)
40 #ifndef COCCI
41 #define tt_double_op(a,op,b) \
42 tt_assert_test_type(a,b,#a" "#op" "#b,double,(val1_ op val2_),"%g", \
43 TT_EXIT_TEST_FUNCTION)
45 /* Declare "double equal" in a sneaky way, so compiler won't complain about
46 * comparing floats with == or !=. Of course, only do this if you know what
47 * you're doing. */
48 #define tt_double_eq(a,b) \
49 STMT_BEGIN \
50 tt_double_op((a), OP_GE, (b)); \
51 tt_double_op((a), OP_LE, (b)); \
52 STMT_END
54 #define tt_size_op(a,op,b) \
55 tt_assert_test_fmt_type(a,b,#a" "#op" "#b,size_t,(val1_ op val2_), \
56 size_t, "%"TOR_PRIuSZ, \
57 {print_ = (size_t) value_;}, {}, TT_EXIT_TEST_FUNCTION)
59 #define tt_u64_op(a,op,b) \
60 tt_assert_test_fmt_type(a,b,#a" "#op" "#b,uint64_t,(val1_ op val2_), \
61 uint64_t, "%"PRIu64, \
62 {print_ = (uint64_t) value_;}, {}, TT_EXIT_TEST_FUNCTION)
64 #define tt_i64_op(a,op,b) \
65 tt_assert_test_fmt_type(a,b,#a" "#op" "#b,int64_t,(val1_ op val2_), \
66 int64_t, "%"PRId64, \
67 {print_ = (int64_t) value_;}, {}, TT_EXIT_TEST_FUNCTION)
68 #endif /* !defined(COCCI) */
70 /**
71 * Declare that the test is done, even though no tt___op() calls were made.
73 * For use when you only want to test calling something, but not check
74 * any values/pointers/etc afterwards.
76 #define tt_finished() TT_EXIT_TEST_FUNCTION
78 const char *get_fname(const char *name);
79 const char *get_fname_rnd(const char *name);
80 struct crypto_pk_t *pk_generate(int idx);
81 void init_pregenerated_keys(void);
82 void free_pregenerated_keys(void);
84 extern const struct testcase_setup_t passthrough_setup;
85 extern const struct testcase_setup_t ed25519_test_setup;
87 extern struct testcase_t accounting_tests[];
88 extern struct testcase_t addr_tests[];
89 extern struct testcase_t address_set_tests[];
90 extern struct testcase_t address_tests[];
91 extern struct testcase_t bridges_tests[];
92 extern struct testcase_t btrack_tests[];
93 extern struct testcase_t buffer_tests[];
94 extern struct testcase_t bwmgt_tests[];
95 extern struct testcase_t cell_format_tests[];
96 extern struct testcase_t cell_queue_tests[];
97 extern struct testcase_t channel_tests[];
98 extern struct testcase_t channelpadding_tests[];
99 extern struct testcase_t circuitpadding_tests[];
100 extern struct testcase_t channeltls_tests[];
101 extern struct testcase_t checkdir_tests[];
102 extern struct testcase_t circuitbuild_tests[];
103 extern struct testcase_t circuitlist_tests[];
104 extern struct testcase_t circuitmux_tests[];
105 extern struct testcase_t circuitmux_ewma_tests[];
106 extern struct testcase_t circuitstats_tests[];
107 extern struct testcase_t circuituse_tests[];
108 extern struct testcase_t compat_libevent_tests[];
109 extern struct testcase_t config_tests[];
110 extern struct testcase_t confmgr_tests[];
111 extern struct testcase_t confparse_tests[];
112 extern struct testcase_t connection_tests[];
113 extern struct testcase_t conscache_tests[];
114 extern struct testcase_t consdiff_tests[];
115 extern struct testcase_t consdiffmgr_tests[];
116 extern struct testcase_t container_tests[];
117 extern struct testcase_t controller_event_tests[];
118 extern struct testcase_t controller_tests[];
119 extern struct testcase_t crypto_ope_tests[];
120 extern struct testcase_t crypto_openssl_tests[];
121 extern struct testcase_t crypto_rng_tests[];
122 extern struct testcase_t crypto_tests[];
123 extern struct testcase_t dir_handle_get_tests[];
124 extern struct testcase_t dir_tests[];
125 extern struct testcase_t dirvote_tests[];
126 extern struct testcase_t dispatch_tests[];
127 extern struct testcase_t dns_tests[];
128 extern struct testcase_t dos_tests[];
129 extern struct testcase_t entryconn_tests[];
130 extern struct testcase_t entrynodes_tests[];
131 extern struct testcase_t extorport_tests[];
132 extern struct testcase_t geoip_tests[];
133 extern struct testcase_t guardfraction_tests[];
134 extern struct testcase_t handle_tests[];
135 extern struct testcase_t hs_cache[];
136 extern struct testcase_t hs_cell_tests[];
137 extern struct testcase_t hs_client_tests[];
138 extern struct testcase_t hs_common_tests[];
139 extern struct testcase_t hs_config_tests[];
140 extern struct testcase_t hs_control_tests[];
141 extern struct testcase_t hs_descriptor[];
142 extern struct testcase_t hs_dos_tests[];
143 extern struct testcase_t hs_intropoint_tests[];
144 extern struct testcase_t hs_metrics_tests[];
145 extern struct testcase_t hs_ntor_tests[];
146 extern struct testcase_t hs_ob_tests[];
147 extern struct testcase_t hs_service_tests[];
148 extern struct testcase_t hs_tests[];
149 extern struct testcase_t introduce_tests[];
150 extern struct testcase_t keypin_tests[];
151 extern struct testcase_t link_handshake_tests[];
152 extern struct testcase_t logging_tests[];
153 extern struct testcase_t mainloop_tests[];
154 extern struct testcase_t metrics_tests[];
155 extern struct testcase_t microdesc_tests[];
156 extern struct testcase_t namemap_tests[];
157 extern struct testcase_t netinfo_tests[];
158 extern struct testcase_t nodelist_tests[];
159 extern struct testcase_t oom_tests[];
160 extern struct testcase_t oos_tests[];
161 extern struct testcase_t options_tests[];
162 extern struct testcase_t options_act_tests[];
163 extern struct testcase_t parsecommon_tests[];
164 extern struct testcase_t pem_tests[];
165 extern struct testcase_t periodic_event_tests[];
166 extern struct testcase_t policy_tests[];
167 extern struct testcase_t prob_distr_tests[];
168 extern struct testcase_t slow_stochastic_prob_distr_tests[];
169 extern struct testcase_t procmon_tests[];
170 extern struct testcase_t process_tests[];
171 extern struct testcase_t process_descs_tests[];
172 extern struct testcase_t proto_haproxy_tests[];
173 extern struct testcase_t proto_http_tests[];
174 extern struct testcase_t proto_misc_tests[];
175 extern struct testcase_t protover_tests[];
176 extern struct testcase_t pt_tests[];
177 extern struct testcase_t pubsub_build_tests[];
178 extern struct testcase_t pubsub_msg_tests[];
179 extern struct testcase_t relay_tests[];
180 extern struct testcase_t relaycell_tests[];
181 extern struct testcase_t relaycrypt_tests[];
182 extern struct testcase_t rend_cache_tests[];
183 extern struct testcase_t replaycache_tests[];
184 extern struct testcase_t router_tests[];
185 extern struct testcase_t routerkeys_tests[];
186 extern struct testcase_t routerlist_tests[];
187 extern struct testcase_t routerset_tests[];
188 extern struct testcase_t scheduler_tests[];
189 extern struct testcase_t sendme_tests[];
190 extern struct testcase_t socks_tests[];
191 extern struct testcase_t sr_tests[];
192 extern struct testcase_t statefile_tests[];
193 extern struct testcase_t stats_tests[];
194 extern struct testcase_t status_tests[];
195 extern struct testcase_t storagedir_tests[];
196 extern struct testcase_t thread_tests[];
197 extern struct testcase_t token_bucket_tests[];
198 extern struct testcase_t tortls_openssl_tests[];
199 extern struct testcase_t tortls_tests[];
200 extern struct testcase_t util_format_tests[];
201 extern struct testcase_t util_process_tests[];
202 extern struct testcase_t util_tests[];
203 extern struct testcase_t voting_flags_tests[];
204 extern struct testcase_t voting_schedule_tests[];
205 extern struct testcase_t x509_tests[];
207 extern struct testcase_t slow_crypto_tests[];
208 extern struct testcase_t slow_process_tests[];
209 extern struct testcase_t slow_ptr_tests[];
211 extern struct testgroup_t testgroups[];
213 extern const char AUTHORITY_CERT_1[];
214 extern const char AUTHORITY_SIGNKEY_1[];
215 extern const char AUTHORITY_SIGNKEY_A_DIGEST[];
216 extern const char AUTHORITY_SIGNKEY_A_DIGEST256[];
217 extern const char AUTHORITY_CERT_2[];
218 extern const char AUTHORITY_SIGNKEY_2[];
219 extern const char AUTHORITY_SIGNKEY_B_DIGEST[];
220 extern const char AUTHORITY_SIGNKEY_B_DIGEST256[];
221 extern const char AUTHORITY_CERT_3[];
222 extern const char AUTHORITY_SIGNKEY_3[];
223 extern const char AUTHORITY_SIGNKEY_C_DIGEST[];
224 extern const char AUTHORITY_SIGNKEY_C_DIGEST256[];
226 #endif /* !defined(TOR_TEST_H) */