blob: f6c53b270ae357c47e0d3b2dabedb8b4567ec835 [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{
Spandan Dase21a8d42024-01-23 23:56:29 +0000109 `dex2oatd`,
satayev333a1732021-05-17 21:35:26 +0100110 `myapex.key`,
111 `mysystemserverclasspathfragment`,
112 })
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000113
114 assertProfileGuided(t, ctx, "foo", "android_common_apex10000", false)
115 assertProfileGuided(t, ctx, "bar", "android_common_apex10000", true)
116 assertProfileGuided(t, ctx, "baz", "android_common_apex10000", false)
satayev333a1732021-05-17 21:35:26 +0100117}
satayevb98371c2021-06-15 16:49:50 +0100118
119func TestSystemserverclasspathFragmentNoGeneratedProto(t *testing.T) {
120 result := android.GroupFixturePreparers(
121 prepareForTestWithSystemserverclasspathFragment,
122 prepareForTestWithMyapex,
satayevabcd5972021-08-06 17:49:46 +0100123 dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"),
satayevb98371c2021-06-15 16:49:50 +0100124 ).RunTestWithBp(t, `
125 apex {
126 name: "myapex",
127 key: "myapex.key",
128 systemserverclasspath_fragments: [
129 "mysystemserverclasspathfragment",
130 ],
131 updatable: false,
132 }
133
134 apex_key {
135 name: "myapex.key",
136 public_key: "testkey.avbpubkey",
137 private_key: "testkey.pem",
138 }
139
140 java_library {
141 name: "foo",
142 srcs: ["b.java"],
143 installable: true,
144 apex_available: [
145 "myapex",
146 ],
147 }
148
149 systemserverclasspath_fragment {
150 name: "mysystemserverclasspathfragment",
151 generate_classpaths_proto: false,
152 contents: [
153 "foo",
154 ],
155 apex_available: [
156 "myapex",
157 ],
158 }
159 `)
160
Jooyung Hana0503a52023-08-23 13:12:50 +0900161 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex", []string{
satayevb98371c2021-06-15 16:49:50 +0100162 "javalib/foo.jar",
163 })
164
Jooyung Hana0503a52023-08-23 13:12:50 +0900165 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex", []string{
Spandan Dase21a8d42024-01-23 23:56:29 +0000166 `dex2oatd`,
satayevb98371c2021-06-15 16:49:50 +0100167 `myapex.key`,
168 `mysystemserverclasspathfragment`,
169 })
170}
satayevd34eb0c2021-08-06 13:20:28 +0100171
172func TestSystemServerClasspathFragmentWithContentNotInMake(t *testing.T) {
173 android.GroupFixturePreparers(
174 prepareForTestWithSystemserverclasspathFragment,
175 prepareForTestWithMyapex,
176 dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"),
177 ).
178 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
Ulya Trafimoviche5b2b492021-10-04 15:42:53 +0100179 `in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS`)).
satayevd34eb0c2021-08-06 13:20:28 +0100180 RunTestWithBp(t, `
181 apex {
182 name: "myapex",
183 key: "myapex.key",
184 systemserverclasspath_fragments: [
185 "mysystemserverclasspathfragment",
186 ],
187 updatable: false,
188 }
189
190 apex_key {
191 name: "myapex.key",
192 public_key: "testkey.avbpubkey",
193 private_key: "testkey.pem",
194 }
195
196 java_library {
197 name: "foo",
198 srcs: ["b.java"],
199 installable: true,
200 apex_available: ["myapex"],
201 }
202
203 java_library {
204 name: "bar",
205 srcs: ["b.java"],
206 installable: true,
207 apex_available: ["myapex"],
208 }
209
210 systemserverclasspath_fragment {
211 name: "mysystemserverclasspathfragment",
212 contents: [
213 "foo",
214 "bar",
215 ],
216 apex_available: [
217 "myapex",
218 ],
219 }
220 `)
221}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000222
223func TestPrebuiltSystemserverclasspathFragmentContents(t *testing.T) {
224 result := android.GroupFixturePreparers(
225 prepareForTestWithSystemserverclasspathFragment,
226 prepareForTestWithMyapex,
Jiakai Zhang81e46812023-02-08 21:56:07 +0800227 dexpreopt.FixtureSetApexSystemServerJars("myapex:foo", "myapex:bar"),
Jiakai Zhangc9864272021-09-26 03:52:19 +0000228 ).RunTestWithBp(t, `
Jiakai Zhang774dd302021-09-26 03:54:25 +0000229 prebuilt_apex {
230 name: "myapex",
231 arch: {
232 arm64: {
233 src: "myapex-arm64.apex",
234 },
235 arm: {
236 src: "myapex-arm.apex",
237 },
238 },
239 exported_systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
240 }
241
Jiakai Zhangc9864272021-09-26 03:52:19 +0000242 java_import {
243 name: "foo",
244 jars: ["foo.jar"],
245 apex_available: [
246 "myapex",
247 ],
248 }
249
Jiakai Zhang81e46812023-02-08 21:56:07 +0800250 java_import {
251 name: "bar",
252 jars: ["bar.jar"],
253 dex_preopt: {
254 profile_guided: true,
255 },
256 apex_available: [
257 "myapex",
258 ],
259 }
260
Jiakai Zhangc9864272021-09-26 03:52:19 +0000261 prebuilt_systemserverclasspath_fragment {
262 name: "mysystemserverclasspathfragment",
263 prefer: true,
264 contents: [
265 "foo",
Jiakai Zhang81e46812023-02-08 21:56:07 +0800266 "bar",
Jiakai Zhangc9864272021-09-26 03:52:19 +0000267 ],
268 apex_available: [
269 "myapex",
270 ],
271 }
272 `)
273
Jiakai Zhang81e46812023-02-08 21:56:07 +0800274 ctx := result.TestContext
275
276 java.CheckModuleDependencies(t, ctx, "myapex", "android_common_myapex", []string{
Spandan Das2069c3f2023-12-06 19:40:24 +0000277 `dex2oatd`,
Spandan Das3576e762024-01-03 18:57:03 +0000278 `prebuilt_myapex.apex.selector`,
279 `prebuilt_myapex.deapexer`,
Jiakai Zhang774dd302021-09-26 03:54:25 +0000280 `prebuilt_mysystemserverclasspathfragment`,
281 })
282
Jiakai Zhang81e46812023-02-08 21:56:07 +0800283 java.CheckModuleDependencies(t, ctx, "mysystemserverclasspathfragment", "android_common_myapex", []string{
Jiakai Zhang81e46812023-02-08 21:56:07 +0800284 `prebuilt_bar`,
Jiakai Zhangc9864272021-09-26 03:52:19 +0000285 `prebuilt_foo`,
Spandan Das3576e762024-01-03 18:57:03 +0000286 `prebuilt_myapex.deapexer`,
Jiakai Zhangc9864272021-09-26 03:52:19 +0000287 })
Jiakai Zhang81e46812023-02-08 21:56:07 +0800288
Spandan Das3576e762024-01-03 18:57:03 +0000289 ensureExactDeapexedContents(t, ctx, "prebuilt_myapex", "android_common", []string{
Jiakai Zhang81e46812023-02-08 21:56:07 +0800290 "javalib/foo.jar",
291 "javalib/bar.jar",
292 "javalib/bar.jar.prof",
293 })
294
Spandan Das2ea84dd2024-01-25 22:12:50 +0000295 assertProfileGuidedPrebuilt(t, ctx, "myapex", "foo", false)
296 assertProfileGuidedPrebuilt(t, ctx, "myapex", "bar", true)
Jiakai Zhangc9864272021-09-26 03:52:19 +0000297}
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000298
299func TestSystemserverclasspathFragmentStandaloneContents(t *testing.T) {
300 result := android.GroupFixturePreparers(
301 prepareForTestWithSystemserverclasspathFragment,
302 prepareForTestWithMyapex,
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000303 dexpreopt.FixtureSetApexStandaloneSystemServerJars("myapex:foo", "myapex:bar", "myapex:baz"),
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000304 ).RunTestWithBp(t, `
305 apex {
306 name: "myapex",
307 key: "myapex.key",
308 systemserverclasspath_fragments: [
309 "mysystemserverclasspathfragment",
310 ],
311 updatable: false,
312 }
313
314 apex_key {
315 name: "myapex.key",
316 public_key: "testkey.avbpubkey",
317 private_key: "testkey.pem",
318 }
319
320 java_library {
321 name: "foo",
322 srcs: ["b.java"],
323 installable: true,
324 apex_available: [
325 "myapex",
326 ],
327 }
328
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800329 java_library {
330 name: "bar",
331 srcs: ["c.java"],
332 dex_preopt: {
333 profile: "bar-art-profile",
334 },
335 installable: true,
336 apex_available: [
337 "myapex",
338 ],
339 }
340
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000341 java_library {
342 name: "baz",
343 srcs: ["d.java"],
344 dex_preopt: {
345 profile_guided: true, // ignored
346 },
347 installable: true,
348 apex_available: [
349 "myapex",
350 ],
351 }
352
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000353 systemserverclasspath_fragment {
354 name: "mysystemserverclasspathfragment",
355 standalone_contents: [
356 "foo",
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800357 "bar",
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000358 "baz",
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000359 ],
360 apex_available: [
361 "myapex",
362 ],
363 }
364 `)
365
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000366 ctx := result.TestContext
367
Jooyung Hana0503a52023-08-23 13:12:50 +0900368 ensureExactContents(t, ctx, "myapex", "android_common_myapex", []string{
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000369 "etc/classpaths/systemserverclasspath.pb",
370 "javalib/foo.jar",
Jiakai Zhang3317ce72023-02-08 01:19:19 +0800371 "javalib/bar.jar",
372 "javalib/bar.jar.prof",
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000373 "javalib/baz.jar",
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000374 })
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000375
376 assertProfileGuided(t, ctx, "foo", "android_common_apex10000", false)
377 assertProfileGuided(t, ctx, "bar", "android_common_apex10000", true)
378 assertProfileGuided(t, ctx, "baz", "android_common_apex10000", false)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000379}
380
381func TestPrebuiltStandaloneSystemserverclasspathFragmentContents(t *testing.T) {
382 result := android.GroupFixturePreparers(
383 prepareForTestWithSystemserverclasspathFragment,
384 prepareForTestWithMyapex,
Jiakai Zhang81e46812023-02-08 21:56:07 +0800385 dexpreopt.FixtureSetApexStandaloneSystemServerJars("myapex:foo", "myapex:bar"),
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000386 ).RunTestWithBp(t, `
387 prebuilt_apex {
388 name: "myapex",
389 arch: {
390 arm64: {
391 src: "myapex-arm64.apex",
392 },
393 arm: {
394 src: "myapex-arm.apex",
395 },
396 },
397 exported_systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
398 }
399
400 java_import {
401 name: "foo",
402 jars: ["foo.jar"],
403 apex_available: [
404 "myapex",
405 ],
406 }
407
Jiakai Zhang81e46812023-02-08 21:56:07 +0800408 java_import {
409 name: "bar",
410 jars: ["bar.jar"],
411 dex_preopt: {
412 profile_guided: true,
413 },
414 apex_available: [
415 "myapex",
416 ],
417 }
418
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000419 prebuilt_systemserverclasspath_fragment {
420 name: "mysystemserverclasspathfragment",
421 prefer: true,
422 standalone_contents: [
423 "foo",
Jiakai Zhang81e46812023-02-08 21:56:07 +0800424 "bar",
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000425 ],
426 apex_available: [
427 "myapex",
428 ],
429 }
430 `)
431
Jiakai Zhang81e46812023-02-08 21:56:07 +0800432 ctx := result.TestContext
433
434 java.CheckModuleDependencies(t, ctx, "mysystemserverclasspathfragment", "android_common_myapex", []string{
Jiakai Zhang81e46812023-02-08 21:56:07 +0800435 `prebuilt_bar`,
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000436 `prebuilt_foo`,
Spandan Das3576e762024-01-03 18:57:03 +0000437 `prebuilt_myapex.deapexer`,
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000438 })
Jiakai Zhang81e46812023-02-08 21:56:07 +0800439
Spandan Das3576e762024-01-03 18:57:03 +0000440 ensureExactDeapexedContents(t, ctx, "prebuilt_myapex", "android_common", []string{
Jiakai Zhang81e46812023-02-08 21:56:07 +0800441 "javalib/foo.jar",
442 "javalib/bar.jar",
443 "javalib/bar.jar.prof",
444 })
445
Spandan Das2ea84dd2024-01-25 22:12:50 +0000446 assertProfileGuidedPrebuilt(t, ctx, "myapex", "foo", false)
447 assertProfileGuidedPrebuilt(t, ctx, "myapex", "bar", true)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000448}
Jiakai Zhang1f4542c2023-02-15 22:43:09 +0000449
450func assertProfileGuided(t *testing.T, ctx *android.TestContext, moduleName string, variant string, expected bool) {
451 dexpreopt := ctx.ModuleForTests(moduleName, variant).Rule("dexpreopt")
452 actual := strings.Contains(dexpreopt.RuleParams.Command, "--profile-file=")
453 if expected != actual {
454 t.Fatalf("Expected profile-guided to be %v, got %v", expected, actual)
455 }
456}
Spandan Das2ea84dd2024-01-25 22:12:50 +0000457
458func assertProfileGuidedPrebuilt(t *testing.T, ctx *android.TestContext, apexName string, moduleName string, expected bool) {
459 dexpreopt := ctx.ModuleForTests(apexName, "android_common_"+apexName).Rule("dexpreopt." + moduleName)
460 actual := strings.Contains(dexpreopt.RuleParams.Command, "--profile-file=")
461 if expected != actual {
462 t.Fatalf("Expected profile-guided to be %v, got %v", expected, actual)
463 }
464}