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" |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 30 | "android/soong/dexpreopt" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 31 | "android/soong/java" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 32 | ) |
| 33 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 34 | var buildDir string |
| 35 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 36 | // names returns name list from white space separated string |
| 37 | func names(s string) (ns []string) { |
| 38 | for _, n := range strings.Split(s, " ") { |
| 39 | if len(n) > 0 { |
| 40 | ns = append(ns, n) |
| 41 | } |
| 42 | } |
| 43 | return |
| 44 | } |
| 45 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 46 | func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) { |
| 47 | t.Helper() |
| 48 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 49 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 50 | if len(errs) > 0 { |
| 51 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 52 | return |
| 53 | } |
| 54 | _, errs = ctx.PrepareBuildActions(config) |
| 55 | if len(errs) > 0 { |
| 56 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 61 | } |
| 62 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 63 | func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
| 64 | t.Helper() |
| 65 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 66 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 67 | android.FailIfErrored(t, errs) |
| 68 | _, errs = ctx.PrepareBuildActions(config) |
| 69 | android.FailIfErrored(t, errs) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 70 | return ctx, config |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 71 | } |
| 72 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 73 | type testCustomizer func(fs map[string][]byte, config android.Config) |
| 74 | |
| 75 | func withFiles(files map[string][]byte) testCustomizer { |
| 76 | return func(fs map[string][]byte, config android.Config) { |
| 77 | for k, v := range files { |
| 78 | fs[k] = v |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | func withTargets(targets map[android.OsType][]android.Target) testCustomizer { |
| 84 | return func(fs map[string][]byte, config android.Config) { |
| 85 | for k, v := range targets { |
| 86 | config.Targets[k] = v |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
Jiyong Park | af8998c | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 91 | func withManifestPackageNameOverrides(specs []string) testCustomizer { |
| 92 | return func(fs map[string][]byte, config android.Config) { |
| 93 | config.TestProductVariables.ManifestPackageNameOverrides = specs |
| 94 | } |
| 95 | } |
| 96 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 97 | func withBinder32bit(fs map[string][]byte, config android.Config) { |
| 98 | config.TestProductVariables.Binder32bit = proptools.BoolPtr(true) |
| 99 | } |
| 100 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 101 | func withUnbundledBuild(fs map[string][]byte, config android.Config) { |
| 102 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 103 | } |
| 104 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 105 | 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] | 106 | android.ClearApexDependency() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 107 | |
| 108 | bp = bp + ` |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 109 | filegroup { |
| 110 | name: "myapex-file_contexts", |
| 111 | srcs: [ |
| 112 | "system/sepolicy/apex/myapex-file_contexts", |
| 113 | ], |
| 114 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 115 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 116 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 117 | bp = bp + cc.GatherRequiredDepsForTest(android.Android) |
| 118 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 119 | bp = bp + java.GatherRequiredDepsForTest() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 120 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 121 | fs := map[string][]byte{ |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 122 | "a.java": nil, |
| 123 | "PrebuiltAppFoo.apk": nil, |
| 124 | "PrebuiltAppFooPriv.apk": nil, |
| 125 | "build/make/target/product/security": nil, |
| 126 | "apex_manifest.json": nil, |
| 127 | "AndroidManifest.xml": nil, |
| 128 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 129 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 130 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 131 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 132 | "system/sepolicy/apex/commonapex-file_contexts": nil, |
| 133 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 134 | "mylib.cpp": nil, |
| 135 | "mylib_common.cpp": nil, |
| 136 | "mytest.cpp": nil, |
| 137 | "mytest1.cpp": nil, |
| 138 | "mytest2.cpp": nil, |
| 139 | "mytest3.cpp": nil, |
| 140 | "myprebuilt": nil, |
| 141 | "my_include": nil, |
| 142 | "foo/bar/MyClass.java": nil, |
| 143 | "prebuilt.jar": nil, |
Paul Duffin | 3766cb7 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 144 | "prebuilt.so": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 145 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 146 | "vendor/foo/devkeys/test.pk8": nil, |
| 147 | "testkey.x509.pem": nil, |
| 148 | "testkey.pk8": nil, |
| 149 | "testkey.override.x509.pem": nil, |
| 150 | "testkey.override.pk8": nil, |
| 151 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 152 | "vendor/foo/devkeys/testkey.pem": nil, |
| 153 | "NOTICE": nil, |
| 154 | "custom_notice": nil, |
Jiyong Park | 162e844 | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 155 | "custom_notice_for_static_lib": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 156 | "testkey2.avbpubkey": nil, |
| 157 | "testkey2.pem": nil, |
| 158 | "myapex-arm64.apex": nil, |
| 159 | "myapex-arm.apex": nil, |
Jaewoong Jung | 8cf307e | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 160 | "myapex.apks": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 161 | "frameworks/base/api/current.txt": nil, |
| 162 | "framework/aidl/a.aidl": nil, |
| 163 | "build/make/core/proguard.flags": nil, |
| 164 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 165 | "dummy.txt": nil, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 166 | } |
| 167 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 168 | cc.GatherRequiredFilesForTest(fs) |
| 169 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 170 | for _, handler := range handlers { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 171 | // The fs now needs to be populated before creating the config, call handlers twice |
| 172 | // for now, once to get any fs changes, and later after the config was created to |
| 173 | // set product variables or targets. |
| 174 | tempConfig := android.TestArchConfig(buildDir, nil, bp, fs) |
| 175 | handler(fs, tempConfig) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 176 | } |
| 177 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 178 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 179 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 180 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 181 | config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 182 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 183 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
| 184 | config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") |
| 185 | |
| 186 | for _, handler := range handlers { |
| 187 | // The fs now needs to be populated before creating the config, call handlers twice |
| 188 | // for now, earlier to get any fs changes, and now after the config was created to |
| 189 | // set product variables or targets. |
| 190 | tempFS := map[string][]byte{} |
| 191 | handler(tempFS, config) |
| 192 | } |
| 193 | |
| 194 | ctx := android.NewTestArchContext() |
| 195 | ctx.RegisterModuleType("apex", BundleFactory) |
| 196 | ctx.RegisterModuleType("apex_test", testApexBundleFactory) |
| 197 | ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
| 198 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 199 | ctx.RegisterModuleType("apex_defaults", defaultsFactory) |
| 200 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
| 201 | ctx.RegisterModuleType("override_apex", overrideApexFactory) |
Jaewoong Jung | 8cf307e | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 202 | ctx.RegisterModuleType("apex_set", apexSetFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 203 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 204 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 205 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 206 | |
Paul Duffin | 77980a8 | 2019-12-19 16:01:36 +0000 | [diff] [blame] | 207 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 208 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 209 | ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) |
| 210 | ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 211 | ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory) |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 212 | ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 213 | ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 214 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 215 | java.RegisterJavaBuildComponents(ctx) |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 216 | java.RegisterSystemModulesBuildComponents(ctx) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 217 | java.RegisterAppBuildComponents(ctx) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 218 | ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 219 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 220 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 221 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 222 | |
| 223 | ctx.Register(config) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 224 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 225 | return ctx, config |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 226 | } |
| 227 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 228 | func setUp() { |
| 229 | var err error |
| 230 | buildDir, err = ioutil.TempDir("", "soong_apex_test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 231 | if err != nil { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 232 | panic(err) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 233 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 234 | } |
| 235 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 236 | func tearDown() { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 237 | os.RemoveAll(buildDir) |
| 238 | } |
| 239 | |
| 240 | // ensure that 'result' contains 'expected' |
| 241 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 242 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 243 | if !strings.Contains(result, expected) { |
| 244 | t.Errorf("%q is not found in %q", expected, result) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // ensures that 'result' does not contain 'notExpected' |
| 249 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 250 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 251 | if strings.Contains(result, notExpected) { |
| 252 | t.Errorf("%q is found in %q", notExpected, result) |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 257 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 258 | if !android.InList(expected, result) { |
| 259 | t.Errorf("%q is not found in %v", expected, result) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 264 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 265 | if android.InList(notExpected, result) { |
| 266 | t.Errorf("%q is found in %v", notExpected, result) |
| 267 | } |
| 268 | } |
| 269 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 270 | func ensureListEmpty(t *testing.T, result []string) { |
| 271 | t.Helper() |
| 272 | if len(result) > 0 { |
| 273 | t.Errorf("%q is expected to be empty", result) |
| 274 | } |
| 275 | } |
| 276 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 277 | // Minimal test |
| 278 | func TestBasicApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 279 | ctx, _ := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 280 | apex_defaults { |
| 281 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 282 | manifest: ":myapex.manifest", |
| 283 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 284 | key: "myapex.key", |
| 285 | native_shared_libs: ["mylib"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 286 | multilib: { |
| 287 | both: { |
| 288 | binaries: ["foo",], |
| 289 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 290 | }, |
Jooyung Han | 5a80d9f | 2019-12-23 15:38:34 +0900 | [diff] [blame] | 291 | java_libs: ["myjar"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 292 | } |
| 293 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 294 | apex { |
| 295 | name: "myapex", |
| 296 | defaults: ["myapex-defaults"], |
| 297 | } |
| 298 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 299 | apex_key { |
| 300 | name: "myapex.key", |
| 301 | public_key: "testkey.avbpubkey", |
| 302 | private_key: "testkey.pem", |
| 303 | } |
| 304 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 305 | filegroup { |
| 306 | name: "myapex.manifest", |
| 307 | srcs: ["apex_manifest.json"], |
| 308 | } |
| 309 | |
| 310 | filegroup { |
| 311 | name: "myapex.androidmanifest", |
| 312 | srcs: ["AndroidManifest.xml"], |
| 313 | } |
| 314 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 315 | cc_library { |
| 316 | name: "mylib", |
| 317 | srcs: ["mylib.cpp"], |
| 318 | shared_libs: ["mylib2"], |
| 319 | system_shared_libs: [], |
| 320 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 321 | // TODO: remove //apex_available:platform |
| 322 | apex_available: [ |
| 323 | "//apex_available:platform", |
| 324 | "myapex", |
| 325 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 326 | } |
| 327 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 328 | cc_binary { |
| 329 | name: "foo", |
| 330 | srcs: ["mylib.cpp"], |
| 331 | compile_multilib: "both", |
| 332 | multilib: { |
| 333 | lib32: { |
| 334 | suffix: "32", |
| 335 | }, |
| 336 | lib64: { |
| 337 | suffix: "64", |
| 338 | }, |
| 339 | }, |
| 340 | symlinks: ["foo_link_"], |
| 341 | symlink_preferred_arch: true, |
| 342 | system_shared_libs: [], |
| 343 | static_executable: true, |
| 344 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 345 | apex_available: [ "myapex" ], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Paul Duffin | 3766cb7 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 348 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 349 | name: "mylib2", |
| 350 | srcs: ["mylib.cpp"], |
| 351 | system_shared_libs: [], |
| 352 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 353 | notice: "custom_notice", |
Jiyong Park | 162e844 | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 354 | static_libs: ["libstatic"], |
| 355 | // TODO: remove //apex_available:platform |
| 356 | apex_available: [ |
| 357 | "//apex_available:platform", |
| 358 | "myapex", |
| 359 | ], |
| 360 | } |
| 361 | |
Paul Duffin | 3766cb7 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 362 | cc_prebuilt_library_shared { |
| 363 | name: "mylib2", |
| 364 | srcs: ["prebuilt.so"], |
| 365 | // TODO: remove //apex_available:platform |
| 366 | apex_available: [ |
| 367 | "//apex_available:platform", |
| 368 | "myapex", |
| 369 | ], |
| 370 | } |
| 371 | |
Jiyong Park | 162e844 | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 372 | cc_library_static { |
| 373 | name: "libstatic", |
| 374 | srcs: ["mylib.cpp"], |
| 375 | system_shared_libs: [], |
| 376 | stl: "none", |
| 377 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 378 | // TODO: remove //apex_available:platform |
| 379 | apex_available: [ |
| 380 | "//apex_available:platform", |
| 381 | "myapex", |
| 382 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 383 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 384 | |
| 385 | java_library { |
| 386 | name: "myjar", |
| 387 | srcs: ["foo/bar/MyClass.java"], |
| 388 | sdk_version: "none", |
| 389 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 390 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 391 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 392 | // TODO: remove //apex_available:platform |
| 393 | apex_available: [ |
| 394 | "//apex_available:platform", |
| 395 | "myapex", |
| 396 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | java_library { |
| 400 | name: "myotherjar", |
| 401 | srcs: ["foo/bar/MyClass.java"], |
| 402 | sdk_version: "none", |
| 403 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 404 | // TODO: remove //apex_available:platform |
| 405 | apex_available: [ |
| 406 | "//apex_available:platform", |
| 407 | "myapex", |
| 408 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 409 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 410 | |
| 411 | java_library { |
| 412 | name: "mysharedjar", |
| 413 | srcs: ["foo/bar/MyClass.java"], |
| 414 | sdk_version: "none", |
| 415 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 416 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 417 | `) |
| 418 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 419 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 420 | |
| 421 | optFlags := apexRule.Args["opt_flags"] |
| 422 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 423 | // Ensure that the NOTICE output is being packaged as an asset. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 424 | 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] | 425 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 426 | copyCmds := apexRule.Args["copy_commands"] |
| 427 | |
| 428 | // Ensure that main rule creates an output |
| 429 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 430 | |
| 431 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 432 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 433 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 434 | |
| 435 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 436 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 437 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 438 | |
| 439 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 440 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 441 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 442 | ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar") |
| 443 | // .. but not for java libs |
| 444 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 445 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 446 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 447 | // Ensure that the platform variant ends with _shared or _common |
| 448 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 449 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 450 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 451 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 452 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 453 | |
| 454 | // Ensure that dynamic dependency to java libs are not included |
| 455 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 456 | |
| 457 | // Ensure that all symlinks are present. |
| 458 | found_foo_link_64 := false |
| 459 | found_foo := false |
| 460 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 461 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 462 | if strings.HasSuffix(cmd, "bin/foo") { |
| 463 | found_foo = true |
| 464 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 465 | found_foo_link_64 = true |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | good := found_foo && found_foo_link_64 |
| 470 | if !good { |
| 471 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 472 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 473 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 474 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 475 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 162e844 | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 476 | if len(noticeInputs) != 3 { |
| 477 | t.Errorf("number of input notice files: expected = 3, actual = %q", len(noticeInputs)) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 478 | } |
| 479 | ensureListContains(t, noticeInputs, "NOTICE") |
| 480 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 162e844 | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 481 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 482 | |
Artur Satayev | 5e7c32d | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 483 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
Artur Satayev | 388d39b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 484 | ensureListContains(t, fullDepsInfo, "myjar(minSdkVersion:(no version)) <- myapex") |
| 485 | ensureListContains(t, fullDepsInfo, "mylib(minSdkVersion:(no version)) <- myapex") |
| 486 | ensureListContains(t, fullDepsInfo, "mylib2(minSdkVersion:(no version)) <- mylib") |
| 487 | ensureListContains(t, fullDepsInfo, "myotherjar(minSdkVersion:(no version)) <- myjar") |
| 488 | ensureListContains(t, fullDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | 5e7c32d | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 489 | |
| 490 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
Artur Satayev | 388d39b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 491 | ensureListContains(t, flatDepsInfo, " myjar(minSdkVersion:(no version))") |
| 492 | ensureListContains(t, flatDepsInfo, " mylib(minSdkVersion:(no version))") |
| 493 | ensureListContains(t, flatDepsInfo, " mylib2(minSdkVersion:(no version))") |
| 494 | ensureListContains(t, flatDepsInfo, " myotherjar(minSdkVersion:(no version))") |
| 495 | ensureListContains(t, flatDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 496 | } |
| 497 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 498 | func TestDefaults(t *testing.T) { |
| 499 | ctx, _ := testApex(t, ` |
| 500 | apex_defaults { |
| 501 | name: "myapex-defaults", |
| 502 | key: "myapex.key", |
| 503 | prebuilts: ["myetc"], |
| 504 | native_shared_libs: ["mylib"], |
| 505 | java_libs: ["myjar"], |
| 506 | apps: ["AppFoo"], |
| 507 | } |
| 508 | |
| 509 | prebuilt_etc { |
| 510 | name: "myetc", |
| 511 | src: "myprebuilt", |
| 512 | } |
| 513 | |
| 514 | apex { |
| 515 | name: "myapex", |
| 516 | defaults: ["myapex-defaults"], |
| 517 | } |
| 518 | |
| 519 | apex_key { |
| 520 | name: "myapex.key", |
| 521 | public_key: "testkey.avbpubkey", |
| 522 | private_key: "testkey.pem", |
| 523 | } |
| 524 | |
| 525 | cc_library { |
| 526 | name: "mylib", |
| 527 | system_shared_libs: [], |
| 528 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 529 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | java_library { |
| 533 | name: "myjar", |
| 534 | srcs: ["foo/bar/MyClass.java"], |
| 535 | sdk_version: "none", |
| 536 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 537 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | android_app { |
| 541 | name: "AppFoo", |
| 542 | srcs: ["foo/bar/MyClass.java"], |
| 543 | sdk_version: "none", |
| 544 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 545 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 546 | } |
| 547 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 548 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 549 | "etc/myetc", |
| 550 | "javalib/myjar.jar", |
| 551 | "lib64/mylib.so", |
| 552 | "app/AppFoo/AppFoo.apk", |
| 553 | }) |
| 554 | } |
| 555 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 556 | func TestApexManifest(t *testing.T) { |
| 557 | ctx, _ := testApex(t, ` |
| 558 | apex { |
| 559 | name: "myapex", |
| 560 | key: "myapex.key", |
| 561 | } |
| 562 | |
| 563 | apex_key { |
| 564 | name: "myapex.key", |
| 565 | public_key: "testkey.avbpubkey", |
| 566 | private_key: "testkey.pem", |
| 567 | } |
| 568 | `) |
| 569 | |
| 570 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 571 | args := module.Rule("apexRule").Args |
| 572 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 573 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 574 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 575 | } |
| 576 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 577 | func TestBasicZipApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 578 | ctx, _ := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 579 | apex { |
| 580 | name: "myapex", |
| 581 | key: "myapex.key", |
| 582 | payload_type: "zip", |
| 583 | native_shared_libs: ["mylib"], |
| 584 | } |
| 585 | |
| 586 | apex_key { |
| 587 | name: "myapex.key", |
| 588 | public_key: "testkey.avbpubkey", |
| 589 | private_key: "testkey.pem", |
| 590 | } |
| 591 | |
| 592 | cc_library { |
| 593 | name: "mylib", |
| 594 | srcs: ["mylib.cpp"], |
| 595 | shared_libs: ["mylib2"], |
| 596 | system_shared_libs: [], |
| 597 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 598 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | cc_library { |
| 602 | name: "mylib2", |
| 603 | srcs: ["mylib.cpp"], |
| 604 | system_shared_libs: [], |
| 605 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 606 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 607 | } |
| 608 | `) |
| 609 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 610 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 611 | copyCmds := zipApexRule.Args["copy_commands"] |
| 612 | |
| 613 | // Ensure that main rule creates an output |
| 614 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 615 | |
| 616 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 617 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 618 | |
| 619 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 620 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 621 | |
| 622 | // Ensure that both direct and indirect deps are copied into apex |
| 623 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 624 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | func TestApexWithStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 628 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 629 | apex { |
| 630 | name: "myapex", |
| 631 | key: "myapex.key", |
| 632 | native_shared_libs: ["mylib", "mylib3"], |
| 633 | } |
| 634 | |
| 635 | apex_key { |
| 636 | name: "myapex.key", |
| 637 | public_key: "testkey.avbpubkey", |
| 638 | private_key: "testkey.pem", |
| 639 | } |
| 640 | |
| 641 | cc_library { |
| 642 | name: "mylib", |
| 643 | srcs: ["mylib.cpp"], |
| 644 | shared_libs: ["mylib2", "mylib3"], |
| 645 | system_shared_libs: [], |
| 646 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 647 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | cc_library { |
| 651 | name: "mylib2", |
| 652 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 653 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 654 | system_shared_libs: [], |
| 655 | stl: "none", |
| 656 | stubs: { |
| 657 | versions: ["1", "2", "3"], |
| 658 | }, |
| 659 | } |
| 660 | |
| 661 | cc_library { |
| 662 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 663 | srcs: ["mylib.cpp"], |
| 664 | shared_libs: ["mylib4"], |
| 665 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 666 | stl: "none", |
| 667 | stubs: { |
| 668 | versions: ["10", "11", "12"], |
| 669 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 670 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 671 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 672 | |
| 673 | cc_library { |
| 674 | name: "mylib4", |
| 675 | srcs: ["mylib.cpp"], |
| 676 | system_shared_libs: [], |
| 677 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 678 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 679 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 680 | `) |
| 681 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 682 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 683 | copyCmds := apexRule.Args["copy_commands"] |
| 684 | |
| 685 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 686 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 687 | |
| 688 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 689 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 690 | |
| 691 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 692 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 693 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 694 | 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] | 695 | |
| 696 | // 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] | 697 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 698 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 699 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 700 | |
| 701 | // 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] | 702 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 703 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 704 | 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] | 705 | |
| 706 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 707 | 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] | 708 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 709 | |
| 710 | // Ensure that genstub is invoked with --apex |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 711 | 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] | 712 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 713 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 714 | "lib64/mylib.so", |
| 715 | "lib64/mylib3.so", |
| 716 | "lib64/mylib4.so", |
| 717 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 718 | } |
| 719 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 720 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 721 | ctx, _ := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 722 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 723 | name: "myapex2", |
| 724 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 725 | native_shared_libs: ["mylib"], |
| 726 | } |
| 727 | |
| 728 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 729 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 730 | public_key: "testkey.avbpubkey", |
| 731 | private_key: "testkey.pem", |
| 732 | } |
| 733 | |
| 734 | cc_library { |
| 735 | name: "mylib", |
| 736 | srcs: ["mylib.cpp"], |
| 737 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 738 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 739 | system_shared_libs: [], |
| 740 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 741 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | cc_library { |
| 745 | name: "libfoo", |
| 746 | srcs: ["mylib.cpp"], |
| 747 | shared_libs: ["libbar"], |
| 748 | system_shared_libs: [], |
| 749 | stl: "none", |
| 750 | stubs: { |
| 751 | versions: ["10", "20", "30"], |
| 752 | }, |
| 753 | } |
| 754 | |
| 755 | cc_library { |
| 756 | name: "libbar", |
| 757 | srcs: ["mylib.cpp"], |
| 758 | system_shared_libs: [], |
| 759 | stl: "none", |
| 760 | } |
| 761 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 762 | cc_library_static { |
| 763 | name: "libbaz", |
| 764 | srcs: ["mylib.cpp"], |
| 765 | system_shared_libs: [], |
| 766 | stl: "none", |
| 767 | apex_available: [ "myapex2" ], |
| 768 | } |
| 769 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 770 | `) |
| 771 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 772 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 773 | copyCmds := apexRule.Args["copy_commands"] |
| 774 | |
| 775 | // Ensure that direct non-stubs dep is always included |
| 776 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 777 | |
| 778 | // Ensure that indirect stubs dep is not included |
| 779 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 780 | |
| 781 | // Ensure that dependency of stubs is not included |
| 782 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 783 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 784 | 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] | 785 | |
| 786 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 787 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 788 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 789 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 790 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 791 | 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] | 792 | |
| 793 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 794 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 795 | |
Artur Satayev | 5e7c32d | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 796 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
Artur Satayev | 388d39b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 797 | ensureListContains(t, fullDepsInfo, "mylib(minSdkVersion:(no version)) <- myapex2") |
| 798 | ensureListContains(t, fullDepsInfo, "libbaz(minSdkVersion:(no version)) <- mylib") |
| 799 | ensureListContains(t, fullDepsInfo, "libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 800 | |
Artur Satayev | 5e7c32d | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 801 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
Artur Satayev | 388d39b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 802 | ensureListContains(t, flatDepsInfo, " mylib(minSdkVersion:(no version))") |
| 803 | ensureListContains(t, flatDepsInfo, " libbaz(minSdkVersion:(no version))") |
| 804 | ensureListContains(t, flatDepsInfo, " libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 805 | } |
| 806 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 807 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 808 | /* |
| 809 | myapex |
| 810 | | |
| 811 | v (runtime_libs) |
| 812 | mylib ------+------> libfoo [provides stub] |
| 813 | | |
| 814 | `------> libbar |
| 815 | */ |
| 816 | ctx, _ := testApex(t, ` |
| 817 | apex { |
| 818 | name: "myapex", |
| 819 | key: "myapex.key", |
| 820 | native_shared_libs: ["mylib"], |
| 821 | } |
| 822 | |
| 823 | apex_key { |
| 824 | name: "myapex.key", |
| 825 | public_key: "testkey.avbpubkey", |
| 826 | private_key: "testkey.pem", |
| 827 | } |
| 828 | |
| 829 | cc_library { |
| 830 | name: "mylib", |
| 831 | srcs: ["mylib.cpp"], |
| 832 | runtime_libs: ["libfoo", "libbar"], |
| 833 | system_shared_libs: [], |
| 834 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 835 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | cc_library { |
| 839 | name: "libfoo", |
| 840 | srcs: ["mylib.cpp"], |
| 841 | system_shared_libs: [], |
| 842 | stl: "none", |
| 843 | stubs: { |
| 844 | versions: ["10", "20", "30"], |
| 845 | }, |
| 846 | } |
| 847 | |
| 848 | cc_library { |
| 849 | name: "libbar", |
| 850 | srcs: ["mylib.cpp"], |
| 851 | system_shared_libs: [], |
| 852 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 853 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | `) |
| 857 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 858 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 859 | copyCmds := apexRule.Args["copy_commands"] |
| 860 | |
| 861 | // Ensure that direct non-stubs dep is always included |
| 862 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 863 | |
| 864 | // Ensure that indirect stubs dep is not included |
| 865 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 866 | |
| 867 | // Ensure that runtime_libs dep in included |
| 868 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 869 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 870 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 871 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 872 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 873 | |
| 874 | } |
| 875 | |
Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 876 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 877 | testcases := []struct { |
| 878 | name string |
| 879 | minSdkVersion string |
| 880 | shouldLink string |
| 881 | shouldNotLink []string |
| 882 | }{ |
| 883 | { |
Jooyung Han | 7406660 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 884 | name: "should link to the latest", |
Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 885 | minSdkVersion: "current", |
| 886 | shouldLink: "30", |
| 887 | shouldNotLink: []string{"29"}, |
| 888 | }, |
| 889 | { |
| 890 | name: "should link to llndk#29", |
| 891 | minSdkVersion: "29", |
| 892 | shouldLink: "29", |
| 893 | shouldNotLink: []string{"30"}, |
| 894 | }, |
| 895 | } |
| 896 | for _, tc := range testcases { |
| 897 | t.Run(tc.name, func(t *testing.T) { |
| 898 | ctx, _ := testApex(t, ` |
| 899 | apex { |
| 900 | name: "myapex", |
| 901 | key: "myapex.key", |
| 902 | use_vendor: true, |
| 903 | native_shared_libs: ["mylib"], |
| 904 | min_sdk_version: "`+tc.minSdkVersion+`", |
| 905 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 906 | |
Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 907 | apex_key { |
| 908 | name: "myapex.key", |
| 909 | public_key: "testkey.avbpubkey", |
| 910 | private_key: "testkey.pem", |
| 911 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 912 | |
Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 913 | cc_library { |
| 914 | name: "mylib", |
| 915 | srcs: ["mylib.cpp"], |
| 916 | vendor_available: true, |
| 917 | shared_libs: ["libbar"], |
| 918 | system_shared_libs: [], |
| 919 | stl: "none", |
| 920 | apex_available: [ "myapex" ], |
| 921 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 922 | |
Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 923 | cc_library { |
| 924 | name: "libbar", |
| 925 | srcs: ["mylib.cpp"], |
| 926 | system_shared_libs: [], |
| 927 | stl: "none", |
| 928 | stubs: { versions: ["29","30"] }, |
| 929 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 930 | |
Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 931 | llndk_library { |
| 932 | name: "libbar", |
| 933 | symbol_file: "", |
| 934 | } |
| 935 | `, func(fs map[string][]byte, config android.Config) { |
| 936 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 937 | }, withUnbundledBuild) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 938 | |
Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 939 | // Ensure that LLNDK dep is not included |
| 940 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 941 | "lib64/mylib.so", |
| 942 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 943 | |
Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 944 | // Ensure that LLNDK dep is required |
| 945 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 946 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 947 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 948 | |
Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 949 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
| 950 | ensureContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so") |
| 951 | for _, ver := range tc.shouldNotLink { |
| 952 | ensureNotContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so") |
| 953 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 954 | |
Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 955 | mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 956 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink) |
| 957 | }) |
| 958 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 959 | } |
| 960 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 961 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 962 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 963 | apex { |
| 964 | name: "myapex", |
| 965 | key: "myapex.key", |
| 966 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 967 | } |
| 968 | |
| 969 | apex_key { |
| 970 | name: "myapex.key", |
| 971 | public_key: "testkey.avbpubkey", |
| 972 | private_key: "testkey.pem", |
| 973 | } |
| 974 | |
| 975 | cc_library { |
| 976 | name: "mylib", |
| 977 | srcs: ["mylib.cpp"], |
| 978 | shared_libs: ["libdl#27"], |
| 979 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 980 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | cc_library_shared { |
| 984 | name: "mylib_shared", |
| 985 | srcs: ["mylib.cpp"], |
| 986 | shared_libs: ["libdl#27"], |
| 987 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 988 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 992 | name: "libBootstrap", |
| 993 | srcs: ["mylib.cpp"], |
| 994 | stl: "none", |
| 995 | bootstrap: true, |
| 996 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 997 | `) |
| 998 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 999 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1000 | copyCmds := apexRule.Args["copy_commands"] |
| 1001 | |
| 1002 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1003 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1004 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1005 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1006 | |
| 1007 | // 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] | 1008 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1009 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1010 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
| 1011 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 1012 | 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] | 1013 | |
| 1014 | // For dependency to libc |
| 1015 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1016 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1017 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1018 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1019 | // ... Cflags from stub is correctly exported to mylib |
| 1020 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 1021 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 1022 | |
| 1023 | // For dependency to libm |
| 1024 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1025 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1026 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1027 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1028 | // ... and is not compiling with the stub |
| 1029 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1030 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1031 | |
| 1032 | // For dependency to libdl |
| 1033 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1034 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1035 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1036 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1037 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1038 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1039 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1040 | // ... Cflags from stub is correctly exported to mylib |
| 1041 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1042 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1043 | |
| 1044 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1045 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1046 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1047 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1048 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1049 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1050 | |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1051 | func TestApexUseStubsAccordingToMinSdkVersionInUnbundledBuild(t *testing.T) { |
| 1052 | // there are three links between liba --> libz |
| 1053 | // 1) myapex -> libx -> liba -> libz : this should be #2 link, but fallback to #1 |
| 1054 | // 2) otherapex -> liby -> liba -> libz : this should be #3 link |
| 1055 | // 3) (platform) -> liba -> libz : this should be non-stub link |
| 1056 | ctx, _ := testApex(t, ` |
| 1057 | apex { |
| 1058 | name: "myapex", |
| 1059 | key: "myapex.key", |
| 1060 | native_shared_libs: ["libx"], |
| 1061 | min_sdk_version: "2", |
| 1062 | } |
| 1063 | |
| 1064 | apex { |
| 1065 | name: "otherapex", |
| 1066 | key: "myapex.key", |
| 1067 | native_shared_libs: ["liby"], |
| 1068 | min_sdk_version: "3", |
| 1069 | } |
| 1070 | |
| 1071 | apex_key { |
| 1072 | name: "myapex.key", |
| 1073 | public_key: "testkey.avbpubkey", |
| 1074 | private_key: "testkey.pem", |
| 1075 | } |
| 1076 | |
| 1077 | cc_library { |
| 1078 | name: "libx", |
| 1079 | shared_libs: ["liba"], |
| 1080 | system_shared_libs: [], |
| 1081 | stl: "none", |
| 1082 | apex_available: [ "myapex" ], |
| 1083 | } |
| 1084 | |
| 1085 | cc_library { |
| 1086 | name: "liby", |
| 1087 | shared_libs: ["liba"], |
| 1088 | system_shared_libs: [], |
| 1089 | stl: "none", |
| 1090 | apex_available: [ "otherapex" ], |
| 1091 | } |
| 1092 | |
| 1093 | cc_library { |
| 1094 | name: "liba", |
| 1095 | shared_libs: ["libz"], |
| 1096 | system_shared_libs: [], |
| 1097 | stl: "none", |
| 1098 | apex_available: [ |
| 1099 | "//apex_available:anyapex", |
| 1100 | "//apex_available:platform", |
| 1101 | ], |
| 1102 | } |
| 1103 | |
| 1104 | cc_library { |
| 1105 | name: "libz", |
| 1106 | system_shared_libs: [], |
| 1107 | stl: "none", |
| 1108 | stubs: { |
| 1109 | versions: ["1", "3"], |
| 1110 | }, |
| 1111 | } |
| 1112 | `, withUnbundledBuild) |
| 1113 | |
| 1114 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1115 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1116 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1117 | } |
| 1118 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1119 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1120 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1121 | } |
| 1122 | // platform liba is linked to non-stub version |
| 1123 | expectLink("liba", "shared", "libz", "shared") |
| 1124 | // liba in myapex is linked to #1 |
| 1125 | expectLink("liba", "shared_myapex", "libz", "shared_1") |
| 1126 | expectNoLink("liba", "shared_myapex", "libz", "shared_3") |
| 1127 | expectNoLink("liba", "shared_myapex", "libz", "shared") |
| 1128 | // liba in otherapex is linked to #3 |
| 1129 | expectLink("liba", "shared_otherapex", "libz", "shared_3") |
| 1130 | expectNoLink("liba", "shared_otherapex", "libz", "shared_1") |
| 1131 | expectNoLink("liba", "shared_otherapex", "libz", "shared") |
| 1132 | } |
| 1133 | |
Jooyung Han | 29e91d2 | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1134 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
| 1135 | ctx, _ := testApex(t, ` |
| 1136 | apex { |
| 1137 | name: "myapex", |
| 1138 | key: "myapex.key", |
| 1139 | native_shared_libs: ["libx"], |
| 1140 | min_sdk_version: "R", |
| 1141 | } |
| 1142 | |
| 1143 | apex_key { |
| 1144 | name: "myapex.key", |
| 1145 | public_key: "testkey.avbpubkey", |
| 1146 | private_key: "testkey.pem", |
| 1147 | } |
| 1148 | |
| 1149 | cc_library { |
| 1150 | name: "libx", |
| 1151 | shared_libs: ["libz"], |
| 1152 | system_shared_libs: [], |
| 1153 | stl: "none", |
| 1154 | apex_available: [ "myapex" ], |
| 1155 | } |
| 1156 | |
| 1157 | cc_library { |
| 1158 | name: "libz", |
| 1159 | system_shared_libs: [], |
| 1160 | stl: "none", |
| 1161 | stubs: { |
| 1162 | versions: ["29", "R"], |
| 1163 | }, |
| 1164 | } |
| 1165 | `, func(fs map[string][]byte, config android.Config) { |
| 1166 | config.TestProductVariables.Platform_version_active_codenames = []string{"R"} |
| 1167 | }) |
| 1168 | |
| 1169 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1170 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1171 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1172 | } |
| 1173 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1174 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1175 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1176 | } |
| 1177 | // 9000 is quite a magic number. |
| 1178 | // Finalized SDK codenames are mapped as P(28), Q(29), ... |
| 1179 | // And, codenames which are not finalized yet(active_codenames + future_codenames) are numbered from 9000, 9001, ... |
| 1180 | // to distinguish them from finalized and future_api(10000) |
| 1181 | // In this test, "R" is assumed not finalized yet( listed in Platform_version_active_codenames) and translated into 9000 |
| 1182 | // (refer android/api_levels.go) |
| 1183 | expectLink("libx", "shared_myapex", "libz", "shared_9000") |
| 1184 | expectNoLink("libx", "shared_myapex", "libz", "shared_29") |
| 1185 | expectNoLink("libx", "shared_myapex", "libz", "shared") |
| 1186 | } |
| 1187 | |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1188 | func TestApexMinSdkVersionDefaultsToLatest(t *testing.T) { |
| 1189 | ctx, _ := testApex(t, ` |
| 1190 | apex { |
| 1191 | name: "myapex", |
| 1192 | key: "myapex.key", |
| 1193 | native_shared_libs: ["libx"], |
| 1194 | } |
| 1195 | |
| 1196 | apex_key { |
| 1197 | name: "myapex.key", |
| 1198 | public_key: "testkey.avbpubkey", |
| 1199 | private_key: "testkey.pem", |
| 1200 | } |
| 1201 | |
| 1202 | cc_library { |
| 1203 | name: "libx", |
| 1204 | shared_libs: ["libz"], |
| 1205 | system_shared_libs: [], |
| 1206 | stl: "none", |
| 1207 | apex_available: [ "myapex" ], |
| 1208 | } |
| 1209 | |
| 1210 | cc_library { |
| 1211 | name: "libz", |
| 1212 | system_shared_libs: [], |
| 1213 | stl: "none", |
| 1214 | stubs: { |
| 1215 | versions: ["1", "2"], |
| 1216 | }, |
| 1217 | } |
| 1218 | `) |
| 1219 | |
| 1220 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1221 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1222 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1223 | } |
| 1224 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1225 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1226 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1227 | } |
| 1228 | expectLink("libx", "shared_myapex", "libz", "shared_2") |
| 1229 | expectNoLink("libx", "shared_myapex", "libz", "shared_1") |
| 1230 | expectNoLink("libx", "shared_myapex", "libz", "shared") |
| 1231 | } |
| 1232 | |
| 1233 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
| 1234 | ctx, _ := testApex(t, ` |
| 1235 | apex { |
| 1236 | name: "myapex", |
| 1237 | key: "myapex.key", |
| 1238 | native_shared_libs: ["libx"], |
| 1239 | } |
| 1240 | |
| 1241 | apex_key { |
| 1242 | name: "myapex.key", |
| 1243 | public_key: "testkey.avbpubkey", |
| 1244 | private_key: "testkey.pem", |
| 1245 | } |
| 1246 | |
| 1247 | cc_library { |
| 1248 | name: "libx", |
| 1249 | system_shared_libs: [], |
| 1250 | stl: "none", |
| 1251 | apex_available: [ "myapex" ], |
| 1252 | stubs: { |
| 1253 | versions: ["1", "2"], |
| 1254 | }, |
| 1255 | } |
| 1256 | |
| 1257 | cc_library { |
| 1258 | name: "libz", |
| 1259 | shared_libs: ["libx"], |
| 1260 | system_shared_libs: [], |
| 1261 | stl: "none", |
| 1262 | } |
| 1263 | `) |
| 1264 | |
| 1265 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1266 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1267 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1268 | } |
| 1269 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1270 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1271 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1272 | } |
| 1273 | expectLink("libz", "shared", "libx", "shared_2") |
| 1274 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1275 | expectNoLink("libz", "shared", "libz", "shared") |
| 1276 | } |
| 1277 | |
Jooyung Han | 7406660 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1278 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1279 | ctx, _ := testApex(t, ` |
| 1280 | apex { |
| 1281 | name: "myapex", |
| 1282 | key: "myapex.key", |
| 1283 | native_shared_libs: ["libx"], |
| 1284 | min_sdk_version: "29", |
| 1285 | } |
| 1286 | |
| 1287 | apex_key { |
| 1288 | name: "myapex.key", |
| 1289 | public_key: "testkey.avbpubkey", |
| 1290 | private_key: "testkey.pem", |
| 1291 | } |
| 1292 | |
| 1293 | cc_library { |
| 1294 | name: "libx", |
| 1295 | shared_libs: ["libbar"], |
| 1296 | apex_available: [ "myapex" ], |
| 1297 | } |
| 1298 | |
| 1299 | cc_library { |
| 1300 | name: "libbar", |
| 1301 | stubs: { |
| 1302 | versions: ["29", "30"], |
| 1303 | }, |
| 1304 | } |
Jooyung Han | 7406660 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1305 | `, func(fs map[string][]byte, config android.Config) { |
| 1306 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1307 | }) |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1308 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1309 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1310 | libFlags := ld.Args["libFlags"] |
| 1311 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1312 | } |
Jooyung Han | 7406660 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1313 | expectLink("libx", "shared_hwasan_myapex", "libbar", "shared_30") |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1314 | } |
| 1315 | |
Jooyung Han | 7406660 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1316 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1317 | ctx, _ := testApex(t, ` |
| 1318 | apex { |
| 1319 | name: "myapex", |
| 1320 | key: "myapex.key", |
| 1321 | native_shared_libs: ["libx"], |
| 1322 | min_sdk_version: "29", |
| 1323 | } |
| 1324 | |
| 1325 | apex_key { |
| 1326 | name: "myapex.key", |
| 1327 | public_key: "testkey.avbpubkey", |
| 1328 | private_key: "testkey.pem", |
| 1329 | } |
| 1330 | |
| 1331 | cc_library { |
| 1332 | name: "libx", |
| 1333 | apex_available: [ "myapex" ], |
| 1334 | } |
Jooyung Han | 7406660 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1335 | `) |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1336 | |
| 1337 | // ensure apex variant of c++ is linked with static unwinder |
| 1338 | cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module) |
| 1339 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped") |
| 1340 | // note that platform variant is not. |
| 1341 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 1342 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped") |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | func TestInvalidMinSdkVersion(t *testing.T) { |
Jooyung Han | 7406660 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1346 | testApexError(t, `"libz" .*: not found a version\(<=29\)`, ` |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1347 | apex { |
| 1348 | name: "myapex", |
| 1349 | key: "myapex.key", |
| 1350 | native_shared_libs: ["libx"], |
| 1351 | min_sdk_version: "29", |
| 1352 | } |
| 1353 | |
| 1354 | apex_key { |
| 1355 | name: "myapex.key", |
| 1356 | public_key: "testkey.avbpubkey", |
| 1357 | private_key: "testkey.pem", |
| 1358 | } |
| 1359 | |
| 1360 | cc_library { |
| 1361 | name: "libx", |
| 1362 | shared_libs: ["libz"], |
| 1363 | system_shared_libs: [], |
| 1364 | stl: "none", |
| 1365 | apex_available: [ "myapex" ], |
| 1366 | } |
| 1367 | |
| 1368 | cc_library { |
| 1369 | name: "libz", |
| 1370 | system_shared_libs: [], |
| 1371 | stl: "none", |
| 1372 | stubs: { |
| 1373 | versions: ["30"], |
| 1374 | }, |
| 1375 | } |
Jooyung Han | 7406660 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1376 | `) |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1377 | |
Jooyung Han | 29e91d2 | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1378 | testApexError(t, `"myapex" .*: min_sdk_version: SDK version should be .*`, ` |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1379 | apex { |
| 1380 | name: "myapex", |
| 1381 | key: "myapex.key", |
Jooyung Han | 29e91d2 | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1382 | min_sdk_version: "abc", |
Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | apex_key { |
| 1386 | name: "myapex.key", |
| 1387 | public_key: "testkey.avbpubkey", |
| 1388 | private_key: "testkey.pem", |
| 1389 | } |
| 1390 | `) |
| 1391 | } |
| 1392 | |
Artur Satayev | 2eedf62 | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1393 | func TestJavaStableSdkVersion(t *testing.T) { |
| 1394 | testCases := []struct { |
| 1395 | name string |
| 1396 | expectedError string |
| 1397 | bp string |
| 1398 | }{ |
| 1399 | { |
| 1400 | name: "Non-updatable apex with non-stable dep", |
| 1401 | bp: ` |
| 1402 | apex { |
| 1403 | name: "myapex", |
| 1404 | java_libs: ["myjar"], |
| 1405 | key: "myapex.key", |
| 1406 | } |
| 1407 | apex_key { |
| 1408 | name: "myapex.key", |
| 1409 | public_key: "testkey.avbpubkey", |
| 1410 | private_key: "testkey.pem", |
| 1411 | } |
| 1412 | java_library { |
| 1413 | name: "myjar", |
| 1414 | srcs: ["foo/bar/MyClass.java"], |
| 1415 | sdk_version: "core_platform", |
| 1416 | apex_available: ["myapex"], |
| 1417 | } |
| 1418 | `, |
| 1419 | }, |
| 1420 | { |
| 1421 | name: "Updatable apex with stable dep", |
| 1422 | bp: ` |
| 1423 | apex { |
| 1424 | name: "myapex", |
| 1425 | java_libs: ["myjar"], |
| 1426 | key: "myapex.key", |
| 1427 | updatable: true, |
| 1428 | min_sdk_version: "29", |
| 1429 | } |
| 1430 | apex_key { |
| 1431 | name: "myapex.key", |
| 1432 | public_key: "testkey.avbpubkey", |
| 1433 | private_key: "testkey.pem", |
| 1434 | } |
| 1435 | java_library { |
| 1436 | name: "myjar", |
| 1437 | srcs: ["foo/bar/MyClass.java"], |
| 1438 | sdk_version: "current", |
| 1439 | apex_available: ["myapex"], |
| 1440 | } |
| 1441 | `, |
| 1442 | }, |
| 1443 | { |
| 1444 | name: "Updatable apex with non-stable dep", |
| 1445 | expectedError: "cannot depend on \"myjar\"", |
| 1446 | bp: ` |
| 1447 | apex { |
| 1448 | name: "myapex", |
| 1449 | java_libs: ["myjar"], |
| 1450 | key: "myapex.key", |
| 1451 | updatable: true, |
| 1452 | } |
| 1453 | apex_key { |
| 1454 | name: "myapex.key", |
| 1455 | public_key: "testkey.avbpubkey", |
| 1456 | private_key: "testkey.pem", |
| 1457 | } |
| 1458 | java_library { |
| 1459 | name: "myjar", |
| 1460 | srcs: ["foo/bar/MyClass.java"], |
| 1461 | sdk_version: "core_platform", |
| 1462 | apex_available: ["myapex"], |
| 1463 | } |
| 1464 | `, |
| 1465 | }, |
| 1466 | { |
| 1467 | name: "Updatable apex with non-stable transitive dep", |
| 1468 | expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against non-public Android API.", |
| 1469 | bp: ` |
| 1470 | apex { |
| 1471 | name: "myapex", |
| 1472 | java_libs: ["myjar"], |
| 1473 | key: "myapex.key", |
| 1474 | updatable: true, |
| 1475 | } |
| 1476 | apex_key { |
| 1477 | name: "myapex.key", |
| 1478 | public_key: "testkey.avbpubkey", |
| 1479 | private_key: "testkey.pem", |
| 1480 | } |
| 1481 | java_library { |
| 1482 | name: "myjar", |
| 1483 | srcs: ["foo/bar/MyClass.java"], |
| 1484 | sdk_version: "current", |
| 1485 | apex_available: ["myapex"], |
| 1486 | static_libs: ["transitive-jar"], |
| 1487 | } |
| 1488 | java_library { |
| 1489 | name: "transitive-jar", |
| 1490 | srcs: ["foo/bar/MyClass.java"], |
| 1491 | sdk_version: "core_platform", |
| 1492 | apex_available: ["myapex"], |
| 1493 | } |
| 1494 | `, |
| 1495 | }, |
| 1496 | } |
| 1497 | |
| 1498 | for _, test := range testCases { |
| 1499 | t.Run(test.name, func(t *testing.T) { |
| 1500 | if test.expectedError == "" { |
| 1501 | testApex(t, test.bp) |
| 1502 | } else { |
| 1503 | testApexError(t, test.expectedError, test.bp) |
| 1504 | } |
| 1505 | }) |
| 1506 | } |
| 1507 | } |
| 1508 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1509 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1510 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1511 | apex { |
| 1512 | name: "myapex", |
| 1513 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1514 | native_shared_libs: ["mylib"], |
| 1515 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1516 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1517 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | apex_key { |
| 1521 | name: "myapex.key", |
| 1522 | public_key: "testkey.avbpubkey", |
| 1523 | private_key: "testkey.pem", |
| 1524 | } |
| 1525 | |
| 1526 | prebuilt_etc { |
| 1527 | name: "myetc", |
| 1528 | src: "myprebuilt", |
| 1529 | sub_dir: "foo/bar", |
| 1530 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1531 | |
| 1532 | cc_library { |
| 1533 | name: "mylib", |
| 1534 | srcs: ["mylib.cpp"], |
| 1535 | relative_install_path: "foo/bar", |
| 1536 | system_shared_libs: [], |
| 1537 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1538 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | cc_binary { |
| 1542 | name: "mybin", |
| 1543 | srcs: ["mylib.cpp"], |
| 1544 | relative_install_path: "foo/bar", |
| 1545 | system_shared_libs: [], |
| 1546 | static_executable: true, |
| 1547 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1548 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1549 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1550 | `) |
| 1551 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1552 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1553 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 1554 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1555 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1556 | ensureListContains(t, dirs, "etc") |
| 1557 | ensureListContains(t, dirs, "etc/foo") |
| 1558 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1559 | ensureListContains(t, dirs, "lib64") |
| 1560 | ensureListContains(t, dirs, "lib64/foo") |
| 1561 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 1562 | ensureListContains(t, dirs, "lib") |
| 1563 | ensureListContains(t, dirs, "lib/foo") |
| 1564 | ensureListContains(t, dirs, "lib/foo/bar") |
| 1565 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 1566 | ensureListContains(t, dirs, "bin") |
| 1567 | ensureListContains(t, dirs, "bin/foo") |
| 1568 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1569 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1570 | |
| 1571 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1572 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1573 | apex { |
| 1574 | name: "myapex", |
| 1575 | key: "myapex.key", |
| 1576 | native_shared_libs: ["mylib"], |
| 1577 | use_vendor: true, |
| 1578 | } |
| 1579 | |
| 1580 | apex_key { |
| 1581 | name: "myapex.key", |
| 1582 | public_key: "testkey.avbpubkey", |
| 1583 | private_key: "testkey.pem", |
| 1584 | } |
| 1585 | |
| 1586 | cc_library { |
| 1587 | name: "mylib", |
| 1588 | srcs: ["mylib.cpp"], |
| 1589 | shared_libs: ["mylib2"], |
| 1590 | system_shared_libs: [], |
| 1591 | vendor_available: true, |
| 1592 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1593 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | cc_library { |
| 1597 | name: "mylib2", |
| 1598 | srcs: ["mylib.cpp"], |
| 1599 | system_shared_libs: [], |
| 1600 | vendor_available: true, |
| 1601 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1602 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1603 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1604 | `, func(fs map[string][]byte, config android.Config) { |
| 1605 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 1606 | }) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1607 | |
| 1608 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1609 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1610 | for _, implicit := range i.Implicits { |
| 1611 | inputsList = append(inputsList, implicit.String()) |
| 1612 | } |
| 1613 | } |
| 1614 | inputsString := strings.Join(inputsList, " ") |
| 1615 | |
| 1616 | // 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] | 1617 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so") |
| 1618 | 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] | 1619 | |
| 1620 | // ensure that the apex does not include core variants |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1621 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so") |
| 1622 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1623 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1624 | |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1625 | func TestUseVendorRestriction(t *testing.T) { |
| 1626 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 1627 | apex { |
| 1628 | name: "myapex", |
| 1629 | key: "myapex.key", |
| 1630 | use_vendor: true, |
| 1631 | } |
| 1632 | apex_key { |
| 1633 | name: "myapex.key", |
| 1634 | public_key: "testkey.avbpubkey", |
| 1635 | private_key: "testkey.pem", |
| 1636 | } |
| 1637 | `, func(fs map[string][]byte, config android.Config) { |
| 1638 | setUseVendorWhitelistForTest(config, []string{""}) |
| 1639 | }) |
| 1640 | // no error with whitelist |
| 1641 | testApex(t, ` |
| 1642 | apex { |
| 1643 | name: "myapex", |
| 1644 | key: "myapex.key", |
| 1645 | use_vendor: true, |
| 1646 | } |
| 1647 | apex_key { |
| 1648 | name: "myapex.key", |
| 1649 | public_key: "testkey.avbpubkey", |
| 1650 | private_key: "testkey.pem", |
| 1651 | } |
| 1652 | `, func(fs map[string][]byte, config android.Config) { |
| 1653 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 1654 | }) |
| 1655 | } |
| 1656 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 1657 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 1658 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 1659 | apex { |
| 1660 | name: "myapex", |
| 1661 | key: "myapex.key", |
| 1662 | native_shared_libs: ["mylib"], |
| 1663 | use_vendor: true, |
| 1664 | } |
| 1665 | |
| 1666 | apex_key { |
| 1667 | name: "myapex.key", |
| 1668 | public_key: "testkey.avbpubkey", |
| 1669 | private_key: "testkey.pem", |
| 1670 | } |
| 1671 | |
| 1672 | cc_library { |
| 1673 | name: "mylib", |
| 1674 | srcs: ["mylib.cpp"], |
| 1675 | system_shared_libs: [], |
| 1676 | stl: "none", |
| 1677 | } |
| 1678 | `) |
| 1679 | } |
| 1680 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1681 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1682 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1683 | apex { |
| 1684 | name: "myapex", |
| 1685 | key: "myapex.key", |
| 1686 | native_shared_libs: ["mylib"], |
| 1687 | } |
| 1688 | |
| 1689 | apex_key { |
| 1690 | name: "myapex.key", |
| 1691 | public_key: "testkey.avbpubkey", |
| 1692 | private_key: "testkey.pem", |
| 1693 | } |
| 1694 | |
| 1695 | cc_library { |
| 1696 | name: "mylib", |
| 1697 | srcs: ["mylib.cpp"], |
| 1698 | system_shared_libs: [], |
| 1699 | stl: "none", |
| 1700 | stubs: { |
| 1701 | versions: ["1", "2", "3"], |
| 1702 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1703 | apex_available: [ |
| 1704 | "//apex_available:platform", |
| 1705 | "myapex", |
| 1706 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | cc_binary { |
| 1710 | name: "not_in_apex", |
| 1711 | srcs: ["mylib.cpp"], |
| 1712 | static_libs: ["mylib"], |
| 1713 | static_executable: true, |
| 1714 | system_shared_libs: [], |
| 1715 | stl: "none", |
| 1716 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1717 | `) |
| 1718 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1719 | 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] | 1720 | |
| 1721 | // 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] | 1722 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1723 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1724 | |
| 1725 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1726 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1727 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1728 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1729 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1730 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1731 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1732 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | cc_library { |
| 1736 | name: "mylib", |
| 1737 | srcs: ["mylib.cpp"], |
| 1738 | system_shared_libs: [], |
| 1739 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1740 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | apex_key { |
| 1744 | name: "myapex.key", |
| 1745 | public_key: "testkey.avbpubkey", |
| 1746 | private_key: "testkey.pem", |
| 1747 | } |
| 1748 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1749 | android_app_certificate { |
| 1750 | name: "myapex.certificate", |
| 1751 | certificate: "testkey", |
| 1752 | } |
| 1753 | |
| 1754 | android_app_certificate { |
| 1755 | name: "myapex.certificate.override", |
| 1756 | certificate: "testkey.override", |
| 1757 | } |
| 1758 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1759 | `) |
| 1760 | |
| 1761 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1762 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1763 | |
| 1764 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 1765 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 1766 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 1767 | } |
| 1768 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 1769 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 1770 | "vendor/foo/devkeys/testkey.pem") |
| 1771 | } |
| 1772 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1773 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1774 | 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] | 1775 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1776 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1777 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1778 | } |
| 1779 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1780 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 1781 | func TestCertificate(t *testing.T) { |
| 1782 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 1783 | ctx, _ := testApex(t, ` |
| 1784 | apex { |
| 1785 | name: "myapex", |
| 1786 | key: "myapex.key", |
| 1787 | } |
| 1788 | apex_key { |
| 1789 | name: "myapex.key", |
| 1790 | public_key: "testkey.avbpubkey", |
| 1791 | private_key: "testkey.pem", |
| 1792 | }`) |
| 1793 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1794 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 1795 | if actual := rule.Args["certificates"]; actual != expected { |
| 1796 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1797 | } |
| 1798 | }) |
| 1799 | t.Run("override when unspecified", func(t *testing.T) { |
| 1800 | ctx, _ := testApex(t, ` |
| 1801 | apex { |
| 1802 | name: "myapex_keytest", |
| 1803 | key: "myapex.key", |
| 1804 | file_contexts: ":myapex-file_contexts", |
| 1805 | } |
| 1806 | apex_key { |
| 1807 | name: "myapex.key", |
| 1808 | public_key: "testkey.avbpubkey", |
| 1809 | private_key: "testkey.pem", |
| 1810 | } |
| 1811 | android_app_certificate { |
| 1812 | name: "myapex.certificate.override", |
| 1813 | certificate: "testkey.override", |
| 1814 | }`) |
| 1815 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1816 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1817 | if actual := rule.Args["certificates"]; actual != expected { |
| 1818 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1819 | } |
| 1820 | }) |
| 1821 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 1822 | ctx, _ := testApex(t, ` |
| 1823 | apex { |
| 1824 | name: "myapex", |
| 1825 | key: "myapex.key", |
| 1826 | certificate: ":myapex.certificate", |
| 1827 | } |
| 1828 | apex_key { |
| 1829 | name: "myapex.key", |
| 1830 | public_key: "testkey.avbpubkey", |
| 1831 | private_key: "testkey.pem", |
| 1832 | } |
| 1833 | android_app_certificate { |
| 1834 | name: "myapex.certificate", |
| 1835 | certificate: "testkey", |
| 1836 | }`) |
| 1837 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1838 | expected := "testkey.x509.pem testkey.pk8" |
| 1839 | if actual := rule.Args["certificates"]; actual != expected { |
| 1840 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1841 | } |
| 1842 | }) |
| 1843 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 1844 | ctx, _ := testApex(t, ` |
| 1845 | apex { |
| 1846 | name: "myapex_keytest", |
| 1847 | key: "myapex.key", |
| 1848 | file_contexts: ":myapex-file_contexts", |
| 1849 | certificate: ":myapex.certificate", |
| 1850 | } |
| 1851 | apex_key { |
| 1852 | name: "myapex.key", |
| 1853 | public_key: "testkey.avbpubkey", |
| 1854 | private_key: "testkey.pem", |
| 1855 | } |
| 1856 | android_app_certificate { |
| 1857 | name: "myapex.certificate.override", |
| 1858 | certificate: "testkey.override", |
| 1859 | }`) |
| 1860 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1861 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1862 | if actual := rule.Args["certificates"]; actual != expected { |
| 1863 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1864 | } |
| 1865 | }) |
| 1866 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 1867 | ctx, _ := testApex(t, ` |
| 1868 | apex { |
| 1869 | name: "myapex", |
| 1870 | key: "myapex.key", |
| 1871 | certificate: "testkey", |
| 1872 | } |
| 1873 | apex_key { |
| 1874 | name: "myapex.key", |
| 1875 | public_key: "testkey.avbpubkey", |
| 1876 | private_key: "testkey.pem", |
| 1877 | }`) |
| 1878 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1879 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 1880 | if actual := rule.Args["certificates"]; actual != expected { |
| 1881 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1882 | } |
| 1883 | }) |
| 1884 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 1885 | ctx, _ := testApex(t, ` |
| 1886 | apex { |
| 1887 | name: "myapex_keytest", |
| 1888 | key: "myapex.key", |
| 1889 | file_contexts: ":myapex-file_contexts", |
| 1890 | certificate: "testkey", |
| 1891 | } |
| 1892 | apex_key { |
| 1893 | name: "myapex.key", |
| 1894 | public_key: "testkey.avbpubkey", |
| 1895 | private_key: "testkey.pem", |
| 1896 | } |
| 1897 | android_app_certificate { |
| 1898 | name: "myapex.certificate.override", |
| 1899 | certificate: "testkey.override", |
| 1900 | }`) |
| 1901 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1902 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1903 | if actual := rule.Args["certificates"]; actual != expected { |
| 1904 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1905 | } |
| 1906 | }) |
| 1907 | } |
| 1908 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1909 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1910 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1911 | apex { |
| 1912 | name: "myapex", |
| 1913 | key: "myapex.key", |
Jooyung Han | 68e511e | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1914 | native_shared_libs: ["mylib", "mylib2"], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | apex { |
| 1918 | name: "otherapex", |
| 1919 | key: "myapex.key", |
Jooyung Han | 68e511e | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1920 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | 61c4154 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1921 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | apex_key { |
| 1925 | name: "myapex.key", |
| 1926 | public_key: "testkey.avbpubkey", |
| 1927 | private_key: "testkey.pem", |
| 1928 | } |
| 1929 | |
| 1930 | cc_library { |
| 1931 | name: "mylib", |
| 1932 | srcs: ["mylib.cpp"], |
| 1933 | system_shared_libs: [], |
| 1934 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1935 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1936 | "myapex", |
| 1937 | "otherapex", |
| 1938 | ], |
Jooyung Han | c3e9263 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 1939 | recovery_available: true, |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1940 | } |
Jooyung Han | 68e511e | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1941 | cc_library { |
| 1942 | name: "mylib2", |
| 1943 | srcs: ["mylib.cpp"], |
| 1944 | system_shared_libs: [], |
| 1945 | stl: "none", |
| 1946 | apex_available: [ |
| 1947 | "myapex", |
| 1948 | "otherapex", |
| 1949 | ], |
| 1950 | use_apex_name_macro: true, |
| 1951 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1952 | `) |
| 1953 | |
Jooyung Han | 68e511e | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1954 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1955 | 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] | 1956 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7406660 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1957 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
Jooyung Han | 68e511e | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1958 | |
Jooyung Han | 61c4154 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1959 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Jooyung Han | 68e511e | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1960 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 1961 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 61c4154 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1962 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1963 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | 68e511e | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1964 | |
Jooyung Han | 61c4154 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1965 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Jooyung Han | 68e511e | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1966 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 1967 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 61c4154 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1968 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1969 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1970 | |
Jooyung Han | 68e511e | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1971 | // When cc_library sets use_apex_name_macro: true |
| 1972 | // apex variants define additional macro to distinguish which apex variant it is built for |
| 1973 | |
| 1974 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 1975 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1976 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 1977 | |
| 1978 | // APEX variant has __ANDROID_APEX__ defined |
| 1979 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1980 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1981 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1982 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1983 | |
Jooyung Han | 68e511e | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1984 | // APEX variant has __ANDROID_APEX__ defined |
| 1985 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 1986 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1987 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1988 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | c3e9263 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 1989 | |
| 1990 | // recovery variant does not set __ANDROID_SDK_VERSION__ |
| 1991 | mylibCFlags = ctx.ModuleForTests("mylib", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1992 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 1993 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1994 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1995 | |
| 1996 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1997 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1998 | apex { |
| 1999 | name: "myapex", |
| 2000 | key: "myapex.key", |
| 2001 | native_shared_libs: ["mylib"], |
| 2002 | } |
| 2003 | |
| 2004 | apex_key { |
| 2005 | name: "myapex.key", |
| 2006 | public_key: "testkey.avbpubkey", |
| 2007 | private_key: "testkey.pem", |
| 2008 | } |
| 2009 | |
| 2010 | cc_library_headers { |
| 2011 | name: "mylib_headers", |
| 2012 | export_include_dirs: ["my_include"], |
| 2013 | system_shared_libs: [], |
| 2014 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2015 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | cc_library { |
| 2019 | name: "mylib", |
| 2020 | srcs: ["mylib.cpp"], |
| 2021 | system_shared_libs: [], |
| 2022 | stl: "none", |
| 2023 | header_libs: ["mylib_headers"], |
| 2024 | export_header_lib_headers: ["mylib_headers"], |
| 2025 | stubs: { |
| 2026 | versions: ["1", "2", "3"], |
| 2027 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2028 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | cc_library { |
| 2032 | name: "otherlib", |
| 2033 | srcs: ["mylib.cpp"], |
| 2034 | system_shared_libs: [], |
| 2035 | stl: "none", |
| 2036 | shared_libs: ["mylib"], |
| 2037 | } |
| 2038 | `) |
| 2039 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2040 | 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] | 2041 | |
| 2042 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 2043 | ensureContains(t, cFlags, "-Imy_include") |
| 2044 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2045 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2046 | type fileInApex struct { |
| 2047 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2048 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2049 | isLink bool |
| 2050 | } |
| 2051 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2052 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2053 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2054 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2055 | copyCmds := apexRule.Args["copy_commands"] |
| 2056 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2057 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2058 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 2059 | cmd = strings.TrimSpace(cmd) |
| 2060 | if cmd == "" { |
| 2061 | continue |
| 2062 | } |
| 2063 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2064 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2065 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2066 | switch terms[0] { |
| 2067 | case "mkdir": |
| 2068 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2069 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2070 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 2071 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2072 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2073 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2074 | isLink = false |
| 2075 | case "ln": |
| 2076 | if len(terms) != 3 && len(terms) != 4 { |
| 2077 | // ln LINK TARGET or ln -s LINK TARGET |
| 2078 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 2079 | } |
| 2080 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2081 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2082 | isLink = true |
| 2083 | default: |
| 2084 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 2085 | } |
| 2086 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2087 | index := strings.Index(dst, imageApexDir) |
| 2088 | if index == -1 { |
| 2089 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 2090 | } |
| 2091 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2092 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2093 | } |
| 2094 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2095 | return ret |
| 2096 | } |
| 2097 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2098 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 2099 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2100 | var failed bool |
| 2101 | var surplus []string |
| 2102 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2103 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | 8d8906c | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2104 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2105 | for _, expected := range files { |
| 2106 | if matched, _ := path.Match(expected, file.path); matched { |
| 2107 | filesMatched[expected] = true |
Jooyung Han | 8d8906c | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2108 | mactchFound = true |
| 2109 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2110 | } |
| 2111 | } |
Jooyung Han | 8d8906c | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2112 | if !mactchFound { |
| 2113 | surplus = append(surplus, file.path) |
| 2114 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2115 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2116 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2117 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2118 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2119 | t.Log("surplus files", surplus) |
| 2120 | failed = true |
| 2121 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2122 | |
| 2123 | if len(files) > len(filesMatched) { |
| 2124 | var missing []string |
| 2125 | for _, expected := range files { |
| 2126 | if !filesMatched[expected] { |
| 2127 | missing = append(missing, expected) |
| 2128 | } |
| 2129 | } |
| 2130 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2131 | t.Log("missing files", missing) |
| 2132 | failed = true |
| 2133 | } |
| 2134 | if failed { |
| 2135 | t.Fail() |
| 2136 | } |
| 2137 | } |
| 2138 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2139 | func TestVndkApexCurrent(t *testing.T) { |
| 2140 | ctx, _ := testApex(t, ` |
| 2141 | apex_vndk { |
| 2142 | name: "myapex", |
| 2143 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | apex_key { |
| 2147 | name: "myapex.key", |
| 2148 | public_key: "testkey.avbpubkey", |
| 2149 | private_key: "testkey.pem", |
| 2150 | } |
| 2151 | |
| 2152 | cc_library { |
| 2153 | name: "libvndk", |
| 2154 | srcs: ["mylib.cpp"], |
| 2155 | vendor_available: true, |
| 2156 | vndk: { |
| 2157 | enabled: true, |
| 2158 | }, |
| 2159 | system_shared_libs: [], |
| 2160 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2161 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | cc_library { |
| 2165 | name: "libvndksp", |
| 2166 | srcs: ["mylib.cpp"], |
| 2167 | vendor_available: true, |
| 2168 | vndk: { |
| 2169 | enabled: true, |
| 2170 | support_system_process: true, |
| 2171 | }, |
| 2172 | system_shared_libs: [], |
| 2173 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2174 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2175 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2176 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2177 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2178 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2179 | "lib/libvndk.so", |
| 2180 | "lib/libvndksp.so", |
Jooyung Han | 8d8906c | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2181 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2182 | "lib64/libvndk.so", |
| 2183 | "lib64/libvndksp.so", |
Jooyung Han | 8d8906c | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2184 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2185 | "etc/llndk.libraries.VER.txt", |
| 2186 | "etc/vndkcore.libraries.VER.txt", |
| 2187 | "etc/vndksp.libraries.VER.txt", |
| 2188 | "etc/vndkprivate.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2189 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 2193 | ctx, _ := testApex(t, ` |
| 2194 | apex_vndk { |
| 2195 | name: "myapex", |
| 2196 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | apex_key { |
| 2200 | name: "myapex.key", |
| 2201 | public_key: "testkey.avbpubkey", |
| 2202 | private_key: "testkey.pem", |
| 2203 | } |
| 2204 | |
| 2205 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2206 | name: "libvndk", |
| 2207 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2208 | vendor_available: true, |
| 2209 | vndk: { |
| 2210 | enabled: true, |
| 2211 | }, |
| 2212 | system_shared_libs: [], |
| 2213 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2214 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2215 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2216 | |
| 2217 | cc_prebuilt_library_shared { |
| 2218 | name: "libvndk.arm", |
| 2219 | srcs: ["libvndk.arm.so"], |
| 2220 | vendor_available: true, |
| 2221 | vndk: { |
| 2222 | enabled: true, |
| 2223 | }, |
| 2224 | enabled: false, |
| 2225 | arch: { |
| 2226 | arm: { |
| 2227 | enabled: true, |
| 2228 | }, |
| 2229 | }, |
| 2230 | system_shared_libs: [], |
| 2231 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2232 | apex_available: [ "myapex" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2233 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2234 | `+vndkLibrariesTxtFiles("current"), |
| 2235 | withFiles(map[string][]byte{ |
| 2236 | "libvndk.so": nil, |
| 2237 | "libvndk.arm.so": nil, |
| 2238 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2239 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2240 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2241 | "lib/libvndk.so", |
| 2242 | "lib/libvndk.arm.so", |
| 2243 | "lib64/libvndk.so", |
Jooyung Han | 8d8906c | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2244 | "lib/libc++.so", |
| 2245 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2246 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2247 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2248 | } |
| 2249 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2250 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 2251 | for _, v := range vers { |
| 2252 | if v == "current" { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 2253 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2254 | result += ` |
| 2255 | vndk_libraries_txt { |
| 2256 | name: "` + txt + `.libraries.txt", |
| 2257 | } |
| 2258 | ` |
| 2259 | } |
| 2260 | } else { |
| 2261 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
| 2262 | result += ` |
| 2263 | prebuilt_etc { |
| 2264 | name: "` + txt + `.libraries.` + v + `.txt", |
| 2265 | src: "dummy.txt", |
| 2266 | } |
| 2267 | ` |
| 2268 | } |
| 2269 | } |
| 2270 | } |
| 2271 | return |
| 2272 | } |
| 2273 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2274 | func TestVndkApexVersion(t *testing.T) { |
| 2275 | ctx, _ := testApex(t, ` |
| 2276 | apex_vndk { |
| 2277 | name: "myapex_v27", |
| 2278 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2279 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2280 | vndk_version: "27", |
| 2281 | } |
| 2282 | |
| 2283 | apex_key { |
| 2284 | name: "myapex.key", |
| 2285 | public_key: "testkey.avbpubkey", |
| 2286 | private_key: "testkey.pem", |
| 2287 | } |
| 2288 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2289 | vndk_prebuilt_shared { |
| 2290 | name: "libvndk27", |
| 2291 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2292 | vendor_available: true, |
| 2293 | vndk: { |
| 2294 | enabled: true, |
| 2295 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2296 | target_arch: "arm64", |
| 2297 | arch: { |
| 2298 | arm: { |
| 2299 | srcs: ["libvndk27_arm.so"], |
| 2300 | }, |
| 2301 | arm64: { |
| 2302 | srcs: ["libvndk27_arm64.so"], |
| 2303 | }, |
| 2304 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2305 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | vndk_prebuilt_shared { |
| 2309 | name: "libvndk27", |
| 2310 | version: "27", |
| 2311 | vendor_available: true, |
| 2312 | vndk: { |
| 2313 | enabled: true, |
| 2314 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2315 | target_arch: "x86_64", |
| 2316 | arch: { |
| 2317 | x86: { |
| 2318 | srcs: ["libvndk27_x86.so"], |
| 2319 | }, |
| 2320 | x86_64: { |
| 2321 | srcs: ["libvndk27_x86_64.so"], |
| 2322 | }, |
| 2323 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2324 | } |
| 2325 | `+vndkLibrariesTxtFiles("27"), |
| 2326 | withFiles(map[string][]byte{ |
| 2327 | "libvndk27_arm.so": nil, |
| 2328 | "libvndk27_arm64.so": nil, |
| 2329 | "libvndk27_x86.so": nil, |
| 2330 | "libvndk27_x86_64.so": nil, |
| 2331 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2332 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2333 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2334 | "lib/libvndk27_arm.so", |
| 2335 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2336 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2337 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { |
| 2341 | testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, ` |
| 2342 | apex_vndk { |
| 2343 | name: "myapex_v27", |
| 2344 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2345 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2346 | vndk_version: "27", |
| 2347 | } |
| 2348 | apex_vndk { |
| 2349 | name: "myapex_v27_other", |
| 2350 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2351 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2352 | vndk_version: "27", |
| 2353 | } |
| 2354 | |
| 2355 | apex_key { |
| 2356 | name: "myapex.key", |
| 2357 | public_key: "testkey.avbpubkey", |
| 2358 | private_key: "testkey.pem", |
| 2359 | } |
| 2360 | |
| 2361 | cc_library { |
| 2362 | name: "libvndk", |
| 2363 | srcs: ["mylib.cpp"], |
| 2364 | vendor_available: true, |
| 2365 | vndk: { |
| 2366 | enabled: true, |
| 2367 | }, |
| 2368 | system_shared_libs: [], |
| 2369 | stl: "none", |
| 2370 | } |
| 2371 | |
| 2372 | vndk_prebuilt_shared { |
| 2373 | name: "libvndk", |
| 2374 | version: "27", |
| 2375 | vendor_available: true, |
| 2376 | vndk: { |
| 2377 | enabled: true, |
| 2378 | }, |
| 2379 | srcs: ["libvndk.so"], |
| 2380 | } |
| 2381 | `, withFiles(map[string][]byte{ |
| 2382 | "libvndk.so": nil, |
| 2383 | })) |
| 2384 | } |
| 2385 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2386 | func TestVndkApexNameRule(t *testing.T) { |
| 2387 | ctx, _ := testApex(t, ` |
| 2388 | apex_vndk { |
| 2389 | name: "myapex", |
| 2390 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2391 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2392 | } |
| 2393 | apex_vndk { |
| 2394 | name: "myapex_v28", |
| 2395 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2396 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2397 | vndk_version: "28", |
| 2398 | } |
| 2399 | apex_key { |
| 2400 | name: "myapex.key", |
| 2401 | public_key: "testkey.avbpubkey", |
| 2402 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2403 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2404 | |
| 2405 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2406 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2407 | actual := proptools.String(bundle.properties.Apex_name) |
| 2408 | if !reflect.DeepEqual(actual, expected) { |
| 2409 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | assertApexName("com.android.vndk.vVER", "myapex") |
| 2414 | assertApexName("com.android.vndk.v28", "myapex_v28") |
| 2415 | } |
| 2416 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2417 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 2418 | ctx, _ := testApex(t, ` |
| 2419 | apex_vndk { |
| 2420 | name: "myapex", |
| 2421 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2422 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | apex_key { |
| 2426 | name: "myapex.key", |
| 2427 | public_key: "testkey.avbpubkey", |
| 2428 | private_key: "testkey.pem", |
| 2429 | } |
| 2430 | |
| 2431 | cc_library { |
| 2432 | name: "libvndk", |
| 2433 | srcs: ["mylib.cpp"], |
| 2434 | vendor_available: true, |
| 2435 | native_bridge_supported: true, |
| 2436 | host_supported: true, |
| 2437 | vndk: { |
| 2438 | enabled: true, |
| 2439 | }, |
| 2440 | system_shared_libs: [], |
| 2441 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2442 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2443 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2444 | `+vndkLibrariesTxtFiles("current"), |
| 2445 | withTargets(map[android.OsType][]android.Target{ |
| 2446 | android.Android: []android.Target{ |
| 2447 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 2448 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 2449 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"}, |
| 2450 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"}, |
| 2451 | }, |
| 2452 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2453 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2454 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2455 | "lib/libvndk.so", |
| 2456 | "lib64/libvndk.so", |
Jooyung Han | 8d8906c | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2457 | "lib/libc++.so", |
| 2458 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2459 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2460 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
| 2464 | testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
| 2465 | apex_vndk { |
| 2466 | name: "myapex", |
| 2467 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2468 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2469 | native_bridge_supported: true, |
| 2470 | } |
| 2471 | |
| 2472 | apex_key { |
| 2473 | name: "myapex.key", |
| 2474 | public_key: "testkey.avbpubkey", |
| 2475 | private_key: "testkey.pem", |
| 2476 | } |
| 2477 | |
| 2478 | cc_library { |
| 2479 | name: "libvndk", |
| 2480 | srcs: ["mylib.cpp"], |
| 2481 | vendor_available: true, |
| 2482 | native_bridge_supported: true, |
| 2483 | host_supported: true, |
| 2484 | vndk: { |
| 2485 | enabled: true, |
| 2486 | }, |
| 2487 | system_shared_libs: [], |
| 2488 | stl: "none", |
| 2489 | } |
| 2490 | `) |
| 2491 | } |
| 2492 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2493 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2494 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2495 | apex_vndk { |
| 2496 | name: "myapex_v27", |
| 2497 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2498 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2499 | vndk_version: "27", |
| 2500 | } |
| 2501 | |
| 2502 | apex_key { |
| 2503 | name: "myapex.key", |
| 2504 | public_key: "testkey.avbpubkey", |
| 2505 | private_key: "testkey.pem", |
| 2506 | } |
| 2507 | |
| 2508 | vndk_prebuilt_shared { |
| 2509 | name: "libvndk27", |
| 2510 | version: "27", |
| 2511 | target_arch: "arm", |
| 2512 | vendor_available: true, |
| 2513 | vndk: { |
| 2514 | enabled: true, |
| 2515 | }, |
| 2516 | arch: { |
| 2517 | arm: { |
| 2518 | srcs: ["libvndk27.so"], |
| 2519 | } |
| 2520 | }, |
| 2521 | } |
| 2522 | |
| 2523 | vndk_prebuilt_shared { |
| 2524 | name: "libvndk27", |
| 2525 | version: "27", |
| 2526 | target_arch: "arm", |
| 2527 | binder32bit: true, |
| 2528 | vendor_available: true, |
| 2529 | vndk: { |
| 2530 | enabled: true, |
| 2531 | }, |
| 2532 | arch: { |
| 2533 | arm: { |
| 2534 | srcs: ["libvndk27binder32.so"], |
| 2535 | } |
| 2536 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2537 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2538 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2539 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2540 | withFiles(map[string][]byte{ |
| 2541 | "libvndk27.so": nil, |
| 2542 | "libvndk27binder32.so": nil, |
| 2543 | }), |
| 2544 | withBinder32bit, |
| 2545 | withTargets(map[android.OsType][]android.Target{ |
| 2546 | android.Android: []android.Target{ |
| 2547 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 2548 | }, |
| 2549 | }), |
| 2550 | ) |
| 2551 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2552 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2553 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2554 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2555 | }) |
| 2556 | } |
| 2557 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2558 | func TestDependenciesInApexManifest(t *testing.T) { |
| 2559 | ctx, _ := testApex(t, ` |
| 2560 | apex { |
| 2561 | name: "myapex_nodep", |
| 2562 | key: "myapex.key", |
| 2563 | native_shared_libs: ["lib_nodep"], |
| 2564 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2565 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | apex { |
| 2569 | name: "myapex_dep", |
| 2570 | key: "myapex.key", |
| 2571 | native_shared_libs: ["lib_dep"], |
| 2572 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2573 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | apex { |
| 2577 | name: "myapex_provider", |
| 2578 | key: "myapex.key", |
| 2579 | native_shared_libs: ["libfoo"], |
| 2580 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2581 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | apex { |
| 2585 | name: "myapex_selfcontained", |
| 2586 | key: "myapex.key", |
| 2587 | native_shared_libs: ["lib_dep", "libfoo"], |
| 2588 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2589 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | apex_key { |
| 2593 | name: "myapex.key", |
| 2594 | public_key: "testkey.avbpubkey", |
| 2595 | private_key: "testkey.pem", |
| 2596 | } |
| 2597 | |
| 2598 | cc_library { |
| 2599 | name: "lib_nodep", |
| 2600 | srcs: ["mylib.cpp"], |
| 2601 | system_shared_libs: [], |
| 2602 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2603 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | cc_library { |
| 2607 | name: "lib_dep", |
| 2608 | srcs: ["mylib.cpp"], |
| 2609 | shared_libs: ["libfoo"], |
| 2610 | system_shared_libs: [], |
| 2611 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2612 | apex_available: [ |
| 2613 | "myapex_dep", |
| 2614 | "myapex_provider", |
| 2615 | "myapex_selfcontained", |
| 2616 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | cc_library { |
| 2620 | name: "libfoo", |
| 2621 | srcs: ["mytest.cpp"], |
| 2622 | stubs: { |
| 2623 | versions: ["1"], |
| 2624 | }, |
| 2625 | system_shared_libs: [], |
| 2626 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2627 | apex_available: [ |
| 2628 | "myapex_provider", |
| 2629 | "myapex_selfcontained", |
| 2630 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2631 | } |
| 2632 | `) |
| 2633 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2634 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2635 | var provideNativeLibs, requireNativeLibs []string |
| 2636 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2637 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2638 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2639 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2640 | ensureListEmpty(t, provideNativeLibs) |
| 2641 | ensureListEmpty(t, requireNativeLibs) |
| 2642 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2643 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2644 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2645 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2646 | ensureListEmpty(t, provideNativeLibs) |
| 2647 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 2648 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2649 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2650 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2651 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2652 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 2653 | ensureListEmpty(t, requireNativeLibs) |
| 2654 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2655 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2656 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2657 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2658 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 2659 | ensureListEmpty(t, requireNativeLibs) |
| 2660 | } |
| 2661 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2662 | func TestApexName(t *testing.T) { |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2663 | ctx, config := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2664 | apex { |
| 2665 | name: "myapex", |
| 2666 | key: "myapex.key", |
| 2667 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2668 | native_shared_libs: ["mylib"], |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | apex_key { |
| 2672 | name: "myapex.key", |
| 2673 | public_key: "testkey.avbpubkey", |
| 2674 | private_key: "testkey.pem", |
| 2675 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2676 | |
| 2677 | cc_library { |
| 2678 | name: "mylib", |
| 2679 | srcs: ["mylib.cpp"], |
| 2680 | system_shared_libs: [], |
| 2681 | stl: "none", |
| 2682 | apex_available: [ |
| 2683 | "//apex_available:platform", |
| 2684 | "myapex", |
| 2685 | ], |
| 2686 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2687 | `) |
| 2688 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2689 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2690 | apexManifestRule := module.Rule("apexManifestRule") |
| 2691 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 2692 | apexRule := module.Rule("apexRule") |
| 2693 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2694 | |
| 2695 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2696 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2697 | name := apexBundle.BaseModuleName() |
| 2698 | prefix := "TARGET_" |
| 2699 | var builder strings.Builder |
| 2700 | data.Custom(&builder, name, prefix, "", data) |
| 2701 | androidMk := builder.String() |
| 2702 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 2703 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2704 | } |
| 2705 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2706 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2707 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2708 | apex { |
| 2709 | name: "myapex", |
| 2710 | key: "myapex.key", |
| 2711 | native_shared_libs: ["mylib_common"], |
| 2712 | } |
| 2713 | |
| 2714 | apex_key { |
| 2715 | name: "myapex.key", |
| 2716 | public_key: "testkey.avbpubkey", |
| 2717 | private_key: "testkey.pem", |
| 2718 | } |
| 2719 | |
| 2720 | cc_library { |
| 2721 | name: "mylib_common", |
| 2722 | srcs: ["mylib.cpp"], |
| 2723 | system_shared_libs: [], |
| 2724 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2725 | apex_available: [ |
| 2726 | "//apex_available:platform", |
| 2727 | "myapex", |
| 2728 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2729 | } |
| 2730 | `) |
| 2731 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2732 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2733 | apexRule := module.Rule("apexRule") |
| 2734 | copyCmds := apexRule.Args["copy_commands"] |
| 2735 | |
| 2736 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 2737 | t.Log("Apex was a test apex!") |
| 2738 | t.Fail() |
| 2739 | } |
| 2740 | // Ensure that main rule creates an output |
| 2741 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2742 | |
| 2743 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2744 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2745 | |
| 2746 | // Ensure that both direct and indirect deps are copied into apex |
| 2747 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 2748 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2749 | // Ensure that the platform variant ends with _shared |
| 2750 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2751 | |
| 2752 | if !android.InAnyApex("mylib_common") { |
| 2753 | t.Log("Found mylib_common not in any apex!") |
| 2754 | t.Fail() |
| 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | func TestTestApex(t *testing.T) { |
| 2759 | if android.InAnyApex("mylib_common_test") { |
| 2760 | 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!") |
| 2761 | } |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2762 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2763 | apex_test { |
| 2764 | name: "myapex", |
| 2765 | key: "myapex.key", |
| 2766 | native_shared_libs: ["mylib_common_test"], |
| 2767 | } |
| 2768 | |
| 2769 | apex_key { |
| 2770 | name: "myapex.key", |
| 2771 | public_key: "testkey.avbpubkey", |
| 2772 | private_key: "testkey.pem", |
| 2773 | } |
| 2774 | |
| 2775 | cc_library { |
| 2776 | name: "mylib_common_test", |
| 2777 | srcs: ["mylib.cpp"], |
| 2778 | system_shared_libs: [], |
| 2779 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2780 | // TODO: remove //apex_available:platform |
| 2781 | apex_available: [ |
| 2782 | "//apex_available:platform", |
| 2783 | "myapex", |
| 2784 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2785 | } |
| 2786 | `) |
| 2787 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2788 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2789 | apexRule := module.Rule("apexRule") |
| 2790 | copyCmds := apexRule.Args["copy_commands"] |
| 2791 | |
| 2792 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 2793 | t.Log("Apex was not a test apex!") |
| 2794 | t.Fail() |
| 2795 | } |
| 2796 | // Ensure that main rule creates an output |
| 2797 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2798 | |
| 2799 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2800 | 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] | 2801 | |
| 2802 | // Ensure that both direct and indirect deps are copied into apex |
| 2803 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 2804 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2805 | // Ensure that the platform variant ends with _shared |
| 2806 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2807 | } |
| 2808 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2809 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2810 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2811 | apex { |
| 2812 | name: "myapex", |
| 2813 | key: "myapex.key", |
| 2814 | multilib: { |
| 2815 | first: { |
| 2816 | native_shared_libs: ["mylib_common"], |
| 2817 | } |
| 2818 | }, |
| 2819 | target: { |
| 2820 | android: { |
| 2821 | multilib: { |
| 2822 | first: { |
| 2823 | native_shared_libs: ["mylib"], |
| 2824 | } |
| 2825 | } |
| 2826 | }, |
| 2827 | host: { |
| 2828 | multilib: { |
| 2829 | first: { |
| 2830 | native_shared_libs: ["mylib2"], |
| 2831 | } |
| 2832 | } |
| 2833 | } |
| 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | apex_key { |
| 2838 | name: "myapex.key", |
| 2839 | public_key: "testkey.avbpubkey", |
| 2840 | private_key: "testkey.pem", |
| 2841 | } |
| 2842 | |
| 2843 | cc_library { |
| 2844 | name: "mylib", |
| 2845 | srcs: ["mylib.cpp"], |
| 2846 | system_shared_libs: [], |
| 2847 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2848 | // TODO: remove //apex_available:platform |
| 2849 | apex_available: [ |
| 2850 | "//apex_available:platform", |
| 2851 | "myapex", |
| 2852 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | cc_library { |
| 2856 | name: "mylib_common", |
| 2857 | srcs: ["mylib.cpp"], |
| 2858 | system_shared_libs: [], |
| 2859 | stl: "none", |
| 2860 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2861 | // TODO: remove //apex_available:platform |
| 2862 | apex_available: [ |
| 2863 | "//apex_available:platform", |
| 2864 | "myapex", |
| 2865 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | cc_library { |
| 2869 | name: "mylib2", |
| 2870 | srcs: ["mylib.cpp"], |
| 2871 | system_shared_libs: [], |
| 2872 | stl: "none", |
| 2873 | compile_multilib: "first", |
| 2874 | } |
| 2875 | `) |
| 2876 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2877 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2878 | copyCmds := apexRule.Args["copy_commands"] |
| 2879 | |
| 2880 | // Ensure that main rule creates an output |
| 2881 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2882 | |
| 2883 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2884 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 2885 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
| 2886 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2887 | |
| 2888 | // Ensure that both direct and indirect deps are copied into apex |
| 2889 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 2890 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 2891 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 2892 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2893 | // Ensure that the platform variant ends with _shared |
| 2894 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 2895 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 2896 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2897 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2898 | |
| 2899 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2900 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2901 | apex { |
| 2902 | name: "myapex", |
| 2903 | key: "myapex.key", |
| 2904 | binaries: ["myscript"], |
| 2905 | } |
| 2906 | |
| 2907 | apex_key { |
| 2908 | name: "myapex.key", |
| 2909 | public_key: "testkey.avbpubkey", |
| 2910 | private_key: "testkey.pem", |
| 2911 | } |
| 2912 | |
| 2913 | sh_binary { |
| 2914 | name: "myscript", |
| 2915 | src: "mylib.cpp", |
| 2916 | filename: "myscript.sh", |
| 2917 | sub_dir: "script", |
| 2918 | } |
| 2919 | `) |
| 2920 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2921 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2922 | copyCmds := apexRule.Args["copy_commands"] |
| 2923 | |
| 2924 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 2925 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2926 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2927 | func TestApexInVariousPartition(t *testing.T) { |
| 2928 | testcases := []struct { |
| 2929 | propName, parition, flattenedPartition string |
| 2930 | }{ |
| 2931 | {"", "system", "system_ext"}, |
| 2932 | {"product_specific: true", "product", "product"}, |
| 2933 | {"soc_specific: true", "vendor", "vendor"}, |
| 2934 | {"proprietary: true", "vendor", "vendor"}, |
| 2935 | {"vendor: true", "vendor", "vendor"}, |
| 2936 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 2937 | } |
| 2938 | for _, tc := range testcases { |
| 2939 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 2940 | ctx, _ := testApex(t, ` |
| 2941 | apex { |
| 2942 | name: "myapex", |
| 2943 | key: "myapex.key", |
| 2944 | `+tc.propName+` |
| 2945 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2946 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2947 | apex_key { |
| 2948 | name: "myapex.key", |
| 2949 | public_key: "testkey.avbpubkey", |
| 2950 | private_key: "testkey.pem", |
| 2951 | } |
| 2952 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2953 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2954 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2955 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 2956 | actual := apex.installDir.String() |
| 2957 | if actual != expected { |
| 2958 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 2959 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2960 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2961 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 2962 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 2963 | actual = flattened.installDir.String() |
| 2964 | if actual != expected { |
| 2965 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 2966 | } |
| 2967 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2968 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2969 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2970 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2971 | func TestFileContexts(t *testing.T) { |
| 2972 | ctx, _ := testApex(t, ` |
| 2973 | apex { |
| 2974 | name: "myapex", |
| 2975 | key: "myapex.key", |
| 2976 | } |
| 2977 | |
| 2978 | apex_key { |
| 2979 | name: "myapex.key", |
| 2980 | public_key: "testkey.avbpubkey", |
| 2981 | private_key: "testkey.pem", |
| 2982 | } |
| 2983 | `) |
| 2984 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2985 | apexRule := module.Rule("apexRule") |
| 2986 | actual := apexRule.Args["file_contexts"] |
| 2987 | expected := "system/sepolicy/apex/myapex-file_contexts" |
| 2988 | if actual != expected { |
| 2989 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2990 | } |
| 2991 | |
| 2992 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
| 2993 | apex { |
| 2994 | name: "myapex", |
| 2995 | key: "myapex.key", |
| 2996 | file_contexts: "my_own_file_contexts", |
| 2997 | } |
| 2998 | |
| 2999 | apex_key { |
| 3000 | name: "myapex.key", |
| 3001 | public_key: "testkey.avbpubkey", |
| 3002 | private_key: "testkey.pem", |
| 3003 | } |
| 3004 | `, withFiles(map[string][]byte{ |
| 3005 | "my_own_file_contexts": nil, |
| 3006 | })) |
| 3007 | |
| 3008 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
| 3009 | apex { |
| 3010 | name: "myapex", |
| 3011 | key: "myapex.key", |
| 3012 | product_specific: true, |
| 3013 | file_contexts: "product_specific_file_contexts", |
| 3014 | } |
| 3015 | |
| 3016 | apex_key { |
| 3017 | name: "myapex.key", |
| 3018 | public_key: "testkey.avbpubkey", |
| 3019 | private_key: "testkey.pem", |
| 3020 | } |
| 3021 | `) |
| 3022 | |
| 3023 | ctx, _ = testApex(t, ` |
| 3024 | apex { |
| 3025 | name: "myapex", |
| 3026 | key: "myapex.key", |
| 3027 | product_specific: true, |
| 3028 | file_contexts: "product_specific_file_contexts", |
| 3029 | } |
| 3030 | |
| 3031 | apex_key { |
| 3032 | name: "myapex.key", |
| 3033 | public_key: "testkey.avbpubkey", |
| 3034 | private_key: "testkey.pem", |
| 3035 | } |
| 3036 | `, withFiles(map[string][]byte{ |
| 3037 | "product_specific_file_contexts": nil, |
| 3038 | })) |
| 3039 | module = ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3040 | apexRule = module.Rule("apexRule") |
| 3041 | actual = apexRule.Args["file_contexts"] |
| 3042 | expected = "product_specific_file_contexts" |
| 3043 | if actual != expected { |
| 3044 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 3045 | } |
| 3046 | |
| 3047 | ctx, _ = testApex(t, ` |
| 3048 | apex { |
| 3049 | name: "myapex", |
| 3050 | key: "myapex.key", |
| 3051 | product_specific: true, |
| 3052 | file_contexts: ":my-file-contexts", |
| 3053 | } |
| 3054 | |
| 3055 | apex_key { |
| 3056 | name: "myapex.key", |
| 3057 | public_key: "testkey.avbpubkey", |
| 3058 | private_key: "testkey.pem", |
| 3059 | } |
| 3060 | |
| 3061 | filegroup { |
| 3062 | name: "my-file-contexts", |
| 3063 | srcs: ["product_specific_file_contexts"], |
| 3064 | } |
| 3065 | `, withFiles(map[string][]byte{ |
| 3066 | "product_specific_file_contexts": nil, |
| 3067 | })) |
| 3068 | module = ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3069 | apexRule = module.Rule("apexRule") |
| 3070 | actual = apexRule.Args["file_contexts"] |
| 3071 | expected = "product_specific_file_contexts" |
| 3072 | if actual != expected { |
| 3073 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 3074 | } |
| 3075 | } |
| 3076 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3077 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3078 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3079 | apex_key { |
| 3080 | name: "myapex.key", |
| 3081 | public_key: ":my.avbpubkey", |
| 3082 | private_key: ":my.pem", |
| 3083 | product_specific: true, |
| 3084 | } |
| 3085 | |
| 3086 | filegroup { |
| 3087 | name: "my.avbpubkey", |
| 3088 | srcs: ["testkey2.avbpubkey"], |
| 3089 | } |
| 3090 | |
| 3091 | filegroup { |
| 3092 | name: "my.pem", |
| 3093 | srcs: ["testkey2.pem"], |
| 3094 | } |
| 3095 | `) |
| 3096 | |
| 3097 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 3098 | expected_pubkey := "testkey2.avbpubkey" |
| 3099 | actual_pubkey := apex_key.public_key_file.String() |
| 3100 | if actual_pubkey != expected_pubkey { |
| 3101 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 3102 | } |
| 3103 | expected_privkey := "testkey2.pem" |
| 3104 | actual_privkey := apex_key.private_key_file.String() |
| 3105 | if actual_privkey != expected_privkey { |
| 3106 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 3107 | } |
| 3108 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3109 | |
| 3110 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3111 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3112 | prebuilt_apex { |
| 3113 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 3114 | arch: { |
| 3115 | arm64: { |
| 3116 | src: "myapex-arm64.apex", |
| 3117 | }, |
| 3118 | arm: { |
| 3119 | src: "myapex-arm.apex", |
| 3120 | }, |
| 3121 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3122 | } |
| 3123 | `) |
| 3124 | |
| 3125 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 3126 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 3127 | expectedInput := "myapex-arm64.apex" |
| 3128 | if prebuilt.inputApex.String() != expectedInput { |
| 3129 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 3130 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3131 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 3132 | |
| 3133 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3134 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 3135 | prebuilt_apex { |
| 3136 | name: "myapex", |
| 3137 | src: "myapex-arm.apex", |
| 3138 | filename: "notmyapex.apex", |
| 3139 | } |
| 3140 | `) |
| 3141 | |
| 3142 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 3143 | |
| 3144 | expected := "notmyapex.apex" |
| 3145 | if p.installFilename != expected { |
| 3146 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 3147 | } |
| 3148 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 3149 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3150 | func TestPrebuiltOverrides(t *testing.T) { |
| 3151 | ctx, config := testApex(t, ` |
| 3152 | prebuilt_apex { |
| 3153 | name: "myapex.prebuilt", |
| 3154 | src: "myapex-arm.apex", |
| 3155 | overrides: [ |
| 3156 | "myapex", |
| 3157 | ], |
| 3158 | } |
| 3159 | `) |
| 3160 | |
| 3161 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 3162 | |
| 3163 | expected := []string{"myapex"} |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 3164 | actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3165 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 3166 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3167 | } |
| 3168 | } |
| 3169 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3170 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3171 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3172 | apex_test { |
| 3173 | name: "myapex", |
| 3174 | key: "myapex.key", |
| 3175 | tests: [ |
| 3176 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3177 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3178 | ], |
| 3179 | } |
| 3180 | |
| 3181 | apex_key { |
| 3182 | name: "myapex.key", |
| 3183 | public_key: "testkey.avbpubkey", |
| 3184 | private_key: "testkey.pem", |
| 3185 | } |
| 3186 | |
| 3187 | cc_test { |
| 3188 | name: "mytest", |
| 3189 | gtest: false, |
| 3190 | srcs: ["mytest.cpp"], |
| 3191 | relative_install_path: "test", |
| 3192 | system_shared_libs: [], |
| 3193 | static_executable: true, |
| 3194 | stl: "none", |
| 3195 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3196 | |
| 3197 | cc_test { |
| 3198 | name: "mytests", |
| 3199 | gtest: false, |
| 3200 | srcs: [ |
| 3201 | "mytest1.cpp", |
| 3202 | "mytest2.cpp", |
| 3203 | "mytest3.cpp", |
| 3204 | ], |
| 3205 | test_per_src: true, |
| 3206 | relative_install_path: "test", |
| 3207 | system_shared_libs: [], |
| 3208 | static_executable: true, |
| 3209 | stl: "none", |
| 3210 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3211 | `) |
| 3212 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3213 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3214 | copyCmds := apexRule.Args["copy_commands"] |
| 3215 | |
| 3216 | // Ensure that test dep is copied into apex. |
| 3217 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3218 | |
| 3219 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 3220 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 3221 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 3222 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3223 | |
| 3224 | // Ensure the module is correctly translated. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3225 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3226 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3227 | name := apexBundle.BaseModuleName() |
| 3228 | prefix := "TARGET_" |
| 3229 | var builder strings.Builder |
| 3230 | data.Custom(&builder, name, prefix, "", data) |
| 3231 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3232 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 3233 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 3234 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 3235 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3236 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3237 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3238 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3239 | } |
| 3240 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 3241 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
| 3242 | ctx, config := testApex(t, ` |
| 3243 | apex { |
| 3244 | name: "myapex", |
| 3245 | key: "myapex.key", |
| 3246 | } |
| 3247 | apex_key { |
| 3248 | name: "myapex.key", |
| 3249 | public_key: "testkey.avbpubkey", |
| 3250 | private_key: "testkey.pem", |
| 3251 | } |
| 3252 | `, func(fs map[string][]byte, config android.Config) { |
| 3253 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 3254 | }) |
| 3255 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 3256 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 3257 | mk := android.AndroidMkDataForTest(t, config, "", ab) |
| 3258 | var builder strings.Builder |
| 3259 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 3260 | androidMk := builder.String() |
| 3261 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 3262 | } |
| 3263 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3264 | func TestApexUsesOtherApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3265 | ctx, _ := testApex(t, ` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3266 | apex { |
| 3267 | name: "myapex", |
| 3268 | key: "myapex.key", |
| 3269 | native_shared_libs: ["mylib"], |
| 3270 | uses: ["commonapex"], |
| 3271 | } |
| 3272 | |
| 3273 | apex { |
| 3274 | name: "commonapex", |
| 3275 | key: "myapex.key", |
| 3276 | native_shared_libs: ["libcommon"], |
| 3277 | provide_cpp_shared_libs: true, |
| 3278 | } |
| 3279 | |
| 3280 | apex_key { |
| 3281 | name: "myapex.key", |
| 3282 | public_key: "testkey.avbpubkey", |
| 3283 | private_key: "testkey.pem", |
| 3284 | } |
| 3285 | |
| 3286 | cc_library { |
| 3287 | name: "mylib", |
| 3288 | srcs: ["mylib.cpp"], |
| 3289 | shared_libs: ["libcommon"], |
| 3290 | system_shared_libs: [], |
| 3291 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3292 | apex_available: [ "myapex" ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | cc_library { |
| 3296 | name: "libcommon", |
| 3297 | srcs: ["mylib_common.cpp"], |
| 3298 | system_shared_libs: [], |
| 3299 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3300 | // TODO: remove //apex_available:platform |
| 3301 | apex_available: [ |
| 3302 | "//apex_available:platform", |
| 3303 | "commonapex", |
| 3304 | "myapex", |
| 3305 | ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3306 | } |
| 3307 | `) |
| 3308 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3309 | module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3310 | apexRule1 := module1.Rule("apexRule") |
| 3311 | copyCmds1 := apexRule1.Args["copy_commands"] |
| 3312 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3313 | module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3314 | apexRule2 := module2.Rule("apexRule") |
| 3315 | copyCmds2 := apexRule2.Args["copy_commands"] |
| 3316 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3317 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 3318 | ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3319 | ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so") |
| 3320 | ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so") |
| 3321 | ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so") |
| 3322 | } |
| 3323 | |
| 3324 | func TestApexUsesFailsIfNotProvided(t *testing.T) { |
| 3325 | testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, ` |
| 3326 | apex { |
| 3327 | name: "myapex", |
| 3328 | key: "myapex.key", |
| 3329 | uses: ["commonapex"], |
| 3330 | } |
| 3331 | |
| 3332 | apex { |
| 3333 | name: "commonapex", |
| 3334 | key: "myapex.key", |
| 3335 | } |
| 3336 | |
| 3337 | apex_key { |
| 3338 | name: "myapex.key", |
| 3339 | public_key: "testkey.avbpubkey", |
| 3340 | private_key: "testkey.pem", |
| 3341 | } |
| 3342 | `) |
| 3343 | testApexError(t, `uses: "commonapex" is not a provider`, ` |
| 3344 | apex { |
| 3345 | name: "myapex", |
| 3346 | key: "myapex.key", |
| 3347 | uses: ["commonapex"], |
| 3348 | } |
| 3349 | |
| 3350 | cc_library { |
| 3351 | name: "commonapex", |
| 3352 | system_shared_libs: [], |
| 3353 | stl: "none", |
| 3354 | } |
| 3355 | |
| 3356 | apex_key { |
| 3357 | name: "myapex.key", |
| 3358 | public_key: "testkey.avbpubkey", |
| 3359 | private_key: "testkey.pem", |
| 3360 | } |
| 3361 | `) |
| 3362 | } |
| 3363 | |
| 3364 | func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) { |
| 3365 | testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, ` |
| 3366 | apex { |
| 3367 | name: "myapex", |
| 3368 | key: "myapex.key", |
| 3369 | use_vendor: true, |
| 3370 | uses: ["commonapex"], |
| 3371 | } |
| 3372 | |
| 3373 | apex { |
| 3374 | name: "commonapex", |
| 3375 | key: "myapex.key", |
| 3376 | provide_cpp_shared_libs: true, |
| 3377 | } |
| 3378 | |
| 3379 | apex_key { |
| 3380 | name: "myapex.key", |
| 3381 | public_key: "testkey.avbpubkey", |
| 3382 | private_key: "testkey.pem", |
| 3383 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 3384 | `, func(fs map[string][]byte, config android.Config) { |
| 3385 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 3386 | }) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3387 | } |
| 3388 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3389 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 3390 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 3391 | apex { |
| 3392 | name: "myapex", |
| 3393 | key: "myapex.key", |
| 3394 | native_shared_libs: ["libfoo"], |
| 3395 | } |
| 3396 | |
| 3397 | apex_key { |
| 3398 | name: "myapex.key", |
| 3399 | public_key: "testkey.avbpubkey", |
| 3400 | private_key: "testkey.pem", |
| 3401 | } |
| 3402 | |
| 3403 | cc_library { |
| 3404 | name: "libfoo", |
| 3405 | stl: "none", |
| 3406 | system_shared_libs: [], |
| 3407 | enabled: false, |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3408 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3409 | } |
| 3410 | `) |
| 3411 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 3412 | apex { |
| 3413 | name: "myapex", |
| 3414 | key: "myapex.key", |
| 3415 | java_libs: ["myjar"], |
| 3416 | } |
| 3417 | |
| 3418 | apex_key { |
| 3419 | name: "myapex.key", |
| 3420 | public_key: "testkey.avbpubkey", |
| 3421 | private_key: "testkey.pem", |
| 3422 | } |
| 3423 | |
| 3424 | java_library { |
| 3425 | name: "myjar", |
| 3426 | srcs: ["foo/bar/MyClass.java"], |
| 3427 | sdk_version: "none", |
| 3428 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3429 | enabled: false, |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3430 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3431 | } |
| 3432 | `) |
| 3433 | } |
| 3434 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3435 | func TestApexWithApps(t *testing.T) { |
| 3436 | ctx, _ := testApex(t, ` |
| 3437 | apex { |
| 3438 | name: "myapex", |
| 3439 | key: "myapex.key", |
| 3440 | apps: [ |
| 3441 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3442 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3443 | ], |
| 3444 | } |
| 3445 | |
| 3446 | apex_key { |
| 3447 | name: "myapex.key", |
| 3448 | public_key: "testkey.avbpubkey", |
| 3449 | private_key: "testkey.pem", |
| 3450 | } |
| 3451 | |
| 3452 | android_app { |
| 3453 | name: "AppFoo", |
| 3454 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 1c93c29 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3455 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3456 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3457 | jni_libs: ["libjni"], |
Colin Cross | 1c93c29 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3458 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3459 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3460 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3461 | |
| 3462 | android_app { |
| 3463 | name: "AppFooPriv", |
| 3464 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 1c93c29 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3465 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3466 | system_modules: "none", |
| 3467 | privileged: true, |
Colin Cross | 1c93c29 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3468 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3469 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3470 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3471 | |
| 3472 | cc_library_shared { |
| 3473 | name: "libjni", |
| 3474 | srcs: ["mylib.cpp"], |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3475 | shared_libs: ["libfoo"], |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3476 | stl: "none", |
| 3477 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3478 | apex_available: [ "myapex" ], |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3479 | sdk_version: "current", |
| 3480 | } |
| 3481 | |
| 3482 | cc_library_shared { |
| 3483 | name: "libfoo", |
| 3484 | stl: "none", |
| 3485 | system_shared_libs: [], |
| 3486 | apex_available: [ "myapex" ], |
| 3487 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3488 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3489 | `) |
| 3490 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3491 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3492 | apexRule := module.Rule("apexRule") |
| 3493 | copyCmds := apexRule.Args["copy_commands"] |
| 3494 | |
| 3495 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3496 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 3497 | |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3498 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs") |
| 3499 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 3500 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3501 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 3502 | } |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3503 | // JNI libraries including transitive deps are |
| 3504 | for _, jni := range []string{"libjni", "libfoo"} { |
Colin Cross | 01fd7cc | 2020-02-19 16:54:04 -0800 | [diff] [blame] | 3505 | jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_sdk_shared_myapex").Module().(*cc.Module).OutputFile() |
Jooyung Han | 6504179 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3506 | // ... embedded inside APK (jnilibs.zip) |
| 3507 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 3508 | // ... and not directly inside the APEX |
| 3509 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 3510 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3511 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3512 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3513 | func TestApexWithAppImports(t *testing.T) { |
| 3514 | ctx, _ := testApex(t, ` |
| 3515 | apex { |
| 3516 | name: "myapex", |
| 3517 | key: "myapex.key", |
| 3518 | apps: [ |
| 3519 | "AppFooPrebuilt", |
| 3520 | "AppFooPrivPrebuilt", |
| 3521 | ], |
| 3522 | } |
| 3523 | |
| 3524 | apex_key { |
| 3525 | name: "myapex.key", |
| 3526 | public_key: "testkey.avbpubkey", |
| 3527 | private_key: "testkey.pem", |
| 3528 | } |
| 3529 | |
| 3530 | android_app_import { |
| 3531 | name: "AppFooPrebuilt", |
| 3532 | apk: "PrebuiltAppFoo.apk", |
| 3533 | presigned: true, |
| 3534 | dex_preopt: { |
| 3535 | enabled: false, |
| 3536 | }, |
| 3537 | } |
| 3538 | |
| 3539 | android_app_import { |
| 3540 | name: "AppFooPrivPrebuilt", |
| 3541 | apk: "PrebuiltAppFooPriv.apk", |
| 3542 | privileged: true, |
| 3543 | presigned: true, |
| 3544 | dex_preopt: { |
| 3545 | enabled: false, |
| 3546 | }, |
Jooyung Han | 65cd0f0 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 3547 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3548 | } |
| 3549 | `) |
| 3550 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3551 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3552 | apexRule := module.Rule("apexRule") |
| 3553 | copyCmds := apexRule.Args["copy_commands"] |
| 3554 | |
| 3555 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 65cd0f0 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 3556 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 3557 | } |
| 3558 | |
| 3559 | func TestApexWithAppImportsPrefer(t *testing.T) { |
| 3560 | ctx, _ := testApex(t, ` |
| 3561 | apex { |
| 3562 | name: "myapex", |
| 3563 | key: "myapex.key", |
| 3564 | apps: [ |
| 3565 | "AppFoo", |
| 3566 | ], |
| 3567 | } |
| 3568 | |
| 3569 | apex_key { |
| 3570 | name: "myapex.key", |
| 3571 | public_key: "testkey.avbpubkey", |
| 3572 | private_key: "testkey.pem", |
| 3573 | } |
| 3574 | |
| 3575 | android_app { |
| 3576 | name: "AppFoo", |
| 3577 | srcs: ["foo/bar/MyClass.java"], |
| 3578 | sdk_version: "none", |
| 3579 | system_modules: "none", |
| 3580 | apex_available: [ "myapex" ], |
| 3581 | } |
| 3582 | |
| 3583 | android_app_import { |
| 3584 | name: "AppFoo", |
| 3585 | apk: "AppFooPrebuilt.apk", |
| 3586 | filename: "AppFooPrebuilt.apk", |
| 3587 | presigned: true, |
| 3588 | prefer: true, |
| 3589 | } |
| 3590 | `, withFiles(map[string][]byte{ |
| 3591 | "AppFooPrebuilt.apk": nil, |
| 3592 | })) |
| 3593 | |
| 3594 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 3595 | "app/AppFoo/AppFooPrebuilt.apk", |
| 3596 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3597 | } |
| 3598 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 3599 | func TestApexWithTestHelperApp(t *testing.T) { |
| 3600 | ctx, _ := testApex(t, ` |
| 3601 | apex { |
| 3602 | name: "myapex", |
| 3603 | key: "myapex.key", |
| 3604 | apps: [ |
| 3605 | "TesterHelpAppFoo", |
| 3606 | ], |
| 3607 | } |
| 3608 | |
| 3609 | apex_key { |
| 3610 | name: "myapex.key", |
| 3611 | public_key: "testkey.avbpubkey", |
| 3612 | private_key: "testkey.pem", |
| 3613 | } |
| 3614 | |
| 3615 | android_test_helper_app { |
| 3616 | name: "TesterHelpAppFoo", |
| 3617 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3618 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | `) |
| 3622 | |
| 3623 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3624 | apexRule := module.Rule("apexRule") |
| 3625 | copyCmds := apexRule.Args["copy_commands"] |
| 3626 | |
| 3627 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 3628 | } |
| 3629 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 3630 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 3631 | // libfoo's apex_available comes from cc_defaults |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3632 | testApexError(t, `requires "libfoo" that is not available for the APEX`, ` |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 3633 | apex { |
| 3634 | name: "myapex", |
| 3635 | key: "myapex.key", |
| 3636 | native_shared_libs: ["libfoo"], |
| 3637 | } |
| 3638 | |
| 3639 | apex_key { |
| 3640 | name: "myapex.key", |
| 3641 | public_key: "testkey.avbpubkey", |
| 3642 | private_key: "testkey.pem", |
| 3643 | } |
| 3644 | |
| 3645 | apex { |
| 3646 | name: "otherapex", |
| 3647 | key: "myapex.key", |
| 3648 | native_shared_libs: ["libfoo"], |
| 3649 | } |
| 3650 | |
| 3651 | cc_defaults { |
| 3652 | name: "libfoo-defaults", |
| 3653 | apex_available: ["otherapex"], |
| 3654 | } |
| 3655 | |
| 3656 | cc_library { |
| 3657 | name: "libfoo", |
| 3658 | defaults: ["libfoo-defaults"], |
| 3659 | stl: "none", |
| 3660 | system_shared_libs: [], |
| 3661 | }`) |
| 3662 | } |
| 3663 | |
Paul Duffin | de7464c | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3664 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3665 | // libfoo is not available to myapex, but only to otherapex |
| 3666 | testApexError(t, "requires \"libfoo\" that is not available for the APEX", ` |
| 3667 | apex { |
| 3668 | name: "myapex", |
| 3669 | key: "myapex.key", |
| 3670 | native_shared_libs: ["libfoo"], |
| 3671 | } |
| 3672 | |
| 3673 | apex_key { |
| 3674 | name: "myapex.key", |
| 3675 | public_key: "testkey.avbpubkey", |
| 3676 | private_key: "testkey.pem", |
| 3677 | } |
| 3678 | |
| 3679 | apex { |
| 3680 | name: "otherapex", |
| 3681 | key: "otherapex.key", |
| 3682 | native_shared_libs: ["libfoo"], |
| 3683 | } |
| 3684 | |
| 3685 | apex_key { |
| 3686 | name: "otherapex.key", |
| 3687 | public_key: "testkey.avbpubkey", |
| 3688 | private_key: "testkey.pem", |
| 3689 | } |
| 3690 | |
| 3691 | cc_library { |
| 3692 | name: "libfoo", |
| 3693 | stl: "none", |
| 3694 | system_shared_libs: [], |
| 3695 | apex_available: ["otherapex"], |
| 3696 | }`) |
Paul Duffin | de7464c | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3697 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3698 | |
Paul Duffin | de7464c | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3699 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3700 | // libbbaz is an indirect dep |
Paul Duffin | 868ecfd | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 3701 | testApexError(t, `requires "libbaz" that is not available for the APEX. Dependency path: |
Paul Duffin | f020796 | 2020-03-31 11:31:36 +0100 | [diff] [blame] | 3702 | .*via tag apex\.dependencyTag.*"sharedLib".* |
Paul Duffin | 868ecfd | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 3703 | .*-> libfoo.*link:shared.* |
Paul Duffin | b20ad0a | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 3704 | .*via tag cc\.DependencyTag.*"shared".* |
Paul Duffin | 868ecfd | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 3705 | .*-> libbar.*link:shared.* |
Paul Duffin | b20ad0a | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 3706 | .*via tag cc\.DependencyTag.*"shared".* |
| 3707 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3708 | apex { |
| 3709 | name: "myapex", |
| 3710 | key: "myapex.key", |
| 3711 | native_shared_libs: ["libfoo"], |
| 3712 | } |
| 3713 | |
| 3714 | apex_key { |
| 3715 | name: "myapex.key", |
| 3716 | public_key: "testkey.avbpubkey", |
| 3717 | private_key: "testkey.pem", |
| 3718 | } |
| 3719 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3720 | cc_library { |
| 3721 | name: "libfoo", |
| 3722 | stl: "none", |
| 3723 | shared_libs: ["libbar"], |
| 3724 | system_shared_libs: [], |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3725 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | cc_library { |
| 3729 | name: "libbar", |
| 3730 | stl: "none", |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3731 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3732 | system_shared_libs: [], |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3733 | apex_available: ["myapex"], |
| 3734 | } |
| 3735 | |
| 3736 | cc_library { |
| 3737 | name: "libbaz", |
| 3738 | stl: "none", |
| 3739 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3740 | }`) |
Paul Duffin | de7464c | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3741 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3742 | |
Paul Duffin | de7464c | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3743 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3744 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 3745 | apex { |
| 3746 | name: "myapex", |
| 3747 | key: "myapex.key", |
| 3748 | native_shared_libs: ["libfoo"], |
| 3749 | } |
| 3750 | |
| 3751 | apex_key { |
| 3752 | name: "myapex.key", |
| 3753 | public_key: "testkey.avbpubkey", |
| 3754 | private_key: "testkey.pem", |
| 3755 | } |
| 3756 | |
| 3757 | cc_library { |
| 3758 | name: "libfoo", |
| 3759 | stl: "none", |
| 3760 | system_shared_libs: [], |
| 3761 | apex_available: ["otherapex"], |
| 3762 | }`) |
| 3763 | |
Paul Duffin | de7464c | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3764 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3765 | apex { |
| 3766 | name: "myapex", |
| 3767 | key: "myapex.key", |
| 3768 | native_shared_libs: ["libfoo", "libbar"], |
| 3769 | } |
| 3770 | |
| 3771 | apex_key { |
| 3772 | name: "myapex.key", |
| 3773 | public_key: "testkey.avbpubkey", |
| 3774 | private_key: "testkey.pem", |
| 3775 | } |
| 3776 | |
| 3777 | cc_library { |
| 3778 | name: "libfoo", |
| 3779 | stl: "none", |
| 3780 | system_shared_libs: [], |
Jiyong Park | 9f14b9b | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 3781 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3782 | apex_available: ["myapex"], |
| 3783 | } |
| 3784 | |
| 3785 | cc_library { |
| 3786 | name: "libbar", |
| 3787 | stl: "none", |
| 3788 | system_shared_libs: [], |
| 3789 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 9f14b9b | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | cc_library { |
| 3793 | name: "libbaz", |
| 3794 | stl: "none", |
| 3795 | system_shared_libs: [], |
| 3796 | stubs: { |
| 3797 | versions: ["10", "20", "30"], |
| 3798 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3799 | }`) |
Paul Duffin | de7464c | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3800 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3801 | |
Jiyong Park | 6a9ddc3 | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 3802 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Paul Duffin | de7464c | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3803 | ctx, _ := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3804 | apex { |
| 3805 | name: "myapex", |
| 3806 | key: "myapex.key", |
Jiyong Park | 6a9ddc3 | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 3807 | native_shared_libs: ["libbar", "libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | apex_key { |
| 3811 | name: "myapex.key", |
| 3812 | public_key: "testkey.avbpubkey", |
| 3813 | private_key: "testkey.pem", |
| 3814 | } |
| 3815 | |
| 3816 | cc_library { |
| 3817 | name: "libfoo", |
| 3818 | stl: "none", |
| 3819 | system_shared_libs: [], |
Jiyong Park | 6a9ddc3 | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 3820 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3821 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 6a9ddc3 | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | cc_library { |
| 3825 | name: "libfoo2", |
| 3826 | stl: "none", |
| 3827 | system_shared_libs: [], |
| 3828 | shared_libs: ["libbaz"], |
| 3829 | apex_available: ["//apex_available:platform"], |
| 3830 | } |
| 3831 | |
| 3832 | cc_library { |
| 3833 | name: "libbar", |
| 3834 | stl: "none", |
| 3835 | system_shared_libs: [], |
| 3836 | apex_available: ["myapex"], |
| 3837 | } |
| 3838 | |
| 3839 | cc_library { |
| 3840 | name: "libbaz", |
| 3841 | stl: "none", |
| 3842 | system_shared_libs: [], |
| 3843 | apex_available: ["myapex"], |
| 3844 | stubs: { |
| 3845 | versions: ["1"], |
| 3846 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3847 | }`) |
| 3848 | |
Jiyong Park | 6a9ddc3 | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 3849 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 3850 | // because it depends on libbar which isn't available to platform |
| 3851 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 3852 | if libfoo.NotAvailableForPlatform() != true { |
| 3853 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 3854 | } |
| 3855 | |
| 3856 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 3857 | // stubs |
| 3858 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 3859 | if libfoo2.NotAvailableForPlatform() == true { |
| 3860 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 3861 | } |
Paul Duffin | de7464c | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3862 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 3863 | |
Paul Duffin | de7464c | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 3864 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Jiyong Park | 6a9ddc3 | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 3865 | ctx, _ := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 3866 | apex { |
| 3867 | name: "myapex", |
| 3868 | key: "myapex.key", |
| 3869 | native_shared_libs: ["libfoo"], |
| 3870 | } |
| 3871 | |
| 3872 | apex_key { |
| 3873 | name: "myapex.key", |
| 3874 | public_key: "testkey.avbpubkey", |
| 3875 | private_key: "testkey.pem", |
| 3876 | } |
| 3877 | |
| 3878 | cc_library { |
| 3879 | name: "libfoo", |
| 3880 | stl: "none", |
| 3881 | system_shared_libs: [], |
| 3882 | apex_available: ["myapex"], |
| 3883 | static: { |
| 3884 | apex_available: ["//apex_available:platform"], |
| 3885 | }, |
| 3886 | }`) |
| 3887 | |
Jiyong Park | 6a9ddc3 | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 3888 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 3889 | if libfooShared.NotAvailableForPlatform() != true { |
| 3890 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 3891 | } |
| 3892 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 3893 | if libfooStatic.NotAvailableForPlatform() != false { |
| 3894 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 3895 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3896 | } |
| 3897 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3898 | func TestOverrideApex(t *testing.T) { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3899 | ctx, config := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3900 | apex { |
| 3901 | name: "myapex", |
| 3902 | key: "myapex.key", |
| 3903 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3904 | overrides: ["oldapex"], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | override_apex { |
| 3908 | name: "override_myapex", |
| 3909 | base: "myapex", |
| 3910 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3911 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 3912 | logging_parent: "com.foo.bar", |
Baligh Uddin | cb6aa12 | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 3913 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | apex_key { |
| 3917 | name: "myapex.key", |
| 3918 | public_key: "testkey.avbpubkey", |
| 3919 | private_key: "testkey.pem", |
| 3920 | } |
| 3921 | |
| 3922 | android_app { |
| 3923 | name: "app", |
| 3924 | srcs: ["foo/bar/MyClass.java"], |
| 3925 | package_name: "foo", |
| 3926 | sdk_version: "none", |
| 3927 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3928 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | override_android_app { |
| 3932 | name: "override_app", |
| 3933 | base: "app", |
| 3934 | package_name: "bar", |
| 3935 | } |
Jiyong Park | a519c54 | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3936 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3937 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 3938 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 3939 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 3940 | if originalVariant.GetOverriddenBy() != "" { |
| 3941 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 3942 | } |
| 3943 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 3944 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 3945 | } |
| 3946 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3947 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 3948 | apexRule := module.Rule("apexRule") |
| 3949 | copyCmds := apexRule.Args["copy_commands"] |
| 3950 | |
| 3951 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 65cd0f0 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 3952 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3953 | |
| 3954 | apexBundle := module.Module().(*apexBundle) |
| 3955 | name := apexBundle.Name() |
| 3956 | if name != "override_myapex" { |
| 3957 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 3958 | } |
| 3959 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 3960 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 3961 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 3962 | } |
| 3963 | |
Jiyong Park | a519c54 | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3964 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | cb6aa12 | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 3965 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | a519c54 | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3966 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3967 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3968 | var builder strings.Builder |
| 3969 | data.Custom(&builder, name, "TARGET_", "", data) |
| 3970 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 3971 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3972 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 3973 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3974 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3975 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 3976 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3977 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 3978 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3979 | } |
| 3980 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3981 | func TestLegacyAndroid10Support(t *testing.T) { |
| 3982 | ctx, _ := testApex(t, ` |
| 3983 | apex { |
| 3984 | name: "myapex", |
| 3985 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3986 | native_shared_libs: ["mylib"], |
Jooyung Han | 23b0adf | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 3987 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | apex_key { |
| 3991 | name: "myapex.key", |
| 3992 | public_key: "testkey.avbpubkey", |
| 3993 | private_key: "testkey.pem", |
| 3994 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3995 | |
| 3996 | cc_library { |
| 3997 | name: "mylib", |
| 3998 | srcs: ["mylib.cpp"], |
| 3999 | stl: "libc++", |
| 4000 | system_shared_libs: [], |
| 4001 | apex_available: [ "myapex" ], |
| 4002 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4003 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4004 | |
| 4005 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4006 | args := module.Rule("apexRule").Args |
| 4007 | 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] | 4008 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4009 | |
| 4010 | // The copies of the libraries in the apex should have one more dependency than |
| 4011 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 4012 | // the dependency names directly here but for some reason the names are blank in |
| 4013 | // this test. |
| 4014 | for _, lib := range []string{"libc++", "mylib"} { |
| 4015 | apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits |
| 4016 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 4017 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 4018 | t.Errorf("%q missing unwinder dep", lib) |
| 4019 | } |
| 4020 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4021 | } |
| 4022 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4023 | func TestJavaSDKLibrary(t *testing.T) { |
| 4024 | ctx, _ := testApex(t, ` |
| 4025 | apex { |
| 4026 | name: "myapex", |
| 4027 | key: "myapex.key", |
| 4028 | java_libs: ["foo"], |
| 4029 | } |
| 4030 | |
| 4031 | apex_key { |
| 4032 | name: "myapex.key", |
| 4033 | public_key: "testkey.avbpubkey", |
| 4034 | private_key: "testkey.pem", |
| 4035 | } |
| 4036 | |
| 4037 | java_sdk_library { |
| 4038 | name: "foo", |
| 4039 | srcs: ["a.java"], |
| 4040 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4041 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4042 | } |
| 4043 | `, withFiles(map[string][]byte{ |
| 4044 | "api/current.txt": nil, |
| 4045 | "api/removed.txt": nil, |
| 4046 | "api/system-current.txt": nil, |
| 4047 | "api/system-removed.txt": nil, |
| 4048 | "api/test-current.txt": nil, |
| 4049 | "api/test-removed.txt": nil, |
| 4050 | })) |
| 4051 | |
| 4052 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 4053 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4054 | "javalib/foo.jar", |
| 4055 | "etc/permissions/foo.xml", |
| 4056 | }) |
| 4057 | // 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] | 4058 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 4059 | 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] | 4060 | } |
| 4061 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 4062 | func TestCompatConfig(t *testing.T) { |
| 4063 | ctx, _ := testApex(t, ` |
| 4064 | apex { |
| 4065 | name: "myapex", |
| 4066 | key: "myapex.key", |
| 4067 | prebuilts: ["myjar-platform-compat-config"], |
| 4068 | java_libs: ["myjar"], |
| 4069 | } |
| 4070 | |
| 4071 | apex_key { |
| 4072 | name: "myapex.key", |
| 4073 | public_key: "testkey.avbpubkey", |
| 4074 | private_key: "testkey.pem", |
| 4075 | } |
| 4076 | |
| 4077 | platform_compat_config { |
| 4078 | name: "myjar-platform-compat-config", |
| 4079 | src: ":myjar", |
| 4080 | } |
| 4081 | |
| 4082 | java_library { |
| 4083 | name: "myjar", |
| 4084 | srcs: ["foo/bar/MyClass.java"], |
| 4085 | sdk_version: "none", |
| 4086 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 4087 | apex_available: [ "myapex" ], |
| 4088 | } |
| 4089 | `) |
| 4090 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4091 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 4092 | "javalib/myjar.jar", |
| 4093 | }) |
| 4094 | } |
| 4095 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 4096 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 4097 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 4098 | apex { |
| 4099 | name: "myapex", |
| 4100 | key: "myapex.key", |
| 4101 | java_libs: ["myjar"], |
| 4102 | } |
| 4103 | |
| 4104 | apex_key { |
| 4105 | name: "myapex.key", |
| 4106 | public_key: "testkey.avbpubkey", |
| 4107 | private_key: "testkey.pem", |
| 4108 | } |
| 4109 | |
| 4110 | java_library { |
| 4111 | name: "myjar", |
| 4112 | srcs: ["foo/bar/MyClass.java"], |
| 4113 | sdk_version: "none", |
| 4114 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 4115 | compile_dex: false, |
Jooyung Han | b8fa86a | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4116 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 4117 | } |
| 4118 | `) |
| 4119 | } |
| 4120 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 4121 | func TestCarryRequiredModuleNames(t *testing.T) { |
| 4122 | ctx, config := testApex(t, ` |
| 4123 | apex { |
| 4124 | name: "myapex", |
| 4125 | key: "myapex.key", |
| 4126 | native_shared_libs: ["mylib"], |
| 4127 | } |
| 4128 | |
| 4129 | apex_key { |
| 4130 | name: "myapex.key", |
| 4131 | public_key: "testkey.avbpubkey", |
| 4132 | private_key: "testkey.pem", |
| 4133 | } |
| 4134 | |
| 4135 | cc_library { |
| 4136 | name: "mylib", |
| 4137 | srcs: ["mylib.cpp"], |
| 4138 | system_shared_libs: [], |
| 4139 | stl: "none", |
| 4140 | required: ["a", "b"], |
| 4141 | host_required: ["c", "d"], |
| 4142 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4143 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 4144 | } |
| 4145 | `) |
| 4146 | |
| 4147 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 4148 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 4149 | name := apexBundle.BaseModuleName() |
| 4150 | prefix := "TARGET_" |
| 4151 | var builder strings.Builder |
| 4152 | data.Custom(&builder, name, prefix, "", data) |
| 4153 | androidMk := builder.String() |
| 4154 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 4155 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 4156 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 4157 | } |
| 4158 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4159 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 4160 | bp := ` |
| 4161 | apex { |
| 4162 | name: "myapex", |
| 4163 | key: "myapex.key", |
| 4164 | native_shared_libs: ["mylib"], |
| 4165 | java_libs: ["myjar"], |
| 4166 | } |
| 4167 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4168 | apex { |
| 4169 | name: "myapex.updatable", |
| 4170 | key: "myapex.key", |
| 4171 | native_shared_libs: ["mylib"], |
| 4172 | java_libs: ["myjar"], |
| 4173 | updatable: true, |
Jooyung Han | ced674e | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 4174 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4175 | } |
| 4176 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4177 | apex_key { |
| 4178 | name: "myapex.key", |
| 4179 | public_key: "testkey.avbpubkey", |
| 4180 | private_key: "testkey.pem", |
| 4181 | } |
| 4182 | |
| 4183 | cc_library { |
| 4184 | name: "mylib", |
| 4185 | srcs: ["mylib.cpp"], |
| 4186 | shared_libs: ["myotherlib"], |
| 4187 | system_shared_libs: [], |
| 4188 | stl: "none", |
| 4189 | apex_available: [ |
| 4190 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4191 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4192 | "//apex_available:platform", |
| 4193 | ], |
| 4194 | } |
| 4195 | |
| 4196 | cc_library { |
| 4197 | name: "myotherlib", |
| 4198 | srcs: ["mylib.cpp"], |
| 4199 | system_shared_libs: [], |
| 4200 | stl: "none", |
| 4201 | apex_available: [ |
| 4202 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4203 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4204 | "//apex_available:platform", |
| 4205 | ], |
| 4206 | } |
| 4207 | |
| 4208 | java_library { |
| 4209 | name: "myjar", |
| 4210 | srcs: ["foo/bar/MyClass.java"], |
| 4211 | sdk_version: "none", |
| 4212 | system_modules: "none", |
| 4213 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4214 | apex_available: [ |
| 4215 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4216 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4217 | "//apex_available:platform", |
| 4218 | ], |
| 4219 | } |
| 4220 | |
| 4221 | java_library { |
| 4222 | name: "myotherjar", |
| 4223 | srcs: ["foo/bar/MyClass.java"], |
| 4224 | sdk_version: "none", |
| 4225 | system_modules: "none", |
| 4226 | apex_available: [ |
| 4227 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4228 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4229 | "//apex_available:platform", |
| 4230 | ], |
| 4231 | } |
| 4232 | ` |
| 4233 | |
| 4234 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 4235 | for _, f := range files { |
| 4236 | if f.path == file { |
| 4237 | if f.isLink { |
| 4238 | t.Errorf("%q is not a real file", file) |
| 4239 | } |
| 4240 | return |
| 4241 | } |
| 4242 | } |
| 4243 | t.Errorf("%q is not found", file) |
| 4244 | } |
| 4245 | |
| 4246 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 4247 | for _, f := range files { |
| 4248 | if f.path == file { |
| 4249 | if !f.isLink { |
| 4250 | t.Errorf("%q is not a symlink", file) |
| 4251 | } |
| 4252 | return |
| 4253 | } |
| 4254 | } |
| 4255 | t.Errorf("%q is not found", file) |
| 4256 | } |
| 4257 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4258 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 4259 | // is updatable or not |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4260 | ctx, _ := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 4261 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4262 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4263 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4264 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 4265 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4266 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 4267 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4268 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4269 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 4270 | |
| 4271 | // 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] | 4272 | ctx, _ = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 4273 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4274 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4275 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4276 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4277 | |
| 4278 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 4279 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4280 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4281 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4282 | } |
| 4283 | |
Jooyung Han | 40b286c | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 4284 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
| 4285 | ctx, _ := testApex(t, ` |
| 4286 | apex { |
| 4287 | name: "myapex", |
| 4288 | key: "myapex.key", |
| 4289 | } |
| 4290 | apex_key { |
| 4291 | name: "myapex.key", |
| 4292 | public_key: "testkey.avbpubkey", |
| 4293 | private_key: "testkey.pem", |
| 4294 | } |
| 4295 | `, func(fs map[string][]byte, config android.Config) { |
| 4296 | delete(config.Targets, android.Android) |
| 4297 | config.AndroidCommonTarget = android.Target{} |
| 4298 | }) |
| 4299 | |
| 4300 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 4301 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 4302 | } |
| 4303 | } |
| 4304 | |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 4305 | func TestAppBundle(t *testing.T) { |
| 4306 | ctx, _ := testApex(t, ` |
| 4307 | apex { |
| 4308 | name: "myapex", |
| 4309 | key: "myapex.key", |
| 4310 | apps: ["AppFoo"], |
| 4311 | } |
| 4312 | |
| 4313 | apex_key { |
| 4314 | name: "myapex.key", |
| 4315 | public_key: "testkey.avbpubkey", |
| 4316 | private_key: "testkey.pem", |
| 4317 | } |
| 4318 | |
| 4319 | android_app { |
| 4320 | name: "AppFoo", |
| 4321 | srcs: ["foo/bar/MyClass.java"], |
| 4322 | sdk_version: "none", |
| 4323 | system_modules: "none", |
| 4324 | apex_available: [ "myapex" ], |
| 4325 | } |
Jiyong Park | af8998c | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 4326 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 4327 | |
| 4328 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config") |
| 4329 | content := bundleConfigRule.Args["content"] |
| 4330 | |
| 4331 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | af8998c | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 4332 | ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`) |
Jiyong Park | d93e1b1 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 4333 | } |
| 4334 | |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4335 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg, bp string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
| 4336 | t.Helper() |
| 4337 | |
| 4338 | bp = bp + ` |
| 4339 | filegroup { |
| 4340 | name: "some-updatable-apex-file_contexts", |
| 4341 | srcs: [ |
| 4342 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 4343 | ], |
| 4344 | } |
Ulya Trafimovich | c0eb0b1 | 2020-04-22 18:05:58 +0100 | [diff] [blame^] | 4345 | |
| 4346 | filegroup { |
| 4347 | name: "some-non-updatable-apex-file_contexts", |
| 4348 | srcs: [ |
| 4349 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 4350 | ], |
| 4351 | } |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4352 | ` |
| 4353 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 4354 | bp += java.GatherRequiredDepsForTest() |
| 4355 | bp += dexpreopt.BpToolModulesForTest() |
| 4356 | |
| 4357 | fs := map[string][]byte{ |
| 4358 | "a.java": nil, |
| 4359 | "a.jar": nil, |
| 4360 | "build/make/target/product/security": nil, |
| 4361 | "apex_manifest.json": nil, |
| 4362 | "AndroidManifest.xml": nil, |
| 4363 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | c0eb0b1 | 2020-04-22 18:05:58 +0100 | [diff] [blame^] | 4364 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4365 | "system/sepolicy/apex/com.android.art.something-file_contexts": nil, |
| 4366 | "framework/aidl/a.aidl": nil, |
| 4367 | } |
| 4368 | cc.GatherRequiredFilesForTest(fs) |
| 4369 | |
| 4370 | ctx := android.NewTestArchContext() |
| 4371 | ctx.RegisterModuleType("apex", BundleFactory) |
| 4372 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 4373 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | eedf3f1 | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 4374 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4375 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
| 4376 | java.RegisterJavaBuildComponents(ctx) |
| 4377 | java.RegisterSystemModulesBuildComponents(ctx) |
| 4378 | java.RegisterAppBuildComponents(ctx) |
| 4379 | java.RegisterDexpreoptBootJarsComponents(ctx) |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4380 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 4381 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 4382 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 4383 | |
| 4384 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 4385 | ctx.Register(config) |
| 4386 | |
| 4387 | _ = dexpreopt.GlobalSoongConfigForTests(config) |
| 4388 | dexpreopt.RegisterToolModulesForTest(ctx) |
| 4389 | pathCtx := android.PathContextForTesting(config) |
| 4390 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 4391 | transformDexpreoptConfig(dexpreoptConfig) |
| 4392 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 4393 | |
| 4394 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 4395 | android.FailIfErrored(t, errs) |
| 4396 | |
| 4397 | _, errs = ctx.PrepareBuildActions(config) |
| 4398 | if errmsg == "" { |
| 4399 | android.FailIfErrored(t, errs) |
| 4400 | } else if len(errs) > 0 { |
| 4401 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 4402 | return |
| 4403 | } else { |
| 4404 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 4405 | } |
| 4406 | } |
| 4407 | |
Jooyung Han | ced674e | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 4408 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 4409 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 4410 | apex { |
| 4411 | name: "myapex", |
| 4412 | key: "myapex.key", |
| 4413 | updatable: true, |
| 4414 | } |
| 4415 | |
| 4416 | apex_key { |
| 4417 | name: "myapex.key", |
| 4418 | public_key: "testkey.avbpubkey", |
| 4419 | private_key: "testkey.pem", |
| 4420 | } |
| 4421 | `) |
| 4422 | } |
| 4423 | |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4424 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
| 4425 | bp := ` |
| 4426 | java_library { |
| 4427 | name: "some-updatable-apex-lib", |
| 4428 | srcs: ["a.java"], |
Artur Satayev | 2eedf62 | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 4429 | sdk_version: "current", |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4430 | apex_available: [ |
| 4431 | "some-updatable-apex", |
| 4432 | ], |
| 4433 | } |
| 4434 | |
| 4435 | java_library { |
Ulya Trafimovich | c0eb0b1 | 2020-04-22 18:05:58 +0100 | [diff] [blame^] | 4436 | name: "some-non-updatable-apex-lib", |
| 4437 | srcs: ["a.java"], |
| 4438 | apex_available: [ |
| 4439 | "some-non-updatable-apex", |
| 4440 | ], |
| 4441 | } |
| 4442 | |
| 4443 | java_library { |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4444 | name: "some-platform-lib", |
| 4445 | srcs: ["a.java"], |
Artur Satayev | 2eedf62 | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 4446 | sdk_version: "current", |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4447 | installable: true, |
| 4448 | } |
| 4449 | |
| 4450 | java_library { |
| 4451 | name: "some-art-lib", |
| 4452 | srcs: ["a.java"], |
Artur Satayev | 2eedf62 | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 4453 | sdk_version: "current", |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4454 | apex_available: [ |
| 4455 | "com.android.art.something", |
| 4456 | ], |
| 4457 | hostdex: true, |
| 4458 | } |
| 4459 | |
| 4460 | apex { |
| 4461 | name: "some-updatable-apex", |
| 4462 | key: "some-updatable-apex.key", |
| 4463 | java_libs: ["some-updatable-apex-lib"], |
Ulya Trafimovich | c0eb0b1 | 2020-04-22 18:05:58 +0100 | [diff] [blame^] | 4464 | updatable: true, |
| 4465 | min_sdk_version: "current", |
| 4466 | } |
| 4467 | |
| 4468 | apex { |
| 4469 | name: "some-non-updatable-apex", |
| 4470 | key: "some-non-updatable-apex.key", |
| 4471 | java_libs: ["some-non-updatable-apex-lib"], |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | apex_key { |
| 4475 | name: "some-updatable-apex.key", |
| 4476 | } |
| 4477 | |
Ulya Trafimovich | c0eb0b1 | 2020-04-22 18:05:58 +0100 | [diff] [blame^] | 4478 | apex_key { |
| 4479 | name: "some-non-updatable-apex.key", |
| 4480 | } |
| 4481 | |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4482 | apex { |
| 4483 | name: "com.android.art.something", |
| 4484 | key: "com.android.art.something.key", |
| 4485 | java_libs: ["some-art-lib"], |
Ulya Trafimovich | c0eb0b1 | 2020-04-22 18:05:58 +0100 | [diff] [blame^] | 4486 | updatable: true, |
| 4487 | min_sdk_version: "current", |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | apex_key { |
| 4491 | name: "com.android.art.something.key", |
| 4492 | } |
| 4493 | ` |
| 4494 | |
| 4495 | var error string |
| 4496 | var transform func(*dexpreopt.GlobalConfig) |
| 4497 | |
| 4498 | // updatable jar from ART apex in the ART boot image => ok |
| 4499 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4500 | config.ArtApexJars = []string{"some-art-lib"} |
| 4501 | } |
| 4502 | testNoUpdatableJarsInBootImage(t, "", bp, transform) |
| 4503 | |
| 4504 | // updatable jar from ART apex in the framework boot image => error |
| 4505 | error = "module 'some-art-lib' from updatable apex 'com.android.art.something' is not allowed in the framework boot image" |
| 4506 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4507 | config.BootJars = []string{"some-art-lib"} |
| 4508 | } |
| 4509 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4510 | |
| 4511 | // updatable jar from some other apex in the ART boot image => error |
| 4512 | error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the ART boot image" |
| 4513 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4514 | config.ArtApexJars = []string{"some-updatable-apex-lib"} |
| 4515 | } |
| 4516 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4517 | |
Ulya Trafimovich | c0eb0b1 | 2020-04-22 18:05:58 +0100 | [diff] [blame^] | 4518 | // non-updatable jar from some other apex in the ART boot image => error |
| 4519 | error = "module 'some-non-updatable-apex-lib' is not allowed in the ART boot image" |
| 4520 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4521 | config.ArtApexJars = []string{"some-non-updatable-apex-lib"} |
| 4522 | } |
| 4523 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4524 | |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4525 | // updatable jar from some other apex in the framework boot image => error |
| 4526 | error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the framework boot image" |
| 4527 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4528 | config.BootJars = []string{"some-updatable-apex-lib"} |
| 4529 | } |
| 4530 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4531 | |
Ulya Trafimovich | c0eb0b1 | 2020-04-22 18:05:58 +0100 | [diff] [blame^] | 4532 | // non-updatable jar from some other apex in the framework boot image => ok |
| 4533 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4534 | config.BootJars = []string{"some-non-updatable-apex-lib"} |
| 4535 | } |
| 4536 | testNoUpdatableJarsInBootImage(t, "", bp, transform) |
| 4537 | |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4538 | // nonexistent jar in the ART boot image => error |
| 4539 | error = "failed to find a dex jar path for module 'nonexistent'" |
| 4540 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4541 | config.ArtApexJars = []string{"nonexistent"} |
| 4542 | } |
| 4543 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4544 | |
| 4545 | // nonexistent jar in the framework boot image => error |
| 4546 | error = "failed to find a dex jar path for module 'nonexistent'" |
| 4547 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4548 | config.BootJars = []string{"nonexistent"} |
| 4549 | } |
| 4550 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4551 | |
| 4552 | // platform jar in the ART boot image => error |
Ulya Trafimovich | c0eb0b1 | 2020-04-22 18:05:58 +0100 | [diff] [blame^] | 4553 | error = "module 'some-platform-lib' is not allowed in the ART boot image" |
Ulya Trafimovich | cc21bba | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 4554 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4555 | config.ArtApexJars = []string{"some-platform-lib"} |
| 4556 | } |
| 4557 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4558 | |
| 4559 | // platform jar in the framework boot image => ok |
| 4560 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4561 | config.BootJars = []string{"some-platform-lib"} |
| 4562 | } |
| 4563 | testNoUpdatableJarsInBootImage(t, "", bp, transform) |
| 4564 | } |
| 4565 | |
Jiyong Park | f0d01b7 | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 4566 | func TestTestFor(t *testing.T) { |
| 4567 | ctx, _ := testApex(t, ` |
| 4568 | apex { |
| 4569 | name: "myapex", |
| 4570 | key: "myapex.key", |
| 4571 | native_shared_libs: ["mylib", "myprivlib"], |
| 4572 | } |
| 4573 | |
| 4574 | apex_key { |
| 4575 | name: "myapex.key", |
| 4576 | public_key: "testkey.avbpubkey", |
| 4577 | private_key: "testkey.pem", |
| 4578 | } |
| 4579 | |
| 4580 | cc_library { |
| 4581 | name: "mylib", |
| 4582 | srcs: ["mylib.cpp"], |
| 4583 | system_shared_libs: [], |
| 4584 | stl: "none", |
| 4585 | stubs: { |
| 4586 | versions: ["1"], |
| 4587 | }, |
| 4588 | apex_available: ["myapex"], |
| 4589 | } |
| 4590 | |
| 4591 | cc_library { |
| 4592 | name: "myprivlib", |
| 4593 | srcs: ["mylib.cpp"], |
| 4594 | system_shared_libs: [], |
| 4595 | stl: "none", |
| 4596 | apex_available: ["myapex"], |
| 4597 | } |
| 4598 | |
| 4599 | |
| 4600 | cc_test { |
| 4601 | name: "mytest", |
| 4602 | gtest: false, |
| 4603 | srcs: ["mylib.cpp"], |
| 4604 | system_shared_libs: [], |
| 4605 | stl: "none", |
| 4606 | shared_libs: ["mylib", "myprivlib"], |
| 4607 | test_for: ["myapex"] |
| 4608 | } |
| 4609 | `) |
| 4610 | |
| 4611 | // the test 'mytest' is a test for the apex, therefore is linked to the |
| 4612 | // actual implementation of mylib instead of its stub. |
| 4613 | ldFlags := ctx.ModuleForTests("mytest", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 4614 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 4615 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
| 4616 | } |
| 4617 | |
Jaewoong Jung | 8cf307e | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 4618 | // TODO(jungjw): Move this to proptools |
| 4619 | func intPtr(i int) *int { |
| 4620 | return &i |
| 4621 | } |
| 4622 | |
| 4623 | func TestApexSet(t *testing.T) { |
| 4624 | ctx, config := testApex(t, ` |
| 4625 | apex_set { |
| 4626 | name: "myapex", |
| 4627 | set: "myapex.apks", |
| 4628 | filename: "foo_v2.apex", |
| 4629 | overrides: ["foo"], |
| 4630 | } |
| 4631 | `, func(fs map[string][]byte, config android.Config) { |
| 4632 | config.TestProductVariables.Platform_sdk_version = intPtr(30) |
| 4633 | config.TestProductVariables.DeviceArch = proptools.StringPtr("arm") |
| 4634 | config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm64") |
| 4635 | }) |
| 4636 | |
| 4637 | m := ctx.ModuleForTests("myapex", "android_common") |
| 4638 | |
| 4639 | // Check extract_apks tool parameters. |
| 4640 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 4641 | actual := extractedApex.Args["abis"] |
| 4642 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 4643 | if actual != expected { |
| 4644 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 4645 | } |
| 4646 | actual = extractedApex.Args["sdk-version"] |
| 4647 | expected = "30" |
| 4648 | if actual != expected { |
| 4649 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 4650 | } |
| 4651 | |
| 4652 | a := m.Module().(*ApexSet) |
| 4653 | expectedOverrides := []string{"foo"} |
| 4654 | actualOverrides := android.AndroidMkEntriesForTest(t, config, "", a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
| 4655 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 4656 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 4657 | } |
| 4658 | } |
| 4659 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4660 | func TestMain(m *testing.M) { |
| 4661 | run := func() int { |
| 4662 | setUp() |
| 4663 | defer tearDown() |
| 4664 | |
| 4665 | return m.Run() |
| 4666 | } |
| 4667 | |
| 4668 | os.Exit(run()) |
| 4669 | } |