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 | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 144 | 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] | 145 | t.Helper() |
| 146 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 147 | bootclasspathFragment := result.ModuleForTests(moduleName, "android_common").Module().(*java.BootclasspathFragmentModule) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 148 | |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 149 | bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 150 | modules := bootclasspathFragmentInfo.Modules() |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 151 | android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String()) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 152 | |
| 153 | // Get a list of all the paths in the boot image sorted by arch type. |
| 154 | allPaths := []string{} |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 155 | bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 156 | for _, archType := range android.ArchTypeList() { |
| 157 | if paths, ok := bootImageFilesByArchType[archType]; ok { |
| 158 | for _, path := range paths { |
| 159 | allPaths = append(allPaths, android.NormalizePathForTesting(path)) |
| 160 | } |
| 161 | } |
| 162 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 163 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 164 | android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n")) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 165 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 166 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 167 | func TestBootclasspathFragmentInArtApex(t *testing.T) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 168 | commonPreparer := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 169 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 170 | prepareForTestWithArtApex, |
| 171 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 172 | android.FixtureWithRootAndroidBp(` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 173 | apex { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 174 | name: "com.android.art", |
| 175 | key: "com.android.art.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 176 | bootclasspath_fragments: [ |
| 177 | "mybootclasspathfragment", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 178 | ], |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 179 | // 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] | 180 | // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the |
| 181 | // apex dedups the files correctly. |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 182 | java_libs: [ |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 183 | "bar", |
| 184 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 185 | updatable: false, |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | apex_key { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 189 | name: "com.android.art.key", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 190 | public_key: "testkey.avbpubkey", |
| 191 | private_key: "testkey.pem", |
| 192 | } |
| 193 | |
| 194 | java_library { |
| 195 | name: "foo", |
| 196 | srcs: ["b.java"], |
| 197 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 198 | apex_available: [ |
| 199 | "com.android.art", |
| 200 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | java_library { |
| 204 | name: "bar", |
| 205 | srcs: ["b.java"], |
| 206 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 207 | apex_available: [ |
| 208 | "com.android.art", |
| 209 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 212 | java_import { |
| 213 | name: "foo", |
| 214 | jars: ["foo.jar"], |
| 215 | apex_available: [ |
| 216 | "com.android.art", |
| 217 | ], |
| 218 | } |
| 219 | |
| 220 | java_import { |
| 221 | name: "bar", |
| 222 | jars: ["bar.jar"], |
| 223 | apex_available: [ |
| 224 | "com.android.art", |
| 225 | ], |
| 226 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 227 | `), |
| 228 | ) |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 229 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 230 | contentsInsert := func(contents []string) string { |
| 231 | insert := "" |
| 232 | if contents != nil { |
| 233 | insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`)) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 234 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 235 | return insert |
| 236 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 237 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 238 | addSource := func(contents ...string) android.FixturePreparer { |
| 239 | text := fmt.Sprintf(` |
| 240 | bootclasspath_fragment { |
| 241 | name: "mybootclasspathfragment", |
| 242 | image_name: "art", |
| 243 | %s |
| 244 | apex_available: [ |
| 245 | "com.android.art", |
| 246 | ], |
| 247 | } |
| 248 | `, contentsInsert(contents)) |
| 249 | |
| 250 | return android.FixtureAddTextFile("art/build/boot/Android.bp", text) |
| 251 | } |
| 252 | |
| 253 | addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer { |
| 254 | text := fmt.Sprintf(` |
| 255 | prebuilt_bootclasspath_fragment { |
| 256 | name: "mybootclasspathfragment", |
| 257 | image_name: "art", |
| 258 | %s |
| 259 | prefer: %t, |
| 260 | apex_available: [ |
| 261 | "com.android.art", |
| 262 | ], |
| 263 | } |
| 264 | `, contentsInsert(contents), prefer) |
| 265 | return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text) |
| 266 | } |
| 267 | |
| 268 | t.Run("boot image files", func(t *testing.T) { |
| 269 | result := android.GroupFixturePreparers( |
| 270 | commonPreparer, |
| 271 | |
| 272 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 273 | // bootclasspath_fragment's contents property. |
| 274 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 275 | addSource("foo", "bar"), |
| 276 | |
| 277 | // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex. |
| 278 | addPrebuilt(true, "foo", "bar"), |
| 279 | ).RunTest(t) |
| 280 | |
| 281 | 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^] | 282 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 283 | "javalib/arm/boot.art", |
| 284 | "javalib/arm/boot.oat", |
| 285 | "javalib/arm/boot.vdex", |
| 286 | "javalib/arm/boot-bar.art", |
| 287 | "javalib/arm/boot-bar.oat", |
| 288 | "javalib/arm/boot-bar.vdex", |
| 289 | "javalib/arm64/boot.art", |
| 290 | "javalib/arm64/boot.oat", |
| 291 | "javalib/arm64/boot.vdex", |
| 292 | "javalib/arm64/boot-bar.art", |
| 293 | "javalib/arm64/boot-bar.oat", |
| 294 | "javalib/arm64/boot-bar.vdex", |
| 295 | "javalib/bar.jar", |
| 296 | "javalib/foo.jar", |
| 297 | }) |
| 298 | |
| 299 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 300 | `bar`, |
| 301 | `com.android.art.key`, |
| 302 | `mybootclasspathfragment`, |
| 303 | }) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 304 | }) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 305 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 306 | t.Run("source with inconsistency between config and contents", func(t *testing.T) { |
| 307 | android.GroupFixturePreparers( |
| 308 | commonPreparer, |
| 309 | |
| 310 | // Create an inconsistency between the ArtApexJars configuration and the art source |
| 311 | // bootclasspath_fragment module's contents property. |
| 312 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 313 | addSource("foo", "bar"), |
| 314 | ). |
| 315 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 316 | RunTest(t) |
| 317 | }) |
| 318 | |
| 319 | t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 320 | android.GroupFixturePreparers( |
| 321 | commonPreparer, |
| 322 | |
| 323 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 324 | // prebuilt_bootclasspath_fragment module's contents property. |
| 325 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 326 | addPrebuilt(false, "foo", "bar"), |
| 327 | ). |
| 328 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 329 | RunTest(t) |
| 330 | }) |
| 331 | |
| 332 | t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 333 | android.GroupFixturePreparers( |
| 334 | commonPreparer, |
| 335 | |
| 336 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 337 | // prebuilt_bootclasspath_fragment module's contents property. |
| 338 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 339 | addPrebuilt(true, "foo", "bar"), |
| 340 | |
| 341 | // Source contents property is consistent with the config. |
| 342 | addSource("foo"), |
| 343 | ). |
| 344 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 345 | RunTest(t) |
| 346 | }) |
| 347 | |
| 348 | t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 349 | android.GroupFixturePreparers( |
| 350 | commonPreparer, |
| 351 | |
| 352 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 353 | // prebuilt_bootclasspath_fragment module's contents property. |
| 354 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 355 | addPrebuilt(false, "foo", "bar"), |
| 356 | |
| 357 | // Source contents property is consistent with the config. |
| 358 | addSource("foo"), |
| 359 | |
| 360 | // This should pass because while the prebuilt is inconsistent with the configuration it is |
| 361 | // not actually used. |
| 362 | ).RunTest(t) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 363 | }) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 366 | func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 367 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 368 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 369 | prepareForTestWithArtApex, |
| 370 | |
| 371 | android.FixtureMergeMockFs(android.MockFS{ |
| 372 | "com.android.art-arm64.apex": nil, |
| 373 | "com.android.art-arm.apex": nil, |
| 374 | }), |
| 375 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 376 | // Configure some libraries in the art bootclasspath_fragment. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 377 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 378 | ).RunTestWithBp(t, ` |
| 379 | prebuilt_apex { |
| 380 | name: "com.android.art", |
| 381 | arch: { |
| 382 | arm64: { |
| 383 | src: "com.android.art-arm64.apex", |
| 384 | }, |
| 385 | arm: { |
| 386 | src: "com.android.art-arm.apex", |
| 387 | }, |
| 388 | }, |
| 389 | exported_java_libs: ["foo", "bar"], |
| 390 | } |
| 391 | |
| 392 | java_import { |
| 393 | name: "foo", |
| 394 | jars: ["foo.jar"], |
| 395 | apex_available: [ |
| 396 | "com.android.art", |
| 397 | ], |
| 398 | } |
| 399 | |
| 400 | java_import { |
| 401 | name: "bar", |
| 402 | jars: ["bar.jar"], |
| 403 | apex_available: [ |
| 404 | "com.android.art", |
| 405 | ], |
| 406 | } |
| 407 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 408 | prebuilt_bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 409 | name: "mybootclasspathfragment", |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 410 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 411 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 412 | contents: ["foo", "bar"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 413 | apex_available: [ |
| 414 | "com.android.art", |
| 415 | ], |
| 416 | } |
| 417 | `) |
| 418 | |
| 419 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common", []string{ |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 420 | `com.android.art.apex.selector`, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 421 | `prebuilt_bar`, |
| 422 | `prebuilt_foo`, |
| 423 | }) |
| 424 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 425 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common", []string{ |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 426 | `dex2oatd`, |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 427 | `prebuilt_bar`, |
| 428 | `prebuilt_foo`, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 429 | }) |
| 430 | } |
| 431 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 432 | func TestBootclasspathFragmentContentsNoName(t *testing.T) { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 433 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 434 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 435 | prepareForTestWithMyapex, |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 436 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
| 437 | java.FixtureConfigureBootJars("myapex:foo", "myapex:bar"), |
| 438 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 439 | // is disabled. |
| 440 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 441 | |
| 442 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 443 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 444 | ).RunTestWithBp(t, ` |
| 445 | apex { |
| 446 | name: "myapex", |
| 447 | key: "myapex.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 448 | bootclasspath_fragments: [ |
| 449 | "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 450 | ], |
| 451 | updatable: false, |
| 452 | } |
| 453 | |
| 454 | apex_key { |
| 455 | name: "myapex.key", |
| 456 | public_key: "testkey.avbpubkey", |
| 457 | private_key: "testkey.pem", |
| 458 | } |
| 459 | |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 460 | java_sdk_library { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 461 | name: "foo", |
| 462 | srcs: ["b.java"], |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 463 | shared_library: false, |
| 464 | public: {enabled: true}, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 465 | apex_available: [ |
| 466 | "myapex", |
| 467 | ], |
| 468 | } |
| 469 | |
| 470 | java_library { |
| 471 | name: "bar", |
| 472 | srcs: ["b.java"], |
| 473 | installable: true, |
| 474 | apex_available: [ |
| 475 | "myapex", |
| 476 | ], |
| 477 | } |
| 478 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 479 | bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 480 | name: "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 481 | contents: [ |
| 482 | "foo", |
| 483 | "bar", |
| 484 | ], |
| 485 | apex_available: [ |
| 486 | "myapex", |
| 487 | ], |
| 488 | } |
| 489 | `) |
| 490 | |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 491 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 492 | // This does not include art, oat or vdex files as they are only included for the art boot |
| 493 | // image. |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame^] | 494 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 495 | "javalib/bar.jar", |
| 496 | "javalib/foo.jar", |
| 497 | }) |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 498 | |
| 499 | java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 500 | `myapex.key`, |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 501 | `mybootclasspathfragment`, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 502 | }) |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 503 | |
| 504 | apex := result.ModuleForTests("myapex", "android_common_myapex_image") |
| 505 | apexRule := apex.Rule("apexRule") |
| 506 | copyCommands := apexRule.Args["copy_commands"] |
| 507 | |
| 508 | // Make sure that the fragment provides the hidden API encoded dex jars to the APEX. |
| 509 | fragment := result.Module("mybootclasspathfragment", "android_common_apex10000") |
| 510 | |
| 511 | info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 512 | |
| 513 | checkFragmentExportedDexJar := func(name string, expectedDexJar string) { |
| 514 | module := result.Module(name, "android_common_apex10000") |
Paul Duffin | 1a8010a | 2021-05-15 12:39:23 +0100 | [diff] [blame] | 515 | dexJar, err := info.DexBootJarPathForContentModule(module) |
| 516 | if err != nil { |
| 517 | t.Error(err) |
| 518 | } |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 519 | android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar) |
| 520 | |
| 521 | expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name) |
| 522 | android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand) |
| 523 | } |
| 524 | |
| 525 | checkFragmentExportedDexJar("foo", "out/soong/.intermediates/foo/android_common_apex10000/hiddenapi/foo.jar") |
| 526 | checkFragmentExportedDexJar("bar", "out/soong/.intermediates/bar/android_common_apex10000/hiddenapi/bar.jar") |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 529 | // TODO(b/177892522) - add test for host apex. |