2015-12-22 18:36:17 +01:00
|
|
|
//===- unittests/TimerTest.cpp - Timer tests ------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/Timer.h"
|
|
|
|
#include "gtest/gtest.h"
|
2015-12-23 02:04:53 +01:00
|
|
|
|
|
|
|
#if LLVM_ON_WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
2016-04-05 22:45:04 +02:00
|
|
|
#include <time.h>
|
2015-12-23 02:04:53 +01:00
|
|
|
#endif
|
2015-12-22 18:36:17 +01:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-12-23 02:04:53 +01:00
|
|
|
// FIXME: Put this somewhere in Support, it's also used in LockFileManager.
|
|
|
|
void SleepMS() {
|
|
|
|
#if LLVM_ON_WIN32
|
|
|
|
Sleep(1);
|
|
|
|
#else
|
|
|
|
struct timespec Interval;
|
|
|
|
Interval.tv_sec = 0;
|
|
|
|
Interval.tv_nsec = 1000000;
|
|
|
|
nanosleep(&Interval, nullptr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-12-22 18:36:17 +01:00
|
|
|
TEST(Timer, Additivity) {
|
2016-11-18 20:43:18 +01:00
|
|
|
Timer T1("T1", "T1");
|
2015-12-22 18:36:17 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(T1.isInitialized());
|
|
|
|
|
|
|
|
T1.startTimer();
|
|
|
|
T1.stopTimer();
|
|
|
|
auto TR1 = T1.getTotalTime();
|
|
|
|
|
|
|
|
T1.startTimer();
|
2015-12-23 02:04:53 +01:00
|
|
|
SleepMS();
|
2015-12-22 18:36:17 +01:00
|
|
|
T1.stopTimer();
|
|
|
|
auto TR2 = T1.getTotalTime();
|
|
|
|
|
|
|
|
EXPECT_TRUE(TR1 < TR2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Timer, CheckIfTriggered) {
|
2016-11-18 20:43:18 +01:00
|
|
|
Timer T1("T1", "T1");
|
2015-12-22 18:36:17 +01:00
|
|
|
|
|
|
|
EXPECT_FALSE(T1.hasTriggered());
|
|
|
|
T1.startTimer();
|
|
|
|
EXPECT_TRUE(T1.hasTriggered());
|
|
|
|
T1.stopTimer();
|
|
|
|
EXPECT_TRUE(T1.hasTriggered());
|
|
|
|
|
|
|
|
T1.clear();
|
|
|
|
EXPECT_FALSE(T1.hasTriggered());
|
|
|
|
}
|
|
|
|
|
2016-04-05 22:45:04 +02:00
|
|
|
} // end anon namespace
|