BIND 10 trac2831, updated. 5d1b066a7702c075d7934a3ce88181b1c02da878 [2831] Add some more checks when the segment is grown
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Apr 9 07:59:47 UTC 2013
The branch, trac2831 has been updated
via 5d1b066a7702c075d7934a3ce88181b1c02da878 (commit)
via b610eee2708d9c1783384c850896c6203ccc3dd2 (commit)
via 58f99ec6977a07a6df8f7053d2e03201245491fd (commit)
from e9e336900ee014c251ad4b25a8e19d36da3a9a2e (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 5d1b066a7702c075d7934a3ce88181b1c02da878
Author: Mukund Sivaraman <muks at isc.org>
Date: Tue Apr 9 13:26:15 2013 +0530
[2831] Add some more checks when the segment is grown
It also makes use a of a prev_size variable (based on the initial
returned segment size).
commit b610eee2708d9c1783384c850896c6203ccc3dd2
Author: Mukund Sivaraman <muks at isc.org>
Date: Tue Apr 9 13:20:46 2013 +0530
[2831] Test getSize() directly with the new size, before and after reset
commit 58f99ec6977a07a6df8f7053d2e03201245491fd
Author: Mukund Sivaraman <muks at isc.org>
Date: Tue Apr 9 13:19:28 2013 +0530
[2831] Make some more minor comment updates
-----------------------------------------------------------------------
Summary of changes:
.../util/tests/memory_segment_mapped_unittest.cc | 56 +++++++++++---------
1 file changed, 32 insertions(+), 24 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/util/tests/memory_segment_mapped_unittest.cc b/src/lib/util/tests/memory_segment_mapped_unittest.cc
index d006fc4..aee50b4 100644
--- a/src/lib/util/tests/memory_segment_mapped_unittest.cc
+++ b/src/lib/util/tests/memory_segment_mapped_unittest.cc
@@ -84,7 +84,8 @@ TEST_F(MemorySegmentMappedTest, createAndModify) {
EXPECT_TRUE(segment_->allMemoryDeallocated());
- // re-open it.
+ // re-open it in read-write mode, but don't try to create it
+ // this time.
segment_.reset(new MemorySegmentMapped(mapped_file, false));
}
}
@@ -94,31 +95,34 @@ TEST_F(MemorySegmentMappedTest, createWithSize) {
// Re-create the mapped file with a non-default initial size, and confirm
// the size is actually the specified one.
- segment_.reset(new MemorySegmentMapped(mapped_file, true, 64 * 1024));
- EXPECT_NE(DEFAULT_INITIAL_SIZE, 64 * 1024);
- EXPECT_EQ(64 * 1024, segment_->getSize());
+ const size_t new_size = 64 * 1024;
+ EXPECT_NE(new_size, segment_->getSize());
+ segment_.reset(new MemorySegmentMapped(mapped_file, true, new_size));
+ EXPECT_EQ(new_size, segment_->getSize());
}
TEST_F(MemorySegmentMappedTest, openFail) {
// The given file is directory
EXPECT_THROW(MemorySegmentMapped("/", true), MemorySegmentOpenError);
- // file doesn't exist and directory isn't writable (we assume the root
- // directory is not writable for the user running the test).
- EXPECT_THROW(MemorySegmentMapped("/test.mapped", true),
+ // file doesn't exist and directory isn't writable (we assume the
+ // following path is not writable for the user running the test).
+ EXPECT_THROW(MemorySegmentMapped("/random-glkwjer098/test.mapped", true),
MemorySegmentOpenError);
- // file doesn't exist and it's read-only (so open-only)
+ // It should fail when file doesn't exist and it's read-only (so
+ // open-only).
EXPECT_THROW(MemorySegmentMapped(TEST_DATA_BUILDDIR "/nosuchfile.mapped"),
MemorySegmentOpenError);
- // Likewise. read-write mode but creation is suppressed.
+ // Likewise, it should fail in read-write mode when creation is
+ // suppressed.
EXPECT_THROW(MemorySegmentMapped(TEST_DATA_BUILDDIR "/nosuchfile.mapped",
false),
MemorySegmentOpenError);
- // Close the segment, break the file with bogus data, and try to reopen.
- // It should fail with exception whether in the read-only or read-write,
- // or "create if not exist" mode.
+ // Close the existing segment, break its file with bogus data, and
+ // try to reopen. It should fail with exception whether in the
+ // read-only or read-write, or "create if not exist" mode.
segment_.reset();
std::ofstream ofs(mapped_file, std::ios::trunc);
ofs << std::string(1024, 'x');
@@ -133,26 +137,30 @@ TEST_F(MemorySegmentMappedTest, openFail) {
TEST_F(MemorySegmentMappedTest, allocate) {
// Various case of allocation. The simplest cases are covered above.
+ // Initially, nothing is allocated.
+ EXPECT_TRUE(segment_->allMemoryDeallocated());
+
// (Clearly) exceeding the available size, which should cause growing
// the segment
- EXPECT_THROW(segment_->allocate(DEFAULT_INITIAL_SIZE + 1),
- MemorySegmentGrown);
+ const size_t prev_size = segment_->getSize();
+ EXPECT_THROW(segment_->allocate(prev_size + 1), MemorySegmentGrown);
// The size should have been doubled.
- EXPECT_EQ(DEFAULT_INITIAL_SIZE * 2, segment_->getSize());
- // In this case it should now succeed.
- void* ptr = segment_->allocate(DEFAULT_INITIAL_SIZE + 1);
- EXPECT_NE(static_cast<void*>(0), ptr);
+ EXPECT_EQ(prev_size * 2, segment_->getSize());
+ // But nothing should have been allocated.
+ EXPECT_TRUE(segment_->allMemoryDeallocated());
+ // Now, the allocation should now succeed.
+ void* ptr = segment_->allocate(prev_size + 1);
+ EXPECT_NE(static_cast<void*>(0), ptr);
EXPECT_FALSE(segment_->allMemoryDeallocated());
// Same set of checks, but for a larger size.
- EXPECT_THROW(segment_->allocate(DEFAULT_INITIAL_SIZE * 10),
- MemorySegmentGrown);
- // the segment should have grown to the minimum size that could allocate
- // the given size of memory.
- EXPECT_EQ(DEFAULT_INITIAL_SIZE * 16, segment_->getSize());
+ EXPECT_THROW(segment_->allocate(prev_size * 10), MemorySegmentGrown);
+ // the segment should have grown to the minimum power-of-2 size that
+ // could allocate the given size of memory.
+ EXPECT_EQ(prev_size * 16, segment_->getSize());
// And allocate() should now succeed.
- ptr = segment_->allocate(DEFAULT_INITIAL_SIZE * 10);
+ ptr = segment_->allocate(prev_size * 10);
EXPECT_NE(static_cast<void*>(0), ptr);
// (we'll left the regions created in the file there; the entire file
More information about the bind10-changes
mailing list