2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

convert zonemgr_test

This commit is contained in:
Evan Hunt 2018-10-25 20:30:51 -07:00
parent 0a4f6122de
commit 01a193ff6c
3 changed files with 109 additions and 98 deletions

View File

@ -30,5 +30,5 @@ atf_test_program{name='time_test'}
tap_test_program{name='tkey_test'} tap_test_program{name='tkey_test'}
atf_test_program{name='tsig_test'} atf_test_program{name='tsig_test'}
atf_test_program{name='update_test'} atf_test_program{name='update_test'}
atf_test_program{name='zonemgr_test'} tap_test_program{name='zonemgr_test'}
tap_test_program{name='zt_test'} tap_test_program{name='zt_test'}

View File

@ -254,9 +254,9 @@ update_test@EXEEXT@: update_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${ISCLIBS} ${LIBS} ${ISCLIBS} ${LIBS}
zonemgr_test@EXEEXT@: zonemgr_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} zonemgr_test@EXEEXT@: zonemgr_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
zonemgr_test.@O@ dnstest.@O@ ${DNSLIBS} \ ${LDFLAGS} -o $@ zonemgr_test.@O@ dnstest.@O@ \
${ISCLIBS} ${LIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
zt_test@EXEEXT@: zt_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} zt_test@EXEEXT@: zt_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \ ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \

View File

@ -9,18 +9,25 @@
* information regarding copyright ownership. * information regarding copyright ownership.
*/ */
/*! \file */
#include <config.h> #include <config.h>
#include <atf-c.h> #if HAVE_CMOCKA
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/buffer.h> #include <isc/buffer.h>
#include <isc/task.h> #include <isc/task.h>
#include <isc/timer.h> #include <isc/timer.h>
#include <isc/util.h>
#include <dns/name.h> #include <dns/name.h>
#include <dns/view.h> #include <dns/view.h>
@ -28,127 +35,121 @@
#include "dnstest.h" #include "dnstest.h"
/* static int
* Individual unit tests _setup(void **state) {
*/ isc_result_t result;
ATF_TC(zonemgr_create);
ATF_TC_HEAD(zonemgr_create, tc) { UNUSED(state);
atf_tc_set_md_var(tc, "descr", "create zone manager");
result = dns_test_begin(NULL, true);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
} }
ATF_TC_BODY(zonemgr_create, tc) {
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
/* create zone manager */
static void
zonemgr_create(void **state) {
dns_zonemgr_t *myzonemgr = NULL; dns_zonemgr_t *myzonemgr = NULL;
isc_result_t result; isc_result_t result;
UNUSED(tc); UNUSED(state);
result = dns_test_begin(NULL, true);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr, result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
&myzonemgr); &myzonemgr);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
dns_zonemgr_shutdown(myzonemgr); dns_zonemgr_shutdown(myzonemgr);
dns_zonemgr_detach(&myzonemgr); dns_zonemgr_detach(&myzonemgr);
ATF_REQUIRE_EQ(myzonemgr, NULL); assert_null(myzonemgr);
dns_test_end();
} }
/* manage and release a zone */
ATF_TC(zonemgr_managezone); static void
ATF_TC_HEAD(zonemgr_managezone, tc) { zonemgr_managezone(void **state) {
atf_tc_set_md_var(tc, "descr", "manage and release a zone");
}
ATF_TC_BODY(zonemgr_managezone, tc) {
dns_zonemgr_t *myzonemgr = NULL; dns_zonemgr_t *myzonemgr = NULL;
dns_zone_t *zone = NULL; dns_zone_t *zone = NULL;
isc_result_t result; isc_result_t result;
UNUSED(tc); UNUSED(state);
result = dns_test_begin(NULL, true);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr, result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
&myzonemgr); &myzonemgr);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
result = dns_test_makezone("foo", &zone, NULL, false); result = dns_test_makezone("foo", &zone, NULL, false);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
/* This should not succeed until the dns_zonemgr_setsize() is run */ /* This should not succeed until the dns_zonemgr_setsize() is run */
result = dns_zonemgr_managezone(myzonemgr, zone); result = dns_zonemgr_managezone(myzonemgr, zone);
ATF_REQUIRE_EQ(result, ISC_R_FAILURE); assert_int_equal(result, ISC_R_FAILURE);
ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0); assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
result = dns_zonemgr_setsize(myzonemgr, 1); result = dns_zonemgr_setsize(myzonemgr, 1);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
/* Now it should succeed */ /* Now it should succeed */
result = dns_zonemgr_managezone(myzonemgr, zone); result = dns_zonemgr_managezone(myzonemgr, zone);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 1); assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 1);
dns_zonemgr_releasezone(myzonemgr, zone); dns_zonemgr_releasezone(myzonemgr, zone);
dns_zone_detach(&zone); dns_zone_detach(&zone);
ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0); assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
dns_zonemgr_shutdown(myzonemgr); dns_zonemgr_shutdown(myzonemgr);
dns_zonemgr_detach(&myzonemgr); dns_zonemgr_detach(&myzonemgr);
ATF_REQUIRE_EQ(myzonemgr, NULL); assert_null(myzonemgr);
dns_test_end();
} }
ATF_TC(zonemgr_createzone); /* create and release a zone */
ATF_TC_HEAD(zonemgr_createzone, tc) { static void
atf_tc_set_md_var(tc, "descr", "create and release a zone"); zonemgr_createzone(void **state) {
}
ATF_TC_BODY(zonemgr_createzone, tc) {
dns_zonemgr_t *myzonemgr = NULL; dns_zonemgr_t *myzonemgr = NULL;
dns_zone_t *zone = NULL; dns_zone_t *zone = NULL;
isc_result_t result; isc_result_t result;
UNUSED(tc); UNUSED(state);
result = dns_test_begin(NULL, true);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr, result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
&myzonemgr); &myzonemgr);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
/* This should not succeed until the dns_zonemgr_setsize() is run */ /* This should not succeed until the dns_zonemgr_setsize() is run */
result = dns_zonemgr_createzone(myzonemgr, &zone); result = dns_zonemgr_createzone(myzonemgr, &zone);
ATF_REQUIRE_EQ(result, ISC_R_FAILURE); assert_int_equal(result, ISC_R_FAILURE);
result = dns_zonemgr_setsize(myzonemgr, 1); result = dns_zonemgr_setsize(myzonemgr, 1);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
/* Now it should succeed */ /* Now it should succeed */
result = dns_zonemgr_createzone(myzonemgr, &zone); result = dns_zonemgr_createzone(myzonemgr, &zone);
ATF_CHECK_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
ATF_CHECK(zone != NULL); assert_non_null(zone);
if (zone != NULL) if (zone != NULL)
dns_zone_detach(&zone); dns_zone_detach(&zone);
dns_zonemgr_shutdown(myzonemgr); dns_zonemgr_shutdown(myzonemgr);
dns_zonemgr_detach(&myzonemgr); dns_zonemgr_detach(&myzonemgr);
ATF_REQUIRE_EQ(myzonemgr, NULL); assert_null(myzonemgr);
dns_test_end();
} }
ATF_TC(zonemgr_unreachable); /* manage and release a zone */
ATF_TC_HEAD(zonemgr_unreachable, tc) { static void
atf_tc_set_md_var(tc, "descr", "manage and release a zone"); zonemgr_unreachable(void **state) {
}
ATF_TC_BODY(zonemgr_unreachable, tc) {
dns_zonemgr_t *myzonemgr = NULL; dns_zonemgr_t *myzonemgr = NULL;
dns_zone_t *zone = NULL; dns_zone_t *zone = NULL;
isc_sockaddr_t addr1, addr2; isc_sockaddr_t addr1, addr2;
@ -156,80 +157,62 @@ ATF_TC_BODY(zonemgr_unreachable, tc) {
isc_result_t result; isc_result_t result;
isc_time_t now; isc_time_t now;
UNUSED(tc); UNUSED(state);
TIME_NOW(&now); TIME_NOW(&now);
result = dns_test_begin(NULL, true);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr, result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
&myzonemgr); &myzonemgr);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
result = dns_test_makezone("foo", &zone, NULL, false); result = dns_test_makezone("foo", &zone, NULL, false);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
result = dns_zonemgr_setsize(myzonemgr, 1); result = dns_zonemgr_setsize(myzonemgr, 1);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
result = dns_zonemgr_managezone(myzonemgr, zone); result = dns_zonemgr_managezone(myzonemgr, zone);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
in.s_addr = inet_addr("10.53.0.1"); in.s_addr = inet_addr("10.53.0.1");
isc_sockaddr_fromin(&addr1, &in, 2112); isc_sockaddr_fromin(&addr1, &in, 2112);
in.s_addr = inet_addr("10.53.0.2"); in.s_addr = inet_addr("10.53.0.2");
isc_sockaddr_fromin(&addr2, &in, 5150); isc_sockaddr_fromin(&addr2, &in, 5150);
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now)); assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
/* /*
* We require multiple unreachableadd calls to mark a server as * We require multiple unreachableadd calls to mark a server as
* unreachable. * unreachable.
*/ */
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now); dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now)); assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now); dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now)); assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
in.s_addr = inet_addr("10.53.0.3"); in.s_addr = inet_addr("10.53.0.3");
isc_sockaddr_fromin(&addr2, &in, 5150); isc_sockaddr_fromin(&addr2, &in, 5150);
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now)); assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
/* /*
* We require multiple unreachableadd calls to mark a server as * We require multiple unreachableadd calls to mark a server as
* unreachable. * unreachable.
*/ */
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now); dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now); dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now)); assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2); dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now)); assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
in.s_addr = inet_addr("10.53.0.2"); in.s_addr = inet_addr("10.53.0.2");
isc_sockaddr_fromin(&addr2, &in, 5150); isc_sockaddr_fromin(&addr2, &in, 5150);
ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now)); assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2); dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now)); assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
dns_zonemgr_releasezone(myzonemgr, zone); dns_zonemgr_releasezone(myzonemgr, zone);
dns_zone_detach(&zone); dns_zone_detach(&zone);
dns_zonemgr_shutdown(myzonemgr); dns_zonemgr_shutdown(myzonemgr);
dns_zonemgr_detach(&myzonemgr); dns_zonemgr_detach(&myzonemgr);
ATF_REQUIRE_EQ(myzonemgr, NULL); assert_null(myzonemgr);
dns_test_end();
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, zonemgr_create);
ATF_TP_ADD_TC(tp, zonemgr_managezone);
ATF_TP_ADD_TC(tp, zonemgr_createzone);
ATF_TP_ADD_TC(tp, zonemgr_unreachable);
return (atf_no_error());
} }
/* /*
@ -251,3 +234,31 @@ ATF_TP_ADD_TCS(tp) {
* - dns_zonemgr_setserialqueryrate * - dns_zonemgr_setserialqueryrate
* - dns_zonemgr_getserialqueryrate * - dns_zonemgr_getserialqueryrate
*/ */
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(zonemgr_create,
_setup, _teardown),
cmocka_unit_test_setup_teardown(zonemgr_managezone,
_setup, _teardown),
cmocka_unit_test_setup_teardown(zonemgr_createzone,
_setup, _teardown),
cmocka_unit_test_setup_teardown(zonemgr_unreachable,
_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