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

Side by Side Diff: base/tracked_objects_unittest.cc

Issue 8496008: Revert 108752 - Support tracking of IPC messages as tasks in profiler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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/tracked_objects.cc ('k') | ipc/ipc_message_macros.h » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Test of classes in the tracked_objects.h classes. 5 // Test of classes in the tracked_objects.h classes.
6 6
7 #include "base/tracked_objects.h" 7 #include "base/tracked_objects.h"
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 "\"file_name\":\"AnotherFileName\"," 627 "\"file_name\":\"AnotherFileName\","
628 "\"function_name\":\"DifferentLives\"," 628 "\"function_name\":\"DifferentLives\","
629 "\"line_number\":999" 629 "\"line_number\":999"
630 "}" 630 "}"
631 "}" 631 "}"
632 "]" 632 "]"
633 "}"; 633 "}";
634 EXPECT_EQ(one_line_result, json); 634 EXPECT_EQ(one_line_result, json);
635 } 635 }
636 636
637 TEST_F(TrackedObjectsTest, TrackedTimerMilliseconds) {
638 // First make sure we basicallly transfer simple milliseconds values as
639 // expected. Most critically, things should not become null.
640 int32 kSomeMilliseconds = 243; // Some example times.
641 int64 kReallyBigMilliseconds = (1LL << 35) + kSomeMilliseconds;
642
643 TrackedTime some = TrackedTime() +
644 Duration::FromMilliseconds(kSomeMilliseconds);
645 EXPECT_EQ(kSomeMilliseconds, (some - TrackedTime()).InMilliseconds());
646 EXPECT_FALSE(some.is_null());
647
648 // Now create a big time, to check that it is wrapped modulo 2^32.
649 base::TimeTicks big = base::TimeTicks() +
650 base::TimeDelta::FromMilliseconds(kReallyBigMilliseconds);
651 EXPECT_EQ(kReallyBigMilliseconds, (big - base::TimeTicks()).InMilliseconds());
652
653 TrackedTime wrapped_big(big);
654 #if defined(USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS)
655 // Expect wrapping at 32 bits.
656 EXPECT_EQ(kSomeMilliseconds, (wrapped_big - TrackedTime()).InMilliseconds());
657 #else // !USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS)
658 // Expect no wrapping at 32 bits.
659 EXPECT_EQ(kReallyBigMilliseconds,
660 (wrapped_big - TrackedTime()).InMilliseconds());
661 #endif // USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS)
662 }
663
664 TEST_F(TrackedObjectsTest, TrackedTimerDuration) {
665 int kFirstMilliseconds = 793;
666 int kSecondMilliseconds = 14889;
667
668 Duration first = Duration::FromMilliseconds(kFirstMilliseconds);
669 Duration second = Duration::FromMilliseconds(kSecondMilliseconds);
670
671 EXPECT_EQ(kFirstMilliseconds, first.InMilliseconds());
672 EXPECT_EQ(kSecondMilliseconds, second.InMilliseconds());
673
674 Duration sum = first + second;
675 EXPECT_EQ(kFirstMilliseconds + kSecondMilliseconds, sum.InMilliseconds());
676 }
677
678 TEST_F(TrackedObjectsTest, TrackedTimerVsTimeTicks) {
679 // Make sure that our 32 bit timer is aligned with the TimeTicks() timer.
680
681 // First get a 64 bit timer (which should not be null).
682 base::TimeTicks ticks_before = base::TimeTicks::Now();
683 EXPECT_FALSE(ticks_before.is_null());
684
685 // Then get a 32 bit timer that can be be null when it wraps.
686 TrackedTime now = TrackedTime::Now();
687
688 // Then get a bracketing time.
689 base::TimeTicks ticks_after = base::TimeTicks::Now();
690 EXPECT_FALSE(ticks_after.is_null());
691
692 // Now make sure that we bracketed our tracked time nicely.
693 Duration before = now - TrackedTime(ticks_before);
694 EXPECT_LE(0, before.InMilliseconds());
695 Duration after = now - TrackedTime(ticks_after);
696 EXPECT_GE(0, after.InMilliseconds());
697 }
698
699 TEST_F(TrackedObjectsTest, TrackedTimerDisabled) {
700 // Check to be sure disabling the collection of data induces a null time
701 // (which we know will return much faster).
702 if (!ThreadData::InitializeAndSetTrackingStatus(false))
703 return;
704 // Since we disabled tracking, we should get a null response.
705 TrackedTime track_now = ThreadData::Now();
706 EXPECT_TRUE(track_now.is_null());
707 }
708
709 TEST_F(TrackedObjectsTest, TrackedTimerEnabled) {
710 if (!ThreadData::InitializeAndSetTrackingStatus(true))
711 return;
712 // Make sure that when we enable tracking, we get a real timer result.
713
714 // First get a 64 bit timer (which should not be null).
715 base::TimeTicks ticks_before = base::TimeTicks::Now();
716 EXPECT_FALSE(ticks_before.is_null());
717
718 // Then get a 32 bit timer that can be null when it wraps.
719 // Crtical difference from the TrackedTimerVsTimeTicks test, is that we use
720 // ThreadData::Now(). It can sometimes return the null time.
721 TrackedTime now = ThreadData::Now();
722
723 // Then get a bracketing time.
724 base::TimeTicks ticks_after = base::TimeTicks::Now();
725 EXPECT_FALSE(ticks_after.is_null());
726
727 // Now make sure that we bracketed our tracked time nicely.
728 Duration before = now - TrackedTime(ticks_before);
729 EXPECT_LE(0, before.InMilliseconds());
730 Duration after = now - TrackedTime(ticks_after);
731 EXPECT_GE(0, after.InMilliseconds());
732 }
733
637 734
638 } // namespace tracked_objects 735 } // namespace tracked_objects
OLDNEW
« no previous file with comments | « base/tracked_objects.cc ('k') | ipc/ipc_message_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698