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