From 70cca3663a0ea6c290b55c290ba5eb1f1c9db572 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 10 Aug 2018 18:55:46 +0000 Subject: Add proxy for syscall time This CL adds a proxy, FXSYS_time, for the time syscall, so that a testing mechanism can be implemented. Specically there is now a flag for pdfium_test, --time=, that allows setting the time since the epoch that will be returned. This plumbed all the way down into the proxy and allows for stable results for tests that depend on getting the current time. There are other places in the code base that will need to be patched like this, that will be dealt with in follow on CLs. BUG=pdfium:1104 Change-Id: I2de185f8d47abe46704dd579c13a54948b7f81e0 Reviewed-on: https://pdfium-review.googlesource.com/39750 Reviewed-by: Tom Sepez Reviewed-by: Lei Zhang Commit-Queue: Ryan Harrison --- core/fxcrt/fx_extension.cpp | 14 ++++++++++++++ core/fxcrt/fx_extension.h | 3 +++ 2 files changed, 17 insertions(+) (limited to 'core') diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index c754a85508..8320b45db4 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -11,6 +11,9 @@ #include #include "third_party/base/compiler_specific.h" +#include "third_party/base/ptr_util.h" + +time_t (*time_func)() = []() -> time_t { return time(nullptr); }; float FXSYS_wcstof(const wchar_t* pwsStr, int32_t iLength, int32_t* pUsedLen) { ASSERT(pwsStr); @@ -167,3 +170,14 @@ size_t FXSYS_ToUTF16BE(uint32_t unicode, char* buf) { FXSYS_IntToFourHexChars(0xDC00 + unicode % 0x400, buf + 4); return 8; } + +void FXSYS_SetTimeFunction(time_t (*func)()) { + time_func = func ? func : []() -> time_t { return time(nullptr); }; +} + +time_t FXSYS_time(time_t* tloc) { + time_t ret_val = time_func(); + if (tloc) + *tloc = ret_val; + return ret_val; +} diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h index dcdd64e1fc..6a49ee1116 100644 --- a/core/fxcrt/fx_extension.h +++ b/core/fxcrt/fx_extension.h @@ -109,4 +109,7 @@ bool FXSYS_SafeLT(const T& lhs, const T& rhs) { return lhs < rhs; } +void FXSYS_SetTimeFunction(time_t (*func)()); +time_t FXSYS_time(time_t* tloc); + #endif // CORE_FXCRT_FX_EXTENSION_H_ -- cgit v1.2.3