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