summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/util/highres_timer_unittest.cc
blob: 225726217d9776b6a6fd77dec30ebf5f8abb7548 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// High resolution timer unit tests.

#include "base/basictypes.h"
#include "base/platform_thread.h"
#include "build/build_config.h"
#include "chrome/browser/sync/util/highres_timer.h"
#include "testing/gtest/include/gtest/gtest.h"

// These unittests have proven to be flaky on buildbot. While we don't want
// them breaking the build, we still build them to guard against bitrot.
// On dev machines during local builds we can enable them.
TEST(HighresTimer, DISABLED_MillisecondClock) {
  HighresTimer timer;

  // Note: this could fail if we context switch between initializing the timer
  // and here. Very unlikely however.
  EXPECT_TRUE(0 == timer.GetElapsedMs());
  timer.Start();
  uint64 half_ms = HighresTimer::GetTimerFrequency() / 2000;
  // Busy wait for half a millisecond.
  while (timer.start_ticks() + half_ms > HighresTimer::GetCurrentTicks()) {
    // Nothing
  }
  EXPECT_TRUE(1 == timer.GetElapsedMs());
}

TEST(HighresTimer, DISABLED_SecondClock) {
  HighresTimer timer;

  EXPECT_TRUE(0 == timer.GetElapsedSec());
  PlatformThread::Sleep(250);
  EXPECT_TRUE(0 == timer.GetElapsedSec());
  EXPECT_TRUE(230 <= timer.GetElapsedMs());
  EXPECT_TRUE(270 >= timer.GetElapsedMs());
  PlatformThread::Sleep(251);
  EXPECT_TRUE(1 == timer.GetElapsedSec());
}