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