| OLD | NEW |
| 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/multiprocess_test.h" | 5 #include "base/multiprocess_test.h" |
| 6 #include "base/platform_thread.h" | 6 #include "base/platform_thread.h" |
| 7 #include "base/simple_thread.h" | 7 #include "base/simple_thread.h" |
| 8 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
| 9 #include "base/stats_table.h" | 9 #include "base/stats_table.h" |
| 10 #include "base/stats_counters.h" | 10 #include "base/stats_counters.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 decrement_counter.Decrement(); | 101 decrement_counter.Decrement(); |
| 102 if (id_ % 2) | 102 if (id_ % 2) |
| 103 mixed_counter.Decrement(); | 103 mixed_counter.Decrement(); |
| 104 else | 104 else |
| 105 mixed_counter.Increment(); | 105 mixed_counter.Increment(); |
| 106 PlatformThread::Sleep(index % 10); // short wait | 106 PlatformThread::Sleep(index % 10); // short wait |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Create a few threads and have them poke on their counters. | 110 // Create a few threads and have them poke on their counters. |
| 111 // TODO(maruel): http://crbug.com/10611 |
| 111 TEST_F(StatsTableTest, MultipleThreads) { | 112 TEST_F(StatsTableTest, MultipleThreads) { |
| 113 #if !defined(OS_MAC) |
| 112 // Create a stats table. | 114 // Create a stats table. |
| 113 const std::string kTableName = "MultipleThreadStatTable"; | 115 const std::string kTableName = "MultipleThreadStatTable"; |
| 114 const int kMaxThreads = 20; | 116 const int kMaxThreads = 20; |
| 115 const int kMaxCounter = 5; | 117 const int kMaxCounter = 5; |
| 116 DeleteShmem(kTableName); | 118 DeleteShmem(kTableName); |
| 117 StatsTable table(kTableName, kMaxThreads, kMaxCounter); | 119 StatsTable table(kTableName, kMaxThreads, kMaxCounter); |
| 118 StatsTable::set_current(&table); | 120 StatsTable::set_current(&table); |
| 119 | 121 |
| 120 EXPECT_EQ(0, table.CountThreadsRegistered()); | 122 EXPECT_EQ(0, table.CountThreadsRegistered()); |
| 121 | 123 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 table.GetCounterValue(name)); | 156 table.GetCounterValue(name)); |
| 155 name = "c:" + kCounterDecrement; | 157 name = "c:" + kCounterDecrement; |
| 156 EXPECT_EQ(-kMaxThreads * kThreadLoops, | 158 EXPECT_EQ(-kMaxThreads * kThreadLoops, |
| 157 table.GetCounterValue(name)); | 159 table.GetCounterValue(name)); |
| 158 name = "c:" + kCounterMixed; | 160 name = "c:" + kCounterMixed; |
| 159 EXPECT_EQ((kMaxThreads % 2) * kThreadLoops, | 161 EXPECT_EQ((kMaxThreads % 2) * kThreadLoops, |
| 160 table.GetCounterValue(name)); | 162 table.GetCounterValue(name)); |
| 161 EXPECT_EQ(0, table.CountThreadsRegistered()); | 163 EXPECT_EQ(0, table.CountThreadsRegistered()); |
| 162 | 164 |
| 163 DeleteShmem(kTableName); | 165 DeleteShmem(kTableName); |
| 166 #else // !defined(OS_MAC) |
| 167 NOT_IMPLEMENTED(); |
| 168 #endif |
| 164 } | 169 } |
| 165 | 170 |
| 166 const std::string kMPTableName = "MultipleProcessStatTable"; | 171 const std::string kMPTableName = "MultipleProcessStatTable"; |
| 167 | 172 |
| 168 MULTIPROCESS_TEST_MAIN(StatsTableMultipleProcessMain) { | 173 MULTIPROCESS_TEST_MAIN(StatsTableMultipleProcessMain) { |
| 169 // Each process will open the shared memory and set counters | 174 // Each process will open the shared memory and set counters |
| 170 // concurrently in a loop. We'll use some pauses to | 175 // concurrently in a loop. We'll use some pauses to |
| 171 // mixup the scheduling. | 176 // mixup the scheduling. |
| 172 | 177 |
| 173 StatsTable table(kMPTableName, 0, 0); | 178 StatsTable table(kMPTableName, 0, 0); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 PlatformThread::Sleep(500); | 399 PlatformThread::Sleep(500); |
| 395 } | 400 } |
| 396 EXPECT_LE(1000, table.GetCounterValue("t:foo")); | 401 EXPECT_LE(1000, table.GetCounterValue("t:foo")); |
| 397 EXPECT_LE(1000, table.GetCounterValue("t:bar")); | 402 EXPECT_LE(1000, table.GetCounterValue("t:bar")); |
| 398 EXPECT_EQ(2, table.GetCounterValue("c:bar")); | 403 EXPECT_EQ(2, table.GetCounterValue("c:bar")); |
| 399 | 404 |
| 400 DeleteShmem(kTableName); | 405 DeleteShmem(kTableName); |
| 401 } | 406 } |
| 402 | 407 |
| 403 } // namespace base | 408 } // namespace base |
| OLD | NEW |