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

Side by Side Diff: base/stats_table_unittest.cc

Issue 126100: Fix StatsTable::RegisterThread so that it doesn't crash if shared memory... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 6 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/stats_table.cc ('k') | no next file » | 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/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 21 matching lines...) Expand all
32 TEST_F(StatsTableTest, VerifySlots) { 32 TEST_F(StatsTableTest, VerifySlots) {
33 const std::string kTableName = "VerifySlotsStatTable"; 33 const std::string kTableName = "VerifySlotsStatTable";
34 const int kMaxThreads = 1; 34 const int kMaxThreads = 1;
35 const int kMaxCounter = 5; 35 const int kMaxCounter = 5;
36 DeleteShmem(kTableName); 36 DeleteShmem(kTableName);
37 StatsTable table(kTableName, kMaxThreads, kMaxCounter); 37 StatsTable table(kTableName, kMaxThreads, kMaxCounter);
38 38
39 // Register a single thread. 39 // Register a single thread.
40 std::string thread_name = "mainThread"; 40 std::string thread_name = "mainThread";
41 int slot_id = table.RegisterThread(thread_name); 41 int slot_id = table.RegisterThread(thread_name);
42 EXPECT_TRUE(slot_id); 42 EXPECT_NE(slot_id, 0);
43 43
44 // Fill up the table with counters. 44 // Fill up the table with counters.
45 std::string counter_base_name = "counter"; 45 std::string counter_base_name = "counter";
46 for (int index=0; index < kMaxCounter; index++) { 46 for (int index=0; index < kMaxCounter; index++) {
47 std::string counter_name = counter_base_name; 47 std::string counter_name = counter_base_name;
48 StringAppendF(&counter_name, "counter.ctr%d", index); 48 StringAppendF(&counter_name, "counter.ctr%d", index);
49 int counter_id = table.FindCounter(counter_name); 49 int counter_id = table.FindCounter(counter_name);
50 EXPECT_GT(counter_id, 0); 50 EXPECT_GT(counter_id, 0);
51 } 51 }
52 52
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 const int kMaxThreads = 20; 254 const int kMaxThreads = 20;
255 const int kMaxCounter = 5; 255 const int kMaxCounter = 5;
256 DeleteShmem(kTableName); 256 DeleteShmem(kTableName);
257 StatsTable table(kTableName, kMaxThreads, kMaxCounter); 257 StatsTable table(kTableName, kMaxThreads, kMaxCounter);
258 StatsTable::set_current(&table); 258 StatsTable::set_current(&table);
259 259
260 MockStatsCounter foo("foo"); 260 MockStatsCounter foo("foo");
261 261
262 // Test initial state. 262 // Test initial state.
263 EXPECT_TRUE(foo.Enabled()); 263 EXPECT_TRUE(foo.Enabled());
264 EXPECT_NE(foo.Pointer(), static_cast<int*>(0)); 264 ASSERT_NE(foo.Pointer(), static_cast<int*>(0));
265 EXPECT_EQ(0, *(foo.Pointer()));
265 EXPECT_EQ(0, table.GetCounterValue("c:foo")); 266 EXPECT_EQ(0, table.GetCounterValue("c:foo"));
266 EXPECT_EQ(0, *(foo.Pointer()));
267 267
268 // Test Increment. 268 // Test Increment.
269 while(*(foo.Pointer()) < 123) foo.Increment(); 269 while(*(foo.Pointer()) < 123) foo.Increment();
270 EXPECT_EQ(123, table.GetCounterValue("c:foo")); 270 EXPECT_EQ(123, table.GetCounterValue("c:foo"));
271 foo.Add(0); 271 foo.Add(0);
272 EXPECT_EQ(123, table.GetCounterValue("c:foo")); 272 EXPECT_EQ(123, table.GetCounterValue("c:foo"));
273 foo.Add(-1); 273 foo.Add(-1);
274 EXPECT_EQ(122, table.GetCounterValue("c:foo")); 274 EXPECT_EQ(122, table.GetCounterValue("c:foo"));
275 275
276 // Test Set. 276 // Test Set.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 PlatformThread::Sleep(500); 398 PlatformThread::Sleep(500);
399 } 399 }
400 EXPECT_LE(1000, table.GetCounterValue("t:foo")); 400 EXPECT_LE(1000, table.GetCounterValue("t:foo"));
401 EXPECT_LE(1000, table.GetCounterValue("t:bar")); 401 EXPECT_LE(1000, table.GetCounterValue("t:bar"));
402 EXPECT_EQ(2, table.GetCounterValue("c:bar")); 402 EXPECT_EQ(2, table.GetCounterValue("c:bar"));
403 403
404 DeleteShmem(kTableName); 404 DeleteShmem(kTableName);
405 } 405 }
406 406
407 } // namespace base 407 } // namespace base
OLDNEW
« no previous file with comments | « base/stats_table.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698