blob: 81a2cde794daf617ff634868039b6e1ad7da0521 [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[] = {
53 LinkerPatch::MethodPatch(16u, dex_file1, 1000u),
54 LinkerPatch::MethodPatch(16u, dex_file1, 1001u),
55 LinkerPatch::MethodPatch(16u, dex_file2, 1000u),
56 LinkerPatch::MethodPatch(16u, dex_file2, 1001u), // Index 3.
57 LinkerPatch::CodePatch(16u, dex_file1, 1000u),
58 LinkerPatch::CodePatch(16u, dex_file1, 1001u),
59 LinkerPatch::CodePatch(16u, dex_file2, 1000u),
60 LinkerPatch::CodePatch(16u, dex_file2, 1001u),
61 LinkerPatch::RelativeCodePatch(16u, dex_file1, 1000u),
62 LinkerPatch::RelativeCodePatch(16u, dex_file1, 1001u),
63 LinkerPatch::RelativeCodePatch(16u, dex_file2, 1000u),
64 LinkerPatch::RelativeCodePatch(16u, dex_file2, 1001u),
Vladimir Marko764d4542017-05-16 10:31:41 +010065 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1000u),
66 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1000u),
67 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1001u),
68 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1001u),
69 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1000u),
70 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1000u),
71 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1001u),
72 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1001u),
73 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1000u),
74 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1000u),
75 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1001u),
76 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1001u),
77 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1000u),
78 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1000u),
79 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1001u),
80 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1001u),
81 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1000u),
82 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1000u),
83 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1001u),
84 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1001u),
85 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1000u),
86 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1000u),
87 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1001u),
88 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1001u),
89 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1000u),
90 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1000u),
91 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1001u),
92 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1001u),
93 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1000u),
94 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1000u),
95 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1001u),
96 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1001u),
Vladimir Marko35831e82015-09-11 11:59:18 +010097 LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3000u, 2000u),
98 LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3001u, 2000u),
99 LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3000u, 2001u),
100 LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3001u, 2001u),
101 LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3000u, 2000u),
102 LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3001u, 2000u),
103 LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3000u, 2001u),
104 LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3001u, 2001u),
Vladimir Marko764d4542017-05-16 10:31:41 +0100105 LinkerPatch::BakerReadBarrierBranchPatch(16u, 0u, 0u),
106 LinkerPatch::BakerReadBarrierBranchPatch(16u, 0u, 1u),
107 LinkerPatch::BakerReadBarrierBranchPatch(16u, 1u, 0u),
108 LinkerPatch::BakerReadBarrierBranchPatch(16u, 1u, 1u),
109
Vladimir Marko35831e82015-09-11 11:59:18 +0100110 LinkerPatch::MethodPatch(32u, dex_file1, 1000u),
111 LinkerPatch::MethodPatch(32u, dex_file1, 1001u),
112 LinkerPatch::MethodPatch(32u, dex_file2, 1000u),
Vladimir Marko764d4542017-05-16 10:31:41 +0100113 LinkerPatch::MethodPatch(32u, dex_file2, 1001u), // Index 3.
Vladimir Marko35831e82015-09-11 11:59:18 +0100114 LinkerPatch::CodePatch(32u, dex_file1, 1000u),
115 LinkerPatch::CodePatch(32u, dex_file1, 1001u),
116 LinkerPatch::CodePatch(32u, dex_file2, 1000u),
117 LinkerPatch::CodePatch(32u, dex_file2, 1001u),
118 LinkerPatch::RelativeCodePatch(32u, dex_file1, 1000u),
119 LinkerPatch::RelativeCodePatch(32u, dex_file1, 1001u),
120 LinkerPatch::RelativeCodePatch(32u, dex_file2, 1000u),
121 LinkerPatch::RelativeCodePatch(32u, dex_file2, 1001u),
Vladimir Marko764d4542017-05-16 10:31:41 +0100122 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1000u),
123 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1000u),
124 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1001u),
125 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1001u),
126 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1000u),
127 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1000u),
128 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1001u),
129 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1001u),
130 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1000u),
131 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1000u),
132 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1001u),
133 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1001u),
134 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1000u),
135 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1000u),
136 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1001u),
137 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1001u),
138 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1000u),
139 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1000u),
140 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1001u),
141 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1001u),
142 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1000u),
143 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1000u),
144 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1001u),
145 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1001u),
146 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1000u),
147 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1000u),
148 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1001u),
149 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1001u),
150 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1000u),
151 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1000u),
152 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1001u),
153 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1001u),
Vladimir Marko35831e82015-09-11 11:59:18 +0100154 LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3000u, 2000u),
155 LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3001u, 2000u),
156 LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3000u, 2001u),
157 LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3001u, 2001u),
158 LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3000u, 2000u),
159 LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3001u, 2000u),
160 LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3000u, 2001u),
161 LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3001u, 2001u),
Vladimir Marko764d4542017-05-16 10:31:41 +0100162 LinkerPatch::BakerReadBarrierBranchPatch(32u, 0u, 0u),
163 LinkerPatch::BakerReadBarrierBranchPatch(32u, 0u, 1u),
164 LinkerPatch::BakerReadBarrierBranchPatch(32u, 1u, 0u),
165 LinkerPatch::BakerReadBarrierBranchPatch(32u, 1u, 1u),
166
167 LinkerPatch::MethodPatch(16u, dex_file2, 1001u), // identical with patch at index 3.
Vladimir Marko35831e82015-09-11 11:59:18 +0100168 };
169 constexpr size_t last_index = arraysize(patches) - 1u;
170
171 for (size_t i = 0; i != arraysize(patches); ++i) {
172 for (size_t j = 0; j != arraysize(patches); ++j) {
173 bool expected = (i != last_index ? i : 3u) == (j != last_index ? j : 3u);
174 EXPECT_EQ(expected, patches[i] == patches[j]) << i << " " << j;
175 }
176 }
177
178 for (size_t i = 0; i != arraysize(patches); ++i) {
179 for (size_t j = 0; j != arraysize(patches); ++j) {
180 bool expected = (i != last_index ? i : 3u) < (j != last_index ? j : 3u);
181 EXPECT_EQ(expected, patches[i] < patches[j]) << i << " " << j;
182 }
183 }
184}
185
186} // namespace art