summaryrefslogtreecommitdiffstats
path: root/chrome_elf/elf_imports_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome_elf/elf_imports_unittest.cc')
-rw-r--r--chrome_elf/elf_imports_unittest.cc32
1 files changed, 25 insertions, 7 deletions
diff --git a/chrome_elf/elf_imports_unittest.cc b/chrome_elf/elf_imports_unittest.cc
index 941c641..87a1f59 100644
--- a/chrome_elf/elf_imports_unittest.cc
+++ b/chrome_elf/elf_imports_unittest.cc
@@ -47,20 +47,35 @@ class ELFImportsTest : public testing::Test {
}
};
+// Run this test only in Release builds.
+//
+// This test makes sure that chrome_elf.dll has only certain types of imports.
+// However, it directly and indirectly depends on base, which has lots more
+// imports than are allowed here.
+//
+// In release builds, the offending imports are all stripped since this
+// depends on a relatively small portion of base. In GYP, this works in debug
+// builds as well because static libraries are used for the sandbox and base
+// targets and the files that use e.g. user32.dll happen to not get brought
+// into the build in the first place (due to the way static libraries are
+// linked where only the required .o files are included). But we don't bother
+// differentiating GYP and GN builds for this purpose.
+//
+// If you break this test, you may have changed base or the Windows sandbox
+// such that more system imports are required to link.
+#ifdef NDEBUG
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");
+
+ std::vector<std::string> elf_imports;
GetImports(dll, &elf_imports);
// Check that ELF has imports.
ASSERT_LT(0u, elf_imports.size()) << "Ensure the chrome_elf_unittests "
"target was built, instead of chrome_elf_unittests.exe";
- std::vector<std::string>::iterator it(elf_imports.begin());
-
static const char* const kValidFilePatterns[] = {
"KERNEL32.dll",
"MSVC*",
@@ -74,15 +89,18 @@ TEST_F(ELFImportsTest, ChromeElfSanityCheck) {
};
// Make sure all of ELF's imports are in the valid imports list.
- for (; it != elf_imports.end(); it++) {
+ for (const std::string& import : elf_imports) {
bool match = false;
for (int i = 0; i < arraysize(kValidFilePatterns); ++i) {
- if (base::MatchPattern(*it, kValidFilePatterns[i]))
+ if (base::MatchPattern(import, kValidFilePatterns[i])) {
match = true;
+ break;
+ }
}
- ASSERT_TRUE(match) << "Illegal import in chrome_elf.dll: " << *it;
+ ASSERT_TRUE(match) << "Illegal import in chrome_elf.dll: " << import;
}
}
+#endif // NDEBUG
TEST_F(ELFImportsTest, ChromeExeSanityCheck) {
std::vector<std::string> exe_imports;