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