Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +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 ( |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 18 | "fmt" |
Jiakai Zhang | 7d3c9e0 | 2021-12-13 17:19:05 +0000 | [diff] [blame] | 19 | "path" |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 20 | "sort" |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 21 | "strings" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 22 | "testing" |
| 23 | |
| 24 | "android/soong/android" |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 25 | "android/soong/dexpreopt" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 26 | "android/soong/java" |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 27 | |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 28 | "github.com/google/blueprint/proptools" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 29 | ) |
| 30 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 31 | // Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART |
| 32 | // bootclasspath_fragment requires modules from the ART apex. |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 33 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 34 | var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers( |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 35 | java.PrepareForTestWithDexpreopt, |
| 36 | PrepareForTestWithApexBuildComponents, |
| 37 | ) |
| 38 | |
| 39 | // Some additional files needed for the art apex. |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 40 | var prepareForTestWithArtApex = android.GroupFixturePreparers( |
| 41 | android.FixtureMergeMockFs(android.MockFS{ |
| 42 | "com.android.art.avbpubkey": nil, |
| 43 | "com.android.art.pem": nil, |
| 44 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 45 | }), |
| 46 | dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"), |
| 47 | ) |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 48 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 49 | func TestBootclasspathFragments(t *testing.T) { |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 50 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 51 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 52 | // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 53 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"), |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 54 | prepareForTestWithArtApex, |
| 55 | |
| 56 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 57 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 58 | ).RunTestWithBp(t, ` |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 59 | java_sdk_library { |
| 60 | name: "foo", |
| 61 | srcs: ["b.java"], |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | java_library { |
| 65 | name: "bar", |
| 66 | srcs: ["b.java"], |
| 67 | installable: true, |
| 68 | } |
| 69 | |
| 70 | apex { |
| 71 | name: "com.android.art", |
| 72 | key: "com.android.art.key", |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 73 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 74 | java_libs: [ |
| 75 | "baz", |
| 76 | "quuz", |
| 77 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 78 | updatable: false, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | apex_key { |
| 82 | name: "com.android.art.key", |
| 83 | public_key: "com.android.art.avbpubkey", |
| 84 | private_key: "com.android.art.pem", |
| 85 | } |
| 86 | |
| 87 | java_library { |
| 88 | name: "baz", |
| 89 | apex_available: [ |
| 90 | "com.android.art", |
| 91 | ], |
| 92 | srcs: ["b.java"], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 93 | compile_dex: true, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | java_library { |
| 97 | name: "quuz", |
| 98 | apex_available: [ |
| 99 | "com.android.art", |
| 100 | ], |
| 101 | srcs: ["b.java"], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 102 | compile_dex: true, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 103 | } |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 104 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 105 | bootclasspath_fragment { |
| 106 | name: "art-bootclasspath-fragment", |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 107 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 108 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 109 | contents: ["baz", "quuz"], |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 110 | apex_available: [ |
| 111 | "com.android.art", |
| 112 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 113 | hidden_api: { |
| 114 | split_packages: ["*"], |
| 115 | }, |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 116 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 117 | `, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 118 | ) |
| 119 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 120 | // Make sure that the art-bootclasspath-fragment is using the correct configuration. |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 121 | checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000", |
| 122 | "com.android.art:baz,com.android.art:quuz", ` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 123 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art |
| 124 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat |
| 125 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex |
| 126 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art |
| 127 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat |
| 128 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex |
| 129 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art |
| 130 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat |
| 131 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex |
| 132 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art |
| 133 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat |
| 134 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex |
| 135 | `) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 138 | func TestBootclasspathFragments_FragmentDependency(t *testing.T) { |
| 139 | result := android.GroupFixturePreparers( |
| 140 | prepareForTestWithBootclasspathFragment, |
| 141 | // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 142 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 143 | java.FixtureConfigureApexBootJars("someapex:foo", "someapex:bar"), |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 144 | prepareForTestWithArtApex, |
| 145 | |
| 146 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 147 | java.FixtureWithLastReleaseApis("foo", "baz"), |
| 148 | ).RunTestWithBp(t, ` |
| 149 | java_sdk_library { |
| 150 | name: "foo", |
| 151 | srcs: ["b.java"], |
| 152 | shared_library: false, |
| 153 | public: { |
| 154 | enabled: true, |
| 155 | }, |
| 156 | system: { |
| 157 | enabled: true, |
| 158 | }, |
| 159 | } |
| 160 | |
| 161 | java_library { |
| 162 | name: "bar", |
| 163 | srcs: ["b.java"], |
| 164 | installable: true, |
| 165 | } |
| 166 | |
| 167 | apex { |
| 168 | name: "com.android.art", |
| 169 | key: "com.android.art.key", |
| 170 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 171 | updatable: false, |
| 172 | } |
| 173 | |
| 174 | apex_key { |
| 175 | name: "com.android.art.key", |
| 176 | public_key: "com.android.art.avbpubkey", |
| 177 | private_key: "com.android.art.pem", |
| 178 | } |
| 179 | |
| 180 | java_sdk_library { |
| 181 | name: "baz", |
| 182 | apex_available: [ |
| 183 | "com.android.art", |
| 184 | ], |
| 185 | srcs: ["b.java"], |
| 186 | shared_library: false, |
| 187 | public: { |
| 188 | enabled: true, |
| 189 | }, |
| 190 | system: { |
| 191 | enabled: true, |
| 192 | }, |
| 193 | test: { |
| 194 | enabled: true, |
| 195 | }, |
| 196 | } |
| 197 | |
| 198 | java_library { |
| 199 | name: "quuz", |
| 200 | apex_available: [ |
| 201 | "com.android.art", |
| 202 | ], |
| 203 | srcs: ["b.java"], |
| 204 | compile_dex: true, |
| 205 | } |
| 206 | |
| 207 | bootclasspath_fragment { |
| 208 | name: "art-bootclasspath-fragment", |
| 209 | image_name: "art", |
| 210 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 211 | contents: ["baz", "quuz"], |
| 212 | apex_available: [ |
| 213 | "com.android.art", |
| 214 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 215 | hidden_api: { |
| 216 | split_packages: ["*"], |
| 217 | }, |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | bootclasspath_fragment { |
| 221 | name: "other-bootclasspath-fragment", |
| 222 | contents: ["foo", "bar"], |
| 223 | fragments: [ |
| 224 | { |
| 225 | apex: "com.android.art", |
| 226 | module: "art-bootclasspath-fragment", |
| 227 | }, |
| 228 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 229 | hidden_api: { |
| 230 | split_packages: ["*"], |
| 231 | }, |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 232 | } |
| 233 | `, |
| 234 | ) |
| 235 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 236 | checkAPIScopeStubs := func(message string, info java.HiddenAPIInfo, apiScope *java.HiddenAPIScope, expectedPaths ...string) { |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 237 | t.Helper() |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 238 | paths := info.TransitiveStubDexJarsByScope.StubDexJarsForScope(apiScope) |
| 239 | android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, paths) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | // Check stub dex paths exported by art. |
| 243 | artFragment := result.Module("art-bootclasspath-fragment", "android_common") |
| 244 | artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo) |
| 245 | |
| 246 | bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar" |
| 247 | bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar" |
| 248 | bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar" |
| 249 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 250 | checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs) |
| 251 | checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs) |
| 252 | checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs) |
| 253 | checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 254 | |
| 255 | // Check stub dex paths exported by other. |
| 256 | otherFragment := result.Module("other-bootclasspath-fragment", "android_common") |
| 257 | otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo) |
| 258 | |
| 259 | fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar" |
| 260 | fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar" |
| 261 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 262 | checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs) |
| 263 | checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs) |
| 264 | checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs) |
| 265 | checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 268 | func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) { |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 269 | t.Helper() |
| 270 | |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 271 | bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 272 | |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 273 | bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 274 | modules := bootclasspathFragmentInfo.Modules() |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 275 | android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String()) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 276 | |
| 277 | // Get a list of all the paths in the boot image sorted by arch type. |
| 278 | allPaths := []string{} |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 279 | bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 280 | for _, archType := range android.ArchTypeList() { |
| 281 | if paths, ok := bootImageFilesByArchType[archType]; ok { |
| 282 | for _, path := range paths { |
| 283 | allPaths = append(allPaths, android.NormalizePathForTesting(path)) |
| 284 | } |
| 285 | } |
| 286 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 287 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 288 | android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n")) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 289 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 290 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 291 | func TestBootclasspathFragmentInArtApex(t *testing.T) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 292 | commonPreparer := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 293 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 294 | prepareForTestWithArtApex, |
| 295 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 296 | android.FixtureWithRootAndroidBp(` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 297 | apex { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 298 | name: "com.android.art", |
| 299 | key: "com.android.art.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 300 | bootclasspath_fragments: [ |
| 301 | "mybootclasspathfragment", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 302 | ], |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 303 | // bar (like foo) should be transitively included in this apex because it is part of the |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 304 | // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the |
| 305 | // apex dedups the files correctly. |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 306 | java_libs: [ |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 307 | "bar", |
| 308 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 309 | updatable: false, |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | apex_key { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 313 | name: "com.android.art.key", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 314 | public_key: "testkey.avbpubkey", |
| 315 | private_key: "testkey.pem", |
| 316 | } |
| 317 | |
| 318 | java_library { |
| 319 | name: "foo", |
| 320 | srcs: ["b.java"], |
| 321 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 322 | apex_available: [ |
| 323 | "com.android.art", |
| 324 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | java_library { |
| 328 | name: "bar", |
| 329 | srcs: ["b.java"], |
| 330 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 331 | apex_available: [ |
| 332 | "com.android.art", |
| 333 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 336 | java_import { |
| 337 | name: "foo", |
| 338 | jars: ["foo.jar"], |
| 339 | apex_available: [ |
| 340 | "com.android.art", |
| 341 | ], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 342 | compile_dex: true, |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | java_import { |
| 346 | name: "bar", |
| 347 | jars: ["bar.jar"], |
| 348 | apex_available: [ |
| 349 | "com.android.art", |
| 350 | ], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 351 | compile_dex: true, |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 352 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 353 | `), |
| 354 | ) |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 355 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 356 | contentsInsert := func(contents []string) string { |
| 357 | insert := "" |
| 358 | if contents != nil { |
| 359 | insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`)) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 360 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 361 | return insert |
| 362 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 363 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 364 | addSource := func(contents ...string) android.FixturePreparer { |
| 365 | text := fmt.Sprintf(` |
| 366 | bootclasspath_fragment { |
| 367 | name: "mybootclasspathfragment", |
| 368 | image_name: "art", |
| 369 | %s |
| 370 | apex_available: [ |
| 371 | "com.android.art", |
| 372 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 373 | hidden_api: { |
| 374 | split_packages: ["*"], |
| 375 | }, |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 376 | } |
| 377 | `, contentsInsert(contents)) |
| 378 | |
| 379 | return android.FixtureAddTextFile("art/build/boot/Android.bp", text) |
| 380 | } |
| 381 | |
| 382 | addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer { |
| 383 | text := fmt.Sprintf(` |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 384 | prebuilt_apex { |
| 385 | name: "com.android.art", |
| 386 | arch: { |
| 387 | arm64: { |
| 388 | src: "com.android.art-arm64.apex", |
| 389 | }, |
| 390 | arm: { |
| 391 | src: "com.android.art-arm.apex", |
| 392 | }, |
| 393 | }, |
| 394 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
| 395 | } |
| 396 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 397 | prebuilt_bootclasspath_fragment { |
| 398 | name: "mybootclasspathfragment", |
| 399 | image_name: "art", |
| 400 | %s |
| 401 | prefer: %t, |
| 402 | apex_available: [ |
| 403 | "com.android.art", |
| 404 | ], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 405 | hidden_api: { |
| 406 | annotation_flags: "mybootclasspathfragment/annotation-flags.csv", |
| 407 | metadata: "mybootclasspathfragment/metadata.csv", |
| 408 | index: "mybootclasspathfragment/index.csv", |
| 409 | stub_flags: "mybootclasspathfragment/stub-flags.csv", |
| 410 | all_flags: "mybootclasspathfragment/all-flags.csv", |
| 411 | }, |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 412 | } |
| 413 | `, contentsInsert(contents), prefer) |
| 414 | return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text) |
| 415 | } |
| 416 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 417 | t.Run("boot image files from source", func(t *testing.T) { |
| 418 | result := android.GroupFixturePreparers( |
| 419 | commonPreparer, |
| 420 | |
| 421 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 422 | // bootclasspath_fragment's contents property. |
| 423 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 424 | addSource("foo", "bar"), |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 425 | java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"), |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 426 | ).RunTest(t) |
| 427 | |
| 428 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 429 | "etc/boot-image.prof", |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 430 | "etc/classpaths/bootclasspath.pb", |
| 431 | "javalib/arm/boot.art", |
| 432 | "javalib/arm/boot.oat", |
| 433 | "javalib/arm/boot.vdex", |
| 434 | "javalib/arm/boot-bar.art", |
| 435 | "javalib/arm/boot-bar.oat", |
| 436 | "javalib/arm/boot-bar.vdex", |
| 437 | "javalib/arm64/boot.art", |
| 438 | "javalib/arm64/boot.oat", |
| 439 | "javalib/arm64/boot.vdex", |
| 440 | "javalib/arm64/boot-bar.art", |
| 441 | "javalib/arm64/boot-bar.oat", |
| 442 | "javalib/arm64/boot-bar.vdex", |
| 443 | "javalib/bar.jar", |
| 444 | "javalib/foo.jar", |
| 445 | }) |
| 446 | |
| 447 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 448 | `bar`, |
| 449 | `com.android.art.key`, |
| 450 | `mybootclasspathfragment`, |
| 451 | }) |
| 452 | |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 453 | // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules. |
| 454 | ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 455 | "mybootclasspathfragment-dexpreopt-arm64-boot.art", |
| 456 | "mybootclasspathfragment-dexpreopt-arm64-boot.oat", |
| 457 | "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", |
| 458 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", |
| 459 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", |
| 460 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", |
| 461 | "mybootclasspathfragment-dexpreopt-arm-boot.art", |
| 462 | "mybootclasspathfragment-dexpreopt-arm-boot.oat", |
| 463 | "mybootclasspathfragment-dexpreopt-arm-boot.vdex", |
| 464 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", |
| 465 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", |
| 466 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", |
| 467 | }) |
| 468 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 469 | // Make sure that the source bootclasspath_fragment copies its dex files to the predefined |
| 470 | // locations for the art image. |
| 471 | module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 472 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
| 473 | }) |
| 474 | |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 475 | t.Run("boot image files from source no boot image in apex", func(t *testing.T) { |
| 476 | result := android.GroupFixturePreparers( |
| 477 | commonPreparer, |
| 478 | |
| 479 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 480 | // bootclasspath_fragment's contents property. |
| 481 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 482 | addSource("foo", "bar"), |
| 483 | java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"), |
| 484 | ).RunTest(t) |
| 485 | |
| 486 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 487 | "etc/boot-image.prof", |
| 488 | "etc/classpaths/bootclasspath.pb", |
| 489 | "javalib/bar.jar", |
| 490 | "javalib/foo.jar", |
| 491 | }) |
| 492 | |
| 493 | ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 494 | "mybootclasspathfragment-dexpreopt-arm64-boot.art", |
| 495 | "mybootclasspathfragment-dexpreopt-arm64-boot.oat", |
| 496 | "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", |
| 497 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", |
| 498 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", |
| 499 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", |
| 500 | "mybootclasspathfragment-dexpreopt-arm-boot.art", |
| 501 | "mybootclasspathfragment-dexpreopt-arm-boot.oat", |
| 502 | "mybootclasspathfragment-dexpreopt-arm-boot.vdex", |
| 503 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", |
| 504 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", |
| 505 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", |
| 506 | }) |
| 507 | }) |
| 508 | |
Jiakai Zhang | 7d3c9e0 | 2021-12-13 17:19:05 +0000 | [diff] [blame] | 509 | t.Run("boot image disable generate profile", func(t *testing.T) { |
| 510 | result := android.GroupFixturePreparers( |
| 511 | commonPreparer, |
| 512 | |
| 513 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 514 | // bootclasspath_fragment's contents property. |
| 515 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 516 | addSource("foo", "bar"), |
| 517 | dexpreopt.FixtureDisableGenerateProfile(true), |
| 518 | ).RunTest(t) |
| 519 | |
| 520 | files := getFiles(t, result.TestContext, "com.android.art", "android_common_com.android.art_image") |
| 521 | for _, file := range files { |
| 522 | matched, _ := path.Match("etc/boot-image.prof", file.path) |
| 523 | android.AssertBoolEquals(t, "\"etc/boot-image.prof\" should not be in the APEX", matched, false) |
| 524 | } |
| 525 | }) |
| 526 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 527 | t.Run("boot image files with preferred prebuilt", func(t *testing.T) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 528 | result := android.GroupFixturePreparers( |
| 529 | commonPreparer, |
| 530 | |
| 531 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 532 | // bootclasspath_fragment's contents property. |
| 533 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 534 | addSource("foo", "bar"), |
| 535 | |
| 536 | // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex. |
| 537 | addPrebuilt(true, "foo", "bar"), |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 538 | |
| 539 | java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"), |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 540 | ).RunTest(t) |
| 541 | |
| 542 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 543 | "etc/boot-image.prof", |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 544 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 545 | "javalib/arm/boot.art", |
| 546 | "javalib/arm/boot.oat", |
| 547 | "javalib/arm/boot.vdex", |
| 548 | "javalib/arm/boot-bar.art", |
| 549 | "javalib/arm/boot-bar.oat", |
| 550 | "javalib/arm/boot-bar.vdex", |
| 551 | "javalib/arm64/boot.art", |
| 552 | "javalib/arm64/boot.oat", |
| 553 | "javalib/arm64/boot.vdex", |
| 554 | "javalib/arm64/boot-bar.art", |
| 555 | "javalib/arm64/boot-bar.oat", |
| 556 | "javalib/arm64/boot-bar.vdex", |
| 557 | "javalib/bar.jar", |
| 558 | "javalib/foo.jar", |
| 559 | }) |
| 560 | |
| 561 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 562 | `bar`, |
| 563 | `com.android.art.key`, |
| 564 | `mybootclasspathfragment`, |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 565 | `prebuilt_com.android.art`, |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 566 | }) |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 567 | |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 568 | // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules. |
| 569 | ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 570 | "mybootclasspathfragment-dexpreopt-arm64-boot.art", |
| 571 | "mybootclasspathfragment-dexpreopt-arm64-boot.oat", |
| 572 | "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", |
| 573 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", |
| 574 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", |
| 575 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", |
| 576 | "mybootclasspathfragment-dexpreopt-arm-boot.art", |
| 577 | "mybootclasspathfragment-dexpreopt-arm-boot.oat", |
| 578 | "mybootclasspathfragment-dexpreopt-arm-boot.vdex", |
| 579 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", |
| 580 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", |
| 581 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", |
| 582 | }) |
| 583 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 584 | // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined |
| 585 | // locations for the art image. |
| 586 | module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art") |
| 587 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 588 | }) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 589 | |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 590 | t.Run("boot image files from preferred prebuilt no boot image in apex", func(t *testing.T) { |
| 591 | result := android.GroupFixturePreparers( |
| 592 | commonPreparer, |
| 593 | |
| 594 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 595 | // bootclasspath_fragment's contents property. |
| 596 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 597 | addSource("foo", "bar"), |
| 598 | |
| 599 | // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex. |
| 600 | addPrebuilt(true, "foo", "bar"), |
| 601 | |
| 602 | java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"), |
| 603 | ).RunTest(t) |
| 604 | |
| 605 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 606 | "etc/boot-image.prof", |
| 607 | "etc/classpaths/bootclasspath.pb", |
| 608 | "javalib/bar.jar", |
| 609 | "javalib/foo.jar", |
| 610 | }) |
| 611 | |
| 612 | ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 613 | "mybootclasspathfragment-dexpreopt-arm64-boot.art", |
| 614 | "mybootclasspathfragment-dexpreopt-arm64-boot.oat", |
| 615 | "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", |
| 616 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", |
| 617 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", |
| 618 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", |
| 619 | "mybootclasspathfragment-dexpreopt-arm-boot.art", |
| 620 | "mybootclasspathfragment-dexpreopt-arm-boot.oat", |
| 621 | "mybootclasspathfragment-dexpreopt-arm-boot.vdex", |
| 622 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", |
| 623 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", |
| 624 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", |
| 625 | }) |
| 626 | }) |
| 627 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 628 | t.Run("source with inconsistency between config and contents", func(t *testing.T) { |
| 629 | android.GroupFixturePreparers( |
| 630 | commonPreparer, |
| 631 | |
| 632 | // Create an inconsistency between the ArtApexJars configuration and the art source |
| 633 | // bootclasspath_fragment module's contents property. |
| 634 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 635 | addSource("foo", "bar"), |
| 636 | ). |
| 637 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 638 | RunTest(t) |
| 639 | }) |
| 640 | |
| 641 | t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 642 | android.GroupFixturePreparers( |
| 643 | commonPreparer, |
| 644 | |
| 645 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 646 | // prebuilt_bootclasspath_fragment module's contents property. |
| 647 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 648 | addPrebuilt(false, "foo", "bar"), |
| 649 | ). |
| 650 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 651 | RunTest(t) |
| 652 | }) |
| 653 | |
| 654 | t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 655 | android.GroupFixturePreparers( |
| 656 | commonPreparer, |
| 657 | |
| 658 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 659 | // prebuilt_bootclasspath_fragment module's contents property. |
| 660 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 661 | addPrebuilt(true, "foo", "bar"), |
| 662 | |
| 663 | // Source contents property is consistent with the config. |
| 664 | addSource("foo"), |
| 665 | ). |
| 666 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 667 | RunTest(t) |
| 668 | }) |
| 669 | |
| 670 | t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 671 | android.GroupFixturePreparers( |
| 672 | commonPreparer, |
| 673 | |
| 674 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 675 | // prebuilt_bootclasspath_fragment module's contents property. |
| 676 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 677 | addPrebuilt(false, "foo", "bar"), |
| 678 | |
| 679 | // Source contents property is consistent with the config. |
| 680 | addSource("foo"), |
| 681 | |
| 682 | // This should pass because while the prebuilt is inconsistent with the configuration it is |
| 683 | // not actually used. |
| 684 | ).RunTest(t) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 685 | }) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 688 | func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 689 | preparers := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 690 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 691 | prepareForTestWithArtApex, |
| 692 | |
| 693 | android.FixtureMergeMockFs(android.MockFS{ |
| 694 | "com.android.art-arm64.apex": nil, |
| 695 | "com.android.art-arm.apex": nil, |
| 696 | }), |
| 697 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 698 | // Configure some libraries in the art bootclasspath_fragment. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 699 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 700 | java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"), |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 701 | ) |
| 702 | |
| 703 | bp := ` |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 704 | prebuilt_apex { |
| 705 | name: "com.android.art", |
| 706 | arch: { |
| 707 | arm64: { |
| 708 | src: "com.android.art-arm64.apex", |
| 709 | }, |
| 710 | arm: { |
| 711 | src: "com.android.art-arm.apex", |
| 712 | }, |
| 713 | }, |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 714 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | java_import { |
| 718 | name: "foo", |
| 719 | jars: ["foo.jar"], |
| 720 | apex_available: [ |
| 721 | "com.android.art", |
| 722 | ], |
| 723 | } |
| 724 | |
| 725 | java_import { |
| 726 | name: "bar", |
| 727 | jars: ["bar.jar"], |
| 728 | apex_available: [ |
| 729 | "com.android.art", |
| 730 | ], |
| 731 | } |
| 732 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 733 | prebuilt_bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 734 | name: "mybootclasspathfragment", |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 735 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 736 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 737 | contents: ["foo", "bar"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 738 | apex_available: [ |
| 739 | "com.android.art", |
| 740 | ], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 741 | hidden_api: { |
| 742 | annotation_flags: "mybootclasspathfragment/annotation-flags.csv", |
| 743 | metadata: "mybootclasspathfragment/metadata.csv", |
| 744 | index: "mybootclasspathfragment/index.csv", |
| 745 | stub_flags: "mybootclasspathfragment/stub-flags.csv", |
| 746 | all_flags: "mybootclasspathfragment/all-flags.csv", |
| 747 | }, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 748 | } |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 749 | |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 750 | // A prebuilt apex with the same apex_name that shouldn't interfere when it isn't enabled. |
| 751 | prebuilt_apex { |
| 752 | name: "com.mycompany.android.art", |
| 753 | apex_name: "com.android.art", |
| 754 | %s |
| 755 | src: "com.mycompany.android.art.apex", |
| 756 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
| 757 | } |
| 758 | ` |
| 759 | |
| 760 | t.Run("disabled alternative APEX", func(t *testing.T) { |
| 761 | result := preparers.RunTestWithBp(t, fmt.Sprintf(bp, "enabled: false,")) |
| 762 | |
| 763 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{ |
| 764 | `com.android.art.apex.selector`, |
| 765 | `prebuilt_mybootclasspathfragment`, |
| 766 | }) |
| 767 | |
| 768 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{ |
| 769 | `com.android.art.deapexer`, |
| 770 | `dex2oatd`, |
| 771 | `prebuilt_bar`, |
| 772 | `prebuilt_foo`, |
| 773 | }) |
| 774 | |
| 775 | module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art") |
| 776 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
| 777 | |
| 778 | // Check that the right deapexer module was chosen for a boot image. |
| 779 | param := module.Output("out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art") |
| 780 | android.AssertStringDoesContain(t, "didn't find the expected deapexer in the input path", param.Input.String(), "/com.android.art.deapexer") |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 781 | }) |
| 782 | |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 783 | t.Run("enabled alternative APEX", func(t *testing.T) { |
| 784 | preparers.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 785 | "Multiple installable prebuilt APEXes provide ambiguous deapexers: com.android.art and com.mycompany.android.art")). |
| 786 | RunTestWithBp(t, fmt.Sprintf(bp, "")) |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 787 | }) |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | // checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the |
| 791 | // predefined locations of boot dex jars used as inputs for the ART boot image. |
| 792 | func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) { |
| 793 | t.Helper() |
| 794 | bootJarLocations := []string{} |
| 795 | for _, output := range module.AllOutputs() { |
| 796 | output = android.StringRelativeToTop(config, output) |
| 797 | if strings.HasPrefix(output, "out/soong/test_device/dex_artjars_input/") { |
| 798 | bootJarLocations = append(bootJarLocations, output) |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | sort.Strings(bootJarLocations) |
| 803 | expected := []string{} |
| 804 | for _, m := range modules { |
| 805 | expected = append(expected, fmt.Sprintf("out/soong/test_device/dex_artjars_input/%s.jar", m)) |
| 806 | } |
| 807 | sort.Strings(expected) |
| 808 | |
| 809 | android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations) |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 812 | func TestBootclasspathFragmentContentsNoName(t *testing.T) { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 813 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 814 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 815 | prepareForTestWithMyapex, |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 816 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 817 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 818 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 819 | // is disabled. |
| 820 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 821 | |
| 822 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 823 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 824 | ).RunTestWithBp(t, ` |
| 825 | apex { |
| 826 | name: "myapex", |
| 827 | key: "myapex.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 828 | bootclasspath_fragments: [ |
| 829 | "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 830 | ], |
| 831 | updatable: false, |
| 832 | } |
| 833 | |
| 834 | apex_key { |
| 835 | name: "myapex.key", |
| 836 | public_key: "testkey.avbpubkey", |
| 837 | private_key: "testkey.pem", |
| 838 | } |
| 839 | |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 840 | java_sdk_library { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 841 | name: "foo", |
| 842 | srcs: ["b.java"], |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 843 | shared_library: false, |
| 844 | public: {enabled: true}, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 845 | apex_available: [ |
| 846 | "myapex", |
| 847 | ], |
| 848 | } |
| 849 | |
| 850 | java_library { |
| 851 | name: "bar", |
| 852 | srcs: ["b.java"], |
| 853 | installable: true, |
| 854 | apex_available: [ |
| 855 | "myapex", |
| 856 | ], |
| 857 | } |
| 858 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 859 | bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 860 | name: "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 861 | contents: [ |
| 862 | "foo", |
| 863 | "bar", |
| 864 | ], |
| 865 | apex_available: [ |
| 866 | "myapex", |
| 867 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 868 | hidden_api: { |
| 869 | split_packages: ["*"], |
| 870 | }, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 871 | } |
| 872 | `) |
| 873 | |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 874 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 875 | // This does not include art, oat or vdex files as they are only included for the art boot |
| 876 | // image. |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 877 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 878 | "javalib/bar.jar", |
| 879 | "javalib/foo.jar", |
| 880 | }) |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 881 | |
| 882 | java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 883 | `myapex.key`, |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 884 | `mybootclasspathfragment`, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 885 | }) |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 886 | |
| 887 | apex := result.ModuleForTests("myapex", "android_common_myapex_image") |
| 888 | apexRule := apex.Rule("apexRule") |
| 889 | copyCommands := apexRule.Args["copy_commands"] |
| 890 | |
| 891 | // Make sure that the fragment provides the hidden API encoded dex jars to the APEX. |
| 892 | fragment := result.Module("mybootclasspathfragment", "android_common_apex10000") |
| 893 | |
| 894 | info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 895 | |
| 896 | checkFragmentExportedDexJar := func(name string, expectedDexJar string) { |
| 897 | module := result.Module(name, "android_common_apex10000") |
Paul Duffin | 1a8010a | 2021-05-15 12:39:23 +0100 | [diff] [blame] | 898 | dexJar, err := info.DexBootJarPathForContentModule(module) |
| 899 | if err != nil { |
| 900 | t.Error(err) |
| 901 | } |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 902 | android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar) |
| 903 | |
| 904 | expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name) |
| 905 | android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand) |
| 906 | } |
| 907 | |
Paul Duffin | 54c98f5 | 2021-05-15 08:54:30 +0100 | [diff] [blame] | 908 | checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar") |
| 909 | checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar") |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 912 | func getDexJarPath(result *android.TestResult, name string) string { |
| 913 | module := result.Module(name, "android_common") |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 914 | return module.(java.UsesLibraryDependency).DexJarBuildPath().Path().RelativeToTop().String() |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | // TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are |
| 918 | // passed to the hiddenapi list tool. |
| 919 | func TestBootclasspathFragment_HiddenAPIList(t *testing.T) { |
| 920 | result := android.GroupFixturePreparers( |
| 921 | prepareForTestWithBootclasspathFragment, |
| 922 | prepareForTestWithArtApex, |
| 923 | prepareForTestWithMyapex, |
| 924 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
| 925 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 926 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 927 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 928 | // is disabled. |
| 929 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 930 | |
| 931 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 932 | java.FixtureWithLastReleaseApis("foo", "quuz"), |
| 933 | ).RunTestWithBp(t, ` |
| 934 | apex { |
| 935 | name: "com.android.art", |
| 936 | key: "com.android.art.key", |
| 937 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 938 | updatable: false, |
| 939 | } |
| 940 | |
| 941 | apex_key { |
| 942 | name: "com.android.art.key", |
| 943 | public_key: "com.android.art.avbpubkey", |
| 944 | private_key: "com.android.art.pem", |
| 945 | } |
| 946 | |
| 947 | java_library { |
| 948 | name: "baz", |
| 949 | apex_available: [ |
| 950 | "com.android.art", |
| 951 | ], |
| 952 | srcs: ["b.java"], |
| 953 | compile_dex: true, |
| 954 | } |
| 955 | |
| 956 | java_sdk_library { |
| 957 | name: "quuz", |
| 958 | apex_available: [ |
| 959 | "com.android.art", |
| 960 | ], |
| 961 | srcs: ["b.java"], |
| 962 | compile_dex: true, |
| 963 | public: {enabled: true}, |
| 964 | system: {enabled: true}, |
| 965 | test: {enabled: true}, |
| 966 | module_lib: {enabled: true}, |
| 967 | } |
| 968 | |
| 969 | bootclasspath_fragment { |
| 970 | name: "art-bootclasspath-fragment", |
| 971 | image_name: "art", |
| 972 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 973 | contents: ["baz", "quuz"], |
| 974 | apex_available: [ |
| 975 | "com.android.art", |
| 976 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 977 | hidden_api: { |
| 978 | split_packages: ["*"], |
| 979 | }, |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | apex { |
| 983 | name: "myapex", |
| 984 | key: "myapex.key", |
| 985 | bootclasspath_fragments: [ |
| 986 | "mybootclasspathfragment", |
| 987 | ], |
| 988 | updatable: false, |
| 989 | } |
| 990 | |
| 991 | apex_key { |
| 992 | name: "myapex.key", |
| 993 | public_key: "testkey.avbpubkey", |
| 994 | private_key: "testkey.pem", |
| 995 | } |
| 996 | |
| 997 | java_sdk_library { |
| 998 | name: "foo", |
| 999 | srcs: ["b.java"], |
| 1000 | shared_library: false, |
| 1001 | public: {enabled: true}, |
| 1002 | apex_available: [ |
| 1003 | "myapex", |
| 1004 | ], |
| 1005 | } |
| 1006 | |
| 1007 | java_library { |
| 1008 | name: "bar", |
| 1009 | srcs: ["b.java"], |
| 1010 | installable: true, |
| 1011 | apex_available: [ |
| 1012 | "myapex", |
| 1013 | ], |
| 1014 | } |
| 1015 | |
| 1016 | bootclasspath_fragment { |
| 1017 | name: "mybootclasspathfragment", |
| 1018 | contents: [ |
| 1019 | "foo", |
| 1020 | "bar", |
| 1021 | ], |
| 1022 | apex_available: [ |
| 1023 | "myapex", |
| 1024 | ], |
| 1025 | fragments: [ |
| 1026 | { |
| 1027 | apex: "com.android.art", |
| 1028 | module: "art-bootclasspath-fragment", |
| 1029 | }, |
| 1030 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 1031 | hidden_api: { |
| 1032 | split_packages: ["*"], |
| 1033 | }, |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 1034 | } |
| 1035 | `) |
| 1036 | |
| 1037 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{ |
| 1038 | "art-bootclasspath-fragment", |
| 1039 | "bar", |
| 1040 | "dex2oatd", |
| 1041 | "foo", |
| 1042 | }) |
| 1043 | |
| 1044 | fooStubs := getDexJarPath(result, "foo.stubs") |
| 1045 | quuzPublicStubs := getDexJarPath(result, "quuz.stubs") |
| 1046 | quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system") |
| 1047 | quuzTestStubs := getDexJarPath(result, "quuz.stubs.test") |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 1048 | quuzModuleLibStubs := getDexJarPath(result, "quuz.stubs.module_lib") |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 1049 | |
| 1050 | // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags. |
| 1051 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 1052 | |
| 1053 | rule := fragment.Rule("modularHiddenAPIStubFlagsFile") |
| 1054 | command := rule.RuleParams.Command |
| 1055 | android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list") |
| 1056 | |
| 1057 | // Make sure that the quuz stubs are available for resolving references from the implementation |
| 1058 | // boot dex jars provided by this module. |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 1059 | android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzModuleLibStubs) |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 1060 | |
| 1061 | // Make sure that the quuz stubs are available for resolving references from the different API |
| 1062 | // stubs provided by this module. |
| 1063 | android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs) |
| 1064 | android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs) |
| 1065 | android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs) |
| 1066 | } |
| 1067 | |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1068 | // TestBootclasspathFragment_AndroidNonUpdatable checks to make sure that setting |
| 1069 | // additional_stubs: ["android-non-updatable"] causes the source android-non-updatable modules to be |
| 1070 | // added to the hiddenapi list tool. |
| 1071 | func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) { |
| 1072 | result := android.GroupFixturePreparers( |
| 1073 | prepareForTestWithBootclasspathFragment, |
| 1074 | prepareForTestWithArtApex, |
| 1075 | prepareForTestWithMyapex, |
| 1076 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 1077 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 1078 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1079 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 1080 | // is disabled. |
| 1081 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 1082 | |
| 1083 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 1084 | java.FixtureWithLastReleaseApis("foo", "android-non-updatable"), |
| 1085 | ).RunTestWithBp(t, ` |
| 1086 | java_sdk_library { |
| 1087 | name: "android-non-updatable", |
| 1088 | srcs: ["b.java"], |
| 1089 | compile_dex: true, |
| 1090 | public: { |
| 1091 | enabled: true, |
| 1092 | }, |
| 1093 | system: { |
| 1094 | enabled: true, |
| 1095 | }, |
| 1096 | test: { |
| 1097 | enabled: true, |
| 1098 | }, |
| 1099 | module_lib: { |
| 1100 | enabled: true, |
| 1101 | }, |
| 1102 | } |
| 1103 | |
| 1104 | apex { |
| 1105 | name: "com.android.art", |
| 1106 | key: "com.android.art.key", |
| 1107 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 1108 | java_libs: [ |
| 1109 | "baz", |
| 1110 | "quuz", |
| 1111 | ], |
| 1112 | updatable: false, |
| 1113 | } |
| 1114 | |
| 1115 | apex_key { |
| 1116 | name: "com.android.art.key", |
| 1117 | public_key: "com.android.art.avbpubkey", |
| 1118 | private_key: "com.android.art.pem", |
| 1119 | } |
| 1120 | |
| 1121 | java_library { |
| 1122 | name: "baz", |
| 1123 | apex_available: [ |
| 1124 | "com.android.art", |
| 1125 | ], |
| 1126 | srcs: ["b.java"], |
| 1127 | compile_dex: true, |
| 1128 | } |
| 1129 | |
| 1130 | java_library { |
| 1131 | name: "quuz", |
| 1132 | apex_available: [ |
| 1133 | "com.android.art", |
| 1134 | ], |
| 1135 | srcs: ["b.java"], |
| 1136 | compile_dex: true, |
| 1137 | } |
| 1138 | |
| 1139 | bootclasspath_fragment { |
| 1140 | name: "art-bootclasspath-fragment", |
| 1141 | image_name: "art", |
| 1142 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 1143 | contents: ["baz", "quuz"], |
| 1144 | apex_available: [ |
| 1145 | "com.android.art", |
| 1146 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 1147 | hidden_api: { |
| 1148 | split_packages: ["*"], |
| 1149 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | apex { |
| 1153 | name: "myapex", |
| 1154 | key: "myapex.key", |
| 1155 | bootclasspath_fragments: [ |
| 1156 | "mybootclasspathfragment", |
| 1157 | ], |
| 1158 | updatable: false, |
| 1159 | } |
| 1160 | |
| 1161 | apex_key { |
| 1162 | name: "myapex.key", |
| 1163 | public_key: "testkey.avbpubkey", |
| 1164 | private_key: "testkey.pem", |
| 1165 | } |
| 1166 | |
| 1167 | java_sdk_library { |
| 1168 | name: "foo", |
| 1169 | srcs: ["b.java"], |
| 1170 | shared_library: false, |
| 1171 | public: {enabled: true}, |
| 1172 | apex_available: [ |
| 1173 | "myapex", |
| 1174 | ], |
| 1175 | } |
| 1176 | |
| 1177 | java_library { |
| 1178 | name: "bar", |
| 1179 | srcs: ["b.java"], |
| 1180 | installable: true, |
| 1181 | apex_available: [ |
| 1182 | "myapex", |
| 1183 | ], |
| 1184 | } |
| 1185 | |
| 1186 | bootclasspath_fragment { |
| 1187 | name: "mybootclasspathfragment", |
| 1188 | contents: [ |
| 1189 | "foo", |
| 1190 | "bar", |
| 1191 | ], |
| 1192 | apex_available: [ |
| 1193 | "myapex", |
| 1194 | ], |
| 1195 | additional_stubs: ["android-non-updatable"], |
| 1196 | fragments: [ |
| 1197 | { |
| 1198 | apex: "com.android.art", |
| 1199 | module: "art-bootclasspath-fragment", |
| 1200 | }, |
| 1201 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 1202 | hidden_api: { |
| 1203 | split_packages: ["*"], |
| 1204 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1205 | } |
| 1206 | `) |
| 1207 | |
| 1208 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{ |
| 1209 | "android-non-updatable.stubs", |
| 1210 | "android-non-updatable.stubs.module_lib", |
| 1211 | "android-non-updatable.stubs.system", |
| 1212 | "android-non-updatable.stubs.test", |
| 1213 | "art-bootclasspath-fragment", |
| 1214 | "bar", |
| 1215 | "dex2oatd", |
| 1216 | "foo", |
| 1217 | }) |
| 1218 | |
| 1219 | nonUpdatablePublicStubs := getDexJarPath(result, "android-non-updatable.stubs") |
| 1220 | nonUpdatableSystemStubs := getDexJarPath(result, "android-non-updatable.stubs.system") |
| 1221 | nonUpdatableTestStubs := getDexJarPath(result, "android-non-updatable.stubs.test") |
| 1222 | nonUpdatableModuleLibStubs := getDexJarPath(result, "android-non-updatable.stubs.module_lib") |
| 1223 | |
| 1224 | // Make sure that the fragment uses the android-non-updatable modules when generating the hidden |
| 1225 | // API flags. |
| 1226 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 1227 | |
| 1228 | rule := fragment.Rule("modularHiddenAPIStubFlagsFile") |
| 1229 | command := rule.RuleParams.Command |
| 1230 | android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list") |
| 1231 | |
| 1232 | // Make sure that the module_lib non-updatable stubs are available for resolving references from |
| 1233 | // the implementation boot dex jars provided by this module. |
| 1234 | android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs) |
| 1235 | |
| 1236 | // Make sure that the appropriate non-updatable stubs are available for resolving references from |
| 1237 | // the different API stubs provided by this module. |
| 1238 | android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs) |
| 1239 | android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs) |
| 1240 | android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs) |
| 1241 | } |
| 1242 | |
| 1243 | // TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks checks to make sure that |
| 1244 | // setting additional_stubs: ["android-non-updatable"] causes the prebuilt android-non-updatable |
| 1245 | // modules to be added to the hiddenapi list tool. |
| 1246 | func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) { |
| 1247 | result := android.GroupFixturePreparers( |
| 1248 | prepareForTestWithBootclasspathFragment, |
| 1249 | java.PrepareForTestWithJavaDefaultModules, |
| 1250 | prepareForTestWithArtApex, |
| 1251 | prepareForTestWithMyapex, |
| 1252 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 1253 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 1254 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1255 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 1256 | // is disabled. |
| 1257 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 1258 | |
| 1259 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1260 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) |
| 1261 | }), |
| 1262 | |
| 1263 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 1264 | java.FixtureWithPrebuiltApis(map[string][]string{ |
| 1265 | "current": {"android-non-updatable"}, |
| 1266 | "30": {"foo"}, |
| 1267 | }), |
| 1268 | ).RunTestWithBp(t, ` |
| 1269 | apex { |
| 1270 | name: "com.android.art", |
| 1271 | key: "com.android.art.key", |
| 1272 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 1273 | java_libs: [ |
| 1274 | "baz", |
| 1275 | "quuz", |
| 1276 | ], |
| 1277 | updatable: false, |
| 1278 | } |
| 1279 | |
| 1280 | apex_key { |
| 1281 | name: "com.android.art.key", |
| 1282 | public_key: "com.android.art.avbpubkey", |
| 1283 | private_key: "com.android.art.pem", |
| 1284 | } |
| 1285 | |
| 1286 | java_library { |
| 1287 | name: "baz", |
| 1288 | apex_available: [ |
| 1289 | "com.android.art", |
| 1290 | ], |
| 1291 | srcs: ["b.java"], |
| 1292 | compile_dex: true, |
| 1293 | } |
| 1294 | |
| 1295 | java_library { |
| 1296 | name: "quuz", |
| 1297 | apex_available: [ |
| 1298 | "com.android.art", |
| 1299 | ], |
| 1300 | srcs: ["b.java"], |
| 1301 | compile_dex: true, |
| 1302 | } |
| 1303 | |
| 1304 | bootclasspath_fragment { |
| 1305 | name: "art-bootclasspath-fragment", |
| 1306 | image_name: "art", |
| 1307 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 1308 | contents: ["baz", "quuz"], |
| 1309 | apex_available: [ |
| 1310 | "com.android.art", |
| 1311 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 1312 | hidden_api: { |
| 1313 | split_packages: ["*"], |
| 1314 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | apex { |
| 1318 | name: "myapex", |
| 1319 | key: "myapex.key", |
| 1320 | bootclasspath_fragments: [ |
| 1321 | "mybootclasspathfragment", |
| 1322 | ], |
| 1323 | updatable: false, |
| 1324 | } |
| 1325 | |
| 1326 | apex_key { |
| 1327 | name: "myapex.key", |
| 1328 | public_key: "testkey.avbpubkey", |
| 1329 | private_key: "testkey.pem", |
| 1330 | } |
| 1331 | |
| 1332 | java_sdk_library { |
| 1333 | name: "foo", |
| 1334 | srcs: ["b.java"], |
| 1335 | shared_library: false, |
| 1336 | public: {enabled: true}, |
| 1337 | apex_available: [ |
| 1338 | "myapex", |
| 1339 | ], |
| 1340 | } |
| 1341 | |
| 1342 | java_library { |
| 1343 | name: "bar", |
| 1344 | srcs: ["b.java"], |
| 1345 | installable: true, |
| 1346 | apex_available: [ |
| 1347 | "myapex", |
| 1348 | ], |
| 1349 | } |
| 1350 | |
| 1351 | bootclasspath_fragment { |
| 1352 | name: "mybootclasspathfragment", |
| 1353 | contents: [ |
| 1354 | "foo", |
| 1355 | "bar", |
| 1356 | ], |
| 1357 | apex_available: [ |
| 1358 | "myapex", |
| 1359 | ], |
| 1360 | additional_stubs: ["android-non-updatable"], |
| 1361 | fragments: [ |
| 1362 | { |
| 1363 | apex: "com.android.art", |
| 1364 | module: "art-bootclasspath-fragment", |
| 1365 | }, |
| 1366 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame^] | 1367 | hidden_api: { |
| 1368 | split_packages: ["*"], |
| 1369 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1370 | } |
| 1371 | `) |
| 1372 | |
| 1373 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{ |
| 1374 | "art-bootclasspath-fragment", |
| 1375 | "bar", |
| 1376 | "dex2oatd", |
| 1377 | "foo", |
| 1378 | "prebuilt_sdk_module-lib_current_android-non-updatable", |
| 1379 | "prebuilt_sdk_public_current_android-non-updatable", |
| 1380 | "prebuilt_sdk_system_current_android-non-updatable", |
| 1381 | "prebuilt_sdk_test_current_android-non-updatable", |
| 1382 | }) |
| 1383 | |
| 1384 | nonUpdatablePublicStubs := getDexJarPath(result, "sdk_public_current_android-non-updatable") |
| 1385 | nonUpdatableSystemStubs := getDexJarPath(result, "sdk_system_current_android-non-updatable") |
| 1386 | nonUpdatableTestStubs := getDexJarPath(result, "sdk_test_current_android-non-updatable") |
| 1387 | nonUpdatableModuleLibStubs := getDexJarPath(result, "sdk_module-lib_current_android-non-updatable") |
| 1388 | |
| 1389 | // Make sure that the fragment uses the android-non-updatable modules when generating the hidden |
| 1390 | // API flags. |
| 1391 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 1392 | |
| 1393 | rule := fragment.Rule("modularHiddenAPIStubFlagsFile") |
| 1394 | command := rule.RuleParams.Command |
| 1395 | android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list") |
| 1396 | |
| 1397 | // Make sure that the module_lib non-updatable stubs are available for resolving references from |
| 1398 | // the implementation boot dex jars provided by this module. |
| 1399 | android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs) |
| 1400 | |
| 1401 | // Make sure that the appropriate non-updatable stubs are available for resolving references from |
| 1402 | // the different API stubs provided by this module. |
| 1403 | android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs) |
| 1404 | android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs) |
| 1405 | android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs) |
| 1406 | } |
| 1407 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 1408 | // TODO(b/177892522) - add test for host apex. |