diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-10-26 11:40:19 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-10-26 11:40:19 +0200 |
commit | 31ce7eeb3c2e6790ed7509f45df80253e9657d18 (patch) | |
tree | 065b002cad1444ba7e7afecc7773febf2ac7b6e5 /vespalib | |
parent | 106567609a5b0efc3285187582acf45a0899b5ef (diff) |
Reanble test after making independent of vm.legacy_va_layout
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/alloc/alloc_test.cpp | 91 |
1 files changed, 38 insertions, 53 deletions
diff --git a/vespalib/src/tests/alloc/alloc_test.cpp b/vespalib/src/tests/alloc/alloc_test.cpp index 2d4ebd14dc2..0e52d06a2d5 100644 --- a/vespalib/src/tests/alloc/alloc_test.cpp +++ b/vespalib/src/tests/alloc/alloc_test.cpp @@ -127,87 +127,72 @@ TEST("auto alloced heap alloc can not be extended, even if resize will be mmappe EXPECT_EQUAL(100ul, buf.size()); } -// Temporary disable test as it depends on sysctl setting vm.legacy_va_layout = 0 -// Setting it too true change the order address space is used by OS. -#if 0 -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); +void verifyExtension(Alloc & buf, size_t currSZ, size_t newSZ) { + bool expectSuccess = (currSZ != newSZ); + void * oldPtr = buf.get(); + EXPECT_EQUAL(currSZ, buf.size()); + EXPECT_EQUAL(expectSuccess, buf.resize_inplace(currSZ+1)); + EXPECT_EQUAL(oldPtr, buf.get()); + EXPECT_EQUAL(newSZ, buf.size()); +} +void ensureRoomForExtension(const Alloc & buf, Alloc & reserved) { // 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); + if (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()); +void verifyNoExtensionWhenNoRoom(Alloc & buf, Alloc & reserved, size_t sz) { + if (reserved.get() > buf.get()) { + // Normally mmapping starts at the top and grows down in address space. + // Then there is no room to extend the last mapping. + EXPECT_EQUAL(reserved.get(), static_cast<const char *>(buf.get()) + buf.size()); + TEST_DO(verifyExtension(buf, sz, sz)); + } else { + EXPECT_EQUAL(buf.get(), static_cast<const char *>(reserved.get()) + reserved.size()); + TEST_DO(verifyExtension(reserved, sz, sz)); + } } -TEST("auto alloced mmap alloc can not be extended if no room") { +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. - EXPECT_GREATER(reserved.get(), buf.get()); - EXPECT_EQUAL(reserved.get(), static_cast<const char *>(buf.get()) + buf.size()); + TEST_DO(ensureRoomForExtension(buf, reserved)); + TEST_DO(verifyExtension(buf, SZ, (SZ/2)*3)); +} - 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("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); + + TEST_DO(verifyNoExtensionWhenNoRoom(buf, reserved, SZ)); } 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(4096ul, buf.size()); - EXPECT_TRUE(buf.resize_inplace(4097)); - EXPECT_EQUAL(oldPtr, buf.get()); - EXPECT_EQUAL(8192ul, buf.size()); + TEST_DO(ensureRoomForExtension(buf, reserved)); + TEST_DO(verifyExtension(buf, 4096, 4096*2)); } 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. - EXPECT_GREATER(reserved.get(), buf.get()); - EXPECT_EQUAL(reserved.get(), static_cast<const char *>(buf.get()) + buf.size()); - - void * oldPtr = buf.get(); - EXPECT_EQUAL(4096ul, buf.size()); - EXPECT_FALSE(buf.resize_inplace(4097)); - EXPECT_EQUAL(oldPtr, buf.get()); - EXPECT_EQUAL(4096ul, buf.size()); + TEST_DO(verifyNoExtensionWhenNoRoom(buf, reserved, 4096)); } -#endif - TEST("heap alloc can not be shrinked") { Alloc buf = Alloc::allocHeap(101); void * oldPtr = buf.get(); |