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

Side by Side Diff: base/shared_memory_unittest.cc

Issue 3035062: Revert 55400 - Cleanup in base. This moves the implementation (and a bunch of... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « base/process_util_unittest.cc ('k') | base/stats_table_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "base/multiprocess_test.h"
6 #include "base/platform_thread.h" 7 #include "base/platform_thread.h"
7 #include "base/scoped_nsautorelease_pool.h" 8 #include "base/scoped_nsautorelease_pool.h"
8 #include "base/shared_memory.h" 9 #include "base/shared_memory.h"
9 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
10 #include "base/test/multiprocess_test.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/multiprocess_func_list.h"
13 12
14 static const int kNumThreads = 5; 13 static const int kNumThreads = 5;
15 static const int kNumTasks = 5; 14 static const int kNumTasks = 5;
16 15
17 namespace base { 16 namespace base {
18 17
19 namespace { 18 namespace {
20 19
21 // Each thread will open the shared memory. Each thread will take a different 4 20 // Each thread will open the shared memory. Each thread will take a different 4
22 // byte int pointer, and keep changing it, with some small pauses in between. 21 // byte int pointer, and keep changing it, with some small pauses in between.
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (i == j) 264 if (i == j)
266 EXPECT_EQ(100, pointers[j][0]); 265 EXPECT_EQ(100, pointers[j][0]);
267 else 266 else
268 EXPECT_EQ(0, pointers[j][0]); 267 EXPECT_EQ(0, pointers[j][0]);
269 } 268 }
270 } 269 }
271 270
272 for (int i = 0; i < count; i++) { 271 for (int i = 0; i < count; i++) {
273 memories[i].Close(); 272 memories[i].Close();
274 } 273 }
274
275 } 275 }
276 276
277
277 // On POSIX it is especially important we test shmem across processes, 278 // On POSIX it is especially important we test shmem across processes,
278 // not just across threads. But the test is enabled on all platforms. 279 // not just across threads. But the test is enabled on all platforms.
279 class SharedMemoryProcessTest : public base::MultiProcessTest { 280 class SharedMemoryProcessTest : public MultiProcessTest {
280 public: 281 public:
281 282
282 static void CleanUp() { 283 static void CleanUp() {
283 SharedMemory memory; 284 SharedMemory memory;
284 memory.Delete(s_test_name_); 285 memory.Delete(s_test_name_);
285 } 286 }
286 287
287 static int TaskTestMain() { 288 static int TaskTestMain() {
288 int errors = 0; 289 int errors = 0;
289 ScopedNSAutoreleasePool pool; // noop if not OSX 290 ScopedNSAutoreleasePool pool; // noop if not OSX
(...skipping 28 matching lines...) Expand all
318 }; 319 };
319 320
320 const wchar_t* const SharedMemoryProcessTest::s_test_name_ = L"MPMem"; 321 const wchar_t* const SharedMemoryProcessTest::s_test_name_ = L"MPMem";
321 322
322 323
323 TEST_F(SharedMemoryProcessTest, Tasks) { 324 TEST_F(SharedMemoryProcessTest, Tasks) {
324 SharedMemoryProcessTest::CleanUp(); 325 SharedMemoryProcessTest::CleanUp();
325 326
326 base::ProcessHandle handles[kNumTasks]; 327 base::ProcessHandle handles[kNumTasks];
327 for (int index = 0; index < kNumTasks; ++index) { 328 for (int index = 0; index < kNumTasks; ++index) {
328 handles[index] = SpawnChild("SharedMemoryTestMain", false); 329 handles[index] = SpawnChild("SharedMemoryTestMain");
329 } 330 }
330 331
331 int exit_code = 0; 332 int exit_code = 0;
332 for (int index = 0; index < kNumTasks; ++index) { 333 for (int index = 0; index < kNumTasks; ++index) {
333 EXPECT_TRUE(base::WaitForExitCode(handles[index], &exit_code)); 334 EXPECT_TRUE(base::WaitForExitCode(handles[index], &exit_code));
334 EXPECT_TRUE(exit_code == 0); 335 EXPECT_TRUE(exit_code == 0);
335 } 336 }
336 337
337 SharedMemoryProcessTest::CleanUp(); 338 SharedMemoryProcessTest::CleanUp();
338 } 339 }
339 340
340 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 341 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
341 return SharedMemoryProcessTest::TaskTestMain(); 342 return SharedMemoryProcessTest::TaskTestMain();
342 } 343 }
343 344
345
344 } // namespace base 346 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util_unittest.cc ('k') | base/stats_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698