summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorWill Harris <wfh@chromium.org>2015-02-26 13:20:07 -0800
committerWill Harris <wfh@chromium.org>2015-02-26 21:23:33 +0000
commit0fabf08b78b13d4bee202152b5cdb138d3cc74e4 (patch)
tree6fbd3e73090c85db8d768b7c9b5e1c6ac9bcf4a4 /base
parentd7d7aa265d725abad14c4385f8e4a9c88d170845 (diff)
downloadchromium_src-0fabf08b78b13d4bee202152b5cdb138d3cc74e4.zip
chromium_src-0fabf08b78b13d4bee202152b5cdb138d3cc74e4.tar.gz
chromium_src-0fabf08b78b13d4bee202152b5cdb138d3cc74e4.tar.bz2
Fix PEImage tests to use a checked in binary.
BUG=167707,461816 R=rvargas@chromium.org Review URL: https://codereview.chromium.org/955273002 Cr-Commit-Position: refs/heads/master@{#318313}
Diffstat (limited to 'base')
-rw-r--r--base/BUILD.gn6
-rw-r--r--base/base.gyp5
-rw-r--r--base/base_unittests.isolate7
-rwxr-xr-xbase/test/data/pe_image/pe_image_test_32.dllbin0 -> 70656 bytes
-rwxr-xr-xbase/test/data/pe_image/pe_image_test_64.dllbin0 -> 82432 bytes
-rw-r--r--base/win/pe_image_unittest.cc195
6 files changed, 39 insertions, 174 deletions
diff --git a/base/BUILD.gn b/base/BUILD.gn
index 9dbc41c..ab04cbd 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -1163,6 +1163,8 @@ source_set("protect_file_posix") {
}
if (is_win) {
+ # Target to manually rebuild pe_image_test.dll which is checked into
+ # base/test/data/pe_image.
shared_library("pe_image_test") {
sources = [
"win/pe_image_test.cc",
@@ -1487,10 +1489,6 @@ test("base_unittests") {
set_sources_assignment_filter(sources_assignment_filter)
}
- if (is_win) {
- deps += [ ":pe_image_test" ]
- }
-
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
}
diff --git a/base/base.gyp b/base/base.gyp
index 30de275..bb86ddd 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -778,9 +778,6 @@
'message_loop/message_pump_libevent_unittest.cc',
'threading/worker_pool_posix_unittest.cc',
],
- 'dependencies': [
- 'pe_image_test',
- ],
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
'msvs_disabled_warnings': [
4267,
@@ -1551,6 +1548,8 @@
},
},
{
+ # Target to manually rebuild pe_image_test.dll which is checked into
+ # base/test/data/pe_image.
'target_name': 'pe_image_test',
'type': 'shared_library',
'sources': [
diff --git a/base/base_unittests.isolate b/base/base_unittests.isolate
index e5495e3..2e33cc0 100644
--- a/base/base_unittests.isolate
+++ b/base/base_unittests.isolate
@@ -72,13 +72,6 @@
],
},
}],
- ['OS=="win"', {
- 'variables': {
- 'files': [
- '<(PRODUCT_DIR)/pe_image_test.dll',
- ],
- },
- }],
],
'includes': [
'base.isolate',
diff --git a/base/test/data/pe_image/pe_image_test_32.dll b/base/test/data/pe_image/pe_image_test_32.dll
new file mode 100755
index 0000000..118ce11
--- /dev/null
+++ b/base/test/data/pe_image/pe_image_test_32.dll
Binary files differ
diff --git a/base/test/data/pe_image/pe_image_test_64.dll b/base/test/data/pe_image/pe_image_test_64.dll
new file mode 100755
index 0000000..70f8ea4
--- /dev/null
+++ b/base/test/data/pe_image/pe_image_test_64.dll
Binary files differ
diff --git a/base/win/pe_image_unittest.cc b/base/win/pe_image_unittest.cc
index 4134741..28b65a4 100644
--- a/base/win/pe_image_unittest.cc
+++ b/base/win/pe_image_unittest.cc
@@ -6,129 +6,10 @@
#include <algorithm>
#include <vector>
-#include "testing/gtest/include/gtest/gtest.h"
+#include "base/files/file_path.h"
+#include "base/path_service.h"
#include "base/win/pe_image.h"
-#include "base/win/windows_version.h"
-
-namespace {
-
-class Expectations {
- public:
- enum Value {
- SECTIONS = 0,
- IMPORTS_DLLS,
- DELAY_DLLS,
- EXPORTS,
- IMPORTS,
- DELAY_IMPORTS,
- RELOCS
- };
-
- enum Arch {
- ARCH_X86 = 0,
- ARCH_X64,
- ARCH_ALL
- };
-
- Expectations();
-
- void SetDefault(Value value, int count);
- void SetOverride(Value value, base::win::Version version,
- Arch arch, int count);
- void SetOverride(Value value, base::win::Version version, int count);
- void SetOverride(Value value, Arch arch, int count);
-
- // returns -1 on failure.
- int GetExpectation(Value value);
-
- private:
- class Override {
- public:
- enum MatchType { MATCH_VERSION, MATCH_ARCH, MATCH_BOTH, MATCH_NONE };
-
- Override(Value value, base::win::Version version, Arch arch, int count)
- : value_(value), version_(version), arch_(arch), count_(count) {
- };
-
- bool Matches(Value value, base::win::Version version,
- Arch arch, MatchType type) {
- if (value_ != value)
- return false;
-
- switch (type) {
- case MATCH_BOTH:
- return (arch == arch_ && version == version_);
- case MATCH_ARCH:
- return (arch == arch_ && version_ == base::win::VERSION_WIN_LAST);
- case MATCH_VERSION:
- return (arch_ == ARCH_ALL && version == version_);
- case MATCH_NONE:
- return (arch_ == ARCH_ALL && version_ == base::win::VERSION_WIN_LAST);
- }
- return false;
- }
-
- int GetCount() { return count_; }
-
- private:
- Value value_;
- base::win::Version version_;
- Arch arch_;
- int count_;
- };
-
- bool MatchesMyArch(Arch arch);
-
- std::vector<Override> overrides_;
- Arch my_arch_;
- base::win::Version my_version_;
-};
-
-Expectations::Expectations() {
- my_version_ = base::win::GetVersion();
-#if defined(ARCH_CPU_64_BITS)
- my_arch_ = ARCH_X64;
-#else
- my_arch_ = ARCH_X86;
-#endif
-}
-
-int Expectations::GetExpectation(Value value) {
- // Prefer OS version specificity over Arch specificity.
- for (auto type : { Override::MATCH_BOTH,
- Override::MATCH_VERSION,
- Override::MATCH_ARCH,
- Override::MATCH_NONE }) {
- for (auto override : overrides_) {
- if (override.Matches(value, my_version_, my_arch_, type))
- return override.GetCount();
- }
- }
- return -1;
-}
-
-void Expectations::SetDefault(Value value, int count) {
- SetOverride(value, base::win::VERSION_WIN_LAST, ARCH_ALL, count);
-}
-
-void Expectations::SetOverride(Value value,
- base::win::Version version,
- Arch arch,
- int count) {
- overrides_.push_back(Override(value, version, arch, count));
-}
-
-void Expectations::SetOverride(Value value,
- base::win::Version version,
- int count) {
- SetOverride(value, version, ARCH_ALL, count);
-}
-
-void Expectations::SetOverride(Value value, Arch arch, int count) {
- SetOverride(value, base::win::VERSION_WIN_LAST, arch, count);
-}
-
-} // namespace
+#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace win {
@@ -210,41 +91,35 @@ bool ExportsCallback(const PEImage& image,
} // namespace
// Tests that we are able to enumerate stuff from a PE file, and that
-// the actual number of items found is within the expected range.
+// the actual number of items found matches an expected value.
TEST(PEImageTest, EnumeratesPE) {
- Expectations expectations;
-
-#ifndef NDEBUG
- // Default Debug expectations.
- expectations.SetDefault(Expectations::SECTIONS, 7);
- expectations.SetDefault(Expectations::IMPORTS_DLLS, 3);
- expectations.SetDefault(Expectations::DELAY_DLLS, 2);
- expectations.SetDefault(Expectations::EXPORTS, 2);
- expectations.SetDefault(Expectations::IMPORTS, 49);
- expectations.SetDefault(Expectations::DELAY_IMPORTS, 2);
- expectations.SetDefault(Expectations::RELOCS, 438);
-
- // 64-bit Debug expectations.
- expectations.SetOverride(Expectations::SECTIONS, Expectations::ARCH_X64, 8);
- expectations.SetOverride(Expectations::IMPORTS, Expectations::ARCH_X64, 69);
- expectations.SetOverride(Expectations::RELOCS, Expectations::ARCH_X64, 632);
+ base::FilePath pe_image_test_path;
+ ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &pe_image_test_path));
+ pe_image_test_path = pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image"));
+
+#if defined(ARCH_CPU_64_BITS)
+ pe_image_test_path =
+ pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image_test_64.dll"));
+ const int sections = 6;
+ const int imports_dlls = 2;
+ const int delay_dlls = 2;
+ const int exports = 2;
+ const int imports = 69;
+ const int delay_imports = 2;
+ const int relocs = 632;
#else
- // Default Release expectations.
- expectations.SetDefault(Expectations::SECTIONS, 5);
- expectations.SetDefault(Expectations::IMPORTS_DLLS, 2);
- expectations.SetDefault(Expectations::DELAY_DLLS, 2);
- expectations.SetDefault(Expectations::EXPORTS, 2);
- expectations.SetDefault(Expectations::IMPORTS, 66);
- expectations.SetDefault(Expectations::DELAY_IMPORTS, 2);
- expectations.SetDefault(Expectations::RELOCS, 1586);
-
- // 64-bit Release expectations.
- expectations.SetOverride(Expectations::SECTIONS, Expectations::ARCH_X64, 6);
- expectations.SetOverride(Expectations::IMPORTS, Expectations::ARCH_X64, 69);
- expectations.SetOverride(Expectations::RELOCS, Expectations::ARCH_X64, 632);
+ pe_image_test_path =
+ pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image_test_32.dll"));
+ const int sections = 5;
+ const int imports_dlls = 2;
+ const int delay_dlls = 2;
+ const int exports = 2;
+ const int imports = 66;
+ const int delay_imports = 2;
+ const int relocs = 1586;
#endif
- HMODULE module = LoadLibrary(L"pe_image_test.dll");
+ HMODULE module = LoadLibrary(pe_image_test_path.value().c_str());
ASSERT_TRUE(NULL != module);
PEImage pe(module);
@@ -252,31 +127,31 @@ TEST(PEImageTest, EnumeratesPE) {
EXPECT_TRUE(pe.VerifyMagic());
pe.EnumSections(SectionsCallback, &count);
- EXPECT_EQ(expectations.GetExpectation(Expectations::SECTIONS), count);
+ EXPECT_EQ(sections, count);
count = 0;
pe.EnumImportChunks(ImportChunksCallback, &count);
- EXPECT_EQ(expectations.GetExpectation(Expectations::IMPORTS_DLLS), count);
+ EXPECT_EQ(imports_dlls, count);
count = 0;
pe.EnumDelayImportChunks(DelayImportChunksCallback, &count);
- EXPECT_EQ(expectations.GetExpectation(Expectations::DELAY_DLLS), count);
+ EXPECT_EQ(delay_dlls, count);
count = 0;
pe.EnumExports(ExportsCallback, &count);
- EXPECT_EQ(expectations.GetExpectation(Expectations::EXPORTS), count);
+ EXPECT_EQ(exports, count);
count = 0;
pe.EnumAllImports(ImportsCallback, &count);
- EXPECT_EQ(expectations.GetExpectation(Expectations::IMPORTS), count);
+ EXPECT_EQ(imports, count);
count = 0;
pe.EnumAllDelayImports(ImportsCallback, &count);
- EXPECT_EQ(expectations.GetExpectation(Expectations::DELAY_IMPORTS), count);
+ EXPECT_EQ(delay_imports, count);
count = 0;
pe.EnumRelocs(RelocsCallback, &count);
- EXPECT_EQ(expectations.GetExpectation(Expectations::RELOCS), count);
+ EXPECT_EQ(relocs, count);
FreeLibrary(module);
}