blob: 0ed3870a6d7dfeaf02931ca27018e2e2e3b650a8 [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"
Cole Faustd7556eb2024-12-02 13:18:58 -080019 "strings"
Jooyung Han9706cbc2021-04-15 22:43:48 +090020 "testing"
21
22 "android/soong/android"
Jiyong Park06c4cdc2024-02-16 15:35:03 +090023 "android/soong/bpf"
Jiyong Parkfa616132021-04-20 11:36:40 +090024 "android/soong/cc"
Jooyung Hane6067592023-03-16 13:11:17 +090025 "android/soong/etc"
Jiyong Park73e5bab2024-04-05 13:37:21 +090026 "android/soong/java"
Jiyong Park9c540c82024-03-26 10:48:27 +090027 "android/soong/phony"
Jooyung Hane6067592023-03-16 13:11:17 +090028
29 "github.com/google/blueprint/proptools"
Jooyung Han9706cbc2021-04-15 22:43:48 +090030)
31
32func TestMain(m *testing.M) {
33 os.Exit(m.Run())
34}
35
36var fixture = android.GroupFixturePreparers(
37 android.PrepareForIntegrationTestWithAndroid,
Jiyong Park73e5bab2024-04-05 13:37:21 +090038 android.PrepareForTestWithAndroidBuildComponents,
Jiyong Park06c4cdc2024-02-16 15:35:03 +090039 bpf.PrepareForTestWithBpf,
Jiyong Parkfa616132021-04-20 11:36:40 +090040 cc.PrepareForIntegrationTestWithCc,
Jiyong Park73e5bab2024-04-05 13:37:21 +090041 etc.PrepareForTestWithPrebuiltEtc,
42 java.PrepareForTestWithJavaBuildComponents,
43 java.PrepareForTestWithJavaDefaultModules,
Jiyong Park9c540c82024-03-26 10:48:27 +090044 phony.PrepareForTestWithPhony,
Jooyung Han9706cbc2021-04-15 22:43:48 +090045 PrepareForTestWithFilesystemBuildComponents,
46)
47
48func TestFileSystemDeps(t *testing.T) {
49 result := fixture.RunTestWithBp(t, `
50 android_filesystem {
51 name: "myfilesystem",
Jiyong Park06c4cdc2024-02-16 15:35:03 +090052 multilib: {
53 common: {
54 deps: [
55 "bpf.o",
Jiyong Park9c540c82024-03-26 10:48:27 +090056 "phony",
Jiyong Park06c4cdc2024-02-16 15:35:03 +090057 ],
58 },
Jiyong Parkeec7c382024-02-16 16:10:13 +090059 lib32: {
60 deps: [
61 "foo",
62 "libbar",
63 ],
64 },
65 lib64: {
66 deps: [
67 "libbar",
68 ],
69 },
Jiyong Park06c4cdc2024-02-16 15:35:03 +090070 },
Jiyong Parkeec7c382024-02-16 16:10:13 +090071 compile_multilib: "both",
Jiyong Park06c4cdc2024-02-16 15:35:03 +090072 }
73
74 bpf {
75 name: "bpf.o",
76 srcs: ["bpf.c"],
Jooyung Han9706cbc2021-04-15 22:43:48 +090077 }
Jiyong Parkeec7c382024-02-16 16:10:13 +090078
79 cc_binary {
80 name: "foo",
81 compile_multilib: "prefer32",
82 }
83
84 cc_library {
85 name: "libbar",
Jiyong Park8bcf3c62024-03-18 18:37:10 +090086 required: ["libbaz"],
Jiyong Parkf21dd652024-04-17 05:22:37 +000087 target: {
88 platform: {
89 required: ["lib_platform_only"],
90 },
91 },
Jiyong Park8bcf3c62024-03-18 18:37:10 +090092 }
93
94 cc_library {
95 name: "libbaz",
Jiyong Parkeec7c382024-02-16 16:10:13 +090096 }
Jiyong Park9c540c82024-03-26 10:48:27 +090097
Jiyong Parkf21dd652024-04-17 05:22:37 +000098 cc_library {
99 name: "lib_platform_only",
100 }
101
Jiyong Park9c540c82024-03-26 10:48:27 +0900102 phony {
103 name: "phony",
Jiyong Park73e5bab2024-04-05 13:37:21 +0900104 required: [
105 "libquz",
106 "myapp",
107 ],
Jiyong Park9c540c82024-03-26 10:48:27 +0900108 }
109
110 cc_library {
111 name: "libquz",
112 }
Jiyong Park73e5bab2024-04-05 13:37:21 +0900113
114 android_app {
115 name: "myapp",
116 platform_apis: true,
117 installable: true,
118 }
Jooyung Han9706cbc2021-04-15 22:43:48 +0900119 `)
120
121 // produces "myfilesystem.img"
122 result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img")
Jiyong Park06c4cdc2024-02-16 15:35:03 +0900123
124 fs := result.ModuleForTests("myfilesystem", "android_common").Module().(*filesystem)
Jiyong Parkeec7c382024-02-16 16:10:13 +0900125 expected := []string{
Jiyong Park73e5bab2024-04-05 13:37:21 +0900126 "app/myapp/myapp.apk",
Jiyong Parkeec7c382024-02-16 16:10:13 +0900127 "bin/foo",
128 "lib/libbar.so",
129 "lib64/libbar.so",
Jiyong Park8bcf3c62024-03-18 18:37:10 +0900130 "lib64/libbaz.so",
Jiyong Park9c540c82024-03-26 10:48:27 +0900131 "lib64/libquz.so",
Jiyong Parkf21dd652024-04-17 05:22:37 +0000132 "lib64/lib_platform_only.so",
Jiyong Parkeec7c382024-02-16 16:10:13 +0900133 "etc/bpf/bpf.o",
134 }
Jiyong Park06c4cdc2024-02-16 15:35:03 +0900135 for _, e := range expected {
136 android.AssertStringListContains(t, "missing entry", fs.entries, e)
137 }
Jooyung Han9706cbc2021-04-15 22:43:48 +0900138}
Jiyong Parkfa616132021-04-20 11:36:40 +0900139
Cole Faust4a2a7c92024-03-12 12:44:40 -0700140func TestIncludeMakeBuiltFiles(t *testing.T) {
141 result := fixture.RunTestWithBp(t, `
142 android_filesystem {
143 name: "myfilesystem",
144 include_make_built_files: "system",
145 }
146 `)
147
148 output := result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img")
149
Colin Cross3b1c6842024-07-26 11:52:57 -0700150 stampFile := "out/target/product/test_device/obj/PACKAGING/system_intermediates/staging_dir.stamp"
151 fileListFile := "out/target/product/test_device/obj/PACKAGING/system_intermediates/file_list.txt"
Cole Faust4a2a7c92024-03-12 12:44:40 -0700152 android.AssertStringListContains(t, "deps of filesystem must include the staging dir stamp file", output.Implicits.Strings(), stampFile)
153 android.AssertStringListContains(t, "deps of filesystem must include the staging dir file list", output.Implicits.Strings(), fileListFile)
154}
155
Jiyong Parkfa616132021-04-20 11:36:40 +0900156func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) {
157 result := fixture.RunTestWithBp(t, `
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900158 android_system_image {
Jiyong Parkfa616132021-04-20 11:36:40 +0900159 name: "myfilesystem",
Kiyoung Kim67118212024-11-07 13:23:44 +0900160 base_dir: "system",
Jiyong Parkfa616132021-04-20 11:36:40 +0900161 deps: [
162 "libfoo",
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900163 "libbar",
Jiyong Parkfa616132021-04-20 11:36:40 +0900164 ],
Spandan Das2047a4c2024-11-11 21:24:58 +0000165 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900166 gen_linker_config: true,
167 linker_config_srcs: ["linker.config.json"],
168 },
Jiyong Parkfa616132021-04-20 11:36:40 +0900169 }
170
171 cc_library {
172 name: "libfoo",
173 stubs: {
174 symbol_file: "libfoo.map.txt",
175 },
176 }
177
178 cc_library {
179 name: "libbar",
180 }
181 `)
182
183 module := result.ModuleForTests("myfilesystem", "android_common")
Kiyoung Kim67118212024-11-07 13:23:44 +0900184 output := module.Output("out/soong/.intermediates/myfilesystem/android_common/root/system/etc/linker.config.pb")
Jiyong Parkfa616132021-04-20 11:36:40 +0900185
Cole Faustd7556eb2024-12-02 13:18:58 -0800186 fullCommand := output.RuleParams.Command
187 startIndex := strings.Index(fullCommand, "conv_linker_config")
188 linkerConfigCommand := fullCommand[startIndex:]
189
Jiyong Parkfa616132021-04-20 11:36:40 +0900190 android.AssertStringDoesContain(t, "linker.config.pb should have libfoo",
Cole Faustd7556eb2024-12-02 13:18:58 -0800191 linkerConfigCommand, "libfoo.so")
Jiyong Parkfa616132021-04-20 11:36:40 +0900192 android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar",
Cole Faustd7556eb2024-12-02 13:18:58 -0800193 linkerConfigCommand, "libbar.so")
Jiyong Parkfa616132021-04-20 11:36:40 +0900194}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900195
196func registerComponent(ctx android.RegistrationContext) {
197 ctx.RegisterModuleType("component", componentFactory)
198}
199
200func componentFactory() android.Module {
201 m := &component{}
202 m.AddProperties(&m.properties)
203 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
204 return m
205}
206
207type component struct {
208 android.ModuleBase
209 properties struct {
210 Install_copy_in_data []string
211 }
212}
213
214func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) {
215 output := android.PathForModuleOut(ctx, c.Name())
216 dir := android.PathForModuleInstall(ctx, "components")
217 ctx.InstallFile(dir, c.Name(), output)
218
219 dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components")
220 for _, d := range c.properties.Install_copy_in_data {
221 ctx.InstallFile(dataDir, d, output)
222 }
223}
224
225func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) {
226 f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent))
227 result := f.RunTestWithBp(t, `
228 android_system_image {
229 name: "myfilesystem",
230 multilib: {
231 common: {
232 deps: ["foo"],
233 },
234 },
Spandan Das2047a4c2024-11-11 21:24:58 +0000235 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900236 gen_linker_config: true,
237 linker_config_srcs: ["linker.config.json"],
238 },
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900239 }
240 component {
241 name: "foo",
242 install_copy_in_data: ["bar"],
243 }
244 `)
245
246 module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage)
Spandan Das978f4532024-12-05 21:05:43 +0000247 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 +0900248}
Jiyong Parkbc485482022-11-15 22:31:49 +0900249
Alice Wang000e3a32023-01-03 16:11:20 +0000250func TestAvbGenVbmetaImage(t *testing.T) {
251 result := fixture.RunTestWithBp(t, `
252 avb_gen_vbmeta_image {
253 name: "input_hashdesc",
254 src: "input.img",
255 partition_name: "input_partition_name",
256 salt: "2222",
257 }`)
258 cmd := result.ModuleForTests("input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command
259 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
260 cmd, "--partition_name input_partition_name")
261 android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image",
262 cmd, "--do_not_append_vbmeta_image")
263 android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image",
264 cmd, "--output_vbmeta_image ")
265 android.AssertStringDoesContain(t, "Can't find --salt argument",
266 cmd, "--salt 2222")
267}
268
Jiyong Parkbc485482022-11-15 22:31:49 +0900269func TestAvbAddHashFooter(t *testing.T) {
270 result := fixture.RunTestWithBp(t, `
Alice Wang000e3a32023-01-03 16:11:20 +0000271 avb_gen_vbmeta_image {
272 name: "input_hashdesc",
273 src: "input.img",
274 partition_name: "input",
275 salt: "2222",
276 }
277
Jiyong Parkbc485482022-11-15 22:31:49 +0900278 avb_add_hash_footer {
279 name: "myfooter",
280 src: "input.img",
281 filename: "output.img",
282 partition_name: "mypartition",
283 private_key: "mykey",
284 salt: "1111",
285 props: [
286 {
287 name: "prop1",
288 value: "value1",
289 },
290 {
291 name: "prop2",
292 file: "value_file",
293 },
294 ],
Alice Wang000e3a32023-01-03 16:11:20 +0000295 include_descriptors_from_images: ["input_hashdesc"],
Jiyong Parkbc485482022-11-15 22:31:49 +0900296 }
297 `)
298 cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command
299 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
300 cmd, "--partition_name mypartition")
301 android.AssertStringDoesContain(t, "Can't find correct --key argument",
302 cmd, "--key mykey")
303 android.AssertStringDoesContain(t, "Can't find --salt argument",
304 cmd, "--salt 1111")
305 android.AssertStringDoesContain(t, "Can't find --prop argument",
306 cmd, "--prop 'prop1:value1'")
307 android.AssertStringDoesContain(t, "Can't find --prop_from_file argument",
308 cmd, "--prop_from_file 'prop2:value_file'")
Alice Wang000e3a32023-01-03 16:11:20 +0000309 android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image",
310 cmd, "--include_descriptors_from_image ")
Jiyong Parkbc485482022-11-15 22:31:49 +0900311}
Jooyung Han54f78052023-02-20 18:17:47 +0900312
Jooyung Hane6067592023-03-16 13:11:17 +0900313func TestFileSystemWithCoverageVariants(t *testing.T) {
314 context := android.GroupFixturePreparers(
315 fixture,
316 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
317 variables.GcovCoverage = proptools.BoolPtr(true)
318 variables.Native_coverage = proptools.BoolPtr(true)
319 }),
320 )
321
322 result := context.RunTestWithBp(t, `
323 prebuilt_etc {
324 name: "prebuilt",
325 src: ":myfilesystem",
326 }
327
328 android_system_image {
329 name: "myfilesystem",
330 deps: [
331 "libfoo",
332 ],
Spandan Das2047a4c2024-11-11 21:24:58 +0000333 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900334 gen_linker_config: true,
335 linker_config_srcs: ["linker.config.json"],
336 },
Jooyung Hane6067592023-03-16 13:11:17 +0900337 }
338
339 cc_library {
340 name: "libfoo",
341 shared_libs: [
342 "libbar",
343 ],
344 stl: "none",
345 }
346
347 cc_library {
348 name: "libbar",
349 stl: "none",
350 }
351 `)
352
353 filesystem := result.ModuleForTests("myfilesystem", "android_common_cov")
Cole Faust3b806d32024-03-11 15:15:03 -0700354 inputs := filesystem.Output("myfilesystem.img").Implicits
Jooyung Hane6067592023-03-16 13:11:17 +0900355 android.AssertStringListContains(t, "filesystem should have libfoo(cov)",
356 inputs.Strings(),
357 "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so")
358 android.AssertStringListContains(t, "filesystem should have libbar(cov)",
359 inputs.Strings(),
360 "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared_cov/libbar.so")
361
362 filesystemOutput := filesystem.Output("myfilesystem.img").Output
363 prebuiltInput := result.ModuleForTests("prebuilt", "android_arm64_armv8-a").Rule("Cp").Input
364 if filesystemOutput != prebuiltInput {
365 t.Error("prebuilt should use cov variant of filesystem")
366 }
367}
Jiyong Parkeaac8232024-03-31 21:27:45 +0900368
369func TestSystemImageDefaults(t *testing.T) {
370 result := fixture.RunTestWithBp(t, `
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900371 android_filesystem_defaults {
Jiyong Parkeaac8232024-03-31 21:27:45 +0900372 name: "defaults",
373 multilib: {
374 common: {
375 deps: [
376 "phony",
377 ],
378 },
379 lib64: {
380 deps: [
381 "libbar",
382 ],
383 },
384 },
385 compile_multilib: "both",
386 }
387
388 android_system_image {
389 name: "system",
390 defaults: ["defaults"],
391 multilib: {
392 lib32: {
393 deps: [
394 "foo",
395 "libbar",
396 ],
397 },
398 },
399 }
400
401 cc_binary {
402 name: "foo",
403 compile_multilib: "prefer32",
404 }
405
406 cc_library {
407 name: "libbar",
408 required: ["libbaz"],
409 }
410
411 cc_library {
412 name: "libbaz",
413 }
414
415 phony {
416 name: "phony",
417 required: ["libquz"],
418 }
419
420 cc_library {
421 name: "libquz",
422 }
423 `)
424
425 fs := result.ModuleForTests("system", "android_common").Module().(*systemImage)
426 expected := []string{
427 "bin/foo",
428 "lib/libbar.so",
429 "lib64/libbar.so",
430 "lib64/libbaz.so",
431 "lib64/libquz.so",
432 }
433 for _, e := range expected {
434 android.AssertStringListContains(t, "missing entry", fs.entries, e)
435 }
436}
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900437
438func TestInconsistentPartitionTypesInDefaults(t *testing.T) {
439 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
440 "doesn't match with the partition type")).
441 RunTestWithBp(t, `
442 android_filesystem_defaults {
443 name: "system_ext_def",
444 partition_type: "system_ext",
445 }
446
447 android_filesystem_defaults {
448 name: "system_def",
449 partition_type: "system",
450 defaults: ["system_ext_def"],
451 }
452
453 android_system_image {
454 name: "system",
455 defaults: ["system_def"],
456 }
457 `)
458}
Jiyong Park16ef7ac2024-05-01 12:36:10 +0000459
460func TestPreventDuplicatedEntries(t *testing.T) {
461 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
462 "packaging conflict at")).
463 RunTestWithBp(t, `
464 android_filesystem {
465 name: "fs",
466 deps: [
467 "foo",
468 "foo_dup",
469 ],
470 }
471
472 cc_binary {
473 name: "foo",
474 }
475
476 cc_binary {
477 name: "foo_dup",
478 stem: "foo",
479 }
480 `)
481}
Jiyong Parkc4b1d552024-05-13 16:47:30 +0900482
483func TestTrackPhonyAsRequiredDep(t *testing.T) {
484 result := fixture.RunTestWithBp(t, `
485 android_filesystem {
486 name: "fs",
487 deps: ["foo"],
488 }
489
490 cc_binary {
491 name: "foo",
492 required: ["phony"],
493 }
494
495 phony {
496 name: "phony",
497 required: ["libbar"],
498 }
499
500 cc_library {
501 name: "libbar",
502 }
503 `)
504
505 fs := result.ModuleForTests("fs", "android_common").Module().(*filesystem)
506 expected := []string{
507 "bin/foo",
508 "lib64/libbar.so",
509 }
510 for _, e := range expected {
511 android.AssertStringListContains(t, "missing entry", fs.entries, e)
512 }
513}
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900514
515func TestFilterOutUnsupportedArches(t *testing.T) {
516 result := fixture.RunTestWithBp(t, `
517 android_filesystem {
518 name: "fs_64_only",
519 deps: ["foo"],
520 }
521
522 android_filesystem {
523 name: "fs_64_32",
524 compile_multilib: "both",
Jiyong Park3ea9b652024-05-15 23:01:54 +0900525 deps: ["foo"],
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900526 }
527
528 cc_binary {
529 name: "foo",
530 required: ["phony"],
531 }
532
533 phony {
534 name: "phony",
535 required: [
536 "libbar",
537 "app",
538 ],
539 }
540
541 cc_library {
542 name: "libbar",
543 }
544
545 android_app {
546 name: "app",
547 srcs: ["a.java"],
548 platform_apis: true,
549 }
550 `)
551 testcases := []struct {
552 fsName string
553 expected []string
554 unexpected []string
555 }{
556 {
557 fsName: "fs_64_only",
558 expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so"},
559 unexpected: []string{"lib/libbar.so"},
560 },
561 {
562 fsName: "fs_64_32",
563 expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so", "lib/libbar.so"},
564 unexpected: []string{},
565 },
566 }
567 for _, c := range testcases {
568 fs := result.ModuleForTests(c.fsName, "android_common").Module().(*filesystem)
569 for _, e := range c.expected {
570 android.AssertStringListContains(t, "missing entry", fs.entries, e)
571 }
572 for _, e := range c.unexpected {
573 android.AssertStringListDoesNotContain(t, "unexpected entry", fs.entries, e)
574 }
575 }
576}
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000577
578func TestErofsPartition(t *testing.T) {
579 result := fixture.RunTestWithBp(t, `
580 android_filesystem {
581 name: "erofs_partition",
582 type: "erofs",
583 erofs: {
584 compressor: "lz4hc,9",
585 compress_hints: "compress_hints.txt",
586 },
587 deps: ["binfoo"],
588 }
589
590 cc_binary {
591 name: "binfoo",
592 }
593 `)
594
595 partition := result.ModuleForTests("erofs_partition", "android_common")
Cole Fauste1676122024-12-03 17:32:25 -0800596 buildImageConfig := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("prop_pre_processing"))
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000597 android.AssertStringDoesContain(t, "erofs fs type", buildImageConfig, "fs_type=erofs")
598 android.AssertStringDoesContain(t, "erofs fs type compress algorithm", buildImageConfig, "erofs_default_compressor=lz4hc,9")
599 android.AssertStringDoesContain(t, "erofs fs type compress hint", buildImageConfig, "erofs_default_compress_hints=compress_hints.txt")
600 android.AssertStringDoesContain(t, "erofs fs type sparse", buildImageConfig, "erofs_sparse_flag=-s")
601}
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000602
mrziwang1a6291f2024-11-07 14:29:25 -0800603func TestF2fsPartition(t *testing.T) {
604 result := fixture.RunTestWithBp(t, `
605 android_filesystem {
606 name: "f2fs_partition",
607 type: "f2fs",
608 }
609 `)
610
611 partition := result.ModuleForTests("f2fs_partition", "android_common")
Cole Fauste1676122024-12-03 17:32:25 -0800612 buildImageConfig := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("prop_pre_processing"))
mrziwang1a6291f2024-11-07 14:29:25 -0800613 android.AssertStringDoesContain(t, "f2fs fs type", buildImageConfig, "fs_type=f2fs")
614 android.AssertStringDoesContain(t, "f2fs fs type sparse", buildImageConfig, "f2fs_sparse_flag=-S")
615}
616
617func TestFsTypesPropertyError(t *testing.T) {
618 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
619 "erofs: erofs is non-empty, but FS type is f2fs\n. Please delete erofs properties if this partition should use f2fs\n")).
620 RunTestWithBp(t, `
621 android_filesystem {
622 name: "f2fs_partition",
623 type: "f2fs",
624 erofs: {
625 compressor: "lz4hc,9",
626 compress_hints: "compress_hints.txt",
627 },
628 }
629 `)
630}
631
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000632// If a system_ext/ module depends on system/ module, the dependency should *not*
633// be installed in system_ext/
634func TestDoNotPackageCrossPartitionDependencies(t *testing.T) {
Spandan Das6d056502024-10-21 15:40:32 +0000635 t.Skip() // TODO (spandandas): Re-enable this
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000636 result := fixture.RunTestWithBp(t, `
637 android_filesystem {
638 name: "myfilesystem",
639 deps: ["binfoo"],
640 partition_type: "system_ext",
641 }
642
643 cc_binary {
644 name: "binfoo",
645 shared_libs: ["libfoo"],
646 system_ext_specific: true,
647 }
648 cc_library_shared {
649 name: "libfoo", // installed in system/
650 }
651 `)
652
653 partition := result.ModuleForTests("myfilesystem", "android_common")
654 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
655 android.AssertDeepEquals(t, "filesystem with dependencies on different partition", "bin/binfoo\n", fileList)
656}
Spandan Das405f2d42024-10-22 18:31:25 +0000657
658// If a cc_library is listed in `deps`, and it has a shared and static variant, then the shared variant
659// should be installed.
660func TestUseSharedVariationOfNativeLib(t *testing.T) {
661 result := fixture.RunTestWithBp(t, `
662 android_filesystem {
663 name: "myfilesystem",
664 deps: ["libfoo"],
665 }
666 // cc_library will create a static and shared variant.
667 cc_library {
668 name: "libfoo",
669 }
670 `)
671
672 partition := result.ModuleForTests("myfilesystem", "android_common")
673 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
Colin Cross386afeb2024-11-13 15:20:13 -0800674 android.AssertDeepEquals(t, "cc_library listed in deps",
675 "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",
676 fileList)
Spandan Das405f2d42024-10-22 18:31:25 +0000677}
Spandan Das6c2b01d2024-10-22 22:16:04 +0000678
679// binfoo1 overrides binbar. transitive deps of binbar should not be installed.
680func TestDoNotInstallTransitiveDepOfOverriddenModule(t *testing.T) {
681 result := fixture.RunTestWithBp(t, `
682android_filesystem {
683 name: "myfilesystem",
684 deps: ["binfoo1", "libfoo2", "binbar"],
685}
686cc_binary {
687 name: "binfoo1",
688 shared_libs: ["libfoo"],
689 overrides: ["binbar"],
690}
691cc_library {
692 name: "libfoo",
693}
694cc_library {
695 name: "libfoo2",
696 overrides: ["libfoo"],
697}
698// binbar gets overridden by binfoo1
699// therefore, libbar should not be installed
700cc_binary {
701 name: "binbar",
702 shared_libs: ["libbar"]
703}
704cc_library {
705 name: "libbar",
706}
707 `)
708
709 partition := result.ModuleForTests("myfilesystem", "android_common")
710 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
Colin Cross386afeb2024-11-13 15:20:13 -0800711 android.AssertDeepEquals(t, "Shared library dep of overridden binary should not be installed",
712 "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",
713 fileList)
Spandan Das6c2b01d2024-10-22 22:16:04 +0000714}
Spandan Das92631882024-10-28 22:49:38 +0000715
716func TestInstallLinkerConfigFile(t *testing.T) {
717 result := fixture.RunTestWithBp(t, `
718android_filesystem {
719 name: "myfilesystem",
720 deps: ["libfoo_has_no_stubs", "libfoo_has_stubs"],
Spandan Das2047a4c2024-11-11 21:24:58 +0000721 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900722 gen_linker_config: true,
723 linker_config_srcs: ["linker.config.json"],
Spandan Das173256b2024-10-31 19:59:30 +0000724 },
Spandan Das918191e2024-10-31 18:27:23 +0000725 partition_type: "vendor",
Spandan Das92631882024-10-28 22:49:38 +0000726}
727cc_library {
728 name: "libfoo_has_no_stubs",
Spandan Das918191e2024-10-31 18:27:23 +0000729 vendor: true,
Spandan Das92631882024-10-28 22:49:38 +0000730}
731cc_library {
732 name: "libfoo_has_stubs",
733 stubs: {symbol_file: "libfoo.map.txt"},
Spandan Das918191e2024-10-31 18:27:23 +0000734 vendor: true,
Spandan Das92631882024-10-28 22:49:38 +0000735}
736 `)
737
738 linkerConfigCmd := result.ModuleForTests("myfilesystem", "android_common").Rule("build_filesystem_image").RuleParams.Command
Spandan Das918191e2024-10-31 18:27:23 +0000739 android.AssertStringDoesContain(t, "Could not find linker.config.json file in cmd", linkerConfigCmd, "conv_linker_config proto --force -s linker.config.json")
740 android.AssertStringDoesContain(t, "Could not find stub in `provideLibs`", linkerConfigCmd, "--key provideLibs --value libfoo_has_stubs.so")
Spandan Das92631882024-10-28 22:49:38 +0000741}
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000742
743// override_android_* modules implicitly override their base module.
744// If both of these are listed in `deps`, the base module should not be installed.
745func TestOverrideModulesInDeps(t *testing.T) {
746 result := fixture.RunTestWithBp(t, `
747 android_filesystem {
748 name: "myfilesystem",
749 deps: ["myapp", "myoverrideapp"],
750 }
751
752 android_app {
753 name: "myapp",
754 platform_apis: true,
755 }
756 override_android_app {
757 name: "myoverrideapp",
758 base: "myapp",
759 }
760 `)
761
762 partition := result.ModuleForTests("myfilesystem", "android_common")
763 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
764 android.AssertStringEquals(t, "filesystem with override app", "app/myoverrideapp/myoverrideapp.apk\n", fileList)
765}
Jihoon Kang6c03c8e2024-11-18 21:30:22 +0000766
767func TestRamdiskPartitionSetsDevNodes(t *testing.T) {
768 result := android.GroupFixturePreparers(
769 fixture,
770 android.FixtureMergeMockFs(android.MockFS{
771 "ramdisk_node_list": nil,
772 }),
773 ).RunTestWithBp(t, `
774 android_filesystem {
775 name: "ramdisk_filesystem",
776 partition_name: "ramdisk",
777 }
778 filegroup {
779 name: "ramdisk_node_list",
780 srcs: ["ramdisk_node_list"],
781 }
782 `)
783
784 android.AssertBoolEquals(
785 t,
786 "Generated ramdisk image expected to depend on \"ramdisk_node_list\" module",
787 true,
788 java.CheckModuleHasDependency(t, result.TestContext, "ramdisk_filesystem", "android_common", "ramdisk_node_list"),
789 )
790}