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