BIND 10 trac2157_2, updated. 89cc0b54c0de3bac967e2ae8135aad6d654edfe1 [2157] editorial fix: namings and comments
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jan 11 07:06:08 UTC 2013
The branch, trac2157_2 has been updated
via 89cc0b54c0de3bac967e2ae8135aad6d654edfe1 (commit)
via acc630c2e40165f605aad3dde959bc2f3871ea6b (commit)
via c7c532323f9f5f9d98050c0728a87e04800d7144 (commit)
via 7f75e58b7f26fc36c457b74770f8bdc0043a1618 (commit)
via 3d3d75ab559780b95a325c9890364e2c80c480a1 (commit)
via b3804a1036a254bf6ba00bae3182cc0486ddf7ff (commit)
via ba18b3b37595da5364dd82adfb880d3cb5d916d2 (commit)
via bd6e48f80ca1eb587ef1895b1614554865b85fa5 (commit)
via 98fd407e255aadf68b0e1ba7c89b0f65619373ad (commit)
from 644541309f301c6f86495db3982eb5ba69b40529 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 89cc0b54c0de3bac967e2ae8135aad6d654edfe1
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Fri Jan 11 15:31:25 2013 +0900
[2157] editorial fix: namings and comments
commit acc630c2e40165f605aad3dde959bc2f3871ea6b
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Fri Jan 11 14:07:28 2013 +0900
[2157] add some notes to generate_docfile
commit c7c532323f9f5f9d98050c0728a87e04800d7144
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Fri Jan 11 13:56:34 2013 +0900
[2157] check some statistics counters are unaffected
commit 7f75e58b7f26fc36c457b74770f8bdc0043a1618
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Thu Dec 27 19:12:26 2012 +0900
[2157] removed wrong note
commit 3d3d75ab559780b95a325c9890364e2c80c480a1
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Thu Dec 27 19:04:27 2012 +0900
[2157] clarify the description of qrynxrrset
commit b3804a1036a254bf6ba00bae3182cc0486ddf7ff
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Dec 26 20:52:36 2012 +0900
[2157] trivial fix of the arrangement of words
commit ba18b3b37595da5364dd82adfb880d3cb5d916d2
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Dec 26 20:50:55 2012 +0900
[2157] rename test script for gen-statisticsitems.py
commit bd6e48f80ca1eb587ef1895b1614554865b85fa5
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Dec 26 20:45:49 2012 +0900
[2157] rename a method per name convention
commit 98fd407e255aadf68b0e1ba7c89b0f65619373ad
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Wed Dec 26 20:42:41 2012 +0900
[2157] skip test which uses sqlite3 data source for static-link
environments
-----------------------------------------------------------------------
Summary of changes:
src/bin/auth/gen-statisticsitems.py.pre.in | 4 +-
src/bin/auth/statistics.h | 48 ++--
src/bin/auth/statistics_msg_items.def | 2 +-
src/bin/auth/tests/Makefile.am | 5 +-
src/bin/auth/tests/auth_srv_unittest.cc | 301 +++++++++++---------
...tisticsitems.py => gen-statisticsitems_test.py} | 4 +-
src/bin/auth/tests/statistics_unittest.cc.pre | 86 ++----
src/bin/auth/tests/statistics_util.cc | 77 +++++
.../auth/tests/statistics_util.h} | 31 +-
9 files changed, 320 insertions(+), 238 deletions(-)
rename src/bin/auth/tests/{statisticsitems.py => gen-statisticsitems_test.py} (98%)
create mode 100644 src/bin/auth/tests/statistics_util.cc
copy src/{lib/util/unittests/resource.cc => bin/auth/tests/statistics_util.h} (62%)
-----------------------------------------------------------------------
diff --git a/src/bin/auth/gen-statisticsitems.py.pre.in b/src/bin/auth/gen-statisticsitems.py.pre.in
index c637d1e..43f81fd 100755
--- a/src/bin/auth/gen-statisticsitems.py.pre.in
+++ b/src/bin/auth/gen-statisticsitems.py.pre.in
@@ -219,6 +219,7 @@ def generate_docfile(docfile, def_mtime):
if word == xmldocument_command_name:
command = ElementTree.SubElement(sim_para, 'command')
command.text = word
+ # append empty string for trailing text
command.tail = ''
prev = command
else:
@@ -226,8 +227,9 @@ def generate_docfile(docfile, def_mtime):
sim_para.text += word + ' '
else:
prev.tail += word + ' '
+ # remove extra trailing whitespaces
sim_para.text = sim_para.text.rstrip()
- if not prev is None:
+ if prev is not None:
prev.tail = prev.tail.rstrip()
else:
# the item is a branch node: call myself for child nodes
diff --git a/src/bin/auth/statistics.h b/src/bin/auth/statistics.h
index 2b294f2..7a096b1 100644
--- a/src/bin/auth/statistics.h
+++ b/src/bin/auth/statistics.h
@@ -58,12 +58,12 @@ private:
TransportProtocolType req_transport_protocol_; // Transport layer protocol
boost::optional<isc::dns::Opcode> req_opcode_; // OpCode
enum BitAttributes {
- REQ_IS_EDNS_0, // request is EDNS ver.0
- REQ_IS_DNSSEC_OK, // DNSSEC OK (DO) bit is set in request
- REQ_IS_TSIG, // request is signed with valid TSIG
- REQ_IS_BADSIG, // request is signed but bad signature
+ REQ_WITH_EDNS_0, // request with EDNS ver.0
+ REQ_WITH_DNSSEC_OK, // DNSSEC OK (DO) bit is set in request
+ REQ_TSIG_SIGNED, // request is signed with valid TSIG
+ REQ_BADSIG, // request is signed but bad signature
RES_IS_TRUNCATED, // response is truncated
- RES_IS_TSIG_SIGNED, // response is TSIG signed
+ RES_TSIG_SIGNED, // response is signed with TSIG
BIT_ATTRIBUTES_TYPES
};
std::bitset<BIT_ATTRIBUTES_TYPES> bit_attributes_;
@@ -76,7 +76,7 @@ public:
req_transport_protocol_(TRANSPORT_UNSPEC)
{}
- /// \brief Return request opcode.
+ /// \brief Return opcode of the request.
/// \return opcode of the request
/// \throw isc::InvalidOperation Opcode is not set
const isc::dns::Opcode& getRequestOpCode() const {
@@ -87,7 +87,7 @@ public:
}
}
- /// \brief Set request opcode.
+ /// \brief Set opcode of the request.
/// \param opcode Opcode of the request
/// \throw None
void setRequestOpCode(const isc::dns::Opcode& opcode) {
@@ -134,52 +134,52 @@ public:
/// \return true if EDNS version of the request is 0
/// \throw None
bool getRequestEDNS0() const {
- return (bit_attributes_[REQ_IS_EDNS_0]);
+ return (bit_attributes_[REQ_WITH_EDNS_0]);
}
/// \brief Set EDNS attribute of the request.
- /// \param is_edns_0 true if EDNS version of the request is 0
+ /// \param with_edns_0 true if EDNS version of the request is 0
/// \throw None
- void setRequestEDNS0(const bool is_edns_0) {
- bit_attributes_[REQ_IS_EDNS_0] = is_edns_0;
+ void setRequestEDNS0(const bool with_edns_0) {
+ bit_attributes_[REQ_WITH_EDNS_0] = with_edns_0;
}
/// \brief Return DNSSEC OK (DO) bit of the request.
/// \return true if DNSSEC OK (DO) bit of the request is set
/// \throw None
bool getRequestDO() const {
- return (bit_attributes_[REQ_IS_DNSSEC_OK]);
+ return (bit_attributes_[REQ_WITH_DNSSEC_OK]);
}
/// \brief Set DNSSEC OK (DO) bit of the request.
/// \param is_dnssec_ok true if DNSSEC OK (DO) bit of the request is set
/// \throw None
- void setRequestDO(const bool is_dnssec_ok) {
- bit_attributes_[REQ_IS_DNSSEC_OK] = is_dnssec_ok;
+ void setRequestDO(const bool with_dnssec_ok) {
+ bit_attributes_[REQ_WITH_DNSSEC_OK] = with_dnssec_ok;
}
/// \brief Return TSIG attribute of the request.
/// \return true if the request is TSIG signed
/// \throw None
bool getRequestSigTSIG() const {
- return (bit_attributes_[REQ_IS_TSIG]);
+ return (bit_attributes_[REQ_TSIG_SIGNED]);
}
/// \brief Return the status of the signature of the request.
/// \return true if the signature of the request is bad
/// \throw None
bool getRequestSigBadSig() const {
- return (bit_attributes_[REQ_IS_BADSIG]);
+ return (bit_attributes_[REQ_BADSIG]);
}
/// \brief Set TSIG attributes of the request.
/// \param is_tsig true if the request is TSIG signed
/// \param is_badsig true if the signature of the request is bad
/// \throw None
- void setRequestSig(const bool is_tsig, const bool is_badsig) {
- assert(!(!is_tsig && is_badsig));
- bit_attributes_[REQ_IS_TSIG] = is_tsig;
- bit_attributes_[REQ_IS_BADSIG] = is_badsig;
+ void setRequestSig(const bool tsig_signed, const bool badsig) {
+ assert(!(!tsig_signed && badsig));
+ bit_attributes_[REQ_TSIG_SIGNED] = tsig_signed;
+ bit_attributes_[REQ_BADSIG] = badsig;
}
/// \brief Return TC (truncated) bit of the response.
@@ -200,14 +200,14 @@ public:
/// \return true if the response is TSIG signed
/// \throw None
bool getResponseSigTSIG() const {
- return (bit_attributes_[RES_IS_TSIG_SIGNED]);
+ return (bit_attributes_[RES_TSIG_SIGNED]);
}
/// \brief Set TSIG attributes of the response.
/// \param is_tsig_signed true if the response is TSIG signed
/// \throw None
- void setResponseSigTSIG(const bool is_tsig_signed) {
- bit_attributes_[RES_IS_TSIG_SIGNED] = is_tsig_signed;
+ void setResponseSigTSIG(const bool signed_tsig) {
+ bit_attributes_[RES_TSIG_SIGNED] = signed_tsig;
}
};
@@ -269,8 +269,6 @@ public:
/// \param response DNS response message.
/// \param done DNS response was sent to the client.
///
- /// \throw std::bad_alloc Internal resource allocation fails
- ///
void inc(const MessageAttributes& msgattrs,
const isc::dns::Message& response, const bool done);
diff --git a/src/bin/auth/statistics_msg_items.def b/src/bin/auth/statistics_msg_items.def
index 47a1308..d8d3597 100644
--- a/src/bin/auth/statistics_msg_items.def
+++ b/src/bin/auth/statistics_msg_items.def
@@ -29,7 +29,7 @@ qrysuccess MSG_QRYSUCCESS Number of queries received by the b10-auth server re
qryauthans MSG_QRYAUTHANS Number of queries received by the b10-auth server resulted in authoritative answer.
qrynoauthans MSG_QRYNOAUTHANS Number of queries received by the b10-auth server resulted in non-authoritative answer.
qryreferral MSG_QRYREFERRAL Number of queries received by the b10-auth server resulted in referral answer.
-qrynxrrset MSG_QRYNXRRSET Number of queries received by the b10-auth server resulted in NoError but the number of answer RR == 0.
+qrynxrrset MSG_QRYNXRRSET Number of queries received by the b10-auth server resulted in NoError and AA bit is set in the response, but the number of answer RR == 0.
authqryrej MSG_QRYREJECT Number of authoritative queries rejected by the b10-auth server.
rcode msg_counter_rcode Rcode statistics =
noerror MSG_RCODE_NOERROR Number of requests received by the b10-auth server resulted in RCODE = 0 (NoError).
diff --git a/src/bin/auth/tests/Makefile.am b/src/bin/auth/tests/Makefile.am
index f39529d..db97962 100644
--- a/src/bin/auth/tests/Makefile.am
+++ b/src/bin/auth/tests/Makefile.am
@@ -46,6 +46,7 @@ run_unittests_SOURCES += ../command.h ../command.cc
run_unittests_SOURCES += ../common.h ../common.cc
run_unittests_SOURCES += ../statistics.h ../statistics.cc ../statistics_items.h
run_unittests_SOURCES += datasrc_util.h datasrc_util.cc
+run_unittests_SOURCES += statistics_util.h statistics_util.cc
run_unittests_SOURCES += auth_srv_unittest.cc
run_unittests_SOURCES += config_unittest.cc
run_unittests_SOURCES += config_syntax_unittest.cc
@@ -78,11 +79,11 @@ run_unittests_LDADD += $(top_builddir)/src/lib/config/tests/libfake_session.la
run_unittests_LDADD += $(GTEST_LDADD)
run_unittests_LDADD += $(SQLITE_LIBS)
-EXTRA_DIST = statisticsitems.py
+EXTRA_DIST = gen-statisticsitems_test.py
check-local:
B10_FROM_BUILD=${abs_top_builddir} ./run_unittests
- $(PYTHON) $(srcdir)/statisticsitems.py $(top_builddir)/src/bin/auth/b10-auth.xml
+ $(PYTHON) $(srcdir)/gen-statisticsitems_test.py $(top_builddir)/src/bin/auth/b10-auth.xml
noinst_PROGRAMS = run_unittests
diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc
index 487ce6c..405b7b8 100644
--- a/src/bin/auth/tests/auth_srv_unittest.cc
+++ b/src/bin/auth/tests/auth_srv_unittest.cc
@@ -47,6 +47,8 @@
#include <testutils/portconfig.h>
#include <testutils/socket_request.h>
+#include "statistics_util.h"
+
#include <gtest/gtest.h>
#include <boost/lexical_cast.hpp>
@@ -73,6 +75,7 @@ using namespace isc::asiodns;
using namespace isc::asiolink;
using namespace isc::testutils;
using namespace isc::server_common::portconfig;
+using namespace isc::auth::unittest;
using isc::UnitTestUtil;
using boost::scoped_ptr;
using isc::auth::statistics::Counters;
@@ -92,17 +95,6 @@ const char* const STATIC_DSRC_FILE = DSRC_DIR "/static.zone";
const char* const CONFIG_INMEMORY_EXAMPLE =
TEST_DATA_DIR "/rfc5155-example.zone.signed";
-// Check if the item has expected value.
-// Before reading the item, check the item exists.
-void
-expectCounterItem(ConstElementPtr stats,
- const std::string& item, const int expected) {
- ConstElementPtr value(Element::create(0));
- ASSERT_TRUE(stats->find(item, value)) << " Item: " << item;
- value = stats->find(item);
- EXPECT_EQ(expected, value->intValue()) << " Item: " << item;
-}
-
class AuthSrvTest : public SrvTestBase {
protected:
AuthSrvTest() :
@@ -206,31 +198,10 @@ protected:
// Check if the counters exist and are initialized to 0.
void
checkCountersAreInitialized() {
+ std::map<std::string, int> expect;
ConstElementPtr stats = server.getStatistics()->
get("zones")->get("_SERVER_");
- expectCounterItem(stats->get("request"), "v4", 0);
- expectCounterItem(stats->get("request"), "v6", 0);
- expectCounterItem(stats->get("request"), "udp", 0);
- expectCounterItem(stats->get("request"), "tcp", 0);
- expectCounterItem(stats->get("request"), "edns0", 0);
- expectCounterItem(stats->get("request"), "badednsver", 0);
- expectCounterItem(stats->get("request"), "tsig", 0);
- expectCounterItem(stats->get("request"), "sig0", 0);
- expectCounterItem(stats->get("request"), "badsig", 0);
- expectCounterItem(stats->get("request"), "dnssec_ok", 0);
- expectCounterItem(stats->get("opcode"), "query", 0);
- expectCounterItem(stats, "responses", 0);
- expectCounterItem(stats->get("response"), "truncated", 0);
- expectCounterItem(stats->get("response"), "edns0", 0);
- expectCounterItem(stats->get("response"), "tsig", 0);
- expectCounterItem(stats->get("response"), "sig0", 0);
- expectCounterItem(stats->get("rcode"), "refused", 0);
- expectCounterItem(stats, "qrysuccess", 0);
- expectCounterItem(stats, "qryauthans", 0);
- expectCounterItem(stats, "qrynoauthans", 0);
- expectCounterItem(stats, "qryreferral", 0);
- expectCounterItem(stats, "qrynxrrset", 0);
- expectCounterItem(stats, "authqryrej", 0);
+ checkStatisticsCounters(stats, expect);
}
MockDNSService dnss_;
@@ -290,9 +261,15 @@ TEST_F(AuthSrvTest, noClientList) {
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after->get("opcode"), "query", 1);
- expectCounterItem(stats_after, "responses", 1);
- expectCounterItem(stats_after->get("rcode"), "refused", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.udp"] = 1;
+ expect["opcode.query"] = 1;
+ expect["responses"] = 1;
+ expect["qrynoauthans"] = 1;
+ expect["authqryrej"] = 1;
+ expect["rcode.refused"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
// Unsupported requests. Should result in NOTIMP.
@@ -313,10 +290,13 @@ TEST_F(AuthSrvTest, multiQuestion) {
TEST_F(AuthSrvTest, shortMessage) {
shortMessage();
- checkAllRcodeCountersZero();
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after, "responses", 0);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.udp"] = 1;
+ expect["opcode.other"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
// Response messages. Must be silently dropped, whether it's a valid response
@@ -324,10 +304,13 @@ TEST_F(AuthSrvTest, shortMessage) {
TEST_F(AuthSrvTest, response) {
response();
- checkAllRcodeCountersZero();
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after, "responses", 0);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 3;
+ expect["request.udp"] = 3;
+ expect["opcode.other"] = 3;
+ checkStatisticsCounters(stats_after, expect);
}
// Query with a broken question
@@ -346,11 +329,16 @@ TEST_F(AuthSrvTest, shortAnswer) {
TEST_F(AuthSrvTest, ednsBadVers) {
ednsBadVers();
- checkAllRcodeCountersZeroExcept(Rcode::BADVERS(), 1);
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after, "responses", 1);
- expectCounterItem(stats_after->get("request"), "badednsver", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.badednsver"] = 1;
+ expect["request.udp"] = 1;
+ expect["opcode.other"] = 1;
+ expect["responses"] = 1;
+ expect["rcode.badvers"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
TEST_F(AuthSrvTest, AXFROverUDP) {
@@ -370,12 +358,13 @@ TEST_F(AuthSrvTest, AXFRSuccess) {
EXPECT_FALSE(dnsserv.hasAnswer());
EXPECT_TRUE(xfrout.isConnected());
- checkAllRcodeCountersZero();
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after->get("opcode"), "query", 1);
- expectCounterItem(stats_after, "responses", 0);
- expectCounterItem(stats_after->get("response"), "truncated", 0);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.tcp"] = 1;
+ expect["opcode.query"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
// Give the server a signed request, but don't give it the key. It will
@@ -413,10 +402,15 @@ TEST_F(AuthSrvTest, TSIGSignedBadKey) {
checkAllRcodeCountersZeroExcept(Rcode::NOTAUTH(), 1);
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after->get("request"), "tsig", 1);
- expectCounterItem(stats_after->get("request"), "badsig", 1);
- expectCounterItem(stats_after, "responses", 1);
- expectCounterItem(stats_after->get("response"), "tsig", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.tsig"] = 1;
+ expect["request.badsig"] = 1;
+ expect["request.udp"] = 1;
+ expect["responses"] = 1;
+ expect["response.tsig"] = 1;
+ expect["rcode.notauth"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
// Give the server a signed request, but signed by a different key
@@ -451,13 +445,17 @@ TEST_F(AuthSrvTest, TSIGBadSig) {
EXPECT_EQ(0, tsig->getRdata().getMACSize()) <<
"It should be unsigned with this error";
- checkAllRcodeCountersZeroExcept(Rcode::NOTAUTH(), 1);
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after->get("request"), "tsig", 1);
- expectCounterItem(stats_after->get("request"), "badsig", 1);
- expectCounterItem(stats_after, "responses", 1);
- expectCounterItem(stats_after->get("response"), "tsig", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.tsig"] = 1;
+ expect["request.badsig"] = 1;
+ expect["request.udp"] = 1;
+ expect["responses"] = 1;
+ expect["response.tsig"] = 1;
+ expect["rcode.notauth"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
// Give the server a signed unsupported request with a bad signature.
@@ -497,14 +495,15 @@ TEST_F(AuthSrvTest, TSIGCheckFirst) {
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after->get("request"), "tsig", 1);
- expectCounterItem(stats_after->get("request"), "badsig", 1);
- expectCounterItem(stats_after, "responses", 1);
- expectCounterItem(stats_after->get("response"), "tsig", 1);
- // TSIG should have failed, and so the per opcode counter shouldn't be
- // incremented.
- expectCounterItem(stats_after->get("opcode"), "other", 0);
- checkAllRcodeCountersZeroExcept(Rcode::NOTAUTH(), 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.tsig"] = 1;
+ expect["request.badsig"] = 1;
+ expect["request.udp"] = 1;
+ expect["responses"] = 1;
+ expect["response.tsig"] = 1;
+ expect["rcode.notauth"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
TEST_F(AuthSrvTest, AXFRConnectFail) {
@@ -661,11 +660,15 @@ TEST_F(AuthSrvTest, notify) {
EXPECT_EQ(RRClass::IN(), question->getClass());
EXPECT_EQ(RRType::SOA(), question->getType());
- checkAllRcodeCountersZeroExcept(Rcode::NOERROR(), 1);
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after->get("opcode"), "notify", 1);
- expectCounterItem(stats_after, "responses", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.udp"] = 1;
+ expect["opcode.notify"] = 1;
+ expect["responses"] = 1;
+ expect["rcode.noerror"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
TEST_F(AuthSrvTest, notifyForCHClass) {
@@ -685,11 +688,15 @@ TEST_F(AuthSrvTest, notifyForCHClass) {
notify_session.getSentMessage()->get("command")->get(1);
EXPECT_EQ("CH", notify_args->get("zone_class")->stringValue());
- checkAllRcodeCountersZeroExcept(Rcode::NOERROR(), 1);
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after->get("opcode"), "notify", 1);
- expectCounterItem(stats_after, "responses", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.udp"] = 1;
+ expect["opcode.notify"] = 1;
+ expect["responses"] = 1;
+ expect["rcode.noerror"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
TEST_F(AuthSrvTest, notifyEmptyQuestion) {
@@ -708,9 +715,13 @@ TEST_F(AuthSrvTest, notifyEmptyQuestion) {
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after->get("opcode"), "notify", 1);
- expectCounterItem(stats_after, "responses", 1);
- expectCounterItem(stats_after->get("rcode"), "formerr", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.udp"] = 1;
+ expect["opcode.notify"] = 1;
+ expect["responses"] = 1;
+ expect["rcode.formerr"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
TEST_F(AuthSrvTest, notifyMultiQuestions) {
@@ -918,12 +929,17 @@ TEST_F(AuthSrvTest, TSIGSigned) {
checkAllRcodeCountersZeroExcept(Rcode::NOERROR(), 1);
ConstElementPtr stats_after = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats_after->get("request"), "tsig", 1);
- expectCounterItem(stats_after->get("request"), "sig0", 0);
- expectCounterItem(stats_after->get("request"), "badsig", 0);
- expectCounterItem(stats_after, "responses", 1);
- expectCounterItem(stats_after, "qryauthans", 1);
- expectCounterItem(stats_after->get("response"), "tsig", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.tsig"] = 1;
+ expect["request.udp"] = 1;
+ expect["opcode.query"] = 1;
+ expect["responses"] = 1;
+ expect["response.tsig"] = 1;
+ expect["qrysuccess"] = 1;
+ expect["qryauthans"] = 1;
+ expect["rcode.noerror"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
// Same test emulating the UDPServer class behavior (defined in libasiolink).
@@ -1049,7 +1065,14 @@ TEST_F(AuthSrvTest, datasourceFail) {
checkAllRcodeCountersZeroExcept(Rcode::SERVFAIL(), 1);
ConstElementPtr stats = server.getStatistics()->get("zones")->
get("_SERVER_");
- expectCounterItem(stats, "responses", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.udp"] = 1;
+ expect["opcode.query"] = 1;
+ expect["responses"] = 1;
+ expect["qrynoauthans"] = 1;
+ expect["rcode.servfail"] = 1;
+ checkStatisticsCounters(stats, expect);
}
#ifdef USE_STATIC_LINK
@@ -1158,17 +1181,14 @@ TEST_F(AuthSrvTest,
opcode.getCode(), QR_FLAG | AA_FLAG, 1, 1, 1, 0);
}
+#ifdef USE_STATIC_LINK
+TEST_F(AuthSrvTest, DISABLED_queryCounterTruncTest) {
+#else
TEST_F(AuthSrvTest, queryCounterTruncTest) {
+#endif
// use CONFIG_TESTDB for large-rdata.example.com.
updateDatabase(&server, CONFIG_TESTDB);
- // The counters should be initialized to 0.
- ConstElementPtr stats_init = server.getStatistics()->
- get("zones")->get("_SERVER_");
- expectCounterItem(stats_init, "responses", 0);
- expectCounterItem(stats_init, "qryauthans", 0);
- expectCounterItem(stats_init->get("response"), "truncated", 0);
-
// Create UDP message and process.
// large-rdata.example.com. TXT; expect it exceeds 512 octet
UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(),
@@ -1181,10 +1201,16 @@ TEST_F(AuthSrvTest, queryCounterTruncTest) {
ConstElementPtr stats_after = server.getStatistics()->
get("zones")->get("_SERVER_");
- expectCounterItem(stats_after, "responses", 1);
- expectCounterItem(stats_after, "qryauthans", 1);
- expectCounterItem(stats_after->get("rcode"), "noerror", 1);
- expectCounterItem(stats_after->get("response"), "truncated", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.udp"] = 1;
+ expect["opcode.query"] = 1;
+ expect["responses"] = 1;
+ expect["response.truncated"] = 1;
+ expect["qrysuccess"] = 1;
+ expect["qryauthans"] = 1;
+ expect["rcode.noerror"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
// Submit UDP normal query and check query counter
TEST_F(AuthSrvTest, queryCounterUDPNormal) {
@@ -1198,29 +1224,15 @@ TEST_F(AuthSrvTest, queryCounterUDPNormal) {
ConstElementPtr stats_after = server.getStatistics()->
get("zones")->get("_SERVER_");
- expectCounterItem(stats_after->get("request"), "v4", 1);
- expectCounterItem(stats_after->get("request"), "v6", 0);
- expectCounterItem(stats_after->get("request"), "udp", 1);
- expectCounterItem(stats_after->get("request"), "tcp", 0);
- expectCounterItem(stats_after->get("request"), "edns0", 0);
- expectCounterItem(stats_after->get("request"), "badednsver", 0);
- expectCounterItem(stats_after->get("request"), "tsig", 0);
- expectCounterItem(stats_after->get("request"), "sig0", 0);
- expectCounterItem(stats_after->get("request"), "badsig", 0);
- expectCounterItem(stats_after->get("request"), "dnssec_ok", 0);
- expectCounterItem(stats_after->get("opcode"), "query", 1);
- expectCounterItem(stats_after, "responses", 1);
- expectCounterItem(stats_after->get("response"), "truncated", 0);
- expectCounterItem(stats_after->get("response"), "edns0", 0);
- expectCounterItem(stats_after->get("response"), "tsig", 0);
- expectCounterItem(stats_after->get("response"), "sig0", 0);
- expectCounterItem(stats_after->get("rcode"), "refused", 1);
- expectCounterItem(stats_after, "qrysuccess", 0);
- expectCounterItem(stats_after, "qryauthans", 0);
- expectCounterItem(stats_after, "qrynoauthans", 1);
- expectCounterItem(stats_after, "qryreferral", 0);
- expectCounterItem(stats_after, "qrynxrrset", 0);
- expectCounterItem(stats_after, "authqryrej", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.udp"] = 1;
+ expect["opcode.query"] = 1;
+ expect["responses"] = 1;
+ expect["qrynoauthans"] = 1;
+ expect["authqryrej"] = 1;
+ expect["rcode.refused"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
// Submit UDP normal query with DNSSEC and check query counter
@@ -1235,11 +1247,20 @@ TEST_F(AuthSrvTest, queryCounterUDPNormalWithDNSSEC) {
ConstElementPtr stats_after = server.getStatistics()->
get("zones")->get("_SERVER_");
- expectCounterItem(stats_after->get("request"), "edns0", 1);
- expectCounterItem(stats_after->get("request"), "dnssec_ok", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.edns0"] = 1;
+ expect["request.udp"] = 1;
+ expect["request.dnssec_ok"] = 1;
+ expect["opcode.query"] = 1;
+ expect["responses"] = 1;
+ expect["qrynoauthans"] = 1;
+ expect["authqryrej"] = 1;
+ expect["rcode.refused"] = 1;
// XXX: with the current implementation, EDNS0 is omitted in
// makeErrorMessage.
- expectCounterItem(stats_after->get("response"), "edns0", 0);
+ expect["response.edns0"] = 0;
+ checkStatisticsCounters(stats_after, expect);
}
// Submit TCP normal query and check query counter
@@ -1254,8 +1275,15 @@ TEST_F(AuthSrvTest, queryCounterTCPNormal) {
ConstElementPtr stats_after = server.getStatistics()->
get("zones")->get("_SERVER_");
- expectCounterItem(stats_after->get("request"), "udp", 0);
- expectCounterItem(stats_after->get("request"), "tcp", 1);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.tcp"] = 1;
+ expect["opcode.query"] = 1;
+ expect["responses"] = 1;
+ expect["qrynoauthans"] = 1;
+ expect["authqryrej"] = 1;
+ expect["rcode.refused"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
// Submit TCP AXFR query and check query counter
@@ -1271,9 +1299,11 @@ TEST_F(AuthSrvTest, queryCounterTCPAXFR) {
ConstElementPtr stats_after = server.getStatistics()->
get("zones")->get("_SERVER_");
- expectCounterItem(stats_after->get("opcode"), "query", 1);
- expectCounterItem(stats_after, "responses", 0);
- expectCounterItem(stats_after->get("response"), "truncated", 0);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.tcp"] = 1;
+ expect["opcode.query"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
// Submit TCP IXFR query and check query counter
@@ -1289,9 +1319,11 @@ TEST_F(AuthSrvTest, queryCounterTCPIXFR) {
ConstElementPtr stats_after = server.getStatistics()->
get("zones")->get("_SERVER_");
- expectCounterItem(stats_after->get("opcode"), "query", 1);
- expectCounterItem(stats_after, "responses", 0);
- expectCounterItem(stats_after->get("response"), "truncated", 0);
+ std::map<std::string, int> expect;
+ expect["request.v4"] = 1;
+ expect["request.tcp"] = 1;
+ expect["opcode.query"] = 1;
+ checkStatisticsCounters(stats_after, expect);
}
TEST_F(AuthSrvTest, queryCounterOpcodes) {
@@ -1300,7 +1332,8 @@ TEST_F(AuthSrvTest, queryCounterOpcodes) {
std::string item_name;
int expected;
if (isc::auth::statistics::opcode_to_msgcounter[i] ==
- isc::auth::statistics::MSG_OPCODE_OTHER) {
+ isc::auth::statistics::MSG_OPCODE_OTHER)
+ {
item_name = "OTHER";
other_expected += i + 1;
expected = other_expected;
@@ -1312,9 +1345,9 @@ TEST_F(AuthSrvTest, queryCounterOpcodes) {
::tolower);
// The counter should be initialized to expected value.
- expectCounterItem(server.getStatistics()->
- get("zones")->get("_SERVER_")->get("opcode"),
- item_name, expected - (i + 1));
+ EXPECT_EQ(server.getStatistics()->get("zones")->get("_SERVER_")->
+ get("opcode")->get(item_name)->intValue(),
+ expected - (i + 1));
// For each possible opcode, create a request message and send it
UnitTestUtil::createRequestMessage(request_message, Opcode(i),
@@ -1332,9 +1365,11 @@ TEST_F(AuthSrvTest, queryCounterOpcodes) {
}
// Confirm the counter.
- expectCounterItem(server.getStatistics()->
- get("zones")->get("_SERVER_")->get("opcode"),
- item_name, expected);
+ // This test only checks for opcodes; some part of the other items
+ // depends on the opcode.
+ EXPECT_EQ(server.getStatistics()->get("zones")->get("_SERVER_")->
+ get("opcode")->get(item_name)->intValue(),
+ expected);
}
}
diff --git a/src/bin/auth/tests/gen-statisticsitems_test.py b/src/bin/auth/tests/gen-statisticsitems_test.py
new file mode 100644
index 0000000..26587db
--- /dev/null
+++ b/src/bin/auth/tests/gen-statisticsitems_test.py
@@ -0,0 +1,91 @@
+# Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+"""\
+This script checks output of gen-statisticsitems.py.
+
+This script checks XML file. Spec file, C++ code and header files syntax is
+checked in the other unittests or system tests.
+"""
+
+import os
+import sys
+from xml.etree import ElementTree
+
+"""\
+User-defined exception for parse error. It is thrown if a file is not
+formatted as expected.
+"""
+class ParseError(Exception):
+ pass
+
+"""\
+Test XML file.
+
+It should have <refsect1> which has <title>STATISTICS DATA</title>.
+Inside the section, it should have one or more <varlistentry> of each item
+inside <variablelist>.
+Each <varlistentry> should have <term> for item name and <simpara> inside
+<listitem> for item description.
+
+Example:
+ <refsect1>
+ <title>STATISTICS DATA</title>
+ <variablelist>
+ <varlistentry>
+ <term>item1</term>
+ <listitem>
+ <simpara>
+ statistics item
+ </simpara>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>item2</term>
+ <listitem>
+ <simpara>
+ another statistics item
+ </simpara>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+"""
+def test_xml_file(xmlfilepath):
+ xmltree = ElementTree.parse(xmlfilepath)
+ root = xmltree.getroot()
+ # find <refsect1> which has <title> of 'STATISTICS DATA'
+ stats_node = [t for t in root.findall('./refsect1')
+ if t.find('./title').text == 'STATISTICS DATA']
+ if not stats_node:
+ raise ParseError('Statistics data section does not exist')
+ # find all <varlistentry> inside <variablelist>
+ entries = stats_node[0].find('./variablelist').findall('./varlistentry')
+ if not entries:
+ raise ParseError('<varlistentry> does not exist inside section')
+ for entry in entries:
+ # find <term> for item name
+ name = entry.find('./term')
+ if name is None or name.text == '':
+ raise ParseError('<term> for item name does not exist')
+ # find <simpara> inside <listitem> for item description
+ description = entry.find('./listitem/simpara')
+ if description is None or description.text == '':
+ raise ParseError('<listitem> nor <simpara> for item description'
+ ' does not exist')
+ return
+
+if __name__ == "__main__":
+ xmlfilepath = sys.argv[1]
+ test_xml_file(xmlfilepath)
diff --git a/src/bin/auth/tests/statistics_unittest.cc.pre b/src/bin/auth/tests/statistics_unittest.cc.pre
index ac37de1..86a7180 100644
--- a/src/bin/auth/tests/statistics_unittest.cc.pre
+++ b/src/bin/auth/tests/statistics_unittest.cc.pre
@@ -29,8 +29,7 @@
#include <dns/tests/unittest_util.h>
-#include <string>
-#include <map>
+#include "statistics_util.h"
#include <unistd.h>
#include <sys/types.h>
@@ -42,6 +41,7 @@ using namespace std;
using namespace isc::dns;
using namespace isc::data;
using namespace isc::auth::statistics;
+using namespace isc::auth::unittest;
namespace {
@@ -54,52 +54,6 @@ protected:
Counters counters;
};
-// flatten counters
-void
-flatten(std::map<std::string, int>& flat_map, const std::string& prefix,
- const isc::data::ConstElementPtr map_element) {
- std::map<std::string, ConstElementPtr> map = map_element->mapValue();
- for (std::map<std::string, ConstElementPtr>::const_iterator
- i = map.begin(), e = map.end();
- i != e;
- ++i)
- {
- switch (i->second->getType()) {
- case isc::data::Element::map:
- flatten(flat_map, i->first + ".", i->second);
- break;
- case isc::data::Element::integer:
- flat_map[prefix + i->first] = i->second->intValue();
- break;
- default:
- FAIL() << "Element Parse Error";
- }
- }
-}
-
-// Test if the counters has expected values specified in expect and the others
-// are zero.
-void
-checkCounters(const isc::data::ConstElementPtr counters,
- const std::map<std::string, int>& expect)
-{
- std::map<std::string, int> stats_map;
- flatten(stats_map, "", counters);
-
- for (std::map<std::string, int>::const_iterator
- i = stats_map.begin(), e = stats_map.end();
- i != e;
- ++i)
- {
- const int value =
- expect.find(i->first) == expect.end() ?
- 0 : expect.find(i->first)->second;
- EXPECT_EQ(value, i->second) << "Expected counter "
- << i->first << " = " << value << ", actual: "
- << i->second;
- }
-}
-
void
buildSkeletonMessage(MessageAttributes& msgattrs) {
msgattrs.setRequestIPVersion(MessageAttributes::IP_VERSION_IPV4);
@@ -164,7 +118,8 @@ TEST_F(CountersTest, incrementResponse) {
expect["qrynoauthans"] = responded ? 1 : 0;
expect["rcode.refused"] = responded ? 1 : 0;
expect["authqryrej"] = responded ? 1 : 0;
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
}
@@ -226,7 +181,8 @@ TEST_F(CountersTest, incrementProtocolType) {
expect["qrynoauthans"] = i+1;
expect["rcode.refused"] = i+1;
expect["authqryrej"] = i+1;
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
}
@@ -263,7 +219,8 @@ TEST_F(CountersTest, incrementDO) {
expect["qrynoauthans"] = i+1;
expect["rcode.refused"] = i+1;
expect["authqryrej"] = i+1;
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
}
@@ -316,7 +273,8 @@ TEST_F(CountersTest, incrementEDNS) {
expect["qrynoauthans"] = i+1;
expect["rcode.refused"] = i+1;
expect["authqryrej"] = i+1;
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
}
@@ -375,7 +333,8 @@ TEST_F(CountersTest, incrementTSIG) {
expect["qrynoauthans"] = i+1 - count_badsig;
expect["rcode.refused"] = i+1 - count_badsig;
expect["authqryrej"] = i+1 - count_badsig;
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
}
@@ -430,7 +389,8 @@ TEST_F(CountersTest, incrementOpcode) {
expect["opcode."+code_text] = j;
}
}
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
}
@@ -489,7 +449,8 @@ TEST_F(CountersTest, incrementRcode) {
expect["rcode."+code_text] = j;
}
}
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
}
@@ -531,7 +492,8 @@ TEST_F(CountersTest, incrementTruncated) {
expect["responses"] = i+1;
expect["rcode.servfail"] = i+1;
expect["response.truncated"] = count_truncated;
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
}
@@ -575,7 +537,8 @@ TEST_F(CountersTest, incrementQryAuthAnsAndNoAuthAns) {
expect["rcode.servfail"] = i+1;
expect["qryauthans"] = count_authans;
expect["qrynoauthans"] = count_noauthans;
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
}
@@ -617,7 +580,8 @@ TEST_F(CountersTest, incrementQrySuccess) {
expect["qrysuccess"] = 1;
// noauthans is also incremented
expect["qrynoauthans"] = 1;
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
TEST_F(CountersTest, incrementQryReferralAndNxrrset) {
@@ -667,7 +631,8 @@ TEST_F(CountersTest, incrementQryReferralAndNxrrset) {
// qryauthans or qrynoauthans is also incremented
expect["qryauthans"] = count_nxrrset;
expect["qrynoauthans"] = count_referral;
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
}
@@ -702,7 +667,8 @@ TEST_F(CountersTest, incrementAuthQryRej) {
expect["authqryrej"] = 1;
// noauthans is also incremented since AA bit is not set
expect["qrynoauthans"] = 1;
- checkCounters(counters.get()->get("zones")->get("_SERVER_"), expect);
+ checkStatisticsCounters(counters.get()->get("zones")->get("_SERVER_"),
+ expect);
}
int
diff --git a/src/bin/auth/tests/statistics_util.cc b/src/bin/auth/tests/statistics_util.cc
new file mode 100644
index 0000000..8aca25a
--- /dev/null
+++ b/src/bin/auth/tests/statistics_util.cc
@@ -0,0 +1,77 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include "statistics_util.h"
+
+#include <gtest/gtest.h>
+
+#include <string>
+#include <map>
+
+namespace {
+void
+flatten(std::map<std::string, int>& flat_map, const std::string& prefix,
+ const isc::data::ConstElementPtr map_element)
+{
+ std::map<std::string, isc::data::ConstElementPtr> map =
+ map_element->mapValue();
+ for (std::map<std::string, isc::data::ConstElementPtr>::const_iterator
+ i = map.begin(), e = map.end();
+ i != e;
+ ++i)
+ {
+ switch (i->second->getType()) {
+ case isc::data::Element::map:
+ flatten(flat_map, i->first + ".", i->second);
+ break;
+ case isc::data::Element::integer:
+ flat_map[prefix + i->first] = i->second->intValue();
+ break;
+ default:
+ FAIL() << "Element Parse Error";
+ }
+ }
+}
+}
+
+namespace isc {
+namespace auth {
+namespace unittest {
+
+// Test if the counters has expected values specified in expect and the others
+// are zero.
+void
+checkStatisticsCounters(const isc::data::ConstElementPtr counters,
+ const std::map<std::string, int>& expect)
+{
+ std::map<std::string, int> stats_map;
+ flatten(stats_map, "", counters);
+
+ for (std::map<std::string, int>::const_iterator
+ i = stats_map.begin(), e = stats_map.end();
+ i != e;
+ ++i)
+ {
+ const int value =
+ expect.find(i->first) == expect.end() ?
+ 0 : expect.find(i->first)->second;
+ EXPECT_EQ(value, i->second) << "Expected counter "
+ << i->first << " = " << value << ", actual: "
+ << i->second;
+ }
+}
+
+} // end of unittest
+} // end of auth
+} // end of isc
diff --git a/src/bin/auth/tests/statistics_util.h b/src/bin/auth/tests/statistics_util.h
new file mode 100644
index 0000000..b01a016
--- /dev/null
+++ b/src/bin/auth/tests/statistics_util.h
@@ -0,0 +1,38 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef __AUTH_STATISTICS_UTIL_H
+#define __AUTH_STATISTICS_UTIL_H 1
+
+#include <cc/data.h>
+
+namespace isc {
+namespace auth {
+namespace unittest {
+
+// Test if the counters has expected values specified in expect and the others
+// are zero.
+void
+checkStatisticsCounters(const isc::data::ConstElementPtr counters,
+ const std::map<std::string, int>& expect);
+
+} // end of unittest
+} // end of auth
+} // end of isc
+
+#endif // __AUTH_STATISTICS_UTIL_H
+
+// Local Variables:
+// mode: c++
+// End:
diff --git a/src/bin/auth/tests/statisticsitems.py b/src/bin/auth/tests/statisticsitems.py
deleted file mode 100644
index f6147d3..0000000
--- a/src/bin/auth/tests/statisticsitems.py
+++ /dev/null
@@ -1,91 +0,0 @@
-# Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-#
-# Permission to use, copy, modify, and/or distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-# PERFORMANCE OF THIS SOFTWARE.
-
-"""\
-This script checks output of gen-statisticsitems.py.
-
-This script checks XML file. Spec file, C++ code and header files syntax is
-checked in the other unittests or system tests.
-"""
-
-import os
-import sys
-from xml.etree import ElementTree
-
-"""\
-User-defined exception for parse error. It is thrown if a file is not
-formatted as expected.
-"""
-class ParseError(Exception):
- pass
-
-"""\
-Test XML file.
-
-It should have <refsect1> which has <title>STATISTICS DATA</title>.
-Inside the section, it should have one or more <varlistentry> of each item
-inside <variablelist>.
-Each <varlistentry> should have <term> for item name and <simpara> inside
-<listitem> for item description.
-
-Example:
- <refsect1>
- <title>STATISTICS DATA</title>
- <variablelist>
- <varlistentry>
- <term>item1</term>
- <listitem>
- <simpara>
- statistics item
- </simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>item2</term>
- <listitem>
- <simpara>
- another statistics item
- </simpara>
- </listitem>
- </varlistentry>
- </variablelist>
- </refsect1>
-"""
-def testXMLfile(xmlfilepath):
- xmltree = ElementTree.parse(xmlfilepath)
- root = xmltree.getroot()
- # find <refsect1> which has <title> of 'STATISTICS DATA'
- stats_node = [t for t in root.findall('./refsect1')
- if t.find('./title').text == 'STATISTICS DATA']
- if not stats_node:
- raise ParseError('Statistics data section does not exist')
- # find all <varlistentry> inside <variablelist>
- entries = stats_node[0].find('./variablelist').findall('./varlistentry')
- if not entries:
- raise ParseError('<varlistentry> does not exist inside section')
- for entry in entries:
- # find <term> for item name
- name = entry.find('./term')
- if name is None or name.text == '':
- raise ParseError('<term> for item name does not exist')
- # find <simpara> inside <listitem> for item description
- description = entry.find('./listitem/simpara')
- if description is None or description.text == '':
- raise ParseError('<listitem> nor <simpara> for item description'
- ' does not exist')
- return
-
-if __name__ == "__main__":
- xmlfilepath = sys.argv[1]
- testXMLfile(xmlfilepath)
More information about the bind10-changes
mailing list