Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | namespace art { |
| 22 | |
| 23 | TEST(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 | |
| 49 | TEST(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 Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 53 | 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 Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 61 | LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3000u, 1000u), |
| 62 | LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3001u, 1000u), |
| 63 | LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3000u, 1001u), |
| 64 | LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3001u, 1001u), |
| 65 | LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3000u, 1000u), |
| 66 | LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3001u, 1000u), |
| 67 | LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3000u, 1001u), |
| 68 | LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3001u, 1001u), |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 69 | LinkerPatch::CodePatch(16u, dex_file1, 1000u), |
| 70 | LinkerPatch::CodePatch(16u, dex_file1, 1001u), |
| 71 | LinkerPatch::CodePatch(16u, dex_file2, 1000u), |
| 72 | LinkerPatch::CodePatch(16u, dex_file2, 1001u), |
| 73 | LinkerPatch::RelativeCodePatch(16u, dex_file1, 1000u), |
| 74 | LinkerPatch::RelativeCodePatch(16u, dex_file1, 1001u), |
| 75 | LinkerPatch::RelativeCodePatch(16u, dex_file2, 1000u), |
| 76 | LinkerPatch::RelativeCodePatch(16u, dex_file2, 1001u), |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 77 | LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1000u), |
| 78 | LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1000u), |
| 79 | LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1001u), |
| 80 | LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1001u), |
| 81 | LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1000u), |
| 82 | LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1000u), |
| 83 | LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1001u), |
| 84 | LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1001u), |
| 85 | LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1000u), |
| 86 | LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1000u), |
| 87 | LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1001u), |
| 88 | LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1001u), |
| 89 | LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1000u), |
| 90 | LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1000u), |
| 91 | LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1001u), |
| 92 | LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1001u), |
| 93 | LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1000u), |
| 94 | LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1000u), |
| 95 | LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1001u), |
| 96 | LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1001u), |
| 97 | LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1000u), |
| 98 | LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1000u), |
| 99 | LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1001u), |
| 100 | LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1001u), |
| 101 | LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1000u), |
| 102 | LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1000u), |
| 103 | LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1001u), |
| 104 | LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1001u), |
| 105 | LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1000u), |
| 106 | LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1000u), |
| 107 | LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1001u), |
| 108 | LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1001u), |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 109 | 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 Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 114 | 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 Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 122 | LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3000u, 1000u), |
| 123 | LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3001u, 1000u), |
| 124 | LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3000u, 1001u), |
| 125 | LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3001u, 1001u), |
| 126 | LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3000u, 1000u), |
| 127 | LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3001u, 1000u), |
| 128 | LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3000u, 1001u), |
| 129 | LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3001u, 1001u), |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 130 | LinkerPatch::CodePatch(32u, dex_file1, 1000u), |
| 131 | LinkerPatch::CodePatch(32u, dex_file1, 1001u), |
| 132 | LinkerPatch::CodePatch(32u, dex_file2, 1000u), |
| 133 | LinkerPatch::CodePatch(32u, dex_file2, 1001u), |
| 134 | LinkerPatch::RelativeCodePatch(32u, dex_file1, 1000u), |
| 135 | LinkerPatch::RelativeCodePatch(32u, dex_file1, 1001u), |
| 136 | LinkerPatch::RelativeCodePatch(32u, dex_file2, 1000u), |
| 137 | LinkerPatch::RelativeCodePatch(32u, dex_file2, 1001u), |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 138 | LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1000u), |
| 139 | LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1000u), |
| 140 | LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1001u), |
| 141 | LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1001u), |
| 142 | LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1000u), |
| 143 | LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1000u), |
| 144 | LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1001u), |
| 145 | LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1001u), |
| 146 | LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1000u), |
| 147 | LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1000u), |
| 148 | LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1001u), |
| 149 | LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1001u), |
| 150 | LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1000u), |
| 151 | LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1000u), |
| 152 | LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1001u), |
| 153 | LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1001u), |
| 154 | LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1000u), |
| 155 | LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1000u), |
| 156 | LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1001u), |
| 157 | LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1001u), |
| 158 | LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1000u), |
| 159 | LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1000u), |
| 160 | LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1001u), |
| 161 | LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1001u), |
| 162 | LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1000u), |
| 163 | LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1000u), |
| 164 | LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1001u), |
| 165 | LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1001u), |
| 166 | LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1000u), |
| 167 | LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1000u), |
| 168 | LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1001u), |
| 169 | LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1001u), |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 170 | 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 Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 175 | LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u), // Same as patch at index 3. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 176 | }; |
| 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 |