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