Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 1 | // Copyright (C) 2021 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 21 | "android/soong/java" |
| 22 | "github.com/google/blueprint" |
| 23 | ) |
| 24 | |
| 25 | // Contains tests for platform_bootclasspath logic from java/platform_bootclasspath.go that requires |
| 26 | // apexes. |
| 27 | |
| 28 | var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers( |
| 29 | java.PrepareForTestWithDexpreopt, |
| 30 | PrepareForTestWithApexBuildComponents, |
| 31 | ) |
| 32 | |
| 33 | func TestPlatformBootclasspathDependencies(t *testing.T) { |
| 34 | result := android.GroupFixturePreparers( |
| 35 | prepareForTestWithPlatformBootclasspath, |
| 36 | prepareForTestWithArtApex, |
| 37 | prepareForTestWithMyapex, |
| 38 | // Configure some libraries in the art and framework boot images. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame^] | 39 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo"), |
| 40 | java.FixtureConfigureUpdatableBootJars("myapex:bar"), |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 41 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 42 | java.FixtureWithLastReleaseApis("foo"), |
| 43 | ).RunTestWithBp(t, ` |
| 44 | apex { |
| 45 | name: "com.android.art", |
| 46 | key: "com.android.art.key", |
| 47 | bootclasspath_fragments: [ |
| 48 | "art-bootclasspath-fragment", |
| 49 | ], |
| 50 | updatable: false, |
| 51 | } |
| 52 | |
| 53 | apex_key { |
| 54 | name: "com.android.art.key", |
| 55 | public_key: "com.android.art.avbpubkey", |
| 56 | private_key: "com.android.art.pem", |
| 57 | } |
| 58 | |
| 59 | bootclasspath_fragment { |
| 60 | name: "art-bootclasspath-fragment", |
| 61 | apex_available: [ |
| 62 | "com.android.art", |
| 63 | ], |
| 64 | contents: [ |
| 65 | "baz", |
| 66 | "quuz", |
| 67 | ], |
| 68 | } |
| 69 | |
| 70 | java_library { |
| 71 | name: "baz", |
| 72 | apex_available: [ |
| 73 | "com.android.art", |
| 74 | ], |
| 75 | srcs: ["b.java"], |
| 76 | installable: true, |
| 77 | } |
| 78 | |
| 79 | // Add a java_import that is not preferred and so won't have an appropriate apex variant created |
| 80 | // for it to make sure that the platform_bootclasspath doesn't try and add a dependency onto it. |
| 81 | java_import { |
| 82 | name: "baz", |
| 83 | apex_available: [ |
| 84 | "com.android.art", |
| 85 | ], |
| 86 | jars: ["b.jar"], |
| 87 | } |
| 88 | |
| 89 | java_library { |
| 90 | name: "quuz", |
| 91 | apex_available: [ |
| 92 | "com.android.art", |
| 93 | ], |
| 94 | srcs: ["b.java"], |
| 95 | installable: true, |
| 96 | } |
| 97 | |
| 98 | apex { |
| 99 | name: "myapex", |
| 100 | key: "myapex.key", |
| 101 | java_libs: [ |
| 102 | "bar", |
| 103 | ], |
| 104 | updatable: false, |
| 105 | } |
| 106 | |
| 107 | apex_key { |
| 108 | name: "myapex.key", |
| 109 | public_key: "testkey.avbpubkey", |
| 110 | private_key: "testkey.pem", |
| 111 | } |
| 112 | |
| 113 | java_sdk_library { |
| 114 | name: "foo", |
| 115 | srcs: ["b.java"], |
| 116 | } |
| 117 | |
| 118 | java_library { |
| 119 | name: "bar", |
| 120 | srcs: ["b.java"], |
| 121 | installable: true, |
| 122 | apex_available: ["myapex"], |
| 123 | permitted_packages: ["bar"], |
| 124 | } |
| 125 | |
| 126 | platform_bootclasspath { |
| 127 | name: "myplatform-bootclasspath", |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 128 | |
| 129 | fragments: [ |
| 130 | { |
| 131 | apex: "com.android.art", |
| 132 | module: "art-bootclasspath-fragment", |
| 133 | }, |
| 134 | ], |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 135 | } |
| 136 | `, |
| 137 | ) |
| 138 | |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 139 | java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{ |
| 140 | "com.android.art:baz", |
| 141 | "com.android.art:quuz", |
| 142 | "platform:foo", |
| 143 | "myapex:bar", |
| 144 | }) |
| 145 | |
| 146 | java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{ |
| 147 | `com.android.art:art-bootclasspath-fragment`, |
| 148 | }) |
| 149 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 150 | // Make sure that the myplatform-bootclasspath has the correct dependencies. |
| 151 | CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{ |
| 152 | `platform:dex2oatd`, |
| 153 | `com.android.art:baz`, |
| 154 | `com.android.art:quuz`, |
| 155 | `platform:foo`, |
| 156 | `myapex:bar`, |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 157 | `com.android.art:art-bootclasspath-fragment`, |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 158 | }) |
| 159 | } |
| 160 | |
| 161 | // CheckModuleDependencies checks the dependencies of the selected module against the expected list. |
| 162 | // |
| 163 | // The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the |
| 164 | // name of the apex, or platform is it is not part of an apex and <module> is the module name. |
| 165 | func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) { |
| 166 | t.Helper() |
| 167 | module := ctx.ModuleForTests(name, variant).Module() |
| 168 | modules := []android.Module{} |
| 169 | ctx.VisitDirectDeps(module, func(m blueprint.Module) { |
| 170 | modules = append(modules, m.(android.Module)) |
| 171 | }) |
| 172 | |
| 173 | pairs := java.ApexNamePairsFromModules(ctx, modules) |
| 174 | android.AssertDeepEquals(t, "module dependencies", expected, pairs) |
| 175 | } |