1c43e99fdSEd Maste /* 2c43e99fdSEd Maste * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 3c43e99fdSEd Maste * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4c43e99fdSEd Maste * 5c43e99fdSEd Maste * Redistribution and use in source and binary forms, with or without 6c43e99fdSEd Maste * modification, are permitted provided that the following conditions 7c43e99fdSEd Maste * are met: 8c43e99fdSEd Maste * 1. Redistributions of source code must retain the above copyright 9c43e99fdSEd Maste * notice, this list of conditions and the following disclaimer. 10c43e99fdSEd Maste * 2. Redistributions in binary form must reproduce the above copyright 11c43e99fdSEd Maste * notice, this list of conditions and the following disclaimer in the 12c43e99fdSEd Maste * documentation and/or other materials provided with the distribution. 13c43e99fdSEd Maste * 3. The name of the author may not be used to endorse or promote products 14c43e99fdSEd Maste * derived from this software without specific prior written permission. 15c43e99fdSEd Maste * 16c43e99fdSEd Maste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17c43e99fdSEd Maste * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18c43e99fdSEd Maste * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19c43e99fdSEd Maste * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20c43e99fdSEd Maste * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21c43e99fdSEd Maste * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22c43e99fdSEd Maste * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23c43e99fdSEd Maste * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24c43e99fdSEd Maste * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25c43e99fdSEd Maste * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26c43e99fdSEd Maste */ 27c43e99fdSEd Maste #ifndef REGRESS_H_INCLUDED_ 28c43e99fdSEd Maste #define REGRESS_H_INCLUDED_ 29c43e99fdSEd Maste 30c43e99fdSEd Maste #ifdef __cplusplus 31c43e99fdSEd Maste extern "C" { 32c43e99fdSEd Maste #endif 33c43e99fdSEd Maste 34c43e99fdSEd Maste #include "tinytest.h" 35c43e99fdSEd Maste #include "tinytest_macros.h" 36c43e99fdSEd Maste 37c43e99fdSEd Maste extern struct testcase_t main_testcases[]; 38c43e99fdSEd Maste extern struct testcase_t evtag_testcases[]; 39c43e99fdSEd Maste extern struct testcase_t evbuffer_testcases[]; 40c43e99fdSEd Maste extern struct testcase_t finalize_testcases[]; 41c43e99fdSEd Maste extern struct testcase_t bufferevent_testcases[]; 42c43e99fdSEd Maste extern struct testcase_t bufferevent_iocp_testcases[]; 43c43e99fdSEd Maste extern struct testcase_t util_testcases[]; 44c43e99fdSEd Maste extern struct testcase_t signal_testcases[]; 45c43e99fdSEd Maste extern struct testcase_t http_testcases[]; 46*b50261e2SCy Schubert extern struct testcase_t http_iocp_testcases[]; 47c43e99fdSEd Maste extern struct testcase_t dns_testcases[]; 48c43e99fdSEd Maste extern struct testcase_t rpc_testcases[]; 49c43e99fdSEd Maste extern struct testcase_t edgetriggered_testcases[]; 50c43e99fdSEd Maste extern struct testcase_t minheap_testcases[]; 51c43e99fdSEd Maste extern struct testcase_t iocp_testcases[]; 52c43e99fdSEd Maste extern struct testcase_t ssl_testcases[]; 53c43e99fdSEd Maste extern struct testcase_t listener_testcases[]; 54c43e99fdSEd Maste extern struct testcase_t listener_iocp_testcases[]; 55c43e99fdSEd Maste extern struct testcase_t thread_testcases[]; 56c43e99fdSEd Maste 57c43e99fdSEd Maste extern struct evutil_weakrand_state test_weakrand_state; 58c43e99fdSEd Maste 59c43e99fdSEd Maste #define test_weakrand() (evutil_weakrand_(&test_weakrand_state)) 60c43e99fdSEd Maste 61c43e99fdSEd Maste void regress_threads(void *); 62c43e99fdSEd Maste void test_bufferevent_zlib(void *); 63c43e99fdSEd Maste 64c43e99fdSEd Maste /* Helpers to wrap old testcases */ 65c43e99fdSEd Maste extern evutil_socket_t pair[2]; 66c43e99fdSEd Maste extern int test_ok; 67c43e99fdSEd Maste extern int called; 68c43e99fdSEd Maste extern struct event_base *global_base; 69c43e99fdSEd Maste extern int in_legacy_test_wrapper; 70c43e99fdSEd Maste 71c43e99fdSEd Maste int regress_make_tmpfile(const void *data, size_t datalen, char **filename_out); 72c43e99fdSEd Maste 73c43e99fdSEd Maste struct basic_test_data { 74c43e99fdSEd Maste struct event_base *base; 75c43e99fdSEd Maste evutil_socket_t pair[2]; 76c43e99fdSEd Maste 77c43e99fdSEd Maste void (*legacy_test_fn)(void); 78c43e99fdSEd Maste 79c43e99fdSEd Maste void *setup_data; 80c43e99fdSEd Maste }; 81c43e99fdSEd Maste extern const struct testcase_setup_t basic_setup; 82c43e99fdSEd Maste 83c43e99fdSEd Maste 84c43e99fdSEd Maste extern const struct testcase_setup_t legacy_setup; 85c43e99fdSEd Maste void run_legacy_test_fn(void *ptr); 86c43e99fdSEd Maste 87c43e99fdSEd Maste extern int libevent_tests_running_in_debug_mode; 88c43e99fdSEd Maste 89c43e99fdSEd Maste /* A couple of flags that basic/legacy_setup can support. */ 90c43e99fdSEd Maste #define TT_NEED_SOCKETPAIR TT_FIRST_USER_FLAG 91c43e99fdSEd Maste #define TT_NEED_BASE (TT_FIRST_USER_FLAG<<1) 92c43e99fdSEd Maste #define TT_NEED_DNS (TT_FIRST_USER_FLAG<<2) 93c43e99fdSEd Maste #define TT_LEGACY (TT_FIRST_USER_FLAG<<3) 94c43e99fdSEd Maste #define TT_NEED_THREADS (TT_FIRST_USER_FLAG<<4) 95c43e99fdSEd Maste #define TT_NO_LOGS (TT_FIRST_USER_FLAG<<5) 96c43e99fdSEd Maste #define TT_ENABLE_IOCP_FLAG (TT_FIRST_USER_FLAG<<6) 97c43e99fdSEd Maste #define TT_ENABLE_IOCP (TT_ENABLE_IOCP_FLAG|TT_NEED_THREADS) 98*b50261e2SCy Schubert #define TT_ENABLE_DEBUG_MODE (TT_ENABLE_IOCP_FLAG<<7) 99c43e99fdSEd Maste 100c43e99fdSEd Maste /* All the flags that a legacy test needs. */ 101c43e99fdSEd Maste #define TT_ISOLATED TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE 102c43e99fdSEd Maste 103c43e99fdSEd Maste 104c43e99fdSEd Maste #define BASIC(name,flags) \ 105c43e99fdSEd Maste { #name, test_## name, flags, &basic_setup, NULL } 106c43e99fdSEd Maste 107c43e99fdSEd Maste #define LEGACY(name,flags) \ 108c43e99fdSEd Maste { #name, run_legacy_test_fn, flags|TT_LEGACY, &legacy_setup, \ 109c43e99fdSEd Maste test_## name } 110c43e99fdSEd Maste 111c43e99fdSEd Maste struct evutil_addrinfo; 112c43e99fdSEd Maste struct evutil_addrinfo *ai_find_by_family(struct evutil_addrinfo *ai, int f); 113c43e99fdSEd Maste struct evutil_addrinfo *ai_find_by_protocol(struct evutil_addrinfo *ai, int p); 114c43e99fdSEd Maste int test_ai_eq_(const struct evutil_addrinfo *ai, const char *sockaddr_port, 115c43e99fdSEd Maste int socktype, int protocol, int line); 116c43e99fdSEd Maste 117c43e99fdSEd Maste #define test_ai_eq(ai, str, s, p) do { \ 118c43e99fdSEd Maste if (test_ai_eq_((ai), (str), (s), (p), __LINE__)<0) \ 119c43e99fdSEd Maste goto end; \ 120c43e99fdSEd Maste } while (0) 121c43e99fdSEd Maste 122c43e99fdSEd Maste #define test_timeval_diff_leq(tv1, tv2, diff, tolerance) \ 123c43e99fdSEd Maste tt_int_op(labs(timeval_msec_diff((tv1), (tv2)) - diff), <=, tolerance) 124c43e99fdSEd Maste 125c43e99fdSEd Maste #define test_timeval_diff_eq(tv1, tv2, diff) \ 126c43e99fdSEd Maste test_timeval_diff_leq((tv1), (tv2), (diff), 50) 127c43e99fdSEd Maste 128c43e99fdSEd Maste long timeval_msec_diff(const struct timeval *start, const struct timeval *end); 129c43e99fdSEd Maste 130c43e99fdSEd Maste #ifndef _WIN32 131c43e99fdSEd Maste pid_t regress_fork(void); 132c43e99fdSEd Maste #endif 133c43e99fdSEd Maste 134c43e99fdSEd Maste #ifdef EVENT__HAVE_OPENSSL 135c43e99fdSEd Maste #include <openssl/ssl.h> 136c43e99fdSEd Maste EVP_PKEY *ssl_getkey(void); 137*b50261e2SCy Schubert X509 *ssl_getcert(EVP_PKEY *key); 138c43e99fdSEd Maste SSL_CTX *get_ssl_ctx(void); 139c43e99fdSEd Maste void init_ssl(void); 140c43e99fdSEd Maste #endif 141c43e99fdSEd Maste 142*b50261e2SCy Schubert void * basic_test_setup(const struct testcase_t *testcase); 143*b50261e2SCy Schubert int basic_test_cleanup(const struct testcase_t *testcase, void *ptr); 144*b50261e2SCy Schubert 145c43e99fdSEd Maste #ifdef __cplusplus 146c43e99fdSEd Maste } 147c43e99fdSEd Maste #endif 148c43e99fdSEd Maste 149c43e99fdSEd Maste #endif /* REGRESS_H_INCLUDED_ */ 150