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

Unified Diff: courgette/rel32_finder_x64_unittest.cc

Issue 2008253004: Refactor rel32 searching process for x64 to make it more similar to x86. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
Index: courgette/rel32_finder_x64_unittest.cc
diff --git a/courgette/rel32_finder_win32_x86_unittest.cc b/courgette/rel32_finder_x64_unittest.cc
similarity index 79%
copy from courgette/rel32_finder_win32_x86_unittest.cc
copy to courgette/rel32_finder_x64_unittest.cc
index 496f0b94bb249bb837bad08f0ca3bcbc9e4a8272..83122e648579608d786f72cde28b6677f84ad063 100644
--- a/courgette/rel32_finder_win32_x86_unittest.cc
+++ b/courgette/rel32_finder_x64_unittest.cc
@@ -1,8 +1,8 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2016 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 "courgette/rel32_finder_win32_x86.h"
+#include "courgette/rel32_finder_x64.h"
#include <stddef.h>
#include <stdint.h>
@@ -20,10 +20,10 @@ namespace courgette {
namespace {
-// Helper class to load and execute a Rel32FinderWin32X86 test case.
-class Rel32FinderWin32X86TestCase {
+// Helper class to load and execute a Rel32FinderX64 test case.
huangs 2016/05/26 18:34:34 There's a lot of duplicate code with rel32_finder_
etiennep 2016/05/26 20:50:10 Done.
+class Rel32FinderX64TestCase {
public:
- Rel32FinderWin32X86TestCase(const std::string& test_data)
+ Rel32FinderX64TestCase(const std::string& test_data)
: text_start_rva_(0),
text_end_rva_(0),
relocs_start_rva_(0),
@@ -33,10 +33,11 @@ class Rel32FinderWin32X86TestCase {
}
void RunTestBasic(std::string name) {
- Rel32FinderWin32X86_Basic finder(relocs_start_rva_, relocs_end_rva_);
+ Rel32FinderX64 finder(relocs_start_rva_, relocs_end_rva_);
ASSERT_FALSE(text_data_.empty());
finder.Find(&text_data_[0], &text_data_[0] + text_data_.size(),
- text_start_rva_, text_end_rva_, abs32_locations_);
+ text_start_rva_, text_end_rva_, image_end_rva_,
+ abs32_locations_);
std::vector<RVA> rel32_locations;
finder.SwapRel32Locations(&rel32_locations);
EXPECT_EQ(expected_rel32_locations_, rel32_locations)
@@ -83,7 +84,7 @@ class Rel32FinderWin32X86TestCase {
}
// Initializes the test case by parsing the multi-line string |test_data|
- // to extract Rel32FinderWin32X86 parameters, and read expected values.
+ // to extract Rel32FinderX64 parameters, and read expected values.
void LoadTestFromString(const std::string& test_data) {
// The first lines (ignoring empty ones) specify RVA bounds.
std::istringstream iss(test_data);
@@ -98,19 +99,22 @@ class Rel32FinderWin32X86TestCase {
// formatted in "DUMPBIN /DISASM" style, i.e.,
// "00401003: E8 00 00 00 00 call 00401008"
// ^ ^ ^ ^ ^ ^
- // We extract up to 6 bytes per line. The remaining are ignored.
+ // We extract up to 7 bytes per line. The remaining are ignored.
huangs 2016/05/26 18:34:34 Keep it at 6; you can wrap instruction to next lin
etiennep 2016/05/26 20:50:10 Done.
const int kBytesBegin = 12;
- const int kBytesEnd = 17;
+ const int kBytesEnd = 22;
ReadNonEmptyLine(iss, &line);
ASSERT_EQ("Program:", line);
while (ReadNonEmptyLine(iss, &line) && line != "Abs32:") {
std::string toks = line.substr(kBytesBegin, kBytesEnd);
- uint32_t vals[6];
- int num_read = sscanf(toks.c_str(), "%X %X %X %X %X %X", &vals[0],
- &vals[1], &vals[2], &vals[3], &vals[4], &vals[5]);
+ uint32_t vals[7];
+ int num_read =
+ sscanf(toks.c_str(), "%X %X %X %X %X %X %X", &vals[0], &vals[1],
+ &vals[2], &vals[3], &vals[4], &vals[5], &vals[6]);
+
for (int i = 0; i < num_read; ++i)
text_data_.push_back(static_cast<uint8_t>(vals[i] & 0xFF));
}
+
ASSERT_FALSE(text_data_.empty());
// The Abs32 section specifies hex RVAs, one per line.
@@ -131,19 +135,18 @@ class Rel32FinderWin32X86TestCase {
}
};
-class Rel32FinderWin32X86Test : public BaseTest {
+class Rel32FinderX64Test : public BaseTest {
public:
void RunTest(const char* test_case_file) {
- Rel32FinderWin32X86TestCase test_case(FileContents(test_case_file));
+ Rel32FinderX64TestCase test_case(FileContents(test_case_file));
test_case.RunTestBasic(test_case_file);
}
};
-TEST_F(Rel32FinderWin32X86Test, TestBasic) {
- RunTest("rel32_win32_x86_01.txt");
- RunTest("rel32_win32_x86_02.txt");
- RunTest("rel32_win32_x86_03.txt");
- RunTest("rel32_win32_x86_04.txt");
+TEST_F(Rel32FinderX64Test, TestBasic) {
+ RunTest("rel32_x64_01.txt");
+ RunTest("rel32_x64_02.txt");
+ RunTest("rel32_x64_03.txt");
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698