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

Side by Side Diff: base/tracked_objects_unittest.cc

Issue 8437018: Test 32bit time in tracked_object (Closed) Base URL: svn://chrome-svn/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 | « no previous file | 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) 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 "\"file_name\":\"AnotherFileName\"," 598 "\"file_name\":\"AnotherFileName\","
599 "\"function_name\":\"DifferentLives\"," 599 "\"function_name\":\"DifferentLives\","
600 "\"line_number\":999" 600 "\"line_number\":999"
601 "}" 601 "}"
602 "}" 602 "}"
603 "]" 603 "]"
604 "}"; 604 "}";
605 EXPECT_EQ(one_line_result, json); 605 EXPECT_EQ(one_line_result, json);
606 } 606 }
607 607
608 TEST_F(TrackedObjectsTest, TrackedTimerMilliseconds) {
609 // First make sure we basicallly transfer simple milliseconds values as
610 // expected. Most critically, things should not become null.
611 int32 kSomeMilliseconds = 243; // Some example times.
612 int64 kReallyBigMilliseconds = (1LL << 35) + kSomeMilliseconds;
613
614 TrackedTime some = TrackedTime() +
615 Duration::FromMilliseconds(kSomeMilliseconds);
616 EXPECT_EQ(kSomeMilliseconds, (some - TrackedTime()).InMilliseconds());
617 EXPECT_FALSE(some.is_null());
618
619 // Now create a big time, to check that it is wrapped modulo 2^32.
620 base::TimeTicks big = base::TimeTicks() +
621 base::TimeDelta::FromMilliseconds(kReallyBigMilliseconds);
622 EXPECT_EQ(kReallyBigMilliseconds, (big - base::TimeTicks()).InMilliseconds());
623
624 TrackedTime wrapped_big(big);
625 #if defined(USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS)
626 // Expect wrapping at 32 bits.
627 EXPECT_EQ(kSomeMilliseconds, (wrapped_big - TrackedTime()).InMilliseconds());
628 #else // !USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS)
629 // Expect no wrapping at 32 bits.
630 EXPECT_EQ(kReallyBigMilliseconds,
631 (wrapped_big - TrackedTime()).InMilliseconds());
632 #endif // USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS)
633 }
634
635 TEST_F(TrackedObjectsTest, TrackedTimerDuration) {
636 int kFirstMilliseconds = 793;
637 int kSecondMilliseconds = 14889;
638
639 Duration first = Duration::FromMilliseconds(kFirstMilliseconds);
640 Duration second = Duration::FromMilliseconds(kSecondMilliseconds);
641
642 EXPECT_EQ(kFirstMilliseconds, first.InMilliseconds());
643 EXPECT_EQ(kSecondMilliseconds, second.InMilliseconds());
644
645 Duration sum = first + second;
646 EXPECT_EQ(kFirstMilliseconds + kSecondMilliseconds, sum.InMilliseconds());
647 }
648
649 TEST_F(TrackedObjectsTest, TrackedTimerVsTicks) {
650 // Make sure that our 32 bit timer is aligned with the TimeTicks() timer.
651
652 // First get a 64 bit timer (which should not be null).
653 base::TimeTicks ticks_before = base::TimeTicks::Now();
654 EXPECT_FALSE(ticks_before.is_null());
655
656 // Then get a 32 bit timer that can be be null when it wraps.
ramant (doing other things) 2011/11/02 01:17:12 nit: be be -> be
jar (doing other things) 2011/11/02 01:34:50 Done.
657 TrackedTime now = TrackedTime::Now();
658
659 // Then get a bracketing time.
660 base::TimeTicks ticks_after = base::TimeTicks::Now();
661 EXPECT_FALSE(ticks_after.is_null());
662
663 // No make sure that we bracketed our tracked time nicely.
ramant (doing other things) 2011/11/02 01:17:12 nit: No -> Now
jar (doing other things) 2011/11/02 01:34:50 Done.
664 Duration before = now - TrackedTime(ticks_before);
665 EXPECT_LE(0, before.InMilliseconds());
666 Duration after = now - TrackedTime(ticks_after);
667 EXPECT_GE(0, after.InMilliseconds());
668 }
669
670 TEST_F(TrackedObjectsTest, TrackedTimerDisabled) {
671 // Check to be sure disabling the collection of data induces a null time
672 // (which we know will return much faster).
673 if (!ThreadData::InitializeAndSetTrackingStatus(false))
674 return;
675 // Since we disabled tracking, we should get a null response.
676 TrackedTime track_now = ThreadData::Now();
677 EXPECT_TRUE(track_now.is_null());
678 }
679
680 TEST_F(TrackedObjectsTest, TrackedTimerEnabled) {
681 if (!ThreadData::InitializeAndSetTrackingStatus(true))
682 return;
683 // Make sure that when we enable tracking, we get a real timer result.
684
685 // First get a 64 bit timer (which should not be null).
686 base::TimeTicks ticks_before = base::TimeTicks::Now();
687 EXPECT_FALSE(ticks_before.is_null());
688
689 // Then get a 32 bit timer that can be be null when it wraps.
ramant (doing other things) 2011/11/02 01:17:12 nit: TrackedTimerVsTicks -> TrackedTime Vs TimeTic
jar (doing other things) 2011/11/02 01:34:50 Done.
690 // Crtical difference from TrackedTimerVsTicks, is that we use ThreadData::.
691 TrackedTime now = ThreadData::Now();
692
693 // Then get a bracketing time.
694 base::TimeTicks ticks_after = base::TimeTicks::Now();
695 EXPECT_FALSE(ticks_after.is_null());
696
697 // No make sure that we bracketed our tracked time nicely.
ramant (doing other things) 2011/11/02 01:17:12 nit: No -> Now
jar (doing other things) 2011/11/02 01:34:50 Done.
698 Duration before = now - TrackedTime(ticks_before);
699 EXPECT_LE(0, before.InMilliseconds());
700 Duration after = now - TrackedTime(ticks_after);
701 EXPECT_GE(0, after.InMilliseconds());
702 }
703
704
608 } // namespace tracked_objects 705 } // namespace tracked_objects
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698