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