blob: 47d06f669ad53af9d70f516f67014abe66b3bb2c [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 ],
Spandan Das2047a4c2024-11-11 21:24:58 +0000164 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900165 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")
Cole Faustfee27012024-12-13 14:10:31 -0800183 output := module.Output("out/soong/.intermediates/myfilesystem/android_common/linker.config.pb")
Jiyong Parkfa616132021-04-20 11:36:40 +0900184
Cole Faustfee27012024-12-13 14:10:31 -0800185 linkerConfigCommand := output.RuleParams.Command
Cole Faustd7556eb2024-12-02 13:18:58 -0800186
Jiyong Parkfa616132021-04-20 11:36:40 +0900187 android.AssertStringDoesContain(t, "linker.config.pb should have libfoo",
Cole Faustd7556eb2024-12-02 13:18:58 -0800188 linkerConfigCommand, "libfoo.so")
Jiyong Parkfa616132021-04-20 11:36:40 +0900189 android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar",
Cole Faustd7556eb2024-12-02 13:18:58 -0800190 linkerConfigCommand, "libbar.so")
Jiyong Parkfa616132021-04-20 11:36:40 +0900191}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900192
193func registerComponent(ctx android.RegistrationContext) {
194 ctx.RegisterModuleType("component", componentFactory)
195}
196
197func componentFactory() android.Module {
198 m := &component{}
199 m.AddProperties(&m.properties)
200 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
201 return m
202}
203
204type component struct {
205 android.ModuleBase
206 properties struct {
207 Install_copy_in_data []string
208 }
209}
210
211func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) {
212 output := android.PathForModuleOut(ctx, c.Name())
213 dir := android.PathForModuleInstall(ctx, "components")
214 ctx.InstallFile(dir, c.Name(), output)
215
216 dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components")
217 for _, d := range c.properties.Install_copy_in_data {
218 ctx.InstallFile(dataDir, d, output)
219 }
220}
221
222func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) {
223 f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent))
224 result := f.RunTestWithBp(t, `
225 android_system_image {
226 name: "myfilesystem",
227 multilib: {
228 common: {
229 deps: ["foo"],
230 },
231 },
Spandan Das2047a4c2024-11-11 21:24:58 +0000232 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900233 gen_linker_config: true,
234 linker_config_srcs: ["linker.config.json"],
235 },
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900236 }
237 component {
238 name: "foo",
239 install_copy_in_data: ["bar"],
240 }
241 `)
242
243 module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage)
Spandan Das978f4532024-12-05 21:05:43 +0000244 android.AssertDeepEquals(t, "entries should have foo and not bar", []string{"components/foo", "etc/linker.config.pb"}, module.entries)
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900245}
Jiyong Parkbc485482022-11-15 22:31:49 +0900246
Alice Wang000e3a32023-01-03 16:11:20 +0000247func TestAvbGenVbmetaImage(t *testing.T) {
248 result := fixture.RunTestWithBp(t, `
249 avb_gen_vbmeta_image {
250 name: "input_hashdesc",
251 src: "input.img",
252 partition_name: "input_partition_name",
253 salt: "2222",
254 }`)
255 cmd := result.ModuleForTests("input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command
256 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
257 cmd, "--partition_name input_partition_name")
258 android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image",
259 cmd, "--do_not_append_vbmeta_image")
260 android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image",
261 cmd, "--output_vbmeta_image ")
262 android.AssertStringDoesContain(t, "Can't find --salt argument",
263 cmd, "--salt 2222")
264}
265
Jiyong Parkbc485482022-11-15 22:31:49 +0900266func TestAvbAddHashFooter(t *testing.T) {
267 result := fixture.RunTestWithBp(t, `
Alice Wang000e3a32023-01-03 16:11:20 +0000268 avb_gen_vbmeta_image {
269 name: "input_hashdesc",
270 src: "input.img",
271 partition_name: "input",
272 salt: "2222",
273 }
274
Jiyong Parkbc485482022-11-15 22:31:49 +0900275 avb_add_hash_footer {
276 name: "myfooter",
277 src: "input.img",
278 filename: "output.img",
279 partition_name: "mypartition",
280 private_key: "mykey",
281 salt: "1111",
282 props: [
283 {
284 name: "prop1",
285 value: "value1",
286 },
287 {
288 name: "prop2",
289 file: "value_file",
290 },
291 ],
Alice Wang000e3a32023-01-03 16:11:20 +0000292 include_descriptors_from_images: ["input_hashdesc"],
Jiyong Parkbc485482022-11-15 22:31:49 +0900293 }
294 `)
295 cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command
296 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
297 cmd, "--partition_name mypartition")
298 android.AssertStringDoesContain(t, "Can't find correct --key argument",
299 cmd, "--key mykey")
300 android.AssertStringDoesContain(t, "Can't find --salt argument",
301 cmd, "--salt 1111")
302 android.AssertStringDoesContain(t, "Can't find --prop argument",
303 cmd, "--prop 'prop1:value1'")
304 android.AssertStringDoesContain(t, "Can't find --prop_from_file argument",
305 cmd, "--prop_from_file 'prop2:value_file'")
Alice Wang000e3a32023-01-03 16:11:20 +0000306 android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image",
307 cmd, "--include_descriptors_from_image ")
Jiyong Parkbc485482022-11-15 22:31:49 +0900308}
Jooyung Han54f78052023-02-20 18:17:47 +0900309
Jooyung Hane6067592023-03-16 13:11:17 +0900310func TestFileSystemWithCoverageVariants(t *testing.T) {
311 context := android.GroupFixturePreparers(
312 fixture,
313 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
314 variables.GcovCoverage = proptools.BoolPtr(true)
315 variables.Native_coverage = proptools.BoolPtr(true)
316 }),
317 )
318
319 result := context.RunTestWithBp(t, `
320 prebuilt_etc {
321 name: "prebuilt",
322 src: ":myfilesystem",
323 }
324
325 android_system_image {
326 name: "myfilesystem",
327 deps: [
328 "libfoo",
329 ],
Spandan Das2047a4c2024-11-11 21:24:58 +0000330 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900331 gen_linker_config: true,
332 linker_config_srcs: ["linker.config.json"],
333 },
Jooyung Hane6067592023-03-16 13:11:17 +0900334 }
335
336 cc_library {
337 name: "libfoo",
338 shared_libs: [
339 "libbar",
340 ],
341 stl: "none",
342 }
343
344 cc_library {
345 name: "libbar",
346 stl: "none",
347 }
348 `)
349
350 filesystem := result.ModuleForTests("myfilesystem", "android_common_cov")
Cole Faust3b806d32024-03-11 15:15:03 -0700351 inputs := filesystem.Output("myfilesystem.img").Implicits
Jooyung Hane6067592023-03-16 13:11:17 +0900352 android.AssertStringListContains(t, "filesystem should have libfoo(cov)",
353 inputs.Strings(),
354 "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so")
355 android.AssertStringListContains(t, "filesystem should have libbar(cov)",
356 inputs.Strings(),
357 "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared_cov/libbar.so")
358
Spandan Das1f0a5a12025-01-15 00:53:15 +0000359 filesystemOutput := filesystem.OutputFiles(result.TestContext, t, "")[0]
Jooyung Hane6067592023-03-16 13:11:17 +0900360 prebuiltInput := result.ModuleForTests("prebuilt", "android_arm64_armv8-a").Rule("Cp").Input
361 if filesystemOutput != prebuiltInput {
362 t.Error("prebuilt should use cov variant of filesystem")
363 }
364}
Jiyong Parkeaac8232024-03-31 21:27:45 +0900365
366func TestSystemImageDefaults(t *testing.T) {
367 result := fixture.RunTestWithBp(t, `
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900368 android_filesystem_defaults {
Jiyong Parkeaac8232024-03-31 21:27:45 +0900369 name: "defaults",
370 multilib: {
371 common: {
372 deps: [
373 "phony",
374 ],
375 },
376 lib64: {
377 deps: [
378 "libbar",
379 ],
380 },
381 },
382 compile_multilib: "both",
383 }
384
385 android_system_image {
386 name: "system",
387 defaults: ["defaults"],
388 multilib: {
389 lib32: {
390 deps: [
391 "foo",
392 "libbar",
393 ],
394 },
395 },
396 }
397
398 cc_binary {
399 name: "foo",
400 compile_multilib: "prefer32",
401 }
402
403 cc_library {
404 name: "libbar",
405 required: ["libbaz"],
406 }
407
408 cc_library {
409 name: "libbaz",
410 }
411
412 phony {
413 name: "phony",
414 required: ["libquz"],
415 }
416
417 cc_library {
418 name: "libquz",
419 }
420 `)
421
422 fs := result.ModuleForTests("system", "android_common").Module().(*systemImage)
423 expected := []string{
424 "bin/foo",
425 "lib/libbar.so",
426 "lib64/libbar.so",
427 "lib64/libbaz.so",
428 "lib64/libquz.so",
429 }
430 for _, e := range expected {
431 android.AssertStringListContains(t, "missing entry", fs.entries, e)
432 }
433}
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900434
435func TestInconsistentPartitionTypesInDefaults(t *testing.T) {
436 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
437 "doesn't match with the partition type")).
438 RunTestWithBp(t, `
439 android_filesystem_defaults {
440 name: "system_ext_def",
441 partition_type: "system_ext",
442 }
443
444 android_filesystem_defaults {
445 name: "system_def",
446 partition_type: "system",
447 defaults: ["system_ext_def"],
448 }
449
450 android_system_image {
451 name: "system",
452 defaults: ["system_def"],
453 }
454 `)
455}
Jiyong Park16ef7ac2024-05-01 12:36:10 +0000456
457func TestPreventDuplicatedEntries(t *testing.T) {
458 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
459 "packaging conflict at")).
460 RunTestWithBp(t, `
461 android_filesystem {
462 name: "fs",
463 deps: [
464 "foo",
465 "foo_dup",
466 ],
467 }
468
469 cc_binary {
470 name: "foo",
471 }
472
473 cc_binary {
474 name: "foo_dup",
475 stem: "foo",
476 }
477 `)
478}
Jiyong Parkc4b1d552024-05-13 16:47:30 +0900479
480func TestTrackPhonyAsRequiredDep(t *testing.T) {
481 result := fixture.RunTestWithBp(t, `
482 android_filesystem {
483 name: "fs",
484 deps: ["foo"],
485 }
486
487 cc_binary {
488 name: "foo",
489 required: ["phony"],
490 }
491
492 phony {
493 name: "phony",
494 required: ["libbar"],
495 }
496
497 cc_library {
498 name: "libbar",
499 }
500 `)
501
502 fs := result.ModuleForTests("fs", "android_common").Module().(*filesystem)
503 expected := []string{
504 "bin/foo",
505 "lib64/libbar.so",
506 }
507 for _, e := range expected {
508 android.AssertStringListContains(t, "missing entry", fs.entries, e)
509 }
510}
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900511
512func TestFilterOutUnsupportedArches(t *testing.T) {
513 result := fixture.RunTestWithBp(t, `
514 android_filesystem {
515 name: "fs_64_only",
516 deps: ["foo"],
517 }
518
519 android_filesystem {
520 name: "fs_64_32",
521 compile_multilib: "both",
Jiyong Park3ea9b652024-05-15 23:01:54 +0900522 deps: ["foo"],
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900523 }
524
525 cc_binary {
526 name: "foo",
527 required: ["phony"],
528 }
529
530 phony {
531 name: "phony",
532 required: [
533 "libbar",
534 "app",
535 ],
536 }
537
538 cc_library {
539 name: "libbar",
540 }
541
542 android_app {
543 name: "app",
544 srcs: ["a.java"],
545 platform_apis: true,
546 }
547 `)
548 testcases := []struct {
549 fsName string
550 expected []string
551 unexpected []string
552 }{
553 {
554 fsName: "fs_64_only",
555 expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so"},
556 unexpected: []string{"lib/libbar.so"},
557 },
558 {
559 fsName: "fs_64_32",
560 expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so", "lib/libbar.so"},
561 unexpected: []string{},
562 },
563 }
564 for _, c := range testcases {
565 fs := result.ModuleForTests(c.fsName, "android_common").Module().(*filesystem)
566 for _, e := range c.expected {
567 android.AssertStringListContains(t, "missing entry", fs.entries, e)
568 }
569 for _, e := range c.unexpected {
570 android.AssertStringListDoesNotContain(t, "unexpected entry", fs.entries, e)
571 }
572 }
573}
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000574
575func TestErofsPartition(t *testing.T) {
576 result := fixture.RunTestWithBp(t, `
577 android_filesystem {
578 name: "erofs_partition",
579 type: "erofs",
580 erofs: {
581 compressor: "lz4hc,9",
582 compress_hints: "compress_hints.txt",
583 },
584 deps: ["binfoo"],
585 }
586
587 cc_binary {
588 name: "binfoo",
589 }
590 `)
591
592 partition := result.ModuleForTests("erofs_partition", "android_common")
Cole Fauste1676122024-12-03 17:32:25 -0800593 buildImageConfig := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("prop_pre_processing"))
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000594 android.AssertStringDoesContain(t, "erofs fs type", buildImageConfig, "fs_type=erofs")
595 android.AssertStringDoesContain(t, "erofs fs type compress algorithm", buildImageConfig, "erofs_default_compressor=lz4hc,9")
596 android.AssertStringDoesContain(t, "erofs fs type compress hint", buildImageConfig, "erofs_default_compress_hints=compress_hints.txt")
597 android.AssertStringDoesContain(t, "erofs fs type sparse", buildImageConfig, "erofs_sparse_flag=-s")
598}
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000599
mrziwang1a6291f2024-11-07 14:29:25 -0800600func TestF2fsPartition(t *testing.T) {
601 result := fixture.RunTestWithBp(t, `
602 android_filesystem {
603 name: "f2fs_partition",
604 type: "f2fs",
605 }
606 `)
607
608 partition := result.ModuleForTests("f2fs_partition", "android_common")
Cole Fauste1676122024-12-03 17:32:25 -0800609 buildImageConfig := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("prop_pre_processing"))
mrziwang1a6291f2024-11-07 14:29:25 -0800610 android.AssertStringDoesContain(t, "f2fs fs type", buildImageConfig, "fs_type=f2fs")
611 android.AssertStringDoesContain(t, "f2fs fs type sparse", buildImageConfig, "f2fs_sparse_flag=-S")
612}
613
614func TestFsTypesPropertyError(t *testing.T) {
615 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
616 "erofs: erofs is non-empty, but FS type is f2fs\n. Please delete erofs properties if this partition should use f2fs\n")).
617 RunTestWithBp(t, `
618 android_filesystem {
619 name: "f2fs_partition",
620 type: "f2fs",
621 erofs: {
622 compressor: "lz4hc,9",
623 compress_hints: "compress_hints.txt",
624 },
625 }
626 `)
627}
628
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000629// If a system_ext/ module depends on system/ module, the dependency should *not*
630// be installed in system_ext/
631func TestDoNotPackageCrossPartitionDependencies(t *testing.T) {
Spandan Das6d056502024-10-21 15:40:32 +0000632 t.Skip() // TODO (spandandas): Re-enable this
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000633 result := fixture.RunTestWithBp(t, `
634 android_filesystem {
635 name: "myfilesystem",
636 deps: ["binfoo"],
637 partition_type: "system_ext",
638 }
639
640 cc_binary {
641 name: "binfoo",
642 shared_libs: ["libfoo"],
643 system_ext_specific: true,
644 }
645 cc_library_shared {
646 name: "libfoo", // installed in system/
647 }
648 `)
649
650 partition := result.ModuleForTests("myfilesystem", "android_common")
651 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
652 android.AssertDeepEquals(t, "filesystem with dependencies on different partition", "bin/binfoo\n", fileList)
653}
Spandan Das405f2d42024-10-22 18:31:25 +0000654
655// If a cc_library is listed in `deps`, and it has a shared and static variant, then the shared variant
656// should be installed.
657func TestUseSharedVariationOfNativeLib(t *testing.T) {
658 result := fixture.RunTestWithBp(t, `
659 android_filesystem {
660 name: "myfilesystem",
661 deps: ["libfoo"],
662 }
663 // cc_library will create a static and shared variant.
664 cc_library {
665 name: "libfoo",
666 }
667 `)
668
669 partition := result.ModuleForTests("myfilesystem", "android_common")
670 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
Colin Cross386afeb2024-11-13 15:20:13 -0800671 android.AssertDeepEquals(t, "cc_library listed in deps",
672 "lib64/bootstrap/libc.so\nlib64/bootstrap/libdl.so\nlib64/bootstrap/libm.so\nlib64/libc++.so\nlib64/libc.so\nlib64/libdl.so\nlib64/libfoo.so\nlib64/libm.so\n",
673 fileList)
Spandan Das405f2d42024-10-22 18:31:25 +0000674}
Spandan Das6c2b01d2024-10-22 22:16:04 +0000675
676// binfoo1 overrides binbar. transitive deps of binbar should not be installed.
677func TestDoNotInstallTransitiveDepOfOverriddenModule(t *testing.T) {
678 result := fixture.RunTestWithBp(t, `
679android_filesystem {
680 name: "myfilesystem",
681 deps: ["binfoo1", "libfoo2", "binbar"],
682}
683cc_binary {
684 name: "binfoo1",
685 shared_libs: ["libfoo"],
686 overrides: ["binbar"],
687}
688cc_library {
689 name: "libfoo",
690}
691cc_library {
692 name: "libfoo2",
693 overrides: ["libfoo"],
694}
695// binbar gets overridden by binfoo1
696// therefore, libbar should not be installed
697cc_binary {
698 name: "binbar",
699 shared_libs: ["libbar"]
700}
701cc_library {
702 name: "libbar",
703}
704 `)
705
706 partition := result.ModuleForTests("myfilesystem", "android_common")
707 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
Colin Cross386afeb2024-11-13 15:20:13 -0800708 android.AssertDeepEquals(t, "Shared library dep of overridden binary should not be installed",
709 "bin/binfoo1\nlib64/bootstrap/libc.so\nlib64/bootstrap/libdl.so\nlib64/bootstrap/libm.so\nlib64/libc++.so\nlib64/libc.so\nlib64/libdl.so\nlib64/libfoo2.so\nlib64/libm.so\n",
710 fileList)
Spandan Das6c2b01d2024-10-22 22:16:04 +0000711}
Spandan Das92631882024-10-28 22:49:38 +0000712
713func TestInstallLinkerConfigFile(t *testing.T) {
714 result := fixture.RunTestWithBp(t, `
715android_filesystem {
716 name: "myfilesystem",
717 deps: ["libfoo_has_no_stubs", "libfoo_has_stubs"],
Spandan Das2047a4c2024-11-11 21:24:58 +0000718 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900719 gen_linker_config: true,
720 linker_config_srcs: ["linker.config.json"],
Spandan Das173256b2024-10-31 19:59:30 +0000721 },
Spandan Das918191e2024-10-31 18:27:23 +0000722 partition_type: "vendor",
Spandan Das92631882024-10-28 22:49:38 +0000723}
724cc_library {
725 name: "libfoo_has_no_stubs",
Spandan Das918191e2024-10-31 18:27:23 +0000726 vendor: true,
Spandan Das92631882024-10-28 22:49:38 +0000727}
728cc_library {
729 name: "libfoo_has_stubs",
730 stubs: {symbol_file: "libfoo.map.txt"},
Spandan Das918191e2024-10-31 18:27:23 +0000731 vendor: true,
Spandan Das92631882024-10-28 22:49:38 +0000732}
733 `)
734
Cole Faustfee27012024-12-13 14:10:31 -0800735 linkerConfigCmd := result.ModuleForTests("myfilesystem", "android_common").Output("out/soong/.intermediates/myfilesystem/android_common/linker.config.pb").RuleParams.Command
Spandan Das918191e2024-10-31 18:27:23 +0000736 android.AssertStringDoesContain(t, "Could not find linker.config.json file in cmd", linkerConfigCmd, "conv_linker_config proto --force -s linker.config.json")
737 android.AssertStringDoesContain(t, "Could not find stub in `provideLibs`", linkerConfigCmd, "--key provideLibs --value libfoo_has_stubs.so")
Spandan Das92631882024-10-28 22:49:38 +0000738}
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000739
740// override_android_* modules implicitly override their base module.
741// If both of these are listed in `deps`, the base module should not be installed.
742func TestOverrideModulesInDeps(t *testing.T) {
743 result := fixture.RunTestWithBp(t, `
744 android_filesystem {
745 name: "myfilesystem",
746 deps: ["myapp", "myoverrideapp"],
747 }
748
749 android_app {
750 name: "myapp",
751 platform_apis: true,
752 }
753 override_android_app {
754 name: "myoverrideapp",
755 base: "myapp",
756 }
757 `)
758
759 partition := result.ModuleForTests("myfilesystem", "android_common")
760 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
761 android.AssertStringEquals(t, "filesystem with override app", "app/myoverrideapp/myoverrideapp.apk\n", fileList)
762}
Jihoon Kang6c03c8e2024-11-18 21:30:22 +0000763
764func TestRamdiskPartitionSetsDevNodes(t *testing.T) {
765 result := android.GroupFixturePreparers(
766 fixture,
767 android.FixtureMergeMockFs(android.MockFS{
768 "ramdisk_node_list": nil,
769 }),
770 ).RunTestWithBp(t, `
771 android_filesystem {
772 name: "ramdisk_filesystem",
773 partition_name: "ramdisk",
774 }
775 filegroup {
776 name: "ramdisk_node_list",
777 srcs: ["ramdisk_node_list"],
778 }
779 `)
780
781 android.AssertBoolEquals(
782 t,
783 "Generated ramdisk image expected to depend on \"ramdisk_node_list\" module",
784 true,
785 java.CheckModuleHasDependency(t, result.TestContext, "ramdisk_filesystem", "android_common", "ramdisk_node_list"),
786 )
787}