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