12b15cb3dSCy Schubert /* 22b15cb3dSCy Schubert * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 32b15cb3dSCy Schubert * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 42b15cb3dSCy Schubert * 52b15cb3dSCy Schubert * Redistribution and use in source and binary forms, with or without 62b15cb3dSCy Schubert * modification, are permitted provided that the following conditions 72b15cb3dSCy Schubert * are met: 82b15cb3dSCy Schubert * 1. Redistributions of source code must retain the above copyright 92b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer. 102b15cb3dSCy Schubert * 2. Redistributions in binary form must reproduce the above copyright 112b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer in the 122b15cb3dSCy Schubert * documentation and/or other materials provided with the distribution. 132b15cb3dSCy Schubert * 3. The name of the author may not be used to endorse or promote products 142b15cb3dSCy Schubert * derived from this software without specific prior written permission. 152b15cb3dSCy Schubert * 162b15cb3dSCy Schubert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 172b15cb3dSCy Schubert * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 182b15cb3dSCy Schubert * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 192b15cb3dSCy Schubert * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 202b15cb3dSCy Schubert * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 212b15cb3dSCy Schubert * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222b15cb3dSCy Schubert * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232b15cb3dSCy Schubert * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242b15cb3dSCy Schubert * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 252b15cb3dSCy Schubert * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262b15cb3dSCy Schubert */ 272b15cb3dSCy Schubert #ifndef REGRESS_H_INCLUDED_ 282b15cb3dSCy Schubert #define REGRESS_H_INCLUDED_ 292b15cb3dSCy Schubert 302b15cb3dSCy Schubert #ifdef __cplusplus 312b15cb3dSCy Schubert extern "C" { 322b15cb3dSCy Schubert #endif 332b15cb3dSCy Schubert 342b15cb3dSCy Schubert #include "tinytest.h" 352b15cb3dSCy Schubert #include "tinytest_macros.h" 362b15cb3dSCy Schubert 372b15cb3dSCy Schubert extern struct testcase_t main_testcases[]; 382b15cb3dSCy Schubert extern struct testcase_t evtag_testcases[]; 392b15cb3dSCy Schubert extern struct testcase_t evbuffer_testcases[]; 402b15cb3dSCy Schubert extern struct testcase_t finalize_testcases[]; 412b15cb3dSCy Schubert extern struct testcase_t bufferevent_testcases[]; 422b15cb3dSCy Schubert extern struct testcase_t bufferevent_iocp_testcases[]; 432b15cb3dSCy Schubert extern struct testcase_t util_testcases[]; 442b15cb3dSCy Schubert extern struct testcase_t signal_testcases[]; 452b15cb3dSCy Schubert extern struct testcase_t http_testcases[]; 46*a466cc55SCy Schubert extern struct testcase_t http_iocp_testcases[]; 472b15cb3dSCy Schubert extern struct testcase_t dns_testcases[]; 482b15cb3dSCy Schubert extern struct testcase_t rpc_testcases[]; 492b15cb3dSCy Schubert extern struct testcase_t edgetriggered_testcases[]; 502b15cb3dSCy Schubert extern struct testcase_t minheap_testcases[]; 512b15cb3dSCy Schubert extern struct testcase_t iocp_testcases[]; 522b15cb3dSCy Schubert extern struct testcase_t ssl_testcases[]; 532b15cb3dSCy Schubert extern struct testcase_t listener_testcases[]; 542b15cb3dSCy Schubert extern struct testcase_t listener_iocp_testcases[]; 552b15cb3dSCy Schubert extern struct testcase_t thread_testcases[]; 562b15cb3dSCy Schubert 57a25439b6SCy Schubert extern struct evutil_weakrand_state test_weakrand_state; 58a25439b6SCy Schubert 59a25439b6SCy Schubert #define test_weakrand() (evutil_weakrand_(&test_weakrand_state)) 60a25439b6SCy Schubert 612b15cb3dSCy Schubert void regress_threads(void *); 622b15cb3dSCy Schubert void test_bufferevent_zlib(void *); 632b15cb3dSCy Schubert 642b15cb3dSCy Schubert /* Helpers to wrap old testcases */ 652b15cb3dSCy Schubert extern evutil_socket_t pair[2]; 662b15cb3dSCy Schubert extern int test_ok; 672b15cb3dSCy Schubert extern int called; 682b15cb3dSCy Schubert extern struct event_base *global_base; 692b15cb3dSCy Schubert extern int in_legacy_test_wrapper; 702b15cb3dSCy Schubert 712b15cb3dSCy Schubert int regress_make_tmpfile(const void *data, size_t datalen, char **filename_out); 722b15cb3dSCy Schubert 732b15cb3dSCy Schubert struct basic_test_data { 742b15cb3dSCy Schubert struct event_base *base; 752b15cb3dSCy Schubert evutil_socket_t pair[2]; 762b15cb3dSCy Schubert 772b15cb3dSCy Schubert void (*legacy_test_fn)(void); 782b15cb3dSCy Schubert 792b15cb3dSCy Schubert void *setup_data; 802b15cb3dSCy Schubert }; 812b15cb3dSCy Schubert extern const struct testcase_setup_t basic_setup; 822b15cb3dSCy Schubert 832b15cb3dSCy Schubert 842b15cb3dSCy Schubert extern const struct testcase_setup_t legacy_setup; 852b15cb3dSCy Schubert void run_legacy_test_fn(void *ptr); 862b15cb3dSCy Schubert 872b15cb3dSCy Schubert extern int libevent_tests_running_in_debug_mode; 882b15cb3dSCy Schubert 892b15cb3dSCy Schubert /* A couple of flags that basic/legacy_setup can support. */ 902b15cb3dSCy Schubert #define TT_NEED_SOCKETPAIR TT_FIRST_USER_FLAG 912b15cb3dSCy Schubert #define TT_NEED_BASE (TT_FIRST_USER_FLAG<<1) 922b15cb3dSCy Schubert #define TT_NEED_DNS (TT_FIRST_USER_FLAG<<2) 932b15cb3dSCy Schubert #define TT_LEGACY (TT_FIRST_USER_FLAG<<3) 942b15cb3dSCy Schubert #define TT_NEED_THREADS (TT_FIRST_USER_FLAG<<4) 952b15cb3dSCy Schubert #define TT_NO_LOGS (TT_FIRST_USER_FLAG<<5) 962b15cb3dSCy Schubert #define TT_ENABLE_IOCP_FLAG (TT_FIRST_USER_FLAG<<6) 972b15cb3dSCy Schubert #define TT_ENABLE_IOCP (TT_ENABLE_IOCP_FLAG|TT_NEED_THREADS) 98*a466cc55SCy Schubert #define TT_ENABLE_DEBUG_MODE (TT_ENABLE_IOCP_FLAG<<7) 992b15cb3dSCy Schubert 1002b15cb3dSCy Schubert /* All the flags that a legacy test needs. */ 1012b15cb3dSCy Schubert #define TT_ISOLATED TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE 1022b15cb3dSCy Schubert 1032b15cb3dSCy Schubert 1042b15cb3dSCy Schubert #define BASIC(name,flags) \ 1052b15cb3dSCy Schubert { #name, test_## name, flags, &basic_setup, NULL } 1062b15cb3dSCy Schubert 1072b15cb3dSCy Schubert #define LEGACY(name,flags) \ 1082b15cb3dSCy Schubert { #name, run_legacy_test_fn, flags|TT_LEGACY, &legacy_setup, \ 1092b15cb3dSCy Schubert test_## name } 1102b15cb3dSCy Schubert 1112b15cb3dSCy Schubert struct evutil_addrinfo; 1122b15cb3dSCy Schubert struct evutil_addrinfo *ai_find_by_family(struct evutil_addrinfo *ai, int f); 1132b15cb3dSCy Schubert struct evutil_addrinfo *ai_find_by_protocol(struct evutil_addrinfo *ai, int p); 1142b15cb3dSCy Schubert int test_ai_eq_(const struct evutil_addrinfo *ai, const char *sockaddr_port, 1152b15cb3dSCy Schubert int socktype, int protocol, int line); 1162b15cb3dSCy Schubert 1172b15cb3dSCy Schubert #define test_ai_eq(ai, str, s, p) do { \ 1182b15cb3dSCy Schubert if (test_ai_eq_((ai), (str), (s), (p), __LINE__)<0) \ 1192b15cb3dSCy Schubert goto end; \ 1202b15cb3dSCy Schubert } while (0) 1212b15cb3dSCy Schubert 1222b15cb3dSCy Schubert #define test_timeval_diff_leq(tv1, tv2, diff, tolerance) \ 123a25439b6SCy Schubert tt_int_op(labs(timeval_msec_diff((tv1), (tv2)) - diff), <=, tolerance) 1242b15cb3dSCy Schubert 1252b15cb3dSCy Schubert #define test_timeval_diff_eq(tv1, tv2, diff) \ 1262b15cb3dSCy Schubert test_timeval_diff_leq((tv1), (tv2), (diff), 50) 1272b15cb3dSCy Schubert 1282b15cb3dSCy Schubert long timeval_msec_diff(const struct timeval *start, const struct timeval *end); 1292b15cb3dSCy Schubert 1302b15cb3dSCy Schubert #ifndef _WIN32 1312b15cb3dSCy Schubert pid_t regress_fork(void); 1322b15cb3dSCy Schubert #endif 1332b15cb3dSCy Schubert 134*a466cc55SCy Schubert #ifdef EVENT__HAVE_OPENSSL 135*a466cc55SCy Schubert #include <openssl/ssl.h> 136*a466cc55SCy Schubert EVP_PKEY *ssl_getkey(void); 137*a466cc55SCy Schubert X509 *ssl_getcert(EVP_PKEY *key); 138*a466cc55SCy Schubert SSL_CTX *get_ssl_ctx(void); 139*a466cc55SCy Schubert void init_ssl(void); 140*a466cc55SCy Schubert #endif 141*a466cc55SCy Schubert 142*a466cc55SCy Schubert void * basic_test_setup(const struct testcase_t *testcase); 143*a466cc55SCy Schubert int basic_test_cleanup(const struct testcase_t *testcase, void *ptr); 144*a466cc55SCy Schubert 1452b15cb3dSCy Schubert #ifdef __cplusplus 1462b15cb3dSCy Schubert } 1472b15cb3dSCy Schubert #endif 1482b15cb3dSCy Schubert 1492b15cb3dSCy Schubert #endif /* REGRESS_H_INCLUDED_ */ 150