BIND 10 rrl, updated. a04bf48f9cbafc3dd1c0790060e99bd0bdb3f4fe [rrl] Add unittests for getFullHash()
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Dec 12 09:49:41 UTC 2013
The branch, rrl has been updated
via a04bf48f9cbafc3dd1c0790060e99bd0bdb3f4fe (commit)
from 9a811320414f0d0e8482660ce46572813fd821b6 (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 a04bf48f9cbafc3dd1c0790060e99bd0bdb3f4fe
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu Dec 12 15:19:15 2013 +0530
[rrl] Add unittests for getFullHash()
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/tests/labelsequence_unittest.cc | 56 +++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/tests/labelsequence_unittest.cc b/src/lib/dns/tests/labelsequence_unittest.cc
index 62cbcec..ce50848 100644
--- a/src/lib/dns/tests/labelsequence_unittest.cc
+++ b/src/lib/dns/tests/labelsequence_unittest.cc
@@ -716,6 +716,62 @@ TEST_F(LabelSequenceTest, getHash) {
hashDistributionCheck(ca_servers);
}
+// A helper function used in the getFullHash test below.
+void
+fullHashDistributionCheck(const char* const* servers, unsigned int seed) {
+ const size_t BUCKETS = 64; // constant used in the MessageRenderer
+ set<Name> names;
+ vector<size_t> hash_counts(BUCKETS);
+
+ // Store all test names and their super domain names (excluding the
+ // "root" label) in the set, calculates their hash values, and increments
+ // the counter for the corresponding hash "bucket".
+ for (size_t i = 0; servers[i] != NULL; ++i) {
+ const Name name(servers[i]);
+ for (size_t l = 0; l < name.getLabelCount() - 1; ++l) {
+ pair<set<Name>::const_iterator, bool> ret =
+ names.insert(name.split(l));
+ if (ret.second) {
+ hash_counts[LabelSequence((*ret.first)).getFullHash(false, seed)
+ % BUCKETS]++;
+ }
+ }
+ }
+
+ // See how many conflicts we have in the buckets. For the testing purpose
+ // we expect there's at most 2 conflicts in each set, which is an
+ // arbitrary choice (it should happen to succeed with the hash function
+ // and data we are using; if it's not the case, maybe with an update to
+ // the hash implementation, we should revise the test).
+ for (size_t i = 0; i < BUCKETS; ++i) {
+ EXPECT_GE(3, hash_counts[i]);
+ }
+}
+
+TEST_F(LabelSequenceTest, getFullHash) {
+ // Trivial case. The same sequence should have the same hash. 42 is
+ // a seed for this test.
+ EXPECT_EQ(ls1.getFullHash(true, 42), ls1.getFullHash(true, 42));
+
+ // Check the case-insensitive mode behavior. 12712 is a seed for
+ // this test.
+ EXPECT_EQ(ls1.getFullHash(false, 12712), ls5.getFullHash(false, 12712));
+
+ // Case-sensitive mismatched seeds test.
+ EXPECT_NE(ls1.getFullHash(true, 42), ls1.getFullHash(true, 41));
+
+ // Case-insensitive mismatched seeds test.
+ EXPECT_NE(ls1.getFullHash(false, 12712), ls5.getFullHash(false, 12711));
+
+ // Check that the distribution of hash values is "not too bad" (such as
+ // everything has the same hash value due to a stupid bug). It's
+ // difficult to check such things reliably. We do some ad hoc tests here.
+ fullHashDistributionCheck(root_servers, 973019);
+ fullHashDistributionCheck(jp_servers, 502212);
+ fullHashDistributionCheck(cn_servers, 778132);
+ fullHashDistributionCheck(ca_servers, 184305);
+}
+
// test operator<<. We simply confirm it appends the result of toText().
TEST_F(LabelSequenceTest, LeftShiftOperator) {
ostringstream oss;
More information about the bind10-changes
mailing list