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", |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 159 | base_dir: "system", |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 160 | deps: [ |
| 161 | "libfoo", |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 162 | "libbar", |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 163 | ], |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 164 | linker_config: { |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 165 | gen_linker_config: true, |
| 166 | linker_config_srcs: ["linker.config.json"], |
| 167 | }, |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | cc_library { |
| 171 | name: "libfoo", |
| 172 | stubs: { |
| 173 | symbol_file: "libfoo.map.txt", |
| 174 | }, |
| 175 | } |
| 176 | |
| 177 | cc_library { |
| 178 | name: "libbar", |
| 179 | } |
| 180 | `) |
| 181 | |
| 182 | module := result.ModuleForTests("myfilesystem", "android_common") |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 183 | output := module.Output("out/soong/.intermediates/myfilesystem/android_common/root/system/etc/linker.config.pb") |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 184 | |
| 185 | android.AssertStringDoesContain(t, "linker.config.pb should have libfoo", |
| 186 | output.RuleParams.Command, "libfoo.so") |
| 187 | android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar", |
| 188 | output.RuleParams.Command, "libbar.so") |
| 189 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 190 | |
| 191 | func registerComponent(ctx android.RegistrationContext) { |
| 192 | ctx.RegisterModuleType("component", componentFactory) |
| 193 | } |
| 194 | |
| 195 | func componentFactory() android.Module { |
| 196 | m := &component{} |
| 197 | m.AddProperties(&m.properties) |
| 198 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 199 | return m |
| 200 | } |
| 201 | |
| 202 | type component struct { |
| 203 | android.ModuleBase |
| 204 | properties struct { |
| 205 | Install_copy_in_data []string |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 210 | output := android.PathForModuleOut(ctx, c.Name()) |
| 211 | dir := android.PathForModuleInstall(ctx, "components") |
| 212 | ctx.InstallFile(dir, c.Name(), output) |
| 213 | |
| 214 | dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components") |
| 215 | for _, d := range c.properties.Install_copy_in_data { |
| 216 | ctx.InstallFile(dataDir, d, output) |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) { |
| 221 | f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent)) |
| 222 | result := f.RunTestWithBp(t, ` |
| 223 | android_system_image { |
| 224 | name: "myfilesystem", |
| 225 | multilib: { |
| 226 | common: { |
| 227 | deps: ["foo"], |
| 228 | }, |
| 229 | }, |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 230 | linker_config: { |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 231 | gen_linker_config: true, |
| 232 | linker_config_srcs: ["linker.config.json"], |
| 233 | }, |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 234 | } |
| 235 | component { |
| 236 | name: "foo", |
| 237 | install_copy_in_data: ["bar"], |
| 238 | } |
| 239 | `) |
| 240 | |
| 241 | module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage) |
| 242 | android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries) |
| 243 | } |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 244 | |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 245 | func TestAvbGenVbmetaImage(t *testing.T) { |
| 246 | result := fixture.RunTestWithBp(t, ` |
| 247 | avb_gen_vbmeta_image { |
| 248 | name: "input_hashdesc", |
| 249 | src: "input.img", |
| 250 | partition_name: "input_partition_name", |
| 251 | salt: "2222", |
| 252 | }`) |
| 253 | cmd := result.ModuleForTests("input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command |
| 254 | android.AssertStringDoesContain(t, "Can't find correct --partition_name argument", |
| 255 | cmd, "--partition_name input_partition_name") |
| 256 | android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image", |
| 257 | cmd, "--do_not_append_vbmeta_image") |
| 258 | android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image", |
| 259 | cmd, "--output_vbmeta_image ") |
| 260 | android.AssertStringDoesContain(t, "Can't find --salt argument", |
| 261 | cmd, "--salt 2222") |
| 262 | } |
| 263 | |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 264 | func TestAvbAddHashFooter(t *testing.T) { |
| 265 | result := fixture.RunTestWithBp(t, ` |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 266 | avb_gen_vbmeta_image { |
| 267 | name: "input_hashdesc", |
| 268 | src: "input.img", |
| 269 | partition_name: "input", |
| 270 | salt: "2222", |
| 271 | } |
| 272 | |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 273 | avb_add_hash_footer { |
| 274 | name: "myfooter", |
| 275 | src: "input.img", |
| 276 | filename: "output.img", |
| 277 | partition_name: "mypartition", |
| 278 | private_key: "mykey", |
| 279 | salt: "1111", |
| 280 | props: [ |
| 281 | { |
| 282 | name: "prop1", |
| 283 | value: "value1", |
| 284 | }, |
| 285 | { |
| 286 | name: "prop2", |
| 287 | file: "value_file", |
| 288 | }, |
| 289 | ], |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 290 | include_descriptors_from_images: ["input_hashdesc"], |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 291 | } |
| 292 | `) |
| 293 | cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command |
| 294 | android.AssertStringDoesContain(t, "Can't find correct --partition_name argument", |
| 295 | cmd, "--partition_name mypartition") |
| 296 | android.AssertStringDoesContain(t, "Can't find correct --key argument", |
| 297 | cmd, "--key mykey") |
| 298 | android.AssertStringDoesContain(t, "Can't find --salt argument", |
| 299 | cmd, "--salt 1111") |
| 300 | android.AssertStringDoesContain(t, "Can't find --prop argument", |
| 301 | cmd, "--prop 'prop1:value1'") |
| 302 | android.AssertStringDoesContain(t, "Can't find --prop_from_file argument", |
| 303 | cmd, "--prop_from_file 'prop2:value_file'") |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 304 | android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image", |
| 305 | cmd, "--include_descriptors_from_image ") |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 306 | } |
Jooyung Han | 54f7805 | 2023-02-20 18:17:47 +0900 | [diff] [blame] | 307 | |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 308 | func TestFileSystemWithCoverageVariants(t *testing.T) { |
| 309 | context := android.GroupFixturePreparers( |
| 310 | fixture, |
| 311 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 312 | variables.GcovCoverage = proptools.BoolPtr(true) |
| 313 | variables.Native_coverage = proptools.BoolPtr(true) |
| 314 | }), |
| 315 | ) |
| 316 | |
| 317 | result := context.RunTestWithBp(t, ` |
| 318 | prebuilt_etc { |
| 319 | name: "prebuilt", |
| 320 | src: ":myfilesystem", |
| 321 | } |
| 322 | |
| 323 | android_system_image { |
| 324 | name: "myfilesystem", |
| 325 | deps: [ |
| 326 | "libfoo", |
| 327 | ], |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 328 | linker_config: { |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 329 | gen_linker_config: true, |
| 330 | linker_config_srcs: ["linker.config.json"], |
| 331 | }, |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | cc_library { |
| 335 | name: "libfoo", |
| 336 | shared_libs: [ |
| 337 | "libbar", |
| 338 | ], |
| 339 | stl: "none", |
| 340 | } |
| 341 | |
| 342 | cc_library { |
| 343 | name: "libbar", |
| 344 | stl: "none", |
| 345 | } |
| 346 | `) |
| 347 | |
| 348 | filesystem := result.ModuleForTests("myfilesystem", "android_common_cov") |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 349 | inputs := filesystem.Output("myfilesystem.img").Implicits |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 350 | android.AssertStringListContains(t, "filesystem should have libfoo(cov)", |
| 351 | inputs.Strings(), |
| 352 | "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so") |
| 353 | android.AssertStringListContains(t, "filesystem should have libbar(cov)", |
| 354 | inputs.Strings(), |
| 355 | "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared_cov/libbar.so") |
| 356 | |
| 357 | filesystemOutput := filesystem.Output("myfilesystem.img").Output |
| 358 | prebuiltInput := result.ModuleForTests("prebuilt", "android_arm64_armv8-a").Rule("Cp").Input |
| 359 | if filesystemOutput != prebuiltInput { |
| 360 | t.Error("prebuilt should use cov variant of filesystem") |
| 361 | } |
| 362 | } |
Jiyong Park | eaac823 | 2024-03-31 21:27:45 +0900 | [diff] [blame] | 363 | |
| 364 | func TestSystemImageDefaults(t *testing.T) { |
| 365 | result := fixture.RunTestWithBp(t, ` |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 366 | android_filesystem_defaults { |
Jiyong Park | eaac823 | 2024-03-31 21:27:45 +0900 | [diff] [blame] | 367 | name: "defaults", |
| 368 | multilib: { |
| 369 | common: { |
| 370 | deps: [ |
| 371 | "phony", |
| 372 | ], |
| 373 | }, |
| 374 | lib64: { |
| 375 | deps: [ |
| 376 | "libbar", |
| 377 | ], |
| 378 | }, |
| 379 | }, |
| 380 | compile_multilib: "both", |
| 381 | } |
| 382 | |
| 383 | android_system_image { |
| 384 | name: "system", |
| 385 | defaults: ["defaults"], |
| 386 | multilib: { |
| 387 | lib32: { |
| 388 | deps: [ |
| 389 | "foo", |
| 390 | "libbar", |
| 391 | ], |
| 392 | }, |
| 393 | }, |
| 394 | } |
| 395 | |
| 396 | cc_binary { |
| 397 | name: "foo", |
| 398 | compile_multilib: "prefer32", |
| 399 | } |
| 400 | |
| 401 | cc_library { |
| 402 | name: "libbar", |
| 403 | required: ["libbaz"], |
| 404 | } |
| 405 | |
| 406 | cc_library { |
| 407 | name: "libbaz", |
| 408 | } |
| 409 | |
| 410 | phony { |
| 411 | name: "phony", |
| 412 | required: ["libquz"], |
| 413 | } |
| 414 | |
| 415 | cc_library { |
| 416 | name: "libquz", |
| 417 | } |
| 418 | `) |
| 419 | |
| 420 | fs := result.ModuleForTests("system", "android_common").Module().(*systemImage) |
| 421 | expected := []string{ |
| 422 | "bin/foo", |
| 423 | "lib/libbar.so", |
| 424 | "lib64/libbar.so", |
| 425 | "lib64/libbaz.so", |
| 426 | "lib64/libquz.so", |
| 427 | } |
| 428 | for _, e := range expected { |
| 429 | android.AssertStringListContains(t, "missing entry", fs.entries, e) |
| 430 | } |
| 431 | } |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 432 | |
| 433 | func TestInconsistentPartitionTypesInDefaults(t *testing.T) { |
| 434 | fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern( |
| 435 | "doesn't match with the partition type")). |
| 436 | RunTestWithBp(t, ` |
| 437 | android_filesystem_defaults { |
| 438 | name: "system_ext_def", |
| 439 | partition_type: "system_ext", |
| 440 | } |
| 441 | |
| 442 | android_filesystem_defaults { |
| 443 | name: "system_def", |
| 444 | partition_type: "system", |
| 445 | defaults: ["system_ext_def"], |
| 446 | } |
| 447 | |
| 448 | android_system_image { |
| 449 | name: "system", |
| 450 | defaults: ["system_def"], |
| 451 | } |
| 452 | `) |
| 453 | } |
Jiyong Park | 16ef7ac | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 454 | |
| 455 | func TestPreventDuplicatedEntries(t *testing.T) { |
| 456 | fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern( |
| 457 | "packaging conflict at")). |
| 458 | RunTestWithBp(t, ` |
| 459 | android_filesystem { |
| 460 | name: "fs", |
| 461 | deps: [ |
| 462 | "foo", |
| 463 | "foo_dup", |
| 464 | ], |
| 465 | } |
| 466 | |
| 467 | cc_binary { |
| 468 | name: "foo", |
| 469 | } |
| 470 | |
| 471 | cc_binary { |
| 472 | name: "foo_dup", |
| 473 | stem: "foo", |
| 474 | } |
| 475 | `) |
| 476 | } |
Jiyong Park | c4b1d55 | 2024-05-13 16:47:30 +0900 | [diff] [blame] | 477 | |
| 478 | func TestTrackPhonyAsRequiredDep(t *testing.T) { |
| 479 | result := fixture.RunTestWithBp(t, ` |
| 480 | android_filesystem { |
| 481 | name: "fs", |
| 482 | deps: ["foo"], |
| 483 | } |
| 484 | |
| 485 | cc_binary { |
| 486 | name: "foo", |
| 487 | required: ["phony"], |
| 488 | } |
| 489 | |
| 490 | phony { |
| 491 | name: "phony", |
| 492 | required: ["libbar"], |
| 493 | } |
| 494 | |
| 495 | cc_library { |
| 496 | name: "libbar", |
| 497 | } |
| 498 | `) |
| 499 | |
| 500 | fs := result.ModuleForTests("fs", "android_common").Module().(*filesystem) |
| 501 | expected := []string{ |
| 502 | "bin/foo", |
| 503 | "lib64/libbar.so", |
| 504 | } |
| 505 | for _, e := range expected { |
| 506 | android.AssertStringListContains(t, "missing entry", fs.entries, e) |
| 507 | } |
| 508 | } |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 509 | |
| 510 | func TestFilterOutUnsupportedArches(t *testing.T) { |
| 511 | result := fixture.RunTestWithBp(t, ` |
| 512 | android_filesystem { |
| 513 | name: "fs_64_only", |
| 514 | deps: ["foo"], |
| 515 | } |
| 516 | |
| 517 | android_filesystem { |
| 518 | name: "fs_64_32", |
| 519 | compile_multilib: "both", |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 520 | deps: ["foo"], |
Jiyong Park | c6a773d | 2024-05-14 21:49:11 +0900 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | cc_binary { |
| 524 | name: "foo", |
| 525 | required: ["phony"], |
| 526 | } |
| 527 | |
| 528 | phony { |
| 529 | name: "phony", |
| 530 | required: [ |
| 531 | "libbar", |
| 532 | "app", |
| 533 | ], |
| 534 | } |
| 535 | |
| 536 | cc_library { |
| 537 | name: "libbar", |
| 538 | } |
| 539 | |
| 540 | android_app { |
| 541 | name: "app", |
| 542 | srcs: ["a.java"], |
| 543 | platform_apis: true, |
| 544 | } |
| 545 | `) |
| 546 | testcases := []struct { |
| 547 | fsName string |
| 548 | expected []string |
| 549 | unexpected []string |
| 550 | }{ |
| 551 | { |
| 552 | fsName: "fs_64_only", |
| 553 | expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so"}, |
| 554 | unexpected: []string{"lib/libbar.so"}, |
| 555 | }, |
| 556 | { |
| 557 | fsName: "fs_64_32", |
| 558 | expected: []string{"app/app/app.apk", "bin/foo", "lib64/libbar.so", "lib/libbar.so"}, |
| 559 | unexpected: []string{}, |
| 560 | }, |
| 561 | } |
| 562 | for _, c := range testcases { |
| 563 | fs := result.ModuleForTests(c.fsName, "android_common").Module().(*filesystem) |
| 564 | for _, e := range c.expected { |
| 565 | android.AssertStringListContains(t, "missing entry", fs.entries, e) |
| 566 | } |
| 567 | for _, e := range c.unexpected { |
| 568 | android.AssertStringListDoesNotContain(t, "unexpected entry", fs.entries, e) |
| 569 | } |
| 570 | } |
| 571 | } |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 572 | |
| 573 | func TestErofsPartition(t *testing.T) { |
| 574 | result := fixture.RunTestWithBp(t, ` |
| 575 | android_filesystem { |
| 576 | name: "erofs_partition", |
| 577 | type: "erofs", |
| 578 | erofs: { |
| 579 | compressor: "lz4hc,9", |
| 580 | compress_hints: "compress_hints.txt", |
| 581 | }, |
| 582 | deps: ["binfoo"], |
| 583 | } |
| 584 | |
| 585 | cc_binary { |
| 586 | name: "binfoo", |
| 587 | } |
| 588 | `) |
| 589 | |
| 590 | partition := result.ModuleForTests("erofs_partition", "android_common") |
| 591 | buildImageConfig := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("prop")) |
| 592 | android.AssertStringDoesContain(t, "erofs fs type", buildImageConfig, "fs_type=erofs") |
| 593 | android.AssertStringDoesContain(t, "erofs fs type compress algorithm", buildImageConfig, "erofs_default_compressor=lz4hc,9") |
| 594 | android.AssertStringDoesContain(t, "erofs fs type compress hint", buildImageConfig, "erofs_default_compress_hints=compress_hints.txt") |
| 595 | android.AssertStringDoesContain(t, "erofs fs type sparse", buildImageConfig, "erofs_sparse_flag=-s") |
| 596 | } |
Hugo Drumond Jacob | 69d829a | 2024-10-21 09:55:45 +0000 | [diff] [blame] | 597 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 598 | func TestF2fsPartition(t *testing.T) { |
| 599 | result := fixture.RunTestWithBp(t, ` |
| 600 | android_filesystem { |
| 601 | name: "f2fs_partition", |
| 602 | type: "f2fs", |
| 603 | } |
| 604 | `) |
| 605 | |
| 606 | partition := result.ModuleForTests("f2fs_partition", "android_common") |
| 607 | buildImageConfig := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("prop")) |
| 608 | android.AssertStringDoesContain(t, "f2fs fs type", buildImageConfig, "fs_type=f2fs") |
| 609 | android.AssertStringDoesContain(t, "f2fs fs type sparse", buildImageConfig, "f2fs_sparse_flag=-S") |
| 610 | } |
| 611 | |
| 612 | func TestFsTypesPropertyError(t *testing.T) { |
| 613 | fixture.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern( |
| 614 | "erofs: erofs is non-empty, but FS type is f2fs\n. Please delete erofs properties if this partition should use f2fs\n")). |
| 615 | RunTestWithBp(t, ` |
| 616 | android_filesystem { |
| 617 | name: "f2fs_partition", |
| 618 | type: "f2fs", |
| 619 | erofs: { |
| 620 | compressor: "lz4hc,9", |
| 621 | compress_hints: "compress_hints.txt", |
| 622 | }, |
| 623 | } |
| 624 | `) |
| 625 | } |
| 626 | |
Hugo Drumond Jacob | 69d829a | 2024-10-21 09:55:45 +0000 | [diff] [blame] | 627 | // If a system_ext/ module depends on system/ module, the dependency should *not* |
| 628 | // be installed in system_ext/ |
| 629 | func TestDoNotPackageCrossPartitionDependencies(t *testing.T) { |
Spandan Das | 6d05650 | 2024-10-21 15:40:32 +0000 | [diff] [blame] | 630 | t.Skip() // TODO (spandandas): Re-enable this |
Hugo Drumond Jacob | 69d829a | 2024-10-21 09:55:45 +0000 | [diff] [blame] | 631 | result := fixture.RunTestWithBp(t, ` |
| 632 | android_filesystem { |
| 633 | name: "myfilesystem", |
| 634 | deps: ["binfoo"], |
| 635 | partition_type: "system_ext", |
| 636 | } |
| 637 | |
| 638 | cc_binary { |
| 639 | name: "binfoo", |
| 640 | shared_libs: ["libfoo"], |
| 641 | system_ext_specific: true, |
| 642 | } |
| 643 | cc_library_shared { |
| 644 | name: "libfoo", // installed in system/ |
| 645 | } |
| 646 | `) |
| 647 | |
| 648 | partition := result.ModuleForTests("myfilesystem", "android_common") |
| 649 | fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList")) |
| 650 | android.AssertDeepEquals(t, "filesystem with dependencies on different partition", "bin/binfoo\n", fileList) |
| 651 | } |
Spandan Das | 405f2d4 | 2024-10-22 18:31:25 +0000 | [diff] [blame] | 652 | |
| 653 | // If a cc_library is listed in `deps`, and it has a shared and static variant, then the shared variant |
| 654 | // should be installed. |
| 655 | func TestUseSharedVariationOfNativeLib(t *testing.T) { |
| 656 | result := fixture.RunTestWithBp(t, ` |
| 657 | android_filesystem { |
| 658 | name: "myfilesystem", |
| 659 | deps: ["libfoo"], |
| 660 | } |
| 661 | // cc_library will create a static and shared variant. |
| 662 | cc_library { |
| 663 | name: "libfoo", |
| 664 | } |
| 665 | `) |
| 666 | |
| 667 | partition := result.ModuleForTests("myfilesystem", "android_common") |
| 668 | fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList")) |
Colin Cross | 386afeb | 2024-11-13 15:20:13 -0800 | [diff] [blame] | 669 | android.AssertDeepEquals(t, "cc_library listed in deps", |
| 670 | "lib64/bootstrap/libc.so\nlib64/bootstrap/libdl.so\nlib64/bootstrap/libm.so\nlib64/libc++.so\nlib64/libc.so\nlib64/libdl.so\nlib64/libfoo.so\nlib64/libm.so\n", |
| 671 | fileList) |
Spandan Das | 405f2d4 | 2024-10-22 18:31:25 +0000 | [diff] [blame] | 672 | } |
Spandan Das | 6c2b01d | 2024-10-22 22:16:04 +0000 | [diff] [blame] | 673 | |
| 674 | // binfoo1 overrides binbar. transitive deps of binbar should not be installed. |
| 675 | func TestDoNotInstallTransitiveDepOfOverriddenModule(t *testing.T) { |
| 676 | result := fixture.RunTestWithBp(t, ` |
| 677 | android_filesystem { |
| 678 | name: "myfilesystem", |
| 679 | deps: ["binfoo1", "libfoo2", "binbar"], |
| 680 | } |
| 681 | cc_binary { |
| 682 | name: "binfoo1", |
| 683 | shared_libs: ["libfoo"], |
| 684 | overrides: ["binbar"], |
| 685 | } |
| 686 | cc_library { |
| 687 | name: "libfoo", |
| 688 | } |
| 689 | cc_library { |
| 690 | name: "libfoo2", |
| 691 | overrides: ["libfoo"], |
| 692 | } |
| 693 | // binbar gets overridden by binfoo1 |
| 694 | // therefore, libbar should not be installed |
| 695 | cc_binary { |
| 696 | name: "binbar", |
| 697 | shared_libs: ["libbar"] |
| 698 | } |
| 699 | cc_library { |
| 700 | name: "libbar", |
| 701 | } |
| 702 | `) |
| 703 | |
| 704 | partition := result.ModuleForTests("myfilesystem", "android_common") |
| 705 | fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList")) |
Colin Cross | 386afeb | 2024-11-13 15:20:13 -0800 | [diff] [blame] | 706 | android.AssertDeepEquals(t, "Shared library dep of overridden binary should not be installed", |
| 707 | "bin/binfoo1\nlib64/bootstrap/libc.so\nlib64/bootstrap/libdl.so\nlib64/bootstrap/libm.so\nlib64/libc++.so\nlib64/libc.so\nlib64/libdl.so\nlib64/libfoo2.so\nlib64/libm.so\n", |
| 708 | fileList) |
Spandan Das | 6c2b01d | 2024-10-22 22:16:04 +0000 | [diff] [blame] | 709 | } |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 710 | |
| 711 | func TestInstallLinkerConfigFile(t *testing.T) { |
| 712 | result := fixture.RunTestWithBp(t, ` |
| 713 | android_filesystem { |
| 714 | name: "myfilesystem", |
| 715 | deps: ["libfoo_has_no_stubs", "libfoo_has_stubs"], |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 716 | linker_config: { |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 717 | gen_linker_config: true, |
| 718 | linker_config_srcs: ["linker.config.json"], |
Spandan Das | 173256b | 2024-10-31 19:59:30 +0000 | [diff] [blame] | 719 | }, |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 720 | partition_type: "vendor", |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 721 | } |
| 722 | cc_library { |
| 723 | name: "libfoo_has_no_stubs", |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 724 | vendor: true, |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 725 | } |
| 726 | cc_library { |
| 727 | name: "libfoo_has_stubs", |
| 728 | stubs: {symbol_file: "libfoo.map.txt"}, |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 729 | vendor: true, |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 730 | } |
| 731 | `) |
| 732 | |
| 733 | linkerConfigCmd := result.ModuleForTests("myfilesystem", "android_common").Rule("build_filesystem_image").RuleParams.Command |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 734 | android.AssertStringDoesContain(t, "Could not find linker.config.json file in cmd", linkerConfigCmd, "conv_linker_config proto --force -s linker.config.json") |
| 735 | android.AssertStringDoesContain(t, "Could not find stub in `provideLibs`", linkerConfigCmd, "--key provideLibs --value libfoo_has_stubs.so") |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 736 | } |
Spandan Das | c1ded7e | 2024-11-01 00:52:33 +0000 | [diff] [blame] | 737 | |
| 738 | // override_android_* modules implicitly override their base module. |
| 739 | // If both of these are listed in `deps`, the base module should not be installed. |
| 740 | func TestOverrideModulesInDeps(t *testing.T) { |
| 741 | result := fixture.RunTestWithBp(t, ` |
| 742 | android_filesystem { |
| 743 | name: "myfilesystem", |
| 744 | deps: ["myapp", "myoverrideapp"], |
| 745 | } |
| 746 | |
| 747 | android_app { |
| 748 | name: "myapp", |
| 749 | platform_apis: true, |
| 750 | } |
| 751 | override_android_app { |
| 752 | name: "myoverrideapp", |
| 753 | base: "myapp", |
| 754 | } |
| 755 | `) |
| 756 | |
| 757 | partition := result.ModuleForTests("myfilesystem", "android_common") |
| 758 | fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList")) |
| 759 | android.AssertStringEquals(t, "filesystem with override app", "app/myoverrideapp/myoverrideapp.apk\n", fileList) |
| 760 | } |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame^] | 761 | |
| 762 | func TestRamdiskPartitionSetsDevNodes(t *testing.T) { |
| 763 | result := android.GroupFixturePreparers( |
| 764 | fixture, |
| 765 | android.FixtureMergeMockFs(android.MockFS{ |
| 766 | "ramdisk_node_list": nil, |
| 767 | }), |
| 768 | ).RunTestWithBp(t, ` |
| 769 | android_filesystem { |
| 770 | name: "ramdisk_filesystem", |
| 771 | partition_name: "ramdisk", |
| 772 | } |
| 773 | filegroup { |
| 774 | name: "ramdisk_node_list", |
| 775 | srcs: ["ramdisk_node_list"], |
| 776 | } |
| 777 | `) |
| 778 | |
| 779 | android.AssertBoolEquals( |
| 780 | t, |
| 781 | "Generated ramdisk image expected to depend on \"ramdisk_node_list\" module", |
| 782 | true, |
| 783 | java.CheckModuleHasDependency(t, result.TestContext, "ramdisk_filesystem", "android_common", "ramdisk_node_list"), |
| 784 | ) |
| 785 | } |