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

Side by Side Diff: base/memory/shared_memory_unittest.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove redundant base:: prefix Created 4 years, 8 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
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/memory/shared_memory.h"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 #include <stdint.h> 8 #include <stdint.h>
7 9
10 #include <memory>
11
8 #include "base/atomicops.h" 12 #include "base/atomicops.h"
9 #include "base/macros.h" 13 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/shared_memory.h"
12 #include "base/memory/shared_memory_handle.h" 14 #include "base/memory/shared_memory_handle.h"
13 #include "base/process/kill.h" 15 #include "base/process/kill.h"
14 #include "base/rand_util.h" 16 #include "base/rand_util.h"
15 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
16 #include "base/sys_info.h" 18 #include "base/sys_info.h"
17 #include "base/test/multiprocess_test.h" 19 #include "base/test/multiprocess_test.h"
18 #include "base/threading/platform_thread.h" 20 #include "base/threading/platform_thread.h"
19 #include "base/time/time.h" 21 #include "base/time/time.h"
20 #include "build/build_config.h" 22 #include "build/build_config.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // On POSIX we have a problem when 2 threads try to create the shmem 241 // On POSIX we have a problem when 2 threads try to create the shmem
240 // (a file) at exactly the same time, since create both creates the 242 // (a file) at exactly the same time, since create both creates the
241 // file and zerofills it. We solve the problem for this unit test 243 // file and zerofills it. We solve the problem for this unit test
242 // (make it not flaky) by starting with 1 thread, then 244 // (make it not flaky) by starting with 1 thread, then
243 // intentionally don't clean up its shmem before running with 245 // intentionally don't clean up its shmem before running with
244 // kNumThreads. 246 // kNumThreads.
245 247
246 int threadcounts[] = { 1, kNumThreads }; 248 int threadcounts[] = { 1, kNumThreads };
247 for (size_t i = 0; i < arraysize(threadcounts); i++) { 249 for (size_t i = 0; i < arraysize(threadcounts); i++) {
248 int numthreads = threadcounts[i]; 250 int numthreads = threadcounts[i];
249 scoped_ptr<PlatformThreadHandle[]> thread_handles; 251 std::unique_ptr<PlatformThreadHandle[]> thread_handles;
250 scoped_ptr<MultipleThreadMain*[]> thread_delegates; 252 std::unique_ptr<MultipleThreadMain* []> thread_delegates;
251 253
252 thread_handles.reset(new PlatformThreadHandle[numthreads]); 254 thread_handles.reset(new PlatformThreadHandle[numthreads]);
253 thread_delegates.reset(new MultipleThreadMain*[numthreads]); 255 thread_delegates.reset(new MultipleThreadMain*[numthreads]);
254 256
255 // Spawn the threads. 257 // Spawn the threads.
256 for (int16_t index = 0; index < numthreads; index++) { 258 for (int16_t index = 0; index < numthreads; index++) {
257 PlatformThreadHandle pth; 259 PlatformThreadHandle pth;
258 thread_delegates[index] = new MultipleThreadMain(index); 260 thread_delegates[index] = new MultipleThreadMain(index);
259 EXPECT_TRUE(PlatformThread::Create(0, thread_delegates[index], &pth)); 261 EXPECT_TRUE(PlatformThread::Create(0, thread_delegates[index], &pth));
260 thread_handles[index] = pth; 262 thread_handles[index] = pth;
(...skipping 11 matching lines...) Expand all
272 274
273 // Allocate private (unique) shared memory with an empty string for a 275 // Allocate private (unique) shared memory with an empty string for a
274 // name. Make sure several of them don't point to the same thing as 276 // name. Make sure several of them don't point to the same thing as
275 // we might expect if the names are equal. 277 // we might expect if the names are equal.
276 TEST(SharedMemoryTest, AnonymousPrivate) { 278 TEST(SharedMemoryTest, AnonymousPrivate) {
277 int i, j; 279 int i, j;
278 int count = 4; 280 int count = 4;
279 bool rv; 281 bool rv;
280 const uint32_t kDataSize = 8192; 282 const uint32_t kDataSize = 8192;
281 283
282 scoped_ptr<SharedMemory[]> memories(new SharedMemory[count]); 284 std::unique_ptr<SharedMemory[]> memories(new SharedMemory[count]);
283 scoped_ptr<int*[]> pointers(new int*[count]); 285 std::unique_ptr<int* []> pointers(new int*[count]);
284 ASSERT_TRUE(memories.get()); 286 ASSERT_TRUE(memories.get());
285 ASSERT_TRUE(pointers.get()); 287 ASSERT_TRUE(pointers.get());
286 288
287 for (i = 0; i < count; i++) { 289 for (i = 0; i < count; i++) {
288 rv = memories[i].CreateAndMapAnonymous(kDataSize); 290 rv = memories[i].CreateAndMapAnonymous(kDataSize);
289 EXPECT_TRUE(rv); 291 EXPECT_TRUE(rv);
290 int* ptr = static_cast<int*>(memories[i].memory()); 292 int* ptr = static_cast<int*>(memories[i].memory());
291 EXPECT_TRUE(ptr); 293 EXPECT_TRUE(ptr);
292 pointers[i] = ptr; 294 pointers[i] = ptr;
293 } 295 }
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 memory.Close(); 706 memory.Close();
705 SharedMemoryProcessTest::CleanUp(); 707 SharedMemoryProcessTest::CleanUp();
706 } 708 }
707 709
708 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 710 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
709 return SharedMemoryProcessTest::TaskTestMain(); 711 return SharedMemoryProcessTest::TaskTestMain();
710 } 712 }
711 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 713 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
712 714
713 } // namespace base 715 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698