2012-04-27 16:07:24 -07:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2012-04-27 16:07:24 -07:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2012-04-27 16:07:24 -07:00
|
|
|
*/
|
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
#if HAVE_CMOCKA
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
Include <sched.h> where necessary for musl libc
All unit tests define the UNIT_TESTING macro, which causes <cmocka.h> to
replace malloc(), calloc(), realloc(), and free() with its own functions
tracking memory allocations. In order for this not to break
compilation, the system header declaring the prototypes for these
standard functions must be included before <cmocka.h>.
Normally, these prototypes are only present in <stdlib.h>, so we make
sure it is included before <cmocka.h>. However, musl libc also defines
the prototypes for calloc() and free() in <sched.h>, which is included
by <pthread.h>, which is included e.g. by <isc/mutex.h>. Thus, unit
tests including "dnstest.h" (which includes <isc/mem.h>, which includes
<isc/mutex.h>) after <cmocka.h> will not compile with musl libc as for
these programs, <sched.h> will be included after <cmocka.h>.
Always including <cmocka.h> after all other header files is not a
feasible solution as that causes the mock assertion macros defined in
<isc/util.h> to mangle the contents of <cmocka.h>, thus breaking
compilation. We cannot really use the __noreturn__ or analyzer_noreturn
attributes with cmocka assertion functions because they do return if the
tested condition is true. The problem is that what BIND unit tests do
is incompatible with Clang Static Analyzer's assumptions: since we use
cmocka, our custom assertion handlers are present in a shared library
(i.e. it is the cmocka library that checks the assertion condition, not
a macro in unit test code). Redefining cmocka's assertion macros in
<isc/util.h> is an ugly hack to overcome that problem - unfortunately,
this is the only way we can think of to make Clang Static Analyzer
properly process unit test code. Giving up on Clang Static Analyzer
being able to properly process unit test code is not a satisfactory
solution.
Undefining _GNU_SOURCE for unit test code could work around the problem
(musl libc's <sched.h> only defines the prototypes for calloc() and
free() when _GNU_SOURCE is defined), but doing that could introduce
discrepancies for unit tests including entire *.c files, so it is also
not a good solution.
All in all, including <sched.h> before <cmocka.h> for all affected unit
tests seems to be the most benign way of working around this musl libc
quirk. While quite an ugly solution, it achieves our goals here, which
are to keep the benefit of proper static analysis of unit test code and
to fix compilation against musl libc.
2019-07-30 21:08:40 +02:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdarg.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <stddef.h>
|
2018-10-26 08:46:28 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-04-27 16:07:24 -07:00
|
|
|
#include <unistd.h>
|
2021-01-14 13:02:57 -08:00
|
|
|
#include <uv.h>
|
2012-04-27 16:07:24 -07:00
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
|
2016-07-11 13:36:16 +10:00
|
|
|
#include <isc/app.h>
|
2012-04-27 16:07:24 -07:00
|
|
|
#include <isc/buffer.h>
|
2021-01-14 13:02:57 -08:00
|
|
|
#include <isc/managers.h>
|
2019-07-01 15:19:29 +02:00
|
|
|
#include <isc/refcount.h>
|
2012-04-27 16:07:24 -07:00
|
|
|
#include <isc/socket.h>
|
|
|
|
#include <isc/task.h>
|
2018-10-26 08:46:28 -07:00
|
|
|
#include <isc/util.h>
|
2012-04-27 16:07:24 -07:00
|
|
|
|
|
|
|
#include <dns/dispatch.h>
|
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/view.h>
|
|
|
|
|
|
|
|
#include "dnstest.h"
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
/* Timeouts in miliseconds */
|
|
|
|
#define T_INIT 120 * 1000
|
|
|
|
#define T_IDLE 120 * 1000
|
|
|
|
#define T_KEEPALIVE 120 * 1000
|
|
|
|
#define T_ADVERTISED 120 * 1000
|
|
|
|
#define T_CONNECT 30 * 1000
|
|
|
|
|
2012-04-27 16:07:24 -07:00
|
|
|
dns_dispatchmgr_t *dispatchmgr = NULL;
|
|
|
|
dns_dispatchset_t *dset = NULL;
|
2021-01-14 13:02:57 -08:00
|
|
|
isc_nm_t *connect_nm = NULL;
|
|
|
|
static isc_sockaddr_t server_addr;
|
|
|
|
static isc_sockaddr_t connect_addr;
|
|
|
|
|
|
|
|
static int
|
|
|
|
setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) {
|
|
|
|
socklen_t addrlen = sizeof(*addr);
|
|
|
|
uv_os_sock_t fd;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
isc_sockaddr_fromin6(addr, &in6addr_loopback, 0);
|
|
|
|
|
|
|
|
fd = socket(AF_INET6, family, 0);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("setup_ephemeral_port: socket()");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
r = bind(fd, (const struct sockaddr *)&addr->type.sa,
|
|
|
|
sizeof(addr->type.sin6));
|
|
|
|
if (r != 0) {
|
|
|
|
perror("setup_ephemeral_port: bind()");
|
|
|
|
close(fd);
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
r = getsockname(fd, (struct sockaddr *)&addr->type.sa, &addrlen);
|
|
|
|
if (r != 0) {
|
|
|
|
perror("setup_ephemeral_port: getsockname()");
|
|
|
|
close(fd);
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if IPV6_RECVERR
|
|
|
|
#define setsockopt_on(socket, level, name) \
|
|
|
|
setsockopt(socket, level, name, &(int){ 1 }, sizeof(int))
|
|
|
|
|
|
|
|
r = setsockopt_on(fd, IPPROTO_IPV6, IPV6_RECVERR);
|
|
|
|
if (r != 0) {
|
|
|
|
perror("setup_ephemeral_port");
|
|
|
|
close(fd);
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (fd);
|
|
|
|
}
|
2012-04-27 16:07:24 -07:00
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_setup(void **state) {
|
2018-10-26 08:46:28 -07:00
|
|
|
isc_result_t result;
|
2021-01-14 13:02:57 -08:00
|
|
|
uv_os_sock_t sock = -1;
|
2018-10-26 08:46:28 -07:00
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, true);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
connect_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
isc_sockaddr_fromin6(&connect_addr, &in6addr_loopback, 0);
|
|
|
|
|
|
|
|
server_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
sock = setup_ephemeral_port(&server_addr, SOCK_DGRAM);
|
|
|
|
if (sock < 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
close(sock);
|
|
|
|
|
|
|
|
/* Create a secondary network manager */
|
|
|
|
isc_managers_create(dt_mctx, ncpus, 0, 0, &connect_nm, NULL, NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
isc_nm_settimeouts(netmgr, T_INIT, T_IDLE, T_KEEPALIVE, T_ADVERTISED);
|
|
|
|
isc_nm_settimeouts(connect_nm, T_INIT, T_IDLE, T_KEEPALIVE,
|
|
|
|
T_ADVERTISED);
|
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_teardown(void **state) {
|
2018-10-26 08:46:28 -07:00
|
|
|
UNUSED(state);
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
isc_managers_destroy(&connect_nm, NULL, NULL, NULL);
|
|
|
|
assert_null(connect_nm);
|
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
dns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-04-27 16:07:24 -07:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
make_dispatchset(unsigned int ndisps) {
|
|
|
|
isc_result_t result;
|
|
|
|
isc_sockaddr_t any;
|
2012-04-27 16:07:24 -07:00
|
|
|
dns_dispatch_t *disp = NULL;
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
result = dns_dispatchmgr_create(dt_mctx, netmgr, &dispatchmgr);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2012-04-27 16:07:24 -07:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-04-27 16:07:24 -07:00
|
|
|
|
|
|
|
isc_sockaddr_any(&any);
|
2021-01-14 13:02:57 -08:00
|
|
|
result = dns_dispatch_createudp(dispatchmgr, taskmgr, &any, 0, &disp);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2012-04-27 16:07:24 -07:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-04-27 16:07:24 -07:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
result = dns_dispatchset_create(dt_mctx, taskmgr, disp, &dset, ndisps);
|
2012-04-27 16:07:24 -07:00
|
|
|
dns_dispatch_detach(&disp);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
reset(void) {
|
2018-10-26 08:46:28 -07:00
|
|
|
if (dset != NULL) {
|
2012-04-27 16:07:24 -07:00
|
|
|
dns_dispatchset_destroy(&dset);
|
2018-10-26 08:46:28 -07:00
|
|
|
}
|
|
|
|
if (dispatchmgr != NULL) {
|
2012-04-27 16:07:24 -07:00
|
|
|
dns_dispatchmgr_destroy(&dispatchmgr);
|
2018-10-26 08:46:28 -07:00
|
|
|
}
|
2012-04-27 16:07:24 -07:00
|
|
|
}
|
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
/* create dispatch set */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
dispatchset_create(void **state) {
|
2012-04-27 16:07:24 -07:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
UNUSED(state);
|
2012-04-27 16:07:24 -07:00
|
|
|
|
|
|
|
result = make_dispatchset(1);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
reset();
|
2012-04-27 16:07:24 -07:00
|
|
|
|
|
|
|
result = make_dispatchset(10);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
reset();
|
2012-04-27 16:07:24 -07:00
|
|
|
}
|
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
/* test dispatch set round-robin */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
dispatchset_get(void **state) {
|
|
|
|
isc_result_t result;
|
2012-04-27 16:07:24 -07:00
|
|
|
dns_dispatch_t *d1, *d2, *d3, *d4, *d5;
|
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
UNUSED(state);
|
2012-04-27 16:07:24 -07:00
|
|
|
|
|
|
|
result = make_dispatchset(1);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2012-04-27 16:07:24 -07:00
|
|
|
|
|
|
|
d1 = dns_dispatchset_get(dset);
|
|
|
|
d2 = dns_dispatchset_get(dset);
|
|
|
|
d3 = dns_dispatchset_get(dset);
|
|
|
|
d4 = dns_dispatchset_get(dset);
|
|
|
|
d5 = dns_dispatchset_get(dset);
|
|
|
|
|
2020-11-26 13:10:40 +01:00
|
|
|
assert_ptr_equal(d1, d2);
|
|
|
|
assert_ptr_equal(d2, d3);
|
|
|
|
assert_ptr_equal(d3, d4);
|
|
|
|
assert_ptr_equal(d4, d5);
|
2012-04-27 16:07:24 -07:00
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
reset();
|
2012-04-27 16:07:24 -07:00
|
|
|
|
|
|
|
result = make_dispatchset(4);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2012-04-27 16:07:24 -07:00
|
|
|
|
|
|
|
d1 = dns_dispatchset_get(dset);
|
|
|
|
d2 = dns_dispatchset_get(dset);
|
|
|
|
d3 = dns_dispatchset_get(dset);
|
|
|
|
d4 = dns_dispatchset_get(dset);
|
|
|
|
d5 = dns_dispatchset_get(dset);
|
|
|
|
|
2020-11-26 13:10:40 +01:00
|
|
|
assert_ptr_equal(d1, d5);
|
|
|
|
assert_ptr_not_equal(d1, d2);
|
|
|
|
assert_ptr_not_equal(d2, d3);
|
|
|
|
assert_ptr_not_equal(d3, d4);
|
|
|
|
assert_ptr_not_equal(d4, d5);
|
2012-04-27 16:07:24 -07:00
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
reset();
|
2012-04-27 16:07:24 -07:00
|
|
|
}
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
struct {
|
|
|
|
isc_nmhandle_t *handle;
|
|
|
|
atomic_uint_fast32_t responses;
|
|
|
|
} testdata;
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
static dns_dispatch_t *dispatch = NULL;
|
|
|
|
static dns_dispentry_t *dispentry = NULL;
|
|
|
|
static atomic_bool first = ATOMIC_VAR_INIT(true);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
static void
|
|
|
|
server_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
|
|
|
UNUSED(handle);
|
|
|
|
UNUSED(eresult);
|
|
|
|
UNUSED(cbarg);
|
|
|
|
|
|
|
|
return;
|
2016-07-11 13:36:16 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-01-14 13:02:57 -08:00
|
|
|
nameserver(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region,
|
|
|
|
void *cbarg) {
|
|
|
|
isc_region_t response;
|
2016-07-11 13:36:16 +10:00
|
|
|
static unsigned char buf1[16];
|
|
|
|
static unsigned char buf2[16];
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
UNUSED(eresult);
|
|
|
|
UNUSED(cbarg);
|
|
|
|
|
|
|
|
memmove(buf1, region->base, 12);
|
2016-07-11 13:36:16 +10:00
|
|
|
memset(buf1 + 12, 0, 4);
|
2020-02-12 13:59:18 +01:00
|
|
|
buf1[2] |= 0x80; /* qr=1 */
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
memmove(buf2, region->base, 12);
|
2016-07-11 13:36:16 +10:00
|
|
|
memset(buf2 + 12, 1, 4);
|
2020-02-12 13:59:18 +01:00
|
|
|
buf2[2] |= 0x80; /* qr=1 */
|
2016-07-11 13:36:16 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* send message to be discarded.
|
|
|
|
*/
|
2021-01-14 13:02:57 -08:00
|
|
|
response.base = buf1;
|
|
|
|
response.length = sizeof(buf1);
|
|
|
|
isc_nm_send(handle, &response, server_senddone, NULL);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* send nextitem message.
|
|
|
|
*/
|
2021-01-14 13:02:57 -08:00
|
|
|
response.base = buf2;
|
|
|
|
response.length = sizeof(buf2);
|
|
|
|
isc_nm_send(handle, &response, server_senddone, NULL);
|
2016-07-11 13:36:16 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
response(isc_task_t *task, isc_event_t *event) {
|
2016-07-11 13:36:16 +10:00
|
|
|
dns_dispatchevent_t *devent = (dns_dispatchevent_t *)event;
|
2020-02-13 14:44:37 -08:00
|
|
|
bool exp_true = true;
|
2016-07-11 13:36:16 +10:00
|
|
|
|
|
|
|
UNUSED(task);
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
atomic_fetch_add_relaxed(&testdata.responses, 1);
|
2019-07-01 15:19:29 +02:00
|
|
|
if (atomic_compare_exchange_strong(&first, &exp_true, false)) {
|
|
|
|
isc_result_t result = dns_dispatch_getnext(dispentry, &devent);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-07-11 13:36:16 +10:00
|
|
|
} else {
|
|
|
|
dns_dispatch_removeresponse(&dispentry, &devent);
|
2021-01-14 13:02:57 -08:00
|
|
|
isc_nmhandle_detach(&testdata.handle);
|
2016-07-11 13:36:16 +10:00
|
|
|
isc_app_shutdown();
|
|
|
|
}
|
2016-08-08 09:35:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-01-14 13:02:57 -08:00
|
|
|
connected(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
|
|
|
isc_region_t *r = (isc_region_t *)cbarg;
|
2016-08-08 09:35:17 +10:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
UNUSED(eresult);
|
|
|
|
|
|
|
|
isc_nmhandle_attach(handle, &testdata.handle);
|
|
|
|
dns_dispatch_send(dispentry, r, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
client_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
|
|
|
UNUSED(handle);
|
|
|
|
UNUSED(eresult);
|
|
|
|
UNUSED(cbarg);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
startit(isc_task_t *task, isc_event_t *event) {
|
|
|
|
UNUSED(task);
|
|
|
|
dns_dispatch_connect(dispentry);
|
2016-08-08 09:35:17 +10:00
|
|
|
isc_event_free(&event);
|
2016-07-11 13:36:16 +10:00
|
|
|
}
|
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
/* test dispatch getnext */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
dispatch_getnext(void **state) {
|
|
|
|
isc_result_t result;
|
2021-01-14 13:02:57 -08:00
|
|
|
isc_region_t region;
|
|
|
|
isc_nmsocket_t *sock = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_task_t *task = NULL;
|
|
|
|
unsigned char message[12];
|
|
|
|
unsigned char rbuf[12];
|
2021-01-14 13:02:57 -08:00
|
|
|
uint16_t id;
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
UNUSED(state);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
testdata.handle = NULL;
|
|
|
|
atomic_init(&testdata.responses, 0);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
result = dns_dispatch_createudp(dispatchmgr, taskmgr, &connect_addr, 0,
|
|
|
|
&dispatch);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a local udp nameserver on the loopback.
|
|
|
|
*/
|
2021-01-14 13:02:57 -08:00
|
|
|
result = isc_nm_listenudp(netmgr, &server_addr, nameserver, NULL, 0,
|
|
|
|
&sock);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
|
|
|
region.base = rbuf;
|
|
|
|
region.length = sizeof(rbuf);
|
2021-01-14 13:02:57 -08:00
|
|
|
result = dns_dispatch_addresponse(
|
|
|
|
dispatch, 0, 10000, &server_addr, task, connected,
|
|
|
|
client_senddone, response, NULL, ®ion, &id, &dispentry);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
|
|
|
memset(message, 0, sizeof(message));
|
|
|
|
message[0] = (id >> 8) & 0xff;
|
|
|
|
message[1] = id & 0xff;
|
|
|
|
|
|
|
|
region.base = message;
|
|
|
|
region.length = sizeof(message);
|
2021-01-14 13:02:57 -08:00
|
|
|
|
|
|
|
result = isc_app_onrun(dt_mctx, task, startit, NULL);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
|
|
|
result = isc_app_run();
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
assert_int_equal(atomic_load_acquire(&testdata.responses), 2);
|
|
|
|
|
|
|
|
isc_nm_stoplistening(sock);
|
|
|
|
isc_nmsocket_close(&sock);
|
|
|
|
assert_null(sock);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Shutdown nameserver.
|
|
|
|
*/
|
|
|
|
isc_task_detach(&task);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shutdown the dispatch.
|
|
|
|
*/
|
|
|
|
dns_dispatch_detach(&dispatch);
|
|
|
|
dns_dispatchmgr_destroy(&dispatchmgr);
|
2018-10-26 08:46:28 -07:00
|
|
|
}
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-26 08:46:28 -07:00
|
|
|
const struct CMUnitTest tests[] = {
|
2020-02-12 13:59:18 +01:00
|
|
|
cmocka_unit_test_setup_teardown(dispatchset_create, _setup,
|
|
|
|
_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(dispatchset_get, _setup,
|
|
|
|
_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(dispatch_getnext, _setup,
|
|
|
|
_teardown),
|
2018-10-26 08:46:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2016-07-11 13:36:16 +10:00
|
|
|
}
|
2012-04-27 16:07:24 -07:00
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-26 08:46:28 -07:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
2021-01-18 19:15:44 +01:00
|
|
|
return (SKIPPED_TEST_EXIT_CODE);
|
2012-04-27 16:07:24 -07:00
|
|
|
}
|
2018-10-26 08:46:28 -07:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if HAVE_CMOCKA */
|