Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1 | // Copyright 2018 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 apex |
| 16 | |
| 17 | import ( |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 18 | "io/ioutil" |
| 19 | "os" |
| 20 | "strings" |
| 21 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/cc" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | func testApex(t *testing.T, bp string) *android.TestContext { |
| 30 | config, buildDir := setup(t) |
| 31 | defer teardown(buildDir) |
| 32 | |
| 33 | ctx := android.NewTestArchContext() |
Alex Light | ee25072 | 2018-12-06 14:00:02 -0800 | [diff] [blame] | 34 | ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(ApexBundleFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 35 | ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory)) |
| 36 | |
| 37 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 38 | ctx.TopDown("apex_deps", apexDepsMutator) |
| 39 | ctx.BottomUp("apex", apexMutator) |
| 40 | }) |
| 41 | |
| 42 | ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) |
| 43 | ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory)) |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 44 | ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory)) |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 45 | ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 46 | ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 47 | ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 48 | ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 49 | ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory)) |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 50 | ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 51 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 52 | ctx.BottomUp("image", cc.ImageMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 53 | ctx.BottomUp("link", cc.LinkageMutator).Parallel() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 54 | ctx.BottomUp("vndk", cc.VndkMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 55 | ctx.BottomUp("version", cc.VersionMutator).Parallel() |
| 56 | ctx.BottomUp("begin", cc.BeginMutator).Parallel() |
| 57 | }) |
| 58 | |
| 59 | ctx.Register() |
| 60 | |
| 61 | bp = bp + ` |
| 62 | toolchain_library { |
| 63 | name: "libcompiler_rt-extras", |
| 64 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 65 | vendor_available: true, |
| 66 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | toolchain_library { |
| 70 | name: "libatomic", |
| 71 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 72 | vendor_available: true, |
| 73 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | toolchain_library { |
| 77 | name: "libgcc", |
| 78 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 79 | vendor_available: true, |
| 80 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | toolchain_library { |
| 84 | name: "libclang_rt.builtins-aarch64-android", |
| 85 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 86 | vendor_available: true, |
| 87 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | toolchain_library { |
| 91 | name: "libclang_rt.builtins-arm-android", |
| 92 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 93 | vendor_available: true, |
| 94 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | cc_object { |
| 98 | name: "crtbegin_so", |
| 99 | stl: "none", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 100 | vendor_available: true, |
| 101 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | cc_object { |
| 105 | name: "crtend_so", |
| 106 | stl: "none", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 107 | vendor_available: true, |
| 108 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 109 | } |
| 110 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 111 | cc_object { |
| 112 | name: "crtbegin_static", |
| 113 | stl: "none", |
| 114 | } |
| 115 | |
| 116 | cc_object { |
| 117 | name: "crtend_android", |
| 118 | stl: "none", |
| 119 | } |
| 120 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 121 | llndk_library { |
| 122 | name: "libc", |
| 123 | symbol_file: "", |
| 124 | } |
| 125 | |
| 126 | llndk_library { |
| 127 | name: "libm", |
| 128 | symbol_file: "", |
| 129 | } |
| 130 | |
| 131 | llndk_library { |
| 132 | name: "libdl", |
| 133 | symbol_file: "", |
| 134 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 135 | ` |
| 136 | |
| 137 | ctx.MockFileSystem(map[string][]byte{ |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 138 | "Android.bp": []byte(bp), |
| 139 | "build/target/product/security": nil, |
| 140 | "apex_manifest.json": nil, |
| 141 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 142 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 143 | "mylib.cpp": nil, |
| 144 | "myprebuilt": nil, |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 145 | "my_include": nil, |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 146 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 147 | "vendor/foo/devkeys/test.pk8": nil, |
| 148 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 149 | "vendor/foo/devkeys/testkey.pem": nil, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 150 | }) |
| 151 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 152 | android.FailIfErrored(t, errs) |
| 153 | _, errs = ctx.PrepareBuildActions(config) |
| 154 | android.FailIfErrored(t, errs) |
| 155 | |
| 156 | return ctx |
| 157 | } |
| 158 | |
| 159 | func setup(t *testing.T) (config android.Config, buildDir string) { |
| 160 | buildDir, err := ioutil.TempDir("", "soong_apex_test") |
| 161 | if err != nil { |
| 162 | t.Fatal(err) |
| 163 | } |
| 164 | |
| 165 | config = android.TestArchConfig(buildDir, nil) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 166 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 167 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 168 | return |
| 169 | } |
| 170 | |
| 171 | func teardown(buildDir string) { |
| 172 | os.RemoveAll(buildDir) |
| 173 | } |
| 174 | |
| 175 | // ensure that 'result' contains 'expected' |
| 176 | func ensureContains(t *testing.T, result string, expected string) { |
| 177 | if !strings.Contains(result, expected) { |
| 178 | t.Errorf("%q is not found in %q", expected, result) |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // ensures that 'result' does not contain 'notExpected' |
| 183 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
| 184 | if strings.Contains(result, notExpected) { |
| 185 | t.Errorf("%q is found in %q", notExpected, result) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | func ensureListContains(t *testing.T, result []string, expected string) { |
| 190 | if !android.InList(expected, result) { |
| 191 | t.Errorf("%q is not found in %v", expected, result) |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
| 196 | if android.InList(notExpected, result) { |
| 197 | t.Errorf("%q is found in %v", notExpected, result) |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // Minimal test |
| 202 | func TestBasicApex(t *testing.T) { |
| 203 | ctx := testApex(t, ` |
| 204 | apex { |
| 205 | name: "myapex", |
| 206 | key: "myapex.key", |
| 207 | native_shared_libs: ["mylib"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 208 | multilib: { |
| 209 | both: { |
| 210 | binaries: ["foo",], |
| 211 | } |
| 212 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | apex_key { |
| 216 | name: "myapex.key", |
| 217 | public_key: "testkey.avbpubkey", |
| 218 | private_key: "testkey.pem", |
| 219 | } |
| 220 | |
| 221 | cc_library { |
| 222 | name: "mylib", |
| 223 | srcs: ["mylib.cpp"], |
| 224 | shared_libs: ["mylib2"], |
| 225 | system_shared_libs: [], |
| 226 | stl: "none", |
| 227 | } |
| 228 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 229 | cc_binary { |
| 230 | name: "foo", |
| 231 | srcs: ["mylib.cpp"], |
| 232 | compile_multilib: "both", |
| 233 | multilib: { |
| 234 | lib32: { |
| 235 | suffix: "32", |
| 236 | }, |
| 237 | lib64: { |
| 238 | suffix: "64", |
| 239 | }, |
| 240 | }, |
| 241 | symlinks: ["foo_link_"], |
| 242 | symlink_preferred_arch: true, |
| 243 | system_shared_libs: [], |
| 244 | static_executable: true, |
| 245 | stl: "none", |
| 246 | } |
| 247 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 248 | cc_library { |
| 249 | name: "mylib2", |
| 250 | srcs: ["mylib.cpp"], |
| 251 | system_shared_libs: [], |
| 252 | stl: "none", |
| 253 | } |
| 254 | `) |
| 255 | |
| 256 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 257 | copyCmds := apexRule.Args["copy_commands"] |
| 258 | |
| 259 | // Ensure that main rule creates an output |
| 260 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 261 | |
| 262 | // Ensure that apex variant is created for the direct dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 263 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 264 | |
| 265 | // Ensure that apex variant is created for the indirect dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 266 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 267 | |
| 268 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 269 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 270 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 271 | |
| 272 | // Ensure that the platform variant ends with _core_shared |
| 273 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared") |
| 274 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 275 | |
| 276 | // Ensure that all symlinks are present. |
| 277 | found_foo_link_64 := false |
| 278 | found_foo := false |
| 279 | for _, cmd := range strings.Split(copyCmds, " && ") { |
| 280 | if strings.HasPrefix(cmd, "ln -s foo64") { |
| 281 | if strings.HasSuffix(cmd, "bin/foo") { |
| 282 | found_foo = true |
| 283 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 284 | found_foo_link_64 = true |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | good := found_foo && found_foo_link_64 |
| 289 | if !good { |
| 290 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 291 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | func TestBasicZipApex(t *testing.T) { |
| 295 | ctx := testApex(t, ` |
| 296 | apex { |
| 297 | name: "myapex", |
| 298 | key: "myapex.key", |
| 299 | payload_type: "zip", |
| 300 | native_shared_libs: ["mylib"], |
| 301 | } |
| 302 | |
| 303 | apex_key { |
| 304 | name: "myapex.key", |
| 305 | public_key: "testkey.avbpubkey", |
| 306 | private_key: "testkey.pem", |
| 307 | } |
| 308 | |
| 309 | cc_library { |
| 310 | name: "mylib", |
| 311 | srcs: ["mylib.cpp"], |
| 312 | shared_libs: ["mylib2"], |
| 313 | system_shared_libs: [], |
| 314 | stl: "none", |
| 315 | } |
| 316 | |
| 317 | cc_library { |
| 318 | name: "mylib2", |
| 319 | srcs: ["mylib.cpp"], |
| 320 | system_shared_libs: [], |
| 321 | stl: "none", |
| 322 | } |
| 323 | `) |
| 324 | |
| 325 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule") |
| 326 | copyCmds := zipApexRule.Args["copy_commands"] |
| 327 | |
| 328 | // Ensure that main rule creates an output |
| 329 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 330 | |
| 331 | // Ensure that APEX variant is created for the direct dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 332 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 333 | |
| 334 | // Ensure that APEX variant is created for the indirect dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 335 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 336 | |
| 337 | // Ensure that both direct and indirect deps are copied into apex |
| 338 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 339 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | func TestApexWithStubs(t *testing.T) { |
| 343 | ctx := testApex(t, ` |
| 344 | apex { |
| 345 | name: "myapex", |
| 346 | key: "myapex.key", |
| 347 | native_shared_libs: ["mylib", "mylib3"], |
| 348 | } |
| 349 | |
| 350 | apex_key { |
| 351 | name: "myapex.key", |
| 352 | public_key: "testkey.avbpubkey", |
| 353 | private_key: "testkey.pem", |
| 354 | } |
| 355 | |
| 356 | cc_library { |
| 357 | name: "mylib", |
| 358 | srcs: ["mylib.cpp"], |
| 359 | shared_libs: ["mylib2", "mylib3"], |
| 360 | system_shared_libs: [], |
| 361 | stl: "none", |
| 362 | } |
| 363 | |
| 364 | cc_library { |
| 365 | name: "mylib2", |
| 366 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 367 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 368 | system_shared_libs: [], |
| 369 | stl: "none", |
| 370 | stubs: { |
| 371 | versions: ["1", "2", "3"], |
| 372 | }, |
| 373 | } |
| 374 | |
| 375 | cc_library { |
| 376 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 377 | srcs: ["mylib.cpp"], |
| 378 | shared_libs: ["mylib4"], |
| 379 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 380 | stl: "none", |
| 381 | stubs: { |
| 382 | versions: ["10", "11", "12"], |
| 383 | }, |
| 384 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 385 | |
| 386 | cc_library { |
| 387 | name: "mylib4", |
| 388 | srcs: ["mylib.cpp"], |
| 389 | system_shared_libs: [], |
| 390 | stl: "none", |
| 391 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 392 | `) |
| 393 | |
| 394 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 395 | copyCmds := apexRule.Args["copy_commands"] |
| 396 | |
| 397 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 398 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 399 | |
| 400 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 401 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 402 | |
| 403 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 404 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 405 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 406 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 407 | |
| 408 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 409 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 410 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 411 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 412 | |
| 413 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 414 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 415 | // .. and not linking to the stubs variant of mylib3 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 416 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 417 | |
| 418 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 419 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 420 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 421 | |
| 422 | // Ensure that genstub is invoked with --apex |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 423 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_3_myapex").Rule("genStubSrc").Args["flags"]) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 424 | } |
| 425 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 426 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
| 427 | ctx := testApex(t, ` |
| 428 | apex { |
| 429 | name: "myapex", |
| 430 | key: "myapex.key", |
| 431 | native_shared_libs: ["mylib"], |
| 432 | } |
| 433 | |
| 434 | apex_key { |
| 435 | name: "myapex.key", |
| 436 | public_key: "testkey.avbpubkey", |
| 437 | private_key: "testkey.pem", |
| 438 | } |
| 439 | |
| 440 | cc_library { |
| 441 | name: "mylib", |
| 442 | srcs: ["mylib.cpp"], |
| 443 | shared_libs: ["libfoo#10"], |
| 444 | system_shared_libs: [], |
| 445 | stl: "none", |
| 446 | } |
| 447 | |
| 448 | cc_library { |
| 449 | name: "libfoo", |
| 450 | srcs: ["mylib.cpp"], |
| 451 | shared_libs: ["libbar"], |
| 452 | system_shared_libs: [], |
| 453 | stl: "none", |
| 454 | stubs: { |
| 455 | versions: ["10", "20", "30"], |
| 456 | }, |
| 457 | } |
| 458 | |
| 459 | cc_library { |
| 460 | name: "libbar", |
| 461 | srcs: ["mylib.cpp"], |
| 462 | system_shared_libs: [], |
| 463 | stl: "none", |
| 464 | } |
| 465 | |
| 466 | `) |
| 467 | |
| 468 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 469 | copyCmds := apexRule.Args["copy_commands"] |
| 470 | |
| 471 | // Ensure that direct non-stubs dep is always included |
| 472 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 473 | |
| 474 | // Ensure that indirect stubs dep is not included |
| 475 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 476 | |
| 477 | // Ensure that dependency of stubs is not included |
| 478 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 479 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 480 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 481 | |
| 482 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 483 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 484 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 485 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 486 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 487 | libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 488 | |
| 489 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 490 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
| 491 | } |
| 492 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 493 | func TestApexWithSystemLibsStubs(t *testing.T) { |
| 494 | ctx := testApex(t, ` |
| 495 | apex { |
| 496 | name: "myapex", |
| 497 | key: "myapex.key", |
| 498 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 499 | } |
| 500 | |
| 501 | apex_key { |
| 502 | name: "myapex.key", |
| 503 | public_key: "testkey.avbpubkey", |
| 504 | private_key: "testkey.pem", |
| 505 | } |
| 506 | |
| 507 | cc_library { |
| 508 | name: "mylib", |
| 509 | srcs: ["mylib.cpp"], |
| 510 | shared_libs: ["libdl#27"], |
| 511 | stl: "none", |
| 512 | } |
| 513 | |
| 514 | cc_library_shared { |
| 515 | name: "mylib_shared", |
| 516 | srcs: ["mylib.cpp"], |
| 517 | shared_libs: ["libdl#27"], |
| 518 | stl: "none", |
| 519 | } |
| 520 | |
| 521 | cc_library { |
| 522 | name: "libc", |
| 523 | no_libgcc: true, |
| 524 | nocrt: true, |
| 525 | system_shared_libs: [], |
| 526 | stl: "none", |
| 527 | stubs: { |
| 528 | versions: ["27", "28", "29"], |
| 529 | }, |
| 530 | } |
| 531 | |
| 532 | cc_library { |
| 533 | name: "libm", |
| 534 | no_libgcc: true, |
| 535 | nocrt: true, |
| 536 | system_shared_libs: [], |
| 537 | stl: "none", |
| 538 | stubs: { |
| 539 | versions: ["27", "28", "29"], |
| 540 | }, |
| 541 | } |
| 542 | |
| 543 | cc_library { |
| 544 | name: "libdl", |
| 545 | no_libgcc: true, |
| 546 | nocrt: true, |
| 547 | system_shared_libs: [], |
| 548 | stl: "none", |
| 549 | stubs: { |
| 550 | versions: ["27", "28", "29"], |
| 551 | }, |
| 552 | } |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 553 | |
| 554 | cc_library { |
| 555 | name: "libBootstrap", |
| 556 | srcs: ["mylib.cpp"], |
| 557 | stl: "none", |
| 558 | bootstrap: true, |
| 559 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 560 | `) |
| 561 | |
| 562 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 563 | copyCmds := apexRule.Args["copy_commands"] |
| 564 | |
| 565 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 566 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 567 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 568 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 569 | |
| 570 | // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs) |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 571 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 572 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 573 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
| 574 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
| 575 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 576 | |
| 577 | // For dependency to libc |
| 578 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 579 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 580 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 581 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 582 | // ... Cflags from stub is correctly exported to mylib |
| 583 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 584 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 585 | |
| 586 | // For dependency to libm |
| 587 | // Ensure that mylib is linking with the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 588 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 589 | // ... and not linking to the stub variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 590 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 591 | // ... and is not compiling with the stub |
| 592 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 593 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 594 | |
| 595 | // For dependency to libdl |
| 596 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 597 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 598 | // ... and not linking to the other versions of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 599 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so") |
| 600 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 601 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 602 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 603 | // ... Cflags from stub is correctly exported to mylib |
| 604 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 605 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 606 | |
| 607 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
| 608 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"] |
| 609 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so") |
| 610 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so") |
| 611 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 612 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 613 | |
| 614 | func TestFilesInSubDir(t *testing.T) { |
| 615 | ctx := testApex(t, ` |
| 616 | apex { |
| 617 | name: "myapex", |
| 618 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 619 | native_shared_libs: ["mylib"], |
| 620 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 621 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 622 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | apex_key { |
| 626 | name: "myapex.key", |
| 627 | public_key: "testkey.avbpubkey", |
| 628 | private_key: "testkey.pem", |
| 629 | } |
| 630 | |
| 631 | prebuilt_etc { |
| 632 | name: "myetc", |
| 633 | src: "myprebuilt", |
| 634 | sub_dir: "foo/bar", |
| 635 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 636 | |
| 637 | cc_library { |
| 638 | name: "mylib", |
| 639 | srcs: ["mylib.cpp"], |
| 640 | relative_install_path: "foo/bar", |
| 641 | system_shared_libs: [], |
| 642 | stl: "none", |
| 643 | } |
| 644 | |
| 645 | cc_binary { |
| 646 | name: "mybin", |
| 647 | srcs: ["mylib.cpp"], |
| 648 | relative_install_path: "foo/bar", |
| 649 | system_shared_libs: [], |
| 650 | static_executable: true, |
| 651 | stl: "none", |
| 652 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 653 | `) |
| 654 | |
| 655 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig") |
| 656 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 657 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 658 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 659 | ensureListContains(t, dirs, "etc") |
| 660 | ensureListContains(t, dirs, "etc/foo") |
| 661 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 662 | ensureListContains(t, dirs, "lib64") |
| 663 | ensureListContains(t, dirs, "lib64/foo") |
| 664 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 665 | ensureListContains(t, dirs, "lib") |
| 666 | ensureListContains(t, dirs, "lib/foo") |
| 667 | ensureListContains(t, dirs, "lib/foo/bar") |
| 668 | |
| 669 | // TODO(b/123721777) respect relative path for binaries |
| 670 | // ensureListContains(t, dirs, "bin") |
| 671 | // ensureListContains(t, dirs, "bin/foo") |
| 672 | // ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 673 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 674 | |
| 675 | func TestUseVendor(t *testing.T) { |
| 676 | ctx := testApex(t, ` |
| 677 | apex { |
| 678 | name: "myapex", |
| 679 | key: "myapex.key", |
| 680 | native_shared_libs: ["mylib"], |
| 681 | use_vendor: true, |
| 682 | } |
| 683 | |
| 684 | apex_key { |
| 685 | name: "myapex.key", |
| 686 | public_key: "testkey.avbpubkey", |
| 687 | private_key: "testkey.pem", |
| 688 | } |
| 689 | |
| 690 | cc_library { |
| 691 | name: "mylib", |
| 692 | srcs: ["mylib.cpp"], |
| 693 | shared_libs: ["mylib2"], |
| 694 | system_shared_libs: [], |
| 695 | vendor_available: true, |
| 696 | stl: "none", |
| 697 | } |
| 698 | |
| 699 | cc_library { |
| 700 | name: "mylib2", |
| 701 | srcs: ["mylib.cpp"], |
| 702 | system_shared_libs: [], |
| 703 | vendor_available: true, |
| 704 | stl: "none", |
| 705 | } |
| 706 | `) |
| 707 | |
| 708 | inputsList := []string{} |
| 709 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() { |
| 710 | for _, implicit := range i.Implicits { |
| 711 | inputsList = append(inputsList, implicit.String()) |
| 712 | } |
| 713 | } |
| 714 | inputsString := strings.Join(inputsList, " ") |
| 715 | |
| 716 | // ensure that the apex includes vendor variants of the direct and indirect deps |
| 717 | ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so") |
| 718 | ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so") |
| 719 | |
| 720 | // ensure that the apex does not include core variants |
| 721 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so") |
| 722 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so") |
| 723 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 724 | |
| 725 | func TestStaticLinking(t *testing.T) { |
| 726 | ctx := testApex(t, ` |
| 727 | apex { |
| 728 | name: "myapex", |
| 729 | key: "myapex.key", |
| 730 | native_shared_libs: ["mylib"], |
| 731 | } |
| 732 | |
| 733 | apex_key { |
| 734 | name: "myapex.key", |
| 735 | public_key: "testkey.avbpubkey", |
| 736 | private_key: "testkey.pem", |
| 737 | } |
| 738 | |
| 739 | cc_library { |
| 740 | name: "mylib", |
| 741 | srcs: ["mylib.cpp"], |
| 742 | system_shared_libs: [], |
| 743 | stl: "none", |
| 744 | stubs: { |
| 745 | versions: ["1", "2", "3"], |
| 746 | }, |
| 747 | } |
| 748 | |
| 749 | cc_binary { |
| 750 | name: "not_in_apex", |
| 751 | srcs: ["mylib.cpp"], |
| 752 | static_libs: ["mylib"], |
| 753 | static_executable: true, |
| 754 | system_shared_libs: [], |
| 755 | stl: "none", |
| 756 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 757 | `) |
| 758 | |
| 759 | ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"] |
| 760 | |
| 761 | // Ensure that not_in_apex is linking with the static variant of mylib |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 762 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 763 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 764 | |
| 765 | func TestKeys(t *testing.T) { |
| 766 | ctx := testApex(t, ` |
| 767 | apex { |
| 768 | name: "myapex", |
| 769 | key: "myapex.key", |
| 770 | native_shared_libs: ["mylib"], |
| 771 | } |
| 772 | |
| 773 | cc_library { |
| 774 | name: "mylib", |
| 775 | srcs: ["mylib.cpp"], |
| 776 | system_shared_libs: [], |
| 777 | stl: "none", |
| 778 | } |
| 779 | |
| 780 | apex_key { |
| 781 | name: "myapex.key", |
| 782 | public_key: "testkey.avbpubkey", |
| 783 | private_key: "testkey.pem", |
| 784 | } |
| 785 | |
| 786 | `) |
| 787 | |
| 788 | // check the APEX keys |
| 789 | keys := ctx.ModuleForTests("myapex.key", "").Module().(*apexKey) |
| 790 | |
| 791 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 792 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 793 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 794 | } |
| 795 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 796 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 797 | "vendor/foo/devkeys/testkey.pem") |
| 798 | } |
| 799 | |
| 800 | // check the APK certs |
| 801 | certs := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("signapk").Args["certificates"] |
| 802 | if certs != "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" { |
| 803 | t.Errorf("cert and private key %q are not %q", certs, |
| 804 | "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8") |
| 805 | } |
| 806 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 807 | |
| 808 | func TestMacro(t *testing.T) { |
| 809 | ctx := testApex(t, ` |
| 810 | apex { |
| 811 | name: "myapex", |
| 812 | key: "myapex.key", |
| 813 | native_shared_libs: ["mylib"], |
| 814 | } |
| 815 | |
| 816 | apex { |
| 817 | name: "otherapex", |
| 818 | key: "myapex.key", |
| 819 | native_shared_libs: ["mylib"], |
| 820 | } |
| 821 | |
| 822 | apex_key { |
| 823 | name: "myapex.key", |
| 824 | public_key: "testkey.avbpubkey", |
| 825 | private_key: "testkey.pem", |
| 826 | } |
| 827 | |
| 828 | cc_library { |
| 829 | name: "mylib", |
| 830 | srcs: ["mylib.cpp"], |
| 831 | system_shared_libs: [], |
| 832 | stl: "none", |
| 833 | } |
| 834 | `) |
| 835 | |
| 836 | // non-APEX variant does not have __ANDROID__APEX__ defined |
| 837 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"] |
| 838 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 839 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 840 | |
| 841 | // APEX variant has __ANDROID_APEX__=<apexname> defined |
| 842 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
| 843 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 844 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 845 | |
| 846 | // APEX variant has __ANDROID_APEX__=<apexname> defined |
| 847 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"] |
| 848 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 849 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 850 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 851 | |
| 852 | func TestHeaderLibsDependency(t *testing.T) { |
| 853 | ctx := testApex(t, ` |
| 854 | apex { |
| 855 | name: "myapex", |
| 856 | key: "myapex.key", |
| 857 | native_shared_libs: ["mylib"], |
| 858 | } |
| 859 | |
| 860 | apex_key { |
| 861 | name: "myapex.key", |
| 862 | public_key: "testkey.avbpubkey", |
| 863 | private_key: "testkey.pem", |
| 864 | } |
| 865 | |
| 866 | cc_library_headers { |
| 867 | name: "mylib_headers", |
| 868 | export_include_dirs: ["my_include"], |
| 869 | system_shared_libs: [], |
| 870 | stl: "none", |
| 871 | } |
| 872 | |
| 873 | cc_library { |
| 874 | name: "mylib", |
| 875 | srcs: ["mylib.cpp"], |
| 876 | system_shared_libs: [], |
| 877 | stl: "none", |
| 878 | header_libs: ["mylib_headers"], |
| 879 | export_header_lib_headers: ["mylib_headers"], |
| 880 | stubs: { |
| 881 | versions: ["1", "2", "3"], |
| 882 | }, |
| 883 | } |
| 884 | |
| 885 | cc_library { |
| 886 | name: "otherlib", |
| 887 | srcs: ["mylib.cpp"], |
| 888 | system_shared_libs: [], |
| 889 | stl: "none", |
| 890 | shared_libs: ["mylib"], |
| 891 | } |
| 892 | `) |
| 893 | |
| 894 | cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"] |
| 895 | |
| 896 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 897 | ensureContains(t, cFlags, "-Imy_include") |
| 898 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 899 | |
| 900 | func TestApexWithTarget(t *testing.T) { |
| 901 | ctx := testApex(t, ` |
| 902 | apex { |
| 903 | name: "myapex", |
| 904 | key: "myapex.key", |
| 905 | multilib: { |
| 906 | first: { |
| 907 | native_shared_libs: ["mylib_common"], |
| 908 | } |
| 909 | }, |
| 910 | target: { |
| 911 | android: { |
| 912 | multilib: { |
| 913 | first: { |
| 914 | native_shared_libs: ["mylib"], |
| 915 | } |
| 916 | } |
| 917 | }, |
| 918 | host: { |
| 919 | multilib: { |
| 920 | first: { |
| 921 | native_shared_libs: ["mylib2"], |
| 922 | } |
| 923 | } |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | apex_key { |
| 929 | name: "myapex.key", |
| 930 | public_key: "testkey.avbpubkey", |
| 931 | private_key: "testkey.pem", |
| 932 | } |
| 933 | |
| 934 | cc_library { |
| 935 | name: "mylib", |
| 936 | srcs: ["mylib.cpp"], |
| 937 | system_shared_libs: [], |
| 938 | stl: "none", |
| 939 | } |
| 940 | |
| 941 | cc_library { |
| 942 | name: "mylib_common", |
| 943 | srcs: ["mylib.cpp"], |
| 944 | system_shared_libs: [], |
| 945 | stl: "none", |
| 946 | compile_multilib: "first", |
| 947 | } |
| 948 | |
| 949 | cc_library { |
| 950 | name: "mylib2", |
| 951 | srcs: ["mylib.cpp"], |
| 952 | system_shared_libs: [], |
| 953 | stl: "none", |
| 954 | compile_multilib: "first", |
| 955 | } |
| 956 | `) |
| 957 | |
| 958 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 959 | copyCmds := apexRule.Args["copy_commands"] |
| 960 | |
| 961 | // Ensure that main rule creates an output |
| 962 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 963 | |
| 964 | // Ensure that apex variant is created for the direct dep |
| 965 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
| 966 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex") |
| 967 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
| 968 | |
| 969 | // Ensure that both direct and indirect deps are copied into apex |
| 970 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 971 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 972 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 973 | |
| 974 | // Ensure that the platform variant ends with _core_shared |
| 975 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared") |
| 976 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared") |
| 977 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared") |
| 978 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 979 | |
| 980 | func TestApexWithShBinary(t *testing.T) { |
| 981 | ctx := testApex(t, ` |
| 982 | apex { |
| 983 | name: "myapex", |
| 984 | key: "myapex.key", |
| 985 | binaries: ["myscript"], |
| 986 | } |
| 987 | |
| 988 | apex_key { |
| 989 | name: "myapex.key", |
| 990 | public_key: "testkey.avbpubkey", |
| 991 | private_key: "testkey.pem", |
| 992 | } |
| 993 | |
| 994 | sh_binary { |
| 995 | name: "myscript", |
| 996 | src: "mylib.cpp", |
| 997 | filename: "myscript.sh", |
| 998 | sub_dir: "script", |
| 999 | } |
| 1000 | `) |
| 1001 | |
| 1002 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 1003 | copyCmds := apexRule.Args["copy_commands"] |
| 1004 | |
| 1005 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 1006 | } |