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