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