llvm.org GIT mirror llvm / b0a5bae
Fix TimeValue::now() on Unix. TimeValue()::now().toEpochTime() is supposed to be the same as time(), but it wasn't, because toEpoch subtracted PosixZeroTime, but now() didn't add PosixZeroTime! Add a unittest to check this works. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94178 91177308-0d34-0410-b5e6-96231b3b80d8 Torok Edwin 9 years ago
2 changed file(s) with 17 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
4747 }
4848
4949 return TimeValue(
50 static_cast( the_time.tv_sec ),
50 static_cast( the_time.tv_sec + PosixZeroTime.seconds_ ),
5151 static_cast( the_time.tv_usec *
5252 NANOSECONDS_PER_MICROSECOND ) );
5353 }
0 //===- llvm/unittest/Support/System.cpp - System tests --===//
1 #include "gtest/gtest.h"
2 #include "llvm/System/TimeValue.h"
3 #include
4
5 using namespace llvm;
6 namespace {
7 class SystemTest : public ::testing::Test {
8 };
9
10 TEST_F(SystemTest, TimeValue) {
11 sys::TimeValue now = sys::TimeValue::now();
12 time_t now_t = time(NULL);
13 EXPECT_TRUE(abs(now_t - now.toEpochTime()) < 2);
14 }
15 }