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

Unified Diff: base/shared_memory_unittest.cc

Issue 11876037: Added SharedMemory::MapFrom. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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
diff --git a/base/shared_memory_unittest.cc b/base/shared_memory_unittest.cc
index bd537692f4880febe1ce12dc9a18e91991296ca4..f02e2753130fafc3f1bde74351b099482f0b2b8c 100644
--- a/base/shared_memory_unittest.cc
+++ b/base/shared_memory_unittest.cc
@@ -8,6 +8,7 @@
#endif
#include "base/memory/scoped_ptr.h"
#include "base/shared_memory.h"
+#include "base/sys_info.h"
#include "base/test/multiprocess_test.h"
#include "base/threading/platform_thread.h"
#include "base/time.h"
@@ -343,6 +344,33 @@ TEST(SharedMemoryTest, AnonymousPrivate) {
}
}
+TEST(SharedMemoryTest, MapAt) {
+ ASSERT_TRUE(SysInfo::VMAllocationGranularity() >= sizeof(uint32));
+ const size_t kCount = SysInfo::VMAllocationGranularity();
+ const size_t kDataSize = kCount * sizeof(uint32);
+
+ SharedMemory memory;
+ ASSERT_TRUE(memory.CreateAndMapAnonymous(kDataSize));
+ ASSERT_TRUE(memory.Map(kDataSize));
+ uint32* ptr = static_cast<uint32*>(memory.memory());
+ ASSERT_NE(ptr, static_cast<void*>(NULL));
+
+ for (size_t i = 0; i < kCount; ++i) {
+ ptr[i] = i;
+ }
+
+ memory.Unmap();
+
+ off_t offset = SysInfo::VMAllocationGranularity();
+ ASSERT_TRUE(memory.MapAt(offset, kDataSize - offset));
+ offset /= sizeof(uint32);
+ ptr = static_cast<uint32*>(memory.memory());
+ ASSERT_NE(ptr, static_cast<void*>(NULL));
+ for (size_t i = offset; i < kCount; ++i) {
+ EXPECT_EQ(ptr[i - offset], i);
+ }
+}
+
#if defined(OS_POSIX)
// Create a shared memory object, mmap it, and mprotect it to PROT_EXEC.
TEST(SharedMemoryTest, AnonymousExecutable) {
« 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