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