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

Side by Side Diff: courgette/disassembler_elf_32_x86_unittest.cc

Issue 2583373002: [Courgette] Simple AssemblyProgram and Disassembler cleanups. (Closed)
Patch Set: Tune up header inclusion. Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « courgette/disassembler_elf_32.cc ('k') | courgette/disassembler_win32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "courgette/disassembler_elf_32_x86.h" 5 #include "courgette/disassembler_elf_32_x86.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/memory/ptr_util.h"
17 #include "courgette/assembly_program.h" 18 #include "courgette/assembly_program.h"
18 #include "courgette/base_test_unittest.h" 19 #include "courgette/base_test_unittest.h"
19 #include "courgette/image_utils.h" 20 #include "courgette/image_utils.h"
20 21
21 namespace courgette { 22 namespace courgette {
22 23
23 namespace { 24 namespace {
24 25
25 class TestDisassemblerElf32X86 : public DisassemblerElf32X86 { 26 class TestDisassemblerElf32X86 : public DisassemblerElf32X86 {
26 public: 27 public:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 void TestExe(const char* file_name, 63 void TestExe(const char* file_name,
63 size_t expected_abs_count, 64 size_t expected_abs_count,
64 size_t expected_rel_count) const; 65 size_t expected_rel_count) const;
65 }; 66 };
66 67
67 void DisassemblerElf32X86Test::TestExe(const char* file_name, 68 void DisassemblerElf32X86Test::TestExe(const char* file_name,
68 size_t expected_abs_count, 69 size_t expected_abs_count,
69 size_t expected_rel_count) const { 70 size_t expected_rel_count) const {
70 std::string file1 = FileContents(file_name); 71 std::string file1 = FileContents(file_name);
71 72
72 std::unique_ptr<TestDisassemblerElf32X86> disassembler( 73 auto disassembler = base::MakeUnique<TestDisassemblerElf32X86>(
73 new TestDisassemblerElf32X86( 74 reinterpret_cast<const uint8_t*>(file1.c_str()), file1.length());
74 reinterpret_cast<const uint8_t*>(file1.c_str()), file1.length()));
75 75
76 bool can_parse_header = disassembler->ParseHeader(); 76 bool can_parse_header = disassembler->ParseHeader();
77 EXPECT_TRUE(can_parse_header); 77 EXPECT_TRUE(can_parse_header);
78 EXPECT_TRUE(disassembler->ok()); 78 EXPECT_TRUE(disassembler->ok());
79 79
80 // The length of the disassembled value will be slightly smaller than the 80 // The length of the disassembled value will be slightly smaller than the
81 // real file, since trailing debug info is not included 81 // real file, since trailing debug info is not included
82 EXPECT_EQ(file1.length(), disassembler->length()); 82 EXPECT_EQ(file1.length(), disassembler->length());
83 83
84 const uint8_t* offset_p = disassembler->FileOffsetToPointer(0); 84 const uint8_t* offset_p = disassembler->FileOffsetToPointer(0);
85 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), 85 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()),
86 reinterpret_cast<const void*>(offset_p)); 86 reinterpret_cast<const void*>(offset_p));
87 EXPECT_EQ(0x7F, offset_p[0]); 87 EXPECT_EQ(0x7F, offset_p[0]);
88 EXPECT_EQ('E', offset_p[1]); 88 EXPECT_EQ('E', offset_p[1]);
89 EXPECT_EQ('L', offset_p[2]); 89 EXPECT_EQ('L', offset_p[2]);
90 EXPECT_EQ('F', offset_p[3]); 90 EXPECT_EQ('F', offset_p[3]);
91 91
92 std::unique_ptr<AssemblyProgram> program(new AssemblyProgram(EXE_ELF_32_X86)); 92 auto program = base::MakeUnique<AssemblyProgram>(EXE_ELF_32_X86, 0);
93 93
94 EXPECT_TRUE(disassembler->Disassemble(program.get())); 94 EXPECT_TRUE(disassembler->Disassemble(program.get()));
95 95
96 const std::vector<RVA>& abs32_list = disassembler->Abs32Locations(); 96 const std::vector<RVA>& abs32_list = disassembler->Abs32Locations();
97 97
98 // Flatten the list typed rel32 to a list of rel32 RVAs. 98 // Flatten the list typed rel32 to a list of rel32 RVAs.
99 std::vector<RVA> rel32_list; 99 std::vector<RVA> rel32_list;
100 rel32_list.reserve(disassembler->Rel32Locations().size()); 100 rel32_list.reserve(disassembler->Rel32Locations().size());
101 for (auto& typed_rel32 : disassembler->Rel32Locations()) 101 for (auto& typed_rel32 : disassembler->Rel32Locations())
102 rel32_list.push_back(typed_rel32->rva()); 102 rel32_list.push_back(typed_rel32->rva());
(...skipping 26 matching lines...) Expand all
129 } 129 }
130 130
131 } // namespace 131 } // namespace
132 132
133 TEST_F(DisassemblerElf32X86Test, All) { 133 TEST_F(DisassemblerElf32X86Test, All) {
134 TestExe("elf-32-1", 200, 3337); 134 TestExe("elf-32-1", 200, 3337);
135 TestExe("elf-32-high-bss", 0, 4); 135 TestExe("elf-32-high-bss", 0, 4);
136 } 136 }
137 137
138 } // namespace courgette 138 } // namespace courgette
OLDNEW
« no previous file with comments | « courgette/disassembler_elf_32.cc ('k') | courgette/disassembler_win32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698