Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3296)

Unified Diff: base/shared_memory_unittest.cc

Issue 12537014: Make SharedMemory track the size that was actually mapped (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/shared_memory_posix.cc ('k') | base/shared_memory_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/shared_memory_unittest.cc
===================================================================
--- base/shared_memory_unittest.cc (revision 190994)
+++ base/shared_memory_unittest.cc (working copy)
@@ -197,11 +197,18 @@
EXPECT_TRUE(rv);
// Memory1 knows it's size because it created it.
- EXPECT_EQ(memory1.created_size(), kDataSize);
+ EXPECT_EQ(memory1.requested_size(), kDataSize);
rv = memory1.Map(kDataSize);
EXPECT_TRUE(rv);
+ // The mapped memory1 must be at least the size we asked for.
+ EXPECT_GE(memory1.mapped_size(), kDataSize);
+
+ // The mapped memory1 shouldn't exceed rounding for allocation granularity.
+ EXPECT_LT(memory1.mapped_size(),
+ kDataSize + base::SysInfo::VMAllocationGranularity());
+
memset(memory1.memory(), 'G', kDataSize);
SharedMemory memory2;
@@ -214,12 +221,19 @@
EXPECT_TRUE(rv);
// Memory2 shouldn't know the size because we didn't create it.
- EXPECT_EQ(memory2.created_size(), 0U);
+ EXPECT_EQ(memory2.requested_size(), 0U);
// We should be able to map the original size.
rv = memory2.Map(kDataSize);
EXPECT_TRUE(rv);
+ // The mapped memory2 must be at least the size of the original.
+ EXPECT_GE(memory2.mapped_size(), kDataSize);
+
+ // The mapped memory2 shouldn't exceed rounding for allocation granularity.
+ EXPECT_LT(memory2.mapped_size(),
+ kDataSize2 + base::SysInfo::VMAllocationGranularity());
+
// Verify that opening memory2 didn't truncate or delete memory 1.
char *start_ptr = static_cast<char *>(memory2.memory());
char *end_ptr = start_ptr + kDataSize;
@@ -382,9 +396,9 @@
options.executable = true;
EXPECT_TRUE(shared_memory.Create(options));
- EXPECT_TRUE(shared_memory.Map(shared_memory.created_size()));
+ EXPECT_TRUE(shared_memory.Map(shared_memory.requested_size()));
- EXPECT_EQ(0, mprotect(shared_memory.memory(), shared_memory.created_size(),
+ EXPECT_EQ(0, mprotect(shared_memory.memory(), shared_memory.requested_size(),
PROT_READ | PROT_EXEC));
}
#endif
« no previous file with comments | « base/shared_memory_posix.cc ('k') | base/shared_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698