2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-23 10:39:16 +00:00
bind/lib/ns/tests/plugin_test.c
Ondřej Surý 978c7b2e89 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
2020-04-21 14:19:48 +02:00

209 lines
4.7 KiB
C

/*
* 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 <limits.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/attributes.h>
#include <isc/mem.h>
#include <isc/platform.h>
#include <isc/result.h>
#include <isc/types.h>
#include <isc/util.h>
ISC_NORETURN void
_fail(const char *const file, const int line);
#include <ns/hooks.h>
#include "nstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = ns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
if (*state != NULL) {
isc_mem_free(mctx, *state);
}
ns_test_end();
return (0);
}
/*%
* Structure containing parameters for run_full_path_test().
*/
typedef struct {
const ns_test_id_t id; /* libns test identifier */
const char *input; /* source string - plugin name or path
* */
size_t output_size; /* size of target char array to
* allocate */
isc_result_t result; /* expected return value */
const char *output; /* expected output string */
} ns_plugin_expandpath_test_params_t;
/*%
* Perform a single ns_plugin_expandpath() check using given parameters.
*/
static void
run_full_path_test(const ns_plugin_expandpath_test_params_t *test,
void **state) {
char **target = (char **)state;
isc_result_t result;
REQUIRE(test != NULL);
REQUIRE(test->id.description != NULL);
REQUIRE(test->input != NULL);
REQUIRE(test->result != ISC_R_SUCCESS || test->output != NULL);
/*
* Prepare a target buffer of given size. Store it in 'state' so that
* it can get cleaned up by _teardown() if the test fails.
*/
*target = isc_mem_allocate(mctx, test->output_size);
/*
* Call ns_plugin_expandpath().
*/
result = ns_plugin_expandpath(test->input, *target, test->output_size);
/*
* Check return value.
*/
if (result != test->result) {
fail_msg("# test \"%s\" on line %d: "
"expected result %d (%s), got %d (%s)",
test->id.description, test->id.lineno, test->result,
isc_result_totext(test->result), result,
isc_result_totext(result));
}
/*
* Check output string if return value indicates success.
*/
if (result == ISC_R_SUCCESS && strcmp(*target, test->output) != 0) {
fail_msg("# test \"%s\" on line %d: "
"expected output \"%s\", got \"%s\"",
test->id.description, test->id.lineno, test->output,
*target);
}
isc_mem_free(mctx, *target);
}
/* test ns_plugin_expandpath() */
static void
ns_plugin_expandpath_test(void **state) {
size_t i;
const ns_plugin_expandpath_test_params_t tests[] = {
{
NS_TEST_ID("correct use with an absolute path"),
.input = "/usr/lib/named/foo.so",
.output_size = PATH_MAX,
.result = ISC_R_SUCCESS,
.output = "/usr/lib/named/foo.so",
},
{
NS_TEST_ID("correct use with a relative path"),
.input = "../../foo.so",
.output_size = PATH_MAX,
.result = ISC_R_SUCCESS,
.output = "../../foo.so",
},
{
NS_TEST_ID("correct use with a filename"),
.input = "foo.so",
.output_size = PATH_MAX,
.result = ISC_R_SUCCESS,
#ifndef WIN32
.output = NAMED_PLUGINDIR "/foo.so",
#else /* ifndef WIN32 */
.output = "foo.so",
#endif /* ifndef WIN32 */
},
{
NS_TEST_ID("no space at all in target buffer"),
.input = "/usr/lib/named/foo.so",
.output_size = 0,
.result = ISC_R_NOSPACE,
},
{
NS_TEST_ID("target buffer too small to fit input"),
.input = "/usr/lib/named/foo.so",
.output_size = 1,
.result = ISC_R_NOSPACE,
},
{
NS_TEST_ID("target buffer too small to fit NULL byte"),
.input = "/foo.so",
.output_size = 7,
.result = ISC_R_NOSPACE,
},
#ifndef WIN32
{
NS_TEST_ID("target buffer too small to fit full path"),
.input = "foo.so",
.output_size = 7,
.result = ISC_R_NOSPACE,
},
#endif /* ifndef WIN32 */
};
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
run_full_path_test(&tests[i], state);
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(ns_plugin_expandpath_test,
_setup, _teardown),
};
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 (0);
}
#endif /* if HAVE_CMOCKA */