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" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 30 | "android/soong/dexpreopt" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 31 | "android/soong/java" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 32 | ) |
| 33 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 34 | var buildDir string |
| 35 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 36 | // names returns name list from white space separated string |
| 37 | func names(s string) (ns []string) { |
| 38 | for _, n := range strings.Split(s, " ") { |
| 39 | if len(n) > 0 { |
| 40 | ns = append(ns, n) |
| 41 | } |
| 42 | } |
| 43 | return |
| 44 | } |
| 45 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 46 | func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) { |
| 47 | t.Helper() |
| 48 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 49 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 50 | if len(errs) > 0 { |
| 51 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 52 | return |
| 53 | } |
| 54 | _, errs = ctx.PrepareBuildActions(config) |
| 55 | if len(errs) > 0 { |
| 56 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 61 | } |
| 62 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 63 | func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
| 64 | t.Helper() |
| 65 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 66 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 67 | android.FailIfErrored(t, errs) |
| 68 | _, errs = ctx.PrepareBuildActions(config) |
| 69 | android.FailIfErrored(t, errs) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 70 | return ctx, config |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 71 | } |
| 72 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 73 | type testCustomizer func(fs map[string][]byte, config android.Config) |
| 74 | |
| 75 | func withFiles(files map[string][]byte) testCustomizer { |
| 76 | return func(fs map[string][]byte, config android.Config) { |
| 77 | for k, v := range files { |
| 78 | fs[k] = v |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | func withTargets(targets map[android.OsType][]android.Target) testCustomizer { |
| 84 | return func(fs map[string][]byte, config android.Config) { |
| 85 | for k, v := range targets { |
| 86 | config.Targets[k] = v |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 91 | // withNativeBridgeTargets sets configuration with targets including: |
| 92 | // - X86_64 (primary) |
| 93 | // - X86 (secondary) |
| 94 | // - Arm64 on X86_64 (native bridge) |
| 95 | // - Arm on X86 (native bridge) |
| 96 | func withNativeBridgeEnabled(fs map[string][]byte, config android.Config) { |
| 97 | config.Targets[android.Android] = []android.Target{ |
| 98 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, |
| 99 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 100 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, |
| 101 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 102 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, |
| 103 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"}, |
| 104 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 105 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"}, |
| 106 | } |
| 107 | } |
| 108 | |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 109 | func withManifestPackageNameOverrides(specs []string) testCustomizer { |
| 110 | return func(fs map[string][]byte, config android.Config) { |
| 111 | config.TestProductVariables.ManifestPackageNameOverrides = specs |
| 112 | } |
| 113 | } |
| 114 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 115 | func withBinder32bit(fs map[string][]byte, config android.Config) { |
| 116 | config.TestProductVariables.Binder32bit = proptools.BoolPtr(true) |
| 117 | } |
| 118 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 119 | func withUnbundledBuild(fs map[string][]byte, config android.Config) { |
| 120 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 121 | } |
| 122 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 123 | 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] | 124 | android.ClearApexDependency() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 125 | |
| 126 | bp = bp + ` |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 127 | filegroup { |
| 128 | name: "myapex-file_contexts", |
| 129 | srcs: [ |
| 130 | "system/sepolicy/apex/myapex-file_contexts", |
| 131 | ], |
| 132 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 133 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 134 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 135 | bp = bp + cc.GatherRequiredDepsForTest(android.Android) |
| 136 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 137 | bp = bp + java.GatherRequiredDepsForTest() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 138 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 139 | fs := map[string][]byte{ |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 140 | "a.java": nil, |
| 141 | "PrebuiltAppFoo.apk": nil, |
| 142 | "PrebuiltAppFooPriv.apk": nil, |
| 143 | "build/make/target/product/security": nil, |
| 144 | "apex_manifest.json": nil, |
| 145 | "AndroidManifest.xml": nil, |
| 146 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 147 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 148 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 149 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 150 | "system/sepolicy/apex/commonapex-file_contexts": nil, |
| 151 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 152 | "mylib.cpp": nil, |
| 153 | "mylib_common.cpp": nil, |
| 154 | "mytest.cpp": nil, |
| 155 | "mytest1.cpp": nil, |
| 156 | "mytest2.cpp": nil, |
| 157 | "mytest3.cpp": nil, |
| 158 | "myprebuilt": nil, |
| 159 | "my_include": nil, |
| 160 | "foo/bar/MyClass.java": nil, |
| 161 | "prebuilt.jar": nil, |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 162 | "prebuilt.so": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 163 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 164 | "vendor/foo/devkeys/test.pk8": nil, |
| 165 | "testkey.x509.pem": nil, |
| 166 | "testkey.pk8": nil, |
| 167 | "testkey.override.x509.pem": nil, |
| 168 | "testkey.override.pk8": nil, |
| 169 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 170 | "vendor/foo/devkeys/testkey.pem": nil, |
| 171 | "NOTICE": nil, |
| 172 | "custom_notice": nil, |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 173 | "custom_notice_for_static_lib": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 174 | "testkey2.avbpubkey": nil, |
| 175 | "testkey2.pem": nil, |
| 176 | "myapex-arm64.apex": nil, |
| 177 | "myapex-arm.apex": nil, |
| 178 | "frameworks/base/api/current.txt": nil, |
| 179 | "framework/aidl/a.aidl": nil, |
| 180 | "build/make/core/proguard.flags": nil, |
| 181 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 182 | "dummy.txt": nil, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 183 | } |
| 184 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 185 | cc.GatherRequiredFilesForTest(fs) |
| 186 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 187 | for _, handler := range handlers { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 188 | // The fs now needs to be populated before creating the config, call handlers twice |
| 189 | // for now, once to get any fs changes, and later after the config was created to |
| 190 | // set product variables or targets. |
| 191 | tempConfig := android.TestArchConfig(buildDir, nil, bp, fs) |
| 192 | handler(fs, tempConfig) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 193 | } |
| 194 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 195 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 196 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 197 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 198 | config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 199 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 200 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
| 201 | config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") |
| 202 | |
| 203 | for _, handler := range handlers { |
| 204 | // The fs now needs to be populated before creating the config, call handlers twice |
| 205 | // for now, earlier to get any fs changes, and now after the config was created to |
| 206 | // set product variables or targets. |
| 207 | tempFS := map[string][]byte{} |
| 208 | handler(tempFS, config) |
| 209 | } |
| 210 | |
| 211 | ctx := android.NewTestArchContext() |
| 212 | ctx.RegisterModuleType("apex", BundleFactory) |
| 213 | ctx.RegisterModuleType("apex_test", testApexBundleFactory) |
| 214 | ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
| 215 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 216 | ctx.RegisterModuleType("apex_defaults", defaultsFactory) |
| 217 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
| 218 | ctx.RegisterModuleType("override_apex", overrideApexFactory) |
| 219 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 220 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 221 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 222 | |
Paul Duffin | 77980a8 | 2019-12-19 16:01:36 +0000 | [diff] [blame] | 223 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 224 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 225 | ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) |
| 226 | ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 227 | ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory) |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 228 | ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 229 | ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 230 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 231 | java.RegisterJavaBuildComponents(ctx) |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 232 | java.RegisterSystemModulesBuildComponents(ctx) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 233 | java.RegisterAppBuildComponents(ctx) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 234 | ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 235 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 236 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 237 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 238 | |
| 239 | ctx.Register(config) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 240 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 241 | return ctx, config |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 242 | } |
| 243 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 244 | func setUp() { |
| 245 | var err error |
| 246 | buildDir, err = ioutil.TempDir("", "soong_apex_test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 247 | if err != nil { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 248 | panic(err) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 249 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 250 | } |
| 251 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 252 | func tearDown() { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 253 | os.RemoveAll(buildDir) |
| 254 | } |
| 255 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 256 | // ensure that 'result' equals 'expected' |
| 257 | func ensureEquals(t *testing.T, result string, expected string) { |
| 258 | t.Helper() |
| 259 | if result != expected { |
| 260 | t.Errorf("%q != %q", expected, result) |
| 261 | } |
| 262 | } |
| 263 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 264 | // ensure that 'result' contains 'expected' |
| 265 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 266 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 267 | if !strings.Contains(result, expected) { |
| 268 | t.Errorf("%q is not found in %q", expected, result) |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | // ensures that 'result' does not contain 'notExpected' |
| 273 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 274 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 275 | if strings.Contains(result, notExpected) { |
| 276 | t.Errorf("%q is found in %q", notExpected, result) |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 281 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 282 | if !android.InList(expected, result) { |
| 283 | t.Errorf("%q is not found in %v", expected, result) |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 288 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 289 | if android.InList(notExpected, result) { |
| 290 | t.Errorf("%q is found in %v", notExpected, result) |
| 291 | } |
| 292 | } |
| 293 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 294 | func ensureListEmpty(t *testing.T, result []string) { |
| 295 | t.Helper() |
| 296 | if len(result) > 0 { |
| 297 | t.Errorf("%q is expected to be empty", result) |
| 298 | } |
| 299 | } |
| 300 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 301 | // Minimal test |
| 302 | func TestBasicApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 303 | ctx, _ := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 304 | apex_defaults { |
| 305 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 306 | manifest: ":myapex.manifest", |
| 307 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 308 | key: "myapex.key", |
| 309 | native_shared_libs: ["mylib"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 310 | multilib: { |
| 311 | both: { |
| 312 | binaries: ["foo",], |
| 313 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 314 | }, |
Jooyung Han | 5a80d9f | 2019-12-23 15:38:34 +0900 | [diff] [blame] | 315 | java_libs: ["myjar"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 316 | } |
| 317 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 318 | apex { |
| 319 | name: "myapex", |
| 320 | defaults: ["myapex-defaults"], |
| 321 | } |
| 322 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 323 | apex_key { |
| 324 | name: "myapex.key", |
| 325 | public_key: "testkey.avbpubkey", |
| 326 | private_key: "testkey.pem", |
| 327 | } |
| 328 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 329 | filegroup { |
| 330 | name: "myapex.manifest", |
| 331 | srcs: ["apex_manifest.json"], |
| 332 | } |
| 333 | |
| 334 | filegroup { |
| 335 | name: "myapex.androidmanifest", |
| 336 | srcs: ["AndroidManifest.xml"], |
| 337 | } |
| 338 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 339 | cc_library { |
| 340 | name: "mylib", |
| 341 | srcs: ["mylib.cpp"], |
| 342 | shared_libs: ["mylib2"], |
| 343 | system_shared_libs: [], |
| 344 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 345 | // TODO: remove //apex_available:platform |
| 346 | apex_available: [ |
| 347 | "//apex_available:platform", |
| 348 | "myapex", |
| 349 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 350 | } |
| 351 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 352 | cc_binary { |
| 353 | name: "foo", |
| 354 | srcs: ["mylib.cpp"], |
| 355 | compile_multilib: "both", |
| 356 | multilib: { |
| 357 | lib32: { |
| 358 | suffix: "32", |
| 359 | }, |
| 360 | lib64: { |
| 361 | suffix: "64", |
| 362 | }, |
| 363 | }, |
| 364 | symlinks: ["foo_link_"], |
| 365 | symlink_preferred_arch: true, |
| 366 | system_shared_libs: [], |
| 367 | static_executable: true, |
| 368 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 369 | apex_available: [ "myapex" ], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 370 | } |
| 371 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 372 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 373 | name: "mylib2", |
| 374 | srcs: ["mylib.cpp"], |
| 375 | system_shared_libs: [], |
| 376 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 377 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 378 | static_libs: ["libstatic"], |
| 379 | // TODO: remove //apex_available:platform |
| 380 | apex_available: [ |
| 381 | "//apex_available:platform", |
| 382 | "myapex", |
| 383 | ], |
| 384 | } |
| 385 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 386 | cc_prebuilt_library_shared { |
| 387 | name: "mylib2", |
| 388 | srcs: ["prebuilt.so"], |
| 389 | // TODO: remove //apex_available:platform |
| 390 | apex_available: [ |
| 391 | "//apex_available:platform", |
| 392 | "myapex", |
| 393 | ], |
| 394 | } |
| 395 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 396 | cc_library_static { |
| 397 | name: "libstatic", |
| 398 | srcs: ["mylib.cpp"], |
| 399 | system_shared_libs: [], |
| 400 | stl: "none", |
| 401 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 402 | // TODO: remove //apex_available:platform |
| 403 | apex_available: [ |
| 404 | "//apex_available:platform", |
| 405 | "myapex", |
| 406 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 407 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 408 | |
| 409 | java_library { |
| 410 | name: "myjar", |
| 411 | srcs: ["foo/bar/MyClass.java"], |
| 412 | sdk_version: "none", |
| 413 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 414 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 415 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 416 | // TODO: remove //apex_available:platform |
| 417 | apex_available: [ |
| 418 | "//apex_available:platform", |
| 419 | "myapex", |
| 420 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | java_library { |
| 424 | name: "myotherjar", |
| 425 | srcs: ["foo/bar/MyClass.java"], |
| 426 | sdk_version: "none", |
| 427 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 428 | // TODO: remove //apex_available:platform |
| 429 | apex_available: [ |
| 430 | "//apex_available:platform", |
| 431 | "myapex", |
| 432 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 433 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 434 | |
| 435 | java_library { |
| 436 | name: "mysharedjar", |
| 437 | srcs: ["foo/bar/MyClass.java"], |
| 438 | sdk_version: "none", |
| 439 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 440 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 441 | `) |
| 442 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 443 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 444 | |
| 445 | optFlags := apexRule.Args["opt_flags"] |
| 446 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 447 | // Ensure that the NOTICE output is being packaged as an asset. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 448 | 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] | 449 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 450 | copyCmds := apexRule.Args["copy_commands"] |
| 451 | |
| 452 | // Ensure that main rule creates an output |
| 453 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 454 | |
| 455 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 456 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 457 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 458 | |
| 459 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 460 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 461 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 462 | |
| 463 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 464 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 465 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 466 | ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar") |
| 467 | // .. but not for java libs |
| 468 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 469 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 470 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 471 | // Ensure that the platform variant ends with _shared or _common |
| 472 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 473 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 474 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 475 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 476 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 477 | |
| 478 | // Ensure that dynamic dependency to java libs are not included |
| 479 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 480 | |
| 481 | // Ensure that all symlinks are present. |
| 482 | found_foo_link_64 := false |
| 483 | found_foo := false |
| 484 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 485 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 486 | if strings.HasSuffix(cmd, "bin/foo") { |
| 487 | found_foo = true |
| 488 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 489 | found_foo_link_64 = true |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | good := found_foo && found_foo_link_64 |
| 494 | if !good { |
| 495 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 496 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 497 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 498 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 499 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 500 | if len(noticeInputs) != 3 { |
| 501 | t.Errorf("number of input notice files: expected = 3, actual = %q", len(noticeInputs)) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 502 | } |
| 503 | ensureListContains(t, noticeInputs, "NOTICE") |
| 504 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 505 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 506 | |
| 507 | depsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("myapex-deps-info.txt").Args["content"], "\\n") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 508 | ensureListContains(t, depsInfo, "myjar <- myapex") |
| 509 | ensureListContains(t, depsInfo, "mylib <- myapex") |
| 510 | ensureListContains(t, depsInfo, "mylib2 <- mylib") |
| 511 | ensureListContains(t, depsInfo, "myotherjar <- myjar") |
| 512 | ensureListContains(t, depsInfo, "mysharedjar (external) <- myjar") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 515 | func TestDefaults(t *testing.T) { |
| 516 | ctx, _ := testApex(t, ` |
| 517 | apex_defaults { |
| 518 | name: "myapex-defaults", |
| 519 | key: "myapex.key", |
| 520 | prebuilts: ["myetc"], |
| 521 | native_shared_libs: ["mylib"], |
| 522 | java_libs: ["myjar"], |
| 523 | apps: ["AppFoo"], |
| 524 | } |
| 525 | |
| 526 | prebuilt_etc { |
| 527 | name: "myetc", |
| 528 | src: "myprebuilt", |
| 529 | } |
| 530 | |
| 531 | apex { |
| 532 | name: "myapex", |
| 533 | defaults: ["myapex-defaults"], |
| 534 | } |
| 535 | |
| 536 | apex_key { |
| 537 | name: "myapex.key", |
| 538 | public_key: "testkey.avbpubkey", |
| 539 | private_key: "testkey.pem", |
| 540 | } |
| 541 | |
| 542 | cc_library { |
| 543 | name: "mylib", |
| 544 | system_shared_libs: [], |
| 545 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 546 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | java_library { |
| 550 | name: "myjar", |
| 551 | srcs: ["foo/bar/MyClass.java"], |
| 552 | sdk_version: "none", |
| 553 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 554 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | android_app { |
| 558 | name: "AppFoo", |
| 559 | srcs: ["foo/bar/MyClass.java"], |
| 560 | sdk_version: "none", |
| 561 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 562 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 563 | } |
| 564 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 565 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 566 | "etc/myetc", |
| 567 | "javalib/myjar.jar", |
| 568 | "lib64/mylib.so", |
| 569 | "app/AppFoo/AppFoo.apk", |
| 570 | }) |
| 571 | } |
| 572 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 573 | func TestApexManifest(t *testing.T) { |
| 574 | ctx, _ := testApex(t, ` |
| 575 | apex { |
| 576 | name: "myapex", |
| 577 | key: "myapex.key", |
| 578 | } |
| 579 | |
| 580 | apex_key { |
| 581 | name: "myapex.key", |
| 582 | public_key: "testkey.avbpubkey", |
| 583 | private_key: "testkey.pem", |
| 584 | } |
| 585 | `) |
| 586 | |
| 587 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 588 | args := module.Rule("apexRule").Args |
| 589 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 590 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 591 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 592 | } |
| 593 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 594 | func TestBasicZipApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 595 | ctx, _ := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 596 | apex { |
| 597 | name: "myapex", |
| 598 | key: "myapex.key", |
| 599 | payload_type: "zip", |
| 600 | native_shared_libs: ["mylib"], |
| 601 | } |
| 602 | |
| 603 | apex_key { |
| 604 | name: "myapex.key", |
| 605 | public_key: "testkey.avbpubkey", |
| 606 | private_key: "testkey.pem", |
| 607 | } |
| 608 | |
| 609 | cc_library { |
| 610 | name: "mylib", |
| 611 | srcs: ["mylib.cpp"], |
| 612 | shared_libs: ["mylib2"], |
| 613 | system_shared_libs: [], |
| 614 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 615 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | cc_library { |
| 619 | name: "mylib2", |
| 620 | srcs: ["mylib.cpp"], |
| 621 | system_shared_libs: [], |
| 622 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 623 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 624 | } |
| 625 | `) |
| 626 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 627 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 628 | copyCmds := zipApexRule.Args["copy_commands"] |
| 629 | |
| 630 | // Ensure that main rule creates an output |
| 631 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 632 | |
| 633 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 634 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 635 | |
| 636 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 637 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 638 | |
| 639 | // Ensure that both direct and indirect deps are copied into apex |
| 640 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 641 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | func TestApexWithStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 645 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 646 | apex { |
| 647 | name: "myapex", |
| 648 | key: "myapex.key", |
| 649 | native_shared_libs: ["mylib", "mylib3"], |
| 650 | } |
| 651 | |
| 652 | apex_key { |
| 653 | name: "myapex.key", |
| 654 | public_key: "testkey.avbpubkey", |
| 655 | private_key: "testkey.pem", |
| 656 | } |
| 657 | |
| 658 | cc_library { |
| 659 | name: "mylib", |
| 660 | srcs: ["mylib.cpp"], |
| 661 | shared_libs: ["mylib2", "mylib3"], |
| 662 | system_shared_libs: [], |
| 663 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 664 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 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 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 687 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 688 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 689 | |
| 690 | cc_library { |
| 691 | name: "mylib4", |
| 692 | srcs: ["mylib.cpp"], |
| 693 | system_shared_libs: [], |
| 694 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 695 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 696 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 697 | `) |
| 698 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 699 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 700 | copyCmds := apexRule.Args["copy_commands"] |
| 701 | |
| 702 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 703 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 704 | |
| 705 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 706 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 707 | |
| 708 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 709 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 710 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 711 | 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] | 712 | |
| 713 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 714 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 715 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 716 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 717 | |
| 718 | // 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] | 719 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 720 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 721 | 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] | 722 | |
| 723 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 724 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 725 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 726 | |
| 727 | // Ensure that genstub is invoked with --apex |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 728 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"]) |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 729 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 730 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 731 | "lib64/mylib.so", |
| 732 | "lib64/mylib3.so", |
| 733 | "lib64/mylib4.so", |
| 734 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 735 | } |
| 736 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 737 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 738 | ctx, _ := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 739 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 740 | name: "myapex2", |
| 741 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 742 | native_shared_libs: ["mylib"], |
| 743 | } |
| 744 | |
| 745 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 746 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 747 | public_key: "testkey.avbpubkey", |
| 748 | private_key: "testkey.pem", |
| 749 | } |
| 750 | |
| 751 | cc_library { |
| 752 | name: "mylib", |
| 753 | srcs: ["mylib.cpp"], |
| 754 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 755 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 756 | system_shared_libs: [], |
| 757 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 758 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | cc_library { |
| 762 | name: "libfoo", |
| 763 | srcs: ["mylib.cpp"], |
| 764 | shared_libs: ["libbar"], |
| 765 | system_shared_libs: [], |
| 766 | stl: "none", |
| 767 | stubs: { |
| 768 | versions: ["10", "20", "30"], |
| 769 | }, |
| 770 | } |
| 771 | |
| 772 | cc_library { |
| 773 | name: "libbar", |
| 774 | srcs: ["mylib.cpp"], |
| 775 | system_shared_libs: [], |
| 776 | stl: "none", |
| 777 | } |
| 778 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 779 | cc_library_static { |
| 780 | name: "libbaz", |
| 781 | srcs: ["mylib.cpp"], |
| 782 | system_shared_libs: [], |
| 783 | stl: "none", |
| 784 | apex_available: [ "myapex2" ], |
| 785 | } |
| 786 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 787 | `) |
| 788 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 789 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 790 | copyCmds := apexRule.Args["copy_commands"] |
| 791 | |
| 792 | // Ensure that direct non-stubs dep is always included |
| 793 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 794 | |
| 795 | // Ensure that indirect stubs dep is not included |
| 796 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 797 | |
| 798 | // Ensure that dependency of stubs is not included |
| 799 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 800 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 801 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 802 | |
| 803 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 804 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 805 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 806 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 807 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 808 | libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 809 | |
| 810 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 811 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 812 | |
| 813 | depsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("myapex2-deps-info.txt").Args["content"], "\\n") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 814 | |
| 815 | ensureListContains(t, depsInfo, "mylib <- myapex2") |
| 816 | ensureListContains(t, depsInfo, "libbaz <- mylib") |
| 817 | ensureListContains(t, depsInfo, "libfoo (external) <- mylib") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 818 | } |
| 819 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 820 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 821 | /* |
| 822 | myapex |
| 823 | | |
| 824 | v (runtime_libs) |
| 825 | mylib ------+------> libfoo [provides stub] |
| 826 | | |
| 827 | `------> libbar |
| 828 | */ |
| 829 | ctx, _ := testApex(t, ` |
| 830 | apex { |
| 831 | name: "myapex", |
| 832 | key: "myapex.key", |
| 833 | native_shared_libs: ["mylib"], |
| 834 | } |
| 835 | |
| 836 | apex_key { |
| 837 | name: "myapex.key", |
| 838 | public_key: "testkey.avbpubkey", |
| 839 | private_key: "testkey.pem", |
| 840 | } |
| 841 | |
| 842 | cc_library { |
| 843 | name: "mylib", |
| 844 | srcs: ["mylib.cpp"], |
| 845 | runtime_libs: ["libfoo", "libbar"], |
| 846 | system_shared_libs: [], |
| 847 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 848 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | cc_library { |
| 852 | name: "libfoo", |
| 853 | srcs: ["mylib.cpp"], |
| 854 | system_shared_libs: [], |
| 855 | stl: "none", |
| 856 | stubs: { |
| 857 | versions: ["10", "20", "30"], |
| 858 | }, |
| 859 | } |
| 860 | |
| 861 | cc_library { |
| 862 | name: "libbar", |
| 863 | srcs: ["mylib.cpp"], |
| 864 | system_shared_libs: [], |
| 865 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 866 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | `) |
| 870 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 871 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 872 | copyCmds := apexRule.Args["copy_commands"] |
| 873 | |
| 874 | // Ensure that direct non-stubs dep is always included |
| 875 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 876 | |
| 877 | // Ensure that indirect stubs dep is not included |
| 878 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 879 | |
| 880 | // Ensure that runtime_libs dep in included |
| 881 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 882 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 883 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 884 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 885 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 886 | |
| 887 | } |
| 888 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 889 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 890 | testcases := []struct { |
| 891 | name string |
| 892 | minSdkVersion string |
| 893 | shouldLink string |
| 894 | shouldNotLink []string |
| 895 | }{ |
| 896 | { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 897 | name: "should link to the latest", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 898 | minSdkVersion: "current", |
| 899 | shouldLink: "30", |
| 900 | shouldNotLink: []string{"29"}, |
| 901 | }, |
| 902 | { |
| 903 | name: "should link to llndk#29", |
| 904 | minSdkVersion: "29", |
| 905 | shouldLink: "29", |
| 906 | shouldNotLink: []string{"30"}, |
| 907 | }, |
| 908 | } |
| 909 | for _, tc := range testcases { |
| 910 | t.Run(tc.name, func(t *testing.T) { |
| 911 | ctx, _ := testApex(t, ` |
| 912 | apex { |
| 913 | name: "myapex", |
| 914 | key: "myapex.key", |
| 915 | use_vendor: true, |
| 916 | native_shared_libs: ["mylib"], |
| 917 | min_sdk_version: "`+tc.minSdkVersion+`", |
| 918 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 919 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 920 | apex_key { |
| 921 | name: "myapex.key", |
| 922 | public_key: "testkey.avbpubkey", |
| 923 | private_key: "testkey.pem", |
| 924 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 925 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 926 | cc_library { |
| 927 | name: "mylib", |
| 928 | srcs: ["mylib.cpp"], |
| 929 | vendor_available: true, |
| 930 | shared_libs: ["libbar"], |
| 931 | system_shared_libs: [], |
| 932 | stl: "none", |
| 933 | apex_available: [ "myapex" ], |
| 934 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 935 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 936 | cc_library { |
| 937 | name: "libbar", |
| 938 | srcs: ["mylib.cpp"], |
| 939 | system_shared_libs: [], |
| 940 | stl: "none", |
| 941 | stubs: { versions: ["29","30"] }, |
| 942 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 943 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 944 | llndk_library { |
| 945 | name: "libbar", |
| 946 | symbol_file: "", |
| 947 | } |
| 948 | `, func(fs map[string][]byte, config android.Config) { |
| 949 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 950 | }, withUnbundledBuild) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 951 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 952 | // Ensure that LLNDK dep is not included |
| 953 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 954 | "lib64/mylib.so", |
| 955 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 956 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 957 | // Ensure that LLNDK dep is required |
| 958 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 959 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 960 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 961 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 962 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
| 963 | ensureContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so") |
| 964 | for _, ver := range tc.shouldNotLink { |
| 965 | ensureNotContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so") |
| 966 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 967 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 968 | mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 969 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink) |
| 970 | }) |
| 971 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 972 | } |
| 973 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 974 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 975 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 976 | apex { |
| 977 | name: "myapex", |
| 978 | key: "myapex.key", |
| 979 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 980 | } |
| 981 | |
| 982 | apex_key { |
| 983 | name: "myapex.key", |
| 984 | public_key: "testkey.avbpubkey", |
| 985 | private_key: "testkey.pem", |
| 986 | } |
| 987 | |
| 988 | cc_library { |
| 989 | name: "mylib", |
| 990 | srcs: ["mylib.cpp"], |
| 991 | shared_libs: ["libdl#27"], |
| 992 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 993 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | cc_library_shared { |
| 997 | name: "mylib_shared", |
| 998 | srcs: ["mylib.cpp"], |
| 999 | shared_libs: ["libdl#27"], |
| 1000 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1001 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1005 | name: "libBootstrap", |
| 1006 | srcs: ["mylib.cpp"], |
| 1007 | stl: "none", |
| 1008 | bootstrap: true, |
| 1009 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1010 | `) |
| 1011 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1012 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1013 | copyCmds := apexRule.Args["copy_commands"] |
| 1014 | |
| 1015 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1016 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1017 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1018 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1019 | |
| 1020 | // 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] | 1021 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1022 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1023 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
| 1024 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 1025 | 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] | 1026 | |
| 1027 | // For dependency to libc |
| 1028 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1029 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1030 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1031 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.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, "__LIBC_API__=29") |
| 1034 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 1035 | |
| 1036 | // For dependency to libm |
| 1037 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1038 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1039 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1040 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1041 | // ... and is not compiling with the stub |
| 1042 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1043 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1044 | |
| 1045 | // For dependency to libdl |
| 1046 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1047 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1048 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1049 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1050 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1051 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1052 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1053 | // ... Cflags from stub is correctly exported to mylib |
| 1054 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1055 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1056 | |
| 1057 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1058 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1059 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1060 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1061 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1062 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1063 | |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1064 | func TestApexUseStubsAccordingToMinSdkVersionInUnbundledBuild(t *testing.T) { |
| 1065 | // there are three links between liba --> libz |
| 1066 | // 1) myapex -> libx -> liba -> libz : this should be #2 link, but fallback to #1 |
| 1067 | // 2) otherapex -> liby -> liba -> libz : this should be #3 link |
| 1068 | // 3) (platform) -> liba -> libz : this should be non-stub link |
| 1069 | ctx, _ := testApex(t, ` |
| 1070 | apex { |
| 1071 | name: "myapex", |
| 1072 | key: "myapex.key", |
| 1073 | native_shared_libs: ["libx"], |
| 1074 | min_sdk_version: "2", |
| 1075 | } |
| 1076 | |
| 1077 | apex { |
| 1078 | name: "otherapex", |
| 1079 | key: "myapex.key", |
| 1080 | native_shared_libs: ["liby"], |
| 1081 | min_sdk_version: "3", |
| 1082 | } |
| 1083 | |
| 1084 | apex_key { |
| 1085 | name: "myapex.key", |
| 1086 | public_key: "testkey.avbpubkey", |
| 1087 | private_key: "testkey.pem", |
| 1088 | } |
| 1089 | |
| 1090 | cc_library { |
| 1091 | name: "libx", |
| 1092 | shared_libs: ["liba"], |
| 1093 | system_shared_libs: [], |
| 1094 | stl: "none", |
| 1095 | apex_available: [ "myapex" ], |
| 1096 | } |
| 1097 | |
| 1098 | cc_library { |
| 1099 | name: "liby", |
| 1100 | shared_libs: ["liba"], |
| 1101 | system_shared_libs: [], |
| 1102 | stl: "none", |
| 1103 | apex_available: [ "otherapex" ], |
| 1104 | } |
| 1105 | |
| 1106 | cc_library { |
| 1107 | name: "liba", |
| 1108 | shared_libs: ["libz"], |
| 1109 | system_shared_libs: [], |
| 1110 | stl: "none", |
| 1111 | apex_available: [ |
| 1112 | "//apex_available:anyapex", |
| 1113 | "//apex_available:platform", |
| 1114 | ], |
| 1115 | } |
| 1116 | |
| 1117 | cc_library { |
| 1118 | name: "libz", |
| 1119 | system_shared_libs: [], |
| 1120 | stl: "none", |
| 1121 | stubs: { |
| 1122 | versions: ["1", "3"], |
| 1123 | }, |
| 1124 | } |
| 1125 | `, withUnbundledBuild) |
| 1126 | |
| 1127 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1128 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1129 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1130 | } |
| 1131 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1132 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1133 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1134 | } |
| 1135 | // platform liba is linked to non-stub version |
| 1136 | expectLink("liba", "shared", "libz", "shared") |
| 1137 | // liba in myapex is linked to #1 |
| 1138 | expectLink("liba", "shared_myapex", "libz", "shared_1") |
| 1139 | expectNoLink("liba", "shared_myapex", "libz", "shared_3") |
| 1140 | expectNoLink("liba", "shared_myapex", "libz", "shared") |
| 1141 | // liba in otherapex is linked to #3 |
| 1142 | expectLink("liba", "shared_otherapex", "libz", "shared_3") |
| 1143 | expectNoLink("liba", "shared_otherapex", "libz", "shared_1") |
| 1144 | expectNoLink("liba", "shared_otherapex", "libz", "shared") |
| 1145 | } |
| 1146 | |
| 1147 | func TestApexMinSdkVersionDefaultsToLatest(t *testing.T) { |
| 1148 | ctx, _ := testApex(t, ` |
| 1149 | apex { |
| 1150 | name: "myapex", |
| 1151 | key: "myapex.key", |
| 1152 | native_shared_libs: ["libx"], |
| 1153 | } |
| 1154 | |
| 1155 | apex_key { |
| 1156 | name: "myapex.key", |
| 1157 | public_key: "testkey.avbpubkey", |
| 1158 | private_key: "testkey.pem", |
| 1159 | } |
| 1160 | |
| 1161 | cc_library { |
| 1162 | name: "libx", |
| 1163 | shared_libs: ["libz"], |
| 1164 | system_shared_libs: [], |
| 1165 | stl: "none", |
| 1166 | apex_available: [ "myapex" ], |
| 1167 | } |
| 1168 | |
| 1169 | cc_library { |
| 1170 | name: "libz", |
| 1171 | system_shared_libs: [], |
| 1172 | stl: "none", |
| 1173 | stubs: { |
| 1174 | versions: ["1", "2"], |
| 1175 | }, |
| 1176 | } |
| 1177 | `) |
| 1178 | |
| 1179 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1180 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1181 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1182 | } |
| 1183 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1184 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1185 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1186 | } |
| 1187 | expectLink("libx", "shared_myapex", "libz", "shared_2") |
| 1188 | expectNoLink("libx", "shared_myapex", "libz", "shared_1") |
| 1189 | expectNoLink("libx", "shared_myapex", "libz", "shared") |
| 1190 | } |
| 1191 | |
| 1192 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
| 1193 | ctx, _ := testApex(t, ` |
| 1194 | apex { |
| 1195 | name: "myapex", |
| 1196 | key: "myapex.key", |
| 1197 | native_shared_libs: ["libx"], |
| 1198 | } |
| 1199 | |
| 1200 | apex_key { |
| 1201 | name: "myapex.key", |
| 1202 | public_key: "testkey.avbpubkey", |
| 1203 | private_key: "testkey.pem", |
| 1204 | } |
| 1205 | |
| 1206 | cc_library { |
| 1207 | name: "libx", |
| 1208 | system_shared_libs: [], |
| 1209 | stl: "none", |
| 1210 | apex_available: [ "myapex" ], |
| 1211 | stubs: { |
| 1212 | versions: ["1", "2"], |
| 1213 | }, |
| 1214 | } |
| 1215 | |
| 1216 | cc_library { |
| 1217 | name: "libz", |
| 1218 | shared_libs: ["libx"], |
| 1219 | system_shared_libs: [], |
| 1220 | stl: "none", |
| 1221 | } |
| 1222 | `) |
| 1223 | |
| 1224 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1225 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1226 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1227 | } |
| 1228 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1229 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1230 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1231 | } |
| 1232 | expectLink("libz", "shared", "libx", "shared_2") |
| 1233 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1234 | expectNoLink("libz", "shared", "libz", "shared") |
| 1235 | } |
| 1236 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1237 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1238 | ctx, _ := testApex(t, ` |
| 1239 | apex { |
| 1240 | name: "myapex", |
| 1241 | key: "myapex.key", |
| 1242 | native_shared_libs: ["libx"], |
| 1243 | min_sdk_version: "29", |
| 1244 | } |
| 1245 | |
| 1246 | apex_key { |
| 1247 | name: "myapex.key", |
| 1248 | public_key: "testkey.avbpubkey", |
| 1249 | private_key: "testkey.pem", |
| 1250 | } |
| 1251 | |
| 1252 | cc_library { |
| 1253 | name: "libx", |
| 1254 | shared_libs: ["libbar"], |
| 1255 | apex_available: [ "myapex" ], |
| 1256 | } |
| 1257 | |
| 1258 | cc_library { |
| 1259 | name: "libbar", |
| 1260 | stubs: { |
| 1261 | versions: ["29", "30"], |
| 1262 | }, |
| 1263 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1264 | `, func(fs map[string][]byte, config android.Config) { |
| 1265 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1266 | }) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1267 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1268 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1269 | libFlags := ld.Args["libFlags"] |
| 1270 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1271 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1272 | expectLink("libx", "shared_hwasan_myapex", "libbar", "shared_30") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1273 | } |
| 1274 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1275 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1276 | ctx, _ := testApex(t, ` |
| 1277 | apex { |
| 1278 | name: "myapex", |
| 1279 | key: "myapex.key", |
| 1280 | native_shared_libs: ["libx"], |
| 1281 | min_sdk_version: "29", |
| 1282 | } |
| 1283 | |
| 1284 | apex_key { |
| 1285 | name: "myapex.key", |
| 1286 | public_key: "testkey.avbpubkey", |
| 1287 | private_key: "testkey.pem", |
| 1288 | } |
| 1289 | |
| 1290 | cc_library { |
| 1291 | name: "libx", |
| 1292 | apex_available: [ "myapex" ], |
| 1293 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1294 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1295 | |
| 1296 | // ensure apex variant of c++ is linked with static unwinder |
| 1297 | cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module) |
| 1298 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped") |
| 1299 | // note that platform variant is not. |
| 1300 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 1301 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | func TestInvalidMinSdkVersion(t *testing.T) { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1305 | testApexError(t, `"libz" .*: not found a version\(<=29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1306 | apex { |
| 1307 | name: "myapex", |
| 1308 | key: "myapex.key", |
| 1309 | native_shared_libs: ["libx"], |
| 1310 | min_sdk_version: "29", |
| 1311 | } |
| 1312 | |
| 1313 | apex_key { |
| 1314 | name: "myapex.key", |
| 1315 | public_key: "testkey.avbpubkey", |
| 1316 | private_key: "testkey.pem", |
| 1317 | } |
| 1318 | |
| 1319 | cc_library { |
| 1320 | name: "libx", |
| 1321 | shared_libs: ["libz"], |
| 1322 | system_shared_libs: [], |
| 1323 | stl: "none", |
| 1324 | apex_available: [ "myapex" ], |
| 1325 | } |
| 1326 | |
| 1327 | cc_library { |
| 1328 | name: "libz", |
| 1329 | system_shared_libs: [], |
| 1330 | stl: "none", |
| 1331 | stubs: { |
| 1332 | versions: ["30"], |
| 1333 | }, |
| 1334 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1335 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1336 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1337 | testApexError(t, `"myapex" .*: min_sdk_version: should be "current" or <number>`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1338 | apex { |
| 1339 | name: "myapex", |
| 1340 | key: "myapex.key", |
| 1341 | min_sdk_version: "R", |
| 1342 | } |
| 1343 | |
| 1344 | apex_key { |
| 1345 | name: "myapex.key", |
| 1346 | public_key: "testkey.avbpubkey", |
| 1347 | private_key: "testkey.pem", |
| 1348 | } |
| 1349 | `) |
| 1350 | } |
| 1351 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1352 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1353 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1354 | apex { |
| 1355 | name: "myapex", |
| 1356 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1357 | native_shared_libs: ["mylib"], |
| 1358 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1359 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1360 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | apex_key { |
| 1364 | name: "myapex.key", |
| 1365 | public_key: "testkey.avbpubkey", |
| 1366 | private_key: "testkey.pem", |
| 1367 | } |
| 1368 | |
| 1369 | prebuilt_etc { |
| 1370 | name: "myetc", |
| 1371 | src: "myprebuilt", |
| 1372 | sub_dir: "foo/bar", |
| 1373 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1374 | |
| 1375 | cc_library { |
| 1376 | name: "mylib", |
| 1377 | srcs: ["mylib.cpp"], |
| 1378 | relative_install_path: "foo/bar", |
| 1379 | system_shared_libs: [], |
| 1380 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1381 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | cc_binary { |
| 1385 | name: "mybin", |
| 1386 | srcs: ["mylib.cpp"], |
| 1387 | relative_install_path: "foo/bar", |
| 1388 | system_shared_libs: [], |
| 1389 | static_executable: true, |
| 1390 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1391 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1392 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1393 | `) |
| 1394 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1395 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1396 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 1397 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1398 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1399 | ensureListContains(t, dirs, "etc") |
| 1400 | ensureListContains(t, dirs, "etc/foo") |
| 1401 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1402 | ensureListContains(t, dirs, "lib64") |
| 1403 | ensureListContains(t, dirs, "lib64/foo") |
| 1404 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 1405 | ensureListContains(t, dirs, "lib") |
| 1406 | ensureListContains(t, dirs, "lib/foo") |
| 1407 | ensureListContains(t, dirs, "lib/foo/bar") |
| 1408 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 1409 | ensureListContains(t, dirs, "bin") |
| 1410 | ensureListContains(t, dirs, "bin/foo") |
| 1411 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1412 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1413 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 1414 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
| 1415 | ctx, _ := testApex(t, ` |
| 1416 | apex { |
| 1417 | name: "myapex", |
| 1418 | key: "myapex.key", |
| 1419 | multilib: { |
| 1420 | both: { |
| 1421 | native_shared_libs: ["mylib"], |
| 1422 | binaries: ["mybin"], |
| 1423 | }, |
| 1424 | }, |
| 1425 | compile_multilib: "both", |
| 1426 | native_bridge_supported: true, |
| 1427 | } |
| 1428 | |
| 1429 | apex_key { |
| 1430 | name: "myapex.key", |
| 1431 | public_key: "testkey.avbpubkey", |
| 1432 | private_key: "testkey.pem", |
| 1433 | } |
| 1434 | |
| 1435 | cc_library { |
| 1436 | name: "mylib", |
| 1437 | relative_install_path: "foo/bar", |
| 1438 | system_shared_libs: [], |
| 1439 | stl: "none", |
| 1440 | apex_available: [ "myapex" ], |
| 1441 | native_bridge_supported: true, |
| 1442 | } |
| 1443 | |
| 1444 | cc_binary { |
| 1445 | name: "mybin", |
| 1446 | relative_install_path: "foo/bar", |
| 1447 | system_shared_libs: [], |
| 1448 | static_executable: true, |
| 1449 | stl: "none", |
| 1450 | apex_available: [ "myapex" ], |
| 1451 | native_bridge_supported: true, |
| 1452 | compile_multilib: "both", // default is "first" for binary |
| 1453 | multilib: { |
| 1454 | lib64: { |
| 1455 | suffix: "64", |
| 1456 | }, |
| 1457 | }, |
| 1458 | } |
| 1459 | `, withNativeBridgeEnabled) |
| 1460 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1461 | "bin/foo/bar/mybin", |
| 1462 | "bin/foo/bar/mybin64", |
| 1463 | "bin/arm/foo/bar/mybin", |
| 1464 | "bin/arm64/foo/bar/mybin64", |
| 1465 | "lib/foo/bar/mylib.so", |
| 1466 | "lib/arm/foo/bar/mylib.so", |
| 1467 | "lib64/foo/bar/mylib.so", |
| 1468 | "lib64/arm64/foo/bar/mylib.so", |
| 1469 | }) |
| 1470 | } |
| 1471 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1472 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1473 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1474 | apex { |
| 1475 | name: "myapex", |
| 1476 | key: "myapex.key", |
| 1477 | native_shared_libs: ["mylib"], |
| 1478 | use_vendor: true, |
| 1479 | } |
| 1480 | |
| 1481 | apex_key { |
| 1482 | name: "myapex.key", |
| 1483 | public_key: "testkey.avbpubkey", |
| 1484 | private_key: "testkey.pem", |
| 1485 | } |
| 1486 | |
| 1487 | cc_library { |
| 1488 | name: "mylib", |
| 1489 | srcs: ["mylib.cpp"], |
| 1490 | shared_libs: ["mylib2"], |
| 1491 | system_shared_libs: [], |
| 1492 | vendor_available: true, |
| 1493 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1494 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | cc_library { |
| 1498 | name: "mylib2", |
| 1499 | srcs: ["mylib.cpp"], |
| 1500 | system_shared_libs: [], |
| 1501 | vendor_available: true, |
| 1502 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1503 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1504 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1505 | `, func(fs map[string][]byte, config android.Config) { |
| 1506 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 1507 | }) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1508 | |
| 1509 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1510 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1511 | for _, implicit := range i.Implicits { |
| 1512 | inputsList = append(inputsList, implicit.String()) |
| 1513 | } |
| 1514 | } |
| 1515 | inputsString := strings.Join(inputsList, " ") |
| 1516 | |
| 1517 | // 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] | 1518 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so") |
| 1519 | 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] | 1520 | |
| 1521 | // ensure that the apex does not include core variants |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1522 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so") |
| 1523 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1524 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1525 | |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1526 | func TestUseVendorRestriction(t *testing.T) { |
| 1527 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 1528 | apex { |
| 1529 | name: "myapex", |
| 1530 | key: "myapex.key", |
| 1531 | use_vendor: true, |
| 1532 | } |
| 1533 | apex_key { |
| 1534 | name: "myapex.key", |
| 1535 | public_key: "testkey.avbpubkey", |
| 1536 | private_key: "testkey.pem", |
| 1537 | } |
| 1538 | `, func(fs map[string][]byte, config android.Config) { |
| 1539 | setUseVendorWhitelistForTest(config, []string{""}) |
| 1540 | }) |
| 1541 | // no error with whitelist |
| 1542 | testApex(t, ` |
| 1543 | apex { |
| 1544 | name: "myapex", |
| 1545 | key: "myapex.key", |
| 1546 | use_vendor: true, |
| 1547 | } |
| 1548 | apex_key { |
| 1549 | name: "myapex.key", |
| 1550 | public_key: "testkey.avbpubkey", |
| 1551 | private_key: "testkey.pem", |
| 1552 | } |
| 1553 | `, func(fs map[string][]byte, config android.Config) { |
| 1554 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 1555 | }) |
| 1556 | } |
| 1557 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 1558 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 1559 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 1560 | apex { |
| 1561 | name: "myapex", |
| 1562 | key: "myapex.key", |
| 1563 | native_shared_libs: ["mylib"], |
| 1564 | use_vendor: true, |
| 1565 | } |
| 1566 | |
| 1567 | apex_key { |
| 1568 | name: "myapex.key", |
| 1569 | public_key: "testkey.avbpubkey", |
| 1570 | private_key: "testkey.pem", |
| 1571 | } |
| 1572 | |
| 1573 | cc_library { |
| 1574 | name: "mylib", |
| 1575 | srcs: ["mylib.cpp"], |
| 1576 | system_shared_libs: [], |
| 1577 | stl: "none", |
| 1578 | } |
| 1579 | `) |
| 1580 | } |
| 1581 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1582 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1583 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1584 | apex { |
| 1585 | name: "myapex", |
| 1586 | key: "myapex.key", |
| 1587 | native_shared_libs: ["mylib"], |
| 1588 | } |
| 1589 | |
| 1590 | apex_key { |
| 1591 | name: "myapex.key", |
| 1592 | public_key: "testkey.avbpubkey", |
| 1593 | private_key: "testkey.pem", |
| 1594 | } |
| 1595 | |
| 1596 | cc_library { |
| 1597 | name: "mylib", |
| 1598 | srcs: ["mylib.cpp"], |
| 1599 | system_shared_libs: [], |
| 1600 | stl: "none", |
| 1601 | stubs: { |
| 1602 | versions: ["1", "2", "3"], |
| 1603 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1604 | apex_available: [ |
| 1605 | "//apex_available:platform", |
| 1606 | "myapex", |
| 1607 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | cc_binary { |
| 1611 | name: "not_in_apex", |
| 1612 | srcs: ["mylib.cpp"], |
| 1613 | static_libs: ["mylib"], |
| 1614 | static_executable: true, |
| 1615 | system_shared_libs: [], |
| 1616 | stl: "none", |
| 1617 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1618 | `) |
| 1619 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1620 | 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] | 1621 | |
| 1622 | // 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] | 1623 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1624 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1625 | |
| 1626 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1627 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1628 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1629 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1630 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1631 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1632 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1633 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | cc_library { |
| 1637 | name: "mylib", |
| 1638 | srcs: ["mylib.cpp"], |
| 1639 | system_shared_libs: [], |
| 1640 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1641 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | apex_key { |
| 1645 | name: "myapex.key", |
| 1646 | public_key: "testkey.avbpubkey", |
| 1647 | private_key: "testkey.pem", |
| 1648 | } |
| 1649 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1650 | android_app_certificate { |
| 1651 | name: "myapex.certificate", |
| 1652 | certificate: "testkey", |
| 1653 | } |
| 1654 | |
| 1655 | android_app_certificate { |
| 1656 | name: "myapex.certificate.override", |
| 1657 | certificate: "testkey.override", |
| 1658 | } |
| 1659 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1660 | `) |
| 1661 | |
| 1662 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1663 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1664 | |
| 1665 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 1666 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 1667 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 1668 | } |
| 1669 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 1670 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 1671 | "vendor/foo/devkeys/testkey.pem") |
| 1672 | } |
| 1673 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1674 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1675 | 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] | 1676 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1677 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1678 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1679 | } |
| 1680 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1681 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 1682 | func TestCertificate(t *testing.T) { |
| 1683 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 1684 | ctx, _ := testApex(t, ` |
| 1685 | apex { |
| 1686 | name: "myapex", |
| 1687 | key: "myapex.key", |
| 1688 | } |
| 1689 | apex_key { |
| 1690 | name: "myapex.key", |
| 1691 | public_key: "testkey.avbpubkey", |
| 1692 | private_key: "testkey.pem", |
| 1693 | }`) |
| 1694 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1695 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 1696 | if actual := rule.Args["certificates"]; actual != expected { |
| 1697 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1698 | } |
| 1699 | }) |
| 1700 | t.Run("override when unspecified", func(t *testing.T) { |
| 1701 | ctx, _ := testApex(t, ` |
| 1702 | apex { |
| 1703 | name: "myapex_keytest", |
| 1704 | key: "myapex.key", |
| 1705 | file_contexts: ":myapex-file_contexts", |
| 1706 | } |
| 1707 | apex_key { |
| 1708 | name: "myapex.key", |
| 1709 | public_key: "testkey.avbpubkey", |
| 1710 | private_key: "testkey.pem", |
| 1711 | } |
| 1712 | android_app_certificate { |
| 1713 | name: "myapex.certificate.override", |
| 1714 | certificate: "testkey.override", |
| 1715 | }`) |
| 1716 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1717 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1718 | if actual := rule.Args["certificates"]; actual != expected { |
| 1719 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1720 | } |
| 1721 | }) |
| 1722 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 1723 | ctx, _ := testApex(t, ` |
| 1724 | apex { |
| 1725 | name: "myapex", |
| 1726 | key: "myapex.key", |
| 1727 | certificate: ":myapex.certificate", |
| 1728 | } |
| 1729 | apex_key { |
| 1730 | name: "myapex.key", |
| 1731 | public_key: "testkey.avbpubkey", |
| 1732 | private_key: "testkey.pem", |
| 1733 | } |
| 1734 | android_app_certificate { |
| 1735 | name: "myapex.certificate", |
| 1736 | certificate: "testkey", |
| 1737 | }`) |
| 1738 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1739 | expected := "testkey.x509.pem testkey.pk8" |
| 1740 | if actual := rule.Args["certificates"]; actual != expected { |
| 1741 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1742 | } |
| 1743 | }) |
| 1744 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 1745 | ctx, _ := testApex(t, ` |
| 1746 | apex { |
| 1747 | name: "myapex_keytest", |
| 1748 | key: "myapex.key", |
| 1749 | file_contexts: ":myapex-file_contexts", |
| 1750 | certificate: ":myapex.certificate", |
| 1751 | } |
| 1752 | apex_key { |
| 1753 | name: "myapex.key", |
| 1754 | public_key: "testkey.avbpubkey", |
| 1755 | private_key: "testkey.pem", |
| 1756 | } |
| 1757 | android_app_certificate { |
| 1758 | name: "myapex.certificate.override", |
| 1759 | certificate: "testkey.override", |
| 1760 | }`) |
| 1761 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1762 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1763 | if actual := rule.Args["certificates"]; actual != expected { |
| 1764 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1765 | } |
| 1766 | }) |
| 1767 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 1768 | ctx, _ := testApex(t, ` |
| 1769 | apex { |
| 1770 | name: "myapex", |
| 1771 | key: "myapex.key", |
| 1772 | certificate: "testkey", |
| 1773 | } |
| 1774 | apex_key { |
| 1775 | name: "myapex.key", |
| 1776 | public_key: "testkey.avbpubkey", |
| 1777 | private_key: "testkey.pem", |
| 1778 | }`) |
| 1779 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1780 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 1781 | if actual := rule.Args["certificates"]; actual != expected { |
| 1782 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1783 | } |
| 1784 | }) |
| 1785 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 1786 | ctx, _ := testApex(t, ` |
| 1787 | apex { |
| 1788 | name: "myapex_keytest", |
| 1789 | key: "myapex.key", |
| 1790 | file_contexts: ":myapex-file_contexts", |
| 1791 | certificate: "testkey", |
| 1792 | } |
| 1793 | apex_key { |
| 1794 | name: "myapex.key", |
| 1795 | public_key: "testkey.avbpubkey", |
| 1796 | private_key: "testkey.pem", |
| 1797 | } |
| 1798 | android_app_certificate { |
| 1799 | name: "myapex.certificate.override", |
| 1800 | certificate: "testkey.override", |
| 1801 | }`) |
| 1802 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1803 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1804 | if actual := rule.Args["certificates"]; actual != expected { |
| 1805 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1806 | } |
| 1807 | }) |
| 1808 | } |
| 1809 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1810 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1811 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1812 | apex { |
| 1813 | name: "myapex", |
| 1814 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1815 | native_shared_libs: ["mylib", "mylib2"], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | apex { |
| 1819 | name: "otherapex", |
| 1820 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1821 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1822 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | apex_key { |
| 1826 | name: "myapex.key", |
| 1827 | public_key: "testkey.avbpubkey", |
| 1828 | private_key: "testkey.pem", |
| 1829 | } |
| 1830 | |
| 1831 | cc_library { |
| 1832 | name: "mylib", |
| 1833 | srcs: ["mylib.cpp"], |
| 1834 | system_shared_libs: [], |
| 1835 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1836 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1837 | "myapex", |
| 1838 | "otherapex", |
| 1839 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 1840 | recovery_available: true, |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1841 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1842 | cc_library { |
| 1843 | name: "mylib2", |
| 1844 | srcs: ["mylib.cpp"], |
| 1845 | system_shared_libs: [], |
| 1846 | stl: "none", |
| 1847 | apex_available: [ |
| 1848 | "myapex", |
| 1849 | "otherapex", |
| 1850 | ], |
| 1851 | use_apex_name_macro: true, |
| 1852 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1853 | `) |
| 1854 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1855 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1856 | 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] | 1857 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1858 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1859 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1860 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1861 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 1862 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1863 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1864 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1865 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1866 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1867 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 1868 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1869 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1870 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1871 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1872 | // When cc_library sets use_apex_name_macro: true |
| 1873 | // apex variants define additional macro to distinguish which apex variant it is built for |
| 1874 | |
| 1875 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 1876 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1877 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 1878 | |
| 1879 | // APEX variant has __ANDROID_APEX__ defined |
| 1880 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1881 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1882 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1883 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1884 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1885 | // APEX variant has __ANDROID_APEX__ defined |
| 1886 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1887 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1888 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1889 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 1890 | |
| 1891 | // recovery variant does not set __ANDROID_SDK_VERSION__ |
| 1892 | mylibCFlags = ctx.ModuleForTests("mylib", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1893 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 1894 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1895 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1896 | |
| 1897 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1898 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1899 | apex { |
| 1900 | name: "myapex", |
| 1901 | key: "myapex.key", |
| 1902 | native_shared_libs: ["mylib"], |
| 1903 | } |
| 1904 | |
| 1905 | apex_key { |
| 1906 | name: "myapex.key", |
| 1907 | public_key: "testkey.avbpubkey", |
| 1908 | private_key: "testkey.pem", |
| 1909 | } |
| 1910 | |
| 1911 | cc_library_headers { |
| 1912 | name: "mylib_headers", |
| 1913 | export_include_dirs: ["my_include"], |
| 1914 | system_shared_libs: [], |
| 1915 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1916 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | cc_library { |
| 1920 | name: "mylib", |
| 1921 | srcs: ["mylib.cpp"], |
| 1922 | system_shared_libs: [], |
| 1923 | stl: "none", |
| 1924 | header_libs: ["mylib_headers"], |
| 1925 | export_header_lib_headers: ["mylib_headers"], |
| 1926 | stubs: { |
| 1927 | versions: ["1", "2", "3"], |
| 1928 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1929 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | cc_library { |
| 1933 | name: "otherlib", |
| 1934 | srcs: ["mylib.cpp"], |
| 1935 | system_shared_libs: [], |
| 1936 | stl: "none", |
| 1937 | shared_libs: ["mylib"], |
| 1938 | } |
| 1939 | `) |
| 1940 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1941 | 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] | 1942 | |
| 1943 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 1944 | ensureContains(t, cFlags, "-Imy_include") |
| 1945 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1946 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1947 | type fileInApex struct { |
| 1948 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1949 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1950 | isLink bool |
| 1951 | } |
| 1952 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1953 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1954 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1955 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1956 | copyCmds := apexRule.Args["copy_commands"] |
| 1957 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1958 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1959 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 1960 | cmd = strings.TrimSpace(cmd) |
| 1961 | if cmd == "" { |
| 1962 | continue |
| 1963 | } |
| 1964 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1965 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1966 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1967 | switch terms[0] { |
| 1968 | case "mkdir": |
| 1969 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1970 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1971 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 1972 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1973 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1974 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1975 | isLink = false |
| 1976 | case "ln": |
| 1977 | if len(terms) != 3 && len(terms) != 4 { |
| 1978 | // ln LINK TARGET or ln -s LINK TARGET |
| 1979 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 1980 | } |
| 1981 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1982 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1983 | isLink = true |
| 1984 | default: |
| 1985 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 1986 | } |
| 1987 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1988 | index := strings.Index(dst, imageApexDir) |
| 1989 | if index == -1 { |
| 1990 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 1991 | } |
| 1992 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1993 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1994 | } |
| 1995 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1996 | return ret |
| 1997 | } |
| 1998 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1999 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 2000 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2001 | var failed bool |
| 2002 | var surplus []string |
| 2003 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2004 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2005 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2006 | for _, expected := range files { |
| 2007 | if matched, _ := path.Match(expected, file.path); matched { |
| 2008 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2009 | mactchFound = true |
| 2010 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2011 | } |
| 2012 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2013 | if !mactchFound { |
| 2014 | surplus = append(surplus, file.path) |
| 2015 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2016 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2017 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2018 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2019 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2020 | t.Log("surplus files", surplus) |
| 2021 | failed = true |
| 2022 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2023 | |
| 2024 | if len(files) > len(filesMatched) { |
| 2025 | var missing []string |
| 2026 | for _, expected := range files { |
| 2027 | if !filesMatched[expected] { |
| 2028 | missing = append(missing, expected) |
| 2029 | } |
| 2030 | } |
| 2031 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2032 | t.Log("missing files", missing) |
| 2033 | failed = true |
| 2034 | } |
| 2035 | if failed { |
| 2036 | t.Fail() |
| 2037 | } |
| 2038 | } |
| 2039 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2040 | func TestVndkApexCurrent(t *testing.T) { |
| 2041 | ctx, _ := testApex(t, ` |
| 2042 | apex_vndk { |
| 2043 | name: "myapex", |
| 2044 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | apex_key { |
| 2048 | name: "myapex.key", |
| 2049 | public_key: "testkey.avbpubkey", |
| 2050 | private_key: "testkey.pem", |
| 2051 | } |
| 2052 | |
| 2053 | cc_library { |
| 2054 | name: "libvndk", |
| 2055 | srcs: ["mylib.cpp"], |
| 2056 | vendor_available: true, |
| 2057 | vndk: { |
| 2058 | enabled: true, |
| 2059 | }, |
| 2060 | system_shared_libs: [], |
| 2061 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2062 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | cc_library { |
| 2066 | name: "libvndksp", |
| 2067 | srcs: ["mylib.cpp"], |
| 2068 | vendor_available: true, |
| 2069 | vndk: { |
| 2070 | enabled: true, |
| 2071 | support_system_process: true, |
| 2072 | }, |
| 2073 | system_shared_libs: [], |
| 2074 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2075 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2076 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2077 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2078 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2079 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2080 | "lib/libvndk.so", |
| 2081 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2082 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2083 | "lib64/libvndk.so", |
| 2084 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2085 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2086 | "etc/llndk.libraries.VER.txt", |
| 2087 | "etc/vndkcore.libraries.VER.txt", |
| 2088 | "etc/vndksp.libraries.VER.txt", |
| 2089 | "etc/vndkprivate.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2090 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 2094 | ctx, _ := testApex(t, ` |
| 2095 | apex_vndk { |
| 2096 | name: "myapex", |
| 2097 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | apex_key { |
| 2101 | name: "myapex.key", |
| 2102 | public_key: "testkey.avbpubkey", |
| 2103 | private_key: "testkey.pem", |
| 2104 | } |
| 2105 | |
| 2106 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2107 | name: "libvndk", |
| 2108 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2109 | vendor_available: true, |
| 2110 | vndk: { |
| 2111 | enabled: true, |
| 2112 | }, |
| 2113 | system_shared_libs: [], |
| 2114 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2115 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2116 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2117 | |
| 2118 | cc_prebuilt_library_shared { |
| 2119 | name: "libvndk.arm", |
| 2120 | srcs: ["libvndk.arm.so"], |
| 2121 | vendor_available: true, |
| 2122 | vndk: { |
| 2123 | enabled: true, |
| 2124 | }, |
| 2125 | enabled: false, |
| 2126 | arch: { |
| 2127 | arm: { |
| 2128 | enabled: true, |
| 2129 | }, |
| 2130 | }, |
| 2131 | system_shared_libs: [], |
| 2132 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2133 | apex_available: [ "myapex" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2134 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2135 | `+vndkLibrariesTxtFiles("current"), |
| 2136 | withFiles(map[string][]byte{ |
| 2137 | "libvndk.so": nil, |
| 2138 | "libvndk.arm.so": nil, |
| 2139 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2140 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2141 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2142 | "lib/libvndk.so", |
| 2143 | "lib/libvndk.arm.so", |
| 2144 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2145 | "lib/libc++.so", |
| 2146 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2147 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2148 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2149 | } |
| 2150 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2151 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 2152 | for _, v := range vers { |
| 2153 | if v == "current" { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 2154 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2155 | result += ` |
| 2156 | vndk_libraries_txt { |
| 2157 | name: "` + txt + `.libraries.txt", |
| 2158 | } |
| 2159 | ` |
| 2160 | } |
| 2161 | } else { |
| 2162 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
| 2163 | result += ` |
| 2164 | prebuilt_etc { |
| 2165 | name: "` + txt + `.libraries.` + v + `.txt", |
| 2166 | src: "dummy.txt", |
| 2167 | } |
| 2168 | ` |
| 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | return |
| 2173 | } |
| 2174 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2175 | func TestVndkApexVersion(t *testing.T) { |
| 2176 | ctx, _ := testApex(t, ` |
| 2177 | apex_vndk { |
| 2178 | name: "myapex_v27", |
| 2179 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2180 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2181 | vndk_version: "27", |
| 2182 | } |
| 2183 | |
| 2184 | apex_key { |
| 2185 | name: "myapex.key", |
| 2186 | public_key: "testkey.avbpubkey", |
| 2187 | private_key: "testkey.pem", |
| 2188 | } |
| 2189 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2190 | vndk_prebuilt_shared { |
| 2191 | name: "libvndk27", |
| 2192 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2193 | vendor_available: true, |
| 2194 | vndk: { |
| 2195 | enabled: true, |
| 2196 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2197 | target_arch: "arm64", |
| 2198 | arch: { |
| 2199 | arm: { |
| 2200 | srcs: ["libvndk27_arm.so"], |
| 2201 | }, |
| 2202 | arm64: { |
| 2203 | srcs: ["libvndk27_arm64.so"], |
| 2204 | }, |
| 2205 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2206 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | vndk_prebuilt_shared { |
| 2210 | name: "libvndk27", |
| 2211 | version: "27", |
| 2212 | vendor_available: true, |
| 2213 | vndk: { |
| 2214 | enabled: true, |
| 2215 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2216 | target_arch: "x86_64", |
| 2217 | arch: { |
| 2218 | x86: { |
| 2219 | srcs: ["libvndk27_x86.so"], |
| 2220 | }, |
| 2221 | x86_64: { |
| 2222 | srcs: ["libvndk27_x86_64.so"], |
| 2223 | }, |
| 2224 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2225 | } |
| 2226 | `+vndkLibrariesTxtFiles("27"), |
| 2227 | withFiles(map[string][]byte{ |
| 2228 | "libvndk27_arm.so": nil, |
| 2229 | "libvndk27_arm64.so": nil, |
| 2230 | "libvndk27_x86.so": nil, |
| 2231 | "libvndk27_x86_64.so": nil, |
| 2232 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2233 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2234 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2235 | "lib/libvndk27_arm.so", |
| 2236 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2237 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2238 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { |
| 2242 | testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, ` |
| 2243 | apex_vndk { |
| 2244 | name: "myapex_v27", |
| 2245 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2246 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2247 | vndk_version: "27", |
| 2248 | } |
| 2249 | apex_vndk { |
| 2250 | name: "myapex_v27_other", |
| 2251 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2252 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2253 | vndk_version: "27", |
| 2254 | } |
| 2255 | |
| 2256 | apex_key { |
| 2257 | name: "myapex.key", |
| 2258 | public_key: "testkey.avbpubkey", |
| 2259 | private_key: "testkey.pem", |
| 2260 | } |
| 2261 | |
| 2262 | cc_library { |
| 2263 | name: "libvndk", |
| 2264 | srcs: ["mylib.cpp"], |
| 2265 | vendor_available: true, |
| 2266 | vndk: { |
| 2267 | enabled: true, |
| 2268 | }, |
| 2269 | system_shared_libs: [], |
| 2270 | stl: "none", |
| 2271 | } |
| 2272 | |
| 2273 | vndk_prebuilt_shared { |
| 2274 | name: "libvndk", |
| 2275 | version: "27", |
| 2276 | vendor_available: true, |
| 2277 | vndk: { |
| 2278 | enabled: true, |
| 2279 | }, |
| 2280 | srcs: ["libvndk.so"], |
| 2281 | } |
| 2282 | `, withFiles(map[string][]byte{ |
| 2283 | "libvndk.so": nil, |
| 2284 | })) |
| 2285 | } |
| 2286 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2287 | func TestVndkApexNameRule(t *testing.T) { |
| 2288 | ctx, _ := testApex(t, ` |
| 2289 | apex_vndk { |
| 2290 | name: "myapex", |
| 2291 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2292 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2293 | } |
| 2294 | apex_vndk { |
| 2295 | name: "myapex_v28", |
| 2296 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2297 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2298 | vndk_version: "28", |
| 2299 | } |
| 2300 | apex_key { |
| 2301 | name: "myapex.key", |
| 2302 | public_key: "testkey.avbpubkey", |
| 2303 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2304 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2305 | |
| 2306 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2307 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2308 | actual := proptools.String(bundle.properties.Apex_name) |
| 2309 | if !reflect.DeepEqual(actual, expected) { |
| 2310 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | assertApexName("com.android.vndk.vVER", "myapex") |
| 2315 | assertApexName("com.android.vndk.v28", "myapex_v28") |
| 2316 | } |
| 2317 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2318 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 2319 | ctx, _ := testApex(t, ` |
| 2320 | apex_vndk { |
| 2321 | name: "myapex", |
| 2322 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2323 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | apex_key { |
| 2327 | name: "myapex.key", |
| 2328 | public_key: "testkey.avbpubkey", |
| 2329 | private_key: "testkey.pem", |
| 2330 | } |
| 2331 | |
| 2332 | cc_library { |
| 2333 | name: "libvndk", |
| 2334 | srcs: ["mylib.cpp"], |
| 2335 | vendor_available: true, |
| 2336 | native_bridge_supported: true, |
| 2337 | host_supported: true, |
| 2338 | vndk: { |
| 2339 | enabled: true, |
| 2340 | }, |
| 2341 | system_shared_libs: [], |
| 2342 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2343 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2344 | } |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2345 | `+vndkLibrariesTxtFiles("current"), withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2346 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2347 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2348 | "lib/libvndk.so", |
| 2349 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2350 | "lib/libc++.so", |
| 2351 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2352 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2353 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
| 2357 | testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
| 2358 | apex_vndk { |
| 2359 | name: "myapex", |
| 2360 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2361 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2362 | native_bridge_supported: true, |
| 2363 | } |
| 2364 | |
| 2365 | apex_key { |
| 2366 | name: "myapex.key", |
| 2367 | public_key: "testkey.avbpubkey", |
| 2368 | private_key: "testkey.pem", |
| 2369 | } |
| 2370 | |
| 2371 | cc_library { |
| 2372 | name: "libvndk", |
| 2373 | srcs: ["mylib.cpp"], |
| 2374 | vendor_available: true, |
| 2375 | native_bridge_supported: true, |
| 2376 | host_supported: true, |
| 2377 | vndk: { |
| 2378 | enabled: true, |
| 2379 | }, |
| 2380 | system_shared_libs: [], |
| 2381 | stl: "none", |
| 2382 | } |
| 2383 | `) |
| 2384 | } |
| 2385 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2386 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2387 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2388 | apex_vndk { |
| 2389 | name: "myapex_v27", |
| 2390 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2391 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2392 | vndk_version: "27", |
| 2393 | } |
| 2394 | |
| 2395 | apex_key { |
| 2396 | name: "myapex.key", |
| 2397 | public_key: "testkey.avbpubkey", |
| 2398 | private_key: "testkey.pem", |
| 2399 | } |
| 2400 | |
| 2401 | vndk_prebuilt_shared { |
| 2402 | name: "libvndk27", |
| 2403 | version: "27", |
| 2404 | target_arch: "arm", |
| 2405 | vendor_available: true, |
| 2406 | vndk: { |
| 2407 | enabled: true, |
| 2408 | }, |
| 2409 | arch: { |
| 2410 | arm: { |
| 2411 | srcs: ["libvndk27.so"], |
| 2412 | } |
| 2413 | }, |
| 2414 | } |
| 2415 | |
| 2416 | vndk_prebuilt_shared { |
| 2417 | name: "libvndk27", |
| 2418 | version: "27", |
| 2419 | target_arch: "arm", |
| 2420 | binder32bit: true, |
| 2421 | vendor_available: true, |
| 2422 | vndk: { |
| 2423 | enabled: true, |
| 2424 | }, |
| 2425 | arch: { |
| 2426 | arm: { |
| 2427 | srcs: ["libvndk27binder32.so"], |
| 2428 | } |
| 2429 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2430 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2431 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2432 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2433 | withFiles(map[string][]byte{ |
| 2434 | "libvndk27.so": nil, |
| 2435 | "libvndk27binder32.so": nil, |
| 2436 | }), |
| 2437 | withBinder32bit, |
| 2438 | withTargets(map[android.OsType][]android.Target{ |
| 2439 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2440 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 2441 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2442 | }, |
| 2443 | }), |
| 2444 | ) |
| 2445 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2446 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2447 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2448 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2449 | }) |
| 2450 | } |
| 2451 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2452 | func TestDependenciesInApexManifest(t *testing.T) { |
| 2453 | ctx, _ := testApex(t, ` |
| 2454 | apex { |
| 2455 | name: "myapex_nodep", |
| 2456 | key: "myapex.key", |
| 2457 | native_shared_libs: ["lib_nodep"], |
| 2458 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2459 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | apex { |
| 2463 | name: "myapex_dep", |
| 2464 | key: "myapex.key", |
| 2465 | native_shared_libs: ["lib_dep"], |
| 2466 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2467 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | apex { |
| 2471 | name: "myapex_provider", |
| 2472 | key: "myapex.key", |
| 2473 | native_shared_libs: ["libfoo"], |
| 2474 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2475 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | apex { |
| 2479 | name: "myapex_selfcontained", |
| 2480 | key: "myapex.key", |
| 2481 | native_shared_libs: ["lib_dep", "libfoo"], |
| 2482 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2483 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | apex_key { |
| 2487 | name: "myapex.key", |
| 2488 | public_key: "testkey.avbpubkey", |
| 2489 | private_key: "testkey.pem", |
| 2490 | } |
| 2491 | |
| 2492 | cc_library { |
| 2493 | name: "lib_nodep", |
| 2494 | srcs: ["mylib.cpp"], |
| 2495 | system_shared_libs: [], |
| 2496 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2497 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | cc_library { |
| 2501 | name: "lib_dep", |
| 2502 | srcs: ["mylib.cpp"], |
| 2503 | shared_libs: ["libfoo"], |
| 2504 | system_shared_libs: [], |
| 2505 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2506 | apex_available: [ |
| 2507 | "myapex_dep", |
| 2508 | "myapex_provider", |
| 2509 | "myapex_selfcontained", |
| 2510 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | cc_library { |
| 2514 | name: "libfoo", |
| 2515 | srcs: ["mytest.cpp"], |
| 2516 | stubs: { |
| 2517 | versions: ["1"], |
| 2518 | }, |
| 2519 | system_shared_libs: [], |
| 2520 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2521 | apex_available: [ |
| 2522 | "myapex_provider", |
| 2523 | "myapex_selfcontained", |
| 2524 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2525 | } |
| 2526 | `) |
| 2527 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2528 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2529 | var provideNativeLibs, requireNativeLibs []string |
| 2530 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2531 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2532 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2533 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2534 | ensureListEmpty(t, provideNativeLibs) |
| 2535 | ensureListEmpty(t, requireNativeLibs) |
| 2536 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2537 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2538 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2539 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2540 | ensureListEmpty(t, provideNativeLibs) |
| 2541 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 2542 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2543 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2544 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2545 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2546 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 2547 | ensureListEmpty(t, requireNativeLibs) |
| 2548 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2549 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2550 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2551 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2552 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 2553 | ensureListEmpty(t, requireNativeLibs) |
| 2554 | } |
| 2555 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2556 | func TestApexName(t *testing.T) { |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2557 | ctx, config := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2558 | apex { |
| 2559 | name: "myapex", |
| 2560 | key: "myapex.key", |
| 2561 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2562 | native_shared_libs: ["mylib"], |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | apex_key { |
| 2566 | name: "myapex.key", |
| 2567 | public_key: "testkey.avbpubkey", |
| 2568 | private_key: "testkey.pem", |
| 2569 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2570 | |
| 2571 | cc_library { |
| 2572 | name: "mylib", |
| 2573 | srcs: ["mylib.cpp"], |
| 2574 | system_shared_libs: [], |
| 2575 | stl: "none", |
| 2576 | apex_available: [ |
| 2577 | "//apex_available:platform", |
| 2578 | "myapex", |
| 2579 | ], |
| 2580 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2581 | `) |
| 2582 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2583 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2584 | apexManifestRule := module.Rule("apexManifestRule") |
| 2585 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 2586 | apexRule := module.Rule("apexRule") |
| 2587 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2588 | |
| 2589 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2590 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2591 | name := apexBundle.BaseModuleName() |
| 2592 | prefix := "TARGET_" |
| 2593 | var builder strings.Builder |
| 2594 | data.Custom(&builder, name, prefix, "", data) |
| 2595 | androidMk := builder.String() |
| 2596 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 2597 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2598 | } |
| 2599 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2600 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2601 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2602 | apex { |
| 2603 | name: "myapex", |
| 2604 | key: "myapex.key", |
| 2605 | native_shared_libs: ["mylib_common"], |
| 2606 | } |
| 2607 | |
| 2608 | apex_key { |
| 2609 | name: "myapex.key", |
| 2610 | public_key: "testkey.avbpubkey", |
| 2611 | private_key: "testkey.pem", |
| 2612 | } |
| 2613 | |
| 2614 | cc_library { |
| 2615 | name: "mylib_common", |
| 2616 | srcs: ["mylib.cpp"], |
| 2617 | system_shared_libs: [], |
| 2618 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2619 | apex_available: [ |
| 2620 | "//apex_available:platform", |
| 2621 | "myapex", |
| 2622 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2623 | } |
| 2624 | `) |
| 2625 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2626 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2627 | apexRule := module.Rule("apexRule") |
| 2628 | copyCmds := apexRule.Args["copy_commands"] |
| 2629 | |
| 2630 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 2631 | t.Log("Apex was a test apex!") |
| 2632 | t.Fail() |
| 2633 | } |
| 2634 | // Ensure that main rule creates an output |
| 2635 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2636 | |
| 2637 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2638 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2639 | |
| 2640 | // Ensure that both direct and indirect deps are copied into apex |
| 2641 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 2642 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2643 | // Ensure that the platform variant ends with _shared |
| 2644 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2645 | |
| 2646 | if !android.InAnyApex("mylib_common") { |
| 2647 | t.Log("Found mylib_common not in any apex!") |
| 2648 | t.Fail() |
| 2649 | } |
| 2650 | } |
| 2651 | |
| 2652 | func TestTestApex(t *testing.T) { |
| 2653 | if android.InAnyApex("mylib_common_test") { |
| 2654 | 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!") |
| 2655 | } |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2656 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2657 | apex_test { |
| 2658 | name: "myapex", |
| 2659 | key: "myapex.key", |
| 2660 | native_shared_libs: ["mylib_common_test"], |
| 2661 | } |
| 2662 | |
| 2663 | apex_key { |
| 2664 | name: "myapex.key", |
| 2665 | public_key: "testkey.avbpubkey", |
| 2666 | private_key: "testkey.pem", |
| 2667 | } |
| 2668 | |
| 2669 | cc_library { |
| 2670 | name: "mylib_common_test", |
| 2671 | srcs: ["mylib.cpp"], |
| 2672 | system_shared_libs: [], |
| 2673 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2674 | // TODO: remove //apex_available:platform |
| 2675 | apex_available: [ |
| 2676 | "//apex_available:platform", |
| 2677 | "myapex", |
| 2678 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2679 | } |
| 2680 | `) |
| 2681 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2682 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2683 | apexRule := module.Rule("apexRule") |
| 2684 | copyCmds := apexRule.Args["copy_commands"] |
| 2685 | |
| 2686 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 2687 | t.Log("Apex was not a test apex!") |
| 2688 | t.Fail() |
| 2689 | } |
| 2690 | // Ensure that main rule creates an output |
| 2691 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2692 | |
| 2693 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2694 | 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] | 2695 | |
| 2696 | // Ensure that both direct and indirect deps are copied into apex |
| 2697 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 2698 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2699 | // Ensure that the platform variant ends with _shared |
| 2700 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2701 | } |
| 2702 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2703 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2704 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2705 | apex { |
| 2706 | name: "myapex", |
| 2707 | key: "myapex.key", |
| 2708 | multilib: { |
| 2709 | first: { |
| 2710 | native_shared_libs: ["mylib_common"], |
| 2711 | } |
| 2712 | }, |
| 2713 | target: { |
| 2714 | android: { |
| 2715 | multilib: { |
| 2716 | first: { |
| 2717 | native_shared_libs: ["mylib"], |
| 2718 | } |
| 2719 | } |
| 2720 | }, |
| 2721 | host: { |
| 2722 | multilib: { |
| 2723 | first: { |
| 2724 | native_shared_libs: ["mylib2"], |
| 2725 | } |
| 2726 | } |
| 2727 | } |
| 2728 | } |
| 2729 | } |
| 2730 | |
| 2731 | apex_key { |
| 2732 | name: "myapex.key", |
| 2733 | public_key: "testkey.avbpubkey", |
| 2734 | private_key: "testkey.pem", |
| 2735 | } |
| 2736 | |
| 2737 | cc_library { |
| 2738 | name: "mylib", |
| 2739 | srcs: ["mylib.cpp"], |
| 2740 | system_shared_libs: [], |
| 2741 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2742 | // TODO: remove //apex_available:platform |
| 2743 | apex_available: [ |
| 2744 | "//apex_available:platform", |
| 2745 | "myapex", |
| 2746 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | cc_library { |
| 2750 | name: "mylib_common", |
| 2751 | srcs: ["mylib.cpp"], |
| 2752 | system_shared_libs: [], |
| 2753 | stl: "none", |
| 2754 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2755 | // TODO: remove //apex_available:platform |
| 2756 | apex_available: [ |
| 2757 | "//apex_available:platform", |
| 2758 | "myapex", |
| 2759 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | cc_library { |
| 2763 | name: "mylib2", |
| 2764 | srcs: ["mylib.cpp"], |
| 2765 | system_shared_libs: [], |
| 2766 | stl: "none", |
| 2767 | compile_multilib: "first", |
| 2768 | } |
| 2769 | `) |
| 2770 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2771 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2772 | copyCmds := apexRule.Args["copy_commands"] |
| 2773 | |
| 2774 | // Ensure that main rule creates an output |
| 2775 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2776 | |
| 2777 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2778 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 2779 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
| 2780 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2781 | |
| 2782 | // Ensure that both direct and indirect deps are copied into apex |
| 2783 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 2784 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 2785 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 2786 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2787 | // Ensure that the platform variant ends with _shared |
| 2788 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 2789 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 2790 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2791 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2792 | |
| 2793 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2794 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2795 | apex { |
| 2796 | name: "myapex", |
| 2797 | key: "myapex.key", |
| 2798 | binaries: ["myscript"], |
| 2799 | } |
| 2800 | |
| 2801 | apex_key { |
| 2802 | name: "myapex.key", |
| 2803 | public_key: "testkey.avbpubkey", |
| 2804 | private_key: "testkey.pem", |
| 2805 | } |
| 2806 | |
| 2807 | sh_binary { |
| 2808 | name: "myscript", |
| 2809 | src: "mylib.cpp", |
| 2810 | filename: "myscript.sh", |
| 2811 | sub_dir: "script", |
| 2812 | } |
| 2813 | `) |
| 2814 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2815 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2816 | copyCmds := apexRule.Args["copy_commands"] |
| 2817 | |
| 2818 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 2819 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2820 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2821 | func TestApexInVariousPartition(t *testing.T) { |
| 2822 | testcases := []struct { |
| 2823 | propName, parition, flattenedPartition string |
| 2824 | }{ |
| 2825 | {"", "system", "system_ext"}, |
| 2826 | {"product_specific: true", "product", "product"}, |
| 2827 | {"soc_specific: true", "vendor", "vendor"}, |
| 2828 | {"proprietary: true", "vendor", "vendor"}, |
| 2829 | {"vendor: true", "vendor", "vendor"}, |
| 2830 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 2831 | } |
| 2832 | for _, tc := range testcases { |
| 2833 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 2834 | ctx, _ := testApex(t, ` |
| 2835 | apex { |
| 2836 | name: "myapex", |
| 2837 | key: "myapex.key", |
| 2838 | `+tc.propName+` |
| 2839 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2840 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2841 | apex_key { |
| 2842 | name: "myapex.key", |
| 2843 | public_key: "testkey.avbpubkey", |
| 2844 | private_key: "testkey.pem", |
| 2845 | } |
| 2846 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2847 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2848 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2849 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 2850 | actual := apex.installDir.String() |
| 2851 | if actual != expected { |
| 2852 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 2853 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2854 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2855 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 2856 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 2857 | actual = flattened.installDir.String() |
| 2858 | if actual != expected { |
| 2859 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 2860 | } |
| 2861 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2862 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2863 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2864 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2865 | func TestFileContexts(t *testing.T) { |
| 2866 | ctx, _ := testApex(t, ` |
| 2867 | apex { |
| 2868 | name: "myapex", |
| 2869 | key: "myapex.key", |
| 2870 | } |
| 2871 | |
| 2872 | apex_key { |
| 2873 | name: "myapex.key", |
| 2874 | public_key: "testkey.avbpubkey", |
| 2875 | private_key: "testkey.pem", |
| 2876 | } |
| 2877 | `) |
| 2878 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2879 | apexRule := module.Rule("apexRule") |
| 2880 | actual := apexRule.Args["file_contexts"] |
| 2881 | expected := "system/sepolicy/apex/myapex-file_contexts" |
| 2882 | if actual != expected { |
| 2883 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2884 | } |
| 2885 | |
| 2886 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
| 2887 | apex { |
| 2888 | name: "myapex", |
| 2889 | key: "myapex.key", |
| 2890 | file_contexts: "my_own_file_contexts", |
| 2891 | } |
| 2892 | |
| 2893 | apex_key { |
| 2894 | name: "myapex.key", |
| 2895 | public_key: "testkey.avbpubkey", |
| 2896 | private_key: "testkey.pem", |
| 2897 | } |
| 2898 | `, withFiles(map[string][]byte{ |
| 2899 | "my_own_file_contexts": nil, |
| 2900 | })) |
| 2901 | |
| 2902 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
| 2903 | apex { |
| 2904 | name: "myapex", |
| 2905 | key: "myapex.key", |
| 2906 | product_specific: true, |
| 2907 | file_contexts: "product_specific_file_contexts", |
| 2908 | } |
| 2909 | |
| 2910 | apex_key { |
| 2911 | name: "myapex.key", |
| 2912 | public_key: "testkey.avbpubkey", |
| 2913 | private_key: "testkey.pem", |
| 2914 | } |
| 2915 | `) |
| 2916 | |
| 2917 | ctx, _ = testApex(t, ` |
| 2918 | apex { |
| 2919 | name: "myapex", |
| 2920 | key: "myapex.key", |
| 2921 | product_specific: true, |
| 2922 | file_contexts: "product_specific_file_contexts", |
| 2923 | } |
| 2924 | |
| 2925 | apex_key { |
| 2926 | name: "myapex.key", |
| 2927 | public_key: "testkey.avbpubkey", |
| 2928 | private_key: "testkey.pem", |
| 2929 | } |
| 2930 | `, withFiles(map[string][]byte{ |
| 2931 | "product_specific_file_contexts": nil, |
| 2932 | })) |
| 2933 | module = ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2934 | apexRule = module.Rule("apexRule") |
| 2935 | actual = apexRule.Args["file_contexts"] |
| 2936 | expected = "product_specific_file_contexts" |
| 2937 | if actual != expected { |
| 2938 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2939 | } |
| 2940 | |
| 2941 | ctx, _ = testApex(t, ` |
| 2942 | apex { |
| 2943 | name: "myapex", |
| 2944 | key: "myapex.key", |
| 2945 | product_specific: true, |
| 2946 | file_contexts: ":my-file-contexts", |
| 2947 | } |
| 2948 | |
| 2949 | apex_key { |
| 2950 | name: "myapex.key", |
| 2951 | public_key: "testkey.avbpubkey", |
| 2952 | private_key: "testkey.pem", |
| 2953 | } |
| 2954 | |
| 2955 | filegroup { |
| 2956 | name: "my-file-contexts", |
| 2957 | srcs: ["product_specific_file_contexts"], |
| 2958 | } |
| 2959 | `, withFiles(map[string][]byte{ |
| 2960 | "product_specific_file_contexts": nil, |
| 2961 | })) |
| 2962 | module = ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2963 | apexRule = module.Rule("apexRule") |
| 2964 | actual = apexRule.Args["file_contexts"] |
| 2965 | expected = "product_specific_file_contexts" |
| 2966 | if actual != expected { |
| 2967 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2968 | } |
| 2969 | } |
| 2970 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2971 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2972 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2973 | apex_key { |
| 2974 | name: "myapex.key", |
| 2975 | public_key: ":my.avbpubkey", |
| 2976 | private_key: ":my.pem", |
| 2977 | product_specific: true, |
| 2978 | } |
| 2979 | |
| 2980 | filegroup { |
| 2981 | name: "my.avbpubkey", |
| 2982 | srcs: ["testkey2.avbpubkey"], |
| 2983 | } |
| 2984 | |
| 2985 | filegroup { |
| 2986 | name: "my.pem", |
| 2987 | srcs: ["testkey2.pem"], |
| 2988 | } |
| 2989 | `) |
| 2990 | |
| 2991 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 2992 | expected_pubkey := "testkey2.avbpubkey" |
| 2993 | actual_pubkey := apex_key.public_key_file.String() |
| 2994 | if actual_pubkey != expected_pubkey { |
| 2995 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 2996 | } |
| 2997 | expected_privkey := "testkey2.pem" |
| 2998 | actual_privkey := apex_key.private_key_file.String() |
| 2999 | if actual_privkey != expected_privkey { |
| 3000 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 3001 | } |
| 3002 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3003 | |
| 3004 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3005 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3006 | prebuilt_apex { |
| 3007 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 3008 | arch: { |
| 3009 | arm64: { |
| 3010 | src: "myapex-arm64.apex", |
| 3011 | }, |
| 3012 | arm: { |
| 3013 | src: "myapex-arm.apex", |
| 3014 | }, |
| 3015 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3016 | } |
| 3017 | `) |
| 3018 | |
| 3019 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 3020 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 3021 | expectedInput := "myapex-arm64.apex" |
| 3022 | if prebuilt.inputApex.String() != expectedInput { |
| 3023 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 3024 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3025 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 3026 | |
| 3027 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3028 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 3029 | prebuilt_apex { |
| 3030 | name: "myapex", |
| 3031 | src: "myapex-arm.apex", |
| 3032 | filename: "notmyapex.apex", |
| 3033 | } |
| 3034 | `) |
| 3035 | |
| 3036 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 3037 | |
| 3038 | expected := "notmyapex.apex" |
| 3039 | if p.installFilename != expected { |
| 3040 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 3041 | } |
| 3042 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 3043 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3044 | func TestPrebuiltOverrides(t *testing.T) { |
| 3045 | ctx, config := testApex(t, ` |
| 3046 | prebuilt_apex { |
| 3047 | name: "myapex.prebuilt", |
| 3048 | src: "myapex-arm.apex", |
| 3049 | overrides: [ |
| 3050 | "myapex", |
| 3051 | ], |
| 3052 | } |
| 3053 | `) |
| 3054 | |
| 3055 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 3056 | |
| 3057 | expected := []string{"myapex"} |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 3058 | actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3059 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 3060 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3061 | } |
| 3062 | } |
| 3063 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3064 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3065 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3066 | apex_test { |
| 3067 | name: "myapex", |
| 3068 | key: "myapex.key", |
| 3069 | tests: [ |
| 3070 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3071 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3072 | ], |
| 3073 | } |
| 3074 | |
| 3075 | apex_key { |
| 3076 | name: "myapex.key", |
| 3077 | public_key: "testkey.avbpubkey", |
| 3078 | private_key: "testkey.pem", |
| 3079 | } |
| 3080 | |
| 3081 | cc_test { |
| 3082 | name: "mytest", |
| 3083 | gtest: false, |
| 3084 | srcs: ["mytest.cpp"], |
| 3085 | relative_install_path: "test", |
| 3086 | system_shared_libs: [], |
| 3087 | static_executable: true, |
| 3088 | stl: "none", |
| 3089 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3090 | |
| 3091 | cc_test { |
| 3092 | name: "mytests", |
| 3093 | gtest: false, |
| 3094 | srcs: [ |
| 3095 | "mytest1.cpp", |
| 3096 | "mytest2.cpp", |
| 3097 | "mytest3.cpp", |
| 3098 | ], |
| 3099 | test_per_src: true, |
| 3100 | relative_install_path: "test", |
| 3101 | system_shared_libs: [], |
| 3102 | static_executable: true, |
| 3103 | stl: "none", |
| 3104 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3105 | `) |
| 3106 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3107 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3108 | copyCmds := apexRule.Args["copy_commands"] |
| 3109 | |
| 3110 | // Ensure that test dep is copied into apex. |
| 3111 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3112 | |
| 3113 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 3114 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 3115 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 3116 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3117 | |
| 3118 | // Ensure the module is correctly translated. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3119 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3120 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3121 | name := apexBundle.BaseModuleName() |
| 3122 | prefix := "TARGET_" |
| 3123 | var builder strings.Builder |
| 3124 | data.Custom(&builder, name, prefix, "", data) |
| 3125 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3126 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 3127 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 3128 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 3129 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3130 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3131 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3132 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3133 | } |
| 3134 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 3135 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
| 3136 | ctx, config := testApex(t, ` |
| 3137 | apex { |
| 3138 | name: "myapex", |
| 3139 | key: "myapex.key", |
| 3140 | } |
| 3141 | apex_key { |
| 3142 | name: "myapex.key", |
| 3143 | public_key: "testkey.avbpubkey", |
| 3144 | private_key: "testkey.pem", |
| 3145 | } |
| 3146 | `, func(fs map[string][]byte, config android.Config) { |
| 3147 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 3148 | }) |
| 3149 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 3150 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 3151 | mk := android.AndroidMkDataForTest(t, config, "", ab) |
| 3152 | var builder strings.Builder |
| 3153 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 3154 | androidMk := builder.String() |
| 3155 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 3156 | } |
| 3157 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3158 | func TestApexUsesOtherApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3159 | ctx, _ := testApex(t, ` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3160 | apex { |
| 3161 | name: "myapex", |
| 3162 | key: "myapex.key", |
| 3163 | native_shared_libs: ["mylib"], |
| 3164 | uses: ["commonapex"], |
| 3165 | } |
| 3166 | |
| 3167 | apex { |
| 3168 | name: "commonapex", |
| 3169 | key: "myapex.key", |
| 3170 | native_shared_libs: ["libcommon"], |
| 3171 | provide_cpp_shared_libs: true, |
| 3172 | } |
| 3173 | |
| 3174 | apex_key { |
| 3175 | name: "myapex.key", |
| 3176 | public_key: "testkey.avbpubkey", |
| 3177 | private_key: "testkey.pem", |
| 3178 | } |
| 3179 | |
| 3180 | cc_library { |
| 3181 | name: "mylib", |
| 3182 | srcs: ["mylib.cpp"], |
| 3183 | shared_libs: ["libcommon"], |
| 3184 | system_shared_libs: [], |
| 3185 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3186 | apex_available: [ "myapex" ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | cc_library { |
| 3190 | name: "libcommon", |
| 3191 | srcs: ["mylib_common.cpp"], |
| 3192 | system_shared_libs: [], |
| 3193 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3194 | // TODO: remove //apex_available:platform |
| 3195 | apex_available: [ |
| 3196 | "//apex_available:platform", |
| 3197 | "commonapex", |
| 3198 | "myapex", |
| 3199 | ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3200 | } |
| 3201 | `) |
| 3202 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3203 | module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3204 | apexRule1 := module1.Rule("apexRule") |
| 3205 | copyCmds1 := apexRule1.Args["copy_commands"] |
| 3206 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3207 | module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3208 | apexRule2 := module2.Rule("apexRule") |
| 3209 | copyCmds2 := apexRule2.Args["copy_commands"] |
| 3210 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3211 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 3212 | ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3213 | ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so") |
| 3214 | ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so") |
| 3215 | ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so") |
| 3216 | } |
| 3217 | |
| 3218 | func TestApexUsesFailsIfNotProvided(t *testing.T) { |
| 3219 | testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, ` |
| 3220 | apex { |
| 3221 | name: "myapex", |
| 3222 | key: "myapex.key", |
| 3223 | uses: ["commonapex"], |
| 3224 | } |
| 3225 | |
| 3226 | apex { |
| 3227 | name: "commonapex", |
| 3228 | key: "myapex.key", |
| 3229 | } |
| 3230 | |
| 3231 | apex_key { |
| 3232 | name: "myapex.key", |
| 3233 | public_key: "testkey.avbpubkey", |
| 3234 | private_key: "testkey.pem", |
| 3235 | } |
| 3236 | `) |
| 3237 | testApexError(t, `uses: "commonapex" is not a provider`, ` |
| 3238 | apex { |
| 3239 | name: "myapex", |
| 3240 | key: "myapex.key", |
| 3241 | uses: ["commonapex"], |
| 3242 | } |
| 3243 | |
| 3244 | cc_library { |
| 3245 | name: "commonapex", |
| 3246 | system_shared_libs: [], |
| 3247 | stl: "none", |
| 3248 | } |
| 3249 | |
| 3250 | apex_key { |
| 3251 | name: "myapex.key", |
| 3252 | public_key: "testkey.avbpubkey", |
| 3253 | private_key: "testkey.pem", |
| 3254 | } |
| 3255 | `) |
| 3256 | } |
| 3257 | |
| 3258 | func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) { |
| 3259 | testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, ` |
| 3260 | apex { |
| 3261 | name: "myapex", |
| 3262 | key: "myapex.key", |
| 3263 | use_vendor: true, |
| 3264 | uses: ["commonapex"], |
| 3265 | } |
| 3266 | |
| 3267 | apex { |
| 3268 | name: "commonapex", |
| 3269 | key: "myapex.key", |
| 3270 | provide_cpp_shared_libs: true, |
| 3271 | } |
| 3272 | |
| 3273 | apex_key { |
| 3274 | name: "myapex.key", |
| 3275 | public_key: "testkey.avbpubkey", |
| 3276 | private_key: "testkey.pem", |
| 3277 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 3278 | `, func(fs map[string][]byte, config android.Config) { |
| 3279 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 3280 | }) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3281 | } |
| 3282 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3283 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 3284 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 3285 | apex { |
| 3286 | name: "myapex", |
| 3287 | key: "myapex.key", |
| 3288 | native_shared_libs: ["libfoo"], |
| 3289 | } |
| 3290 | |
| 3291 | apex_key { |
| 3292 | name: "myapex.key", |
| 3293 | public_key: "testkey.avbpubkey", |
| 3294 | private_key: "testkey.pem", |
| 3295 | } |
| 3296 | |
| 3297 | cc_library { |
| 3298 | name: "libfoo", |
| 3299 | stl: "none", |
| 3300 | system_shared_libs: [], |
| 3301 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3302 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3303 | } |
| 3304 | `) |
| 3305 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 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", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3323 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3324 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3325 | } |
| 3326 | `) |
| 3327 | } |
| 3328 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3329 | func TestApexWithApps(t *testing.T) { |
| 3330 | ctx, _ := testApex(t, ` |
| 3331 | apex { |
| 3332 | name: "myapex", |
| 3333 | key: "myapex.key", |
| 3334 | apps: [ |
| 3335 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3336 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3337 | ], |
| 3338 | } |
| 3339 | |
| 3340 | apex_key { |
| 3341 | name: "myapex.key", |
| 3342 | public_key: "testkey.avbpubkey", |
| 3343 | private_key: "testkey.pem", |
| 3344 | } |
| 3345 | |
| 3346 | android_app { |
| 3347 | name: "AppFoo", |
| 3348 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3349 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3350 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3351 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3352 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3353 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3354 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3355 | |
| 3356 | android_app { |
| 3357 | name: "AppFooPriv", |
| 3358 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3359 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3360 | system_modules: "none", |
| 3361 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3362 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3363 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3364 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3365 | |
| 3366 | cc_library_shared { |
| 3367 | name: "libjni", |
| 3368 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3369 | shared_libs: ["libfoo"], |
| 3370 | stl: "none", |
| 3371 | system_shared_libs: [], |
| 3372 | apex_available: [ "myapex" ], |
| 3373 | sdk_version: "current", |
| 3374 | } |
| 3375 | |
| 3376 | cc_library_shared { |
| 3377 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3378 | stl: "none", |
| 3379 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3380 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3381 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3382 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3383 | `) |
| 3384 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3385 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3386 | apexRule := module.Rule("apexRule") |
| 3387 | copyCmds := apexRule.Args["copy_commands"] |
| 3388 | |
| 3389 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3390 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 3391 | |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3392 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs") |
| 3393 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 3394 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3395 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 3396 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3397 | // JNI libraries including transitive deps are |
| 3398 | for _, jni := range []string{"libjni", "libfoo"} { |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 3399 | jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_sdk_shared_myapex").Module().(*cc.Module).OutputFile() |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3400 | // ... embedded inside APK (jnilibs.zip) |
| 3401 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 3402 | // ... and not directly inside the APEX |
| 3403 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 3404 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3405 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3406 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3407 | func TestApexWithAppImports(t *testing.T) { |
| 3408 | ctx, _ := testApex(t, ` |
| 3409 | apex { |
| 3410 | name: "myapex", |
| 3411 | key: "myapex.key", |
| 3412 | apps: [ |
| 3413 | "AppFooPrebuilt", |
| 3414 | "AppFooPrivPrebuilt", |
| 3415 | ], |
| 3416 | } |
| 3417 | |
| 3418 | apex_key { |
| 3419 | name: "myapex.key", |
| 3420 | public_key: "testkey.avbpubkey", |
| 3421 | private_key: "testkey.pem", |
| 3422 | } |
| 3423 | |
| 3424 | android_app_import { |
| 3425 | name: "AppFooPrebuilt", |
| 3426 | apk: "PrebuiltAppFoo.apk", |
| 3427 | presigned: true, |
| 3428 | dex_preopt: { |
| 3429 | enabled: false, |
| 3430 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 3431 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3432 | } |
| 3433 | |
| 3434 | android_app_import { |
| 3435 | name: "AppFooPrivPrebuilt", |
| 3436 | apk: "PrebuiltAppFooPriv.apk", |
| 3437 | privileged: true, |
| 3438 | presigned: true, |
| 3439 | dex_preopt: { |
| 3440 | enabled: false, |
| 3441 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 3442 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 3443 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3444 | } |
| 3445 | `) |
| 3446 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3447 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3448 | apexRule := module.Rule("apexRule") |
| 3449 | copyCmds := apexRule.Args["copy_commands"] |
| 3450 | |
| 3451 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 3452 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 3453 | } |
| 3454 | |
| 3455 | func TestApexWithAppImportsPrefer(t *testing.T) { |
| 3456 | ctx, _ := testApex(t, ` |
| 3457 | apex { |
| 3458 | name: "myapex", |
| 3459 | key: "myapex.key", |
| 3460 | apps: [ |
| 3461 | "AppFoo", |
| 3462 | ], |
| 3463 | } |
| 3464 | |
| 3465 | apex_key { |
| 3466 | name: "myapex.key", |
| 3467 | public_key: "testkey.avbpubkey", |
| 3468 | private_key: "testkey.pem", |
| 3469 | } |
| 3470 | |
| 3471 | android_app { |
| 3472 | name: "AppFoo", |
| 3473 | srcs: ["foo/bar/MyClass.java"], |
| 3474 | sdk_version: "none", |
| 3475 | system_modules: "none", |
| 3476 | apex_available: [ "myapex" ], |
| 3477 | } |
| 3478 | |
| 3479 | android_app_import { |
| 3480 | name: "AppFoo", |
| 3481 | apk: "AppFooPrebuilt.apk", |
| 3482 | filename: "AppFooPrebuilt.apk", |
| 3483 | presigned: true, |
| 3484 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 3485 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 3486 | } |
| 3487 | `, withFiles(map[string][]byte{ |
| 3488 | "AppFooPrebuilt.apk": nil, |
| 3489 | })) |
| 3490 | |
| 3491 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 3492 | "app/AppFoo/AppFooPrebuilt.apk", |
| 3493 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3494 | } |
| 3495 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 3496 | func TestApexWithTestHelperApp(t *testing.T) { |
| 3497 | ctx, _ := testApex(t, ` |
| 3498 | apex { |
| 3499 | name: "myapex", |
| 3500 | key: "myapex.key", |
| 3501 | apps: [ |
| 3502 | "TesterHelpAppFoo", |
| 3503 | ], |
| 3504 | } |
| 3505 | |
| 3506 | apex_key { |
| 3507 | name: "myapex.key", |
| 3508 | public_key: "testkey.avbpubkey", |
| 3509 | private_key: "testkey.pem", |
| 3510 | } |
| 3511 | |
| 3512 | android_test_helper_app { |
| 3513 | name: "TesterHelpAppFoo", |
| 3514 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3515 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | `) |
| 3519 | |
| 3520 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3521 | apexRule := module.Rule("apexRule") |
| 3522 | copyCmds := apexRule.Args["copy_commands"] |
| 3523 | |
| 3524 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 3525 | } |
| 3526 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 3527 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 3528 | // libfoo's apex_available comes from cc_defaults |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3529 | testApexError(t, `requires "libfoo" that is not available for the APEX`, ` |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 3530 | apex { |
| 3531 | name: "myapex", |
| 3532 | key: "myapex.key", |
| 3533 | native_shared_libs: ["libfoo"], |
| 3534 | } |
| 3535 | |
| 3536 | apex_key { |
| 3537 | name: "myapex.key", |
| 3538 | public_key: "testkey.avbpubkey", |
| 3539 | private_key: "testkey.pem", |
| 3540 | } |
| 3541 | |
| 3542 | apex { |
| 3543 | name: "otherapex", |
| 3544 | key: "myapex.key", |
| 3545 | native_shared_libs: ["libfoo"], |
| 3546 | } |
| 3547 | |
| 3548 | cc_defaults { |
| 3549 | name: "libfoo-defaults", |
| 3550 | apex_available: ["otherapex"], |
| 3551 | } |
| 3552 | |
| 3553 | cc_library { |
| 3554 | name: "libfoo", |
| 3555 | defaults: ["libfoo-defaults"], |
| 3556 | stl: "none", |
| 3557 | system_shared_libs: [], |
| 3558 | }`) |
| 3559 | } |
| 3560 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3561 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3562 | // libfoo is not available to myapex, but only to otherapex |
| 3563 | testApexError(t, "requires \"libfoo\" that is not available for the APEX", ` |
| 3564 | apex { |
| 3565 | name: "myapex", |
| 3566 | key: "myapex.key", |
| 3567 | native_shared_libs: ["libfoo"], |
| 3568 | } |
| 3569 | |
| 3570 | apex_key { |
| 3571 | name: "myapex.key", |
| 3572 | public_key: "testkey.avbpubkey", |
| 3573 | private_key: "testkey.pem", |
| 3574 | } |
| 3575 | |
| 3576 | apex { |
| 3577 | name: "otherapex", |
| 3578 | key: "otherapex.key", |
| 3579 | native_shared_libs: ["libfoo"], |
| 3580 | } |
| 3581 | |
| 3582 | apex_key { |
| 3583 | name: "otherapex.key", |
| 3584 | public_key: "testkey.avbpubkey", |
| 3585 | private_key: "testkey.pem", |
| 3586 | } |
| 3587 | |
| 3588 | cc_library { |
| 3589 | name: "libfoo", |
| 3590 | stl: "none", |
| 3591 | system_shared_libs: [], |
| 3592 | apex_available: ["otherapex"], |
| 3593 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3594 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3595 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3596 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3597 | // libbbaz is an indirect dep |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 3598 | testApexError(t, `requires "libbaz" that is not available for the APEX. Dependency path: |
Paul Duffin | c519244 | 2020-03-31 11:31:36 +0100 | [diff] [blame] | 3599 | .*via tag apex\.dependencyTag.*"sharedLib".* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 3600 | .*-> libfoo.*link:shared.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 3601 | .*via tag cc\.DependencyTag.*"shared".* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 3602 | .*-> libbar.*link:shared.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 3603 | .*via tag cc\.DependencyTag.*"shared".* |
| 3604 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3605 | apex { |
| 3606 | name: "myapex", |
| 3607 | key: "myapex.key", |
| 3608 | native_shared_libs: ["libfoo"], |
| 3609 | } |
| 3610 | |
| 3611 | apex_key { |
| 3612 | name: "myapex.key", |
| 3613 | public_key: "testkey.avbpubkey", |
| 3614 | private_key: "testkey.pem", |
| 3615 | } |
| 3616 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3617 | cc_library { |
| 3618 | name: "libfoo", |
| 3619 | stl: "none", |
| 3620 | shared_libs: ["libbar"], |
| 3621 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3622 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | cc_library { |
| 3626 | name: "libbar", |
| 3627 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3628 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3629 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3630 | apex_available: ["myapex"], |
| 3631 | } |
| 3632 | |
| 3633 | cc_library { |
| 3634 | name: "libbaz", |
| 3635 | stl: "none", |
| 3636 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3637 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3638 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3639 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3640 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3641 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 3642 | apex { |
| 3643 | name: "myapex", |
| 3644 | key: "myapex.key", |
| 3645 | native_shared_libs: ["libfoo"], |
| 3646 | } |
| 3647 | |
| 3648 | apex_key { |
| 3649 | name: "myapex.key", |
| 3650 | public_key: "testkey.avbpubkey", |
| 3651 | private_key: "testkey.pem", |
| 3652 | } |
| 3653 | |
| 3654 | cc_library { |
| 3655 | name: "libfoo", |
| 3656 | stl: "none", |
| 3657 | system_shared_libs: [], |
| 3658 | apex_available: ["otherapex"], |
| 3659 | }`) |
| 3660 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3661 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3662 | apex { |
| 3663 | name: "myapex", |
| 3664 | key: "myapex.key", |
| 3665 | native_shared_libs: ["libfoo", "libbar"], |
| 3666 | } |
| 3667 | |
| 3668 | apex_key { |
| 3669 | name: "myapex.key", |
| 3670 | public_key: "testkey.avbpubkey", |
| 3671 | private_key: "testkey.pem", |
| 3672 | } |
| 3673 | |
| 3674 | cc_library { |
| 3675 | name: "libfoo", |
| 3676 | stl: "none", |
| 3677 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 3678 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3679 | apex_available: ["myapex"], |
| 3680 | } |
| 3681 | |
| 3682 | cc_library { |
| 3683 | name: "libbar", |
| 3684 | stl: "none", |
| 3685 | system_shared_libs: [], |
| 3686 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | cc_library { |
| 3690 | name: "libbaz", |
| 3691 | stl: "none", |
| 3692 | system_shared_libs: [], |
| 3693 | stubs: { |
| 3694 | versions: ["10", "20", "30"], |
| 3695 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3696 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3697 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3698 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame^] | 3699 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3700 | ctx, _ := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3701 | apex { |
| 3702 | name: "myapex", |
| 3703 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame^] | 3704 | native_shared_libs: ["libbar", "libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3705 | } |
| 3706 | |
| 3707 | apex_key { |
| 3708 | name: "myapex.key", |
| 3709 | public_key: "testkey.avbpubkey", |
| 3710 | private_key: "testkey.pem", |
| 3711 | } |
| 3712 | |
| 3713 | cc_library { |
| 3714 | name: "libfoo", |
| 3715 | stl: "none", |
| 3716 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame^] | 3717 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3718 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame^] | 3719 | } |
| 3720 | |
| 3721 | cc_library { |
| 3722 | name: "libfoo2", |
| 3723 | stl: "none", |
| 3724 | system_shared_libs: [], |
| 3725 | shared_libs: ["libbaz"], |
| 3726 | apex_available: ["//apex_available:platform"], |
| 3727 | } |
| 3728 | |
| 3729 | cc_library { |
| 3730 | name: "libbar", |
| 3731 | stl: "none", |
| 3732 | system_shared_libs: [], |
| 3733 | apex_available: ["myapex"], |
| 3734 | } |
| 3735 | |
| 3736 | cc_library { |
| 3737 | name: "libbaz", |
| 3738 | stl: "none", |
| 3739 | system_shared_libs: [], |
| 3740 | apex_available: ["myapex"], |
| 3741 | stubs: { |
| 3742 | versions: ["1"], |
| 3743 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3744 | }`) |
| 3745 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame^] | 3746 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 3747 | // because it depends on libbar which isn't available to platform |
| 3748 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 3749 | if libfoo.NotAvailableForPlatform() != true { |
| 3750 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 3751 | } |
| 3752 | |
| 3753 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 3754 | // stubs |
| 3755 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 3756 | if libfoo2.NotAvailableForPlatform() == true { |
| 3757 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 3758 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3759 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 3760 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3761 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame^] | 3762 | ctx, _ := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 3763 | apex { |
| 3764 | name: "myapex", |
| 3765 | key: "myapex.key", |
| 3766 | native_shared_libs: ["libfoo"], |
| 3767 | } |
| 3768 | |
| 3769 | apex_key { |
| 3770 | name: "myapex.key", |
| 3771 | public_key: "testkey.avbpubkey", |
| 3772 | private_key: "testkey.pem", |
| 3773 | } |
| 3774 | |
| 3775 | cc_library { |
| 3776 | name: "libfoo", |
| 3777 | stl: "none", |
| 3778 | system_shared_libs: [], |
| 3779 | apex_available: ["myapex"], |
| 3780 | static: { |
| 3781 | apex_available: ["//apex_available:platform"], |
| 3782 | }, |
| 3783 | }`) |
| 3784 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame^] | 3785 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 3786 | if libfooShared.NotAvailableForPlatform() != true { |
| 3787 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 3788 | } |
| 3789 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 3790 | if libfooStatic.NotAvailableForPlatform() != false { |
| 3791 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 3792 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3793 | } |
| 3794 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3795 | func TestOverrideApex(t *testing.T) { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3796 | ctx, config := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3797 | apex { |
| 3798 | name: "myapex", |
| 3799 | key: "myapex.key", |
| 3800 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3801 | overrides: ["oldapex"], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | override_apex { |
| 3805 | name: "override_myapex", |
| 3806 | base: "myapex", |
| 3807 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3808 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 3809 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 3810 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | apex_key { |
| 3814 | name: "myapex.key", |
| 3815 | public_key: "testkey.avbpubkey", |
| 3816 | private_key: "testkey.pem", |
| 3817 | } |
| 3818 | |
| 3819 | android_app { |
| 3820 | name: "app", |
| 3821 | srcs: ["foo/bar/MyClass.java"], |
| 3822 | package_name: "foo", |
| 3823 | sdk_version: "none", |
| 3824 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3825 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | override_android_app { |
| 3829 | name: "override_app", |
| 3830 | base: "app", |
| 3831 | package_name: "bar", |
| 3832 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3833 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3834 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 3835 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 3836 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 3837 | if originalVariant.GetOverriddenBy() != "" { |
| 3838 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 3839 | } |
| 3840 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 3841 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 3842 | } |
| 3843 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3844 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 3845 | apexRule := module.Rule("apexRule") |
| 3846 | copyCmds := apexRule.Args["copy_commands"] |
| 3847 | |
| 3848 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 3849 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3850 | |
| 3851 | apexBundle := module.Module().(*apexBundle) |
| 3852 | name := apexBundle.Name() |
| 3853 | if name != "override_myapex" { |
| 3854 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 3855 | } |
| 3856 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 3857 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 3858 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 3859 | } |
| 3860 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3861 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 3862 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3863 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3864 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3865 | var builder strings.Builder |
| 3866 | data.Custom(&builder, name, "TARGET_", "", data) |
| 3867 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 3868 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3869 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 3870 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3871 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3872 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 3873 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3874 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 3875 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3876 | } |
| 3877 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3878 | func TestLegacyAndroid10Support(t *testing.T) { |
| 3879 | ctx, _ := testApex(t, ` |
| 3880 | apex { |
| 3881 | name: "myapex", |
| 3882 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3883 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 3884 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | apex_key { |
| 3888 | name: "myapex.key", |
| 3889 | public_key: "testkey.avbpubkey", |
| 3890 | private_key: "testkey.pem", |
| 3891 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3892 | |
| 3893 | cc_library { |
| 3894 | name: "mylib", |
| 3895 | srcs: ["mylib.cpp"], |
| 3896 | stl: "libc++", |
| 3897 | system_shared_libs: [], |
| 3898 | apex_available: [ "myapex" ], |
| 3899 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3900 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3901 | |
| 3902 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3903 | args := module.Rule("apexRule").Args |
| 3904 | ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String()) |
Dario Freni | e354690 | 2020-01-14 23:50:25 +0000 | [diff] [blame] | 3905 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3906 | |
| 3907 | // The copies of the libraries in the apex should have one more dependency than |
| 3908 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 3909 | // the dependency names directly here but for some reason the names are blank in |
| 3910 | // this test. |
| 3911 | for _, lib := range []string{"libc++", "mylib"} { |
| 3912 | apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits |
| 3913 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 3914 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 3915 | t.Errorf("%q missing unwinder dep", lib) |
| 3916 | } |
| 3917 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3918 | } |
| 3919 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 3920 | func TestJavaSDKLibrary(t *testing.T) { |
| 3921 | ctx, _ := testApex(t, ` |
| 3922 | apex { |
| 3923 | name: "myapex", |
| 3924 | key: "myapex.key", |
| 3925 | java_libs: ["foo"], |
| 3926 | } |
| 3927 | |
| 3928 | apex_key { |
| 3929 | name: "myapex.key", |
| 3930 | public_key: "testkey.avbpubkey", |
| 3931 | private_key: "testkey.pem", |
| 3932 | } |
| 3933 | |
| 3934 | java_sdk_library { |
| 3935 | name: "foo", |
| 3936 | srcs: ["a.java"], |
| 3937 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3938 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 3939 | } |
| 3940 | `, withFiles(map[string][]byte{ |
| 3941 | "api/current.txt": nil, |
| 3942 | "api/removed.txt": nil, |
| 3943 | "api/system-current.txt": nil, |
| 3944 | "api/system-removed.txt": nil, |
| 3945 | "api/test-current.txt": nil, |
| 3946 | "api/test-removed.txt": nil, |
| 3947 | })) |
| 3948 | |
| 3949 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3950 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 3951 | "javalib/foo.jar", |
| 3952 | "etc/permissions/foo.xml", |
| 3953 | }) |
| 3954 | // Permission XML should point to the activated path of impl jar of java_sdk_library |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3955 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 3956 | ensureContains(t, sdkLibrary.RuleParams.Command, `<library name=\"foo\" file=\"/apex/myapex/javalib/foo.jar\"`) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 3957 | } |
| 3958 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 3959 | func TestCompatConfig(t *testing.T) { |
| 3960 | ctx, _ := testApex(t, ` |
| 3961 | apex { |
| 3962 | name: "myapex", |
| 3963 | key: "myapex.key", |
| 3964 | prebuilts: ["myjar-platform-compat-config"], |
| 3965 | java_libs: ["myjar"], |
| 3966 | } |
| 3967 | |
| 3968 | apex_key { |
| 3969 | name: "myapex.key", |
| 3970 | public_key: "testkey.avbpubkey", |
| 3971 | private_key: "testkey.pem", |
| 3972 | } |
| 3973 | |
| 3974 | platform_compat_config { |
| 3975 | name: "myjar-platform-compat-config", |
| 3976 | src: ":myjar", |
| 3977 | } |
| 3978 | |
| 3979 | java_library { |
| 3980 | name: "myjar", |
| 3981 | srcs: ["foo/bar/MyClass.java"], |
| 3982 | sdk_version: "none", |
| 3983 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 3984 | apex_available: [ "myapex" ], |
| 3985 | } |
| 3986 | `) |
| 3987 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 3988 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 3989 | "javalib/myjar.jar", |
| 3990 | }) |
| 3991 | } |
| 3992 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 3993 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 3994 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 3995 | apex { |
| 3996 | name: "myapex", |
| 3997 | key: "myapex.key", |
| 3998 | java_libs: ["myjar"], |
| 3999 | } |
| 4000 | |
| 4001 | apex_key { |
| 4002 | name: "myapex.key", |
| 4003 | public_key: "testkey.avbpubkey", |
| 4004 | private_key: "testkey.pem", |
| 4005 | } |
| 4006 | |
| 4007 | java_library { |
| 4008 | name: "myjar", |
| 4009 | srcs: ["foo/bar/MyClass.java"], |
| 4010 | sdk_version: "none", |
| 4011 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 4012 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4013 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 4014 | } |
| 4015 | `) |
| 4016 | } |
| 4017 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 4018 | func TestCarryRequiredModuleNames(t *testing.T) { |
| 4019 | ctx, config := testApex(t, ` |
| 4020 | apex { |
| 4021 | name: "myapex", |
| 4022 | key: "myapex.key", |
| 4023 | native_shared_libs: ["mylib"], |
| 4024 | } |
| 4025 | |
| 4026 | apex_key { |
| 4027 | name: "myapex.key", |
| 4028 | public_key: "testkey.avbpubkey", |
| 4029 | private_key: "testkey.pem", |
| 4030 | } |
| 4031 | |
| 4032 | cc_library { |
| 4033 | name: "mylib", |
| 4034 | srcs: ["mylib.cpp"], |
| 4035 | system_shared_libs: [], |
| 4036 | stl: "none", |
| 4037 | required: ["a", "b"], |
| 4038 | host_required: ["c", "d"], |
| 4039 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4040 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 4041 | } |
| 4042 | `) |
| 4043 | |
| 4044 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 4045 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 4046 | name := apexBundle.BaseModuleName() |
| 4047 | prefix := "TARGET_" |
| 4048 | var builder strings.Builder |
| 4049 | data.Custom(&builder, name, prefix, "", data) |
| 4050 | androidMk := builder.String() |
| 4051 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 4052 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 4053 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 4054 | } |
| 4055 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4056 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 4057 | bp := ` |
| 4058 | apex { |
| 4059 | name: "myapex", |
| 4060 | key: "myapex.key", |
| 4061 | native_shared_libs: ["mylib"], |
| 4062 | java_libs: ["myjar"], |
| 4063 | } |
| 4064 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4065 | apex { |
| 4066 | name: "myapex.updatable", |
| 4067 | key: "myapex.key", |
| 4068 | native_shared_libs: ["mylib"], |
| 4069 | java_libs: ["myjar"], |
| 4070 | updatable: true, |
| 4071 | } |
| 4072 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4073 | apex_key { |
| 4074 | name: "myapex.key", |
| 4075 | public_key: "testkey.avbpubkey", |
| 4076 | private_key: "testkey.pem", |
| 4077 | } |
| 4078 | |
| 4079 | cc_library { |
| 4080 | name: "mylib", |
| 4081 | srcs: ["mylib.cpp"], |
| 4082 | shared_libs: ["myotherlib"], |
| 4083 | system_shared_libs: [], |
| 4084 | stl: "none", |
| 4085 | apex_available: [ |
| 4086 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4087 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4088 | "//apex_available:platform", |
| 4089 | ], |
| 4090 | } |
| 4091 | |
| 4092 | cc_library { |
| 4093 | name: "myotherlib", |
| 4094 | srcs: ["mylib.cpp"], |
| 4095 | system_shared_libs: [], |
| 4096 | stl: "none", |
| 4097 | apex_available: [ |
| 4098 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4099 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4100 | "//apex_available:platform", |
| 4101 | ], |
| 4102 | } |
| 4103 | |
| 4104 | java_library { |
| 4105 | name: "myjar", |
| 4106 | srcs: ["foo/bar/MyClass.java"], |
| 4107 | sdk_version: "none", |
| 4108 | system_modules: "none", |
| 4109 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4110 | apex_available: [ |
| 4111 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4112 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4113 | "//apex_available:platform", |
| 4114 | ], |
| 4115 | } |
| 4116 | |
| 4117 | java_library { |
| 4118 | name: "myotherjar", |
| 4119 | srcs: ["foo/bar/MyClass.java"], |
| 4120 | sdk_version: "none", |
| 4121 | system_modules: "none", |
| 4122 | apex_available: [ |
| 4123 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4124 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4125 | "//apex_available:platform", |
| 4126 | ], |
| 4127 | } |
| 4128 | ` |
| 4129 | |
| 4130 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 4131 | for _, f := range files { |
| 4132 | if f.path == file { |
| 4133 | if f.isLink { |
| 4134 | t.Errorf("%q is not a real file", file) |
| 4135 | } |
| 4136 | return |
| 4137 | } |
| 4138 | } |
| 4139 | t.Errorf("%q is not found", file) |
| 4140 | } |
| 4141 | |
| 4142 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 4143 | for _, f := range files { |
| 4144 | if f.path == file { |
| 4145 | if !f.isLink { |
| 4146 | t.Errorf("%q is not a symlink", file) |
| 4147 | } |
| 4148 | return |
| 4149 | } |
| 4150 | } |
| 4151 | t.Errorf("%q is not found", file) |
| 4152 | } |
| 4153 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4154 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 4155 | // is updatable or not |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4156 | ctx, _ := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 4157 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4158 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4159 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4160 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 4161 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4162 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 4163 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4164 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4165 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 4166 | |
| 4167 | // For bundled build, symlink to the system for the non-updatable APEXes only |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4168 | ctx, _ = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 4169 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4170 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4171 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4172 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4173 | |
| 4174 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 4175 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4176 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4177 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4178 | } |
| 4179 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 4180 | func TestApexWithJniLibs(t *testing.T) { |
| 4181 | ctx, _ := testApex(t, ` |
| 4182 | apex { |
| 4183 | name: "myapex", |
| 4184 | key: "myapex.key", |
| 4185 | jni_libs: ["mylib"], |
| 4186 | } |
| 4187 | |
| 4188 | apex_key { |
| 4189 | name: "myapex.key", |
| 4190 | public_key: "testkey.avbpubkey", |
| 4191 | private_key: "testkey.pem", |
| 4192 | } |
| 4193 | |
| 4194 | cc_library { |
| 4195 | name: "mylib", |
| 4196 | srcs: ["mylib.cpp"], |
| 4197 | shared_libs: ["mylib2"], |
| 4198 | system_shared_libs: [], |
| 4199 | stl: "none", |
| 4200 | apex_available: [ "myapex" ], |
| 4201 | } |
| 4202 | |
| 4203 | cc_library { |
| 4204 | name: "mylib2", |
| 4205 | srcs: ["mylib.cpp"], |
| 4206 | system_shared_libs: [], |
| 4207 | stl: "none", |
| 4208 | apex_available: [ "myapex" ], |
| 4209 | } |
| 4210 | `) |
| 4211 | |
| 4212 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 4213 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 4214 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 4215 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4216 | "lib64/mylib.so", |
| 4217 | "lib64/mylib2.so", |
| 4218 | }) |
| 4219 | } |
| 4220 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 4221 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
| 4222 | ctx, _ := testApex(t, ` |
| 4223 | apex { |
| 4224 | name: "myapex", |
| 4225 | key: "myapex.key", |
| 4226 | } |
| 4227 | apex_key { |
| 4228 | name: "myapex.key", |
| 4229 | public_key: "testkey.avbpubkey", |
| 4230 | private_key: "testkey.pem", |
| 4231 | } |
| 4232 | `, func(fs map[string][]byte, config android.Config) { |
| 4233 | delete(config.Targets, android.Android) |
| 4234 | config.AndroidCommonTarget = android.Target{} |
| 4235 | }) |
| 4236 | |
| 4237 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 4238 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 4239 | } |
| 4240 | } |
| 4241 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 4242 | func TestApexWithJniLibs_Errors(t *testing.T) { |
| 4243 | testApexError(t, `jni_libs: "xxx" is not a cc_library`, ` |
| 4244 | apex { |
| 4245 | name: "myapex", |
| 4246 | key: "myapex.key", |
| 4247 | jni_libs: ["xxx"], |
| 4248 | } |
| 4249 | |
| 4250 | apex_key { |
| 4251 | name: "myapex.key", |
| 4252 | public_key: "testkey.avbpubkey", |
| 4253 | private_key: "testkey.pem", |
| 4254 | } |
| 4255 | |
| 4256 | prebuilt_etc { |
| 4257 | name: "xxx", |
| 4258 | src: "xxx", |
| 4259 | } |
| 4260 | `, withFiles(map[string][]byte{ |
| 4261 | "xxx": nil, |
| 4262 | })) |
| 4263 | } |
| 4264 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 4265 | func TestAppBundle(t *testing.T) { |
| 4266 | ctx, _ := testApex(t, ` |
| 4267 | apex { |
| 4268 | name: "myapex", |
| 4269 | key: "myapex.key", |
| 4270 | apps: ["AppFoo"], |
| 4271 | } |
| 4272 | |
| 4273 | apex_key { |
| 4274 | name: "myapex.key", |
| 4275 | public_key: "testkey.avbpubkey", |
| 4276 | private_key: "testkey.pem", |
| 4277 | } |
| 4278 | |
| 4279 | android_app { |
| 4280 | name: "AppFoo", |
| 4281 | srcs: ["foo/bar/MyClass.java"], |
| 4282 | sdk_version: "none", |
| 4283 | system_modules: "none", |
| 4284 | apex_available: [ "myapex" ], |
| 4285 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 4286 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 4287 | |
| 4288 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config") |
| 4289 | content := bundleConfigRule.Args["content"] |
| 4290 | |
| 4291 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 4292 | ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 4293 | } |
| 4294 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4295 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg, bp string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
| 4296 | t.Helper() |
| 4297 | |
| 4298 | bp = bp + ` |
| 4299 | filegroup { |
| 4300 | name: "some-updatable-apex-file_contexts", |
| 4301 | srcs: [ |
| 4302 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 4303 | ], |
| 4304 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 4305 | |
| 4306 | filegroup { |
| 4307 | name: "some-non-updatable-apex-file_contexts", |
| 4308 | srcs: [ |
| 4309 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 4310 | ], |
| 4311 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4312 | ` |
| 4313 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 4314 | bp += java.GatherRequiredDepsForTest() |
| 4315 | bp += dexpreopt.BpToolModulesForTest() |
| 4316 | |
| 4317 | fs := map[string][]byte{ |
| 4318 | "a.java": nil, |
| 4319 | "a.jar": nil, |
| 4320 | "build/make/target/product/security": nil, |
| 4321 | "apex_manifest.json": nil, |
| 4322 | "AndroidManifest.xml": nil, |
| 4323 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 4324 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4325 | "system/sepolicy/apex/com.android.art.something-file_contexts": nil, |
| 4326 | "framework/aidl/a.aidl": nil, |
| 4327 | } |
| 4328 | cc.GatherRequiredFilesForTest(fs) |
| 4329 | |
| 4330 | ctx := android.NewTestArchContext() |
| 4331 | ctx.RegisterModuleType("apex", BundleFactory) |
| 4332 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 4333 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 4334 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
| 4335 | java.RegisterJavaBuildComponents(ctx) |
| 4336 | java.RegisterSystemModulesBuildComponents(ctx) |
| 4337 | java.RegisterAppBuildComponents(ctx) |
| 4338 | java.RegisterDexpreoptBootJarsComponents(ctx) |
| 4339 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 4340 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 4341 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 4342 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 4343 | |
| 4344 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 4345 | ctx.Register(config) |
| 4346 | |
| 4347 | _ = dexpreopt.GlobalSoongConfigForTests(config) |
| 4348 | dexpreopt.RegisterToolModulesForTest(ctx) |
| 4349 | pathCtx := android.PathContextForTesting(config) |
| 4350 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 4351 | transformDexpreoptConfig(dexpreoptConfig) |
| 4352 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 4353 | |
| 4354 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 4355 | android.FailIfErrored(t, errs) |
| 4356 | |
| 4357 | _, errs = ctx.PrepareBuildActions(config) |
| 4358 | if errmsg == "" { |
| 4359 | android.FailIfErrored(t, errs) |
| 4360 | } else if len(errs) > 0 { |
| 4361 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 4362 | return |
| 4363 | } else { |
| 4364 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 4365 | } |
| 4366 | } |
| 4367 | |
| 4368 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
| 4369 | bp := ` |
| 4370 | java_library { |
| 4371 | name: "some-updatable-apex-lib", |
| 4372 | srcs: ["a.java"], |
| 4373 | apex_available: [ |
| 4374 | "some-updatable-apex", |
| 4375 | ], |
| 4376 | } |
| 4377 | |
| 4378 | java_library { |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 4379 | name: "some-non-updatable-apex-lib", |
| 4380 | srcs: ["a.java"], |
| 4381 | apex_available: [ |
| 4382 | "some-non-updatable-apex", |
| 4383 | ], |
| 4384 | } |
| 4385 | |
| 4386 | java_library { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4387 | name: "some-platform-lib", |
| 4388 | srcs: ["a.java"], |
| 4389 | installable: true, |
| 4390 | } |
| 4391 | |
| 4392 | java_library { |
| 4393 | name: "some-art-lib", |
| 4394 | srcs: ["a.java"], |
| 4395 | apex_available: [ |
| 4396 | "com.android.art.something", |
| 4397 | ], |
| 4398 | hostdex: true, |
| 4399 | } |
| 4400 | |
| 4401 | apex { |
| 4402 | name: "some-updatable-apex", |
| 4403 | key: "some-updatable-apex.key", |
| 4404 | java_libs: ["some-updatable-apex-lib"], |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 4405 | updatable: true, |
| 4406 | } |
| 4407 | |
| 4408 | apex { |
| 4409 | name: "some-non-updatable-apex", |
| 4410 | key: "some-non-updatable-apex.key", |
| 4411 | java_libs: ["some-non-updatable-apex-lib"], |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | apex_key { |
| 4415 | name: "some-updatable-apex.key", |
| 4416 | } |
| 4417 | |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 4418 | apex_key { |
| 4419 | name: "some-non-updatable-apex.key", |
| 4420 | } |
| 4421 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4422 | apex { |
| 4423 | name: "com.android.art.something", |
| 4424 | key: "com.android.art.something.key", |
| 4425 | java_libs: ["some-art-lib"], |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 4426 | updatable: true, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | apex_key { |
| 4430 | name: "com.android.art.something.key", |
| 4431 | } |
| 4432 | ` |
| 4433 | |
| 4434 | var error string |
| 4435 | var transform func(*dexpreopt.GlobalConfig) |
| 4436 | |
| 4437 | // updatable jar from ART apex in the ART boot image => ok |
| 4438 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4439 | config.ArtApexJars = []string{"some-art-lib"} |
| 4440 | } |
| 4441 | testNoUpdatableJarsInBootImage(t, "", bp, transform) |
| 4442 | |
| 4443 | // updatable jar from ART apex in the framework boot image => error |
| 4444 | error = "module 'some-art-lib' from updatable apex 'com.android.art.something' is not allowed in the framework boot image" |
| 4445 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4446 | config.BootJars = []string{"some-art-lib"} |
| 4447 | } |
| 4448 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4449 | |
| 4450 | // updatable jar from some other apex in the ART boot image => error |
| 4451 | error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the ART boot image" |
| 4452 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4453 | config.ArtApexJars = []string{"some-updatable-apex-lib"} |
| 4454 | } |
| 4455 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4456 | |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 4457 | // non-updatable jar from some other apex in the ART boot image => error |
| 4458 | error = "module 'some-non-updatable-apex-lib' is not allowed in the ART boot image" |
| 4459 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4460 | config.ArtApexJars = []string{"some-non-updatable-apex-lib"} |
| 4461 | } |
| 4462 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4463 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4464 | // updatable jar from some other apex in the framework boot image => error |
| 4465 | error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the framework boot image" |
| 4466 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4467 | config.BootJars = []string{"some-updatable-apex-lib"} |
| 4468 | } |
| 4469 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4470 | |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 4471 | // non-updatable jar from some other apex in the framework boot image => ok |
| 4472 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4473 | config.BootJars = []string{"some-non-updatable-apex-lib"} |
| 4474 | } |
| 4475 | testNoUpdatableJarsInBootImage(t, "", bp, transform) |
| 4476 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4477 | // nonexistent jar in the ART boot image => error |
| 4478 | error = "failed to find a dex jar path for module 'nonexistent'" |
| 4479 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4480 | config.ArtApexJars = []string{"nonexistent"} |
| 4481 | } |
| 4482 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4483 | |
| 4484 | // nonexistent jar in the framework boot image => error |
| 4485 | error = "failed to find a dex jar path for module 'nonexistent'" |
| 4486 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4487 | config.BootJars = []string{"nonexistent"} |
| 4488 | } |
| 4489 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4490 | |
| 4491 | // platform jar in the ART boot image => error |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 4492 | error = "module 'some-platform-lib' is not allowed in the ART boot image" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4493 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4494 | config.ArtApexJars = []string{"some-platform-lib"} |
| 4495 | } |
| 4496 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4497 | |
| 4498 | // platform jar in the framework boot image => ok |
| 4499 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4500 | config.BootJars = []string{"some-platform-lib"} |
| 4501 | } |
| 4502 | testNoUpdatableJarsInBootImage(t, "", bp, transform) |
| 4503 | } |
| 4504 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4505 | func TestMain(m *testing.M) { |
| 4506 | run := func() int { |
| 4507 | setUp() |
| 4508 | defer tearDown() |
| 4509 | |
| 4510 | return m.Run() |
| 4511 | } |
| 4512 | |
| 4513 | os.Exit(run()) |
| 4514 | } |