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