| 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/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 SharedMemory memory; | 675 SharedMemory memory; |
| 676 bool rv = memory.CreateNamedDeprecated(s_test_name_, true, s_data_size_); | 676 bool rv = memory.CreateNamedDeprecated(s_test_name_, true, s_data_size_); |
| 677 ASSERT_TRUE(rv); | 677 ASSERT_TRUE(rv); |
| 678 rv = memory.Map(s_data_size_); | 678 rv = memory.Map(s_data_size_); |
| 679 ASSERT_TRUE(rv); | 679 ASSERT_TRUE(rv); |
| 680 int* ptr = static_cast<int*>(memory.memory()); | 680 int* ptr = static_cast<int*>(memory.memory()); |
| 681 *ptr = 0; | 681 *ptr = 0; |
| 682 | 682 |
| 683 // Start |kNumTasks| processes, each of which atomically increments the first | 683 // Start |kNumTasks| processes, each of which atomically increments the first |
| 684 // word by 1. | 684 // word by 1. |
| 685 Process processes[kNumTasks]; | 685 SpawnChildResult children[kNumTasks]; |
| 686 for (int index = 0; index < kNumTasks; ++index) { | 686 for (int index = 0; index < kNumTasks; ++index) { |
| 687 processes[index] = SpawnChild("SharedMemoryTestMain"); | 687 children[index] = SpawnChild("SharedMemoryTestMain"); |
| 688 ASSERT_TRUE(processes[index].IsValid()); | 688 ASSERT_TRUE(children[index].process.IsValid()); |
| 689 } | 689 } |
| 690 | 690 |
| 691 // Check that each process exited correctly. | 691 // Check that each process exited correctly. |
| 692 int exit_code = 0; | 692 int exit_code = 0; |
| 693 for (int index = 0; index < kNumTasks; ++index) { | 693 for (int index = 0; index < kNumTasks; ++index) { |
| 694 EXPECT_TRUE(processes[index].WaitForExit(&exit_code)); | 694 EXPECT_TRUE(children[index].process.WaitForExit(&exit_code)); |
| 695 EXPECT_EQ(0, exit_code); | 695 EXPECT_EQ(0, exit_code); |
| 696 } | 696 } |
| 697 | 697 |
| 698 // Check that the shared memory region reflects |kNumTasks| increments. | 698 // Check that the shared memory region reflects |kNumTasks| increments. |
| 699 ASSERT_EQ(kNumTasks, *ptr); | 699 ASSERT_EQ(kNumTasks, *ptr); |
| 700 | 700 |
| 701 memory.Close(); | 701 memory.Close(); |
| 702 SharedMemoryProcessTest::CleanUp(); | 702 SharedMemoryProcessTest::CleanUp(); |
| 703 } | 703 } |
| 704 | 704 |
| 705 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 705 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
| 706 return SharedMemoryProcessTest::TaskTestMain(); | 706 return SharedMemoryProcessTest::TaskTestMain(); |
| 707 } | 707 } |
| 708 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 708 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
| 709 | 709 |
| 710 } // namespace base | 710 } // namespace base |
| OLD | NEW |