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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_elf/chrome_elf.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdint.h>
6 #include <windows.h>
7
8 #include <algorithm>
9 #include <vector>
10
11 #include "base/base_paths.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h"
15 #include "base/files/memory_mapped_file.h"
16 #include "base/path_service.h"
17 #include "base/strings/string_util.h"
18 #include "base/win/pe_image.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 namespace {
22
23 class ELFImportsTest : public testing::Test {
24 protected:
25 static bool ImportsCallback(const base::win::PEImage &image,
26 LPCSTR module,
27 PIMAGE_THUNK_DATA name_table,
28 PIMAGE_THUNK_DATA iat,
29 PVOID cookie) {
30 std::vector<std::string>* import_list =
31 reinterpret_cast<std::vector<std::string>*>(cookie);
32 import_list->push_back(module);
33 return true;
34 }
35
36 void GetImports(const base::FilePath& module_path,
37 std::vector<std::string>* imports) {
38 ASSERT_TRUE(imports != NULL);
39
40 base::MemoryMappedFile module_mmap;
41
42 ASSERT_TRUE(module_mmap.Initialize(module_path));
43 base::win::PEImageAsData pe_image_data(
44 reinterpret_cast<HMODULE>(const_cast<uint8*>(module_mmap.data())));
45 pe_image_data.EnumImportChunks(ELFImportsTest::ImportsCallback, imports);
46 }
47 };
48
49 TEST_F(ELFImportsTest, ChromeElfSanityCheck) {
50 std::vector<std::string> elf_imports;
51
52 base::FilePath dll;
53 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &dll));
54 dll = dll.Append(L"chrome_elf.dll");
55 GetImports(dll, &elf_imports);
56
57 // Check that ELF has imports.
58 ASSERT_LT(0u, elf_imports.size());
59
60 std::vector<std::string>::iterator it(elf_imports.begin());
61
62 static const char* const kValidFilePatterns[] = {
63 "KERNEL32.dll",
64 "MSVC*",
65 "ADVAPI32.dll"};
66
67 // Make sure all of ELF's imports are in the valid imports list.
68 for (; it != elf_imports.end(); it++) {
69 bool match = false;
70 for (int i = 0; i < arraysize(kValidFilePatterns); ++i) {
71 if (MatchPattern(*it, kValidFilePatterns[i]))
72 match = true;
73 }
74 ASSERT_TRUE(match) << "Illegal import in chrome_elf.dll.";
75 }
76 }
77
78 #if defined(ARCH_CPU_64_BITS)
79 #define MAYBE_ChromeExeSanityCheck DISABLED_ChromeExeSanityCheck
80 #else
81 #define MAYBE_ChromeExeSanityCheck ChromeExeSanityCheck
82 #endif
83 // Fails on 64-bit Windows, see http://crbug.com/335173.
84 TEST_F(ELFImportsTest, MAYBE_ChromeExeSanityCheck) {
85 std::vector<std::string> exe_imports;
86
87 base::FilePath exe;
88 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe));
89 exe = exe.Append(L"chrome.exe");
90 GetImports(exe, &exe_imports);
91
92 // Check that chrome.exe has imports.
93 ASSERT_LT(0u, exe_imports.size());
94
95 // Chrome.exe's first import must be ELF.
96 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) <<
97 "Illegal import order in chrome.exe";
98 }
99
100 } // namespace
OLDNEW
« 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