2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 18:19:42 +00:00
bind/lib/irs/tests/resconf_test.c

140 lines
3.6 KiB
C
Raw Normal View History

/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* 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 http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/mem.h>
#include <isc/util.h>
#include <irs/resconf.h>
static isc_mem_t *mctx = NULL;
static void
Complete rewrite the BIND 9 build system The rewrite of BIND 9 build system is a large work and cannot be reasonable split into separate merge requests. Addition of the automake has a positive effect on the readability and maintainability of the build system as it is more declarative, it allows conditional and we are able to drop all of the custom make code that BIND 9 developed over the years to overcome the deficiencies of autoconf + custom Makefile.in files. This squashed commit contains following changes: - conversion (or rather fresh rewrite) of all Makefile.in files to Makefile.am by using automake - the libtool is now properly integrated with automake (the way we used it was rather hackish as the only official way how to use libtool is via automake - the dynamic module loading was rewritten from a custom patchwork to libtool's libltdl (which includes the patchwork to support module loading on different systems internally) - conversion of the unit test executor from kyua to automake parallel driver - conversion of the system test executor from custom make/shell to automake parallel driver - The GSSAPI has been refactored, the custom SPNEGO on the basis that all major KRB5/GSSAPI (mit-krb5, heimdal and Windows) implementations support SPNEGO mechanism. - The various defunct tests from bin/tests have been removed: bin/tests/optional and bin/tests/pkcs11 - The text files generated from the MD files have been removed, the MarkDown has been designed to be readable by both humans and computers - The xsl header is now generated by a simple sed command instead of perl helper - The <irs/platform.h> header has been removed - cleanups of configure.ac script to make it more simpler, addition of multiple macros (there's still work to be done though) - the tarball can now be prepared with `make dist` - the system tests are partially able to run in oot build Here's a list of unfinished work that needs to be completed in subsequent merge requests: - `make distcheck` doesn't yet work (because of system tests oot run is not yet finished) - documentation is not yet built, there's a different merge request with docbook to sphinx-build rst conversion that needs to be rebased and adapted on top of the automake - msvc build is non functional yet and we need to decide whether we will just cross-compile bind9 using mingw-w64 or fix the msvc build - contributed dlz modules are not included neither in the autoconf nor automake
2018-08-07 16:46:53 +02:00
setup_test(void) {
isc_mem_create(&mctx);
/*
* the caller might run from another directory, but tests
* that access test data files must first chdir to the proper
* location.
*/
assert_return_code(chdir(TESTS_DIR), 0);
}
/* test irs_resconf_load() */
static void
2020-02-13 14:44:37 -08:00
irs_resconf_load_test(void **state) {
isc_result_t result;
irs_resconf_t *resconf = NULL;
2020-02-13 14:44:37 -08:00
unsigned int i;
struct {
2020-02-13 14:44:37 -08:00
const char *file;
isc_result_t loadres;
isc_result_t (*check)(irs_resconf_t *resconf);
isc_result_t checkres;
} tests[] = {
{ "testdata/domain.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
{ "testdata/nameserver-v4.conf", ISC_R_SUCCESS, NULL,
ISC_R_SUCCESS },
{ "testdata/nameserver-v6.conf", ISC_R_SUCCESS, NULL,
ISC_R_SUCCESS },
{ "testdata/nameserver-v6-scoped.conf", ISC_R_SUCCESS, NULL,
ISC_R_SUCCESS },
{ "testdata/options-debug.conf", ISC_R_SUCCESS, NULL,
ISC_R_SUCCESS },
{ "testdata/options-ndots.conf", ISC_R_SUCCESS, NULL,
ISC_R_SUCCESS },
{ "testdata/options-timeout.conf", ISC_R_SUCCESS, NULL,
ISC_R_SUCCESS },
{ "testdata/options-unknown.conf", ISC_R_SUCCESS, NULL,
ISC_R_SUCCESS },
{ "testdata/options.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
{ "testdata/options-bad-ndots.conf", ISC_R_RANGE, NULL,
ISC_R_SUCCESS },
{ "testdata/options-empty.conf", ISC_R_UNEXPECTEDEND, NULL,
ISC_R_SUCCESS },
{ "testdata/port.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
{ "testdata/resolv.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
{ "testdata/search.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
{ "testdata/sortlist-v4.conf", ISC_R_SUCCESS, NULL,
ISC_R_SUCCESS },
{ "testdata/timeout.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
{ "testdata/unknown.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }
};
UNUSED(state);
setup_test();
for (i = 0; i < sizeof(tests) / sizeof(tests[1]); i++) {
result = irs_resconf_load(mctx, tests[i].file, &resconf);
if (result != tests[i].loadres) {
fail_msg("# unexpected result %s loading %s",
isc_result_totext(result), tests[i].file);
}
if (result == ISC_R_SUCCESS && resconf == NULL) {
fail_msg("# NULL on success loading %s", tests[i].file);
} else if (result != ISC_R_SUCCESS && resconf != NULL) {
fail_msg("# non-NULL on failure loading %s",
tests[i].file);
}
if (resconf != NULL && tests[i].check != NULL) {
result = (tests[i].check)(resconf);
if (result != tests[i].checkres) {
fail_msg("# unexpected result %s loading %s",
isc_result_totext(result),
tests[i].file);
}
}
if (resconf != NULL) {
irs_resconf_destroy(&resconf);
}
}
isc_mem_detach(&mctx);
}
int
2020-02-13 14:44:37 -08:00
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(irs_resconf_load_test),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
2020-02-13 14:44:37 -08:00
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (0);
}
#endif /* if HAVE_CMOCKA */