From 8171e6f76591536e0670c76f42a31f3ccd37a90e Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Thu, 14 May 2015 18:45:28 -0700 Subject: [PATCH] win: Fix module timestamp test This test was added in https://codereview.chromium.org/1052813002. It was previously checking the timestamp from in-memory module traversal vs. the disk mtime. This is flaky (of course) because it depends on the linker writing the header and closing the file during the same time quantum. So the bots occasionally failed with: [ RUN ] ProcessInfo.Self e:\b\build\slave\chromium_win_dbg\build\crashpad\util\win\process_info_test.cc(86): error: Value of: GetTimestampForModule(GetModuleHandleW(nullptr)) Actual: 1431650338 Expected: modules[0].timestamp Which is: 1431650337 Instead, use imagehlp to pull the timestamp out of the header so that it matches the header value that will be the in-memory timestamp. R=cpu@chromium.org TBR=mark@chromium.org Review URL: https://codereview.chromium.org/1139103003 --- util/util_test.gyp | 1 + util/win/process_info_test.cc | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/util/util_test.gyp b/util/util_test.gyp index e2af6e0..2ae2c11 100644 --- a/util/util_test.gyp +++ b/util/util_test.gyp @@ -96,6 +96,7 @@ ], 'link_settings': { 'libraries': [ + '-limagehlp.lib', '-lrpcrt4.lib', ], }, diff --git a/util/win/process_info_test.cc b/util/win/process_info_test.cc index 792b3f3..3bc18c7 100644 --- a/util/win/process_info_test.cc +++ b/util/win/process_info_test.cc @@ -14,6 +14,7 @@ #include "util/win/process_info.h" +#include #include #include @@ -32,15 +33,12 @@ namespace { const wchar_t kNtdllName[] = L"\\ntdll.dll"; time_t GetTimestampForModule(HMODULE module) { - wchar_t filename[MAX_PATH]; - if (!GetModuleFileName(module, filename, arraysize(filename))) + char filename[MAX_PATH]; + // `char` and GetModuleFileNameA because ImageLoad is ANSI only. + if (!GetModuleFileNameA(module, filename, arraysize(filename))) return 0; - struct _stat stat_buf; - int rv = _wstat(filename, &stat_buf); - EXPECT_EQ(0, rv); - if (rv != 0) - return 0; - return stat_buf.st_mtime; + LOADED_IMAGE* loaded_image = ImageLoad(filename, nullptr); + return loaded_image->FileHeader->FileHeader.TimeDateStamp; } TEST(ProcessInfo, Self) {