| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 SharedMemory memory; | 51 SharedMemory memory; |
| 52 bool rv = memory.CreateNamed(s_test_name_, true, kDataSize); | 52 bool rv = memory.CreateNamed(s_test_name_, true, kDataSize); |
| 53 EXPECT_TRUE(rv); | 53 EXPECT_TRUE(rv); |
| 54 rv = memory.Map(kDataSize); | 54 rv = memory.Map(kDataSize); |
| 55 EXPECT_TRUE(rv); | 55 EXPECT_TRUE(rv); |
| 56 int *ptr = static_cast<int*>(memory.memory()) + id_; | 56 int *ptr = static_cast<int*>(memory.memory()) + id_; |
| 57 EXPECT_EQ(0, *ptr); | 57 EXPECT_EQ(0, *ptr); |
| 58 | 58 |
| 59 for (int idx = 0; idx < 100; idx++) { | 59 for (int idx = 0; idx < 100; idx++) { |
| 60 *ptr = idx; | 60 *ptr = idx; |
| 61 PlatformThread::Sleep(1); // Short wait. | 61 PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); |
| 62 EXPECT_EQ(*ptr, idx); | 62 EXPECT_EQ(*ptr, idx); |
| 63 } | 63 } |
| 64 // Reset back to 0 for the next test that uses the same name. | 64 // Reset back to 0 for the next test that uses the same name. |
| 65 *ptr = 0; | 65 *ptr = 0; |
| 66 | 66 |
| 67 memory.Close(); | 67 memory.Close(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 int16 id_; | 71 int16 id_; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 SharedMemory memory2(handle, false); | 108 SharedMemory memory2(handle, false); |
| 109 EXPECT_TRUE(memory2.Map(kDataSize)); | 109 EXPECT_TRUE(memory2.Map(kDataSize)); |
| 110 volatile int* const ptr = static_cast<int*>(memory2.memory()); | 110 volatile int* const ptr = static_cast<int*>(memory2.memory()); |
| 111 | 111 |
| 112 for (int idx = 0; idx < 20; idx++) { | 112 for (int idx = 0; idx < 20; idx++) { |
| 113 memory2.Lock(); | 113 memory2.Lock(); |
| 114 int i = (id_ << 16) + idx; | 114 int i = (id_ << 16) + idx; |
| 115 *ptr = i; | 115 *ptr = i; |
| 116 PlatformThread::Sleep(1); // Short wait. | 116 PlatformThread::Sleep(TimeDelta::FromMilliseconds(1)); |
| 117 EXPECT_EQ(*ptr, i); | 117 EXPECT_EQ(*ptr, i); |
| 118 memory2.Unlock(); | 118 memory2.Unlock(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 memory2.Close(); | 121 memory2.Close(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 int id_; | 125 int id_; |
| 126 | 126 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 rv = memory.Map(kDataSize); | 381 rv = memory.Map(kDataSize); |
| 382 EXPECT_TRUE(rv); | 382 EXPECT_TRUE(rv); |
| 383 if (rv != true) | 383 if (rv != true) |
| 384 errors++; | 384 errors++; |
| 385 int *ptr = static_cast<int*>(memory.memory()); | 385 int *ptr = static_cast<int*>(memory.memory()); |
| 386 | 386 |
| 387 for (int idx = 0; idx < 20; idx++) { | 387 for (int idx = 0; idx < 20; idx++) { |
| 388 memory.Lock(); | 388 memory.Lock(); |
| 389 int i = (1 << 16) + idx; | 389 int i = (1 << 16) + idx; |
| 390 *ptr = i; | 390 *ptr = i; |
| 391 PlatformThread::Sleep(10); // Short wait. | 391 PlatformThread::Sleep(TimeDelta::FromMilliseconds(10)); |
| 392 if (*ptr != i) | 392 if (*ptr != i) |
| 393 errors++; | 393 errors++; |
| 394 memory.Unlock(); | 394 memory.Unlock(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 memory.Close(); | 397 memory.Close(); |
| 398 return errors; | 398 return errors; |
| 399 } | 399 } |
| 400 | 400 |
| 401 private: | 401 private: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 427 } | 427 } |
| 428 | 428 |
| 429 SharedMemoryProcessTest::CleanUp(); | 429 SharedMemoryProcessTest::CleanUp(); |
| 430 } | 430 } |
| 431 | 431 |
| 432 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 432 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
| 433 return SharedMemoryProcessTest::TaskTestMain(); | 433 return SharedMemoryProcessTest::TaskTestMain(); |
| 434 } | 434 } |
| 435 | 435 |
| 436 } // namespace base | 436 } // namespace base |
| OLD | NEW |