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