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