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

Side by Side Diff: third_party/tcmalloc/chromium/src/tests/profile-handler_unittest.cc

Issue 9667026: Revert 126020 - Experiment for updating the tcmalloc chromium branch to r144 (gperftools 2.0). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 2009 Google Inc. All Rights Reserved. 1 // Copyright 2009 Google Inc. All Rights Reserved.
2 // Author: Nabeel Mian (nabeelmian@google.com) 2 // Author: Nabeel Mian (nabeelmian@google.com)
3 // Chris Demetriou (cgd@google.com) 3 // Chris Demetriou (cgd@google.com)
4 // 4 //
5 // This file contains the unit tests for profile-handler.h interface. 5 // This file contains the unit tests for profile-handler.h interface.
6 //
7 // It is linked into three separate unit tests:
8 // profile-handler_unittest tests basic functionality
9 // profile-handler_disable_test tests that the profiler
10 // is disabled with --install_signal_handlers=false
11 // profile-handler_conflict_test tests that the profiler
12 // is disabled when a SIGPROF handler is registered before InitGoogle.
13 6
14 #include "config.h" 7 #include "config.h"
15 #include "profile-handler.h" 8 #include "profile-handler.h"
16 9
17 #include <assert.h> 10 #include <assert.h>
18 #include <pthread.h> 11 #include <pthread.h>
19 #include <sys/time.h> 12 #include <sys/time.h>
20 #include <time.h> 13 #include <time.h>
21 #include "base/logging.h" 14 #include "base/logging.h"
22 #include "base/simple_mutex.h" 15 #include "base/simple_mutex.h"
23 16
24 // Some helpful macros for the test class 17 // Some helpful macros for the test class
25 #define TEST_F(cls, fn) void cls :: fn() 18 #define TEST_F(cls, fn) void cls :: fn()
26 19
27 // Do we expect the profiler to be enabled?
28 DEFINE_bool(test_profiler_enabled, true,
29 "expect profiler to be enabled during tests");
30
31 // Should we look at the kernel signal handler settings during the test?
32 // Not if we're in conflict_test, because we can't distinguish its nop
33 // handler from the real one.
34 DEFINE_bool(test_profiler_signal_handler, true,
35 "check profiler signal handler during tests");
36
37 namespace { 20 namespace {
38 21
39 // TODO(csilvers): error-checking on the pthreads routines 22 // TODO(csilvers): error-checking on the pthreads routines
40 class Thread { 23 class Thread {
41 public: 24 public:
42 Thread() : joinable_(false) { } 25 Thread() : joinable_(false) { }
43 void SetJoinable(bool value) { joinable_ = value; } 26 void SetJoinable(bool value) { joinable_ = value; }
44 void Start() { 27 void Start() {
45 pthread_attr_t attr; 28 pthread_attr_t attr;
46 pthread_attr_init(&attr); 29 pthread_attr_init(&attr);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 ProfileHandlerGetState(&state); 271 ProfileHandlerGetState(&state);
289 return state.interrupts; 272 return state.interrupts;
290 } 273 }
291 274
292 // Verifies that a callback is correctly registered and receiving 275 // Verifies that a callback is correctly registered and receiving
293 // profile ticks. 276 // profile ticks.
294 void VerifyRegistration(const int& tick_counter) { 277 void VerifyRegistration(const int& tick_counter) {
295 // Check the callback count. 278 // Check the callback count.
296 EXPECT_GT(GetCallbackCount(), 0); 279 EXPECT_GT(GetCallbackCount(), 0);
297 // Check that the profile timer is enabled. 280 // Check that the profile timer is enabled.
298 EXPECT_EQ(FLAGS_test_profiler_enabled, IsTimerEnabled()); 281 EXPECT_TRUE(IsTimerEnabled());
299 // Check that the signal handler is enabled. 282 // Check that the signal handler is enabled.
300 if (FLAGS_test_profiler_signal_handler) { 283 EXPECT_TRUE(IsSignalEnabled());
301 EXPECT_EQ(FLAGS_test_profiler_enabled, IsSignalEnabled());
302 }
303 uint64 interrupts_before = GetInterruptCount(); 284 uint64 interrupts_before = GetInterruptCount();
304 // Sleep for a bit and check that tick counter is making progress. 285 // Sleep for a bit and check that tick counter is making progress.
305 int old_tick_count = tick_counter; 286 int old_tick_count = tick_counter;
306 Delay(kSleepInterval); 287 Delay(kSleepInterval);
307 int new_tick_count = tick_counter; 288 int new_tick_count = tick_counter;
289 EXPECT_GT(new_tick_count, old_tick_count);
308 uint64 interrupts_after = GetInterruptCount(); 290 uint64 interrupts_after = GetInterruptCount();
309 if (FLAGS_test_profiler_enabled) { 291 EXPECT_GT(interrupts_after, interrupts_before);
310 EXPECT_GT(new_tick_count, old_tick_count);
311 EXPECT_GT(interrupts_after, interrupts_before);
312 } else {
313 EXPECT_EQ(new_tick_count, old_tick_count);
314 EXPECT_EQ(interrupts_after, interrupts_before);
315 }
316 } 292 }
317 293
318 // Verifies that a callback is not receiving profile ticks. 294 // Verifies that a callback is not receiving profile ticks.
319 void VerifyUnregistration(const int& tick_counter) { 295 void VerifyUnregistration(const int& tick_counter) {
320 // Sleep for a bit and check that tick counter is not making progress. 296 // Sleep for a bit and check that tick counter is not making progress.
321 int old_tick_count = tick_counter; 297 int old_tick_count = tick_counter;
322 Delay(kSleepInterval); 298 Delay(kSleepInterval);
323 int new_tick_count = tick_counter; 299 int new_tick_count = tick_counter;
324 EXPECT_EQ(old_tick_count, new_tick_count); 300 EXPECT_EQ(old_tick_count, new_tick_count);
325 // If no callbacks, signal handler and shared timer should be disabled. 301 // If no callbacks, signal handler and shared timer should be disabled.
326 if (GetCallbackCount() == 0) { 302 if (GetCallbackCount() == 0) {
327 if (FLAGS_test_profiler_signal_handler) { 303 EXPECT_FALSE(IsSignalEnabled());
328 EXPECT_FALSE(IsSignalEnabled());
329 }
330 if (timer_separate_) { 304 if (timer_separate_) {
331 EXPECT_TRUE(IsTimerEnabled()); 305 EXPECT_TRUE(IsTimerEnabled());
332 } else { 306 } else {
333 EXPECT_FALSE(IsTimerEnabled()); 307 EXPECT_FALSE(IsTimerEnabled());
334 } 308 }
335 } 309 }
336 } 310 }
337 311
338 // Verifies that the SIGPROF/SIGALRM interrupt handler is disabled and the 312 // Verifies that the SIGPROF/SIGALRM interrupt handler is disabled and the
339 // timer, if shared, is disabled. Expects the worker to be running. 313 // timer, if shared, is disabled. Expects the worker to be running.
340 void VerifyDisabled() { 314 void VerifyDisabled() {
341 // Check that the signal handler is disabled. 315 // Check that the signal handler is disabled.
342 if (FLAGS_test_profiler_signal_handler) { 316 EXPECT_FALSE(IsSignalEnabled());
343 EXPECT_FALSE(IsSignalEnabled());
344 }
345 // Check that the callback count is 0. 317 // Check that the callback count is 0.
346 EXPECT_EQ(0, GetCallbackCount()); 318 EXPECT_EQ(0, GetCallbackCount());
347 // Check that the timer is disabled if shared, enabled otherwise. 319 // Check that the timer is disabled if shared, enabled otherwise.
348 if (timer_separate_) { 320 if (timer_separate_) {
349 EXPECT_TRUE(IsTimerEnabled()); 321 EXPECT_TRUE(IsTimerEnabled());
350 } else { 322 } else {
351 EXPECT_FALSE(IsTimerEnabled()); 323 EXPECT_FALSE(IsTimerEnabled());
352 } 324 }
353 // Verify that the ProfileHandler is not accumulating profile ticks. 325 // Verify that the ProfileHandler is not accumulating profile ticks.
354 uint64 interrupts_before = GetInterruptCount(); 326 uint64 interrupts_before = GetInterruptCount();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 // Register a callback and check that profile ticks are being delivered. 458 // Register a callback and check that profile ticks are being delivered.
487 int tick_count; 459 int tick_count;
488 RegisterCallback(&tick_count); 460 RegisterCallback(&tick_count);
489 EXPECT_EQ(1, GetCallbackCount()); 461 EXPECT_EQ(1, GetCallbackCount());
490 VerifyRegistration(tick_count); 462 VerifyRegistration(tick_count);
491 463
492 // Register a second thread and verify that timer and signal handler are 464 // Register a second thread and verify that timer and signal handler are
493 // correctly enabled. 465 // correctly enabled.
494 RegisterThread(); 466 RegisterThread();
495 EXPECT_EQ(1, GetCallbackCount()); 467 EXPECT_EQ(1, GetCallbackCount());
496 EXPECT_EQ(FLAGS_test_profiler_enabled, IsTimerEnabled()); 468 EXPECT_TRUE(IsTimerEnabled());
497 if (FLAGS_test_profiler_signal_handler) { 469 EXPECT_TRUE(IsSignalEnabled());
498 EXPECT_EQ(FLAGS_test_profiler_enabled, IsSignalEnabled());
499 }
500 } 470 }
501 471
502 } // namespace 472 } // namespace
503 473
504 int main(int argc, char** argv) { 474 int main(int argc, char** argv) {
505 return ProfileHandlerTest::RUN_ALL_TESTS(); 475 return ProfileHandlerTest::RUN_ALL_TESTS();
506 } 476 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698