2011-10-12 23:09:35 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2011-10-12 23:09:35 +00:00
|
|
|
*
|
2021-06-03 08:37:05 +02:00
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2011-10-12 23:09:35 +00:00
|
|
|
*/
|
|
|
|
|
2023-05-18 15:12:23 +02:00
|
|
|
#include <inttypes.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
|
|
|
#include <setjmp.h>
|
2018-11-09 10:23:49 -08:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2011-10-13 07:56:32 +00:00
|
|
|
#include <stdlib.h>
|
2018-11-09 10:23:49 -08:00
|
|
|
#include <string.h>
|
2011-10-13 07:56:32 +00:00
|
|
|
#include <unistd.h>
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
|
2011-10-12 23:09:35 +00:00
|
|
|
#include <isc/file.h>
|
|
|
|
#include <isc/result.h>
|
|
|
|
#include <isc/serial.h>
|
|
|
|
#include <isc/stdtime.h>
|
2018-11-09 10:23:49 -08:00
|
|
|
#include <isc/string.h>
|
|
|
|
#include <isc/util.h>
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
#include <dns/db.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <dns/nsec3.h>
|
2011-10-12 23:09:35 +00:00
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatasetiter.h>
|
|
|
|
|
2022-05-03 11:37:31 +02:00
|
|
|
#include <tests/dns.h>
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
static char tempname[11] = "dtXXXXXXXX";
|
|
|
|
static dns_db_t *db1 = NULL, *db2 = NULL;
|
2018-11-09 10:23:49 -08:00
|
|
|
static dns_dbversion_t *v1 = NULL, *v2 = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The code below enables us to trap assertion failures for testing
|
|
|
|
* purposes. local_callback() is set as the callback function for
|
|
|
|
* isc_assertion_failed(). It calls mock_assert() so that CMOCKA
|
2020-02-20 14:49:36 -08:00
|
|
|
* will be able to see it, then returns to the calling function via
|
2018-11-09 10:23:49 -08:00
|
|
|
* longjmp() so that the abort() call in isc_assertion_failed() will
|
|
|
|
* never be reached. Use check_assertion() to check for assertions
|
|
|
|
* instead of expect_assert_failure().
|
|
|
|
*/
|
|
|
|
jmp_buf assertion;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#define check_assertion(function_call) \
|
|
|
|
do { \
|
|
|
|
const int r = setjmp(assertion); \
|
|
|
|
if (r == 0) { \
|
|
|
|
expect_assert_failure(function_call); \
|
|
|
|
} \
|
|
|
|
} while (false);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
static void
|
2015-01-20 13:29:18 -08:00
|
|
|
local_callback(const char *file, int line, isc_assertiontype_t type,
|
2020-02-13 14:44:37 -08:00
|
|
|
const char *cond) {
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(type);
|
|
|
|
|
|
|
|
mock_assert(1, cond, file, line);
|
|
|
|
longjmp(assertion, 1);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
static int
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
setup_test(void **state) {
|
2018-11-09 10:23:49 -08:00
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
isc_assertion_setcallback(local_callback);
|
|
|
|
|
2024-03-05 16:17:33 -08:00
|
|
|
res = dns_db_create(mctx, ZONEDB_DEFAULT, dns_rootname, dns_dbtype_zone,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdataclass_in, 0, NULL, &db1);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_db_newversion(db1, &v1);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_non_null(v1);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2024-03-05 16:17:33 -08:00
|
|
|
res = dns_db_create(mctx, ZONEDB_DEFAULT, dns_rootname, dns_dbtype_zone,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdataclass_in, 0, NULL, &db2);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_db_newversion(db2, &v2);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_non_null(v1);
|
|
|
|
|
2024-11-19 10:38:03 +01:00
|
|
|
return 0;
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
static int
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
teardown_test(void **state) {
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
if (strcmp(tempname, "dtXXXXXXXX") != 0) {
|
|
|
|
unlink(tempname);
|
|
|
|
}
|
|
|
|
|
2011-10-12 23:09:35 +00:00
|
|
|
if (v1 != NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_db_closeversion(db1, &v1, false);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(v1);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
if (db1 != NULL) {
|
|
|
|
dns_db_detach(&db1);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(db1);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (v2 != NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_db_closeversion(db2, &v2, false);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(v2);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
if (db2 != NULL) {
|
|
|
|
dns_db_detach(&db2);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(db2);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
2018-11-09 10:23:49 -08:00
|
|
|
|
2024-11-19 10:38:03 +01:00
|
|
|
return 0;
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-11-09 10:23:49 -08:00
|
|
|
* Check dns_db_attachversion() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
2011-10-12 23:09:35 +00:00
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(attachversion) {
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_dbversion_t *v = NULL;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_db_attachversion(db1, v1, &v);
|
|
|
|
assert_ptr_equal(v, v1);
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_db_closeversion(db1, &v, false);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(v);
|
2011-10-13 22:48:24 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_attachversion(db1, v2, &v));
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_closeversion() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(closeversion) {
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-13 22:48:24 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_non_null(v1);
|
|
|
|
dns_db_closeversion(db1, &v1, false);
|
|
|
|
assert_null(v1);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_closeversion(db1, &v2, false));
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_find() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(find) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t res;
|
|
|
|
dns_rdataset_t rdataset;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_fixedname_t fixed;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t *name = NULL;
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
name = dns_fixedname_initname(&fixed);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
2020-02-12 13:59:18 +01:00
|
|
|
res = dns_db_find(db1, dns_rootname, v1, dns_rdatatype_soa, 0, 0, NULL,
|
|
|
|
name, &rdataset, NULL);
|
2024-12-19 14:19:43 -08:00
|
|
|
/*
|
|
|
|
* Note: in the QPzone database, the root node always exists,
|
|
|
|
* even if it's empty, so we would get DNS_R_NXRRSET from this
|
|
|
|
* query. In other databases (including the old RBTDB) the root
|
|
|
|
* node can be nonexistent, and the query would then return
|
|
|
|
* DNS_R_NXDOMAIN. Allow for both possibilities.
|
|
|
|
*/
|
|
|
|
assert_true(res == DNS_R_NXRRSET || res == DNS_R_NXDOMAIN);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
if (dns_rdataset_isassociated(&rdataset)) {
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
2018-10-24 20:00:46 +02:00
|
|
|
}
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_rdataset_init(&rdataset);
|
Silence unchecked return of dns_db_find()
190 dns_rdataset_init(&rdataset);
3. Condition r == 0, taking true branch.
4. Condition result, taking false branch.
CID 1452691 (#1 of 1): Unchecked return value (CHECKED_RETURN)
5. check_return: Calling dns_db_find without checking return
value (as is done elsewhere 39 out of 45 times).
191 check_assertion(dns_db_find(db1, dns_rootname, v2,
192 dns_rdatatype_soa, 0, 0, NULL,
193 name, &rdataset, NULL));
2020-02-06 11:02:55 +11:00
|
|
|
check_assertion((void)dns_db_find(db1, dns_rootname, v2,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatype_soa, 0, 0, NULL, name,
|
|
|
|
&rdataset, NULL));
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_allrdatasets() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(allrdatasets) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t res;
|
|
|
|
dns_dbnode_t *node = NULL;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_rdatasetiter_t *iterator = NULL;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2022-11-16 10:47:40 +11:00
|
|
|
res = dns_db_allrdatasets(db1, node, v1, 0, 0, &iterator);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2022-11-16 10:47:40 +11:00
|
|
|
check_assertion(dns_db_allrdatasets(db1, node, v2, 0, 0, &iterator));
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_rdatasetiter_destroy(&iterator);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(iterator);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_db_detachnode(db1, &node);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_findrdataset() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(findrdataset) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_rdataset_t rdataset;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_dbnode_t *node = NULL;
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
2020-02-12 13:59:18 +01:00
|
|
|
res = dns_db_findrdataset(db1, node, v1, dns_rdatatype_soa, 0, 0,
|
|
|
|
&rdataset, NULL);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_int_equal(res, ISC_R_NOTFOUND);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
if (dns_rdataset_isassociated(&rdataset)) {
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
2018-10-24 20:00:46 +02:00
|
|
|
}
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_rdataset_init(&rdataset);
|
2020-02-12 13:59:18 +01:00
|
|
|
check_assertion(dns_db_findrdataset(db1, node, v2, dns_rdatatype_soa, 0,
|
|
|
|
0, &rdataset, NULL));
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_db_detachnode(db1, &node);
|
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_deleterdataset() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(deleterdataset) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_dbnode_t *node = NULL;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_deleterdataset(db1, node, v1, dns_rdatatype_soa, 0);
|
|
|
|
assert_int_equal(res, DNS_R_UNCHANGED);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
check_assertion(
|
|
|
|
dns_db_deleterdataset(db1, node, v2, dns_rdatatype_soa, 0));
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_db_detachnode(db1, &node);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_subtractrdataset() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(subtract) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t res;
|
|
|
|
dns_rdataset_t rdataset;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_rdatalist_t rdatalist;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_dbnode_t *node = NULL;
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
dns_rdatalist_init(&rdatalist);
|
|
|
|
|
|
|
|
rdatalist.rdclass = dns_rdataclass_in;
|
|
|
|
|
2022-07-29 12:40:45 +00:00
|
|
|
dns_rdatalist_tordataset(&rdatalist, &rdataset);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-13 22:48:24 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_subtractrdataset(db1, node, v1, &rdataset, 0, NULL);
|
|
|
|
assert_int_equal(res, DNS_R_UNCHANGED);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
if (dns_rdataset_isassociated(&rdataset)) {
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
}
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_rdataset_init(&rdataset);
|
2022-07-29 12:40:45 +00:00
|
|
|
dns_rdatalist_tordataset(&rdatalist, &rdataset);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
check_assertion(
|
|
|
|
dns_db_subtractrdataset(db1, node, v2, &rdataset, 0, NULL));
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_db_detachnode(db1, &node);
|
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_addrdataset() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(addrdataset) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t res;
|
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
dns_dbnode_t *node = NULL;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_rdatalist_t rdatalist;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
dns_rdatalist_init(&rdatalist);
|
|
|
|
|
|
|
|
rdatalist.rdclass = dns_rdataclass_in;
|
|
|
|
|
2022-07-29 12:40:45 +00:00
|
|
|
dns_rdatalist_tordataset(&rdatalist, &rdataset);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_addrdataset(db1, node, v1, 0, &rdataset, 0, NULL);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
check_assertion(
|
|
|
|
dns_db_addrdataset(db1, node, v2, 0, &rdataset, 0, NULL));
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_db_detachnode(db1, &node);
|
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_getnsec3parameters() passes with matching db and version,
|
|
|
|
* and asserts with mis-matching db and version.
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(getnsec3parameters) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t res;
|
|
|
|
dns_hash_t hash;
|
|
|
|
uint8_t flags;
|
|
|
|
uint16_t iterations;
|
2011-10-12 23:09:35 +00:00
|
|
|
unsigned char salt[DNS_NSEC3_SALTSIZE];
|
2020-02-13 14:44:37 -08:00
|
|
|
size_t salt_length = sizeof(salt);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
res = dns_db_getnsec3parameters(db1, v1, &hash, &flags, &iterations,
|
|
|
|
salt, &salt_length);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_int_equal(res, ISC_R_NOTFOUND);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
check_assertion(dns_db_getnsec3parameters(
|
|
|
|
db1, v2, &hash, &flags, &iterations, salt, &salt_length));
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_TEST_LIST_START
|
|
|
|
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(attachversion, setup_test, teardown_test)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(closeversion, setup_test, teardown_test)
|
|
|
|
ISC_TEST_LIST_END
|
|
|
|
|
|
|
|
ISC_TEST_MAIN
|