1*eabc0478Schristos /* $NetBSD: regress.h,v 1.7 2024/08/18 20:47:23 christos Exp $ */ 28585484eSchristos 38585484eSchristos /* 48585484eSchristos * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 58585484eSchristos * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 68585484eSchristos * 78585484eSchristos * Redistribution and use in source and binary forms, with or without 88585484eSchristos * modification, are permitted provided that the following conditions 98585484eSchristos * are met: 108585484eSchristos * 1. Redistributions of source code must retain the above copyright 118585484eSchristos * notice, this list of conditions and the following disclaimer. 128585484eSchristos * 2. Redistributions in binary form must reproduce the above copyright 138585484eSchristos * notice, this list of conditions and the following disclaimer in the 148585484eSchristos * documentation and/or other materials provided with the distribution. 158585484eSchristos * 3. The name of the author may not be used to endorse or promote products 168585484eSchristos * derived from this software without specific prior written permission. 178585484eSchristos * 188585484eSchristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 198585484eSchristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 208585484eSchristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 218585484eSchristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 228585484eSchristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 238585484eSchristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 248585484eSchristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 258585484eSchristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 268585484eSchristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 278585484eSchristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 288585484eSchristos */ 298585484eSchristos #ifndef REGRESS_H_INCLUDED_ 308585484eSchristos #define REGRESS_H_INCLUDED_ 318585484eSchristos 328585484eSchristos #ifdef __cplusplus 338585484eSchristos extern "C" { 348585484eSchristos #endif 358585484eSchristos 368585484eSchristos #include "tinytest.h" 378585484eSchristos #include "tinytest_macros.h" 388585484eSchristos 398585484eSchristos extern struct testcase_t main_testcases[]; 408585484eSchristos extern struct testcase_t evtag_testcases[]; 418585484eSchristos extern struct testcase_t evbuffer_testcases[]; 42b8ecfcfeSchristos extern struct testcase_t finalize_testcases[]; 438585484eSchristos extern struct testcase_t bufferevent_testcases[]; 448585484eSchristos extern struct testcase_t bufferevent_iocp_testcases[]; 458585484eSchristos extern struct testcase_t util_testcases[]; 468585484eSchristos extern struct testcase_t signal_testcases[]; 478585484eSchristos extern struct testcase_t http_testcases[]; 48*eabc0478Schristos extern struct testcase_t http_iocp_testcases[]; 498585484eSchristos extern struct testcase_t dns_testcases[]; 508585484eSchristos extern struct testcase_t rpc_testcases[]; 518585484eSchristos extern struct testcase_t edgetriggered_testcases[]; 528585484eSchristos extern struct testcase_t minheap_testcases[]; 538585484eSchristos extern struct testcase_t iocp_testcases[]; 548585484eSchristos extern struct testcase_t ssl_testcases[]; 558585484eSchristos extern struct testcase_t listener_testcases[]; 568585484eSchristos extern struct testcase_t listener_iocp_testcases[]; 578585484eSchristos extern struct testcase_t thread_testcases[]; 588585484eSchristos 597476e6e4Schristos extern struct evutil_weakrand_state test_weakrand_state; 607476e6e4Schristos 617476e6e4Schristos #define test_weakrand() (evutil_weakrand_(&test_weakrand_state)) 627476e6e4Schristos 638585484eSchristos void regress_threads(void *); 648585484eSchristos void test_bufferevent_zlib(void *); 658585484eSchristos 668585484eSchristos /* Helpers to wrap old testcases */ 678585484eSchristos extern evutil_socket_t pair[2]; 688585484eSchristos extern int test_ok; 698585484eSchristos extern int called; 708585484eSchristos extern struct event_base *global_base; 718585484eSchristos extern int in_legacy_test_wrapper; 728585484eSchristos 738585484eSchristos int regress_make_tmpfile(const void *data, size_t datalen, char **filename_out); 748585484eSchristos 758585484eSchristos struct basic_test_data { 768585484eSchristos struct event_base *base; 778585484eSchristos evutil_socket_t pair[2]; 788585484eSchristos 798585484eSchristos void (*legacy_test_fn)(void); 808585484eSchristos 818585484eSchristos void *setup_data; 828585484eSchristos }; 838585484eSchristos extern const struct testcase_setup_t basic_setup; 848585484eSchristos 858585484eSchristos 868585484eSchristos extern const struct testcase_setup_t legacy_setup; 878585484eSchristos void run_legacy_test_fn(void *ptr); 888585484eSchristos 89b8ecfcfeSchristos extern int libevent_tests_running_in_debug_mode; 90b8ecfcfeSchristos 918585484eSchristos /* A couple of flags that basic/legacy_setup can support. */ 928585484eSchristos #define TT_NEED_SOCKETPAIR TT_FIRST_USER_FLAG 938585484eSchristos #define TT_NEED_BASE (TT_FIRST_USER_FLAG<<1) 948585484eSchristos #define TT_NEED_DNS (TT_FIRST_USER_FLAG<<2) 958585484eSchristos #define TT_LEGACY (TT_FIRST_USER_FLAG<<3) 968585484eSchristos #define TT_NEED_THREADS (TT_FIRST_USER_FLAG<<4) 978585484eSchristos #define TT_NO_LOGS (TT_FIRST_USER_FLAG<<5) 988585484eSchristos #define TT_ENABLE_IOCP_FLAG (TT_FIRST_USER_FLAG<<6) 998585484eSchristos #define TT_ENABLE_IOCP (TT_ENABLE_IOCP_FLAG|TT_NEED_THREADS) 100*eabc0478Schristos #define TT_ENABLE_DEBUG_MODE (TT_ENABLE_IOCP_FLAG<<7) 1018585484eSchristos 1028585484eSchristos /* All the flags that a legacy test needs. */ 1038585484eSchristos #define TT_ISOLATED TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE 1048585484eSchristos 1058585484eSchristos 1068585484eSchristos #define BASIC(name,flags) \ 1078585484eSchristos { #name, test_## name, flags, &basic_setup, NULL } 1088585484eSchristos 1098585484eSchristos #define LEGACY(name,flags) \ 1108585484eSchristos { #name, run_legacy_test_fn, flags|TT_LEGACY, &legacy_setup, \ 1118585484eSchristos test_## name } 1128585484eSchristos 1138585484eSchristos struct evutil_addrinfo; 1148585484eSchristos struct evutil_addrinfo *ai_find_by_family(struct evutil_addrinfo *ai, int f); 1158585484eSchristos struct evutil_addrinfo *ai_find_by_protocol(struct evutil_addrinfo *ai, int p); 1168585484eSchristos int test_ai_eq_(const struct evutil_addrinfo *ai, const char *sockaddr_port, 1178585484eSchristos int socktype, int protocol, int line); 1188585484eSchristos 1198585484eSchristos #define test_ai_eq(ai, str, s, p) do { \ 1208585484eSchristos if (test_ai_eq_((ai), (str), (s), (p), __LINE__)<0) \ 1218585484eSchristos goto end; \ 1228585484eSchristos } while (0) 1238585484eSchristos 1248585484eSchristos #define test_timeval_diff_leq(tv1, tv2, diff, tolerance) \ 1257476e6e4Schristos tt_int_op(labs(timeval_msec_diff((tv1), (tv2)) - diff), <=, tolerance) 1268585484eSchristos 1278585484eSchristos #define test_timeval_diff_eq(tv1, tv2, diff) \ 1288585484eSchristos test_timeval_diff_leq((tv1), (tv2), (diff), 50) 1298585484eSchristos 1308585484eSchristos long timeval_msec_diff(const struct timeval *start, const struct timeval *end); 1318585484eSchristos 1328585484eSchristos #ifndef _WIN32 1338585484eSchristos pid_t regress_fork(void); 1348585484eSchristos #endif 1358585484eSchristos 136*eabc0478Schristos #ifdef EVENT__HAVE_OPENSSL 137*eabc0478Schristos #include <openssl/ssl.h> 138*eabc0478Schristos EVP_PKEY *ssl_getkey(void); 139*eabc0478Schristos X509 *ssl_getcert(EVP_PKEY *key); 140*eabc0478Schristos SSL_CTX *get_ssl_ctx(void); 141*eabc0478Schristos void init_ssl(void); 142*eabc0478Schristos #endif 143*eabc0478Schristos 144*eabc0478Schristos void * basic_test_setup(const struct testcase_t *testcase); 145*eabc0478Schristos int basic_test_cleanup(const struct testcase_t *testcase, void *ptr); 146*eabc0478Schristos 1478585484eSchristos #ifdef __cplusplus 1488585484eSchristos } 1498585484eSchristos #endif 1508585484eSchristos 1518585484eSchristos #endif /* REGRESS_H_INCLUDED_ */ 152