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