diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-04 00:17:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-04 00:17:54 +0100 |
commit | 1ece7c2b9b7ae8c95029e8c553ad277bcd0668fd (patch) | |
tree | 2f755a028df5044c552f3c6ebfe6d65049731178 /vespalib/src/tests/alloc/alloc_test.cpp | |
parent | 4a5c54e6e3780f7a02d83ec325938317ef3837b1 (diff) |
Revert "Balder/extend in place rebased"
Diffstat (limited to 'vespalib/src/tests/alloc/alloc_test.cpp')
-rw-r--r-- | vespalib/src/tests/alloc/alloc_test.cpp | 177 |
1 files changed, 10 insertions, 167 deletions
diff --git a/vespalib/src/tests/alloc/alloc_test.cpp b/vespalib/src/tests/alloc/alloc_test.cpp index f614ca79f04..e217abfbd16 100644 --- a/vespalib/src/tests/alloc/alloc_test.cpp +++ b/vespalib/src/tests/alloc/alloc_test.cpp @@ -16,11 +16,11 @@ testSwap(T & a, T & b) { void * tmpA(a.get()); void * tmpB(b.get()); - EXPECT_EQUAL(4096u, a.size()); - EXPECT_EQUAL(8192, b.size()); + EXPECT_EQUAL(100u, a.size()); + EXPECT_EQUAL(200u, b.size()); std::swap(a, b); - EXPECT_EQUAL(4096u, b.size()); - EXPECT_EQUAL(8192, a.size()); + EXPECT_EQUAL(100u, b.size()); + EXPECT_EQUAL(200u, a.size()); EXPECT_EQUAL(tmpA, b.get()); EXPECT_EQUAL(tmpB, a.get()); } @@ -39,24 +39,24 @@ TEST("test basics") { } { Alloc h = Alloc::allocMMap(100); - EXPECT_EQUAL(4096u, h.size()); + EXPECT_EQUAL(100u, h.size()); EXPECT_TRUE(h.get() != nullptr); } { - Alloc a = Alloc::allocHeap(4096), b = Alloc::allocHeap(8192); + Alloc a = Alloc::allocHeap(100), b = Alloc::allocHeap(200); testSwap(a, b); } { - Alloc a = Alloc::allocMMap(4096), b = Alloc::allocMMap(8192); + Alloc a = Alloc::allocMMap(100), b = Alloc::allocMMap(200); testSwap(a, b); } { - Alloc a = Alloc::allocAlignedHeap(4096, 1024), b = Alloc::allocAlignedHeap(8192, 1024); + Alloc a = Alloc::allocAlignedHeap(100, 1024), b = Alloc::allocAlignedHeap(200, 1024); testSwap(a, b); } { - Alloc a = Alloc::allocHeap(4096); - Alloc b = Alloc::allocMMap(8192); + Alloc a = Alloc::allocHeap(100); + Alloc b = Alloc::allocMMap(200); testSwap(a, b); } { @@ -102,161 +102,4 @@ TEST("rounding of large mmaped buffer") { EXPECT_EQUAL(MemoryAllocator::HUGEPAGE_SIZE*12, buf.size()); } -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()); -} - -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); - - // 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(4096, buf.size()); - EXPECT_TRUE(buf.resize_inplace(4097)); - EXPECT_EQUAL(oldPtr, buf.get()); - EXPECT_EQUAL(8192, buf.size()); -} - -TEST("mmap alloc can not be extended if no room") { - Alloc reserved = Alloc::allocMMap(100); - Alloc buf = Alloc::allocMMap(100); - - // 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(4096, buf.size()); - EXPECT_FALSE(buf.resize_inplace(4097)); - EXPECT_EQUAL(oldPtr, buf.get()); - EXPECT_EQUAL(4096, 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("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(); } |