1 /*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <gtest/gtest.h>
18
19 #include "base/macros.h"
20 #include "linker_patch.h"
21
22 namespace art HIDDEN {
23 namespace linker {
24
TEST(LinkerPatch,LinkerPatchOperators)25 TEST(LinkerPatch, LinkerPatchOperators) {
26 const DexFile* dex_file1 = reinterpret_cast<const DexFile*>(1);
27 const DexFile* dex_file2 = reinterpret_cast<const DexFile*>(2);
28 LinkerPatch patches[] = {
29 LinkerPatch::IntrinsicReferencePatch(16u, 3000u, 1000u),
30 LinkerPatch::IntrinsicReferencePatch(16u, 3001u, 1000u),
31 LinkerPatch::IntrinsicReferencePatch(16u, 3000u, 1001u),
32 LinkerPatch::IntrinsicReferencePatch(16u, 3001u, 1001u),
33 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3000u, 1000u),
34 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1000u),
35 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3000u, 1001u),
36 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u), // Index 7.
37 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3000u, 1000u),
38 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3001u, 1000u),
39 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3000u, 1001u),
40 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3001u, 1001u),
41 LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3000u, 1000u),
42 LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3001u, 1000u),
43 LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3000u, 1001u),
44 LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3001u, 1001u),
45 LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3000u, 1000u),
46 LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3001u, 1000u),
47 LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3000u, 1001u),
48 LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3001u, 1001u),
49 LinkerPatch::RelativeCodePatch(16u, dex_file1, 1000u),
50 LinkerPatch::RelativeCodePatch(16u, dex_file1, 1001u),
51 LinkerPatch::RelativeCodePatch(16u, dex_file2, 1000u),
52 LinkerPatch::RelativeCodePatch(16u, dex_file2, 1001u),
53 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1000u),
54 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1000u),
55 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1001u),
56 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1001u),
57 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1000u),
58 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1000u),
59 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1001u),
60 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1001u),
61 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1000u),
62 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1000u),
63 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1001u),
64 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1001u),
65 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1000u),
66 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1000u),
67 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1001u),
68 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1001u),
69 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1000u),
70 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1000u),
71 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1001u),
72 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1001u),
73 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1000u),
74 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1000u),
75 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1001u),
76 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1001u),
77 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1000u),
78 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1000u),
79 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1001u),
80 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1001u),
81 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1000u),
82 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1000u),
83 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1001u),
84 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1001u),
85 LinkerPatch::BakerReadBarrierBranchPatch(16u, 0u, 0u),
86 LinkerPatch::BakerReadBarrierBranchPatch(16u, 0u, 1u),
87 LinkerPatch::BakerReadBarrierBranchPatch(16u, 1u, 0u),
88 LinkerPatch::BakerReadBarrierBranchPatch(16u, 1u, 1u),
89
90 LinkerPatch::IntrinsicReferencePatch(32u, 3000u, 1000u),
91 LinkerPatch::IntrinsicReferencePatch(32u, 3001u, 1000u),
92 LinkerPatch::IntrinsicReferencePatch(32u, 3000u, 1001u),
93 LinkerPatch::IntrinsicReferencePatch(32u, 3001u, 1001u),
94 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3000u, 1000u),
95 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3001u, 1000u),
96 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3000u, 1001u),
97 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3001u, 1001u),
98 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3000u, 1000u),
99 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3001u, 1000u),
100 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3000u, 1001u),
101 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3001u, 1001u),
102 LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3000u, 1000u),
103 LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3001u, 1000u),
104 LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3000u, 1001u),
105 LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3001u, 1001u),
106 LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3000u, 1000u),
107 LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3001u, 1000u),
108 LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3000u, 1001u),
109 LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3001u, 1001u),
110 LinkerPatch::RelativeCodePatch(32u, dex_file1, 1000u),
111 LinkerPatch::RelativeCodePatch(32u, dex_file1, 1001u),
112 LinkerPatch::RelativeCodePatch(32u, dex_file2, 1000u),
113 LinkerPatch::RelativeCodePatch(32u, dex_file2, 1001u),
114 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1000u),
115 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1000u),
116 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1001u),
117 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1001u),
118 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1000u),
119 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1000u),
120 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1001u),
121 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1001u),
122 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1000u),
123 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1000u),
124 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1001u),
125 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1001u),
126 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1000u),
127 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1000u),
128 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1001u),
129 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1001u),
130 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1000u),
131 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1000u),
132 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1001u),
133 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1001u),
134 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1000u),
135 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1000u),
136 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1001u),
137 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1001u),
138 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1000u),
139 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1000u),
140 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1001u),
141 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1001u),
142 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1000u),
143 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1000u),
144 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1001u),
145 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1001u),
146 LinkerPatch::BakerReadBarrierBranchPatch(32u, 0u, 0u),
147 LinkerPatch::BakerReadBarrierBranchPatch(32u, 0u, 1u),
148 LinkerPatch::BakerReadBarrierBranchPatch(32u, 1u, 0u),
149 LinkerPatch::BakerReadBarrierBranchPatch(32u, 1u, 1u),
150
151 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u), // Same as patch at index 7.
152 };
153 constexpr size_t last_index = arraysize(patches) - 1u;
154
155 for (size_t i = 0; i != arraysize(patches); ++i) {
156 for (size_t j = 0; j != arraysize(patches); ++j) {
157 bool expected = (i != last_index ? i : 7u) == (j != last_index ? j : 7u);
158 EXPECT_EQ(expected, patches[i] == patches[j]) << i << " " << j;
159 }
160 }
161
162 for (size_t i = 0; i != arraysize(patches); ++i) {
163 for (size_t j = 0; j != arraysize(patches); ++j) {
164 bool expected = (i != last_index ? i : 7u) < (j != last_index ? j : 7u);
165 EXPECT_EQ(expected, patches[i] < patches[j]) << i << " " << j;
166 }
167 }
168 }
169
170 } // namespace linker
171 } // namespace art
172