blob: 40d05814e1277e83528379fba005d181c240400a [file] [log] [blame]
satayev333a1732021-05-17 21:35:26 +01001// 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 (
Jiakai Zhang1f4542c2023-02-15 22:43:09 +000018 "strings"
satayev333a1732021-05-17 21:35:26 +010019 "testing"
20
21 "android/soong/android"
Jiakai Zhang1f4542c2023-02-15 22:43:09 +000022 "android/soong/dexpreopt"
satayev333a1732021-05-17 21:35:26 +010023 "android/soong/java"
24)
25
26var prepareForTestWithSystemserverclasspathFragment = android.GroupFixturePreparers(
27 java.PrepareForTestWithDexpreopt,
28 PrepareForTestWithApexBuildComponents,
29)
30
31func TestSystemserverclasspathFragmentContents(t *testing.T) {
32 result := android.GroupFixturePreparers(
33 prepareForTestWithSystemserverclasspathFragment,
34 prepareForTestWithMyapex,
Jiakai Zhang1f4542c2023-02-15 22:43:09 +000035 dexpreopt.FixtureSetApexSystemServerJars("myapex:foo", "myapex:bar", "myapex:baz"),
satayev333a1732021-05-17 21:35:26 +010036 ).RunTestWithBp(t, `
37 apex {
38 name: "myapex",
39 key: "myapex.key",
40 systemserverclasspath_fragments: [
41 "mysystemserverclasspathfragment",
42 ],
43 updatable: false,
44 }
45
46 apex_key {
47 name: "myapex.key",
48 public_key: "testkey.avbpubkey",
49 private_key: "testkey.pem",
50 }
51
52 java_library {
53 name: "foo",
54 srcs: ["b.java"],
55 installable: true,
56 apex_available: [
57 "myapex",
58 ],
59 }
60
Jiakai Zhang3317ce72023-02-08 01:19:19 +080061 java_library {
62 name: "bar",
63 srcs: ["c.java"],
64 installable: true,
65 dex_preopt: {
66 profile: "bar-art-profile",
67 },
68 apex_available: [
69 "myapex",
70 ],
71 }
72
Jiakai Zhang1f4542c2023-02-15 22:43:09 +000073 java_library {
74 name: "baz",
75 srcs: ["d.java"],
76 installable: true,
77 dex_preopt: {
78 profile_guided: true, // ignored
79 },
80 apex_available: [
81 "myapex",
82 ],
83 }
84
satayev333a1732021-05-17 21:35:26 +010085 systemserverclasspath_fragment {
86 name: "mysystemserverclasspathfragment",
87 contents: [
88 "foo",
Jiakai Zhang3317ce72023-02-08 01:19:19 +080089 "bar",
Jiakai Zhang1f4542c2023-02-15 22:43:09 +000090 "baz",
satayev333a1732021-05-17 21:35:26 +010091 ],
92 apex_available: [
93 "myapex",
94 ],
95 }
96 `)
97
Jiakai Zhang1f4542c2023-02-15 22:43:09 +000098 ctx := result.TestContext
99
Jooyung Hana0503a52023-08-23 13:12:50 +0900100 ensureExactContents(t, ctx, "myapex", "android_common_myapex", []string{
satayev227e7452021-05-20 21:35:06 +0100101 "etc/classpaths/systemserverclasspath.pb",
satayev333a1732021-05-17 21:35:26 +0100102 "javalib/foo.jar",
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800103 "javalib/bar.jar",
104 "javalib/bar.jar.prof",
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000105 "javalib/baz.jar",
satayev333a1732021-05-17 21:35:26 +0100106 })
107
Jooyung Hana0503a52023-08-23 13:12:50 +0900108 java.CheckModuleDependencies(t, ctx, "myapex", "android_common_myapex", []string{
satayev333a1732021-05-17 21:35:26 +0100109 `myapex.key`,
110 `mysystemserverclasspathfragment`,
111 })
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000112
113 assertProfileGuided(t, ctx, "foo", "android_common_apex10000", false)
114 assertProfileGuided(t, ctx, "bar", "android_common_apex10000", true)
115 assertProfileGuided(t, ctx, "baz", "android_common_apex10000", false)
satayev333a1732021-05-17 21:35:26 +0100116}
satayevb98371c2021-06-15 16:49:50 +0100117
118func TestSystemserverclasspathFragmentNoGeneratedProto(t *testing.T) {
119 result := android.GroupFixturePreparers(
120 prepareForTestWithSystemserverclasspathFragment,
121 prepareForTestWithMyapex,
satayevabcd5972021-08-06 17:49:46 +0100122 dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"),
satayevb98371c2021-06-15 16:49:50 +0100123 ).RunTestWithBp(t, `
124 apex {
125 name: "myapex",
126 key: "myapex.key",
127 systemserverclasspath_fragments: [
128 "mysystemserverclasspathfragment",
129 ],
130 updatable: false,
131 }
132
133 apex_key {
134 name: "myapex.key",
135 public_key: "testkey.avbpubkey",
136 private_key: "testkey.pem",
137 }
138
139 java_library {
140 name: "foo",
141 srcs: ["b.java"],
142 installable: true,
143 apex_available: [
144 "myapex",
145 ],
146 }
147
148 systemserverclasspath_fragment {
149 name: "mysystemserverclasspathfragment",
150 generate_classpaths_proto: false,
151 contents: [
152 "foo",
153 ],
154 apex_available: [
155 "myapex",
156 ],
157 }
158 `)
159
Jooyung Hana0503a52023-08-23 13:12:50 +0900160 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex", []string{
satayevb98371c2021-06-15 16:49:50 +0100161 "javalib/foo.jar",
162 })
163
Jooyung Hana0503a52023-08-23 13:12:50 +0900164 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex", []string{
satayevb98371c2021-06-15 16:49:50 +0100165 `myapex.key`,
166 `mysystemserverclasspathfragment`,
167 })
168}
satayevd34eb0c2021-08-06 13:20:28 +0100169
170func TestSystemServerClasspathFragmentWithContentNotInMake(t *testing.T) {
171 android.GroupFixturePreparers(
172 prepareForTestWithSystemserverclasspathFragment,
173 prepareForTestWithMyapex,
174 dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"),
175 ).
176 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
Ulya Trafimoviche5b2b492021-10-04 15:42:53 +0100177 `in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS`)).
satayevd34eb0c2021-08-06 13:20:28 +0100178 RunTestWithBp(t, `
179 apex {
180 name: "myapex",
181 key: "myapex.key",
182 systemserverclasspath_fragments: [
183 "mysystemserverclasspathfragment",
184 ],
185 updatable: false,
186 }
187
188 apex_key {
189 name: "myapex.key",
190 public_key: "testkey.avbpubkey",
191 private_key: "testkey.pem",
192 }
193
194 java_library {
195 name: "foo",
196 srcs: ["b.java"],
197 installable: true,
198 apex_available: ["myapex"],
199 }
200
201 java_library {
202 name: "bar",
203 srcs: ["b.java"],
204 installable: true,
205 apex_available: ["myapex"],
206 }
207
208 systemserverclasspath_fragment {
209 name: "mysystemserverclasspathfragment",
210 contents: [
211 "foo",
212 "bar",
213 ],
214 apex_available: [
215 "myapex",
216 ],
217 }
218 `)
219}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000220
221func TestPrebuiltSystemserverclasspathFragmentContents(t *testing.T) {
222 result := android.GroupFixturePreparers(
223 prepareForTestWithSystemserverclasspathFragment,
224 prepareForTestWithMyapex,
Jiakai Zhang81e46812023-02-08 21:56:07 +0800225 dexpreopt.FixtureSetApexSystemServerJars("myapex:foo", "myapex:bar"),
Jiakai Zhangc9864272021-09-26 03:52:19 +0000226 ).RunTestWithBp(t, `
Jiakai Zhang774dd302021-09-26 03:54:25 +0000227 prebuilt_apex {
228 name: "myapex",
229 arch: {
230 arm64: {
231 src: "myapex-arm64.apex",
232 },
233 arm: {
234 src: "myapex-arm.apex",
235 },
236 },
237 exported_systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
238 }
239
Jiakai Zhangc9864272021-09-26 03:52:19 +0000240 java_import {
241 name: "foo",
242 jars: ["foo.jar"],
243 apex_available: [
244 "myapex",
245 ],
246 }
247
Jiakai Zhang81e46812023-02-08 21:56:07 +0800248 java_import {
249 name: "bar",
250 jars: ["bar.jar"],
251 dex_preopt: {
252 profile_guided: true,
253 },
254 apex_available: [
255 "myapex",
256 ],
257 }
258
Jiakai Zhangc9864272021-09-26 03:52:19 +0000259 prebuilt_systemserverclasspath_fragment {
260 name: "mysystemserverclasspathfragment",
261 prefer: true,
262 contents: [
263 "foo",
Jiakai Zhang81e46812023-02-08 21:56:07 +0800264 "bar",
Jiakai Zhangc9864272021-09-26 03:52:19 +0000265 ],
266 apex_available: [
267 "myapex",
268 ],
269 }
270 `)
271
Jiakai Zhang81e46812023-02-08 21:56:07 +0800272 ctx := result.TestContext
273
274 java.CheckModuleDependencies(t, ctx, "myapex", "android_common_myapex", []string{
Jiakai Zhang774dd302021-09-26 03:54:25 +0000275 `myapex.apex.selector`,
276 `prebuilt_mysystemserverclasspathfragment`,
277 })
278
Jiakai Zhang81e46812023-02-08 21:56:07 +0800279 java.CheckModuleDependencies(t, ctx, "mysystemserverclasspathfragment", "android_common_myapex", []string{
Jiakai Zhang774dd302021-09-26 03:54:25 +0000280 `myapex.deapexer`,
Jiakai Zhang81e46812023-02-08 21:56:07 +0800281 `prebuilt_bar`,
Jiakai Zhangc9864272021-09-26 03:52:19 +0000282 `prebuilt_foo`,
283 })
Jiakai Zhang81e46812023-02-08 21:56:07 +0800284
285 ensureExactDeapexedContents(t, ctx, "myapex", "android_common", []string{
286 "javalib/foo.jar",
287 "javalib/bar.jar",
288 "javalib/bar.jar.prof",
289 })
290
291 assertProfileGuided(t, ctx, "foo", "android_common_myapex", false)
292 assertProfileGuided(t, ctx, "bar", "android_common_myapex", true)
Jiakai Zhangc9864272021-09-26 03:52:19 +0000293}
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000294
295func TestSystemserverclasspathFragmentStandaloneContents(t *testing.T) {
296 result := android.GroupFixturePreparers(
297 prepareForTestWithSystemserverclasspathFragment,
298 prepareForTestWithMyapex,
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000299 dexpreopt.FixtureSetApexStandaloneSystemServerJars("myapex:foo", "myapex:bar", "myapex:baz"),
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000300 ).RunTestWithBp(t, `
301 apex {
302 name: "myapex",
303 key: "myapex.key",
304 systemserverclasspath_fragments: [
305 "mysystemserverclasspathfragment",
306 ],
307 updatable: false,
308 }
309
310 apex_key {
311 name: "myapex.key",
312 public_key: "testkey.avbpubkey",
313 private_key: "testkey.pem",
314 }
315
316 java_library {
317 name: "foo",
318 srcs: ["b.java"],
319 installable: true,
320 apex_available: [
321 "myapex",
322 ],
323 }
324
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800325 java_library {
326 name: "bar",
327 srcs: ["c.java"],
328 dex_preopt: {
329 profile: "bar-art-profile",
330 },
331 installable: true,
332 apex_available: [
333 "myapex",
334 ],
335 }
336
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000337 java_library {
338 name: "baz",
339 srcs: ["d.java"],
340 dex_preopt: {
341 profile_guided: true, // ignored
342 },
343 installable: true,
344 apex_available: [
345 "myapex",
346 ],
347 }
348
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000349 systemserverclasspath_fragment {
350 name: "mysystemserverclasspathfragment",
351 standalone_contents: [
352 "foo",
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800353 "bar",
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000354 "baz",
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000355 ],
356 apex_available: [
357 "myapex",
358 ],
359 }
360 `)
361
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000362 ctx := result.TestContext
363
Jooyung Hana0503a52023-08-23 13:12:50 +0900364 ensureExactContents(t, ctx, "myapex", "android_common_myapex", []string{
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000365 "etc/classpaths/systemserverclasspath.pb",
366 "javalib/foo.jar",
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800367 "javalib/bar.jar",
368 "javalib/bar.jar.prof",
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000369 "javalib/baz.jar",
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000370 })
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000371
372 assertProfileGuided(t, ctx, "foo", "android_common_apex10000", false)
373 assertProfileGuided(t, ctx, "bar", "android_common_apex10000", true)
374 assertProfileGuided(t, ctx, "baz", "android_common_apex10000", false)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000375}
376
377func TestPrebuiltStandaloneSystemserverclasspathFragmentContents(t *testing.T) {
378 result := android.GroupFixturePreparers(
379 prepareForTestWithSystemserverclasspathFragment,
380 prepareForTestWithMyapex,
Jiakai Zhang81e46812023-02-08 21:56:07 +0800381 dexpreopt.FixtureSetApexStandaloneSystemServerJars("myapex:foo", "myapex:bar"),
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000382 ).RunTestWithBp(t, `
383 prebuilt_apex {
384 name: "myapex",
385 arch: {
386 arm64: {
387 src: "myapex-arm64.apex",
388 },
389 arm: {
390 src: "myapex-arm.apex",
391 },
392 },
393 exported_systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
394 }
395
396 java_import {
397 name: "foo",
398 jars: ["foo.jar"],
399 apex_available: [
400 "myapex",
401 ],
402 }
403
Jiakai Zhang81e46812023-02-08 21:56:07 +0800404 java_import {
405 name: "bar",
406 jars: ["bar.jar"],
407 dex_preopt: {
408 profile_guided: true,
409 },
410 apex_available: [
411 "myapex",
412 ],
413 }
414
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000415 prebuilt_systemserverclasspath_fragment {
416 name: "mysystemserverclasspathfragment",
417 prefer: true,
418 standalone_contents: [
419 "foo",
Jiakai Zhang81e46812023-02-08 21:56:07 +0800420 "bar",
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000421 ],
422 apex_available: [
423 "myapex",
424 ],
425 }
426 `)
427
Jiakai Zhang81e46812023-02-08 21:56:07 +0800428 ctx := result.TestContext
429
430 java.CheckModuleDependencies(t, ctx, "mysystemserverclasspathfragment", "android_common_myapex", []string{
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000431 `myapex.deapexer`,
Jiakai Zhang81e46812023-02-08 21:56:07 +0800432 `prebuilt_bar`,
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000433 `prebuilt_foo`,
434 })
Jiakai Zhang81e46812023-02-08 21:56:07 +0800435
436 ensureExactDeapexedContents(t, ctx, "myapex", "android_common", []string{
437 "javalib/foo.jar",
438 "javalib/bar.jar",
439 "javalib/bar.jar.prof",
440 })
441
442 assertProfileGuided(t, ctx, "foo", "android_common_myapex", false)
443 assertProfileGuided(t, ctx, "bar", "android_common_myapex", true)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000444}
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000445
446func assertProfileGuided(t *testing.T, ctx *android.TestContext, moduleName string, variant string, expected bool) {
447 dexpreopt := ctx.ModuleForTests(moduleName, variant).Rule("dexpreopt")
448 actual := strings.Contains(dexpreopt.RuleParams.Command, "--profile-file=")
449 if expected != actual {
450 t.Fatalf("Expected profile-guided to be %v, got %v", expected, actual)
451 }
452}