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