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

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

Issue 9311003: Update the tcmalloc chromium branch to r144 (gperftools 2.0), and merge chromium-specific changes. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebasec 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.
6 13
7 #include "config.h" 14 #include "config.h"
8 #include "profile-handler.h" 15 #include "profile-handler.h"
9 16
10 #include <assert.h> 17 #include <assert.h>
11 #include <pthread.h> 18 #include <pthread.h>
12 #include <sys/time.h> 19 #include <sys/time.h>
13 #include <time.h> 20 #include <time.h>
14 #include "base/logging.h" 21 #include "base/logging.h"
15 #include "base/simple_mutex.h" 22 #include "base/simple_mutex.h"
16 23
17 // Some helpful macros for the test class 24 // Some helpful macros for the test class
18 #define TEST_F(cls, fn) void cls :: fn() 25 #define TEST_F(cls, fn) void cls :: fn()
19 26
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
20 namespace { 37 namespace {
21 38
22 // TODO(csilvers): error-checking on the pthreads routines 39 // TODO(csilvers): error-checking on the pthreads routines
23 class Thread { 40 class Thread {
24 public: 41 public:
25 Thread() : joinable_(false) { } 42 Thread() : joinable_(false) { }
26 void SetJoinable(bool value) { joinable_ = value; } 43 void SetJoinable(bool value) { joinable_ = value; }
27 void Start() { 44 void Start() {
28 pthread_attr_t attr; 45 pthread_attr_t attr;
29 pthread_attr_init(&attr); 46 pthread_attr_init(&attr);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 ProfileHandlerGetState(&state); 288 ProfileHandlerGetState(&state);
272 return state.interrupts; 289 return state.interrupts;
273 } 290 }
274 291
275 // Verifies that a callback is correctly registered and receiving 292 // Verifies that a callback is correctly registered and receiving
276 // profile ticks. 293 // profile ticks.
277 void VerifyRegistration(const int& tick_counter) { 294 void VerifyRegistration(const int& tick_counter) {
278 // Check the callback count. 295 // Check the callback count.
279 EXPECT_GT(GetCallbackCount(), 0); 296 EXPECT_GT(GetCallbackCount(), 0);
280 // Check that the profile timer is enabled. 297 // Check that the profile timer is enabled.
281 EXPECT_TRUE(IsTimerEnabled()); 298 EXPECT_EQ(FLAGS_test_profiler_enabled, IsTimerEnabled());
282 // Check that the signal handler is enabled. 299 // Check that the signal handler is enabled.
283 EXPECT_TRUE(IsSignalEnabled()); 300 if (FLAGS_test_profiler_signal_handler) {
301 EXPECT_EQ(FLAGS_test_profiler_enabled, IsSignalEnabled());
302 }
284 uint64 interrupts_before = GetInterruptCount(); 303 uint64 interrupts_before = GetInterruptCount();
285 // Sleep for a bit and check that tick counter is making progress. 304 // Sleep for a bit and check that tick counter is making progress.
286 int old_tick_count = tick_counter; 305 int old_tick_count = tick_counter;
287 Delay(kSleepInterval); 306 Delay(kSleepInterval);
288 int new_tick_count = tick_counter; 307 int new_tick_count = tick_counter;
289 EXPECT_GT(new_tick_count, old_tick_count);
290 uint64 interrupts_after = GetInterruptCount(); 308 uint64 interrupts_after = GetInterruptCount();
291 EXPECT_GT(interrupts_after, interrupts_before); 309 if (FLAGS_test_profiler_enabled) {
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 }
292 } 316 }
293 317
294 // Verifies that a callback is not receiving profile ticks. 318 // Verifies that a callback is not receiving profile ticks.
295 void VerifyUnregistration(const int& tick_counter) { 319 void VerifyUnregistration(const int& tick_counter) {
296 // Sleep for a bit and check that tick counter is not making progress. 320 // Sleep for a bit and check that tick counter is not making progress.
297 int old_tick_count = tick_counter; 321 int old_tick_count = tick_counter;
298 Delay(kSleepInterval); 322 Delay(kSleepInterval);
299 int new_tick_count = tick_counter; 323 int new_tick_count = tick_counter;
300 EXPECT_EQ(old_tick_count, new_tick_count); 324 EXPECT_EQ(old_tick_count, new_tick_count);
301 // If no callbacks, signal handler and shared timer should be disabled. 325 // If no callbacks, signal handler and shared timer should be disabled.
302 if (GetCallbackCount() == 0) { 326 if (GetCallbackCount() == 0) {
303 EXPECT_FALSE(IsSignalEnabled()); 327 if (FLAGS_test_profiler_signal_handler) {
328 EXPECT_FALSE(IsSignalEnabled());
329 }
304 if (timer_separate_) { 330 if (timer_separate_) {
305 EXPECT_TRUE(IsTimerEnabled()); 331 EXPECT_TRUE(IsTimerEnabled());
306 } else { 332 } else {
307 EXPECT_FALSE(IsTimerEnabled()); 333 EXPECT_FALSE(IsTimerEnabled());
308 } 334 }
309 } 335 }
310 } 336 }
311 337
312 // Verifies that the SIGPROF/SIGALRM interrupt handler is disabled and the 338 // Verifies that the SIGPROF/SIGALRM interrupt handler is disabled and the
313 // timer, if shared, is disabled. Expects the worker to be running. 339 // timer, if shared, is disabled. Expects the worker to be running.
314 void VerifyDisabled() { 340 void VerifyDisabled() {
315 // Check that the signal handler is disabled. 341 // Check that the signal handler is disabled.
316 EXPECT_FALSE(IsSignalEnabled()); 342 if (FLAGS_test_profiler_signal_handler) {
343 EXPECT_FALSE(IsSignalEnabled());
344 }
317 // Check that the callback count is 0. 345 // Check that the callback count is 0.
318 EXPECT_EQ(0, GetCallbackCount()); 346 EXPECT_EQ(0, GetCallbackCount());
319 // Check that the timer is disabled if shared, enabled otherwise. 347 // Check that the timer is disabled if shared, enabled otherwise.
320 if (timer_separate_) { 348 if (timer_separate_) {
321 EXPECT_TRUE(IsTimerEnabled()); 349 EXPECT_TRUE(IsTimerEnabled());
322 } else { 350 } else {
323 EXPECT_FALSE(IsTimerEnabled()); 351 EXPECT_FALSE(IsTimerEnabled());
324 } 352 }
325 // Verify that the ProfileHandler is not accumulating profile ticks. 353 // Verify that the ProfileHandler is not accumulating profile ticks.
326 uint64 interrupts_before = GetInterruptCount(); 354 uint64 interrupts_before = GetInterruptCount();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // Register a callback and check that profile ticks are being delivered. 486 // Register a callback and check that profile ticks are being delivered.
459 int tick_count; 487 int tick_count;
460 RegisterCallback(&tick_count); 488 RegisterCallback(&tick_count);
461 EXPECT_EQ(1, GetCallbackCount()); 489 EXPECT_EQ(1, GetCallbackCount());
462 VerifyRegistration(tick_count); 490 VerifyRegistration(tick_count);
463 491
464 // Register a second thread and verify that timer and signal handler are 492 // Register a second thread and verify that timer and signal handler are
465 // correctly enabled. 493 // correctly enabled.
466 RegisterThread(); 494 RegisterThread();
467 EXPECT_EQ(1, GetCallbackCount()); 495 EXPECT_EQ(1, GetCallbackCount());
468 EXPECT_TRUE(IsTimerEnabled()); 496 EXPECT_EQ(FLAGS_test_profiler_enabled, IsTimerEnabled());
469 EXPECT_TRUE(IsSignalEnabled()); 497 if (FLAGS_test_profiler_signal_handler) {
498 EXPECT_EQ(FLAGS_test_profiler_enabled, IsSignalEnabled());
499 }
470 } 500 }
471 501
472 } // namespace 502 } // namespace
473 503
474 int main(int argc, char** argv) { 504 int main(int argc, char** argv) {
475 return ProfileHandlerTest::RUN_ALL_TESTS(); 505 return ProfileHandlerTest::RUN_ALL_TESTS();
476 } 506 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698