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
|
|
|
*
|
2021-06-03 08:37:05 +02:00
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
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-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>
|
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
|
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/task.h>
|
2018-10-26 08:46:28 -07:00
|
|
|
#include <isc/util.h>
|
2022-04-27 17:41:47 +02:00
|
|
|
#include <isc/uv.h>
|
2012-04-27 16:07:24 -07:00
|
|
|
|
|
|
|
#include <dns/dispatch.h>
|
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/view.h>
|
|
|
|
|
2022-05-03 11:37:31 +02:00
|
|
|
#include <tests/dns.h>
|
2012-04-27 16:07:24 -07:00
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
uv_sem_t sem;
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
/* Timeouts in miliseconds */
|
2021-08-04 13:14:11 -07:00
|
|
|
#define T_SERVER_INIT 5000
|
|
|
|
#define T_SERVER_IDLE 5000
|
|
|
|
#define T_SERVER_KEEPALIVE 5000
|
|
|
|
#define T_SERVER_ADVERTISED 5000
|
|
|
|
|
|
|
|
#define T_CLIENT_INIT 2000
|
|
|
|
#define T_CLIENT_IDLE 2000
|
|
|
|
#define T_CLIENT_KEEPALIVE 2000
|
|
|
|
#define T_CLIENT_ADVERTISED 2000
|
|
|
|
|
|
|
|
#define T_CLIENT_CONNECT 1000
|
2021-01-14 13:02:57 -08:00
|
|
|
|
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;
|
2021-08-04 13:14:11 -07:00
|
|
|
static isc_sockaddr_t udp_server_addr;
|
|
|
|
static isc_sockaddr_t udp_connect_addr;
|
|
|
|
static isc_sockaddr_t tcp_server_addr;
|
|
|
|
static isc_sockaddr_t tcp_connect_addr;
|
|
|
|
|
|
|
|
const struct in6_addr in6addr_blackhole = { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 1 } } };
|
2021-01-14 13:02:57 -08:00
|
|
|
|
|
|
|
static int
|
|
|
|
setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) {
|
|
|
|
socklen_t addrlen = sizeof(*addr);
|
2022-04-27 17:41:47 +02:00
|
|
|
uv_os_sock_t fd = -1;
|
2021-01-14 13:02:57 -08:00
|
|
|
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
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
static void
|
|
|
|
reset_testdata(void);
|
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_setup(void **state) {
|
2021-01-14 13:02:57 -08:00
|
|
|
uv_os_sock_t sock = -1;
|
2021-08-04 13:14:11 -07:00
|
|
|
int r;
|
2018-10-26 08:46:28 -07:00
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
udp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
isc_sockaddr_fromin6(&udp_connect_addr, &in6addr_loopback, 0);
|
|
|
|
|
|
|
|
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
2021-01-14 13:02:57 -08:00
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
udp_server_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
sock = setup_ephemeral_port(&udp_server_addr, SOCK_DGRAM);
|
|
|
|
if (sock < 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
close(sock);
|
|
|
|
|
|
|
|
tcp_server_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
sock = setup_ephemeral_port(&tcp_server_addr, SOCK_STREAM);
|
2021-01-14 13:02:57 -08:00
|
|
|
if (sock < 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
close(sock);
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
setup_managers(state);
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
/* Create a secondary network manager */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_managers_create(mctx, workers, 0, &connect_nm, NULL, NULL);
|
2021-01-14 13:02:57 -08:00
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
isc_nm_settimeouts(netmgr, T_SERVER_INIT, T_SERVER_IDLE,
|
|
|
|
T_SERVER_KEEPALIVE, T_SERVER_ADVERTISED);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use shorter client-side timeouts, to ensure that clients
|
|
|
|
* time out before the server.
|
|
|
|
*/
|
|
|
|
isc_nm_settimeouts(connect_nm, T_CLIENT_INIT, T_CLIENT_IDLE,
|
|
|
|
T_CLIENT_KEEPALIVE, T_CLIENT_ADVERTISED);
|
|
|
|
|
|
|
|
r = uv_sem_init(&sem, 0);
|
|
|
|
assert_int_equal(r, 0);
|
|
|
|
|
|
|
|
reset_testdata();
|
2021-01-14 13:02:57 -08:00
|
|
|
|
2018-10-26 08:46:28 -07:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_teardown(void **state) {
|
2021-08-04 13:14:11 -07:00
|
|
|
uv_sem_destroy(&sem);
|
|
|
|
|
2021-10-03 00:27:52 -07:00
|
|
|
isc_managers_destroy(&connect_nm, NULL, NULL);
|
2021-01-14 13:02:57 -08:00
|
|
|
assert_null(connect_nm);
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
teardown_managers(state);
|
2018-10-26 08:46:28 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
result = dns_dispatchmgr_create(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-08-04 13:14:11 -07:00
|
|
|
result = dns_dispatch_createudp(dispatchmgr, &any, &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
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
result = dns_dispatchset_create(mctx, 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) {
|
2021-05-25 22:54:17 -07:00
|
|
|
dns_dispatchmgr_detach(&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 */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(dispatchset_create) {
|
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 */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(dispatchset_get) {
|
2020-02-13 14:44:37 -08:00
|
|
|
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 {
|
|
|
|
atomic_uint_fast32_t responses;
|
2021-08-04 13:14:11 -07:00
|
|
|
atomic_uint_fast32_t result;
|
2021-01-14 13:02:57 -08:00
|
|
|
} 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;
|
2022-03-08 23:55:10 +01:00
|
|
|
static atomic_bool first = true;
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
static void
|
|
|
|
reset_testdata(void) {
|
|
|
|
atomic_init(&testdata.responses, 0);
|
|
|
|
atomic_init(&testdata.result, ISC_R_UNSET);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
static isc_result_t
|
|
|
|
accept_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
|
|
|
UNUSED(handle);
|
|
|
|
UNUSED(cbarg);
|
|
|
|
|
|
|
|
return (eresult);
|
|
|
|
}
|
|
|
|
|
2016-07-11 13:36:16 +10:00
|
|
|
static void
|
2021-08-04 13:14:11 -07:00
|
|
|
noop_nameserver(isc_nmhandle_t *handle, isc_result_t eresult,
|
|
|
|
isc_region_t *region, void *cbarg) {
|
|
|
|
UNUSED(handle);
|
|
|
|
UNUSED(eresult);
|
|
|
|
UNUSED(region);
|
|
|
|
UNUSED(cbarg);
|
|
|
|
}
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
static void
|
|
|
|
response_getnext(isc_result_t result, isc_region_t *region, void *arg) {
|
|
|
|
UNUSED(region);
|
|
|
|
UNUSED(arg);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
atomic_fetch_add_relaxed(&testdata.responses, 1);
|
2021-08-04 13:14:11 -07:00
|
|
|
|
|
|
|
if (atomic_compare_exchange_strong(&first, &(bool){ true }, false)) {
|
|
|
|
result = dns_dispatch_getnext(dispentry);
|
2018-10-26 08:46:28 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-07-11 13:36:16 +10:00
|
|
|
} else {
|
2021-08-04 13:14:11 -07:00
|
|
|
uv_sem_post(&sem);
|
2016-07-11 13:36:16 +10:00
|
|
|
}
|
2016-08-08 09:35:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-08-04 13:14:11 -07:00
|
|
|
response(isc_result_t eresult, isc_region_t *region, void *arg) {
|
|
|
|
UNUSED(region);
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
|
|
switch (eresult) {
|
|
|
|
case ISC_R_EOF:
|
|
|
|
case ISC_R_CANCELED:
|
|
|
|
case ISC_R_SHUTTINGDOWN:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
atomic_fetch_add_relaxed(&testdata.responses, 1);
|
|
|
|
atomic_store_relaxed(&testdata.result, eresult);
|
|
|
|
}
|
|
|
|
|
|
|
|
uv_sem_post(&sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
response_timeout(isc_result_t eresult, isc_region_t *region, void *arg) {
|
|
|
|
UNUSED(region);
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
|
|
atomic_store_relaxed(&testdata.result, eresult);
|
|
|
|
|
|
|
|
uv_sem_post(&sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
connected(isc_result_t eresult, isc_region_t *region, void *cbarg) {
|
2021-01-14 13:02:57 -08:00
|
|
|
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);
|
2021-08-04 13:14:11 -07:00
|
|
|
UNUSED(region);
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
dns_dispatch_send(dispentry, r, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-08-04 13:14:11 -07:00
|
|
|
client_senddone(isc_result_t eresult, isc_region_t *region, void *cbarg) {
|
2021-01-14 13:02:57 -08:00
|
|
|
UNUSED(eresult);
|
2021-08-04 13:14:11 -07:00
|
|
|
UNUSED(region);
|
2021-01-14 13:02:57 -08:00
|
|
|
UNUSED(cbarg);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-08-04 13:14:11 -07:00
|
|
|
timeout_connected(isc_result_t eresult, isc_region_t *region, void *cbarg) {
|
|
|
|
UNUSED(region);
|
|
|
|
UNUSED(cbarg);
|
|
|
|
|
|
|
|
atomic_store_relaxed(&testdata.result, eresult);
|
|
|
|
|
|
|
|
uv_sem_post(&sem);
|
|
|
|
}
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(dispatch_timeout_tcp_connect) {
|
2021-08-04 13:14:11 -07:00
|
|
|
isc_result_t result;
|
|
|
|
isc_region_t region;
|
|
|
|
unsigned char rbuf[12] = { 0 };
|
|
|
|
unsigned char message[12] = { 0 };
|
|
|
|
uint16_t id;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_blackhole, 0);
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr);
|
2021-08-04 13:14:11 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_dispatch_createtcp(dispatchmgr, &tcp_connect_addr,
|
|
|
|
&tcp_server_addr, -1, &dispatch);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
region.base = rbuf;
|
|
|
|
region.length = sizeof(rbuf);
|
|
|
|
|
2021-10-03 15:15:50 -07:00
|
|
|
result = dns_dispatch_add(dispatch, 0, T_CLIENT_CONNECT,
|
|
|
|
&tcp_server_addr, timeout_connected,
|
|
|
|
client_senddone, response, ®ion, &id,
|
|
|
|
&dispentry);
|
2021-08-04 13:14:11 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
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
|
|
|
dns_dispatch_connect(dispentry);
|
2021-08-04 13:14:11 -07:00
|
|
|
|
|
|
|
uv_sem_wait(&sem);
|
|
|
|
|
2021-10-03 15:15:50 -07:00
|
|
|
dns_dispatch_done(&dispentry);
|
2021-08-04 13:14:11 -07:00
|
|
|
|
|
|
|
dns_dispatch_detach(&dispatch);
|
|
|
|
dns_dispatchmgr_detach(&dispatchmgr);
|
|
|
|
|
|
|
|
/* Skip if the IPv6 is not available or not blackholed */
|
|
|
|
|
|
|
|
result = atomic_load_acquire(&testdata.result);
|
|
|
|
if (result == ISC_R_ADDRNOTAVAIL || result == ISC_R_CONNREFUSED) {
|
|
|
|
skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_int_equal(result, ISC_R_TIMEDOUT);
|
2016-07-11 13:36:16 +10:00
|
|
|
}
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(dispatch_timeout_tcp_response) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
2021-01-14 13:02:57 -08:00
|
|
|
isc_region_t region;
|
2021-08-04 13:14:11 -07:00
|
|
|
unsigned char rbuf[12] = { 0 };
|
|
|
|
unsigned char message[12] = { 0 };
|
|
|
|
uint16_t id;
|
2021-01-14 13:02:57 -08:00
|
|
|
isc_nmsocket_t *sock = NULL;
|
2021-08-04 13:14:11 -07:00
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr);
|
2021-08-04 13:14:11 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_dispatch_createtcp(dispatchmgr, &tcp_connect_addr,
|
|
|
|
&tcp_server_addr, -1, &dispatch);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listentcpdns(netmgr, ISC_NM_LISTEN_ONE,
|
|
|
|
&tcp_server_addr, noop_nameserver, NULL,
|
|
|
|
accept_cb, NULL, 0, NULL, &sock);
|
2021-08-04 13:14:11 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
region.base = rbuf;
|
|
|
|
region.length = sizeof(rbuf);
|
|
|
|
|
2021-10-03 15:15:50 -07:00
|
|
|
result = dns_dispatch_add(dispatch, 0, T_CLIENT_CONNECT,
|
|
|
|
&tcp_server_addr, connected, client_senddone,
|
|
|
|
response_timeout, ®ion, &id, &dispentry);
|
2021-08-04 13:14:11 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
memset(message, 0, sizeof(message));
|
|
|
|
message[0] = (id >> 8) & 0xff;
|
|
|
|
message[1] = id & 0xff;
|
|
|
|
|
|
|
|
region.base = message;
|
|
|
|
region.length = sizeof(message);
|
|
|
|
|
|
|
|
dns_dispatch_connect(dispentry);
|
|
|
|
|
|
|
|
uv_sem_wait(&sem);
|
|
|
|
|
|
|
|
assert_int_equal(atomic_load_acquire(&testdata.result), ISC_R_TIMEDOUT);
|
|
|
|
|
|
|
|
isc_nm_stoplistening(sock);
|
|
|
|
isc_nmsocket_close(&sock);
|
|
|
|
assert_null(sock);
|
|
|
|
|
2021-10-03 15:15:50 -07:00
|
|
|
dns_dispatch_done(&dispentry);
|
2021-08-04 13:14:11 -07:00
|
|
|
|
|
|
|
dns_dispatch_detach(&dispatch);
|
|
|
|
dns_dispatchmgr_detach(&dispatchmgr);
|
|
|
|
}
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(dispatch_tcp_response) {
|
2021-08-04 13:14:11 -07:00
|
|
|
isc_result_t result;
|
|
|
|
isc_region_t region;
|
|
|
|
unsigned char rbuf[12] = { 0 };
|
|
|
|
unsigned char message[12] = { 0 };
|
2021-01-14 13:02:57 -08:00
|
|
|
uint16_t id;
|
2021-08-04 13:14:11 -07:00
|
|
|
isc_nmsocket_t *sock = NULL;
|
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-08-04 13:14:11 -07:00
|
|
|
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr);
|
2021-08-04 13:14:11 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_dispatch_createtcp(dispatchmgr, &tcp_connect_addr,
|
|
|
|
&tcp_server_addr, -1, &dispatch);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listentcpdns(netmgr, ISC_NM_LISTEN_ONE,
|
|
|
|
&tcp_server_addr, nameserver, NULL,
|
2022-03-23 13:57:15 +01:00
|
|
|
accept_cb, NULL, 0, NULL, &sock);
|
2021-08-04 13:14:11 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
region.base = rbuf;
|
|
|
|
region.length = sizeof(rbuf);
|
|
|
|
|
2021-10-03 15:15:50 -07:00
|
|
|
result = dns_dispatch_add(dispatch, 0, T_CLIENT_CONNECT,
|
|
|
|
&tcp_server_addr, connected, client_senddone,
|
|
|
|
response, ®ion, &id, &dispentry);
|
2021-08-04 13:14:11 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
memset(message, 0, sizeof(message));
|
|
|
|
message[0] = (id >> 8) & 0xff;
|
|
|
|
message[1] = id & 0xff;
|
|
|
|
|
|
|
|
region.base = message;
|
|
|
|
region.length = sizeof(message);
|
|
|
|
|
|
|
|
dns_dispatch_connect(dispentry);
|
|
|
|
|
|
|
|
uv_sem_wait(&sem);
|
|
|
|
|
|
|
|
assert_in_range(atomic_load_acquire(&testdata.responses), 1, 2);
|
|
|
|
assert_int_equal(atomic_load_acquire(&testdata.result), ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
|
|
|
|
isc_nm_stoplistening(sock);
|
|
|
|
isc_nmsocket_close(&sock);
|
|
|
|
assert_null(sock);
|
|
|
|
|
2021-10-03 15:15:50 -07:00
|
|
|
dns_dispatch_done(&dispentry);
|
2021-08-04 13:14:11 -07:00
|
|
|
|
|
|
|
dns_dispatch_detach(&dispatch);
|
|
|
|
dns_dispatchmgr_detach(&dispatchmgr);
|
|
|
|
}
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(dispatch_timeout_udp_response) {
|
2021-08-04 13:14:11 -07:00
|
|
|
isc_result_t result;
|
|
|
|
isc_region_t region;
|
|
|
|
unsigned char rbuf[12] = { 0 };
|
|
|
|
unsigned char message[12] = { 0 };
|
|
|
|
uint16_t id;
|
|
|
|
isc_nmsocket_t *sock = NULL;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
udp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
isc_sockaddr_fromin6(&udp_connect_addr, &in6addr_loopback, 0);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
result = dns_dispatchmgr_create(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-08-04 13:14:11 -07:00
|
|
|
result = dns_dispatch_createudp(dispatchmgr, &tcp_connect_addr,
|
|
|
|
&dispatch);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listenudp(netmgr, ISC_NM_LISTEN_ONE, &udp_server_addr,
|
|
|
|
noop_nameserver, NULL, &sock);
|
2021-08-04 13:14:11 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
region.base = rbuf;
|
|
|
|
region.length = sizeof(rbuf);
|
|
|
|
|
2021-10-03 15:15:50 -07:00
|
|
|
result = dns_dispatch_add(dispatch, 0, T_CLIENT_CONNECT,
|
|
|
|
&udp_server_addr, connected, client_senddone,
|
|
|
|
response_timeout, ®ion, &id, &dispentry);
|
2021-08-04 13:14:11 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
memset(message, 0, sizeof(message));
|
|
|
|
message[0] = (id >> 8) & 0xff;
|
|
|
|
message[1] = id & 0xff;
|
|
|
|
|
|
|
|
region.base = message;
|
|
|
|
region.length = sizeof(message);
|
|
|
|
|
|
|
|
dns_dispatch_connect(dispentry);
|
|
|
|
|
|
|
|
uv_sem_wait(&sem);
|
|
|
|
|
|
|
|
assert_int_equal(atomic_load_acquire(&testdata.result), ISC_R_TIMEDOUT);
|
|
|
|
|
|
|
|
isc_nm_stoplistening(sock);
|
|
|
|
isc_nmsocket_close(&sock);
|
|
|
|
assert_null(sock);
|
|
|
|
|
2021-10-03 15:15:50 -07:00
|
|
|
dns_dispatch_done(&dispentry);
|
2021-08-04 13:14:11 -07:00
|
|
|
|
|
|
|
dns_dispatch_detach(&dispatch);
|
|
|
|
dns_dispatchmgr_detach(&dispatchmgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test dispatch getnext */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(dispatch_getnext) {
|
2021-08-04 13:14:11 -07:00
|
|
|
isc_result_t result;
|
|
|
|
isc_region_t region;
|
|
|
|
isc_nmsocket_t *sock = NULL;
|
|
|
|
unsigned char message[12] = { 0 };
|
|
|
|
unsigned char rbuf[12] = { 0 };
|
|
|
|
uint16_t id;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
result = dns_dispatchmgr_create(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-08-04 13:14:11 -07:00
|
|
|
result = dns_dispatch_createudp(dispatchmgr, &udp_connect_addr,
|
2021-01-14 13:02:57 -08:00
|
|
|
&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.
|
|
|
|
*/
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listenudp(netmgr, ISC_NM_LISTEN_ONE, &udp_server_addr,
|
|
|
|
nameserver, NULL, &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-10-03 15:15:50 -07:00
|
|
|
result = dns_dispatch_add(dispatch, 0, T_CLIENT_CONNECT,
|
|
|
|
&udp_server_addr, connected, client_senddone,
|
|
|
|
response_getnext, ®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
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
dns_dispatch_connect(dispentry);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
uv_sem_wait(&sem);
|
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);
|
|
|
|
|
2021-08-04 13:14:11 -07:00
|
|
|
/* Cleanup */
|
2021-01-14 13:02:57 -08:00
|
|
|
isc_nm_stoplistening(sock);
|
|
|
|
isc_nmsocket_close(&sock);
|
|
|
|
assert_null(sock);
|
2016-07-11 13:36:16 +10:00
|
|
|
|
2021-10-03 15:15:50 -07:00
|
|
|
dns_dispatch_done(&dispentry);
|
2016-07-11 13:36:16 +10:00
|
|
|
dns_dispatch_detach(&dispatch);
|
2021-05-25 22:54:17 -07:00
|
|
|
dns_dispatchmgr_detach(&dispatchmgr);
|
2018-10-26 08:46:28 -07:00
|
|
|
}
|
2016-07-11 13:36:16 +10:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_TEST_LIST_START
|
2018-10-26 08:46:28 -07:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_TEST_ENTRY_CUSTOM(dispatch_timeout_tcp_connect, _setup, _teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(dispatch_timeout_tcp_response, _setup, _teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(dispatch_tcp_response, _setup, _teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(dispatch_timeout_udp_response, _setup, _teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(dispatchset_create, _setup, _teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(dispatchset_get, _setup, _teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(dispatch_getnext, _setup, _teardown)
|
2018-10-26 08:46:28 -07:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_TEST_LIST_END
|
2018-10-26 08:46:28 -07:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_TEST_MAIN
|