blob: e57e45cb6ac79e99328c39d9c9ac6dda06a318f6 [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"
Colin Cross90607e92025-02-11 14:58:07 -0800121 result.ModuleForTests(t, "myfilesystem", "android_common").Output("myfilesystem.img")
Jiyong Park06c4cdc2024-02-16 15:35:03 +0900122
Colin Cross90607e92025-02-11 14:58:07 -0800123 fs := result.ModuleForTests(t, "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
139func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) {
140 result := fixture.RunTestWithBp(t, `
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900141 android_system_image {
Jiyong Parkfa616132021-04-20 11:36:40 +0900142 name: "myfilesystem",
Kiyoung Kim67118212024-11-07 13:23:44 +0900143 base_dir: "system",
Jiyong Parkfa616132021-04-20 11:36:40 +0900144 deps: [
145 "libfoo",
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900146 "libbar",
Jiyong Parkfa616132021-04-20 11:36:40 +0900147 ],
Spandan Das2047a4c2024-11-11 21:24:58 +0000148 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900149 gen_linker_config: true,
150 linker_config_srcs: ["linker.config.json"],
151 },
Jiyong Parkfa616132021-04-20 11:36:40 +0900152 }
153
154 cc_library {
155 name: "libfoo",
156 stubs: {
157 symbol_file: "libfoo.map.txt",
158 },
159 }
160
161 cc_library {
162 name: "libbar",
163 }
164 `)
165
Colin Cross90607e92025-02-11 14:58:07 -0800166 module := result.ModuleForTests(t, "myfilesystem", "android_common")
Cole Faustfee27012024-12-13 14:10:31 -0800167 output := module.Output("out/soong/.intermediates/myfilesystem/android_common/linker.config.pb")
Jiyong Parkfa616132021-04-20 11:36:40 +0900168
Cole Faustfee27012024-12-13 14:10:31 -0800169 linkerConfigCommand := output.RuleParams.Command
Cole Faustd7556eb2024-12-02 13:18:58 -0800170
Jiyong Parkfa616132021-04-20 11:36:40 +0900171 android.AssertStringDoesContain(t, "linker.config.pb should have libfoo",
Cole Faustd7556eb2024-12-02 13:18:58 -0800172 linkerConfigCommand, "libfoo.so")
Jiyong Parkfa616132021-04-20 11:36:40 +0900173 android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar",
Cole Faustd7556eb2024-12-02 13:18:58 -0800174 linkerConfigCommand, "libbar.so")
Jiyong Parkfa616132021-04-20 11:36:40 +0900175}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900176
177func registerComponent(ctx android.RegistrationContext) {
178 ctx.RegisterModuleType("component", componentFactory)
179}
180
181func componentFactory() android.Module {
182 m := &component{}
183 m.AddProperties(&m.properties)
184 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
185 return m
186}
187
188type component struct {
189 android.ModuleBase
190 properties struct {
191 Install_copy_in_data []string
192 }
193}
194
195func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) {
196 output := android.PathForModuleOut(ctx, c.Name())
197 dir := android.PathForModuleInstall(ctx, "components")
198 ctx.InstallFile(dir, c.Name(), output)
199
200 dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components")
201 for _, d := range c.properties.Install_copy_in_data {
202 ctx.InstallFile(dataDir, d, output)
203 }
204}
205
206func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) {
207 f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent))
208 result := f.RunTestWithBp(t, `
209 android_system_image {
210 name: "myfilesystem",
211 multilib: {
212 common: {
213 deps: ["foo"],
214 },
215 },
Spandan Das2047a4c2024-11-11 21:24:58 +0000216 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900217 gen_linker_config: true,
218 linker_config_srcs: ["linker.config.json"],
219 },
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900220 }
221 component {
222 name: "foo",
223 install_copy_in_data: ["bar"],
224 }
225 `)
226
Colin Cross90607e92025-02-11 14:58:07 -0800227 module := result.ModuleForTests(t, "myfilesystem", "android_common").Module().(*systemImage)
Spandan Das978f4532024-12-05 21:05:43 +0000228 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 +0900229}
Jiyong Parkbc485482022-11-15 22:31:49 +0900230
Alice Wang000e3a32023-01-03 16:11:20 +0000231func TestAvbGenVbmetaImage(t *testing.T) {
232 result := fixture.RunTestWithBp(t, `
233 avb_gen_vbmeta_image {
234 name: "input_hashdesc",
235 src: "input.img",
236 partition_name: "input_partition_name",
237 salt: "2222",
238 }`)
Colin Cross90607e92025-02-11 14:58:07 -0800239 cmd := result.ModuleForTests(t, "input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command
Alice Wang000e3a32023-01-03 16:11:20 +0000240 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
241 cmd, "--partition_name input_partition_name")
242 android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image",
243 cmd, "--do_not_append_vbmeta_image")
244 android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image",
245 cmd, "--output_vbmeta_image ")
246 android.AssertStringDoesContain(t, "Can't find --salt argument",
247 cmd, "--salt 2222")
248}
249
Jiyong Parkbc485482022-11-15 22:31:49 +0900250func TestAvbAddHashFooter(t *testing.T) {
251 result := fixture.RunTestWithBp(t, `
Alice Wang000e3a32023-01-03 16:11:20 +0000252 avb_gen_vbmeta_image {
253 name: "input_hashdesc",
254 src: "input.img",
255 partition_name: "input",
256 salt: "2222",
257 }
258
Jiyong Parkbc485482022-11-15 22:31:49 +0900259 avb_add_hash_footer {
260 name: "myfooter",
261 src: "input.img",
262 filename: "output.img",
263 partition_name: "mypartition",
264 private_key: "mykey",
265 salt: "1111",
266 props: [
267 {
268 name: "prop1",
269 value: "value1",
270 },
271 {
272 name: "prop2",
273 file: "value_file",
274 },
275 ],
Alice Wang000e3a32023-01-03 16:11:20 +0000276 include_descriptors_from_images: ["input_hashdesc"],
Jiyong Parkbc485482022-11-15 22:31:49 +0900277 }
278 `)
Colin Cross90607e92025-02-11 14:58:07 -0800279 cmd := result.ModuleForTests(t, "myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command
Jiyong Parkbc485482022-11-15 22:31:49 +0900280 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
281 cmd, "--partition_name mypartition")
282 android.AssertStringDoesContain(t, "Can't find correct --key argument",
283 cmd, "--key mykey")
284 android.AssertStringDoesContain(t, "Can't find --salt argument",
285 cmd, "--salt 1111")
286 android.AssertStringDoesContain(t, "Can't find --prop argument",
287 cmd, "--prop 'prop1:value1'")
288 android.AssertStringDoesContain(t, "Can't find --prop_from_file argument",
289 cmd, "--prop_from_file 'prop2:value_file'")
Alice Wang000e3a32023-01-03 16:11:20 +0000290 android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image",
291 cmd, "--include_descriptors_from_image ")
Jiyong Parkbc485482022-11-15 22:31:49 +0900292}
Jooyung Han54f78052023-02-20 18:17:47 +0900293
Jooyung Hane6067592023-03-16 13:11:17 +0900294func TestFileSystemWithCoverageVariants(t *testing.T) {
295 context := android.GroupFixturePreparers(
296 fixture,
297 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
298 variables.GcovCoverage = proptools.BoolPtr(true)
299 variables.Native_coverage = proptools.BoolPtr(true)
300 }),
301 )
302
303 result := context.RunTestWithBp(t, `
304 prebuilt_etc {
305 name: "prebuilt",
306 src: ":myfilesystem",
307 }
308
309 android_system_image {
310 name: "myfilesystem",
311 deps: [
312 "libfoo",
313 ],
Spandan Das2047a4c2024-11-11 21:24:58 +0000314 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900315 gen_linker_config: true,
316 linker_config_srcs: ["linker.config.json"],
317 },
Jooyung Hane6067592023-03-16 13:11:17 +0900318 }
319
320 cc_library {
321 name: "libfoo",
322 shared_libs: [
323 "libbar",
324 ],
325 stl: "none",
326 }
327
328 cc_library {
329 name: "libbar",
330 stl: "none",
331 }
332 `)
333
Colin Cross90607e92025-02-11 14:58:07 -0800334 filesystem := result.ModuleForTests(t, "myfilesystem", "android_common_cov")
Spandan Das5ef1a9c2025-02-11 18:50:17 +0000335 inputs := filesystem.Output("staging_dir.timestamp").Implicits
Jooyung Hane6067592023-03-16 13:11:17 +0900336 android.AssertStringListContains(t, "filesystem should have libfoo(cov)",
337 inputs.Strings(),
338 "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so")
339 android.AssertStringListContains(t, "filesystem should have libbar(cov)",
340 inputs.Strings(),
341 "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared_cov/libbar.so")
342
Spandan Das1f0a5a12025-01-15 00:53:15 +0000343 filesystemOutput := filesystem.OutputFiles(result.TestContext, t, "")[0]
Colin Cross90607e92025-02-11 14:58:07 -0800344 prebuiltInput := result.ModuleForTests(t, "prebuilt", "android_arm64_armv8-a").Rule("Cp").Input
Jooyung Hane6067592023-03-16 13:11:17 +0900345 if filesystemOutput != prebuiltInput {
346 t.Error("prebuilt should use cov variant of filesystem")
347 }
348}
Jiyong Parkeaac8232024-03-31 21:27:45 +0900349
350func TestSystemImageDefaults(t *testing.T) {
351 result := fixture.RunTestWithBp(t, `
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900352 android_filesystem_defaults {
Jiyong Parkeaac8232024-03-31 21:27:45 +0900353 name: "defaults",
354 multilib: {
355 common: {
356 deps: [
357 "phony",
358 ],
359 },
360 lib64: {
361 deps: [
362 "libbar",
363 ],
364 },
365 },
366 compile_multilib: "both",
367 }
368
369 android_system_image {
370 name: "system",
371 defaults: ["defaults"],
372 multilib: {
373 lib32: {
374 deps: [
375 "foo",
376 "libbar",
377 ],
378 },
379 },
380 }
381
382 cc_binary {
383 name: "foo",
384 compile_multilib: "prefer32",
385 }
386
387 cc_library {
388 name: "libbar",
389 required: ["libbaz"],
390 }
391
392 cc_library {
393 name: "libbaz",
394 }
395
396 phony {
397 name: "phony",
398 required: ["libquz"],
399 }
400
401 cc_library {
402 name: "libquz",
403 }
404 `)
405
Colin Cross90607e92025-02-11 14:58:07 -0800406 fs := result.ModuleForTests(t, "system", "android_common").Module().(*systemImage)
Jiyong Parkeaac8232024-03-31 21:27:45 +0900407 expected := []string{
408 "bin/foo",
409 "lib/libbar.so",
410 "lib64/libbar.so",
411 "lib64/libbaz.so",
412 "lib64/libquz.so",
413 }
414 for _, e := range expected {
415 android.AssertStringListContains(t, "missing entry", fs.entries, e)
416 }
417}
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900418
419func TestInconsistentPartitionTypesInDefaults(t *testing.T) {
420 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
421 "doesn't match with the partition type")).
422 RunTestWithBp(t, `
423 android_filesystem_defaults {
424 name: "system_ext_def",
425 partition_type: "system_ext",
426 }
427
428 android_filesystem_defaults {
429 name: "system_def",
430 partition_type: "system",
431 defaults: ["system_ext_def"],
432 }
433
434 android_system_image {
435 name: "system",
436 defaults: ["system_def"],
437 }
438 `)
439}
Jiyong Park16ef7ac2024-05-01 12:36:10 +0000440
441func TestPreventDuplicatedEntries(t *testing.T) {
442 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
443 "packaging conflict at")).
444 RunTestWithBp(t, `
445 android_filesystem {
446 name: "fs",
447 deps: [
448 "foo",
449 "foo_dup",
450 ],
451 }
452
453 cc_binary {
454 name: "foo",
455 }
456
457 cc_binary {
458 name: "foo_dup",
459 stem: "foo",
460 }
461 `)
462}
Jiyong Parkc4b1d552024-05-13 16:47:30 +0900463
464func TestTrackPhonyAsRequiredDep(t *testing.T) {
465 result := fixture.RunTestWithBp(t, `
466 android_filesystem {
467 name: "fs",
468 deps: ["foo"],
469 }
470
471 cc_binary {
472 name: "foo",
473 required: ["phony"],
474 }
475
476 phony {
477 name: "phony",
478 required: ["libbar"],
479 }
480
481 cc_library {
482 name: "libbar",
483 }
484 `)
485
Colin Cross90607e92025-02-11 14:58:07 -0800486 fs := result.ModuleForTests(t, "fs", "android_common").Module().(*filesystem)
Jiyong Parkc4b1d552024-05-13 16:47:30 +0900487 expected := []string{
488 "bin/foo",
489 "lib64/libbar.so",
490 }
491 for _, e := range expected {
492 android.AssertStringListContains(t, "missing entry", fs.entries, e)
493 }
494}
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900495
496func TestFilterOutUnsupportedArches(t *testing.T) {
497 result := fixture.RunTestWithBp(t, `
498 android_filesystem {
499 name: "fs_64_only",
500 deps: ["foo"],
501 }
502
503 android_filesystem {
504 name: "fs_64_32",
505 compile_multilib: "both",
Jiyong Park3ea9b652024-05-15 23:01:54 +0900506 deps: ["foo"],
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900507 }
508
509 cc_binary {
510 name: "foo",
511 required: ["phony"],
512 }
513
514 phony {
515 name: "phony",
516 required: [
517 "libbar",
518 "app",
519 ],
520 }
521
522 cc_library {
523 name: "libbar",
524 }
525
526 android_app {
527 name: "app",
528 srcs: ["a.java"],
529 platform_apis: true,
530 }
531 `)
532 testcases := []struct {
533 fsName string
534 expected []string
535 unexpected []string
536 }{
537 {
538 fsName: "fs_64_only",
539 expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so"},
540 unexpected: []string{"lib/libbar.so"},
541 },
542 {
543 fsName: "fs_64_32",
544 expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so", "lib/libbar.so"},
545 unexpected: []string{},
546 },
547 }
548 for _, c := range testcases {
Colin Cross90607e92025-02-11 14:58:07 -0800549 fs := result.ModuleForTests(t, c.fsName, "android_common").Module().(*filesystem)
Jiyong Parkc6a773d2024-05-14 21:49:11 +0900550 for _, e := range c.expected {
551 android.AssertStringListContains(t, "missing entry", fs.entries, e)
552 }
553 for _, e := range c.unexpected {
554 android.AssertStringListDoesNotContain(t, "unexpected entry", fs.entries, e)
555 }
556 }
557}
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000558
559func TestErofsPartition(t *testing.T) {
560 result := fixture.RunTestWithBp(t, `
561 android_filesystem {
562 name: "erofs_partition",
563 type: "erofs",
564 erofs: {
565 compressor: "lz4hc,9",
566 compress_hints: "compress_hints.txt",
567 },
568 deps: ["binfoo"],
569 }
570
571 cc_binary {
572 name: "binfoo",
573 }
574 `)
575
Colin Cross90607e92025-02-11 14:58:07 -0800576 partition := result.ModuleForTests(t, "erofs_partition", "android_common")
Cole Fauste1676122024-12-03 17:32:25 -0800577 buildImageConfig := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("prop_pre_processing"))
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000578 android.AssertStringDoesContain(t, "erofs fs type", buildImageConfig, "fs_type=erofs")
579 android.AssertStringDoesContain(t, "erofs fs type compress algorithm", buildImageConfig, "erofs_default_compressor=lz4hc,9")
580 android.AssertStringDoesContain(t, "erofs fs type compress hint", buildImageConfig, "erofs_default_compress_hints=compress_hints.txt")
581 android.AssertStringDoesContain(t, "erofs fs type sparse", buildImageConfig, "erofs_sparse_flag=-s")
582}
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000583
mrziwang1a6291f2024-11-07 14:29:25 -0800584func TestF2fsPartition(t *testing.T) {
585 result := fixture.RunTestWithBp(t, `
586 android_filesystem {
587 name: "f2fs_partition",
588 type: "f2fs",
589 }
590 `)
591
Colin Cross90607e92025-02-11 14:58:07 -0800592 partition := result.ModuleForTests(t, "f2fs_partition", "android_common")
Cole Fauste1676122024-12-03 17:32:25 -0800593 buildImageConfig := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("prop_pre_processing"))
mrziwang1a6291f2024-11-07 14:29:25 -0800594 android.AssertStringDoesContain(t, "f2fs fs type", buildImageConfig, "fs_type=f2fs")
595 android.AssertStringDoesContain(t, "f2fs fs type sparse", buildImageConfig, "f2fs_sparse_flag=-S")
596}
597
598func TestFsTypesPropertyError(t *testing.T) {
599 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
600 "erofs: erofs is non-empty, but FS type is f2fs\n. Please delete erofs properties if this partition should use f2fs\n")).
601 RunTestWithBp(t, `
602 android_filesystem {
603 name: "f2fs_partition",
604 type: "f2fs",
605 erofs: {
606 compressor: "lz4hc,9",
607 compress_hints: "compress_hints.txt",
608 },
609 }
610 `)
611}
612
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000613// If a system_ext/ module depends on system/ module, the dependency should *not*
614// be installed in system_ext/
615func TestDoNotPackageCrossPartitionDependencies(t *testing.T) {
Spandan Das6d056502024-10-21 15:40:32 +0000616 t.Skip() // TODO (spandandas): Re-enable this
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000617 result := fixture.RunTestWithBp(t, `
618 android_filesystem {
619 name: "myfilesystem",
620 deps: ["binfoo"],
621 partition_type: "system_ext",
622 }
623
624 cc_binary {
625 name: "binfoo",
626 shared_libs: ["libfoo"],
627 system_ext_specific: true,
628 }
629 cc_library_shared {
630 name: "libfoo", // installed in system/
631 }
632 `)
633
Colin Cross90607e92025-02-11 14:58:07 -0800634 partition := result.ModuleForTests(t, "myfilesystem", "android_common")
Hugo Drumond Jacob69d829a2024-10-21 09:55:45 +0000635 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
636 android.AssertDeepEquals(t, "filesystem with dependencies on different partition", "bin/binfoo\n", fileList)
637}
Spandan Das405f2d42024-10-22 18:31:25 +0000638
639// If a cc_library is listed in `deps`, and it has a shared and static variant, then the shared variant
640// should be installed.
641func TestUseSharedVariationOfNativeLib(t *testing.T) {
642 result := fixture.RunTestWithBp(t, `
643 android_filesystem {
644 name: "myfilesystem",
645 deps: ["libfoo"],
646 }
647 // cc_library will create a static and shared variant.
648 cc_library {
649 name: "libfoo",
650 }
651 `)
652
Colin Cross90607e92025-02-11 14:58:07 -0800653 partition := result.ModuleForTests(t, "myfilesystem", "android_common")
Spandan Das405f2d42024-10-22 18:31:25 +0000654 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
Colin Cross386afeb2024-11-13 15:20:13 -0800655 android.AssertDeepEquals(t, "cc_library listed in deps",
656 "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",
657 fileList)
Spandan Das405f2d42024-10-22 18:31:25 +0000658}
Spandan Das6c2b01d2024-10-22 22:16:04 +0000659
660// binfoo1 overrides binbar. transitive deps of binbar should not be installed.
661func TestDoNotInstallTransitiveDepOfOverriddenModule(t *testing.T) {
662 result := fixture.RunTestWithBp(t, `
663android_filesystem {
664 name: "myfilesystem",
665 deps: ["binfoo1", "libfoo2", "binbar"],
666}
667cc_binary {
668 name: "binfoo1",
669 shared_libs: ["libfoo"],
670 overrides: ["binbar"],
671}
672cc_library {
673 name: "libfoo",
674}
675cc_library {
676 name: "libfoo2",
677 overrides: ["libfoo"],
678}
679// binbar gets overridden by binfoo1
680// therefore, libbar should not be installed
681cc_binary {
682 name: "binbar",
683 shared_libs: ["libbar"]
684}
685cc_library {
686 name: "libbar",
687}
688 `)
689
Colin Cross90607e92025-02-11 14:58:07 -0800690 partition := result.ModuleForTests(t, "myfilesystem", "android_common")
Spandan Das6c2b01d2024-10-22 22:16:04 +0000691 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
Colin Cross386afeb2024-11-13 15:20:13 -0800692 android.AssertDeepEquals(t, "Shared library dep of overridden binary should not be installed",
693 "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",
694 fileList)
Spandan Das6c2b01d2024-10-22 22:16:04 +0000695}
Spandan Das92631882024-10-28 22:49:38 +0000696
697func TestInstallLinkerConfigFile(t *testing.T) {
698 result := fixture.RunTestWithBp(t, `
699android_filesystem {
700 name: "myfilesystem",
701 deps: ["libfoo_has_no_stubs", "libfoo_has_stubs"],
Spandan Das2047a4c2024-11-11 21:24:58 +0000702 linker_config: {
Kiyoung Kim67118212024-11-07 13:23:44 +0900703 gen_linker_config: true,
704 linker_config_srcs: ["linker.config.json"],
Spandan Das173256b2024-10-31 19:59:30 +0000705 },
Spandan Das918191e2024-10-31 18:27:23 +0000706 partition_type: "vendor",
Spandan Das92631882024-10-28 22:49:38 +0000707}
708cc_library {
709 name: "libfoo_has_no_stubs",
Spandan Das918191e2024-10-31 18:27:23 +0000710 vendor: true,
Spandan Das92631882024-10-28 22:49:38 +0000711}
712cc_library {
713 name: "libfoo_has_stubs",
714 stubs: {symbol_file: "libfoo.map.txt"},
Spandan Das918191e2024-10-31 18:27:23 +0000715 vendor: true,
Spandan Das92631882024-10-28 22:49:38 +0000716}
717 `)
718
Colin Cross90607e92025-02-11 14:58:07 -0800719 linkerConfigCmd := result.ModuleForTests(t, "myfilesystem", "android_common").Output("out/soong/.intermediates/myfilesystem/android_common/linker.config.pb").RuleParams.Command
Spandan Das918191e2024-10-31 18:27:23 +0000720 android.AssertStringDoesContain(t, "Could not find linker.config.json file in cmd", linkerConfigCmd, "conv_linker_config proto --force -s linker.config.json")
721 android.AssertStringDoesContain(t, "Could not find stub in `provideLibs`", linkerConfigCmd, "--key provideLibs --value libfoo_has_stubs.so")
Spandan Das92631882024-10-28 22:49:38 +0000722}
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000723
724// override_android_* modules implicitly override their base module.
725// If both of these are listed in `deps`, the base module should not be installed.
Inseob Kim0c67c8e2025-03-14 18:33:55 +0900726// Also, required deps should be updated too.
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000727func TestOverrideModulesInDeps(t *testing.T) {
728 result := fixture.RunTestWithBp(t, `
Inseob Kim0c67c8e2025-03-14 18:33:55 +0900729 cc_library_shared {
730 name: "libfoo",
731 stl: "none",
732 system_shared_libs: [],
733 }
734 cc_library_shared {
735 name: "libbar",
736 stl: "none",
737 system_shared_libs: [],
738 }
Inseob Kim76150492025-03-20 10:46:06 +0900739 phony {
740 name: "myapp_phony",
741 required: ["myapp"],
Inseob Kim0c67c8e2025-03-14 18:33:55 +0900742 }
Inseob Kim76150492025-03-20 10:46:06 +0900743 phony {
744 name: "myoverrideapp_phony",
745 required: ["myoverrideapp"],
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000746 }
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000747 android_app {
748 name: "myapp",
749 platform_apis: true,
Inseob Kim0c67c8e2025-03-14 18:33:55 +0900750 required: ["libfoo"],
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000751 }
752 override_android_app {
753 name: "myoverrideapp",
754 base: "myapp",
Inseob Kim0c67c8e2025-03-14 18:33:55 +0900755 required: ["libbar"],
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000756 }
Inseob Kim76150492025-03-20 10:46:06 +0900757 android_filesystem {
758 name: "myfilesystem",
759 deps: ["myapp"],
760 }
761 android_filesystem {
762 name: "myfilesystem_overridden",
763 deps: ["myapp", "myoverrideapp"],
764 }
765 android_filesystem {
766 name: "myfilesystem_overridden_indirect",
767 deps: ["myapp_phony", "myoverrideapp_phony"],
768 }
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000769 `)
770
Colin Cross90607e92025-02-11 14:58:07 -0800771 partition := result.ModuleForTests(t, "myfilesystem", "android_common")
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000772 fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
Inseob Kim0c67c8e2025-03-14 18:33:55 +0900773 android.AssertStringEquals(t, "filesystem without override app", "app/myapp/myapp.apk\nlib64/libfoo.so\n", fileList)
774
Inseob Kim76150492025-03-20 10:46:06 +0900775 for _, overridden := range []string{"myfilesystem_overridden", "myfilesystem_overridden_indirect"} {
776 overriddenPartition := result.ModuleForTests(t, overridden, "android_common")
777 overriddenFileList := android.ContentFromFileRuleForTests(t, result.TestContext, overriddenPartition.Output("fileList"))
778 android.AssertStringEquals(t, "filesystem with "+overridden, "app/myoverrideapp/myoverrideapp.apk\nlib64/libbar.so\n", overriddenFileList)
779 }
Spandan Dasc1ded7e2024-11-01 00:52:33 +0000780}
Jihoon Kang6c03c8e2024-11-18 21:30:22 +0000781
782func TestRamdiskPartitionSetsDevNodes(t *testing.T) {
783 result := android.GroupFixturePreparers(
784 fixture,
785 android.FixtureMergeMockFs(android.MockFS{
786 "ramdisk_node_list": nil,
787 }),
788 ).RunTestWithBp(t, `
789 android_filesystem {
790 name: "ramdisk_filesystem",
791 partition_name: "ramdisk",
792 }
793 filegroup {
794 name: "ramdisk_node_list",
795 srcs: ["ramdisk_node_list"],
796 }
797 `)
798
799 android.AssertBoolEquals(
800 t,
801 "Generated ramdisk image expected to depend on \"ramdisk_node_list\" module",
802 true,
803 java.CheckModuleHasDependency(t, result.TestContext, "ramdisk_filesystem", "android_common", "ramdisk_node_list"),
804 )
805}