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" |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 19 | "strings" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 20 | "testing" |
| 21 | |
| 22 | "android/soong/android" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 23 | "android/soong/java" |
| 24 | ) |
| 25 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 26 | // Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART |
| 27 | // bootclasspath_fragment requires modules from the ART apex. |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 28 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 29 | var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers( |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 30 | java.PrepareForTestWithDexpreopt, |
| 31 | PrepareForTestWithApexBuildComponents, |
| 32 | ) |
| 33 | |
| 34 | // Some additional files needed for the art apex. |
| 35 | var prepareForTestWithArtApex = android.FixtureMergeMockFs(android.MockFS{ |
| 36 | "com.android.art.avbpubkey": nil, |
| 37 | "com.android.art.pem": nil, |
| 38 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 39 | }) |
| 40 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 41 | func TestBootclasspathFragments(t *testing.T) { |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 42 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 43 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 44 | // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 45 | 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] | 46 | prepareForTestWithArtApex, |
| 47 | |
| 48 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 49 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 50 | ).RunTestWithBp(t, ` |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 51 | java_sdk_library { |
| 52 | name: "foo", |
| 53 | srcs: ["b.java"], |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | java_library { |
| 57 | name: "bar", |
| 58 | srcs: ["b.java"], |
| 59 | installable: true, |
| 60 | } |
| 61 | |
| 62 | apex { |
| 63 | name: "com.android.art", |
| 64 | key: "com.android.art.key", |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 65 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 66 | java_libs: [ |
| 67 | "baz", |
| 68 | "quuz", |
| 69 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 70 | updatable: false, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | apex_key { |
| 74 | name: "com.android.art.key", |
| 75 | public_key: "com.android.art.avbpubkey", |
| 76 | private_key: "com.android.art.pem", |
| 77 | } |
| 78 | |
| 79 | java_library { |
| 80 | name: "baz", |
| 81 | apex_available: [ |
| 82 | "com.android.art", |
| 83 | ], |
| 84 | srcs: ["b.java"], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 85 | compile_dex: true, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | java_library { |
| 89 | name: "quuz", |
| 90 | apex_available: [ |
| 91 | "com.android.art", |
| 92 | ], |
| 93 | srcs: ["b.java"], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 94 | compile_dex: true, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 95 | } |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 96 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 97 | bootclasspath_fragment { |
| 98 | name: "art-bootclasspath-fragment", |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 99 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 100 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 101 | contents: ["baz", "quuz"], |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 102 | apex_available: [ |
| 103 | "com.android.art", |
| 104 | ], |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 105 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 106 | `, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 107 | ) |
| 108 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 109 | // Make sure that the art-bootclasspath-fragment is using the correct configuration. |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 110 | checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000", |
| 111 | "com.android.art:baz,com.android.art:quuz", ` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 112 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art |
| 113 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat |
| 114 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex |
| 115 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art |
| 116 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat |
| 117 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex |
| 118 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art |
| 119 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat |
| 120 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex |
| 121 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art |
| 122 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat |
| 123 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex |
| 124 | `) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 127 | func TestBootclasspathFragments_FragmentDependency(t *testing.T) { |
| 128 | result := android.GroupFixturePreparers( |
| 129 | prepareForTestWithBootclasspathFragment, |
| 130 | // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath. |
| 131 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"), |
| 132 | prepareForTestWithArtApex, |
| 133 | |
| 134 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 135 | java.FixtureWithLastReleaseApis("foo", "baz"), |
| 136 | ).RunTestWithBp(t, ` |
| 137 | java_sdk_library { |
| 138 | name: "foo", |
| 139 | srcs: ["b.java"], |
| 140 | shared_library: false, |
| 141 | public: { |
| 142 | enabled: true, |
| 143 | }, |
| 144 | system: { |
| 145 | enabled: true, |
| 146 | }, |
| 147 | } |
| 148 | |
| 149 | java_library { |
| 150 | name: "bar", |
| 151 | srcs: ["b.java"], |
| 152 | installable: true, |
| 153 | } |
| 154 | |
| 155 | apex { |
| 156 | name: "com.android.art", |
| 157 | key: "com.android.art.key", |
| 158 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 159 | updatable: false, |
| 160 | } |
| 161 | |
| 162 | apex_key { |
| 163 | name: "com.android.art.key", |
| 164 | public_key: "com.android.art.avbpubkey", |
| 165 | private_key: "com.android.art.pem", |
| 166 | } |
| 167 | |
| 168 | java_sdk_library { |
| 169 | name: "baz", |
| 170 | apex_available: [ |
| 171 | "com.android.art", |
| 172 | ], |
| 173 | srcs: ["b.java"], |
| 174 | shared_library: false, |
| 175 | public: { |
| 176 | enabled: true, |
| 177 | }, |
| 178 | system: { |
| 179 | enabled: true, |
| 180 | }, |
| 181 | test: { |
| 182 | enabled: true, |
| 183 | }, |
| 184 | } |
| 185 | |
| 186 | java_library { |
| 187 | name: "quuz", |
| 188 | apex_available: [ |
| 189 | "com.android.art", |
| 190 | ], |
| 191 | srcs: ["b.java"], |
| 192 | compile_dex: true, |
| 193 | } |
| 194 | |
| 195 | bootclasspath_fragment { |
| 196 | name: "art-bootclasspath-fragment", |
| 197 | image_name: "art", |
| 198 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 199 | contents: ["baz", "quuz"], |
| 200 | apex_available: [ |
| 201 | "com.android.art", |
| 202 | ], |
| 203 | } |
| 204 | |
| 205 | bootclasspath_fragment { |
| 206 | name: "other-bootclasspath-fragment", |
| 207 | contents: ["foo", "bar"], |
| 208 | fragments: [ |
| 209 | { |
| 210 | apex: "com.android.art", |
| 211 | module: "art-bootclasspath-fragment", |
| 212 | }, |
| 213 | ], |
| 214 | } |
| 215 | `, |
| 216 | ) |
| 217 | |
| 218 | checkSdkKindStubs := func(message string, info java.HiddenAPIInfo, kind android.SdkKind, expectedPaths ...string) { |
| 219 | t.Helper() |
| 220 | android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, kind), expectedPaths, info.TransitiveStubDexJarsByKind[kind]) |
| 221 | } |
| 222 | |
| 223 | // Check stub dex paths exported by art. |
| 224 | artFragment := result.Module("art-bootclasspath-fragment", "android_common") |
| 225 | artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo) |
| 226 | |
| 227 | bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar" |
| 228 | bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar" |
| 229 | bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar" |
| 230 | |
| 231 | checkSdkKindStubs("art", artInfo, android.SdkPublic, bazPublicStubs) |
| 232 | checkSdkKindStubs("art", artInfo, android.SdkSystem, bazSystemStubs) |
| 233 | checkSdkKindStubs("art", artInfo, android.SdkTest, bazTestStubs) |
| 234 | checkSdkKindStubs("art", artInfo, android.SdkCorePlatform) |
| 235 | |
| 236 | // Check stub dex paths exported by other. |
| 237 | otherFragment := result.Module("other-bootclasspath-fragment", "android_common") |
| 238 | otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo) |
| 239 | |
| 240 | fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar" |
| 241 | fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar" |
| 242 | |
| 243 | checkSdkKindStubs("other", otherInfo, android.SdkPublic, bazPublicStubs, fooPublicStubs) |
| 244 | checkSdkKindStubs("other", otherInfo, android.SdkSystem, bazSystemStubs, fooSystemStubs) |
| 245 | checkSdkKindStubs("other", otherInfo, android.SdkTest, bazTestStubs, fooSystemStubs) |
| 246 | checkSdkKindStubs("other", otherInfo, android.SdkCorePlatform) |
| 247 | } |
| 248 | |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 249 | 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] | 250 | t.Helper() |
| 251 | |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 252 | bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 253 | |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 254 | bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 255 | modules := bootclasspathFragmentInfo.Modules() |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 256 | android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String()) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 257 | |
| 258 | // Get a list of all the paths in the boot image sorted by arch type. |
| 259 | allPaths := []string{} |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 260 | bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 261 | for _, archType := range android.ArchTypeList() { |
| 262 | if paths, ok := bootImageFilesByArchType[archType]; ok { |
| 263 | for _, path := range paths { |
| 264 | allPaths = append(allPaths, android.NormalizePathForTesting(path)) |
| 265 | } |
| 266 | } |
| 267 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 268 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 269 | android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n")) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 270 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 271 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 272 | func TestBootclasspathFragmentInArtApex(t *testing.T) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 273 | commonPreparer := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 274 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 275 | prepareForTestWithArtApex, |
| 276 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 277 | android.FixtureWithRootAndroidBp(` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 278 | apex { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 279 | name: "com.android.art", |
| 280 | key: "com.android.art.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 281 | bootclasspath_fragments: [ |
| 282 | "mybootclasspathfragment", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 283 | ], |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 284 | // 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] | 285 | // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the |
| 286 | // apex dedups the files correctly. |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 287 | java_libs: [ |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 288 | "bar", |
| 289 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 290 | updatable: false, |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | apex_key { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 294 | name: "com.android.art.key", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 295 | public_key: "testkey.avbpubkey", |
| 296 | private_key: "testkey.pem", |
| 297 | } |
| 298 | |
| 299 | java_library { |
| 300 | name: "foo", |
| 301 | srcs: ["b.java"], |
| 302 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 303 | apex_available: [ |
| 304 | "com.android.art", |
| 305 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | java_library { |
| 309 | name: "bar", |
| 310 | srcs: ["b.java"], |
| 311 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 312 | apex_available: [ |
| 313 | "com.android.art", |
| 314 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 317 | java_import { |
| 318 | name: "foo", |
| 319 | jars: ["foo.jar"], |
| 320 | apex_available: [ |
| 321 | "com.android.art", |
| 322 | ], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 323 | compile_dex: true, |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | java_import { |
| 327 | name: "bar", |
| 328 | jars: ["bar.jar"], |
| 329 | apex_available: [ |
| 330 | "com.android.art", |
| 331 | ], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 332 | compile_dex: true, |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 333 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 334 | `), |
| 335 | ) |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 336 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 337 | contentsInsert := func(contents []string) string { |
| 338 | insert := "" |
| 339 | if contents != nil { |
| 340 | insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`)) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 341 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 342 | return insert |
| 343 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 344 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 345 | addSource := func(contents ...string) android.FixturePreparer { |
| 346 | text := fmt.Sprintf(` |
| 347 | bootclasspath_fragment { |
| 348 | name: "mybootclasspathfragment", |
| 349 | image_name: "art", |
| 350 | %s |
| 351 | apex_available: [ |
| 352 | "com.android.art", |
| 353 | ], |
| 354 | } |
| 355 | `, contentsInsert(contents)) |
| 356 | |
| 357 | return android.FixtureAddTextFile("art/build/boot/Android.bp", text) |
| 358 | } |
| 359 | |
| 360 | addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer { |
| 361 | text := fmt.Sprintf(` |
| 362 | prebuilt_bootclasspath_fragment { |
| 363 | name: "mybootclasspathfragment", |
| 364 | image_name: "art", |
| 365 | %s |
| 366 | prefer: %t, |
| 367 | apex_available: [ |
| 368 | "com.android.art", |
| 369 | ], |
| 370 | } |
| 371 | `, contentsInsert(contents), prefer) |
| 372 | return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text) |
| 373 | } |
| 374 | |
| 375 | t.Run("boot image files", func(t *testing.T) { |
| 376 | result := android.GroupFixturePreparers( |
| 377 | commonPreparer, |
| 378 | |
| 379 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 380 | // bootclasspath_fragment's contents property. |
| 381 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 382 | addSource("foo", "bar"), |
| 383 | |
| 384 | // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex. |
| 385 | addPrebuilt(true, "foo", "bar"), |
| 386 | ).RunTest(t) |
| 387 | |
| 388 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 389 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 390 | "javalib/arm/boot.art", |
| 391 | "javalib/arm/boot.oat", |
| 392 | "javalib/arm/boot.vdex", |
| 393 | "javalib/arm/boot-bar.art", |
| 394 | "javalib/arm/boot-bar.oat", |
| 395 | "javalib/arm/boot-bar.vdex", |
| 396 | "javalib/arm64/boot.art", |
| 397 | "javalib/arm64/boot.oat", |
| 398 | "javalib/arm64/boot.vdex", |
| 399 | "javalib/arm64/boot-bar.art", |
| 400 | "javalib/arm64/boot-bar.oat", |
| 401 | "javalib/arm64/boot-bar.vdex", |
| 402 | "javalib/bar.jar", |
| 403 | "javalib/foo.jar", |
| 404 | }) |
| 405 | |
| 406 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 407 | `bar`, |
| 408 | `com.android.art.key`, |
| 409 | `mybootclasspathfragment`, |
| 410 | }) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 411 | }) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 412 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 413 | t.Run("source with inconsistency between config and contents", func(t *testing.T) { |
| 414 | android.GroupFixturePreparers( |
| 415 | commonPreparer, |
| 416 | |
| 417 | // Create an inconsistency between the ArtApexJars configuration and the art source |
| 418 | // bootclasspath_fragment module's contents property. |
| 419 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 420 | addSource("foo", "bar"), |
| 421 | ). |
| 422 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 423 | RunTest(t) |
| 424 | }) |
| 425 | |
| 426 | t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 427 | android.GroupFixturePreparers( |
| 428 | commonPreparer, |
| 429 | |
| 430 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 431 | // prebuilt_bootclasspath_fragment module's contents property. |
| 432 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 433 | addPrebuilt(false, "foo", "bar"), |
| 434 | ). |
| 435 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 436 | RunTest(t) |
| 437 | }) |
| 438 | |
| 439 | t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 440 | android.GroupFixturePreparers( |
| 441 | commonPreparer, |
| 442 | |
| 443 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 444 | // prebuilt_bootclasspath_fragment module's contents property. |
| 445 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 446 | addPrebuilt(true, "foo", "bar"), |
| 447 | |
| 448 | // Source contents property is consistent with the config. |
| 449 | addSource("foo"), |
| 450 | ). |
| 451 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 452 | RunTest(t) |
| 453 | }) |
| 454 | |
| 455 | t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 456 | android.GroupFixturePreparers( |
| 457 | commonPreparer, |
| 458 | |
| 459 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 460 | // prebuilt_bootclasspath_fragment module's contents property. |
| 461 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 462 | addPrebuilt(false, "foo", "bar"), |
| 463 | |
| 464 | // Source contents property is consistent with the config. |
| 465 | addSource("foo"), |
| 466 | |
| 467 | // This should pass because while the prebuilt is inconsistent with the configuration it is |
| 468 | // not actually used. |
| 469 | ).RunTest(t) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 470 | }) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 473 | func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 474 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 475 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 476 | prepareForTestWithArtApex, |
| 477 | |
| 478 | android.FixtureMergeMockFs(android.MockFS{ |
| 479 | "com.android.art-arm64.apex": nil, |
| 480 | "com.android.art-arm.apex": nil, |
| 481 | }), |
| 482 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 483 | // Configure some libraries in the art bootclasspath_fragment. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 484 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 485 | ).RunTestWithBp(t, ` |
| 486 | prebuilt_apex { |
| 487 | name: "com.android.art", |
| 488 | arch: { |
| 489 | arm64: { |
| 490 | src: "com.android.art-arm64.apex", |
| 491 | }, |
| 492 | arm: { |
| 493 | src: "com.android.art-arm.apex", |
| 494 | }, |
| 495 | }, |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 496 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | java_import { |
| 500 | name: "foo", |
| 501 | jars: ["foo.jar"], |
| 502 | apex_available: [ |
| 503 | "com.android.art", |
| 504 | ], |
| 505 | } |
| 506 | |
| 507 | java_import { |
| 508 | name: "bar", |
| 509 | jars: ["bar.jar"], |
| 510 | apex_available: [ |
| 511 | "com.android.art", |
| 512 | ], |
| 513 | } |
| 514 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 515 | prebuilt_bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 516 | name: "mybootclasspathfragment", |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 517 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 518 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 519 | contents: ["foo", "bar"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 520 | apex_available: [ |
| 521 | "com.android.art", |
| 522 | ], |
| 523 | } |
| 524 | `) |
| 525 | |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 526 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{ |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 527 | `com.android.art.apex.selector`, |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 528 | `prebuilt_mybootclasspathfragment`, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 529 | }) |
| 530 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 531 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common", []string{ |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 532 | `dex2oatd`, |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 533 | `prebuilt_bar`, |
| 534 | `prebuilt_foo`, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 535 | }) |
| 536 | } |
| 537 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 538 | func TestBootclasspathFragmentContentsNoName(t *testing.T) { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 539 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 540 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 541 | prepareForTestWithMyapex, |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 542 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
| 543 | java.FixtureConfigureBootJars("myapex:foo", "myapex:bar"), |
| 544 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 545 | // is disabled. |
| 546 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 547 | |
| 548 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 549 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 550 | ).RunTestWithBp(t, ` |
| 551 | apex { |
| 552 | name: "myapex", |
| 553 | key: "myapex.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 554 | bootclasspath_fragments: [ |
| 555 | "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 556 | ], |
| 557 | updatable: false, |
| 558 | } |
| 559 | |
| 560 | apex_key { |
| 561 | name: "myapex.key", |
| 562 | public_key: "testkey.avbpubkey", |
| 563 | private_key: "testkey.pem", |
| 564 | } |
| 565 | |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 566 | java_sdk_library { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 567 | name: "foo", |
| 568 | srcs: ["b.java"], |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 569 | shared_library: false, |
| 570 | public: {enabled: true}, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 571 | apex_available: [ |
| 572 | "myapex", |
| 573 | ], |
| 574 | } |
| 575 | |
| 576 | java_library { |
| 577 | name: "bar", |
| 578 | srcs: ["b.java"], |
| 579 | installable: true, |
| 580 | apex_available: [ |
| 581 | "myapex", |
| 582 | ], |
| 583 | } |
| 584 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 585 | bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 586 | name: "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 587 | contents: [ |
| 588 | "foo", |
| 589 | "bar", |
| 590 | ], |
| 591 | apex_available: [ |
| 592 | "myapex", |
| 593 | ], |
| 594 | } |
| 595 | `) |
| 596 | |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 597 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 598 | // This does not include art, oat or vdex files as they are only included for the art boot |
| 599 | // image. |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 600 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 601 | "javalib/bar.jar", |
| 602 | "javalib/foo.jar", |
| 603 | }) |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 604 | |
| 605 | java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 606 | `myapex.key`, |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 607 | `mybootclasspathfragment`, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 608 | }) |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 609 | |
| 610 | apex := result.ModuleForTests("myapex", "android_common_myapex_image") |
| 611 | apexRule := apex.Rule("apexRule") |
| 612 | copyCommands := apexRule.Args["copy_commands"] |
| 613 | |
| 614 | // Make sure that the fragment provides the hidden API encoded dex jars to the APEX. |
| 615 | fragment := result.Module("mybootclasspathfragment", "android_common_apex10000") |
| 616 | |
| 617 | info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 618 | |
| 619 | checkFragmentExportedDexJar := func(name string, expectedDexJar string) { |
| 620 | module := result.Module(name, "android_common_apex10000") |
Paul Duffin | 1a8010a | 2021-05-15 12:39:23 +0100 | [diff] [blame] | 621 | dexJar, err := info.DexBootJarPathForContentModule(module) |
| 622 | if err != nil { |
| 623 | t.Error(err) |
| 624 | } |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 625 | android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar) |
| 626 | |
| 627 | expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name) |
| 628 | android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand) |
| 629 | } |
| 630 | |
Paul Duffin | 54c98f5 | 2021-05-15 08:54:30 +0100 | [diff] [blame] | 631 | checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar") |
| 632 | 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] | 633 | } |
| 634 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 635 | // TODO(b/177892522) - add test for host apex. |