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

Side by Side Diff: courgette/adjustment_method_unittest.cc

Issue 1935203002: [Courgette] Using LabelManager to reduce Courgette-apply peak RAM by 25%. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync. 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 unified diff | Download patch
« no previous file with comments | « no previous file | courgette/assembly_program.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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 #include <vector>
8 9
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "courgette/assembly_program.h" 11 #include "courgette/assembly_program.h"
11 #include "courgette/courgette.h" 12 #include "courgette/courgette.h"
12 #include "courgette/encoded_program.h" 13 #include "courgette/encoded_program.h"
14 #include "courgette/image_utils.h"
13 #include "courgette/streams.h" 15 #include "courgette/streams.h"
14 16
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 class AdjustmentMethodTest : public testing::Test { 19 class AdjustmentMethodTest : public testing::Test {
18 public: 20 public:
19 void Test1() const; 21 void Test1() const;
20 22
21 private: 23 private:
22 void SetUp() { 24 void SetUp() {
23 } 25 }
24 26
25 void TearDown() { 27 void TearDown() {
26 } 28 }
27 29
28 // Returns one of two similar simple programs. These differ only in Label 30 // Returns one of two similar simple programs. These differ only in Label
29 // assignment, so it is possible to make them look identical. 31 // assignment, so it is possible to make them look identical.
30 std::unique_ptr<courgette::AssemblyProgram> MakeProgram(int kind) const { 32 std::unique_ptr<courgette::AssemblyProgram> MakeProgram(int kind) const {
31 std::unique_ptr<courgette::AssemblyProgram> prog( 33 std::unique_ptr<courgette::AssemblyProgram> prog(
32 new courgette::AssemblyProgram(courgette::EXE_WIN_32_X86)); 34 new courgette::AssemblyProgram(courgette::EXE_WIN_32_X86));
33 prog->set_image_base(0x00400000); 35 prog->set_image_base(0x00400000);
34 36
35 courgette::Label* labelA = prog->FindOrMakeAbs32Label(0x00410000); 37 courgette::RVA kRvaA = 0x00410000;
36 courgette::Label* labelB = prog->FindOrMakeAbs32Label(0x00410004); 38 courgette::RVA kRvaB = 0x00410004;
39
40 std::vector<courgette::RVA> abs32_rvas;
41 abs32_rvas.push_back(kRvaA);
42 abs32_rvas.push_back(kRvaB);
43 std::vector<courgette::RVA> rel32_rvas; // Stub.
44
45 courgette::TrivialRvaVisitor abs32_visitor(abs32_rvas);
46 courgette::TrivialRvaVisitor rel32_visitor(rel32_rvas);
47 prog->PrecomputeLabels(&abs32_visitor, &rel32_visitor);
48
49 courgette::Label* labelA = prog->FindAbs32Label(kRvaA);
50 courgette::Label* labelB = prog->FindAbs32Label(kRvaB);
37 51
38 EXPECT_TRUE(prog->EmitAbs32(labelA)); 52 EXPECT_TRUE(prog->EmitAbs32(labelA));
39 EXPECT_TRUE(prog->EmitAbs32(labelA)); 53 EXPECT_TRUE(prog->EmitAbs32(labelA));
40 EXPECT_TRUE(prog->EmitAbs32(labelB)); 54 EXPECT_TRUE(prog->EmitAbs32(labelB));
41 EXPECT_TRUE(prog->EmitAbs32(labelA)); 55 EXPECT_TRUE(prog->EmitAbs32(labelA));
42 EXPECT_TRUE(prog->EmitAbs32(labelA)); 56 EXPECT_TRUE(prog->EmitAbs32(labelA));
43 EXPECT_TRUE(prog->EmitAbs32(labelB)); 57 EXPECT_TRUE(prog->EmitAbs32(labelB));
44 58
45 if (kind == 0) { 59 if (kind == 0) {
46 labelA->index_ = 0; 60 labelA->index_ = 0;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 95
82 courgette::SinkStream sink; 96 courgette::SinkStream sink;
83 bool can_collect = sinks.CopyTo(&sink); 97 bool can_collect = sinks.CopyTo(&sink);
84 EXPECT_TRUE(can_collect); 98 EXPECT_TRUE(can_collect);
85 99
86 return std::string(reinterpret_cast<const char *>(sink.Buffer()), 100 return std::string(reinterpret_cast<const char *>(sink.Buffer()),
87 sink.Length()); 101 sink.Length());
88 } 102 }
89 }; 103 };
90 104
91
92 void AdjustmentMethodTest::Test1() const { 105 void AdjustmentMethodTest::Test1() const {
93 std::unique_ptr<courgette::AssemblyProgram> prog1 = MakeProgramA(); 106 std::unique_ptr<courgette::AssemblyProgram> prog1 = MakeProgramA();
94 std::unique_ptr<courgette::AssemblyProgram> prog2 = MakeProgramB(); 107 std::unique_ptr<courgette::AssemblyProgram> prog2 = MakeProgramB();
95 std::string s1 = Serialize(std::move(prog1)); 108 std::string s1 = Serialize(std::move(prog1));
96 std::string s2 = Serialize(std::move(prog2)); 109 std::string s2 = Serialize(std::move(prog2));
97 110
98 // Don't use EXPECT_EQ because strings are unprintable. 111 // Don't use EXPECT_EQ because strings are unprintable.
99 EXPECT_FALSE(s1 == s2); // Unadjusted A and B differ. 112 EXPECT_FALSE(s1 == s2); // Unadjusted A and B differ.
100 113
101 std::unique_ptr<courgette::AssemblyProgram> prog5 = MakeProgramA(); 114 std::unique_ptr<courgette::AssemblyProgram> prog5 = MakeProgramA();
102 std::unique_ptr<courgette::AssemblyProgram> prog6 = MakeProgramB(); 115 std::unique_ptr<courgette::AssemblyProgram> prog6 = MakeProgramB();
103 courgette::Status can_adjust = Adjust(*prog5, prog6.get()); 116 courgette::Status can_adjust = Adjust(*prog5, prog6.get());
104 EXPECT_EQ(courgette::C_OK, can_adjust); 117 EXPECT_EQ(courgette::C_OK, can_adjust);
105 std::string s5 = Serialize(std::move(prog5)); 118 std::string s5 = Serialize(std::move(prog5));
106 std::string s6 = Serialize(std::move(prog6)); 119 std::string s6 = Serialize(std::move(prog6));
107 120
108 EXPECT_TRUE(s1 == s5); // Adjustment did not change A (prog5) 121 EXPECT_TRUE(s1 == s5); // Adjustment did not change A (prog5)
109 EXPECT_TRUE(s5 == s6); // Adjustment did change B into A 122 EXPECT_TRUE(s5 == s6); // Adjustment did change B into A
110 } 123 }
111 124
112
113 TEST_F(AdjustmentMethodTest, All) { 125 TEST_F(AdjustmentMethodTest, All) {
114 Test1(); 126 Test1();
115 } 127 }
OLDNEW
« no previous file with comments | « no previous file | courgette/assembly_program.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698