Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11260)

Unified Diff: chrome_elf/elf_imports_unittest.cc

Issue 109483003: Make sure Chrome_elf.dll imports are correct and that it the first import of chrome.exe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable tests on Winx64 Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome_elf/chrome_elf.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome_elf/elf_imports_unittest.cc
diff --git a/chrome_elf/elf_imports_unittest.cc b/chrome_elf/elf_imports_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b25288c67792eea15f79531abd36f6fecbf77691
--- /dev/null
+++ b/chrome_elf/elf_imports_unittest.cc
@@ -0,0 +1,100 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdint.h>
+#include <windows.h>
+
+#include <algorithm>
+#include <vector>
+
+#include "base/base_paths.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/files/file_path.h"
+#include "base/files/memory_mapped_file.h"
+#include "base/path_service.h"
+#include "base/strings/string_util.h"
+#include "base/win/pe_image.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class ELFImportsTest : public testing::Test {
+ protected:
+ static bool ImportsCallback(const base::win::PEImage &image,
+ LPCSTR module,
+ PIMAGE_THUNK_DATA name_table,
+ PIMAGE_THUNK_DATA iat,
+ PVOID cookie) {
+ std::vector<std::string>* import_list =
+ reinterpret_cast<std::vector<std::string>*>(cookie);
+ import_list->push_back(module);
+ return true;
+ }
+
+ void GetImports(const base::FilePath& module_path,
+ std::vector<std::string>* imports) {
+ ASSERT_TRUE(imports != NULL);
+
+ base::MemoryMappedFile module_mmap;
+
+ ASSERT_TRUE(module_mmap.Initialize(module_path));
+ base::win::PEImageAsData pe_image_data(
+ reinterpret_cast<HMODULE>(const_cast<uint8*>(module_mmap.data())));
+ pe_image_data.EnumImportChunks(ELFImportsTest::ImportsCallback, imports);
+ }
+};
+
+TEST_F(ELFImportsTest, ChromeElfSanityCheck) {
+ std::vector<std::string> elf_imports;
+
+ base::FilePath dll;
+ ASSERT_TRUE(PathService::Get(base::DIR_EXE, &dll));
+ dll = dll.Append(L"chrome_elf.dll");
+ GetImports(dll, &elf_imports);
+
+ // Check that ELF has imports.
+ ASSERT_LT(0u, elf_imports.size());
+
+ std::vector<std::string>::iterator it(elf_imports.begin());
+
+ static const char* const kValidFilePatterns[] = {
+ "KERNEL32.dll",
+ "MSVC*",
+ "ADVAPI32.dll"};
+
+ // Make sure all of ELF's imports are in the valid imports list.
+ for (; it != elf_imports.end(); it++) {
+ bool match = false;
+ for (int i = 0; i < arraysize(kValidFilePatterns); ++i) {
+ if (MatchPattern(*it, kValidFilePatterns[i]))
+ match = true;
+ }
+ ASSERT_TRUE(match) << "Illegal import in chrome_elf.dll.";
+ }
+}
+
+#if defined(ARCH_CPU_64_BITS)
+#define MAYBE_ChromeExeSanityCheck DISABLED_ChromeExeSanityCheck
+#else
+#define MAYBE_ChromeExeSanityCheck ChromeExeSanityCheck
+#endif
+// Fails on 64-bit Windows, see http://crbug.com/335173.
+TEST_F(ELFImportsTest, MAYBE_ChromeExeSanityCheck) {
+ std::vector<std::string> exe_imports;
+
+ base::FilePath exe;
+ ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe));
+ exe = exe.Append(L"chrome.exe");
+ GetImports(exe, &exe_imports);
+
+ // Check that chrome.exe has imports.
+ ASSERT_LT(0u, exe_imports.size());
+
+ // Chrome.exe's first import must be ELF.
+ EXPECT_EQ("chrome_elf.dll", exe_imports[0]) <<
+ "Illegal import order in chrome.exe";
+}
+
+} // namespace
« no previous file with comments | « chrome_elf/chrome_elf.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698