diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-03 11:00:16 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-03 11:01:57 +0100 |
commit | c0ecc5d29f69fcd6824ad971a3ce4773330a6f1e (patch) | |
tree | af032c2598096a0072e90bc655c3a3c4eb532446 /vespalib/src/tests/alloc/alloc_test.cpp | |
parent | 23d144ff2e2e828aa7a45932b7b5363f8fbc1651 (diff) |
Implement both extension and shrinking of buffers.
Diffstat (limited to 'vespalib/src/tests/alloc/alloc_test.cpp')
-rw-r--r-- | vespalib/src/tests/alloc/alloc_test.cpp | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/vespalib/src/tests/alloc/alloc_test.cpp b/vespalib/src/tests/alloc/alloc_test.cpp index 6950287edb1..03d600c6559 100644 --- a/vespalib/src/tests/alloc/alloc_test.cpp +++ b/vespalib/src/tests/alloc/alloc_test.cpp @@ -103,23 +103,51 @@ TEST("rounding of large mmaped buffer") { } TEST("heap alloc can not be extended") { - Alloc buf = Alloc::allocHeap(100); - void * oldPtr = buf.get(); - EXPECT_EQUAL(100, buf.size()); - EXPECT_FALSE(buf.resize_inplace(101)); - EXPECT_EQUAL(oldPtr, buf.get()); - EXPECT_EQUAL(100, buf.size()); + Alloc buf = Alloc::allocHeap(100); + void * oldPtr = buf.get(); + EXPECT_EQUAL(100, buf.size()); + EXPECT_FALSE(buf.resize_inplace(101)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL(100, buf.size()); } -TEST("mmap alloc can be extended") { - Alloc buf = Alloc::allocMMap(100); - void * oldPtr = buf.get(); - EXPECT_EQUAL(4096, buf.size()); - EXPECT_TRUE(buf.resize_inplace(4097)); - EXPECT_EQUAL(oldPtr, buf.get()); - EXPECT_EQUAL(8192, buf.size()); +TEST("mmap alloc can be extended if room") { + Alloc reserved = Alloc::allocMMap(100); + Alloc buf = Alloc::allocMMap(100); + + // Normally mmapping starts at the top and grows down in address space. + // The there is no room to extend the last mapping. + // So in order to verify this we first mmap a reserved area that we unmap + // before we test extension. + EXPECT_GREATER(reserved.get(), buf.get()); + EXPECT_EQUAL(reserved.get(), static_cast<const char *>(buf.get()) + buf.size()); + { + Alloc().swap(reserved); + } + + void * oldPtr = buf.get(); + EXPECT_EQUAL(4096, buf.size()); + EXPECT_TRUE(buf.resize_inplace(4097)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL(8192, buf.size()); } +TEST("heap alloc can not be shrinked") { + Alloc buf = Alloc::allocHeap(101); + void * oldPtr = buf.get(); + EXPECT_EQUAL(101, buf.size()); + EXPECT_FALSE(buf.resize_inplace(100)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL(101, buf.size()); +} +TEST("mmap alloc can be shrinked") { + Alloc buf = Alloc::allocMMap(4097); + void * oldPtr = buf.get(); + EXPECT_EQUAL(8192, buf.size()); + EXPECT_TRUE(buf.resize_inplace(4095)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL(4096, buf.size()); +} TEST_MAIN() { TEST_RUN_ALL(); } |