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

Unified Diff: courgette/disassembler_elf_32_x86_unittest.cc

Issue 1792603006: Revert of [Courgette] Clean up Disassembler; fix ELF Memory leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « courgette/disassembler_elf_32_x86.cc ('k') | courgette/disassembler_win32_x64.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/disassembler_elf_32_x86_unittest.cc
diff --git a/courgette/disassembler_elf_32_x86_unittest.cc b/courgette/disassembler_elf_32_x86_unittest.cc
index c15b8dff366a5d956a3176b8e0a5d28abf14e3fc..3ce6a630d3b94d91cb10078640fd9961356f9e32 100644
--- a/courgette/disassembler_elf_32_x86_unittest.cc
+++ b/courgette/disassembler_elf_32_x86_unittest.cc
@@ -2,25 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "courgette/disassembler_elf_32_x86.h"
-
#include <stddef.h>
#include <stdint.h>
-#include <algorithm>
-#include <string>
-
-#include "base/memory/scoped_ptr.h"
#include "courgette/assembly_program.h"
#include "courgette/base_test_unittest.h"
-#include "courgette/image_utils.h"
-
-namespace courgette {
-
-namespace {
+#include "courgette/disassembler_elf_32_x86.h"
class DisassemblerElf32X86Test : public BaseTest {
public:
+
void TestExe(const char* file_name,
size_t expected_abs_count,
size_t expected_rel_count) const;
@@ -29,11 +20,10 @@
void DisassemblerElf32X86Test::TestExe(const char* file_name,
size_t expected_abs_count,
size_t expected_rel_count) const {
- using TypedRVA = DisassemblerElf32::TypedRVA;
std::string file1 = FileContents(file_name);
- scoped_ptr<DisassemblerElf32X86> disassembler(
- new DisassemblerElf32X86(file1.c_str(), file1.length()));
+ scoped_ptr<courgette::DisassemblerElf32X86> disassembler(
+ new courgette::DisassemblerElf32X86(file1.c_str(), file1.length()));
bool can_parse_header = disassembler->ParseHeader();
EXPECT_TRUE(can_parse_header);
@@ -43,7 +33,7 @@
// real file, since trailing debug info is not included
EXPECT_EQ(file1.length(), disassembler->length());
- const uint8_t* offset_p = disassembler->FileOffsetToPointer(0);
+ const uint8_t* offset_p = disassembler->OffsetToPointer(0);
EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()),
reinterpret_cast<const void*>(offset_p));
EXPECT_EQ(0x7F, offset_p[0]);
@@ -51,45 +41,46 @@
EXPECT_EQ('L', offset_p[2]);
EXPECT_EQ('F', offset_p[3]);
- scoped_ptr<AssemblyProgram> program(new AssemblyProgram(EXE_ELF_32_X86));
+ courgette::AssemblyProgram* program =
+ new courgette::AssemblyProgram(courgette::EXE_ELF_32_X86);
- EXPECT_TRUE(disassembler->Disassemble(program.get()));
+ EXPECT_TRUE(disassembler->Disassemble(program));
- const std::vector<RVA>& abs32_list = disassembler->Abs32Locations();
+ EXPECT_EQ(disassembler->Abs32Locations().size(), expected_abs_count);
+ EXPECT_EQ(disassembler->Rel32Locations().size(), expected_rel_count);
- // Flatten the list typed rel32 to a list of rel32 RVAs.
- std::vector<RVA> rel32_list;
- rel32_list.reserve(disassembler->Rel32Locations().size());
- for (TypedRVA* typed_rel32 : disassembler->Rel32Locations())
- rel32_list.push_back(typed_rel32->rva());
+ // Prove that none of the rel32 RVAs overlap with abs32 RVAs
+ std::set<courgette::RVA> abs(disassembler->Abs32Locations().begin(),
+ disassembler->Abs32Locations().end());
+ std::set<courgette::DisassemblerElf32::TypedRVA*>
+ rel(disassembler->Rel32Locations().begin(),
+ disassembler->Rel32Locations().end());
+ for (std::vector<courgette::DisassemblerElf32::TypedRVA*>::iterator
+ rel32 = disassembler->Rel32Locations().begin();
+ rel32 != disassembler->Rel32Locations().end();
+ rel32++) {
+ EXPECT_TRUE(abs.find((*rel32)->rva()) == abs.end());
+ }
- EXPECT_EQ(expected_abs_count, abs32_list.size());
- EXPECT_EQ(expected_rel_count, rel32_list.size());
-
- EXPECT_TRUE(std::is_sorted(abs32_list.begin(), abs32_list.end()));
- EXPECT_TRUE(std::is_sorted(rel32_list.begin(), rel32_list.end()));
-
- // Verify that rel32 RVAs do not overlap with abs32 RVAs.
- // TODO(huangs): Fix this to account for RVA's 4-byte width.
- bool found_match = false;
- std::vector<RVA>::const_iterator abs32_it = abs32_list.begin();
- std::vector<RVA>::const_iterator rel32_it = rel32_list.begin();
- while (abs32_it != abs32_list.end() && rel32_it != rel32_list.end()) {
- if (*abs32_it < *rel32_it) {
- ++abs32_it;
- } else if (*abs32_it > *rel32_it) {
- ++rel32_it;
- } else {
- found_match = true;
+ for (std::vector<courgette::RVA>::iterator abs32 =
+ disassembler->Abs32Locations().begin();
+ abs32 != disassembler->Abs32Locations().end();
+ abs32++) {
+ bool found = false;
+ for (std::vector<courgette::DisassemblerElf32::TypedRVA*>::iterator
+ rel32 = disassembler->Rel32Locations().begin();
+ rel32 != disassembler->Rel32Locations().end();
+ rel32++) {
+ if (*abs32 == (*rel32)->rva()) {
+ found = true;
+ break;
+ }
}
+ EXPECT_TRUE(!found);
}
- EXPECT_FALSE(found_match);
+ delete program;
}
-
-} // namespace
TEST_F(DisassemblerElf32X86Test, All) {
TestExe("elf-32-1", 200, 3442);
}
-
-} // namespace courgette
« no previous file with comments | « courgette/disassembler_elf_32_x86.cc ('k') | courgette/disassembler_win32_x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698