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