1290001Sglebius/*
2290001Sglebius * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3290001Sglebius * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4290001Sglebius *
5290001Sglebius * Redistribution and use in source and binary forms, with or without
6290001Sglebius * modification, are permitted provided that the following conditions
7290001Sglebius * are met:
8290001Sglebius * 1. Redistributions of source code must retain the above copyright
9290001Sglebius *    notice, this list of conditions and the following disclaimer.
10290001Sglebius * 2. Redistributions in binary form must reproduce the above copyright
11290001Sglebius *    notice, this list of conditions and the following disclaimer in the
12290001Sglebius *    documentation and/or other materials provided with the distribution.
13290001Sglebius * 3. The name of the author may not be used to endorse or promote products
14290001Sglebius *    derived from this software without specific prior written permission.
15290001Sglebius *
16290001Sglebius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17290001Sglebius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18290001Sglebius * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19290001Sglebius * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20290001Sglebius * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21290001Sglebius * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22290001Sglebius * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23290001Sglebius * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24290001Sglebius * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25290001Sglebius * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26290001Sglebius */
27290001Sglebius#ifndef REGRESS_H_INCLUDED_
28290001Sglebius#define REGRESS_H_INCLUDED_
29290001Sglebius
30290001Sglebius#ifdef __cplusplus
31290001Sglebiusextern "C" {
32290001Sglebius#endif
33290001Sglebius
34290001Sglebius#include "tinytest.h"
35290001Sglebius#include "tinytest_macros.h"
36290001Sglebius
37290001Sglebiusextern struct testcase_t main_testcases[];
38290001Sglebiusextern struct testcase_t evtag_testcases[];
39290001Sglebiusextern struct testcase_t evbuffer_testcases[];
40290001Sglebiusextern struct testcase_t finalize_testcases[];
41290001Sglebiusextern struct testcase_t bufferevent_testcases[];
42290001Sglebiusextern struct testcase_t bufferevent_iocp_testcases[];
43290001Sglebiusextern struct testcase_t util_testcases[];
44290001Sglebiusextern struct testcase_t signal_testcases[];
45290001Sglebiusextern struct testcase_t http_testcases[];
46290001Sglebiusextern struct testcase_t dns_testcases[];
47290001Sglebiusextern struct testcase_t rpc_testcases[];
48290001Sglebiusextern struct testcase_t edgetriggered_testcases[];
49290001Sglebiusextern struct testcase_t minheap_testcases[];
50290001Sglebiusextern struct testcase_t iocp_testcases[];
51290001Sglebiusextern struct testcase_t ssl_testcases[];
52290001Sglebiusextern struct testcase_t listener_testcases[];
53290001Sglebiusextern struct testcase_t listener_iocp_testcases[];
54290001Sglebiusextern struct testcase_t thread_testcases[];
55290001Sglebius
56290001Sglebiusextern struct evutil_weakrand_state test_weakrand_state;
57290001Sglebius
58290001Sglebius#define test_weakrand() (evutil_weakrand_(&test_weakrand_state))
59290001Sglebius
60290001Sglebiusvoid regress_threads(void *);
61290001Sglebiusvoid test_bufferevent_zlib(void *);
62290001Sglebius
63290001Sglebius/* Helpers to wrap old testcases */
64290001Sglebiusextern evutil_socket_t pair[2];
65290001Sglebiusextern int test_ok;
66290001Sglebiusextern int called;
67290001Sglebiusextern struct event_base *global_base;
68290001Sglebiusextern int in_legacy_test_wrapper;
69290001Sglebius
70290001Sglebiusint regress_make_tmpfile(const void *data, size_t datalen, char **filename_out);
71290001Sglebius
72290001Sglebiusstruct basic_test_data {
73290001Sglebius	struct event_base *base;
74290001Sglebius	evutil_socket_t pair[2];
75290001Sglebius
76290001Sglebius	void (*legacy_test_fn)(void);
77290001Sglebius
78290001Sglebius	void *setup_data;
79290001Sglebius};
80290001Sglebiusextern const struct testcase_setup_t basic_setup;
81290001Sglebius
82290001Sglebius
83290001Sglebiusextern const struct testcase_setup_t legacy_setup;
84290001Sglebiusvoid run_legacy_test_fn(void *ptr);
85290001Sglebius
86290001Sglebiusextern int libevent_tests_running_in_debug_mode;
87290001Sglebius
88290001Sglebius/* A couple of flags that basic/legacy_setup can support. */
89290001Sglebius#define TT_NEED_SOCKETPAIR	TT_FIRST_USER_FLAG
90290001Sglebius#define TT_NEED_BASE		(TT_FIRST_USER_FLAG<<1)
91290001Sglebius#define TT_NEED_DNS		(TT_FIRST_USER_FLAG<<2)
92290001Sglebius#define TT_LEGACY		(TT_FIRST_USER_FLAG<<3)
93290001Sglebius#define TT_NEED_THREADS		(TT_FIRST_USER_FLAG<<4)
94290001Sglebius#define TT_NO_LOGS		(TT_FIRST_USER_FLAG<<5)
95290001Sglebius#define TT_ENABLE_IOCP_FLAG	(TT_FIRST_USER_FLAG<<6)
96290001Sglebius#define TT_ENABLE_IOCP		(TT_ENABLE_IOCP_FLAG|TT_NEED_THREADS)
97290001Sglebius
98290001Sglebius/* All the flags that a legacy test needs. */
99290001Sglebius#define TT_ISOLATED TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE
100290001Sglebius
101290001Sglebius
102290001Sglebius#define BASIC(name,flags)						\
103290001Sglebius	{ #name, test_## name, flags, &basic_setup, NULL }
104290001Sglebius
105290001Sglebius#define LEGACY(name,flags)						\
106290001Sglebius	{ #name, run_legacy_test_fn, flags|TT_LEGACY, &legacy_setup,	\
107290001Sglebius	  test_## name }
108290001Sglebius
109290001Sglebiusstruct evutil_addrinfo;
110290001Sglebiusstruct evutil_addrinfo *ai_find_by_family(struct evutil_addrinfo *ai, int f);
111290001Sglebiusstruct evutil_addrinfo *ai_find_by_protocol(struct evutil_addrinfo *ai, int p);
112290001Sglebiusint test_ai_eq_(const struct evutil_addrinfo *ai, const char *sockaddr_port,
113290001Sglebius    int socktype, int protocol, int line);
114290001Sglebius
115290001Sglebius#define test_ai_eq(ai, str, s, p) do {					\
116290001Sglebius		if (test_ai_eq_((ai), (str), (s), (p), __LINE__)<0)	\
117290001Sglebius			goto end;					\
118290001Sglebius	} while (0)
119290001Sglebius
120290001Sglebius#define test_timeval_diff_leq(tv1, tv2, diff, tolerance)		\
121290001Sglebius	tt_int_op(labs(timeval_msec_diff((tv1), (tv2)) - diff), <=, tolerance)
122290001Sglebius
123290001Sglebius#define test_timeval_diff_eq(tv1, tv2, diff)				\
124290001Sglebius	test_timeval_diff_leq((tv1), (tv2), (diff), 50)
125290001Sglebius
126290001Sglebiuslong timeval_msec_diff(const struct timeval *start, const struct timeval *end);
127290001Sglebius
128290001Sglebius#ifndef _WIN32
129290001Sglebiuspid_t regress_fork(void);
130290001Sglebius#endif
131290001Sglebius
132290001Sglebius#ifdef __cplusplus
133290001Sglebius}
134290001Sglebius#endif
135290001Sglebius
136290001Sglebius#endif /* REGRESS_H_INCLUDED_ */
137