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