rdatasetstats_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012  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 <dns/stats.h>
00028 
00029 #include "dnstest.h"
00030 
00031 /*
00032  * Helper functions
00033  */
00034 static void
00035 set_typestats(dns_stats_t *stats, dns_rdatatype_t type,
00036               isc_boolean_t stale)
00037 {
00038         dns_rdatastatstype_t which;
00039         unsigned int attributes;
00040 
00041         attributes = 0;
00042         if (stale) attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
00043         which = DNS_RDATASTATSTYPE_VALUE(type, attributes);
00044         dns_rdatasetstats_increment(stats, which);
00045 
00046         attributes = DNS_RDATASTATSTYPE_ATTR_NXRRSET;
00047         if (stale) attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
00048         which = DNS_RDATASTATSTYPE_VALUE(type, attributes);
00049         dns_rdatasetstats_increment(stats, which);
00050 }
00051 
00052 static void
00053 set_nxdomainstats(dns_stats_t *stats, isc_boolean_t stale) {
00054         dns_rdatastatstype_t which;
00055         unsigned int attributes;
00056 
00057         attributes = DNS_RDATASTATSTYPE_ATTR_NXDOMAIN;
00058         if (stale) attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
00059         which = DNS_RDATASTATSTYPE_VALUE(0, attributes);
00060         dns_rdatasetstats_increment(stats, which);
00061 }
00062 
00063 static void
00064 checkit1(dns_rdatastatstype_t which, isc_uint64_t value, void *arg) {
00065         unsigned int attributes;
00066 #if debug
00067         unsigned int type;
00068 #endif
00069 
00070         UNUSED(which);
00071         UNUSED(arg);
00072 
00073         attributes = DNS_RDATASTATSTYPE_ATTR(which);
00074 #if debug
00075         type = DNS_RDATASTATSTYPE_BASE(which);
00076 
00077         fprintf(stderr, "%s%s%s%s/%u, %u\n",
00078                 attributes & DNS_RDATASTATSTYPE_ATTR_OTHERTYPE ? "O" : " ",
00079                 attributes & DNS_RDATASTATSTYPE_ATTR_NXRRSET ? "!" : " ",
00080                 attributes & DNS_RDATASTATSTYPE_ATTR_STALE ? "#" : " ",
00081                 attributes & DNS_RDATASTATSTYPE_ATTR_NXDOMAIN ? "X" : " ",
00082                 type, (unsigned)value);
00083 #endif
00084         if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0)
00085                 ATF_REQUIRE_EQ(value, 1);
00086         else
00087                 ATF_REQUIRE_EQ(value, 0);
00088 }
00089 
00090 static void
00091 checkit2(dns_rdatastatstype_t which, isc_uint64_t value, void *arg) {
00092         unsigned int attributes;
00093 #if debug
00094         unsigned int type;
00095 #endif
00096 
00097         UNUSED(which);
00098         UNUSED(arg);
00099 
00100         attributes = DNS_RDATASTATSTYPE_ATTR(which);
00101 #if debug
00102         type = DNS_RDATASTATSTYPE_BASE(which);
00103 
00104         fprintf(stderr, "%s%s%s%s/%u, %u\n",
00105                 attributes & DNS_RDATASTATSTYPE_ATTR_OTHERTYPE ? "O" : " ",
00106                 attributes & DNS_RDATASTATSTYPE_ATTR_NXRRSET ? "!" : " ",
00107                 attributes & DNS_RDATASTATSTYPE_ATTR_STALE ? "#" : " ",
00108                 attributes & DNS_RDATASTATSTYPE_ATTR_NXDOMAIN ? "X" : " ",
00109                 type, (unsigned)value);
00110 #endif
00111         if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0)
00112                 ATF_REQUIRE_EQ(value, 0);
00113         else
00114                 ATF_REQUIRE_EQ(value, 1);
00115 }
00116 /*
00117  * Individual unit tests
00118  */
00119 
00120 ATF_TC(rdatasetstats);
00121 ATF_TC_HEAD(rdatasetstats, tc) {
00122         atf_tc_set_md_var(tc, "descr", "test that rdatasetstats counters are properly set");
00123 }
00124 ATF_TC_BODY(rdatasetstats, tc) {
00125         unsigned int i;
00126         dns_stats_t *stats = NULL;
00127         isc_result_t result;
00128 
00129         UNUSED(tc);
00130 
00131         result = dns_test_begin(NULL, ISC_TRUE);
00132         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00133 
00134         result = dns_rdatasetstats_create(mctx, &stats);
00135         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00136 
00137         /* First 256 types. */
00138         for (i = 0; i <= 255; i++)
00139                 set_typestats(stats, (dns_rdatatype_t)i, ISC_FALSE);
00140         /* Specials */
00141         set_typestats(stats, dns_rdatatype_dlv, ISC_FALSE);
00142         set_typestats(stats, (dns_rdatatype_t)1000, ISC_FALSE);
00143         set_nxdomainstats(stats, ISC_FALSE);
00144 
00145         /*
00146          * Check that all counters are set to appropriately.
00147          */
00148         dns_rdatasetstats_dump(stats, checkit1, NULL, 1);
00149 
00150         /* First 256 types. */
00151         for (i = 0; i <= 255; i++)
00152                 set_typestats(stats, (dns_rdatatype_t)i, ISC_TRUE);
00153         /* Specials */
00154         set_typestats(stats, dns_rdatatype_dlv, ISC_TRUE);
00155         set_typestats(stats, (dns_rdatatype_t)1000, ISC_TRUE);
00156         set_nxdomainstats(stats, ISC_TRUE);
00157 
00158         /*
00159          * Check that all counters are set to appropriately.
00160          */
00161         dns_rdatasetstats_dump(stats, checkit2, NULL, 1);
00162 
00163         dns_stats_detach(&stats);
00164         dns_test_end();
00165 }
00166 
00167 /*
00168  * Main
00169  */
00170 ATF_TP_ADD_TCS(tp) {
00171         ATF_TP_ADD_TC(tp, rdatasetstats);
00172         return (atf_no_error());
00173 }
00174 

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