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