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

Side by Side Diff: base/shared_memory_unittest.cc

Issue 3026055: Cleanup in base. This moves the implementation (and a bunch of header file... (Closed) Base URL: svn://chrome-svn/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
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"
7 #include "base/platform_thread.h" 6 #include "base/platform_thread.h"
8 #include "base/scoped_nsautorelease_pool.h" 7 #include "base/scoped_nsautorelease_pool.h"
9 #include "base/shared_memory.h" 8 #include "base/shared_memory.h"
10 #include "base/scoped_ptr.h" 9 #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"
12 13
13 static const int kNumThreads = 5; 14 static const int kNumThreads = 5;
14 static const int kNumTasks = 5; 15 static const int kNumTasks = 5;
15 16
16 namespace base { 17 namespace base {
17 18
18 namespace { 19 namespace {
19 20
20 // Each thread will open the shared memory. Each thread will take a different 4 21 // Each thread will open the shared memory. Each thread will take a different 4
21 // byte int pointer, and keep changing it, with some small pauses in between. 22 // 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
264 if (i == j) 265 if (i == j)
265 EXPECT_EQ(100, pointers[j][0]); 266 EXPECT_EQ(100, pointers[j][0]);
266 else 267 else
267 EXPECT_EQ(0, pointers[j][0]); 268 EXPECT_EQ(0, pointers[j][0]);
268 } 269 }
269 } 270 }
270 271
271 for (int i = 0; i < count; i++) { 272 for (int i = 0; i < count; i++) {
272 memories[i].Close(); 273 memories[i].Close();
273 } 274 }
274
275 } 275 }
276 276
277
278 // On POSIX it is especially important we test shmem across processes, 277 // On POSIX it is especially important we test shmem across processes,
279 // not just across threads. But the test is enabled on all platforms. 278 // not just across threads. But the test is enabled on all platforms.
280 class SharedMemoryProcessTest : public MultiProcessTest { 279 class SharedMemoryProcessTest : public base::MultiProcessTest {
281 public: 280 public:
282 281
283 static void CleanUp() { 282 static void CleanUp() {
284 SharedMemory memory; 283 SharedMemory memory;
285 memory.Delete(s_test_name_); 284 memory.Delete(s_test_name_);
286 } 285 }
287 286
288 static int TaskTestMain() { 287 static int TaskTestMain() {
289 int errors = 0; 288 int errors = 0;
290 ScopedNSAutoreleasePool pool; // noop if not OSX 289 ScopedNSAutoreleasePool pool; // noop if not OSX
(...skipping 28 matching lines...) Expand all
319 }; 318 };
320 319
321 const wchar_t* const SharedMemoryProcessTest::s_test_name_ = L"MPMem"; 320 const wchar_t* const SharedMemoryProcessTest::s_test_name_ = L"MPMem";
322 321
323 322
324 TEST_F(SharedMemoryProcessTest, Tasks) { 323 TEST_F(SharedMemoryProcessTest, Tasks) {
325 SharedMemoryProcessTest::CleanUp(); 324 SharedMemoryProcessTest::CleanUp();
326 325
327 base::ProcessHandle handles[kNumTasks]; 326 base::ProcessHandle handles[kNumTasks];
328 for (int index = 0; index < kNumTasks; ++index) { 327 for (int index = 0; index < kNumTasks; ++index) {
329 handles[index] = SpawnChild("SharedMemoryTestMain"); 328 handles[index] = SpawnChild("SharedMemoryTestMain", false);
330 } 329 }
331 330
332 int exit_code = 0; 331 int exit_code = 0;
333 for (int index = 0; index < kNumTasks; ++index) { 332 for (int index = 0; index < kNumTasks; ++index) {
334 EXPECT_TRUE(base::WaitForExitCode(handles[index], &exit_code)); 333 EXPECT_TRUE(base::WaitForExitCode(handles[index], &exit_code));
335 EXPECT_TRUE(exit_code == 0); 334 EXPECT_TRUE(exit_code == 0);
336 } 335 }
337 336
338 SharedMemoryProcessTest::CleanUp(); 337 SharedMemoryProcessTest::CleanUp();
339 } 338 }
340 339
341 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 340 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
342 return SharedMemoryProcessTest::TaskTestMain(); 341 return SharedMemoryProcessTest::TaskTestMain();
343 } 342 }
344 343
345
346 } // namespace base 344 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698