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