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