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