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 | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 18 | "fmt" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 19 | "os" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 20 | "path" |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 21 | "path/filepath" |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 22 | "reflect" |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 23 | "regexp" |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 24 | "sort" |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 25 | "strconv" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 26 | "strings" |
| 27 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 28 | |
| 29 | "github.com/google/blueprint/proptools" |
| 30 | |
| 31 | "android/soong/android" |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 32 | "android/soong/bpf" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 33 | "android/soong/cc" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 34 | "android/soong/dexpreopt" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 35 | prebuilt_etc "android/soong/etc" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 36 | "android/soong/java" |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 37 | "android/soong/rust" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 38 | "android/soong/sh" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 39 | ) |
| 40 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 41 | // names returns name list from white space separated string |
| 42 | func names(s string) (ns []string) { |
| 43 | for _, n := range strings.Split(s, " ") { |
| 44 | if len(n) > 0 { |
| 45 | ns = append(ns, n) |
| 46 | } |
| 47 | } |
| 48 | return |
| 49 | } |
| 50 | |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 51 | func testApexError(t *testing.T, pattern, bp string, preparers ...android.FixturePreparer) { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 52 | t.Helper() |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 53 | android.GroupFixturePreparers( |
| 54 | prepareForApexTest, |
| 55 | android.GroupFixturePreparers(preparers...), |
| 56 | ). |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 57 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 58 | RunTestWithBp(t, bp) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 59 | } |
| 60 | |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 61 | func testApex(t *testing.T, bp string, preparers ...android.FixturePreparer) *android.TestContext { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 62 | t.Helper() |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 63 | |
| 64 | optionalBpPreparer := android.NullFixturePreparer |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 65 | if bp != "" { |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 66 | optionalBpPreparer = android.FixtureWithRootAndroidBp(bp) |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 67 | } |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 68 | |
| 69 | result := android.GroupFixturePreparers( |
| 70 | prepareForApexTest, |
| 71 | android.GroupFixturePreparers(preparers...), |
| 72 | optionalBpPreparer, |
| 73 | ).RunTest(t) |
| 74 | |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 75 | return result.TestContext |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 76 | } |
| 77 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 78 | func withFiles(files android.MockFS) android.FixturePreparer { |
| 79 | return files.AddToFixture() |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 80 | } |
| 81 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 82 | func withTargets(targets map[android.OsType][]android.Target) android.FixturePreparer { |
| 83 | return android.FixtureModifyConfig(func(config android.Config) { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 84 | for k, v := range targets { |
| 85 | config.Targets[k] = v |
| 86 | } |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 87 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 88 | } |
| 89 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 90 | // withNativeBridgeTargets sets configuration with targets including: |
| 91 | // - X86_64 (primary) |
| 92 | // - X86 (secondary) |
| 93 | // - Arm64 on X86_64 (native bridge) |
| 94 | // - Arm on X86 (native bridge) |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 95 | var withNativeBridgeEnabled = android.FixtureModifyConfig( |
| 96 | func(config android.Config) { |
| 97 | config.Targets[android.Android] = []android.Target{ |
| 98 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, |
| 99 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 100 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, |
| 101 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 102 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, |
| 103 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"}, |
| 104 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 105 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"}, |
| 106 | } |
| 107 | }, |
| 108 | ) |
| 109 | |
| 110 | func withManifestPackageNameOverrides(specs []string) android.FixturePreparer { |
| 111 | return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 112 | variables.ManifestPackageNameOverrides = specs |
| 113 | }) |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 114 | } |
| 115 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 116 | var withBinder32bit = android.FixtureModifyProductVariables( |
| 117 | func(variables android.FixtureProductVariables) { |
| 118 | variables.Binder32bit = proptools.BoolPtr(true) |
| 119 | }, |
| 120 | ) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 121 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 122 | var withUnbundledBuild = android.FixtureModifyProductVariables( |
| 123 | func(variables android.FixtureProductVariables) { |
| 124 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 125 | }, |
| 126 | ) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 127 | |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 128 | // Legacy preparer used for running tests within the apex package. |
| 129 | // |
| 130 | // This includes everything that was needed to run any test in the apex package prior to the |
| 131 | // introduction of the test fixtures. Tests that are being converted to use fixtures directly |
| 132 | // rather than through the testApex...() methods should avoid using this and instead use the |
| 133 | // various preparers directly, using android.GroupFixturePreparers(...) to group them when |
| 134 | // necessary. |
| 135 | // |
| 136 | // deprecated |
| 137 | var prepareForApexTest = android.GroupFixturePreparers( |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 138 | // General preparers in alphabetical order as test infrastructure will enforce correct |
| 139 | // registration order. |
| 140 | android.PrepareForTestWithAndroidBuildComponents, |
| 141 | bpf.PrepareForTestWithBpf, |
| 142 | cc.PrepareForTestWithCcBuildComponents, |
| 143 | java.PrepareForTestWithJavaDefaultModules, |
| 144 | prebuilt_etc.PrepareForTestWithPrebuiltEtc, |
| 145 | rust.PrepareForTestWithRustDefaultModules, |
| 146 | sh.PrepareForTestWithShBuildComponents, |
| 147 | |
| 148 | PrepareForTestWithApexBuildComponents, |
| 149 | |
| 150 | // Additional apex test specific preparers. |
| 151 | android.FixtureAddTextFile("system/sepolicy/Android.bp", ` |
| 152 | filegroup { |
| 153 | name: "myapex-file_contexts", |
| 154 | srcs: [ |
| 155 | "apex/myapex-file_contexts", |
| 156 | ], |
| 157 | } |
| 158 | `), |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 159 | prepareForTestWithMyapex, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 160 | android.FixtureMergeMockFs(android.MockFS{ |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 161 | "a.java": nil, |
| 162 | "PrebuiltAppFoo.apk": nil, |
| 163 | "PrebuiltAppFooPriv.apk": nil, |
| 164 | "apex_manifest.json": nil, |
| 165 | "AndroidManifest.xml": nil, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 166 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
| 167 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
| 168 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 169 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
| 170 | "system/sepolicy/apex/com.android.vndk.current-file_contexts": nil, |
| 171 | "mylib.cpp": nil, |
| 172 | "mytest.cpp": nil, |
| 173 | "mytest1.cpp": nil, |
| 174 | "mytest2.cpp": nil, |
| 175 | "mytest3.cpp": nil, |
| 176 | "myprebuilt": nil, |
| 177 | "my_include": nil, |
| 178 | "foo/bar/MyClass.java": nil, |
| 179 | "prebuilt.jar": nil, |
| 180 | "prebuilt.so": nil, |
| 181 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 182 | "vendor/foo/devkeys/test.pk8": nil, |
| 183 | "testkey.x509.pem": nil, |
| 184 | "testkey.pk8": nil, |
| 185 | "testkey.override.x509.pem": nil, |
| 186 | "testkey.override.pk8": nil, |
| 187 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 188 | "vendor/foo/devkeys/testkey.pem": nil, |
| 189 | "NOTICE": nil, |
| 190 | "custom_notice": nil, |
| 191 | "custom_notice_for_static_lib": nil, |
| 192 | "testkey2.avbpubkey": nil, |
| 193 | "testkey2.pem": nil, |
| 194 | "myapex-arm64.apex": nil, |
| 195 | "myapex-arm.apex": nil, |
| 196 | "myapex.apks": nil, |
| 197 | "frameworks/base/api/current.txt": nil, |
| 198 | "framework/aidl/a.aidl": nil, |
| 199 | "build/make/core/proguard.flags": nil, |
| 200 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 201 | "dummy.txt": nil, |
| 202 | "baz": nil, |
| 203 | "bar/baz": nil, |
| 204 | "testdata/baz": nil, |
| 205 | "AppSet.apks": nil, |
| 206 | "foo.rs": nil, |
| 207 | "libfoo.jar": nil, |
| 208 | "libbar.jar": nil, |
| 209 | }, |
| 210 | ), |
| 211 | |
| 212 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 213 | variables.DeviceVndkVersion = proptools.StringPtr("current") |
| 214 | variables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 215 | variables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 216 | variables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 217 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
| 218 | variables.Platform_version_active_codenames = []string{"Q"} |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 219 | variables.Platform_vndk_version = proptools.StringPtr("29") |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 220 | }), |
| 221 | ) |
| 222 | |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 223 | var prepareForTestWithMyapex = android.FixtureMergeMockFs(android.MockFS{ |
| 224 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 225 | }) |
| 226 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 227 | // ensure that 'result' equals 'expected' |
| 228 | func ensureEquals(t *testing.T, result string, expected string) { |
| 229 | t.Helper() |
| 230 | if result != expected { |
| 231 | t.Errorf("%q != %q", expected, result) |
| 232 | } |
| 233 | } |
| 234 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 235 | // ensure that 'result' contains 'expected' |
| 236 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 237 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 238 | if !strings.Contains(result, expected) { |
| 239 | t.Errorf("%q is not found in %q", expected, result) |
| 240 | } |
| 241 | } |
| 242 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 243 | // ensure that 'result' contains 'expected' exactly one time |
| 244 | func ensureContainsOnce(t *testing.T, result string, expected string) { |
| 245 | t.Helper() |
| 246 | count := strings.Count(result, expected) |
| 247 | if count != 1 { |
| 248 | t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result) |
| 249 | } |
| 250 | } |
| 251 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 252 | // ensures that 'result' does not contain 'notExpected' |
| 253 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 254 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 255 | if strings.Contains(result, notExpected) { |
| 256 | t.Errorf("%q is found in %q", notExpected, result) |
| 257 | } |
| 258 | } |
| 259 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 260 | func ensureMatches(t *testing.T, result string, expectedRex string) { |
| 261 | ok, err := regexp.MatchString(expectedRex, result) |
| 262 | if err != nil { |
| 263 | t.Fatalf("regexp failure trying to match %s against `%s` expression: %s", result, expectedRex, err) |
| 264 | return |
| 265 | } |
| 266 | if !ok { |
| 267 | t.Errorf("%s does not match regular expession %s", result, expectedRex) |
| 268 | } |
| 269 | } |
| 270 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 271 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 272 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 273 | if !android.InList(expected, result) { |
| 274 | t.Errorf("%q is not found in %v", expected, result) |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 279 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 280 | if android.InList(notExpected, result) { |
| 281 | t.Errorf("%q is found in %v", notExpected, result) |
| 282 | } |
| 283 | } |
| 284 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 285 | func ensureListEmpty(t *testing.T, result []string) { |
| 286 | t.Helper() |
| 287 | if len(result) > 0 { |
| 288 | t.Errorf("%q is expected to be empty", result) |
| 289 | } |
| 290 | } |
| 291 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 292 | func ensureListNotEmpty(t *testing.T, result []string) { |
| 293 | t.Helper() |
| 294 | if len(result) == 0 { |
| 295 | t.Errorf("%q is expected to be not empty", result) |
| 296 | } |
| 297 | } |
| 298 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 299 | // Minimal test |
| 300 | func TestBasicApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 301 | ctx := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 302 | apex_defaults { |
| 303 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 304 | manifest: ":myapex.manifest", |
| 305 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 306 | key: "myapex.key", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 307 | binaries: ["foo.rust"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 308 | native_shared_libs: [ |
| 309 | "mylib", |
| 310 | "libfoo.ffi", |
| 311 | ], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 312 | rust_dyn_libs: ["libfoo.dylib.rust"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 313 | multilib: { |
| 314 | both: { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 315 | binaries: ["foo"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 316 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 317 | }, |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 318 | java_libs: [ |
| 319 | "myjar", |
| 320 | "myjar_dex", |
| 321 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 322 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 323 | } |
| 324 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 325 | apex { |
| 326 | name: "myapex", |
| 327 | defaults: ["myapex-defaults"], |
| 328 | } |
| 329 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 330 | apex_key { |
| 331 | name: "myapex.key", |
| 332 | public_key: "testkey.avbpubkey", |
| 333 | private_key: "testkey.pem", |
| 334 | } |
| 335 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 336 | filegroup { |
| 337 | name: "myapex.manifest", |
| 338 | srcs: ["apex_manifest.json"], |
| 339 | } |
| 340 | |
| 341 | filegroup { |
| 342 | name: "myapex.androidmanifest", |
| 343 | srcs: ["AndroidManifest.xml"], |
| 344 | } |
| 345 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 346 | cc_library { |
| 347 | name: "mylib", |
| 348 | srcs: ["mylib.cpp"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 349 | shared_libs: [ |
| 350 | "mylib2", |
| 351 | "libbar.ffi", |
| 352 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 353 | system_shared_libs: [], |
| 354 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 355 | // TODO: remove //apex_available:platform |
| 356 | apex_available: [ |
| 357 | "//apex_available:platform", |
| 358 | "myapex", |
| 359 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 360 | } |
| 361 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 362 | cc_binary { |
| 363 | name: "foo", |
| 364 | srcs: ["mylib.cpp"], |
| 365 | compile_multilib: "both", |
| 366 | multilib: { |
| 367 | lib32: { |
| 368 | suffix: "32", |
| 369 | }, |
| 370 | lib64: { |
| 371 | suffix: "64", |
| 372 | }, |
| 373 | }, |
| 374 | symlinks: ["foo_link_"], |
| 375 | symlink_preferred_arch: true, |
| 376 | system_shared_libs: [], |
| 377 | static_executable: true, |
| 378 | stl: "none", |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 379 | apex_available: [ "myapex", "com.android.gki.*" ], |
| 380 | } |
| 381 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 382 | rust_binary { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 383 | name: "foo.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 384 | srcs: ["foo.rs"], |
| 385 | rlibs: ["libfoo.rlib.rust"], |
| 386 | dylibs: ["libfoo.dylib.rust"], |
| 387 | apex_available: ["myapex"], |
| 388 | } |
| 389 | |
| 390 | rust_library_rlib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 391 | name: "libfoo.rlib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 392 | srcs: ["foo.rs"], |
| 393 | crate_name: "foo", |
| 394 | apex_available: ["myapex"], |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 395 | shared_libs: ["libfoo.shared_from_rust"], |
| 396 | } |
| 397 | |
| 398 | cc_library_shared { |
| 399 | name: "libfoo.shared_from_rust", |
| 400 | srcs: ["mylib.cpp"], |
| 401 | system_shared_libs: [], |
| 402 | stl: "none", |
| 403 | apex_available: ["myapex"], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | rust_library_dylib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 407 | name: "libfoo.dylib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 408 | srcs: ["foo.rs"], |
| 409 | crate_name: "foo", |
| 410 | apex_available: ["myapex"], |
| 411 | } |
| 412 | |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 413 | rust_ffi_shared { |
| 414 | name: "libfoo.ffi", |
| 415 | srcs: ["foo.rs"], |
| 416 | crate_name: "foo", |
| 417 | apex_available: ["myapex"], |
| 418 | } |
| 419 | |
| 420 | rust_ffi_shared { |
| 421 | name: "libbar.ffi", |
| 422 | srcs: ["foo.rs"], |
| 423 | crate_name: "bar", |
| 424 | apex_available: ["myapex"], |
| 425 | } |
| 426 | |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 427 | apex { |
| 428 | name: "com.android.gki.fake", |
| 429 | binaries: ["foo"], |
| 430 | key: "myapex.key", |
| 431 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 432 | updatable: false, |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 435 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 436 | name: "mylib2", |
| 437 | srcs: ["mylib.cpp"], |
| 438 | system_shared_libs: [], |
| 439 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 440 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 441 | static_libs: ["libstatic"], |
| 442 | // TODO: remove //apex_available:platform |
| 443 | apex_available: [ |
| 444 | "//apex_available:platform", |
| 445 | "myapex", |
| 446 | ], |
| 447 | } |
| 448 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 449 | cc_prebuilt_library_shared { |
| 450 | name: "mylib2", |
| 451 | srcs: ["prebuilt.so"], |
| 452 | // TODO: remove //apex_available:platform |
| 453 | apex_available: [ |
| 454 | "//apex_available:platform", |
| 455 | "myapex", |
| 456 | ], |
| 457 | } |
| 458 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 459 | cc_library_static { |
| 460 | name: "libstatic", |
| 461 | srcs: ["mylib.cpp"], |
| 462 | system_shared_libs: [], |
| 463 | stl: "none", |
| 464 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 465 | // TODO: remove //apex_available:platform |
| 466 | apex_available: [ |
| 467 | "//apex_available:platform", |
| 468 | "myapex", |
| 469 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 470 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 471 | |
| 472 | java_library { |
| 473 | name: "myjar", |
| 474 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 475 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 476 | sdk_version: "none", |
| 477 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 478 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 479 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 480 | // TODO: remove //apex_available:platform |
| 481 | apex_available: [ |
| 482 | "//apex_available:platform", |
| 483 | "myapex", |
| 484 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 485 | } |
| 486 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 487 | dex_import { |
| 488 | name: "myjar_dex", |
| 489 | jars: ["prebuilt.jar"], |
| 490 | apex_available: [ |
| 491 | "//apex_available:platform", |
| 492 | "myapex", |
| 493 | ], |
| 494 | } |
| 495 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 496 | java_library { |
| 497 | name: "myotherjar", |
| 498 | srcs: ["foo/bar/MyClass.java"], |
| 499 | sdk_version: "none", |
| 500 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 501 | // TODO: remove //apex_available:platform |
| 502 | apex_available: [ |
| 503 | "//apex_available:platform", |
| 504 | "myapex", |
| 505 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 506 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 507 | |
| 508 | java_library { |
| 509 | name: "mysharedjar", |
| 510 | srcs: ["foo/bar/MyClass.java"], |
| 511 | sdk_version: "none", |
| 512 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 513 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 514 | `) |
| 515 | |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 516 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 517 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 518 | // Make sure that Android.mk is created |
| 519 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 520 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 521 | var builder strings.Builder |
| 522 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 523 | |
| 524 | androidMk := builder.String() |
| 525 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 526 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 527 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 528 | optFlags := apexRule.Args["opt_flags"] |
| 529 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 530 | // Ensure that the NOTICE output is being packaged as an asset. |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 531 | ensureContains(t, optFlags, "--assets_dir out/soong/.intermediates/myapex/android_common_myapex_image/NOTICE") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 532 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 533 | copyCmds := apexRule.Args["copy_commands"] |
| 534 | |
| 535 | // Ensure that main rule creates an output |
| 536 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 537 | |
| 538 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 539 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 540 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") |
| 541 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 542 | ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 543 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 544 | |
| 545 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 546 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
| 547 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 548 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000") |
| 549 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.dylib.rust"), "android_arm64_armv8-a_dylib_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 550 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 551 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.shared_from_rust"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 552 | |
| 553 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 554 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 555 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 556 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 557 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 558 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 559 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so") |
| 560 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so") |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 561 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 562 | // .. but not for java libs |
| 563 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 564 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 565 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 566 | // Ensure that the platform variant ends with _shared or _common |
| 567 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 568 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 569 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 570 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 571 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 572 | |
| 573 | // Ensure that dynamic dependency to java libs are not included |
| 574 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 575 | |
| 576 | // Ensure that all symlinks are present. |
| 577 | found_foo_link_64 := false |
| 578 | found_foo := false |
| 579 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 580 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 581 | if strings.HasSuffix(cmd, "bin/foo") { |
| 582 | found_foo = true |
| 583 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 584 | found_foo_link_64 = true |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | good := found_foo && found_foo_link_64 |
| 589 | if !good { |
| 590 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 591 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 592 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 593 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 594 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 595 | if len(noticeInputs) != 3 { |
| 596 | 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] | 597 | } |
| 598 | ensureListContains(t, noticeInputs, "NOTICE") |
| 599 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 600 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 601 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 602 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 603 | ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 604 | ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib") |
| 605 | ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar") |
| 606 | ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 607 | |
| 608 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 609 | ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 610 | ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))") |
| 611 | ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))") |
| 612 | ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 613 | } |
| 614 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 615 | func TestDefaults(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 616 | ctx := testApex(t, ` |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 617 | apex_defaults { |
| 618 | name: "myapex-defaults", |
| 619 | key: "myapex.key", |
| 620 | prebuilts: ["myetc"], |
| 621 | native_shared_libs: ["mylib"], |
| 622 | java_libs: ["myjar"], |
| 623 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 624 | rros: ["rro"], |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 625 | bpfs: ["bpf"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 626 | updatable: false, |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | prebuilt_etc { |
| 630 | name: "myetc", |
| 631 | src: "myprebuilt", |
| 632 | } |
| 633 | |
| 634 | apex { |
| 635 | name: "myapex", |
| 636 | defaults: ["myapex-defaults"], |
| 637 | } |
| 638 | |
| 639 | apex_key { |
| 640 | name: "myapex.key", |
| 641 | public_key: "testkey.avbpubkey", |
| 642 | private_key: "testkey.pem", |
| 643 | } |
| 644 | |
| 645 | cc_library { |
| 646 | name: "mylib", |
| 647 | system_shared_libs: [], |
| 648 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 649 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | java_library { |
| 653 | name: "myjar", |
| 654 | srcs: ["foo/bar/MyClass.java"], |
| 655 | sdk_version: "none", |
| 656 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 657 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | android_app { |
| 661 | name: "AppFoo", |
| 662 | srcs: ["foo/bar/MyClass.java"], |
| 663 | sdk_version: "none", |
| 664 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 665 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 666 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 667 | |
| 668 | runtime_resource_overlay { |
| 669 | name: "rro", |
| 670 | theme: "blue", |
| 671 | } |
| 672 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 673 | bpf { |
| 674 | name: "bpf", |
| 675 | srcs: ["bpf.c", "bpf2.c"], |
| 676 | } |
| 677 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 678 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 679 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 680 | "etc/myetc", |
| 681 | "javalib/myjar.jar", |
| 682 | "lib64/mylib.so", |
| 683 | "app/AppFoo/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 684 | "overlay/blue/rro.apk", |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 685 | "etc/bpf/bpf.o", |
| 686 | "etc/bpf/bpf2.o", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 687 | }) |
| 688 | } |
| 689 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 690 | func TestApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 691 | ctx := testApex(t, ` |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 692 | apex { |
| 693 | name: "myapex", |
| 694 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 695 | updatable: false, |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | apex_key { |
| 699 | name: "myapex.key", |
| 700 | public_key: "testkey.avbpubkey", |
| 701 | private_key: "testkey.pem", |
| 702 | } |
| 703 | `) |
| 704 | |
| 705 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 706 | args := module.Rule("apexRule").Args |
| 707 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 708 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 709 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 710 | } |
| 711 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 712 | func TestBasicZipApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 713 | ctx := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 714 | apex { |
| 715 | name: "myapex", |
| 716 | key: "myapex.key", |
| 717 | payload_type: "zip", |
| 718 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 719 | updatable: false, |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | apex_key { |
| 723 | name: "myapex.key", |
| 724 | public_key: "testkey.avbpubkey", |
| 725 | private_key: "testkey.pem", |
| 726 | } |
| 727 | |
| 728 | cc_library { |
| 729 | name: "mylib", |
| 730 | srcs: ["mylib.cpp"], |
| 731 | shared_libs: ["mylib2"], |
| 732 | system_shared_libs: [], |
| 733 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 734 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | cc_library { |
| 738 | name: "mylib2", |
| 739 | srcs: ["mylib.cpp"], |
| 740 | system_shared_libs: [], |
| 741 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 742 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 743 | } |
| 744 | `) |
| 745 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 746 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 747 | copyCmds := zipApexRule.Args["copy_commands"] |
| 748 | |
| 749 | // Ensure that main rule creates an output |
| 750 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 751 | |
| 752 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 753 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 754 | |
| 755 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 756 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 757 | |
| 758 | // Ensure that both direct and indirect deps are copied into apex |
| 759 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 760 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | func TestApexWithStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 764 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 765 | apex { |
| 766 | name: "myapex", |
| 767 | key: "myapex.key", |
| 768 | native_shared_libs: ["mylib", "mylib3"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 769 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | apex_key { |
| 773 | name: "myapex.key", |
| 774 | public_key: "testkey.avbpubkey", |
| 775 | private_key: "testkey.pem", |
| 776 | } |
| 777 | |
| 778 | cc_library { |
| 779 | name: "mylib", |
| 780 | srcs: ["mylib.cpp"], |
| 781 | shared_libs: ["mylib2", "mylib3"], |
| 782 | system_shared_libs: [], |
| 783 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 784 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | cc_library { |
| 788 | name: "mylib2", |
| 789 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 790 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 791 | system_shared_libs: [], |
| 792 | stl: "none", |
| 793 | stubs: { |
| 794 | versions: ["1", "2", "3"], |
| 795 | }, |
| 796 | } |
| 797 | |
| 798 | cc_library { |
| 799 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 800 | srcs: ["mylib.cpp"], |
| 801 | shared_libs: ["mylib4"], |
| 802 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 803 | stl: "none", |
| 804 | stubs: { |
| 805 | versions: ["10", "11", "12"], |
| 806 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 807 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 808 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 809 | |
| 810 | cc_library { |
| 811 | name: "mylib4", |
| 812 | srcs: ["mylib.cpp"], |
| 813 | system_shared_libs: [], |
| 814 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 815 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 816 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 817 | `) |
| 818 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 819 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 820 | copyCmds := apexRule.Args["copy_commands"] |
| 821 | |
| 822 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 823 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 824 | |
| 825 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 826 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 827 | |
| 828 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 829 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 830 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 831 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 832 | |
| 833 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 834 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 835 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 836 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 837 | |
| 838 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 839 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 840 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 841 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 842 | |
| 843 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 844 | 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] | 845 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 846 | |
| 847 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 848 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_3").Rule("genStubSrc").Args["flags"]) |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 849 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 850 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 851 | "lib64/mylib.so", |
| 852 | "lib64/mylib3.so", |
| 853 | "lib64/mylib4.so", |
| 854 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 855 | } |
| 856 | |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 857 | func TestApexWithStubsWithMinSdkVersion(t *testing.T) { |
| 858 | t.Parallel() |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 859 | ctx := testApex(t, ` |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 860 | apex { |
| 861 | name: "myapex", |
| 862 | key: "myapex.key", |
| 863 | native_shared_libs: ["mylib", "mylib3"], |
| 864 | min_sdk_version: "29", |
| 865 | } |
| 866 | |
| 867 | apex_key { |
| 868 | name: "myapex.key", |
| 869 | public_key: "testkey.avbpubkey", |
| 870 | private_key: "testkey.pem", |
| 871 | } |
| 872 | |
| 873 | cc_library { |
| 874 | name: "mylib", |
| 875 | srcs: ["mylib.cpp"], |
| 876 | shared_libs: ["mylib2", "mylib3"], |
| 877 | system_shared_libs: [], |
| 878 | stl: "none", |
| 879 | apex_available: [ "myapex" ], |
| 880 | min_sdk_version: "28", |
| 881 | } |
| 882 | |
| 883 | cc_library { |
| 884 | name: "mylib2", |
| 885 | srcs: ["mylib.cpp"], |
| 886 | cflags: ["-include mylib.h"], |
| 887 | system_shared_libs: [], |
| 888 | stl: "none", |
| 889 | stubs: { |
| 890 | versions: ["28", "29", "30", "current"], |
| 891 | }, |
| 892 | min_sdk_version: "28", |
| 893 | } |
| 894 | |
| 895 | cc_library { |
| 896 | name: "mylib3", |
| 897 | srcs: ["mylib.cpp"], |
| 898 | shared_libs: ["mylib4"], |
| 899 | system_shared_libs: [], |
| 900 | stl: "none", |
| 901 | stubs: { |
| 902 | versions: ["28", "29", "30", "current"], |
| 903 | }, |
| 904 | apex_available: [ "myapex" ], |
| 905 | min_sdk_version: "28", |
| 906 | } |
| 907 | |
| 908 | cc_library { |
| 909 | name: "mylib4", |
| 910 | srcs: ["mylib.cpp"], |
| 911 | system_shared_libs: [], |
| 912 | stl: "none", |
| 913 | apex_available: [ "myapex" ], |
| 914 | min_sdk_version: "28", |
| 915 | } |
| 916 | `) |
| 917 | |
| 918 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 919 | copyCmds := apexRule.Args["copy_commands"] |
| 920 | |
| 921 | // Ensure that direct non-stubs dep is always included |
| 922 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 923 | |
| 924 | // Ensure that indirect stubs dep is not included |
| 925 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 926 | |
| 927 | // Ensure that direct stubs dep is included |
| 928 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 929 | |
| 930 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"] |
| 931 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 932 | // Ensure that mylib is linking with the latest version of stub for mylib2 |
| 933 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 934 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| 935 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 936 | |
| 937 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| 938 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so") |
| 939 | // .. and not linking to the stubs variant of mylib3 |
| 940 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so") |
| 941 | |
| 942 | // Ensure that stubs libs are built without -include flags |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 943 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("cc").Args["cFlags"] |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 944 | ensureNotContains(t, mylib2Cflags, "-include ") |
| 945 | |
| 946 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 947 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("genStubSrc").Args["flags"]) |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 948 | |
| 949 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 950 | "lib64/mylib.so", |
| 951 | "lib64/mylib3.so", |
| 952 | "lib64/mylib4.so", |
| 953 | }) |
| 954 | } |
| 955 | |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 956 | func TestApex_PlatformUsesLatestStubFromApex(t *testing.T) { |
| 957 | t.Parallel() |
| 958 | // myapex (Z) |
| 959 | // mylib -----------------. |
| 960 | // | |
| 961 | // otherapex (29) | |
| 962 | // libstub's versions: 29 Z current |
| 963 | // | |
| 964 | // <platform> | |
| 965 | // libplatform ----------------' |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 966 | ctx := testApex(t, ` |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 967 | apex { |
| 968 | name: "myapex", |
| 969 | key: "myapex.key", |
| 970 | native_shared_libs: ["mylib"], |
| 971 | min_sdk_version: "Z", // non-final |
| 972 | } |
| 973 | |
| 974 | cc_library { |
| 975 | name: "mylib", |
| 976 | srcs: ["mylib.cpp"], |
| 977 | shared_libs: ["libstub"], |
| 978 | apex_available: ["myapex"], |
| 979 | min_sdk_version: "Z", |
| 980 | } |
| 981 | |
| 982 | apex_key { |
| 983 | name: "myapex.key", |
| 984 | public_key: "testkey.avbpubkey", |
| 985 | private_key: "testkey.pem", |
| 986 | } |
| 987 | |
| 988 | apex { |
| 989 | name: "otherapex", |
| 990 | key: "myapex.key", |
| 991 | native_shared_libs: ["libstub"], |
| 992 | min_sdk_version: "29", |
| 993 | } |
| 994 | |
| 995 | cc_library { |
| 996 | name: "libstub", |
| 997 | srcs: ["mylib.cpp"], |
| 998 | stubs: { |
| 999 | versions: ["29", "Z", "current"], |
| 1000 | }, |
| 1001 | apex_available: ["otherapex"], |
| 1002 | min_sdk_version: "29", |
| 1003 | } |
| 1004 | |
| 1005 | // platform module depending on libstub from otherapex should use the latest stub("current") |
| 1006 | cc_library { |
| 1007 | name: "libplatform", |
| 1008 | srcs: ["mylib.cpp"], |
| 1009 | shared_libs: ["libstub"], |
| 1010 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1011 | `, |
| 1012 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1013 | variables.Platform_sdk_codename = proptools.StringPtr("Z") |
| 1014 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
| 1015 | variables.Platform_version_active_codenames = []string{"Z"} |
| 1016 | }), |
| 1017 | ) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1018 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1019 | // Ensure that mylib from myapex is built against the latest stub (current) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1020 | mylibCflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1021 | ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=10000 ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1022 | mylibLdflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1023 | ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1024 | |
| 1025 | // Ensure that libplatform is built against latest stub ("current") of mylib3 from the apex |
| 1026 | libplatformCflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1027 | ensureContains(t, libplatformCflags, "-D__LIBSTUB_API__=10000 ") // "current" maps to 10000 |
| 1028 | libplatformLdflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1029 | ensureContains(t, libplatformLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
| 1030 | } |
| 1031 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1032 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1033 | ctx := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1034 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1035 | name: "myapex2", |
| 1036 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1037 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1038 | updatable: false, |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1042 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1043 | public_key: "testkey.avbpubkey", |
| 1044 | private_key: "testkey.pem", |
| 1045 | } |
| 1046 | |
| 1047 | cc_library { |
| 1048 | name: "mylib", |
| 1049 | srcs: ["mylib.cpp"], |
| 1050 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1051 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1052 | system_shared_libs: [], |
| 1053 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1054 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | cc_library { |
| 1058 | name: "libfoo", |
| 1059 | srcs: ["mylib.cpp"], |
| 1060 | shared_libs: ["libbar"], |
| 1061 | system_shared_libs: [], |
| 1062 | stl: "none", |
| 1063 | stubs: { |
| 1064 | versions: ["10", "20", "30"], |
| 1065 | }, |
| 1066 | } |
| 1067 | |
| 1068 | cc_library { |
| 1069 | name: "libbar", |
| 1070 | srcs: ["mylib.cpp"], |
| 1071 | system_shared_libs: [], |
| 1072 | stl: "none", |
| 1073 | } |
| 1074 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1075 | cc_library_static { |
| 1076 | name: "libbaz", |
| 1077 | srcs: ["mylib.cpp"], |
| 1078 | system_shared_libs: [], |
| 1079 | stl: "none", |
| 1080 | apex_available: [ "myapex2" ], |
| 1081 | } |
| 1082 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1083 | `) |
| 1084 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1085 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1086 | copyCmds := apexRule.Args["copy_commands"] |
| 1087 | |
| 1088 | // Ensure that direct non-stubs dep is always included |
| 1089 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1090 | |
| 1091 | // Ensure that indirect stubs dep is not included |
| 1092 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1093 | |
| 1094 | // Ensure that dependency of stubs is not included |
| 1095 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1096 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1097 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1098 | |
| 1099 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1100 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1101 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1102 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1103 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1104 | 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] | 1105 | |
| 1106 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 1107 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1108 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1109 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 1110 | ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1111 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1112 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 1113 | ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1114 | } |
| 1115 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1116 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 1117 | /* |
| 1118 | myapex |
| 1119 | | |
| 1120 | v (runtime_libs) |
| 1121 | mylib ------+------> libfoo [provides stub] |
| 1122 | | |
| 1123 | `------> libbar |
| 1124 | */ |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1125 | ctx := testApex(t, ` |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1126 | apex { |
| 1127 | name: "myapex", |
| 1128 | key: "myapex.key", |
| 1129 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1130 | updatable: false, |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | apex_key { |
| 1134 | name: "myapex.key", |
| 1135 | public_key: "testkey.avbpubkey", |
| 1136 | private_key: "testkey.pem", |
| 1137 | } |
| 1138 | |
| 1139 | cc_library { |
| 1140 | name: "mylib", |
| 1141 | srcs: ["mylib.cpp"], |
| 1142 | runtime_libs: ["libfoo", "libbar"], |
| 1143 | system_shared_libs: [], |
| 1144 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1145 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | cc_library { |
| 1149 | name: "libfoo", |
| 1150 | srcs: ["mylib.cpp"], |
| 1151 | system_shared_libs: [], |
| 1152 | stl: "none", |
| 1153 | stubs: { |
| 1154 | versions: ["10", "20", "30"], |
| 1155 | }, |
| 1156 | } |
| 1157 | |
| 1158 | cc_library { |
| 1159 | name: "libbar", |
| 1160 | srcs: ["mylib.cpp"], |
| 1161 | system_shared_libs: [], |
| 1162 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1163 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | `) |
| 1167 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1168 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1169 | copyCmds := apexRule.Args["copy_commands"] |
| 1170 | |
| 1171 | // Ensure that direct non-stubs dep is always included |
| 1172 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1173 | |
| 1174 | // Ensure that indirect stubs dep is not included |
| 1175 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1176 | |
| 1177 | // Ensure that runtime_libs dep in included |
| 1178 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1179 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1180 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1181 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1182 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1183 | |
| 1184 | } |
| 1185 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1186 | var prepareForTestOfRuntimeApexWithHwasan = android.GroupFixturePreparers( |
| 1187 | cc.PrepareForTestWithCcBuildComponents, |
| 1188 | PrepareForTestWithApexBuildComponents, |
| 1189 | android.FixtureAddTextFile("bionic/apex/Android.bp", ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1190 | apex { |
| 1191 | name: "com.android.runtime", |
| 1192 | key: "com.android.runtime.key", |
| 1193 | native_shared_libs: ["libc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1194 | updatable: false, |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | apex_key { |
| 1198 | name: "com.android.runtime.key", |
| 1199 | public_key: "testkey.avbpubkey", |
| 1200 | private_key: "testkey.pem", |
| 1201 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1202 | `), |
| 1203 | android.FixtureAddFile("system/sepolicy/apex/com.android.runtime-file_contexts", nil), |
| 1204 | ) |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1205 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1206 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1207 | result := android.GroupFixturePreparers(prepareForTestOfRuntimeApexWithHwasan).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1208 | cc_library { |
| 1209 | name: "libc", |
| 1210 | no_libcrt: true, |
| 1211 | nocrt: true, |
| 1212 | stl: "none", |
| 1213 | system_shared_libs: [], |
| 1214 | stubs: { versions: ["1"] }, |
| 1215 | apex_available: ["com.android.runtime"], |
| 1216 | |
| 1217 | sanitize: { |
| 1218 | hwaddress: true, |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | cc_prebuilt_library_shared { |
| 1223 | name: "libclang_rt.hwasan-aarch64-android", |
| 1224 | no_libcrt: true, |
| 1225 | nocrt: true, |
| 1226 | stl: "none", |
| 1227 | system_shared_libs: [], |
| 1228 | srcs: [""], |
| 1229 | stubs: { versions: ["1"] }, |
| 1230 | |
| 1231 | sanitize: { |
| 1232 | never: true, |
| 1233 | }, |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1234 | } `) |
| 1235 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1236 | |
| 1237 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1238 | "lib64/bionic/libc.so", |
| 1239 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1240 | }) |
| 1241 | |
| 1242 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1243 | |
| 1244 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1245 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1246 | |
| 1247 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1248 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1249 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1250 | } |
| 1251 | |
| 1252 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1253 | result := android.GroupFixturePreparers( |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1254 | prepareForTestOfRuntimeApexWithHwasan, |
| 1255 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1256 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1257 | }), |
| 1258 | ).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1259 | cc_library { |
| 1260 | name: "libc", |
| 1261 | no_libcrt: true, |
| 1262 | nocrt: true, |
| 1263 | stl: "none", |
| 1264 | system_shared_libs: [], |
| 1265 | stubs: { versions: ["1"] }, |
| 1266 | apex_available: ["com.android.runtime"], |
| 1267 | } |
| 1268 | |
| 1269 | cc_prebuilt_library_shared { |
| 1270 | name: "libclang_rt.hwasan-aarch64-android", |
| 1271 | no_libcrt: true, |
| 1272 | nocrt: true, |
| 1273 | stl: "none", |
| 1274 | system_shared_libs: [], |
| 1275 | srcs: [""], |
| 1276 | stubs: { versions: ["1"] }, |
| 1277 | |
| 1278 | sanitize: { |
| 1279 | never: true, |
| 1280 | }, |
| 1281 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1282 | `) |
| 1283 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1284 | |
| 1285 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1286 | "lib64/bionic/libc.so", |
| 1287 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1288 | }) |
| 1289 | |
| 1290 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1291 | |
| 1292 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1293 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1294 | |
| 1295 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1296 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1297 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1298 | } |
| 1299 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1300 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1301 | testcases := []struct { |
| 1302 | name string |
| 1303 | minSdkVersion string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1304 | apexVariant string |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1305 | shouldLink string |
| 1306 | shouldNotLink []string |
| 1307 | }{ |
| 1308 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1309 | name: "unspecified version links to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1310 | minSdkVersion: "", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1311 | apexVariant: "apex10000", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1312 | shouldLink: "current", |
| 1313 | shouldNotLink: []string{"29", "30"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1314 | }, |
| 1315 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1316 | name: "always use the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1317 | minSdkVersion: "min_sdk_version: \"29\",", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1318 | apexVariant: "apex29", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1319 | shouldLink: "current", |
| 1320 | shouldNotLink: []string{"29", "30"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1321 | }, |
| 1322 | } |
| 1323 | for _, tc := range testcases { |
| 1324 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1325 | ctx := testApex(t, ` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1326 | apex { |
| 1327 | name: "myapex", |
| 1328 | key: "myapex.key", |
| 1329 | use_vendor: true, |
| 1330 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1331 | updatable: false, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1332 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1333 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1334 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1335 | apex_key { |
| 1336 | name: "myapex.key", |
| 1337 | public_key: "testkey.avbpubkey", |
| 1338 | private_key: "testkey.pem", |
| 1339 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1340 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1341 | cc_library { |
| 1342 | name: "mylib", |
| 1343 | srcs: ["mylib.cpp"], |
| 1344 | vendor_available: true, |
| 1345 | shared_libs: ["libbar"], |
| 1346 | system_shared_libs: [], |
| 1347 | stl: "none", |
| 1348 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1349 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1350 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1351 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1352 | cc_library { |
| 1353 | name: "libbar", |
| 1354 | srcs: ["mylib.cpp"], |
| 1355 | system_shared_libs: [], |
| 1356 | stl: "none", |
| 1357 | stubs: { versions: ["29","30"] }, |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1358 | llndk_stubs: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1359 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1360 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1361 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1362 | name: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1363 | symbol_file: "", |
| 1364 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1365 | `, |
| 1366 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 1367 | withUnbundledBuild, |
| 1368 | ) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1369 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1370 | // Ensure that LLNDK dep is not included |
| 1371 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1372 | "lib64/mylib.so", |
| 1373 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1374 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1375 | // Ensure that LLNDK dep is required |
| 1376 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1377 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1378 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1379 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1380 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.29_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"] |
| 1381 | ensureContains(t, mylibLdFlags, "libbar/android_vendor.29_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1382 | for _, ver := range tc.shouldNotLink { |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1383 | ensureNotContains(t, mylibLdFlags, "libbar/android_vendor.29_arm64_armv8-a_shared_"+ver+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1384 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1385 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1386 | mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.29_arm64_armv8-a_static_"+tc.apexVariant).Rule("cc").Args["cFlags"] |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1387 | ver := tc.shouldLink |
| 1388 | if tc.shouldLink == "current" { |
| 1389 | ver = strconv.Itoa(android.FutureApiLevelInt) |
| 1390 | } |
| 1391 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+ver) |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1392 | }) |
| 1393 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1394 | } |
| 1395 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1396 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1397 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1398 | apex { |
| 1399 | name: "myapex", |
| 1400 | key: "myapex.key", |
| 1401 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1402 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | apex_key { |
| 1406 | name: "myapex.key", |
| 1407 | public_key: "testkey.avbpubkey", |
| 1408 | private_key: "testkey.pem", |
| 1409 | } |
| 1410 | |
| 1411 | cc_library { |
| 1412 | name: "mylib", |
| 1413 | srcs: ["mylib.cpp"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1414 | system_shared_libs: ["libc", "libm"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1415 | shared_libs: ["libdl#27"], |
| 1416 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1417 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | cc_library_shared { |
| 1421 | name: "mylib_shared", |
| 1422 | srcs: ["mylib.cpp"], |
| 1423 | shared_libs: ["libdl#27"], |
| 1424 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1425 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1429 | name: "libBootstrap", |
| 1430 | srcs: ["mylib.cpp"], |
| 1431 | stl: "none", |
| 1432 | bootstrap: true, |
| 1433 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1434 | `) |
| 1435 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1436 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1437 | copyCmds := apexRule.Args["copy_commands"] |
| 1438 | |
| 1439 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1440 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1441 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1442 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1443 | |
| 1444 | // 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] | 1445 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1446 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1447 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1448 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1449 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_apex10000").Rule("cc").Args["cFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1450 | |
| 1451 | // For dependency to libc |
| 1452 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1453 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_current/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1454 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1455 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1456 | // ... Cflags from stub is correctly exported to mylib |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1457 | ensureContains(t, mylibCFlags, "__LIBC_API__=10000") |
| 1458 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1459 | |
| 1460 | // For dependency to libm |
| 1461 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1462 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1463 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1464 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1465 | // ... and is not compiling with the stub |
| 1466 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1467 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1468 | |
| 1469 | // For dependency to libdl |
| 1470 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1471 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1472 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1473 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1474 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1475 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1476 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1477 | // ... Cflags from stub is correctly exported to mylib |
| 1478 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1479 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1480 | |
| 1481 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1482 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1483 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1484 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1485 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1486 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1487 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1488 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1489 | // there are three links between liba --> libz. |
| 1490 | // 1) myapex -> libx -> liba -> libz : this should be #30 link |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1491 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1492 | // 3) (platform) -> liba -> libz : this should be non-stub link |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1493 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1494 | apex { |
| 1495 | name: "myapex", |
| 1496 | key: "myapex.key", |
| 1497 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1498 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | apex { |
| 1502 | name: "otherapex", |
| 1503 | key: "myapex.key", |
| 1504 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1505 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | apex_key { |
| 1509 | name: "myapex.key", |
| 1510 | public_key: "testkey.avbpubkey", |
| 1511 | private_key: "testkey.pem", |
| 1512 | } |
| 1513 | |
| 1514 | cc_library { |
| 1515 | name: "libx", |
| 1516 | shared_libs: ["liba"], |
| 1517 | system_shared_libs: [], |
| 1518 | stl: "none", |
| 1519 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1520 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | cc_library { |
| 1524 | name: "liby", |
| 1525 | shared_libs: ["liba"], |
| 1526 | system_shared_libs: [], |
| 1527 | stl: "none", |
| 1528 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1529 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | cc_library { |
| 1533 | name: "liba", |
| 1534 | shared_libs: ["libz"], |
| 1535 | system_shared_libs: [], |
| 1536 | stl: "none", |
| 1537 | apex_available: [ |
| 1538 | "//apex_available:anyapex", |
| 1539 | "//apex_available:platform", |
| 1540 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1541 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | cc_library { |
| 1545 | name: "libz", |
| 1546 | system_shared_libs: [], |
| 1547 | stl: "none", |
| 1548 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1549 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1550 | }, |
| 1551 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1552 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1553 | |
| 1554 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1555 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1556 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1557 | } |
| 1558 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1559 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1560 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1561 | } |
| 1562 | // platform liba is linked to non-stub version |
| 1563 | expectLink("liba", "shared", "libz", "shared") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1564 | // liba in myapex is linked to current |
| 1565 | expectLink("liba", "shared_apex29", "libz", "shared_current") |
| 1566 | expectNoLink("liba", "shared_apex29", "libz", "shared_30") |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1567 | expectNoLink("liba", "shared_apex29", "libz", "shared_28") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1568 | expectNoLink("liba", "shared_apex29", "libz", "shared") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1569 | // liba in otherapex is linked to current |
| 1570 | expectLink("liba", "shared_apex30", "libz", "shared_current") |
| 1571 | expectNoLink("liba", "shared_apex30", "libz", "shared_30") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1572 | expectNoLink("liba", "shared_apex30", "libz", "shared_28") |
| 1573 | expectNoLink("liba", "shared_apex30", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1574 | } |
| 1575 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1576 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1577 | ctx := testApex(t, ` |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1578 | apex { |
| 1579 | name: "myapex", |
| 1580 | key: "myapex.key", |
| 1581 | native_shared_libs: ["libx"], |
| 1582 | min_sdk_version: "R", |
| 1583 | } |
| 1584 | |
| 1585 | apex_key { |
| 1586 | name: "myapex.key", |
| 1587 | public_key: "testkey.avbpubkey", |
| 1588 | private_key: "testkey.pem", |
| 1589 | } |
| 1590 | |
| 1591 | cc_library { |
| 1592 | name: "libx", |
| 1593 | shared_libs: ["libz"], |
| 1594 | system_shared_libs: [], |
| 1595 | stl: "none", |
| 1596 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1597 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | cc_library { |
| 1601 | name: "libz", |
| 1602 | system_shared_libs: [], |
| 1603 | stl: "none", |
| 1604 | stubs: { |
| 1605 | versions: ["29", "R"], |
| 1606 | }, |
| 1607 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1608 | `, |
| 1609 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1610 | variables.Platform_version_active_codenames = []string{"R"} |
| 1611 | }), |
| 1612 | ) |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1613 | |
| 1614 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1615 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1616 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1617 | } |
| 1618 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1619 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1620 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1621 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1622 | expectLink("libx", "shared_apex10000", "libz", "shared_current") |
| 1623 | expectNoLink("libx", "shared_apex10000", "libz", "shared_R") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1624 | expectNoLink("libx", "shared_apex10000", "libz", "shared_29") |
| 1625 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1626 | } |
| 1627 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1628 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1629 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1630 | apex { |
| 1631 | name: "myapex", |
| 1632 | key: "myapex.key", |
| 1633 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1634 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | apex_key { |
| 1638 | name: "myapex.key", |
| 1639 | public_key: "testkey.avbpubkey", |
| 1640 | private_key: "testkey.pem", |
| 1641 | } |
| 1642 | |
| 1643 | cc_library { |
| 1644 | name: "libx", |
| 1645 | shared_libs: ["libz"], |
| 1646 | system_shared_libs: [], |
| 1647 | stl: "none", |
| 1648 | apex_available: [ "myapex" ], |
| 1649 | } |
| 1650 | |
| 1651 | cc_library { |
| 1652 | name: "libz", |
| 1653 | system_shared_libs: [], |
| 1654 | stl: "none", |
| 1655 | stubs: { |
| 1656 | versions: ["1", "2"], |
| 1657 | }, |
| 1658 | } |
| 1659 | `) |
| 1660 | |
| 1661 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1662 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1663 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1664 | } |
| 1665 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1666 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1667 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1668 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1669 | expectLink("libx", "shared_apex10000", "libz", "shared_current") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1670 | expectNoLink("libx", "shared_apex10000", "libz", "shared_1") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1671 | expectNoLink("libx", "shared_apex10000", "libz", "shared_2") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1672 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1676 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1677 | apex { |
| 1678 | name: "myapex", |
| 1679 | key: "myapex.key", |
| 1680 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1681 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | apex_key { |
| 1685 | name: "myapex.key", |
| 1686 | public_key: "testkey.avbpubkey", |
| 1687 | private_key: "testkey.pem", |
| 1688 | } |
| 1689 | |
| 1690 | cc_library { |
| 1691 | name: "libx", |
| 1692 | system_shared_libs: [], |
| 1693 | stl: "none", |
| 1694 | apex_available: [ "myapex" ], |
| 1695 | stubs: { |
| 1696 | versions: ["1", "2"], |
| 1697 | }, |
| 1698 | } |
| 1699 | |
| 1700 | cc_library { |
| 1701 | name: "libz", |
| 1702 | shared_libs: ["libx"], |
| 1703 | system_shared_libs: [], |
| 1704 | stl: "none", |
| 1705 | } |
| 1706 | `) |
| 1707 | |
| 1708 | expectLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1709 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1710 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1711 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1712 | } |
| 1713 | expectNoLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1714 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1715 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1716 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1717 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1718 | expectLink("libz", "shared", "libx", "shared_current") |
| 1719 | expectNoLink("libz", "shared", "libx", "shared_2") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1720 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1721 | expectNoLink("libz", "shared", "libz", "shared") |
| 1722 | } |
| 1723 | |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1724 | var prepareForTestWithSantitizeHwaddress = android.FixtureModifyProductVariables( |
| 1725 | func(variables android.FixtureProductVariables) { |
| 1726 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1727 | }, |
| 1728 | ) |
| 1729 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1730 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1731 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1732 | apex { |
| 1733 | name: "myapex", |
| 1734 | key: "myapex.key", |
| 1735 | native_shared_libs: ["libx"], |
| 1736 | min_sdk_version: "29", |
| 1737 | } |
| 1738 | |
| 1739 | apex_key { |
| 1740 | name: "myapex.key", |
| 1741 | public_key: "testkey.avbpubkey", |
| 1742 | private_key: "testkey.pem", |
| 1743 | } |
| 1744 | |
| 1745 | cc_library { |
| 1746 | name: "libx", |
| 1747 | shared_libs: ["libbar"], |
| 1748 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1749 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | cc_library { |
| 1753 | name: "libbar", |
| 1754 | stubs: { |
| 1755 | versions: ["29", "30"], |
| 1756 | }, |
| 1757 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1758 | `, |
| 1759 | prepareForTestWithSantitizeHwaddress, |
| 1760 | ) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1761 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1762 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1763 | libFlags := ld.Args["libFlags"] |
| 1764 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1765 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1766 | expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_current") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1767 | } |
| 1768 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1769 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1770 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1771 | apex { |
| 1772 | name: "myapex", |
| 1773 | key: "myapex.key", |
| 1774 | native_shared_libs: ["libx"], |
| 1775 | min_sdk_version: "29", |
| 1776 | } |
| 1777 | |
| 1778 | apex_key { |
| 1779 | name: "myapex.key", |
| 1780 | public_key: "testkey.avbpubkey", |
| 1781 | private_key: "testkey.pem", |
| 1782 | } |
| 1783 | |
| 1784 | cc_library { |
| 1785 | name: "libx", |
| 1786 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1787 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1788 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1789 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1790 | |
| 1791 | // ensure apex variant of c++ is linked with static unwinder |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1792 | cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_apex29").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 1793 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1794 | // note that platform variant is not. |
| 1795 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 1796 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1797 | } |
| 1798 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1799 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 1800 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1801 | apex { |
| 1802 | name: "myapex", |
| 1803 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1804 | native_shared_libs: ["mylib"], |
| 1805 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | apex_key { |
| 1809 | name: "myapex.key", |
| 1810 | public_key: "testkey.avbpubkey", |
| 1811 | private_key: "testkey.pem", |
| 1812 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1813 | |
| 1814 | cc_library { |
| 1815 | name: "mylib", |
| 1816 | srcs: ["mylib.cpp"], |
| 1817 | system_shared_libs: [], |
| 1818 | stl: "none", |
| 1819 | apex_available: [ |
| 1820 | "myapex", |
| 1821 | ], |
| 1822 | min_sdk_version: "30", |
| 1823 | } |
| 1824 | `) |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1825 | |
| 1826 | testApexError(t, `module "libfoo.ffi".*: should support min_sdk_version\(29\)`, ` |
| 1827 | apex { |
| 1828 | name: "myapex", |
| 1829 | key: "myapex.key", |
| 1830 | native_shared_libs: ["libfoo.ffi"], |
| 1831 | min_sdk_version: "29", |
| 1832 | } |
| 1833 | |
| 1834 | apex_key { |
| 1835 | name: "myapex.key", |
| 1836 | public_key: "testkey.avbpubkey", |
| 1837 | private_key: "testkey.pem", |
| 1838 | } |
| 1839 | |
| 1840 | rust_ffi_shared { |
| 1841 | name: "libfoo.ffi", |
| 1842 | srcs: ["foo.rs"], |
| 1843 | crate_name: "foo", |
| 1844 | apex_available: [ |
| 1845 | "myapex", |
| 1846 | ], |
| 1847 | min_sdk_version: "30", |
| 1848 | } |
| 1849 | `) |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1850 | |
| 1851 | testApexError(t, `module "libfoo".*: should support min_sdk_version\(29\)`, ` |
| 1852 | apex { |
| 1853 | name: "myapex", |
| 1854 | key: "myapex.key", |
| 1855 | java_libs: ["libfoo"], |
| 1856 | min_sdk_version: "29", |
| 1857 | } |
| 1858 | |
| 1859 | apex_key { |
| 1860 | name: "myapex.key", |
| 1861 | public_key: "testkey.avbpubkey", |
| 1862 | private_key: "testkey.pem", |
| 1863 | } |
| 1864 | |
| 1865 | java_import { |
| 1866 | name: "libfoo", |
| 1867 | jars: ["libfoo.jar"], |
| 1868 | apex_available: [ |
| 1869 | "myapex", |
| 1870 | ], |
| 1871 | min_sdk_version: "30", |
| 1872 | } |
| 1873 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 1877 | testApex(t, ` |
| 1878 | apex { |
| 1879 | name: "myapex", |
| 1880 | key: "myapex.key", |
| 1881 | native_shared_libs: ["libfoo"], |
| 1882 | java_libs: ["libbar"], |
| 1883 | min_sdk_version: "29", |
| 1884 | } |
| 1885 | |
| 1886 | apex_key { |
| 1887 | name: "myapex.key", |
| 1888 | public_key: "testkey.avbpubkey", |
| 1889 | private_key: "testkey.pem", |
| 1890 | } |
| 1891 | |
| 1892 | cc_library { |
| 1893 | name: "libfoo", |
| 1894 | srcs: ["mylib.cpp"], |
| 1895 | shared_libs: ["libfoo_dep"], |
| 1896 | apex_available: ["myapex"], |
| 1897 | min_sdk_version: "29", |
| 1898 | } |
| 1899 | |
| 1900 | cc_library { |
| 1901 | name: "libfoo_dep", |
| 1902 | srcs: ["mylib.cpp"], |
| 1903 | apex_available: ["myapex"], |
| 1904 | min_sdk_version: "29", |
| 1905 | } |
| 1906 | |
| 1907 | java_library { |
| 1908 | name: "libbar", |
| 1909 | sdk_version: "current", |
| 1910 | srcs: ["a.java"], |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1911 | static_libs: [ |
| 1912 | "libbar_dep", |
| 1913 | "libbar_import_dep", |
| 1914 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1915 | apex_available: ["myapex"], |
| 1916 | min_sdk_version: "29", |
| 1917 | } |
| 1918 | |
| 1919 | java_library { |
| 1920 | name: "libbar_dep", |
| 1921 | sdk_version: "current", |
| 1922 | srcs: ["a.java"], |
| 1923 | apex_available: ["myapex"], |
| 1924 | min_sdk_version: "29", |
| 1925 | } |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1926 | |
| 1927 | java_import { |
| 1928 | name: "libbar_import_dep", |
| 1929 | jars: ["libbar.jar"], |
| 1930 | apex_available: ["myapex"], |
| 1931 | min_sdk_version: "29", |
| 1932 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1933 | `) |
| 1934 | } |
| 1935 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1936 | func TestJavaStableSdkVersion(t *testing.T) { |
| 1937 | testCases := []struct { |
| 1938 | name string |
| 1939 | expectedError string |
| 1940 | bp string |
| 1941 | }{ |
| 1942 | { |
| 1943 | name: "Non-updatable apex with non-stable dep", |
| 1944 | bp: ` |
| 1945 | apex { |
| 1946 | name: "myapex", |
| 1947 | java_libs: ["myjar"], |
| 1948 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1949 | updatable: false, |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1950 | } |
| 1951 | apex_key { |
| 1952 | name: "myapex.key", |
| 1953 | public_key: "testkey.avbpubkey", |
| 1954 | private_key: "testkey.pem", |
| 1955 | } |
| 1956 | java_library { |
| 1957 | name: "myjar", |
| 1958 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 1959 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1960 | apex_available: ["myapex"], |
| 1961 | } |
| 1962 | `, |
| 1963 | }, |
| 1964 | { |
| 1965 | name: "Updatable apex with stable dep", |
| 1966 | bp: ` |
| 1967 | apex { |
| 1968 | name: "myapex", |
| 1969 | java_libs: ["myjar"], |
| 1970 | key: "myapex.key", |
| 1971 | updatable: true, |
| 1972 | min_sdk_version: "29", |
| 1973 | } |
| 1974 | apex_key { |
| 1975 | name: "myapex.key", |
| 1976 | public_key: "testkey.avbpubkey", |
| 1977 | private_key: "testkey.pem", |
| 1978 | } |
| 1979 | java_library { |
| 1980 | name: "myjar", |
| 1981 | srcs: ["foo/bar/MyClass.java"], |
| 1982 | sdk_version: "current", |
| 1983 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1984 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1985 | } |
| 1986 | `, |
| 1987 | }, |
| 1988 | { |
| 1989 | name: "Updatable apex with non-stable dep", |
| 1990 | expectedError: "cannot depend on \"myjar\"", |
| 1991 | bp: ` |
| 1992 | apex { |
| 1993 | name: "myapex", |
| 1994 | java_libs: ["myjar"], |
| 1995 | key: "myapex.key", |
| 1996 | updatable: true, |
| 1997 | } |
| 1998 | apex_key { |
| 1999 | name: "myapex.key", |
| 2000 | public_key: "testkey.avbpubkey", |
| 2001 | private_key: "testkey.pem", |
| 2002 | } |
| 2003 | java_library { |
| 2004 | name: "myjar", |
| 2005 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2006 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2007 | apex_available: ["myapex"], |
| 2008 | } |
| 2009 | `, |
| 2010 | }, |
| 2011 | { |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2012 | name: "Updatable apex with non-stable transitive dep", |
| 2013 | // This is not actually detecting that the transitive dependency is unstable, rather it is |
| 2014 | // detecting that the transitive dependency is building against a wider API surface than the |
| 2015 | // module that depends on it is using. |
Jiyong Park | 670e0f6 | 2021-02-18 13:10:18 +0900 | [diff] [blame] | 2016 | expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against private API.", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2017 | bp: ` |
| 2018 | apex { |
| 2019 | name: "myapex", |
| 2020 | java_libs: ["myjar"], |
| 2021 | key: "myapex.key", |
| 2022 | updatable: true, |
| 2023 | } |
| 2024 | apex_key { |
| 2025 | name: "myapex.key", |
| 2026 | public_key: "testkey.avbpubkey", |
| 2027 | private_key: "testkey.pem", |
| 2028 | } |
| 2029 | java_library { |
| 2030 | name: "myjar", |
| 2031 | srcs: ["foo/bar/MyClass.java"], |
| 2032 | sdk_version: "current", |
| 2033 | apex_available: ["myapex"], |
| 2034 | static_libs: ["transitive-jar"], |
| 2035 | } |
| 2036 | java_library { |
| 2037 | name: "transitive-jar", |
| 2038 | srcs: ["foo/bar/MyClass.java"], |
| 2039 | sdk_version: "core_platform", |
| 2040 | apex_available: ["myapex"], |
| 2041 | } |
| 2042 | `, |
| 2043 | }, |
| 2044 | } |
| 2045 | |
| 2046 | for _, test := range testCases { |
| 2047 | t.Run(test.name, func(t *testing.T) { |
| 2048 | if test.expectedError == "" { |
| 2049 | testApex(t, test.bp) |
| 2050 | } else { |
| 2051 | testApexError(t, test.expectedError, test.bp) |
| 2052 | } |
| 2053 | }) |
| 2054 | } |
| 2055 | } |
| 2056 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2057 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 2058 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2059 | apex { |
| 2060 | name: "myapex", |
| 2061 | key: "myapex.key", |
| 2062 | native_shared_libs: ["mylib"], |
| 2063 | min_sdk_version: "29", |
| 2064 | } |
| 2065 | |
| 2066 | apex_key { |
| 2067 | name: "myapex.key", |
| 2068 | public_key: "testkey.avbpubkey", |
| 2069 | private_key: "testkey.pem", |
| 2070 | } |
| 2071 | |
| 2072 | cc_library { |
| 2073 | name: "mylib", |
| 2074 | srcs: ["mylib.cpp"], |
| 2075 | shared_libs: ["mylib2"], |
| 2076 | system_shared_libs: [], |
| 2077 | stl: "none", |
| 2078 | apex_available: [ |
| 2079 | "myapex", |
| 2080 | ], |
| 2081 | min_sdk_version: "29", |
| 2082 | } |
| 2083 | |
| 2084 | // indirect part of the apex |
| 2085 | cc_library { |
| 2086 | name: "mylib2", |
| 2087 | srcs: ["mylib.cpp"], |
| 2088 | system_shared_libs: [], |
| 2089 | stl: "none", |
| 2090 | apex_available: [ |
| 2091 | "myapex", |
| 2092 | ], |
| 2093 | min_sdk_version: "30", |
| 2094 | } |
| 2095 | `) |
| 2096 | } |
| 2097 | |
| 2098 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 2099 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2100 | apex { |
| 2101 | name: "myapex", |
| 2102 | key: "myapex.key", |
| 2103 | apps: ["AppFoo"], |
| 2104 | min_sdk_version: "29", |
| 2105 | } |
| 2106 | |
| 2107 | apex_key { |
| 2108 | name: "myapex.key", |
| 2109 | public_key: "testkey.avbpubkey", |
| 2110 | private_key: "testkey.pem", |
| 2111 | } |
| 2112 | |
| 2113 | android_app { |
| 2114 | name: "AppFoo", |
| 2115 | srcs: ["foo/bar/MyClass.java"], |
| 2116 | sdk_version: "current", |
| 2117 | min_sdk_version: "29", |
| 2118 | system_modules: "none", |
| 2119 | stl: "none", |
| 2120 | static_libs: ["bar"], |
| 2121 | apex_available: [ "myapex" ], |
| 2122 | } |
| 2123 | |
| 2124 | java_library { |
| 2125 | name: "bar", |
| 2126 | sdk_version: "current", |
| 2127 | srcs: ["a.java"], |
| 2128 | apex_available: [ "myapex" ], |
| 2129 | } |
| 2130 | `) |
| 2131 | } |
| 2132 | |
| 2133 | func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2134 | ctx := testApex(t, ` |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2135 | apex { |
| 2136 | name: "myapex", |
| 2137 | key: "myapex.key", |
| 2138 | native_shared_libs: ["mylib"], |
| 2139 | min_sdk_version: "29", |
| 2140 | } |
| 2141 | |
| 2142 | apex_key { |
| 2143 | name: "myapex.key", |
| 2144 | public_key: "testkey.avbpubkey", |
| 2145 | private_key: "testkey.pem", |
| 2146 | } |
| 2147 | |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2148 | // mylib in myapex will link to mylib2#current |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2149 | // mylib in otherapex will link to mylib2(non-stub) in otherapex as well |
| 2150 | cc_library { |
| 2151 | name: "mylib", |
| 2152 | srcs: ["mylib.cpp"], |
| 2153 | shared_libs: ["mylib2"], |
| 2154 | system_shared_libs: [], |
| 2155 | stl: "none", |
| 2156 | apex_available: ["myapex", "otherapex"], |
| 2157 | min_sdk_version: "29", |
| 2158 | } |
| 2159 | |
| 2160 | cc_library { |
| 2161 | name: "mylib2", |
| 2162 | srcs: ["mylib.cpp"], |
| 2163 | system_shared_libs: [], |
| 2164 | stl: "none", |
| 2165 | apex_available: ["otherapex"], |
| 2166 | stubs: { versions: ["29", "30"] }, |
| 2167 | min_sdk_version: "30", |
| 2168 | } |
| 2169 | |
| 2170 | apex { |
| 2171 | name: "otherapex", |
| 2172 | key: "myapex.key", |
| 2173 | native_shared_libs: ["mylib", "mylib2"], |
| 2174 | min_sdk_version: "30", |
| 2175 | } |
| 2176 | `) |
| 2177 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2178 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2179 | libFlags := ld.Args["libFlags"] |
| 2180 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2181 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2182 | expectLink("mylib", "shared_apex29", "mylib2", "shared_current") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2183 | expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2184 | } |
| 2185 | |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2186 | func TestApexMinSdkVersion_WorksWithSdkCodename(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2187 | withSAsActiveCodeNames := android.FixtureModifyProductVariables( |
| 2188 | func(variables android.FixtureProductVariables) { |
| 2189 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2190 | variables.Platform_version_active_codenames = []string{"S"} |
| 2191 | }, |
| 2192 | ) |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2193 | testApexError(t, `libbar.*: should support min_sdk_version\(S\)`, ` |
| 2194 | apex { |
| 2195 | name: "myapex", |
| 2196 | key: "myapex.key", |
| 2197 | native_shared_libs: ["libfoo"], |
| 2198 | min_sdk_version: "S", |
| 2199 | } |
| 2200 | apex_key { |
| 2201 | name: "myapex.key", |
| 2202 | public_key: "testkey.avbpubkey", |
| 2203 | private_key: "testkey.pem", |
| 2204 | } |
| 2205 | cc_library { |
| 2206 | name: "libfoo", |
| 2207 | shared_libs: ["libbar"], |
| 2208 | apex_available: ["myapex"], |
| 2209 | min_sdk_version: "29", |
| 2210 | } |
| 2211 | cc_library { |
| 2212 | name: "libbar", |
| 2213 | apex_available: ["myapex"], |
| 2214 | } |
| 2215 | `, withSAsActiveCodeNames) |
| 2216 | } |
| 2217 | |
| 2218 | func TestApexMinSdkVersion_WorksWithActiveCodenames(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2219 | withSAsActiveCodeNames := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2220 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2221 | variables.Platform_version_active_codenames = []string{"S", "T"} |
| 2222 | }) |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2223 | ctx := testApex(t, ` |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2224 | apex { |
| 2225 | name: "myapex", |
| 2226 | key: "myapex.key", |
| 2227 | native_shared_libs: ["libfoo"], |
| 2228 | min_sdk_version: "S", |
| 2229 | } |
| 2230 | apex_key { |
| 2231 | name: "myapex.key", |
| 2232 | public_key: "testkey.avbpubkey", |
| 2233 | private_key: "testkey.pem", |
| 2234 | } |
| 2235 | cc_library { |
| 2236 | name: "libfoo", |
| 2237 | shared_libs: ["libbar"], |
| 2238 | apex_available: ["myapex"], |
| 2239 | min_sdk_version: "S", |
| 2240 | } |
| 2241 | cc_library { |
| 2242 | name: "libbar", |
| 2243 | stubs: { |
| 2244 | symbol_file: "libbar.map.txt", |
| 2245 | versions: ["30", "S", "T"], |
| 2246 | }, |
| 2247 | } |
| 2248 | `, withSAsActiveCodeNames) |
| 2249 | |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2250 | // ensure libfoo is linked with current version of libbar stub |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2251 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_apex10000") |
| 2252 | libFlags := libfoo.Rule("ld").Args["libFlags"] |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2253 | ensureContains(t, libFlags, "android_arm64_armv8-a_shared_current/libbar.so") |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2254 | } |
| 2255 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2256 | func TestFilesInSubDir(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2257 | ctx := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2258 | apex { |
| 2259 | name: "myapex", |
| 2260 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2261 | native_shared_libs: ["mylib"], |
| 2262 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2263 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2264 | compile_multilib: "both", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2265 | updatable: false, |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | apex_key { |
| 2269 | name: "myapex.key", |
| 2270 | public_key: "testkey.avbpubkey", |
| 2271 | private_key: "testkey.pem", |
| 2272 | } |
| 2273 | |
| 2274 | prebuilt_etc { |
| 2275 | name: "myetc", |
| 2276 | src: "myprebuilt", |
| 2277 | sub_dir: "foo/bar", |
| 2278 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2279 | |
| 2280 | cc_library { |
| 2281 | name: "mylib", |
| 2282 | srcs: ["mylib.cpp"], |
| 2283 | relative_install_path: "foo/bar", |
| 2284 | system_shared_libs: [], |
| 2285 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2286 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | cc_binary { |
| 2290 | name: "mybin", |
| 2291 | srcs: ["mylib.cpp"], |
| 2292 | relative_install_path: "foo/bar", |
| 2293 | system_shared_libs: [], |
| 2294 | static_executable: true, |
| 2295 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2296 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2297 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2298 | `) |
| 2299 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2300 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2301 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 2302 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2303 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2304 | ensureListContains(t, dirs, "etc") |
| 2305 | ensureListContains(t, dirs, "etc/foo") |
| 2306 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2307 | ensureListContains(t, dirs, "lib64") |
| 2308 | ensureListContains(t, dirs, "lib64/foo") |
| 2309 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 2310 | ensureListContains(t, dirs, "lib") |
| 2311 | ensureListContains(t, dirs, "lib/foo") |
| 2312 | ensureListContains(t, dirs, "lib/foo/bar") |
| 2313 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 2314 | ensureListContains(t, dirs, "bin") |
| 2315 | ensureListContains(t, dirs, "bin/foo") |
| 2316 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2317 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2318 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2319 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2320 | ctx := testApex(t, ` |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2321 | apex { |
| 2322 | name: "myapex", |
| 2323 | key: "myapex.key", |
| 2324 | multilib: { |
| 2325 | both: { |
| 2326 | native_shared_libs: ["mylib"], |
| 2327 | binaries: ["mybin"], |
| 2328 | }, |
| 2329 | }, |
| 2330 | compile_multilib: "both", |
| 2331 | native_bridge_supported: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2332 | updatable: false, |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | apex_key { |
| 2336 | name: "myapex.key", |
| 2337 | public_key: "testkey.avbpubkey", |
| 2338 | private_key: "testkey.pem", |
| 2339 | } |
| 2340 | |
| 2341 | cc_library { |
| 2342 | name: "mylib", |
| 2343 | relative_install_path: "foo/bar", |
| 2344 | system_shared_libs: [], |
| 2345 | stl: "none", |
| 2346 | apex_available: [ "myapex" ], |
| 2347 | native_bridge_supported: true, |
| 2348 | } |
| 2349 | |
| 2350 | cc_binary { |
| 2351 | name: "mybin", |
| 2352 | relative_install_path: "foo/bar", |
| 2353 | system_shared_libs: [], |
| 2354 | static_executable: true, |
| 2355 | stl: "none", |
| 2356 | apex_available: [ "myapex" ], |
| 2357 | native_bridge_supported: true, |
| 2358 | compile_multilib: "both", // default is "first" for binary |
| 2359 | multilib: { |
| 2360 | lib64: { |
| 2361 | suffix: "64", |
| 2362 | }, |
| 2363 | }, |
| 2364 | } |
| 2365 | `, withNativeBridgeEnabled) |
| 2366 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2367 | "bin/foo/bar/mybin", |
| 2368 | "bin/foo/bar/mybin64", |
| 2369 | "bin/arm/foo/bar/mybin", |
| 2370 | "bin/arm64/foo/bar/mybin64", |
| 2371 | "lib/foo/bar/mylib.so", |
| 2372 | "lib/arm/foo/bar/mylib.so", |
| 2373 | "lib64/foo/bar/mylib.so", |
| 2374 | "lib64/arm64/foo/bar/mylib.so", |
| 2375 | }) |
| 2376 | } |
| 2377 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2378 | func TestUseVendor(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2379 | ctx := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2380 | apex { |
| 2381 | name: "myapex", |
| 2382 | key: "myapex.key", |
| 2383 | native_shared_libs: ["mylib"], |
| 2384 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2385 | updatable: false, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | apex_key { |
| 2389 | name: "myapex.key", |
| 2390 | public_key: "testkey.avbpubkey", |
| 2391 | private_key: "testkey.pem", |
| 2392 | } |
| 2393 | |
| 2394 | cc_library { |
| 2395 | name: "mylib", |
| 2396 | srcs: ["mylib.cpp"], |
| 2397 | shared_libs: ["mylib2"], |
| 2398 | system_shared_libs: [], |
| 2399 | vendor_available: true, |
| 2400 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2401 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | cc_library { |
| 2405 | name: "mylib2", |
| 2406 | srcs: ["mylib.cpp"], |
| 2407 | system_shared_libs: [], |
| 2408 | vendor_available: true, |
| 2409 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2410 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2411 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2412 | `, |
| 2413 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2414 | ) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2415 | |
| 2416 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2417 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2418 | for _, implicit := range i.Implicits { |
| 2419 | inputsList = append(inputsList, implicit.String()) |
| 2420 | } |
| 2421 | } |
| 2422 | inputsString := strings.Join(inputsList, " ") |
| 2423 | |
| 2424 | // ensure that the apex includes vendor variants of the direct and indirect deps |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2425 | ensureContains(t, inputsString, "android_vendor.29_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2426 | ensureContains(t, inputsString, "android_vendor.29_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2427 | |
| 2428 | // ensure that the apex does not include core variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2429 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2430 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2431 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2432 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2433 | func TestUseVendorNotAllowedForSystemApexes(t *testing.T) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2434 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 2435 | apex { |
| 2436 | name: "myapex", |
| 2437 | key: "myapex.key", |
| 2438 | use_vendor: true, |
| 2439 | } |
| 2440 | apex_key { |
| 2441 | name: "myapex.key", |
| 2442 | public_key: "testkey.avbpubkey", |
| 2443 | private_key: "testkey.pem", |
| 2444 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2445 | `, |
| 2446 | setUseVendorAllowListForTest([]string{""}), |
| 2447 | ) |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2448 | // no error with allow list |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2449 | testApex(t, ` |
| 2450 | apex { |
| 2451 | name: "myapex", |
| 2452 | key: "myapex.key", |
| 2453 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2454 | updatable: false, |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2455 | } |
| 2456 | apex_key { |
| 2457 | name: "myapex.key", |
| 2458 | public_key: "testkey.avbpubkey", |
| 2459 | private_key: "testkey.pem", |
| 2460 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2461 | `, |
| 2462 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2463 | ) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2464 | } |
| 2465 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2466 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 2467 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 2468 | apex { |
| 2469 | name: "myapex", |
| 2470 | key: "myapex.key", |
| 2471 | native_shared_libs: ["mylib"], |
| 2472 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2473 | updatable: false, |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | apex_key { |
| 2477 | name: "myapex.key", |
| 2478 | public_key: "testkey.avbpubkey", |
| 2479 | private_key: "testkey.pem", |
| 2480 | } |
| 2481 | |
| 2482 | cc_library { |
| 2483 | name: "mylib", |
| 2484 | srcs: ["mylib.cpp"], |
| 2485 | system_shared_libs: [], |
| 2486 | stl: "none", |
| 2487 | } |
| 2488 | `) |
| 2489 | } |
| 2490 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2491 | func TestVendorApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2492 | ctx := testApex(t, ` |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2493 | apex { |
| 2494 | name: "myapex", |
| 2495 | key: "myapex.key", |
| 2496 | binaries: ["mybin"], |
| 2497 | vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2498 | updatable: false, |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2499 | } |
| 2500 | apex_key { |
| 2501 | name: "myapex.key", |
| 2502 | public_key: "testkey.avbpubkey", |
| 2503 | private_key: "testkey.pem", |
| 2504 | } |
| 2505 | cc_binary { |
| 2506 | name: "mybin", |
| 2507 | vendor: true, |
| 2508 | shared_libs: ["libfoo"], |
| 2509 | } |
| 2510 | cc_library { |
| 2511 | name: "libfoo", |
| 2512 | proprietary: true, |
| 2513 | } |
| 2514 | `) |
| 2515 | |
| 2516 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2517 | "bin/mybin", |
| 2518 | "lib64/libfoo.so", |
| 2519 | // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX |
| 2520 | "lib64/libc++.so", |
| 2521 | }) |
| 2522 | |
| 2523 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2524 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2525 | name := apexBundle.BaseModuleName() |
| 2526 | prefix := "TARGET_" |
| 2527 | var builder strings.Builder |
| 2528 | data.Custom(&builder, name, prefix, "", data) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2529 | androidMk := android.StringRelativeToTop(ctx.Config(), builder.String()) |
| 2530 | installPath := "out/target/product/test_device/vendor/apex" |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 2531 | ensureContains(t, androidMk, "LOCAL_MODULE_PATH := "+installPath) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2532 | |
| 2533 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2534 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2535 | ensureListNotContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2536 | } |
| 2537 | |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2538 | func TestVendorApex_use_vndk_as_stable(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2539 | ctx := testApex(t, ` |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2540 | apex { |
| 2541 | name: "myapex", |
| 2542 | key: "myapex.key", |
| 2543 | binaries: ["mybin"], |
| 2544 | vendor: true, |
| 2545 | use_vndk_as_stable: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2546 | updatable: false, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2547 | } |
| 2548 | apex_key { |
| 2549 | name: "myapex.key", |
| 2550 | public_key: "testkey.avbpubkey", |
| 2551 | private_key: "testkey.pem", |
| 2552 | } |
| 2553 | cc_binary { |
| 2554 | name: "mybin", |
| 2555 | vendor: true, |
| 2556 | shared_libs: ["libvndk", "libvendor"], |
| 2557 | } |
| 2558 | cc_library { |
| 2559 | name: "libvndk", |
| 2560 | vndk: { |
| 2561 | enabled: true, |
| 2562 | }, |
| 2563 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2564 | product_available: true, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2565 | } |
| 2566 | cc_library { |
| 2567 | name: "libvendor", |
| 2568 | vendor: true, |
| 2569 | } |
| 2570 | `) |
| 2571 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2572 | vendorVariant := "android_vendor.29_arm64_armv8-a" |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2573 | |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 2574 | ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_apex10000").Rule("ld") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2575 | libs := names(ldRule.Args["libFlags"]) |
| 2576 | // VNDK libs(libvndk/libc++) as they are |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2577 | ensureListContains(t, libs, "out/soong/.intermediates/libvndk/"+vendorVariant+"_shared/libvndk.so") |
| 2578 | ensureListContains(t, libs, "out/soong/.intermediates/"+cc.DefaultCcCommonTestModulesDir+"libc++/"+vendorVariant+"_shared/libc++.so") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2579 | // non-stable Vendor libs as APEX variants |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2580 | ensureListContains(t, libs, "out/soong/.intermediates/libvendor/"+vendorVariant+"_shared_apex10000/libvendor.so") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2581 | |
| 2582 | // VNDK libs are not included when use_vndk_as_stable: true |
| 2583 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2584 | "bin/mybin", |
| 2585 | "lib64/libvendor.so", |
| 2586 | }) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2587 | |
| 2588 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2589 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2590 | ensureListContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2591 | } |
| 2592 | |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2593 | func TestProductVariant(t *testing.T) { |
| 2594 | ctx := testApex(t, ` |
| 2595 | apex { |
| 2596 | name: "myapex", |
| 2597 | key: "myapex.key", |
| 2598 | updatable: false, |
| 2599 | product_specific: true, |
| 2600 | binaries: ["foo"], |
| 2601 | } |
| 2602 | |
| 2603 | apex_key { |
| 2604 | name: "myapex.key", |
| 2605 | public_key: "testkey.avbpubkey", |
| 2606 | private_key: "testkey.pem", |
| 2607 | } |
| 2608 | |
| 2609 | cc_binary { |
| 2610 | name: "foo", |
| 2611 | product_available: true, |
| 2612 | apex_available: ["myapex"], |
| 2613 | srcs: ["foo.cpp"], |
| 2614 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2615 | `, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2616 | variables.ProductVndkVersion = proptools.StringPtr("current") |
| 2617 | }), |
| 2618 | ) |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2619 | |
| 2620 | cflags := strings.Fields( |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2621 | ctx.ModuleForTests("foo", "android_product.29_arm64_armv8-a_apex10000").Rule("cc").Args["cFlags"]) |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2622 | ensureListContains(t, cflags, "-D__ANDROID_VNDK__") |
| 2623 | ensureListContains(t, cflags, "-D__ANDROID_APEX__") |
| 2624 | ensureListContains(t, cflags, "-D__ANDROID_PRODUCT__") |
| 2625 | ensureListNotContains(t, cflags, "-D__ANDROID_VENDOR__") |
| 2626 | } |
| 2627 | |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2628 | func TestApex_withPrebuiltFirmware(t *testing.T) { |
| 2629 | testCases := []struct { |
| 2630 | name string |
| 2631 | additionalProp string |
| 2632 | }{ |
| 2633 | {"system apex with prebuilt_firmware", ""}, |
| 2634 | {"vendor apex with prebuilt_firmware", "vendor: true,"}, |
| 2635 | } |
| 2636 | for _, tc := range testCases { |
| 2637 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2638 | ctx := testApex(t, ` |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2639 | apex { |
| 2640 | name: "myapex", |
| 2641 | key: "myapex.key", |
| 2642 | prebuilts: ["myfirmware"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2643 | updatable: false, |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2644 | `+tc.additionalProp+` |
| 2645 | } |
| 2646 | apex_key { |
| 2647 | name: "myapex.key", |
| 2648 | public_key: "testkey.avbpubkey", |
| 2649 | private_key: "testkey.pem", |
| 2650 | } |
| 2651 | prebuilt_firmware { |
| 2652 | name: "myfirmware", |
| 2653 | src: "myfirmware.bin", |
| 2654 | filename_from_src: true, |
| 2655 | `+tc.additionalProp+` |
| 2656 | } |
| 2657 | `) |
| 2658 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2659 | "etc/firmware/myfirmware.bin", |
| 2660 | }) |
| 2661 | }) |
| 2662 | } |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 2663 | } |
| 2664 | |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2665 | func TestAndroidMk_UseVendorRequired(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2666 | ctx := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2667 | apex { |
| 2668 | name: "myapex", |
| 2669 | key: "myapex.key", |
| 2670 | use_vendor: true, |
| 2671 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2672 | updatable: false, |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | apex_key { |
| 2676 | name: "myapex.key", |
| 2677 | public_key: "testkey.avbpubkey", |
| 2678 | private_key: "testkey.pem", |
| 2679 | } |
| 2680 | |
| 2681 | cc_library { |
| 2682 | name: "mylib", |
| 2683 | vendor_available: true, |
| 2684 | apex_available: ["myapex"], |
| 2685 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2686 | `, |
| 2687 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2688 | ) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2689 | |
| 2690 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2691 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2692 | name := apexBundle.BaseModuleName() |
| 2693 | prefix := "TARGET_" |
| 2694 | var builder strings.Builder |
| 2695 | data.Custom(&builder, name, prefix, "", data) |
| 2696 | androidMk := builder.String() |
| 2697 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc libm libdl\n") |
| 2698 | } |
| 2699 | |
| 2700 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2701 | ctx := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2702 | apex { |
| 2703 | name: "myapex", |
| 2704 | key: "myapex.key", |
| 2705 | vendor: true, |
| 2706 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2707 | updatable: false, |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | apex_key { |
| 2711 | name: "myapex.key", |
| 2712 | public_key: "testkey.avbpubkey", |
| 2713 | private_key: "testkey.pem", |
| 2714 | } |
| 2715 | |
| 2716 | cc_library { |
| 2717 | name: "mylib", |
| 2718 | vendor_available: true, |
| 2719 | } |
| 2720 | `) |
| 2721 | |
| 2722 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2723 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2724 | name := apexBundle.BaseModuleName() |
| 2725 | prefix := "TARGET_" |
| 2726 | var builder strings.Builder |
| 2727 | data.Custom(&builder, name, prefix, "", data) |
| 2728 | androidMk := builder.String() |
| 2729 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc.vendor libm.vendor libdl.vendor\n") |
| 2730 | } |
| 2731 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2732 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2733 | ctx := testApex(t, ` |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2734 | apex { |
| 2735 | name: "myapex", |
| 2736 | key: "myapex.key", |
| 2737 | vintf_fragments: ["fragment.xml"], |
| 2738 | init_rc: ["init.rc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2739 | updatable: false, |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2740 | } |
| 2741 | apex_key { |
| 2742 | name: "myapex.key", |
| 2743 | public_key: "testkey.avbpubkey", |
| 2744 | private_key: "testkey.pem", |
| 2745 | } |
| 2746 | cc_binary { |
| 2747 | name: "mybin", |
| 2748 | } |
| 2749 | `) |
| 2750 | |
| 2751 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2752 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2753 | name := apexBundle.BaseModuleName() |
| 2754 | prefix := "TARGET_" |
| 2755 | var builder strings.Builder |
| 2756 | data.Custom(&builder, name, prefix, "", data) |
| 2757 | androidMk := builder.String() |
| 2758 | ensureContains(t, androidMk, "LOCAL_VINTF_FRAGMENTS := fragment.xml\n") |
Liz Kammer | 0c4f71c | 2021-04-06 10:35:10 -0400 | [diff] [blame] | 2759 | ensureContains(t, androidMk, "LOCAL_FULL_INIT_RC := init.rc\n") |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2760 | } |
| 2761 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2762 | func TestStaticLinking(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2763 | ctx := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2764 | apex { |
| 2765 | name: "myapex", |
| 2766 | key: "myapex.key", |
| 2767 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2768 | updatable: false, |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 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", |
| 2779 | srcs: ["mylib.cpp"], |
| 2780 | system_shared_libs: [], |
| 2781 | stl: "none", |
| 2782 | stubs: { |
| 2783 | versions: ["1", "2", "3"], |
| 2784 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2785 | apex_available: [ |
| 2786 | "//apex_available:platform", |
| 2787 | "myapex", |
| 2788 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | cc_binary { |
| 2792 | name: "not_in_apex", |
| 2793 | srcs: ["mylib.cpp"], |
| 2794 | static_libs: ["mylib"], |
| 2795 | static_executable: true, |
| 2796 | system_shared_libs: [], |
| 2797 | stl: "none", |
| 2798 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2799 | `) |
| 2800 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2801 | 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] | 2802 | |
| 2803 | // 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] | 2804 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2805 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2806 | |
| 2807 | func TestKeys(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2808 | ctx := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2809 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2810 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2811 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2812 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2813 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2814 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2815 | updatable: false, |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | cc_library { |
| 2819 | name: "mylib", |
| 2820 | srcs: ["mylib.cpp"], |
| 2821 | system_shared_libs: [], |
| 2822 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2823 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | apex_key { |
| 2827 | name: "myapex.key", |
| 2828 | public_key: "testkey.avbpubkey", |
| 2829 | private_key: "testkey.pem", |
| 2830 | } |
| 2831 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2832 | android_app_certificate { |
| 2833 | name: "myapex.certificate", |
| 2834 | certificate: "testkey", |
| 2835 | } |
| 2836 | |
| 2837 | android_app_certificate { |
| 2838 | name: "myapex.certificate.override", |
| 2839 | certificate: "testkey.override", |
| 2840 | } |
| 2841 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2842 | `) |
| 2843 | |
| 2844 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2845 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2846 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2847 | if keys.publicKeyFile.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 2848 | t.Errorf("public key %q is not %q", keys.publicKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2849 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 2850 | } |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2851 | if keys.privateKeyFile.String() != "vendor/foo/devkeys/testkey.pem" { |
| 2852 | t.Errorf("private key %q is not %q", keys.privateKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2853 | "vendor/foo/devkeys/testkey.pem") |
| 2854 | } |
| 2855 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2856 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2857 | 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] | 2858 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2859 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2860 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2861 | } |
| 2862 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2863 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2864 | func TestCertificate(t *testing.T) { |
| 2865 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2866 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2867 | apex { |
| 2868 | name: "myapex", |
| 2869 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2870 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2871 | } |
| 2872 | apex_key { |
| 2873 | name: "myapex.key", |
| 2874 | public_key: "testkey.avbpubkey", |
| 2875 | private_key: "testkey.pem", |
| 2876 | }`) |
| 2877 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2878 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 2879 | if actual := rule.Args["certificates"]; actual != expected { |
| 2880 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2881 | } |
| 2882 | }) |
| 2883 | t.Run("override when unspecified", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2884 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2885 | apex { |
| 2886 | name: "myapex_keytest", |
| 2887 | key: "myapex.key", |
| 2888 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2889 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2890 | } |
| 2891 | apex_key { |
| 2892 | name: "myapex.key", |
| 2893 | public_key: "testkey.avbpubkey", |
| 2894 | private_key: "testkey.pem", |
| 2895 | } |
| 2896 | android_app_certificate { |
| 2897 | name: "myapex.certificate.override", |
| 2898 | certificate: "testkey.override", |
| 2899 | }`) |
| 2900 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2901 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2902 | if actual := rule.Args["certificates"]; actual != expected { |
| 2903 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2904 | } |
| 2905 | }) |
| 2906 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2907 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2908 | apex { |
| 2909 | name: "myapex", |
| 2910 | key: "myapex.key", |
| 2911 | certificate: ":myapex.certificate", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2912 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2913 | } |
| 2914 | apex_key { |
| 2915 | name: "myapex.key", |
| 2916 | public_key: "testkey.avbpubkey", |
| 2917 | private_key: "testkey.pem", |
| 2918 | } |
| 2919 | android_app_certificate { |
| 2920 | name: "myapex.certificate", |
| 2921 | certificate: "testkey", |
| 2922 | }`) |
| 2923 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2924 | expected := "testkey.x509.pem testkey.pk8" |
| 2925 | if actual := rule.Args["certificates"]; actual != expected { |
| 2926 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2927 | } |
| 2928 | }) |
| 2929 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2930 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2931 | apex { |
| 2932 | name: "myapex_keytest", |
| 2933 | key: "myapex.key", |
| 2934 | file_contexts: ":myapex-file_contexts", |
| 2935 | certificate: ":myapex.certificate", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2936 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2937 | } |
| 2938 | apex_key { |
| 2939 | name: "myapex.key", |
| 2940 | public_key: "testkey.avbpubkey", |
| 2941 | private_key: "testkey.pem", |
| 2942 | } |
| 2943 | android_app_certificate { |
| 2944 | name: "myapex.certificate.override", |
| 2945 | certificate: "testkey.override", |
| 2946 | }`) |
| 2947 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2948 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2949 | if actual := rule.Args["certificates"]; actual != expected { |
| 2950 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2951 | } |
| 2952 | }) |
| 2953 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2954 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2955 | apex { |
| 2956 | name: "myapex", |
| 2957 | key: "myapex.key", |
| 2958 | certificate: "testkey", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2959 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2960 | } |
| 2961 | apex_key { |
| 2962 | name: "myapex.key", |
| 2963 | public_key: "testkey.avbpubkey", |
| 2964 | private_key: "testkey.pem", |
| 2965 | }`) |
| 2966 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2967 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 2968 | if actual := rule.Args["certificates"]; actual != expected { |
| 2969 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2970 | } |
| 2971 | }) |
| 2972 | t.Run("override when specified as <name>", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2973 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2974 | apex { |
| 2975 | name: "myapex_keytest", |
| 2976 | key: "myapex.key", |
| 2977 | file_contexts: ":myapex-file_contexts", |
| 2978 | certificate: "testkey", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2979 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2980 | } |
| 2981 | apex_key { |
| 2982 | name: "myapex.key", |
| 2983 | public_key: "testkey.avbpubkey", |
| 2984 | private_key: "testkey.pem", |
| 2985 | } |
| 2986 | android_app_certificate { |
| 2987 | name: "myapex.certificate.override", |
| 2988 | certificate: "testkey.override", |
| 2989 | }`) |
| 2990 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2991 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2992 | if actual := rule.Args["certificates"]; actual != expected { |
| 2993 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2994 | } |
| 2995 | }) |
| 2996 | } |
| 2997 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2998 | func TestMacro(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2999 | ctx := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3000 | apex { |
| 3001 | name: "myapex", |
| 3002 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3003 | native_shared_libs: ["mylib", "mylib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3004 | updatable: false, |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | apex { |
| 3008 | name: "otherapex", |
| 3009 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3010 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3011 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | apex_key { |
| 3015 | name: "myapex.key", |
| 3016 | public_key: "testkey.avbpubkey", |
| 3017 | private_key: "testkey.pem", |
| 3018 | } |
| 3019 | |
| 3020 | cc_library { |
| 3021 | name: "mylib", |
| 3022 | srcs: ["mylib.cpp"], |
| 3023 | system_shared_libs: [], |
| 3024 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3025 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3026 | "myapex", |
| 3027 | "otherapex", |
| 3028 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3029 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3030 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3031 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3032 | cc_library { |
| 3033 | name: "mylib2", |
| 3034 | srcs: ["mylib.cpp"], |
| 3035 | system_shared_libs: [], |
| 3036 | stl: "none", |
| 3037 | apex_available: [ |
| 3038 | "myapex", |
| 3039 | "otherapex", |
| 3040 | ], |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3041 | static_libs: ["mylib3"], |
| 3042 | recovery_available: true, |
| 3043 | min_sdk_version: "29", |
| 3044 | } |
| 3045 | cc_library { |
| 3046 | name: "mylib3", |
| 3047 | srcs: ["mylib.cpp"], |
| 3048 | system_shared_libs: [], |
| 3049 | stl: "none", |
| 3050 | apex_available: [ |
| 3051 | "myapex", |
| 3052 | "otherapex", |
| 3053 | ], |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3054 | use_apex_name_macro: true, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3055 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3056 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3057 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3058 | `) |
| 3059 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3060 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3061 | 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] | 3062 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3063 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3064 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3065 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3066 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3067 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3068 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3069 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3070 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3071 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3072 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex29").Rule("cc").Args["cFlags"] |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3073 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3074 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3075 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3076 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3077 | // When a cc_library sets use_apex_name_macro: true each apex gets a unique variant and |
| 3078 | // each variant defines additional macros to distinguish which apex variant it is built for |
| 3079 | |
| 3080 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3081 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3082 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3083 | |
| 3084 | // APEX variant has __ANDROID_APEX__ defined |
| 3085 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 3086 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3087 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3088 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3089 | |
| 3090 | // APEX variant has __ANDROID_APEX__ defined |
| 3091 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 3092 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3093 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3094 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3095 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3096 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3097 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3098 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3099 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3100 | |
| 3101 | // When a dependency of a cc_library sets use_apex_name_macro: true each apex gets a unique |
| 3102 | // variant. |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3103 | |
| 3104 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3105 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3106 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3107 | |
| 3108 | // APEX variant has __ANDROID_APEX__ defined |
| 3109 | 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] | 3110 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3111 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3112 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3113 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3114 | // APEX variant has __ANDROID_APEX__ defined |
| 3115 | 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] | 3116 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3117 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3118 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3119 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3120 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3121 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3122 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3123 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3124 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3125 | |
| 3126 | func TestHeaderLibsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3127 | ctx := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3128 | apex { |
| 3129 | name: "myapex", |
| 3130 | key: "myapex.key", |
| 3131 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3132 | updatable: false, |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3133 | } |
| 3134 | |
| 3135 | apex_key { |
| 3136 | name: "myapex.key", |
| 3137 | public_key: "testkey.avbpubkey", |
| 3138 | private_key: "testkey.pem", |
| 3139 | } |
| 3140 | |
| 3141 | cc_library_headers { |
| 3142 | name: "mylib_headers", |
| 3143 | export_include_dirs: ["my_include"], |
| 3144 | system_shared_libs: [], |
| 3145 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3146 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | cc_library { |
| 3150 | name: "mylib", |
| 3151 | srcs: ["mylib.cpp"], |
| 3152 | system_shared_libs: [], |
| 3153 | stl: "none", |
| 3154 | header_libs: ["mylib_headers"], |
| 3155 | export_header_lib_headers: ["mylib_headers"], |
| 3156 | stubs: { |
| 3157 | versions: ["1", "2", "3"], |
| 3158 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3159 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | cc_library { |
| 3163 | name: "otherlib", |
| 3164 | srcs: ["mylib.cpp"], |
| 3165 | system_shared_libs: [], |
| 3166 | stl: "none", |
| 3167 | shared_libs: ["mylib"], |
| 3168 | } |
| 3169 | `) |
| 3170 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3171 | 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] | 3172 | |
| 3173 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 3174 | ensureContains(t, cFlags, "-Imy_include") |
| 3175 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3176 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3177 | type fileInApex struct { |
| 3178 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3179 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3180 | isLink bool |
| 3181 | } |
| 3182 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3183 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3184 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3185 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3186 | copyCmds := apexRule.Args["copy_commands"] |
| 3187 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3188 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3189 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 3190 | cmd = strings.TrimSpace(cmd) |
| 3191 | if cmd == "" { |
| 3192 | continue |
| 3193 | } |
| 3194 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3195 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3196 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3197 | switch terms[0] { |
| 3198 | case "mkdir": |
| 3199 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3200 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3201 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 3202 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3203 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3204 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3205 | isLink = false |
| 3206 | case "ln": |
| 3207 | if len(terms) != 3 && len(terms) != 4 { |
| 3208 | // ln LINK TARGET or ln -s LINK TARGET |
| 3209 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 3210 | } |
| 3211 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3212 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3213 | isLink = true |
| 3214 | default: |
| 3215 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 3216 | } |
| 3217 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3218 | index := strings.Index(dst, imageApexDir) |
| 3219 | if index == -1 { |
| 3220 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 3221 | } |
| 3222 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3223 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3224 | } |
| 3225 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3226 | return ret |
| 3227 | } |
| 3228 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3229 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 3230 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3231 | var failed bool |
| 3232 | var surplus []string |
| 3233 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3234 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3235 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3236 | for _, expected := range files { |
| 3237 | if matched, _ := path.Match(expected, file.path); matched { |
| 3238 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3239 | mactchFound = true |
| 3240 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3241 | } |
| 3242 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3243 | if !mactchFound { |
| 3244 | surplus = append(surplus, file.path) |
| 3245 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3246 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3247 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3248 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3249 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3250 | t.Log("surplus files", surplus) |
| 3251 | failed = true |
| 3252 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3253 | |
| 3254 | if len(files) > len(filesMatched) { |
| 3255 | var missing []string |
| 3256 | for _, expected := range files { |
| 3257 | if !filesMatched[expected] { |
| 3258 | missing = append(missing, expected) |
| 3259 | } |
| 3260 | } |
| 3261 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3262 | t.Log("missing files", missing) |
| 3263 | failed = true |
| 3264 | } |
| 3265 | if failed { |
| 3266 | t.Fail() |
| 3267 | } |
| 3268 | } |
| 3269 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3270 | func TestVndkApexCurrent(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3271 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3272 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3273 | name: "com.android.vndk.current", |
| 3274 | key: "com.android.vndk.current.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3275 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3279 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3280 | public_key: "testkey.avbpubkey", |
| 3281 | private_key: "testkey.pem", |
| 3282 | } |
| 3283 | |
| 3284 | cc_library { |
| 3285 | name: "libvndk", |
| 3286 | srcs: ["mylib.cpp"], |
| 3287 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3288 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3289 | vndk: { |
| 3290 | enabled: true, |
| 3291 | }, |
| 3292 | system_shared_libs: [], |
| 3293 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3294 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | cc_library { |
| 3298 | name: "libvndksp", |
| 3299 | srcs: ["mylib.cpp"], |
| 3300 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3301 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3302 | vndk: { |
| 3303 | enabled: true, |
| 3304 | support_system_process: true, |
| 3305 | }, |
| 3306 | system_shared_libs: [], |
| 3307 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3308 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3309 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3310 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3311 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3312 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3313 | "lib/libvndk.so", |
| 3314 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3315 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3316 | "lib64/libvndk.so", |
| 3317 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3318 | "lib64/libc++.so", |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 3319 | "etc/llndk.libraries.29.txt", |
| 3320 | "etc/vndkcore.libraries.29.txt", |
| 3321 | "etc/vndksp.libraries.29.txt", |
| 3322 | "etc/vndkprivate.libraries.29.txt", |
| 3323 | "etc/vndkproduct.libraries.29.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3324 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | func TestVndkApexWithPrebuilt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3328 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3329 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3330 | name: "com.android.vndk.current", |
| 3331 | key: "com.android.vndk.current.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3332 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3336 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3337 | public_key: "testkey.avbpubkey", |
| 3338 | private_key: "testkey.pem", |
| 3339 | } |
| 3340 | |
| 3341 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3342 | name: "libvndk", |
| 3343 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3344 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3345 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3346 | vndk: { |
| 3347 | enabled: true, |
| 3348 | }, |
| 3349 | system_shared_libs: [], |
| 3350 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3351 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3352 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3353 | |
| 3354 | cc_prebuilt_library_shared { |
| 3355 | name: "libvndk.arm", |
| 3356 | srcs: ["libvndk.arm.so"], |
| 3357 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3358 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3359 | vndk: { |
| 3360 | enabled: true, |
| 3361 | }, |
| 3362 | enabled: false, |
| 3363 | arch: { |
| 3364 | arm: { |
| 3365 | enabled: true, |
| 3366 | }, |
| 3367 | }, |
| 3368 | system_shared_libs: [], |
| 3369 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3370 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3371 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3372 | `+vndkLibrariesTxtFiles("current"), |
| 3373 | withFiles(map[string][]byte{ |
| 3374 | "libvndk.so": nil, |
| 3375 | "libvndk.arm.so": nil, |
| 3376 | })) |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3377 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3378 | "lib/libvndk.so", |
| 3379 | "lib/libvndk.arm.so", |
| 3380 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3381 | "lib/libc++.so", |
| 3382 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3383 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3384 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3385 | } |
| 3386 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3387 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 3388 | for _, v := range vers { |
| 3389 | if v == "current" { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3390 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3391 | result += ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 3392 | ` + txt + `_libraries_txt { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3393 | name: "` + txt + `.libraries.txt", |
| 3394 | } |
| 3395 | ` |
| 3396 | } |
| 3397 | } else { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3398 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3399 | result += ` |
| 3400 | prebuilt_etc { |
| 3401 | name: "` + txt + `.libraries.` + v + `.txt", |
| 3402 | src: "dummy.txt", |
| 3403 | } |
| 3404 | ` |
| 3405 | } |
| 3406 | } |
| 3407 | } |
| 3408 | return |
| 3409 | } |
| 3410 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3411 | func TestVndkApexVersion(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3412 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3413 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3414 | name: "com.android.vndk.v27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3415 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3416 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3417 | vndk_version: "27", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3418 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | apex_key { |
| 3422 | name: "myapex.key", |
| 3423 | public_key: "testkey.avbpubkey", |
| 3424 | private_key: "testkey.pem", |
| 3425 | } |
| 3426 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3427 | vndk_prebuilt_shared { |
| 3428 | name: "libvndk27", |
| 3429 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3430 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3431 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3432 | vndk: { |
| 3433 | enabled: true, |
| 3434 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3435 | target_arch: "arm64", |
| 3436 | arch: { |
| 3437 | arm: { |
| 3438 | srcs: ["libvndk27_arm.so"], |
| 3439 | }, |
| 3440 | arm64: { |
| 3441 | srcs: ["libvndk27_arm64.so"], |
| 3442 | }, |
| 3443 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3444 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | vndk_prebuilt_shared { |
| 3448 | name: "libvndk27", |
| 3449 | version: "27", |
| 3450 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3451 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3452 | vndk: { |
| 3453 | enabled: true, |
| 3454 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3455 | target_arch: "x86_64", |
| 3456 | arch: { |
| 3457 | x86: { |
| 3458 | srcs: ["libvndk27_x86.so"], |
| 3459 | }, |
| 3460 | x86_64: { |
| 3461 | srcs: ["libvndk27_x86_64.so"], |
| 3462 | }, |
| 3463 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3464 | } |
| 3465 | `+vndkLibrariesTxtFiles("27"), |
| 3466 | withFiles(map[string][]byte{ |
| 3467 | "libvndk27_arm.so": nil, |
| 3468 | "libvndk27_arm64.so": nil, |
| 3469 | "libvndk27_x86.so": nil, |
| 3470 | "libvndk27_x86_64.so": nil, |
| 3471 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3472 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3473 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3474 | "lib/libvndk27_arm.so", |
| 3475 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3476 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3477 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3478 | } |
| 3479 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3480 | func TestVndkApexNameRule(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3481 | ctx := testApex(t, ` |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3482 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3483 | name: "com.android.vndk.current", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3484 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3485 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3486 | updatable: false, |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3487 | } |
| 3488 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3489 | name: "com.android.vndk.v28", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3490 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3491 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3492 | vndk_version: "28", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3493 | updatable: false, |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3494 | } |
| 3495 | apex_key { |
| 3496 | name: "myapex.key", |
| 3497 | public_key: "testkey.avbpubkey", |
| 3498 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3499 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3500 | |
| 3501 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3502 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3503 | actual := proptools.String(bundle.properties.Apex_name) |
| 3504 | if !reflect.DeepEqual(actual, expected) { |
| 3505 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3506 | } |
| 3507 | } |
| 3508 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 3509 | assertApexName("com.android.vndk.v29", "com.android.vndk.current") |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3510 | assertApexName("com.android.vndk.v28", "com.android.vndk.v28") |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3511 | } |
| 3512 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3513 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3514 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3515 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3516 | name: "com.android.vndk.current", |
| 3517 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3518 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3519 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3523 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3524 | public_key: "testkey.avbpubkey", |
| 3525 | private_key: "testkey.pem", |
| 3526 | } |
| 3527 | |
| 3528 | cc_library { |
| 3529 | name: "libvndk", |
| 3530 | srcs: ["mylib.cpp"], |
| 3531 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3532 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3533 | native_bridge_supported: true, |
| 3534 | host_supported: true, |
| 3535 | vndk: { |
| 3536 | enabled: true, |
| 3537 | }, |
| 3538 | system_shared_libs: [], |
| 3539 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3540 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3541 | } |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3542 | `+vndkLibrariesTxtFiles("current"), |
| 3543 | withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3544 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3545 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3546 | "lib/libvndk.so", |
| 3547 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3548 | "lib/libc++.so", |
| 3549 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3550 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3551 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3555 | testApexError(t, `module "com.android.vndk.current" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3556 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3557 | name: "com.android.vndk.current", |
| 3558 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3559 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3560 | native_bridge_supported: true, |
| 3561 | } |
| 3562 | |
| 3563 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3564 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3565 | public_key: "testkey.avbpubkey", |
| 3566 | private_key: "testkey.pem", |
| 3567 | } |
| 3568 | |
| 3569 | cc_library { |
| 3570 | name: "libvndk", |
| 3571 | srcs: ["mylib.cpp"], |
| 3572 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3573 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3574 | native_bridge_supported: true, |
| 3575 | host_supported: true, |
| 3576 | vndk: { |
| 3577 | enabled: true, |
| 3578 | }, |
| 3579 | system_shared_libs: [], |
| 3580 | stl: "none", |
| 3581 | } |
| 3582 | `) |
| 3583 | } |
| 3584 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3585 | func TestVndkApexWithBinder32(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3586 | ctx := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3587 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3588 | name: "com.android.vndk.v27", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3589 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3590 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3591 | vndk_version: "27", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3592 | updatable: false, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | apex_key { |
| 3596 | name: "myapex.key", |
| 3597 | public_key: "testkey.avbpubkey", |
| 3598 | private_key: "testkey.pem", |
| 3599 | } |
| 3600 | |
| 3601 | vndk_prebuilt_shared { |
| 3602 | name: "libvndk27", |
| 3603 | version: "27", |
| 3604 | target_arch: "arm", |
| 3605 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3606 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3607 | vndk: { |
| 3608 | enabled: true, |
| 3609 | }, |
| 3610 | arch: { |
| 3611 | arm: { |
| 3612 | srcs: ["libvndk27.so"], |
| 3613 | } |
| 3614 | }, |
| 3615 | } |
| 3616 | |
| 3617 | vndk_prebuilt_shared { |
| 3618 | name: "libvndk27", |
| 3619 | version: "27", |
| 3620 | target_arch: "arm", |
| 3621 | binder32bit: true, |
| 3622 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3623 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3624 | vndk: { |
| 3625 | enabled: true, |
| 3626 | }, |
| 3627 | arch: { |
| 3628 | arm: { |
| 3629 | srcs: ["libvndk27binder32.so"], |
| 3630 | } |
| 3631 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3632 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3633 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3634 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3635 | withFiles(map[string][]byte{ |
| 3636 | "libvndk27.so": nil, |
| 3637 | "libvndk27binder32.so": nil, |
| 3638 | }), |
| 3639 | withBinder32bit, |
| 3640 | withTargets(map[android.OsType][]android.Target{ |
| 3641 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3642 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3643 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3644 | }, |
| 3645 | }), |
| 3646 | ) |
| 3647 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3648 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3649 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3650 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3651 | }) |
| 3652 | } |
| 3653 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3654 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3655 | ctx := testApex(t, ` |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3656 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3657 | name: "com.android.vndk.current", |
| 3658 | key: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3659 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3660 | updatable: false, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3664 | name: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3665 | public_key: "testkey.avbpubkey", |
| 3666 | private_key: "testkey.pem", |
| 3667 | } |
| 3668 | |
| 3669 | cc_library { |
| 3670 | name: "libz", |
| 3671 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3672 | product_available: true, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3673 | vndk: { |
| 3674 | enabled: true, |
| 3675 | }, |
| 3676 | stubs: { |
| 3677 | symbol_file: "libz.map.txt", |
| 3678 | versions: ["30"], |
| 3679 | } |
| 3680 | } |
| 3681 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3682 | "libz.map.txt": nil, |
| 3683 | })) |
| 3684 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3685 | apexManifestRule := ctx.ModuleForTests("com.android.vndk.current", "android_common_image").Rule("apexManifestRule") |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3686 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3687 | ensureListEmpty(t, provideNativeLibs) |
| 3688 | } |
| 3689 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3690 | func TestDependenciesInApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3691 | ctx := testApex(t, ` |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3692 | apex { |
| 3693 | name: "myapex_nodep", |
| 3694 | key: "myapex.key", |
| 3695 | native_shared_libs: ["lib_nodep"], |
| 3696 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3697 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3698 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | apex { |
| 3702 | name: "myapex_dep", |
| 3703 | key: "myapex.key", |
| 3704 | native_shared_libs: ["lib_dep"], |
| 3705 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3706 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3707 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | apex { |
| 3711 | name: "myapex_provider", |
| 3712 | key: "myapex.key", |
| 3713 | native_shared_libs: ["libfoo"], |
| 3714 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3715 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3716 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | apex { |
| 3720 | name: "myapex_selfcontained", |
| 3721 | key: "myapex.key", |
| 3722 | native_shared_libs: ["lib_dep", "libfoo"], |
| 3723 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3724 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3725 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | apex_key { |
| 3729 | name: "myapex.key", |
| 3730 | public_key: "testkey.avbpubkey", |
| 3731 | private_key: "testkey.pem", |
| 3732 | } |
| 3733 | |
| 3734 | cc_library { |
| 3735 | name: "lib_nodep", |
| 3736 | srcs: ["mylib.cpp"], |
| 3737 | system_shared_libs: [], |
| 3738 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3739 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | cc_library { |
| 3743 | name: "lib_dep", |
| 3744 | srcs: ["mylib.cpp"], |
| 3745 | shared_libs: ["libfoo"], |
| 3746 | system_shared_libs: [], |
| 3747 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3748 | apex_available: [ |
| 3749 | "myapex_dep", |
| 3750 | "myapex_provider", |
| 3751 | "myapex_selfcontained", |
| 3752 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | cc_library { |
| 3756 | name: "libfoo", |
| 3757 | srcs: ["mytest.cpp"], |
| 3758 | stubs: { |
| 3759 | versions: ["1"], |
| 3760 | }, |
| 3761 | system_shared_libs: [], |
| 3762 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3763 | apex_available: [ |
| 3764 | "myapex_provider", |
| 3765 | "myapex_selfcontained", |
| 3766 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3767 | } |
| 3768 | `) |
| 3769 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3770 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3771 | var provideNativeLibs, requireNativeLibs []string |
| 3772 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3773 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3774 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3775 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3776 | ensureListEmpty(t, provideNativeLibs) |
| 3777 | ensureListEmpty(t, requireNativeLibs) |
| 3778 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3779 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3780 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3781 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3782 | ensureListEmpty(t, provideNativeLibs) |
| 3783 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 3784 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3785 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3786 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3787 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3788 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3789 | ensureListEmpty(t, requireNativeLibs) |
| 3790 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3791 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3792 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3793 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3794 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3795 | ensureListEmpty(t, requireNativeLibs) |
| 3796 | } |
| 3797 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3798 | func TestApexName(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3799 | ctx := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3800 | apex { |
| 3801 | name: "myapex", |
| 3802 | key: "myapex.key", |
| 3803 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3804 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3805 | updatable: false, |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3806 | } |
| 3807 | |
| 3808 | apex_key { |
| 3809 | name: "myapex.key", |
| 3810 | public_key: "testkey.avbpubkey", |
| 3811 | private_key: "testkey.pem", |
| 3812 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3813 | |
| 3814 | cc_library { |
| 3815 | name: "mylib", |
| 3816 | srcs: ["mylib.cpp"], |
| 3817 | system_shared_libs: [], |
| 3818 | stl: "none", |
| 3819 | apex_available: [ |
| 3820 | "//apex_available:platform", |
| 3821 | "myapex", |
| 3822 | ], |
| 3823 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3824 | `) |
| 3825 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3826 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3827 | apexManifestRule := module.Rule("apexManifestRule") |
| 3828 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 3829 | apexRule := module.Rule("apexRule") |
| 3830 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3831 | |
| 3832 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3833 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3834 | name := apexBundle.BaseModuleName() |
| 3835 | prefix := "TARGET_" |
| 3836 | var builder strings.Builder |
| 3837 | data.Custom(&builder, name, prefix, "", data) |
| 3838 | androidMk := builder.String() |
| 3839 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 3840 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3841 | } |
| 3842 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3843 | func TestNonTestApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3844 | ctx := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3845 | apex { |
| 3846 | name: "myapex", |
| 3847 | key: "myapex.key", |
| 3848 | native_shared_libs: ["mylib_common"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3849 | updatable: false, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | apex_key { |
| 3853 | name: "myapex.key", |
| 3854 | public_key: "testkey.avbpubkey", |
| 3855 | private_key: "testkey.pem", |
| 3856 | } |
| 3857 | |
| 3858 | cc_library { |
| 3859 | name: "mylib_common", |
| 3860 | srcs: ["mylib.cpp"], |
| 3861 | system_shared_libs: [], |
| 3862 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3863 | apex_available: [ |
| 3864 | "//apex_available:platform", |
| 3865 | "myapex", |
| 3866 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3867 | } |
| 3868 | `) |
| 3869 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3870 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3871 | apexRule := module.Rule("apexRule") |
| 3872 | copyCmds := apexRule.Args["copy_commands"] |
| 3873 | |
| 3874 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 3875 | t.Log("Apex was a test apex!") |
| 3876 | t.Fail() |
| 3877 | } |
| 3878 | // Ensure that main rule creates an output |
| 3879 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3880 | |
| 3881 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3882 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3883 | |
| 3884 | // Ensure that both direct and indirect deps are copied into apex |
| 3885 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3886 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3887 | // Ensure that the platform variant ends with _shared |
| 3888 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3889 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3890 | if !ctx.ModuleForTests("mylib_common", "android_arm64_armv8-a_shared_apex10000").Module().(*cc.Module).InAnyApex() { |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3891 | t.Log("Found mylib_common not in any apex!") |
| 3892 | t.Fail() |
| 3893 | } |
| 3894 | } |
| 3895 | |
| 3896 | func TestTestApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3897 | ctx := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3898 | apex_test { |
| 3899 | name: "myapex", |
| 3900 | key: "myapex.key", |
| 3901 | native_shared_libs: ["mylib_common_test"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3902 | updatable: false, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3903 | } |
| 3904 | |
| 3905 | apex_key { |
| 3906 | name: "myapex.key", |
| 3907 | public_key: "testkey.avbpubkey", |
| 3908 | private_key: "testkey.pem", |
| 3909 | } |
| 3910 | |
| 3911 | cc_library { |
| 3912 | name: "mylib_common_test", |
| 3913 | srcs: ["mylib.cpp"], |
| 3914 | system_shared_libs: [], |
| 3915 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3916 | // TODO: remove //apex_available:platform |
| 3917 | apex_available: [ |
| 3918 | "//apex_available:platform", |
| 3919 | "myapex", |
| 3920 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3921 | } |
| 3922 | `) |
| 3923 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3924 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3925 | apexRule := module.Rule("apexRule") |
| 3926 | copyCmds := apexRule.Args["copy_commands"] |
| 3927 | |
| 3928 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 3929 | t.Log("Apex was not a test apex!") |
| 3930 | t.Fail() |
| 3931 | } |
| 3932 | // Ensure that main rule creates an output |
| 3933 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3934 | |
| 3935 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3936 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3937 | |
| 3938 | // Ensure that both direct and indirect deps are copied into apex |
| 3939 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 3940 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3941 | // Ensure that the platform variant ends with _shared |
| 3942 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3943 | } |
| 3944 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3945 | func TestApexWithTarget(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3946 | ctx := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3947 | apex { |
| 3948 | name: "myapex", |
| 3949 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3950 | updatable: false, |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3951 | multilib: { |
| 3952 | first: { |
| 3953 | native_shared_libs: ["mylib_common"], |
| 3954 | } |
| 3955 | }, |
| 3956 | target: { |
| 3957 | android: { |
| 3958 | multilib: { |
| 3959 | first: { |
| 3960 | native_shared_libs: ["mylib"], |
| 3961 | } |
| 3962 | } |
| 3963 | }, |
| 3964 | host: { |
| 3965 | multilib: { |
| 3966 | first: { |
| 3967 | native_shared_libs: ["mylib2"], |
| 3968 | } |
| 3969 | } |
| 3970 | } |
| 3971 | } |
| 3972 | } |
| 3973 | |
| 3974 | apex_key { |
| 3975 | name: "myapex.key", |
| 3976 | public_key: "testkey.avbpubkey", |
| 3977 | private_key: "testkey.pem", |
| 3978 | } |
| 3979 | |
| 3980 | cc_library { |
| 3981 | name: "mylib", |
| 3982 | srcs: ["mylib.cpp"], |
| 3983 | system_shared_libs: [], |
| 3984 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3985 | // TODO: remove //apex_available:platform |
| 3986 | apex_available: [ |
| 3987 | "//apex_available:platform", |
| 3988 | "myapex", |
| 3989 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | cc_library { |
| 3993 | name: "mylib_common", |
| 3994 | srcs: ["mylib.cpp"], |
| 3995 | system_shared_libs: [], |
| 3996 | stl: "none", |
| 3997 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3998 | // TODO: remove //apex_available:platform |
| 3999 | apex_available: [ |
| 4000 | "//apex_available:platform", |
| 4001 | "myapex", |
| 4002 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | cc_library { |
| 4006 | name: "mylib2", |
| 4007 | srcs: ["mylib.cpp"], |
| 4008 | system_shared_libs: [], |
| 4009 | stl: "none", |
| 4010 | compile_multilib: "first", |
| 4011 | } |
| 4012 | `) |
| 4013 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4014 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4015 | copyCmds := apexRule.Args["copy_commands"] |
| 4016 | |
| 4017 | // Ensure that main rule creates an output |
| 4018 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 4019 | |
| 4020 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4021 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 4022 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
| 4023 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4024 | |
| 4025 | // Ensure that both direct and indirect deps are copied into apex |
| 4026 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 4027 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 4028 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 4029 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4030 | // Ensure that the platform variant ends with _shared |
| 4031 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 4032 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 4033 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4034 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4035 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4036 | func TestApexWithArch(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4037 | ctx := testApex(t, ` |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4038 | apex { |
| 4039 | name: "myapex", |
| 4040 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4041 | updatable: false, |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4042 | arch: { |
| 4043 | arm64: { |
| 4044 | native_shared_libs: ["mylib.arm64"], |
| 4045 | }, |
| 4046 | x86_64: { |
| 4047 | native_shared_libs: ["mylib.x64"], |
| 4048 | }, |
| 4049 | } |
| 4050 | } |
| 4051 | |
| 4052 | apex_key { |
| 4053 | name: "myapex.key", |
| 4054 | public_key: "testkey.avbpubkey", |
| 4055 | private_key: "testkey.pem", |
| 4056 | } |
| 4057 | |
| 4058 | cc_library { |
| 4059 | name: "mylib.arm64", |
| 4060 | srcs: ["mylib.cpp"], |
| 4061 | system_shared_libs: [], |
| 4062 | stl: "none", |
| 4063 | // TODO: remove //apex_available:platform |
| 4064 | apex_available: [ |
| 4065 | "//apex_available:platform", |
| 4066 | "myapex", |
| 4067 | ], |
| 4068 | } |
| 4069 | |
| 4070 | cc_library { |
| 4071 | name: "mylib.x64", |
| 4072 | srcs: ["mylib.cpp"], |
| 4073 | system_shared_libs: [], |
| 4074 | stl: "none", |
| 4075 | // TODO: remove //apex_available:platform |
| 4076 | apex_available: [ |
| 4077 | "//apex_available:platform", |
| 4078 | "myapex", |
| 4079 | ], |
| 4080 | } |
| 4081 | `) |
| 4082 | |
| 4083 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 4084 | copyCmds := apexRule.Args["copy_commands"] |
| 4085 | |
| 4086 | // Ensure that apex variant is created for the direct dep |
| 4087 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib.arm64"), "android_arm64_armv8-a_shared_apex10000") |
| 4088 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib.x64"), "android_arm64_armv8-a_shared_apex10000") |
| 4089 | |
| 4090 | // Ensure that both direct and indirect deps are copied into apex |
| 4091 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.arm64.so") |
| 4092 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib.x64.so") |
| 4093 | } |
| 4094 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4095 | func TestApexWithShBinary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4096 | ctx := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4097 | apex { |
| 4098 | name: "myapex", |
| 4099 | key: "myapex.key", |
| 4100 | binaries: ["myscript"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4101 | updatable: false, |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | apex_key { |
| 4105 | name: "myapex.key", |
| 4106 | public_key: "testkey.avbpubkey", |
| 4107 | private_key: "testkey.pem", |
| 4108 | } |
| 4109 | |
| 4110 | sh_binary { |
| 4111 | name: "myscript", |
| 4112 | src: "mylib.cpp", |
| 4113 | filename: "myscript.sh", |
| 4114 | sub_dir: "script", |
| 4115 | } |
| 4116 | `) |
| 4117 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4118 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4119 | copyCmds := apexRule.Args["copy_commands"] |
| 4120 | |
| 4121 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 4122 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4123 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4124 | func TestApexInVariousPartition(t *testing.T) { |
| 4125 | testcases := []struct { |
| 4126 | propName, parition, flattenedPartition string |
| 4127 | }{ |
| 4128 | {"", "system", "system_ext"}, |
| 4129 | {"product_specific: true", "product", "product"}, |
| 4130 | {"soc_specific: true", "vendor", "vendor"}, |
| 4131 | {"proprietary: true", "vendor", "vendor"}, |
| 4132 | {"vendor: true", "vendor", "vendor"}, |
| 4133 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 4134 | } |
| 4135 | for _, tc := range testcases { |
| 4136 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4137 | ctx := testApex(t, ` |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4138 | apex { |
| 4139 | name: "myapex", |
| 4140 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4141 | updatable: false, |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4142 | `+tc.propName+` |
| 4143 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4144 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4145 | apex_key { |
| 4146 | name: "myapex.key", |
| 4147 | public_key: "testkey.avbpubkey", |
| 4148 | private_key: "testkey.pem", |
| 4149 | } |
| 4150 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4151 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4152 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 4153 | expected := "out/soong/target/product/test_device/" + tc.parition + "/apex" |
| 4154 | actual := apex.installDir.RelativeToTop().String() |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4155 | if actual != expected { |
| 4156 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4157 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4158 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4159 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 4160 | expected = "out/soong/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 4161 | actual = flattened.installDir.RelativeToTop().String() |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4162 | if actual != expected { |
| 4163 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4164 | } |
| 4165 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4166 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4167 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4168 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4169 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4170 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4171 | apex { |
| 4172 | name: "myapex", |
| 4173 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4174 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4175 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4176 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4177 | apex_key { |
| 4178 | name: "myapex.key", |
| 4179 | public_key: "testkey.avbpubkey", |
| 4180 | private_key: "testkey.pem", |
| 4181 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4182 | `) |
| 4183 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4184 | rule := module.Output("file_contexts") |
| 4185 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 4186 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4187 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4188 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4189 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4190 | apex { |
| 4191 | name: "myapex", |
| 4192 | key: "myapex.key", |
| 4193 | file_contexts: "my_own_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4194 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4195 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4196 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4197 | apex_key { |
| 4198 | name: "myapex.key", |
| 4199 | public_key: "testkey.avbpubkey", |
| 4200 | private_key: "testkey.pem", |
| 4201 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4202 | `, withFiles(map[string][]byte{ |
| 4203 | "my_own_file_contexts": nil, |
| 4204 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4205 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4206 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4207 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4208 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4209 | apex { |
| 4210 | name: "myapex", |
| 4211 | key: "myapex.key", |
| 4212 | product_specific: true, |
| 4213 | file_contexts: "product_specific_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4214 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4215 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4216 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4217 | apex_key { |
| 4218 | name: "myapex.key", |
| 4219 | public_key: "testkey.avbpubkey", |
| 4220 | private_key: "testkey.pem", |
| 4221 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4222 | `) |
| 4223 | |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4224 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4225 | apex { |
| 4226 | name: "myapex", |
| 4227 | key: "myapex.key", |
| 4228 | product_specific: true, |
| 4229 | file_contexts: "product_specific_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4230 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4231 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4232 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4233 | apex_key { |
| 4234 | name: "myapex.key", |
| 4235 | public_key: "testkey.avbpubkey", |
| 4236 | private_key: "testkey.pem", |
| 4237 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4238 | `, withFiles(map[string][]byte{ |
| 4239 | "product_specific_file_contexts": nil, |
| 4240 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4241 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4242 | rule := module.Output("file_contexts") |
| 4243 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 4244 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4245 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4246 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4247 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4248 | apex { |
| 4249 | name: "myapex", |
| 4250 | key: "myapex.key", |
| 4251 | product_specific: true, |
| 4252 | file_contexts: ":my-file-contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4253 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4254 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4255 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4256 | apex_key { |
| 4257 | name: "myapex.key", |
| 4258 | public_key: "testkey.avbpubkey", |
| 4259 | private_key: "testkey.pem", |
| 4260 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4261 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4262 | filegroup { |
| 4263 | name: "my-file-contexts", |
| 4264 | srcs: ["product_specific_file_contexts"], |
| 4265 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4266 | `, withFiles(map[string][]byte{ |
| 4267 | "product_specific_file_contexts": nil, |
| 4268 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4269 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4270 | rule := module.Output("file_contexts") |
| 4271 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4272 | } |
| 4273 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4274 | func TestApexKeyFromOtherModule(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4275 | ctx := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4276 | apex_key { |
| 4277 | name: "myapex.key", |
| 4278 | public_key: ":my.avbpubkey", |
| 4279 | private_key: ":my.pem", |
| 4280 | product_specific: true, |
| 4281 | } |
| 4282 | |
| 4283 | filegroup { |
| 4284 | name: "my.avbpubkey", |
| 4285 | srcs: ["testkey2.avbpubkey"], |
| 4286 | } |
| 4287 | |
| 4288 | filegroup { |
| 4289 | name: "my.pem", |
| 4290 | srcs: ["testkey2.pem"], |
| 4291 | } |
| 4292 | `) |
| 4293 | |
| 4294 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 4295 | expected_pubkey := "testkey2.avbpubkey" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4296 | actual_pubkey := apex_key.publicKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4297 | if actual_pubkey != expected_pubkey { |
| 4298 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 4299 | } |
| 4300 | expected_privkey := "testkey2.pem" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4301 | actual_privkey := apex_key.privateKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4302 | if actual_privkey != expected_privkey { |
| 4303 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 4304 | } |
| 4305 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4306 | |
| 4307 | func TestPrebuilt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4308 | ctx := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4309 | prebuilt_apex { |
| 4310 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4311 | arch: { |
| 4312 | arm64: { |
| 4313 | src: "myapex-arm64.apex", |
| 4314 | }, |
| 4315 | arm: { |
| 4316 | src: "myapex-arm.apex", |
| 4317 | }, |
| 4318 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4319 | } |
| 4320 | `) |
| 4321 | |
| 4322 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4323 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4324 | expectedInput := "myapex-arm64.apex" |
| 4325 | if prebuilt.inputApex.String() != expectedInput { |
| 4326 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 4327 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4328 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4329 | |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 4330 | func TestPrebuiltMissingSrc(t *testing.T) { |
| 4331 | testApexError(t, `module "myapex" variant "android_common".*: prebuilt_apex does not support "arm64_armv8-a"`, ` |
| 4332 | prebuilt_apex { |
| 4333 | name: "myapex", |
| 4334 | } |
| 4335 | `) |
| 4336 | } |
| 4337 | |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4338 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4339 | ctx := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4340 | prebuilt_apex { |
| 4341 | name: "myapex", |
| 4342 | src: "myapex-arm.apex", |
| 4343 | filename: "notmyapex.apex", |
| 4344 | } |
| 4345 | `) |
| 4346 | |
| 4347 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4348 | |
| 4349 | expected := "notmyapex.apex" |
| 4350 | if p.installFilename != expected { |
| 4351 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 4352 | } |
| 4353 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4354 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4355 | func TestPrebuiltOverrides(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4356 | ctx := testApex(t, ` |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4357 | prebuilt_apex { |
| 4358 | name: "myapex.prebuilt", |
| 4359 | src: "myapex-arm.apex", |
| 4360 | overrides: [ |
| 4361 | "myapex", |
| 4362 | ], |
| 4363 | } |
| 4364 | `) |
| 4365 | |
| 4366 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 4367 | |
| 4368 | expected := []string{"myapex"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4369 | actual := android.AndroidMkEntriesForTest(t, ctx, p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4370 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 4371 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4372 | } |
| 4373 | } |
| 4374 | |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4375 | // These tests verify that the prebuilt_apex/deapexer to java_import wiring allows for the |
| 4376 | // propagation of paths to dex implementation jars from the former to the latter. |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4377 | func TestPrebuiltExportDexImplementationJars(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 4378 | transform := android.NullFixturePreparer |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4379 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4380 | checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4381 | // Make sure the import has been given the correct path to the dex jar. |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 4382 | p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4383 | dexJarBuildPath := p.DexJarBuildPath() |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4384 | stem := android.RemoveOptionalPrebuiltPrefix(name) |
| 4385 | if expected, actual := ".intermediates/myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar", android.NormalizePathForTesting(dexJarBuildPath); actual != expected { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4386 | t.Errorf("Incorrect DexJarBuildPath value '%s', expected '%s'", actual, expected) |
| 4387 | } |
| 4388 | } |
| 4389 | |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4390 | ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4391 | // Make sure that an apex variant is not created for the source module. |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4392 | if expected, actual := []string{"android_common"}, ctx.ModuleVariantsForTests(name); !reflect.DeepEqual(expected, actual) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4393 | t.Errorf("invalid set of variants for %q: expected %q, found %q", "libfoo", expected, actual) |
| 4394 | } |
| 4395 | } |
| 4396 | |
| 4397 | t.Run("prebuilt only", func(t *testing.T) { |
| 4398 | bp := ` |
| 4399 | prebuilt_apex { |
| 4400 | name: "myapex", |
| 4401 | arch: { |
| 4402 | arm64: { |
| 4403 | src: "myapex-arm64.apex", |
| 4404 | }, |
| 4405 | arm: { |
| 4406 | src: "myapex-arm.apex", |
| 4407 | }, |
| 4408 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4409 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | java_import { |
| 4413 | name: "libfoo", |
| 4414 | jars: ["libfoo.jar"], |
| 4415 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4416 | |
| 4417 | java_sdk_library_import { |
| 4418 | name: "libbar", |
| 4419 | public: { |
| 4420 | jars: ["libbar.jar"], |
| 4421 | }, |
| 4422 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4423 | ` |
| 4424 | |
| 4425 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4426 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4427 | |
Paul Duffin | f6932af | 2021-02-26 18:21:56 +0000 | [diff] [blame] | 4428 | // Make sure that the deapexer has the correct input APEX. |
| 4429 | deapexer := ctx.ModuleForTests("myapex.deapexer", "android_common") |
| 4430 | rule := deapexer.Rule("deapexer") |
| 4431 | if expected, actual := []string{"myapex-arm64.apex"}, android.NormalizePathsForTesting(rule.Implicits); !reflect.DeepEqual(expected, actual) { |
| 4432 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4433 | } |
| 4434 | |
Paul Duffin | 0d10c3c | 2021-03-01 17:09:32 +0000 | [diff] [blame] | 4435 | // Make sure that the prebuilt_apex has the correct input APEX. |
| 4436 | prebuiltApex := ctx.ModuleForTests("myapex", "android_common") |
| 4437 | rule = prebuiltApex.Rule("android/soong/android.Cp") |
| 4438 | if expected, actual := "myapex-arm64.apex", android.NormalizePathForTesting(rule.Input); !reflect.DeepEqual(expected, actual) { |
| 4439 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4440 | } |
| 4441 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4442 | checkDexJarBuildPath(t, ctx, "libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4443 | |
| 4444 | checkDexJarBuildPath(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4445 | }) |
| 4446 | |
| 4447 | t.Run("prebuilt with source preferred", func(t *testing.T) { |
| 4448 | |
| 4449 | bp := ` |
| 4450 | prebuilt_apex { |
| 4451 | name: "myapex", |
| 4452 | arch: { |
| 4453 | arm64: { |
| 4454 | src: "myapex-arm64.apex", |
| 4455 | }, |
| 4456 | arm: { |
| 4457 | src: "myapex-arm.apex", |
| 4458 | }, |
| 4459 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4460 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | java_import { |
| 4464 | name: "libfoo", |
| 4465 | jars: ["libfoo.jar"], |
| 4466 | } |
| 4467 | |
| 4468 | java_library { |
| 4469 | name: "libfoo", |
| 4470 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4471 | |
| 4472 | java_sdk_library_import { |
| 4473 | name: "libbar", |
| 4474 | public: { |
| 4475 | jars: ["libbar.jar"], |
| 4476 | }, |
| 4477 | } |
| 4478 | |
| 4479 | java_sdk_library { |
| 4480 | name: "libbar", |
| 4481 | srcs: ["foo/bar/MyClass.java"], |
| 4482 | unsafe_ignore_missing_latest_api: true, |
| 4483 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4484 | ` |
| 4485 | |
| 4486 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4487 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4488 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4489 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4490 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4491 | |
| 4492 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
| 4493 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4494 | }) |
| 4495 | |
| 4496 | t.Run("prebuilt preferred with source", func(t *testing.T) { |
| 4497 | bp := ` |
| 4498 | prebuilt_apex { |
| 4499 | name: "myapex", |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4500 | arch: { |
| 4501 | arm64: { |
| 4502 | src: "myapex-arm64.apex", |
| 4503 | }, |
| 4504 | arm: { |
| 4505 | src: "myapex-arm.apex", |
| 4506 | }, |
| 4507 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4508 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4509 | } |
| 4510 | |
| 4511 | java_import { |
| 4512 | name: "libfoo", |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4513 | prefer: true, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4514 | jars: ["libfoo.jar"], |
| 4515 | } |
| 4516 | |
| 4517 | java_library { |
| 4518 | name: "libfoo", |
| 4519 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4520 | |
| 4521 | java_sdk_library_import { |
| 4522 | name: "libbar", |
| 4523 | prefer: true, |
| 4524 | public: { |
| 4525 | jars: ["libbar.jar"], |
| 4526 | }, |
| 4527 | } |
| 4528 | |
| 4529 | java_sdk_library { |
| 4530 | name: "libbar", |
| 4531 | srcs: ["foo/bar/MyClass.java"], |
| 4532 | unsafe_ignore_missing_latest_api: true, |
| 4533 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4534 | ` |
| 4535 | |
| 4536 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4537 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4538 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4539 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4540 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4541 | |
| 4542 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
| 4543 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4544 | }) |
| 4545 | } |
| 4546 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4547 | func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 4548 | preparer := java.FixtureConfigureBootJars("myapex:libfoo", "myapex:libbar") |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4549 | |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4550 | checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) { |
| 4551 | t.Helper() |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4552 | s := ctx.SingletonForTests("dex_bootjars") |
| 4553 | foundLibfooJar := false |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4554 | base := stem + ".jar" |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4555 | for _, output := range s.AllOutputs() { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4556 | if filepath.Base(output) == base { |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4557 | foundLibfooJar = true |
| 4558 | buildRule := s.Output(output) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 4559 | android.AssertStringEquals(t, "boot dex jar path", bootDexJarPath, buildRule.Input.String()) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4560 | } |
| 4561 | } |
| 4562 | if !foundLibfooJar { |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 4563 | t.Errorf("Rule for libfoo.jar missing in dex_bootjars singleton outputs %q", android.StringPathsRelativeToTop(ctx.Config().BuildDir(), s.AllOutputs())) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4564 | } |
| 4565 | } |
| 4566 | |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4567 | checkHiddenAPIIndexInputs := func(t *testing.T, ctx *android.TestContext, expectedInputs string) { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4568 | t.Helper() |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame^] | 4569 | platformBootclasspath := ctx.ModuleForTests("platform-bootclasspath", "android_common") |
| 4570 | indexRule := platformBootclasspath.Rule("platform-bootclasspath-monolithic-hiddenapi-index") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4571 | java.CheckHiddenAPIRuleInputs(t, expectedInputs, indexRule) |
| 4572 | } |
| 4573 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4574 | t.Run("prebuilt only", func(t *testing.T) { |
| 4575 | bp := ` |
| 4576 | prebuilt_apex { |
| 4577 | name: "myapex", |
| 4578 | arch: { |
| 4579 | arm64: { |
| 4580 | src: "myapex-arm64.apex", |
| 4581 | }, |
| 4582 | arm: { |
| 4583 | src: "myapex-arm.apex", |
| 4584 | }, |
| 4585 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4586 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4587 | } |
| 4588 | |
| 4589 | java_import { |
| 4590 | name: "libfoo", |
| 4591 | jars: ["libfoo.jar"], |
| 4592 | apex_available: ["myapex"], |
| 4593 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4594 | |
| 4595 | java_sdk_library_import { |
| 4596 | name: "libbar", |
| 4597 | public: { |
| 4598 | jars: ["libbar.jar"], |
| 4599 | }, |
| 4600 | apex_available: ["myapex"], |
| 4601 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4602 | ` |
| 4603 | |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 4604 | ctx := testDexpreoptWithApexes(t, bp, "", preparer) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 4605 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4606 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4607 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4608 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4609 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4610 | .intermediates/libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4611 | .intermediates/libfoo/android_common_myapex/hiddenapi/index.csv |
| 4612 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4613 | }) |
| 4614 | |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 4615 | t.Run("apex_set only", func(t *testing.T) { |
| 4616 | bp := ` |
| 4617 | apex_set { |
| 4618 | name: "myapex", |
| 4619 | set: "myapex.apks", |
| 4620 | exported_java_libs: ["libfoo", "libbar"], |
| 4621 | } |
| 4622 | |
| 4623 | java_import { |
| 4624 | name: "libfoo", |
| 4625 | jars: ["libfoo.jar"], |
| 4626 | apex_available: ["myapex"], |
| 4627 | } |
| 4628 | |
| 4629 | java_sdk_library_import { |
| 4630 | name: "libbar", |
| 4631 | public: { |
| 4632 | jars: ["libbar.jar"], |
| 4633 | }, |
| 4634 | apex_available: ["myapex"], |
| 4635 | } |
| 4636 | ` |
| 4637 | |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 4638 | ctx := testDexpreoptWithApexes(t, bp, "", preparer) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 4639 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4640 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
| 4641 | |
| 4642 | // Make sure that the dex file from the apex_set contributes to the hiddenapi index file. |
| 4643 | checkHiddenAPIIndexInputs(t, ctx, ` |
| 4644 | .intermediates/libbar/android_common_myapex/hiddenapi/index.csv |
| 4645 | .intermediates/libfoo/android_common_myapex/hiddenapi/index.csv |
| 4646 | `) |
| 4647 | }) |
| 4648 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4649 | t.Run("prebuilt with source library preferred", func(t *testing.T) { |
| 4650 | bp := ` |
| 4651 | prebuilt_apex { |
| 4652 | name: "myapex", |
| 4653 | arch: { |
| 4654 | arm64: { |
| 4655 | src: "myapex-arm64.apex", |
| 4656 | }, |
| 4657 | arm: { |
| 4658 | src: "myapex-arm.apex", |
| 4659 | }, |
| 4660 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4661 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | java_import { |
| 4665 | name: "libfoo", |
| 4666 | jars: ["libfoo.jar"], |
| 4667 | apex_available: ["myapex"], |
| 4668 | } |
| 4669 | |
| 4670 | java_library { |
| 4671 | name: "libfoo", |
| 4672 | srcs: ["foo/bar/MyClass.java"], |
| 4673 | apex_available: ["myapex"], |
| 4674 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4675 | |
| 4676 | java_sdk_library_import { |
| 4677 | name: "libbar", |
| 4678 | public: { |
| 4679 | jars: ["libbar.jar"], |
| 4680 | }, |
| 4681 | apex_available: ["myapex"], |
| 4682 | } |
| 4683 | |
| 4684 | java_sdk_library { |
| 4685 | name: "libbar", |
| 4686 | srcs: ["foo/bar/MyClass.java"], |
| 4687 | unsafe_ignore_missing_latest_api: true, |
| 4688 | apex_available: ["myapex"], |
| 4689 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4690 | ` |
| 4691 | |
| 4692 | // In this test the source (java_library) libfoo is active since the |
| 4693 | // prebuilt (java_import) defaults to prefer:false. However the |
| 4694 | // prebuilt_apex module always depends on the prebuilt, and so it doesn't |
| 4695 | // find the dex boot jar in it. We either need to disable the source libfoo |
| 4696 | // or make the prebuilt libfoo preferred. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 4697 | testDexpreoptWithApexes(t, bp, "failed to find a dex jar path for module 'libfoo'", preparer) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4698 | }) |
| 4699 | |
| 4700 | t.Run("prebuilt library preferred with source", func(t *testing.T) { |
| 4701 | bp := ` |
| 4702 | prebuilt_apex { |
| 4703 | name: "myapex", |
| 4704 | arch: { |
| 4705 | arm64: { |
| 4706 | src: "myapex-arm64.apex", |
| 4707 | }, |
| 4708 | arm: { |
| 4709 | src: "myapex-arm.apex", |
| 4710 | }, |
| 4711 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4712 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4713 | } |
| 4714 | |
| 4715 | java_import { |
| 4716 | name: "libfoo", |
| 4717 | prefer: true, |
| 4718 | jars: ["libfoo.jar"], |
| 4719 | apex_available: ["myapex"], |
| 4720 | } |
| 4721 | |
| 4722 | java_library { |
| 4723 | name: "libfoo", |
| 4724 | srcs: ["foo/bar/MyClass.java"], |
| 4725 | apex_available: ["myapex"], |
| 4726 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4727 | |
| 4728 | java_sdk_library_import { |
| 4729 | name: "libbar", |
| 4730 | prefer: true, |
| 4731 | public: { |
| 4732 | jars: ["libbar.jar"], |
| 4733 | }, |
| 4734 | apex_available: ["myapex"], |
| 4735 | } |
| 4736 | |
| 4737 | java_sdk_library { |
| 4738 | name: "libbar", |
| 4739 | srcs: ["foo/bar/MyClass.java"], |
| 4740 | unsafe_ignore_missing_latest_api: true, |
| 4741 | apex_available: ["myapex"], |
| 4742 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4743 | ` |
| 4744 | |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 4745 | ctx := testDexpreoptWithApexes(t, bp, "", preparer) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 4746 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4747 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4748 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4749 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4750 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4751 | .intermediates/prebuilt_libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4752 | .intermediates/prebuilt_libfoo/android_common_myapex/hiddenapi/index.csv |
| 4753 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4754 | }) |
| 4755 | |
| 4756 | t.Run("prebuilt with source apex preferred", func(t *testing.T) { |
| 4757 | bp := ` |
| 4758 | apex { |
| 4759 | name: "myapex", |
| 4760 | key: "myapex.key", |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4761 | java_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4762 | updatable: false, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | apex_key { |
| 4766 | name: "myapex.key", |
| 4767 | public_key: "testkey.avbpubkey", |
| 4768 | private_key: "testkey.pem", |
| 4769 | } |
| 4770 | |
| 4771 | prebuilt_apex { |
| 4772 | name: "myapex", |
| 4773 | arch: { |
| 4774 | arm64: { |
| 4775 | src: "myapex-arm64.apex", |
| 4776 | }, |
| 4777 | arm: { |
| 4778 | src: "myapex-arm.apex", |
| 4779 | }, |
| 4780 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4781 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | java_import { |
| 4785 | name: "libfoo", |
| 4786 | jars: ["libfoo.jar"], |
| 4787 | apex_available: ["myapex"], |
| 4788 | } |
| 4789 | |
| 4790 | java_library { |
| 4791 | name: "libfoo", |
| 4792 | srcs: ["foo/bar/MyClass.java"], |
| 4793 | apex_available: ["myapex"], |
| 4794 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4795 | |
| 4796 | java_sdk_library_import { |
| 4797 | name: "libbar", |
| 4798 | public: { |
| 4799 | jars: ["libbar.jar"], |
| 4800 | }, |
| 4801 | apex_available: ["myapex"], |
| 4802 | } |
| 4803 | |
| 4804 | java_sdk_library { |
| 4805 | name: "libbar", |
| 4806 | srcs: ["foo/bar/MyClass.java"], |
| 4807 | unsafe_ignore_missing_latest_api: true, |
| 4808 | apex_available: ["myapex"], |
| 4809 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4810 | ` |
| 4811 | |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 4812 | ctx := testDexpreoptWithApexes(t, bp, "", preparer) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 4813 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar") |
| 4814 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/libbar/android_common_myapex/hiddenapi/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4815 | |
| 4816 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4817 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4818 | .intermediates/libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4819 | .intermediates/libfoo/android_common_apex10000/hiddenapi/index.csv |
| 4820 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4821 | }) |
| 4822 | |
| 4823 | t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) { |
| 4824 | bp := ` |
| 4825 | apex { |
| 4826 | name: "myapex", |
| 4827 | enabled: false, |
| 4828 | key: "myapex.key", |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 4829 | java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | apex_key { |
| 4833 | name: "myapex.key", |
| 4834 | public_key: "testkey.avbpubkey", |
| 4835 | private_key: "testkey.pem", |
| 4836 | } |
| 4837 | |
| 4838 | prebuilt_apex { |
| 4839 | name: "myapex", |
| 4840 | arch: { |
| 4841 | arm64: { |
| 4842 | src: "myapex-arm64.apex", |
| 4843 | }, |
| 4844 | arm: { |
| 4845 | src: "myapex-arm.apex", |
| 4846 | }, |
| 4847 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4848 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | java_import { |
| 4852 | name: "libfoo", |
| 4853 | prefer: true, |
| 4854 | jars: ["libfoo.jar"], |
| 4855 | apex_available: ["myapex"], |
| 4856 | } |
| 4857 | |
| 4858 | java_library { |
| 4859 | name: "libfoo", |
| 4860 | srcs: ["foo/bar/MyClass.java"], |
| 4861 | apex_available: ["myapex"], |
| 4862 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4863 | |
| 4864 | java_sdk_library_import { |
| 4865 | name: "libbar", |
| 4866 | prefer: true, |
| 4867 | public: { |
| 4868 | jars: ["libbar.jar"], |
| 4869 | }, |
| 4870 | apex_available: ["myapex"], |
| 4871 | } |
| 4872 | |
| 4873 | java_sdk_library { |
| 4874 | name: "libbar", |
| 4875 | srcs: ["foo/bar/MyClass.java"], |
| 4876 | unsafe_ignore_missing_latest_api: true, |
| 4877 | apex_available: ["myapex"], |
| 4878 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4879 | ` |
| 4880 | |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 4881 | ctx := testDexpreoptWithApexes(t, bp, "", preparer) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 4882 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4883 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4884 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4885 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4886 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 4887 | .intermediates/prebuilt_libbar/android_common_myapex/hiddenapi/index.csv |
| 4888 | .intermediates/prebuilt_libfoo/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4889 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4890 | }) |
| 4891 | } |
| 4892 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4893 | func TestApexWithTests(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4894 | ctx := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4895 | apex_test { |
| 4896 | name: "myapex", |
| 4897 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4898 | updatable: false, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4899 | tests: [ |
| 4900 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4901 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4902 | ], |
| 4903 | } |
| 4904 | |
| 4905 | apex_key { |
| 4906 | name: "myapex.key", |
| 4907 | public_key: "testkey.avbpubkey", |
| 4908 | private_key: "testkey.pem", |
| 4909 | } |
| 4910 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4911 | filegroup { |
| 4912 | name: "fg", |
| 4913 | srcs: [ |
| 4914 | "baz", |
| 4915 | "bar/baz" |
| 4916 | ], |
| 4917 | } |
| 4918 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4919 | cc_test { |
| 4920 | name: "mytest", |
| 4921 | gtest: false, |
| 4922 | srcs: ["mytest.cpp"], |
| 4923 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4924 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4925 | system_shared_libs: [], |
| 4926 | static_executable: true, |
| 4927 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4928 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4929 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4930 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4931 | cc_library { |
| 4932 | name: "mylib", |
| 4933 | srcs: ["mylib.cpp"], |
| 4934 | system_shared_libs: [], |
| 4935 | stl: "none", |
| 4936 | } |
| 4937 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4938 | filegroup { |
| 4939 | name: "fg2", |
| 4940 | srcs: [ |
| 4941 | "testdata/baz" |
| 4942 | ], |
| 4943 | } |
| 4944 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4945 | cc_test { |
| 4946 | name: "mytests", |
| 4947 | gtest: false, |
| 4948 | srcs: [ |
| 4949 | "mytest1.cpp", |
| 4950 | "mytest2.cpp", |
| 4951 | "mytest3.cpp", |
| 4952 | ], |
| 4953 | test_per_src: true, |
| 4954 | relative_install_path: "test", |
| 4955 | system_shared_libs: [], |
| 4956 | static_executable: true, |
| 4957 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4958 | data: [ |
| 4959 | ":fg", |
| 4960 | ":fg2", |
| 4961 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4962 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4963 | `) |
| 4964 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4965 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4966 | copyCmds := apexRule.Args["copy_commands"] |
| 4967 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4968 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4969 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4970 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4971 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4972 | //Ensure that test data are copied into apex. |
| 4973 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 4974 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 4975 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4976 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 4977 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 4978 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 4979 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4980 | |
| 4981 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4982 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4983 | data := android.AndroidMkDataForTest(t, ctx, bundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4984 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4985 | prefix := "TARGET_" |
| 4986 | var builder strings.Builder |
| 4987 | data.Custom(&builder, name, prefix, "", data) |
| 4988 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4989 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 4990 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 4991 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 4992 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4993 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4994 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4995 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4996 | |
| 4997 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4998 | data = android.AndroidMkDataForTest(t, ctx, flatBundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4999 | data.Custom(&builder, name, prefix, "", data) |
| 5000 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 5001 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 5002 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5003 | } |
| 5004 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5005 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5006 | ctx := testApex(t, ` |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5007 | apex { |
| 5008 | name: "myapex", |
| 5009 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5010 | updatable: false, |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5011 | } |
| 5012 | apex_key { |
| 5013 | name: "myapex.key", |
| 5014 | public_key: "testkey.avbpubkey", |
| 5015 | private_key: "testkey.pem", |
| 5016 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 5017 | `, |
| 5018 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 5019 | variables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 5020 | }), |
| 5021 | ) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5022 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 5023 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5024 | mk := android.AndroidMkDataForTest(t, ctx, ab) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5025 | var builder strings.Builder |
| 5026 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 5027 | androidMk := builder.String() |
| 5028 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 5029 | } |
| 5030 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5031 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 5032 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 5033 | apex { |
| 5034 | name: "myapex", |
| 5035 | key: "myapex.key", |
| 5036 | native_shared_libs: ["libfoo"], |
| 5037 | } |
| 5038 | |
| 5039 | apex_key { |
| 5040 | name: "myapex.key", |
| 5041 | public_key: "testkey.avbpubkey", |
| 5042 | private_key: "testkey.pem", |
| 5043 | } |
| 5044 | |
| 5045 | cc_library { |
| 5046 | name: "libfoo", |
| 5047 | stl: "none", |
| 5048 | system_shared_libs: [], |
| 5049 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5050 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5051 | } |
| 5052 | `) |
| 5053 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 5054 | apex { |
| 5055 | name: "myapex", |
| 5056 | key: "myapex.key", |
| 5057 | java_libs: ["myjar"], |
| 5058 | } |
| 5059 | |
| 5060 | apex_key { |
| 5061 | name: "myapex.key", |
| 5062 | public_key: "testkey.avbpubkey", |
| 5063 | private_key: "testkey.pem", |
| 5064 | } |
| 5065 | |
| 5066 | java_library { |
| 5067 | name: "myjar", |
| 5068 | srcs: ["foo/bar/MyClass.java"], |
| 5069 | sdk_version: "none", |
| 5070 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5071 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5072 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5073 | } |
| 5074 | `) |
| 5075 | } |
| 5076 | |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5077 | func TestApexWithJavaImport(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5078 | ctx := testApex(t, ` |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5079 | apex { |
| 5080 | name: "myapex", |
| 5081 | key: "myapex.key", |
| 5082 | java_libs: ["myjavaimport"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5083 | updatable: false, |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | apex_key { |
| 5087 | name: "myapex.key", |
| 5088 | public_key: "testkey.avbpubkey", |
| 5089 | private_key: "testkey.pem", |
| 5090 | } |
| 5091 | |
| 5092 | java_import { |
| 5093 | name: "myjavaimport", |
| 5094 | apex_available: ["myapex"], |
| 5095 | jars: ["my.jar"], |
| 5096 | compile_dex: true, |
| 5097 | } |
| 5098 | `) |
| 5099 | |
| 5100 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5101 | apexRule := module.Rule("apexRule") |
| 5102 | copyCmds := apexRule.Args["copy_commands"] |
| 5103 | ensureContains(t, copyCmds, "image.apex/javalib/myjavaimport.jar") |
| 5104 | } |
| 5105 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5106 | func TestApexWithApps(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5107 | ctx := testApex(t, ` |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5108 | apex { |
| 5109 | name: "myapex", |
| 5110 | key: "myapex.key", |
| 5111 | apps: [ |
| 5112 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5113 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5114 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5115 | updatable: false, |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | apex_key { |
| 5119 | name: "myapex.key", |
| 5120 | public_key: "testkey.avbpubkey", |
| 5121 | private_key: "testkey.pem", |
| 5122 | } |
| 5123 | |
| 5124 | android_app { |
| 5125 | name: "AppFoo", |
| 5126 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5127 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5128 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5129 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5130 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5131 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5132 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5133 | |
| 5134 | android_app { |
| 5135 | name: "AppFooPriv", |
| 5136 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5137 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5138 | system_modules: "none", |
| 5139 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5140 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5141 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5142 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5143 | |
| 5144 | cc_library_shared { |
| 5145 | name: "libjni", |
| 5146 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5147 | shared_libs: ["libfoo"], |
| 5148 | stl: "none", |
| 5149 | system_shared_libs: [], |
| 5150 | apex_available: [ "myapex" ], |
| 5151 | sdk_version: "current", |
| 5152 | } |
| 5153 | |
| 5154 | cc_library_shared { |
| 5155 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5156 | stl: "none", |
| 5157 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 5158 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5159 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5160 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5161 | `) |
| 5162 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5163 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5164 | apexRule := module.Rule("apexRule") |
| 5165 | copyCmds := apexRule.Args["copy_commands"] |
| 5166 | |
| 5167 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5168 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5169 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5170 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5171 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5172 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5173 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5174 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5175 | // JNI libraries including transitive deps are |
| 5176 | for _, jni := range []string{"libjni", "libfoo"} { |
Paul Duffin | afdd406 | 2021-03-30 19:44:07 +0100 | [diff] [blame] | 5177 | jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_sdk_shared_apex10000").Module().(*cc.Module).OutputFile().RelativeToTop() |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5178 | // ... embedded inside APK (jnilibs.zip) |
| 5179 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 5180 | // ... and not directly inside the APEX |
| 5181 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 5182 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5183 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5184 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5185 | func TestApexWithAppImports(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5186 | ctx := testApex(t, ` |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5187 | apex { |
| 5188 | name: "myapex", |
| 5189 | key: "myapex.key", |
| 5190 | apps: [ |
| 5191 | "AppFooPrebuilt", |
| 5192 | "AppFooPrivPrebuilt", |
| 5193 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5194 | updatable: false, |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | apex_key { |
| 5198 | name: "myapex.key", |
| 5199 | public_key: "testkey.avbpubkey", |
| 5200 | private_key: "testkey.pem", |
| 5201 | } |
| 5202 | |
| 5203 | android_app_import { |
| 5204 | name: "AppFooPrebuilt", |
| 5205 | apk: "PrebuiltAppFoo.apk", |
| 5206 | presigned: true, |
| 5207 | dex_preopt: { |
| 5208 | enabled: false, |
| 5209 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5210 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | android_app_import { |
| 5214 | name: "AppFooPrivPrebuilt", |
| 5215 | apk: "PrebuiltAppFooPriv.apk", |
| 5216 | privileged: true, |
| 5217 | presigned: true, |
| 5218 | dex_preopt: { |
| 5219 | enabled: false, |
| 5220 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5221 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5222 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5223 | } |
| 5224 | `) |
| 5225 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5226 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5227 | apexRule := module.Rule("apexRule") |
| 5228 | copyCmds := apexRule.Args["copy_commands"] |
| 5229 | |
| 5230 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5231 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 5232 | } |
| 5233 | |
| 5234 | func TestApexWithAppImportsPrefer(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5235 | ctx := testApex(t, ` |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5236 | apex { |
| 5237 | name: "myapex", |
| 5238 | key: "myapex.key", |
| 5239 | apps: [ |
| 5240 | "AppFoo", |
| 5241 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5242 | updatable: false, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | apex_key { |
| 5246 | name: "myapex.key", |
| 5247 | public_key: "testkey.avbpubkey", |
| 5248 | private_key: "testkey.pem", |
| 5249 | } |
| 5250 | |
| 5251 | android_app { |
| 5252 | name: "AppFoo", |
| 5253 | srcs: ["foo/bar/MyClass.java"], |
| 5254 | sdk_version: "none", |
| 5255 | system_modules: "none", |
| 5256 | apex_available: [ "myapex" ], |
| 5257 | } |
| 5258 | |
| 5259 | android_app_import { |
| 5260 | name: "AppFoo", |
| 5261 | apk: "AppFooPrebuilt.apk", |
| 5262 | filename: "AppFooPrebuilt.apk", |
| 5263 | presigned: true, |
| 5264 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5265 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5266 | } |
| 5267 | `, withFiles(map[string][]byte{ |
| 5268 | "AppFooPrebuilt.apk": nil, |
| 5269 | })) |
| 5270 | |
| 5271 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 86feead | 2021-03-08 13:11:48 +0900 | [diff] [blame] | 5272 | "app/AppFoo/AppFooPrebuilt.apk", |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5273 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5274 | } |
| 5275 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5276 | func TestApexWithTestHelperApp(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5277 | ctx := testApex(t, ` |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5278 | apex { |
| 5279 | name: "myapex", |
| 5280 | key: "myapex.key", |
| 5281 | apps: [ |
| 5282 | "TesterHelpAppFoo", |
| 5283 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5284 | updatable: false, |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | apex_key { |
| 5288 | name: "myapex.key", |
| 5289 | public_key: "testkey.avbpubkey", |
| 5290 | private_key: "testkey.pem", |
| 5291 | } |
| 5292 | |
| 5293 | android_test_helper_app { |
| 5294 | name: "TesterHelpAppFoo", |
| 5295 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5296 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5297 | } |
| 5298 | |
| 5299 | `) |
| 5300 | |
| 5301 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5302 | apexRule := module.Rule("apexRule") |
| 5303 | copyCmds := apexRule.Args["copy_commands"] |
| 5304 | |
| 5305 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 5306 | } |
| 5307 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5308 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 5309 | // libfoo's apex_available comes from cc_defaults |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5310 | testApexError(t, `requires "libfoo" that doesn't list the APEX under 'apex_available'.`, ` |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5311 | apex { |
| 5312 | name: "myapex", |
| 5313 | key: "myapex.key", |
| 5314 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5315 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | apex_key { |
| 5319 | name: "myapex.key", |
| 5320 | public_key: "testkey.avbpubkey", |
| 5321 | private_key: "testkey.pem", |
| 5322 | } |
| 5323 | |
| 5324 | apex { |
| 5325 | name: "otherapex", |
| 5326 | key: "myapex.key", |
| 5327 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5328 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | cc_defaults { |
| 5332 | name: "libfoo-defaults", |
| 5333 | apex_available: ["otherapex"], |
| 5334 | } |
| 5335 | |
| 5336 | cc_library { |
| 5337 | name: "libfoo", |
| 5338 | defaults: ["libfoo-defaults"], |
| 5339 | stl: "none", |
| 5340 | system_shared_libs: [], |
| 5341 | }`) |
| 5342 | } |
| 5343 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5344 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5345 | // libfoo is not available to myapex, but only to otherapex |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5346 | testApexError(t, "requires \"libfoo\" that doesn't list the APEX under 'apex_available'.", ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5347 | apex { |
| 5348 | name: "myapex", |
| 5349 | key: "myapex.key", |
| 5350 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5351 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5352 | } |
| 5353 | |
| 5354 | apex_key { |
| 5355 | name: "myapex.key", |
| 5356 | public_key: "testkey.avbpubkey", |
| 5357 | private_key: "testkey.pem", |
| 5358 | } |
| 5359 | |
| 5360 | apex { |
| 5361 | name: "otherapex", |
| 5362 | key: "otherapex.key", |
| 5363 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5364 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | apex_key { |
| 5368 | name: "otherapex.key", |
| 5369 | public_key: "testkey.avbpubkey", |
| 5370 | private_key: "testkey.pem", |
| 5371 | } |
| 5372 | |
| 5373 | cc_library { |
| 5374 | name: "libfoo", |
| 5375 | stl: "none", |
| 5376 | system_shared_libs: [], |
| 5377 | apex_available: ["otherapex"], |
| 5378 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5379 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5380 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5381 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5382 | // libbbaz is an indirect dep |
Jiyong Park | 767dbd9 | 2021-03-04 13:03:10 +0900 | [diff] [blame] | 5383 | testApexError(t, `requires "libbaz" that doesn't list the APEX under 'apex_available'.\n\nDependency path: |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5384 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5385 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5386 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5387 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5388 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 5389 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5390 | apex { |
| 5391 | name: "myapex", |
| 5392 | key: "myapex.key", |
| 5393 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5394 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5395 | } |
| 5396 | |
| 5397 | apex_key { |
| 5398 | name: "myapex.key", |
| 5399 | public_key: "testkey.avbpubkey", |
| 5400 | private_key: "testkey.pem", |
| 5401 | } |
| 5402 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5403 | cc_library { |
| 5404 | name: "libfoo", |
| 5405 | stl: "none", |
| 5406 | shared_libs: ["libbar"], |
| 5407 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5408 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | cc_library { |
| 5412 | name: "libbar", |
| 5413 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5414 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5415 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5416 | apex_available: ["myapex"], |
| 5417 | } |
| 5418 | |
| 5419 | cc_library { |
| 5420 | name: "libbaz", |
| 5421 | stl: "none", |
| 5422 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5423 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5424 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5425 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5426 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5427 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 5428 | apex { |
| 5429 | name: "myapex", |
| 5430 | key: "myapex.key", |
| 5431 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5432 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | apex_key { |
| 5436 | name: "myapex.key", |
| 5437 | public_key: "testkey.avbpubkey", |
| 5438 | private_key: "testkey.pem", |
| 5439 | } |
| 5440 | |
| 5441 | cc_library { |
| 5442 | name: "libfoo", |
| 5443 | stl: "none", |
| 5444 | system_shared_libs: [], |
| 5445 | apex_available: ["otherapex"], |
| 5446 | }`) |
| 5447 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5448 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5449 | apex { |
| 5450 | name: "myapex", |
| 5451 | key: "myapex.key", |
| 5452 | native_shared_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5453 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | apex_key { |
| 5457 | name: "myapex.key", |
| 5458 | public_key: "testkey.avbpubkey", |
| 5459 | private_key: "testkey.pem", |
| 5460 | } |
| 5461 | |
| 5462 | cc_library { |
| 5463 | name: "libfoo", |
| 5464 | stl: "none", |
| 5465 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5466 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5467 | apex_available: ["myapex"], |
| 5468 | } |
| 5469 | |
| 5470 | cc_library { |
| 5471 | name: "libbar", |
| 5472 | stl: "none", |
| 5473 | system_shared_libs: [], |
| 5474 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | cc_library { |
| 5478 | name: "libbaz", |
| 5479 | stl: "none", |
| 5480 | system_shared_libs: [], |
| 5481 | stubs: { |
| 5482 | versions: ["10", "20", "30"], |
| 5483 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5484 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5485 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5486 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5487 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5488 | ctx := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5489 | apex { |
| 5490 | name: "myapex", |
| 5491 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5492 | native_shared_libs: ["libbar", "libbaz"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5493 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | apex_key { |
| 5497 | name: "myapex.key", |
| 5498 | public_key: "testkey.avbpubkey", |
| 5499 | private_key: "testkey.pem", |
| 5500 | } |
| 5501 | |
| 5502 | cc_library { |
| 5503 | name: "libfoo", |
| 5504 | stl: "none", |
| 5505 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5506 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5507 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5508 | } |
| 5509 | |
| 5510 | cc_library { |
| 5511 | name: "libfoo2", |
| 5512 | stl: "none", |
| 5513 | system_shared_libs: [], |
| 5514 | shared_libs: ["libbaz"], |
| 5515 | apex_available: ["//apex_available:platform"], |
| 5516 | } |
| 5517 | |
| 5518 | cc_library { |
| 5519 | name: "libbar", |
| 5520 | stl: "none", |
| 5521 | system_shared_libs: [], |
| 5522 | apex_available: ["myapex"], |
| 5523 | } |
| 5524 | |
| 5525 | cc_library { |
| 5526 | name: "libbaz", |
| 5527 | stl: "none", |
| 5528 | system_shared_libs: [], |
| 5529 | apex_available: ["myapex"], |
| 5530 | stubs: { |
| 5531 | versions: ["1"], |
| 5532 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5533 | }`) |
| 5534 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5535 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 5536 | // because it depends on libbar which isn't available to platform |
| 5537 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5538 | if libfoo.NotAvailableForPlatform() != true { |
| 5539 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 5540 | } |
| 5541 | |
| 5542 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 5543 | // stubs |
| 5544 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5545 | if libfoo2.NotAvailableForPlatform() == true { |
| 5546 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 5547 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5548 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5549 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5550 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5551 | ctx := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5552 | apex { |
| 5553 | name: "myapex", |
| 5554 | key: "myapex.key", |
| 5555 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5556 | updatable: false, |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5557 | } |
| 5558 | |
| 5559 | apex_key { |
| 5560 | name: "myapex.key", |
| 5561 | public_key: "testkey.avbpubkey", |
| 5562 | private_key: "testkey.pem", |
| 5563 | } |
| 5564 | |
| 5565 | cc_library { |
| 5566 | name: "libfoo", |
| 5567 | stl: "none", |
| 5568 | system_shared_libs: [], |
| 5569 | apex_available: ["myapex"], |
| 5570 | static: { |
| 5571 | apex_available: ["//apex_available:platform"], |
| 5572 | }, |
| 5573 | }`) |
| 5574 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5575 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5576 | if libfooShared.NotAvailableForPlatform() != true { |
| 5577 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 5578 | } |
| 5579 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 5580 | if libfooStatic.NotAvailableForPlatform() != false { |
| 5581 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 5582 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5583 | } |
| 5584 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5585 | func TestOverrideApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5586 | ctx := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5587 | apex { |
| 5588 | name: "myapex", |
| 5589 | key: "myapex.key", |
| 5590 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5591 | overrides: ["oldapex"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5592 | updatable: false, |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | override_apex { |
| 5596 | name: "override_myapex", |
| 5597 | base: "myapex", |
| 5598 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5599 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5600 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5601 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | apex_key { |
| 5605 | name: "myapex.key", |
| 5606 | public_key: "testkey.avbpubkey", |
| 5607 | private_key: "testkey.pem", |
| 5608 | } |
| 5609 | |
| 5610 | android_app { |
| 5611 | name: "app", |
| 5612 | srcs: ["foo/bar/MyClass.java"], |
| 5613 | package_name: "foo", |
| 5614 | sdk_version: "none", |
| 5615 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5616 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | override_android_app { |
| 5620 | name: "override_app", |
| 5621 | base: "app", |
| 5622 | package_name: "bar", |
| 5623 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5624 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5625 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 5626 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 5627 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 5628 | if originalVariant.GetOverriddenBy() != "" { |
| 5629 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 5630 | } |
| 5631 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 5632 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 5633 | } |
| 5634 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5635 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 5636 | apexRule := module.Rule("apexRule") |
| 5637 | copyCmds := apexRule.Args["copy_commands"] |
| 5638 | |
| 5639 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5640 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5641 | |
| 5642 | apexBundle := module.Module().(*apexBundle) |
| 5643 | name := apexBundle.Name() |
| 5644 | if name != "override_myapex" { |
| 5645 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 5646 | } |
| 5647 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5648 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 5649 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 5650 | } |
| 5651 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5652 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5653 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5654 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5655 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5656 | var builder strings.Builder |
| 5657 | data.Custom(&builder, name, "TARGET_", "", data) |
| 5658 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5659 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5660 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 5661 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5662 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5663 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5664 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5665 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 5666 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5667 | } |
| 5668 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5669 | func TestLegacyAndroid10Support(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5670 | ctx := testApex(t, ` |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5671 | apex { |
| 5672 | name: "myapex", |
| 5673 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5674 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 5675 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5676 | } |
| 5677 | |
| 5678 | apex_key { |
| 5679 | name: "myapex.key", |
| 5680 | public_key: "testkey.avbpubkey", |
| 5681 | private_key: "testkey.pem", |
| 5682 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5683 | |
| 5684 | cc_library { |
| 5685 | name: "mylib", |
| 5686 | srcs: ["mylib.cpp"], |
| 5687 | stl: "libc++", |
| 5688 | system_shared_libs: [], |
| 5689 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5690 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5691 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5692 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5693 | |
| 5694 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5695 | args := module.Rule("apexRule").Args |
| 5696 | 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] | 5697 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5698 | |
| 5699 | // The copies of the libraries in the apex should have one more dependency than |
| 5700 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 5701 | // the dependency names directly here but for some reason the names are blank in |
| 5702 | // this test. |
| 5703 | for _, lib := range []string{"libc++", "mylib"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5704 | apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_apex29").Rule("ld").Implicits |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5705 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 5706 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 5707 | t.Errorf("%q missing unwinder dep", lib) |
| 5708 | } |
| 5709 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5710 | } |
| 5711 | |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 5712 | var filesForSdkLibrary = android.MockFS{ |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5713 | "api/current.txt": nil, |
| 5714 | "api/removed.txt": nil, |
| 5715 | "api/system-current.txt": nil, |
| 5716 | "api/system-removed.txt": nil, |
| 5717 | "api/test-current.txt": nil, |
| 5718 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5719 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5720 | "100/public/api/foo.txt": nil, |
| 5721 | "100/public/api/foo-removed.txt": nil, |
| 5722 | "100/system/api/foo.txt": nil, |
| 5723 | "100/system/api/foo-removed.txt": nil, |
| 5724 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5725 | // For java_sdk_library_import |
| 5726 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5727 | } |
| 5728 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5729 | func TestJavaSDKLibrary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5730 | ctx := testApex(t, ` |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5731 | apex { |
| 5732 | name: "myapex", |
| 5733 | key: "myapex.key", |
| 5734 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5735 | updatable: false, |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5736 | } |
| 5737 | |
| 5738 | apex_key { |
| 5739 | name: "myapex.key", |
| 5740 | public_key: "testkey.avbpubkey", |
| 5741 | private_key: "testkey.pem", |
| 5742 | } |
| 5743 | |
| 5744 | java_sdk_library { |
| 5745 | name: "foo", |
| 5746 | srcs: ["a.java"], |
| 5747 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5748 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5749 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5750 | |
| 5751 | prebuilt_apis { |
| 5752 | name: "sdk", |
| 5753 | api_dirs: ["100"], |
| 5754 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5755 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5756 | |
| 5757 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5758 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5759 | "javalib/foo.jar", |
| 5760 | "etc/permissions/foo.xml", |
| 5761 | }) |
| 5762 | // 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] | 5763 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 5764 | 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] | 5765 | } |
| 5766 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5767 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5768 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5769 | apex { |
| 5770 | name: "myapex", |
| 5771 | key: "myapex.key", |
| 5772 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5773 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5774 | } |
| 5775 | |
| 5776 | apex_key { |
| 5777 | name: "myapex.key", |
| 5778 | public_key: "testkey.avbpubkey", |
| 5779 | private_key: "testkey.pem", |
| 5780 | } |
| 5781 | |
| 5782 | java_sdk_library { |
| 5783 | name: "foo", |
| 5784 | srcs: ["a.java"], |
| 5785 | api_packages: ["foo"], |
| 5786 | apex_available: ["myapex"], |
| 5787 | sdk_version: "none", |
| 5788 | system_modules: "none", |
| 5789 | } |
| 5790 | |
| 5791 | java_library { |
| 5792 | name: "bar", |
| 5793 | srcs: ["a.java"], |
| 5794 | libs: ["foo"], |
| 5795 | apex_available: ["myapex"], |
| 5796 | sdk_version: "none", |
| 5797 | system_modules: "none", |
| 5798 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5799 | |
| 5800 | prebuilt_apis { |
| 5801 | name: "sdk", |
| 5802 | api_dirs: ["100"], |
| 5803 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5804 | `, withFiles(filesForSdkLibrary)) |
| 5805 | |
| 5806 | // java_sdk_library installs both impl jar and permission XML |
| 5807 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5808 | "javalib/bar.jar", |
| 5809 | "javalib/foo.jar", |
| 5810 | "etc/permissions/foo.xml", |
| 5811 | }) |
| 5812 | |
| 5813 | // The bar library should depend on the implementation jar. |
| 5814 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 5815 | if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5816 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5817 | } |
| 5818 | } |
| 5819 | |
| 5820 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5821 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5822 | apex { |
| 5823 | name: "myapex", |
| 5824 | key: "myapex.key", |
| 5825 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5826 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5827 | } |
| 5828 | |
| 5829 | apex_key { |
| 5830 | name: "myapex.key", |
| 5831 | public_key: "testkey.avbpubkey", |
| 5832 | private_key: "testkey.pem", |
| 5833 | } |
| 5834 | |
| 5835 | java_sdk_library { |
| 5836 | name: "foo", |
| 5837 | srcs: ["a.java"], |
| 5838 | api_packages: ["foo"], |
| 5839 | apex_available: ["myapex"], |
| 5840 | sdk_version: "none", |
| 5841 | system_modules: "none", |
| 5842 | } |
| 5843 | |
| 5844 | java_library { |
| 5845 | name: "bar", |
| 5846 | srcs: ["a.java"], |
| 5847 | libs: ["foo"], |
| 5848 | sdk_version: "none", |
| 5849 | system_modules: "none", |
| 5850 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5851 | |
| 5852 | prebuilt_apis { |
| 5853 | name: "sdk", |
| 5854 | api_dirs: ["100"], |
| 5855 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5856 | `, withFiles(filesForSdkLibrary)) |
| 5857 | |
| 5858 | // java_sdk_library installs both impl jar and permission XML |
| 5859 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5860 | "javalib/foo.jar", |
| 5861 | "etc/permissions/foo.xml", |
| 5862 | }) |
| 5863 | |
| 5864 | // The bar library should depend on the stubs jar. |
| 5865 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 5866 | if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5867 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5868 | } |
| 5869 | } |
| 5870 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5871 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5872 | ctx := testApex(t, ` |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5873 | prebuilt_apis { |
| 5874 | name: "sdk", |
| 5875 | api_dirs: ["100"], |
| 5876 | }`, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5877 | withFiles(map[string][]byte{ |
| 5878 | "apex/a.java": nil, |
| 5879 | "apex/apex_manifest.json": nil, |
| 5880 | "apex/Android.bp": []byte(` |
| 5881 | package { |
| 5882 | default_visibility: ["//visibility:private"], |
| 5883 | } |
| 5884 | |
| 5885 | apex { |
| 5886 | name: "myapex", |
| 5887 | key: "myapex.key", |
| 5888 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5889 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5890 | } |
| 5891 | |
| 5892 | apex_key { |
| 5893 | name: "myapex.key", |
| 5894 | public_key: "testkey.avbpubkey", |
| 5895 | private_key: "testkey.pem", |
| 5896 | } |
| 5897 | |
| 5898 | java_library { |
| 5899 | name: "bar", |
| 5900 | srcs: ["a.java"], |
| 5901 | libs: ["foo"], |
| 5902 | apex_available: ["myapex"], |
| 5903 | sdk_version: "none", |
| 5904 | system_modules: "none", |
| 5905 | } |
| 5906 | `), |
| 5907 | "source/a.java": nil, |
| 5908 | "source/api/current.txt": nil, |
| 5909 | "source/api/removed.txt": nil, |
| 5910 | "source/Android.bp": []byte(` |
| 5911 | package { |
| 5912 | default_visibility: ["//visibility:private"], |
| 5913 | } |
| 5914 | |
| 5915 | java_sdk_library { |
| 5916 | name: "foo", |
| 5917 | visibility: ["//apex"], |
| 5918 | srcs: ["a.java"], |
| 5919 | api_packages: ["foo"], |
| 5920 | apex_available: ["myapex"], |
| 5921 | sdk_version: "none", |
| 5922 | system_modules: "none", |
| 5923 | public: { |
| 5924 | enabled: true, |
| 5925 | }, |
| 5926 | } |
| 5927 | `), |
| 5928 | "prebuilt/a.jar": nil, |
| 5929 | "prebuilt/Android.bp": []byte(` |
| 5930 | package { |
| 5931 | default_visibility: ["//visibility:private"], |
| 5932 | } |
| 5933 | |
| 5934 | java_sdk_library_import { |
| 5935 | name: "foo", |
| 5936 | visibility: ["//apex", "//source"], |
| 5937 | apex_available: ["myapex"], |
| 5938 | prefer: true, |
| 5939 | public: { |
| 5940 | jars: ["a.jar"], |
| 5941 | }, |
| 5942 | } |
| 5943 | `), |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5944 | }), withFiles(filesForSdkLibrary), |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5945 | ) |
| 5946 | |
| 5947 | // java_sdk_library installs both impl jar and permission XML |
| 5948 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5949 | "javalib/bar.jar", |
| 5950 | "javalib/foo.jar", |
| 5951 | "etc/permissions/foo.xml", |
| 5952 | }) |
| 5953 | |
| 5954 | // The bar library should depend on the implementation jar. |
| 5955 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 5956 | if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.impl\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5957 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5958 | } |
| 5959 | } |
| 5960 | |
| 5961 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 5962 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 5963 | apex { |
| 5964 | name: "myapex", |
| 5965 | key: "myapex.key", |
| 5966 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5967 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5968 | } |
| 5969 | |
| 5970 | apex_key { |
| 5971 | name: "myapex.key", |
| 5972 | public_key: "testkey.avbpubkey", |
| 5973 | private_key: "testkey.pem", |
| 5974 | } |
| 5975 | |
| 5976 | java_sdk_library_import { |
| 5977 | name: "foo", |
| 5978 | apex_available: ["myapex"], |
| 5979 | prefer: true, |
| 5980 | public: { |
| 5981 | jars: ["a.jar"], |
| 5982 | }, |
| 5983 | } |
| 5984 | |
| 5985 | `, withFiles(filesForSdkLibrary)) |
| 5986 | } |
| 5987 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5988 | func TestCompatConfig(t *testing.T) { |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 5989 | result := android.GroupFixturePreparers( |
| 5990 | prepareForApexTest, |
| 5991 | java.PrepareForTestWithPlatformCompatConfig, |
| 5992 | ).RunTestWithBp(t, ` |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5993 | apex { |
| 5994 | name: "myapex", |
| 5995 | key: "myapex.key", |
Paul Duffin | 3abc174 | 2021-03-15 19:32:23 +0000 | [diff] [blame] | 5996 | compat_configs: ["myjar-platform-compat-config"], |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5997 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5998 | updatable: false, |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5999 | } |
| 6000 | |
| 6001 | apex_key { |
| 6002 | name: "myapex.key", |
| 6003 | public_key: "testkey.avbpubkey", |
| 6004 | private_key: "testkey.pem", |
| 6005 | } |
| 6006 | |
| 6007 | platform_compat_config { |
| 6008 | name: "myjar-platform-compat-config", |
| 6009 | src: ":myjar", |
| 6010 | } |
| 6011 | |
| 6012 | java_library { |
| 6013 | name: "myjar", |
| 6014 | srcs: ["foo/bar/MyClass.java"], |
| 6015 | sdk_version: "none", |
| 6016 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6017 | apex_available: [ "myapex" ], |
| 6018 | } |
Paul Duffin | 1b29e00 | 2021-03-16 15:06:54 +0000 | [diff] [blame] | 6019 | |
| 6020 | // Make sure that a preferred prebuilt does not affect the apex contents. |
| 6021 | prebuilt_platform_compat_config { |
| 6022 | name: "myjar-platform-compat-config", |
| 6023 | metadata: "compat-config/metadata.xml", |
| 6024 | prefer: true, |
| 6025 | } |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6026 | `) |
Paul Duffin | a369c7b | 2021-03-09 03:08:05 +0000 | [diff] [blame] | 6027 | ctx := result.TestContext |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6028 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6029 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 6030 | "javalib/myjar.jar", |
| 6031 | }) |
| 6032 | } |
| 6033 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6034 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 6035 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 6036 | apex { |
| 6037 | name: "myapex", |
| 6038 | key: "myapex.key", |
| 6039 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6040 | updatable: false, |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6041 | } |
| 6042 | |
| 6043 | apex_key { |
| 6044 | name: "myapex.key", |
| 6045 | public_key: "testkey.avbpubkey", |
| 6046 | private_key: "testkey.pem", |
| 6047 | } |
| 6048 | |
| 6049 | java_library { |
| 6050 | name: "myjar", |
| 6051 | srcs: ["foo/bar/MyClass.java"], |
| 6052 | sdk_version: "none", |
| 6053 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 6054 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 6055 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6056 | } |
| 6057 | `) |
| 6058 | } |
| 6059 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6060 | func TestCarryRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6061 | ctx := testApex(t, ` |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6062 | apex { |
| 6063 | name: "myapex", |
| 6064 | key: "myapex.key", |
| 6065 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6066 | updatable: false, |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6067 | } |
| 6068 | |
| 6069 | apex_key { |
| 6070 | name: "myapex.key", |
| 6071 | public_key: "testkey.avbpubkey", |
| 6072 | private_key: "testkey.pem", |
| 6073 | } |
| 6074 | |
| 6075 | cc_library { |
| 6076 | name: "mylib", |
| 6077 | srcs: ["mylib.cpp"], |
| 6078 | system_shared_libs: [], |
| 6079 | stl: "none", |
| 6080 | required: ["a", "b"], |
| 6081 | host_required: ["c", "d"], |
| 6082 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6083 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6084 | } |
| 6085 | `) |
| 6086 | |
| 6087 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6088 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6089 | name := apexBundle.BaseModuleName() |
| 6090 | prefix := "TARGET_" |
| 6091 | var builder strings.Builder |
| 6092 | data.Custom(&builder, name, prefix, "", data) |
| 6093 | androidMk := builder.String() |
| 6094 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 6095 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 6096 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 6097 | } |
| 6098 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6099 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 6100 | bp := ` |
| 6101 | apex { |
| 6102 | name: "myapex", |
| 6103 | key: "myapex.key", |
| 6104 | native_shared_libs: ["mylib"], |
| 6105 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6106 | updatable: false, |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6107 | } |
| 6108 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6109 | apex { |
| 6110 | name: "myapex.updatable", |
| 6111 | key: "myapex.key", |
| 6112 | native_shared_libs: ["mylib"], |
| 6113 | java_libs: ["myjar"], |
| 6114 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6115 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6116 | } |
| 6117 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6118 | apex_key { |
| 6119 | name: "myapex.key", |
| 6120 | public_key: "testkey.avbpubkey", |
| 6121 | private_key: "testkey.pem", |
| 6122 | } |
| 6123 | |
| 6124 | cc_library { |
| 6125 | name: "mylib", |
| 6126 | srcs: ["mylib.cpp"], |
| 6127 | shared_libs: ["myotherlib"], |
| 6128 | system_shared_libs: [], |
| 6129 | stl: "none", |
| 6130 | apex_available: [ |
| 6131 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6132 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6133 | "//apex_available:platform", |
| 6134 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6135 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6136 | } |
| 6137 | |
| 6138 | cc_library { |
| 6139 | name: "myotherlib", |
| 6140 | srcs: ["mylib.cpp"], |
| 6141 | system_shared_libs: [], |
| 6142 | stl: "none", |
| 6143 | apex_available: [ |
| 6144 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6145 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6146 | "//apex_available:platform", |
| 6147 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6148 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6149 | } |
| 6150 | |
| 6151 | java_library { |
| 6152 | name: "myjar", |
| 6153 | srcs: ["foo/bar/MyClass.java"], |
| 6154 | sdk_version: "none", |
| 6155 | system_modules: "none", |
| 6156 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6157 | apex_available: [ |
| 6158 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6159 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6160 | "//apex_available:platform", |
| 6161 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6162 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6163 | } |
| 6164 | |
| 6165 | java_library { |
| 6166 | name: "myotherjar", |
| 6167 | srcs: ["foo/bar/MyClass.java"], |
| 6168 | sdk_version: "none", |
| 6169 | system_modules: "none", |
| 6170 | apex_available: [ |
| 6171 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6172 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6173 | "//apex_available:platform", |
| 6174 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6175 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6176 | } |
| 6177 | ` |
| 6178 | |
| 6179 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 6180 | for _, f := range files { |
| 6181 | if f.path == file { |
| 6182 | if f.isLink { |
| 6183 | t.Errorf("%q is not a real file", file) |
| 6184 | } |
| 6185 | return |
| 6186 | } |
| 6187 | } |
| 6188 | t.Errorf("%q is not found", file) |
| 6189 | } |
| 6190 | |
| 6191 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 6192 | for _, f := range files { |
| 6193 | if f.path == file { |
| 6194 | if !f.isLink { |
| 6195 | t.Errorf("%q is not a symlink", file) |
| 6196 | } |
| 6197 | return |
| 6198 | } |
| 6199 | } |
| 6200 | t.Errorf("%q is not found", file) |
| 6201 | } |
| 6202 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6203 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 6204 | // is updatable or not |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6205 | ctx := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6206 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6207 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6208 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6209 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6210 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6211 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6212 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6213 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6214 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6215 | |
| 6216 | // For bundled build, symlink to the system for the non-updatable APEXes only |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6217 | ctx = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6218 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6219 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6220 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6221 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6222 | |
| 6223 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6224 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6225 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6226 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6227 | } |
| 6228 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6229 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6230 | ctx := testApex(t, ` |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6231 | apex { |
| 6232 | name: "myapex", |
| 6233 | key: "myapex.key", |
| 6234 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6235 | updatable: false, |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6236 | } |
| 6237 | |
| 6238 | apex_key { |
| 6239 | name: "myapex.key", |
| 6240 | public_key: "testkey.avbpubkey", |
| 6241 | private_key: "testkey.pem", |
| 6242 | } |
| 6243 | |
| 6244 | cc_library_shared { |
| 6245 | name: "mylib", |
| 6246 | srcs: ["mylib.cpp"], |
| 6247 | shared_libs: ["myotherlib"], |
| 6248 | system_shared_libs: [], |
| 6249 | stl: "none", |
| 6250 | apex_available: [ |
| 6251 | "myapex", |
| 6252 | "//apex_available:platform", |
| 6253 | ], |
| 6254 | } |
| 6255 | |
| 6256 | cc_prebuilt_library_shared { |
| 6257 | name: "myotherlib", |
| 6258 | srcs: ["prebuilt.so"], |
| 6259 | system_shared_libs: [], |
| 6260 | stl: "none", |
| 6261 | apex_available: [ |
| 6262 | "myapex", |
| 6263 | "//apex_available:platform", |
| 6264 | ], |
| 6265 | } |
| 6266 | `) |
| 6267 | |
| 6268 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6269 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6270 | var builder strings.Builder |
| 6271 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 6272 | androidMk := builder.String() |
| 6273 | // `myotherlib` is added to `myapex` as symlink |
| 6274 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 6275 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 6276 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 6277 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 6278 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += mylib.myapex:64 myotherlib:64 apex_manifest.pb.myapex apex_pubkey.myapex\n") |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6279 | } |
| 6280 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6281 | func TestApexWithJniLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6282 | ctx := testApex(t, ` |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6283 | apex { |
| 6284 | name: "myapex", |
| 6285 | key: "myapex.key", |
| 6286 | jni_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6287 | updatable: false, |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6288 | } |
| 6289 | |
| 6290 | apex_key { |
| 6291 | name: "myapex.key", |
| 6292 | public_key: "testkey.avbpubkey", |
| 6293 | private_key: "testkey.pem", |
| 6294 | } |
| 6295 | |
| 6296 | cc_library { |
| 6297 | name: "mylib", |
| 6298 | srcs: ["mylib.cpp"], |
| 6299 | shared_libs: ["mylib2"], |
| 6300 | system_shared_libs: [], |
| 6301 | stl: "none", |
| 6302 | apex_available: [ "myapex" ], |
| 6303 | } |
| 6304 | |
| 6305 | cc_library { |
| 6306 | name: "mylib2", |
| 6307 | srcs: ["mylib.cpp"], |
| 6308 | system_shared_libs: [], |
| 6309 | stl: "none", |
| 6310 | apex_available: [ "myapex" ], |
| 6311 | } |
| 6312 | `) |
| 6313 | |
| 6314 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 6315 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 6316 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 6317 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6318 | "lib64/mylib.so", |
| 6319 | "lib64/mylib2.so", |
| 6320 | }) |
| 6321 | } |
| 6322 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6323 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6324 | ctx := testApex(t, ` |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6325 | apex { |
| 6326 | name: "myapex", |
| 6327 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6328 | updatable: false, |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6329 | } |
| 6330 | apex_key { |
| 6331 | name: "myapex.key", |
| 6332 | public_key: "testkey.avbpubkey", |
| 6333 | private_key: "testkey.pem", |
| 6334 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 6335 | `, |
| 6336 | android.FixtureModifyConfig(func(config android.Config) { |
| 6337 | delete(config.Targets, android.Android) |
| 6338 | config.AndroidCommonTarget = android.Target{} |
| 6339 | }), |
| 6340 | ) |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6341 | |
| 6342 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 6343 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 6344 | } |
| 6345 | } |
| 6346 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6347 | func TestAppBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6348 | ctx := testApex(t, ` |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6349 | apex { |
| 6350 | name: "myapex", |
| 6351 | key: "myapex.key", |
| 6352 | apps: ["AppFoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6353 | updatable: false, |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6354 | } |
| 6355 | |
| 6356 | apex_key { |
| 6357 | name: "myapex.key", |
| 6358 | public_key: "testkey.avbpubkey", |
| 6359 | private_key: "testkey.pem", |
| 6360 | } |
| 6361 | |
| 6362 | android_app { |
| 6363 | name: "AppFoo", |
| 6364 | srcs: ["foo/bar/MyClass.java"], |
| 6365 | sdk_version: "none", |
| 6366 | system_modules: "none", |
| 6367 | apex_available: [ "myapex" ], |
| 6368 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6369 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6370 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6371 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json") |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6372 | content := bundleConfigRule.Args["content"] |
| 6373 | |
| 6374 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6375 | ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6376 | } |
| 6377 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6378 | func TestAppSetBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6379 | ctx := testApex(t, ` |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6380 | apex { |
| 6381 | name: "myapex", |
| 6382 | key: "myapex.key", |
| 6383 | apps: ["AppSet"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6384 | updatable: false, |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6385 | } |
| 6386 | |
| 6387 | apex_key { |
| 6388 | name: "myapex.key", |
| 6389 | public_key: "testkey.avbpubkey", |
| 6390 | private_key: "testkey.pem", |
| 6391 | } |
| 6392 | |
| 6393 | android_app_set { |
| 6394 | name: "AppSet", |
| 6395 | set: "AppSet.apks", |
| 6396 | }`) |
| 6397 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6398 | bundleConfigRule := mod.Output("bundle_config.json") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6399 | content := bundleConfigRule.Args["content"] |
| 6400 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 6401 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 6402 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 6403 | if len(copyCmds) != 3 { |
| 6404 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 6405 | } |
| 6406 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 6407 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 6408 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 6409 | } |
| 6410 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6411 | func TestAppSetBundlePrebuilt(t *testing.T) { |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6412 | bp := ` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6413 | apex_set { |
| 6414 | name: "myapex", |
| 6415 | filename: "foo_v2.apex", |
| 6416 | sanitized: { |
| 6417 | none: { set: "myapex.apks", }, |
| 6418 | hwaddress: { set: "myapex.hwasan.apks", }, |
| 6419 | }, |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6420 | } |
| 6421 | ` |
| 6422 | ctx := testApex(t, bp, prepareForTestWithSantitizeHwaddress) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6423 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6424 | // Check that the extractor produces the correct output file from the correct input file. |
| 6425 | extractorOutput := "out/soong/.intermediates/myapex.apex.extractor/android_common/extracted/myapex.hwasan.apks" |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6426 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6427 | m := ctx.ModuleForTests("myapex.apex.extractor", "android_common") |
| 6428 | extractedApex := m.Output(extractorOutput) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6429 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6430 | android.AssertArrayString(t, "extractor input", []string{"myapex.hwasan.apks"}, extractedApex.Inputs.Strings()) |
| 6431 | |
| 6432 | // Ditto for the apex. |
| 6433 | m = ctx.ModuleForTests("myapex", "android_common") |
| 6434 | copiedApex := m.Output("out/soong/.intermediates/myapex/android_common/foo_v2.apex") |
| 6435 | |
| 6436 | android.AssertStringEquals(t, "myapex input", extractorOutput, copiedApex.Input.String()) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6437 | } |
| 6438 | |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6439 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, preparer android.FixturePreparer) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6440 | t.Helper() |
| 6441 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6442 | bp := ` |
| 6443 | java_library { |
| 6444 | name: "some-updatable-apex-lib", |
| 6445 | srcs: ["a.java"], |
| 6446 | sdk_version: "current", |
| 6447 | apex_available: [ |
| 6448 | "some-updatable-apex", |
| 6449 | ], |
| 6450 | } |
| 6451 | |
| 6452 | java_library { |
| 6453 | name: "some-non-updatable-apex-lib", |
| 6454 | srcs: ["a.java"], |
| 6455 | apex_available: [ |
| 6456 | "some-non-updatable-apex", |
| 6457 | ], |
| 6458 | } |
| 6459 | |
| 6460 | java_library { |
| 6461 | name: "some-platform-lib", |
| 6462 | srcs: ["a.java"], |
| 6463 | sdk_version: "current", |
| 6464 | installable: true, |
| 6465 | } |
| 6466 | |
| 6467 | java_library { |
| 6468 | name: "some-art-lib", |
| 6469 | srcs: ["a.java"], |
| 6470 | sdk_version: "current", |
| 6471 | apex_available: [ |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6472 | "com.android.art.debug", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6473 | ], |
| 6474 | hostdex: true, |
| 6475 | } |
| 6476 | |
| 6477 | apex { |
| 6478 | name: "some-updatable-apex", |
| 6479 | key: "some-updatable-apex.key", |
| 6480 | java_libs: ["some-updatable-apex-lib"], |
| 6481 | updatable: true, |
| 6482 | min_sdk_version: "current", |
| 6483 | } |
| 6484 | |
| 6485 | apex { |
| 6486 | name: "some-non-updatable-apex", |
| 6487 | key: "some-non-updatable-apex.key", |
| 6488 | java_libs: ["some-non-updatable-apex-lib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6489 | updatable: false, |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | apex_key { |
| 6493 | name: "some-updatable-apex.key", |
| 6494 | } |
| 6495 | |
| 6496 | apex_key { |
| 6497 | name: "some-non-updatable-apex.key", |
| 6498 | } |
| 6499 | |
| 6500 | apex { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6501 | name: "com.android.art.debug", |
| 6502 | key: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6503 | java_libs: ["some-art-lib"], |
| 6504 | updatable: true, |
| 6505 | min_sdk_version: "current", |
| 6506 | } |
| 6507 | |
| 6508 | apex_key { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6509 | name: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6510 | } |
| 6511 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6512 | filegroup { |
| 6513 | name: "some-updatable-apex-file_contexts", |
| 6514 | srcs: [ |
| 6515 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 6516 | ], |
| 6517 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6518 | |
| 6519 | filegroup { |
| 6520 | name: "some-non-updatable-apex-file_contexts", |
| 6521 | srcs: [ |
| 6522 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 6523 | ], |
| 6524 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6525 | ` |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 6526 | |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6527 | testDexpreoptWithApexes(t, bp, errmsg, preparer) |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 6528 | } |
| 6529 | |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6530 | func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, preparer android.FixturePreparer) *android.TestContext { |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 6531 | t.Helper() |
| 6532 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 6533 | fs := android.MockFS{ |
| 6534 | "a.java": nil, |
| 6535 | "a.jar": nil, |
| 6536 | "apex_manifest.json": nil, |
| 6537 | "AndroidManifest.xml": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 6538 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6539 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
| 6540 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
| 6541 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 6542 | "framework/aidl/a.aidl": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6543 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6544 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 6545 | errorHandler := android.FixtureExpectsNoErrors |
| 6546 | if errmsg != "" { |
| 6547 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6548 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6549 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 6550 | result := android.GroupFixturePreparers( |
| 6551 | cc.PrepareForTestWithCcDefaultModules, |
| 6552 | java.PrepareForTestWithHiddenApiBuildComponents, |
| 6553 | java.PrepareForTestWithJavaDefaultModules, |
| 6554 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 6555 | PrepareForTestWithApexBuildComponents, |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6556 | preparer, |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 6557 | fs.AddToFixture(), |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 6558 | android.FixtureAddTextFile("frameworks/base/boot/Android.bp", ` |
| 6559 | platform_bootclasspath { |
| 6560 | name: "platform-bootclasspath", |
| 6561 | } |
| 6562 | `), |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 6563 | ). |
| 6564 | ExtendWithErrorHandler(errorHandler). |
| 6565 | RunTestWithBp(t, bp) |
| 6566 | |
| 6567 | return result.TestContext |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6568 | } |
| 6569 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6570 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 6571 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 6572 | apex { |
| 6573 | name: "myapex", |
| 6574 | key: "myapex.key", |
| 6575 | updatable: true, |
| 6576 | } |
| 6577 | |
| 6578 | apex_key { |
| 6579 | name: "myapex.key", |
| 6580 | public_key: "testkey.avbpubkey", |
| 6581 | private_key: "testkey.pem", |
| 6582 | } |
| 6583 | `) |
| 6584 | } |
| 6585 | |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6586 | func TestUpdatableDefault_should_set_min_sdk_version(t *testing.T) { |
| 6587 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 6588 | apex { |
| 6589 | name: "myapex", |
| 6590 | key: "myapex.key", |
| 6591 | } |
| 6592 | |
| 6593 | apex_key { |
| 6594 | name: "myapex.key", |
| 6595 | public_key: "testkey.avbpubkey", |
| 6596 | private_key: "testkey.pem", |
| 6597 | } |
| 6598 | `) |
| 6599 | } |
| 6600 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6601 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6602 | // Set the BootJars in dexpreopt.GlobalConfig and productVariables to the same value. This can |
| 6603 | // result in an invalid configuration as it does not set the ArtApexJars and allows art apex |
| 6604 | // modules to be included in the BootJars. |
| 6605 | prepareSetBootJars := func(bootJars ...string) android.FixturePreparer { |
| 6606 | return android.GroupFixturePreparers( |
| 6607 | dexpreopt.FixtureSetBootJars(bootJars...), |
| 6608 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 6609 | variables.BootJars = android.CreateTestConfiguredJarList(bootJars) |
| 6610 | }), |
| 6611 | ) |
| 6612 | } |
| 6613 | |
| 6614 | // Set the ArtApexJars and BootJars in dexpreopt.GlobalConfig and productVariables all to the |
| 6615 | // same value. This can result in an invalid configuration as it allows non art apex jars to be |
| 6616 | // specified in the ArtApexJars configuration. |
| 6617 | prepareSetArtJars := func(bootJars ...string) android.FixturePreparer { |
| 6618 | return android.GroupFixturePreparers( |
| 6619 | dexpreopt.FixtureSetArtBootJars(bootJars...), |
| 6620 | dexpreopt.FixtureSetBootJars(bootJars...), |
| 6621 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 6622 | variables.BootJars = android.CreateTestConfiguredJarList(bootJars) |
| 6623 | }), |
| 6624 | ) |
| 6625 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6626 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6627 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6628 | preparer := java.FixtureConfigureBootJars("com.android.art.debug:some-art-lib") |
| 6629 | testNoUpdatableJarsInBootImage(t, "", preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6630 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6631 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6632 | t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6633 | err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image` |
| 6634 | // Update the dexpreopt BootJars directly. |
| 6635 | preparer := prepareSetBootJars("com.android.art.debug:some-art-lib") |
| 6636 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6637 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6638 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6639 | t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6640 | err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the ART boot image` |
| 6641 | // Update the dexpreopt ArtApexJars directly. |
| 6642 | preparer := prepareSetArtJars("some-updatable-apex:some-updatable-apex-lib") |
| 6643 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6644 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6645 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6646 | t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6647 | err := `module "some-non-updatable-apex-lib" is not allowed in the ART boot image` |
| 6648 | // Update the dexpreopt ArtApexJars directly. |
| 6649 | preparer := prepareSetArtJars("some-non-updatable-apex:some-non-updatable-apex-lib") |
| 6650 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6651 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6652 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6653 | t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6654 | err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image` |
| 6655 | preparer := java.FixtureConfigureBootJars("some-updatable-apex:some-updatable-apex-lib") |
| 6656 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6657 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6658 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6659 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6660 | preparer := java.FixtureConfigureBootJars("some-non-updatable-apex:some-non-updatable-apex-lib") |
| 6661 | testNoUpdatableJarsInBootImage(t, "", preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6662 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6663 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6664 | t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 6665 | err := `"platform-bootclasspath" depends on undefined module "nonexistent"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6666 | preparer := java.FixtureConfigureBootJars("platform:nonexistent") |
| 6667 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6668 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6669 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6670 | t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) { |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 6671 | err := `"platform-bootclasspath" depends on undefined module "nonexistent"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6672 | preparer := java.FixtureConfigureBootJars("platform:nonexistent") |
| 6673 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6674 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6675 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6676 | t.Run("platform jar in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6677 | err := `module "some-platform-lib" is not allowed in the ART boot image` |
| 6678 | // Update the dexpreopt ArtApexJars directly. |
| 6679 | preparer := prepareSetArtJars("platform:some-platform-lib") |
| 6680 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6681 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6682 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6683 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6684 | preparer := java.FixtureConfigureBootJars("platform:some-platform-lib") |
| 6685 | testNoUpdatableJarsInBootImage(t, "", preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6686 | }) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6687 | } |
| 6688 | |
| 6689 | func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6690 | preparer := java.FixtureConfigureBootJars("myapex:libfoo") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6691 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6692 | testDexpreoptWithApexes(t, ` |
| 6693 | prebuilt_apex { |
| 6694 | name: "myapex" , |
| 6695 | arch: { |
| 6696 | arm64: { |
| 6697 | src: "myapex-arm64.apex", |
| 6698 | }, |
| 6699 | arm: { |
| 6700 | src: "myapex-arm.apex", |
| 6701 | }, |
| 6702 | }, |
| 6703 | exported_java_libs: ["libfoo"], |
| 6704 | } |
| 6705 | |
| 6706 | java_import { |
| 6707 | name: "libfoo", |
| 6708 | jars: ["libfoo.jar"], |
| 6709 | } |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6710 | `, "", preparer) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6711 | }) |
| 6712 | |
| 6713 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6714 | testDexpreoptWithApexes(t, ` |
| 6715 | prebuilt_apex { |
| 6716 | name: "myapex" , |
| 6717 | arch: { |
| 6718 | arm64: { |
| 6719 | src: "myapex-arm64.apex", |
| 6720 | }, |
| 6721 | arm: { |
| 6722 | src: "myapex-arm.apex", |
| 6723 | }, |
| 6724 | }, |
| 6725 | exported_java_libs: ["libfoo"], |
| 6726 | } |
| 6727 | |
| 6728 | java_import { |
| 6729 | name: "libfoo", |
| 6730 | jars: ["libfoo.jar"], |
| 6731 | } |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 6732 | `, "", preparer) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6733 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6734 | } |
| 6735 | |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6736 | func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) { |
| 6737 | t.Helper() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6738 | bp += ` |
| 6739 | apex_key { |
| 6740 | name: "myapex.key", |
| 6741 | public_key: "testkey.avbpubkey", |
| 6742 | private_key: "testkey.pem", |
| 6743 | }` |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 6744 | fs := android.MockFS{ |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6745 | "lib1/src/A.java": nil, |
| 6746 | "lib2/src/B.java": nil, |
| 6747 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 6748 | } |
| 6749 | |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 6750 | errorHandler := android.FixtureExpectsNoErrors |
| 6751 | if errmsg != "" { |
| 6752 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6753 | } |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6754 | |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 6755 | android.GroupFixturePreparers( |
| 6756 | android.PrepareForTestWithAndroidBuildComponents, |
| 6757 | java.PrepareForTestWithJavaBuildComponents, |
| 6758 | PrepareForTestWithApexBuildComponents, |
| 6759 | android.PrepareForTestWithNeverallowRules(rules), |
| 6760 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 6761 | updatableBootJars := make([]string, 0, len(apexBootJars)) |
| 6762 | for _, apexBootJar := range apexBootJars { |
| 6763 | updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar) |
| 6764 | } |
| 6765 | variables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars) |
| 6766 | }), |
| 6767 | fs.AddToFixture(), |
| 6768 | ). |
| 6769 | ExtendWithErrorHandler(errorHandler). |
| 6770 | RunTestWithBp(t, bp) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6771 | } |
| 6772 | |
| 6773 | func TestApexPermittedPackagesRules(t *testing.T) { |
| 6774 | testcases := []struct { |
| 6775 | name string |
| 6776 | expectedError string |
| 6777 | bp string |
| 6778 | bootJars []string |
| 6779 | modulesPackages map[string][]string |
| 6780 | }{ |
| 6781 | |
| 6782 | { |
| 6783 | name: "Non-Bootclasspath apex jar not satisfying allowed module packages.", |
| 6784 | expectedError: "", |
| 6785 | bp: ` |
| 6786 | java_library { |
| 6787 | name: "bcp_lib1", |
| 6788 | srcs: ["lib1/src/*.java"], |
| 6789 | permitted_packages: ["foo.bar"], |
| 6790 | apex_available: ["myapex"], |
| 6791 | sdk_version: "none", |
| 6792 | system_modules: "none", |
| 6793 | } |
| 6794 | java_library { |
| 6795 | name: "nonbcp_lib2", |
| 6796 | srcs: ["lib2/src/*.java"], |
| 6797 | apex_available: ["myapex"], |
| 6798 | permitted_packages: ["a.b"], |
| 6799 | sdk_version: "none", |
| 6800 | system_modules: "none", |
| 6801 | } |
| 6802 | apex { |
| 6803 | name: "myapex", |
| 6804 | key: "myapex.key", |
| 6805 | java_libs: ["bcp_lib1", "nonbcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6806 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6807 | }`, |
| 6808 | bootJars: []string{"bcp_lib1"}, |
| 6809 | modulesPackages: map[string][]string{ |
| 6810 | "myapex": []string{ |
| 6811 | "foo.bar", |
| 6812 | }, |
| 6813 | }, |
| 6814 | }, |
| 6815 | { |
| 6816 | name: "Bootclasspath apex jar not satisfying allowed module packages.", |
| 6817 | expectedError: `module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar. Please jarjar or move code around.`, |
| 6818 | bp: ` |
| 6819 | java_library { |
| 6820 | name: "bcp_lib1", |
| 6821 | srcs: ["lib1/src/*.java"], |
| 6822 | apex_available: ["myapex"], |
| 6823 | permitted_packages: ["foo.bar"], |
| 6824 | sdk_version: "none", |
| 6825 | system_modules: "none", |
| 6826 | } |
| 6827 | java_library { |
| 6828 | name: "bcp_lib2", |
| 6829 | srcs: ["lib2/src/*.java"], |
| 6830 | apex_available: ["myapex"], |
| 6831 | permitted_packages: ["foo.bar", "bar.baz"], |
| 6832 | sdk_version: "none", |
| 6833 | system_modules: "none", |
| 6834 | } |
| 6835 | apex { |
| 6836 | name: "myapex", |
| 6837 | key: "myapex.key", |
| 6838 | java_libs: ["bcp_lib1", "bcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6839 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6840 | } |
| 6841 | `, |
| 6842 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
| 6843 | modulesPackages: map[string][]string{ |
| 6844 | "myapex": []string{ |
| 6845 | "foo.bar", |
| 6846 | }, |
| 6847 | }, |
| 6848 | }, |
| 6849 | } |
| 6850 | for _, tc := range testcases { |
| 6851 | t.Run(tc.name, func(t *testing.T) { |
| 6852 | rules := createApexPermittedPackagesRules(tc.modulesPackages) |
| 6853 | testApexPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules) |
| 6854 | }) |
| 6855 | } |
| 6856 | } |
| 6857 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6858 | func TestTestFor(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6859 | ctx := testApex(t, ` |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6860 | apex { |
| 6861 | name: "myapex", |
| 6862 | key: "myapex.key", |
| 6863 | native_shared_libs: ["mylib", "myprivlib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6864 | updatable: false, |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6865 | } |
| 6866 | |
| 6867 | apex_key { |
| 6868 | name: "myapex.key", |
| 6869 | public_key: "testkey.avbpubkey", |
| 6870 | private_key: "testkey.pem", |
| 6871 | } |
| 6872 | |
| 6873 | cc_library { |
| 6874 | name: "mylib", |
| 6875 | srcs: ["mylib.cpp"], |
| 6876 | system_shared_libs: [], |
| 6877 | stl: "none", |
| 6878 | stubs: { |
| 6879 | versions: ["1"], |
| 6880 | }, |
| 6881 | apex_available: ["myapex"], |
| 6882 | } |
| 6883 | |
| 6884 | cc_library { |
| 6885 | name: "myprivlib", |
| 6886 | srcs: ["mylib.cpp"], |
| 6887 | system_shared_libs: [], |
| 6888 | stl: "none", |
| 6889 | apex_available: ["myapex"], |
| 6890 | } |
| 6891 | |
| 6892 | |
| 6893 | cc_test { |
| 6894 | name: "mytest", |
| 6895 | gtest: false, |
| 6896 | srcs: ["mylib.cpp"], |
| 6897 | system_shared_libs: [], |
| 6898 | stl: "none", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6899 | shared_libs: ["mylib", "myprivlib", "mytestlib"], |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6900 | test_for: ["myapex"] |
| 6901 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6902 | |
| 6903 | cc_library { |
| 6904 | name: "mytestlib", |
| 6905 | srcs: ["mylib.cpp"], |
| 6906 | system_shared_libs: [], |
| 6907 | shared_libs: ["mylib", "myprivlib"], |
| 6908 | stl: "none", |
| 6909 | test_for: ["myapex"], |
| 6910 | } |
| 6911 | |
| 6912 | cc_benchmark { |
| 6913 | name: "mybench", |
| 6914 | srcs: ["mylib.cpp"], |
| 6915 | system_shared_libs: [], |
| 6916 | shared_libs: ["mylib", "myprivlib"], |
| 6917 | stl: "none", |
| 6918 | test_for: ["myapex"], |
| 6919 | } |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6920 | `) |
| 6921 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6922 | ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) { |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 6923 | ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ") |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6924 | mylibLdFlags := android.FilterListPred(ldFlags, func(s string) bool { return strings.HasPrefix(s, linkedLib) }) |
| 6925 | android.AssertArrayString(t, "unexpected "+linkedLib+" link library for "+mod, []string{linkedLib + expectedVariant}, mylibLdFlags) |
| 6926 | } |
| 6927 | |
| 6928 | // These modules are tests for the apex, therefore are linked to the |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6929 | // actual implementation of mylib instead of its stub. |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6930 | ensureLinkedLibIs("mytest", "android_arm64_armv8-a", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 6931 | ensureLinkedLibIs("mytestlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 6932 | ensureLinkedLibIs("mybench", "android_arm64_armv8-a", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 6933 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6934 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6935 | func TestIndirectTestFor(t *testing.T) { |
| 6936 | ctx := testApex(t, ` |
| 6937 | apex { |
| 6938 | name: "myapex", |
| 6939 | key: "myapex.key", |
| 6940 | native_shared_libs: ["mylib", "myprivlib"], |
| 6941 | updatable: false, |
| 6942 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6943 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6944 | apex_key { |
| 6945 | name: "myapex.key", |
| 6946 | public_key: "testkey.avbpubkey", |
| 6947 | private_key: "testkey.pem", |
| 6948 | } |
| 6949 | |
| 6950 | cc_library { |
| 6951 | name: "mylib", |
| 6952 | srcs: ["mylib.cpp"], |
| 6953 | system_shared_libs: [], |
| 6954 | stl: "none", |
| 6955 | stubs: { |
| 6956 | versions: ["1"], |
| 6957 | }, |
| 6958 | apex_available: ["myapex"], |
| 6959 | } |
| 6960 | |
| 6961 | cc_library { |
| 6962 | name: "myprivlib", |
| 6963 | srcs: ["mylib.cpp"], |
| 6964 | system_shared_libs: [], |
| 6965 | stl: "none", |
| 6966 | shared_libs: ["mylib"], |
| 6967 | apex_available: ["myapex"], |
| 6968 | } |
| 6969 | |
| 6970 | cc_library { |
| 6971 | name: "mytestlib", |
| 6972 | srcs: ["mylib.cpp"], |
| 6973 | system_shared_libs: [], |
| 6974 | shared_libs: ["myprivlib"], |
| 6975 | stl: "none", |
| 6976 | test_for: ["myapex"], |
| 6977 | } |
| 6978 | `) |
| 6979 | |
| 6980 | ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) { |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 6981 | ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ") |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6982 | mylibLdFlags := android.FilterListPred(ldFlags, func(s string) bool { return strings.HasPrefix(s, linkedLib) }) |
| 6983 | android.AssertArrayString(t, "unexpected "+linkedLib+" link library for "+mod, []string{linkedLib + expectedVariant}, mylibLdFlags) |
| 6984 | } |
| 6985 | |
| 6986 | // The platform variant of mytestlib links to the platform variant of the |
| 6987 | // internal myprivlib. |
| 6988 | ensureLinkedLibIs("mytestlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/myprivlib/", "android_arm64_armv8-a_shared/myprivlib.so") |
| 6989 | |
| 6990 | // The platform variant of myprivlib links to the platform variant of mylib |
| 6991 | // and bypasses its stubs. |
| 6992 | ensureLinkedLibIs("myprivlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6993 | } |
| 6994 | |
Martin Stjernholm | ec00900 | 2021-03-27 15:18:31 +0000 | [diff] [blame] | 6995 | func TestTestForForLibInOtherApex(t *testing.T) { |
| 6996 | // This case is only allowed for known overlapping APEXes, i.e. the ART APEXes. |
| 6997 | _ = testApex(t, ` |
| 6998 | apex { |
| 6999 | name: "com.android.art", |
| 7000 | key: "myapex.key", |
| 7001 | native_shared_libs: ["mylib"], |
| 7002 | updatable: false, |
| 7003 | } |
| 7004 | |
| 7005 | apex { |
| 7006 | name: "com.android.art.debug", |
| 7007 | key: "myapex.key", |
| 7008 | native_shared_libs: ["mylib", "mytestlib"], |
| 7009 | updatable: false, |
| 7010 | } |
| 7011 | |
| 7012 | apex_key { |
| 7013 | name: "myapex.key", |
| 7014 | public_key: "testkey.avbpubkey", |
| 7015 | private_key: "testkey.pem", |
| 7016 | } |
| 7017 | |
| 7018 | cc_library { |
| 7019 | name: "mylib", |
| 7020 | srcs: ["mylib.cpp"], |
| 7021 | system_shared_libs: [], |
| 7022 | stl: "none", |
| 7023 | stubs: { |
| 7024 | versions: ["1"], |
| 7025 | }, |
| 7026 | apex_available: ["com.android.art", "com.android.art.debug"], |
| 7027 | } |
| 7028 | |
| 7029 | cc_library { |
| 7030 | name: "mytestlib", |
| 7031 | srcs: ["mylib.cpp"], |
| 7032 | system_shared_libs: [], |
| 7033 | shared_libs: ["mylib"], |
| 7034 | stl: "none", |
| 7035 | apex_available: ["com.android.art.debug"], |
| 7036 | test_for: ["com.android.art"], |
| 7037 | } |
| 7038 | `, |
| 7039 | android.MockFS{ |
| 7040 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 7041 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
| 7042 | }.AddToFixture()) |
| 7043 | } |
| 7044 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7045 | // TODO(jungjw): Move this to proptools |
| 7046 | func intPtr(i int) *int { |
| 7047 | return &i |
| 7048 | } |
| 7049 | |
| 7050 | func TestApexSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7051 | ctx := testApex(t, ` |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7052 | apex_set { |
| 7053 | name: "myapex", |
| 7054 | set: "myapex.apks", |
| 7055 | filename: "foo_v2.apex", |
| 7056 | overrides: ["foo"], |
| 7057 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 7058 | `, |
| 7059 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7060 | variables.Platform_sdk_version = intPtr(30) |
| 7061 | }), |
| 7062 | android.FixtureModifyConfig(func(config android.Config) { |
| 7063 | config.Targets[android.Android] = []android.Target{ |
| 7064 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}}, |
| 7065 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}}, |
| 7066 | } |
| 7067 | }), |
| 7068 | ) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7069 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7070 | m := ctx.ModuleForTests("myapex.apex.extractor", "android_common") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7071 | |
| 7072 | // Check extract_apks tool parameters. |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7073 | extractedApex := m.Output("extracted/myapex.apks") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7074 | actual := extractedApex.Args["abis"] |
| 7075 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 7076 | if actual != expected { |
| 7077 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 7078 | } |
| 7079 | actual = extractedApex.Args["sdk-version"] |
| 7080 | expected = "30" |
| 7081 | if actual != expected { |
| 7082 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 7083 | } |
| 7084 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7085 | m = ctx.ModuleForTests("myapex", "android_common") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7086 | a := m.Module().(*ApexSet) |
| 7087 | expectedOverrides := []string{"foo"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7088 | actualOverrides := android.AndroidMkEntriesForTest(t, ctx, a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7089 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 7090 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 7091 | } |
| 7092 | } |
| 7093 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 7094 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 7095 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 7096 | apex { |
| 7097 | name: "myapex", |
| 7098 | key: "myapex.key", |
| 7099 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7100 | updatable: false, |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 7101 | } |
| 7102 | |
| 7103 | apex_key { |
| 7104 | name: "myapex.key", |
| 7105 | public_key: "testkey.avbpubkey", |
| 7106 | private_key: "testkey.pem", |
| 7107 | } |
| 7108 | |
| 7109 | cc_library { |
| 7110 | name: "mylib", |
| 7111 | srcs: ["mylib.cpp"], |
| 7112 | static_libs: ["otherlib"], |
| 7113 | system_shared_libs: [], |
| 7114 | stl: "none", |
| 7115 | apex_available: [ "myapex" ], |
| 7116 | } |
| 7117 | |
| 7118 | cc_library { |
| 7119 | name: "otherlib", |
| 7120 | srcs: ["mylib.cpp"], |
| 7121 | system_shared_libs: [], |
| 7122 | stl: "none", |
| 7123 | stubs: { |
| 7124 | versions: ["1", "2", "3"], |
| 7125 | }, |
| 7126 | apex_available: [ "myapex" ], |
| 7127 | } |
| 7128 | `) |
| 7129 | } |
| 7130 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 7131 | func TestApexKeysTxt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7132 | ctx := testApex(t, ` |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 7133 | apex { |
| 7134 | name: "myapex", |
| 7135 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7136 | updatable: false, |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 7137 | } |
| 7138 | |
| 7139 | apex_key { |
| 7140 | name: "myapex.key", |
| 7141 | public_key: "testkey.avbpubkey", |
| 7142 | private_key: "testkey.pem", |
| 7143 | } |
| 7144 | |
| 7145 | prebuilt_apex { |
| 7146 | name: "myapex", |
| 7147 | prefer: true, |
| 7148 | arch: { |
| 7149 | arm64: { |
| 7150 | src: "myapex-arm64.apex", |
| 7151 | }, |
| 7152 | arm: { |
| 7153 | src: "myapex-arm.apex", |
| 7154 | }, |
| 7155 | }, |
| 7156 | } |
| 7157 | |
| 7158 | apex_set { |
| 7159 | name: "myapex_set", |
| 7160 | set: "myapex.apks", |
| 7161 | filename: "myapex_set.apex", |
| 7162 | overrides: ["myapex"], |
| 7163 | } |
| 7164 | `) |
| 7165 | |
| 7166 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 7167 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 7168 | ensureContains(t, content, `name="myapex_set.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`) |
Jiyong Park | 03a7f3e | 2020-06-18 19:34:42 +0900 | [diff] [blame] | 7169 | ensureContains(t, content, `name="myapex.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`) |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 7170 | } |
| 7171 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 7172 | func TestAllowedFiles(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7173 | ctx := testApex(t, ` |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 7174 | apex { |
| 7175 | name: "myapex", |
| 7176 | key: "myapex.key", |
| 7177 | apps: ["app"], |
| 7178 | allowed_files: "allowed.txt", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7179 | updatable: false, |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 7180 | } |
| 7181 | |
| 7182 | apex_key { |
| 7183 | name: "myapex.key", |
| 7184 | public_key: "testkey.avbpubkey", |
| 7185 | private_key: "testkey.pem", |
| 7186 | } |
| 7187 | |
| 7188 | android_app { |
| 7189 | name: "app", |
| 7190 | srcs: ["foo/bar/MyClass.java"], |
| 7191 | package_name: "foo", |
| 7192 | sdk_version: "none", |
| 7193 | system_modules: "none", |
| 7194 | apex_available: [ "myapex" ], |
| 7195 | } |
| 7196 | `, withFiles(map[string][]byte{ |
| 7197 | "sub/Android.bp": []byte(` |
| 7198 | override_apex { |
| 7199 | name: "override_myapex", |
| 7200 | base: "myapex", |
| 7201 | apps: ["override_app"], |
| 7202 | allowed_files: ":allowed", |
| 7203 | } |
| 7204 | // Overridable "path" property should be referenced indirectly |
| 7205 | filegroup { |
| 7206 | name: "allowed", |
| 7207 | srcs: ["allowed.txt"], |
| 7208 | } |
| 7209 | override_android_app { |
| 7210 | name: "override_app", |
| 7211 | base: "app", |
| 7212 | package_name: "bar", |
| 7213 | } |
| 7214 | `), |
| 7215 | })) |
| 7216 | |
| 7217 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 7218 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 7219 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 7220 | } |
| 7221 | |
| 7222 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 7223 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 7224 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 7225 | } |
| 7226 | } |
| 7227 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7228 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7229 | testApex(t, ` |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7230 | apex { |
| 7231 | name: "myapex", |
| 7232 | key: "myapex.key", |
| 7233 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7234 | updatable: false, |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7235 | } |
| 7236 | |
| 7237 | apex_key { |
| 7238 | name: "myapex.key", |
| 7239 | public_key: "testkey.avbpubkey", |
| 7240 | private_key: "testkey.pem", |
| 7241 | } |
| 7242 | |
| 7243 | cc_library { |
| 7244 | name: "mylib", |
| 7245 | srcs: ["mylib.cpp"], |
| 7246 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 7247 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7248 | }, |
| 7249 | apex_available: ["myapex"], |
| 7250 | } |
| 7251 | |
| 7252 | cc_prebuilt_library_shared { |
| 7253 | name: "mylib", |
| 7254 | prefer: false, |
| 7255 | srcs: ["prebuilt.so"], |
| 7256 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 7257 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7258 | }, |
| 7259 | apex_available: ["myapex"], |
| 7260 | } |
| 7261 | `) |
| 7262 | } |
| 7263 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7264 | func TestCompressedApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7265 | ctx := testApex(t, ` |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7266 | apex { |
| 7267 | name: "myapex", |
| 7268 | key: "myapex.key", |
| 7269 | compressible: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7270 | updatable: false, |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7271 | } |
| 7272 | apex_key { |
| 7273 | name: "myapex.key", |
| 7274 | public_key: "testkey.avbpubkey", |
| 7275 | private_key: "testkey.pem", |
| 7276 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 7277 | `, |
| 7278 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7279 | variables.CompressedApex = proptools.BoolPtr(true) |
| 7280 | }), |
| 7281 | ) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7282 | |
| 7283 | compressRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("compressRule") |
| 7284 | ensureContains(t, compressRule.Output.String(), "myapex.capex.unsigned") |
| 7285 | |
| 7286 | signApkRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("sign compressedApex") |
| 7287 | ensureEquals(t, signApkRule.Input.String(), compressRule.Output.String()) |
| 7288 | |
| 7289 | // Make sure output of bundle is .capex |
| 7290 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 7291 | ensureContains(t, ab.outputFile.String(), "myapex.capex") |
| 7292 | |
| 7293 | // Verify android.mk rules |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7294 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7295 | var builder strings.Builder |
| 7296 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7297 | androidMk := builder.String() |
| 7298 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.capex\n") |
| 7299 | } |
| 7300 | |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7301 | func TestPreferredPrebuiltSharedLibDep(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7302 | ctx := testApex(t, ` |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7303 | apex { |
| 7304 | name: "myapex", |
| 7305 | key: "myapex.key", |
| 7306 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7307 | updatable: false, |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7308 | } |
| 7309 | |
| 7310 | apex_key { |
| 7311 | name: "myapex.key", |
| 7312 | public_key: "testkey.avbpubkey", |
| 7313 | private_key: "testkey.pem", |
| 7314 | } |
| 7315 | |
| 7316 | cc_library { |
| 7317 | name: "mylib", |
| 7318 | srcs: ["mylib.cpp"], |
| 7319 | apex_available: ["myapex"], |
| 7320 | shared_libs: ["otherlib"], |
| 7321 | system_shared_libs: [], |
| 7322 | } |
| 7323 | |
| 7324 | cc_library { |
| 7325 | name: "otherlib", |
| 7326 | srcs: ["mylib.cpp"], |
| 7327 | stubs: { |
| 7328 | versions: ["current"], |
| 7329 | }, |
| 7330 | } |
| 7331 | |
| 7332 | cc_prebuilt_library_shared { |
| 7333 | name: "otherlib", |
| 7334 | prefer: true, |
| 7335 | srcs: ["prebuilt.so"], |
| 7336 | stubs: { |
| 7337 | versions: ["current"], |
| 7338 | }, |
| 7339 | } |
| 7340 | `) |
| 7341 | |
| 7342 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7343 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7344 | var builder strings.Builder |
| 7345 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7346 | androidMk := builder.String() |
| 7347 | |
| 7348 | // The make level dependency needs to be on otherlib - prebuilt_otherlib isn't |
| 7349 | // a thing there. |
| 7350 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherlib\n") |
| 7351 | } |
| 7352 | |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7353 | func TestExcludeDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7354 | ctx := testApex(t, ` |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7355 | apex { |
| 7356 | name: "myapex", |
| 7357 | key: "myapex.key", |
| 7358 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7359 | updatable: false, |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7360 | } |
| 7361 | |
| 7362 | apex_key { |
| 7363 | name: "myapex.key", |
| 7364 | public_key: "testkey.avbpubkey", |
| 7365 | private_key: "testkey.pem", |
| 7366 | } |
| 7367 | |
| 7368 | cc_library { |
| 7369 | name: "mylib", |
| 7370 | srcs: ["mylib.cpp"], |
| 7371 | system_shared_libs: [], |
| 7372 | stl: "none", |
| 7373 | apex_available: ["myapex"], |
| 7374 | shared_libs: ["mylib2"], |
| 7375 | target: { |
| 7376 | apex: { |
| 7377 | exclude_shared_libs: ["mylib2"], |
| 7378 | }, |
| 7379 | }, |
| 7380 | } |
| 7381 | |
| 7382 | cc_library { |
| 7383 | name: "mylib2", |
| 7384 | srcs: ["mylib.cpp"], |
| 7385 | system_shared_libs: [], |
| 7386 | stl: "none", |
| 7387 | } |
| 7388 | `) |
| 7389 | |
| 7390 | // Check if mylib is linked to mylib2 for the non-apex target |
| 7391 | ldFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 7392 | ensureContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 7393 | |
| 7394 | // Make sure that the link doesn't occur for the apex target |
| 7395 | ldFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 7396 | ensureNotContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared_apex10000/mylib2.so") |
| 7397 | |
| 7398 | // It shouldn't appear in the copy cmd as well. |
| 7399 | copyCmds := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").Args["copy_commands"] |
| 7400 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 7401 | } |
| 7402 | |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7403 | func TestPrebuiltStubLibDep(t *testing.T) { |
| 7404 | bpBase := ` |
| 7405 | apex { |
| 7406 | name: "myapex", |
| 7407 | key: "myapex.key", |
| 7408 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7409 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7410 | } |
| 7411 | apex_key { |
| 7412 | name: "myapex.key", |
| 7413 | public_key: "testkey.avbpubkey", |
| 7414 | private_key: "testkey.pem", |
| 7415 | } |
| 7416 | cc_library { |
| 7417 | name: "mylib", |
| 7418 | srcs: ["mylib.cpp"], |
| 7419 | apex_available: ["myapex"], |
| 7420 | shared_libs: ["stublib"], |
| 7421 | system_shared_libs: [], |
| 7422 | } |
| 7423 | apex { |
| 7424 | name: "otherapex", |
| 7425 | enabled: %s, |
| 7426 | key: "myapex.key", |
| 7427 | native_shared_libs: ["stublib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7428 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7429 | } |
| 7430 | ` |
| 7431 | |
| 7432 | stublibSourceBp := ` |
| 7433 | cc_library { |
| 7434 | name: "stublib", |
| 7435 | srcs: ["mylib.cpp"], |
| 7436 | apex_available: ["otherapex"], |
| 7437 | system_shared_libs: [], |
| 7438 | stl: "none", |
| 7439 | stubs: { |
| 7440 | versions: ["1"], |
| 7441 | }, |
| 7442 | } |
| 7443 | ` |
| 7444 | |
| 7445 | stublibPrebuiltBp := ` |
| 7446 | cc_prebuilt_library_shared { |
| 7447 | name: "stublib", |
| 7448 | srcs: ["prebuilt.so"], |
| 7449 | apex_available: ["otherapex"], |
| 7450 | stubs: { |
| 7451 | versions: ["1"], |
| 7452 | }, |
| 7453 | %s |
| 7454 | } |
| 7455 | ` |
| 7456 | |
| 7457 | tests := []struct { |
| 7458 | name string |
| 7459 | stublibBp string |
| 7460 | usePrebuilt bool |
| 7461 | modNames []string // Modules to collect AndroidMkEntries for |
| 7462 | otherApexEnabled []string |
| 7463 | }{ |
| 7464 | { |
| 7465 | name: "only_source", |
| 7466 | stublibBp: stublibSourceBp, |
| 7467 | usePrebuilt: false, |
| 7468 | modNames: []string{"stublib"}, |
| 7469 | otherApexEnabled: []string{"true", "false"}, |
| 7470 | }, |
| 7471 | { |
| 7472 | name: "source_preferred", |
| 7473 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, ""), |
| 7474 | usePrebuilt: false, |
| 7475 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 7476 | otherApexEnabled: []string{"true", "false"}, |
| 7477 | }, |
| 7478 | { |
| 7479 | name: "prebuilt_preferred", |
| 7480 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, "prefer: true,"), |
| 7481 | usePrebuilt: true, |
| 7482 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 7483 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 7484 | }, |
| 7485 | { |
| 7486 | name: "only_prebuilt", |
| 7487 | stublibBp: fmt.Sprintf(stublibPrebuiltBp, ""), |
| 7488 | usePrebuilt: true, |
| 7489 | modNames: []string{"stublib"}, |
| 7490 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 7491 | }, |
| 7492 | } |
| 7493 | |
| 7494 | for _, test := range tests { |
| 7495 | t.Run(test.name, func(t *testing.T) { |
| 7496 | for _, otherApexEnabled := range test.otherApexEnabled { |
| 7497 | t.Run("otherapex_enabled_"+otherApexEnabled, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7498 | ctx := testApex(t, fmt.Sprintf(bpBase, otherApexEnabled)+test.stublibBp) |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7499 | |
| 7500 | type modAndMkEntries struct { |
| 7501 | mod *cc.Module |
| 7502 | mkEntries android.AndroidMkEntries |
| 7503 | } |
| 7504 | entries := []*modAndMkEntries{} |
| 7505 | |
| 7506 | // Gather shared lib modules that are installable |
| 7507 | for _, modName := range test.modNames { |
| 7508 | for _, variant := range ctx.ModuleVariantsForTests(modName) { |
| 7509 | if !strings.HasPrefix(variant, "android_arm64_armv8-a_shared") { |
| 7510 | continue |
| 7511 | } |
| 7512 | mod := ctx.ModuleForTests(modName, variant).Module().(*cc.Module) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 7513 | if !mod.Enabled() || mod.IsHideFromMake() { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7514 | continue |
| 7515 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7516 | for _, ent := range android.AndroidMkEntriesForTest(t, ctx, mod) { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7517 | if ent.Disabled { |
| 7518 | continue |
| 7519 | } |
| 7520 | entries = append(entries, &modAndMkEntries{ |
| 7521 | mod: mod, |
| 7522 | mkEntries: ent, |
| 7523 | }) |
| 7524 | } |
| 7525 | } |
| 7526 | } |
| 7527 | |
| 7528 | var entry *modAndMkEntries = nil |
| 7529 | for _, ent := range entries { |
| 7530 | if strings.Join(ent.mkEntries.EntryMap["LOCAL_MODULE"], ",") == "stublib" { |
| 7531 | if entry != nil { |
| 7532 | t.Errorf("More than one AndroidMk entry for \"stublib\": %s and %s", entry.mod, ent.mod) |
| 7533 | } else { |
| 7534 | entry = ent |
| 7535 | } |
| 7536 | } |
| 7537 | } |
| 7538 | |
| 7539 | if entry == nil { |
| 7540 | t.Errorf("AndroidMk entry for \"stublib\" missing") |
| 7541 | } else { |
| 7542 | isPrebuilt := entry.mod.Prebuilt() != nil |
| 7543 | if isPrebuilt != test.usePrebuilt { |
| 7544 | t.Errorf("Wrong module for \"stublib\" AndroidMk entry: got prebuilt %t, want prebuilt %t", isPrebuilt, test.usePrebuilt) |
| 7545 | } |
| 7546 | if !entry.mod.IsStubs() { |
| 7547 | t.Errorf("Module for \"stublib\" AndroidMk entry isn't a stub: %s", entry.mod) |
| 7548 | } |
| 7549 | if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil { |
| 7550 | t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries) |
| 7551 | } |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 7552 | cflags := entry.mkEntries.EntryMap["LOCAL_EXPORT_CFLAGS"] |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 7553 | expected := "-D__STUBLIB_API__=10000" |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 7554 | if !android.InList(expected, cflags) { |
| 7555 | t.Errorf("LOCAL_EXPORT_CFLAGS expected to have %q, but got %q", expected, cflags) |
| 7556 | } |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7557 | } |
| 7558 | }) |
| 7559 | } |
| 7560 | }) |
| 7561 | } |
| 7562 | } |
| 7563 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 7564 | func TestMain(m *testing.M) { |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 7565 | os.Exit(m.Run()) |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 7566 | } |