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