| 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/stats_table.h" | 7 #include "base/stats_table.h" |
| 8 #include "base/stats_counters.h" | 8 #include "base/stats_counters.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/multiprocess_func_list.h" |
| 11 | 12 |
| 12 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
| 13 #include <process.h> | 14 #include <process.h> |
| 14 #include <windows.h> | 15 #include <windows.h> |
| 15 #endif | 16 #endif |
| 16 | 17 |
| 17 using base::TimeTicks; | 18 using base::TimeTicks; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 class StatsTableTest : public MultiProcessTest { | 21 class StatsTableTest : public MultiProcessTest { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 table.GetCounterValue(name)); | 145 table.GetCounterValue(name)); |
| 145 name = L"c:" + kCounterMixed; | 146 name = L"c:" + kCounterMixed; |
| 146 EXPECT_EQ((kMaxThreads % 2) * kThreadLoops, | 147 EXPECT_EQ((kMaxThreads % 2) * kThreadLoops, |
| 147 table.GetCounterValue(name)); | 148 table.GetCounterValue(name)); |
| 148 EXPECT_EQ(0, table.CountThreadsRegistered()); | 149 EXPECT_EQ(0, table.CountThreadsRegistered()); |
| 149 } | 150 } |
| 150 #endif // defined(OS_WIN) | 151 #endif // defined(OS_WIN) |
| 151 | 152 |
| 152 const std::wstring kTableName = L"MultipleProcessStatTable"; | 153 const std::wstring kTableName = L"MultipleProcessStatTable"; |
| 153 | 154 |
| 154 extern "C" int DYNAMIC_EXPORT StatsTableMultipleProcessMain() { | 155 MULTIPROCESS_TEST_MAIN(StatsTableMultipleProcessMain) { |
| 155 // Each process will open the shared memory and set counters | 156 // Each process will open the shared memory and set counters |
| 156 // concurrently in a loop. We'll use some pauses to | 157 // concurrently in a loop. We'll use some pauses to |
| 157 // mixup the scheduling. | 158 // mixup the scheduling. |
| 158 | 159 |
| 159 StatsTable table(kTableName, 0, 0); | 160 StatsTable table(kTableName, 0, 0); |
| 160 StatsTable::set_current(&table); | 161 StatsTable::set_current(&table); |
| 161 StatsCounter zero_counter(kCounterZero); | 162 StatsCounter zero_counter(kCounterZero); |
| 162 StatsCounter lucky13_counter(kCounter1313); | 163 StatsCounter lucky13_counter(kCounter1313); |
| 163 StatsCounter increment_counter(kCounterIncrement); | 164 StatsCounter increment_counter(kCounterIncrement); |
| 164 StatsCounter decrement_counter(kCounterDecrement); | 165 StatsCounter decrement_counter(kCounterDecrement); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 StatsScope<StatsCounterTimer> timer(foo); | 373 StatsScope<StatsCounterTimer> timer(foo); |
| 373 StatsScope<StatsRate> timer2(bar); | 374 StatsScope<StatsRate> timer2(bar); |
| 374 PlatformThread::Sleep(500); | 375 PlatformThread::Sleep(500); |
| 375 } | 376 } |
| 376 EXPECT_LE(1000, table.GetCounterValue(L"t:foo")); | 377 EXPECT_LE(1000, table.GetCounterValue(L"t:foo")); |
| 377 EXPECT_LE(1000, table.GetCounterValue(L"t:bar")); | 378 EXPECT_LE(1000, table.GetCounterValue(L"t:bar")); |
| 378 EXPECT_EQ(2, table.GetCounterValue(L"c:bar")); | 379 EXPECT_EQ(2, table.GetCounterValue(L"c:bar")); |
| 379 } | 380 } |
| 380 | 381 |
| 381 } // namespace | 382 } // namespace |
| OLD | NEW |