2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

Merge branch 'ondrej-unit-tests-refactoring' into 'main'

Give the unit tests a big overhaul and move all the unit tests to /tests/<libname>/

See merge request isc-projects/bind9!6243
This commit is contained in:
Ondřej Surý
2022-05-31 08:56:05 +00:00
211 changed files with 2381 additions and 5801 deletions

View File

@@ -58,6 +58,8 @@ IncludeCategories:
Priority: 55
- Regex: '^".*"'
Priority: 99
- Regex: '^<tests/'
Priority: 100
- Regex: '<openssl/'
Priority: 1
- Regex: '<(mysql|protobuf-c)/'

View File

@@ -48,6 +48,8 @@ IncludeCategories:
Priority: 7
- Regex: '^(<[^/]*)/)'
Priority: 8
- Regex: '^<tests/'
Priority: 10
- Regex: '<[[:alnum:].]+>'
Priority: 1
- Regex: '".*"'

View File

@@ -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:

View File

@@ -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.

View File

@@ -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 \

View File

@@ -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)

View File

@@ -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

View File

@@ -321,7 +321,3 @@ if HAVE_LMDB
libdns_la_CPPFLAGS += $(LMDB_CFLAGS)
libdns_la_LIBADD += $(LMDB_LIBS)
endif
if HAVE_CMOCKA
SUBDIRS = tests
endif

1
lib/dns/tests Symbolic link
View File

@@ -0,0 +1 @@
../../tests/dns

View File

@@ -25,7 +25,3 @@ libirs_la_LIBADD = \
libirs_la_LDFLAGS = \
$(AM_LDFLAGS) \
-release "$(PACKAGE_VERSION)"
if HAVE_CMOCKA
SUBDIRS = tests
endif

1
lib/irs/tests Symbolic link
View File

@@ -0,0 +1 @@
../../tests/irs

View File

@@ -251,7 +251,3 @@ libisc_la_CPPFLAGS += \
libisc_la_LIBADD += \
$(LIBXML2_LIBS)
endif HAVE_LIBXML2
if HAVE_CMOCKA
SUBDIRS = tests
endif

1
lib/isc/tests Symbolic link
View File

@@ -0,0 +1 @@
../../tests/isc

View File

@@ -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 <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include <isc/buffer.h>
#include <isc/hash.h>
#include <isc/managers.h>
#include <isc/mem.h>
#include <isc/os.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
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);
}

View File

@@ -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 <inttypes.h>
#include <stdbool.h>
#include <isc/buffer.h>
#include <isc/hash.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/netmgr.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
#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);

View File

@@ -33,7 +33,3 @@ libisccfg_la_LIBADD = \
libisccfg_la_LDFLAGS = \
$(AM_LDFLAGS) \
-release "$(PACKAGE_VERSION)"
if HAVE_CMOCKA
SUBDIRS = tests
endif

1
lib/isccfg/tests Symbolic link
View File

@@ -0,0 +1 @@
../../tests/isccfg

View File

@@ -55,7 +55,3 @@ libns_la_LIBADD = \
libns_la_LDFLAGS = \
$(AM_LDFLAGS) \
-release "$(PACKAGE_VERSION)"
if HAVE_CMOCKA
SUBDIRS = tests
endif

1
lib/ns/tests Symbolic link
View File

@@ -0,0 +1 @@
../../tests/ns

1
tests/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/unit-test-driver.sh

16
tests/Makefile.am Normal file
View File

@@ -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 =

View File

@@ -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) \

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -31,36 +29,14 @@
#include <dns/acl.h>
#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 <tests/dns.h>
#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, &notnone);
result = dns_acl_create(mctx, 1, &notnone);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_acl_create(dt_mctx, 1, &notany);
result = dns_acl_create(mctx, 1, &notany);
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, &notgeoip);
result = dns_acl_create(mctx, 1, &notgeoip);
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -29,28 +27,7 @@
#include <dns/name.h>
#include <dns/rdatalist.h>
#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 <tests/dns.h>
#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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -31,33 +29,12 @@
#include <dns/journal.h>
#include <dns/name.h>
#include "dnstest.h"
#include <tests/dns.h>
#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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -30,33 +28,12 @@
#include <dns/dbiterator.h>
#include <dns/name.h>
#include "dnstest.h"
#include <tests/dns.h>
#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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -37,7 +35,7 @@
#include <dns/rdataset.h>
#include <dns/rdatasetiter.h>
#include "dnstest.h"
#include <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -30,33 +28,36 @@
#include <dns/name.h>
#include "../dst_internal.h"
#include "dnstest.h"
#include "dst_internal.h"
#include <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@@ -37,7 +35,7 @@
#include <dns/name.h>
#include <dns/view.h>
#include "dnstest.h"
#include <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -34,6 +32,8 @@
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@@ -24,6 +22,9 @@
#define UNIT_TESTING
#include <cmocka.h>
#include <fstrm.h>
#include <protobuf-c/protobuf-c.h>
#include <isc/buffer.h>
#include <isc/file.h>
@@ -35,63 +36,48 @@
#include <dns/dnstap.h>
#include <dns/view.h>
#include "dnstest.h"
#include <tests/dns.h>
#ifdef HAVE_DNSTAP
#define TAPFILE TESTS_DIR "/testdata/dnstap/dnstap.file"
#define TAPSOCK TESTS_DIR "/testdata/dnstap/dnstap.sock"
#include <fstrm.h>
#include <protobuf-c/protobuf-c.h>
#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 <stdio.h>
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

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -33,26 +31,24 @@
#include <dst/dst.h>
#include "../dst_internal.h"
#include "dnstest.h"
#include "dst_internal.h"
#include <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -34,11 +32,9 @@
#include <dns/geoip.h>
#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 <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@@ -42,28 +40,7 @@
#include <dst/dst.h>
#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 <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -40,28 +38,7 @@
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#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 <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@@ -38,35 +36,13 @@
#include <dns/fixedname.h>
#include <dns/name.h>
#include "dnstest.h"
#include <tests/dns.h>
/* 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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -30,28 +28,7 @@
#include <dns/db.h>
#include <dns/nsec3.h>
#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 <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -32,8 +30,9 @@
#include <dns/db.h>
#include <dns/nsec3.h>
#include "../zone_p.h"
#include "dnstest.h"
#include "zone_p.h"
#include <tests/dns.h>
#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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -28,46 +26,22 @@
#include <dns/peer.h>
#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 <tests/dns.h>
/* 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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@@ -35,27 +33,30 @@
#include <dst/dst.h>
#include "dnstest.h"
#include <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <ctype.h>
#include <fcntl.h>
#include <inttypes.h>
@@ -29,7 +27,6 @@
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/file.h>
#include <isc/hash.h>
@@ -54,7 +51,7 @@
#include <dst/dst.h>
#include "dnstest.h"
#include <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -29,33 +27,18 @@
#include <dns/rbt.h>
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#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 <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -35,7 +33,7 @@
#include <dns/rdata.h>
#include "dnstest.h"
#include <tests/dns.h>
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 <character-string>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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -29,32 +27,10 @@
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#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 <tests/dns.h>
/* 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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@@ -31,28 +29,7 @@
#include <dns/stats.h>
#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 <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -36,7 +34,7 @@
#include <dns/resolver.h>
#include <dns/view.h>
#include "dnstest.h"
#include <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -28,26 +26,30 @@
#include <isc/print.h>
#include <isc/util.h>
#include "../dst_internal.h"
#include "dnstest.h"
#include "dst_internal.h"
#include <tests/dns.h>
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@@ -45,29 +43,9 @@
#include <dst/dst.h>
#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 <tests/dns.h>
/*%
* 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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

Some files were not shown because too many files have changed in this diff Show More