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