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" |
| 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 22 | "android/soong/bpf" |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 23 | "android/soong/cc" |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 24 | "android/soong/etc" |
Jiyong Park | 73e5bab | 2024-04-05 13:37:21 +0900 | [diff] [blame] | 25 | "android/soong/java" |
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 | 73e5bab | 2024-04-05 13:37:21 +0900 | [diff] [blame] | 37 | android.PrepareForTestWithAndroidBuildComponents, |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 38 | bpf.PrepareForTestWithBpf, |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 39 | cc.PrepareForIntegrationTestWithCc, |
Jiyong Park | 73e5bab | 2024-04-05 13:37:21 +0900 | [diff] [blame] | 40 | etc.PrepareForTestWithPrebuiltEtc, |
| 41 | java.PrepareForTestWithJavaBuildComponents, |
| 42 | java.PrepareForTestWithJavaDefaultModules, |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 43 | phony.PrepareForTestWithPhony, |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 44 | PrepareForTestWithFilesystemBuildComponents, |
| 45 | ) |
| 46 | |
| 47 | func TestFileSystemDeps(t *testing.T) { |
| 48 | result := fixture.RunTestWithBp(t, ` |
| 49 | android_filesystem { |
| 50 | name: "myfilesystem", |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 51 | multilib: { |
| 52 | common: { |
| 53 | deps: [ |
| 54 | "bpf.o", |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 55 | "phony", |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 56 | ], |
| 57 | }, |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 58 | lib32: { |
| 59 | deps: [ |
| 60 | "foo", |
| 61 | "libbar", |
| 62 | ], |
| 63 | }, |
| 64 | lib64: { |
| 65 | deps: [ |
| 66 | "libbar", |
| 67 | ], |
| 68 | }, |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 69 | }, |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 70 | compile_multilib: "both", |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | bpf { |
| 74 | name: "bpf.o", |
| 75 | srcs: ["bpf.c"], |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 76 | } |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 77 | |
| 78 | cc_binary { |
| 79 | name: "foo", |
| 80 | compile_multilib: "prefer32", |
| 81 | } |
| 82 | |
| 83 | cc_library { |
| 84 | name: "libbar", |
Jiyong Park | 8bcf3c6 | 2024-03-18 18:37:10 +0900 | [diff] [blame] | 85 | required: ["libbaz"], |
Jiyong Park | f21dd65 | 2024-04-17 05:22:37 +0000 | [diff] [blame] | 86 | target: { |
| 87 | platform: { |
| 88 | required: ["lib_platform_only"], |
| 89 | }, |
| 90 | }, |
Jiyong Park | 8bcf3c6 | 2024-03-18 18:37:10 +0900 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | cc_library { |
| 94 | name: "libbaz", |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 95 | } |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 96 | |
Jiyong Park | f21dd65 | 2024-04-17 05:22:37 +0000 | [diff] [blame] | 97 | cc_library { |
| 98 | name: "lib_platform_only", |
| 99 | } |
| 100 | |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 101 | phony { |
| 102 | name: "phony", |
Jiyong Park | 73e5bab | 2024-04-05 13:37:21 +0900 | [diff] [blame] | 103 | required: [ |
| 104 | "libquz", |
| 105 | "myapp", |
| 106 | ], |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | cc_library { |
| 110 | name: "libquz", |
| 111 | } |
Jiyong Park | 73e5bab | 2024-04-05 13:37:21 +0900 | [diff] [blame] | 112 | |
| 113 | android_app { |
| 114 | name: "myapp", |
| 115 | platform_apis: true, |
| 116 | installable: true, |
| 117 | } |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 118 | `) |
| 119 | |
| 120 | // produces "myfilesystem.img" |
| 121 | result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img") |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 122 | |
| 123 | fs := result.ModuleForTests("myfilesystem", "android_common").Module().(*filesystem) |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 124 | expected := []string{ |
Jiyong Park | 73e5bab | 2024-04-05 13:37:21 +0900 | [diff] [blame] | 125 | "app/myapp/myapp.apk", |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 126 | "bin/foo", |
| 127 | "lib/libbar.so", |
| 128 | "lib64/libbar.so", |
Jiyong Park | 8bcf3c6 | 2024-03-18 18:37:10 +0900 | [diff] [blame] | 129 | "lib64/libbaz.so", |
Jiyong Park | 9c540c8 | 2024-03-26 10:48:27 +0900 | [diff] [blame] | 130 | "lib64/libquz.so", |
Jiyong Park | f21dd65 | 2024-04-17 05:22:37 +0000 | [diff] [blame] | 131 | "lib64/lib_platform_only.so", |
Jiyong Park | eec7c38 | 2024-02-16 16:10:13 +0900 | [diff] [blame] | 132 | "etc/bpf/bpf.o", |
| 133 | } |
Jiyong Park | 06c4cdc | 2024-02-16 15:35:03 +0900 | [diff] [blame] | 134 | for _, e := range expected { |
| 135 | android.AssertStringListContains(t, "missing entry", fs.entries, e) |
| 136 | } |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 137 | } |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 138 | |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 139 | func TestIncludeMakeBuiltFiles(t *testing.T) { |
| 140 | result := fixture.RunTestWithBp(t, ` |
| 141 | android_filesystem { |
| 142 | name: "myfilesystem", |
| 143 | include_make_built_files: "system", |
| 144 | } |
| 145 | `) |
| 146 | |
| 147 | output := result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img") |
| 148 | |
Colin Cross | 3b1c684 | 2024-07-26 11:52:57 -0700 | [diff] [blame^] | 149 | stampFile := "out/target/product/test_device/obj/PACKAGING/system_intermediates/staging_dir.stamp" |
| 150 | fileListFile := "out/target/product/test_device/obj/PACKAGING/system_intermediates/file_list.txt" |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 151 | android.AssertStringListContains(t, "deps of filesystem must include the staging dir stamp file", output.Implicits.Strings(), stampFile) |
| 152 | android.AssertStringListContains(t, "deps of filesystem must include the staging dir file list", output.Implicits.Strings(), fileListFile) |
| 153 | } |
| 154 | |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 155 | func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) { |
| 156 | result := fixture.RunTestWithBp(t, ` |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 157 | android_system_image { |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 158 | name: "myfilesystem", |
| 159 | deps: [ |
| 160 | "libfoo", |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 161 | "libbar", |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 162 | ], |
| 163 | linker_config_src: "linker.config.json", |
| 164 | } |
| 165 | |
| 166 | cc_library { |
| 167 | name: "libfoo", |
| 168 | stubs: { |
| 169 | symbol_file: "libfoo.map.txt", |
| 170 | }, |
| 171 | } |
| 172 | |
| 173 | cc_library { |
| 174 | name: "libbar", |
| 175 | } |
| 176 | `) |
| 177 | |
| 178 | module := result.ModuleForTests("myfilesystem", "android_common") |
| 179 | output := module.Output("system/etc/linker.config.pb") |
| 180 | |
| 181 | android.AssertStringDoesContain(t, "linker.config.pb should have libfoo", |
| 182 | output.RuleParams.Command, "libfoo.so") |
| 183 | android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar", |
| 184 | output.RuleParams.Command, "libbar.so") |
| 185 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 186 | |
| 187 | func registerComponent(ctx android.RegistrationContext) { |
| 188 | ctx.RegisterModuleType("component", componentFactory) |
| 189 | } |
| 190 | |
| 191 | func componentFactory() android.Module { |
| 192 | m := &component{} |
| 193 | m.AddProperties(&m.properties) |
| 194 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 195 | return m |
| 196 | } |
| 197 | |
| 198 | type component struct { |
| 199 | android.ModuleBase |
| 200 | properties struct { |
| 201 | Install_copy_in_data []string |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 206 | output := android.PathForModuleOut(ctx, c.Name()) |
| 207 | dir := android.PathForModuleInstall(ctx, "components") |
| 208 | ctx.InstallFile(dir, c.Name(), output) |
| 209 | |
| 210 | dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components") |
| 211 | for _, d := range c.properties.Install_copy_in_data { |
| 212 | ctx.InstallFile(dataDir, d, output) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) { |
| 217 | f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent)) |
| 218 | result := f.RunTestWithBp(t, ` |
| 219 | android_system_image { |
| 220 | name: "myfilesystem", |
| 221 | multilib: { |
| 222 | common: { |
| 223 | deps: ["foo"], |
| 224 | }, |
| 225 | }, |
| 226 | linker_config_src: "linker.config.json", |
| 227 | } |
| 228 | component { |
| 229 | name: "foo", |
| 230 | install_copy_in_data: ["bar"], |
| 231 | } |
| 232 | `) |
| 233 | |
| 234 | module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage) |
| 235 | android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries) |
| 236 | } |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 237 | |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 238 | func TestAvbGenVbmetaImage(t *testing.T) { |
| 239 | result := fixture.RunTestWithBp(t, ` |
| 240 | avb_gen_vbmeta_image { |
| 241 | name: "input_hashdesc", |
| 242 | src: "input.img", |
| 243 | partition_name: "input_partition_name", |
| 244 | salt: "2222", |
| 245 | }`) |
| 246 | cmd := result.ModuleForTests("input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command |
| 247 | android.AssertStringDoesContain(t, "Can't find correct --partition_name argument", |
| 248 | cmd, "--partition_name input_partition_name") |
| 249 | android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image", |
| 250 | cmd, "--do_not_append_vbmeta_image") |
| 251 | android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image", |
| 252 | cmd, "--output_vbmeta_image ") |
| 253 | android.AssertStringDoesContain(t, "Can't find --salt argument", |
| 254 | cmd, "--salt 2222") |
| 255 | } |
| 256 | |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 257 | func TestAvbAddHashFooter(t *testing.T) { |
| 258 | result := fixture.RunTestWithBp(t, ` |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 259 | avb_gen_vbmeta_image { |
| 260 | name: "input_hashdesc", |
| 261 | src: "input.img", |
| 262 | partition_name: "input", |
| 263 | salt: "2222", |
| 264 | } |
| 265 | |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 266 | avb_add_hash_footer { |
| 267 | name: "myfooter", |
| 268 | src: "input.img", |
| 269 | filename: "output.img", |
| 270 | partition_name: "mypartition", |
| 271 | private_key: "mykey", |
| 272 | salt: "1111", |
| 273 | props: [ |
| 274 | { |
| 275 | name: "prop1", |
| 276 | value: "value1", |
| 277 | }, |
| 278 | { |
| 279 | name: "prop2", |
| 280 | file: "value_file", |
| 281 | }, |
| 282 | ], |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 283 | include_descriptors_from_images: ["input_hashdesc"], |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 284 | } |
| 285 | `) |
| 286 | cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command |
| 287 | android.AssertStringDoesContain(t, "Can't find correct --partition_name argument", |
| 288 | cmd, "--partition_name mypartition") |
| 289 | android.AssertStringDoesContain(t, "Can't find correct --key argument", |
| 290 | cmd, "--key mykey") |
| 291 | android.AssertStringDoesContain(t, "Can't find --salt argument", |
| 292 | cmd, "--salt 1111") |
| 293 | android.AssertStringDoesContain(t, "Can't find --prop argument", |
| 294 | cmd, "--prop 'prop1:value1'") |
| 295 | android.AssertStringDoesContain(t, "Can't find --prop_from_file argument", |
| 296 | cmd, "--prop_from_file 'prop2:value_file'") |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 297 | android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image", |
| 298 | cmd, "--include_descriptors_from_image ") |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 299 | } |
Jooyung Han | 54f7805 | 2023-02-20 18:17:47 +0900 | [diff] [blame] | 300 | |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 301 | func TestFileSystemWithCoverageVariants(t *testing.T) { |
| 302 | context := android.GroupFixturePreparers( |
| 303 | fixture, |
| 304 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 305 | variables.GcovCoverage = proptools.BoolPtr(true) |
| 306 | variables.Native_coverage = proptools.BoolPtr(true) |
| 307 | }), |
| 308 | ) |
| 309 | |
| 310 | result := context.RunTestWithBp(t, ` |
| 311 | prebuilt_etc { |
| 312 | name: "prebuilt", |
| 313 | src: ":myfilesystem", |
| 314 | } |
| 315 | |
| 316 | android_system_image { |
| 317 | name: "myfilesystem", |
| 318 | deps: [ |
| 319 | "libfoo", |
| 320 | ], |
| 321 | linker_config_src: "linker.config.json", |
| 322 | } |
| 323 | |
| 324 | cc_library { |
| 325 | name: "libfoo", |
| 326 | shared_libs: [ |
| 327 | "libbar", |
| 328 | ], |
| 329 | stl: "none", |
| 330 | } |
| 331 | |
| 332 | cc_library { |
| 333 | name: "libbar", |
| 334 | stl: "none", |
| 335 | } |
| 336 | `) |
| 337 | |
| 338 | filesystem := result.ModuleForTests("myfilesystem", "android_common_cov") |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 339 | inputs := filesystem.Output("myfilesystem.img").Implicits |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 340 | android.AssertStringListContains(t, "filesystem should have libfoo(cov)", |
| 341 | inputs.Strings(), |
| 342 | "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so") |
| 343 | android.AssertStringListContains(t, "filesystem should have libbar(cov)", |
| 344 | inputs.Strings(), |
| 345 | "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared_cov/libbar.so") |
| 346 | |
| 347 | filesystemOutput := filesystem.Output("myfilesystem.img").Output |
| 348 | prebuiltInput := result.ModuleForTests("prebuilt", "android_arm64_armv8-a").Rule("Cp").Input |
| 349 | if filesystemOutput != prebuiltInput { |
| 350 | t.Error("prebuilt should use cov variant of filesystem") |
| 351 | } |
| 352 | } |
Jiyong Park | eaac823 | 2024-03-31 21:27:45 +0900 | [diff] [blame] | 353 | |
| 354 | func TestSystemImageDefaults(t *testing.T) { |
| 355 | result := fixture.RunTestWithBp(t, ` |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 356 | android_filesystem_defaults { |
Jiyong Park | eaac823 | 2024-03-31 21:27:45 +0900 | [diff] [blame] | 357 | name: "defaults", |
| 358 | multilib: { |
| 359 | common: { |
| 360 | deps: [ |
| 361 | "phony", |
| 362 | ], |
| 363 | }, |
| 364 | lib64: { |
| 365 | deps: [ |
| 366 | "libbar", |
| 367 | ], |
| 368 | }, |
| 369 | }, |
| 370 | compile_multilib: "both", |
| 371 | } |
| 372 | |
| 373 | android_system_image { |
| 374 | name: "system", |
| 375 | defaults: ["defaults"], |
| 376 | multilib: { |
| 377 | lib32: { |
| 378 | deps: [ |
| 379 | "foo", |
| 380 | "libbar", |
| 381 | ], |
| 382 | }, |
| 383 | }, |
| 384 | } |
| 385 | |
| 386 | cc_binary { |
| 387 | name: "foo", |
| 388 | compile_multilib: "prefer32", |
| 389 | } |
| 390 | |
| 391 | cc_library { |
| 392 | name: "libbar", |
| 393 | required: ["libbaz"], |
| 394 | } |
| 395 | |
| 396 | cc_library { |
| 397 | name: "libbaz", |
| 398 | } |
| 399 | |
| 400 | phony { |
| 401 | name: "phony", |
| 402 | required: ["libquz"], |
| 403 | } |
| 404 | |
| 405 | cc_library { |
| 406 | name: "libquz", |
| 407 | } |
| 408 | `) |
| 409 | |
| 410 | fs := result.ModuleForTests("system", "android_common").Module().(*systemImage) |
| 411 | expected := []string{ |
| 412 | "bin/foo", |
| 413 | "lib/libbar.so", |
| 414 | "lib64/libbar.so", |
| 415 | "lib64/libbaz.so", |
| 416 | "lib64/libquz.so", |
| 417 | } |
| 418 | for _, e := range expected { |
| 419 | android.AssertStringListContains(t, "missing entry", fs.entries, e) |
| 420 | } |
| 421 | } |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 422 | |
| 423 | func TestInconsistentPartitionTypesInDefaults(t *testing.T) { |
| 424 | fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern( |
| 425 | "doesn't match with the partition type")). |
| 426 | RunTestWithBp(t, ` |
| 427 | android_filesystem_defaults { |
| 428 | name: "system_ext_def", |
| 429 | partition_type: "system_ext", |
| 430 | } |
| 431 | |
| 432 | android_filesystem_defaults { |
| 433 | name: "system_def", |
| 434 | partition_type: "system", |
| 435 | defaults: ["system_ext_def"], |
| 436 | } |
| 437 | |
| 438 | android_system_image { |
| 439 | name: "system", |
| 440 | defaults: ["system_def"], |
| 441 | } |
| 442 | `) |
| 443 | } |
Jiyong Park | 16ef7ac | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 444 | |
| 445 | func TestPreventDuplicatedEntries(t *testing.T) { |
| 446 | fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern( |
| 447 | "packaging conflict at")). |
| 448 | RunTestWithBp(t, ` |
| 449 | android_filesystem { |
| 450 | name: "fs", |
| 451 | deps: [ |
| 452 | "foo", |
| 453 | "foo_dup", |
| 454 | ], |
| 455 | } |
| 456 | |
| 457 | cc_binary { |
| 458 | name: "foo", |
| 459 | } |
| 460 | |
| 461 | cc_binary { |
| 462 | name: "foo_dup", |
| 463 | stem: "foo", |
| 464 | } |
| 465 | `) |
| 466 | } |
Jiyong Park | c4b1d55 | 2024-05-13 16:47:30 +0900 | [diff] [blame] | 467 | |
| 468 | func TestTrackPhonyAsRequiredDep(t *testing.T) { |
| 469 | result := fixture.RunTestWithBp(t, ` |
| 470 | android_filesystem { |
| 471 | name: "fs", |
| 472 | deps: ["foo"], |
| 473 | } |
| 474 | |
| 475 | cc_binary { |
| 476 | name: "foo", |
| 477 | required: ["phony"], |
| 478 | } |
| 479 | |
| 480 | phony { |
| 481 | name: "phony", |
| 482 | required: ["libbar"], |
| 483 | } |
| 484 | |
| 485 | cc_library { |
| 486 | name: "libbar", |
| 487 | } |
| 488 | `) |
| 489 | |
| 490 | fs := result.ModuleForTests("fs", "android_common").Module().(*filesystem) |
| 491 | expected := []string{ |
| 492 | "bin/foo", |
| 493 | "lib64/libbar.so", |
| 494 | } |
| 495 | for _, e := range expected { |
| 496 | android.AssertStringListContains(t, "missing entry", fs.entries, e) |
| 497 | } |
| 498 | } |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 499 | |
| 500 | func TestFilterOutUnsupportedArches(t *testing.T) { |
| 501 | result := fixture.RunTestWithBp(t, ` |
| 502 | android_filesystem { |
| 503 | name: "fs_64_only", |
| 504 | deps: ["foo"], |
| 505 | } |
| 506 | |
| 507 | android_filesystem { |
| 508 | name: "fs_64_32", |
| 509 | compile_multilib: "both", |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 510 | deps: ["foo"], |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | cc_binary { |
| 514 | name: "foo", |
| 515 | required: ["phony"], |
| 516 | } |
| 517 | |
| 518 | phony { |
| 519 | name: "phony", |
| 520 | required: [ |
| 521 | "libbar", |
| 522 | "app", |
| 523 | ], |
| 524 | } |
| 525 | |
| 526 | cc_library { |
| 527 | name: "libbar", |
| 528 | } |
| 529 | |
| 530 | android_app { |
| 531 | name: "app", |
| 532 | srcs: ["a.java"], |
| 533 | platform_apis: true, |
| 534 | } |
| 535 | `) |
| 536 | testcases := []struct { |
| 537 | fsName string |
| 538 | expected []string |
| 539 | unexpected []string |
| 540 | }{ |
| 541 | { |
| 542 | fsName: "fs_64_only", |
| 543 | expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so"}, |
| 544 | unexpected: []string{"lib/libbar.so"}, |
| 545 | }, |
| 546 | { |
| 547 | fsName: "fs_64_32", |
| 548 | expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so", "lib/libbar.so"}, |
| 549 | unexpected: []string{}, |
| 550 | }, |
| 551 | } |
| 552 | for _, c := range testcases { |
| 553 | fs := result.ModuleForTests(c.fsName, "android_common").Module().(*filesystem) |
| 554 | for _, e := range c.expected { |
| 555 | android.AssertStringListContains(t, "missing entry", fs.entries, e) |
| 556 | } |
| 557 | for _, e := range c.unexpected { |
| 558 | android.AssertStringListDoesNotContain(t, "unexpected entry", fs.entries, e) |
| 559 | } |
| 560 | } |
| 561 | } |