blob: 72b2282adea3bb36dd87dabcc184100f079b2dae [file] [log] [blame]
Vladimir Marko35831e82015-09-11 11:59:18 +01001/*
2 * Copyright (C) 2015 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 "compiled_method.h"
20
21namespace art {
22
23TEST(CompiledMethod, SrcMapElemOperators) {
24 SrcMapElem elems[] = {
25 { 1u, -1 },
26 { 1u, 0 },
27 { 1u, 1 },
28 { 2u, -1 },
29 { 2u, 0 }, // Index 4.
30 { 2u, 1 },
31 { 2u, 0u }, // Index 6: Arbitrarily add identical SrcMapElem with index 4.
32 };
33
34 for (size_t i = 0; i != arraysize(elems); ++i) {
35 for (size_t j = 0; j != arraysize(elems); ++j) {
36 bool expected = (i != 6u ? i : 4u) == (j != 6u ? j : 4u);
37 EXPECT_EQ(expected, elems[i] == elems[j]) << i << " " << j;
38 }
39 }
40
41 for (size_t i = 0; i != arraysize(elems); ++i) {
42 for (size_t j = 0; j != arraysize(elems); ++j) {
43 bool expected = (i != 6u ? i : 4u) < (j != 6u ? j : 4u);
44 EXPECT_EQ(expected, elems[i] < elems[j]) << i << " " << j;
45 }
46 }
47}
48
49TEST(CompiledMethod, LinkerPatchOperators) {
50 const DexFile* dex_file1 = reinterpret_cast<const DexFile*>(1);
51 const DexFile* dex_file2 = reinterpret_cast<const DexFile*>(2);
52 LinkerPatch patches[] = {
Vladimir Marko65979462017-05-19 17:25:12 +010053 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3000u, 1000u),
54 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1000u),
55 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3000u, 1001u),
56 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u), // Index 3.
57 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3000u, 1000u),
58 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3001u, 1000u),
59 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3000u, 1001u),
60 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3001u, 1001u),
Vladimir Marko35831e82015-09-11 11:59:18 +010061 LinkerPatch::CodePatch(16u, dex_file1, 1000u),
62 LinkerPatch::CodePatch(16u, dex_file1, 1001u),
63 LinkerPatch::CodePatch(16u, dex_file2, 1000u),
64 LinkerPatch::CodePatch(16u, dex_file2, 1001u),
65 LinkerPatch::RelativeCodePatch(16u, dex_file1, 1000u),
66 LinkerPatch::RelativeCodePatch(16u, dex_file1, 1001u),
67 LinkerPatch::RelativeCodePatch(16u, dex_file2, 1000u),
68 LinkerPatch::RelativeCodePatch(16u, dex_file2, 1001u),
Vladimir Marko764d4542017-05-16 10:31:41 +010069 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1000u),
70 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1000u),
71 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1001u),
72 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1001u),
73 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1000u),
74 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1000u),
75 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1001u),
76 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1001u),
77 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1000u),
78 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1000u),
79 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1001u),
80 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1001u),
81 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1000u),
82 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1000u),
83 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1001u),
84 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1001u),
85 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1000u),
86 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1000u),
87 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1001u),
88 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1001u),
89 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1000u),
90 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1000u),
91 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1001u),
92 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1001u),
93 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1000u),
94 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1000u),
95 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1001u),
96 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1001u),
97 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1000u),
98 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1000u),
99 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1001u),
100 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1001u),
Vladimir Marko35831e82015-09-11 11:59:18 +0100101 LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3000u, 2000u),
102 LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3001u, 2000u),
103 LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3000u, 2001u),
104 LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3001u, 2001u),
105 LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3000u, 2000u),
106 LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3001u, 2000u),
107 LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3000u, 2001u),
108 LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3001u, 2001u),
Vladimir Marko764d4542017-05-16 10:31:41 +0100109 LinkerPatch::BakerReadBarrierBranchPatch(16u, 0u, 0u),
110 LinkerPatch::BakerReadBarrierBranchPatch(16u, 0u, 1u),
111 LinkerPatch::BakerReadBarrierBranchPatch(16u, 1u, 0u),
112 LinkerPatch::BakerReadBarrierBranchPatch(16u, 1u, 1u),
113
Vladimir Marko65979462017-05-19 17:25:12 +0100114 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3000u, 1000u),
115 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3001u, 1000u),
116 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3000u, 1001u),
117 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3001u, 1001u),
118 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3000u, 1000u),
119 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3001u, 1000u),
120 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3000u, 1001u),
121 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3001u, 1001u),
Vladimir Marko35831e82015-09-11 11:59:18 +0100122 LinkerPatch::CodePatch(32u, dex_file1, 1000u),
123 LinkerPatch::CodePatch(32u, dex_file1, 1001u),
124 LinkerPatch::CodePatch(32u, dex_file2, 1000u),
125 LinkerPatch::CodePatch(32u, dex_file2, 1001u),
126 LinkerPatch::RelativeCodePatch(32u, dex_file1, 1000u),
127 LinkerPatch::RelativeCodePatch(32u, dex_file1, 1001u),
128 LinkerPatch::RelativeCodePatch(32u, dex_file2, 1000u),
129 LinkerPatch::RelativeCodePatch(32u, dex_file2, 1001u),
Vladimir Marko764d4542017-05-16 10:31:41 +0100130 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1000u),
131 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1000u),
132 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1001u),
133 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1001u),
134 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1000u),
135 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1000u),
136 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1001u),
137 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1001u),
138 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1000u),
139 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1000u),
140 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1001u),
141 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1001u),
142 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1000u),
143 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1000u),
144 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1001u),
145 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1001u),
146 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1000u),
147 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1000u),
148 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1001u),
149 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1001u),
150 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1000u),
151 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1000u),
152 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1001u),
153 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1001u),
154 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1000u),
155 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1000u),
156 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1001u),
157 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1001u),
158 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1000u),
159 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1000u),
160 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1001u),
161 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1001u),
Vladimir Marko35831e82015-09-11 11:59:18 +0100162 LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3000u, 2000u),
163 LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3001u, 2000u),
164 LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3000u, 2001u),
165 LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3001u, 2001u),
166 LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3000u, 2000u),
167 LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3001u, 2000u),
168 LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3000u, 2001u),
169 LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3001u, 2001u),
Vladimir Marko764d4542017-05-16 10:31:41 +0100170 LinkerPatch::BakerReadBarrierBranchPatch(32u, 0u, 0u),
171 LinkerPatch::BakerReadBarrierBranchPatch(32u, 0u, 1u),
172 LinkerPatch::BakerReadBarrierBranchPatch(32u, 1u, 0u),
173 LinkerPatch::BakerReadBarrierBranchPatch(32u, 1u, 1u),
174
Vladimir Marko65979462017-05-19 17:25:12 +0100175 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u), // Same as patch at index 3.
Vladimir Marko35831e82015-09-11 11:59:18 +0100176 };
177 constexpr size_t last_index = arraysize(patches) - 1u;
178
179 for (size_t i = 0; i != arraysize(patches); ++i) {
180 for (size_t j = 0; j != arraysize(patches); ++j) {
181 bool expected = (i != last_index ? i : 3u) == (j != last_index ? j : 3u);
182 EXPECT_EQ(expected, patches[i] == patches[j]) << i << " " << j;
183 }
184 }
185
186 for (size_t i = 0; i != arraysize(patches); ++i) {
187 for (size_t j = 0; j != arraysize(patches); ++j) {
188 bool expected = (i != last_index ? i : 3u) < (j != last_index ? j : 3u);
189 EXPECT_EQ(expected, patches[i] < patches[j]) << i << " " << j;
190 }
191 }
192}
193
194} // namespace art