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 | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 251 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 252 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 253 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 254 | ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 255 | cc.RegisterVndkLibraryTxtTypes(ctx) |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 256 | prebuilt_etc.RegisterPrebuiltEtcBuildComponents(ctx) |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 257 | ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 258 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 259 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 260 | ctx.RegisterSingletonType("apex_keys_text", apexKeysTextFactory) |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 261 | ctx.RegisterModuleType("bpf", bpf.BpfFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 262 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 263 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 264 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 265 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 266 | ctx.Register() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 267 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 268 | return ctx, config |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 269 | } |
| 270 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 271 | func setUp() { |
| 272 | var err error |
| 273 | buildDir, err = ioutil.TempDir("", "soong_apex_test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 274 | if err != nil { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 275 | panic(err) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 276 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 277 | } |
| 278 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 279 | func tearDown() { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 280 | _ = os.RemoveAll(buildDir) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 281 | } |
| 282 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 283 | // ensure that 'result' equals 'expected' |
| 284 | func ensureEquals(t *testing.T, result string, expected string) { |
| 285 | t.Helper() |
| 286 | if result != expected { |
| 287 | t.Errorf("%q != %q", expected, result) |
| 288 | } |
| 289 | } |
| 290 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 291 | // ensure that 'result' contains 'expected' |
| 292 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 293 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 294 | if !strings.Contains(result, expected) { |
| 295 | t.Errorf("%q is not found in %q", expected, result) |
| 296 | } |
| 297 | } |
| 298 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 299 | // ensure that 'result' contains 'expected' exactly one time |
| 300 | func ensureContainsOnce(t *testing.T, result string, expected string) { |
| 301 | t.Helper() |
| 302 | count := strings.Count(result, expected) |
| 303 | if count != 1 { |
| 304 | t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result) |
| 305 | } |
| 306 | } |
| 307 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 308 | // ensures that 'result' does not contain 'notExpected' |
| 309 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 310 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 311 | if strings.Contains(result, notExpected) { |
| 312 | t.Errorf("%q is found in %q", notExpected, result) |
| 313 | } |
| 314 | } |
| 315 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 316 | func ensureMatches(t *testing.T, result string, expectedRex string) { |
| 317 | ok, err := regexp.MatchString(expectedRex, result) |
| 318 | if err != nil { |
| 319 | t.Fatalf("regexp failure trying to match %s against `%s` expression: %s", result, expectedRex, err) |
| 320 | return |
| 321 | } |
| 322 | if !ok { |
| 323 | t.Errorf("%s does not match regular expession %s", result, expectedRex) |
| 324 | } |
| 325 | } |
| 326 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 327 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 328 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 329 | if !android.InList(expected, result) { |
| 330 | t.Errorf("%q is not found in %v", expected, result) |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 335 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 336 | if android.InList(notExpected, result) { |
| 337 | t.Errorf("%q is found in %v", notExpected, result) |
| 338 | } |
| 339 | } |
| 340 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 341 | func ensureListEmpty(t *testing.T, result []string) { |
| 342 | t.Helper() |
| 343 | if len(result) > 0 { |
| 344 | t.Errorf("%q is expected to be empty", result) |
| 345 | } |
| 346 | } |
| 347 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 348 | func ensureListNotEmpty(t *testing.T, result []string) { |
| 349 | t.Helper() |
| 350 | if len(result) == 0 { |
| 351 | t.Errorf("%q is expected to be not empty", result) |
| 352 | } |
| 353 | } |
| 354 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 355 | // Minimal test |
| 356 | func TestBasicApex(t *testing.T) { |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 357 | ctx, config := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 358 | apex_defaults { |
| 359 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 360 | manifest: ":myapex.manifest", |
| 361 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 362 | key: "myapex.key", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 363 | binaries: ["foo.rust"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 364 | native_shared_libs: [ |
| 365 | "mylib", |
| 366 | "libfoo.ffi", |
| 367 | ], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 368 | rust_dyn_libs: ["libfoo.dylib.rust"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 369 | multilib: { |
| 370 | both: { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 371 | binaries: ["foo"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 372 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 373 | }, |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 374 | java_libs: [ |
| 375 | "myjar", |
| 376 | "myjar_dex", |
| 377 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 378 | } |
| 379 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 380 | apex { |
| 381 | name: "myapex", |
| 382 | defaults: ["myapex-defaults"], |
| 383 | } |
| 384 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 385 | apex_key { |
| 386 | name: "myapex.key", |
| 387 | public_key: "testkey.avbpubkey", |
| 388 | private_key: "testkey.pem", |
| 389 | } |
| 390 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 391 | filegroup { |
| 392 | name: "myapex.manifest", |
| 393 | srcs: ["apex_manifest.json"], |
| 394 | } |
| 395 | |
| 396 | filegroup { |
| 397 | name: "myapex.androidmanifest", |
| 398 | srcs: ["AndroidManifest.xml"], |
| 399 | } |
| 400 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 401 | cc_library { |
| 402 | name: "mylib", |
| 403 | srcs: ["mylib.cpp"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 404 | shared_libs: [ |
| 405 | "mylib2", |
| 406 | "libbar.ffi", |
| 407 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 408 | system_shared_libs: [], |
| 409 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 410 | // TODO: remove //apex_available:platform |
| 411 | apex_available: [ |
| 412 | "//apex_available:platform", |
| 413 | "myapex", |
| 414 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 415 | } |
| 416 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 417 | cc_binary { |
| 418 | name: "foo", |
| 419 | srcs: ["mylib.cpp"], |
| 420 | compile_multilib: "both", |
| 421 | multilib: { |
| 422 | lib32: { |
| 423 | suffix: "32", |
| 424 | }, |
| 425 | lib64: { |
| 426 | suffix: "64", |
| 427 | }, |
| 428 | }, |
| 429 | symlinks: ["foo_link_"], |
| 430 | symlink_preferred_arch: true, |
| 431 | system_shared_libs: [], |
| 432 | static_executable: true, |
| 433 | stl: "none", |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 434 | apex_available: [ "myapex", "com.android.gki.*" ], |
| 435 | } |
| 436 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 437 | rust_binary { |
| 438 | name: "foo.rust", |
| 439 | srcs: ["foo.rs"], |
| 440 | rlibs: ["libfoo.rlib.rust"], |
| 441 | dylibs: ["libfoo.dylib.rust"], |
| 442 | apex_available: ["myapex"], |
| 443 | } |
| 444 | |
| 445 | rust_library_rlib { |
| 446 | name: "libfoo.rlib.rust", |
| 447 | srcs: ["foo.rs"], |
| 448 | crate_name: "foo", |
| 449 | apex_available: ["myapex"], |
| 450 | } |
| 451 | |
| 452 | rust_library_dylib { |
| 453 | name: "libfoo.dylib.rust", |
| 454 | srcs: ["foo.rs"], |
| 455 | crate_name: "foo", |
| 456 | apex_available: ["myapex"], |
| 457 | } |
| 458 | |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 459 | rust_ffi_shared { |
| 460 | name: "libfoo.ffi", |
| 461 | srcs: ["foo.rs"], |
| 462 | crate_name: "foo", |
| 463 | apex_available: ["myapex"], |
| 464 | } |
| 465 | |
| 466 | rust_ffi_shared { |
| 467 | name: "libbar.ffi", |
| 468 | srcs: ["foo.rs"], |
| 469 | crate_name: "bar", |
| 470 | apex_available: ["myapex"], |
| 471 | } |
| 472 | |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 473 | apex { |
| 474 | name: "com.android.gki.fake", |
| 475 | binaries: ["foo"], |
| 476 | key: "myapex.key", |
| 477 | file_contexts: ":myapex-file_contexts", |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 478 | } |
| 479 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 480 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 481 | name: "mylib2", |
| 482 | srcs: ["mylib.cpp"], |
| 483 | system_shared_libs: [], |
| 484 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 485 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 486 | static_libs: ["libstatic"], |
| 487 | // TODO: remove //apex_available:platform |
| 488 | apex_available: [ |
| 489 | "//apex_available:platform", |
| 490 | "myapex", |
| 491 | ], |
| 492 | } |
| 493 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 494 | cc_prebuilt_library_shared { |
| 495 | name: "mylib2", |
| 496 | srcs: ["prebuilt.so"], |
| 497 | // TODO: remove //apex_available:platform |
| 498 | apex_available: [ |
| 499 | "//apex_available:platform", |
| 500 | "myapex", |
| 501 | ], |
| 502 | } |
| 503 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 504 | cc_library_static { |
| 505 | name: "libstatic", |
| 506 | srcs: ["mylib.cpp"], |
| 507 | system_shared_libs: [], |
| 508 | stl: "none", |
| 509 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 510 | // TODO: remove //apex_available:platform |
| 511 | apex_available: [ |
| 512 | "//apex_available:platform", |
| 513 | "myapex", |
| 514 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 515 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 516 | |
| 517 | java_library { |
| 518 | name: "myjar", |
| 519 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 520 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 521 | sdk_version: "none", |
| 522 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 523 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 524 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 525 | // TODO: remove //apex_available:platform |
| 526 | apex_available: [ |
| 527 | "//apex_available:platform", |
| 528 | "myapex", |
| 529 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 530 | } |
| 531 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 532 | dex_import { |
| 533 | name: "myjar_dex", |
| 534 | jars: ["prebuilt.jar"], |
| 535 | apex_available: [ |
| 536 | "//apex_available:platform", |
| 537 | "myapex", |
| 538 | ], |
| 539 | } |
| 540 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 541 | java_library { |
| 542 | name: "myotherjar", |
| 543 | srcs: ["foo/bar/MyClass.java"], |
| 544 | sdk_version: "none", |
| 545 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 546 | // TODO: remove //apex_available:platform |
| 547 | apex_available: [ |
| 548 | "//apex_available:platform", |
| 549 | "myapex", |
| 550 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 551 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 552 | |
| 553 | java_library { |
| 554 | name: "mysharedjar", |
| 555 | srcs: ["foo/bar/MyClass.java"], |
| 556 | sdk_version: "none", |
| 557 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 558 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 559 | `) |
| 560 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 561 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 562 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 563 | // Make sure that Android.mk is created |
| 564 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 565 | data := android.AndroidMkDataForTest(t, config, "", ab) |
| 566 | var builder strings.Builder |
| 567 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 568 | |
| 569 | androidMk := builder.String() |
| 570 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 571 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 572 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 573 | optFlags := apexRule.Args["opt_flags"] |
| 574 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 575 | // Ensure that the NOTICE output is being packaged as an asset. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 576 | 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] | 577 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 578 | copyCmds := apexRule.Args["copy_commands"] |
| 579 | |
| 580 | // Ensure that main rule creates an output |
| 581 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 582 | |
| 583 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 584 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 585 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") |
| 586 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 587 | ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 588 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 589 | |
| 590 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 591 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
| 592 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 593 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000") |
| 594 | 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] | 595 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 596 | |
| 597 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 598 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 599 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 600 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 601 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 602 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 603 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so") |
| 604 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 605 | // .. but not for java libs |
| 606 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 607 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 608 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 609 | // Ensure that the platform variant ends with _shared or _common |
| 610 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 611 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 612 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 613 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 614 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 615 | |
| 616 | // Ensure that dynamic dependency to java libs are not included |
| 617 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 618 | |
| 619 | // Ensure that all symlinks are present. |
| 620 | found_foo_link_64 := false |
| 621 | found_foo := false |
| 622 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 623 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 624 | if strings.HasSuffix(cmd, "bin/foo") { |
| 625 | found_foo = true |
| 626 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 627 | found_foo_link_64 = true |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | good := found_foo && found_foo_link_64 |
| 632 | if !good { |
| 633 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 634 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 635 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 636 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 637 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 638 | if len(noticeInputs) != 3 { |
| 639 | 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] | 640 | } |
| 641 | ensureListContains(t, noticeInputs, "NOTICE") |
| 642 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 643 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 644 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 645 | 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] | 646 | ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex") |
| 647 | ensureListContains(t, fullDepsInfo, " mylib(minSdkVersion:(no version)) <- myapex") |
| 648 | ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib") |
| 649 | ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar") |
| 650 | ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 651 | |
| 652 | 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] | 653 | ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))") |
| 654 | ensureListContains(t, flatDepsInfo, "mylib(minSdkVersion:(no version))") |
| 655 | ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))") |
| 656 | ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))") |
| 657 | ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 658 | } |
| 659 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 660 | func TestDefaults(t *testing.T) { |
| 661 | ctx, _ := testApex(t, ` |
| 662 | apex_defaults { |
| 663 | name: "myapex-defaults", |
| 664 | key: "myapex.key", |
| 665 | prebuilts: ["myetc"], |
| 666 | native_shared_libs: ["mylib"], |
| 667 | java_libs: ["myjar"], |
| 668 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 669 | rros: ["rro"], |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 670 | bpfs: ["bpf"], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | prebuilt_etc { |
| 674 | name: "myetc", |
| 675 | src: "myprebuilt", |
| 676 | } |
| 677 | |
| 678 | apex { |
| 679 | name: "myapex", |
| 680 | defaults: ["myapex-defaults"], |
| 681 | } |
| 682 | |
| 683 | apex_key { |
| 684 | name: "myapex.key", |
| 685 | public_key: "testkey.avbpubkey", |
| 686 | private_key: "testkey.pem", |
| 687 | } |
| 688 | |
| 689 | cc_library { |
| 690 | name: "mylib", |
| 691 | system_shared_libs: [], |
| 692 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 693 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | java_library { |
| 697 | name: "myjar", |
| 698 | srcs: ["foo/bar/MyClass.java"], |
| 699 | sdk_version: "none", |
| 700 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 701 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | android_app { |
| 705 | name: "AppFoo", |
| 706 | srcs: ["foo/bar/MyClass.java"], |
| 707 | sdk_version: "none", |
| 708 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 709 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 710 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 711 | |
| 712 | runtime_resource_overlay { |
| 713 | name: "rro", |
| 714 | theme: "blue", |
| 715 | } |
| 716 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 717 | bpf { |
| 718 | name: "bpf", |
| 719 | srcs: ["bpf.c", "bpf2.c"], |
| 720 | } |
| 721 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 722 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 723 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 724 | "etc/myetc", |
| 725 | "javalib/myjar.jar", |
| 726 | "lib64/mylib.so", |
| 727 | "app/AppFoo/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 728 | "overlay/blue/rro.apk", |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 729 | "etc/bpf/bpf.o", |
| 730 | "etc/bpf/bpf2.o", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 731 | }) |
| 732 | } |
| 733 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 734 | func TestApexManifest(t *testing.T) { |
| 735 | ctx, _ := testApex(t, ` |
| 736 | apex { |
| 737 | name: "myapex", |
| 738 | key: "myapex.key", |
| 739 | } |
| 740 | |
| 741 | apex_key { |
| 742 | name: "myapex.key", |
| 743 | public_key: "testkey.avbpubkey", |
| 744 | private_key: "testkey.pem", |
| 745 | } |
| 746 | `) |
| 747 | |
| 748 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 749 | args := module.Rule("apexRule").Args |
| 750 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 751 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 752 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 753 | } |
| 754 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 755 | func TestBasicZipApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 756 | ctx, _ := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 757 | apex { |
| 758 | name: "myapex", |
| 759 | key: "myapex.key", |
| 760 | payload_type: "zip", |
| 761 | native_shared_libs: ["mylib"], |
| 762 | } |
| 763 | |
| 764 | apex_key { |
| 765 | name: "myapex.key", |
| 766 | public_key: "testkey.avbpubkey", |
| 767 | private_key: "testkey.pem", |
| 768 | } |
| 769 | |
| 770 | cc_library { |
| 771 | name: "mylib", |
| 772 | srcs: ["mylib.cpp"], |
| 773 | shared_libs: ["mylib2"], |
| 774 | system_shared_libs: [], |
| 775 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 776 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | cc_library { |
| 780 | name: "mylib2", |
| 781 | srcs: ["mylib.cpp"], |
| 782 | system_shared_libs: [], |
| 783 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 784 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 785 | } |
| 786 | `) |
| 787 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 788 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 789 | copyCmds := zipApexRule.Args["copy_commands"] |
| 790 | |
| 791 | // Ensure that main rule creates an output |
| 792 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 793 | |
| 794 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 795 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 796 | |
| 797 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 798 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 799 | |
| 800 | // Ensure that both direct and indirect deps are copied into apex |
| 801 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 802 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | func TestApexWithStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 806 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 807 | apex { |
| 808 | name: "myapex", |
| 809 | key: "myapex.key", |
| 810 | native_shared_libs: ["mylib", "mylib3"], |
| 811 | } |
| 812 | |
| 813 | apex_key { |
| 814 | name: "myapex.key", |
| 815 | public_key: "testkey.avbpubkey", |
| 816 | private_key: "testkey.pem", |
| 817 | } |
| 818 | |
| 819 | cc_library { |
| 820 | name: "mylib", |
| 821 | srcs: ["mylib.cpp"], |
| 822 | shared_libs: ["mylib2", "mylib3"], |
| 823 | system_shared_libs: [], |
| 824 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 825 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | cc_library { |
| 829 | name: "mylib2", |
| 830 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 831 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 832 | system_shared_libs: [], |
| 833 | stl: "none", |
| 834 | stubs: { |
| 835 | versions: ["1", "2", "3"], |
| 836 | }, |
| 837 | } |
| 838 | |
| 839 | cc_library { |
| 840 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 841 | srcs: ["mylib.cpp"], |
| 842 | shared_libs: ["mylib4"], |
| 843 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 844 | stl: "none", |
| 845 | stubs: { |
| 846 | versions: ["10", "11", "12"], |
| 847 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 848 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 849 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 850 | |
| 851 | cc_library { |
| 852 | name: "mylib4", |
| 853 | srcs: ["mylib.cpp"], |
| 854 | system_shared_libs: [], |
| 855 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 856 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 857 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 858 | `) |
| 859 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 860 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 861 | copyCmds := apexRule.Args["copy_commands"] |
| 862 | |
| 863 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 864 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 865 | |
| 866 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 867 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 868 | |
| 869 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 870 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 871 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 872 | 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] | 873 | |
| 874 | // 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] | 875 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 876 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 877 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 878 | |
| 879 | // 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] | 880 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 881 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 882 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 883 | |
| 884 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 885 | 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] | 886 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 887 | |
| 888 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 889 | 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] | 890 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 891 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 892 | "lib64/mylib.so", |
| 893 | "lib64/mylib3.so", |
| 894 | "lib64/mylib4.so", |
| 895 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 896 | } |
| 897 | |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 898 | func TestApexWithStubsWithMinSdkVersion(t *testing.T) { |
| 899 | t.Parallel() |
| 900 | ctx, _ := testApex(t, ` |
| 901 | apex { |
| 902 | name: "myapex", |
| 903 | key: "myapex.key", |
| 904 | native_shared_libs: ["mylib", "mylib3"], |
| 905 | min_sdk_version: "29", |
| 906 | } |
| 907 | |
| 908 | apex_key { |
| 909 | name: "myapex.key", |
| 910 | public_key: "testkey.avbpubkey", |
| 911 | private_key: "testkey.pem", |
| 912 | } |
| 913 | |
| 914 | cc_library { |
| 915 | name: "mylib", |
| 916 | srcs: ["mylib.cpp"], |
| 917 | shared_libs: ["mylib2", "mylib3"], |
| 918 | system_shared_libs: [], |
| 919 | stl: "none", |
| 920 | apex_available: [ "myapex" ], |
| 921 | min_sdk_version: "28", |
| 922 | } |
| 923 | |
| 924 | cc_library { |
| 925 | name: "mylib2", |
| 926 | srcs: ["mylib.cpp"], |
| 927 | cflags: ["-include mylib.h"], |
| 928 | system_shared_libs: [], |
| 929 | stl: "none", |
| 930 | stubs: { |
| 931 | versions: ["28", "29", "30", "current"], |
| 932 | }, |
| 933 | min_sdk_version: "28", |
| 934 | } |
| 935 | |
| 936 | cc_library { |
| 937 | name: "mylib3", |
| 938 | srcs: ["mylib.cpp"], |
| 939 | shared_libs: ["mylib4"], |
| 940 | system_shared_libs: [], |
| 941 | stl: "none", |
| 942 | stubs: { |
| 943 | versions: ["28", "29", "30", "current"], |
| 944 | }, |
| 945 | apex_available: [ "myapex" ], |
| 946 | min_sdk_version: "28", |
| 947 | } |
| 948 | |
| 949 | cc_library { |
| 950 | name: "mylib4", |
| 951 | srcs: ["mylib.cpp"], |
| 952 | system_shared_libs: [], |
| 953 | stl: "none", |
| 954 | apex_available: [ "myapex" ], |
| 955 | min_sdk_version: "28", |
| 956 | } |
| 957 | `) |
| 958 | |
| 959 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 960 | copyCmds := apexRule.Args["copy_commands"] |
| 961 | |
| 962 | // Ensure that direct non-stubs dep is always included |
| 963 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 964 | |
| 965 | // Ensure that indirect stubs dep is not included |
| 966 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 967 | |
| 968 | // Ensure that direct stubs dep is included |
| 969 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 970 | |
| 971 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"] |
| 972 | |
| 973 | // Ensure that mylib is linking with the version 29 stubs for mylib2 |
| 974 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_29/mylib2.so") |
| 975 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| 976 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 977 | |
| 978 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| 979 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so") |
| 980 | // .. and not linking to the stubs variant of mylib3 |
| 981 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so") |
| 982 | |
| 983 | // Ensure that stubs libs are built without -include flags |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 984 | 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] | 985 | ensureNotContains(t, mylib2Cflags, "-include ") |
| 986 | |
| 987 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 988 | 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] | 989 | |
| 990 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 991 | "lib64/mylib.so", |
| 992 | "lib64/mylib3.so", |
| 993 | "lib64/mylib4.so", |
| 994 | }) |
| 995 | } |
| 996 | |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 997 | func TestApex_PlatformUsesLatestStubFromApex(t *testing.T) { |
| 998 | t.Parallel() |
| 999 | // myapex (Z) |
| 1000 | // mylib -----------------. |
| 1001 | // | |
| 1002 | // otherapex (29) | |
| 1003 | // libstub's versions: 29 Z current |
| 1004 | // | |
| 1005 | // <platform> | |
| 1006 | // libplatform ----------------' |
| 1007 | ctx, _ := testApex(t, ` |
| 1008 | apex { |
| 1009 | name: "myapex", |
| 1010 | key: "myapex.key", |
| 1011 | native_shared_libs: ["mylib"], |
| 1012 | min_sdk_version: "Z", // non-final |
| 1013 | } |
| 1014 | |
| 1015 | cc_library { |
| 1016 | name: "mylib", |
| 1017 | srcs: ["mylib.cpp"], |
| 1018 | shared_libs: ["libstub"], |
| 1019 | apex_available: ["myapex"], |
| 1020 | min_sdk_version: "Z", |
| 1021 | } |
| 1022 | |
| 1023 | apex_key { |
| 1024 | name: "myapex.key", |
| 1025 | public_key: "testkey.avbpubkey", |
| 1026 | private_key: "testkey.pem", |
| 1027 | } |
| 1028 | |
| 1029 | apex { |
| 1030 | name: "otherapex", |
| 1031 | key: "myapex.key", |
| 1032 | native_shared_libs: ["libstub"], |
| 1033 | min_sdk_version: "29", |
| 1034 | } |
| 1035 | |
| 1036 | cc_library { |
| 1037 | name: "libstub", |
| 1038 | srcs: ["mylib.cpp"], |
| 1039 | stubs: { |
| 1040 | versions: ["29", "Z", "current"], |
| 1041 | }, |
| 1042 | apex_available: ["otherapex"], |
| 1043 | min_sdk_version: "29", |
| 1044 | } |
| 1045 | |
| 1046 | // platform module depending on libstub from otherapex should use the latest stub("current") |
| 1047 | cc_library { |
| 1048 | name: "libplatform", |
| 1049 | srcs: ["mylib.cpp"], |
| 1050 | shared_libs: ["libstub"], |
| 1051 | } |
| 1052 | `, func(fs map[string][]byte, config android.Config) { |
| 1053 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Z") |
| 1054 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
| 1055 | config.TestProductVariables.Platform_version_active_codenames = []string{"Z"} |
| 1056 | }) |
| 1057 | |
| 1058 | // Ensure that mylib from myapex is built against "min_sdk_version" stub ("Z"), which is non-final |
| 1059 | mylibCflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1060 | ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=9000 ") |
| 1061 | mylibLdflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1062 | ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_Z/libstub.so ") |
| 1063 | |
| 1064 | // Ensure that libplatform is built against latest stub ("current") of mylib3 from the apex |
| 1065 | libplatformCflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1066 | ensureContains(t, libplatformCflags, "-D__LIBSTUB_API__=10000 ") // "current" maps to 10000 |
| 1067 | libplatformLdflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1068 | ensureContains(t, libplatformLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
| 1069 | } |
| 1070 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1071 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1072 | ctx, _ := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1073 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1074 | name: "myapex2", |
| 1075 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1076 | native_shared_libs: ["mylib"], |
| 1077 | } |
| 1078 | |
| 1079 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1080 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1081 | public_key: "testkey.avbpubkey", |
| 1082 | private_key: "testkey.pem", |
| 1083 | } |
| 1084 | |
| 1085 | cc_library { |
| 1086 | name: "mylib", |
| 1087 | srcs: ["mylib.cpp"], |
| 1088 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1089 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1090 | system_shared_libs: [], |
| 1091 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1092 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | cc_library { |
| 1096 | name: "libfoo", |
| 1097 | srcs: ["mylib.cpp"], |
| 1098 | shared_libs: ["libbar"], |
| 1099 | system_shared_libs: [], |
| 1100 | stl: "none", |
| 1101 | stubs: { |
| 1102 | versions: ["10", "20", "30"], |
| 1103 | }, |
| 1104 | } |
| 1105 | |
| 1106 | cc_library { |
| 1107 | name: "libbar", |
| 1108 | srcs: ["mylib.cpp"], |
| 1109 | system_shared_libs: [], |
| 1110 | stl: "none", |
| 1111 | } |
| 1112 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1113 | cc_library_static { |
| 1114 | name: "libbaz", |
| 1115 | srcs: ["mylib.cpp"], |
| 1116 | system_shared_libs: [], |
| 1117 | stl: "none", |
| 1118 | apex_available: [ "myapex2" ], |
| 1119 | } |
| 1120 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1121 | `) |
| 1122 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1123 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1124 | copyCmds := apexRule.Args["copy_commands"] |
| 1125 | |
| 1126 | // Ensure that direct non-stubs dep is always included |
| 1127 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1128 | |
| 1129 | // Ensure that indirect stubs dep is not included |
| 1130 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1131 | |
| 1132 | // Ensure that dependency of stubs is not included |
| 1133 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1134 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1135 | 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] | 1136 | |
| 1137 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1138 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1139 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1140 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1141 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1142 | 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] | 1143 | |
| 1144 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 1145 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1146 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1147 | 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] | 1148 | ensureListContains(t, fullDepsInfo, " mylib(minSdkVersion:(no version)) <- myapex2") |
| 1149 | ensureListContains(t, fullDepsInfo, " libbaz(minSdkVersion:(no version)) <- mylib") |
| 1150 | ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1151 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1152 | 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] | 1153 | ensureListContains(t, flatDepsInfo, "mylib(minSdkVersion:(no version))") |
| 1154 | ensureListContains(t, flatDepsInfo, "libbaz(minSdkVersion:(no version))") |
| 1155 | ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1156 | } |
| 1157 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1158 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 1159 | /* |
| 1160 | myapex |
| 1161 | | |
| 1162 | v (runtime_libs) |
| 1163 | mylib ------+------> libfoo [provides stub] |
| 1164 | | |
| 1165 | `------> libbar |
| 1166 | */ |
| 1167 | ctx, _ := testApex(t, ` |
| 1168 | apex { |
| 1169 | name: "myapex", |
| 1170 | key: "myapex.key", |
| 1171 | native_shared_libs: ["mylib"], |
| 1172 | } |
| 1173 | |
| 1174 | apex_key { |
| 1175 | name: "myapex.key", |
| 1176 | public_key: "testkey.avbpubkey", |
| 1177 | private_key: "testkey.pem", |
| 1178 | } |
| 1179 | |
| 1180 | cc_library { |
| 1181 | name: "mylib", |
| 1182 | srcs: ["mylib.cpp"], |
| 1183 | runtime_libs: ["libfoo", "libbar"], |
| 1184 | system_shared_libs: [], |
| 1185 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1186 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | cc_library { |
| 1190 | name: "libfoo", |
| 1191 | srcs: ["mylib.cpp"], |
| 1192 | system_shared_libs: [], |
| 1193 | stl: "none", |
| 1194 | stubs: { |
| 1195 | versions: ["10", "20", "30"], |
| 1196 | }, |
| 1197 | } |
| 1198 | |
| 1199 | cc_library { |
| 1200 | name: "libbar", |
| 1201 | srcs: ["mylib.cpp"], |
| 1202 | system_shared_libs: [], |
| 1203 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1204 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | `) |
| 1208 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1209 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1210 | copyCmds := apexRule.Args["copy_commands"] |
| 1211 | |
| 1212 | // Ensure that direct non-stubs dep is always included |
| 1213 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1214 | |
| 1215 | // Ensure that indirect stubs dep is not included |
| 1216 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1217 | |
| 1218 | // Ensure that runtime_libs dep in included |
| 1219 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1220 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1221 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1222 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1223 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1224 | |
| 1225 | } |
| 1226 | |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1227 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
| 1228 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 1229 | bp := ` |
| 1230 | apex { |
| 1231 | name: "com.android.runtime", |
| 1232 | key: "com.android.runtime.key", |
| 1233 | native_shared_libs: ["libc"], |
| 1234 | } |
| 1235 | |
| 1236 | apex_key { |
| 1237 | name: "com.android.runtime.key", |
| 1238 | public_key: "testkey.avbpubkey", |
| 1239 | private_key: "testkey.pem", |
| 1240 | } |
| 1241 | |
| 1242 | cc_library { |
| 1243 | name: "libc", |
| 1244 | no_libcrt: true, |
| 1245 | nocrt: true, |
| 1246 | stl: "none", |
| 1247 | system_shared_libs: [], |
| 1248 | stubs: { versions: ["1"] }, |
| 1249 | apex_available: ["com.android.runtime"], |
| 1250 | |
| 1251 | sanitize: { |
| 1252 | hwaddress: true, |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | cc_prebuilt_library_shared { |
| 1257 | name: "libclang_rt.hwasan-aarch64-android", |
| 1258 | no_libcrt: true, |
| 1259 | nocrt: true, |
| 1260 | stl: "none", |
| 1261 | system_shared_libs: [], |
| 1262 | srcs: [""], |
| 1263 | stubs: { versions: ["1"] }, |
| 1264 | |
| 1265 | sanitize: { |
| 1266 | never: true, |
| 1267 | }, |
| 1268 | } |
| 1269 | ` |
| 1270 | // override bp to use hard-coded names: com.android.runtime and libc |
| 1271 | fs["Android.bp"] = []byte(bp) |
| 1272 | fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil |
| 1273 | }) |
| 1274 | |
| 1275 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1276 | "lib64/bionic/libc.so", |
| 1277 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1278 | }) |
| 1279 | |
| 1280 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1281 | |
| 1282 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1283 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1284 | |
| 1285 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1286 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1287 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1288 | } |
| 1289 | |
| 1290 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
| 1291 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 1292 | bp := ` |
| 1293 | apex { |
| 1294 | name: "com.android.runtime", |
| 1295 | key: "com.android.runtime.key", |
| 1296 | native_shared_libs: ["libc"], |
| 1297 | } |
| 1298 | |
| 1299 | apex_key { |
| 1300 | name: "com.android.runtime.key", |
| 1301 | public_key: "testkey.avbpubkey", |
| 1302 | private_key: "testkey.pem", |
| 1303 | } |
| 1304 | |
| 1305 | cc_library { |
| 1306 | name: "libc", |
| 1307 | no_libcrt: true, |
| 1308 | nocrt: true, |
| 1309 | stl: "none", |
| 1310 | system_shared_libs: [], |
| 1311 | stubs: { versions: ["1"] }, |
| 1312 | apex_available: ["com.android.runtime"], |
| 1313 | } |
| 1314 | |
| 1315 | cc_prebuilt_library_shared { |
| 1316 | name: "libclang_rt.hwasan-aarch64-android", |
| 1317 | no_libcrt: true, |
| 1318 | nocrt: true, |
| 1319 | stl: "none", |
| 1320 | system_shared_libs: [], |
| 1321 | srcs: [""], |
| 1322 | stubs: { versions: ["1"] }, |
| 1323 | |
| 1324 | sanitize: { |
| 1325 | never: true, |
| 1326 | }, |
| 1327 | } |
| 1328 | ` |
| 1329 | // override bp to use hard-coded names: com.android.runtime and libc |
| 1330 | fs["Android.bp"] = []byte(bp) |
| 1331 | fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil |
| 1332 | |
| 1333 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1334 | }) |
| 1335 | |
| 1336 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1337 | "lib64/bionic/libc.so", |
| 1338 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1339 | }) |
| 1340 | |
| 1341 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1342 | |
| 1343 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1344 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1345 | |
| 1346 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1347 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1348 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1349 | } |
| 1350 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1351 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1352 | testcases := []struct { |
| 1353 | name string |
| 1354 | minSdkVersion string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1355 | apexVariant string |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1356 | shouldLink string |
| 1357 | shouldNotLink []string |
| 1358 | }{ |
| 1359 | { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1360 | name: "should link to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1361 | minSdkVersion: "", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1362 | apexVariant: "apex10000", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1363 | shouldLink: "30", |
| 1364 | shouldNotLink: []string{"29"}, |
| 1365 | }, |
| 1366 | { |
| 1367 | name: "should link to llndk#29", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1368 | minSdkVersion: "min_sdk_version: \"29\",", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1369 | apexVariant: "apex29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1370 | shouldLink: "29", |
| 1371 | shouldNotLink: []string{"30"}, |
| 1372 | }, |
| 1373 | } |
| 1374 | for _, tc := range testcases { |
| 1375 | t.Run(tc.name, func(t *testing.T) { |
| 1376 | ctx, _ := testApex(t, ` |
| 1377 | apex { |
| 1378 | name: "myapex", |
| 1379 | key: "myapex.key", |
| 1380 | use_vendor: true, |
| 1381 | native_shared_libs: ["mylib"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1382 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1383 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1384 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1385 | apex_key { |
| 1386 | name: "myapex.key", |
| 1387 | public_key: "testkey.avbpubkey", |
| 1388 | private_key: "testkey.pem", |
| 1389 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1390 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1391 | cc_library { |
| 1392 | name: "mylib", |
| 1393 | srcs: ["mylib.cpp"], |
| 1394 | vendor_available: true, |
| 1395 | shared_libs: ["libbar"], |
| 1396 | system_shared_libs: [], |
| 1397 | stl: "none", |
| 1398 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1399 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1400 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1401 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1402 | cc_library { |
| 1403 | name: "libbar", |
| 1404 | srcs: ["mylib.cpp"], |
| 1405 | system_shared_libs: [], |
| 1406 | stl: "none", |
| 1407 | stubs: { versions: ["29","30"] }, |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1408 | llndk_stubs: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1409 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1410 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1411 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1412 | name: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1413 | symbol_file: "", |
| 1414 | } |
| 1415 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 1416 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1417 | }, withUnbundledBuild) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1418 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1419 | // Ensure that LLNDK dep is not included |
| 1420 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1421 | "lib64/mylib.so", |
| 1422 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1423 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1424 | // Ensure that LLNDK dep is required |
| 1425 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1426 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1427 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1428 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1429 | 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] | 1430 | 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] | 1431 | for _, ver := range tc.shouldNotLink { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 1432 | 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] | 1433 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1434 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1435 | 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] | 1436 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink) |
| 1437 | }) |
| 1438 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1439 | } |
| 1440 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1441 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1442 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1443 | apex { |
| 1444 | name: "myapex", |
| 1445 | key: "myapex.key", |
| 1446 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 1447 | } |
| 1448 | |
| 1449 | apex_key { |
| 1450 | name: "myapex.key", |
| 1451 | public_key: "testkey.avbpubkey", |
| 1452 | private_key: "testkey.pem", |
| 1453 | } |
| 1454 | |
| 1455 | cc_library { |
| 1456 | name: "mylib", |
| 1457 | srcs: ["mylib.cpp"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1458 | system_shared_libs: ["libc", "libm"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1459 | shared_libs: ["libdl#27"], |
| 1460 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1461 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | cc_library_shared { |
| 1465 | name: "mylib_shared", |
| 1466 | srcs: ["mylib.cpp"], |
| 1467 | shared_libs: ["libdl#27"], |
| 1468 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1469 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1473 | name: "libBootstrap", |
| 1474 | srcs: ["mylib.cpp"], |
| 1475 | stl: "none", |
| 1476 | bootstrap: true, |
| 1477 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1478 | `) |
| 1479 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1480 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1481 | copyCmds := apexRule.Args["copy_commands"] |
| 1482 | |
| 1483 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1484 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1485 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1486 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1487 | |
| 1488 | // 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] | 1489 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1490 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1491 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1492 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1493 | 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] | 1494 | |
| 1495 | // For dependency to libc |
| 1496 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1497 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1498 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1499 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1500 | // ... Cflags from stub is correctly exported to mylib |
| 1501 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 1502 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 1503 | |
| 1504 | // For dependency to libm |
| 1505 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1506 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1507 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1508 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1509 | // ... and is not compiling with the stub |
| 1510 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1511 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1512 | |
| 1513 | // For dependency to libdl |
| 1514 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1515 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1516 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1517 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1518 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1519 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1520 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1521 | // ... Cflags from stub is correctly exported to mylib |
| 1522 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1523 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1524 | |
| 1525 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1526 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1527 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1528 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1529 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1530 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1531 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1532 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1533 | // there are three links between liba --> libz |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1534 | // 1) myapex -> libx -> liba -> libz : this should be #29 link, but fallback to #28 |
| 1535 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1536 | // 3) (platform) -> liba -> libz : this should be non-stub link |
| 1537 | ctx, _ := testApex(t, ` |
| 1538 | apex { |
| 1539 | name: "myapex", |
| 1540 | key: "myapex.key", |
| 1541 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1542 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | apex { |
| 1546 | name: "otherapex", |
| 1547 | key: "myapex.key", |
| 1548 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1549 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | apex_key { |
| 1553 | name: "myapex.key", |
| 1554 | public_key: "testkey.avbpubkey", |
| 1555 | private_key: "testkey.pem", |
| 1556 | } |
| 1557 | |
| 1558 | cc_library { |
| 1559 | name: "libx", |
| 1560 | shared_libs: ["liba"], |
| 1561 | system_shared_libs: [], |
| 1562 | stl: "none", |
| 1563 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1564 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | cc_library { |
| 1568 | name: "liby", |
| 1569 | shared_libs: ["liba"], |
| 1570 | system_shared_libs: [], |
| 1571 | stl: "none", |
| 1572 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1573 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | cc_library { |
| 1577 | name: "liba", |
| 1578 | shared_libs: ["libz"], |
| 1579 | system_shared_libs: [], |
| 1580 | stl: "none", |
| 1581 | apex_available: [ |
| 1582 | "//apex_available:anyapex", |
| 1583 | "//apex_available:platform", |
| 1584 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1585 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | cc_library { |
| 1589 | name: "libz", |
| 1590 | system_shared_libs: [], |
| 1591 | stl: "none", |
| 1592 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1593 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1594 | }, |
| 1595 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1596 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1597 | |
| 1598 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1599 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1600 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1601 | } |
| 1602 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1603 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1604 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1605 | } |
| 1606 | // platform liba is linked to non-stub version |
| 1607 | expectLink("liba", "shared", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1608 | // liba in myapex is linked to #28 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1609 | expectLink("liba", "shared_apex29", "libz", "shared_28") |
| 1610 | expectNoLink("liba", "shared_apex29", "libz", "shared_30") |
| 1611 | expectNoLink("liba", "shared_apex29", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1612 | // liba in otherapex is linked to #30 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1613 | expectLink("liba", "shared_apex30", "libz", "shared_30") |
| 1614 | expectNoLink("liba", "shared_apex30", "libz", "shared_28") |
| 1615 | expectNoLink("liba", "shared_apex30", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1616 | } |
| 1617 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1618 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
| 1619 | ctx, _ := testApex(t, ` |
| 1620 | apex { |
| 1621 | name: "myapex", |
| 1622 | key: "myapex.key", |
| 1623 | native_shared_libs: ["libx"], |
| 1624 | min_sdk_version: "R", |
| 1625 | } |
| 1626 | |
| 1627 | apex_key { |
| 1628 | name: "myapex.key", |
| 1629 | public_key: "testkey.avbpubkey", |
| 1630 | private_key: "testkey.pem", |
| 1631 | } |
| 1632 | |
| 1633 | cc_library { |
| 1634 | name: "libx", |
| 1635 | shared_libs: ["libz"], |
| 1636 | system_shared_libs: [], |
| 1637 | stl: "none", |
| 1638 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1639 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | cc_library { |
| 1643 | name: "libz", |
| 1644 | system_shared_libs: [], |
| 1645 | stl: "none", |
| 1646 | stubs: { |
| 1647 | versions: ["29", "R"], |
| 1648 | }, |
| 1649 | } |
| 1650 | `, func(fs map[string][]byte, config android.Config) { |
| 1651 | config.TestProductVariables.Platform_version_active_codenames = []string{"R"} |
| 1652 | }) |
| 1653 | |
| 1654 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1655 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1656 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1657 | } |
| 1658 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1659 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1660 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1661 | } |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1662 | expectLink("libx", "shared_apex10000", "libz", "shared_R") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1663 | expectNoLink("libx", "shared_apex10000", "libz", "shared_29") |
| 1664 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1665 | } |
| 1666 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1667 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1668 | ctx, _ := testApex(t, ` |
| 1669 | apex { |
| 1670 | name: "myapex", |
| 1671 | key: "myapex.key", |
| 1672 | native_shared_libs: ["libx"], |
| 1673 | } |
| 1674 | |
| 1675 | apex_key { |
| 1676 | name: "myapex.key", |
| 1677 | public_key: "testkey.avbpubkey", |
| 1678 | private_key: "testkey.pem", |
| 1679 | } |
| 1680 | |
| 1681 | cc_library { |
| 1682 | name: "libx", |
| 1683 | shared_libs: ["libz"], |
| 1684 | system_shared_libs: [], |
| 1685 | stl: "none", |
| 1686 | apex_available: [ "myapex" ], |
| 1687 | } |
| 1688 | |
| 1689 | cc_library { |
| 1690 | name: "libz", |
| 1691 | system_shared_libs: [], |
| 1692 | stl: "none", |
| 1693 | stubs: { |
| 1694 | versions: ["1", "2"], |
| 1695 | }, |
| 1696 | } |
| 1697 | `) |
| 1698 | |
| 1699 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1700 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1701 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1702 | } |
| 1703 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1704 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1705 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1706 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1707 | expectLink("libx", "shared_apex10000", "libz", "shared_2") |
| 1708 | expectNoLink("libx", "shared_apex10000", "libz", "shared_1") |
| 1709 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
| 1713 | ctx, _ := testApex(t, ` |
| 1714 | apex { |
| 1715 | name: "myapex", |
| 1716 | key: "myapex.key", |
| 1717 | native_shared_libs: ["libx"], |
| 1718 | } |
| 1719 | |
| 1720 | apex_key { |
| 1721 | name: "myapex.key", |
| 1722 | public_key: "testkey.avbpubkey", |
| 1723 | private_key: "testkey.pem", |
| 1724 | } |
| 1725 | |
| 1726 | cc_library { |
| 1727 | name: "libx", |
| 1728 | system_shared_libs: [], |
| 1729 | stl: "none", |
| 1730 | apex_available: [ "myapex" ], |
| 1731 | stubs: { |
| 1732 | versions: ["1", "2"], |
| 1733 | }, |
| 1734 | } |
| 1735 | |
| 1736 | cc_library { |
| 1737 | name: "libz", |
| 1738 | shared_libs: ["libx"], |
| 1739 | system_shared_libs: [], |
| 1740 | stl: "none", |
| 1741 | } |
| 1742 | `) |
| 1743 | |
| 1744 | expectLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1745 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1746 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1747 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1748 | } |
| 1749 | expectNoLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1750 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1751 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1752 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1753 | } |
| 1754 | expectLink("libz", "shared", "libx", "shared_2") |
| 1755 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1756 | expectNoLink("libz", "shared", "libz", "shared") |
| 1757 | } |
| 1758 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1759 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1760 | ctx, _ := testApex(t, ` |
| 1761 | apex { |
| 1762 | name: "myapex", |
| 1763 | key: "myapex.key", |
| 1764 | native_shared_libs: ["libx"], |
| 1765 | min_sdk_version: "29", |
| 1766 | } |
| 1767 | |
| 1768 | apex_key { |
| 1769 | name: "myapex.key", |
| 1770 | public_key: "testkey.avbpubkey", |
| 1771 | private_key: "testkey.pem", |
| 1772 | } |
| 1773 | |
| 1774 | cc_library { |
| 1775 | name: "libx", |
| 1776 | shared_libs: ["libbar"], |
| 1777 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1778 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | cc_library { |
| 1782 | name: "libbar", |
| 1783 | stubs: { |
| 1784 | versions: ["29", "30"], |
| 1785 | }, |
| 1786 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1787 | `, func(fs map[string][]byte, config android.Config) { |
| 1788 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1789 | }) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1790 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1791 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1792 | libFlags := ld.Args["libFlags"] |
| 1793 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1794 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1795 | expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_30") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1796 | } |
| 1797 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1798 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1799 | ctx, _ := testApex(t, ` |
| 1800 | apex { |
| 1801 | name: "myapex", |
| 1802 | key: "myapex.key", |
| 1803 | native_shared_libs: ["libx"], |
| 1804 | min_sdk_version: "29", |
| 1805 | } |
| 1806 | |
| 1807 | apex_key { |
| 1808 | name: "myapex.key", |
| 1809 | public_key: "testkey.avbpubkey", |
| 1810 | private_key: "testkey.pem", |
| 1811 | } |
| 1812 | |
| 1813 | cc_library { |
| 1814 | name: "libx", |
| 1815 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1816 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1817 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1818 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1819 | |
| 1820 | // ensure apex variant of c++ is linked with static unwinder |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1821 | 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] | 1822 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1823 | // note that platform variant is not. |
| 1824 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 1825 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1826 | } |
| 1827 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1828 | func TestApexMinSdkVersion_ErrorIfIncompatibleStubs(t *testing.T) { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1829 | testApexError(t, `"libz" .*: not found a version\(<=29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1830 | apex { |
| 1831 | name: "myapex", |
| 1832 | key: "myapex.key", |
| 1833 | native_shared_libs: ["libx"], |
| 1834 | min_sdk_version: "29", |
| 1835 | } |
| 1836 | |
| 1837 | apex_key { |
| 1838 | name: "myapex.key", |
| 1839 | public_key: "testkey.avbpubkey", |
| 1840 | private_key: "testkey.pem", |
| 1841 | } |
| 1842 | |
| 1843 | cc_library { |
| 1844 | name: "libx", |
| 1845 | shared_libs: ["libz"], |
| 1846 | system_shared_libs: [], |
| 1847 | stl: "none", |
| 1848 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1849 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | cc_library { |
| 1853 | name: "libz", |
| 1854 | system_shared_libs: [], |
| 1855 | stl: "none", |
| 1856 | stubs: { |
| 1857 | versions: ["30"], |
| 1858 | }, |
| 1859 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1860 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1861 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1862 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1863 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 1864 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1865 | apex { |
| 1866 | name: "myapex", |
| 1867 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1868 | native_shared_libs: ["mylib"], |
| 1869 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | apex_key { |
| 1873 | name: "myapex.key", |
| 1874 | public_key: "testkey.avbpubkey", |
| 1875 | private_key: "testkey.pem", |
| 1876 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1877 | |
| 1878 | cc_library { |
| 1879 | name: "mylib", |
| 1880 | srcs: ["mylib.cpp"], |
| 1881 | system_shared_libs: [], |
| 1882 | stl: "none", |
| 1883 | apex_available: [ |
| 1884 | "myapex", |
| 1885 | ], |
| 1886 | min_sdk_version: "30", |
| 1887 | } |
| 1888 | `) |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1889 | |
| 1890 | testApexError(t, `module "libfoo.ffi".*: should support min_sdk_version\(29\)`, ` |
| 1891 | apex { |
| 1892 | name: "myapex", |
| 1893 | key: "myapex.key", |
| 1894 | native_shared_libs: ["libfoo.ffi"], |
| 1895 | min_sdk_version: "29", |
| 1896 | } |
| 1897 | |
| 1898 | apex_key { |
| 1899 | name: "myapex.key", |
| 1900 | public_key: "testkey.avbpubkey", |
| 1901 | private_key: "testkey.pem", |
| 1902 | } |
| 1903 | |
| 1904 | rust_ffi_shared { |
| 1905 | name: "libfoo.ffi", |
| 1906 | srcs: ["foo.rs"], |
| 1907 | crate_name: "foo", |
| 1908 | apex_available: [ |
| 1909 | "myapex", |
| 1910 | ], |
| 1911 | min_sdk_version: "30", |
| 1912 | } |
| 1913 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 1917 | testApex(t, ` |
| 1918 | apex { |
| 1919 | name: "myapex", |
| 1920 | key: "myapex.key", |
| 1921 | native_shared_libs: ["libfoo"], |
| 1922 | java_libs: ["libbar"], |
| 1923 | min_sdk_version: "29", |
| 1924 | } |
| 1925 | |
| 1926 | apex_key { |
| 1927 | name: "myapex.key", |
| 1928 | public_key: "testkey.avbpubkey", |
| 1929 | private_key: "testkey.pem", |
| 1930 | } |
| 1931 | |
| 1932 | cc_library { |
| 1933 | name: "libfoo", |
| 1934 | srcs: ["mylib.cpp"], |
| 1935 | shared_libs: ["libfoo_dep"], |
| 1936 | apex_available: ["myapex"], |
| 1937 | min_sdk_version: "29", |
| 1938 | } |
| 1939 | |
| 1940 | cc_library { |
| 1941 | name: "libfoo_dep", |
| 1942 | srcs: ["mylib.cpp"], |
| 1943 | apex_available: ["myapex"], |
| 1944 | min_sdk_version: "29", |
| 1945 | } |
| 1946 | |
| 1947 | java_library { |
| 1948 | name: "libbar", |
| 1949 | sdk_version: "current", |
| 1950 | srcs: ["a.java"], |
| 1951 | static_libs: ["libbar_dep"], |
| 1952 | apex_available: ["myapex"], |
| 1953 | min_sdk_version: "29", |
| 1954 | } |
| 1955 | |
| 1956 | java_library { |
| 1957 | name: "libbar_dep", |
| 1958 | sdk_version: "current", |
| 1959 | srcs: ["a.java"], |
| 1960 | apex_available: ["myapex"], |
| 1961 | min_sdk_version: "29", |
| 1962 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1963 | `) |
| 1964 | } |
| 1965 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1966 | func TestJavaStableSdkVersion(t *testing.T) { |
| 1967 | testCases := []struct { |
| 1968 | name string |
| 1969 | expectedError string |
| 1970 | bp string |
| 1971 | }{ |
| 1972 | { |
| 1973 | name: "Non-updatable apex with non-stable dep", |
| 1974 | bp: ` |
| 1975 | apex { |
| 1976 | name: "myapex", |
| 1977 | java_libs: ["myjar"], |
| 1978 | key: "myapex.key", |
| 1979 | } |
| 1980 | apex_key { |
| 1981 | name: "myapex.key", |
| 1982 | public_key: "testkey.avbpubkey", |
| 1983 | private_key: "testkey.pem", |
| 1984 | } |
| 1985 | java_library { |
| 1986 | name: "myjar", |
| 1987 | srcs: ["foo/bar/MyClass.java"], |
| 1988 | sdk_version: "core_platform", |
| 1989 | apex_available: ["myapex"], |
| 1990 | } |
| 1991 | `, |
| 1992 | }, |
| 1993 | { |
| 1994 | name: "Updatable apex with stable dep", |
| 1995 | bp: ` |
| 1996 | apex { |
| 1997 | name: "myapex", |
| 1998 | java_libs: ["myjar"], |
| 1999 | key: "myapex.key", |
| 2000 | updatable: true, |
| 2001 | min_sdk_version: "29", |
| 2002 | } |
| 2003 | apex_key { |
| 2004 | name: "myapex.key", |
| 2005 | public_key: "testkey.avbpubkey", |
| 2006 | private_key: "testkey.pem", |
| 2007 | } |
| 2008 | java_library { |
| 2009 | name: "myjar", |
| 2010 | srcs: ["foo/bar/MyClass.java"], |
| 2011 | sdk_version: "current", |
| 2012 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2013 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2014 | } |
| 2015 | `, |
| 2016 | }, |
| 2017 | { |
| 2018 | name: "Updatable apex with non-stable dep", |
| 2019 | expectedError: "cannot depend on \"myjar\"", |
| 2020 | bp: ` |
| 2021 | apex { |
| 2022 | name: "myapex", |
| 2023 | java_libs: ["myjar"], |
| 2024 | key: "myapex.key", |
| 2025 | updatable: true, |
| 2026 | } |
| 2027 | apex_key { |
| 2028 | name: "myapex.key", |
| 2029 | public_key: "testkey.avbpubkey", |
| 2030 | private_key: "testkey.pem", |
| 2031 | } |
| 2032 | java_library { |
| 2033 | name: "myjar", |
| 2034 | srcs: ["foo/bar/MyClass.java"], |
| 2035 | sdk_version: "core_platform", |
| 2036 | apex_available: ["myapex"], |
| 2037 | } |
| 2038 | `, |
| 2039 | }, |
| 2040 | { |
| 2041 | name: "Updatable apex with non-stable transitive dep", |
| 2042 | expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against non-public Android API.", |
| 2043 | bp: ` |
| 2044 | apex { |
| 2045 | name: "myapex", |
| 2046 | java_libs: ["myjar"], |
| 2047 | key: "myapex.key", |
| 2048 | updatable: true, |
| 2049 | } |
| 2050 | apex_key { |
| 2051 | name: "myapex.key", |
| 2052 | public_key: "testkey.avbpubkey", |
| 2053 | private_key: "testkey.pem", |
| 2054 | } |
| 2055 | java_library { |
| 2056 | name: "myjar", |
| 2057 | srcs: ["foo/bar/MyClass.java"], |
| 2058 | sdk_version: "current", |
| 2059 | apex_available: ["myapex"], |
| 2060 | static_libs: ["transitive-jar"], |
| 2061 | } |
| 2062 | java_library { |
| 2063 | name: "transitive-jar", |
| 2064 | srcs: ["foo/bar/MyClass.java"], |
| 2065 | sdk_version: "core_platform", |
| 2066 | apex_available: ["myapex"], |
| 2067 | } |
| 2068 | `, |
| 2069 | }, |
| 2070 | } |
| 2071 | |
| 2072 | for _, test := range testCases { |
| 2073 | t.Run(test.name, func(t *testing.T) { |
| 2074 | if test.expectedError == "" { |
| 2075 | testApex(t, test.bp) |
| 2076 | } else { |
| 2077 | testApexError(t, test.expectedError, test.bp) |
| 2078 | } |
| 2079 | }) |
| 2080 | } |
| 2081 | } |
| 2082 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2083 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 2084 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2085 | apex { |
| 2086 | name: "myapex", |
| 2087 | key: "myapex.key", |
| 2088 | native_shared_libs: ["mylib"], |
| 2089 | min_sdk_version: "29", |
| 2090 | } |
| 2091 | |
| 2092 | apex_key { |
| 2093 | name: "myapex.key", |
| 2094 | public_key: "testkey.avbpubkey", |
| 2095 | private_key: "testkey.pem", |
| 2096 | } |
| 2097 | |
| 2098 | cc_library { |
| 2099 | name: "mylib", |
| 2100 | srcs: ["mylib.cpp"], |
| 2101 | shared_libs: ["mylib2"], |
| 2102 | system_shared_libs: [], |
| 2103 | stl: "none", |
| 2104 | apex_available: [ |
| 2105 | "myapex", |
| 2106 | ], |
| 2107 | min_sdk_version: "29", |
| 2108 | } |
| 2109 | |
| 2110 | // indirect part of the apex |
| 2111 | cc_library { |
| 2112 | name: "mylib2", |
| 2113 | srcs: ["mylib.cpp"], |
| 2114 | system_shared_libs: [], |
| 2115 | stl: "none", |
| 2116 | apex_available: [ |
| 2117 | "myapex", |
| 2118 | ], |
| 2119 | min_sdk_version: "30", |
| 2120 | } |
| 2121 | `) |
| 2122 | } |
| 2123 | |
| 2124 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 2125 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2126 | apex { |
| 2127 | name: "myapex", |
| 2128 | key: "myapex.key", |
| 2129 | apps: ["AppFoo"], |
| 2130 | min_sdk_version: "29", |
| 2131 | } |
| 2132 | |
| 2133 | apex_key { |
| 2134 | name: "myapex.key", |
| 2135 | public_key: "testkey.avbpubkey", |
| 2136 | private_key: "testkey.pem", |
| 2137 | } |
| 2138 | |
| 2139 | android_app { |
| 2140 | name: "AppFoo", |
| 2141 | srcs: ["foo/bar/MyClass.java"], |
| 2142 | sdk_version: "current", |
| 2143 | min_sdk_version: "29", |
| 2144 | system_modules: "none", |
| 2145 | stl: "none", |
| 2146 | static_libs: ["bar"], |
| 2147 | apex_available: [ "myapex" ], |
| 2148 | } |
| 2149 | |
| 2150 | java_library { |
| 2151 | name: "bar", |
| 2152 | sdk_version: "current", |
| 2153 | srcs: ["a.java"], |
| 2154 | apex_available: [ "myapex" ], |
| 2155 | } |
| 2156 | `) |
| 2157 | } |
| 2158 | |
| 2159 | func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) { |
| 2160 | ctx, _ := testApex(t, ` |
| 2161 | apex { |
| 2162 | name: "myapex", |
| 2163 | key: "myapex.key", |
| 2164 | native_shared_libs: ["mylib"], |
| 2165 | min_sdk_version: "29", |
| 2166 | } |
| 2167 | |
| 2168 | apex_key { |
| 2169 | name: "myapex.key", |
| 2170 | public_key: "testkey.avbpubkey", |
| 2171 | private_key: "testkey.pem", |
| 2172 | } |
| 2173 | |
| 2174 | // mylib in myapex will link to mylib2#29 |
| 2175 | // mylib in otherapex will link to mylib2(non-stub) in otherapex as well |
| 2176 | cc_library { |
| 2177 | name: "mylib", |
| 2178 | srcs: ["mylib.cpp"], |
| 2179 | shared_libs: ["mylib2"], |
| 2180 | system_shared_libs: [], |
| 2181 | stl: "none", |
| 2182 | apex_available: ["myapex", "otherapex"], |
| 2183 | min_sdk_version: "29", |
| 2184 | } |
| 2185 | |
| 2186 | cc_library { |
| 2187 | name: "mylib2", |
| 2188 | srcs: ["mylib.cpp"], |
| 2189 | system_shared_libs: [], |
| 2190 | stl: "none", |
| 2191 | apex_available: ["otherapex"], |
| 2192 | stubs: { versions: ["29", "30"] }, |
| 2193 | min_sdk_version: "30", |
| 2194 | } |
| 2195 | |
| 2196 | apex { |
| 2197 | name: "otherapex", |
| 2198 | key: "myapex.key", |
| 2199 | native_shared_libs: ["mylib", "mylib2"], |
| 2200 | min_sdk_version: "30", |
| 2201 | } |
| 2202 | `) |
| 2203 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2204 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2205 | libFlags := ld.Args["libFlags"] |
| 2206 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2207 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2208 | expectLink("mylib", "shared_apex29", "mylib2", "shared_29") |
| 2209 | expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2210 | } |
| 2211 | |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2212 | func TestApexMinSdkVersion_WorksWithSdkCodename(t *testing.T) { |
| 2213 | withSAsActiveCodeNames := func(fs map[string][]byte, config android.Config) { |
| 2214 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2215 | config.TestProductVariables.Platform_version_active_codenames = []string{"S"} |
| 2216 | } |
| 2217 | testApexError(t, `libbar.*: should support min_sdk_version\(S\)`, ` |
| 2218 | apex { |
| 2219 | name: "myapex", |
| 2220 | key: "myapex.key", |
| 2221 | native_shared_libs: ["libfoo"], |
| 2222 | min_sdk_version: "S", |
| 2223 | } |
| 2224 | apex_key { |
| 2225 | name: "myapex.key", |
| 2226 | public_key: "testkey.avbpubkey", |
| 2227 | private_key: "testkey.pem", |
| 2228 | } |
| 2229 | cc_library { |
| 2230 | name: "libfoo", |
| 2231 | shared_libs: ["libbar"], |
| 2232 | apex_available: ["myapex"], |
| 2233 | min_sdk_version: "29", |
| 2234 | } |
| 2235 | cc_library { |
| 2236 | name: "libbar", |
| 2237 | apex_available: ["myapex"], |
| 2238 | } |
| 2239 | `, withSAsActiveCodeNames) |
| 2240 | } |
| 2241 | |
| 2242 | func TestApexMinSdkVersion_WorksWithActiveCodenames(t *testing.T) { |
| 2243 | withSAsActiveCodeNames := func(fs map[string][]byte, config android.Config) { |
| 2244 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2245 | config.TestProductVariables.Platform_version_active_codenames = []string{"S", "T"} |
| 2246 | } |
| 2247 | ctx, _ := testApex(t, ` |
| 2248 | apex { |
| 2249 | name: "myapex", |
| 2250 | key: "myapex.key", |
| 2251 | native_shared_libs: ["libfoo"], |
| 2252 | min_sdk_version: "S", |
| 2253 | } |
| 2254 | apex_key { |
| 2255 | name: "myapex.key", |
| 2256 | public_key: "testkey.avbpubkey", |
| 2257 | private_key: "testkey.pem", |
| 2258 | } |
| 2259 | cc_library { |
| 2260 | name: "libfoo", |
| 2261 | shared_libs: ["libbar"], |
| 2262 | apex_available: ["myapex"], |
| 2263 | min_sdk_version: "S", |
| 2264 | } |
| 2265 | cc_library { |
| 2266 | name: "libbar", |
| 2267 | stubs: { |
| 2268 | symbol_file: "libbar.map.txt", |
| 2269 | versions: ["30", "S", "T"], |
| 2270 | }, |
| 2271 | } |
| 2272 | `, withSAsActiveCodeNames) |
| 2273 | |
| 2274 | // ensure libfoo is linked with "S" version of libbar stub |
| 2275 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_apex10000") |
| 2276 | libFlags := libfoo.Rule("ld").Args["libFlags"] |
| 2277 | ensureContains(t, libFlags, "android_arm64_armv8-a_shared_S/libbar.so") |
| 2278 | } |
| 2279 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2280 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2281 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2282 | apex { |
| 2283 | name: "myapex", |
| 2284 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2285 | native_shared_libs: ["mylib"], |
| 2286 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2287 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2288 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | apex_key { |
| 2292 | name: "myapex.key", |
| 2293 | public_key: "testkey.avbpubkey", |
| 2294 | private_key: "testkey.pem", |
| 2295 | } |
| 2296 | |
| 2297 | prebuilt_etc { |
| 2298 | name: "myetc", |
| 2299 | src: "myprebuilt", |
| 2300 | sub_dir: "foo/bar", |
| 2301 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2302 | |
| 2303 | cc_library { |
| 2304 | name: "mylib", |
| 2305 | srcs: ["mylib.cpp"], |
| 2306 | relative_install_path: "foo/bar", |
| 2307 | system_shared_libs: [], |
| 2308 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2309 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | cc_binary { |
| 2313 | name: "mybin", |
| 2314 | srcs: ["mylib.cpp"], |
| 2315 | relative_install_path: "foo/bar", |
| 2316 | system_shared_libs: [], |
| 2317 | static_executable: true, |
| 2318 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2319 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2320 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2321 | `) |
| 2322 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2323 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2324 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 2325 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2326 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2327 | ensureListContains(t, dirs, "etc") |
| 2328 | ensureListContains(t, dirs, "etc/foo") |
| 2329 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2330 | ensureListContains(t, dirs, "lib64") |
| 2331 | ensureListContains(t, dirs, "lib64/foo") |
| 2332 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 2333 | ensureListContains(t, dirs, "lib") |
| 2334 | ensureListContains(t, dirs, "lib/foo") |
| 2335 | ensureListContains(t, dirs, "lib/foo/bar") |
| 2336 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 2337 | ensureListContains(t, dirs, "bin") |
| 2338 | ensureListContains(t, dirs, "bin/foo") |
| 2339 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2340 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2341 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2342 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
| 2343 | ctx, _ := testApex(t, ` |
| 2344 | apex { |
| 2345 | name: "myapex", |
| 2346 | key: "myapex.key", |
| 2347 | multilib: { |
| 2348 | both: { |
| 2349 | native_shared_libs: ["mylib"], |
| 2350 | binaries: ["mybin"], |
| 2351 | }, |
| 2352 | }, |
| 2353 | compile_multilib: "both", |
| 2354 | native_bridge_supported: true, |
| 2355 | } |
| 2356 | |
| 2357 | apex_key { |
| 2358 | name: "myapex.key", |
| 2359 | public_key: "testkey.avbpubkey", |
| 2360 | private_key: "testkey.pem", |
| 2361 | } |
| 2362 | |
| 2363 | cc_library { |
| 2364 | name: "mylib", |
| 2365 | relative_install_path: "foo/bar", |
| 2366 | system_shared_libs: [], |
| 2367 | stl: "none", |
| 2368 | apex_available: [ "myapex" ], |
| 2369 | native_bridge_supported: true, |
| 2370 | } |
| 2371 | |
| 2372 | cc_binary { |
| 2373 | name: "mybin", |
| 2374 | relative_install_path: "foo/bar", |
| 2375 | system_shared_libs: [], |
| 2376 | static_executable: true, |
| 2377 | stl: "none", |
| 2378 | apex_available: [ "myapex" ], |
| 2379 | native_bridge_supported: true, |
| 2380 | compile_multilib: "both", // default is "first" for binary |
| 2381 | multilib: { |
| 2382 | lib64: { |
| 2383 | suffix: "64", |
| 2384 | }, |
| 2385 | }, |
| 2386 | } |
| 2387 | `, withNativeBridgeEnabled) |
| 2388 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2389 | "bin/foo/bar/mybin", |
| 2390 | "bin/foo/bar/mybin64", |
| 2391 | "bin/arm/foo/bar/mybin", |
| 2392 | "bin/arm64/foo/bar/mybin64", |
| 2393 | "lib/foo/bar/mylib.so", |
| 2394 | "lib/arm/foo/bar/mylib.so", |
| 2395 | "lib64/foo/bar/mylib.so", |
| 2396 | "lib64/arm64/foo/bar/mylib.so", |
| 2397 | }) |
| 2398 | } |
| 2399 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2400 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2401 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2402 | apex { |
| 2403 | name: "myapex", |
| 2404 | key: "myapex.key", |
| 2405 | native_shared_libs: ["mylib"], |
| 2406 | use_vendor: true, |
| 2407 | } |
| 2408 | |
| 2409 | apex_key { |
| 2410 | name: "myapex.key", |
| 2411 | public_key: "testkey.avbpubkey", |
| 2412 | private_key: "testkey.pem", |
| 2413 | } |
| 2414 | |
| 2415 | cc_library { |
| 2416 | name: "mylib", |
| 2417 | srcs: ["mylib.cpp"], |
| 2418 | shared_libs: ["mylib2"], |
| 2419 | system_shared_libs: [], |
| 2420 | vendor_available: true, |
| 2421 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2422 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | cc_library { |
| 2426 | name: "mylib2", |
| 2427 | srcs: ["mylib.cpp"], |
| 2428 | system_shared_libs: [], |
| 2429 | vendor_available: true, |
| 2430 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2431 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2432 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2433 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2434 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2435 | }) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2436 | |
| 2437 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2438 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2439 | for _, implicit := range i.Implicits { |
| 2440 | inputsList = append(inputsList, implicit.String()) |
| 2441 | } |
| 2442 | } |
| 2443 | inputsString := strings.Join(inputsList, " ") |
| 2444 | |
| 2445 | // 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] | 2446 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2447 | 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] | 2448 | |
| 2449 | // ensure that the apex does not include core variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2450 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2451 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2452 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2453 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2454 | func TestUseVendorNotAllowedForSystemApexes(t *testing.T) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2455 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 2456 | apex { |
| 2457 | name: "myapex", |
| 2458 | key: "myapex.key", |
| 2459 | use_vendor: true, |
| 2460 | } |
| 2461 | apex_key { |
| 2462 | name: "myapex.key", |
| 2463 | public_key: "testkey.avbpubkey", |
| 2464 | private_key: "testkey.pem", |
| 2465 | } |
| 2466 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2467 | setUseVendorAllowListForTest(config, []string{""}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2468 | }) |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2469 | // no error with allow list |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2470 | testApex(t, ` |
| 2471 | apex { |
| 2472 | name: "myapex", |
| 2473 | key: "myapex.key", |
| 2474 | use_vendor: true, |
| 2475 | } |
| 2476 | apex_key { |
| 2477 | name: "myapex.key", |
| 2478 | public_key: "testkey.avbpubkey", |
| 2479 | private_key: "testkey.pem", |
| 2480 | } |
| 2481 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2482 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2483 | }) |
| 2484 | } |
| 2485 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2486 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 2487 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 2488 | apex { |
| 2489 | name: "myapex", |
| 2490 | key: "myapex.key", |
| 2491 | native_shared_libs: ["mylib"], |
| 2492 | use_vendor: true, |
| 2493 | } |
| 2494 | |
| 2495 | apex_key { |
| 2496 | name: "myapex.key", |
| 2497 | public_key: "testkey.avbpubkey", |
| 2498 | private_key: "testkey.pem", |
| 2499 | } |
| 2500 | |
| 2501 | cc_library { |
| 2502 | name: "mylib", |
| 2503 | srcs: ["mylib.cpp"], |
| 2504 | system_shared_libs: [], |
| 2505 | stl: "none", |
| 2506 | } |
| 2507 | `) |
| 2508 | } |
| 2509 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2510 | func TestVendorApex(t *testing.T) { |
| 2511 | ctx, config := testApex(t, ` |
| 2512 | apex { |
| 2513 | name: "myapex", |
| 2514 | key: "myapex.key", |
| 2515 | binaries: ["mybin"], |
| 2516 | vendor: true, |
| 2517 | } |
| 2518 | apex_key { |
| 2519 | name: "myapex.key", |
| 2520 | public_key: "testkey.avbpubkey", |
| 2521 | private_key: "testkey.pem", |
| 2522 | } |
| 2523 | cc_binary { |
| 2524 | name: "mybin", |
| 2525 | vendor: true, |
| 2526 | shared_libs: ["libfoo"], |
| 2527 | } |
| 2528 | cc_library { |
| 2529 | name: "libfoo", |
| 2530 | proprietary: true, |
| 2531 | } |
| 2532 | `) |
| 2533 | |
| 2534 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2535 | "bin/mybin", |
| 2536 | "lib64/libfoo.so", |
| 2537 | // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX |
| 2538 | "lib64/libc++.so", |
| 2539 | }) |
| 2540 | |
| 2541 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2542 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2543 | name := apexBundle.BaseModuleName() |
| 2544 | prefix := "TARGET_" |
| 2545 | var builder strings.Builder |
| 2546 | data.Custom(&builder, name, prefix, "", data) |
| 2547 | androidMk := builder.String() |
| 2548 | 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] | 2549 | |
| 2550 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2551 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2552 | ensureListNotContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2553 | } |
| 2554 | |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2555 | func TestVendorApex_use_vndk_as_stable(t *testing.T) { |
| 2556 | ctx, _ := testApex(t, ` |
| 2557 | apex { |
| 2558 | name: "myapex", |
| 2559 | key: "myapex.key", |
| 2560 | binaries: ["mybin"], |
| 2561 | vendor: true, |
| 2562 | use_vndk_as_stable: true, |
| 2563 | } |
| 2564 | apex_key { |
| 2565 | name: "myapex.key", |
| 2566 | public_key: "testkey.avbpubkey", |
| 2567 | private_key: "testkey.pem", |
| 2568 | } |
| 2569 | cc_binary { |
| 2570 | name: "mybin", |
| 2571 | vendor: true, |
| 2572 | shared_libs: ["libvndk", "libvendor"], |
| 2573 | } |
| 2574 | cc_library { |
| 2575 | name: "libvndk", |
| 2576 | vndk: { |
| 2577 | enabled: true, |
| 2578 | }, |
| 2579 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2580 | product_available: true, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2581 | } |
| 2582 | cc_library { |
| 2583 | name: "libvendor", |
| 2584 | vendor: true, |
| 2585 | } |
| 2586 | `) |
| 2587 | |
| 2588 | vendorVariant := "android_vendor.VER_arm64_armv8-a" |
| 2589 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2590 | ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_apex10000").Rule("ld") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2591 | libs := names(ldRule.Args["libFlags"]) |
| 2592 | // VNDK libs(libvndk/libc++) as they are |
| 2593 | ensureListContains(t, libs, buildDir+"/.intermediates/libvndk/"+vendorVariant+"_shared/libvndk.so") |
| 2594 | ensureListContains(t, libs, buildDir+"/.intermediates/libc++/"+vendorVariant+"_shared/libc++.so") |
| 2595 | // non-stable Vendor libs as APEX variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2596 | ensureListContains(t, libs, buildDir+"/.intermediates/libvendor/"+vendorVariant+"_shared_apex10000/libvendor.so") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2597 | |
| 2598 | // VNDK libs are not included when use_vndk_as_stable: true |
| 2599 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2600 | "bin/mybin", |
| 2601 | "lib64/libvendor.so", |
| 2602 | }) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2603 | |
| 2604 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2605 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2606 | ensureListContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2607 | } |
| 2608 | |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2609 | func TestApex_withPrebuiltFirmware(t *testing.T) { |
| 2610 | testCases := []struct { |
| 2611 | name string |
| 2612 | additionalProp string |
| 2613 | }{ |
| 2614 | {"system apex with prebuilt_firmware", ""}, |
| 2615 | {"vendor apex with prebuilt_firmware", "vendor: true,"}, |
| 2616 | } |
| 2617 | for _, tc := range testCases { |
| 2618 | t.Run(tc.name, func(t *testing.T) { |
| 2619 | ctx, _ := testApex(t, ` |
| 2620 | apex { |
| 2621 | name: "myapex", |
| 2622 | key: "myapex.key", |
| 2623 | prebuilts: ["myfirmware"], |
| 2624 | `+tc.additionalProp+` |
| 2625 | } |
| 2626 | apex_key { |
| 2627 | name: "myapex.key", |
| 2628 | public_key: "testkey.avbpubkey", |
| 2629 | private_key: "testkey.pem", |
| 2630 | } |
| 2631 | prebuilt_firmware { |
| 2632 | name: "myfirmware", |
| 2633 | src: "myfirmware.bin", |
| 2634 | filename_from_src: true, |
| 2635 | `+tc.additionalProp+` |
| 2636 | } |
| 2637 | `) |
| 2638 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2639 | "etc/firmware/myfirmware.bin", |
| 2640 | }) |
| 2641 | }) |
| 2642 | } |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 2643 | } |
| 2644 | |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2645 | func TestAndroidMk_UseVendorRequired(t *testing.T) { |
| 2646 | ctx, config := testApex(t, ` |
| 2647 | apex { |
| 2648 | name: "myapex", |
| 2649 | key: "myapex.key", |
| 2650 | use_vendor: true, |
| 2651 | native_shared_libs: ["mylib"], |
| 2652 | } |
| 2653 | |
| 2654 | apex_key { |
| 2655 | name: "myapex.key", |
| 2656 | public_key: "testkey.avbpubkey", |
| 2657 | private_key: "testkey.pem", |
| 2658 | } |
| 2659 | |
| 2660 | cc_library { |
| 2661 | name: "mylib", |
| 2662 | vendor_available: true, |
| 2663 | apex_available: ["myapex"], |
| 2664 | } |
| 2665 | `, func(fs map[string][]byte, config android.Config) { |
| 2666 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
| 2667 | }) |
| 2668 | |
| 2669 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2670 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2671 | name := apexBundle.BaseModuleName() |
| 2672 | prefix := "TARGET_" |
| 2673 | var builder strings.Builder |
| 2674 | data.Custom(&builder, name, prefix, "", data) |
| 2675 | androidMk := builder.String() |
| 2676 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc libm libdl\n") |
| 2677 | } |
| 2678 | |
| 2679 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
| 2680 | ctx, config := testApex(t, ` |
| 2681 | apex { |
| 2682 | name: "myapex", |
| 2683 | key: "myapex.key", |
| 2684 | vendor: true, |
| 2685 | native_shared_libs: ["mylib"], |
| 2686 | } |
| 2687 | |
| 2688 | apex_key { |
| 2689 | name: "myapex.key", |
| 2690 | public_key: "testkey.avbpubkey", |
| 2691 | private_key: "testkey.pem", |
| 2692 | } |
| 2693 | |
| 2694 | cc_library { |
| 2695 | name: "mylib", |
| 2696 | vendor_available: true, |
| 2697 | } |
| 2698 | `) |
| 2699 | |
| 2700 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2701 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2702 | name := apexBundle.BaseModuleName() |
| 2703 | prefix := "TARGET_" |
| 2704 | var builder strings.Builder |
| 2705 | data.Custom(&builder, name, prefix, "", data) |
| 2706 | androidMk := builder.String() |
| 2707 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc.vendor libm.vendor libdl.vendor\n") |
| 2708 | } |
| 2709 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2710 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
| 2711 | ctx, config := testApex(t, ` |
| 2712 | apex { |
| 2713 | name: "myapex", |
| 2714 | key: "myapex.key", |
| 2715 | vintf_fragments: ["fragment.xml"], |
| 2716 | init_rc: ["init.rc"], |
| 2717 | } |
| 2718 | apex_key { |
| 2719 | name: "myapex.key", |
| 2720 | public_key: "testkey.avbpubkey", |
| 2721 | private_key: "testkey.pem", |
| 2722 | } |
| 2723 | cc_binary { |
| 2724 | name: "mybin", |
| 2725 | } |
| 2726 | `) |
| 2727 | |
| 2728 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2729 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2730 | name := apexBundle.BaseModuleName() |
| 2731 | prefix := "TARGET_" |
| 2732 | var builder strings.Builder |
| 2733 | data.Custom(&builder, name, prefix, "", data) |
| 2734 | androidMk := builder.String() |
| 2735 | ensureContains(t, androidMk, "LOCAL_VINTF_FRAGMENTS := fragment.xml\n") |
| 2736 | ensureContains(t, androidMk, "LOCAL_INIT_RC := init.rc\n") |
| 2737 | } |
| 2738 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2739 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2740 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2741 | apex { |
| 2742 | name: "myapex", |
| 2743 | key: "myapex.key", |
| 2744 | native_shared_libs: ["mylib"], |
| 2745 | } |
| 2746 | |
| 2747 | apex_key { |
| 2748 | name: "myapex.key", |
| 2749 | public_key: "testkey.avbpubkey", |
| 2750 | private_key: "testkey.pem", |
| 2751 | } |
| 2752 | |
| 2753 | cc_library { |
| 2754 | name: "mylib", |
| 2755 | srcs: ["mylib.cpp"], |
| 2756 | system_shared_libs: [], |
| 2757 | stl: "none", |
| 2758 | stubs: { |
| 2759 | versions: ["1", "2", "3"], |
| 2760 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2761 | apex_available: [ |
| 2762 | "//apex_available:platform", |
| 2763 | "myapex", |
| 2764 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2765 | } |
| 2766 | |
| 2767 | cc_binary { |
| 2768 | name: "not_in_apex", |
| 2769 | srcs: ["mylib.cpp"], |
| 2770 | static_libs: ["mylib"], |
| 2771 | static_executable: true, |
| 2772 | system_shared_libs: [], |
| 2773 | stl: "none", |
| 2774 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2775 | `) |
| 2776 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2777 | 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] | 2778 | |
| 2779 | // 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] | 2780 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2781 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2782 | |
| 2783 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2784 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2785 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2786 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2787 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2788 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2789 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2790 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | cc_library { |
| 2794 | name: "mylib", |
| 2795 | srcs: ["mylib.cpp"], |
| 2796 | system_shared_libs: [], |
| 2797 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2798 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | apex_key { |
| 2802 | name: "myapex.key", |
| 2803 | public_key: "testkey.avbpubkey", |
| 2804 | private_key: "testkey.pem", |
| 2805 | } |
| 2806 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2807 | android_app_certificate { |
| 2808 | name: "myapex.certificate", |
| 2809 | certificate: "testkey", |
| 2810 | } |
| 2811 | |
| 2812 | android_app_certificate { |
| 2813 | name: "myapex.certificate.override", |
| 2814 | certificate: "testkey.override", |
| 2815 | } |
| 2816 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2817 | `) |
| 2818 | |
| 2819 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2820 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2821 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2822 | if keys.publicKeyFile.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 2823 | t.Errorf("public key %q is not %q", keys.publicKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2824 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 2825 | } |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2826 | if keys.privateKeyFile.String() != "vendor/foo/devkeys/testkey.pem" { |
| 2827 | t.Errorf("private key %q is not %q", keys.privateKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2828 | "vendor/foo/devkeys/testkey.pem") |
| 2829 | } |
| 2830 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2831 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2832 | 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] | 2833 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2834 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2835 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2836 | } |
| 2837 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2838 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2839 | func TestCertificate(t *testing.T) { |
| 2840 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 2841 | ctx, _ := testApex(t, ` |
| 2842 | apex { |
| 2843 | name: "myapex", |
| 2844 | key: "myapex.key", |
| 2845 | } |
| 2846 | apex_key { |
| 2847 | name: "myapex.key", |
| 2848 | public_key: "testkey.avbpubkey", |
| 2849 | private_key: "testkey.pem", |
| 2850 | }`) |
| 2851 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2852 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 2853 | if actual := rule.Args["certificates"]; actual != expected { |
| 2854 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2855 | } |
| 2856 | }) |
| 2857 | t.Run("override when unspecified", func(t *testing.T) { |
| 2858 | ctx, _ := testApex(t, ` |
| 2859 | apex { |
| 2860 | name: "myapex_keytest", |
| 2861 | key: "myapex.key", |
| 2862 | file_contexts: ":myapex-file_contexts", |
| 2863 | } |
| 2864 | apex_key { |
| 2865 | name: "myapex.key", |
| 2866 | public_key: "testkey.avbpubkey", |
| 2867 | private_key: "testkey.pem", |
| 2868 | } |
| 2869 | android_app_certificate { |
| 2870 | name: "myapex.certificate.override", |
| 2871 | certificate: "testkey.override", |
| 2872 | }`) |
| 2873 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2874 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2875 | if actual := rule.Args["certificates"]; actual != expected { |
| 2876 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2877 | } |
| 2878 | }) |
| 2879 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 2880 | ctx, _ := testApex(t, ` |
| 2881 | apex { |
| 2882 | name: "myapex", |
| 2883 | key: "myapex.key", |
| 2884 | certificate: ":myapex.certificate", |
| 2885 | } |
| 2886 | apex_key { |
| 2887 | name: "myapex.key", |
| 2888 | public_key: "testkey.avbpubkey", |
| 2889 | private_key: "testkey.pem", |
| 2890 | } |
| 2891 | android_app_certificate { |
| 2892 | name: "myapex.certificate", |
| 2893 | certificate: "testkey", |
| 2894 | }`) |
| 2895 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2896 | expected := "testkey.x509.pem testkey.pk8" |
| 2897 | if actual := rule.Args["certificates"]; actual != expected { |
| 2898 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2899 | } |
| 2900 | }) |
| 2901 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 2902 | ctx, _ := testApex(t, ` |
| 2903 | apex { |
| 2904 | name: "myapex_keytest", |
| 2905 | key: "myapex.key", |
| 2906 | file_contexts: ":myapex-file_contexts", |
| 2907 | certificate: ":myapex.certificate", |
| 2908 | } |
| 2909 | apex_key { |
| 2910 | name: "myapex.key", |
| 2911 | public_key: "testkey.avbpubkey", |
| 2912 | private_key: "testkey.pem", |
| 2913 | } |
| 2914 | android_app_certificate { |
| 2915 | name: "myapex.certificate.override", |
| 2916 | certificate: "testkey.override", |
| 2917 | }`) |
| 2918 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2919 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2920 | if actual := rule.Args["certificates"]; actual != expected { |
| 2921 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2922 | } |
| 2923 | }) |
| 2924 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 2925 | ctx, _ := testApex(t, ` |
| 2926 | apex { |
| 2927 | name: "myapex", |
| 2928 | key: "myapex.key", |
| 2929 | certificate: "testkey", |
| 2930 | } |
| 2931 | apex_key { |
| 2932 | name: "myapex.key", |
| 2933 | public_key: "testkey.avbpubkey", |
| 2934 | private_key: "testkey.pem", |
| 2935 | }`) |
| 2936 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2937 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 2938 | if actual := rule.Args["certificates"]; actual != expected { |
| 2939 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2940 | } |
| 2941 | }) |
| 2942 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 2943 | ctx, _ := testApex(t, ` |
| 2944 | apex { |
| 2945 | name: "myapex_keytest", |
| 2946 | key: "myapex.key", |
| 2947 | file_contexts: ":myapex-file_contexts", |
| 2948 | certificate: "testkey", |
| 2949 | } |
| 2950 | apex_key { |
| 2951 | name: "myapex.key", |
| 2952 | public_key: "testkey.avbpubkey", |
| 2953 | private_key: "testkey.pem", |
| 2954 | } |
| 2955 | android_app_certificate { |
| 2956 | name: "myapex.certificate.override", |
| 2957 | certificate: "testkey.override", |
| 2958 | }`) |
| 2959 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2960 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2961 | if actual := rule.Args["certificates"]; actual != expected { |
| 2962 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2963 | } |
| 2964 | }) |
| 2965 | } |
| 2966 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2967 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2968 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2969 | apex { |
| 2970 | name: "myapex", |
| 2971 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2972 | native_shared_libs: ["mylib", "mylib2"], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | apex { |
| 2976 | name: "otherapex", |
| 2977 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2978 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2979 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | apex_key { |
| 2983 | name: "myapex.key", |
| 2984 | public_key: "testkey.avbpubkey", |
| 2985 | private_key: "testkey.pem", |
| 2986 | } |
| 2987 | |
| 2988 | cc_library { |
| 2989 | name: "mylib", |
| 2990 | srcs: ["mylib.cpp"], |
| 2991 | system_shared_libs: [], |
| 2992 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2993 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2994 | "myapex", |
| 2995 | "otherapex", |
| 2996 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2997 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2998 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2999 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3000 | cc_library { |
| 3001 | name: "mylib2", |
| 3002 | srcs: ["mylib.cpp"], |
| 3003 | system_shared_libs: [], |
| 3004 | stl: "none", |
| 3005 | apex_available: [ |
| 3006 | "myapex", |
| 3007 | "otherapex", |
| 3008 | ], |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3009 | static_libs: ["mylib3"], |
| 3010 | recovery_available: true, |
| 3011 | min_sdk_version: "29", |
| 3012 | } |
| 3013 | cc_library { |
| 3014 | name: "mylib3", |
| 3015 | srcs: ["mylib.cpp"], |
| 3016 | system_shared_libs: [], |
| 3017 | stl: "none", |
| 3018 | apex_available: [ |
| 3019 | "myapex", |
| 3020 | "otherapex", |
| 3021 | ], |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3022 | use_apex_name_macro: true, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3023 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3024 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3025 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3026 | `) |
| 3027 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3028 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3029 | 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] | 3030 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3031 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3032 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3033 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3034 | 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] | 3035 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3036 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3037 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3038 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3039 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3040 | 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] | 3041 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3042 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3043 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3044 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3045 | // When a cc_library sets use_apex_name_macro: true each apex gets a unique variant and |
| 3046 | // each variant defines additional macros to distinguish which apex variant it is built for |
| 3047 | |
| 3048 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3049 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3050 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3051 | |
| 3052 | // APEX variant has __ANDROID_APEX__ defined |
| 3053 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 3054 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3055 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3056 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3057 | |
| 3058 | // APEX variant has __ANDROID_APEX__ defined |
| 3059 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 3060 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3061 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3062 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3063 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3064 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3065 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3066 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3067 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3068 | |
| 3069 | // When a dependency of a cc_library sets use_apex_name_macro: true each apex gets a unique |
| 3070 | // variant. |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3071 | |
| 3072 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3073 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3074 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3075 | |
| 3076 | // APEX variant has __ANDROID_APEX__ defined |
| 3077 | 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] | 3078 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3079 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3080 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3081 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3082 | // APEX variant has __ANDROID_APEX__ defined |
| 3083 | 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] | 3084 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3085 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3086 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3087 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3088 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3089 | 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] | 3090 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3091 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3092 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3093 | |
| 3094 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3095 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3096 | apex { |
| 3097 | name: "myapex", |
| 3098 | key: "myapex.key", |
| 3099 | native_shared_libs: ["mylib"], |
| 3100 | } |
| 3101 | |
| 3102 | apex_key { |
| 3103 | name: "myapex.key", |
| 3104 | public_key: "testkey.avbpubkey", |
| 3105 | private_key: "testkey.pem", |
| 3106 | } |
| 3107 | |
| 3108 | cc_library_headers { |
| 3109 | name: "mylib_headers", |
| 3110 | export_include_dirs: ["my_include"], |
| 3111 | system_shared_libs: [], |
| 3112 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3113 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | cc_library { |
| 3117 | name: "mylib", |
| 3118 | srcs: ["mylib.cpp"], |
| 3119 | system_shared_libs: [], |
| 3120 | stl: "none", |
| 3121 | header_libs: ["mylib_headers"], |
| 3122 | export_header_lib_headers: ["mylib_headers"], |
| 3123 | stubs: { |
| 3124 | versions: ["1", "2", "3"], |
| 3125 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3126 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | cc_library { |
| 3130 | name: "otherlib", |
| 3131 | srcs: ["mylib.cpp"], |
| 3132 | system_shared_libs: [], |
| 3133 | stl: "none", |
| 3134 | shared_libs: ["mylib"], |
| 3135 | } |
| 3136 | `) |
| 3137 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3138 | 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] | 3139 | |
| 3140 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 3141 | ensureContains(t, cFlags, "-Imy_include") |
| 3142 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3143 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3144 | type fileInApex struct { |
| 3145 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3146 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3147 | isLink bool |
| 3148 | } |
| 3149 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3150 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3151 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3152 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3153 | copyCmds := apexRule.Args["copy_commands"] |
| 3154 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3155 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3156 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 3157 | cmd = strings.TrimSpace(cmd) |
| 3158 | if cmd == "" { |
| 3159 | continue |
| 3160 | } |
| 3161 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3162 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3163 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3164 | switch terms[0] { |
| 3165 | case "mkdir": |
| 3166 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3167 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3168 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 3169 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3170 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3171 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3172 | isLink = false |
| 3173 | case "ln": |
| 3174 | if len(terms) != 3 && len(terms) != 4 { |
| 3175 | // ln LINK TARGET or ln -s LINK TARGET |
| 3176 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 3177 | } |
| 3178 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3179 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3180 | isLink = true |
| 3181 | default: |
| 3182 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 3183 | } |
| 3184 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3185 | index := strings.Index(dst, imageApexDir) |
| 3186 | if index == -1 { |
| 3187 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 3188 | } |
| 3189 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3190 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3191 | } |
| 3192 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3193 | return ret |
| 3194 | } |
| 3195 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3196 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 3197 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3198 | var failed bool |
| 3199 | var surplus []string |
| 3200 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3201 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3202 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3203 | for _, expected := range files { |
| 3204 | if matched, _ := path.Match(expected, file.path); matched { |
| 3205 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3206 | mactchFound = true |
| 3207 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3208 | } |
| 3209 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3210 | if !mactchFound { |
| 3211 | surplus = append(surplus, file.path) |
| 3212 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3213 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3214 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3215 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3216 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3217 | t.Log("surplus files", surplus) |
| 3218 | failed = true |
| 3219 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3220 | |
| 3221 | if len(files) > len(filesMatched) { |
| 3222 | var missing []string |
| 3223 | for _, expected := range files { |
| 3224 | if !filesMatched[expected] { |
| 3225 | missing = append(missing, expected) |
| 3226 | } |
| 3227 | } |
| 3228 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3229 | t.Log("missing files", missing) |
| 3230 | failed = true |
| 3231 | } |
| 3232 | if failed { |
| 3233 | t.Fail() |
| 3234 | } |
| 3235 | } |
| 3236 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3237 | func TestVndkApexCurrent(t *testing.T) { |
| 3238 | ctx, _ := testApex(t, ` |
| 3239 | apex_vndk { |
| 3240 | name: "myapex", |
| 3241 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | apex_key { |
| 3245 | name: "myapex.key", |
| 3246 | public_key: "testkey.avbpubkey", |
| 3247 | private_key: "testkey.pem", |
| 3248 | } |
| 3249 | |
| 3250 | cc_library { |
| 3251 | name: "libvndk", |
| 3252 | srcs: ["mylib.cpp"], |
| 3253 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3254 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3255 | vndk: { |
| 3256 | enabled: true, |
| 3257 | }, |
| 3258 | system_shared_libs: [], |
| 3259 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3260 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | cc_library { |
| 3264 | name: "libvndksp", |
| 3265 | srcs: ["mylib.cpp"], |
| 3266 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3267 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3268 | vndk: { |
| 3269 | enabled: true, |
| 3270 | support_system_process: true, |
| 3271 | }, |
| 3272 | system_shared_libs: [], |
| 3273 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3274 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3275 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3276 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3277 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3278 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3279 | "lib/libvndk.so", |
| 3280 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3281 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3282 | "lib64/libvndk.so", |
| 3283 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3284 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3285 | "etc/llndk.libraries.VER.txt", |
| 3286 | "etc/vndkcore.libraries.VER.txt", |
| 3287 | "etc/vndksp.libraries.VER.txt", |
| 3288 | "etc/vndkprivate.libraries.VER.txt", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3289 | "etc/vndkproduct.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3290 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 3294 | ctx, _ := testApex(t, ` |
| 3295 | apex_vndk { |
| 3296 | name: "myapex", |
| 3297 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3298 | } |
| 3299 | |
| 3300 | apex_key { |
| 3301 | name: "myapex.key", |
| 3302 | public_key: "testkey.avbpubkey", |
| 3303 | private_key: "testkey.pem", |
| 3304 | } |
| 3305 | |
| 3306 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3307 | name: "libvndk", |
| 3308 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3309 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3310 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3311 | vndk: { |
| 3312 | enabled: true, |
| 3313 | }, |
| 3314 | system_shared_libs: [], |
| 3315 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3316 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3317 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3318 | |
| 3319 | cc_prebuilt_library_shared { |
| 3320 | name: "libvndk.arm", |
| 3321 | srcs: ["libvndk.arm.so"], |
| 3322 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3323 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3324 | vndk: { |
| 3325 | enabled: true, |
| 3326 | }, |
| 3327 | enabled: false, |
| 3328 | arch: { |
| 3329 | arm: { |
| 3330 | enabled: true, |
| 3331 | }, |
| 3332 | }, |
| 3333 | system_shared_libs: [], |
| 3334 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3335 | apex_available: [ "myapex" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3336 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3337 | `+vndkLibrariesTxtFiles("current"), |
| 3338 | withFiles(map[string][]byte{ |
| 3339 | "libvndk.so": nil, |
| 3340 | "libvndk.arm.so": nil, |
| 3341 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3342 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3343 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3344 | "lib/libvndk.so", |
| 3345 | "lib/libvndk.arm.so", |
| 3346 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3347 | "lib/libc++.so", |
| 3348 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3349 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3350 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3351 | } |
| 3352 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3353 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 3354 | for _, v := range vers { |
| 3355 | if v == "current" { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3356 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3357 | result += ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 3358 | ` + txt + `_libraries_txt { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3359 | name: "` + txt + `.libraries.txt", |
| 3360 | } |
| 3361 | ` |
| 3362 | } |
| 3363 | } else { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3364 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3365 | result += ` |
| 3366 | prebuilt_etc { |
| 3367 | name: "` + txt + `.libraries.` + v + `.txt", |
| 3368 | src: "dummy.txt", |
| 3369 | } |
| 3370 | ` |
| 3371 | } |
| 3372 | } |
| 3373 | } |
| 3374 | return |
| 3375 | } |
| 3376 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3377 | func TestVndkApexVersion(t *testing.T) { |
| 3378 | ctx, _ := testApex(t, ` |
| 3379 | apex_vndk { |
| 3380 | name: "myapex_v27", |
| 3381 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3382 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3383 | vndk_version: "27", |
| 3384 | } |
| 3385 | |
| 3386 | apex_key { |
| 3387 | name: "myapex.key", |
| 3388 | public_key: "testkey.avbpubkey", |
| 3389 | private_key: "testkey.pem", |
| 3390 | } |
| 3391 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3392 | vndk_prebuilt_shared { |
| 3393 | name: "libvndk27", |
| 3394 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3395 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3396 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3397 | vndk: { |
| 3398 | enabled: true, |
| 3399 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3400 | target_arch: "arm64", |
| 3401 | arch: { |
| 3402 | arm: { |
| 3403 | srcs: ["libvndk27_arm.so"], |
| 3404 | }, |
| 3405 | arm64: { |
| 3406 | srcs: ["libvndk27_arm64.so"], |
| 3407 | }, |
| 3408 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3409 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | vndk_prebuilt_shared { |
| 3413 | name: "libvndk27", |
| 3414 | version: "27", |
| 3415 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3416 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3417 | vndk: { |
| 3418 | enabled: true, |
| 3419 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3420 | target_arch: "x86_64", |
| 3421 | arch: { |
| 3422 | x86: { |
| 3423 | srcs: ["libvndk27_x86.so"], |
| 3424 | }, |
| 3425 | x86_64: { |
| 3426 | srcs: ["libvndk27_x86_64.so"], |
| 3427 | }, |
| 3428 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3429 | } |
| 3430 | `+vndkLibrariesTxtFiles("27"), |
| 3431 | withFiles(map[string][]byte{ |
| 3432 | "libvndk27_arm.so": nil, |
| 3433 | "libvndk27_arm64.so": nil, |
| 3434 | "libvndk27_x86.so": nil, |
| 3435 | "libvndk27_x86_64.so": nil, |
| 3436 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3437 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3438 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3439 | "lib/libvndk27_arm.so", |
| 3440 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3441 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3442 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { |
| 3446 | testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, ` |
| 3447 | apex_vndk { |
| 3448 | name: "myapex_v27", |
| 3449 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3450 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3451 | vndk_version: "27", |
| 3452 | } |
| 3453 | apex_vndk { |
| 3454 | name: "myapex_v27_other", |
| 3455 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3456 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3457 | vndk_version: "27", |
| 3458 | } |
| 3459 | |
| 3460 | apex_key { |
| 3461 | name: "myapex.key", |
| 3462 | public_key: "testkey.avbpubkey", |
| 3463 | private_key: "testkey.pem", |
| 3464 | } |
| 3465 | |
| 3466 | cc_library { |
| 3467 | name: "libvndk", |
| 3468 | srcs: ["mylib.cpp"], |
| 3469 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3470 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3471 | vndk: { |
| 3472 | enabled: true, |
| 3473 | }, |
| 3474 | system_shared_libs: [], |
| 3475 | stl: "none", |
| 3476 | } |
| 3477 | |
| 3478 | vndk_prebuilt_shared { |
| 3479 | name: "libvndk", |
| 3480 | version: "27", |
| 3481 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3482 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3483 | vndk: { |
| 3484 | enabled: true, |
| 3485 | }, |
| 3486 | srcs: ["libvndk.so"], |
| 3487 | } |
| 3488 | `, withFiles(map[string][]byte{ |
| 3489 | "libvndk.so": nil, |
| 3490 | })) |
| 3491 | } |
| 3492 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3493 | func TestVndkApexNameRule(t *testing.T) { |
| 3494 | ctx, _ := testApex(t, ` |
| 3495 | apex_vndk { |
| 3496 | name: "myapex", |
| 3497 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3498 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3499 | } |
| 3500 | apex_vndk { |
| 3501 | name: "myapex_v28", |
| 3502 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3503 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3504 | vndk_version: "28", |
| 3505 | } |
| 3506 | apex_key { |
| 3507 | name: "myapex.key", |
| 3508 | public_key: "testkey.avbpubkey", |
| 3509 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3510 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3511 | |
| 3512 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3513 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3514 | actual := proptools.String(bundle.properties.Apex_name) |
| 3515 | if !reflect.DeepEqual(actual, expected) { |
| 3516 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3517 | } |
| 3518 | } |
| 3519 | |
| 3520 | assertApexName("com.android.vndk.vVER", "myapex") |
| 3521 | assertApexName("com.android.vndk.v28", "myapex_v28") |
| 3522 | } |
| 3523 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3524 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 3525 | ctx, _ := testApex(t, ` |
| 3526 | apex_vndk { |
| 3527 | name: "myapex", |
| 3528 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3529 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | apex_key { |
| 3533 | name: "myapex.key", |
| 3534 | public_key: "testkey.avbpubkey", |
| 3535 | private_key: "testkey.pem", |
| 3536 | } |
| 3537 | |
| 3538 | cc_library { |
| 3539 | name: "libvndk", |
| 3540 | srcs: ["mylib.cpp"], |
| 3541 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3542 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3543 | native_bridge_supported: true, |
| 3544 | host_supported: true, |
| 3545 | vndk: { |
| 3546 | enabled: true, |
| 3547 | }, |
| 3548 | system_shared_libs: [], |
| 3549 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3550 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3551 | } |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3552 | `+vndkLibrariesTxtFiles("current"), withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3553 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3554 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3555 | "lib/libvndk.so", |
| 3556 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3557 | "lib/libc++.so", |
| 3558 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3559 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3560 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
| 3564 | testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
| 3565 | apex_vndk { |
| 3566 | name: "myapex", |
| 3567 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3568 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3569 | native_bridge_supported: true, |
| 3570 | } |
| 3571 | |
| 3572 | apex_key { |
| 3573 | name: "myapex.key", |
| 3574 | public_key: "testkey.avbpubkey", |
| 3575 | private_key: "testkey.pem", |
| 3576 | } |
| 3577 | |
| 3578 | cc_library { |
| 3579 | name: "libvndk", |
| 3580 | srcs: ["mylib.cpp"], |
| 3581 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3582 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3583 | native_bridge_supported: true, |
| 3584 | host_supported: true, |
| 3585 | vndk: { |
| 3586 | enabled: true, |
| 3587 | }, |
| 3588 | system_shared_libs: [], |
| 3589 | stl: "none", |
| 3590 | } |
| 3591 | `) |
| 3592 | } |
| 3593 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3594 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3595 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3596 | apex_vndk { |
| 3597 | name: "myapex_v27", |
| 3598 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3599 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3600 | vndk_version: "27", |
| 3601 | } |
| 3602 | |
| 3603 | apex_key { |
| 3604 | name: "myapex.key", |
| 3605 | public_key: "testkey.avbpubkey", |
| 3606 | private_key: "testkey.pem", |
| 3607 | } |
| 3608 | |
| 3609 | vndk_prebuilt_shared { |
| 3610 | name: "libvndk27", |
| 3611 | version: "27", |
| 3612 | target_arch: "arm", |
| 3613 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3614 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3615 | vndk: { |
| 3616 | enabled: true, |
| 3617 | }, |
| 3618 | arch: { |
| 3619 | arm: { |
| 3620 | srcs: ["libvndk27.so"], |
| 3621 | } |
| 3622 | }, |
| 3623 | } |
| 3624 | |
| 3625 | vndk_prebuilt_shared { |
| 3626 | name: "libvndk27", |
| 3627 | version: "27", |
| 3628 | target_arch: "arm", |
| 3629 | binder32bit: true, |
| 3630 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3631 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3632 | vndk: { |
| 3633 | enabled: true, |
| 3634 | }, |
| 3635 | arch: { |
| 3636 | arm: { |
| 3637 | srcs: ["libvndk27binder32.so"], |
| 3638 | } |
| 3639 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3640 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3641 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3642 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3643 | withFiles(map[string][]byte{ |
| 3644 | "libvndk27.so": nil, |
| 3645 | "libvndk27binder32.so": nil, |
| 3646 | }), |
| 3647 | withBinder32bit, |
| 3648 | withTargets(map[android.OsType][]android.Target{ |
| 3649 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3650 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3651 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3652 | }, |
| 3653 | }), |
| 3654 | ) |
| 3655 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3656 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3657 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3658 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3659 | }) |
| 3660 | } |
| 3661 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3662 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
| 3663 | ctx, _ := testApex(t, ` |
| 3664 | apex_vndk { |
| 3665 | name: "myapex", |
| 3666 | key: "myapex.key", |
| 3667 | file_contexts: ":myapex-file_contexts", |
| 3668 | } |
| 3669 | |
| 3670 | apex_key { |
| 3671 | name: "myapex.key", |
| 3672 | public_key: "testkey.avbpubkey", |
| 3673 | private_key: "testkey.pem", |
| 3674 | } |
| 3675 | |
| 3676 | cc_library { |
| 3677 | name: "libz", |
| 3678 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3679 | product_available: true, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3680 | vndk: { |
| 3681 | enabled: true, |
| 3682 | }, |
| 3683 | stubs: { |
| 3684 | symbol_file: "libz.map.txt", |
| 3685 | versions: ["30"], |
| 3686 | } |
| 3687 | } |
| 3688 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3689 | "libz.map.txt": nil, |
| 3690 | })) |
| 3691 | |
| 3692 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_image").Rule("apexManifestRule") |
| 3693 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3694 | ensureListEmpty(t, provideNativeLibs) |
| 3695 | } |
| 3696 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3697 | func TestDependenciesInApexManifest(t *testing.T) { |
| 3698 | ctx, _ := testApex(t, ` |
| 3699 | apex { |
| 3700 | name: "myapex_nodep", |
| 3701 | key: "myapex.key", |
| 3702 | native_shared_libs: ["lib_nodep"], |
| 3703 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3704 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3705 | } |
| 3706 | |
| 3707 | apex { |
| 3708 | name: "myapex_dep", |
| 3709 | key: "myapex.key", |
| 3710 | native_shared_libs: ["lib_dep"], |
| 3711 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3712 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | apex { |
| 3716 | name: "myapex_provider", |
| 3717 | key: "myapex.key", |
| 3718 | native_shared_libs: ["libfoo"], |
| 3719 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3720 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | apex { |
| 3724 | name: "myapex_selfcontained", |
| 3725 | key: "myapex.key", |
| 3726 | native_shared_libs: ["lib_dep", "libfoo"], |
| 3727 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3728 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | apex_key { |
| 3732 | name: "myapex.key", |
| 3733 | public_key: "testkey.avbpubkey", |
| 3734 | private_key: "testkey.pem", |
| 3735 | } |
| 3736 | |
| 3737 | cc_library { |
| 3738 | name: "lib_nodep", |
| 3739 | srcs: ["mylib.cpp"], |
| 3740 | system_shared_libs: [], |
| 3741 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3742 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | cc_library { |
| 3746 | name: "lib_dep", |
| 3747 | srcs: ["mylib.cpp"], |
| 3748 | shared_libs: ["libfoo"], |
| 3749 | system_shared_libs: [], |
| 3750 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3751 | apex_available: [ |
| 3752 | "myapex_dep", |
| 3753 | "myapex_provider", |
| 3754 | "myapex_selfcontained", |
| 3755 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | cc_library { |
| 3759 | name: "libfoo", |
| 3760 | srcs: ["mytest.cpp"], |
| 3761 | stubs: { |
| 3762 | versions: ["1"], |
| 3763 | }, |
| 3764 | system_shared_libs: [], |
| 3765 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3766 | apex_available: [ |
| 3767 | "myapex_provider", |
| 3768 | "myapex_selfcontained", |
| 3769 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3770 | } |
| 3771 | `) |
| 3772 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3773 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3774 | var provideNativeLibs, requireNativeLibs []string |
| 3775 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3776 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3777 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3778 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3779 | ensureListEmpty(t, provideNativeLibs) |
| 3780 | ensureListEmpty(t, requireNativeLibs) |
| 3781 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3782 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3783 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3784 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3785 | ensureListEmpty(t, provideNativeLibs) |
| 3786 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 3787 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3788 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3789 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3790 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3791 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3792 | ensureListEmpty(t, requireNativeLibs) |
| 3793 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3794 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3795 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3796 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3797 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3798 | ensureListEmpty(t, requireNativeLibs) |
| 3799 | } |
| 3800 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3801 | func TestApexName(t *testing.T) { |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3802 | ctx, config := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3803 | apex { |
| 3804 | name: "myapex", |
| 3805 | key: "myapex.key", |
| 3806 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3807 | native_shared_libs: ["mylib"], |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | apex_key { |
| 3811 | name: "myapex.key", |
| 3812 | public_key: "testkey.avbpubkey", |
| 3813 | private_key: "testkey.pem", |
| 3814 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3815 | |
| 3816 | cc_library { |
| 3817 | name: "mylib", |
| 3818 | srcs: ["mylib.cpp"], |
| 3819 | system_shared_libs: [], |
| 3820 | stl: "none", |
| 3821 | apex_available: [ |
| 3822 | "//apex_available:platform", |
| 3823 | "myapex", |
| 3824 | ], |
| 3825 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3826 | `) |
| 3827 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3828 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3829 | apexManifestRule := module.Rule("apexManifestRule") |
| 3830 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 3831 | apexRule := module.Rule("apexRule") |
| 3832 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3833 | |
| 3834 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3835 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3836 | name := apexBundle.BaseModuleName() |
| 3837 | prefix := "TARGET_" |
| 3838 | var builder strings.Builder |
| 3839 | data.Custom(&builder, name, prefix, "", data) |
| 3840 | androidMk := builder.String() |
| 3841 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 3842 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3843 | } |
| 3844 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3845 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3846 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3847 | apex { |
| 3848 | name: "myapex", |
| 3849 | key: "myapex.key", |
| 3850 | native_shared_libs: ["mylib_common"], |
| 3851 | } |
| 3852 | |
| 3853 | apex_key { |
| 3854 | name: "myapex.key", |
| 3855 | public_key: "testkey.avbpubkey", |
| 3856 | private_key: "testkey.pem", |
| 3857 | } |
| 3858 | |
| 3859 | cc_library { |
| 3860 | name: "mylib_common", |
| 3861 | srcs: ["mylib.cpp"], |
| 3862 | system_shared_libs: [], |
| 3863 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3864 | apex_available: [ |
| 3865 | "//apex_available:platform", |
| 3866 | "myapex", |
| 3867 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3868 | } |
| 3869 | `) |
| 3870 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3871 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3872 | apexRule := module.Rule("apexRule") |
| 3873 | copyCmds := apexRule.Args["copy_commands"] |
| 3874 | |
| 3875 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 3876 | t.Log("Apex was a test apex!") |
| 3877 | t.Fail() |
| 3878 | } |
| 3879 | // Ensure that main rule creates an output |
| 3880 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3881 | |
| 3882 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3883 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3884 | |
| 3885 | // Ensure that both direct and indirect deps are copied into apex |
| 3886 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3887 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3888 | // Ensure that the platform variant ends with _shared |
| 3889 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3890 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3891 | 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] | 3892 | t.Log("Found mylib_common not in any apex!") |
| 3893 | t.Fail() |
| 3894 | } |
| 3895 | } |
| 3896 | |
| 3897 | func TestTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3898 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3899 | apex_test { |
| 3900 | name: "myapex", |
| 3901 | key: "myapex.key", |
| 3902 | native_shared_libs: ["mylib_common_test"], |
| 3903 | } |
| 3904 | |
| 3905 | apex_key { |
| 3906 | name: "myapex.key", |
| 3907 | public_key: "testkey.avbpubkey", |
| 3908 | private_key: "testkey.pem", |
| 3909 | } |
| 3910 | |
| 3911 | cc_library { |
| 3912 | name: "mylib_common_test", |
| 3913 | srcs: ["mylib.cpp"], |
| 3914 | system_shared_libs: [], |
| 3915 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3916 | // TODO: remove //apex_available:platform |
| 3917 | apex_available: [ |
| 3918 | "//apex_available:platform", |
| 3919 | "myapex", |
| 3920 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3921 | } |
| 3922 | `) |
| 3923 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3924 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3925 | apexRule := module.Rule("apexRule") |
| 3926 | copyCmds := apexRule.Args["copy_commands"] |
| 3927 | |
| 3928 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 3929 | t.Log("Apex was not a test apex!") |
| 3930 | t.Fail() |
| 3931 | } |
| 3932 | // Ensure that main rule creates an output |
| 3933 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3934 | |
| 3935 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3936 | 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] | 3937 | |
| 3938 | // Ensure that both direct and indirect deps are copied into apex |
| 3939 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 3940 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3941 | // Ensure that the platform variant ends with _shared |
| 3942 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3943 | } |
| 3944 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3945 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3946 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3947 | apex { |
| 3948 | name: "myapex", |
| 3949 | key: "myapex.key", |
| 3950 | multilib: { |
| 3951 | first: { |
| 3952 | native_shared_libs: ["mylib_common"], |
| 3953 | } |
| 3954 | }, |
| 3955 | target: { |
| 3956 | android: { |
| 3957 | multilib: { |
| 3958 | first: { |
| 3959 | native_shared_libs: ["mylib"], |
| 3960 | } |
| 3961 | } |
| 3962 | }, |
| 3963 | host: { |
| 3964 | multilib: { |
| 3965 | first: { |
| 3966 | native_shared_libs: ["mylib2"], |
| 3967 | } |
| 3968 | } |
| 3969 | } |
| 3970 | } |
| 3971 | } |
| 3972 | |
| 3973 | apex_key { |
| 3974 | name: "myapex.key", |
| 3975 | public_key: "testkey.avbpubkey", |
| 3976 | private_key: "testkey.pem", |
| 3977 | } |
| 3978 | |
| 3979 | cc_library { |
| 3980 | name: "mylib", |
| 3981 | srcs: ["mylib.cpp"], |
| 3982 | system_shared_libs: [], |
| 3983 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3984 | // TODO: remove //apex_available:platform |
| 3985 | apex_available: [ |
| 3986 | "//apex_available:platform", |
| 3987 | "myapex", |
| 3988 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | cc_library { |
| 3992 | name: "mylib_common", |
| 3993 | srcs: ["mylib.cpp"], |
| 3994 | system_shared_libs: [], |
| 3995 | stl: "none", |
| 3996 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3997 | // TODO: remove //apex_available:platform |
| 3998 | apex_available: [ |
| 3999 | "//apex_available:platform", |
| 4000 | "myapex", |
| 4001 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | cc_library { |
| 4005 | name: "mylib2", |
| 4006 | srcs: ["mylib.cpp"], |
| 4007 | system_shared_libs: [], |
| 4008 | stl: "none", |
| 4009 | compile_multilib: "first", |
| 4010 | } |
| 4011 | `) |
| 4012 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4013 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4014 | copyCmds := apexRule.Args["copy_commands"] |
| 4015 | |
| 4016 | // Ensure that main rule creates an output |
| 4017 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 4018 | |
| 4019 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4020 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 4021 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
| 4022 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4023 | |
| 4024 | // Ensure that both direct and indirect deps are copied into apex |
| 4025 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 4026 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 4027 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 4028 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4029 | // Ensure that the platform variant ends with _shared |
| 4030 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 4031 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 4032 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4033 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4034 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4035 | func TestApexWithArch(t *testing.T) { |
| 4036 | ctx, _ := testApex(t, ` |
| 4037 | apex { |
| 4038 | name: "myapex", |
| 4039 | key: "myapex.key", |
| 4040 | arch: { |
| 4041 | arm64: { |
| 4042 | native_shared_libs: ["mylib.arm64"], |
| 4043 | }, |
| 4044 | x86_64: { |
| 4045 | native_shared_libs: ["mylib.x64"], |
| 4046 | }, |
| 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | apex_key { |
| 4051 | name: "myapex.key", |
| 4052 | public_key: "testkey.avbpubkey", |
| 4053 | private_key: "testkey.pem", |
| 4054 | } |
| 4055 | |
| 4056 | cc_library { |
| 4057 | name: "mylib.arm64", |
| 4058 | srcs: ["mylib.cpp"], |
| 4059 | system_shared_libs: [], |
| 4060 | stl: "none", |
| 4061 | // TODO: remove //apex_available:platform |
| 4062 | apex_available: [ |
| 4063 | "//apex_available:platform", |
| 4064 | "myapex", |
| 4065 | ], |
| 4066 | } |
| 4067 | |
| 4068 | cc_library { |
| 4069 | name: "mylib.x64", |
| 4070 | srcs: ["mylib.cpp"], |
| 4071 | system_shared_libs: [], |
| 4072 | stl: "none", |
| 4073 | // TODO: remove //apex_available:platform |
| 4074 | apex_available: [ |
| 4075 | "//apex_available:platform", |
| 4076 | "myapex", |
| 4077 | ], |
| 4078 | } |
| 4079 | `) |
| 4080 | |
| 4081 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 4082 | copyCmds := apexRule.Args["copy_commands"] |
| 4083 | |
| 4084 | // Ensure that apex variant is created for the direct dep |
| 4085 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib.arm64"), "android_arm64_armv8-a_shared_apex10000") |
| 4086 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib.x64"), "android_arm64_armv8-a_shared_apex10000") |
| 4087 | |
| 4088 | // Ensure that both direct and indirect deps are copied into apex |
| 4089 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.arm64.so") |
| 4090 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib.x64.so") |
| 4091 | } |
| 4092 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4093 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4094 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4095 | apex { |
| 4096 | name: "myapex", |
| 4097 | key: "myapex.key", |
| 4098 | binaries: ["myscript"], |
| 4099 | } |
| 4100 | |
| 4101 | apex_key { |
| 4102 | name: "myapex.key", |
| 4103 | public_key: "testkey.avbpubkey", |
| 4104 | private_key: "testkey.pem", |
| 4105 | } |
| 4106 | |
| 4107 | sh_binary { |
| 4108 | name: "myscript", |
| 4109 | src: "mylib.cpp", |
| 4110 | filename: "myscript.sh", |
| 4111 | sub_dir: "script", |
| 4112 | } |
| 4113 | `) |
| 4114 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4115 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4116 | copyCmds := apexRule.Args["copy_commands"] |
| 4117 | |
| 4118 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 4119 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4120 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4121 | func TestApexInVariousPartition(t *testing.T) { |
| 4122 | testcases := []struct { |
| 4123 | propName, parition, flattenedPartition string |
| 4124 | }{ |
| 4125 | {"", "system", "system_ext"}, |
| 4126 | {"product_specific: true", "product", "product"}, |
| 4127 | {"soc_specific: true", "vendor", "vendor"}, |
| 4128 | {"proprietary: true", "vendor", "vendor"}, |
| 4129 | {"vendor: true", "vendor", "vendor"}, |
| 4130 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 4131 | } |
| 4132 | for _, tc := range testcases { |
| 4133 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 4134 | ctx, _ := testApex(t, ` |
| 4135 | apex { |
| 4136 | name: "myapex", |
| 4137 | key: "myapex.key", |
| 4138 | `+tc.propName+` |
| 4139 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4140 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4141 | apex_key { |
| 4142 | name: "myapex.key", |
| 4143 | public_key: "testkey.avbpubkey", |
| 4144 | private_key: "testkey.pem", |
| 4145 | } |
| 4146 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4147 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4148 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 4149 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 4150 | actual := apex.installDir.String() |
| 4151 | if actual != expected { |
| 4152 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4153 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4154 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4155 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 4156 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 4157 | actual = flattened.installDir.String() |
| 4158 | if actual != expected { |
| 4159 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4160 | } |
| 4161 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4162 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4163 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4164 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4165 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4166 | ctx, _ := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4167 | apex { |
| 4168 | name: "myapex", |
| 4169 | key: "myapex.key", |
| 4170 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4171 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4172 | apex_key { |
| 4173 | name: "myapex.key", |
| 4174 | public_key: "testkey.avbpubkey", |
| 4175 | private_key: "testkey.pem", |
| 4176 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4177 | `) |
| 4178 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4179 | rule := module.Output("file_contexts") |
| 4180 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 4181 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4182 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4183 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4184 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4185 | apex { |
| 4186 | name: "myapex", |
| 4187 | key: "myapex.key", |
| 4188 | file_contexts: "my_own_file_contexts", |
| 4189 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4190 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4191 | apex_key { |
| 4192 | name: "myapex.key", |
| 4193 | public_key: "testkey.avbpubkey", |
| 4194 | private_key: "testkey.pem", |
| 4195 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4196 | `, withFiles(map[string][]byte{ |
| 4197 | "my_own_file_contexts": nil, |
| 4198 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4199 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4200 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4201 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4202 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4203 | apex { |
| 4204 | name: "myapex", |
| 4205 | key: "myapex.key", |
| 4206 | product_specific: true, |
| 4207 | file_contexts: "product_specific_file_contexts", |
| 4208 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4209 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4210 | apex_key { |
| 4211 | name: "myapex.key", |
| 4212 | public_key: "testkey.avbpubkey", |
| 4213 | private_key: "testkey.pem", |
| 4214 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4215 | `) |
| 4216 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4217 | ctx, _ := testApex(t, ` |
| 4218 | apex { |
| 4219 | name: "myapex", |
| 4220 | key: "myapex.key", |
| 4221 | product_specific: true, |
| 4222 | file_contexts: "product_specific_file_contexts", |
| 4223 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4224 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4225 | apex_key { |
| 4226 | name: "myapex.key", |
| 4227 | public_key: "testkey.avbpubkey", |
| 4228 | private_key: "testkey.pem", |
| 4229 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4230 | `, withFiles(map[string][]byte{ |
| 4231 | "product_specific_file_contexts": nil, |
| 4232 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4233 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4234 | rule := module.Output("file_contexts") |
| 4235 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 4236 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4237 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4238 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
| 4239 | ctx, _ := testApex(t, ` |
| 4240 | apex { |
| 4241 | name: "myapex", |
| 4242 | key: "myapex.key", |
| 4243 | product_specific: true, |
| 4244 | file_contexts: ":my-file-contexts", |
| 4245 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4246 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4247 | apex_key { |
| 4248 | name: "myapex.key", |
| 4249 | public_key: "testkey.avbpubkey", |
| 4250 | private_key: "testkey.pem", |
| 4251 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4252 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4253 | filegroup { |
| 4254 | name: "my-file-contexts", |
| 4255 | srcs: ["product_specific_file_contexts"], |
| 4256 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4257 | `, withFiles(map[string][]byte{ |
| 4258 | "product_specific_file_contexts": nil, |
| 4259 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4260 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4261 | rule := module.Output("file_contexts") |
| 4262 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4263 | } |
| 4264 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4265 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4266 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4267 | apex_key { |
| 4268 | name: "myapex.key", |
| 4269 | public_key: ":my.avbpubkey", |
| 4270 | private_key: ":my.pem", |
| 4271 | product_specific: true, |
| 4272 | } |
| 4273 | |
| 4274 | filegroup { |
| 4275 | name: "my.avbpubkey", |
| 4276 | srcs: ["testkey2.avbpubkey"], |
| 4277 | } |
| 4278 | |
| 4279 | filegroup { |
| 4280 | name: "my.pem", |
| 4281 | srcs: ["testkey2.pem"], |
| 4282 | } |
| 4283 | `) |
| 4284 | |
| 4285 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 4286 | expected_pubkey := "testkey2.avbpubkey" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4287 | actual_pubkey := apex_key.publicKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4288 | if actual_pubkey != expected_pubkey { |
| 4289 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 4290 | } |
| 4291 | expected_privkey := "testkey2.pem" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4292 | actual_privkey := apex_key.privateKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4293 | if actual_privkey != expected_privkey { |
| 4294 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 4295 | } |
| 4296 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4297 | |
| 4298 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4299 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4300 | prebuilt_apex { |
| 4301 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4302 | arch: { |
| 4303 | arm64: { |
| 4304 | src: "myapex-arm64.apex", |
| 4305 | }, |
| 4306 | arm: { |
| 4307 | src: "myapex-arm.apex", |
| 4308 | }, |
| 4309 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4310 | } |
| 4311 | `) |
| 4312 | |
| 4313 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4314 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4315 | expectedInput := "myapex-arm64.apex" |
| 4316 | if prebuilt.inputApex.String() != expectedInput { |
| 4317 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 4318 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4319 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4320 | |
| 4321 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4322 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4323 | prebuilt_apex { |
| 4324 | name: "myapex", |
| 4325 | src: "myapex-arm.apex", |
| 4326 | filename: "notmyapex.apex", |
| 4327 | } |
| 4328 | `) |
| 4329 | |
| 4330 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4331 | |
| 4332 | expected := "notmyapex.apex" |
| 4333 | if p.installFilename != expected { |
| 4334 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 4335 | } |
| 4336 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4337 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4338 | func TestPrebuiltOverrides(t *testing.T) { |
| 4339 | ctx, config := testApex(t, ` |
| 4340 | prebuilt_apex { |
| 4341 | name: "myapex.prebuilt", |
| 4342 | src: "myapex-arm.apex", |
| 4343 | overrides: [ |
| 4344 | "myapex", |
| 4345 | ], |
| 4346 | } |
| 4347 | `) |
| 4348 | |
| 4349 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 4350 | |
| 4351 | expected := []string{"myapex"} |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 4352 | actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4353 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 4354 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4355 | } |
| 4356 | } |
| 4357 | |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4358 | // These tests verify that the prebuilt_apex/deapexer to java_import wiring allows for the |
| 4359 | // propagation of paths to dex implementation jars from the former to the latter. |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4360 | func TestPrebuiltExportDexImplementationJars(t *testing.T) { |
| 4361 | transform := func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4362 | // Empty transformation. |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4363 | } |
| 4364 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4365 | checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4366 | // Make sure the import has been given the correct path to the dex jar. |
| 4367 | p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.Dependency) |
| 4368 | dexJarBuildPath := p.DexJarBuildPath() |
| 4369 | if expected, actual := ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar", android.NormalizePathForTesting(dexJarBuildPath); actual != expected { |
| 4370 | t.Errorf("Incorrect DexJarBuildPath value '%s', expected '%s'", actual, expected) |
| 4371 | } |
| 4372 | } |
| 4373 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4374 | ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4375 | // Make sure that an apex variant is not created for the source module. |
| 4376 | if expected, actual := []string{"android_common"}, ctx.ModuleVariantsForTests("libfoo"); !reflect.DeepEqual(expected, actual) { |
| 4377 | t.Errorf("invalid set of variants for %q: expected %q, found %q", "libfoo", expected, actual) |
| 4378 | } |
| 4379 | } |
| 4380 | |
| 4381 | t.Run("prebuilt only", func(t *testing.T) { |
| 4382 | bp := ` |
| 4383 | prebuilt_apex { |
| 4384 | name: "myapex", |
| 4385 | arch: { |
| 4386 | arm64: { |
| 4387 | src: "myapex-arm64.apex", |
| 4388 | }, |
| 4389 | arm: { |
| 4390 | src: "myapex-arm.apex", |
| 4391 | }, |
| 4392 | }, |
| 4393 | exported_java_libs: ["libfoo"], |
| 4394 | } |
| 4395 | |
| 4396 | java_import { |
| 4397 | name: "libfoo", |
| 4398 | jars: ["libfoo.jar"], |
| 4399 | } |
| 4400 | ` |
| 4401 | |
| 4402 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4403 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4404 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4405 | checkDexJarBuildPath(t, ctx, "libfoo") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4406 | }) |
| 4407 | |
| 4408 | t.Run("prebuilt with source preferred", func(t *testing.T) { |
| 4409 | |
| 4410 | bp := ` |
| 4411 | prebuilt_apex { |
| 4412 | name: "myapex", |
| 4413 | arch: { |
| 4414 | arm64: { |
| 4415 | src: "myapex-arm64.apex", |
| 4416 | }, |
| 4417 | arm: { |
| 4418 | src: "myapex-arm.apex", |
| 4419 | }, |
| 4420 | }, |
| 4421 | exported_java_libs: ["libfoo"], |
| 4422 | } |
| 4423 | |
| 4424 | java_import { |
| 4425 | name: "libfoo", |
| 4426 | jars: ["libfoo.jar"], |
| 4427 | } |
| 4428 | |
| 4429 | java_library { |
| 4430 | name: "libfoo", |
| 4431 | } |
| 4432 | ` |
| 4433 | |
| 4434 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4435 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4436 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4437 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
| 4438 | ensureNoSourceVariant(t, ctx) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4439 | }) |
| 4440 | |
| 4441 | t.Run("prebuilt preferred with source", func(t *testing.T) { |
| 4442 | bp := ` |
| 4443 | prebuilt_apex { |
| 4444 | name: "myapex", |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4445 | arch: { |
| 4446 | arm64: { |
| 4447 | src: "myapex-arm64.apex", |
| 4448 | }, |
| 4449 | arm: { |
| 4450 | src: "myapex-arm.apex", |
| 4451 | }, |
| 4452 | }, |
| 4453 | exported_java_libs: ["libfoo"], |
| 4454 | } |
| 4455 | |
| 4456 | java_import { |
| 4457 | name: "libfoo", |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4458 | prefer: true, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4459 | jars: ["libfoo.jar"], |
| 4460 | } |
| 4461 | |
| 4462 | java_library { |
| 4463 | name: "libfoo", |
| 4464 | } |
| 4465 | ` |
| 4466 | |
| 4467 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4468 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4469 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4470 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
| 4471 | ensureNoSourceVariant(t, ctx) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4472 | }) |
| 4473 | } |
| 4474 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4475 | func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { |
| 4476 | transform := func(config *dexpreopt.GlobalConfig) { |
| 4477 | config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo"}) |
| 4478 | } |
| 4479 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4480 | checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, bootDexJarPath string) { |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4481 | s := ctx.SingletonForTests("dex_bootjars") |
| 4482 | foundLibfooJar := false |
| 4483 | for _, output := range s.AllOutputs() { |
| 4484 | if strings.HasSuffix(output, "/libfoo.jar") { |
| 4485 | foundLibfooJar = true |
| 4486 | buildRule := s.Output(output) |
| 4487 | actual := android.NormalizePathForTesting(buildRule.Input) |
| 4488 | if actual != bootDexJarPath { |
| 4489 | t.Errorf("Incorrect boot dex jar path '%s', expected '%s'", actual, bootDexJarPath) |
| 4490 | } |
| 4491 | } |
| 4492 | } |
| 4493 | if !foundLibfooJar { |
| 4494 | t.Errorf("Rule for libfoo.jar missing in dex_bootjars singleton outputs") |
| 4495 | } |
| 4496 | } |
| 4497 | |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame^] | 4498 | checkHiddenAPIIndexInputs := func(t *testing.T, ctx *android.TestContext, expectedInputs string) { |
| 4499 | hiddenAPIIndex := ctx.SingletonForTests("hiddenapi_index") |
| 4500 | indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index") |
| 4501 | java.CheckHiddenAPIRuleInputs(t, expectedInputs, indexRule) |
| 4502 | } |
| 4503 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4504 | t.Run("prebuilt only", func(t *testing.T) { |
| 4505 | bp := ` |
| 4506 | prebuilt_apex { |
| 4507 | name: "myapex", |
| 4508 | arch: { |
| 4509 | arm64: { |
| 4510 | src: "myapex-arm64.apex", |
| 4511 | }, |
| 4512 | arm: { |
| 4513 | src: "myapex-arm.apex", |
| 4514 | }, |
| 4515 | }, |
| 4516 | exported_java_libs: ["libfoo"], |
| 4517 | } |
| 4518 | |
| 4519 | java_import { |
| 4520 | name: "libfoo", |
| 4521 | jars: ["libfoo.jar"], |
| 4522 | apex_available: ["myapex"], |
| 4523 | } |
| 4524 | ` |
| 4525 | |
| 4526 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4527 | checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame^] | 4528 | |
| 4529 | // Make sure that the dex file from the prebuilt_apex does NOT contribute to the hiddenapi index |
| 4530 | // file. |
| 4531 | checkHiddenAPIIndexInputs(t, ctx, ``) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4532 | }) |
| 4533 | |
| 4534 | t.Run("prebuilt with source library preferred", func(t *testing.T) { |
| 4535 | bp := ` |
| 4536 | prebuilt_apex { |
| 4537 | name: "myapex", |
| 4538 | arch: { |
| 4539 | arm64: { |
| 4540 | src: "myapex-arm64.apex", |
| 4541 | }, |
| 4542 | arm: { |
| 4543 | src: "myapex-arm.apex", |
| 4544 | }, |
| 4545 | }, |
| 4546 | exported_java_libs: ["libfoo"], |
| 4547 | } |
| 4548 | |
| 4549 | java_import { |
| 4550 | name: "libfoo", |
| 4551 | jars: ["libfoo.jar"], |
| 4552 | apex_available: ["myapex"], |
| 4553 | } |
| 4554 | |
| 4555 | java_library { |
| 4556 | name: "libfoo", |
| 4557 | srcs: ["foo/bar/MyClass.java"], |
| 4558 | apex_available: ["myapex"], |
| 4559 | } |
| 4560 | ` |
| 4561 | |
| 4562 | // In this test the source (java_library) libfoo is active since the |
| 4563 | // prebuilt (java_import) defaults to prefer:false. However the |
| 4564 | // prebuilt_apex module always depends on the prebuilt, and so it doesn't |
| 4565 | // find the dex boot jar in it. We either need to disable the source libfoo |
| 4566 | // or make the prebuilt libfoo preferred. |
| 4567 | testDexpreoptWithApexes(t, bp, "failed to find a dex jar path for module 'libfoo'", transform) |
| 4568 | }) |
| 4569 | |
| 4570 | t.Run("prebuilt library preferred with source", func(t *testing.T) { |
| 4571 | bp := ` |
| 4572 | prebuilt_apex { |
| 4573 | name: "myapex", |
| 4574 | arch: { |
| 4575 | arm64: { |
| 4576 | src: "myapex-arm64.apex", |
| 4577 | }, |
| 4578 | arm: { |
| 4579 | src: "myapex-arm.apex", |
| 4580 | }, |
| 4581 | }, |
| 4582 | exported_java_libs: ["libfoo"], |
| 4583 | } |
| 4584 | |
| 4585 | java_import { |
| 4586 | name: "libfoo", |
| 4587 | prefer: true, |
| 4588 | jars: ["libfoo.jar"], |
| 4589 | apex_available: ["myapex"], |
| 4590 | } |
| 4591 | |
| 4592 | java_library { |
| 4593 | name: "libfoo", |
| 4594 | srcs: ["foo/bar/MyClass.java"], |
| 4595 | apex_available: ["myapex"], |
| 4596 | } |
| 4597 | ` |
| 4598 | |
| 4599 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4600 | checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame^] | 4601 | |
| 4602 | // Make sure that the dex file from the prebuilt_apex does NOT contribute to the hiddenapi index |
| 4603 | // file. |
| 4604 | checkHiddenAPIIndexInputs(t, ctx, ``) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4605 | }) |
| 4606 | |
| 4607 | t.Run("prebuilt with source apex preferred", func(t *testing.T) { |
| 4608 | bp := ` |
| 4609 | apex { |
| 4610 | name: "myapex", |
| 4611 | key: "myapex.key", |
| 4612 | java_libs: ["libfoo"], |
| 4613 | } |
| 4614 | |
| 4615 | apex_key { |
| 4616 | name: "myapex.key", |
| 4617 | public_key: "testkey.avbpubkey", |
| 4618 | private_key: "testkey.pem", |
| 4619 | } |
| 4620 | |
| 4621 | prebuilt_apex { |
| 4622 | name: "myapex", |
| 4623 | arch: { |
| 4624 | arm64: { |
| 4625 | src: "myapex-arm64.apex", |
| 4626 | }, |
| 4627 | arm: { |
| 4628 | src: "myapex-arm.apex", |
| 4629 | }, |
| 4630 | }, |
| 4631 | exported_java_libs: ["libfoo"], |
| 4632 | } |
| 4633 | |
| 4634 | java_import { |
| 4635 | name: "libfoo", |
| 4636 | jars: ["libfoo.jar"], |
| 4637 | apex_available: ["myapex"], |
| 4638 | } |
| 4639 | |
| 4640 | java_library { |
| 4641 | name: "libfoo", |
| 4642 | srcs: ["foo/bar/MyClass.java"], |
| 4643 | apex_available: ["myapex"], |
| 4644 | } |
| 4645 | ` |
| 4646 | |
| 4647 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 4648 | checkBootDexJarPath(t, ctx, ".intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame^] | 4649 | |
| 4650 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4651 | checkHiddenAPIIndexInputs(t, ctx, ` |
| 4652 | .intermediates/libfoo/android_common_apex10000/hiddenapi/index.csv |
| 4653 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4654 | }) |
| 4655 | |
| 4656 | t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) { |
| 4657 | bp := ` |
| 4658 | apex { |
| 4659 | name: "myapex", |
| 4660 | enabled: false, |
| 4661 | key: "myapex.key", |
| 4662 | java_libs: ["libfoo"], |
| 4663 | } |
| 4664 | |
| 4665 | apex_key { |
| 4666 | name: "myapex.key", |
| 4667 | public_key: "testkey.avbpubkey", |
| 4668 | private_key: "testkey.pem", |
| 4669 | } |
| 4670 | |
| 4671 | prebuilt_apex { |
| 4672 | name: "myapex", |
| 4673 | arch: { |
| 4674 | arm64: { |
| 4675 | src: "myapex-arm64.apex", |
| 4676 | }, |
| 4677 | arm: { |
| 4678 | src: "myapex-arm.apex", |
| 4679 | }, |
| 4680 | }, |
| 4681 | exported_java_libs: ["libfoo"], |
| 4682 | } |
| 4683 | |
| 4684 | java_import { |
| 4685 | name: "libfoo", |
| 4686 | prefer: true, |
| 4687 | jars: ["libfoo.jar"], |
| 4688 | apex_available: ["myapex"], |
| 4689 | } |
| 4690 | |
| 4691 | java_library { |
| 4692 | name: "libfoo", |
| 4693 | srcs: ["foo/bar/MyClass.java"], |
| 4694 | apex_available: ["myapex"], |
| 4695 | } |
| 4696 | ` |
| 4697 | |
| 4698 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4699 | checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame^] | 4700 | |
| 4701 | // Make sure that the dex file from the prebuilt_apex does NOT contribute to the hiddenapi index |
| 4702 | // file. |
| 4703 | checkHiddenAPIIndexInputs(t, ctx, ``) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4704 | }) |
| 4705 | } |
| 4706 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4707 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4708 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4709 | apex_test { |
| 4710 | name: "myapex", |
| 4711 | key: "myapex.key", |
| 4712 | tests: [ |
| 4713 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4714 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4715 | ], |
| 4716 | } |
| 4717 | |
| 4718 | apex_key { |
| 4719 | name: "myapex.key", |
| 4720 | public_key: "testkey.avbpubkey", |
| 4721 | private_key: "testkey.pem", |
| 4722 | } |
| 4723 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4724 | filegroup { |
| 4725 | name: "fg", |
| 4726 | srcs: [ |
| 4727 | "baz", |
| 4728 | "bar/baz" |
| 4729 | ], |
| 4730 | } |
| 4731 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4732 | cc_test { |
| 4733 | name: "mytest", |
| 4734 | gtest: false, |
| 4735 | srcs: ["mytest.cpp"], |
| 4736 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4737 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4738 | system_shared_libs: [], |
| 4739 | static_executable: true, |
| 4740 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4741 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4742 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4743 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4744 | cc_library { |
| 4745 | name: "mylib", |
| 4746 | srcs: ["mylib.cpp"], |
| 4747 | system_shared_libs: [], |
| 4748 | stl: "none", |
| 4749 | } |
| 4750 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4751 | filegroup { |
| 4752 | name: "fg2", |
| 4753 | srcs: [ |
| 4754 | "testdata/baz" |
| 4755 | ], |
| 4756 | } |
| 4757 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4758 | cc_test { |
| 4759 | name: "mytests", |
| 4760 | gtest: false, |
| 4761 | srcs: [ |
| 4762 | "mytest1.cpp", |
| 4763 | "mytest2.cpp", |
| 4764 | "mytest3.cpp", |
| 4765 | ], |
| 4766 | test_per_src: true, |
| 4767 | relative_install_path: "test", |
| 4768 | system_shared_libs: [], |
| 4769 | static_executable: true, |
| 4770 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4771 | data: [ |
| 4772 | ":fg", |
| 4773 | ":fg2", |
| 4774 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4775 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4776 | `) |
| 4777 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4778 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4779 | copyCmds := apexRule.Args["copy_commands"] |
| 4780 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4781 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4782 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4783 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4784 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4785 | //Ensure that test data are copied into apex. |
| 4786 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 4787 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 4788 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4789 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 4790 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 4791 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 4792 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4793 | |
| 4794 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4795 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 4796 | data := android.AndroidMkDataForTest(t, config, "", bundle) |
| 4797 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4798 | prefix := "TARGET_" |
| 4799 | var builder strings.Builder |
| 4800 | data.Custom(&builder, name, prefix, "", data) |
| 4801 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4802 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 4803 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 4804 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 4805 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4806 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4807 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4808 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4809 | |
| 4810 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 4811 | data = android.AndroidMkDataForTest(t, config, "", flatBundle) |
| 4812 | data.Custom(&builder, name, prefix, "", data) |
| 4813 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4814 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 4815 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4816 | } |
| 4817 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4818 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
| 4819 | ctx, config := testApex(t, ` |
| 4820 | apex { |
| 4821 | name: "myapex", |
| 4822 | key: "myapex.key", |
| 4823 | } |
| 4824 | apex_key { |
| 4825 | name: "myapex.key", |
| 4826 | public_key: "testkey.avbpubkey", |
| 4827 | private_key: "testkey.pem", |
| 4828 | } |
| 4829 | `, func(fs map[string][]byte, config android.Config) { |
| 4830 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 4831 | }) |
| 4832 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 4833 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4834 | mk := android.AndroidMkDataForTest(t, config, "", ab) |
| 4835 | var builder strings.Builder |
| 4836 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 4837 | androidMk := builder.String() |
| 4838 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 4839 | } |
| 4840 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4841 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 4842 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 4843 | apex { |
| 4844 | name: "myapex", |
| 4845 | key: "myapex.key", |
| 4846 | native_shared_libs: ["libfoo"], |
| 4847 | } |
| 4848 | |
| 4849 | apex_key { |
| 4850 | name: "myapex.key", |
| 4851 | public_key: "testkey.avbpubkey", |
| 4852 | private_key: "testkey.pem", |
| 4853 | } |
| 4854 | |
| 4855 | cc_library { |
| 4856 | name: "libfoo", |
| 4857 | stl: "none", |
| 4858 | system_shared_libs: [], |
| 4859 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4860 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4861 | } |
| 4862 | `) |
| 4863 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 4864 | apex { |
| 4865 | name: "myapex", |
| 4866 | key: "myapex.key", |
| 4867 | java_libs: ["myjar"], |
| 4868 | } |
| 4869 | |
| 4870 | apex_key { |
| 4871 | name: "myapex.key", |
| 4872 | public_key: "testkey.avbpubkey", |
| 4873 | private_key: "testkey.pem", |
| 4874 | } |
| 4875 | |
| 4876 | java_library { |
| 4877 | name: "myjar", |
| 4878 | srcs: ["foo/bar/MyClass.java"], |
| 4879 | sdk_version: "none", |
| 4880 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4881 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4882 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4883 | } |
| 4884 | `) |
| 4885 | } |
| 4886 | |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 4887 | func TestApexWithJavaImport(t *testing.T) { |
| 4888 | ctx, _ := testApex(t, ` |
| 4889 | apex { |
| 4890 | name: "myapex", |
| 4891 | key: "myapex.key", |
| 4892 | java_libs: ["myjavaimport"], |
| 4893 | } |
| 4894 | |
| 4895 | apex_key { |
| 4896 | name: "myapex.key", |
| 4897 | public_key: "testkey.avbpubkey", |
| 4898 | private_key: "testkey.pem", |
| 4899 | } |
| 4900 | |
| 4901 | java_import { |
| 4902 | name: "myjavaimport", |
| 4903 | apex_available: ["myapex"], |
| 4904 | jars: ["my.jar"], |
| 4905 | compile_dex: true, |
| 4906 | } |
| 4907 | `) |
| 4908 | |
| 4909 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4910 | apexRule := module.Rule("apexRule") |
| 4911 | copyCmds := apexRule.Args["copy_commands"] |
| 4912 | ensureContains(t, copyCmds, "image.apex/javalib/myjavaimport.jar") |
| 4913 | } |
| 4914 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4915 | func TestApexWithApps(t *testing.T) { |
| 4916 | ctx, _ := testApex(t, ` |
| 4917 | apex { |
| 4918 | name: "myapex", |
| 4919 | key: "myapex.key", |
| 4920 | apps: [ |
| 4921 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4922 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4923 | ], |
| 4924 | } |
| 4925 | |
| 4926 | apex_key { |
| 4927 | name: "myapex.key", |
| 4928 | public_key: "testkey.avbpubkey", |
| 4929 | private_key: "testkey.pem", |
| 4930 | } |
| 4931 | |
| 4932 | android_app { |
| 4933 | name: "AppFoo", |
| 4934 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4935 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4936 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4937 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4938 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4939 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4940 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4941 | |
| 4942 | android_app { |
| 4943 | name: "AppFooPriv", |
| 4944 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4945 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4946 | system_modules: "none", |
| 4947 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4948 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4949 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4950 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4951 | |
| 4952 | cc_library_shared { |
| 4953 | name: "libjni", |
| 4954 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4955 | shared_libs: ["libfoo"], |
| 4956 | stl: "none", |
| 4957 | system_shared_libs: [], |
| 4958 | apex_available: [ "myapex" ], |
| 4959 | sdk_version: "current", |
| 4960 | } |
| 4961 | |
| 4962 | cc_library_shared { |
| 4963 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4964 | stl: "none", |
| 4965 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 4966 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4967 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4968 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4969 | `) |
| 4970 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4971 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4972 | apexRule := module.Rule("apexRule") |
| 4973 | copyCmds := apexRule.Args["copy_commands"] |
| 4974 | |
| 4975 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4976 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4977 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4978 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4979 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4980 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4981 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4982 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4983 | // JNI libraries including transitive deps are |
| 4984 | for _, jni := range []string{"libjni", "libfoo"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4985 | 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] | 4986 | // ... embedded inside APK (jnilibs.zip) |
| 4987 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 4988 | // ... and not directly inside the APEX |
| 4989 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 4990 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4991 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4992 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4993 | func TestApexWithAppImports(t *testing.T) { |
| 4994 | ctx, _ := testApex(t, ` |
| 4995 | apex { |
| 4996 | name: "myapex", |
| 4997 | key: "myapex.key", |
| 4998 | apps: [ |
| 4999 | "AppFooPrebuilt", |
| 5000 | "AppFooPrivPrebuilt", |
| 5001 | ], |
| 5002 | } |
| 5003 | |
| 5004 | apex_key { |
| 5005 | name: "myapex.key", |
| 5006 | public_key: "testkey.avbpubkey", |
| 5007 | private_key: "testkey.pem", |
| 5008 | } |
| 5009 | |
| 5010 | android_app_import { |
| 5011 | name: "AppFooPrebuilt", |
| 5012 | apk: "PrebuiltAppFoo.apk", |
| 5013 | presigned: true, |
| 5014 | dex_preopt: { |
| 5015 | enabled: false, |
| 5016 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5017 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | android_app_import { |
| 5021 | name: "AppFooPrivPrebuilt", |
| 5022 | apk: "PrebuiltAppFooPriv.apk", |
| 5023 | privileged: true, |
| 5024 | presigned: true, |
| 5025 | dex_preopt: { |
| 5026 | enabled: false, |
| 5027 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5028 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5029 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5030 | } |
| 5031 | `) |
| 5032 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5033 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5034 | apexRule := module.Rule("apexRule") |
| 5035 | copyCmds := apexRule.Args["copy_commands"] |
| 5036 | |
| 5037 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5038 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 5039 | } |
| 5040 | |
| 5041 | func TestApexWithAppImportsPrefer(t *testing.T) { |
| 5042 | ctx, _ := testApex(t, ` |
| 5043 | apex { |
| 5044 | name: "myapex", |
| 5045 | key: "myapex.key", |
| 5046 | apps: [ |
| 5047 | "AppFoo", |
| 5048 | ], |
| 5049 | } |
| 5050 | |
| 5051 | apex_key { |
| 5052 | name: "myapex.key", |
| 5053 | public_key: "testkey.avbpubkey", |
| 5054 | private_key: "testkey.pem", |
| 5055 | } |
| 5056 | |
| 5057 | android_app { |
| 5058 | name: "AppFoo", |
| 5059 | srcs: ["foo/bar/MyClass.java"], |
| 5060 | sdk_version: "none", |
| 5061 | system_modules: "none", |
| 5062 | apex_available: [ "myapex" ], |
| 5063 | } |
| 5064 | |
| 5065 | android_app_import { |
| 5066 | name: "AppFoo", |
| 5067 | apk: "AppFooPrebuilt.apk", |
| 5068 | filename: "AppFooPrebuilt.apk", |
| 5069 | presigned: true, |
| 5070 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5071 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5072 | } |
| 5073 | `, withFiles(map[string][]byte{ |
| 5074 | "AppFooPrebuilt.apk": nil, |
| 5075 | })) |
| 5076 | |
| 5077 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5078 | "app/AppFoo/AppFooPrebuilt.apk", |
| 5079 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5080 | } |
| 5081 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5082 | func TestApexWithTestHelperApp(t *testing.T) { |
| 5083 | ctx, _ := testApex(t, ` |
| 5084 | apex { |
| 5085 | name: "myapex", |
| 5086 | key: "myapex.key", |
| 5087 | apps: [ |
| 5088 | "TesterHelpAppFoo", |
| 5089 | ], |
| 5090 | } |
| 5091 | |
| 5092 | apex_key { |
| 5093 | name: "myapex.key", |
| 5094 | public_key: "testkey.avbpubkey", |
| 5095 | private_key: "testkey.pem", |
| 5096 | } |
| 5097 | |
| 5098 | android_test_helper_app { |
| 5099 | name: "TesterHelpAppFoo", |
| 5100 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5101 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | `) |
| 5105 | |
| 5106 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5107 | apexRule := module.Rule("apexRule") |
| 5108 | copyCmds := apexRule.Args["copy_commands"] |
| 5109 | |
| 5110 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 5111 | } |
| 5112 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5113 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 5114 | // libfoo's apex_available comes from cc_defaults |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5115 | 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] | 5116 | apex { |
| 5117 | name: "myapex", |
| 5118 | key: "myapex.key", |
| 5119 | native_shared_libs: ["libfoo"], |
| 5120 | } |
| 5121 | |
| 5122 | apex_key { |
| 5123 | name: "myapex.key", |
| 5124 | public_key: "testkey.avbpubkey", |
| 5125 | private_key: "testkey.pem", |
| 5126 | } |
| 5127 | |
| 5128 | apex { |
| 5129 | name: "otherapex", |
| 5130 | key: "myapex.key", |
| 5131 | native_shared_libs: ["libfoo"], |
| 5132 | } |
| 5133 | |
| 5134 | cc_defaults { |
| 5135 | name: "libfoo-defaults", |
| 5136 | apex_available: ["otherapex"], |
| 5137 | } |
| 5138 | |
| 5139 | cc_library { |
| 5140 | name: "libfoo", |
| 5141 | defaults: ["libfoo-defaults"], |
| 5142 | stl: "none", |
| 5143 | system_shared_libs: [], |
| 5144 | }`) |
| 5145 | } |
| 5146 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5147 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5148 | // libfoo is not available to myapex, but only to otherapex |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5149 | 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] | 5150 | apex { |
| 5151 | name: "myapex", |
| 5152 | key: "myapex.key", |
| 5153 | native_shared_libs: ["libfoo"], |
| 5154 | } |
| 5155 | |
| 5156 | apex_key { |
| 5157 | name: "myapex.key", |
| 5158 | public_key: "testkey.avbpubkey", |
| 5159 | private_key: "testkey.pem", |
| 5160 | } |
| 5161 | |
| 5162 | apex { |
| 5163 | name: "otherapex", |
| 5164 | key: "otherapex.key", |
| 5165 | native_shared_libs: ["libfoo"], |
| 5166 | } |
| 5167 | |
| 5168 | apex_key { |
| 5169 | name: "otherapex.key", |
| 5170 | public_key: "testkey.avbpubkey", |
| 5171 | private_key: "testkey.pem", |
| 5172 | } |
| 5173 | |
| 5174 | cc_library { |
| 5175 | name: "libfoo", |
| 5176 | stl: "none", |
| 5177 | system_shared_libs: [], |
| 5178 | apex_available: ["otherapex"], |
| 5179 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5180 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5181 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5182 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5183 | // libbbaz is an indirect dep |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5184 | 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] | 5185 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5186 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5187 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5188 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5189 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 5190 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5191 | apex { |
| 5192 | name: "myapex", |
| 5193 | key: "myapex.key", |
| 5194 | native_shared_libs: ["libfoo"], |
| 5195 | } |
| 5196 | |
| 5197 | apex_key { |
| 5198 | name: "myapex.key", |
| 5199 | public_key: "testkey.avbpubkey", |
| 5200 | private_key: "testkey.pem", |
| 5201 | } |
| 5202 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5203 | cc_library { |
| 5204 | name: "libfoo", |
| 5205 | stl: "none", |
| 5206 | shared_libs: ["libbar"], |
| 5207 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5208 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | cc_library { |
| 5212 | name: "libbar", |
| 5213 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5214 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5215 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5216 | apex_available: ["myapex"], |
| 5217 | } |
| 5218 | |
| 5219 | cc_library { |
| 5220 | name: "libbaz", |
| 5221 | stl: "none", |
| 5222 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5223 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5224 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5225 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5226 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5227 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 5228 | apex { |
| 5229 | name: "myapex", |
| 5230 | key: "myapex.key", |
| 5231 | native_shared_libs: ["libfoo"], |
| 5232 | } |
| 5233 | |
| 5234 | apex_key { |
| 5235 | name: "myapex.key", |
| 5236 | public_key: "testkey.avbpubkey", |
| 5237 | private_key: "testkey.pem", |
| 5238 | } |
| 5239 | |
| 5240 | cc_library { |
| 5241 | name: "libfoo", |
| 5242 | stl: "none", |
| 5243 | system_shared_libs: [], |
| 5244 | apex_available: ["otherapex"], |
| 5245 | }`) |
| 5246 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5247 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5248 | apex { |
| 5249 | name: "myapex", |
| 5250 | key: "myapex.key", |
| 5251 | native_shared_libs: ["libfoo", "libbar"], |
| 5252 | } |
| 5253 | |
| 5254 | apex_key { |
| 5255 | name: "myapex.key", |
| 5256 | public_key: "testkey.avbpubkey", |
| 5257 | private_key: "testkey.pem", |
| 5258 | } |
| 5259 | |
| 5260 | cc_library { |
| 5261 | name: "libfoo", |
| 5262 | stl: "none", |
| 5263 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5264 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5265 | apex_available: ["myapex"], |
| 5266 | } |
| 5267 | |
| 5268 | cc_library { |
| 5269 | name: "libbar", |
| 5270 | stl: "none", |
| 5271 | system_shared_libs: [], |
| 5272 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | cc_library { |
| 5276 | name: "libbaz", |
| 5277 | stl: "none", |
| 5278 | system_shared_libs: [], |
| 5279 | stubs: { |
| 5280 | versions: ["10", "20", "30"], |
| 5281 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5282 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5283 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5284 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5285 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5286 | ctx, _ := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5287 | apex { |
| 5288 | name: "myapex", |
| 5289 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5290 | native_shared_libs: ["libbar", "libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | apex_key { |
| 5294 | name: "myapex.key", |
| 5295 | public_key: "testkey.avbpubkey", |
| 5296 | private_key: "testkey.pem", |
| 5297 | } |
| 5298 | |
| 5299 | cc_library { |
| 5300 | name: "libfoo", |
| 5301 | stl: "none", |
| 5302 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5303 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5304 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | cc_library { |
| 5308 | name: "libfoo2", |
| 5309 | stl: "none", |
| 5310 | system_shared_libs: [], |
| 5311 | shared_libs: ["libbaz"], |
| 5312 | apex_available: ["//apex_available:platform"], |
| 5313 | } |
| 5314 | |
| 5315 | cc_library { |
| 5316 | name: "libbar", |
| 5317 | stl: "none", |
| 5318 | system_shared_libs: [], |
| 5319 | apex_available: ["myapex"], |
| 5320 | } |
| 5321 | |
| 5322 | cc_library { |
| 5323 | name: "libbaz", |
| 5324 | stl: "none", |
| 5325 | system_shared_libs: [], |
| 5326 | apex_available: ["myapex"], |
| 5327 | stubs: { |
| 5328 | versions: ["1"], |
| 5329 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5330 | }`) |
| 5331 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5332 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 5333 | // because it depends on libbar which isn't available to platform |
| 5334 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5335 | if libfoo.NotAvailableForPlatform() != true { |
| 5336 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 5337 | } |
| 5338 | |
| 5339 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 5340 | // stubs |
| 5341 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5342 | if libfoo2.NotAvailableForPlatform() == true { |
| 5343 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 5344 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5345 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5346 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5347 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5348 | ctx, _ := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5349 | apex { |
| 5350 | name: "myapex", |
| 5351 | key: "myapex.key", |
| 5352 | native_shared_libs: ["libfoo"], |
| 5353 | } |
| 5354 | |
| 5355 | apex_key { |
| 5356 | name: "myapex.key", |
| 5357 | public_key: "testkey.avbpubkey", |
| 5358 | private_key: "testkey.pem", |
| 5359 | } |
| 5360 | |
| 5361 | cc_library { |
| 5362 | name: "libfoo", |
| 5363 | stl: "none", |
| 5364 | system_shared_libs: [], |
| 5365 | apex_available: ["myapex"], |
| 5366 | static: { |
| 5367 | apex_available: ["//apex_available:platform"], |
| 5368 | }, |
| 5369 | }`) |
| 5370 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5371 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5372 | if libfooShared.NotAvailableForPlatform() != true { |
| 5373 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 5374 | } |
| 5375 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 5376 | if libfooStatic.NotAvailableForPlatform() != false { |
| 5377 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 5378 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5379 | } |
| 5380 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5381 | func TestOverrideApex(t *testing.T) { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5382 | ctx, config := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5383 | apex { |
| 5384 | name: "myapex", |
| 5385 | key: "myapex.key", |
| 5386 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5387 | overrides: ["oldapex"], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | override_apex { |
| 5391 | name: "override_myapex", |
| 5392 | base: "myapex", |
| 5393 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5394 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5395 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5396 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | apex_key { |
| 5400 | name: "myapex.key", |
| 5401 | public_key: "testkey.avbpubkey", |
| 5402 | private_key: "testkey.pem", |
| 5403 | } |
| 5404 | |
| 5405 | android_app { |
| 5406 | name: "app", |
| 5407 | srcs: ["foo/bar/MyClass.java"], |
| 5408 | package_name: "foo", |
| 5409 | sdk_version: "none", |
| 5410 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5411 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5412 | } |
| 5413 | |
| 5414 | override_android_app { |
| 5415 | name: "override_app", |
| 5416 | base: "app", |
| 5417 | package_name: "bar", |
| 5418 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5419 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5420 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 5421 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 5422 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 5423 | if originalVariant.GetOverriddenBy() != "" { |
| 5424 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 5425 | } |
| 5426 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 5427 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 5428 | } |
| 5429 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5430 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 5431 | apexRule := module.Rule("apexRule") |
| 5432 | copyCmds := apexRule.Args["copy_commands"] |
| 5433 | |
| 5434 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5435 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5436 | |
| 5437 | apexBundle := module.Module().(*apexBundle) |
| 5438 | name := apexBundle.Name() |
| 5439 | if name != "override_myapex" { |
| 5440 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 5441 | } |
| 5442 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5443 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 5444 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 5445 | } |
| 5446 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5447 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5448 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5449 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5450 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 5451 | var builder strings.Builder |
| 5452 | data.Custom(&builder, name, "TARGET_", "", data) |
| 5453 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5454 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5455 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 5456 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5457 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5458 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5459 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5460 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 5461 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5462 | } |
| 5463 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5464 | func TestLegacyAndroid10Support(t *testing.T) { |
| 5465 | ctx, _ := testApex(t, ` |
| 5466 | apex { |
| 5467 | name: "myapex", |
| 5468 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5469 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 5470 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5471 | } |
| 5472 | |
| 5473 | apex_key { |
| 5474 | name: "myapex.key", |
| 5475 | public_key: "testkey.avbpubkey", |
| 5476 | private_key: "testkey.pem", |
| 5477 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5478 | |
| 5479 | cc_library { |
| 5480 | name: "mylib", |
| 5481 | srcs: ["mylib.cpp"], |
| 5482 | stl: "libc++", |
| 5483 | system_shared_libs: [], |
| 5484 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5485 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5486 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5487 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5488 | |
| 5489 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5490 | args := module.Rule("apexRule").Args |
| 5491 | 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] | 5492 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5493 | |
| 5494 | // The copies of the libraries in the apex should have one more dependency than |
| 5495 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 5496 | // the dependency names directly here but for some reason the names are blank in |
| 5497 | // this test. |
| 5498 | for _, lib := range []string{"libc++", "mylib"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5499 | 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] | 5500 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 5501 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 5502 | t.Errorf("%q missing unwinder dep", lib) |
| 5503 | } |
| 5504 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5505 | } |
| 5506 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5507 | var filesForSdkLibrary = map[string][]byte{ |
| 5508 | "api/current.txt": nil, |
| 5509 | "api/removed.txt": nil, |
| 5510 | "api/system-current.txt": nil, |
| 5511 | "api/system-removed.txt": nil, |
| 5512 | "api/test-current.txt": nil, |
| 5513 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5514 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5515 | "100/public/api/foo.txt": nil, |
| 5516 | "100/public/api/foo-removed.txt": nil, |
| 5517 | "100/system/api/foo.txt": nil, |
| 5518 | "100/system/api/foo-removed.txt": nil, |
| 5519 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5520 | // For java_sdk_library_import |
| 5521 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5522 | } |
| 5523 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5524 | func TestJavaSDKLibrary(t *testing.T) { |
| 5525 | ctx, _ := testApex(t, ` |
| 5526 | apex { |
| 5527 | name: "myapex", |
| 5528 | key: "myapex.key", |
| 5529 | java_libs: ["foo"], |
| 5530 | } |
| 5531 | |
| 5532 | apex_key { |
| 5533 | name: "myapex.key", |
| 5534 | public_key: "testkey.avbpubkey", |
| 5535 | private_key: "testkey.pem", |
| 5536 | } |
| 5537 | |
| 5538 | java_sdk_library { |
| 5539 | name: "foo", |
| 5540 | srcs: ["a.java"], |
| 5541 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5542 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5543 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5544 | |
| 5545 | prebuilt_apis { |
| 5546 | name: "sdk", |
| 5547 | api_dirs: ["100"], |
| 5548 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5549 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5550 | |
| 5551 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5552 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5553 | "javalib/foo.jar", |
| 5554 | "etc/permissions/foo.xml", |
| 5555 | }) |
| 5556 | // 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] | 5557 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 5558 | 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] | 5559 | } |
| 5560 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5561 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
| 5562 | ctx, _ := testApex(t, ` |
| 5563 | apex { |
| 5564 | name: "myapex", |
| 5565 | key: "myapex.key", |
| 5566 | java_libs: ["foo", "bar"], |
| 5567 | } |
| 5568 | |
| 5569 | apex_key { |
| 5570 | name: "myapex.key", |
| 5571 | public_key: "testkey.avbpubkey", |
| 5572 | private_key: "testkey.pem", |
| 5573 | } |
| 5574 | |
| 5575 | java_sdk_library { |
| 5576 | name: "foo", |
| 5577 | srcs: ["a.java"], |
| 5578 | api_packages: ["foo"], |
| 5579 | apex_available: ["myapex"], |
| 5580 | sdk_version: "none", |
| 5581 | system_modules: "none", |
| 5582 | } |
| 5583 | |
| 5584 | java_library { |
| 5585 | name: "bar", |
| 5586 | srcs: ["a.java"], |
| 5587 | libs: ["foo"], |
| 5588 | apex_available: ["myapex"], |
| 5589 | sdk_version: "none", |
| 5590 | system_modules: "none", |
| 5591 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5592 | |
| 5593 | prebuilt_apis { |
| 5594 | name: "sdk", |
| 5595 | api_dirs: ["100"], |
| 5596 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5597 | `, withFiles(filesForSdkLibrary)) |
| 5598 | |
| 5599 | // java_sdk_library installs both impl jar and permission XML |
| 5600 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5601 | "javalib/bar.jar", |
| 5602 | "javalib/foo.jar", |
| 5603 | "etc/permissions/foo.xml", |
| 5604 | }) |
| 5605 | |
| 5606 | // The bar library should depend on the implementation jar. |
| 5607 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 5608 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5609 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
| 5614 | ctx, _ := testApex(t, ` |
| 5615 | apex { |
| 5616 | name: "myapex", |
| 5617 | key: "myapex.key", |
| 5618 | java_libs: ["foo"], |
| 5619 | } |
| 5620 | |
| 5621 | apex_key { |
| 5622 | name: "myapex.key", |
| 5623 | public_key: "testkey.avbpubkey", |
| 5624 | private_key: "testkey.pem", |
| 5625 | } |
| 5626 | |
| 5627 | java_sdk_library { |
| 5628 | name: "foo", |
| 5629 | srcs: ["a.java"], |
| 5630 | api_packages: ["foo"], |
| 5631 | apex_available: ["myapex"], |
| 5632 | sdk_version: "none", |
| 5633 | system_modules: "none", |
| 5634 | } |
| 5635 | |
| 5636 | java_library { |
| 5637 | name: "bar", |
| 5638 | srcs: ["a.java"], |
| 5639 | libs: ["foo"], |
| 5640 | sdk_version: "none", |
| 5641 | system_modules: "none", |
| 5642 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5643 | |
| 5644 | prebuilt_apis { |
| 5645 | name: "sdk", |
| 5646 | api_dirs: ["100"], |
| 5647 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5648 | `, withFiles(filesForSdkLibrary)) |
| 5649 | |
| 5650 | // java_sdk_library installs both impl jar and permission XML |
| 5651 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5652 | "javalib/foo.jar", |
| 5653 | "etc/permissions/foo.xml", |
| 5654 | }) |
| 5655 | |
| 5656 | // The bar library should depend on the stubs jar. |
| 5657 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
| 5658 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5659 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5660 | } |
| 5661 | } |
| 5662 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5663 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5664 | ctx, _ := testApex(t, ` |
| 5665 | prebuilt_apis { |
| 5666 | name: "sdk", |
| 5667 | api_dirs: ["100"], |
| 5668 | }`, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5669 | withFiles(map[string][]byte{ |
| 5670 | "apex/a.java": nil, |
| 5671 | "apex/apex_manifest.json": nil, |
| 5672 | "apex/Android.bp": []byte(` |
| 5673 | package { |
| 5674 | default_visibility: ["//visibility:private"], |
| 5675 | } |
| 5676 | |
| 5677 | apex { |
| 5678 | name: "myapex", |
| 5679 | key: "myapex.key", |
| 5680 | java_libs: ["foo", "bar"], |
| 5681 | } |
| 5682 | |
| 5683 | apex_key { |
| 5684 | name: "myapex.key", |
| 5685 | public_key: "testkey.avbpubkey", |
| 5686 | private_key: "testkey.pem", |
| 5687 | } |
| 5688 | |
| 5689 | java_library { |
| 5690 | name: "bar", |
| 5691 | srcs: ["a.java"], |
| 5692 | libs: ["foo"], |
| 5693 | apex_available: ["myapex"], |
| 5694 | sdk_version: "none", |
| 5695 | system_modules: "none", |
| 5696 | } |
| 5697 | `), |
| 5698 | "source/a.java": nil, |
| 5699 | "source/api/current.txt": nil, |
| 5700 | "source/api/removed.txt": nil, |
| 5701 | "source/Android.bp": []byte(` |
| 5702 | package { |
| 5703 | default_visibility: ["//visibility:private"], |
| 5704 | } |
| 5705 | |
| 5706 | java_sdk_library { |
| 5707 | name: "foo", |
| 5708 | visibility: ["//apex"], |
| 5709 | srcs: ["a.java"], |
| 5710 | api_packages: ["foo"], |
| 5711 | apex_available: ["myapex"], |
| 5712 | sdk_version: "none", |
| 5713 | system_modules: "none", |
| 5714 | public: { |
| 5715 | enabled: true, |
| 5716 | }, |
| 5717 | } |
| 5718 | `), |
| 5719 | "prebuilt/a.jar": nil, |
| 5720 | "prebuilt/Android.bp": []byte(` |
| 5721 | package { |
| 5722 | default_visibility: ["//visibility:private"], |
| 5723 | } |
| 5724 | |
| 5725 | java_sdk_library_import { |
| 5726 | name: "foo", |
| 5727 | visibility: ["//apex", "//source"], |
| 5728 | apex_available: ["myapex"], |
| 5729 | prefer: true, |
| 5730 | public: { |
| 5731 | jars: ["a.jar"], |
| 5732 | }, |
| 5733 | } |
| 5734 | `), |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5735 | }), withFiles(filesForSdkLibrary), |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5736 | ) |
| 5737 | |
| 5738 | // java_sdk_library installs both impl jar and permission XML |
| 5739 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5740 | "javalib/bar.jar", |
| 5741 | "javalib/foo.jar", |
| 5742 | "etc/permissions/foo.xml", |
| 5743 | }) |
| 5744 | |
| 5745 | // The bar library should depend on the implementation jar. |
| 5746 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 5747 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.impl\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5748 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5749 | } |
| 5750 | } |
| 5751 | |
| 5752 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 5753 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 5754 | apex { |
| 5755 | name: "myapex", |
| 5756 | key: "myapex.key", |
| 5757 | java_libs: ["foo"], |
| 5758 | } |
| 5759 | |
| 5760 | apex_key { |
| 5761 | name: "myapex.key", |
| 5762 | public_key: "testkey.avbpubkey", |
| 5763 | private_key: "testkey.pem", |
| 5764 | } |
| 5765 | |
| 5766 | java_sdk_library_import { |
| 5767 | name: "foo", |
| 5768 | apex_available: ["myapex"], |
| 5769 | prefer: true, |
| 5770 | public: { |
| 5771 | jars: ["a.jar"], |
| 5772 | }, |
| 5773 | } |
| 5774 | |
| 5775 | `, withFiles(filesForSdkLibrary)) |
| 5776 | } |
| 5777 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5778 | func TestCompatConfig(t *testing.T) { |
| 5779 | ctx, _ := testApex(t, ` |
| 5780 | apex { |
| 5781 | name: "myapex", |
| 5782 | key: "myapex.key", |
| 5783 | prebuilts: ["myjar-platform-compat-config"], |
| 5784 | java_libs: ["myjar"], |
| 5785 | } |
| 5786 | |
| 5787 | apex_key { |
| 5788 | name: "myapex.key", |
| 5789 | public_key: "testkey.avbpubkey", |
| 5790 | private_key: "testkey.pem", |
| 5791 | } |
| 5792 | |
| 5793 | platform_compat_config { |
| 5794 | name: "myjar-platform-compat-config", |
| 5795 | src: ":myjar", |
| 5796 | } |
| 5797 | |
| 5798 | java_library { |
| 5799 | name: "myjar", |
| 5800 | srcs: ["foo/bar/MyClass.java"], |
| 5801 | sdk_version: "none", |
| 5802 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5803 | apex_available: [ "myapex" ], |
| 5804 | } |
| 5805 | `) |
| 5806 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5807 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 5808 | "javalib/myjar.jar", |
| 5809 | }) |
| 5810 | } |
| 5811 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5812 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 5813 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 5814 | apex { |
| 5815 | name: "myapex", |
| 5816 | key: "myapex.key", |
| 5817 | java_libs: ["myjar"], |
| 5818 | } |
| 5819 | |
| 5820 | apex_key { |
| 5821 | name: "myapex.key", |
| 5822 | public_key: "testkey.avbpubkey", |
| 5823 | private_key: "testkey.pem", |
| 5824 | } |
| 5825 | |
| 5826 | java_library { |
| 5827 | name: "myjar", |
| 5828 | srcs: ["foo/bar/MyClass.java"], |
| 5829 | sdk_version: "none", |
| 5830 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 5831 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5832 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5833 | } |
| 5834 | `) |
| 5835 | } |
| 5836 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5837 | func TestCarryRequiredModuleNames(t *testing.T) { |
| 5838 | ctx, config := testApex(t, ` |
| 5839 | apex { |
| 5840 | name: "myapex", |
| 5841 | key: "myapex.key", |
| 5842 | native_shared_libs: ["mylib"], |
| 5843 | } |
| 5844 | |
| 5845 | apex_key { |
| 5846 | name: "myapex.key", |
| 5847 | public_key: "testkey.avbpubkey", |
| 5848 | private_key: "testkey.pem", |
| 5849 | } |
| 5850 | |
| 5851 | cc_library { |
| 5852 | name: "mylib", |
| 5853 | srcs: ["mylib.cpp"], |
| 5854 | system_shared_libs: [], |
| 5855 | stl: "none", |
| 5856 | required: ["a", "b"], |
| 5857 | host_required: ["c", "d"], |
| 5858 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5859 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5860 | } |
| 5861 | `) |
| 5862 | |
| 5863 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 5864 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 5865 | name := apexBundle.BaseModuleName() |
| 5866 | prefix := "TARGET_" |
| 5867 | var builder strings.Builder |
| 5868 | data.Custom(&builder, name, prefix, "", data) |
| 5869 | androidMk := builder.String() |
| 5870 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 5871 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 5872 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 5873 | } |
| 5874 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5875 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 5876 | bp := ` |
| 5877 | apex { |
| 5878 | name: "myapex", |
| 5879 | key: "myapex.key", |
| 5880 | native_shared_libs: ["mylib"], |
| 5881 | java_libs: ["myjar"], |
| 5882 | } |
| 5883 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5884 | apex { |
| 5885 | name: "myapex.updatable", |
| 5886 | key: "myapex.key", |
| 5887 | native_shared_libs: ["mylib"], |
| 5888 | java_libs: ["myjar"], |
| 5889 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 5890 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5891 | } |
| 5892 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5893 | apex_key { |
| 5894 | name: "myapex.key", |
| 5895 | public_key: "testkey.avbpubkey", |
| 5896 | private_key: "testkey.pem", |
| 5897 | } |
| 5898 | |
| 5899 | cc_library { |
| 5900 | name: "mylib", |
| 5901 | srcs: ["mylib.cpp"], |
| 5902 | shared_libs: ["myotherlib"], |
| 5903 | system_shared_libs: [], |
| 5904 | stl: "none", |
| 5905 | apex_available: [ |
| 5906 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5907 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5908 | "//apex_available:platform", |
| 5909 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5910 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | cc_library { |
| 5914 | name: "myotherlib", |
| 5915 | srcs: ["mylib.cpp"], |
| 5916 | system_shared_libs: [], |
| 5917 | stl: "none", |
| 5918 | apex_available: [ |
| 5919 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5920 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5921 | "//apex_available:platform", |
| 5922 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5923 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | java_library { |
| 5927 | name: "myjar", |
| 5928 | srcs: ["foo/bar/MyClass.java"], |
| 5929 | sdk_version: "none", |
| 5930 | system_modules: "none", |
| 5931 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5932 | apex_available: [ |
| 5933 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5934 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5935 | "//apex_available:platform", |
| 5936 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5937 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5938 | } |
| 5939 | |
| 5940 | java_library { |
| 5941 | name: "myotherjar", |
| 5942 | srcs: ["foo/bar/MyClass.java"], |
| 5943 | sdk_version: "none", |
| 5944 | system_modules: "none", |
| 5945 | apex_available: [ |
| 5946 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5947 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5948 | "//apex_available:platform", |
| 5949 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5950 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5951 | } |
| 5952 | ` |
| 5953 | |
| 5954 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 5955 | for _, f := range files { |
| 5956 | if f.path == file { |
| 5957 | if f.isLink { |
| 5958 | t.Errorf("%q is not a real file", file) |
| 5959 | } |
| 5960 | return |
| 5961 | } |
| 5962 | } |
| 5963 | t.Errorf("%q is not found", file) |
| 5964 | } |
| 5965 | |
| 5966 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 5967 | for _, f := range files { |
| 5968 | if f.path == file { |
| 5969 | if !f.isLink { |
| 5970 | t.Errorf("%q is not a symlink", file) |
| 5971 | } |
| 5972 | return |
| 5973 | } |
| 5974 | } |
| 5975 | t.Errorf("%q is not found", file) |
| 5976 | } |
| 5977 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5978 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 5979 | // is updatable or not |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5980 | ctx, _ := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5981 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5982 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5983 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5984 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 5985 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5986 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 5987 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5988 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5989 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 5990 | |
| 5991 | // 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] | 5992 | ctx, _ = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5993 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5994 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5995 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5996 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5997 | |
| 5998 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 5999 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6000 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6001 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6002 | } |
| 6003 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6004 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
| 6005 | ctx, config := testApex(t, ` |
| 6006 | apex { |
| 6007 | name: "myapex", |
| 6008 | key: "myapex.key", |
| 6009 | native_shared_libs: ["mylib"], |
| 6010 | } |
| 6011 | |
| 6012 | apex_key { |
| 6013 | name: "myapex.key", |
| 6014 | public_key: "testkey.avbpubkey", |
| 6015 | private_key: "testkey.pem", |
| 6016 | } |
| 6017 | |
| 6018 | cc_library_shared { |
| 6019 | name: "mylib", |
| 6020 | srcs: ["mylib.cpp"], |
| 6021 | shared_libs: ["myotherlib"], |
| 6022 | system_shared_libs: [], |
| 6023 | stl: "none", |
| 6024 | apex_available: [ |
| 6025 | "myapex", |
| 6026 | "//apex_available:platform", |
| 6027 | ], |
| 6028 | } |
| 6029 | |
| 6030 | cc_prebuilt_library_shared { |
| 6031 | name: "myotherlib", |
| 6032 | srcs: ["prebuilt.so"], |
| 6033 | system_shared_libs: [], |
| 6034 | stl: "none", |
| 6035 | apex_available: [ |
| 6036 | "myapex", |
| 6037 | "//apex_available:platform", |
| 6038 | ], |
| 6039 | } |
| 6040 | `) |
| 6041 | |
| 6042 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 6043 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 6044 | var builder strings.Builder |
| 6045 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 6046 | androidMk := builder.String() |
| 6047 | // `myotherlib` is added to `myapex` as symlink |
| 6048 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 6049 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 6050 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 6051 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 6052 | 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] | 6053 | } |
| 6054 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6055 | func TestApexWithJniLibs(t *testing.T) { |
| 6056 | ctx, _ := testApex(t, ` |
| 6057 | apex { |
| 6058 | name: "myapex", |
| 6059 | key: "myapex.key", |
| 6060 | jni_libs: ["mylib"], |
| 6061 | } |
| 6062 | |
| 6063 | apex_key { |
| 6064 | name: "myapex.key", |
| 6065 | public_key: "testkey.avbpubkey", |
| 6066 | private_key: "testkey.pem", |
| 6067 | } |
| 6068 | |
| 6069 | cc_library { |
| 6070 | name: "mylib", |
| 6071 | srcs: ["mylib.cpp"], |
| 6072 | shared_libs: ["mylib2"], |
| 6073 | system_shared_libs: [], |
| 6074 | stl: "none", |
| 6075 | apex_available: [ "myapex" ], |
| 6076 | } |
| 6077 | |
| 6078 | cc_library { |
| 6079 | name: "mylib2", |
| 6080 | srcs: ["mylib.cpp"], |
| 6081 | system_shared_libs: [], |
| 6082 | stl: "none", |
| 6083 | apex_available: [ "myapex" ], |
| 6084 | } |
| 6085 | `) |
| 6086 | |
| 6087 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 6088 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 6089 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 6090 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6091 | "lib64/mylib.so", |
| 6092 | "lib64/mylib2.so", |
| 6093 | }) |
| 6094 | } |
| 6095 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6096 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
| 6097 | ctx, _ := testApex(t, ` |
| 6098 | apex { |
| 6099 | name: "myapex", |
| 6100 | key: "myapex.key", |
| 6101 | } |
| 6102 | apex_key { |
| 6103 | name: "myapex.key", |
| 6104 | public_key: "testkey.avbpubkey", |
| 6105 | private_key: "testkey.pem", |
| 6106 | } |
| 6107 | `, func(fs map[string][]byte, config android.Config) { |
| 6108 | delete(config.Targets, android.Android) |
| 6109 | config.AndroidCommonTarget = android.Target{} |
| 6110 | }) |
| 6111 | |
| 6112 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 6113 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 6114 | } |
| 6115 | } |
| 6116 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6117 | func TestAppBundle(t *testing.T) { |
| 6118 | ctx, _ := testApex(t, ` |
| 6119 | apex { |
| 6120 | name: "myapex", |
| 6121 | key: "myapex.key", |
| 6122 | apps: ["AppFoo"], |
| 6123 | } |
| 6124 | |
| 6125 | apex_key { |
| 6126 | name: "myapex.key", |
| 6127 | public_key: "testkey.avbpubkey", |
| 6128 | private_key: "testkey.pem", |
| 6129 | } |
| 6130 | |
| 6131 | android_app { |
| 6132 | name: "AppFoo", |
| 6133 | srcs: ["foo/bar/MyClass.java"], |
| 6134 | sdk_version: "none", |
| 6135 | system_modules: "none", |
| 6136 | apex_available: [ "myapex" ], |
| 6137 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6138 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6139 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6140 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json") |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6141 | content := bundleConfigRule.Args["content"] |
| 6142 | |
| 6143 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6144 | 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] | 6145 | } |
| 6146 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6147 | func TestAppSetBundle(t *testing.T) { |
| 6148 | ctx, _ := testApex(t, ` |
| 6149 | apex { |
| 6150 | name: "myapex", |
| 6151 | key: "myapex.key", |
| 6152 | apps: ["AppSet"], |
| 6153 | } |
| 6154 | |
| 6155 | apex_key { |
| 6156 | name: "myapex.key", |
| 6157 | public_key: "testkey.avbpubkey", |
| 6158 | private_key: "testkey.pem", |
| 6159 | } |
| 6160 | |
| 6161 | android_app_set { |
| 6162 | name: "AppSet", |
| 6163 | set: "AppSet.apks", |
| 6164 | }`) |
| 6165 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6166 | bundleConfigRule := mod.Output("bundle_config.json") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6167 | content := bundleConfigRule.Args["content"] |
| 6168 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 6169 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 6170 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 6171 | if len(copyCmds) != 3 { |
| 6172 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 6173 | } |
| 6174 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 6175 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 6176 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 6177 | } |
| 6178 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6179 | func TestAppSetBundlePrebuilt(t *testing.T) { |
| 6180 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 6181 | bp := ` |
| 6182 | apex_set { |
| 6183 | name: "myapex", |
| 6184 | filename: "foo_v2.apex", |
| 6185 | sanitized: { |
| 6186 | none: { set: "myapex.apks", }, |
| 6187 | hwaddress: { set: "myapex.hwasan.apks", }, |
| 6188 | }, |
| 6189 | }` |
| 6190 | fs["Android.bp"] = []byte(bp) |
| 6191 | |
| 6192 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 6193 | }) |
| 6194 | |
| 6195 | m := ctx.ModuleForTests("myapex", "android_common") |
| 6196 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 6197 | |
| 6198 | actual := extractedApex.Inputs |
| 6199 | if len(actual) != 1 { |
| 6200 | t.Errorf("expected a single input") |
| 6201 | } |
| 6202 | |
| 6203 | expected := "myapex.hwasan.apks" |
| 6204 | if actual[0].String() != expected { |
| 6205 | t.Errorf("expected %s, got %s", expected, actual[0].String()) |
| 6206 | } |
| 6207 | } |
| 6208 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6209 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6210 | t.Helper() |
| 6211 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6212 | bp := ` |
| 6213 | java_library { |
| 6214 | name: "some-updatable-apex-lib", |
| 6215 | srcs: ["a.java"], |
| 6216 | sdk_version: "current", |
| 6217 | apex_available: [ |
| 6218 | "some-updatable-apex", |
| 6219 | ], |
| 6220 | } |
| 6221 | |
| 6222 | java_library { |
| 6223 | name: "some-non-updatable-apex-lib", |
| 6224 | srcs: ["a.java"], |
| 6225 | apex_available: [ |
| 6226 | "some-non-updatable-apex", |
| 6227 | ], |
| 6228 | } |
| 6229 | |
| 6230 | java_library { |
| 6231 | name: "some-platform-lib", |
| 6232 | srcs: ["a.java"], |
| 6233 | sdk_version: "current", |
| 6234 | installable: true, |
| 6235 | } |
| 6236 | |
| 6237 | java_library { |
| 6238 | name: "some-art-lib", |
| 6239 | srcs: ["a.java"], |
| 6240 | sdk_version: "current", |
| 6241 | apex_available: [ |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6242 | "com.android.art.debug", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6243 | ], |
| 6244 | hostdex: true, |
| 6245 | } |
| 6246 | |
| 6247 | apex { |
| 6248 | name: "some-updatable-apex", |
| 6249 | key: "some-updatable-apex.key", |
| 6250 | java_libs: ["some-updatable-apex-lib"], |
| 6251 | updatable: true, |
| 6252 | min_sdk_version: "current", |
| 6253 | } |
| 6254 | |
| 6255 | apex { |
| 6256 | name: "some-non-updatable-apex", |
| 6257 | key: "some-non-updatable-apex.key", |
| 6258 | java_libs: ["some-non-updatable-apex-lib"], |
| 6259 | } |
| 6260 | |
| 6261 | apex_key { |
| 6262 | name: "some-updatable-apex.key", |
| 6263 | } |
| 6264 | |
| 6265 | apex_key { |
| 6266 | name: "some-non-updatable-apex.key", |
| 6267 | } |
| 6268 | |
| 6269 | apex { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6270 | name: "com.android.art.debug", |
| 6271 | key: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6272 | java_libs: ["some-art-lib"], |
| 6273 | updatable: true, |
| 6274 | min_sdk_version: "current", |
| 6275 | } |
| 6276 | |
| 6277 | apex_key { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6278 | name: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6279 | } |
| 6280 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6281 | filegroup { |
| 6282 | name: "some-updatable-apex-file_contexts", |
| 6283 | srcs: [ |
| 6284 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 6285 | ], |
| 6286 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6287 | |
| 6288 | filegroup { |
| 6289 | name: "some-non-updatable-apex-file_contexts", |
| 6290 | srcs: [ |
| 6291 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 6292 | ], |
| 6293 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6294 | ` |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 6295 | |
| 6296 | testDexpreoptWithApexes(t, bp, errmsg, transformDexpreoptConfig) |
| 6297 | } |
| 6298 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6299 | 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] | 6300 | t.Helper() |
| 6301 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6302 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 6303 | bp += java.GatherRequiredDepsForTest() |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6304 | |
| 6305 | fs := map[string][]byte{ |
| 6306 | "a.java": nil, |
| 6307 | "a.jar": nil, |
| 6308 | "build/make/target/product/security": nil, |
| 6309 | "apex_manifest.json": nil, |
| 6310 | "AndroidManifest.xml": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 6311 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6312 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
| 6313 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
| 6314 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 6315 | "framework/aidl/a.aidl": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6316 | } |
| 6317 | cc.GatherRequiredFilesForTest(fs) |
| 6318 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6319 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 6320 | |
| 6321 | ctx := android.NewTestArchContext(config) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6322 | ctx.RegisterModuleType("apex", BundleFactory) |
| 6323 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6324 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6325 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 6326 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 6327 | android.RegisterPrebuiltMutators(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6328 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 6329 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6330 | java.RegisterHiddenApiSingletonComponents(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6331 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 6332 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 6333 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 6334 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6335 | ctx.Register() |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6336 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6337 | pathCtx := android.PathContextForTesting(config) |
| 6338 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 6339 | transformDexpreoptConfig(dexpreoptConfig) |
| 6340 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 6341 | |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6342 | // Make sure that any changes to these dexpreopt properties are mirrored in the corresponding |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame^] | 6343 | // product variables. |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6344 | config.TestProductVariables.BootJars = dexpreoptConfig.BootJars |
| 6345 | config.TestProductVariables.UpdatableBootJars = dexpreoptConfig.UpdatableBootJars |
| 6346 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6347 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 6348 | android.FailIfErrored(t, errs) |
| 6349 | |
| 6350 | _, errs = ctx.PrepareBuildActions(config) |
| 6351 | if errmsg == "" { |
| 6352 | android.FailIfErrored(t, errs) |
| 6353 | } else if len(errs) > 0 { |
| 6354 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6355 | } else { |
| 6356 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 6357 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6358 | |
| 6359 | return ctx |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6360 | } |
| 6361 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6362 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 6363 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 6364 | apex { |
| 6365 | name: "myapex", |
| 6366 | key: "myapex.key", |
| 6367 | updatable: true, |
| 6368 | } |
| 6369 | |
| 6370 | apex_key { |
| 6371 | name: "myapex.key", |
| 6372 | public_key: "testkey.avbpubkey", |
| 6373 | private_key: "testkey.pem", |
| 6374 | } |
| 6375 | `) |
| 6376 | } |
| 6377 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6378 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6379 | var err string |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6380 | var transform func(*dexpreopt.GlobalConfig) |
| 6381 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6382 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
| 6383 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6384 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6385 | } |
| 6386 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6387 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6388 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6389 | t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6390 | err = `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6391 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6392 | config.BootJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6393 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6394 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6395 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6396 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6397 | 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] | 6398 | 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] | 6399 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6400 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6401 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6402 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6403 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6404 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6405 | 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] | 6406 | 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] | 6407 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6408 | 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] | 6409 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6410 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6411 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6412 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6413 | 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] | 6414 | 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] | 6415 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6416 | config.BootJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6417 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6418 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6419 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6420 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6421 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
| 6422 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6423 | 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] | 6424 | } |
| 6425 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6426 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6427 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6428 | 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] | 6429 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6430 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6431 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6432 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6433 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6434 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6435 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6436 | 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] | 6437 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6438 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6439 | config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6440 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6441 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6442 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6443 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6444 | 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] | 6445 | 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] | 6446 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6447 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6448 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6449 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6450 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6451 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6452 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
| 6453 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6454 | config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6455 | } |
| 6456 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6457 | }) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6458 | |
| 6459 | } |
| 6460 | |
| 6461 | func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { |
| 6462 | transform := func(config *dexpreopt.GlobalConfig) { |
| 6463 | config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo"}) |
| 6464 | } |
| 6465 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6466 | testDexpreoptWithApexes(t, ` |
| 6467 | prebuilt_apex { |
| 6468 | name: "myapex" , |
| 6469 | arch: { |
| 6470 | arm64: { |
| 6471 | src: "myapex-arm64.apex", |
| 6472 | }, |
| 6473 | arm: { |
| 6474 | src: "myapex-arm.apex", |
| 6475 | }, |
| 6476 | }, |
| 6477 | exported_java_libs: ["libfoo"], |
| 6478 | } |
| 6479 | |
| 6480 | java_import { |
| 6481 | name: "libfoo", |
| 6482 | jars: ["libfoo.jar"], |
| 6483 | } |
| 6484 | `, "", transform) |
| 6485 | }) |
| 6486 | |
| 6487 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6488 | testDexpreoptWithApexes(t, ` |
| 6489 | prebuilt_apex { |
| 6490 | name: "myapex" , |
| 6491 | arch: { |
| 6492 | arm64: { |
| 6493 | src: "myapex-arm64.apex", |
| 6494 | }, |
| 6495 | arm: { |
| 6496 | src: "myapex-arm.apex", |
| 6497 | }, |
| 6498 | }, |
| 6499 | exported_java_libs: ["libfoo"], |
| 6500 | } |
| 6501 | |
| 6502 | java_import { |
| 6503 | name: "libfoo", |
| 6504 | jars: ["libfoo.jar"], |
| 6505 | } |
| 6506 | `, "", transform) |
| 6507 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6508 | } |
| 6509 | |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6510 | func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) { |
| 6511 | t.Helper() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6512 | bp += ` |
| 6513 | apex_key { |
| 6514 | name: "myapex.key", |
| 6515 | public_key: "testkey.avbpubkey", |
| 6516 | private_key: "testkey.pem", |
| 6517 | }` |
| 6518 | fs := map[string][]byte{ |
| 6519 | "lib1/src/A.java": nil, |
| 6520 | "lib2/src/B.java": nil, |
| 6521 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 6522 | } |
| 6523 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6524 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 6525 | android.SetTestNeverallowRules(config, rules) |
| 6526 | updatableBootJars := make([]string, 0, len(apexBootJars)) |
| 6527 | for _, apexBootJar := range apexBootJars { |
| 6528 | updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar) |
| 6529 | } |
| 6530 | config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars) |
| 6531 | |
| 6532 | ctx := android.NewTestArchContext(config) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6533 | ctx.RegisterModuleType("apex", BundleFactory) |
| 6534 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 6535 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 6536 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 6537 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6538 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 6539 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 6540 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 6541 | ctx.PostDepsMutators(android.RegisterNeverallowMutator) |
| 6542 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6543 | ctx.Register() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6544 | |
| 6545 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 6546 | android.FailIfErrored(t, errs) |
| 6547 | |
| 6548 | _, errs = ctx.PrepareBuildActions(config) |
| 6549 | if errmsg == "" { |
| 6550 | android.FailIfErrored(t, errs) |
| 6551 | } else if len(errs) > 0 { |
| 6552 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 6553 | return |
| 6554 | } else { |
| 6555 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 6556 | } |
| 6557 | } |
| 6558 | |
| 6559 | func TestApexPermittedPackagesRules(t *testing.T) { |
| 6560 | testcases := []struct { |
| 6561 | name string |
| 6562 | expectedError string |
| 6563 | bp string |
| 6564 | bootJars []string |
| 6565 | modulesPackages map[string][]string |
| 6566 | }{ |
| 6567 | |
| 6568 | { |
| 6569 | name: "Non-Bootclasspath apex jar not satisfying allowed module packages.", |
| 6570 | expectedError: "", |
| 6571 | bp: ` |
| 6572 | java_library { |
| 6573 | name: "bcp_lib1", |
| 6574 | srcs: ["lib1/src/*.java"], |
| 6575 | permitted_packages: ["foo.bar"], |
| 6576 | apex_available: ["myapex"], |
| 6577 | sdk_version: "none", |
| 6578 | system_modules: "none", |
| 6579 | } |
| 6580 | java_library { |
| 6581 | name: "nonbcp_lib2", |
| 6582 | srcs: ["lib2/src/*.java"], |
| 6583 | apex_available: ["myapex"], |
| 6584 | permitted_packages: ["a.b"], |
| 6585 | sdk_version: "none", |
| 6586 | system_modules: "none", |
| 6587 | } |
| 6588 | apex { |
| 6589 | name: "myapex", |
| 6590 | key: "myapex.key", |
| 6591 | java_libs: ["bcp_lib1", "nonbcp_lib2"], |
| 6592 | }`, |
| 6593 | bootJars: []string{"bcp_lib1"}, |
| 6594 | modulesPackages: map[string][]string{ |
| 6595 | "myapex": []string{ |
| 6596 | "foo.bar", |
| 6597 | }, |
| 6598 | }, |
| 6599 | }, |
| 6600 | { |
| 6601 | name: "Bootclasspath apex jar not satisfying allowed module packages.", |
| 6602 | 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.`, |
| 6603 | bp: ` |
| 6604 | java_library { |
| 6605 | name: "bcp_lib1", |
| 6606 | srcs: ["lib1/src/*.java"], |
| 6607 | apex_available: ["myapex"], |
| 6608 | permitted_packages: ["foo.bar"], |
| 6609 | sdk_version: "none", |
| 6610 | system_modules: "none", |
| 6611 | } |
| 6612 | java_library { |
| 6613 | name: "bcp_lib2", |
| 6614 | srcs: ["lib2/src/*.java"], |
| 6615 | apex_available: ["myapex"], |
| 6616 | permitted_packages: ["foo.bar", "bar.baz"], |
| 6617 | sdk_version: "none", |
| 6618 | system_modules: "none", |
| 6619 | } |
| 6620 | apex { |
| 6621 | name: "myapex", |
| 6622 | key: "myapex.key", |
| 6623 | java_libs: ["bcp_lib1", "bcp_lib2"], |
| 6624 | } |
| 6625 | `, |
| 6626 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
| 6627 | modulesPackages: map[string][]string{ |
| 6628 | "myapex": []string{ |
| 6629 | "foo.bar", |
| 6630 | }, |
| 6631 | }, |
| 6632 | }, |
| 6633 | } |
| 6634 | for _, tc := range testcases { |
| 6635 | t.Run(tc.name, func(t *testing.T) { |
| 6636 | rules := createApexPermittedPackagesRules(tc.modulesPackages) |
| 6637 | testApexPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules) |
| 6638 | }) |
| 6639 | } |
| 6640 | } |
| 6641 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6642 | func TestTestFor(t *testing.T) { |
| 6643 | ctx, _ := testApex(t, ` |
| 6644 | apex { |
| 6645 | name: "myapex", |
| 6646 | key: "myapex.key", |
| 6647 | native_shared_libs: ["mylib", "myprivlib"], |
| 6648 | } |
| 6649 | |
| 6650 | apex_key { |
| 6651 | name: "myapex.key", |
| 6652 | public_key: "testkey.avbpubkey", |
| 6653 | private_key: "testkey.pem", |
| 6654 | } |
| 6655 | |
| 6656 | cc_library { |
| 6657 | name: "mylib", |
| 6658 | srcs: ["mylib.cpp"], |
| 6659 | system_shared_libs: [], |
| 6660 | stl: "none", |
| 6661 | stubs: { |
| 6662 | versions: ["1"], |
| 6663 | }, |
| 6664 | apex_available: ["myapex"], |
| 6665 | } |
| 6666 | |
| 6667 | cc_library { |
| 6668 | name: "myprivlib", |
| 6669 | srcs: ["mylib.cpp"], |
| 6670 | system_shared_libs: [], |
| 6671 | stl: "none", |
| 6672 | apex_available: ["myapex"], |
| 6673 | } |
| 6674 | |
| 6675 | |
| 6676 | cc_test { |
| 6677 | name: "mytest", |
| 6678 | gtest: false, |
| 6679 | srcs: ["mylib.cpp"], |
| 6680 | system_shared_libs: [], |
| 6681 | stl: "none", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6682 | shared_libs: ["mylib", "myprivlib", "mytestlib"], |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6683 | test_for: ["myapex"] |
| 6684 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6685 | |
| 6686 | cc_library { |
| 6687 | name: "mytestlib", |
| 6688 | srcs: ["mylib.cpp"], |
| 6689 | system_shared_libs: [], |
| 6690 | shared_libs: ["mylib", "myprivlib"], |
| 6691 | stl: "none", |
| 6692 | test_for: ["myapex"], |
| 6693 | } |
| 6694 | |
| 6695 | cc_benchmark { |
| 6696 | name: "mybench", |
| 6697 | srcs: ["mylib.cpp"], |
| 6698 | system_shared_libs: [], |
| 6699 | shared_libs: ["mylib", "myprivlib"], |
| 6700 | stl: "none", |
| 6701 | test_for: ["myapex"], |
| 6702 | } |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6703 | `) |
| 6704 | |
| 6705 | // the test 'mytest' is a test for the apex, therefore is linked to the |
| 6706 | // actual implementation of mylib instead of its stub. |
| 6707 | ldFlags := ctx.ModuleForTests("mytest", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 6708 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6709 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6710 | |
| 6711 | // The same should be true for cc_library |
| 6712 | ldFlags = ctx.ModuleForTests("mytestlib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 6713 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6714 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
| 6715 | |
| 6716 | // ... and for cc_benchmark |
| 6717 | ldFlags = ctx.ModuleForTests("mybench", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 6718 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6719 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6720 | } |
| 6721 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6722 | // TODO(jungjw): Move this to proptools |
| 6723 | func intPtr(i int) *int { |
| 6724 | return &i |
| 6725 | } |
| 6726 | |
| 6727 | func TestApexSet(t *testing.T) { |
| 6728 | ctx, config := testApex(t, ` |
| 6729 | apex_set { |
| 6730 | name: "myapex", |
| 6731 | set: "myapex.apks", |
| 6732 | filename: "foo_v2.apex", |
| 6733 | overrides: ["foo"], |
| 6734 | } |
| 6735 | `, func(fs map[string][]byte, config android.Config) { |
| 6736 | config.TestProductVariables.Platform_sdk_version = intPtr(30) |
Jaewoong Jung | 829b713 | 2020-06-10 12:23:32 -0700 | [diff] [blame] | 6737 | config.Targets[android.Android] = []android.Target{ |
| 6738 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}}, |
| 6739 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}}, |
| 6740 | } |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6741 | }) |
| 6742 | |
| 6743 | m := ctx.ModuleForTests("myapex", "android_common") |
| 6744 | |
| 6745 | // Check extract_apks tool parameters. |
| 6746 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 6747 | actual := extractedApex.Args["abis"] |
| 6748 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 6749 | if actual != expected { |
| 6750 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6751 | } |
| 6752 | actual = extractedApex.Args["sdk-version"] |
| 6753 | expected = "30" |
| 6754 | if actual != expected { |
| 6755 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6756 | } |
| 6757 | |
| 6758 | a := m.Module().(*ApexSet) |
| 6759 | expectedOverrides := []string{"foo"} |
| 6760 | actualOverrides := android.AndroidMkEntriesForTest(t, config, "", a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
| 6761 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 6762 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 6763 | } |
| 6764 | } |
| 6765 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 6766 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 6767 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 6768 | apex { |
| 6769 | name: "myapex", |
| 6770 | key: "myapex.key", |
| 6771 | native_shared_libs: ["mylib"], |
| 6772 | } |
| 6773 | |
| 6774 | apex_key { |
| 6775 | name: "myapex.key", |
| 6776 | public_key: "testkey.avbpubkey", |
| 6777 | private_key: "testkey.pem", |
| 6778 | } |
| 6779 | |
| 6780 | cc_library { |
| 6781 | name: "mylib", |
| 6782 | srcs: ["mylib.cpp"], |
| 6783 | static_libs: ["otherlib"], |
| 6784 | system_shared_libs: [], |
| 6785 | stl: "none", |
| 6786 | apex_available: [ "myapex" ], |
| 6787 | } |
| 6788 | |
| 6789 | cc_library { |
| 6790 | name: "otherlib", |
| 6791 | srcs: ["mylib.cpp"], |
| 6792 | system_shared_libs: [], |
| 6793 | stl: "none", |
| 6794 | stubs: { |
| 6795 | versions: ["1", "2", "3"], |
| 6796 | }, |
| 6797 | apex_available: [ "myapex" ], |
| 6798 | } |
| 6799 | `) |
| 6800 | } |
| 6801 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 6802 | func TestApexKeysTxt(t *testing.T) { |
| 6803 | ctx, _ := testApex(t, ` |
| 6804 | apex { |
| 6805 | name: "myapex", |
| 6806 | key: "myapex.key", |
| 6807 | } |
| 6808 | |
| 6809 | apex_key { |
| 6810 | name: "myapex.key", |
| 6811 | public_key: "testkey.avbpubkey", |
| 6812 | private_key: "testkey.pem", |
| 6813 | } |
| 6814 | |
| 6815 | prebuilt_apex { |
| 6816 | name: "myapex", |
| 6817 | prefer: true, |
| 6818 | arch: { |
| 6819 | arm64: { |
| 6820 | src: "myapex-arm64.apex", |
| 6821 | }, |
| 6822 | arm: { |
| 6823 | src: "myapex-arm.apex", |
| 6824 | }, |
| 6825 | }, |
| 6826 | } |
| 6827 | |
| 6828 | apex_set { |
| 6829 | name: "myapex_set", |
| 6830 | set: "myapex.apks", |
| 6831 | filename: "myapex_set.apex", |
| 6832 | overrides: ["myapex"], |
| 6833 | } |
| 6834 | `) |
| 6835 | |
| 6836 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 6837 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 6838 | 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] | 6839 | 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] | 6840 | } |
| 6841 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 6842 | func TestAllowedFiles(t *testing.T) { |
| 6843 | ctx, _ := testApex(t, ` |
| 6844 | apex { |
| 6845 | name: "myapex", |
| 6846 | key: "myapex.key", |
| 6847 | apps: ["app"], |
| 6848 | allowed_files: "allowed.txt", |
| 6849 | } |
| 6850 | |
| 6851 | apex_key { |
| 6852 | name: "myapex.key", |
| 6853 | public_key: "testkey.avbpubkey", |
| 6854 | private_key: "testkey.pem", |
| 6855 | } |
| 6856 | |
| 6857 | android_app { |
| 6858 | name: "app", |
| 6859 | srcs: ["foo/bar/MyClass.java"], |
| 6860 | package_name: "foo", |
| 6861 | sdk_version: "none", |
| 6862 | system_modules: "none", |
| 6863 | apex_available: [ "myapex" ], |
| 6864 | } |
| 6865 | `, withFiles(map[string][]byte{ |
| 6866 | "sub/Android.bp": []byte(` |
| 6867 | override_apex { |
| 6868 | name: "override_myapex", |
| 6869 | base: "myapex", |
| 6870 | apps: ["override_app"], |
| 6871 | allowed_files: ":allowed", |
| 6872 | } |
| 6873 | // Overridable "path" property should be referenced indirectly |
| 6874 | filegroup { |
| 6875 | name: "allowed", |
| 6876 | srcs: ["allowed.txt"], |
| 6877 | } |
| 6878 | override_android_app { |
| 6879 | name: "override_app", |
| 6880 | base: "app", |
| 6881 | package_name: "bar", |
| 6882 | } |
| 6883 | `), |
| 6884 | })) |
| 6885 | |
| 6886 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 6887 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 6888 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 6889 | } |
| 6890 | |
| 6891 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 6892 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 6893 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 6894 | } |
| 6895 | } |
| 6896 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6897 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
| 6898 | _, _ = testApex(t, ` |
| 6899 | apex { |
| 6900 | name: "myapex", |
| 6901 | key: "myapex.key", |
| 6902 | native_shared_libs: ["mylib"], |
| 6903 | } |
| 6904 | |
| 6905 | apex_key { |
| 6906 | name: "myapex.key", |
| 6907 | public_key: "testkey.avbpubkey", |
| 6908 | private_key: "testkey.pem", |
| 6909 | } |
| 6910 | |
| 6911 | cc_library { |
| 6912 | name: "mylib", |
| 6913 | srcs: ["mylib.cpp"], |
| 6914 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 6915 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6916 | }, |
| 6917 | apex_available: ["myapex"], |
| 6918 | } |
| 6919 | |
| 6920 | cc_prebuilt_library_shared { |
| 6921 | name: "mylib", |
| 6922 | prefer: false, |
| 6923 | srcs: ["prebuilt.so"], |
| 6924 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 6925 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6926 | }, |
| 6927 | apex_available: ["myapex"], |
| 6928 | } |
| 6929 | `) |
| 6930 | } |
| 6931 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 6932 | func TestCompressedApex(t *testing.T) { |
| 6933 | ctx, config := testApex(t, ` |
| 6934 | apex { |
| 6935 | name: "myapex", |
| 6936 | key: "myapex.key", |
| 6937 | compressible: true, |
| 6938 | } |
| 6939 | apex_key { |
| 6940 | name: "myapex.key", |
| 6941 | public_key: "testkey.avbpubkey", |
| 6942 | private_key: "testkey.pem", |
| 6943 | } |
| 6944 | `, func(fs map[string][]byte, config android.Config) { |
| 6945 | config.TestProductVariables.CompressedApex = proptools.BoolPtr(true) |
| 6946 | }) |
| 6947 | |
| 6948 | compressRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("compressRule") |
| 6949 | ensureContains(t, compressRule.Output.String(), "myapex.capex.unsigned") |
| 6950 | |
| 6951 | signApkRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("sign compressedApex") |
| 6952 | ensureEquals(t, signApkRule.Input.String(), compressRule.Output.String()) |
| 6953 | |
| 6954 | // Make sure output of bundle is .capex |
| 6955 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 6956 | ensureContains(t, ab.outputFile.String(), "myapex.capex") |
| 6957 | |
| 6958 | // Verify android.mk rules |
| 6959 | data := android.AndroidMkDataForTest(t, config, "", ab) |
| 6960 | var builder strings.Builder |
| 6961 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 6962 | androidMk := builder.String() |
| 6963 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.capex\n") |
| 6964 | } |
| 6965 | |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 6966 | func TestPreferredPrebuiltSharedLibDep(t *testing.T) { |
| 6967 | ctx, config := testApex(t, ` |
| 6968 | apex { |
| 6969 | name: "myapex", |
| 6970 | key: "myapex.key", |
| 6971 | native_shared_libs: ["mylib"], |
| 6972 | } |
| 6973 | |
| 6974 | apex_key { |
| 6975 | name: "myapex.key", |
| 6976 | public_key: "testkey.avbpubkey", |
| 6977 | private_key: "testkey.pem", |
| 6978 | } |
| 6979 | |
| 6980 | cc_library { |
| 6981 | name: "mylib", |
| 6982 | srcs: ["mylib.cpp"], |
| 6983 | apex_available: ["myapex"], |
| 6984 | shared_libs: ["otherlib"], |
| 6985 | system_shared_libs: [], |
| 6986 | } |
| 6987 | |
| 6988 | cc_library { |
| 6989 | name: "otherlib", |
| 6990 | srcs: ["mylib.cpp"], |
| 6991 | stubs: { |
| 6992 | versions: ["current"], |
| 6993 | }, |
| 6994 | } |
| 6995 | |
| 6996 | cc_prebuilt_library_shared { |
| 6997 | name: "otherlib", |
| 6998 | prefer: true, |
| 6999 | srcs: ["prebuilt.so"], |
| 7000 | stubs: { |
| 7001 | versions: ["current"], |
| 7002 | }, |
| 7003 | } |
| 7004 | `) |
| 7005 | |
| 7006 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 7007 | data := android.AndroidMkDataForTest(t, config, "", ab) |
| 7008 | var builder strings.Builder |
| 7009 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7010 | androidMk := builder.String() |
| 7011 | |
| 7012 | // The make level dependency needs to be on otherlib - prebuilt_otherlib isn't |
| 7013 | // a thing there. |
| 7014 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherlib\n") |
| 7015 | } |
| 7016 | |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7017 | func TestExcludeDependency(t *testing.T) { |
| 7018 | ctx, _ := testApex(t, ` |
| 7019 | apex { |
| 7020 | name: "myapex", |
| 7021 | key: "myapex.key", |
| 7022 | native_shared_libs: ["mylib"], |
| 7023 | } |
| 7024 | |
| 7025 | apex_key { |
| 7026 | name: "myapex.key", |
| 7027 | public_key: "testkey.avbpubkey", |
| 7028 | private_key: "testkey.pem", |
| 7029 | } |
| 7030 | |
| 7031 | cc_library { |
| 7032 | name: "mylib", |
| 7033 | srcs: ["mylib.cpp"], |
| 7034 | system_shared_libs: [], |
| 7035 | stl: "none", |
| 7036 | apex_available: ["myapex"], |
| 7037 | shared_libs: ["mylib2"], |
| 7038 | target: { |
| 7039 | apex: { |
| 7040 | exclude_shared_libs: ["mylib2"], |
| 7041 | }, |
| 7042 | }, |
| 7043 | } |
| 7044 | |
| 7045 | cc_library { |
| 7046 | name: "mylib2", |
| 7047 | srcs: ["mylib.cpp"], |
| 7048 | system_shared_libs: [], |
| 7049 | stl: "none", |
| 7050 | } |
| 7051 | `) |
| 7052 | |
| 7053 | // Check if mylib is linked to mylib2 for the non-apex target |
| 7054 | ldFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 7055 | ensureContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 7056 | |
| 7057 | // Make sure that the link doesn't occur for the apex target |
| 7058 | ldFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 7059 | ensureNotContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared_apex10000/mylib2.so") |
| 7060 | |
| 7061 | // It shouldn't appear in the copy cmd as well. |
| 7062 | copyCmds := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").Args["copy_commands"] |
| 7063 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 7064 | } |
| 7065 | |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7066 | func TestPrebuiltStubLibDep(t *testing.T) { |
| 7067 | bpBase := ` |
| 7068 | apex { |
| 7069 | name: "myapex", |
| 7070 | key: "myapex.key", |
| 7071 | native_shared_libs: ["mylib"], |
| 7072 | } |
| 7073 | apex_key { |
| 7074 | name: "myapex.key", |
| 7075 | public_key: "testkey.avbpubkey", |
| 7076 | private_key: "testkey.pem", |
| 7077 | } |
| 7078 | cc_library { |
| 7079 | name: "mylib", |
| 7080 | srcs: ["mylib.cpp"], |
| 7081 | apex_available: ["myapex"], |
| 7082 | shared_libs: ["stublib"], |
| 7083 | system_shared_libs: [], |
| 7084 | } |
| 7085 | apex { |
| 7086 | name: "otherapex", |
| 7087 | enabled: %s, |
| 7088 | key: "myapex.key", |
| 7089 | native_shared_libs: ["stublib"], |
| 7090 | } |
| 7091 | ` |
| 7092 | |
| 7093 | stublibSourceBp := ` |
| 7094 | cc_library { |
| 7095 | name: "stublib", |
| 7096 | srcs: ["mylib.cpp"], |
| 7097 | apex_available: ["otherapex"], |
| 7098 | system_shared_libs: [], |
| 7099 | stl: "none", |
| 7100 | stubs: { |
| 7101 | versions: ["1"], |
| 7102 | }, |
| 7103 | } |
| 7104 | ` |
| 7105 | |
| 7106 | stublibPrebuiltBp := ` |
| 7107 | cc_prebuilt_library_shared { |
| 7108 | name: "stublib", |
| 7109 | srcs: ["prebuilt.so"], |
| 7110 | apex_available: ["otherapex"], |
| 7111 | stubs: { |
| 7112 | versions: ["1"], |
| 7113 | }, |
| 7114 | %s |
| 7115 | } |
| 7116 | ` |
| 7117 | |
| 7118 | tests := []struct { |
| 7119 | name string |
| 7120 | stublibBp string |
| 7121 | usePrebuilt bool |
| 7122 | modNames []string // Modules to collect AndroidMkEntries for |
| 7123 | otherApexEnabled []string |
| 7124 | }{ |
| 7125 | { |
| 7126 | name: "only_source", |
| 7127 | stublibBp: stublibSourceBp, |
| 7128 | usePrebuilt: false, |
| 7129 | modNames: []string{"stublib"}, |
| 7130 | otherApexEnabled: []string{"true", "false"}, |
| 7131 | }, |
| 7132 | { |
| 7133 | name: "source_preferred", |
| 7134 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, ""), |
| 7135 | usePrebuilt: false, |
| 7136 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 7137 | otherApexEnabled: []string{"true", "false"}, |
| 7138 | }, |
| 7139 | { |
| 7140 | name: "prebuilt_preferred", |
| 7141 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, "prefer: true,"), |
| 7142 | usePrebuilt: true, |
| 7143 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 7144 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 7145 | }, |
| 7146 | { |
| 7147 | name: "only_prebuilt", |
| 7148 | stublibBp: fmt.Sprintf(stublibPrebuiltBp, ""), |
| 7149 | usePrebuilt: true, |
| 7150 | modNames: []string{"stublib"}, |
| 7151 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 7152 | }, |
| 7153 | } |
| 7154 | |
| 7155 | for _, test := range tests { |
| 7156 | t.Run(test.name, func(t *testing.T) { |
| 7157 | for _, otherApexEnabled := range test.otherApexEnabled { |
| 7158 | t.Run("otherapex_enabled_"+otherApexEnabled, func(t *testing.T) { |
| 7159 | ctx, config := testApex(t, fmt.Sprintf(bpBase, otherApexEnabled)+test.stublibBp) |
| 7160 | |
| 7161 | type modAndMkEntries struct { |
| 7162 | mod *cc.Module |
| 7163 | mkEntries android.AndroidMkEntries |
| 7164 | } |
| 7165 | entries := []*modAndMkEntries{} |
| 7166 | |
| 7167 | // Gather shared lib modules that are installable |
| 7168 | for _, modName := range test.modNames { |
| 7169 | for _, variant := range ctx.ModuleVariantsForTests(modName) { |
| 7170 | if !strings.HasPrefix(variant, "android_arm64_armv8-a_shared") { |
| 7171 | continue |
| 7172 | } |
| 7173 | mod := ctx.ModuleForTests(modName, variant).Module().(*cc.Module) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 7174 | if !mod.Enabled() || mod.IsHideFromMake() { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7175 | continue |
| 7176 | } |
| 7177 | for _, ent := range android.AndroidMkEntriesForTest(t, config, "", mod) { |
| 7178 | if ent.Disabled { |
| 7179 | continue |
| 7180 | } |
| 7181 | entries = append(entries, &modAndMkEntries{ |
| 7182 | mod: mod, |
| 7183 | mkEntries: ent, |
| 7184 | }) |
| 7185 | } |
| 7186 | } |
| 7187 | } |
| 7188 | |
| 7189 | var entry *modAndMkEntries = nil |
| 7190 | for _, ent := range entries { |
| 7191 | if strings.Join(ent.mkEntries.EntryMap["LOCAL_MODULE"], ",") == "stublib" { |
| 7192 | if entry != nil { |
| 7193 | t.Errorf("More than one AndroidMk entry for \"stublib\": %s and %s", entry.mod, ent.mod) |
| 7194 | } else { |
| 7195 | entry = ent |
| 7196 | } |
| 7197 | } |
| 7198 | } |
| 7199 | |
| 7200 | if entry == nil { |
| 7201 | t.Errorf("AndroidMk entry for \"stublib\" missing") |
| 7202 | } else { |
| 7203 | isPrebuilt := entry.mod.Prebuilt() != nil |
| 7204 | if isPrebuilt != test.usePrebuilt { |
| 7205 | t.Errorf("Wrong module for \"stublib\" AndroidMk entry: got prebuilt %t, want prebuilt %t", isPrebuilt, test.usePrebuilt) |
| 7206 | } |
| 7207 | if !entry.mod.IsStubs() { |
| 7208 | t.Errorf("Module for \"stublib\" AndroidMk entry isn't a stub: %s", entry.mod) |
| 7209 | } |
| 7210 | if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil { |
| 7211 | t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries) |
| 7212 | } |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 7213 | cflags := entry.mkEntries.EntryMap["LOCAL_EXPORT_CFLAGS"] |
| 7214 | expected := "-D__STUBLIB_API__=1" |
| 7215 | if !android.InList(expected, cflags) { |
| 7216 | t.Errorf("LOCAL_EXPORT_CFLAGS expected to have %q, but got %q", expected, cflags) |
| 7217 | } |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7218 | } |
| 7219 | }) |
| 7220 | } |
| 7221 | }) |
| 7222 | } |
| 7223 | } |
| 7224 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 7225 | func TestMain(m *testing.M) { |
| 7226 | run := func() int { |
| 7227 | setUp() |
| 7228 | defer tearDown() |
| 7229 | |
| 7230 | return m.Run() |
| 7231 | } |
| 7232 | |
| 7233 | os.Exit(run()) |
| 7234 | } |