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 | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 18 | "strings" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | "android/soong/dexpreopt" |
| 23 | "android/soong/java" |
| 24 | ) |
| 25 | |
| 26 | // Contains tests for boot_image logic from java/boot_image.go as the ART boot image requires |
| 27 | // modules from the ART apex. |
| 28 | |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 29 | var prepareForTestWithBootImage = android.GroupFixturePreparers( |
| 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 | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 41 | func TestBootImages(t *testing.T) { |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 42 | result := android.GroupFixturePreparers( |
| 43 | prepareForTestWithBootImage, |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 44 | // Configure some libraries in the art and framework boot images. |
| 45 | dexpreopt.FixtureSetArtBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 46 | dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"), |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 47 | prepareForTestWithArtApex, |
| 48 | |
| 49 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 50 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 51 | ).RunTestWithBp(t, ` |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 52 | java_sdk_library { |
| 53 | name: "foo", |
| 54 | srcs: ["b.java"], |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | java_library { |
| 58 | name: "bar", |
| 59 | srcs: ["b.java"], |
| 60 | installable: true, |
| 61 | } |
| 62 | |
| 63 | apex { |
| 64 | name: "com.android.art", |
| 65 | key: "com.android.art.key", |
| 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"], |
| 85 | } |
| 86 | |
| 87 | java_library { |
| 88 | name: "quuz", |
| 89 | apex_available: [ |
| 90 | "com.android.art", |
| 91 | ], |
| 92 | srcs: ["b.java"], |
| 93 | } |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 94 | |
| 95 | boot_image { |
| 96 | name: "art-boot-image", |
| 97 | image_name: "art", |
| 98 | } |
| 99 | |
| 100 | boot_image { |
| 101 | name: "framework-boot-image", |
| 102 | image_name: "boot", |
| 103 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 104 | `, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 105 | ) |
| 106 | |
| 107 | // Make sure that the framework-boot-image is using the correct configuration. |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 108 | checkBootImage(t, result, "framework-boot-image", "platform:foo,platform:bar", ` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 109 | test_device/dex_bootjars/android/system/framework/arm/boot-foo.art |
| 110 | test_device/dex_bootjars/android/system/framework/arm/boot-foo.oat |
| 111 | test_device/dex_bootjars/android/system/framework/arm/boot-foo.vdex |
| 112 | test_device/dex_bootjars/android/system/framework/arm/boot-bar.art |
| 113 | test_device/dex_bootjars/android/system/framework/arm/boot-bar.oat |
| 114 | test_device/dex_bootjars/android/system/framework/arm/boot-bar.vdex |
| 115 | test_device/dex_bootjars/android/system/framework/arm64/boot-foo.art |
| 116 | test_device/dex_bootjars/android/system/framework/arm64/boot-foo.oat |
| 117 | test_device/dex_bootjars/android/system/framework/arm64/boot-foo.vdex |
| 118 | test_device/dex_bootjars/android/system/framework/arm64/boot-bar.art |
| 119 | test_device/dex_bootjars/android/system/framework/arm64/boot-bar.oat |
| 120 | test_device/dex_bootjars/android/system/framework/arm64/boot-bar.vdex |
| 121 | `) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 122 | |
| 123 | // Make sure that the art-boot-image is using the correct configuration. |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 124 | checkBootImage(t, result, "art-boot-image", "com.android.art:baz,com.android.art:quuz", ` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 125 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art |
| 126 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat |
| 127 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex |
| 128 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art |
| 129 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat |
| 130 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex |
| 131 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art |
| 132 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat |
| 133 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex |
| 134 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art |
| 135 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat |
| 136 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex |
| 137 | `) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 140 | func checkBootImage(t *testing.T, result *android.TestResult, moduleName string, expectedConfiguredModules string, expectedBootImageFiles string) { |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 141 | t.Helper() |
| 142 | |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 143 | bootImage := result.ModuleForTests(moduleName, "android_common").Module().(*java.BootImageModule) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 144 | |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 145 | bootImageInfo := result.ModuleProvider(bootImage, java.BootImageInfoProvider).(java.BootImageInfo) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 146 | modules := bootImageInfo.Modules() |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 147 | android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String()) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 148 | |
| 149 | // Get a list of all the paths in the boot image sorted by arch type. |
| 150 | allPaths := []string{} |
| 151 | bootImageFilesByArchType := bootImageInfo.AndroidBootImageFilesByArchType() |
| 152 | for _, archType := range android.ArchTypeList() { |
| 153 | if paths, ok := bootImageFilesByArchType[archType]; ok { |
| 154 | for _, path := range paths { |
| 155 | allPaths = append(allPaths, android.NormalizePathForTesting(path)) |
| 156 | } |
| 157 | } |
| 158 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 159 | |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 160 | android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootImageFiles, strings.Join(allPaths, "\n")) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 161 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 162 | |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 163 | func TestBootImageInArtApex(t *testing.T) { |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 164 | result := android.GroupFixturePreparers( |
| 165 | prepareForTestWithBootImage, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 166 | prepareForTestWithArtApex, |
| 167 | |
| 168 | // Configure some libraries in the art boot image. |
| 169 | dexpreopt.FixtureSetArtBootJars("com.android.art:foo", "com.android.art:bar"), |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 170 | ).RunTestWithBp(t, ` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 171 | apex { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 172 | name: "com.android.art", |
| 173 | key: "com.android.art.key", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 174 | boot_images: [ |
| 175 | "mybootimage", |
| 176 | ], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 177 | java_libs: [ |
| 178 | "foo", |
| 179 | "bar", |
| 180 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 181 | updatable: false, |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | apex_key { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 185 | name: "com.android.art.key", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 186 | public_key: "testkey.avbpubkey", |
| 187 | private_key: "testkey.pem", |
| 188 | } |
| 189 | |
| 190 | java_library { |
| 191 | name: "foo", |
| 192 | srcs: ["b.java"], |
| 193 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 194 | apex_available: [ |
| 195 | "com.android.art", |
| 196 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | java_library { |
| 200 | name: "bar", |
| 201 | srcs: ["b.java"], |
| 202 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 203 | apex_available: [ |
| 204 | "com.android.art", |
| 205 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | boot_image { |
| 209 | name: "mybootimage", |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 210 | image_name: "art", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 211 | apex_available: [ |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 212 | "com.android.art", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 213 | ], |
| 214 | } |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 215 | |
| 216 | // Make sure that a preferred prebuilt doesn't affect the apex. |
| 217 | prebuilt_boot_image { |
| 218 | name: "mybootimage", |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 219 | image_name: "art", |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 220 | prefer: true, |
| 221 | apex_available: [ |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 222 | "com.android.art", |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 223 | ], |
| 224 | } |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 225 | `) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 226 | |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 227 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 228 | "javalib/arm/boot.art", |
| 229 | "javalib/arm/boot.oat", |
| 230 | "javalib/arm/boot.vdex", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 231 | "javalib/arm/boot-bar.art", |
| 232 | "javalib/arm/boot-bar.oat", |
| 233 | "javalib/arm/boot-bar.vdex", |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 234 | "javalib/arm64/boot.art", |
| 235 | "javalib/arm64/boot.oat", |
| 236 | "javalib/arm64/boot.vdex", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 237 | "javalib/arm64/boot-bar.art", |
| 238 | "javalib/arm64/boot-bar.oat", |
| 239 | "javalib/arm64/boot-bar.vdex", |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 240 | "javalib/bar.jar", |
| 241 | "javalib/foo.jar", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 242 | }) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 243 | |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 244 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 245 | `bar`, |
| 246 | `com.android.art.key`, |
| 247 | `foo`, |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 248 | `mybootimage`, |
| 249 | }) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 252 | func TestBootImageInPrebuiltArtApex(t *testing.T) { |
| 253 | result := android.GroupFixturePreparers( |
| 254 | prepareForTestWithBootImage, |
| 255 | prepareForTestWithArtApex, |
| 256 | |
| 257 | android.FixtureMergeMockFs(android.MockFS{ |
| 258 | "com.android.art-arm64.apex": nil, |
| 259 | "com.android.art-arm.apex": nil, |
| 260 | }), |
| 261 | |
| 262 | // Configure some libraries in the art boot image. |
| 263 | dexpreopt.FixtureSetArtBootJars("com.android.art:foo", "com.android.art:bar"), |
| 264 | ).RunTestWithBp(t, ` |
| 265 | prebuilt_apex { |
| 266 | name: "com.android.art", |
| 267 | arch: { |
| 268 | arm64: { |
| 269 | src: "com.android.art-arm64.apex", |
| 270 | }, |
| 271 | arm: { |
| 272 | src: "com.android.art-arm.apex", |
| 273 | }, |
| 274 | }, |
| 275 | exported_java_libs: ["foo", "bar"], |
| 276 | } |
| 277 | |
| 278 | java_import { |
| 279 | name: "foo", |
| 280 | jars: ["foo.jar"], |
| 281 | apex_available: [ |
| 282 | "com.android.art", |
| 283 | ], |
| 284 | } |
| 285 | |
| 286 | java_import { |
| 287 | name: "bar", |
| 288 | jars: ["bar.jar"], |
| 289 | apex_available: [ |
| 290 | "com.android.art", |
| 291 | ], |
| 292 | } |
| 293 | |
| 294 | prebuilt_boot_image { |
| 295 | name: "mybootimage", |
| 296 | image_name: "art", |
| 297 | apex_available: [ |
| 298 | "com.android.art", |
| 299 | ], |
| 300 | } |
| 301 | `) |
| 302 | |
| 303 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common", []string{ |
| 304 | `prebuilt_bar`, |
| 305 | `prebuilt_foo`, |
| 306 | }) |
| 307 | |
| 308 | java.CheckModuleDependencies(t, result.TestContext, "mybootimage", "android_common", []string{ |
| 309 | `dex2oatd`, |
| 310 | }) |
| 311 | } |
| 312 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 313 | // TODO(b/177892522) - add test for host apex. |