diff --git a/.clang-format b/.clang-format index 7137d8e008..41a90bf5bb 100644 --- a/.clang-format +++ b/.clang-format @@ -58,6 +58,8 @@ IncludeCategories: Priority: 55 - Regex: '^".*"' Priority: 99 + - Regex: '^' Priority: 1 - Regex: '".*"' diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 501ff99b37..b6d7ad9d43 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1420,9 +1420,9 @@ gcov: # Generate XML file in the Cobertura XML format suitable for use by GitLab # for the purpose of displaying code coverage information in the diff view # of a given merge request. - - gcovr --root . --exclude-directories bin/tests --exclude-directories doc --exclude-directories lib/samples --exclude 'lib/.*/tests/.*' --xml -o coverage.xml - - gcovr --root . --exclude-directories bin/tests --exclude-directories doc --exclude-directories lib/samples --exclude 'lib/.*/tests/.*' --html-details -o coverage.html - - gcovr --root . --exclude-directories bin/tests --exclude-directories doc --exclude-directories lib/samples --exclude 'lib/.*/tests/.*' -o coverage.txt + - gcovr --root . --exclude-directories bin/tests --exclude-directories doc --exclude-directories lib/samples --exclude tests --xml -o coverage.xml + - gcovr --root . --exclude-directories bin/tests --exclude-directories doc --exclude-directories lib/samples --exclude tests --html-details -o coverage.html + - gcovr --root . --exclude-directories bin/tests --exclude-directories doc --exclude-directories lib/samples --exclude tests -o coverage.txt - tail -n 3 coverage.txt artifacts: paths: diff --git a/CHANGES b/CHANGES index edd4233b05..23c72d1811 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +5895. [test] Add new set of unit test macros and move the unit + tests under single namespace in /tests/. [GL !6243] + 5894. [func] Avoid periodic interface re-scans on Linux by default, where a reliable event-based mechanism for detecting interface state changes is available. diff --git a/Makefile.am b/Makefile.am index f2005cfab7..2f09561659 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,10 @@ include $(top_srcdir)/Makefile.top SUBDIRS = . lib doc bin fuzz +if HAVE_CMOCKA +SUBDIRS += tests +endif HAVE_CMOCKA + BUILT_SOURCES = bind.keys.h CLEANFILES = bind.keys.h @@ -12,7 +16,7 @@ dist_sysconf_DATA = bind.keys .PHONY: doc -EXTRA_DIST = \ +EXTRA_DIST = \ util/bindkeys.pl \ contrib \ CHANGES \ diff --git a/Makefile.tests b/Makefile.tests index 7ae2c5ada1..e1b7e0e046 100644 --- a/Makefile.tests +++ b/Makefile.tests @@ -3,18 +3,21 @@ unit-local: check +if HAVE_CMOCKA TESTS = $(check_PROGRAMS) +endif HAVE_CMOCKA -LOG_COMPILER = $(builddir)/../../unit-test-driver.sh +LOG_COMPILER = $(top_builddir)/tests/unit-test-driver.sh AM_CFLAGS += \ + -I$(top_srcdir)/tests/include \ $(TEST_CFLAGS) AM_CPPFLAGS += \ $(CMOCKA_CFLAGS) \ -DNAMED_PLUGINDIR=\"$(pkglibdir)\" \ - -DSKIPPED_TEST_EXIT_CODE=77 \ -DTESTS_DIR=\"$(abs_srcdir)\" -LDADD += \ +LDADD += \ + $(top_builddir)/tests/libtest/libtest.la \ $(CMOCKA_LIBS) diff --git a/configure.ac b/configure.ac index 7b284ef6da..6d7f5feb54 100644 --- a/configure.ac +++ b/configure.ac @@ -1581,14 +1581,16 @@ AC_CONFIG_FILES([doc/Makefile # Unit Tests -AC_CONFIG_FILES([lib/isc/tests/Makefile - lib/dns/tests/Makefile - lib/ns/tests/Makefile - lib/irs/tests/Makefile - lib/isccfg/tests/Makefile]) +AC_CONFIG_FILES([tests/Makefile + tests/isc/Makefile + tests/dns/Makefile + tests/ns/Makefile + tests/irs/Makefile + tests/isccfg/Makefile + tests/libtest/Makefile]) -AC_CONFIG_FILES([lib/unit-test-driver.sh], - [chmod +x lib/unit-test-driver.sh]) +AC_CONFIG_FILES([tests/unit-test-driver.sh], + [chmod +x tests/unit-test-driver.sh]) # System Tests diff --git a/lib/dns/Makefile.am b/lib/dns/Makefile.am index cf49c33b38..35602b2259 100644 --- a/lib/dns/Makefile.am +++ b/lib/dns/Makefile.am @@ -321,7 +321,3 @@ if HAVE_LMDB libdns_la_CPPFLAGS += $(LMDB_CFLAGS) libdns_la_LIBADD += $(LMDB_LIBS) endif - -if HAVE_CMOCKA -SUBDIRS = tests -endif diff --git a/lib/dns/tests b/lib/dns/tests new file mode 120000 index 0000000000..e4acc10b18 --- /dev/null +++ b/lib/dns/tests @@ -0,0 +1 @@ +../../tests/dns \ No newline at end of file diff --git a/lib/irs/Makefile.am b/lib/irs/Makefile.am index eac972b26d..85c4065af3 100644 --- a/lib/irs/Makefile.am +++ b/lib/irs/Makefile.am @@ -25,7 +25,3 @@ libirs_la_LIBADD = \ libirs_la_LDFLAGS = \ $(AM_LDFLAGS) \ -release "$(PACKAGE_VERSION)" - -if HAVE_CMOCKA -SUBDIRS = tests -endif diff --git a/lib/irs/tests b/lib/irs/tests new file mode 120000 index 0000000000..247a63e1e5 --- /dev/null +++ b/lib/irs/tests @@ -0,0 +1 @@ +../../tests/irs \ No newline at end of file diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index 16bb818f46..fb443b5d6e 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -251,7 +251,3 @@ libisc_la_CPPFLAGS += \ libisc_la_LIBADD += \ $(LIBXML2_LIBS) endif HAVE_LIBXML2 - -if HAVE_CMOCKA -SUBDIRS = tests -endif diff --git a/lib/isc/tests b/lib/isc/tests new file mode 120000 index 0000000000..9c8d7ce1d0 --- /dev/null +++ b/lib/isc/tests @@ -0,0 +1 @@ +../../tests/isc \ No newline at end of file diff --git a/lib/isc/tests/isctest.c b/lib/isc/tests/isctest.c deleted file mode 100644 index 31690357c9..0000000000 --- a/lib/isc/tests/isctest.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * 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 "isctest.h" -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -isc_mem_t *test_mctx = NULL; -isc_log_t *test_lctx = NULL; -isc_taskmgr_t *taskmgr = NULL; -isc_timermgr_t *timermgr = NULL; -isc_nm_t *netmgr = NULL; -isc_task_t *maintask = NULL; -int ncpus; - -static bool test_running = false; - -/* - * Logging categories: this needs to match the list in bin/named/log.c. - */ -static isc_logcategory_t categories[] = { { "", 0 }, - { "client", 0 }, - { "network", 0 }, - { "update", 0 }, - { "queries", 0 }, - { "unmatched", 0 }, - { "update-security", 0 }, - { "query-errors", 0 }, - { NULL, 0 } }; - -static void -cleanup_managers(void) { - if (maintask != NULL) { - isc_task_detach(&maintask); - } - isc_managers_destroy(netmgr == NULL ? NULL : &netmgr, - taskmgr == NULL ? NULL : &taskmgr, - timermgr == NULL ? NULL : &timermgr); -} - -static isc_result_t -create_managers(unsigned int workers) { - isc_result_t result; - char *p; - - if (workers == 0) { - workers = isc_os_ncpus(); - } - p = getenv("ISC_TASK_WORKERS"); - if (p != NULL) { - workers = atoi(p); - } - INSIST(workers != 0); - - isc_managers_create(test_mctx, workers, 0, &netmgr, &taskmgr, - &timermgr); - - CHECK(isc_task_create(taskmgr, 0, &maintask, 0)); - isc_taskmgr_setexcltask(taskmgr, maintask); - - return (ISC_R_SUCCESS); - -cleanup: - cleanup_managers(); - return (result); -} - -isc_result_t -isc_test_begin(FILE *logfile, bool start_managers, unsigned int workers) { - isc_result_t result; - - INSIST(!test_running); - test_running = true; - - isc_mem_debugging |= ISC_MEM_DEBUGRECORD; - - INSIST(test_mctx == NULL); - isc_mem_create(&test_mctx); - - if (logfile != NULL) { - isc_logdestination_t destination; - isc_logconfig_t *logconfig = NULL; - - INSIST(test_lctx == NULL); - isc_log_create(test_mctx, &test_lctx, &logconfig); - isc_log_registercategories(test_lctx, categories); - isc_log_setcontext(test_lctx); - - destination.file.stream = logfile; - destination.file.name = NULL; - destination.file.versions = ISC_LOG_ROLLNEVER; - destination.file.maximum_size = 0; - isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, - ISC_LOG_DYNAMIC, &destination, 0); - CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); - } - - ncpus = isc_os_ncpus(); - - if (start_managers) { - CHECK(create_managers(workers)); - } - - return (ISC_R_SUCCESS); - -cleanup: - isc_test_end(); - return (result); -} - -void -isc_test_end(void) { - if (maintask != NULL) { - isc_task_detach(&maintask); - } - - cleanup_managers(); - - if (test_lctx != NULL) { - isc_log_destroy(&test_lctx); - } - if (test_mctx != NULL) { - isc_mem_destroy(&test_mctx); - } - - test_running = false; -} - -/* - * Sleep for 'usec' microseconds. - */ -void -isc_test_nap(uint32_t usec) { - struct timespec ts; - - ts.tv_sec = usec / 1000000; - ts.tv_nsec = (usec % 1000000) * 1000; - nanosleep(&ts, NULL); -} diff --git a/lib/isc/tests/isctest.h b/lib/isc/tests/isctest.h deleted file mode 100644 index 36067a1434..0000000000 --- a/lib/isc/tests/isctest.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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. - */ - -#pragma once - -/*! \file */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define CHECK(r) \ - do { \ - result = (r); \ - if (result != ISC_R_SUCCESS) \ - goto cleanup; \ - } while (0) - -extern isc_mem_t *test_mctx; -extern isc_log_t *test_lctx; -extern isc_taskmgr_t *taskmgr; -extern isc_timermgr_t *timermgr; -extern isc_nm_t *netmgr; -extern int ncpus; - -isc_result_t -isc_test_begin(FILE *logfile, bool start_managers, unsigned int workers); -/*%< - * Begin test, logging to 'logfile' or default if not specified. - * - * If 'start_managers' is set, start a task manager, timer manager, - * and socket manager. - * - * If 'workers' is zero, use the number of CPUs on the system as a default; - * otherwise, set up the task manager with the specified number of worker - * threads. The environment variable ISC_TASK_WORKERS overrides this value. - */ - -void -isc_test_end(void); - -void -isc_test_nap(uint32_t usec); diff --git a/lib/isccfg/Makefile.am b/lib/isccfg/Makefile.am index 3205e3b93b..32e905aa96 100644 --- a/lib/isccfg/Makefile.am +++ b/lib/isccfg/Makefile.am @@ -33,7 +33,3 @@ libisccfg_la_LIBADD = \ libisccfg_la_LDFLAGS = \ $(AM_LDFLAGS) \ -release "$(PACKAGE_VERSION)" - -if HAVE_CMOCKA -SUBDIRS = tests -endif diff --git a/lib/isccfg/tests b/lib/isccfg/tests new file mode 120000 index 0000000000..1d7dfaf423 --- /dev/null +++ b/lib/isccfg/tests @@ -0,0 +1 @@ +../../tests/isccfg \ No newline at end of file diff --git a/lib/ns/Makefile.am b/lib/ns/Makefile.am index b2d5d73b4c..eb86aebe18 100644 --- a/lib/ns/Makefile.am +++ b/lib/ns/Makefile.am @@ -55,7 +55,3 @@ libns_la_LIBADD = \ libns_la_LDFLAGS = \ $(AM_LDFLAGS) \ -release "$(PACKAGE_VERSION)" - -if HAVE_CMOCKA -SUBDIRS = tests -endif diff --git a/lib/ns/tests b/lib/ns/tests new file mode 120000 index 0000000000..0ec3da8d12 --- /dev/null +++ b/lib/ns/tests @@ -0,0 +1 @@ +../../tests/ns \ No newline at end of file diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000000..78fe21f457 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +/unit-test-driver.sh diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000000..8b5dcbe842 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,16 @@ +include $(top_srcdir)/Makefile.top + +AM_CPPFLAGS += \ + $(LIBISC_CFLAGS) \ + $(LIBDNS_CFLAGS) \ + $(LIBNS_CFLAGS) \ + $(LIBUV_CFLAGS) \ + -I$(top_srcdir)/lib/isc + +LDADD += \ + $(LIBISC_LIBS) \ + $(LIBDNS_LIBS) \ + $(LIBNS_LIBS) + +SUBDIRS = libtest isc dns ns isccfg irs +check_PROGRAMS = diff --git a/lib/dns/tests/.gitignore b/tests/dns/.gitignore similarity index 100% rename from lib/dns/tests/.gitignore rename to tests/dns/.gitignore diff --git a/lib/dns/tests/Kdh.+002+18602.key b/tests/dns/Kdh.+002+18602.key similarity index 100% rename from lib/dns/tests/Kdh.+002+18602.key rename to tests/dns/Kdh.+002+18602.key diff --git a/lib/dns/tests/Krsa.+005+29235.key b/tests/dns/Krsa.+005+29235.key similarity index 100% rename from lib/dns/tests/Krsa.+005+29235.key rename to tests/dns/Krsa.+005+29235.key diff --git a/lib/dns/tests/Makefile.am b/tests/dns/Makefile.am similarity index 92% rename from lib/dns/tests/Makefile.am rename to tests/dns/Makefile.am index 5819b19489..0164a4ad87 100644 --- a/lib/dns/tests/Makefile.am +++ b/tests/dns/Makefile.am @@ -6,17 +6,15 @@ AM_CPPFLAGS += \ $(LIBUV_CFLAGS) \ $(KRB5_CFLAGS) \ -DSRCDIR=\"$(abs_srcdir)\" \ - -DBUILDDIR=\"$(abs_builddir)\" + -DBUILDDIR=\"$(abs_builddir)\" \ + -I$(top_srcdir)/lib/isc \ + -I$(top_srcdir)/lib/dns LDADD += \ - libdnstest.la \ $(LIBISC_LIBS) \ $(LIBUV_LIBS) \ $(LIBDNS_LIBS) -check_LTLIBRARIES = libdnstest.la -libdnstest_la_SOURCES = dnstest.c dnstest.h - check_PROGRAMS = \ acl_test \ db_test \ @@ -75,7 +73,8 @@ check_PROGRAMS += \ geoip_test_CPPFLAGS = \ $(AM_CPPFLAGS) \ - $(MAXMINDDB_CFLAGS) + $(MAXMINDDB_CFLAGS) \ + -DTEST_GEOIP_DATA=\"$(top_srcdir)/bin/tests/system/geoip2/data\" geoip_test_LDADD = \ $(LDADD) \ diff --git a/lib/dns/tests/acl_test.c b/tests/dns/acl_test.c similarity index 73% rename from lib/dns/tests/acl_test.c rename to tests/dns/acl_test.c index 21941a2e9c..210ab45dfa 100644 --- a/lib/dns/tests/acl_test.c +++ b/tests/dns/acl_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -31,36 +29,14 @@ #include -#include "dnstest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#include #define BUFLEN 255 #define BIGBUFLEN (70 * 1024) #define TEST_ORIGIN "test" /* test that dns_acl_isinsecure works */ -static void -dns_acl_isinsecure_test(void **state) { +ISC_RUN_TEST_IMPL(dns_acl_isinsecure) { isc_result_t result; dns_acl_t *any = NULL; dns_acl_t *none = NULL; @@ -74,16 +50,16 @@ dns_acl_isinsecure_test(void **state) { UNUSED(state); - result = dns_acl_any(dt_mctx, &any); + result = dns_acl_any(mctx, &any); assert_int_equal(result, ISC_R_SUCCESS); - result = dns_acl_none(dt_mctx, &none); + result = dns_acl_none(mctx, &none); assert_int_equal(result, ISC_R_SUCCESS); - result = dns_acl_create(dt_mctx, 1, ¬none); + result = dns_acl_create(mctx, 1, ¬none); assert_int_equal(result, ISC_R_SUCCESS); - result = dns_acl_create(dt_mctx, 1, ¬any); + result = dns_acl_create(mctx, 1, ¬any); assert_int_equal(result, ISC_R_SUCCESS); result = dns_acl_merge(notnone, none, false); @@ -93,7 +69,7 @@ dns_acl_isinsecure_test(void **state) { assert_int_equal(result, ISC_R_SUCCESS); #if defined(HAVE_GEOIP2) - result = dns_acl_create(dt_mctx, 1, &geoip); + result = dns_acl_create(mctx, 1, &geoip); assert_int_equal(result, ISC_R_SUCCESS); de = geoip->elements; @@ -108,7 +84,7 @@ dns_acl_isinsecure_test(void **state) { de->node_num = dns_acl_node_count(geoip); geoip->length++; - result = dns_acl_create(dt_mctx, 1, ¬geoip); + result = dns_acl_create(mctx, 1, ¬geoip); assert_int_equal(result, ISC_R_SUCCESS); result = dns_acl_merge(notgeoip, geoip, false); @@ -135,24 +111,8 @@ dns_acl_isinsecure_test(void **state) { #endif /* HAVE_GEOIP2 */ } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(dns_acl_isinsecure_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(dns_acl_isinsecure) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/comparekeys/Kexample-d.+008+53461.key b/tests/dns/comparekeys/Kexample-d.+008+53461.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-d.+008+53461.key rename to tests/dns/comparekeys/Kexample-d.+008+53461.key diff --git a/lib/dns/tests/comparekeys/Kexample-d.+008+53461.private b/tests/dns/comparekeys/Kexample-d.+008+53461.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-d.+008+53461.private rename to tests/dns/comparekeys/Kexample-d.+008+53461.private diff --git a/lib/dns/tests/comparekeys/Kexample-e.+008+53973.key b/tests/dns/comparekeys/Kexample-e.+008+53973.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-e.+008+53973.key rename to tests/dns/comparekeys/Kexample-e.+008+53973.key diff --git a/lib/dns/tests/comparekeys/Kexample-e.+008+53973.private b/tests/dns/comparekeys/Kexample-e.+008+53973.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-e.+008+53973.private rename to tests/dns/comparekeys/Kexample-e.+008+53973.private diff --git a/lib/dns/tests/comparekeys/Kexample-n.+008+37464.key b/tests/dns/comparekeys/Kexample-n.+008+37464.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-n.+008+37464.key rename to tests/dns/comparekeys/Kexample-n.+008+37464.key diff --git a/lib/dns/tests/comparekeys/Kexample-n.+008+37464.private b/tests/dns/comparekeys/Kexample-n.+008+37464.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-n.+008+37464.private rename to tests/dns/comparekeys/Kexample-n.+008+37464.private diff --git a/lib/dns/tests/comparekeys/Kexample-p.+008+53461.key b/tests/dns/comparekeys/Kexample-p.+008+53461.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-p.+008+53461.key rename to tests/dns/comparekeys/Kexample-p.+008+53461.key diff --git a/lib/dns/tests/comparekeys/Kexample-p.+008+53461.private b/tests/dns/comparekeys/Kexample-p.+008+53461.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-p.+008+53461.private rename to tests/dns/comparekeys/Kexample-p.+008+53461.private diff --git a/lib/dns/tests/comparekeys/Kexample-private.+002+65316.key b/tests/dns/comparekeys/Kexample-private.+002+65316.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-private.+002+65316.key rename to tests/dns/comparekeys/Kexample-private.+002+65316.key diff --git a/lib/dns/tests/comparekeys/Kexample-private.+002+65316.private b/tests/dns/comparekeys/Kexample-private.+002+65316.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-private.+002+65316.private rename to tests/dns/comparekeys/Kexample-private.+002+65316.private diff --git a/lib/dns/tests/comparekeys/Kexample-q.+008+53461.key b/tests/dns/comparekeys/Kexample-q.+008+53461.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-q.+008+53461.key rename to tests/dns/comparekeys/Kexample-q.+008+53461.key diff --git a/lib/dns/tests/comparekeys/Kexample-q.+008+53461.private b/tests/dns/comparekeys/Kexample-q.+008+53461.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample-q.+008+53461.private rename to tests/dns/comparekeys/Kexample-q.+008+53461.private diff --git a/lib/dns/tests/comparekeys/Kexample.+002+65316.key b/tests/dns/comparekeys/Kexample.+002+65316.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample.+002+65316.key rename to tests/dns/comparekeys/Kexample.+002+65316.key diff --git a/lib/dns/tests/comparekeys/Kexample.+002+65316.private b/tests/dns/comparekeys/Kexample.+002+65316.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample.+002+65316.private rename to tests/dns/comparekeys/Kexample.+002+65316.private diff --git a/lib/dns/tests/comparekeys/Kexample.+008+53461.key b/tests/dns/comparekeys/Kexample.+008+53461.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample.+008+53461.key rename to tests/dns/comparekeys/Kexample.+008+53461.key diff --git a/lib/dns/tests/comparekeys/Kexample.+008+53461.private b/tests/dns/comparekeys/Kexample.+008+53461.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample.+008+53461.private rename to tests/dns/comparekeys/Kexample.+008+53461.private diff --git a/lib/dns/tests/comparekeys/Kexample.+013+19786.key b/tests/dns/comparekeys/Kexample.+013+19786.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample.+013+19786.key rename to tests/dns/comparekeys/Kexample.+013+19786.key diff --git a/lib/dns/tests/comparekeys/Kexample.+013+19786.private b/tests/dns/comparekeys/Kexample.+013+19786.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample.+013+19786.private rename to tests/dns/comparekeys/Kexample.+013+19786.private diff --git a/lib/dns/tests/comparekeys/Kexample.+015+63663.key b/tests/dns/comparekeys/Kexample.+015+63663.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample.+015+63663.key rename to tests/dns/comparekeys/Kexample.+015+63663.key diff --git a/lib/dns/tests/comparekeys/Kexample.+015+63663.private b/tests/dns/comparekeys/Kexample.+015+63663.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample.+015+63663.private rename to tests/dns/comparekeys/Kexample.+015+63663.private diff --git a/lib/dns/tests/comparekeys/Kexample2.+002+19823.key b/tests/dns/comparekeys/Kexample2.+002+19823.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample2.+002+19823.key rename to tests/dns/comparekeys/Kexample2.+002+19823.key diff --git a/lib/dns/tests/comparekeys/Kexample2.+002+19823.private b/tests/dns/comparekeys/Kexample2.+002+19823.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample2.+002+19823.private rename to tests/dns/comparekeys/Kexample2.+002+19823.private diff --git a/lib/dns/tests/comparekeys/Kexample2.+008+37993.key b/tests/dns/comparekeys/Kexample2.+008+37993.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample2.+008+37993.key rename to tests/dns/comparekeys/Kexample2.+008+37993.key diff --git a/lib/dns/tests/comparekeys/Kexample2.+008+37993.private b/tests/dns/comparekeys/Kexample2.+008+37993.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample2.+008+37993.private rename to tests/dns/comparekeys/Kexample2.+008+37993.private diff --git a/lib/dns/tests/comparekeys/Kexample2.+013+16384.key b/tests/dns/comparekeys/Kexample2.+013+16384.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample2.+013+16384.key rename to tests/dns/comparekeys/Kexample2.+013+16384.key diff --git a/lib/dns/tests/comparekeys/Kexample2.+013+16384.private b/tests/dns/comparekeys/Kexample2.+013+16384.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample2.+013+16384.private rename to tests/dns/comparekeys/Kexample2.+013+16384.private diff --git a/lib/dns/tests/comparekeys/Kexample2.+015+37529.key b/tests/dns/comparekeys/Kexample2.+015+37529.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample2.+015+37529.key rename to tests/dns/comparekeys/Kexample2.+015+37529.key diff --git a/lib/dns/tests/comparekeys/Kexample2.+015+37529.private b/tests/dns/comparekeys/Kexample2.+015+37529.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample2.+015+37529.private rename to tests/dns/comparekeys/Kexample2.+015+37529.private diff --git a/lib/dns/tests/comparekeys/Kexample3.+002+17187.key b/tests/dns/comparekeys/Kexample3.+002+17187.key similarity index 100% rename from lib/dns/tests/comparekeys/Kexample3.+002+17187.key rename to tests/dns/comparekeys/Kexample3.+002+17187.key diff --git a/lib/dns/tests/comparekeys/Kexample3.+002+17187.private b/tests/dns/comparekeys/Kexample3.+002+17187.private similarity index 100% rename from lib/dns/tests/comparekeys/Kexample3.+002+17187.private rename to tests/dns/comparekeys/Kexample3.+002+17187.private diff --git a/lib/dns/tests/db_test.c b/tests/dns/db_test.c similarity index 84% rename from lib/dns/tests/db_test.c rename to tests/dns/db_test.c index 5b7ba64ec7..27fcf7deea 100644 --- a/lib/dns/tests/db_test.c +++ b/tests/dns/db_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -29,28 +27,7 @@ #include #include -#include "dnstest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#include #define BUFLEN 255 #define BIGBUFLEN (64 * 1024) @@ -61,17 +38,13 @@ _teardown(void **state) { */ /* test multiple calls to dns_db_getoriginnode */ -static void -getoriginnode_test(void **state) { +ISC_RUN_TEST_IMPL(getoriginnode) { dns_db_t *db = NULL; dns_dbnode_t *node = NULL; - isc_mem_t *mctx = NULL; isc_result_t result; UNUSED(state); - isc_mem_create(&mctx); - result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); assert_int_equal(result, ISC_R_SUCCESS); @@ -85,21 +58,16 @@ getoriginnode_test(void **state) { dns_db_detachnode(db, &node); dns_db_detach(&db); - isc_mem_detach(&mctx); } /* test getservestalettl and setservestalettl */ -static void -getsetservestalettl_test(void **state) { +ISC_RUN_TEST_IMPL(getsetservestalettl) { dns_db_t *db = NULL; - isc_mem_t *mctx = NULL; isc_result_t result; dns_ttl_t ttl; UNUSED(state); - isc_mem_create(&mctx); - result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache, dns_rdataclass_in, 0, NULL, &db); assert_int_equal(result, ISC_R_SUCCESS); @@ -119,12 +87,10 @@ getsetservestalettl_test(void **state) { assert_int_equal(ttl, 6 * 3600); dns_db_detach(&db); - isc_mem_detach(&mctx); } /* check DNS_DBFIND_STALEOK works */ -static void -dns_dbfind_staleok_test(void **state) { +ISC_RUN_TEST_IMPL(dns_dbfind_staleok) { dns_db_t *db = NULL; dns_dbnode_t *node = NULL; dns_fixedname_t example_fixed; @@ -135,14 +101,11 @@ dns_dbfind_staleok_test(void **state) { dns_rdataset_t rdataset; int count; int pass; - isc_mem_t *mctx = NULL; isc_result_t result; unsigned char data[] = { 0x0a, 0x00, 0x00, 0x01 }; UNUSED(state); - isc_mem_create(&mctx); - result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache, dns_rdataclass_in, 0, NULL, &db); assert_int_equal(result, ISC_R_SUCCESS); @@ -277,18 +240,16 @@ dns_dbfind_staleok_test(void **state) { } dns_db_detach(&db); - isc_mem_detach(&mctx); } /* database class */ -static void -class_test(void **state) { +ISC_RUN_TEST_IMPL(class) { isc_result_t result; dns_db_t *db = NULL; UNUSED(state); - result = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone, + result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); assert_int_equal(result, ISC_R_SUCCESS); @@ -302,15 +263,14 @@ class_test(void **state) { } /* database type */ -static void -dbtype_test(void **state) { +ISC_RUN_TEST_IMPL(dbtype) { isc_result_t result; dns_db_t *db = NULL; UNUSED(state); /* DB has zone semantics */ - result = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone, + result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); assert_int_equal(result, ISC_R_SUCCESS); result = dns_db_load(db, "testdata/db/data.db", dns_masterformat_text, @@ -321,7 +281,7 @@ dbtype_test(void **state) { dns_db_detach(&db); /* DB has cache semantics */ - result = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_cache, + result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache, dns_rdataclass_in, 0, NULL, &db); assert_int_equal(result, ISC_R_SUCCESS); result = dns_db_load(db, "testdata/db/data.db", dns_masterformat_text, @@ -333,8 +293,7 @@ dbtype_test(void **state) { } /* database versions */ -static void -version_test(void **state) { +ISC_RUN_TEST_IMPL(version) { isc_result_t result; dns_fixedname_t fname, ffound; dns_name_t *name, *foundname; @@ -400,29 +359,13 @@ version_test(void **state) { dns_db_detach(&db); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(getoriginnode_test), - cmocka_unit_test(getsetservestalettl_test), - cmocka_unit_test(dns_dbfind_staleok_test), - cmocka_unit_test_setup_teardown(class_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(dbtype_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(version_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(getoriginnode) +ISC_TEST_ENTRY(getsetservestalettl) +ISC_TEST_ENTRY(dns_dbfind_staleok) +ISC_TEST_ENTRY(class) +ISC_TEST_ENTRY(dbtype) +ISC_TEST_ENTRY(version) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/dbdiff_test.c b/tests/dns/dbdiff_test.c similarity index 75% rename from lib/dns/tests/dbdiff_test.c rename to tests/dns/dbdiff_test.c index 05bb761615..12490a8dca 100644 --- a/lib/dns/tests/dbdiff_test.c +++ b/tests/dns/dbdiff_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -31,33 +29,12 @@ #include #include -#include "dnstest.h" +#include #define BUFLEN 255 #define BIGBUFLEN (64 * 1024) #define TEST_ORIGIN "test" -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} - static void test_create(const char *oldfile, dns_db_t **old, const char *newfile, dns_db_t **newdb) { @@ -71,8 +48,7 @@ test_create(const char *oldfile, dns_db_t **old, const char *newfile, } /* dns_db_diffx of identical content */ -static void -diffx_same(void **state) { +ISC_RUN_TEST_IMPL(diffx_same) { dns_db_t *newdb = NULL, *olddb = NULL; isc_result_t result; dns_diff_t diff; @@ -82,7 +58,7 @@ diffx_same(void **state) { test_create("testdata/diff/zone1.data", &olddb, "testdata/diff/zone1.data", &newdb); - dns_diff_init(dt_mctx, &diff); + dns_diff_init(mctx, &diff); result = dns_db_diffx(&diff, newdb, NULL, olddb, NULL, NULL); assert_int_equal(result, ISC_R_SUCCESS); @@ -95,8 +71,7 @@ diffx_same(void **state) { } /* dns_db_diffx of zone with record added */ -static void -diffx_add(void **state) { +ISC_RUN_TEST_IMPL(diffx_add) { dns_db_t *newdb = NULL, *olddb = NULL; dns_difftuple_t *tuple; isc_result_t result; @@ -108,7 +83,7 @@ diffx_add(void **state) { test_create("testdata/diff/zone1.data", &olddb, "testdata/diff/zone2.data", &newdb); - dns_diff_init(dt_mctx, &diff); + dns_diff_init(mctx, &diff); result = dns_db_diffx(&diff, newdb, NULL, olddb, NULL, NULL); assert_int_equal(result, ISC_R_SUCCESS); @@ -128,8 +103,7 @@ diffx_add(void **state) { } /* dns_db_diffx of zone with record removed */ -static void -diffx_remove(void **state) { +ISC_RUN_TEST_IMPL(diffx_remove) { dns_db_t *newdb = NULL, *olddb = NULL; dns_difftuple_t *tuple; isc_result_t result; @@ -141,7 +115,7 @@ diffx_remove(void **state) { test_create("testdata/diff/zone1.data", &olddb, "testdata/diff/zone3.data", &newdb); - dns_diff_init(dt_mctx, &diff); + dns_diff_init(mctx, &diff); result = dns_db_diffx(&diff, newdb, NULL, olddb, NULL, NULL); assert_int_equal(result, ISC_R_SUCCESS); @@ -160,26 +134,10 @@ diffx_remove(void **state) { dns_db_detach(&olddb); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(diffx_same, _setup, _teardown), - cmocka_unit_test_setup_teardown(diffx_add, _setup, _teardown), - cmocka_unit_test_setup_teardown(diffx_remove, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(diffx_same) +ISC_TEST_ENTRY(diffx_add) +ISC_TEST_ENTRY(diffx_remove) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/dbiterator_test.c b/tests/dns/dbiterator_test.c similarity index 78% rename from lib/dns/tests/dbiterator_test.c rename to tests/dns/dbiterator_test.c index 2182672ef0..90e8536fc2 100644 --- a/lib/dns/tests/dbiterator_test.c +++ b/tests/dns/dbiterator_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -30,33 +28,12 @@ #include #include -#include "dnstest.h" +#include #define BUFLEN 255 #define BIGBUFLEN (64 * 1024) #define TEST_ORIGIN "test" -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} - static isc_result_t make_name(const char *src, dns_name_t *name) { isc_buffer_t b; @@ -82,15 +59,13 @@ test_create(const char *filename) { dns_db_detach(&db); } -static void -create(void **state) { +ISC_RUN_TEST_IMPL(create) { UNUSED(state); test_create("testdata/dbiterator/zone1.data"); } -static void -create_nsec3(void **state) { +ISC_RUN_TEST_IMPL(create_nsec3) { UNUSED(state); test_create("testdata/dbiterator/zone2.data"); @@ -133,15 +108,13 @@ test_walk(const char *filename, int nodes) { dns_db_detach(&db); } -static void -walk(void **state) { +ISC_RUN_TEST_IMPL(walk) { UNUSED(state); test_walk("testdata/dbiterator/zone1.data", 12); } -static void -walk_nsec3(void **state) { +ISC_RUN_TEST_IMPL(walk_nsec3) { UNUSED(state); test_walk("testdata/dbiterator/zone2.data", 33); @@ -184,15 +157,13 @@ test_reverse(const char *filename) { dns_db_detach(&db); } -static void -reverse(void **state) { +ISC_RUN_TEST_IMPL(reverse) { UNUSED(state); test_reverse("testdata/dbiterator/zone1.data"); } -static void -reverse_nsec3(void **state) { +ISC_RUN_TEST_IMPL(reverse_nsec3) { UNUSED(state); test_reverse("testdata/dbiterator/zone2.data"); @@ -241,15 +212,13 @@ test_seek_node(const char *filename, int nodes) { dns_db_detach(&db); } -static void -seek_node(void **state) { +ISC_RUN_TEST_IMPL(seek_node) { UNUSED(state); test_seek_node("testdata/dbiterator/zone1.data", 9); } -static void -seek_node_nsec3(void **state) { +ISC_RUN_TEST_IMPL(seek_node_nsec3) { UNUSED(state); test_seek_node("testdata/dbiterator/zone2.data", 30); @@ -285,15 +254,13 @@ test_seek_empty(const char *filename) { dns_db_detach(&db); } -static void -seek_empty(void **state) { +ISC_RUN_TEST_IMPL(seek_empty) { UNUSED(state); test_seek_empty("testdata/dbiterator/zone1.data"); } -static void -seek_empty_nsec3(void **state) { +ISC_RUN_TEST_IMPL(seek_empty_nsec3) { UNUSED(state); test_seek_empty("testdata/dbiterator/zone2.data"); @@ -334,15 +301,13 @@ test_seek_nx(const char *filename) { dns_db_detach(&db); } -static void -seek_nx(void **state) { +ISC_RUN_TEST_IMPL(seek_nx) { UNUSED(state); test_seek_nx("testdata/dbiterator/zone1.data"); } -static void -seek_nx_nsec3(void **state) { +ISC_RUN_TEST_IMPL(seek_nx_nsec3) { UNUSED(state); test_seek_nx("testdata/dbiterator/zone2.data"); @@ -356,39 +321,19 @@ seek_nx_nsec3(void **state) { * dns_dbiterator_origin * dns_dbiterator_setcleanmode */ -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(create, _setup, _teardown), - cmocka_unit_test_setup_teardown(create_nsec3, _setup, - _teardown), - cmocka_unit_test_setup_teardown(walk, _setup, _teardown), - cmocka_unit_test_setup_teardown(walk_nsec3, _setup, _teardown), - cmocka_unit_test_setup_teardown(reverse, _setup, _teardown), - cmocka_unit_test_setup_teardown(reverse_nsec3, _setup, - _teardown), - cmocka_unit_test_setup_teardown(seek_node, _setup, _teardown), - cmocka_unit_test_setup_teardown(seek_node_nsec3, _setup, - _teardown), - cmocka_unit_test_setup_teardown(seek_empty, _setup, _teardown), - cmocka_unit_test_setup_teardown(seek_empty_nsec3, _setup, - _teardown), - cmocka_unit_test_setup_teardown(seek_nx, _setup, _teardown), - cmocka_unit_test_setup_teardown(seek_nx_nsec3, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(create) +ISC_TEST_ENTRY(create_nsec3) +ISC_TEST_ENTRY(walk) +ISC_TEST_ENTRY(walk_nsec3) +ISC_TEST_ENTRY(reverse) +ISC_TEST_ENTRY(reverse_nsec3) +ISC_TEST_ENTRY(seek_node) +ISC_TEST_ENTRY(seek_node_nsec3) +ISC_TEST_ENTRY(seek_empty) +ISC_TEST_ENTRY(seek_empty_nsec3) +ISC_TEST_ENTRY(seek_nx) +ISC_TEST_ENTRY(seek_nx_nsec3) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/dbversion_test.c b/tests/dns/dbversion_test.c similarity index 85% rename from lib/dns/tests/dbversion_test.c rename to tests/dns/dbversion_test.c index 7dabf74aa5..8124563f49 100644 --- a/lib/dns/tests/dbversion_test.c +++ b/tests/dns/dbversion_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -37,7 +35,7 @@ #include #include -#include "dnstest.h" +#include static char tempname[11] = "dtXXXXXXXX"; static dns_db_t *db1 = NULL, *db2 = NULL; @@ -72,23 +70,20 @@ local_callback(const char *file, int line, isc_assertiontype_t type, } static int -_setup(void **state) { +setup_test(void **state) { isc_result_t res; UNUSED(state); isc_assertion_setcallback(local_callback); - res = dns_test_begin(NULL, false); - assert_int_equal(res, ISC_R_SUCCESS); - - res = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone, + res = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db1); assert_int_equal(res, ISC_R_SUCCESS); dns_db_newversion(db1, &v1); assert_non_null(v1); - res = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone, + res = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db2); assert_int_equal(res, ISC_R_SUCCESS); dns_db_newversion(db2, &v2); @@ -98,7 +93,7 @@ _setup(void **state) { } static int -_teardown(void **state) { +teardown_test(void **state) { UNUSED(state); if (strcmp(tempname, "dtXXXXXXXX") != 0) { @@ -123,8 +118,6 @@ _teardown(void **state) { assert_null(db2); } - dns_test_end(); - return (0); } @@ -132,8 +125,7 @@ _teardown(void **state) { * Check dns_db_attachversion() passes with matching db and version, and * asserts with mis-matching db and version. */ -static void -attachversion(void **state) { +ISC_RUN_TEST_IMPL(attachversion) { dns_dbversion_t *v = NULL; UNUSED(state); @@ -150,8 +142,7 @@ attachversion(void **state) { * Check dns_db_closeversion() passes with matching db and version, and * asserts with mis-matching db and version. */ -static void -closeversion(void **state) { +ISC_RUN_TEST_IMPL(closeversion) { UNUSED(state); assert_non_null(v1); @@ -165,8 +156,7 @@ closeversion(void **state) { * Check dns_db_find() passes with matching db and version, and * asserts with mis-matching db and version. */ -static void -find(void **state) { +ISC_RUN_TEST_IMPL(find) { isc_result_t res; dns_rdataset_t rdataset; dns_fixedname_t fixed; @@ -195,8 +185,7 @@ find(void **state) { * Check dns_db_allrdatasets() passes with matching db and version, and * asserts with mis-matching db and version. */ -static void -allrdatasets(void **state) { +ISC_RUN_TEST_IMPL(allrdatasets) { isc_result_t res; dns_dbnode_t *node = NULL; dns_rdatasetiter_t *iterator = NULL; @@ -222,8 +211,7 @@ allrdatasets(void **state) { * Check dns_db_findrdataset() passes with matching db and version, and * asserts with mis-matching db and version. */ -static void -findrdataset(void **state) { +ISC_RUN_TEST_IMPL(findrdataset) { isc_result_t res; dns_rdataset_t rdataset; dns_dbnode_t *node = NULL; @@ -254,8 +242,7 @@ findrdataset(void **state) { * Check dns_db_deleterdataset() passes with matching db and version, and * asserts with mis-matching db and version. */ -static void -deleterdataset(void **state) { +ISC_RUN_TEST_IMPL(deleterdataset) { isc_result_t res; dns_dbnode_t *node = NULL; @@ -277,8 +264,7 @@ deleterdataset(void **state) { * Check dns_db_subtractrdataset() passes with matching db and version, and * asserts with mis-matching db and version. */ -static void -subtract(void **state) { +ISC_RUN_TEST_IMPL(subtract) { isc_result_t res; dns_rdataset_t rdataset; dns_rdatalist_t rdatalist; @@ -319,8 +305,7 @@ subtract(void **state) { * Check dns_db_dump() passes with matching db and version, and * asserts with mis-matching db and version. */ -static void -dump(void **state) { +ISC_RUN_TEST_IMPL(dump) { isc_result_t res; FILE *f = NULL; @@ -340,8 +325,7 @@ dump(void **state) { * Check dns_db_addrdataset() passes with matching db and version, and * asserts with mis-matching db and version. */ -static void -addrdataset(void **state) { +ISC_RUN_TEST_IMPL(addrdataset) { isc_result_t res; dns_rdataset_t rdataset; dns_dbnode_t *node = NULL; @@ -374,8 +358,7 @@ addrdataset(void **state) { * Check dns_db_getnsec3parameters() passes with matching db and version, * and asserts with mis-matching db and version. */ -static void -getnsec3parameters(void **state) { +ISC_RUN_TEST_IMPL(getnsec3parameters) { isc_result_t res; dns_hash_t hash; uint8_t flags; @@ -397,8 +380,7 @@ getnsec3parameters(void **state) { * Check dns_db_resigned() passes with matching db and version, and * asserts with mis-matching db and version. */ -static void -resigned(void **state) { +ISC_RUN_TEST_IMPL(resigned) { isc_result_t res; dns_rdataset_t rdataset, added; dns_dbnode_t *node = NULL; @@ -461,39 +443,18 @@ resigned(void **state) { dns_rdataset_disassociate(&added); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(dump, _setup, _teardown), - cmocka_unit_test_setup_teardown(find, _setup, _teardown), - cmocka_unit_test_setup_teardown(allrdatasets, _setup, - _teardown), - cmocka_unit_test_setup_teardown(findrdataset, _setup, - _teardown), - cmocka_unit_test_setup_teardown(deleterdataset, _setup, - _teardown), - cmocka_unit_test_setup_teardown(subtract, _setup, _teardown), - cmocka_unit_test_setup_teardown(addrdataset, _setup, _teardown), - cmocka_unit_test_setup_teardown(getnsec3parameters, _setup, - _teardown), - cmocka_unit_test_setup_teardown(resigned, _setup, _teardown), - cmocka_unit_test_setup_teardown(attachversion, _setup, - _teardown), - cmocka_unit_test_setup_teardown(closeversion, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(dump, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(find, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(allrdatasets, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(findrdataset, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(deleterdataset, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(subtract, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(addrdataset, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(getnsec3parameters, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(resigned, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(attachversion, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(closeversion, setup_test, teardown_test) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/dh_test.c b/tests/dns/dh_test.c similarity index 70% rename from lib/dns/tests/dh_test.c rename to tests/dns/dh_test.c index c48aced42e..acc7c697fc 100644 --- a/lib/dns/tests/dh_test.c +++ b/tests/dns/dh_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -30,33 +28,36 @@ #include -#include "../dst_internal.h" -#include "dnstest.h" +#include "dst_internal.h" + +#include static int -_setup(void **state) { +setup_test(void **state) { isc_result_t result; UNUSED(state); - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); + result = dst_lib_init(mctx, NULL); + + if (result != ISC_R_SUCCESS) { + return (1); + } return (0); } static int -_teardown(void **state) { +teardown_test(void **state) { UNUSED(state); - dns_test_end(); + dst_lib_destroy(); return (0); } /* OpenSSL DH_compute_key() failure */ -static void -dh_computesecret(void **state) { +ISC_RUN_TEST_IMPL(dh_computesecret) { dst_key_t *key = NULL; isc_buffer_t buf; unsigned char array[1024]; @@ -73,7 +74,7 @@ dh_computesecret(void **state) { assert_int_equal(result, ISC_R_SUCCESS); result = dst_key_fromfile(name, 18602, DST_ALG_DH, - DST_TYPE_PUBLIC | DST_TYPE_KEY, "./", dt_mctx, + DST_TYPE_PUBLIC | DST_TYPE_KEY, "./", mctx, &key); assert_int_equal(result, ISC_R_SUCCESS); @@ -86,24 +87,8 @@ dh_computesecret(void **state) { dst_key_free(&key); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(dh_computesecret, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(dh_computesecret, setup_test, teardown_test) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/dispatch_test.c b/tests/dns/dispatch_test.c similarity index 85% rename from lib/dns/tests/dispatch_test.c rename to tests/dns/dispatch_test.c index 76d498041d..a297330864 100644 --- a/lib/dns/tests/dispatch_test.c +++ b/tests/dns/dispatch_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -37,7 +35,7 @@ #include #include -#include "dnstest.h" +#include uv_sem_t sem; @@ -114,15 +112,9 @@ reset_testdata(void); static int _setup(void **state) { - isc_result_t result; uv_os_sock_t sock = -1; int r; - UNUSED(state); - - result = dns_test_begin(NULL, true); - assert_int_equal(result, ISC_R_SUCCESS); - udp_connect_addr = (isc_sockaddr_t){ .length = 0 }; isc_sockaddr_fromin6(&udp_connect_addr, &in6addr_loopback, 0); @@ -143,8 +135,10 @@ _setup(void **state) { } close(sock); + setup_managers(state); + /* Create a secondary network manager */ - isc_managers_create(dt_mctx, ncpus, 0, &connect_nm, NULL, NULL); + isc_managers_create(mctx, workers, 0, &connect_nm, NULL, NULL); isc_nm_settimeouts(netmgr, T_SERVER_INIT, T_SERVER_IDLE, T_SERVER_KEEPALIVE, T_SERVER_ADVERTISED); @@ -166,14 +160,12 @@ _setup(void **state) { static int _teardown(void **state) { - UNUSED(state); - uv_sem_destroy(&sem); isc_managers_destroy(&connect_nm, NULL, NULL); assert_null(connect_nm); - dns_test_end(); + teardown_managers(state); return (0); } @@ -184,7 +176,7 @@ make_dispatchset(unsigned int ndisps) { isc_sockaddr_t any; dns_dispatch_t *disp = NULL; - result = dns_dispatchmgr_create(dt_mctx, netmgr, &dispatchmgr); + result = dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr); if (result != ISC_R_SUCCESS) { return (result); } @@ -195,7 +187,7 @@ make_dispatchset(unsigned int ndisps) { return (result); } - result = dns_dispatchset_create(dt_mctx, disp, &dset, ndisps); + result = dns_dispatchset_create(mctx, disp, &dset, ndisps); dns_dispatch_detach(&disp); return (result); @@ -212,8 +204,7 @@ reset(void) { } /* create dispatch set */ -static void -dispatchset_create(void **state) { +ISC_RUN_TEST_IMPL(dispatchset_create) { isc_result_t result; UNUSED(state); @@ -228,8 +219,7 @@ dispatchset_create(void **state) { } /* test dispatch set round-robin */ -static void -dispatchset_get(void **state) { +ISC_RUN_TEST_IMPL(dispatchset_get) { isc_result_t result; dns_dispatch_t *d1, *d2, *d3, *d4, *d5; @@ -290,9 +280,6 @@ server_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) { UNUSED(eresult); UNUSED(cbarg); - fprintf(stderr, "%s(..., %s, ...)\n", __func__, - isc_result_totext(eresult)); - return; } @@ -366,9 +353,6 @@ response(isc_result_t eresult, isc_region_t *region, void *arg) { UNUSED(region); UNUSED(arg); - fprintf(stderr, "%s(..., %s, ...)\n", __func__, - isc_result_totext(eresult)); - switch (eresult) { case ISC_R_EOF: case ISC_R_CANCELED: @@ -387,9 +371,6 @@ response_timeout(isc_result_t eresult, isc_region_t *region, void *arg) { UNUSED(region); UNUSED(arg); - fprintf(stderr, "%s(..., %s, ...)\n", __func__, - isc_result_totext(eresult)); - atomic_store_relaxed(&testdata.result, eresult); uv_sem_post(&sem); @@ -402,9 +383,6 @@ connected(isc_result_t eresult, isc_region_t *region, void *cbarg) { UNUSED(eresult); UNUSED(region); - fprintf(stderr, "%s(..., %s, ...)\n", __func__, - isc_result_totext(eresult)); - dns_dispatch_send(dispentry, r, -1); } @@ -414,9 +392,6 @@ client_senddone(isc_result_t eresult, isc_region_t *region, void *cbarg) { UNUSED(region); UNUSED(cbarg); - fprintf(stderr, "%s(..., %s, ...)\n", __func__, - isc_result_totext(eresult)); - return; } @@ -425,16 +400,12 @@ timeout_connected(isc_result_t eresult, isc_region_t *region, void *cbarg) { UNUSED(region); UNUSED(cbarg); - fprintf(stderr, "%s(..., %s, ...)\n", __func__, - isc_result_totext(eresult)); - atomic_store_relaxed(&testdata.result, eresult); uv_sem_post(&sem); } -static void -dispatch_timeout_tcp_connect(void **state) { +ISC_RUN_TEST_IMPL(dispatch_timeout_tcp_connect) { isc_result_t result; isc_region_t region; unsigned char rbuf[12] = { 0 }; @@ -446,7 +417,7 @@ dispatch_timeout_tcp_connect(void **state) { tcp_connect_addr = (isc_sockaddr_t){ .length = 0 }; isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_blackhole, 0); - result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr); + result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createtcp(dispatchmgr, &tcp_connect_addr, @@ -489,8 +460,7 @@ dispatch_timeout_tcp_connect(void **state) { assert_int_equal(result, ISC_R_TIMEDOUT); } -static void -dispatch_timeout_tcp_response(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(dispatch_timeout_tcp_response) { isc_result_t result; isc_region_t region; unsigned char rbuf[12] = { 0 }; @@ -503,7 +473,7 @@ dispatch_timeout_tcp_response(void **state __attribute__((unused))) { tcp_connect_addr = (isc_sockaddr_t){ .length = 0 }; isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0); - result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr); + result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createtcp(dispatchmgr, &tcp_connect_addr, @@ -546,8 +516,7 @@ dispatch_timeout_tcp_response(void **state __attribute__((unused))) { dns_dispatchmgr_detach(&dispatchmgr); } -static void -dispatch_tcp_response(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(dispatch_tcp_response) { isc_result_t result; isc_region_t region; unsigned char rbuf[12] = { 0 }; @@ -560,7 +529,7 @@ dispatch_tcp_response(void **state __attribute__((unused))) { tcp_connect_addr = (isc_sockaddr_t){ .length = 0 }; isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0); - result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr); + result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createtcp(dispatchmgr, &tcp_connect_addr, @@ -606,8 +575,7 @@ dispatch_tcp_response(void **state __attribute__((unused))) { dns_dispatchmgr_detach(&dispatchmgr); } -static void -dispatch_timeout_udp_response(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(dispatch_timeout_udp_response) { isc_result_t result; isc_region_t region; unsigned char rbuf[12] = { 0 }; @@ -620,7 +588,7 @@ dispatch_timeout_udp_response(void **state __attribute__((unused))) { udp_connect_addr = (isc_sockaddr_t){ .length = 0 }; isc_sockaddr_fromin6(&udp_connect_addr, &in6addr_loopback, 0); - result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr); + result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createudp(dispatchmgr, &tcp_connect_addr, @@ -663,8 +631,7 @@ dispatch_timeout_udp_response(void **state __attribute__((unused))) { } /* test dispatch getnext */ -static void -dispatch_getnext(void **state) { +ISC_RUN_TEST_IMPL(dispatch_getnext) { isc_result_t result; isc_region_t region; isc_nmsocket_t *sock = NULL; @@ -674,7 +641,7 @@ dispatch_getnext(void **state) { UNUSED(state); - result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr); + result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createudp(dispatchmgr, &udp_connect_addr, @@ -718,36 +685,16 @@ dispatch_getnext(void **state) { dns_dispatchmgr_detach(&dispatchmgr); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(dispatch_timeout_tcp_connect, - _setup, _teardown), - cmocka_unit_test_setup_teardown(dispatch_timeout_tcp_response, - _setup, _teardown), - cmocka_unit_test_setup_teardown(dispatch_tcp_response, _setup, - _teardown), - cmocka_unit_test_setup_teardown(dispatch_timeout_udp_response, - _setup, _teardown), - cmocka_unit_test_setup_teardown(dispatchset_create, _setup, - _teardown), - cmocka_unit_test_setup_teardown(dispatchset_get, _setup, - _teardown), - cmocka_unit_test_setup_teardown(dispatch_getnext, _setup, - _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +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) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/dns64_test.c b/tests/dns/dns64_test.c similarity index 93% rename from lib/dns/tests/dns64_test.c rename to tests/dns/dns64_test.c index d70baa28c0..6ca96551e6 100644 --- a/lib/dns/tests/dns64_test.c +++ b/tests/dns/dns64_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -34,6 +32,8 @@ #include #include +#include + static void multiple_prefixes(void) { size_t i, count; @@ -121,8 +121,7 @@ multiple_prefixes(void) { assert_true(have_p1 != have_p2); } -static void -dns64_findprefix(void **state) { +ISC_RUN_TEST_IMPL(dns64_findprefix) { unsigned int i, j, o; isc_result_t result; struct { @@ -165,8 +164,6 @@ dns64_findprefix(void **state) { ISC_R_NOTFOUND }, }; - UNUSED(state); - for (i = 0; i < ARRAY_SIZE(tests); i++) { size_t count = 2; dns_rdataset_t rdataset; @@ -231,22 +228,8 @@ dns64_findprefix(void **state) { multiple_prefixes(); } -int -main(void) { - const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown( - dns64_findprefix, NULL, NULL) }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(dns64_findprefix) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif +ISC_TEST_MAIN diff --git a/lib/dns/tests/dnstap_test.c b/tests/dns/dnstap_test.c similarity index 78% rename from lib/dns/tests/dnstap_test.c rename to tests/dns/dnstap_test.c index fea3a023b1..8fdb952a38 100644 --- a/lib/dns/tests/dnstap_test.c +++ b/tests/dns/dnstap_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -24,6 +22,9 @@ #define UNIT_TESTING #include +#include + +#include #include #include @@ -35,63 +36,48 @@ #include #include -#include "dnstest.h" +#include -#ifdef HAVE_DNSTAP +#define TAPFILE TESTS_DIR "/testdata/dnstap/dnstap.file" +#define TAPSOCK TESTS_DIR "/testdata/dnstap/dnstap.sock" -#include - -#include - -#define TAPFILE "testdata/dnstap/dnstap.file" -#define TAPSOCK "testdata/dnstap/dnstap.sock" - -#define TAPSAVED "testdata/dnstap/dnstap.saved" -#define TAPTEXT "testdata/dnstap/dnstap.text" +#define TAPSAVED TESTS_DIR "/testdata/dnstap/dnstap.saved" +#define TAPTEXT TESTS_DIR "/testdata/dnstap/dnstap.text" static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} - -static void -cleanup(void) { +cleanup(void **state __attribute__((__unused__))) { (void)isc_file_remove(TAPFILE); (void)isc_file_remove(TAPSOCK); + + return (0); +} + +static int +setup(void **state) { + /* + * Make sure files are cleaned up before the test runs. + */ + cleanup(state); + + /* + * Make sure text conversions match the time zone in which + * the testdata was originally generated. + */ + setenv("TZ", "PDT8", 1); + return (0); } /* set up dnstap environment */ -static void -create_test(void **state) { +ISC_RUN_TEST_IMPL(dns_dt_create) { isc_result_t result; dns_dtenv_t *dtenv = NULL; struct fstrm_iothr_options *fopt; - UNUSED(state); - - cleanup(); - fopt = fstrm_iothr_options_init(); assert_non_null(fopt); fstrm_iothr_options_set_num_input_queues(fopt, 1); - result = dns_dt_create(dt_mctx, dns_dtmode_file, TAPFILE, &fopt, NULL, + result = dns_dt_create(mctx, dns_dtmode_file, TAPFILE, &fopt, NULL, &dtenv); assert_int_equal(result, ISC_R_SUCCESS); if (dtenv != NULL) { @@ -107,7 +93,7 @@ create_test(void **state) { assert_non_null(fopt); fstrm_iothr_options_set_num_input_queues(fopt, 1); - result = dns_dt_create(dt_mctx, dns_dtmode_unix, TAPSOCK, &fopt, NULL, + result = dns_dt_create(mctx, dns_dtmode_unix, TAPSOCK, &fopt, NULL, &dtenv); assert_int_equal(result, ISC_R_SUCCESS); if (dtenv != NULL) { @@ -124,7 +110,7 @@ create_test(void **state) { assert_non_null(fopt); fstrm_iothr_options_set_num_input_queues(fopt, 1); - result = dns_dt_create(dt_mctx, 33, TAPSOCK, &fopt, NULL, &dtenv); + result = dns_dt_create(mctx, 33, TAPSOCK, &fopt, NULL, &dtenv); assert_int_equal(result, ISC_R_FAILURE); assert_null(dtenv); if (dtenv != NULL) { @@ -133,13 +119,10 @@ create_test(void **state) { if (fopt != NULL) { fstrm_iothr_options_destroy(&fopt); } - - cleanup(); } /* send dnstap messages */ -static void -send_test(void **state) { +ISC_RUN_TEST_IMPL(dns_dt_send) { isc_result_t result; dns_dtenv_t *dtenv = NULL; dns_dthandle_t *handle = NULL; @@ -163,18 +146,14 @@ send_test(void **state) { isc_time_t p, f; struct fstrm_iothr_options *fopt; - UNUSED(state); - - cleanup(); - - result = dns_test_makeview("test", &view); + result = dns_test_makeview("test", false, &view); assert_int_equal(result, ISC_R_SUCCESS); fopt = fstrm_iothr_options_init(); assert_non_null(fopt); fstrm_iothr_options_set_num_input_queues(fopt, 1); - result = dns_dt_create(dt_mctx, dns_dtmode_file, TAPFILE, &fopt, NULL, + result = dns_dt_create(mctx, dns_dtmode_file, TAPFILE, &fopt, NULL, &dtenv); assert_int_equal(result, ISC_R_SUCCESS); @@ -192,7 +171,7 @@ send_test(void **state) { memset(&zr, 0, sizeof(zr)); isc_buffer_init(&zb, zone, sizeof(zone)); - result = dns_compress_init(&cctx, -1, dt_mctx); + result = dns_compress_init(&cctx, -1, mctx); assert_int_equal(result, ISC_R_SUCCESS); dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); result = dns_name_towire(zname, &cctx, &zb); @@ -266,7 +245,7 @@ send_test(void **state) { dns_dt_detach(&dtenv); dns_view_detach(&view); - result = dns_dt_open(TAPFILE, dns_dtmode_file, dt_mctx, &handle); + result = dns_dt_open(TAPFILE, dns_dtmode_file, mctx, &handle); assert_int_equal(result, ISC_R_SUCCESS); while (dns_dt_getframe(handle, &data, &dsize) == ISC_R_SUCCESS) { @@ -278,7 +257,7 @@ send_test(void **state) { r.base = data; r.length = dsize; - result = dns_dt_parse(dt_mctx, &r, &dtdata); + result = dns_dt_parse(mctx, &r, &dtdata); assert_int_equal(result, ISC_R_SUCCESS); if (result != ISC_R_SUCCESS) { n++; @@ -299,12 +278,10 @@ send_test(void **state) { if (handle != NULL) { dns_dt_close(&handle); } - cleanup(); } /* dnstap message to text */ -static void -totext_test(void **state) { +ISC_RUN_TEST_IMPL(dns_dt_totext) { isc_result_t result; dns_dthandle_t *handle = NULL; uint8_t *data; @@ -313,7 +290,7 @@ totext_test(void **state) { UNUSED(state); - result = dns_dt_open(TAPSAVED, dns_dtmode_file, dt_mctx, &handle); + result = dns_dt_open(TAPSAVED, dns_dtmode_file, mctx, &handle); assert_int_equal(result, ISC_R_SUCCESS); result = isc_stdio_open(TAPTEXT, "r", &fp); @@ -341,13 +318,13 @@ totext_test(void **state) { } /* parse dnstap frame */ - result = dns_dt_parse(dt_mctx, &r, &dtdata); + result = dns_dt_parse(mctx, &r, &dtdata); assert_int_equal(result, ISC_R_SUCCESS); if (result != ISC_R_SUCCESS) { continue; } - isc_buffer_allocate(dt_mctx, &b, 2048); + isc_buffer_allocate(mctx, &b, 2048); assert_non_null(b); if (b == NULL) { break; @@ -366,37 +343,14 @@ totext_test(void **state) { if (handle != NULL) { dns_dt_close(&handle); } - cleanup(); -} -#endif /* HAVE_DNSTAP */ - -int -main(void) { -#if HAVE_DNSTAP - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(create_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(send_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(totext_test, _setup, _teardown), - }; - - /* make sure text conversion gets the right local time */ - setenv("TZ", "PST8", 1); - - return (cmocka_run_group_tests(tests, NULL, NULL)); -#else /* if HAVE_DNSTAP */ - print_message("1..0 # Skipped: dnstap not enabled\n"); - return (SKIPPED_TEST_EXIT_CODE); -#endif /* HAVE_DNSTAP */ } -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_START -#include +ISC_TEST_ENTRY_CUSTOM(dns_dt_create, setup, cleanup) +ISC_TEST_ENTRY_CUSTOM(dns_dt_send, setup, cleanup) +ISC_TEST_ENTRY_CUSTOM(dns_dt_totext, setup, cleanup) -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} +ISC_TEST_LIST_END -#endif /* HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/dst_test.c b/tests/dns/dst_test.c similarity index 91% rename from lib/dns/tests/dst_test.c rename to tests/dns/dst_test.c index 805be7e689..28bd2ec72e 100644 --- a/lib/dns/tests/dst_test.c +++ b/tests/dns/dst_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -33,26 +31,24 @@ #include -#include "../dst_internal.h" -#include "dnstest.h" +#include "dst_internal.h" + +#include static int -_setup(void **state) { - isc_result_t result; - +setup_test(void **state) { UNUSED(state); - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); + dst_lib_init(mctx, NULL); return (0); } static int -_teardown(void **state) { +teardown_test(void **state) { UNUSED(state); - dns_test_end(); + dst_lib_destroy(); return (0); } @@ -73,7 +69,7 @@ sig_fromfile(const char *path, isc_buffer_t *buf) { result = isc_file_getsizefd(fileno(fp), &size); assert_int_equal(result, ISC_R_SUCCESS); - data = isc_mem_get(dt_mctx, (size + 1)); + data = isc_mem_get(mctx, (size + 1)); assert_non_null(data); len = (size_t)size; @@ -123,7 +119,7 @@ sig_fromfile(const char *path, isc_buffer_t *buf) { result = ISC_R_SUCCESS; err: - isc_mem_put(dt_mctx, data, size + 1); + isc_mem_put(mctx, data, size + 1); return (result); } @@ -154,7 +150,7 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname, result = isc_file_getsizefd(fileno(fp), &size); assert_int_equal(result, ISC_R_SUCCESS); - data = isc_mem_get(dt_mctx, (size + 1)); + data = isc_mem_get(mctx, (size + 1)); assert_non_null(data); p = data; @@ -175,7 +171,7 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname, isc_buffer_add(&b, strlen(keyname)); result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL); assert_int_equal(result, ISC_R_SUCCESS); - result = dst_key_fromfile(name, id, alg, type, "testdata/dst", dt_mctx, + result = dst_key_fromfile(name, id, alg, type, "testdata/dst", mctx, &key); assert_int_equal(result, ISC_R_SUCCESS); @@ -197,8 +193,8 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname, */ isc_buffer_remainingregion(&sigbuf, &sigreg); - result = dst_context_create(key, dt_mctx, DNS_LOGCATEGORY_GENERAL, - false, 0, &ctx); + result = dst_context_create(key, mctx, DNS_LOGCATEGORY_GENERAL, false, + 0, &ctx); assert_int_equal(result, ISC_R_SUCCESS); result = dst_context_adddata(ctx, &datareg); @@ -215,8 +211,8 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname, isc_result_t result2; dst_context_destroy(&ctx); - result2 = dst_context_create( - key, dt_mctx, DNS_LOGCATEGORY_GENERAL, false, 0, &ctx); + result2 = dst_context_create(key, mctx, DNS_LOGCATEGORY_GENERAL, + false, 0, &ctx); assert_int_equal(result2, ISC_R_SUCCESS); result2 = dst_context_adddata(ctx, &datareg); @@ -241,7 +237,7 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname, fprintf(stderr, "# %s:\n# %s\n", sigpath, hexbuf); } - isc_mem_put(dt_mctx, data, size + 1); + isc_mem_put(mctx, data, size + 1); dst_context_destroy(&ctx); dst_key_free(&key); @@ -251,10 +247,7 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname, return; } -static void -sig_test(void **state) { - UNUSED(state); - +ISC_RUN_TEST_IMPL(sig_test) { struct { const char *datapath; const char *sigpath; @@ -310,7 +303,7 @@ check_cmp(const char *key1_name, dns_keytag_t key1_id, const char *key2_name, result = dns_name_fromtext(name1, &b1, dns_rootname, 0, NULL); assert_int_equal(result, ISC_R_SUCCESS); result = dst_key_fromfile(name1, key1_id, alg, type, "comparekeys", - dt_mctx, &key1); + mctx, &key1); assert_int_equal(result, ISC_R_SUCCESS); /* @@ -322,7 +315,7 @@ check_cmp(const char *key1_name, dns_keytag_t key1_id, const char *key2_name, result = dns_name_fromtext(name2, &b2, dns_rootname, 0, NULL); assert_int_equal(result, ISC_R_SUCCESS); result = dst_key_fromfile(name2, key2_id, alg, type, "comparekeys", - dt_mctx, &key2); + mctx, &key2); assert_int_equal(result, ISC_R_SUCCESS); /* @@ -346,10 +339,7 @@ check_cmp(const char *key1_name, dns_keytag_t key1_id, const char *key2_name, return; } -static void -cmp_test(void **state) { - UNUSED(state); - +ISC_RUN_TEST_IMPL(cmp_test) { struct { const char *key1_name; dns_keytag_t key1_id; @@ -477,24 +467,9 @@ cmp_test(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(sig_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(cmp_test, _setup, _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(sig_test, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(cmp_test, setup_test, teardown_test) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/geoip_test.c b/tests/dns/geoip_test.c similarity index 87% rename from lib/dns/tests/geoip_test.c rename to tests/dns/geoip_test.c index abe64f9e4e..8af48f448c 100644 --- a/lib/dns/tests/geoip_test.c +++ b/tests/dns/geoip_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -34,11 +32,9 @@ #include -#include "../geoip2.c" -#include "dnstest.h" +#include "geoip2.c" -/* Use GeoIP2 databases from the 'geoip2' system test */ -#define TEST_GEOIP_DATA "../../../bin/tests/system/geoip2/data" +#include static dns_geoip_databases_t geoip; @@ -50,14 +46,9 @@ static void close_geoip(void); static int -_setup(void **state) { - isc_result_t result; - +setup_test(void **state) { UNUSED(state); - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - /* Use databases from the geoip system test */ load_geoip(TEST_GEOIP_DATA); @@ -65,13 +56,11 @@ _setup(void **state) { } static int -_teardown(void **state) { +teardown_test(void **state) { UNUSED(state); close_geoip(); - dns_test_end(); - return (0); } @@ -135,8 +124,7 @@ entry_exists(dns_geoip_subtype_t subtype, const char *addr) { * present in all databases, 192.0.2.128 should only be present in the country * database, ::1 should be absent from all databases). */ -static void -baseline(void **state) { +ISC_RUN_TEST_IMPL(baseline) { dns_geoip_subtype_t subtype; UNUSED(state); @@ -214,8 +202,7 @@ do_lookup_string_v6(const char *addr, dns_geoip_subtype_t subtype, } /* GeoIP country matching */ -static void -country(void **state) { +ISC_RUN_TEST_IMPL(country) { bool match; UNUSED(state); @@ -240,8 +227,7 @@ country(void **state) { } /* GeoIP country (ipv6) matching */ -static void -country_v6(void **state) { +ISC_RUN_TEST_IMPL(country_v6) { bool match; UNUSED(state); @@ -260,8 +246,7 @@ country_v6(void **state) { } /* GeoIP city (ipv4) matching */ -static void -city(void **state) { +ISC_RUN_TEST_IMPL(city) { bool match; UNUSED(state); @@ -298,8 +283,7 @@ city(void **state) { } /* GeoIP city (ipv6) matching */ -static void -city_v6(void **state) { +ISC_RUN_TEST_IMPL(city_v6) { bool match; UNUSED(state); @@ -339,8 +323,7 @@ city_v6(void **state) { } /* GeoIP asnum matching */ -static void -asnum(void **state) { +ISC_RUN_TEST_IMPL(asnum) { bool match; UNUSED(state); @@ -354,8 +337,7 @@ asnum(void **state) { } /* GeoIP isp matching */ -static void -isp(void **state) { +ISC_RUN_TEST_IMPL(isp) { bool match; UNUSED(state); @@ -370,8 +352,7 @@ isp(void **state) { } /* GeoIP org matching */ -static void -org(void **state) { +ISC_RUN_TEST_IMPL(org) { bool match; UNUSED(state); @@ -386,8 +367,7 @@ org(void **state) { } /* GeoIP domain matching */ -static void -domain(void **state) { +ISC_RUN_TEST_IMPL(domain) { bool match; UNUSED(state); @@ -400,27 +380,16 @@ domain(void **state) { assert_true(match); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(baseline), cmocka_unit_test(country), - cmocka_unit_test(country_v6), cmocka_unit_test(city), - cmocka_unit_test(city_v6), cmocka_unit_test(asnum), - cmocka_unit_test(isp), cmocka_unit_test(org), - cmocka_unit_test(domain), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(baseline, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(country, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(country_v6, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(city, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(city_v6, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(asnum, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(isp, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(org, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(domain, setup_test, teardown_test) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/keytable_test.c b/tests/dns/keytable_test.c similarity index 93% rename from lib/dns/tests/keytable_test.c rename to tests/dns/keytable_test.c index e08f94effd..bc7b60d12e 100644 --- a/lib/dns/tests/keytable_test.c +++ b/tests/dns/keytable_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -42,28 +40,7 @@ #include -#include "dnstest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, true); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#include dns_keytable_t *keytable = NULL; dns_ntatable_t *ntatable = NULL; @@ -123,7 +100,7 @@ create_keystruct(uint16_t flags, uint8_t proto, uint8_t alg, const char *keystr, keystruct->common.rdclass = rdclass; keystruct->common.rdtype = dns_rdatatype_dnskey; - keystruct->mctx = dt_mctx; + keystruct->mctx = mctx; ISC_LINK_INIT(&keystruct->common, link); keystruct->flags = flags; keystruct->protocol = proto; @@ -134,7 +111,7 @@ create_keystruct(uint16_t flags, uint8_t proto, uint8_t alg, const char *keystr, ISC_R_SUCCESS); isc_buffer_usedregion(&keydatabuf, &r); keystruct->datalen = r.length; - keystruct->data = isc_mem_allocate(dt_mctx, r.length); + keystruct->data = isc_mem_allocate(mctx, r.length); memmove(keystruct->data, r.base, r.length); } @@ -182,11 +159,10 @@ create_tables(void) { dns_name_t *keyname = dns_fixedname_name(&fn); isc_stdtime_t now; - result = dns_test_makeview("view", &view); + result = dns_test_makeview("view", false, &view); assert_int_equal(result, ISC_R_SUCCESS); - assert_int_equal(dns_keytable_create(dt_mctx, &keytable), - ISC_R_SUCCESS); + assert_int_equal(dns_keytable_create(mctx, &keytable), ISC_R_SUCCESS); assert_int_equal( dns_ntatable_create(view, taskmgr, timermgr, &ntatable), ISC_R_SUCCESS); @@ -229,8 +205,7 @@ destroy_tables(void) { } /* add keys to the keytable */ -static void -add_test(void **state) { +ISC_RUN_TEST_IMPL(dns_keytable_add) { dns_keynode_t *keynode = NULL; dns_keynode_t *null_keynode = NULL; unsigned char digest[ISC_MAX_MD_SIZE]; @@ -380,10 +355,7 @@ add_test(void **state) { } /* delete keys from the keytable */ -static void -delete_test(void **state) { - UNUSED(state); - +ISC_RUN_TEST_IMPL(dns_keytable_delete) { create_tables(); /* dns_keytable_delete requires exact match */ @@ -409,8 +381,7 @@ delete_test(void **state) { } /* delete key nodes from the keytable */ -static void -deletekey_test(void **state) { +ISC_RUN_TEST_IMPL(dns_keytable_deletekey) { dns_rdata_dnskey_t dnskey; dns_fixedname_t fn; dns_name_t *keyname = dns_fixedname_name(&fn); @@ -475,8 +446,7 @@ deletekey_test(void **state) { } /* check find-variant operations */ -static void -find_test(void **state) { +ISC_RUN_TEST_IMPL(dns_keytable_find) { dns_keynode_t *keynode = NULL; dns_fixedname_t fname; dns_name_t *name; @@ -530,8 +500,7 @@ find_test(void **state) { } /* check issecuredomain() */ -static void -issecuredomain_test(void **state) { +ISC_RUN_TEST_IMPL(dns_keytable_issecuredomain) { bool issecure; const char **n; const char *names[] = { "example.com", "sub.example.com", @@ -568,8 +537,7 @@ issecuredomain_test(void **state) { } /* check dns_keytable_dump() */ -static void -dump_test(void **state) { +ISC_RUN_TEST_IMPL(dns_keytable_dump) { FILE *f = fopen("/dev/null", "w"); UNUSED(state); @@ -587,8 +555,7 @@ dump_test(void **state) { } /* check negative trust anchors */ -static void -nta_test(void **state) { +ISC_RUN_TEST_IMPL(dns_keytable_nta) { isc_result_t result; bool issecure, covered; dns_fixedname_t fn; @@ -600,13 +567,13 @@ nta_test(void **state) { UNUSED(state); - result = dns_test_makeview("view", &myview); + result = dns_test_makeview("view", false, &myview); assert_int_equal(result, ISC_R_SUCCESS); result = isc_task_create(taskmgr, 0, &myview->task, 0); assert_int_equal(result, ISC_R_SUCCESS); - result = dns_view_initsecroots(myview, dt_mctx); + result = dns_view_initsecroots(myview, mctx); assert_int_equal(result, ISC_R_SUCCESS); result = dns_view_getsecroots(myview, &keytable); assert_int_equal(result, ISC_R_SUCCESS); @@ -692,29 +659,17 @@ nta_test(void **state) { dns_view_detach(&myview); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(add_test), - cmocka_unit_test(delete_test), - cmocka_unit_test(deletekey_test), - cmocka_unit_test(find_test), - cmocka_unit_test(issecuredomain_test), - cmocka_unit_test(dump_test), - cmocka_unit_test(nta_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} +ISC_TEST_ENTRY_CUSTOM(dns_keytable_add, setup_managers, teardown_managers) +ISC_TEST_ENTRY_CUSTOM(dns_keytable_delete, setup_managers, teardown_managers) +ISC_TEST_ENTRY_CUSTOM(dns_keytable_deletekey, setup_managers, teardown_managers) +ISC_TEST_ENTRY_CUSTOM(dns_keytable_find, setup_managers, teardown_managers) +ISC_TEST_ENTRY_CUSTOM(dns_keytable_issecuredomain, setup_managers, + teardown_managers) +ISC_TEST_ENTRY_CUSTOM(dns_keytable_dump, setup_managers, teardown_managers) +ISC_TEST_ENTRY_CUSTOM(dns_keytable_nta, setup_managers, teardown_managers) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/master_test.c b/tests/dns/master_test.c similarity index 80% rename from lib/dns/tests/master_test.c rename to tests/dns/master_test.c index 2e5cfae3ab..1642b0d12e 100644 --- a/lib/dns/tests/master_test.c +++ b/tests/dns/master_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -40,28 +38,7 @@ #include #include -#include "dnstest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#include static void nullmsg(dns_rdatacallbacks_t *cb, const char *fmt, ...) { @@ -174,7 +151,7 @@ test_master(const char *workdir, const char *testfile, result = dns_master_loadfile(testfile, &dns_origin, &dns_origin, dns_rdataclass_in, true, 0, &callbacks, - NULL, NULL, dt_mctx, format, 0); + NULL, NULL, mctx, format, 0); return (result); } @@ -182,15 +159,14 @@ test_master(const char *workdir, const char *testfile, static void include_callback(const char *filename, void *arg) { char **argp = (char **)arg; - *argp = isc_mem_strdup(dt_mctx, filename); + *argp = isc_mem_strdup(mctx, filename); } /* * Successful load test: * dns_master_loadfile() loads a valid master file and returns success */ -static void -load_test(void **state) { +ISC_RUN_TEST_IMPL(load) { isc_result_t result; UNUSED(state); @@ -204,8 +180,7 @@ load_test(void **state) { * Unexpected end of file test: * dns_master_loadfile() returns DNS_R_UNEXPECTED when file ends too soon */ -static void -unexpected_test(void **state) { +ISC_RUN_TEST_IMPL(unexpected) { isc_result_t result; UNUSED(state); @@ -220,8 +195,7 @@ unexpected_test(void **state) { * dns_master_loadfile() accepts broken zones with no TTL for first record * if it is an SOA */ -static void -noowner_test(void **state) { +ISC_RUN_TEST_IMPL(noowner) { isc_result_t result; UNUSED(state); @@ -236,8 +210,7 @@ noowner_test(void **state) { * dns_master_loadfile() returns DNS_R_NOOWNER when no owner name is * specified */ -static void -nottl_test(void **state) { +ISC_RUN_TEST_IMPL(nottl) { isc_result_t result; UNUSED(state); @@ -252,8 +225,7 @@ nottl_test(void **state) { * dns_master_loadfile() returns DNS_R_BADCLASS when record class doesn't * match zone class */ -static void -badclass_test(void **state) { +ISC_RUN_TEST_IMPL(badclass) { isc_result_t result; UNUSED(state); @@ -267,8 +239,7 @@ badclass_test(void **state) { * Too big rdata test: * dns_master_loadfile() returns ISC_R_NOSPACE when record is too big */ -static void -toobig_test(void **state) { +ISC_RUN_TEST_IMPL(toobig) { isc_result_t result; UNUSED(state); @@ -282,8 +253,7 @@ toobig_test(void **state) { * Maximum rdata test: * dns_master_loadfile() returns ISC_R_SUCCESS when record is maximum size */ -static void -maxrdata_test(void **state) { +ISC_RUN_TEST_IMPL(maxrdata) { isc_result_t result; UNUSED(state); @@ -297,8 +267,7 @@ maxrdata_test(void **state) { * DNSKEY test: * dns_master_loadfile() understands DNSKEY with key material */ -static void -dnskey_test(void **state) { +ISC_RUN_TEST_IMPL(dnskey) { isc_result_t result; UNUSED(state); @@ -315,8 +284,7 @@ dnskey_test(void **state) { * RFC 4034 removed the ability to signal NOKEY, so empty key material should * be rejected. */ -static void -dnsnokey_test(void **state) { +ISC_RUN_TEST_IMPL(dnsnokey) { isc_result_t result; UNUSED(state); @@ -330,8 +298,7 @@ dnsnokey_test(void **state) { * Include test: * dns_master_loadfile() understands $INCLUDE */ -static void -include_test(void **state) { +ISC_RUN_TEST_IMPL(include) { isc_result_t result; UNUSED(state); @@ -345,8 +312,7 @@ include_test(void **state) { * Include file list test: * dns_master_loadfile4() returns names of included file */ -static void -master_includelist_test(void **state) { +ISC_RUN_TEST_IMPL(master_includelist) { isc_result_t result; char *filename = NULL; @@ -361,12 +327,12 @@ master_includelist_test(void **state) { result = dns_master_loadfile( "testdata/master/master8.data", &dns_origin, &dns_origin, dns_rdataclass_in, 0, true, &callbacks, include_callback, - &filename, dt_mctx, dns_masterformat_text, 0); + &filename, mctx, dns_masterformat_text, 0); assert_int_equal(result, DNS_R_SEENINCLUDE); assert_non_null(filename); if (filename != NULL) { assert_string_equal(filename, "testdata/master/master6.data"); - isc_mem_free(dt_mctx, filename); + isc_mem_free(mctx, filename); } } @@ -374,8 +340,7 @@ master_includelist_test(void **state) { * Include failure test: * dns_master_loadfile() understands $INCLUDE failures */ -static void -includefail_test(void **state) { +ISC_RUN_TEST_IMPL(includefail) { isc_result_t result; UNUSED(state); @@ -389,8 +354,7 @@ includefail_test(void **state) { * Non-empty blank lines test: * dns_master_loadfile() handles non-empty blank lines */ -static void -blanklines_test(void **state) { +ISC_RUN_TEST_IMPL(blanklines) { isc_result_t result; UNUSED(state); @@ -405,8 +369,7 @@ blanklines_test(void **state) { * dns_master_loadfile() allows leading zeroes in SOA */ -static void -leadingzero_test(void **state) { +ISC_RUN_TEST_IMPL(leadingzero) { isc_result_t result; UNUSED(state); @@ -417,8 +380,7 @@ leadingzero_test(void **state) { } /* masterfile totext tests */ -static void -totext_test(void **state) { +ISC_RUN_TEST_IMPL(totext) { isc_result_t result; dns_rdataset_t rdataset; dns_rdatalist_t rdatalist; @@ -455,8 +417,7 @@ totext_test(void **state) { * Raw load test: * dns_master_loadfile() loads a valid raw file and returns success */ -static void -loadraw_test(void **state) { +ISC_RUN_TEST_IMPL(loadraw) { isc_result_t result; UNUSED(state); @@ -488,8 +449,7 @@ loadraw_test(void **state) { * Raw dump test: * dns_master_dump*() functions dump valid raw files */ -static void -dumpraw_test(void **state) { +ISC_RUN_TEST_IMPL(dumpraw) { isc_result_t result; dns_db_t *db = NULL; dns_dbversion_t *version = NULL; @@ -512,7 +472,7 @@ dumpraw_test(void **state) { &target); assert_int_equal(result, ISC_R_SUCCESS); - result = dns_db_create(dt_mctx, "rbt", &dnsorigin, dns_dbtype_zone, + result = dns_db_create(mctx, "rbt", &dnsorigin, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); assert_int_equal(result, ISC_R_SUCCESS); @@ -528,9 +488,8 @@ dumpraw_test(void **state) { dns_db_currentversion(db, &version); - result = dns_master_dump(dt_mctx, db, version, - &dns_master_style_default, "test.dump", - dns_masterformat_raw, NULL); + result = dns_master_dump(mctx, db, version, &dns_master_style_default, + "test.dump", dns_masterformat_raw, NULL); assert_int_equal(result, ISC_R_SUCCESS); result = test_master(NULL, "test.dump", dns_masterformat_raw, nullmsg, @@ -544,9 +503,8 @@ dumpraw_test(void **state) { header.flags |= DNS_MASTERRAW_SOURCESERIALSET; unlink("test.dump"); - result = dns_master_dump(dt_mctx, db, version, - &dns_master_style_default, "test.dump", - dns_masterformat_raw, &header); + result = dns_master_dump(mctx, db, version, &dns_master_style_default, + "test.dump", dns_masterformat_raw, &header); assert_int_equal(result, ISC_R_SUCCESS); result = test_master(NULL, "test.dump", dns_masterformat_raw, nullmsg, @@ -587,8 +545,7 @@ warn_expect(struct dns_rdatacallbacks *mycallbacks, const char *fmt, ...) { * Origin change test: * dns_master_loadfile() rejects zones with inherited name following $ORIGIN */ -static void -neworigin_test(void **state) { +ISC_RUN_TEST_IMPL(neworigin) { isc_result_t result; UNUSED(state); @@ -600,53 +557,25 @@ neworigin_test(void **state) { assert_true(warn_expect_result); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(load_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(unexpected_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(noowner_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(nottl_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(badclass_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(dnskey_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(dnsnokey_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(include_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(master_includelist_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(includefail_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(blanklines_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(leadingzero_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(totext_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(loadraw_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(dumpraw_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(toobig_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(maxrdata_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(neworigin_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(load) +ISC_TEST_ENTRY(unexpected) +ISC_TEST_ENTRY(noowner) +ISC_TEST_ENTRY(nottl) +ISC_TEST_ENTRY(badclass) +ISC_TEST_ENTRY(dnskey) +ISC_TEST_ENTRY(dnsnokey) +ISC_TEST_ENTRY(include) +ISC_TEST_ENTRY(master_includelist) +ISC_TEST_ENTRY(includefail) +ISC_TEST_ENTRY(blanklines) +ISC_TEST_ENTRY(leadingzero) +ISC_TEST_ENTRY(totext) +ISC_TEST_ENTRY(loadraw) +ISC_TEST_ENTRY(dumpraw) +ISC_TEST_ENTRY(toobig) +ISC_TEST_ENTRY(maxrdata) +ISC_TEST_ENTRY(neworigin) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/mkraw.pl b/tests/dns/mkraw.pl similarity index 100% rename from lib/dns/tests/mkraw.pl rename to tests/dns/mkraw.pl diff --git a/lib/dns/tests/name_test.c b/tests/dns/name_test.c similarity index 88% rename from lib/dns/tests/name_test.c rename to tests/dns/name_test.c index e48c64e28a..511ee3c8b3 100644 --- a/lib/dns/tests/name_test.c +++ b/tests/dns/name_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -38,35 +36,13 @@ #include #include -#include "dnstest.h" +#include /* Set to true (or use -v option) for verbose output */ static bool verbose = false; -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} - /* dns_name_fullcompare test */ -static void -fullcompare_test(void **state) { +ISC_RUN_TEST_IMPL(fullcompare) { dns_fixedname_t fixed1; dns_fixedname_t fixed2; dns_name_t *name1; @@ -182,8 +158,7 @@ compress_test(dns_name_t *name1, dns_name_t *name2, dns_name_t *name3, } /* name compression test */ -static void -compression_test(void **state) { +ISC_RUN_TEST_IMPL(compression) { unsigned int allowed; dns_compress_t cctx; dns_decompress_t dctx; @@ -216,7 +191,7 @@ compression_test(void **state) { /* Test 1: NONE */ allowed = DNS_COMPRESS_NONE; - assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, allowed); @@ -229,7 +204,7 @@ compression_test(void **state) { /* Test2: GLOBAL14 */ allowed = DNS_COMPRESS_GLOBAL14; - assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, allowed); @@ -242,7 +217,7 @@ compression_test(void **state) { /* Test3: ALL */ allowed = DNS_COMPRESS_ALL; - assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, allowed); @@ -255,7 +230,7 @@ compression_test(void **state) { /* Test4: NONE disabled */ allowed = DNS_COMPRESS_NONE; - assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); dns_compress_disable(&cctx); dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); @@ -269,7 +244,7 @@ compression_test(void **state) { /* Test5: GLOBAL14 disabled */ allowed = DNS_COMPRESS_GLOBAL14; - assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); dns_compress_disable(&cctx); dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); @@ -283,7 +258,7 @@ compression_test(void **state) { /* Test6: ALL disabled */ allowed = DNS_COMPRESS_ALL; - assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); dns_compress_disable(&cctx); dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); @@ -297,8 +272,7 @@ compression_test(void **state) { } /* is trust-anchor-telemetry test */ -static void -istat_test(void **state) { +ISC_RUN_TEST_IMPL(istat) { dns_fixedname_t fixed; dns_name_t *name; isc_result_t result; @@ -341,8 +315,7 @@ istat_test(void **state) { } /* dns_nane_init */ -static void -init_test(void **state) { +ISC_RUN_TEST_IMPL(init) { dns_name_t name; unsigned char offsets[1]; @@ -359,8 +332,7 @@ init_test(void **state) { } /* dns_nane_invalidate */ -static void -invalidate_test(void **state) { +ISC_RUN_TEST_IMPL(invalidate) { dns_name_t name; unsigned char offsets[1]; @@ -378,8 +350,7 @@ invalidate_test(void **state) { } /* dns_nane_setbuffer/hasbuffer */ -static void -buffer_test(void **state) { +ISC_RUN_TEST_IMPL(buffer) { dns_name_t name; unsigned char buf[BUFSIZ]; isc_buffer_t b; @@ -394,8 +365,7 @@ buffer_test(void **state) { } /* dns_nane_isabsolute */ -static void -isabsolute_test(void **state) { +ISC_RUN_TEST_IMPL(isabsolute) { struct { const char *namestr; bool expect; @@ -429,8 +399,7 @@ isabsolute_test(void **state) { } /* dns_nane_hash */ -static void -hash_test(void **state) { +ISC_RUN_TEST_IMPL(hash) { struct { const char *name1; const char *name2; @@ -493,8 +462,7 @@ hash_test(void **state) { } /* dns_nane_issubdomain */ -static void -issubdomain_test(void **state) { +ISC_RUN_TEST_IMPL(issubdomain) { struct { const char *name1; const char *name2; @@ -537,8 +505,7 @@ issubdomain_test(void **state) { } /* dns_nane_countlabels */ -static void -countlabels_test(void **state) { +ISC_RUN_TEST_IMPL(countlabels) { struct { const char *namestr; unsigned int expect; @@ -573,8 +540,7 @@ countlabels_test(void **state) { } /* dns_nane_getlabel */ -static void -getlabel_test(void **state) { +ISC_RUN_TEST_IMPL(getlabel) { struct { const char *name1; unsigned int pos1; @@ -617,8 +583,7 @@ getlabel_test(void **state) { } /* dns_nane_getlabelsequence */ -static void -getlabelsequence_test(void **state) { +ISC_RUN_TEST_IMPL(getlabelsequence) { struct { const char *name1; unsigned int pos1; @@ -673,8 +638,7 @@ getlabelsequence_test(void **state) { /* Benchmark dns_name_fromwire() implementation */ -static void * -fromwire_thread(void *arg) { +ISC_RUN_TEST_IMPL(fromwire_thread(void *arg) { unsigned int maxval = 32000000; uint8_t data[] = { 3, 'w', 'w', 'w', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 7, 'i', @@ -709,8 +673,7 @@ fromwire_thread(void *arg) { return (NULL); } -static void -benchmark_test(void **state) { +ISC_RUN_TEST_IMPL(benchmark) { isc_result_t result; unsigned int i; isc_time_t ts1, ts2; @@ -747,50 +710,22 @@ benchmark_test(void **state) { #endif /* DNS_BENCHMARK_TESTS */ -int -main(int argc, char **argv) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(fullcompare_test), - cmocka_unit_test_setup_teardown(compression_test, _setup, - _teardown), - cmocka_unit_test(istat_test), - cmocka_unit_test(init_test), - cmocka_unit_test(invalidate_test), - cmocka_unit_test(buffer_test), - cmocka_unit_test(isabsolute_test), - cmocka_unit_test(hash_test), - cmocka_unit_test(issubdomain_test), - cmocka_unit_test(countlabels_test), - cmocka_unit_test(getlabel_test), - cmocka_unit_test(getlabelsequence_test), +ISC_TEST_LIST_START +ISC_TEST_ENTRY(fullcompare) +ISC_TEST_ENTRY(compression) +ISC_TEST_ENTRY(istat) +ISC_TEST_ENTRY(init) +ISC_TEST_ENTRY(invalidate) +ISC_TEST_ENTRY(buffer) +ISC_TEST_ENTRY(isabsolute) +ISC_TEST_ENTRY(hash) +ISC_TEST_ENTRY(issubdomain) +ISC_TEST_ENTRY(countlabels) +ISC_TEST_ENTRY(getlabel) +ISC_TEST_ENTRY(getlabelsequence) #ifdef DNS_BENCHMARK_TESTS - cmocka_unit_test_setup_teardown(benchmark_test, _setup, - _teardown), +ISC_TEST_ENTRY(benchmark) #endif /* DNS_BENCHMARK_TESTS */ - }; - int c; +ISC_TEST_LIST_END - while ((c = isc_commandline_parse(argc, argv, "v")) != -1) { - switch (c) { - case 'v': - verbose = true; - break; - default: - break; - } - } - - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/nsec3_test.c b/tests/dns/nsec3_test.c similarity index 82% rename from lib/dns/tests/nsec3_test.c rename to tests/dns/nsec3_test.c index 69f4be5885..7d6e424705 100644 --- a/lib/dns/tests/nsec3_test.c +++ b/tests/dns/nsec3_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -30,28 +28,7 @@ #include #include -#include "dnstest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#include static void iteration_test(const char *file, unsigned int expected) { @@ -134,8 +111,7 @@ nsec3param_salttotext_test(const nsec3param_salttotext_test_params_t *params) { * check that appropriate max iterations is returned for different * key size mixes */ -static void -max_iterations(void **state) { +ISC_RUN_TEST_IMPL(max_iterations) { UNUSED(state); iteration_test("testdata/nsec3/1024.db", 150); @@ -146,8 +122,7 @@ max_iterations(void **state) { } /* check dns_nsec3param_salttotext() */ -static void -nsec3param_salttotext(void **state) { +ISC_RUN_TEST_IMPL(nsec3param_salttotext) { size_t i; const nsec3param_salttotext_test_params_t tests[] = { @@ -171,26 +146,9 @@ nsec3param_salttotext(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(max_iterations, _setup, - _teardown), - cmocka_unit_test_setup_teardown(nsec3param_salttotext, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(max_iterations) +ISC_TEST_ENTRY(nsec3param_salttotext) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/nsec3param_test.c b/tests/dns/nsec3param_test.c similarity index 90% rename from lib/dns/tests/nsec3param_test.c rename to tests/dns/nsec3param_test.c index 65a4b8f4ba..3bd50e59a4 100644 --- a/lib/dns/tests/nsec3param_test.c +++ b/tests/dns/nsec3param_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -32,8 +30,9 @@ #include #include -#include "../zone_p.h" -#include "dnstest.h" +#include "zone_p.h" + +#include #define HASH 1 #define FLAGS 0 @@ -41,27 +40,6 @@ #define SALTLEN 4 #define SALT "FEDCBA98" -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} - /*% * Structures containing parameters for nsec3param_salttotext_test(). */ @@ -184,8 +162,7 @@ nsec3param_change_test(const nsec3param_change_test_params_t *test) { dns_zone_detach(&zone); } -static void -nsec3param_change(void **state) { +ISC_RUN_TEST_IMPL(nsec3param_change) { size_t i; /* @@ -281,24 +258,8 @@ nsec3param_change(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(nsec3param_change, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(nsec3param_change) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/peer_test.c b/tests/dns/peer_test.c similarity index 81% rename from lib/dns/tests/peer_test.c rename to tests/dns/peer_test.c index 69ca8bb068..32ef932d93 100644 --- a/lib/dns/tests/peer_test.c +++ b/tests/dns/peer_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -28,46 +26,22 @@ #include -#include "dnstest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#include /* Test DSCP set/get functions */ -static void -dscp(void **state) { +ISC_RUN_TEST_IMPL(dscp) { isc_result_t result; isc_netaddr_t netaddr; struct in_addr ina; dns_peer_t *peer = NULL; isc_dscp_t dscp; - UNUSED(state); - /* * Create peer structure for the loopback address. */ ina.s_addr = INADDR_LOOPBACK; isc_netaddr_fromin(&netaddr, &ina); - result = dns_peer_new(dt_mctx, &netaddr, &peer); + result = dns_peer_new(mctx, &netaddr, &peer); assert_int_equal(result, ISC_R_SUCCESS); /* @@ -153,23 +127,10 @@ dscp(void **state) { dns_peer_detach(&peer); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(dscp, _setup, _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(dscp) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/private_test.c b/tests/dns/private_test.c similarity index 86% rename from lib/dns/tests/private_test.c rename to tests/dns/private_test.c index 1938e143ab..adaf441cf4 100644 --- a/lib/dns/tests/private_test.c +++ b/tests/dns/private_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -35,27 +33,30 @@ #include -#include "dnstest.h" +#include static dns_rdatatype_t privatetype = 65534; static int -_setup(void **state) { +setup_test(void **state) { isc_result_t result; UNUSED(state); - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); + result = dst_lib_init(mctx, NULL); + + if (result != ISC_R_SUCCESS) { + return (1); + } return (0); } static int -_teardown(void **state) { +teardown_test(void **state) { UNUSED(state); - dns_test_end(); + dst_lib_destroy(); return (0); } @@ -147,8 +148,7 @@ make_nsec3(nsec3_testcase_t *testcase, dns_rdata_t *private, } /* convert private signing records to text */ -static void -private_signing_totext_test(void **state) { +ISC_RUN_TEST_IMPL(private_signing_totext) { dns_rdata_t private; int i; @@ -180,8 +180,7 @@ private_signing_totext_test(void **state) { } /* convert private chain records to text */ -static void -private_nsec3_totext_test(void **state) { +ISC_RUN_TEST_IMPL(private_nsec3_totext) { dns_rdata_t private; int i; @@ -215,26 +214,9 @@ private_nsec3_totext_test(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(private_signing_totext_test, - _setup, _teardown), - cmocka_unit_test_setup_teardown(private_nsec3_totext_test, - _setup, _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(private_signing_totext, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(private_nsec3_totext, setup_test, teardown_test) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/rbt_test.c b/tests/dns/rbt_test.c similarity index 89% rename from lib/dns/tests/rbt_test.c rename to tests/dns/rbt_test.c index dea2ae94f5..c66c365e59 100644 --- a/lib/dns/tests/rbt_test.c +++ b/tests/dns/rbt_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include #include @@ -29,7 +27,6 @@ #define UNIT_TESTING #include -#include #include #include #include @@ -54,7 +51,7 @@ #include -#include "dnstest.h" +#include typedef struct { dns_rbt_t *rbt; @@ -127,31 +124,11 @@ static const char *const ordered_names[] = { static const size_t ordered_names_count = (sizeof(ordered_names) / sizeof(*ordered_names)); -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} static void delete_data(void *data, void *arg) { UNUSED(arg); - isc_mem_put(dt_mctx, data, sizeof(size_t)); + isc_mem_put(mctx, data, sizeof(size_t)); } static test_context_t * @@ -160,16 +137,15 @@ test_context_setup(void) { isc_result_t result; size_t i; - ctx = isc_mem_get(dt_mctx, sizeof(*ctx)); + ctx = isc_mem_get(mctx, sizeof(*ctx)); assert_non_null(ctx); ctx->rbt = NULL; - result = dns_rbt_create(dt_mctx, delete_data, NULL, &ctx->rbt); + result = dns_rbt_create(mctx, delete_data, NULL, &ctx->rbt); assert_int_equal(result, ISC_R_SUCCESS); ctx->rbt_distances = NULL; - result = dns_rbt_create(dt_mctx, delete_data, NULL, - &ctx->rbt_distances); + result = dns_rbt_create(mctx, delete_data, NULL, &ctx->rbt_distances); assert_int_equal(result, ISC_R_SUCCESS); for (i = 0; i < domain_names_count; i++) { @@ -181,13 +157,13 @@ test_context_setup(void) { name = dns_fixedname_name(&fname); - n = isc_mem_get(dt_mctx, sizeof(size_t)); + n = isc_mem_get(mctx, sizeof(size_t)); assert_non_null(n); *n = i + 1; result = dns_rbt_addname(ctx->rbt, name, n); assert_int_equal(result, ISC_R_SUCCESS); - n = isc_mem_get(dt_mctx, sizeof(size_t)); + n = isc_mem_get(mctx, sizeof(size_t)); assert_non_null(n); *n = node_distances[i]; result = dns_rbt_addname(ctx->rbt_distances, name, n); @@ -202,7 +178,7 @@ test_context_teardown(test_context_t *ctx) { dns_rbt_destroy(&ctx->rbt); dns_rbt_destroy(&ctx->rbt_distances); - isc_mem_put(dt_mctx, ctx, sizeof(*ctx)); + isc_mem_put(mctx, ctx, sizeof(*ctx)); } /* @@ -233,13 +209,10 @@ check_test_data(dns_rbt_t *rbt) { } /* Test the creation of an rbt */ -static void -rbt_create(void **state) { +ISC_RUN_TEST_IMPL(rbt_create) { test_context_t *ctx; bool tree_ok; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; ctx = test_context_setup(); @@ -253,12 +226,9 @@ rbt_create(void **state) { } /* Test dns_rbt_nodecount() on a tree */ -static void -rbt_nodecount(void **state) { +ISC_RUN_TEST_IMPL(rbt_nodecount) { test_context_t *ctx; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; ctx = test_context_setup(); @@ -269,8 +239,7 @@ rbt_nodecount(void **state) { } /* Test dns_rbtnode_get_distance() on a tree */ -static void -rbtnode_get_distance(void **state) { +ISC_RUN_TEST_IMPL(rbtnode_get_distance) { isc_result_t result; test_context_t *ctx; const char *name_str = "a"; @@ -279,8 +248,6 @@ rbtnode_get_distance(void **state) { dns_rbtnode_t *node = NULL; dns_rbtnodechain_t chain; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; ctx = test_context_setup(); @@ -322,19 +289,16 @@ rbtnode_get_distance(void **state) { * path from a sub-tree's root to a node is no more than * 2log(n). This check verifies that the tree is balanced. */ -static void -rbt_check_distance_random(void **state) { +ISC_RUN_TEST_IMPL(rbt_check_distance_random) { dns_rbt_t *mytree = NULL; const unsigned int log_num_nodes = 16; isc_result_t result; bool tree_ok; int i; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; - result = dns_rbt_create(dt_mctx, delete_data, NULL, &mytree); + result = dns_rbt_create(mctx, delete_data, NULL, &mytree); assert_int_equal(result, ISC_R_SUCCESS); /* Names are inserted in random order. */ @@ -351,7 +315,7 @@ rbt_check_distance_random(void **state) { size_t *n; char namebuf[34]; - n = isc_mem_get(dt_mctx, sizeof(size_t)); + n = isc_mem_get(mctx, sizeof(size_t)); assert_non_null(n); *n = i + 1; @@ -400,19 +364,16 @@ rbt_check_distance_random(void **state) { * path from a sub-tree's root to a node is no more than * 2log(n). This check verifies that the tree is balanced. */ -static void -rbt_check_distance_ordered(void **state) { +ISC_RUN_TEST_IMPL(rbt_check_distance_ordered) { dns_rbt_t *mytree = NULL; const unsigned int log_num_nodes = 16; isc_result_t result; bool tree_ok; int i; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; - result = dns_rbt_create(dt_mctx, delete_data, NULL, &mytree); + result = dns_rbt_create(mctx, delete_data, NULL, &mytree); assert_int_equal(result, ISC_R_SUCCESS); /* Names are inserted in sorted order. */ @@ -431,7 +392,7 @@ rbt_check_distance_ordered(void **state) { dns_fixedname_t fname; dns_name_t *name; - n = isc_mem_get(dt_mctx, sizeof(size_t)); + n = isc_mem_get(mctx, sizeof(size_t)); assert_non_null(n); *n = i + 1; @@ -479,25 +440,22 @@ compare_labelsequences(dns_rbtnode_t *node, const char *labelstr) { dns_name_init(&name, NULL); dns_rbt_namefromnode(node, &name); - result = dns_name_tostring(&name, &nodestr, dt_mctx); + result = dns_name_tostring(&name, &nodestr, mctx); assert_int_equal(result, ISC_R_SUCCESS); is_equal = strcmp(labelstr, nodestr) == 0 ? true : false; - isc_mem_free(dt_mctx, nodestr); + isc_mem_free(mctx, nodestr); return (is_equal); } /* Test insertion into a tree */ -static void -rbt_insert(void **state) { +ISC_RUN_TEST_IMPL(rbt_insert) { isc_result_t result; test_context_t *ctx; dns_rbtnode_t *node; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; ctx = test_context_setup(); @@ -653,13 +611,10 @@ rbt_insert(void **state) { * as a red-black tree. This test checks node deletion when upper nodes * have data. */ -static void -rbt_remove(void **state) { +ISC_RUN_TEST_IMPL(rbt_remove) { isc_result_t result; size_t j; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; /* @@ -675,7 +630,7 @@ rbt_remove(void **state) { size_t start_node; /* Create a tree. */ - result = dns_rbt_create(dt_mctx, delete_data, NULL, &mytree); + result = dns_rbt_create(mctx, delete_data, NULL, &mytree); assert_int_equal(result, ISC_R_SUCCESS); /* Insert test data into the tree. */ @@ -703,7 +658,7 @@ rbt_remove(void **state) { assert_non_null(node); assert_null(node->data); - n = isc_mem_get(dt_mctx, sizeof(size_t)); + n = isc_mem_get(mctx, sizeof(size_t)); assert_non_null(n); *n = i; @@ -843,7 +798,7 @@ insert_nodes(dns_rbt_t *mytree, char **names, size_t *names_count, size_t *n; char namebuf[34]; - n = isc_mem_get(dt_mctx, sizeof(size_t)); + n = isc_mem_get(mctx, sizeof(size_t)); assert_non_null(n); *n = i; /* Unused value */ @@ -868,7 +823,7 @@ insert_nodes(dns_rbt_t *mytree, char **names, size_t *names_count, result = dns_rbt_addnode(mytree, name, &node); if (result == ISC_R_SUCCESS) { node->data = n; - names[*names_count] = isc_mem_strdup(dt_mctx, + names[*names_count] = isc_mem_strdup(mctx, namebuf); assert_non_null(names[*names_count]); *names_count += 1; @@ -899,7 +854,7 @@ remove_nodes(dns_rbt_t *mytree, char **names, size_t *names_count, result = dns_rbt_deletename(mytree, name, false); assert_int_equal(result, ISC_R_SUCCESS); - isc_mem_free(dt_mctx, names[node]); + isc_mem_free(mctx, names[node]); if (*names_count > 0) { names[node] = names[*names_count - 1]; names[*names_count - 1] = NULL; @@ -944,8 +899,7 @@ check_tree(dns_rbt_t *mytree, char **names, size_t names_count) { * forest. The number of nodes in the tree level doesn't grow * over 1024. */ -static void -rbt_insert_and_remove(void **state) { +ISC_RUN_TEST_IMPL(rbt_insert_and_remove) { isc_result_t result; dns_rbt_t *mytree = NULL; size_t *n; @@ -953,14 +907,12 @@ rbt_insert_and_remove(void **state) { size_t names_count; int i; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; - result = dns_rbt_create(dt_mctx, delete_data, NULL, &mytree); + result = dns_rbt_create(mctx, delete_data, NULL, &mytree); assert_int_equal(result, ISC_R_SUCCESS); - n = isc_mem_get(dt_mctx, sizeof(size_t)); + n = isc_mem_get(mctx, sizeof(size_t)); assert_non_null(n); result = dns_rbt_addname(mytree, dns_rootname, n); assert_int_equal(result, ISC_R_SUCCESS); @@ -999,7 +951,7 @@ rbt_insert_and_remove(void **state) { for (i = 0; i < 1024; i++) { if (names[i] != NULL) { - isc_mem_free(dt_mctx, names[i]); + isc_mem_free(mctx, names[i]); } } @@ -1011,16 +963,13 @@ rbt_insert_and_remove(void **state) { } /* Test findname return values */ -static void -rbt_findname(void **state) { +ISC_RUN_TEST_IMPL(rbt_findname) { isc_result_t result; test_context_t *ctx = NULL; dns_fixedname_t fname, found; dns_name_t *name = NULL, *foundname = NULL; size_t *n = NULL; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; ctx = test_context_setup(); @@ -1059,21 +1008,18 @@ rbt_findname(void **state) { } /* Test addname return values */ -static void -rbt_addname(void **state) { +ISC_RUN_TEST_IMPL(rbt_addname) { isc_result_t result; test_context_t *ctx = NULL; dns_fixedname_t fname; dns_name_t *name = NULL; size_t *n; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; ctx = test_context_setup(); - n = isc_mem_get(dt_mctx, sizeof(size_t)); + n = isc_mem_get(mctx, sizeof(size_t)); assert_non_null(n); *n = 1; @@ -1085,26 +1031,23 @@ rbt_addname(void **state) { assert_int_equal(result, ISC_R_SUCCESS); /* Now add again, should get ISC_R_EXISTS */ - n = isc_mem_get(dt_mctx, sizeof(size_t)); + n = isc_mem_get(mctx, sizeof(size_t)); assert_non_null(n); *n = 2; result = dns_rbt_addname(ctx->rbt, name, n); assert_int_equal(result, ISC_R_EXISTS); - isc_mem_put(dt_mctx, n, sizeof(size_t)); + isc_mem_put(mctx, n, sizeof(size_t)); test_context_teardown(ctx); } /* Test deletename return values */ -static void -rbt_deletename(void **state) { +ISC_RUN_TEST_IMPL(rbt_deletename) { isc_result_t result; test_context_t *ctx = NULL; dns_fixedname_t fname; dns_name_t *name = NULL; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; ctx = test_context_setup(); @@ -1125,8 +1068,7 @@ rbt_deletename(void **state) { } /* Test nodechain */ -static void -rbt_nodechain(void **state) { +ISC_RUN_TEST_IMPL(rbt_nodechain) { isc_result_t result; test_context_t *ctx; dns_fixedname_t fname, found, expect; @@ -1134,8 +1076,6 @@ rbt_nodechain(void **state) { dns_rbtnode_t *node = NULL; dns_rbtnodechain_t chain; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; ctx = test_context_setup(); @@ -1186,15 +1126,12 @@ rbt_nodechain(void **state) { } /* Test addname return values */ -static void -rbtnode_namelen(void **state) { +ISC_RUN_TEST_IMPL(rbtnode_namelen) { isc_result_t result; test_context_t *ctx = NULL; dns_rbtnode_t *node; unsigned int len; - UNUSED(state); - isc_mem_debugging = ISC_MEM_DEBUGRECORD; ctx = test_context_setup(); @@ -1267,8 +1204,7 @@ find_thread(void *arg) { } /* Benchmark RBT implementation */ -static void -benchmark(void **state) { +ISC_RUN_TEST_IMPL(benchmark) { isc_result_t result; char namestr[sizeof("name18446744073709551616.example.org.")]; unsigned int r; @@ -1281,8 +1217,6 @@ benchmark(void **state) { unsigned int nthreads; isc_thread_t threads[32]; - UNUSED(state); - srandom(time(NULL)); debug_mem_record = false; @@ -1301,7 +1235,7 @@ benchmark(void **state) { /* Create a tree. */ mytree = NULL; - result = dns_rbt_create(dt_mctx, NULL, NULL, &mytree); + result = dns_rbt_create(mctx, NULL, NULL, &mytree); assert_int_equal(result, ISC_R_SUCCESS); /* Insert test data into the tree. */ @@ -1343,47 +1277,24 @@ benchmark(void **state) { } #endif /* defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__) */ -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(rbt_create, _setup, _teardown), - cmocka_unit_test_setup_teardown(rbt_nodecount, _setup, - _teardown), - cmocka_unit_test_setup_teardown(rbtnode_get_distance, _setup, - _teardown), - cmocka_unit_test_setup_teardown(rbt_check_distance_random, - _setup, _teardown), - cmocka_unit_test_setup_teardown(rbt_check_distance_ordered, - _setup, _teardown), - cmocka_unit_test_setup_teardown(rbt_insert, _setup, _teardown), - cmocka_unit_test_setup_teardown(rbt_remove, _setup, _teardown), - cmocka_unit_test_setup_teardown(rbt_insert_and_remove, _setup, - _teardown), - cmocka_unit_test_setup_teardown(rbt_findname, _setup, - _teardown), - cmocka_unit_test_setup_teardown(rbt_addname, _setup, _teardown), - cmocka_unit_test_setup_teardown(rbt_deletename, _setup, - _teardown), - cmocka_unit_test_setup_teardown(rbt_nodechain, _setup, - _teardown), - cmocka_unit_test_setup_teardown(rbtnode_namelen, _setup, - _teardown), +ISC_TEST_LIST_START +ISC_TEST_ENTRY(rbt_create) +ISC_TEST_ENTRY(rbt_nodecount) +ISC_TEST_ENTRY(rbtnode_get_distance) +ISC_TEST_ENTRY(rbt_check_distance_random) +ISC_TEST_ENTRY(rbt_check_distance_ordered) +ISC_TEST_ENTRY(rbt_insert) +ISC_TEST_ENTRY(rbt_remove) +ISC_TEST_ENTRY(rbt_insert_and_remove) +ISC_TEST_ENTRY(rbt_findname) +ISC_TEST_ENTRY(rbt_addname) +ISC_TEST_ENTRY(rbt_deletename) +ISC_TEST_ENTRY(rbt_nodechain) +ISC_TEST_ENTRY(rbtnode_namelen) #if defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__) - cmocka_unit_test_setup_teardown(benchmark, _setup, _teardown), +ISC_TEST_ENTRY(benchmark) #endif /* defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__) */ - }; - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_LIST_END -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/rbtdb_test.c b/tests/dns/rbtdb_test.c similarity index 86% rename from lib/dns/tests/rbtdb_test.c rename to tests/dns/rbtdb_test.c index 3f523b19f9..817dd67e2f 100644 --- a/lib/dns/tests/rbtdb_test.c +++ b/tests/dns/rbtdb_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -29,33 +27,18 @@ #include #include #include - -#include "dnstest.h" +#define KEEP_BEFORE /* Include the main file */ -#include "../rbtdb.c" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#undef CHECK +#include "rbtdb.c" +#pragma GCC diagnostic pop -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#undef CHECK +#include const char *ownercase_vectors[12][2] = { { @@ -157,8 +140,7 @@ ownercase_test_one(const char *str1, const char *str2) { return (dns_name_caseequal(name1, name2)); } -static void -ownercase_test(void **state) { +ISC_RUN_TEST_IMPL(ownercase) { UNUSED(state); for (size_t n = 0; n < ARRAY_SIZE(ownercase_vectors); n++) { @@ -172,8 +154,7 @@ ownercase_test(void **state) { assert_false(ownercase_test_one("\\216", "\\246")); } -static void -setownercase_test(void **state) { +ISC_RUN_TEST_IMPL(setownercase) { isc_result_t result; rbtdb_nodelock_t node_locks[1]; dns_rbtdb_t rbtdb = { .node_locks = node_locks }; @@ -222,24 +203,9 @@ setownercase_test(void **state) { assert_true(dns_name_caseequal(name1, name2)); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(ownercase_test), - cmocka_unit_test(setownercase_test), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(ownercase) +ISC_TEST_ENTRY(setownercase) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/rdata_test.c b/tests/dns/rdata_test.c similarity index 92% rename from lib/dns/tests/rdata_test.c rename to tests/dns/rdata_test.c index 33b118d87d..71149eafaf 100644 --- a/lib/dns/tests/rdata_test.c +++ b/tests/dns/rdata_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -35,7 +33,7 @@ #include -#include "dnstest.h" +#include static bool debug = false; @@ -56,27 +54,6 @@ struct textvsunknown { }; typedef struct textvsunknown textvsunknown_t; -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} - /* * An array of these structures is passed to check_text_ok(). */ @@ -199,7 +176,7 @@ rdata_towire(dns_rdata_t *rdata, unsigned char *dst, size_t dstlen, /* * Try converting input data into uncompressed wire form. */ - dns_compress_init(&cctx, -1, dt_mctx); + dns_compress_init(&cctx, -1, mctx); result = dns_rdata_towire(rdata, &cctx, &target); dns_compress_invalidate(&cctx); @@ -285,7 +262,7 @@ check_struct_conversions(dns_rdata_t *rdata, size_t structsize, char buf[1024]; unsigned int count = 0; - rdata_struct = isc_mem_allocate(dt_mctx, structsize); + rdata_struct = isc_mem_allocate(mctx, structsize); assert_non_null(rdata_struct); /* @@ -365,7 +342,7 @@ check_struct_conversions(dns_rdata_t *rdata, size_t structsize, } } - isc_mem_free(dt_mctx, rdata_struct); + isc_mem_free(mctx, rdata_struct); } /* @@ -892,8 +869,7 @@ key_required(void **state, dns_rdatatype_t type, size_t size) { } /* APL RDATA manipulations */ -static void -apl(void **state) { +ISC_RUN_TEST_IMPL(apl) { text_ok_t text_ok[] = { /* empty list */ TEXT_VALID(""), @@ -934,8 +910,6 @@ apl(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, true, dns_rdataclass_in, dns_rdatatype_apl, sizeof(dns_rdata_in_apl_t)); } @@ -977,8 +951,7 @@ apl(void **state) { * * ATMA RRs cause no additional section processing. */ -static void -atma(void **state) { +ISC_RUN_TEST_IMPL(atma) { text_ok_t text_ok[] = { TEXT_VALID("00"), TEXT_VALID_CHANGED("0.0", "00"), /* @@ -1041,15 +1014,12 @@ atma(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_atma, sizeof(dns_rdata_in_atma_t)); } /* AMTRELAY RDATA manipulations */ -static void -amtrelay(void **state) { +ISC_RUN_TEST_IMPL(amtrelay) { text_ok_t text_ok[] = { TEXT_INVALID(""), TEXT_INVALID("0"), TEXT_INVALID("0 0"), /* gateway type 0 */ @@ -1121,14 +1091,11 @@ amtrelay(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_amtrelay, sizeof(dns_rdata_amtrelay_t)); } -static void -cdnskey(void **state) { +ISC_RUN_TEST_IMPL(cdnskey) { key_required(state, dns_rdatatype_cdnskey, sizeof(dns_rdata_cdnskey_t)); } @@ -1196,8 +1163,7 @@ cdnskey(void **state) { * must understand the semantics associated with a bit in the Type Bit * Map field that has been set to 1. */ -static void -csync(void **state) { +ISC_RUN_TEST_IMPL(csync) { text_ok_t text_ok[] = { TEXT_INVALID(""), TEXT_INVALID("0"), TEXT_VALID("0 0"), @@ -1252,14 +1218,11 @@ csync(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_csync, sizeof(dns_rdata_csync_t)); } -static void -dnskey(void **state) { +ISC_RUN_TEST_IMPL(dnskey) { key_required(state, dns_rdatatype_dnskey, sizeof(dns_rdata_dnskey_t)); } @@ -1323,8 +1286,7 @@ dnskey(void **state) { * character ("-", ASCII 45). White space is permitted within Base64 * data. */ -static void -doa(void **state) { +ISC_RUN_TEST_IMPL(doa) { text_ok_t text_ok[] = { /* * Valid, non-empty DOA-DATA. @@ -1471,8 +1433,6 @@ doa(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_doa, sizeof(dns_rdata_doa_t)); } @@ -1539,8 +1499,7 @@ doa(void **state) { * DNSKEY RR size. As of the time of this writing, the only defined * digest algorithm is SHA-1, which produces a 20 octet digest. */ -static void -ds(void **state) { +ISC_RUN_TEST_IMPL(ds) { text_ok_t text_ok[] = { /* * Invalid, empty record. @@ -1742,8 +1701,6 @@ ds(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_ds, sizeof(dns_rdata_ds_t)); } @@ -1808,8 +1765,7 @@ ds(void **state) { * All fields are in network byte order ("big-endian", per [RFC1700], * Data Notation). */ -static void -edns_client_subnet(void **state) { +ISC_RUN_TEST_IMPL(edns_client_subnet) { wire_ok_t wire_ok[] = { /* * Option code with no content. @@ -1883,8 +1839,6 @@ edns_client_subnet(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(NULL, wire_ok, NULL, true, dns_rdataclass_in, dns_rdatatype_opt, sizeof(dns_rdata_opt_t)); } @@ -1898,8 +1852,7 @@ edns_client_subnet(void **state) { * significant. For readability, whitespace may be included in the value * field and should be ignored when reading a master file. */ -static void -eid(void **state) { +ISC_RUN_TEST_IMPL(eid) { text_ok_t text_ok[] = { TEXT_VALID("AABBCC"), TEXT_VALID_CHANGED("AA bb cc", "AABBCC"), TEXT_INVALID("aab"), @@ -1913,8 +1866,6 @@ eid(void **state) { */ WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_eid, sizeof(dns_rdata_in_eid_t)); } @@ -1922,8 +1873,7 @@ eid(void **state) { /* * test that an oversized HIP record will be rejected */ -static void -hip(void **state) { +ISC_RUN_TEST_IMPL(hip) { text_ok_t text_ok[] = { /* RFC 8005 examples. */ TEXT_VALID_LOOP(0, "2 200100107B1A74DF365639CC39F1D578 " @@ -1959,8 +1909,6 @@ hip(void **state) { isc_result_t result; size_t i; - UNUSED(state); - /* * Fill the rest of input buffer with compression pointers. */ @@ -2037,8 +1985,7 @@ hip(void **state) { * as one or two s, i.e., count followed by * characters. */ -static void -isdn(void **state) { +ISC_RUN_TEST_IMPL(isdn) { wire_ok_t wire_ok[] = { /* * "". */ @@ -2061,8 +2008,6 @@ isdn(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_isdn, sizeof(dns_rdata_isdn_t)); } @@ -2070,8 +2015,7 @@ isdn(void **state) { /* * KEY tests. */ -static void -key(void **state) { +ISC_RUN_TEST_IMPL(key) { wire_ok_t wire_ok[] = { /* * RDATA is comprised of: @@ -2144,8 +2088,6 @@ key(void **state) { TEXT_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_key, sizeof(dns_rdata_key_t)); } @@ -2153,8 +2095,7 @@ key(void **state) { /* * LOC tests. */ -static void -loc(void **state) { +ISC_RUN_TEST_IMPL(loc) { text_ok_t text_ok[] = { TEXT_VALID_CHANGED("0 N 0 E 0", "0 0 0.000 N 0 0 0.000 E 0.00m " "1m 10000m 10m"), @@ -2209,8 +2150,6 @@ loc(void **state) { TEXT_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, 0, NULL, false, dns_rdataclass_in, dns_rdatatype_loc, sizeof(dns_rdata_loc_t)); } @@ -2224,8 +2163,7 @@ loc(void **state) { * significant. For readability, whitespace may be included in the value * field and should be ignored when reading a master file. */ -static void -nimloc(void **state) { +ISC_RUN_TEST_IMPL(nimloc) { text_ok_t text_ok[] = { TEXT_VALID("AABBCC"), TEXT_VALID_CHANGED("AA bb cc", "AABBCC"), TEXT_INVALID("aab"), @@ -2239,8 +2177,6 @@ nimloc(void **state) { */ WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_nimloc, sizeof(dns_rdata_in_nimloc_t)); } @@ -2311,8 +2247,7 @@ nimloc(void **state) { * Bits representing pseudo-types MUST be clear, as they do not appear * in zone data. If encountered, they MUST be ignored upon being read. */ -static void -nsec(void **state) { +ISC_RUN_TEST_IMPL(nsec) { text_ok_t text_ok[] = { TEXT_INVALID(""), TEXT_INVALID("."), TEXT_VALID(". RRSIG"), TEXT_SENTINEL() }; wire_ok_t wire_ok[] = { WIRE_INVALID(0x00), WIRE_INVALID(0x00, 0x00), @@ -2320,8 +2255,6 @@ nsec(void **state) { WIRE_VALID(0x00, 0x00, 0x01, 0x02), WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_nsec, sizeof(dns_rdata_nsec_t)); } @@ -2331,8 +2264,7 @@ nsec(void **state) { * * RFC 5155. */ -static void -nsec3(void **state) { +ISC_RUN_TEST_IMPL(nsec3) { text_ok_t text_ok[] = { TEXT_INVALID(""), TEXT_INVALID("."), TEXT_INVALID(". RRSIG"), @@ -2352,15 +2284,12 @@ nsec3(void **state) { "AJHVGTICN6K0VDA53GCHFMT219SRRQLM"), TEXT_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, NULL, NULL, false, dns_rdataclass_in, dns_rdatatype_nsec3, sizeof(dns_rdata_nsec3_t)); } /* NXT RDATA manipulations */ -static void -nxt(void **state) { +ISC_RUN_TEST_IMPL(nxt) { compare_ok_t compare_ok[] = { COMPARE("a. A SIG", "a. A SIG", 0), /* @@ -2379,14 +2308,11 @@ nxt(void **state) { COMPARE("b. A SIG AAAA", "b. A AAAA SIG", 0), COMPARE_SENTINEL() }; - UNUSED(state); - check_rdata(NULL, NULL, compare_ok, false, dns_rdataclass_in, dns_rdatatype_nxt, sizeof(dns_rdata_nxt_t)); } -static void -rkey(void **state) { +ISC_RUN_TEST_IMPL(rkey) { text_ok_t text_ok[] = { /* * Valid, flags set to 0 and a key is present. */ @@ -2420,108 +2346,8 @@ rkey(void **state) { dns_rdatatype_rkey, sizeof(dns_rdata_rkey_t)); } -/* - * rrsig (sig) tests. - */ -static void -sig_rrsig(void **state) { - wire_ok_t wire_ok[] = { - /* - * RDATA is comprised of: - * - * type covered: 2 - * algorithm: 1 - * labels: 1 - * original ttl: 4 - * signature expiration: 4 - * time signed: 4 - * key footprint: 2 - * signer: variable - * signature: variable - * - if algorithm is PRIVATEDNS the algorithm name is embedded - * at the start of the signature - * - if algorithm is PRIVATEOID the algorithm OID is embedded - * at the start of the signature - */ - /* PRIVATEDNS example. */ - WIRE_INVALID(0x00, 0x01, 253, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 's', 'i', 'g', 'n', 'e', 'r', - 0x00, 0x07, 'e', 'x', 'a', 'm', 'p', 'l', 'e', - 0x00), - /* PRIVATEDNS example. + sigdata */ - WIRE_VALID(0x00, 0x01, 253, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 's', 'i', 'g', 'n', 'e', 'r', 0x00, 0x07, 'e', - 'x', 'a', 'm', 'p', 'l', 'e', 0x00, 0x00), - /* PRIVATEDNS compression pointer. */ - WIRE_INVALID(0x00, 0x00, 0x00, 253, 0xc0, 0x00, 0x00), - /* PRIVATEOID */ - WIRE_INVALID(0x00, 0x01, 254, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 's', 'i', 'g', 'n', 'e', 'r', - 0x00, 0x00), - /* PRIVATEOID 1.3.6.1.4.1.2495 */ - WIRE_INVALID(0x00, 0x01, 254, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 's', 'i', 'g', 'n', 'e', 'r', - 0x00, 0x06, 0x07, 0x2b, 0x06, 0x01, 0x04, 0x01, - 0x93, 0x3f), - /* PRIVATEOID 1.3.6.1.4.1.2495 + sigdata */ - WIRE_VALID(0x00, 0x01, 254, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 's', 'i', 'g', 'n', 'e', 'r', 0x00, 0x06, 0x07, - 0x2b, 0x06, 0x01, 0x04, 0x01, 0x93, 0x3f, 0x00), - /* PRIVATEOID malformed OID - high-bit set on last octet */ - WIRE_INVALID(0x00, 0x01, 254, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 's', 'i', 'g', 'n', 'e', 'r', - 0x00, 0x06, 0x07, 0x2b, 0x06, 0x01, 0x04, 0x01, - 0x93, 0xbf, 0x00), - WIRE_SENTINEL() - }; - text_ok_t text_ok[] = { - /* PRIVATEDNS example. */ - TEXT_INVALID("A 253 1 0 19700101000001 19700101000000 0 " - "signer. B2V4YW1wbGUA"), - /* PRIVATEDNS example. + sigdata */ - TEXT_VALID("A 253 1 0 19700101000001 19700101000000 0 signer. " - "B2V4YW1wbGUAAA=="), - /* PRIVATEDNS compression pointer. */ - TEXT_INVALID("A 253 1 0 19700101000001 19700101000000 0 " - "signer. wAAA"), - /* PRIVATEOID */ - TEXT_INVALID("A 254 1 0 19700101000001 19700101000000 0 " - "signer. AA=="), - /* PRIVATEOID 1.3.6.1.4.1.2495 */ - TEXT_INVALID("A 254 1 0 19700101000001 19700101000000 0 " - "signer. BgcrBgEEAZM/"), - /* PRIVATEOID 1.3.6.1.4.1.2495 + sigdata */ - TEXT_VALID("A 254 1 0 19700101000001 19700101000000 0 signer. " - "BgcrBgEEAZM/AA=="), - /* PRIVATEOID malformed OID - high-bit set on last octet */ - TEXT_INVALID("A 254 1 0 19700101000001 19700101000000 0 " - "signer. BgcrBgEEAZO/AA=="), - /* PRIVATEOID malformed OID - wrong tag */ - TEXT_INVALID("A 254 1 0 19700101000001 19700101000000 0 " - "signer. BwcrBgEEAZM/AA=="), - /* - * Sentinel. - */ - TEXT_SENTINEL() - }; - - UNUSED(state); - - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, - dns_rdatatype_sig, sizeof(dns_rdata_sig_t)); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, - dns_rdatatype_rrsig, sizeof(dns_rdata_rrsig_t)); -} - /* SSHFP RDATA manipulations */ -static void -sshfp(void **state) { +ISC_RUN_TEST_IMPL(sshfp) { text_ok_t text_ok[] = { TEXT_INVALID(""), /* too short */ TEXT_INVALID("0"), /* reserved, too short */ TEXT_VALID("0 0"), /* no finger print */ @@ -2598,8 +2424,6 @@ sshfp(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_sshfp, sizeof(dns_rdata_sshfp_t)); } @@ -2643,8 +2467,7 @@ sshfp(void **state) { * port 25; if zero, SMTP service is not supported on the specified * address. */ -static void -wks(void **state) { +ISC_RUN_TEST_IMPL(wks) { text_ok_t text_ok[] = { /* * Valid, IPv4 address in dotted-quad form. */ @@ -2681,14 +2504,11 @@ wks(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_wks, sizeof(dns_rdata_in_wks_t)); } -static void -https_svcb(void **state) { +ISC_RUN_TEST_IMPL(https_svcb) { /* * Known keys: mandatory, apln, no-default-alpn, port, * ipv4hint, port, ipv6hint. @@ -2932,8 +2752,6 @@ https_svcb(void **state) { { NULL, NULL } }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_svcb, sizeof(dns_rdata_in_svcb_t)); check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, @@ -3030,8 +2848,7 @@ https_svcb(void **state) { * */ -static void -zonemd(void **state) { +ISC_RUN_TEST_IMPL(zonemd) { text_ok_t text_ok[] = { TEXT_INVALID(""), /* No digest scheme or digest type*/ @@ -3198,16 +3015,13 @@ zonemd(void **state) { WIRE_SENTINEL() }; - UNUSED(state); - check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, dns_rdatatype_zonemd, sizeof(dns_rdata_zonemd_t)); } -static void -atcname(void **state) { +ISC_RUN_TEST_IMPL(atcname) { unsigned int i; - UNUSED(state); + #define UNR "# Unexpected result from dns_rdatatype_atcname for type %u\n" for (i = 0; i < 0xffffU; i++) { bool tf = dns_rdatatype_atcname((dns_rdatatype_t)i); @@ -3231,10 +3045,9 @@ atcname(void **state) { #undef UNR } -static void -atparent(void **state) { +ISC_RUN_TEST_IMPL(atparent) { unsigned int i; - UNUSED(state); + #define UNR "# Unexpected result from dns_rdatatype_atparent for type %u\n" for (i = 0; i < 0xffffU; i++) { bool tf = dns_rdatatype_atparent((dns_rdatatype_t)i); @@ -3256,10 +3069,8 @@ atparent(void **state) { #undef UNR } -static void -iszonecutauth(void **state) { +ISC_RUN_TEST_IMPL(iszonecutauth) { unsigned int i; - UNUSED(state); #define UNR "# Unexpected result from dns_rdatatype_iszonecutauth for type %u\n" for (i = 0; i < 0xffffU; i++) { bool tf = dns_rdatatype_iszonecutauth((dns_rdatatype_t)i); @@ -3285,88 +3096,37 @@ iszonecutauth(void **state) { #undef UNR } -int -main(int argc, char **argv) { - const struct CMUnitTest tests[] = { - /* types */ - cmocka_unit_test_setup_teardown(amtrelay, _setup, _teardown), - cmocka_unit_test_setup_teardown(apl, _setup, _teardown), - cmocka_unit_test_setup_teardown(atma, _setup, _teardown), - cmocka_unit_test_setup_teardown(cdnskey, _setup, _teardown), - cmocka_unit_test_setup_teardown(csync, _setup, _teardown), - cmocka_unit_test_setup_teardown(dnskey, _setup, _teardown), - cmocka_unit_test_setup_teardown(doa, _setup, _teardown), - cmocka_unit_test_setup_teardown(ds, _setup, _teardown), - cmocka_unit_test_setup_teardown(eid, _setup, _teardown), - cmocka_unit_test_setup_teardown(hip, _setup, _teardown), - cmocka_unit_test_setup_teardown(https_svcb, _setup, _teardown), - cmocka_unit_test_setup_teardown(isdn, _setup, _teardown), - cmocka_unit_test_setup_teardown(key, _setup, _teardown), - cmocka_unit_test_setup_teardown(loc, _setup, _teardown), - cmocka_unit_test_setup_teardown(nimloc, _setup, _teardown), - cmocka_unit_test_setup_teardown(nsec, _setup, _teardown), - cmocka_unit_test_setup_teardown(nsec3, _setup, _teardown), - cmocka_unit_test_setup_teardown(nxt, _setup, _teardown), - cmocka_unit_test_setup_teardown(rkey, _setup, _teardown), - cmocka_unit_test_setup_teardown(sig_rrsig, _setup, _teardown), - cmocka_unit_test_setup_teardown(sshfp, _setup, _teardown), - cmocka_unit_test_setup_teardown(wks, _setup, _teardown), - cmocka_unit_test_setup_teardown(zonemd, _setup, _teardown), - /* other tests */ - cmocka_unit_test_setup_teardown(edns_client_subnet, _setup, - _teardown), - cmocka_unit_test_setup_teardown(atcname, NULL, NULL), - cmocka_unit_test_setup_teardown(atparent, NULL, NULL), - cmocka_unit_test_setup_teardown(iszonecutauth, NULL, NULL), - }; - struct CMUnitTest selected[sizeof(tests) / sizeof(tests[0])]; - size_t i; - int c; +ISC_TEST_LIST_START - memset(selected, 0, sizeof(selected)); +/* types */ +ISC_TEST_ENTRY(amtrelay) +ISC_TEST_ENTRY(apl) +ISC_TEST_ENTRY(atma) +ISC_TEST_ENTRY(cdnskey) +ISC_TEST_ENTRY(csync) +ISC_TEST_ENTRY(dnskey) +ISC_TEST_ENTRY(doa) +ISC_TEST_ENTRY(ds) +ISC_TEST_ENTRY(eid) +ISC_TEST_ENTRY(hip) +ISC_TEST_ENTRY(https_svcb) +ISC_TEST_ENTRY(isdn) +ISC_TEST_ENTRY(key) +ISC_TEST_ENTRY(loc) +ISC_TEST_ENTRY(nimloc) +ISC_TEST_ENTRY(nsec) +ISC_TEST_ENTRY(nsec3) +ISC_TEST_ENTRY(nxt) +ISC_TEST_ENTRY(rkey) +ISC_TEST_ENTRY(sshfp) +ISC_TEST_ENTRY(wks) +ISC_TEST_ENTRY(zonemd) - while ((c = isc_commandline_parse(argc, argv, "dlt:")) != -1) { - switch (c) { - case 'd': - debug = true; - break; - case 'l': - for (i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++) - { - if (tests[i].name != NULL) { - fprintf(stdout, "%s\n", tests[i].name); - } - } - return (0); - case 't': - if (!cmocka_add_test_byname( - tests, isc_commandline_argument, selected)) - { - fprintf(stderr, "unknown test '%s'\n", - isc_commandline_argument); - exit(1); - } - break; - default: - break; - } - } +/* other tests */ +ISC_TEST_ENTRY(edns_client_subnet) +ISC_TEST_ENTRY(atcname) +ISC_TEST_ENTRY(atparent) +ISC_TEST_ENTRY(iszonecutauth) +ISC_TEST_LIST_END - if (selected[0].name != NULL) { - return (cmocka_run_group_tests(selected, NULL, NULL)); - } else { - return (cmocka_run_group_tests(tests, NULL, NULL)); - } -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/rdataset_test.c b/tests/dns/rdataset_test.c similarity index 79% rename from lib/dns/tests/rdataset_test.c rename to tests/dns/rdataset_test.c index ebdd128312..e9b47ecbf3 100644 --- a/lib/dns/tests/rdataset_test.c +++ b/tests/dns/rdataset_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -29,32 +27,10 @@ #include #include -#include "dnstest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#include /* test trimming of rdataset TTLs */ -static void -trimttl(void **state) { +ISC_RUN_TEST_IMPL(trimttl) { dns_rdataset_t rdataset, sigrdataset; dns_rdata_rrsig_t rrsig; isc_stdtime_t ttltimenow, ttltimeexpire; @@ -124,23 +100,8 @@ trimttl(void **state) { assert_int_equal(sigrdataset.ttl, 0); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(trimttl, _setup, _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(trimttl) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/rdatasetstats_test.c b/tests/dns/rdatasetstats_test.c similarity index 86% rename from lib/dns/tests/rdatasetstats_test.c rename to tests/dns/rdatasetstats_test.c index 20b333dc67..743803474c 100644 --- a/lib/dns/tests/rdatasetstats_test.c +++ b/tests/dns/rdatasetstats_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -31,28 +29,7 @@ #include -#include "dnstest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#include static void set_typestats(dns_stats_t *stats, dns_rdatatype_t type) { @@ -220,7 +197,7 @@ rdatasetstats(void **state, bool servestale) { UNUSED(state); - result = dns_rdatasetstats_create(dt_mctx, &stats); + result = dns_rdatasetstats_create(mctx, &stats); assert_int_equal(result, ISC_R_SUCCESS); /* First 255 types. */ @@ -272,41 +249,17 @@ rdatasetstats(void **state, bool servestale) { * Test that rdatasetstats counters are properly set when moving from * active -> stale -> ancient. */ -static void -test_rdatasetstats_active_stale_ancient(void **state) { - rdatasetstats(state, true); -} +ISC_RUN_TEST_IMPL(active_stale_ancient) { rdatasetstats(state, true); } /* * Test that rdatasetstats counters are properly set when moving from * active -> ancient. */ -static void -test_rdatasetstats_active_ancient(void **state) { - rdatasetstats(state, false); -} +ISC_RUN_TEST_IMPL(active_ancient) { rdatasetstats(state, false); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown( - test_rdatasetstats_active_stale_ancient, _setup, - _teardown), - cmocka_unit_test_setup_teardown( - test_rdatasetstats_active_ancient, _setup, _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(active_stale_ancient) +ISC_TEST_ENTRY(active_ancient) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/resolver_test.c b/tests/dns/resolver_test.c similarity index 73% rename from lib/dns/tests/resolver_test.c rename to tests/dns/resolver_test.c index 6cd1c80fac..634dbc4a28 100644 --- a/lib/dns/tests/resolver_test.c +++ b/tests/dns/resolver_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -36,7 +34,7 @@ #include #include -#include "dnstest.h" +#include static dns_dispatchmgr_t *dispatchmgr = NULL; static dns_dispatch_t *dispatch = NULL; @@ -47,15 +45,12 @@ _setup(void **state) { isc_result_t result; isc_sockaddr_t local; - UNUSED(state); + setup_managers(state); - result = dns_test_begin(NULL, true); + result = dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); - result = dns_dispatchmgr_create(dt_mctx, netmgr, &dispatchmgr); - assert_int_equal(result, ISC_R_SUCCESS); - - result = dns_test_makeview("view", &view); + result = dns_test_makeview("view", true, &view); assert_int_equal(result, ISC_R_SUCCESS); isc_sockaddr_any(&local); @@ -67,12 +62,11 @@ _setup(void **state) { static int _teardown(void **state) { - UNUSED(state); - dns_dispatch_detach(&dispatch); dns_view_detach(&view); dns_dispatchmgr_detach(&dispatchmgr); - dns_test_end(); + + teardown_managers(state); return (0); } @@ -93,8 +87,7 @@ destroy_resolver(dns_resolver_t **resolverp) { } /* dns_resolver_create */ -static void -create_test(void **state) { +ISC_RUN_TEST_IMPL(dns_resolver_create) { dns_resolver_t *resolver = NULL; UNUSED(state); @@ -104,8 +97,7 @@ create_test(void **state) { } /* dns_resolver_gettimeout */ -static void -gettimeout_test(void **state) { +ISC_RUN_TEST_IMPL(dns_resolver_gettimeout) { dns_resolver_t *resolver = NULL; unsigned int timeout; @@ -120,8 +112,7 @@ gettimeout_test(void **state) { } /* dns_resolver_settimeout */ -static void -settimeout_test(void **state) { +ISC_RUN_TEST_IMPL(dns_resolver_settimeout) { dns_resolver_t *resolver = NULL; unsigned int default_timeout, timeout; @@ -138,8 +129,7 @@ settimeout_test(void **state) { } /* dns_resolver_settimeout */ -static void -settimeout_default_test(void **state) { +ISC_RUN_TEST_IMPL(dns_resolver_settimeout_default) { dns_resolver_t *resolver = NULL; unsigned int default_timeout, timeout; @@ -161,8 +151,7 @@ settimeout_default_test(void **state) { } /* dns_resolver_settimeout below minimum */ -static void -settimeout_belowmin_test(void **state) { +ISC_RUN_TEST_IMPL(dns_resolver_settimeout_belowmin) { dns_resolver_t *resolver = NULL; unsigned int default_timeout, timeout; @@ -180,8 +169,7 @@ settimeout_belowmin_test(void **state) { } /* dns_resolver_settimeout over maximum */ -static void -settimeout_overmax_test(void **state) { +ISC_RUN_TEST_IMPL(dns_resolver_settimeout_overmax) { dns_resolver_t *resolver = NULL; unsigned int timeout; @@ -195,33 +183,15 @@ settimeout_overmax_test(void **state) { destroy_resolver(&resolver); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(create_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(gettimeout_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(settimeout_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(settimeout_default_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(settimeout_belowmin_test, - _setup, _teardown), - cmocka_unit_test_setup_teardown(settimeout_overmax_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY_CUSTOM(dns_resolver_create, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(dns_resolver_gettimeout, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(dns_resolver_settimeout, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(dns_resolver_settimeout_default, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(dns_resolver_settimeout_belowmin, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(dns_resolver_settimeout_overmax, _setup, _teardown) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/rsa_test.c b/tests/dns/rsa_test.c similarity index 89% rename from lib/dns/tests/rsa_test.c rename to tests/dns/rsa_test.c index 7ed61eb3ed..8b2bd89219 100644 --- a/lib/dns/tests/rsa_test.c +++ b/tests/dns/rsa_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -28,26 +26,30 @@ #include #include -#include "../dst_internal.h" -#include "dnstest.h" +#include "dst_internal.h" + +#include static int -_setup(void **state) { +setup_test(void **state) { isc_result_t result; UNUSED(state); - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); + result = dst_lib_init(mctx, NULL); + + if (result != ISC_R_SUCCESS) { + return (1); + } return (0); } static int -_teardown(void **state) { +teardown_test(void **state) { UNUSED(state); - dns_test_end(); + dst_lib_destroy(); return (0); } @@ -131,8 +133,7 @@ static unsigned char sigsha512[512] = { }; /* RSA verify */ -static void -isc_rsa_verify_test(void **state) { +ISC_RUN_TEST_IMPL(isc_rsa_verify) { isc_result_t ret; dns_fixedname_t fname; isc_buffer_t buf; @@ -150,12 +151,12 @@ isc_rsa_verify_test(void **state) { assert_int_equal(ret, ISC_R_SUCCESS); ret = dst_key_fromfile(name, 29235, DST_ALG_RSASHA1, DST_TYPE_PUBLIC, - "./", dt_mctx, &key); + "./", mctx, &key); assert_int_equal(ret, ISC_R_SUCCESS); /* RSASHA1 */ - ret = dst_context_create(key, dt_mctx, DNS_LOGCATEGORY_DNSSEC, false, 0, + ret = dst_context_create(key, mctx, DNS_LOGCATEGORY_DNSSEC, false, 0, &ctx); assert_int_equal(ret, ISC_R_SUCCESS); @@ -175,7 +176,7 @@ isc_rsa_verify_test(void **state) { key->key_alg = DST_ALG_RSASHA256; - ret = dst_context_create(key, dt_mctx, DNS_LOGCATEGORY_DNSSEC, false, 0, + ret = dst_context_create(key, mctx, DNS_LOGCATEGORY_DNSSEC, false, 0, &ctx); assert_int_equal(ret, ISC_R_SUCCESS); @@ -195,7 +196,7 @@ isc_rsa_verify_test(void **state) { key->key_alg = DST_ALG_RSASHA512; - ret = dst_context_create(key, dt_mctx, DNS_LOGCATEGORY_DNSSEC, false, 0, + ret = dst_context_create(key, mctx, DNS_LOGCATEGORY_DNSSEC, false, 0, &ctx); assert_int_equal(ret, ISC_R_SUCCESS); @@ -214,24 +215,8 @@ isc_rsa_verify_test(void **state) { dst_key_free(&key); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(isc_rsa_verify_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(isc_rsa_verify, setup_test, teardown_test) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/sigs_test.c b/tests/dns/sigs_test.c similarity index 93% rename from lib/dns/tests/sigs_test.c rename to tests/dns/sigs_test.c index a6d1b2c08b..55183057f1 100644 --- a/lib/dns/tests/sigs_test.c +++ b/tests/dns/sigs_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -45,29 +43,9 @@ #include -#include "../zone_p.h" -#include "dnstest.h" +#include "zone_p.h" -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#include /*% * Structure characterizing a single diff tuple in the dns_diff_t structure @@ -95,6 +73,30 @@ typedef struct { * */ } updatesigs_test_params_t; +static int +setup_test(void **state) { + isc_result_t result; + + UNUSED(state); + + result = dst_lib_init(mctx, NULL); + + if (result != ISC_R_SUCCESS) { + return (1); + } + + return (0); +} + +static int +teardown_test(void **state) { + UNUSED(state); + + dst_lib_destroy(); + + return (0); +} + /*% * Check whether the 'found' tuple matches the 'expected' tuple. 'found' is * the 'index'th tuple output by dns__zone_updatesigs() in test 'test'. @@ -126,8 +128,7 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found, * Check owner name. */ expected_name = dns_fixedname_initname(&expected_fname); - result = dns_name_fromstring(expected_name, expected->owner, 0, - dt_mctx); + result = dns_name_fromstring(expected_name, expected->owner, 0, mctx); assert_int_equal(result, ISC_R_SUCCESS); dns_name_format(&found->name, found_name, sizeof(found_name)); assert_true(dns_name_equal(expected_name, &found->name)); @@ -235,7 +236,7 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone, /* * Initialize the structure dns__zone_updatesigs() will modify. */ - dns_diff_init(dt_mctx, &zone_diff); + dns_diff_init(mctx, &zone_diff); /* * Check whether dns__zone_updatesigs() behaves as expected. @@ -287,8 +288,7 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone, } /* dns__zone_updatesigs() tests */ -static void -updatesigs_next_test(void **state) { +ISC_RUN_TEST_IMPL(updatesigs_next) { dst_key_t *zone_keys[DNS_MAXZONEKEYS]; dns_zone_t *zone = NULL; dns_db_t *db = NULL; @@ -314,8 +314,8 @@ updatesigs_next_test(void **state) { assert_int_equal(result, ISC_R_SUCCESS); isc_stdtime_get(&now); - result = dns__zone_findkeys(zone, db, NULL, now, dt_mctx, - DNS_MAXZONEKEYS, zone_keys, &nkeys); + result = dns__zone_findkeys(zone, db, NULL, now, mctx, DNS_MAXZONEKEYS, + zone_keys, &nkeys); assert_int_equal(result, ISC_R_SUCCESS); assert_int_equal(nkeys, 2); @@ -438,24 +438,8 @@ updatesigs_next_test(void **state) { dns_zone_detach(&zone); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(updatesigs_next_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(updatesigs_next, setup_test, teardown_test) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/testdata/db/data.db b/tests/dns/testdata/db/data.db similarity index 100% rename from lib/dns/tests/testdata/db/data.db rename to tests/dns/testdata/db/data.db diff --git a/lib/dns/tests/testdata/dbiterator/zone1.data b/tests/dns/testdata/dbiterator/zone1.data similarity index 100% rename from lib/dns/tests/testdata/dbiterator/zone1.data rename to tests/dns/testdata/dbiterator/zone1.data diff --git a/lib/dns/tests/testdata/dbiterator/zone2.data b/tests/dns/testdata/dbiterator/zone2.data similarity index 100% rename from lib/dns/tests/testdata/dbiterator/zone2.data rename to tests/dns/testdata/dbiterator/zone2.data diff --git a/lib/dns/tests/testdata/diff/zone1.data b/tests/dns/testdata/diff/zone1.data similarity index 100% rename from lib/dns/tests/testdata/diff/zone1.data rename to tests/dns/testdata/diff/zone1.data diff --git a/lib/dns/tests/testdata/diff/zone2.data b/tests/dns/testdata/diff/zone2.data similarity index 100% rename from lib/dns/tests/testdata/diff/zone2.data rename to tests/dns/testdata/diff/zone2.data diff --git a/lib/dns/tests/testdata/diff/zone3.data b/tests/dns/testdata/diff/zone3.data similarity index 100% rename from lib/dns/tests/testdata/diff/zone3.data rename to tests/dns/testdata/diff/zone3.data diff --git a/lib/dns/tests/testdata/dnstap/dnstap.saved b/tests/dns/testdata/dnstap/dnstap.saved similarity index 100% rename from lib/dns/tests/testdata/dnstap/dnstap.saved rename to tests/dns/testdata/dnstap/dnstap.saved diff --git a/lib/dns/tests/testdata/dnstap/dnstap.text b/tests/dns/testdata/dnstap/dnstap.text similarity index 100% rename from lib/dns/tests/testdata/dnstap/dnstap.text rename to tests/dns/testdata/dnstap/dnstap.text diff --git a/lib/dns/tests/testdata/dnstap/query.auth b/tests/dns/testdata/dnstap/query.auth similarity index 100% rename from lib/dns/tests/testdata/dnstap/query.auth rename to tests/dns/testdata/dnstap/query.auth diff --git a/lib/dns/tests/testdata/dnstap/query.recursive b/tests/dns/testdata/dnstap/query.recursive similarity index 100% rename from lib/dns/tests/testdata/dnstap/query.recursive rename to tests/dns/testdata/dnstap/query.recursive diff --git a/lib/dns/tests/testdata/dnstap/response.auth b/tests/dns/testdata/dnstap/response.auth similarity index 100% rename from lib/dns/tests/testdata/dnstap/response.auth rename to tests/dns/testdata/dnstap/response.auth diff --git a/lib/dns/tests/testdata/dnstap/response.recursive b/tests/dns/testdata/dnstap/response.recursive similarity index 100% rename from lib/dns/tests/testdata/dnstap/response.recursive rename to tests/dns/testdata/dnstap/response.recursive diff --git a/lib/dns/tests/testdata/dst/Ktest.+008+11349.key b/tests/dns/testdata/dst/Ktest.+008+11349.key similarity index 100% rename from lib/dns/tests/testdata/dst/Ktest.+008+11349.key rename to tests/dns/testdata/dst/Ktest.+008+11349.key diff --git a/lib/dns/tests/testdata/dst/Ktest.+008+11349.private b/tests/dns/testdata/dst/Ktest.+008+11349.private similarity index 100% rename from lib/dns/tests/testdata/dst/Ktest.+008+11349.private rename to tests/dns/testdata/dst/Ktest.+008+11349.private diff --git a/lib/dns/tests/testdata/dst/Ktest.+013+49130.key b/tests/dns/testdata/dst/Ktest.+013+49130.key similarity index 100% rename from lib/dns/tests/testdata/dst/Ktest.+013+49130.key rename to tests/dns/testdata/dst/Ktest.+013+49130.key diff --git a/lib/dns/tests/testdata/dst/Ktest.+013+49130.private b/tests/dns/testdata/dst/Ktest.+013+49130.private similarity index 100% rename from lib/dns/tests/testdata/dst/Ktest.+013+49130.private rename to tests/dns/testdata/dst/Ktest.+013+49130.private diff --git a/lib/dns/tests/testdata/dst/test1.data b/tests/dns/testdata/dst/test1.data similarity index 100% rename from lib/dns/tests/testdata/dst/test1.data rename to tests/dns/testdata/dst/test1.data diff --git a/lib/dns/tests/testdata/dst/test1.ecdsa256sig b/tests/dns/testdata/dst/test1.ecdsa256sig similarity index 100% rename from lib/dns/tests/testdata/dst/test1.ecdsa256sig rename to tests/dns/testdata/dst/test1.ecdsa256sig diff --git a/lib/dns/tests/testdata/dst/test1.rsasha256sig b/tests/dns/testdata/dst/test1.rsasha256sig similarity index 100% rename from lib/dns/tests/testdata/dst/test1.rsasha256sig rename to tests/dns/testdata/dst/test1.rsasha256sig diff --git a/lib/dns/tests/testdata/dst/test2.data b/tests/dns/testdata/dst/test2.data similarity index 100% rename from lib/dns/tests/testdata/dst/test2.data rename to tests/dns/testdata/dst/test2.data diff --git a/lib/dns/tests/testdata/dstrandom/random.data b/tests/dns/testdata/dstrandom/random.data similarity index 100% rename from lib/dns/tests/testdata/dstrandom/random.data rename to tests/dns/testdata/dstrandom/random.data diff --git a/lib/dns/tests/testdata/master/.gitignore b/tests/dns/testdata/master/.gitignore similarity index 100% rename from lib/dns/tests/testdata/master/.gitignore rename to tests/dns/testdata/master/.gitignore diff --git a/lib/dns/tests/testdata/master/master1.data b/tests/dns/testdata/master/master1.data similarity index 100% rename from lib/dns/tests/testdata/master/master1.data rename to tests/dns/testdata/master/master1.data diff --git a/lib/dns/tests/testdata/master/master10.data b/tests/dns/testdata/master/master10.data similarity index 100% rename from lib/dns/tests/testdata/master/master10.data rename to tests/dns/testdata/master/master10.data diff --git a/lib/dns/tests/testdata/master/master11.data b/tests/dns/testdata/master/master11.data similarity index 100% rename from lib/dns/tests/testdata/master/master11.data rename to tests/dns/testdata/master/master11.data diff --git a/lib/dns/tests/testdata/master/master12.data.in b/tests/dns/testdata/master/master12.data.in similarity index 100% rename from lib/dns/tests/testdata/master/master12.data.in rename to tests/dns/testdata/master/master12.data.in diff --git a/lib/dns/tests/testdata/master/master13.data.in b/tests/dns/testdata/master/master13.data.in similarity index 100% rename from lib/dns/tests/testdata/master/master13.data.in rename to tests/dns/testdata/master/master13.data.in diff --git a/lib/dns/tests/testdata/master/master14.data.in b/tests/dns/testdata/master/master14.data.in similarity index 100% rename from lib/dns/tests/testdata/master/master14.data.in rename to tests/dns/testdata/master/master14.data.in diff --git a/lib/dns/tests/testdata/master/master15.data b/tests/dns/testdata/master/master15.data similarity index 100% rename from lib/dns/tests/testdata/master/master15.data rename to tests/dns/testdata/master/master15.data diff --git a/lib/dns/tests/testdata/master/master16.data b/tests/dns/testdata/master/master16.data similarity index 100% rename from lib/dns/tests/testdata/master/master16.data rename to tests/dns/testdata/master/master16.data diff --git a/lib/dns/tests/testdata/master/master17.data b/tests/dns/testdata/master/master17.data similarity index 100% rename from lib/dns/tests/testdata/master/master17.data rename to tests/dns/testdata/master/master17.data diff --git a/lib/dns/tests/testdata/master/master18.data b/tests/dns/testdata/master/master18.data similarity index 100% rename from lib/dns/tests/testdata/master/master18.data rename to tests/dns/testdata/master/master18.data diff --git a/lib/dns/tests/testdata/master/master2.data b/tests/dns/testdata/master/master2.data similarity index 100% rename from lib/dns/tests/testdata/master/master2.data rename to tests/dns/testdata/master/master2.data diff --git a/lib/dns/tests/testdata/master/master3.data b/tests/dns/testdata/master/master3.data similarity index 100% rename from lib/dns/tests/testdata/master/master3.data rename to tests/dns/testdata/master/master3.data diff --git a/lib/dns/tests/testdata/master/master4.data b/tests/dns/testdata/master/master4.data similarity index 100% rename from lib/dns/tests/testdata/master/master4.data rename to tests/dns/testdata/master/master4.data diff --git a/lib/dns/tests/testdata/master/master5.data b/tests/dns/testdata/master/master5.data similarity index 100% rename from lib/dns/tests/testdata/master/master5.data rename to tests/dns/testdata/master/master5.data diff --git a/lib/dns/tests/testdata/master/master6.data b/tests/dns/testdata/master/master6.data similarity index 100% rename from lib/dns/tests/testdata/master/master6.data rename to tests/dns/testdata/master/master6.data diff --git a/lib/dns/tests/testdata/master/master7.data b/tests/dns/testdata/master/master7.data similarity index 100% rename from lib/dns/tests/testdata/master/master7.data rename to tests/dns/testdata/master/master7.data diff --git a/lib/dns/tests/testdata/master/master8.data b/tests/dns/testdata/master/master8.data similarity index 100% rename from lib/dns/tests/testdata/master/master8.data rename to tests/dns/testdata/master/master8.data diff --git a/lib/dns/tests/testdata/master/master9.data b/tests/dns/testdata/master/master9.data similarity index 100% rename from lib/dns/tests/testdata/master/master9.data rename to tests/dns/testdata/master/master9.data diff --git a/lib/dns/tests/testdata/nsec3/1024.db b/tests/dns/testdata/nsec3/1024.db similarity index 100% rename from lib/dns/tests/testdata/nsec3/1024.db rename to tests/dns/testdata/nsec3/1024.db diff --git a/lib/dns/tests/testdata/nsec3/2048.db b/tests/dns/testdata/nsec3/2048.db similarity index 100% rename from lib/dns/tests/testdata/nsec3/2048.db rename to tests/dns/testdata/nsec3/2048.db diff --git a/lib/dns/tests/testdata/nsec3/4096.db b/tests/dns/testdata/nsec3/4096.db similarity index 100% rename from lib/dns/tests/testdata/nsec3/4096.db rename to tests/dns/testdata/nsec3/4096.db diff --git a/lib/dns/tests/testdata/nsec3/min-1024.db b/tests/dns/testdata/nsec3/min-1024.db similarity index 100% rename from lib/dns/tests/testdata/nsec3/min-1024.db rename to tests/dns/testdata/nsec3/min-1024.db diff --git a/lib/dns/tests/testdata/nsec3/min-2048.db b/tests/dns/testdata/nsec3/min-2048.db similarity index 100% rename from lib/dns/tests/testdata/nsec3/min-2048.db rename to tests/dns/testdata/nsec3/min-2048.db diff --git a/lib/dns/tests/testdata/nsec3param/nsec3.db.signed b/tests/dns/testdata/nsec3param/nsec3.db.signed similarity index 100% rename from lib/dns/tests/testdata/nsec3param/nsec3.db.signed rename to tests/dns/testdata/nsec3param/nsec3.db.signed diff --git a/lib/dns/tests/testdata/zt/zone1.db b/tests/dns/testdata/zt/zone1.db similarity index 100% rename from lib/dns/tests/testdata/zt/zone1.db rename to tests/dns/testdata/zt/zone1.db diff --git a/lib/dns/tests/testkeys/Kexample.+008+20386.key b/tests/dns/testkeys/Kexample.+008+20386.key similarity index 100% rename from lib/dns/tests/testkeys/Kexample.+008+20386.key rename to tests/dns/testkeys/Kexample.+008+20386.key diff --git a/lib/dns/tests/testkeys/Kexample.+008+20386.private b/tests/dns/testkeys/Kexample.+008+20386.private similarity index 100% rename from lib/dns/tests/testkeys/Kexample.+008+20386.private rename to tests/dns/testkeys/Kexample.+008+20386.private diff --git a/lib/dns/tests/testkeys/Kexample.+008+37464.key b/tests/dns/testkeys/Kexample.+008+37464.key similarity index 100% rename from lib/dns/tests/testkeys/Kexample.+008+37464.key rename to tests/dns/testkeys/Kexample.+008+37464.key diff --git a/lib/dns/tests/testkeys/Kexample.+008+37464.private b/tests/dns/testkeys/Kexample.+008+37464.private similarity index 100% rename from lib/dns/tests/testkeys/Kexample.+008+37464.private rename to tests/dns/testkeys/Kexample.+008+37464.private diff --git a/lib/dns/tests/time_test.c b/tests/dns/time_test.c similarity index 75% rename from lib/dns/tests/time_test.c rename to tests/dns/time_test.c index a1e50f8039..f6e19481f4 100644 --- a/lib/dns/tests/time_test.c +++ b/tests/dns/time_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -29,34 +27,12 @@ #include -#include "dnstest.h" +#include #define TEST_ORIGIN "test" -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} - /* value = 0xfffffffff <-> 19691231235959 */ -static void -epoch_minus_one_test(void **state) { +ISC_RUN_TEST_IMPL(epoch_minus_one) { const char *test_text = "19691231235959"; const uint32_t test_time = 0xffffffff; isc_result_t result; @@ -77,8 +53,7 @@ epoch_minus_one_test(void **state) { } /* value = 0x000000000 <-> 19700101000000*/ -static void -epoch_test(void **state) { +ISC_RUN_TEST_IMPL(epoch) { const char *test_text = "19700101000000"; const uint32_t test_time = 0x00000000; isc_result_t result; @@ -99,8 +74,7 @@ epoch_test(void **state) { } /* value = 0x7fffffff <-> 20380119031407 */ -static void -half_maxint_test(void **state) { +ISC_RUN_TEST_IMPL(half_maxint) { const char *test_text = "20380119031407"; const uint32_t test_time = 0x7fffffff; isc_result_t result; @@ -121,8 +95,7 @@ half_maxint_test(void **state) { } /* value = 0x80000000 <-> 20380119031408 */ -static void -half_plus_one_test(void **state) { +ISC_RUN_TEST_IMPL(half_plus_one) { const char *test_text = "20380119031408"; const uint32_t test_time = 0x80000000; isc_result_t result; @@ -143,8 +116,7 @@ half_plus_one_test(void **state) { } /* value = 0xef68f5d0 <-> 19610307130000 */ -static void -fifty_before_test(void **state) { +ISC_RUN_TEST_IMPL(fifty_before) { isc_result_t result; const char *test_text = "19610307130000"; const uint32_t test_time = 0xef68f5d0; @@ -165,8 +137,7 @@ fifty_before_test(void **state) { } /* value = 0x4d74d6d0 <-> 20110307130000 */ -static void -some_ago_test(void **state) { +ISC_RUN_TEST_IMPL(some_ago) { const char *test_text = "20110307130000"; const uint32_t test_time = 0x4d74d6d0; isc_result_t result; @@ -186,33 +157,13 @@ some_ago_test(void **state) { assert_int_equal(when, test_time); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(epoch_minus_one_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(epoch_test, _setup, _teardown), - cmocka_unit_test_setup_teardown(half_maxint_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(half_plus_one_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(fifty_before_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(some_ago_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(epoch_minus_one) +ISC_TEST_ENTRY(epoch) +ISC_TEST_ENTRY(half_maxint) +ISC_TEST_ENTRY(half_plus_one) +ISC_TEST_ENTRY(fifty_before) +ISC_TEST_ENTRY(some_ago) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/tsig_test.c b/tests/dns/tsig_test.c similarity index 84% rename from lib/dns/tests/tsig_test.c rename to tests/dns/tsig_test.c index 1354ef7dc3..f94a0fa016 100644 --- a/lib/dns/tests/tsig_test.c +++ b/tests/dns/tsig_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -32,42 +30,38 @@ #include #include -#include "../tsig_p.h" -#include "dnstest.h" +#include "tsig_p.h" -#define CHECK(r) \ - do { \ - result = (r); \ - if (result != ISC_R_SUCCESS) { \ - goto cleanup; \ - } \ - } while (0) +#include #define TEST_ORIGIN "test" +static int debug = 0; + static int -_setup(void **state) { +setup_test(void **state) { isc_result_t result; UNUSED(state); - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); + result = dst_lib_init(mctx, NULL); + + if (result != ISC_R_SUCCESS) { + return (1); + } return (0); } static int -_teardown(void **state) { +teardown_test(void **state) { UNUSED(state); - dns_test_end(); + dst_lib_destroy(); return (0); } -static int debug = 0; - static isc_result_t add_mac(dst_context_t *tsigctx, isc_buffer_t *buf) { dns_rdata_any_tsig_t tsig; @@ -111,7 +105,7 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) { memset(&tsig, 0, sizeof(tsig)); - CHECK(dns_compress_init(&cctx, -1, dt_mctx)); + CHECK(dns_compress_init(&cctx, -1, mctx)); invalidate_ctx = true; tsig.common.rdclass = dns_rdataclass_any; @@ -135,13 +129,13 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) { CHECK(dst_context_adddata(tsigctx, &r)); CHECK(dst_key_sigsize(key->key, &sigsize)); - tsig.signature = isc_mem_get(dt_mctx, sigsize); + tsig.signature = isc_mem_get(mctx, sigsize); isc_buffer_init(&sigbuf, tsig.signature, sigsize); CHECK(dst_context_sign(tsigctx, &sigbuf)); tsig.siglen = isc_buffer_usedlength(&sigbuf); assert_int_equal(sigsize, tsig.siglen); - isc_buffer_allocate(dt_mctx, &dynbuf, 512); + isc_buffer_allocate(mctx, &dynbuf, 512); CHECK(dns_rdata_fromstruct(&rdata, dns_rdataclass_any, dns_rdatatype_tsig, &tsig, dynbuf)); dns_rdatalist_init(&rdatalist); @@ -162,7 +156,7 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) { } cleanup: if (tsig.signature != NULL) { - isc_mem_put(dt_mctx, tsig.signature, sigsize); + isc_mem_put(mctx, tsig.signature, sigsize); } if (dynbuf != NULL) { isc_buffer_free(&dynbuf); @@ -186,13 +180,13 @@ printmessage(dns_message_t *msg) { } do { - buf = isc_mem_get(dt_mctx, len); + buf = isc_mem_get(mctx, len); isc_buffer_init(&b, buf, len); result = dns_message_totext(msg, &dns_master_style_debug, 0, &b); if (result == ISC_R_NOSPACE) { - isc_mem_put(dt_mctx, buf, len); + isc_mem_put(mctx, buf, len); len *= 2; } else if (result == ISC_R_SUCCESS) { printf("%.*s\n", (int)isc_buffer_usedlength(&b), buf); @@ -200,7 +194,7 @@ printmessage(dns_message_t *msg) { } while (result == ISC_R_NOSPACE); if (buf != NULL) { - isc_mem_put(dt_mctx, buf, len); + isc_mem_put(mctx, buf, len); } } @@ -211,7 +205,7 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key, dns_compress_t cctx; isc_result_t result; - dns_message_create(dt_mctx, DNS_MESSAGE_INTENTRENDER, &msg); + dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &msg); assert_non_null(msg); msg->id = 50; @@ -238,7 +232,7 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key, assert_int_equal(result, ISC_R_SUCCESS); } - result = dns_compress_init(&cctx, -1, dt_mctx); + result = dns_compress_init(&cctx, -1, mctx); assert_int_equal(result, ISC_R_SUCCESS); result = dns_message_renderbegin(msg, &cctx, buf); @@ -258,7 +252,7 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key, isc_buffer_free(tsigin); } - result = dns_message_getquerytsig(msg, dt_mctx, tsigout); + result = dns_message_getquerytsig(msg, mctx, tsigout); assert_int_equal(result, ISC_R_SUCCESS); } @@ -272,8 +266,7 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key, * and last messages contain TSIGs but the intermediate message doesn't * correctly verifies. */ -static void -tsig_tcp_test(void **state) { +ISC_RUN_TEST_IMPL(tsig_tcp) { const dns_name_t *tsigowner = NULL; dns_fixedname_t fkeyname; dns_message_t *msg = NULL; @@ -297,11 +290,11 @@ tsig_tcp_test(void **state) { result = dns_name_fromstring(keyname, "test", 0, NULL); assert_int_equal(result, ISC_R_SUCCESS); - result = dns_tsigkeyring_create(dt_mctx, &ring); + result = dns_tsigkeyring_create(mctx, &ring); assert_int_equal(result, ISC_R_SUCCESS); result = dns_tsigkey_create(keyname, dns_tsig_hmacsha256_name, secret, - sizeof(secret), false, NULL, 0, 0, dt_mctx, + sizeof(secret), false, NULL, 0, 0, mctx, ring, &key); assert_int_equal(result, ISC_R_SUCCESS); assert_non_null(key); @@ -309,21 +302,21 @@ tsig_tcp_test(void **state) { /* * Create request. */ - isc_buffer_allocate(dt_mctx, &buf, 65535); + isc_buffer_allocate(mctx, &buf, 65535); render(buf, 0, key, &tsigout, &querytsig, NULL); isc_buffer_free(&buf); /* * Create response message 1. */ - isc_buffer_allocate(dt_mctx, &buf, 65535); + isc_buffer_allocate(mctx, &buf, 65535); render(buf, DNS_MESSAGEFLAG_QR, key, &querytsig, &tsigout, NULL); assert_non_null(tsigout); /* * Process response message 1. */ - dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg); + dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg); assert_non_null(msg); result = dns_message_settsigkey(msg, key); @@ -347,7 +340,7 @@ tsig_tcp_test(void **state) { */ assert_non_null(dns_message_gettsig(msg, &tsigowner)); - result = dns_message_getquerytsig(msg, dt_mctx, &tsigin); + result = dns_message_getquerytsig(msg, mctx, &tsigin); assert_int_equal(result, ISC_R_SUCCESS); tsigctx = msg->tsigctx; @@ -355,7 +348,7 @@ tsig_tcp_test(void **state) { isc_buffer_free(&buf); dns_message_detach(&msg); - result = dst_context_create(key->key, dt_mctx, DNS_LOGCATEGORY_DNSSEC, + result = dst_context_create(key->key, mctx, DNS_LOGCATEGORY_DNSSEC, false, 0, &outctx); assert_int_equal(result, ISC_R_SUCCESS); assert_non_null(outctx); @@ -369,7 +362,7 @@ tsig_tcp_test(void **state) { /* * Create response message 2. */ - isc_buffer_allocate(dt_mctx, &buf, 65535); + isc_buffer_allocate(mctx, &buf, 65535); assert_int_equal(result, ISC_R_SUCCESS); render(buf, DNS_MESSAGEFLAG_QR, key, &tsigout, &tsigout, outctx); @@ -377,7 +370,7 @@ tsig_tcp_test(void **state) { /* * Process response message 2. */ - dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg); + dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg); assert_non_null(msg); msg->tcp_continuation = 1; @@ -414,7 +407,7 @@ tsig_tcp_test(void **state) { /* * Create response message 3. */ - isc_buffer_allocate(dt_mctx, &buf, 65535); + isc_buffer_allocate(mctx, &buf, 65535); render(buf, DNS_MESSAGEFLAG_QR, key, &tsigout, &tsigout, outctx); result = add_tsig(outctx, key, buf); @@ -423,7 +416,7 @@ tsig_tcp_test(void **state) { /* * Process response message 3. */ - dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg); + dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg); assert_non_null(msg); msg->tcp_continuation = 1; @@ -455,7 +448,7 @@ tsig_tcp_test(void **state) { isc_buffer_free(&tsigin); } - result = dns_message_getquerytsig(msg, dt_mctx, &tsigin); + result = dns_message_getquerytsig(msg, mctx, &tsigin); assert_int_equal(result, ISC_R_SUCCESS); isc_buffer_free(&buf); @@ -480,8 +473,7 @@ tsig_tcp_test(void **state) { } /* Tests the dns__tsig_algvalid function */ -static void -algvalid_test(void **state) { +ISC_RUN_TEST_IMPL(algvalid) { UNUSED(state); assert_true(dns__tsig_algvalid(DST_ALG_HMACMD5)); @@ -496,8 +488,7 @@ algvalid_test(void **state) { } /* Tests the dns__tsig_algfromname function */ -static void -algfromname_test(void **state) { +ISC_RUN_TEST_IMPL(algfromname) { UNUSED(state); assert_int_equal(dns__tsig_algfromname(DNS_TSIG_HMACMD5_NAME), @@ -532,14 +523,13 @@ static void test_name(const char *name_string, const dns_name_t *expected) { dns_name_t name; dns_name_init(&name, NULL); - assert_int_equal(dns_name_fromstring(&name, name_string, 0, dt_mctx), + assert_int_equal(dns_name_fromstring(&name, name_string, 0, mctx), ISC_R_SUCCESS); assert_ptr_equal(dns__tsig_algnamefromname(&name), expected); - dns_name_free(&name, dt_mctx); + dns_name_free(&name, mctx); } -static void -algnamefromname_test(void **state) { +ISC_RUN_TEST_IMPL(algnamefromname) { UNUSED(state); /* test the standard algorithms */ @@ -558,8 +548,7 @@ algnamefromname_test(void **state) { } /* Tests the dns__tsig_algallocated function */ -static void -algallocated_test(void **state) { +ISC_RUN_TEST_IMPL(algallocated) { UNUSED(state); /* test the standard algorithms */ @@ -577,29 +566,12 @@ algallocated_test(void **state) { assert_true(dns__tsig_algallocated(dns_rootname)); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(tsig_tcp_test, _setup, - _teardown), - cmocka_unit_test(algvalid_test), - cmocka_unit_test(algfromname_test), - cmocka_unit_test_setup_teardown(algnamefromname_test, _setup, - _teardown), - cmocka_unit_test(algallocated_test), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(tsig_tcp, setup_test, teardown_test) +ISC_TEST_ENTRY(algvalid) +ISC_TEST_ENTRY(algfromname) +ISC_TEST_ENTRY_CUSTOM(algnamefromname, setup_test, teardown_test) +ISC_TEST_ENTRY(algallocated) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/update_test.c b/tests/dns/update_test.c similarity index 74% rename from lib/dns/tests/update_test.c rename to tests/dns/update_test.c index affc9e9669..afeaa5ce83 100644 --- a/lib/dns/tests/update_test.c +++ b/tests/dns/update_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -31,39 +29,31 @@ #include #include - -#include "dnstest.h" +#define KEEP_BEFORE /* * Fix the linking order problem for overridden isc_stdtime_get() by making * everything local. This also allows static functions from update.c to be * tested. */ -#include "../update.c" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#undef CHECK +#include "update.c" +#pragma GCC diagnostic pop + +#undef CHECK +#include static int -_setup(void **state) { - isc_result_t result; - +setup_test(void **state) { UNUSED(state); - result = dns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - setenv("TZ", "", 1); return (0); } -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} - static uint32_t mystdtime; static void @@ -83,8 +73,7 @@ isc_stdtime_get(isc_stdtime_t *now) { } /* simple increment by 1 */ -static void -increment_test(void **state) { +ISC_RUN_TEST_IMPL(increment) { uint32_t old = 50; uint32_t serial; @@ -97,8 +86,7 @@ increment_test(void **state) { } /* increment past zero, 0xfffffffff -> 1 */ -static void -increment_past_zero_test(void **state) { +ISC_RUN_TEST_IMPL(increment_past_zero) { uint32_t old = 0xffffffffu; uint32_t serial; @@ -111,8 +99,7 @@ increment_past_zero_test(void **state) { } /* past to unixtime */ -static void -past_to_unix_test(void **state) { +ISC_RUN_TEST_IMPL(past_to_unix) { uint32_t old; uint32_t serial; @@ -128,8 +115,7 @@ past_to_unix_test(void **state) { } /* now to unixtime */ -static void -now_to_unix_test(void **state) { +ISC_RUN_TEST_IMPL(now_to_unix) { uint32_t old; uint32_t serial; @@ -145,8 +131,7 @@ now_to_unix_test(void **state) { } /* future to unixtime */ -static void -future_to_unix_test(void **state) { +ISC_RUN_TEST_IMPL(future_to_unix) { uint32_t old; uint32_t serial; @@ -162,8 +147,7 @@ future_to_unix_test(void **state) { } /* undefined plus 1 to unixtime */ -static void -undefined_plus1_to_unix_test(void **state) { +ISC_RUN_TEST_IMPL(undefined_plus1_to_unix) { uint32_t old; uint32_t serial; @@ -180,8 +164,7 @@ undefined_plus1_to_unix_test(void **state) { } /* undefined minus 1 to unixtime */ -static void -undefined_minus1_to_unix_test(void **state) { +ISC_RUN_TEST_IMPL(undefined_minus1_to_unix) { uint32_t old; uint32_t serial; @@ -198,8 +181,7 @@ undefined_minus1_to_unix_test(void **state) { } /* undefined to unixtime */ -static void -undefined_to_unix_test(void **state) { +ISC_RUN_TEST_IMPL(undefined_to_unix) { uint32_t old; uint32_t serial; @@ -215,8 +197,7 @@ undefined_to_unix_test(void **state) { } /* handle unixtime being zero */ -static void -unixtime_zero_test(void **state) { +ISC_RUN_TEST_IMPL(unixtime_zero) { uint32_t old; uint32_t serial; @@ -232,8 +213,7 @@ unixtime_zero_test(void **state) { } /* past to date */ -static void -past_to_date_test(void **state) { +ISC_RUN_TEST_IMPL(past_to_date) { uint32_t old, serial; dns_updatemethod_t used = dns_updatemethod_none; @@ -251,8 +231,7 @@ past_to_date_test(void **state) { } /* now to date */ -static void -now_to_date_test(void **state) { +ISC_RUN_TEST_IMPL(now_to_date) { uint32_t old; uint32_t serial; dns_updatemethod_t used = dns_updatemethod_none; @@ -287,8 +266,7 @@ now_to_date_test(void **state) { } /* future to date */ -static void -future_to_date_test(void **state) { +ISC_RUN_TEST_IMPL(future_to_date) { uint32_t old; uint32_t serial; dns_updatemethod_t used = dns_updatemethod_none; @@ -313,46 +291,19 @@ future_to_date_test(void **state) { assert_int_equal(dns_updatemethod_increment, used); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(increment_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(increment_past_zero_test, - _setup, _teardown), - cmocka_unit_test_setup_teardown(past_to_unix_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(now_to_unix_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(future_to_unix_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(undefined_to_unix_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(undefined_plus1_to_unix_test, - _setup, _teardown), - cmocka_unit_test_setup_teardown(undefined_minus1_to_unix_test, - _setup, _teardown), - cmocka_unit_test_setup_teardown(unixtime_zero_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(past_to_date_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(now_to_date_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(future_to_date_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(increment, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(increment_past_zero, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(past_to_unix, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(now_to_unix, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(future_to_unix, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(undefined_to_unix, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(undefined_plus1_to_unix, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(undefined_minus1_to_unix, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(unixtime_zero, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(past_to_date, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(now_to_date, setup_test, NULL) +ISC_TEST_ENTRY_CUSTOM(future_to_date, setup_test, NULL) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/zonemgr_test.c b/tests/dns/zonemgr_test.c similarity index 78% rename from lib/dns/tests/zonemgr_test.c rename to tests/dns/zonemgr_test.c index e2f48e62a4..cf1c718ba2 100644 --- a/lib/dns/tests/zonemgr_test.c +++ b/tests/dns/zonemgr_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -33,38 +31,16 @@ #include #include -#include "dnstest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, true); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - dns_test_end(); - - return (0); -} +#include /* create zone manager */ -static void -zonemgr_create(void **state) { +ISC_RUN_TEST_IMPL(dns_zonemgr_create) { dns_zonemgr_t *myzonemgr = NULL; isc_result_t result; UNUSED(state); - result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr, + result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr, &myzonemgr); assert_int_equal(result, ISC_R_SUCCESS); @@ -74,15 +50,14 @@ zonemgr_create(void **state) { } /* manage and release a zone */ -static void -zonemgr_managezone(void **state) { +ISC_RUN_TEST_IMPL(dns_zonemgr_managezone) { dns_zonemgr_t *myzonemgr = NULL; dns_zone_t *zone = NULL; isc_result_t result; UNUSED(state); - result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr, + result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr, &myzonemgr); assert_int_equal(result, ISC_R_SUCCESS); @@ -108,15 +83,14 @@ zonemgr_managezone(void **state) { } /* create and release a zone */ -static void -zonemgr_createzone(void **state) { +ISC_RUN_TEST_IMPL(dns_zonemgr_createzone) { dns_zonemgr_t *myzonemgr = NULL; dns_zone_t *zone = NULL; isc_result_t result; UNUSED(state); - result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr, + result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr, &myzonemgr); assert_int_equal(result, ISC_R_SUCCESS); @@ -134,8 +108,7 @@ zonemgr_createzone(void **state) { } /* manage and release a zone */ -static void -zonemgr_unreachable(void **state) { +ISC_RUN_TEST_IMPL(dns_zonemgr_unreachable) { dns_zonemgr_t *myzonemgr = NULL; dns_zone_t *zone = NULL; isc_sockaddr_t addr1, addr2; @@ -147,7 +120,7 @@ zonemgr_unreachable(void **state) { TIME_NOW(&now); - result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr, + result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr, &myzonemgr); assert_int_equal(result, ISC_R_SUCCESS); @@ -217,30 +190,14 @@ zonemgr_unreachable(void **state) { * - dns_zonemgr_getserialqueryrate */ -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(zonemgr_create, _setup, - _teardown), - cmocka_unit_test_setup_teardown(zonemgr_managezone, _setup, - _teardown), - cmocka_unit_test_setup_teardown(zonemgr_createzone, _setup, - _teardown), - cmocka_unit_test_setup_teardown(zonemgr_unreachable, _setup, - _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY_CUSTOM(dns_zonemgr_create, setup_managers, teardown_managers) +ISC_TEST_ENTRY_CUSTOM(dns_zonemgr_managezone, setup_managers, teardown_managers) +ISC_TEST_ENTRY_CUSTOM(dns_zonemgr_createzone, setup_managers, teardown_managers) +ISC_TEST_ENTRY_CUSTOM(dns_zonemgr_unreachable, setup_managers, + teardown_managers) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/dns/tests/zt_test.c b/tests/dns/zt_test.c similarity index 87% rename from lib/dns/tests/zt_test.c rename to tests/dns/zt_test.c index aa56216cb1..74cbe059a2 100644 --- a/lib/dns/tests/zt_test.c +++ b/tests/dns/zt_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -39,35 +37,30 @@ #include #include -#include "dnstest.h" - -struct args { - void *arg1; - void *arg2; - bool arg3; -}; +#include static int _setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = dns_test_begin(NULL, true); - assert_int_equal(result, ISC_R_SUCCESS); + isc_app_start(); + setup_managers(state); return (0); } static int _teardown(void **state) { - UNUSED(state); - - dns_test_end(); + teardown_managers(state); + isc_app_finish(); return (0); } +struct args { + void *arg1; + void *arg2; + bool arg3; +}; + static isc_result_t count_zone(dns_zone_t *zone, void *uap) { int *nzones = (int *)uap; @@ -122,8 +115,7 @@ start_zone_asyncload(isc_task_t *task, isc_event_t *event) { } /* apply a function to a zone table */ -static void -apply(void **state) { +ISC_RUN_TEST_IMPL(dns_zt_apply) { isc_result_t result; dns_zone_t *zone = NULL; dns_view_t *view = NULL; @@ -157,8 +149,7 @@ apply(void **state) { } /* asynchronous zone load */ -static void -asyncload_zone(void **state) { +ISC_RUN_TEST_IMPL(dns_zt_asyncload_zone) { isc_result_t result; int n; dns_zone_t *zone = NULL; @@ -202,7 +193,7 @@ asyncload_zone(void **state) { args.arg1 = zone; args.arg2 = &done; args.arg3 = false; - isc_app_onrun(dt_mctx, maintask, start_zone_asyncload, &args); + isc_app_onrun(mctx, maintask, start_zone_asyncload, &args); isc_app_run(); while (dns__zone_loadpending(zone) && i++ < 5000) { @@ -224,7 +215,7 @@ asyncload_zone(void **state) { args.arg1 = zone; args.arg2 = &done; args.arg3 = true; - isc_app_onrun(dt_mctx, maintask, start_zone_asyncload, &args); + isc_app_onrun(mctx, maintask, start_zone_asyncload, &args); isc_app_run(); @@ -241,7 +232,7 @@ asyncload_zone(void **state) { args.arg1 = zone; args.arg2 = &done; args.arg3 = false; - isc_app_onrun(dt_mctx, maintask, start_zone_asyncload, &args); + isc_app_onrun(mctx, maintask, start_zone_asyncload, &args); isc_app_run(); @@ -266,8 +257,7 @@ asyncload_zone(void **state) { } /* asynchronous zone table load */ -static void -asyncload_zt(void **state) { +ISC_RUN_TEST_IMPL(dns_zt_asyncload_zt) { isc_result_t result; dns_zone_t *zone1 = NULL, *zone2 = NULL, *zone3 = NULL; dns_view_t *view; @@ -316,7 +306,7 @@ asyncload_zt(void **state) { args.arg1 = zt; args.arg2 = &done; - isc_app_onrun(dt_mctx, maintask, start_zt_asyncload, &args); + isc_app_onrun(mctx, maintask, start_zt_asyncload, &args); isc_app_run(); while (!atomic_load(&done) && i++ < 5000) { @@ -350,27 +340,12 @@ asyncload_zt(void **state) { dns_view_detach(&view); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(apply, _setup, _teardown), - cmocka_unit_test_setup_teardown(asyncload_zone, _setup, - _teardown), - cmocka_unit_test_setup_teardown(asyncload_zt, _setup, - _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY_CUSTOM(dns_zt_apply, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(dns_zt_asyncload_zone, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(dns_zt_asyncload_zt, _setup, _teardown) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/tests/include/tests/.clang-format b/tests/include/tests/.clang-format new file mode 120000 index 0000000000..0e62f72bcf --- /dev/null +++ b/tests/include/tests/.clang-format @@ -0,0 +1 @@ +../../../.clang-format.headers \ No newline at end of file diff --git a/lib/dns/tests/dnstest.h b/tests/include/tests/dns.h similarity index 87% rename from lib/dns/tests/dnstest.h rename to tests/include/tests/dns.h index 1abfd6315e..64a265b660 100644 --- a/lib/dns/tests/dnstest.h +++ b/tests/include/tests/dns.h @@ -28,15 +28,20 @@ #include #include +#include #include #include +#include + +extern dns_zonemgr_t *zonemgr; + typedef struct { dns_diffop_t op; - const char *owner; - dns_ttl_t ttl; - const char *type; - const char *rdata; + const char *owner; + dns_ttl_t ttl; + const char *type; + const char *rdata; } zonechange_t; #define ZONECHANGE_SENTINEL \ @@ -44,25 +49,8 @@ typedef struct { 0, NULL, 0, NULL, NULL \ } -extern isc_mem_t *dt_mctx; -extern isc_log_t *lctx; -extern isc_taskmgr_t *taskmgr; -extern isc_task_t *maintask; -extern isc_timermgr_t *timermgr; -extern isc_nm_t *netmgr; -extern dns_zonemgr_t *zonemgr; -extern bool app_running; -extern int ncpus; -extern bool debug_mem_record; - isc_result_t -dns_test_begin(FILE *logfile, bool create_managers); - -void -dns_test_end(void); - -isc_result_t -dns_test_makeview(const char *name, dns_view_t **viewp); +dns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp); /*% * Create a zone with origin 'name', return a pointer to the zone object in diff --git a/tests/include/tests/isc.h b/tests/include/tests/isc.h new file mode 100644 index 0000000000..38dadb4679 --- /dev/null +++ b/tests/include/tests/isc.h @@ -0,0 +1,119 @@ +/* + * 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. + */ + +#pragma once + +/*! \file */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "netmgr_p.h" +#include "task_p.h" +#include "timer_p.h" + +#define CHECK(r) \ + do { \ + result = (r); \ + if (result != ISC_R_SUCCESS) \ + goto cleanup; \ + } while (0) + +extern isc_mem_t *mctx; +extern isc_nm_t *netmgr; +extern isc_taskmgr_t *taskmgr; +extern isc_timermgr_t *timermgr; +extern unsigned int workers; +extern isc_task_t *maintask; + +#define isc_test_nap(ms) uv_sleep(ms) + +int +setup_managers(void **state); +int +teardown_managers(void **state); + +#ifndef TESTS_DIR +#define TESTS_DIR "./" +#endif + +/* clang-format off */ +/* Copied from cmocka */ +#define ISC_TEST_ENTRY(name) \ + { #name, run_test_##name, NULL, NULL, NULL }, +#define ISC_TEST_ENTRY_SETUP(name) \ + { #name, run_test_##name, setup_test_##name, NULL, NULL }, +#define ISC_TEST_ENTRY_TEARDOWN(name) \ + { #name, run_test_##name, NULL, teardown_test_##name, NULL }, +#define ISC_TEST_ENTRY_SETUP_TEARDOWN(name) \ + { #name, run_test_##name, setup_test_##name, teardown_test_##name, NULL }, +#define ISC_TEST_ENTRY_CUSTOM(name, setup, teardown) \ + { #name, run_test_##name, setup, teardown, NULL }, +/* clang-format on */ + +#define ISC_SETUP_TEST_DECLARE(name) \ + int setup_test_##name(void **state __attribute__((unused))); + +#define ISC_RUN_TEST_DECLARE(name) \ + void run_test_##name(void **state __attribute__((unused))); + +#define ISC_TEARDOWN_TEST_DECLARE(name) \ + int teardown_test_##name(void **state __attribute__((unused))) + +#define ISC_SETUP_TEST_IMPL(name) \ + int setup_test_##name(void **state __attribute__((unused))); \ + int setup_test_##name(void **state __attribute__((unused))) + +#define ISC_RUN_TEST_IMPL(name) \ + void run_test_##name(void **state __attribute__((unused))); \ + void run_test_##name(void **state __attribute__((unused))) + +#define ISC_TEARDOWN_TEST_IMPL(name) \ + int teardown_test_##name(void **state __attribute__((unused))); \ + int teardown_test_##name(void **state __attribute__((unused))) + +#define ISC_TEST_LIST_START const struct CMUnitTest tests[] = { +#define ISC_TEST_LIST_END \ + } \ + ; + +#define ISC_TEST_MAIN ISC_TEST_MAIN_CUSTOM(NULL, NULL) + +#define ISC_TEST_MAIN_CUSTOM(setup, teardown) \ + int main(void) { \ + int r; \ + \ + signal(SIGPIPE, SIG_IGN); \ + \ + isc_mem_debugging |= ISC_MEM_DEBUGRECORD; \ + isc_mem_create(&mctx); \ + \ + r = cmocka_run_group_tests(tests, setup, teardown); \ + \ + isc_mem_destroy(&mctx); \ + \ + return (r); \ + } diff --git a/lib/ns/tests/nstest.h b/tests/include/tests/ns.h similarity index 73% rename from lib/ns/tests/nstest.h rename to tests/include/tests/ns.h index 58e6ebca73..2317e7daee 100644 --- a/lib/ns/tests/nstest.h +++ b/tests/include/tests/ns.h @@ -34,9 +34,11 @@ #include #include +#include + typedef struct ns_test_id { const char *description; - int lineno; + int lineno; } ns_test_id_t; #define NS_TEST_ID(desc) \ @@ -51,56 +53,24 @@ typedef struct ns_test_id { goto cleanup; \ } while (0) -extern isc_mem_t *mctx; -extern isc_log_t *lctx; -extern isc_taskmgr_t *taskmgr; -extern isc_task_t *maintask; -extern isc_timermgr_t *timermgr; -extern dns_zonemgr_t *zonemgr; extern dns_dispatchmgr_t *dispatchmgr; -extern ns_clientmgr_t *clientmgr; +extern ns_clientmgr_t *clientmgr; extern ns_interfacemgr_t *interfacemgr; -extern ns_server_t *sctx; -extern bool app_running; -extern bool debug_mem_record; +extern ns_server_t *sctx; #ifdef NETMGR_TRACE #define FLARG \ - , const char *file __attribute__((unused)), \ + , const char *file __attribute__((unused)), \ unsigned int line __attribute__((unused)), \ - const char *func __attribute__((unused)) + const char *func __attribute__((unused)) #else #define FLARG #endif -isc_result_t -ns_test_begin(FILE *logfile, bool create_managers); - -void -ns_test_end(void); - -/*% - * Create a view. If "with_cache" is set to true, a cache database will - * also be created and attached to the created view. - */ -isc_result_t -ns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp); - -isc_result_t -ns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view, - bool keepview); - -isc_result_t -ns_test_setupzonemgr(void); - -isc_result_t -ns_test_managezone(dns_zone_t *zone); - -void -ns_test_releasezone(dns_zone_t *zone); - -void -ns_test_closezonemgr(void); +int +setup_server(void **state); +int +teardown_server(void **state); /*% * Load data for zone "zonename" from file "filename" and start serving it to @@ -117,9 +87,6 @@ ns_test_serve_zone(const char *zonename, const char *filename, void ns_test_cleanup_zone(void); -void -ns_test_nap(uint32_t usec); - isc_result_t ns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin, const char *testfile); @@ -135,10 +102,10 @@ ns_test_getclient(ns_interface_t *ifp0, bool tcp, ns_client_t **clientp); * Structure containing parameters for ns_test_qctx_create(). */ typedef struct ns_test_qctx_create_params { - const char *qname; + const char *qname; dns_rdatatype_t qtype; - unsigned int qflags; - bool with_cache; + unsigned int qflags; + bool with_cache; } ns_test_qctx_create_params_t; /*% @@ -150,7 +117,7 @@ typedef struct ns_test_qctx_create_params { */ isc_result_t ns_test_qctx_create(const ns_test_qctx_create_params_t *params, - query_ctx_t **qctxp); + query_ctx_t **qctxp); /*% * Destroy a query context created by ns_test_qctx_create(). diff --git a/lib/irs/tests/Makefile.am b/tests/irs/Makefile.am similarity index 100% rename from lib/irs/tests/Makefile.am rename to tests/irs/Makefile.am diff --git a/lib/irs/tests/resconf_test.c b/tests/irs/resconf_test.c similarity index 100% rename from lib/irs/tests/resconf_test.c rename to tests/irs/resconf_test.c diff --git a/lib/irs/tests/testdata/domain.conf b/tests/irs/testdata/domain.conf similarity index 100% rename from lib/irs/tests/testdata/domain.conf rename to tests/irs/testdata/domain.conf diff --git a/lib/irs/tests/testdata/nameserver-v4.conf b/tests/irs/testdata/nameserver-v4.conf similarity index 100% rename from lib/irs/tests/testdata/nameserver-v4.conf rename to tests/irs/testdata/nameserver-v4.conf diff --git a/lib/irs/tests/testdata/nameserver-v6-scoped.conf b/tests/irs/testdata/nameserver-v6-scoped.conf similarity index 100% rename from lib/irs/tests/testdata/nameserver-v6-scoped.conf rename to tests/irs/testdata/nameserver-v6-scoped.conf diff --git a/lib/irs/tests/testdata/nameserver-v6.conf b/tests/irs/testdata/nameserver-v6.conf similarity index 100% rename from lib/irs/tests/testdata/nameserver-v6.conf rename to tests/irs/testdata/nameserver-v6.conf diff --git a/lib/irs/tests/testdata/options-attempts.conf b/tests/irs/testdata/options-attempts.conf similarity index 100% rename from lib/irs/tests/testdata/options-attempts.conf rename to tests/irs/testdata/options-attempts.conf diff --git a/lib/irs/tests/testdata/options-bad-ndots.conf b/tests/irs/testdata/options-bad-ndots.conf similarity index 100% rename from lib/irs/tests/testdata/options-bad-ndots.conf rename to tests/irs/testdata/options-bad-ndots.conf diff --git a/lib/irs/tests/testdata/options-debug.conf b/tests/irs/testdata/options-debug.conf similarity index 100% rename from lib/irs/tests/testdata/options-debug.conf rename to tests/irs/testdata/options-debug.conf diff --git a/lib/irs/tests/testdata/options-empty.conf b/tests/irs/testdata/options-empty.conf similarity index 100% rename from lib/irs/tests/testdata/options-empty.conf rename to tests/irs/testdata/options-empty.conf diff --git a/lib/irs/tests/testdata/options-ndots.conf b/tests/irs/testdata/options-ndots.conf similarity index 100% rename from lib/irs/tests/testdata/options-ndots.conf rename to tests/irs/testdata/options-ndots.conf diff --git a/lib/irs/tests/testdata/options-timeout.conf b/tests/irs/testdata/options-timeout.conf similarity index 100% rename from lib/irs/tests/testdata/options-timeout.conf rename to tests/irs/testdata/options-timeout.conf diff --git a/lib/irs/tests/testdata/options-unknown.conf b/tests/irs/testdata/options-unknown.conf similarity index 100% rename from lib/irs/tests/testdata/options-unknown.conf rename to tests/irs/testdata/options-unknown.conf diff --git a/lib/irs/tests/testdata/options.conf b/tests/irs/testdata/options.conf similarity index 100% rename from lib/irs/tests/testdata/options.conf rename to tests/irs/testdata/options.conf diff --git a/lib/irs/tests/testdata/port.conf b/tests/irs/testdata/port.conf similarity index 100% rename from lib/irs/tests/testdata/port.conf rename to tests/irs/testdata/port.conf diff --git a/lib/irs/tests/testdata/resolv.conf b/tests/irs/testdata/resolv.conf similarity index 100% rename from lib/irs/tests/testdata/resolv.conf rename to tests/irs/testdata/resolv.conf diff --git a/lib/irs/tests/testdata/search.conf b/tests/irs/testdata/search.conf similarity index 100% rename from lib/irs/tests/testdata/search.conf rename to tests/irs/testdata/search.conf diff --git a/lib/irs/tests/testdata/sortlist-v4.conf b/tests/irs/testdata/sortlist-v4.conf similarity index 100% rename from lib/irs/tests/testdata/sortlist-v4.conf rename to tests/irs/testdata/sortlist-v4.conf diff --git a/lib/irs/tests/testdata/timeout.conf b/tests/irs/testdata/timeout.conf similarity index 100% rename from lib/irs/tests/testdata/timeout.conf rename to tests/irs/testdata/timeout.conf diff --git a/lib/irs/tests/testdata/unknown.conf b/tests/irs/testdata/unknown.conf similarity index 100% rename from lib/irs/tests/testdata/unknown.conf rename to tests/irs/testdata/unknown.conf diff --git a/lib/isc/tests/Makefile.am b/tests/isc/Makefile.am similarity index 73% rename from lib/isc/tests/Makefile.am rename to tests/isc/Makefile.am index 07ce59c9a8..6ce570c882 100644 --- a/lib/isc/tests/Makefile.am +++ b/tests/isc/Makefile.am @@ -2,17 +2,12 @@ include $(top_srcdir)/Makefile.top AM_CPPFLAGS += \ $(LIBISC_CFLAGS) \ - -I.. + $(LIBUV_CFLAGS) \ + -I$(top_srcdir)/lib/isc LDADD += \ - libisctest.la \ - $(LIBISC_LIBS) - -check_LTLIBRARIES = libisctest.la -libisctest_la_SOURCES = \ - isctest.c \ - isctest.h \ - uv_wrap.h + $(LIBISC_LIBS) \ + $(LIBUV_LIBS) check_PROGRAMS = \ aes_test \ @@ -51,14 +46,12 @@ check_PROGRAMS += \ doh_test_CPPFLAGS = \ $(AM_CPPFLAGS) \ - $(LIBUV_CFLAGS) \ $(LIBNGHTTP2_CFLAGS) \ $(OPENSSL_CFLAGS) doh_test_LDADD = \ $(LDADD) \ - $(LIBNGHTTP2_LIBS) \ - $(LIBUV_LIBS) + $(LIBNGHTTP2_LIBS) endif HAVE_LIBNGHTTP2 hmac_test_CPPFLAGS = \ @@ -81,14 +74,22 @@ random_test_LDADD = \ $(LDADD) \ -lm -netmgr_test_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - $(LIBUV_CFLAGS) \ - $(OPENSSL_CFLAGS) +task_test_CPPFLAGS = \ + $(AM_CPPFLAGS) + +task_test_LDADD = \ + $(LDADD) + +if HAVE_LIBXML2 +task_test_CPPFLAGS += $(LIBXML2_CFLAGS) +task_test_LDADD += $(LIBXML2_LIBS) +endif HAVE_LIBXML2 + +if HAVE_JSON_C +task_test_CPPFLAGS += $(JSON_C_CFLAGS) +task_test_LDADD += $(JSON_C_LIBS) +endif HAVE_JSON_C -netmgr_test_LDADD = \ - $(LDADD) \ - $(LIBUV_LIBS) EXTRA_DIST = testdata diff --git a/lib/isc/tests/aes_test.c b/tests/isc/aes_test.c similarity index 92% rename from lib/isc/tests/aes_test.c rename to tests/isc/aes_test.c index 4fd09d1829..c328b92b02 100644 --- a/lib/isc/tests/aes_test.c +++ b/tests/isc/aes_test.c @@ -11,8 +11,7 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - +#include /* IWYU pragma: keep */ #include #include #include @@ -30,6 +29,8 @@ #include #include +#include + /* * Test data from NIST KAT */ @@ -77,8 +78,7 @@ typedef struct aes_testcase { } aes_testcase_t; /* AES 128 test vectors */ -static void -isc_aes128_test(void **state) { +ISC_RUN_TEST_IMPL(isc_aes128_test) { aes_testcase_t testcases[] = { /* Test 1 (KAT ECBVarTxt128 #3) */ { "00000000000000000000000000000000", "F0000000000000000000000000000000", @@ -124,8 +124,7 @@ isc_aes128_test(void **state) { } /* AES 192 test vectors */ -static void -isc_aes192_test(void **state) { +ISC_RUN_TEST_IMPL(isc_aes192_test) { aes_testcase_t testcases[] = { /* Test 1 (KAT ECBVarTxt192 #3) */ { "000000000000000000000000000000000000000000000000", @@ -156,8 +155,6 @@ isc_aes192_test(void **state) { aes_testcase_t *testcase = testcases; - UNUSED(state); - while (testcase->key != NULL) { len = fromhexstr(testcase->key, key); assert_int_equal(len, ISC_AES192_KEYLENGTH); @@ -172,8 +169,7 @@ isc_aes192_test(void **state) { } /* AES 256 test vectors */ -static void -isc_aes256_test(void **state) { +ISC_RUN_TEST_IMPL(isc_aes256_test) { aes_testcase_t testcases[] = { /* Test 1 (KAT ECBVarTxt256 #3) */ { "00000000000000000000000000000000" "00000000000000000000000000000000", @@ -224,25 +220,12 @@ isc_aes256_test(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_aes128_test), - cmocka_unit_test(isc_aes192_test), - cmocka_unit_test(isc_aes256_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_aes128_test) +ISC_TEST_ENTRY(isc_aes192_test) +ISC_TEST_ENTRY(isc_aes256_test) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/buffer_test.c b/tests/isc/buffer_test.c similarity index 83% rename from lib/isc/tests/buffer_test.c rename to tests/isc/buffer_test.c index 91eb890155..8335248fa0 100644 --- a/lib/isc/tests/buffer_test.c +++ b/tests/isc/buffer_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include #include /* IWYU pragma: keep */ @@ -34,39 +32,17 @@ #include #include -#include "isctest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} +#include /* reserve space in dynamic buffers */ -static void -isc_buffer_reserve_test(void **state) { +ISC_RUN_TEST_IMPL(isc_buffer_reserve) { isc_result_t result; isc_buffer_t *b; UNUSED(state); b = NULL; - isc_buffer_allocate(test_mctx, &b, 1024); + isc_buffer_allocate(mctx, &b, 1024); assert_int_equal(b->length, 1024); /* @@ -125,8 +101,7 @@ isc_buffer_reserve_test(void **state) { } /* dynamic buffer automatic reallocation */ -static void -isc_buffer_dynamic_test(void **state) { +ISC_RUN_TEST_IMPL(isc_buffer_dynamic) { isc_buffer_t *b; size_t last_length = 10; int i; @@ -134,7 +109,7 @@ isc_buffer_dynamic_test(void **state) { UNUSED(state); b = NULL; - isc_buffer_allocate(test_mctx, &b, last_length); + isc_buffer_allocate(mctx, &b, last_length); assert_non_null(b); assert_int_equal(b->length, last_length); @@ -178,8 +153,7 @@ isc_buffer_dynamic_test(void **state) { } /* copy a region into a buffer */ -static void -isc_buffer_copyregion_test(void **state) { +ISC_RUN_TEST_IMPL(isc_buffer_copyregion) { unsigned char data[] = { 0x11, 0x22, 0x33, 0x44 }; isc_buffer_t *b = NULL; isc_result_t result; @@ -191,7 +165,7 @@ isc_buffer_copyregion_test(void **state) { UNUSED(state); - isc_buffer_allocate(test_mctx, &b, sizeof(data)); + isc_buffer_allocate(mctx, &b, sizeof(data)); /* * Fill originally allocated buffer space. @@ -216,8 +190,7 @@ isc_buffer_copyregion_test(void **state) { } /* sprintf() into a buffer */ -static void -isc_buffer_printf_test(void **state) { +ISC_RUN_TEST_IMPL(isc_buffer_printf) { unsigned int used, prev_used; const char *empty_fmt; isc_result_t result; @@ -230,7 +203,7 @@ isc_buffer_printf_test(void **state) { * Prepare a buffer with auto-reallocation enabled. */ b = NULL; - isc_buffer_allocate(test_mctx, &b, 0); + isc_buffer_allocate(mctx, &b, 0); isc_buffer_setautorealloc(b, true); /* @@ -322,30 +295,13 @@ isc_buffer_printf_test(void **state) { assert_int_equal(used, 7); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(isc_buffer_reserve_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(isc_buffer_dynamic_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(isc_buffer_copyregion_test, - _setup, _teardown), - cmocka_unit_test_setup_teardown(isc_buffer_printf_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_buffer_reserve) +ISC_TEST_ENTRY(isc_buffer_dynamic) +ISC_TEST_ENTRY(isc_buffer_copyregion) +ISC_TEST_ENTRY(isc_buffer_printf) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/counter_test.c b/tests/isc/counter_test.c similarity index 62% rename from lib/isc/tests/counter_test.c rename to tests/isc/counter_test.c index 6a454f888b..065a6f0a3b 100644 --- a/lib/isc/tests/counter_test.c +++ b/tests/isc/counter_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -27,39 +25,17 @@ #include #include -#include "isctest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} +#include /* test isc_counter object */ -static void -isc_counter_test(void **state) { +ISC_RUN_TEST_IMPL(isc_counter) { isc_result_t result; isc_counter_t *counter = NULL; int i; UNUSED(state); - result = isc_counter_create(test_mctx, 0, &counter); + result = isc_counter_create(mctx, 0, &counter); assert_int_equal(result, ISC_R_SUCCESS); for (i = 0; i < 10; i++) { @@ -82,24 +58,10 @@ isc_counter_test(void **state) { isc_counter_detach(&counter); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(isc_counter_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_counter) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/crc64_test.c b/tests/isc/crc64_test.c similarity index 74% rename from lib/isc/tests/crc64_test.c rename to tests/isc/crc64_test.c index 1c4f4f430d..9b8ff47b9e 100644 --- a/lib/isc/tests/crc64_test.c +++ b/tests/isc/crc64_test.c @@ -13,8 +13,7 @@ /* ! \file */ -#if HAVE_CMOCKA - +#include /* IWYU pragma: keep */ #include #include #include @@ -29,21 +28,13 @@ #include #include +#include + #define TEST_INPUT(x) (x), sizeof(x) - 1 -typedef struct hash_testcase { - const char *input; - size_t input_len; - const char *result; - int repeats; -} hash_testcase_t; - -static void -isc_crc64_init_test(void **state) { +ISC_RUN_TEST_IMPL(isc_crc64_init) { uint64_t crc; - UNUSED(state); - isc_crc64_init(&crc); assert_int_equal(crc, 0xffffffffffffffffUL); } @@ -68,10 +59,7 @@ _crc64(const char *buf, size_t buflen, const char *result, const int repeats) { } /* 64-bit cyclic redundancy check */ -static void -isc_crc64_test(void **state) { - UNUSED(state); - +ISC_RUN_TEST_IMPL(isc_crc64) { _crc64(TEST_INPUT(""), "0000000000000000", 1); _crc64(TEST_INPUT("a"), "CE73F427ACC0A99A", 1); _crc64(TEST_INPUT("abc"), "048B813AF9F49702", 1); @@ -85,24 +73,11 @@ isc_crc64_test(void **state) { "81E5EB73C8E7874A", 1); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_crc64_init_test), - cmocka_unit_test(isc_crc64_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_crc64_init) +ISC_TEST_ENTRY(isc_crc64) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/doh_test.c b/tests/isc/doh_test.c similarity index 78% rename from lib/isc/tests/doh_test.c rename to tests/isc/doh_test.c index 84ffc49317..b8c5d1f81f 100644 --- a/lib/isc/tests/doh_test.c +++ b/tests/isc/doh_test.c @@ -11,7 +11,6 @@ * information regarding copyright ownership. */ -#if defined(HAVE_CMOCKA) && defined(HAVE_LIBNGHTTP2) #include #include /* IWYU pragma: keep */ #include @@ -41,11 +40,12 @@ #include "uv_wrap.h" #define KEEP_BEFORE -#include "../netmgr/http.c" -#include "../netmgr/netmgr-int.h" -#include "../netmgr/socket.c" -#include "../netmgr_p.h" -#include "isctest.h" +#include "netmgr/http.c" +#include "netmgr/netmgr-int.h" +#include "netmgr/socket.c" +#include "netmgr_p.h" + +#include #define MAX_NM 2 @@ -68,8 +68,6 @@ static atomic_int_fast64_t total_sends = 0; static atomic_bool was_error = false; -static unsigned int workers = 0; - static bool reuse_supported = true; static bool noanswer = false; @@ -87,6 +85,8 @@ static atomic_bool check_listener_quota = false; static isc_nm_http_endpoints_t *endpoints = NULL; +static bool skip_long_tests = false; + /* Timeout for soft-timeout tests (0.05 seconds) */ #define T_SOFT 50 @@ -113,6 +113,12 @@ static isc_nm_http_endpoints_t *endpoints = NULL; #define X(v) #endif +#define SKIP_IN_CI \ + if (skip_long_tests) { \ + skip(); \ + return; \ + } + typedef struct csdata { isc_nm_recv_cb_t reply_cb; void *cb_arg; @@ -240,39 +246,6 @@ setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) { return (fd); } -static int -_setup(void **state) { - char *p = NULL; - - UNUSED(state); - - if (workers == 0) { - workers = isc_os_ncpus(); - } - p = getenv("ISC_TASK_WORKERS"); - if (p != NULL) { - workers = atoi(p); - } - INSIST(workers != 0); - - if (isc_test_begin(NULL, false, workers) != ISC_R_SUCCESS) { - return (-1); - } - - signal(SIGPIPE, SIG_IGN); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} - /* Generic */ static void @@ -288,9 +261,10 @@ thread_local uint8_t tcp_buffer_storage[4096]; thread_local size_t tcp_buffer_length = 0; static int -nm_setup(void **state) { - size_t nworkers = ISC_MAX(ISC_MIN(workers, 32), 1); - int tcp_listen_sock = -1; +setup_test(void **state) { + char *env_workers = getenv("ISC_TASK_WORKERS"); + size_t nworkers; + uv_os_sock_t tcp_listen_sock = -1; isc_nm_t **nm = NULL; tcp_listen_addr = (isc_sockaddr_t){ .length = 0 }; @@ -301,6 +275,18 @@ nm_setup(void **state) { close(tcp_listen_sock); tcp_listen_sock = -1; + if (env_workers != NULL) { + workers = atoi(env_workers); + } else { + workers = isc_os_ncpus(); + } + INSIST(workers > 0); + nworkers = ISC_MAX(ISC_MIN(workers, 32), 1); + + if (!reuse_supported || getenv("CI") != NULL) { + skip_long_tests = true; + } + atomic_store(&total_sends, NSENDS * NWRITES); atomic_store(&nsends, atomic_load(&total_sends)); @@ -324,9 +310,9 @@ nm_setup(void **state) { return (-1); } - nm = isc_mem_get(test_mctx, MAX_NM * sizeof(nm[0])); + nm = isc_mem_get(mctx, MAX_NM * sizeof(nm[0])); for (size_t i = 0; i < MAX_NM; i++) { - isc__netmgr_create(test_mctx, nworkers, &nm[i]); + isc__netmgr_create(mctx, nworkers, &nm[i]); assert_non_null(nm[i]); } @@ -337,14 +323,14 @@ nm_setup(void **state) { isc_tlsctx_createclient(&client_tlsctx); isc_tlsctx_enable_http2client_alpn(client_tlsctx); client_sess_cache = isc_tlsctx_client_session_cache_new( - test_mctx, client_tlsctx, + mctx, client_tlsctx, ISC_TLSCTX_CLIENT_SESSION_CACHE_DEFAULT_SIZE); isc_quota_init(&listener_quota, 0); atomic_store(&check_listener_quota, false); INSIST(endpoints == NULL); - endpoints = isc_nm_http_endpoints_new(test_mctx); + endpoints = isc_nm_http_endpoints_new(mctx); *state = nm; @@ -352,14 +338,14 @@ nm_setup(void **state) { } static int -nm_teardown(void **state) { +teardown_test(void **state) { isc_nm_t **nm = (isc_nm_t **)*state; for (size_t i = 0; i < MAX_NM; i++) { isc__netmgr_destroy(&nm[i]); assert_null(nm[i]); } - isc_mem_put(test_mctx, nm, MAX_NM * sizeof(nm[0])); + isc_mem_put(mctx, nm, MAX_NM * sizeof(nm[0])); if (server_tlsctx != NULL) { isc_tlsctx_free(&server_tlsctx); @@ -468,8 +454,7 @@ doh_receive_request_cb(isc_nmhandle_t *handle, isc_result_t eresult, } } -static void -mock_doh_uv_tcp_bind(void **state) { +ISC_RUN_TEST_IMPL(mock_doh_uv_tcp_bind) { isc_nm_t **nm = (isc_nm_t **)*state; isc_nm_t *listen_nm = nm[0]; isc_result_t result = ISC_R_SUCCESS; @@ -526,14 +511,12 @@ doh_noop(void **state) { assert_int_equal(0, atomic_load(&ssends)); } -static void -doh_noop_POST(void **state) { +ISC_RUN_TEST_IMPL(doh_noop_POST) { atomic_store(&POST, true); doh_noop(state); } -static void -doh_noop_GET(void **state) { +ISC_RUN_TEST_IMPL(doh_noop_GET) { atomic_store(&POST, false); doh_noop(state); } @@ -569,14 +552,12 @@ doh_noresponse(void **state) { isc__netmgr_shutdown(connect_nm); } -static void -doh_noresponse_POST(void **state) { +ISC_RUN_TEST_IMPL(doh_noresponse_POST) { atomic_store(&POST, true); doh_noresponse(state); } -static void -doh_noresponse_GET(void **state) { +ISC_RUN_TEST_IMPL(doh_noresponse_GET) { atomic_store(&POST, false); doh_noresponse(state); } @@ -682,7 +663,7 @@ doh_timeout_recovery(void **state) { if (atomic_load(&ctimeouts) == 5) { break; } - isc_test_nap(1000); + isc_test_nap(1); } assert_true(atomic_load(&ctimeouts) == 5); @@ -692,14 +673,16 @@ doh_timeout_recovery(void **state) { isc__netmgr_shutdown(connect_nm); } -static void -doh_timeout_recovery_POST(void **state) { +ISC_RUN_TEST_IMPL(doh_timeout_recovery_POST) { + SKIP_IN_CI; + atomic_store(&POST, true); doh_timeout_recovery(state); } -static void -doh_timeout_recovery_GET(void **state) { +ISC_RUN_TEST_IMPL(doh_timeout_recovery_GET) { + SKIP_IN_CI; + atomic_store(&POST, false); doh_timeout_recovery(state); } @@ -753,7 +736,7 @@ doh_connect_thread(isc_threadarg_t arg) { */ int_fast64_t active = atomic_fetch_add(&active_cconnects, 1); if (atomic_load(&slowdown) || active > workers) { - isc_test_nap(1000 * (active - workers)); + isc_test_nap(active - workers); atomic_store(&slowdown, false); } connect_send_request( @@ -833,56 +816,64 @@ doh_recv_one(void **state) { assert_int_equal(atomic_load(&ssends), 1); } -static void -doh_recv_one_POST(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_one_POST) { + SKIP_IN_CI; + atomic_store(&POST, true); doh_recv_one(state); } -static void -doh_recv_one_GET(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_one_GET) { + SKIP_IN_CI; + atomic_store(&POST, false); doh_recv_one(state); } -static void -doh_recv_one_POST_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_one_POST_TLS) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, true); doh_recv_one(state); } -static void -doh_recv_one_GET_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_one_GET_TLS) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, false); doh_recv_one(state); } -static void -doh_recv_one_POST_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_one_POST_quota) { + SKIP_IN_CI; + atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_recv_one(state); } -static void -doh_recv_one_GET_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_one_GET_quota) { + SKIP_IN_CI; + atomic_store(&POST, false); atomic_store(&check_listener_quota, true); doh_recv_one(state); } -static void -doh_recv_one_POST_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_one_POST_TLS_quota) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_recv_one(state); } -static void -doh_recv_one_GET_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_one_GET_TLS_quota) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, false); atomic_store(&check_listener_quota, true); @@ -988,56 +979,64 @@ doh_recv_two(void **state) { assert_int_equal(atomic_load(&ssends), 2); } -static void -doh_recv_two_POST(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_two_POST) { + SKIP_IN_CI; + atomic_store(&POST, true); doh_recv_two(state); } -static void -doh_recv_two_GET(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_two_GET) { + SKIP_IN_CI; + atomic_store(&POST, false); doh_recv_two(state); } -static void -doh_recv_two_POST_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_two_POST_TLS) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, true); doh_recv_two(state); } -static void -doh_recv_two_GET_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_two_GET_TLS) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, false); doh_recv_two(state); } -static void -doh_recv_two_POST_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_two_POST_quota) { + SKIP_IN_CI; + atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_recv_two(state); } -static void -doh_recv_two_GET_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_two_GET_quota) { + SKIP_IN_CI; + atomic_store(&POST, false); atomic_store(&check_listener_quota, true); doh_recv_two(state); } -static void -doh_recv_two_POST_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_two_POST_TLS_quota) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_recv_two(state); } -static void -doh_recv_two_GET_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_two_GET_TLS_quota) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, false); atomic_store(&check_listener_quota, true); @@ -1074,7 +1073,7 @@ doh_recv_send(void **state) { if (atomic_load(&was_error)) { break; } - isc_test_nap(100); + isc_test_nap(1); } for (size_t i = 0; i < nthreads; i++) { @@ -1098,56 +1097,64 @@ doh_recv_send(void **state) { CHECK_RANGE_FULL(ssends); } -static void -doh_recv_send_POST(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_send_POST) { + SKIP_IN_CI; + atomic_store(&POST, true); doh_recv_send(state); } -static void -doh_recv_send_GET(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_send_GET) { + SKIP_IN_CI; + atomic_store(&POST, false); doh_recv_send(state); } -static void -doh_recv_send_POST_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_send_POST_TLS) { + SKIP_IN_CI; + atomic_store(&POST, true); atomic_store(&use_TLS, true); doh_recv_send(state); } -static void -doh_recv_send_GET_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_send_GET_TLS) { + SKIP_IN_CI; + atomic_store(&POST, false); atomic_store(&use_TLS, true); doh_recv_send(state); } -static void -doh_recv_send_POST_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_send_POST_quota) { + SKIP_IN_CI; + atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_recv_send(state); } -static void -doh_recv_send_GET_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_send_GET_quota) { + SKIP_IN_CI; + atomic_store(&POST, false); atomic_store(&check_listener_quota, true); doh_recv_send(state); } -static void -doh_recv_send_POST_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_send_POST_TLS_quota) { + SKIP_IN_CI; + atomic_store(&POST, true); atomic_store(&use_TLS, true); atomic_store(&check_listener_quota, true); doh_recv_send(state); } -static void -doh_recv_send_GET_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_send_GET_TLS_quota) { + SKIP_IN_CI; + atomic_store(&POST, false); atomic_store(&use_TLS, true); atomic_store(&check_listener_quota, true); @@ -1209,56 +1216,64 @@ doh_recv_half_send(void **state) { CHECK_RANGE_HALF(ssends); } -static void -doh_recv_half_send_POST(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_half_send_POST) { + SKIP_IN_CI; + atomic_store(&POST, true); doh_recv_half_send(state); } -static void -doh_recv_half_send_GET(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_half_send_GET) { + SKIP_IN_CI; + atomic_store(&POST, false); doh_recv_half_send(state); } -static void -doh_recv_half_send_POST_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_half_send_POST_TLS) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, true); doh_recv_half_send(state); } -static void -doh_recv_half_send_GET_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_half_send_GET_TLS) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, false); doh_recv_half_send(state); } -static void -doh_recv_half_send_POST_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_half_send_POST_quota) { + SKIP_IN_CI; + atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_recv_half_send(state); } -static void -doh_recv_half_send_GET_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_half_send_GET_quota) { + SKIP_IN_CI; + atomic_store(&POST, false); atomic_store(&check_listener_quota, true); doh_recv_half_send(state); } -static void -doh_recv_half_send_POST_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_half_send_POST_TLS_quota) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_recv_half_send(state); } -static void -doh_recv_half_send_GET_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_recv_half_send_GET_TLS_quota) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, false); atomic_store(&check_listener_quota, true); @@ -1320,56 +1335,64 @@ doh_half_recv_send(void **state) { CHECK_RANGE_HALF(ssends); } -static void -doh_half_recv_send_POST(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_send_POST) { + SKIP_IN_CI; + atomic_store(&POST, true); doh_half_recv_send(state); } -static void -doh_half_recv_send_GET(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_send_GET) { + SKIP_IN_CI; + atomic_store(&POST, false); doh_half_recv_send(state); } -static void -doh_half_recv_send_POST_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_send_POST_TLS) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, true); doh_half_recv_send(state); } -static void -doh_half_recv_send_GET_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_send_GET_TLS) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, false); doh_half_recv_send(state); } -static void -doh_half_recv_send_POST_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_send_POST_quota) { + SKIP_IN_CI; + atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_half_recv_send(state); } -static void -doh_half_recv_send_GET_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_send_GET_quota) { + SKIP_IN_CI; + atomic_store(&POST, false); atomic_store(&check_listener_quota, true); doh_half_recv_send(state); } -static void -doh_half_recv_send_POST_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_send_POST_TLS_quota) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_half_recv_send(state); } -static void -doh_half_recv_send_GET_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_send_GET_TLS_quota) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, false); atomic_store(&check_listener_quota, true); @@ -1430,56 +1453,64 @@ doh_half_recv_half_send(void **state) { CHECK_RANGE_HALF(ssends); } -static void -doh_half_recv_half_send_POST(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_half_send_POST) { + SKIP_IN_CI; + atomic_store(&POST, true); doh_half_recv_half_send(state); } -static void -doh_half_recv_half_send_GET(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_half_send_GET) { + SKIP_IN_CI; + atomic_store(&POST, false); doh_half_recv_half_send(state); } -static void -doh_half_recv_half_send_POST_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_half_send_POST_TLS) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, true); doh_half_recv_half_send(state); } -static void -doh_half_recv_half_send_GET_TLS(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_half_send_GET_TLS) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, false); doh_half_recv_half_send(state); } -static void -doh_half_recv_half_send_POST_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_half_send_POST_quota) { + SKIP_IN_CI; + atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_half_recv_half_send(state); } -static void -doh_half_recv_half_send_GET_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_half_send_GET_quota) { + SKIP_IN_CI; + atomic_store(&POST, false); atomic_store(&check_listener_quota, true); doh_half_recv_half_send(state); } -static void -doh_half_recv_half_send_POST_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_half_send_POST_TLS_quota) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, true); atomic_store(&check_listener_quota, true); doh_half_recv_half_send(state); } -static void -doh_half_recv_half_send_GET_TLS_quota(void **state) { +ISC_RUN_TEST_IMPL(doh_half_recv_half_send_GET_TLS_quota) { + SKIP_IN_CI; + atomic_store(&use_TLS, true); atomic_store(&POST, false); atomic_store(&check_listener_quota, true); @@ -1487,8 +1518,7 @@ doh_half_recv_half_send_GET_TLS_quota(void **state) { } /* See: GL #2858, !5319 */ -static void -doh_bad_connect_uri(void **state) { +ISC_RUN_TEST_IMPL(doh_bad_connect_uri) { isc_nm_t **nm = (isc_nm_t **)*state; isc_nm_t *listen_nm = nm[0]; isc_nm_t *connect_nm = nm[1]; @@ -1548,8 +1578,7 @@ doh_bad_connect_uri(void **state) { assert_int_equal(atomic_load(&ssends), 0); } -static void -doh_parse_GET_query_string(void **state) { +ISC_RUN_TEST_IMPL(doh_parse_GET_query_string) { UNUSED(state); /* valid */ { @@ -1771,8 +1800,7 @@ doh_parse_GET_query_string(void **state) { } } -static void -doh_base64url_to_base64(void **state) { +ISC_RUN_TEST_IMPL(doh_base64url_to_base64) { UNUSED(state); char *res; size_t res_len = 0; @@ -1781,90 +1809,90 @@ doh_base64url_to_base64(void **state) { char test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4"; char res_test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4="; - res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test), + res = isc__nm_base64url_to_base64(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char test[] = "YW55IGNhcm5hbCBwbGVhcw"; char res_test[] = "YW55IGNhcm5hbCBwbGVhcw=="; - res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test), + res = isc__nm_base64url_to_base64(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char test[] = "YW55IGNhcm5hbCBwbGVhc3Vy"; char res_test[] = "YW55IGNhcm5hbCBwbGVhc3Vy"; - res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test), + res = isc__nm_base64url_to_base64(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char test[] = "YW55IGNhcm5hbCBwbGVhc3U"; char res_test[] = "YW55IGNhcm5hbCBwbGVhc3U="; - res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test), + res = isc__nm_base64url_to_base64(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char test[] = "YW55IGNhcm5hbCBwbGVhcw"; char res_test[] = "YW55IGNhcm5hbCBwbGVhcw=="; - res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test), + res = isc__nm_base64url_to_base64(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char test[] = "PDw_Pz8-Pg"; char res_test[] = "PDw/Pz8+Pg=="; - res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test), + res = isc__nm_base64url_to_base64(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char test[] = "PDw_Pz8-Pg"; char res_test[] = "PDw/Pz8+Pg=="; - res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test), + res = isc__nm_base64url_to_base64(mctx, test, strlen(test), NULL); assert_non_null(res); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* invalid */ { char test[] = "YW55IGNhcm5hbCBwbGVhcw"; res_len = 0; - res = isc__nm_base64url_to_base64(test_mctx, test, 0, &res_len); + res = isc__nm_base64url_to_base64(mctx, test, 0, &res_len); assert_null(res); assert_true(res_len == 0); } @@ -1873,7 +1901,7 @@ doh_base64url_to_base64(void **state) { char test[] = ""; res_len = 0; - res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test), + res = isc__nm_base64url_to_base64(mctx, test, strlen(test), &res_len); assert_null(res); assert_true(res_len == 0); @@ -1883,7 +1911,7 @@ doh_base64url_to_base64(void **state) { char test[] = "PDw_Pz8-Pg=="; res_len = 0; - res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test), + res = isc__nm_base64url_to_base64(mctx, test, strlen(test), &res_len); assert_null(res); assert_true(res_len == 0); @@ -1894,7 +1922,7 @@ doh_base64url_to_base64(void **state) { end */ res_len = 0; - res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test), + res = isc__nm_base64url_to_base64(mctx, test, strlen(test), &res_len); assert_null(res); assert_true(res_len == 0); @@ -1903,15 +1931,13 @@ doh_base64url_to_base64(void **state) { { res_len = 0; - res = isc__nm_base64url_to_base64(test_mctx, NULL, 31231, - &res_len); + res = isc__nm_base64url_to_base64(mctx, NULL, 31231, &res_len); assert_null(res); assert_true(res_len == 0); } } -static void -doh_base64_to_base64url(void **state) { +ISC_RUN_TEST_IMPL(doh_base64_to_base64url) { char *res; size_t res_len = 0; UNUSED(state); @@ -1920,90 +1946,90 @@ doh_base64_to_base64url(void **state) { char res_test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4"; char test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4="; - res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test), + res = isc__nm_base64_to_base64url(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char res_test[] = "YW55IGNhcm5hbCBwbGVhcw"; char test[] = "YW55IGNhcm5hbCBwbGVhcw=="; - res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test), + res = isc__nm_base64_to_base64url(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char res_test[] = "YW55IGNhcm5hbCBwbGVhc3Vy"; char test[] = "YW55IGNhcm5hbCBwbGVhc3Vy"; - res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test), + res = isc__nm_base64_to_base64url(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char res_test[] = "YW55IGNhcm5hbCBwbGVhc3U"; char test[] = "YW55IGNhcm5hbCBwbGVhc3U="; - res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test), + res = isc__nm_base64_to_base64url(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char res_test[] = "YW55IGNhcm5hbCBwbGVhcw"; char test[] = "YW55IGNhcm5hbCBwbGVhcw=="; - res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test), + res = isc__nm_base64_to_base64url(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char res_test[] = "PDw_Pz8-Pg"; char test[] = "PDw/Pz8+Pg=="; - res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test), + res = isc__nm_base64_to_base64url(mctx, test, strlen(test), &res_len); assert_non_null(res); assert_true(res_len == strlen(res_test)); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* valid */ { char res_test[] = "PDw_Pz8-Pg"; char test[] = "PDw/Pz8+Pg=="; - res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test), + res = isc__nm_base64_to_base64url(mctx, test, strlen(test), NULL); assert_non_null(res); assert_true(strcmp(res, res_test) == 0); - isc_mem_free(test_mctx, res); + isc_mem_free(mctx, res); } /* invalid */ { char test[] = "YW55IGNhcm5hbCBwbGVhcw"; res_len = 0; - res = isc__nm_base64_to_base64url(test_mctx, test, 0, &res_len); + res = isc__nm_base64_to_base64url(mctx, test, 0, &res_len); assert_null(res); assert_true(res_len == 0); } @@ -2012,7 +2038,7 @@ doh_base64_to_base64url(void **state) { char test[] = ""; res_len = 0; - res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test), + res = isc__nm_base64_to_base64url(mctx, test, strlen(test), &res_len); assert_null(res); assert_true(res_len == 0); @@ -2022,7 +2048,7 @@ doh_base64_to_base64url(void **state) { char test[] = "PDw_Pz8-Pg=="; res_len = 0; - res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test), + res = isc__nm_base64_to_base64url(mctx, test, strlen(test), &res_len); assert_null(res); assert_true(res_len == 0); @@ -2033,7 +2059,7 @@ doh_base64_to_base64url(void **state) { end */ res_len = 0; - res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test), + res = isc__nm_base64_to_base64url(mctx, test, strlen(test), &res_len); assert_null(res); assert_true(res_len == 0); @@ -2042,15 +2068,13 @@ doh_base64_to_base64url(void **state) { { res_len = 0; - res = isc__nm_base64_to_base64url(test_mctx, NULL, 31231, - &res_len); + res = isc__nm_base64_to_base64url(mctx, NULL, 31231, &res_len); assert_null(res); assert_true(res_len == 0); } } -static void -doh_path_validation(void **state) { +ISC_RUN_TEST_IMPL(doh_path_validation) { UNUSED(state); assert_true(isc_nm_http_path_isvalid("/")); @@ -2084,8 +2108,7 @@ doh_path_validation(void **state) { assert_true(isc_nm_http_path_isvalid("/123")); } -static void -doh_connect_makeuri(void **state) { +ISC_RUN_TEST_IMPL(doh_connect_makeuri) { struct in_addr localhostv4 = { .s_addr = ntohl(INADDR_LOOPBACK) }; isc_sockaddr_t sa; char uri[256]; @@ -2210,195 +2233,78 @@ doh_connect_makeuri(void **state) { assert_true(strcmp("https://[::1]:44343/dns-query", uri) == 0); } -int -main(void) { - const struct CMUnitTest tests_short[] = { - cmocka_unit_test_setup_teardown(mock_doh_uv_tcp_bind, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_parse_GET_query_string, - NULL, NULL), - cmocka_unit_test_setup_teardown(doh_base64url_to_base64, NULL, - NULL), - cmocka_unit_test_setup_teardown(doh_base64_to_base64url, NULL, - NULL), - cmocka_unit_test_setup_teardown(doh_path_validation, NULL, - NULL), - cmocka_unit_test_setup_teardown(doh_connect_makeuri, NULL, - NULL), - cmocka_unit_test_setup_teardown(doh_noop_POST, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_noop_GET, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_noresponse_POST, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_noresponse_GET, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_bad_connect_uri, nm_setup, - nm_teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(mock_doh_uv_tcp_bind, setup_test, teardown_test) +ISC_TEST_ENTRY(doh_parse_GET_query_string) +ISC_TEST_ENTRY(doh_base64url_to_base64) +ISC_TEST_ENTRY(doh_base64_to_base64url) +ISC_TEST_ENTRY(doh_path_validation) +ISC_TEST_ENTRY(doh_connect_makeuri) +ISC_TEST_ENTRY_CUSTOM(doh_noop_POST, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_noop_GET, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_noresponse_POST, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_noresponse_GET, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_timeout_recovery_POST, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_timeout_recovery_GET, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST_TLS, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET_TLS, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST_TLS_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET_TLS_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST_TLS, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET_TLS, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST_TLS_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET_TLS_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET_TLS, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST_TLS, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET_TLS_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST_TLS_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_GET, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_POST, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_GET_TLS, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_POST_TLS, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_GET_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_POST_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_GET_TLS_quota, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_POST_TLS_quota, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_GET, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_POST, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_GET_TLS, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_POST_TLS, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_GET_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_POST_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_GET_TLS_quota, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_POST_TLS_quota, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_GET, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_POST, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_GET_TLS, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_POST_TLS, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_GET_quota, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_POST_quota, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_GET_TLS_quota, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_POST_TLS_quota, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(doh_bad_connect_uri, setup_test, teardown_test) +ISC_TEST_LIST_END - const struct CMUnitTest tests_long[] = { - cmocka_unit_test_setup_teardown(mock_doh_uv_tcp_bind, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_parse_GET_query_string, - NULL, NULL), - cmocka_unit_test_setup_teardown(doh_base64url_to_base64, NULL, - NULL), - cmocka_unit_test_setup_teardown(doh_base64_to_base64url, NULL, - NULL), - cmocka_unit_test_setup_teardown(doh_path_validation, NULL, - NULL), - cmocka_unit_test_setup_teardown(doh_connect_makeuri, NULL, - NULL), - cmocka_unit_test_setup_teardown(doh_noop_POST, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_noop_GET, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_noresponse_POST, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_noresponse_GET, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_timeout_recovery_POST, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_timeout_recovery_GET, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_one_POST, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_one_GET, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_one_POST_TLS, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_one_GET_TLS, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_one_POST_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_one_GET_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_one_POST_TLS_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_one_GET_TLS_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_two_POST, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_two_GET, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_two_POST_TLS, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_two_GET_TLS, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_two_POST_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_two_GET_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_two_POST_TLS_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_two_GET_TLS_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_send_GET, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_send_POST, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_send_GET_TLS, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_send_POST_TLS, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_send_GET_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_send_POST_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_send_GET_TLS_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_send_POST_TLS_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_half_send_GET, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_half_send_POST, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_half_send_GET_TLS, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_half_send_POST_TLS, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_half_send_GET_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_recv_half_send_POST_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown( - doh_recv_half_send_GET_TLS_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - doh_recv_half_send_POST_TLS_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_half_recv_send_GET, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_half_recv_send_POST, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_half_recv_send_GET_TLS, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_half_recv_send_POST_TLS, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_half_recv_send_GET_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_half_recv_send_POST_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown( - doh_half_recv_send_GET_TLS_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - doh_half_recv_send_POST_TLS_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_half_recv_half_send_GET, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_half_recv_half_send_POST, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(doh_half_recv_half_send_GET_TLS, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown( - doh_half_recv_half_send_POST_TLS, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - doh_half_recv_half_send_GET_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - doh_half_recv_half_send_POST_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - doh_half_recv_half_send_GET_TLS_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - doh_half_recv_half_send_POST_TLS_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(doh_bad_connect_uri, nm_setup, - nm_teardown), - }; - int result = 0; - -#if OPENSSL_VERSION_NUMBER < 0x10100000L - UNUSED(tests_long); - result = (cmocka_run_group_tests(tests_short, _setup, _teardown)); -#else - if (getenv("CI") != NULL || !reuse_supported) { - result = (cmocka_run_group_tests(tests_short, _setup, - _teardown)); - } else { - result = - (cmocka_run_group_tests(tests_long, _setup, _teardown)); - } -#endif - return result; -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { -#if HAVE_LIBNGHTTP2 - printf("1..0 # Skipped: cmocka not available\n"); -#else - printf("1..0 # Skipped: libnghttp2 is not available\n"); -#endif - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/errno_test.c b/tests/isc/errno_test.c similarity index 86% rename from lib/isc/tests/errno_test.c rename to tests/isc/errno_test.c index 56da65125a..11d48fa8f5 100644 --- a/lib/isc/tests/errno_test.c +++ b/tests/isc/errno_test.c @@ -11,9 +11,8 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include +#include /* IWYU pragma: keep */ #include #include #include @@ -27,6 +26,8 @@ #include #include +#include + typedef struct { int err; isc_result_t result; @@ -87,13 +88,10 @@ testpair_t testpair[] = { { EPERM, ISC_R_NOPERM }, { 0, ISC_R_UNEXPECTED } }; /* convert errno to ISC result */ -static void -isc_errno_toresult_test(void **state) { +ISC_RUN_TEST_IMPL(isc_errno_toresult) { isc_result_t result, expect; size_t i; - UNUSED(state); - for (i = 0; i < sizeof(testpair) / sizeof(testpair[0]); i++) { result = isc_errno_toresult(testpair[i].err); expect = testpair[i].result; @@ -101,23 +99,10 @@ isc_errno_toresult_test(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_errno_toresult_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_errno_toresult) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/file_test.c b/tests/isc/file_test.c similarity index 87% rename from lib/isc/tests/file_test.c rename to tests/isc/file_test.c index 0169f2951e..39670b57eb 100644 --- a/lib/isc/tests/file_test.c +++ b/tests/isc/file_test.c @@ -11,9 +11,8 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include +#include /* IWYU pragma: keep */ #include #include #include @@ -28,6 +27,8 @@ #include #include +#include + #define NAME "internal" #define SHA "3bed2cb3a3acf7b6a8ef408420cc682d5520e26976d354254f528c965612054f" #define TRUNC_SHA "3bed2cb3a3acf7b6" @@ -52,8 +53,7 @@ touch(const char *filename) { } /* test sanitized filenames */ -static void -isc_file_sanitize_test(void **state) { +ISC_RUN_TEST_IMPL(isc_file_sanitize) { isc_result_t result; char buf[1024]; @@ -88,8 +88,7 @@ isc_file_sanitize_test(void **state) { } /* test filename templates */ -static void -isc_file_template_test(void **state) { +ISC_RUN_TEST_IMPL(isc_file_template) { isc_result_t result; char buf[1024]; @@ -131,24 +130,11 @@ isc_file_template_test(void **state) { assert_string_equal(buf, "file-XXXXXXXX"); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_file_sanitize_test), - cmocka_unit_test(isc_file_template_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_file_sanitize) +ISC_TEST_ENTRY(isc_file_template) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/hash_test.c b/tests/isc/hash_test.c similarity index 76% rename from lib/isc/tests/hash_test.c rename to tests/isc/hash_test.c index daa6aee718..10a8c27e58 100644 --- a/lib/isc/tests/hash_test.c +++ b/tests/isc/hash_test.c @@ -11,9 +11,8 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include +#include /* IWYU pragma: keep */ #include #include #include @@ -33,11 +32,10 @@ #include #include -#define TEST_INPUT(x) (x), sizeof(x) - 1 +#include -/*Hash function test */ -static void -isc_hash_function_test(void **state) { +/* Hash function test */ +ISC_RUN_TEST_IMPL(isc_hash_function) { unsigned int h1; unsigned int h2; @@ -69,8 +67,7 @@ isc_hash_function_test(void **state) { } /* Hash function initializer test */ -static void -isc_hash_initializer_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hash_initializer) { unsigned int h1; unsigned int h2; @@ -89,24 +86,11 @@ isc_hash_initializer_test(void **state) { assert_int_equal(h1, h2); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_hash_function_test), - cmocka_unit_test(isc_hash_initializer_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_hash_function) +ISC_TEST_ENTRY(isc_hash_initializer) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/heap_test.c b/tests/isc/heap_test.c similarity index 62% rename from lib/isc/tests/heap_test.c rename to tests/isc/heap_test.c index 5c41b20d32..9e29a4b812 100644 --- a/lib/isc/tests/heap_test.c +++ b/tests/isc/heap_test.c @@ -13,8 +13,6 @@ /* ! \file */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -29,28 +27,7 @@ #include #include -#include "isctest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} +#include struct e { unsigned int value; @@ -73,14 +50,13 @@ idx(void *p, unsigned int i) { } /* test isc_heap_delete() */ -static void -isc_heap_delete_test(void **state) { +ISC_RUN_TEST_IMPL(isc_heap_delete) { isc_heap_t *heap = NULL; struct e e1 = { 100, 0 }; UNUSED(state); - isc_heap_create(test_mctx, compare, idx, 0, &heap); + isc_heap_create(mctx, compare, idx, 0, &heap); assert_non_null(heap); isc_heap_insert(heap, &e1); @@ -93,23 +69,10 @@ isc_heap_delete_test(void **state) { assert_null(heap); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_heap_delete_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} +ISC_TEST_ENTRY(isc_heap_delete) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/hmac_test.c b/tests/isc/hmac_test.c similarity index 94% rename from lib/isc/tests/hmac_test.c rename to tests/isc/hmac_test.c index 2dbeff6b84..ac567d6884 100644 --- a/lib/isc/tests/hmac_test.c +++ b/tests/isc/hmac_test.c @@ -13,8 +13,6 @@ /* ! \file */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -31,7 +29,9 @@ #include #include -#include "../hmac.c" +#include "hmac.c" + +#include #define TEST_INPUT(x) (x), sizeof(x) - 1 @@ -65,8 +65,7 @@ _reset(void **state) { return (0); } -static void -isc_hmac_new_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_new) { UNUSED(state); isc_hmac_t *hmac = isc_hmac_new(); @@ -74,8 +73,7 @@ isc_hmac_new_test(void **state) { isc_hmac_free(hmac); /* Cleanup */ } -static void -isc_hmac_free_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_free) { UNUSED(state); isc_hmac_t *hmac = isc_hmac_new(); @@ -87,13 +85,13 @@ isc_hmac_free_test(void **state) { static void isc_hmac_test(isc_hmac_t *hmac, const void *key, size_t keylen, const isc_md_type_t *type, const char *buf, size_t buflen, - const char *result, const int repeats) { + const char *result, const size_t repeats) { + isc_result_t res; + assert_non_null(hmac); assert_int_equal(isc_hmac_init(hmac, key, keylen, type), ISC_R_SUCCESS); - int i; - - for (i = 0; i < repeats; i++) { + for (size_t i = 0; i < repeats; i++) { assert_int_equal(isc_hmac_update(hmac, (const unsigned char *)buf, buflen), @@ -110,14 +108,15 @@ isc_hmac_test(isc_hmac_t *hmac, const void *key, size_t keylen, isc_buffer_t b; isc_buffer_init(&b, hexdigest, sizeof(hexdigest)); - assert_return_code(isc_hex_totext(&r, 0, "", &b), ISC_R_SUCCESS); + res = isc_hex_totext(&r, 0, "", &b); + + assert_return_code(res, ISC_R_SUCCESS); assert_memory_equal(hexdigest, result, (result ? strlen(result) : 0)); assert_int_equal(isc_hmac_reset(hmac), ISC_R_SUCCESS); } -static void -isc_hmac_init_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_init) { isc_hmac_t *hmac = *state; assert_non_null(hmac); @@ -152,8 +151,7 @@ isc_hmac_init_test(void **state) { assert_int_equal(isc_hmac_reset(hmac), ISC_R_SUCCESS); } -static void -isc_hmac_update_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_update) { isc_hmac_t *hmac = *state; assert_non_null(hmac); @@ -165,8 +163,7 @@ isc_hmac_update_test(void **state) { ISC_R_SUCCESS); } -static void -isc_hmac_reset_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_reset) { isc_hmac_t *hmac = *state; #if 0 unsigned char digest[ISC_MAX_MD_SIZE] __attribute((unused)); @@ -194,8 +191,7 @@ isc_hmac_reset_test(void **state) { #endif /* if 0 */ } -static void -isc_hmac_final_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_final) { isc_hmac_t *hmac = *state; assert_non_null(hmac); @@ -213,8 +209,7 @@ isc_hmac_final_test(void **state) { expect_assert_failure(isc_hmac_final(hmac, digest, NULL)); } -static void -isc_hmac_md5_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_md5) { isc_hmac_t *hmac = *state; /* Test 0 */ @@ -311,8 +306,7 @@ isc_hmac_md5_test(void **state) { #endif /* if 0 */ } -static void -isc_hmac_sha1_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_sha1) { isc_hmac_t *hmac = *state; /* Test 0 */ @@ -395,8 +389,7 @@ isc_hmac_sha1_test(void **state) { "E8E99D0F45237D786D6BBAA7965C7808BBFF1A91", 1); } -static void -isc_hmac_sha224_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_sha224) { isc_hmac_t *hmac = *state; /* Test 0 */ @@ -519,8 +512,7 @@ isc_hmac_sha224_test(void **state) { 1); } -static void -isc_hmac_sha256_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_sha256) { isc_hmac_t *hmac = *state; /* Test 0 */ @@ -643,8 +635,7 @@ isc_hmac_sha256_test(void **state) { 1); } -static void -isc_hmac_sha384_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_sha384) { isc_hmac_t *hmac = *state; /* Test 0 */ @@ -773,8 +764,7 @@ isc_hmac_sha384_test(void **state) { 1); } -static void -isc_hmac_sha512_test(void **state) { +ISC_RUN_TEST_IMPL(isc_hmac_sha512) { isc_hmac_t *hmac = *state; /* Test 0 */ @@ -904,47 +894,25 @@ isc_hmac_sha512_test(void **state) { 1); } -int -main(void) { - const struct CMUnitTest tests[] = { - /* isc_hmac_new() */ - cmocka_unit_test(isc_hmac_new_test), +ISC_TEST_LIST_START - /* isc_hmac_init() */ - cmocka_unit_test_setup_teardown(isc_hmac_init_test, _reset, - _reset), +ISC_TEST_ENTRY(isc_hmac_new) +ISC_TEST_ENTRY_CUSTOM(isc_hmac_init, _reset, _reset) - /* isc_hmac_reset() */ - cmocka_unit_test_setup_teardown(isc_hmac_reset_test, _reset, - _reset), +ISC_TEST_ENTRY_CUSTOM(isc_hmac_reset, _reset, _reset) - /* isc_hmac_init() -> isc_hmac_update() -> isc_hmac_final() */ - cmocka_unit_test(isc_hmac_md5_test), - cmocka_unit_test(isc_hmac_sha1_test), - cmocka_unit_test(isc_hmac_sha224_test), - cmocka_unit_test(isc_hmac_sha256_test), - cmocka_unit_test(isc_hmac_sha384_test), - cmocka_unit_test(isc_hmac_sha512_test), +ISC_TEST_ENTRY(isc_hmac_md5) +ISC_TEST_ENTRY(isc_hmac_sha1) +ISC_TEST_ENTRY(isc_hmac_sha224) +ISC_TEST_ENTRY(isc_hmac_sha256) +ISC_TEST_ENTRY(isc_hmac_sha384) +ISC_TEST_ENTRY(isc_hmac_sha512) - cmocka_unit_test_setup_teardown(isc_hmac_update_test, _reset, - _reset), - cmocka_unit_test_setup_teardown(isc_hmac_final_test, _reset, - _reset), +ISC_TEST_ENTRY_CUSTOM(isc_hmac_update, _reset, _reset) +ISC_TEST_ENTRY_CUSTOM(isc_hmac_final, _reset, _reset) - cmocka_unit_test(isc_hmac_free_test), - }; +ISC_TEST_ENTRY(isc_hmac_free) - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} +ISC_TEST_LIST_END -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN_CUSTOM(_setup, _teardown) diff --git a/lib/isc/tests/ht_test.c b/tests/isc/ht_test.c similarity index 89% rename from lib/isc/tests/ht_test.c rename to tests/isc/ht_test.c index 2d3cbe142d..152994e47d 100644 --- a/lib/isc/tests/ht_test.c +++ b/tests/isc/ht_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -32,32 +30,13 @@ #include #include -#include "isctest.h" +#include /* INCLUDE LAST */ -#include "../ht.c" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} +#define mctx __mctx +#include "ht.c" +#undef mctx static void test_ht_full(uint8_t init_bits, uint8_t finish_bits, uintptr_t count) { @@ -65,7 +44,7 @@ test_ht_full(uint8_t init_bits, uint8_t finish_bits, uintptr_t count) { isc_result_t result; uintptr_t i; - isc_ht_init(&ht, test_mctx, init_bits, ISC_HT_CASE_SENSITIVE); + isc_ht_init(&ht, mctx, init_bits, ISC_HT_CASE_SENSITIVE); assert_non_null(ht); for (i = 1; i < count; i++) { @@ -212,7 +191,7 @@ test_ht_iterator(void) { unsigned char key[16]; size_t tksize; - isc_ht_init(&ht, test_mctx, HT_MIN_BITS, ISC_HT_CASE_SENSITIVE); + isc_ht_init(&ht, mctx, HT_MIN_BITS, ISC_HT_CASE_SENSITIVE); assert_non_null(ht); for (i = 1; i <= count; i++) { /* @@ -318,53 +297,35 @@ test_ht_iterator(void) { } /* 24 bit, 200K elements test, no rehashing */ -static void -isc_ht_24(void **state) { +ISC_RUN_TEST_IMPL(isc_ht_24) { UNUSED(state); test_ht_full(24, 24, 200000); } /* 15 bit, 45K elements test, full rehashing */ -static void -isc_ht_15(void **state) { +ISC_RUN_TEST_IMPL(isc_ht_15) { UNUSED(state); test_ht_full(1, 15, 48000); } /* 8 bit, 20k elements test, partial rehashing */ -static void -isc_ht_8(void **state) { +ISC_RUN_TEST_IMPL(isc_ht_8) { UNUSED(state); test_ht_full(8, 14, 20000); } /* test hashtable iterator */ -static void -isc_ht_iterator_test(void **state) { + +ISC_RUN_TEST_IMPL(isc_ht_iterator) { UNUSED(state); test_ht_iterator(); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_ht_24), - cmocka_unit_test(isc_ht_15), - cmocka_unit_test(isc_ht_8), - cmocka_unit_test(isc_ht_iterator_test), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(isc_ht_24) +ISC_TEST_ENTRY(isc_ht_15) +ISC_TEST_ENTRY(isc_ht_8) +ISC_TEST_ENTRY(isc_ht_iterator) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/lex_test.c b/tests/isc/lex_test.c similarity index 81% rename from lib/isc/tests/lex_test.c rename to tests/isc/lex_test.c index 4f8f80dc07..cf6bfe2ea5 100644 --- a/lib/isc/tests/lex_test.c +++ b/tests/isc/lex_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -29,36 +27,12 @@ #include #include -#include "isctest.h" +#include #define AS_STR(x) (x).value.as_textregion.base -static bool debug = false; - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} - /* check handling of 0xff */ -static void -lex_0xff(void **state) { +ISC_RUN_TEST_IMPL(lex_0xff) { isc_result_t result; isc_lex_t *lex = NULL; isc_buffer_t death_buf; @@ -68,7 +42,7 @@ lex_0xff(void **state) { UNUSED(state); - result = isc_lex_create(test_mctx, 1024, &lex); + result = isc_lex_create(mctx, 1024, &lex); assert_int_equal(result, ISC_R_SUCCESS); isc_buffer_init(&death_buf, &death[0], sizeof(death)); @@ -84,8 +58,7 @@ lex_0xff(void **state) { } /* check setting of source line */ -static void -lex_setline(void **state) { +ISC_RUN_TEST_IMPL(lex_setline) { isc_result_t result; isc_lex_t *lex = NULL; unsigned char text[] = "text\nto\nbe\nprocessed\nby\nlexer"; @@ -96,7 +69,7 @@ lex_setline(void **state) { UNUSED(state); - result = isc_lex_create(test_mctx, 1024, &lex); + result = isc_lex_create(mctx, 1024, &lex); assert_int_equal(result, ISC_R_SUCCESS); isc_buffer_init(&buf, &text[0], sizeof(text)); @@ -209,8 +182,7 @@ static struct { /*% * string */ -static void -lex_string(void **state) { +ISC_RUN_TEST_IMPL(lex_string) { isc_buffer_t buf; isc_lex_t *lex = NULL; isc_result_t result; @@ -220,7 +192,7 @@ lex_string(void **state) { UNUSED(state); for (i = 0; i < ARRAY_SIZE(parse_tests); i++) { - result = isc_lex_create(test_mctx, 1024, &lex); + result = isc_lex_create(mctx, 1024, &lex); assert_int_equal(result, ISC_R_SUCCESS); isc_buffer_constinit(&buf, parse_tests[i].text, @@ -236,12 +208,6 @@ lex_string(void **state) { memset(&token, 0, sizeof(token)); result = isc_lex_getmastertoken(lex, &token, isc_tokentype_string, true); - if (debug) { - fprintf(stdout, "# '%s' -> result=%s/%s, type=%d/%d\n", - parse_tests[i].text, isc_result_toid(result), - isc_result_toid(parse_tests[i].string_result), - token.type, parse_tests[i].string_type); - } assert_int_equal(result, parse_tests[i].string_result); if (result == ISC_R_SUCCESS) { @@ -250,10 +216,6 @@ lex_string(void **state) { case isc_tokentype_qstring: case isc_tokentype_vpair: case isc_tokentype_qvpair: - if (debug) { - fprintf(stdout, "# value='%s'\n", - AS_STR(token)); - } assert_int_equal(token.type, parse_tests[i].string_type); assert_string_equal( @@ -274,8 +236,7 @@ lex_string(void **state) { /*% * qstring */ -static void -lex_qstring(void **state) { +ISC_RUN_TEST_IMPL(lex_qstring) { isc_buffer_t buf; isc_lex_t *lex = NULL; isc_result_t result; @@ -285,7 +246,7 @@ lex_qstring(void **state) { UNUSED(state); for (i = 0; i < ARRAY_SIZE(parse_tests); i++) { - result = isc_lex_create(test_mctx, 1024, &lex); + result = isc_lex_create(mctx, 1024, &lex); assert_int_equal(result, ISC_R_SUCCESS); isc_buffer_constinit(&buf, parse_tests[i].text, @@ -301,12 +262,6 @@ lex_qstring(void **state) { memset(&token, 0, sizeof(token)); result = isc_lex_getmastertoken(lex, &token, isc_tokentype_qstring, true); - if (debug) { - fprintf(stdout, "# '%s' -> result=%s/%s, type=%d/%d\n", - parse_tests[i].text, isc_result_toid(result), - isc_result_toid(parse_tests[i].qstring_result), - token.type, parse_tests[i].qstring_type); - } assert_int_equal(result, parse_tests[i].qstring_result); if (result == ISC_R_SUCCESS) { @@ -315,10 +270,6 @@ lex_qstring(void **state) { case isc_tokentype_qstring: case isc_tokentype_vpair: case isc_tokentype_qvpair: - if (debug) { - fprintf(stdout, "# value='%s'\n", - AS_STR(token)); - } assert_int_equal(token.type, parse_tests[i].qstring_type); assert_string_equal( @@ -340,8 +291,7 @@ lex_qstring(void **state) { * keypair is =. This has implications double quotes * in key names. */ -static void -lex_keypair(void **state) { +ISC_RUN_TEST_IMPL(lex_keypair) { isc_buffer_t buf; isc_lex_t *lex = NULL; isc_result_t result; @@ -351,7 +301,7 @@ lex_keypair(void **state) { UNUSED(state); for (i = 0; i < ARRAY_SIZE(parse_tests); i++) { - result = isc_lex_create(test_mctx, 1024, &lex); + result = isc_lex_create(mctx, 1024, &lex); assert_int_equal(result, ISC_R_SUCCESS); isc_buffer_constinit(&buf, parse_tests[i].text, @@ -367,12 +317,6 @@ lex_keypair(void **state) { memset(&token, 0, sizeof(token)); result = isc_lex_getmastertoken(lex, &token, isc_tokentype_qvpair, true); - if (debug) { - fprintf(stdout, "# '%s' -> result=%s/%s, type=%d/%d\n", - parse_tests[i].text, isc_result_toid(result), - isc_result_toid(parse_tests[i].qvpair_result), - token.type, parse_tests[i].qvpair_type); - } assert_int_equal(result, parse_tests[i].qvpair_result); if (result == ISC_R_SUCCESS) { @@ -381,10 +325,6 @@ lex_keypair(void **state) { case isc_tokentype_qstring: case isc_tokentype_vpair: case isc_tokentype_qvpair: - if (debug) { - fprintf(stdout, "# value='%s'\n", - AS_STR(token)); - } assert_int_equal(token.type, parse_tests[i].qvpair_type); assert_string_equal( @@ -402,31 +342,13 @@ lex_keypair(void **state) { } } -int -main(int argc, char *argv[]) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(lex_0xff), cmocka_unit_test(lex_keypair), - cmocka_unit_test(lex_setline), cmocka_unit_test(lex_string), - cmocka_unit_test(lex_qstring), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(lex_0xff) +ISC_TEST_ENTRY(lex_keypair) +ISC_TEST_ENTRY(lex_setline) +ISC_TEST_ENTRY(lex_string) +ISC_TEST_ENTRY(lex_qstring) - UNUSED(argv); +ISC_TEST_LIST_END - if (argc > 1) { - debug = true; - } - - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/md_test.c b/tests/isc/md_test.c similarity index 90% rename from lib/isc/tests/md_test.c rename to tests/isc/md_test.c index 83c44c4213..d7d154c13b 100644 --- a/lib/isc/tests/md_test.c +++ b/tests/isc/md_test.c @@ -11,8 +11,7 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - +#include /* IWYU pragma: keep */ #include #include #include @@ -30,7 +29,9 @@ #include #include -#include "../md.c" +#include "md.c" + +#include #define TEST_INPUT(x) (x), sizeof(x) - 1 @@ -64,19 +65,13 @@ _reset(void **state) { return (0); } -static void -isc_md_new_test(void **state) { - UNUSED(state); - +ISC_RUN_TEST_IMPL(isc_md_new) { isc_md_t *md = isc_md_new(); assert_non_null(md); isc_md_free(md); /* Cleanup */ } -static void -isc_md_free_test(void **state) { - UNUSED(state); - +ISC_RUN_TEST_IMPL(isc_md_free) { isc_md_t *md = isc_md_new(); assert_non_null(md); isc_md_free(md); /* Test freeing valid message digest context */ @@ -85,13 +80,13 @@ isc_md_free_test(void **state) { static void isc_md_test(isc_md_t *md, const isc_md_type_t *type, const char *buf, - size_t buflen, const char *result, const int repeats) { + size_t buflen, const char *result, const size_t repeats) { + isc_result_t res; + assert_non_null(md); assert_int_equal(isc_md_init(md, type), ISC_R_SUCCESS); - int i; - - for (i = 0; i < repeats; i++) { + for (size_t i = 0; i < repeats; i++) { assert_int_equal( isc_md_update(md, (const unsigned char *)buf, buflen), ISC_R_SUCCESS); @@ -106,14 +101,15 @@ isc_md_test(isc_md_t *md, const isc_md_type_t *type, const char *buf, isc_buffer_t b; isc_buffer_init(&b, hexdigest, sizeof(hexdigest)); - assert_return_code(isc_hex_totext(&r, 0, "", &b), ISC_R_SUCCESS); + res = isc_hex_totext(&r, 0, "", &b); + + assert_return_code(res, ISC_R_SUCCESS); assert_memory_equal(hexdigest, result, (result ? strlen(result) : 0)); assert_int_equal(isc_md_reset(md), ISC_R_SUCCESS); } -static void -isc_md_init_test(void **state) { +ISC_RUN_TEST_IMPL(isc_md_init) { isc_md_t *md = *state; assert_non_null(md); @@ -140,8 +136,7 @@ isc_md_init_test(void **state) { assert_int_equal(isc_md_reset(md), ISC_R_SUCCESS); } -static void -isc_md_update_test(void **state) { +ISC_RUN_TEST_IMPL(isc_md_update) { isc_md_t *md = *state; assert_non_null(md); @@ -153,8 +148,7 @@ isc_md_update_test(void **state) { ISC_R_SUCCESS); } -static void -isc_md_reset_test(void **state) { +ISC_RUN_TEST_IMPL(isc_md_reset) { isc_md_t *md = *state; #if 0 unsigned char digest[ISC_MAX_MD_SIZE] __attribute((unused)); @@ -181,8 +175,7 @@ isc_md_reset_test(void **state) { #endif /* if 0 */ } -static void -isc_md_final_test(void **state) { +ISC_RUN_TEST_IMPL(isc_md_final) { isc_md_t *md = *state; assert_non_null(md); @@ -198,8 +191,7 @@ isc_md_final_test(void **state) { assert_int_equal(isc_md_final(md, digest, NULL), ISC_R_SUCCESS); } -static void -isc_md_md5_test(void **state) { +ISC_RUN_TEST_IMPL(isc_md_md5) { isc_md_t *md = *state; isc_md_test(md, ISC_MD_MD5, NULL, 0, NULL, 0); isc_md_test(md, ISC_MD_MD5, TEST_INPUT(""), @@ -222,8 +214,7 @@ isc_md_md5_test(void **state) { "57EDF4A22BE3C955AC49DA2E2107B67A", 1); } -static void -isc_md_sha1_test(void **state) { +ISC_RUN_TEST_IMPL(isc_md_sha1) { isc_md_t *md = *state; isc_md_test(md, ISC_MD_SHA1, NULL, 0, NULL, 0); isc_md_test(md, ISC_MD_SHA1, TEST_INPUT(""), @@ -266,8 +257,7 @@ isc_md_sha1_test(void **state) { "CB0082C8F197D260991BA6A460E76E202BAD27B3", 1); } -static void -isc_md_sha224_test(void **state) { +ISC_RUN_TEST_IMPL(isc_md_sha224) { isc_md_t *md = *state; isc_md_test(md, ISC_MD_SHA224, NULL, 0, NULL, 0); @@ -326,8 +316,7 @@ isc_md_sha224_test(void **state) { 1); } -static void -isc_md_sha256_test(void **state) { +ISC_RUN_TEST_IMPL(isc_md_sha256) { isc_md_t *md = *state; isc_md_test(md, ISC_MD_SHA256, NULL, 0, NULL, 0); @@ -388,8 +377,7 @@ isc_md_sha256_test(void **state) { 1); } -static void -isc_md_sha384_test(void **state) { +ISC_RUN_TEST_IMPL(isc_md_sha384) { isc_md_t *md = *state; isc_md_test(md, ISC_MD_SHA384, NULL, 0, NULL, 0); @@ -465,8 +453,7 @@ isc_md_sha384_test(void **state) { 1); } -static void -isc_md_sha512_test(void **state) { +ISC_RUN_TEST_IMPL(isc_md_sha512) { isc_md_t *md = *state; isc_md_test(md, ISC_MD_SHA512, NULL, 0, NULL, 0); @@ -541,47 +528,27 @@ isc_md_sha512_test(void **state) { 1); } -int -main(void) { - const struct CMUnitTest tests[] = { - /* isc_md_new() */ - cmocka_unit_test(isc_md_new_test), +ISC_TEST_LIST_START - /* isc_md_init() */ - cmocka_unit_test_setup_teardown(isc_md_init_test, _reset, - _reset), +ISC_TEST_ENTRY(isc_md_new) - /* isc_md_reset() */ - cmocka_unit_test_setup_teardown(isc_md_reset_test, _reset, - _reset), +ISC_TEST_ENTRY_CUSTOM(isc_md_init, _reset, _reset) - /* isc_md_init() -> isc_md_update() -> isc_md_final() */ - cmocka_unit_test(isc_md_md5_test), - cmocka_unit_test(isc_md_sha1_test), - cmocka_unit_test(isc_md_sha224_test), - cmocka_unit_test(isc_md_sha256_test), - cmocka_unit_test(isc_md_sha384_test), - cmocka_unit_test(isc_md_sha512_test), +ISC_TEST_ENTRY_CUSTOM(isc_md_reset, _reset, _reset) - cmocka_unit_test_setup_teardown(isc_md_update_test, _reset, - _reset), - cmocka_unit_test_setup_teardown(isc_md_final_test, _reset, - _reset), +ISC_TEST_ENTRY(isc_md_md5) +ISC_TEST_ENTRY(isc_md_sha1) - cmocka_unit_test(isc_md_free_test), - }; +ISC_TEST_ENTRY(isc_md_sha224) +ISC_TEST_ENTRY(isc_md_sha256) +ISC_TEST_ENTRY(isc_md_sha384) +ISC_TEST_ENTRY(isc_md_sha512) - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} +ISC_TEST_ENTRY_CUSTOM(isc_md_update, _reset, _reset) +ISC_TEST_ENTRY_CUSTOM(isc_md_final, _reset, _reset) -#else /* HAVE_CMOCKA */ +ISC_TEST_ENTRY(isc_md_free) -#include +ISC_TEST_LIST_END -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN_CUSTOM(_setup, _teardown) diff --git a/lib/isc/tests/mem_test.c b/tests/isc/mem_test.c similarity index 76% rename from lib/isc/tests/mem_test.c rename to tests/isc/mem_test.c index 5f382a3819..f2bbdbd3f4 100644 --- a/lib/isc/tests/mem_test.c +++ b/tests/isc/mem_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include #include /* IWYU pragma: keep */ @@ -37,29 +35,9 @@ #include #include -#include "../mem_p.h" -#include "isctest.h" +#include "mem_p.h" -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} +#include #define MP1_FREEMAX 10 #define MP1_FILLCNT 10 @@ -69,8 +47,7 @@ _teardown(void **state) { #define MP2_FILLCNT 25 /* general memory system tests */ -static void -isc_mem_test(void **state) { +ISC_RUN_TEST_IMPL(isc_mem) { void *items1[50]; void *items2[50]; void *tmp; @@ -80,8 +57,8 @@ isc_mem_test(void **state) { UNUSED(state); - isc_mempool_create(test_mctx, 24, &mp1); - isc_mempool_create(test_mctx, 31, &mp2); + isc_mempool_create(mctx, 24, &mp1); + isc_mempool_create(mctx, 31, &mp2); isc_mempool_setfreemax(mp1, MP1_FREEMAX); isc_mempool_setfillcount(mp1, MP1_FILLCNT); @@ -141,7 +118,7 @@ isc_mem_test(void **state) { isc_mempool_destroy(&mp1); isc_mempool_destroy(&mp2); - isc_mempool_create(test_mctx, 2, &mp1); + isc_mempool_create(mctx, 2, &mp1); tmp = isc_mempool_get(mp1); assert_non_null(tmp); @@ -153,8 +130,7 @@ isc_mem_test(void **state) { #if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) /* aligned memory system tests */ -static void -isc_mem_aligned_test(void **state) { +ISC_RUN_TEST_IMPL(isc_mem_aligned) { isc_mem_t *mctx2 = NULL; void *ptr; size_t alignment; @@ -165,22 +141,21 @@ isc_mem_aligned_test(void **state) { /* Check different alignment sizes up to the page size */ for (alignment = sizeof(void *); alignment <= 4096; alignment *= 2) { size_t size = alignment / 2 - 1; - ptr = isc_mem_get_aligned(test_mctx, size, alignment); + ptr = isc_mem_get_aligned(mctx, size, alignment); /* Check if the pointer is properly aligned */ aligned = (((uintptr_t)ptr / alignment) * alignment); assert_ptr_equal(aligned, (uintptr_t)ptr); /* Check if we can resize to range */ - ptr = isc_mem_reget_aligned(test_mctx, ptr, size, + ptr = isc_mem_reget_aligned(mctx, ptr, size, size * 2 + alignment, alignment); /* Check if the pointer is still properly aligned */ aligned = (((uintptr_t)ptr / alignment) * alignment); assert_ptr_equal(aligned, (uintptr_t)ptr); - isc_mem_put_aligned(test_mctx, ptr, size * 2 + alignment, - alignment); + isc_mem_put_aligned(mctx, ptr, size * 2 + alignment, alignment); /* Check whether isc_mem_putanddetach_detach() also works */ isc_mem_create(&mctx2); @@ -191,8 +166,7 @@ isc_mem_aligned_test(void **state) { #endif /* defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) */ /* test TotalUse calculation */ -static void -isc_mem_total_test(void **state) { +ISC_RUN_TEST_IMPL(isc_mem_total) { isc_mem_t *mctx2 = NULL; size_t before, after; ssize_t diff; @@ -220,16 +194,16 @@ isc_mem_total_test(void **state) { /* ISC_MEMFLAG_INTERNAL */ - before = isc_mem_total(test_mctx); + before = isc_mem_total(mctx); for (i = 0; i < 100000; i++) { void *ptr; - ptr = isc_mem_get(test_mctx, 2048); - isc_mem_put(test_mctx, ptr, 2048); + ptr = isc_mem_get(mctx, 2048); + isc_mem_put(mctx, ptr, 2048); } - after = isc_mem_total(test_mctx); + after = isc_mem_total(mctx); diff = after - before; assert_int_equal(diff, (2048) * 100000); @@ -238,8 +212,7 @@ isc_mem_total_test(void **state) { } /* test InUse calculation */ -static void -isc_mem_inuse_test(void **state) { +ISC_RUN_TEST_IMPL(isc_mem_inuse) { isc_mem_t *mctx2 = NULL; size_t before, after; ssize_t diff; @@ -262,43 +235,41 @@ isc_mem_inuse_test(void **state) { isc_mem_destroy(&mctx2); } -static void -isc_mem_zeroget_test(void **state) { +ISC_RUN_TEST_IMPL(isc_mem_zeroget) { uint8_t *data = NULL; UNUSED(state); - data = isc_mem_get(test_mctx, 0); + data = isc_mem_get(mctx, 0); assert_non_null(data); - isc_mem_put(test_mctx, data, 0); + isc_mem_put(mctx, data, 0); } #define REGET_INIT_SIZE 1024 #define REGET_GROW_SIZE 2048 #define REGET_SHRINK_SIZE 512 -static void -isc_mem_reget_test(void **state) { +ISC_RUN_TEST_IMPL(isc_mem_reget) { uint8_t *data = NULL; UNUSED(state); /* test that we can reget NULL */ - data = isc_mem_reget(test_mctx, NULL, 0, REGET_INIT_SIZE); + data = isc_mem_reget(mctx, NULL, 0, REGET_INIT_SIZE); assert_non_null(data); - isc_mem_put(test_mctx, data, REGET_INIT_SIZE); + isc_mem_put(mctx, data, REGET_INIT_SIZE); /* test that we can re-get a zero-length allocation */ - data = isc_mem_get(test_mctx, 0); + data = isc_mem_get(mctx, 0); assert_non_null(data); - data = isc_mem_reget(test_mctx, data, 0, REGET_INIT_SIZE); + data = isc_mem_reget(mctx, data, 0, REGET_INIT_SIZE); assert_non_null(data); for (size_t i = 0; i < REGET_INIT_SIZE; i++) { data[i] = i % UINT8_MAX; } - data = isc_mem_reget(test_mctx, data, REGET_INIT_SIZE, REGET_GROW_SIZE); + data = isc_mem_reget(mctx, data, REGET_INIT_SIZE, REGET_GROW_SIZE); assert_non_null(data); for (size_t i = 0; i < REGET_INIT_SIZE; i++) { @@ -309,22 +280,20 @@ isc_mem_reget_test(void **state) { data[i - 1] = i % UINT8_MAX; } - data = isc_mem_reget(test_mctx, data, REGET_GROW_SIZE, - REGET_SHRINK_SIZE); + data = isc_mem_reget(mctx, data, REGET_GROW_SIZE, REGET_SHRINK_SIZE); assert_non_null(data); for (size_t i = REGET_SHRINK_SIZE; i > 0; i--) { assert_int_equal(data[i - 1], i % UINT8_MAX); } - isc_mem_put(test_mctx, data, REGET_SHRINK_SIZE); + isc_mem_put(mctx, data, REGET_SHRINK_SIZE); } #if ISC_MEM_TRACKLINES /* test mem with no flags */ -static void -isc_mem_noflags_test(void **state) { +ISC_RUN_TEST_IMPL(isc_mem_noflags) { isc_result_t result; isc_mem_t *mctx2 = NULL; char buf[4096], *p, *q; @@ -368,8 +337,7 @@ isc_mem_noflags_test(void **state) { } /* test mem with record flag */ -static void -isc_mem_recordflag_test(void **state) { +ISC_RUN_TEST_IMPL(isc_mem_recordflag) { isc_result_t result; isc_mem_t *mctx2 = NULL; char buf[4096], *p; @@ -409,8 +377,7 @@ isc_mem_recordflag_test(void **state) { } /* test mem with trace flag */ -static void -isc_mem_traceflag_test(void **state) { +ISC_RUN_TEST_IMPL(isc_mem_traceflag) { isc_result_t result; isc_mem_t *mctx2 = NULL; char buf[4096], *p; @@ -470,7 +437,7 @@ static atomic_size_t mem_size; static isc_threadresult_t mem_thread(isc_threadarg_t arg) { - isc_mem_t *mctx = (isc_mem_t *)arg; + isc_mem_t *mctx2 = (isc_mem_t *)arg; void *items[NUM_ITEMS]; size_t size = atomic_load(&mem_size); while (!atomic_compare_exchange_weak(&mem_size, &size, size / 2)) { @@ -479,18 +446,17 @@ mem_thread(isc_threadarg_t arg) { for (int i = 0; i < ITERS; i++) { for (int j = 0; j < NUM_ITEMS; j++) { - items[j] = isc_mem_get(mctx, size); + items[j] = isc_mem_get(mctx2, size); } for (int j = 0; j < NUM_ITEMS; j++) { - isc_mem_put(mctx, items[j], size); + isc_mem_put(mctx2, items[j], size); } } return ((isc_threadresult_t)0); } -static void -isc_mem_benchmark(void **state) { +ISC_RUN_TEST_IMPL(isc_mem_benchmark) { int nthreads = ISC_MAX(ISC_MIN(isc_os_ncpus(), 32), 1); isc_thread_t threads[32]; isc_time_t ts1, ts2; @@ -505,7 +471,7 @@ isc_mem_benchmark(void **state) { assert_int_equal(result, ISC_R_SUCCESS); for (int i = 0; i < nthreads; i++) { - isc_thread_create(mem_thread, test_mctx, &threads[i]); + isc_thread_create(mem_thread, mctx, &threads[i]); } for (int i = 0; i < nthreads; i++) { isc_thread_join(threads[i], NULL); @@ -525,58 +491,31 @@ isc_mem_benchmark(void **state) { #endif /* __SANITIZE_THREAD */ -/* - * Main - */ +ISC_TEST_LIST_START -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(isc_mem_test, _setup, - _teardown), +ISC_TEST_ENTRY(isc_mem) #if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) - cmocka_unit_test_setup_teardown(isc_mem_aligned_test, _setup, - _teardown), +ISC_TEST_ENTRY(isc_mem_aligned) #endif /* defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) */ - cmocka_unit_test_setup_teardown(isc_mem_total_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(isc_mem_inuse_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(isc_mem_zeroget_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(isc_mem_reget_test, _setup, - _teardown), +ISC_TEST_ENTRY(isc_mem_total) +ISC_TEST_ENTRY(isc_mem_inuse) +ISC_TEST_ENTRY(isc_mem_zeroget) +ISC_TEST_ENTRY(isc_mem_reget) #if !defined(__SANITIZE_THREAD__) - cmocka_unit_test_setup_teardown(isc_mem_benchmark, _setup, - _teardown), +ISC_TEST_ENTRY(isc_mem_benchmark) #endif /* __SANITIZE_THREAD__ */ #if ISC_MEM_TRACKLINES - cmocka_unit_test_setup_teardown(isc_mem_noflags_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(isc_mem_recordflag_test, _setup, - _teardown), - /* - * traceflag_test closes stderr, which causes weird - * side effects for any next test trying to use libuv. - * This test has to be the last one to avoid problems. - */ - cmocka_unit_test_setup_teardown(isc_mem_traceflag_test, _setup, - _teardown), +ISC_TEST_ENTRY(isc_mem_noflags) +ISC_TEST_ENTRY(isc_mem_recordflag) +/* + * traceflag_test closes stderr, which causes weird + * side effects for any next test trying to use libuv. + * This test has to be the last one to avoid problems. + */ +ISC_TEST_ENTRY(isc_mem_traceflag) #endif /* if ISC_MEM_TRACKLINES */ - }; - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_LIST_END -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/netaddr_test.c b/tests/isc/netaddr_test.c similarity index 85% rename from lib/isc/tests/netaddr_test.c rename to tests/isc/netaddr_test.c index 473e7474e3..b44982c26b 100644 --- a/lib/isc/tests/netaddr_test.c +++ b/tests/isc/netaddr_test.c @@ -11,8 +11,7 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - +#include /* IWYU pragma: keep */ #include #include #include @@ -28,9 +27,10 @@ #include #include +#include + /* test isc_netaddr_isnetzero() */ -static void -netaddr_isnetzero(void **state) { +ISC_RUN_TEST_IMPL(netaddr_isnetzero) { unsigned int i; struct in_addr ina; struct { @@ -41,12 +41,12 @@ netaddr_isnetzero(void **state) { { "10.0.0.0", false }, { "10.9.0.0", false }, { "10.9.8.0", false }, { "10.9.8.7", false }, { "127.0.0.0", false }, { "127.0.0.1", false } }; - bool result; isc_netaddr_t netaddr; UNUSED(state); for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { + bool result; ina.s_addr = inet_addr(tests[i].address); isc_netaddr_fromin(&netaddr, &ina); result = isc_netaddr_isnetzero(&netaddr); @@ -55,8 +55,7 @@ netaddr_isnetzero(void **state) { } /* test isc_netaddr_masktoprefixlen() calculates correct prefix lengths */ -static void -netaddr_masktoprefixlen(void **state) { +ISC_RUN_TEST_IMPL(netaddr_masktoprefixlen) { struct in_addr na_a; struct in_addr na_b; struct in_addr na_c; @@ -97,8 +96,7 @@ netaddr_masktoprefixlen(void **state) { } /* check multicast addresses are detected properly */ -static void -netaddr_multicast(void **state) { +ISC_RUN_TEST_IMPL(netaddr_multicast) { unsigned int i; struct { int family; @@ -135,25 +133,12 @@ netaddr_multicast(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(netaddr_isnetzero), - cmocka_unit_test(netaddr_masktoprefixlen), - cmocka_unit_test(netaddr_multicast), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(netaddr_isnetzero) +ISC_TEST_ENTRY(netaddr_masktoprefixlen) +ISC_TEST_ENTRY(netaddr_multicast) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/netmgr_test.c b/tests/isc/netmgr_test.c similarity index 81% rename from lib/isc/tests/netmgr_test.c rename to tests/isc/netmgr_test.c index b0b8db649b..1bd5d68819 100644 --- a/lib/isc/tests/netmgr_test.c +++ b/tests/isc/netmgr_test.c @@ -11,7 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA #include /* IWYU pragma: keep */ #include #include @@ -34,11 +33,15 @@ #include "uv_wrap.h" #define KEEP_BEFORE -#include "../netmgr/netmgr-int.h" -#include "../netmgr/socket.c" -#include "../netmgr/udp.c" -#include "../netmgr_p.h" -#include "isctest.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +//#include "netmgr/netmgr.c" +#include "netmgr/socket.c" +#include "netmgr/udp.c" +#include "uv.c" +#pragma GCC diagnostic pop + +#include typedef void (*stream_connect_function)(isc_nm_t *nm); @@ -70,7 +73,6 @@ static isc_region_t stop_msg = { .base = (unsigned char *)&stop_magic, .length = sizeof(stop_magic) }; static atomic_bool do_send = false; -static unsigned int workers = 0; static atomic_int_fast64_t nsends; static int_fast64_t esends; /* expected sends */ @@ -119,9 +121,9 @@ static isc_nm_recv_cb_t connect_readcb = NULL; #define T_ADVERTISED 120 * 1000 #define T_CONNECT 30 * 1000 -/* Wait for 1 second (1000 * 1000 microseconds) */ +/* Wait for 1 second (1000 milliseconds) */ #define WAIT_REPEATS 1000 -#define T_WAIT 1000 /* In microseconds */ +#define T_WAIT 1 /* 1 millisecond */ #define WAIT_FOR(v, op, val) \ { \ @@ -191,61 +193,6 @@ static isc_nm_recv_cb_t connect_readcb = NULL; #define atomic_assert_int_ge(val, exp) assert_true(atomic_load(&val) >= exp) #define atomic_assert_int_gt(val, exp) assert_true(atomic_load(&val) > exp) -static int -_setup(void **state __attribute__((unused))) { - char *p = NULL; - - if (workers == 0) { - workers = isc_os_ncpus(); - } - p = getenv("ISC_TASK_WORKERS"); - if (p != NULL) { - workers = atoi(p); - } - INSIST(workers != 0); - - if (isc_test_begin(NULL, false, workers) != ISC_R_SUCCESS) { - return (-1); - } - - signal(SIGPIPE, SIG_IGN); - - if (getenv("CI") == NULL || getenv("CI_ENABLE_ALL_TESTS") != NULL) { - esends = NSENDS * workers; - } else { - esends = workers; - skip_long_tests = true; - } - - if (isc_tlsctx_createserver(NULL, NULL, &tcp_listen_tlsctx) != - ISC_R_SUCCESS) { - return (-1); - } - if (isc_tlsctx_createclient(&tcp_connect_tlsctx) != ISC_R_SUCCESS) { - return (-1); - } - - isc_tlsctx_enable_dot_client_alpn(tcp_connect_tlsctx); - - tcp_tlsctx_client_sess_cache = isc_tlsctx_client_session_cache_new( - test_mctx, tcp_connect_tlsctx, - ISC_TLSCTX_CLIENT_SESSION_CACHE_DEFAULT_SIZE); - - return (0); -} - -static int -_teardown(void **state __attribute__((unused))) { - isc_tlsctx_free(&tcp_connect_tlsctx); - isc_tlsctx_free(&tcp_listen_tlsctx); - - isc_tlsctx_client_session_cache_detach(&tcp_tlsctx_client_sess_cache); - - isc_test_end(); - - return (0); -} - static int setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) { socklen_t addrlen = sizeof(*addr); @@ -291,9 +238,26 @@ setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) { } static int -nm_setup(void **state __attribute__((unused))) { +setup_test(void **state __attribute__((unused))) { + char *env_workers = getenv("ISC_TASK_WORKERS"); uv_os_sock_t tcp_listen_sock = -1; uv_os_sock_t udp_listen_sock = -1; + size_t nworkers; + + if (env_workers != NULL) { + workers = atoi(env_workers); + } else { + workers = isc_os_ncpus(); + } + INSIST(workers > 0); + nworkers = ISC_MAX(ISC_MIN(workers, 32), 1); + + if (getenv("CI") != NULL && getenv("CI_ENABLE_ALL_TESTS") == NULL) { + skip_long_tests = true; + esends = nworkers; + } else { + esends = NSENDS * nworkers; + } udp_connect_addr = (isc_sockaddr_t){ .length = 0 }; isc_sockaddr_fromin6(&udp_connect_addr, &in6addr_loopback, 0); @@ -343,12 +307,12 @@ nm_setup(void **state __attribute__((unused))) { return (-1); } - isc__netmgr_create(test_mctx, workers, &listen_nm); + isc__netmgr_create(mctx, nworkers, &listen_nm); assert_non_null(listen_nm); isc_nm_settimeouts(listen_nm, T_INIT, T_IDLE, T_KEEPALIVE, T_ADVERTISED); - isc__netmgr_create(test_mctx, workers, &connect_nm); + isc__netmgr_create(mctx, nworkers, &connect_nm); assert_non_null(connect_nm); isc_nm_settimeouts(connect_nm, T_INIT, T_IDLE, T_KEEPALIVE, T_ADVERTISED); @@ -359,19 +323,38 @@ nm_setup(void **state __attribute__((unused))) { connect_readcb = connect_read_cb; noanswer = false; + if (isc_tlsctx_createserver(NULL, NULL, &tcp_listen_tlsctx) != + ISC_R_SUCCESS) { + return (-1); + } + if (isc_tlsctx_createclient(&tcp_connect_tlsctx) != ISC_R_SUCCESS) { + return (-1); + } + + isc_tlsctx_enable_dot_client_alpn(tcp_connect_tlsctx); + + tcp_tlsctx_client_sess_cache = isc_tlsctx_client_session_cache_new( + mctx, tcp_connect_tlsctx, + ISC_TLSCTX_CLIENT_SESSION_CACHE_DEFAULT_SIZE); + return (0); } static int -nm_teardown(void **state __attribute__((unused))) { +teardown_test(void **state __attribute__((unused))) { UNUSED(state); + isc_tlsctx_free(&tcp_connect_tlsctx); + isc_tlsctx_free(&tcp_listen_tlsctx); + isc__netmgr_destroy(&connect_nm); assert_null(connect_nm); isc__netmgr_destroy(&listen_nm); assert_null(listen_nm); + isc_tlsctx_client_session_cache_detach(&tcp_tlsctx_client_sess_cache); + WAIT_FOR_EQ(active_cconnects, 0); WAIT_FOR_EQ(active_csends, 0); WAIT_FOR_EQ(active_csends, 0); @@ -614,7 +597,7 @@ connect_thread(isc_threadarg_t arg) { * start slowing down the connections to prevent the * thundering herd problem. */ - isc_test_nap((active - workers) * 1000); + isc_test_nap(active - workers); } connect(connect_nm); } @@ -630,8 +613,7 @@ udp_connect(isc_nm_t *nm) { connect_connect_cb, NULL, T_CONNECT); } -static void -mock_listenudp_uv_udp_open(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(mock_listenudp_uv_udp_open) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -646,8 +628,7 @@ mock_listenudp_uv_udp_open(void **state __attribute__((unused))) { RESET_RETURN; } -static void -mock_listenudp_uv_udp_bind(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(mock_listenudp_uv_udp_bind) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -662,8 +643,7 @@ mock_listenudp_uv_udp_bind(void **state __attribute__((unused))) { RESET_RETURN; } -static void -mock_listenudp_uv_udp_recv_start(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(mock_listenudp_uv_udp_recv_start) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -678,8 +658,7 @@ mock_listenudp_uv_udp_recv_start(void **state __attribute__((unused))) { RESET_RETURN; } -static void -mock_udpconnect_uv_udp_open(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(mock_udpconnect_uv_udp_open) { WILL_RETURN(uv_udp_open, UV_ENOMEM); connect_readcb = NULL; @@ -691,8 +670,7 @@ mock_udpconnect_uv_udp_open(void **state __attribute__((unused))) { RESET_RETURN; } -static void -mock_udpconnect_uv_udp_bind(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(mock_udpconnect_uv_udp_bind) { WILL_RETURN(uv_udp_bind, UV_ENOMEM); connect_readcb = NULL; @@ -705,8 +683,7 @@ mock_udpconnect_uv_udp_bind(void **state __attribute__((unused))) { } #if UV_VERSION_HEX >= UV_VERSION(1, 27, 0) -static void -mock_udpconnect_uv_udp_connect(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(mock_udpconnect_uv_udp_connect) { WILL_RETURN(uv_udp_connect, UV_ENOMEM); connect_readcb = NULL; @@ -719,8 +696,7 @@ mock_udpconnect_uv_udp_connect(void **state __attribute__((unused))) { } #endif -static void -mock_udpconnect_uv_recv_buffer_size(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(mock_udpconnect_uv_recv_buffer_size) { WILL_RETURN(uv_recv_buffer_size, UV_ENOMEM); connect_readcb = NULL; @@ -732,8 +708,7 @@ mock_udpconnect_uv_recv_buffer_size(void **state __attribute__((unused))) { RESET_RETURN; } -static void -mock_udpconnect_uv_send_buffer_size(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(mock_udpconnect_uv_send_buffer_size) { WILL_RETURN(uv_send_buffer_size, UV_ENOMEM); connect_readcb = NULL; @@ -745,8 +720,7 @@ mock_udpconnect_uv_send_buffer_size(void **state __attribute__((unused))) { RESET_RETURN; } -static void -udp_noop(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(udp_noop) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -772,8 +746,7 @@ udp_noop(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 0); } -static void -udp_noresponse(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(udp_noresponse) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -829,8 +802,7 @@ timeout_retry_cb(isc_nmhandle_t *handle, isc_result_t eresult, isc_nmhandle_detach(&handle); } -static void -udp_timeout_recovery(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(udp_timeout_recovery) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -868,8 +840,7 @@ udp_timeout_recovery(void **state __attribute__((unused))) { isc__netmgr_shutdown(connect_nm); } -static void -udp_recv_one(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(udp_recv_one) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -909,8 +880,7 @@ udp_recv_one(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 0); } -static void -udp_recv_two(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(udp_recv_two) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -956,8 +926,7 @@ udp_recv_two(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 1); } -static void -udp_recv_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(udp_recv_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -1002,8 +971,7 @@ udp_recv_send(void **state __attribute__((unused))) { CHECK_RANGE_FULL(ssends); } -static void -udp_recv_half_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(udp_recv_half_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -1049,8 +1017,7 @@ udp_recv_half_send(void **state __attribute__((unused))) { CHECK_RANGE_HALF(ssends); } -static void -udp_half_recv_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(udp_half_recv_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -1078,7 +1045,7 @@ udp_half_recv_send(void **state __attribute__((unused))) { assert_null(listen_sock); /* Try to send a little while longer */ - isc_test_nap((esends / 2) * 10000); + isc_test_nap((esends / 2) * 10); isc__netmgr_shutdown(connect_nm); @@ -1099,8 +1066,7 @@ udp_half_recv_send(void **state __attribute__((unused))) { CHECK_RANGE_HALF(ssends); } -static void -udp_half_recv_half_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(udp_half_recv_half_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -1525,7 +1491,7 @@ stream_half_recv_send(void **state __attribute__((unused))) { assert_null(listen_sock); /* Try to send a little while longer */ - isc_test_nap((esends / 2) * 10000); + isc_test_nap((esends / 2) * 10); isc__netmgr_shutdown(connect_nm); @@ -1597,147 +1563,114 @@ stream_half_recv_half_send(void **state __attribute__((unused))) { } /* TCP */ -static void -tcp_noop(void **state) { - stream_noop(state); -} +ISC_RUN_TEST_IMPL(tcp_noop) { stream_noop(state); } -static void -tcp_noresponse(void **state) { - stream_noresponse(state); -} +ISC_RUN_TEST_IMPL(tcp_noresponse) { stream_noresponse(state); } -static void -tcp_timeout_recovery(void **state) { - stream_timeout_recovery(state); -} +ISC_RUN_TEST_IMPL(tcp_timeout_recovery) { stream_timeout_recovery(state); } -static void -tcp_recv_one(void **state) { - stream_recv_one(state); -} +ISC_RUN_TEST_IMPL(tcp_recv_one) { stream_recv_one(state); } -static void -tcp_recv_two(void **state) { - stream_recv_two(state); -} +ISC_RUN_TEST_IMPL(tcp_recv_two) { stream_recv_two(state); } -static void -tcp_recv_send(void **state) { +ISC_RUN_TEST_IMPL(tcp_recv_send) { SKIP_IN_CI; stream_recv_send(state); } -static void -tcp_recv_half_send(void **state) { +ISC_RUN_TEST_IMPL(tcp_recv_half_send) { SKIP_IN_CI; stream_recv_half_send(state); } -static void -tcp_half_recv_send(void **state) { +ISC_RUN_TEST_IMPL(tcp_half_recv_send) { SKIP_IN_CI; stream_half_recv_send(state); } -static void -tcp_half_recv_half_send(void **state) { +ISC_RUN_TEST_IMPL(tcp_half_recv_half_send) { SKIP_IN_CI; stream_half_recv_half_send(state); } -static void -tcp_recv_send_sendback(void **state) { +ISC_RUN_TEST_IMPL(tcp_recv_send_sendback) { SKIP_IN_CI; stream_recv_send(state); } -static void -tcp_recv_half_send_sendback(void **state) { +ISC_RUN_TEST_IMPL(tcp_recv_half_send_sendback) { SKIP_IN_CI; stream_recv_half_send(state); } -static void -tcp_half_recv_send_sendback(void **state) { +ISC_RUN_TEST_IMPL(tcp_half_recv_send_sendback) { SKIP_IN_CI; stream_half_recv_send(state); } -static void -tcp_half_recv_half_send_sendback(void **state) { +ISC_RUN_TEST_IMPL(tcp_half_recv_half_send_sendback) { SKIP_IN_CI; stream_half_recv_half_send(state); } /* TCP Quota */ -static void -tcp_recv_one_quota(void **state) { +ISC_RUN_TEST_IMPL(tcp_recv_one_quota) { atomic_store(&check_listener_quota, true); stream_recv_one(state); } -static void -tcp_recv_two_quota(void **state) { +ISC_RUN_TEST_IMPL(tcp_recv_two_quota) { atomic_store(&check_listener_quota, true); stream_recv_two(state); } -static void -tcp_recv_send_quota(void **state) { +ISC_RUN_TEST_IMPL(tcp_recv_send_quota) { SKIP_IN_CI; atomic_store(&check_listener_quota, true); stream_recv_send(state); } -static void -tcp_recv_half_send_quota(void **state) { +ISC_RUN_TEST_IMPL(tcp_recv_half_send_quota) { SKIP_IN_CI; atomic_store(&check_listener_quota, true); stream_recv_half_send(state); } -static void -tcp_half_recv_send_quota(void **state) { +ISC_RUN_TEST_IMPL(tcp_half_recv_send_quota) { SKIP_IN_CI; atomic_store(&check_listener_quota, true); stream_half_recv_send(state); } -static void -tcp_half_recv_half_send_quota(void **state) { +ISC_RUN_TEST_IMPL(tcp_half_recv_half_send_quota) { SKIP_IN_CI; atomic_store(&check_listener_quota, true); stream_half_recv_half_send(state); } -static void -tcp_recv_send_quota_sendback(void **state) { +ISC_RUN_TEST_IMPL(tcp_recv_send_quota_sendback) { SKIP_IN_CI; atomic_store(&check_listener_quota, true); allow_send_back = true; stream_recv_send(state); } -static void -tcp_recv_half_send_quota_sendback(void **state) { +ISC_RUN_TEST_IMPL(tcp_recv_half_send_quota_sendback) { SKIP_IN_CI; atomic_store(&check_listener_quota, true); allow_send_back = true; stream_recv_half_send(state); } -static void -tcp_half_recv_send_quota_sendback(void **state) { +ISC_RUN_TEST_IMPL(tcp_half_recv_send_quota_sendback) { SKIP_IN_CI; atomic_store(&check_listener_quota, true); allow_send_back = true; stream_half_recv_send(state); } -static void -tcp_half_recv_half_send_quota_sendback(void **state) { +ISC_RUN_TEST_IMPL(tcp_half_recv_half_send_quota_sendback) { SKIP_IN_CI; atomic_store(&check_listener_quota, true); allow_send_back = true; @@ -1752,8 +1685,7 @@ tcpdns_connect(isc_nm_t *nm) { connect_connect_cb, NULL, T_CONNECT); } -static void -tcpdns_noop(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tcpdns_noop) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -1779,8 +1711,7 @@ tcpdns_noop(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 0); } -static void -tcpdns_noresponse(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tcpdns_noresponse) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -1790,7 +1721,7 @@ tcpdns_noresponse(void **state __attribute__((unused))) { NULL, noop_accept_cb, NULL, 0, NULL, &listen_sock); if (result != ISC_R_SUCCESS) { isc_refcount_decrement(&active_cconnects); - isc_test_nap(1000); + isc_test_nap(1); } assert_int_equal(result, ISC_R_SUCCESS); @@ -1818,8 +1749,7 @@ tcpdns_noresponse(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 0); } -static void -tcpdns_timeout_recovery(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tcpdns_timeout_recovery) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -1860,8 +1790,7 @@ tcpdns_timeout_recovery(void **state __attribute__((unused))) { isc__netmgr_shutdown(connect_nm); } -static void -tcpdns_recv_one(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tcpdns_recv_one) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -1901,8 +1830,7 @@ tcpdns_recv_one(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 0); } -static void -tcpdns_recv_two(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tcpdns_recv_two) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -1949,8 +1877,7 @@ tcpdns_recv_two(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 1); } -static void -tcpdns_recv_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tcpdns_recv_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -1995,8 +1922,7 @@ tcpdns_recv_send(void **state __attribute__((unused))) { CHECK_RANGE_FULL(ssends); } -static void -tcpdns_recv_half_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tcpdns_recv_half_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -2042,8 +1968,7 @@ tcpdns_recv_half_send(void **state __attribute__((unused))) { CHECK_RANGE_HALF(ssends); } -static void -tcpdns_half_recv_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tcpdns_half_recv_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -2071,7 +1996,7 @@ tcpdns_half_recv_send(void **state __attribute__((unused))) { assert_null(listen_sock); /* Try to send a little while longer */ - isc_test_nap((esends / 2) * 10000); + isc_test_nap((esends / 2) * 10); isc__netmgr_shutdown(connect_nm); @@ -2092,8 +2017,7 @@ tcpdns_half_recv_send(void **state __attribute__((unused))) { CHECK_RANGE_HALF(ssends); } -static void -tcpdns_half_recv_half_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tcpdns_half_recv_half_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -2148,90 +2072,77 @@ tls_connect(isc_nm_t *nm) { tcp_tlsctx_client_sess_cache, T_CONNECT); } -static void -tls_noop(void **state) { +ISC_RUN_TEST_IMPL(tls_noop) { stream_use_TLS = true; stream_noop(state); } -static void -tls_noresponse(void **state) { +ISC_RUN_TEST_IMPL(tls_noresponse) { stream_use_TLS = true; stream_noresponse(state); } -static void -tls_timeout_recovery(void **state) { +ISC_RUN_TEST_IMPL(tls_timeout_recovery) { stream_use_TLS = true; stream_timeout_recovery(state); } -static void -tls_recv_one(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_one) { stream_use_TLS = true; stream_recv_one(state); } -static void -tls_recv_two(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_two) { stream_use_TLS = true; stream_recv_two(state); } -static void -tls_recv_send(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_send) { SKIP_IN_CI; stream_use_TLS = true; stream_recv_send(state); } -static void -tls_recv_half_send(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_half_send) { SKIP_IN_CI; stream_use_TLS = true; stream_recv_half_send(state); } -static void -tls_half_recv_send(void **state) { +ISC_RUN_TEST_IMPL(tls_half_recv_send) { SKIP_IN_CI; stream_use_TLS = true; stream_half_recv_send(state); } -static void -tls_half_recv_half_send(void **state) { +ISC_RUN_TEST_IMPL(tls_half_recv_half_send) { SKIP_IN_CI; stream_use_TLS = true; stream_half_recv_half_send(state); } -static void -tls_recv_send_sendback(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_send_sendback) { SKIP_IN_CI; stream_use_TLS = true; allow_send_back = true; stream_recv_send(state); } -static void -tls_recv_half_send_sendback(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_half_send_sendback) { SKIP_IN_CI; stream_use_TLS = true; allow_send_back = true; stream_recv_half_send(state); } -static void -tls_half_recv_send_sendback(void **state) { +ISC_RUN_TEST_IMPL(tls_half_recv_send_sendback) { SKIP_IN_CI; stream_use_TLS = true; allow_send_back = true; stream_half_recv_send(state); } -static void -tls_half_recv_half_send_sendback(void **state) { +ISC_RUN_TEST_IMPL(tls_half_recv_half_send_sendback) { SKIP_IN_CI; stream_use_TLS = true; allow_send_back = true; @@ -2240,54 +2151,47 @@ tls_half_recv_half_send_sendback(void **state) { /* TLS quota */ -static void -tls_recv_one_quota(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_one_quota) { stream_use_TLS = true; atomic_store(&check_listener_quota, true); stream_recv_one(state); } -static void -tls_recv_two_quota(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_two_quota) { stream_use_TLS = true; atomic_store(&check_listener_quota, true); stream_recv_two(state); } -static void -tls_recv_send_quota(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_send_quota) { SKIP_IN_CI; stream_use_TLS = true; atomic_store(&check_listener_quota, true); stream_recv_send(state); } -static void -tls_recv_half_send_quota(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_half_send_quota) { SKIP_IN_CI; stream_use_TLS = true; atomic_store(&check_listener_quota, true); stream_recv_half_send(state); } -static void -tls_half_recv_send_quota(void **state) { +ISC_RUN_TEST_IMPL(tls_half_recv_send_quota) { SKIP_IN_CI; stream_use_TLS = true; atomic_store(&check_listener_quota, true); stream_half_recv_send(state); } -static void -tls_half_recv_half_send_quota(void **state) { +ISC_RUN_TEST_IMPL(tls_half_recv_half_send_quota) { SKIP_IN_CI; stream_use_TLS = true; atomic_store(&check_listener_quota, true); stream_half_recv_half_send(state); } -static void -tls_recv_send_quota_sendback(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_send_quota_sendback) { SKIP_IN_CI; stream_use_TLS = true; allow_send_back = true; @@ -2295,8 +2199,7 @@ tls_recv_send_quota_sendback(void **state) { stream_recv_send(state); } -static void -tls_recv_half_send_quota_sendback(void **state) { +ISC_RUN_TEST_IMPL(tls_recv_half_send_quota_sendback) { SKIP_IN_CI; stream_use_TLS = true; allow_send_back = true; @@ -2304,8 +2207,7 @@ tls_recv_half_send_quota_sendback(void **state) { stream_recv_half_send(state); } -static void -tls_half_recv_send_quota_sendback(void **state) { +ISC_RUN_TEST_IMPL(tls_half_recv_send_quota_sendback) { SKIP_IN_CI; stream_use_TLS = true; allow_send_back = true; @@ -2313,8 +2215,7 @@ tls_half_recv_send_quota_sendback(void **state) { stream_half_recv_send(state); } -static void -tls_half_recv_half_send_quota_sendback(void **state) { +ISC_RUN_TEST_IMPL(tls_half_recv_half_send_quota_sendback) { SKIP_IN_CI; stream_use_TLS = true; allow_send_back = true; @@ -2332,8 +2233,7 @@ tlsdns_connect(isc_nm_t *nm) { tcp_connect_tlsctx, tcp_tlsctx_client_sess_cache); } -static void -tlsdns_noop(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_noop) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -2362,8 +2262,7 @@ tlsdns_noop(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 0); } -static void -tlsdns_noresponse(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_noresponse) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_sockaddr_t connect_addr; @@ -2403,8 +2302,7 @@ tlsdns_noresponse(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 0); } -static void -tlsdns_timeout_recovery(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_timeout_recovery) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_sockaddr_t connect_addr; @@ -2451,8 +2349,7 @@ tlsdns_timeout_recovery(void **state __attribute__((unused))) { isc__netmgr_shutdown(connect_nm); } -static void -tlsdns_recv_one(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_recv_one) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -2494,8 +2391,7 @@ tlsdns_recv_one(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 0); } -static void -tlsdns_recv_two(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_recv_two) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -2545,8 +2441,7 @@ tlsdns_recv_two(void **state __attribute__((unused))) { atomic_assert_int_eq(ssends, 1); } -static void -tlsdns_recv_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_recv_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -2592,8 +2487,7 @@ tlsdns_recv_send(void **state __attribute__((unused))) { CHECK_RANGE_FULL(ssends); } -static void -tlsdns_recv_half_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_recv_half_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -2640,8 +2534,7 @@ tlsdns_recv_half_send(void **state __attribute__((unused))) { CHECK_RANGE_HALF(ssends); } -static void -tlsdns_half_recv_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_half_recv_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -2670,7 +2563,7 @@ tlsdns_half_recv_send(void **state __attribute__((unused))) { assert_null(listen_sock); /* Try to send a little while longer */ - isc_test_nap((esends / 2) * 10000); + isc_test_nap((esends / 2) * 10); isc__netmgr_shutdown(connect_nm); @@ -2691,8 +2584,7 @@ tlsdns_half_recv_send(void **state __attribute__((unused))) { CHECK_RANGE_HALF(ssends); } -static void -tlsdns_half_recv_half_send(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_half_recv_half_send) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_thread_t threads[workers]; @@ -2764,8 +2656,7 @@ tlsdns_connect_connect_noalpn(isc_nmhandle_t *handle, isc_result_t eresult, connect_send(handle); } -static void -tlsdns_connect_noalpn(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_connect_noalpn) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_sockaddr_t connect_addr; @@ -2830,8 +2721,7 @@ tls_accept_cb_noalpn(isc_nmhandle_t *handle, isc_result_t eresult, return (stream_accept_cb(handle, eresult, cbarg)); } -static void -tlsdns_listen_noalpn(void **state __attribute__((unused))) { +ISC_RUN_TEST_IMPL(tlsdns_listen_noalpn) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; isc_sockaddr_t connect_addr; @@ -2881,218 +2771,120 @@ tlsdns_listen_noalpn(void **state __attribute__((unused))) { } #endif /* HAVE_LIBNGHTTP2 */ -int -main(void) { - const struct CMUnitTest tests[] = { - /* UDP */ - cmocka_unit_test_setup_teardown(mock_listenudp_uv_udp_open, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(mock_listenudp_uv_udp_bind, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown( - mock_listenudp_uv_udp_recv_start, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(mock_udpconnect_uv_udp_open, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(mock_udpconnect_uv_udp_bind, - nm_setup, nm_teardown), +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(mock_listenudp_uv_udp_open, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(mock_listenudp_uv_udp_bind, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(mock_listenudp_uv_udp_recv_start, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(mock_udpconnect_uv_udp_open, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(mock_udpconnect_uv_udp_bind, setup_test, teardown_test) #if UV_VERSION_HEX >= UV_VERSION(1, 27, 0) - cmocka_unit_test_setup_teardown(mock_udpconnect_uv_udp_connect, - nm_setup, nm_teardown), +ISC_TEST_ENTRY_CUSTOM(mock_udpconnect_uv_udp_connect, setup_test, teardown_test) #endif - cmocka_unit_test_setup_teardown( - mock_udpconnect_uv_recv_buffer_size, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - mock_udpconnect_uv_send_buffer_size, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(udp_noop, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(udp_noresponse, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(udp_timeout_recovery, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(udp_recv_one, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(udp_recv_two, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(udp_recv_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(udp_recv_half_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(udp_half_recv_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(udp_half_recv_half_send, - nm_setup, nm_teardown), +ISC_TEST_ENTRY_CUSTOM(mock_udpconnect_uv_recv_buffer_size, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(mock_udpconnect_uv_send_buffer_size, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(udp_noop, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(udp_noresponse, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(udp_timeout_recovery, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(udp_recv_one, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(udp_recv_two, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(udp_recv_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(udp_recv_half_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(udp_half_recv_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(udp_half_recv_half_send, setup_test, teardown_test) - /* TCP */ - cmocka_unit_test_setup_teardown(tcp_noop, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_noresponse, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_timeout_recovery, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_recv_one, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_recv_two, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_recv_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_recv_half_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_half_recv_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_half_recv_half_send, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tcp_recv_send_sendback, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tcp_recv_half_send_sendback, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tcp_half_recv_send_sendback, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown( - tcp_half_recv_half_send_sendback, nm_setup, - nm_teardown), +/* TCP */ +ISC_TEST_ENTRY_CUSTOM(tcp_noop, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_noresponse, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_timeout_recovery, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_one, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_two, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_half_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_half_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_send_sendback, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_half_send_sendback, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_send_sendback, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_half_send_sendback, setup_test, + teardown_test) - /* TCP Quota */ - cmocka_unit_test_setup_teardown(tcp_recv_one_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_recv_two_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_recv_send_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcp_recv_half_send_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tcp_half_recv_send_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tcp_half_recv_half_send_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tcp_recv_send_quota_sendback, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown( - tcp_recv_half_send_quota_sendback, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - tcp_half_recv_send_quota_sendback, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - tcp_half_recv_half_send_quota_sendback, nm_setup, - nm_teardown), +/* TCP Quota */ +ISC_TEST_ENTRY_CUSTOM(tcp_recv_one_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_two_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_send_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_half_send_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_send_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_half_send_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_send_quota_sendback, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_recv_half_send_quota_sendback, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_send_quota_sendback, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_half_send_quota_sendback, setup_test, + teardown_test) - /* TCPDNS */ - cmocka_unit_test_setup_teardown(tcpdns_recv_one, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcpdns_recv_two, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcpdns_noop, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcpdns_noresponse, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcpdns_timeout_recovery, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tcpdns_recv_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcpdns_recv_half_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcpdns_half_recv_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tcpdns_half_recv_half_send, - nm_setup, nm_teardown), +/* TCPDNS */ +ISC_TEST_ENTRY_CUSTOM(tcpdns_recv_one, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcpdns_recv_two, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcpdns_noop, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcpdns_noresponse, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcpdns_timeout_recovery, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcpdns_recv_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcpdns_recv_half_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcpdns_half_recv_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tcpdns_half_recv_half_send, setup_test, teardown_test) #if HAVE_LIBNGHTTP2 - /* TLS */ - cmocka_unit_test_setup_teardown(tls_noop, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_noresponse, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_timeout_recovery, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_recv_one, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_recv_two, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_recv_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_recv_half_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_half_recv_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_half_recv_half_send, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tls_recv_send_sendback, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tls_recv_half_send_sendback, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tls_half_recv_send_sendback, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown( - tls_half_recv_half_send_sendback, nm_setup, - nm_teardown), +/* TLS */ +ISC_TEST_ENTRY_CUSTOM(tls_noop, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_noresponse, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_timeout_recovery, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_one, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_two, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_half_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_half_recv_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_half_recv_half_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_send_sendback, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_half_send_sendback, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_half_recv_send_sendback, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_half_recv_half_send_sendback, setup_test, + teardown_test) - /* TLS quota */ - cmocka_unit_test_setup_teardown(tls_recv_one_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_recv_two_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_recv_send_quota, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tls_recv_half_send_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tls_half_recv_send_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tls_half_recv_half_send_quota, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tls_recv_send_quota_sendback, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown( - tls_recv_half_send_quota_sendback, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - tls_half_recv_send_quota_sendback, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown( - tls_half_recv_half_send_quota_sendback, nm_setup, - nm_teardown), +/* TLS quota */ +ISC_TEST_ENTRY_CUSTOM(tls_recv_one_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_two_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_send_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_half_send_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_half_recv_send_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_half_recv_half_send_quota, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_send_quota_sendback, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_recv_half_send_quota_sendback, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_half_recv_send_quota_sendback, setup_test, + teardown_test) +ISC_TEST_ENTRY_CUSTOM(tls_half_recv_half_send_quota_sendback, setup_test, + teardown_test) #endif - /* TLSDNS */ - cmocka_unit_test_setup_teardown(tlsdns_recv_one, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tlsdns_recv_two, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tlsdns_noop, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tlsdns_noresponse, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tlsdns_timeout_recovery, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tlsdns_recv_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tlsdns_recv_half_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tlsdns_half_recv_send, nm_setup, - nm_teardown), - cmocka_unit_test_setup_teardown(tlsdns_half_recv_half_send, - nm_setup, nm_teardown), - cmocka_unit_test_setup_teardown(tlsdns_connect_noalpn, nm_setup, - nm_teardown), +/* TLSDNS */ +ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_one, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_two, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tlsdns_noop, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tlsdns_noresponse, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tlsdns_timeout_recovery, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_half_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tlsdns_half_recv_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tlsdns_half_recv_half_send, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(tlsdns_connect_noalpn, setup_test, teardown_test) #ifdef HAVE_LIBNGHTTP2 - cmocka_unit_test_setup_teardown(tlsdns_listen_noalpn, nm_setup, - nm_teardown), +ISC_TEST_ENTRY_CUSTOM(tlsdns_listen_noalpn, setup_test, teardown_test) #endif - }; - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} +ISC_TEST_LIST_END -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/parse_test.c b/tests/isc/parse_test.c similarity index 62% rename from lib/isc/tests/parse_test.c rename to tests/isc/parse_test.c index 378690dd9f..a5b516a027 100644 --- a/lib/isc/tests/parse_test.c +++ b/tests/isc/parse_test.c @@ -13,8 +13,6 @@ /*! \file */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -31,37 +29,13 @@ #include #include -#include "isctest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} +#include /* Test for 32 bit overflow on 64 bit machines in isc_parse_uint32 */ -static void -parse_overflow(void **state) { +ISC_RUN_TEST_IMPL(parse_overflow) { isc_result_t result; uint32_t output; - UNUSED(state); - result = isc_parse_uint32(&output, "1234567890", 10); assert_int_equal(ISC_R_SUCCESS, result); assert_int_equal(1234567890, output); @@ -73,24 +47,10 @@ parse_overflow(void **state) { assert_int_equal(ISC_R_RANGE, result); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(parse_overflow, _setup, - _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(parse_overflow) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/quota_test.c b/tests/isc/quota_test.c similarity index 89% rename from lib/isc/tests/quota_test.c rename to tests/isc/quota_test.c index 854afd92b5..d4ae843a4a 100644 --- a/lib/isc/tests/quota_test.c +++ b/tests/isc/quota_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -29,11 +27,11 @@ #include #include #include +#include -#include "isctest.h" +#include -static void -isc_quota_get_set_test(void **state) { +ISC_RUN_TEST_IMPL(isc_quota_get_set) { UNUSED(state); isc_quota_t quota; isc_quota_t *quota2 = NULL; @@ -79,8 +77,7 @@ add_quota(isc_quota_t *source, isc_quota_t **target, assert_int_equal(isc_quota_getused(source), expected_used); } -static void -isc_quota_hard_test(void **state) { +ISC_RUN_TEST_IMPL(isc_quota_hard) { isc_quota_t quota; isc_quota_t *quotas[110]; int i; @@ -111,8 +108,7 @@ isc_quota_hard_test(void **state) { isc_quota_destroy("a); } -static void -isc_quota_soft_test(void **state) { +ISC_RUN_TEST_IMPL(isc_quota_soft) { isc_quota_t quota; isc_quota_t *quotas[110]; int i; @@ -165,8 +161,7 @@ callback(isc_quota_t *quota, void *data) { } } -static void -isc_quota_callback_test(void **state) { +ISC_RUN_TEST_IMPL(isc_quota_callback) { isc_result_t result; isc_quota_t quota; isc_quota_t *quotas[30]; @@ -260,7 +255,7 @@ isc_thread_t g_threads[10 * 100]; static void * quota_detach(void *quotap) { isc_quota_t *quota = (isc_quota_t *)quotap; - isc_test_nap(10000); + uv_sleep(10); isc_quota_detach("a); return ((isc_threadresult_t)0); } @@ -291,8 +286,7 @@ quota_thread(void *qtip) { return ((isc_threadresult_t)0); } -static void -isc_quota_callback_mt_test(void **state) { +ISC_RUN_TEST_IMPL(isc_quota_callback_mt) { UNUSED(state); isc_quota_t quota; int i; @@ -313,14 +307,14 @@ isc_quota_callback_mt_test(void **state) { for (i = 0; i < (int)atomic_load(&g_tnum); i++) { isc_thread_join(g_threads[i], NULL); } - int direct = 0, callback = 0; + int direct = 0, ncallback = 0; for (i = 0; i < 10; i++) { direct += atomic_load(&qtis[i].direct); - callback += atomic_load(&qtis[i].callback); + ncallback += atomic_load(&qtis[i].callback); } /* Total quota gained must be 10 threads * 100 tries */ - assert_int_equal(direct + callback, 10 * 100); + assert_int_equal(direct + ncallback, 10 * 100); /* * At least 100 must be direct, the rest is virtually random: * - in a regular run I'm constantly getting 100:900 ratio @@ -332,27 +326,14 @@ isc_quota_callback_mt_test(void **state) { isc_quota_destroy("a); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_quota_get_set_test), - cmocka_unit_test(isc_quota_hard_test), - cmocka_unit_test(isc_quota_soft_test), - cmocka_unit_test(isc_quota_callback_test), - cmocka_unit_test(isc_quota_callback_mt_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_quota_get_set) +ISC_TEST_ENTRY(isc_quota_hard) +ISC_TEST_ENTRY(isc_quota_soft) +ISC_TEST_ENTRY(isc_quota_callback) +ISC_TEST_ENTRY(isc_quota_callback_mt) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/radix_test.c b/tests/isc/radix_test.c similarity index 71% rename from lib/isc/tests/radix_test.c rename to tests/isc/radix_test.c index 132b64d596..2fe9294d69 100644 --- a/lib/isc/tests/radix_test.c +++ b/tests/isc/radix_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -29,32 +27,10 @@ #include #include -#include "isctest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} +#include /* test radix searching */ -static void -isc_radix_search_test(void **state) { +ISC_RUN_TEST_IMPL(isc_radix_search) { isc_radix_tree_t *radix = NULL; isc_radix_node_t *node; isc_prefix_t prefix; @@ -64,7 +40,7 @@ isc_radix_search_test(void **state) { UNUSED(state); - result = isc_radix_create(test_mctx, &radix, 32); + result = isc_radix_create(mctx, &radix, 32); assert_int_equal(result, ISC_R_SUCCESS); in_addr.s_addr = inet_addr("3.3.3.0"); @@ -101,24 +77,9 @@ isc_radix_search_test(void **state) { isc_radix_destroy(radix, NULL); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(isc_radix_search_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_radix_search) -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_LIST_END +ISC_TEST_MAIN diff --git a/lib/isc/tests/random_test.c b/tests/isc/random_test.c similarity index 77% rename from lib/isc/tests/random_test.c rename to tests/isc/random_test.c index 040e1a5f77..8c41e97138 100644 --- a/lib/isc/tests/random_test.c +++ b/tests/isc/random_test.c @@ -18,8 +18,6 @@ * random. The test is expected to fail on occasion by random happenstance. */ -#if HAVE_CMOCKA - #include #include #include /* IWYU pragma: keep */ @@ -40,11 +38,11 @@ #include #include -#include "isctest.h" +#include #define REPS 25000 -typedef double(pvalue_func_t)(isc_mem_t *mctx, uint16_t *values, size_t length); +typedef double(pvalue_func_t)(uint16_t *values, size_t length); /* igamc(), igam(), etc. were adapted (and cleaned up) from the Cephes * math library: @@ -66,9 +64,6 @@ igamc(double a, double x); static double igam(double a, double x); -/* Set to true (or use -v option) for verbose output */ -static bool verbose = false; - typedef enum { ISC_RANDOM8, ISC_RANDOM16, @@ -78,31 +73,10 @@ typedef enum { ISC_NONCE_BYTES } isc_random_func; -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} - static double igamc(double a, double x) { - double ans, ax, c, yc, r, t, y, z; - double pk, pkm1, pkm2, qk, qkm1, qkm2; + double ans, ax, c, r, t, y, z; + double pkm1, pkm2, qkm1, qkm2; if ((x <= 0) || (a <= 0)) { return (1.0); @@ -130,6 +104,7 @@ igamc(double a, double x) { ans = pkm1 / qkm1; do { + double yc, pk, qk; c += 1.0; y += 1.0; z += 2.0; @@ -258,13 +233,12 @@ tables_init(void) { */ static uint32_t matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) { - size_t i, j, k; unsigned int rt = 0; uint32_t rank = 0; uint32_t tmp; - for (k = 0; k < rows; k++) { - i = k; + for (size_t k = 0; k < rows; k++) { + size_t i = k; while (rt >= cols || ((bits[i] >> rt) & 1) == 0) { i++; @@ -289,7 +263,7 @@ matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) { bits[k] = tmp; } - for (j = i + 1; j < rows; j++) { + for (size_t j = i + 1; j < rows; j++) { if (((bits[j] >> rt) & 1) == 0) { continue; } else { @@ -363,7 +337,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) { break; } - p_value = (*func)(test_mctx, (uint16_t *)values, REPS * 2); + p_value = (*func)((uint16_t *)values, REPS * 2); if (p_value >= 0.01) { passed++; } @@ -384,13 +358,6 @@ random_test(pvalue_func_t *func, isc_random_func test_func) { lower_confidence = p_hat - (3.0 * sqrt((p_hat * (1.0 - p_hat)) / m)); higher_confidence = p_hat + (3.0 * sqrt((p_hat * (1.0 - p_hat)) / m)); - if (verbose) { - print_message("# passed=%u/1000\n", passed); - print_message("# higher_confidence=%f, lower_confidence=%f, " - "proportion=%f\n", - higher_confidence, lower_confidence, proportion); - } - assert_in_range(proportion, lower_confidence, higher_confidence); /* @@ -407,29 +374,17 @@ random_test(pvalue_func_t *func, isc_random_func test_func) { /* Pre-requisite that at least 55 sequences are processed. */ assert_true(m >= 55); - if (verbose) { - print_message("# "); - } - chi_square = 0.0; for (j = 0; j < 10; j++) { double numer; double denom; - if (verbose) { - print_message("hist%u=%u ", j, histogram[j]); - } - numer = (histogram[j] - (m / 10.0)) * (histogram[j] - (m / 10.0)); denom = m / 10.0; chi_square += numer / denom; } - if (verbose) { - print_message("\n"); - } - p_value_t = igamc(9 / 2.0, chi_square / 2.0); assert_true(p_value_t >= 0.0001); @@ -440,7 +395,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) { * RANDOM test suite. */ static double -monobit(isc_mem_t *mctx, uint16_t *values, size_t length) { +monobit(uint16_t *values, size_t length) { size_t i; int32_t scount; uint32_t numbits; @@ -459,10 +414,6 @@ monobit(isc_mem_t *mctx, uint16_t *values, size_t length) { /* Preconditions (section 2.1.7 in NIST SP 800-22) */ assert_true(numbits >= 100); - if (verbose) { - print_message("# numbits=%u, scount=%d\n", numbits, scount); - } - s_obs = abs(scount) / sqrt(numbits); p_value = erfc(s_obs / sqrt(2.0)); @@ -473,7 +424,7 @@ monobit(isc_mem_t *mctx, uint16_t *values, size_t length) { * This is the runs test taken from the NIST SP 800-22 RNG test suite. */ static double -runs(isc_mem_t *mctx, uint16_t *values, size_t length) { +runs(uint16_t *values, size_t length) { size_t i; uint32_t bcount; uint32_t numbits; @@ -481,7 +432,6 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) { double tau; uint32_t j; uint32_t b; - uint8_t bit_this; uint8_t bit_prev; uint32_t v_obs; double numer; @@ -497,10 +447,6 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) { bcount += bitcounts_table[values[i]]; } - if (verbose) { - print_message("# numbits=%u, bcount=%u\n", numbits, bcount); - } - pi = (double)bcount / (double)numbits; tau = 2.0 / sqrt(numbits); @@ -524,7 +470,7 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) { v_obs = 0; for (i = 1; i < numbits; i++) { - bit_this = (values[j] & (1U << b)) == 0 ? 0 : 1; + uint8_t bit_this = (values[j] & (1U << b)) == 0 ? 0 : 1; if (b == 0) { b = 15; j++; @@ -552,7 +498,7 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) { * test suite. */ static double -blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) { +blockfrequency(uint16_t *values, size_t length) { uint32_t i; uint32_t numbits; uint32_t mbits; @@ -567,10 +513,6 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) { mwords = mbits / 16; numblocks = numbits / mbits; - if (verbose) { - print_message("# numblocks=%u\n", numblocks); - } - /* Preconditions (section 2.2.7 in NIST SP 800-22) */ assert_true(numbits >= 100); assert_true(mbits >= 20); @@ -603,10 +545,6 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) { isc_mem_put(mctx, pi, numblocks * sizeof(double)); - if (verbose) { - print_message("# chi_square=%f\n", chi_square); - } - p_value = igamc(numblocks * 0.5, chi_square * 0.5); return (p_value); @@ -617,7 +555,7 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) { * test suite. */ static double -binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) { +binarymatrixrank(uint16_t *values, size_t length) { uint32_t i; size_t matrix_m; size_t matrix_q; @@ -693,11 +631,6 @@ binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) { chi_square = term1 + term2 + term3; - if (verbose) { - print_message("# fm_0=%u, fm_1=%u, fm_rest=%u, chi_square=%f\n", - fm_0, fm_1, fm_rest, chi_square); - } - p_value = exp(-chi_square * 0.5); return (p_value); @@ -708,32 +641,28 @@ binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) { ***/ /* Monobit test for the RANDOM */ -static void -isc_random32_monobit(void **state) { +ISC_RUN_TEST_IMPL(isc_random32_monobit) { UNUSED(state); random_test(monobit, ISC_RANDOM32); } /* Runs test for the RANDOM */ -static void -isc_random32_runs(void **state) { +ISC_RUN_TEST_IMPL(isc_random32_runs) { UNUSED(state); random_test(runs, ISC_RANDOM32); } /* Block frequency test for the RANDOM */ -static void -isc_random32_blockfrequency(void **state) { +ISC_RUN_TEST_IMPL(isc_random32_blockfrequency) { UNUSED(state); random_test(blockfrequency, ISC_RANDOM32); } /* Binary matrix rank test for the RANDOM */ -static void -isc_random32_binarymatrixrank(void **state) { +ISC_RUN_TEST_IMPL(isc_random32_binarymatrixrank) { UNUSED(state); random_test(binarymatrixrank, ISC_RANDOM32); @@ -744,32 +673,28 @@ isc_random32_binarymatrixrank(void **state) { ***/ /* Monobit test for the RANDOM */ -static void -isc_random_bytes_monobit(void **state) { +ISC_RUN_TEST_IMPL(isc_random_bytes_monobit) { UNUSED(state); random_test(monobit, ISC_RANDOM_BYTES); } /* Runs test for the RANDOM */ -static void -isc_random_bytes_runs(void **state) { +ISC_RUN_TEST_IMPL(isc_random_bytes_runs) { UNUSED(state); random_test(runs, ISC_RANDOM_BYTES); } /* Block frequency test for the RANDOM */ -static void -isc_random_bytes_blockfrequency(void **state) { +ISC_RUN_TEST_IMPL(isc_random_bytes_blockfrequency) { UNUSED(state); random_test(blockfrequency, ISC_RANDOM_BYTES); } /* Binary matrix rank test for the RANDOM */ -static void -isc_random_bytes_binarymatrixrank(void **state) { +ISC_RUN_TEST_IMPL(isc_random_bytes_binarymatrixrank) { UNUSED(state); random_test(binarymatrixrank, ISC_RANDOM_BYTES); @@ -780,32 +705,28 @@ isc_random_bytes_binarymatrixrank(void **state) { ***/ /* Monobit test for the RANDOM */ -static void -isc_random_uniform_monobit(void **state) { +ISC_RUN_TEST_IMPL(isc_random_uniform_monobit) { UNUSED(state); random_test(monobit, ISC_RANDOM_UNIFORM); } /* Runs test for the RANDOM */ -static void -isc_random_uniform_runs(void **state) { +ISC_RUN_TEST_IMPL(isc_random_uniform_runs) { UNUSED(state); random_test(runs, ISC_RANDOM_UNIFORM); } /* Block frequency test for the RANDOM */ -static void -isc_random_uniform_blockfrequency(void **state) { +ISC_RUN_TEST_IMPL(isc_random_uniform_blockfrequency) { UNUSED(state); random_test(blockfrequency, ISC_RANDOM_UNIFORM); } /* Binary matrix rank test for the RANDOM */ -static void -isc_random_uniform_binarymatrixrank(void **state) { +ISC_RUN_TEST_IMPL(isc_random_uniform_binarymatrixrank) { UNUSED(state); random_test(binarymatrixrank, ISC_RANDOM_UNIFORM); @@ -814,80 +735,52 @@ isc_random_uniform_binarymatrixrank(void **state) { /* Tests for isc_nonce_bytes() function */ /* Monobit test for the RANDOM */ -static void -isc_nonce_bytes_monobit(void **state) { +ISC_RUN_TEST_IMPL(isc_nonce_bytes_monobit) { UNUSED(state); random_test(monobit, ISC_NONCE_BYTES); } /* Runs test for the RANDOM */ -static void -isc_nonce_bytes_runs(void **state) { +ISC_RUN_TEST_IMPL(isc_nonce_bytes_runs) { UNUSED(state); random_test(runs, ISC_NONCE_BYTES); } /* Block frequency test for the RANDOM */ -static void -isc_nonce_bytes_blockfrequency(void **state) { +ISC_RUN_TEST_IMPL(isc_nonce_bytes_blockfrequency) { UNUSED(state); random_test(blockfrequency, ISC_NONCE_BYTES); } /* Binary matrix rank test for the RANDOM */ -static void -isc_nonce_bytes_binarymatrixrank(void **state) { +ISC_RUN_TEST_IMPL(isc_nonce_bytes_binarymatrixrank) { UNUSED(state); random_test(binarymatrixrank, ISC_NONCE_BYTES); } -int -main(int argc, char **argv) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_random32_monobit), - cmocka_unit_test(isc_random32_runs), - cmocka_unit_test(isc_random32_blockfrequency), - cmocka_unit_test(isc_random32_binarymatrixrank), - cmocka_unit_test(isc_random_bytes_monobit), - cmocka_unit_test(isc_random_bytes_runs), - cmocka_unit_test(isc_random_bytes_blockfrequency), - cmocka_unit_test(isc_random_bytes_binarymatrixrank), - cmocka_unit_test(isc_random_uniform_monobit), - cmocka_unit_test(isc_random_uniform_runs), - cmocka_unit_test(isc_random_uniform_blockfrequency), - cmocka_unit_test(isc_random_uniform_binarymatrixrank), - cmocka_unit_test(isc_nonce_bytes_monobit), - cmocka_unit_test(isc_nonce_bytes_runs), - cmocka_unit_test(isc_nonce_bytes_blockfrequency), - cmocka_unit_test(isc_nonce_bytes_binarymatrixrank), - }; - int c; +ISC_TEST_LIST_START - while ((c = isc_commandline_parse(argc, argv, "v")) != -1) { - switch (c) { - case 'v': - verbose = true; - break; - default: - break; - } - } +ISC_TEST_ENTRY(isc_random32_monobit) +ISC_TEST_ENTRY(isc_random32_runs) +ISC_TEST_ENTRY(isc_random32_blockfrequency) +ISC_TEST_ENTRY(isc_random32_binarymatrixrank) +ISC_TEST_ENTRY(isc_random_bytes_monobit) +ISC_TEST_ENTRY(isc_random_bytes_runs) +ISC_TEST_ENTRY(isc_random_bytes_blockfrequency) +ISC_TEST_ENTRY(isc_random_bytes_binarymatrixrank) +ISC_TEST_ENTRY(isc_random_uniform_monobit) +ISC_TEST_ENTRY(isc_random_uniform_runs) +ISC_TEST_ENTRY(isc_random_uniform_blockfrequency) +ISC_TEST_ENTRY(isc_random_uniform_binarymatrixrank) +ISC_TEST_ENTRY(isc_nonce_bytes_monobit) +ISC_TEST_ENTRY(isc_nonce_bytes_runs) +ISC_TEST_ENTRY(isc_nonce_bytes_blockfrequency) +ISC_TEST_ENTRY(isc_nonce_bytes_binarymatrixrank) - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} +ISC_TEST_LIST_END -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/regex_test.c b/tests/isc/regex_test.c similarity index 98% rename from lib/isc/tests/regex_test.c rename to tests/isc/regex_test.c index 700df92105..dd44d3bc89 100644 --- a/lib/isc/tests/regex_test.c +++ b/tests/isc/regex_test.c @@ -11,8 +11,7 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - +#include /* IWYU pragma: keep */ #include #include #include @@ -33,12 +32,10 @@ #include #include -/* Set to true (or use -v option) for verbose output */ -static bool verbose = false; +#include /* test isc_regex_validate() */ -static void -regex_validate(void **state) { +ISC_RUN_TEST_IMPL(regex_validate) { /* * test regex were generated using http://code.google.com/p/regfuzz/ * modified to use only printable characters @@ -2303,23 +2300,10 @@ regex_validate(void **state) { (r == 0 && tests[i].expect == -1)) && !tests[i].exception) { - if (verbose) { - print_error("regcomp(%s) -> %s expected %s\n", - tests[i].expression, - r != 0 ? "bad" : "good", - tests[i].expect == -1 ? "bad" - : "good"); - } } else if (r == 0 && preg.re_nsub != (unsigned int)tests[i].expect && !tests[i].exception) { - if (verbose) { - print_error("%s preg.re_nsub %lu expected %d\n", - tests[i].expression, - (unsigned long)preg.re_nsub, - tests[i].expect); - } tests[i].expect = preg.re_nsub; } if (r == 0) { @@ -2341,34 +2325,10 @@ regex_validate(void **state) { } } -int -main(int argc, char **argv) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(regex_validate), - }; - int c; +ISC_TEST_LIST_START - while ((c = isc_commandline_parse(argc, argv, "v")) != -1) { - switch (c) { - case 'v': - verbose = true; - break; - default: - break; - } - } +ISC_TEST_ENTRY(regex_validate) - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_LIST_END -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/result_test.c b/tests/isc/result_test.c similarity index 69% rename from lib/isc/tests/result_test.c rename to tests/isc/result_test.c index 8de3c46c02..cca66b85d6 100644 --- a/lib/isc/tests/result_test.c +++ b/tests/isc/result_test.c @@ -11,8 +11,7 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - +#include /* IWYU pragma: keep */ #include #include #include @@ -26,9 +25,10 @@ #include #include +#include + /* convert result to identifier string */ -static void -isc_result_toid_test(void **state) { +ISC_RUN_TEST_IMPL(isc_result_toid) { const char *id; UNUSED(state); @@ -41,8 +41,7 @@ isc_result_toid_test(void **state) { } /* convert result to description string */ -static void -isc_result_totext_test(void **state) { +ISC_RUN_TEST_IMPL(isc_result_totext) { const char *str; UNUSED(state); @@ -54,24 +53,11 @@ isc_result_totext_test(void **state) { assert_string_equal("failure", str); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_result_toid_test), - cmocka_unit_test(isc_result_totext_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_result_toid) +ISC_TEST_ENTRY(isc_result_totext) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/safe_test.c b/tests/isc/safe_test.c similarity index 78% rename from lib/isc/tests/safe_test.c rename to tests/isc/safe_test.c index 89bd3ba8bd..39221649c2 100644 --- a/lib/isc/tests/safe_test.c +++ b/tests/isc/safe_test.c @@ -13,8 +13,6 @@ /* ! \file */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -28,9 +26,10 @@ #include #include +#include + /* test isc_safe_memequal() */ -static void -isc_safe_memequal_test(void **state) { +ISC_RUN_TEST_IMPL(isc_safe_memequal) { UNUSED(state); assert_true(isc_safe_memequal("test", "test", 4)); @@ -44,8 +43,7 @@ isc_safe_memequal_test(void **state) { } /* test isc_safe_memwipe() */ -static void -isc_safe_memwipe_test(void **state) { +ISC_RUN_TEST_IMPL(isc_safe_memwipe) { UNUSED(state); /* These should pass. */ @@ -84,24 +82,10 @@ isc_safe_memwipe_test(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_safe_memequal_test), - cmocka_unit_test(isc_safe_memwipe_test), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY(isc_safe_memequal) +ISC_TEST_ENTRY(isc_safe_memwipe) - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_LIST_END -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/siphash_test.c b/tests/isc/siphash_test.c similarity index 92% rename from lib/isc/tests/siphash_test.c rename to tests/isc/siphash_test.c index 72c7126858..5480afd791 100644 --- a/lib/isc/tests/siphash_test.c +++ b/tests/isc/siphash_test.c @@ -11,8 +11,7 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - +#include /* IWYU pragma: keep */ #include #include #include @@ -24,7 +23,9 @@ #include -#include "../siphash.c" +#include "siphash.c" + +#include const uint8_t vectors_sip64[64][8] = { { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72 }, @@ -128,8 +129,7 @@ const uint8_t vectors_hsip32[64][4] = { { 0xbd, 0x83, 0x99, 0x7a }, { 0x59, 0xea, 0x4a, 0x74 } }; -static void -isc_siphash24_test(void **state) { +ISC_RUN_TEST_IMPL(isc_siphash24) { UNUSED(state); uint8_t in[64], out[8], key[16]; @@ -144,8 +144,7 @@ isc_siphash24_test(void **state) { } } -static void -isc_halfsiphash24_test(void **state) { +ISC_RUN_TEST_IMPL(isc_halfsiphash24) { UNUSED(state); uint8_t in[64], out[4], key[16]; @@ -160,24 +159,11 @@ isc_halfsiphash24_test(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_siphash24_test), - cmocka_unit_test(isc_halfsiphash24_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_siphash24) +ISC_TEST_ENTRY(isc_halfsiphash24) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/sockaddr_test.c b/tests/isc/sockaddr_test.c similarity index 78% rename from lib/isc/tests/sockaddr_test.c rename to tests/isc/sockaddr_test.c index 6719a6ee3a..126bfa9fe4 100644 --- a/lib/isc/tests/sockaddr_test.c +++ b/tests/isc/sockaddr_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -30,32 +28,10 @@ #include #include -#include "isctest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} +#include /* test sockaddr hash */ -static void -sockaddr_hash(void **state) { +ISC_RUN_TEST_IMPL(sockaddr_hash) { isc_sockaddr_t addr; struct in_addr in; struct in6_addr in6; @@ -80,13 +56,12 @@ sockaddr_hash(void **state) { } /* test isc_sockaddr_isnetzero() */ -static void -sockaddr_isnetzero(void **state) { +ISC_RUN_TEST_IMPL(sockaddr_isnetzero) { isc_sockaddr_t addr; struct in_addr in; struct in6_addr in6; bool r; - int ret; + size_t i; struct { const char *string; @@ -123,7 +98,7 @@ sockaddr_isnetzero(void **state) { } for (i = 0; i < sizeof(data6) / sizeof(data6[0]); i++) { - ret = inet_pton(AF_INET6, data6[i].string, &in6); + int ret = inet_pton(AF_INET6, data6[i].string, &in6); assert_int_equal(ret, 1); isc_sockaddr_fromin6(&addr, &in6, 1); r = isc_sockaddr_isnetzero(&addr); @@ -135,8 +110,7 @@ sockaddr_isnetzero(void **state) { * test that isc_sockaddr_eqaddrprefix() returns true when prefixes of a * and b are equal, and false when they are not equal */ -static void -sockaddr_eqaddrprefix(void **state) { +ISC_RUN_TEST_IMPL(sockaddr_eqaddrprefix) { struct in_addr ina_a; struct in_addr ina_b; struct in_addr ina_c; @@ -163,26 +137,12 @@ sockaddr_eqaddrprefix(void **state) { assert_false(isc_sockaddr_eqaddrprefix(&isa_a, &isa_c, 16)); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(sockaddr_hash, _setup, - _teardown), - cmocka_unit_test(sockaddr_isnetzero), - cmocka_unit_test(sockaddr_eqaddrprefix), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(sockaddr_hash) +ISC_TEST_ENTRY(sockaddr_isnetzero) +ISC_TEST_ENTRY(sockaddr_eqaddrprefix) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/stats_test.c b/tests/isc/stats_test.c similarity index 76% rename from lib/isc/tests/stats_test.c rename to tests/isc/stats_test.c index 89b2462e8f..79d784e2df 100644 --- a/lib/isc/tests/stats_test.c +++ b/tests/isc/stats_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -28,38 +26,16 @@ #include #include -#include "isctest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} +#include /* test stats */ -static void -isc_stats_basic_test(void **state) { +ISC_RUN_TEST_IMPL(isc_stats_basic) { isc_stats_t *stats = NULL; isc_result_t result; UNUSED(state); - result = isc_stats_create(test_mctx, &stats, 4); + result = isc_stats_create(mctx, &stats, 4); assert_int_equal(result, ISC_R_SUCCESS); assert_int_equal(isc_stats_ncounters(stats), 4); @@ -118,24 +94,10 @@ isc_stats_basic_test(void **state) { isc_stats_detach(&stats); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(isc_stats_basic_test, _setup, - _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_stats_basic) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/symtab_test.c b/tests/isc/symtab_test.c similarity index 72% rename from lib/isc/tests/symtab_test.c rename to tests/isc/symtab_test.c index 4b8230887d..bcbc0c43bb 100644 --- a/lib/isc/tests/symtab_test.c +++ b/tests/isc/symtab_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -28,41 +26,19 @@ #include #include -#include "isctest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - UNUSED(state); - - isc_test_end(); - - return (0); -} +#include static void undefine(char *key, unsigned int type, isc_symvalue_t value, void *arg) { UNUSED(arg); assert_int_equal(type, 1); - isc_mem_free(test_mctx, key); - isc_mem_free(test_mctx, value.as_pointer); + isc_mem_free(mctx, key); + isc_mem_free(mctx, value.as_pointer); } /* test symbol table growth */ -static void -symtab_grow(void **state) { +ISC_RUN_TEST_IMPL(symtab_grow) { isc_result_t result; isc_symtab_t *st = NULL; isc_symvalue_t value; @@ -71,7 +47,7 @@ symtab_grow(void **state) { UNUSED(state); - result = isc_symtab_create(test_mctx, 3, undefine, NULL, false, &st); + result = isc_symtab_create(mctx, 3, undefine, NULL, false, &st); assert_int_equal(result, ISC_R_SUCCESS); assert_non_null(st); @@ -85,9 +61,9 @@ symtab_grow(void **state) { char str[16], *key; snprintf(str, sizeof(str), "%04x", i); - key = isc_mem_strdup(test_mctx, str); + key = isc_mem_strdup(mctx, str); assert_non_null(key); - value.as_pointer = isc_mem_strdup(test_mctx, str); + value.as_pointer = isc_mem_strdup(mctx, str); assert_non_null(value.as_pointer); result = isc_symtab_define(st, key, 1, value, policy); assert_int_equal(result, ISC_R_SUCCESS); @@ -103,9 +79,9 @@ symtab_grow(void **state) { char str[16], *key; snprintf(str, sizeof(str), "%04x", i); - key = isc_mem_strdup(test_mctx, str); + key = isc_mem_strdup(mctx, str); assert_non_null(key); - value.as_pointer = isc_mem_strdup(test_mctx, str); + value.as_pointer = isc_mem_strdup(mctx, str); assert_non_null(value.as_pointer); result = isc_symtab_define(st, key, 1, value, policy); assert_int_equal(result, ISC_R_EXISTS); @@ -149,23 +125,10 @@ symtab_grow(void **state) { isc_symtab_destroy(&st); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(symtab_grow, _setup, _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(symtab_grow) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/task_test.c b/tests/isc/task_test.c similarity index 78% rename from lib/isc/tests/task_test.c rename to tests/isc/task_test.c index b06e7158af..f7a20786d7 100644 --- a/lib/isc/tests/task_test.c +++ b/tests/isc/task_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -38,8 +36,9 @@ #include #include #include +#include -#include "isctest.h" +#include /* Set to true (or use -v option) for verbose output */ static bool verbose = false; @@ -53,60 +52,45 @@ static atomic_bool done; static int _setup(void **state) { - isc_result_t result; - - UNUSED(state); - isc_mutex_init(&lock); - isc_condition_init(&cv); - result = isc_test_begin(NULL, true, 0); - assert_int_equal(result, ISC_R_SUCCESS); + workers = 0; + setup_managers(state); return (0); } static int _setup2(void **state) { - isc_result_t result; - - UNUSED(state); - isc_mutex_init(&lock); - isc_condition_init(&cv); /* Two worker threads */ - result = isc_test_begin(NULL, true, 2); - assert_int_equal(result, ISC_R_SUCCESS); + workers = 2; + setup_managers(state); return (0); } static int _setup4(void **state) { - isc_result_t result; - - UNUSED(state); - isc_mutex_init(&lock); - isc_condition_init(&cv); /* Four worker threads */ - result = isc_test_begin(NULL, true, 4); - assert_int_equal(result, ISC_R_SUCCESS); + workers = 4; + setup_managers(state); return (0); } static int _teardown(void **state) { - UNUSED(state); + teardown_managers(state); - isc_test_end(); isc_condition_destroy(&cv); + isc_mutex_destroy(&lock); return (0); } @@ -124,8 +108,7 @@ set(isc_task_t *task, isc_event_t *event) { #include /* Create a task */ -static void -create_task(void **state) { +ISC_RUN_TEST_IMPL(create_task) { isc_result_t result; isc_task_t *task = NULL; @@ -139,8 +122,7 @@ create_task(void **state) { } /* Process events */ -static void -all_events(void **state) { +ISC_RUN_TEST_IMPL(all_events) { isc_result_t result; isc_task_t *task = NULL; isc_event_t *event = NULL; @@ -157,14 +139,14 @@ all_events(void **state) { assert_int_equal(result, ISC_R_SUCCESS); /* First event */ - event = isc_event_allocate(test_mctx, task, ISC_TASKEVENT_TEST, set, &a, + event = isc_event_allocate(mctx, task, ISC_TASKEVENT_TEST, set, &a, sizeof(isc_event_t)); assert_non_null(event); assert_int_equal(atomic_load(&a), 0); isc_task_send(task, &event); - event = isc_event_allocate(test_mctx, task, ISC_TASKEVENT_TEST, set, &b, + event = isc_event_allocate(mctx, task, ISC_TASKEVENT_TEST, set, &b, sizeof(isc_event_t)); assert_non_null(event); @@ -172,7 +154,7 @@ all_events(void **state) { isc_task_send(task, &event); while ((atomic_load(&a) == 0 || atomic_load(&b) == 0) && i++ < 5000) { - isc_test_nap(1000); + uv_sleep(1); } assert_int_not_equal(atomic_load(&a), 0); @@ -223,8 +205,7 @@ static char four[] = "4"; static char tick[] = "tick"; static char tock[] = "tock"; -static void -basic(void **state) { +ISC_RUN_TEST_IMPL(basic) { isc_result_t result; isc_task_t *task1 = NULL; isc_task_t *task2 = NULL; @@ -272,7 +253,7 @@ basic(void **state) { * structure (socket, timer, task, etc) but this is just a * test program. */ - event = isc_event_allocate(test_mctx, (void *)1, 1, basic_cb, + event = isc_event_allocate(mctx, (void *)1, 1, basic_cb, testarray[i], sizeof(*event)); assert_non_null(event); isc_task_send(task1, &event); @@ -347,8 +328,7 @@ exclusive_cb(isc_task_t *task, isc_event_t *event) { } } -static void -task_exclusive(void **state) { +ISC_RUN_TEST_IMPL(task_exclusive) { isc_task_t *tasks[10]; isc_result_t result; int i; @@ -374,12 +354,12 @@ task_exclusive(void **state) { assert_int_equal(result, ISC_R_SUCCESS); } - v = isc_mem_get(test_mctx, sizeof *v); + v = isc_mem_get(mctx, sizeof *v); assert_non_null(v); *v = i; - event = isc_event_allocate(test_mctx, NULL, 1, exclusive_cb, v, + event = isc_event_allocate(mctx, NULL, 1, exclusive_cb, v, sizeof(*event)); assert_non_null(event); @@ -392,7 +372,7 @@ task_exclusive(void **state) { } while (atomic_load(&counter) > 0) { - isc_test_nap(1000); + uv_sleep(1); } } @@ -429,8 +409,7 @@ maxtask_cb(isc_task_t *task, isc_event_t *event) { } } -static void -manytasks(void **state) { +ISC_RUN_TEST_IMPL(manytasks) { isc_event_t *event = NULL; uintptr_t ntasks = 2; /* 0000; */ @@ -443,8 +422,8 @@ manytasks(void **state) { atomic_init(&done, false); - event = isc_event_allocate(test_mctx, NULL, 1, maxtask_cb, - (void *)ntasks, sizeof(*event)); + event = isc_event_allocate(mctx, NULL, 1, maxtask_cb, (void *)ntasks, + sizeof(*event)); assert_non_null(event); LOCK(&lock); @@ -518,12 +497,12 @@ try_purgeevent(void) { /* * Block the task on cv. */ - event1 = isc_event_allocate(test_mctx, (void *)1, (isc_eventtype_t)1, + event1 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1, pge_event1, NULL, sizeof(*event1)); assert_non_null(event1); isc_task_send(task, &event1); - event2 = isc_event_allocate(test_mctx, (void *)1, (isc_eventtype_t)1, + event2 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1, pge_event2, NULL, sizeof(*event2)); assert_non_null(event2); @@ -553,7 +532,6 @@ try_purgeevent(void) { WAITUNTIL(&cv, &lock, &now); } - UNLOCK(&lock); isc_task_detach(&task); @@ -566,72 +544,21 @@ try_purgeevent(void) { * task's queue and returns true. */ -static void -purgeevent(void **state) { +ISC_RUN_TEST_IMPL(purgeevent) { UNUSED(state); try_purgeevent(); } -int -main(int argc, char **argv) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(manytasks, _setup, _teardown), - cmocka_unit_test_setup_teardown(all_events, _setup, _teardown), - cmocka_unit_test_setup_teardown(basic, _setup2, _teardown), - cmocka_unit_test_setup_teardown(create_task, _setup, _teardown), - cmocka_unit_test_setup_teardown(purgeevent, _setup2, _teardown), - cmocka_unit_test_setup_teardown(task_exclusive, _setup4, - _teardown), - }; - struct CMUnitTest selected[sizeof(tests) / sizeof(tests[0])]; - size_t i; - int c; +ISC_TEST_LIST_START - memset(selected, 0, sizeof(selected)); +ISC_TEST_ENTRY_CUSTOM(manytasks, _setup4, _teardown) +ISC_TEST_ENTRY_CUSTOM(all_events, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(basic, _setup2, _teardown) +ISC_TEST_ENTRY_CUSTOM(create_task, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(purgeevent, _setup2, _teardown) +ISC_TEST_ENTRY_CUSTOM(task_exclusive, _setup4, _teardown) - while ((c = isc_commandline_parse(argc, argv, "lt:v")) != -1) { - switch (c) { - case 'l': - for (i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++) - { - if (tests[i].name != NULL) { - fprintf(stdout, "%s\n", tests[i].name); - } - } - return (0); - case 't': - if (!cmocka_add_test_byname( - tests, isc_commandline_argument, selected)) - { - fprintf(stderr, "unknown test '%s'\n", - isc_commandline_argument); - exit(1); - } - break; - case 'v': - verbose = true; - break; - default: - break; - } - } +ISC_TEST_LIST_END - if (selected[0].name != NULL) { - return (cmocka_run_group_tests(selected, NULL, NULL)); - } else { - return (cmocka_run_group_tests(tests, NULL, NULL)); - } -} - -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/testdata/file/keep b/tests/isc/testdata/file/keep similarity index 100% rename from lib/isc/tests/testdata/file/keep rename to tests/isc/testdata/file/keep diff --git a/lib/isc/tests/time_test.c b/tests/isc/time_test.c similarity index 89% rename from lib/isc/tests/time_test.c rename to tests/isc/time_test.c index 870d9bfbd8..4b355a7003 100644 --- a/lib/isc/tests/time_test.c +++ b/tests/isc/time_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -28,7 +26,9 @@ #include #include -#include "../time.c" +#include "time.c" + +#include #define NS_PER_S 1000000000 /*%< Nanoseconds per second. */ #define MAX_NS (NS_PER_S - 1) @@ -66,8 +66,7 @@ const struct time_vectors vectors_sub[7] = { { { 0, 0 }, { 0, MAX_NS }, { 0, 0 }, ISC_R_RANGE }, }; -static void -isc_time_add_test(void **state) { +ISC_RUN_TEST_IMPL(isc_time_add_test) { UNUSED(state); for (size_t i = 0; i < ARRAY_SIZE(vectors_add); i++) { @@ -100,8 +99,7 @@ isc_time_add_test(void **state) { &(isc_time_t){ 0, 0 }, &(isc_interval_t){ 0, 0 }, NULL)); } -static void -isc_time_sub_test(void **state) { +ISC_RUN_TEST_IMPL(isc_time_sub_test) { UNUSED(state); for (size_t i = 0; i < ARRAY_SIZE(vectors_sub); i++) { @@ -134,8 +132,8 @@ isc_time_sub_test(void **state) { } /* parse http time stamp */ -static void -isc_time_parsehttptimestamp_test(void **state) { + +ISC_RUN_TEST_IMPL(isc_time_parsehttptimestamp_test) { isc_result_t result; isc_time_t t, x; char buf[ISC_FORMATHTTPTIMESTAMP_SIZE]; @@ -153,8 +151,8 @@ isc_time_parsehttptimestamp_test(void **state) { } /* print UTC in ISO8601 */ -static void -isc_time_formatISO8601_test(void **state) { + +ISC_RUN_TEST_IMPL(isc_time_formatISO8601_test) { isc_result_t result; isc_time_t t; char buf[64]; @@ -189,8 +187,8 @@ isc_time_formatISO8601_test(void **state) { } /* print UTC in ISO8601 with milliseconds */ -static void -isc_time_formatISO8601ms_test(void **state) { + +ISC_RUN_TEST_IMPL(isc_time_formatISO8601ms_test) { isc_result_t result; isc_time_t t; char buf[64]; @@ -226,8 +224,8 @@ isc_time_formatISO8601ms_test(void **state) { } /* print UTC in ISO8601 with microseconds */ -static void -isc_time_formatISO8601us_test(void **state) { + +ISC_RUN_TEST_IMPL(isc_time_formatISO8601us_test) { isc_result_t result; isc_time_t t; char buf[64]; @@ -263,8 +261,8 @@ isc_time_formatISO8601us_test(void **state) { } /* print local time in ISO8601 */ -static void -isc_time_formatISO8601L_test(void **state) { + +ISC_RUN_TEST_IMPL(isc_time_formatISO8601L_test) { isc_result_t result; isc_time_t t; char buf[64]; @@ -298,8 +296,8 @@ isc_time_formatISO8601L_test(void **state) { } /* print local time in ISO8601 with milliseconds */ -static void -isc_time_formatISO8601Lms_test(void **state) { + +ISC_RUN_TEST_IMPL(isc_time_formatISO8601Lms_test) { isc_result_t result; isc_time_t t; char buf[64]; @@ -334,8 +332,8 @@ isc_time_formatISO8601Lms_test(void **state) { } /* print local time in ISO8601 with microseconds */ -static void -isc_time_formatISO8601Lus_test(void **state) { + +ISC_RUN_TEST_IMPL(isc_time_formatISO8601Lus_test) { isc_result_t result; isc_time_t t; char buf[64]; @@ -370,8 +368,8 @@ isc_time_formatISO8601Lus_test(void **state) { } /* print UTC time as yyyymmddhhmmsssss */ -static void -isc_time_formatshorttimestamp_test(void **state) { + +ISC_RUN_TEST_IMPL(isc_time_formatshorttimestamp_test) { isc_result_t result; isc_time_t t; char buf[64]; @@ -399,32 +397,19 @@ isc_time_formatshorttimestamp_test(void **state) { assert_string_equal(buf, "20151213094640123"); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(isc_time_add_test), - cmocka_unit_test(isc_time_sub_test), - cmocka_unit_test(isc_time_parsehttptimestamp_test), - cmocka_unit_test(isc_time_formatISO8601_test), - cmocka_unit_test(isc_time_formatISO8601ms_test), - cmocka_unit_test(isc_time_formatISO8601us_test), - cmocka_unit_test(isc_time_formatISO8601L_test), - cmocka_unit_test(isc_time_formatISO8601Lms_test), - cmocka_unit_test(isc_time_formatISO8601Lus_test), - cmocka_unit_test(isc_time_formatshorttimestamp_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(isc_time_add_test) +ISC_TEST_ENTRY(isc_time_sub_test) +ISC_TEST_ENTRY(isc_time_parsehttptimestamp_test) +ISC_TEST_ENTRY(isc_time_formatISO8601_test) +ISC_TEST_ENTRY(isc_time_formatISO8601ms_test) +ISC_TEST_ENTRY(isc_time_formatISO8601us_test) +ISC_TEST_ENTRY(isc_time_formatISO8601L_test) +ISC_TEST_ENTRY(isc_time_formatISO8601Lms_test) +ISC_TEST_ENTRY(isc_time_formatISO8601Lus_test) +ISC_TEST_ENTRY(isc_time_formatshorttimestamp_test) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/timer_test.c b/tests/isc/timer_test.c similarity index 92% rename from lib/isc/tests/timer_test.c rename to tests/isc/timer_test.c index b91e0ac15f..eeea651371 100644 --- a/lib/isc/tests/timer_test.c +++ b/tests/isc/timer_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -34,9 +32,11 @@ #include #include #include +#include -#include "../timer.c" -#include "isctest.h" +#include "timer.c" + +#include /* Set to true (or use -v option) for verbose output */ static bool verbose = false; @@ -58,24 +58,16 @@ static int nevents; static int _setup(void **state) { - isc_result_t result; - - UNUSED(state); - - /* Timer tests require two worker threads */ - result = isc_test_begin(NULL, true, 2); - assert_int_equal(result, ISC_R_SUCCESS); - atomic_init(&errcnt, ISC_R_SUCCESS); + setup_managers(state); + return (0); } static int _teardown(void **state) { - UNUSED(state); - - isc_test_end(); + teardown_managers(state); return (0); } @@ -176,7 +168,8 @@ subthread_assert_result_equal(isc_result_t result, isc_result_t expected, const char *file, unsigned int line) { if (result != expected) { printf("# %s:%u subthread_assert_result_equal(%u != %u)\n", - file, line, result, expected); + file, line, (unsigned int)result, + (unsigned int)expected); set_global_error(result); } } @@ -251,8 +244,7 @@ ticktock(isc_task_t *task, isc_event_t *event) { */ /* timer type ticker */ -static void -ticker(void **state) { +ISC_RUN_TEST_IMPL(ticker) { isc_interval_t interval; UNUSED(state); @@ -316,8 +308,7 @@ test_idle(isc_task_t *task, isc_event_t *event) { } /* timer type once idles out */ -static void -once_idle(void **state) { +ISC_RUN_TEST_IMPL(once_idle) { isc_interval_t interval; UNUSED(state); @@ -398,8 +389,7 @@ test_reset(isc_task_t *task, isc_event_t *event) { } } -static void -reset(void **state) { +ISC_RUN_TEST_IMPL(reset) { isc_interval_t interval; UNUSED(state); @@ -480,8 +470,7 @@ once_event(isc_task_t *task, isc_event_t *event) { } /* timer events purged */ -static void -purge(void **state) { +ISC_RUN_TEST_IMPL(purge) { isc_result_t result; isc_interval_t interval; @@ -520,7 +509,7 @@ purge(void **state) { * Wait for shutdown processing to complete. */ while (!atomic_load(&shutdownflag)) { - isc_test_nap(1000); + uv_sleep(1); } assert_int_equal(atomic_load(&errcnt), ISC_R_SUCCESS); @@ -533,37 +522,12 @@ purge(void **state) { isc_task_detach(&task2); } -int -main(int argc, char **argv) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(ticker), - cmocka_unit_test(once_idle), - cmocka_unit_test(reset), - cmocka_unit_test(purge), - }; - int c; +ISC_TEST_LIST_START - while ((c = isc_commandline_parse(argc, argv, "v")) != -1) { - switch (c) { - case 'v': - verbose = true; - break; - default: - break; - } - } +ISC_TEST_ENTRY_CUSTOM(once_idle, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(reset, _setup, _teardown) +ISC_TEST_ENTRY_CUSTOM(purge, _setup, _teardown) - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} +ISC_TEST_LIST_END -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/isc/tests/uv_wrap.h b/tests/isc/uv_wrap.h similarity index 100% rename from lib/isc/tests/uv_wrap.h rename to tests/isc/uv_wrap.h diff --git a/lib/isccfg/tests/Makefile.am b/tests/isccfg/Makefile.am similarity index 84% rename from lib/isccfg/tests/Makefile.am rename to tests/isccfg/Makefile.am index cb21d57fc5..73655a5401 100644 --- a/lib/isccfg/tests/Makefile.am +++ b/tests/isccfg/Makefile.am @@ -3,7 +3,8 @@ include $(top_srcdir)/Makefile.top AM_CPPFLAGS += \ $(LIBISC_CFLAGS) \ $(LIBDNS_CFLAGS) \ - $(LIBISCCFG_CFLAGS) + $(LIBISCCFG_CFLAGS) \ + -I$(top_srcdir)/lib/isc LDADD += \ $(LIBISC_LIBS) \ diff --git a/lib/isccfg/tests/duration_test.c b/tests/isccfg/duration_test.c similarity index 79% rename from lib/isccfg/tests/duration_test.c rename to tests/isccfg/duration_test.c index 343f66dba9..1fa15e32d9 100644 --- a/lib/isccfg/tests/duration_test.c +++ b/tests/isccfg/duration_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -36,14 +34,8 @@ #include #include -#define CHECK(r) \ - do { \ - result = (r); \ - if (result != ISC_R_SUCCESS) \ - goto cleanup; \ - } while (0) +#include -isc_mem_t *mctx = NULL; isc_log_t *lctx = NULL; static isc_logcategory_t categories[] = { { "", 0 }, { "client", 0 }, @@ -55,23 +47,8 @@ static isc_logcategory_t categories[] = { { "", 0 }, { "query-errors", 0 }, { NULL, 0 } }; -static void -cleanup(void) { - if (lctx != NULL) { - isc_log_destroy(&lctx); - } - if (mctx != NULL) { - isc_mem_destroy(&mctx); - } -} - -static isc_result_t -setup(void) { +ISC_SETUP_TEST_IMPL(group) { isc_result_t result; - - isc_mem_debugging |= ISC_MEM_DEBUGRECORD; - isc_mem_create(&mctx); - isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; @@ -85,13 +62,24 @@ setup(void) { destination.file.maximum_size = 0; isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, 0); - CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); + result = isc_log_usechannel(logconfig, "stderr", NULL, NULL); - return (ISC_R_SUCCESS); + if (result != ISC_R_SUCCESS) { + return (-1); + } -cleanup: - cleanup(); - return (result); + return (0); +} + +ISC_TEARDOWN_TEST_IMPL(group) { + if (lctx == NULL) { + return (-1); + } + + isc_log_setcontext(NULL); + isc_log_destroy(&lctx); + + return (0); } struct duration_conf { @@ -101,8 +89,7 @@ struct duration_conf { typedef struct duration_conf duration_conf_t; /* test cfg_obj_asduration() */ -static void -cfg_obj_asduration_test(void **state) { +ISC_RUN_TEST_IMPL(cfg_obj_asduration) { isc_result_t result; duration_conf_t durations[] = { { .string = "PT0S", .time = 0 }, @@ -133,10 +120,6 @@ cfg_obj_asduration_test(void **state) { cfg_parser_t *p1 = NULL; cfg_obj_t *c1 = NULL; - UNUSED(state); - - setup(); - for (int i = 0; i < num; i++) { const cfg_listelt_t *element; const cfg_obj_t *kasps = NULL; @@ -177,27 +160,12 @@ cfg_obj_asduration_test(void **state) { cfg_obj_destroy(p1, &c1); cfg_parser_destroy(&p1); } - - cleanup(); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(cfg_obj_asduration_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY(cfg_obj_asduration) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN_CUSTOM(setup_test_group, teardown_test_group) diff --git a/lib/isccfg/tests/parser_test.c b/tests/isccfg/parser_test.c similarity index 77% rename from lib/isccfg/tests/parser_test.c rename to tests/isccfg/parser_test.c index 5f28a7d9ab..9a524ea2ad 100644 --- a/lib/isccfg/tests/parser_test.c +++ b/tests/isccfg/parser_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -38,14 +36,8 @@ #include #include -#define CHECK(r) \ - do { \ - result = (r); \ - if (result != ISC_R_SUCCESS) \ - goto cleanup; \ - } while (0) +#include -isc_mem_t *mctx = NULL; isc_log_t *lctx = NULL; static isc_logcategory_t categories[] = { { "", 0 }, { "client", 0 }, @@ -57,24 +49,8 @@ static isc_logcategory_t categories[] = { { "", 0 }, { "query-errors", 0 }, { NULL, 0 } }; -static void -cleanup(void) { - if (lctx != NULL) { - isc_log_setcontext(NULL); - isc_log_destroy(&lctx); - } - if (mctx != NULL) { - isc_mem_destroy(&mctx); - } -} - -static isc_result_t -setup(void) { +ISC_SETUP_TEST_IMPL(group) { isc_result_t result; - - isc_mem_debugging |= ISC_MEM_DEBUGRECORD; - isc_mem_create(&mctx); - isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; @@ -88,32 +64,22 @@ setup(void) { destination.file.maximum_size = 0; isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, 0); - CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); + result = isc_log_usechannel(logconfig, "stderr", NULL, NULL); - return (ISC_R_SUCCESS); - -cleanup: - cleanup(); - return (result); -} - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = setup(); - assert_int_equal(result, ISC_R_SUCCESS); + if (result != ISC_R_SUCCESS) { + return (-1); + } return (0); } -static int -_teardown(void **state) { - UNUSED(state); +ISC_TEARDOWN_TEST_IMPL(group) { + if (lctx == NULL) { + return (-1); + } - cleanup(); + isc_log_setcontext(NULL); + isc_log_destroy(&lctx); return (0); } @@ -126,8 +92,7 @@ append(void *arg, const char *str, int len) { snprintf(buf + l, 1024 - l, "%.*s", len, str); } -static void -addzoneconf(void **state) { +ISC_RUN_TEST_IMPL(addzoneconf) { isc_result_t result; isc_buffer_t b; cfg_parser_t *p = NULL; @@ -142,8 +107,6 @@ addzoneconf(void **state) { }; char buf[1024]; - UNUSED(state); - /* Parse with default line numbering */ result = cfg_parser_create(mctx, lctx, &p); assert_int_equal(result, ISC_R_SUCCESS); @@ -182,16 +145,13 @@ addzoneconf(void **state) { } /* test cfg_parse_buffer() */ -static void -parse_buffer_test(void **state) { +ISC_RUN_TEST_IMPL(parse_buffer) { isc_result_t result; unsigned char text[] = "options\n{\nrecursion yes;\n};\n"; isc_buffer_t buf1, buf2; cfg_parser_t *p1 = NULL, *p2 = NULL; cfg_obj_t *c1 = NULL, *c2 = NULL; - UNUSED(state); - isc_buffer_init(&buf1, &text[0], sizeof(text) - 1); isc_buffer_add(&buf1, sizeof(text) - 1); @@ -224,14 +184,11 @@ parse_buffer_test(void **state) { } /* test cfg_map_firstclause() */ -static void -cfg_map_firstclause_test(void **state) { +ISC_RUN_TEST_IMPL(cfg_map_firstclause) { const char *name = NULL; const void *clauses = NULL; unsigned int idx; - UNUSED(state); - name = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx); assert_non_null(name); assert_non_null(clauses); @@ -239,14 +196,11 @@ cfg_map_firstclause_test(void **state) { } /* test cfg_map_nextclause() */ -static void -cfg_map_nextclause_test(void **state) { +ISC_RUN_TEST_IMPL(cfg_map_nextclause) { const char *name = NULL; const void *clauses = NULL; unsigned int idx; - UNUSED(state); - name = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx); assert_non_null(name); assert_non_null(clauses); @@ -263,26 +217,13 @@ cfg_map_nextclause_test(void **state) { } while (name != NULL); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(addzoneconf), - cmocka_unit_test(parse_buffer_test), - cmocka_unit_test(cfg_map_firstclause_test), - cmocka_unit_test(cfg_map_nextclause_test), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, _setup, _teardown)); -} +ISC_TEST_ENTRY(addzoneconf) +ISC_TEST_ENTRY(parse_buffer) +ISC_TEST_ENTRY(cfg_map_firstclause) +ISC_TEST_ENTRY(cfg_map_nextclause) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN_CUSTOM(setup_test_group, teardown_test_group) diff --git a/tests/libtest/Makefile.am b/tests/libtest/Makefile.am new file mode 100644 index 0000000000..2699f4bfcf --- /dev/null +++ b/tests/libtest/Makefile.am @@ -0,0 +1,28 @@ +include $(top_srcdir)/Makefile.top + +AM_CPPFLAGS += \ + $(LIBISC_CFLAGS) \ + $(LIBDNS_CFLAGS) \ + $(LIBNS_CFLAGS) \ + $(LIBUV_CFLAGS) \ + -I$(top_srcdir)/lib/isc + +LDADD += \ + $(LIBISC_LIBS) \ + $(LIBDNS_LIBS) \ + $(LIBNS_LIBS) + +check_LTLIBRARIES = libtest.la + +noinst_libtest_ladir = .. +noinst_libtest_la_HEADERS = \ + ../include/tests/dns.h \ + ../include/tests/isc.h \ + ../include/tests/ns.h +libtest_la_SOURCES = \ + $(noinst_libtest_la_HEADERS) \ + dns.c \ + isc.c \ + ns.c + +include $(top_srcdir)/Makefile.tests diff --git a/lib/dns/tests/dnstest.c b/tests/libtest/dns.c similarity index 69% rename from lib/dns/tests/dnstest.c rename to tests/libtest/dns.c index 5f01e10d45..bbe8ce6e43 100644 --- a/lib/dns/tests/dnstest.c +++ b/tests/libtest/dns.c @@ -24,11 +24,9 @@ #include #include -#if HAVE_CMOCKA #define UNIT_TESTING #include -#include #include #include #include @@ -55,172 +53,45 @@ #include #include -#include "dnstest.h" +#include -#define CHECK(r) \ - do { \ - result = (r); \ - if (result != ISC_R_SUCCESS) { \ - goto cleanup; \ - } \ - } while (0) - -isc_mem_t *dt_mctx = NULL; -isc_log_t *lctx = NULL; -isc_nm_t *netmgr = NULL; -isc_taskmgr_t *taskmgr = NULL; -isc_task_t *maintask = NULL; -isc_timermgr_t *timermgr = NULL; dns_zonemgr_t *zonemgr = NULL; -bool app_running = false; -int ncpus; -bool debug_mem_record = true; - -static bool dst_active = false; -static bool test_running = false; - -/* - * Logging categories: this needs to match the list in bin/named/log.c. - */ -static isc_logcategory_t categories[] = { { "", 0 }, - { "client", 0 }, - { "network", 0 }, - { "update", 0 }, - { "queries", 0 }, - { "unmatched", 0 }, - { "update-security", 0 }, - { "query-errors", 0 }, - { NULL, 0 } }; - -static void -cleanup_managers(void) { - if (maintask != NULL) { - isc_task_detach(&maintask); - } - - isc_managers_destroy(netmgr == NULL ? NULL : &netmgr, - taskmgr == NULL ? NULL : &taskmgr, - timermgr == NULL ? NULL : &timermgr); - - if (app_running) { - isc_app_finish(); - } -} - -static isc_result_t -create_managers(void) { - isc_result_t result; - ncpus = isc_os_ncpus(); - - isc_managers_create(dt_mctx, ncpus, 0, &netmgr, &taskmgr, &timermgr); - CHECK(isc_task_create(taskmgr, 0, &maintask, 0)); - return (ISC_R_SUCCESS); - -cleanup: - cleanup_managers(); - return (result); -} - -isc_result_t -dns_test_begin(FILE *logfile, bool start_managers) { - isc_result_t result; - - INSIST(!test_running); - test_running = true; - - if (start_managers) { - CHECK(isc_app_start()); - } - if (debug_mem_record) { - isc_mem_debugging |= ISC_MEM_DEBUGRECORD; - } - - INSIST(dt_mctx == NULL); - isc_mem_create(&dt_mctx); - - /* Don't check the memory leaks as they hide the assertions */ - isc_mem_setdestroycheck(dt_mctx, false); - - INSIST(!dst_active); - CHECK(dst_lib_init(dt_mctx, NULL)); - dst_active = true; - - if (logfile != NULL) { - isc_logdestination_t destination; - isc_logconfig_t *logconfig = NULL; - - INSIST(lctx == NULL); - isc_log_create(dt_mctx, &lctx, &logconfig); - isc_log_registercategories(lctx, categories); - isc_log_setcontext(lctx); - dns_log_init(lctx); - dns_log_setcontext(lctx); - - destination.file.stream = logfile; - destination.file.name = NULL; - destination.file.versions = ISC_LOG_ROLLNEVER; - destination.file.maximum_size = 0; - isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, - ISC_LOG_DYNAMIC, &destination, 0); - CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); - } - - if (start_managers) { - CHECK(create_managers()); - } - - /* - * The caller might run from another directory, so tests - * that access test data files must first chdir to the proper - * location. - */ - if (chdir(TESTS_DIR) == -1) { - CHECK(ISC_R_FAILURE); - } - - return (ISC_R_SUCCESS); - -cleanup: - dns_test_end(); - return (result); -} - -void -dns_test_end(void) { - cleanup_managers(); - - dst_lib_destroy(); - dst_active = false; - - if (lctx != NULL) { - isc_log_destroy(&lctx); - } - - if (dt_mctx != NULL) { - isc_mem_destroy(&dt_mctx); - } - - test_running = false; -} /* * Create a view. */ isc_result_t -dns_test_makeview(const char *name, dns_view_t **viewp) { +dns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp) { isc_result_t result; dns_view_t *view = NULL; + dns_cache_t *cache = NULL; + + result = dns_view_create(mctx, dns_rdataclass_in, name, &view); + if (result != ISC_R_SUCCESS) { + return (result); + } + + if (with_cache) { + result = dns_cache_create(mctx, mctx, taskmgr, timermgr, + dns_rdataclass_in, "", "rbt", 0, NULL, + &cache); + if (result != ISC_R_SUCCESS) { + dns_view_detach(&view); + return (result); + } + + dns_view_setcache(view, cache, false); + /* + * Reference count for "cache" is now at 2, so decrement it in + * order for the cache to be automatically freed when "view" + * gets freed. + */ + dns_cache_detach(&cache); + } - CHECK(dns_view_create(dt_mctx, dns_rdataclass_in, name, &view)); *viewp = view; return (ISC_R_SUCCESS); - -cleanup: - if (view != NULL) { - dns_view_detach(&view); - } - return (result); } isc_result_t @@ -236,7 +107,7 @@ dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view, /* * Create the zone structure. */ - result = dns_zone_create(&zone, dt_mctx, 0); + result = dns_zone_create(&zone, mctx, 0); if (result != ISC_R_SUCCESS) { return (result); } @@ -259,7 +130,7 @@ dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view, * If requested, create a view. */ if (createview) { - result = dns_test_makeview("view", &view); + result = dns_test_makeview("view", false, &view); if (result != ISC_R_SUCCESS) { goto detach_zone; } @@ -292,8 +163,7 @@ dns_test_setupzonemgr(void) { isc_result_t result; REQUIRE(zonemgr == NULL); - result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr, - &zonemgr); + result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr, &zonemgr); return (result); } @@ -346,8 +216,8 @@ dns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin, return (result); } - result = dns_db_create(dt_mctx, "rbt", name, dbtype, dns_rdataclass_in, - 0, NULL, db); + result = dns_db_create(mctx, "rbt", name, dbtype, dns_rdataclass_in, 0, + NULL, db); if (result != ISC_R_SUCCESS) { return (result); } @@ -426,10 +296,12 @@ dns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz, continue; } if (len % 2 != 0U) { - CHECK(ISC_R_UNEXPECTEDEND); + result = ISC_R_UNEXPECTEDEND; + break; } if (len > bufsiz * 2) { - CHECK(ISC_R_NOSPACE); + result = ISC_R_NOSPACE; + break; } rp = s; for (i = 0; i < len; i += 2) { @@ -440,11 +312,10 @@ dns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz, } } - *sizep = bp - buf; + if (result == ISC_R_SUCCESS) { + *sizep = bp - buf; + } - result = ISC_R_SUCCESS; - -cleanup: isc_stdio_close(f); return (result); } @@ -481,7 +352,7 @@ dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass, /* * Create a lexer as one is required by dns_rdata_fromtext(). */ - result = isc_lex_create(dt_mctx, 64, &lex); + result = isc_lex_create(mctx, 64, &lex); if (result != ISC_R_SUCCESS) { return (result); } @@ -527,7 +398,7 @@ dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass, * Parse input string, determining result. */ result = dns_rdata_fromtext(rdata, rdclass, rdtype, lex, dns_rootname, - 0, dt_mctx, &target, &callbacks); + 0, mctx, &target, &callbacks); destroy_lexer: isc_lex_destroy(&lex); @@ -546,7 +417,7 @@ dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname) { name = dns_fixedname_initname(fname); - isc_buffer_allocate(dt_mctx, &b, length); + isc_buffer_allocate(mctx, &b, length); isc_buffer_putmem(b, (const unsigned char *)namestr, length); result = dns_name_fromtext(name, b, dns_rootname, 0, NULL); @@ -571,15 +442,14 @@ dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes, REQUIRE(diff != NULL); REQUIRE(changes != NULL); - dns_diff_init(dt_mctx, diff); + dns_diff_init(mctx, diff); for (i = 0; changes[i].owner != NULL; i++) { /* * Parse owner name. */ name = dns_fixedname_initname(&fixedname); - result = dns_name_fromstring(name, changes[i].owner, 0, - dt_mctx); + result = dns_name_fromstring(name, changes[i].owner, 0, mctx); if (result != ISC_R_SUCCESS) { break; } @@ -610,7 +480,7 @@ dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes, * Create a diff tuple for the parsed change and append it to * the diff. */ - result = dns_difftuple_create(dt_mctx, changes[i].op, name, + result = dns_difftuple_create(mctx, changes[i].op, name, changes[i].ttl, &rdata, &tuple); if (result != ISC_R_SUCCESS) { break; @@ -624,4 +494,3 @@ dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes, return (result); } -#endif /* HAVE_CMOCKA */ diff --git a/tests/libtest/isc.c b/tests/libtest/isc.c new file mode 100644 index 0000000000..61e29c2a34 --- /dev/null +++ b/tests/libtest/isc.c @@ -0,0 +1,87 @@ +/* + * 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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "netmgr_p.h" +#include "task_p.h" +#include "timer_p.h" + +#include + +isc_mem_t *mctx = NULL; +isc_taskmgr_t *taskmgr = NULL; +isc_timermgr_t *timermgr = NULL; +isc_nm_t *netmgr = NULL; +unsigned int workers = 0; +isc_task_t *maintask = NULL; + +int +setup_managers(void **state) { + isc_result_t result; + + UNUSED(state); + + REQUIRE(mctx != NULL); + + if (workers == 0) { + char *env_workers = getenv("ISC_TASK_WORKERS"); + if (env_workers != NULL) { + workers = atoi(env_workers); + } else { + workers = isc_os_ncpus(); + } + INSIST(workers > 0); + } + + result = isc_managers_create(mctx, workers, 0, &netmgr, &taskmgr, + &timermgr); + if (result != ISC_R_SUCCESS) { + return (-1); + } + + result = isc_task_create(taskmgr, 0, &maintask, 0); + if (result != ISC_R_SUCCESS) { + return (-1); + } + + isc_taskmgr_setexcltask(taskmgr, maintask); + + return (0); +} + +int +teardown_managers(void **state) { + UNUSED(state); + + isc_task_detach(&maintask); + isc_managers_destroy(&netmgr, &taskmgr, &timermgr); + + return (0); +} diff --git a/lib/ns/tests/nstest.c b/tests/libtest/ns.c similarity index 62% rename from lib/ns/tests/nstest.c rename to tests/libtest/ns.c index 6afaed065f..6de395b6ab 100644 --- a/lib/ns/tests/nstest.c +++ b/tests/libtest/ns.c @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -51,25 +50,82 @@ #include #include -#include "nstest.h" +#include -isc_mem_t *mctx = NULL; -isc_log_t *lctx = NULL; -isc_nm_t *netmgr = NULL; -isc_taskmgr_t *taskmgr = NULL; -isc_task_t *maintask = NULL; -isc_timermgr_t *timermgr = NULL; -dns_zonemgr_t *zonemgr = NULL; dns_dispatchmgr_t *dispatchmgr = NULL; ns_clientmgr_t *clientmgr = NULL; ns_interfacemgr_t *interfacemgr = NULL; ns_server_t *sctx = NULL; -bool app_running = false; bool debug_mem_record = true; -static atomic_bool run_managers = false; -static bool dst_active = false; -static bool test_running = false; +static isc_result_t +matchview(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr, + dns_message_t *message, dns_aclenv_t *env, isc_result_t *sigresultp, + dns_view_t **viewp) { + UNUSED(srcaddr); + UNUSED(destaddr); + UNUSED(message); + UNUSED(env); + UNUSED(sigresultp); + UNUSED(viewp); + + return (ISC_R_NOTIMPLEMENTED); +} + +int +setup_server(void **state) { + isc_result_t result; + ns_listenlist_t *listenon = NULL; + in_port_t port = 5300 + isc_random8(); + + setup_managers(state); + + ns_server_create(mctx, matchview, &sctx); + + result = dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr); + if (result != ISC_R_SUCCESS) { + return (-1); + } + + result = ns_interfacemgr_create(mctx, sctx, taskmgr, timermgr, netmgr, + dispatchmgr, maintask, NULL, false, + &interfacemgr); + if (result != ISC_R_SUCCESS) { + return (-1); + } + + result = ns_listenlist_default(mctx, port, -1, true, AF_INET, + &listenon); + if (result != ISC_R_SUCCESS) { + return (-1); + } + + ns_interfacemgr_setlistenon4(interfacemgr, listenon); + ns_listenlist_detach(&listenon); + + clientmgr = ns_interfacemgr_getclientmgr(interfacemgr); + + return (0); +} + +int +teardown_server(void **state) { + if (interfacemgr != NULL) { + ns_interfacemgr_shutdown(interfacemgr); + ns_interfacemgr_detach(&interfacemgr); + } + + if (dispatchmgr != NULL) { + dns_dispatchmgr_detach(&dispatchmgr); + } + + if (sctx != NULL) { + ns_server_detach(&sctx); + } + + teardown_managers(state); + return (0); +} static dns_zone_t *served_zone = NULL; @@ -124,359 +180,6 @@ isc__nmhandle_detach(isc_nmhandle_t **handlep FLARG) { return; } -/* - * Logging categories: this needs to match the list in lib/ns/log.c. - */ -static isc_logcategory_t categories[] = { { "", 0 }, - { "client", 0 }, - { "network", 0 }, - { "update", 0 }, - { "queries", 0 }, - { "unmatched", 0 }, - { "update-security", 0 }, - { "query-errors", 0 }, - { NULL, 0 } }; - -static isc_result_t -matchview(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr, - dns_message_t *message, dns_aclenv_t *env, isc_result_t *sigresultp, - dns_view_t **viewp) { - UNUSED(srcaddr); - UNUSED(destaddr); - UNUSED(message); - UNUSED(env); - UNUSED(sigresultp); - UNUSED(viewp); - - return (ISC_R_NOTIMPLEMENTED); -} - -/* - * These need to be shut down from a running task. - */ -static atomic_bool shutdown_done = false; -static void -shutdown_managers(isc_task_t *task, isc_event_t *event) { - UNUSED(task); - - isc_event_free(&event); - - if (interfacemgr != NULL) { - ns_interfacemgr_shutdown(interfacemgr); - ns_interfacemgr_detach(&interfacemgr); - } - - if (dispatchmgr != NULL) { - dns_dispatchmgr_detach(&dispatchmgr); - } - - atomic_store(&shutdown_done, true); - atomic_store(&run_managers, false); -} - -static void -cleanup_managers(void) { - atomic_store(&shutdown_done, false); - - if (maintask != NULL) { - isc_event_t *event = isc_event_allocate( - mctx, NULL, ISC_TASKEVENT_TEST, shutdown_managers, NULL, - sizeof(*event)); - isc_task_send(maintask, &event); - isc_task_detach(&maintask); - } - - while (atomic_load(&run_managers) && !atomic_load(&shutdown_done)) { - /* - * There's no straightforward way to determine - * whether all the clients have shut down, so - * we'll just sleep for a bit and hope. - */ - ns_test_nap(500000); - } - - if (sctx != NULL) { - ns_server_detach(&sctx); - } - if (interfacemgr != NULL) { - ns_interfacemgr_detach(&interfacemgr); - } - - isc_managers_destroy(netmgr == NULL ? NULL : &netmgr, - taskmgr == NULL ? NULL : &taskmgr, - timermgr == NULL ? NULL : &timermgr); - - if (app_running) { - isc_app_finish(); - } -} - -static void -scan_interfaces(isc_task_t *task, isc_event_t *event) { - UNUSED(task); - - ns_interfacemgr_scan(interfacemgr, true, false); - isc_event_free(&event); -} - -static isc_result_t -create_managers(void) { - isc_result_t result; - in_port_t port = 5300 + isc_random8(); - ns_listenlist_t *listenon = NULL; - isc_event_t *event = NULL; - int ncpus = isc_os_ncpus(); - - isc_managers_create(mctx, ncpus, 0, &netmgr, &taskmgr, &timermgr); - CHECK(isc_task_create(taskmgr, 0, &maintask, 0)); - isc_taskmgr_setexcltask(taskmgr, maintask); - - CHECK(ns_server_create(mctx, matchview, &sctx)); - - CHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr)); - - CHECK(ns_interfacemgr_create(mctx, sctx, taskmgr, timermgr, netmgr, - dispatchmgr, maintask, NULL, false, - &interfacemgr)); - - CHECK(ns_listenlist_default(mctx, port, -1, true, AF_INET, &listenon)); - ns_interfacemgr_setlistenon4(interfacemgr, listenon); - ns_listenlist_detach(&listenon); - - event = isc_event_allocate(mctx, maintask, ISC_TASKEVENT_TEST, - scan_interfaces, NULL, sizeof(isc_event_t)); - isc_task_send(maintask, &event); - - clientmgr = ns_interfacemgr_getclientmgr(interfacemgr); - - atomic_store(&run_managers, true); - - return (ISC_R_SUCCESS); - -cleanup: - cleanup_managers(); - return (result); -} - -isc_result_t -ns_test_begin(FILE *logfile, bool start_managers) { - isc_result_t result; - - INSIST(!test_running); - test_running = true; - - if (start_managers) { - isc_resourcevalue_t files; - - /* - * The 'listenlist_test', 'notify_test', and 'query_test' - * tests need more than 256 descriptors with 8 cpus. - * Bump up to at least 1024. - */ - result = isc_resource_getcurlimit(isc_resource_openfiles, - &files); - if (result == ISC_R_SUCCESS) { - if (files < 1024) { - files = 1024; - (void)isc_resource_setlimit( - isc_resource_openfiles, files); - } - } - CHECK(isc_app_start()); - } - if (debug_mem_record) { - isc_mem_debugging |= ISC_MEM_DEBUGRECORD; - } - - INSIST(mctx == NULL); - isc_mem_create(&mctx); - - if (!dst_active) { - CHECK(dst_lib_init(mctx, NULL)); - dst_active = true; - } - - if (logfile != NULL) { - isc_logdestination_t destination; - isc_logconfig_t *logconfig = NULL; - - INSIST(lctx == NULL); - isc_log_create(mctx, &lctx, &logconfig); - - isc_log_registercategories(lctx, categories); - isc_log_setcontext(lctx); - dns_log_init(lctx); - dns_log_setcontext(lctx); - - destination.file.stream = logfile; - destination.file.name = NULL; - destination.file.versions = ISC_LOG_ROLLNEVER; - destination.file.maximum_size = 0; - isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, - ISC_LOG_DYNAMIC, &destination, 0); - CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); - } - - if (start_managers) { - CHECK(create_managers()); - } - - /* - * atf-run changes us to a /tmp directory, so tests - * that access test data files must first chdir to the proper - * location. - */ - if (chdir(TESTS_DIR) == -1) { - CHECK(ISC_R_FAILURE); - } - - return (ISC_R_SUCCESS); - -cleanup: - ns_test_end(); - return (result); -} - -void -ns_test_end(void) { - cleanup_managers(); - - dst_lib_destroy(); - dst_active = false; - - if (lctx != NULL) { - isc_log_destroy(&lctx); - } - - if (mctx != NULL) { - isc_mem_destroy(&mctx); - } - - test_running = false; -} - -isc_result_t -ns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp) { - dns_cache_t *cache = NULL; - dns_view_t *view = NULL; - isc_result_t result; - - CHECK(dns_view_create(mctx, dns_rdataclass_in, name, &view)); - - if (with_cache) { - CHECK(dns_cache_create(mctx, mctx, taskmgr, timermgr, - dns_rdataclass_in, "", "rbt", 0, NULL, - &cache)); - dns_view_setcache(view, cache, false); - /* - * Reference count for "cache" is now at 2, so decrement it in - * order for the cache to be automatically freed when "view" - * gets freed. - */ - dns_cache_detach(&cache); - } - - *viewp = view; - - return (ISC_R_SUCCESS); - -cleanup: - if (view != NULL) { - dns_view_detach(&view); - } - return (result); -} - -/* - * Create a zone with origin 'name', return a pointer to the zone object in - * 'zonep'. If 'view' is set, add the zone to that view; otherwise, create - * a new view for the purpose. - * - * If the created view is going to be needed by the caller subsequently, - * then 'keepview' should be set to true; this will prevent the view - * from being detached. In this case, the caller is responsible for - * detaching the view. - */ -isc_result_t -ns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view, - bool keepview) { - isc_result_t result; - dns_zone_t *zone = NULL; - isc_buffer_t buffer; - dns_fixedname_t fixorigin; - dns_name_t *origin; - - if (view == NULL) { - CHECK(dns_view_create(mctx, dns_rdataclass_in, "view", &view)); - } else if (!keepview) { - keepview = true; - } - - zone = *zonep; - if (zone == NULL) { - CHECK(dns_zone_create(&zone, mctx, 0)); - } - - isc_buffer_constinit(&buffer, name, strlen(name)); - isc_buffer_add(&buffer, strlen(name)); - origin = dns_fixedname_initname(&fixorigin); - CHECK(dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL)); - CHECK(dns_zone_setorigin(zone, origin)); - dns_zone_setview(zone, view); - dns_zone_settype(zone, dns_zone_primary); - dns_zone_setclass(zone, view->rdclass); - dns_view_addzone(view, zone); - - if (!keepview) { - dns_view_detach(&view); - } - - *zonep = zone; - - return (ISC_R_SUCCESS); - -cleanup: - if (zone != NULL) { - dns_zone_detach(&zone); - } - if (view != NULL) { - dns_view_detach(&view); - } - return (result); -} - -isc_result_t -ns_test_setupzonemgr(void) { - isc_result_t result; - REQUIRE(zonemgr == NULL); - - result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr, &zonemgr); - return (result); -} - -isc_result_t -ns_test_managezone(dns_zone_t *zone) { - isc_result_t result; - REQUIRE(zonemgr != NULL); - - result = dns_zonemgr_managezone(zonemgr, zone); - return (result); -} - -void -ns_test_releasezone(dns_zone_t *zone) { - REQUIRE(zonemgr != NULL); - dns_zonemgr_releasezone(zonemgr, zone); -} - -void -ns_test_closezonemgr(void) { - REQUIRE(zonemgr != NULL); - - dns_zonemgr_shutdown(zonemgr); - dns_zonemgr_detach(&zonemgr); -} - isc_result_t ns_test_serve_zone(const char *zonename, const char *filename, dns_view_t *view) { @@ -486,7 +189,7 @@ ns_test_serve_zone(const char *zonename, const char *filename, /* * Prepare zone structure for further processing. */ - result = ns_test_makezone(zonename, &served_zone, view, true); + result = dns_test_makezone(zonename, &served_zone, view, false); if (result != ISC_R_SUCCESS) { return (result); } @@ -494,7 +197,7 @@ ns_test_serve_zone(const char *zonename, const char *filename, /* * Start zone manager. */ - result = ns_test_setupzonemgr(); + result = dns_test_setupzonemgr(); if (result != ISC_R_SUCCESS) { goto free_zone; } @@ -502,7 +205,7 @@ ns_test_serve_zone(const char *zonename, const char *filename, /* * Add the zone to the zone manager. */ - result = ns_test_managezone(served_zone); + result = dns_test_managezone(served_zone); if (result != ISC_R_SUCCESS) { goto close_zonemgr; } @@ -533,9 +236,9 @@ ns_test_serve_zone(const char *zonename, const char *filename, return (ISC_R_SUCCESS); release_zone: - ns_test_releasezone(served_zone); + dns_test_releasezone(served_zone); close_zonemgr: - ns_test_closezonemgr(); + dns_test_closezonemgr(); free_zone: dns_zone_detach(&served_zone); @@ -544,8 +247,8 @@ free_zone: void ns_test_cleanup_zone(void) { - ns_test_releasezone(served_zone); - ns_test_closezonemgr(); + dns_test_releasezone(served_zone); + dns_test_closezonemgr(); dns_zone_detach(&served_zone); } @@ -776,7 +479,7 @@ ns_test_qctx_create(const ns_test_qctx_create_params_t *params, /* * Every client needs to belong to a view. */ - result = ns_test_makeview("view", params->with_cache, &client->view); + result = dns_test_makeview("view", params->with_cache, &client->view); if (result != ISC_R_SUCCESS) { goto detach_client; } @@ -860,18 +563,6 @@ ns_test_hook_catch_call(void *arg, void *data, isc_result_t *resultp) { return (NS_HOOK_RETURN); } -/* - * Sleep for 'usec' microseconds. - */ -void -ns_test_nap(uint32_t usec) { - struct timespec ts; - - ts.tv_sec = usec / 1000000; - ts.tv_nsec = (usec % 1000000) * 1000; - nanosleep(&ts, NULL); -} - isc_result_t ns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin, const char *testfile) { diff --git a/lib/ns/tests/Makefile.am b/tests/ns/Makefile.am similarity index 72% rename from lib/ns/tests/Makefile.am rename to tests/ns/Makefile.am index 6b08b21346..50f87ca40a 100644 --- a/lib/ns/tests/Makefile.am +++ b/tests/ns/Makefile.am @@ -3,19 +3,15 @@ include $(top_srcdir)/Makefile.top AM_CPPFLAGS += \ $(LIBISC_CFLAGS) \ $(LIBDNS_CFLAGS) \ - $(LIBNS_CFLAGS) + $(LIBNS_CFLAGS) \ + -I$(top_srcdir)/lib/isc \ + -I$(top_srcdir)/lib/dns LDADD += \ - libnstest.la \ $(LIBISC_LIBS) \ $(LIBDNS_LIBS) \ $(LIBNS_LIBS) -check_LTLIBRARIES = libnstest.la -libnstest_la_SOURCES = \ - nstest.c \ - nstest.h - check_PROGRAMS = \ listenlist_test \ notify_test \ diff --git a/lib/ns/tests/listenlist_test.c b/tests/ns/listenlist_test.c similarity index 78% rename from lib/ns/tests/listenlist_test.c rename to tests/ns/listenlist_test.c index 6810c3416a..565b943f7d 100644 --- a/lib/ns/tests/listenlist_test.c +++ b/tests/ns/listenlist_test.c @@ -11,10 +11,6 @@ * information regarding copyright ownership. */ -#include - -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -24,6 +20,8 @@ #include #include +#include + #define UNIT_TESTING #include @@ -35,36 +33,28 @@ #include -#include "nstest.h" +#include static int _setup(void **state) { - isc_result_t result; - - UNUSED(state); - isc__nm_force_tid(0); - result = ns_test_begin(NULL, true); - assert_int_equal(result, ISC_R_SUCCESS); + setup_managers(state); return (0); } static int _teardown(void **state) { - UNUSED(state); - isc__nm_force_tid(-1); - ns_test_end(); + teardown_managers(state); return (0); } /* test that ns_listenlist_default() works */ -static void -ns_listenlist_default_test(void **state) { +ISC_RUN_TEST_IMPL(ns_listenlist_default) { isc_result_t result; in_port_t port = 5300 + isc_random8(); ns_listenlist_t *list = NULL; @@ -120,25 +110,10 @@ ns_listenlist_default_test(void **state) { ns_listenlist_detach(&list); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(ns_listenlist_default_test, - _setup, _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY_CUSTOM(ns_listenlist_default, _setup, _teardown) -#else /* HAVE_CMOCKA */ +ISC_TEST_LIST_END -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/ns/tests/notify_test.c b/tests/ns/notify_test.c similarity index 79% rename from lib/ns/tests/notify_test.c rename to tests/ns/notify_test.c index 7c7b33f9c7..c5e3009640 100644 --- a/lib/ns/tests/notify_test.c +++ b/tests/ns/notify_test.c @@ -11,10 +11,6 @@ * information regarding copyright ownership. */ -#include - -#if HAVE_CMOCKA - #include /* IWYU pragma: keep */ #include #include @@ -24,6 +20,8 @@ #include #include +#include + #define UNIT_TESTING #include @@ -39,31 +37,19 @@ #include #include -#include "nstest.h" +#include +#include static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - +setup_test(void **state) { isc__nm_force_tid(0); - - result = ns_test_begin(NULL, true); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); + return (setup_server(state)); } static int -_teardown(void **state) { - UNUSED(state); - +teardown_test(void **state) { isc__nm_force_tid(-1); - - ns_test_end(); - - return (0); + return (teardown_server(state)); } static void @@ -88,8 +74,7 @@ check_response(isc_buffer_t *buf) { } /* test ns_notify_start() */ -static void -notify_start(void **state) { +ISC_RUN_TEST_IMPL(ns_notify_start) { isc_result_t result; ns_client_t *client = NULL; isc_nmhandle_t *handle = NULL; @@ -103,7 +88,7 @@ notify_start(void **state) { result = ns_test_getclient(NULL, false, &client); assert_int_equal(result, ISC_R_SUCCESS); - result = ns_test_makeview("view", false, &client->view); + result = dns_test_makeview("view", false, &client->view); assert_int_equal(result, ISC_R_SUCCESS); result = ns_test_serve_zone("example.com", "testdata/notify/zone1.db", @@ -148,24 +133,8 @@ notify_start(void **state) { isc_nmhandle_detach(&handle); } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(notify_start, _setup, - _teardown), - }; +ISC_TEST_LIST_START +ISC_TEST_ENTRY_CUSTOM(ns_notify_start, setup_test, teardown_test) +ISC_TEST_LIST_END - return (cmocka_run_group_tests(tests, NULL, NULL)); -} -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/ns/tests/plugin_test.c b/tests/ns/plugin_test.c similarity index 83% rename from lib/ns/tests/plugin_test.c rename to tests/ns/plugin_test.c index 0feba053d3..6434fae3a4 100644 --- a/lib/ns/tests/plugin_test.c +++ b/tests/ns/plugin_test.c @@ -11,8 +11,6 @@ * information regarding copyright ownership. */ -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -37,30 +35,7 @@ _fail(const char *const file, const int line); #include -#include "nstest.h" - -static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - - result = ns_test_begin(NULL, false); - assert_int_equal(result, ISC_R_SUCCESS); - - return (0); -} - -static int -_teardown(void **state) { - if (*state != NULL) { - isc_mem_free(mctx, *state); - } - - ns_test_end(); - - return (0); -} +#include /*% * Structure containing parameters for run_full_path_test(). @@ -125,8 +100,7 @@ run_full_path_test(const ns_plugin_expandpath_test_params_t *test, } /* test ns_plugin_expandpath() */ -static void -ns_plugin_expandpath_test(void **state) { +ISC_RUN_TEST_IMPL(ns_plugin_expandpath) { size_t i; const ns_plugin_expandpath_test_params_t tests[] = { @@ -182,23 +156,10 @@ ns_plugin_expandpath_test(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(ns_plugin_expandpath_test, - _setup, _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} -#else /* HAVE_CMOCKA */ +ISC_TEST_ENTRY_CUSTOM(ns_plugin_expandpath, setup_managers, teardown_managers) -#include +ISC_TEST_LIST_END -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* if HAVE_CMOCKA */ +ISC_TEST_MAIN diff --git a/lib/ns/tests/query_test.c b/tests/ns/query_test.c similarity index 97% rename from lib/ns/tests/query_test.c rename to tests/ns/query_test.c index 35cb4b89c6..c86d98d9ac 100644 --- a/lib/ns/tests/query_test.c +++ b/tests/ns/query_test.c @@ -11,10 +11,6 @@ * information regarding copyright ownership. */ -#include - -#if HAVE_CMOCKA - #include #include /* IWYU pragma: keep */ #include @@ -24,6 +20,8 @@ #include #include +#include + #define UNIT_TESTING #include @@ -40,30 +38,19 @@ #include #include -#include "nstest.h" +#include static int -_setup(void **state) { - isc_result_t result; - - UNUSED(state); - +setup_test(void **state) { isc__nm_force_tid(0); - - result = ns_test_begin(NULL, true); - assert_int_equal(result, ISC_R_SUCCESS); - + setup_server(state); return (0); } static int -_teardown(void **state) { - UNUSED(state); - +teardown_test(void **state) { isc__nm_force_tid(-1); - - ns_test_end(); - + teardown_server(state); return (0); } @@ -183,8 +170,7 @@ run_sfcache_test(const ns__query_sfcache_test_params_t *test) { } /* test ns__query_sfcache() */ -static void -ns__query_sfcache_test(void **state) { +ISC_RUN_TEST_IMPL(ns_query_sfcache) { size_t i; const ns__query_sfcache_test_params_t tests[] = { @@ -326,6 +312,7 @@ run_start_test(const ns__query_start_test_params_t *test) { /* * Interrupt execution if query_lookup() or ns_query_done() is called. */ + ns_hooktable_create(mctx, &query_hooks); ns_hook_add(query_hooks, mctx, NS_QUERY_LOOKUP_BEGIN, &hook); ns_hook_add(query_hooks, mctx, NS_QUERY_DONE_BEGIN, &hook); @@ -447,8 +434,7 @@ run_start_test(const ns__query_start_test_params_t *test) { } /* test ns__query_start() */ -static void -ns__query_start_test(void **state) { +ISC_RUN_TEST_IMPL(ns_query_start) { size_t i; const ns__query_start_test_params_t tests[] = { @@ -1027,8 +1013,7 @@ run_hookasync_test(const ns__query_hookasync_test_params_t *test) { } } -static void -ns__query_hookasync_test(void **state) { +ISC_RUN_TEST_IMPL(ns_query_hookasync) { size_t i; UNUSED(state); @@ -1461,8 +1446,7 @@ run_hookasync_e2e_test(const ns__query_hookasync_e2e_test_params_t *test) { ns_hooktable_free(mctx, (void **)&ns__hook_table); } -static void -ns__query_hookasync_e2e_test(void **state) { +ISC_RUN_TEST_IMPL(ns_query_hookasync_e2e) { UNUSED(state); const ns__query_hookasync_e2e_test_params_t tests[] = { @@ -1505,31 +1489,12 @@ ns__query_hookasync_e2e_test(void **state) { } } -int -main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(ns__query_sfcache_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(ns__query_start_test, _setup, - _teardown), - cmocka_unit_test_setup_teardown(ns__query_hookasync_test, - _setup, _teardown), - cmocka_unit_test_setup_teardown(ns__query_hookasync_e2e_test, - _setup, _teardown), - }; +ISC_TEST_LIST_START - return (cmocka_run_group_tests(tests, NULL, NULL)); -} +ISC_TEST_ENTRY_CUSTOM(ns_query_sfcache, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(ns_query_start, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(ns_query_hookasync, setup_test, teardown_test) +ISC_TEST_ENTRY_CUSTOM(ns_query_hookasync_e2e, setup_test, teardown_test) -#else /* HAVE_CMOCKA */ - -#include - -int -main(void) { - printf("1..0 # Skipped: cmocka not available\n"); - - return (SKIPPED_TEST_EXIT_CODE); -} - -#endif /* HAVE_CMOCKA */ +ISC_TEST_LIST_END +ISC_TEST_MAIN diff --git a/lib/ns/tests/testdata/notify/notify1.msg b/tests/ns/testdata/notify/notify1.msg similarity index 100% rename from lib/ns/tests/testdata/notify/notify1.msg rename to tests/ns/testdata/notify/notify1.msg diff --git a/lib/ns/tests/testdata/notify/zone1.db b/tests/ns/testdata/notify/zone1.db similarity index 100% rename from lib/ns/tests/testdata/notify/zone1.db rename to tests/ns/testdata/notify/zone1.db diff --git a/lib/ns/tests/testdata/query/foo.db b/tests/ns/testdata/query/foo.db similarity index 100% rename from lib/ns/tests/testdata/query/foo.db rename to tests/ns/testdata/query/foo.db diff --git a/lib/unit-test-driver.sh.in b/tests/unit-test-driver.sh.in similarity index 100% rename from lib/unit-test-driver.sh.in rename to tests/unit-test-driver.sh.in