Commit a9753d0f authored by Penny MacNeil's avatar Penny MacNeil Committed by Commit Bot

[chrome_elf tests] Pull import tests out into new unittest.

This isolates the huge dependency on chrome.exe, so that dev
is way faster and solution filters are smaller, etc.
No change to the tests.

TEST=new chrome_elf_import_unittests.exe

NOTRY=true

Bug: 769590
Cq-Include-Trybots: master.tryserver.chromium.win:win10_chromium_x64_rel_ng
Change-Id: Ie6a1a8ca106f2424de69502748ee40133f7ca66c
Reviewed-on: https://chromium-review.googlesource.com/691555
Commit-Queue: Penny MacNeil <pennymac@chromium.org>
Reviewed-by: 's avatarRobert Shield <robertshield@chromium.org>
Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505651}
parent d80d63c4
......@@ -573,6 +573,7 @@ group("gn_all") {
"//base:pe_image_test",
"//chrome/install_static:install_static_unittests",
"//chrome/installer/setup:setup_unittests",
"//chrome_elf:chrome_elf_import_unittests",
"//chrome_elf:chrome_elf_unittests",
"//chrome_elf:dll_hash_main",
"//cloud_print:cloud_print_unittests",
......
......@@ -227,7 +227,6 @@ test("chrome_elf_unittests") {
sources = [
"blacklist/test/blacklist_test.cc",
"chrome_elf_util_unittest.cc",
"elf_imports_unittest.cc",
"hook_util/test/hook_util_test.cc",
"nt_registry/nt_registry_unittest.cc",
"run_all_unittests.cc",
......@@ -244,7 +243,6 @@ test("chrome_elf_unittests") {
":security",
"//base",
"//base/test:test_support",
"//chrome",
"//chrome/common:version_header",
"//chrome/install_static:install_static_util",
"//chrome/install_static/test:test_support",
......@@ -252,6 +250,28 @@ test("chrome_elf_unittests") {
"//sandbox",
"//testing/gtest",
]
data_deps = [
":blacklist_test_dll_1",
":blacklist_test_dll_2",
":blacklist_test_dll_3",
":chrome_elf",
]
}
test("chrome_elf_import_unittests") {
output_name = "chrome_elf_import_unittests"
sources = [
"elf_imports_unittest.cc",
]
include_dirs = [ "$target_gen_dir" ]
deps = [
"//base",
"//base/test:test_support",
"//chrome",
"//chrome/install_static:install_static_util",
"//chrome/install_static/test:test_support",
"//testing/gtest",
]
# It's not easily possible to have //chrome in data_deps without changing
# the //chrome target to bundle up both initial/chrome.exe and chrome.exe.
......@@ -261,9 +281,6 @@ test("chrome_elf_unittests") {
"$root_out_dir/chrome.exe",
]
data_deps = [
":blacklist_test_dll_1",
":blacklist_test_dll_2",
":blacklist_test_dll_3",
":chrome_elf",
]
......
......@@ -9,6 +9,7 @@
#include <vector>
#include "base/base_paths.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
......@@ -17,7 +18,11 @@
#include "base/strings/pattern.h"
#include "base/strings/string_util.h"
#include "base/test/launcher/test_launcher.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
#include "base/win/pe_image.h"
#include "build/build_config.h"
#include "chrome/install_static/test/scoped_install_details.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
......@@ -75,8 +80,9 @@ TEST_F(ELFImportsTest, ChromeElfSanityCheck) {
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";
ASSERT_LT(0u, elf_imports.size())
<< "Ensure the chrome_elf_import_unittests "
"target was built, instead of chrome_elf_import_unittests.exe";
static const char* const kValidFilePatterns[] = {
"KERNEL32.dll",
......@@ -141,9 +147,9 @@ TEST_F(ELFImportsTest, DISABLED_ChromeElfLoadSanityTestImpl) {
ASSERT_TRUE(PathService::Get(base::DIR_EXE, &dll));
dll = dll.Append(L"chrome_elf.dll");
// We don't expect user32 to be loaded in chrome_elf_unittests. If this test
// case fails, then it means that a dependency on user32 has crept into the
// chrome_elf_unittests executable, which needs to be removed.
// We don't expect user32 to be loaded in chrome_elf_import_unittests. If this
// test case fails, then it means that a dependency on user32 has crept into
// the chrome_elf_imports_unittests executable, which needs to be removed.
// NOTE: it may be a secondary dependency of another system DLL. If so,
// try adding a "/DELAYLOAD:<blah>.dll" to the build.gn file.
ASSERT_EQ(nullptr, ::GetModuleHandle(L"user32.dll"));
......@@ -166,13 +172,31 @@ TEST_F(ELFImportsTest, ChromeExeSanityCheck) {
GetImports(exe, &exe_imports);
// Check that chrome.exe has imports.
ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests "
"target was built, instead of chrome_elf_unittests.exe";
ASSERT_LT(0u, exe_imports.size())
<< "Ensure the chrome_elf_import_unittests "
"target was built, instead of chrome_elf_import_unittests.exe";
// Chrome.exe's first import must be ELF.
EXPECT_EQ("chrome_elf.dll", exe_imports[0]) <<
"Illegal import order in chrome.exe (ensure the chrome_elf_unittest "
"target was built, instead of just chrome_elf_unittests.exe)";
EXPECT_EQ("chrome_elf.dll", exe_imports[0])
<< "Illegal import order in chrome.exe (ensure the "
"chrome_elf_import_unittest "
"target was built, instead of just chrome_elf_import_unittests.exe)";
}
} // namespace
int main(int argc, char** argv) {
// Ensure that the CommandLine instance honors the command line passed in
// instead of the default behavior on Windows which is to use the shell32
// CommandLineToArgvW API. The chrome_elf_imports_unittests test suite should
// not depend on user32 directly or indirectly (For the curious shell32
// depends on user32)
base::CommandLine::InitUsingArgvForTesting(argc, argv);
install_static::ScopedInstallDetails scoped_install_details;
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTests(
argc, argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
......@@ -20,8 +20,7 @@ int main(int argc, char** argv) {
install_static::ScopedInstallDetails scoped_install_details;
base::TestSuite test_suite(argc, argv);
int ret = base::LaunchUnitTests(
return base::LaunchUnitTests(
argc, argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
return ret;
}
......@@ -2239,6 +2239,12 @@
},
"test": "chrome_app_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "chrome_elf_import_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
......@@ -5881,6 +5887,12 @@
},
"test": "chrome_app_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "chrome_elf_import_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
......@@ -6183,6 +6195,12 @@
},
"test": "chrome_app_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "chrome_elf_import_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
......
......@@ -80,6 +80,12 @@
},
"test": "chrome_app_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "chrome_elf_import_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
......@@ -604,6 +610,12 @@
},
"test": "chrome_app_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "chrome_elf_import_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
......@@ -1187,6 +1199,12 @@
},
"test": "chrome_app_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "chrome_elf_import_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
......@@ -1738,6 +1756,12 @@
},
"test": "chrome_app_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "chrome_elf_import_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
......
......@@ -272,6 +272,10 @@
"label": "//chrome/test:chrome_app_unittests",
"type": "console_test_launcher",
},
"chrome_elf_import_unittests": {
"label": "//chrome_elf:chrome_elf_import_unittests",
"type": "raw",
},
"chrome_elf_unittests": {
"label": "//chrome_elf:chrome_elf_unittests",
"type": "raw",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment