Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package filesystem |
| 16 | |
| 17 | import ( |
| 18 | "os" |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 19 | "path/filepath" |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 20 | "testing" |
| 21 | |
| 22 | "android/soong/android" |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 23 | "android/soong/bpf" |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 24 | "android/soong/cc" |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 25 | "android/soong/etc" |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 26 | "android/soong/phony" |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 27 | |
| 28 | "github.com/google/blueprint/proptools" |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 29 | ) |
| 30 | |
| 31 | func TestMain(m *testing.M) { |
| 32 | os.Exit(m.Run()) |
| 33 | } |
| 34 | |
| 35 | var fixture = android.GroupFixturePreparers( |
| 36 | android.PrepareForIntegrationTestWithAndroid, |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 37 | bpf.PrepareForTestWithBpf, |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 38 | etc.PrepareForTestWithPrebuiltEtc, |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 39 | cc.PrepareForIntegrationTestWithCc, |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 40 | phony.PrepareForTestWithPhony, |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 41 | PrepareForTestWithFilesystemBuildComponents, |
| 42 | ) |
| 43 | |
| 44 | func TestFileSystemDeps(t *testing.T) { |
| 45 | result := fixture.RunTestWithBp(t, ` |
| 46 | android_filesystem { |
| 47 | name: "myfilesystem", |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 48 | multilib: { |
| 49 | common: { |
| 50 | deps: [ |
| 51 | "bpf.o", |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 52 | "phony", |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 53 | ], |
| 54 | }, |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 55 | lib32: { |
| 56 | deps: [ |
| 57 | "foo", |
| 58 | "libbar", |
| 59 | ], |
| 60 | }, |
| 61 | lib64: { |
| 62 | deps: [ |
| 63 | "libbar", |
| 64 | ], |
| 65 | }, |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 66 | }, |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 67 | compile_multilib: "both", |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | bpf { |
| 71 | name: "bpf.o", |
| 72 | srcs: ["bpf.c"], |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 73 | } |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 74 | |
| 75 | cc_binary { |
| 76 | name: "foo", |
| 77 | compile_multilib: "prefer32", |
| 78 | } |
| 79 | |
| 80 | cc_library { |
| 81 | name: "libbar", |
Jiyong Park | 8bcf3c6 | 2024-03-18 18:37:10 +0900 | [diff] [blame] | 82 | required: ["libbaz"], |
| 83 | } |
| 84 | |
| 85 | cc_library { |
| 86 | name: "libbaz", |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 87 | } |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 88 | |
| 89 | phony { |
| 90 | name: "phony", |
| 91 | required: ["libquz"], |
| 92 | } |
| 93 | |
| 94 | cc_library { |
| 95 | name: "libquz", |
| 96 | } |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 97 | `) |
| 98 | |
| 99 | // produces "myfilesystem.img" |
| 100 | result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img") |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 101 | |
| 102 | fs := result.ModuleForTests("myfilesystem", "android_common").Module().(*filesystem) |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 103 | expected := []string{ |
| 104 | "bin/foo", |
| 105 | "lib/libbar.so", |
| 106 | "lib64/libbar.so", |
Jiyong Park | 8bcf3c6 | 2024-03-18 18:37:10 +0900 | [diff] [blame] | 107 | "lib64/libbaz.so", |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 108 | "lib64/libquz.so", |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 109 | "etc/bpf/bpf.o", |
| 110 | } |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 111 | for _, e := range expected { |
| 112 | android.AssertStringListContains(t, "missing entry", fs.entries, e) |
| 113 | } |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 114 | } |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 115 | |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 116 | func TestIncludeMakeBuiltFiles(t *testing.T) { |
| 117 | result := fixture.RunTestWithBp(t, ` |
| 118 | android_filesystem { |
| 119 | name: "myfilesystem", |
| 120 | include_make_built_files: "system", |
| 121 | } |
| 122 | `) |
| 123 | |
| 124 | output := result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img") |
| 125 | |
| 126 | stampFile := filepath.Join(result.Config.OutDir(), "target/product/test_device/obj/PACKAGING/system_intermediates/staging_dir.stamp") |
| 127 | fileListFile := filepath.Join(result.Config.OutDir(), "target/product/test_device/obj/PACKAGING/system_intermediates/file_list.txt") |
| 128 | android.AssertStringListContains(t, "deps of filesystem must include the staging dir stamp file", output.Implicits.Strings(), stampFile) |
| 129 | android.AssertStringListContains(t, "deps of filesystem must include the staging dir file list", output.Implicits.Strings(), fileListFile) |
| 130 | } |
| 131 | |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 132 | func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) { |
| 133 | result := fixture.RunTestWithBp(t, ` |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 134 | android_system_image { |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 135 | name: "myfilesystem", |
| 136 | deps: [ |
| 137 | "libfoo", |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 138 | "libbar", |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 139 | ], |
| 140 | linker_config_src: "linker.config.json", |
| 141 | } |
| 142 | |
| 143 | cc_library { |
| 144 | name: "libfoo", |
| 145 | stubs: { |
| 146 | symbol_file: "libfoo.map.txt", |
| 147 | }, |
| 148 | } |
| 149 | |
| 150 | cc_library { |
| 151 | name: "libbar", |
| 152 | } |
| 153 | `) |
| 154 | |
| 155 | module := result.ModuleForTests("myfilesystem", "android_common") |
| 156 | output := module.Output("system/etc/linker.config.pb") |
| 157 | |
| 158 | android.AssertStringDoesContain(t, "linker.config.pb should have libfoo", |
| 159 | output.RuleParams.Command, "libfoo.so") |
| 160 | android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar", |
| 161 | output.RuleParams.Command, "libbar.so") |
| 162 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 163 | |
| 164 | func registerComponent(ctx android.RegistrationContext) { |
| 165 | ctx.RegisterModuleType("component", componentFactory) |
| 166 | } |
| 167 | |
| 168 | func componentFactory() android.Module { |
| 169 | m := &component{} |
| 170 | m.AddProperties(&m.properties) |
| 171 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 172 | return m |
| 173 | } |
| 174 | |
| 175 | type component struct { |
| 176 | android.ModuleBase |
| 177 | properties struct { |
| 178 | Install_copy_in_data []string |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 183 | output := android.PathForModuleOut(ctx, c.Name()) |
| 184 | dir := android.PathForModuleInstall(ctx, "components") |
| 185 | ctx.InstallFile(dir, c.Name(), output) |
| 186 | |
| 187 | dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components") |
| 188 | for _, d := range c.properties.Install_copy_in_data { |
| 189 | ctx.InstallFile(dataDir, d, output) |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) { |
| 194 | f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent)) |
| 195 | result := f.RunTestWithBp(t, ` |
| 196 | android_system_image { |
| 197 | name: "myfilesystem", |
| 198 | multilib: { |
| 199 | common: { |
| 200 | deps: ["foo"], |
| 201 | }, |
| 202 | }, |
| 203 | linker_config_src: "linker.config.json", |
| 204 | } |
| 205 | component { |
| 206 | name: "foo", |
| 207 | install_copy_in_data: ["bar"], |
| 208 | } |
| 209 | `) |
| 210 | |
| 211 | module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage) |
| 212 | android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries) |
| 213 | } |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 214 | |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 215 | func TestAvbGenVbmetaImage(t *testing.T) { |
| 216 | result := fixture.RunTestWithBp(t, ` |
| 217 | avb_gen_vbmeta_image { |
| 218 | name: "input_hashdesc", |
| 219 | src: "input.img", |
| 220 | partition_name: "input_partition_name", |
| 221 | salt: "2222", |
| 222 | }`) |
| 223 | cmd := result.ModuleForTests("input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command |
| 224 | android.AssertStringDoesContain(t, "Can't find correct --partition_name argument", |
| 225 | cmd, "--partition_name input_partition_name") |
| 226 | android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image", |
| 227 | cmd, "--do_not_append_vbmeta_image") |
| 228 | android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image", |
| 229 | cmd, "--output_vbmeta_image ") |
| 230 | android.AssertStringDoesContain(t, "Can't find --salt argument", |
| 231 | cmd, "--salt 2222") |
| 232 | } |
| 233 | |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 234 | func TestAvbAddHashFooter(t *testing.T) { |
| 235 | result := fixture.RunTestWithBp(t, ` |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 236 | avb_gen_vbmeta_image { |
| 237 | name: "input_hashdesc", |
| 238 | src: "input.img", |
| 239 | partition_name: "input", |
| 240 | salt: "2222", |
| 241 | } |
| 242 | |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 243 | avb_add_hash_footer { |
| 244 | name: "myfooter", |
| 245 | src: "input.img", |
| 246 | filename: "output.img", |
| 247 | partition_name: "mypartition", |
| 248 | private_key: "mykey", |
| 249 | salt: "1111", |
| 250 | props: [ |
| 251 | { |
| 252 | name: "prop1", |
| 253 | value: "value1", |
| 254 | }, |
| 255 | { |
| 256 | name: "prop2", |
| 257 | file: "value_file", |
| 258 | }, |
| 259 | ], |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 260 | include_descriptors_from_images: ["input_hashdesc"], |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 261 | } |
| 262 | `) |
| 263 | cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command |
| 264 | android.AssertStringDoesContain(t, "Can't find correct --partition_name argument", |
| 265 | cmd, "--partition_name mypartition") |
| 266 | android.AssertStringDoesContain(t, "Can't find correct --key argument", |
| 267 | cmd, "--key mykey") |
| 268 | android.AssertStringDoesContain(t, "Can't find --salt argument", |
| 269 | cmd, "--salt 1111") |
| 270 | android.AssertStringDoesContain(t, "Can't find --prop argument", |
| 271 | cmd, "--prop 'prop1:value1'") |
| 272 | android.AssertStringDoesContain(t, "Can't find --prop_from_file argument", |
| 273 | cmd, "--prop_from_file 'prop2:value_file'") |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 274 | android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image", |
| 275 | cmd, "--include_descriptors_from_image ") |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 276 | } |
Jooyung Han | 54f7805 | 2023-02-20 18:17:47 +0900 | [diff] [blame] | 277 | |
| 278 | func TestFileSystemShouldInstallCoreVariantIfTargetBuildAppsIsSet(t *testing.T) { |
| 279 | context := android.GroupFixturePreparers( |
| 280 | fixture, |
| 281 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 282 | variables.Unbundled_build_apps = []string{"bar"} |
| 283 | }), |
| 284 | ) |
| 285 | result := context.RunTestWithBp(t, ` |
| 286 | android_system_image { |
| 287 | name: "myfilesystem", |
| 288 | deps: [ |
| 289 | "libfoo", |
| 290 | ], |
| 291 | linker_config_src: "linker.config.json", |
| 292 | } |
| 293 | |
| 294 | cc_library { |
| 295 | name: "libfoo", |
| 296 | shared_libs: [ |
| 297 | "libbar", |
| 298 | ], |
| 299 | stl: "none", |
| 300 | } |
| 301 | |
| 302 | cc_library { |
| 303 | name: "libbar", |
| 304 | sdk_version: "9", |
| 305 | stl: "none", |
| 306 | } |
| 307 | `) |
| 308 | |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 309 | inputs := result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img").Implicits |
Jooyung Han | 54f7805 | 2023-02-20 18:17:47 +0900 | [diff] [blame] | 310 | android.AssertStringListContains(t, "filesystem should have libbar even for unbundled build", |
| 311 | inputs.Strings(), |
| 312 | "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so") |
| 313 | } |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 314 | |
| 315 | func TestFileSystemWithCoverageVariants(t *testing.T) { |
| 316 | context := android.GroupFixturePreparers( |
| 317 | fixture, |
| 318 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 319 | variables.GcovCoverage = proptools.BoolPtr(true) |
| 320 | variables.Native_coverage = proptools.BoolPtr(true) |
| 321 | }), |
| 322 | ) |
| 323 | |
| 324 | result := context.RunTestWithBp(t, ` |
| 325 | prebuilt_etc { |
| 326 | name: "prebuilt", |
| 327 | src: ":myfilesystem", |
| 328 | } |
| 329 | |
| 330 | android_system_image { |
| 331 | name: "myfilesystem", |
| 332 | deps: [ |
| 333 | "libfoo", |
| 334 | ], |
| 335 | linker_config_src: "linker.config.json", |
| 336 | } |
| 337 | |
| 338 | cc_library { |
| 339 | name: "libfoo", |
| 340 | shared_libs: [ |
| 341 | "libbar", |
| 342 | ], |
| 343 | stl: "none", |
| 344 | } |
| 345 | |
| 346 | cc_library { |
| 347 | name: "libbar", |
| 348 | stl: "none", |
| 349 | } |
| 350 | `) |
| 351 | |
| 352 | filesystem := result.ModuleForTests("myfilesystem", "android_common_cov") |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 353 | inputs := filesystem.Output("myfilesystem.img").Implicits |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 354 | android.AssertStringListContains(t, "filesystem should have libfoo(cov)", |
| 355 | inputs.Strings(), |
| 356 | "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so") |
| 357 | android.AssertStringListContains(t, "filesystem should have libbar(cov)", |
| 358 | inputs.Strings(), |
| 359 | "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared_cov/libbar.so") |
| 360 | |
| 361 | filesystemOutput := filesystem.Output("myfilesystem.img").Output |
| 362 | prebuiltInput := result.ModuleForTests("prebuilt", "android_arm64_armv8-a").Rule("Cp").Input |
| 363 | if filesystemOutput != prebuiltInput { |
| 364 | t.Error("prebuilt should use cov variant of filesystem") |
| 365 | } |
| 366 | } |