diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-03 22:14:42 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-03 22:14:42 +0100 |
commit | 8baa92fc7a465c0295e6fa0603f5ce5738bafd92 (patch) | |
tree | 8e5cf4607a647726204b3f0a81e948c456912322 /vespalib/src/tests/alloc | |
parent | 8fd7bdfae6ddee3ba4f6d9a586b82a327510e3cb (diff) |
Added tests for the auto alloc for what works and what does not.
Tested all the border passings.
Use mmap also for the range (mmapLimit - HUGE_PAGESIZE/2 + 1) -> mmapLimit.
For all practical purposes this affects only 1M+1 to 2M.
Diffstat (limited to 'vespalib/src/tests/alloc')
-rw-r--r-- | vespalib/src/tests/alloc/alloc_test.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/vespalib/src/tests/alloc/alloc_test.cpp b/vespalib/src/tests/alloc/alloc_test.cpp index a533197ef91..f614ca79f04 100644 --- a/vespalib/src/tests/alloc/alloc_test.cpp +++ b/vespalib/src/tests/alloc/alloc_test.cpp @@ -111,6 +111,65 @@ TEST("heap alloc can not be extended") { EXPECT_EQUAL(100, buf.size()); } +TEST("auto alloced heap alloc can not be extended") { + Alloc buf = Alloc::alloc(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("auto alloced heap alloc can not be extended, even if resize will be mmapped") { + Alloc buf = Alloc::alloc(100); + void * oldPtr = buf.get(); + EXPECT_EQUAL(100, buf.size()); + EXPECT_FALSE(buf.resize_inplace(MemoryAllocator::HUGEPAGE_SIZE*3)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL(100, buf.size()); +} + +TEST("auto alloced mmap alloc can be extended if room") { + static constexpr size_t SZ = MemoryAllocator::HUGEPAGE_SIZE*2; + Alloc reserved = Alloc::alloc(SZ); + Alloc buf = Alloc::alloc(SZ); + + // Normally mmapping starts at the top and grows down in address space. + // Then 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(SZ, buf.size()); + EXPECT_TRUE(buf.resize_inplace(SZ+1)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL((SZ/2)*3, buf.size()); +} + +TEST("auto alloced mmap alloc can not be extended if no room") { + static constexpr size_t SZ = MemoryAllocator::HUGEPAGE_SIZE*2; + Alloc reserved = Alloc::alloc(SZ); + Alloc buf = Alloc::alloc(SZ); + + // Normally mmapping starts at the top and grows down in address space. + // Then 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()); + + void * oldPtr = buf.get(); + EXPECT_EQUAL(SZ, buf.size()); + EXPECT_FALSE(buf.resize_inplace(SZ+1)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL(SZ, buf.size()); +} + TEST("mmap alloc can be extended if room") { Alloc reserved = Alloc::allocMMap(100); Alloc buf = Alloc::allocMMap(100); @@ -168,4 +227,36 @@ TEST("mmap alloc can be shrinked") { EXPECT_EQUAL(4096, buf.size()); } +TEST("auto alloced heap alloc can not be shrinked") { + Alloc buf = Alloc::alloc(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("auto alloced mmap alloc can be shrinked") { + static constexpr size_t SZ = MemoryAllocator::HUGEPAGE_SIZE; + Alloc buf = Alloc::alloc(SZ + 1); + void * oldPtr = buf.get(); + EXPECT_EQUAL(SZ + MemoryAllocator::HUGEPAGE_SIZE, buf.size()); + EXPECT_TRUE(buf.resize_inplace(SZ-1)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL(SZ, buf.size()); +} + +TEST("auto alloced mmap alloc can not be shrinked below HUGEPAGE_SIZE/2 + 1 ") { + static constexpr size_t SZ = MemoryAllocator::HUGEPAGE_SIZE; + Alloc buf = Alloc::alloc(SZ + 1); + void * oldPtr = buf.get(); + EXPECT_EQUAL(SZ + MemoryAllocator::HUGEPAGE_SIZE, buf.size()); + EXPECT_TRUE(buf.resize_inplace(SZ/2 + 1)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL(SZ, buf.size()); + EXPECT_FALSE(buf.resize_inplace(SZ/2)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL(SZ, buf.size()); +} + TEST_MAIN() { TEST_RUN_ALL(); } |