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/time/time_unittest.cc

Issue 56973012: Implement Time::ThreadNow() on Mac. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: exclude OS_IOS from the IsThreadNowSupported check Created 7 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
« no previous file with comments | « base/time/time_mac.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/time/time.h" 5 #include "base/time/time.h"
6 6
7 #include <time.h> 7 #include <time.h>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } 632 }
633 633
634 TEST(TimeTicks, HighResNow) { 634 TEST(TimeTicks, HighResNow) {
635 HighResClockTest(&TimeTicks::HighResNow); 635 HighResClockTest(&TimeTicks::HighResNow);
636 } 636 }
637 637
638 TEST(TimeTicks, ThreadNow) { 638 TEST(TimeTicks, ThreadNow) {
639 if (TimeTicks::IsThreadNowSupported()) { 639 if (TimeTicks::IsThreadNowSupported()) {
640 TimeTicks begin = TimeTicks::Now(); 640 TimeTicks begin = TimeTicks::Now();
641 TimeTicks begin_thread = TimeTicks::ThreadNow(); 641 TimeTicks begin_thread = TimeTicks::ThreadNow();
642 // Sleep for 10 milliseconds to get the thread de-scheduled 642 // Make sure that ThreadNow value is non-zero.
643 EXPECT_GT(begin_thread, TimeTicks());
644 // Sleep for 10 milliseconds to get the thread de-scheduled.
643 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 645 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
644 TimeTicks end_thread = TimeTicks::ThreadNow(); 646 TimeTicks end_thread = TimeTicks::ThreadNow();
645 TimeTicks end = TimeTicks::Now(); 647 TimeTicks end = TimeTicks::Now();
646 TimeDelta delta = end - begin; 648 TimeDelta delta = end - begin;
647 TimeDelta delta_thread = end_thread - begin_thread; 649 TimeDelta delta_thread = end_thread - begin_thread;
650 // Make sure that some thread time have elapsed.
Nico 2013/11/05 23:20:06 s/have/has/
651 EXPECT_GT(delta_thread.InMicroseconds(), 0);
652 // But the thread time is at least 9ms less than clock time.
648 TimeDelta difference = delta - delta_thread; 653 TimeDelta difference = delta - delta_thread;
649 EXPECT_GE(difference.InMicroseconds(), 9000); 654 EXPECT_GE(difference.InMicroseconds(), 9000);
650 } 655 }
651 } 656 }
652 657
653 TEST(TimeTicks, NowFromSystemTraceTime) { 658 TEST(TimeTicks, NowFromSystemTraceTime) {
654 // Re-use HighResNow test for now since clock properties are identical. 659 // Re-use HighResNow test for now since clock properties are identical.
655 HighResClockTest(&TimeTicks::NowFromSystemTraceTime); 660 HighResClockTest(&TimeTicks::NowFromSystemTraceTime);
656 } 661 }
657 662
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 exploded.minute = 0; 711 exploded.minute = 0;
707 exploded.second = 0; 712 exploded.second = 0;
708 exploded.millisecond = 0; 713 exploded.millisecond = 0;
709 Time t = Time::FromUTCExploded(exploded); 714 Time t = Time::FromUTCExploded(exploded);
710 // Unix 1970 epoch. 715 // Unix 1970 epoch.
711 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); 716 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue());
712 717
713 // We can't test 1601 epoch, since the system time functions on Linux 718 // We can't test 1601 epoch, since the system time functions on Linux
714 // only compute years starting from 1900. 719 // only compute years starting from 1900.
715 } 720 }
OLDNEW
« no previous file with comments | « base/time/time_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698