OLD | NEW |
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" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 options.executable = true; | 354 options.executable = true; |
355 | 355 |
356 EXPECT_TRUE(shared_memory.Create(options)); | 356 EXPECT_TRUE(shared_memory.Create(options)); |
357 EXPECT_TRUE(shared_memory.Map(shared_memory.created_size())); | 357 EXPECT_TRUE(shared_memory.Map(shared_memory.created_size())); |
358 | 358 |
359 EXPECT_EQ(0, mprotect(shared_memory.memory(), shared_memory.created_size(), | 359 EXPECT_EQ(0, mprotect(shared_memory.memory(), shared_memory.created_size(), |
360 PROT_READ | PROT_EXEC)); | 360 PROT_READ | PROT_EXEC)); |
361 } | 361 } |
362 #endif | 362 #endif |
363 | 363 |
| 364 // Map() will return addresses which are aligned to the platform page size, this |
| 365 // varies from platform to platform though. Since we'd like to advertise a |
| 366 // minimum alignment that callers can count on, test for it here. |
| 367 TEST(SharedMemoryTest, MapMinimumAlignment) { |
| 368 static const int kDataSize = 8192; |
| 369 |
| 370 SharedMemory shared_memory; |
| 371 ASSERT_TRUE(shared_memory.CreateAndMapAnonymous(kDataSize)); |
| 372 EXPECT_EQ(0U, reinterpret_cast<uintptr_t>( |
| 373 shared_memory.memory()) & (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); |
| 374 shared_memory.Close(); |
| 375 } |
| 376 |
364 #if !defined(OS_IOS) // iOS does not allow multiple processes. | 377 #if !defined(OS_IOS) // iOS does not allow multiple processes. |
365 | 378 |
366 // On POSIX it is especially important we test shmem across processes, | 379 // On POSIX it is especially important we test shmem across processes, |
367 // not just across threads. But the test is enabled on all platforms. | 380 // not just across threads. But the test is enabled on all platforms. |
368 class SharedMemoryProcessTest : public MultiProcessTest { | 381 class SharedMemoryProcessTest : public MultiProcessTest { |
369 public: | 382 public: |
370 | 383 |
371 static void CleanUp() { | 384 static void CleanUp() { |
372 SharedMemory memory; | 385 SharedMemory memory; |
373 memory.Delete(s_test_name_); | 386 memory.Delete(s_test_name_); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 SharedMemoryProcessTest::CleanUp(); | 441 SharedMemoryProcessTest::CleanUp(); |
429 } | 442 } |
430 | 443 |
431 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 444 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
432 return SharedMemoryProcessTest::TaskTestMain(); | 445 return SharedMemoryProcessTest::TaskTestMain(); |
433 } | 446 } |
434 | 447 |
435 #endif // !OS_IOS | 448 #endif // !OS_IOS |
436 | 449 |
437 } // namespace base | 450 } // namespace base |
OLD | NEW |