Zachary Turner 1e021a162e [Windows] Remove the #include <eh.h> hack.
Prior to MSVC 2015 we had to manually include this header any
time we were going to include <thread> or <future> due to a
bug in MSVC's STL implementation.  This has been fixed in MSVC
for some time now, and we require VS 2015 minimum, so we can
remove this across all subprojects.

llvm-svn: 296906
2017-03-03 20:21:59 +00:00

67 lines
1.9 KiB
C++

//===-- TimerTest.cpp -------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Core/Timer.h"
#include "gtest/gtest.h"
#include "lldb/Utility/StreamString.h"
#include <thread>
using namespace lldb_private;
TEST(TimerTest, CategoryTimes) {
Timer::ResetCategoryTimes();
{
Timer t("CAT1", "");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
StreamString ss;
Timer::DumpCategoryTimes(&ss);
double seconds;
ASSERT_EQ(1, sscanf(ss.GetData(), "%lf sec for CAT1", &seconds));
EXPECT_LT(0.001, seconds);
EXPECT_GT(0.1, seconds);
}
TEST(TimerTest, CategoryTimesNested) {
Timer::ResetCategoryTimes();
{
Timer t1("CAT1", "");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
Timer t2("CAT1", "");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
StreamString ss;
Timer::DumpCategoryTimes(&ss);
double seconds;
ASSERT_EQ(1, sscanf(ss.GetData(), "%lf sec for CAT1", &seconds));
EXPECT_LT(0.002, seconds);
EXPECT_GT(0.2, seconds);
}
TEST(TimerTest, CategoryTimes2) {
Timer::ResetCategoryTimes();
{
Timer t1("CAT1", "");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
Timer t2("CAT2", "");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
StreamString ss;
Timer::DumpCategoryTimes(&ss);
double seconds1, seconds2;
ASSERT_EQ(2, sscanf(ss.GetData(), "%lf sec for CAT1%*[\n ]%lf sec for CAT2",
&seconds1, &seconds2))
<< "String: " << ss.GetData();
EXPECT_LT(0.01, seconds1);
EXPECT_GT(1, seconds1);
EXPECT_LT(0.001, seconds2);
EXPECT_GT(0.1, seconds2);
}