Author: labath Date: Thu Nov 3 05:07:47 2016 New Revision: 285892 URL: http://llvm.org/viewvc/llvm-project?rev=285892&view=rev Log: Fix Timer unit test
I did not take into account that the output of the Dump function will be non-deterministic. Fix that by increasing of the times, this also makes the test check that the dump function sorts the output. Modified: lldb/trunk/unittests/Core/TimerTest.cpp Modified: lldb/trunk/unittests/Core/TimerTest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/TimerTest.cpp?rev=285892&r1=285891&r2=285892&view=diff ============================================================================== --- lldb/trunk/unittests/Core/TimerTest.cpp (original) +++ lldb/trunk/unittests/Core/TimerTest.cpp Thu Nov 3 05:07:47 2016 @@ -40,10 +40,8 @@ TEST(TimerTest, CategoryTimesNested) { { Timer t1("CAT1", ""); std::this_thread::sleep_for(std::chrono::milliseconds(10)); - { - Timer t2("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); @@ -57,19 +55,18 @@ 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)); - { - 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)); - EXPECT_LT(0.001, seconds1); - EXPECT_GT(0.1, seconds1); + &seconds1, &seconds2)) + << "String: " << ss.GetString(); + EXPECT_LT(0.01, seconds1); + EXPECT_GT(1, seconds1); EXPECT_LT(0.001, seconds2); EXPECT_GT(0.1, seconds2); } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits