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 | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 18 | "fmt" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 19 | "io/ioutil" |
| 20 | "os" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 21 | "path" |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 22 | "reflect" |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 23 | "regexp" |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 24 | "sort" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 25 | "strings" |
| 26 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 27 | |
| 28 | "github.com/google/blueprint/proptools" |
| 29 | |
| 30 | "android/soong/android" |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 31 | "android/soong/bpf" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 32 | "android/soong/cc" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 33 | "android/soong/dexpreopt" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 34 | prebuilt_etc "android/soong/etc" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 35 | "android/soong/java" |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 36 | "android/soong/rust" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 37 | "android/soong/sh" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 38 | ) |
| 39 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 40 | var buildDir string |
| 41 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 42 | // names returns name list from white space separated string |
| 43 | func names(s string) (ns []string) { |
| 44 | for _, n := range strings.Split(s, " ") { |
| 45 | if len(n) > 0 { |
| 46 | ns = append(ns, n) |
| 47 | } |
| 48 | } |
| 49 | return |
| 50 | } |
| 51 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 52 | func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) { |
| 53 | t.Helper() |
| 54 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 55 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 56 | if len(errs) > 0 { |
| 57 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 58 | return |
| 59 | } |
| 60 | _, errs = ctx.PrepareBuildActions(config) |
| 61 | if len(errs) > 0 { |
| 62 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 67 | } |
| 68 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 69 | func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
| 70 | t.Helper() |
| 71 | ctx, config := testApexContext(t, bp, handlers...) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 72 | _, errs := ctx.ParseBlueprintsFiles(".") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 73 | android.FailIfErrored(t, errs) |
| 74 | _, errs = ctx.PrepareBuildActions(config) |
| 75 | android.FailIfErrored(t, errs) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 76 | return ctx, config |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 77 | } |
| 78 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 79 | type testCustomizer func(fs map[string][]byte, config android.Config) |
| 80 | |
| 81 | func withFiles(files map[string][]byte) testCustomizer { |
| 82 | return func(fs map[string][]byte, config android.Config) { |
| 83 | for k, v := range files { |
| 84 | fs[k] = v |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | func withTargets(targets map[android.OsType][]android.Target) testCustomizer { |
| 90 | return func(fs map[string][]byte, config android.Config) { |
| 91 | for k, v := range targets { |
| 92 | config.Targets[k] = v |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 97 | // withNativeBridgeTargets sets configuration with targets including: |
| 98 | // - X86_64 (primary) |
| 99 | // - X86 (secondary) |
| 100 | // - Arm64 on X86_64 (native bridge) |
| 101 | // - Arm on X86 (native bridge) |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 102 | func withNativeBridgeEnabled(_ map[string][]byte, config android.Config) { |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 103 | config.Targets[android.Android] = []android.Target{ |
| 104 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, |
| 105 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 106 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, |
| 107 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 108 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, |
| 109 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"}, |
| 110 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 111 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"}, |
| 112 | } |
| 113 | } |
| 114 | |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 115 | func withManifestPackageNameOverrides(specs []string) testCustomizer { |
| 116 | return func(fs map[string][]byte, config android.Config) { |
| 117 | config.TestProductVariables.ManifestPackageNameOverrides = specs |
| 118 | } |
| 119 | } |
| 120 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 121 | func withBinder32bit(_ map[string][]byte, config android.Config) { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 122 | config.TestProductVariables.Binder32bit = proptools.BoolPtr(true) |
| 123 | } |
| 124 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 125 | func withUnbundledBuild(_ map[string][]byte, config android.Config) { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 126 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 127 | } |
| 128 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 129 | func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 130 | bp = bp + ` |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 131 | filegroup { |
| 132 | name: "myapex-file_contexts", |
| 133 | srcs: [ |
| 134 | "system/sepolicy/apex/myapex-file_contexts", |
| 135 | ], |
| 136 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 137 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 138 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 139 | bp = bp + cc.GatherRequiredDepsForTest(android.Android) |
| 140 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 141 | bp = bp + rust.GatherRequiredDepsForTest() |
| 142 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 143 | bp = bp + java.GatherRequiredDepsForTest() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 144 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 145 | fs := map[string][]byte{ |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 146 | "a.java": nil, |
| 147 | "PrebuiltAppFoo.apk": nil, |
| 148 | "PrebuiltAppFooPriv.apk": nil, |
| 149 | "build/make/target/product/security": nil, |
| 150 | "apex_manifest.json": nil, |
| 151 | "AndroidManifest.xml": nil, |
| 152 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 153 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 154 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 155 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 156 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 157 | "mylib.cpp": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 158 | "mytest.cpp": nil, |
| 159 | "mytest1.cpp": nil, |
| 160 | "mytest2.cpp": nil, |
| 161 | "mytest3.cpp": nil, |
| 162 | "myprebuilt": nil, |
| 163 | "my_include": nil, |
| 164 | "foo/bar/MyClass.java": nil, |
| 165 | "prebuilt.jar": nil, |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 166 | "prebuilt.so": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 167 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 168 | "vendor/foo/devkeys/test.pk8": nil, |
| 169 | "testkey.x509.pem": nil, |
| 170 | "testkey.pk8": nil, |
| 171 | "testkey.override.x509.pem": nil, |
| 172 | "testkey.override.pk8": nil, |
| 173 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 174 | "vendor/foo/devkeys/testkey.pem": nil, |
| 175 | "NOTICE": nil, |
| 176 | "custom_notice": nil, |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 177 | "custom_notice_for_static_lib": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 178 | "testkey2.avbpubkey": nil, |
| 179 | "testkey2.pem": nil, |
| 180 | "myapex-arm64.apex": nil, |
| 181 | "myapex-arm.apex": nil, |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 182 | "myapex.apks": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 183 | "frameworks/base/api/current.txt": nil, |
| 184 | "framework/aidl/a.aidl": nil, |
| 185 | "build/make/core/proguard.flags": nil, |
| 186 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 187 | "dummy.txt": nil, |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 188 | "baz": nil, |
| 189 | "bar/baz": nil, |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 190 | "testdata/baz": nil, |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 191 | "AppSet.apks": nil, |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 192 | "foo.rs": nil, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 193 | "libfoo.jar": nil, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 194 | } |
| 195 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 196 | cc.GatherRequiredFilesForTest(fs) |
| 197 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 198 | for _, handler := range handlers { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 199 | // The fs now needs to be populated before creating the config, call handlers twice |
| 200 | // for now, once to get any fs changes, and later after the config was created to |
| 201 | // set product variables or targets. |
| 202 | tempConfig := android.TestArchConfig(buildDir, nil, bp, fs) |
| 203 | handler(fs, tempConfig) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 204 | } |
| 205 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 206 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 207 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 208 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 209 | config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 210 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 211 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 212 | config.TestProductVariables.Platform_version_active_codenames = []string{"Q"} |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 213 | config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") |
| 214 | |
| 215 | for _, handler := range handlers { |
| 216 | // The fs now needs to be populated before creating the config, call handlers twice |
| 217 | // for now, earlier to get any fs changes, and now after the config was created to |
| 218 | // set product variables or targets. |
| 219 | tempFS := map[string][]byte{} |
| 220 | handler(tempFS, config) |
| 221 | } |
| 222 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 223 | ctx := android.NewTestArchContext(config) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 224 | |
| 225 | // from android package |
| 226 | android.RegisterPackageBuildComponents(ctx) |
| 227 | ctx.PreArchMutators(android.RegisterVisibilityRuleChecker) |
| 228 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 229 | ctx.RegisterModuleType("apex", BundleFactory) |
| 230 | ctx.RegisterModuleType("apex_test", testApexBundleFactory) |
| 231 | ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
| 232 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 233 | ctx.RegisterModuleType("apex_defaults", defaultsFactory) |
| 234 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
| 235 | ctx.RegisterModuleType("override_apex", overrideApexFactory) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 236 | ctx.RegisterModuleType("apex_set", apexSetFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 237 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 238 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 239 | ctx.PreArchMutators(android.RegisterComponentsMutator) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 240 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 241 | |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 242 | android.RegisterPrebuiltMutators(ctx) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 243 | |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 244 | // Register these after the prebuilt mutators have been registered to match what |
| 245 | // happens at runtime. |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 246 | ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer) |
| 247 | ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer) |
| 248 | |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 249 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 250 | rust.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 251 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 252 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 253 | ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 254 | cc.RegisterVndkLibraryTxtTypes(ctx) |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 255 | prebuilt_etc.RegisterPrebuiltEtcBuildComponents(ctx) |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 256 | ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 257 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 258 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 259 | java.RegisterJavaBuildComponents(ctx) |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 260 | java.RegisterSystemModulesBuildComponents(ctx) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 261 | java.RegisterAppBuildComponents(ctx) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 262 | java.RegisterAppImportBuildComponents(ctx) |
| 263 | java.RegisterAppSetBuildComponents(ctx) |
| 264 | java.RegisterRuntimeResourceOverlayBuildComponents(ctx) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 265 | java.RegisterSdkLibraryBuildComponents(ctx) |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 266 | java.RegisterPrebuiltApisBuildComponents(ctx) |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 267 | ctx.RegisterSingletonType("apex_keys_text", apexKeysTextFactory) |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 268 | ctx.RegisterModuleType("bpf", bpf.BpfFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 269 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 270 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 271 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 272 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 273 | ctx.Register() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 274 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 275 | return ctx, config |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 276 | } |
| 277 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 278 | func setUp() { |
| 279 | var err error |
| 280 | buildDir, err = ioutil.TempDir("", "soong_apex_test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 281 | if err != nil { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 282 | panic(err) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 283 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 284 | } |
| 285 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 286 | func tearDown() { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 287 | _ = os.RemoveAll(buildDir) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 288 | } |
| 289 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 290 | // ensure that 'result' equals 'expected' |
| 291 | func ensureEquals(t *testing.T, result string, expected string) { |
| 292 | t.Helper() |
| 293 | if result != expected { |
| 294 | t.Errorf("%q != %q", expected, result) |
| 295 | } |
| 296 | } |
| 297 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 298 | // ensure that 'result' contains 'expected' |
| 299 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 300 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 301 | if !strings.Contains(result, expected) { |
| 302 | t.Errorf("%q is not found in %q", expected, result) |
| 303 | } |
| 304 | } |
| 305 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 306 | // ensure that 'result' contains 'expected' exactly one time |
| 307 | func ensureContainsOnce(t *testing.T, result string, expected string) { |
| 308 | t.Helper() |
| 309 | count := strings.Count(result, expected) |
| 310 | if count != 1 { |
| 311 | t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result) |
| 312 | } |
| 313 | } |
| 314 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 315 | // ensures that 'result' does not contain 'notExpected' |
| 316 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 317 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 318 | if strings.Contains(result, notExpected) { |
| 319 | t.Errorf("%q is found in %q", notExpected, result) |
| 320 | } |
| 321 | } |
| 322 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 323 | func ensureMatches(t *testing.T, result string, expectedRex string) { |
| 324 | ok, err := regexp.MatchString(expectedRex, result) |
| 325 | if err != nil { |
| 326 | t.Fatalf("regexp failure trying to match %s against `%s` expression: %s", result, expectedRex, err) |
| 327 | return |
| 328 | } |
| 329 | if !ok { |
| 330 | t.Errorf("%s does not match regular expession %s", result, expectedRex) |
| 331 | } |
| 332 | } |
| 333 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 334 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 335 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 336 | if !android.InList(expected, result) { |
| 337 | t.Errorf("%q is not found in %v", expected, result) |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 342 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 343 | if android.InList(notExpected, result) { |
| 344 | t.Errorf("%q is found in %v", notExpected, result) |
| 345 | } |
| 346 | } |
| 347 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 348 | func ensureListEmpty(t *testing.T, result []string) { |
| 349 | t.Helper() |
| 350 | if len(result) > 0 { |
| 351 | t.Errorf("%q is expected to be empty", result) |
| 352 | } |
| 353 | } |
| 354 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 355 | func ensureListNotEmpty(t *testing.T, result []string) { |
| 356 | t.Helper() |
| 357 | if len(result) == 0 { |
| 358 | t.Errorf("%q is expected to be not empty", result) |
| 359 | } |
| 360 | } |
| 361 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 362 | // Minimal test |
| 363 | func TestBasicApex(t *testing.T) { |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 364 | ctx, config := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 365 | apex_defaults { |
| 366 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 367 | manifest: ":myapex.manifest", |
| 368 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 369 | key: "myapex.key", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 370 | binaries: ["foo.rust"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 371 | native_shared_libs: [ |
| 372 | "mylib", |
| 373 | "libfoo.ffi", |
| 374 | ], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 375 | rust_dyn_libs: ["libfoo.dylib.rust"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 376 | multilib: { |
| 377 | both: { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 378 | binaries: ["foo"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 379 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 380 | }, |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 381 | java_libs: [ |
| 382 | "myjar", |
| 383 | "myjar_dex", |
| 384 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 385 | } |
| 386 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 387 | apex { |
| 388 | name: "myapex", |
| 389 | defaults: ["myapex-defaults"], |
| 390 | } |
| 391 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 392 | apex_key { |
| 393 | name: "myapex.key", |
| 394 | public_key: "testkey.avbpubkey", |
| 395 | private_key: "testkey.pem", |
| 396 | } |
| 397 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 398 | filegroup { |
| 399 | name: "myapex.manifest", |
| 400 | srcs: ["apex_manifest.json"], |
| 401 | } |
| 402 | |
| 403 | filegroup { |
| 404 | name: "myapex.androidmanifest", |
| 405 | srcs: ["AndroidManifest.xml"], |
| 406 | } |
| 407 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 408 | cc_library { |
| 409 | name: "mylib", |
| 410 | srcs: ["mylib.cpp"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 411 | shared_libs: [ |
| 412 | "mylib2", |
| 413 | "libbar.ffi", |
| 414 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 415 | system_shared_libs: [], |
| 416 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 417 | // TODO: remove //apex_available:platform |
| 418 | apex_available: [ |
| 419 | "//apex_available:platform", |
| 420 | "myapex", |
| 421 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 422 | } |
| 423 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 424 | cc_binary { |
| 425 | name: "foo", |
| 426 | srcs: ["mylib.cpp"], |
| 427 | compile_multilib: "both", |
| 428 | multilib: { |
| 429 | lib32: { |
| 430 | suffix: "32", |
| 431 | }, |
| 432 | lib64: { |
| 433 | suffix: "64", |
| 434 | }, |
| 435 | }, |
| 436 | symlinks: ["foo_link_"], |
| 437 | symlink_preferred_arch: true, |
| 438 | system_shared_libs: [], |
| 439 | static_executable: true, |
| 440 | stl: "none", |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 441 | apex_available: [ "myapex", "com.android.gki.*" ], |
| 442 | } |
| 443 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 444 | rust_binary { |
| 445 | name: "foo.rust", |
| 446 | srcs: ["foo.rs"], |
| 447 | rlibs: ["libfoo.rlib.rust"], |
| 448 | dylibs: ["libfoo.dylib.rust"], |
| 449 | apex_available: ["myapex"], |
| 450 | } |
| 451 | |
| 452 | rust_library_rlib { |
| 453 | name: "libfoo.rlib.rust", |
| 454 | srcs: ["foo.rs"], |
| 455 | crate_name: "foo", |
| 456 | apex_available: ["myapex"], |
| 457 | } |
| 458 | |
| 459 | rust_library_dylib { |
| 460 | name: "libfoo.dylib.rust", |
| 461 | srcs: ["foo.rs"], |
| 462 | crate_name: "foo", |
| 463 | apex_available: ["myapex"], |
| 464 | } |
| 465 | |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 466 | rust_ffi_shared { |
| 467 | name: "libfoo.ffi", |
| 468 | srcs: ["foo.rs"], |
| 469 | crate_name: "foo", |
| 470 | apex_available: ["myapex"], |
| 471 | } |
| 472 | |
| 473 | rust_ffi_shared { |
| 474 | name: "libbar.ffi", |
| 475 | srcs: ["foo.rs"], |
| 476 | crate_name: "bar", |
| 477 | apex_available: ["myapex"], |
| 478 | } |
| 479 | |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 480 | apex { |
| 481 | name: "com.android.gki.fake", |
| 482 | binaries: ["foo"], |
| 483 | key: "myapex.key", |
| 484 | file_contexts: ":myapex-file_contexts", |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 487 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 488 | name: "mylib2", |
| 489 | srcs: ["mylib.cpp"], |
| 490 | system_shared_libs: [], |
| 491 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 492 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 493 | static_libs: ["libstatic"], |
| 494 | // TODO: remove //apex_available:platform |
| 495 | apex_available: [ |
| 496 | "//apex_available:platform", |
| 497 | "myapex", |
| 498 | ], |
| 499 | } |
| 500 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 501 | cc_prebuilt_library_shared { |
| 502 | name: "mylib2", |
| 503 | srcs: ["prebuilt.so"], |
| 504 | // TODO: remove //apex_available:platform |
| 505 | apex_available: [ |
| 506 | "//apex_available:platform", |
| 507 | "myapex", |
| 508 | ], |
| 509 | } |
| 510 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 511 | cc_library_static { |
| 512 | name: "libstatic", |
| 513 | srcs: ["mylib.cpp"], |
| 514 | system_shared_libs: [], |
| 515 | stl: "none", |
| 516 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 517 | // TODO: remove //apex_available:platform |
| 518 | apex_available: [ |
| 519 | "//apex_available:platform", |
| 520 | "myapex", |
| 521 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 522 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 523 | |
| 524 | java_library { |
| 525 | name: "myjar", |
| 526 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 527 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 528 | sdk_version: "none", |
| 529 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 530 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 531 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 532 | // TODO: remove //apex_available:platform |
| 533 | apex_available: [ |
| 534 | "//apex_available:platform", |
| 535 | "myapex", |
| 536 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 537 | } |
| 538 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 539 | dex_import { |
| 540 | name: "myjar_dex", |
| 541 | jars: ["prebuilt.jar"], |
| 542 | apex_available: [ |
| 543 | "//apex_available:platform", |
| 544 | "myapex", |
| 545 | ], |
| 546 | } |
| 547 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 548 | java_library { |
| 549 | name: "myotherjar", |
| 550 | srcs: ["foo/bar/MyClass.java"], |
| 551 | sdk_version: "none", |
| 552 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 553 | // TODO: remove //apex_available:platform |
| 554 | apex_available: [ |
| 555 | "//apex_available:platform", |
| 556 | "myapex", |
| 557 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 558 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 559 | |
| 560 | java_library { |
| 561 | name: "mysharedjar", |
| 562 | srcs: ["foo/bar/MyClass.java"], |
| 563 | sdk_version: "none", |
| 564 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 565 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 566 | `) |
| 567 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 568 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 569 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 570 | // Make sure that Android.mk is created |
| 571 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 572 | data := android.AndroidMkDataForTest(t, config, "", ab) |
| 573 | var builder strings.Builder |
| 574 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 575 | |
| 576 | androidMk := builder.String() |
| 577 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 578 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 579 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 580 | optFlags := apexRule.Args["opt_flags"] |
| 581 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 582 | // Ensure that the NOTICE output is being packaged as an asset. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 583 | 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] | 584 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 585 | copyCmds := apexRule.Args["copy_commands"] |
| 586 | |
| 587 | // Ensure that main rule creates an output |
| 588 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 589 | |
| 590 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 591 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 592 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") |
| 593 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 594 | ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 595 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 596 | |
| 597 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 598 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
| 599 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 600 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000") |
| 601 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.dylib.rust"), "android_arm64_armv8-a_dylib_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 602 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 603 | |
| 604 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 605 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 606 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 607 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 608 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 609 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 610 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so") |
| 611 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 612 | // .. but not for java libs |
| 613 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 614 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 615 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 616 | // Ensure that the platform variant ends with _shared or _common |
| 617 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 618 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 619 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 620 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 621 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 622 | |
| 623 | // Ensure that dynamic dependency to java libs are not included |
| 624 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 625 | |
| 626 | // Ensure that all symlinks are present. |
| 627 | found_foo_link_64 := false |
| 628 | found_foo := false |
| 629 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 630 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 631 | if strings.HasSuffix(cmd, "bin/foo") { |
| 632 | found_foo = true |
| 633 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 634 | found_foo_link_64 = true |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | good := found_foo && found_foo_link_64 |
| 639 | if !good { |
| 640 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 641 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 642 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 643 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 644 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 645 | if len(noticeInputs) != 3 { |
| 646 | 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] | 647 | } |
| 648 | ensureListContains(t, noticeInputs, "NOTICE") |
| 649 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 650 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 651 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 652 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 653 | ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex") |
| 654 | ensureListContains(t, fullDepsInfo, " mylib(minSdkVersion:(no version)) <- myapex") |
| 655 | ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib") |
| 656 | ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar") |
| 657 | ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 658 | |
| 659 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 660 | ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))") |
| 661 | ensureListContains(t, flatDepsInfo, "mylib(minSdkVersion:(no version))") |
| 662 | ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))") |
| 663 | ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))") |
| 664 | ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 665 | } |
| 666 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 667 | func TestDefaults(t *testing.T) { |
| 668 | ctx, _ := testApex(t, ` |
| 669 | apex_defaults { |
| 670 | name: "myapex-defaults", |
| 671 | key: "myapex.key", |
| 672 | prebuilts: ["myetc"], |
| 673 | native_shared_libs: ["mylib"], |
| 674 | java_libs: ["myjar"], |
| 675 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 676 | rros: ["rro"], |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 677 | bpfs: ["bpf"], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | prebuilt_etc { |
| 681 | name: "myetc", |
| 682 | src: "myprebuilt", |
| 683 | } |
| 684 | |
| 685 | apex { |
| 686 | name: "myapex", |
| 687 | defaults: ["myapex-defaults"], |
| 688 | } |
| 689 | |
| 690 | apex_key { |
| 691 | name: "myapex.key", |
| 692 | public_key: "testkey.avbpubkey", |
| 693 | private_key: "testkey.pem", |
| 694 | } |
| 695 | |
| 696 | cc_library { |
| 697 | name: "mylib", |
| 698 | system_shared_libs: [], |
| 699 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 700 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | java_library { |
| 704 | name: "myjar", |
| 705 | srcs: ["foo/bar/MyClass.java"], |
| 706 | sdk_version: "none", |
| 707 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 708 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | android_app { |
| 712 | name: "AppFoo", |
| 713 | srcs: ["foo/bar/MyClass.java"], |
| 714 | sdk_version: "none", |
| 715 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 716 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 717 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 718 | |
| 719 | runtime_resource_overlay { |
| 720 | name: "rro", |
| 721 | theme: "blue", |
| 722 | } |
| 723 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 724 | bpf { |
| 725 | name: "bpf", |
| 726 | srcs: ["bpf.c", "bpf2.c"], |
| 727 | } |
| 728 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +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 | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 731 | "etc/myetc", |
| 732 | "javalib/myjar.jar", |
| 733 | "lib64/mylib.so", |
| 734 | "app/AppFoo/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 735 | "overlay/blue/rro.apk", |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 736 | "etc/bpf/bpf.o", |
| 737 | "etc/bpf/bpf2.o", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 738 | }) |
| 739 | } |
| 740 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 741 | func TestApexManifest(t *testing.T) { |
| 742 | ctx, _ := testApex(t, ` |
| 743 | apex { |
| 744 | name: "myapex", |
| 745 | key: "myapex.key", |
| 746 | } |
| 747 | |
| 748 | apex_key { |
| 749 | name: "myapex.key", |
| 750 | public_key: "testkey.avbpubkey", |
| 751 | private_key: "testkey.pem", |
| 752 | } |
| 753 | `) |
| 754 | |
| 755 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 756 | args := module.Rule("apexRule").Args |
| 757 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 758 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 759 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 760 | } |
| 761 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 762 | func TestBasicZipApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 763 | ctx, _ := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 764 | apex { |
| 765 | name: "myapex", |
| 766 | key: "myapex.key", |
| 767 | payload_type: "zip", |
| 768 | native_shared_libs: ["mylib"], |
| 769 | } |
| 770 | |
| 771 | apex_key { |
| 772 | name: "myapex.key", |
| 773 | public_key: "testkey.avbpubkey", |
| 774 | private_key: "testkey.pem", |
| 775 | } |
| 776 | |
| 777 | cc_library { |
| 778 | name: "mylib", |
| 779 | srcs: ["mylib.cpp"], |
| 780 | shared_libs: ["mylib2"], |
| 781 | system_shared_libs: [], |
| 782 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 783 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | cc_library { |
| 787 | name: "mylib2", |
| 788 | srcs: ["mylib.cpp"], |
| 789 | system_shared_libs: [], |
| 790 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 791 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 792 | } |
| 793 | `) |
| 794 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 795 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 796 | copyCmds := zipApexRule.Args["copy_commands"] |
| 797 | |
| 798 | // Ensure that main rule creates an output |
| 799 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 800 | |
| 801 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 802 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 803 | |
| 804 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 805 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 806 | |
| 807 | // Ensure that both direct and indirect deps are copied into apex |
| 808 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 809 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | func TestApexWithStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 813 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 814 | apex { |
| 815 | name: "myapex", |
| 816 | key: "myapex.key", |
| 817 | native_shared_libs: ["mylib", "mylib3"], |
| 818 | } |
| 819 | |
| 820 | apex_key { |
| 821 | name: "myapex.key", |
| 822 | public_key: "testkey.avbpubkey", |
| 823 | private_key: "testkey.pem", |
| 824 | } |
| 825 | |
| 826 | cc_library { |
| 827 | name: "mylib", |
| 828 | srcs: ["mylib.cpp"], |
| 829 | shared_libs: ["mylib2", "mylib3"], |
| 830 | system_shared_libs: [], |
| 831 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 832 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | cc_library { |
| 836 | name: "mylib2", |
| 837 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 838 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 839 | system_shared_libs: [], |
| 840 | stl: "none", |
| 841 | stubs: { |
| 842 | versions: ["1", "2", "3"], |
| 843 | }, |
| 844 | } |
| 845 | |
| 846 | cc_library { |
| 847 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 848 | srcs: ["mylib.cpp"], |
| 849 | shared_libs: ["mylib4"], |
| 850 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 851 | stl: "none", |
| 852 | stubs: { |
| 853 | versions: ["10", "11", "12"], |
| 854 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 855 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 856 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 857 | |
| 858 | cc_library { |
| 859 | name: "mylib4", |
| 860 | srcs: ["mylib.cpp"], |
| 861 | system_shared_libs: [], |
| 862 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 863 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 864 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 865 | `) |
| 866 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 867 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 868 | copyCmds := apexRule.Args["copy_commands"] |
| 869 | |
| 870 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 871 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 872 | |
| 873 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 874 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 875 | |
| 876 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 877 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 878 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 879 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 880 | |
| 881 | // 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] | 882 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 883 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 884 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 885 | |
| 886 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 887 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 888 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 889 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 890 | |
| 891 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 892 | 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] | 893 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 894 | |
| 895 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 896 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_3").Rule("genStubSrc").Args["flags"]) |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 897 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 898 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 899 | "lib64/mylib.so", |
| 900 | "lib64/mylib3.so", |
| 901 | "lib64/mylib4.so", |
| 902 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 903 | } |
| 904 | |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 905 | func TestApexWithStubsWithMinSdkVersion(t *testing.T) { |
| 906 | t.Parallel() |
| 907 | ctx, _ := testApex(t, ` |
| 908 | apex { |
| 909 | name: "myapex", |
| 910 | key: "myapex.key", |
| 911 | native_shared_libs: ["mylib", "mylib3"], |
| 912 | min_sdk_version: "29", |
| 913 | } |
| 914 | |
| 915 | apex_key { |
| 916 | name: "myapex.key", |
| 917 | public_key: "testkey.avbpubkey", |
| 918 | private_key: "testkey.pem", |
| 919 | } |
| 920 | |
| 921 | cc_library { |
| 922 | name: "mylib", |
| 923 | srcs: ["mylib.cpp"], |
| 924 | shared_libs: ["mylib2", "mylib3"], |
| 925 | system_shared_libs: [], |
| 926 | stl: "none", |
| 927 | apex_available: [ "myapex" ], |
| 928 | min_sdk_version: "28", |
| 929 | } |
| 930 | |
| 931 | cc_library { |
| 932 | name: "mylib2", |
| 933 | srcs: ["mylib.cpp"], |
| 934 | cflags: ["-include mylib.h"], |
| 935 | system_shared_libs: [], |
| 936 | stl: "none", |
| 937 | stubs: { |
| 938 | versions: ["28", "29", "30", "current"], |
| 939 | }, |
| 940 | min_sdk_version: "28", |
| 941 | } |
| 942 | |
| 943 | cc_library { |
| 944 | name: "mylib3", |
| 945 | srcs: ["mylib.cpp"], |
| 946 | shared_libs: ["mylib4"], |
| 947 | system_shared_libs: [], |
| 948 | stl: "none", |
| 949 | stubs: { |
| 950 | versions: ["28", "29", "30", "current"], |
| 951 | }, |
| 952 | apex_available: [ "myapex" ], |
| 953 | min_sdk_version: "28", |
| 954 | } |
| 955 | |
| 956 | cc_library { |
| 957 | name: "mylib4", |
| 958 | srcs: ["mylib.cpp"], |
| 959 | system_shared_libs: [], |
| 960 | stl: "none", |
| 961 | apex_available: [ "myapex" ], |
| 962 | min_sdk_version: "28", |
| 963 | } |
| 964 | `) |
| 965 | |
| 966 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 967 | copyCmds := apexRule.Args["copy_commands"] |
| 968 | |
| 969 | // Ensure that direct non-stubs dep is always included |
| 970 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 971 | |
| 972 | // Ensure that indirect stubs dep is not included |
| 973 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 974 | |
| 975 | // Ensure that direct stubs dep is included |
| 976 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 977 | |
| 978 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"] |
| 979 | |
| 980 | // Ensure that mylib is linking with the version 29 stubs for mylib2 |
| 981 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_29/mylib2.so") |
| 982 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| 983 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 984 | |
| 985 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| 986 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so") |
| 987 | // .. and not linking to the stubs variant of mylib3 |
| 988 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so") |
| 989 | |
| 990 | // Ensure that stubs libs are built without -include flags |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 991 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("cc").Args["cFlags"] |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 992 | ensureNotContains(t, mylib2Cflags, "-include ") |
| 993 | |
| 994 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 995 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("genStubSrc").Args["flags"]) |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 996 | |
| 997 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 998 | "lib64/mylib.so", |
| 999 | "lib64/mylib3.so", |
| 1000 | "lib64/mylib4.so", |
| 1001 | }) |
| 1002 | } |
| 1003 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1004 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1005 | ctx, _ := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1006 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1007 | name: "myapex2", |
| 1008 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1009 | native_shared_libs: ["mylib"], |
| 1010 | } |
| 1011 | |
| 1012 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1013 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1014 | public_key: "testkey.avbpubkey", |
| 1015 | private_key: "testkey.pem", |
| 1016 | } |
| 1017 | |
| 1018 | cc_library { |
| 1019 | name: "mylib", |
| 1020 | srcs: ["mylib.cpp"], |
| 1021 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1022 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1023 | system_shared_libs: [], |
| 1024 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1025 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | cc_library { |
| 1029 | name: "libfoo", |
| 1030 | srcs: ["mylib.cpp"], |
| 1031 | shared_libs: ["libbar"], |
| 1032 | system_shared_libs: [], |
| 1033 | stl: "none", |
| 1034 | stubs: { |
| 1035 | versions: ["10", "20", "30"], |
| 1036 | }, |
| 1037 | } |
| 1038 | |
| 1039 | cc_library { |
| 1040 | name: "libbar", |
| 1041 | srcs: ["mylib.cpp"], |
| 1042 | system_shared_libs: [], |
| 1043 | stl: "none", |
| 1044 | } |
| 1045 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1046 | cc_library_static { |
| 1047 | name: "libbaz", |
| 1048 | srcs: ["mylib.cpp"], |
| 1049 | system_shared_libs: [], |
| 1050 | stl: "none", |
| 1051 | apex_available: [ "myapex2" ], |
| 1052 | } |
| 1053 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1054 | `) |
| 1055 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1056 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1057 | copyCmds := apexRule.Args["copy_commands"] |
| 1058 | |
| 1059 | // Ensure that direct non-stubs dep is always included |
| 1060 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1061 | |
| 1062 | // Ensure that indirect stubs dep is not included |
| 1063 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1064 | |
| 1065 | // Ensure that dependency of stubs is not included |
| 1066 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1067 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1068 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1069 | |
| 1070 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1071 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1072 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1073 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1074 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1075 | 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] | 1076 | |
| 1077 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 1078 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1079 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1080 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 1081 | ensureListContains(t, fullDepsInfo, " mylib(minSdkVersion:(no version)) <- myapex2") |
| 1082 | ensureListContains(t, fullDepsInfo, " libbaz(minSdkVersion:(no version)) <- mylib") |
| 1083 | ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1084 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1085 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 1086 | ensureListContains(t, flatDepsInfo, "mylib(minSdkVersion:(no version))") |
| 1087 | ensureListContains(t, flatDepsInfo, "libbaz(minSdkVersion:(no version))") |
| 1088 | ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1089 | } |
| 1090 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1091 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 1092 | /* |
| 1093 | myapex |
| 1094 | | |
| 1095 | v (runtime_libs) |
| 1096 | mylib ------+------> libfoo [provides stub] |
| 1097 | | |
| 1098 | `------> libbar |
| 1099 | */ |
| 1100 | ctx, _ := testApex(t, ` |
| 1101 | apex { |
| 1102 | name: "myapex", |
| 1103 | key: "myapex.key", |
| 1104 | native_shared_libs: ["mylib"], |
| 1105 | } |
| 1106 | |
| 1107 | apex_key { |
| 1108 | name: "myapex.key", |
| 1109 | public_key: "testkey.avbpubkey", |
| 1110 | private_key: "testkey.pem", |
| 1111 | } |
| 1112 | |
| 1113 | cc_library { |
| 1114 | name: "mylib", |
| 1115 | srcs: ["mylib.cpp"], |
| 1116 | runtime_libs: ["libfoo", "libbar"], |
| 1117 | system_shared_libs: [], |
| 1118 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1119 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | cc_library { |
| 1123 | name: "libfoo", |
| 1124 | srcs: ["mylib.cpp"], |
| 1125 | system_shared_libs: [], |
| 1126 | stl: "none", |
| 1127 | stubs: { |
| 1128 | versions: ["10", "20", "30"], |
| 1129 | }, |
| 1130 | } |
| 1131 | |
| 1132 | cc_library { |
| 1133 | name: "libbar", |
| 1134 | srcs: ["mylib.cpp"], |
| 1135 | system_shared_libs: [], |
| 1136 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1137 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | `) |
| 1141 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1142 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1143 | copyCmds := apexRule.Args["copy_commands"] |
| 1144 | |
| 1145 | // Ensure that direct non-stubs dep is always included |
| 1146 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1147 | |
| 1148 | // Ensure that indirect stubs dep is not included |
| 1149 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1150 | |
| 1151 | // Ensure that runtime_libs dep in included |
| 1152 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1153 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1154 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1155 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1156 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1157 | |
| 1158 | } |
| 1159 | |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1160 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
| 1161 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 1162 | bp := ` |
| 1163 | apex { |
| 1164 | name: "com.android.runtime", |
| 1165 | key: "com.android.runtime.key", |
| 1166 | native_shared_libs: ["libc"], |
| 1167 | } |
| 1168 | |
| 1169 | apex_key { |
| 1170 | name: "com.android.runtime.key", |
| 1171 | public_key: "testkey.avbpubkey", |
| 1172 | private_key: "testkey.pem", |
| 1173 | } |
| 1174 | |
| 1175 | cc_library { |
| 1176 | name: "libc", |
| 1177 | no_libcrt: true, |
| 1178 | nocrt: true, |
| 1179 | stl: "none", |
| 1180 | system_shared_libs: [], |
| 1181 | stubs: { versions: ["1"] }, |
| 1182 | apex_available: ["com.android.runtime"], |
| 1183 | |
| 1184 | sanitize: { |
| 1185 | hwaddress: true, |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | cc_prebuilt_library_shared { |
| 1190 | name: "libclang_rt.hwasan-aarch64-android", |
| 1191 | no_libcrt: true, |
| 1192 | nocrt: true, |
| 1193 | stl: "none", |
| 1194 | system_shared_libs: [], |
| 1195 | srcs: [""], |
| 1196 | stubs: { versions: ["1"] }, |
| 1197 | |
| 1198 | sanitize: { |
| 1199 | never: true, |
| 1200 | }, |
| 1201 | } |
| 1202 | ` |
| 1203 | // override bp to use hard-coded names: com.android.runtime and libc |
| 1204 | fs["Android.bp"] = []byte(bp) |
| 1205 | fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil |
| 1206 | }) |
| 1207 | |
| 1208 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1209 | "lib64/bionic/libc.so", |
| 1210 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1211 | }) |
| 1212 | |
| 1213 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1214 | |
| 1215 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1216 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1217 | |
| 1218 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1219 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1220 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1221 | } |
| 1222 | |
| 1223 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
| 1224 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 1225 | bp := ` |
| 1226 | apex { |
| 1227 | name: "com.android.runtime", |
| 1228 | key: "com.android.runtime.key", |
| 1229 | native_shared_libs: ["libc"], |
| 1230 | } |
| 1231 | |
| 1232 | apex_key { |
| 1233 | name: "com.android.runtime.key", |
| 1234 | public_key: "testkey.avbpubkey", |
| 1235 | private_key: "testkey.pem", |
| 1236 | } |
| 1237 | |
| 1238 | cc_library { |
| 1239 | name: "libc", |
| 1240 | no_libcrt: true, |
| 1241 | nocrt: true, |
| 1242 | stl: "none", |
| 1243 | system_shared_libs: [], |
| 1244 | stubs: { versions: ["1"] }, |
| 1245 | apex_available: ["com.android.runtime"], |
| 1246 | } |
| 1247 | |
| 1248 | cc_prebuilt_library_shared { |
| 1249 | name: "libclang_rt.hwasan-aarch64-android", |
| 1250 | no_libcrt: true, |
| 1251 | nocrt: true, |
| 1252 | stl: "none", |
| 1253 | system_shared_libs: [], |
| 1254 | srcs: [""], |
| 1255 | stubs: { versions: ["1"] }, |
| 1256 | |
| 1257 | sanitize: { |
| 1258 | never: true, |
| 1259 | }, |
| 1260 | } |
| 1261 | ` |
| 1262 | // override bp to use hard-coded names: com.android.runtime and libc |
| 1263 | fs["Android.bp"] = []byte(bp) |
| 1264 | fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil |
| 1265 | |
| 1266 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1267 | }) |
| 1268 | |
| 1269 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1270 | "lib64/bionic/libc.so", |
| 1271 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1272 | }) |
| 1273 | |
| 1274 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1275 | |
| 1276 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1277 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1278 | |
| 1279 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1280 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1281 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1282 | } |
| 1283 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1284 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1285 | testcases := []struct { |
| 1286 | name string |
| 1287 | minSdkVersion string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1288 | apexVariant string |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1289 | shouldLink string |
| 1290 | shouldNotLink []string |
| 1291 | }{ |
| 1292 | { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1293 | name: "should link to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1294 | minSdkVersion: "", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1295 | apexVariant: "apex10000", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1296 | shouldLink: "30", |
| 1297 | shouldNotLink: []string{"29"}, |
| 1298 | }, |
| 1299 | { |
| 1300 | name: "should link to llndk#29", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1301 | minSdkVersion: "min_sdk_version: \"29\",", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1302 | apexVariant: "apex29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1303 | shouldLink: "29", |
| 1304 | shouldNotLink: []string{"30"}, |
| 1305 | }, |
| 1306 | } |
| 1307 | for _, tc := range testcases { |
| 1308 | t.Run(tc.name, func(t *testing.T) { |
| 1309 | ctx, _ := testApex(t, ` |
| 1310 | apex { |
| 1311 | name: "myapex", |
| 1312 | key: "myapex.key", |
| 1313 | use_vendor: true, |
| 1314 | native_shared_libs: ["mylib"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1315 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1316 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1317 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1318 | apex_key { |
| 1319 | name: "myapex.key", |
| 1320 | public_key: "testkey.avbpubkey", |
| 1321 | private_key: "testkey.pem", |
| 1322 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1323 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1324 | cc_library { |
| 1325 | name: "mylib", |
| 1326 | srcs: ["mylib.cpp"], |
| 1327 | vendor_available: true, |
| 1328 | shared_libs: ["libbar"], |
| 1329 | system_shared_libs: [], |
| 1330 | stl: "none", |
| 1331 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1332 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1333 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1334 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1335 | cc_library { |
| 1336 | name: "libbar", |
| 1337 | srcs: ["mylib.cpp"], |
| 1338 | system_shared_libs: [], |
| 1339 | stl: "none", |
| 1340 | stubs: { versions: ["29","30"] }, |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1341 | llndk_stubs: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1342 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1343 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1344 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1345 | name: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1346 | symbol_file: "", |
| 1347 | } |
| 1348 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 1349 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1350 | }, withUnbundledBuild) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1351 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1352 | // Ensure that LLNDK dep is not included |
| 1353 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1354 | "lib64/mylib.so", |
| 1355 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1356 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1357 | // Ensure that LLNDK dep is required |
| 1358 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1359 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1360 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1361 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1362 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"] |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 1363 | ensureContains(t, mylibLdFlags, "libbar/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1364 | for _, ver := range tc.shouldNotLink { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 1365 | ensureNotContains(t, mylibLdFlags, "libbar/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1366 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1367 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1368 | mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_"+tc.apexVariant).Rule("cc").Args["cFlags"] |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1369 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink) |
| 1370 | }) |
| 1371 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1372 | } |
| 1373 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1374 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1375 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1376 | apex { |
| 1377 | name: "myapex", |
| 1378 | key: "myapex.key", |
| 1379 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 1380 | } |
| 1381 | |
| 1382 | apex_key { |
| 1383 | name: "myapex.key", |
| 1384 | public_key: "testkey.avbpubkey", |
| 1385 | private_key: "testkey.pem", |
| 1386 | } |
| 1387 | |
| 1388 | cc_library { |
| 1389 | name: "mylib", |
| 1390 | srcs: ["mylib.cpp"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1391 | system_shared_libs: ["libc", "libm"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1392 | shared_libs: ["libdl#27"], |
| 1393 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1394 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | cc_library_shared { |
| 1398 | name: "mylib_shared", |
| 1399 | srcs: ["mylib.cpp"], |
| 1400 | shared_libs: ["libdl#27"], |
| 1401 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1402 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1406 | name: "libBootstrap", |
| 1407 | srcs: ["mylib.cpp"], |
| 1408 | stl: "none", |
| 1409 | bootstrap: true, |
| 1410 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1411 | `) |
| 1412 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1413 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1414 | copyCmds := apexRule.Args["copy_commands"] |
| 1415 | |
| 1416 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1417 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1418 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1419 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1420 | |
| 1421 | // 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] | 1422 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1423 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1424 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1425 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1426 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_apex10000").Rule("cc").Args["cFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1427 | |
| 1428 | // For dependency to libc |
| 1429 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1430 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1431 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1432 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1433 | // ... Cflags from stub is correctly exported to mylib |
| 1434 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 1435 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 1436 | |
| 1437 | // For dependency to libm |
| 1438 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1439 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1440 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1441 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1442 | // ... and is not compiling with the stub |
| 1443 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1444 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1445 | |
| 1446 | // For dependency to libdl |
| 1447 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1448 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1449 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1450 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1451 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1452 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1453 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1454 | // ... Cflags from stub is correctly exported to mylib |
| 1455 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1456 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1457 | |
| 1458 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1459 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1460 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1461 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1462 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1463 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1464 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1465 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1466 | // there are three links between liba --> libz |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1467 | // 1) myapex -> libx -> liba -> libz : this should be #29 link, but fallback to #28 |
| 1468 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1469 | // 3) (platform) -> liba -> libz : this should be non-stub link |
| 1470 | ctx, _ := testApex(t, ` |
| 1471 | apex { |
| 1472 | name: "myapex", |
| 1473 | key: "myapex.key", |
| 1474 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1475 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | apex { |
| 1479 | name: "otherapex", |
| 1480 | key: "myapex.key", |
| 1481 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1482 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | apex_key { |
| 1486 | name: "myapex.key", |
| 1487 | public_key: "testkey.avbpubkey", |
| 1488 | private_key: "testkey.pem", |
| 1489 | } |
| 1490 | |
| 1491 | cc_library { |
| 1492 | name: "libx", |
| 1493 | shared_libs: ["liba"], |
| 1494 | system_shared_libs: [], |
| 1495 | stl: "none", |
| 1496 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1497 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | cc_library { |
| 1501 | name: "liby", |
| 1502 | shared_libs: ["liba"], |
| 1503 | system_shared_libs: [], |
| 1504 | stl: "none", |
| 1505 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1506 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | cc_library { |
| 1510 | name: "liba", |
| 1511 | shared_libs: ["libz"], |
| 1512 | system_shared_libs: [], |
| 1513 | stl: "none", |
| 1514 | apex_available: [ |
| 1515 | "//apex_available:anyapex", |
| 1516 | "//apex_available:platform", |
| 1517 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1518 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | cc_library { |
| 1522 | name: "libz", |
| 1523 | system_shared_libs: [], |
| 1524 | stl: "none", |
| 1525 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1526 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1527 | }, |
| 1528 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1529 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1530 | |
| 1531 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1532 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1533 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1534 | } |
| 1535 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1536 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1537 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1538 | } |
| 1539 | // platform liba is linked to non-stub version |
| 1540 | expectLink("liba", "shared", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1541 | // liba in myapex is linked to #28 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1542 | expectLink("liba", "shared_apex29", "libz", "shared_28") |
| 1543 | expectNoLink("liba", "shared_apex29", "libz", "shared_30") |
| 1544 | expectNoLink("liba", "shared_apex29", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1545 | // liba in otherapex is linked to #30 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1546 | expectLink("liba", "shared_apex30", "libz", "shared_30") |
| 1547 | expectNoLink("liba", "shared_apex30", "libz", "shared_28") |
| 1548 | expectNoLink("liba", "shared_apex30", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1549 | } |
| 1550 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1551 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
| 1552 | ctx, _ := testApex(t, ` |
| 1553 | apex { |
| 1554 | name: "myapex", |
| 1555 | key: "myapex.key", |
| 1556 | native_shared_libs: ["libx"], |
| 1557 | min_sdk_version: "R", |
| 1558 | } |
| 1559 | |
| 1560 | apex_key { |
| 1561 | name: "myapex.key", |
| 1562 | public_key: "testkey.avbpubkey", |
| 1563 | private_key: "testkey.pem", |
| 1564 | } |
| 1565 | |
| 1566 | cc_library { |
| 1567 | name: "libx", |
| 1568 | shared_libs: ["libz"], |
| 1569 | system_shared_libs: [], |
| 1570 | stl: "none", |
| 1571 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1572 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | cc_library { |
| 1576 | name: "libz", |
| 1577 | system_shared_libs: [], |
| 1578 | stl: "none", |
| 1579 | stubs: { |
| 1580 | versions: ["29", "R"], |
| 1581 | }, |
| 1582 | } |
| 1583 | `, func(fs map[string][]byte, config android.Config) { |
| 1584 | config.TestProductVariables.Platform_version_active_codenames = []string{"R"} |
| 1585 | }) |
| 1586 | |
| 1587 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1588 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1589 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1590 | } |
| 1591 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1592 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1593 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1594 | } |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1595 | expectLink("libx", "shared_apex10000", "libz", "shared_R") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1596 | expectNoLink("libx", "shared_apex10000", "libz", "shared_29") |
| 1597 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1598 | } |
| 1599 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1600 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1601 | ctx, _ := testApex(t, ` |
| 1602 | apex { |
| 1603 | name: "myapex", |
| 1604 | key: "myapex.key", |
| 1605 | native_shared_libs: ["libx"], |
| 1606 | } |
| 1607 | |
| 1608 | apex_key { |
| 1609 | name: "myapex.key", |
| 1610 | public_key: "testkey.avbpubkey", |
| 1611 | private_key: "testkey.pem", |
| 1612 | } |
| 1613 | |
| 1614 | cc_library { |
| 1615 | name: "libx", |
| 1616 | shared_libs: ["libz"], |
| 1617 | system_shared_libs: [], |
| 1618 | stl: "none", |
| 1619 | apex_available: [ "myapex" ], |
| 1620 | } |
| 1621 | |
| 1622 | cc_library { |
| 1623 | name: "libz", |
| 1624 | system_shared_libs: [], |
| 1625 | stl: "none", |
| 1626 | stubs: { |
| 1627 | versions: ["1", "2"], |
| 1628 | }, |
| 1629 | } |
| 1630 | `) |
| 1631 | |
| 1632 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1633 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1634 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1635 | } |
| 1636 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1637 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1638 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1639 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1640 | expectLink("libx", "shared_apex10000", "libz", "shared_2") |
| 1641 | expectNoLink("libx", "shared_apex10000", "libz", "shared_1") |
| 1642 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
| 1646 | ctx, _ := testApex(t, ` |
| 1647 | apex { |
| 1648 | name: "myapex", |
| 1649 | key: "myapex.key", |
| 1650 | native_shared_libs: ["libx"], |
| 1651 | } |
| 1652 | |
| 1653 | apex_key { |
| 1654 | name: "myapex.key", |
| 1655 | public_key: "testkey.avbpubkey", |
| 1656 | private_key: "testkey.pem", |
| 1657 | } |
| 1658 | |
| 1659 | cc_library { |
| 1660 | name: "libx", |
| 1661 | system_shared_libs: [], |
| 1662 | stl: "none", |
| 1663 | apex_available: [ "myapex" ], |
| 1664 | stubs: { |
| 1665 | versions: ["1", "2"], |
| 1666 | }, |
| 1667 | } |
| 1668 | |
| 1669 | cc_library { |
| 1670 | name: "libz", |
| 1671 | shared_libs: ["libx"], |
| 1672 | system_shared_libs: [], |
| 1673 | stl: "none", |
| 1674 | } |
| 1675 | `) |
| 1676 | |
| 1677 | expectLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1678 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1679 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1680 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1681 | } |
| 1682 | expectNoLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1683 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1684 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1685 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1686 | } |
| 1687 | expectLink("libz", "shared", "libx", "shared_2") |
| 1688 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1689 | expectNoLink("libz", "shared", "libz", "shared") |
| 1690 | } |
| 1691 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1692 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1693 | ctx, _ := testApex(t, ` |
| 1694 | apex { |
| 1695 | name: "myapex", |
| 1696 | key: "myapex.key", |
| 1697 | native_shared_libs: ["libx"], |
| 1698 | min_sdk_version: "29", |
| 1699 | } |
| 1700 | |
| 1701 | apex_key { |
| 1702 | name: "myapex.key", |
| 1703 | public_key: "testkey.avbpubkey", |
| 1704 | private_key: "testkey.pem", |
| 1705 | } |
| 1706 | |
| 1707 | cc_library { |
| 1708 | name: "libx", |
| 1709 | shared_libs: ["libbar"], |
| 1710 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1711 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | cc_library { |
| 1715 | name: "libbar", |
| 1716 | stubs: { |
| 1717 | versions: ["29", "30"], |
| 1718 | }, |
| 1719 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1720 | `, func(fs map[string][]byte, config android.Config) { |
| 1721 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1722 | }) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1723 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1724 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1725 | libFlags := ld.Args["libFlags"] |
| 1726 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1727 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1728 | expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_30") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1729 | } |
| 1730 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1731 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1732 | ctx, _ := testApex(t, ` |
| 1733 | apex { |
| 1734 | name: "myapex", |
| 1735 | key: "myapex.key", |
| 1736 | native_shared_libs: ["libx"], |
| 1737 | min_sdk_version: "29", |
| 1738 | } |
| 1739 | |
| 1740 | apex_key { |
| 1741 | name: "myapex.key", |
| 1742 | public_key: "testkey.avbpubkey", |
| 1743 | private_key: "testkey.pem", |
| 1744 | } |
| 1745 | |
| 1746 | cc_library { |
| 1747 | name: "libx", |
| 1748 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1749 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1750 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1751 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1752 | |
| 1753 | // ensure apex variant of c++ is linked with static unwinder |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1754 | cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_apex29").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 1755 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1756 | // note that platform variant is not. |
| 1757 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 1758 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1759 | } |
| 1760 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1761 | func TestApexMinSdkVersion_ErrorIfIncompatibleStubs(t *testing.T) { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1762 | testApexError(t, `"libz" .*: not found a version\(<=29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1763 | apex { |
| 1764 | name: "myapex", |
| 1765 | key: "myapex.key", |
| 1766 | native_shared_libs: ["libx"], |
| 1767 | min_sdk_version: "29", |
| 1768 | } |
| 1769 | |
| 1770 | apex_key { |
| 1771 | name: "myapex.key", |
| 1772 | public_key: "testkey.avbpubkey", |
| 1773 | private_key: "testkey.pem", |
| 1774 | } |
| 1775 | |
| 1776 | cc_library { |
| 1777 | name: "libx", |
| 1778 | shared_libs: ["libz"], |
| 1779 | system_shared_libs: [], |
| 1780 | stl: "none", |
| 1781 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1782 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | cc_library { |
| 1786 | name: "libz", |
| 1787 | system_shared_libs: [], |
| 1788 | stl: "none", |
| 1789 | stubs: { |
| 1790 | versions: ["30"], |
| 1791 | }, |
| 1792 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1793 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1794 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1795 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1796 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 1797 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1798 | apex { |
| 1799 | name: "myapex", |
| 1800 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1801 | native_shared_libs: ["mylib"], |
| 1802 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | apex_key { |
| 1806 | name: "myapex.key", |
| 1807 | public_key: "testkey.avbpubkey", |
| 1808 | private_key: "testkey.pem", |
| 1809 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1810 | |
| 1811 | cc_library { |
| 1812 | name: "mylib", |
| 1813 | srcs: ["mylib.cpp"], |
| 1814 | system_shared_libs: [], |
| 1815 | stl: "none", |
| 1816 | apex_available: [ |
| 1817 | "myapex", |
| 1818 | ], |
| 1819 | min_sdk_version: "30", |
| 1820 | } |
| 1821 | `) |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1822 | |
| 1823 | testApexError(t, `module "libfoo.ffi".*: should support min_sdk_version\(29\)`, ` |
| 1824 | apex { |
| 1825 | name: "myapex", |
| 1826 | key: "myapex.key", |
| 1827 | native_shared_libs: ["libfoo.ffi"], |
| 1828 | min_sdk_version: "29", |
| 1829 | } |
| 1830 | |
| 1831 | apex_key { |
| 1832 | name: "myapex.key", |
| 1833 | public_key: "testkey.avbpubkey", |
| 1834 | private_key: "testkey.pem", |
| 1835 | } |
| 1836 | |
| 1837 | rust_ffi_shared { |
| 1838 | name: "libfoo.ffi", |
| 1839 | srcs: ["foo.rs"], |
| 1840 | crate_name: "foo", |
| 1841 | apex_available: [ |
| 1842 | "myapex", |
| 1843 | ], |
| 1844 | min_sdk_version: "30", |
| 1845 | } |
| 1846 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 1850 | testApex(t, ` |
| 1851 | apex { |
| 1852 | name: "myapex", |
| 1853 | key: "myapex.key", |
| 1854 | native_shared_libs: ["libfoo"], |
| 1855 | java_libs: ["libbar"], |
| 1856 | min_sdk_version: "29", |
| 1857 | } |
| 1858 | |
| 1859 | apex_key { |
| 1860 | name: "myapex.key", |
| 1861 | public_key: "testkey.avbpubkey", |
| 1862 | private_key: "testkey.pem", |
| 1863 | } |
| 1864 | |
| 1865 | cc_library { |
| 1866 | name: "libfoo", |
| 1867 | srcs: ["mylib.cpp"], |
| 1868 | shared_libs: ["libfoo_dep"], |
| 1869 | apex_available: ["myapex"], |
| 1870 | min_sdk_version: "29", |
| 1871 | } |
| 1872 | |
| 1873 | cc_library { |
| 1874 | name: "libfoo_dep", |
| 1875 | srcs: ["mylib.cpp"], |
| 1876 | apex_available: ["myapex"], |
| 1877 | min_sdk_version: "29", |
| 1878 | } |
| 1879 | |
| 1880 | java_library { |
| 1881 | name: "libbar", |
| 1882 | sdk_version: "current", |
| 1883 | srcs: ["a.java"], |
| 1884 | static_libs: ["libbar_dep"], |
| 1885 | apex_available: ["myapex"], |
| 1886 | min_sdk_version: "29", |
| 1887 | } |
| 1888 | |
| 1889 | java_library { |
| 1890 | name: "libbar_dep", |
| 1891 | sdk_version: "current", |
| 1892 | srcs: ["a.java"], |
| 1893 | apex_available: ["myapex"], |
| 1894 | min_sdk_version: "29", |
| 1895 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1896 | `) |
| 1897 | } |
| 1898 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1899 | func TestJavaStableSdkVersion(t *testing.T) { |
| 1900 | testCases := []struct { |
| 1901 | name string |
| 1902 | expectedError string |
| 1903 | bp string |
| 1904 | }{ |
| 1905 | { |
| 1906 | name: "Non-updatable apex with non-stable dep", |
| 1907 | bp: ` |
| 1908 | apex { |
| 1909 | name: "myapex", |
| 1910 | java_libs: ["myjar"], |
| 1911 | key: "myapex.key", |
| 1912 | } |
| 1913 | apex_key { |
| 1914 | name: "myapex.key", |
| 1915 | public_key: "testkey.avbpubkey", |
| 1916 | private_key: "testkey.pem", |
| 1917 | } |
| 1918 | java_library { |
| 1919 | name: "myjar", |
| 1920 | srcs: ["foo/bar/MyClass.java"], |
| 1921 | sdk_version: "core_platform", |
| 1922 | apex_available: ["myapex"], |
| 1923 | } |
| 1924 | `, |
| 1925 | }, |
| 1926 | { |
| 1927 | name: "Updatable apex with stable dep", |
| 1928 | bp: ` |
| 1929 | apex { |
| 1930 | name: "myapex", |
| 1931 | java_libs: ["myjar"], |
| 1932 | key: "myapex.key", |
| 1933 | updatable: true, |
| 1934 | min_sdk_version: "29", |
| 1935 | } |
| 1936 | apex_key { |
| 1937 | name: "myapex.key", |
| 1938 | public_key: "testkey.avbpubkey", |
| 1939 | private_key: "testkey.pem", |
| 1940 | } |
| 1941 | java_library { |
| 1942 | name: "myjar", |
| 1943 | srcs: ["foo/bar/MyClass.java"], |
| 1944 | sdk_version: "current", |
| 1945 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1946 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1947 | } |
| 1948 | `, |
| 1949 | }, |
| 1950 | { |
| 1951 | name: "Updatable apex with non-stable dep", |
| 1952 | expectedError: "cannot depend on \"myjar\"", |
| 1953 | bp: ` |
| 1954 | apex { |
| 1955 | name: "myapex", |
| 1956 | java_libs: ["myjar"], |
| 1957 | key: "myapex.key", |
| 1958 | updatable: true, |
| 1959 | } |
| 1960 | apex_key { |
| 1961 | name: "myapex.key", |
| 1962 | public_key: "testkey.avbpubkey", |
| 1963 | private_key: "testkey.pem", |
| 1964 | } |
| 1965 | java_library { |
| 1966 | name: "myjar", |
| 1967 | srcs: ["foo/bar/MyClass.java"], |
| 1968 | sdk_version: "core_platform", |
| 1969 | apex_available: ["myapex"], |
| 1970 | } |
| 1971 | `, |
| 1972 | }, |
| 1973 | { |
| 1974 | name: "Updatable apex with non-stable transitive dep", |
| 1975 | expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against non-public Android API.", |
| 1976 | bp: ` |
| 1977 | apex { |
| 1978 | name: "myapex", |
| 1979 | java_libs: ["myjar"], |
| 1980 | key: "myapex.key", |
| 1981 | updatable: true, |
| 1982 | } |
| 1983 | apex_key { |
| 1984 | name: "myapex.key", |
| 1985 | public_key: "testkey.avbpubkey", |
| 1986 | private_key: "testkey.pem", |
| 1987 | } |
| 1988 | java_library { |
| 1989 | name: "myjar", |
| 1990 | srcs: ["foo/bar/MyClass.java"], |
| 1991 | sdk_version: "current", |
| 1992 | apex_available: ["myapex"], |
| 1993 | static_libs: ["transitive-jar"], |
| 1994 | } |
| 1995 | java_library { |
| 1996 | name: "transitive-jar", |
| 1997 | srcs: ["foo/bar/MyClass.java"], |
| 1998 | sdk_version: "core_platform", |
| 1999 | apex_available: ["myapex"], |
| 2000 | } |
| 2001 | `, |
| 2002 | }, |
| 2003 | } |
| 2004 | |
| 2005 | for _, test := range testCases { |
| 2006 | t.Run(test.name, func(t *testing.T) { |
| 2007 | if test.expectedError == "" { |
| 2008 | testApex(t, test.bp) |
| 2009 | } else { |
| 2010 | testApexError(t, test.expectedError, test.bp) |
| 2011 | } |
| 2012 | }) |
| 2013 | } |
| 2014 | } |
| 2015 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2016 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 2017 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2018 | apex { |
| 2019 | name: "myapex", |
| 2020 | key: "myapex.key", |
| 2021 | native_shared_libs: ["mylib"], |
| 2022 | min_sdk_version: "29", |
| 2023 | } |
| 2024 | |
| 2025 | apex_key { |
| 2026 | name: "myapex.key", |
| 2027 | public_key: "testkey.avbpubkey", |
| 2028 | private_key: "testkey.pem", |
| 2029 | } |
| 2030 | |
| 2031 | cc_library { |
| 2032 | name: "mylib", |
| 2033 | srcs: ["mylib.cpp"], |
| 2034 | shared_libs: ["mylib2"], |
| 2035 | system_shared_libs: [], |
| 2036 | stl: "none", |
| 2037 | apex_available: [ |
| 2038 | "myapex", |
| 2039 | ], |
| 2040 | min_sdk_version: "29", |
| 2041 | } |
| 2042 | |
| 2043 | // indirect part of the apex |
| 2044 | cc_library { |
| 2045 | name: "mylib2", |
| 2046 | srcs: ["mylib.cpp"], |
| 2047 | system_shared_libs: [], |
| 2048 | stl: "none", |
| 2049 | apex_available: [ |
| 2050 | "myapex", |
| 2051 | ], |
| 2052 | min_sdk_version: "30", |
| 2053 | } |
| 2054 | `) |
| 2055 | } |
| 2056 | |
| 2057 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 2058 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2059 | apex { |
| 2060 | name: "myapex", |
| 2061 | key: "myapex.key", |
| 2062 | apps: ["AppFoo"], |
| 2063 | min_sdk_version: "29", |
| 2064 | } |
| 2065 | |
| 2066 | apex_key { |
| 2067 | name: "myapex.key", |
| 2068 | public_key: "testkey.avbpubkey", |
| 2069 | private_key: "testkey.pem", |
| 2070 | } |
| 2071 | |
| 2072 | android_app { |
| 2073 | name: "AppFoo", |
| 2074 | srcs: ["foo/bar/MyClass.java"], |
| 2075 | sdk_version: "current", |
| 2076 | min_sdk_version: "29", |
| 2077 | system_modules: "none", |
| 2078 | stl: "none", |
| 2079 | static_libs: ["bar"], |
| 2080 | apex_available: [ "myapex" ], |
| 2081 | } |
| 2082 | |
| 2083 | java_library { |
| 2084 | name: "bar", |
| 2085 | sdk_version: "current", |
| 2086 | srcs: ["a.java"], |
| 2087 | apex_available: [ "myapex" ], |
| 2088 | } |
| 2089 | `) |
| 2090 | } |
| 2091 | |
| 2092 | func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) { |
| 2093 | ctx, _ := testApex(t, ` |
| 2094 | apex { |
| 2095 | name: "myapex", |
| 2096 | key: "myapex.key", |
| 2097 | native_shared_libs: ["mylib"], |
| 2098 | min_sdk_version: "29", |
| 2099 | } |
| 2100 | |
| 2101 | apex_key { |
| 2102 | name: "myapex.key", |
| 2103 | public_key: "testkey.avbpubkey", |
| 2104 | private_key: "testkey.pem", |
| 2105 | } |
| 2106 | |
| 2107 | // mylib in myapex will link to mylib2#29 |
| 2108 | // mylib in otherapex will link to mylib2(non-stub) in otherapex as well |
| 2109 | cc_library { |
| 2110 | name: "mylib", |
| 2111 | srcs: ["mylib.cpp"], |
| 2112 | shared_libs: ["mylib2"], |
| 2113 | system_shared_libs: [], |
| 2114 | stl: "none", |
| 2115 | apex_available: ["myapex", "otherapex"], |
| 2116 | min_sdk_version: "29", |
| 2117 | } |
| 2118 | |
| 2119 | cc_library { |
| 2120 | name: "mylib2", |
| 2121 | srcs: ["mylib.cpp"], |
| 2122 | system_shared_libs: [], |
| 2123 | stl: "none", |
| 2124 | apex_available: ["otherapex"], |
| 2125 | stubs: { versions: ["29", "30"] }, |
| 2126 | min_sdk_version: "30", |
| 2127 | } |
| 2128 | |
| 2129 | apex { |
| 2130 | name: "otherapex", |
| 2131 | key: "myapex.key", |
| 2132 | native_shared_libs: ["mylib", "mylib2"], |
| 2133 | min_sdk_version: "30", |
| 2134 | } |
| 2135 | `) |
| 2136 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2137 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2138 | libFlags := ld.Args["libFlags"] |
| 2139 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2140 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2141 | expectLink("mylib", "shared_apex29", "mylib2", "shared_29") |
| 2142 | expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2143 | } |
| 2144 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2145 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2146 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2147 | apex { |
| 2148 | name: "myapex", |
| 2149 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2150 | native_shared_libs: ["mylib"], |
| 2151 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2152 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2153 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | apex_key { |
| 2157 | name: "myapex.key", |
| 2158 | public_key: "testkey.avbpubkey", |
| 2159 | private_key: "testkey.pem", |
| 2160 | } |
| 2161 | |
| 2162 | prebuilt_etc { |
| 2163 | name: "myetc", |
| 2164 | src: "myprebuilt", |
| 2165 | sub_dir: "foo/bar", |
| 2166 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2167 | |
| 2168 | cc_library { |
| 2169 | name: "mylib", |
| 2170 | srcs: ["mylib.cpp"], |
| 2171 | relative_install_path: "foo/bar", |
| 2172 | system_shared_libs: [], |
| 2173 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2174 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | cc_binary { |
| 2178 | name: "mybin", |
| 2179 | srcs: ["mylib.cpp"], |
| 2180 | relative_install_path: "foo/bar", |
| 2181 | system_shared_libs: [], |
| 2182 | static_executable: true, |
| 2183 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2184 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2185 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2186 | `) |
| 2187 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2188 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2189 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 2190 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2191 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2192 | ensureListContains(t, dirs, "etc") |
| 2193 | ensureListContains(t, dirs, "etc/foo") |
| 2194 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2195 | ensureListContains(t, dirs, "lib64") |
| 2196 | ensureListContains(t, dirs, "lib64/foo") |
| 2197 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 2198 | ensureListContains(t, dirs, "lib") |
| 2199 | ensureListContains(t, dirs, "lib/foo") |
| 2200 | ensureListContains(t, dirs, "lib/foo/bar") |
| 2201 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 2202 | ensureListContains(t, dirs, "bin") |
| 2203 | ensureListContains(t, dirs, "bin/foo") |
| 2204 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2205 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2206 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2207 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
| 2208 | ctx, _ := testApex(t, ` |
| 2209 | apex { |
| 2210 | name: "myapex", |
| 2211 | key: "myapex.key", |
| 2212 | multilib: { |
| 2213 | both: { |
| 2214 | native_shared_libs: ["mylib"], |
| 2215 | binaries: ["mybin"], |
| 2216 | }, |
| 2217 | }, |
| 2218 | compile_multilib: "both", |
| 2219 | native_bridge_supported: true, |
| 2220 | } |
| 2221 | |
| 2222 | apex_key { |
| 2223 | name: "myapex.key", |
| 2224 | public_key: "testkey.avbpubkey", |
| 2225 | private_key: "testkey.pem", |
| 2226 | } |
| 2227 | |
| 2228 | cc_library { |
| 2229 | name: "mylib", |
| 2230 | relative_install_path: "foo/bar", |
| 2231 | system_shared_libs: [], |
| 2232 | stl: "none", |
| 2233 | apex_available: [ "myapex" ], |
| 2234 | native_bridge_supported: true, |
| 2235 | } |
| 2236 | |
| 2237 | cc_binary { |
| 2238 | name: "mybin", |
| 2239 | relative_install_path: "foo/bar", |
| 2240 | system_shared_libs: [], |
| 2241 | static_executable: true, |
| 2242 | stl: "none", |
| 2243 | apex_available: [ "myapex" ], |
| 2244 | native_bridge_supported: true, |
| 2245 | compile_multilib: "both", // default is "first" for binary |
| 2246 | multilib: { |
| 2247 | lib64: { |
| 2248 | suffix: "64", |
| 2249 | }, |
| 2250 | }, |
| 2251 | } |
| 2252 | `, withNativeBridgeEnabled) |
| 2253 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2254 | "bin/foo/bar/mybin", |
| 2255 | "bin/foo/bar/mybin64", |
| 2256 | "bin/arm/foo/bar/mybin", |
| 2257 | "bin/arm64/foo/bar/mybin64", |
| 2258 | "lib/foo/bar/mylib.so", |
| 2259 | "lib/arm/foo/bar/mylib.so", |
| 2260 | "lib64/foo/bar/mylib.so", |
| 2261 | "lib64/arm64/foo/bar/mylib.so", |
| 2262 | }) |
| 2263 | } |
| 2264 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2265 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2266 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2267 | apex { |
| 2268 | name: "myapex", |
| 2269 | key: "myapex.key", |
| 2270 | native_shared_libs: ["mylib"], |
| 2271 | use_vendor: true, |
| 2272 | } |
| 2273 | |
| 2274 | apex_key { |
| 2275 | name: "myapex.key", |
| 2276 | public_key: "testkey.avbpubkey", |
| 2277 | private_key: "testkey.pem", |
| 2278 | } |
| 2279 | |
| 2280 | cc_library { |
| 2281 | name: "mylib", |
| 2282 | srcs: ["mylib.cpp"], |
| 2283 | shared_libs: ["mylib2"], |
| 2284 | system_shared_libs: [], |
| 2285 | vendor_available: true, |
| 2286 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2287 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | cc_library { |
| 2291 | name: "mylib2", |
| 2292 | srcs: ["mylib.cpp"], |
| 2293 | system_shared_libs: [], |
| 2294 | vendor_available: true, |
| 2295 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2296 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2297 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2298 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2299 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2300 | }) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2301 | |
| 2302 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2303 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2304 | for _, implicit := range i.Implicits { |
| 2305 | inputsList = append(inputsList, implicit.String()) |
| 2306 | } |
| 2307 | } |
| 2308 | inputsString := strings.Join(inputsList, " ") |
| 2309 | |
| 2310 | // ensure that the apex includes vendor variants of the direct and indirect deps |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2311 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2312 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2313 | |
| 2314 | // ensure that the apex does not include core variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2315 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2316 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2317 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2318 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2319 | func TestUseVendorNotAllowedForSystemApexes(t *testing.T) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2320 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 2321 | apex { |
| 2322 | name: "myapex", |
| 2323 | key: "myapex.key", |
| 2324 | use_vendor: true, |
| 2325 | } |
| 2326 | apex_key { |
| 2327 | name: "myapex.key", |
| 2328 | public_key: "testkey.avbpubkey", |
| 2329 | private_key: "testkey.pem", |
| 2330 | } |
| 2331 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2332 | setUseVendorAllowListForTest(config, []string{""}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2333 | }) |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2334 | // no error with allow list |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2335 | testApex(t, ` |
| 2336 | apex { |
| 2337 | name: "myapex", |
| 2338 | key: "myapex.key", |
| 2339 | use_vendor: true, |
| 2340 | } |
| 2341 | apex_key { |
| 2342 | name: "myapex.key", |
| 2343 | public_key: "testkey.avbpubkey", |
| 2344 | private_key: "testkey.pem", |
| 2345 | } |
| 2346 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2347 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2348 | }) |
| 2349 | } |
| 2350 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2351 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 2352 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 2353 | apex { |
| 2354 | name: "myapex", |
| 2355 | key: "myapex.key", |
| 2356 | native_shared_libs: ["mylib"], |
| 2357 | use_vendor: true, |
| 2358 | } |
| 2359 | |
| 2360 | apex_key { |
| 2361 | name: "myapex.key", |
| 2362 | public_key: "testkey.avbpubkey", |
| 2363 | private_key: "testkey.pem", |
| 2364 | } |
| 2365 | |
| 2366 | cc_library { |
| 2367 | name: "mylib", |
| 2368 | srcs: ["mylib.cpp"], |
| 2369 | system_shared_libs: [], |
| 2370 | stl: "none", |
| 2371 | } |
| 2372 | `) |
| 2373 | } |
| 2374 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2375 | func TestVendorApex(t *testing.T) { |
| 2376 | ctx, config := testApex(t, ` |
| 2377 | apex { |
| 2378 | name: "myapex", |
| 2379 | key: "myapex.key", |
| 2380 | binaries: ["mybin"], |
| 2381 | vendor: true, |
| 2382 | } |
| 2383 | apex_key { |
| 2384 | name: "myapex.key", |
| 2385 | public_key: "testkey.avbpubkey", |
| 2386 | private_key: "testkey.pem", |
| 2387 | } |
| 2388 | cc_binary { |
| 2389 | name: "mybin", |
| 2390 | vendor: true, |
| 2391 | shared_libs: ["libfoo"], |
| 2392 | } |
| 2393 | cc_library { |
| 2394 | name: "libfoo", |
| 2395 | proprietary: true, |
| 2396 | } |
| 2397 | `) |
| 2398 | |
| 2399 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2400 | "bin/mybin", |
| 2401 | "lib64/libfoo.so", |
| 2402 | // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX |
| 2403 | "lib64/libc++.so", |
| 2404 | }) |
| 2405 | |
| 2406 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2407 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2408 | name := apexBundle.BaseModuleName() |
| 2409 | prefix := "TARGET_" |
| 2410 | var builder strings.Builder |
| 2411 | data.Custom(&builder, name, prefix, "", data) |
| 2412 | androidMk := builder.String() |
| 2413 | ensureContains(t, androidMk, `LOCAL_MODULE_PATH := /tmp/target/product/test_device/vendor/apex`) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2414 | |
| 2415 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2416 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2417 | ensureListNotContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2418 | } |
| 2419 | |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2420 | func TestVendorApex_use_vndk_as_stable(t *testing.T) { |
| 2421 | ctx, _ := testApex(t, ` |
| 2422 | apex { |
| 2423 | name: "myapex", |
| 2424 | key: "myapex.key", |
| 2425 | binaries: ["mybin"], |
| 2426 | vendor: true, |
| 2427 | use_vndk_as_stable: true, |
| 2428 | } |
| 2429 | apex_key { |
| 2430 | name: "myapex.key", |
| 2431 | public_key: "testkey.avbpubkey", |
| 2432 | private_key: "testkey.pem", |
| 2433 | } |
| 2434 | cc_binary { |
| 2435 | name: "mybin", |
| 2436 | vendor: true, |
| 2437 | shared_libs: ["libvndk", "libvendor"], |
| 2438 | } |
| 2439 | cc_library { |
| 2440 | name: "libvndk", |
| 2441 | vndk: { |
| 2442 | enabled: true, |
| 2443 | }, |
| 2444 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2445 | product_available: true, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2446 | } |
| 2447 | cc_library { |
| 2448 | name: "libvendor", |
| 2449 | vendor: true, |
| 2450 | } |
| 2451 | `) |
| 2452 | |
| 2453 | vendorVariant := "android_vendor.VER_arm64_armv8-a" |
| 2454 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2455 | ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_apex10000").Rule("ld") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2456 | libs := names(ldRule.Args["libFlags"]) |
| 2457 | // VNDK libs(libvndk/libc++) as they are |
| 2458 | ensureListContains(t, libs, buildDir+"/.intermediates/libvndk/"+vendorVariant+"_shared/libvndk.so") |
| 2459 | ensureListContains(t, libs, buildDir+"/.intermediates/libc++/"+vendorVariant+"_shared/libc++.so") |
| 2460 | // non-stable Vendor libs as APEX variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2461 | ensureListContains(t, libs, buildDir+"/.intermediates/libvendor/"+vendorVariant+"_shared_apex10000/libvendor.so") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2462 | |
| 2463 | // VNDK libs are not included when use_vndk_as_stable: true |
| 2464 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2465 | "bin/mybin", |
| 2466 | "lib64/libvendor.so", |
| 2467 | }) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2468 | |
| 2469 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2470 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2471 | ensureListContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2472 | } |
| 2473 | |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2474 | func TestApex_withPrebuiltFirmware(t *testing.T) { |
| 2475 | testCases := []struct { |
| 2476 | name string |
| 2477 | additionalProp string |
| 2478 | }{ |
| 2479 | {"system apex with prebuilt_firmware", ""}, |
| 2480 | {"vendor apex with prebuilt_firmware", "vendor: true,"}, |
| 2481 | } |
| 2482 | for _, tc := range testCases { |
| 2483 | t.Run(tc.name, func(t *testing.T) { |
| 2484 | ctx, _ := testApex(t, ` |
| 2485 | apex { |
| 2486 | name: "myapex", |
| 2487 | key: "myapex.key", |
| 2488 | prebuilts: ["myfirmware"], |
| 2489 | `+tc.additionalProp+` |
| 2490 | } |
| 2491 | apex_key { |
| 2492 | name: "myapex.key", |
| 2493 | public_key: "testkey.avbpubkey", |
| 2494 | private_key: "testkey.pem", |
| 2495 | } |
| 2496 | prebuilt_firmware { |
| 2497 | name: "myfirmware", |
| 2498 | src: "myfirmware.bin", |
| 2499 | filename_from_src: true, |
| 2500 | `+tc.additionalProp+` |
| 2501 | } |
| 2502 | `) |
| 2503 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2504 | "etc/firmware/myfirmware.bin", |
| 2505 | }) |
| 2506 | }) |
| 2507 | } |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 2508 | } |
| 2509 | |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2510 | func TestAndroidMk_UseVendorRequired(t *testing.T) { |
| 2511 | ctx, config := testApex(t, ` |
| 2512 | apex { |
| 2513 | name: "myapex", |
| 2514 | key: "myapex.key", |
| 2515 | use_vendor: true, |
| 2516 | native_shared_libs: ["mylib"], |
| 2517 | } |
| 2518 | |
| 2519 | apex_key { |
| 2520 | name: "myapex.key", |
| 2521 | public_key: "testkey.avbpubkey", |
| 2522 | private_key: "testkey.pem", |
| 2523 | } |
| 2524 | |
| 2525 | cc_library { |
| 2526 | name: "mylib", |
| 2527 | vendor_available: true, |
| 2528 | apex_available: ["myapex"], |
| 2529 | } |
| 2530 | `, func(fs map[string][]byte, config android.Config) { |
| 2531 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
| 2532 | }) |
| 2533 | |
| 2534 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2535 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2536 | name := apexBundle.BaseModuleName() |
| 2537 | prefix := "TARGET_" |
| 2538 | var builder strings.Builder |
| 2539 | data.Custom(&builder, name, prefix, "", data) |
| 2540 | androidMk := builder.String() |
| 2541 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc libm libdl\n") |
| 2542 | } |
| 2543 | |
| 2544 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
| 2545 | ctx, config := testApex(t, ` |
| 2546 | apex { |
| 2547 | name: "myapex", |
| 2548 | key: "myapex.key", |
| 2549 | vendor: true, |
| 2550 | native_shared_libs: ["mylib"], |
| 2551 | } |
| 2552 | |
| 2553 | apex_key { |
| 2554 | name: "myapex.key", |
| 2555 | public_key: "testkey.avbpubkey", |
| 2556 | private_key: "testkey.pem", |
| 2557 | } |
| 2558 | |
| 2559 | cc_library { |
| 2560 | name: "mylib", |
| 2561 | vendor_available: true, |
| 2562 | } |
| 2563 | `) |
| 2564 | |
| 2565 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2566 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2567 | name := apexBundle.BaseModuleName() |
| 2568 | prefix := "TARGET_" |
| 2569 | var builder strings.Builder |
| 2570 | data.Custom(&builder, name, prefix, "", data) |
| 2571 | androidMk := builder.String() |
| 2572 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc.vendor libm.vendor libdl.vendor\n") |
| 2573 | } |
| 2574 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2575 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
| 2576 | ctx, config := testApex(t, ` |
| 2577 | apex { |
| 2578 | name: "myapex", |
| 2579 | key: "myapex.key", |
| 2580 | vintf_fragments: ["fragment.xml"], |
| 2581 | init_rc: ["init.rc"], |
| 2582 | } |
| 2583 | apex_key { |
| 2584 | name: "myapex.key", |
| 2585 | public_key: "testkey.avbpubkey", |
| 2586 | private_key: "testkey.pem", |
| 2587 | } |
| 2588 | cc_binary { |
| 2589 | name: "mybin", |
| 2590 | } |
| 2591 | `) |
| 2592 | |
| 2593 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2594 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2595 | name := apexBundle.BaseModuleName() |
| 2596 | prefix := "TARGET_" |
| 2597 | var builder strings.Builder |
| 2598 | data.Custom(&builder, name, prefix, "", data) |
| 2599 | androidMk := builder.String() |
| 2600 | ensureContains(t, androidMk, "LOCAL_VINTF_FRAGMENTS := fragment.xml\n") |
| 2601 | ensureContains(t, androidMk, "LOCAL_INIT_RC := init.rc\n") |
| 2602 | } |
| 2603 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2604 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2605 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2606 | apex { |
| 2607 | name: "myapex", |
| 2608 | key: "myapex.key", |
| 2609 | native_shared_libs: ["mylib"], |
| 2610 | } |
| 2611 | |
| 2612 | apex_key { |
| 2613 | name: "myapex.key", |
| 2614 | public_key: "testkey.avbpubkey", |
| 2615 | private_key: "testkey.pem", |
| 2616 | } |
| 2617 | |
| 2618 | cc_library { |
| 2619 | name: "mylib", |
| 2620 | srcs: ["mylib.cpp"], |
| 2621 | system_shared_libs: [], |
| 2622 | stl: "none", |
| 2623 | stubs: { |
| 2624 | versions: ["1", "2", "3"], |
| 2625 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2626 | apex_available: [ |
| 2627 | "//apex_available:platform", |
| 2628 | "myapex", |
| 2629 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | cc_binary { |
| 2633 | name: "not_in_apex", |
| 2634 | srcs: ["mylib.cpp"], |
| 2635 | static_libs: ["mylib"], |
| 2636 | static_executable: true, |
| 2637 | system_shared_libs: [], |
| 2638 | stl: "none", |
| 2639 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2640 | `) |
| 2641 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2642 | 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] | 2643 | |
| 2644 | // 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] | 2645 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2646 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2647 | |
| 2648 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2649 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2650 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2651 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2652 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2653 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2654 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2655 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | cc_library { |
| 2659 | name: "mylib", |
| 2660 | srcs: ["mylib.cpp"], |
| 2661 | system_shared_libs: [], |
| 2662 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2663 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | apex_key { |
| 2667 | name: "myapex.key", |
| 2668 | public_key: "testkey.avbpubkey", |
| 2669 | private_key: "testkey.pem", |
| 2670 | } |
| 2671 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2672 | android_app_certificate { |
| 2673 | name: "myapex.certificate", |
| 2674 | certificate: "testkey", |
| 2675 | } |
| 2676 | |
| 2677 | android_app_certificate { |
| 2678 | name: "myapex.certificate.override", |
| 2679 | certificate: "testkey.override", |
| 2680 | } |
| 2681 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2682 | `) |
| 2683 | |
| 2684 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2685 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2686 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2687 | if keys.publicKeyFile.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 2688 | t.Errorf("public key %q is not %q", keys.publicKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2689 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 2690 | } |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2691 | if keys.privateKeyFile.String() != "vendor/foo/devkeys/testkey.pem" { |
| 2692 | t.Errorf("private key %q is not %q", keys.privateKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2693 | "vendor/foo/devkeys/testkey.pem") |
| 2694 | } |
| 2695 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2696 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2697 | 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] | 2698 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2699 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2700 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2701 | } |
| 2702 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2703 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2704 | func TestCertificate(t *testing.T) { |
| 2705 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 2706 | ctx, _ := testApex(t, ` |
| 2707 | apex { |
| 2708 | name: "myapex", |
| 2709 | key: "myapex.key", |
| 2710 | } |
| 2711 | apex_key { |
| 2712 | name: "myapex.key", |
| 2713 | public_key: "testkey.avbpubkey", |
| 2714 | private_key: "testkey.pem", |
| 2715 | }`) |
| 2716 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2717 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 2718 | if actual := rule.Args["certificates"]; actual != expected { |
| 2719 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2720 | } |
| 2721 | }) |
| 2722 | t.Run("override when unspecified", func(t *testing.T) { |
| 2723 | ctx, _ := testApex(t, ` |
| 2724 | apex { |
| 2725 | name: "myapex_keytest", |
| 2726 | key: "myapex.key", |
| 2727 | file_contexts: ":myapex-file_contexts", |
| 2728 | } |
| 2729 | apex_key { |
| 2730 | name: "myapex.key", |
| 2731 | public_key: "testkey.avbpubkey", |
| 2732 | private_key: "testkey.pem", |
| 2733 | } |
| 2734 | android_app_certificate { |
| 2735 | name: "myapex.certificate.override", |
| 2736 | certificate: "testkey.override", |
| 2737 | }`) |
| 2738 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2739 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2740 | if actual := rule.Args["certificates"]; actual != expected { |
| 2741 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2742 | } |
| 2743 | }) |
| 2744 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 2745 | ctx, _ := testApex(t, ` |
| 2746 | apex { |
| 2747 | name: "myapex", |
| 2748 | key: "myapex.key", |
| 2749 | certificate: ":myapex.certificate", |
| 2750 | } |
| 2751 | apex_key { |
| 2752 | name: "myapex.key", |
| 2753 | public_key: "testkey.avbpubkey", |
| 2754 | private_key: "testkey.pem", |
| 2755 | } |
| 2756 | android_app_certificate { |
| 2757 | name: "myapex.certificate", |
| 2758 | certificate: "testkey", |
| 2759 | }`) |
| 2760 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2761 | expected := "testkey.x509.pem testkey.pk8" |
| 2762 | if actual := rule.Args["certificates"]; actual != expected { |
| 2763 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2764 | } |
| 2765 | }) |
| 2766 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 2767 | ctx, _ := testApex(t, ` |
| 2768 | apex { |
| 2769 | name: "myapex_keytest", |
| 2770 | key: "myapex.key", |
| 2771 | file_contexts: ":myapex-file_contexts", |
| 2772 | certificate: ":myapex.certificate", |
| 2773 | } |
| 2774 | apex_key { |
| 2775 | name: "myapex.key", |
| 2776 | public_key: "testkey.avbpubkey", |
| 2777 | private_key: "testkey.pem", |
| 2778 | } |
| 2779 | android_app_certificate { |
| 2780 | name: "myapex.certificate.override", |
| 2781 | certificate: "testkey.override", |
| 2782 | }`) |
| 2783 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2784 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2785 | if actual := rule.Args["certificates"]; actual != expected { |
| 2786 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2787 | } |
| 2788 | }) |
| 2789 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 2790 | ctx, _ := testApex(t, ` |
| 2791 | apex { |
| 2792 | name: "myapex", |
| 2793 | key: "myapex.key", |
| 2794 | certificate: "testkey", |
| 2795 | } |
| 2796 | apex_key { |
| 2797 | name: "myapex.key", |
| 2798 | public_key: "testkey.avbpubkey", |
| 2799 | private_key: "testkey.pem", |
| 2800 | }`) |
| 2801 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2802 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 2803 | if actual := rule.Args["certificates"]; actual != expected { |
| 2804 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2805 | } |
| 2806 | }) |
| 2807 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 2808 | ctx, _ := testApex(t, ` |
| 2809 | apex { |
| 2810 | name: "myapex_keytest", |
| 2811 | key: "myapex.key", |
| 2812 | file_contexts: ":myapex-file_contexts", |
| 2813 | certificate: "testkey", |
| 2814 | } |
| 2815 | apex_key { |
| 2816 | name: "myapex.key", |
| 2817 | public_key: "testkey.avbpubkey", |
| 2818 | private_key: "testkey.pem", |
| 2819 | } |
| 2820 | android_app_certificate { |
| 2821 | name: "myapex.certificate.override", |
| 2822 | certificate: "testkey.override", |
| 2823 | }`) |
| 2824 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2825 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2826 | if actual := rule.Args["certificates"]; actual != expected { |
| 2827 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2828 | } |
| 2829 | }) |
| 2830 | } |
| 2831 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2832 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2833 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2834 | apex { |
| 2835 | name: "myapex", |
| 2836 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2837 | native_shared_libs: ["mylib", "mylib2"], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | apex { |
| 2841 | name: "otherapex", |
| 2842 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2843 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2844 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | apex_key { |
| 2848 | name: "myapex.key", |
| 2849 | public_key: "testkey.avbpubkey", |
| 2850 | private_key: "testkey.pem", |
| 2851 | } |
| 2852 | |
| 2853 | cc_library { |
| 2854 | name: "mylib", |
| 2855 | srcs: ["mylib.cpp"], |
| 2856 | system_shared_libs: [], |
| 2857 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2858 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2859 | "myapex", |
| 2860 | "otherapex", |
| 2861 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2862 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2863 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2864 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2865 | cc_library { |
| 2866 | name: "mylib2", |
| 2867 | srcs: ["mylib.cpp"], |
| 2868 | system_shared_libs: [], |
| 2869 | stl: "none", |
| 2870 | apex_available: [ |
| 2871 | "myapex", |
| 2872 | "otherapex", |
| 2873 | ], |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2874 | static_libs: ["mylib3"], |
| 2875 | recovery_available: true, |
| 2876 | min_sdk_version: "29", |
| 2877 | } |
| 2878 | cc_library { |
| 2879 | name: "mylib3", |
| 2880 | srcs: ["mylib.cpp"], |
| 2881 | system_shared_libs: [], |
| 2882 | stl: "none", |
| 2883 | apex_available: [ |
| 2884 | "myapex", |
| 2885 | "otherapex", |
| 2886 | ], |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2887 | use_apex_name_macro: true, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2888 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2889 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2890 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2891 | `) |
| 2892 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2893 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2894 | 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] | 2895 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 2896 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2897 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2898 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2899 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2900 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 2901 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2902 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2903 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2904 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2905 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex29").Rule("cc").Args["cFlags"] |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2906 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 2907 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2908 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2909 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2910 | // When a cc_library sets use_apex_name_macro: true each apex gets a unique variant and |
| 2911 | // each variant defines additional macros to distinguish which apex variant it is built for |
| 2912 | |
| 2913 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 2914 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 2915 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2916 | |
| 2917 | // APEX variant has __ANDROID_APEX__ defined |
| 2918 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 2919 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2920 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 2921 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 2922 | |
| 2923 | // APEX variant has __ANDROID_APEX__ defined |
| 2924 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 2925 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2926 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 2927 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 2928 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 2929 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2930 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 2931 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 2932 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2933 | |
| 2934 | // When a dependency of a cc_library sets use_apex_name_macro: true each apex gets a unique |
| 2935 | // variant. |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2936 | |
| 2937 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 2938 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 2939 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2940 | |
| 2941 | // APEX variant has __ANDROID_APEX__ defined |
| 2942 | 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] | 2943 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2944 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2945 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2946 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2947 | // APEX variant has __ANDROID_APEX__ defined |
| 2948 | 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] | 2949 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2950 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2951 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2952 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 2953 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2954 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2955 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 2956 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2957 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2958 | |
| 2959 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2960 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2961 | apex { |
| 2962 | name: "myapex", |
| 2963 | key: "myapex.key", |
| 2964 | native_shared_libs: ["mylib"], |
| 2965 | } |
| 2966 | |
| 2967 | apex_key { |
| 2968 | name: "myapex.key", |
| 2969 | public_key: "testkey.avbpubkey", |
| 2970 | private_key: "testkey.pem", |
| 2971 | } |
| 2972 | |
| 2973 | cc_library_headers { |
| 2974 | name: "mylib_headers", |
| 2975 | export_include_dirs: ["my_include"], |
| 2976 | system_shared_libs: [], |
| 2977 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2978 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | cc_library { |
| 2982 | name: "mylib", |
| 2983 | srcs: ["mylib.cpp"], |
| 2984 | system_shared_libs: [], |
| 2985 | stl: "none", |
| 2986 | header_libs: ["mylib_headers"], |
| 2987 | export_header_lib_headers: ["mylib_headers"], |
| 2988 | stubs: { |
| 2989 | versions: ["1", "2", "3"], |
| 2990 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2991 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | cc_library { |
| 2995 | name: "otherlib", |
| 2996 | srcs: ["mylib.cpp"], |
| 2997 | system_shared_libs: [], |
| 2998 | stl: "none", |
| 2999 | shared_libs: ["mylib"], |
| 3000 | } |
| 3001 | `) |
| 3002 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3003 | 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] | 3004 | |
| 3005 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 3006 | ensureContains(t, cFlags, "-Imy_include") |
| 3007 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3008 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3009 | type fileInApex struct { |
| 3010 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3011 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3012 | isLink bool |
| 3013 | } |
| 3014 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3015 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3016 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3017 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3018 | copyCmds := apexRule.Args["copy_commands"] |
| 3019 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3020 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3021 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 3022 | cmd = strings.TrimSpace(cmd) |
| 3023 | if cmd == "" { |
| 3024 | continue |
| 3025 | } |
| 3026 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3027 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3028 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3029 | switch terms[0] { |
| 3030 | case "mkdir": |
| 3031 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3032 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3033 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 3034 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3035 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3036 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3037 | isLink = false |
| 3038 | case "ln": |
| 3039 | if len(terms) != 3 && len(terms) != 4 { |
| 3040 | // ln LINK TARGET or ln -s LINK TARGET |
| 3041 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 3042 | } |
| 3043 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3044 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3045 | isLink = true |
| 3046 | default: |
| 3047 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 3048 | } |
| 3049 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3050 | index := strings.Index(dst, imageApexDir) |
| 3051 | if index == -1 { |
| 3052 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 3053 | } |
| 3054 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3055 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3056 | } |
| 3057 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3058 | return ret |
| 3059 | } |
| 3060 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3061 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 3062 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3063 | var failed bool |
| 3064 | var surplus []string |
| 3065 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3066 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3067 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3068 | for _, expected := range files { |
| 3069 | if matched, _ := path.Match(expected, file.path); matched { |
| 3070 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3071 | mactchFound = true |
| 3072 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3073 | } |
| 3074 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3075 | if !mactchFound { |
| 3076 | surplus = append(surplus, file.path) |
| 3077 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3078 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3079 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3080 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3081 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3082 | t.Log("surplus files", surplus) |
| 3083 | failed = true |
| 3084 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3085 | |
| 3086 | if len(files) > len(filesMatched) { |
| 3087 | var missing []string |
| 3088 | for _, expected := range files { |
| 3089 | if !filesMatched[expected] { |
| 3090 | missing = append(missing, expected) |
| 3091 | } |
| 3092 | } |
| 3093 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3094 | t.Log("missing files", missing) |
| 3095 | failed = true |
| 3096 | } |
| 3097 | if failed { |
| 3098 | t.Fail() |
| 3099 | } |
| 3100 | } |
| 3101 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3102 | func TestVndkApexCurrent(t *testing.T) { |
| 3103 | ctx, _ := testApex(t, ` |
| 3104 | apex_vndk { |
| 3105 | name: "myapex", |
| 3106 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3107 | } |
| 3108 | |
| 3109 | apex_key { |
| 3110 | name: "myapex.key", |
| 3111 | public_key: "testkey.avbpubkey", |
| 3112 | private_key: "testkey.pem", |
| 3113 | } |
| 3114 | |
| 3115 | cc_library { |
| 3116 | name: "libvndk", |
| 3117 | srcs: ["mylib.cpp"], |
| 3118 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3119 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3120 | vndk: { |
| 3121 | enabled: true, |
| 3122 | }, |
| 3123 | system_shared_libs: [], |
| 3124 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3125 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | cc_library { |
| 3129 | name: "libvndksp", |
| 3130 | srcs: ["mylib.cpp"], |
| 3131 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3132 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3133 | vndk: { |
| 3134 | enabled: true, |
| 3135 | support_system_process: true, |
| 3136 | }, |
| 3137 | system_shared_libs: [], |
| 3138 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3139 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3140 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3141 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3142 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3143 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3144 | "lib/libvndk.so", |
| 3145 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3146 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3147 | "lib64/libvndk.so", |
| 3148 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3149 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3150 | "etc/llndk.libraries.VER.txt", |
| 3151 | "etc/vndkcore.libraries.VER.txt", |
| 3152 | "etc/vndksp.libraries.VER.txt", |
| 3153 | "etc/vndkprivate.libraries.VER.txt", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3154 | "etc/vndkproduct.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3155 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 3159 | ctx, _ := testApex(t, ` |
| 3160 | apex_vndk { |
| 3161 | name: "myapex", |
| 3162 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | apex_key { |
| 3166 | name: "myapex.key", |
| 3167 | public_key: "testkey.avbpubkey", |
| 3168 | private_key: "testkey.pem", |
| 3169 | } |
| 3170 | |
| 3171 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3172 | name: "libvndk", |
| 3173 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3174 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3175 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3176 | vndk: { |
| 3177 | enabled: true, |
| 3178 | }, |
| 3179 | system_shared_libs: [], |
| 3180 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3181 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3182 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3183 | |
| 3184 | cc_prebuilt_library_shared { |
| 3185 | name: "libvndk.arm", |
| 3186 | srcs: ["libvndk.arm.so"], |
| 3187 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3188 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3189 | vndk: { |
| 3190 | enabled: true, |
| 3191 | }, |
| 3192 | enabled: false, |
| 3193 | arch: { |
| 3194 | arm: { |
| 3195 | enabled: true, |
| 3196 | }, |
| 3197 | }, |
| 3198 | system_shared_libs: [], |
| 3199 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3200 | apex_available: [ "myapex" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3201 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3202 | `+vndkLibrariesTxtFiles("current"), |
| 3203 | withFiles(map[string][]byte{ |
| 3204 | "libvndk.so": nil, |
| 3205 | "libvndk.arm.so": nil, |
| 3206 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3207 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3208 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3209 | "lib/libvndk.so", |
| 3210 | "lib/libvndk.arm.so", |
| 3211 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3212 | "lib/libc++.so", |
| 3213 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3214 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3215 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3216 | } |
| 3217 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3218 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 3219 | for _, v := range vers { |
| 3220 | if v == "current" { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3221 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3222 | result += ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 3223 | ` + txt + `_libraries_txt { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3224 | name: "` + txt + `.libraries.txt", |
| 3225 | } |
| 3226 | ` |
| 3227 | } |
| 3228 | } else { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3229 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3230 | result += ` |
| 3231 | prebuilt_etc { |
| 3232 | name: "` + txt + `.libraries.` + v + `.txt", |
| 3233 | src: "dummy.txt", |
| 3234 | } |
| 3235 | ` |
| 3236 | } |
| 3237 | } |
| 3238 | } |
| 3239 | return |
| 3240 | } |
| 3241 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3242 | func TestVndkApexVersion(t *testing.T) { |
| 3243 | ctx, _ := testApex(t, ` |
| 3244 | apex_vndk { |
| 3245 | name: "myapex_v27", |
| 3246 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3247 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3248 | vndk_version: "27", |
| 3249 | } |
| 3250 | |
| 3251 | apex_key { |
| 3252 | name: "myapex.key", |
| 3253 | public_key: "testkey.avbpubkey", |
| 3254 | private_key: "testkey.pem", |
| 3255 | } |
| 3256 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3257 | vndk_prebuilt_shared { |
| 3258 | name: "libvndk27", |
| 3259 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3260 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3261 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3262 | vndk: { |
| 3263 | enabled: true, |
| 3264 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3265 | target_arch: "arm64", |
| 3266 | arch: { |
| 3267 | arm: { |
| 3268 | srcs: ["libvndk27_arm.so"], |
| 3269 | }, |
| 3270 | arm64: { |
| 3271 | srcs: ["libvndk27_arm64.so"], |
| 3272 | }, |
| 3273 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3274 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | vndk_prebuilt_shared { |
| 3278 | name: "libvndk27", |
| 3279 | version: "27", |
| 3280 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3281 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3282 | vndk: { |
| 3283 | enabled: true, |
| 3284 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3285 | target_arch: "x86_64", |
| 3286 | arch: { |
| 3287 | x86: { |
| 3288 | srcs: ["libvndk27_x86.so"], |
| 3289 | }, |
| 3290 | x86_64: { |
| 3291 | srcs: ["libvndk27_x86_64.so"], |
| 3292 | }, |
| 3293 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3294 | } |
| 3295 | `+vndkLibrariesTxtFiles("27"), |
| 3296 | withFiles(map[string][]byte{ |
| 3297 | "libvndk27_arm.so": nil, |
| 3298 | "libvndk27_arm64.so": nil, |
| 3299 | "libvndk27_x86.so": nil, |
| 3300 | "libvndk27_x86_64.so": nil, |
| 3301 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3302 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3303 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3304 | "lib/libvndk27_arm.so", |
| 3305 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3306 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3307 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { |
| 3311 | testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, ` |
| 3312 | apex_vndk { |
| 3313 | name: "myapex_v27", |
| 3314 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3315 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3316 | vndk_version: "27", |
| 3317 | } |
| 3318 | apex_vndk { |
| 3319 | name: "myapex_v27_other", |
| 3320 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3321 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3322 | vndk_version: "27", |
| 3323 | } |
| 3324 | |
| 3325 | apex_key { |
| 3326 | name: "myapex.key", |
| 3327 | public_key: "testkey.avbpubkey", |
| 3328 | private_key: "testkey.pem", |
| 3329 | } |
| 3330 | |
| 3331 | cc_library { |
| 3332 | name: "libvndk", |
| 3333 | srcs: ["mylib.cpp"], |
| 3334 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3335 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3336 | vndk: { |
| 3337 | enabled: true, |
| 3338 | }, |
| 3339 | system_shared_libs: [], |
| 3340 | stl: "none", |
| 3341 | } |
| 3342 | |
| 3343 | vndk_prebuilt_shared { |
| 3344 | name: "libvndk", |
| 3345 | version: "27", |
| 3346 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3347 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3348 | vndk: { |
| 3349 | enabled: true, |
| 3350 | }, |
| 3351 | srcs: ["libvndk.so"], |
| 3352 | } |
| 3353 | `, withFiles(map[string][]byte{ |
| 3354 | "libvndk.so": nil, |
| 3355 | })) |
| 3356 | } |
| 3357 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3358 | func TestVndkApexNameRule(t *testing.T) { |
| 3359 | ctx, _ := testApex(t, ` |
| 3360 | apex_vndk { |
| 3361 | name: "myapex", |
| 3362 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3363 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3364 | } |
| 3365 | apex_vndk { |
| 3366 | name: "myapex_v28", |
| 3367 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3368 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3369 | vndk_version: "28", |
| 3370 | } |
| 3371 | apex_key { |
| 3372 | name: "myapex.key", |
| 3373 | public_key: "testkey.avbpubkey", |
| 3374 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3375 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3376 | |
| 3377 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3378 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3379 | actual := proptools.String(bundle.properties.Apex_name) |
| 3380 | if !reflect.DeepEqual(actual, expected) { |
| 3381 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3382 | } |
| 3383 | } |
| 3384 | |
| 3385 | assertApexName("com.android.vndk.vVER", "myapex") |
| 3386 | assertApexName("com.android.vndk.v28", "myapex_v28") |
| 3387 | } |
| 3388 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3389 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 3390 | ctx, _ := testApex(t, ` |
| 3391 | apex_vndk { |
| 3392 | name: "myapex", |
| 3393 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3394 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | apex_key { |
| 3398 | name: "myapex.key", |
| 3399 | public_key: "testkey.avbpubkey", |
| 3400 | private_key: "testkey.pem", |
| 3401 | } |
| 3402 | |
| 3403 | cc_library { |
| 3404 | name: "libvndk", |
| 3405 | srcs: ["mylib.cpp"], |
| 3406 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3407 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3408 | native_bridge_supported: true, |
| 3409 | host_supported: true, |
| 3410 | vndk: { |
| 3411 | enabled: true, |
| 3412 | }, |
| 3413 | system_shared_libs: [], |
| 3414 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3415 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3416 | } |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3417 | `+vndkLibrariesTxtFiles("current"), withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3418 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3419 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3420 | "lib/libvndk.so", |
| 3421 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3422 | "lib/libc++.so", |
| 3423 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3424 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3425 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3426 | } |
| 3427 | |
| 3428 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
| 3429 | testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
| 3430 | apex_vndk { |
| 3431 | name: "myapex", |
| 3432 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3433 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3434 | native_bridge_supported: true, |
| 3435 | } |
| 3436 | |
| 3437 | apex_key { |
| 3438 | name: "myapex.key", |
| 3439 | public_key: "testkey.avbpubkey", |
| 3440 | private_key: "testkey.pem", |
| 3441 | } |
| 3442 | |
| 3443 | cc_library { |
| 3444 | name: "libvndk", |
| 3445 | srcs: ["mylib.cpp"], |
| 3446 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3447 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3448 | native_bridge_supported: true, |
| 3449 | host_supported: true, |
| 3450 | vndk: { |
| 3451 | enabled: true, |
| 3452 | }, |
| 3453 | system_shared_libs: [], |
| 3454 | stl: "none", |
| 3455 | } |
| 3456 | `) |
| 3457 | } |
| 3458 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3459 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3460 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3461 | apex_vndk { |
| 3462 | name: "myapex_v27", |
| 3463 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3464 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3465 | vndk_version: "27", |
| 3466 | } |
| 3467 | |
| 3468 | apex_key { |
| 3469 | name: "myapex.key", |
| 3470 | public_key: "testkey.avbpubkey", |
| 3471 | private_key: "testkey.pem", |
| 3472 | } |
| 3473 | |
| 3474 | vndk_prebuilt_shared { |
| 3475 | name: "libvndk27", |
| 3476 | version: "27", |
| 3477 | target_arch: "arm", |
| 3478 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3479 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3480 | vndk: { |
| 3481 | enabled: true, |
| 3482 | }, |
| 3483 | arch: { |
| 3484 | arm: { |
| 3485 | srcs: ["libvndk27.so"], |
| 3486 | } |
| 3487 | }, |
| 3488 | } |
| 3489 | |
| 3490 | vndk_prebuilt_shared { |
| 3491 | name: "libvndk27", |
| 3492 | version: "27", |
| 3493 | target_arch: "arm", |
| 3494 | binder32bit: true, |
| 3495 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3496 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3497 | vndk: { |
| 3498 | enabled: true, |
| 3499 | }, |
| 3500 | arch: { |
| 3501 | arm: { |
| 3502 | srcs: ["libvndk27binder32.so"], |
| 3503 | } |
| 3504 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3505 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3506 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3507 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3508 | withFiles(map[string][]byte{ |
| 3509 | "libvndk27.so": nil, |
| 3510 | "libvndk27binder32.so": nil, |
| 3511 | }), |
| 3512 | withBinder32bit, |
| 3513 | withTargets(map[android.OsType][]android.Target{ |
| 3514 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3515 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3516 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3517 | }, |
| 3518 | }), |
| 3519 | ) |
| 3520 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3521 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3522 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3523 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3524 | }) |
| 3525 | } |
| 3526 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3527 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
| 3528 | ctx, _ := testApex(t, ` |
| 3529 | apex_vndk { |
| 3530 | name: "myapex", |
| 3531 | key: "myapex.key", |
| 3532 | file_contexts: ":myapex-file_contexts", |
| 3533 | } |
| 3534 | |
| 3535 | apex_key { |
| 3536 | name: "myapex.key", |
| 3537 | public_key: "testkey.avbpubkey", |
| 3538 | private_key: "testkey.pem", |
| 3539 | } |
| 3540 | |
| 3541 | cc_library { |
| 3542 | name: "libz", |
| 3543 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3544 | product_available: true, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3545 | vndk: { |
| 3546 | enabled: true, |
| 3547 | }, |
| 3548 | stubs: { |
| 3549 | symbol_file: "libz.map.txt", |
| 3550 | versions: ["30"], |
| 3551 | } |
| 3552 | } |
| 3553 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3554 | "libz.map.txt": nil, |
| 3555 | })) |
| 3556 | |
| 3557 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_image").Rule("apexManifestRule") |
| 3558 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3559 | ensureListEmpty(t, provideNativeLibs) |
| 3560 | } |
| 3561 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3562 | func TestDependenciesInApexManifest(t *testing.T) { |
| 3563 | ctx, _ := testApex(t, ` |
| 3564 | apex { |
| 3565 | name: "myapex_nodep", |
| 3566 | key: "myapex.key", |
| 3567 | native_shared_libs: ["lib_nodep"], |
| 3568 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3569 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | apex { |
| 3573 | name: "myapex_dep", |
| 3574 | key: "myapex.key", |
| 3575 | native_shared_libs: ["lib_dep"], |
| 3576 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3577 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | apex { |
| 3581 | name: "myapex_provider", |
| 3582 | key: "myapex.key", |
| 3583 | native_shared_libs: ["libfoo"], |
| 3584 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3585 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | apex { |
| 3589 | name: "myapex_selfcontained", |
| 3590 | key: "myapex.key", |
| 3591 | native_shared_libs: ["lib_dep", "libfoo"], |
| 3592 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3593 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | apex_key { |
| 3597 | name: "myapex.key", |
| 3598 | public_key: "testkey.avbpubkey", |
| 3599 | private_key: "testkey.pem", |
| 3600 | } |
| 3601 | |
| 3602 | cc_library { |
| 3603 | name: "lib_nodep", |
| 3604 | srcs: ["mylib.cpp"], |
| 3605 | system_shared_libs: [], |
| 3606 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3607 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | cc_library { |
| 3611 | name: "lib_dep", |
| 3612 | srcs: ["mylib.cpp"], |
| 3613 | shared_libs: ["libfoo"], |
| 3614 | system_shared_libs: [], |
| 3615 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3616 | apex_available: [ |
| 3617 | "myapex_dep", |
| 3618 | "myapex_provider", |
| 3619 | "myapex_selfcontained", |
| 3620 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | cc_library { |
| 3624 | name: "libfoo", |
| 3625 | srcs: ["mytest.cpp"], |
| 3626 | stubs: { |
| 3627 | versions: ["1"], |
| 3628 | }, |
| 3629 | system_shared_libs: [], |
| 3630 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3631 | apex_available: [ |
| 3632 | "myapex_provider", |
| 3633 | "myapex_selfcontained", |
| 3634 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3635 | } |
| 3636 | `) |
| 3637 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3638 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3639 | var provideNativeLibs, requireNativeLibs []string |
| 3640 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3641 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3642 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3643 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3644 | ensureListEmpty(t, provideNativeLibs) |
| 3645 | ensureListEmpty(t, requireNativeLibs) |
| 3646 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3647 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3648 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3649 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3650 | ensureListEmpty(t, provideNativeLibs) |
| 3651 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 3652 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3653 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3654 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3655 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3656 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3657 | ensureListEmpty(t, requireNativeLibs) |
| 3658 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3659 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3660 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3661 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3662 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3663 | ensureListEmpty(t, requireNativeLibs) |
| 3664 | } |
| 3665 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3666 | func TestApexName(t *testing.T) { |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3667 | ctx, config := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3668 | apex { |
| 3669 | name: "myapex", |
| 3670 | key: "myapex.key", |
| 3671 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3672 | native_shared_libs: ["mylib"], |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | apex_key { |
| 3676 | name: "myapex.key", |
| 3677 | public_key: "testkey.avbpubkey", |
| 3678 | private_key: "testkey.pem", |
| 3679 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3680 | |
| 3681 | cc_library { |
| 3682 | name: "mylib", |
| 3683 | srcs: ["mylib.cpp"], |
| 3684 | system_shared_libs: [], |
| 3685 | stl: "none", |
| 3686 | apex_available: [ |
| 3687 | "//apex_available:platform", |
| 3688 | "myapex", |
| 3689 | ], |
| 3690 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3691 | `) |
| 3692 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3693 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3694 | apexManifestRule := module.Rule("apexManifestRule") |
| 3695 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 3696 | apexRule := module.Rule("apexRule") |
| 3697 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3698 | |
| 3699 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3700 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3701 | name := apexBundle.BaseModuleName() |
| 3702 | prefix := "TARGET_" |
| 3703 | var builder strings.Builder |
| 3704 | data.Custom(&builder, name, prefix, "", data) |
| 3705 | androidMk := builder.String() |
| 3706 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 3707 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3708 | } |
| 3709 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3710 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3711 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3712 | apex { |
| 3713 | name: "myapex", |
| 3714 | key: "myapex.key", |
| 3715 | native_shared_libs: ["mylib_common"], |
| 3716 | } |
| 3717 | |
| 3718 | apex_key { |
| 3719 | name: "myapex.key", |
| 3720 | public_key: "testkey.avbpubkey", |
| 3721 | private_key: "testkey.pem", |
| 3722 | } |
| 3723 | |
| 3724 | cc_library { |
| 3725 | name: "mylib_common", |
| 3726 | srcs: ["mylib.cpp"], |
| 3727 | system_shared_libs: [], |
| 3728 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3729 | apex_available: [ |
| 3730 | "//apex_available:platform", |
| 3731 | "myapex", |
| 3732 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3733 | } |
| 3734 | `) |
| 3735 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3736 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3737 | apexRule := module.Rule("apexRule") |
| 3738 | copyCmds := apexRule.Args["copy_commands"] |
| 3739 | |
| 3740 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 3741 | t.Log("Apex was a test apex!") |
| 3742 | t.Fail() |
| 3743 | } |
| 3744 | // Ensure that main rule creates an output |
| 3745 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3746 | |
| 3747 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3748 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3749 | |
| 3750 | // Ensure that both direct and indirect deps are copied into apex |
| 3751 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3752 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3753 | // Ensure that the platform variant ends with _shared |
| 3754 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3755 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3756 | if !ctx.ModuleForTests("mylib_common", "android_arm64_armv8-a_shared_apex10000").Module().(*cc.Module).InAnyApex() { |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3757 | t.Log("Found mylib_common not in any apex!") |
| 3758 | t.Fail() |
| 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | func TestTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3763 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3764 | apex_test { |
| 3765 | name: "myapex", |
| 3766 | key: "myapex.key", |
| 3767 | native_shared_libs: ["mylib_common_test"], |
| 3768 | } |
| 3769 | |
| 3770 | apex_key { |
| 3771 | name: "myapex.key", |
| 3772 | public_key: "testkey.avbpubkey", |
| 3773 | private_key: "testkey.pem", |
| 3774 | } |
| 3775 | |
| 3776 | cc_library { |
| 3777 | name: "mylib_common_test", |
| 3778 | srcs: ["mylib.cpp"], |
| 3779 | system_shared_libs: [], |
| 3780 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3781 | // TODO: remove //apex_available:platform |
| 3782 | apex_available: [ |
| 3783 | "//apex_available:platform", |
| 3784 | "myapex", |
| 3785 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3786 | } |
| 3787 | `) |
| 3788 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3789 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3790 | apexRule := module.Rule("apexRule") |
| 3791 | copyCmds := apexRule.Args["copy_commands"] |
| 3792 | |
| 3793 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 3794 | t.Log("Apex was not a test apex!") |
| 3795 | t.Fail() |
| 3796 | } |
| 3797 | // Ensure that main rule creates an output |
| 3798 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3799 | |
| 3800 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3801 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3802 | |
| 3803 | // Ensure that both direct and indirect deps are copied into apex |
| 3804 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 3805 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3806 | // Ensure that the platform variant ends with _shared |
| 3807 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3808 | } |
| 3809 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3810 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3811 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3812 | apex { |
| 3813 | name: "myapex", |
| 3814 | key: "myapex.key", |
| 3815 | multilib: { |
| 3816 | first: { |
| 3817 | native_shared_libs: ["mylib_common"], |
| 3818 | } |
| 3819 | }, |
| 3820 | target: { |
| 3821 | android: { |
| 3822 | multilib: { |
| 3823 | first: { |
| 3824 | native_shared_libs: ["mylib"], |
| 3825 | } |
| 3826 | } |
| 3827 | }, |
| 3828 | host: { |
| 3829 | multilib: { |
| 3830 | first: { |
| 3831 | native_shared_libs: ["mylib2"], |
| 3832 | } |
| 3833 | } |
| 3834 | } |
| 3835 | } |
| 3836 | } |
| 3837 | |
| 3838 | apex_key { |
| 3839 | name: "myapex.key", |
| 3840 | public_key: "testkey.avbpubkey", |
| 3841 | private_key: "testkey.pem", |
| 3842 | } |
| 3843 | |
| 3844 | cc_library { |
| 3845 | name: "mylib", |
| 3846 | srcs: ["mylib.cpp"], |
| 3847 | system_shared_libs: [], |
| 3848 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3849 | // TODO: remove //apex_available:platform |
| 3850 | apex_available: [ |
| 3851 | "//apex_available:platform", |
| 3852 | "myapex", |
| 3853 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3854 | } |
| 3855 | |
| 3856 | cc_library { |
| 3857 | name: "mylib_common", |
| 3858 | srcs: ["mylib.cpp"], |
| 3859 | system_shared_libs: [], |
| 3860 | stl: "none", |
| 3861 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3862 | // TODO: remove //apex_available:platform |
| 3863 | apex_available: [ |
| 3864 | "//apex_available:platform", |
| 3865 | "myapex", |
| 3866 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | cc_library { |
| 3870 | name: "mylib2", |
| 3871 | srcs: ["mylib.cpp"], |
| 3872 | system_shared_libs: [], |
| 3873 | stl: "none", |
| 3874 | compile_multilib: "first", |
| 3875 | } |
| 3876 | `) |
| 3877 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3878 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3879 | copyCmds := apexRule.Args["copy_commands"] |
| 3880 | |
| 3881 | // Ensure that main rule creates an output |
| 3882 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3883 | |
| 3884 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3885 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 3886 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
| 3887 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3888 | |
| 3889 | // Ensure that both direct and indirect deps are copied into apex |
| 3890 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 3891 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3892 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 3893 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3894 | // Ensure that the platform variant ends with _shared |
| 3895 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 3896 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 3897 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3898 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3899 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 3900 | func TestApexWithArch(t *testing.T) { |
| 3901 | ctx, _ := testApex(t, ` |
| 3902 | apex { |
| 3903 | name: "myapex", |
| 3904 | key: "myapex.key", |
| 3905 | arch: { |
| 3906 | arm64: { |
| 3907 | native_shared_libs: ["mylib.arm64"], |
| 3908 | }, |
| 3909 | x86_64: { |
| 3910 | native_shared_libs: ["mylib.x64"], |
| 3911 | }, |
| 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | apex_key { |
| 3916 | name: "myapex.key", |
| 3917 | public_key: "testkey.avbpubkey", |
| 3918 | private_key: "testkey.pem", |
| 3919 | } |
| 3920 | |
| 3921 | cc_library { |
| 3922 | name: "mylib.arm64", |
| 3923 | srcs: ["mylib.cpp"], |
| 3924 | system_shared_libs: [], |
| 3925 | stl: "none", |
| 3926 | // TODO: remove //apex_available:platform |
| 3927 | apex_available: [ |
| 3928 | "//apex_available:platform", |
| 3929 | "myapex", |
| 3930 | ], |
| 3931 | } |
| 3932 | |
| 3933 | cc_library { |
| 3934 | name: "mylib.x64", |
| 3935 | srcs: ["mylib.cpp"], |
| 3936 | system_shared_libs: [], |
| 3937 | stl: "none", |
| 3938 | // TODO: remove //apex_available:platform |
| 3939 | apex_available: [ |
| 3940 | "//apex_available:platform", |
| 3941 | "myapex", |
| 3942 | ], |
| 3943 | } |
| 3944 | `) |
| 3945 | |
| 3946 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 3947 | copyCmds := apexRule.Args["copy_commands"] |
| 3948 | |
| 3949 | // Ensure that apex variant is created for the direct dep |
| 3950 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib.arm64"), "android_arm64_armv8-a_shared_apex10000") |
| 3951 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib.x64"), "android_arm64_armv8-a_shared_apex10000") |
| 3952 | |
| 3953 | // Ensure that both direct and indirect deps are copied into apex |
| 3954 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.arm64.so") |
| 3955 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib.x64.so") |
| 3956 | } |
| 3957 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3958 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3959 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3960 | apex { |
| 3961 | name: "myapex", |
| 3962 | key: "myapex.key", |
| 3963 | binaries: ["myscript"], |
| 3964 | } |
| 3965 | |
| 3966 | apex_key { |
| 3967 | name: "myapex.key", |
| 3968 | public_key: "testkey.avbpubkey", |
| 3969 | private_key: "testkey.pem", |
| 3970 | } |
| 3971 | |
| 3972 | sh_binary { |
| 3973 | name: "myscript", |
| 3974 | src: "mylib.cpp", |
| 3975 | filename: "myscript.sh", |
| 3976 | sub_dir: "script", |
| 3977 | } |
| 3978 | `) |
| 3979 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3980 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3981 | copyCmds := apexRule.Args["copy_commands"] |
| 3982 | |
| 3983 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 3984 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3985 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3986 | func TestApexInVariousPartition(t *testing.T) { |
| 3987 | testcases := []struct { |
| 3988 | propName, parition, flattenedPartition string |
| 3989 | }{ |
| 3990 | {"", "system", "system_ext"}, |
| 3991 | {"product_specific: true", "product", "product"}, |
| 3992 | {"soc_specific: true", "vendor", "vendor"}, |
| 3993 | {"proprietary: true", "vendor", "vendor"}, |
| 3994 | {"vendor: true", "vendor", "vendor"}, |
| 3995 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 3996 | } |
| 3997 | for _, tc := range testcases { |
| 3998 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 3999 | ctx, _ := testApex(t, ` |
| 4000 | apex { |
| 4001 | name: "myapex", |
| 4002 | key: "myapex.key", |
| 4003 | `+tc.propName+` |
| 4004 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4005 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4006 | apex_key { |
| 4007 | name: "myapex.key", |
| 4008 | public_key: "testkey.avbpubkey", |
| 4009 | private_key: "testkey.pem", |
| 4010 | } |
| 4011 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4012 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4013 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 4014 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 4015 | actual := apex.installDir.String() |
| 4016 | if actual != expected { |
| 4017 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4018 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4019 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4020 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 4021 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 4022 | actual = flattened.installDir.String() |
| 4023 | if actual != expected { |
| 4024 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4025 | } |
| 4026 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4027 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4028 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4029 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4030 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4031 | ctx, _ := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4032 | apex { |
| 4033 | name: "myapex", |
| 4034 | key: "myapex.key", |
| 4035 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4036 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4037 | apex_key { |
| 4038 | name: "myapex.key", |
| 4039 | public_key: "testkey.avbpubkey", |
| 4040 | private_key: "testkey.pem", |
| 4041 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4042 | `) |
| 4043 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4044 | rule := module.Output("file_contexts") |
| 4045 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 4046 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4047 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4048 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4049 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4050 | apex { |
| 4051 | name: "myapex", |
| 4052 | key: "myapex.key", |
| 4053 | file_contexts: "my_own_file_contexts", |
| 4054 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4055 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4056 | apex_key { |
| 4057 | name: "myapex.key", |
| 4058 | public_key: "testkey.avbpubkey", |
| 4059 | private_key: "testkey.pem", |
| 4060 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4061 | `, withFiles(map[string][]byte{ |
| 4062 | "my_own_file_contexts": nil, |
| 4063 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4064 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4065 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4066 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4067 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4068 | apex { |
| 4069 | name: "myapex", |
| 4070 | key: "myapex.key", |
| 4071 | product_specific: true, |
| 4072 | file_contexts: "product_specific_file_contexts", |
| 4073 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4074 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4075 | apex_key { |
| 4076 | name: "myapex.key", |
| 4077 | public_key: "testkey.avbpubkey", |
| 4078 | private_key: "testkey.pem", |
| 4079 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4080 | `) |
| 4081 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4082 | ctx, _ := testApex(t, ` |
| 4083 | apex { |
| 4084 | name: "myapex", |
| 4085 | key: "myapex.key", |
| 4086 | product_specific: true, |
| 4087 | file_contexts: "product_specific_file_contexts", |
| 4088 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4089 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4090 | apex_key { |
| 4091 | name: "myapex.key", |
| 4092 | public_key: "testkey.avbpubkey", |
| 4093 | private_key: "testkey.pem", |
| 4094 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4095 | `, withFiles(map[string][]byte{ |
| 4096 | "product_specific_file_contexts": nil, |
| 4097 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4098 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4099 | rule := module.Output("file_contexts") |
| 4100 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 4101 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4102 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4103 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
| 4104 | ctx, _ := testApex(t, ` |
| 4105 | apex { |
| 4106 | name: "myapex", |
| 4107 | key: "myapex.key", |
| 4108 | product_specific: true, |
| 4109 | file_contexts: ":my-file-contexts", |
| 4110 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4111 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4112 | apex_key { |
| 4113 | name: "myapex.key", |
| 4114 | public_key: "testkey.avbpubkey", |
| 4115 | private_key: "testkey.pem", |
| 4116 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4117 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4118 | filegroup { |
| 4119 | name: "my-file-contexts", |
| 4120 | srcs: ["product_specific_file_contexts"], |
| 4121 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4122 | `, withFiles(map[string][]byte{ |
| 4123 | "product_specific_file_contexts": nil, |
| 4124 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4125 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4126 | rule := module.Output("file_contexts") |
| 4127 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4128 | } |
| 4129 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4130 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4131 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4132 | apex_key { |
| 4133 | name: "myapex.key", |
| 4134 | public_key: ":my.avbpubkey", |
| 4135 | private_key: ":my.pem", |
| 4136 | product_specific: true, |
| 4137 | } |
| 4138 | |
| 4139 | filegroup { |
| 4140 | name: "my.avbpubkey", |
| 4141 | srcs: ["testkey2.avbpubkey"], |
| 4142 | } |
| 4143 | |
| 4144 | filegroup { |
| 4145 | name: "my.pem", |
| 4146 | srcs: ["testkey2.pem"], |
| 4147 | } |
| 4148 | `) |
| 4149 | |
| 4150 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 4151 | expected_pubkey := "testkey2.avbpubkey" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4152 | actual_pubkey := apex_key.publicKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4153 | if actual_pubkey != expected_pubkey { |
| 4154 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 4155 | } |
| 4156 | expected_privkey := "testkey2.pem" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4157 | actual_privkey := apex_key.privateKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4158 | if actual_privkey != expected_privkey { |
| 4159 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 4160 | } |
| 4161 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4162 | |
| 4163 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4164 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4165 | prebuilt_apex { |
| 4166 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4167 | arch: { |
| 4168 | arm64: { |
| 4169 | src: "myapex-arm64.apex", |
| 4170 | }, |
| 4171 | arm: { |
| 4172 | src: "myapex-arm.apex", |
| 4173 | }, |
| 4174 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4175 | } |
| 4176 | `) |
| 4177 | |
| 4178 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4179 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4180 | expectedInput := "myapex-arm64.apex" |
| 4181 | if prebuilt.inputApex.String() != expectedInput { |
| 4182 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 4183 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4184 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4185 | |
| 4186 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4187 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4188 | prebuilt_apex { |
| 4189 | name: "myapex", |
| 4190 | src: "myapex-arm.apex", |
| 4191 | filename: "notmyapex.apex", |
| 4192 | } |
| 4193 | `) |
| 4194 | |
| 4195 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4196 | |
| 4197 | expected := "notmyapex.apex" |
| 4198 | if p.installFilename != expected { |
| 4199 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 4200 | } |
| 4201 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4202 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4203 | func TestPrebuiltOverrides(t *testing.T) { |
| 4204 | ctx, config := testApex(t, ` |
| 4205 | prebuilt_apex { |
| 4206 | name: "myapex.prebuilt", |
| 4207 | src: "myapex-arm.apex", |
| 4208 | overrides: [ |
| 4209 | "myapex", |
| 4210 | ], |
| 4211 | } |
| 4212 | `) |
| 4213 | |
| 4214 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 4215 | |
| 4216 | expected := []string{"myapex"} |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 4217 | actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4218 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 4219 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4220 | } |
| 4221 | } |
| 4222 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4223 | func TestPrebuiltExportDexImplementationJars(t *testing.T) { |
| 4224 | transform := func(config *dexpreopt.GlobalConfig) { |
| 4225 | config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo"}) |
| 4226 | } |
| 4227 | |
| 4228 | checkDexJarBuildPath := func(ctx *android.TestContext, name string) { |
| 4229 | // Make sure the import has been given the correct path to the dex jar. |
| 4230 | p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.Dependency) |
| 4231 | dexJarBuildPath := p.DexJarBuildPath() |
| 4232 | if expected, actual := ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar", android.NormalizePathForTesting(dexJarBuildPath); actual != expected { |
| 4233 | t.Errorf("Incorrect DexJarBuildPath value '%s', expected '%s'", actual, expected) |
| 4234 | } |
| 4235 | } |
| 4236 | |
| 4237 | ensureNoSourceVariant := func(ctx *android.TestContext) { |
| 4238 | // Make sure that an apex variant is not created for the source module. |
| 4239 | if expected, actual := []string{"android_common"}, ctx.ModuleVariantsForTests("libfoo"); !reflect.DeepEqual(expected, actual) { |
| 4240 | t.Errorf("invalid set of variants for %q: expected %q, found %q", "libfoo", expected, actual) |
| 4241 | } |
| 4242 | } |
| 4243 | |
| 4244 | t.Run("prebuilt only", func(t *testing.T) { |
| 4245 | bp := ` |
| 4246 | prebuilt_apex { |
| 4247 | name: "myapex", |
| 4248 | arch: { |
| 4249 | arm64: { |
| 4250 | src: "myapex-arm64.apex", |
| 4251 | }, |
| 4252 | arm: { |
| 4253 | src: "myapex-arm.apex", |
| 4254 | }, |
| 4255 | }, |
| 4256 | exported_java_libs: ["libfoo"], |
| 4257 | } |
| 4258 | |
| 4259 | java_import { |
| 4260 | name: "libfoo", |
| 4261 | jars: ["libfoo.jar"], |
| 4262 | } |
| 4263 | ` |
| 4264 | |
| 4265 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4266 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4267 | |
| 4268 | checkDexJarBuildPath(ctx, "libfoo") |
| 4269 | }) |
| 4270 | |
| 4271 | t.Run("prebuilt with source preferred", func(t *testing.T) { |
| 4272 | |
| 4273 | bp := ` |
| 4274 | prebuilt_apex { |
| 4275 | name: "myapex", |
| 4276 | arch: { |
| 4277 | arm64: { |
| 4278 | src: "myapex-arm64.apex", |
| 4279 | }, |
| 4280 | arm: { |
| 4281 | src: "myapex-arm.apex", |
| 4282 | }, |
| 4283 | }, |
| 4284 | exported_java_libs: ["libfoo"], |
| 4285 | } |
| 4286 | |
| 4287 | java_import { |
| 4288 | name: "libfoo", |
| 4289 | jars: ["libfoo.jar"], |
| 4290 | } |
| 4291 | |
| 4292 | java_library { |
| 4293 | name: "libfoo", |
| 4294 | } |
| 4295 | ` |
| 4296 | |
| 4297 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4298 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4299 | |
| 4300 | checkDexJarBuildPath(ctx, "prebuilt_libfoo") |
| 4301 | ensureNoSourceVariant(ctx) |
| 4302 | }) |
| 4303 | |
| 4304 | t.Run("prebuilt preferred with source", func(t *testing.T) { |
| 4305 | bp := ` |
| 4306 | prebuilt_apex { |
| 4307 | name: "myapex", |
| 4308 | prefer: true, |
| 4309 | arch: { |
| 4310 | arm64: { |
| 4311 | src: "myapex-arm64.apex", |
| 4312 | }, |
| 4313 | arm: { |
| 4314 | src: "myapex-arm.apex", |
| 4315 | }, |
| 4316 | }, |
| 4317 | exported_java_libs: ["libfoo"], |
| 4318 | } |
| 4319 | |
| 4320 | java_import { |
| 4321 | name: "libfoo", |
| 4322 | jars: ["libfoo.jar"], |
| 4323 | } |
| 4324 | |
| 4325 | java_library { |
| 4326 | name: "libfoo", |
| 4327 | } |
| 4328 | ` |
| 4329 | |
| 4330 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4331 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4332 | |
| 4333 | checkDexJarBuildPath(ctx, "prebuilt_libfoo") |
| 4334 | ensureNoSourceVariant(ctx) |
| 4335 | }) |
| 4336 | } |
| 4337 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4338 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4339 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4340 | apex_test { |
| 4341 | name: "myapex", |
| 4342 | key: "myapex.key", |
| 4343 | tests: [ |
| 4344 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4345 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4346 | ], |
| 4347 | } |
| 4348 | |
| 4349 | apex_key { |
| 4350 | name: "myapex.key", |
| 4351 | public_key: "testkey.avbpubkey", |
| 4352 | private_key: "testkey.pem", |
| 4353 | } |
| 4354 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4355 | filegroup { |
| 4356 | name: "fg", |
| 4357 | srcs: [ |
| 4358 | "baz", |
| 4359 | "bar/baz" |
| 4360 | ], |
| 4361 | } |
| 4362 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4363 | cc_test { |
| 4364 | name: "mytest", |
| 4365 | gtest: false, |
| 4366 | srcs: ["mytest.cpp"], |
| 4367 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4368 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4369 | system_shared_libs: [], |
| 4370 | static_executable: true, |
| 4371 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4372 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4373 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4374 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4375 | cc_library { |
| 4376 | name: "mylib", |
| 4377 | srcs: ["mylib.cpp"], |
| 4378 | system_shared_libs: [], |
| 4379 | stl: "none", |
| 4380 | } |
| 4381 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4382 | filegroup { |
| 4383 | name: "fg2", |
| 4384 | srcs: [ |
| 4385 | "testdata/baz" |
| 4386 | ], |
| 4387 | } |
| 4388 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4389 | cc_test { |
| 4390 | name: "mytests", |
| 4391 | gtest: false, |
| 4392 | srcs: [ |
| 4393 | "mytest1.cpp", |
| 4394 | "mytest2.cpp", |
| 4395 | "mytest3.cpp", |
| 4396 | ], |
| 4397 | test_per_src: true, |
| 4398 | relative_install_path: "test", |
| 4399 | system_shared_libs: [], |
| 4400 | static_executable: true, |
| 4401 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4402 | data: [ |
| 4403 | ":fg", |
| 4404 | ":fg2", |
| 4405 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4406 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4407 | `) |
| 4408 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4409 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4410 | copyCmds := apexRule.Args["copy_commands"] |
| 4411 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4412 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4413 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4414 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4415 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4416 | //Ensure that test data are copied into apex. |
| 4417 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 4418 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 4419 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4420 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 4421 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 4422 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 4423 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4424 | |
| 4425 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4426 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 4427 | data := android.AndroidMkDataForTest(t, config, "", bundle) |
| 4428 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4429 | prefix := "TARGET_" |
| 4430 | var builder strings.Builder |
| 4431 | data.Custom(&builder, name, prefix, "", data) |
| 4432 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4433 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 4434 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 4435 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 4436 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4437 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4438 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4439 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4440 | |
| 4441 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 4442 | data = android.AndroidMkDataForTest(t, config, "", flatBundle) |
| 4443 | data.Custom(&builder, name, prefix, "", data) |
| 4444 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4445 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 4446 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4447 | } |
| 4448 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4449 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
| 4450 | ctx, config := testApex(t, ` |
| 4451 | apex { |
| 4452 | name: "myapex", |
| 4453 | key: "myapex.key", |
| 4454 | } |
| 4455 | apex_key { |
| 4456 | name: "myapex.key", |
| 4457 | public_key: "testkey.avbpubkey", |
| 4458 | private_key: "testkey.pem", |
| 4459 | } |
| 4460 | `, func(fs map[string][]byte, config android.Config) { |
| 4461 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 4462 | }) |
| 4463 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 4464 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4465 | mk := android.AndroidMkDataForTest(t, config, "", ab) |
| 4466 | var builder strings.Builder |
| 4467 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 4468 | androidMk := builder.String() |
| 4469 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 4470 | } |
| 4471 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4472 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 4473 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 4474 | apex { |
| 4475 | name: "myapex", |
| 4476 | key: "myapex.key", |
| 4477 | native_shared_libs: ["libfoo"], |
| 4478 | } |
| 4479 | |
| 4480 | apex_key { |
| 4481 | name: "myapex.key", |
| 4482 | public_key: "testkey.avbpubkey", |
| 4483 | private_key: "testkey.pem", |
| 4484 | } |
| 4485 | |
| 4486 | cc_library { |
| 4487 | name: "libfoo", |
| 4488 | stl: "none", |
| 4489 | system_shared_libs: [], |
| 4490 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4491 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4492 | } |
| 4493 | `) |
| 4494 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 4495 | apex { |
| 4496 | name: "myapex", |
| 4497 | key: "myapex.key", |
| 4498 | java_libs: ["myjar"], |
| 4499 | } |
| 4500 | |
| 4501 | apex_key { |
| 4502 | name: "myapex.key", |
| 4503 | public_key: "testkey.avbpubkey", |
| 4504 | private_key: "testkey.pem", |
| 4505 | } |
| 4506 | |
| 4507 | java_library { |
| 4508 | name: "myjar", |
| 4509 | srcs: ["foo/bar/MyClass.java"], |
| 4510 | sdk_version: "none", |
| 4511 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4512 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4513 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4514 | } |
| 4515 | `) |
| 4516 | } |
| 4517 | |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 4518 | func TestApexWithJavaImport(t *testing.T) { |
| 4519 | ctx, _ := testApex(t, ` |
| 4520 | apex { |
| 4521 | name: "myapex", |
| 4522 | key: "myapex.key", |
| 4523 | java_libs: ["myjavaimport"], |
| 4524 | } |
| 4525 | |
| 4526 | apex_key { |
| 4527 | name: "myapex.key", |
| 4528 | public_key: "testkey.avbpubkey", |
| 4529 | private_key: "testkey.pem", |
| 4530 | } |
| 4531 | |
| 4532 | java_import { |
| 4533 | name: "myjavaimport", |
| 4534 | apex_available: ["myapex"], |
| 4535 | jars: ["my.jar"], |
| 4536 | compile_dex: true, |
| 4537 | } |
| 4538 | `) |
| 4539 | |
| 4540 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4541 | apexRule := module.Rule("apexRule") |
| 4542 | copyCmds := apexRule.Args["copy_commands"] |
| 4543 | ensureContains(t, copyCmds, "image.apex/javalib/myjavaimport.jar") |
| 4544 | } |
| 4545 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4546 | func TestApexWithApps(t *testing.T) { |
| 4547 | ctx, _ := testApex(t, ` |
| 4548 | apex { |
| 4549 | name: "myapex", |
| 4550 | key: "myapex.key", |
| 4551 | apps: [ |
| 4552 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4553 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4554 | ], |
| 4555 | } |
| 4556 | |
| 4557 | apex_key { |
| 4558 | name: "myapex.key", |
| 4559 | public_key: "testkey.avbpubkey", |
| 4560 | private_key: "testkey.pem", |
| 4561 | } |
| 4562 | |
| 4563 | android_app { |
| 4564 | name: "AppFoo", |
| 4565 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4566 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4567 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4568 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4569 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4570 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4571 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4572 | |
| 4573 | android_app { |
| 4574 | name: "AppFooPriv", |
| 4575 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4576 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4577 | system_modules: "none", |
| 4578 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4579 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4580 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4581 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4582 | |
| 4583 | cc_library_shared { |
| 4584 | name: "libjni", |
| 4585 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4586 | shared_libs: ["libfoo"], |
| 4587 | stl: "none", |
| 4588 | system_shared_libs: [], |
| 4589 | apex_available: [ "myapex" ], |
| 4590 | sdk_version: "current", |
| 4591 | } |
| 4592 | |
| 4593 | cc_library_shared { |
| 4594 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4595 | stl: "none", |
| 4596 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 4597 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4598 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4599 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4600 | `) |
| 4601 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4602 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4603 | apexRule := module.Rule("apexRule") |
| 4604 | copyCmds := apexRule.Args["copy_commands"] |
| 4605 | |
| 4606 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4607 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4608 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4609 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4610 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4611 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4612 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4613 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4614 | // JNI libraries including transitive deps are |
| 4615 | for _, jni := range []string{"libjni", "libfoo"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4616 | jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_sdk_shared_apex10000").Module().(*cc.Module).OutputFile() |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4617 | // ... embedded inside APK (jnilibs.zip) |
| 4618 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 4619 | // ... and not directly inside the APEX |
| 4620 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 4621 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4622 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4623 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4624 | func TestApexWithAppImports(t *testing.T) { |
| 4625 | ctx, _ := testApex(t, ` |
| 4626 | apex { |
| 4627 | name: "myapex", |
| 4628 | key: "myapex.key", |
| 4629 | apps: [ |
| 4630 | "AppFooPrebuilt", |
| 4631 | "AppFooPrivPrebuilt", |
| 4632 | ], |
| 4633 | } |
| 4634 | |
| 4635 | apex_key { |
| 4636 | name: "myapex.key", |
| 4637 | public_key: "testkey.avbpubkey", |
| 4638 | private_key: "testkey.pem", |
| 4639 | } |
| 4640 | |
| 4641 | android_app_import { |
| 4642 | name: "AppFooPrebuilt", |
| 4643 | apk: "PrebuiltAppFoo.apk", |
| 4644 | presigned: true, |
| 4645 | dex_preopt: { |
| 4646 | enabled: false, |
| 4647 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4648 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | android_app_import { |
| 4652 | name: "AppFooPrivPrebuilt", |
| 4653 | apk: "PrebuiltAppFooPriv.apk", |
| 4654 | privileged: true, |
| 4655 | presigned: true, |
| 4656 | dex_preopt: { |
| 4657 | enabled: false, |
| 4658 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4659 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4660 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4661 | } |
| 4662 | `) |
| 4663 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4664 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4665 | apexRule := module.Rule("apexRule") |
| 4666 | copyCmds := apexRule.Args["copy_commands"] |
| 4667 | |
| 4668 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4669 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 4670 | } |
| 4671 | |
| 4672 | func TestApexWithAppImportsPrefer(t *testing.T) { |
| 4673 | ctx, _ := testApex(t, ` |
| 4674 | apex { |
| 4675 | name: "myapex", |
| 4676 | key: "myapex.key", |
| 4677 | apps: [ |
| 4678 | "AppFoo", |
| 4679 | ], |
| 4680 | } |
| 4681 | |
| 4682 | apex_key { |
| 4683 | name: "myapex.key", |
| 4684 | public_key: "testkey.avbpubkey", |
| 4685 | private_key: "testkey.pem", |
| 4686 | } |
| 4687 | |
| 4688 | android_app { |
| 4689 | name: "AppFoo", |
| 4690 | srcs: ["foo/bar/MyClass.java"], |
| 4691 | sdk_version: "none", |
| 4692 | system_modules: "none", |
| 4693 | apex_available: [ "myapex" ], |
| 4694 | } |
| 4695 | |
| 4696 | android_app_import { |
| 4697 | name: "AppFoo", |
| 4698 | apk: "AppFooPrebuilt.apk", |
| 4699 | filename: "AppFooPrebuilt.apk", |
| 4700 | presigned: true, |
| 4701 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4702 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4703 | } |
| 4704 | `, withFiles(map[string][]byte{ |
| 4705 | "AppFooPrebuilt.apk": nil, |
| 4706 | })) |
| 4707 | |
| 4708 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4709 | "app/AppFoo/AppFooPrebuilt.apk", |
| 4710 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4711 | } |
| 4712 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 4713 | func TestApexWithTestHelperApp(t *testing.T) { |
| 4714 | ctx, _ := testApex(t, ` |
| 4715 | apex { |
| 4716 | name: "myapex", |
| 4717 | key: "myapex.key", |
| 4718 | apps: [ |
| 4719 | "TesterHelpAppFoo", |
| 4720 | ], |
| 4721 | } |
| 4722 | |
| 4723 | apex_key { |
| 4724 | name: "myapex.key", |
| 4725 | public_key: "testkey.avbpubkey", |
| 4726 | private_key: "testkey.pem", |
| 4727 | } |
| 4728 | |
| 4729 | android_test_helper_app { |
| 4730 | name: "TesterHelpAppFoo", |
| 4731 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4732 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | `) |
| 4736 | |
| 4737 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4738 | apexRule := module.Rule("apexRule") |
| 4739 | copyCmds := apexRule.Args["copy_commands"] |
| 4740 | |
| 4741 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 4742 | } |
| 4743 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 4744 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 4745 | // libfoo's apex_available comes from cc_defaults |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 4746 | testApexError(t, `requires "libfoo" that doesn't list the APEX under 'apex_available'.`, ` |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 4747 | apex { |
| 4748 | name: "myapex", |
| 4749 | key: "myapex.key", |
| 4750 | native_shared_libs: ["libfoo"], |
| 4751 | } |
| 4752 | |
| 4753 | apex_key { |
| 4754 | name: "myapex.key", |
| 4755 | public_key: "testkey.avbpubkey", |
| 4756 | private_key: "testkey.pem", |
| 4757 | } |
| 4758 | |
| 4759 | apex { |
| 4760 | name: "otherapex", |
| 4761 | key: "myapex.key", |
| 4762 | native_shared_libs: ["libfoo"], |
| 4763 | } |
| 4764 | |
| 4765 | cc_defaults { |
| 4766 | name: "libfoo-defaults", |
| 4767 | apex_available: ["otherapex"], |
| 4768 | } |
| 4769 | |
| 4770 | cc_library { |
| 4771 | name: "libfoo", |
| 4772 | defaults: ["libfoo-defaults"], |
| 4773 | stl: "none", |
| 4774 | system_shared_libs: [], |
| 4775 | }`) |
| 4776 | } |
| 4777 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4778 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4779 | // libfoo is not available to myapex, but only to otherapex |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 4780 | testApexError(t, "requires \"libfoo\" that doesn't list the APEX under 'apex_available'.", ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4781 | apex { |
| 4782 | name: "myapex", |
| 4783 | key: "myapex.key", |
| 4784 | native_shared_libs: ["libfoo"], |
| 4785 | } |
| 4786 | |
| 4787 | apex_key { |
| 4788 | name: "myapex.key", |
| 4789 | public_key: "testkey.avbpubkey", |
| 4790 | private_key: "testkey.pem", |
| 4791 | } |
| 4792 | |
| 4793 | apex { |
| 4794 | name: "otherapex", |
| 4795 | key: "otherapex.key", |
| 4796 | native_shared_libs: ["libfoo"], |
| 4797 | } |
| 4798 | |
| 4799 | apex_key { |
| 4800 | name: "otherapex.key", |
| 4801 | public_key: "testkey.avbpubkey", |
| 4802 | private_key: "testkey.pem", |
| 4803 | } |
| 4804 | |
| 4805 | cc_library { |
| 4806 | name: "libfoo", |
| 4807 | stl: "none", |
| 4808 | system_shared_libs: [], |
| 4809 | apex_available: ["otherapex"], |
| 4810 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4811 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4812 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4813 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4814 | // libbbaz is an indirect dep |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 4815 | testApexError(t, `requires "libbaz" that doesn't list the APEX under 'apex_available'. Dependency path: |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 4816 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4817 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 4818 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4819 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 4820 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 4821 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4822 | apex { |
| 4823 | name: "myapex", |
| 4824 | key: "myapex.key", |
| 4825 | native_shared_libs: ["libfoo"], |
| 4826 | } |
| 4827 | |
| 4828 | apex_key { |
| 4829 | name: "myapex.key", |
| 4830 | public_key: "testkey.avbpubkey", |
| 4831 | private_key: "testkey.pem", |
| 4832 | } |
| 4833 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4834 | cc_library { |
| 4835 | name: "libfoo", |
| 4836 | stl: "none", |
| 4837 | shared_libs: ["libbar"], |
| 4838 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4839 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | cc_library { |
| 4843 | name: "libbar", |
| 4844 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4845 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4846 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4847 | apex_available: ["myapex"], |
| 4848 | } |
| 4849 | |
| 4850 | cc_library { |
| 4851 | name: "libbaz", |
| 4852 | stl: "none", |
| 4853 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4854 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4855 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4856 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4857 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4858 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 4859 | apex { |
| 4860 | name: "myapex", |
| 4861 | key: "myapex.key", |
| 4862 | native_shared_libs: ["libfoo"], |
| 4863 | } |
| 4864 | |
| 4865 | apex_key { |
| 4866 | name: "myapex.key", |
| 4867 | public_key: "testkey.avbpubkey", |
| 4868 | private_key: "testkey.pem", |
| 4869 | } |
| 4870 | |
| 4871 | cc_library { |
| 4872 | name: "libfoo", |
| 4873 | stl: "none", |
| 4874 | system_shared_libs: [], |
| 4875 | apex_available: ["otherapex"], |
| 4876 | }`) |
| 4877 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4878 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4879 | apex { |
| 4880 | name: "myapex", |
| 4881 | key: "myapex.key", |
| 4882 | native_shared_libs: ["libfoo", "libbar"], |
| 4883 | } |
| 4884 | |
| 4885 | apex_key { |
| 4886 | name: "myapex.key", |
| 4887 | public_key: "testkey.avbpubkey", |
| 4888 | private_key: "testkey.pem", |
| 4889 | } |
| 4890 | |
| 4891 | cc_library { |
| 4892 | name: "libfoo", |
| 4893 | stl: "none", |
| 4894 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 4895 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4896 | apex_available: ["myapex"], |
| 4897 | } |
| 4898 | |
| 4899 | cc_library { |
| 4900 | name: "libbar", |
| 4901 | stl: "none", |
| 4902 | system_shared_libs: [], |
| 4903 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | cc_library { |
| 4907 | name: "libbaz", |
| 4908 | stl: "none", |
| 4909 | system_shared_libs: [], |
| 4910 | stubs: { |
| 4911 | versions: ["10", "20", "30"], |
| 4912 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4913 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4914 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4915 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4916 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4917 | ctx, _ := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4918 | apex { |
| 4919 | name: "myapex", |
| 4920 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4921 | native_shared_libs: ["libbar", "libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | apex_key { |
| 4925 | name: "myapex.key", |
| 4926 | public_key: "testkey.avbpubkey", |
| 4927 | private_key: "testkey.pem", |
| 4928 | } |
| 4929 | |
| 4930 | cc_library { |
| 4931 | name: "libfoo", |
| 4932 | stl: "none", |
| 4933 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4934 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4935 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4936 | } |
| 4937 | |
| 4938 | cc_library { |
| 4939 | name: "libfoo2", |
| 4940 | stl: "none", |
| 4941 | system_shared_libs: [], |
| 4942 | shared_libs: ["libbaz"], |
| 4943 | apex_available: ["//apex_available:platform"], |
| 4944 | } |
| 4945 | |
| 4946 | cc_library { |
| 4947 | name: "libbar", |
| 4948 | stl: "none", |
| 4949 | system_shared_libs: [], |
| 4950 | apex_available: ["myapex"], |
| 4951 | } |
| 4952 | |
| 4953 | cc_library { |
| 4954 | name: "libbaz", |
| 4955 | stl: "none", |
| 4956 | system_shared_libs: [], |
| 4957 | apex_available: ["myapex"], |
| 4958 | stubs: { |
| 4959 | versions: ["1"], |
| 4960 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4961 | }`) |
| 4962 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4963 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 4964 | // because it depends on libbar which isn't available to platform |
| 4965 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4966 | if libfoo.NotAvailableForPlatform() != true { |
| 4967 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 4968 | } |
| 4969 | |
| 4970 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 4971 | // stubs |
| 4972 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4973 | if libfoo2.NotAvailableForPlatform() == true { |
| 4974 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 4975 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4976 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 4977 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4978 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4979 | ctx, _ := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 4980 | apex { |
| 4981 | name: "myapex", |
| 4982 | key: "myapex.key", |
| 4983 | native_shared_libs: ["libfoo"], |
| 4984 | } |
| 4985 | |
| 4986 | apex_key { |
| 4987 | name: "myapex.key", |
| 4988 | public_key: "testkey.avbpubkey", |
| 4989 | private_key: "testkey.pem", |
| 4990 | } |
| 4991 | |
| 4992 | cc_library { |
| 4993 | name: "libfoo", |
| 4994 | stl: "none", |
| 4995 | system_shared_libs: [], |
| 4996 | apex_available: ["myapex"], |
| 4997 | static: { |
| 4998 | apex_available: ["//apex_available:platform"], |
| 4999 | }, |
| 5000 | }`) |
| 5001 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5002 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5003 | if libfooShared.NotAvailableForPlatform() != true { |
| 5004 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 5005 | } |
| 5006 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 5007 | if libfooStatic.NotAvailableForPlatform() != false { |
| 5008 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 5009 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5010 | } |
| 5011 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5012 | func TestOverrideApex(t *testing.T) { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5013 | ctx, config := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5014 | apex { |
| 5015 | name: "myapex", |
| 5016 | key: "myapex.key", |
| 5017 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5018 | overrides: ["oldapex"], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | override_apex { |
| 5022 | name: "override_myapex", |
| 5023 | base: "myapex", |
| 5024 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5025 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5026 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5027 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | apex_key { |
| 5031 | name: "myapex.key", |
| 5032 | public_key: "testkey.avbpubkey", |
| 5033 | private_key: "testkey.pem", |
| 5034 | } |
| 5035 | |
| 5036 | android_app { |
| 5037 | name: "app", |
| 5038 | srcs: ["foo/bar/MyClass.java"], |
| 5039 | package_name: "foo", |
| 5040 | sdk_version: "none", |
| 5041 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5042 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | override_android_app { |
| 5046 | name: "override_app", |
| 5047 | base: "app", |
| 5048 | package_name: "bar", |
| 5049 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5050 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5051 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 5052 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 5053 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 5054 | if originalVariant.GetOverriddenBy() != "" { |
| 5055 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 5056 | } |
| 5057 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 5058 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 5059 | } |
| 5060 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5061 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 5062 | apexRule := module.Rule("apexRule") |
| 5063 | copyCmds := apexRule.Args["copy_commands"] |
| 5064 | |
| 5065 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5066 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5067 | |
| 5068 | apexBundle := module.Module().(*apexBundle) |
| 5069 | name := apexBundle.Name() |
| 5070 | if name != "override_myapex" { |
| 5071 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 5072 | } |
| 5073 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5074 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 5075 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 5076 | } |
| 5077 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5078 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5079 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5080 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5081 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 5082 | var builder strings.Builder |
| 5083 | data.Custom(&builder, name, "TARGET_", "", data) |
| 5084 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5085 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5086 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 5087 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5088 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5089 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5090 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5091 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 5092 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5093 | } |
| 5094 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5095 | func TestLegacyAndroid10Support(t *testing.T) { |
| 5096 | ctx, _ := testApex(t, ` |
| 5097 | apex { |
| 5098 | name: "myapex", |
| 5099 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5100 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 5101 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | apex_key { |
| 5105 | name: "myapex.key", |
| 5106 | public_key: "testkey.avbpubkey", |
| 5107 | private_key: "testkey.pem", |
| 5108 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5109 | |
| 5110 | cc_library { |
| 5111 | name: "mylib", |
| 5112 | srcs: ["mylib.cpp"], |
| 5113 | stl: "libc++", |
| 5114 | system_shared_libs: [], |
| 5115 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5116 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5117 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5118 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5119 | |
| 5120 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5121 | args := module.Rule("apexRule").Args |
| 5122 | 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] | 5123 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5124 | |
| 5125 | // The copies of the libraries in the apex should have one more dependency than |
| 5126 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 5127 | // the dependency names directly here but for some reason the names are blank in |
| 5128 | // this test. |
| 5129 | for _, lib := range []string{"libc++", "mylib"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5130 | apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_apex29").Rule("ld").Implicits |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5131 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 5132 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 5133 | t.Errorf("%q missing unwinder dep", lib) |
| 5134 | } |
| 5135 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5136 | } |
| 5137 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5138 | var filesForSdkLibrary = map[string][]byte{ |
| 5139 | "api/current.txt": nil, |
| 5140 | "api/removed.txt": nil, |
| 5141 | "api/system-current.txt": nil, |
| 5142 | "api/system-removed.txt": nil, |
| 5143 | "api/test-current.txt": nil, |
| 5144 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5145 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5146 | "100/public/api/foo.txt": nil, |
| 5147 | "100/public/api/foo-removed.txt": nil, |
| 5148 | "100/system/api/foo.txt": nil, |
| 5149 | "100/system/api/foo-removed.txt": nil, |
| 5150 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5151 | // For java_sdk_library_import |
| 5152 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5153 | } |
| 5154 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5155 | func TestJavaSDKLibrary(t *testing.T) { |
| 5156 | ctx, _ := testApex(t, ` |
| 5157 | apex { |
| 5158 | name: "myapex", |
| 5159 | key: "myapex.key", |
| 5160 | java_libs: ["foo"], |
| 5161 | } |
| 5162 | |
| 5163 | apex_key { |
| 5164 | name: "myapex.key", |
| 5165 | public_key: "testkey.avbpubkey", |
| 5166 | private_key: "testkey.pem", |
| 5167 | } |
| 5168 | |
| 5169 | java_sdk_library { |
| 5170 | name: "foo", |
| 5171 | srcs: ["a.java"], |
| 5172 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5173 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5174 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5175 | |
| 5176 | prebuilt_apis { |
| 5177 | name: "sdk", |
| 5178 | api_dirs: ["100"], |
| 5179 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5180 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5181 | |
| 5182 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5183 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5184 | "javalib/foo.jar", |
| 5185 | "etc/permissions/foo.xml", |
| 5186 | }) |
| 5187 | // 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] | 5188 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 5189 | 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] | 5190 | } |
| 5191 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5192 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
| 5193 | ctx, _ := testApex(t, ` |
| 5194 | apex { |
| 5195 | name: "myapex", |
| 5196 | key: "myapex.key", |
| 5197 | java_libs: ["foo", "bar"], |
| 5198 | } |
| 5199 | |
| 5200 | apex_key { |
| 5201 | name: "myapex.key", |
| 5202 | public_key: "testkey.avbpubkey", |
| 5203 | private_key: "testkey.pem", |
| 5204 | } |
| 5205 | |
| 5206 | java_sdk_library { |
| 5207 | name: "foo", |
| 5208 | srcs: ["a.java"], |
| 5209 | api_packages: ["foo"], |
| 5210 | apex_available: ["myapex"], |
| 5211 | sdk_version: "none", |
| 5212 | system_modules: "none", |
| 5213 | } |
| 5214 | |
| 5215 | java_library { |
| 5216 | name: "bar", |
| 5217 | srcs: ["a.java"], |
| 5218 | libs: ["foo"], |
| 5219 | apex_available: ["myapex"], |
| 5220 | sdk_version: "none", |
| 5221 | system_modules: "none", |
| 5222 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5223 | |
| 5224 | prebuilt_apis { |
| 5225 | name: "sdk", |
| 5226 | api_dirs: ["100"], |
| 5227 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5228 | `, withFiles(filesForSdkLibrary)) |
| 5229 | |
| 5230 | // java_sdk_library installs both impl jar and permission XML |
| 5231 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5232 | "javalib/bar.jar", |
| 5233 | "javalib/foo.jar", |
| 5234 | "etc/permissions/foo.xml", |
| 5235 | }) |
| 5236 | |
| 5237 | // The bar library should depend on the implementation jar. |
| 5238 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 5239 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5240 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5241 | } |
| 5242 | } |
| 5243 | |
| 5244 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
| 5245 | ctx, _ := testApex(t, ` |
| 5246 | apex { |
| 5247 | name: "myapex", |
| 5248 | key: "myapex.key", |
| 5249 | java_libs: ["foo"], |
| 5250 | } |
| 5251 | |
| 5252 | apex_key { |
| 5253 | name: "myapex.key", |
| 5254 | public_key: "testkey.avbpubkey", |
| 5255 | private_key: "testkey.pem", |
| 5256 | } |
| 5257 | |
| 5258 | java_sdk_library { |
| 5259 | name: "foo", |
| 5260 | srcs: ["a.java"], |
| 5261 | api_packages: ["foo"], |
| 5262 | apex_available: ["myapex"], |
| 5263 | sdk_version: "none", |
| 5264 | system_modules: "none", |
| 5265 | } |
| 5266 | |
| 5267 | java_library { |
| 5268 | name: "bar", |
| 5269 | srcs: ["a.java"], |
| 5270 | libs: ["foo"], |
| 5271 | sdk_version: "none", |
| 5272 | system_modules: "none", |
| 5273 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5274 | |
| 5275 | prebuilt_apis { |
| 5276 | name: "sdk", |
| 5277 | api_dirs: ["100"], |
| 5278 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5279 | `, withFiles(filesForSdkLibrary)) |
| 5280 | |
| 5281 | // java_sdk_library installs both impl jar and permission XML |
| 5282 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5283 | "javalib/foo.jar", |
| 5284 | "etc/permissions/foo.xml", |
| 5285 | }) |
| 5286 | |
| 5287 | // The bar library should depend on the stubs jar. |
| 5288 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
| 5289 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5290 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5291 | } |
| 5292 | } |
| 5293 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5294 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5295 | ctx, _ := testApex(t, ` |
| 5296 | prebuilt_apis { |
| 5297 | name: "sdk", |
| 5298 | api_dirs: ["100"], |
| 5299 | }`, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5300 | withFiles(map[string][]byte{ |
| 5301 | "apex/a.java": nil, |
| 5302 | "apex/apex_manifest.json": nil, |
| 5303 | "apex/Android.bp": []byte(` |
| 5304 | package { |
| 5305 | default_visibility: ["//visibility:private"], |
| 5306 | } |
| 5307 | |
| 5308 | apex { |
| 5309 | name: "myapex", |
| 5310 | key: "myapex.key", |
| 5311 | java_libs: ["foo", "bar"], |
| 5312 | } |
| 5313 | |
| 5314 | apex_key { |
| 5315 | name: "myapex.key", |
| 5316 | public_key: "testkey.avbpubkey", |
| 5317 | private_key: "testkey.pem", |
| 5318 | } |
| 5319 | |
| 5320 | java_library { |
| 5321 | name: "bar", |
| 5322 | srcs: ["a.java"], |
| 5323 | libs: ["foo"], |
| 5324 | apex_available: ["myapex"], |
| 5325 | sdk_version: "none", |
| 5326 | system_modules: "none", |
| 5327 | } |
| 5328 | `), |
| 5329 | "source/a.java": nil, |
| 5330 | "source/api/current.txt": nil, |
| 5331 | "source/api/removed.txt": nil, |
| 5332 | "source/Android.bp": []byte(` |
| 5333 | package { |
| 5334 | default_visibility: ["//visibility:private"], |
| 5335 | } |
| 5336 | |
| 5337 | java_sdk_library { |
| 5338 | name: "foo", |
| 5339 | visibility: ["//apex"], |
| 5340 | srcs: ["a.java"], |
| 5341 | api_packages: ["foo"], |
| 5342 | apex_available: ["myapex"], |
| 5343 | sdk_version: "none", |
| 5344 | system_modules: "none", |
| 5345 | public: { |
| 5346 | enabled: true, |
| 5347 | }, |
| 5348 | } |
| 5349 | `), |
| 5350 | "prebuilt/a.jar": nil, |
| 5351 | "prebuilt/Android.bp": []byte(` |
| 5352 | package { |
| 5353 | default_visibility: ["//visibility:private"], |
| 5354 | } |
| 5355 | |
| 5356 | java_sdk_library_import { |
| 5357 | name: "foo", |
| 5358 | visibility: ["//apex", "//source"], |
| 5359 | apex_available: ["myapex"], |
| 5360 | prefer: true, |
| 5361 | public: { |
| 5362 | jars: ["a.jar"], |
| 5363 | }, |
| 5364 | } |
| 5365 | `), |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5366 | }), withFiles(filesForSdkLibrary), |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5367 | ) |
| 5368 | |
| 5369 | // java_sdk_library installs both impl jar and permission XML |
| 5370 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5371 | "javalib/bar.jar", |
| 5372 | "javalib/foo.jar", |
| 5373 | "etc/permissions/foo.xml", |
| 5374 | }) |
| 5375 | |
| 5376 | // The bar library should depend on the implementation jar. |
| 5377 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 5378 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.impl\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5379 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5380 | } |
| 5381 | } |
| 5382 | |
| 5383 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 5384 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 5385 | apex { |
| 5386 | name: "myapex", |
| 5387 | key: "myapex.key", |
| 5388 | java_libs: ["foo"], |
| 5389 | } |
| 5390 | |
| 5391 | apex_key { |
| 5392 | name: "myapex.key", |
| 5393 | public_key: "testkey.avbpubkey", |
| 5394 | private_key: "testkey.pem", |
| 5395 | } |
| 5396 | |
| 5397 | java_sdk_library_import { |
| 5398 | name: "foo", |
| 5399 | apex_available: ["myapex"], |
| 5400 | prefer: true, |
| 5401 | public: { |
| 5402 | jars: ["a.jar"], |
| 5403 | }, |
| 5404 | } |
| 5405 | |
| 5406 | `, withFiles(filesForSdkLibrary)) |
| 5407 | } |
| 5408 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5409 | func TestCompatConfig(t *testing.T) { |
| 5410 | ctx, _ := testApex(t, ` |
| 5411 | apex { |
| 5412 | name: "myapex", |
| 5413 | key: "myapex.key", |
| 5414 | prebuilts: ["myjar-platform-compat-config"], |
| 5415 | java_libs: ["myjar"], |
| 5416 | } |
| 5417 | |
| 5418 | apex_key { |
| 5419 | name: "myapex.key", |
| 5420 | public_key: "testkey.avbpubkey", |
| 5421 | private_key: "testkey.pem", |
| 5422 | } |
| 5423 | |
| 5424 | platform_compat_config { |
| 5425 | name: "myjar-platform-compat-config", |
| 5426 | src: ":myjar", |
| 5427 | } |
| 5428 | |
| 5429 | java_library { |
| 5430 | name: "myjar", |
| 5431 | srcs: ["foo/bar/MyClass.java"], |
| 5432 | sdk_version: "none", |
| 5433 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5434 | apex_available: [ "myapex" ], |
| 5435 | } |
| 5436 | `) |
| 5437 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5438 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 5439 | "javalib/myjar.jar", |
| 5440 | }) |
| 5441 | } |
| 5442 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5443 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 5444 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 5445 | apex { |
| 5446 | name: "myapex", |
| 5447 | key: "myapex.key", |
| 5448 | java_libs: ["myjar"], |
| 5449 | } |
| 5450 | |
| 5451 | apex_key { |
| 5452 | name: "myapex.key", |
| 5453 | public_key: "testkey.avbpubkey", |
| 5454 | private_key: "testkey.pem", |
| 5455 | } |
| 5456 | |
| 5457 | java_library { |
| 5458 | name: "myjar", |
| 5459 | srcs: ["foo/bar/MyClass.java"], |
| 5460 | sdk_version: "none", |
| 5461 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 5462 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5463 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5464 | } |
| 5465 | `) |
| 5466 | } |
| 5467 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5468 | func TestCarryRequiredModuleNames(t *testing.T) { |
| 5469 | ctx, config := testApex(t, ` |
| 5470 | apex { |
| 5471 | name: "myapex", |
| 5472 | key: "myapex.key", |
| 5473 | native_shared_libs: ["mylib"], |
| 5474 | } |
| 5475 | |
| 5476 | apex_key { |
| 5477 | name: "myapex.key", |
| 5478 | public_key: "testkey.avbpubkey", |
| 5479 | private_key: "testkey.pem", |
| 5480 | } |
| 5481 | |
| 5482 | cc_library { |
| 5483 | name: "mylib", |
| 5484 | srcs: ["mylib.cpp"], |
| 5485 | system_shared_libs: [], |
| 5486 | stl: "none", |
| 5487 | required: ["a", "b"], |
| 5488 | host_required: ["c", "d"], |
| 5489 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5490 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5491 | } |
| 5492 | `) |
| 5493 | |
| 5494 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 5495 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 5496 | name := apexBundle.BaseModuleName() |
| 5497 | prefix := "TARGET_" |
| 5498 | var builder strings.Builder |
| 5499 | data.Custom(&builder, name, prefix, "", data) |
| 5500 | androidMk := builder.String() |
| 5501 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 5502 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 5503 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 5504 | } |
| 5505 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5506 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 5507 | bp := ` |
| 5508 | apex { |
| 5509 | name: "myapex", |
| 5510 | key: "myapex.key", |
| 5511 | native_shared_libs: ["mylib"], |
| 5512 | java_libs: ["myjar"], |
| 5513 | } |
| 5514 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5515 | apex { |
| 5516 | name: "myapex.updatable", |
| 5517 | key: "myapex.key", |
| 5518 | native_shared_libs: ["mylib"], |
| 5519 | java_libs: ["myjar"], |
| 5520 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 5521 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5522 | } |
| 5523 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5524 | apex_key { |
| 5525 | name: "myapex.key", |
| 5526 | public_key: "testkey.avbpubkey", |
| 5527 | private_key: "testkey.pem", |
| 5528 | } |
| 5529 | |
| 5530 | cc_library { |
| 5531 | name: "mylib", |
| 5532 | srcs: ["mylib.cpp"], |
| 5533 | shared_libs: ["myotherlib"], |
| 5534 | system_shared_libs: [], |
| 5535 | stl: "none", |
| 5536 | apex_available: [ |
| 5537 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5538 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5539 | "//apex_available:platform", |
| 5540 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5541 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | cc_library { |
| 5545 | name: "myotherlib", |
| 5546 | srcs: ["mylib.cpp"], |
| 5547 | system_shared_libs: [], |
| 5548 | stl: "none", |
| 5549 | apex_available: [ |
| 5550 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5551 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5552 | "//apex_available:platform", |
| 5553 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5554 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5555 | } |
| 5556 | |
| 5557 | java_library { |
| 5558 | name: "myjar", |
| 5559 | srcs: ["foo/bar/MyClass.java"], |
| 5560 | sdk_version: "none", |
| 5561 | system_modules: "none", |
| 5562 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5563 | apex_available: [ |
| 5564 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5565 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5566 | "//apex_available:platform", |
| 5567 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5568 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | java_library { |
| 5572 | name: "myotherjar", |
| 5573 | srcs: ["foo/bar/MyClass.java"], |
| 5574 | sdk_version: "none", |
| 5575 | system_modules: "none", |
| 5576 | apex_available: [ |
| 5577 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5578 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5579 | "//apex_available:platform", |
| 5580 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5581 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5582 | } |
| 5583 | ` |
| 5584 | |
| 5585 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 5586 | for _, f := range files { |
| 5587 | if f.path == file { |
| 5588 | if f.isLink { |
| 5589 | t.Errorf("%q is not a real file", file) |
| 5590 | } |
| 5591 | return |
| 5592 | } |
| 5593 | } |
| 5594 | t.Errorf("%q is not found", file) |
| 5595 | } |
| 5596 | |
| 5597 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 5598 | for _, f := range files { |
| 5599 | if f.path == file { |
| 5600 | if !f.isLink { |
| 5601 | t.Errorf("%q is not a symlink", file) |
| 5602 | } |
| 5603 | return |
| 5604 | } |
| 5605 | } |
| 5606 | t.Errorf("%q is not found", file) |
| 5607 | } |
| 5608 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5609 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 5610 | // is updatable or not |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5611 | ctx, _ := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5612 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5613 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5614 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5615 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 5616 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5617 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 5618 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5619 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5620 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 5621 | |
| 5622 | // 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] | 5623 | ctx, _ = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5624 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5625 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5626 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5627 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5628 | |
| 5629 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 5630 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5631 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5632 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5633 | } |
| 5634 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 5635 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
| 5636 | ctx, config := testApex(t, ` |
| 5637 | apex { |
| 5638 | name: "myapex", |
| 5639 | key: "myapex.key", |
| 5640 | native_shared_libs: ["mylib"], |
| 5641 | } |
| 5642 | |
| 5643 | apex_key { |
| 5644 | name: "myapex.key", |
| 5645 | public_key: "testkey.avbpubkey", |
| 5646 | private_key: "testkey.pem", |
| 5647 | } |
| 5648 | |
| 5649 | cc_library_shared { |
| 5650 | name: "mylib", |
| 5651 | srcs: ["mylib.cpp"], |
| 5652 | shared_libs: ["myotherlib"], |
| 5653 | system_shared_libs: [], |
| 5654 | stl: "none", |
| 5655 | apex_available: [ |
| 5656 | "myapex", |
| 5657 | "//apex_available:platform", |
| 5658 | ], |
| 5659 | } |
| 5660 | |
| 5661 | cc_prebuilt_library_shared { |
| 5662 | name: "myotherlib", |
| 5663 | srcs: ["prebuilt.so"], |
| 5664 | system_shared_libs: [], |
| 5665 | stl: "none", |
| 5666 | apex_available: [ |
| 5667 | "myapex", |
| 5668 | "//apex_available:platform", |
| 5669 | ], |
| 5670 | } |
| 5671 | `) |
| 5672 | |
| 5673 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 5674 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 5675 | var builder strings.Builder |
| 5676 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 5677 | androidMk := builder.String() |
| 5678 | // `myotherlib` is added to `myapex` as symlink |
| 5679 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 5680 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 5681 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 5682 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 5683 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += mylib.myapex:64 myotherlib:64 apex_manifest.pb.myapex apex_pubkey.myapex\n") |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 5684 | } |
| 5685 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 5686 | func TestApexWithJniLibs(t *testing.T) { |
| 5687 | ctx, _ := testApex(t, ` |
| 5688 | apex { |
| 5689 | name: "myapex", |
| 5690 | key: "myapex.key", |
| 5691 | jni_libs: ["mylib"], |
| 5692 | } |
| 5693 | |
| 5694 | apex_key { |
| 5695 | name: "myapex.key", |
| 5696 | public_key: "testkey.avbpubkey", |
| 5697 | private_key: "testkey.pem", |
| 5698 | } |
| 5699 | |
| 5700 | cc_library { |
| 5701 | name: "mylib", |
| 5702 | srcs: ["mylib.cpp"], |
| 5703 | shared_libs: ["mylib2"], |
| 5704 | system_shared_libs: [], |
| 5705 | stl: "none", |
| 5706 | apex_available: [ "myapex" ], |
| 5707 | } |
| 5708 | |
| 5709 | cc_library { |
| 5710 | name: "mylib2", |
| 5711 | srcs: ["mylib.cpp"], |
| 5712 | system_shared_libs: [], |
| 5713 | stl: "none", |
| 5714 | apex_available: [ "myapex" ], |
| 5715 | } |
| 5716 | `) |
| 5717 | |
| 5718 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 5719 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 5720 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 5721 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5722 | "lib64/mylib.so", |
| 5723 | "lib64/mylib2.so", |
| 5724 | }) |
| 5725 | } |
| 5726 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 5727 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
| 5728 | ctx, _ := testApex(t, ` |
| 5729 | apex { |
| 5730 | name: "myapex", |
| 5731 | key: "myapex.key", |
| 5732 | } |
| 5733 | apex_key { |
| 5734 | name: "myapex.key", |
| 5735 | public_key: "testkey.avbpubkey", |
| 5736 | private_key: "testkey.pem", |
| 5737 | } |
| 5738 | `, func(fs map[string][]byte, config android.Config) { |
| 5739 | delete(config.Targets, android.Android) |
| 5740 | config.AndroidCommonTarget = android.Target{} |
| 5741 | }) |
| 5742 | |
| 5743 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 5744 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 5745 | } |
| 5746 | } |
| 5747 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 5748 | func TestAppBundle(t *testing.T) { |
| 5749 | ctx, _ := testApex(t, ` |
| 5750 | apex { |
| 5751 | name: "myapex", |
| 5752 | key: "myapex.key", |
| 5753 | apps: ["AppFoo"], |
| 5754 | } |
| 5755 | |
| 5756 | apex_key { |
| 5757 | name: "myapex.key", |
| 5758 | public_key: "testkey.avbpubkey", |
| 5759 | private_key: "testkey.pem", |
| 5760 | } |
| 5761 | |
| 5762 | android_app { |
| 5763 | name: "AppFoo", |
| 5764 | srcs: ["foo/bar/MyClass.java"], |
| 5765 | sdk_version: "none", |
| 5766 | system_modules: "none", |
| 5767 | apex_available: [ "myapex" ], |
| 5768 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 5769 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 5770 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 5771 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json") |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 5772 | content := bundleConfigRule.Args["content"] |
| 5773 | |
| 5774 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 5775 | 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] | 5776 | } |
| 5777 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5778 | func TestAppSetBundle(t *testing.T) { |
| 5779 | ctx, _ := testApex(t, ` |
| 5780 | apex { |
| 5781 | name: "myapex", |
| 5782 | key: "myapex.key", |
| 5783 | apps: ["AppSet"], |
| 5784 | } |
| 5785 | |
| 5786 | apex_key { |
| 5787 | name: "myapex.key", |
| 5788 | public_key: "testkey.avbpubkey", |
| 5789 | private_key: "testkey.pem", |
| 5790 | } |
| 5791 | |
| 5792 | android_app_set { |
| 5793 | name: "AppSet", |
| 5794 | set: "AppSet.apks", |
| 5795 | }`) |
| 5796 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 5797 | bundleConfigRule := mod.Output("bundle_config.json") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5798 | content := bundleConfigRule.Args["content"] |
| 5799 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 5800 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 5801 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 5802 | if len(copyCmds) != 3 { |
| 5803 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 5804 | } |
| 5805 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 5806 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 5807 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 5808 | } |
| 5809 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 5810 | func TestAppSetBundlePrebuilt(t *testing.T) { |
| 5811 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 5812 | bp := ` |
| 5813 | apex_set { |
| 5814 | name: "myapex", |
| 5815 | filename: "foo_v2.apex", |
| 5816 | sanitized: { |
| 5817 | none: { set: "myapex.apks", }, |
| 5818 | hwaddress: { set: "myapex.hwasan.apks", }, |
| 5819 | }, |
| 5820 | }` |
| 5821 | fs["Android.bp"] = []byte(bp) |
| 5822 | |
| 5823 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 5824 | }) |
| 5825 | |
| 5826 | m := ctx.ModuleForTests("myapex", "android_common") |
| 5827 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 5828 | |
| 5829 | actual := extractedApex.Inputs |
| 5830 | if len(actual) != 1 { |
| 5831 | t.Errorf("expected a single input") |
| 5832 | } |
| 5833 | |
| 5834 | expected := "myapex.hwasan.apks" |
| 5835 | if actual[0].String() != expected { |
| 5836 | t.Errorf("expected %s, got %s", expected, actual[0].String()) |
| 5837 | } |
| 5838 | } |
| 5839 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5840 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5841 | t.Helper() |
| 5842 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5843 | bp := ` |
| 5844 | java_library { |
| 5845 | name: "some-updatable-apex-lib", |
| 5846 | srcs: ["a.java"], |
| 5847 | sdk_version: "current", |
| 5848 | apex_available: [ |
| 5849 | "some-updatable-apex", |
| 5850 | ], |
| 5851 | } |
| 5852 | |
| 5853 | java_library { |
| 5854 | name: "some-non-updatable-apex-lib", |
| 5855 | srcs: ["a.java"], |
| 5856 | apex_available: [ |
| 5857 | "some-non-updatable-apex", |
| 5858 | ], |
| 5859 | } |
| 5860 | |
| 5861 | java_library { |
| 5862 | name: "some-platform-lib", |
| 5863 | srcs: ["a.java"], |
| 5864 | sdk_version: "current", |
| 5865 | installable: true, |
| 5866 | } |
| 5867 | |
| 5868 | java_library { |
| 5869 | name: "some-art-lib", |
| 5870 | srcs: ["a.java"], |
| 5871 | sdk_version: "current", |
| 5872 | apex_available: [ |
| 5873 | "com.android.art.something", |
| 5874 | ], |
| 5875 | hostdex: true, |
| 5876 | } |
| 5877 | |
| 5878 | apex { |
| 5879 | name: "some-updatable-apex", |
| 5880 | key: "some-updatable-apex.key", |
| 5881 | java_libs: ["some-updatable-apex-lib"], |
| 5882 | updatable: true, |
| 5883 | min_sdk_version: "current", |
| 5884 | } |
| 5885 | |
| 5886 | apex { |
| 5887 | name: "some-non-updatable-apex", |
| 5888 | key: "some-non-updatable-apex.key", |
| 5889 | java_libs: ["some-non-updatable-apex-lib"], |
| 5890 | } |
| 5891 | |
| 5892 | apex_key { |
| 5893 | name: "some-updatable-apex.key", |
| 5894 | } |
| 5895 | |
| 5896 | apex_key { |
| 5897 | name: "some-non-updatable-apex.key", |
| 5898 | } |
| 5899 | |
| 5900 | apex { |
| 5901 | name: "com.android.art.something", |
| 5902 | key: "com.android.art.something.key", |
| 5903 | java_libs: ["some-art-lib"], |
| 5904 | updatable: true, |
| 5905 | min_sdk_version: "current", |
| 5906 | } |
| 5907 | |
| 5908 | apex_key { |
| 5909 | name: "com.android.art.something.key", |
| 5910 | } |
| 5911 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5912 | filegroup { |
| 5913 | name: "some-updatable-apex-file_contexts", |
| 5914 | srcs: [ |
| 5915 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 5916 | ], |
| 5917 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5918 | |
| 5919 | filegroup { |
| 5920 | name: "some-non-updatable-apex-file_contexts", |
| 5921 | srcs: [ |
| 5922 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 5923 | ], |
| 5924 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5925 | ` |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 5926 | |
| 5927 | testDexpreoptWithApexes(t, bp, errmsg, transformDexpreoptConfig) |
| 5928 | } |
| 5929 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 5930 | func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) *android.TestContext { |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 5931 | t.Helper() |
| 5932 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5933 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 5934 | bp += java.GatherRequiredDepsForTest() |
| 5935 | bp += dexpreopt.BpToolModulesForTest() |
| 5936 | |
| 5937 | fs := map[string][]byte{ |
| 5938 | "a.java": nil, |
| 5939 | "a.jar": nil, |
| 5940 | "build/make/target/product/security": nil, |
| 5941 | "apex_manifest.json": nil, |
| 5942 | "AndroidManifest.xml": nil, |
| 5943 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5944 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5945 | "system/sepolicy/apex/com.android.art.something-file_contexts": nil, |
| 5946 | "framework/aidl/a.aidl": nil, |
| 5947 | } |
| 5948 | cc.GatherRequiredFilesForTest(fs) |
| 5949 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 5950 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 5951 | |
| 5952 | ctx := android.NewTestArchContext(config) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5953 | ctx.RegisterModuleType("apex", BundleFactory) |
| 5954 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 5955 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5956 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 5957 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 5958 | android.RegisterPrebuiltMutators(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5959 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
| 5960 | java.RegisterJavaBuildComponents(ctx) |
| 5961 | java.RegisterSystemModulesBuildComponents(ctx) |
| 5962 | java.RegisterAppBuildComponents(ctx) |
| 5963 | java.RegisterDexpreoptBootJarsComponents(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5964 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 5965 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 5966 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 5967 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 5968 | ctx.Register() |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5969 | |
| 5970 | _ = dexpreopt.GlobalSoongConfigForTests(config) |
| 5971 | dexpreopt.RegisterToolModulesForTest(ctx) |
| 5972 | pathCtx := android.PathContextForTesting(config) |
| 5973 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 5974 | transformDexpreoptConfig(dexpreoptConfig) |
| 5975 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 5976 | |
| 5977 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 5978 | android.FailIfErrored(t, errs) |
| 5979 | |
| 5980 | _, errs = ctx.PrepareBuildActions(config) |
| 5981 | if errmsg == "" { |
| 5982 | android.FailIfErrored(t, errs) |
| 5983 | } else if len(errs) > 0 { |
| 5984 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5985 | } else { |
| 5986 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 5987 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 5988 | |
| 5989 | return ctx |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5990 | } |
| 5991 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 5992 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 5993 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 5994 | apex { |
| 5995 | name: "myapex", |
| 5996 | key: "myapex.key", |
| 5997 | updatable: true, |
| 5998 | } |
| 5999 | |
| 6000 | apex_key { |
| 6001 | name: "myapex.key", |
| 6002 | public_key: "testkey.avbpubkey", |
| 6003 | private_key: "testkey.pem", |
| 6004 | } |
| 6005 | `) |
| 6006 | } |
| 6007 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6008 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6009 | var err string |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6010 | var transform func(*dexpreopt.GlobalConfig) |
| 6011 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6012 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
| 6013 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6014 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"com.android.art.something:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6015 | } |
| 6016 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6017 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6018 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6019 | t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6020 | err = `module "some-art-lib" from updatable apexes \["com.android.art.something"\] is not allowed in the framework boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6021 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6022 | config.BootJars = android.CreateTestConfiguredJarList([]string{"com.android.art.something:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6023 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6024 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6025 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6026 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6027 | t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6028 | err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6029 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6030 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6031 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6032 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6033 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6034 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6035 | t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6036 | err = `module "some-non-updatable-apex-lib" is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6037 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6038 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6039 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6040 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6041 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6042 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6043 | t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6044 | err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6045 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6046 | config.BootJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6047 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6048 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6049 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6050 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6051 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
| 6052 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6053 | config.BootJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6054 | } |
| 6055 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6056 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6057 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6058 | t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6059 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6060 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6061 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6062 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6063 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6064 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6065 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6066 | t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6067 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6068 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6069 | config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6070 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6071 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6072 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6073 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6074 | t.Run("platform jar in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6075 | err = `module "some-platform-lib" is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6076 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6077 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6078 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6079 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6080 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6081 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6082 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
| 6083 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6084 | config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6085 | } |
| 6086 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6087 | }) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6088 | |
| 6089 | } |
| 6090 | |
| 6091 | func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { |
| 6092 | transform := func(config *dexpreopt.GlobalConfig) { |
| 6093 | config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo"}) |
| 6094 | } |
| 6095 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6096 | testDexpreoptWithApexes(t, ` |
| 6097 | prebuilt_apex { |
| 6098 | name: "myapex" , |
| 6099 | arch: { |
| 6100 | arm64: { |
| 6101 | src: "myapex-arm64.apex", |
| 6102 | }, |
| 6103 | arm: { |
| 6104 | src: "myapex-arm.apex", |
| 6105 | }, |
| 6106 | }, |
| 6107 | exported_java_libs: ["libfoo"], |
| 6108 | } |
| 6109 | |
| 6110 | java_import { |
| 6111 | name: "libfoo", |
| 6112 | jars: ["libfoo.jar"], |
| 6113 | } |
| 6114 | `, "", transform) |
| 6115 | }) |
| 6116 | |
| 6117 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6118 | testDexpreoptWithApexes(t, ` |
| 6119 | prebuilt_apex { |
| 6120 | name: "myapex" , |
| 6121 | arch: { |
| 6122 | arm64: { |
| 6123 | src: "myapex-arm64.apex", |
| 6124 | }, |
| 6125 | arm: { |
| 6126 | src: "myapex-arm.apex", |
| 6127 | }, |
| 6128 | }, |
| 6129 | exported_java_libs: ["libfoo"], |
| 6130 | } |
| 6131 | |
| 6132 | java_import { |
| 6133 | name: "libfoo", |
| 6134 | jars: ["libfoo.jar"], |
| 6135 | } |
| 6136 | `, "", transform) |
| 6137 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6138 | } |
| 6139 | |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6140 | func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) { |
| 6141 | t.Helper() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6142 | bp += ` |
| 6143 | apex_key { |
| 6144 | name: "myapex.key", |
| 6145 | public_key: "testkey.avbpubkey", |
| 6146 | private_key: "testkey.pem", |
| 6147 | }` |
| 6148 | fs := map[string][]byte{ |
| 6149 | "lib1/src/A.java": nil, |
| 6150 | "lib2/src/B.java": nil, |
| 6151 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 6152 | } |
| 6153 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6154 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 6155 | android.SetTestNeverallowRules(config, rules) |
| 6156 | updatableBootJars := make([]string, 0, len(apexBootJars)) |
| 6157 | for _, apexBootJar := range apexBootJars { |
| 6158 | updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar) |
| 6159 | } |
| 6160 | config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars) |
| 6161 | |
| 6162 | ctx := android.NewTestArchContext(config) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6163 | ctx.RegisterModuleType("apex", BundleFactory) |
| 6164 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 6165 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 6166 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
| 6167 | java.RegisterJavaBuildComponents(ctx) |
| 6168 | java.RegisterSystemModulesBuildComponents(ctx) |
| 6169 | java.RegisterDexpreoptBootJarsComponents(ctx) |
| 6170 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 6171 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 6172 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 6173 | ctx.PostDepsMutators(android.RegisterNeverallowMutator) |
| 6174 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6175 | ctx.Register() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6176 | |
| 6177 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 6178 | android.FailIfErrored(t, errs) |
| 6179 | |
| 6180 | _, errs = ctx.PrepareBuildActions(config) |
| 6181 | if errmsg == "" { |
| 6182 | android.FailIfErrored(t, errs) |
| 6183 | } else if len(errs) > 0 { |
| 6184 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 6185 | return |
| 6186 | } else { |
| 6187 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 6188 | } |
| 6189 | } |
| 6190 | |
| 6191 | func TestApexPermittedPackagesRules(t *testing.T) { |
| 6192 | testcases := []struct { |
| 6193 | name string |
| 6194 | expectedError string |
| 6195 | bp string |
| 6196 | bootJars []string |
| 6197 | modulesPackages map[string][]string |
| 6198 | }{ |
| 6199 | |
| 6200 | { |
| 6201 | name: "Non-Bootclasspath apex jar not satisfying allowed module packages.", |
| 6202 | expectedError: "", |
| 6203 | bp: ` |
| 6204 | java_library { |
| 6205 | name: "bcp_lib1", |
| 6206 | srcs: ["lib1/src/*.java"], |
| 6207 | permitted_packages: ["foo.bar"], |
| 6208 | apex_available: ["myapex"], |
| 6209 | sdk_version: "none", |
| 6210 | system_modules: "none", |
| 6211 | } |
| 6212 | java_library { |
| 6213 | name: "nonbcp_lib2", |
| 6214 | srcs: ["lib2/src/*.java"], |
| 6215 | apex_available: ["myapex"], |
| 6216 | permitted_packages: ["a.b"], |
| 6217 | sdk_version: "none", |
| 6218 | system_modules: "none", |
| 6219 | } |
| 6220 | apex { |
| 6221 | name: "myapex", |
| 6222 | key: "myapex.key", |
| 6223 | java_libs: ["bcp_lib1", "nonbcp_lib2"], |
| 6224 | }`, |
| 6225 | bootJars: []string{"bcp_lib1"}, |
| 6226 | modulesPackages: map[string][]string{ |
| 6227 | "myapex": []string{ |
| 6228 | "foo.bar", |
| 6229 | }, |
| 6230 | }, |
| 6231 | }, |
| 6232 | { |
| 6233 | name: "Bootclasspath apex jar not satisfying allowed module packages.", |
| 6234 | expectedError: `module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar. Please jarjar or move code around.`, |
| 6235 | bp: ` |
| 6236 | java_library { |
| 6237 | name: "bcp_lib1", |
| 6238 | srcs: ["lib1/src/*.java"], |
| 6239 | apex_available: ["myapex"], |
| 6240 | permitted_packages: ["foo.bar"], |
| 6241 | sdk_version: "none", |
| 6242 | system_modules: "none", |
| 6243 | } |
| 6244 | java_library { |
| 6245 | name: "bcp_lib2", |
| 6246 | srcs: ["lib2/src/*.java"], |
| 6247 | apex_available: ["myapex"], |
| 6248 | permitted_packages: ["foo.bar", "bar.baz"], |
| 6249 | sdk_version: "none", |
| 6250 | system_modules: "none", |
| 6251 | } |
| 6252 | apex { |
| 6253 | name: "myapex", |
| 6254 | key: "myapex.key", |
| 6255 | java_libs: ["bcp_lib1", "bcp_lib2"], |
| 6256 | } |
| 6257 | `, |
| 6258 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
| 6259 | modulesPackages: map[string][]string{ |
| 6260 | "myapex": []string{ |
| 6261 | "foo.bar", |
| 6262 | }, |
| 6263 | }, |
| 6264 | }, |
| 6265 | } |
| 6266 | for _, tc := range testcases { |
| 6267 | t.Run(tc.name, func(t *testing.T) { |
| 6268 | rules := createApexPermittedPackagesRules(tc.modulesPackages) |
| 6269 | testApexPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules) |
| 6270 | }) |
| 6271 | } |
| 6272 | } |
| 6273 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6274 | func TestTestFor(t *testing.T) { |
| 6275 | ctx, _ := testApex(t, ` |
| 6276 | apex { |
| 6277 | name: "myapex", |
| 6278 | key: "myapex.key", |
| 6279 | native_shared_libs: ["mylib", "myprivlib"], |
| 6280 | } |
| 6281 | |
| 6282 | apex_key { |
| 6283 | name: "myapex.key", |
| 6284 | public_key: "testkey.avbpubkey", |
| 6285 | private_key: "testkey.pem", |
| 6286 | } |
| 6287 | |
| 6288 | cc_library { |
| 6289 | name: "mylib", |
| 6290 | srcs: ["mylib.cpp"], |
| 6291 | system_shared_libs: [], |
| 6292 | stl: "none", |
| 6293 | stubs: { |
| 6294 | versions: ["1"], |
| 6295 | }, |
| 6296 | apex_available: ["myapex"], |
| 6297 | } |
| 6298 | |
| 6299 | cc_library { |
| 6300 | name: "myprivlib", |
| 6301 | srcs: ["mylib.cpp"], |
| 6302 | system_shared_libs: [], |
| 6303 | stl: "none", |
| 6304 | apex_available: ["myapex"], |
| 6305 | } |
| 6306 | |
| 6307 | |
| 6308 | cc_test { |
| 6309 | name: "mytest", |
| 6310 | gtest: false, |
| 6311 | srcs: ["mylib.cpp"], |
| 6312 | system_shared_libs: [], |
| 6313 | stl: "none", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6314 | shared_libs: ["mylib", "myprivlib", "mytestlib"], |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6315 | test_for: ["myapex"] |
| 6316 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6317 | |
| 6318 | cc_library { |
| 6319 | name: "mytestlib", |
| 6320 | srcs: ["mylib.cpp"], |
| 6321 | system_shared_libs: [], |
| 6322 | shared_libs: ["mylib", "myprivlib"], |
| 6323 | stl: "none", |
| 6324 | test_for: ["myapex"], |
| 6325 | } |
| 6326 | |
| 6327 | cc_benchmark { |
| 6328 | name: "mybench", |
| 6329 | srcs: ["mylib.cpp"], |
| 6330 | system_shared_libs: [], |
| 6331 | shared_libs: ["mylib", "myprivlib"], |
| 6332 | stl: "none", |
| 6333 | test_for: ["myapex"], |
| 6334 | } |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6335 | `) |
| 6336 | |
| 6337 | // the test 'mytest' is a test for the apex, therefore is linked to the |
| 6338 | // actual implementation of mylib instead of its stub. |
| 6339 | ldFlags := ctx.ModuleForTests("mytest", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 6340 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6341 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6342 | |
| 6343 | // The same should be true for cc_library |
| 6344 | ldFlags = ctx.ModuleForTests("mytestlib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 6345 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6346 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
| 6347 | |
| 6348 | // ... and for cc_benchmark |
| 6349 | ldFlags = ctx.ModuleForTests("mybench", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 6350 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6351 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6352 | } |
| 6353 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6354 | // TODO(jungjw): Move this to proptools |
| 6355 | func intPtr(i int) *int { |
| 6356 | return &i |
| 6357 | } |
| 6358 | |
| 6359 | func TestApexSet(t *testing.T) { |
| 6360 | ctx, config := testApex(t, ` |
| 6361 | apex_set { |
| 6362 | name: "myapex", |
| 6363 | set: "myapex.apks", |
| 6364 | filename: "foo_v2.apex", |
| 6365 | overrides: ["foo"], |
| 6366 | } |
| 6367 | `, func(fs map[string][]byte, config android.Config) { |
| 6368 | config.TestProductVariables.Platform_sdk_version = intPtr(30) |
Jaewoong Jung | 829b713 | 2020-06-10 12:23:32 -0700 | [diff] [blame] | 6369 | config.Targets[android.Android] = []android.Target{ |
| 6370 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}}, |
| 6371 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}}, |
| 6372 | } |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6373 | }) |
| 6374 | |
| 6375 | m := ctx.ModuleForTests("myapex", "android_common") |
| 6376 | |
| 6377 | // Check extract_apks tool parameters. |
| 6378 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 6379 | actual := extractedApex.Args["abis"] |
| 6380 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 6381 | if actual != expected { |
| 6382 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6383 | } |
| 6384 | actual = extractedApex.Args["sdk-version"] |
| 6385 | expected = "30" |
| 6386 | if actual != expected { |
| 6387 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6388 | } |
| 6389 | |
| 6390 | a := m.Module().(*ApexSet) |
| 6391 | expectedOverrides := []string{"foo"} |
| 6392 | actualOverrides := android.AndroidMkEntriesForTest(t, config, "", a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
| 6393 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 6394 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 6395 | } |
| 6396 | } |
| 6397 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 6398 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 6399 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 6400 | apex { |
| 6401 | name: "myapex", |
| 6402 | key: "myapex.key", |
| 6403 | native_shared_libs: ["mylib"], |
| 6404 | } |
| 6405 | |
| 6406 | apex_key { |
| 6407 | name: "myapex.key", |
| 6408 | public_key: "testkey.avbpubkey", |
| 6409 | private_key: "testkey.pem", |
| 6410 | } |
| 6411 | |
| 6412 | cc_library { |
| 6413 | name: "mylib", |
| 6414 | srcs: ["mylib.cpp"], |
| 6415 | static_libs: ["otherlib"], |
| 6416 | system_shared_libs: [], |
| 6417 | stl: "none", |
| 6418 | apex_available: [ "myapex" ], |
| 6419 | } |
| 6420 | |
| 6421 | cc_library { |
| 6422 | name: "otherlib", |
| 6423 | srcs: ["mylib.cpp"], |
| 6424 | system_shared_libs: [], |
| 6425 | stl: "none", |
| 6426 | stubs: { |
| 6427 | versions: ["1", "2", "3"], |
| 6428 | }, |
| 6429 | apex_available: [ "myapex" ], |
| 6430 | } |
| 6431 | `) |
| 6432 | } |
| 6433 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 6434 | func TestApexKeysTxt(t *testing.T) { |
| 6435 | ctx, _ := testApex(t, ` |
| 6436 | apex { |
| 6437 | name: "myapex", |
| 6438 | key: "myapex.key", |
| 6439 | } |
| 6440 | |
| 6441 | apex_key { |
| 6442 | name: "myapex.key", |
| 6443 | public_key: "testkey.avbpubkey", |
| 6444 | private_key: "testkey.pem", |
| 6445 | } |
| 6446 | |
| 6447 | prebuilt_apex { |
| 6448 | name: "myapex", |
| 6449 | prefer: true, |
| 6450 | arch: { |
| 6451 | arm64: { |
| 6452 | src: "myapex-arm64.apex", |
| 6453 | }, |
| 6454 | arm: { |
| 6455 | src: "myapex-arm.apex", |
| 6456 | }, |
| 6457 | }, |
| 6458 | } |
| 6459 | |
| 6460 | apex_set { |
| 6461 | name: "myapex_set", |
| 6462 | set: "myapex.apks", |
| 6463 | filename: "myapex_set.apex", |
| 6464 | overrides: ["myapex"], |
| 6465 | } |
| 6466 | `) |
| 6467 | |
| 6468 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 6469 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 6470 | ensureContains(t, content, `name="myapex_set.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`) |
Jiyong Park | 03a7f3e | 2020-06-18 19:34:42 +0900 | [diff] [blame] | 6471 | ensureContains(t, content, `name="myapex.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`) |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 6472 | } |
| 6473 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 6474 | func TestAllowedFiles(t *testing.T) { |
| 6475 | ctx, _ := testApex(t, ` |
| 6476 | apex { |
| 6477 | name: "myapex", |
| 6478 | key: "myapex.key", |
| 6479 | apps: ["app"], |
| 6480 | allowed_files: "allowed.txt", |
| 6481 | } |
| 6482 | |
| 6483 | apex_key { |
| 6484 | name: "myapex.key", |
| 6485 | public_key: "testkey.avbpubkey", |
| 6486 | private_key: "testkey.pem", |
| 6487 | } |
| 6488 | |
| 6489 | android_app { |
| 6490 | name: "app", |
| 6491 | srcs: ["foo/bar/MyClass.java"], |
| 6492 | package_name: "foo", |
| 6493 | sdk_version: "none", |
| 6494 | system_modules: "none", |
| 6495 | apex_available: [ "myapex" ], |
| 6496 | } |
| 6497 | `, withFiles(map[string][]byte{ |
| 6498 | "sub/Android.bp": []byte(` |
| 6499 | override_apex { |
| 6500 | name: "override_myapex", |
| 6501 | base: "myapex", |
| 6502 | apps: ["override_app"], |
| 6503 | allowed_files: ":allowed", |
| 6504 | } |
| 6505 | // Overridable "path" property should be referenced indirectly |
| 6506 | filegroup { |
| 6507 | name: "allowed", |
| 6508 | srcs: ["allowed.txt"], |
| 6509 | } |
| 6510 | override_android_app { |
| 6511 | name: "override_app", |
| 6512 | base: "app", |
| 6513 | package_name: "bar", |
| 6514 | } |
| 6515 | `), |
| 6516 | })) |
| 6517 | |
| 6518 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 6519 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 6520 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 6521 | } |
| 6522 | |
| 6523 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 6524 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 6525 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 6526 | } |
| 6527 | } |
| 6528 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6529 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
| 6530 | _, _ = testApex(t, ` |
| 6531 | apex { |
| 6532 | name: "myapex", |
| 6533 | key: "myapex.key", |
| 6534 | native_shared_libs: ["mylib"], |
| 6535 | } |
| 6536 | |
| 6537 | apex_key { |
| 6538 | name: "myapex.key", |
| 6539 | public_key: "testkey.avbpubkey", |
| 6540 | private_key: "testkey.pem", |
| 6541 | } |
| 6542 | |
| 6543 | cc_library { |
| 6544 | name: "mylib", |
| 6545 | srcs: ["mylib.cpp"], |
| 6546 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 6547 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6548 | }, |
| 6549 | apex_available: ["myapex"], |
| 6550 | } |
| 6551 | |
| 6552 | cc_prebuilt_library_shared { |
| 6553 | name: "mylib", |
| 6554 | prefer: false, |
| 6555 | srcs: ["prebuilt.so"], |
| 6556 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 6557 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6558 | }, |
| 6559 | apex_available: ["myapex"], |
| 6560 | } |
| 6561 | `) |
| 6562 | } |
| 6563 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 6564 | func TestCompressedApex(t *testing.T) { |
| 6565 | ctx, config := testApex(t, ` |
| 6566 | apex { |
| 6567 | name: "myapex", |
| 6568 | key: "myapex.key", |
| 6569 | compressible: true, |
| 6570 | } |
| 6571 | apex_key { |
| 6572 | name: "myapex.key", |
| 6573 | public_key: "testkey.avbpubkey", |
| 6574 | private_key: "testkey.pem", |
| 6575 | } |
| 6576 | `, func(fs map[string][]byte, config android.Config) { |
| 6577 | config.TestProductVariables.CompressedApex = proptools.BoolPtr(true) |
| 6578 | }) |
| 6579 | |
| 6580 | compressRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("compressRule") |
| 6581 | ensureContains(t, compressRule.Output.String(), "myapex.capex.unsigned") |
| 6582 | |
| 6583 | signApkRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("sign compressedApex") |
| 6584 | ensureEquals(t, signApkRule.Input.String(), compressRule.Output.String()) |
| 6585 | |
| 6586 | // Make sure output of bundle is .capex |
| 6587 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 6588 | ensureContains(t, ab.outputFile.String(), "myapex.capex") |
| 6589 | |
| 6590 | // Verify android.mk rules |
| 6591 | data := android.AndroidMkDataForTest(t, config, "", ab) |
| 6592 | var builder strings.Builder |
| 6593 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 6594 | androidMk := builder.String() |
| 6595 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.capex\n") |
| 6596 | } |
| 6597 | |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 6598 | func TestPreferredPrebuiltSharedLibDep(t *testing.T) { |
| 6599 | ctx, config := testApex(t, ` |
| 6600 | apex { |
| 6601 | name: "myapex", |
| 6602 | key: "myapex.key", |
| 6603 | native_shared_libs: ["mylib"], |
| 6604 | } |
| 6605 | |
| 6606 | apex_key { |
| 6607 | name: "myapex.key", |
| 6608 | public_key: "testkey.avbpubkey", |
| 6609 | private_key: "testkey.pem", |
| 6610 | } |
| 6611 | |
| 6612 | cc_library { |
| 6613 | name: "mylib", |
| 6614 | srcs: ["mylib.cpp"], |
| 6615 | apex_available: ["myapex"], |
| 6616 | shared_libs: ["otherlib"], |
| 6617 | system_shared_libs: [], |
| 6618 | } |
| 6619 | |
| 6620 | cc_library { |
| 6621 | name: "otherlib", |
| 6622 | srcs: ["mylib.cpp"], |
| 6623 | stubs: { |
| 6624 | versions: ["current"], |
| 6625 | }, |
| 6626 | } |
| 6627 | |
| 6628 | cc_prebuilt_library_shared { |
| 6629 | name: "otherlib", |
| 6630 | prefer: true, |
| 6631 | srcs: ["prebuilt.so"], |
| 6632 | stubs: { |
| 6633 | versions: ["current"], |
| 6634 | }, |
| 6635 | } |
| 6636 | `) |
| 6637 | |
| 6638 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 6639 | data := android.AndroidMkDataForTest(t, config, "", ab) |
| 6640 | var builder strings.Builder |
| 6641 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 6642 | androidMk := builder.String() |
| 6643 | |
| 6644 | // The make level dependency needs to be on otherlib - prebuilt_otherlib isn't |
| 6645 | // a thing there. |
| 6646 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherlib\n") |
| 6647 | } |
| 6648 | |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 6649 | func TestExcludeDependency(t *testing.T) { |
| 6650 | ctx, _ := testApex(t, ` |
| 6651 | apex { |
| 6652 | name: "myapex", |
| 6653 | key: "myapex.key", |
| 6654 | native_shared_libs: ["mylib"], |
| 6655 | } |
| 6656 | |
| 6657 | apex_key { |
| 6658 | name: "myapex.key", |
| 6659 | public_key: "testkey.avbpubkey", |
| 6660 | private_key: "testkey.pem", |
| 6661 | } |
| 6662 | |
| 6663 | cc_library { |
| 6664 | name: "mylib", |
| 6665 | srcs: ["mylib.cpp"], |
| 6666 | system_shared_libs: [], |
| 6667 | stl: "none", |
| 6668 | apex_available: ["myapex"], |
| 6669 | shared_libs: ["mylib2"], |
| 6670 | target: { |
| 6671 | apex: { |
| 6672 | exclude_shared_libs: ["mylib2"], |
| 6673 | }, |
| 6674 | }, |
| 6675 | } |
| 6676 | |
| 6677 | cc_library { |
| 6678 | name: "mylib2", |
| 6679 | srcs: ["mylib.cpp"], |
| 6680 | system_shared_libs: [], |
| 6681 | stl: "none", |
| 6682 | } |
| 6683 | `) |
| 6684 | |
| 6685 | // Check if mylib is linked to mylib2 for the non-apex target |
| 6686 | ldFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 6687 | ensureContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 6688 | |
| 6689 | // Make sure that the link doesn't occur for the apex target |
| 6690 | ldFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 6691 | ensureNotContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared_apex10000/mylib2.so") |
| 6692 | |
| 6693 | // It shouldn't appear in the copy cmd as well. |
| 6694 | copyCmds := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").Args["copy_commands"] |
| 6695 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 6696 | } |
| 6697 | |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 6698 | func TestPrebuiltStubLibDep(t *testing.T) { |
| 6699 | bpBase := ` |
| 6700 | apex { |
| 6701 | name: "myapex", |
| 6702 | key: "myapex.key", |
| 6703 | native_shared_libs: ["mylib"], |
| 6704 | } |
| 6705 | apex_key { |
| 6706 | name: "myapex.key", |
| 6707 | public_key: "testkey.avbpubkey", |
| 6708 | private_key: "testkey.pem", |
| 6709 | } |
| 6710 | cc_library { |
| 6711 | name: "mylib", |
| 6712 | srcs: ["mylib.cpp"], |
| 6713 | apex_available: ["myapex"], |
| 6714 | shared_libs: ["stublib"], |
| 6715 | system_shared_libs: [], |
| 6716 | } |
| 6717 | apex { |
| 6718 | name: "otherapex", |
| 6719 | enabled: %s, |
| 6720 | key: "myapex.key", |
| 6721 | native_shared_libs: ["stublib"], |
| 6722 | } |
| 6723 | ` |
| 6724 | |
| 6725 | stublibSourceBp := ` |
| 6726 | cc_library { |
| 6727 | name: "stublib", |
| 6728 | srcs: ["mylib.cpp"], |
| 6729 | apex_available: ["otherapex"], |
| 6730 | system_shared_libs: [], |
| 6731 | stl: "none", |
| 6732 | stubs: { |
| 6733 | versions: ["1"], |
| 6734 | }, |
| 6735 | } |
| 6736 | ` |
| 6737 | |
| 6738 | stublibPrebuiltBp := ` |
| 6739 | cc_prebuilt_library_shared { |
| 6740 | name: "stublib", |
| 6741 | srcs: ["prebuilt.so"], |
| 6742 | apex_available: ["otherapex"], |
| 6743 | stubs: { |
| 6744 | versions: ["1"], |
| 6745 | }, |
| 6746 | %s |
| 6747 | } |
| 6748 | ` |
| 6749 | |
| 6750 | tests := []struct { |
| 6751 | name string |
| 6752 | stublibBp string |
| 6753 | usePrebuilt bool |
| 6754 | modNames []string // Modules to collect AndroidMkEntries for |
| 6755 | otherApexEnabled []string |
| 6756 | }{ |
| 6757 | { |
| 6758 | name: "only_source", |
| 6759 | stublibBp: stublibSourceBp, |
| 6760 | usePrebuilt: false, |
| 6761 | modNames: []string{"stublib"}, |
| 6762 | otherApexEnabled: []string{"true", "false"}, |
| 6763 | }, |
| 6764 | { |
| 6765 | name: "source_preferred", |
| 6766 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, ""), |
| 6767 | usePrebuilt: false, |
| 6768 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 6769 | otherApexEnabled: []string{"true", "false"}, |
| 6770 | }, |
| 6771 | { |
| 6772 | name: "prebuilt_preferred", |
| 6773 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, "prefer: true,"), |
| 6774 | usePrebuilt: true, |
| 6775 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 6776 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 6777 | }, |
| 6778 | { |
| 6779 | name: "only_prebuilt", |
| 6780 | stublibBp: fmt.Sprintf(stublibPrebuiltBp, ""), |
| 6781 | usePrebuilt: true, |
| 6782 | modNames: []string{"stublib"}, |
| 6783 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 6784 | }, |
| 6785 | } |
| 6786 | |
| 6787 | for _, test := range tests { |
| 6788 | t.Run(test.name, func(t *testing.T) { |
| 6789 | for _, otherApexEnabled := range test.otherApexEnabled { |
| 6790 | t.Run("otherapex_enabled_"+otherApexEnabled, func(t *testing.T) { |
| 6791 | ctx, config := testApex(t, fmt.Sprintf(bpBase, otherApexEnabled)+test.stublibBp) |
| 6792 | |
| 6793 | type modAndMkEntries struct { |
| 6794 | mod *cc.Module |
| 6795 | mkEntries android.AndroidMkEntries |
| 6796 | } |
| 6797 | entries := []*modAndMkEntries{} |
| 6798 | |
| 6799 | // Gather shared lib modules that are installable |
| 6800 | for _, modName := range test.modNames { |
| 6801 | for _, variant := range ctx.ModuleVariantsForTests(modName) { |
| 6802 | if !strings.HasPrefix(variant, "android_arm64_armv8-a_shared") { |
| 6803 | continue |
| 6804 | } |
| 6805 | mod := ctx.ModuleForTests(modName, variant).Module().(*cc.Module) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 6806 | if !mod.Enabled() || mod.IsHideFromMake() { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 6807 | continue |
| 6808 | } |
| 6809 | for _, ent := range android.AndroidMkEntriesForTest(t, config, "", mod) { |
| 6810 | if ent.Disabled { |
| 6811 | continue |
| 6812 | } |
| 6813 | entries = append(entries, &modAndMkEntries{ |
| 6814 | mod: mod, |
| 6815 | mkEntries: ent, |
| 6816 | }) |
| 6817 | } |
| 6818 | } |
| 6819 | } |
| 6820 | |
| 6821 | var entry *modAndMkEntries = nil |
| 6822 | for _, ent := range entries { |
| 6823 | if strings.Join(ent.mkEntries.EntryMap["LOCAL_MODULE"], ",") == "stublib" { |
| 6824 | if entry != nil { |
| 6825 | t.Errorf("More than one AndroidMk entry for \"stublib\": %s and %s", entry.mod, ent.mod) |
| 6826 | } else { |
| 6827 | entry = ent |
| 6828 | } |
| 6829 | } |
| 6830 | } |
| 6831 | |
| 6832 | if entry == nil { |
| 6833 | t.Errorf("AndroidMk entry for \"stublib\" missing") |
| 6834 | } else { |
| 6835 | isPrebuilt := entry.mod.Prebuilt() != nil |
| 6836 | if isPrebuilt != test.usePrebuilt { |
| 6837 | t.Errorf("Wrong module for \"stublib\" AndroidMk entry: got prebuilt %t, want prebuilt %t", isPrebuilt, test.usePrebuilt) |
| 6838 | } |
| 6839 | if !entry.mod.IsStubs() { |
| 6840 | t.Errorf("Module for \"stublib\" AndroidMk entry isn't a stub: %s", entry.mod) |
| 6841 | } |
| 6842 | if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil { |
| 6843 | t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries) |
| 6844 | } |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 6845 | cflags := entry.mkEntries.EntryMap["LOCAL_EXPORT_CFLAGS"] |
| 6846 | expected := "-D__STUBLIB_API__=1" |
| 6847 | if !android.InList(expected, cflags) { |
| 6848 | t.Errorf("LOCAL_EXPORT_CFLAGS expected to have %q, but got %q", expected, cflags) |
| 6849 | } |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 6850 | } |
| 6851 | }) |
| 6852 | } |
| 6853 | }) |
| 6854 | } |
| 6855 | } |
| 6856 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 6857 | func TestMain(m *testing.M) { |
| 6858 | run := func() int { |
| 6859 | setUp() |
| 6860 | defer tearDown() |
| 6861 | |
| 6862 | return m.Run() |
| 6863 | } |
| 6864 | |
| 6865 | os.Exit(run()) |
| 6866 | } |