blob: d447d70111993b5277398999d6d2c99925aaa515 [file] [log] [blame]
Paul Duffin3451e162021-01-20 15:16:56 +00001// 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
15package apex
16
17import (
Paul Duffina1d60252021-01-21 18:13:43 +000018 "strings"
Paul Duffin3451e162021-01-20 15:16:56 +000019 "testing"
20
21 "android/soong/android"
Paul Duffin3451e162021-01-20 15:16:56 +000022 "android/soong/java"
23)
24
25// Contains tests for boot_image logic from java/boot_image.go as the ART boot image requires
26// modules from the ART apex.
27
Paul Duffin52bfaa42021-03-23 23:40:12 +000028var prepareForTestWithBootImage = android.GroupFixturePreparers(
29 java.PrepareForTestWithDexpreopt,
30 PrepareForTestWithApexBuildComponents,
31)
32
33// Some additional files needed for the art apex.
34var prepareForTestWithArtApex = android.FixtureMergeMockFs(android.MockFS{
35 "com.android.art.avbpubkey": nil,
36 "com.android.art.pem": nil,
37 "system/sepolicy/apex/com.android.art-file_contexts": nil,
38})
39
Paul Duffin3451e162021-01-20 15:16:56 +000040func TestBootImages(t *testing.T) {
Paul Duffin52bfaa42021-03-23 23:40:12 +000041 result := android.GroupFixturePreparers(
42 prepareForTestWithBootImage,
Paul Duffin34d433a2021-03-09 14:13:25 +000043 // Configure some libraries in the art and framework boot images.
Paul Duffin60264a02021-04-12 20:02:36 +010044 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
Paul Duffin52bfaa42021-03-23 23:40:12 +000045 prepareForTestWithArtApex,
46
47 java.PrepareForTestWithJavaSdkLibraryFiles,
48 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin34d433a2021-03-09 14:13:25 +000049 ).RunTestWithBp(t, `
Paul Duffin3451e162021-01-20 15:16:56 +000050 java_sdk_library {
51 name: "foo",
52 srcs: ["b.java"],
Paul Duffin3451e162021-01-20 15:16:56 +000053 }
54
55 java_library {
56 name: "bar",
57 srcs: ["b.java"],
58 installable: true,
59 }
60
61 apex {
62 name: "com.android.art",
63 key: "com.android.art.key",
64 java_libs: [
65 "baz",
66 "quuz",
67 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +000068 updatable: false,
Paul Duffin3451e162021-01-20 15:16:56 +000069 }
70
71 apex_key {
72 name: "com.android.art.key",
73 public_key: "com.android.art.avbpubkey",
74 private_key: "com.android.art.pem",
75 }
76
77 java_library {
78 name: "baz",
79 apex_available: [
80 "com.android.art",
81 ],
82 srcs: ["b.java"],
83 }
84
85 java_library {
86 name: "quuz",
87 apex_available: [
88 "com.android.art",
89 ],
90 srcs: ["b.java"],
91 }
Paul Duffin5bbfef82021-01-30 12:57:26 +000092
93 boot_image {
94 name: "art-boot-image",
95 image_name: "art",
Paul Duffinc7ef9892021-03-23 23:21:59 +000096 apex_available: [
97 "com.android.art",
98 ],
Paul Duffin5bbfef82021-01-30 12:57:26 +000099 }
100
101 boot_image {
102 name: "framework-boot-image",
103 image_name: "boot",
104 }
Paul Duffin3451e162021-01-20 15:16:56 +0000105`,
Paul Duffin3451e162021-01-20 15:16:56 +0000106 )
107
108 // Make sure that the framework-boot-image is using the correct configuration.
Paul Duffin34d433a2021-03-09 14:13:25 +0000109 checkBootImage(t, result, "framework-boot-image", "platform:foo,platform:bar", `
Paul Duffina1d60252021-01-21 18:13:43 +0000110test_device/dex_bootjars/android/system/framework/arm/boot-foo.art
111test_device/dex_bootjars/android/system/framework/arm/boot-foo.oat
112test_device/dex_bootjars/android/system/framework/arm/boot-foo.vdex
113test_device/dex_bootjars/android/system/framework/arm/boot-bar.art
114test_device/dex_bootjars/android/system/framework/arm/boot-bar.oat
115test_device/dex_bootjars/android/system/framework/arm/boot-bar.vdex
116test_device/dex_bootjars/android/system/framework/arm64/boot-foo.art
117test_device/dex_bootjars/android/system/framework/arm64/boot-foo.oat
118test_device/dex_bootjars/android/system/framework/arm64/boot-foo.vdex
119test_device/dex_bootjars/android/system/framework/arm64/boot-bar.art
120test_device/dex_bootjars/android/system/framework/arm64/boot-bar.oat
121test_device/dex_bootjars/android/system/framework/arm64/boot-bar.vdex
122`)
Paul Duffin3451e162021-01-20 15:16:56 +0000123
124 // Make sure that the art-boot-image is using the correct configuration.
Paul Duffin34d433a2021-03-09 14:13:25 +0000125 checkBootImage(t, result, "art-boot-image", "com.android.art:baz,com.android.art:quuz", `
Paul Duffina1d60252021-01-21 18:13:43 +0000126test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
127test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
128test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
129test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art
130test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat
131test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex
132test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art
133test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat
134test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex
135test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art
136test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat
137test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex
138`)
Paul Duffin3451e162021-01-20 15:16:56 +0000139}
140
Paul Duffin34d433a2021-03-09 14:13:25 +0000141func checkBootImage(t *testing.T, result *android.TestResult, moduleName string, expectedConfiguredModules string, expectedBootImageFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000142 t.Helper()
143
Paul Duffin34d433a2021-03-09 14:13:25 +0000144 bootImage := result.ModuleForTests(moduleName, "android_common").Module().(*java.BootImageModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000145
Paul Duffin34d433a2021-03-09 14:13:25 +0000146 bootImageInfo := result.ModuleProvider(bootImage, java.BootImageInfoProvider).(java.BootImageInfo)
Paul Duffin3451e162021-01-20 15:16:56 +0000147 modules := bootImageInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000148 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000149
150 // Get a list of all the paths in the boot image sorted by arch type.
151 allPaths := []string{}
152 bootImageFilesByArchType := bootImageInfo.AndroidBootImageFilesByArchType()
153 for _, archType := range android.ArchTypeList() {
154 if paths, ok := bootImageFilesByArchType[archType]; ok {
155 for _, path := range paths {
156 allPaths = append(allPaths, android.NormalizePathForTesting(path))
157 }
158 }
159 }
Paul Duffin3451e162021-01-20 15:16:56 +0000160
Paul Duffin34d433a2021-03-09 14:13:25 +0000161 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootImageFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000162}
Paul Duffina1d60252021-01-21 18:13:43 +0000163
Paul Duffin9ea71c02021-03-23 22:53:07 +0000164func TestBootImageInArtApex(t *testing.T) {
Paul Duffin52bfaa42021-03-23 23:40:12 +0000165 result := android.GroupFixturePreparers(
166 prepareForTestWithBootImage,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000167 prepareForTestWithArtApex,
168
169 // Configure some libraries in the art boot image.
Paul Duffin60264a02021-04-12 20:02:36 +0100170 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
Paul Duffin34d433a2021-03-09 14:13:25 +0000171 ).RunTestWithBp(t, `
Paul Duffina1d60252021-01-21 18:13:43 +0000172 apex {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000173 name: "com.android.art",
174 key: "com.android.art.key",
Paul Duffina1d60252021-01-21 18:13:43 +0000175 boot_images: [
176 "mybootimage",
177 ],
Paul Duffin4d101b62021-03-24 15:42:20 +0000178 // bar (like foo) should be transitively included in this apex because it is part of the
179 // mybootimage boot_image. However, it is kept here to ensure that the apex dedups the files
180 // correctly.
Paul Duffin9ea71c02021-03-23 22:53:07 +0000181 java_libs: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000182 "bar",
183 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000184 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000185 }
186
187 apex_key {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000188 name: "com.android.art.key",
Paul Duffina1d60252021-01-21 18:13:43 +0000189 public_key: "testkey.avbpubkey",
190 private_key: "testkey.pem",
191 }
192
193 java_library {
194 name: "foo",
195 srcs: ["b.java"],
196 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000197 apex_available: [
198 "com.android.art",
199 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000200 }
201
202 java_library {
203 name: "bar",
204 srcs: ["b.java"],
205 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000206 apex_available: [
207 "com.android.art",
208 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000209 }
210
211 boot_image {
212 name: "mybootimage",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000213 image_name: "art",
Paul Duffina1d60252021-01-21 18:13:43 +0000214 apex_available: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000215 "com.android.art",
Paul Duffina1d60252021-01-21 18:13:43 +0000216 ],
217 }
Paul Duffin396229f2021-03-18 18:30:31 +0000218
219 // Make sure that a preferred prebuilt doesn't affect the apex.
220 prebuilt_boot_image {
221 name: "mybootimage",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000222 image_name: "art",
Paul Duffin396229f2021-03-18 18:30:31 +0000223 prefer: true,
224 apex_available: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000225 "com.android.art",
Paul Duffin396229f2021-03-18 18:30:31 +0000226 ],
227 }
Paul Duffin34d433a2021-03-09 14:13:25 +0000228 `)
Paul Duffina1d60252021-01-21 18:13:43 +0000229
Paul Duffin9ea71c02021-03-23 22:53:07 +0000230 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
231 "javalib/arm/boot.art",
232 "javalib/arm/boot.oat",
233 "javalib/arm/boot.vdex",
Paul Duffina1d60252021-01-21 18:13:43 +0000234 "javalib/arm/boot-bar.art",
235 "javalib/arm/boot-bar.oat",
236 "javalib/arm/boot-bar.vdex",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000237 "javalib/arm64/boot.art",
238 "javalib/arm64/boot.oat",
239 "javalib/arm64/boot.vdex",
Paul Duffina1d60252021-01-21 18:13:43 +0000240 "javalib/arm64/boot-bar.art",
241 "javalib/arm64/boot-bar.oat",
242 "javalib/arm64/boot-bar.vdex",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000243 "javalib/bar.jar",
244 "javalib/foo.jar",
Paul Duffina1d60252021-01-21 18:13:43 +0000245 })
Paul Duffin396229f2021-03-18 18:30:31 +0000246
Paul Duffin9ea71c02021-03-23 22:53:07 +0000247 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
248 `bar`,
249 `com.android.art.key`,
Paul Duffin396229f2021-03-18 18:30:31 +0000250 `mybootimage`,
251 })
Paul Duffina1d60252021-01-21 18:13:43 +0000252}
253
Paul Duffin9ea71c02021-03-23 22:53:07 +0000254func TestBootImageInPrebuiltArtApex(t *testing.T) {
255 result := android.GroupFixturePreparers(
256 prepareForTestWithBootImage,
257 prepareForTestWithArtApex,
258
259 android.FixtureMergeMockFs(android.MockFS{
260 "com.android.art-arm64.apex": nil,
261 "com.android.art-arm.apex": nil,
262 }),
263
264 // Configure some libraries in the art boot image.
Paul Duffin60264a02021-04-12 20:02:36 +0100265 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
Paul Duffin9ea71c02021-03-23 22:53:07 +0000266 ).RunTestWithBp(t, `
267 prebuilt_apex {
268 name: "com.android.art",
269 arch: {
270 arm64: {
271 src: "com.android.art-arm64.apex",
272 },
273 arm: {
274 src: "com.android.art-arm.apex",
275 },
276 },
277 exported_java_libs: ["foo", "bar"],
278 }
279
280 java_import {
281 name: "foo",
282 jars: ["foo.jar"],
283 apex_available: [
284 "com.android.art",
285 ],
286 }
287
288 java_import {
289 name: "bar",
290 jars: ["bar.jar"],
291 apex_available: [
292 "com.android.art",
293 ],
294 }
295
296 prebuilt_boot_image {
297 name: "mybootimage",
298 image_name: "art",
299 apex_available: [
300 "com.android.art",
301 ],
302 }
303 `)
304
305 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common", []string{
Paul Duffin11216db2021-03-01 14:14:52 +0000306 `com.android.art.apex.selector`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000307 `prebuilt_bar`,
308 `prebuilt_foo`,
309 })
310
311 java.CheckModuleDependencies(t, result.TestContext, "mybootimage", "android_common", []string{
312 `dex2oatd`,
Paul Duffinc7ef9892021-03-23 23:21:59 +0000313 `prebuilt_bar`,
314 `prebuilt_foo`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000315 })
316}
317
Paul Duffin82886d62021-03-24 01:34:57 +0000318func TestBootImageContentsNoName(t *testing.T) {
319 result := android.GroupFixturePreparers(
320 prepareForTestWithBootImage,
321 prepareForTestWithMyapex,
322 ).RunTestWithBp(t, `
323 apex {
324 name: "myapex",
325 key: "myapex.key",
326 boot_images: [
327 "mybootimage",
328 ],
329 updatable: false,
330 }
331
332 apex_key {
333 name: "myapex.key",
334 public_key: "testkey.avbpubkey",
335 private_key: "testkey.pem",
336 }
337
338 java_library {
339 name: "foo",
340 srcs: ["b.java"],
341 installable: true,
342 apex_available: [
343 "myapex",
344 ],
345 }
346
347 java_library {
348 name: "bar",
349 srcs: ["b.java"],
350 installable: true,
351 apex_available: [
352 "myapex",
353 ],
354 }
355
356 boot_image {
357 name: "mybootimage",
358 contents: [
359 "foo",
360 "bar",
361 ],
362 apex_available: [
363 "myapex",
364 ],
365 }
366 `)
367
Paul Duffin4d101b62021-03-24 15:42:20 +0000368 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
369 // This does not include art, oat or vdex files as they are only included for the art boot
370 // image.
371 "javalib/bar.jar",
372 "javalib/foo.jar",
373 })
Paul Duffin82886d62021-03-24 01:34:57 +0000374
375 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
376 `myapex.key`,
377 `mybootimage`,
378 })
379}
380
Paul Duffina1d60252021-01-21 18:13:43 +0000381// TODO(b/177892522) - add test for host apex.