Commit f4ca083e authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2836-2] use managed_mapped_file to cause remap at different addr.

the original setup was not really portable and quite dangerous, making
a very large file.
parent 3a6ae66c
......@@ -17,6 +17,8 @@
#include <datasrc/memory/segment_object_holder.h>
#include <boost/interprocess/managed_mapped_file.hpp>
#include <gtest/gtest.h>
using namespace isc::util;
......@@ -92,13 +94,25 @@ TEST(SegmentObjectHolderTest, grow) {
// Allocate a bit of memory, to get a unique address
void* mark = segment.allocate(1);
segment.setNamedAddress("mark", mark);
// We'd like to cause 'mark' will be mapped at a different address on
// MemorySegmentGrown; there doesn't seem to be a reliable and safe way
// to cause this situation, but opening another mapped region seems to
// often work in practice. We use Boost managed_mapped_file directly
// to ignore the imposed file lock with MemorySegmentMapped.
using boost::interprocess::managed_mapped_file;
using boost::interprocess::open_only;
managed_mapped_file mapped_sgmt(open_only, mapped_file);
// Try allocating bigger and bigger chunks of data until the segment
// actually relocates
size_t alloc_size = 1024;
while (mark == segment.getNamedAddress("mark")) {
EXPECT_THROW(allocateUntilGrows(segment, alloc_size),
EXPECT_THROW(allocateUntilGrows(segment, alloc_size), MemorySegmentGrown);
// Confirm it's now mapped at a different address.
EXPECT_NE(mark, segment.getNamedAddress("mark"))
<< "portability assumption for the test doesn't hold; "
"disable the test by setting env variable GTEST_FILTER to "
mark = segment.getNamedAddress("mark");
segment.deallocate(mark, 1);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment