blob: 3a5071d34b2d10ad627bbb6c33d0899574a26d42 [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 Faust4a2a7c92024-03-12 12:44:40 -070019 "path/filepath"
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
150 stampFile := filepath.Join(result.Config.OutDir(), "target/product/test_device/obj/PACKAGING/system_intermediates/staging_dir.stamp")
151 fileListFile := filepath.Join(result.Config.OutDir(), "target/product/test_device/obj/PACKAGING/system_intermediates/file_list.txt")
152 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",
160 deps: [
161 "libfoo",
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900162 "libbar",
Jiyong Parkfa616132021-04-20 11:36:40 +0900163 ],
164 linker_config_src: "linker.config.json",
165 }
166
167 cc_library {
168 name: "libfoo",
169 stubs: {
170 symbol_file: "libfoo.map.txt",
171 },
172 }
173
174 cc_library {
175 name: "libbar",
176 }
177 `)
178
179 module := result.ModuleForTests("myfilesystem", "android_common")
180 output := module.Output("system/etc/linker.config.pb")
181
182 android.AssertStringDoesContain(t, "linker.config.pb should have libfoo",
183 output.RuleParams.Command, "libfoo.so")
184 android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar",
185 output.RuleParams.Command, "libbar.so")
186}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900187
188func registerComponent(ctx android.RegistrationContext) {
189 ctx.RegisterModuleType("component", componentFactory)
190}
191
192func componentFactory() android.Module {
193 m := &component{}
194 m.AddProperties(&m.properties)
195 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
196 return m
197}
198
199type component struct {
200 android.ModuleBase
201 properties struct {
202 Install_copy_in_data []string
203 }
204}
205
206func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) {
207 output := android.PathForModuleOut(ctx, c.Name())
208 dir := android.PathForModuleInstall(ctx, "components")
209 ctx.InstallFile(dir, c.Name(), output)
210
211 dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components")
212 for _, d := range c.properties.Install_copy_in_data {
213 ctx.InstallFile(dataDir, d, output)
214 }
215}
216
217func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) {
218 f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent))
219 result := f.RunTestWithBp(t, `
220 android_system_image {
221 name: "myfilesystem",
222 multilib: {
223 common: {
224 deps: ["foo"],
225 },
226 },
227 linker_config_src: "linker.config.json",
228 }
229 component {
230 name: "foo",
231 install_copy_in_data: ["bar"],
232 }
233 `)
234
235 module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage)
236 android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries)
237}
Jiyong Parkbc485482022-11-15 22:31:49 +0900238
Alice Wang000e3a32023-01-03 16:11:20 +0000239func TestAvbGenVbmetaImage(t *testing.T) {
240 result := fixture.RunTestWithBp(t, `
241 avb_gen_vbmeta_image {
242 name: "input_hashdesc",
243 src: "input.img",
244 partition_name: "input_partition_name",
245 salt: "2222",
246 }`)
247 cmd := result.ModuleForTests("input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command
248 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
249 cmd, "--partition_name input_partition_name")
250 android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image",
251 cmd, "--do_not_append_vbmeta_image")
252 android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image",
253 cmd, "--output_vbmeta_image ")
254 android.AssertStringDoesContain(t, "Can't find --salt argument",
255 cmd, "--salt 2222")
256}
257
Jiyong Parkbc485482022-11-15 22:31:49 +0900258func TestAvbAddHashFooter(t *testing.T) {
259 result := fixture.RunTestWithBp(t, `
Alice Wang000e3a32023-01-03 16:11:20 +0000260 avb_gen_vbmeta_image {
261 name: "input_hashdesc",
262 src: "input.img",
263 partition_name: "input",
264 salt: "2222",
265 }
266
Jiyong Parkbc485482022-11-15 22:31:49 +0900267 avb_add_hash_footer {
268 name: "myfooter",
269 src: "input.img",
270 filename: "output.img",
271 partition_name: "mypartition",
272 private_key: "mykey",
273 salt: "1111",
274 props: [
275 {
276 name: "prop1",
277 value: "value1",
278 },
279 {
280 name: "prop2",
281 file: "value_file",
282 },
283 ],
Alice Wang000e3a32023-01-03 16:11:20 +0000284 include_descriptors_from_images: ["input_hashdesc"],
Jiyong Parkbc485482022-11-15 22:31:49 +0900285 }
286 `)
287 cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command
288 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
289 cmd, "--partition_name mypartition")
290 android.AssertStringDoesContain(t, "Can't find correct --key argument",
291 cmd, "--key mykey")
292 android.AssertStringDoesContain(t, "Can't find --salt argument",
293 cmd, "--salt 1111")
294 android.AssertStringDoesContain(t, "Can't find --prop argument",
295 cmd, "--prop 'prop1:value1'")
296 android.AssertStringDoesContain(t, "Can't find --prop_from_file argument",
297 cmd, "--prop_from_file 'prop2:value_file'")
Alice Wang000e3a32023-01-03 16:11:20 +0000298 android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image",
299 cmd, "--include_descriptors_from_image ")
Jiyong Parkbc485482022-11-15 22:31:49 +0900300}
Jooyung Han54f78052023-02-20 18:17:47 +0900301
302func TestFileSystemShouldInstallCoreVariantIfTargetBuildAppsIsSet(t *testing.T) {
303 context := android.GroupFixturePreparers(
304 fixture,
305 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
306 variables.Unbundled_build_apps = []string{"bar"}
307 }),
308 )
309 result := context.RunTestWithBp(t, `
310 android_system_image {
311 name: "myfilesystem",
312 deps: [
313 "libfoo",
314 ],
315 linker_config_src: "linker.config.json",
316 }
317
318 cc_library {
319 name: "libfoo",
320 shared_libs: [
321 "libbar",
322 ],
323 stl: "none",
324 }
325
326 cc_library {
327 name: "libbar",
328 sdk_version: "9",
329 stl: "none",
330 }
331 `)
332
Cole Faust3b806d32024-03-11 15:15:03 -0700333 inputs := result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img").Implicits
Jooyung Han54f78052023-02-20 18:17:47 +0900334 android.AssertStringListContains(t, "filesystem should have libbar even for unbundled build",
335 inputs.Strings(),
336 "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so")
337}
Jooyung Hane6067592023-03-16 13:11:17 +0900338
339func TestFileSystemWithCoverageVariants(t *testing.T) {
340 context := android.GroupFixturePreparers(
341 fixture,
342 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
343 variables.GcovCoverage = proptools.BoolPtr(true)
344 variables.Native_coverage = proptools.BoolPtr(true)
345 }),
346 )
347
348 result := context.RunTestWithBp(t, `
349 prebuilt_etc {
350 name: "prebuilt",
351 src: ":myfilesystem",
352 }
353
354 android_system_image {
355 name: "myfilesystem",
356 deps: [
357 "libfoo",
358 ],
359 linker_config_src: "linker.config.json",
360 }
361
362 cc_library {
363 name: "libfoo",
364 shared_libs: [
365 "libbar",
366 ],
367 stl: "none",
368 }
369
370 cc_library {
371 name: "libbar",
372 stl: "none",
373 }
374 `)
375
376 filesystem := result.ModuleForTests("myfilesystem", "android_common_cov")
Cole Faust3b806d32024-03-11 15:15:03 -0700377 inputs := filesystem.Output("myfilesystem.img").Implicits
Jooyung Hane6067592023-03-16 13:11:17 +0900378 android.AssertStringListContains(t, "filesystem should have libfoo(cov)",
379 inputs.Strings(),
380 "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so")
381 android.AssertStringListContains(t, "filesystem should have libbar(cov)",
382 inputs.Strings(),
383 "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared_cov/libbar.so")
384
385 filesystemOutput := filesystem.Output("myfilesystem.img").Output
386 prebuiltInput := result.ModuleForTests("prebuilt", "android_arm64_armv8-a").Rule("Cp").Input
387 if filesystemOutput != prebuiltInput {
388 t.Error("prebuilt should use cov variant of filesystem")
389 }
390}
Jiyong Parkeaac8232024-03-31 21:27:45 +0900391
392func TestSystemImageDefaults(t *testing.T) {
393 result := fixture.RunTestWithBp(t, `
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900394 android_filesystem_defaults {
Jiyong Parkeaac8232024-03-31 21:27:45 +0900395 name: "defaults",
396 multilib: {
397 common: {
398 deps: [
399 "phony",
400 ],
401 },
402 lib64: {
403 deps: [
404 "libbar",
405 ],
406 },
407 },
408 compile_multilib: "both",
409 }
410
411 android_system_image {
412 name: "system",
413 defaults: ["defaults"],
414 multilib: {
415 lib32: {
416 deps: [
417 "foo",
418 "libbar",
419 ],
420 },
421 },
422 }
423
424 cc_binary {
425 name: "foo",
426 compile_multilib: "prefer32",
427 }
428
429 cc_library {
430 name: "libbar",
431 required: ["libbaz"],
432 }
433
434 cc_library {
435 name: "libbaz",
436 }
437
438 phony {
439 name: "phony",
440 required: ["libquz"],
441 }
442
443 cc_library {
444 name: "libquz",
445 }
446 `)
447
448 fs := result.ModuleForTests("system", "android_common").Module().(*systemImage)
449 expected := []string{
450 "bin/foo",
451 "lib/libbar.so",
452 "lib64/libbar.so",
453 "lib64/libbaz.so",
454 "lib64/libquz.so",
455 }
456 for _, e := range expected {
457 android.AssertStringListContains(t, "missing entry", fs.entries, e)
458 }
459}
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900460
461func TestInconsistentPartitionTypesInDefaults(t *testing.T) {
462 fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
463 "doesn't match with the partition type")).
464 RunTestWithBp(t, `
465 android_filesystem_defaults {
466 name: "system_ext_def",
467 partition_type: "system_ext",
468 }
469
470 android_filesystem_defaults {
471 name: "system_def",
472 partition_type: "system",
473 defaults: ["system_ext_def"],
474 }
475
476 android_system_image {
477 name: "system",
478 defaults: ["system_def"],
479 }
480 `)
481}