Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 1 | /* |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 2 | * Copyright (C) 2017 The Android Open Source Project |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 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 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 19 | #include "linker_patch.h" |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 20 | |
| 21 | namespace art { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 22 | namespace linker { |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 23 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 24 | TEST(LinkerPatch, LinkerPatchOperators) { |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 25 | const DexFile* dex_file1 = reinterpret_cast<const DexFile*>(1); |
| 26 | const DexFile* dex_file2 = reinterpret_cast<const DexFile*>(2); |
| 27 | LinkerPatch patches[] = { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 28 | LinkerPatch::IntrinsicReferencePatch(16u, 3000u, 1000u), |
| 29 | LinkerPatch::IntrinsicReferencePatch(16u, 3001u, 1000u), |
| 30 | LinkerPatch::IntrinsicReferencePatch(16u, 3000u, 1001u), |
| 31 | LinkerPatch::IntrinsicReferencePatch(16u, 3001u, 1001u), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 32 | LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3000u, 1000u), |
| 33 | LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1000u), |
| 34 | LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3000u, 1001u), |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 35 | LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u), // Index 7. |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 36 | 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 Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 40 | 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 Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 48 | 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 Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 52 | 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 Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 84 | 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 Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 89 | LinkerPatch::IntrinsicReferencePatch(32u, 3000u, 1000u), |
| 90 | LinkerPatch::IntrinsicReferencePatch(32u, 3001u, 1000u), |
| 91 | LinkerPatch::IntrinsicReferencePatch(32u, 3000u, 1001u), |
| 92 | LinkerPatch::IntrinsicReferencePatch(32u, 3001u, 1001u), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 93 | 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 Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 101 | 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 Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 109 | 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 Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 113 | 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 Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 145 | 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 Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 150 | LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u), // Same as patch at index 7. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 151 | }; |
| 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 Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 156 | bool expected = (i != last_index ? i : 7u) == (j != last_index ? j : 7u); |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 157 | 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 Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 163 | bool expected = (i != last_index ? i : 7u) < (j != last_index ? j : 7u); |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 164 | EXPECT_EQ(expected, patches[i] < patches[j]) << i << " " << j; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 169 | } // namespace linker |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 170 | } // namespace art |