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" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 20 | "path" |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 21 | "reflect" |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 22 | "sort" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 23 | "strings" |
| 24 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 25 | |
| 26 | "github.com/google/blueprint/proptools" |
| 27 | |
| 28 | "android/soong/android" |
| 29 | "android/soong/cc" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 30 | "android/soong/java" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 31 | ) |
| 32 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 33 | var buildDir string |
| 34 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 35 | // names returns name list from white space separated string |
| 36 | func names(s string) (ns []string) { |
| 37 | for _, n := range strings.Split(s, " ") { |
| 38 | if len(n) > 0 { |
| 39 | ns = append(ns, n) |
| 40 | } |
| 41 | } |
| 42 | return |
| 43 | } |
| 44 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 45 | func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) { |
| 46 | t.Helper() |
| 47 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 48 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 49 | if len(errs) > 0 { |
| 50 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 51 | return |
| 52 | } |
| 53 | _, errs = ctx.PrepareBuildActions(config) |
| 54 | if len(errs) > 0 { |
| 55 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 56 | return |
| 57 | } |
| 58 | |
| 59 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 60 | } |
| 61 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 62 | func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
| 63 | t.Helper() |
| 64 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 65 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 66 | android.FailIfErrored(t, errs) |
| 67 | _, errs = ctx.PrepareBuildActions(config) |
| 68 | android.FailIfErrored(t, errs) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 69 | return ctx, config |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 70 | } |
| 71 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 72 | type testCustomizer func(fs map[string][]byte, config android.Config) |
| 73 | |
| 74 | func withFiles(files map[string][]byte) testCustomizer { |
| 75 | return func(fs map[string][]byte, config android.Config) { |
| 76 | for k, v := range files { |
| 77 | fs[k] = v |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | func withTargets(targets map[android.OsType][]android.Target) testCustomizer { |
| 83 | return func(fs map[string][]byte, config android.Config) { |
| 84 | for k, v := range targets { |
| 85 | config.Targets[k] = v |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 90 | func withBinder32bit(fs map[string][]byte, config android.Config) { |
| 91 | config.TestProductVariables.Binder32bit = proptools.BoolPtr(true) |
| 92 | } |
| 93 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 94 | func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 95 | android.ClearApexDependency() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 96 | |
| 97 | bp = bp + ` |
| 98 | toolchain_library { |
| 99 | name: "libcompiler_rt-extras", |
| 100 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 101 | vendor_available: true, |
| 102 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | toolchain_library { |
| 106 | name: "libatomic", |
| 107 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 108 | vendor_available: true, |
| 109 | recovery_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 110 | native_bridge_supported: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | toolchain_library { |
| 114 | name: "libgcc", |
| 115 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 116 | vendor_available: true, |
| 117 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | toolchain_library { |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 121 | name: "libgcc_stripped", |
| 122 | src: "", |
| 123 | vendor_available: true, |
| 124 | recovery_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 125 | native_bridge_supported: true, |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | toolchain_library { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 129 | name: "libclang_rt.builtins-aarch64-android", |
| 130 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 131 | vendor_available: true, |
| 132 | recovery_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 133 | native_bridge_supported: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | toolchain_library { |
| 137 | name: "libclang_rt.builtins-arm-android", |
| 138 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 139 | vendor_available: true, |
| 140 | recovery_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 141 | native_bridge_supported: true, |
| 142 | } |
| 143 | |
| 144 | toolchain_library { |
| 145 | name: "libclang_rt.builtins-x86_64-android", |
| 146 | src: "", |
| 147 | vendor_available: true, |
| 148 | recovery_available: true, |
| 149 | native_bridge_supported: true, |
| 150 | } |
| 151 | |
| 152 | toolchain_library { |
| 153 | name: "libclang_rt.builtins-i686-android", |
| 154 | src: "", |
| 155 | vendor_available: true, |
| 156 | recovery_available: true, |
| 157 | native_bridge_supported: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | cc_object { |
| 161 | name: "crtbegin_so", |
| 162 | stl: "none", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 163 | vendor_available: true, |
| 164 | recovery_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 165 | native_bridge_supported: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | cc_object { |
| 169 | name: "crtend_so", |
| 170 | stl: "none", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 171 | vendor_available: true, |
| 172 | recovery_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 173 | native_bridge_supported: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 174 | } |
| 175 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 176 | cc_object { |
| 177 | name: "crtbegin_static", |
| 178 | stl: "none", |
| 179 | } |
| 180 | |
| 181 | cc_object { |
| 182 | name: "crtend_android", |
| 183 | stl: "none", |
| 184 | } |
| 185 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 186 | llndk_library { |
| 187 | name: "libc", |
| 188 | symbol_file: "", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 189 | native_bridge_supported: true, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | llndk_library { |
| 193 | name: "libm", |
| 194 | symbol_file: "", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 195 | native_bridge_supported: true, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | llndk_library { |
| 199 | name: "libdl", |
| 200 | symbol_file: "", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 201 | native_bridge_supported: true, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 202 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 203 | |
| 204 | filegroup { |
| 205 | name: "myapex-file_contexts", |
| 206 | srcs: [ |
| 207 | "system/sepolicy/apex/myapex-file_contexts", |
| 208 | ], |
| 209 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 210 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame^] | 211 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 212 | bp = bp + java.GatherRequiredDepsForTest() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 213 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 214 | fs := map[string][]byte{ |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 215 | "a.java": nil, |
| 216 | "PrebuiltAppFoo.apk": nil, |
| 217 | "PrebuiltAppFooPriv.apk": nil, |
| 218 | "build/make/target/product/security": nil, |
| 219 | "apex_manifest.json": nil, |
| 220 | "AndroidManifest.xml": nil, |
| 221 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 222 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 223 | "system/sepolicy/apex/commonapex-file_contexts": nil, |
| 224 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame^] | 225 | "mylib.cpp": nil, |
| 226 | "mylib_common.cpp": nil, |
| 227 | "mytest.cpp": nil, |
| 228 | "mytest1.cpp": nil, |
| 229 | "mytest2.cpp": nil, |
| 230 | "mytest3.cpp": nil, |
| 231 | "myprebuilt": nil, |
| 232 | "my_include": nil, |
| 233 | "foo/bar/MyClass.java": nil, |
| 234 | "prebuilt.jar": nil, |
| 235 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 236 | "vendor/foo/devkeys/test.pk8": nil, |
| 237 | "testkey.x509.pem": nil, |
| 238 | "testkey.pk8": nil, |
| 239 | "testkey.override.x509.pem": nil, |
| 240 | "testkey.override.pk8": nil, |
| 241 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 242 | "vendor/foo/devkeys/testkey.pem": nil, |
| 243 | "NOTICE": nil, |
| 244 | "custom_notice": nil, |
| 245 | "testkey2.avbpubkey": nil, |
| 246 | "testkey2.pem": nil, |
| 247 | "myapex-arm64.apex": nil, |
| 248 | "myapex-arm.apex": nil, |
| 249 | "frameworks/base/api/current.txt": nil, |
| 250 | "framework/aidl/a.aidl": nil, |
| 251 | "build/make/core/proguard.flags": nil, |
| 252 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 253 | "dummy.txt": nil, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | for _, handler := range handlers { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame^] | 257 | // The fs now needs to be populated before creating the config, call handlers twice |
| 258 | // for now, once to get any fs changes, and later after the config was created to |
| 259 | // set product variables or targets. |
| 260 | tempConfig := android.TestArchConfig(buildDir, nil, bp, fs) |
| 261 | handler(fs, tempConfig) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 262 | } |
| 263 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame^] | 264 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 265 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 266 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 267 | config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 268 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 269 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
| 270 | config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") |
| 271 | |
| 272 | for _, handler := range handlers { |
| 273 | // The fs now needs to be populated before creating the config, call handlers twice |
| 274 | // for now, earlier to get any fs changes, and now after the config was created to |
| 275 | // set product variables or targets. |
| 276 | tempFS := map[string][]byte{} |
| 277 | handler(tempFS, config) |
| 278 | } |
| 279 | |
| 280 | ctx := android.NewTestArchContext() |
| 281 | ctx.RegisterModuleType("apex", BundleFactory) |
| 282 | ctx.RegisterModuleType("apex_test", testApexBundleFactory) |
| 283 | ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
| 284 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 285 | ctx.RegisterModuleType("apex_defaults", defaultsFactory) |
| 286 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
| 287 | ctx.RegisterModuleType("override_apex", overrideApexFactory) |
| 288 | |
| 289 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
| 290 | ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory) |
| 291 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 292 | ctx.RegisterModuleType("cc_prebuilt_library_shared", cc.PrebuiltSharedLibraryFactory) |
| 293 | ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) |
| 294 | ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) |
| 295 | ctx.RegisterModuleType("cc_object", cc.ObjectFactory) |
| 296 | ctx.RegisterModuleType("cc_defaults", func() android.Module { |
| 297 | return cc.DefaultsFactory() |
| 298 | }) |
| 299 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
| 300 | ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory) |
| 301 | ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) |
| 302 | ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory) |
| 303 | ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) |
| 304 | ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory) |
| 305 | ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory) |
| 306 | ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) |
| 307 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 308 | ctx.RegisterModuleType("java_library", java.LibraryFactory) |
| 309 | ctx.RegisterModuleType("java_import", java.ImportFactory) |
| 310 | ctx.RegisterModuleType("java_system_modules", java.SystemModulesFactory) |
| 311 | ctx.RegisterModuleType("android_app", java.AndroidAppFactory) |
| 312 | ctx.RegisterModuleType("android_app_import", java.AndroidAppImportFactory) |
| 313 | ctx.RegisterModuleType("override_android_app", java.OverrideAndroidAppModuleFactory) |
| 314 | |
| 315 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 316 | ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 317 | ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel() |
| 318 | }) |
| 319 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 320 | ctx.BottomUp("vndk", cc.VndkMutator).Parallel() |
| 321 | ctx.BottomUp("link", cc.LinkageMutator).Parallel() |
| 322 | ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel() |
| 323 | ctx.BottomUp("version", cc.VersionMutator).Parallel() |
| 324 | ctx.BottomUp("begin", cc.BeginMutator).Parallel() |
| 325 | }) |
| 326 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 327 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 328 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 329 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 330 | ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel() |
| 331 | ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel() |
| 332 | }) |
| 333 | |
| 334 | ctx.Register(config) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 335 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 336 | return ctx, config |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 337 | } |
| 338 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 339 | func setUp() { |
| 340 | var err error |
| 341 | buildDir, err = ioutil.TempDir("", "soong_apex_test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 342 | if err != nil { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 343 | panic(err) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 344 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 345 | } |
| 346 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 347 | func tearDown() { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 348 | os.RemoveAll(buildDir) |
| 349 | } |
| 350 | |
| 351 | // ensure that 'result' contains 'expected' |
| 352 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 353 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 354 | if !strings.Contains(result, expected) { |
| 355 | t.Errorf("%q is not found in %q", expected, result) |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // ensures that 'result' does not contain 'notExpected' |
| 360 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 361 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 362 | if strings.Contains(result, notExpected) { |
| 363 | t.Errorf("%q is found in %q", notExpected, result) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 368 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 369 | if !android.InList(expected, result) { |
| 370 | t.Errorf("%q is not found in %v", expected, result) |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 375 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 376 | if android.InList(notExpected, result) { |
| 377 | t.Errorf("%q is found in %v", notExpected, result) |
| 378 | } |
| 379 | } |
| 380 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 381 | func ensureListEmpty(t *testing.T, result []string) { |
| 382 | t.Helper() |
| 383 | if len(result) > 0 { |
| 384 | t.Errorf("%q is expected to be empty", result) |
| 385 | } |
| 386 | } |
| 387 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 388 | // Minimal test |
| 389 | func TestBasicApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 390 | ctx, _ := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 391 | apex_defaults { |
| 392 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 393 | manifest: ":myapex.manifest", |
| 394 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 395 | key: "myapex.key", |
| 396 | native_shared_libs: ["mylib"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 397 | multilib: { |
| 398 | both: { |
| 399 | binaries: ["foo",], |
| 400 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 401 | }, |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 402 | java_libs: ["myjar", "myprebuiltjar"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 403 | } |
| 404 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 405 | apex { |
| 406 | name: "myapex", |
| 407 | defaults: ["myapex-defaults"], |
| 408 | } |
| 409 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 410 | apex_key { |
| 411 | name: "myapex.key", |
| 412 | public_key: "testkey.avbpubkey", |
| 413 | private_key: "testkey.pem", |
| 414 | } |
| 415 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 416 | filegroup { |
| 417 | name: "myapex.manifest", |
| 418 | srcs: ["apex_manifest.json"], |
| 419 | } |
| 420 | |
| 421 | filegroup { |
| 422 | name: "myapex.androidmanifest", |
| 423 | srcs: ["AndroidManifest.xml"], |
| 424 | } |
| 425 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 426 | cc_library { |
| 427 | name: "mylib", |
| 428 | srcs: ["mylib.cpp"], |
| 429 | shared_libs: ["mylib2"], |
| 430 | system_shared_libs: [], |
| 431 | stl: "none", |
| 432 | } |
| 433 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 434 | cc_binary { |
| 435 | name: "foo", |
| 436 | srcs: ["mylib.cpp"], |
| 437 | compile_multilib: "both", |
| 438 | multilib: { |
| 439 | lib32: { |
| 440 | suffix: "32", |
| 441 | }, |
| 442 | lib64: { |
| 443 | suffix: "64", |
| 444 | }, |
| 445 | }, |
| 446 | symlinks: ["foo_link_"], |
| 447 | symlink_preferred_arch: true, |
| 448 | system_shared_libs: [], |
| 449 | static_executable: true, |
| 450 | stl: "none", |
| 451 | } |
| 452 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 453 | cc_library { |
| 454 | name: "mylib2", |
| 455 | srcs: ["mylib.cpp"], |
| 456 | system_shared_libs: [], |
| 457 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 458 | notice: "custom_notice", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 459 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 460 | |
| 461 | java_library { |
| 462 | name: "myjar", |
| 463 | srcs: ["foo/bar/MyClass.java"], |
| 464 | sdk_version: "none", |
| 465 | system_modules: "none", |
| 466 | compile_dex: true, |
| 467 | static_libs: ["myotherjar"], |
| 468 | } |
| 469 | |
| 470 | java_library { |
| 471 | name: "myotherjar", |
| 472 | srcs: ["foo/bar/MyClass.java"], |
| 473 | sdk_version: "none", |
| 474 | system_modules: "none", |
| 475 | compile_dex: true, |
| 476 | } |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 477 | |
| 478 | java_import { |
| 479 | name: "myprebuiltjar", |
| 480 | jars: ["prebuilt.jar"], |
| 481 | installable: true, |
| 482 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 483 | `) |
| 484 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 485 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 486 | |
| 487 | optFlags := apexRule.Args["opt_flags"] |
| 488 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 489 | // Ensure that the NOTICE output is being packaged as an asset. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 490 | ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 491 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 492 | copyCmds := apexRule.Args["copy_commands"] |
| 493 | |
| 494 | // Ensure that main rule creates an output |
| 495 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 496 | |
| 497 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 498 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 499 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex") |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 500 | ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 501 | |
| 502 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 503 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 504 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 505 | |
| 506 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 507 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 508 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 509 | ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar") |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 510 | ensureContains(t, copyCmds, "image.apex/javalib/myprebuiltjar.jar") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 511 | // .. but not for java libs |
| 512 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 513 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 514 | // Ensure that the platform variant ends with _shared or _common |
| 515 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 516 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 517 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 518 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 519 | ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 520 | |
| 521 | // Ensure that all symlinks are present. |
| 522 | found_foo_link_64 := false |
| 523 | found_foo := false |
| 524 | for _, cmd := range strings.Split(copyCmds, " && ") { |
| 525 | if strings.HasPrefix(cmd, "ln -s foo64") { |
| 526 | if strings.HasSuffix(cmd, "bin/foo") { |
| 527 | found_foo = true |
| 528 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 529 | found_foo_link_64 = true |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | good := found_foo && found_foo_link_64 |
| 534 | if !good { |
| 535 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 536 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 537 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 538 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 539 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 540 | if len(noticeInputs) != 2 { |
| 541 | t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs)) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 542 | } |
| 543 | ensureListContains(t, noticeInputs, "NOTICE") |
| 544 | ensureListContains(t, noticeInputs, "custom_notice") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 547 | func TestDefaults(t *testing.T) { |
| 548 | ctx, _ := testApex(t, ` |
| 549 | apex_defaults { |
| 550 | name: "myapex-defaults", |
| 551 | key: "myapex.key", |
| 552 | prebuilts: ["myetc"], |
| 553 | native_shared_libs: ["mylib"], |
| 554 | java_libs: ["myjar"], |
| 555 | apps: ["AppFoo"], |
| 556 | } |
| 557 | |
| 558 | prebuilt_etc { |
| 559 | name: "myetc", |
| 560 | src: "myprebuilt", |
| 561 | } |
| 562 | |
| 563 | apex { |
| 564 | name: "myapex", |
| 565 | defaults: ["myapex-defaults"], |
| 566 | } |
| 567 | |
| 568 | apex_key { |
| 569 | name: "myapex.key", |
| 570 | public_key: "testkey.avbpubkey", |
| 571 | private_key: "testkey.pem", |
| 572 | } |
| 573 | |
| 574 | cc_library { |
| 575 | name: "mylib", |
| 576 | system_shared_libs: [], |
| 577 | stl: "none", |
| 578 | } |
| 579 | |
| 580 | java_library { |
| 581 | name: "myjar", |
| 582 | srcs: ["foo/bar/MyClass.java"], |
| 583 | sdk_version: "none", |
| 584 | system_modules: "none", |
| 585 | compile_dex: true, |
| 586 | } |
| 587 | |
| 588 | android_app { |
| 589 | name: "AppFoo", |
| 590 | srcs: ["foo/bar/MyClass.java"], |
| 591 | sdk_version: "none", |
| 592 | system_modules: "none", |
| 593 | } |
| 594 | `) |
| 595 | ensureExactContents(t, ctx, "myapex", []string{ |
| 596 | "etc/myetc", |
| 597 | "javalib/myjar.jar", |
| 598 | "lib64/mylib.so", |
| 599 | "app/AppFoo/AppFoo.apk", |
| 600 | }) |
| 601 | } |
| 602 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 603 | func TestApexManifest(t *testing.T) { |
| 604 | ctx, _ := testApex(t, ` |
| 605 | apex { |
| 606 | name: "myapex", |
| 607 | key: "myapex.key", |
| 608 | } |
| 609 | |
| 610 | apex_key { |
| 611 | name: "myapex.key", |
| 612 | public_key: "testkey.avbpubkey", |
| 613 | private_key: "testkey.pem", |
| 614 | } |
| 615 | `) |
| 616 | |
| 617 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 618 | args := module.Rule("apexRule").Args |
| 619 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 620 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 621 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 622 | } |
| 623 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 624 | func TestBasicZipApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 625 | ctx, _ := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 626 | apex { |
| 627 | name: "myapex", |
| 628 | key: "myapex.key", |
| 629 | payload_type: "zip", |
| 630 | native_shared_libs: ["mylib"], |
| 631 | } |
| 632 | |
| 633 | apex_key { |
| 634 | name: "myapex.key", |
| 635 | public_key: "testkey.avbpubkey", |
| 636 | private_key: "testkey.pem", |
| 637 | } |
| 638 | |
| 639 | cc_library { |
| 640 | name: "mylib", |
| 641 | srcs: ["mylib.cpp"], |
| 642 | shared_libs: ["mylib2"], |
| 643 | system_shared_libs: [], |
| 644 | stl: "none", |
| 645 | } |
| 646 | |
| 647 | cc_library { |
| 648 | name: "mylib2", |
| 649 | srcs: ["mylib.cpp"], |
| 650 | system_shared_libs: [], |
| 651 | stl: "none", |
| 652 | } |
| 653 | `) |
| 654 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 655 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 656 | copyCmds := zipApexRule.Args["copy_commands"] |
| 657 | |
| 658 | // Ensure that main rule creates an output |
| 659 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 660 | |
| 661 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 662 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 663 | |
| 664 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 665 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 666 | |
| 667 | // Ensure that both direct and indirect deps are copied into apex |
| 668 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 669 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | func TestApexWithStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 673 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 674 | apex { |
| 675 | name: "myapex", |
| 676 | key: "myapex.key", |
| 677 | native_shared_libs: ["mylib", "mylib3"], |
| 678 | } |
| 679 | |
| 680 | apex_key { |
| 681 | name: "myapex.key", |
| 682 | public_key: "testkey.avbpubkey", |
| 683 | private_key: "testkey.pem", |
| 684 | } |
| 685 | |
| 686 | cc_library { |
| 687 | name: "mylib", |
| 688 | srcs: ["mylib.cpp"], |
| 689 | shared_libs: ["mylib2", "mylib3"], |
| 690 | system_shared_libs: [], |
| 691 | stl: "none", |
| 692 | } |
| 693 | |
| 694 | cc_library { |
| 695 | name: "mylib2", |
| 696 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 697 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 698 | system_shared_libs: [], |
| 699 | stl: "none", |
| 700 | stubs: { |
| 701 | versions: ["1", "2", "3"], |
| 702 | }, |
| 703 | } |
| 704 | |
| 705 | cc_library { |
| 706 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 707 | srcs: ["mylib.cpp"], |
| 708 | shared_libs: ["mylib4"], |
| 709 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 710 | stl: "none", |
| 711 | stubs: { |
| 712 | versions: ["10", "11", "12"], |
| 713 | }, |
| 714 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 715 | |
| 716 | cc_library { |
| 717 | name: "mylib4", |
| 718 | srcs: ["mylib.cpp"], |
| 719 | system_shared_libs: [], |
| 720 | stl: "none", |
| 721 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 722 | `) |
| 723 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 724 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 725 | copyCmds := apexRule.Args["copy_commands"] |
| 726 | |
| 727 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 728 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 729 | |
| 730 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 731 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 732 | |
| 733 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 734 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 735 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 736 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 737 | |
| 738 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 739 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3_myapex/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 740 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 741 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_myapex/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 742 | |
| 743 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 744 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 745 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 746 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 747 | |
| 748 | // Ensure that stubs libs are built without -include flags |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 749 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 750 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 751 | |
| 752 | // Ensure that genstub is invoked with --apex |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 753 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3_myapex").Rule("genStubSrc").Args["flags"]) |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 754 | |
| 755 | ensureExactContents(t, ctx, "myapex", []string{ |
| 756 | "lib64/mylib.so", |
| 757 | "lib64/mylib3.so", |
| 758 | "lib64/mylib4.so", |
| 759 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 760 | } |
| 761 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 762 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 763 | ctx, _ := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 764 | apex { |
| 765 | name: "myapex", |
| 766 | key: "myapex.key", |
| 767 | native_shared_libs: ["mylib"], |
| 768 | } |
| 769 | |
| 770 | apex_key { |
| 771 | name: "myapex.key", |
| 772 | public_key: "testkey.avbpubkey", |
| 773 | private_key: "testkey.pem", |
| 774 | } |
| 775 | |
| 776 | cc_library { |
| 777 | name: "mylib", |
| 778 | srcs: ["mylib.cpp"], |
| 779 | shared_libs: ["libfoo#10"], |
| 780 | system_shared_libs: [], |
| 781 | stl: "none", |
| 782 | } |
| 783 | |
| 784 | cc_library { |
| 785 | name: "libfoo", |
| 786 | srcs: ["mylib.cpp"], |
| 787 | shared_libs: ["libbar"], |
| 788 | system_shared_libs: [], |
| 789 | stl: "none", |
| 790 | stubs: { |
| 791 | versions: ["10", "20", "30"], |
| 792 | }, |
| 793 | } |
| 794 | |
| 795 | cc_library { |
| 796 | name: "libbar", |
| 797 | srcs: ["mylib.cpp"], |
| 798 | system_shared_libs: [], |
| 799 | stl: "none", |
| 800 | } |
| 801 | |
| 802 | `) |
| 803 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 804 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 805 | copyCmds := apexRule.Args["copy_commands"] |
| 806 | |
| 807 | // Ensure that direct non-stubs dep is always included |
| 808 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 809 | |
| 810 | // Ensure that indirect stubs dep is not included |
| 811 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 812 | |
| 813 | // Ensure that dependency of stubs is not included |
| 814 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 815 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 816 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 817 | |
| 818 | // Ensure that mylib is linking with version 10 of libfoo |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 819 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10_myapex/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 820 | // ... and not linking to the non-stub (impl) variant of libfoo |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 821 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_myapex/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 822 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 823 | libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 824 | |
| 825 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 826 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
| 827 | } |
| 828 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 829 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 830 | /* |
| 831 | myapex |
| 832 | | |
| 833 | v (runtime_libs) |
| 834 | mylib ------+------> libfoo [provides stub] |
| 835 | | |
| 836 | `------> libbar |
| 837 | */ |
| 838 | ctx, _ := testApex(t, ` |
| 839 | apex { |
| 840 | name: "myapex", |
| 841 | key: "myapex.key", |
| 842 | native_shared_libs: ["mylib"], |
| 843 | } |
| 844 | |
| 845 | apex_key { |
| 846 | name: "myapex.key", |
| 847 | public_key: "testkey.avbpubkey", |
| 848 | private_key: "testkey.pem", |
| 849 | } |
| 850 | |
| 851 | cc_library { |
| 852 | name: "mylib", |
| 853 | srcs: ["mylib.cpp"], |
| 854 | runtime_libs: ["libfoo", "libbar"], |
| 855 | system_shared_libs: [], |
| 856 | stl: "none", |
| 857 | } |
| 858 | |
| 859 | cc_library { |
| 860 | name: "libfoo", |
| 861 | srcs: ["mylib.cpp"], |
| 862 | system_shared_libs: [], |
| 863 | stl: "none", |
| 864 | stubs: { |
| 865 | versions: ["10", "20", "30"], |
| 866 | }, |
| 867 | } |
| 868 | |
| 869 | cc_library { |
| 870 | name: "libbar", |
| 871 | srcs: ["mylib.cpp"], |
| 872 | system_shared_libs: [], |
| 873 | stl: "none", |
| 874 | } |
| 875 | |
| 876 | `) |
| 877 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 878 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 879 | copyCmds := apexRule.Args["copy_commands"] |
| 880 | |
| 881 | // Ensure that direct non-stubs dep is always included |
| 882 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 883 | |
| 884 | // Ensure that indirect stubs dep is not included |
| 885 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 886 | |
| 887 | // Ensure that runtime_libs dep in included |
| 888 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 889 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 890 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 891 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 892 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 893 | |
| 894 | } |
| 895 | |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 896 | func TestApexDependencyToLLNDK(t *testing.T) { |
| 897 | ctx, _ := testApex(t, ` |
| 898 | apex { |
| 899 | name: "myapex", |
| 900 | key: "myapex.key", |
| 901 | use_vendor: true, |
| 902 | native_shared_libs: ["mylib"], |
| 903 | } |
| 904 | |
| 905 | apex_key { |
| 906 | name: "myapex.key", |
| 907 | public_key: "testkey.avbpubkey", |
| 908 | private_key: "testkey.pem", |
| 909 | } |
| 910 | |
| 911 | cc_library { |
| 912 | name: "mylib", |
| 913 | srcs: ["mylib.cpp"], |
| 914 | vendor_available: true, |
| 915 | shared_libs: ["libbar"], |
| 916 | system_shared_libs: [], |
| 917 | stl: "none", |
| 918 | } |
| 919 | |
| 920 | cc_library { |
| 921 | name: "libbar", |
| 922 | srcs: ["mylib.cpp"], |
| 923 | system_shared_libs: [], |
| 924 | stl: "none", |
| 925 | } |
| 926 | |
| 927 | llndk_library { |
| 928 | name: "libbar", |
| 929 | symbol_file: "", |
| 930 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 931 | `, func(fs map[string][]byte, config android.Config) { |
| 932 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 933 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 934 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 935 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 936 | copyCmds := apexRule.Args["copy_commands"] |
| 937 | |
| 938 | // Ensure that LLNDK dep is not included |
| 939 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 940 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 941 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 942 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 943 | |
| 944 | // Ensure that LLNDK dep is required |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 945 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 946 | |
| 947 | } |
| 948 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 949 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 950 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 951 | apex { |
| 952 | name: "myapex", |
| 953 | key: "myapex.key", |
| 954 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 955 | } |
| 956 | |
| 957 | apex_key { |
| 958 | name: "myapex.key", |
| 959 | public_key: "testkey.avbpubkey", |
| 960 | private_key: "testkey.pem", |
| 961 | } |
| 962 | |
| 963 | cc_library { |
| 964 | name: "mylib", |
| 965 | srcs: ["mylib.cpp"], |
| 966 | shared_libs: ["libdl#27"], |
| 967 | stl: "none", |
| 968 | } |
| 969 | |
| 970 | cc_library_shared { |
| 971 | name: "mylib_shared", |
| 972 | srcs: ["mylib.cpp"], |
| 973 | shared_libs: ["libdl#27"], |
| 974 | stl: "none", |
| 975 | } |
| 976 | |
| 977 | cc_library { |
| 978 | name: "libc", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 979 | no_libcrt: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 980 | nocrt: true, |
| 981 | system_shared_libs: [], |
| 982 | stl: "none", |
| 983 | stubs: { |
| 984 | versions: ["27", "28", "29"], |
| 985 | }, |
| 986 | } |
| 987 | |
| 988 | cc_library { |
| 989 | name: "libm", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 990 | no_libcrt: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 991 | nocrt: true, |
| 992 | system_shared_libs: [], |
| 993 | stl: "none", |
| 994 | stubs: { |
| 995 | versions: ["27", "28", "29"], |
| 996 | }, |
| 997 | } |
| 998 | |
| 999 | cc_library { |
| 1000 | name: "libdl", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 1001 | no_libcrt: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1002 | nocrt: true, |
| 1003 | system_shared_libs: [], |
| 1004 | stl: "none", |
| 1005 | stubs: { |
| 1006 | versions: ["27", "28", "29"], |
| 1007 | }, |
| 1008 | } |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1009 | |
| 1010 | cc_library { |
| 1011 | name: "libBootstrap", |
| 1012 | srcs: ["mylib.cpp"], |
| 1013 | stl: "none", |
| 1014 | bootstrap: true, |
| 1015 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1016 | `) |
| 1017 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1018 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1019 | copyCmds := apexRule.Args["copy_commands"] |
| 1020 | |
| 1021 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1022 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1023 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1024 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1025 | |
| 1026 | // 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] | 1027 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1028 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1029 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
| 1030 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 1031 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1032 | |
| 1033 | // For dependency to libc |
| 1034 | // Ensure that mylib is linking with the latest version of stubs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1035 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29_myapex/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1036 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1037 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_myapex/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1038 | // ... Cflags from stub is correctly exported to mylib |
| 1039 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 1040 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 1041 | |
| 1042 | // For dependency to libm |
| 1043 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1044 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1045 | // ... and not linking to the stub variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1046 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1047 | // ... and is not compiling with the stub |
| 1048 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1049 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1050 | |
| 1051 | // For dependency to libdl |
| 1052 | // Ensure that mylib is linking with the specified version of stubs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1053 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1054 | // ... and not linking to the other versions of stubs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1055 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28_myapex/libdl.so") |
| 1056 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1057 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1058 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1059 | // ... Cflags from stub is correctly exported to mylib |
| 1060 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1061 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1062 | |
| 1063 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1064 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1065 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1066 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1067 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1068 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1069 | |
| 1070 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1071 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1072 | apex { |
| 1073 | name: "myapex", |
| 1074 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1075 | native_shared_libs: ["mylib"], |
| 1076 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1077 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1078 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | apex_key { |
| 1082 | name: "myapex.key", |
| 1083 | public_key: "testkey.avbpubkey", |
| 1084 | private_key: "testkey.pem", |
| 1085 | } |
| 1086 | |
| 1087 | prebuilt_etc { |
| 1088 | name: "myetc", |
| 1089 | src: "myprebuilt", |
| 1090 | sub_dir: "foo/bar", |
| 1091 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1092 | |
| 1093 | cc_library { |
| 1094 | name: "mylib", |
| 1095 | srcs: ["mylib.cpp"], |
| 1096 | relative_install_path: "foo/bar", |
| 1097 | system_shared_libs: [], |
| 1098 | stl: "none", |
| 1099 | } |
| 1100 | |
| 1101 | cc_binary { |
| 1102 | name: "mybin", |
| 1103 | srcs: ["mylib.cpp"], |
| 1104 | relative_install_path: "foo/bar", |
| 1105 | system_shared_libs: [], |
| 1106 | static_executable: true, |
| 1107 | stl: "none", |
| 1108 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1109 | `) |
| 1110 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1111 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1112 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 1113 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1114 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1115 | ensureListContains(t, dirs, "etc") |
| 1116 | ensureListContains(t, dirs, "etc/foo") |
| 1117 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1118 | ensureListContains(t, dirs, "lib64") |
| 1119 | ensureListContains(t, dirs, "lib64/foo") |
| 1120 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 1121 | ensureListContains(t, dirs, "lib") |
| 1122 | ensureListContains(t, dirs, "lib/foo") |
| 1123 | ensureListContains(t, dirs, "lib/foo/bar") |
| 1124 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 1125 | ensureListContains(t, dirs, "bin") |
| 1126 | ensureListContains(t, dirs, "bin/foo") |
| 1127 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1128 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1129 | |
| 1130 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1131 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1132 | apex { |
| 1133 | name: "myapex", |
| 1134 | key: "myapex.key", |
| 1135 | native_shared_libs: ["mylib"], |
| 1136 | use_vendor: true, |
| 1137 | } |
| 1138 | |
| 1139 | apex_key { |
| 1140 | name: "myapex.key", |
| 1141 | public_key: "testkey.avbpubkey", |
| 1142 | private_key: "testkey.pem", |
| 1143 | } |
| 1144 | |
| 1145 | cc_library { |
| 1146 | name: "mylib", |
| 1147 | srcs: ["mylib.cpp"], |
| 1148 | shared_libs: ["mylib2"], |
| 1149 | system_shared_libs: [], |
| 1150 | vendor_available: true, |
| 1151 | stl: "none", |
| 1152 | } |
| 1153 | |
| 1154 | cc_library { |
| 1155 | name: "mylib2", |
| 1156 | srcs: ["mylib.cpp"], |
| 1157 | system_shared_libs: [], |
| 1158 | vendor_available: true, |
| 1159 | stl: "none", |
| 1160 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1161 | `, func(fs map[string][]byte, config android.Config) { |
| 1162 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 1163 | }) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1164 | |
| 1165 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1166 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1167 | for _, implicit := range i.Implicits { |
| 1168 | inputsList = append(inputsList, implicit.String()) |
| 1169 | } |
| 1170 | } |
| 1171 | inputsString := strings.Join(inputsList, " ") |
| 1172 | |
| 1173 | // ensure that the apex includes vendor variants of the direct and indirect deps |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 1174 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so") |
| 1175 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1176 | |
| 1177 | // ensure that the apex does not include core variants |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1178 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so") |
| 1179 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1180 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1181 | |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1182 | func TestUseVendorRestriction(t *testing.T) { |
| 1183 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 1184 | apex { |
| 1185 | name: "myapex", |
| 1186 | key: "myapex.key", |
| 1187 | use_vendor: true, |
| 1188 | } |
| 1189 | apex_key { |
| 1190 | name: "myapex.key", |
| 1191 | public_key: "testkey.avbpubkey", |
| 1192 | private_key: "testkey.pem", |
| 1193 | } |
| 1194 | `, func(fs map[string][]byte, config android.Config) { |
| 1195 | setUseVendorWhitelistForTest(config, []string{""}) |
| 1196 | }) |
| 1197 | // no error with whitelist |
| 1198 | testApex(t, ` |
| 1199 | apex { |
| 1200 | name: "myapex", |
| 1201 | key: "myapex.key", |
| 1202 | use_vendor: true, |
| 1203 | } |
| 1204 | apex_key { |
| 1205 | name: "myapex.key", |
| 1206 | public_key: "testkey.avbpubkey", |
| 1207 | private_key: "testkey.pem", |
| 1208 | } |
| 1209 | `, func(fs map[string][]byte, config android.Config) { |
| 1210 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 1211 | }) |
| 1212 | } |
| 1213 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 1214 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 1215 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 1216 | apex { |
| 1217 | name: "myapex", |
| 1218 | key: "myapex.key", |
| 1219 | native_shared_libs: ["mylib"], |
| 1220 | use_vendor: true, |
| 1221 | } |
| 1222 | |
| 1223 | apex_key { |
| 1224 | name: "myapex.key", |
| 1225 | public_key: "testkey.avbpubkey", |
| 1226 | private_key: "testkey.pem", |
| 1227 | } |
| 1228 | |
| 1229 | cc_library { |
| 1230 | name: "mylib", |
| 1231 | srcs: ["mylib.cpp"], |
| 1232 | system_shared_libs: [], |
| 1233 | stl: "none", |
| 1234 | } |
| 1235 | `) |
| 1236 | } |
| 1237 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1238 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1239 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1240 | apex { |
| 1241 | name: "myapex", |
| 1242 | key: "myapex.key", |
| 1243 | native_shared_libs: ["mylib"], |
| 1244 | } |
| 1245 | |
| 1246 | apex_key { |
| 1247 | name: "myapex.key", |
| 1248 | public_key: "testkey.avbpubkey", |
| 1249 | private_key: "testkey.pem", |
| 1250 | } |
| 1251 | |
| 1252 | cc_library { |
| 1253 | name: "mylib", |
| 1254 | srcs: ["mylib.cpp"], |
| 1255 | system_shared_libs: [], |
| 1256 | stl: "none", |
| 1257 | stubs: { |
| 1258 | versions: ["1", "2", "3"], |
| 1259 | }, |
| 1260 | } |
| 1261 | |
| 1262 | cc_binary { |
| 1263 | name: "not_in_apex", |
| 1264 | srcs: ["mylib.cpp"], |
| 1265 | static_libs: ["mylib"], |
| 1266 | static_executable: true, |
| 1267 | system_shared_libs: [], |
| 1268 | stl: "none", |
| 1269 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1270 | `) |
| 1271 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1272 | ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1273 | |
| 1274 | // Ensure that not_in_apex is linking with the static variant of mylib |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1275 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1276 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1277 | |
| 1278 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1279 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1280 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1281 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1282 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1283 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1284 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1285 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | cc_library { |
| 1289 | name: "mylib", |
| 1290 | srcs: ["mylib.cpp"], |
| 1291 | system_shared_libs: [], |
| 1292 | stl: "none", |
| 1293 | } |
| 1294 | |
| 1295 | apex_key { |
| 1296 | name: "myapex.key", |
| 1297 | public_key: "testkey.avbpubkey", |
| 1298 | private_key: "testkey.pem", |
| 1299 | } |
| 1300 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1301 | android_app_certificate { |
| 1302 | name: "myapex.certificate", |
| 1303 | certificate: "testkey", |
| 1304 | } |
| 1305 | |
| 1306 | android_app_certificate { |
| 1307 | name: "myapex.certificate.override", |
| 1308 | certificate: "testkey.override", |
| 1309 | } |
| 1310 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1311 | `) |
| 1312 | |
| 1313 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1314 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1315 | |
| 1316 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 1317 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 1318 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 1319 | } |
| 1320 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 1321 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 1322 | "vendor/foo/devkeys/testkey.pem") |
| 1323 | } |
| 1324 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1325 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1326 | certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"] |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1327 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1328 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1329 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1330 | } |
| 1331 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1332 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 1333 | func TestCertificate(t *testing.T) { |
| 1334 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 1335 | ctx, _ := testApex(t, ` |
| 1336 | apex { |
| 1337 | name: "myapex", |
| 1338 | key: "myapex.key", |
| 1339 | } |
| 1340 | apex_key { |
| 1341 | name: "myapex.key", |
| 1342 | public_key: "testkey.avbpubkey", |
| 1343 | private_key: "testkey.pem", |
| 1344 | }`) |
| 1345 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1346 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 1347 | if actual := rule.Args["certificates"]; actual != expected { |
| 1348 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1349 | } |
| 1350 | }) |
| 1351 | t.Run("override when unspecified", func(t *testing.T) { |
| 1352 | ctx, _ := testApex(t, ` |
| 1353 | apex { |
| 1354 | name: "myapex_keytest", |
| 1355 | key: "myapex.key", |
| 1356 | file_contexts: ":myapex-file_contexts", |
| 1357 | } |
| 1358 | apex_key { |
| 1359 | name: "myapex.key", |
| 1360 | public_key: "testkey.avbpubkey", |
| 1361 | private_key: "testkey.pem", |
| 1362 | } |
| 1363 | android_app_certificate { |
| 1364 | name: "myapex.certificate.override", |
| 1365 | certificate: "testkey.override", |
| 1366 | }`) |
| 1367 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1368 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1369 | if actual := rule.Args["certificates"]; actual != expected { |
| 1370 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1371 | } |
| 1372 | }) |
| 1373 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 1374 | ctx, _ := testApex(t, ` |
| 1375 | apex { |
| 1376 | name: "myapex", |
| 1377 | key: "myapex.key", |
| 1378 | certificate: ":myapex.certificate", |
| 1379 | } |
| 1380 | apex_key { |
| 1381 | name: "myapex.key", |
| 1382 | public_key: "testkey.avbpubkey", |
| 1383 | private_key: "testkey.pem", |
| 1384 | } |
| 1385 | android_app_certificate { |
| 1386 | name: "myapex.certificate", |
| 1387 | certificate: "testkey", |
| 1388 | }`) |
| 1389 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1390 | expected := "testkey.x509.pem testkey.pk8" |
| 1391 | if actual := rule.Args["certificates"]; actual != expected { |
| 1392 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1393 | } |
| 1394 | }) |
| 1395 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 1396 | ctx, _ := testApex(t, ` |
| 1397 | apex { |
| 1398 | name: "myapex_keytest", |
| 1399 | key: "myapex.key", |
| 1400 | file_contexts: ":myapex-file_contexts", |
| 1401 | certificate: ":myapex.certificate", |
| 1402 | } |
| 1403 | apex_key { |
| 1404 | name: "myapex.key", |
| 1405 | public_key: "testkey.avbpubkey", |
| 1406 | private_key: "testkey.pem", |
| 1407 | } |
| 1408 | android_app_certificate { |
| 1409 | name: "myapex.certificate.override", |
| 1410 | certificate: "testkey.override", |
| 1411 | }`) |
| 1412 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1413 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1414 | if actual := rule.Args["certificates"]; actual != expected { |
| 1415 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1416 | } |
| 1417 | }) |
| 1418 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 1419 | ctx, _ := testApex(t, ` |
| 1420 | apex { |
| 1421 | name: "myapex", |
| 1422 | key: "myapex.key", |
| 1423 | certificate: "testkey", |
| 1424 | } |
| 1425 | apex_key { |
| 1426 | name: "myapex.key", |
| 1427 | public_key: "testkey.avbpubkey", |
| 1428 | private_key: "testkey.pem", |
| 1429 | }`) |
| 1430 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1431 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 1432 | if actual := rule.Args["certificates"]; actual != expected { |
| 1433 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1434 | } |
| 1435 | }) |
| 1436 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 1437 | ctx, _ := testApex(t, ` |
| 1438 | apex { |
| 1439 | name: "myapex_keytest", |
| 1440 | key: "myapex.key", |
| 1441 | file_contexts: ":myapex-file_contexts", |
| 1442 | certificate: "testkey", |
| 1443 | } |
| 1444 | apex_key { |
| 1445 | name: "myapex.key", |
| 1446 | public_key: "testkey.avbpubkey", |
| 1447 | private_key: "testkey.pem", |
| 1448 | } |
| 1449 | android_app_certificate { |
| 1450 | name: "myapex.certificate.override", |
| 1451 | certificate: "testkey.override", |
| 1452 | }`) |
| 1453 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1454 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1455 | if actual := rule.Args["certificates"]; actual != expected { |
| 1456 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1457 | } |
| 1458 | }) |
| 1459 | } |
| 1460 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1461 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1462 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1463 | apex { |
| 1464 | name: "myapex", |
| 1465 | key: "myapex.key", |
| 1466 | native_shared_libs: ["mylib"], |
| 1467 | } |
| 1468 | |
| 1469 | apex { |
| 1470 | name: "otherapex", |
| 1471 | key: "myapex.key", |
| 1472 | native_shared_libs: ["mylib"], |
| 1473 | } |
| 1474 | |
| 1475 | apex_key { |
| 1476 | name: "myapex.key", |
| 1477 | public_key: "testkey.avbpubkey", |
| 1478 | private_key: "testkey.pem", |
| 1479 | } |
| 1480 | |
| 1481 | cc_library { |
| 1482 | name: "mylib", |
| 1483 | srcs: ["mylib.cpp"], |
| 1484 | system_shared_libs: [], |
| 1485 | stl: "none", |
| 1486 | } |
| 1487 | `) |
| 1488 | |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1489 | // non-APEX variant does not have __ANDROID_APEX(_NAME)__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1490 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1491 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1492 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1493 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1494 | |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1495 | // APEX variant has __ANDROID_APEX(_NAME)__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1496 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1497 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1498 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1499 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1500 | |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1501 | // APEX variant has __ANDROID_APEX(_NAME)__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1502 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1503 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1504 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1505 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1506 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1507 | |
| 1508 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1509 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1510 | apex { |
| 1511 | name: "myapex", |
| 1512 | key: "myapex.key", |
| 1513 | native_shared_libs: ["mylib"], |
| 1514 | } |
| 1515 | |
| 1516 | apex_key { |
| 1517 | name: "myapex.key", |
| 1518 | public_key: "testkey.avbpubkey", |
| 1519 | private_key: "testkey.pem", |
| 1520 | } |
| 1521 | |
| 1522 | cc_library_headers { |
| 1523 | name: "mylib_headers", |
| 1524 | export_include_dirs: ["my_include"], |
| 1525 | system_shared_libs: [], |
| 1526 | stl: "none", |
| 1527 | } |
| 1528 | |
| 1529 | cc_library { |
| 1530 | name: "mylib", |
| 1531 | srcs: ["mylib.cpp"], |
| 1532 | system_shared_libs: [], |
| 1533 | stl: "none", |
| 1534 | header_libs: ["mylib_headers"], |
| 1535 | export_header_lib_headers: ["mylib_headers"], |
| 1536 | stubs: { |
| 1537 | versions: ["1", "2", "3"], |
| 1538 | }, |
| 1539 | } |
| 1540 | |
| 1541 | cc_library { |
| 1542 | name: "otherlib", |
| 1543 | srcs: ["mylib.cpp"], |
| 1544 | system_shared_libs: [], |
| 1545 | stl: "none", |
| 1546 | shared_libs: ["mylib"], |
| 1547 | } |
| 1548 | `) |
| 1549 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1550 | cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1551 | |
| 1552 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 1553 | ensureContains(t, cFlags, "-Imy_include") |
| 1554 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1555 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1556 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName string, files []string) { |
| 1557 | t.Helper() |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1558 | apexRule := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1559 | copyCmds := apexRule.Args["copy_commands"] |
| 1560 | imageApexDir := "/image.apex/" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1561 | var failed bool |
| 1562 | var surplus []string |
| 1563 | filesMatched := make(map[string]bool) |
| 1564 | addContent := func(content string) { |
| 1565 | for _, expected := range files { |
| 1566 | if matched, _ := path.Match(expected, content); matched { |
| 1567 | filesMatched[expected] = true |
| 1568 | return |
| 1569 | } |
| 1570 | } |
| 1571 | surplus = append(surplus, content) |
| 1572 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1573 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 1574 | cmd = strings.TrimSpace(cmd) |
| 1575 | if cmd == "" { |
| 1576 | continue |
| 1577 | } |
| 1578 | terms := strings.Split(cmd, " ") |
| 1579 | switch terms[0] { |
| 1580 | case "mkdir": |
| 1581 | case "cp": |
| 1582 | if len(terms) != 3 { |
| 1583 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 1584 | } |
| 1585 | dst := terms[2] |
| 1586 | index := strings.Index(dst, imageApexDir) |
| 1587 | if index == -1 { |
| 1588 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 1589 | } |
| 1590 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1591 | addContent(dstFile) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1592 | default: |
| 1593 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 1594 | } |
| 1595 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1596 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1597 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1598 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1599 | t.Log("surplus files", surplus) |
| 1600 | failed = true |
| 1601 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1602 | |
| 1603 | if len(files) > len(filesMatched) { |
| 1604 | var missing []string |
| 1605 | for _, expected := range files { |
| 1606 | if !filesMatched[expected] { |
| 1607 | missing = append(missing, expected) |
| 1608 | } |
| 1609 | } |
| 1610 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1611 | t.Log("missing files", missing) |
| 1612 | failed = true |
| 1613 | } |
| 1614 | if failed { |
| 1615 | t.Fail() |
| 1616 | } |
| 1617 | } |
| 1618 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1619 | func TestVndkApexCurrent(t *testing.T) { |
| 1620 | ctx, _ := testApex(t, ` |
| 1621 | apex_vndk { |
| 1622 | name: "myapex", |
| 1623 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | apex_key { |
| 1627 | name: "myapex.key", |
| 1628 | public_key: "testkey.avbpubkey", |
| 1629 | private_key: "testkey.pem", |
| 1630 | } |
| 1631 | |
| 1632 | cc_library { |
| 1633 | name: "libvndk", |
| 1634 | srcs: ["mylib.cpp"], |
| 1635 | vendor_available: true, |
| 1636 | vndk: { |
| 1637 | enabled: true, |
| 1638 | }, |
| 1639 | system_shared_libs: [], |
| 1640 | stl: "none", |
| 1641 | } |
| 1642 | |
| 1643 | cc_library { |
| 1644 | name: "libvndksp", |
| 1645 | srcs: ["mylib.cpp"], |
| 1646 | vendor_available: true, |
| 1647 | vndk: { |
| 1648 | enabled: true, |
| 1649 | support_system_process: true, |
| 1650 | }, |
| 1651 | system_shared_libs: [], |
| 1652 | stl: "none", |
| 1653 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1654 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1655 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1656 | ensureExactContents(t, ctx, "myapex", []string{ |
| 1657 | "lib/libvndk.so", |
| 1658 | "lib/libvndksp.so", |
| 1659 | "lib64/libvndk.so", |
| 1660 | "lib64/libvndksp.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1661 | "etc/llndk.libraries.VER.txt", |
| 1662 | "etc/vndkcore.libraries.VER.txt", |
| 1663 | "etc/vndksp.libraries.VER.txt", |
| 1664 | "etc/vndkprivate.libraries.VER.txt", |
| 1665 | "etc/vndkcorevariant.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1666 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 1670 | ctx, _ := testApex(t, ` |
| 1671 | apex_vndk { |
| 1672 | name: "myapex", |
| 1673 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | apex_key { |
| 1677 | name: "myapex.key", |
| 1678 | public_key: "testkey.avbpubkey", |
| 1679 | private_key: "testkey.pem", |
| 1680 | } |
| 1681 | |
| 1682 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1683 | name: "libvndk", |
| 1684 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1685 | vendor_available: true, |
| 1686 | vndk: { |
| 1687 | enabled: true, |
| 1688 | }, |
| 1689 | system_shared_libs: [], |
| 1690 | stl: "none", |
| 1691 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1692 | |
| 1693 | cc_prebuilt_library_shared { |
| 1694 | name: "libvndk.arm", |
| 1695 | srcs: ["libvndk.arm.so"], |
| 1696 | vendor_available: true, |
| 1697 | vndk: { |
| 1698 | enabled: true, |
| 1699 | }, |
| 1700 | enabled: false, |
| 1701 | arch: { |
| 1702 | arm: { |
| 1703 | enabled: true, |
| 1704 | }, |
| 1705 | }, |
| 1706 | system_shared_libs: [], |
| 1707 | stl: "none", |
| 1708 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1709 | `+vndkLibrariesTxtFiles("current"), |
| 1710 | withFiles(map[string][]byte{ |
| 1711 | "libvndk.so": nil, |
| 1712 | "libvndk.arm.so": nil, |
| 1713 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1714 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1715 | ensureExactContents(t, ctx, "myapex", []string{ |
| 1716 | "lib/libvndk.so", |
| 1717 | "lib/libvndk.arm.so", |
| 1718 | "lib64/libvndk.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1719 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1720 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1721 | } |
| 1722 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1723 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 1724 | for _, v := range vers { |
| 1725 | if v == "current" { |
| 1726 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkcorevariant"} { |
| 1727 | result += ` |
| 1728 | vndk_libraries_txt { |
| 1729 | name: "` + txt + `.libraries.txt", |
| 1730 | } |
| 1731 | ` |
| 1732 | } |
| 1733 | } else { |
| 1734 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
| 1735 | result += ` |
| 1736 | prebuilt_etc { |
| 1737 | name: "` + txt + `.libraries.` + v + `.txt", |
| 1738 | src: "dummy.txt", |
| 1739 | } |
| 1740 | ` |
| 1741 | } |
| 1742 | } |
| 1743 | } |
| 1744 | return |
| 1745 | } |
| 1746 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1747 | func TestVndkApexVersion(t *testing.T) { |
| 1748 | ctx, _ := testApex(t, ` |
| 1749 | apex_vndk { |
| 1750 | name: "myapex_v27", |
| 1751 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1752 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1753 | vndk_version: "27", |
| 1754 | } |
| 1755 | |
| 1756 | apex_key { |
| 1757 | name: "myapex.key", |
| 1758 | public_key: "testkey.avbpubkey", |
| 1759 | private_key: "testkey.pem", |
| 1760 | } |
| 1761 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1762 | vndk_prebuilt_shared { |
| 1763 | name: "libvndk27", |
| 1764 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1765 | vendor_available: true, |
| 1766 | vndk: { |
| 1767 | enabled: true, |
| 1768 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1769 | target_arch: "arm64", |
| 1770 | arch: { |
| 1771 | arm: { |
| 1772 | srcs: ["libvndk27_arm.so"], |
| 1773 | }, |
| 1774 | arm64: { |
| 1775 | srcs: ["libvndk27_arm64.so"], |
| 1776 | }, |
| 1777 | }, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | vndk_prebuilt_shared { |
| 1781 | name: "libvndk27", |
| 1782 | version: "27", |
| 1783 | vendor_available: true, |
| 1784 | vndk: { |
| 1785 | enabled: true, |
| 1786 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1787 | target_arch: "x86_64", |
| 1788 | arch: { |
| 1789 | x86: { |
| 1790 | srcs: ["libvndk27_x86.so"], |
| 1791 | }, |
| 1792 | x86_64: { |
| 1793 | srcs: ["libvndk27_x86_64.so"], |
| 1794 | }, |
| 1795 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1796 | } |
| 1797 | `+vndkLibrariesTxtFiles("27"), |
| 1798 | withFiles(map[string][]byte{ |
| 1799 | "libvndk27_arm.so": nil, |
| 1800 | "libvndk27_arm64.so": nil, |
| 1801 | "libvndk27_x86.so": nil, |
| 1802 | "libvndk27_x86_64.so": nil, |
| 1803 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1804 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1805 | ensureExactContents(t, ctx, "myapex_v27", []string{ |
| 1806 | "lib/libvndk27_arm.so", |
| 1807 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1808 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1809 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { |
| 1813 | testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, ` |
| 1814 | apex_vndk { |
| 1815 | name: "myapex_v27", |
| 1816 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1817 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1818 | vndk_version: "27", |
| 1819 | } |
| 1820 | apex_vndk { |
| 1821 | name: "myapex_v27_other", |
| 1822 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1823 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1824 | vndk_version: "27", |
| 1825 | } |
| 1826 | |
| 1827 | apex_key { |
| 1828 | name: "myapex.key", |
| 1829 | public_key: "testkey.avbpubkey", |
| 1830 | private_key: "testkey.pem", |
| 1831 | } |
| 1832 | |
| 1833 | cc_library { |
| 1834 | name: "libvndk", |
| 1835 | srcs: ["mylib.cpp"], |
| 1836 | vendor_available: true, |
| 1837 | vndk: { |
| 1838 | enabled: true, |
| 1839 | }, |
| 1840 | system_shared_libs: [], |
| 1841 | stl: "none", |
| 1842 | } |
| 1843 | |
| 1844 | vndk_prebuilt_shared { |
| 1845 | name: "libvndk", |
| 1846 | version: "27", |
| 1847 | vendor_available: true, |
| 1848 | vndk: { |
| 1849 | enabled: true, |
| 1850 | }, |
| 1851 | srcs: ["libvndk.so"], |
| 1852 | } |
| 1853 | `, withFiles(map[string][]byte{ |
| 1854 | "libvndk.so": nil, |
| 1855 | })) |
| 1856 | } |
| 1857 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 1858 | func TestVndkApexNameRule(t *testing.T) { |
| 1859 | ctx, _ := testApex(t, ` |
| 1860 | apex_vndk { |
| 1861 | name: "myapex", |
| 1862 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1863 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 1864 | } |
| 1865 | apex_vndk { |
| 1866 | name: "myapex_v28", |
| 1867 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1868 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 1869 | vndk_version: "28", |
| 1870 | } |
| 1871 | apex_key { |
| 1872 | name: "myapex.key", |
| 1873 | public_key: "testkey.avbpubkey", |
| 1874 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1875 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 1876 | |
| 1877 | assertApexName := func(expected, moduleName string) { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1878 | bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 1879 | actual := proptools.String(bundle.properties.Apex_name) |
| 1880 | if !reflect.DeepEqual(actual, expected) { |
| 1881 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | assertApexName("com.android.vndk.vVER", "myapex") |
| 1886 | assertApexName("com.android.vndk.v28", "myapex_v28") |
| 1887 | } |
| 1888 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1889 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 1890 | ctx, _ := testApex(t, ` |
| 1891 | apex_vndk { |
| 1892 | name: "myapex", |
| 1893 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1894 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | apex_key { |
| 1898 | name: "myapex.key", |
| 1899 | public_key: "testkey.avbpubkey", |
| 1900 | private_key: "testkey.pem", |
| 1901 | } |
| 1902 | |
| 1903 | cc_library { |
| 1904 | name: "libvndk", |
| 1905 | srcs: ["mylib.cpp"], |
| 1906 | vendor_available: true, |
| 1907 | native_bridge_supported: true, |
| 1908 | host_supported: true, |
| 1909 | vndk: { |
| 1910 | enabled: true, |
| 1911 | }, |
| 1912 | system_shared_libs: [], |
| 1913 | stl: "none", |
| 1914 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1915 | `+vndkLibrariesTxtFiles("current"), |
| 1916 | withTargets(map[android.OsType][]android.Target{ |
| 1917 | android.Android: []android.Target{ |
| 1918 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 1919 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 1920 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"}, |
| 1921 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"}, |
| 1922 | }, |
| 1923 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1924 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1925 | ensureExactContents(t, ctx, "myapex", []string{ |
| 1926 | "lib/libvndk.so", |
| 1927 | "lib64/libvndk.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1928 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1929 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
| 1933 | testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
| 1934 | apex_vndk { |
| 1935 | name: "myapex", |
| 1936 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1937 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1938 | native_bridge_supported: true, |
| 1939 | } |
| 1940 | |
| 1941 | apex_key { |
| 1942 | name: "myapex.key", |
| 1943 | public_key: "testkey.avbpubkey", |
| 1944 | private_key: "testkey.pem", |
| 1945 | } |
| 1946 | |
| 1947 | cc_library { |
| 1948 | name: "libvndk", |
| 1949 | srcs: ["mylib.cpp"], |
| 1950 | vendor_available: true, |
| 1951 | native_bridge_supported: true, |
| 1952 | host_supported: true, |
| 1953 | vndk: { |
| 1954 | enabled: true, |
| 1955 | }, |
| 1956 | system_shared_libs: [], |
| 1957 | stl: "none", |
| 1958 | } |
| 1959 | `) |
| 1960 | } |
| 1961 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1962 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1963 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1964 | apex_vndk { |
| 1965 | name: "myapex_v27", |
| 1966 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1967 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1968 | vndk_version: "27", |
| 1969 | } |
| 1970 | |
| 1971 | apex_key { |
| 1972 | name: "myapex.key", |
| 1973 | public_key: "testkey.avbpubkey", |
| 1974 | private_key: "testkey.pem", |
| 1975 | } |
| 1976 | |
| 1977 | vndk_prebuilt_shared { |
| 1978 | name: "libvndk27", |
| 1979 | version: "27", |
| 1980 | target_arch: "arm", |
| 1981 | vendor_available: true, |
| 1982 | vndk: { |
| 1983 | enabled: true, |
| 1984 | }, |
| 1985 | arch: { |
| 1986 | arm: { |
| 1987 | srcs: ["libvndk27.so"], |
| 1988 | } |
| 1989 | }, |
| 1990 | } |
| 1991 | |
| 1992 | vndk_prebuilt_shared { |
| 1993 | name: "libvndk27", |
| 1994 | version: "27", |
| 1995 | target_arch: "arm", |
| 1996 | binder32bit: true, |
| 1997 | vendor_available: true, |
| 1998 | vndk: { |
| 1999 | enabled: true, |
| 2000 | }, |
| 2001 | arch: { |
| 2002 | arm: { |
| 2003 | srcs: ["libvndk27binder32.so"], |
| 2004 | } |
| 2005 | }, |
| 2006 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2007 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2008 | withFiles(map[string][]byte{ |
| 2009 | "libvndk27.so": nil, |
| 2010 | "libvndk27binder32.so": nil, |
| 2011 | }), |
| 2012 | withBinder32bit, |
| 2013 | withTargets(map[android.OsType][]android.Target{ |
| 2014 | android.Android: []android.Target{ |
| 2015 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 2016 | }, |
| 2017 | }), |
| 2018 | ) |
| 2019 | |
| 2020 | ensureExactContents(t, ctx, "myapex_v27", []string{ |
| 2021 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2022 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2023 | }) |
| 2024 | } |
| 2025 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2026 | func TestDependenciesInApexManifest(t *testing.T) { |
| 2027 | ctx, _ := testApex(t, ` |
| 2028 | apex { |
| 2029 | name: "myapex_nodep", |
| 2030 | key: "myapex.key", |
| 2031 | native_shared_libs: ["lib_nodep"], |
| 2032 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2033 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | apex { |
| 2037 | name: "myapex_dep", |
| 2038 | key: "myapex.key", |
| 2039 | native_shared_libs: ["lib_dep"], |
| 2040 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2041 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | apex { |
| 2045 | name: "myapex_provider", |
| 2046 | key: "myapex.key", |
| 2047 | native_shared_libs: ["libfoo"], |
| 2048 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2049 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | apex { |
| 2053 | name: "myapex_selfcontained", |
| 2054 | key: "myapex.key", |
| 2055 | native_shared_libs: ["lib_dep", "libfoo"], |
| 2056 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2057 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | apex_key { |
| 2061 | name: "myapex.key", |
| 2062 | public_key: "testkey.avbpubkey", |
| 2063 | private_key: "testkey.pem", |
| 2064 | } |
| 2065 | |
| 2066 | cc_library { |
| 2067 | name: "lib_nodep", |
| 2068 | srcs: ["mylib.cpp"], |
| 2069 | system_shared_libs: [], |
| 2070 | stl: "none", |
| 2071 | } |
| 2072 | |
| 2073 | cc_library { |
| 2074 | name: "lib_dep", |
| 2075 | srcs: ["mylib.cpp"], |
| 2076 | shared_libs: ["libfoo"], |
| 2077 | system_shared_libs: [], |
| 2078 | stl: "none", |
| 2079 | } |
| 2080 | |
| 2081 | cc_library { |
| 2082 | name: "libfoo", |
| 2083 | srcs: ["mytest.cpp"], |
| 2084 | stubs: { |
| 2085 | versions: ["1"], |
| 2086 | }, |
| 2087 | system_shared_libs: [], |
| 2088 | stl: "none", |
| 2089 | } |
| 2090 | `) |
| 2091 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2092 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2093 | var provideNativeLibs, requireNativeLibs []string |
| 2094 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2095 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2096 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2097 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2098 | ensureListEmpty(t, provideNativeLibs) |
| 2099 | ensureListEmpty(t, requireNativeLibs) |
| 2100 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2101 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2102 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2103 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2104 | ensureListEmpty(t, provideNativeLibs) |
| 2105 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 2106 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2107 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2108 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2109 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2110 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 2111 | ensureListEmpty(t, requireNativeLibs) |
| 2112 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2113 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2114 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2115 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2116 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 2117 | ensureListEmpty(t, requireNativeLibs) |
| 2118 | } |
| 2119 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2120 | func TestApexName(t *testing.T) { |
| 2121 | ctx, _ := testApex(t, ` |
| 2122 | apex { |
| 2123 | name: "myapex", |
| 2124 | key: "myapex.key", |
| 2125 | apex_name: "com.android.myapex", |
| 2126 | } |
| 2127 | |
| 2128 | apex_key { |
| 2129 | name: "myapex.key", |
| 2130 | public_key: "testkey.avbpubkey", |
| 2131 | private_key: "testkey.pem", |
| 2132 | } |
| 2133 | `) |
| 2134 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2135 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2136 | apexManifestRule := module.Rule("apexManifestRule") |
| 2137 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 2138 | apexRule := module.Rule("apexRule") |
| 2139 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
| 2140 | } |
| 2141 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2142 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2143 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2144 | apex { |
| 2145 | name: "myapex", |
| 2146 | key: "myapex.key", |
| 2147 | native_shared_libs: ["mylib_common"], |
| 2148 | } |
| 2149 | |
| 2150 | apex_key { |
| 2151 | name: "myapex.key", |
| 2152 | public_key: "testkey.avbpubkey", |
| 2153 | private_key: "testkey.pem", |
| 2154 | } |
| 2155 | |
| 2156 | cc_library { |
| 2157 | name: "mylib_common", |
| 2158 | srcs: ["mylib.cpp"], |
| 2159 | system_shared_libs: [], |
| 2160 | stl: "none", |
| 2161 | } |
| 2162 | `) |
| 2163 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2164 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2165 | apexRule := module.Rule("apexRule") |
| 2166 | copyCmds := apexRule.Args["copy_commands"] |
| 2167 | |
| 2168 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 2169 | t.Log("Apex was a test apex!") |
| 2170 | t.Fail() |
| 2171 | } |
| 2172 | // Ensure that main rule creates an output |
| 2173 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2174 | |
| 2175 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2176 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2177 | |
| 2178 | // Ensure that both direct and indirect deps are copied into apex |
| 2179 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 2180 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2181 | // Ensure that the platform variant ends with _shared |
| 2182 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2183 | |
| 2184 | if !android.InAnyApex("mylib_common") { |
| 2185 | t.Log("Found mylib_common not in any apex!") |
| 2186 | t.Fail() |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | func TestTestApex(t *testing.T) { |
| 2191 | if android.InAnyApex("mylib_common_test") { |
| 2192 | 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!") |
| 2193 | } |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2194 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2195 | apex_test { |
| 2196 | name: "myapex", |
| 2197 | key: "myapex.key", |
| 2198 | native_shared_libs: ["mylib_common_test"], |
| 2199 | } |
| 2200 | |
| 2201 | apex_key { |
| 2202 | name: "myapex.key", |
| 2203 | public_key: "testkey.avbpubkey", |
| 2204 | private_key: "testkey.pem", |
| 2205 | } |
| 2206 | |
| 2207 | cc_library { |
| 2208 | name: "mylib_common_test", |
| 2209 | srcs: ["mylib.cpp"], |
| 2210 | system_shared_libs: [], |
| 2211 | stl: "none", |
| 2212 | } |
| 2213 | `) |
| 2214 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2215 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2216 | apexRule := module.Rule("apexRule") |
| 2217 | copyCmds := apexRule.Args["copy_commands"] |
| 2218 | |
| 2219 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 2220 | t.Log("Apex was not a test apex!") |
| 2221 | t.Fail() |
| 2222 | } |
| 2223 | // Ensure that main rule creates an output |
| 2224 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2225 | |
| 2226 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2227 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2228 | |
| 2229 | // Ensure that both direct and indirect deps are copied into apex |
| 2230 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 2231 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2232 | // Ensure that the platform variant ends with _shared |
| 2233 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2234 | |
| 2235 | if android.InAnyApex("mylib_common_test") { |
| 2236 | t.Log("Found mylib_common_test in some apex!") |
| 2237 | t.Fail() |
| 2238 | } |
| 2239 | } |
| 2240 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2241 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2242 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2243 | apex { |
| 2244 | name: "myapex", |
| 2245 | key: "myapex.key", |
| 2246 | multilib: { |
| 2247 | first: { |
| 2248 | native_shared_libs: ["mylib_common"], |
| 2249 | } |
| 2250 | }, |
| 2251 | target: { |
| 2252 | android: { |
| 2253 | multilib: { |
| 2254 | first: { |
| 2255 | native_shared_libs: ["mylib"], |
| 2256 | } |
| 2257 | } |
| 2258 | }, |
| 2259 | host: { |
| 2260 | multilib: { |
| 2261 | first: { |
| 2262 | native_shared_libs: ["mylib2"], |
| 2263 | } |
| 2264 | } |
| 2265 | } |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | apex_key { |
| 2270 | name: "myapex.key", |
| 2271 | public_key: "testkey.avbpubkey", |
| 2272 | private_key: "testkey.pem", |
| 2273 | } |
| 2274 | |
| 2275 | cc_library { |
| 2276 | name: "mylib", |
| 2277 | srcs: ["mylib.cpp"], |
| 2278 | system_shared_libs: [], |
| 2279 | stl: "none", |
| 2280 | } |
| 2281 | |
| 2282 | cc_library { |
| 2283 | name: "mylib_common", |
| 2284 | srcs: ["mylib.cpp"], |
| 2285 | system_shared_libs: [], |
| 2286 | stl: "none", |
| 2287 | compile_multilib: "first", |
| 2288 | } |
| 2289 | |
| 2290 | cc_library { |
| 2291 | name: "mylib2", |
| 2292 | srcs: ["mylib.cpp"], |
| 2293 | system_shared_libs: [], |
| 2294 | stl: "none", |
| 2295 | compile_multilib: "first", |
| 2296 | } |
| 2297 | `) |
| 2298 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2299 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2300 | copyCmds := apexRule.Args["copy_commands"] |
| 2301 | |
| 2302 | // Ensure that main rule creates an output |
| 2303 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2304 | |
| 2305 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2306 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 2307 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
| 2308 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2309 | |
| 2310 | // Ensure that both direct and indirect deps are copied into apex |
| 2311 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 2312 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 2313 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 2314 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2315 | // Ensure that the platform variant ends with _shared |
| 2316 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 2317 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 2318 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2319 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2320 | |
| 2321 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2322 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2323 | apex { |
| 2324 | name: "myapex", |
| 2325 | key: "myapex.key", |
| 2326 | binaries: ["myscript"], |
| 2327 | } |
| 2328 | |
| 2329 | apex_key { |
| 2330 | name: "myapex.key", |
| 2331 | public_key: "testkey.avbpubkey", |
| 2332 | private_key: "testkey.pem", |
| 2333 | } |
| 2334 | |
| 2335 | sh_binary { |
| 2336 | name: "myscript", |
| 2337 | src: "mylib.cpp", |
| 2338 | filename: "myscript.sh", |
| 2339 | sub_dir: "script", |
| 2340 | } |
| 2341 | `) |
| 2342 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2343 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2344 | copyCmds := apexRule.Args["copy_commands"] |
| 2345 | |
| 2346 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 2347 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2348 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2349 | func TestApexInVariousPartition(t *testing.T) { |
| 2350 | testcases := []struct { |
| 2351 | propName, parition, flattenedPartition string |
| 2352 | }{ |
| 2353 | {"", "system", "system_ext"}, |
| 2354 | {"product_specific: true", "product", "product"}, |
| 2355 | {"soc_specific: true", "vendor", "vendor"}, |
| 2356 | {"proprietary: true", "vendor", "vendor"}, |
| 2357 | {"vendor: true", "vendor", "vendor"}, |
| 2358 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 2359 | } |
| 2360 | for _, tc := range testcases { |
| 2361 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 2362 | ctx, _ := testApex(t, ` |
| 2363 | apex { |
| 2364 | name: "myapex", |
| 2365 | key: "myapex.key", |
| 2366 | `+tc.propName+` |
| 2367 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2368 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2369 | apex_key { |
| 2370 | name: "myapex.key", |
| 2371 | public_key: "testkey.avbpubkey", |
| 2372 | private_key: "testkey.pem", |
| 2373 | } |
| 2374 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2375 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2376 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2377 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 2378 | actual := apex.installDir.String() |
| 2379 | if actual != expected { |
| 2380 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 2381 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2382 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2383 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 2384 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 2385 | actual = flattened.installDir.String() |
| 2386 | if actual != expected { |
| 2387 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 2388 | } |
| 2389 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2390 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2391 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2392 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2393 | func TestFileContexts(t *testing.T) { |
| 2394 | ctx, _ := testApex(t, ` |
| 2395 | apex { |
| 2396 | name: "myapex", |
| 2397 | key: "myapex.key", |
| 2398 | } |
| 2399 | |
| 2400 | apex_key { |
| 2401 | name: "myapex.key", |
| 2402 | public_key: "testkey.avbpubkey", |
| 2403 | private_key: "testkey.pem", |
| 2404 | } |
| 2405 | `) |
| 2406 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2407 | apexRule := module.Rule("apexRule") |
| 2408 | actual := apexRule.Args["file_contexts"] |
| 2409 | expected := "system/sepolicy/apex/myapex-file_contexts" |
| 2410 | if actual != expected { |
| 2411 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2412 | } |
| 2413 | |
| 2414 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
| 2415 | apex { |
| 2416 | name: "myapex", |
| 2417 | key: "myapex.key", |
| 2418 | file_contexts: "my_own_file_contexts", |
| 2419 | } |
| 2420 | |
| 2421 | apex_key { |
| 2422 | name: "myapex.key", |
| 2423 | public_key: "testkey.avbpubkey", |
| 2424 | private_key: "testkey.pem", |
| 2425 | } |
| 2426 | `, withFiles(map[string][]byte{ |
| 2427 | "my_own_file_contexts": nil, |
| 2428 | })) |
| 2429 | |
| 2430 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
| 2431 | apex { |
| 2432 | name: "myapex", |
| 2433 | key: "myapex.key", |
| 2434 | product_specific: true, |
| 2435 | file_contexts: "product_specific_file_contexts", |
| 2436 | } |
| 2437 | |
| 2438 | apex_key { |
| 2439 | name: "myapex.key", |
| 2440 | public_key: "testkey.avbpubkey", |
| 2441 | private_key: "testkey.pem", |
| 2442 | } |
| 2443 | `) |
| 2444 | |
| 2445 | ctx, _ = testApex(t, ` |
| 2446 | apex { |
| 2447 | name: "myapex", |
| 2448 | key: "myapex.key", |
| 2449 | product_specific: true, |
| 2450 | file_contexts: "product_specific_file_contexts", |
| 2451 | } |
| 2452 | |
| 2453 | apex_key { |
| 2454 | name: "myapex.key", |
| 2455 | public_key: "testkey.avbpubkey", |
| 2456 | private_key: "testkey.pem", |
| 2457 | } |
| 2458 | `, withFiles(map[string][]byte{ |
| 2459 | "product_specific_file_contexts": nil, |
| 2460 | })) |
| 2461 | module = ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2462 | apexRule = module.Rule("apexRule") |
| 2463 | actual = apexRule.Args["file_contexts"] |
| 2464 | expected = "product_specific_file_contexts" |
| 2465 | if actual != expected { |
| 2466 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2467 | } |
| 2468 | |
| 2469 | ctx, _ = testApex(t, ` |
| 2470 | apex { |
| 2471 | name: "myapex", |
| 2472 | key: "myapex.key", |
| 2473 | product_specific: true, |
| 2474 | file_contexts: ":my-file-contexts", |
| 2475 | } |
| 2476 | |
| 2477 | apex_key { |
| 2478 | name: "myapex.key", |
| 2479 | public_key: "testkey.avbpubkey", |
| 2480 | private_key: "testkey.pem", |
| 2481 | } |
| 2482 | |
| 2483 | filegroup { |
| 2484 | name: "my-file-contexts", |
| 2485 | srcs: ["product_specific_file_contexts"], |
| 2486 | } |
| 2487 | `, withFiles(map[string][]byte{ |
| 2488 | "product_specific_file_contexts": nil, |
| 2489 | })) |
| 2490 | module = ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2491 | apexRule = module.Rule("apexRule") |
| 2492 | actual = apexRule.Args["file_contexts"] |
| 2493 | expected = "product_specific_file_contexts" |
| 2494 | if actual != expected { |
| 2495 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2496 | } |
| 2497 | } |
| 2498 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2499 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2500 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2501 | apex_key { |
| 2502 | name: "myapex.key", |
| 2503 | public_key: ":my.avbpubkey", |
| 2504 | private_key: ":my.pem", |
| 2505 | product_specific: true, |
| 2506 | } |
| 2507 | |
| 2508 | filegroup { |
| 2509 | name: "my.avbpubkey", |
| 2510 | srcs: ["testkey2.avbpubkey"], |
| 2511 | } |
| 2512 | |
| 2513 | filegroup { |
| 2514 | name: "my.pem", |
| 2515 | srcs: ["testkey2.pem"], |
| 2516 | } |
| 2517 | `) |
| 2518 | |
| 2519 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 2520 | expected_pubkey := "testkey2.avbpubkey" |
| 2521 | actual_pubkey := apex_key.public_key_file.String() |
| 2522 | if actual_pubkey != expected_pubkey { |
| 2523 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 2524 | } |
| 2525 | expected_privkey := "testkey2.pem" |
| 2526 | actual_privkey := apex_key.private_key_file.String() |
| 2527 | if actual_privkey != expected_privkey { |
| 2528 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 2529 | } |
| 2530 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2531 | |
| 2532 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2533 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2534 | prebuilt_apex { |
| 2535 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 2536 | arch: { |
| 2537 | arm64: { |
| 2538 | src: "myapex-arm64.apex", |
| 2539 | }, |
| 2540 | arm: { |
| 2541 | src: "myapex-arm.apex", |
| 2542 | }, |
| 2543 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2544 | } |
| 2545 | `) |
| 2546 | |
| 2547 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 2548 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 2549 | expectedInput := "myapex-arm64.apex" |
| 2550 | if prebuilt.inputApex.String() != expectedInput { |
| 2551 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 2552 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2553 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 2554 | |
| 2555 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2556 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 2557 | prebuilt_apex { |
| 2558 | name: "myapex", |
| 2559 | src: "myapex-arm.apex", |
| 2560 | filename: "notmyapex.apex", |
| 2561 | } |
| 2562 | `) |
| 2563 | |
| 2564 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 2565 | |
| 2566 | expected := "notmyapex.apex" |
| 2567 | if p.installFilename != expected { |
| 2568 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 2569 | } |
| 2570 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 2571 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2572 | func TestPrebuiltOverrides(t *testing.T) { |
| 2573 | ctx, config := testApex(t, ` |
| 2574 | prebuilt_apex { |
| 2575 | name: "myapex.prebuilt", |
| 2576 | src: "myapex-arm.apex", |
| 2577 | overrides: [ |
| 2578 | "myapex", |
| 2579 | ], |
| 2580 | } |
| 2581 | `) |
| 2582 | |
| 2583 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 2584 | |
| 2585 | expected := []string{"myapex"} |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 2586 | actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2587 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 2588 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2592 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2593 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2594 | apex_test { |
| 2595 | name: "myapex", |
| 2596 | key: "myapex.key", |
| 2597 | tests: [ |
| 2598 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 2599 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2600 | ], |
| 2601 | } |
| 2602 | |
| 2603 | apex_key { |
| 2604 | name: "myapex.key", |
| 2605 | public_key: "testkey.avbpubkey", |
| 2606 | private_key: "testkey.pem", |
| 2607 | } |
| 2608 | |
| 2609 | cc_test { |
| 2610 | name: "mytest", |
| 2611 | gtest: false, |
| 2612 | srcs: ["mytest.cpp"], |
| 2613 | relative_install_path: "test", |
| 2614 | system_shared_libs: [], |
| 2615 | static_executable: true, |
| 2616 | stl: "none", |
| 2617 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 2618 | |
| 2619 | cc_test { |
| 2620 | name: "mytests", |
| 2621 | gtest: false, |
| 2622 | srcs: [ |
| 2623 | "mytest1.cpp", |
| 2624 | "mytest2.cpp", |
| 2625 | "mytest3.cpp", |
| 2626 | ], |
| 2627 | test_per_src: true, |
| 2628 | relative_install_path: "test", |
| 2629 | system_shared_libs: [], |
| 2630 | static_executable: true, |
| 2631 | stl: "none", |
| 2632 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2633 | `) |
| 2634 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2635 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2636 | copyCmds := apexRule.Args["copy_commands"] |
| 2637 | |
| 2638 | // Ensure that test dep is copied into apex. |
| 2639 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 2640 | |
| 2641 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 2642 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 2643 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 2644 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2645 | |
| 2646 | // Ensure the module is correctly translated. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2647 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2648 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2649 | name := apexBundle.BaseModuleName() |
| 2650 | prefix := "TARGET_" |
| 2651 | var builder strings.Builder |
| 2652 | data.Custom(&builder, name, prefix, "", data) |
| 2653 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2654 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 2655 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 2656 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 2657 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 2658 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2659 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2660 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2661 | } |
| 2662 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 2663 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
| 2664 | ctx, config := testApex(t, ` |
| 2665 | apex { |
| 2666 | name: "myapex", |
| 2667 | key: "myapex.key", |
| 2668 | } |
| 2669 | apex_key { |
| 2670 | name: "myapex.key", |
| 2671 | public_key: "testkey.avbpubkey", |
| 2672 | private_key: "testkey.pem", |
| 2673 | } |
| 2674 | `, func(fs map[string][]byte, config android.Config) { |
| 2675 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 2676 | }) |
| 2677 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2678 | ensureListContains(t, ab.externalDeps, "myapex.flattened") |
| 2679 | mk := android.AndroidMkDataForTest(t, config, "", ab) |
| 2680 | var builder strings.Builder |
| 2681 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 2682 | androidMk := builder.String() |
| 2683 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 2684 | } |
| 2685 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2686 | func TestApexUsesOtherApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2687 | ctx, _ := testApex(t, ` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2688 | apex { |
| 2689 | name: "myapex", |
| 2690 | key: "myapex.key", |
| 2691 | native_shared_libs: ["mylib"], |
| 2692 | uses: ["commonapex"], |
| 2693 | } |
| 2694 | |
| 2695 | apex { |
| 2696 | name: "commonapex", |
| 2697 | key: "myapex.key", |
| 2698 | native_shared_libs: ["libcommon"], |
| 2699 | provide_cpp_shared_libs: true, |
| 2700 | } |
| 2701 | |
| 2702 | apex_key { |
| 2703 | name: "myapex.key", |
| 2704 | public_key: "testkey.avbpubkey", |
| 2705 | private_key: "testkey.pem", |
| 2706 | } |
| 2707 | |
| 2708 | cc_library { |
| 2709 | name: "mylib", |
| 2710 | srcs: ["mylib.cpp"], |
| 2711 | shared_libs: ["libcommon"], |
| 2712 | system_shared_libs: [], |
| 2713 | stl: "none", |
| 2714 | } |
| 2715 | |
| 2716 | cc_library { |
| 2717 | name: "libcommon", |
| 2718 | srcs: ["mylib_common.cpp"], |
| 2719 | system_shared_libs: [], |
| 2720 | stl: "none", |
| 2721 | } |
| 2722 | `) |
| 2723 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2724 | module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2725 | apexRule1 := module1.Rule("apexRule") |
| 2726 | copyCmds1 := apexRule1.Args["copy_commands"] |
| 2727 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2728 | module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2729 | apexRule2 := module2.Rule("apexRule") |
| 2730 | copyCmds2 := apexRule2.Args["copy_commands"] |
| 2731 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2732 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 2733 | ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2734 | ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so") |
| 2735 | ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so") |
| 2736 | ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so") |
| 2737 | } |
| 2738 | |
| 2739 | func TestApexUsesFailsIfNotProvided(t *testing.T) { |
| 2740 | testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, ` |
| 2741 | apex { |
| 2742 | name: "myapex", |
| 2743 | key: "myapex.key", |
| 2744 | uses: ["commonapex"], |
| 2745 | } |
| 2746 | |
| 2747 | apex { |
| 2748 | name: "commonapex", |
| 2749 | key: "myapex.key", |
| 2750 | } |
| 2751 | |
| 2752 | apex_key { |
| 2753 | name: "myapex.key", |
| 2754 | public_key: "testkey.avbpubkey", |
| 2755 | private_key: "testkey.pem", |
| 2756 | } |
| 2757 | `) |
| 2758 | testApexError(t, `uses: "commonapex" is not a provider`, ` |
| 2759 | apex { |
| 2760 | name: "myapex", |
| 2761 | key: "myapex.key", |
| 2762 | uses: ["commonapex"], |
| 2763 | } |
| 2764 | |
| 2765 | cc_library { |
| 2766 | name: "commonapex", |
| 2767 | system_shared_libs: [], |
| 2768 | stl: "none", |
| 2769 | } |
| 2770 | |
| 2771 | apex_key { |
| 2772 | name: "myapex.key", |
| 2773 | public_key: "testkey.avbpubkey", |
| 2774 | private_key: "testkey.pem", |
| 2775 | } |
| 2776 | `) |
| 2777 | } |
| 2778 | |
| 2779 | func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) { |
| 2780 | testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, ` |
| 2781 | apex { |
| 2782 | name: "myapex", |
| 2783 | key: "myapex.key", |
| 2784 | use_vendor: true, |
| 2785 | uses: ["commonapex"], |
| 2786 | } |
| 2787 | |
| 2788 | apex { |
| 2789 | name: "commonapex", |
| 2790 | key: "myapex.key", |
| 2791 | provide_cpp_shared_libs: true, |
| 2792 | } |
| 2793 | |
| 2794 | apex_key { |
| 2795 | name: "myapex.key", |
| 2796 | public_key: "testkey.avbpubkey", |
| 2797 | private_key: "testkey.pem", |
| 2798 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2799 | `, func(fs map[string][]byte, config android.Config) { |
| 2800 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 2801 | }) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2802 | } |
| 2803 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 2804 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 2805 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 2806 | apex { |
| 2807 | name: "myapex", |
| 2808 | key: "myapex.key", |
| 2809 | native_shared_libs: ["libfoo"], |
| 2810 | } |
| 2811 | |
| 2812 | apex_key { |
| 2813 | name: "myapex.key", |
| 2814 | public_key: "testkey.avbpubkey", |
| 2815 | private_key: "testkey.pem", |
| 2816 | } |
| 2817 | |
| 2818 | cc_library { |
| 2819 | name: "libfoo", |
| 2820 | stl: "none", |
| 2821 | system_shared_libs: [], |
| 2822 | enabled: false, |
| 2823 | } |
| 2824 | `) |
| 2825 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 2826 | apex { |
| 2827 | name: "myapex", |
| 2828 | key: "myapex.key", |
| 2829 | java_libs: ["myjar"], |
| 2830 | } |
| 2831 | |
| 2832 | apex_key { |
| 2833 | name: "myapex.key", |
| 2834 | public_key: "testkey.avbpubkey", |
| 2835 | private_key: "testkey.pem", |
| 2836 | } |
| 2837 | |
| 2838 | java_library { |
| 2839 | name: "myjar", |
| 2840 | srcs: ["foo/bar/MyClass.java"], |
| 2841 | sdk_version: "none", |
| 2842 | system_modules: "none", |
| 2843 | compile_dex: true, |
| 2844 | enabled: false, |
| 2845 | } |
| 2846 | `) |
| 2847 | } |
| 2848 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2849 | func TestApexWithApps(t *testing.T) { |
| 2850 | ctx, _ := testApex(t, ` |
| 2851 | apex { |
| 2852 | name: "myapex", |
| 2853 | key: "myapex.key", |
| 2854 | apps: [ |
| 2855 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 2856 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2857 | ], |
| 2858 | } |
| 2859 | |
| 2860 | apex_key { |
| 2861 | name: "myapex.key", |
| 2862 | public_key: "testkey.avbpubkey", |
| 2863 | private_key: "testkey.pem", |
| 2864 | } |
| 2865 | |
| 2866 | android_app { |
| 2867 | name: "AppFoo", |
| 2868 | srcs: ["foo/bar/MyClass.java"], |
| 2869 | sdk_version: "none", |
| 2870 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 2871 | jni_libs: ["libjni"], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2872 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 2873 | |
| 2874 | android_app { |
| 2875 | name: "AppFooPriv", |
| 2876 | srcs: ["foo/bar/MyClass.java"], |
| 2877 | sdk_version: "none", |
| 2878 | system_modules: "none", |
| 2879 | privileged: true, |
| 2880 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 2881 | |
| 2882 | cc_library_shared { |
| 2883 | name: "libjni", |
| 2884 | srcs: ["mylib.cpp"], |
| 2885 | stl: "none", |
| 2886 | system_shared_libs: [], |
| 2887 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2888 | `) |
| 2889 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2890 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2891 | apexRule := module.Rule("apexRule") |
| 2892 | copyCmds := apexRule.Args["copy_commands"] |
| 2893 | |
| 2894 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 2895 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 2896 | |
| 2897 | // JNI libraries are embedded inside APK |
| 2898 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Rule("zip") |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2899 | libjniOutput := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile() |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 2900 | ensureListContains(t, appZipRule.Implicits.Strings(), libjniOutput.String()) |
| 2901 | // ... uncompressed |
| 2902 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
| 2903 | t.Errorf("jni lib is not uncompressed for AppFoo") |
| 2904 | } |
| 2905 | // ... and not directly inside the APEX |
| 2906 | ensureNotContains(t, copyCmds, "image.apex/lib64/libjni.so") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 2907 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2908 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 2909 | func TestApexWithAppImports(t *testing.T) { |
| 2910 | ctx, _ := testApex(t, ` |
| 2911 | apex { |
| 2912 | name: "myapex", |
| 2913 | key: "myapex.key", |
| 2914 | apps: [ |
| 2915 | "AppFooPrebuilt", |
| 2916 | "AppFooPrivPrebuilt", |
| 2917 | ], |
| 2918 | } |
| 2919 | |
| 2920 | apex_key { |
| 2921 | name: "myapex.key", |
| 2922 | public_key: "testkey.avbpubkey", |
| 2923 | private_key: "testkey.pem", |
| 2924 | } |
| 2925 | |
| 2926 | android_app_import { |
| 2927 | name: "AppFooPrebuilt", |
| 2928 | apk: "PrebuiltAppFoo.apk", |
| 2929 | presigned: true, |
| 2930 | dex_preopt: { |
| 2931 | enabled: false, |
| 2932 | }, |
| 2933 | } |
| 2934 | |
| 2935 | android_app_import { |
| 2936 | name: "AppFooPrivPrebuilt", |
| 2937 | apk: "PrebuiltAppFooPriv.apk", |
| 2938 | privileged: true, |
| 2939 | presigned: true, |
| 2940 | dex_preopt: { |
| 2941 | enabled: false, |
| 2942 | }, |
| 2943 | } |
| 2944 | `) |
| 2945 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2946 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 2947 | apexRule := module.Rule("apexRule") |
| 2948 | copyCmds := apexRule.Args["copy_commands"] |
| 2949 | |
| 2950 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
| 2951 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2952 | } |
| 2953 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2954 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 2955 | // libfoo's apex_available comes from cc_defaults |
| 2956 | testApexError(t, `"myapex" .*: requires "libfoo" that is not available for the APEX`, ` |
| 2957 | apex { |
| 2958 | name: "myapex", |
| 2959 | key: "myapex.key", |
| 2960 | native_shared_libs: ["libfoo"], |
| 2961 | } |
| 2962 | |
| 2963 | apex_key { |
| 2964 | name: "myapex.key", |
| 2965 | public_key: "testkey.avbpubkey", |
| 2966 | private_key: "testkey.pem", |
| 2967 | } |
| 2968 | |
| 2969 | apex { |
| 2970 | name: "otherapex", |
| 2971 | key: "myapex.key", |
| 2972 | native_shared_libs: ["libfoo"], |
| 2973 | } |
| 2974 | |
| 2975 | cc_defaults { |
| 2976 | name: "libfoo-defaults", |
| 2977 | apex_available: ["otherapex"], |
| 2978 | } |
| 2979 | |
| 2980 | cc_library { |
| 2981 | name: "libfoo", |
| 2982 | defaults: ["libfoo-defaults"], |
| 2983 | stl: "none", |
| 2984 | system_shared_libs: [], |
| 2985 | }`) |
| 2986 | } |
| 2987 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 2988 | func TestApexAvailable(t *testing.T) { |
| 2989 | // libfoo is not available to myapex, but only to otherapex |
| 2990 | testApexError(t, "requires \"libfoo\" that is not available for the APEX", ` |
| 2991 | apex { |
| 2992 | name: "myapex", |
| 2993 | key: "myapex.key", |
| 2994 | native_shared_libs: ["libfoo"], |
| 2995 | } |
| 2996 | |
| 2997 | apex_key { |
| 2998 | name: "myapex.key", |
| 2999 | public_key: "testkey.avbpubkey", |
| 3000 | private_key: "testkey.pem", |
| 3001 | } |
| 3002 | |
| 3003 | apex { |
| 3004 | name: "otherapex", |
| 3005 | key: "otherapex.key", |
| 3006 | native_shared_libs: ["libfoo"], |
| 3007 | } |
| 3008 | |
| 3009 | apex_key { |
| 3010 | name: "otherapex.key", |
| 3011 | public_key: "testkey.avbpubkey", |
| 3012 | private_key: "testkey.pem", |
| 3013 | } |
| 3014 | |
| 3015 | cc_library { |
| 3016 | name: "libfoo", |
| 3017 | stl: "none", |
| 3018 | system_shared_libs: [], |
| 3019 | apex_available: ["otherapex"], |
| 3020 | }`) |
| 3021 | |
| 3022 | // libbar is an indirect dep |
| 3023 | testApexError(t, "requires \"libbar\" that is not available for the APEX", ` |
| 3024 | apex { |
| 3025 | name: "myapex", |
| 3026 | key: "myapex.key", |
| 3027 | native_shared_libs: ["libfoo"], |
| 3028 | } |
| 3029 | |
| 3030 | apex_key { |
| 3031 | name: "myapex.key", |
| 3032 | public_key: "testkey.avbpubkey", |
| 3033 | private_key: "testkey.pem", |
| 3034 | } |
| 3035 | |
| 3036 | apex { |
| 3037 | name: "otherapex", |
| 3038 | key: "otherapex.key", |
| 3039 | native_shared_libs: ["libfoo"], |
| 3040 | } |
| 3041 | |
| 3042 | apex_key { |
| 3043 | name: "otherapex.key", |
| 3044 | public_key: "testkey.avbpubkey", |
| 3045 | private_key: "testkey.pem", |
| 3046 | } |
| 3047 | |
| 3048 | cc_library { |
| 3049 | name: "libfoo", |
| 3050 | stl: "none", |
| 3051 | shared_libs: ["libbar"], |
| 3052 | system_shared_libs: [], |
| 3053 | apex_available: ["myapex", "otherapex"], |
| 3054 | } |
| 3055 | |
| 3056 | cc_library { |
| 3057 | name: "libbar", |
| 3058 | stl: "none", |
| 3059 | system_shared_libs: [], |
| 3060 | apex_available: ["otherapex"], |
| 3061 | }`) |
| 3062 | |
| 3063 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 3064 | apex { |
| 3065 | name: "myapex", |
| 3066 | key: "myapex.key", |
| 3067 | native_shared_libs: ["libfoo"], |
| 3068 | } |
| 3069 | |
| 3070 | apex_key { |
| 3071 | name: "myapex.key", |
| 3072 | public_key: "testkey.avbpubkey", |
| 3073 | private_key: "testkey.pem", |
| 3074 | } |
| 3075 | |
| 3076 | cc_library { |
| 3077 | name: "libfoo", |
| 3078 | stl: "none", |
| 3079 | system_shared_libs: [], |
| 3080 | apex_available: ["otherapex"], |
| 3081 | }`) |
| 3082 | |
| 3083 | ctx, _ := testApex(t, ` |
| 3084 | apex { |
| 3085 | name: "myapex", |
| 3086 | key: "myapex.key", |
| 3087 | native_shared_libs: ["libfoo", "libbar"], |
| 3088 | } |
| 3089 | |
| 3090 | apex_key { |
| 3091 | name: "myapex.key", |
| 3092 | public_key: "testkey.avbpubkey", |
| 3093 | private_key: "testkey.pem", |
| 3094 | } |
| 3095 | |
| 3096 | cc_library { |
| 3097 | name: "libfoo", |
| 3098 | stl: "none", |
| 3099 | system_shared_libs: [], |
| 3100 | apex_available: ["myapex"], |
| 3101 | } |
| 3102 | |
| 3103 | cc_library { |
| 3104 | name: "libbar", |
| 3105 | stl: "none", |
| 3106 | system_shared_libs: [], |
| 3107 | apex_available: ["//apex_available:anyapex"], |
| 3108 | }`) |
| 3109 | |
| 3110 | // check that libfoo and libbar are created only for myapex, but not for the platform |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3111 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex") |
| 3112 | ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared") |
| 3113 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex") |
| 3114 | ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared") |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3115 | |
| 3116 | ctx, _ = testApex(t, ` |
| 3117 | apex { |
| 3118 | name: "myapex", |
| 3119 | key: "myapex.key", |
| 3120 | } |
| 3121 | |
| 3122 | apex_key { |
| 3123 | name: "myapex.key", |
| 3124 | public_key: "testkey.avbpubkey", |
| 3125 | private_key: "testkey.pem", |
| 3126 | } |
| 3127 | |
| 3128 | cc_library { |
| 3129 | name: "libfoo", |
| 3130 | stl: "none", |
| 3131 | system_shared_libs: [], |
| 3132 | apex_available: ["//apex_available:platform"], |
| 3133 | }`) |
| 3134 | |
| 3135 | // check that libfoo is created only for the platform |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3136 | ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex") |
| 3137 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared") |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 3138 | |
| 3139 | ctx, _ = testApex(t, ` |
| 3140 | apex { |
| 3141 | name: "myapex", |
| 3142 | key: "myapex.key", |
| 3143 | native_shared_libs: ["libfoo"], |
| 3144 | } |
| 3145 | |
| 3146 | apex_key { |
| 3147 | name: "myapex.key", |
| 3148 | public_key: "testkey.avbpubkey", |
| 3149 | private_key: "testkey.pem", |
| 3150 | } |
| 3151 | |
| 3152 | cc_library { |
| 3153 | name: "libfoo", |
| 3154 | stl: "none", |
| 3155 | system_shared_libs: [], |
| 3156 | apex_available: ["myapex"], |
| 3157 | static: { |
| 3158 | apex_available: ["//apex_available:platform"], |
| 3159 | }, |
| 3160 | }`) |
| 3161 | |
| 3162 | // shared variant of libfoo is only available to myapex |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3163 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex") |
| 3164 | ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared") |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 3165 | // but the static variant is available to both myapex and the platform |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3166 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex") |
| 3167 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static") |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3168 | } |
| 3169 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3170 | func TestOverrideApex(t *testing.T) { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3171 | ctx, config := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3172 | apex { |
| 3173 | name: "myapex", |
| 3174 | key: "myapex.key", |
| 3175 | apps: ["app"], |
| 3176 | } |
| 3177 | |
| 3178 | override_apex { |
| 3179 | name: "override_myapex", |
| 3180 | base: "myapex", |
| 3181 | apps: ["override_app"], |
| 3182 | } |
| 3183 | |
| 3184 | apex_key { |
| 3185 | name: "myapex.key", |
| 3186 | public_key: "testkey.avbpubkey", |
| 3187 | private_key: "testkey.pem", |
| 3188 | } |
| 3189 | |
| 3190 | android_app { |
| 3191 | name: "app", |
| 3192 | srcs: ["foo/bar/MyClass.java"], |
| 3193 | package_name: "foo", |
| 3194 | sdk_version: "none", |
| 3195 | system_modules: "none", |
| 3196 | } |
| 3197 | |
| 3198 | override_android_app { |
| 3199 | name: "override_app", |
| 3200 | base: "app", |
| 3201 | package_name: "bar", |
| 3202 | } |
| 3203 | `) |
| 3204 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 3205 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 3206 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 3207 | if originalVariant.GetOverriddenBy() != "" { |
| 3208 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 3209 | } |
| 3210 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 3211 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 3212 | } |
| 3213 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3214 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 3215 | apexRule := module.Rule("apexRule") |
| 3216 | copyCmds := apexRule.Args["copy_commands"] |
| 3217 | |
| 3218 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
| 3219 | ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3220 | |
| 3221 | apexBundle := module.Module().(*apexBundle) |
| 3222 | name := apexBundle.Name() |
| 3223 | if name != "override_myapex" { |
| 3224 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 3225 | } |
| 3226 | |
| 3227 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3228 | var builder strings.Builder |
| 3229 | data.Custom(&builder, name, "TARGET_", "", data) |
| 3230 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 3231 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3232 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 3233 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
| 3234 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 3235 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3236 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 3237 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3238 | } |
| 3239 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3240 | func TestLegacyAndroid10Support(t *testing.T) { |
| 3241 | ctx, _ := testApex(t, ` |
| 3242 | apex { |
| 3243 | name: "myapex", |
| 3244 | key: "myapex.key", |
| 3245 | legacy_android10_support: true, |
| 3246 | } |
| 3247 | |
| 3248 | apex_key { |
| 3249 | name: "myapex.key", |
| 3250 | public_key: "testkey.avbpubkey", |
| 3251 | private_key: "testkey.pem", |
| 3252 | } |
| 3253 | `) |
| 3254 | |
| 3255 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3256 | args := module.Rule("apexRule").Args |
| 3257 | ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String()) |
| 3258 | } |
| 3259 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 3260 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 3261 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 3262 | apex { |
| 3263 | name: "myapex", |
| 3264 | key: "myapex.key", |
| 3265 | java_libs: ["myjar"], |
| 3266 | } |
| 3267 | |
| 3268 | apex_key { |
| 3269 | name: "myapex.key", |
| 3270 | public_key: "testkey.avbpubkey", |
| 3271 | private_key: "testkey.pem", |
| 3272 | } |
| 3273 | |
| 3274 | java_library { |
| 3275 | name: "myjar", |
| 3276 | srcs: ["foo/bar/MyClass.java"], |
| 3277 | sdk_version: "none", |
| 3278 | system_modules: "none", |
| 3279 | } |
| 3280 | `) |
| 3281 | } |
| 3282 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 3283 | func TestMain(m *testing.M) { |
| 3284 | run := func() int { |
| 3285 | setUp() |
| 3286 | defer tearDown() |
| 3287 | |
| 3288 | return m.Run() |
| 3289 | } |
| 3290 | |
| 3291 | os.Exit(run()) |
| 3292 | } |