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