BIND 10 trac2811, updated. bb9ff965b73e08cc800083546b46a5b5ede22a41 [2811] Add test with names inserted in sorted order

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Feb 25 17:05:53 UTC 2013


The branch, trac2811 has been updated
       via  bb9ff965b73e08cc800083546b46a5b5ede22a41 (commit)
      from  a7161e686461f435a1e21b4918d1ad6bc45844c3 (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 bb9ff965b73e08cc800083546b46a5b5ede22a41
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Feb 25 22:35:38 2013 +0530

    [2811] Add test with names inserted in sorted order

-----------------------------------------------------------------------

Summary of changes:
 .../datasrc/tests/memory/domaintree_unittest.cc    |   46 +++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/tests/memory/domaintree_unittest.cc b/src/lib/datasrc/tests/memory/domaintree_unittest.cc
index ae329dd..48ac111 100644
--- a/src/lib/datasrc/tests/memory/domaintree_unittest.cc
+++ b/src/lib/datasrc/tests/memory/domaintree_unittest.cc
@@ -29,6 +29,8 @@
 
 #include <dns/tests/unittest_util.h>
 
+#include <boost/format.hpp>
+
 using namespace std;
 using namespace isc;
 using namespace isc::dns;
@@ -148,12 +150,14 @@ TEST_F(DomainTreeTest, getDistance) {
     }
 }
 
-TEST_F(DomainTreeTest, checkDistance) {
+TEST_F(DomainTreeTest, checkDistanceRandom) {
     // This test checks an important performance-related property of the
     // DomainTree (a red-black tree), which is important for us: the
     // longest path from a sub-tree's root to a node is no more than
     // 2log(n). This tests that the tree is balanced.
 
+    // Names are inserted in random order.
+
     TreeHolder mytree_holder(mem_sgmt_, TestDomainTree::create(mem_sgmt_));
     TestDomainTree& mytree = *mytree_holder.get();
     isc::util::random::UniformRandomIntegerGenerator gen('a', 'z');
@@ -200,6 +204,46 @@ TEST_F(DomainTreeTest, checkDistance) {
     }
 }
 
+TEST_F(DomainTreeTest, checkDistanceSorted) {
+    // This test checks an important performance-related property of the
+    // DomainTree (a red-black tree), which is important for us: the
+    // longest path from a sub-tree's root to a node is no more than
+    // 2log(n). This tests that the tree is balanced.
+
+    // Names are inserted in sorted order.
+
+    TreeHolder mytree_holder(mem_sgmt_, TestDomainTree::create(mem_sgmt_));
+    TestDomainTree& mytree = *mytree_holder.get();
+    const size_t log_num_nodes = 20;
+
+    // Make a large million+ node top-level domain tree, i.e., the
+    // following code inserts names such as:
+    //
+    //   name000000.
+    //   name000001.
+    //   name000002.
+    //   name000003.
+    //
+    for (int i = 0; i < (1 << log_num_nodes); i++) {
+        const string namestr(boost::str(boost::format("name%06x.") % i));
+        mytree.insert(mem_sgmt_, Name(namestr), &dtnode);
+        EXPECT_EQ(static_cast<int*>(NULL), dtnode->setData(new int(i + 1)));
+    }
+
+    TestDomainTreeNodeChain node_path;
+    const TestDomainTreeNode* node = NULL;
+
+    // Try to find a node left of the left-most node, and start from its
+    // next node (which is the left-most node in its subtree).
+    EXPECT_EQ(TestDomainTree::NOTFOUND,
+              mytree.find<void*>(Name("0"), &node, node_path, NULL, NULL));
+    while ((node = mytree.nextNode(node_path)) != NULL) {
+        // The distance from each node to its sub-tree root must be less
+        // than 2 * log(n).
+        EXPECT_GE(2 * log_num_nodes, node->getDistance());
+    }
+}
+
 TEST_F(DomainTreeTest, setGetData) {
     // set new data to an existing node.  It should have some data.
     int* newdata = new int(11);



More information about the bind10-changes mailing list