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 | |
| 979 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 980 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 981 | apex { |
| 982 | name: "myapex", |
| 983 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 984 | native_shared_libs: ["mylib"], |
| 985 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 986 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 987 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | apex_key { |
| 991 | name: "myapex.key", |
| 992 | public_key: "testkey.avbpubkey", |
| 993 | private_key: "testkey.pem", |
| 994 | } |
| 995 | |
| 996 | prebuilt_etc { |
| 997 | name: "myetc", |
| 998 | src: "myprebuilt", |
| 999 | sub_dir: "foo/bar", |
| 1000 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1001 | |
| 1002 | cc_library { |
| 1003 | name: "mylib", |
| 1004 | srcs: ["mylib.cpp"], |
| 1005 | relative_install_path: "foo/bar", |
| 1006 | system_shared_libs: [], |
| 1007 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1008 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | cc_binary { |
| 1012 | name: "mybin", |
| 1013 | srcs: ["mylib.cpp"], |
| 1014 | relative_install_path: "foo/bar", |
| 1015 | system_shared_libs: [], |
| 1016 | static_executable: true, |
| 1017 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1018 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1019 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1020 | `) |
| 1021 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1022 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1023 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 1024 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1025 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1026 | ensureListContains(t, dirs, "etc") |
| 1027 | ensureListContains(t, dirs, "etc/foo") |
| 1028 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1029 | ensureListContains(t, dirs, "lib64") |
| 1030 | ensureListContains(t, dirs, "lib64/foo") |
| 1031 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 1032 | ensureListContains(t, dirs, "lib") |
| 1033 | ensureListContains(t, dirs, "lib/foo") |
| 1034 | ensureListContains(t, dirs, "lib/foo/bar") |
| 1035 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 1036 | ensureListContains(t, dirs, "bin") |
| 1037 | ensureListContains(t, dirs, "bin/foo") |
| 1038 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1039 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1040 | |
| 1041 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1042 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1043 | apex { |
| 1044 | name: "myapex", |
| 1045 | key: "myapex.key", |
| 1046 | native_shared_libs: ["mylib"], |
| 1047 | use_vendor: true, |
| 1048 | } |
| 1049 | |
| 1050 | apex_key { |
| 1051 | name: "myapex.key", |
| 1052 | public_key: "testkey.avbpubkey", |
| 1053 | private_key: "testkey.pem", |
| 1054 | } |
| 1055 | |
| 1056 | cc_library { |
| 1057 | name: "mylib", |
| 1058 | srcs: ["mylib.cpp"], |
| 1059 | shared_libs: ["mylib2"], |
| 1060 | system_shared_libs: [], |
| 1061 | vendor_available: true, |
| 1062 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1063 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | cc_library { |
| 1067 | name: "mylib2", |
| 1068 | srcs: ["mylib.cpp"], |
| 1069 | system_shared_libs: [], |
| 1070 | vendor_available: true, |
| 1071 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1072 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1073 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1074 | `, func(fs map[string][]byte, config android.Config) { |
| 1075 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 1076 | }) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1077 | |
| 1078 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1079 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1080 | for _, implicit := range i.Implicits { |
| 1081 | inputsList = append(inputsList, implicit.String()) |
| 1082 | } |
| 1083 | } |
| 1084 | inputsString := strings.Join(inputsList, " ") |
| 1085 | |
| 1086 | // 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] | 1087 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so") |
| 1088 | 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] | 1089 | |
| 1090 | // ensure that the apex does not include core variants |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1091 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so") |
| 1092 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1093 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1094 | |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1095 | func TestUseVendorRestriction(t *testing.T) { |
| 1096 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 1097 | apex { |
| 1098 | name: "myapex", |
| 1099 | key: "myapex.key", |
| 1100 | use_vendor: true, |
| 1101 | } |
| 1102 | apex_key { |
| 1103 | name: "myapex.key", |
| 1104 | public_key: "testkey.avbpubkey", |
| 1105 | private_key: "testkey.pem", |
| 1106 | } |
| 1107 | `, func(fs map[string][]byte, config android.Config) { |
| 1108 | setUseVendorWhitelistForTest(config, []string{""}) |
| 1109 | }) |
| 1110 | // no error with whitelist |
| 1111 | testApex(t, ` |
| 1112 | apex { |
| 1113 | name: "myapex", |
| 1114 | key: "myapex.key", |
| 1115 | use_vendor: true, |
| 1116 | } |
| 1117 | apex_key { |
| 1118 | name: "myapex.key", |
| 1119 | public_key: "testkey.avbpubkey", |
| 1120 | private_key: "testkey.pem", |
| 1121 | } |
| 1122 | `, func(fs map[string][]byte, config android.Config) { |
| 1123 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 1124 | }) |
| 1125 | } |
| 1126 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 1127 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 1128 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 1129 | apex { |
| 1130 | name: "myapex", |
| 1131 | key: "myapex.key", |
| 1132 | native_shared_libs: ["mylib"], |
| 1133 | use_vendor: true, |
| 1134 | } |
| 1135 | |
| 1136 | apex_key { |
| 1137 | name: "myapex.key", |
| 1138 | public_key: "testkey.avbpubkey", |
| 1139 | private_key: "testkey.pem", |
| 1140 | } |
| 1141 | |
| 1142 | cc_library { |
| 1143 | name: "mylib", |
| 1144 | srcs: ["mylib.cpp"], |
| 1145 | system_shared_libs: [], |
| 1146 | stl: "none", |
| 1147 | } |
| 1148 | `) |
| 1149 | } |
| 1150 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1151 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1152 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1153 | apex { |
| 1154 | name: "myapex", |
| 1155 | key: "myapex.key", |
| 1156 | native_shared_libs: ["mylib"], |
| 1157 | } |
| 1158 | |
| 1159 | apex_key { |
| 1160 | name: "myapex.key", |
| 1161 | public_key: "testkey.avbpubkey", |
| 1162 | private_key: "testkey.pem", |
| 1163 | } |
| 1164 | |
| 1165 | cc_library { |
| 1166 | name: "mylib", |
| 1167 | srcs: ["mylib.cpp"], |
| 1168 | system_shared_libs: [], |
| 1169 | stl: "none", |
| 1170 | stubs: { |
| 1171 | versions: ["1", "2", "3"], |
| 1172 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1173 | apex_available: [ |
| 1174 | "//apex_available:platform", |
| 1175 | "myapex", |
| 1176 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | cc_binary { |
| 1180 | name: "not_in_apex", |
| 1181 | srcs: ["mylib.cpp"], |
| 1182 | static_libs: ["mylib"], |
| 1183 | static_executable: true, |
| 1184 | system_shared_libs: [], |
| 1185 | stl: "none", |
| 1186 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1187 | `) |
| 1188 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1189 | 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] | 1190 | |
| 1191 | // 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] | 1192 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1193 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1194 | |
| 1195 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1196 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1197 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1198 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1199 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1200 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1201 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1202 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | cc_library { |
| 1206 | name: "mylib", |
| 1207 | srcs: ["mylib.cpp"], |
| 1208 | system_shared_libs: [], |
| 1209 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1210 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | apex_key { |
| 1214 | name: "myapex.key", |
| 1215 | public_key: "testkey.avbpubkey", |
| 1216 | private_key: "testkey.pem", |
| 1217 | } |
| 1218 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1219 | android_app_certificate { |
| 1220 | name: "myapex.certificate", |
| 1221 | certificate: "testkey", |
| 1222 | } |
| 1223 | |
| 1224 | android_app_certificate { |
| 1225 | name: "myapex.certificate.override", |
| 1226 | certificate: "testkey.override", |
| 1227 | } |
| 1228 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1229 | `) |
| 1230 | |
| 1231 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1232 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1233 | |
| 1234 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 1235 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 1236 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 1237 | } |
| 1238 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 1239 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 1240 | "vendor/foo/devkeys/testkey.pem") |
| 1241 | } |
| 1242 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1243 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1244 | 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] | 1245 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1246 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1247 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1248 | } |
| 1249 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1250 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 1251 | func TestCertificate(t *testing.T) { |
| 1252 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 1253 | ctx, _ := testApex(t, ` |
| 1254 | apex { |
| 1255 | name: "myapex", |
| 1256 | key: "myapex.key", |
| 1257 | } |
| 1258 | apex_key { |
| 1259 | name: "myapex.key", |
| 1260 | public_key: "testkey.avbpubkey", |
| 1261 | private_key: "testkey.pem", |
| 1262 | }`) |
| 1263 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1264 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 1265 | if actual := rule.Args["certificates"]; actual != expected { |
| 1266 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1267 | } |
| 1268 | }) |
| 1269 | t.Run("override when unspecified", func(t *testing.T) { |
| 1270 | ctx, _ := testApex(t, ` |
| 1271 | apex { |
| 1272 | name: "myapex_keytest", |
| 1273 | key: "myapex.key", |
| 1274 | file_contexts: ":myapex-file_contexts", |
| 1275 | } |
| 1276 | apex_key { |
| 1277 | name: "myapex.key", |
| 1278 | public_key: "testkey.avbpubkey", |
| 1279 | private_key: "testkey.pem", |
| 1280 | } |
| 1281 | android_app_certificate { |
| 1282 | name: "myapex.certificate.override", |
| 1283 | certificate: "testkey.override", |
| 1284 | }`) |
| 1285 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1286 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1287 | if actual := rule.Args["certificates"]; actual != expected { |
| 1288 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1289 | } |
| 1290 | }) |
| 1291 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 1292 | ctx, _ := testApex(t, ` |
| 1293 | apex { |
| 1294 | name: "myapex", |
| 1295 | key: "myapex.key", |
| 1296 | certificate: ":myapex.certificate", |
| 1297 | } |
| 1298 | apex_key { |
| 1299 | name: "myapex.key", |
| 1300 | public_key: "testkey.avbpubkey", |
| 1301 | private_key: "testkey.pem", |
| 1302 | } |
| 1303 | android_app_certificate { |
| 1304 | name: "myapex.certificate", |
| 1305 | certificate: "testkey", |
| 1306 | }`) |
| 1307 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1308 | expected := "testkey.x509.pem testkey.pk8" |
| 1309 | if actual := rule.Args["certificates"]; actual != expected { |
| 1310 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1311 | } |
| 1312 | }) |
| 1313 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 1314 | ctx, _ := testApex(t, ` |
| 1315 | apex { |
| 1316 | name: "myapex_keytest", |
| 1317 | key: "myapex.key", |
| 1318 | file_contexts: ":myapex-file_contexts", |
| 1319 | certificate: ":myapex.certificate", |
| 1320 | } |
| 1321 | apex_key { |
| 1322 | name: "myapex.key", |
| 1323 | public_key: "testkey.avbpubkey", |
| 1324 | private_key: "testkey.pem", |
| 1325 | } |
| 1326 | android_app_certificate { |
| 1327 | name: "myapex.certificate.override", |
| 1328 | certificate: "testkey.override", |
| 1329 | }`) |
| 1330 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1331 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1332 | if actual := rule.Args["certificates"]; actual != expected { |
| 1333 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1334 | } |
| 1335 | }) |
| 1336 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 1337 | ctx, _ := testApex(t, ` |
| 1338 | apex { |
| 1339 | name: "myapex", |
| 1340 | key: "myapex.key", |
| 1341 | certificate: "testkey", |
| 1342 | } |
| 1343 | apex_key { |
| 1344 | name: "myapex.key", |
| 1345 | public_key: "testkey.avbpubkey", |
| 1346 | private_key: "testkey.pem", |
| 1347 | }`) |
| 1348 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1349 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 1350 | if actual := rule.Args["certificates"]; actual != expected { |
| 1351 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1352 | } |
| 1353 | }) |
| 1354 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 1355 | ctx, _ := testApex(t, ` |
| 1356 | apex { |
| 1357 | name: "myapex_keytest", |
| 1358 | key: "myapex.key", |
| 1359 | file_contexts: ":myapex-file_contexts", |
| 1360 | certificate: "testkey", |
| 1361 | } |
| 1362 | apex_key { |
| 1363 | name: "myapex.key", |
| 1364 | public_key: "testkey.avbpubkey", |
| 1365 | private_key: "testkey.pem", |
| 1366 | } |
| 1367 | android_app_certificate { |
| 1368 | name: "myapex.certificate.override", |
| 1369 | certificate: "testkey.override", |
| 1370 | }`) |
| 1371 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1372 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1373 | if actual := rule.Args["certificates"]; actual != expected { |
| 1374 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1375 | } |
| 1376 | }) |
| 1377 | } |
| 1378 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1379 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1380 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1381 | apex { |
| 1382 | name: "myapex", |
| 1383 | key: "myapex.key", |
| 1384 | native_shared_libs: ["mylib"], |
| 1385 | } |
| 1386 | |
| 1387 | apex { |
| 1388 | name: "otherapex", |
| 1389 | key: "myapex.key", |
| 1390 | native_shared_libs: ["mylib"], |
| 1391 | } |
| 1392 | |
| 1393 | apex_key { |
| 1394 | name: "myapex.key", |
| 1395 | public_key: "testkey.avbpubkey", |
| 1396 | private_key: "testkey.pem", |
| 1397 | } |
| 1398 | |
| 1399 | cc_library { |
| 1400 | name: "mylib", |
| 1401 | srcs: ["mylib.cpp"], |
| 1402 | system_shared_libs: [], |
| 1403 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1404 | // TODO: remove //apex_available:platform |
| 1405 | apex_available: [ |
| 1406 | "//apex_available:platform", |
| 1407 | "myapex", |
| 1408 | "otherapex", |
| 1409 | ], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1410 | } |
| 1411 | `) |
| 1412 | |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1413 | // non-APEX variant does not have __ANDROID_APEX(_NAME)__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1414 | 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] | 1415 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1416 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1417 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1418 | |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1419 | // APEX variant has __ANDROID_APEX(_NAME)__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1420 | 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] | 1421 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1422 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1423 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1424 | |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1425 | // APEX variant has __ANDROID_APEX(_NAME)__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1426 | 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] | 1427 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1428 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1429 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1430 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1431 | |
| 1432 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1433 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1434 | apex { |
| 1435 | name: "myapex", |
| 1436 | key: "myapex.key", |
| 1437 | native_shared_libs: ["mylib"], |
| 1438 | } |
| 1439 | |
| 1440 | apex_key { |
| 1441 | name: "myapex.key", |
| 1442 | public_key: "testkey.avbpubkey", |
| 1443 | private_key: "testkey.pem", |
| 1444 | } |
| 1445 | |
| 1446 | cc_library_headers { |
| 1447 | name: "mylib_headers", |
| 1448 | export_include_dirs: ["my_include"], |
| 1449 | system_shared_libs: [], |
| 1450 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1451 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | cc_library { |
| 1455 | name: "mylib", |
| 1456 | srcs: ["mylib.cpp"], |
| 1457 | system_shared_libs: [], |
| 1458 | stl: "none", |
| 1459 | header_libs: ["mylib_headers"], |
| 1460 | export_header_lib_headers: ["mylib_headers"], |
| 1461 | stubs: { |
| 1462 | versions: ["1", "2", "3"], |
| 1463 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1464 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | cc_library { |
| 1468 | name: "otherlib", |
| 1469 | srcs: ["mylib.cpp"], |
| 1470 | system_shared_libs: [], |
| 1471 | stl: "none", |
| 1472 | shared_libs: ["mylib"], |
| 1473 | } |
| 1474 | `) |
| 1475 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1476 | 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] | 1477 | |
| 1478 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 1479 | ensureContains(t, cFlags, "-Imy_include") |
| 1480 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1481 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1482 | type fileInApex struct { |
| 1483 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1484 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1485 | isLink bool |
| 1486 | } |
| 1487 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1488 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1489 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1490 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1491 | copyCmds := apexRule.Args["copy_commands"] |
| 1492 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1493 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1494 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 1495 | cmd = strings.TrimSpace(cmd) |
| 1496 | if cmd == "" { |
| 1497 | continue |
| 1498 | } |
| 1499 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1500 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1501 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1502 | switch terms[0] { |
| 1503 | case "mkdir": |
| 1504 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1505 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1506 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 1507 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1508 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1509 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1510 | isLink = false |
| 1511 | case "ln": |
| 1512 | if len(terms) != 3 && len(terms) != 4 { |
| 1513 | // ln LINK TARGET or ln -s LINK TARGET |
| 1514 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 1515 | } |
| 1516 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1517 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1518 | isLink = true |
| 1519 | default: |
| 1520 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 1521 | } |
| 1522 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1523 | index := strings.Index(dst, imageApexDir) |
| 1524 | if index == -1 { |
| 1525 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 1526 | } |
| 1527 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1528 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1529 | } |
| 1530 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1531 | return ret |
| 1532 | } |
| 1533 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1534 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 1535 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1536 | var failed bool |
| 1537 | var surplus []string |
| 1538 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1539 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1540 | for _, expected := range files { |
| 1541 | if matched, _ := path.Match(expected, file.path); matched { |
| 1542 | filesMatched[expected] = true |
| 1543 | return |
| 1544 | } |
| 1545 | } |
| 1546 | surplus = append(surplus, file.path) |
| 1547 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1548 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1549 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1550 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1551 | t.Log("surplus files", surplus) |
| 1552 | failed = true |
| 1553 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1554 | |
| 1555 | if len(files) > len(filesMatched) { |
| 1556 | var missing []string |
| 1557 | for _, expected := range files { |
| 1558 | if !filesMatched[expected] { |
| 1559 | missing = append(missing, expected) |
| 1560 | } |
| 1561 | } |
| 1562 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1563 | t.Log("missing files", missing) |
| 1564 | failed = true |
| 1565 | } |
| 1566 | if failed { |
| 1567 | t.Fail() |
| 1568 | } |
| 1569 | } |
| 1570 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1571 | func TestVndkApexCurrent(t *testing.T) { |
| 1572 | ctx, _ := testApex(t, ` |
| 1573 | apex_vndk { |
| 1574 | name: "myapex", |
| 1575 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | apex_key { |
| 1579 | name: "myapex.key", |
| 1580 | public_key: "testkey.avbpubkey", |
| 1581 | private_key: "testkey.pem", |
| 1582 | } |
| 1583 | |
| 1584 | cc_library { |
| 1585 | name: "libvndk", |
| 1586 | srcs: ["mylib.cpp"], |
| 1587 | vendor_available: true, |
| 1588 | vndk: { |
| 1589 | enabled: true, |
| 1590 | }, |
| 1591 | system_shared_libs: [], |
| 1592 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1593 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | cc_library { |
| 1597 | name: "libvndksp", |
| 1598 | srcs: ["mylib.cpp"], |
| 1599 | vendor_available: true, |
| 1600 | vndk: { |
| 1601 | enabled: true, |
| 1602 | support_system_process: true, |
| 1603 | }, |
| 1604 | system_shared_libs: [], |
| 1605 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1606 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1607 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1608 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1609 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1610 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1611 | "lib/libvndk.so", |
| 1612 | "lib/libvndksp.so", |
| 1613 | "lib64/libvndk.so", |
| 1614 | "lib64/libvndksp.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1615 | "etc/llndk.libraries.VER.txt", |
| 1616 | "etc/vndkcore.libraries.VER.txt", |
| 1617 | "etc/vndksp.libraries.VER.txt", |
| 1618 | "etc/vndkprivate.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1619 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 1623 | ctx, _ := testApex(t, ` |
| 1624 | apex_vndk { |
| 1625 | name: "myapex", |
| 1626 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | apex_key { |
| 1630 | name: "myapex.key", |
| 1631 | public_key: "testkey.avbpubkey", |
| 1632 | private_key: "testkey.pem", |
| 1633 | } |
| 1634 | |
| 1635 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1636 | name: "libvndk", |
| 1637 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1638 | vendor_available: true, |
| 1639 | vndk: { |
| 1640 | enabled: true, |
| 1641 | }, |
| 1642 | system_shared_libs: [], |
| 1643 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1644 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1645 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1646 | |
| 1647 | cc_prebuilt_library_shared { |
| 1648 | name: "libvndk.arm", |
| 1649 | srcs: ["libvndk.arm.so"], |
| 1650 | vendor_available: true, |
| 1651 | vndk: { |
| 1652 | enabled: true, |
| 1653 | }, |
| 1654 | enabled: false, |
| 1655 | arch: { |
| 1656 | arm: { |
| 1657 | enabled: true, |
| 1658 | }, |
| 1659 | }, |
| 1660 | system_shared_libs: [], |
| 1661 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1662 | apex_available: [ "myapex" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1663 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1664 | `+vndkLibrariesTxtFiles("current"), |
| 1665 | withFiles(map[string][]byte{ |
| 1666 | "libvndk.so": nil, |
| 1667 | "libvndk.arm.so": nil, |
| 1668 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1669 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1670 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1671 | "lib/libvndk.so", |
| 1672 | "lib/libvndk.arm.so", |
| 1673 | "lib64/libvndk.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1674 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1675 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1676 | } |
| 1677 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1678 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 1679 | for _, v := range vers { |
| 1680 | if v == "current" { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 1681 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1682 | result += ` |
| 1683 | vndk_libraries_txt { |
| 1684 | name: "` + txt + `.libraries.txt", |
| 1685 | } |
| 1686 | ` |
| 1687 | } |
| 1688 | } else { |
| 1689 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
| 1690 | result += ` |
| 1691 | prebuilt_etc { |
| 1692 | name: "` + txt + `.libraries.` + v + `.txt", |
| 1693 | src: "dummy.txt", |
| 1694 | } |
| 1695 | ` |
| 1696 | } |
| 1697 | } |
| 1698 | } |
| 1699 | return |
| 1700 | } |
| 1701 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1702 | func TestVndkApexVersion(t *testing.T) { |
| 1703 | ctx, _ := testApex(t, ` |
| 1704 | apex_vndk { |
| 1705 | name: "myapex_v27", |
| 1706 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1707 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1708 | vndk_version: "27", |
| 1709 | } |
| 1710 | |
| 1711 | apex_key { |
| 1712 | name: "myapex.key", |
| 1713 | public_key: "testkey.avbpubkey", |
| 1714 | private_key: "testkey.pem", |
| 1715 | } |
| 1716 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1717 | vndk_prebuilt_shared { |
| 1718 | name: "libvndk27", |
| 1719 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1720 | vendor_available: true, |
| 1721 | vndk: { |
| 1722 | enabled: true, |
| 1723 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1724 | target_arch: "arm64", |
| 1725 | arch: { |
| 1726 | arm: { |
| 1727 | srcs: ["libvndk27_arm.so"], |
| 1728 | }, |
| 1729 | arm64: { |
| 1730 | srcs: ["libvndk27_arm64.so"], |
| 1731 | }, |
| 1732 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1733 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | vndk_prebuilt_shared { |
| 1737 | name: "libvndk27", |
| 1738 | version: "27", |
| 1739 | vendor_available: true, |
| 1740 | vndk: { |
| 1741 | enabled: true, |
| 1742 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1743 | target_arch: "x86_64", |
| 1744 | arch: { |
| 1745 | x86: { |
| 1746 | srcs: ["libvndk27_x86.so"], |
| 1747 | }, |
| 1748 | x86_64: { |
| 1749 | srcs: ["libvndk27_x86_64.so"], |
| 1750 | }, |
| 1751 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1752 | } |
| 1753 | `+vndkLibrariesTxtFiles("27"), |
| 1754 | withFiles(map[string][]byte{ |
| 1755 | "libvndk27_arm.so": nil, |
| 1756 | "libvndk27_arm64.so": nil, |
| 1757 | "libvndk27_x86.so": nil, |
| 1758 | "libvndk27_x86_64.so": nil, |
| 1759 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1760 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1761 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1762 | "lib/libvndk27_arm.so", |
| 1763 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1764 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1765 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { |
| 1769 | testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, ` |
| 1770 | apex_vndk { |
| 1771 | name: "myapex_v27", |
| 1772 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1773 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1774 | vndk_version: "27", |
| 1775 | } |
| 1776 | apex_vndk { |
| 1777 | name: "myapex_v27_other", |
| 1778 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1779 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1780 | vndk_version: "27", |
| 1781 | } |
| 1782 | |
| 1783 | apex_key { |
| 1784 | name: "myapex.key", |
| 1785 | public_key: "testkey.avbpubkey", |
| 1786 | private_key: "testkey.pem", |
| 1787 | } |
| 1788 | |
| 1789 | cc_library { |
| 1790 | name: "libvndk", |
| 1791 | srcs: ["mylib.cpp"], |
| 1792 | vendor_available: true, |
| 1793 | vndk: { |
| 1794 | enabled: true, |
| 1795 | }, |
| 1796 | system_shared_libs: [], |
| 1797 | stl: "none", |
| 1798 | } |
| 1799 | |
| 1800 | vndk_prebuilt_shared { |
| 1801 | name: "libvndk", |
| 1802 | version: "27", |
| 1803 | vendor_available: true, |
| 1804 | vndk: { |
| 1805 | enabled: true, |
| 1806 | }, |
| 1807 | srcs: ["libvndk.so"], |
| 1808 | } |
| 1809 | `, withFiles(map[string][]byte{ |
| 1810 | "libvndk.so": nil, |
| 1811 | })) |
| 1812 | } |
| 1813 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 1814 | func TestVndkApexNameRule(t *testing.T) { |
| 1815 | ctx, _ := testApex(t, ` |
| 1816 | apex_vndk { |
| 1817 | name: "myapex", |
| 1818 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1819 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 1820 | } |
| 1821 | apex_vndk { |
| 1822 | name: "myapex_v28", |
| 1823 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1824 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 1825 | vndk_version: "28", |
| 1826 | } |
| 1827 | apex_key { |
| 1828 | name: "myapex.key", |
| 1829 | public_key: "testkey.avbpubkey", |
| 1830 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1831 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 1832 | |
| 1833 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1834 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 1835 | actual := proptools.String(bundle.properties.Apex_name) |
| 1836 | if !reflect.DeepEqual(actual, expected) { |
| 1837 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 1838 | } |
| 1839 | } |
| 1840 | |
| 1841 | assertApexName("com.android.vndk.vVER", "myapex") |
| 1842 | assertApexName("com.android.vndk.v28", "myapex_v28") |
| 1843 | } |
| 1844 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1845 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 1846 | ctx, _ := testApex(t, ` |
| 1847 | apex_vndk { |
| 1848 | name: "myapex", |
| 1849 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1850 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | apex_key { |
| 1854 | name: "myapex.key", |
| 1855 | public_key: "testkey.avbpubkey", |
| 1856 | private_key: "testkey.pem", |
| 1857 | } |
| 1858 | |
| 1859 | cc_library { |
| 1860 | name: "libvndk", |
| 1861 | srcs: ["mylib.cpp"], |
| 1862 | vendor_available: true, |
| 1863 | native_bridge_supported: true, |
| 1864 | host_supported: true, |
| 1865 | vndk: { |
| 1866 | enabled: true, |
| 1867 | }, |
| 1868 | system_shared_libs: [], |
| 1869 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1870 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1871 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1872 | `+vndkLibrariesTxtFiles("current"), |
| 1873 | withTargets(map[android.OsType][]android.Target{ |
| 1874 | android.Android: []android.Target{ |
| 1875 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 1876 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 1877 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"}, |
| 1878 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"}, |
| 1879 | }, |
| 1880 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1881 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1882 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1883 | "lib/libvndk.so", |
| 1884 | "lib64/libvndk.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1885 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1886 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
| 1890 | testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
| 1891 | apex_vndk { |
| 1892 | name: "myapex", |
| 1893 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1894 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1895 | native_bridge_supported: true, |
| 1896 | } |
| 1897 | |
| 1898 | apex_key { |
| 1899 | name: "myapex.key", |
| 1900 | public_key: "testkey.avbpubkey", |
| 1901 | private_key: "testkey.pem", |
| 1902 | } |
| 1903 | |
| 1904 | cc_library { |
| 1905 | name: "libvndk", |
| 1906 | srcs: ["mylib.cpp"], |
| 1907 | vendor_available: true, |
| 1908 | native_bridge_supported: true, |
| 1909 | host_supported: true, |
| 1910 | vndk: { |
| 1911 | enabled: true, |
| 1912 | }, |
| 1913 | system_shared_libs: [], |
| 1914 | stl: "none", |
| 1915 | } |
| 1916 | `) |
| 1917 | } |
| 1918 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1919 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1920 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1921 | apex_vndk { |
| 1922 | name: "myapex_v27", |
| 1923 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1924 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1925 | vndk_version: "27", |
| 1926 | } |
| 1927 | |
| 1928 | apex_key { |
| 1929 | name: "myapex.key", |
| 1930 | public_key: "testkey.avbpubkey", |
| 1931 | private_key: "testkey.pem", |
| 1932 | } |
| 1933 | |
| 1934 | vndk_prebuilt_shared { |
| 1935 | name: "libvndk27", |
| 1936 | version: "27", |
| 1937 | target_arch: "arm", |
| 1938 | vendor_available: true, |
| 1939 | vndk: { |
| 1940 | enabled: true, |
| 1941 | }, |
| 1942 | arch: { |
| 1943 | arm: { |
| 1944 | srcs: ["libvndk27.so"], |
| 1945 | } |
| 1946 | }, |
| 1947 | } |
| 1948 | |
| 1949 | vndk_prebuilt_shared { |
| 1950 | name: "libvndk27", |
| 1951 | version: "27", |
| 1952 | target_arch: "arm", |
| 1953 | binder32bit: true, |
| 1954 | vendor_available: true, |
| 1955 | vndk: { |
| 1956 | enabled: true, |
| 1957 | }, |
| 1958 | arch: { |
| 1959 | arm: { |
| 1960 | srcs: ["libvndk27binder32.so"], |
| 1961 | } |
| 1962 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1963 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1964 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1965 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1966 | withFiles(map[string][]byte{ |
| 1967 | "libvndk27.so": nil, |
| 1968 | "libvndk27binder32.so": nil, |
| 1969 | }), |
| 1970 | withBinder32bit, |
| 1971 | withTargets(map[android.OsType][]android.Target{ |
| 1972 | android.Android: []android.Target{ |
| 1973 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 1974 | }, |
| 1975 | }), |
| 1976 | ) |
| 1977 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1978 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1979 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1980 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1981 | }) |
| 1982 | } |
| 1983 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1984 | func TestDependenciesInApexManifest(t *testing.T) { |
| 1985 | ctx, _ := testApex(t, ` |
| 1986 | apex { |
| 1987 | name: "myapex_nodep", |
| 1988 | key: "myapex.key", |
| 1989 | native_shared_libs: ["lib_nodep"], |
| 1990 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1991 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | apex { |
| 1995 | name: "myapex_dep", |
| 1996 | key: "myapex.key", |
| 1997 | native_shared_libs: ["lib_dep"], |
| 1998 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1999 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | apex { |
| 2003 | name: "myapex_provider", |
| 2004 | key: "myapex.key", |
| 2005 | native_shared_libs: ["libfoo"], |
| 2006 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2007 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | apex { |
| 2011 | name: "myapex_selfcontained", |
| 2012 | key: "myapex.key", |
| 2013 | native_shared_libs: ["lib_dep", "libfoo"], |
| 2014 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2015 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | apex_key { |
| 2019 | name: "myapex.key", |
| 2020 | public_key: "testkey.avbpubkey", |
| 2021 | private_key: "testkey.pem", |
| 2022 | } |
| 2023 | |
| 2024 | cc_library { |
| 2025 | name: "lib_nodep", |
| 2026 | srcs: ["mylib.cpp"], |
| 2027 | system_shared_libs: [], |
| 2028 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2029 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | cc_library { |
| 2033 | name: "lib_dep", |
| 2034 | srcs: ["mylib.cpp"], |
| 2035 | shared_libs: ["libfoo"], |
| 2036 | system_shared_libs: [], |
| 2037 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2038 | apex_available: [ |
| 2039 | "myapex_dep", |
| 2040 | "myapex_provider", |
| 2041 | "myapex_selfcontained", |
| 2042 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | cc_library { |
| 2046 | name: "libfoo", |
| 2047 | srcs: ["mytest.cpp"], |
| 2048 | stubs: { |
| 2049 | versions: ["1"], |
| 2050 | }, |
| 2051 | system_shared_libs: [], |
| 2052 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2053 | apex_available: [ |
| 2054 | "myapex_provider", |
| 2055 | "myapex_selfcontained", |
| 2056 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2057 | } |
| 2058 | `) |
| 2059 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2060 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2061 | var provideNativeLibs, requireNativeLibs []string |
| 2062 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2063 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2064 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2065 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2066 | ensureListEmpty(t, provideNativeLibs) |
| 2067 | ensureListEmpty(t, requireNativeLibs) |
| 2068 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2069 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2070 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2071 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2072 | ensureListEmpty(t, provideNativeLibs) |
| 2073 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 2074 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2075 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2076 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2077 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2078 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 2079 | ensureListEmpty(t, requireNativeLibs) |
| 2080 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2081 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2082 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2083 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2084 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 2085 | ensureListEmpty(t, requireNativeLibs) |
| 2086 | } |
| 2087 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2088 | func TestApexName(t *testing.T) { |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2089 | ctx, config := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2090 | apex { |
| 2091 | name: "myapex", |
| 2092 | key: "myapex.key", |
| 2093 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2094 | native_shared_libs: ["mylib"], |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | apex_key { |
| 2098 | name: "myapex.key", |
| 2099 | public_key: "testkey.avbpubkey", |
| 2100 | private_key: "testkey.pem", |
| 2101 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2102 | |
| 2103 | cc_library { |
| 2104 | name: "mylib", |
| 2105 | srcs: ["mylib.cpp"], |
| 2106 | system_shared_libs: [], |
| 2107 | stl: "none", |
| 2108 | apex_available: [ |
| 2109 | "//apex_available:platform", |
| 2110 | "myapex", |
| 2111 | ], |
| 2112 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2113 | `) |
| 2114 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2115 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2116 | apexManifestRule := module.Rule("apexManifestRule") |
| 2117 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 2118 | apexRule := module.Rule("apexRule") |
| 2119 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2120 | |
| 2121 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2122 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2123 | name := apexBundle.BaseModuleName() |
| 2124 | prefix := "TARGET_" |
| 2125 | var builder strings.Builder |
| 2126 | data.Custom(&builder, name, prefix, "", data) |
| 2127 | androidMk := builder.String() |
| 2128 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 2129 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2130 | } |
| 2131 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2132 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2133 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2134 | apex { |
| 2135 | name: "myapex", |
| 2136 | key: "myapex.key", |
| 2137 | native_shared_libs: ["mylib_common"], |
| 2138 | } |
| 2139 | |
| 2140 | apex_key { |
| 2141 | name: "myapex.key", |
| 2142 | public_key: "testkey.avbpubkey", |
| 2143 | private_key: "testkey.pem", |
| 2144 | } |
| 2145 | |
| 2146 | cc_library { |
| 2147 | name: "mylib_common", |
| 2148 | srcs: ["mylib.cpp"], |
| 2149 | system_shared_libs: [], |
| 2150 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2151 | apex_available: [ |
| 2152 | "//apex_available:platform", |
| 2153 | "myapex", |
| 2154 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2155 | } |
| 2156 | `) |
| 2157 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2158 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2159 | apexRule := module.Rule("apexRule") |
| 2160 | copyCmds := apexRule.Args["copy_commands"] |
| 2161 | |
| 2162 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 2163 | t.Log("Apex was a test apex!") |
| 2164 | t.Fail() |
| 2165 | } |
| 2166 | // Ensure that main rule creates an output |
| 2167 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2168 | |
| 2169 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2170 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2171 | |
| 2172 | // Ensure that both direct and indirect deps are copied into apex |
| 2173 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 2174 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2175 | // Ensure that the platform variant ends with _shared |
| 2176 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2177 | |
| 2178 | if !android.InAnyApex("mylib_common") { |
| 2179 | t.Log("Found mylib_common not in any apex!") |
| 2180 | t.Fail() |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | func TestTestApex(t *testing.T) { |
| 2185 | if android.InAnyApex("mylib_common_test") { |
| 2186 | 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!") |
| 2187 | } |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2188 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2189 | apex_test { |
| 2190 | name: "myapex", |
| 2191 | key: "myapex.key", |
| 2192 | native_shared_libs: ["mylib_common_test"], |
| 2193 | } |
| 2194 | |
| 2195 | apex_key { |
| 2196 | name: "myapex.key", |
| 2197 | public_key: "testkey.avbpubkey", |
| 2198 | private_key: "testkey.pem", |
| 2199 | } |
| 2200 | |
| 2201 | cc_library { |
| 2202 | name: "mylib_common_test", |
| 2203 | srcs: ["mylib.cpp"], |
| 2204 | system_shared_libs: [], |
| 2205 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2206 | // TODO: remove //apex_available:platform |
| 2207 | apex_available: [ |
| 2208 | "//apex_available:platform", |
| 2209 | "myapex", |
| 2210 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2211 | } |
| 2212 | `) |
| 2213 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2214 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2215 | apexRule := module.Rule("apexRule") |
| 2216 | copyCmds := apexRule.Args["copy_commands"] |
| 2217 | |
| 2218 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 2219 | t.Log("Apex was not a test apex!") |
| 2220 | t.Fail() |
| 2221 | } |
| 2222 | // Ensure that main rule creates an output |
| 2223 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2224 | |
| 2225 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2226 | 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] | 2227 | |
| 2228 | // Ensure that both direct and indirect deps are copied into apex |
| 2229 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 2230 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2231 | // Ensure that the platform variant ends with _shared |
| 2232 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2233 | } |
| 2234 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2235 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2236 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2237 | apex { |
| 2238 | name: "myapex", |
| 2239 | key: "myapex.key", |
| 2240 | multilib: { |
| 2241 | first: { |
| 2242 | native_shared_libs: ["mylib_common"], |
| 2243 | } |
| 2244 | }, |
| 2245 | target: { |
| 2246 | android: { |
| 2247 | multilib: { |
| 2248 | first: { |
| 2249 | native_shared_libs: ["mylib"], |
| 2250 | } |
| 2251 | } |
| 2252 | }, |
| 2253 | host: { |
| 2254 | multilib: { |
| 2255 | first: { |
| 2256 | native_shared_libs: ["mylib2"], |
| 2257 | } |
| 2258 | } |
| 2259 | } |
| 2260 | } |
| 2261 | } |
| 2262 | |
| 2263 | apex_key { |
| 2264 | name: "myapex.key", |
| 2265 | public_key: "testkey.avbpubkey", |
| 2266 | private_key: "testkey.pem", |
| 2267 | } |
| 2268 | |
| 2269 | cc_library { |
| 2270 | name: "mylib", |
| 2271 | srcs: ["mylib.cpp"], |
| 2272 | system_shared_libs: [], |
| 2273 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2274 | // TODO: remove //apex_available:platform |
| 2275 | apex_available: [ |
| 2276 | "//apex_available:platform", |
| 2277 | "myapex", |
| 2278 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | cc_library { |
| 2282 | name: "mylib_common", |
| 2283 | srcs: ["mylib.cpp"], |
| 2284 | system_shared_libs: [], |
| 2285 | stl: "none", |
| 2286 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2287 | // TODO: remove //apex_available:platform |
| 2288 | apex_available: [ |
| 2289 | "//apex_available:platform", |
| 2290 | "myapex", |
| 2291 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | cc_library { |
| 2295 | name: "mylib2", |
| 2296 | srcs: ["mylib.cpp"], |
| 2297 | system_shared_libs: [], |
| 2298 | stl: "none", |
| 2299 | compile_multilib: "first", |
| 2300 | } |
| 2301 | `) |
| 2302 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2303 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2304 | copyCmds := apexRule.Args["copy_commands"] |
| 2305 | |
| 2306 | // Ensure that main rule creates an output |
| 2307 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2308 | |
| 2309 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2310 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 2311 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
| 2312 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2313 | |
| 2314 | // Ensure that both direct and indirect deps are copied into apex |
| 2315 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 2316 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 2317 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 2318 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2319 | // Ensure that the platform variant ends with _shared |
| 2320 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 2321 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 2322 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2323 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2324 | |
| 2325 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2326 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2327 | apex { |
| 2328 | name: "myapex", |
| 2329 | key: "myapex.key", |
| 2330 | binaries: ["myscript"], |
| 2331 | } |
| 2332 | |
| 2333 | apex_key { |
| 2334 | name: "myapex.key", |
| 2335 | public_key: "testkey.avbpubkey", |
| 2336 | private_key: "testkey.pem", |
| 2337 | } |
| 2338 | |
| 2339 | sh_binary { |
| 2340 | name: "myscript", |
| 2341 | src: "mylib.cpp", |
| 2342 | filename: "myscript.sh", |
| 2343 | sub_dir: "script", |
| 2344 | } |
| 2345 | `) |
| 2346 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2347 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2348 | copyCmds := apexRule.Args["copy_commands"] |
| 2349 | |
| 2350 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 2351 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2352 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2353 | func TestApexInVariousPartition(t *testing.T) { |
| 2354 | testcases := []struct { |
| 2355 | propName, parition, flattenedPartition string |
| 2356 | }{ |
| 2357 | {"", "system", "system_ext"}, |
| 2358 | {"product_specific: true", "product", "product"}, |
| 2359 | {"soc_specific: true", "vendor", "vendor"}, |
| 2360 | {"proprietary: true", "vendor", "vendor"}, |
| 2361 | {"vendor: true", "vendor", "vendor"}, |
| 2362 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 2363 | } |
| 2364 | for _, tc := range testcases { |
| 2365 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 2366 | ctx, _ := testApex(t, ` |
| 2367 | apex { |
| 2368 | name: "myapex", |
| 2369 | key: "myapex.key", |
| 2370 | `+tc.propName+` |
| 2371 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2372 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2373 | apex_key { |
| 2374 | name: "myapex.key", |
| 2375 | public_key: "testkey.avbpubkey", |
| 2376 | private_key: "testkey.pem", |
| 2377 | } |
| 2378 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2379 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2380 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2381 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 2382 | actual := apex.installDir.String() |
| 2383 | if actual != expected { |
| 2384 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 2385 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2386 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2387 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 2388 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 2389 | actual = flattened.installDir.String() |
| 2390 | if actual != expected { |
| 2391 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 2392 | } |
| 2393 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2394 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2395 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2396 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2397 | func TestFileContexts(t *testing.T) { |
| 2398 | ctx, _ := testApex(t, ` |
| 2399 | apex { |
| 2400 | name: "myapex", |
| 2401 | key: "myapex.key", |
| 2402 | } |
| 2403 | |
| 2404 | apex_key { |
| 2405 | name: "myapex.key", |
| 2406 | public_key: "testkey.avbpubkey", |
| 2407 | private_key: "testkey.pem", |
| 2408 | } |
| 2409 | `) |
| 2410 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2411 | apexRule := module.Rule("apexRule") |
| 2412 | actual := apexRule.Args["file_contexts"] |
| 2413 | expected := "system/sepolicy/apex/myapex-file_contexts" |
| 2414 | if actual != expected { |
| 2415 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2416 | } |
| 2417 | |
| 2418 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
| 2419 | apex { |
| 2420 | name: "myapex", |
| 2421 | key: "myapex.key", |
| 2422 | file_contexts: "my_own_file_contexts", |
| 2423 | } |
| 2424 | |
| 2425 | apex_key { |
| 2426 | name: "myapex.key", |
| 2427 | public_key: "testkey.avbpubkey", |
| 2428 | private_key: "testkey.pem", |
| 2429 | } |
| 2430 | `, withFiles(map[string][]byte{ |
| 2431 | "my_own_file_contexts": nil, |
| 2432 | })) |
| 2433 | |
| 2434 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
| 2435 | apex { |
| 2436 | name: "myapex", |
| 2437 | key: "myapex.key", |
| 2438 | product_specific: true, |
| 2439 | file_contexts: "product_specific_file_contexts", |
| 2440 | } |
| 2441 | |
| 2442 | apex_key { |
| 2443 | name: "myapex.key", |
| 2444 | public_key: "testkey.avbpubkey", |
| 2445 | private_key: "testkey.pem", |
| 2446 | } |
| 2447 | `) |
| 2448 | |
| 2449 | ctx, _ = testApex(t, ` |
| 2450 | apex { |
| 2451 | name: "myapex", |
| 2452 | key: "myapex.key", |
| 2453 | product_specific: true, |
| 2454 | file_contexts: "product_specific_file_contexts", |
| 2455 | } |
| 2456 | |
| 2457 | apex_key { |
| 2458 | name: "myapex.key", |
| 2459 | public_key: "testkey.avbpubkey", |
| 2460 | private_key: "testkey.pem", |
| 2461 | } |
| 2462 | `, withFiles(map[string][]byte{ |
| 2463 | "product_specific_file_contexts": nil, |
| 2464 | })) |
| 2465 | module = ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2466 | apexRule = module.Rule("apexRule") |
| 2467 | actual = apexRule.Args["file_contexts"] |
| 2468 | expected = "product_specific_file_contexts" |
| 2469 | if actual != expected { |
| 2470 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2471 | } |
| 2472 | |
| 2473 | ctx, _ = testApex(t, ` |
| 2474 | apex { |
| 2475 | name: "myapex", |
| 2476 | key: "myapex.key", |
| 2477 | product_specific: true, |
| 2478 | file_contexts: ":my-file-contexts", |
| 2479 | } |
| 2480 | |
| 2481 | apex_key { |
| 2482 | name: "myapex.key", |
| 2483 | public_key: "testkey.avbpubkey", |
| 2484 | private_key: "testkey.pem", |
| 2485 | } |
| 2486 | |
| 2487 | filegroup { |
| 2488 | name: "my-file-contexts", |
| 2489 | srcs: ["product_specific_file_contexts"], |
| 2490 | } |
| 2491 | `, withFiles(map[string][]byte{ |
| 2492 | "product_specific_file_contexts": nil, |
| 2493 | })) |
| 2494 | module = ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2495 | apexRule = module.Rule("apexRule") |
| 2496 | actual = apexRule.Args["file_contexts"] |
| 2497 | expected = "product_specific_file_contexts" |
| 2498 | if actual != expected { |
| 2499 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2500 | } |
| 2501 | } |
| 2502 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2503 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2504 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2505 | apex_key { |
| 2506 | name: "myapex.key", |
| 2507 | public_key: ":my.avbpubkey", |
| 2508 | private_key: ":my.pem", |
| 2509 | product_specific: true, |
| 2510 | } |
| 2511 | |
| 2512 | filegroup { |
| 2513 | name: "my.avbpubkey", |
| 2514 | srcs: ["testkey2.avbpubkey"], |
| 2515 | } |
| 2516 | |
| 2517 | filegroup { |
| 2518 | name: "my.pem", |
| 2519 | srcs: ["testkey2.pem"], |
| 2520 | } |
| 2521 | `) |
| 2522 | |
| 2523 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 2524 | expected_pubkey := "testkey2.avbpubkey" |
| 2525 | actual_pubkey := apex_key.public_key_file.String() |
| 2526 | if actual_pubkey != expected_pubkey { |
| 2527 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 2528 | } |
| 2529 | expected_privkey := "testkey2.pem" |
| 2530 | actual_privkey := apex_key.private_key_file.String() |
| 2531 | if actual_privkey != expected_privkey { |
| 2532 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 2533 | } |
| 2534 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2535 | |
| 2536 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2537 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2538 | prebuilt_apex { |
| 2539 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 2540 | arch: { |
| 2541 | arm64: { |
| 2542 | src: "myapex-arm64.apex", |
| 2543 | }, |
| 2544 | arm: { |
| 2545 | src: "myapex-arm.apex", |
| 2546 | }, |
| 2547 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2548 | } |
| 2549 | `) |
| 2550 | |
| 2551 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 2552 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 2553 | expectedInput := "myapex-arm64.apex" |
| 2554 | if prebuilt.inputApex.String() != expectedInput { |
| 2555 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 2556 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2557 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 2558 | |
| 2559 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2560 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 2561 | prebuilt_apex { |
| 2562 | name: "myapex", |
| 2563 | src: "myapex-arm.apex", |
| 2564 | filename: "notmyapex.apex", |
| 2565 | } |
| 2566 | `) |
| 2567 | |
| 2568 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 2569 | |
| 2570 | expected := "notmyapex.apex" |
| 2571 | if p.installFilename != expected { |
| 2572 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 2573 | } |
| 2574 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 2575 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2576 | func TestPrebuiltOverrides(t *testing.T) { |
| 2577 | ctx, config := testApex(t, ` |
| 2578 | prebuilt_apex { |
| 2579 | name: "myapex.prebuilt", |
| 2580 | src: "myapex-arm.apex", |
| 2581 | overrides: [ |
| 2582 | "myapex", |
| 2583 | ], |
| 2584 | } |
| 2585 | `) |
| 2586 | |
| 2587 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 2588 | |
| 2589 | expected := []string{"myapex"} |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 2590 | actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2591 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 2592 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2596 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2597 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2598 | apex_test { |
| 2599 | name: "myapex", |
| 2600 | key: "myapex.key", |
| 2601 | tests: [ |
| 2602 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 2603 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2604 | ], |
| 2605 | } |
| 2606 | |
| 2607 | apex_key { |
| 2608 | name: "myapex.key", |
| 2609 | public_key: "testkey.avbpubkey", |
| 2610 | private_key: "testkey.pem", |
| 2611 | } |
| 2612 | |
| 2613 | cc_test { |
| 2614 | name: "mytest", |
| 2615 | gtest: false, |
| 2616 | srcs: ["mytest.cpp"], |
| 2617 | relative_install_path: "test", |
| 2618 | system_shared_libs: [], |
| 2619 | static_executable: true, |
| 2620 | stl: "none", |
| 2621 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 2622 | |
| 2623 | cc_test { |
| 2624 | name: "mytests", |
| 2625 | gtest: false, |
| 2626 | srcs: [ |
| 2627 | "mytest1.cpp", |
| 2628 | "mytest2.cpp", |
| 2629 | "mytest3.cpp", |
| 2630 | ], |
| 2631 | test_per_src: true, |
| 2632 | relative_install_path: "test", |
| 2633 | system_shared_libs: [], |
| 2634 | static_executable: true, |
| 2635 | stl: "none", |
| 2636 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2637 | `) |
| 2638 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2639 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2640 | copyCmds := apexRule.Args["copy_commands"] |
| 2641 | |
| 2642 | // Ensure that test dep is copied into apex. |
| 2643 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 2644 | |
| 2645 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 2646 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 2647 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 2648 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2649 | |
| 2650 | // Ensure the module is correctly translated. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2651 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2652 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2653 | name := apexBundle.BaseModuleName() |
| 2654 | prefix := "TARGET_" |
| 2655 | var builder strings.Builder |
| 2656 | data.Custom(&builder, name, prefix, "", data) |
| 2657 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2658 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 2659 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 2660 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 2661 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 2662 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2663 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2664 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 2665 | } |
| 2666 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 2667 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
| 2668 | ctx, config := testApex(t, ` |
| 2669 | apex { |
| 2670 | name: "myapex", |
| 2671 | key: "myapex.key", |
| 2672 | } |
| 2673 | apex_key { |
| 2674 | name: "myapex.key", |
| 2675 | public_key: "testkey.avbpubkey", |
| 2676 | private_key: "testkey.pem", |
| 2677 | } |
| 2678 | `, func(fs map[string][]byte, config android.Config) { |
| 2679 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 2680 | }) |
| 2681 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 2682 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 2683 | mk := android.AndroidMkDataForTest(t, config, "", ab) |
| 2684 | var builder strings.Builder |
| 2685 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 2686 | androidMk := builder.String() |
| 2687 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 2688 | } |
| 2689 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2690 | func TestApexUsesOtherApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2691 | ctx, _ := testApex(t, ` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2692 | apex { |
| 2693 | name: "myapex", |
| 2694 | key: "myapex.key", |
| 2695 | native_shared_libs: ["mylib"], |
| 2696 | uses: ["commonapex"], |
| 2697 | } |
| 2698 | |
| 2699 | apex { |
| 2700 | name: "commonapex", |
| 2701 | key: "myapex.key", |
| 2702 | native_shared_libs: ["libcommon"], |
| 2703 | provide_cpp_shared_libs: true, |
| 2704 | } |
| 2705 | |
| 2706 | apex_key { |
| 2707 | name: "myapex.key", |
| 2708 | public_key: "testkey.avbpubkey", |
| 2709 | private_key: "testkey.pem", |
| 2710 | } |
| 2711 | |
| 2712 | cc_library { |
| 2713 | name: "mylib", |
| 2714 | srcs: ["mylib.cpp"], |
| 2715 | shared_libs: ["libcommon"], |
| 2716 | system_shared_libs: [], |
| 2717 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2718 | apex_available: [ "myapex" ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | cc_library { |
| 2722 | name: "libcommon", |
| 2723 | srcs: ["mylib_common.cpp"], |
| 2724 | system_shared_libs: [], |
| 2725 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2726 | // TODO: remove //apex_available:platform |
| 2727 | apex_available: [ |
| 2728 | "//apex_available:platform", |
| 2729 | "commonapex", |
| 2730 | "myapex", |
| 2731 | ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2732 | } |
| 2733 | `) |
| 2734 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2735 | module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2736 | apexRule1 := module1.Rule("apexRule") |
| 2737 | copyCmds1 := apexRule1.Args["copy_commands"] |
| 2738 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2739 | module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2740 | apexRule2 := module2.Rule("apexRule") |
| 2741 | copyCmds2 := apexRule2.Args["copy_commands"] |
| 2742 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2743 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 2744 | ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2745 | ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so") |
| 2746 | ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so") |
| 2747 | ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so") |
| 2748 | } |
| 2749 | |
| 2750 | func TestApexUsesFailsIfNotProvided(t *testing.T) { |
| 2751 | testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, ` |
| 2752 | apex { |
| 2753 | name: "myapex", |
| 2754 | key: "myapex.key", |
| 2755 | uses: ["commonapex"], |
| 2756 | } |
| 2757 | |
| 2758 | apex { |
| 2759 | name: "commonapex", |
| 2760 | key: "myapex.key", |
| 2761 | } |
| 2762 | |
| 2763 | apex_key { |
| 2764 | name: "myapex.key", |
| 2765 | public_key: "testkey.avbpubkey", |
| 2766 | private_key: "testkey.pem", |
| 2767 | } |
| 2768 | `) |
| 2769 | testApexError(t, `uses: "commonapex" is not a provider`, ` |
| 2770 | apex { |
| 2771 | name: "myapex", |
| 2772 | key: "myapex.key", |
| 2773 | uses: ["commonapex"], |
| 2774 | } |
| 2775 | |
| 2776 | cc_library { |
| 2777 | name: "commonapex", |
| 2778 | system_shared_libs: [], |
| 2779 | stl: "none", |
| 2780 | } |
| 2781 | |
| 2782 | apex_key { |
| 2783 | name: "myapex.key", |
| 2784 | public_key: "testkey.avbpubkey", |
| 2785 | private_key: "testkey.pem", |
| 2786 | } |
| 2787 | `) |
| 2788 | } |
| 2789 | |
| 2790 | func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) { |
| 2791 | testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, ` |
| 2792 | apex { |
| 2793 | name: "myapex", |
| 2794 | key: "myapex.key", |
| 2795 | use_vendor: true, |
| 2796 | uses: ["commonapex"], |
| 2797 | } |
| 2798 | |
| 2799 | apex { |
| 2800 | name: "commonapex", |
| 2801 | key: "myapex.key", |
| 2802 | provide_cpp_shared_libs: true, |
| 2803 | } |
| 2804 | |
| 2805 | apex_key { |
| 2806 | name: "myapex.key", |
| 2807 | public_key: "testkey.avbpubkey", |
| 2808 | private_key: "testkey.pem", |
| 2809 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2810 | `, func(fs map[string][]byte, config android.Config) { |
| 2811 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 2812 | }) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2813 | } |
| 2814 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 2815 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 2816 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 2817 | apex { |
| 2818 | name: "myapex", |
| 2819 | key: "myapex.key", |
| 2820 | native_shared_libs: ["libfoo"], |
| 2821 | } |
| 2822 | |
| 2823 | apex_key { |
| 2824 | name: "myapex.key", |
| 2825 | public_key: "testkey.avbpubkey", |
| 2826 | private_key: "testkey.pem", |
| 2827 | } |
| 2828 | |
| 2829 | cc_library { |
| 2830 | name: "libfoo", |
| 2831 | stl: "none", |
| 2832 | system_shared_libs: [], |
| 2833 | enabled: false, |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 2834 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 2835 | } |
| 2836 | `) |
| 2837 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 2838 | apex { |
| 2839 | name: "myapex", |
| 2840 | key: "myapex.key", |
| 2841 | java_libs: ["myjar"], |
| 2842 | } |
| 2843 | |
| 2844 | apex_key { |
| 2845 | name: "myapex.key", |
| 2846 | public_key: "testkey.avbpubkey", |
| 2847 | private_key: "testkey.pem", |
| 2848 | } |
| 2849 | |
| 2850 | java_library { |
| 2851 | name: "myjar", |
| 2852 | srcs: ["foo/bar/MyClass.java"], |
| 2853 | sdk_version: "none", |
| 2854 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 2855 | enabled: false, |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 2856 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 2857 | } |
| 2858 | `) |
| 2859 | } |
| 2860 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2861 | func TestApexWithApps(t *testing.T) { |
| 2862 | ctx, _ := testApex(t, ` |
| 2863 | apex { |
| 2864 | name: "myapex", |
| 2865 | key: "myapex.key", |
| 2866 | apps: [ |
| 2867 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 2868 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2869 | ], |
| 2870 | } |
| 2871 | |
| 2872 | apex_key { |
| 2873 | name: "myapex.key", |
| 2874 | public_key: "testkey.avbpubkey", |
| 2875 | private_key: "testkey.pem", |
| 2876 | } |
| 2877 | |
| 2878 | android_app { |
| 2879 | name: "AppFoo", |
| 2880 | srcs: ["foo/bar/MyClass.java"], |
| 2881 | sdk_version: "none", |
| 2882 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 2883 | jni_libs: ["libjni"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2884 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2885 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 2886 | |
| 2887 | android_app { |
| 2888 | name: "AppFooPriv", |
| 2889 | srcs: ["foo/bar/MyClass.java"], |
| 2890 | sdk_version: "none", |
| 2891 | system_modules: "none", |
| 2892 | privileged: true, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2893 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 2894 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 2895 | |
| 2896 | cc_library_shared { |
| 2897 | name: "libjni", |
| 2898 | srcs: ["mylib.cpp"], |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 2899 | shared_libs: ["libfoo"], |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 2900 | stl: "none", |
| 2901 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2902 | apex_available: [ "myapex" ], |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 2903 | sdk_version: "current", |
| 2904 | } |
| 2905 | |
| 2906 | cc_library_shared { |
| 2907 | name: "libfoo", |
| 2908 | stl: "none", |
| 2909 | system_shared_libs: [], |
| 2910 | apex_available: [ "myapex" ], |
| 2911 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 2912 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2913 | `) |
| 2914 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2915 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2916 | apexRule := module.Rule("apexRule") |
| 2917 | copyCmds := apexRule.Args["copy_commands"] |
| 2918 | |
| 2919 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 2920 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 2921 | |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 2922 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs") |
| 2923 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 2924 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 2925 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 2926 | } |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 2927 | // JNI libraries including transitive deps are |
| 2928 | for _, jni := range []string{"libjni", "libfoo"} { |
| 2929 | jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile() |
| 2930 | // ... embedded inside APK (jnilibs.zip) |
| 2931 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 2932 | // ... and not directly inside the APEX |
| 2933 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 2934 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 2935 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2936 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 2937 | func TestApexWithAppImports(t *testing.T) { |
| 2938 | ctx, _ := testApex(t, ` |
| 2939 | apex { |
| 2940 | name: "myapex", |
| 2941 | key: "myapex.key", |
| 2942 | apps: [ |
| 2943 | "AppFooPrebuilt", |
| 2944 | "AppFooPrivPrebuilt", |
| 2945 | ], |
| 2946 | } |
| 2947 | |
| 2948 | apex_key { |
| 2949 | name: "myapex.key", |
| 2950 | public_key: "testkey.avbpubkey", |
| 2951 | private_key: "testkey.pem", |
| 2952 | } |
| 2953 | |
| 2954 | android_app_import { |
| 2955 | name: "AppFooPrebuilt", |
| 2956 | apk: "PrebuiltAppFoo.apk", |
| 2957 | presigned: true, |
| 2958 | dex_preopt: { |
| 2959 | enabled: false, |
| 2960 | }, |
| 2961 | } |
| 2962 | |
| 2963 | android_app_import { |
| 2964 | name: "AppFooPrivPrebuilt", |
| 2965 | apk: "PrebuiltAppFooPriv.apk", |
| 2966 | privileged: true, |
| 2967 | presigned: true, |
| 2968 | dex_preopt: { |
| 2969 | enabled: false, |
| 2970 | }, |
| 2971 | } |
| 2972 | `) |
| 2973 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2974 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 2975 | apexRule := module.Rule("apexRule") |
| 2976 | copyCmds := apexRule.Args["copy_commands"] |
| 2977 | |
| 2978 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
| 2979 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 2980 | } |
| 2981 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 2982 | func TestApexWithTestHelperApp(t *testing.T) { |
| 2983 | ctx, _ := testApex(t, ` |
| 2984 | apex { |
| 2985 | name: "myapex", |
| 2986 | key: "myapex.key", |
| 2987 | apps: [ |
| 2988 | "TesterHelpAppFoo", |
| 2989 | ], |
| 2990 | } |
| 2991 | |
| 2992 | apex_key { |
| 2993 | name: "myapex.key", |
| 2994 | public_key: "testkey.avbpubkey", |
| 2995 | private_key: "testkey.pem", |
| 2996 | } |
| 2997 | |
| 2998 | android_test_helper_app { |
| 2999 | name: "TesterHelpAppFoo", |
| 3000 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3001 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | `) |
| 3005 | |
| 3006 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3007 | apexRule := module.Rule("apexRule") |
| 3008 | copyCmds := apexRule.Args["copy_commands"] |
| 3009 | |
| 3010 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 3011 | } |
| 3012 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 3013 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 3014 | // libfoo's apex_available comes from cc_defaults |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3015 | testApexError(t, `requires "libfoo" that is not available for the APEX`, ` |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 3016 | apex { |
| 3017 | name: "myapex", |
| 3018 | key: "myapex.key", |
| 3019 | native_shared_libs: ["libfoo"], |
| 3020 | } |
| 3021 | |
| 3022 | apex_key { |
| 3023 | name: "myapex.key", |
| 3024 | public_key: "testkey.avbpubkey", |
| 3025 | private_key: "testkey.pem", |
| 3026 | } |
| 3027 | |
| 3028 | apex { |
| 3029 | name: "otherapex", |
| 3030 | key: "myapex.key", |
| 3031 | native_shared_libs: ["libfoo"], |
| 3032 | } |
| 3033 | |
| 3034 | cc_defaults { |
| 3035 | name: "libfoo-defaults", |
| 3036 | apex_available: ["otherapex"], |
| 3037 | } |
| 3038 | |
| 3039 | cc_library { |
| 3040 | name: "libfoo", |
| 3041 | defaults: ["libfoo-defaults"], |
| 3042 | stl: "none", |
| 3043 | system_shared_libs: [], |
| 3044 | }`) |
| 3045 | } |
| 3046 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3047 | func TestApexAvailable(t *testing.T) { |
| 3048 | // libfoo is not available to myapex, but only to otherapex |
| 3049 | testApexError(t, "requires \"libfoo\" that is not available for the APEX", ` |
| 3050 | apex { |
| 3051 | name: "myapex", |
| 3052 | key: "myapex.key", |
| 3053 | native_shared_libs: ["libfoo"], |
| 3054 | } |
| 3055 | |
| 3056 | apex_key { |
| 3057 | name: "myapex.key", |
| 3058 | public_key: "testkey.avbpubkey", |
| 3059 | private_key: "testkey.pem", |
| 3060 | } |
| 3061 | |
| 3062 | apex { |
| 3063 | name: "otherapex", |
| 3064 | key: "otherapex.key", |
| 3065 | native_shared_libs: ["libfoo"], |
| 3066 | } |
| 3067 | |
| 3068 | apex_key { |
| 3069 | name: "otherapex.key", |
| 3070 | public_key: "testkey.avbpubkey", |
| 3071 | private_key: "testkey.pem", |
| 3072 | } |
| 3073 | |
| 3074 | cc_library { |
| 3075 | name: "libfoo", |
| 3076 | stl: "none", |
| 3077 | system_shared_libs: [], |
| 3078 | apex_available: ["otherapex"], |
| 3079 | }`) |
| 3080 | |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3081 | // libbbaz is an indirect dep |
| 3082 | testApexError(t, "requires \"libbaz\" that is not available for the APEX", ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3083 | apex { |
| 3084 | name: "myapex", |
| 3085 | key: "myapex.key", |
| 3086 | native_shared_libs: ["libfoo"], |
| 3087 | } |
| 3088 | |
| 3089 | apex_key { |
| 3090 | name: "myapex.key", |
| 3091 | public_key: "testkey.avbpubkey", |
| 3092 | private_key: "testkey.pem", |
| 3093 | } |
| 3094 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3095 | cc_library { |
| 3096 | name: "libfoo", |
| 3097 | stl: "none", |
| 3098 | shared_libs: ["libbar"], |
| 3099 | system_shared_libs: [], |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3100 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | cc_library { |
| 3104 | name: "libbar", |
| 3105 | stl: "none", |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3106 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3107 | system_shared_libs: [], |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3108 | apex_available: ["myapex"], |
| 3109 | } |
| 3110 | |
| 3111 | cc_library { |
| 3112 | name: "libbaz", |
| 3113 | stl: "none", |
| 3114 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3115 | }`) |
| 3116 | |
| 3117 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 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 | apex_available: ["otherapex"], |
| 3135 | }`) |
| 3136 | |
| 3137 | ctx, _ := testApex(t, ` |
| 3138 | apex { |
| 3139 | name: "myapex", |
| 3140 | key: "myapex.key", |
| 3141 | native_shared_libs: ["libfoo", "libbar"], |
| 3142 | } |
| 3143 | |
| 3144 | apex_key { |
| 3145 | name: "myapex.key", |
| 3146 | public_key: "testkey.avbpubkey", |
| 3147 | private_key: "testkey.pem", |
| 3148 | } |
| 3149 | |
| 3150 | cc_library { |
| 3151 | name: "libfoo", |
| 3152 | stl: "none", |
| 3153 | system_shared_libs: [], |
Jiyong Park | 9f14b9b | 2020-03-01 17:29:06 +0900 | [diff] [blame^] | 3154 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3155 | apex_available: ["myapex"], |
| 3156 | } |
| 3157 | |
| 3158 | cc_library { |
| 3159 | name: "libbar", |
| 3160 | stl: "none", |
| 3161 | system_shared_libs: [], |
| 3162 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 9f14b9b | 2020-03-01 17:29:06 +0900 | [diff] [blame^] | 3163 | } |
| 3164 | |
| 3165 | cc_library { |
| 3166 | name: "libbaz", |
| 3167 | stl: "none", |
| 3168 | system_shared_libs: [], |
| 3169 | stubs: { |
| 3170 | versions: ["10", "20", "30"], |
| 3171 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3172 | }`) |
| 3173 | |
| 3174 | // 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] | 3175 | // TODO(jiyong) the checks for the platform variant are removed because we now create |
| 3176 | // the platform variant regardless of the apex_availability. Instead, we will make sure that |
| 3177 | // the platform variants are not used from other platform modules. When that is done, |
| 3178 | // these checks will be replaced by expecting a specific error message that will be |
| 3179 | // emitted when the platform variant is used. |
| 3180 | // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex") |
| 3181 | // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared") |
| 3182 | // ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex") |
| 3183 | // ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared") |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3184 | |
| 3185 | ctx, _ = testApex(t, ` |
| 3186 | apex { |
| 3187 | name: "myapex", |
| 3188 | key: "myapex.key", |
| 3189 | } |
| 3190 | |
| 3191 | apex_key { |
| 3192 | name: "myapex.key", |
| 3193 | public_key: "testkey.avbpubkey", |
| 3194 | private_key: "testkey.pem", |
| 3195 | } |
| 3196 | |
| 3197 | cc_library { |
| 3198 | name: "libfoo", |
| 3199 | stl: "none", |
| 3200 | system_shared_libs: [], |
| 3201 | apex_available: ["//apex_available:platform"], |
| 3202 | }`) |
| 3203 | |
| 3204 | // check that libfoo is created only for the platform |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3205 | ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex") |
| 3206 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared") |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 3207 | |
| 3208 | ctx, _ = testApex(t, ` |
| 3209 | apex { |
| 3210 | name: "myapex", |
| 3211 | key: "myapex.key", |
| 3212 | native_shared_libs: ["libfoo"], |
| 3213 | } |
| 3214 | |
| 3215 | apex_key { |
| 3216 | name: "myapex.key", |
| 3217 | public_key: "testkey.avbpubkey", |
| 3218 | private_key: "testkey.pem", |
| 3219 | } |
| 3220 | |
| 3221 | cc_library { |
| 3222 | name: "libfoo", |
| 3223 | stl: "none", |
| 3224 | system_shared_libs: [], |
| 3225 | apex_available: ["myapex"], |
| 3226 | static: { |
| 3227 | apex_available: ["//apex_available:platform"], |
| 3228 | }, |
| 3229 | }`) |
| 3230 | |
| 3231 | // shared variant of libfoo is only available to myapex |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3232 | // TODO(jiyong) the checks for the platform variant are removed because we now create |
| 3233 | // the platform variant regardless of the apex_availability. Instead, we will make sure that |
| 3234 | // the platform variants are not used from other platform modules. When that is done, |
| 3235 | // these checks will be replaced by expecting a specific error message that will be |
| 3236 | // emitted when the platform variant is used. |
| 3237 | // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex") |
| 3238 | // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared") |
| 3239 | // // but the static variant is available to both myapex and the platform |
| 3240 | // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex") |
| 3241 | // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static") |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3242 | } |
| 3243 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3244 | func TestOverrideApex(t *testing.T) { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3245 | ctx, config := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3246 | apex { |
| 3247 | name: "myapex", |
| 3248 | key: "myapex.key", |
| 3249 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3250 | overrides: ["oldapex"], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | override_apex { |
| 3254 | name: "override_myapex", |
| 3255 | base: "myapex", |
| 3256 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3257 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 3258 | logging_parent: "com.foo.bar", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | apex_key { |
| 3262 | name: "myapex.key", |
| 3263 | public_key: "testkey.avbpubkey", |
| 3264 | private_key: "testkey.pem", |
| 3265 | } |
| 3266 | |
| 3267 | android_app { |
| 3268 | name: "app", |
| 3269 | srcs: ["foo/bar/MyClass.java"], |
| 3270 | package_name: "foo", |
| 3271 | sdk_version: "none", |
| 3272 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3273 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | override_android_app { |
| 3277 | name: "override_app", |
| 3278 | base: "app", |
| 3279 | package_name: "bar", |
| 3280 | } |
Jiyong Park | a519c54 | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3281 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3282 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 3283 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 3284 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 3285 | if originalVariant.GetOverriddenBy() != "" { |
| 3286 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 3287 | } |
| 3288 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 3289 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 3290 | } |
| 3291 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3292 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 3293 | apexRule := module.Rule("apexRule") |
| 3294 | copyCmds := apexRule.Args["copy_commands"] |
| 3295 | |
| 3296 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
| 3297 | ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3298 | |
| 3299 | apexBundle := module.Module().(*apexBundle) |
| 3300 | name := apexBundle.Name() |
| 3301 | if name != "override_myapex" { |
| 3302 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 3303 | } |
| 3304 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 3305 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 3306 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 3307 | } |
| 3308 | |
Jiyong Park | a519c54 | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3309 | optFlags := apexRule.Args["opt_flags"] |
| 3310 | ensureContains(t, optFlags, "--override_apk_package_name com.android.myapex") |
| 3311 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3312 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3313 | var builder strings.Builder |
| 3314 | data.Custom(&builder, name, "TARGET_", "", data) |
| 3315 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 3316 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3317 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 3318 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3319 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3320 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 3321 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3322 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 3323 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3324 | } |
| 3325 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3326 | func TestLegacyAndroid10Support(t *testing.T) { |
| 3327 | ctx, _ := testApex(t, ` |
| 3328 | apex { |
| 3329 | name: "myapex", |
| 3330 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3331 | native_shared_libs: ["mylib"], |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3332 | legacy_android10_support: true, |
| 3333 | } |
| 3334 | |
| 3335 | apex_key { |
| 3336 | name: "myapex.key", |
| 3337 | public_key: "testkey.avbpubkey", |
| 3338 | private_key: "testkey.pem", |
| 3339 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3340 | |
| 3341 | cc_library { |
| 3342 | name: "mylib", |
| 3343 | srcs: ["mylib.cpp"], |
| 3344 | stl: "libc++", |
| 3345 | system_shared_libs: [], |
| 3346 | apex_available: [ "myapex" ], |
| 3347 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3348 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3349 | |
| 3350 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3351 | args := module.Rule("apexRule").Args |
| 3352 | 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] | 3353 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3354 | |
| 3355 | // The copies of the libraries in the apex should have one more dependency than |
| 3356 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 3357 | // the dependency names directly here but for some reason the names are blank in |
| 3358 | // this test. |
| 3359 | for _, lib := range []string{"libc++", "mylib"} { |
| 3360 | apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits |
| 3361 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 3362 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 3363 | t.Errorf("%q missing unwinder dep", lib) |
| 3364 | } |
| 3365 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3366 | } |
| 3367 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 3368 | func TestJavaSDKLibrary(t *testing.T) { |
| 3369 | ctx, _ := testApex(t, ` |
| 3370 | apex { |
| 3371 | name: "myapex", |
| 3372 | key: "myapex.key", |
| 3373 | java_libs: ["foo"], |
| 3374 | } |
| 3375 | |
| 3376 | apex_key { |
| 3377 | name: "myapex.key", |
| 3378 | public_key: "testkey.avbpubkey", |
| 3379 | private_key: "testkey.pem", |
| 3380 | } |
| 3381 | |
| 3382 | java_sdk_library { |
| 3383 | name: "foo", |
| 3384 | srcs: ["a.java"], |
| 3385 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3386 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 3387 | } |
| 3388 | `, withFiles(map[string][]byte{ |
| 3389 | "api/current.txt": nil, |
| 3390 | "api/removed.txt": nil, |
| 3391 | "api/system-current.txt": nil, |
| 3392 | "api/system-removed.txt": nil, |
| 3393 | "api/test-current.txt": nil, |
| 3394 | "api/test-removed.txt": nil, |
| 3395 | })) |
| 3396 | |
| 3397 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3398 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 3399 | "javalib/foo.jar", |
| 3400 | "etc/permissions/foo.xml", |
| 3401 | }) |
| 3402 | // 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] | 3403 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 3404 | 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] | 3405 | } |
| 3406 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 3407 | func TestCompatConfig(t *testing.T) { |
| 3408 | ctx, _ := testApex(t, ` |
| 3409 | apex { |
| 3410 | name: "myapex", |
| 3411 | key: "myapex.key", |
| 3412 | prebuilts: ["myjar-platform-compat-config"], |
| 3413 | java_libs: ["myjar"], |
| 3414 | } |
| 3415 | |
| 3416 | apex_key { |
| 3417 | name: "myapex.key", |
| 3418 | public_key: "testkey.avbpubkey", |
| 3419 | private_key: "testkey.pem", |
| 3420 | } |
| 3421 | |
| 3422 | platform_compat_config { |
| 3423 | name: "myjar-platform-compat-config", |
| 3424 | src: ":myjar", |
| 3425 | } |
| 3426 | |
| 3427 | java_library { |
| 3428 | name: "myjar", |
| 3429 | srcs: ["foo/bar/MyClass.java"], |
| 3430 | sdk_version: "none", |
| 3431 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 3432 | apex_available: [ "myapex" ], |
| 3433 | } |
| 3434 | `) |
| 3435 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 3436 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 3437 | "javalib/myjar.jar", |
| 3438 | }) |
| 3439 | } |
| 3440 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 3441 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 3442 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 3443 | apex { |
| 3444 | name: "myapex", |
| 3445 | key: "myapex.key", |
| 3446 | java_libs: ["myjar"], |
| 3447 | } |
| 3448 | |
| 3449 | apex_key { |
| 3450 | name: "myapex.key", |
| 3451 | public_key: "testkey.avbpubkey", |
| 3452 | private_key: "testkey.pem", |
| 3453 | } |
| 3454 | |
| 3455 | java_library { |
| 3456 | name: "myjar", |
| 3457 | srcs: ["foo/bar/MyClass.java"], |
| 3458 | sdk_version: "none", |
| 3459 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 3460 | compile_dex: false, |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3461 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 3462 | } |
| 3463 | `) |
| 3464 | } |
| 3465 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 3466 | func TestCarryRequiredModuleNames(t *testing.T) { |
| 3467 | ctx, config := testApex(t, ` |
| 3468 | apex { |
| 3469 | name: "myapex", |
| 3470 | key: "myapex.key", |
| 3471 | native_shared_libs: ["mylib"], |
| 3472 | } |
| 3473 | |
| 3474 | apex_key { |
| 3475 | name: "myapex.key", |
| 3476 | public_key: "testkey.avbpubkey", |
| 3477 | private_key: "testkey.pem", |
| 3478 | } |
| 3479 | |
| 3480 | cc_library { |
| 3481 | name: "mylib", |
| 3482 | srcs: ["mylib.cpp"], |
| 3483 | system_shared_libs: [], |
| 3484 | stl: "none", |
| 3485 | required: ["a", "b"], |
| 3486 | host_required: ["c", "d"], |
| 3487 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3488 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 3489 | } |
| 3490 | `) |
| 3491 | |
| 3492 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3493 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3494 | name := apexBundle.BaseModuleName() |
| 3495 | prefix := "TARGET_" |
| 3496 | var builder strings.Builder |
| 3497 | data.Custom(&builder, name, prefix, "", data) |
| 3498 | androidMk := builder.String() |
| 3499 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 3500 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 3501 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 3502 | } |
| 3503 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3504 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 3505 | bp := ` |
| 3506 | apex { |
| 3507 | name: "myapex", |
| 3508 | key: "myapex.key", |
| 3509 | native_shared_libs: ["mylib"], |
| 3510 | java_libs: ["myjar"], |
| 3511 | } |
| 3512 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3513 | apex { |
| 3514 | name: "myapex.updatable", |
| 3515 | key: "myapex.key", |
| 3516 | native_shared_libs: ["mylib"], |
| 3517 | java_libs: ["myjar"], |
| 3518 | updatable: true, |
| 3519 | } |
| 3520 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3521 | apex_key { |
| 3522 | name: "myapex.key", |
| 3523 | public_key: "testkey.avbpubkey", |
| 3524 | private_key: "testkey.pem", |
| 3525 | } |
| 3526 | |
| 3527 | cc_library { |
| 3528 | name: "mylib", |
| 3529 | srcs: ["mylib.cpp"], |
| 3530 | shared_libs: ["myotherlib"], |
| 3531 | system_shared_libs: [], |
| 3532 | stl: "none", |
| 3533 | apex_available: [ |
| 3534 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3535 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3536 | "//apex_available:platform", |
| 3537 | ], |
| 3538 | } |
| 3539 | |
| 3540 | cc_library { |
| 3541 | name: "myotherlib", |
| 3542 | srcs: ["mylib.cpp"], |
| 3543 | system_shared_libs: [], |
| 3544 | stl: "none", |
| 3545 | apex_available: [ |
| 3546 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3547 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3548 | "//apex_available:platform", |
| 3549 | ], |
| 3550 | } |
| 3551 | |
| 3552 | java_library { |
| 3553 | name: "myjar", |
| 3554 | srcs: ["foo/bar/MyClass.java"], |
| 3555 | sdk_version: "none", |
| 3556 | system_modules: "none", |
| 3557 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3558 | apex_available: [ |
| 3559 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3560 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3561 | "//apex_available:platform", |
| 3562 | ], |
| 3563 | } |
| 3564 | |
| 3565 | java_library { |
| 3566 | name: "myotherjar", |
| 3567 | srcs: ["foo/bar/MyClass.java"], |
| 3568 | sdk_version: "none", |
| 3569 | system_modules: "none", |
| 3570 | apex_available: [ |
| 3571 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3572 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3573 | "//apex_available:platform", |
| 3574 | ], |
| 3575 | } |
| 3576 | ` |
| 3577 | |
| 3578 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 3579 | for _, f := range files { |
| 3580 | if f.path == file { |
| 3581 | if f.isLink { |
| 3582 | t.Errorf("%q is not a real file", file) |
| 3583 | } |
| 3584 | return |
| 3585 | } |
| 3586 | } |
| 3587 | t.Errorf("%q is not found", file) |
| 3588 | } |
| 3589 | |
| 3590 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 3591 | for _, f := range files { |
| 3592 | if f.path == file { |
| 3593 | if !f.isLink { |
| 3594 | t.Errorf("%q is not a symlink", file) |
| 3595 | } |
| 3596 | return |
| 3597 | } |
| 3598 | } |
| 3599 | t.Errorf("%q is not found", file) |
| 3600 | } |
| 3601 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3602 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 3603 | // is updatable or not |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3604 | ctx, _ := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3605 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3606 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 3607 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 3608 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 3609 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3610 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 3611 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 3612 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 3613 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 3614 | |
| 3615 | // 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] | 3616 | ctx, _ = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3617 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3618 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 3619 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 3620 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3621 | |
| 3622 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 3623 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 3624 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 3625 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3626 | } |
| 3627 | |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 3628 | func TestAppBundle(t *testing.T) { |
| 3629 | ctx, _ := testApex(t, ` |
| 3630 | apex { |
| 3631 | name: "myapex", |
| 3632 | key: "myapex.key", |
| 3633 | apps: ["AppFoo"], |
| 3634 | } |
| 3635 | |
| 3636 | apex_key { |
| 3637 | name: "myapex.key", |
| 3638 | public_key: "testkey.avbpubkey", |
| 3639 | private_key: "testkey.pem", |
| 3640 | } |
| 3641 | |
| 3642 | android_app { |
| 3643 | name: "AppFoo", |
| 3644 | srcs: ["foo/bar/MyClass.java"], |
| 3645 | sdk_version: "none", |
| 3646 | system_modules: "none", |
| 3647 | apex_available: [ "myapex" ], |
| 3648 | } |
Jiyong Park | af8998c | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 3649 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 3650 | |
| 3651 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config") |
| 3652 | content := bundleConfigRule.Args["content"] |
| 3653 | |
| 3654 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | af8998c | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 3655 | 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] | 3656 | } |
| 3657 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 3658 | func TestMain(m *testing.M) { |
| 3659 | run := func() int { |
| 3660 | setUp() |
| 3661 | defer tearDown() |
| 3662 | |
| 3663 | return m.Run() |
| 3664 | } |
| 3665 | |
| 3666 | os.Exit(run()) |
| 3667 | } |