blob: 91b45fc745e5ea1241f7c79c76be4dad3560c91a [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"
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 Duffin52bfaa42021-03-23 23:40:12 +000029var prepareForTestWithBootImage = android.GroupFixturePreparers(
30 java.PrepareForTestWithDexpreopt,
31 PrepareForTestWithApexBuildComponents,
32)
33
34// Some additional files needed for the art apex.
35var 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 Duffin3451e162021-01-20 15:16:56 +000041func TestBootImages(t *testing.T) {
Paul Duffin52bfaa42021-03-23 23:40:12 +000042 result := android.GroupFixturePreparers(
43 prepareForTestWithBootImage,
Paul Duffin34d433a2021-03-09 14:13:25 +000044 // 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 Duffin52bfaa42021-03-23 23:40:12 +000047 prepareForTestWithArtApex,
48
49 java.PrepareForTestWithJavaSdkLibraryFiles,
50 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin34d433a2021-03-09 14:13:25 +000051 ).RunTestWithBp(t, `
Paul Duffin3451e162021-01-20 15:16:56 +000052 java_sdk_library {
53 name: "foo",
54 srcs: ["b.java"],
Paul Duffin3451e162021-01-20 15:16:56 +000055 }
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 Inwoodf8dcf5e2021-02-16 11:40:16 +000070 updatable: false,
Paul Duffin3451e162021-01-20 15:16:56 +000071 }
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 Duffin5bbfef82021-01-30 12:57:26 +000094
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 Duffin3451e162021-01-20 15:16:56 +0000104`,
Paul Duffin3451e162021-01-20 15:16:56 +0000105 )
106
107 // Make sure that the framework-boot-image is using the correct configuration.
Paul Duffin34d433a2021-03-09 14:13:25 +0000108 checkBootImage(t, result, "framework-boot-image", "platform:foo,platform:bar", `
Paul Duffina1d60252021-01-21 18:13:43 +0000109test_device/dex_bootjars/android/system/framework/arm/boot-foo.art
110test_device/dex_bootjars/android/system/framework/arm/boot-foo.oat
111test_device/dex_bootjars/android/system/framework/arm/boot-foo.vdex
112test_device/dex_bootjars/android/system/framework/arm/boot-bar.art
113test_device/dex_bootjars/android/system/framework/arm/boot-bar.oat
114test_device/dex_bootjars/android/system/framework/arm/boot-bar.vdex
115test_device/dex_bootjars/android/system/framework/arm64/boot-foo.art
116test_device/dex_bootjars/android/system/framework/arm64/boot-foo.oat
117test_device/dex_bootjars/android/system/framework/arm64/boot-foo.vdex
118test_device/dex_bootjars/android/system/framework/arm64/boot-bar.art
119test_device/dex_bootjars/android/system/framework/arm64/boot-bar.oat
120test_device/dex_bootjars/android/system/framework/arm64/boot-bar.vdex
121`)
Paul Duffin3451e162021-01-20 15:16:56 +0000122
123 // Make sure that the art-boot-image is using the correct configuration.
Paul Duffin34d433a2021-03-09 14:13:25 +0000124 checkBootImage(t, result, "art-boot-image", "com.android.art:baz,com.android.art:quuz", `
Paul Duffina1d60252021-01-21 18:13:43 +0000125test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
126test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
127test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
128test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art
129test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat
130test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex
131test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art
132test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat
133test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex
134test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art
135test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat
136test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex
137`)
Paul Duffin3451e162021-01-20 15:16:56 +0000138}
139
Paul Duffin34d433a2021-03-09 14:13:25 +0000140func checkBootImage(t *testing.T, result *android.TestResult, moduleName string, expectedConfiguredModules string, expectedBootImageFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000141 t.Helper()
142
Paul Duffin34d433a2021-03-09 14:13:25 +0000143 bootImage := result.ModuleForTests(moduleName, "android_common").Module().(*java.BootImageModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000144
Paul Duffin34d433a2021-03-09 14:13:25 +0000145 bootImageInfo := result.ModuleProvider(bootImage, java.BootImageInfoProvider).(java.BootImageInfo)
Paul Duffin3451e162021-01-20 15:16:56 +0000146 modules := bootImageInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000147 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000148
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 Duffin3451e162021-01-20 15:16:56 +0000159
Paul Duffin34d433a2021-03-09 14:13:25 +0000160 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootImageFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000161}
Paul Duffina1d60252021-01-21 18:13:43 +0000162
163func TestBootImageInApex(t *testing.T) {
Paul Duffin52bfaa42021-03-23 23:40:12 +0000164 result := android.GroupFixturePreparers(
165 prepareForTestWithBootImage,
166 prepareForTestWithMyapex,
Paul Duffin34d433a2021-03-09 14:13:25 +0000167 // Configure some libraries in the framework boot image.
168 dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"),
169 ).RunTestWithBp(t, `
Paul Duffina1d60252021-01-21 18:13:43 +0000170 apex {
171 name: "myapex",
172 key: "myapex.key",
173 boot_images: [
174 "mybootimage",
175 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000176 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000177 }
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 Duffin396229f2021-03-18 18:30:31 +0000204
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 Duffin34d433a2021-03-09 14:13:25 +0000214 `)
Paul Duffina1d60252021-01-21 18:13:43 +0000215
Paul Duffin34d433a2021-03-09 14:13:25 +0000216 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
Paul Duffina1d60252021-01-21 18:13:43 +0000217 "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 Duffin396229f2021-03-18 18:30:31 +0000230
231 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
232 `myapex.key`,
233 `mybootimage`,
234 })
Paul Duffina1d60252021-01-21 18:13:43 +0000235}
236
237// TODO(b/177892522) - add test for host apex.