blob: 7e37e422924aeab36bed19b15ac9809d6068c6d5 [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
29func TestBootImages(t *testing.T) {
Paul Duffin34d433a2021-03-09 14:13:25 +000030 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 Duffin3451e162021-01-20 15:16:56 +000042 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 Inwoodf8dcf5e2021-02-16 11:40:16 +000061 updatable: false,
Paul Duffin3451e162021-01-20 15:16:56 +000062 }
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 Duffin5bbfef82021-01-30 12:57:26 +000085
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 Duffin3451e162021-01-20 15:16:56 +000095`,
Paul Duffin3451e162021-01-20 15:16:56 +000096 )
97
98 // Make sure that the framework-boot-image is using the correct configuration.
Paul Duffin34d433a2021-03-09 14:13:25 +000099 checkBootImage(t, result, "framework-boot-image", "platform:foo,platform:bar", `
Paul Duffina1d60252021-01-21 18:13:43 +0000100test_device/dex_bootjars/android/system/framework/arm/boot-foo.art
101test_device/dex_bootjars/android/system/framework/arm/boot-foo.oat
102test_device/dex_bootjars/android/system/framework/arm/boot-foo.vdex
103test_device/dex_bootjars/android/system/framework/arm/boot-bar.art
104test_device/dex_bootjars/android/system/framework/arm/boot-bar.oat
105test_device/dex_bootjars/android/system/framework/arm/boot-bar.vdex
106test_device/dex_bootjars/android/system/framework/arm64/boot-foo.art
107test_device/dex_bootjars/android/system/framework/arm64/boot-foo.oat
108test_device/dex_bootjars/android/system/framework/arm64/boot-foo.vdex
109test_device/dex_bootjars/android/system/framework/arm64/boot-bar.art
110test_device/dex_bootjars/android/system/framework/arm64/boot-bar.oat
111test_device/dex_bootjars/android/system/framework/arm64/boot-bar.vdex
112`)
Paul Duffin3451e162021-01-20 15:16:56 +0000113
114 // Make sure that the art-boot-image is using the correct configuration.
Paul Duffin34d433a2021-03-09 14:13:25 +0000115 checkBootImage(t, result, "art-boot-image", "com.android.art:baz,com.android.art:quuz", `
Paul Duffina1d60252021-01-21 18:13:43 +0000116test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
117test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
118test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
119test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art
120test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat
121test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex
122test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art
123test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat
124test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex
125test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art
126test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat
127test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex
128`)
Paul Duffin3451e162021-01-20 15:16:56 +0000129}
130
Paul Duffin34d433a2021-03-09 14:13:25 +0000131func checkBootImage(t *testing.T, result *android.TestResult, moduleName string, expectedConfiguredModules string, expectedBootImageFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000132 t.Helper()
133
Paul Duffin34d433a2021-03-09 14:13:25 +0000134 bootImage := result.ModuleForTests(moduleName, "android_common").Module().(*java.BootImageModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000135
Paul Duffin34d433a2021-03-09 14:13:25 +0000136 bootImageInfo := result.ModuleProvider(bootImage, java.BootImageInfoProvider).(java.BootImageInfo)
Paul Duffin3451e162021-01-20 15:16:56 +0000137 modules := bootImageInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000138 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000139
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 Duffin3451e162021-01-20 15:16:56 +0000150
Paul Duffin34d433a2021-03-09 14:13:25 +0000151 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootImageFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000152}
Paul Duffina1d60252021-01-21 18:13:43 +0000153
154func TestBootImageInApex(t *testing.T) {
Paul Duffin34d433a2021-03-09 14:13:25 +0000155 result := apexFixtureFactory.Extend(
156 // Configure some libraries in the framework boot image.
157 dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"),
158 ).RunTestWithBp(t, `
Paul Duffina1d60252021-01-21 18:13:43 +0000159 apex {
160 name: "myapex",
161 key: "myapex.key",
162 boot_images: [
163 "mybootimage",
164 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000165 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000166 }
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 Duffin34d433a2021-03-09 14:13:25 +0000193 `)
Paul Duffina1d60252021-01-21 18:13:43 +0000194
Paul Duffin34d433a2021-03-09 14:13:25 +0000195 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
Paul Duffina1d60252021-01-21 18:13:43 +0000196 "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.