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