BuildBot fix, compiler complains about array decay to pointer
[llvm-core.git] / unittests / Support / TimerTest.cpp
bloba92ecf1ac5102582fba2c91491e9ac51eca4a98c
1 //===- unittests/TimerTest.cpp - Timer tests ------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/Timer.h"
11 #include "gtest/gtest.h"
13 #if _WIN32
14 #include <windows.h>
15 #else
16 #include <time.h>
17 #endif
19 using namespace llvm;
21 namespace {
23 // FIXME: Put this somewhere in Support, it's also used in LockFileManager.
24 void SleepMS() {
25 #if _WIN32
26 Sleep(1);
27 #else
28 struct timespec Interval;
29 Interval.tv_sec = 0;
30 Interval.tv_nsec = 1000000;
31 nanosleep(&Interval, nullptr);
32 #endif
35 TEST(Timer, Additivity) {
36 Timer T1("T1", "T1");
38 EXPECT_TRUE(T1.isInitialized());
40 T1.startTimer();
41 T1.stopTimer();
42 auto TR1 = T1.getTotalTime();
44 T1.startTimer();
45 SleepMS();
46 T1.stopTimer();
47 auto TR2 = T1.getTotalTime();
49 EXPECT_TRUE(TR1 < TR2);
52 TEST(Timer, CheckIfTriggered) {
53 Timer T1("T1", "T1");
55 EXPECT_FALSE(T1.hasTriggered());
56 T1.startTimer();
57 EXPECT_TRUE(T1.hasTriggered());
58 T1.stopTimer();
59 EXPECT_TRUE(T1.hasTriggered());
61 T1.clear();
62 EXPECT_FALSE(T1.hasTriggered());
65 } // end anon namespace