]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2831] check two different addressed from getNamedAddress can share the data.
authorJINMEI Tatuya <jinmei@isc.org>
Wed, 10 Apr 2013 03:34:29 +0000 (20:34 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Wed, 10 Apr 2013 03:34:29 +0000 (20:34 -0700)
src/lib/util/tests/memory_segment_mapped_unittest.cc

index 3c777606ced62942fe168fa3922d6987a4ce7b2d..58690cfc99c7556205824780bf1a3714c821404a 100644 (file)
@@ -216,6 +216,7 @@ TEST_F(MemorySegmentMappedTest, badDeallocate) {
     EXPECT_TRUE(segment_->allMemoryDeallocated());
 }
 
+// A helper of namedAddress.
 void
 checkNamedData(const std::string& name, const std::vector<uint8_t>& data,
                MemorySegment& sgmt, bool delete_after_check = false)
@@ -223,6 +224,23 @@ checkNamedData(const std::string& name, const std::vector<uint8_t>& data,
     void* dp = sgmt.getNamedAddress(name.c_str());
     ASSERT_TRUE(dp);
     EXPECT_EQ(0, std::memcmp(dp, &data[0], data.size()));
+
+    // Open a separate read-only segment and checks the same named data
+    // Since the mapped space should be different, the resulting bare address
+    // from getNamedAddress should also be different, but it should actually
+    // point to the same data.
+    // Note: it's mostly violation of the API assumption to open read-only
+    // and read-write segments at the same time, but unless we modify the
+    // segment throughout the lifetime of the read-only segment, it should
+    // work.
+    scoped_ptr<MemorySegmentMapped> segment_ro(
+        new MemorySegmentMapped(mapped_file));
+    void* dp2 = segment_ro->getNamedAddress(name.c_str());
+    ASSERT_TRUE(dp2);
+    EXPECT_NE(dp, dp2);
+    EXPECT_EQ(0, std::memcmp(dp2, &data[0], data.size()));
+    segment_ro.reset();
+
     if (delete_after_check) {
         sgmt.deallocate(dp, data.size());
     }