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

Side by Side Diff: courgette/disassembler_elf_32_x86_unittest.cc

Issue 2055343002: Courgette: Add static method QuickDetect() to optimize program detection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Propagate uint8_t* to unittests and Nits Created 4 years, 6 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
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 "courgette/assembly_program.h" 17 #include "courgette/assembly_program.h"
18 #include "courgette/base_test_unittest.h" 18 #include "courgette/base_test_unittest.h"
19 #include "courgette/image_utils.h" 19 #include "courgette/image_utils.h"
20 20
21 namespace courgette { 21 namespace courgette {
22 22
23 namespace { 23 namespace {
24 24
25 class TestDisassemblerElf32X86 : public DisassemblerElf32X86 { 25 class TestDisassemblerElf32X86 : public DisassemblerElf32X86 {
26 public: 26 public:
27 TestDisassemblerElf32X86(const void* start, size_t length) 27 TestDisassemblerElf32X86(const uint8_t* start, size_t length)
28 : DisassemblerElf32X86(start, length) { } 28 : DisassemblerElf32X86(start, length) {}
29 ~TestDisassemblerElf32X86() override { } 29 ~TestDisassemblerElf32X86() override { }
huangs 2016/06/15 00:13:04 May as well change "{ }" to "{}" in this line.
etiennep 2016/06/15 20:38:06 Done.
30 30
31 void TestSectionHeaderFileOffsetOrder() { 31 void TestSectionHeaderFileOffsetOrder() {
32 std::vector<FileOffset> file_offsets; 32 std::vector<FileOffset> file_offsets;
33 for (Elf32_Half section_id : section_header_file_offset_order_) { 33 for (Elf32_Half section_id : section_header_file_offset_order_) {
34 const Elf32_Shdr* section_header = SectionHeader(section_id); 34 const Elf32_Shdr* section_header = SectionHeader(section_id);
35 file_offsets.push_back(section_header->sh_offset); 35 file_offsets.push_back(section_header->sh_offset);
36 } 36 }
37 EXPECT_EQ(static_cast<size_t>(SectionHeaderCount()), file_offsets.size()); 37 EXPECT_EQ(static_cast<size_t>(SectionHeaderCount()), file_offsets.size());
38 EXPECT_TRUE(std::is_sorted(file_offsets.begin(), file_offsets.end())); 38 EXPECT_TRUE(std::is_sorted(file_offsets.begin(), file_offsets.end()));
39 } 39 }
(...skipping 23 matching lines...) Expand all
63 size_t expected_abs_count, 63 size_t expected_abs_count,
64 size_t expected_rel_count) const; 64 size_t expected_rel_count) const;
65 }; 65 };
66 66
67 void DisassemblerElf32X86Test::TestExe(const char* file_name, 67 void DisassemblerElf32X86Test::TestExe(const char* file_name,
68 size_t expected_abs_count, 68 size_t expected_abs_count,
69 size_t expected_rel_count) const { 69 size_t expected_rel_count) const {
70 std::string file1 = FileContents(file_name); 70 std::string file1 = FileContents(file_name);
71 71
72 std::unique_ptr<TestDisassemblerElf32X86> disassembler( 72 std::unique_ptr<TestDisassemblerElf32X86> disassembler(
73 new TestDisassemblerElf32X86(file1.c_str(), file1.length())); 73 new TestDisassemblerElf32X86(
74 reinterpret_cast<const uint8_t*>(file1.c_str()), file1.length()));
74 75
75 bool can_parse_header = disassembler->ParseHeader(); 76 bool can_parse_header = disassembler->ParseHeader();
76 EXPECT_TRUE(can_parse_header); 77 EXPECT_TRUE(can_parse_header);
77 EXPECT_TRUE(disassembler->ok()); 78 EXPECT_TRUE(disassembler->ok());
78 79
79 // 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
80 // real file, since trailing debug info is not included 81 // real file, since trailing debug info is not included
81 EXPECT_EQ(file1.length(), disassembler->length()); 82 EXPECT_EQ(file1.length(), disassembler->length());
82 83
83 const uint8_t* offset_p = disassembler->FileOffsetToPointer(0); 84 const uint8_t* offset_p = disassembler->FileOffsetToPointer(0);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 129 }
129 130
130 } // namespace 131 } // namespace
131 132
132 TEST_F(DisassemblerElf32X86Test, All) { 133 TEST_F(DisassemblerElf32X86Test, All) {
133 TestExe("elf-32-1", 200, 3337); 134 TestExe("elf-32-1", 200, 3337);
134 TestExe("elf-32-high-bss", 0, 4); 135 TestExe("elf-32-high-bss", 0, 4);
135 } 136 }
136 137
137 } // namespace courgette 138 } // namespace courgette
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698