xref: /netbsd-src/external/bsd/libevent/dist/test/regress_testutils.h (revision 805a1ce9000bc0ec0951bf35f7e52b85cafb37e2)
1*805a1ce9Schristos /*	$NetBSD: regress_testutils.h,v 1.1.1.2 2017/01/31 21:14:53 christos Exp $	*/
26ecf6635Schristos /*
36ecf6635Schristos  * Copyright (c) 2010-2012 Niels Provos and Nick Mathewson
46ecf6635Schristos  *
56ecf6635Schristos  * Redistribution and use in source and binary forms, with or without
66ecf6635Schristos  * modification, are permitted provided that the following conditions
76ecf6635Schristos  * are met:
86ecf6635Schristos  * 1. Redistributions of source code must retain the above copyright
96ecf6635Schristos  *    notice, this list of conditions and the following disclaimer.
106ecf6635Schristos  * 2. Redistributions in binary form must reproduce the above copyright
116ecf6635Schristos  *    notice, this list of conditions and the following disclaimer in the
126ecf6635Schristos  *    documentation and/or other materials provided with the distribution.
136ecf6635Schristos  * 3. The name of the author may not be used to endorse or promote products
146ecf6635Schristos  *    derived from this software without specific prior written permission.
156ecf6635Schristos  *
166ecf6635Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
176ecf6635Schristos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
186ecf6635Schristos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
196ecf6635Schristos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
206ecf6635Schristos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
216ecf6635Schristos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
226ecf6635Schristos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236ecf6635Schristos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246ecf6635Schristos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
256ecf6635Schristos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
266ecf6635Schristos  */
276ecf6635Schristos 
28*805a1ce9Schristos #ifndef REGRESS_TESTUTILS_H_INCLUDED_
29*805a1ce9Schristos #define REGRESS_TESTUTILS_H_INCLUDED_
306ecf6635Schristos 
316ecf6635Schristos #include "event2/dns.h"
326ecf6635Schristos 
336ecf6635Schristos struct regress_dns_server_table {
346ecf6635Schristos 	const char *q;
356ecf6635Schristos 	const char *anstype;
366ecf6635Schristos 	const char *ans;
376ecf6635Schristos 	int seen;
38*805a1ce9Schristos 	int lower;
396ecf6635Schristos };
406ecf6635Schristos 
416ecf6635Schristos struct evdns_server_port *
426ecf6635Schristos regress_get_dnsserver(struct event_base *base,
436ecf6635Schristos     ev_uint16_t *portnum,
446ecf6635Schristos     evutil_socket_t *psock,
456ecf6635Schristos     evdns_request_callback_fn_type cb,
466ecf6635Schristos     void *arg);
476ecf6635Schristos 
486ecf6635Schristos /* Helper: return the port that a socket is bound on, in host order. */
496ecf6635Schristos int regress_get_socket_port(evutil_socket_t fd);
506ecf6635Schristos 
516ecf6635Schristos /* used to look up pre-canned responses in a search table */
526ecf6635Schristos void regress_dns_server_cb(
536ecf6635Schristos 	struct evdns_server_request *req, void *data);
546ecf6635Schristos 
556ecf6635Schristos /* globally allocates a dns server that serves from a search table */
566ecf6635Schristos int regress_dnsserver(struct event_base *base, ev_uint16_t *port,
576ecf6635Schristos     struct regress_dns_server_table *seach_table);
586ecf6635Schristos 
596ecf6635Schristos /* clean up the global dns server resources */
606ecf6635Schristos void regress_clean_dnsserver(void);
616ecf6635Schristos 
626ecf6635Schristos struct evconnlistener;
636ecf6635Schristos struct sockaddr;
646ecf6635Schristos int regress_get_listener_addr(struct evconnlistener *lev,
656ecf6635Schristos     struct sockaddr *sa, ev_socklen_t *socklen);
666ecf6635Schristos 
67*805a1ce9Schristos #endif /* REGRESS_TESTUTILS_H_INCLUDED_ */
686ecf6635Schristos 
69