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 | |
| 163 | func TestBootImageInApex(t *testing.T) { |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame^] | 164 | result := android.GroupFixturePreparers( |
| 165 | prepareForTestWithBootImage, |
| 166 | prepareForTestWithMyapex, |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 167 | // Configure some libraries in the framework boot image. |
| 168 | dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"), |
| 169 | ).RunTestWithBp(t, ` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 170 | apex { |
| 171 | name: "myapex", |
| 172 | key: "myapex.key", |
| 173 | boot_images: [ |
| 174 | "mybootimage", |
| 175 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 176 | updatable: false, |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | apex_key { |
| 180 | name: "myapex.key", |
| 181 | public_key: "testkey.avbpubkey", |
| 182 | private_key: "testkey.pem", |
| 183 | } |
| 184 | |
| 185 | java_library { |
| 186 | name: "foo", |
| 187 | srcs: ["b.java"], |
| 188 | installable: true, |
| 189 | } |
| 190 | |
| 191 | java_library { |
| 192 | name: "bar", |
| 193 | srcs: ["b.java"], |
| 194 | installable: true, |
| 195 | } |
| 196 | |
| 197 | boot_image { |
| 198 | name: "mybootimage", |
| 199 | image_name: "boot", |
| 200 | apex_available: [ |
| 201 | "myapex", |
| 202 | ], |
| 203 | } |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 204 | |
| 205 | // Make sure that a preferred prebuilt doesn't affect the apex. |
| 206 | prebuilt_boot_image { |
| 207 | name: "mybootimage", |
| 208 | image_name: "boot", |
| 209 | prefer: true, |
| 210 | apex_available: [ |
| 211 | "myapex", |
| 212 | ], |
| 213 | } |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 214 | `) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 215 | |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 216 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 217 | "javalib/arm/boot-bar.art", |
| 218 | "javalib/arm/boot-bar.oat", |
| 219 | "javalib/arm/boot-bar.vdex", |
| 220 | "javalib/arm/boot-foo.art", |
| 221 | "javalib/arm/boot-foo.oat", |
| 222 | "javalib/arm/boot-foo.vdex", |
| 223 | "javalib/arm64/boot-bar.art", |
| 224 | "javalib/arm64/boot-bar.oat", |
| 225 | "javalib/arm64/boot-bar.vdex", |
| 226 | "javalib/arm64/boot-foo.art", |
| 227 | "javalib/arm64/boot-foo.oat", |
| 228 | "javalib/arm64/boot-foo.vdex", |
| 229 | }) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 230 | |
| 231 | java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 232 | `myapex.key`, |
| 233 | `mybootimage`, |
| 234 | }) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | // TODO(b/177892522) - add test for host apex. |