Bug 1481958: Add binary version check to TestNativeNt; r=mhowell
authorAaron Klotz <aklotz@mozilla.com>
Wed, 08 Aug 2018 16:20:49 -0600
changeset 486123 64c7e3b34869ce65e1ece5ff6bc61dcd17d94fe9
parent 486122 9705ac8fbee347f99503d2fa1723143bbdd3bdb8
child 486124 aea50d33724cf43f19cc81f8c6de668ec7016f66
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1481958
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1481958: Add binary version check to TestNativeNt; r=mhowell
browser/app/winlauncher/test/TestNativeNt.cpp
browser/app/winlauncher/test/moz.build
--- a/browser/app/winlauncher/test/TestNativeNt.cpp
+++ b/browser/app/winlauncher/test/TestNativeNt.cpp
@@ -1,17 +1,19 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
 
 #include "NativeNt.h"
+#include "mozilla/UniquePtr.h"
 
 #include <stdio.h>
+#include <windows.h>
 
 const wchar_t kNormal[] = L"Foo.dll";
 const wchar_t kHex12[] = L"Foo.ABCDEF012345.dll";
 const wchar_t kHex15[] = L"ABCDEF012345678.dll";
 const wchar_t kHex16[] = L"ABCDEF0123456789.dll";
 const wchar_t kHex17[] = L"ABCDEF0123456789a.dll";
 const wchar_t kHex24[] = L"ABCDEF0123456789cdabef98.dll";
 const wchar_t kHex8[] = L"01234567.dll";
@@ -29,16 +31,17 @@ const char kFailFmt[] = "TEST-FAILED | N
   }
 
 #define EXPECT_FAIL(fn, varName) \
   RUN_TEST(fn, varName, false) \
 
 #define EXPECT_SUCCESS(fn, varName) \
   RUN_TEST(fn, varName, true)
 
+using namespace mozilla;
 using namespace mozilla::nt;
 
 int main(int argc, char* argv[])
 {
   UNICODE_STRING normal;
   ::RtlInitUnicodeString(&normal, kNormal);
 
   UNICODE_STRING hex12;
@@ -87,11 +90,58 @@ int main(int argc, char* argv[])
   EXPECT_FAIL(IsFileNameAtLeast16HexDigits, hex15);
   EXPECT_FAIL(IsFileNameAtLeast16HexDigits, prefixedHex16);
 
   if (RtlGetProcessHeap() != ::GetProcessHeap()) {
     printf("TEST-FAILED | NativeNt | RtlGetProcessHeap() is broken\n");
     return 1;
   }
 
+  const wchar_t kKernel32[] = L"kernel32.dll";
+  DWORD verInfoSize = ::GetFileVersionInfoSizeW(kKernel32, nullptr);
+  if (!verInfoSize) {
+    printf("TEST-FAILED | NativeNt | Call to GetFileVersionInfoSizeW failed with code %lu\n",
+           ::GetLastError());
+    return 1;
+  }
+
+  auto verInfoBuf = MakeUnique<char[]>(verInfoSize);
+
+  if (!::GetFileVersionInfoW(kKernel32, 0, verInfoSize, verInfoBuf.get())) {
+    printf("TEST-FAILED | NativeNt | Call to GetFileVersionInfoW failed with code %lu\n",
+           ::GetLastError());
+    return 1;
+  }
+
+  UINT len;
+  VS_FIXEDFILEINFO* fixedFileInfo = nullptr;
+  if (!::VerQueryValueW(verInfoBuf.get(), L"\\", (LPVOID*)&fixedFileInfo, &len)) {
+    printf("TEST-FAILED | NativeNt | Call to VerQueryValueW failed with code %lu\n",
+           ::GetLastError());
+    return 1;
+  }
+
+  const uint64_t expectedVersion =
+    (static_cast<uint64_t>(fixedFileInfo->dwFileVersionMS) << 32) |
+    static_cast<uint64_t>(fixedFileInfo->dwFileVersionLS);
+
+  PEHeaders k32headers(::GetModuleHandleW(kKernel32));
+  if (!k32headers) {
+    printf("TEST-FAILED | NativeNt | Failed parsing kernel32.dll's PE headers\n");
+    return 1;
+  }
+
+  uint64_t version;
+  if (!k32headers.GetVersionInfo(version)) {
+    printf("TEST-FAILED | NativeNt | Unable to obtain version information from kernel32.dll\n");
+    return 1;
+  }
+
+  if (version != expectedVersion) {
+    printf("TEST-FAILED | NativeNt | kernel32.dll's detected version "
+           "(0x%016llX) does not match expected version (0x%016llX)\n",
+           version, expectedVersion);
+    return 1;
+  }
+
   return 0;
 }
 
--- a/browser/app/winlauncher/test/moz.build
+++ b/browser/app/winlauncher/test/moz.build
@@ -8,13 +8,14 @@ DisableStlWrapping()
 
 CppUnitTests(['TestNativeNt'])
 
 LOCAL_INCLUDES += [
     '/browser/app/winlauncher',
 ]
 
 OS_LIBS += [
+    'mincore',
     'ntdll',
 ]
 
 if CONFIG['CC_TYPE'] == 'clang-cl':
     AllowCompilerWarnings()  # workaround for bug 1090497