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 | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2206 | func TestAndroidMk_UseVendorRequired(t *testing.T) { |
| 2207 | ctx, config := testApex(t, ` |
| 2208 | apex { |
| 2209 | name: "myapex", |
| 2210 | key: "myapex.key", |
| 2211 | use_vendor: true, |
| 2212 | native_shared_libs: ["mylib"], |
| 2213 | } |
| 2214 | |
| 2215 | apex_key { |
| 2216 | name: "myapex.key", |
| 2217 | public_key: "testkey.avbpubkey", |
| 2218 | private_key: "testkey.pem", |
| 2219 | } |
| 2220 | |
| 2221 | cc_library { |
| 2222 | name: "mylib", |
| 2223 | vendor_available: true, |
| 2224 | apex_available: ["myapex"], |
| 2225 | } |
| 2226 | `, func(fs map[string][]byte, config android.Config) { |
| 2227 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
| 2228 | }) |
| 2229 | |
| 2230 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2231 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2232 | name := apexBundle.BaseModuleName() |
| 2233 | prefix := "TARGET_" |
| 2234 | var builder strings.Builder |
| 2235 | data.Custom(&builder, name, prefix, "", data) |
| 2236 | androidMk := builder.String() |
| 2237 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc libm libdl\n") |
| 2238 | } |
| 2239 | |
| 2240 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
| 2241 | ctx, config := testApex(t, ` |
| 2242 | apex { |
| 2243 | name: "myapex", |
| 2244 | key: "myapex.key", |
| 2245 | vendor: true, |
| 2246 | native_shared_libs: ["mylib"], |
| 2247 | } |
| 2248 | |
| 2249 | apex_key { |
| 2250 | name: "myapex.key", |
| 2251 | public_key: "testkey.avbpubkey", |
| 2252 | private_key: "testkey.pem", |
| 2253 | } |
| 2254 | |
| 2255 | cc_library { |
| 2256 | name: "mylib", |
| 2257 | vendor_available: true, |
| 2258 | } |
| 2259 | `) |
| 2260 | |
| 2261 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2262 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2263 | name := apexBundle.BaseModuleName() |
| 2264 | prefix := "TARGET_" |
| 2265 | var builder strings.Builder |
| 2266 | data.Custom(&builder, name, prefix, "", data) |
| 2267 | androidMk := builder.String() |
| 2268 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc.vendor libm.vendor libdl.vendor\n") |
| 2269 | } |
| 2270 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2271 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
| 2272 | ctx, config := testApex(t, ` |
| 2273 | apex { |
| 2274 | name: "myapex", |
| 2275 | key: "myapex.key", |
| 2276 | vintf_fragments: ["fragment.xml"], |
| 2277 | init_rc: ["init.rc"], |
| 2278 | } |
| 2279 | apex_key { |
| 2280 | name: "myapex.key", |
| 2281 | public_key: "testkey.avbpubkey", |
| 2282 | private_key: "testkey.pem", |
| 2283 | } |
| 2284 | cc_binary { |
| 2285 | name: "mybin", |
| 2286 | } |
| 2287 | `) |
| 2288 | |
| 2289 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2290 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2291 | name := apexBundle.BaseModuleName() |
| 2292 | prefix := "TARGET_" |
| 2293 | var builder strings.Builder |
| 2294 | data.Custom(&builder, name, prefix, "", data) |
| 2295 | androidMk := builder.String() |
| 2296 | ensureContains(t, androidMk, "LOCAL_VINTF_FRAGMENTS := fragment.xml\n") |
| 2297 | ensureContains(t, androidMk, "LOCAL_INIT_RC := init.rc\n") |
| 2298 | } |
| 2299 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2300 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2301 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2302 | apex { |
| 2303 | name: "myapex", |
| 2304 | key: "myapex.key", |
| 2305 | native_shared_libs: ["mylib"], |
| 2306 | } |
| 2307 | |
| 2308 | apex_key { |
| 2309 | name: "myapex.key", |
| 2310 | public_key: "testkey.avbpubkey", |
| 2311 | private_key: "testkey.pem", |
| 2312 | } |
| 2313 | |
| 2314 | cc_library { |
| 2315 | name: "mylib", |
| 2316 | srcs: ["mylib.cpp"], |
| 2317 | system_shared_libs: [], |
| 2318 | stl: "none", |
| 2319 | stubs: { |
| 2320 | versions: ["1", "2", "3"], |
| 2321 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2322 | apex_available: [ |
| 2323 | "//apex_available:platform", |
| 2324 | "myapex", |
| 2325 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | cc_binary { |
| 2329 | name: "not_in_apex", |
| 2330 | srcs: ["mylib.cpp"], |
| 2331 | static_libs: ["mylib"], |
| 2332 | static_executable: true, |
| 2333 | system_shared_libs: [], |
| 2334 | stl: "none", |
| 2335 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2336 | `) |
| 2337 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2338 | 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] | 2339 | |
| 2340 | // 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] | 2341 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2342 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2343 | |
| 2344 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2345 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2346 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2347 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2348 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2349 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2350 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2351 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | cc_library { |
| 2355 | name: "mylib", |
| 2356 | srcs: ["mylib.cpp"], |
| 2357 | system_shared_libs: [], |
| 2358 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2359 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | apex_key { |
| 2363 | name: "myapex.key", |
| 2364 | public_key: "testkey.avbpubkey", |
| 2365 | private_key: "testkey.pem", |
| 2366 | } |
| 2367 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2368 | android_app_certificate { |
| 2369 | name: "myapex.certificate", |
| 2370 | certificate: "testkey", |
| 2371 | } |
| 2372 | |
| 2373 | android_app_certificate { |
| 2374 | name: "myapex.certificate.override", |
| 2375 | certificate: "testkey.override", |
| 2376 | } |
| 2377 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2378 | `) |
| 2379 | |
| 2380 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2381 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2382 | |
| 2383 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 2384 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 2385 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 2386 | } |
| 2387 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 2388 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 2389 | "vendor/foo/devkeys/testkey.pem") |
| 2390 | } |
| 2391 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2392 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2393 | 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] | 2394 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2395 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2396 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2397 | } |
| 2398 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2399 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2400 | func TestCertificate(t *testing.T) { |
| 2401 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 2402 | ctx, _ := testApex(t, ` |
| 2403 | apex { |
| 2404 | name: "myapex", |
| 2405 | key: "myapex.key", |
| 2406 | } |
| 2407 | apex_key { |
| 2408 | name: "myapex.key", |
| 2409 | public_key: "testkey.avbpubkey", |
| 2410 | private_key: "testkey.pem", |
| 2411 | }`) |
| 2412 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2413 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 2414 | if actual := rule.Args["certificates"]; actual != expected { |
| 2415 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2416 | } |
| 2417 | }) |
| 2418 | t.Run("override when unspecified", func(t *testing.T) { |
| 2419 | ctx, _ := testApex(t, ` |
| 2420 | apex { |
| 2421 | name: "myapex_keytest", |
| 2422 | key: "myapex.key", |
| 2423 | file_contexts: ":myapex-file_contexts", |
| 2424 | } |
| 2425 | apex_key { |
| 2426 | name: "myapex.key", |
| 2427 | public_key: "testkey.avbpubkey", |
| 2428 | private_key: "testkey.pem", |
| 2429 | } |
| 2430 | android_app_certificate { |
| 2431 | name: "myapex.certificate.override", |
| 2432 | certificate: "testkey.override", |
| 2433 | }`) |
| 2434 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2435 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2436 | if actual := rule.Args["certificates"]; actual != expected { |
| 2437 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2438 | } |
| 2439 | }) |
| 2440 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 2441 | ctx, _ := testApex(t, ` |
| 2442 | apex { |
| 2443 | name: "myapex", |
| 2444 | key: "myapex.key", |
| 2445 | certificate: ":myapex.certificate", |
| 2446 | } |
| 2447 | apex_key { |
| 2448 | name: "myapex.key", |
| 2449 | public_key: "testkey.avbpubkey", |
| 2450 | private_key: "testkey.pem", |
| 2451 | } |
| 2452 | android_app_certificate { |
| 2453 | name: "myapex.certificate", |
| 2454 | certificate: "testkey", |
| 2455 | }`) |
| 2456 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2457 | expected := "testkey.x509.pem testkey.pk8" |
| 2458 | if actual := rule.Args["certificates"]; actual != expected { |
| 2459 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2460 | } |
| 2461 | }) |
| 2462 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 2463 | ctx, _ := testApex(t, ` |
| 2464 | apex { |
| 2465 | name: "myapex_keytest", |
| 2466 | key: "myapex.key", |
| 2467 | file_contexts: ":myapex-file_contexts", |
| 2468 | certificate: ":myapex.certificate", |
| 2469 | } |
| 2470 | apex_key { |
| 2471 | name: "myapex.key", |
| 2472 | public_key: "testkey.avbpubkey", |
| 2473 | private_key: "testkey.pem", |
| 2474 | } |
| 2475 | android_app_certificate { |
| 2476 | name: "myapex.certificate.override", |
| 2477 | certificate: "testkey.override", |
| 2478 | }`) |
| 2479 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2480 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2481 | if actual := rule.Args["certificates"]; actual != expected { |
| 2482 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2483 | } |
| 2484 | }) |
| 2485 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 2486 | ctx, _ := testApex(t, ` |
| 2487 | apex { |
| 2488 | name: "myapex", |
| 2489 | key: "myapex.key", |
| 2490 | certificate: "testkey", |
| 2491 | } |
| 2492 | apex_key { |
| 2493 | name: "myapex.key", |
| 2494 | public_key: "testkey.avbpubkey", |
| 2495 | private_key: "testkey.pem", |
| 2496 | }`) |
| 2497 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2498 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 2499 | if actual := rule.Args["certificates"]; actual != expected { |
| 2500 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2501 | } |
| 2502 | }) |
| 2503 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 2504 | ctx, _ := testApex(t, ` |
| 2505 | apex { |
| 2506 | name: "myapex_keytest", |
| 2507 | key: "myapex.key", |
| 2508 | file_contexts: ":myapex-file_contexts", |
| 2509 | certificate: "testkey", |
| 2510 | } |
| 2511 | apex_key { |
| 2512 | name: "myapex.key", |
| 2513 | public_key: "testkey.avbpubkey", |
| 2514 | private_key: "testkey.pem", |
| 2515 | } |
| 2516 | android_app_certificate { |
| 2517 | name: "myapex.certificate.override", |
| 2518 | certificate: "testkey.override", |
| 2519 | }`) |
| 2520 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2521 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2522 | if actual := rule.Args["certificates"]; actual != expected { |
| 2523 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2524 | } |
| 2525 | }) |
| 2526 | } |
| 2527 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2528 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2529 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2530 | apex { |
| 2531 | name: "myapex", |
| 2532 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2533 | native_shared_libs: ["mylib", "mylib2"], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | apex { |
| 2537 | name: "otherapex", |
| 2538 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2539 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2540 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | apex_key { |
| 2544 | name: "myapex.key", |
| 2545 | public_key: "testkey.avbpubkey", |
| 2546 | private_key: "testkey.pem", |
| 2547 | } |
| 2548 | |
| 2549 | cc_library { |
| 2550 | name: "mylib", |
| 2551 | srcs: ["mylib.cpp"], |
| 2552 | system_shared_libs: [], |
| 2553 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2554 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2555 | "myapex", |
| 2556 | "otherapex", |
| 2557 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2558 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2559 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2560 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2561 | cc_library { |
| 2562 | name: "mylib2", |
| 2563 | srcs: ["mylib.cpp"], |
| 2564 | system_shared_libs: [], |
| 2565 | stl: "none", |
| 2566 | apex_available: [ |
| 2567 | "myapex", |
| 2568 | "otherapex", |
| 2569 | ], |
| 2570 | use_apex_name_macro: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2571 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2572 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2573 | `) |
| 2574 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2575 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2576 | 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] | 2577 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 2578 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2579 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2580 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2581 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 2582 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2583 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2584 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2585 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2586 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2587 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 2588 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2589 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2590 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2591 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2592 | // When cc_library sets use_apex_name_macro: true |
| 2593 | // apex variants define additional macro to distinguish which apex variant it is built for |
| 2594 | |
| 2595 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 2596 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 2597 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2598 | |
| 2599 | // APEX variant has __ANDROID_APEX__ defined |
| 2600 | 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] | 2601 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2602 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 2603 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2604 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2605 | // APEX variant has __ANDROID_APEX__ defined |
| 2606 | 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] | 2607 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2608 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 2609 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2610 | |
| 2611 | // recovery variant does not set __ANDROID_SDK_VERSION__ |
| 2612 | mylibCFlags = ctx.ModuleForTests("mylib", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 2613 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2614 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2615 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2616 | |
| 2617 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2618 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2619 | apex { |
| 2620 | name: "myapex", |
| 2621 | key: "myapex.key", |
| 2622 | native_shared_libs: ["mylib"], |
| 2623 | } |
| 2624 | |
| 2625 | apex_key { |
| 2626 | name: "myapex.key", |
| 2627 | public_key: "testkey.avbpubkey", |
| 2628 | private_key: "testkey.pem", |
| 2629 | } |
| 2630 | |
| 2631 | cc_library_headers { |
| 2632 | name: "mylib_headers", |
| 2633 | export_include_dirs: ["my_include"], |
| 2634 | system_shared_libs: [], |
| 2635 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2636 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | cc_library { |
| 2640 | name: "mylib", |
| 2641 | srcs: ["mylib.cpp"], |
| 2642 | system_shared_libs: [], |
| 2643 | stl: "none", |
| 2644 | header_libs: ["mylib_headers"], |
| 2645 | export_header_lib_headers: ["mylib_headers"], |
| 2646 | stubs: { |
| 2647 | versions: ["1", "2", "3"], |
| 2648 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2649 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | cc_library { |
| 2653 | name: "otherlib", |
| 2654 | srcs: ["mylib.cpp"], |
| 2655 | system_shared_libs: [], |
| 2656 | stl: "none", |
| 2657 | shared_libs: ["mylib"], |
| 2658 | } |
| 2659 | `) |
| 2660 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2661 | 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] | 2662 | |
| 2663 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 2664 | ensureContains(t, cFlags, "-Imy_include") |
| 2665 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2666 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2667 | type fileInApex struct { |
| 2668 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2669 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2670 | isLink bool |
| 2671 | } |
| 2672 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2673 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2674 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2675 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2676 | copyCmds := apexRule.Args["copy_commands"] |
| 2677 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2678 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2679 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 2680 | cmd = strings.TrimSpace(cmd) |
| 2681 | if cmd == "" { |
| 2682 | continue |
| 2683 | } |
| 2684 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2685 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2686 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2687 | switch terms[0] { |
| 2688 | case "mkdir": |
| 2689 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2690 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2691 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 2692 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2693 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2694 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2695 | isLink = false |
| 2696 | case "ln": |
| 2697 | if len(terms) != 3 && len(terms) != 4 { |
| 2698 | // ln LINK TARGET or ln -s LINK TARGET |
| 2699 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 2700 | } |
| 2701 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2702 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2703 | isLink = true |
| 2704 | default: |
| 2705 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 2706 | } |
| 2707 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2708 | index := strings.Index(dst, imageApexDir) |
| 2709 | if index == -1 { |
| 2710 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 2711 | } |
| 2712 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2713 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2714 | } |
| 2715 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2716 | return ret |
| 2717 | } |
| 2718 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2719 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 2720 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2721 | var failed bool |
| 2722 | var surplus []string |
| 2723 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2724 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2725 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2726 | for _, expected := range files { |
| 2727 | if matched, _ := path.Match(expected, file.path); matched { |
| 2728 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2729 | mactchFound = true |
| 2730 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2731 | } |
| 2732 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2733 | if !mactchFound { |
| 2734 | surplus = append(surplus, file.path) |
| 2735 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2736 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2737 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2738 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2739 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2740 | t.Log("surplus files", surplus) |
| 2741 | failed = true |
| 2742 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2743 | |
| 2744 | if len(files) > len(filesMatched) { |
| 2745 | var missing []string |
| 2746 | for _, expected := range files { |
| 2747 | if !filesMatched[expected] { |
| 2748 | missing = append(missing, expected) |
| 2749 | } |
| 2750 | } |
| 2751 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2752 | t.Log("missing files", missing) |
| 2753 | failed = true |
| 2754 | } |
| 2755 | if failed { |
| 2756 | t.Fail() |
| 2757 | } |
| 2758 | } |
| 2759 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2760 | func TestVndkApexCurrent(t *testing.T) { |
| 2761 | ctx, _ := testApex(t, ` |
| 2762 | apex_vndk { |
| 2763 | name: "myapex", |
| 2764 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2765 | } |
| 2766 | |
| 2767 | apex_key { |
| 2768 | name: "myapex.key", |
| 2769 | public_key: "testkey.avbpubkey", |
| 2770 | private_key: "testkey.pem", |
| 2771 | } |
| 2772 | |
| 2773 | cc_library { |
| 2774 | name: "libvndk", |
| 2775 | srcs: ["mylib.cpp"], |
| 2776 | vendor_available: true, |
| 2777 | vndk: { |
| 2778 | enabled: true, |
| 2779 | }, |
| 2780 | system_shared_libs: [], |
| 2781 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2782 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | cc_library { |
| 2786 | name: "libvndksp", |
| 2787 | srcs: ["mylib.cpp"], |
| 2788 | vendor_available: true, |
| 2789 | vndk: { |
| 2790 | enabled: true, |
| 2791 | support_system_process: true, |
| 2792 | }, |
| 2793 | system_shared_libs: [], |
| 2794 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2795 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2796 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2797 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2798 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2799 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2800 | "lib/libvndk.so", |
| 2801 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2802 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2803 | "lib64/libvndk.so", |
| 2804 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2805 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2806 | "etc/llndk.libraries.VER.txt", |
| 2807 | "etc/vndkcore.libraries.VER.txt", |
| 2808 | "etc/vndksp.libraries.VER.txt", |
| 2809 | "etc/vndkprivate.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2810 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 2814 | ctx, _ := testApex(t, ` |
| 2815 | apex_vndk { |
| 2816 | name: "myapex", |
| 2817 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | apex_key { |
| 2821 | name: "myapex.key", |
| 2822 | public_key: "testkey.avbpubkey", |
| 2823 | private_key: "testkey.pem", |
| 2824 | } |
| 2825 | |
| 2826 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2827 | name: "libvndk", |
| 2828 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2829 | vendor_available: true, |
| 2830 | vndk: { |
| 2831 | enabled: true, |
| 2832 | }, |
| 2833 | system_shared_libs: [], |
| 2834 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2835 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2836 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2837 | |
| 2838 | cc_prebuilt_library_shared { |
| 2839 | name: "libvndk.arm", |
| 2840 | srcs: ["libvndk.arm.so"], |
| 2841 | vendor_available: true, |
| 2842 | vndk: { |
| 2843 | enabled: true, |
| 2844 | }, |
| 2845 | enabled: false, |
| 2846 | arch: { |
| 2847 | arm: { |
| 2848 | enabled: true, |
| 2849 | }, |
| 2850 | }, |
| 2851 | system_shared_libs: [], |
| 2852 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2853 | apex_available: [ "myapex" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2854 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2855 | `+vndkLibrariesTxtFiles("current"), |
| 2856 | withFiles(map[string][]byte{ |
| 2857 | "libvndk.so": nil, |
| 2858 | "libvndk.arm.so": nil, |
| 2859 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2860 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2861 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2862 | "lib/libvndk.so", |
| 2863 | "lib/libvndk.arm.so", |
| 2864 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2865 | "lib/libc++.so", |
| 2866 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2867 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2868 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2869 | } |
| 2870 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2871 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 2872 | for _, v := range vers { |
| 2873 | if v == "current" { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 2874 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2875 | result += ` |
| 2876 | vndk_libraries_txt { |
| 2877 | name: "` + txt + `.libraries.txt", |
| 2878 | } |
| 2879 | ` |
| 2880 | } |
| 2881 | } else { |
| 2882 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
| 2883 | result += ` |
| 2884 | prebuilt_etc { |
| 2885 | name: "` + txt + `.libraries.` + v + `.txt", |
| 2886 | src: "dummy.txt", |
| 2887 | } |
| 2888 | ` |
| 2889 | } |
| 2890 | } |
| 2891 | } |
| 2892 | return |
| 2893 | } |
| 2894 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2895 | func TestVndkApexVersion(t *testing.T) { |
| 2896 | ctx, _ := testApex(t, ` |
| 2897 | apex_vndk { |
| 2898 | name: "myapex_v27", |
| 2899 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2900 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2901 | vndk_version: "27", |
| 2902 | } |
| 2903 | |
| 2904 | apex_key { |
| 2905 | name: "myapex.key", |
| 2906 | public_key: "testkey.avbpubkey", |
| 2907 | private_key: "testkey.pem", |
| 2908 | } |
| 2909 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2910 | vndk_prebuilt_shared { |
| 2911 | name: "libvndk27", |
| 2912 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2913 | vendor_available: true, |
| 2914 | vndk: { |
| 2915 | enabled: true, |
| 2916 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2917 | target_arch: "arm64", |
| 2918 | arch: { |
| 2919 | arm: { |
| 2920 | srcs: ["libvndk27_arm.so"], |
| 2921 | }, |
| 2922 | arm64: { |
| 2923 | srcs: ["libvndk27_arm64.so"], |
| 2924 | }, |
| 2925 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2926 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | vndk_prebuilt_shared { |
| 2930 | name: "libvndk27", |
| 2931 | version: "27", |
| 2932 | vendor_available: true, |
| 2933 | vndk: { |
| 2934 | enabled: true, |
| 2935 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2936 | target_arch: "x86_64", |
| 2937 | arch: { |
| 2938 | x86: { |
| 2939 | srcs: ["libvndk27_x86.so"], |
| 2940 | }, |
| 2941 | x86_64: { |
| 2942 | srcs: ["libvndk27_x86_64.so"], |
| 2943 | }, |
| 2944 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2945 | } |
| 2946 | `+vndkLibrariesTxtFiles("27"), |
| 2947 | withFiles(map[string][]byte{ |
| 2948 | "libvndk27_arm.so": nil, |
| 2949 | "libvndk27_arm64.so": nil, |
| 2950 | "libvndk27_x86.so": nil, |
| 2951 | "libvndk27_x86_64.so": nil, |
| 2952 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2953 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2954 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2955 | "lib/libvndk27_arm.so", |
| 2956 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2957 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2958 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { |
| 2962 | testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, ` |
| 2963 | apex_vndk { |
| 2964 | name: "myapex_v27", |
| 2965 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2966 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2967 | vndk_version: "27", |
| 2968 | } |
| 2969 | apex_vndk { |
| 2970 | name: "myapex_v27_other", |
| 2971 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2972 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2973 | vndk_version: "27", |
| 2974 | } |
| 2975 | |
| 2976 | apex_key { |
| 2977 | name: "myapex.key", |
| 2978 | public_key: "testkey.avbpubkey", |
| 2979 | private_key: "testkey.pem", |
| 2980 | } |
| 2981 | |
| 2982 | cc_library { |
| 2983 | name: "libvndk", |
| 2984 | srcs: ["mylib.cpp"], |
| 2985 | vendor_available: true, |
| 2986 | vndk: { |
| 2987 | enabled: true, |
| 2988 | }, |
| 2989 | system_shared_libs: [], |
| 2990 | stl: "none", |
| 2991 | } |
| 2992 | |
| 2993 | vndk_prebuilt_shared { |
| 2994 | name: "libvndk", |
| 2995 | version: "27", |
| 2996 | vendor_available: true, |
| 2997 | vndk: { |
| 2998 | enabled: true, |
| 2999 | }, |
| 3000 | srcs: ["libvndk.so"], |
| 3001 | } |
| 3002 | `, withFiles(map[string][]byte{ |
| 3003 | "libvndk.so": nil, |
| 3004 | })) |
| 3005 | } |
| 3006 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3007 | func TestVndkApexNameRule(t *testing.T) { |
| 3008 | ctx, _ := testApex(t, ` |
| 3009 | apex_vndk { |
| 3010 | name: "myapex", |
| 3011 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3012 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3013 | } |
| 3014 | apex_vndk { |
| 3015 | name: "myapex_v28", |
| 3016 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3017 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3018 | vndk_version: "28", |
| 3019 | } |
| 3020 | apex_key { |
| 3021 | name: "myapex.key", |
| 3022 | public_key: "testkey.avbpubkey", |
| 3023 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3024 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3025 | |
| 3026 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3027 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3028 | actual := proptools.String(bundle.properties.Apex_name) |
| 3029 | if !reflect.DeepEqual(actual, expected) { |
| 3030 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3031 | } |
| 3032 | } |
| 3033 | |
| 3034 | assertApexName("com.android.vndk.vVER", "myapex") |
| 3035 | assertApexName("com.android.vndk.v28", "myapex_v28") |
| 3036 | } |
| 3037 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3038 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 3039 | ctx, _ := testApex(t, ` |
| 3040 | apex_vndk { |
| 3041 | name: "myapex", |
| 3042 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3043 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | apex_key { |
| 3047 | name: "myapex.key", |
| 3048 | public_key: "testkey.avbpubkey", |
| 3049 | private_key: "testkey.pem", |
| 3050 | } |
| 3051 | |
| 3052 | cc_library { |
| 3053 | name: "libvndk", |
| 3054 | srcs: ["mylib.cpp"], |
| 3055 | vendor_available: true, |
| 3056 | native_bridge_supported: true, |
| 3057 | host_supported: true, |
| 3058 | vndk: { |
| 3059 | enabled: true, |
| 3060 | }, |
| 3061 | system_shared_libs: [], |
| 3062 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3063 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3064 | } |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3065 | `+vndkLibrariesTxtFiles("current"), withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3066 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3067 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3068 | "lib/libvndk.so", |
| 3069 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3070 | "lib/libc++.so", |
| 3071 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3072 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3073 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
| 3077 | testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
| 3078 | apex_vndk { |
| 3079 | name: "myapex", |
| 3080 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3081 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3082 | native_bridge_supported: true, |
| 3083 | } |
| 3084 | |
| 3085 | apex_key { |
| 3086 | name: "myapex.key", |
| 3087 | public_key: "testkey.avbpubkey", |
| 3088 | private_key: "testkey.pem", |
| 3089 | } |
| 3090 | |
| 3091 | cc_library { |
| 3092 | name: "libvndk", |
| 3093 | srcs: ["mylib.cpp"], |
| 3094 | vendor_available: true, |
| 3095 | native_bridge_supported: true, |
| 3096 | host_supported: true, |
| 3097 | vndk: { |
| 3098 | enabled: true, |
| 3099 | }, |
| 3100 | system_shared_libs: [], |
| 3101 | stl: "none", |
| 3102 | } |
| 3103 | `) |
| 3104 | } |
| 3105 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3106 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3107 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3108 | apex_vndk { |
| 3109 | name: "myapex_v27", |
| 3110 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3111 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3112 | vndk_version: "27", |
| 3113 | } |
| 3114 | |
| 3115 | apex_key { |
| 3116 | name: "myapex.key", |
| 3117 | public_key: "testkey.avbpubkey", |
| 3118 | private_key: "testkey.pem", |
| 3119 | } |
| 3120 | |
| 3121 | vndk_prebuilt_shared { |
| 3122 | name: "libvndk27", |
| 3123 | version: "27", |
| 3124 | target_arch: "arm", |
| 3125 | vendor_available: true, |
| 3126 | vndk: { |
| 3127 | enabled: true, |
| 3128 | }, |
| 3129 | arch: { |
| 3130 | arm: { |
| 3131 | srcs: ["libvndk27.so"], |
| 3132 | } |
| 3133 | }, |
| 3134 | } |
| 3135 | |
| 3136 | vndk_prebuilt_shared { |
| 3137 | name: "libvndk27", |
| 3138 | version: "27", |
| 3139 | target_arch: "arm", |
| 3140 | binder32bit: true, |
| 3141 | vendor_available: true, |
| 3142 | vndk: { |
| 3143 | enabled: true, |
| 3144 | }, |
| 3145 | arch: { |
| 3146 | arm: { |
| 3147 | srcs: ["libvndk27binder32.so"], |
| 3148 | } |
| 3149 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3150 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3151 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3152 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3153 | withFiles(map[string][]byte{ |
| 3154 | "libvndk27.so": nil, |
| 3155 | "libvndk27binder32.so": nil, |
| 3156 | }), |
| 3157 | withBinder32bit, |
| 3158 | withTargets(map[android.OsType][]android.Target{ |
| 3159 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3160 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3161 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3162 | }, |
| 3163 | }), |
| 3164 | ) |
| 3165 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3166 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3167 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3168 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3169 | }) |
| 3170 | } |
| 3171 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3172 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
| 3173 | ctx, _ := testApex(t, ` |
| 3174 | apex_vndk { |
| 3175 | name: "myapex", |
| 3176 | key: "myapex.key", |
| 3177 | file_contexts: ":myapex-file_contexts", |
| 3178 | } |
| 3179 | |
| 3180 | apex_key { |
| 3181 | name: "myapex.key", |
| 3182 | public_key: "testkey.avbpubkey", |
| 3183 | private_key: "testkey.pem", |
| 3184 | } |
| 3185 | |
| 3186 | cc_library { |
| 3187 | name: "libz", |
| 3188 | vendor_available: true, |
| 3189 | vndk: { |
| 3190 | enabled: true, |
| 3191 | }, |
| 3192 | stubs: { |
| 3193 | symbol_file: "libz.map.txt", |
| 3194 | versions: ["30"], |
| 3195 | } |
| 3196 | } |
| 3197 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3198 | "libz.map.txt": nil, |
| 3199 | })) |
| 3200 | |
| 3201 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_image").Rule("apexManifestRule") |
| 3202 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3203 | ensureListEmpty(t, provideNativeLibs) |
| 3204 | } |
| 3205 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3206 | func TestDependenciesInApexManifest(t *testing.T) { |
| 3207 | ctx, _ := testApex(t, ` |
| 3208 | apex { |
| 3209 | name: "myapex_nodep", |
| 3210 | key: "myapex.key", |
| 3211 | native_shared_libs: ["lib_nodep"], |
| 3212 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3213 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | apex { |
| 3217 | name: "myapex_dep", |
| 3218 | key: "myapex.key", |
| 3219 | native_shared_libs: ["lib_dep"], |
| 3220 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3221 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | apex { |
| 3225 | name: "myapex_provider", |
| 3226 | key: "myapex.key", |
| 3227 | native_shared_libs: ["libfoo"], |
| 3228 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3229 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | apex { |
| 3233 | name: "myapex_selfcontained", |
| 3234 | key: "myapex.key", |
| 3235 | native_shared_libs: ["lib_dep", "libfoo"], |
| 3236 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3237 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | apex_key { |
| 3241 | name: "myapex.key", |
| 3242 | public_key: "testkey.avbpubkey", |
| 3243 | private_key: "testkey.pem", |
| 3244 | } |
| 3245 | |
| 3246 | cc_library { |
| 3247 | name: "lib_nodep", |
| 3248 | srcs: ["mylib.cpp"], |
| 3249 | system_shared_libs: [], |
| 3250 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3251 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | cc_library { |
| 3255 | name: "lib_dep", |
| 3256 | srcs: ["mylib.cpp"], |
| 3257 | shared_libs: ["libfoo"], |
| 3258 | system_shared_libs: [], |
| 3259 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3260 | apex_available: [ |
| 3261 | "myapex_dep", |
| 3262 | "myapex_provider", |
| 3263 | "myapex_selfcontained", |
| 3264 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | cc_library { |
| 3268 | name: "libfoo", |
| 3269 | srcs: ["mytest.cpp"], |
| 3270 | stubs: { |
| 3271 | versions: ["1"], |
| 3272 | }, |
| 3273 | system_shared_libs: [], |
| 3274 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3275 | apex_available: [ |
| 3276 | "myapex_provider", |
| 3277 | "myapex_selfcontained", |
| 3278 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3279 | } |
| 3280 | `) |
| 3281 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3282 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3283 | var provideNativeLibs, requireNativeLibs []string |
| 3284 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3285 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3286 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3287 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3288 | ensureListEmpty(t, provideNativeLibs) |
| 3289 | ensureListEmpty(t, requireNativeLibs) |
| 3290 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3291 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3292 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3293 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3294 | ensureListEmpty(t, provideNativeLibs) |
| 3295 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 3296 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3297 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3298 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3299 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3300 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3301 | ensureListEmpty(t, requireNativeLibs) |
| 3302 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3303 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3304 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3305 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3306 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3307 | ensureListEmpty(t, requireNativeLibs) |
| 3308 | } |
| 3309 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3310 | func TestApexName(t *testing.T) { |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3311 | ctx, config := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3312 | apex { |
| 3313 | name: "myapex", |
| 3314 | key: "myapex.key", |
| 3315 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3316 | native_shared_libs: ["mylib"], |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | apex_key { |
| 3320 | name: "myapex.key", |
| 3321 | public_key: "testkey.avbpubkey", |
| 3322 | private_key: "testkey.pem", |
| 3323 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3324 | |
| 3325 | cc_library { |
| 3326 | name: "mylib", |
| 3327 | srcs: ["mylib.cpp"], |
| 3328 | system_shared_libs: [], |
| 3329 | stl: "none", |
| 3330 | apex_available: [ |
| 3331 | "//apex_available:platform", |
| 3332 | "myapex", |
| 3333 | ], |
| 3334 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3335 | `) |
| 3336 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3337 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3338 | apexManifestRule := module.Rule("apexManifestRule") |
| 3339 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 3340 | apexRule := module.Rule("apexRule") |
| 3341 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3342 | |
| 3343 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3344 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3345 | name := apexBundle.BaseModuleName() |
| 3346 | prefix := "TARGET_" |
| 3347 | var builder strings.Builder |
| 3348 | data.Custom(&builder, name, prefix, "", data) |
| 3349 | androidMk := builder.String() |
| 3350 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 3351 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3352 | } |
| 3353 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3354 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3355 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3356 | apex { |
| 3357 | name: "myapex", |
| 3358 | key: "myapex.key", |
| 3359 | native_shared_libs: ["mylib_common"], |
| 3360 | } |
| 3361 | |
| 3362 | apex_key { |
| 3363 | name: "myapex.key", |
| 3364 | public_key: "testkey.avbpubkey", |
| 3365 | private_key: "testkey.pem", |
| 3366 | } |
| 3367 | |
| 3368 | cc_library { |
| 3369 | name: "mylib_common", |
| 3370 | srcs: ["mylib.cpp"], |
| 3371 | system_shared_libs: [], |
| 3372 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3373 | apex_available: [ |
| 3374 | "//apex_available:platform", |
| 3375 | "myapex", |
| 3376 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3377 | } |
| 3378 | `) |
| 3379 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3380 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3381 | apexRule := module.Rule("apexRule") |
| 3382 | copyCmds := apexRule.Args["copy_commands"] |
| 3383 | |
| 3384 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 3385 | t.Log("Apex was a test apex!") |
| 3386 | t.Fail() |
| 3387 | } |
| 3388 | // Ensure that main rule creates an output |
| 3389 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3390 | |
| 3391 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3392 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3393 | |
| 3394 | // Ensure that both direct and indirect deps are copied into apex |
| 3395 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3396 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3397 | // Ensure that the platform variant ends with _shared |
| 3398 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3399 | |
| 3400 | if !android.InAnyApex("mylib_common") { |
| 3401 | t.Log("Found mylib_common not in any apex!") |
| 3402 | t.Fail() |
| 3403 | } |
| 3404 | } |
| 3405 | |
| 3406 | func TestTestApex(t *testing.T) { |
| 3407 | if android.InAnyApex("mylib_common_test") { |
| 3408 | 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!") |
| 3409 | } |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3410 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3411 | apex_test { |
| 3412 | name: "myapex", |
| 3413 | key: "myapex.key", |
| 3414 | native_shared_libs: ["mylib_common_test"], |
| 3415 | } |
| 3416 | |
| 3417 | apex_key { |
| 3418 | name: "myapex.key", |
| 3419 | public_key: "testkey.avbpubkey", |
| 3420 | private_key: "testkey.pem", |
| 3421 | } |
| 3422 | |
| 3423 | cc_library { |
| 3424 | name: "mylib_common_test", |
| 3425 | srcs: ["mylib.cpp"], |
| 3426 | system_shared_libs: [], |
| 3427 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3428 | // TODO: remove //apex_available:platform |
| 3429 | apex_available: [ |
| 3430 | "//apex_available:platform", |
| 3431 | "myapex", |
| 3432 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3433 | } |
| 3434 | `) |
| 3435 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3436 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3437 | apexRule := module.Rule("apexRule") |
| 3438 | copyCmds := apexRule.Args["copy_commands"] |
| 3439 | |
| 3440 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 3441 | t.Log("Apex was not a test apex!") |
| 3442 | t.Fail() |
| 3443 | } |
| 3444 | // Ensure that main rule creates an output |
| 3445 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3446 | |
| 3447 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3448 | 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] | 3449 | |
| 3450 | // Ensure that both direct and indirect deps are copied into apex |
| 3451 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 3452 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3453 | // Ensure that the platform variant ends with _shared |
| 3454 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3455 | } |
| 3456 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3457 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3458 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3459 | apex { |
| 3460 | name: "myapex", |
| 3461 | key: "myapex.key", |
| 3462 | multilib: { |
| 3463 | first: { |
| 3464 | native_shared_libs: ["mylib_common"], |
| 3465 | } |
| 3466 | }, |
| 3467 | target: { |
| 3468 | android: { |
| 3469 | multilib: { |
| 3470 | first: { |
| 3471 | native_shared_libs: ["mylib"], |
| 3472 | } |
| 3473 | } |
| 3474 | }, |
| 3475 | host: { |
| 3476 | multilib: { |
| 3477 | first: { |
| 3478 | native_shared_libs: ["mylib2"], |
| 3479 | } |
| 3480 | } |
| 3481 | } |
| 3482 | } |
| 3483 | } |
| 3484 | |
| 3485 | apex_key { |
| 3486 | name: "myapex.key", |
| 3487 | public_key: "testkey.avbpubkey", |
| 3488 | private_key: "testkey.pem", |
| 3489 | } |
| 3490 | |
| 3491 | cc_library { |
| 3492 | name: "mylib", |
| 3493 | srcs: ["mylib.cpp"], |
| 3494 | system_shared_libs: [], |
| 3495 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3496 | // TODO: remove //apex_available:platform |
| 3497 | apex_available: [ |
| 3498 | "//apex_available:platform", |
| 3499 | "myapex", |
| 3500 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | cc_library { |
| 3504 | name: "mylib_common", |
| 3505 | srcs: ["mylib.cpp"], |
| 3506 | system_shared_libs: [], |
| 3507 | stl: "none", |
| 3508 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3509 | // TODO: remove //apex_available:platform |
| 3510 | apex_available: [ |
| 3511 | "//apex_available:platform", |
| 3512 | "myapex", |
| 3513 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | cc_library { |
| 3517 | name: "mylib2", |
| 3518 | srcs: ["mylib.cpp"], |
| 3519 | system_shared_libs: [], |
| 3520 | stl: "none", |
| 3521 | compile_multilib: "first", |
| 3522 | } |
| 3523 | `) |
| 3524 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3525 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3526 | copyCmds := apexRule.Args["copy_commands"] |
| 3527 | |
| 3528 | // Ensure that main rule creates an output |
| 3529 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3530 | |
| 3531 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3532 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 3533 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
| 3534 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3535 | |
| 3536 | // Ensure that both direct and indirect deps are copied into apex |
| 3537 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 3538 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3539 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 3540 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3541 | // Ensure that the platform variant ends with _shared |
| 3542 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 3543 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 3544 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3545 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3546 | |
| 3547 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3548 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3549 | apex { |
| 3550 | name: "myapex", |
| 3551 | key: "myapex.key", |
| 3552 | binaries: ["myscript"], |
| 3553 | } |
| 3554 | |
| 3555 | apex_key { |
| 3556 | name: "myapex.key", |
| 3557 | public_key: "testkey.avbpubkey", |
| 3558 | private_key: "testkey.pem", |
| 3559 | } |
| 3560 | |
| 3561 | sh_binary { |
| 3562 | name: "myscript", |
| 3563 | src: "mylib.cpp", |
| 3564 | filename: "myscript.sh", |
| 3565 | sub_dir: "script", |
| 3566 | } |
| 3567 | `) |
| 3568 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3569 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3570 | copyCmds := apexRule.Args["copy_commands"] |
| 3571 | |
| 3572 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 3573 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3574 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3575 | func TestApexInVariousPartition(t *testing.T) { |
| 3576 | testcases := []struct { |
| 3577 | propName, parition, flattenedPartition string |
| 3578 | }{ |
| 3579 | {"", "system", "system_ext"}, |
| 3580 | {"product_specific: true", "product", "product"}, |
| 3581 | {"soc_specific: true", "vendor", "vendor"}, |
| 3582 | {"proprietary: true", "vendor", "vendor"}, |
| 3583 | {"vendor: true", "vendor", "vendor"}, |
| 3584 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 3585 | } |
| 3586 | for _, tc := range testcases { |
| 3587 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 3588 | ctx, _ := testApex(t, ` |
| 3589 | apex { |
| 3590 | name: "myapex", |
| 3591 | key: "myapex.key", |
| 3592 | `+tc.propName+` |
| 3593 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3594 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3595 | apex_key { |
| 3596 | name: "myapex.key", |
| 3597 | public_key: "testkey.avbpubkey", |
| 3598 | private_key: "testkey.pem", |
| 3599 | } |
| 3600 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3601 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3602 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3603 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 3604 | actual := apex.installDir.String() |
| 3605 | if actual != expected { |
| 3606 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 3607 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3608 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3609 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 3610 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 3611 | actual = flattened.installDir.String() |
| 3612 | if actual != expected { |
| 3613 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 3614 | } |
| 3615 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3616 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3617 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3618 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3619 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3620 | ctx, _ := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3621 | apex { |
| 3622 | name: "myapex", |
| 3623 | key: "myapex.key", |
| 3624 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3625 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3626 | apex_key { |
| 3627 | name: "myapex.key", |
| 3628 | public_key: "testkey.avbpubkey", |
| 3629 | private_key: "testkey.pem", |
| 3630 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3631 | `) |
| 3632 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3633 | rule := module.Output("file_contexts") |
| 3634 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 3635 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3636 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3637 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3638 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3639 | apex { |
| 3640 | name: "myapex", |
| 3641 | key: "myapex.key", |
| 3642 | file_contexts: "my_own_file_contexts", |
| 3643 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3644 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3645 | apex_key { |
| 3646 | name: "myapex.key", |
| 3647 | public_key: "testkey.avbpubkey", |
| 3648 | private_key: "testkey.pem", |
| 3649 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3650 | `, withFiles(map[string][]byte{ |
| 3651 | "my_own_file_contexts": nil, |
| 3652 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3653 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3654 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3655 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3656 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3657 | apex { |
| 3658 | name: "myapex", |
| 3659 | key: "myapex.key", |
| 3660 | product_specific: true, |
| 3661 | file_contexts: "product_specific_file_contexts", |
| 3662 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3663 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3664 | apex_key { |
| 3665 | name: "myapex.key", |
| 3666 | public_key: "testkey.avbpubkey", |
| 3667 | private_key: "testkey.pem", |
| 3668 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3669 | `) |
| 3670 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3671 | ctx, _ := testApex(t, ` |
| 3672 | apex { |
| 3673 | name: "myapex", |
| 3674 | key: "myapex.key", |
| 3675 | product_specific: true, |
| 3676 | file_contexts: "product_specific_file_contexts", |
| 3677 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3678 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3679 | apex_key { |
| 3680 | name: "myapex.key", |
| 3681 | public_key: "testkey.avbpubkey", |
| 3682 | private_key: "testkey.pem", |
| 3683 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3684 | `, withFiles(map[string][]byte{ |
| 3685 | "product_specific_file_contexts": nil, |
| 3686 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3687 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3688 | rule := module.Output("file_contexts") |
| 3689 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 3690 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3691 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3692 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
| 3693 | ctx, _ := testApex(t, ` |
| 3694 | apex { |
| 3695 | name: "myapex", |
| 3696 | key: "myapex.key", |
| 3697 | product_specific: true, |
| 3698 | file_contexts: ":my-file-contexts", |
| 3699 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3700 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3701 | apex_key { |
| 3702 | name: "myapex.key", |
| 3703 | public_key: "testkey.avbpubkey", |
| 3704 | private_key: "testkey.pem", |
| 3705 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3706 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3707 | filegroup { |
| 3708 | name: "my-file-contexts", |
| 3709 | srcs: ["product_specific_file_contexts"], |
| 3710 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3711 | `, withFiles(map[string][]byte{ |
| 3712 | "product_specific_file_contexts": nil, |
| 3713 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3714 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3715 | rule := module.Output("file_contexts") |
| 3716 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3717 | } |
| 3718 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3719 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3720 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3721 | apex_key { |
| 3722 | name: "myapex.key", |
| 3723 | public_key: ":my.avbpubkey", |
| 3724 | private_key: ":my.pem", |
| 3725 | product_specific: true, |
| 3726 | } |
| 3727 | |
| 3728 | filegroup { |
| 3729 | name: "my.avbpubkey", |
| 3730 | srcs: ["testkey2.avbpubkey"], |
| 3731 | } |
| 3732 | |
| 3733 | filegroup { |
| 3734 | name: "my.pem", |
| 3735 | srcs: ["testkey2.pem"], |
| 3736 | } |
| 3737 | `) |
| 3738 | |
| 3739 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 3740 | expected_pubkey := "testkey2.avbpubkey" |
| 3741 | actual_pubkey := apex_key.public_key_file.String() |
| 3742 | if actual_pubkey != expected_pubkey { |
| 3743 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 3744 | } |
| 3745 | expected_privkey := "testkey2.pem" |
| 3746 | actual_privkey := apex_key.private_key_file.String() |
| 3747 | if actual_privkey != expected_privkey { |
| 3748 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 3749 | } |
| 3750 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3751 | |
| 3752 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3753 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3754 | prebuilt_apex { |
| 3755 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 3756 | arch: { |
| 3757 | arm64: { |
| 3758 | src: "myapex-arm64.apex", |
| 3759 | }, |
| 3760 | arm: { |
| 3761 | src: "myapex-arm.apex", |
| 3762 | }, |
| 3763 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3764 | } |
| 3765 | `) |
| 3766 | |
| 3767 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 3768 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 3769 | expectedInput := "myapex-arm64.apex" |
| 3770 | if prebuilt.inputApex.String() != expectedInput { |
| 3771 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 3772 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3773 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 3774 | |
| 3775 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3776 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 3777 | prebuilt_apex { |
| 3778 | name: "myapex", |
| 3779 | src: "myapex-arm.apex", |
| 3780 | filename: "notmyapex.apex", |
| 3781 | } |
| 3782 | `) |
| 3783 | |
| 3784 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 3785 | |
| 3786 | expected := "notmyapex.apex" |
| 3787 | if p.installFilename != expected { |
| 3788 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 3789 | } |
| 3790 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 3791 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3792 | func TestPrebuiltOverrides(t *testing.T) { |
| 3793 | ctx, config := testApex(t, ` |
| 3794 | prebuilt_apex { |
| 3795 | name: "myapex.prebuilt", |
| 3796 | src: "myapex-arm.apex", |
| 3797 | overrides: [ |
| 3798 | "myapex", |
| 3799 | ], |
| 3800 | } |
| 3801 | `) |
| 3802 | |
| 3803 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 3804 | |
| 3805 | expected := []string{"myapex"} |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 3806 | actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3807 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 3808 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3812 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3813 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3814 | apex_test { |
| 3815 | name: "myapex", |
| 3816 | key: "myapex.key", |
| 3817 | tests: [ |
| 3818 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3819 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3820 | ], |
| 3821 | } |
| 3822 | |
| 3823 | apex_key { |
| 3824 | name: "myapex.key", |
| 3825 | public_key: "testkey.avbpubkey", |
| 3826 | private_key: "testkey.pem", |
| 3827 | } |
| 3828 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 3829 | filegroup { |
| 3830 | name: "fg", |
| 3831 | srcs: [ |
| 3832 | "baz", |
| 3833 | "bar/baz" |
| 3834 | ], |
| 3835 | } |
| 3836 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3837 | cc_test { |
| 3838 | name: "mytest", |
| 3839 | gtest: false, |
| 3840 | srcs: ["mytest.cpp"], |
| 3841 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 3842 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3843 | system_shared_libs: [], |
| 3844 | static_executable: true, |
| 3845 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 3846 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3847 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3848 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 3849 | cc_library { |
| 3850 | name: "mylib", |
| 3851 | srcs: ["mylib.cpp"], |
| 3852 | system_shared_libs: [], |
| 3853 | stl: "none", |
| 3854 | } |
| 3855 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 3856 | filegroup { |
| 3857 | name: "fg2", |
| 3858 | srcs: [ |
| 3859 | "testdata/baz" |
| 3860 | ], |
| 3861 | } |
| 3862 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3863 | cc_test { |
| 3864 | name: "mytests", |
| 3865 | gtest: false, |
| 3866 | srcs: [ |
| 3867 | "mytest1.cpp", |
| 3868 | "mytest2.cpp", |
| 3869 | "mytest3.cpp", |
| 3870 | ], |
| 3871 | test_per_src: true, |
| 3872 | relative_install_path: "test", |
| 3873 | system_shared_libs: [], |
| 3874 | static_executable: true, |
| 3875 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 3876 | data: [ |
| 3877 | ":fg", |
| 3878 | ":fg2", |
| 3879 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3880 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3881 | `) |
| 3882 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3883 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3884 | copyCmds := apexRule.Args["copy_commands"] |
| 3885 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 3886 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3887 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 3888 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3889 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 3890 | //Ensure that test data are copied into apex. |
| 3891 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 3892 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 3893 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3894 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 3895 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 3896 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 3897 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3898 | |
| 3899 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 3900 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3901 | data := android.AndroidMkDataForTest(t, config, "", bundle) |
| 3902 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3903 | prefix := "TARGET_" |
| 3904 | var builder strings.Builder |
| 3905 | data.Custom(&builder, name, prefix, "", data) |
| 3906 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3907 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 3908 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 3909 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 3910 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3911 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3912 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3913 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 3914 | |
| 3915 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 3916 | data = android.AndroidMkDataForTest(t, config, "", flatBundle) |
| 3917 | data.Custom(&builder, name, prefix, "", data) |
| 3918 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 3919 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 3920 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3921 | } |
| 3922 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 3923 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
| 3924 | ctx, config := testApex(t, ` |
| 3925 | apex { |
| 3926 | name: "myapex", |
| 3927 | key: "myapex.key", |
| 3928 | } |
| 3929 | apex_key { |
| 3930 | name: "myapex.key", |
| 3931 | public_key: "testkey.avbpubkey", |
| 3932 | private_key: "testkey.pem", |
| 3933 | } |
| 3934 | `, func(fs map[string][]byte, config android.Config) { |
| 3935 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 3936 | }) |
| 3937 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 3938 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 3939 | mk := android.AndroidMkDataForTest(t, config, "", ab) |
| 3940 | var builder strings.Builder |
| 3941 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 3942 | androidMk := builder.String() |
| 3943 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 3944 | } |
| 3945 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3946 | func TestApexUsesOtherApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3947 | ctx, _ := testApex(t, ` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3948 | apex { |
| 3949 | name: "myapex", |
| 3950 | key: "myapex.key", |
| 3951 | native_shared_libs: ["mylib"], |
| 3952 | uses: ["commonapex"], |
| 3953 | } |
| 3954 | |
| 3955 | apex { |
| 3956 | name: "commonapex", |
| 3957 | key: "myapex.key", |
| 3958 | native_shared_libs: ["libcommon"], |
| 3959 | provide_cpp_shared_libs: true, |
| 3960 | } |
| 3961 | |
| 3962 | apex_key { |
| 3963 | name: "myapex.key", |
| 3964 | public_key: "testkey.avbpubkey", |
| 3965 | private_key: "testkey.pem", |
| 3966 | } |
| 3967 | |
| 3968 | cc_library { |
| 3969 | name: "mylib", |
| 3970 | srcs: ["mylib.cpp"], |
| 3971 | shared_libs: ["libcommon"], |
| 3972 | system_shared_libs: [], |
| 3973 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3974 | apex_available: [ "myapex" ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | cc_library { |
| 3978 | name: "libcommon", |
| 3979 | srcs: ["mylib_common.cpp"], |
| 3980 | system_shared_libs: [], |
| 3981 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3982 | // TODO: remove //apex_available:platform |
| 3983 | apex_available: [ |
| 3984 | "//apex_available:platform", |
| 3985 | "commonapex", |
| 3986 | "myapex", |
| 3987 | ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3988 | } |
| 3989 | `) |
| 3990 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3991 | module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3992 | apexRule1 := module1.Rule("apexRule") |
| 3993 | copyCmds1 := apexRule1.Args["copy_commands"] |
| 3994 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3995 | module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3996 | apexRule2 := module2.Rule("apexRule") |
| 3997 | copyCmds2 := apexRule2.Args["copy_commands"] |
| 3998 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3999 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 4000 | ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4001 | ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so") |
| 4002 | ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so") |
| 4003 | ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so") |
| 4004 | } |
| 4005 | |
| 4006 | func TestApexUsesFailsIfNotProvided(t *testing.T) { |
| 4007 | testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, ` |
| 4008 | apex { |
| 4009 | name: "myapex", |
| 4010 | key: "myapex.key", |
| 4011 | uses: ["commonapex"], |
| 4012 | } |
| 4013 | |
| 4014 | apex { |
| 4015 | name: "commonapex", |
| 4016 | key: "myapex.key", |
| 4017 | } |
| 4018 | |
| 4019 | apex_key { |
| 4020 | name: "myapex.key", |
| 4021 | public_key: "testkey.avbpubkey", |
| 4022 | private_key: "testkey.pem", |
| 4023 | } |
| 4024 | `) |
| 4025 | testApexError(t, `uses: "commonapex" is not a provider`, ` |
| 4026 | apex { |
| 4027 | name: "myapex", |
| 4028 | key: "myapex.key", |
| 4029 | uses: ["commonapex"], |
| 4030 | } |
| 4031 | |
| 4032 | cc_library { |
| 4033 | name: "commonapex", |
| 4034 | system_shared_libs: [], |
| 4035 | stl: "none", |
| 4036 | } |
| 4037 | |
| 4038 | apex_key { |
| 4039 | name: "myapex.key", |
| 4040 | public_key: "testkey.avbpubkey", |
| 4041 | private_key: "testkey.pem", |
| 4042 | } |
| 4043 | `) |
| 4044 | } |
| 4045 | |
| 4046 | func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) { |
| 4047 | testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, ` |
| 4048 | apex { |
| 4049 | name: "myapex", |
| 4050 | key: "myapex.key", |
| 4051 | use_vendor: true, |
| 4052 | uses: ["commonapex"], |
| 4053 | } |
| 4054 | |
| 4055 | apex { |
| 4056 | name: "commonapex", |
| 4057 | key: "myapex.key", |
| 4058 | provide_cpp_shared_libs: true, |
| 4059 | } |
| 4060 | |
| 4061 | apex_key { |
| 4062 | name: "myapex.key", |
| 4063 | public_key: "testkey.avbpubkey", |
| 4064 | private_key: "testkey.pem", |
| 4065 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 4066 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 4067 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 4068 | }) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4069 | } |
| 4070 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4071 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 4072 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 4073 | apex { |
| 4074 | name: "myapex", |
| 4075 | key: "myapex.key", |
| 4076 | native_shared_libs: ["libfoo"], |
| 4077 | } |
| 4078 | |
| 4079 | apex_key { |
| 4080 | name: "myapex.key", |
| 4081 | public_key: "testkey.avbpubkey", |
| 4082 | private_key: "testkey.pem", |
| 4083 | } |
| 4084 | |
| 4085 | cc_library { |
| 4086 | name: "libfoo", |
| 4087 | stl: "none", |
| 4088 | system_shared_libs: [], |
| 4089 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4090 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4091 | } |
| 4092 | `) |
| 4093 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 4094 | apex { |
| 4095 | name: "myapex", |
| 4096 | key: "myapex.key", |
| 4097 | java_libs: ["myjar"], |
| 4098 | } |
| 4099 | |
| 4100 | apex_key { |
| 4101 | name: "myapex.key", |
| 4102 | public_key: "testkey.avbpubkey", |
| 4103 | private_key: "testkey.pem", |
| 4104 | } |
| 4105 | |
| 4106 | java_library { |
| 4107 | name: "myjar", |
| 4108 | srcs: ["foo/bar/MyClass.java"], |
| 4109 | sdk_version: "none", |
| 4110 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4111 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4112 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4113 | } |
| 4114 | `) |
| 4115 | } |
| 4116 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4117 | func TestApexWithApps(t *testing.T) { |
| 4118 | ctx, _ := testApex(t, ` |
| 4119 | apex { |
| 4120 | name: "myapex", |
| 4121 | key: "myapex.key", |
| 4122 | apps: [ |
| 4123 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4124 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4125 | ], |
| 4126 | } |
| 4127 | |
| 4128 | apex_key { |
| 4129 | name: "myapex.key", |
| 4130 | public_key: "testkey.avbpubkey", |
| 4131 | private_key: "testkey.pem", |
| 4132 | } |
| 4133 | |
| 4134 | android_app { |
| 4135 | name: "AppFoo", |
| 4136 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4137 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4138 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4139 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4140 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4141 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4142 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4143 | |
| 4144 | android_app { |
| 4145 | name: "AppFooPriv", |
| 4146 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4147 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4148 | system_modules: "none", |
| 4149 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4150 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4151 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4152 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4153 | |
| 4154 | cc_library_shared { |
| 4155 | name: "libjni", |
| 4156 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4157 | shared_libs: ["libfoo"], |
| 4158 | stl: "none", |
| 4159 | system_shared_libs: [], |
| 4160 | apex_available: [ "myapex" ], |
| 4161 | sdk_version: "current", |
| 4162 | } |
| 4163 | |
| 4164 | cc_library_shared { |
| 4165 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4166 | stl: "none", |
| 4167 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 4168 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4169 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4170 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4171 | `) |
| 4172 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4173 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4174 | apexRule := module.Rule("apexRule") |
| 4175 | copyCmds := apexRule.Args["copy_commands"] |
| 4176 | |
| 4177 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4178 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4179 | |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4180 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs") |
| 4181 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4182 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4183 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4184 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4185 | // JNI libraries including transitive deps are |
| 4186 | for _, jni := range []string{"libjni", "libfoo"} { |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 4187 | 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] | 4188 | // ... embedded inside APK (jnilibs.zip) |
| 4189 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 4190 | // ... and not directly inside the APEX |
| 4191 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 4192 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4193 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4194 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4195 | func TestApexWithAppImports(t *testing.T) { |
| 4196 | ctx, _ := testApex(t, ` |
| 4197 | apex { |
| 4198 | name: "myapex", |
| 4199 | key: "myapex.key", |
| 4200 | apps: [ |
| 4201 | "AppFooPrebuilt", |
| 4202 | "AppFooPrivPrebuilt", |
| 4203 | ], |
| 4204 | } |
| 4205 | |
| 4206 | apex_key { |
| 4207 | name: "myapex.key", |
| 4208 | public_key: "testkey.avbpubkey", |
| 4209 | private_key: "testkey.pem", |
| 4210 | } |
| 4211 | |
| 4212 | android_app_import { |
| 4213 | name: "AppFooPrebuilt", |
| 4214 | apk: "PrebuiltAppFoo.apk", |
| 4215 | presigned: true, |
| 4216 | dex_preopt: { |
| 4217 | enabled: false, |
| 4218 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4219 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4220 | } |
| 4221 | |
| 4222 | android_app_import { |
| 4223 | name: "AppFooPrivPrebuilt", |
| 4224 | apk: "PrebuiltAppFooPriv.apk", |
| 4225 | privileged: true, |
| 4226 | presigned: true, |
| 4227 | dex_preopt: { |
| 4228 | enabled: false, |
| 4229 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4230 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4231 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4232 | } |
| 4233 | `) |
| 4234 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4235 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4236 | apexRule := module.Rule("apexRule") |
| 4237 | copyCmds := apexRule.Args["copy_commands"] |
| 4238 | |
| 4239 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4240 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 4241 | } |
| 4242 | |
| 4243 | func TestApexWithAppImportsPrefer(t *testing.T) { |
| 4244 | ctx, _ := testApex(t, ` |
| 4245 | apex { |
| 4246 | name: "myapex", |
| 4247 | key: "myapex.key", |
| 4248 | apps: [ |
| 4249 | "AppFoo", |
| 4250 | ], |
| 4251 | } |
| 4252 | |
| 4253 | apex_key { |
| 4254 | name: "myapex.key", |
| 4255 | public_key: "testkey.avbpubkey", |
| 4256 | private_key: "testkey.pem", |
| 4257 | } |
| 4258 | |
| 4259 | android_app { |
| 4260 | name: "AppFoo", |
| 4261 | srcs: ["foo/bar/MyClass.java"], |
| 4262 | sdk_version: "none", |
| 4263 | system_modules: "none", |
| 4264 | apex_available: [ "myapex" ], |
| 4265 | } |
| 4266 | |
| 4267 | android_app_import { |
| 4268 | name: "AppFoo", |
| 4269 | apk: "AppFooPrebuilt.apk", |
| 4270 | filename: "AppFooPrebuilt.apk", |
| 4271 | presigned: true, |
| 4272 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4273 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4274 | } |
| 4275 | `, withFiles(map[string][]byte{ |
| 4276 | "AppFooPrebuilt.apk": nil, |
| 4277 | })) |
| 4278 | |
| 4279 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4280 | "app/AppFoo/AppFooPrebuilt.apk", |
| 4281 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4282 | } |
| 4283 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 4284 | func TestApexWithTestHelperApp(t *testing.T) { |
| 4285 | ctx, _ := testApex(t, ` |
| 4286 | apex { |
| 4287 | name: "myapex", |
| 4288 | key: "myapex.key", |
| 4289 | apps: [ |
| 4290 | "TesterHelpAppFoo", |
| 4291 | ], |
| 4292 | } |
| 4293 | |
| 4294 | apex_key { |
| 4295 | name: "myapex.key", |
| 4296 | public_key: "testkey.avbpubkey", |
| 4297 | private_key: "testkey.pem", |
| 4298 | } |
| 4299 | |
| 4300 | android_test_helper_app { |
| 4301 | name: "TesterHelpAppFoo", |
| 4302 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4303 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | `) |
| 4307 | |
| 4308 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4309 | apexRule := module.Rule("apexRule") |
| 4310 | copyCmds := apexRule.Args["copy_commands"] |
| 4311 | |
| 4312 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 4313 | } |
| 4314 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 4315 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 4316 | // libfoo's apex_available comes from cc_defaults |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4317 | testApexError(t, `requires "libfoo" that is not available for the APEX`, ` |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 4318 | apex { |
| 4319 | name: "myapex", |
| 4320 | key: "myapex.key", |
| 4321 | native_shared_libs: ["libfoo"], |
| 4322 | } |
| 4323 | |
| 4324 | apex_key { |
| 4325 | name: "myapex.key", |
| 4326 | public_key: "testkey.avbpubkey", |
| 4327 | private_key: "testkey.pem", |
| 4328 | } |
| 4329 | |
| 4330 | apex { |
| 4331 | name: "otherapex", |
| 4332 | key: "myapex.key", |
| 4333 | native_shared_libs: ["libfoo"], |
| 4334 | } |
| 4335 | |
| 4336 | cc_defaults { |
| 4337 | name: "libfoo-defaults", |
| 4338 | apex_available: ["otherapex"], |
| 4339 | } |
| 4340 | |
| 4341 | cc_library { |
| 4342 | name: "libfoo", |
| 4343 | defaults: ["libfoo-defaults"], |
| 4344 | stl: "none", |
| 4345 | system_shared_libs: [], |
| 4346 | }`) |
| 4347 | } |
| 4348 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4349 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4350 | // libfoo is not available to myapex, but only to otherapex |
| 4351 | testApexError(t, "requires \"libfoo\" that is not available for the APEX", ` |
| 4352 | apex { |
| 4353 | name: "myapex", |
| 4354 | key: "myapex.key", |
| 4355 | native_shared_libs: ["libfoo"], |
| 4356 | } |
| 4357 | |
| 4358 | apex_key { |
| 4359 | name: "myapex.key", |
| 4360 | public_key: "testkey.avbpubkey", |
| 4361 | private_key: "testkey.pem", |
| 4362 | } |
| 4363 | |
| 4364 | apex { |
| 4365 | name: "otherapex", |
| 4366 | key: "otherapex.key", |
| 4367 | native_shared_libs: ["libfoo"], |
| 4368 | } |
| 4369 | |
| 4370 | apex_key { |
| 4371 | name: "otherapex.key", |
| 4372 | public_key: "testkey.avbpubkey", |
| 4373 | private_key: "testkey.pem", |
| 4374 | } |
| 4375 | |
| 4376 | cc_library { |
| 4377 | name: "libfoo", |
| 4378 | stl: "none", |
| 4379 | system_shared_libs: [], |
| 4380 | apex_available: ["otherapex"], |
| 4381 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4382 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4383 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4384 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4385 | // libbbaz is an indirect dep |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4386 | testApexError(t, `requires "libbaz" that is not available for the APEX. Dependency path: |
Paul Duffin | c519244 | 2020-03-31 11:31:36 +0100 | [diff] [blame] | 4387 | .*via tag apex\.dependencyTag.*"sharedLib".* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4388 | .*-> libfoo.*link:shared.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 4389 | .*via tag cc\.DependencyTag.*"shared".* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4390 | .*-> libbar.*link:shared.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 4391 | .*via tag cc\.DependencyTag.*"shared".* |
| 4392 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4393 | apex { |
| 4394 | name: "myapex", |
| 4395 | key: "myapex.key", |
| 4396 | native_shared_libs: ["libfoo"], |
| 4397 | } |
| 4398 | |
| 4399 | apex_key { |
| 4400 | name: "myapex.key", |
| 4401 | public_key: "testkey.avbpubkey", |
| 4402 | private_key: "testkey.pem", |
| 4403 | } |
| 4404 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4405 | cc_library { |
| 4406 | name: "libfoo", |
| 4407 | stl: "none", |
| 4408 | shared_libs: ["libbar"], |
| 4409 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4410 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | cc_library { |
| 4414 | name: "libbar", |
| 4415 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4416 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4417 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4418 | apex_available: ["myapex"], |
| 4419 | } |
| 4420 | |
| 4421 | cc_library { |
| 4422 | name: "libbaz", |
| 4423 | stl: "none", |
| 4424 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4425 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4426 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4427 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4428 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4429 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 4430 | apex { |
| 4431 | name: "myapex", |
| 4432 | key: "myapex.key", |
| 4433 | native_shared_libs: ["libfoo"], |
| 4434 | } |
| 4435 | |
| 4436 | apex_key { |
| 4437 | name: "myapex.key", |
| 4438 | public_key: "testkey.avbpubkey", |
| 4439 | private_key: "testkey.pem", |
| 4440 | } |
| 4441 | |
| 4442 | cc_library { |
| 4443 | name: "libfoo", |
| 4444 | stl: "none", |
| 4445 | system_shared_libs: [], |
| 4446 | apex_available: ["otherapex"], |
| 4447 | }`) |
| 4448 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4449 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4450 | apex { |
| 4451 | name: "myapex", |
| 4452 | key: "myapex.key", |
| 4453 | native_shared_libs: ["libfoo", "libbar"], |
| 4454 | } |
| 4455 | |
| 4456 | apex_key { |
| 4457 | name: "myapex.key", |
| 4458 | public_key: "testkey.avbpubkey", |
| 4459 | private_key: "testkey.pem", |
| 4460 | } |
| 4461 | |
| 4462 | cc_library { |
| 4463 | name: "libfoo", |
| 4464 | stl: "none", |
| 4465 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 4466 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4467 | apex_available: ["myapex"], |
| 4468 | } |
| 4469 | |
| 4470 | cc_library { |
| 4471 | name: "libbar", |
| 4472 | stl: "none", |
| 4473 | system_shared_libs: [], |
| 4474 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | cc_library { |
| 4478 | name: "libbaz", |
| 4479 | stl: "none", |
| 4480 | system_shared_libs: [], |
| 4481 | stubs: { |
| 4482 | versions: ["10", "20", "30"], |
| 4483 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4484 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4485 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4486 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4487 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4488 | ctx, _ := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4489 | apex { |
| 4490 | name: "myapex", |
| 4491 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4492 | native_shared_libs: ["libbar", "libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | apex_key { |
| 4496 | name: "myapex.key", |
| 4497 | public_key: "testkey.avbpubkey", |
| 4498 | private_key: "testkey.pem", |
| 4499 | } |
| 4500 | |
| 4501 | cc_library { |
| 4502 | name: "libfoo", |
| 4503 | stl: "none", |
| 4504 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4505 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4506 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | cc_library { |
| 4510 | name: "libfoo2", |
| 4511 | stl: "none", |
| 4512 | system_shared_libs: [], |
| 4513 | shared_libs: ["libbaz"], |
| 4514 | apex_available: ["//apex_available:platform"], |
| 4515 | } |
| 4516 | |
| 4517 | cc_library { |
| 4518 | name: "libbar", |
| 4519 | stl: "none", |
| 4520 | system_shared_libs: [], |
| 4521 | apex_available: ["myapex"], |
| 4522 | } |
| 4523 | |
| 4524 | cc_library { |
| 4525 | name: "libbaz", |
| 4526 | stl: "none", |
| 4527 | system_shared_libs: [], |
| 4528 | apex_available: ["myapex"], |
| 4529 | stubs: { |
| 4530 | versions: ["1"], |
| 4531 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4532 | }`) |
| 4533 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4534 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 4535 | // because it depends on libbar which isn't available to platform |
| 4536 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4537 | if libfoo.NotAvailableForPlatform() != true { |
| 4538 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 4539 | } |
| 4540 | |
| 4541 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 4542 | // stubs |
| 4543 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4544 | if libfoo2.NotAvailableForPlatform() == true { |
| 4545 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 4546 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4547 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 4548 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4549 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4550 | ctx, _ := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 4551 | apex { |
| 4552 | name: "myapex", |
| 4553 | key: "myapex.key", |
| 4554 | native_shared_libs: ["libfoo"], |
| 4555 | } |
| 4556 | |
| 4557 | apex_key { |
| 4558 | name: "myapex.key", |
| 4559 | public_key: "testkey.avbpubkey", |
| 4560 | private_key: "testkey.pem", |
| 4561 | } |
| 4562 | |
| 4563 | cc_library { |
| 4564 | name: "libfoo", |
| 4565 | stl: "none", |
| 4566 | system_shared_libs: [], |
| 4567 | apex_available: ["myapex"], |
| 4568 | static: { |
| 4569 | apex_available: ["//apex_available:platform"], |
| 4570 | }, |
| 4571 | }`) |
| 4572 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4573 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4574 | if libfooShared.NotAvailableForPlatform() != true { |
| 4575 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 4576 | } |
| 4577 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 4578 | if libfooStatic.NotAvailableForPlatform() != false { |
| 4579 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 4580 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4581 | } |
| 4582 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4583 | func TestOverrideApex(t *testing.T) { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4584 | ctx, config := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4585 | apex { |
| 4586 | name: "myapex", |
| 4587 | key: "myapex.key", |
| 4588 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 4589 | overrides: ["oldapex"], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | override_apex { |
| 4593 | name: "override_myapex", |
| 4594 | base: "myapex", |
| 4595 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 4596 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 4597 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 4598 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | apex_key { |
| 4602 | name: "myapex.key", |
| 4603 | public_key: "testkey.avbpubkey", |
| 4604 | private_key: "testkey.pem", |
| 4605 | } |
| 4606 | |
| 4607 | android_app { |
| 4608 | name: "app", |
| 4609 | srcs: ["foo/bar/MyClass.java"], |
| 4610 | package_name: "foo", |
| 4611 | sdk_version: "none", |
| 4612 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4613 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4614 | } |
| 4615 | |
| 4616 | override_android_app { |
| 4617 | name: "override_app", |
| 4618 | base: "app", |
| 4619 | package_name: "bar", |
| 4620 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 4621 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4622 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 4623 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 4624 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 4625 | if originalVariant.GetOverriddenBy() != "" { |
| 4626 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 4627 | } |
| 4628 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 4629 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 4630 | } |
| 4631 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4632 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 4633 | apexRule := module.Rule("apexRule") |
| 4634 | copyCmds := apexRule.Args["copy_commands"] |
| 4635 | |
| 4636 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4637 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4638 | |
| 4639 | apexBundle := module.Module().(*apexBundle) |
| 4640 | name := apexBundle.Name() |
| 4641 | if name != "override_myapex" { |
| 4642 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 4643 | } |
| 4644 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 4645 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 4646 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 4647 | } |
| 4648 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 4649 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 4650 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 4651 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4652 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 4653 | var builder strings.Builder |
| 4654 | data.Custom(&builder, name, "TARGET_", "", data) |
| 4655 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 4656 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4657 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 4658 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 4659 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4660 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 4661 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4662 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 4663 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4664 | } |
| 4665 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4666 | func TestLegacyAndroid10Support(t *testing.T) { |
| 4667 | ctx, _ := testApex(t, ` |
| 4668 | apex { |
| 4669 | name: "myapex", |
| 4670 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4671 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 4672 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | apex_key { |
| 4676 | name: "myapex.key", |
| 4677 | public_key: "testkey.avbpubkey", |
| 4678 | private_key: "testkey.pem", |
| 4679 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4680 | |
| 4681 | cc_library { |
| 4682 | name: "mylib", |
| 4683 | srcs: ["mylib.cpp"], |
| 4684 | stl: "libc++", |
| 4685 | system_shared_libs: [], |
| 4686 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 4687 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4688 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4689 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4690 | |
| 4691 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4692 | args := module.Rule("apexRule").Args |
| 4693 | 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] | 4694 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4695 | |
| 4696 | // The copies of the libraries in the apex should have one more dependency than |
| 4697 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 4698 | // the dependency names directly here but for some reason the names are blank in |
| 4699 | // this test. |
| 4700 | for _, lib := range []string{"libc++", "mylib"} { |
| 4701 | apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits |
| 4702 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 4703 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 4704 | t.Errorf("%q missing unwinder dep", lib) |
| 4705 | } |
| 4706 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4707 | } |
| 4708 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4709 | var filesForSdkLibrary = map[string][]byte{ |
| 4710 | "api/current.txt": nil, |
| 4711 | "api/removed.txt": nil, |
| 4712 | "api/system-current.txt": nil, |
| 4713 | "api/system-removed.txt": nil, |
| 4714 | "api/test-current.txt": nil, |
| 4715 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 4716 | |
| 4717 | // For java_sdk_library_import |
| 4718 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4719 | } |
| 4720 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4721 | func TestJavaSDKLibrary(t *testing.T) { |
| 4722 | ctx, _ := testApex(t, ` |
| 4723 | apex { |
| 4724 | name: "myapex", |
| 4725 | key: "myapex.key", |
| 4726 | java_libs: ["foo"], |
| 4727 | } |
| 4728 | |
| 4729 | apex_key { |
| 4730 | name: "myapex.key", |
| 4731 | public_key: "testkey.avbpubkey", |
| 4732 | private_key: "testkey.pem", |
| 4733 | } |
| 4734 | |
| 4735 | java_sdk_library { |
| 4736 | name: "foo", |
| 4737 | srcs: ["a.java"], |
| 4738 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4739 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4740 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4741 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4742 | |
| 4743 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 4744 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4745 | "javalib/foo.jar", |
| 4746 | "etc/permissions/foo.xml", |
| 4747 | }) |
| 4748 | // 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] | 4749 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 4750 | 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] | 4751 | } |
| 4752 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4753 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
| 4754 | ctx, _ := testApex(t, ` |
| 4755 | apex { |
| 4756 | name: "myapex", |
| 4757 | key: "myapex.key", |
| 4758 | java_libs: ["foo", "bar"], |
| 4759 | } |
| 4760 | |
| 4761 | apex_key { |
| 4762 | name: "myapex.key", |
| 4763 | public_key: "testkey.avbpubkey", |
| 4764 | private_key: "testkey.pem", |
| 4765 | } |
| 4766 | |
| 4767 | java_sdk_library { |
| 4768 | name: "foo", |
| 4769 | srcs: ["a.java"], |
| 4770 | api_packages: ["foo"], |
| 4771 | apex_available: ["myapex"], |
| 4772 | sdk_version: "none", |
| 4773 | system_modules: "none", |
| 4774 | } |
| 4775 | |
| 4776 | java_library { |
| 4777 | name: "bar", |
| 4778 | srcs: ["a.java"], |
| 4779 | libs: ["foo"], |
| 4780 | apex_available: ["myapex"], |
| 4781 | sdk_version: "none", |
| 4782 | system_modules: "none", |
| 4783 | } |
| 4784 | `, withFiles(filesForSdkLibrary)) |
| 4785 | |
| 4786 | // java_sdk_library installs both impl jar and permission XML |
| 4787 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4788 | "javalib/bar.jar", |
| 4789 | "javalib/foo.jar", |
| 4790 | "etc/permissions/foo.xml", |
| 4791 | }) |
| 4792 | |
| 4793 | // The bar library should depend on the implementation jar. |
| 4794 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 4795 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 4796 | t.Errorf("expected %q, found %#q", expected, actual) |
| 4797 | } |
| 4798 | } |
| 4799 | |
| 4800 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
| 4801 | ctx, _ := testApex(t, ` |
| 4802 | apex { |
| 4803 | name: "myapex", |
| 4804 | key: "myapex.key", |
| 4805 | java_libs: ["foo"], |
| 4806 | } |
| 4807 | |
| 4808 | apex_key { |
| 4809 | name: "myapex.key", |
| 4810 | public_key: "testkey.avbpubkey", |
| 4811 | private_key: "testkey.pem", |
| 4812 | } |
| 4813 | |
| 4814 | java_sdk_library { |
| 4815 | name: "foo", |
| 4816 | srcs: ["a.java"], |
| 4817 | api_packages: ["foo"], |
| 4818 | apex_available: ["myapex"], |
| 4819 | sdk_version: "none", |
| 4820 | system_modules: "none", |
| 4821 | } |
| 4822 | |
| 4823 | java_library { |
| 4824 | name: "bar", |
| 4825 | srcs: ["a.java"], |
| 4826 | libs: ["foo"], |
| 4827 | sdk_version: "none", |
| 4828 | system_modules: "none", |
| 4829 | } |
| 4830 | `, withFiles(filesForSdkLibrary)) |
| 4831 | |
| 4832 | // java_sdk_library installs both impl jar and permission XML |
| 4833 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4834 | "javalib/foo.jar", |
| 4835 | "etc/permissions/foo.xml", |
| 4836 | }) |
| 4837 | |
| 4838 | // The bar library should depend on the stubs jar. |
| 4839 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
| 4840 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 4841 | t.Errorf("expected %q, found %#q", expected, actual) |
| 4842 | } |
| 4843 | } |
| 4844 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 4845 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
| 4846 | ctx, _ := testApex(t, ``, |
| 4847 | withFiles(map[string][]byte{ |
| 4848 | "apex/a.java": nil, |
| 4849 | "apex/apex_manifest.json": nil, |
| 4850 | "apex/Android.bp": []byte(` |
| 4851 | package { |
| 4852 | default_visibility: ["//visibility:private"], |
| 4853 | } |
| 4854 | |
| 4855 | apex { |
| 4856 | name: "myapex", |
| 4857 | key: "myapex.key", |
| 4858 | java_libs: ["foo", "bar"], |
| 4859 | } |
| 4860 | |
| 4861 | apex_key { |
| 4862 | name: "myapex.key", |
| 4863 | public_key: "testkey.avbpubkey", |
| 4864 | private_key: "testkey.pem", |
| 4865 | } |
| 4866 | |
| 4867 | java_library { |
| 4868 | name: "bar", |
| 4869 | srcs: ["a.java"], |
| 4870 | libs: ["foo"], |
| 4871 | apex_available: ["myapex"], |
| 4872 | sdk_version: "none", |
| 4873 | system_modules: "none", |
| 4874 | } |
| 4875 | `), |
| 4876 | "source/a.java": nil, |
| 4877 | "source/api/current.txt": nil, |
| 4878 | "source/api/removed.txt": nil, |
| 4879 | "source/Android.bp": []byte(` |
| 4880 | package { |
| 4881 | default_visibility: ["//visibility:private"], |
| 4882 | } |
| 4883 | |
| 4884 | java_sdk_library { |
| 4885 | name: "foo", |
| 4886 | visibility: ["//apex"], |
| 4887 | srcs: ["a.java"], |
| 4888 | api_packages: ["foo"], |
| 4889 | apex_available: ["myapex"], |
| 4890 | sdk_version: "none", |
| 4891 | system_modules: "none", |
| 4892 | public: { |
| 4893 | enabled: true, |
| 4894 | }, |
| 4895 | } |
| 4896 | `), |
| 4897 | "prebuilt/a.jar": nil, |
| 4898 | "prebuilt/Android.bp": []byte(` |
| 4899 | package { |
| 4900 | default_visibility: ["//visibility:private"], |
| 4901 | } |
| 4902 | |
| 4903 | java_sdk_library_import { |
| 4904 | name: "foo", |
| 4905 | visibility: ["//apex", "//source"], |
| 4906 | apex_available: ["myapex"], |
| 4907 | prefer: true, |
| 4908 | public: { |
| 4909 | jars: ["a.jar"], |
| 4910 | }, |
| 4911 | } |
| 4912 | `), |
| 4913 | }), |
| 4914 | ) |
| 4915 | |
| 4916 | // java_sdk_library installs both impl jar and permission XML |
| 4917 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4918 | "javalib/bar.jar", |
| 4919 | "javalib/foo.jar", |
| 4920 | "etc/permissions/foo.xml", |
| 4921 | }) |
| 4922 | |
| 4923 | // The bar library should depend on the implementation jar. |
| 4924 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 4925 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.impl\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 4926 | t.Errorf("expected %q, found %#q", expected, actual) |
| 4927 | } |
| 4928 | } |
| 4929 | |
| 4930 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 4931 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 4932 | apex { |
| 4933 | name: "myapex", |
| 4934 | key: "myapex.key", |
| 4935 | java_libs: ["foo"], |
| 4936 | } |
| 4937 | |
| 4938 | apex_key { |
| 4939 | name: "myapex.key", |
| 4940 | public_key: "testkey.avbpubkey", |
| 4941 | private_key: "testkey.pem", |
| 4942 | } |
| 4943 | |
| 4944 | java_sdk_library_import { |
| 4945 | name: "foo", |
| 4946 | apex_available: ["myapex"], |
| 4947 | prefer: true, |
| 4948 | public: { |
| 4949 | jars: ["a.jar"], |
| 4950 | }, |
| 4951 | } |
| 4952 | |
| 4953 | `, withFiles(filesForSdkLibrary)) |
| 4954 | } |
| 4955 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 4956 | func TestCompatConfig(t *testing.T) { |
| 4957 | ctx, _ := testApex(t, ` |
| 4958 | apex { |
| 4959 | name: "myapex", |
| 4960 | key: "myapex.key", |
| 4961 | prebuilts: ["myjar-platform-compat-config"], |
| 4962 | java_libs: ["myjar"], |
| 4963 | } |
| 4964 | |
| 4965 | apex_key { |
| 4966 | name: "myapex.key", |
| 4967 | public_key: "testkey.avbpubkey", |
| 4968 | private_key: "testkey.pem", |
| 4969 | } |
| 4970 | |
| 4971 | platform_compat_config { |
| 4972 | name: "myjar-platform-compat-config", |
| 4973 | src: ":myjar", |
| 4974 | } |
| 4975 | |
| 4976 | java_library { |
| 4977 | name: "myjar", |
| 4978 | srcs: ["foo/bar/MyClass.java"], |
| 4979 | sdk_version: "none", |
| 4980 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 4981 | apex_available: [ "myapex" ], |
| 4982 | } |
| 4983 | `) |
| 4984 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4985 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 4986 | "javalib/myjar.jar", |
| 4987 | }) |
| 4988 | } |
| 4989 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 4990 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 4991 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 4992 | apex { |
| 4993 | name: "myapex", |
| 4994 | key: "myapex.key", |
| 4995 | java_libs: ["myjar"], |
| 4996 | } |
| 4997 | |
| 4998 | apex_key { |
| 4999 | name: "myapex.key", |
| 5000 | public_key: "testkey.avbpubkey", |
| 5001 | private_key: "testkey.pem", |
| 5002 | } |
| 5003 | |
| 5004 | java_library { |
| 5005 | name: "myjar", |
| 5006 | srcs: ["foo/bar/MyClass.java"], |
| 5007 | sdk_version: "none", |
| 5008 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 5009 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5010 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5011 | } |
| 5012 | `) |
| 5013 | } |
| 5014 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5015 | func TestCarryRequiredModuleNames(t *testing.T) { |
| 5016 | ctx, config := testApex(t, ` |
| 5017 | apex { |
| 5018 | name: "myapex", |
| 5019 | key: "myapex.key", |
| 5020 | native_shared_libs: ["mylib"], |
| 5021 | } |
| 5022 | |
| 5023 | apex_key { |
| 5024 | name: "myapex.key", |
| 5025 | public_key: "testkey.avbpubkey", |
| 5026 | private_key: "testkey.pem", |
| 5027 | } |
| 5028 | |
| 5029 | cc_library { |
| 5030 | name: "mylib", |
| 5031 | srcs: ["mylib.cpp"], |
| 5032 | system_shared_libs: [], |
| 5033 | stl: "none", |
| 5034 | required: ["a", "b"], |
| 5035 | host_required: ["c", "d"], |
| 5036 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5037 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5038 | } |
| 5039 | `) |
| 5040 | |
| 5041 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 5042 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 5043 | name := apexBundle.BaseModuleName() |
| 5044 | prefix := "TARGET_" |
| 5045 | var builder strings.Builder |
| 5046 | data.Custom(&builder, name, prefix, "", data) |
| 5047 | androidMk := builder.String() |
| 5048 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 5049 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 5050 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 5051 | } |
| 5052 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5053 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 5054 | bp := ` |
| 5055 | apex { |
| 5056 | name: "myapex", |
| 5057 | key: "myapex.key", |
| 5058 | native_shared_libs: ["mylib"], |
| 5059 | java_libs: ["myjar"], |
| 5060 | } |
| 5061 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5062 | apex { |
| 5063 | name: "myapex.updatable", |
| 5064 | key: "myapex.key", |
| 5065 | native_shared_libs: ["mylib"], |
| 5066 | java_libs: ["myjar"], |
| 5067 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 5068 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5069 | } |
| 5070 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5071 | apex_key { |
| 5072 | name: "myapex.key", |
| 5073 | public_key: "testkey.avbpubkey", |
| 5074 | private_key: "testkey.pem", |
| 5075 | } |
| 5076 | |
| 5077 | cc_library { |
| 5078 | name: "mylib", |
| 5079 | srcs: ["mylib.cpp"], |
| 5080 | shared_libs: ["myotherlib"], |
| 5081 | system_shared_libs: [], |
| 5082 | stl: "none", |
| 5083 | apex_available: [ |
| 5084 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5085 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5086 | "//apex_available:platform", |
| 5087 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5088 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | cc_library { |
| 5092 | name: "myotherlib", |
| 5093 | srcs: ["mylib.cpp"], |
| 5094 | system_shared_libs: [], |
| 5095 | stl: "none", |
| 5096 | apex_available: [ |
| 5097 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5098 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5099 | "//apex_available:platform", |
| 5100 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5101 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | java_library { |
| 5105 | name: "myjar", |
| 5106 | srcs: ["foo/bar/MyClass.java"], |
| 5107 | sdk_version: "none", |
| 5108 | system_modules: "none", |
| 5109 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5110 | apex_available: [ |
| 5111 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5112 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5113 | "//apex_available:platform", |
| 5114 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5115 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | java_library { |
| 5119 | name: "myotherjar", |
| 5120 | srcs: ["foo/bar/MyClass.java"], |
| 5121 | sdk_version: "none", |
| 5122 | system_modules: "none", |
| 5123 | apex_available: [ |
| 5124 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5125 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5126 | "//apex_available:platform", |
| 5127 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5128 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5129 | } |
| 5130 | ` |
| 5131 | |
| 5132 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 5133 | for _, f := range files { |
| 5134 | if f.path == file { |
| 5135 | if f.isLink { |
| 5136 | t.Errorf("%q is not a real file", file) |
| 5137 | } |
| 5138 | return |
| 5139 | } |
| 5140 | } |
| 5141 | t.Errorf("%q is not found", file) |
| 5142 | } |
| 5143 | |
| 5144 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 5145 | for _, f := range files { |
| 5146 | if f.path == file { |
| 5147 | if !f.isLink { |
| 5148 | t.Errorf("%q is not a symlink", file) |
| 5149 | } |
| 5150 | return |
| 5151 | } |
| 5152 | } |
| 5153 | t.Errorf("%q is not found", file) |
| 5154 | } |
| 5155 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5156 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 5157 | // is updatable or not |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5158 | ctx, _ := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5159 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5160 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5161 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5162 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 5163 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5164 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 5165 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5166 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5167 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 5168 | |
| 5169 | // 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] | 5170 | ctx, _ = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5171 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5172 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5173 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5174 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5175 | |
| 5176 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 5177 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5178 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5179 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5180 | } |
| 5181 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 5182 | func TestApexWithJniLibs(t *testing.T) { |
| 5183 | ctx, _ := testApex(t, ` |
| 5184 | apex { |
| 5185 | name: "myapex", |
| 5186 | key: "myapex.key", |
| 5187 | jni_libs: ["mylib"], |
| 5188 | } |
| 5189 | |
| 5190 | apex_key { |
| 5191 | name: "myapex.key", |
| 5192 | public_key: "testkey.avbpubkey", |
| 5193 | private_key: "testkey.pem", |
| 5194 | } |
| 5195 | |
| 5196 | cc_library { |
| 5197 | name: "mylib", |
| 5198 | srcs: ["mylib.cpp"], |
| 5199 | shared_libs: ["mylib2"], |
| 5200 | system_shared_libs: [], |
| 5201 | stl: "none", |
| 5202 | apex_available: [ "myapex" ], |
| 5203 | } |
| 5204 | |
| 5205 | cc_library { |
| 5206 | name: "mylib2", |
| 5207 | srcs: ["mylib.cpp"], |
| 5208 | system_shared_libs: [], |
| 5209 | stl: "none", |
| 5210 | apex_available: [ "myapex" ], |
| 5211 | } |
| 5212 | `) |
| 5213 | |
| 5214 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 5215 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 5216 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 5217 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5218 | "lib64/mylib.so", |
| 5219 | "lib64/mylib2.so", |
| 5220 | }) |
| 5221 | } |
| 5222 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 5223 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
| 5224 | ctx, _ := testApex(t, ` |
| 5225 | apex { |
| 5226 | name: "myapex", |
| 5227 | key: "myapex.key", |
| 5228 | } |
| 5229 | apex_key { |
| 5230 | name: "myapex.key", |
| 5231 | public_key: "testkey.avbpubkey", |
| 5232 | private_key: "testkey.pem", |
| 5233 | } |
| 5234 | `, func(fs map[string][]byte, config android.Config) { |
| 5235 | delete(config.Targets, android.Android) |
| 5236 | config.AndroidCommonTarget = android.Target{} |
| 5237 | }) |
| 5238 | |
| 5239 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 5240 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 5241 | } |
| 5242 | } |
| 5243 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 5244 | func TestApexWithJniLibs_Errors(t *testing.T) { |
| 5245 | testApexError(t, `jni_libs: "xxx" is not a cc_library`, ` |
| 5246 | apex { |
| 5247 | name: "myapex", |
| 5248 | key: "myapex.key", |
| 5249 | jni_libs: ["xxx"], |
| 5250 | } |
| 5251 | |
| 5252 | apex_key { |
| 5253 | name: "myapex.key", |
| 5254 | public_key: "testkey.avbpubkey", |
| 5255 | private_key: "testkey.pem", |
| 5256 | } |
| 5257 | |
| 5258 | prebuilt_etc { |
| 5259 | name: "xxx", |
| 5260 | src: "xxx", |
| 5261 | } |
| 5262 | `, withFiles(map[string][]byte{ |
| 5263 | "xxx": nil, |
| 5264 | })) |
| 5265 | } |
| 5266 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 5267 | func TestAppBundle(t *testing.T) { |
| 5268 | ctx, _ := testApex(t, ` |
| 5269 | apex { |
| 5270 | name: "myapex", |
| 5271 | key: "myapex.key", |
| 5272 | apps: ["AppFoo"], |
| 5273 | } |
| 5274 | |
| 5275 | apex_key { |
| 5276 | name: "myapex.key", |
| 5277 | public_key: "testkey.avbpubkey", |
| 5278 | private_key: "testkey.pem", |
| 5279 | } |
| 5280 | |
| 5281 | android_app { |
| 5282 | name: "AppFoo", |
| 5283 | srcs: ["foo/bar/MyClass.java"], |
| 5284 | sdk_version: "none", |
| 5285 | system_modules: "none", |
| 5286 | apex_available: [ "myapex" ], |
| 5287 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 5288 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 5289 | |
| 5290 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config") |
| 5291 | content := bundleConfigRule.Args["content"] |
| 5292 | |
| 5293 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 5294 | 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] | 5295 | } |
| 5296 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5297 | func TestAppSetBundle(t *testing.T) { |
| 5298 | ctx, _ := testApex(t, ` |
| 5299 | apex { |
| 5300 | name: "myapex", |
| 5301 | key: "myapex.key", |
| 5302 | apps: ["AppSet"], |
| 5303 | } |
| 5304 | |
| 5305 | apex_key { |
| 5306 | name: "myapex.key", |
| 5307 | public_key: "testkey.avbpubkey", |
| 5308 | private_key: "testkey.pem", |
| 5309 | } |
| 5310 | |
| 5311 | android_app_set { |
| 5312 | name: "AppSet", |
| 5313 | set: "AppSet.apks", |
| 5314 | }`) |
| 5315 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5316 | bundleConfigRule := mod.Description("Bundle Config") |
| 5317 | content := bundleConfigRule.Args["content"] |
| 5318 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 5319 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 5320 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 5321 | if len(copyCmds) != 3 { |
| 5322 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 5323 | } |
| 5324 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 5325 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 5326 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 5327 | } |
| 5328 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5329 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5330 | t.Helper() |
| 5331 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5332 | bp := ` |
| 5333 | java_library { |
| 5334 | name: "some-updatable-apex-lib", |
| 5335 | srcs: ["a.java"], |
| 5336 | sdk_version: "current", |
| 5337 | apex_available: [ |
| 5338 | "some-updatable-apex", |
| 5339 | ], |
| 5340 | } |
| 5341 | |
| 5342 | java_library { |
| 5343 | name: "some-non-updatable-apex-lib", |
| 5344 | srcs: ["a.java"], |
| 5345 | apex_available: [ |
| 5346 | "some-non-updatable-apex", |
| 5347 | ], |
| 5348 | } |
| 5349 | |
| 5350 | java_library { |
| 5351 | name: "some-platform-lib", |
| 5352 | srcs: ["a.java"], |
| 5353 | sdk_version: "current", |
| 5354 | installable: true, |
| 5355 | } |
| 5356 | |
| 5357 | java_library { |
| 5358 | name: "some-art-lib", |
| 5359 | srcs: ["a.java"], |
| 5360 | sdk_version: "current", |
| 5361 | apex_available: [ |
| 5362 | "com.android.art.something", |
| 5363 | ], |
| 5364 | hostdex: true, |
| 5365 | } |
| 5366 | |
| 5367 | apex { |
| 5368 | name: "some-updatable-apex", |
| 5369 | key: "some-updatable-apex.key", |
| 5370 | java_libs: ["some-updatable-apex-lib"], |
| 5371 | updatable: true, |
| 5372 | min_sdk_version: "current", |
| 5373 | } |
| 5374 | |
| 5375 | apex { |
| 5376 | name: "some-non-updatable-apex", |
| 5377 | key: "some-non-updatable-apex.key", |
| 5378 | java_libs: ["some-non-updatable-apex-lib"], |
| 5379 | } |
| 5380 | |
| 5381 | apex_key { |
| 5382 | name: "some-updatable-apex.key", |
| 5383 | } |
| 5384 | |
| 5385 | apex_key { |
| 5386 | name: "some-non-updatable-apex.key", |
| 5387 | } |
| 5388 | |
| 5389 | apex { |
| 5390 | name: "com.android.art.something", |
| 5391 | key: "com.android.art.something.key", |
| 5392 | java_libs: ["some-art-lib"], |
| 5393 | updatable: true, |
| 5394 | min_sdk_version: "current", |
| 5395 | } |
| 5396 | |
| 5397 | apex_key { |
| 5398 | name: "com.android.art.something.key", |
| 5399 | } |
| 5400 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5401 | filegroup { |
| 5402 | name: "some-updatable-apex-file_contexts", |
| 5403 | srcs: [ |
| 5404 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 5405 | ], |
| 5406 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5407 | |
| 5408 | filegroup { |
| 5409 | name: "some-non-updatable-apex-file_contexts", |
| 5410 | srcs: [ |
| 5411 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 5412 | ], |
| 5413 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5414 | ` |
| 5415 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 5416 | bp += java.GatherRequiredDepsForTest() |
| 5417 | bp += dexpreopt.BpToolModulesForTest() |
| 5418 | |
| 5419 | fs := map[string][]byte{ |
| 5420 | "a.java": nil, |
| 5421 | "a.jar": nil, |
| 5422 | "build/make/target/product/security": nil, |
| 5423 | "apex_manifest.json": nil, |
| 5424 | "AndroidManifest.xml": nil, |
| 5425 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5426 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5427 | "system/sepolicy/apex/com.android.art.something-file_contexts": nil, |
| 5428 | "framework/aidl/a.aidl": nil, |
| 5429 | } |
| 5430 | cc.GatherRequiredFilesForTest(fs) |
| 5431 | |
| 5432 | ctx := android.NewTestArchContext() |
| 5433 | ctx.RegisterModuleType("apex", BundleFactory) |
| 5434 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 5435 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 5436 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5437 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
| 5438 | java.RegisterJavaBuildComponents(ctx) |
| 5439 | java.RegisterSystemModulesBuildComponents(ctx) |
| 5440 | java.RegisterAppBuildComponents(ctx) |
| 5441 | java.RegisterDexpreoptBootJarsComponents(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5442 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 5443 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 5444 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 5445 | |
| 5446 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 5447 | ctx.Register(config) |
| 5448 | |
| 5449 | _ = dexpreopt.GlobalSoongConfigForTests(config) |
| 5450 | dexpreopt.RegisterToolModulesForTest(ctx) |
| 5451 | pathCtx := android.PathContextForTesting(config) |
| 5452 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 5453 | transformDexpreoptConfig(dexpreoptConfig) |
| 5454 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 5455 | |
| 5456 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 5457 | android.FailIfErrored(t, errs) |
| 5458 | |
| 5459 | _, errs = ctx.PrepareBuildActions(config) |
| 5460 | if errmsg == "" { |
| 5461 | android.FailIfErrored(t, errs) |
| 5462 | } else if len(errs) > 0 { |
| 5463 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 5464 | return |
| 5465 | } else { |
| 5466 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 5467 | } |
| 5468 | } |
| 5469 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 5470 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 5471 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 5472 | apex { |
| 5473 | name: "myapex", |
| 5474 | key: "myapex.key", |
| 5475 | updatable: true, |
| 5476 | } |
| 5477 | |
| 5478 | apex_key { |
| 5479 | name: "myapex.key", |
| 5480 | public_key: "testkey.avbpubkey", |
| 5481 | private_key: "testkey.pem", |
| 5482 | } |
| 5483 | `) |
| 5484 | } |
| 5485 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5486 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5487 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5488 | var err string |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5489 | var transform func(*dexpreopt.GlobalConfig) |
| 5490 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5491 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
| 5492 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5493 | config.ArtApexJars = []string{"com.android.art.something:some-art-lib"} |
| 5494 | } |
| 5495 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 5496 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5497 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5498 | 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] | 5499 | 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] | 5500 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5501 | config.BootJars = []string{"com.android.art.something:some-art-lib"} |
| 5502 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5503 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5504 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5505 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5506 | 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] | 5507 | 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] | 5508 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5509 | config.ArtApexJars = []string{"some-updatable-apex:some-updatable-apex-lib"} |
| 5510 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5511 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5512 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5513 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5514 | 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] | 5515 | 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] | 5516 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5517 | config.ArtApexJars = []string{"some-non-updatable-apex:some-non-updatable-apex-lib"} |
| 5518 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5519 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5520 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5521 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5522 | 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] | 5523 | 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] | 5524 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5525 | config.BootJars = []string{"some-updatable-apex:some-updatable-apex-lib"} |
| 5526 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5527 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5528 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5529 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5530 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
| 5531 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5532 | config.BootJars = []string{"some-non-updatable-apex:some-non-updatable-apex-lib"} |
| 5533 | } |
| 5534 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 5535 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5536 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5537 | 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] | 5538 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5539 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5540 | config.ArtApexJars = []string{"platform:nonexistent"} |
| 5541 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5542 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5543 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5544 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5545 | 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] | 5546 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5547 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5548 | config.BootJars = []string{"platform:nonexistent"} |
| 5549 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5550 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5551 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5552 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5553 | 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] | 5554 | 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] | 5555 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5556 | config.ArtApexJars = []string{"platform:some-platform-lib"} |
| 5557 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5558 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5559 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5560 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5561 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
| 5562 | transform = func(config *dexpreopt.GlobalConfig) { |
| 5563 | config.BootJars = []string{"platform:some-platform-lib"} |
| 5564 | } |
| 5565 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 5566 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5567 | } |
| 5568 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 5569 | func TestTestFor(t *testing.T) { |
| 5570 | ctx, _ := testApex(t, ` |
| 5571 | apex { |
| 5572 | name: "myapex", |
| 5573 | key: "myapex.key", |
| 5574 | native_shared_libs: ["mylib", "myprivlib"], |
| 5575 | } |
| 5576 | |
| 5577 | apex_key { |
| 5578 | name: "myapex.key", |
| 5579 | public_key: "testkey.avbpubkey", |
| 5580 | private_key: "testkey.pem", |
| 5581 | } |
| 5582 | |
| 5583 | cc_library { |
| 5584 | name: "mylib", |
| 5585 | srcs: ["mylib.cpp"], |
| 5586 | system_shared_libs: [], |
| 5587 | stl: "none", |
| 5588 | stubs: { |
| 5589 | versions: ["1"], |
| 5590 | }, |
| 5591 | apex_available: ["myapex"], |
| 5592 | } |
| 5593 | |
| 5594 | cc_library { |
| 5595 | name: "myprivlib", |
| 5596 | srcs: ["mylib.cpp"], |
| 5597 | system_shared_libs: [], |
| 5598 | stl: "none", |
| 5599 | apex_available: ["myapex"], |
| 5600 | } |
| 5601 | |
| 5602 | |
| 5603 | cc_test { |
| 5604 | name: "mytest", |
| 5605 | gtest: false, |
| 5606 | srcs: ["mylib.cpp"], |
| 5607 | system_shared_libs: [], |
| 5608 | stl: "none", |
| 5609 | shared_libs: ["mylib", "myprivlib"], |
| 5610 | test_for: ["myapex"] |
| 5611 | } |
| 5612 | `) |
| 5613 | |
| 5614 | // the test 'mytest' is a test for the apex, therefore is linked to the |
| 5615 | // actual implementation of mylib instead of its stub. |
| 5616 | ldFlags := ctx.ModuleForTests("mytest", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 5617 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 5618 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
| 5619 | } |
| 5620 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 5621 | // TODO(jungjw): Move this to proptools |
| 5622 | func intPtr(i int) *int { |
| 5623 | return &i |
| 5624 | } |
| 5625 | |
| 5626 | func TestApexSet(t *testing.T) { |
| 5627 | ctx, config := testApex(t, ` |
| 5628 | apex_set { |
| 5629 | name: "myapex", |
| 5630 | set: "myapex.apks", |
| 5631 | filename: "foo_v2.apex", |
| 5632 | overrides: ["foo"], |
| 5633 | } |
| 5634 | `, func(fs map[string][]byte, config android.Config) { |
| 5635 | config.TestProductVariables.Platform_sdk_version = intPtr(30) |
| 5636 | config.TestProductVariables.DeviceArch = proptools.StringPtr("arm") |
| 5637 | config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm64") |
| 5638 | }) |
| 5639 | |
| 5640 | m := ctx.ModuleForTests("myapex", "android_common") |
| 5641 | |
| 5642 | // Check extract_apks tool parameters. |
| 5643 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 5644 | actual := extractedApex.Args["abis"] |
| 5645 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 5646 | if actual != expected { |
| 5647 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 5648 | } |
| 5649 | actual = extractedApex.Args["sdk-version"] |
| 5650 | expected = "30" |
| 5651 | if actual != expected { |
| 5652 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 5653 | } |
| 5654 | |
| 5655 | a := m.Module().(*ApexSet) |
| 5656 | expectedOverrides := []string{"foo"} |
| 5657 | actualOverrides := android.AndroidMkEntriesForTest(t, config, "", a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
| 5658 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 5659 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 5660 | } |
| 5661 | } |
| 5662 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 5663 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 5664 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 5665 | apex { |
| 5666 | name: "myapex", |
| 5667 | key: "myapex.key", |
| 5668 | native_shared_libs: ["mylib"], |
| 5669 | } |
| 5670 | |
| 5671 | apex_key { |
| 5672 | name: "myapex.key", |
| 5673 | public_key: "testkey.avbpubkey", |
| 5674 | private_key: "testkey.pem", |
| 5675 | } |
| 5676 | |
| 5677 | cc_library { |
| 5678 | name: "mylib", |
| 5679 | srcs: ["mylib.cpp"], |
| 5680 | static_libs: ["otherlib"], |
| 5681 | system_shared_libs: [], |
| 5682 | stl: "none", |
| 5683 | apex_available: [ "myapex" ], |
| 5684 | } |
| 5685 | |
| 5686 | cc_library { |
| 5687 | name: "otherlib", |
| 5688 | srcs: ["mylib.cpp"], |
| 5689 | system_shared_libs: [], |
| 5690 | stl: "none", |
| 5691 | stubs: { |
| 5692 | versions: ["1", "2", "3"], |
| 5693 | }, |
| 5694 | apex_available: [ "myapex" ], |
| 5695 | } |
| 5696 | `) |
| 5697 | } |
| 5698 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 5699 | func TestApexKeysTxt(t *testing.T) { |
| 5700 | ctx, _ := testApex(t, ` |
| 5701 | apex { |
| 5702 | name: "myapex", |
| 5703 | key: "myapex.key", |
| 5704 | } |
| 5705 | |
| 5706 | apex_key { |
| 5707 | name: "myapex.key", |
| 5708 | public_key: "testkey.avbpubkey", |
| 5709 | private_key: "testkey.pem", |
| 5710 | } |
| 5711 | |
| 5712 | prebuilt_apex { |
| 5713 | name: "myapex", |
| 5714 | prefer: true, |
| 5715 | arch: { |
| 5716 | arm64: { |
| 5717 | src: "myapex-arm64.apex", |
| 5718 | }, |
| 5719 | arm: { |
| 5720 | src: "myapex-arm.apex", |
| 5721 | }, |
| 5722 | }, |
| 5723 | } |
| 5724 | |
| 5725 | apex_set { |
| 5726 | name: "myapex_set", |
| 5727 | set: "myapex.apks", |
| 5728 | filename: "myapex_set.apex", |
| 5729 | overrides: ["myapex"], |
| 5730 | } |
| 5731 | `) |
| 5732 | |
| 5733 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 5734 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 5735 | 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] | 5736 | 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] | 5737 | } |
| 5738 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 5739 | func TestAllowedFiles(t *testing.T) { |
| 5740 | ctx, _ := testApex(t, ` |
| 5741 | apex { |
| 5742 | name: "myapex", |
| 5743 | key: "myapex.key", |
| 5744 | apps: ["app"], |
| 5745 | allowed_files: "allowed.txt", |
| 5746 | } |
| 5747 | |
| 5748 | apex_key { |
| 5749 | name: "myapex.key", |
| 5750 | public_key: "testkey.avbpubkey", |
| 5751 | private_key: "testkey.pem", |
| 5752 | } |
| 5753 | |
| 5754 | android_app { |
| 5755 | name: "app", |
| 5756 | srcs: ["foo/bar/MyClass.java"], |
| 5757 | package_name: "foo", |
| 5758 | sdk_version: "none", |
| 5759 | system_modules: "none", |
| 5760 | apex_available: [ "myapex" ], |
| 5761 | } |
| 5762 | `, withFiles(map[string][]byte{ |
| 5763 | "sub/Android.bp": []byte(` |
| 5764 | override_apex { |
| 5765 | name: "override_myapex", |
| 5766 | base: "myapex", |
| 5767 | apps: ["override_app"], |
| 5768 | allowed_files: ":allowed", |
| 5769 | } |
| 5770 | // Overridable "path" property should be referenced indirectly |
| 5771 | filegroup { |
| 5772 | name: "allowed", |
| 5773 | srcs: ["allowed.txt"], |
| 5774 | } |
| 5775 | override_android_app { |
| 5776 | name: "override_app", |
| 5777 | base: "app", |
| 5778 | package_name: "bar", |
| 5779 | } |
| 5780 | `), |
| 5781 | })) |
| 5782 | |
| 5783 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 5784 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 5785 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 5786 | } |
| 5787 | |
| 5788 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 5789 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 5790 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 5791 | } |
| 5792 | } |
| 5793 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 5794 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
| 5795 | _, _ = testApex(t, ` |
| 5796 | apex { |
| 5797 | name: "myapex", |
| 5798 | key: "myapex.key", |
| 5799 | native_shared_libs: ["mylib"], |
| 5800 | } |
| 5801 | |
| 5802 | apex_key { |
| 5803 | name: "myapex.key", |
| 5804 | public_key: "testkey.avbpubkey", |
| 5805 | private_key: "testkey.pem", |
| 5806 | } |
| 5807 | |
| 5808 | cc_library { |
| 5809 | name: "mylib", |
| 5810 | srcs: ["mylib.cpp"], |
| 5811 | stubs: { |
| 5812 | versions: ["10000"], |
| 5813 | }, |
| 5814 | apex_available: ["myapex"], |
| 5815 | } |
| 5816 | |
| 5817 | cc_prebuilt_library_shared { |
| 5818 | name: "mylib", |
| 5819 | prefer: false, |
| 5820 | srcs: ["prebuilt.so"], |
| 5821 | stubs: { |
| 5822 | versions: ["10000"], |
| 5823 | }, |
| 5824 | apex_available: ["myapex"], |
| 5825 | } |
| 5826 | `) |
| 5827 | } |
| 5828 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 5829 | func TestMain(m *testing.M) { |
| 5830 | run := func() int { |
| 5831 | setUp() |
| 5832 | defer tearDown() |
| 5833 | |
| 5834 | return m.Run() |
| 5835 | } |
| 5836 | |
| 5837 | os.Exit(run()) |
| 5838 | } |