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" |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 22 | "path/filepath" |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 23 | "reflect" |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 24 | "regexp" |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 25 | "sort" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 26 | "strings" |
| 27 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 28 | |
| 29 | "github.com/google/blueprint/proptools" |
| 30 | |
| 31 | "android/soong/android" |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 32 | "android/soong/bpf" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 33 | "android/soong/cc" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 34 | "android/soong/dexpreopt" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 35 | prebuilt_etc "android/soong/etc" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 36 | "android/soong/java" |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 37 | "android/soong/rust" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 38 | "android/soong/sh" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 39 | ) |
| 40 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 41 | var buildDir string |
| 42 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 43 | // names returns name list from white space separated string |
| 44 | func names(s string) (ns []string) { |
| 45 | for _, n := range strings.Split(s, " ") { |
| 46 | if len(n) > 0 { |
| 47 | ns = append(ns, n) |
| 48 | } |
| 49 | } |
| 50 | return |
| 51 | } |
| 52 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 53 | func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) { |
| 54 | t.Helper() |
| 55 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 56 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 57 | if len(errs) > 0 { |
| 58 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 59 | return |
| 60 | } |
| 61 | _, errs = ctx.PrepareBuildActions(config) |
| 62 | if len(errs) > 0 { |
| 63 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 68 | } |
| 69 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 70 | func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
| 71 | t.Helper() |
| 72 | ctx, config := testApexContext(t, bp, handlers...) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 73 | _, errs := ctx.ParseBlueprintsFiles(".") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 74 | android.FailIfErrored(t, errs) |
| 75 | _, errs = ctx.PrepareBuildActions(config) |
| 76 | android.FailIfErrored(t, errs) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 77 | return ctx, config |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 78 | } |
| 79 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 80 | type testCustomizer func(fs map[string][]byte, config android.Config) |
| 81 | |
| 82 | func withFiles(files map[string][]byte) testCustomizer { |
| 83 | return func(fs map[string][]byte, config android.Config) { |
| 84 | for k, v := range files { |
| 85 | fs[k] = v |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | func withTargets(targets map[android.OsType][]android.Target) testCustomizer { |
| 91 | return func(fs map[string][]byte, config android.Config) { |
| 92 | for k, v := range targets { |
| 93 | config.Targets[k] = v |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 98 | // withNativeBridgeTargets sets configuration with targets including: |
| 99 | // - X86_64 (primary) |
| 100 | // - X86 (secondary) |
| 101 | // - Arm64 on X86_64 (native bridge) |
| 102 | // - Arm on X86 (native bridge) |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 103 | func withNativeBridgeEnabled(_ map[string][]byte, config android.Config) { |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 104 | config.Targets[android.Android] = []android.Target{ |
| 105 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, |
| 106 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 107 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, |
| 108 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 109 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, |
| 110 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"}, |
| 111 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 112 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"}, |
| 113 | } |
| 114 | } |
| 115 | |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 116 | func withManifestPackageNameOverrides(specs []string) testCustomizer { |
| 117 | return func(fs map[string][]byte, config android.Config) { |
| 118 | config.TestProductVariables.ManifestPackageNameOverrides = specs |
| 119 | } |
| 120 | } |
| 121 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 122 | func withBinder32bit(_ map[string][]byte, config android.Config) { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 123 | config.TestProductVariables.Binder32bit = proptools.BoolPtr(true) |
| 124 | } |
| 125 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 126 | func withUnbundledBuild(_ map[string][]byte, config android.Config) { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 127 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 128 | } |
| 129 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 130 | func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 131 | bp = bp + ` |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 132 | filegroup { |
| 133 | name: "myapex-file_contexts", |
| 134 | srcs: [ |
| 135 | "system/sepolicy/apex/myapex-file_contexts", |
| 136 | ], |
| 137 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 138 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 139 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 140 | bp = bp + cc.GatherRequiredDepsForTest(android.Android) |
| 141 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 142 | bp = bp + rust.GatherRequiredDepsForTest() |
| 143 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 144 | bp = bp + java.GatherRequiredDepsForTest() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 145 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 146 | fs := map[string][]byte{ |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 147 | "a.java": nil, |
| 148 | "PrebuiltAppFoo.apk": nil, |
| 149 | "PrebuiltAppFooPriv.apk": nil, |
| 150 | "build/make/target/product/security": nil, |
| 151 | "apex_manifest.json": nil, |
| 152 | "AndroidManifest.xml": nil, |
| 153 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 154 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
| 155 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
| 156 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 157 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
| 158 | "system/sepolicy/apex/com.android.vndk.current-file_contexts": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 159 | "mylib.cpp": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 160 | "mytest.cpp": nil, |
| 161 | "mytest1.cpp": nil, |
| 162 | "mytest2.cpp": nil, |
| 163 | "mytest3.cpp": nil, |
| 164 | "myprebuilt": nil, |
| 165 | "my_include": nil, |
| 166 | "foo/bar/MyClass.java": nil, |
| 167 | "prebuilt.jar": nil, |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 168 | "prebuilt.so": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 169 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 170 | "vendor/foo/devkeys/test.pk8": nil, |
| 171 | "testkey.x509.pem": nil, |
| 172 | "testkey.pk8": nil, |
| 173 | "testkey.override.x509.pem": nil, |
| 174 | "testkey.override.pk8": nil, |
| 175 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 176 | "vendor/foo/devkeys/testkey.pem": nil, |
| 177 | "NOTICE": nil, |
| 178 | "custom_notice": nil, |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 179 | "custom_notice_for_static_lib": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 180 | "testkey2.avbpubkey": nil, |
| 181 | "testkey2.pem": nil, |
| 182 | "myapex-arm64.apex": nil, |
| 183 | "myapex-arm.apex": nil, |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 184 | "myapex.apks": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 185 | "frameworks/base/api/current.txt": nil, |
| 186 | "framework/aidl/a.aidl": nil, |
| 187 | "build/make/core/proguard.flags": nil, |
| 188 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 189 | "dummy.txt": nil, |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 190 | "baz": nil, |
| 191 | "bar/baz": nil, |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 192 | "testdata/baz": nil, |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 193 | "AppSet.apks": nil, |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 194 | "foo.rs": nil, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 195 | "libfoo.jar": nil, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 196 | "libbar.jar": nil, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 197 | } |
| 198 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 199 | cc.GatherRequiredFilesForTest(fs) |
| 200 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 201 | for _, handler := range handlers { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 202 | // The fs now needs to be populated before creating the config, call handlers twice |
| 203 | // for now, once to get any fs changes, and later after the config was created to |
| 204 | // set product variables or targets. |
| 205 | tempConfig := android.TestArchConfig(buildDir, nil, bp, fs) |
| 206 | handler(fs, tempConfig) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 207 | } |
| 208 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 209 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 210 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 211 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 212 | config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 213 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 214 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 215 | config.TestProductVariables.Platform_version_active_codenames = []string{"Q"} |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 216 | config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") |
| 217 | |
| 218 | for _, handler := range handlers { |
| 219 | // The fs now needs to be populated before creating the config, call handlers twice |
| 220 | // for now, earlier to get any fs changes, and now after the config was created to |
| 221 | // set product variables or targets. |
| 222 | tempFS := map[string][]byte{} |
| 223 | handler(tempFS, config) |
| 224 | } |
| 225 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 226 | ctx := android.NewTestArchContext(config) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 227 | |
| 228 | // from android package |
| 229 | android.RegisterPackageBuildComponents(ctx) |
| 230 | ctx.PreArchMutators(android.RegisterVisibilityRuleChecker) |
| 231 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 232 | ctx.RegisterModuleType("apex", BundleFactory) |
| 233 | ctx.RegisterModuleType("apex_test", testApexBundleFactory) |
| 234 | ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
| 235 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 236 | ctx.RegisterModuleType("apex_defaults", defaultsFactory) |
| 237 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
| 238 | ctx.RegisterModuleType("override_apex", overrideApexFactory) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 239 | ctx.RegisterModuleType("apex_set", apexSetFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 240 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 241 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 242 | ctx.PreArchMutators(android.RegisterComponentsMutator) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 243 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 244 | |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 245 | android.RegisterPrebuiltMutators(ctx) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 246 | |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 247 | // Register these after the prebuilt mutators have been registered to match what |
| 248 | // happens at runtime. |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 249 | ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer) |
| 250 | ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer) |
| 251 | |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 252 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 253 | rust.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 254 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 255 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 256 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 257 | ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 258 | cc.RegisterVndkLibraryTxtTypes(ctx) |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 259 | prebuilt_etc.RegisterPrebuiltEtcBuildComponents(ctx) |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 260 | ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 261 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 262 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 263 | ctx.RegisterSingletonType("apex_keys_text", apexKeysTextFactory) |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 264 | ctx.RegisterModuleType("bpf", bpf.BpfFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 265 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 266 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 267 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 268 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 269 | ctx.Register() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 270 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 271 | return ctx, config |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 272 | } |
| 273 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 274 | func setUp() { |
| 275 | var err error |
| 276 | buildDir, err = ioutil.TempDir("", "soong_apex_test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 277 | if err != nil { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 278 | panic(err) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 279 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 280 | } |
| 281 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 282 | func tearDown() { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 283 | _ = os.RemoveAll(buildDir) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 284 | } |
| 285 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 286 | // ensure that 'result' equals 'expected' |
| 287 | func ensureEquals(t *testing.T, result string, expected string) { |
| 288 | t.Helper() |
| 289 | if result != expected { |
| 290 | t.Errorf("%q != %q", expected, result) |
| 291 | } |
| 292 | } |
| 293 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 294 | // ensure that 'result' contains 'expected' |
| 295 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 296 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 297 | if !strings.Contains(result, expected) { |
| 298 | t.Errorf("%q is not found in %q", expected, result) |
| 299 | } |
| 300 | } |
| 301 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 302 | // ensure that 'result' contains 'expected' exactly one time |
| 303 | func ensureContainsOnce(t *testing.T, result string, expected string) { |
| 304 | t.Helper() |
| 305 | count := strings.Count(result, expected) |
| 306 | if count != 1 { |
| 307 | t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result) |
| 308 | } |
| 309 | } |
| 310 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 311 | // ensures that 'result' does not contain 'notExpected' |
| 312 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 313 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 314 | if strings.Contains(result, notExpected) { |
| 315 | t.Errorf("%q is found in %q", notExpected, result) |
| 316 | } |
| 317 | } |
| 318 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 319 | func ensureMatches(t *testing.T, result string, expectedRex string) { |
| 320 | ok, err := regexp.MatchString(expectedRex, result) |
| 321 | if err != nil { |
| 322 | t.Fatalf("regexp failure trying to match %s against `%s` expression: %s", result, expectedRex, err) |
| 323 | return |
| 324 | } |
| 325 | if !ok { |
| 326 | t.Errorf("%s does not match regular expession %s", result, expectedRex) |
| 327 | } |
| 328 | } |
| 329 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 330 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 331 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 332 | if !android.InList(expected, result) { |
| 333 | t.Errorf("%q is not found in %v", expected, result) |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 338 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 339 | if android.InList(notExpected, result) { |
| 340 | t.Errorf("%q is found in %v", notExpected, result) |
| 341 | } |
| 342 | } |
| 343 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 344 | func ensureListEmpty(t *testing.T, result []string) { |
| 345 | t.Helper() |
| 346 | if len(result) > 0 { |
| 347 | t.Errorf("%q is expected to be empty", result) |
| 348 | } |
| 349 | } |
| 350 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 351 | func ensureListNotEmpty(t *testing.T, result []string) { |
| 352 | t.Helper() |
| 353 | if len(result) == 0 { |
| 354 | t.Errorf("%q is expected to be not empty", result) |
| 355 | } |
| 356 | } |
| 357 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 358 | // Minimal test |
| 359 | func TestBasicApex(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 360 | ctx, _ := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 361 | apex_defaults { |
| 362 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 363 | manifest: ":myapex.manifest", |
| 364 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 365 | key: "myapex.key", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 366 | binaries: ["foo.rust"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 367 | native_shared_libs: [ |
| 368 | "mylib", |
| 369 | "libfoo.ffi", |
| 370 | ], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 371 | rust_dyn_libs: ["libfoo.dylib.rust"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 372 | multilib: { |
| 373 | both: { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 374 | binaries: ["foo"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 375 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 376 | }, |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 377 | java_libs: [ |
| 378 | "myjar", |
| 379 | "myjar_dex", |
| 380 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 381 | } |
| 382 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 383 | apex { |
| 384 | name: "myapex", |
| 385 | defaults: ["myapex-defaults"], |
| 386 | } |
| 387 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 388 | apex_key { |
| 389 | name: "myapex.key", |
| 390 | public_key: "testkey.avbpubkey", |
| 391 | private_key: "testkey.pem", |
| 392 | } |
| 393 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 394 | filegroup { |
| 395 | name: "myapex.manifest", |
| 396 | srcs: ["apex_manifest.json"], |
| 397 | } |
| 398 | |
| 399 | filegroup { |
| 400 | name: "myapex.androidmanifest", |
| 401 | srcs: ["AndroidManifest.xml"], |
| 402 | } |
| 403 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 404 | cc_library { |
| 405 | name: "mylib", |
| 406 | srcs: ["mylib.cpp"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 407 | shared_libs: [ |
| 408 | "mylib2", |
| 409 | "libbar.ffi", |
| 410 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 411 | system_shared_libs: [], |
| 412 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 413 | // TODO: remove //apex_available:platform |
| 414 | apex_available: [ |
| 415 | "//apex_available:platform", |
| 416 | "myapex", |
| 417 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 418 | } |
| 419 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 420 | cc_binary { |
| 421 | name: "foo", |
| 422 | srcs: ["mylib.cpp"], |
| 423 | compile_multilib: "both", |
| 424 | multilib: { |
| 425 | lib32: { |
| 426 | suffix: "32", |
| 427 | }, |
| 428 | lib64: { |
| 429 | suffix: "64", |
| 430 | }, |
| 431 | }, |
| 432 | symlinks: ["foo_link_"], |
| 433 | symlink_preferred_arch: true, |
| 434 | system_shared_libs: [], |
| 435 | static_executable: true, |
| 436 | stl: "none", |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 437 | apex_available: [ "myapex", "com.android.gki.*" ], |
| 438 | } |
| 439 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 440 | rust_binary { |
| 441 | name: "foo.rust", |
| 442 | srcs: ["foo.rs"], |
| 443 | rlibs: ["libfoo.rlib.rust"], |
| 444 | dylibs: ["libfoo.dylib.rust"], |
| 445 | apex_available: ["myapex"], |
| 446 | } |
| 447 | |
| 448 | rust_library_rlib { |
| 449 | name: "libfoo.rlib.rust", |
| 450 | srcs: ["foo.rs"], |
| 451 | crate_name: "foo", |
| 452 | apex_available: ["myapex"], |
| 453 | } |
| 454 | |
| 455 | rust_library_dylib { |
| 456 | name: "libfoo.dylib.rust", |
| 457 | srcs: ["foo.rs"], |
| 458 | crate_name: "foo", |
| 459 | apex_available: ["myapex"], |
| 460 | } |
| 461 | |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 462 | rust_ffi_shared { |
| 463 | name: "libfoo.ffi", |
| 464 | srcs: ["foo.rs"], |
| 465 | crate_name: "foo", |
| 466 | apex_available: ["myapex"], |
| 467 | } |
| 468 | |
| 469 | rust_ffi_shared { |
| 470 | name: "libbar.ffi", |
| 471 | srcs: ["foo.rs"], |
| 472 | crate_name: "bar", |
| 473 | apex_available: ["myapex"], |
| 474 | } |
| 475 | |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 476 | apex { |
| 477 | name: "com.android.gki.fake", |
| 478 | binaries: ["foo"], |
| 479 | key: "myapex.key", |
| 480 | file_contexts: ":myapex-file_contexts", |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 483 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 484 | name: "mylib2", |
| 485 | srcs: ["mylib.cpp"], |
| 486 | system_shared_libs: [], |
| 487 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 488 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 489 | static_libs: ["libstatic"], |
| 490 | // TODO: remove //apex_available:platform |
| 491 | apex_available: [ |
| 492 | "//apex_available:platform", |
| 493 | "myapex", |
| 494 | ], |
| 495 | } |
| 496 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 497 | cc_prebuilt_library_shared { |
| 498 | name: "mylib2", |
| 499 | srcs: ["prebuilt.so"], |
| 500 | // TODO: remove //apex_available:platform |
| 501 | apex_available: [ |
| 502 | "//apex_available:platform", |
| 503 | "myapex", |
| 504 | ], |
| 505 | } |
| 506 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 507 | cc_library_static { |
| 508 | name: "libstatic", |
| 509 | srcs: ["mylib.cpp"], |
| 510 | system_shared_libs: [], |
| 511 | stl: "none", |
| 512 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 513 | // TODO: remove //apex_available:platform |
| 514 | apex_available: [ |
| 515 | "//apex_available:platform", |
| 516 | "myapex", |
| 517 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 518 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 519 | |
| 520 | java_library { |
| 521 | name: "myjar", |
| 522 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 523 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 524 | sdk_version: "none", |
| 525 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 526 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 527 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 528 | // TODO: remove //apex_available:platform |
| 529 | apex_available: [ |
| 530 | "//apex_available:platform", |
| 531 | "myapex", |
| 532 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 533 | } |
| 534 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 535 | dex_import { |
| 536 | name: "myjar_dex", |
| 537 | jars: ["prebuilt.jar"], |
| 538 | apex_available: [ |
| 539 | "//apex_available:platform", |
| 540 | "myapex", |
| 541 | ], |
| 542 | } |
| 543 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 544 | java_library { |
| 545 | name: "myotherjar", |
| 546 | srcs: ["foo/bar/MyClass.java"], |
| 547 | sdk_version: "none", |
| 548 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 549 | // TODO: remove //apex_available:platform |
| 550 | apex_available: [ |
| 551 | "//apex_available:platform", |
| 552 | "myapex", |
| 553 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 554 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 555 | |
| 556 | java_library { |
| 557 | name: "mysharedjar", |
| 558 | srcs: ["foo/bar/MyClass.java"], |
| 559 | sdk_version: "none", |
| 560 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 561 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 562 | `) |
| 563 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 564 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 565 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 566 | // Make sure that Android.mk is created |
| 567 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 568 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 569 | var builder strings.Builder |
| 570 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 571 | |
| 572 | androidMk := builder.String() |
| 573 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 574 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 575 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 576 | optFlags := apexRule.Args["opt_flags"] |
| 577 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 578 | // Ensure that the NOTICE output is being packaged as an asset. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 579 | 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] | 580 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 581 | copyCmds := apexRule.Args["copy_commands"] |
| 582 | |
| 583 | // Ensure that main rule creates an output |
| 584 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 585 | |
| 586 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 587 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 588 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") |
| 589 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 590 | ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 591 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 592 | |
| 593 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 594 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
| 595 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 596 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000") |
| 597 | 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] | 598 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 599 | |
| 600 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 601 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 602 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 603 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 604 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 605 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 606 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so") |
| 607 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 608 | // .. but not for java libs |
| 609 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 610 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 611 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 612 | // Ensure that the platform variant ends with _shared or _common |
| 613 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 614 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 615 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 616 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 617 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 618 | |
| 619 | // Ensure that dynamic dependency to java libs are not included |
| 620 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 621 | |
| 622 | // Ensure that all symlinks are present. |
| 623 | found_foo_link_64 := false |
| 624 | found_foo := false |
| 625 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 626 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 627 | if strings.HasSuffix(cmd, "bin/foo") { |
| 628 | found_foo = true |
| 629 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 630 | found_foo_link_64 = true |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | good := found_foo && found_foo_link_64 |
| 635 | if !good { |
| 636 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 637 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 638 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 639 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 640 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 641 | if len(noticeInputs) != 3 { |
| 642 | 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] | 643 | } |
| 644 | ensureListContains(t, noticeInputs, "NOTICE") |
| 645 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 646 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 647 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 648 | 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] | 649 | ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex") |
| 650 | ensureListContains(t, fullDepsInfo, " mylib(minSdkVersion:(no version)) <- myapex") |
| 651 | ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib") |
| 652 | ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar") |
| 653 | ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 654 | |
| 655 | 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] | 656 | ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))") |
| 657 | ensureListContains(t, flatDepsInfo, "mylib(minSdkVersion:(no version))") |
| 658 | ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))") |
| 659 | ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))") |
| 660 | ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 661 | } |
| 662 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 663 | func TestDefaults(t *testing.T) { |
| 664 | ctx, _ := testApex(t, ` |
| 665 | apex_defaults { |
| 666 | name: "myapex-defaults", |
| 667 | key: "myapex.key", |
| 668 | prebuilts: ["myetc"], |
| 669 | native_shared_libs: ["mylib"], |
| 670 | java_libs: ["myjar"], |
| 671 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 672 | rros: ["rro"], |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 673 | bpfs: ["bpf"], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | prebuilt_etc { |
| 677 | name: "myetc", |
| 678 | src: "myprebuilt", |
| 679 | } |
| 680 | |
| 681 | apex { |
| 682 | name: "myapex", |
| 683 | defaults: ["myapex-defaults"], |
| 684 | } |
| 685 | |
| 686 | apex_key { |
| 687 | name: "myapex.key", |
| 688 | public_key: "testkey.avbpubkey", |
| 689 | private_key: "testkey.pem", |
| 690 | } |
| 691 | |
| 692 | cc_library { |
| 693 | name: "mylib", |
| 694 | system_shared_libs: [], |
| 695 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 696 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | java_library { |
| 700 | name: "myjar", |
| 701 | srcs: ["foo/bar/MyClass.java"], |
| 702 | sdk_version: "none", |
| 703 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 704 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | android_app { |
| 708 | name: "AppFoo", |
| 709 | srcs: ["foo/bar/MyClass.java"], |
| 710 | sdk_version: "none", |
| 711 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 712 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 713 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 714 | |
| 715 | runtime_resource_overlay { |
| 716 | name: "rro", |
| 717 | theme: "blue", |
| 718 | } |
| 719 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 720 | bpf { |
| 721 | name: "bpf", |
| 722 | srcs: ["bpf.c", "bpf2.c"], |
| 723 | } |
| 724 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 725 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 726 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 727 | "etc/myetc", |
| 728 | "javalib/myjar.jar", |
| 729 | "lib64/mylib.so", |
| 730 | "app/AppFoo/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 731 | "overlay/blue/rro.apk", |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 732 | "etc/bpf/bpf.o", |
| 733 | "etc/bpf/bpf2.o", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 734 | }) |
| 735 | } |
| 736 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 737 | func TestApexManifest(t *testing.T) { |
| 738 | ctx, _ := testApex(t, ` |
| 739 | apex { |
| 740 | name: "myapex", |
| 741 | key: "myapex.key", |
| 742 | } |
| 743 | |
| 744 | apex_key { |
| 745 | name: "myapex.key", |
| 746 | public_key: "testkey.avbpubkey", |
| 747 | private_key: "testkey.pem", |
| 748 | } |
| 749 | `) |
| 750 | |
| 751 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 752 | args := module.Rule("apexRule").Args |
| 753 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 754 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 755 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 756 | } |
| 757 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 758 | func TestBasicZipApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 759 | ctx, _ := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 760 | apex { |
| 761 | name: "myapex", |
| 762 | key: "myapex.key", |
| 763 | payload_type: "zip", |
| 764 | native_shared_libs: ["mylib"], |
| 765 | } |
| 766 | |
| 767 | apex_key { |
| 768 | name: "myapex.key", |
| 769 | public_key: "testkey.avbpubkey", |
| 770 | private_key: "testkey.pem", |
| 771 | } |
| 772 | |
| 773 | cc_library { |
| 774 | name: "mylib", |
| 775 | srcs: ["mylib.cpp"], |
| 776 | shared_libs: ["mylib2"], |
| 777 | system_shared_libs: [], |
| 778 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 779 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | cc_library { |
| 783 | name: "mylib2", |
| 784 | srcs: ["mylib.cpp"], |
| 785 | system_shared_libs: [], |
| 786 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 787 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 788 | } |
| 789 | `) |
| 790 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 791 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 792 | copyCmds := zipApexRule.Args["copy_commands"] |
| 793 | |
| 794 | // Ensure that main rule creates an output |
| 795 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 796 | |
| 797 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 798 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 799 | |
| 800 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 801 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 802 | |
| 803 | // Ensure that both direct and indirect deps are copied into apex |
| 804 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 805 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | func TestApexWithStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 809 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 810 | apex { |
| 811 | name: "myapex", |
| 812 | key: "myapex.key", |
| 813 | native_shared_libs: ["mylib", "mylib3"], |
| 814 | } |
| 815 | |
| 816 | apex_key { |
| 817 | name: "myapex.key", |
| 818 | public_key: "testkey.avbpubkey", |
| 819 | private_key: "testkey.pem", |
| 820 | } |
| 821 | |
| 822 | cc_library { |
| 823 | name: "mylib", |
| 824 | srcs: ["mylib.cpp"], |
| 825 | shared_libs: ["mylib2", "mylib3"], |
| 826 | system_shared_libs: [], |
| 827 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 828 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | cc_library { |
| 832 | name: "mylib2", |
| 833 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 834 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 835 | system_shared_libs: [], |
| 836 | stl: "none", |
| 837 | stubs: { |
| 838 | versions: ["1", "2", "3"], |
| 839 | }, |
| 840 | } |
| 841 | |
| 842 | cc_library { |
| 843 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 844 | srcs: ["mylib.cpp"], |
| 845 | shared_libs: ["mylib4"], |
| 846 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 847 | stl: "none", |
| 848 | stubs: { |
| 849 | versions: ["10", "11", "12"], |
| 850 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 851 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 852 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 853 | |
| 854 | cc_library { |
| 855 | name: "mylib4", |
| 856 | srcs: ["mylib.cpp"], |
| 857 | system_shared_libs: [], |
| 858 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 859 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 860 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 861 | `) |
| 862 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 863 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 864 | copyCmds := apexRule.Args["copy_commands"] |
| 865 | |
| 866 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 867 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 868 | |
| 869 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 870 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 871 | |
| 872 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 873 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 874 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 875 | 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] | 876 | |
| 877 | // 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] | 878 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 879 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 880 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 881 | |
| 882 | // 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] | 883 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 884 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 885 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 886 | |
| 887 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 888 | 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] | 889 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 890 | |
| 891 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 892 | 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] | 893 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 894 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 895 | "lib64/mylib.so", |
| 896 | "lib64/mylib3.so", |
| 897 | "lib64/mylib4.so", |
| 898 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 899 | } |
| 900 | |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 901 | func TestApexWithStubsWithMinSdkVersion(t *testing.T) { |
| 902 | t.Parallel() |
| 903 | ctx, _ := testApex(t, ` |
| 904 | apex { |
| 905 | name: "myapex", |
| 906 | key: "myapex.key", |
| 907 | native_shared_libs: ["mylib", "mylib3"], |
| 908 | min_sdk_version: "29", |
| 909 | } |
| 910 | |
| 911 | apex_key { |
| 912 | name: "myapex.key", |
| 913 | public_key: "testkey.avbpubkey", |
| 914 | private_key: "testkey.pem", |
| 915 | } |
| 916 | |
| 917 | cc_library { |
| 918 | name: "mylib", |
| 919 | srcs: ["mylib.cpp"], |
| 920 | shared_libs: ["mylib2", "mylib3"], |
| 921 | system_shared_libs: [], |
| 922 | stl: "none", |
| 923 | apex_available: [ "myapex" ], |
| 924 | min_sdk_version: "28", |
| 925 | } |
| 926 | |
| 927 | cc_library { |
| 928 | name: "mylib2", |
| 929 | srcs: ["mylib.cpp"], |
| 930 | cflags: ["-include mylib.h"], |
| 931 | system_shared_libs: [], |
| 932 | stl: "none", |
| 933 | stubs: { |
| 934 | versions: ["28", "29", "30", "current"], |
| 935 | }, |
| 936 | min_sdk_version: "28", |
| 937 | } |
| 938 | |
| 939 | cc_library { |
| 940 | name: "mylib3", |
| 941 | srcs: ["mylib.cpp"], |
| 942 | shared_libs: ["mylib4"], |
| 943 | system_shared_libs: [], |
| 944 | stl: "none", |
| 945 | stubs: { |
| 946 | versions: ["28", "29", "30", "current"], |
| 947 | }, |
| 948 | apex_available: [ "myapex" ], |
| 949 | min_sdk_version: "28", |
| 950 | } |
| 951 | |
| 952 | cc_library { |
| 953 | name: "mylib4", |
| 954 | srcs: ["mylib.cpp"], |
| 955 | system_shared_libs: [], |
| 956 | stl: "none", |
| 957 | apex_available: [ "myapex" ], |
| 958 | min_sdk_version: "28", |
| 959 | } |
| 960 | `) |
| 961 | |
| 962 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 963 | copyCmds := apexRule.Args["copy_commands"] |
| 964 | |
| 965 | // Ensure that direct non-stubs dep is always included |
| 966 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 967 | |
| 968 | // Ensure that indirect stubs dep is not included |
| 969 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 970 | |
| 971 | // Ensure that direct stubs dep is included |
| 972 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 973 | |
| 974 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"] |
| 975 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 976 | // Ensure that mylib is linking with the latest version of stub for mylib2 |
| 977 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 978 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| 979 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 980 | |
| 981 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| 982 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so") |
| 983 | // .. and not linking to the stubs variant of mylib3 |
| 984 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so") |
| 985 | |
| 986 | // Ensure that stubs libs are built without -include flags |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 987 | 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] | 988 | ensureNotContains(t, mylib2Cflags, "-include ") |
| 989 | |
| 990 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 991 | 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] | 992 | |
| 993 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 994 | "lib64/mylib.so", |
| 995 | "lib64/mylib3.so", |
| 996 | "lib64/mylib4.so", |
| 997 | }) |
| 998 | } |
| 999 | |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1000 | func TestApex_PlatformUsesLatestStubFromApex(t *testing.T) { |
| 1001 | t.Parallel() |
| 1002 | // myapex (Z) |
| 1003 | // mylib -----------------. |
| 1004 | // | |
| 1005 | // otherapex (29) | |
| 1006 | // libstub's versions: 29 Z current |
| 1007 | // | |
| 1008 | // <platform> | |
| 1009 | // libplatform ----------------' |
| 1010 | ctx, _ := testApex(t, ` |
| 1011 | apex { |
| 1012 | name: "myapex", |
| 1013 | key: "myapex.key", |
| 1014 | native_shared_libs: ["mylib"], |
| 1015 | min_sdk_version: "Z", // non-final |
| 1016 | } |
| 1017 | |
| 1018 | cc_library { |
| 1019 | name: "mylib", |
| 1020 | srcs: ["mylib.cpp"], |
| 1021 | shared_libs: ["libstub"], |
| 1022 | apex_available: ["myapex"], |
| 1023 | min_sdk_version: "Z", |
| 1024 | } |
| 1025 | |
| 1026 | apex_key { |
| 1027 | name: "myapex.key", |
| 1028 | public_key: "testkey.avbpubkey", |
| 1029 | private_key: "testkey.pem", |
| 1030 | } |
| 1031 | |
| 1032 | apex { |
| 1033 | name: "otherapex", |
| 1034 | key: "myapex.key", |
| 1035 | native_shared_libs: ["libstub"], |
| 1036 | min_sdk_version: "29", |
| 1037 | } |
| 1038 | |
| 1039 | cc_library { |
| 1040 | name: "libstub", |
| 1041 | srcs: ["mylib.cpp"], |
| 1042 | stubs: { |
| 1043 | versions: ["29", "Z", "current"], |
| 1044 | }, |
| 1045 | apex_available: ["otherapex"], |
| 1046 | min_sdk_version: "29", |
| 1047 | } |
| 1048 | |
| 1049 | // platform module depending on libstub from otherapex should use the latest stub("current") |
| 1050 | cc_library { |
| 1051 | name: "libplatform", |
| 1052 | srcs: ["mylib.cpp"], |
| 1053 | shared_libs: ["libstub"], |
| 1054 | } |
| 1055 | `, func(fs map[string][]byte, config android.Config) { |
| 1056 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Z") |
| 1057 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
| 1058 | config.TestProductVariables.Platform_version_active_codenames = []string{"Z"} |
| 1059 | }) |
| 1060 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1061 | // Ensure that mylib from myapex is built against the latest stub (current) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1062 | mylibCflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1063 | ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=10000 ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1064 | mylibLdflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1065 | ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1066 | |
| 1067 | // Ensure that libplatform is built against latest stub ("current") of mylib3 from the apex |
| 1068 | libplatformCflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1069 | ensureContains(t, libplatformCflags, "-D__LIBSTUB_API__=10000 ") // "current" maps to 10000 |
| 1070 | libplatformLdflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1071 | ensureContains(t, libplatformLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
| 1072 | } |
| 1073 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1074 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1075 | ctx, _ := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1076 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1077 | name: "myapex2", |
| 1078 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1079 | native_shared_libs: ["mylib"], |
| 1080 | } |
| 1081 | |
| 1082 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1083 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1084 | public_key: "testkey.avbpubkey", |
| 1085 | private_key: "testkey.pem", |
| 1086 | } |
| 1087 | |
| 1088 | cc_library { |
| 1089 | name: "mylib", |
| 1090 | srcs: ["mylib.cpp"], |
| 1091 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1092 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1093 | system_shared_libs: [], |
| 1094 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1095 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | cc_library { |
| 1099 | name: "libfoo", |
| 1100 | srcs: ["mylib.cpp"], |
| 1101 | shared_libs: ["libbar"], |
| 1102 | system_shared_libs: [], |
| 1103 | stl: "none", |
| 1104 | stubs: { |
| 1105 | versions: ["10", "20", "30"], |
| 1106 | }, |
| 1107 | } |
| 1108 | |
| 1109 | cc_library { |
| 1110 | name: "libbar", |
| 1111 | srcs: ["mylib.cpp"], |
| 1112 | system_shared_libs: [], |
| 1113 | stl: "none", |
| 1114 | } |
| 1115 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1116 | cc_library_static { |
| 1117 | name: "libbaz", |
| 1118 | srcs: ["mylib.cpp"], |
| 1119 | system_shared_libs: [], |
| 1120 | stl: "none", |
| 1121 | apex_available: [ "myapex2" ], |
| 1122 | } |
| 1123 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1124 | `) |
| 1125 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1126 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1127 | copyCmds := apexRule.Args["copy_commands"] |
| 1128 | |
| 1129 | // Ensure that direct non-stubs dep is always included |
| 1130 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1131 | |
| 1132 | // Ensure that indirect stubs dep is not included |
| 1133 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1134 | |
| 1135 | // Ensure that dependency of stubs is not included |
| 1136 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1137 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1138 | 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] | 1139 | |
| 1140 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1141 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1142 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1143 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1144 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1145 | 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] | 1146 | |
| 1147 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 1148 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1149 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1150 | 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] | 1151 | ensureListContains(t, fullDepsInfo, " mylib(minSdkVersion:(no version)) <- myapex2") |
| 1152 | ensureListContains(t, fullDepsInfo, " libbaz(minSdkVersion:(no version)) <- mylib") |
| 1153 | ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1154 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1155 | 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] | 1156 | ensureListContains(t, flatDepsInfo, "mylib(minSdkVersion:(no version))") |
| 1157 | ensureListContains(t, flatDepsInfo, "libbaz(minSdkVersion:(no version))") |
| 1158 | ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1159 | } |
| 1160 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1161 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 1162 | /* |
| 1163 | myapex |
| 1164 | | |
| 1165 | v (runtime_libs) |
| 1166 | mylib ------+------> libfoo [provides stub] |
| 1167 | | |
| 1168 | `------> libbar |
| 1169 | */ |
| 1170 | ctx, _ := testApex(t, ` |
| 1171 | apex { |
| 1172 | name: "myapex", |
| 1173 | key: "myapex.key", |
| 1174 | native_shared_libs: ["mylib"], |
| 1175 | } |
| 1176 | |
| 1177 | apex_key { |
| 1178 | name: "myapex.key", |
| 1179 | public_key: "testkey.avbpubkey", |
| 1180 | private_key: "testkey.pem", |
| 1181 | } |
| 1182 | |
| 1183 | cc_library { |
| 1184 | name: "mylib", |
| 1185 | srcs: ["mylib.cpp"], |
| 1186 | runtime_libs: ["libfoo", "libbar"], |
| 1187 | system_shared_libs: [], |
| 1188 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1189 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | cc_library { |
| 1193 | name: "libfoo", |
| 1194 | srcs: ["mylib.cpp"], |
| 1195 | system_shared_libs: [], |
| 1196 | stl: "none", |
| 1197 | stubs: { |
| 1198 | versions: ["10", "20", "30"], |
| 1199 | }, |
| 1200 | } |
| 1201 | |
| 1202 | cc_library { |
| 1203 | name: "libbar", |
| 1204 | srcs: ["mylib.cpp"], |
| 1205 | system_shared_libs: [], |
| 1206 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1207 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | `) |
| 1211 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1212 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1213 | copyCmds := apexRule.Args["copy_commands"] |
| 1214 | |
| 1215 | // Ensure that direct non-stubs dep is always included |
| 1216 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1217 | |
| 1218 | // Ensure that indirect stubs dep is not included |
| 1219 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1220 | |
| 1221 | // Ensure that runtime_libs dep in included |
| 1222 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1223 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1224 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1225 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1226 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1227 | |
| 1228 | } |
| 1229 | |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1230 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
| 1231 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 1232 | bp := ` |
| 1233 | apex { |
| 1234 | name: "com.android.runtime", |
| 1235 | key: "com.android.runtime.key", |
| 1236 | native_shared_libs: ["libc"], |
| 1237 | } |
| 1238 | |
| 1239 | apex_key { |
| 1240 | name: "com.android.runtime.key", |
| 1241 | public_key: "testkey.avbpubkey", |
| 1242 | private_key: "testkey.pem", |
| 1243 | } |
| 1244 | |
| 1245 | cc_library { |
| 1246 | name: "libc", |
| 1247 | no_libcrt: true, |
| 1248 | nocrt: true, |
| 1249 | stl: "none", |
| 1250 | system_shared_libs: [], |
| 1251 | stubs: { versions: ["1"] }, |
| 1252 | apex_available: ["com.android.runtime"], |
| 1253 | |
| 1254 | sanitize: { |
| 1255 | hwaddress: true, |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | cc_prebuilt_library_shared { |
| 1260 | name: "libclang_rt.hwasan-aarch64-android", |
| 1261 | no_libcrt: true, |
| 1262 | nocrt: true, |
| 1263 | stl: "none", |
| 1264 | system_shared_libs: [], |
| 1265 | srcs: [""], |
| 1266 | stubs: { versions: ["1"] }, |
| 1267 | |
| 1268 | sanitize: { |
| 1269 | never: true, |
| 1270 | }, |
| 1271 | } |
| 1272 | ` |
| 1273 | // override bp to use hard-coded names: com.android.runtime and libc |
| 1274 | fs["Android.bp"] = []byte(bp) |
| 1275 | fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil |
| 1276 | }) |
| 1277 | |
| 1278 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1279 | "lib64/bionic/libc.so", |
| 1280 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1281 | }) |
| 1282 | |
| 1283 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1284 | |
| 1285 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1286 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1287 | |
| 1288 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1289 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1290 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1291 | } |
| 1292 | |
| 1293 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
| 1294 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 1295 | bp := ` |
| 1296 | apex { |
| 1297 | name: "com.android.runtime", |
| 1298 | key: "com.android.runtime.key", |
| 1299 | native_shared_libs: ["libc"], |
| 1300 | } |
| 1301 | |
| 1302 | apex_key { |
| 1303 | name: "com.android.runtime.key", |
| 1304 | public_key: "testkey.avbpubkey", |
| 1305 | private_key: "testkey.pem", |
| 1306 | } |
| 1307 | |
| 1308 | cc_library { |
| 1309 | name: "libc", |
| 1310 | no_libcrt: true, |
| 1311 | nocrt: true, |
| 1312 | stl: "none", |
| 1313 | system_shared_libs: [], |
| 1314 | stubs: { versions: ["1"] }, |
| 1315 | apex_available: ["com.android.runtime"], |
| 1316 | } |
| 1317 | |
| 1318 | cc_prebuilt_library_shared { |
| 1319 | name: "libclang_rt.hwasan-aarch64-android", |
| 1320 | no_libcrt: true, |
| 1321 | nocrt: true, |
| 1322 | stl: "none", |
| 1323 | system_shared_libs: [], |
| 1324 | srcs: [""], |
| 1325 | stubs: { versions: ["1"] }, |
| 1326 | |
| 1327 | sanitize: { |
| 1328 | never: true, |
| 1329 | }, |
| 1330 | } |
| 1331 | ` |
| 1332 | // override bp to use hard-coded names: com.android.runtime and libc |
| 1333 | fs["Android.bp"] = []byte(bp) |
| 1334 | fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil |
| 1335 | |
| 1336 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1337 | }) |
| 1338 | |
| 1339 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1340 | "lib64/bionic/libc.so", |
| 1341 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1342 | }) |
| 1343 | |
| 1344 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1345 | |
| 1346 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1347 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1348 | |
| 1349 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1350 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1351 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1352 | } |
| 1353 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1354 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1355 | testcases := []struct { |
| 1356 | name string |
| 1357 | minSdkVersion string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1358 | apexVariant string |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1359 | shouldLink string |
| 1360 | shouldNotLink []string |
| 1361 | }{ |
| 1362 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1363 | name: "unspecified version links to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1364 | minSdkVersion: "", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1365 | apexVariant: "apex10000", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1366 | shouldLink: "30", |
| 1367 | shouldNotLink: []string{"29"}, |
| 1368 | }, |
| 1369 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1370 | name: "always use the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1371 | minSdkVersion: "min_sdk_version: \"29\",", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1372 | apexVariant: "apex29", |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1373 | shouldLink: "30", |
| 1374 | shouldNotLink: []string{"29"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1375 | }, |
| 1376 | } |
| 1377 | for _, tc := range testcases { |
| 1378 | t.Run(tc.name, func(t *testing.T) { |
| 1379 | ctx, _ := testApex(t, ` |
| 1380 | apex { |
| 1381 | name: "myapex", |
| 1382 | key: "myapex.key", |
| 1383 | use_vendor: true, |
| 1384 | native_shared_libs: ["mylib"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1385 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1386 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1387 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1388 | apex_key { |
| 1389 | name: "myapex.key", |
| 1390 | public_key: "testkey.avbpubkey", |
| 1391 | private_key: "testkey.pem", |
| 1392 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1393 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1394 | cc_library { |
| 1395 | name: "mylib", |
| 1396 | srcs: ["mylib.cpp"], |
| 1397 | vendor_available: true, |
| 1398 | shared_libs: ["libbar"], |
| 1399 | system_shared_libs: [], |
| 1400 | stl: "none", |
| 1401 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1402 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1403 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1404 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1405 | cc_library { |
| 1406 | name: "libbar", |
| 1407 | srcs: ["mylib.cpp"], |
| 1408 | system_shared_libs: [], |
| 1409 | stl: "none", |
| 1410 | stubs: { versions: ["29","30"] }, |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1411 | llndk_stubs: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1412 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1413 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1414 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1415 | name: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1416 | symbol_file: "", |
| 1417 | } |
| 1418 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 1419 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1420 | }, withUnbundledBuild) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1421 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1422 | // Ensure that LLNDK dep is not included |
| 1423 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1424 | "lib64/mylib.so", |
| 1425 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1426 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1427 | // Ensure that LLNDK dep is required |
| 1428 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1429 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1430 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1431 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1432 | 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] | 1433 | 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] | 1434 | for _, ver := range tc.shouldNotLink { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 1435 | 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] | 1436 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1437 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1438 | 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] | 1439 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink) |
| 1440 | }) |
| 1441 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1442 | } |
| 1443 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1444 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1445 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1446 | apex { |
| 1447 | name: "myapex", |
| 1448 | key: "myapex.key", |
| 1449 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 1450 | } |
| 1451 | |
| 1452 | apex_key { |
| 1453 | name: "myapex.key", |
| 1454 | public_key: "testkey.avbpubkey", |
| 1455 | private_key: "testkey.pem", |
| 1456 | } |
| 1457 | |
| 1458 | cc_library { |
| 1459 | name: "mylib", |
| 1460 | srcs: ["mylib.cpp"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1461 | system_shared_libs: ["libc", "libm"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1462 | shared_libs: ["libdl#27"], |
| 1463 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1464 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | cc_library_shared { |
| 1468 | name: "mylib_shared", |
| 1469 | srcs: ["mylib.cpp"], |
| 1470 | shared_libs: ["libdl#27"], |
| 1471 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1472 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1476 | name: "libBootstrap", |
| 1477 | srcs: ["mylib.cpp"], |
| 1478 | stl: "none", |
| 1479 | bootstrap: true, |
| 1480 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1481 | `) |
| 1482 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1483 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1484 | copyCmds := apexRule.Args["copy_commands"] |
| 1485 | |
| 1486 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1487 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1488 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1489 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1490 | |
| 1491 | // 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] | 1492 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1493 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1494 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1495 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1496 | 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] | 1497 | |
| 1498 | // For dependency to libc |
| 1499 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1500 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1501 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1502 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1503 | // ... Cflags from stub is correctly exported to mylib |
| 1504 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 1505 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 1506 | |
| 1507 | // For dependency to libm |
| 1508 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1509 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1510 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1511 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1512 | // ... and is not compiling with the stub |
| 1513 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1514 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1515 | |
| 1516 | // For dependency to libdl |
| 1517 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1518 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1519 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1520 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1521 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1522 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1523 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1524 | // ... Cflags from stub is correctly exported to mylib |
| 1525 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1526 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1527 | |
| 1528 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1529 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1530 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1531 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1532 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1533 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1534 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1535 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1536 | // there are three links between liba --> libz. |
| 1537 | // 1) myapex -> libx -> liba -> libz : this should be #30 link |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1538 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1539 | // 3) (platform) -> liba -> libz : this should be non-stub link |
| 1540 | ctx, _ := testApex(t, ` |
| 1541 | apex { |
| 1542 | name: "myapex", |
| 1543 | key: "myapex.key", |
| 1544 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1545 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | apex { |
| 1549 | name: "otherapex", |
| 1550 | key: "myapex.key", |
| 1551 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1552 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | apex_key { |
| 1556 | name: "myapex.key", |
| 1557 | public_key: "testkey.avbpubkey", |
| 1558 | private_key: "testkey.pem", |
| 1559 | } |
| 1560 | |
| 1561 | cc_library { |
| 1562 | name: "libx", |
| 1563 | shared_libs: ["liba"], |
| 1564 | system_shared_libs: [], |
| 1565 | stl: "none", |
| 1566 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1567 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | cc_library { |
| 1571 | name: "liby", |
| 1572 | shared_libs: ["liba"], |
| 1573 | system_shared_libs: [], |
| 1574 | stl: "none", |
| 1575 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1576 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | cc_library { |
| 1580 | name: "liba", |
| 1581 | shared_libs: ["libz"], |
| 1582 | system_shared_libs: [], |
| 1583 | stl: "none", |
| 1584 | apex_available: [ |
| 1585 | "//apex_available:anyapex", |
| 1586 | "//apex_available:platform", |
| 1587 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1588 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | cc_library { |
| 1592 | name: "libz", |
| 1593 | system_shared_libs: [], |
| 1594 | stl: "none", |
| 1595 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1596 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1597 | }, |
| 1598 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1599 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1600 | |
| 1601 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1602 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1603 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1604 | } |
| 1605 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1606 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1607 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1608 | } |
| 1609 | // platform liba is linked to non-stub version |
| 1610 | expectLink("liba", "shared", "libz", "shared") |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1611 | // liba in myapex is linked to #30 |
| 1612 | expectLink("liba", "shared_apex29", "libz", "shared_30") |
| 1613 | expectNoLink("liba", "shared_apex29", "libz", "shared_28") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1614 | expectNoLink("liba", "shared_apex29", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1615 | // liba in otherapex is linked to #30 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1616 | expectLink("liba", "shared_apex30", "libz", "shared_30") |
| 1617 | expectNoLink("liba", "shared_apex30", "libz", "shared_28") |
| 1618 | expectNoLink("liba", "shared_apex30", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1619 | } |
| 1620 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1621 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
| 1622 | ctx, _ := testApex(t, ` |
| 1623 | apex { |
| 1624 | name: "myapex", |
| 1625 | key: "myapex.key", |
| 1626 | native_shared_libs: ["libx"], |
| 1627 | min_sdk_version: "R", |
| 1628 | } |
| 1629 | |
| 1630 | apex_key { |
| 1631 | name: "myapex.key", |
| 1632 | public_key: "testkey.avbpubkey", |
| 1633 | private_key: "testkey.pem", |
| 1634 | } |
| 1635 | |
| 1636 | cc_library { |
| 1637 | name: "libx", |
| 1638 | shared_libs: ["libz"], |
| 1639 | system_shared_libs: [], |
| 1640 | stl: "none", |
| 1641 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1642 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | cc_library { |
| 1646 | name: "libz", |
| 1647 | system_shared_libs: [], |
| 1648 | stl: "none", |
| 1649 | stubs: { |
| 1650 | versions: ["29", "R"], |
| 1651 | }, |
| 1652 | } |
| 1653 | `, func(fs map[string][]byte, config android.Config) { |
| 1654 | config.TestProductVariables.Platform_version_active_codenames = []string{"R"} |
| 1655 | }) |
| 1656 | |
| 1657 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1658 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1659 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1660 | } |
| 1661 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1662 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1663 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1664 | } |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1665 | expectLink("libx", "shared_apex10000", "libz", "shared_R") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1666 | expectNoLink("libx", "shared_apex10000", "libz", "shared_29") |
| 1667 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1668 | } |
| 1669 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1670 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1671 | ctx, _ := testApex(t, ` |
| 1672 | apex { |
| 1673 | name: "myapex", |
| 1674 | key: "myapex.key", |
| 1675 | native_shared_libs: ["libx"], |
| 1676 | } |
| 1677 | |
| 1678 | apex_key { |
| 1679 | name: "myapex.key", |
| 1680 | public_key: "testkey.avbpubkey", |
| 1681 | private_key: "testkey.pem", |
| 1682 | } |
| 1683 | |
| 1684 | cc_library { |
| 1685 | name: "libx", |
| 1686 | shared_libs: ["libz"], |
| 1687 | system_shared_libs: [], |
| 1688 | stl: "none", |
| 1689 | apex_available: [ "myapex" ], |
| 1690 | } |
| 1691 | |
| 1692 | cc_library { |
| 1693 | name: "libz", |
| 1694 | system_shared_libs: [], |
| 1695 | stl: "none", |
| 1696 | stubs: { |
| 1697 | versions: ["1", "2"], |
| 1698 | }, |
| 1699 | } |
| 1700 | `) |
| 1701 | |
| 1702 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1703 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1704 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1705 | } |
| 1706 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1707 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1708 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1709 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1710 | expectLink("libx", "shared_apex10000", "libz", "shared_2") |
| 1711 | expectNoLink("libx", "shared_apex10000", "libz", "shared_1") |
| 1712 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
| 1716 | ctx, _ := testApex(t, ` |
| 1717 | apex { |
| 1718 | name: "myapex", |
| 1719 | key: "myapex.key", |
| 1720 | native_shared_libs: ["libx"], |
| 1721 | } |
| 1722 | |
| 1723 | apex_key { |
| 1724 | name: "myapex.key", |
| 1725 | public_key: "testkey.avbpubkey", |
| 1726 | private_key: "testkey.pem", |
| 1727 | } |
| 1728 | |
| 1729 | cc_library { |
| 1730 | name: "libx", |
| 1731 | system_shared_libs: [], |
| 1732 | stl: "none", |
| 1733 | apex_available: [ "myapex" ], |
| 1734 | stubs: { |
| 1735 | versions: ["1", "2"], |
| 1736 | }, |
| 1737 | } |
| 1738 | |
| 1739 | cc_library { |
| 1740 | name: "libz", |
| 1741 | shared_libs: ["libx"], |
| 1742 | system_shared_libs: [], |
| 1743 | stl: "none", |
| 1744 | } |
| 1745 | `) |
| 1746 | |
| 1747 | expectLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1748 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1749 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1750 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1751 | } |
| 1752 | expectNoLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1753 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1754 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1755 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1756 | } |
| 1757 | expectLink("libz", "shared", "libx", "shared_2") |
| 1758 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1759 | expectNoLink("libz", "shared", "libz", "shared") |
| 1760 | } |
| 1761 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1762 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1763 | ctx, _ := testApex(t, ` |
| 1764 | apex { |
| 1765 | name: "myapex", |
| 1766 | key: "myapex.key", |
| 1767 | native_shared_libs: ["libx"], |
| 1768 | min_sdk_version: "29", |
| 1769 | } |
| 1770 | |
| 1771 | apex_key { |
| 1772 | name: "myapex.key", |
| 1773 | public_key: "testkey.avbpubkey", |
| 1774 | private_key: "testkey.pem", |
| 1775 | } |
| 1776 | |
| 1777 | cc_library { |
| 1778 | name: "libx", |
| 1779 | shared_libs: ["libbar"], |
| 1780 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1781 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | cc_library { |
| 1785 | name: "libbar", |
| 1786 | stubs: { |
| 1787 | versions: ["29", "30"], |
| 1788 | }, |
| 1789 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1790 | `, func(fs map[string][]byte, config android.Config) { |
| 1791 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1792 | }) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1793 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1794 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1795 | libFlags := ld.Args["libFlags"] |
| 1796 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1797 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1798 | expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_30") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1799 | } |
| 1800 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1801 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1802 | ctx, _ := testApex(t, ` |
| 1803 | apex { |
| 1804 | name: "myapex", |
| 1805 | key: "myapex.key", |
| 1806 | native_shared_libs: ["libx"], |
| 1807 | min_sdk_version: "29", |
| 1808 | } |
| 1809 | |
| 1810 | apex_key { |
| 1811 | name: "myapex.key", |
| 1812 | public_key: "testkey.avbpubkey", |
| 1813 | private_key: "testkey.pem", |
| 1814 | } |
| 1815 | |
| 1816 | cc_library { |
| 1817 | name: "libx", |
| 1818 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1819 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1820 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1821 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1822 | |
| 1823 | // ensure apex variant of c++ is linked with static unwinder |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1824 | 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] | 1825 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1826 | // note that platform variant is not. |
| 1827 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 1828 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1829 | } |
| 1830 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1831 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 1832 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1833 | apex { |
| 1834 | name: "myapex", |
| 1835 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1836 | native_shared_libs: ["mylib"], |
| 1837 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | apex_key { |
| 1841 | name: "myapex.key", |
| 1842 | public_key: "testkey.avbpubkey", |
| 1843 | private_key: "testkey.pem", |
| 1844 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1845 | |
| 1846 | cc_library { |
| 1847 | name: "mylib", |
| 1848 | srcs: ["mylib.cpp"], |
| 1849 | system_shared_libs: [], |
| 1850 | stl: "none", |
| 1851 | apex_available: [ |
| 1852 | "myapex", |
| 1853 | ], |
| 1854 | min_sdk_version: "30", |
| 1855 | } |
| 1856 | `) |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1857 | |
| 1858 | testApexError(t, `module "libfoo.ffi".*: should support min_sdk_version\(29\)`, ` |
| 1859 | apex { |
| 1860 | name: "myapex", |
| 1861 | key: "myapex.key", |
| 1862 | native_shared_libs: ["libfoo.ffi"], |
| 1863 | min_sdk_version: "29", |
| 1864 | } |
| 1865 | |
| 1866 | apex_key { |
| 1867 | name: "myapex.key", |
| 1868 | public_key: "testkey.avbpubkey", |
| 1869 | private_key: "testkey.pem", |
| 1870 | } |
| 1871 | |
| 1872 | rust_ffi_shared { |
| 1873 | name: "libfoo.ffi", |
| 1874 | srcs: ["foo.rs"], |
| 1875 | crate_name: "foo", |
| 1876 | apex_available: [ |
| 1877 | "myapex", |
| 1878 | ], |
| 1879 | min_sdk_version: "30", |
| 1880 | } |
| 1881 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 1885 | testApex(t, ` |
| 1886 | apex { |
| 1887 | name: "myapex", |
| 1888 | key: "myapex.key", |
| 1889 | native_shared_libs: ["libfoo"], |
| 1890 | java_libs: ["libbar"], |
| 1891 | min_sdk_version: "29", |
| 1892 | } |
| 1893 | |
| 1894 | apex_key { |
| 1895 | name: "myapex.key", |
| 1896 | public_key: "testkey.avbpubkey", |
| 1897 | private_key: "testkey.pem", |
| 1898 | } |
| 1899 | |
| 1900 | cc_library { |
| 1901 | name: "libfoo", |
| 1902 | srcs: ["mylib.cpp"], |
| 1903 | shared_libs: ["libfoo_dep"], |
| 1904 | apex_available: ["myapex"], |
| 1905 | min_sdk_version: "29", |
| 1906 | } |
| 1907 | |
| 1908 | cc_library { |
| 1909 | name: "libfoo_dep", |
| 1910 | srcs: ["mylib.cpp"], |
| 1911 | apex_available: ["myapex"], |
| 1912 | min_sdk_version: "29", |
| 1913 | } |
| 1914 | |
| 1915 | java_library { |
| 1916 | name: "libbar", |
| 1917 | sdk_version: "current", |
| 1918 | srcs: ["a.java"], |
| 1919 | static_libs: ["libbar_dep"], |
| 1920 | apex_available: ["myapex"], |
| 1921 | min_sdk_version: "29", |
| 1922 | } |
| 1923 | |
| 1924 | java_library { |
| 1925 | name: "libbar_dep", |
| 1926 | sdk_version: "current", |
| 1927 | srcs: ["a.java"], |
| 1928 | apex_available: ["myapex"], |
| 1929 | min_sdk_version: "29", |
| 1930 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1931 | `) |
| 1932 | } |
| 1933 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1934 | func TestJavaStableSdkVersion(t *testing.T) { |
| 1935 | testCases := []struct { |
| 1936 | name string |
| 1937 | expectedError string |
| 1938 | bp string |
| 1939 | }{ |
| 1940 | { |
| 1941 | name: "Non-updatable apex with non-stable dep", |
| 1942 | bp: ` |
| 1943 | apex { |
| 1944 | name: "myapex", |
| 1945 | java_libs: ["myjar"], |
| 1946 | key: "myapex.key", |
| 1947 | } |
| 1948 | apex_key { |
| 1949 | name: "myapex.key", |
| 1950 | public_key: "testkey.avbpubkey", |
| 1951 | private_key: "testkey.pem", |
| 1952 | } |
| 1953 | java_library { |
| 1954 | name: "myjar", |
| 1955 | srcs: ["foo/bar/MyClass.java"], |
| 1956 | sdk_version: "core_platform", |
| 1957 | apex_available: ["myapex"], |
| 1958 | } |
| 1959 | `, |
| 1960 | }, |
| 1961 | { |
| 1962 | name: "Updatable apex with stable dep", |
| 1963 | bp: ` |
| 1964 | apex { |
| 1965 | name: "myapex", |
| 1966 | java_libs: ["myjar"], |
| 1967 | key: "myapex.key", |
| 1968 | updatable: true, |
| 1969 | min_sdk_version: "29", |
| 1970 | } |
| 1971 | apex_key { |
| 1972 | name: "myapex.key", |
| 1973 | public_key: "testkey.avbpubkey", |
| 1974 | private_key: "testkey.pem", |
| 1975 | } |
| 1976 | java_library { |
| 1977 | name: "myjar", |
| 1978 | srcs: ["foo/bar/MyClass.java"], |
| 1979 | sdk_version: "current", |
| 1980 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1981 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1982 | } |
| 1983 | `, |
| 1984 | }, |
| 1985 | { |
| 1986 | name: "Updatable apex with non-stable dep", |
| 1987 | expectedError: "cannot depend on \"myjar\"", |
| 1988 | bp: ` |
| 1989 | apex { |
| 1990 | name: "myapex", |
| 1991 | java_libs: ["myjar"], |
| 1992 | key: "myapex.key", |
| 1993 | updatable: true, |
| 1994 | } |
| 1995 | apex_key { |
| 1996 | name: "myapex.key", |
| 1997 | public_key: "testkey.avbpubkey", |
| 1998 | private_key: "testkey.pem", |
| 1999 | } |
| 2000 | java_library { |
| 2001 | name: "myjar", |
| 2002 | srcs: ["foo/bar/MyClass.java"], |
| 2003 | sdk_version: "core_platform", |
| 2004 | apex_available: ["myapex"], |
| 2005 | } |
| 2006 | `, |
| 2007 | }, |
| 2008 | { |
| 2009 | name: "Updatable apex with non-stable transitive dep", |
Jiyong Park | 670e0f6 | 2021-02-18 13:10:18 +0900 | [diff] [blame] | 2010 | expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against private API.", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2011 | bp: ` |
| 2012 | apex { |
| 2013 | name: "myapex", |
| 2014 | java_libs: ["myjar"], |
| 2015 | key: "myapex.key", |
| 2016 | updatable: true, |
| 2017 | } |
| 2018 | apex_key { |
| 2019 | name: "myapex.key", |
| 2020 | public_key: "testkey.avbpubkey", |
| 2021 | private_key: "testkey.pem", |
| 2022 | } |
| 2023 | java_library { |
| 2024 | name: "myjar", |
| 2025 | srcs: ["foo/bar/MyClass.java"], |
| 2026 | sdk_version: "current", |
| 2027 | apex_available: ["myapex"], |
| 2028 | static_libs: ["transitive-jar"], |
| 2029 | } |
| 2030 | java_library { |
| 2031 | name: "transitive-jar", |
| 2032 | srcs: ["foo/bar/MyClass.java"], |
| 2033 | sdk_version: "core_platform", |
| 2034 | apex_available: ["myapex"], |
| 2035 | } |
| 2036 | `, |
| 2037 | }, |
| 2038 | } |
| 2039 | |
| 2040 | for _, test := range testCases { |
| 2041 | t.Run(test.name, func(t *testing.T) { |
| 2042 | if test.expectedError == "" { |
| 2043 | testApex(t, test.bp) |
| 2044 | } else { |
| 2045 | testApexError(t, test.expectedError, test.bp) |
| 2046 | } |
| 2047 | }) |
| 2048 | } |
| 2049 | } |
| 2050 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2051 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 2052 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2053 | apex { |
| 2054 | name: "myapex", |
| 2055 | key: "myapex.key", |
| 2056 | native_shared_libs: ["mylib"], |
| 2057 | min_sdk_version: "29", |
| 2058 | } |
| 2059 | |
| 2060 | apex_key { |
| 2061 | name: "myapex.key", |
| 2062 | public_key: "testkey.avbpubkey", |
| 2063 | private_key: "testkey.pem", |
| 2064 | } |
| 2065 | |
| 2066 | cc_library { |
| 2067 | name: "mylib", |
| 2068 | srcs: ["mylib.cpp"], |
| 2069 | shared_libs: ["mylib2"], |
| 2070 | system_shared_libs: [], |
| 2071 | stl: "none", |
| 2072 | apex_available: [ |
| 2073 | "myapex", |
| 2074 | ], |
| 2075 | min_sdk_version: "29", |
| 2076 | } |
| 2077 | |
| 2078 | // indirect part of the apex |
| 2079 | cc_library { |
| 2080 | name: "mylib2", |
| 2081 | srcs: ["mylib.cpp"], |
| 2082 | system_shared_libs: [], |
| 2083 | stl: "none", |
| 2084 | apex_available: [ |
| 2085 | "myapex", |
| 2086 | ], |
| 2087 | min_sdk_version: "30", |
| 2088 | } |
| 2089 | `) |
| 2090 | } |
| 2091 | |
| 2092 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 2093 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2094 | apex { |
| 2095 | name: "myapex", |
| 2096 | key: "myapex.key", |
| 2097 | apps: ["AppFoo"], |
| 2098 | min_sdk_version: "29", |
| 2099 | } |
| 2100 | |
| 2101 | apex_key { |
| 2102 | name: "myapex.key", |
| 2103 | public_key: "testkey.avbpubkey", |
| 2104 | private_key: "testkey.pem", |
| 2105 | } |
| 2106 | |
| 2107 | android_app { |
| 2108 | name: "AppFoo", |
| 2109 | srcs: ["foo/bar/MyClass.java"], |
| 2110 | sdk_version: "current", |
| 2111 | min_sdk_version: "29", |
| 2112 | system_modules: "none", |
| 2113 | stl: "none", |
| 2114 | static_libs: ["bar"], |
| 2115 | apex_available: [ "myapex" ], |
| 2116 | } |
| 2117 | |
| 2118 | java_library { |
| 2119 | name: "bar", |
| 2120 | sdk_version: "current", |
| 2121 | srcs: ["a.java"], |
| 2122 | apex_available: [ "myapex" ], |
| 2123 | } |
| 2124 | `) |
| 2125 | } |
| 2126 | |
| 2127 | func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) { |
| 2128 | ctx, _ := testApex(t, ` |
| 2129 | apex { |
| 2130 | name: "myapex", |
| 2131 | key: "myapex.key", |
| 2132 | native_shared_libs: ["mylib"], |
| 2133 | min_sdk_version: "29", |
| 2134 | } |
| 2135 | |
| 2136 | apex_key { |
| 2137 | name: "myapex.key", |
| 2138 | public_key: "testkey.avbpubkey", |
| 2139 | private_key: "testkey.pem", |
| 2140 | } |
| 2141 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 2142 | // mylib in myapex will link to mylib2#30 |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2143 | // mylib in otherapex will link to mylib2(non-stub) in otherapex as well |
| 2144 | cc_library { |
| 2145 | name: "mylib", |
| 2146 | srcs: ["mylib.cpp"], |
| 2147 | shared_libs: ["mylib2"], |
| 2148 | system_shared_libs: [], |
| 2149 | stl: "none", |
| 2150 | apex_available: ["myapex", "otherapex"], |
| 2151 | min_sdk_version: "29", |
| 2152 | } |
| 2153 | |
| 2154 | cc_library { |
| 2155 | name: "mylib2", |
| 2156 | srcs: ["mylib.cpp"], |
| 2157 | system_shared_libs: [], |
| 2158 | stl: "none", |
| 2159 | apex_available: ["otherapex"], |
| 2160 | stubs: { versions: ["29", "30"] }, |
| 2161 | min_sdk_version: "30", |
| 2162 | } |
| 2163 | |
| 2164 | apex { |
| 2165 | name: "otherapex", |
| 2166 | key: "myapex.key", |
| 2167 | native_shared_libs: ["mylib", "mylib2"], |
| 2168 | min_sdk_version: "30", |
| 2169 | } |
| 2170 | `) |
| 2171 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2172 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2173 | libFlags := ld.Args["libFlags"] |
| 2174 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2175 | } |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 2176 | expectLink("mylib", "shared_apex29", "mylib2", "shared_30") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2177 | expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2178 | } |
| 2179 | |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2180 | func TestApexMinSdkVersion_WorksWithSdkCodename(t *testing.T) { |
| 2181 | withSAsActiveCodeNames := func(fs map[string][]byte, config android.Config) { |
| 2182 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2183 | config.TestProductVariables.Platform_version_active_codenames = []string{"S"} |
| 2184 | } |
| 2185 | testApexError(t, `libbar.*: should support min_sdk_version\(S\)`, ` |
| 2186 | apex { |
| 2187 | name: "myapex", |
| 2188 | key: "myapex.key", |
| 2189 | native_shared_libs: ["libfoo"], |
| 2190 | min_sdk_version: "S", |
| 2191 | } |
| 2192 | apex_key { |
| 2193 | name: "myapex.key", |
| 2194 | public_key: "testkey.avbpubkey", |
| 2195 | private_key: "testkey.pem", |
| 2196 | } |
| 2197 | cc_library { |
| 2198 | name: "libfoo", |
| 2199 | shared_libs: ["libbar"], |
| 2200 | apex_available: ["myapex"], |
| 2201 | min_sdk_version: "29", |
| 2202 | } |
| 2203 | cc_library { |
| 2204 | name: "libbar", |
| 2205 | apex_available: ["myapex"], |
| 2206 | } |
| 2207 | `, withSAsActiveCodeNames) |
| 2208 | } |
| 2209 | |
| 2210 | func TestApexMinSdkVersion_WorksWithActiveCodenames(t *testing.T) { |
| 2211 | withSAsActiveCodeNames := func(fs map[string][]byte, config android.Config) { |
| 2212 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2213 | config.TestProductVariables.Platform_version_active_codenames = []string{"S", "T"} |
| 2214 | } |
| 2215 | ctx, _ := testApex(t, ` |
| 2216 | apex { |
| 2217 | name: "myapex", |
| 2218 | key: "myapex.key", |
| 2219 | native_shared_libs: ["libfoo"], |
| 2220 | min_sdk_version: "S", |
| 2221 | } |
| 2222 | apex_key { |
| 2223 | name: "myapex.key", |
| 2224 | public_key: "testkey.avbpubkey", |
| 2225 | private_key: "testkey.pem", |
| 2226 | } |
| 2227 | cc_library { |
| 2228 | name: "libfoo", |
| 2229 | shared_libs: ["libbar"], |
| 2230 | apex_available: ["myapex"], |
| 2231 | min_sdk_version: "S", |
| 2232 | } |
| 2233 | cc_library { |
| 2234 | name: "libbar", |
| 2235 | stubs: { |
| 2236 | symbol_file: "libbar.map.txt", |
| 2237 | versions: ["30", "S", "T"], |
| 2238 | }, |
| 2239 | } |
| 2240 | `, withSAsActiveCodeNames) |
| 2241 | |
| 2242 | // ensure libfoo is linked with "S" version of libbar stub |
| 2243 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_apex10000") |
| 2244 | libFlags := libfoo.Rule("ld").Args["libFlags"] |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 2245 | ensureContains(t, libFlags, "android_arm64_armv8-a_shared_T/libbar.so") |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2246 | } |
| 2247 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2248 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2249 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2250 | apex { |
| 2251 | name: "myapex", |
| 2252 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2253 | native_shared_libs: ["mylib"], |
| 2254 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2255 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2256 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | apex_key { |
| 2260 | name: "myapex.key", |
| 2261 | public_key: "testkey.avbpubkey", |
| 2262 | private_key: "testkey.pem", |
| 2263 | } |
| 2264 | |
| 2265 | prebuilt_etc { |
| 2266 | name: "myetc", |
| 2267 | src: "myprebuilt", |
| 2268 | sub_dir: "foo/bar", |
| 2269 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2270 | |
| 2271 | cc_library { |
| 2272 | name: "mylib", |
| 2273 | srcs: ["mylib.cpp"], |
| 2274 | relative_install_path: "foo/bar", |
| 2275 | system_shared_libs: [], |
| 2276 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2277 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | cc_binary { |
| 2281 | name: "mybin", |
| 2282 | srcs: ["mylib.cpp"], |
| 2283 | relative_install_path: "foo/bar", |
| 2284 | system_shared_libs: [], |
| 2285 | static_executable: true, |
| 2286 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2287 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2288 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2289 | `) |
| 2290 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2291 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2292 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 2293 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2294 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2295 | ensureListContains(t, dirs, "etc") |
| 2296 | ensureListContains(t, dirs, "etc/foo") |
| 2297 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2298 | ensureListContains(t, dirs, "lib64") |
| 2299 | ensureListContains(t, dirs, "lib64/foo") |
| 2300 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 2301 | ensureListContains(t, dirs, "lib") |
| 2302 | ensureListContains(t, dirs, "lib/foo") |
| 2303 | ensureListContains(t, dirs, "lib/foo/bar") |
| 2304 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 2305 | ensureListContains(t, dirs, "bin") |
| 2306 | ensureListContains(t, dirs, "bin/foo") |
| 2307 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2308 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2309 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2310 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
| 2311 | ctx, _ := testApex(t, ` |
| 2312 | apex { |
| 2313 | name: "myapex", |
| 2314 | key: "myapex.key", |
| 2315 | multilib: { |
| 2316 | both: { |
| 2317 | native_shared_libs: ["mylib"], |
| 2318 | binaries: ["mybin"], |
| 2319 | }, |
| 2320 | }, |
| 2321 | compile_multilib: "both", |
| 2322 | native_bridge_supported: true, |
| 2323 | } |
| 2324 | |
| 2325 | apex_key { |
| 2326 | name: "myapex.key", |
| 2327 | public_key: "testkey.avbpubkey", |
| 2328 | private_key: "testkey.pem", |
| 2329 | } |
| 2330 | |
| 2331 | cc_library { |
| 2332 | name: "mylib", |
| 2333 | relative_install_path: "foo/bar", |
| 2334 | system_shared_libs: [], |
| 2335 | stl: "none", |
| 2336 | apex_available: [ "myapex" ], |
| 2337 | native_bridge_supported: true, |
| 2338 | } |
| 2339 | |
| 2340 | cc_binary { |
| 2341 | name: "mybin", |
| 2342 | relative_install_path: "foo/bar", |
| 2343 | system_shared_libs: [], |
| 2344 | static_executable: true, |
| 2345 | stl: "none", |
| 2346 | apex_available: [ "myapex" ], |
| 2347 | native_bridge_supported: true, |
| 2348 | compile_multilib: "both", // default is "first" for binary |
| 2349 | multilib: { |
| 2350 | lib64: { |
| 2351 | suffix: "64", |
| 2352 | }, |
| 2353 | }, |
| 2354 | } |
| 2355 | `, withNativeBridgeEnabled) |
| 2356 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2357 | "bin/foo/bar/mybin", |
| 2358 | "bin/foo/bar/mybin64", |
| 2359 | "bin/arm/foo/bar/mybin", |
| 2360 | "bin/arm64/foo/bar/mybin64", |
| 2361 | "lib/foo/bar/mylib.so", |
| 2362 | "lib/arm/foo/bar/mylib.so", |
| 2363 | "lib64/foo/bar/mylib.so", |
| 2364 | "lib64/arm64/foo/bar/mylib.so", |
| 2365 | }) |
| 2366 | } |
| 2367 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2368 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2369 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2370 | apex { |
| 2371 | name: "myapex", |
| 2372 | key: "myapex.key", |
| 2373 | native_shared_libs: ["mylib"], |
| 2374 | use_vendor: true, |
| 2375 | } |
| 2376 | |
| 2377 | apex_key { |
| 2378 | name: "myapex.key", |
| 2379 | public_key: "testkey.avbpubkey", |
| 2380 | private_key: "testkey.pem", |
| 2381 | } |
| 2382 | |
| 2383 | cc_library { |
| 2384 | name: "mylib", |
| 2385 | srcs: ["mylib.cpp"], |
| 2386 | shared_libs: ["mylib2"], |
| 2387 | system_shared_libs: [], |
| 2388 | vendor_available: true, |
| 2389 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2390 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | cc_library { |
| 2394 | name: "mylib2", |
| 2395 | srcs: ["mylib.cpp"], |
| 2396 | system_shared_libs: [], |
| 2397 | vendor_available: true, |
| 2398 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2399 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2400 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2401 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2402 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2403 | }) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2404 | |
| 2405 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2406 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2407 | for _, implicit := range i.Implicits { |
| 2408 | inputsList = append(inputsList, implicit.String()) |
| 2409 | } |
| 2410 | } |
| 2411 | inputsString := strings.Join(inputsList, " ") |
| 2412 | |
| 2413 | // 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] | 2414 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2415 | 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] | 2416 | |
| 2417 | // ensure that the apex does not include core variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2418 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2419 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2420 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2421 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2422 | func TestUseVendorNotAllowedForSystemApexes(t *testing.T) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2423 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 2424 | apex { |
| 2425 | name: "myapex", |
| 2426 | key: "myapex.key", |
| 2427 | use_vendor: true, |
| 2428 | } |
| 2429 | apex_key { |
| 2430 | name: "myapex.key", |
| 2431 | public_key: "testkey.avbpubkey", |
| 2432 | private_key: "testkey.pem", |
| 2433 | } |
| 2434 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2435 | setUseVendorAllowListForTest(config, []string{""}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2436 | }) |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2437 | // no error with allow list |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2438 | testApex(t, ` |
| 2439 | apex { |
| 2440 | name: "myapex", |
| 2441 | key: "myapex.key", |
| 2442 | use_vendor: true, |
| 2443 | } |
| 2444 | apex_key { |
| 2445 | name: "myapex.key", |
| 2446 | public_key: "testkey.avbpubkey", |
| 2447 | private_key: "testkey.pem", |
| 2448 | } |
| 2449 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2450 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2451 | }) |
| 2452 | } |
| 2453 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2454 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 2455 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 2456 | apex { |
| 2457 | name: "myapex", |
| 2458 | key: "myapex.key", |
| 2459 | native_shared_libs: ["mylib"], |
| 2460 | use_vendor: true, |
| 2461 | } |
| 2462 | |
| 2463 | apex_key { |
| 2464 | name: "myapex.key", |
| 2465 | public_key: "testkey.avbpubkey", |
| 2466 | private_key: "testkey.pem", |
| 2467 | } |
| 2468 | |
| 2469 | cc_library { |
| 2470 | name: "mylib", |
| 2471 | srcs: ["mylib.cpp"], |
| 2472 | system_shared_libs: [], |
| 2473 | stl: "none", |
| 2474 | } |
| 2475 | `) |
| 2476 | } |
| 2477 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2478 | func TestVendorApex(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2479 | ctx, _ := testApex(t, ` |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2480 | apex { |
| 2481 | name: "myapex", |
| 2482 | key: "myapex.key", |
| 2483 | binaries: ["mybin"], |
| 2484 | vendor: true, |
| 2485 | } |
| 2486 | apex_key { |
| 2487 | name: "myapex.key", |
| 2488 | public_key: "testkey.avbpubkey", |
| 2489 | private_key: "testkey.pem", |
| 2490 | } |
| 2491 | cc_binary { |
| 2492 | name: "mybin", |
| 2493 | vendor: true, |
| 2494 | shared_libs: ["libfoo"], |
| 2495 | } |
| 2496 | cc_library { |
| 2497 | name: "libfoo", |
| 2498 | proprietary: true, |
| 2499 | } |
| 2500 | `) |
| 2501 | |
| 2502 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2503 | "bin/mybin", |
| 2504 | "lib64/libfoo.so", |
| 2505 | // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX |
| 2506 | "lib64/libc++.so", |
| 2507 | }) |
| 2508 | |
| 2509 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2510 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2511 | name := apexBundle.BaseModuleName() |
| 2512 | prefix := "TARGET_" |
| 2513 | var builder strings.Builder |
| 2514 | data.Custom(&builder, name, prefix, "", data) |
| 2515 | androidMk := builder.String() |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame^] | 2516 | installPath := path.Join(buildDir, "../target/product/test_device/vendor/apex") |
| 2517 | ensureContains(t, androidMk, "LOCAL_MODULE_PATH := "+installPath) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2518 | |
| 2519 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2520 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2521 | ensureListNotContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2522 | } |
| 2523 | |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2524 | func TestVendorApex_use_vndk_as_stable(t *testing.T) { |
| 2525 | ctx, _ := testApex(t, ` |
| 2526 | apex { |
| 2527 | name: "myapex", |
| 2528 | key: "myapex.key", |
| 2529 | binaries: ["mybin"], |
| 2530 | vendor: true, |
| 2531 | use_vndk_as_stable: true, |
| 2532 | } |
| 2533 | apex_key { |
| 2534 | name: "myapex.key", |
| 2535 | public_key: "testkey.avbpubkey", |
| 2536 | private_key: "testkey.pem", |
| 2537 | } |
| 2538 | cc_binary { |
| 2539 | name: "mybin", |
| 2540 | vendor: true, |
| 2541 | shared_libs: ["libvndk", "libvendor"], |
| 2542 | } |
| 2543 | cc_library { |
| 2544 | name: "libvndk", |
| 2545 | vndk: { |
| 2546 | enabled: true, |
| 2547 | }, |
| 2548 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2549 | product_available: true, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2550 | } |
| 2551 | cc_library { |
| 2552 | name: "libvendor", |
| 2553 | vendor: true, |
| 2554 | } |
| 2555 | `) |
| 2556 | |
| 2557 | vendorVariant := "android_vendor.VER_arm64_armv8-a" |
| 2558 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2559 | ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_apex10000").Rule("ld") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2560 | libs := names(ldRule.Args["libFlags"]) |
| 2561 | // VNDK libs(libvndk/libc++) as they are |
| 2562 | ensureListContains(t, libs, buildDir+"/.intermediates/libvndk/"+vendorVariant+"_shared/libvndk.so") |
| 2563 | ensureListContains(t, libs, buildDir+"/.intermediates/libc++/"+vendorVariant+"_shared/libc++.so") |
| 2564 | // non-stable Vendor libs as APEX variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2565 | ensureListContains(t, libs, buildDir+"/.intermediates/libvendor/"+vendorVariant+"_shared_apex10000/libvendor.so") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2566 | |
| 2567 | // VNDK libs are not included when use_vndk_as_stable: true |
| 2568 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2569 | "bin/mybin", |
| 2570 | "lib64/libvendor.so", |
| 2571 | }) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2572 | |
| 2573 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2574 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2575 | ensureListContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2576 | } |
| 2577 | |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2578 | func TestApex_withPrebuiltFirmware(t *testing.T) { |
| 2579 | testCases := []struct { |
| 2580 | name string |
| 2581 | additionalProp string |
| 2582 | }{ |
| 2583 | {"system apex with prebuilt_firmware", ""}, |
| 2584 | {"vendor apex with prebuilt_firmware", "vendor: true,"}, |
| 2585 | } |
| 2586 | for _, tc := range testCases { |
| 2587 | t.Run(tc.name, func(t *testing.T) { |
| 2588 | ctx, _ := testApex(t, ` |
| 2589 | apex { |
| 2590 | name: "myapex", |
| 2591 | key: "myapex.key", |
| 2592 | prebuilts: ["myfirmware"], |
| 2593 | `+tc.additionalProp+` |
| 2594 | } |
| 2595 | apex_key { |
| 2596 | name: "myapex.key", |
| 2597 | public_key: "testkey.avbpubkey", |
| 2598 | private_key: "testkey.pem", |
| 2599 | } |
| 2600 | prebuilt_firmware { |
| 2601 | name: "myfirmware", |
| 2602 | src: "myfirmware.bin", |
| 2603 | filename_from_src: true, |
| 2604 | `+tc.additionalProp+` |
| 2605 | } |
| 2606 | `) |
| 2607 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2608 | "etc/firmware/myfirmware.bin", |
| 2609 | }) |
| 2610 | }) |
| 2611 | } |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 2612 | } |
| 2613 | |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2614 | func TestAndroidMk_UseVendorRequired(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2615 | ctx, _ := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2616 | apex { |
| 2617 | name: "myapex", |
| 2618 | key: "myapex.key", |
| 2619 | use_vendor: true, |
| 2620 | native_shared_libs: ["mylib"], |
| 2621 | } |
| 2622 | |
| 2623 | apex_key { |
| 2624 | name: "myapex.key", |
| 2625 | public_key: "testkey.avbpubkey", |
| 2626 | private_key: "testkey.pem", |
| 2627 | } |
| 2628 | |
| 2629 | cc_library { |
| 2630 | name: "mylib", |
| 2631 | vendor_available: true, |
| 2632 | apex_available: ["myapex"], |
| 2633 | } |
| 2634 | `, func(fs map[string][]byte, config android.Config) { |
| 2635 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
| 2636 | }) |
| 2637 | |
| 2638 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2639 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2640 | name := apexBundle.BaseModuleName() |
| 2641 | prefix := "TARGET_" |
| 2642 | var builder strings.Builder |
| 2643 | data.Custom(&builder, name, prefix, "", data) |
| 2644 | androidMk := builder.String() |
| 2645 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc libm libdl\n") |
| 2646 | } |
| 2647 | |
| 2648 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2649 | ctx, _ := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2650 | apex { |
| 2651 | name: "myapex", |
| 2652 | key: "myapex.key", |
| 2653 | vendor: true, |
| 2654 | native_shared_libs: ["mylib"], |
| 2655 | } |
| 2656 | |
| 2657 | apex_key { |
| 2658 | name: "myapex.key", |
| 2659 | public_key: "testkey.avbpubkey", |
| 2660 | private_key: "testkey.pem", |
| 2661 | } |
| 2662 | |
| 2663 | cc_library { |
| 2664 | name: "mylib", |
| 2665 | vendor_available: true, |
| 2666 | } |
| 2667 | `) |
| 2668 | |
| 2669 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2670 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 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.vendor libm.vendor libdl.vendor\n") |
| 2677 | } |
| 2678 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2679 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2680 | ctx, _ := testApex(t, ` |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2681 | apex { |
| 2682 | name: "myapex", |
| 2683 | key: "myapex.key", |
| 2684 | vintf_fragments: ["fragment.xml"], |
| 2685 | init_rc: ["init.rc"], |
| 2686 | } |
| 2687 | apex_key { |
| 2688 | name: "myapex.key", |
| 2689 | public_key: "testkey.avbpubkey", |
| 2690 | private_key: "testkey.pem", |
| 2691 | } |
| 2692 | cc_binary { |
| 2693 | name: "mybin", |
| 2694 | } |
| 2695 | `) |
| 2696 | |
| 2697 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2698 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2699 | name := apexBundle.BaseModuleName() |
| 2700 | prefix := "TARGET_" |
| 2701 | var builder strings.Builder |
| 2702 | data.Custom(&builder, name, prefix, "", data) |
| 2703 | androidMk := builder.String() |
| 2704 | ensureContains(t, androidMk, "LOCAL_VINTF_FRAGMENTS := fragment.xml\n") |
| 2705 | ensureContains(t, androidMk, "LOCAL_INIT_RC := init.rc\n") |
| 2706 | } |
| 2707 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2708 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2709 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2710 | apex { |
| 2711 | name: "myapex", |
| 2712 | key: "myapex.key", |
| 2713 | native_shared_libs: ["mylib"], |
| 2714 | } |
| 2715 | |
| 2716 | apex_key { |
| 2717 | name: "myapex.key", |
| 2718 | public_key: "testkey.avbpubkey", |
| 2719 | private_key: "testkey.pem", |
| 2720 | } |
| 2721 | |
| 2722 | cc_library { |
| 2723 | name: "mylib", |
| 2724 | srcs: ["mylib.cpp"], |
| 2725 | system_shared_libs: [], |
| 2726 | stl: "none", |
| 2727 | stubs: { |
| 2728 | versions: ["1", "2", "3"], |
| 2729 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2730 | apex_available: [ |
| 2731 | "//apex_available:platform", |
| 2732 | "myapex", |
| 2733 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | cc_binary { |
| 2737 | name: "not_in_apex", |
| 2738 | srcs: ["mylib.cpp"], |
| 2739 | static_libs: ["mylib"], |
| 2740 | static_executable: true, |
| 2741 | system_shared_libs: [], |
| 2742 | stl: "none", |
| 2743 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2744 | `) |
| 2745 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2746 | 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] | 2747 | |
| 2748 | // 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] | 2749 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2750 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2751 | |
| 2752 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2753 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2754 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2755 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2756 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2757 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2758 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2759 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | cc_library { |
| 2763 | name: "mylib", |
| 2764 | srcs: ["mylib.cpp"], |
| 2765 | system_shared_libs: [], |
| 2766 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2767 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | apex_key { |
| 2771 | name: "myapex.key", |
| 2772 | public_key: "testkey.avbpubkey", |
| 2773 | private_key: "testkey.pem", |
| 2774 | } |
| 2775 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2776 | android_app_certificate { |
| 2777 | name: "myapex.certificate", |
| 2778 | certificate: "testkey", |
| 2779 | } |
| 2780 | |
| 2781 | android_app_certificate { |
| 2782 | name: "myapex.certificate.override", |
| 2783 | certificate: "testkey.override", |
| 2784 | } |
| 2785 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2786 | `) |
| 2787 | |
| 2788 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2789 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2790 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2791 | if keys.publicKeyFile.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 2792 | t.Errorf("public key %q is not %q", keys.publicKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2793 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 2794 | } |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2795 | if keys.privateKeyFile.String() != "vendor/foo/devkeys/testkey.pem" { |
| 2796 | t.Errorf("private key %q is not %q", keys.privateKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2797 | "vendor/foo/devkeys/testkey.pem") |
| 2798 | } |
| 2799 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2800 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2801 | 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] | 2802 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2803 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2804 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2805 | } |
| 2806 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2807 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2808 | func TestCertificate(t *testing.T) { |
| 2809 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 2810 | ctx, _ := testApex(t, ` |
| 2811 | apex { |
| 2812 | name: "myapex", |
| 2813 | key: "myapex.key", |
| 2814 | } |
| 2815 | apex_key { |
| 2816 | name: "myapex.key", |
| 2817 | public_key: "testkey.avbpubkey", |
| 2818 | private_key: "testkey.pem", |
| 2819 | }`) |
| 2820 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2821 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 2822 | if actual := rule.Args["certificates"]; actual != expected { |
| 2823 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2824 | } |
| 2825 | }) |
| 2826 | t.Run("override when unspecified", func(t *testing.T) { |
| 2827 | ctx, _ := testApex(t, ` |
| 2828 | apex { |
| 2829 | name: "myapex_keytest", |
| 2830 | key: "myapex.key", |
| 2831 | file_contexts: ":myapex-file_contexts", |
| 2832 | } |
| 2833 | apex_key { |
| 2834 | name: "myapex.key", |
| 2835 | public_key: "testkey.avbpubkey", |
| 2836 | private_key: "testkey.pem", |
| 2837 | } |
| 2838 | android_app_certificate { |
| 2839 | name: "myapex.certificate.override", |
| 2840 | certificate: "testkey.override", |
| 2841 | }`) |
| 2842 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2843 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2844 | if actual := rule.Args["certificates"]; actual != expected { |
| 2845 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2846 | } |
| 2847 | }) |
| 2848 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 2849 | ctx, _ := testApex(t, ` |
| 2850 | apex { |
| 2851 | name: "myapex", |
| 2852 | key: "myapex.key", |
| 2853 | certificate: ":myapex.certificate", |
| 2854 | } |
| 2855 | apex_key { |
| 2856 | name: "myapex.key", |
| 2857 | public_key: "testkey.avbpubkey", |
| 2858 | private_key: "testkey.pem", |
| 2859 | } |
| 2860 | android_app_certificate { |
| 2861 | name: "myapex.certificate", |
| 2862 | certificate: "testkey", |
| 2863 | }`) |
| 2864 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2865 | expected := "testkey.x509.pem testkey.pk8" |
| 2866 | if actual := rule.Args["certificates"]; actual != expected { |
| 2867 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2868 | } |
| 2869 | }) |
| 2870 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 2871 | ctx, _ := testApex(t, ` |
| 2872 | apex { |
| 2873 | name: "myapex_keytest", |
| 2874 | key: "myapex.key", |
| 2875 | file_contexts: ":myapex-file_contexts", |
| 2876 | certificate: ":myapex.certificate", |
| 2877 | } |
| 2878 | apex_key { |
| 2879 | name: "myapex.key", |
| 2880 | public_key: "testkey.avbpubkey", |
| 2881 | private_key: "testkey.pem", |
| 2882 | } |
| 2883 | android_app_certificate { |
| 2884 | name: "myapex.certificate.override", |
| 2885 | certificate: "testkey.override", |
| 2886 | }`) |
| 2887 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2888 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2889 | if actual := rule.Args["certificates"]; actual != expected { |
| 2890 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2891 | } |
| 2892 | }) |
| 2893 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 2894 | ctx, _ := testApex(t, ` |
| 2895 | apex { |
| 2896 | name: "myapex", |
| 2897 | key: "myapex.key", |
| 2898 | certificate: "testkey", |
| 2899 | } |
| 2900 | apex_key { |
| 2901 | name: "myapex.key", |
| 2902 | public_key: "testkey.avbpubkey", |
| 2903 | private_key: "testkey.pem", |
| 2904 | }`) |
| 2905 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2906 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 2907 | if actual := rule.Args["certificates"]; actual != expected { |
| 2908 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2909 | } |
| 2910 | }) |
| 2911 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 2912 | ctx, _ := testApex(t, ` |
| 2913 | apex { |
| 2914 | name: "myapex_keytest", |
| 2915 | key: "myapex.key", |
| 2916 | file_contexts: ":myapex-file_contexts", |
| 2917 | certificate: "testkey", |
| 2918 | } |
| 2919 | apex_key { |
| 2920 | name: "myapex.key", |
| 2921 | public_key: "testkey.avbpubkey", |
| 2922 | private_key: "testkey.pem", |
| 2923 | } |
| 2924 | android_app_certificate { |
| 2925 | name: "myapex.certificate.override", |
| 2926 | certificate: "testkey.override", |
| 2927 | }`) |
| 2928 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2929 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2930 | if actual := rule.Args["certificates"]; actual != expected { |
| 2931 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2932 | } |
| 2933 | }) |
| 2934 | } |
| 2935 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2936 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2937 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2938 | apex { |
| 2939 | name: "myapex", |
| 2940 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2941 | native_shared_libs: ["mylib", "mylib2"], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | apex { |
| 2945 | name: "otherapex", |
| 2946 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2947 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2948 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2949 | } |
| 2950 | |
| 2951 | apex_key { |
| 2952 | name: "myapex.key", |
| 2953 | public_key: "testkey.avbpubkey", |
| 2954 | private_key: "testkey.pem", |
| 2955 | } |
| 2956 | |
| 2957 | cc_library { |
| 2958 | name: "mylib", |
| 2959 | srcs: ["mylib.cpp"], |
| 2960 | system_shared_libs: [], |
| 2961 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2962 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2963 | "myapex", |
| 2964 | "otherapex", |
| 2965 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2966 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2967 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2968 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2969 | cc_library { |
| 2970 | name: "mylib2", |
| 2971 | srcs: ["mylib.cpp"], |
| 2972 | system_shared_libs: [], |
| 2973 | stl: "none", |
| 2974 | apex_available: [ |
| 2975 | "myapex", |
| 2976 | "otherapex", |
| 2977 | ], |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2978 | static_libs: ["mylib3"], |
| 2979 | recovery_available: true, |
| 2980 | min_sdk_version: "29", |
| 2981 | } |
| 2982 | cc_library { |
| 2983 | name: "mylib3", |
| 2984 | srcs: ["mylib.cpp"], |
| 2985 | system_shared_libs: [], |
| 2986 | stl: "none", |
| 2987 | apex_available: [ |
| 2988 | "myapex", |
| 2989 | "otherapex", |
| 2990 | ], |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2991 | use_apex_name_macro: true, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2992 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2993 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2994 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2995 | `) |
| 2996 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2997 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2998 | 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] | 2999 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3000 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3001 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3002 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3003 | 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] | 3004 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3005 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3006 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3007 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3008 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3009 | 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] | 3010 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3011 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3012 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3013 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3014 | // When a cc_library sets use_apex_name_macro: true each apex gets a unique variant and |
| 3015 | // each variant defines additional macros to distinguish which apex variant it is built for |
| 3016 | |
| 3017 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3018 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3019 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3020 | |
| 3021 | // APEX variant has __ANDROID_APEX__ defined |
| 3022 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 3023 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3024 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3025 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3026 | |
| 3027 | // APEX variant has __ANDROID_APEX__ defined |
| 3028 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 3029 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3030 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3031 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3032 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3033 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3034 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3035 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3036 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3037 | |
| 3038 | // When a dependency of a cc_library sets use_apex_name_macro: true each apex gets a unique |
| 3039 | // variant. |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3040 | |
| 3041 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3042 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3043 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3044 | |
| 3045 | // APEX variant has __ANDROID_APEX__ defined |
| 3046 | 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] | 3047 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3048 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3049 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3050 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3051 | // APEX variant has __ANDROID_APEX__ defined |
| 3052 | 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] | 3053 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3054 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3055 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3056 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3057 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3058 | 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] | 3059 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3060 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3061 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3062 | |
| 3063 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3064 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3065 | apex { |
| 3066 | name: "myapex", |
| 3067 | key: "myapex.key", |
| 3068 | native_shared_libs: ["mylib"], |
| 3069 | } |
| 3070 | |
| 3071 | apex_key { |
| 3072 | name: "myapex.key", |
| 3073 | public_key: "testkey.avbpubkey", |
| 3074 | private_key: "testkey.pem", |
| 3075 | } |
| 3076 | |
| 3077 | cc_library_headers { |
| 3078 | name: "mylib_headers", |
| 3079 | export_include_dirs: ["my_include"], |
| 3080 | system_shared_libs: [], |
| 3081 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3082 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | cc_library { |
| 3086 | name: "mylib", |
| 3087 | srcs: ["mylib.cpp"], |
| 3088 | system_shared_libs: [], |
| 3089 | stl: "none", |
| 3090 | header_libs: ["mylib_headers"], |
| 3091 | export_header_lib_headers: ["mylib_headers"], |
| 3092 | stubs: { |
| 3093 | versions: ["1", "2", "3"], |
| 3094 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3095 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | cc_library { |
| 3099 | name: "otherlib", |
| 3100 | srcs: ["mylib.cpp"], |
| 3101 | system_shared_libs: [], |
| 3102 | stl: "none", |
| 3103 | shared_libs: ["mylib"], |
| 3104 | } |
| 3105 | `) |
| 3106 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3107 | 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] | 3108 | |
| 3109 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 3110 | ensureContains(t, cFlags, "-Imy_include") |
| 3111 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3112 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3113 | type fileInApex struct { |
| 3114 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3115 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3116 | isLink bool |
| 3117 | } |
| 3118 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3119 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3120 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3121 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3122 | copyCmds := apexRule.Args["copy_commands"] |
| 3123 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3124 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3125 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 3126 | cmd = strings.TrimSpace(cmd) |
| 3127 | if cmd == "" { |
| 3128 | continue |
| 3129 | } |
| 3130 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3131 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3132 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3133 | switch terms[0] { |
| 3134 | case "mkdir": |
| 3135 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3136 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3137 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 3138 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3139 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3140 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3141 | isLink = false |
| 3142 | case "ln": |
| 3143 | if len(terms) != 3 && len(terms) != 4 { |
| 3144 | // ln LINK TARGET or ln -s LINK TARGET |
| 3145 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 3146 | } |
| 3147 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3148 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3149 | isLink = true |
| 3150 | default: |
| 3151 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 3152 | } |
| 3153 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3154 | index := strings.Index(dst, imageApexDir) |
| 3155 | if index == -1 { |
| 3156 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 3157 | } |
| 3158 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3159 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3160 | } |
| 3161 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3162 | return ret |
| 3163 | } |
| 3164 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3165 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 3166 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3167 | var failed bool |
| 3168 | var surplus []string |
| 3169 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3170 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3171 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3172 | for _, expected := range files { |
| 3173 | if matched, _ := path.Match(expected, file.path); matched { |
| 3174 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3175 | mactchFound = true |
| 3176 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3177 | } |
| 3178 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3179 | if !mactchFound { |
| 3180 | surplus = append(surplus, file.path) |
| 3181 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3182 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3183 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3184 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3185 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3186 | t.Log("surplus files", surplus) |
| 3187 | failed = true |
| 3188 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3189 | |
| 3190 | if len(files) > len(filesMatched) { |
| 3191 | var missing []string |
| 3192 | for _, expected := range files { |
| 3193 | if !filesMatched[expected] { |
| 3194 | missing = append(missing, expected) |
| 3195 | } |
| 3196 | } |
| 3197 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3198 | t.Log("missing files", missing) |
| 3199 | failed = true |
| 3200 | } |
| 3201 | if failed { |
| 3202 | t.Fail() |
| 3203 | } |
| 3204 | } |
| 3205 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3206 | func TestVndkApexCurrent(t *testing.T) { |
| 3207 | ctx, _ := testApex(t, ` |
| 3208 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3209 | name: "com.android.vndk.current", |
| 3210 | key: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3214 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3215 | public_key: "testkey.avbpubkey", |
| 3216 | private_key: "testkey.pem", |
| 3217 | } |
| 3218 | |
| 3219 | cc_library { |
| 3220 | name: "libvndk", |
| 3221 | srcs: ["mylib.cpp"], |
| 3222 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3223 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3224 | vndk: { |
| 3225 | enabled: true, |
| 3226 | }, |
| 3227 | system_shared_libs: [], |
| 3228 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3229 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | cc_library { |
| 3233 | name: "libvndksp", |
| 3234 | srcs: ["mylib.cpp"], |
| 3235 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3236 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3237 | vndk: { |
| 3238 | enabled: true, |
| 3239 | support_system_process: true, |
| 3240 | }, |
| 3241 | system_shared_libs: [], |
| 3242 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3243 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3244 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3245 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3246 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3247 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3248 | "lib/libvndk.so", |
| 3249 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3250 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3251 | "lib64/libvndk.so", |
| 3252 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3253 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3254 | "etc/llndk.libraries.VER.txt", |
| 3255 | "etc/vndkcore.libraries.VER.txt", |
| 3256 | "etc/vndksp.libraries.VER.txt", |
| 3257 | "etc/vndkprivate.libraries.VER.txt", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3258 | "etc/vndkproduct.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3259 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3260 | } |
| 3261 | |
| 3262 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 3263 | ctx, _ := testApex(t, ` |
| 3264 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3265 | name: "com.android.vndk.current", |
| 3266 | key: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3270 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3271 | public_key: "testkey.avbpubkey", |
| 3272 | private_key: "testkey.pem", |
| 3273 | } |
| 3274 | |
| 3275 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3276 | name: "libvndk", |
| 3277 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3278 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3279 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3280 | vndk: { |
| 3281 | enabled: true, |
| 3282 | }, |
| 3283 | system_shared_libs: [], |
| 3284 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3285 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3286 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3287 | |
| 3288 | cc_prebuilt_library_shared { |
| 3289 | name: "libvndk.arm", |
| 3290 | srcs: ["libvndk.arm.so"], |
| 3291 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3292 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3293 | vndk: { |
| 3294 | enabled: true, |
| 3295 | }, |
| 3296 | enabled: false, |
| 3297 | arch: { |
| 3298 | arm: { |
| 3299 | enabled: true, |
| 3300 | }, |
| 3301 | }, |
| 3302 | system_shared_libs: [], |
| 3303 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3304 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3305 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3306 | `+vndkLibrariesTxtFiles("current"), |
| 3307 | withFiles(map[string][]byte{ |
| 3308 | "libvndk.so": nil, |
| 3309 | "libvndk.arm.so": nil, |
| 3310 | })) |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3311 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3312 | "lib/libvndk.so", |
| 3313 | "lib/libvndk.arm.so", |
| 3314 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3315 | "lib/libc++.so", |
| 3316 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3317 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3318 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3319 | } |
| 3320 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3321 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 3322 | for _, v := range vers { |
| 3323 | if v == "current" { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3324 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3325 | result += ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 3326 | ` + txt + `_libraries_txt { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3327 | name: "` + txt + `.libraries.txt", |
| 3328 | } |
| 3329 | ` |
| 3330 | } |
| 3331 | } else { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3332 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3333 | result += ` |
| 3334 | prebuilt_etc { |
| 3335 | name: "` + txt + `.libraries.` + v + `.txt", |
| 3336 | src: "dummy.txt", |
| 3337 | } |
| 3338 | ` |
| 3339 | } |
| 3340 | } |
| 3341 | } |
| 3342 | return |
| 3343 | } |
| 3344 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3345 | func TestVndkApexVersion(t *testing.T) { |
| 3346 | ctx, _ := testApex(t, ` |
| 3347 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3348 | name: "com.android.vndk.v27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3349 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3350 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3351 | vndk_version: "27", |
| 3352 | } |
| 3353 | |
| 3354 | apex_key { |
| 3355 | name: "myapex.key", |
| 3356 | public_key: "testkey.avbpubkey", |
| 3357 | private_key: "testkey.pem", |
| 3358 | } |
| 3359 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3360 | vndk_prebuilt_shared { |
| 3361 | name: "libvndk27", |
| 3362 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3363 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3364 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3365 | vndk: { |
| 3366 | enabled: true, |
| 3367 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3368 | target_arch: "arm64", |
| 3369 | arch: { |
| 3370 | arm: { |
| 3371 | srcs: ["libvndk27_arm.so"], |
| 3372 | }, |
| 3373 | arm64: { |
| 3374 | srcs: ["libvndk27_arm64.so"], |
| 3375 | }, |
| 3376 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3377 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | vndk_prebuilt_shared { |
| 3381 | name: "libvndk27", |
| 3382 | version: "27", |
| 3383 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3384 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3385 | vndk: { |
| 3386 | enabled: true, |
| 3387 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3388 | target_arch: "x86_64", |
| 3389 | arch: { |
| 3390 | x86: { |
| 3391 | srcs: ["libvndk27_x86.so"], |
| 3392 | }, |
| 3393 | x86_64: { |
| 3394 | srcs: ["libvndk27_x86_64.so"], |
| 3395 | }, |
| 3396 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3397 | } |
| 3398 | `+vndkLibrariesTxtFiles("27"), |
| 3399 | withFiles(map[string][]byte{ |
| 3400 | "libvndk27_arm.so": nil, |
| 3401 | "libvndk27_arm64.so": nil, |
| 3402 | "libvndk27_x86.so": nil, |
| 3403 | "libvndk27_x86_64.so": nil, |
| 3404 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3405 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3406 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3407 | "lib/libvndk27_arm.so", |
| 3408 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3409 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3410 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3411 | } |
| 3412 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3413 | func TestVndkApexNameRule(t *testing.T) { |
| 3414 | ctx, _ := testApex(t, ` |
| 3415 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3416 | name: "com.android.vndk.current", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3417 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3418 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3419 | } |
| 3420 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3421 | name: "com.android.vndk.v28", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3422 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3423 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3424 | vndk_version: "28", |
| 3425 | } |
| 3426 | apex_key { |
| 3427 | name: "myapex.key", |
| 3428 | public_key: "testkey.avbpubkey", |
| 3429 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3430 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3431 | |
| 3432 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3433 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3434 | actual := proptools.String(bundle.properties.Apex_name) |
| 3435 | if !reflect.DeepEqual(actual, expected) { |
| 3436 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3437 | } |
| 3438 | } |
| 3439 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3440 | assertApexName("com.android.vndk.vVER", "com.android.vndk.current") |
| 3441 | assertApexName("com.android.vndk.v28", "com.android.vndk.v28") |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3442 | } |
| 3443 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3444 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 3445 | ctx, _ := testApex(t, ` |
| 3446 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3447 | name: "com.android.vndk.current", |
| 3448 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3449 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3453 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3454 | public_key: "testkey.avbpubkey", |
| 3455 | private_key: "testkey.pem", |
| 3456 | } |
| 3457 | |
| 3458 | cc_library { |
| 3459 | name: "libvndk", |
| 3460 | srcs: ["mylib.cpp"], |
| 3461 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3462 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3463 | native_bridge_supported: true, |
| 3464 | host_supported: true, |
| 3465 | vndk: { |
| 3466 | enabled: true, |
| 3467 | }, |
| 3468 | system_shared_libs: [], |
| 3469 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3470 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3471 | } |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3472 | `+vndkLibrariesTxtFiles("current"), |
| 3473 | withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3474 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3475 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3476 | "lib/libvndk.so", |
| 3477 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3478 | "lib/libc++.so", |
| 3479 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3480 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3481 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3485 | testApexError(t, `module "com.android.vndk.current" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3486 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3487 | name: "com.android.vndk.current", |
| 3488 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3489 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3490 | native_bridge_supported: true, |
| 3491 | } |
| 3492 | |
| 3493 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3494 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3495 | public_key: "testkey.avbpubkey", |
| 3496 | private_key: "testkey.pem", |
| 3497 | } |
| 3498 | |
| 3499 | cc_library { |
| 3500 | name: "libvndk", |
| 3501 | srcs: ["mylib.cpp"], |
| 3502 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3503 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3504 | native_bridge_supported: true, |
| 3505 | host_supported: true, |
| 3506 | vndk: { |
| 3507 | enabled: true, |
| 3508 | }, |
| 3509 | system_shared_libs: [], |
| 3510 | stl: "none", |
| 3511 | } |
| 3512 | `) |
| 3513 | } |
| 3514 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3515 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3516 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3517 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3518 | name: "com.android.vndk.v27", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3519 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3520 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3521 | vndk_version: "27", |
| 3522 | } |
| 3523 | |
| 3524 | apex_key { |
| 3525 | name: "myapex.key", |
| 3526 | public_key: "testkey.avbpubkey", |
| 3527 | private_key: "testkey.pem", |
| 3528 | } |
| 3529 | |
| 3530 | vndk_prebuilt_shared { |
| 3531 | name: "libvndk27", |
| 3532 | version: "27", |
| 3533 | target_arch: "arm", |
| 3534 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3535 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3536 | vndk: { |
| 3537 | enabled: true, |
| 3538 | }, |
| 3539 | arch: { |
| 3540 | arm: { |
| 3541 | srcs: ["libvndk27.so"], |
| 3542 | } |
| 3543 | }, |
| 3544 | } |
| 3545 | |
| 3546 | vndk_prebuilt_shared { |
| 3547 | name: "libvndk27", |
| 3548 | version: "27", |
| 3549 | target_arch: "arm", |
| 3550 | binder32bit: true, |
| 3551 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3552 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3553 | vndk: { |
| 3554 | enabled: true, |
| 3555 | }, |
| 3556 | arch: { |
| 3557 | arm: { |
| 3558 | srcs: ["libvndk27binder32.so"], |
| 3559 | } |
| 3560 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3561 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3562 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3563 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3564 | withFiles(map[string][]byte{ |
| 3565 | "libvndk27.so": nil, |
| 3566 | "libvndk27binder32.so": nil, |
| 3567 | }), |
| 3568 | withBinder32bit, |
| 3569 | withTargets(map[android.OsType][]android.Target{ |
| 3570 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3571 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3572 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3573 | }, |
| 3574 | }), |
| 3575 | ) |
| 3576 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3577 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3578 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3579 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3580 | }) |
| 3581 | } |
| 3582 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3583 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
| 3584 | ctx, _ := testApex(t, ` |
| 3585 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3586 | name: "com.android.vndk.current", |
| 3587 | key: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3588 | file_contexts: ":myapex-file_contexts", |
| 3589 | } |
| 3590 | |
| 3591 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3592 | name: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3593 | public_key: "testkey.avbpubkey", |
| 3594 | private_key: "testkey.pem", |
| 3595 | } |
| 3596 | |
| 3597 | cc_library { |
| 3598 | name: "libz", |
| 3599 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3600 | product_available: true, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3601 | vndk: { |
| 3602 | enabled: true, |
| 3603 | }, |
| 3604 | stubs: { |
| 3605 | symbol_file: "libz.map.txt", |
| 3606 | versions: ["30"], |
| 3607 | } |
| 3608 | } |
| 3609 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3610 | "libz.map.txt": nil, |
| 3611 | })) |
| 3612 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3613 | apexManifestRule := ctx.ModuleForTests("com.android.vndk.current", "android_common_image").Rule("apexManifestRule") |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3614 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3615 | ensureListEmpty(t, provideNativeLibs) |
| 3616 | } |
| 3617 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3618 | func TestDependenciesInApexManifest(t *testing.T) { |
| 3619 | ctx, _ := testApex(t, ` |
| 3620 | apex { |
| 3621 | name: "myapex_nodep", |
| 3622 | key: "myapex.key", |
| 3623 | native_shared_libs: ["lib_nodep"], |
| 3624 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3625 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | apex { |
| 3629 | name: "myapex_dep", |
| 3630 | key: "myapex.key", |
| 3631 | native_shared_libs: ["lib_dep"], |
| 3632 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3633 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3634 | } |
| 3635 | |
| 3636 | apex { |
| 3637 | name: "myapex_provider", |
| 3638 | key: "myapex.key", |
| 3639 | native_shared_libs: ["libfoo"], |
| 3640 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3641 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | apex { |
| 3645 | name: "myapex_selfcontained", |
| 3646 | key: "myapex.key", |
| 3647 | native_shared_libs: ["lib_dep", "libfoo"], |
| 3648 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3649 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | apex_key { |
| 3653 | name: "myapex.key", |
| 3654 | public_key: "testkey.avbpubkey", |
| 3655 | private_key: "testkey.pem", |
| 3656 | } |
| 3657 | |
| 3658 | cc_library { |
| 3659 | name: "lib_nodep", |
| 3660 | srcs: ["mylib.cpp"], |
| 3661 | system_shared_libs: [], |
| 3662 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3663 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | cc_library { |
| 3667 | name: "lib_dep", |
| 3668 | srcs: ["mylib.cpp"], |
| 3669 | shared_libs: ["libfoo"], |
| 3670 | system_shared_libs: [], |
| 3671 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3672 | apex_available: [ |
| 3673 | "myapex_dep", |
| 3674 | "myapex_provider", |
| 3675 | "myapex_selfcontained", |
| 3676 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | cc_library { |
| 3680 | name: "libfoo", |
| 3681 | srcs: ["mytest.cpp"], |
| 3682 | stubs: { |
| 3683 | versions: ["1"], |
| 3684 | }, |
| 3685 | system_shared_libs: [], |
| 3686 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3687 | apex_available: [ |
| 3688 | "myapex_provider", |
| 3689 | "myapex_selfcontained", |
| 3690 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3691 | } |
| 3692 | `) |
| 3693 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3694 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3695 | var provideNativeLibs, requireNativeLibs []string |
| 3696 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3697 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3698 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3699 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3700 | ensureListEmpty(t, provideNativeLibs) |
| 3701 | ensureListEmpty(t, requireNativeLibs) |
| 3702 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3703 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3704 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3705 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3706 | ensureListEmpty(t, provideNativeLibs) |
| 3707 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 3708 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3709 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3710 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3711 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3712 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3713 | ensureListEmpty(t, requireNativeLibs) |
| 3714 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3715 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3716 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3717 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3718 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3719 | ensureListEmpty(t, requireNativeLibs) |
| 3720 | } |
| 3721 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3722 | func TestApexName(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3723 | ctx, _ := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3724 | apex { |
| 3725 | name: "myapex", |
| 3726 | key: "myapex.key", |
| 3727 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3728 | native_shared_libs: ["mylib"], |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | apex_key { |
| 3732 | name: "myapex.key", |
| 3733 | public_key: "testkey.avbpubkey", |
| 3734 | private_key: "testkey.pem", |
| 3735 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3736 | |
| 3737 | cc_library { |
| 3738 | name: "mylib", |
| 3739 | srcs: ["mylib.cpp"], |
| 3740 | system_shared_libs: [], |
| 3741 | stl: "none", |
| 3742 | apex_available: [ |
| 3743 | "//apex_available:platform", |
| 3744 | "myapex", |
| 3745 | ], |
| 3746 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3747 | `) |
| 3748 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3749 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3750 | apexManifestRule := module.Rule("apexManifestRule") |
| 3751 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 3752 | apexRule := module.Rule("apexRule") |
| 3753 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3754 | |
| 3755 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3756 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3757 | name := apexBundle.BaseModuleName() |
| 3758 | prefix := "TARGET_" |
| 3759 | var builder strings.Builder |
| 3760 | data.Custom(&builder, name, prefix, "", data) |
| 3761 | androidMk := builder.String() |
| 3762 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 3763 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3764 | } |
| 3765 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3766 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3767 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3768 | apex { |
| 3769 | name: "myapex", |
| 3770 | key: "myapex.key", |
| 3771 | native_shared_libs: ["mylib_common"], |
| 3772 | } |
| 3773 | |
| 3774 | apex_key { |
| 3775 | name: "myapex.key", |
| 3776 | public_key: "testkey.avbpubkey", |
| 3777 | private_key: "testkey.pem", |
| 3778 | } |
| 3779 | |
| 3780 | cc_library { |
| 3781 | name: "mylib_common", |
| 3782 | srcs: ["mylib.cpp"], |
| 3783 | system_shared_libs: [], |
| 3784 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3785 | apex_available: [ |
| 3786 | "//apex_available:platform", |
| 3787 | "myapex", |
| 3788 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3789 | } |
| 3790 | `) |
| 3791 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3792 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3793 | apexRule := module.Rule("apexRule") |
| 3794 | copyCmds := apexRule.Args["copy_commands"] |
| 3795 | |
| 3796 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 3797 | t.Log("Apex was a test apex!") |
| 3798 | t.Fail() |
| 3799 | } |
| 3800 | // Ensure that main rule creates an output |
| 3801 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3802 | |
| 3803 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3804 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3805 | |
| 3806 | // Ensure that both direct and indirect deps are copied into apex |
| 3807 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3808 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3809 | // Ensure that the platform variant ends with _shared |
| 3810 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3811 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3812 | 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] | 3813 | t.Log("Found mylib_common not in any apex!") |
| 3814 | t.Fail() |
| 3815 | } |
| 3816 | } |
| 3817 | |
| 3818 | func TestTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3819 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3820 | apex_test { |
| 3821 | name: "myapex", |
| 3822 | key: "myapex.key", |
| 3823 | native_shared_libs: ["mylib_common_test"], |
| 3824 | } |
| 3825 | |
| 3826 | apex_key { |
| 3827 | name: "myapex.key", |
| 3828 | public_key: "testkey.avbpubkey", |
| 3829 | private_key: "testkey.pem", |
| 3830 | } |
| 3831 | |
| 3832 | cc_library { |
| 3833 | name: "mylib_common_test", |
| 3834 | srcs: ["mylib.cpp"], |
| 3835 | system_shared_libs: [], |
| 3836 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3837 | // TODO: remove //apex_available:platform |
| 3838 | apex_available: [ |
| 3839 | "//apex_available:platform", |
| 3840 | "myapex", |
| 3841 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3842 | } |
| 3843 | `) |
| 3844 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3845 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3846 | apexRule := module.Rule("apexRule") |
| 3847 | copyCmds := apexRule.Args["copy_commands"] |
| 3848 | |
| 3849 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 3850 | t.Log("Apex was not a test apex!") |
| 3851 | t.Fail() |
| 3852 | } |
| 3853 | // Ensure that main rule creates an output |
| 3854 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3855 | |
| 3856 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3857 | 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] | 3858 | |
| 3859 | // Ensure that both direct and indirect deps are copied into apex |
| 3860 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 3861 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3862 | // Ensure that the platform variant ends with _shared |
| 3863 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3864 | } |
| 3865 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3866 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3867 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3868 | apex { |
| 3869 | name: "myapex", |
| 3870 | key: "myapex.key", |
| 3871 | multilib: { |
| 3872 | first: { |
| 3873 | native_shared_libs: ["mylib_common"], |
| 3874 | } |
| 3875 | }, |
| 3876 | target: { |
| 3877 | android: { |
| 3878 | multilib: { |
| 3879 | first: { |
| 3880 | native_shared_libs: ["mylib"], |
| 3881 | } |
| 3882 | } |
| 3883 | }, |
| 3884 | host: { |
| 3885 | multilib: { |
| 3886 | first: { |
| 3887 | native_shared_libs: ["mylib2"], |
| 3888 | } |
| 3889 | } |
| 3890 | } |
| 3891 | } |
| 3892 | } |
| 3893 | |
| 3894 | apex_key { |
| 3895 | name: "myapex.key", |
| 3896 | public_key: "testkey.avbpubkey", |
| 3897 | private_key: "testkey.pem", |
| 3898 | } |
| 3899 | |
| 3900 | cc_library { |
| 3901 | name: "mylib", |
| 3902 | srcs: ["mylib.cpp"], |
| 3903 | system_shared_libs: [], |
| 3904 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3905 | // TODO: remove //apex_available:platform |
| 3906 | apex_available: [ |
| 3907 | "//apex_available:platform", |
| 3908 | "myapex", |
| 3909 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3910 | } |
| 3911 | |
| 3912 | cc_library { |
| 3913 | name: "mylib_common", |
| 3914 | srcs: ["mylib.cpp"], |
| 3915 | system_shared_libs: [], |
| 3916 | stl: "none", |
| 3917 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3918 | // TODO: remove //apex_available:platform |
| 3919 | apex_available: [ |
| 3920 | "//apex_available:platform", |
| 3921 | "myapex", |
| 3922 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | cc_library { |
| 3926 | name: "mylib2", |
| 3927 | srcs: ["mylib.cpp"], |
| 3928 | system_shared_libs: [], |
| 3929 | stl: "none", |
| 3930 | compile_multilib: "first", |
| 3931 | } |
| 3932 | `) |
| 3933 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3934 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3935 | copyCmds := apexRule.Args["copy_commands"] |
| 3936 | |
| 3937 | // Ensure that main rule creates an output |
| 3938 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3939 | |
| 3940 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3941 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 3942 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
| 3943 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3944 | |
| 3945 | // Ensure that both direct and indirect deps are copied into apex |
| 3946 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 3947 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3948 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 3949 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3950 | // Ensure that the platform variant ends with _shared |
| 3951 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 3952 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 3953 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3954 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3955 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 3956 | func TestApexWithArch(t *testing.T) { |
| 3957 | ctx, _ := testApex(t, ` |
| 3958 | apex { |
| 3959 | name: "myapex", |
| 3960 | key: "myapex.key", |
| 3961 | arch: { |
| 3962 | arm64: { |
| 3963 | native_shared_libs: ["mylib.arm64"], |
| 3964 | }, |
| 3965 | x86_64: { |
| 3966 | native_shared_libs: ["mylib.x64"], |
| 3967 | }, |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | apex_key { |
| 3972 | name: "myapex.key", |
| 3973 | public_key: "testkey.avbpubkey", |
| 3974 | private_key: "testkey.pem", |
| 3975 | } |
| 3976 | |
| 3977 | cc_library { |
| 3978 | name: "mylib.arm64", |
| 3979 | srcs: ["mylib.cpp"], |
| 3980 | system_shared_libs: [], |
| 3981 | stl: "none", |
| 3982 | // TODO: remove //apex_available:platform |
| 3983 | apex_available: [ |
| 3984 | "//apex_available:platform", |
| 3985 | "myapex", |
| 3986 | ], |
| 3987 | } |
| 3988 | |
| 3989 | cc_library { |
| 3990 | name: "mylib.x64", |
| 3991 | srcs: ["mylib.cpp"], |
| 3992 | system_shared_libs: [], |
| 3993 | stl: "none", |
| 3994 | // TODO: remove //apex_available:platform |
| 3995 | apex_available: [ |
| 3996 | "//apex_available:platform", |
| 3997 | "myapex", |
| 3998 | ], |
| 3999 | } |
| 4000 | `) |
| 4001 | |
| 4002 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 4003 | copyCmds := apexRule.Args["copy_commands"] |
| 4004 | |
| 4005 | // Ensure that apex variant is created for the direct dep |
| 4006 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib.arm64"), "android_arm64_armv8-a_shared_apex10000") |
| 4007 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib.x64"), "android_arm64_armv8-a_shared_apex10000") |
| 4008 | |
| 4009 | // Ensure that both direct and indirect deps are copied into apex |
| 4010 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.arm64.so") |
| 4011 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib.x64.so") |
| 4012 | } |
| 4013 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4014 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4015 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4016 | apex { |
| 4017 | name: "myapex", |
| 4018 | key: "myapex.key", |
| 4019 | binaries: ["myscript"], |
| 4020 | } |
| 4021 | |
| 4022 | apex_key { |
| 4023 | name: "myapex.key", |
| 4024 | public_key: "testkey.avbpubkey", |
| 4025 | private_key: "testkey.pem", |
| 4026 | } |
| 4027 | |
| 4028 | sh_binary { |
| 4029 | name: "myscript", |
| 4030 | src: "mylib.cpp", |
| 4031 | filename: "myscript.sh", |
| 4032 | sub_dir: "script", |
| 4033 | } |
| 4034 | `) |
| 4035 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4036 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4037 | copyCmds := apexRule.Args["copy_commands"] |
| 4038 | |
| 4039 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 4040 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4041 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4042 | func TestApexInVariousPartition(t *testing.T) { |
| 4043 | testcases := []struct { |
| 4044 | propName, parition, flattenedPartition string |
| 4045 | }{ |
| 4046 | {"", "system", "system_ext"}, |
| 4047 | {"product_specific: true", "product", "product"}, |
| 4048 | {"soc_specific: true", "vendor", "vendor"}, |
| 4049 | {"proprietary: true", "vendor", "vendor"}, |
| 4050 | {"vendor: true", "vendor", "vendor"}, |
| 4051 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 4052 | } |
| 4053 | for _, tc := range testcases { |
| 4054 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 4055 | ctx, _ := testApex(t, ` |
| 4056 | apex { |
| 4057 | name: "myapex", |
| 4058 | key: "myapex.key", |
| 4059 | `+tc.propName+` |
| 4060 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4061 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4062 | apex_key { |
| 4063 | name: "myapex.key", |
| 4064 | public_key: "testkey.avbpubkey", |
| 4065 | private_key: "testkey.pem", |
| 4066 | } |
| 4067 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4068 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4069 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 4070 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 4071 | actual := apex.installDir.String() |
| 4072 | if actual != expected { |
| 4073 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4074 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4075 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4076 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 4077 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 4078 | actual = flattened.installDir.String() |
| 4079 | if actual != expected { |
| 4080 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4081 | } |
| 4082 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4083 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4084 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4085 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4086 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4087 | ctx, _ := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4088 | apex { |
| 4089 | name: "myapex", |
| 4090 | key: "myapex.key", |
| 4091 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4092 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4093 | apex_key { |
| 4094 | name: "myapex.key", |
| 4095 | public_key: "testkey.avbpubkey", |
| 4096 | private_key: "testkey.pem", |
| 4097 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4098 | `) |
| 4099 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4100 | rule := module.Output("file_contexts") |
| 4101 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 4102 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4103 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4104 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4105 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4106 | apex { |
| 4107 | name: "myapex", |
| 4108 | key: "myapex.key", |
| 4109 | file_contexts: "my_own_file_contexts", |
| 4110 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4111 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4112 | apex_key { |
| 4113 | name: "myapex.key", |
| 4114 | public_key: "testkey.avbpubkey", |
| 4115 | private_key: "testkey.pem", |
| 4116 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4117 | `, withFiles(map[string][]byte{ |
| 4118 | "my_own_file_contexts": nil, |
| 4119 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4120 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4121 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4122 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4123 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4124 | apex { |
| 4125 | name: "myapex", |
| 4126 | key: "myapex.key", |
| 4127 | product_specific: true, |
| 4128 | file_contexts: "product_specific_file_contexts", |
| 4129 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4130 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4131 | apex_key { |
| 4132 | name: "myapex.key", |
| 4133 | public_key: "testkey.avbpubkey", |
| 4134 | private_key: "testkey.pem", |
| 4135 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4136 | `) |
| 4137 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4138 | ctx, _ := testApex(t, ` |
| 4139 | apex { |
| 4140 | name: "myapex", |
| 4141 | key: "myapex.key", |
| 4142 | product_specific: true, |
| 4143 | file_contexts: "product_specific_file_contexts", |
| 4144 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4145 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4146 | apex_key { |
| 4147 | name: "myapex.key", |
| 4148 | public_key: "testkey.avbpubkey", |
| 4149 | private_key: "testkey.pem", |
| 4150 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4151 | `, withFiles(map[string][]byte{ |
| 4152 | "product_specific_file_contexts": nil, |
| 4153 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4154 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4155 | rule := module.Output("file_contexts") |
| 4156 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 4157 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4158 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4159 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
| 4160 | ctx, _ := testApex(t, ` |
| 4161 | apex { |
| 4162 | name: "myapex", |
| 4163 | key: "myapex.key", |
| 4164 | product_specific: true, |
| 4165 | file_contexts: ":my-file-contexts", |
| 4166 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4167 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4168 | apex_key { |
| 4169 | name: "myapex.key", |
| 4170 | public_key: "testkey.avbpubkey", |
| 4171 | private_key: "testkey.pem", |
| 4172 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4173 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4174 | filegroup { |
| 4175 | name: "my-file-contexts", |
| 4176 | srcs: ["product_specific_file_contexts"], |
| 4177 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4178 | `, withFiles(map[string][]byte{ |
| 4179 | "product_specific_file_contexts": nil, |
| 4180 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4181 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4182 | rule := module.Output("file_contexts") |
| 4183 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4184 | } |
| 4185 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4186 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4187 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4188 | apex_key { |
| 4189 | name: "myapex.key", |
| 4190 | public_key: ":my.avbpubkey", |
| 4191 | private_key: ":my.pem", |
| 4192 | product_specific: true, |
| 4193 | } |
| 4194 | |
| 4195 | filegroup { |
| 4196 | name: "my.avbpubkey", |
| 4197 | srcs: ["testkey2.avbpubkey"], |
| 4198 | } |
| 4199 | |
| 4200 | filegroup { |
| 4201 | name: "my.pem", |
| 4202 | srcs: ["testkey2.pem"], |
| 4203 | } |
| 4204 | `) |
| 4205 | |
| 4206 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 4207 | expected_pubkey := "testkey2.avbpubkey" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4208 | actual_pubkey := apex_key.publicKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4209 | if actual_pubkey != expected_pubkey { |
| 4210 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 4211 | } |
| 4212 | expected_privkey := "testkey2.pem" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4213 | actual_privkey := apex_key.privateKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4214 | if actual_privkey != expected_privkey { |
| 4215 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 4216 | } |
| 4217 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4218 | |
| 4219 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4220 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4221 | prebuilt_apex { |
| 4222 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4223 | arch: { |
| 4224 | arm64: { |
| 4225 | src: "myapex-arm64.apex", |
| 4226 | }, |
| 4227 | arm: { |
| 4228 | src: "myapex-arm.apex", |
| 4229 | }, |
| 4230 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4231 | } |
| 4232 | `) |
| 4233 | |
| 4234 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4235 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4236 | expectedInput := "myapex-arm64.apex" |
| 4237 | if prebuilt.inputApex.String() != expectedInput { |
| 4238 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 4239 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4240 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4241 | |
| 4242 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4243 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4244 | prebuilt_apex { |
| 4245 | name: "myapex", |
| 4246 | src: "myapex-arm.apex", |
| 4247 | filename: "notmyapex.apex", |
| 4248 | } |
| 4249 | `) |
| 4250 | |
| 4251 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4252 | |
| 4253 | expected := "notmyapex.apex" |
| 4254 | if p.installFilename != expected { |
| 4255 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 4256 | } |
| 4257 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4258 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4259 | func TestPrebuiltOverrides(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4260 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4261 | prebuilt_apex { |
| 4262 | name: "myapex.prebuilt", |
| 4263 | src: "myapex-arm.apex", |
| 4264 | overrides: [ |
| 4265 | "myapex", |
| 4266 | ], |
| 4267 | } |
| 4268 | `) |
| 4269 | |
| 4270 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 4271 | |
| 4272 | expected := []string{"myapex"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4273 | actual := android.AndroidMkEntriesForTest(t, ctx, p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4274 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 4275 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4276 | } |
| 4277 | } |
| 4278 | |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4279 | // These tests verify that the prebuilt_apex/deapexer to java_import wiring allows for the |
| 4280 | // 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] | 4281 | func TestPrebuiltExportDexImplementationJars(t *testing.T) { |
| 4282 | transform := func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4283 | // Empty transformation. |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4284 | } |
| 4285 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4286 | checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4287 | // Make sure the import has been given the correct path to the dex jar. |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 4288 | p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4289 | dexJarBuildPath := p.DexJarBuildPath() |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4290 | stem := android.RemoveOptionalPrebuiltPrefix(name) |
| 4291 | if expected, actual := ".intermediates/myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar", android.NormalizePathForTesting(dexJarBuildPath); actual != expected { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4292 | t.Errorf("Incorrect DexJarBuildPath value '%s', expected '%s'", actual, expected) |
| 4293 | } |
| 4294 | } |
| 4295 | |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4296 | ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4297 | // Make sure that an apex variant is not created for the source module. |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4298 | if expected, actual := []string{"android_common"}, ctx.ModuleVariantsForTests(name); !reflect.DeepEqual(expected, actual) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4299 | t.Errorf("invalid set of variants for %q: expected %q, found %q", "libfoo", expected, actual) |
| 4300 | } |
| 4301 | } |
| 4302 | |
| 4303 | t.Run("prebuilt only", func(t *testing.T) { |
| 4304 | bp := ` |
| 4305 | prebuilt_apex { |
| 4306 | name: "myapex", |
| 4307 | arch: { |
| 4308 | arm64: { |
| 4309 | src: "myapex-arm64.apex", |
| 4310 | }, |
| 4311 | arm: { |
| 4312 | src: "myapex-arm.apex", |
| 4313 | }, |
| 4314 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4315 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | java_import { |
| 4319 | name: "libfoo", |
| 4320 | jars: ["libfoo.jar"], |
| 4321 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4322 | |
| 4323 | java_sdk_library_import { |
| 4324 | name: "libbar", |
| 4325 | public: { |
| 4326 | jars: ["libbar.jar"], |
| 4327 | }, |
| 4328 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4329 | ` |
| 4330 | |
| 4331 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4332 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4333 | |
Paul Duffin | f6932af | 2021-02-26 18:21:56 +0000 | [diff] [blame] | 4334 | // Make sure that the deapexer has the correct input APEX. |
| 4335 | deapexer := ctx.ModuleForTests("myapex.deapexer", "android_common") |
| 4336 | rule := deapexer.Rule("deapexer") |
| 4337 | if expected, actual := []string{"myapex-arm64.apex"}, android.NormalizePathsForTesting(rule.Implicits); !reflect.DeepEqual(expected, actual) { |
| 4338 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4339 | } |
| 4340 | |
Paul Duffin | 0d10c3c | 2021-03-01 17:09:32 +0000 | [diff] [blame] | 4341 | // Make sure that the prebuilt_apex has the correct input APEX. |
| 4342 | prebuiltApex := ctx.ModuleForTests("myapex", "android_common") |
| 4343 | rule = prebuiltApex.Rule("android/soong/android.Cp") |
| 4344 | if expected, actual := "myapex-arm64.apex", android.NormalizePathForTesting(rule.Input); !reflect.DeepEqual(expected, actual) { |
| 4345 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4346 | } |
| 4347 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4348 | checkDexJarBuildPath(t, ctx, "libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4349 | |
| 4350 | checkDexJarBuildPath(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4351 | }) |
| 4352 | |
| 4353 | t.Run("prebuilt with source preferred", func(t *testing.T) { |
| 4354 | |
| 4355 | bp := ` |
| 4356 | prebuilt_apex { |
| 4357 | name: "myapex", |
| 4358 | arch: { |
| 4359 | arm64: { |
| 4360 | src: "myapex-arm64.apex", |
| 4361 | }, |
| 4362 | arm: { |
| 4363 | src: "myapex-arm.apex", |
| 4364 | }, |
| 4365 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4366 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | java_import { |
| 4370 | name: "libfoo", |
| 4371 | jars: ["libfoo.jar"], |
| 4372 | } |
| 4373 | |
| 4374 | java_library { |
| 4375 | name: "libfoo", |
| 4376 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4377 | |
| 4378 | java_sdk_library_import { |
| 4379 | name: "libbar", |
| 4380 | public: { |
| 4381 | jars: ["libbar.jar"], |
| 4382 | }, |
| 4383 | } |
| 4384 | |
| 4385 | java_sdk_library { |
| 4386 | name: "libbar", |
| 4387 | srcs: ["foo/bar/MyClass.java"], |
| 4388 | unsafe_ignore_missing_latest_api: true, |
| 4389 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4390 | ` |
| 4391 | |
| 4392 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4393 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4394 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4395 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4396 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4397 | |
| 4398 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
| 4399 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4400 | }) |
| 4401 | |
| 4402 | t.Run("prebuilt preferred with source", func(t *testing.T) { |
| 4403 | bp := ` |
| 4404 | prebuilt_apex { |
| 4405 | name: "myapex", |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4406 | arch: { |
| 4407 | arm64: { |
| 4408 | src: "myapex-arm64.apex", |
| 4409 | }, |
| 4410 | arm: { |
| 4411 | src: "myapex-arm.apex", |
| 4412 | }, |
| 4413 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4414 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | java_import { |
| 4418 | name: "libfoo", |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4419 | prefer: true, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4420 | jars: ["libfoo.jar"], |
| 4421 | } |
| 4422 | |
| 4423 | java_library { |
| 4424 | name: "libfoo", |
| 4425 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4426 | |
| 4427 | java_sdk_library_import { |
| 4428 | name: "libbar", |
| 4429 | prefer: true, |
| 4430 | public: { |
| 4431 | jars: ["libbar.jar"], |
| 4432 | }, |
| 4433 | } |
| 4434 | |
| 4435 | java_sdk_library { |
| 4436 | name: "libbar", |
| 4437 | srcs: ["foo/bar/MyClass.java"], |
| 4438 | unsafe_ignore_missing_latest_api: true, |
| 4439 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4440 | ` |
| 4441 | |
| 4442 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4443 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4444 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4445 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4446 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4447 | |
| 4448 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
| 4449 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4450 | }) |
| 4451 | } |
| 4452 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4453 | func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { |
| 4454 | transform := func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4455 | config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo", "myapex:libbar"}) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4456 | } |
| 4457 | |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4458 | checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) { |
| 4459 | t.Helper() |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4460 | s := ctx.SingletonForTests("dex_bootjars") |
| 4461 | foundLibfooJar := false |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4462 | base := stem + ".jar" |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4463 | for _, output := range s.AllOutputs() { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4464 | if filepath.Base(output) == base { |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4465 | foundLibfooJar = true |
| 4466 | buildRule := s.Output(output) |
| 4467 | actual := android.NormalizePathForTesting(buildRule.Input) |
| 4468 | if actual != bootDexJarPath { |
| 4469 | t.Errorf("Incorrect boot dex jar path '%s', expected '%s'", actual, bootDexJarPath) |
| 4470 | } |
| 4471 | } |
| 4472 | } |
| 4473 | if !foundLibfooJar { |
| 4474 | t.Errorf("Rule for libfoo.jar missing in dex_bootjars singleton outputs") |
| 4475 | } |
| 4476 | } |
| 4477 | |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4478 | checkHiddenAPIIndexInputs := func(t *testing.T, ctx *android.TestContext, expectedInputs string) { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4479 | t.Helper() |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4480 | hiddenAPIIndex := ctx.SingletonForTests("hiddenapi_index") |
| 4481 | indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index") |
| 4482 | java.CheckHiddenAPIRuleInputs(t, expectedInputs, indexRule) |
| 4483 | } |
| 4484 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4485 | t.Run("prebuilt only", func(t *testing.T) { |
| 4486 | bp := ` |
| 4487 | prebuilt_apex { |
| 4488 | name: "myapex", |
| 4489 | arch: { |
| 4490 | arm64: { |
| 4491 | src: "myapex-arm64.apex", |
| 4492 | }, |
| 4493 | arm: { |
| 4494 | src: "myapex-arm.apex", |
| 4495 | }, |
| 4496 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4497 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4498 | } |
| 4499 | |
| 4500 | java_import { |
| 4501 | name: "libfoo", |
| 4502 | jars: ["libfoo.jar"], |
| 4503 | apex_available: ["myapex"], |
| 4504 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4505 | |
| 4506 | java_sdk_library_import { |
| 4507 | name: "libbar", |
| 4508 | public: { |
| 4509 | jars: ["libbar.jar"], |
| 4510 | }, |
| 4511 | apex_available: ["myapex"], |
| 4512 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4513 | ` |
| 4514 | |
| 4515 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4516 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4517 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4518 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4519 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4520 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4521 | .intermediates/libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4522 | .intermediates/libfoo/android_common_myapex/hiddenapi/index.csv |
| 4523 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4524 | }) |
| 4525 | |
| 4526 | t.Run("prebuilt with source library preferred", func(t *testing.T) { |
| 4527 | bp := ` |
| 4528 | prebuilt_apex { |
| 4529 | name: "myapex", |
| 4530 | arch: { |
| 4531 | arm64: { |
| 4532 | src: "myapex-arm64.apex", |
| 4533 | }, |
| 4534 | arm: { |
| 4535 | src: "myapex-arm.apex", |
| 4536 | }, |
| 4537 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4538 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | java_import { |
| 4542 | name: "libfoo", |
| 4543 | jars: ["libfoo.jar"], |
| 4544 | apex_available: ["myapex"], |
| 4545 | } |
| 4546 | |
| 4547 | java_library { |
| 4548 | name: "libfoo", |
| 4549 | srcs: ["foo/bar/MyClass.java"], |
| 4550 | apex_available: ["myapex"], |
| 4551 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4552 | |
| 4553 | java_sdk_library_import { |
| 4554 | name: "libbar", |
| 4555 | public: { |
| 4556 | jars: ["libbar.jar"], |
| 4557 | }, |
| 4558 | apex_available: ["myapex"], |
| 4559 | } |
| 4560 | |
| 4561 | java_sdk_library { |
| 4562 | name: "libbar", |
| 4563 | srcs: ["foo/bar/MyClass.java"], |
| 4564 | unsafe_ignore_missing_latest_api: true, |
| 4565 | apex_available: ["myapex"], |
| 4566 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4567 | ` |
| 4568 | |
| 4569 | // In this test the source (java_library) libfoo is active since the |
| 4570 | // prebuilt (java_import) defaults to prefer:false. However the |
| 4571 | // prebuilt_apex module always depends on the prebuilt, and so it doesn't |
| 4572 | // find the dex boot jar in it. We either need to disable the source libfoo |
| 4573 | // or make the prebuilt libfoo preferred. |
| 4574 | testDexpreoptWithApexes(t, bp, "failed to find a dex jar path for module 'libfoo'", transform) |
| 4575 | }) |
| 4576 | |
| 4577 | t.Run("prebuilt library preferred with source", func(t *testing.T) { |
| 4578 | bp := ` |
| 4579 | prebuilt_apex { |
| 4580 | name: "myapex", |
| 4581 | arch: { |
| 4582 | arm64: { |
| 4583 | src: "myapex-arm64.apex", |
| 4584 | }, |
| 4585 | arm: { |
| 4586 | src: "myapex-arm.apex", |
| 4587 | }, |
| 4588 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4589 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | java_import { |
| 4593 | name: "libfoo", |
| 4594 | prefer: true, |
| 4595 | jars: ["libfoo.jar"], |
| 4596 | apex_available: ["myapex"], |
| 4597 | } |
| 4598 | |
| 4599 | java_library { |
| 4600 | name: "libfoo", |
| 4601 | srcs: ["foo/bar/MyClass.java"], |
| 4602 | apex_available: ["myapex"], |
| 4603 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4604 | |
| 4605 | java_sdk_library_import { |
| 4606 | name: "libbar", |
| 4607 | prefer: true, |
| 4608 | public: { |
| 4609 | jars: ["libbar.jar"], |
| 4610 | }, |
| 4611 | apex_available: ["myapex"], |
| 4612 | } |
| 4613 | |
| 4614 | java_sdk_library { |
| 4615 | name: "libbar", |
| 4616 | srcs: ["foo/bar/MyClass.java"], |
| 4617 | unsafe_ignore_missing_latest_api: true, |
| 4618 | apex_available: ["myapex"], |
| 4619 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4620 | ` |
| 4621 | |
| 4622 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4623 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4624 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4625 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4626 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4627 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4628 | .intermediates/prebuilt_libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4629 | .intermediates/prebuilt_libfoo/android_common_myapex/hiddenapi/index.csv |
| 4630 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4631 | }) |
| 4632 | |
| 4633 | t.Run("prebuilt with source apex preferred", func(t *testing.T) { |
| 4634 | bp := ` |
| 4635 | apex { |
| 4636 | name: "myapex", |
| 4637 | key: "myapex.key", |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4638 | java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | apex_key { |
| 4642 | name: "myapex.key", |
| 4643 | public_key: "testkey.avbpubkey", |
| 4644 | private_key: "testkey.pem", |
| 4645 | } |
| 4646 | |
| 4647 | prebuilt_apex { |
| 4648 | name: "myapex", |
| 4649 | arch: { |
| 4650 | arm64: { |
| 4651 | src: "myapex-arm64.apex", |
| 4652 | }, |
| 4653 | arm: { |
| 4654 | src: "myapex-arm.apex", |
| 4655 | }, |
| 4656 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4657 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | java_import { |
| 4661 | name: "libfoo", |
| 4662 | jars: ["libfoo.jar"], |
| 4663 | apex_available: ["myapex"], |
| 4664 | } |
| 4665 | |
| 4666 | java_library { |
| 4667 | name: "libfoo", |
| 4668 | srcs: ["foo/bar/MyClass.java"], |
| 4669 | apex_available: ["myapex"], |
| 4670 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4671 | |
| 4672 | java_sdk_library_import { |
| 4673 | name: "libbar", |
| 4674 | public: { |
| 4675 | jars: ["libbar.jar"], |
| 4676 | }, |
| 4677 | apex_available: ["myapex"], |
| 4678 | } |
| 4679 | |
| 4680 | java_sdk_library { |
| 4681 | name: "libbar", |
| 4682 | srcs: ["foo/bar/MyClass.java"], |
| 4683 | unsafe_ignore_missing_latest_api: true, |
| 4684 | apex_available: ["myapex"], |
| 4685 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4686 | ` |
| 4687 | |
| 4688 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4689 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar") |
| 4690 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/libbar/android_common_myapex/hiddenapi/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4691 | |
| 4692 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4693 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4694 | .intermediates/libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4695 | .intermediates/libfoo/android_common_apex10000/hiddenapi/index.csv |
| 4696 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4697 | }) |
| 4698 | |
| 4699 | t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) { |
| 4700 | bp := ` |
| 4701 | apex { |
| 4702 | name: "myapex", |
| 4703 | enabled: false, |
| 4704 | key: "myapex.key", |
| 4705 | java_libs: ["libfoo"], |
| 4706 | } |
| 4707 | |
| 4708 | apex_key { |
| 4709 | name: "myapex.key", |
| 4710 | public_key: "testkey.avbpubkey", |
| 4711 | private_key: "testkey.pem", |
| 4712 | } |
| 4713 | |
| 4714 | prebuilt_apex { |
| 4715 | name: "myapex", |
| 4716 | arch: { |
| 4717 | arm64: { |
| 4718 | src: "myapex-arm64.apex", |
| 4719 | }, |
| 4720 | arm: { |
| 4721 | src: "myapex-arm.apex", |
| 4722 | }, |
| 4723 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4724 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | java_import { |
| 4728 | name: "libfoo", |
| 4729 | prefer: true, |
| 4730 | jars: ["libfoo.jar"], |
| 4731 | apex_available: ["myapex"], |
| 4732 | } |
| 4733 | |
| 4734 | java_library { |
| 4735 | name: "libfoo", |
| 4736 | srcs: ["foo/bar/MyClass.java"], |
| 4737 | apex_available: ["myapex"], |
| 4738 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4739 | |
| 4740 | java_sdk_library_import { |
| 4741 | name: "libbar", |
| 4742 | prefer: true, |
| 4743 | public: { |
| 4744 | jars: ["libbar.jar"], |
| 4745 | }, |
| 4746 | apex_available: ["myapex"], |
| 4747 | } |
| 4748 | |
| 4749 | java_sdk_library { |
| 4750 | name: "libbar", |
| 4751 | srcs: ["foo/bar/MyClass.java"], |
| 4752 | unsafe_ignore_missing_latest_api: true, |
| 4753 | apex_available: ["myapex"], |
| 4754 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4755 | ` |
| 4756 | |
| 4757 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4758 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4759 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4760 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4761 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4762 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4763 | .intermediates/prebuilt_libbar/android_common_prebuilt_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4764 | .intermediates/prebuilt_libfoo/android_common_prebuilt_myapex/hiddenapi/index.csv |
| 4765 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4766 | }) |
| 4767 | } |
| 4768 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4769 | func TestApexWithTests(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4770 | ctx, _ := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4771 | apex_test { |
| 4772 | name: "myapex", |
| 4773 | key: "myapex.key", |
| 4774 | tests: [ |
| 4775 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4776 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4777 | ], |
| 4778 | } |
| 4779 | |
| 4780 | apex_key { |
| 4781 | name: "myapex.key", |
| 4782 | public_key: "testkey.avbpubkey", |
| 4783 | private_key: "testkey.pem", |
| 4784 | } |
| 4785 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4786 | filegroup { |
| 4787 | name: "fg", |
| 4788 | srcs: [ |
| 4789 | "baz", |
| 4790 | "bar/baz" |
| 4791 | ], |
| 4792 | } |
| 4793 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4794 | cc_test { |
| 4795 | name: "mytest", |
| 4796 | gtest: false, |
| 4797 | srcs: ["mytest.cpp"], |
| 4798 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4799 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4800 | system_shared_libs: [], |
| 4801 | static_executable: true, |
| 4802 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4803 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4804 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4805 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4806 | cc_library { |
| 4807 | name: "mylib", |
| 4808 | srcs: ["mylib.cpp"], |
| 4809 | system_shared_libs: [], |
| 4810 | stl: "none", |
| 4811 | } |
| 4812 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4813 | filegroup { |
| 4814 | name: "fg2", |
| 4815 | srcs: [ |
| 4816 | "testdata/baz" |
| 4817 | ], |
| 4818 | } |
| 4819 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4820 | cc_test { |
| 4821 | name: "mytests", |
| 4822 | gtest: false, |
| 4823 | srcs: [ |
| 4824 | "mytest1.cpp", |
| 4825 | "mytest2.cpp", |
| 4826 | "mytest3.cpp", |
| 4827 | ], |
| 4828 | test_per_src: true, |
| 4829 | relative_install_path: "test", |
| 4830 | system_shared_libs: [], |
| 4831 | static_executable: true, |
| 4832 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4833 | data: [ |
| 4834 | ":fg", |
| 4835 | ":fg2", |
| 4836 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4837 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4838 | `) |
| 4839 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4840 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4841 | copyCmds := apexRule.Args["copy_commands"] |
| 4842 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4843 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4844 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4845 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4846 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4847 | //Ensure that test data are copied into apex. |
| 4848 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 4849 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 4850 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4851 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 4852 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 4853 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 4854 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4855 | |
| 4856 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4857 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4858 | data := android.AndroidMkDataForTest(t, ctx, bundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4859 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4860 | prefix := "TARGET_" |
| 4861 | var builder strings.Builder |
| 4862 | data.Custom(&builder, name, prefix, "", data) |
| 4863 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4864 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 4865 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 4866 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 4867 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4868 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4869 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4870 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4871 | |
| 4872 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4873 | data = android.AndroidMkDataForTest(t, ctx, flatBundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4874 | data.Custom(&builder, name, prefix, "", data) |
| 4875 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4876 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 4877 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4878 | } |
| 4879 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4880 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4881 | ctx, _ := testApex(t, ` |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4882 | apex { |
| 4883 | name: "myapex", |
| 4884 | key: "myapex.key", |
| 4885 | } |
| 4886 | apex_key { |
| 4887 | name: "myapex.key", |
| 4888 | public_key: "testkey.avbpubkey", |
| 4889 | private_key: "testkey.pem", |
| 4890 | } |
| 4891 | `, func(fs map[string][]byte, config android.Config) { |
| 4892 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 4893 | }) |
| 4894 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 4895 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4896 | mk := android.AndroidMkDataForTest(t, ctx, ab) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4897 | var builder strings.Builder |
| 4898 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 4899 | androidMk := builder.String() |
| 4900 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 4901 | } |
| 4902 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4903 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 4904 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 4905 | apex { |
| 4906 | name: "myapex", |
| 4907 | key: "myapex.key", |
| 4908 | native_shared_libs: ["libfoo"], |
| 4909 | } |
| 4910 | |
| 4911 | apex_key { |
| 4912 | name: "myapex.key", |
| 4913 | public_key: "testkey.avbpubkey", |
| 4914 | private_key: "testkey.pem", |
| 4915 | } |
| 4916 | |
| 4917 | cc_library { |
| 4918 | name: "libfoo", |
| 4919 | stl: "none", |
| 4920 | system_shared_libs: [], |
| 4921 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4922 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4923 | } |
| 4924 | `) |
| 4925 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 4926 | apex { |
| 4927 | name: "myapex", |
| 4928 | key: "myapex.key", |
| 4929 | java_libs: ["myjar"], |
| 4930 | } |
| 4931 | |
| 4932 | apex_key { |
| 4933 | name: "myapex.key", |
| 4934 | public_key: "testkey.avbpubkey", |
| 4935 | private_key: "testkey.pem", |
| 4936 | } |
| 4937 | |
| 4938 | java_library { |
| 4939 | name: "myjar", |
| 4940 | srcs: ["foo/bar/MyClass.java"], |
| 4941 | sdk_version: "none", |
| 4942 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4943 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4944 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4945 | } |
| 4946 | `) |
| 4947 | } |
| 4948 | |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 4949 | func TestApexWithJavaImport(t *testing.T) { |
| 4950 | ctx, _ := testApex(t, ` |
| 4951 | apex { |
| 4952 | name: "myapex", |
| 4953 | key: "myapex.key", |
| 4954 | java_libs: ["myjavaimport"], |
| 4955 | } |
| 4956 | |
| 4957 | apex_key { |
| 4958 | name: "myapex.key", |
| 4959 | public_key: "testkey.avbpubkey", |
| 4960 | private_key: "testkey.pem", |
| 4961 | } |
| 4962 | |
| 4963 | java_import { |
| 4964 | name: "myjavaimport", |
| 4965 | apex_available: ["myapex"], |
| 4966 | jars: ["my.jar"], |
| 4967 | compile_dex: true, |
| 4968 | } |
| 4969 | `) |
| 4970 | |
| 4971 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4972 | apexRule := module.Rule("apexRule") |
| 4973 | copyCmds := apexRule.Args["copy_commands"] |
| 4974 | ensureContains(t, copyCmds, "image.apex/javalib/myjavaimport.jar") |
| 4975 | } |
| 4976 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4977 | func TestApexWithApps(t *testing.T) { |
| 4978 | ctx, _ := testApex(t, ` |
| 4979 | apex { |
| 4980 | name: "myapex", |
| 4981 | key: "myapex.key", |
| 4982 | apps: [ |
| 4983 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4984 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4985 | ], |
| 4986 | } |
| 4987 | |
| 4988 | apex_key { |
| 4989 | name: "myapex.key", |
| 4990 | public_key: "testkey.avbpubkey", |
| 4991 | private_key: "testkey.pem", |
| 4992 | } |
| 4993 | |
| 4994 | android_app { |
| 4995 | name: "AppFoo", |
| 4996 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4997 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4998 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4999 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5000 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5001 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5002 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5003 | |
| 5004 | android_app { |
| 5005 | name: "AppFooPriv", |
| 5006 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5007 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5008 | system_modules: "none", |
| 5009 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5010 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5011 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5012 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5013 | |
| 5014 | cc_library_shared { |
| 5015 | name: "libjni", |
| 5016 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5017 | shared_libs: ["libfoo"], |
| 5018 | stl: "none", |
| 5019 | system_shared_libs: [], |
| 5020 | apex_available: [ "myapex" ], |
| 5021 | sdk_version: "current", |
| 5022 | } |
| 5023 | |
| 5024 | cc_library_shared { |
| 5025 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5026 | stl: "none", |
| 5027 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 5028 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5029 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5030 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5031 | `) |
| 5032 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5033 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5034 | apexRule := module.Rule("apexRule") |
| 5035 | copyCmds := apexRule.Args["copy_commands"] |
| 5036 | |
| 5037 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5038 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5039 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5040 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5041 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5042 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5043 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5044 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5045 | // JNI libraries including transitive deps are |
| 5046 | for _, jni := range []string{"libjni", "libfoo"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5047 | 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] | 5048 | // ... embedded inside APK (jnilibs.zip) |
| 5049 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 5050 | // ... and not directly inside the APEX |
| 5051 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 5052 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5053 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5054 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5055 | func TestApexWithAppImports(t *testing.T) { |
| 5056 | ctx, _ := testApex(t, ` |
| 5057 | apex { |
| 5058 | name: "myapex", |
| 5059 | key: "myapex.key", |
| 5060 | apps: [ |
| 5061 | "AppFooPrebuilt", |
| 5062 | "AppFooPrivPrebuilt", |
| 5063 | ], |
| 5064 | } |
| 5065 | |
| 5066 | apex_key { |
| 5067 | name: "myapex.key", |
| 5068 | public_key: "testkey.avbpubkey", |
| 5069 | private_key: "testkey.pem", |
| 5070 | } |
| 5071 | |
| 5072 | android_app_import { |
| 5073 | name: "AppFooPrebuilt", |
| 5074 | apk: "PrebuiltAppFoo.apk", |
| 5075 | presigned: true, |
| 5076 | dex_preopt: { |
| 5077 | enabled: false, |
| 5078 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5079 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5080 | } |
| 5081 | |
| 5082 | android_app_import { |
| 5083 | name: "AppFooPrivPrebuilt", |
| 5084 | apk: "PrebuiltAppFooPriv.apk", |
| 5085 | privileged: true, |
| 5086 | presigned: true, |
| 5087 | dex_preopt: { |
| 5088 | enabled: false, |
| 5089 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5090 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5091 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5092 | } |
| 5093 | `) |
| 5094 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5095 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5096 | apexRule := module.Rule("apexRule") |
| 5097 | copyCmds := apexRule.Args["copy_commands"] |
| 5098 | |
| 5099 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5100 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 5101 | } |
| 5102 | |
| 5103 | func TestApexWithAppImportsPrefer(t *testing.T) { |
| 5104 | ctx, _ := testApex(t, ` |
| 5105 | apex { |
| 5106 | name: "myapex", |
| 5107 | key: "myapex.key", |
| 5108 | apps: [ |
| 5109 | "AppFoo", |
| 5110 | ], |
| 5111 | } |
| 5112 | |
| 5113 | apex_key { |
| 5114 | name: "myapex.key", |
| 5115 | public_key: "testkey.avbpubkey", |
| 5116 | private_key: "testkey.pem", |
| 5117 | } |
| 5118 | |
| 5119 | android_app { |
| 5120 | name: "AppFoo", |
| 5121 | srcs: ["foo/bar/MyClass.java"], |
| 5122 | sdk_version: "none", |
| 5123 | system_modules: "none", |
| 5124 | apex_available: [ "myapex" ], |
| 5125 | } |
| 5126 | |
| 5127 | android_app_import { |
| 5128 | name: "AppFoo", |
| 5129 | apk: "AppFooPrebuilt.apk", |
| 5130 | filename: "AppFooPrebuilt.apk", |
| 5131 | presigned: true, |
| 5132 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5133 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5134 | } |
| 5135 | `, withFiles(map[string][]byte{ |
| 5136 | "AppFooPrebuilt.apk": nil, |
| 5137 | })) |
| 5138 | |
| 5139 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5140 | "app/AppFoo/AppFooPrebuilt.apk", |
| 5141 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5142 | } |
| 5143 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5144 | func TestApexWithTestHelperApp(t *testing.T) { |
| 5145 | ctx, _ := testApex(t, ` |
| 5146 | apex { |
| 5147 | name: "myapex", |
| 5148 | key: "myapex.key", |
| 5149 | apps: [ |
| 5150 | "TesterHelpAppFoo", |
| 5151 | ], |
| 5152 | } |
| 5153 | |
| 5154 | apex_key { |
| 5155 | name: "myapex.key", |
| 5156 | public_key: "testkey.avbpubkey", |
| 5157 | private_key: "testkey.pem", |
| 5158 | } |
| 5159 | |
| 5160 | android_test_helper_app { |
| 5161 | name: "TesterHelpAppFoo", |
| 5162 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5163 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | `) |
| 5167 | |
| 5168 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5169 | apexRule := module.Rule("apexRule") |
| 5170 | copyCmds := apexRule.Args["copy_commands"] |
| 5171 | |
| 5172 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 5173 | } |
| 5174 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5175 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 5176 | // libfoo's apex_available comes from cc_defaults |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5177 | 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] | 5178 | apex { |
| 5179 | name: "myapex", |
| 5180 | key: "myapex.key", |
| 5181 | native_shared_libs: ["libfoo"], |
| 5182 | } |
| 5183 | |
| 5184 | apex_key { |
| 5185 | name: "myapex.key", |
| 5186 | public_key: "testkey.avbpubkey", |
| 5187 | private_key: "testkey.pem", |
| 5188 | } |
| 5189 | |
| 5190 | apex { |
| 5191 | name: "otherapex", |
| 5192 | key: "myapex.key", |
| 5193 | native_shared_libs: ["libfoo"], |
| 5194 | } |
| 5195 | |
| 5196 | cc_defaults { |
| 5197 | name: "libfoo-defaults", |
| 5198 | apex_available: ["otherapex"], |
| 5199 | } |
| 5200 | |
| 5201 | cc_library { |
| 5202 | name: "libfoo", |
| 5203 | defaults: ["libfoo-defaults"], |
| 5204 | stl: "none", |
| 5205 | system_shared_libs: [], |
| 5206 | }`) |
| 5207 | } |
| 5208 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5209 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5210 | // libfoo is not available to myapex, but only to otherapex |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5211 | 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] | 5212 | apex { |
| 5213 | name: "myapex", |
| 5214 | key: "myapex.key", |
| 5215 | native_shared_libs: ["libfoo"], |
| 5216 | } |
| 5217 | |
| 5218 | apex_key { |
| 5219 | name: "myapex.key", |
| 5220 | public_key: "testkey.avbpubkey", |
| 5221 | private_key: "testkey.pem", |
| 5222 | } |
| 5223 | |
| 5224 | apex { |
| 5225 | name: "otherapex", |
| 5226 | key: "otherapex.key", |
| 5227 | native_shared_libs: ["libfoo"], |
| 5228 | } |
| 5229 | |
| 5230 | apex_key { |
| 5231 | name: "otherapex.key", |
| 5232 | public_key: "testkey.avbpubkey", |
| 5233 | private_key: "testkey.pem", |
| 5234 | } |
| 5235 | |
| 5236 | cc_library { |
| 5237 | name: "libfoo", |
| 5238 | stl: "none", |
| 5239 | system_shared_libs: [], |
| 5240 | apex_available: ["otherapex"], |
| 5241 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5242 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5243 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5244 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5245 | // libbbaz is an indirect dep |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5246 | 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] | 5247 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5248 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5249 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5250 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5251 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 5252 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5253 | apex { |
| 5254 | name: "myapex", |
| 5255 | key: "myapex.key", |
| 5256 | native_shared_libs: ["libfoo"], |
| 5257 | } |
| 5258 | |
| 5259 | apex_key { |
| 5260 | name: "myapex.key", |
| 5261 | public_key: "testkey.avbpubkey", |
| 5262 | private_key: "testkey.pem", |
| 5263 | } |
| 5264 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5265 | cc_library { |
| 5266 | name: "libfoo", |
| 5267 | stl: "none", |
| 5268 | shared_libs: ["libbar"], |
| 5269 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5270 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | cc_library { |
| 5274 | name: "libbar", |
| 5275 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5276 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5277 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5278 | apex_available: ["myapex"], |
| 5279 | } |
| 5280 | |
| 5281 | cc_library { |
| 5282 | name: "libbaz", |
| 5283 | stl: "none", |
| 5284 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5285 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5286 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5287 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5288 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5289 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 5290 | apex { |
| 5291 | name: "myapex", |
| 5292 | key: "myapex.key", |
| 5293 | native_shared_libs: ["libfoo"], |
| 5294 | } |
| 5295 | |
| 5296 | apex_key { |
| 5297 | name: "myapex.key", |
| 5298 | public_key: "testkey.avbpubkey", |
| 5299 | private_key: "testkey.pem", |
| 5300 | } |
| 5301 | |
| 5302 | cc_library { |
| 5303 | name: "libfoo", |
| 5304 | stl: "none", |
| 5305 | system_shared_libs: [], |
| 5306 | apex_available: ["otherapex"], |
| 5307 | }`) |
| 5308 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5309 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5310 | apex { |
| 5311 | name: "myapex", |
| 5312 | key: "myapex.key", |
| 5313 | native_shared_libs: ["libfoo", "libbar"], |
| 5314 | } |
| 5315 | |
| 5316 | apex_key { |
| 5317 | name: "myapex.key", |
| 5318 | public_key: "testkey.avbpubkey", |
| 5319 | private_key: "testkey.pem", |
| 5320 | } |
| 5321 | |
| 5322 | cc_library { |
| 5323 | name: "libfoo", |
| 5324 | stl: "none", |
| 5325 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5326 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5327 | apex_available: ["myapex"], |
| 5328 | } |
| 5329 | |
| 5330 | cc_library { |
| 5331 | name: "libbar", |
| 5332 | stl: "none", |
| 5333 | system_shared_libs: [], |
| 5334 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | cc_library { |
| 5338 | name: "libbaz", |
| 5339 | stl: "none", |
| 5340 | system_shared_libs: [], |
| 5341 | stubs: { |
| 5342 | versions: ["10", "20", "30"], |
| 5343 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5344 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5345 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5346 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5347 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5348 | ctx, _ := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5349 | apex { |
| 5350 | name: "myapex", |
| 5351 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5352 | native_shared_libs: ["libbar", "libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 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: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5365 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5366 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5367 | } |
| 5368 | |
| 5369 | cc_library { |
| 5370 | name: "libfoo2", |
| 5371 | stl: "none", |
| 5372 | system_shared_libs: [], |
| 5373 | shared_libs: ["libbaz"], |
| 5374 | apex_available: ["//apex_available:platform"], |
| 5375 | } |
| 5376 | |
| 5377 | cc_library { |
| 5378 | name: "libbar", |
| 5379 | stl: "none", |
| 5380 | system_shared_libs: [], |
| 5381 | apex_available: ["myapex"], |
| 5382 | } |
| 5383 | |
| 5384 | cc_library { |
| 5385 | name: "libbaz", |
| 5386 | stl: "none", |
| 5387 | system_shared_libs: [], |
| 5388 | apex_available: ["myapex"], |
| 5389 | stubs: { |
| 5390 | versions: ["1"], |
| 5391 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5392 | }`) |
| 5393 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5394 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 5395 | // because it depends on libbar which isn't available to platform |
| 5396 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5397 | if libfoo.NotAvailableForPlatform() != true { |
| 5398 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 5399 | } |
| 5400 | |
| 5401 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 5402 | // stubs |
| 5403 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5404 | if libfoo2.NotAvailableForPlatform() == true { |
| 5405 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 5406 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5407 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5408 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5409 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5410 | ctx, _ := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5411 | apex { |
| 5412 | name: "myapex", |
| 5413 | key: "myapex.key", |
| 5414 | native_shared_libs: ["libfoo"], |
| 5415 | } |
| 5416 | |
| 5417 | apex_key { |
| 5418 | name: "myapex.key", |
| 5419 | public_key: "testkey.avbpubkey", |
| 5420 | private_key: "testkey.pem", |
| 5421 | } |
| 5422 | |
| 5423 | cc_library { |
| 5424 | name: "libfoo", |
| 5425 | stl: "none", |
| 5426 | system_shared_libs: [], |
| 5427 | apex_available: ["myapex"], |
| 5428 | static: { |
| 5429 | apex_available: ["//apex_available:platform"], |
| 5430 | }, |
| 5431 | }`) |
| 5432 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5433 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5434 | if libfooShared.NotAvailableForPlatform() != true { |
| 5435 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 5436 | } |
| 5437 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 5438 | if libfooStatic.NotAvailableForPlatform() != false { |
| 5439 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 5440 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5441 | } |
| 5442 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5443 | func TestOverrideApex(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5444 | ctx, _ := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5445 | apex { |
| 5446 | name: "myapex", |
| 5447 | key: "myapex.key", |
| 5448 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5449 | overrides: ["oldapex"], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5450 | } |
| 5451 | |
| 5452 | override_apex { |
| 5453 | name: "override_myapex", |
| 5454 | base: "myapex", |
| 5455 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5456 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5457 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5458 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | apex_key { |
| 5462 | name: "myapex.key", |
| 5463 | public_key: "testkey.avbpubkey", |
| 5464 | private_key: "testkey.pem", |
| 5465 | } |
| 5466 | |
| 5467 | android_app { |
| 5468 | name: "app", |
| 5469 | srcs: ["foo/bar/MyClass.java"], |
| 5470 | package_name: "foo", |
| 5471 | sdk_version: "none", |
| 5472 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5473 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | override_android_app { |
| 5477 | name: "override_app", |
| 5478 | base: "app", |
| 5479 | package_name: "bar", |
| 5480 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5481 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5482 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 5483 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 5484 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 5485 | if originalVariant.GetOverriddenBy() != "" { |
| 5486 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 5487 | } |
| 5488 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 5489 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 5490 | } |
| 5491 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5492 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 5493 | apexRule := module.Rule("apexRule") |
| 5494 | copyCmds := apexRule.Args["copy_commands"] |
| 5495 | |
| 5496 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5497 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5498 | |
| 5499 | apexBundle := module.Module().(*apexBundle) |
| 5500 | name := apexBundle.Name() |
| 5501 | if name != "override_myapex" { |
| 5502 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 5503 | } |
| 5504 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5505 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 5506 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 5507 | } |
| 5508 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5509 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5510 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5511 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5512 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5513 | var builder strings.Builder |
| 5514 | data.Custom(&builder, name, "TARGET_", "", data) |
| 5515 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5516 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5517 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 5518 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5519 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5520 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5521 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5522 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 5523 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5524 | } |
| 5525 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5526 | func TestLegacyAndroid10Support(t *testing.T) { |
| 5527 | ctx, _ := testApex(t, ` |
| 5528 | apex { |
| 5529 | name: "myapex", |
| 5530 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5531 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 5532 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | apex_key { |
| 5536 | name: "myapex.key", |
| 5537 | public_key: "testkey.avbpubkey", |
| 5538 | private_key: "testkey.pem", |
| 5539 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5540 | |
| 5541 | cc_library { |
| 5542 | name: "mylib", |
| 5543 | srcs: ["mylib.cpp"], |
| 5544 | stl: "libc++", |
| 5545 | system_shared_libs: [], |
| 5546 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5547 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5548 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5549 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5550 | |
| 5551 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5552 | args := module.Rule("apexRule").Args |
| 5553 | 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] | 5554 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5555 | |
| 5556 | // The copies of the libraries in the apex should have one more dependency than |
| 5557 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 5558 | // the dependency names directly here but for some reason the names are blank in |
| 5559 | // this test. |
| 5560 | for _, lib := range []string{"libc++", "mylib"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5561 | 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] | 5562 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 5563 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 5564 | t.Errorf("%q missing unwinder dep", lib) |
| 5565 | } |
| 5566 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5567 | } |
| 5568 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5569 | var filesForSdkLibrary = map[string][]byte{ |
| 5570 | "api/current.txt": nil, |
| 5571 | "api/removed.txt": nil, |
| 5572 | "api/system-current.txt": nil, |
| 5573 | "api/system-removed.txt": nil, |
| 5574 | "api/test-current.txt": nil, |
| 5575 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5576 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5577 | "100/public/api/foo.txt": nil, |
| 5578 | "100/public/api/foo-removed.txt": nil, |
| 5579 | "100/system/api/foo.txt": nil, |
| 5580 | "100/system/api/foo-removed.txt": nil, |
| 5581 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5582 | // For java_sdk_library_import |
| 5583 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5584 | } |
| 5585 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5586 | func TestJavaSDKLibrary(t *testing.T) { |
| 5587 | ctx, _ := testApex(t, ` |
| 5588 | apex { |
| 5589 | name: "myapex", |
| 5590 | key: "myapex.key", |
| 5591 | java_libs: ["foo"], |
| 5592 | } |
| 5593 | |
| 5594 | apex_key { |
| 5595 | name: "myapex.key", |
| 5596 | public_key: "testkey.avbpubkey", |
| 5597 | private_key: "testkey.pem", |
| 5598 | } |
| 5599 | |
| 5600 | java_sdk_library { |
| 5601 | name: "foo", |
| 5602 | srcs: ["a.java"], |
| 5603 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5604 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5605 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5606 | |
| 5607 | prebuilt_apis { |
| 5608 | name: "sdk", |
| 5609 | api_dirs: ["100"], |
| 5610 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5611 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5612 | |
| 5613 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5614 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5615 | "javalib/foo.jar", |
| 5616 | "etc/permissions/foo.xml", |
| 5617 | }) |
| 5618 | // 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] | 5619 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 5620 | 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] | 5621 | } |
| 5622 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5623 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
| 5624 | ctx, _ := testApex(t, ` |
| 5625 | apex { |
| 5626 | name: "myapex", |
| 5627 | key: "myapex.key", |
| 5628 | java_libs: ["foo", "bar"], |
| 5629 | } |
| 5630 | |
| 5631 | apex_key { |
| 5632 | name: "myapex.key", |
| 5633 | public_key: "testkey.avbpubkey", |
| 5634 | private_key: "testkey.pem", |
| 5635 | } |
| 5636 | |
| 5637 | java_sdk_library { |
| 5638 | name: "foo", |
| 5639 | srcs: ["a.java"], |
| 5640 | api_packages: ["foo"], |
| 5641 | apex_available: ["myapex"], |
| 5642 | sdk_version: "none", |
| 5643 | system_modules: "none", |
| 5644 | } |
| 5645 | |
| 5646 | java_library { |
| 5647 | name: "bar", |
| 5648 | srcs: ["a.java"], |
| 5649 | libs: ["foo"], |
| 5650 | apex_available: ["myapex"], |
| 5651 | sdk_version: "none", |
| 5652 | system_modules: "none", |
| 5653 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5654 | |
| 5655 | prebuilt_apis { |
| 5656 | name: "sdk", |
| 5657 | api_dirs: ["100"], |
| 5658 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5659 | `, withFiles(filesForSdkLibrary)) |
| 5660 | |
| 5661 | // java_sdk_library installs both impl jar and permission XML |
| 5662 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5663 | "javalib/bar.jar", |
| 5664 | "javalib/foo.jar", |
| 5665 | "etc/permissions/foo.xml", |
| 5666 | }) |
| 5667 | |
| 5668 | // The bar library should depend on the implementation jar. |
| 5669 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 5670 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5671 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5672 | } |
| 5673 | } |
| 5674 | |
| 5675 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
| 5676 | ctx, _ := testApex(t, ` |
| 5677 | apex { |
| 5678 | name: "myapex", |
| 5679 | key: "myapex.key", |
| 5680 | java_libs: ["foo"], |
| 5681 | } |
| 5682 | |
| 5683 | apex_key { |
| 5684 | name: "myapex.key", |
| 5685 | public_key: "testkey.avbpubkey", |
| 5686 | private_key: "testkey.pem", |
| 5687 | } |
| 5688 | |
| 5689 | java_sdk_library { |
| 5690 | name: "foo", |
| 5691 | srcs: ["a.java"], |
| 5692 | api_packages: ["foo"], |
| 5693 | apex_available: ["myapex"], |
| 5694 | sdk_version: "none", |
| 5695 | system_modules: "none", |
| 5696 | } |
| 5697 | |
| 5698 | java_library { |
| 5699 | name: "bar", |
| 5700 | srcs: ["a.java"], |
| 5701 | libs: ["foo"], |
| 5702 | sdk_version: "none", |
| 5703 | system_modules: "none", |
| 5704 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5705 | |
| 5706 | prebuilt_apis { |
| 5707 | name: "sdk", |
| 5708 | api_dirs: ["100"], |
| 5709 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5710 | `, withFiles(filesForSdkLibrary)) |
| 5711 | |
| 5712 | // java_sdk_library installs both impl jar and permission XML |
| 5713 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5714 | "javalib/foo.jar", |
| 5715 | "etc/permissions/foo.xml", |
| 5716 | }) |
| 5717 | |
| 5718 | // The bar library should depend on the stubs jar. |
| 5719 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
| 5720 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5721 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5722 | } |
| 5723 | } |
| 5724 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5725 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5726 | ctx, _ := testApex(t, ` |
| 5727 | prebuilt_apis { |
| 5728 | name: "sdk", |
| 5729 | api_dirs: ["100"], |
| 5730 | }`, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5731 | withFiles(map[string][]byte{ |
| 5732 | "apex/a.java": nil, |
| 5733 | "apex/apex_manifest.json": nil, |
| 5734 | "apex/Android.bp": []byte(` |
| 5735 | package { |
| 5736 | default_visibility: ["//visibility:private"], |
| 5737 | } |
| 5738 | |
| 5739 | apex { |
| 5740 | name: "myapex", |
| 5741 | key: "myapex.key", |
| 5742 | java_libs: ["foo", "bar"], |
| 5743 | } |
| 5744 | |
| 5745 | apex_key { |
| 5746 | name: "myapex.key", |
| 5747 | public_key: "testkey.avbpubkey", |
| 5748 | private_key: "testkey.pem", |
| 5749 | } |
| 5750 | |
| 5751 | java_library { |
| 5752 | name: "bar", |
| 5753 | srcs: ["a.java"], |
| 5754 | libs: ["foo"], |
| 5755 | apex_available: ["myapex"], |
| 5756 | sdk_version: "none", |
| 5757 | system_modules: "none", |
| 5758 | } |
| 5759 | `), |
| 5760 | "source/a.java": nil, |
| 5761 | "source/api/current.txt": nil, |
| 5762 | "source/api/removed.txt": nil, |
| 5763 | "source/Android.bp": []byte(` |
| 5764 | package { |
| 5765 | default_visibility: ["//visibility:private"], |
| 5766 | } |
| 5767 | |
| 5768 | java_sdk_library { |
| 5769 | name: "foo", |
| 5770 | visibility: ["//apex"], |
| 5771 | srcs: ["a.java"], |
| 5772 | api_packages: ["foo"], |
| 5773 | apex_available: ["myapex"], |
| 5774 | sdk_version: "none", |
| 5775 | system_modules: "none", |
| 5776 | public: { |
| 5777 | enabled: true, |
| 5778 | }, |
| 5779 | } |
| 5780 | `), |
| 5781 | "prebuilt/a.jar": nil, |
| 5782 | "prebuilt/Android.bp": []byte(` |
| 5783 | package { |
| 5784 | default_visibility: ["//visibility:private"], |
| 5785 | } |
| 5786 | |
| 5787 | java_sdk_library_import { |
| 5788 | name: "foo", |
| 5789 | visibility: ["//apex", "//source"], |
| 5790 | apex_available: ["myapex"], |
| 5791 | prefer: true, |
| 5792 | public: { |
| 5793 | jars: ["a.jar"], |
| 5794 | }, |
| 5795 | } |
| 5796 | `), |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5797 | }), withFiles(filesForSdkLibrary), |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5798 | ) |
| 5799 | |
| 5800 | // java_sdk_library installs both impl jar and permission XML |
| 5801 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5802 | "javalib/bar.jar", |
| 5803 | "javalib/foo.jar", |
| 5804 | "etc/permissions/foo.xml", |
| 5805 | }) |
| 5806 | |
| 5807 | // The bar library should depend on the implementation jar. |
| 5808 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 5809 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.impl\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5810 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5811 | } |
| 5812 | } |
| 5813 | |
| 5814 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 5815 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 5816 | apex { |
| 5817 | name: "myapex", |
| 5818 | key: "myapex.key", |
| 5819 | java_libs: ["foo"], |
| 5820 | } |
| 5821 | |
| 5822 | apex_key { |
| 5823 | name: "myapex.key", |
| 5824 | public_key: "testkey.avbpubkey", |
| 5825 | private_key: "testkey.pem", |
| 5826 | } |
| 5827 | |
| 5828 | java_sdk_library_import { |
| 5829 | name: "foo", |
| 5830 | apex_available: ["myapex"], |
| 5831 | prefer: true, |
| 5832 | public: { |
| 5833 | jars: ["a.jar"], |
| 5834 | }, |
| 5835 | } |
| 5836 | |
| 5837 | `, withFiles(filesForSdkLibrary)) |
| 5838 | } |
| 5839 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5840 | func TestCompatConfig(t *testing.T) { |
| 5841 | ctx, _ := testApex(t, ` |
| 5842 | apex { |
| 5843 | name: "myapex", |
| 5844 | key: "myapex.key", |
| 5845 | prebuilts: ["myjar-platform-compat-config"], |
| 5846 | java_libs: ["myjar"], |
| 5847 | } |
| 5848 | |
| 5849 | apex_key { |
| 5850 | name: "myapex.key", |
| 5851 | public_key: "testkey.avbpubkey", |
| 5852 | private_key: "testkey.pem", |
| 5853 | } |
| 5854 | |
| 5855 | platform_compat_config { |
| 5856 | name: "myjar-platform-compat-config", |
| 5857 | src: ":myjar", |
| 5858 | } |
| 5859 | |
| 5860 | java_library { |
| 5861 | name: "myjar", |
| 5862 | srcs: ["foo/bar/MyClass.java"], |
| 5863 | sdk_version: "none", |
| 5864 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5865 | apex_available: [ "myapex" ], |
| 5866 | } |
| 5867 | `) |
| 5868 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5869 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 5870 | "javalib/myjar.jar", |
| 5871 | }) |
| 5872 | } |
| 5873 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5874 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 5875 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 5876 | apex { |
| 5877 | name: "myapex", |
| 5878 | key: "myapex.key", |
| 5879 | java_libs: ["myjar"], |
| 5880 | } |
| 5881 | |
| 5882 | apex_key { |
| 5883 | name: "myapex.key", |
| 5884 | public_key: "testkey.avbpubkey", |
| 5885 | private_key: "testkey.pem", |
| 5886 | } |
| 5887 | |
| 5888 | java_library { |
| 5889 | name: "myjar", |
| 5890 | srcs: ["foo/bar/MyClass.java"], |
| 5891 | sdk_version: "none", |
| 5892 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 5893 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5894 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5895 | } |
| 5896 | `) |
| 5897 | } |
| 5898 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5899 | func TestCarryRequiredModuleNames(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5900 | ctx, _ := testApex(t, ` |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5901 | apex { |
| 5902 | name: "myapex", |
| 5903 | key: "myapex.key", |
| 5904 | native_shared_libs: ["mylib"], |
| 5905 | } |
| 5906 | |
| 5907 | apex_key { |
| 5908 | name: "myapex.key", |
| 5909 | public_key: "testkey.avbpubkey", |
| 5910 | private_key: "testkey.pem", |
| 5911 | } |
| 5912 | |
| 5913 | cc_library { |
| 5914 | name: "mylib", |
| 5915 | srcs: ["mylib.cpp"], |
| 5916 | system_shared_libs: [], |
| 5917 | stl: "none", |
| 5918 | required: ["a", "b"], |
| 5919 | host_required: ["c", "d"], |
| 5920 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5921 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5922 | } |
| 5923 | `) |
| 5924 | |
| 5925 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5926 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5927 | name := apexBundle.BaseModuleName() |
| 5928 | prefix := "TARGET_" |
| 5929 | var builder strings.Builder |
| 5930 | data.Custom(&builder, name, prefix, "", data) |
| 5931 | androidMk := builder.String() |
| 5932 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 5933 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 5934 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 5935 | } |
| 5936 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5937 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 5938 | bp := ` |
| 5939 | apex { |
| 5940 | name: "myapex", |
| 5941 | key: "myapex.key", |
| 5942 | native_shared_libs: ["mylib"], |
| 5943 | java_libs: ["myjar"], |
| 5944 | } |
| 5945 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5946 | apex { |
| 5947 | name: "myapex.updatable", |
| 5948 | key: "myapex.key", |
| 5949 | native_shared_libs: ["mylib"], |
| 5950 | java_libs: ["myjar"], |
| 5951 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 5952 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5953 | } |
| 5954 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5955 | apex_key { |
| 5956 | name: "myapex.key", |
| 5957 | public_key: "testkey.avbpubkey", |
| 5958 | private_key: "testkey.pem", |
| 5959 | } |
| 5960 | |
| 5961 | cc_library { |
| 5962 | name: "mylib", |
| 5963 | srcs: ["mylib.cpp"], |
| 5964 | shared_libs: ["myotherlib"], |
| 5965 | system_shared_libs: [], |
| 5966 | stl: "none", |
| 5967 | apex_available: [ |
| 5968 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5969 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5970 | "//apex_available:platform", |
| 5971 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5972 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5973 | } |
| 5974 | |
| 5975 | cc_library { |
| 5976 | name: "myotherlib", |
| 5977 | srcs: ["mylib.cpp"], |
| 5978 | system_shared_libs: [], |
| 5979 | stl: "none", |
| 5980 | apex_available: [ |
| 5981 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5982 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5983 | "//apex_available:platform", |
| 5984 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5985 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | java_library { |
| 5989 | name: "myjar", |
| 5990 | srcs: ["foo/bar/MyClass.java"], |
| 5991 | sdk_version: "none", |
| 5992 | system_modules: "none", |
| 5993 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5994 | apex_available: [ |
| 5995 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5996 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5997 | "//apex_available:platform", |
| 5998 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5999 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6000 | } |
| 6001 | |
| 6002 | java_library { |
| 6003 | name: "myotherjar", |
| 6004 | srcs: ["foo/bar/MyClass.java"], |
| 6005 | sdk_version: "none", |
| 6006 | system_modules: "none", |
| 6007 | apex_available: [ |
| 6008 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6009 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6010 | "//apex_available:platform", |
| 6011 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6012 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6013 | } |
| 6014 | ` |
| 6015 | |
| 6016 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 6017 | for _, f := range files { |
| 6018 | if f.path == file { |
| 6019 | if f.isLink { |
| 6020 | t.Errorf("%q is not a real file", file) |
| 6021 | } |
| 6022 | return |
| 6023 | } |
| 6024 | } |
| 6025 | t.Errorf("%q is not found", file) |
| 6026 | } |
| 6027 | |
| 6028 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 6029 | for _, f := range files { |
| 6030 | if f.path == file { |
| 6031 | if !f.isLink { |
| 6032 | t.Errorf("%q is not a symlink", file) |
| 6033 | } |
| 6034 | return |
| 6035 | } |
| 6036 | } |
| 6037 | t.Errorf("%q is not found", file) |
| 6038 | } |
| 6039 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6040 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 6041 | // is updatable or not |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6042 | ctx, _ := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6043 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6044 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6045 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6046 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6047 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6048 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6049 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6050 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6051 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6052 | |
| 6053 | // 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] | 6054 | ctx, _ = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6055 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6056 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6057 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6058 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6059 | |
| 6060 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6061 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6062 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6063 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6064 | } |
| 6065 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6066 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6067 | ctx, _ := testApex(t, ` |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6068 | apex { |
| 6069 | name: "myapex", |
| 6070 | key: "myapex.key", |
| 6071 | native_shared_libs: ["mylib"], |
| 6072 | } |
| 6073 | |
| 6074 | apex_key { |
| 6075 | name: "myapex.key", |
| 6076 | public_key: "testkey.avbpubkey", |
| 6077 | private_key: "testkey.pem", |
| 6078 | } |
| 6079 | |
| 6080 | cc_library_shared { |
| 6081 | name: "mylib", |
| 6082 | srcs: ["mylib.cpp"], |
| 6083 | shared_libs: ["myotherlib"], |
| 6084 | system_shared_libs: [], |
| 6085 | stl: "none", |
| 6086 | apex_available: [ |
| 6087 | "myapex", |
| 6088 | "//apex_available:platform", |
| 6089 | ], |
| 6090 | } |
| 6091 | |
| 6092 | cc_prebuilt_library_shared { |
| 6093 | name: "myotherlib", |
| 6094 | srcs: ["prebuilt.so"], |
| 6095 | system_shared_libs: [], |
| 6096 | stl: "none", |
| 6097 | apex_available: [ |
| 6098 | "myapex", |
| 6099 | "//apex_available:platform", |
| 6100 | ], |
| 6101 | } |
| 6102 | `) |
| 6103 | |
| 6104 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6105 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6106 | var builder strings.Builder |
| 6107 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 6108 | androidMk := builder.String() |
| 6109 | // `myotherlib` is added to `myapex` as symlink |
| 6110 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 6111 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 6112 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 6113 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 6114 | 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] | 6115 | } |
| 6116 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6117 | func TestApexWithJniLibs(t *testing.T) { |
| 6118 | ctx, _ := testApex(t, ` |
| 6119 | apex { |
| 6120 | name: "myapex", |
| 6121 | key: "myapex.key", |
| 6122 | jni_libs: ["mylib"], |
| 6123 | } |
| 6124 | |
| 6125 | apex_key { |
| 6126 | name: "myapex.key", |
| 6127 | public_key: "testkey.avbpubkey", |
| 6128 | private_key: "testkey.pem", |
| 6129 | } |
| 6130 | |
| 6131 | cc_library { |
| 6132 | name: "mylib", |
| 6133 | srcs: ["mylib.cpp"], |
| 6134 | shared_libs: ["mylib2"], |
| 6135 | system_shared_libs: [], |
| 6136 | stl: "none", |
| 6137 | apex_available: [ "myapex" ], |
| 6138 | } |
| 6139 | |
| 6140 | cc_library { |
| 6141 | name: "mylib2", |
| 6142 | srcs: ["mylib.cpp"], |
| 6143 | system_shared_libs: [], |
| 6144 | stl: "none", |
| 6145 | apex_available: [ "myapex" ], |
| 6146 | } |
| 6147 | `) |
| 6148 | |
| 6149 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 6150 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 6151 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 6152 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6153 | "lib64/mylib.so", |
| 6154 | "lib64/mylib2.so", |
| 6155 | }) |
| 6156 | } |
| 6157 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6158 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
| 6159 | ctx, _ := testApex(t, ` |
| 6160 | apex { |
| 6161 | name: "myapex", |
| 6162 | key: "myapex.key", |
| 6163 | } |
| 6164 | apex_key { |
| 6165 | name: "myapex.key", |
| 6166 | public_key: "testkey.avbpubkey", |
| 6167 | private_key: "testkey.pem", |
| 6168 | } |
| 6169 | `, func(fs map[string][]byte, config android.Config) { |
| 6170 | delete(config.Targets, android.Android) |
| 6171 | config.AndroidCommonTarget = android.Target{} |
| 6172 | }) |
| 6173 | |
| 6174 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 6175 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 6176 | } |
| 6177 | } |
| 6178 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6179 | func TestAppBundle(t *testing.T) { |
| 6180 | ctx, _ := testApex(t, ` |
| 6181 | apex { |
| 6182 | name: "myapex", |
| 6183 | key: "myapex.key", |
| 6184 | apps: ["AppFoo"], |
| 6185 | } |
| 6186 | |
| 6187 | apex_key { |
| 6188 | name: "myapex.key", |
| 6189 | public_key: "testkey.avbpubkey", |
| 6190 | private_key: "testkey.pem", |
| 6191 | } |
| 6192 | |
| 6193 | android_app { |
| 6194 | name: "AppFoo", |
| 6195 | srcs: ["foo/bar/MyClass.java"], |
| 6196 | sdk_version: "none", |
| 6197 | system_modules: "none", |
| 6198 | apex_available: [ "myapex" ], |
| 6199 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6200 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6201 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6202 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json") |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6203 | content := bundleConfigRule.Args["content"] |
| 6204 | |
| 6205 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6206 | 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] | 6207 | } |
| 6208 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6209 | func TestAppSetBundle(t *testing.T) { |
| 6210 | ctx, _ := testApex(t, ` |
| 6211 | apex { |
| 6212 | name: "myapex", |
| 6213 | key: "myapex.key", |
| 6214 | apps: ["AppSet"], |
| 6215 | } |
| 6216 | |
| 6217 | apex_key { |
| 6218 | name: "myapex.key", |
| 6219 | public_key: "testkey.avbpubkey", |
| 6220 | private_key: "testkey.pem", |
| 6221 | } |
| 6222 | |
| 6223 | android_app_set { |
| 6224 | name: "AppSet", |
| 6225 | set: "AppSet.apks", |
| 6226 | }`) |
| 6227 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6228 | bundleConfigRule := mod.Output("bundle_config.json") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6229 | content := bundleConfigRule.Args["content"] |
| 6230 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 6231 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 6232 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 6233 | if len(copyCmds) != 3 { |
| 6234 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 6235 | } |
| 6236 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 6237 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 6238 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 6239 | } |
| 6240 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6241 | func TestAppSetBundlePrebuilt(t *testing.T) { |
| 6242 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 6243 | bp := ` |
| 6244 | apex_set { |
| 6245 | name: "myapex", |
| 6246 | filename: "foo_v2.apex", |
| 6247 | sanitized: { |
| 6248 | none: { set: "myapex.apks", }, |
| 6249 | hwaddress: { set: "myapex.hwasan.apks", }, |
| 6250 | }, |
| 6251 | }` |
| 6252 | fs["Android.bp"] = []byte(bp) |
| 6253 | |
| 6254 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 6255 | }) |
| 6256 | |
| 6257 | m := ctx.ModuleForTests("myapex", "android_common") |
| 6258 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 6259 | |
| 6260 | actual := extractedApex.Inputs |
| 6261 | if len(actual) != 1 { |
| 6262 | t.Errorf("expected a single input") |
| 6263 | } |
| 6264 | |
| 6265 | expected := "myapex.hwasan.apks" |
| 6266 | if actual[0].String() != expected { |
| 6267 | t.Errorf("expected %s, got %s", expected, actual[0].String()) |
| 6268 | } |
| 6269 | } |
| 6270 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6271 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6272 | t.Helper() |
| 6273 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6274 | bp := ` |
| 6275 | java_library { |
| 6276 | name: "some-updatable-apex-lib", |
| 6277 | srcs: ["a.java"], |
| 6278 | sdk_version: "current", |
| 6279 | apex_available: [ |
| 6280 | "some-updatable-apex", |
| 6281 | ], |
| 6282 | } |
| 6283 | |
| 6284 | java_library { |
| 6285 | name: "some-non-updatable-apex-lib", |
| 6286 | srcs: ["a.java"], |
| 6287 | apex_available: [ |
| 6288 | "some-non-updatable-apex", |
| 6289 | ], |
| 6290 | } |
| 6291 | |
| 6292 | java_library { |
| 6293 | name: "some-platform-lib", |
| 6294 | srcs: ["a.java"], |
| 6295 | sdk_version: "current", |
| 6296 | installable: true, |
| 6297 | } |
| 6298 | |
| 6299 | java_library { |
| 6300 | name: "some-art-lib", |
| 6301 | srcs: ["a.java"], |
| 6302 | sdk_version: "current", |
| 6303 | apex_available: [ |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6304 | "com.android.art.debug", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6305 | ], |
| 6306 | hostdex: true, |
| 6307 | } |
| 6308 | |
| 6309 | apex { |
| 6310 | name: "some-updatable-apex", |
| 6311 | key: "some-updatable-apex.key", |
| 6312 | java_libs: ["some-updatable-apex-lib"], |
| 6313 | updatable: true, |
| 6314 | min_sdk_version: "current", |
| 6315 | } |
| 6316 | |
| 6317 | apex { |
| 6318 | name: "some-non-updatable-apex", |
| 6319 | key: "some-non-updatable-apex.key", |
| 6320 | java_libs: ["some-non-updatable-apex-lib"], |
| 6321 | } |
| 6322 | |
| 6323 | apex_key { |
| 6324 | name: "some-updatable-apex.key", |
| 6325 | } |
| 6326 | |
| 6327 | apex_key { |
| 6328 | name: "some-non-updatable-apex.key", |
| 6329 | } |
| 6330 | |
| 6331 | apex { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6332 | name: "com.android.art.debug", |
| 6333 | key: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6334 | java_libs: ["some-art-lib"], |
| 6335 | updatable: true, |
| 6336 | min_sdk_version: "current", |
| 6337 | } |
| 6338 | |
| 6339 | apex_key { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6340 | name: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6341 | } |
| 6342 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6343 | filegroup { |
| 6344 | name: "some-updatable-apex-file_contexts", |
| 6345 | srcs: [ |
| 6346 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 6347 | ], |
| 6348 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6349 | |
| 6350 | filegroup { |
| 6351 | name: "some-non-updatable-apex-file_contexts", |
| 6352 | srcs: [ |
| 6353 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 6354 | ], |
| 6355 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6356 | ` |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 6357 | |
| 6358 | testDexpreoptWithApexes(t, bp, errmsg, transformDexpreoptConfig) |
| 6359 | } |
| 6360 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6361 | 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] | 6362 | t.Helper() |
| 6363 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6364 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 6365 | bp += java.GatherRequiredDepsForTest() |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6366 | |
| 6367 | fs := map[string][]byte{ |
| 6368 | "a.java": nil, |
| 6369 | "a.jar": nil, |
| 6370 | "build/make/target/product/security": nil, |
| 6371 | "apex_manifest.json": nil, |
| 6372 | "AndroidManifest.xml": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 6373 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6374 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
| 6375 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
| 6376 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 6377 | "framework/aidl/a.aidl": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6378 | } |
| 6379 | cc.GatherRequiredFilesForTest(fs) |
| 6380 | |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 6381 | for k, v := range filesForSdkLibrary { |
| 6382 | fs[k] = v |
| 6383 | } |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6384 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 6385 | |
| 6386 | ctx := android.NewTestArchContext(config) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6387 | ctx.RegisterModuleType("apex", BundleFactory) |
| 6388 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6389 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6390 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 6391 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 6392 | ctx.PreArchMutators(android.RegisterComponentsMutator) |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 6393 | android.RegisterPrebuiltMutators(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6394 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 6395 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6396 | java.RegisterHiddenApiSingletonComponents(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6397 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 6398 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 6399 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 6400 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6401 | ctx.Register() |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6402 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6403 | pathCtx := android.PathContextForTesting(config) |
| 6404 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 6405 | transformDexpreoptConfig(dexpreoptConfig) |
| 6406 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 6407 | |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6408 | // 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] | 6409 | // product variables. |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6410 | config.TestProductVariables.BootJars = dexpreoptConfig.BootJars |
| 6411 | config.TestProductVariables.UpdatableBootJars = dexpreoptConfig.UpdatableBootJars |
| 6412 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6413 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 6414 | android.FailIfErrored(t, errs) |
| 6415 | |
| 6416 | _, errs = ctx.PrepareBuildActions(config) |
| 6417 | if errmsg == "" { |
| 6418 | android.FailIfErrored(t, errs) |
| 6419 | } else if len(errs) > 0 { |
| 6420 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6421 | } else { |
| 6422 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 6423 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6424 | |
| 6425 | return ctx |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6426 | } |
| 6427 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6428 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 6429 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 6430 | apex { |
| 6431 | name: "myapex", |
| 6432 | key: "myapex.key", |
| 6433 | updatable: true, |
| 6434 | } |
| 6435 | |
| 6436 | apex_key { |
| 6437 | name: "myapex.key", |
| 6438 | public_key: "testkey.avbpubkey", |
| 6439 | private_key: "testkey.pem", |
| 6440 | } |
| 6441 | `) |
| 6442 | } |
| 6443 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6444 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6445 | var err string |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6446 | var transform func(*dexpreopt.GlobalConfig) |
| 6447 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6448 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
| 6449 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6450 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6451 | } |
| 6452 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6453 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6454 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6455 | 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] | 6456 | 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] | 6457 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6458 | config.BootJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6459 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6460 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6461 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6462 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6463 | 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] | 6464 | 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] | 6465 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6466 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6467 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6468 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6469 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6470 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6471 | 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] | 6472 | 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] | 6473 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6474 | 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] | 6475 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6476 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6477 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6478 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6479 | 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] | 6480 | 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] | 6481 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6482 | config.BootJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6483 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6484 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6485 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6486 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6487 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
| 6488 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6489 | 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] | 6490 | } |
| 6491 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6492 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6493 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6494 | 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] | 6495 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6496 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6497 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6498 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6499 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6500 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6501 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6502 | 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] | 6503 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6504 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6505 | config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6506 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6507 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6508 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6509 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6510 | 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] | 6511 | 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] | 6512 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6513 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6514 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6515 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6516 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6517 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6518 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
| 6519 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6520 | config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6521 | } |
| 6522 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6523 | }) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6524 | |
| 6525 | } |
| 6526 | |
| 6527 | func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { |
| 6528 | transform := func(config *dexpreopt.GlobalConfig) { |
| 6529 | config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo"}) |
| 6530 | } |
| 6531 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6532 | testDexpreoptWithApexes(t, ` |
| 6533 | prebuilt_apex { |
| 6534 | name: "myapex" , |
| 6535 | arch: { |
| 6536 | arm64: { |
| 6537 | src: "myapex-arm64.apex", |
| 6538 | }, |
| 6539 | arm: { |
| 6540 | src: "myapex-arm.apex", |
| 6541 | }, |
| 6542 | }, |
| 6543 | exported_java_libs: ["libfoo"], |
| 6544 | } |
| 6545 | |
| 6546 | java_import { |
| 6547 | name: "libfoo", |
| 6548 | jars: ["libfoo.jar"], |
| 6549 | } |
| 6550 | `, "", transform) |
| 6551 | }) |
| 6552 | |
| 6553 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6554 | testDexpreoptWithApexes(t, ` |
| 6555 | prebuilt_apex { |
| 6556 | name: "myapex" , |
| 6557 | arch: { |
| 6558 | arm64: { |
| 6559 | src: "myapex-arm64.apex", |
| 6560 | }, |
| 6561 | arm: { |
| 6562 | src: "myapex-arm.apex", |
| 6563 | }, |
| 6564 | }, |
| 6565 | exported_java_libs: ["libfoo"], |
| 6566 | } |
| 6567 | |
| 6568 | java_import { |
| 6569 | name: "libfoo", |
| 6570 | jars: ["libfoo.jar"], |
| 6571 | } |
| 6572 | `, "", transform) |
| 6573 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6574 | } |
| 6575 | |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6576 | func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) { |
| 6577 | t.Helper() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6578 | bp += ` |
| 6579 | apex_key { |
| 6580 | name: "myapex.key", |
| 6581 | public_key: "testkey.avbpubkey", |
| 6582 | private_key: "testkey.pem", |
| 6583 | }` |
| 6584 | fs := map[string][]byte{ |
| 6585 | "lib1/src/A.java": nil, |
| 6586 | "lib2/src/B.java": nil, |
| 6587 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 6588 | } |
| 6589 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6590 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 6591 | android.SetTestNeverallowRules(config, rules) |
| 6592 | updatableBootJars := make([]string, 0, len(apexBootJars)) |
| 6593 | for _, apexBootJar := range apexBootJars { |
| 6594 | updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar) |
| 6595 | } |
| 6596 | config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars) |
| 6597 | |
| 6598 | ctx := android.NewTestArchContext(config) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6599 | ctx.RegisterModuleType("apex", BundleFactory) |
| 6600 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 6601 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 6602 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 6603 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6604 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 6605 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 6606 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 6607 | ctx.PostDepsMutators(android.RegisterNeverallowMutator) |
| 6608 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6609 | ctx.Register() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6610 | |
| 6611 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 6612 | android.FailIfErrored(t, errs) |
| 6613 | |
| 6614 | _, errs = ctx.PrepareBuildActions(config) |
| 6615 | if errmsg == "" { |
| 6616 | android.FailIfErrored(t, errs) |
| 6617 | } else if len(errs) > 0 { |
| 6618 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 6619 | return |
| 6620 | } else { |
| 6621 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 6622 | } |
| 6623 | } |
| 6624 | |
| 6625 | func TestApexPermittedPackagesRules(t *testing.T) { |
| 6626 | testcases := []struct { |
| 6627 | name string |
| 6628 | expectedError string |
| 6629 | bp string |
| 6630 | bootJars []string |
| 6631 | modulesPackages map[string][]string |
| 6632 | }{ |
| 6633 | |
| 6634 | { |
| 6635 | name: "Non-Bootclasspath apex jar not satisfying allowed module packages.", |
| 6636 | expectedError: "", |
| 6637 | bp: ` |
| 6638 | java_library { |
| 6639 | name: "bcp_lib1", |
| 6640 | srcs: ["lib1/src/*.java"], |
| 6641 | permitted_packages: ["foo.bar"], |
| 6642 | apex_available: ["myapex"], |
| 6643 | sdk_version: "none", |
| 6644 | system_modules: "none", |
| 6645 | } |
| 6646 | java_library { |
| 6647 | name: "nonbcp_lib2", |
| 6648 | srcs: ["lib2/src/*.java"], |
| 6649 | apex_available: ["myapex"], |
| 6650 | permitted_packages: ["a.b"], |
| 6651 | sdk_version: "none", |
| 6652 | system_modules: "none", |
| 6653 | } |
| 6654 | apex { |
| 6655 | name: "myapex", |
| 6656 | key: "myapex.key", |
| 6657 | java_libs: ["bcp_lib1", "nonbcp_lib2"], |
| 6658 | }`, |
| 6659 | bootJars: []string{"bcp_lib1"}, |
| 6660 | modulesPackages: map[string][]string{ |
| 6661 | "myapex": []string{ |
| 6662 | "foo.bar", |
| 6663 | }, |
| 6664 | }, |
| 6665 | }, |
| 6666 | { |
| 6667 | name: "Bootclasspath apex jar not satisfying allowed module packages.", |
| 6668 | 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.`, |
| 6669 | bp: ` |
| 6670 | java_library { |
| 6671 | name: "bcp_lib1", |
| 6672 | srcs: ["lib1/src/*.java"], |
| 6673 | apex_available: ["myapex"], |
| 6674 | permitted_packages: ["foo.bar"], |
| 6675 | sdk_version: "none", |
| 6676 | system_modules: "none", |
| 6677 | } |
| 6678 | java_library { |
| 6679 | name: "bcp_lib2", |
| 6680 | srcs: ["lib2/src/*.java"], |
| 6681 | apex_available: ["myapex"], |
| 6682 | permitted_packages: ["foo.bar", "bar.baz"], |
| 6683 | sdk_version: "none", |
| 6684 | system_modules: "none", |
| 6685 | } |
| 6686 | apex { |
| 6687 | name: "myapex", |
| 6688 | key: "myapex.key", |
| 6689 | java_libs: ["bcp_lib1", "bcp_lib2"], |
| 6690 | } |
| 6691 | `, |
| 6692 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
| 6693 | modulesPackages: map[string][]string{ |
| 6694 | "myapex": []string{ |
| 6695 | "foo.bar", |
| 6696 | }, |
| 6697 | }, |
| 6698 | }, |
| 6699 | } |
| 6700 | for _, tc := range testcases { |
| 6701 | t.Run(tc.name, func(t *testing.T) { |
| 6702 | rules := createApexPermittedPackagesRules(tc.modulesPackages) |
| 6703 | testApexPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules) |
| 6704 | }) |
| 6705 | } |
| 6706 | } |
| 6707 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6708 | func TestTestFor(t *testing.T) { |
| 6709 | ctx, _ := testApex(t, ` |
| 6710 | apex { |
| 6711 | name: "myapex", |
| 6712 | key: "myapex.key", |
| 6713 | native_shared_libs: ["mylib", "myprivlib"], |
| 6714 | } |
| 6715 | |
| 6716 | apex_key { |
| 6717 | name: "myapex.key", |
| 6718 | public_key: "testkey.avbpubkey", |
| 6719 | private_key: "testkey.pem", |
| 6720 | } |
| 6721 | |
| 6722 | cc_library { |
| 6723 | name: "mylib", |
| 6724 | srcs: ["mylib.cpp"], |
| 6725 | system_shared_libs: [], |
| 6726 | stl: "none", |
| 6727 | stubs: { |
| 6728 | versions: ["1"], |
| 6729 | }, |
| 6730 | apex_available: ["myapex"], |
| 6731 | } |
| 6732 | |
| 6733 | cc_library { |
| 6734 | name: "myprivlib", |
| 6735 | srcs: ["mylib.cpp"], |
| 6736 | system_shared_libs: [], |
| 6737 | stl: "none", |
| 6738 | apex_available: ["myapex"], |
| 6739 | } |
| 6740 | |
| 6741 | |
| 6742 | cc_test { |
| 6743 | name: "mytest", |
| 6744 | gtest: false, |
| 6745 | srcs: ["mylib.cpp"], |
| 6746 | system_shared_libs: [], |
| 6747 | stl: "none", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6748 | shared_libs: ["mylib", "myprivlib", "mytestlib"], |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6749 | test_for: ["myapex"] |
| 6750 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6751 | |
| 6752 | cc_library { |
| 6753 | name: "mytestlib", |
| 6754 | srcs: ["mylib.cpp"], |
| 6755 | system_shared_libs: [], |
| 6756 | shared_libs: ["mylib", "myprivlib"], |
| 6757 | stl: "none", |
| 6758 | test_for: ["myapex"], |
| 6759 | } |
| 6760 | |
| 6761 | cc_benchmark { |
| 6762 | name: "mybench", |
| 6763 | srcs: ["mylib.cpp"], |
| 6764 | system_shared_libs: [], |
| 6765 | shared_libs: ["mylib", "myprivlib"], |
| 6766 | stl: "none", |
| 6767 | test_for: ["myapex"], |
| 6768 | } |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6769 | `) |
| 6770 | |
| 6771 | // the test 'mytest' is a test for the apex, therefore is linked to the |
| 6772 | // actual implementation of mylib instead of its stub. |
| 6773 | ldFlags := ctx.ModuleForTests("mytest", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 6774 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6775 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6776 | |
| 6777 | // The same should be true for cc_library |
| 6778 | ldFlags = ctx.ModuleForTests("mytestlib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 6779 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6780 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
| 6781 | |
| 6782 | // ... and for cc_benchmark |
| 6783 | ldFlags = ctx.ModuleForTests("mybench", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 6784 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6785 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6786 | } |
| 6787 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6788 | // TODO(jungjw): Move this to proptools |
| 6789 | func intPtr(i int) *int { |
| 6790 | return &i |
| 6791 | } |
| 6792 | |
| 6793 | func TestApexSet(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6794 | ctx, _ := testApex(t, ` |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6795 | apex_set { |
| 6796 | name: "myapex", |
| 6797 | set: "myapex.apks", |
| 6798 | filename: "foo_v2.apex", |
| 6799 | overrides: ["foo"], |
| 6800 | } |
| 6801 | `, func(fs map[string][]byte, config android.Config) { |
| 6802 | config.TestProductVariables.Platform_sdk_version = intPtr(30) |
Jaewoong Jung | 829b713 | 2020-06-10 12:23:32 -0700 | [diff] [blame] | 6803 | config.Targets[android.Android] = []android.Target{ |
| 6804 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}}, |
| 6805 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}}, |
| 6806 | } |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6807 | }) |
| 6808 | |
| 6809 | m := ctx.ModuleForTests("myapex", "android_common") |
| 6810 | |
| 6811 | // Check extract_apks tool parameters. |
| 6812 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 6813 | actual := extractedApex.Args["abis"] |
| 6814 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 6815 | if actual != expected { |
| 6816 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6817 | } |
| 6818 | actual = extractedApex.Args["sdk-version"] |
| 6819 | expected = "30" |
| 6820 | if actual != expected { |
| 6821 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6822 | } |
| 6823 | |
| 6824 | a := m.Module().(*ApexSet) |
| 6825 | expectedOverrides := []string{"foo"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6826 | actualOverrides := android.AndroidMkEntriesForTest(t, ctx, a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6827 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 6828 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 6829 | } |
| 6830 | } |
| 6831 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 6832 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 6833 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 6834 | apex { |
| 6835 | name: "myapex", |
| 6836 | key: "myapex.key", |
| 6837 | native_shared_libs: ["mylib"], |
| 6838 | } |
| 6839 | |
| 6840 | apex_key { |
| 6841 | name: "myapex.key", |
| 6842 | public_key: "testkey.avbpubkey", |
| 6843 | private_key: "testkey.pem", |
| 6844 | } |
| 6845 | |
| 6846 | cc_library { |
| 6847 | name: "mylib", |
| 6848 | srcs: ["mylib.cpp"], |
| 6849 | static_libs: ["otherlib"], |
| 6850 | system_shared_libs: [], |
| 6851 | stl: "none", |
| 6852 | apex_available: [ "myapex" ], |
| 6853 | } |
| 6854 | |
| 6855 | cc_library { |
| 6856 | name: "otherlib", |
| 6857 | srcs: ["mylib.cpp"], |
| 6858 | system_shared_libs: [], |
| 6859 | stl: "none", |
| 6860 | stubs: { |
| 6861 | versions: ["1", "2", "3"], |
| 6862 | }, |
| 6863 | apex_available: [ "myapex" ], |
| 6864 | } |
| 6865 | `) |
| 6866 | } |
| 6867 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 6868 | func TestApexKeysTxt(t *testing.T) { |
| 6869 | ctx, _ := testApex(t, ` |
| 6870 | apex { |
| 6871 | name: "myapex", |
| 6872 | key: "myapex.key", |
| 6873 | } |
| 6874 | |
| 6875 | apex_key { |
| 6876 | name: "myapex.key", |
| 6877 | public_key: "testkey.avbpubkey", |
| 6878 | private_key: "testkey.pem", |
| 6879 | } |
| 6880 | |
| 6881 | prebuilt_apex { |
| 6882 | name: "myapex", |
| 6883 | prefer: true, |
| 6884 | arch: { |
| 6885 | arm64: { |
| 6886 | src: "myapex-arm64.apex", |
| 6887 | }, |
| 6888 | arm: { |
| 6889 | src: "myapex-arm.apex", |
| 6890 | }, |
| 6891 | }, |
| 6892 | } |
| 6893 | |
| 6894 | apex_set { |
| 6895 | name: "myapex_set", |
| 6896 | set: "myapex.apks", |
| 6897 | filename: "myapex_set.apex", |
| 6898 | overrides: ["myapex"], |
| 6899 | } |
| 6900 | `) |
| 6901 | |
| 6902 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 6903 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 6904 | 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] | 6905 | 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] | 6906 | } |
| 6907 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 6908 | func TestAllowedFiles(t *testing.T) { |
| 6909 | ctx, _ := testApex(t, ` |
| 6910 | apex { |
| 6911 | name: "myapex", |
| 6912 | key: "myapex.key", |
| 6913 | apps: ["app"], |
| 6914 | allowed_files: "allowed.txt", |
| 6915 | } |
| 6916 | |
| 6917 | apex_key { |
| 6918 | name: "myapex.key", |
| 6919 | public_key: "testkey.avbpubkey", |
| 6920 | private_key: "testkey.pem", |
| 6921 | } |
| 6922 | |
| 6923 | android_app { |
| 6924 | name: "app", |
| 6925 | srcs: ["foo/bar/MyClass.java"], |
| 6926 | package_name: "foo", |
| 6927 | sdk_version: "none", |
| 6928 | system_modules: "none", |
| 6929 | apex_available: [ "myapex" ], |
| 6930 | } |
| 6931 | `, withFiles(map[string][]byte{ |
| 6932 | "sub/Android.bp": []byte(` |
| 6933 | override_apex { |
| 6934 | name: "override_myapex", |
| 6935 | base: "myapex", |
| 6936 | apps: ["override_app"], |
| 6937 | allowed_files: ":allowed", |
| 6938 | } |
| 6939 | // Overridable "path" property should be referenced indirectly |
| 6940 | filegroup { |
| 6941 | name: "allowed", |
| 6942 | srcs: ["allowed.txt"], |
| 6943 | } |
| 6944 | override_android_app { |
| 6945 | name: "override_app", |
| 6946 | base: "app", |
| 6947 | package_name: "bar", |
| 6948 | } |
| 6949 | `), |
| 6950 | })) |
| 6951 | |
| 6952 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 6953 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 6954 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 6955 | } |
| 6956 | |
| 6957 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 6958 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 6959 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 6960 | } |
| 6961 | } |
| 6962 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6963 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
| 6964 | _, _ = testApex(t, ` |
| 6965 | apex { |
| 6966 | name: "myapex", |
| 6967 | key: "myapex.key", |
| 6968 | native_shared_libs: ["mylib"], |
| 6969 | } |
| 6970 | |
| 6971 | apex_key { |
| 6972 | name: "myapex.key", |
| 6973 | public_key: "testkey.avbpubkey", |
| 6974 | private_key: "testkey.pem", |
| 6975 | } |
| 6976 | |
| 6977 | cc_library { |
| 6978 | name: "mylib", |
| 6979 | srcs: ["mylib.cpp"], |
| 6980 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 6981 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6982 | }, |
| 6983 | apex_available: ["myapex"], |
| 6984 | } |
| 6985 | |
| 6986 | cc_prebuilt_library_shared { |
| 6987 | name: "mylib", |
| 6988 | prefer: false, |
| 6989 | srcs: ["prebuilt.so"], |
| 6990 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 6991 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6992 | }, |
| 6993 | apex_available: ["myapex"], |
| 6994 | } |
| 6995 | `) |
| 6996 | } |
| 6997 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 6998 | func TestCompressedApex(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6999 | ctx, _ := testApex(t, ` |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7000 | apex { |
| 7001 | name: "myapex", |
| 7002 | key: "myapex.key", |
| 7003 | compressible: true, |
| 7004 | } |
| 7005 | apex_key { |
| 7006 | name: "myapex.key", |
| 7007 | public_key: "testkey.avbpubkey", |
| 7008 | private_key: "testkey.pem", |
| 7009 | } |
| 7010 | `, func(fs map[string][]byte, config android.Config) { |
| 7011 | config.TestProductVariables.CompressedApex = proptools.BoolPtr(true) |
| 7012 | }) |
| 7013 | |
| 7014 | compressRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("compressRule") |
| 7015 | ensureContains(t, compressRule.Output.String(), "myapex.capex.unsigned") |
| 7016 | |
| 7017 | signApkRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("sign compressedApex") |
| 7018 | ensureEquals(t, signApkRule.Input.String(), compressRule.Output.String()) |
| 7019 | |
| 7020 | // Make sure output of bundle is .capex |
| 7021 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 7022 | ensureContains(t, ab.outputFile.String(), "myapex.capex") |
| 7023 | |
| 7024 | // Verify android.mk rules |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7025 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7026 | var builder strings.Builder |
| 7027 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7028 | androidMk := builder.String() |
| 7029 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.capex\n") |
| 7030 | } |
| 7031 | |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7032 | func TestPreferredPrebuiltSharedLibDep(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7033 | ctx, _ := testApex(t, ` |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7034 | apex { |
| 7035 | name: "myapex", |
| 7036 | key: "myapex.key", |
| 7037 | native_shared_libs: ["mylib"], |
| 7038 | } |
| 7039 | |
| 7040 | apex_key { |
| 7041 | name: "myapex.key", |
| 7042 | public_key: "testkey.avbpubkey", |
| 7043 | private_key: "testkey.pem", |
| 7044 | } |
| 7045 | |
| 7046 | cc_library { |
| 7047 | name: "mylib", |
| 7048 | srcs: ["mylib.cpp"], |
| 7049 | apex_available: ["myapex"], |
| 7050 | shared_libs: ["otherlib"], |
| 7051 | system_shared_libs: [], |
| 7052 | } |
| 7053 | |
| 7054 | cc_library { |
| 7055 | name: "otherlib", |
| 7056 | srcs: ["mylib.cpp"], |
| 7057 | stubs: { |
| 7058 | versions: ["current"], |
| 7059 | }, |
| 7060 | } |
| 7061 | |
| 7062 | cc_prebuilt_library_shared { |
| 7063 | name: "otherlib", |
| 7064 | prefer: true, |
| 7065 | srcs: ["prebuilt.so"], |
| 7066 | stubs: { |
| 7067 | versions: ["current"], |
| 7068 | }, |
| 7069 | } |
| 7070 | `) |
| 7071 | |
| 7072 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7073 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7074 | var builder strings.Builder |
| 7075 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7076 | androidMk := builder.String() |
| 7077 | |
| 7078 | // The make level dependency needs to be on otherlib - prebuilt_otherlib isn't |
| 7079 | // a thing there. |
| 7080 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherlib\n") |
| 7081 | } |
| 7082 | |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7083 | func TestExcludeDependency(t *testing.T) { |
| 7084 | ctx, _ := testApex(t, ` |
| 7085 | apex { |
| 7086 | name: "myapex", |
| 7087 | key: "myapex.key", |
| 7088 | native_shared_libs: ["mylib"], |
| 7089 | } |
| 7090 | |
| 7091 | apex_key { |
| 7092 | name: "myapex.key", |
| 7093 | public_key: "testkey.avbpubkey", |
| 7094 | private_key: "testkey.pem", |
| 7095 | } |
| 7096 | |
| 7097 | cc_library { |
| 7098 | name: "mylib", |
| 7099 | srcs: ["mylib.cpp"], |
| 7100 | system_shared_libs: [], |
| 7101 | stl: "none", |
| 7102 | apex_available: ["myapex"], |
| 7103 | shared_libs: ["mylib2"], |
| 7104 | target: { |
| 7105 | apex: { |
| 7106 | exclude_shared_libs: ["mylib2"], |
| 7107 | }, |
| 7108 | }, |
| 7109 | } |
| 7110 | |
| 7111 | cc_library { |
| 7112 | name: "mylib2", |
| 7113 | srcs: ["mylib.cpp"], |
| 7114 | system_shared_libs: [], |
| 7115 | stl: "none", |
| 7116 | } |
| 7117 | `) |
| 7118 | |
| 7119 | // Check if mylib is linked to mylib2 for the non-apex target |
| 7120 | ldFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 7121 | ensureContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 7122 | |
| 7123 | // Make sure that the link doesn't occur for the apex target |
| 7124 | ldFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 7125 | ensureNotContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared_apex10000/mylib2.so") |
| 7126 | |
| 7127 | // It shouldn't appear in the copy cmd as well. |
| 7128 | copyCmds := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").Args["copy_commands"] |
| 7129 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 7130 | } |
| 7131 | |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7132 | func TestPrebuiltStubLibDep(t *testing.T) { |
| 7133 | bpBase := ` |
| 7134 | apex { |
| 7135 | name: "myapex", |
| 7136 | key: "myapex.key", |
| 7137 | native_shared_libs: ["mylib"], |
| 7138 | } |
| 7139 | apex_key { |
| 7140 | name: "myapex.key", |
| 7141 | public_key: "testkey.avbpubkey", |
| 7142 | private_key: "testkey.pem", |
| 7143 | } |
| 7144 | cc_library { |
| 7145 | name: "mylib", |
| 7146 | srcs: ["mylib.cpp"], |
| 7147 | apex_available: ["myapex"], |
| 7148 | shared_libs: ["stublib"], |
| 7149 | system_shared_libs: [], |
| 7150 | } |
| 7151 | apex { |
| 7152 | name: "otherapex", |
| 7153 | enabled: %s, |
| 7154 | key: "myapex.key", |
| 7155 | native_shared_libs: ["stublib"], |
| 7156 | } |
| 7157 | ` |
| 7158 | |
| 7159 | stublibSourceBp := ` |
| 7160 | cc_library { |
| 7161 | name: "stublib", |
| 7162 | srcs: ["mylib.cpp"], |
| 7163 | apex_available: ["otherapex"], |
| 7164 | system_shared_libs: [], |
| 7165 | stl: "none", |
| 7166 | stubs: { |
| 7167 | versions: ["1"], |
| 7168 | }, |
| 7169 | } |
| 7170 | ` |
| 7171 | |
| 7172 | stublibPrebuiltBp := ` |
| 7173 | cc_prebuilt_library_shared { |
| 7174 | name: "stublib", |
| 7175 | srcs: ["prebuilt.so"], |
| 7176 | apex_available: ["otherapex"], |
| 7177 | stubs: { |
| 7178 | versions: ["1"], |
| 7179 | }, |
| 7180 | %s |
| 7181 | } |
| 7182 | ` |
| 7183 | |
| 7184 | tests := []struct { |
| 7185 | name string |
| 7186 | stublibBp string |
| 7187 | usePrebuilt bool |
| 7188 | modNames []string // Modules to collect AndroidMkEntries for |
| 7189 | otherApexEnabled []string |
| 7190 | }{ |
| 7191 | { |
| 7192 | name: "only_source", |
| 7193 | stublibBp: stublibSourceBp, |
| 7194 | usePrebuilt: false, |
| 7195 | modNames: []string{"stublib"}, |
| 7196 | otherApexEnabled: []string{"true", "false"}, |
| 7197 | }, |
| 7198 | { |
| 7199 | name: "source_preferred", |
| 7200 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, ""), |
| 7201 | usePrebuilt: false, |
| 7202 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 7203 | otherApexEnabled: []string{"true", "false"}, |
| 7204 | }, |
| 7205 | { |
| 7206 | name: "prebuilt_preferred", |
| 7207 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, "prefer: true,"), |
| 7208 | usePrebuilt: true, |
| 7209 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 7210 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 7211 | }, |
| 7212 | { |
| 7213 | name: "only_prebuilt", |
| 7214 | stublibBp: fmt.Sprintf(stublibPrebuiltBp, ""), |
| 7215 | usePrebuilt: true, |
| 7216 | modNames: []string{"stublib"}, |
| 7217 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 7218 | }, |
| 7219 | } |
| 7220 | |
| 7221 | for _, test := range tests { |
| 7222 | t.Run(test.name, func(t *testing.T) { |
| 7223 | for _, otherApexEnabled := range test.otherApexEnabled { |
| 7224 | t.Run("otherapex_enabled_"+otherApexEnabled, func(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7225 | ctx, _ := testApex(t, fmt.Sprintf(bpBase, otherApexEnabled)+test.stublibBp) |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7226 | |
| 7227 | type modAndMkEntries struct { |
| 7228 | mod *cc.Module |
| 7229 | mkEntries android.AndroidMkEntries |
| 7230 | } |
| 7231 | entries := []*modAndMkEntries{} |
| 7232 | |
| 7233 | // Gather shared lib modules that are installable |
| 7234 | for _, modName := range test.modNames { |
| 7235 | for _, variant := range ctx.ModuleVariantsForTests(modName) { |
| 7236 | if !strings.HasPrefix(variant, "android_arm64_armv8-a_shared") { |
| 7237 | continue |
| 7238 | } |
| 7239 | mod := ctx.ModuleForTests(modName, variant).Module().(*cc.Module) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 7240 | if !mod.Enabled() || mod.IsHideFromMake() { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7241 | continue |
| 7242 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7243 | for _, ent := range android.AndroidMkEntriesForTest(t, ctx, mod) { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7244 | if ent.Disabled { |
| 7245 | continue |
| 7246 | } |
| 7247 | entries = append(entries, &modAndMkEntries{ |
| 7248 | mod: mod, |
| 7249 | mkEntries: ent, |
| 7250 | }) |
| 7251 | } |
| 7252 | } |
| 7253 | } |
| 7254 | |
| 7255 | var entry *modAndMkEntries = nil |
| 7256 | for _, ent := range entries { |
| 7257 | if strings.Join(ent.mkEntries.EntryMap["LOCAL_MODULE"], ",") == "stublib" { |
| 7258 | if entry != nil { |
| 7259 | t.Errorf("More than one AndroidMk entry for \"stublib\": %s and %s", entry.mod, ent.mod) |
| 7260 | } else { |
| 7261 | entry = ent |
| 7262 | } |
| 7263 | } |
| 7264 | } |
| 7265 | |
| 7266 | if entry == nil { |
| 7267 | t.Errorf("AndroidMk entry for \"stublib\" missing") |
| 7268 | } else { |
| 7269 | isPrebuilt := entry.mod.Prebuilt() != nil |
| 7270 | if isPrebuilt != test.usePrebuilt { |
| 7271 | t.Errorf("Wrong module for \"stublib\" AndroidMk entry: got prebuilt %t, want prebuilt %t", isPrebuilt, test.usePrebuilt) |
| 7272 | } |
| 7273 | if !entry.mod.IsStubs() { |
| 7274 | t.Errorf("Module for \"stublib\" AndroidMk entry isn't a stub: %s", entry.mod) |
| 7275 | } |
| 7276 | if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil { |
| 7277 | t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries) |
| 7278 | } |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 7279 | cflags := entry.mkEntries.EntryMap["LOCAL_EXPORT_CFLAGS"] |
| 7280 | expected := "-D__STUBLIB_API__=1" |
| 7281 | if !android.InList(expected, cflags) { |
| 7282 | t.Errorf("LOCAL_EXPORT_CFLAGS expected to have %q, but got %q", expected, cflags) |
| 7283 | } |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7284 | } |
| 7285 | }) |
| 7286 | } |
| 7287 | }) |
| 7288 | } |
| 7289 | } |
| 7290 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 7291 | func TestMain(m *testing.M) { |
| 7292 | run := func() int { |
| 7293 | setUp() |
| 7294 | defer tearDown() |
| 7295 | |
| 7296 | return m.Run() |
| 7297 | } |
| 7298 | |
| 7299 | os.Exit(run()) |
| 7300 | } |