Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 18 | "io/ioutil" |
| 19 | "os" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 20 | "path" |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 21 | "reflect" |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 22 | "regexp" |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 23 | "sort" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 24 | "strings" |
| 25 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 26 | |
| 27 | "github.com/google/blueprint/proptools" |
| 28 | |
| 29 | "android/soong/android" |
| 30 | "android/soong/cc" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 31 | "android/soong/dexpreopt" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 32 | prebuilt_etc "android/soong/etc" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 33 | "android/soong/java" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 34 | "android/soong/sh" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 35 | ) |
| 36 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 37 | var buildDir string |
| 38 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 39 | // names returns name list from white space separated string |
| 40 | func names(s string) (ns []string) { |
| 41 | for _, n := range strings.Split(s, " ") { |
| 42 | if len(n) > 0 { |
| 43 | ns = append(ns, n) |
| 44 | } |
| 45 | } |
| 46 | return |
| 47 | } |
| 48 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 49 | func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) { |
| 50 | t.Helper() |
| 51 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 52 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 53 | if len(errs) > 0 { |
| 54 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 55 | return |
| 56 | } |
| 57 | _, errs = ctx.PrepareBuildActions(config) |
| 58 | if len(errs) > 0 { |
| 59 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 64 | } |
| 65 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 66 | func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
| 67 | t.Helper() |
| 68 | ctx, config := testApexContext(t, bp, handlers...) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 69 | _, errs := ctx.ParseBlueprintsFiles(".") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 70 | android.FailIfErrored(t, errs) |
| 71 | _, errs = ctx.PrepareBuildActions(config) |
| 72 | android.FailIfErrored(t, errs) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 73 | return ctx, config |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 74 | } |
| 75 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 76 | type testCustomizer func(fs map[string][]byte, config android.Config) |
| 77 | |
| 78 | func withFiles(files map[string][]byte) testCustomizer { |
| 79 | return func(fs map[string][]byte, config android.Config) { |
| 80 | for k, v := range files { |
| 81 | fs[k] = v |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func withTargets(targets map[android.OsType][]android.Target) testCustomizer { |
| 87 | return func(fs map[string][]byte, config android.Config) { |
| 88 | for k, v := range targets { |
| 89 | config.Targets[k] = v |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 94 | // withNativeBridgeTargets sets configuration with targets including: |
| 95 | // - X86_64 (primary) |
| 96 | // - X86 (secondary) |
| 97 | // - Arm64 on X86_64 (native bridge) |
| 98 | // - Arm on X86 (native bridge) |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 99 | func withNativeBridgeEnabled(_ map[string][]byte, config android.Config) { |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 100 | config.Targets[android.Android] = []android.Target{ |
| 101 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, |
| 102 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 103 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, |
| 104 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 105 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, |
| 106 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"}, |
| 107 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 108 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"}, |
| 109 | } |
| 110 | } |
| 111 | |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 112 | func withManifestPackageNameOverrides(specs []string) testCustomizer { |
| 113 | return func(fs map[string][]byte, config android.Config) { |
| 114 | config.TestProductVariables.ManifestPackageNameOverrides = specs |
| 115 | } |
| 116 | } |
| 117 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 118 | func withBinder32bit(_ map[string][]byte, config android.Config) { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 119 | config.TestProductVariables.Binder32bit = proptools.BoolPtr(true) |
| 120 | } |
| 121 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 122 | func withUnbundledBuild(_ map[string][]byte, config android.Config) { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 123 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 124 | } |
| 125 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 126 | func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 127 | android.ClearApexDependency() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 128 | |
| 129 | bp = bp + ` |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 130 | filegroup { |
| 131 | name: "myapex-file_contexts", |
| 132 | srcs: [ |
| 133 | "system/sepolicy/apex/myapex-file_contexts", |
| 134 | ], |
| 135 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 136 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 137 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 138 | bp = bp + cc.GatherRequiredDepsForTest(android.Android) |
| 139 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 140 | bp = bp + java.GatherRequiredDepsForTest() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 141 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 142 | fs := map[string][]byte{ |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 143 | "a.java": nil, |
| 144 | "PrebuiltAppFoo.apk": nil, |
| 145 | "PrebuiltAppFooPriv.apk": nil, |
| 146 | "build/make/target/product/security": nil, |
| 147 | "apex_manifest.json": nil, |
| 148 | "AndroidManifest.xml": nil, |
| 149 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 150 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 151 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 152 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 153 | "system/sepolicy/apex/commonapex-file_contexts": nil, |
| 154 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 155 | "mylib.cpp": nil, |
| 156 | "mylib_common.cpp": nil, |
| 157 | "mytest.cpp": nil, |
| 158 | "mytest1.cpp": nil, |
| 159 | "mytest2.cpp": nil, |
| 160 | "mytest3.cpp": nil, |
| 161 | "myprebuilt": nil, |
| 162 | "my_include": nil, |
| 163 | "foo/bar/MyClass.java": nil, |
| 164 | "prebuilt.jar": nil, |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 165 | "prebuilt.so": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 166 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 167 | "vendor/foo/devkeys/test.pk8": nil, |
| 168 | "testkey.x509.pem": nil, |
| 169 | "testkey.pk8": nil, |
| 170 | "testkey.override.x509.pem": nil, |
| 171 | "testkey.override.pk8": nil, |
| 172 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 173 | "vendor/foo/devkeys/testkey.pem": nil, |
| 174 | "NOTICE": nil, |
| 175 | "custom_notice": nil, |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 176 | "custom_notice_for_static_lib": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 177 | "testkey2.avbpubkey": nil, |
| 178 | "testkey2.pem": nil, |
| 179 | "myapex-arm64.apex": nil, |
| 180 | "myapex-arm.apex": nil, |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 181 | "myapex.apks": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 182 | "frameworks/base/api/current.txt": nil, |
| 183 | "framework/aidl/a.aidl": nil, |
| 184 | "build/make/core/proguard.flags": nil, |
| 185 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 186 | "dummy.txt": nil, |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 187 | "baz": nil, |
| 188 | "bar/baz": nil, |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 189 | "testdata/baz": nil, |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 190 | "AppSet.apks": nil, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 191 | } |
| 192 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 193 | cc.GatherRequiredFilesForTest(fs) |
| 194 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 195 | for _, handler := range handlers { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 196 | // The fs now needs to be populated before creating the config, call handlers twice |
| 197 | // for now, once to get any fs changes, and later after the config was created to |
| 198 | // set product variables or targets. |
| 199 | tempConfig := android.TestArchConfig(buildDir, nil, bp, fs) |
| 200 | handler(fs, tempConfig) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 201 | } |
| 202 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 203 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 204 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 205 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 206 | config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 207 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 208 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 209 | config.TestProductVariables.Platform_version_active_codenames = []string{"R"} |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 210 | config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") |
| 211 | |
| 212 | for _, handler := range handlers { |
| 213 | // The fs now needs to be populated before creating the config, call handlers twice |
| 214 | // for now, earlier to get any fs changes, and now after the config was created to |
| 215 | // set product variables or targets. |
| 216 | tempFS := map[string][]byte{} |
| 217 | handler(tempFS, config) |
| 218 | } |
| 219 | |
| 220 | ctx := android.NewTestArchContext() |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 221 | |
| 222 | // from android package |
| 223 | android.RegisterPackageBuildComponents(ctx) |
| 224 | ctx.PreArchMutators(android.RegisterVisibilityRuleChecker) |
| 225 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 226 | ctx.RegisterModuleType("apex", BundleFactory) |
| 227 | ctx.RegisterModuleType("apex_test", testApexBundleFactory) |
| 228 | ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
| 229 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 230 | ctx.RegisterModuleType("apex_defaults", defaultsFactory) |
| 231 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
| 232 | ctx.RegisterModuleType("override_apex", overrideApexFactory) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 233 | ctx.RegisterModuleType("apex_set", apexSetFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 234 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 235 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 236 | ctx.PreArchMutators(android.RegisterComponentsMutator) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 237 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 238 | |
Paul Duffin | 77980a8 | 2019-12-19 16:01:36 +0000 | [diff] [blame] | 239 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 240 | |
| 241 | // Register this after the prebuilt mutators have been registered (in |
| 242 | // cc.RegisterRequiredBuildComponentsForTest) to match what happens at runtime. |
| 243 | ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer) |
| 244 | ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer) |
| 245 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 246 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 247 | ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) |
| 248 | ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 249 | ctx.RegisterModuleType("prebuilt_etc", prebuilt_etc.PrebuiltEtcFactory) |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 250 | ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 251 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 252 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 253 | java.RegisterJavaBuildComponents(ctx) |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 254 | java.RegisterSystemModulesBuildComponents(ctx) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 255 | java.RegisterAppBuildComponents(ctx) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 256 | java.RegisterSdkLibraryBuildComponents(ctx) |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 257 | ctx.RegisterSingletonType("apex_keys_text", apexKeysTextFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 258 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 259 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 260 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 261 | |
| 262 | ctx.Register(config) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 263 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 264 | return ctx, config |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 265 | } |
| 266 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 267 | func setUp() { |
| 268 | var err error |
| 269 | buildDir, err = ioutil.TempDir("", "soong_apex_test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 270 | if err != nil { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 271 | panic(err) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 272 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 273 | } |
| 274 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 275 | func tearDown() { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 276 | _ = os.RemoveAll(buildDir) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 277 | } |
| 278 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 279 | // ensure that 'result' equals 'expected' |
| 280 | func ensureEquals(t *testing.T, result string, expected string) { |
| 281 | t.Helper() |
| 282 | if result != expected { |
| 283 | t.Errorf("%q != %q", expected, result) |
| 284 | } |
| 285 | } |
| 286 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 287 | // ensure that 'result' contains 'expected' |
| 288 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 289 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 290 | if !strings.Contains(result, expected) { |
| 291 | t.Errorf("%q is not found in %q", expected, result) |
| 292 | } |
| 293 | } |
| 294 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 295 | // ensure that 'result' contains 'expected' exactly one time |
| 296 | func ensureContainsOnce(t *testing.T, result string, expected string) { |
| 297 | t.Helper() |
| 298 | count := strings.Count(result, expected) |
| 299 | if count != 1 { |
| 300 | t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result) |
| 301 | } |
| 302 | } |
| 303 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 304 | // ensures that 'result' does not contain 'notExpected' |
| 305 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 306 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 307 | if strings.Contains(result, notExpected) { |
| 308 | t.Errorf("%q is found in %q", notExpected, result) |
| 309 | } |
| 310 | } |
| 311 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 312 | func ensureMatches(t *testing.T, result string, expectedRex string) { |
| 313 | ok, err := regexp.MatchString(expectedRex, result) |
| 314 | if err != nil { |
| 315 | t.Fatalf("regexp failure trying to match %s against `%s` expression: %s", result, expectedRex, err) |
| 316 | return |
| 317 | } |
| 318 | if !ok { |
| 319 | t.Errorf("%s does not match regular expession %s", result, expectedRex) |
| 320 | } |
| 321 | } |
| 322 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 323 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 324 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 325 | if !android.InList(expected, result) { |
| 326 | t.Errorf("%q is not found in %v", expected, result) |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | func ensureListNotContains(t *testing.T, result []string, notExpected 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(notExpected, result) { |
| 333 | t.Errorf("%q is found in %v", notExpected, result) |
| 334 | } |
| 335 | } |
| 336 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 337 | func ensureListEmpty(t *testing.T, result []string) { |
| 338 | t.Helper() |
| 339 | if len(result) > 0 { |
| 340 | t.Errorf("%q is expected to be empty", result) |
| 341 | } |
| 342 | } |
| 343 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 344 | // Minimal test |
| 345 | func TestBasicApex(t *testing.T) { |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 346 | ctx, config := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 347 | apex_defaults { |
| 348 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 349 | manifest: ":myapex.manifest", |
| 350 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 351 | key: "myapex.key", |
| 352 | native_shared_libs: ["mylib"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 353 | multilib: { |
| 354 | both: { |
| 355 | binaries: ["foo",], |
| 356 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 357 | }, |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 358 | java_libs: [ |
| 359 | "myjar", |
| 360 | "myjar_dex", |
| 361 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 362 | } |
| 363 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 364 | apex { |
| 365 | name: "myapex", |
| 366 | defaults: ["myapex-defaults"], |
| 367 | } |
| 368 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 369 | apex_key { |
| 370 | name: "myapex.key", |
| 371 | public_key: "testkey.avbpubkey", |
| 372 | private_key: "testkey.pem", |
| 373 | } |
| 374 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 375 | filegroup { |
| 376 | name: "myapex.manifest", |
| 377 | srcs: ["apex_manifest.json"], |
| 378 | } |
| 379 | |
| 380 | filegroup { |
| 381 | name: "myapex.androidmanifest", |
| 382 | srcs: ["AndroidManifest.xml"], |
| 383 | } |
| 384 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 385 | cc_library { |
| 386 | name: "mylib", |
| 387 | srcs: ["mylib.cpp"], |
| 388 | shared_libs: ["mylib2"], |
| 389 | system_shared_libs: [], |
| 390 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 391 | // TODO: remove //apex_available:platform |
| 392 | apex_available: [ |
| 393 | "//apex_available:platform", |
| 394 | "myapex", |
| 395 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 396 | } |
| 397 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 398 | cc_binary { |
| 399 | name: "foo", |
| 400 | srcs: ["mylib.cpp"], |
| 401 | compile_multilib: "both", |
| 402 | multilib: { |
| 403 | lib32: { |
| 404 | suffix: "32", |
| 405 | }, |
| 406 | lib64: { |
| 407 | suffix: "64", |
| 408 | }, |
| 409 | }, |
| 410 | symlinks: ["foo_link_"], |
| 411 | symlink_preferred_arch: true, |
| 412 | system_shared_libs: [], |
| 413 | static_executable: true, |
| 414 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 415 | apex_available: [ "myapex" ], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 418 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 419 | name: "mylib2", |
| 420 | srcs: ["mylib.cpp"], |
| 421 | system_shared_libs: [], |
| 422 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 423 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 424 | static_libs: ["libstatic"], |
| 425 | // TODO: remove //apex_available:platform |
| 426 | apex_available: [ |
| 427 | "//apex_available:platform", |
| 428 | "myapex", |
| 429 | ], |
| 430 | } |
| 431 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 432 | cc_prebuilt_library_shared { |
| 433 | name: "mylib2", |
| 434 | srcs: ["prebuilt.so"], |
| 435 | // TODO: remove //apex_available:platform |
| 436 | apex_available: [ |
| 437 | "//apex_available:platform", |
| 438 | "myapex", |
| 439 | ], |
| 440 | } |
| 441 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 442 | cc_library_static { |
| 443 | name: "libstatic", |
| 444 | srcs: ["mylib.cpp"], |
| 445 | system_shared_libs: [], |
| 446 | stl: "none", |
| 447 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 448 | // TODO: remove //apex_available:platform |
| 449 | apex_available: [ |
| 450 | "//apex_available:platform", |
| 451 | "myapex", |
| 452 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 453 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 454 | |
| 455 | java_library { |
| 456 | name: "myjar", |
| 457 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 458 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 459 | sdk_version: "none", |
| 460 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 461 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 462 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 463 | // TODO: remove //apex_available:platform |
| 464 | apex_available: [ |
| 465 | "//apex_available:platform", |
| 466 | "myapex", |
| 467 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 468 | } |
| 469 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 470 | dex_import { |
| 471 | name: "myjar_dex", |
| 472 | jars: ["prebuilt.jar"], |
| 473 | apex_available: [ |
| 474 | "//apex_available:platform", |
| 475 | "myapex", |
| 476 | ], |
| 477 | } |
| 478 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 479 | java_library { |
| 480 | name: "myotherjar", |
| 481 | srcs: ["foo/bar/MyClass.java"], |
| 482 | sdk_version: "none", |
| 483 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 484 | // TODO: remove //apex_available:platform |
| 485 | apex_available: [ |
| 486 | "//apex_available:platform", |
| 487 | "myapex", |
| 488 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 489 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 490 | |
| 491 | java_library { |
| 492 | name: "mysharedjar", |
| 493 | srcs: ["foo/bar/MyClass.java"], |
| 494 | sdk_version: "none", |
| 495 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 496 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 497 | `) |
| 498 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 499 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 500 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 501 | // Make sure that Android.mk is created |
| 502 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 503 | data := android.AndroidMkDataForTest(t, config, "", ab) |
| 504 | var builder strings.Builder |
| 505 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 506 | |
| 507 | androidMk := builder.String() |
| 508 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 509 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 510 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 511 | optFlags := apexRule.Args["opt_flags"] |
| 512 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 513 | // Ensure that the NOTICE output is being packaged as an asset. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 514 | 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] | 515 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 516 | copyCmds := apexRule.Args["copy_commands"] |
| 517 | |
| 518 | // Ensure that main rule creates an output |
| 519 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 520 | |
| 521 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 522 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 523 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 524 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 525 | |
| 526 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 527 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 528 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 529 | |
| 530 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 531 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 532 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 533 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 534 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 535 | // .. but not for java libs |
| 536 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 537 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 538 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 539 | // Ensure that the platform variant ends with _shared or _common |
| 540 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 541 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 542 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 543 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 544 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 545 | |
| 546 | // Ensure that dynamic dependency to java libs are not included |
| 547 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 548 | |
| 549 | // Ensure that all symlinks are present. |
| 550 | found_foo_link_64 := false |
| 551 | found_foo := false |
| 552 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 553 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 554 | if strings.HasSuffix(cmd, "bin/foo") { |
| 555 | found_foo = true |
| 556 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 557 | found_foo_link_64 = true |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | good := found_foo && found_foo_link_64 |
| 562 | if !good { |
| 563 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 564 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 565 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 566 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 567 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 568 | if len(noticeInputs) != 3 { |
| 569 | 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] | 570 | } |
| 571 | ensureListContains(t, noticeInputs, "NOTICE") |
| 572 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 573 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 574 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 575 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
satayev | 53bbc08 | 2020-07-23 15:15:54 +0000 | [diff] [blame] | 576 | ensureListContains(t, fullDepsInfo, "myjar(minSdkVersion:(no version)) <- myapex") |
| 577 | ensureListContains(t, fullDepsInfo, "mylib(minSdkVersion:(no version)) <- myapex") |
| 578 | ensureListContains(t, fullDepsInfo, "mylib2(minSdkVersion:(no version)) <- mylib") |
| 579 | ensureListContains(t, fullDepsInfo, "myotherjar(minSdkVersion:(no version)) <- myjar") |
| 580 | ensureListContains(t, fullDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 581 | |
| 582 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
satayev | 53bbc08 | 2020-07-23 15:15:54 +0000 | [diff] [blame] | 583 | ensureListContains(t, flatDepsInfo, " myjar(minSdkVersion:(no version))") |
| 584 | ensureListContains(t, flatDepsInfo, " mylib(minSdkVersion:(no version))") |
| 585 | ensureListContains(t, flatDepsInfo, " mylib2(minSdkVersion:(no version))") |
| 586 | ensureListContains(t, flatDepsInfo, " myotherjar(minSdkVersion:(no version))") |
| 587 | ensureListContains(t, flatDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 588 | } |
| 589 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 590 | func TestDefaults(t *testing.T) { |
| 591 | ctx, _ := testApex(t, ` |
| 592 | apex_defaults { |
| 593 | name: "myapex-defaults", |
| 594 | key: "myapex.key", |
| 595 | prebuilts: ["myetc"], |
| 596 | native_shared_libs: ["mylib"], |
| 597 | java_libs: ["myjar"], |
| 598 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 599 | rros: ["rro"], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | prebuilt_etc { |
| 603 | name: "myetc", |
| 604 | src: "myprebuilt", |
| 605 | } |
| 606 | |
| 607 | apex { |
| 608 | name: "myapex", |
| 609 | defaults: ["myapex-defaults"], |
| 610 | } |
| 611 | |
| 612 | apex_key { |
| 613 | name: "myapex.key", |
| 614 | public_key: "testkey.avbpubkey", |
| 615 | private_key: "testkey.pem", |
| 616 | } |
| 617 | |
| 618 | cc_library { |
| 619 | name: "mylib", |
| 620 | system_shared_libs: [], |
| 621 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 622 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | java_library { |
| 626 | name: "myjar", |
| 627 | srcs: ["foo/bar/MyClass.java"], |
| 628 | sdk_version: "none", |
| 629 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 630 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | android_app { |
| 634 | name: "AppFoo", |
| 635 | srcs: ["foo/bar/MyClass.java"], |
| 636 | sdk_version: "none", |
| 637 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 638 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 639 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 640 | |
| 641 | runtime_resource_overlay { |
| 642 | name: "rro", |
| 643 | theme: "blue", |
| 644 | } |
| 645 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 646 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 647 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 648 | "etc/myetc", |
| 649 | "javalib/myjar.jar", |
| 650 | "lib64/mylib.so", |
| 651 | "app/AppFoo/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 652 | "overlay/blue/rro.apk", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 653 | }) |
| 654 | } |
| 655 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 656 | func TestApexManifest(t *testing.T) { |
| 657 | ctx, _ := testApex(t, ` |
| 658 | apex { |
| 659 | name: "myapex", |
| 660 | key: "myapex.key", |
| 661 | } |
| 662 | |
| 663 | apex_key { |
| 664 | name: "myapex.key", |
| 665 | public_key: "testkey.avbpubkey", |
| 666 | private_key: "testkey.pem", |
| 667 | } |
| 668 | `) |
| 669 | |
| 670 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 671 | args := module.Rule("apexRule").Args |
| 672 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 673 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 674 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 675 | } |
| 676 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 677 | func TestBasicZipApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 678 | ctx, _ := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 679 | apex { |
| 680 | name: "myapex", |
| 681 | key: "myapex.key", |
| 682 | payload_type: "zip", |
| 683 | native_shared_libs: ["mylib"], |
| 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 | srcs: ["mylib.cpp"], |
| 695 | shared_libs: ["mylib2"], |
| 696 | system_shared_libs: [], |
| 697 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 698 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | cc_library { |
| 702 | name: "mylib2", |
| 703 | srcs: ["mylib.cpp"], |
| 704 | system_shared_libs: [], |
| 705 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 706 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 707 | } |
| 708 | `) |
| 709 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 710 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 711 | copyCmds := zipApexRule.Args["copy_commands"] |
| 712 | |
| 713 | // Ensure that main rule creates an output |
| 714 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 715 | |
| 716 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 717 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 718 | |
| 719 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 720 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 721 | |
| 722 | // Ensure that both direct and indirect deps are copied into apex |
| 723 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 724 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | func TestApexWithStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 728 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 729 | apex { |
| 730 | name: "myapex", |
| 731 | key: "myapex.key", |
| 732 | native_shared_libs: ["mylib", "mylib3"], |
| 733 | } |
| 734 | |
| 735 | apex_key { |
| 736 | name: "myapex.key", |
| 737 | public_key: "testkey.avbpubkey", |
| 738 | private_key: "testkey.pem", |
| 739 | } |
| 740 | |
| 741 | cc_library { |
| 742 | name: "mylib", |
| 743 | srcs: ["mylib.cpp"], |
| 744 | shared_libs: ["mylib2", "mylib3"], |
| 745 | system_shared_libs: [], |
| 746 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 747 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | cc_library { |
| 751 | name: "mylib2", |
| 752 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 753 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 754 | system_shared_libs: [], |
| 755 | stl: "none", |
| 756 | stubs: { |
| 757 | versions: ["1", "2", "3"], |
| 758 | }, |
| 759 | } |
| 760 | |
| 761 | cc_library { |
| 762 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 763 | srcs: ["mylib.cpp"], |
| 764 | shared_libs: ["mylib4"], |
| 765 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 766 | stl: "none", |
| 767 | stubs: { |
| 768 | versions: ["10", "11", "12"], |
| 769 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 770 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 771 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 772 | |
| 773 | cc_library { |
| 774 | name: "mylib4", |
| 775 | srcs: ["mylib.cpp"], |
| 776 | system_shared_libs: [], |
| 777 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 778 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 779 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 780 | `) |
| 781 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 782 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 783 | copyCmds := apexRule.Args["copy_commands"] |
| 784 | |
| 785 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 786 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 787 | |
| 788 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 789 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 790 | |
| 791 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 792 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 793 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 794 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 795 | |
| 796 | // 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] | 797 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 798 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 799 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 800 | |
| 801 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 802 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 803 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 804 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 805 | |
| 806 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 807 | 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] | 808 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 809 | |
| 810 | // Ensure that genstub is invoked with --apex |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 811 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"]) |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 812 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 813 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 814 | "lib64/mylib.so", |
| 815 | "lib64/mylib3.so", |
| 816 | "lib64/mylib4.so", |
| 817 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 818 | } |
| 819 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 820 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 821 | ctx, _ := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 822 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 823 | name: "myapex2", |
| 824 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 825 | native_shared_libs: ["mylib"], |
| 826 | } |
| 827 | |
| 828 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 829 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 830 | public_key: "testkey.avbpubkey", |
| 831 | private_key: "testkey.pem", |
| 832 | } |
| 833 | |
| 834 | cc_library { |
| 835 | name: "mylib", |
| 836 | srcs: ["mylib.cpp"], |
| 837 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 838 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 839 | system_shared_libs: [], |
| 840 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 841 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | cc_library { |
| 845 | name: "libfoo", |
| 846 | srcs: ["mylib.cpp"], |
| 847 | shared_libs: ["libbar"], |
| 848 | system_shared_libs: [], |
| 849 | stl: "none", |
| 850 | stubs: { |
| 851 | versions: ["10", "20", "30"], |
| 852 | }, |
| 853 | } |
| 854 | |
| 855 | cc_library { |
| 856 | name: "libbar", |
| 857 | srcs: ["mylib.cpp"], |
| 858 | system_shared_libs: [], |
| 859 | stl: "none", |
| 860 | } |
| 861 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 862 | cc_library_static { |
| 863 | name: "libbaz", |
| 864 | srcs: ["mylib.cpp"], |
| 865 | system_shared_libs: [], |
| 866 | stl: "none", |
| 867 | apex_available: [ "myapex2" ], |
| 868 | } |
| 869 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 870 | `) |
| 871 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 872 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 873 | copyCmds := apexRule.Args["copy_commands"] |
| 874 | |
| 875 | // Ensure that direct non-stubs dep is always included |
| 876 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 877 | |
| 878 | // Ensure that indirect stubs dep is not included |
| 879 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 880 | |
| 881 | // Ensure that dependency of stubs is not included |
| 882 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 883 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 884 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 885 | |
| 886 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 887 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 888 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 889 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 890 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 891 | 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] | 892 | |
| 893 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 894 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 895 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 896 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
satayev | 53bbc08 | 2020-07-23 15:15:54 +0000 | [diff] [blame] | 897 | ensureListContains(t, fullDepsInfo, "mylib(minSdkVersion:(no version)) <- myapex2") |
| 898 | ensureListContains(t, fullDepsInfo, "libbaz(minSdkVersion:(no version)) <- mylib") |
| 899 | ensureListContains(t, fullDepsInfo, "libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 900 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 901 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
satayev | 53bbc08 | 2020-07-23 15:15:54 +0000 | [diff] [blame] | 902 | ensureListContains(t, flatDepsInfo, " mylib(minSdkVersion:(no version))") |
| 903 | ensureListContains(t, flatDepsInfo, " libbaz(minSdkVersion:(no version))") |
| 904 | ensureListContains(t, flatDepsInfo, " libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 905 | } |
| 906 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 907 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 908 | /* |
| 909 | myapex |
| 910 | | |
| 911 | v (runtime_libs) |
| 912 | mylib ------+------> libfoo [provides stub] |
| 913 | | |
| 914 | `------> libbar |
| 915 | */ |
| 916 | ctx, _ := testApex(t, ` |
| 917 | apex { |
| 918 | name: "myapex", |
| 919 | key: "myapex.key", |
| 920 | native_shared_libs: ["mylib"], |
| 921 | } |
| 922 | |
| 923 | apex_key { |
| 924 | name: "myapex.key", |
| 925 | public_key: "testkey.avbpubkey", |
| 926 | private_key: "testkey.pem", |
| 927 | } |
| 928 | |
| 929 | cc_library { |
| 930 | name: "mylib", |
| 931 | srcs: ["mylib.cpp"], |
| 932 | runtime_libs: ["libfoo", "libbar"], |
| 933 | system_shared_libs: [], |
| 934 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 935 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | cc_library { |
| 939 | name: "libfoo", |
| 940 | srcs: ["mylib.cpp"], |
| 941 | system_shared_libs: [], |
| 942 | stl: "none", |
| 943 | stubs: { |
| 944 | versions: ["10", "20", "30"], |
| 945 | }, |
| 946 | } |
| 947 | |
| 948 | cc_library { |
| 949 | name: "libbar", |
| 950 | srcs: ["mylib.cpp"], |
| 951 | system_shared_libs: [], |
| 952 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 953 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | `) |
| 957 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 958 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 959 | copyCmds := apexRule.Args["copy_commands"] |
| 960 | |
| 961 | // Ensure that direct non-stubs dep is always included |
| 962 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 963 | |
| 964 | // Ensure that indirect stubs dep is not included |
| 965 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 966 | |
| 967 | // Ensure that runtime_libs dep in included |
| 968 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 969 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 970 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 971 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 972 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 973 | |
| 974 | } |
| 975 | |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 976 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
| 977 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 978 | bp := ` |
| 979 | apex { |
| 980 | name: "com.android.runtime", |
| 981 | key: "com.android.runtime.key", |
| 982 | native_shared_libs: ["libc"], |
| 983 | } |
| 984 | |
| 985 | apex_key { |
| 986 | name: "com.android.runtime.key", |
| 987 | public_key: "testkey.avbpubkey", |
| 988 | private_key: "testkey.pem", |
| 989 | } |
| 990 | |
| 991 | cc_library { |
| 992 | name: "libc", |
| 993 | no_libcrt: true, |
| 994 | nocrt: true, |
| 995 | stl: "none", |
| 996 | system_shared_libs: [], |
| 997 | stubs: { versions: ["1"] }, |
| 998 | apex_available: ["com.android.runtime"], |
| 999 | |
| 1000 | sanitize: { |
| 1001 | hwaddress: true, |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | cc_prebuilt_library_shared { |
| 1006 | name: "libclang_rt.hwasan-aarch64-android", |
| 1007 | no_libcrt: true, |
| 1008 | nocrt: true, |
| 1009 | stl: "none", |
| 1010 | system_shared_libs: [], |
| 1011 | srcs: [""], |
| 1012 | stubs: { versions: ["1"] }, |
| 1013 | |
| 1014 | sanitize: { |
| 1015 | never: true, |
| 1016 | }, |
| 1017 | } |
| 1018 | ` |
| 1019 | // override bp to use hard-coded names: com.android.runtime and libc |
| 1020 | fs["Android.bp"] = []byte(bp) |
| 1021 | fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil |
| 1022 | }) |
| 1023 | |
| 1024 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1025 | "lib64/bionic/libc.so", |
| 1026 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1027 | }) |
| 1028 | |
| 1029 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1030 | |
| 1031 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1032 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1033 | |
| 1034 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1035 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1036 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1037 | } |
| 1038 | |
| 1039 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
| 1040 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 1041 | bp := ` |
| 1042 | apex { |
| 1043 | name: "com.android.runtime", |
| 1044 | key: "com.android.runtime.key", |
| 1045 | native_shared_libs: ["libc"], |
| 1046 | } |
| 1047 | |
| 1048 | apex_key { |
| 1049 | name: "com.android.runtime.key", |
| 1050 | public_key: "testkey.avbpubkey", |
| 1051 | private_key: "testkey.pem", |
| 1052 | } |
| 1053 | |
| 1054 | cc_library { |
| 1055 | name: "libc", |
| 1056 | no_libcrt: true, |
| 1057 | nocrt: true, |
| 1058 | stl: "none", |
| 1059 | system_shared_libs: [], |
| 1060 | stubs: { versions: ["1"] }, |
| 1061 | apex_available: ["com.android.runtime"], |
| 1062 | } |
| 1063 | |
| 1064 | cc_prebuilt_library_shared { |
| 1065 | name: "libclang_rt.hwasan-aarch64-android", |
| 1066 | no_libcrt: true, |
| 1067 | nocrt: true, |
| 1068 | stl: "none", |
| 1069 | system_shared_libs: [], |
| 1070 | srcs: [""], |
| 1071 | stubs: { versions: ["1"] }, |
| 1072 | |
| 1073 | sanitize: { |
| 1074 | never: true, |
| 1075 | }, |
| 1076 | } |
| 1077 | ` |
| 1078 | // override bp to use hard-coded names: com.android.runtime and libc |
| 1079 | fs["Android.bp"] = []byte(bp) |
| 1080 | fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil |
| 1081 | |
| 1082 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1083 | }) |
| 1084 | |
| 1085 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1086 | "lib64/bionic/libc.so", |
| 1087 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1088 | }) |
| 1089 | |
| 1090 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1091 | |
| 1092 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1093 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1094 | |
| 1095 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1096 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1097 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1098 | } |
| 1099 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1100 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1101 | testcases := []struct { |
| 1102 | name string |
| 1103 | minSdkVersion string |
| 1104 | shouldLink string |
| 1105 | shouldNotLink []string |
| 1106 | }{ |
| 1107 | { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1108 | name: "should link to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1109 | minSdkVersion: "", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1110 | shouldLink: "30", |
| 1111 | shouldNotLink: []string{"29"}, |
| 1112 | }, |
| 1113 | { |
| 1114 | name: "should link to llndk#29", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1115 | minSdkVersion: "min_sdk_version: \"29\",", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1116 | shouldLink: "29", |
| 1117 | shouldNotLink: []string{"30"}, |
| 1118 | }, |
| 1119 | } |
| 1120 | for _, tc := range testcases { |
| 1121 | t.Run(tc.name, func(t *testing.T) { |
| 1122 | ctx, _ := testApex(t, ` |
| 1123 | apex { |
| 1124 | name: "myapex", |
| 1125 | key: "myapex.key", |
| 1126 | use_vendor: true, |
| 1127 | native_shared_libs: ["mylib"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1128 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1129 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1130 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1131 | apex_key { |
| 1132 | name: "myapex.key", |
| 1133 | public_key: "testkey.avbpubkey", |
| 1134 | private_key: "testkey.pem", |
| 1135 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1136 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1137 | cc_library { |
| 1138 | name: "mylib", |
| 1139 | srcs: ["mylib.cpp"], |
| 1140 | vendor_available: true, |
| 1141 | shared_libs: ["libbar"], |
| 1142 | system_shared_libs: [], |
| 1143 | stl: "none", |
| 1144 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1145 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1146 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1147 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1148 | cc_library { |
| 1149 | name: "libbar", |
| 1150 | srcs: ["mylib.cpp"], |
| 1151 | system_shared_libs: [], |
| 1152 | stl: "none", |
| 1153 | stubs: { versions: ["29","30"] }, |
| 1154 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1155 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1156 | llndk_library { |
| 1157 | name: "libbar", |
| 1158 | symbol_file: "", |
| 1159 | } |
| 1160 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 1161 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1162 | }, withUnbundledBuild) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1163 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1164 | // Ensure that LLNDK dep is not included |
| 1165 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1166 | "lib64/mylib.so", |
| 1167 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1168 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1169 | // Ensure that LLNDK dep is required |
| 1170 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1171 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1172 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1173 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1174 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
| 1175 | ensureContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so") |
| 1176 | for _, ver := range tc.shouldNotLink { |
| 1177 | ensureNotContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so") |
| 1178 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1179 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1180 | mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 1181 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink) |
| 1182 | }) |
| 1183 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1184 | } |
| 1185 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1186 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1187 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1188 | apex { |
| 1189 | name: "myapex", |
| 1190 | key: "myapex.key", |
| 1191 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 1192 | } |
| 1193 | |
| 1194 | apex_key { |
| 1195 | name: "myapex.key", |
| 1196 | public_key: "testkey.avbpubkey", |
| 1197 | private_key: "testkey.pem", |
| 1198 | } |
| 1199 | |
| 1200 | cc_library { |
| 1201 | name: "mylib", |
| 1202 | srcs: ["mylib.cpp"], |
| 1203 | shared_libs: ["libdl#27"], |
| 1204 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1205 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | cc_library_shared { |
| 1209 | name: "mylib_shared", |
| 1210 | srcs: ["mylib.cpp"], |
| 1211 | shared_libs: ["libdl#27"], |
| 1212 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1213 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1217 | name: "libBootstrap", |
| 1218 | srcs: ["mylib.cpp"], |
| 1219 | stl: "none", |
| 1220 | bootstrap: true, |
| 1221 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1222 | `) |
| 1223 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1224 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1225 | copyCmds := apexRule.Args["copy_commands"] |
| 1226 | |
| 1227 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1228 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1229 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1230 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1231 | |
| 1232 | // 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] | 1233 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1234 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1235 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
| 1236 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 1237 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1238 | |
| 1239 | // For dependency to libc |
| 1240 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1241 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1242 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1243 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1244 | // ... Cflags from stub is correctly exported to mylib |
| 1245 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 1246 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 1247 | |
| 1248 | // For dependency to libm |
| 1249 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1250 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1251 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1252 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1253 | // ... and is not compiling with the stub |
| 1254 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1255 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1256 | |
| 1257 | // For dependency to libdl |
| 1258 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1259 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1260 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1261 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1262 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1263 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1264 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1265 | // ... Cflags from stub is correctly exported to mylib |
| 1266 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1267 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1268 | |
| 1269 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1270 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1271 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1272 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1273 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1274 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1275 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1276 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1277 | // there are three links between liba --> libz |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1278 | // 1) myapex -> libx -> liba -> libz : this should be #29 link, but fallback to #28 |
| 1279 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1280 | // 3) (platform) -> liba -> libz : this should be non-stub link |
| 1281 | ctx, _ := testApex(t, ` |
| 1282 | apex { |
| 1283 | name: "myapex", |
| 1284 | key: "myapex.key", |
| 1285 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1286 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | apex { |
| 1290 | name: "otherapex", |
| 1291 | key: "myapex.key", |
| 1292 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1293 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | apex_key { |
| 1297 | name: "myapex.key", |
| 1298 | public_key: "testkey.avbpubkey", |
| 1299 | private_key: "testkey.pem", |
| 1300 | } |
| 1301 | |
| 1302 | cc_library { |
| 1303 | name: "libx", |
| 1304 | shared_libs: ["liba"], |
| 1305 | system_shared_libs: [], |
| 1306 | stl: "none", |
| 1307 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1308 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | cc_library { |
| 1312 | name: "liby", |
| 1313 | shared_libs: ["liba"], |
| 1314 | system_shared_libs: [], |
| 1315 | stl: "none", |
| 1316 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1317 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | cc_library { |
| 1321 | name: "liba", |
| 1322 | shared_libs: ["libz"], |
| 1323 | system_shared_libs: [], |
| 1324 | stl: "none", |
| 1325 | apex_available: [ |
| 1326 | "//apex_available:anyapex", |
| 1327 | "//apex_available:platform", |
| 1328 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1329 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | cc_library { |
| 1333 | name: "libz", |
| 1334 | system_shared_libs: [], |
| 1335 | stl: "none", |
| 1336 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1337 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1338 | }, |
| 1339 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1340 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1341 | |
| 1342 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1343 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1344 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1345 | } |
| 1346 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1347 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1348 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1349 | } |
| 1350 | // platform liba is linked to non-stub version |
| 1351 | expectLink("liba", "shared", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1352 | // liba in myapex is linked to #28 |
| 1353 | expectLink("liba", "shared_myapex", "libz", "shared_28") |
| 1354 | expectNoLink("liba", "shared_myapex", "libz", "shared_30") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1355 | expectNoLink("liba", "shared_myapex", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1356 | // liba in otherapex is linked to #30 |
| 1357 | expectLink("liba", "shared_otherapex", "libz", "shared_30") |
| 1358 | expectNoLink("liba", "shared_otherapex", "libz", "shared_28") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1359 | expectNoLink("liba", "shared_otherapex", "libz", "shared") |
| 1360 | } |
| 1361 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1362 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
| 1363 | ctx, _ := testApex(t, ` |
| 1364 | apex { |
| 1365 | name: "myapex", |
| 1366 | key: "myapex.key", |
| 1367 | native_shared_libs: ["libx"], |
| 1368 | min_sdk_version: "R", |
| 1369 | } |
| 1370 | |
| 1371 | apex_key { |
| 1372 | name: "myapex.key", |
| 1373 | public_key: "testkey.avbpubkey", |
| 1374 | private_key: "testkey.pem", |
| 1375 | } |
| 1376 | |
| 1377 | cc_library { |
| 1378 | name: "libx", |
| 1379 | shared_libs: ["libz"], |
| 1380 | system_shared_libs: [], |
| 1381 | stl: "none", |
| 1382 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1383 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | cc_library { |
| 1387 | name: "libz", |
| 1388 | system_shared_libs: [], |
| 1389 | stl: "none", |
| 1390 | stubs: { |
| 1391 | versions: ["29", "R"], |
| 1392 | }, |
| 1393 | } |
| 1394 | `, func(fs map[string][]byte, config android.Config) { |
| 1395 | config.TestProductVariables.Platform_version_active_codenames = []string{"R"} |
| 1396 | }) |
| 1397 | |
| 1398 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1399 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1400 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1401 | } |
| 1402 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1403 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1404 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1405 | } |
| 1406 | // 9000 is quite a magic number. |
| 1407 | // Finalized SDK codenames are mapped as P(28), Q(29), ... |
| 1408 | // And, codenames which are not finalized yet(active_codenames + future_codenames) are numbered from 9000, 9001, ... |
| 1409 | // to distinguish them from finalized and future_api(10000) |
| 1410 | // In this test, "R" is assumed not finalized yet( listed in Platform_version_active_codenames) and translated into 9000 |
| 1411 | // (refer android/api_levels.go) |
| 1412 | expectLink("libx", "shared_myapex", "libz", "shared_9000") |
| 1413 | expectNoLink("libx", "shared_myapex", "libz", "shared_29") |
| 1414 | expectNoLink("libx", "shared_myapex", "libz", "shared") |
| 1415 | } |
| 1416 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1417 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1418 | ctx, _ := testApex(t, ` |
| 1419 | apex { |
| 1420 | name: "myapex", |
| 1421 | key: "myapex.key", |
| 1422 | native_shared_libs: ["libx"], |
| 1423 | } |
| 1424 | |
| 1425 | apex_key { |
| 1426 | name: "myapex.key", |
| 1427 | public_key: "testkey.avbpubkey", |
| 1428 | private_key: "testkey.pem", |
| 1429 | } |
| 1430 | |
| 1431 | cc_library { |
| 1432 | name: "libx", |
| 1433 | shared_libs: ["libz"], |
| 1434 | system_shared_libs: [], |
| 1435 | stl: "none", |
| 1436 | apex_available: [ "myapex" ], |
| 1437 | } |
| 1438 | |
| 1439 | cc_library { |
| 1440 | name: "libz", |
| 1441 | system_shared_libs: [], |
| 1442 | stl: "none", |
| 1443 | stubs: { |
| 1444 | versions: ["1", "2"], |
| 1445 | }, |
| 1446 | } |
| 1447 | `) |
| 1448 | |
| 1449 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1450 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1451 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1452 | } |
| 1453 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1454 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1455 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1456 | } |
| 1457 | expectLink("libx", "shared_myapex", "libz", "shared_2") |
| 1458 | expectNoLink("libx", "shared_myapex", "libz", "shared_1") |
| 1459 | expectNoLink("libx", "shared_myapex", "libz", "shared") |
| 1460 | } |
| 1461 | |
| 1462 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
| 1463 | ctx, _ := testApex(t, ` |
| 1464 | apex { |
| 1465 | name: "myapex", |
| 1466 | key: "myapex.key", |
| 1467 | native_shared_libs: ["libx"], |
| 1468 | } |
| 1469 | |
| 1470 | apex_key { |
| 1471 | name: "myapex.key", |
| 1472 | public_key: "testkey.avbpubkey", |
| 1473 | private_key: "testkey.pem", |
| 1474 | } |
| 1475 | |
| 1476 | cc_library { |
| 1477 | name: "libx", |
| 1478 | system_shared_libs: [], |
| 1479 | stl: "none", |
| 1480 | apex_available: [ "myapex" ], |
| 1481 | stubs: { |
| 1482 | versions: ["1", "2"], |
| 1483 | }, |
| 1484 | } |
| 1485 | |
| 1486 | cc_library { |
| 1487 | name: "libz", |
| 1488 | shared_libs: ["libx"], |
| 1489 | system_shared_libs: [], |
| 1490 | stl: "none", |
| 1491 | } |
| 1492 | `) |
| 1493 | |
| 1494 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1495 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1496 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1497 | } |
| 1498 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1499 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1500 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1501 | } |
| 1502 | expectLink("libz", "shared", "libx", "shared_2") |
| 1503 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1504 | expectNoLink("libz", "shared", "libz", "shared") |
| 1505 | } |
| 1506 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1507 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1508 | ctx, _ := testApex(t, ` |
| 1509 | apex { |
| 1510 | name: "myapex", |
| 1511 | key: "myapex.key", |
| 1512 | native_shared_libs: ["libx"], |
| 1513 | min_sdk_version: "29", |
| 1514 | } |
| 1515 | |
| 1516 | apex_key { |
| 1517 | name: "myapex.key", |
| 1518 | public_key: "testkey.avbpubkey", |
| 1519 | private_key: "testkey.pem", |
| 1520 | } |
| 1521 | |
| 1522 | cc_library { |
| 1523 | name: "libx", |
| 1524 | shared_libs: ["libbar"], |
| 1525 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1526 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | cc_library { |
| 1530 | name: "libbar", |
| 1531 | stubs: { |
| 1532 | versions: ["29", "30"], |
| 1533 | }, |
| 1534 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1535 | `, func(fs map[string][]byte, config android.Config) { |
| 1536 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1537 | }) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1538 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1539 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1540 | libFlags := ld.Args["libFlags"] |
| 1541 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1542 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1543 | expectLink("libx", "shared_hwasan_myapex", "libbar", "shared_30") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1544 | } |
| 1545 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1546 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1547 | ctx, _ := testApex(t, ` |
| 1548 | apex { |
| 1549 | name: "myapex", |
| 1550 | key: "myapex.key", |
| 1551 | native_shared_libs: ["libx"], |
| 1552 | min_sdk_version: "29", |
| 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 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1564 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1565 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1566 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1567 | |
| 1568 | // ensure apex variant of c++ is linked with static unwinder |
| 1569 | cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module) |
| 1570 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped") |
| 1571 | // note that platform variant is not. |
| 1572 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 1573 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1574 | } |
| 1575 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1576 | func TestApexMinSdkVersion_ErrorIfIncompatibleStubs(t *testing.T) { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1577 | testApexError(t, `"libz" .*: not found a version\(<=29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1578 | apex { |
| 1579 | name: "myapex", |
| 1580 | key: "myapex.key", |
| 1581 | native_shared_libs: ["libx"], |
| 1582 | min_sdk_version: "29", |
| 1583 | } |
| 1584 | |
| 1585 | apex_key { |
| 1586 | name: "myapex.key", |
| 1587 | public_key: "testkey.avbpubkey", |
| 1588 | private_key: "testkey.pem", |
| 1589 | } |
| 1590 | |
| 1591 | cc_library { |
| 1592 | name: "libx", |
| 1593 | shared_libs: ["libz"], |
| 1594 | system_shared_libs: [], |
| 1595 | stl: "none", |
| 1596 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1597 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | cc_library { |
| 1601 | name: "libz", |
| 1602 | system_shared_libs: [], |
| 1603 | stl: "none", |
| 1604 | stubs: { |
| 1605 | versions: ["30"], |
| 1606 | }, |
| 1607 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1608 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1609 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1610 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1611 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 1612 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1613 | apex { |
| 1614 | name: "myapex", |
| 1615 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1616 | native_shared_libs: ["mylib"], |
| 1617 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | apex_key { |
| 1621 | name: "myapex.key", |
| 1622 | public_key: "testkey.avbpubkey", |
| 1623 | private_key: "testkey.pem", |
| 1624 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1625 | |
| 1626 | cc_library { |
| 1627 | name: "mylib", |
| 1628 | srcs: ["mylib.cpp"], |
| 1629 | system_shared_libs: [], |
| 1630 | stl: "none", |
| 1631 | apex_available: [ |
| 1632 | "myapex", |
| 1633 | ], |
| 1634 | min_sdk_version: "30", |
| 1635 | } |
| 1636 | `) |
| 1637 | } |
| 1638 | |
| 1639 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 1640 | testApex(t, ` |
| 1641 | apex { |
| 1642 | name: "myapex", |
| 1643 | key: "myapex.key", |
| 1644 | native_shared_libs: ["libfoo"], |
| 1645 | java_libs: ["libbar"], |
| 1646 | min_sdk_version: "29", |
| 1647 | } |
| 1648 | |
| 1649 | apex_key { |
| 1650 | name: "myapex.key", |
| 1651 | public_key: "testkey.avbpubkey", |
| 1652 | private_key: "testkey.pem", |
| 1653 | } |
| 1654 | |
| 1655 | cc_library { |
| 1656 | name: "libfoo", |
| 1657 | srcs: ["mylib.cpp"], |
| 1658 | shared_libs: ["libfoo_dep"], |
| 1659 | apex_available: ["myapex"], |
| 1660 | min_sdk_version: "29", |
| 1661 | } |
| 1662 | |
| 1663 | cc_library { |
| 1664 | name: "libfoo_dep", |
| 1665 | srcs: ["mylib.cpp"], |
| 1666 | apex_available: ["myapex"], |
| 1667 | min_sdk_version: "29", |
| 1668 | } |
| 1669 | |
| 1670 | java_library { |
| 1671 | name: "libbar", |
| 1672 | sdk_version: "current", |
| 1673 | srcs: ["a.java"], |
| 1674 | static_libs: ["libbar_dep"], |
| 1675 | apex_available: ["myapex"], |
| 1676 | min_sdk_version: "29", |
| 1677 | } |
| 1678 | |
| 1679 | java_library { |
| 1680 | name: "libbar_dep", |
| 1681 | sdk_version: "current", |
| 1682 | srcs: ["a.java"], |
| 1683 | apex_available: ["myapex"], |
| 1684 | min_sdk_version: "29", |
| 1685 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1686 | `) |
| 1687 | } |
| 1688 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1689 | func TestJavaStableSdkVersion(t *testing.T) { |
| 1690 | testCases := []struct { |
| 1691 | name string |
| 1692 | expectedError string |
| 1693 | bp string |
| 1694 | }{ |
| 1695 | { |
| 1696 | name: "Non-updatable apex with non-stable dep", |
| 1697 | bp: ` |
| 1698 | apex { |
| 1699 | name: "myapex", |
| 1700 | java_libs: ["myjar"], |
| 1701 | key: "myapex.key", |
| 1702 | } |
| 1703 | apex_key { |
| 1704 | name: "myapex.key", |
| 1705 | public_key: "testkey.avbpubkey", |
| 1706 | private_key: "testkey.pem", |
| 1707 | } |
| 1708 | java_library { |
| 1709 | name: "myjar", |
| 1710 | srcs: ["foo/bar/MyClass.java"], |
| 1711 | sdk_version: "core_platform", |
| 1712 | apex_available: ["myapex"], |
| 1713 | } |
| 1714 | `, |
| 1715 | }, |
| 1716 | { |
| 1717 | name: "Updatable apex with stable dep", |
| 1718 | bp: ` |
| 1719 | apex { |
| 1720 | name: "myapex", |
| 1721 | java_libs: ["myjar"], |
| 1722 | key: "myapex.key", |
| 1723 | updatable: true, |
| 1724 | min_sdk_version: "29", |
| 1725 | } |
| 1726 | apex_key { |
| 1727 | name: "myapex.key", |
| 1728 | public_key: "testkey.avbpubkey", |
| 1729 | private_key: "testkey.pem", |
| 1730 | } |
| 1731 | java_library { |
| 1732 | name: "myjar", |
| 1733 | srcs: ["foo/bar/MyClass.java"], |
| 1734 | sdk_version: "current", |
| 1735 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1736 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1737 | } |
| 1738 | `, |
| 1739 | }, |
| 1740 | { |
| 1741 | name: "Updatable apex with non-stable dep", |
| 1742 | expectedError: "cannot depend on \"myjar\"", |
| 1743 | bp: ` |
| 1744 | apex { |
| 1745 | name: "myapex", |
| 1746 | java_libs: ["myjar"], |
| 1747 | key: "myapex.key", |
| 1748 | updatable: true, |
| 1749 | } |
| 1750 | apex_key { |
| 1751 | name: "myapex.key", |
| 1752 | public_key: "testkey.avbpubkey", |
| 1753 | private_key: "testkey.pem", |
| 1754 | } |
| 1755 | java_library { |
| 1756 | name: "myjar", |
| 1757 | srcs: ["foo/bar/MyClass.java"], |
| 1758 | sdk_version: "core_platform", |
| 1759 | apex_available: ["myapex"], |
| 1760 | } |
| 1761 | `, |
| 1762 | }, |
| 1763 | { |
| 1764 | name: "Updatable apex with non-stable transitive dep", |
| 1765 | expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against non-public Android API.", |
| 1766 | bp: ` |
| 1767 | apex { |
| 1768 | name: "myapex", |
| 1769 | java_libs: ["myjar"], |
| 1770 | key: "myapex.key", |
| 1771 | updatable: true, |
| 1772 | } |
| 1773 | apex_key { |
| 1774 | name: "myapex.key", |
| 1775 | public_key: "testkey.avbpubkey", |
| 1776 | private_key: "testkey.pem", |
| 1777 | } |
| 1778 | java_library { |
| 1779 | name: "myjar", |
| 1780 | srcs: ["foo/bar/MyClass.java"], |
| 1781 | sdk_version: "current", |
| 1782 | apex_available: ["myapex"], |
| 1783 | static_libs: ["transitive-jar"], |
| 1784 | } |
| 1785 | java_library { |
| 1786 | name: "transitive-jar", |
| 1787 | srcs: ["foo/bar/MyClass.java"], |
| 1788 | sdk_version: "core_platform", |
| 1789 | apex_available: ["myapex"], |
| 1790 | } |
| 1791 | `, |
| 1792 | }, |
| 1793 | } |
| 1794 | |
| 1795 | for _, test := range testCases { |
| 1796 | t.Run(test.name, func(t *testing.T) { |
| 1797 | if test.expectedError == "" { |
| 1798 | testApex(t, test.bp) |
| 1799 | } else { |
| 1800 | testApexError(t, test.expectedError, test.bp) |
| 1801 | } |
| 1802 | }) |
| 1803 | } |
| 1804 | } |
| 1805 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1806 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 1807 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 1808 | apex { |
| 1809 | name: "myapex", |
| 1810 | key: "myapex.key", |
| 1811 | native_shared_libs: ["mylib"], |
| 1812 | min_sdk_version: "29", |
| 1813 | } |
| 1814 | |
| 1815 | apex_key { |
| 1816 | name: "myapex.key", |
| 1817 | public_key: "testkey.avbpubkey", |
| 1818 | private_key: "testkey.pem", |
| 1819 | } |
| 1820 | |
| 1821 | cc_library { |
| 1822 | name: "mylib", |
| 1823 | srcs: ["mylib.cpp"], |
| 1824 | shared_libs: ["mylib2"], |
| 1825 | system_shared_libs: [], |
| 1826 | stl: "none", |
| 1827 | apex_available: [ |
| 1828 | "myapex", |
| 1829 | ], |
| 1830 | min_sdk_version: "29", |
| 1831 | } |
| 1832 | |
| 1833 | // indirect part of the apex |
| 1834 | cc_library { |
| 1835 | name: "mylib2", |
| 1836 | srcs: ["mylib.cpp"], |
| 1837 | system_shared_libs: [], |
| 1838 | stl: "none", |
| 1839 | apex_available: [ |
| 1840 | "myapex", |
| 1841 | ], |
| 1842 | min_sdk_version: "30", |
| 1843 | } |
| 1844 | `) |
| 1845 | } |
| 1846 | |
| 1847 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 1848 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 1849 | apex { |
| 1850 | name: "myapex", |
| 1851 | key: "myapex.key", |
| 1852 | apps: ["AppFoo"], |
| 1853 | min_sdk_version: "29", |
| 1854 | } |
| 1855 | |
| 1856 | apex_key { |
| 1857 | name: "myapex.key", |
| 1858 | public_key: "testkey.avbpubkey", |
| 1859 | private_key: "testkey.pem", |
| 1860 | } |
| 1861 | |
| 1862 | android_app { |
| 1863 | name: "AppFoo", |
| 1864 | srcs: ["foo/bar/MyClass.java"], |
| 1865 | sdk_version: "current", |
| 1866 | min_sdk_version: "29", |
| 1867 | system_modules: "none", |
| 1868 | stl: "none", |
| 1869 | static_libs: ["bar"], |
| 1870 | apex_available: [ "myapex" ], |
| 1871 | } |
| 1872 | |
| 1873 | java_library { |
| 1874 | name: "bar", |
| 1875 | sdk_version: "current", |
| 1876 | srcs: ["a.java"], |
| 1877 | apex_available: [ "myapex" ], |
| 1878 | } |
| 1879 | `) |
| 1880 | } |
| 1881 | |
| 1882 | func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) { |
| 1883 | ctx, _ := testApex(t, ` |
| 1884 | apex { |
| 1885 | name: "myapex", |
| 1886 | key: "myapex.key", |
| 1887 | native_shared_libs: ["mylib"], |
| 1888 | min_sdk_version: "29", |
| 1889 | } |
| 1890 | |
| 1891 | apex_key { |
| 1892 | name: "myapex.key", |
| 1893 | public_key: "testkey.avbpubkey", |
| 1894 | private_key: "testkey.pem", |
| 1895 | } |
| 1896 | |
| 1897 | // mylib in myapex will link to mylib2#29 |
| 1898 | // mylib in otherapex will link to mylib2(non-stub) in otherapex as well |
| 1899 | cc_library { |
| 1900 | name: "mylib", |
| 1901 | srcs: ["mylib.cpp"], |
| 1902 | shared_libs: ["mylib2"], |
| 1903 | system_shared_libs: [], |
| 1904 | stl: "none", |
| 1905 | apex_available: ["myapex", "otherapex"], |
| 1906 | min_sdk_version: "29", |
| 1907 | } |
| 1908 | |
| 1909 | cc_library { |
| 1910 | name: "mylib2", |
| 1911 | srcs: ["mylib.cpp"], |
| 1912 | system_shared_libs: [], |
| 1913 | stl: "none", |
| 1914 | apex_available: ["otherapex"], |
| 1915 | stubs: { versions: ["29", "30"] }, |
| 1916 | min_sdk_version: "30", |
| 1917 | } |
| 1918 | |
| 1919 | apex { |
| 1920 | name: "otherapex", |
| 1921 | key: "myapex.key", |
| 1922 | native_shared_libs: ["mylib", "mylib2"], |
| 1923 | min_sdk_version: "30", |
| 1924 | } |
| 1925 | `) |
| 1926 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1927 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1928 | libFlags := ld.Args["libFlags"] |
| 1929 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1930 | } |
| 1931 | expectLink("mylib", "shared_myapex", "mylib2", "shared_29") |
| 1932 | expectLink("mylib", "shared_otherapex", "mylib2", "shared_otherapex") |
| 1933 | } |
| 1934 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1935 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1936 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1937 | apex { |
| 1938 | name: "myapex", |
| 1939 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1940 | native_shared_libs: ["mylib"], |
| 1941 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1942 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1943 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | apex_key { |
| 1947 | name: "myapex.key", |
| 1948 | public_key: "testkey.avbpubkey", |
| 1949 | private_key: "testkey.pem", |
| 1950 | } |
| 1951 | |
| 1952 | prebuilt_etc { |
| 1953 | name: "myetc", |
| 1954 | src: "myprebuilt", |
| 1955 | sub_dir: "foo/bar", |
| 1956 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1957 | |
| 1958 | cc_library { |
| 1959 | name: "mylib", |
| 1960 | srcs: ["mylib.cpp"], |
| 1961 | relative_install_path: "foo/bar", |
| 1962 | system_shared_libs: [], |
| 1963 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1964 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | cc_binary { |
| 1968 | name: "mybin", |
| 1969 | srcs: ["mylib.cpp"], |
| 1970 | relative_install_path: "foo/bar", |
| 1971 | system_shared_libs: [], |
| 1972 | static_executable: true, |
| 1973 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1974 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1975 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1976 | `) |
| 1977 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1978 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1979 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 1980 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1981 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1982 | ensureListContains(t, dirs, "etc") |
| 1983 | ensureListContains(t, dirs, "etc/foo") |
| 1984 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1985 | ensureListContains(t, dirs, "lib64") |
| 1986 | ensureListContains(t, dirs, "lib64/foo") |
| 1987 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 1988 | ensureListContains(t, dirs, "lib") |
| 1989 | ensureListContains(t, dirs, "lib/foo") |
| 1990 | ensureListContains(t, dirs, "lib/foo/bar") |
| 1991 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 1992 | ensureListContains(t, dirs, "bin") |
| 1993 | ensureListContains(t, dirs, "bin/foo") |
| 1994 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1995 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1996 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 1997 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
| 1998 | ctx, _ := testApex(t, ` |
| 1999 | apex { |
| 2000 | name: "myapex", |
| 2001 | key: "myapex.key", |
| 2002 | multilib: { |
| 2003 | both: { |
| 2004 | native_shared_libs: ["mylib"], |
| 2005 | binaries: ["mybin"], |
| 2006 | }, |
| 2007 | }, |
| 2008 | compile_multilib: "both", |
| 2009 | native_bridge_supported: true, |
| 2010 | } |
| 2011 | |
| 2012 | apex_key { |
| 2013 | name: "myapex.key", |
| 2014 | public_key: "testkey.avbpubkey", |
| 2015 | private_key: "testkey.pem", |
| 2016 | } |
| 2017 | |
| 2018 | cc_library { |
| 2019 | name: "mylib", |
| 2020 | relative_install_path: "foo/bar", |
| 2021 | system_shared_libs: [], |
| 2022 | stl: "none", |
| 2023 | apex_available: [ "myapex" ], |
| 2024 | native_bridge_supported: true, |
| 2025 | } |
| 2026 | |
| 2027 | cc_binary { |
| 2028 | name: "mybin", |
| 2029 | relative_install_path: "foo/bar", |
| 2030 | system_shared_libs: [], |
| 2031 | static_executable: true, |
| 2032 | stl: "none", |
| 2033 | apex_available: [ "myapex" ], |
| 2034 | native_bridge_supported: true, |
| 2035 | compile_multilib: "both", // default is "first" for binary |
| 2036 | multilib: { |
| 2037 | lib64: { |
| 2038 | suffix: "64", |
| 2039 | }, |
| 2040 | }, |
| 2041 | } |
| 2042 | `, withNativeBridgeEnabled) |
| 2043 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2044 | "bin/foo/bar/mybin", |
| 2045 | "bin/foo/bar/mybin64", |
| 2046 | "bin/arm/foo/bar/mybin", |
| 2047 | "bin/arm64/foo/bar/mybin64", |
| 2048 | "lib/foo/bar/mylib.so", |
| 2049 | "lib/arm/foo/bar/mylib.so", |
| 2050 | "lib64/foo/bar/mylib.so", |
| 2051 | "lib64/arm64/foo/bar/mylib.so", |
| 2052 | }) |
| 2053 | } |
| 2054 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2055 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2056 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2057 | apex { |
| 2058 | name: "myapex", |
| 2059 | key: "myapex.key", |
| 2060 | native_shared_libs: ["mylib"], |
| 2061 | use_vendor: true, |
| 2062 | } |
| 2063 | |
| 2064 | apex_key { |
| 2065 | name: "myapex.key", |
| 2066 | public_key: "testkey.avbpubkey", |
| 2067 | private_key: "testkey.pem", |
| 2068 | } |
| 2069 | |
| 2070 | cc_library { |
| 2071 | name: "mylib", |
| 2072 | srcs: ["mylib.cpp"], |
| 2073 | shared_libs: ["mylib2"], |
| 2074 | system_shared_libs: [], |
| 2075 | vendor_available: true, |
| 2076 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2077 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | cc_library { |
| 2081 | name: "mylib2", |
| 2082 | srcs: ["mylib.cpp"], |
| 2083 | system_shared_libs: [], |
| 2084 | vendor_available: true, |
| 2085 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2086 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2087 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2088 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2089 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2090 | }) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2091 | |
| 2092 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2093 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2094 | for _, implicit := range i.Implicits { |
| 2095 | inputsList = append(inputsList, implicit.String()) |
| 2096 | } |
| 2097 | } |
| 2098 | inputsString := strings.Join(inputsList, " ") |
| 2099 | |
| 2100 | // ensure that the apex includes vendor variants of the direct and indirect deps |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2101 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so") |
| 2102 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2103 | |
| 2104 | // ensure that the apex does not include core variants |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2105 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so") |
| 2106 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2107 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2108 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2109 | func TestUseVendorNotAllowedForSystemApexes(t *testing.T) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2110 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 2111 | apex { |
| 2112 | name: "myapex", |
| 2113 | key: "myapex.key", |
| 2114 | use_vendor: true, |
| 2115 | } |
| 2116 | apex_key { |
| 2117 | name: "myapex.key", |
| 2118 | public_key: "testkey.avbpubkey", |
| 2119 | private_key: "testkey.pem", |
| 2120 | } |
| 2121 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2122 | setUseVendorAllowListForTest(config, []string{""}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2123 | }) |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2124 | // no error with allow list |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2125 | testApex(t, ` |
| 2126 | apex { |
| 2127 | name: "myapex", |
| 2128 | key: "myapex.key", |
| 2129 | use_vendor: true, |
| 2130 | } |
| 2131 | apex_key { |
| 2132 | name: "myapex.key", |
| 2133 | public_key: "testkey.avbpubkey", |
| 2134 | private_key: "testkey.pem", |
| 2135 | } |
| 2136 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2137 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2138 | }) |
| 2139 | } |
| 2140 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2141 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 2142 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 2143 | apex { |
| 2144 | name: "myapex", |
| 2145 | key: "myapex.key", |
| 2146 | native_shared_libs: ["mylib"], |
| 2147 | use_vendor: true, |
| 2148 | } |
| 2149 | |
| 2150 | apex_key { |
| 2151 | name: "myapex.key", |
| 2152 | public_key: "testkey.avbpubkey", |
| 2153 | private_key: "testkey.pem", |
| 2154 | } |
| 2155 | |
| 2156 | cc_library { |
| 2157 | name: "mylib", |
| 2158 | srcs: ["mylib.cpp"], |
| 2159 | system_shared_libs: [], |
| 2160 | stl: "none", |
| 2161 | } |
| 2162 | `) |
| 2163 | } |
| 2164 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2165 | func TestVendorApex(t *testing.T) { |
| 2166 | ctx, config := testApex(t, ` |
| 2167 | apex { |
| 2168 | name: "myapex", |
| 2169 | key: "myapex.key", |
| 2170 | binaries: ["mybin"], |
| 2171 | vendor: true, |
| 2172 | } |
| 2173 | apex_key { |
| 2174 | name: "myapex.key", |
| 2175 | public_key: "testkey.avbpubkey", |
| 2176 | private_key: "testkey.pem", |
| 2177 | } |
| 2178 | cc_binary { |
| 2179 | name: "mybin", |
| 2180 | vendor: true, |
| 2181 | shared_libs: ["libfoo"], |
| 2182 | } |
| 2183 | cc_library { |
| 2184 | name: "libfoo", |
| 2185 | proprietary: true, |
| 2186 | } |
| 2187 | `) |
| 2188 | |
| 2189 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2190 | "bin/mybin", |
| 2191 | "lib64/libfoo.so", |
| 2192 | // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX |
| 2193 | "lib64/libc++.so", |
| 2194 | }) |
| 2195 | |
| 2196 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2197 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2198 | name := apexBundle.BaseModuleName() |
| 2199 | prefix := "TARGET_" |
| 2200 | var builder strings.Builder |
| 2201 | data.Custom(&builder, name, prefix, "", data) |
| 2202 | androidMk := builder.String() |
| 2203 | ensureContains(t, androidMk, `LOCAL_MODULE_PATH := /tmp/target/product/test_device/vendor/apex`) |
| 2204 | } |
| 2205 | |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2206 | func TestVendorApex_use_vndk_as_stable(t *testing.T) { |
| 2207 | ctx, _ := testApex(t, ` |
| 2208 | apex { |
| 2209 | name: "myapex", |
| 2210 | key: "myapex.key", |
| 2211 | binaries: ["mybin"], |
| 2212 | vendor: true, |
| 2213 | use_vndk_as_stable: true, |
| 2214 | } |
| 2215 | apex_key { |
| 2216 | name: "myapex.key", |
| 2217 | public_key: "testkey.avbpubkey", |
| 2218 | private_key: "testkey.pem", |
| 2219 | } |
| 2220 | cc_binary { |
| 2221 | name: "mybin", |
| 2222 | vendor: true, |
| 2223 | shared_libs: ["libvndk", "libvendor"], |
| 2224 | } |
| 2225 | cc_library { |
| 2226 | name: "libvndk", |
| 2227 | vndk: { |
| 2228 | enabled: true, |
| 2229 | }, |
| 2230 | vendor_available: true, |
| 2231 | } |
| 2232 | cc_library { |
| 2233 | name: "libvendor", |
| 2234 | vendor: true, |
| 2235 | } |
| 2236 | `) |
| 2237 | |
| 2238 | vendorVariant := "android_vendor.VER_arm64_armv8-a" |
| 2239 | |
| 2240 | ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_myapex").Rule("ld") |
| 2241 | libs := names(ldRule.Args["libFlags"]) |
| 2242 | // VNDK libs(libvndk/libc++) as they are |
| 2243 | ensureListContains(t, libs, buildDir+"/.intermediates/libvndk/"+vendorVariant+"_shared/libvndk.so") |
| 2244 | ensureListContains(t, libs, buildDir+"/.intermediates/libc++/"+vendorVariant+"_shared/libc++.so") |
| 2245 | // non-stable Vendor libs as APEX variants |
| 2246 | ensureListContains(t, libs, buildDir+"/.intermediates/libvendor/"+vendorVariant+"_shared_myapex/libvendor.so") |
| 2247 | |
| 2248 | // VNDK libs are not included when use_vndk_as_stable: true |
| 2249 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2250 | "bin/mybin", |
| 2251 | "lib64/libvendor.so", |
| 2252 | }) |
| 2253 | } |
| 2254 | |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2255 | func TestAndroidMk_UseVendorRequired(t *testing.T) { |
| 2256 | ctx, config := testApex(t, ` |
| 2257 | apex { |
| 2258 | name: "myapex", |
| 2259 | key: "myapex.key", |
| 2260 | use_vendor: true, |
| 2261 | native_shared_libs: ["mylib"], |
| 2262 | } |
| 2263 | |
| 2264 | apex_key { |
| 2265 | name: "myapex.key", |
| 2266 | public_key: "testkey.avbpubkey", |
| 2267 | private_key: "testkey.pem", |
| 2268 | } |
| 2269 | |
| 2270 | cc_library { |
| 2271 | name: "mylib", |
| 2272 | vendor_available: true, |
| 2273 | apex_available: ["myapex"], |
| 2274 | } |
| 2275 | `, func(fs map[string][]byte, config android.Config) { |
| 2276 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
| 2277 | }) |
| 2278 | |
| 2279 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2280 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2281 | name := apexBundle.BaseModuleName() |
| 2282 | prefix := "TARGET_" |
| 2283 | var builder strings.Builder |
| 2284 | data.Custom(&builder, name, prefix, "", data) |
| 2285 | androidMk := builder.String() |
| 2286 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc libm libdl\n") |
| 2287 | } |
| 2288 | |
| 2289 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
| 2290 | ctx, config := testApex(t, ` |
| 2291 | apex { |
| 2292 | name: "myapex", |
| 2293 | key: "myapex.key", |
| 2294 | vendor: true, |
| 2295 | native_shared_libs: ["mylib"], |
| 2296 | } |
| 2297 | |
| 2298 | apex_key { |
| 2299 | name: "myapex.key", |
| 2300 | public_key: "testkey.avbpubkey", |
| 2301 | private_key: "testkey.pem", |
| 2302 | } |
| 2303 | |
| 2304 | cc_library { |
| 2305 | name: "mylib", |
| 2306 | vendor_available: true, |
| 2307 | } |
| 2308 | `) |
| 2309 | |
| 2310 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2311 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2312 | name := apexBundle.BaseModuleName() |
| 2313 | prefix := "TARGET_" |
| 2314 | var builder strings.Builder |
| 2315 | data.Custom(&builder, name, prefix, "", data) |
| 2316 | androidMk := builder.String() |
| 2317 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc.vendor libm.vendor libdl.vendor\n") |
| 2318 | } |
| 2319 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2320 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
| 2321 | ctx, config := testApex(t, ` |
| 2322 | apex { |
| 2323 | name: "myapex", |
| 2324 | key: "myapex.key", |
| 2325 | vintf_fragments: ["fragment.xml"], |
| 2326 | init_rc: ["init.rc"], |
| 2327 | } |
| 2328 | apex_key { |
| 2329 | name: "myapex.key", |
| 2330 | public_key: "testkey.avbpubkey", |
| 2331 | private_key: "testkey.pem", |
| 2332 | } |
| 2333 | cc_binary { |
| 2334 | name: "mybin", |
| 2335 | } |
| 2336 | `) |
| 2337 | |
| 2338 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2339 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2340 | name := apexBundle.BaseModuleName() |
| 2341 | prefix := "TARGET_" |
| 2342 | var builder strings.Builder |
| 2343 | data.Custom(&builder, name, prefix, "", data) |
| 2344 | androidMk := builder.String() |
| 2345 | ensureContains(t, androidMk, "LOCAL_VINTF_FRAGMENTS := fragment.xml\n") |
| 2346 | ensureContains(t, androidMk, "LOCAL_INIT_RC := init.rc\n") |
| 2347 | } |
| 2348 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2349 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2350 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2351 | apex { |
| 2352 | name: "myapex", |
| 2353 | key: "myapex.key", |
| 2354 | native_shared_libs: ["mylib"], |
| 2355 | } |
| 2356 | |
| 2357 | apex_key { |
| 2358 | name: "myapex.key", |
| 2359 | public_key: "testkey.avbpubkey", |
| 2360 | private_key: "testkey.pem", |
| 2361 | } |
| 2362 | |
| 2363 | cc_library { |
| 2364 | name: "mylib", |
| 2365 | srcs: ["mylib.cpp"], |
| 2366 | system_shared_libs: [], |
| 2367 | stl: "none", |
| 2368 | stubs: { |
| 2369 | versions: ["1", "2", "3"], |
| 2370 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2371 | apex_available: [ |
| 2372 | "//apex_available:platform", |
| 2373 | "myapex", |
| 2374 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | cc_binary { |
| 2378 | name: "not_in_apex", |
| 2379 | srcs: ["mylib.cpp"], |
| 2380 | static_libs: ["mylib"], |
| 2381 | static_executable: true, |
| 2382 | system_shared_libs: [], |
| 2383 | stl: "none", |
| 2384 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2385 | `) |
| 2386 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2387 | 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] | 2388 | |
| 2389 | // 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] | 2390 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2391 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2392 | |
| 2393 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2394 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2395 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2396 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2397 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2398 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2399 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2400 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | cc_library { |
| 2404 | name: "mylib", |
| 2405 | srcs: ["mylib.cpp"], |
| 2406 | system_shared_libs: [], |
| 2407 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2408 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | apex_key { |
| 2412 | name: "myapex.key", |
| 2413 | public_key: "testkey.avbpubkey", |
| 2414 | private_key: "testkey.pem", |
| 2415 | } |
| 2416 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2417 | android_app_certificate { |
| 2418 | name: "myapex.certificate", |
| 2419 | certificate: "testkey", |
| 2420 | } |
| 2421 | |
| 2422 | android_app_certificate { |
| 2423 | name: "myapex.certificate.override", |
| 2424 | certificate: "testkey.override", |
| 2425 | } |
| 2426 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2427 | `) |
| 2428 | |
| 2429 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2430 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2431 | |
| 2432 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 2433 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 2434 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 2435 | } |
| 2436 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 2437 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 2438 | "vendor/foo/devkeys/testkey.pem") |
| 2439 | } |
| 2440 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2441 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2442 | 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] | 2443 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2444 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2445 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2446 | } |
| 2447 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2448 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2449 | func TestCertificate(t *testing.T) { |
| 2450 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 2451 | ctx, _ := testApex(t, ` |
| 2452 | apex { |
| 2453 | name: "myapex", |
| 2454 | key: "myapex.key", |
| 2455 | } |
| 2456 | apex_key { |
| 2457 | name: "myapex.key", |
| 2458 | public_key: "testkey.avbpubkey", |
| 2459 | private_key: "testkey.pem", |
| 2460 | }`) |
| 2461 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2462 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 2463 | if actual := rule.Args["certificates"]; actual != expected { |
| 2464 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2465 | } |
| 2466 | }) |
| 2467 | t.Run("override when unspecified", func(t *testing.T) { |
| 2468 | ctx, _ := testApex(t, ` |
| 2469 | apex { |
| 2470 | name: "myapex_keytest", |
| 2471 | key: "myapex.key", |
| 2472 | file_contexts: ":myapex-file_contexts", |
| 2473 | } |
| 2474 | apex_key { |
| 2475 | name: "myapex.key", |
| 2476 | public_key: "testkey.avbpubkey", |
| 2477 | private_key: "testkey.pem", |
| 2478 | } |
| 2479 | android_app_certificate { |
| 2480 | name: "myapex.certificate.override", |
| 2481 | certificate: "testkey.override", |
| 2482 | }`) |
| 2483 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2484 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2485 | if actual := rule.Args["certificates"]; actual != expected { |
| 2486 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2487 | } |
| 2488 | }) |
| 2489 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 2490 | ctx, _ := testApex(t, ` |
| 2491 | apex { |
| 2492 | name: "myapex", |
| 2493 | key: "myapex.key", |
| 2494 | certificate: ":myapex.certificate", |
| 2495 | } |
| 2496 | apex_key { |
| 2497 | name: "myapex.key", |
| 2498 | public_key: "testkey.avbpubkey", |
| 2499 | private_key: "testkey.pem", |
| 2500 | } |
| 2501 | android_app_certificate { |
| 2502 | name: "myapex.certificate", |
| 2503 | certificate: "testkey", |
| 2504 | }`) |
| 2505 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2506 | expected := "testkey.x509.pem testkey.pk8" |
| 2507 | if actual := rule.Args["certificates"]; actual != expected { |
| 2508 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2509 | } |
| 2510 | }) |
| 2511 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 2512 | ctx, _ := testApex(t, ` |
| 2513 | apex { |
| 2514 | name: "myapex_keytest", |
| 2515 | key: "myapex.key", |
| 2516 | file_contexts: ":myapex-file_contexts", |
| 2517 | certificate: ":myapex.certificate", |
| 2518 | } |
| 2519 | apex_key { |
| 2520 | name: "myapex.key", |
| 2521 | public_key: "testkey.avbpubkey", |
| 2522 | private_key: "testkey.pem", |
| 2523 | } |
| 2524 | android_app_certificate { |
| 2525 | name: "myapex.certificate.override", |
| 2526 | certificate: "testkey.override", |
| 2527 | }`) |
| 2528 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2529 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2530 | if actual := rule.Args["certificates"]; actual != expected { |
| 2531 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2532 | } |
| 2533 | }) |
| 2534 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 2535 | ctx, _ := testApex(t, ` |
| 2536 | apex { |
| 2537 | name: "myapex", |
| 2538 | key: "myapex.key", |
| 2539 | certificate: "testkey", |
| 2540 | } |
| 2541 | apex_key { |
| 2542 | name: "myapex.key", |
| 2543 | public_key: "testkey.avbpubkey", |
| 2544 | private_key: "testkey.pem", |
| 2545 | }`) |
| 2546 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2547 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 2548 | if actual := rule.Args["certificates"]; actual != expected { |
| 2549 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2550 | } |
| 2551 | }) |
| 2552 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 2553 | ctx, _ := testApex(t, ` |
| 2554 | apex { |
| 2555 | name: "myapex_keytest", |
| 2556 | key: "myapex.key", |
| 2557 | file_contexts: ":myapex-file_contexts", |
| 2558 | certificate: "testkey", |
| 2559 | } |
| 2560 | apex_key { |
| 2561 | name: "myapex.key", |
| 2562 | public_key: "testkey.avbpubkey", |
| 2563 | private_key: "testkey.pem", |
| 2564 | } |
| 2565 | android_app_certificate { |
| 2566 | name: "myapex.certificate.override", |
| 2567 | certificate: "testkey.override", |
| 2568 | }`) |
| 2569 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2570 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2571 | if actual := rule.Args["certificates"]; actual != expected { |
| 2572 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2573 | } |
| 2574 | }) |
| 2575 | } |
| 2576 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2577 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2578 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2579 | apex { |
| 2580 | name: "myapex", |
| 2581 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2582 | native_shared_libs: ["mylib", "mylib2"], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | apex { |
| 2586 | name: "otherapex", |
| 2587 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2588 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2589 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | apex_key { |
| 2593 | name: "myapex.key", |
| 2594 | public_key: "testkey.avbpubkey", |
| 2595 | private_key: "testkey.pem", |
| 2596 | } |
| 2597 | |
| 2598 | cc_library { |
| 2599 | name: "mylib", |
| 2600 | srcs: ["mylib.cpp"], |
| 2601 | system_shared_libs: [], |
| 2602 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2603 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2604 | "myapex", |
| 2605 | "otherapex", |
| 2606 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2607 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2608 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2609 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2610 | cc_library { |
| 2611 | name: "mylib2", |
| 2612 | srcs: ["mylib.cpp"], |
| 2613 | system_shared_libs: [], |
| 2614 | stl: "none", |
| 2615 | apex_available: [ |
| 2616 | "myapex", |
| 2617 | "otherapex", |
| 2618 | ], |
| 2619 | use_apex_name_macro: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2620 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2621 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2622 | `) |
| 2623 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2624 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2625 | 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] | 2626 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 2627 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2628 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2629 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2630 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 2631 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2632 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2633 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2634 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2635 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2636 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 2637 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2638 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2639 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2640 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2641 | // When cc_library sets use_apex_name_macro: true |
| 2642 | // apex variants define additional macro to distinguish which apex variant it is built for |
| 2643 | |
| 2644 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 2645 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 2646 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2647 | |
| 2648 | // APEX variant has __ANDROID_APEX__ defined |
| 2649 | 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] | 2650 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2651 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 2652 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2653 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2654 | // APEX variant has __ANDROID_APEX__ defined |
| 2655 | 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] | 2656 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2657 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 2658 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2659 | |
| 2660 | // recovery variant does not set __ANDROID_SDK_VERSION__ |
| 2661 | mylibCFlags = ctx.ModuleForTests("mylib", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 2662 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2663 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2664 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2665 | |
| 2666 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2667 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2668 | apex { |
| 2669 | name: "myapex", |
| 2670 | key: "myapex.key", |
| 2671 | native_shared_libs: ["mylib"], |
| 2672 | } |
| 2673 | |
| 2674 | apex_key { |
| 2675 | name: "myapex.key", |
| 2676 | public_key: "testkey.avbpubkey", |
| 2677 | private_key: "testkey.pem", |
| 2678 | } |
| 2679 | |
| 2680 | cc_library_headers { |
| 2681 | name: "mylib_headers", |
| 2682 | export_include_dirs: ["my_include"], |
| 2683 | system_shared_libs: [], |
| 2684 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2685 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | cc_library { |
| 2689 | name: "mylib", |
| 2690 | srcs: ["mylib.cpp"], |
| 2691 | system_shared_libs: [], |
| 2692 | stl: "none", |
| 2693 | header_libs: ["mylib_headers"], |
| 2694 | export_header_lib_headers: ["mylib_headers"], |
| 2695 | stubs: { |
| 2696 | versions: ["1", "2", "3"], |
| 2697 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2698 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | cc_library { |
| 2702 | name: "otherlib", |
| 2703 | srcs: ["mylib.cpp"], |
| 2704 | system_shared_libs: [], |
| 2705 | stl: "none", |
| 2706 | shared_libs: ["mylib"], |
| 2707 | } |
| 2708 | `) |
| 2709 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2710 | 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] | 2711 | |
| 2712 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 2713 | ensureContains(t, cFlags, "-Imy_include") |
| 2714 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2715 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2716 | type fileInApex struct { |
| 2717 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2718 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2719 | isLink bool |
| 2720 | } |
| 2721 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2722 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2723 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2724 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2725 | copyCmds := apexRule.Args["copy_commands"] |
| 2726 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2727 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2728 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 2729 | cmd = strings.TrimSpace(cmd) |
| 2730 | if cmd == "" { |
| 2731 | continue |
| 2732 | } |
| 2733 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2734 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2735 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2736 | switch terms[0] { |
| 2737 | case "mkdir": |
| 2738 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2739 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2740 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 2741 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2742 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2743 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2744 | isLink = false |
| 2745 | case "ln": |
| 2746 | if len(terms) != 3 && len(terms) != 4 { |
| 2747 | // ln LINK TARGET or ln -s LINK TARGET |
| 2748 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 2749 | } |
| 2750 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2751 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2752 | isLink = true |
| 2753 | default: |
| 2754 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 2755 | } |
| 2756 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2757 | index := strings.Index(dst, imageApexDir) |
| 2758 | if index == -1 { |
| 2759 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 2760 | } |
| 2761 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2762 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2763 | } |
| 2764 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2765 | return ret |
| 2766 | } |
| 2767 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2768 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 2769 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2770 | var failed bool |
| 2771 | var surplus []string |
| 2772 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2773 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2774 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2775 | for _, expected := range files { |
| 2776 | if matched, _ := path.Match(expected, file.path); matched { |
| 2777 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2778 | mactchFound = true |
| 2779 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2780 | } |
| 2781 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2782 | if !mactchFound { |
| 2783 | surplus = append(surplus, file.path) |
| 2784 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2785 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2786 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2787 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2788 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2789 | t.Log("surplus files", surplus) |
| 2790 | failed = true |
| 2791 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2792 | |
| 2793 | if len(files) > len(filesMatched) { |
| 2794 | var missing []string |
| 2795 | for _, expected := range files { |
| 2796 | if !filesMatched[expected] { |
| 2797 | missing = append(missing, expected) |
| 2798 | } |
| 2799 | } |
| 2800 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2801 | t.Log("missing files", missing) |
| 2802 | failed = true |
| 2803 | } |
| 2804 | if failed { |
| 2805 | t.Fail() |
| 2806 | } |
| 2807 | } |
| 2808 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2809 | func TestVndkApexCurrent(t *testing.T) { |
| 2810 | ctx, _ := testApex(t, ` |
| 2811 | apex_vndk { |
| 2812 | name: "myapex", |
| 2813 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | apex_key { |
| 2817 | name: "myapex.key", |
| 2818 | public_key: "testkey.avbpubkey", |
| 2819 | private_key: "testkey.pem", |
| 2820 | } |
| 2821 | |
| 2822 | cc_library { |
| 2823 | name: "libvndk", |
| 2824 | srcs: ["mylib.cpp"], |
| 2825 | vendor_available: true, |
| 2826 | vndk: { |
| 2827 | enabled: true, |
| 2828 | }, |
| 2829 | system_shared_libs: [], |
| 2830 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2831 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | cc_library { |
| 2835 | name: "libvndksp", |
| 2836 | srcs: ["mylib.cpp"], |
| 2837 | vendor_available: true, |
| 2838 | vndk: { |
| 2839 | enabled: true, |
| 2840 | support_system_process: true, |
| 2841 | }, |
| 2842 | system_shared_libs: [], |
| 2843 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2844 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2845 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2846 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2847 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2848 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2849 | "lib/libvndk.so", |
| 2850 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2851 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2852 | "lib64/libvndk.so", |
| 2853 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2854 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2855 | "etc/llndk.libraries.VER.txt", |
| 2856 | "etc/vndkcore.libraries.VER.txt", |
| 2857 | "etc/vndksp.libraries.VER.txt", |
| 2858 | "etc/vndkprivate.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2859 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 2863 | ctx, _ := testApex(t, ` |
| 2864 | apex_vndk { |
| 2865 | name: "myapex", |
| 2866 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | apex_key { |
| 2870 | name: "myapex.key", |
| 2871 | public_key: "testkey.avbpubkey", |
| 2872 | private_key: "testkey.pem", |
| 2873 | } |
| 2874 | |
| 2875 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2876 | name: "libvndk", |
| 2877 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2878 | vendor_available: true, |
| 2879 | vndk: { |
| 2880 | enabled: true, |
| 2881 | }, |
| 2882 | system_shared_libs: [], |
| 2883 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2884 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2885 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2886 | |
| 2887 | cc_prebuilt_library_shared { |
| 2888 | name: "libvndk.arm", |
| 2889 | srcs: ["libvndk.arm.so"], |
| 2890 | vendor_available: true, |
| 2891 | vndk: { |
| 2892 | enabled: true, |
| 2893 | }, |
| 2894 | enabled: false, |
| 2895 | arch: { |
| 2896 | arm: { |
| 2897 | enabled: true, |
| 2898 | }, |
| 2899 | }, |
| 2900 | system_shared_libs: [], |
| 2901 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2902 | apex_available: [ "myapex" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2903 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2904 | `+vndkLibrariesTxtFiles("current"), |
| 2905 | withFiles(map[string][]byte{ |
| 2906 | "libvndk.so": nil, |
| 2907 | "libvndk.arm.so": nil, |
| 2908 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2909 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2910 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2911 | "lib/libvndk.so", |
| 2912 | "lib/libvndk.arm.so", |
| 2913 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2914 | "lib/libc++.so", |
| 2915 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2916 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2917 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2918 | } |
| 2919 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2920 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 2921 | for _, v := range vers { |
| 2922 | if v == "current" { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 2923 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2924 | result += ` |
| 2925 | vndk_libraries_txt { |
| 2926 | name: "` + txt + `.libraries.txt", |
| 2927 | } |
| 2928 | ` |
| 2929 | } |
| 2930 | } else { |
| 2931 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
| 2932 | result += ` |
| 2933 | prebuilt_etc { |
| 2934 | name: "` + txt + `.libraries.` + v + `.txt", |
| 2935 | src: "dummy.txt", |
| 2936 | } |
| 2937 | ` |
| 2938 | } |
| 2939 | } |
| 2940 | } |
| 2941 | return |
| 2942 | } |
| 2943 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2944 | func TestVndkApexVersion(t *testing.T) { |
| 2945 | ctx, _ := testApex(t, ` |
| 2946 | apex_vndk { |
| 2947 | name: "myapex_v27", |
| 2948 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2949 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2950 | vndk_version: "27", |
| 2951 | } |
| 2952 | |
| 2953 | apex_key { |
| 2954 | name: "myapex.key", |
| 2955 | public_key: "testkey.avbpubkey", |
| 2956 | private_key: "testkey.pem", |
| 2957 | } |
| 2958 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2959 | vndk_prebuilt_shared { |
| 2960 | name: "libvndk27", |
| 2961 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2962 | vendor_available: true, |
| 2963 | vndk: { |
| 2964 | enabled: true, |
| 2965 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2966 | target_arch: "arm64", |
| 2967 | arch: { |
| 2968 | arm: { |
| 2969 | srcs: ["libvndk27_arm.so"], |
| 2970 | }, |
| 2971 | arm64: { |
| 2972 | srcs: ["libvndk27_arm64.so"], |
| 2973 | }, |
| 2974 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2975 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | vndk_prebuilt_shared { |
| 2979 | name: "libvndk27", |
| 2980 | version: "27", |
| 2981 | vendor_available: true, |
| 2982 | vndk: { |
| 2983 | enabled: true, |
| 2984 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2985 | target_arch: "x86_64", |
| 2986 | arch: { |
| 2987 | x86: { |
| 2988 | srcs: ["libvndk27_x86.so"], |
| 2989 | }, |
| 2990 | x86_64: { |
| 2991 | srcs: ["libvndk27_x86_64.so"], |
| 2992 | }, |
| 2993 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2994 | } |
| 2995 | `+vndkLibrariesTxtFiles("27"), |
| 2996 | withFiles(map[string][]byte{ |
| 2997 | "libvndk27_arm.so": nil, |
| 2998 | "libvndk27_arm64.so": nil, |
| 2999 | "libvndk27_x86.so": nil, |
| 3000 | "libvndk27_x86_64.so": nil, |
| 3001 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3002 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3003 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3004 | "lib/libvndk27_arm.so", |
| 3005 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3006 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3007 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { |
| 3011 | testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, ` |
| 3012 | apex_vndk { |
| 3013 | name: "myapex_v27", |
| 3014 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3015 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3016 | vndk_version: "27", |
| 3017 | } |
| 3018 | apex_vndk { |
| 3019 | name: "myapex_v27_other", |
| 3020 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3021 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3022 | vndk_version: "27", |
| 3023 | } |
| 3024 | |
| 3025 | apex_key { |
| 3026 | name: "myapex.key", |
| 3027 | public_key: "testkey.avbpubkey", |
| 3028 | private_key: "testkey.pem", |
| 3029 | } |
| 3030 | |
| 3031 | cc_library { |
| 3032 | name: "libvndk", |
| 3033 | srcs: ["mylib.cpp"], |
| 3034 | vendor_available: true, |
| 3035 | vndk: { |
| 3036 | enabled: true, |
| 3037 | }, |
| 3038 | system_shared_libs: [], |
| 3039 | stl: "none", |
| 3040 | } |
| 3041 | |
| 3042 | vndk_prebuilt_shared { |
| 3043 | name: "libvndk", |
| 3044 | version: "27", |
| 3045 | vendor_available: true, |
| 3046 | vndk: { |
| 3047 | enabled: true, |
| 3048 | }, |
| 3049 | srcs: ["libvndk.so"], |
| 3050 | } |
| 3051 | `, withFiles(map[string][]byte{ |
| 3052 | "libvndk.so": nil, |
| 3053 | })) |
| 3054 | } |
| 3055 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3056 | func TestVndkApexNameRule(t *testing.T) { |
| 3057 | ctx, _ := testApex(t, ` |
| 3058 | apex_vndk { |
| 3059 | name: "myapex", |
| 3060 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3061 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3062 | } |
| 3063 | apex_vndk { |
| 3064 | name: "myapex_v28", |
| 3065 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3066 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3067 | vndk_version: "28", |
| 3068 | } |
| 3069 | apex_key { |
| 3070 | name: "myapex.key", |
| 3071 | public_key: "testkey.avbpubkey", |
| 3072 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3073 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3074 | |
| 3075 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3076 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3077 | actual := proptools.String(bundle.properties.Apex_name) |
| 3078 | if !reflect.DeepEqual(actual, expected) { |
| 3079 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3080 | } |
| 3081 | } |
| 3082 | |
| 3083 | assertApexName("com.android.vndk.vVER", "myapex") |
| 3084 | assertApexName("com.android.vndk.v28", "myapex_v28") |
| 3085 | } |
| 3086 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3087 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 3088 | ctx, _ := testApex(t, ` |
| 3089 | apex_vndk { |
| 3090 | name: "myapex", |
| 3091 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3092 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | apex_key { |
| 3096 | name: "myapex.key", |
| 3097 | public_key: "testkey.avbpubkey", |
| 3098 | private_key: "testkey.pem", |
| 3099 | } |
| 3100 | |
| 3101 | cc_library { |
| 3102 | name: "libvndk", |
| 3103 | srcs: ["mylib.cpp"], |
| 3104 | vendor_available: true, |
| 3105 | native_bridge_supported: true, |
| 3106 | host_supported: true, |
| 3107 | vndk: { |
| 3108 | enabled: true, |
| 3109 | }, |
| 3110 | system_shared_libs: [], |
| 3111 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3112 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3113 | } |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3114 | `+vndkLibrariesTxtFiles("current"), withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3115 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3116 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3117 | "lib/libvndk.so", |
| 3118 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3119 | "lib/libc++.so", |
| 3120 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3121 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3122 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
| 3126 | testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
| 3127 | apex_vndk { |
| 3128 | name: "myapex", |
| 3129 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3130 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3131 | native_bridge_supported: true, |
| 3132 | } |
| 3133 | |
| 3134 | apex_key { |
| 3135 | name: "myapex.key", |
| 3136 | public_key: "testkey.avbpubkey", |
| 3137 | private_key: "testkey.pem", |
| 3138 | } |
| 3139 | |
| 3140 | cc_library { |
| 3141 | name: "libvndk", |
| 3142 | srcs: ["mylib.cpp"], |
| 3143 | vendor_available: true, |
| 3144 | native_bridge_supported: true, |
| 3145 | host_supported: true, |
| 3146 | vndk: { |
| 3147 | enabled: true, |
| 3148 | }, |
| 3149 | system_shared_libs: [], |
| 3150 | stl: "none", |
| 3151 | } |
| 3152 | `) |
| 3153 | } |
| 3154 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3155 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3156 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3157 | apex_vndk { |
| 3158 | name: "myapex_v27", |
| 3159 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3160 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3161 | vndk_version: "27", |
| 3162 | } |
| 3163 | |
| 3164 | apex_key { |
| 3165 | name: "myapex.key", |
| 3166 | public_key: "testkey.avbpubkey", |
| 3167 | private_key: "testkey.pem", |
| 3168 | } |
| 3169 | |
| 3170 | vndk_prebuilt_shared { |
| 3171 | name: "libvndk27", |
| 3172 | version: "27", |
| 3173 | target_arch: "arm", |
| 3174 | vendor_available: true, |
| 3175 | vndk: { |
| 3176 | enabled: true, |
| 3177 | }, |
| 3178 | arch: { |
| 3179 | arm: { |
| 3180 | srcs: ["libvndk27.so"], |
| 3181 | } |
| 3182 | }, |
| 3183 | } |
| 3184 | |
| 3185 | vndk_prebuilt_shared { |
| 3186 | name: "libvndk27", |
| 3187 | version: "27", |
| 3188 | target_arch: "arm", |
| 3189 | binder32bit: true, |
| 3190 | vendor_available: true, |
| 3191 | vndk: { |
| 3192 | enabled: true, |
| 3193 | }, |
| 3194 | arch: { |
| 3195 | arm: { |
| 3196 | srcs: ["libvndk27binder32.so"], |
| 3197 | } |
| 3198 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3199 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3200 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3201 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3202 | withFiles(map[string][]byte{ |
| 3203 | "libvndk27.so": nil, |
| 3204 | "libvndk27binder32.so": nil, |
| 3205 | }), |
| 3206 | withBinder32bit, |
| 3207 | withTargets(map[android.OsType][]android.Target{ |
| 3208 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3209 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3210 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3211 | }, |
| 3212 | }), |
| 3213 | ) |
| 3214 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3215 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3216 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3217 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3218 | }) |
| 3219 | } |
| 3220 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3221 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
| 3222 | ctx, _ := testApex(t, ` |
| 3223 | apex_vndk { |
| 3224 | name: "myapex", |
| 3225 | key: "myapex.key", |
| 3226 | file_contexts: ":myapex-file_contexts", |
| 3227 | } |
| 3228 | |
| 3229 | apex_key { |
| 3230 | name: "myapex.key", |
| 3231 | public_key: "testkey.avbpubkey", |
| 3232 | private_key: "testkey.pem", |
| 3233 | } |
| 3234 | |
| 3235 | cc_library { |
| 3236 | name: "libz", |
| 3237 | vendor_available: true, |
| 3238 | vndk: { |
| 3239 | enabled: true, |
| 3240 | }, |
| 3241 | stubs: { |
| 3242 | symbol_file: "libz.map.txt", |
| 3243 | versions: ["30"], |
| 3244 | } |
| 3245 | } |
| 3246 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3247 | "libz.map.txt": nil, |
| 3248 | })) |
| 3249 | |
| 3250 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_image").Rule("apexManifestRule") |
| 3251 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3252 | ensureListEmpty(t, provideNativeLibs) |
| 3253 | } |
| 3254 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3255 | func TestDependenciesInApexManifest(t *testing.T) { |
| 3256 | ctx, _ := testApex(t, ` |
| 3257 | apex { |
| 3258 | name: "myapex_nodep", |
| 3259 | key: "myapex.key", |
| 3260 | native_shared_libs: ["lib_nodep"], |
| 3261 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3262 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | apex { |
| 3266 | name: "myapex_dep", |
| 3267 | key: "myapex.key", |
| 3268 | native_shared_libs: ["lib_dep"], |
| 3269 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3270 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | apex { |
| 3274 | name: "myapex_provider", |
| 3275 | key: "myapex.key", |
| 3276 | native_shared_libs: ["libfoo"], |
| 3277 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3278 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | apex { |
| 3282 | name: "myapex_selfcontained", |
| 3283 | key: "myapex.key", |
| 3284 | native_shared_libs: ["lib_dep", "libfoo"], |
| 3285 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3286 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | apex_key { |
| 3290 | name: "myapex.key", |
| 3291 | public_key: "testkey.avbpubkey", |
| 3292 | private_key: "testkey.pem", |
| 3293 | } |
| 3294 | |
| 3295 | cc_library { |
| 3296 | name: "lib_nodep", |
| 3297 | srcs: ["mylib.cpp"], |
| 3298 | system_shared_libs: [], |
| 3299 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3300 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3301 | } |
| 3302 | |
| 3303 | cc_library { |
| 3304 | name: "lib_dep", |
| 3305 | srcs: ["mylib.cpp"], |
| 3306 | shared_libs: ["libfoo"], |
| 3307 | system_shared_libs: [], |
| 3308 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3309 | apex_available: [ |
| 3310 | "myapex_dep", |
| 3311 | "myapex_provider", |
| 3312 | "myapex_selfcontained", |
| 3313 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | cc_library { |
| 3317 | name: "libfoo", |
| 3318 | srcs: ["mytest.cpp"], |
| 3319 | stubs: { |
| 3320 | versions: ["1"], |
| 3321 | }, |
| 3322 | system_shared_libs: [], |
| 3323 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3324 | apex_available: [ |
| 3325 | "myapex_provider", |
| 3326 | "myapex_selfcontained", |
| 3327 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3328 | } |
| 3329 | `) |
| 3330 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3331 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3332 | var provideNativeLibs, requireNativeLibs []string |
| 3333 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3334 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3335 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3336 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3337 | ensureListEmpty(t, provideNativeLibs) |
| 3338 | ensureListEmpty(t, requireNativeLibs) |
| 3339 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3340 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3341 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3342 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3343 | ensureListEmpty(t, provideNativeLibs) |
| 3344 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 3345 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3346 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3347 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3348 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3349 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3350 | ensureListEmpty(t, requireNativeLibs) |
| 3351 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3352 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3353 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3354 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3355 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3356 | ensureListEmpty(t, requireNativeLibs) |
| 3357 | } |
| 3358 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3359 | func TestApexName(t *testing.T) { |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3360 | ctx, config := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3361 | apex { |
| 3362 | name: "myapex", |
| 3363 | key: "myapex.key", |
| 3364 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3365 | native_shared_libs: ["mylib"], |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | apex_key { |
| 3369 | name: "myapex.key", |
| 3370 | public_key: "testkey.avbpubkey", |
| 3371 | private_key: "testkey.pem", |
| 3372 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3373 | |
| 3374 | cc_library { |
| 3375 | name: "mylib", |
| 3376 | srcs: ["mylib.cpp"], |
| 3377 | system_shared_libs: [], |
| 3378 | stl: "none", |
| 3379 | apex_available: [ |
| 3380 | "//apex_available:platform", |
| 3381 | "myapex", |
| 3382 | ], |
| 3383 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3384 | `) |
| 3385 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3386 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3387 | apexManifestRule := module.Rule("apexManifestRule") |
| 3388 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 3389 | apexRule := module.Rule("apexRule") |
| 3390 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3391 | |
| 3392 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3393 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3394 | name := apexBundle.BaseModuleName() |
| 3395 | prefix := "TARGET_" |
| 3396 | var builder strings.Builder |
| 3397 | data.Custom(&builder, name, prefix, "", data) |
| 3398 | androidMk := builder.String() |
| 3399 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 3400 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3401 | } |
| 3402 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3403 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3404 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3405 | apex { |
| 3406 | name: "myapex", |
| 3407 | key: "myapex.key", |
| 3408 | native_shared_libs: ["mylib_common"], |
| 3409 | } |
| 3410 | |
| 3411 | apex_key { |
| 3412 | name: "myapex.key", |
| 3413 | public_key: "testkey.avbpubkey", |
| 3414 | private_key: "testkey.pem", |
| 3415 | } |
| 3416 | |
| 3417 | cc_library { |
| 3418 | name: "mylib_common", |
| 3419 | srcs: ["mylib.cpp"], |
| 3420 | system_shared_libs: [], |
| 3421 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3422 | apex_available: [ |
| 3423 | "//apex_available:platform", |
| 3424 | "myapex", |
| 3425 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3426 | } |
| 3427 | `) |
| 3428 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3429 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3430 | apexRule := module.Rule("apexRule") |
| 3431 | copyCmds := apexRule.Args["copy_commands"] |
| 3432 | |
| 3433 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 3434 | t.Log("Apex was a test apex!") |
| 3435 | t.Fail() |
| 3436 | } |
| 3437 | // Ensure that main rule creates an output |
| 3438 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3439 | |
| 3440 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3441 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3442 | |
| 3443 | // Ensure that both direct and indirect deps are copied into apex |
| 3444 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3445 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3446 | // Ensure that the platform variant ends with _shared |
| 3447 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3448 | |
| 3449 | if !android.InAnyApex("mylib_common") { |
| 3450 | t.Log("Found mylib_common not in any apex!") |
| 3451 | t.Fail() |
| 3452 | } |
| 3453 | } |
| 3454 | |
| 3455 | func TestTestApex(t *testing.T) { |
| 3456 | if android.InAnyApex("mylib_common_test") { |
| 3457 | t.Fatal("mylib_common_test must not be used in any other tests since this checks that global state is not updated in an illegal way!") |
| 3458 | } |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3459 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3460 | apex_test { |
| 3461 | name: "myapex", |
| 3462 | key: "myapex.key", |
| 3463 | native_shared_libs: ["mylib_common_test"], |
| 3464 | } |
| 3465 | |
| 3466 | apex_key { |
| 3467 | name: "myapex.key", |
| 3468 | public_key: "testkey.avbpubkey", |
| 3469 | private_key: "testkey.pem", |
| 3470 | } |
| 3471 | |
| 3472 | cc_library { |
| 3473 | name: "mylib_common_test", |
| 3474 | srcs: ["mylib.cpp"], |
| 3475 | system_shared_libs: [], |
| 3476 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3477 | // TODO: remove //apex_available:platform |
| 3478 | apex_available: [ |
| 3479 | "//apex_available:platform", |
| 3480 | "myapex", |
| 3481 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3482 | } |
| 3483 | `) |
| 3484 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3485 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3486 | apexRule := module.Rule("apexRule") |
| 3487 | copyCmds := apexRule.Args["copy_commands"] |
| 3488 | |
| 3489 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 3490 | t.Log("Apex was not a test apex!") |
| 3491 | t.Fail() |
| 3492 | } |
| 3493 | // Ensure that main rule creates an output |
| 3494 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3495 | |
| 3496 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3497 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3498 | |
| 3499 | // Ensure that both direct and indirect deps are copied into apex |
| 3500 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 3501 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3502 | // Ensure that the platform variant ends with _shared |
| 3503 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3504 | } |
| 3505 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3506 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3507 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3508 | apex { |
| 3509 | name: "myapex", |
| 3510 | key: "myapex.key", |
| 3511 | multilib: { |
| 3512 | first: { |
| 3513 | native_shared_libs: ["mylib_common"], |
| 3514 | } |
| 3515 | }, |
| 3516 | target: { |
| 3517 | android: { |
| 3518 | multilib: { |
| 3519 | first: { |
| 3520 | native_shared_libs: ["mylib"], |
| 3521 | } |
| 3522 | } |
| 3523 | }, |
| 3524 | host: { |
| 3525 | multilib: { |
| 3526 | first: { |
| 3527 | native_shared_libs: ["mylib2"], |
| 3528 | } |
| 3529 | } |
| 3530 | } |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | apex_key { |
| 3535 | name: "myapex.key", |
| 3536 | public_key: "testkey.avbpubkey", |
| 3537 | private_key: "testkey.pem", |
| 3538 | } |
| 3539 | |
| 3540 | cc_library { |
| 3541 | name: "mylib", |
| 3542 | srcs: ["mylib.cpp"], |
| 3543 | system_shared_libs: [], |
| 3544 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3545 | // TODO: remove //apex_available:platform |
| 3546 | apex_available: [ |
| 3547 | "//apex_available:platform", |
| 3548 | "myapex", |
| 3549 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | cc_library { |
| 3553 | name: "mylib_common", |
| 3554 | srcs: ["mylib.cpp"], |
| 3555 | system_shared_libs: [], |
| 3556 | stl: "none", |
| 3557 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3558 | // TODO: remove //apex_available:platform |
| 3559 | apex_available: [ |
| 3560 | "//apex_available:platform", |
| 3561 | "myapex", |
| 3562 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | cc_library { |
| 3566 | name: "mylib2", |
| 3567 | srcs: ["mylib.cpp"], |
| 3568 | system_shared_libs: [], |
| 3569 | stl: "none", |
| 3570 | compile_multilib: "first", |
| 3571 | } |
| 3572 | `) |
| 3573 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3574 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3575 | copyCmds := apexRule.Args["copy_commands"] |
| 3576 | |
| 3577 | // Ensure that main rule creates an output |
| 3578 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3579 | |
| 3580 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3581 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 3582 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
| 3583 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3584 | |
| 3585 | // Ensure that both direct and indirect deps are copied into apex |
| 3586 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 3587 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3588 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 3589 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3590 | // Ensure that the platform variant ends with _shared |
| 3591 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 3592 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 3593 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3594 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3595 | |
| 3596 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3597 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3598 | apex { |
| 3599 | name: "myapex", |
| 3600 | key: "myapex.key", |
| 3601 | binaries: ["myscript"], |
| 3602 | } |
| 3603 | |
| 3604 | apex_key { |
| 3605 | name: "myapex.key", |
| 3606 | public_key: "testkey.avbpubkey", |
| 3607 | private_key: "testkey.pem", |
| 3608 | } |
| 3609 | |
| 3610 | sh_binary { |
| 3611 | name: "myscript", |
| 3612 | src: "mylib.cpp", |
| 3613 | filename: "myscript.sh", |
| 3614 | sub_dir: "script", |
| 3615 | } |
| 3616 | `) |
| 3617 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3618 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3619 | copyCmds := apexRule.Args["copy_commands"] |
| 3620 | |
| 3621 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 3622 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3623 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3624 | func TestApexInVariousPartition(t *testing.T) { |
| 3625 | testcases := []struct { |
| 3626 | propName, parition, flattenedPartition string |
| 3627 | }{ |
| 3628 | {"", "system", "system_ext"}, |
| 3629 | {"product_specific: true", "product", "product"}, |
| 3630 | {"soc_specific: true", "vendor", "vendor"}, |
| 3631 | {"proprietary: true", "vendor", "vendor"}, |
| 3632 | {"vendor: true", "vendor", "vendor"}, |
| 3633 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 3634 | } |
| 3635 | for _, tc := range testcases { |
| 3636 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 3637 | ctx, _ := testApex(t, ` |
| 3638 | apex { |
| 3639 | name: "myapex", |
| 3640 | key: "myapex.key", |
| 3641 | `+tc.propName+` |
| 3642 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3643 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3644 | apex_key { |
| 3645 | name: "myapex.key", |
| 3646 | public_key: "testkey.avbpubkey", |
| 3647 | private_key: "testkey.pem", |
| 3648 | } |
| 3649 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3650 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3651 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3652 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 3653 | actual := apex.installDir.String() |
| 3654 | if actual != expected { |
| 3655 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 3656 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3657 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3658 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 3659 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 3660 | actual = flattened.installDir.String() |
| 3661 | if actual != expected { |
| 3662 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 3663 | } |
| 3664 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3665 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3666 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3667 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3668 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3669 | ctx, _ := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3670 | apex { |
| 3671 | name: "myapex", |
| 3672 | key: "myapex.key", |
| 3673 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3674 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3675 | apex_key { |
| 3676 | name: "myapex.key", |
| 3677 | public_key: "testkey.avbpubkey", |
| 3678 | private_key: "testkey.pem", |
| 3679 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3680 | `) |
| 3681 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3682 | rule := module.Output("file_contexts") |
| 3683 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 3684 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3685 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3686 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3687 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3688 | apex { |
| 3689 | name: "myapex", |
| 3690 | key: "myapex.key", |
| 3691 | file_contexts: "my_own_file_contexts", |
| 3692 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3693 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3694 | apex_key { |
| 3695 | name: "myapex.key", |
| 3696 | public_key: "testkey.avbpubkey", |
| 3697 | private_key: "testkey.pem", |
| 3698 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3699 | `, withFiles(map[string][]byte{ |
| 3700 | "my_own_file_contexts": nil, |
| 3701 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3702 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3703 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3704 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3705 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3706 | apex { |
| 3707 | name: "myapex", |
| 3708 | key: "myapex.key", |
| 3709 | product_specific: true, |
| 3710 | file_contexts: "product_specific_file_contexts", |
| 3711 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3712 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3713 | apex_key { |
| 3714 | name: "myapex.key", |
| 3715 | public_key: "testkey.avbpubkey", |
| 3716 | private_key: "testkey.pem", |
| 3717 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3718 | `) |
| 3719 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3720 | ctx, _ := testApex(t, ` |
| 3721 | apex { |
| 3722 | name: "myapex", |
| 3723 | key: "myapex.key", |
| 3724 | product_specific: true, |
| 3725 | file_contexts: "product_specific_file_contexts", |
| 3726 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3727 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3728 | apex_key { |
| 3729 | name: "myapex.key", |
| 3730 | public_key: "testkey.avbpubkey", |
| 3731 | private_key: "testkey.pem", |
| 3732 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3733 | `, withFiles(map[string][]byte{ |
| 3734 | "product_specific_file_contexts": nil, |
| 3735 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3736 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3737 | rule := module.Output("file_contexts") |
| 3738 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 3739 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3740 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3741 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
| 3742 | ctx, _ := testApex(t, ` |
| 3743 | apex { |
| 3744 | name: "myapex", |
| 3745 | key: "myapex.key", |
| 3746 | product_specific: true, |
| 3747 | file_contexts: ":my-file-contexts", |
| 3748 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3749 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3750 | apex_key { |
| 3751 | name: "myapex.key", |
| 3752 | public_key: "testkey.avbpubkey", |
| 3753 | private_key: "testkey.pem", |
| 3754 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3755 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3756 | filegroup { |
| 3757 | name: "my-file-contexts", |
| 3758 | srcs: ["product_specific_file_contexts"], |
| 3759 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3760 | `, withFiles(map[string][]byte{ |
| 3761 | "product_specific_file_contexts": nil, |
| 3762 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3763 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3764 | rule := module.Output("file_contexts") |
| 3765 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3766 | } |
| 3767 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3768 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3769 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3770 | apex_key { |
| 3771 | name: "myapex.key", |
| 3772 | public_key: ":my.avbpubkey", |
| 3773 | private_key: ":my.pem", |
| 3774 | product_specific: true, |
| 3775 | } |
| 3776 | |
| 3777 | filegroup { |
| 3778 | name: "my.avbpubkey", |
| 3779 | srcs: ["testkey2.avbpubkey"], |
| 3780 | } |
| 3781 | |
| 3782 | filegroup { |
| 3783 | name: "my.pem", |
| 3784 | srcs: ["testkey2.pem"], |
| 3785 | } |
| 3786 | `) |
| 3787 | |
| 3788 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 3789 | expected_pubkey := "testkey2.avbpubkey" |
| 3790 | actual_pubkey := apex_key.public_key_file.String() |
| 3791 | if actual_pubkey != expected_pubkey { |
| 3792 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 3793 | } |
| 3794 | expected_privkey := "testkey2.pem" |
| 3795 | actual_privkey := apex_key.private_key_file.String() |
| 3796 | if actual_privkey != expected_privkey { |
| 3797 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 3798 | } |
| 3799 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3800 | |
| 3801 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3802 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3803 | prebuilt_apex { |
| 3804 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 3805 | arch: { |
| 3806 | arm64: { |
| 3807 | src: "myapex-arm64.apex", |
| 3808 | }, |
| 3809 | arm: { |
| 3810 | src: "myapex-arm.apex", |
| 3811 | }, |
| 3812 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3813 | } |
| 3814 | `) |
| 3815 | |
| 3816 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 3817 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 3818 | expectedInput := "myapex-arm64.apex" |
| 3819 | if prebuilt.inputApex.String() != expectedInput { |
| 3820 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 3821 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3822 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 3823 | |
| 3824 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3825 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 3826 | prebuilt_apex { |
| 3827 | name: "myapex", |
| 3828 | src: "myapex-arm.apex", |
| 3829 | filename: "notmyapex.apex", |
| 3830 | } |
| 3831 | `) |
| 3832 | |
| 3833 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 3834 | |
| 3835 | expected := "notmyapex.apex" |
| 3836 | if p.installFilename != expected { |
| 3837 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 3838 | } |
| 3839 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 3840 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3841 | func TestPrebuiltOverrides(t *testing.T) { |
| 3842 | ctx, config := testApex(t, ` |
| 3843 | prebuilt_apex { |
| 3844 | name: "myapex.prebuilt", |
| 3845 | src: "myapex-arm.apex", |
| 3846 | overrides: [ |
| 3847 | "myapex", |
| 3848 | ], |
| 3849 | } |
| 3850 | `) |
| 3851 | |
| 3852 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 3853 | |
| 3854 | expected := []string{"myapex"} |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 3855 | actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3856 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 3857 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3858 | } |
| 3859 | } |
| 3860 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3861 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3862 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3863 | apex_test { |
| 3864 | name: "myapex", |
| 3865 | key: "myapex.key", |
| 3866 | tests: [ |
| 3867 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3868 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3869 | ], |
| 3870 | } |
| 3871 | |
| 3872 | apex_key { |
| 3873 | name: "myapex.key", |
| 3874 | public_key: "testkey.avbpubkey", |
| 3875 | private_key: "testkey.pem", |
| 3876 | } |
| 3877 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 3878 | filegroup { |
| 3879 | name: "fg", |
| 3880 | srcs: [ |
| 3881 | "baz", |
| 3882 | "bar/baz" |
| 3883 | ], |
| 3884 | } |
| 3885 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3886 | cc_test { |
| 3887 | name: "mytest", |
| 3888 | gtest: false, |
| 3889 | srcs: ["mytest.cpp"], |
| 3890 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 3891 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3892 | system_shared_libs: [], |
| 3893 | static_executable: true, |
| 3894 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 3895 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3896 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3897 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 3898 | cc_library { |
| 3899 | name: "mylib", |
| 3900 | srcs: ["mylib.cpp"], |
| 3901 | system_shared_libs: [], |
| 3902 | stl: "none", |
| 3903 | } |
| 3904 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 3905 | filegroup { |
| 3906 | name: "fg2", |
| 3907 | srcs: [ |
| 3908 | "testdata/baz" |
| 3909 | ], |
| 3910 | } |
| 3911 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3912 | cc_test { |
| 3913 | name: "mytests", |
| 3914 | gtest: false, |
| 3915 | srcs: [ |
| 3916 | "mytest1.cpp", |
| 3917 | "mytest2.cpp", |
| 3918 | "mytest3.cpp", |
| 3919 | ], |
| 3920 | test_per_src: true, |
| 3921 | relative_install_path: "test", |
| 3922 | system_shared_libs: [], |
| 3923 | static_executable: true, |
| 3924 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 3925 | data: [ |
| 3926 | ":fg", |
| 3927 | ":fg2", |
| 3928 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3929 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3930 | `) |
| 3931 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3932 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3933 | copyCmds := apexRule.Args["copy_commands"] |
| 3934 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 3935 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3936 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 3937 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3938 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 3939 | //Ensure that test data are copied into apex. |
| 3940 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 3941 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 3942 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3943 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 3944 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 3945 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 3946 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3947 | |
| 3948 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 3949 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3950 | data := android.AndroidMkDataForTest(t, config, "", bundle) |
| 3951 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3952 | prefix := "TARGET_" |
| 3953 | var builder strings.Builder |
| 3954 | data.Custom(&builder, name, prefix, "", data) |
| 3955 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3956 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 3957 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 3958 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 3959 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3960 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3961 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3962 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 3963 | |
| 3964 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 3965 | data = android.AndroidMkDataForTest(t, config, "", flatBundle) |
| 3966 | data.Custom(&builder, name, prefix, "", data) |
| 3967 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 3968 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 3969 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3970 | } |
| 3971 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 3972 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
| 3973 | ctx, config := testApex(t, ` |
| 3974 | apex { |
| 3975 | name: "myapex", |
| 3976 | key: "myapex.key", |
| 3977 | } |
| 3978 | apex_key { |
| 3979 | name: "myapex.key", |
| 3980 | public_key: "testkey.avbpubkey", |
| 3981 | private_key: "testkey.pem", |
| 3982 | } |
| 3983 | `, func(fs map[string][]byte, config android.Config) { |
| 3984 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 3985 | }) |
| 3986 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 3987 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 3988 | mk := android.AndroidMkDataForTest(t, config, "", ab) |
| 3989 | var builder strings.Builder |
| 3990 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 3991 | androidMk := builder.String() |
| 3992 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 3993 | } |
| 3994 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3995 | func TestApexUsesOtherApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3996 | ctx, _ := testApex(t, ` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3997 | apex { |
| 3998 | name: "myapex", |
| 3999 | key: "myapex.key", |
| 4000 | native_shared_libs: ["mylib"], |
| 4001 | uses: ["commonapex"], |
| 4002 | } |
| 4003 | |
| 4004 | apex { |
| 4005 | name: "commonapex", |
| 4006 | key: "myapex.key", |
| 4007 | native_shared_libs: ["libcommon"], |
| 4008 | provide_cpp_shared_libs: true, |
| 4009 | } |
| 4010 | |
| 4011 | apex_key { |
| 4012 | name: "myapex.key", |
| 4013 | public_key: "testkey.avbpubkey", |
| 4014 | private_key: "testkey.pem", |
| 4015 | } |
| 4016 | |
| 4017 | cc_library { |
| 4018 | name: "mylib", |
| 4019 | srcs: ["mylib.cpp"], |
| 4020 | shared_libs: ["libcommon"], |
| 4021 | system_shared_libs: [], |
| 4022 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4023 | apex_available: [ "myapex" ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4024 | } |
| 4025 | |
| 4026 | cc_library { |
| 4027 | name: "libcommon", |
| 4028 | srcs: ["mylib_common.cpp"], |
| 4029 | system_shared_libs: [], |
| 4030 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4031 | // TODO: remove //apex_available:platform |
| 4032 | apex_available: [ |
| 4033 | "//apex_available:platform", |
| 4034 | "commonapex", |
| 4035 | "myapex", |
| 4036 | ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4037 | } |
| 4038 | `) |
| 4039 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4040 | module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4041 | apexRule1 := module1.Rule("apexRule") |
| 4042 | copyCmds1 := apexRule1.Args["copy_commands"] |
| 4043 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4044 | module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4045 | apexRule2 := module2.Rule("apexRule") |
| 4046 | copyCmds2 := apexRule2.Args["copy_commands"] |
| 4047 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4048 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 4049 | ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4050 | ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so") |
| 4051 | ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so") |
| 4052 | ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so") |
| 4053 | } |
| 4054 | |
| 4055 | func TestApexUsesFailsIfNotProvided(t *testing.T) { |
| 4056 | testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, ` |
| 4057 | apex { |
| 4058 | name: "myapex", |
| 4059 | key: "myapex.key", |
| 4060 | uses: ["commonapex"], |
| 4061 | } |
| 4062 | |
| 4063 | apex { |
| 4064 | name: "commonapex", |
| 4065 | key: "myapex.key", |
| 4066 | } |
| 4067 | |
| 4068 | apex_key { |
| 4069 | name: "myapex.key", |
| 4070 | public_key: "testkey.avbpubkey", |
| 4071 | private_key: "testkey.pem", |
| 4072 | } |
| 4073 | `) |
| 4074 | testApexError(t, `uses: "commonapex" is not a provider`, ` |
| 4075 | apex { |
| 4076 | name: "myapex", |
| 4077 | key: "myapex.key", |
| 4078 | uses: ["commonapex"], |
| 4079 | } |
| 4080 | |
| 4081 | cc_library { |
| 4082 | name: "commonapex", |
| 4083 | system_shared_libs: [], |
| 4084 | stl: "none", |
| 4085 | } |
| 4086 | |
| 4087 | apex_key { |
| 4088 | name: "myapex.key", |
| 4089 | public_key: "testkey.avbpubkey", |
| 4090 | private_key: "testkey.pem", |
| 4091 | } |
| 4092 | `) |
| 4093 | } |
| 4094 | |
| 4095 | func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) { |
| 4096 | testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, ` |
| 4097 | apex { |
| 4098 | name: "myapex", |
| 4099 | key: "myapex.key", |
| 4100 | use_vendor: true, |
| 4101 | uses: ["commonapex"], |
| 4102 | } |
| 4103 | |
| 4104 | apex { |
| 4105 | name: "commonapex", |
| 4106 | key: "myapex.key", |
| 4107 | provide_cpp_shared_libs: true, |
| 4108 | } |
| 4109 | |
| 4110 | apex_key { |
| 4111 | name: "myapex.key", |
| 4112 | public_key: "testkey.avbpubkey", |
| 4113 | private_key: "testkey.pem", |
| 4114 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 4115 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 4116 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 4117 | }) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4118 | } |
| 4119 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4120 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 4121 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 4122 | apex { |
| 4123 | name: "myapex", |
| 4124 | key: "myapex.key", |
| 4125 | native_shared_libs: ["libfoo"], |
| 4126 | } |
| 4127 | |
| 4128 | apex_key { |
| 4129 | name: "myapex.key", |
| 4130 | public_key: "testkey.avbpubkey", |
| 4131 | private_key: "testkey.pem", |
| 4132 | } |
| 4133 | |
| 4134 | cc_library { |
| 4135 | name: "libfoo", |
| 4136 | stl: "none", |
| 4137 | system_shared_libs: [], |
| 4138 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4139 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4140 | } |
| 4141 | `) |
| 4142 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 4143 | apex { |
| 4144 | name: "myapex", |
| 4145 | key: "myapex.key", |
| 4146 | java_libs: ["myjar"], |
| 4147 | } |
| 4148 | |
| 4149 | apex_key { |
| 4150 | name: "myapex.key", |
| 4151 | public_key: "testkey.avbpubkey", |
| 4152 | private_key: "testkey.pem", |
| 4153 | } |
| 4154 | |
| 4155 | java_library { |
| 4156 | name: "myjar", |
| 4157 | srcs: ["foo/bar/MyClass.java"], |
| 4158 | sdk_version: "none", |
| 4159 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4160 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4161 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4162 | } |
| 4163 | `) |
| 4164 | } |
| 4165 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4166 | func TestApexWithApps(t *testing.T) { |
| 4167 | ctx, _ := testApex(t, ` |
| 4168 | apex { |
| 4169 | name: "myapex", |
| 4170 | key: "myapex.key", |
| 4171 | apps: [ |
| 4172 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4173 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4174 | ], |
| 4175 | } |
| 4176 | |
| 4177 | apex_key { |
| 4178 | name: "myapex.key", |
| 4179 | public_key: "testkey.avbpubkey", |
| 4180 | private_key: "testkey.pem", |
| 4181 | } |
| 4182 | |
| 4183 | android_app { |
| 4184 | name: "AppFoo", |
| 4185 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4186 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4187 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4188 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4189 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4190 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4191 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4192 | |
| 4193 | android_app { |
| 4194 | name: "AppFooPriv", |
| 4195 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4196 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4197 | system_modules: "none", |
| 4198 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4199 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4200 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4201 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4202 | |
| 4203 | cc_library_shared { |
| 4204 | name: "libjni", |
| 4205 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4206 | shared_libs: ["libfoo"], |
| 4207 | stl: "none", |
| 4208 | system_shared_libs: [], |
| 4209 | apex_available: [ "myapex" ], |
| 4210 | sdk_version: "current", |
| 4211 | } |
| 4212 | |
| 4213 | cc_library_shared { |
| 4214 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4215 | stl: "none", |
| 4216 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 4217 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4218 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4219 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4220 | `) |
| 4221 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4222 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4223 | apexRule := module.Rule("apexRule") |
| 4224 | copyCmds := apexRule.Args["copy_commands"] |
| 4225 | |
| 4226 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4227 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4228 | |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4229 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs") |
| 4230 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4231 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4232 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4233 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4234 | // JNI libraries including transitive deps are |
| 4235 | for _, jni := range []string{"libjni", "libfoo"} { |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 4236 | jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_sdk_shared_myapex").Module().(*cc.Module).OutputFile() |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4237 | // ... embedded inside APK (jnilibs.zip) |
| 4238 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 4239 | // ... and not directly inside the APEX |
| 4240 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 4241 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4242 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4243 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4244 | func TestApexWithAppImports(t *testing.T) { |
| 4245 | ctx, _ := testApex(t, ` |
| 4246 | apex { |
| 4247 | name: "myapex", |
| 4248 | key: "myapex.key", |
| 4249 | apps: [ |
| 4250 | "AppFooPrebuilt", |
| 4251 | "AppFooPrivPrebuilt", |
| 4252 | ], |
| 4253 | } |
| 4254 | |
| 4255 | apex_key { |
| 4256 | name: "myapex.key", |
| 4257 | public_key: "testkey.avbpubkey", |
| 4258 | private_key: "testkey.pem", |
| 4259 | } |
| 4260 | |
| 4261 | android_app_import { |
| 4262 | name: "AppFooPrebuilt", |
| 4263 | apk: "PrebuiltAppFoo.apk", |
| 4264 | presigned: true, |
| 4265 | dex_preopt: { |
| 4266 | enabled: false, |
| 4267 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4268 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | android_app_import { |
| 4272 | name: "AppFooPrivPrebuilt", |
| 4273 | apk: "PrebuiltAppFooPriv.apk", |
| 4274 | privileged: true, |
| 4275 | presigned: true, |
| 4276 | dex_preopt: { |
| 4277 | enabled: false, |
| 4278 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4279 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4280 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4281 | } |
| 4282 | `) |
| 4283 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4284 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4285 | apexRule := module.Rule("apexRule") |
| 4286 | copyCmds := apexRule.Args["copy_commands"] |
| 4287 | |
| 4288 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4289 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 4290 | } |
| 4291 | |
| 4292 | func TestApexWithAppImportsPrefer(t *testing.T) { |
| 4293 | ctx, _ := testApex(t, ` |
| 4294 | apex { |
| 4295 | name: "myapex", |
| 4296 | key: "myapex.key", |
| 4297 | apps: [ |
| 4298 | "AppFoo", |
| 4299 | ], |
| 4300 | } |
| 4301 | |
| 4302 | apex_key { |
| 4303 | name: "myapex.key", |
| 4304 | public_key: "testkey.avbpubkey", |
| 4305 | private_key: "testkey.pem", |
| 4306 | } |
| 4307 | |
| 4308 | android_app { |
| 4309 | name: "AppFoo", |
| 4310 | srcs: ["foo/bar/MyClass.java"], |
| 4311 | sdk_version: "none", |
| 4312 | system_modules: "none", |
| 4313 | apex_available: [ "myapex" ], |
| 4314 | } |
| 4315 | |
| 4316 | android_app_import { |
| 4317 | name: "AppFoo", |
| 4318 | apk: "AppFooPrebuilt.apk", |
| 4319 | filename: "AppFooPrebuilt.apk", |
| 4320 | presigned: true, |
| 4321 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4322 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4323 | } |
| 4324 | `, withFiles(map[string][]byte{ |
| 4325 | "AppFooPrebuilt.apk": nil, |
| 4326 | })) |
| 4327 | |
| 4328 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4329 | "app/AppFoo/AppFooPrebuilt.apk", |
| 4330 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4331 | } |
| 4332 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 4333 | func TestApexWithTestHelperApp(t *testing.T) { |
| 4334 | ctx, _ := testApex(t, ` |
| 4335 | apex { |
| 4336 | name: "myapex", |
| 4337 | key: "myapex.key", |
| 4338 | apps: [ |
| 4339 | "TesterHelpAppFoo", |
| 4340 | ], |
| 4341 | } |
| 4342 | |
| 4343 | apex_key { |
| 4344 | name: "myapex.key", |
| 4345 | public_key: "testkey.avbpubkey", |
| 4346 | private_key: "testkey.pem", |
| 4347 | } |
| 4348 | |
| 4349 | android_test_helper_app { |
| 4350 | name: "TesterHelpAppFoo", |
| 4351 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4352 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 4353 | } |
| 4354 | |
| 4355 | `) |
| 4356 | |
| 4357 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4358 | apexRule := module.Rule("apexRule") |
| 4359 | copyCmds := apexRule.Args["copy_commands"] |
| 4360 | |
| 4361 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 4362 | } |
| 4363 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 4364 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 4365 | // libfoo's apex_available comes from cc_defaults |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4366 | testApexError(t, `requires "libfoo" that is not available for the APEX`, ` |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 4367 | apex { |
| 4368 | name: "myapex", |
| 4369 | key: "myapex.key", |
| 4370 | native_shared_libs: ["libfoo"], |
| 4371 | } |
| 4372 | |
| 4373 | apex_key { |
| 4374 | name: "myapex.key", |
| 4375 | public_key: "testkey.avbpubkey", |
| 4376 | private_key: "testkey.pem", |
| 4377 | } |
| 4378 | |
| 4379 | apex { |
| 4380 | name: "otherapex", |
| 4381 | key: "myapex.key", |
| 4382 | native_shared_libs: ["libfoo"], |
| 4383 | } |
| 4384 | |
| 4385 | cc_defaults { |
| 4386 | name: "libfoo-defaults", |
| 4387 | apex_available: ["otherapex"], |
| 4388 | } |
| 4389 | |
| 4390 | cc_library { |
| 4391 | name: "libfoo", |
| 4392 | defaults: ["libfoo-defaults"], |
| 4393 | stl: "none", |
| 4394 | system_shared_libs: [], |
| 4395 | }`) |
| 4396 | } |
| 4397 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4398 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4399 | // libfoo is not available to myapex, but only to otherapex |
| 4400 | testApexError(t, "requires \"libfoo\" that is not available for the APEX", ` |
| 4401 | apex { |
| 4402 | name: "myapex", |
| 4403 | key: "myapex.key", |
| 4404 | native_shared_libs: ["libfoo"], |
| 4405 | } |
| 4406 | |
| 4407 | apex_key { |
| 4408 | name: "myapex.key", |
| 4409 | public_key: "testkey.avbpubkey", |
| 4410 | private_key: "testkey.pem", |
| 4411 | } |
| 4412 | |
| 4413 | apex { |
| 4414 | name: "otherapex", |
| 4415 | key: "otherapex.key", |
| 4416 | native_shared_libs: ["libfoo"], |
| 4417 | } |
| 4418 | |
| 4419 | apex_key { |
| 4420 | name: "otherapex.key", |
| 4421 | public_key: "testkey.avbpubkey", |
| 4422 | private_key: "testkey.pem", |
| 4423 | } |
| 4424 | |
| 4425 | cc_library { |
| 4426 | name: "libfoo", |
| 4427 | stl: "none", |
| 4428 | system_shared_libs: [], |
| 4429 | apex_available: ["otherapex"], |
| 4430 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4431 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4432 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4433 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4434 | // libbbaz is an indirect dep |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4435 | testApexError(t, `requires "libbaz" that is not available for the APEX. Dependency path: |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame^] | 4436 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4437 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame^] | 4438 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4439 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame^] | 4440 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 4441 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4442 | apex { |
| 4443 | name: "myapex", |
| 4444 | key: "myapex.key", |
| 4445 | native_shared_libs: ["libfoo"], |
| 4446 | } |
| 4447 | |
| 4448 | apex_key { |
| 4449 | name: "myapex.key", |
| 4450 | public_key: "testkey.avbpubkey", |
| 4451 | private_key: "testkey.pem", |
| 4452 | } |
| 4453 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4454 | cc_library { |
| 4455 | name: "libfoo", |
| 4456 | stl: "none", |
| 4457 | shared_libs: ["libbar"], |
| 4458 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4459 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4460 | } |
| 4461 | |
| 4462 | cc_library { |
| 4463 | name: "libbar", |
| 4464 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4465 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4466 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4467 | apex_available: ["myapex"], |
| 4468 | } |
| 4469 | |
| 4470 | cc_library { |
| 4471 | name: "libbaz", |
| 4472 | stl: "none", |
| 4473 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4474 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4475 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4476 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4477 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4478 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 4479 | apex { |
| 4480 | name: "myapex", |
| 4481 | key: "myapex.key", |
| 4482 | native_shared_libs: ["libfoo"], |
| 4483 | } |
| 4484 | |
| 4485 | apex_key { |
| 4486 | name: "myapex.key", |
| 4487 | public_key: "testkey.avbpubkey", |
| 4488 | private_key: "testkey.pem", |
| 4489 | } |
| 4490 | |
| 4491 | cc_library { |
| 4492 | name: "libfoo", |
| 4493 | stl: "none", |
| 4494 | system_shared_libs: [], |
| 4495 | apex_available: ["otherapex"], |
| 4496 | }`) |
| 4497 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4498 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4499 | apex { |
| 4500 | name: "myapex", |
| 4501 | key: "myapex.key", |
| 4502 | native_shared_libs: ["libfoo", "libbar"], |
| 4503 | } |
| 4504 | |
| 4505 | apex_key { |
| 4506 | name: "myapex.key", |
| 4507 | public_key: "testkey.avbpubkey", |
| 4508 | private_key: "testkey.pem", |
| 4509 | } |
| 4510 | |
| 4511 | cc_library { |
| 4512 | name: "libfoo", |
| 4513 | stl: "none", |
| 4514 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 4515 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4516 | apex_available: ["myapex"], |
| 4517 | } |
| 4518 | |
| 4519 | cc_library { |
| 4520 | name: "libbar", |
| 4521 | stl: "none", |
| 4522 | system_shared_libs: [], |
| 4523 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | cc_library { |
| 4527 | name: "libbaz", |
| 4528 | stl: "none", |
| 4529 | system_shared_libs: [], |
| 4530 | stubs: { |
| 4531 | versions: ["10", "20", "30"], |
| 4532 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4533 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4534 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4535 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4536 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4537 | ctx, _ := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4538 | apex { |
| 4539 | name: "myapex", |
| 4540 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4541 | native_shared_libs: ["libbar", "libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | apex_key { |
| 4545 | name: "myapex.key", |
| 4546 | public_key: "testkey.avbpubkey", |
| 4547 | private_key: "testkey.pem", |
| 4548 | } |
| 4549 | |
| 4550 | cc_library { |
| 4551 | name: "libfoo", |
| 4552 | stl: "none", |
| 4553 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4554 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4555 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | cc_library { |
| 4559 | name: "libfoo2", |
| 4560 | stl: "none", |
| 4561 | system_shared_libs: [], |
| 4562 | shared_libs: ["libbaz"], |
| 4563 | apex_available: ["//apex_available:platform"], |
| 4564 | } |
| 4565 | |
| 4566 | cc_library { |
| 4567 | name: "libbar", |
| 4568 | stl: "none", |
| 4569 | system_shared_libs: [], |
| 4570 | apex_available: ["myapex"], |
| 4571 | } |
| 4572 | |
| 4573 | cc_library { |
| 4574 | name: "libbaz", |
| 4575 | stl: "none", |
| 4576 | system_shared_libs: [], |
| 4577 | apex_available: ["myapex"], |
| 4578 | stubs: { |
| 4579 | versions: ["1"], |
| 4580 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4581 | }`) |
| 4582 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4583 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 4584 | // because it depends on libbar which isn't available to platform |
| 4585 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4586 | if libfoo.NotAvailableForPlatform() != true { |
| 4587 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 4588 | } |
| 4589 | |
| 4590 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 4591 | // stubs |
| 4592 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4593 | if libfoo2.NotAvailableForPlatform() == true { |
| 4594 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 4595 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4596 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 4597 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4598 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4599 | ctx, _ := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 4600 | apex { |
| 4601 | name: "myapex", |
| 4602 | key: "myapex.key", |
| 4603 | native_shared_libs: ["libfoo"], |
| 4604 | } |
| 4605 | |
| 4606 | apex_key { |
| 4607 | name: "myapex.key", |
| 4608 | public_key: "testkey.avbpubkey", |
| 4609 | private_key: "testkey.pem", |
| 4610 | } |
| 4611 | |
| 4612 | cc_library { |
| 4613 | name: "libfoo", |
| 4614 | stl: "none", |
| 4615 | system_shared_libs: [], |
| 4616 | apex_available: ["myapex"], |
| 4617 | static: { |
| 4618 | apex_available: ["//apex_available:platform"], |
| 4619 | }, |
| 4620 | }`) |
| 4621 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4622 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4623 | if libfooShared.NotAvailableForPlatform() != true { |
| 4624 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 4625 | } |
| 4626 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 4627 | if libfooStatic.NotAvailableForPlatform() != false { |
| 4628 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 4629 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4630 | } |
| 4631 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4632 | func TestOverrideApex(t *testing.T) { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4633 | ctx, config := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4634 | apex { |
| 4635 | name: "myapex", |
| 4636 | key: "myapex.key", |
| 4637 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 4638 | overrides: ["oldapex"], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | override_apex { |
| 4642 | name: "override_myapex", |
| 4643 | base: "myapex", |
| 4644 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 4645 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 4646 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 4647 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | apex_key { |
| 4651 | name: "myapex.key", |
| 4652 | public_key: "testkey.avbpubkey", |
| 4653 | private_key: "testkey.pem", |
| 4654 | } |
| 4655 | |
| 4656 | android_app { |
| 4657 | name: "app", |
| 4658 | srcs: ["foo/bar/MyClass.java"], |
| 4659 | package_name: "foo", |
| 4660 | sdk_version: "none", |
| 4661 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4662 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | override_android_app { |
| 4666 | name: "override_app", |
| 4667 | base: "app", |
| 4668 | package_name: "bar", |
| 4669 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 4670 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4671 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 4672 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 4673 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 4674 | if originalVariant.GetOverriddenBy() != "" { |
| 4675 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 4676 | } |
| 4677 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 4678 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 4679 | } |
| 4680 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4681 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 4682 | apexRule := module.Rule("apexRule") |
| 4683 | copyCmds := apexRule.Args["copy_commands"] |
| 4684 | |
| 4685 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4686 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4687 | |
| 4688 | apexBundle := module.Module().(*apexBundle) |
| 4689 | name := apexBundle.Name() |
| 4690 | if name != "override_myapex" { |
| 4691 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 4692 | } |
| 4693 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 4694 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 4695 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 4696 | } |
| 4697 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 4698 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 4699 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 4700 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4701 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 4702 | var builder strings.Builder |
| 4703 | data.Custom(&builder, name, "TARGET_", "", data) |
| 4704 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 4705 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4706 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 4707 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 4708 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4709 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 4710 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4711 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 4712 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4713 | } |
| 4714 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4715 | func TestLegacyAndroid10Support(t *testing.T) { |
| 4716 | ctx, _ := testApex(t, ` |
| 4717 | apex { |
| 4718 | name: "myapex", |
| 4719 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4720 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 4721 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | apex_key { |
| 4725 | name: "myapex.key", |
| 4726 | public_key: "testkey.avbpubkey", |
| 4727 | private_key: "testkey.pem", |
| 4728 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4729 | |
| 4730 | cc_library { |
| 4731 | name: "mylib", |
| 4732 | srcs: ["mylib.cpp"], |
| 4733 | stl: "libc++", |
| 4734 | system_shared_libs: [], |
| 4735 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 4736 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4737 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4738 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4739 | |
| 4740 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4741 | args := module.Rule("apexRule").Args |
| 4742 | 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] | 4743 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4744 | |
| 4745 | // The copies of the libraries in the apex should have one more dependency than |
| 4746 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 4747 | // the dependency names directly here but for some reason the names are blank in |
| 4748 | // this test. |
| 4749 | for _, lib := range []string{"libc++", "mylib"} { |
| 4750 | apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits |
| 4751 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 4752 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 4753 | t.Errorf("%q missing unwinder dep", lib) |
| 4754 | } |
| 4755 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4756 | } |
| 4757 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4758 | var filesForSdkLibrary = map[string][]byte{ |
| 4759 | "api/current.txt": nil, |
| 4760 | "api/removed.txt": nil, |
| 4761 | "api/system-current.txt": nil, |
| 4762 | "api/system-removed.txt": nil, |
| 4763 | "api/test-current.txt": nil, |
| 4764 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 4765 | |
| 4766 | // For java_sdk_library_import |
| 4767 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4768 | } |
| 4769 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4770 | func TestJavaSDKLibrary(t *testing.T) { |
| 4771 | ctx, _ := testApex(t, ` |
| 4772 | apex { |
| 4773 | name: "myapex", |
| 4774 | key: "myapex.key", |
| 4775 | java_libs: ["foo"], |
| 4776 | } |
| 4777 | |
| 4778 | apex_key { |
| 4779 | name: "myapex.key", |
| 4780 | public_key: "testkey.avbpubkey", |
| 4781 | private_key: "testkey.pem", |
| 4782 | } |
| 4783 | |
| 4784 | java_sdk_library { |
| 4785 | name: "foo", |
| 4786 | srcs: ["a.java"], |
| 4787 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4788 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4789 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4790 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4791 | |
| 4792 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 4793 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4794 | "javalib/foo.jar", |
| 4795 | "etc/permissions/foo.xml", |
| 4796 | }) |
| 4797 | // 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] | 4798 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 4799 | 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] | 4800 | } |
| 4801 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4802 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
| 4803 | ctx, _ := testApex(t, ` |
| 4804 | apex { |
| 4805 | name: "myapex", |
| 4806 | key: "myapex.key", |
| 4807 | java_libs: ["foo", "bar"], |
| 4808 | } |
| 4809 | |
| 4810 | apex_key { |
| 4811 | name: "myapex.key", |
| 4812 | public_key: "testkey.avbpubkey", |
| 4813 | private_key: "testkey.pem", |
| 4814 | } |
| 4815 | |
| 4816 | java_sdk_library { |
| 4817 | name: "foo", |
| 4818 | srcs: ["a.java"], |
| 4819 | api_packages: ["foo"], |
| 4820 | apex_available: ["myapex"], |
| 4821 | sdk_version: "none", |
| 4822 | system_modules: "none", |
| 4823 | } |
| 4824 | |
| 4825 | java_library { |
| 4826 | name: "bar", |
| 4827 | srcs: ["a.java"], |
| 4828 | libs: ["foo"], |
| 4829 | apex_available: ["myapex"], |
| 4830 | sdk_version: "none", |
| 4831 | system_modules: "none", |
| 4832 | } |
| 4833 | `, withFiles(filesForSdkLibrary)) |
| 4834 | |
| 4835 | // java_sdk_library installs both impl jar and permission XML |
| 4836 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4837 | "javalib/bar.jar", |
| 4838 | "javalib/foo.jar", |
| 4839 | "etc/permissions/foo.xml", |
| 4840 | }) |
| 4841 | |
| 4842 | // The bar library should depend on the implementation jar. |
| 4843 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 4844 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 4845 | t.Errorf("expected %q, found %#q", expected, actual) |
| 4846 | } |
| 4847 | } |
| 4848 | |
| 4849 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
| 4850 | ctx, _ := testApex(t, ` |
| 4851 | apex { |
| 4852 | name: "myapex", |
| 4853 | key: "myapex.key", |
| 4854 | java_libs: ["foo"], |
| 4855 | } |
| 4856 | |
| 4857 | apex_key { |
| 4858 | name: "myapex.key", |
| 4859 | public_key: "testkey.avbpubkey", |
| 4860 | private_key: "testkey.pem", |
| 4861 | } |
| 4862 | |
| 4863 | java_sdk_library { |
| 4864 | name: "foo", |
| 4865 | srcs: ["a.java"], |
| 4866 | api_packages: ["foo"], |
| 4867 | apex_available: ["myapex"], |
| 4868 | sdk_version: "none", |
| 4869 | system_modules: "none", |
| 4870 | } |
| 4871 | |
| 4872 | java_library { |
| 4873 | name: "bar", |
| 4874 | srcs: ["a.java"], |
| 4875 | libs: ["foo"], |
| 4876 | sdk_version: "none", |
| 4877 | system_modules: "none", |
| 4878 | } |
| 4879 | `, withFiles(filesForSdkLibrary)) |
| 4880 | |
| 4881 | // java_sdk_library installs both impl jar and permission XML |
| 4882 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4883 | "javalib/foo.jar", |
| 4884 | "etc/permissions/foo.xml", |
| 4885 | }) |
| 4886 | |
| 4887 | // The bar library should depend on the stubs jar. |
| 4888 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
| 4889 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 4890 | t.Errorf("expected %q, found %#q", expected, actual) |
| 4891 | } |
| 4892 | } |
| 4893 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 4894 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
| 4895 | ctx, _ := testApex(t, ``, |
| 4896 | withFiles(map[string][]byte{ |
| 4897 | "apex/a.java": nil, |
| 4898 | "apex/apex_manifest.json": nil, |
| 4899 | "apex/Android.bp": []byte(` |
| 4900 | package { |
| 4901 | default_visibility: ["//visibility:private"], |
| 4902 | } |
| 4903 | |
| 4904 | apex { |
| 4905 | name: "myapex", |
| 4906 | key: "myapex.key", |
| 4907 | java_libs: ["foo", "bar"], |
| 4908 | } |
| 4909 | |
| 4910 | apex_key { |
| 4911 | name: "myapex.key", |
| 4912 | public_key: "testkey.avbpubkey", |
| 4913 | private_key: "testkey.pem", |
| 4914 | } |
| 4915 | |
| 4916 | java_library { |
| 4917 | name: "bar", |
| 4918 | srcs: ["a.java"], |
| 4919 | libs: ["foo"], |
| 4920 | apex_available: ["myapex"], |
| 4921 | sdk_version: "none", |
| 4922 | system_modules: "none", |
| 4923 | } |
| 4924 | `), |
| 4925 | "source/a.java": nil, |
| 4926 | "source/api/current.txt": nil, |
| 4927 | "source/api/removed.txt": nil, |
| 4928 | "source/Android.bp": []byte(` |
| 4929 | package { |
| 4930 | default_visibility: ["//visibility:private"], |
| 4931 | } |
| 4932 | |
| 4933 | java_sdk_library { |
| 4934 | name: "foo", |
| 4935 | visibility: ["//apex"], |
| 4936 | srcs: ["a.java"], |
| 4937 | api_packages: ["foo"], |
| 4938 | apex_available: ["myapex"], |
| 4939 | sdk_version: "none", |
| 4940 | system_modules: "none", |
| 4941 | public: { |
| 4942 | enabled: true, |
| 4943 | }, |
| 4944 | } |
| 4945 | `), |
| 4946 | "prebuilt/a.jar": nil, |
| 4947 | "prebuilt/Android.bp": []byte(` |
| 4948 | package { |
| 4949 | default_visibility: ["//visibility:private"], |
| 4950 | } |
| 4951 | |
| 4952 | java_sdk_library_import { |
| 4953 | name: "foo", |
| 4954 | visibility: ["//apex", "//source"], |
| 4955 | apex_available: ["myapex"], |
| 4956 | prefer: true, |
| 4957 | public: { |
| 4958 | jars: ["a.jar"], |
| 4959 | }, |
| 4960 | } |
| 4961 | `), |
| 4962 | }), |
| 4963 | ) |
| 4964 | |
| 4965 | // java_sdk_library installs both impl jar and permission XML |
| 4966 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4967 | "javalib/bar.jar", |
| 4968 | "javalib/foo.jar", |
| 4969 | "etc/permissions/foo.xml", |
| 4970 | }) |
| 4971 | |
| 4972 | // The bar library should depend on the implementation jar. |
| 4973 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 4974 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.impl\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 4975 | t.Errorf("expected %q, found %#q", expected, actual) |
| 4976 | } |
| 4977 | } |
| 4978 | |
| 4979 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 4980 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 4981 | apex { |
| 4982 | name: "myapex", |
| 4983 | key: "myapex.key", |
| 4984 | java_libs: ["foo"], |
| 4985 | } |
| 4986 | |
| 4987 | apex_key { |
| 4988 | name: "myapex.key", |
| 4989 | public_key: "testkey.avbpubkey", |
| 4990 | private_key: "testkey.pem", |
| 4991 | } |
| 4992 | |
| 4993 | java_sdk_library_import { |
| 4994 | name: "foo", |
| 4995 | apex_available: ["myapex"], |
| 4996 | prefer: true, |
| 4997 | public: { |
| 4998 | jars: ["a.jar"], |
| 4999 | }, |
| 5000 | } |
| 5001 | |
| 5002 | `, withFiles(filesForSdkLibrary)) |
| 5003 | } |
| 5004 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5005 | func TestCompatConfig(t *testing.T) { |
| 5006 | ctx, _ := testApex(t, ` |
| 5007 | apex { |
| 5008 | name: "myapex", |
| 5009 | key: "myapex.key", |
| 5010 | prebuilts: ["myjar-platform-compat-config"], |
| 5011 | java_libs: ["myjar"], |
| 5012 | } |
| 5013 | |
| 5014 | apex_key { |
| 5015 | name: "myapex.key", |
| 5016 | public_key: "testkey.avbpubkey", |
| 5017 | private_key: "testkey.pem", |
| 5018 | } |
| 5019 | |
| 5020 | platform_compat_config { |
| 5021 | name: "myjar-platform-compat-config", |
| 5022 | src: ":myjar", |
| 5023 | } |
| 5024 | |
| 5025 | java_library { |
| 5026 | name: "myjar", |
| 5027 | srcs: ["foo/bar/MyClass.java"], |
| 5028 | sdk_version: "none", |
| 5029 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5030 | apex_available: [ "myapex" ], |
| 5031 | } |
| 5032 | `) |
| 5033 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5034 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 5035 | "javalib/myjar.jar", |
| 5036 | }) |
| 5037 | } |
| 5038 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5039 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 5040 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 5041 | apex { |
| 5042 | name: "myapex", |
| 5043 | key: "myapex.key", |
| 5044 | java_libs: ["myjar"], |
| 5045 | } |
| 5046 | |
| 5047 | apex_key { |
| 5048 | name: "myapex.key", |
| 5049 | public_key: "testkey.avbpubkey", |
| 5050 | private_key: "testkey.pem", |
| 5051 | } |
| 5052 | |
| 5053 | java_library { |
| 5054 | name: "myjar", |
| 5055 | srcs: ["foo/bar/MyClass.java"], |
| 5056 | sdk_version: "none", |
| 5057 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 5058 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5059 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5060 | } |
| 5061 | `) |
| 5062 | } |
| 5063 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5064 | func TestCarryRequiredModuleNames(t *testing.T) { |
| 5065 | ctx, config := testApex(t, ` |
| 5066 | apex { |
| 5067 | name: "myapex", |
| 5068 | key: "myapex.key", |
| 5069 | native_shared_libs: ["mylib"], |
| 5070 | } |
| 5071 | |
| 5072 | apex_key { |
| 5073 | name: "myapex.key", |
| 5074 | public_key: "testkey.avbpubkey", |
| 5075 | private_key: "testkey.pem", |
| 5076 | } |
| 5077 | |
| 5078 | cc_library { |
| 5079 | name: "mylib", |
| 5080 | srcs: ["mylib.cpp"], |
| 5081 | system_shared_libs: [], |
| 5082 | stl: "none", |
| 5083 | required: ["a", "b"], |
| 5084 | host_required: ["c", "d"], |
| 5085 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5086 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5087 | } |
| 5088 | `) |
| 5089 | |
| 5090 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 5091 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 5092 | name := apexBundle.BaseModuleName() |
| 5093 | prefix := "TARGET_" |
| 5094 | var builder strings.Builder |
| 5095 | data.Custom(&builder, name, prefix, "", data) |
| 5096 | androidMk := builder.String() |
| 5097 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 5098 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 5099 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 5100 | } |
| 5101 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5102 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 5103 | bp := ` |
| 5104 | apex { |
| 5105 | name: "myapex", |
| 5106 | key: "myapex.key", |
| 5107 | native_shared_libs: ["mylib"], |
| 5108 | java_libs: ["myjar"], |
| 5109 | } |
| 5110 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5111 | apex { |
| 5112 | name: "myapex.updatable", |
| 5113 | key: "myapex.key", |
| 5114 | native_shared_libs: ["mylib"], |
| 5115 | java_libs: ["myjar"], |
| 5116 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 5117 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5118 | } |
| 5119 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5120 | apex_key { |
| 5121 | name: "myapex.key", |
| 5122 | public_key: "testkey.avbpubkey", |
| 5123 | private_key: "testkey.pem", |
| 5124 | } |
| 5125 | |
| 5126 | cc_library { |
| 5127 | name: "mylib", |
| 5128 | srcs: ["mylib.cpp"], |
| 5129 | shared_libs: ["myotherlib"], |
| 5130 | system_shared_libs: [], |
| 5131 | stl: "none", |
| 5132 | apex_available: [ |
| 5133 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5134 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5135 | "//apex_available:platform", |
| 5136 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5137 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | cc_library { |
| 5141 | name: "myotherlib", |
| 5142 | srcs: ["mylib.cpp"], |
| 5143 | system_shared_libs: [], |
| 5144 | stl: "none", |
| 5145 | apex_available: [ |
| 5146 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5147 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5148 | "//apex_available:platform", |
| 5149 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5150 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5151 | } |
| 5152 | |
| 5153 | java_library { |
| 5154 | name: "myjar", |
| 5155 | srcs: ["foo/bar/MyClass.java"], |
| 5156 | sdk_version: "none", |
| 5157 | system_modules: "none", |
| 5158 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5159 | apex_available: [ |
| 5160 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5161 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5162 | "//apex_available:platform", |
| 5163 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5164 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | java_library { |
| 5168 | name: "myotherjar", |
| 5169 | srcs: ["foo/bar/MyClass.java"], |
| 5170 | sdk_version: "none", |
| 5171 | system_modules: "none", |
| 5172 | apex_available: [ |
| 5173 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5174 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5175 | "//apex_available:platform", |
| 5176 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5177 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5178 | } |
| 5179 | ` |
| 5180 | |
| 5181 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 5182 | for _, f := range files { |
| 5183 | if f.path == file { |
| 5184 | if f.isLink { |
| 5185 | t.Errorf("%q is not a real file", file) |
| 5186 | } |
| 5187 | return |
| 5188 | } |
| 5189 | } |
| 5190 | t.Errorf("%q is not found", file) |
| 5191 | } |
| 5192 | |
| 5193 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 5194 | for _, f := range files { |
| 5195 | if f.path == file { |
| 5196 | if !f.isLink { |
| 5197 | t.Errorf("%q is not a symlink", file) |
| 5198 | } |
| 5199 | return |
| 5200 | } |
| 5201 | } |
| 5202 | t.Errorf("%q is not found", file) |
| 5203 | } |
| 5204 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5205 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 5206 | // is updatable or not |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5207 | ctx, _ := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5208 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5209 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5210 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5211 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 5212 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5213 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 5214 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5215 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5216 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 5217 | |
| 5218 | // 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] | 5219 | ctx, _ = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5220 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5221 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5222 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5223 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5224 | |
| 5225 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 5226 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5227 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5228 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5229 | } |
| 5230 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 5231 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
| 5232 | ctx, config := testApex(t, ` |
| 5233 | apex { |
| 5234 | name: "myapex", |
| 5235 | key: "myapex.key", |
| 5236 | native_shared_libs: ["mylib"], |
| 5237 | } |
| 5238 | |
| 5239 | apex_key { |
| 5240 | name: "myapex.key", |
| 5241 | public_key: "testkey.avbpubkey", |
| 5242 | private_key: "testkey.pem", |
| 5243 | } |
| 5244 | |
| 5245 | cc_library_shared { |
| 5246 | name: "mylib", |
| 5247 | srcs: ["mylib.cpp"], |
| 5248 | shared_libs: ["myotherlib"], |
| 5249 | system_shared_libs: [], |
| 5250 | stl: "none", |
| 5251 | apex_available: [ |
| 5252 | "myapex", |
| 5253 | "//apex_available:platform", |
| 5254 | ], |
| 5255 | } |
| 5256 | |
| 5257 | cc_prebuilt_library_shared { |
| 5258 | name: "myotherlib", |
| 5259 | srcs: ["prebuilt.so"], |
| 5260 | system_shared_libs: [], |
| 5261 | stl: "none", |
| 5262 | apex_available: [ |
| 5263 | "myapex", |
| 5264 | "//apex_available:platform", |
| 5265 | ], |
| 5266 | } |
| 5267 | `) |
| 5268 | |
| 5269 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 5270 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 5271 | var builder strings.Builder |
| 5272 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 5273 | androidMk := builder.String() |
| 5274 | // `myotherlib` is added to `myapex` as symlink |
| 5275 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 5276 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 5277 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 5278 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
| 5279 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += mylib.myapex myotherlib apex_manifest.pb.myapex apex_pubkey.myapex\n") |
| 5280 | } |
| 5281 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 5282 | func TestApexWithJniLibs(t *testing.T) { |
| 5283 | ctx, _ := testApex(t, ` |
| 5284 | apex { |
| 5285 | name: "myapex", |
| 5286 | key: "myapex.key", |
| 5287 | jni_libs: ["mylib"], |
| 5288 | } |
| 5289 | |
| 5290 | apex_key { |
| 5291 | name: "myapex.key", |
| 5292 | public_key: "testkey.avbpubkey", |
| 5293 | private_key: "testkey.pem", |
| 5294 | } |
| 5295 | |
| 5296 | cc_library { |
| 5297 | name: "mylib", |
| 5298 | srcs: ["mylib.cpp"], |
| 5299 | shared_libs: ["mylib2"], |
| 5300 | system_shared_libs: [], |
| 5301 | stl: "none", |
| 5302 | apex_available: [ "myapex" ], |
| 5303 | } |
| 5304 | |
| 5305 | cc_library { |
| 5306 | name: "mylib2", |
| 5307 | srcs: ["mylib.cpp"], |
| 5308 | system_shared_libs: [], |
| 5309 | stl: "none", |
| 5310 | apex_available: [ "myapex" ], |
| 5311 | } |
| 5312 | `) |
| 5313 | |
| 5314 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 5315 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 5316 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 5317 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5318 | "lib64/mylib.so", |
| 5319 | "lib64/mylib2.so", |
| 5320 | }) |
| 5321 | } |
| 5322 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 5323 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
| 5324 | ctx, _ := testApex(t, ` |
| 5325 | apex { |
| 5326 | name: "myapex", |
| 5327 | key: "myapex.key", |
| 5328 | } |
| 5329 | apex_key { |
| 5330 | name: "myapex.key", |
| 5331 | public_key: "testkey.avbpubkey", |
| 5332 | private_key: "testkey.pem", |
| 5333 | } |
| 5334 | `, func(fs map[string][]byte, config android.Config) { |
| 5335 | delete(config.Targets, android.Android) |
| 5336 | config.AndroidCommonTarget = android.Target{} |
| 5337 | }) |
| 5338 | |
| 5339 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 5340 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 5341 | } |
| 5342 | } |
| 5343 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 5344 | func TestApexWithJniLibs_Errors(t *testing.T) { |
| 5345 | testApexError(t, `jni_libs: "xxx" is not a cc_library`, ` |
| 5346 | apex { |
| 5347 | name: "myapex", |
| 5348 | key: "myapex.key", |
| 5349 | jni_libs: ["xxx"], |
| 5350 | } |
| 5351 | |
| 5352 | apex_key { |
| 5353 | name: "myapex.key", |
| 5354 | public_key: "testkey.avbpubkey", |
| 5355 | private_key: "testkey.pem", |
| 5356 | } |
| 5357 | |
| 5358 | prebuilt_etc { |
| 5359 | name: "xxx", |
| 5360 | src: "xxx", |
| 5361 | } |
| 5362 | `, withFiles(map[string][]byte{ |
| 5363 | "xxx": nil, |
| 5364 | })) |
| 5365 | } |
| 5366 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 5367 | func TestAppBundle(t *testing.T) { |
| 5368 | ctx, _ := testApex(t, ` |
| 5369 | apex { |
| 5370 | name: "myapex", |
| 5371 | key: "myapex.key", |
| 5372 | apps: ["AppFoo"], |
| 5373 | } |
| 5374 | |
| 5375 | apex_key { |
| 5376 | name: "myapex.key", |
| 5377 | public_key: "testkey.avbpubkey", |
| 5378 | private_key: "testkey.pem", |
| 5379 | } |
| 5380 | |
| 5381 | android_app { |
| 5382 | name: "AppFoo", |
| 5383 | srcs: ["foo/bar/MyClass.java"], |
| 5384 | sdk_version: "none", |
| 5385 | system_modules: "none", |
| 5386 | apex_available: [ "myapex" ], |
| 5387 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 5388 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 5389 | |
| 5390 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config") |
| 5391 | content := bundleConfigRule.Args["content"] |
| 5392 | |
| 5393 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 5394 | 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] | 5395 | } |
| 5396 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5397 | func TestAppSetBundle(t *testing.T) { |
| 5398 | ctx, _ := testApex(t, ` |
| 5399 | apex { |
| 5400 | name: "myapex", |
| 5401 | key: "myapex.key", |
| 5402 | apps: ["AppSet"], |
| 5403 | } |
| 5404 | |
| 5405 | apex_key { |
| 5406 | name: "myapex.key", |
| 5407 | public_key: "testkey.avbpubkey", |
| 5408 | private_key: "testkey.pem", |
| 5409 | } |
| 5410 | |
| 5411 | android_app_set { |
| 5412 | name: "AppSet", |
| 5413 | set: "AppSet.apks", |
| 5414 | }`) |
| 5415 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5416 | bundleConfigRule := mod.Description("Bundle Config") |
| 5417 | content := bundleConfigRule.Args["content"] |
| 5418 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 5419 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 5420 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 5421 | if len(copyCmds) != 3 { |
| 5422 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 5423 | } |
| 5424 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 5425 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 5426 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 5427 | } |
| 5428 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5429 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5430 | t.Helper() |
| 5431 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5432 | bp := ` |
| 5433 | java_library { |
| 5434 | name: "some-updatable-apex-lib", |
| 5435 | srcs: ["a.java"], |
| 5436 | sdk_version: "current", |
| 5437 | apex_available: [ |
| 5438 | "some-updatable-apex", |
| 5439 | ], |
| 5440 | } |
| 5441 | |
| 5442 | java_library { |
| 5443 | name: "some-non-updatable-apex-lib", |
| 5444 | srcs: ["a.java"], |
| 5445 | apex_available: [ |
| 5446 | "some-non-updatable-apex", |
| 5447 | ], |
| 5448 | } |
| 5449 | |
| 5450 | java_library { |
| 5451 | name: "some-platform-lib", |
| 5452 | srcs: ["a.java"], |
| 5453 | sdk_version: "current", |
| 5454 | installable: true, |
| 5455 | } |
| 5456 | |
| 5457 | java_library { |
| 5458 | name: "some-art-lib", |
| 5459 | srcs: ["a.java"], |
| 5460 | sdk_version: "current", |
| 5461 | apex_available: [ |
| 5462 | "com.android.art.something", |
| 5463 | ], |
| 5464 | hostdex: true, |
| 5465 | } |
| 5466 | |
| 5467 | apex { |
| 5468 | name: "some-updatable-apex", |
| 5469 | key: "some-updatable-apex.key", |
| 5470 | java_libs: ["some-updatable-apex-lib"], |
| 5471 | updatable: true, |
| 5472 | min_sdk_version: "current", |
| 5473 | } |
| 5474 | |
| 5475 | apex { |
| 5476 | name: "some-non-updatable-apex", |
| 5477 | key: "some-non-updatable-apex.key", |
| 5478 | java_libs: ["some-non-updatable-apex-lib"], |
| 5479 | } |
| 5480 | |
| 5481 | apex_key { |
| 5482 | name: "some-updatable-apex.key", |
| 5483 | } |
| 5484 | |
| 5485 | apex_key { |
| 5486 | name: "some-non-updatable-apex.key", |
| 5487 | } |
| 5488 | |
| 5489 | apex { |
| 5490 | name: "com.android.art.something", |
| 5491 | key: "com.android.art.something.key", |
| 5492 | java_libs: ["some-art-lib"], |
| 5493 | updatable: true, |
| 5494 | min_sdk_version: "current", |
| 5495 | } |
| 5496 | |
| 5497 | apex_key { |
| 5498 | name: "com.android.art.something.key", |
| 5499 | } |
| 5500 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5501 | filegroup { |
| 5502 | name: "some-updatable-apex-file_contexts", |
| 5503 | srcs: [ |
| 5504 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 5505 | ], |
| 5506 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5507 | |
| 5508 | filegroup { |
| 5509 | name: "some-non-updatable-apex-file_contexts", |
| 5510 | srcs: [ |
| 5511 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 5512 | ], |
| 5513 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5514 | ` |
| 5515 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 5516 | bp += java.GatherRequiredDepsForTest() |
| 5517 | bp += dexpreopt.BpToolModulesForTest() |
| 5518 | |
| 5519 | fs := map[string][]byte{ |
| 5520 | "a.java": nil, |
| 5521 | "a.jar": nil, |
| 5522 | "build/make/target/product/security": nil, |
| 5523 | "apex_manifest.json": nil, |
| 5524 | "AndroidManifest.xml": nil, |
| 5525 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5526 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5527 | "system/sepolicy/apex/com.android.art.something-file_contexts": nil, |
| 5528 | "framework/aidl/a.aidl": nil, |
| 5529 | } |
| 5530 | cc.GatherRequiredFilesForTest(fs) |
| 5531 | |
| 5532 | ctx := android.NewTestArchContext() |
| 5533 | ctx.RegisterModuleType("apex", BundleFactory) |
| 5534 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 5535 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 5536 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5537 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
| 5538 | java.RegisterJavaBuildComponents(ctx) |
| 5539 | java.RegisterSystemModulesBuildComponents(ctx) |
| 5540 | java.RegisterAppBuildComponents(ctx) |
| 5541 | java.RegisterDexpreoptBootJarsComponents(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5542 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 5543 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 5544 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 5545 | |
| 5546 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 5547 | ctx.Register(config) |
| 5548 | |
| 5549 | _ = dexpreopt.GlobalSoongConfigForTests(config) |
| 5550 | dexpreopt.RegisterToolModulesForTest(ctx) |
| 5551 | pathCtx := android.PathContextForTesting(config) |
| 5552 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 5553 | transformDexpreoptConfig(dexpreoptConfig) |
| 5554 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 5555 | |
| 5556 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 5557 | android.FailIfErrored(t, errs) |
| 5558 | |
| 5559 | _, errs = ctx.PrepareBuildActions(config) |
| 5560 | if errmsg == "" { |
| 5561 | android.FailIfErrored(t, errs) |
| 5562 | } else if len(errs) > 0 { |
| 5563 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 5564 | return |
| 5565 | } else { |
| 5566 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 5567 | } |
| 5568 | } |
| 5569 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 5570 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 5571 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 5572 | apex { |
| 5573 | name: "myapex", |
| 5574 | key: "myapex.key", |
| 5575 | updatable: true, |
| 5576 | } |
| 5577 | |
| 5578 | apex_key { |
| 5579 | name: "myapex.key", |
| 5580 | public_key: "testkey.avbpubkey", |
| 5581 | private_key: "testkey.pem", |
| 5582 | } |
| 5583 | `) |
| 5584 | } |
| 5585 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5586 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5587 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5588 | var err string |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5589 | var transform func(*dexpreopt.GlobalConfig) |
| 5590 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5591 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
| 5592 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5593 | config.ArtApexJars = []string{"com.android.art.something:some-art-lib"} |
| 5594 | } |
| 5595 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 5596 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5597 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5598 | t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5599 | err = "module 'some-art-lib' from updatable apex 'com.android.art.something' is not allowed in the framework boot image" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5600 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5601 | config.BootJars = []string{"com.android.art.something:some-art-lib"} |
| 5602 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5603 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5604 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5605 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5606 | t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5607 | err = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the ART boot image" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5608 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5609 | config.ArtApexJars = []string{"some-updatable-apex:some-updatable-apex-lib"} |
| 5610 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5611 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5612 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5613 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5614 | t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5615 | 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] | 5616 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5617 | config.ArtApexJars = []string{"some-non-updatable-apex:some-non-updatable-apex-lib"} |
| 5618 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5619 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5620 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5621 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5622 | t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5623 | err = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the framework boot image" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5624 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5625 | config.BootJars = []string{"some-updatable-apex:some-updatable-apex-lib"} |
| 5626 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5627 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5628 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5629 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5630 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
| 5631 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5632 | config.BootJars = []string{"some-non-updatable-apex:some-non-updatable-apex-lib"} |
| 5633 | } |
| 5634 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 5635 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5636 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5637 | 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] | 5638 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5639 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5640 | config.ArtApexJars = []string{"platform:nonexistent"} |
| 5641 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5642 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5643 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5644 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5645 | 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] | 5646 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5647 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5648 | config.BootJars = []string{"platform:nonexistent"} |
| 5649 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5650 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5651 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5652 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5653 | t.Run("platform jar in the ART boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5654 | 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] | 5655 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5656 | config.ArtApexJars = []string{"platform:some-platform-lib"} |
| 5657 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5658 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5659 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5660 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5661 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
| 5662 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5663 | config.BootJars = []string{"platform:some-platform-lib"} |
| 5664 | } |
| 5665 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 5666 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5667 | } |
| 5668 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 5669 | func TestTestFor(t *testing.T) { |
| 5670 | ctx, _ := testApex(t, ` |
| 5671 | apex { |
| 5672 | name: "myapex", |
| 5673 | key: "myapex.key", |
| 5674 | native_shared_libs: ["mylib", "myprivlib"], |
| 5675 | } |
| 5676 | |
| 5677 | apex_key { |
| 5678 | name: "myapex.key", |
| 5679 | public_key: "testkey.avbpubkey", |
| 5680 | private_key: "testkey.pem", |
| 5681 | } |
| 5682 | |
| 5683 | cc_library { |
| 5684 | name: "mylib", |
| 5685 | srcs: ["mylib.cpp"], |
| 5686 | system_shared_libs: [], |
| 5687 | stl: "none", |
| 5688 | stubs: { |
| 5689 | versions: ["1"], |
| 5690 | }, |
| 5691 | apex_available: ["myapex"], |
| 5692 | } |
| 5693 | |
| 5694 | cc_library { |
| 5695 | name: "myprivlib", |
| 5696 | srcs: ["mylib.cpp"], |
| 5697 | system_shared_libs: [], |
| 5698 | stl: "none", |
| 5699 | apex_available: ["myapex"], |
| 5700 | } |
| 5701 | |
| 5702 | |
| 5703 | cc_test { |
| 5704 | name: "mytest", |
| 5705 | gtest: false, |
| 5706 | srcs: ["mylib.cpp"], |
| 5707 | system_shared_libs: [], |
| 5708 | stl: "none", |
| 5709 | shared_libs: ["mylib", "myprivlib"], |
| 5710 | test_for: ["myapex"] |
| 5711 | } |
| 5712 | `) |
| 5713 | |
| 5714 | // the test 'mytest' is a test for the apex, therefore is linked to the |
| 5715 | // actual implementation of mylib instead of its stub. |
| 5716 | ldFlags := ctx.ModuleForTests("mytest", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 5717 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 5718 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
| 5719 | } |
| 5720 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 5721 | // TODO(jungjw): Move this to proptools |
| 5722 | func intPtr(i int) *int { |
| 5723 | return &i |
| 5724 | } |
| 5725 | |
| 5726 | func TestApexSet(t *testing.T) { |
| 5727 | ctx, config := testApex(t, ` |
| 5728 | apex_set { |
| 5729 | name: "myapex", |
| 5730 | set: "myapex.apks", |
| 5731 | filename: "foo_v2.apex", |
| 5732 | overrides: ["foo"], |
| 5733 | } |
| 5734 | `, func(fs map[string][]byte, config android.Config) { |
| 5735 | config.TestProductVariables.Platform_sdk_version = intPtr(30) |
| 5736 | config.TestProductVariables.DeviceArch = proptools.StringPtr("arm") |
| 5737 | config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm64") |
| 5738 | }) |
| 5739 | |
| 5740 | m := ctx.ModuleForTests("myapex", "android_common") |
| 5741 | |
| 5742 | // Check extract_apks tool parameters. |
| 5743 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 5744 | actual := extractedApex.Args["abis"] |
| 5745 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 5746 | if actual != expected { |
| 5747 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 5748 | } |
| 5749 | actual = extractedApex.Args["sdk-version"] |
| 5750 | expected = "30" |
| 5751 | if actual != expected { |
| 5752 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 5753 | } |
| 5754 | |
| 5755 | a := m.Module().(*ApexSet) |
| 5756 | expectedOverrides := []string{"foo"} |
| 5757 | actualOverrides := android.AndroidMkEntriesForTest(t, config, "", a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
| 5758 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 5759 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 5760 | } |
| 5761 | } |
| 5762 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 5763 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 5764 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 5765 | apex { |
| 5766 | name: "myapex", |
| 5767 | key: "myapex.key", |
| 5768 | native_shared_libs: ["mylib"], |
| 5769 | } |
| 5770 | |
| 5771 | apex_key { |
| 5772 | name: "myapex.key", |
| 5773 | public_key: "testkey.avbpubkey", |
| 5774 | private_key: "testkey.pem", |
| 5775 | } |
| 5776 | |
| 5777 | cc_library { |
| 5778 | name: "mylib", |
| 5779 | srcs: ["mylib.cpp"], |
| 5780 | static_libs: ["otherlib"], |
| 5781 | system_shared_libs: [], |
| 5782 | stl: "none", |
| 5783 | apex_available: [ "myapex" ], |
| 5784 | } |
| 5785 | |
| 5786 | cc_library { |
| 5787 | name: "otherlib", |
| 5788 | srcs: ["mylib.cpp"], |
| 5789 | system_shared_libs: [], |
| 5790 | stl: "none", |
| 5791 | stubs: { |
| 5792 | versions: ["1", "2", "3"], |
| 5793 | }, |
| 5794 | apex_available: [ "myapex" ], |
| 5795 | } |
| 5796 | `) |
| 5797 | } |
| 5798 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 5799 | func TestApexKeysTxt(t *testing.T) { |
| 5800 | ctx, _ := testApex(t, ` |
| 5801 | apex { |
| 5802 | name: "myapex", |
| 5803 | key: "myapex.key", |
| 5804 | } |
| 5805 | |
| 5806 | apex_key { |
| 5807 | name: "myapex.key", |
| 5808 | public_key: "testkey.avbpubkey", |
| 5809 | private_key: "testkey.pem", |
| 5810 | } |
| 5811 | |
| 5812 | prebuilt_apex { |
| 5813 | name: "myapex", |
| 5814 | prefer: true, |
| 5815 | arch: { |
| 5816 | arm64: { |
| 5817 | src: "myapex-arm64.apex", |
| 5818 | }, |
| 5819 | arm: { |
| 5820 | src: "myapex-arm.apex", |
| 5821 | }, |
| 5822 | }, |
| 5823 | } |
| 5824 | |
| 5825 | apex_set { |
| 5826 | name: "myapex_set", |
| 5827 | set: "myapex.apks", |
| 5828 | filename: "myapex_set.apex", |
| 5829 | overrides: ["myapex"], |
| 5830 | } |
| 5831 | `) |
| 5832 | |
| 5833 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 5834 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 5835 | 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] | 5836 | 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] | 5837 | } |
| 5838 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 5839 | func TestAllowedFiles(t *testing.T) { |
| 5840 | ctx, _ := testApex(t, ` |
| 5841 | apex { |
| 5842 | name: "myapex", |
| 5843 | key: "myapex.key", |
| 5844 | apps: ["app"], |
| 5845 | allowed_files: "allowed.txt", |
| 5846 | } |
| 5847 | |
| 5848 | apex_key { |
| 5849 | name: "myapex.key", |
| 5850 | public_key: "testkey.avbpubkey", |
| 5851 | private_key: "testkey.pem", |
| 5852 | } |
| 5853 | |
| 5854 | android_app { |
| 5855 | name: "app", |
| 5856 | srcs: ["foo/bar/MyClass.java"], |
| 5857 | package_name: "foo", |
| 5858 | sdk_version: "none", |
| 5859 | system_modules: "none", |
| 5860 | apex_available: [ "myapex" ], |
| 5861 | } |
| 5862 | `, withFiles(map[string][]byte{ |
| 5863 | "sub/Android.bp": []byte(` |
| 5864 | override_apex { |
| 5865 | name: "override_myapex", |
| 5866 | base: "myapex", |
| 5867 | apps: ["override_app"], |
| 5868 | allowed_files: ":allowed", |
| 5869 | } |
| 5870 | // Overridable "path" property should be referenced indirectly |
| 5871 | filegroup { |
| 5872 | name: "allowed", |
| 5873 | srcs: ["allowed.txt"], |
| 5874 | } |
| 5875 | override_android_app { |
| 5876 | name: "override_app", |
| 5877 | base: "app", |
| 5878 | package_name: "bar", |
| 5879 | } |
| 5880 | `), |
| 5881 | })) |
| 5882 | |
| 5883 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 5884 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 5885 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 5886 | } |
| 5887 | |
| 5888 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 5889 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 5890 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 5891 | } |
| 5892 | } |
| 5893 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 5894 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
| 5895 | _, _ = testApex(t, ` |
| 5896 | apex { |
| 5897 | name: "myapex", |
| 5898 | key: "myapex.key", |
| 5899 | native_shared_libs: ["mylib"], |
| 5900 | } |
| 5901 | |
| 5902 | apex_key { |
| 5903 | name: "myapex.key", |
| 5904 | public_key: "testkey.avbpubkey", |
| 5905 | private_key: "testkey.pem", |
| 5906 | } |
| 5907 | |
| 5908 | cc_library { |
| 5909 | name: "mylib", |
| 5910 | srcs: ["mylib.cpp"], |
| 5911 | stubs: { |
| 5912 | versions: ["10000"], |
| 5913 | }, |
| 5914 | apex_available: ["myapex"], |
| 5915 | } |
| 5916 | |
| 5917 | cc_prebuilt_library_shared { |
| 5918 | name: "mylib", |
| 5919 | prefer: false, |
| 5920 | srcs: ["prebuilt.so"], |
| 5921 | stubs: { |
| 5922 | versions: ["10000"], |
| 5923 | }, |
| 5924 | apex_available: ["myapex"], |
| 5925 | } |
| 5926 | `) |
| 5927 | } |
| 5928 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 5929 | func TestMain(m *testing.M) { |
| 5930 | run := func() int { |
| 5931 | setUp() |
| 5932 | defer tearDown() |
| 5933 | |
| 5934 | return m.Run() |
| 5935 | } |
| 5936 | |
| 5937 | os.Exit(run()) |
| 5938 | } |