dispatch_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012, 2014  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/socket.h>
00029 #include <isc/task.h>
00030 #include <isc/timer.h>
00031 
00032 #include <dns/dispatch.h>
00033 #include <dns/name.h>
00034 #include <dns/view.h>
00035 
00036 #include "dnstest.h"
00037 
00038 dns_dispatchmgr_t *dispatchmgr = NULL;
00039 dns_dispatchset_t *dset = NULL;
00040 
00041 static isc_result_t
00042 make_dispatchset(unsigned int ndisps) {
00043         isc_result_t result;
00044         isc_sockaddr_t any;
00045         unsigned int attrs;
00046         dns_dispatch_t *disp = NULL;
00047 
00048         result = dns_dispatchmgr_create(mctx, NULL, &dispatchmgr);
00049         if (result != ISC_R_SUCCESS)
00050                 return (result);
00051 
00052         isc_sockaddr_any(&any);
00053         attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP;
00054         result = dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr,
00055                                      &any, 512, 6, 1024, 17, 19, attrs,
00056                                      attrs, &disp);
00057         if (result != ISC_R_SUCCESS)
00058                 return (result);
00059 
00060         result = dns_dispatchset_create(mctx, socketmgr, taskmgr, disp,
00061                                         &dset, ndisps);
00062         dns_dispatch_detach(&disp);
00063 
00064         return (result);
00065 }
00066 
00067 static void
00068 teardown(void) {
00069         if (dset != NULL)
00070                 dns_dispatchset_destroy(&dset);
00071         if (dispatchmgr != NULL)
00072                 dns_dispatchmgr_destroy(&dispatchmgr);
00073 }
00074 
00075 /*
00076  * Individual unit tests
00077  */
00078 ATF_TC(dispatchset_create);
00079 ATF_TC_HEAD(dispatchset_create, tc) {
00080         atf_tc_set_md_var(tc, "descr", "create dispatch set");
00081 }
00082 ATF_TC_BODY(dispatchset_create, tc) {
00083         isc_result_t result;
00084 
00085         UNUSED(tc);
00086 
00087         result = dns_test_begin(NULL, ISC_TRUE);
00088         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00089 
00090         result = make_dispatchset(1);
00091         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00092         teardown();
00093 
00094         result = make_dispatchset(10);
00095         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00096         teardown();
00097 
00098         dns_test_end();
00099 }
00100 
00101 
00102 
00103 ATF_TC(dispatchset_get);
00104 ATF_TC_HEAD(dispatchset_get, tc) {
00105         atf_tc_set_md_var(tc, "descr", "test dispatch set round-robin");
00106 }
00107 ATF_TC_BODY(dispatchset_get, tc) {
00108         isc_result_t result;
00109         dns_dispatch_t *d1, *d2, *d3, *d4, *d5;
00110 
00111         UNUSED(tc);
00112 
00113         result = dns_test_begin(NULL, ISC_TRUE);
00114         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00115 
00116         result = make_dispatchset(1);
00117         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00118 
00119         d1 = dns_dispatchset_get(dset);
00120         d2 = dns_dispatchset_get(dset);
00121         d3 = dns_dispatchset_get(dset);
00122         d4 = dns_dispatchset_get(dset);
00123         d5 = dns_dispatchset_get(dset);
00124 
00125         ATF_CHECK_EQ(d1, d2);
00126         ATF_CHECK_EQ(d2, d3);
00127         ATF_CHECK_EQ(d3, d4);
00128         ATF_CHECK_EQ(d4, d5);
00129 
00130         teardown();
00131 
00132         result = make_dispatchset(4);
00133         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00134 
00135         d1 = dns_dispatchset_get(dset);
00136         d2 = dns_dispatchset_get(dset);
00137         d3 = dns_dispatchset_get(dset);
00138         d4 = dns_dispatchset_get(dset);
00139         d5 = dns_dispatchset_get(dset);
00140 
00141         ATF_CHECK_EQ(d1, d5);
00142         ATF_CHECK(d1 != d2);
00143         ATF_CHECK(d2 != d3);
00144         ATF_CHECK(d3 != d4);
00145         ATF_CHECK(d4 != d5);
00146 
00147         teardown();
00148         dns_test_end();
00149 }
00150 
00151 
00152 /*
00153  * Main
00154  */
00155 ATF_TP_ADD_TCS(tp) {
00156         ATF_TP_ADD_TC(tp, dispatchset_create);
00157         ATF_TP_ADD_TC(tp, dispatchset_get);
00158         return (atf_no_error());
00159 }
00160 

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