blob: 205a216a07a210d9e3d8dadabb673d4485abe933 [file] [log] [blame]
Jooyung Han9706cbc2021-04-15 22:43:48 +09001// Copyright 2021 Google Inc. All rights reserved.
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 filesystem
16
17import (
18 "os"
19 "testing"
20
21 "android/soong/android"
Jiyong Park06c4cdc2024-02-16 15:35:03 +090022 "android/soong/bpf"
Jiyong Parkfa616132021-04-20 11:36:40 +090023 "android/soong/cc"
Jooyung Hane6067592023-03-16 13:11:17 +090024 "android/soong/etc"
Jiyong Park73e5bab2024-04-05 13:37:21 +090025 "android/soong/java"
Jiyong Park9c540c82024-03-26 10:48:27 +090026 "android/soong/phony"
Jooyung Hane6067592023-03-16 13:11:17 +090027
28 "github.com/google/blueprint/proptools"
Jooyung Han9706cbc2021-04-15 22:43:48 +090029)
30
31func TestMain(m *testing.M) {
32 os.Exit(m.Run())
33}
34
35var fixture = android.GroupFixturePreparers(
36 android.PrepareForIntegrationTestWithAndroid,
Jiyong Park73e5bab2024-04-05 13:37:21 +090037 android.PrepareForTestWithAndroidBuildComponents,
Jiyong Park06c4cdc2024-02-16 15:35:03 +090038 bpf.PrepareForTestWithBpf,
Jiyong Parkfa616132021-04-20 11:36:40 +090039 cc.PrepareForIntegrationTestWithCc,
Jiyong Park73e5bab2024-04-05 13:37:21 +090040 etc.PrepareForTestWithPrebuiltEtc,
41 java.PrepareForTestWithJavaBuildComponents,
42 java.PrepareForTestWithJavaDefaultModules,
Jiyong Park9c540c82024-03-26 10:48:27 +090043 phony.PrepareForTestWithPhony,
Jooyung Han9706cbc2021-04-15 22:43:48 +090044 PrepareForTestWithFilesystemBuildComponents,
45)
46
47func TestFileSystemDeps(t *testing.T) {
48 result := fixture.RunTestWithBp(t, `
49 android_filesystem {
50 name: "myfilesystem",
Jiyong Park06c4cdc2024-02-16 15:35:03 +090051 multilib: {
52 common: {
53 deps: [
54 "bpf.o",
Jiyong Park9c540c82024-03-26 10:48:27 +090055 "phony",
Jiyong Park06c4cdc2024-02-16 15:35:03 +090056 ],
57 },
Jiyong Parkeec7c382024-02-16 16:10:13 +090058 lib32: {
59 deps: [
60 "foo",
61 "libbar",
62 ],
63 },
64 lib64: {
65 deps: [
66 "libbar",
67 ],
68 },
Jiyong Park06c4cdc2024-02-16 15:35:03 +090069 },
Jiyong Parkeec7c382024-02-16 16:10:13 +090070 compile_multilib: "both",
Jiyong Park06c4cdc2024-02-16 15:35:03 +090071 }
72
73 bpf {
74 name: "bpf.o",
75 srcs: ["bpf.c"],
Jooyung Han9706cbc2021-04-15 22:43:48 +090076 }
Jiyong Parkeec7c382024-02-16 16:10:13 +090077
78 cc_binary {
79 name: "foo",
80 compile_multilib: "prefer32",
81 }
82
83 cc_library {
84 name: "libbar",
Jiyong Park8bcf3c62024-03-18 18:37:10 +090085 required: ["libbaz"],
Jiyong Parkf21dd652024-04-17 05:22:37 +000086 target: {
87 platform: {
88 required: ["lib_platform_only"],
89 },
90 },
Jiyong Park8bcf3c62024-03-18 18:37:10 +090091 }
92
93 cc_library {
94 name: "libbaz",
Jiyong Parkeec7c382024-02-16 16:10:13 +090095 }
Jiyong Park9c540c82024-03-26 10:48:27 +090096
Jiyong Parkf21dd652024-04-17 05:22:37 +000097 cc_library {
98 name: "lib_platform_only",
99 }
100
Jiyong Park9c540c82024-03-26 10:48:27 +0900101 phony {
102 name: "phony",
Jiyong Park73e5bab2024-04-05 13:37:21 +0900103 required: [
104 "libquz",
105 "myapp",
106 ],
Jiyong Park9c540c82024-03-26 10:48:27 +0900107 }
108
109 cc_library {
110 name: "libquz",
111 }
Jiyong Park73e5bab2024-04-05 13:37:21 +0900112
113 android_app {
114 name: "myapp",
115 platform_apis: true,
116 installable: true,
117 }
Jooyung Han9706cbc2021-04-15 22:43:48 +0900118 `)
119
120 // produces "myfilesystem.img"
121 result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img")
Jiyong Park06c4cdc2024-02-16 15:35:03 +0900122
123 fs := result.ModuleForTests("myfilesystem", "android_common").Module().(*filesystem)
Jiyong Parkeec7c382024-02-16 16:10:13 +0900124 expected := []string{
Jiyong Park73e5bab2024-04-05 13:37:21 +0900125 "app/myapp/myapp.apk",
Jiyong Parkeec7c382024-02-16 16:10:13 +0900126 "bin/foo",
127 "lib/libbar.so",
128 "lib64/libbar.so",
Jiyong Park8bcf3c62024-03-18 18:37:10 +0900129 "lib64/libbaz.so",
Jiyong Park9c540c82024-03-26 10:48:27 +0900130 "lib64/libquz.so",
Jiyong Parkf21dd652024-04-17 05:22:37 +0000131 "lib64/lib_platform_only.so",
Jiyong Parkeec7c382024-02-16 16:10:13 +0900132 "etc/bpf/bpf.o",
133 }
Jiyong Park06c4cdc2024-02-16 15:35:03 +0900134 for _, e := range expected {
135 android.AssertStringListContains(t, "missing entry", fs.entries, e)
136 }
Jooyung Han9706cbc2021-04-15 22:43:48 +0900137}
Jiyong Parkfa616132021-04-20 11:36:40 +0900138
Cole Faust4a2a7c92024-03-12 12:44:40 -0700139func TestIncludeMakeBuiltFiles(t *testing.T) {
140 result := fixture.RunTestWithBp(t, `
141 android_filesystem {
142 name: "myfilesystem",
143 include_make_built_files: "system",
144 }
145 `)
146
147 output := result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img")
148
Colin Cross3b1c6842024-07-26 11:52:57 -0700149 stampFile := "out/target/product/test_device/obj/PACKAGING/system_intermediates/staging_dir.stamp"
150 fileListFile := "out/target/product/test_device/obj/PACKAGING/system_intermediates/file_list.txt"
Cole Faust4a2a7c92024-03-12 12:44:40 -0700151 android.AssertStringListContains(t, "deps of filesystem must include the staging dir stamp file", output.Implicits.Strings(), stampFile)
152 android.AssertStringListContains(t, "deps of filesystem must include the staging dir file list", output.Implicits.Strings(), fileListFile)
153}
154
Jiyong Parkfa616132021-04-20 11:36:40 +0900155func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) {
156 result := fixture.RunTestWithBp(t, `
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900157 android_system_image {
Jiyong Parkfa616132021-04-20 11:36:40 +0900158 name: "myfilesystem",
Kiyoung Kim67118212024-11-07 13:23:44 +0900159 base_dir: "system",
Jiyong Parkfa616132021-04-20 11:36:40 +0900160 deps: [
161 "libfoo",
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900162 "libbar",
Jiyong Parkfa616132021-04-20 11:36:40 +0900163 ],
Kiyoung Kim67118212024-11-07 13:23:44 +0900164 linkerconfig: {
165 gen_linker_config: true,
166 linker_config_srcs: ["linker.config.json"],
167 },
Jiyong Parkfa616132021-04-20 11:36:40 +0900168 }
169
170 cc_library {
171 name: "libfoo",
172 stubs: {
173 symbol_file: "libfoo.map.txt",
174 },
175 }
176
177 cc_library {
178 name: "libbar",
179 }
180 `)
181
182 module := result.ModuleForTests("myfilesystem", "android_common")
Kiyoung Kim67118212024-11-07 13:23:44 +0900183 output := module.Output("out/soong/.intermediates/myfilesystem/android_common/root/system/etc/linker.config.pb")
Jiyong Parkfa616132021-04-20 11:36:40 +0900184
185 android.AssertStringDoesContain(t, "linker.config.pb should have libfoo",
186 output.RuleParams.Command, "libfoo.so")
187 android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar",
188 output.RuleParams.Command, "libbar.so")
189}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900190
191func registerComponent(ctx android.RegistrationContext) {
192 ctx.RegisterModuleType("component", componentFactory)
193}
194
195func componentFactory() android.Module {
196 m := &component{}
197 m.AddProperties(&m.properties)
198 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
199 return m
200}
201
202type component struct {
203 android.ModuleBase
204 properties struct {
205 Install_copy_in_data []string
206 }
207}
208
209func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) {
210 output := android.PathForModuleOut(ctx, c.Name())
211 dir := android.PathForModuleInstall(ctx, "components")
212 ctx.InstallFile(dir, c.Name(), output)
213
214 dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components")
215 for _, d := range c.properties.Install_copy_in_data {
216 ctx.InstallFile(dataDir, d, output)
217 }
218}
219
220func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) {
221 f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent))
222 result := f.RunTestWithBp(t, `
223 android_system_image {
224 name: "myfilesystem",
225 multilib: {
226 common: {
227 deps: ["foo"],
228 },
229 },
Kiyoung Kim67118212024-11-07 13:23:44 +0900230 linkerconfig: {
231 gen_linker_config: true,
232 linker_config_srcs: ["linker.config.json"],
233 },
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900234 }
235 component {
236 name: "foo",
237 install_copy_in_data: ["bar"],
238 }
239 `)
240
241 module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage)
242 android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries)
243}
Jiyong Parkbc485482022-11-15 22:31:49 +0900244
Alice Wang000e3a32023-01-03 16:11:20 +0000245func TestAvbGenVbmetaImage(t *testing.T) {
246 result := fixture.RunTestWithBp(t, `
247 avb_gen_vbmeta_image {
248 name: "input_hashdesc",
249 src: "input.img",
250 partition_name: "input_partition_name",
251 salt: "2222",
252 }`)
253 cmd := result.ModuleForTests("input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command
254 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
255 cmd, "--partition_name input_partition_name")
256 android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image",
257 cmd, "--do_not_append_vbmeta_image")
258 android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image",
259 cmd, "--output_vbmeta_image ")
260 android.AssertStringDoesContain(t, "Can't find --salt argument",
261 cmd, "--salt 2222")
262}
263
Jiyong Parkbc485482022-11-15 22:31:49 +0900264func TestAvbAddHashFooter(t *testing.T) {
265 result := fixture.RunTestWithBp(t, `
Alice Wang000e3a32023-01-03 16:11:20 +0000266 avb_gen_vbmeta_image {
267 name: "input_hashdesc",
268 src: "input.img",
269 partition_name: "input",
270 salt: "2222",
271 }
272
Jiyong Parkbc485482022-11-15 22:31:49 +0900273 avb_add_hash_footer {
274 name: "myfooter",
275 src: "input.img",
276 filename: "output.img",
277 partition_name: "mypartition",
278 private_key: "mykey",
279 salt: "1111",
280 props: [
281 {
282 name: "prop1",
283 value: "value1",
284 },
285 {
286 name: "prop2",
287 file: "value_file",
288 },
289 ],
Alice Wang000e3a32023-01-03 16:11:20 +0000290 include_descriptors_from_images: ["input_hashdesc"],
Jiyong Parkbc485482022-11-15 22:31:49 +0900291 }
292 `)
293 cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command
294 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
295 cmd, "--partition_name mypartition")
296 android.AssertStringDoesContain(t, "Can't find correct --key argument",
297 cmd, "--key mykey")
298 android.AssertStringDoesContain(t, "Can't find --salt argument",
299 cmd, "--salt 1111")
300 android.AssertStringDoesContain(t, "Can't find --prop argument",
301 cmd, "--prop 'prop1:value1'")
302 android.AssertStringDoesContain(t, "Can't find --prop_from_file argument",
303 cmd, "--prop_from_file 'prop2:value_file'")
Alice Wang000e3a32023-01-03 16:11:20 +0000304 android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image",
305 cmd, "--include_descriptors_from_image ")
Jiyong Parkbc485482022-11-15 22:31:49 +0900306}
Jooyung Han54f78052023-02-20 18:17:47 +0900307
Jooyung Hane6067592023-03-16 13:11:17 +0900308func TestFileSystemWithCoverageVariants(t *testing.T) {
309 context := android.GroupFixturePreparers(
310 fixture,
311 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
312 variables.GcovCoverage = proptools.BoolPtr(true)
313 variables.Native_coverage = proptools.BoolPtr(true)
314 }),
315 )
316
317 result := context.RunTestWithBp(t, `
318 prebuilt_etc {
319 name: "prebuilt",
320 src: ":myfilesystem",
321 }
322
323 android_system_image {
324 name: "myfilesystem",
325 deps: [
326 "libfoo",
327 ],
Kiyoung Kim67118212024-11-07 13:23:44 +0900328 linkerconfig: {
329 gen_linker_config: true,
330 linker_config_srcs: ["linker.config.json"],
331 },
Jooyung Hane6067592023-03-16 13:11:17 +0900332 }
333
334 cc_library {
335 name: "libfoo",
336 shared_libs: [
337 "libbar",
338 ],
339 stl: "none",
340 }
341
342 cc_library {
343 name: "libbar",
344 stl: "none",
345 }
346 `)
347
348 filesystem := result.ModuleForTests("myfilesystem", "android_common_cov")
Cole Faust3b806d32024-03-11 15:15:03 -0700349 inputs := filesystem.Output("myfilesystem.img").Implicits
Jooyung Hane6067592023-03-16 13:11:17 +0900350 android.AssertStringListContains(t, "filesystem should have libfoo(cov)",
351 inputs.Strings(),
352 "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so")
353 android.AssertStringListContains(t, "filesystem should have libbar(cov)",
354 inputs.Strings(),
355 "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared_cov/libbar.so")
356
357 filesystemOutput := filesystem.Output("myfilesystem.img").Output
358 prebuiltInput := result.ModuleForTests("prebuilt", "android_arm64_armv8-a").Rule("Cp").Input
359 if filesystemOutput != prebuiltInput {
360 t.Error("prebuilt should use cov variant of filesystem")
361 }
362}
Jiyong Parkeaac8232024-03-31 21:27:45 +0900363
364func TestSystemImageDefaults(t *testing.T) {
365 result := fixture.RunTestWithBp(t, `
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900366 android_filesystem_defaults {
Jiyong Parkeaac8232024-03-31 21:27:45 +0900367 name: "defaults",
368 multilib: {
369 common: {
370 deps: [
371 "phony",
372 ],
373 },
374 lib64: {
375 deps: [
376 "libbar",
377 ],
378 },
379 },
380 compile_multilib: "both",
381 }
382
383 android_system_image {
384 name: "system",
385 defaults: ["defaults"],
386 multilib: {
387 lib32: {
388 deps: [
389 "foo",
390 "libbar",
391 ],
392 },
393 },
394 }
395
396 cc_binary {
397 name: "foo",
398 compile_multilib: "prefer32",
399 }
400
401 cc_library {
402 name: "libbar",
403 required: ["libbaz"],
404 }
405
406 cc_library {
407 name: "libbaz",
408 }
409
410 phony {
411 name: "phony",
412 required: ["libquz"],
413 }
414
415 cc_library {
416 name: "libquz",
417 }
418 `)
419
420 fs := result.ModuleForTests("system", "android_common").Module().(*systemImage)
421 expected := []string{
422 "bin/foo",
423 "lib/libbar.so",
424 "lib64/libbar.so",
425 "lib64/libbaz.so",
426 "lib64/libquz.so",
427 }
428 for _, e := range expected {
429 android.AssertStringListContains(t, "missing entry", fs.entries, e)
430 }
431}
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900432
433func TestInconsistentPartitionTypesInDefaults(t *testing.T) {
434 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
435 "doesn't match with the partition type")).
436 RunTestWithBp(t, `
437 android_filesystem_defaults {
438 name: "system_ext_def",
439 partition_type: "system_ext",
440 }
441
442 android_filesystem_defaults {
443 name: "system_def",
444 partition_type: "system",
445 defaults: ["system_ext_def"],
446 }
447
448 android_system_image {
449 name: "system",
450 defaults: ["system_def"],
451 }
452 `)
453}
Jiyong Park16ef7ac2024-05-01 12:36:10 +0000454
455func TestPreventDuplicatedEntries(t *testing.T) {
456 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
457 "packaging conflict at")).
458 RunTestWithBp(t, `
459 android_filesystem {
460 name: "fs",
461 deps: [
462 "foo",
463 "foo_dup",
464 ],
465 }
466
467 cc_binary {
468 name: "foo",
469 }
470
471 cc_binary {
472 name: "foo_dup",
473 stem: "foo",
474 }
475 `)
476}
Jiyong Parkc4b1d552024-05-13 16:47:30 +0900477
478func TestTrackPhonyAsRequiredDep(t *testing.T) {
479 result := fixture.RunTestWithBp(t, `
480 android_filesystem {
481 name: "fs",
482 deps: ["foo"],
483 }
484
485 cc_binary {
486 name: "foo",
487 required: ["phony"],
488 }
489
490 phony {
491 name: "phony",
492 required: ["libbar"],
493 }
494
495 cc_library {
496 name: "libbar",
497 }
498 `)
499
500 fs := result.ModuleForTests("fs", "android_common").Module().(*filesystem)
501 expected := []string{
502 "bin/foo",
503 "lib64/libbar.so",
504 }
505 for _, e := range expected {
506 android.AssertStringListContains(t, "missing entry", fs.entries, e)
507 }
508}
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900509
510func TestFilterOutUnsupportedArches(t *testing.T) {
511 result := fixture.RunTestWithBp(t, `
512 android_filesystem {
513 name: "fs_64_only",
514 deps: ["foo"],
515 }
516
517 android_filesystem {
518 name: "fs_64_32",
519 compile_multilib: "both",
Jiyong Park3ea9b652024-05-15 23:01:54 +0900520 deps: ["foo"],
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900521 }
522
523 cc_binary {
524 name: "foo",
525 required: ["phony"],
526 }
527
528 phony {
529 name: "phony",
530 required: [
531 "libbar",
532 "app",
533 ],
534 }
535
536 cc_library {
537 name: "libbar",
538 }
539
540 android_app {
541 name: "app",
542 srcs: ["a.java"],
543 platform_apis: true,
544 }
545 `)
546 testcases := []struct {
547 fsName string
548 expected []string
549 unexpected []string
550 }{
551 {
552 fsName: "fs_64_only",
553 expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so"},
554 unexpected: []string{"lib/libbar.so"},
555 },
556 {
557 fsName: "fs_64_32",
558 expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so", "lib/libbar.so"},
559 unexpected: []string{},
560 },
561 }
562 for _, c := range testcases {
563 fs := result.ModuleForTests(c.fsName, "android_common").Module().(*filesystem)
564 for _, e := range c.expected {
565 android.AssertStringListContains(t, "missing entry", fs.entries, e)
566 }
567 for _, e := range c.unexpected {
568 android.AssertStringListDoesNotContain(t, "unexpected entry", fs.entries, e)
569 }
570 }
571}
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000572
573func TestErofsPartition(t *testing.T) {
574 result := fixture.RunTestWithBp(t, `
575 android_filesystem {
576 name: "erofs_partition",
577 type: "erofs",
578 erofs: {
579 compressor: "lz4hc,9",
580 compress_hints: "compress_hints.txt",
581 },
582 deps: ["binfoo"],
583 }
584
585 cc_binary {
586 name: "binfoo",
587 }
588 `)
589
590 partition := result.ModuleForTests("erofs_partition", "android_common")
591 buildImageConfig := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("prop"))
592 android.AssertStringDoesContain(t, "erofs fs type", buildImageConfig, "fs_type=erofs")
593 android.AssertStringDoesContain(t, "erofs fs type compress algorithm", buildImageConfig, "erofs_default_compressor=lz4hc,9")
594 android.AssertStringDoesContain(t, "erofs fs type compress hint", buildImageConfig, "erofs_default_compress_hints=compress_hints.txt")
595 android.AssertStringDoesContain(t, "erofs fs type sparse", buildImageConfig, "erofs_sparse_flag=-s")
596}
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000597
598// If a system_ext/ module depends on system/ module, the dependency should *not*
599// be installed in system_ext/
600func TestDoNotPackageCrossPartitionDependencies(t *testing.T) {
Spandan Das6d056502024-10-21 15:40:32 +0000601 t.Skip() // TODO (spandandas): Re-enable this
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000602 result := fixture.RunTestWithBp(t, `
603 android_filesystem {
604 name: "myfilesystem",
605 deps: ["binfoo"],
606 partition_type: "system_ext",
607 }
608
609 cc_binary {
610 name: "binfoo",
611 shared_libs: ["libfoo"],
612 system_ext_specific: true,
613 }
614 cc_library_shared {
615 name: "libfoo", // installed in system/
616 }
617 `)
618
619 partition := result.ModuleForTests("myfilesystem", "android_common")
620 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
621 android.AssertDeepEquals(t, "filesystem with dependencies on different partition", "bin/binfoo\n", fileList)
622}
Spandan Das405f2d42024-10-22 18:31:25 +0000623
624// If a cc_library is listed in `deps`, and it has a shared and static variant, then the shared variant
625// should be installed.
626func TestUseSharedVariationOfNativeLib(t *testing.T) {
627 result := fixture.RunTestWithBp(t, `
628 android_filesystem {
629 name: "myfilesystem",
630 deps: ["libfoo"],
631 }
632 // cc_library will create a static and shared variant.
633 cc_library {
634 name: "libfoo",
635 }
636 `)
637
638 partition := result.ModuleForTests("myfilesystem", "android_common")
639 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
640 android.AssertDeepEquals(t, "cc_library listed in deps", "lib64/libc++.so\nlib64/libc.so\nlib64/libdl.so\nlib64/libfoo.so\nlib64/libm.so\n", fileList)
641}
Spandan Das6c2b01d2024-10-22 22:16:04 +0000642
643// binfoo1 overrides binbar. transitive deps of binbar should not be installed.
644func TestDoNotInstallTransitiveDepOfOverriddenModule(t *testing.T) {
645 result := fixture.RunTestWithBp(t, `
646android_filesystem {
647 name: "myfilesystem",
648 deps: ["binfoo1", "libfoo2", "binbar"],
649}
650cc_binary {
651 name: "binfoo1",
652 shared_libs: ["libfoo"],
653 overrides: ["binbar"],
654}
655cc_library {
656 name: "libfoo",
657}
658cc_library {
659 name: "libfoo2",
660 overrides: ["libfoo"],
661}
662// binbar gets overridden by binfoo1
663// therefore, libbar should not be installed
664cc_binary {
665 name: "binbar",
666 shared_libs: ["libbar"]
667}
668cc_library {
669 name: "libbar",
670}
671 `)
672
673 partition := result.ModuleForTests("myfilesystem", "android_common")
674 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
675 android.AssertDeepEquals(t, "Shared library dep of overridden binary should not be installed", fileList, "bin/binfoo1\nlib64/libc++.so\nlib64/libc.so\nlib64/libdl.so\nlib64/libfoo2.so\nlib64/libm.so\n")
676}
Spandan Das92631882024-10-28 22:49:38 +0000677
678func TestInstallLinkerConfigFile(t *testing.T) {
679 result := fixture.RunTestWithBp(t, `
680android_filesystem {
681 name: "myfilesystem",
682 deps: ["libfoo_has_no_stubs", "libfoo_has_stubs"],
Spandan Das173256b2024-10-31 19:59:30 +0000683 linkerconfig: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900684 gen_linker_config: true,
685 linker_config_srcs: ["linker.config.json"],
Spandan Das173256b2024-10-31 19:59:30 +0000686 },
Spandan Das918191e2024-10-31 18:27:23 +0000687 partition_type: "vendor",
Spandan Das92631882024-10-28 22:49:38 +0000688}
689cc_library {
690 name: "libfoo_has_no_stubs",
Spandan Das918191e2024-10-31 18:27:23 +0000691 vendor: true,
Spandan Das92631882024-10-28 22:49:38 +0000692}
693cc_library {
694 name: "libfoo_has_stubs",
695 stubs: {symbol_file: "libfoo.map.txt"},
Spandan Das918191e2024-10-31 18:27:23 +0000696 vendor: true,
Spandan Das92631882024-10-28 22:49:38 +0000697}
698 `)
699
700 linkerConfigCmd := result.ModuleForTests("myfilesystem", "android_common").Rule("build_filesystem_image").RuleParams.Command
Spandan Das918191e2024-10-31 18:27:23 +0000701 android.AssertStringDoesContain(t, "Could not find linker.config.json file in cmd", linkerConfigCmd, "conv_linker_config proto --force -s linker.config.json")
702 android.AssertStringDoesContain(t, "Could not find stub in `provideLibs`", linkerConfigCmd, "--key provideLibs --value libfoo_has_stubs.so")
Spandan Das92631882024-10-28 22:49:38 +0000703}
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000704
705// override_android_* modules implicitly override their base module.
706// If both of these are listed in `deps`, the base module should not be installed.
707func TestOverrideModulesInDeps(t *testing.T) {
708 result := fixture.RunTestWithBp(t, `
709 android_filesystem {
710 name: "myfilesystem",
711 deps: ["myapp", "myoverrideapp"],
712 }
713
714 android_app {
715 name: "myapp",
716 platform_apis: true,
717 }
718 override_android_app {
719 name: "myoverrideapp",
720 base: "myapp",
721 }
722 `)
723
724 partition := result.ModuleForTests("myfilesystem", "android_common")
725 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
726 android.AssertStringEquals(t, "filesystem with override app", "app/myoverrideapp/myoverrideapp.apk\n", fileList)
727}