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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // On POSIX we have a problem when 2 threads try to create the shmem | 242 // On POSIX we have a problem when 2 threads try to create the shmem |
243 // (a file) at exactly the same time, since create both creates the | 243 // (a file) at exactly the same time, since create both creates the |
244 // file and zerofills it. We solve the problem for this unit test | 244 // file and zerofills it. We solve the problem for this unit test |
245 // (make it not flaky) by starting with 1 thread, then | 245 // (make it not flaky) by starting with 1 thread, then |
246 // intentionally don't clean up its shmem before running with | 246 // intentionally don't clean up its shmem before running with |
247 // kNumThreads. | 247 // kNumThreads. |
248 | 248 |
249 int threadcounts[] = { 1, kNumThreads }; | 249 int threadcounts[] = { 1, kNumThreads }; |
250 for (size_t i = 0; i < arraysize(threadcounts); i++) { | 250 for (size_t i = 0; i < arraysize(threadcounts); i++) { |
251 int numthreads = threadcounts[i]; | 251 int numthreads = threadcounts[i]; |
252 scoped_array<PlatformThreadHandle> thread_handles; | 252 scoped_ptr<PlatformThreadHandle[]> thread_handles; |
253 scoped_array<MultipleThreadMain*> thread_delegates; | 253 scoped_ptr<MultipleThreadMain*[]> thread_delegates; |
254 | 254 |
255 thread_handles.reset(new PlatformThreadHandle[numthreads]); | 255 thread_handles.reset(new PlatformThreadHandle[numthreads]); |
256 thread_delegates.reset(new MultipleThreadMain*[numthreads]); | 256 thread_delegates.reset(new MultipleThreadMain*[numthreads]); |
257 | 257 |
258 // Spawn the threads. | 258 // Spawn the threads. |
259 for (int16 index = 0; index < numthreads; index++) { | 259 for (int16 index = 0; index < numthreads; index++) { |
260 PlatformThreadHandle pth; | 260 PlatformThreadHandle pth; |
261 thread_delegates[index] = new MultipleThreadMain(index); | 261 thread_delegates[index] = new MultipleThreadMain(index); |
262 EXPECT_TRUE(PlatformThread::Create(0, thread_delegates[index], &pth)); | 262 EXPECT_TRUE(PlatformThread::Create(0, thread_delegates[index], &pth)); |
263 thread_handles[index] = pth; | 263 thread_handles[index] = pth; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 302 |
303 // Allocate private (unique) shared memory with an empty string for a | 303 // Allocate private (unique) shared memory with an empty string for a |
304 // name. Make sure several of them don't point to the same thing as | 304 // name. Make sure several of them don't point to the same thing as |
305 // we might expect if the names are equal. | 305 // we might expect if the names are equal. |
306 TEST(SharedMemoryTest, AnonymousPrivate) { | 306 TEST(SharedMemoryTest, AnonymousPrivate) { |
307 int i, j; | 307 int i, j; |
308 int count = 4; | 308 int count = 4; |
309 bool rv; | 309 bool rv; |
310 const uint32 kDataSize = 8192; | 310 const uint32 kDataSize = 8192; |
311 | 311 |
312 scoped_array<SharedMemory> memories(new SharedMemory[count]); | 312 scoped_ptr<SharedMemory[]> memories(new SharedMemory[count]); |
313 scoped_array<int*> pointers(new int*[count]); | 313 scoped_ptr<int*[]> pointers(new int*[count]); |
314 ASSERT_TRUE(memories.get()); | 314 ASSERT_TRUE(memories.get()); |
315 ASSERT_TRUE(pointers.get()); | 315 ASSERT_TRUE(pointers.get()); |
316 | 316 |
317 for (i = 0; i < count; i++) { | 317 for (i = 0; i < count; i++) { |
318 rv = memories[i].CreateAndMapAnonymous(kDataSize); | 318 rv = memories[i].CreateAndMapAnonymous(kDataSize); |
319 EXPECT_TRUE(rv); | 319 EXPECT_TRUE(rv); |
320 int *ptr = static_cast<int*>(memories[i].memory()); | 320 int *ptr = static_cast<int*>(memories[i].memory()); |
321 EXPECT_TRUE(ptr); | 321 EXPECT_TRUE(ptr); |
322 pointers[i] = ptr; | 322 pointers[i] = ptr; |
323 } | 323 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 SharedMemoryProcessTest::CleanUp(); | 469 SharedMemoryProcessTest::CleanUp(); |
470 } | 470 } |
471 | 471 |
472 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 472 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
473 return SharedMemoryProcessTest::TaskTestMain(); | 473 return SharedMemoryProcessTest::TaskTestMain(); |
474 } | 474 } |
475 | 475 |
476 #endif // !OS_IOS | 476 #endif // !OS_IOS |
477 | 477 |
478 } // namespace base | 478 } // namespace base |
OLD | NEW |