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