summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-08-10 18:55:46 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-10 18:55:46 +0000
commit70cca3663a0ea6c290b55c290ba5eb1f1c9db572 (patch)
tree795a8448eb76b90320d46aca1808e6d64a6b3ae5 /samples
parent6655d95a8586c1f272d5d418bb63514abbe1d695 (diff)
downloadpdfium-70cca3663a0ea6c290b55c290ba5eb1f1c9db572.tar.xz
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 <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'samples')
-rw-r--r--samples/pdfium_test.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index 14a62a4bc4..b7538a8c6f 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -115,6 +115,7 @@ struct Options {
std::string font_directory;
int first_page = 0; // First 0-based page number to renderer.
int last_page = 0; // Last 0-based page number to renderer.
+ time_t time = -1;
};
Optional<std::string> ExpandDirectoryPath(const std::string& path) {
@@ -424,6 +425,17 @@ bool ParseCommandLine(const std::vector<std::string>& args,
}
} else if (cur_arg == "--md5") {
options->md5 = true;
+ } else if (cur_arg.size() > 7 && cur_arg.compare(0, 7, "--time=") == 0) {
+ if (options->time > -1) {
+ fprintf(stderr, "Duplicate --time argument\n");
+ return false;
+ }
+ const std::string time_string = cur_arg.substr(7);
+ std::stringstream(time_string) >> options->time;
+ if (options->time < 0) {
+ fprintf(stderr, "Invalid --time argument, must be non-negative\n");
+ return false;
+ }
} else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') {
fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str());
return false;
@@ -834,6 +846,7 @@ constexpr char kUsageString[] =
" --skp - write page images <pdf-name>.<page-number>.skp\n"
#endif
" --md5 - write output image paths and their md5 hashes to stdout.\n"
+ " --time=<number> - Seconds since the epoch to set system time.\n"
"";
} // namespace
@@ -889,6 +902,13 @@ int main(int argc, const char* argv[]) {
FSDK_SetUnSpObjProcessHandler(&unsupported_info);
+ if (options.time > -1) {
+ // This must be a static var to avoid explicit capture, so the lambda can be
+ // converted to a function ptr.
+ static time_t time_ret = options.time;
+ FSDK_SetTimeFunction([]() -> time_t { return time_ret; });
+ }
+
for (const std::string& filename : files) {
size_t file_length = 0;
std::unique_ptr<char, pdfium::FreeDeleter> file_contents =