2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 13:08:06 +00:00

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

135 lines
2.5 KiB
C
Raw Normal View History

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
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* 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
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*! \file */
#include <inttypes.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
Increase the number of available file descriptors notify_test and query_test run out of descriptors on some platforms. % ./notify_test [==========] Running 1 test(s). [ RUN ] notify_start netmgr/tcp.c:369: REQUIRE(csock->fd >= 0) failed, back trace 0 libisc-9.19.9-dev.dylib 0x00000001045c5080 default_callback + 72 1 libisc-9.19.9-dev.dylib 0x00000001045c4ffc isc_assertion_failed + 56 2 libisc-9.19.9-dev.dylib 0x00000001045b8bcc start_tcp_child + 304 3 libisc-9.19.9-dev.dylib 0x00000001045b8710 isc_nm_listentcp + 636 4 libisc-9.19.9-dev.dylib 0x00000001045b3e0c isc_nm_listenstreamdns + 344 5 libns-9.19.9-dev.dylib 0x0000000104b90630 ns_interface_listentcp + 152 6 libns-9.19.9-dev.dylib 0x0000000104b8f65c interface_setup + 488 7 libns-9.19.9-dev.dylib 0x0000000104b8de98 do_scan + 2028 8 libns-9.19.9-dev.dylib 0x0000000104b8d640 ns_interfacemgr_scan + 212 9 notify_test 0x000000010418ddd0 scan_interfaces + 44 10 libisc-9.19.9-dev.dylib 0x00000001045d5fd8 isc__job_cb + 116 11 libuv.1.dylib 0x000000010545afe4 uv__run_idle + 152 12 libuv.1.dylib 0x0000000105455cd0 uv_run + 204 13 libisc-9.19.9-dev.dylib 0x00000001045e1120 loop_run + 460 14 libisc-9.19.9-dev.dylib 0x00000001045df824 loop_thread + 44 15 libisc-9.19.9-dev.dylib 0x00000001045df6dc isc_loopmgr_run + 456 16 notify_test 0x000000010418b900 run_test_notify_start + 88 17 libcmocka.0.dylib 0x00000001054968c0 cmocka_run_one_test_or_fixture + 448 18 libcmocka.0.dylib 0x0000000105494ca4 _cmocka_run_group_tests + 848 19 notify_test 0x000000010418be60 main + 120 20 libdyld.dylib 0x0000000181509430 start + 4 Abort % ./query_test [==========] Running 4 test(s). [ RUN ] ns__query_sfcache netmgr/tcp.c:369: REQUIRE(csock->fd >= 0) failed, back trace 0 libisc-9.19.9-dev.dylib 0x000000010294d080 default_callback + 72 1 libisc-9.19.9-dev.dylib 0x000000010294cffc isc_assertion_failed + 56 2 libisc-9.19.9-dev.dylib 0x0000000102940bcc start_tcp_child + 304 3 libisc-9.19.9-dev.dylib 0x0000000102940710 isc_nm_listentcp + 636 4 libisc-9.19.9-dev.dylib 0x000000010293be0c isc_nm_listenstreamdns + 344 5 libns-9.19.9-dev.dylib 0x00000001026cc630 ns_interface_listentcp + 152 6 libns-9.19.9-dev.dylib 0x00000001026cb65c interface_setup + 488 7 libns-9.19.9-dev.dylib 0x00000001026c9e98 do_scan + 2028 8 libns-9.19.9-dev.dylib 0x00000001026c9640 ns_interfacemgr_scan + 212 9 query_test 0x00000001026a1018 scan_interfaces + 44 10 libisc-9.19.9-dev.dylib 0x000000010295dfd8 isc__job_cb + 116 11 libuv.1.dylib 0x0000000103996fe4 uv__run_idle + 152 12 libuv.1.dylib 0x0000000103991cd0 uv_run + 204 13 libisc-9.19.9-dev.dylib 0x0000000102969120 loop_run + 460 14 libisc-9.19.9-dev.dylib 0x0000000102967824 loop_thread + 44 15 libisc-9.19.9-dev.dylib 0x00000001029676dc isc_loopmgr_run + 456 16 query_test 0x000000010269cf34 run_test_ns__query_sfcache + 88 17 libcmocka.0.dylib 0x00000001028068c0 cmocka_run_one_test_or_fixture + 448 18 libcmocka.0.dylib 0x0000000102804ca4 _cmocka_run_group_tests + 848 19 query_test 0x000000010269eab8 main + 116 20 libdyld.dylib 0x0000000181509430 start + 4 Abort % expected_creads can exceed the number of file descriptors on some platforms. % ./udp_test [==========] Running 18 test(s). [ RUN ] mock_listenudp_uv_udp_open [ OK ] mock_listenudp_uv_udp_open [ RUN ] mock_listenudp_uv_udp_bind [ OK ] mock_listenudp_uv_udp_bind [ RUN ] mock_listenudp_uv_udp_recv_start [ OK ] mock_listenudp_uv_udp_recv_start [ RUN ] mock_udpconnect_uv_udp_open [ OK ] mock_udpconnect_uv_udp_open [ RUN ] mock_udpconnect_uv_udp_bind [ OK ] mock_udpconnect_uv_udp_bind [ RUN ] mock_udpconnect_uv_udp_connect [ OK ] mock_udpconnect_uv_udp_connect [ RUN ] mock_udpconnect_uv_recv_buffer_size [ OK ] mock_udpconnect_uv_recv_buffer_size [ RUN ] mock_udpconnect_uv_send_buffer_size [ OK ] mock_udpconnect_uv_send_buffer_size [ RUN ] udp_noop [ OK ] udp_noop [ RUN ] udp_noresponse [ OK ] udp_noresponse [ RUN ] udp_shutdown_connect [ OK ] udp_shutdown_connect [ RUN ] udp_shutdown_read [ OK ] udp_shutdown_read [ RUN ] udp_cancel_read [ OK ] udp_cancel_read [ RUN ] udp_timeout_recovery [ OK ] udp_timeout_recovery [ RUN ] udp_double_read [ OK ] udp_double_read [ RUN ] udp_recv_one [ OK ] udp_recv_one [ RUN ] udp_recv_two [ OK ] udp_recv_two [ RUN ] udp_recv_send udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) %
2023-01-04 16:59:47 +11:00
#include <sys/resource.h>
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
#include <time.h>
#include <isc/buffer.h>
#include <isc/hash.h>
2022-07-26 13:03:22 +02:00
#include <isc/loop.h>
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
#include <isc/managers.h>
#include <isc/mem.h>
#include <isc/os.h>
#include <isc/string.h>
#include <isc/timer.h>
#include <isc/util.h>
#include <tests/isc.h>
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_mem_t *mctx = NULL;
isc_log_t *lctx = NULL;
2022-07-26 13:03:22 +02:00
isc_loop_t *mainloop = NULL;
isc_loopmgr_t *loopmgr = 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
isc_nm_t *netmgr = NULL;
unsigned int workers = -1;
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
Increase the number of available file descriptors notify_test and query_test run out of descriptors on some platforms. % ./notify_test [==========] Running 1 test(s). [ RUN ] notify_start netmgr/tcp.c:369: REQUIRE(csock->fd >= 0) failed, back trace 0 libisc-9.19.9-dev.dylib 0x00000001045c5080 default_callback + 72 1 libisc-9.19.9-dev.dylib 0x00000001045c4ffc isc_assertion_failed + 56 2 libisc-9.19.9-dev.dylib 0x00000001045b8bcc start_tcp_child + 304 3 libisc-9.19.9-dev.dylib 0x00000001045b8710 isc_nm_listentcp + 636 4 libisc-9.19.9-dev.dylib 0x00000001045b3e0c isc_nm_listenstreamdns + 344 5 libns-9.19.9-dev.dylib 0x0000000104b90630 ns_interface_listentcp + 152 6 libns-9.19.9-dev.dylib 0x0000000104b8f65c interface_setup + 488 7 libns-9.19.9-dev.dylib 0x0000000104b8de98 do_scan + 2028 8 libns-9.19.9-dev.dylib 0x0000000104b8d640 ns_interfacemgr_scan + 212 9 notify_test 0x000000010418ddd0 scan_interfaces + 44 10 libisc-9.19.9-dev.dylib 0x00000001045d5fd8 isc__job_cb + 116 11 libuv.1.dylib 0x000000010545afe4 uv__run_idle + 152 12 libuv.1.dylib 0x0000000105455cd0 uv_run + 204 13 libisc-9.19.9-dev.dylib 0x00000001045e1120 loop_run + 460 14 libisc-9.19.9-dev.dylib 0x00000001045df824 loop_thread + 44 15 libisc-9.19.9-dev.dylib 0x00000001045df6dc isc_loopmgr_run + 456 16 notify_test 0x000000010418b900 run_test_notify_start + 88 17 libcmocka.0.dylib 0x00000001054968c0 cmocka_run_one_test_or_fixture + 448 18 libcmocka.0.dylib 0x0000000105494ca4 _cmocka_run_group_tests + 848 19 notify_test 0x000000010418be60 main + 120 20 libdyld.dylib 0x0000000181509430 start + 4 Abort % ./query_test [==========] Running 4 test(s). [ RUN ] ns__query_sfcache netmgr/tcp.c:369: REQUIRE(csock->fd >= 0) failed, back trace 0 libisc-9.19.9-dev.dylib 0x000000010294d080 default_callback + 72 1 libisc-9.19.9-dev.dylib 0x000000010294cffc isc_assertion_failed + 56 2 libisc-9.19.9-dev.dylib 0x0000000102940bcc start_tcp_child + 304 3 libisc-9.19.9-dev.dylib 0x0000000102940710 isc_nm_listentcp + 636 4 libisc-9.19.9-dev.dylib 0x000000010293be0c isc_nm_listenstreamdns + 344 5 libns-9.19.9-dev.dylib 0x00000001026cc630 ns_interface_listentcp + 152 6 libns-9.19.9-dev.dylib 0x00000001026cb65c interface_setup + 488 7 libns-9.19.9-dev.dylib 0x00000001026c9e98 do_scan + 2028 8 libns-9.19.9-dev.dylib 0x00000001026c9640 ns_interfacemgr_scan + 212 9 query_test 0x00000001026a1018 scan_interfaces + 44 10 libisc-9.19.9-dev.dylib 0x000000010295dfd8 isc__job_cb + 116 11 libuv.1.dylib 0x0000000103996fe4 uv__run_idle + 152 12 libuv.1.dylib 0x0000000103991cd0 uv_run + 204 13 libisc-9.19.9-dev.dylib 0x0000000102969120 loop_run + 460 14 libisc-9.19.9-dev.dylib 0x0000000102967824 loop_thread + 44 15 libisc-9.19.9-dev.dylib 0x00000001029676dc isc_loopmgr_run + 456 16 query_test 0x000000010269cf34 run_test_ns__query_sfcache + 88 17 libcmocka.0.dylib 0x00000001028068c0 cmocka_run_one_test_or_fixture + 448 18 libcmocka.0.dylib 0x0000000102804ca4 _cmocka_run_group_tests + 848 19 query_test 0x000000010269eab8 main + 116 20 libdyld.dylib 0x0000000181509430 start + 4 Abort % expected_creads can exceed the number of file descriptors on some platforms. % ./udp_test [==========] Running 18 test(s). [ RUN ] mock_listenudp_uv_udp_open [ OK ] mock_listenudp_uv_udp_open [ RUN ] mock_listenudp_uv_udp_bind [ OK ] mock_listenudp_uv_udp_bind [ RUN ] mock_listenudp_uv_udp_recv_start [ OK ] mock_listenudp_uv_udp_recv_start [ RUN ] mock_udpconnect_uv_udp_open [ OK ] mock_udpconnect_uv_udp_open [ RUN ] mock_udpconnect_uv_udp_bind [ OK ] mock_udpconnect_uv_udp_bind [ RUN ] mock_udpconnect_uv_udp_connect [ OK ] mock_udpconnect_uv_udp_connect [ RUN ] mock_udpconnect_uv_recv_buffer_size [ OK ] mock_udpconnect_uv_recv_buffer_size [ RUN ] mock_udpconnect_uv_send_buffer_size [ OK ] mock_udpconnect_uv_send_buffer_size [ RUN ] udp_noop [ OK ] udp_noop [ RUN ] udp_noresponse [ OK ] udp_noresponse [ RUN ] udp_shutdown_connect [ OK ] udp_shutdown_connect [ RUN ] udp_shutdown_read [ OK ] udp_shutdown_read [ RUN ] udp_cancel_read [ OK ] udp_cancel_read [ RUN ] udp_timeout_recovery [ OK ] udp_timeout_recovery [ RUN ] udp_double_read [ OK ] udp_double_read [ RUN ] udp_recv_one [ OK ] udp_recv_one [ RUN ] udp_recv_two [ OK ] udp_recv_two [ RUN ] udp_recv_send udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) %
2023-01-04 16:59:47 +11:00
static void
adjustnofile(void) {
struct rlimit rl;
if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
if (rl.rlim_cur != rl.rlim_max) {
rl.rlim_cur = rl.rlim_max;
setrlimit(RLIMIT_NOFILE, &rl);
}
}
}
2022-07-26 13:03:22 +02:00
int
setup_mctx(void **state __attribute__((__unused__))) {
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
isc_mem_create(&mctx);
return (0);
}
int
teardown_mctx(void **state __attribute__((__unused__))) {
isc_mem_destroy(&mctx);
return (0);
}
int
setup_loopmgr(void **state __attribute__((__unused__))) {
char *env_workers = NULL;
REQUIRE(mctx != NULL);
env_workers = getenv("ISC_TASK_WORKERS");
if (env_workers != NULL) {
workers = atoi(env_workers);
} else {
/* We always need at least two loops for some of the tests */
workers = isc_os_ncpus() + 1;
}
INSIST(workers != 0);
isc_loopmgr_create(mctx, workers, &loopmgr);
mainloop = isc_loop_main(loopmgr);
return (0);
}
int
teardown_loopmgr(void **state __attribute__((__unused__))) {
REQUIRE(netmgr == NULL);
mainloop = NULL;
isc_loopmgr_destroy(&loopmgr);
return (0);
}
int
setup_netmgr(void **state __attribute__((__unused__))) {
REQUIRE(loopmgr != 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
Increase the number of available file descriptors notify_test and query_test run out of descriptors on some platforms. % ./notify_test [==========] Running 1 test(s). [ RUN ] notify_start netmgr/tcp.c:369: REQUIRE(csock->fd >= 0) failed, back trace 0 libisc-9.19.9-dev.dylib 0x00000001045c5080 default_callback + 72 1 libisc-9.19.9-dev.dylib 0x00000001045c4ffc isc_assertion_failed + 56 2 libisc-9.19.9-dev.dylib 0x00000001045b8bcc start_tcp_child + 304 3 libisc-9.19.9-dev.dylib 0x00000001045b8710 isc_nm_listentcp + 636 4 libisc-9.19.9-dev.dylib 0x00000001045b3e0c isc_nm_listenstreamdns + 344 5 libns-9.19.9-dev.dylib 0x0000000104b90630 ns_interface_listentcp + 152 6 libns-9.19.9-dev.dylib 0x0000000104b8f65c interface_setup + 488 7 libns-9.19.9-dev.dylib 0x0000000104b8de98 do_scan + 2028 8 libns-9.19.9-dev.dylib 0x0000000104b8d640 ns_interfacemgr_scan + 212 9 notify_test 0x000000010418ddd0 scan_interfaces + 44 10 libisc-9.19.9-dev.dylib 0x00000001045d5fd8 isc__job_cb + 116 11 libuv.1.dylib 0x000000010545afe4 uv__run_idle + 152 12 libuv.1.dylib 0x0000000105455cd0 uv_run + 204 13 libisc-9.19.9-dev.dylib 0x00000001045e1120 loop_run + 460 14 libisc-9.19.9-dev.dylib 0x00000001045df824 loop_thread + 44 15 libisc-9.19.9-dev.dylib 0x00000001045df6dc isc_loopmgr_run + 456 16 notify_test 0x000000010418b900 run_test_notify_start + 88 17 libcmocka.0.dylib 0x00000001054968c0 cmocka_run_one_test_or_fixture + 448 18 libcmocka.0.dylib 0x0000000105494ca4 _cmocka_run_group_tests + 848 19 notify_test 0x000000010418be60 main + 120 20 libdyld.dylib 0x0000000181509430 start + 4 Abort % ./query_test [==========] Running 4 test(s). [ RUN ] ns__query_sfcache netmgr/tcp.c:369: REQUIRE(csock->fd >= 0) failed, back trace 0 libisc-9.19.9-dev.dylib 0x000000010294d080 default_callback + 72 1 libisc-9.19.9-dev.dylib 0x000000010294cffc isc_assertion_failed + 56 2 libisc-9.19.9-dev.dylib 0x0000000102940bcc start_tcp_child + 304 3 libisc-9.19.9-dev.dylib 0x0000000102940710 isc_nm_listentcp + 636 4 libisc-9.19.9-dev.dylib 0x000000010293be0c isc_nm_listenstreamdns + 344 5 libns-9.19.9-dev.dylib 0x00000001026cc630 ns_interface_listentcp + 152 6 libns-9.19.9-dev.dylib 0x00000001026cb65c interface_setup + 488 7 libns-9.19.9-dev.dylib 0x00000001026c9e98 do_scan + 2028 8 libns-9.19.9-dev.dylib 0x00000001026c9640 ns_interfacemgr_scan + 212 9 query_test 0x00000001026a1018 scan_interfaces + 44 10 libisc-9.19.9-dev.dylib 0x000000010295dfd8 isc__job_cb + 116 11 libuv.1.dylib 0x0000000103996fe4 uv__run_idle + 152 12 libuv.1.dylib 0x0000000103991cd0 uv_run + 204 13 libisc-9.19.9-dev.dylib 0x0000000102969120 loop_run + 460 14 libisc-9.19.9-dev.dylib 0x0000000102967824 loop_thread + 44 15 libisc-9.19.9-dev.dylib 0x00000001029676dc isc_loopmgr_run + 456 16 query_test 0x000000010269cf34 run_test_ns__query_sfcache + 88 17 libcmocka.0.dylib 0x00000001028068c0 cmocka_run_one_test_or_fixture + 448 18 libcmocka.0.dylib 0x0000000102804ca4 _cmocka_run_group_tests + 848 19 query_test 0x000000010269eab8 main + 116 20 libdyld.dylib 0x0000000181509430 start + 4 Abort % expected_creads can exceed the number of file descriptors on some platforms. % ./udp_test [==========] Running 18 test(s). [ RUN ] mock_listenudp_uv_udp_open [ OK ] mock_listenudp_uv_udp_open [ RUN ] mock_listenudp_uv_udp_bind [ OK ] mock_listenudp_uv_udp_bind [ RUN ] mock_listenudp_uv_udp_recv_start [ OK ] mock_listenudp_uv_udp_recv_start [ RUN ] mock_udpconnect_uv_udp_open [ OK ] mock_udpconnect_uv_udp_open [ RUN ] mock_udpconnect_uv_udp_bind [ OK ] mock_udpconnect_uv_udp_bind [ RUN ] mock_udpconnect_uv_udp_connect [ OK ] mock_udpconnect_uv_udp_connect [ RUN ] mock_udpconnect_uv_recv_buffer_size [ OK ] mock_udpconnect_uv_recv_buffer_size [ RUN ] mock_udpconnect_uv_send_buffer_size [ OK ] mock_udpconnect_uv_send_buffer_size [ RUN ] udp_noop [ OK ] udp_noop [ RUN ] udp_noresponse [ OK ] udp_noresponse [ RUN ] udp_shutdown_connect [ OK ] udp_shutdown_connect [ RUN ] udp_shutdown_read [ OK ] udp_shutdown_read [ RUN ] udp_cancel_read [ OK ] udp_cancel_read [ RUN ] udp_timeout_recovery [ OK ] udp_timeout_recovery [ RUN ] udp_double_read [ OK ] udp_double_read [ RUN ] udp_recv_one [ OK ] udp_recv_one [ RUN ] udp_recv_two [ OK ] udp_recv_two [ RUN ] udp_recv_send udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) udp__connect_cb(0x0, too many open files, 0x0) %
2023-01-04 16:59:47 +11:00
adjustnofile();
isc_netmgr_create(mctx, loopmgr, &netmgr);
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
return (0);
}
int
teardown_netmgr(void **state __attribute__((__unused__))) {
REQUIRE(loopmgr != NULL);
isc_netmgr_destroy(&netmgr);
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
return (0);
}
int
setup_managers(void **state) {
setup_loopmgr(state);
setup_netmgr(state);
return (0);
}
int
teardown_managers(void **state) {
teardown_netmgr(state);
teardown_loopmgr(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
return (0);
}