mirror of
https://github.com/RPCS3/llvm.git
synced 2026-08-28 05:10:05 -04:00
bca3cda284
Summary: std::chrono mostly covers the functionality of llvm::sys::TimeValue and lldb_private::TimeValue. This header adds a bit of utility functions and typedefs, which make the usage of the library and porting code from TimeValues easier. Rationale: - TimePoint typedef - precision of system_clock is implementation defined - using a well-defined precision helps maintain consistency between platforms, makes it interact better with existing TimeValue classes, and avoids cases there a time point is implicitly convertible to a specific precision on some platforms but not on others. - system_clock::to_time_t only accepts time_points with the default system precision (even though time_t has only second precision on all platforms we support). To avoid the need for explicit casts, I have added a toTimeT() wrapper function. toTimePoint(time_t) was not strictly necessary, but I have added it for symmetry. Reviewers: zturner, mehdi_amini Subscribers: beanz, mgorny, llvm-commits, modocache Differential Revision: https://reviews.llvm.org/D25416 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284590 91177308-0d34-0410-b5e6-96231b3b80d8
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
//===- llvm/unittest/Support/TimeValueTest.cpp - Time Value tests ---------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "gtest/gtest.h"
|
|
#include "llvm/Support/TimeValue.h"
|
|
#include <time.h>
|
|
|
|
using namespace llvm;
|
|
namespace {
|
|
|
|
TEST(TimeValue, time_t) {
|
|
sys::TimeValue now = sys::TimeValue::now();
|
|
time_t now_t = time(nullptr);
|
|
EXPECT_TRUE(std::abs(static_cast<long>(now_t - now.toEpochTime())) < 2);
|
|
}
|
|
|
|
TEST(TimeValue, Win32FILETIME) {
|
|
uint64_t epoch_as_filetime = 0x19DB1DED53E8000ULL;
|
|
uint32_t ns = 765432100;
|
|
sys::TimeValue epoch;
|
|
|
|
// FILETIME has 100ns of intervals.
|
|
uint64_t ft1970 = epoch_as_filetime + ns / 100;
|
|
epoch.fromWin32Time(ft1970);
|
|
|
|
// The "seconds" part in Posix time may be expected as zero.
|
|
EXPECT_EQ(0u, epoch.toEpochTime());
|
|
EXPECT_EQ(ns, static_cast<uint32_t>(epoch.nanoseconds()));
|
|
|
|
// Confirm it reversible.
|
|
EXPECT_EQ(ft1970, epoch.toWin32Time());
|
|
}
|
|
|
|
TEST(TimeValue, Chrono) {
|
|
sys::TimeValue TV;
|
|
TV.fromEpochTime(0);
|
|
sys::TimePoint<> TP = TV;
|
|
EXPECT_EQ(0u, sys::toTimeT(TP));
|
|
|
|
TP += std::chrono::seconds(47);
|
|
TV = TP;
|
|
EXPECT_EQ(47u, TV.toEpochTime());
|
|
}
|
|
}
|