Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 1 | // Copyright 2020 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 android |
| 16 | |
| 17 | import ( |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 18 | "testing" |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 19 | |
| 20 | "github.com/google/blueprint" |
Jooyung Han | 8707cd7 | 2021-07-23 02:49:46 +0900 | [diff] [blame] | 21 | "github.com/google/blueprint/proptools" |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | // Module to be packaged |
| 25 | type componentTestModule struct { |
| 26 | ModuleBase |
| 27 | props struct { |
Jooyung Han | 8707cd7 | 2021-07-23 02:49:46 +0900 | [diff] [blame] | 28 | Deps []string |
| 29 | Skip_install *bool |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
Jiyong Park | d630bdd | 2020-11-25 11:47:24 +0900 | [diff] [blame] | 33 | // dep tag used in this test. All dependencies are considered as installable. |
| 34 | type installDepTag struct { |
| 35 | blueprint.BaseDependencyTag |
| 36 | InstallAlwaysNeededDependencyTag |
| 37 | } |
| 38 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 39 | func componentTestModuleFactory() Module { |
| 40 | m := &componentTestModule{} |
| 41 | m.AddProperties(&m.props) |
| 42 | InitAndroidArchModule(m, HostAndDeviceSupported, MultilibBoth) |
| 43 | return m |
| 44 | } |
| 45 | |
| 46 | func (m *componentTestModule) DepsMutator(ctx BottomUpMutatorContext) { |
Jiyong Park | d630bdd | 2020-11-25 11:47:24 +0900 | [diff] [blame] | 47 | ctx.AddDependency(ctx.Module(), installDepTag{}, m.props.Deps...) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | func (m *componentTestModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 51 | builtFile := PathForModuleOut(ctx, m.Name()) |
| 52 | dir := ctx.Target().Arch.ArchType.Multilib |
| 53 | installDir := PathForModuleInstall(ctx, dir) |
Jooyung Han | 8707cd7 | 2021-07-23 02:49:46 +0900 | [diff] [blame] | 54 | if proptools.Bool(m.props.Skip_install) { |
| 55 | m.SkipInstall() |
| 56 | } |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 57 | ctx.InstallFile(installDir, m.Name(), builtFile) |
| 58 | } |
| 59 | |
| 60 | // Module that itself is a package |
| 61 | type packageTestModule struct { |
| 62 | ModuleBase |
| 63 | PackagingBase |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 64 | properties struct { |
| 65 | Install_deps []string `android:` |
| 66 | } |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 67 | entries []string |
| 68 | } |
| 69 | |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 70 | func packageMultiTargetTestModuleFactory() Module { |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 71 | module := &packageTestModule{} |
| 72 | InitPackageModule(module) |
| 73 | InitAndroidMultiTargetsArchModule(module, DeviceSupported, MultilibCommon) |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 74 | module.AddProperties(&module.properties) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 75 | return module |
| 76 | } |
| 77 | |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 78 | func packageTestModuleFactory() Module { |
| 79 | module := &packageTestModule{} |
| 80 | InitPackageModule(module) |
| 81 | InitAndroidArchModule(module, DeviceSupported, MultilibBoth) |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 82 | module.AddProperties(&module.properties) |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 83 | return module |
| 84 | } |
| 85 | |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 86 | type packagingDepTag struct { |
| 87 | blueprint.BaseDependencyTag |
| 88 | PackagingItemAlwaysDepTag |
| 89 | } |
| 90 | |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 91 | func (m *packageTestModule) DepsMutator(ctx BottomUpMutatorContext) { |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 92 | m.AddDeps(ctx, packagingDepTag{}) |
| 93 | ctx.AddDependency(ctx.Module(), installDepTag{}, m.properties.Install_deps...) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | func (m *packageTestModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
Paul Duffin | 4076a75 | 2021-02-02 10:59:54 +0000 | [diff] [blame] | 97 | zipFile := PathForModuleOut(ctx, "myzip.zip") |
Jooyung Han | a883428 | 2022-03-25 11:40:12 +0900 | [diff] [blame] | 98 | m.entries = m.CopyDepsToZip(ctx, m.GatherPackagingSpecs(ctx), zipFile) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 99 | } |
| 100 | |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 101 | func runPackagingTest(t *testing.T, multitarget bool, bp string, expected []string) { |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 102 | t.Helper() |
| 103 | |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 104 | var archVariant string |
Paul Duffin | c3bdd31 | 2021-03-17 00:06:49 +0000 | [diff] [blame] | 105 | var moduleFactory ModuleFactory |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 106 | if multitarget { |
| 107 | archVariant = "android_common" |
Paul Duffin | c3bdd31 | 2021-03-17 00:06:49 +0000 | [diff] [blame] | 108 | moduleFactory = packageMultiTargetTestModuleFactory |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 109 | } else { |
| 110 | archVariant = "android_arm64_armv8-a" |
Paul Duffin | c3bdd31 | 2021-03-17 00:06:49 +0000 | [diff] [blame] | 111 | moduleFactory = packageTestModuleFactory |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 112 | } |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 113 | |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 114 | result := GroupFixturePreparers( |
Paul Duffin | c3bdd31 | 2021-03-17 00:06:49 +0000 | [diff] [blame] | 115 | PrepareForTestWithArchMutator, |
| 116 | FixtureRegisterWithContext(func(ctx RegistrationContext) { |
| 117 | ctx.RegisterModuleType("component", componentTestModuleFactory) |
| 118 | ctx.RegisterModuleType("package_module", moduleFactory) |
| 119 | }), |
| 120 | FixtureWithRootAndroidBp(bp), |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 121 | ).RunTest(t) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 122 | |
Paul Duffin | c3bdd31 | 2021-03-17 00:06:49 +0000 | [diff] [blame] | 123 | p := result.Module("package", archVariant).(*packageTestModule) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 124 | actual := p.entries |
| 125 | actual = SortedUniqueStrings(actual) |
| 126 | expected = SortedUniqueStrings(expected) |
Paul Duffin | c3bdd31 | 2021-03-17 00:06:49 +0000 | [diff] [blame] | 127 | AssertDeepEquals(t, "package entries", expected, actual) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 128 | } |
| 129 | |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 130 | func TestPackagingBaseMultiTarget(t *testing.T) { |
| 131 | multiTarget := true |
| 132 | runPackagingTest(t, multiTarget, |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 133 | ` |
| 134 | component { |
| 135 | name: "foo", |
| 136 | } |
| 137 | |
| 138 | package_module { |
| 139 | name: "package", |
| 140 | deps: ["foo"], |
| 141 | } |
| 142 | `, []string{"lib64/foo"}) |
| 143 | |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 144 | runPackagingTest(t, multiTarget, |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 145 | ` |
| 146 | component { |
| 147 | name: "foo", |
| 148 | deps: ["bar"], |
| 149 | } |
| 150 | |
| 151 | component { |
| 152 | name: "bar", |
| 153 | } |
| 154 | |
| 155 | package_module { |
| 156 | name: "package", |
| 157 | deps: ["foo"], |
| 158 | } |
| 159 | `, []string{"lib64/foo", "lib64/bar"}) |
| 160 | |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 161 | runPackagingTest(t, multiTarget, |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 162 | ` |
| 163 | component { |
| 164 | name: "foo", |
| 165 | deps: ["bar"], |
| 166 | } |
| 167 | |
| 168 | component { |
| 169 | name: "bar", |
| 170 | } |
| 171 | |
| 172 | package_module { |
| 173 | name: "package", |
| 174 | deps: ["foo"], |
| 175 | compile_multilib: "both", |
| 176 | } |
| 177 | `, []string{"lib32/foo", "lib32/bar", "lib64/foo", "lib64/bar"}) |
| 178 | |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 179 | runPackagingTest(t, multiTarget, |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 180 | ` |
| 181 | component { |
| 182 | name: "foo", |
| 183 | } |
| 184 | |
| 185 | component { |
| 186 | name: "bar", |
| 187 | compile_multilib: "32", |
| 188 | } |
| 189 | |
| 190 | package_module { |
| 191 | name: "package", |
| 192 | deps: ["foo"], |
| 193 | multilib: { |
| 194 | lib32: { |
| 195 | deps: ["bar"], |
| 196 | }, |
| 197 | }, |
| 198 | compile_multilib: "both", |
| 199 | } |
| 200 | `, []string{"lib32/foo", "lib32/bar", "lib64/foo"}) |
| 201 | |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 202 | runPackagingTest(t, multiTarget, |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 203 | ` |
| 204 | component { |
| 205 | name: "foo", |
| 206 | } |
| 207 | |
| 208 | component { |
| 209 | name: "bar", |
| 210 | } |
| 211 | |
| 212 | package_module { |
| 213 | name: "package", |
| 214 | deps: ["foo"], |
| 215 | multilib: { |
| 216 | first: { |
| 217 | deps: ["bar"], |
| 218 | }, |
| 219 | }, |
| 220 | compile_multilib: "both", |
| 221 | } |
| 222 | `, []string{"lib32/foo", "lib64/foo", "lib64/bar"}) |
Jiyong Park | 2136d15 | 2021-02-01 23:24:56 +0900 | [diff] [blame] | 223 | |
| 224 | runPackagingTest(t, multiTarget, |
| 225 | ` |
| 226 | component { |
| 227 | name: "foo", |
| 228 | } |
| 229 | |
| 230 | component { |
| 231 | name: "bar", |
| 232 | } |
| 233 | |
| 234 | component { |
| 235 | name: "baz", |
| 236 | } |
| 237 | |
| 238 | package_module { |
| 239 | name: "package", |
| 240 | deps: ["foo"], |
| 241 | arch: { |
| 242 | arm64: { |
| 243 | deps: ["bar"], |
| 244 | }, |
| 245 | x86_64: { |
| 246 | deps: ["baz"], |
| 247 | }, |
| 248 | }, |
| 249 | compile_multilib: "both", |
| 250 | } |
| 251 | `, []string{"lib32/foo", "lib64/foo", "lib64/bar"}) |
| 252 | } |
| 253 | |
| 254 | func TestPackagingBaseSingleTarget(t *testing.T) { |
| 255 | multiTarget := false |
| 256 | runPackagingTest(t, multiTarget, |
| 257 | ` |
| 258 | component { |
| 259 | name: "foo", |
| 260 | } |
| 261 | |
| 262 | package_module { |
| 263 | name: "package", |
| 264 | deps: ["foo"], |
| 265 | } |
| 266 | `, []string{"lib64/foo"}) |
| 267 | |
| 268 | runPackagingTest(t, multiTarget, |
| 269 | ` |
| 270 | component { |
| 271 | name: "foo", |
| 272 | deps: ["bar"], |
| 273 | } |
| 274 | |
| 275 | component { |
| 276 | name: "bar", |
| 277 | } |
| 278 | |
| 279 | package_module { |
| 280 | name: "package", |
| 281 | deps: ["foo"], |
| 282 | } |
| 283 | `, []string{"lib64/foo", "lib64/bar"}) |
| 284 | |
| 285 | runPackagingTest(t, multiTarget, |
| 286 | ` |
| 287 | component { |
| 288 | name: "foo", |
| 289 | } |
| 290 | |
| 291 | component { |
| 292 | name: "bar", |
| 293 | compile_multilib: "32", |
| 294 | } |
| 295 | |
| 296 | package_module { |
| 297 | name: "package", |
| 298 | deps: ["foo"], |
| 299 | multilib: { |
| 300 | lib32: { |
| 301 | deps: ["bar"], |
| 302 | }, |
| 303 | }, |
| 304 | } |
| 305 | `, []string{"lib64/foo"}) |
| 306 | |
| 307 | runPackagingTest(t, multiTarget, |
| 308 | ` |
| 309 | component { |
| 310 | name: "foo", |
| 311 | } |
| 312 | |
| 313 | component { |
| 314 | name: "bar", |
| 315 | } |
| 316 | |
| 317 | package_module { |
| 318 | name: "package", |
| 319 | deps: ["foo"], |
| 320 | multilib: { |
| 321 | lib64: { |
| 322 | deps: ["bar"], |
| 323 | }, |
| 324 | }, |
| 325 | } |
| 326 | `, []string{"lib64/foo", "lib64/bar"}) |
| 327 | |
| 328 | runPackagingTest(t, multiTarget, |
| 329 | ` |
| 330 | component { |
| 331 | name: "foo", |
| 332 | } |
| 333 | |
| 334 | component { |
| 335 | name: "bar", |
| 336 | } |
| 337 | |
| 338 | component { |
| 339 | name: "baz", |
| 340 | } |
| 341 | |
| 342 | package_module { |
| 343 | name: "package", |
| 344 | deps: ["foo"], |
| 345 | arch: { |
| 346 | arm64: { |
| 347 | deps: ["bar"], |
| 348 | }, |
| 349 | x86_64: { |
| 350 | deps: ["baz"], |
| 351 | }, |
| 352 | }, |
| 353 | } |
| 354 | `, []string{"lib64/foo", "lib64/bar"}) |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 355 | |
| 356 | runPackagingTest(t, multiTarget, |
| 357 | ` |
| 358 | component { |
| 359 | name: "foo", |
| 360 | } |
| 361 | |
| 362 | component { |
| 363 | name: "bar", |
| 364 | } |
| 365 | |
| 366 | package_module { |
| 367 | name: "package", |
| 368 | deps: ["foo"], |
| 369 | install_deps: ["bar"], |
| 370 | } |
| 371 | `, []string{"lib64/foo"}) |
Jiyong Park | dda8f69 | 2020-11-09 18:38:48 +0900 | [diff] [blame] | 372 | } |
Jooyung Han | 8707cd7 | 2021-07-23 02:49:46 +0900 | [diff] [blame] | 373 | |
| 374 | func TestPackagingWithSkipInstallDeps(t *testing.T) { |
| 375 | // package -[dep]-> foo -[dep]-> bar -[dep]-> baz |
| 376 | // OK SKIPPED |
| 377 | multiTarget := false |
| 378 | runPackagingTest(t, multiTarget, |
| 379 | ` |
| 380 | component { |
| 381 | name: "foo", |
| 382 | deps: ["bar"], |
| 383 | } |
| 384 | |
| 385 | component { |
| 386 | name: "bar", |
| 387 | deps: ["baz"], |
| 388 | skip_install: true, |
| 389 | } |
| 390 | |
| 391 | component { |
| 392 | name: "baz", |
| 393 | } |
| 394 | |
| 395 | package_module { |
| 396 | name: "package", |
| 397 | deps: ["foo"], |
| 398 | } |
| 399 | `, []string{"lib64/foo"}) |
| 400 | } |