blob: 997418c4f7f591d7db8e0dcc91818e0191454b87 [file] [log] [blame]
Vladimir Marko35831e82015-09-11 11:59:18 +01001/*
Vladimir Markod8dbc8d2017-09-20 13:37:47 +01002 * Copyright (C) 2017 The Android Open Source Project
Vladimir Marko35831e82015-09-11 11:59:18 +01003 *
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
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010019#include "linker_patch.h"
Vladimir Marko35831e82015-09-11 11:59:18 +010020
21namespace art {
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010022namespace linker {
Vladimir Marko35831e82015-09-11 11:59:18 +010023
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010024TEST(LinkerPatch, LinkerPatchOperators) {
Vladimir Marko35831e82015-09-11 11:59:18 +010025 const DexFile* dex_file1 = reinterpret_cast<const DexFile*>(1);
26 const DexFile* dex_file2 = reinterpret_cast<const DexFile*>(2);
27 LinkerPatch patches[] = {
Vladimir Marko8e524ad2018-07-13 10:27:43 +010028 LinkerPatch::IntrinsicReferencePatch(16u, 3000u, 1000u),
29 LinkerPatch::IntrinsicReferencePatch(16u, 3001u, 1000u),
30 LinkerPatch::IntrinsicReferencePatch(16u, 3000u, 1001u),
31 LinkerPatch::IntrinsicReferencePatch(16u, 3001u, 1001u),
Vladimir Marko65979462017-05-19 17:25:12 +010032 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3000u, 1000u),
33 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1000u),
34 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3000u, 1001u),
Vladimir Marko8e524ad2018-07-13 10:27:43 +010035 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u), // Index 7.
Vladimir Marko65979462017-05-19 17:25:12 +010036 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3000u, 1000u),
37 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3001u, 1000u),
38 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3000u, 1001u),
39 LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3001u, 1001u),
Vladimir Marko0eb882b2017-05-15 13:39:18 +010040 LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3000u, 1000u),
41 LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3001u, 1000u),
42 LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3000u, 1001u),
43 LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3001u, 1001u),
44 LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3000u, 1000u),
45 LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3001u, 1000u),
46 LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3000u, 1001u),
47 LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3001u, 1001u),
Vladimir Marko35831e82015-09-11 11:59:18 +010048 LinkerPatch::RelativeCodePatch(16u, dex_file1, 1000u),
49 LinkerPatch::RelativeCodePatch(16u, dex_file1, 1001u),
50 LinkerPatch::RelativeCodePatch(16u, dex_file2, 1000u),
51 LinkerPatch::RelativeCodePatch(16u, dex_file2, 1001u),
Vladimir Marko764d4542017-05-16 10:31:41 +010052 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1000u),
53 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1000u),
54 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1001u),
55 LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1001u),
56 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1000u),
57 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1000u),
58 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1001u),
59 LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1001u),
60 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1000u),
61 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1000u),
62 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1001u),
63 LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1001u),
64 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1000u),
65 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1000u),
66 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1001u),
67 LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1001u),
68 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1000u),
69 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1000u),
70 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1001u),
71 LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1001u),
72 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1000u),
73 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1000u),
74 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1001u),
75 LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1001u),
76 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1000u),
77 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1000u),
78 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1001u),
79 LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1001u),
80 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1000u),
81 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1000u),
82 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1001u),
83 LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1001u),
Vladimir Marko764d4542017-05-16 10:31:41 +010084 LinkerPatch::BakerReadBarrierBranchPatch(16u, 0u, 0u),
85 LinkerPatch::BakerReadBarrierBranchPatch(16u, 0u, 1u),
86 LinkerPatch::BakerReadBarrierBranchPatch(16u, 1u, 0u),
87 LinkerPatch::BakerReadBarrierBranchPatch(16u, 1u, 1u),
88
Vladimir Marko8e524ad2018-07-13 10:27:43 +010089 LinkerPatch::IntrinsicReferencePatch(32u, 3000u, 1000u),
90 LinkerPatch::IntrinsicReferencePatch(32u, 3001u, 1000u),
91 LinkerPatch::IntrinsicReferencePatch(32u, 3000u, 1001u),
92 LinkerPatch::IntrinsicReferencePatch(32u, 3001u, 1001u),
Vladimir Marko65979462017-05-19 17:25:12 +010093 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3000u, 1000u),
94 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3001u, 1000u),
95 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3000u, 1001u),
96 LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3001u, 1001u),
97 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3000u, 1000u),
98 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3001u, 1000u),
99 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3000u, 1001u),
100 LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3001u, 1001u),
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100101 LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3000u, 1000u),
102 LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3001u, 1000u),
103 LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3000u, 1001u),
104 LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3001u, 1001u),
105 LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3000u, 1000u),
106 LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3001u, 1000u),
107 LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3000u, 1001u),
108 LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3001u, 1001u),
Vladimir Marko35831e82015-09-11 11:59:18 +0100109 LinkerPatch::RelativeCodePatch(32u, dex_file1, 1000u),
110 LinkerPatch::RelativeCodePatch(32u, dex_file1, 1001u),
111 LinkerPatch::RelativeCodePatch(32u, dex_file2, 1000u),
112 LinkerPatch::RelativeCodePatch(32u, dex_file2, 1001u),
Vladimir Marko764d4542017-05-16 10:31:41 +0100113 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1000u),
114 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1000u),
115 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1001u),
116 LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1001u),
117 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1000u),
118 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1000u),
119 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1001u),
120 LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1001u),
121 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1000u),
122 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1000u),
123 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1001u),
124 LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1001u),
125 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1000u),
126 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1000u),
127 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1001u),
128 LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1001u),
129 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1000u),
130 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1000u),
131 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1001u),
132 LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1001u),
133 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1000u),
134 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1000u),
135 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1001u),
136 LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1001u),
137 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1000u),
138 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1000u),
139 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1001u),
140 LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1001u),
141 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1000u),
142 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1000u),
143 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1001u),
144 LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1001u),
Vladimir Marko764d4542017-05-16 10:31:41 +0100145 LinkerPatch::BakerReadBarrierBranchPatch(32u, 0u, 0u),
146 LinkerPatch::BakerReadBarrierBranchPatch(32u, 0u, 1u),
147 LinkerPatch::BakerReadBarrierBranchPatch(32u, 1u, 0u),
148 LinkerPatch::BakerReadBarrierBranchPatch(32u, 1u, 1u),
149
Vladimir Marko8e524ad2018-07-13 10:27:43 +0100150 LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u), // Same as patch at index 7.
Vladimir Marko35831e82015-09-11 11:59:18 +0100151 };
152 constexpr size_t last_index = arraysize(patches) - 1u;
153
154 for (size_t i = 0; i != arraysize(patches); ++i) {
155 for (size_t j = 0; j != arraysize(patches); ++j) {
Vladimir Marko8e524ad2018-07-13 10:27:43 +0100156 bool expected = (i != last_index ? i : 7u) == (j != last_index ? j : 7u);
Vladimir Marko35831e82015-09-11 11:59:18 +0100157 EXPECT_EQ(expected, patches[i] == patches[j]) << i << " " << j;
158 }
159 }
160
161 for (size_t i = 0; i != arraysize(patches); ++i) {
162 for (size_t j = 0; j != arraysize(patches); ++j) {
Vladimir Marko8e524ad2018-07-13 10:27:43 +0100163 bool expected = (i != last_index ? i : 7u) < (j != last_index ? j : 7u);
Vladimir Marko35831e82015-09-11 11:59:18 +0100164 EXPECT_EQ(expected, patches[i] < patches[j]) << i << " " << j;
165 }
166 }
167}
168
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100169} // namespace linker
Vladimir Marko35831e82015-09-11 11:59:18 +0100170} // namespace art