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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #if defined(OS_MACOSX) 6 #if defined(OS_MACOSX)
7 #include "base/mac/scoped_nsautorelease_pool.h" 7 #include "base/mac/scoped_nsautorelease_pool.h"
8 #endif 8 #endif
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
11 #include "base/sys_info.h"
11 #include "base/test/multiprocess_test.h" 12 #include "base/test/multiprocess_test.h"
12 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/multiprocess_func_list.h" 16 #include "testing/multiprocess_func_list.h"
16 17
17 #if defined(OS_MACOSX) 18 #if defined(OS_MACOSX)
18 #include "base/mac/scoped_nsautorelease_pool.h" 19 #include "base/mac/scoped_nsautorelease_pool.h"
19 #endif 20 #endif
20 21
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 else 337 else
337 EXPECT_EQ(0, pointers[j][0]); 338 EXPECT_EQ(0, pointers[j][0]);
338 } 339 }
339 } 340 }
340 341
341 for (int i = 0; i < count; i++) { 342 for (int i = 0; i < count; i++) {
342 memories[i].Close(); 343 memories[i].Close();
343 } 344 }
344 } 345 }
345 346
347 TEST(SharedMemoryTest, MapFrom) {
348 ASSERT_TRUE(SysInfo::VMAllocationGranularity() >= sizeof(uint32));
349 const size_t kCount = SysInfo::VMAllocationGranularity();
350 const size_t kDataSize = kCount * sizeof(uint32);
351 static const char kTestName[] = "SharedMemoryMapFrom";
352
353 SharedMemory memory1;
354 memory1.Delete(kTestName);
355 ASSERT_TRUE(memory1.CreateNamed(kTestName, false, kDataSize));
356 ASSERT_TRUE(memory1.Map(kDataSize));
357 uint32* ptr1 = static_cast<uint32*>(memory1.memory());
358 ASSERT_NE(ptr1, static_cast<void*>(NULL));
359
360 for (size_t i = 0; i < kCount; ++i) {
361 ptr1[i] = i;
362 }
363
364 SharedMemory memory2;
365 ASSERT_TRUE(memory2.CreateNamed(kTestName, true, kDataSize));
366 off_t offset = SysInfo::VMAllocationGranularity();
367 ASSERT_TRUE(memory2.MapFrom(offset, kDataSize - offset));
368 offset /= sizeof(uint32);
369 uint32* ptr2 = static_cast<uint32*>(memory2.memory());
370 ASSERT_NE(ptr2, static_cast<void*>(NULL));
371 for (size_t i = offset; i < kCount; ++i) {
372 ASSERT_EQ(ptr2[i - offset], i);
373 }
374 memory1.Delete(kTestName);
375 }
376
346 #if defined(OS_POSIX) 377 #if defined(OS_POSIX)
347 // Create a shared memory object, mmap it, and mprotect it to PROT_EXEC. 378 // Create a shared memory object, mmap it, and mprotect it to PROT_EXEC.
348 TEST(SharedMemoryTest, AnonymousExecutable) { 379 TEST(SharedMemoryTest, AnonymousExecutable) {
349 const uint32 kTestSize = 1 << 16; 380 const uint32 kTestSize = 1 << 16;
350 381
351 SharedMemory shared_memory; 382 SharedMemory shared_memory;
352 SharedMemoryCreateOptions options; 383 SharedMemoryCreateOptions options;
353 options.size = kTestSize; 384 options.size = kTestSize;
354 options.executable = true; 385 options.executable = true;
355 386
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 SharedMemoryProcessTest::CleanUp(); 472 SharedMemoryProcessTest::CleanUp();
442 } 473 }
443 474
444 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 475 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
445 return SharedMemoryProcessTest::TaskTestMain(); 476 return SharedMemoryProcessTest::TaskTestMain();
446 } 477 }
447 478
448 #endif // !OS_IOS 479 #endif // !OS_IOS
449 480
450 } // namespace base 481 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698