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[] = { |
| 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), |
| 65 | LinkerPatch::TypePatch(16u, dex_file1, 1000u), |
| 66 | LinkerPatch::TypePatch(16u, dex_file1, 1001u), |
| 67 | LinkerPatch::TypePatch(16u, dex_file2, 1000u), |
| 68 | LinkerPatch::TypePatch(16u, dex_file2, 1001u), |
| 69 | LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3000u, 2000u), |
| 70 | LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3001u, 2000u), |
| 71 | LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3000u, 2001u), |
| 72 | LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3001u, 2001u), |
| 73 | LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3000u, 2000u), |
| 74 | LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3001u, 2000u), |
| 75 | LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3000u, 2001u), |
| 76 | LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3001u, 2001u), |
| 77 | LinkerPatch::MethodPatch(32u, dex_file1, 1000u), |
| 78 | LinkerPatch::MethodPatch(32u, dex_file1, 1001u), |
| 79 | LinkerPatch::MethodPatch(32u, dex_file2, 1000u), |
| 80 | LinkerPatch::MethodPatch(32u, dex_file2, 1001u), |
| 81 | LinkerPatch::CodePatch(32u, dex_file1, 1000u), |
| 82 | LinkerPatch::CodePatch(32u, dex_file1, 1001u), |
| 83 | LinkerPatch::CodePatch(32u, dex_file2, 1000u), |
| 84 | LinkerPatch::CodePatch(32u, dex_file2, 1001u), |
| 85 | LinkerPatch::RelativeCodePatch(32u, dex_file1, 1000u), |
| 86 | LinkerPatch::RelativeCodePatch(32u, dex_file1, 1001u), |
| 87 | LinkerPatch::RelativeCodePatch(32u, dex_file2, 1000u), |
| 88 | LinkerPatch::RelativeCodePatch(32u, dex_file2, 1001u), |
| 89 | LinkerPatch::TypePatch(32u, dex_file1, 1000u), |
| 90 | LinkerPatch::TypePatch(32u, dex_file1, 1001u), |
| 91 | LinkerPatch::TypePatch(32u, dex_file2, 1000u), |
| 92 | LinkerPatch::TypePatch(32u, dex_file2, 1001u), |
| 93 | LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3000u, 2000u), |
| 94 | LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3001u, 2000u), |
| 95 | LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3000u, 2001u), |
| 96 | LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3001u, 2001u), |
| 97 | LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3000u, 2000u), |
| 98 | LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3001u, 2000u), |
| 99 | LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3000u, 2001u), |
| 100 | LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3001u, 2001u), |
| 101 | LinkerPatch::MethodPatch(16u, dex_file2, 1001u), // identical with patch as index 3. |
| 102 | }; |
| 103 | constexpr size_t last_index = arraysize(patches) - 1u; |
| 104 | |
| 105 | for (size_t i = 0; i != arraysize(patches); ++i) { |
| 106 | for (size_t j = 0; j != arraysize(patches); ++j) { |
| 107 | bool expected = (i != last_index ? i : 3u) == (j != last_index ? j : 3u); |
| 108 | EXPECT_EQ(expected, patches[i] == patches[j]) << i << " " << j; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | for (size_t i = 0; i != arraysize(patches); ++i) { |
| 113 | for (size_t j = 0; j != arraysize(patches); ++j) { |
| 114 | bool expected = (i != last_index ? i : 3u) < (j != last_index ? j : 3u); |
| 115 | EXPECT_EQ(expected, patches[i] < patches[j]) << i << " " << j; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | } // namespace art |