BIND 10 trac2836, updated. d42136528ea0edc6c7ea45c3c4d4c542217f9d33 [2836] Use other segments in the tests as well
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu May 2 13:28:41 UTC 2013
The branch, trac2836 has been updated
via d42136528ea0edc6c7ea45c3c4d4c542217f9d33 (commit)
from 1024b43c68506682dd55cf1cf9c5fc9dbc8cd96b (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 d42136528ea0edc6c7ea45c3c4d4c542217f9d33
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu May 2 15:22:43 2013 +0200
[2836] Use other segments in the tests as well
Use other memory segments than just the test one.
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/tests/memory/Makefile.am | 2 +
.../tests/memory/zone_data_updater_unittest.cc | 52 ++++++++++++++++++++
2 files changed, 54 insertions(+)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/tests/memory/Makefile.am b/src/lib/datasrc/tests/memory/Makefile.am
index f77d212..e0b05b6 100644
--- a/src/lib/datasrc/tests/memory/Makefile.am
+++ b/src/lib/datasrc/tests/memory/Makefile.am
@@ -4,6 +4,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_builddir)/src/lib/dns -I$(top_srcdir)/src/lib/dns
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(abs_srcdir)/testdata\"
+AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_builddir)\"
+
AM_CXXFLAGS = $(B10_CXXFLAGS)
diff --git a/src/lib/datasrc/tests/memory/zone_data_updater_unittest.cc b/src/lib/datasrc/tests/memory/zone_data_updater_unittest.cc
index c8bbf59..ae18246 100644
--- a/src/lib/datasrc/tests/memory/zone_data_updater_unittest.cc
+++ b/src/lib/datasrc/tests/memory/zone_data_updater_unittest.cc
@@ -25,6 +25,9 @@
#include <dns/rrset.h>
#include <dns/rrttl.h>
+#include <util/memory_segment_local.h>
+#include <util/memory_segment_mapped.h>
+
#include "memory_segment_test.h"
#include <gtest/gtest.h>
@@ -39,10 +42,18 @@ using namespace isc::datasrc::memory;
namespace {
+const char* const mapped_file = TEST_DATA_BUILDDIR "/test.mapped";
+
+// An abstract factory class for the segments. We want fresh segment for each
+// test, so we have different factories for them.
class SegmentCreator {
public:
typedef boost::shared_ptr<isc::util::MemorySegment> SegmentPtr;
+ // Create the segment.
virtual SegmentPtr create() const = 0;
+ // Clean-up after the test. Most of them will be just NOP (the default),
+ // but the file-mapped one needs to remove the file.
+ virtual void cleanup() const {};
};
class ZoneDataUpdaterTest : public ::testing::TestWithParam<SegmentCreator*> {
@@ -61,6 +72,7 @@ protected:
if (!mem_sgmt_->allMemoryDeallocated()) {
ADD_FAILURE() << "Memory leak detected";
}
+ GetParam()->cleanup();
}
void clearZoneData() {
@@ -91,6 +103,46 @@ INSTANTIATE_TEST_CASE_P(TestSegment, ZoneDataUpdaterTest,
::testing::Values(static_cast<SegmentCreator*>(
&test_segment_creator)));
+class MemorySegmentCreator : public SegmentCreator {
+public:
+ virtual SegmentPtr create() const {
+ // We are not really supposed to create the segment directly in real
+ // code, but it should be OK inside tests.
+ return SegmentPtr(new isc::util::MemorySegmentLocal);
+ }
+};
+
+MemorySegmentCreator memory_segment_creator;
+
+INSTANTIATE_TEST_CASE_P(LocalSegment, ZoneDataUpdaterTest,
+ ::testing::Values(static_cast<SegmentCreator*>(
+ &memory_segment_creator)));
+
+class MappedSegmentCreator : public SegmentCreator {
+public:
+ MappedSegmentCreator(size_t initial_size =
+ isc::util::MemorySegmentMapped::INITIAL_SIZE) :
+ initial_size_(initial_size)
+ {}
+ virtual SegmentPtr create() const {
+ return SegmentPtr(new isc::util::MemorySegmentMapped(mapped_file,
+ isc::util::MemorySegmentMapped::CREATE_ONLY, initial_size_));
+ }
+ virtual void cleanup() const {
+ EXPECT_EQ(0, unlink(mapped_file));
+ }
+private:
+ size_t initial_size_;
+};
+
+// There should be no initialization fiasco there. We only set int value inside
+// and don't use it until the create() is called.
+MappedSegmentCreator small_creator(4092), default_creator;
+
+INSTANTIATE_TEST_CASE_P(MappedSegment, ZoneDataUpdaterTest, ::testing::Values(
+ static_cast<SegmentCreator*>(&small_creator),
+ static_cast<SegmentCreator*>(&default_creator)));
+
TEST_P(ZoneDataUpdaterTest, bothNull) {
// At least either covered RRset or RRSIG must be non NULL.
EXPECT_THROW(updater_->add(ConstRRsetPtr(), ConstRRsetPtr()),
More information about the bind10-changes
mailing list