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

Side by Side Diff: base/time_unittest.cc

Issue 10257020: Add interface to system trace clock. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 (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.h" 5 #include "base/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/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 496
497 if (delta.InMicroseconds() <= kTargetGranularityUs) 497 if (delta.InMicroseconds() <= kTargetGranularityUs)
498 success = true; 498 success = true;
499 } 499 }
500 500
501 // In high resolution mode, we expect to see the clock increment 501 // In high resolution mode, we expect to see the clock increment
502 // in intervals less than 15ms. 502 // in intervals less than 15ms.
503 EXPECT_TRUE(success); 503 EXPECT_TRUE(success);
504 } 504 }
505 505
506 TEST(TimeTicks, NowFromSystemTraceTime) {
507 #if defined(OS_WIN)
508 // HighResNow doesn't work on some systems. Since the product still works
509 // even if it doesn't work, it makes this entire test questionable.
510 if (!TimeTicks::IsHighResClockWorking())
511 return;
512 #endif
513
514 // Why do we loop here?
515 // We're trying to measure that intervals increment in a VERY small amount
516 // of time -- less than 15ms. Unfortunately, if we happen to have a
517 // context switch in the middle of our test, the context switch could easily
518 // exceed our limit. So, we iterate on this several times. As long as we're
519 // able to detect the fine-granularity timers at least once, then the test
520 // has succeeded.
521
522 const int kTargetGranularityUs = 15000; // 15ms
jar (doing other things) 2012/04/27 22:50:18 Ordinary system clocks can be set to run faster th
Sam Leffler 2012/04/27 22:56:07 This is c&p of the HighRes test; I did not write t
jar (doing other things) 2012/04/30 22:05:57 I see now. I read this as new code, and made comm
Sam Leffler 2012/04/30 22:47:58 Done.
523
524 bool success = false;
525 int retries = 100; // Arbitrary.
jar (doing other things) 2012/04/27 22:50:18 100 sounds plausible.... but it is always nice to
Sam Leffler 2012/04/27 22:56:07 I don't see the HighRes test failing so think this
526 TimeDelta delta;
527 while (!success && retries--) {
528 TimeTicks ticks_start = TimeTicks::NowFromSystemTraceTime();
529 // Loop until we can detect that the clock has changed. Non-HighRes timers
530 // will increment in chunks, e.g. 15ms. By spinning until we see a clock
531 // change, we detect the minimum time between measurements.
532 do {
533 delta = TimeTicks::NowFromSystemTraceTime() - ticks_start;
534 } while (delta.InMilliseconds() == 0);
jar (doing other things) 2012/04/27 22:50:18 Why don't you look for any change? Why does the m
Sam Leffler 2012/04/27 22:56:07 Again, this is just the existing HighRes test; if
535
536 if (delta.InMicroseconds() <= kTargetGranularityUs)
537 success = true;
538 }
539
540 // In high resolution mode, we expect to see the clock increment
541 // in intervals less than 15ms.
542 EXPECT_TRUE(success);
543 }
544
506 TEST(TimeDelta, FromAndIn) { 545 TEST(TimeDelta, FromAndIn) {
507 EXPECT_TRUE(TimeDelta::FromDays(2) == TimeDelta::FromHours(48)); 546 EXPECT_TRUE(TimeDelta::FromDays(2) == TimeDelta::FromHours(48));
508 EXPECT_TRUE(TimeDelta::FromHours(3) == TimeDelta::FromMinutes(180)); 547 EXPECT_TRUE(TimeDelta::FromHours(3) == TimeDelta::FromMinutes(180));
509 EXPECT_TRUE(TimeDelta::FromMinutes(2) == TimeDelta::FromSeconds(120)); 548 EXPECT_TRUE(TimeDelta::FromMinutes(2) == TimeDelta::FromSeconds(120));
510 EXPECT_TRUE(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000)); 549 EXPECT_TRUE(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000));
511 EXPECT_TRUE(TimeDelta::FromMilliseconds(2) == 550 EXPECT_TRUE(TimeDelta::FromMilliseconds(2) ==
512 TimeDelta::FromMicroseconds(2000)); 551 TimeDelta::FromMicroseconds(2000));
513 EXPECT_EQ(13, TimeDelta::FromDays(13).InDays()); 552 EXPECT_EQ(13, TimeDelta::FromDays(13).InDays());
514 EXPECT_EQ(13, TimeDelta::FromHours(13).InHours()); 553 EXPECT_EQ(13, TimeDelta::FromHours(13).InHours());
515 EXPECT_EQ(13, TimeDelta::FromMinutes(13).InMinutes()); 554 EXPECT_EQ(13, TimeDelta::FromMinutes(13).InMinutes());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 exploded.minute = 0; 593 exploded.minute = 0;
555 exploded.second = 0; 594 exploded.second = 0;
556 exploded.millisecond = 0; 595 exploded.millisecond = 0;
557 Time t = Time::FromUTCExploded(exploded); 596 Time t = Time::FromUTCExploded(exploded);
558 // Unix 1970 epoch. 597 // Unix 1970 epoch.
559 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); 598 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue());
560 599
561 // We can't test 1601 epoch, since the system time functions on Linux 600 // We can't test 1601 epoch, since the system time functions on Linux
562 // only compute years starting from 1900. 601 // only compute years starting from 1900.
563 } 602 }
OLDNEW
« base/time.h ('K') | « base/time_posix.cc ('k') | base/time_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698