summaryrefslogtreecommitdiffstats
path: root/tests/include
diff options
context:
space:
mode:
Diffstat (limited to 'tests/include')
-rw-r--r--tests/include/tests/dns.h122
-rw-r--r--tests/include/tests/isc.h119
-rw-r--r--tests/include/tests/ns.h132
3 files changed, 373 insertions, 0 deletions
diff --git a/tests/include/tests/dns.h b/tests/include/tests/dns.h
new file mode 100644
index 0000000..64a265b
--- /dev/null
+++ b/tests/include/tests/dns.h
@@ -0,0 +1,122 @@
+/*
+ * 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/result.h>
+#include <isc/string.h>
+#include <isc/task.h>
+#include <isc/timer.h>
+#include <isc/util.h>
+
+#include <dns/cache.h>
+#include <dns/diff.h>
+#include <dns/zone.h>
+
+#include <tests/isc.h>
+
+extern dns_zonemgr_t *zonemgr;
+
+typedef struct {
+ dns_diffop_t op;
+ const char *owner;
+ dns_ttl_t ttl;
+ const char *type;
+ const char *rdata;
+} zonechange_t;
+
+#define ZONECHANGE_SENTINEL \
+ { \
+ 0, NULL, 0, NULL, NULL \
+ }
+
+isc_result_t
+dns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp);
+
+/*%
+ * Create a zone with origin 'name', return a pointer to the zone object in
+ * 'zonep'.
+ *
+ * If 'view' is set, the returned zone will be assigned to the passed view.
+ * 'createview' must be set to false when 'view' is non-NULL.
+ *
+ * If 'view' is not set and 'createview' is true, a new view is also created
+ * and the returned zone is assigned to it. This imposes two requirements on
+ * the caller: 1) the returned zone has to be subsequently assigned to a zone
+ * manager, otherwise its cleanup will fail, 2) the created view has to be
+ * cleaned up by the caller.
+ *
+ * If 'view' is not set and 'createview' is false, the returned zone will not
+ * be assigned to any view.
+ */
+isc_result_t
+dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
+ bool createview);
+
+isc_result_t
+dns_test_setupzonemgr(void);
+
+isc_result_t
+dns_test_managezone(dns_zone_t *zone);
+
+void
+dns_test_releasezone(dns_zone_t *zone);
+
+void
+dns_test_closezonemgr(void);
+
+void
+dns_test_nap(uint32_t usec);
+
+isc_result_t
+dns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
+ const char *testfile);
+
+isc_result_t
+dns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz,
+ size_t *sizep);
+
+char *
+dns_test_tohex(const unsigned char *data, size_t len, char *buf, size_t buflen);
+
+/*%
+ * Try parsing text form RDATA in "src" (of class "rdclass" and type "rdtype")
+ * into a structure representing that RDATA at "rdata", storing the
+ * uncompressed wire form of that RDATA at "dst", which is "dstlen" bytes long.
+ * Set 'warnings' to true to print logged warnings from dns_rdata_fromtext().
+ */
+isc_result_t
+dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
+ dns_rdatatype_t rdtype, unsigned char *dst,
+ size_t dstlen, const char *src, bool warnings);
+
+void
+dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname);
+
+/*%
+ * Given a pointer to an uninitialized dns_diff_t structure in 'diff', make it
+ * contain diff tuples representing zone database changes listed in 'changes'.
+ * Set 'warnings' to true to print logged warnings from dns_rdata_fromtext().
+ */
+isc_result_t
+dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes,
+ bool warnings);
diff --git a/tests/include/tests/isc.h b/tests/include/tests/isc.h
new file mode 100644
index 0000000..6131c20
--- /dev/null
+++ b/tests/include/tests/isc.h
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+#pragma once
+
+/*! \file */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <uv.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>
+
+#include "netmgr_p.h"
+#include "task_p.h"
+#include "timer_p.h"
+
+#define CHECK(r) \
+ do { \
+ result = (r); \
+ if (result != ISC_R_SUCCESS) \
+ goto cleanup; \
+ } while (0)
+
+extern isc_mem_t *mctx;
+extern isc_nm_t *netmgr;
+extern isc_taskmgr_t *taskmgr;
+extern isc_timermgr_t *timermgr;
+extern unsigned int workers;
+extern isc_task_t *maintask;
+
+#define isc_test_nap(ms) uv_sleep(ms)
+
+int
+setup_managers(void **state);
+int
+teardown_managers(void **state);
+
+#ifndef TESTS_DIR
+#define TESTS_DIR "./"
+#endif
+
+/* clang-format off */
+/* Copied from cmocka */
+#define ISC_TEST_ENTRY(name) \
+ { #name, run_test_##name, NULL, NULL, NULL },
+#define ISC_TEST_ENTRY_SETUP(name) \
+ { #name, run_test_##name, setup_test_##name, NULL, NULL },
+#define ISC_TEST_ENTRY_TEARDOWN(name) \
+ { #name, run_test_##name, NULL, teardown_test_##name, NULL },
+#define ISC_TEST_ENTRY_SETUP_TEARDOWN(name) \
+ { #name, run_test_##name, setup_test_##name, teardown_test_##name, NULL },
+#define ISC_TEST_ENTRY_CUSTOM(name, setup, teardown) \
+ { #name, run_test_##name, setup, teardown, NULL },
+/* clang-format on */
+
+#define ISC_SETUP_TEST_DECLARE(name) \
+ int setup_test_##name(void **state __attribute__((unused)));
+
+#define ISC_RUN_TEST_DECLARE(name) \
+ void run_test_##name(void **state __attribute__((unused)));
+
+#define ISC_TEARDOWN_TEST_DECLARE(name) \
+ int teardown_test_##name(void **state __attribute__((unused)))
+
+#define ISC_SETUP_TEST_IMPL(name) \
+ int setup_test_##name(void **state __attribute__((unused))); \
+ int setup_test_##name(void **state __attribute__((unused)))
+
+#define ISC_RUN_TEST_IMPL(name) \
+ void run_test_##name(void **state __attribute__((unused))); \
+ void run_test_##name(void **state __attribute__((unused)))
+
+#define ISC_TEARDOWN_TEST_IMPL(name) \
+ int teardown_test_##name(void **state __attribute__((unused))); \
+ int teardown_test_##name(void **state __attribute__((unused)))
+
+#define ISC_TEST_LIST_START const struct CMUnitTest tests[] = {
+#define ISC_TEST_LIST_END \
+ } \
+ ;
+
+#define ISC_TEST_MAIN ISC_TEST_MAIN_CUSTOM(NULL, NULL)
+
+#define ISC_TEST_MAIN_CUSTOM(setup, teardown) \
+ int main(void) { \
+ int r; \
+ \
+ signal(SIGPIPE, SIG_IGN); \
+ \
+ isc_mem_debugging |= ISC_MEM_DEBUGRECORD; \
+ isc_mem_create(&mctx); \
+ \
+ r = cmocka_run_group_tests(tests, setup, teardown); \
+ \
+ isc_mem_destroy(&mctx); \
+ \
+ return (r); \
+ }
diff --git a/tests/include/tests/ns.h b/tests/include/tests/ns.h
new file mode 100644
index 0000000..175cb90
--- /dev/null
+++ b/tests/include/tests/ns.h
@@ -0,0 +1,132 @@
+/*
+ * 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/result.h>
+#include <isc/string.h>
+#include <isc/task.h>
+#include <isc/timer.h>
+#include <isc/util.h>
+
+#include <dns/zone.h>
+
+#include <ns/client.h>
+#include <ns/hooks.h>
+#include <ns/interfacemgr.h>
+
+#include <tests/dns.h>
+
+typedef struct ns_test_id {
+ const char *description;
+ int lineno;
+} ns_test_id_t;
+
+#define NS_TEST_ID(desc) \
+ { \
+ .description = desc, .lineno = __LINE__ \
+ }
+
+#define CHECK(r) \
+ do { \
+ result = (r); \
+ if (result != ISC_R_SUCCESS) \
+ goto cleanup; \
+ } while (0)
+
+extern dns_dispatchmgr_t *dispatchmgr;
+extern ns_clientmgr_t *clientmgr;
+extern ns_interfacemgr_t *interfacemgr;
+extern ns_server_t *sctx;
+
+#ifdef NETMGR_TRACE
+#define FLARG \
+ , const char *file __attribute__((unused)), \
+ unsigned int line __attribute__((unused)), \
+ const char *func __attribute__((unused))
+#else
+#define FLARG
+#endif
+
+int
+setup_server(void **state);
+int
+teardown_server(void **state);
+
+/*%
+ * Load data for zone "zonename" from file "filename" and start serving it to
+ * clients matching "view". Only one zone loaded using this function can be
+ * served at any given time.
+ */
+isc_result_t
+ns_test_serve_zone(const char *zonename, const char *filename,
+ dns_view_t *view);
+
+/*%
+ * Release the zone loaded by ns_test_serve_zone().
+ */
+void
+ns_test_cleanup_zone(void);
+
+isc_result_t
+ns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
+ const char *testfile);
+
+isc_result_t
+ns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz,
+ size_t *sizep);
+
+isc_result_t
+ns_test_getclient(ns_interface_t *ifp0, bool tcp, ns_client_t **clientp);
+
+/*%
+ * Structure containing parameters for ns_test_qctx_create().
+ */
+typedef struct ns_test_qctx_create_params {
+ const char *qname;
+ dns_rdatatype_t qtype;
+ unsigned int qflags;
+ bool with_cache;
+} ns_test_qctx_create_params_t;
+
+/*%
+ * Prepare a query context identical with one that would be prepared if a query
+ * with given QNAME, QTYPE and flags was received from a client. Recursion is
+ * assumed to be allowed for this client. If "with_cache" is set to true,
+ * a cache database will be created and associated with the view matching the
+ * incoming query.
+ */
+isc_result_t
+ns_test_qctx_create(const ns_test_qctx_create_params_t *params,
+ query_ctx_t **qctxp);
+
+/*%
+ * Destroy a query context created by ns_test_qctx_create().
+ */
+void
+ns_test_qctx_destroy(query_ctx_t **qctxp);
+
+/*%
+ * A hook callback interrupting execution at given hook's insertion point.
+ */
+ns_hookresult_t
+ns_test_hook_catch_call(void *arg, void *data, isc_result_t *resultp);