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