| 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/stats_table.h" | 8 #include "base/stats_table.h" |
| 9 #include "base/stats_counters.h" | 9 #include "base/stats_counters.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.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 #include "testing/multiprocess_func_list.h" |
| 13 | 13 |
| 14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 15 #include <process.h> | 15 #include <process.h> |
| 16 #include <windows.h> | 16 #include <windows.h> |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 using base::TimeTicks; | 19 namespace base { |
| 20 | 20 |
| 21 namespace { | |
| 22 class StatsTableTest : public MultiProcessTest { | 21 class StatsTableTest : public MultiProcessTest { |
| 23 }; | 22 }; |
| 24 | 23 |
| 25 // Open a StatsTable and verify that we can write to each of the | 24 // Open a StatsTable and verify that we can write to each of the |
| 26 // locations in the table. | 25 // locations in the table. |
| 27 TEST_F(StatsTableTest, VerifySlots) { | 26 TEST_F(StatsTableTest, VerifySlots) { |
| 28 const std::wstring kTableName = L"VerifySlotsStatTable"; | 27 const std::wstring kTableName = L"VerifySlotsStatTable"; |
| 29 const int kMaxThreads = 1; | 28 const int kMaxThreads = 1; |
| 30 const int kMaxCounter = 5; | 29 const int kMaxCounter = 5; |
| 31 StatsTable table(kTableName, kMaxThreads, kMaxCounter); | 30 StatsTable table(kTableName, kMaxThreads, kMaxCounter); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 ProcessHandle procs[kMaxProcs]; | 191 ProcessHandle procs[kMaxProcs]; |
| 193 | 192 |
| 194 // Spawn the processes. | 193 // Spawn the processes. |
| 195 for (int16 index = 0; index < kMaxProcs; index++) { | 194 for (int16 index = 0; index < kMaxProcs; index++) { |
| 196 procs[index] = this->SpawnChild(L"StatsTableMultipleProcessMain"); | 195 procs[index] = this->SpawnChild(L"StatsTableMultipleProcessMain"); |
| 197 EXPECT_NE(static_cast<ProcessHandle>(NULL), procs[index]); | 196 EXPECT_NE(static_cast<ProcessHandle>(NULL), procs[index]); |
| 198 } | 197 } |
| 199 | 198 |
| 200 // Wait for the processes to finish. | 199 // Wait for the processes to finish. |
| 201 for (int index = 0; index < kMaxProcs; index++) { | 200 for (int index = 0; index < kMaxProcs; index++) { |
| 202 EXPECT_TRUE(process_util::WaitForSingleProcess(procs[index], 60 * 1000)); | 201 EXPECT_TRUE(WaitForSingleProcess(procs[index], 60 * 1000)); |
| 203 } | 202 } |
| 204 | 203 |
| 205 StatsCounter zero_counter(kCounterZero); | 204 StatsCounter zero_counter(kCounterZero); |
| 206 StatsCounter lucky13_counter(kCounter1313); | 205 StatsCounter lucky13_counter(kCounter1313); |
| 207 StatsCounter increment_counter(kCounterIncrement); | 206 StatsCounter increment_counter(kCounterIncrement); |
| 208 StatsCounter decrement_counter(kCounterDecrement); | 207 StatsCounter decrement_counter(kCounterDecrement); |
| 209 | 208 |
| 210 // Verify the various counters are correct. | 209 // Verify the various counters are correct. |
| 211 std::wstring name; | 210 std::wstring name; |
| 212 name = L"c:" + kCounterZero; | 211 name = L"c:" + kCounterZero; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 { | 373 { |
| 375 StatsScope<StatsCounterTimer> timer(foo); | 374 StatsScope<StatsCounterTimer> timer(foo); |
| 376 StatsScope<StatsRate> timer2(bar); | 375 StatsScope<StatsRate> timer2(bar); |
| 377 PlatformThread::Sleep(500); | 376 PlatformThread::Sleep(500); |
| 378 } | 377 } |
| 379 EXPECT_LE(1000, table.GetCounterValue(L"t:foo")); | 378 EXPECT_LE(1000, table.GetCounterValue(L"t:foo")); |
| 380 EXPECT_LE(1000, table.GetCounterValue(L"t:bar")); | 379 EXPECT_LE(1000, table.GetCounterValue(L"t:bar")); |
| 381 EXPECT_EQ(2, table.GetCounterValue(L"c:bar")); | 380 EXPECT_EQ(2, table.GetCounterValue(L"c:bar")); |
| 382 } | 381 } |
| 383 | 382 |
| 384 } // namespace | 383 } // namespace base |
| OLD | NEW |