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 | |
| 29 | func TestBootImages(t *testing.T) { |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 30 | result := apexFixtureFactory.Extend( |
| 31 | // Configure some libraries in the art and framework boot images. |
| 32 | dexpreopt.FixtureSetArtBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 33 | dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"), |
| 34 | filesForSdkLibrary.AddToFixture(), |
| 35 | // Some additional files needed for the art apex. |
| 36 | android.FixtureMergeMockFs(android.MockFS{ |
| 37 | "com.android.art.avbpubkey": nil, |
| 38 | "com.android.art.pem": nil, |
| 39 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 40 | }), |
| 41 | ).RunTestWithBp(t, ` |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 42 | java_sdk_library { |
| 43 | name: "foo", |
| 44 | srcs: ["b.java"], |
| 45 | unsafe_ignore_missing_latest_api: true, |
| 46 | } |
| 47 | |
| 48 | java_library { |
| 49 | name: "bar", |
| 50 | srcs: ["b.java"], |
| 51 | installable: true, |
| 52 | } |
| 53 | |
| 54 | apex { |
| 55 | name: "com.android.art", |
| 56 | key: "com.android.art.key", |
| 57 | java_libs: [ |
| 58 | "baz", |
| 59 | "quuz", |
| 60 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 61 | updatable: false, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | apex_key { |
| 65 | name: "com.android.art.key", |
| 66 | public_key: "com.android.art.avbpubkey", |
| 67 | private_key: "com.android.art.pem", |
| 68 | } |
| 69 | |
| 70 | java_library { |
| 71 | name: "baz", |
| 72 | apex_available: [ |
| 73 | "com.android.art", |
| 74 | ], |
| 75 | srcs: ["b.java"], |
| 76 | } |
| 77 | |
| 78 | java_library { |
| 79 | name: "quuz", |
| 80 | apex_available: [ |
| 81 | "com.android.art", |
| 82 | ], |
| 83 | srcs: ["b.java"], |
| 84 | } |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 85 | |
| 86 | boot_image { |
| 87 | name: "art-boot-image", |
| 88 | image_name: "art", |
| 89 | } |
| 90 | |
| 91 | boot_image { |
| 92 | name: "framework-boot-image", |
| 93 | image_name: "boot", |
| 94 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 95 | `, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 96 | ) |
| 97 | |
| 98 | // Make sure that the framework-boot-image is using the correct configuration. |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 99 | checkBootImage(t, result, "framework-boot-image", "platform:foo,platform:bar", ` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 100 | test_device/dex_bootjars/android/system/framework/arm/boot-foo.art |
| 101 | test_device/dex_bootjars/android/system/framework/arm/boot-foo.oat |
| 102 | test_device/dex_bootjars/android/system/framework/arm/boot-foo.vdex |
| 103 | test_device/dex_bootjars/android/system/framework/arm/boot-bar.art |
| 104 | test_device/dex_bootjars/android/system/framework/arm/boot-bar.oat |
| 105 | test_device/dex_bootjars/android/system/framework/arm/boot-bar.vdex |
| 106 | test_device/dex_bootjars/android/system/framework/arm64/boot-foo.art |
| 107 | test_device/dex_bootjars/android/system/framework/arm64/boot-foo.oat |
| 108 | test_device/dex_bootjars/android/system/framework/arm64/boot-foo.vdex |
| 109 | test_device/dex_bootjars/android/system/framework/arm64/boot-bar.art |
| 110 | test_device/dex_bootjars/android/system/framework/arm64/boot-bar.oat |
| 111 | test_device/dex_bootjars/android/system/framework/arm64/boot-bar.vdex |
| 112 | `) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 113 | |
| 114 | // Make sure that the art-boot-image is using the correct configuration. |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 115 | 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] | 116 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art |
| 117 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat |
| 118 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex |
| 119 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art |
| 120 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat |
| 121 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex |
| 122 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art |
| 123 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat |
| 124 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex |
| 125 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art |
| 126 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat |
| 127 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex |
| 128 | `) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 131 | 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] | 132 | t.Helper() |
| 133 | |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 134 | bootImage := result.ModuleForTests(moduleName, "android_common").Module().(*java.BootImageModule) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 135 | |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 136 | bootImageInfo := result.ModuleProvider(bootImage, java.BootImageInfoProvider).(java.BootImageInfo) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 137 | modules := bootImageInfo.Modules() |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 138 | android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String()) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 139 | |
| 140 | // Get a list of all the paths in the boot image sorted by arch type. |
| 141 | allPaths := []string{} |
| 142 | bootImageFilesByArchType := bootImageInfo.AndroidBootImageFilesByArchType() |
| 143 | for _, archType := range android.ArchTypeList() { |
| 144 | if paths, ok := bootImageFilesByArchType[archType]; ok { |
| 145 | for _, path := range paths { |
| 146 | allPaths = append(allPaths, android.NormalizePathForTesting(path)) |
| 147 | } |
| 148 | } |
| 149 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 150 | |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 151 | android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootImageFiles, strings.Join(allPaths, "\n")) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 152 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 153 | |
| 154 | func TestBootImageInApex(t *testing.T) { |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 155 | result := apexFixtureFactory.Extend( |
| 156 | // Configure some libraries in the framework boot image. |
| 157 | dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"), |
| 158 | ).RunTestWithBp(t, ` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 159 | apex { |
| 160 | name: "myapex", |
| 161 | key: "myapex.key", |
| 162 | boot_images: [ |
| 163 | "mybootimage", |
| 164 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 165 | updatable: false, |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | apex_key { |
| 169 | name: "myapex.key", |
| 170 | public_key: "testkey.avbpubkey", |
| 171 | private_key: "testkey.pem", |
| 172 | } |
| 173 | |
| 174 | java_library { |
| 175 | name: "foo", |
| 176 | srcs: ["b.java"], |
| 177 | installable: true, |
| 178 | } |
| 179 | |
| 180 | java_library { |
| 181 | name: "bar", |
| 182 | srcs: ["b.java"], |
| 183 | installable: true, |
| 184 | } |
| 185 | |
| 186 | boot_image { |
| 187 | name: "mybootimage", |
| 188 | image_name: "boot", |
| 189 | apex_available: [ |
| 190 | "myapex", |
| 191 | ], |
| 192 | } |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 193 | `) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 194 | |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame^] | 195 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 196 | "javalib/arm/boot-bar.art", |
| 197 | "javalib/arm/boot-bar.oat", |
| 198 | "javalib/arm/boot-bar.vdex", |
| 199 | "javalib/arm/boot-foo.art", |
| 200 | "javalib/arm/boot-foo.oat", |
| 201 | "javalib/arm/boot-foo.vdex", |
| 202 | "javalib/arm64/boot-bar.art", |
| 203 | "javalib/arm64/boot-bar.oat", |
| 204 | "javalib/arm64/boot-bar.vdex", |
| 205 | "javalib/arm64/boot-foo.art", |
| 206 | "javalib/arm64/boot-foo.oat", |
| 207 | "javalib/arm64/boot-foo.vdex", |
| 208 | }) |
| 209 | } |
| 210 | |
| 211 | // TODO(b/177892522) - add test for host apex. |