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