blob: 7547ff8190de3f985d8553b71ffaa622dd67fb40 [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"
25
26 "github.com/google/blueprint/proptools"
Jooyung Han9706cbc2021-04-15 22:43:48 +090027)
28
29func TestMain(m *testing.M) {
30 os.Exit(m.Run())
31}
32
33var fixture = android.GroupFixturePreparers(
34 android.PrepareForIntegrationTestWithAndroid,
Jiyong Park06c4cdc2024-02-16 15:35:03 +090035 bpf.PrepareForTestWithBpf,
Jooyung Hane6067592023-03-16 13:11:17 +090036 etc.PrepareForTestWithPrebuiltEtc,
Jiyong Parkfa616132021-04-20 11:36:40 +090037 cc.PrepareForIntegrationTestWithCc,
Jooyung Han9706cbc2021-04-15 22:43:48 +090038 PrepareForTestWithFilesystemBuildComponents,
39)
40
41func TestFileSystemDeps(t *testing.T) {
42 result := fixture.RunTestWithBp(t, `
43 android_filesystem {
44 name: "myfilesystem",
Jiyong Park06c4cdc2024-02-16 15:35:03 +090045 multilib: {
46 common: {
47 deps: [
48 "bpf.o",
49 ],
50 },
51 },
52 }
53
54 bpf {
55 name: "bpf.o",
56 srcs: ["bpf.c"],
Jooyung Han9706cbc2021-04-15 22:43:48 +090057 }
58 `)
59
60 // produces "myfilesystem.img"
61 result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img")
Jiyong Park06c4cdc2024-02-16 15:35:03 +090062
63 fs := result.ModuleForTests("myfilesystem", "android_common").Module().(*filesystem)
64 expected := []string{"etc/bpf/bpf.o"}
65 for _, e := range expected {
66 android.AssertStringListContains(t, "missing entry", fs.entries, e)
67 }
Jooyung Han9706cbc2021-04-15 22:43:48 +090068}
Jiyong Parkfa616132021-04-20 11:36:40 +090069
70func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) {
71 result := fixture.RunTestWithBp(t, `
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090072 android_system_image {
Jiyong Parkfa616132021-04-20 11:36:40 +090073 name: "myfilesystem",
74 deps: [
75 "libfoo",
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090076 "libbar",
Jiyong Parkfa616132021-04-20 11:36:40 +090077 ],
78 linker_config_src: "linker.config.json",
79 }
80
81 cc_library {
82 name: "libfoo",
83 stubs: {
84 symbol_file: "libfoo.map.txt",
85 },
86 }
87
88 cc_library {
89 name: "libbar",
90 }
91 `)
92
93 module := result.ModuleForTests("myfilesystem", "android_common")
94 output := module.Output("system/etc/linker.config.pb")
95
96 android.AssertStringDoesContain(t, "linker.config.pb should have libfoo",
97 output.RuleParams.Command, "libfoo.so")
98 android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar",
99 output.RuleParams.Command, "libbar.so")
100}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900101
102func registerComponent(ctx android.RegistrationContext) {
103 ctx.RegisterModuleType("component", componentFactory)
104}
105
106func componentFactory() android.Module {
107 m := &component{}
108 m.AddProperties(&m.properties)
109 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
110 return m
111}
112
113type component struct {
114 android.ModuleBase
115 properties struct {
116 Install_copy_in_data []string
117 }
118}
119
120func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) {
121 output := android.PathForModuleOut(ctx, c.Name())
122 dir := android.PathForModuleInstall(ctx, "components")
123 ctx.InstallFile(dir, c.Name(), output)
124
125 dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components")
126 for _, d := range c.properties.Install_copy_in_data {
127 ctx.InstallFile(dataDir, d, output)
128 }
129}
130
131func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) {
132 f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent))
133 result := f.RunTestWithBp(t, `
134 android_system_image {
135 name: "myfilesystem",
136 multilib: {
137 common: {
138 deps: ["foo"],
139 },
140 },
141 linker_config_src: "linker.config.json",
142 }
143 component {
144 name: "foo",
145 install_copy_in_data: ["bar"],
146 }
147 `)
148
149 module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage)
150 android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries)
151}
Jiyong Parkbc485482022-11-15 22:31:49 +0900152
Alice Wang000e3a32023-01-03 16:11:20 +0000153func TestAvbGenVbmetaImage(t *testing.T) {
154 result := fixture.RunTestWithBp(t, `
155 avb_gen_vbmeta_image {
156 name: "input_hashdesc",
157 src: "input.img",
158 partition_name: "input_partition_name",
159 salt: "2222",
160 }`)
161 cmd := result.ModuleForTests("input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command
162 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
163 cmd, "--partition_name input_partition_name")
164 android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image",
165 cmd, "--do_not_append_vbmeta_image")
166 android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image",
167 cmd, "--output_vbmeta_image ")
168 android.AssertStringDoesContain(t, "Can't find --salt argument",
169 cmd, "--salt 2222")
170}
171
Jiyong Parkbc485482022-11-15 22:31:49 +0900172func TestAvbAddHashFooter(t *testing.T) {
173 result := fixture.RunTestWithBp(t, `
Alice Wang000e3a32023-01-03 16:11:20 +0000174 avb_gen_vbmeta_image {
175 name: "input_hashdesc",
176 src: "input.img",
177 partition_name: "input",
178 salt: "2222",
179 }
180
Jiyong Parkbc485482022-11-15 22:31:49 +0900181 avb_add_hash_footer {
182 name: "myfooter",
183 src: "input.img",
184 filename: "output.img",
185 partition_name: "mypartition",
186 private_key: "mykey",
187 salt: "1111",
188 props: [
189 {
190 name: "prop1",
191 value: "value1",
192 },
193 {
194 name: "prop2",
195 file: "value_file",
196 },
197 ],
Alice Wang000e3a32023-01-03 16:11:20 +0000198 include_descriptors_from_images: ["input_hashdesc"],
Jiyong Parkbc485482022-11-15 22:31:49 +0900199 }
200 `)
201 cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command
202 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
203 cmd, "--partition_name mypartition")
204 android.AssertStringDoesContain(t, "Can't find correct --key argument",
205 cmd, "--key mykey")
206 android.AssertStringDoesContain(t, "Can't find --salt argument",
207 cmd, "--salt 1111")
208 android.AssertStringDoesContain(t, "Can't find --prop argument",
209 cmd, "--prop 'prop1:value1'")
210 android.AssertStringDoesContain(t, "Can't find --prop_from_file argument",
211 cmd, "--prop_from_file 'prop2:value_file'")
Alice Wang000e3a32023-01-03 16:11:20 +0000212 android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image",
213 cmd, "--include_descriptors_from_image ")
Jiyong Parkbc485482022-11-15 22:31:49 +0900214}
Jooyung Han54f78052023-02-20 18:17:47 +0900215
216func TestFileSystemShouldInstallCoreVariantIfTargetBuildAppsIsSet(t *testing.T) {
217 context := android.GroupFixturePreparers(
218 fixture,
219 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
220 variables.Unbundled_build_apps = []string{"bar"}
221 }),
222 )
223 result := context.RunTestWithBp(t, `
224 android_system_image {
225 name: "myfilesystem",
226 deps: [
227 "libfoo",
228 ],
229 linker_config_src: "linker.config.json",
230 }
231
232 cc_library {
233 name: "libfoo",
234 shared_libs: [
235 "libbar",
236 ],
237 stl: "none",
238 }
239
240 cc_library {
241 name: "libbar",
242 sdk_version: "9",
243 stl: "none",
244 }
245 `)
246
247 inputs := result.ModuleForTests("myfilesystem", "android_common").Output("deps.zip").Implicits
248 android.AssertStringListContains(t, "filesystem should have libbar even for unbundled build",
249 inputs.Strings(),
250 "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so")
251}
Jooyung Hane6067592023-03-16 13:11:17 +0900252
253func TestFileSystemWithCoverageVariants(t *testing.T) {
254 context := android.GroupFixturePreparers(
255 fixture,
256 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
257 variables.GcovCoverage = proptools.BoolPtr(true)
258 variables.Native_coverage = proptools.BoolPtr(true)
259 }),
260 )
261
262 result := context.RunTestWithBp(t, `
263 prebuilt_etc {
264 name: "prebuilt",
265 src: ":myfilesystem",
266 }
267
268 android_system_image {
269 name: "myfilesystem",
270 deps: [
271 "libfoo",
272 ],
273 linker_config_src: "linker.config.json",
274 }
275
276 cc_library {
277 name: "libfoo",
278 shared_libs: [
279 "libbar",
280 ],
281 stl: "none",
282 }
283
284 cc_library {
285 name: "libbar",
286 stl: "none",
287 }
288 `)
289
290 filesystem := result.ModuleForTests("myfilesystem", "android_common_cov")
291 inputs := filesystem.Output("deps.zip").Implicits
292 android.AssertStringListContains(t, "filesystem should have libfoo(cov)",
293 inputs.Strings(),
294 "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so")
295 android.AssertStringListContains(t, "filesystem should have libbar(cov)",
296 inputs.Strings(),
297 "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared_cov/libbar.so")
298
299 filesystemOutput := filesystem.Output("myfilesystem.img").Output
300 prebuiltInput := result.ModuleForTests("prebuilt", "android_arm64_armv8-a").Rule("Cp").Input
301 if filesystemOutput != prebuiltInput {
302 t.Error("prebuilt should use cov variant of filesystem")
303 }
304}