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