zonemgr_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011-2013, 2015  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id$ */
00018 
00019 /*! \file */
00020 
00021 #include <config.h>
00022 
00023 #include <atf-c.h>
00024 
00025 #include <unistd.h>
00026 
00027 #include <isc/buffer.h>
00028 #include <isc/task.h>
00029 #include <isc/timer.h>
00030 
00031 #include <dns/name.h>
00032 #include <dns/view.h>
00033 #include <dns/zone.h>
00034 
00035 #include "dnstest.h"
00036 
00037 /*
00038  * Individual unit tests
00039  */
00040 ATF_TC(zonemgr_create);
00041 ATF_TC_HEAD(zonemgr_create, tc) {
00042         atf_tc_set_md_var(tc, "descr", "create zone manager");
00043 }
00044 ATF_TC_BODY(zonemgr_create, tc) {
00045         dns_zonemgr_t *myzonemgr = NULL;
00046         isc_result_t result;
00047 
00048         UNUSED(tc);
00049 
00050         result = dns_test_begin(NULL, ISC_TRUE);
00051         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00052 
00053         result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
00054                                     &myzonemgr);
00055         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00056 
00057         dns_zonemgr_shutdown(myzonemgr);
00058         dns_zonemgr_detach(&myzonemgr);
00059         ATF_REQUIRE_EQ(myzonemgr, NULL);
00060 
00061         dns_test_end();
00062 }
00063 
00064 
00065 ATF_TC(zonemgr_managezone);
00066 ATF_TC_HEAD(zonemgr_managezone, tc) {
00067         atf_tc_set_md_var(tc, "descr", "manage and release a zone");
00068 }
00069 ATF_TC_BODY(zonemgr_managezone, tc) {
00070         dns_zonemgr_t *myzonemgr = NULL;
00071         dns_zone_t *zone = NULL;
00072         isc_result_t result;
00073 
00074         UNUSED(tc);
00075 
00076         result = dns_test_begin(NULL, ISC_TRUE);
00077         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00078 
00079         result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
00080                                     &myzonemgr);
00081         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00082 
00083         result = dns_test_makezone("foo", &zone, NULL, ISC_FALSE);
00084         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00085 
00086         /* This should not succeed until the dns_zonemgr_setsize() is run */
00087         result = dns_zonemgr_managezone(myzonemgr, zone);
00088         ATF_REQUIRE_EQ(result, ISC_R_FAILURE);
00089 
00090         ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
00091 
00092         result = dns_zonemgr_setsize(myzonemgr, 1);
00093         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00094 
00095         /* Now it should succeed */
00096         result = dns_zonemgr_managezone(myzonemgr, zone);
00097         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00098 
00099         ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 1);
00100 
00101         dns_zonemgr_releasezone(myzonemgr, zone);
00102         dns_zone_detach(&zone);
00103 
00104         ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
00105 
00106         dns_zonemgr_shutdown(myzonemgr);
00107         dns_zonemgr_detach(&myzonemgr);
00108         ATF_REQUIRE_EQ(myzonemgr, NULL);
00109 
00110         dns_test_end();
00111 }
00112 
00113 ATF_TC(zonemgr_createzone);
00114 ATF_TC_HEAD(zonemgr_createzone, tc) {
00115         atf_tc_set_md_var(tc, "descr", "create and release a zone");
00116 }
00117 ATF_TC_BODY(zonemgr_createzone, tc) {
00118         dns_zonemgr_t *myzonemgr = NULL;
00119         dns_zone_t *zone = NULL;
00120         isc_result_t result;
00121 
00122         UNUSED(tc);
00123 
00124         result = dns_test_begin(NULL, ISC_TRUE);
00125         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00126 
00127         result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
00128                                     &myzonemgr);
00129         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00130 
00131         /* This should not succeed until the dns_zonemgr_setsize() is run */
00132         result = dns_zonemgr_createzone(myzonemgr, &zone);
00133         ATF_REQUIRE_EQ(result, ISC_R_FAILURE);
00134 
00135         result = dns_zonemgr_setsize(myzonemgr, 1);
00136         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00137 
00138         /* Now it should succeed */
00139         result = dns_zonemgr_createzone(myzonemgr, &zone);
00140         ATF_CHECK_EQ(result, ISC_R_SUCCESS);
00141         ATF_CHECK(zone != NULL);
00142 
00143         if (zone != NULL)
00144                 dns_zone_detach(&zone);
00145 
00146         dns_zonemgr_shutdown(myzonemgr);
00147         dns_zonemgr_detach(&myzonemgr);
00148         ATF_REQUIRE_EQ(myzonemgr, NULL);
00149 
00150         dns_test_end();
00151 }
00152 
00153 ATF_TC(zonemgr_unreachable);
00154 ATF_TC_HEAD(zonemgr_unreachable, tc) {
00155         atf_tc_set_md_var(tc, "descr", "manage and release a zone");
00156 }
00157 ATF_TC_BODY(zonemgr_unreachable, tc) {
00158         dns_zonemgr_t *myzonemgr = NULL;
00159         dns_zone_t *zone = NULL;
00160         isc_sockaddr_t addr1, addr2;
00161         struct in_addr in;
00162         isc_result_t result;
00163         isc_time_t now;
00164 
00165         UNUSED(tc);
00166 
00167         TIME_NOW(&now);
00168 
00169         result = dns_test_begin(NULL, ISC_TRUE);
00170 
00171         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00172 
00173         result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
00174                                     &myzonemgr);
00175         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00176 
00177         result = dns_test_makezone("foo", &zone, NULL, ISC_FALSE);
00178         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00179 
00180         result = dns_zonemgr_setsize(myzonemgr, 1);
00181         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00182 
00183         result = dns_zonemgr_managezone(myzonemgr, zone);
00184         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00185 
00186         in.s_addr = inet_addr("10.53.0.1");
00187         isc_sockaddr_fromin(&addr1, &in, 2112);
00188         in.s_addr = inet_addr("10.53.0.2");
00189         isc_sockaddr_fromin(&addr2, &in, 5150);
00190         ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
00191         /*
00192          * We require multiple unreachableadd calls to mark a server as
00193          * unreachable.
00194          */
00195         dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
00196         ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
00197         dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
00198         ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
00199 
00200         in.s_addr = inet_addr("10.53.0.3");
00201         isc_sockaddr_fromin(&addr2, &in, 5150);
00202         ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
00203         /*
00204          * We require multiple unreachableadd calls to mark a server as
00205          * unreachable.
00206          */
00207         dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
00208         dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
00209         ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
00210 
00211         dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
00212         ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
00213 
00214         in.s_addr = inet_addr("10.53.0.2");
00215         isc_sockaddr_fromin(&addr2, &in, 5150);
00216         ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
00217         dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
00218         ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
00219 
00220         dns_zonemgr_releasezone(myzonemgr, zone);
00221         dns_zone_detach(&zone);
00222         dns_zonemgr_shutdown(myzonemgr);
00223         dns_zonemgr_detach(&myzonemgr);
00224         ATF_REQUIRE_EQ(myzonemgr, NULL);
00225 
00226         dns_test_end();
00227 }
00228 
00229 
00230 /*
00231  * Main
00232  */
00233 ATF_TP_ADD_TCS(tp) {
00234         ATF_TP_ADD_TC(tp, zonemgr_create);
00235         ATF_TP_ADD_TC(tp, zonemgr_managezone);
00236         ATF_TP_ADD_TC(tp, zonemgr_createzone);
00237         ATF_TP_ADD_TC(tp, zonemgr_unreachable);
00238         return (atf_no_error());
00239 }
00240 
00241 /*
00242  * XXX:
00243  * dns_zonemgr API calls that are not yet part of this unit test:
00244  *
00245  *      - dns_zonemgr_attach
00246  *      - dns_zonemgr_forcemaint
00247  *      - dns_zonemgr_resumexfrs
00248  *      - dns_zonemgr_shutdown
00249  *      - dns_zonemgr_setsize
00250  *      - dns_zonemgr_settransfersin
00251  *      - dns_zonemgr_getttransfersin
00252  *      - dns_zonemgr_settransfersperns
00253  *      - dns_zonemgr_getttransfersperns
00254  *      - dns_zonemgr_setiolimit
00255  *      - dns_zonemgr_getiolimit
00256  *      - dns_zonemgr_dbdestroyed
00257  *      - dns_zonemgr_setserialqueryrate
00258  *      - dns_zonemgr_getserialqueryrate
00259  */

Generated on Tue Apr 28 17:41:02 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha