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: [], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 377 | stl: "none", |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 378 | apex_available: [ "myapex", "com.android.gki.*" ], |
| 379 | } |
| 380 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 381 | rust_binary { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 382 | name: "foo.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 383 | srcs: ["foo.rs"], |
| 384 | rlibs: ["libfoo.rlib.rust"], |
| 385 | dylibs: ["libfoo.dylib.rust"], |
| 386 | apex_available: ["myapex"], |
| 387 | } |
| 388 | |
| 389 | rust_library_rlib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 390 | name: "libfoo.rlib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 391 | srcs: ["foo.rs"], |
| 392 | crate_name: "foo", |
| 393 | apex_available: ["myapex"], |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 394 | shared_libs: ["libfoo.shared_from_rust"], |
| 395 | } |
| 396 | |
| 397 | cc_library_shared { |
| 398 | name: "libfoo.shared_from_rust", |
| 399 | srcs: ["mylib.cpp"], |
| 400 | system_shared_libs: [], |
| 401 | stl: "none", |
| 402 | apex_available: ["myapex"], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | rust_library_dylib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 406 | name: "libfoo.dylib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 407 | srcs: ["foo.rs"], |
| 408 | crate_name: "foo", |
| 409 | apex_available: ["myapex"], |
| 410 | } |
| 411 | |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 412 | rust_ffi_shared { |
| 413 | name: "libfoo.ffi", |
| 414 | srcs: ["foo.rs"], |
| 415 | crate_name: "foo", |
| 416 | apex_available: ["myapex"], |
| 417 | } |
| 418 | |
| 419 | rust_ffi_shared { |
| 420 | name: "libbar.ffi", |
| 421 | srcs: ["foo.rs"], |
| 422 | crate_name: "bar", |
| 423 | apex_available: ["myapex"], |
| 424 | } |
| 425 | |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 426 | apex { |
| 427 | name: "com.android.gki.fake", |
| 428 | binaries: ["foo"], |
| 429 | key: "myapex.key", |
| 430 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 431 | updatable: false, |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 434 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 435 | name: "mylib2", |
| 436 | srcs: ["mylib.cpp"], |
| 437 | system_shared_libs: [], |
| 438 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 439 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 440 | static_libs: ["libstatic"], |
| 441 | // TODO: remove //apex_available:platform |
| 442 | apex_available: [ |
| 443 | "//apex_available:platform", |
| 444 | "myapex", |
| 445 | ], |
| 446 | } |
| 447 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 448 | cc_prebuilt_library_shared { |
| 449 | name: "mylib2", |
| 450 | srcs: ["prebuilt.so"], |
| 451 | // TODO: remove //apex_available:platform |
| 452 | apex_available: [ |
| 453 | "//apex_available:platform", |
| 454 | "myapex", |
| 455 | ], |
| 456 | } |
| 457 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 458 | cc_library_static { |
| 459 | name: "libstatic", |
| 460 | srcs: ["mylib.cpp"], |
| 461 | system_shared_libs: [], |
| 462 | stl: "none", |
| 463 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 464 | // TODO: remove //apex_available:platform |
| 465 | apex_available: [ |
| 466 | "//apex_available:platform", |
| 467 | "myapex", |
| 468 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 469 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 470 | |
| 471 | java_library { |
| 472 | name: "myjar", |
| 473 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 474 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 475 | sdk_version: "none", |
| 476 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 477 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 478 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 479 | // TODO: remove //apex_available:platform |
| 480 | apex_available: [ |
| 481 | "//apex_available:platform", |
| 482 | "myapex", |
| 483 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 484 | } |
| 485 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 486 | dex_import { |
| 487 | name: "myjar_dex", |
| 488 | jars: ["prebuilt.jar"], |
| 489 | apex_available: [ |
| 490 | "//apex_available:platform", |
| 491 | "myapex", |
| 492 | ], |
| 493 | } |
| 494 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 495 | java_library { |
| 496 | name: "myotherjar", |
| 497 | srcs: ["foo/bar/MyClass.java"], |
| 498 | sdk_version: "none", |
| 499 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 500 | // TODO: remove //apex_available:platform |
| 501 | apex_available: [ |
| 502 | "//apex_available:platform", |
| 503 | "myapex", |
| 504 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 505 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 506 | |
| 507 | java_library { |
| 508 | name: "mysharedjar", |
| 509 | srcs: ["foo/bar/MyClass.java"], |
| 510 | sdk_version: "none", |
| 511 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 512 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 513 | `) |
| 514 | |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 515 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 516 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 517 | // Make sure that Android.mk is created |
| 518 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 519 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 520 | var builder strings.Builder |
| 521 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 522 | |
| 523 | androidMk := builder.String() |
| 524 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 525 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 526 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 527 | optFlags := apexRule.Args["opt_flags"] |
| 528 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 529 | // Ensure that the NOTICE output is being packaged as an asset. |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 530 | 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] | 531 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 532 | copyCmds := apexRule.Args["copy_commands"] |
| 533 | |
| 534 | // Ensure that main rule creates an output |
| 535 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 536 | |
| 537 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 538 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 539 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") |
| 540 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 541 | ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 542 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 543 | |
| 544 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 545 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
| 546 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 547 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000") |
| 548 | 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] | 549 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 550 | 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] | 551 | |
| 552 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 553 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 554 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 555 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 556 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 557 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 558 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so") |
| 559 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so") |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 560 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 561 | // .. but not for java libs |
| 562 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 563 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 564 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 565 | // Ensure that the platform variant ends with _shared or _common |
| 566 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 567 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 568 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 569 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 570 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 571 | |
| 572 | // Ensure that dynamic dependency to java libs are not included |
| 573 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 574 | |
| 575 | // Ensure that all symlinks are present. |
| 576 | found_foo_link_64 := false |
| 577 | found_foo := false |
| 578 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 579 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 580 | if strings.HasSuffix(cmd, "bin/foo") { |
| 581 | found_foo = true |
| 582 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 583 | found_foo_link_64 = true |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | good := found_foo && found_foo_link_64 |
| 588 | if !good { |
| 589 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 590 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 591 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 592 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 593 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 594 | if len(noticeInputs) != 3 { |
| 595 | 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] | 596 | } |
| 597 | ensureListContains(t, noticeInputs, "NOTICE") |
| 598 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 599 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 600 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 601 | 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] | 602 | ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 603 | ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib") |
| 604 | ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar") |
| 605 | ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 606 | |
| 607 | 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] | 608 | ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 609 | ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))") |
| 610 | ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))") |
| 611 | ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 614 | func TestDefaults(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 615 | ctx := testApex(t, ` |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 616 | apex_defaults { |
| 617 | name: "myapex-defaults", |
| 618 | key: "myapex.key", |
| 619 | prebuilts: ["myetc"], |
| 620 | native_shared_libs: ["mylib"], |
| 621 | java_libs: ["myjar"], |
| 622 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 623 | rros: ["rro"], |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 624 | bpfs: ["bpf"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 625 | updatable: false, |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | prebuilt_etc { |
| 629 | name: "myetc", |
| 630 | src: "myprebuilt", |
| 631 | } |
| 632 | |
| 633 | apex { |
| 634 | name: "myapex", |
| 635 | defaults: ["myapex-defaults"], |
| 636 | } |
| 637 | |
| 638 | apex_key { |
| 639 | name: "myapex.key", |
| 640 | public_key: "testkey.avbpubkey", |
| 641 | private_key: "testkey.pem", |
| 642 | } |
| 643 | |
| 644 | cc_library { |
| 645 | name: "mylib", |
| 646 | system_shared_libs: [], |
| 647 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 648 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | java_library { |
| 652 | name: "myjar", |
| 653 | srcs: ["foo/bar/MyClass.java"], |
| 654 | sdk_version: "none", |
| 655 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 656 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | android_app { |
| 660 | name: "AppFoo", |
| 661 | srcs: ["foo/bar/MyClass.java"], |
| 662 | sdk_version: "none", |
| 663 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 664 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 665 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 666 | |
| 667 | runtime_resource_overlay { |
| 668 | name: "rro", |
| 669 | theme: "blue", |
| 670 | } |
| 671 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 672 | bpf { |
| 673 | name: "bpf", |
| 674 | srcs: ["bpf.c", "bpf2.c"], |
| 675 | } |
| 676 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 677 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 678 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 679 | "etc/myetc", |
| 680 | "javalib/myjar.jar", |
| 681 | "lib64/mylib.so", |
| 682 | "app/AppFoo/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 683 | "overlay/blue/rro.apk", |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 684 | "etc/bpf/bpf.o", |
| 685 | "etc/bpf/bpf2.o", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 686 | }) |
| 687 | } |
| 688 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 689 | func TestApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 690 | ctx := testApex(t, ` |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 691 | apex { |
| 692 | name: "myapex", |
| 693 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 694 | updatable: false, |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | apex_key { |
| 698 | name: "myapex.key", |
| 699 | public_key: "testkey.avbpubkey", |
| 700 | private_key: "testkey.pem", |
| 701 | } |
| 702 | `) |
| 703 | |
| 704 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 705 | args := module.Rule("apexRule").Args |
| 706 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 707 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 708 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 709 | } |
| 710 | |
Liz Kammer | 4854a7d | 2021-05-27 14:28:27 -0400 | [diff] [blame] | 711 | func TestApexManifestMinSdkVersion(t *testing.T) { |
| 712 | ctx := testApex(t, ` |
| 713 | apex_defaults { |
| 714 | name: "my_defaults", |
| 715 | key: "myapex.key", |
| 716 | product_specific: true, |
| 717 | file_contexts: ":my-file-contexts", |
| 718 | updatable: false, |
| 719 | } |
| 720 | apex { |
| 721 | name: "myapex_30", |
| 722 | min_sdk_version: "30", |
| 723 | defaults: ["my_defaults"], |
| 724 | } |
| 725 | |
| 726 | apex { |
| 727 | name: "myapex_current", |
| 728 | min_sdk_version: "current", |
| 729 | defaults: ["my_defaults"], |
| 730 | } |
| 731 | |
| 732 | apex { |
| 733 | name: "myapex_none", |
| 734 | defaults: ["my_defaults"], |
| 735 | } |
| 736 | |
| 737 | apex_key { |
| 738 | name: "myapex.key", |
| 739 | public_key: "testkey.avbpubkey", |
| 740 | private_key: "testkey.pem", |
| 741 | } |
| 742 | |
| 743 | filegroup { |
| 744 | name: "my-file-contexts", |
| 745 | srcs: ["product_specific_file_contexts"], |
| 746 | } |
| 747 | `, withFiles(map[string][]byte{ |
| 748 | "product_specific_file_contexts": nil, |
| 749 | }), android.FixtureModifyProductVariables( |
| 750 | func(variables android.FixtureProductVariables) { |
| 751 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 752 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(false) |
| 753 | }), android.FixtureMergeEnv(map[string]string{ |
| 754 | "UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT": "true", |
| 755 | })) |
| 756 | |
| 757 | testCases := []struct { |
| 758 | module string |
| 759 | minSdkVersion string |
| 760 | }{ |
| 761 | { |
| 762 | module: "myapex_30", |
| 763 | minSdkVersion: "30", |
| 764 | }, |
| 765 | { |
| 766 | module: "myapex_current", |
| 767 | minSdkVersion: "Q.$$(cat out/soong/api_fingerprint.txt)", |
| 768 | }, |
| 769 | { |
| 770 | module: "myapex_none", |
| 771 | minSdkVersion: "Q.$$(cat out/soong/api_fingerprint.txt)", |
| 772 | }, |
| 773 | } |
| 774 | for _, tc := range testCases { |
| 775 | module := ctx.ModuleForTests(tc.module, "android_common_"+tc.module+"_image") |
| 776 | args := module.Rule("apexRule").Args |
| 777 | optFlags := args["opt_flags"] |
| 778 | if !strings.Contains(optFlags, "--min_sdk_version "+tc.minSdkVersion) { |
| 779 | t.Errorf("%s: Expected min_sdk_version=%s, got: %s", tc.module, tc.minSdkVersion, optFlags) |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 784 | func TestBasicZipApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 785 | ctx := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 786 | apex { |
| 787 | name: "myapex", |
| 788 | key: "myapex.key", |
| 789 | payload_type: "zip", |
| 790 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 791 | updatable: false, |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | apex_key { |
| 795 | name: "myapex.key", |
| 796 | public_key: "testkey.avbpubkey", |
| 797 | private_key: "testkey.pem", |
| 798 | } |
| 799 | |
| 800 | cc_library { |
| 801 | name: "mylib", |
| 802 | srcs: ["mylib.cpp"], |
| 803 | shared_libs: ["mylib2"], |
| 804 | system_shared_libs: [], |
| 805 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 806 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | cc_library { |
| 810 | name: "mylib2", |
| 811 | srcs: ["mylib.cpp"], |
| 812 | system_shared_libs: [], |
| 813 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 814 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 815 | } |
| 816 | `) |
| 817 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 818 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 819 | copyCmds := zipApexRule.Args["copy_commands"] |
| 820 | |
| 821 | // Ensure that main rule creates an output |
| 822 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 823 | |
| 824 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 825 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 826 | |
| 827 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 828 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 829 | |
| 830 | // Ensure that both direct and indirect deps are copied into apex |
| 831 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 832 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | func TestApexWithStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 836 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 837 | apex { |
| 838 | name: "myapex", |
| 839 | key: "myapex.key", |
| 840 | native_shared_libs: ["mylib", "mylib3"], |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 841 | binaries: ["foo.rust"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 842 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | apex_key { |
| 846 | name: "myapex.key", |
| 847 | public_key: "testkey.avbpubkey", |
| 848 | private_key: "testkey.pem", |
| 849 | } |
| 850 | |
| 851 | cc_library { |
| 852 | name: "mylib", |
| 853 | srcs: ["mylib.cpp"], |
| 854 | shared_libs: ["mylib2", "mylib3"], |
| 855 | system_shared_libs: [], |
| 856 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 857 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | cc_library { |
| 861 | name: "mylib2", |
| 862 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 863 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 864 | system_shared_libs: [], |
| 865 | stl: "none", |
| 866 | stubs: { |
| 867 | versions: ["1", "2", "3"], |
| 868 | }, |
| 869 | } |
| 870 | |
| 871 | cc_library { |
| 872 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 873 | srcs: ["mylib.cpp"], |
| 874 | shared_libs: ["mylib4"], |
| 875 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 876 | stl: "none", |
| 877 | stubs: { |
| 878 | versions: ["10", "11", "12"], |
| 879 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 880 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 881 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 882 | |
| 883 | cc_library { |
| 884 | name: "mylib4", |
| 885 | srcs: ["mylib.cpp"], |
| 886 | system_shared_libs: [], |
| 887 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 888 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 889 | } |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 890 | |
| 891 | rust_binary { |
| 892 | name: "foo.rust", |
| 893 | srcs: ["foo.rs"], |
| 894 | shared_libs: ["libfoo.shared_from_rust"], |
| 895 | prefer_rlib: true, |
| 896 | apex_available: ["myapex"], |
| 897 | } |
| 898 | |
| 899 | cc_library_shared { |
| 900 | name: "libfoo.shared_from_rust", |
| 901 | srcs: ["mylib.cpp"], |
| 902 | system_shared_libs: [], |
| 903 | stl: "none", |
| 904 | stubs: { |
| 905 | versions: ["10", "11", "12"], |
| 906 | }, |
| 907 | } |
| 908 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 909 | `) |
| 910 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 911 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 912 | copyCmds := apexRule.Args["copy_commands"] |
| 913 | |
| 914 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 915 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 916 | |
| 917 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 918 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 919 | |
| 920 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 921 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 922 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 923 | 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] | 924 | |
| 925 | // 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] | 926 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 927 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 928 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 929 | |
| 930 | // 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] | 931 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 932 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 933 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 934 | |
| 935 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 936 | 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] | 937 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 938 | |
| 939 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 940 | 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] | 941 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 942 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 943 | "lib64/mylib.so", |
| 944 | "lib64/mylib3.so", |
| 945 | "lib64/mylib4.so", |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 946 | "bin/foo.rust", |
| 947 | "lib64/libc++.so", // by the implicit dependency from foo.rust |
| 948 | "lib64/liblog.so", // by the implicit dependency from foo.rust |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 949 | }) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 950 | |
| 951 | // Ensure that stub dependency from a rust module is not included |
| 952 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so") |
| 953 | // The rust module is linked to the stub cc library |
| 954 | rustDeps := ctx.ModuleForTests("foo.rust", "android_arm64_armv8-a_apex10000").Rule("rustc").Args["linkFlags"] |
| 955 | ensureContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared_current/libfoo.shared_from_rust.so") |
| 956 | ensureNotContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared/libfoo.shared_from_rust.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 957 | } |
| 958 | |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 959 | func TestApexCanUsePrivateApis(t *testing.T) { |
| 960 | ctx := testApex(t, ` |
| 961 | apex { |
| 962 | name: "myapex", |
| 963 | key: "myapex.key", |
| 964 | native_shared_libs: ["mylib"], |
| 965 | binaries: ["foo.rust"], |
| 966 | updatable: false, |
| 967 | platform_apis: true, |
| 968 | } |
| 969 | |
| 970 | apex_key { |
| 971 | name: "myapex.key", |
| 972 | public_key: "testkey.avbpubkey", |
| 973 | private_key: "testkey.pem", |
| 974 | } |
| 975 | |
| 976 | cc_library { |
| 977 | name: "mylib", |
| 978 | srcs: ["mylib.cpp"], |
| 979 | shared_libs: ["mylib2"], |
| 980 | system_shared_libs: [], |
| 981 | stl: "none", |
| 982 | apex_available: [ "myapex" ], |
| 983 | } |
| 984 | |
| 985 | cc_library { |
| 986 | name: "mylib2", |
| 987 | srcs: ["mylib.cpp"], |
| 988 | cflags: ["-include mylib.h"], |
| 989 | system_shared_libs: [], |
| 990 | stl: "none", |
| 991 | stubs: { |
| 992 | versions: ["1", "2", "3"], |
| 993 | }, |
| 994 | } |
| 995 | |
| 996 | rust_binary { |
| 997 | name: "foo.rust", |
| 998 | srcs: ["foo.rs"], |
| 999 | shared_libs: ["libfoo.shared_from_rust"], |
| 1000 | prefer_rlib: true, |
| 1001 | apex_available: ["myapex"], |
| 1002 | } |
| 1003 | |
| 1004 | cc_library_shared { |
| 1005 | name: "libfoo.shared_from_rust", |
| 1006 | srcs: ["mylib.cpp"], |
| 1007 | system_shared_libs: [], |
| 1008 | stl: "none", |
| 1009 | stubs: { |
| 1010 | versions: ["10", "11", "12"], |
| 1011 | }, |
| 1012 | } |
| 1013 | `) |
| 1014 | |
| 1015 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 1016 | copyCmds := apexRule.Args["copy_commands"] |
| 1017 | |
| 1018 | // Ensure that indirect stubs dep is not included |
| 1019 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 1020 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so") |
| 1021 | |
| 1022 | // Ensure that we are using non-stub variants of mylib2 and libfoo.shared_from_rust (because |
| 1023 | // of the platform_apis: true) |
| 1024 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000_private").Rule("ld").Args["libFlags"] |
| 1025 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
| 1026 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 1027 | rustDeps := ctx.ModuleForTests("foo.rust", "android_arm64_armv8-a_apex10000_private").Rule("rustc").Args["linkFlags"] |
| 1028 | ensureNotContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared_current/libfoo.shared_from_rust.so") |
| 1029 | ensureContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared/libfoo.shared_from_rust.so") |
| 1030 | } |
| 1031 | |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1032 | func TestApexWithStubsWithMinSdkVersion(t *testing.T) { |
| 1033 | t.Parallel() |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1034 | ctx := testApex(t, ` |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1035 | apex { |
| 1036 | name: "myapex", |
| 1037 | key: "myapex.key", |
| 1038 | native_shared_libs: ["mylib", "mylib3"], |
| 1039 | min_sdk_version: "29", |
| 1040 | } |
| 1041 | |
| 1042 | apex_key { |
| 1043 | name: "myapex.key", |
| 1044 | public_key: "testkey.avbpubkey", |
| 1045 | private_key: "testkey.pem", |
| 1046 | } |
| 1047 | |
| 1048 | cc_library { |
| 1049 | name: "mylib", |
| 1050 | srcs: ["mylib.cpp"], |
| 1051 | shared_libs: ["mylib2", "mylib3"], |
| 1052 | system_shared_libs: [], |
| 1053 | stl: "none", |
| 1054 | apex_available: [ "myapex" ], |
| 1055 | min_sdk_version: "28", |
| 1056 | } |
| 1057 | |
| 1058 | cc_library { |
| 1059 | name: "mylib2", |
| 1060 | srcs: ["mylib.cpp"], |
| 1061 | cflags: ["-include mylib.h"], |
| 1062 | system_shared_libs: [], |
| 1063 | stl: "none", |
| 1064 | stubs: { |
| 1065 | versions: ["28", "29", "30", "current"], |
| 1066 | }, |
| 1067 | min_sdk_version: "28", |
| 1068 | } |
| 1069 | |
| 1070 | cc_library { |
| 1071 | name: "mylib3", |
| 1072 | srcs: ["mylib.cpp"], |
| 1073 | shared_libs: ["mylib4"], |
| 1074 | system_shared_libs: [], |
| 1075 | stl: "none", |
| 1076 | stubs: { |
| 1077 | versions: ["28", "29", "30", "current"], |
| 1078 | }, |
| 1079 | apex_available: [ "myapex" ], |
| 1080 | min_sdk_version: "28", |
| 1081 | } |
| 1082 | |
| 1083 | cc_library { |
| 1084 | name: "mylib4", |
| 1085 | srcs: ["mylib.cpp"], |
| 1086 | system_shared_libs: [], |
| 1087 | stl: "none", |
| 1088 | apex_available: [ "myapex" ], |
| 1089 | min_sdk_version: "28", |
| 1090 | } |
| 1091 | `) |
| 1092 | |
| 1093 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 1094 | copyCmds := apexRule.Args["copy_commands"] |
| 1095 | |
| 1096 | // Ensure that direct non-stubs dep is always included |
| 1097 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1098 | |
| 1099 | // Ensure that indirect stubs dep is not included |
| 1100 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 1101 | |
| 1102 | // Ensure that direct stubs dep is included |
| 1103 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 1104 | |
| 1105 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"] |
| 1106 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1107 | // Ensure that mylib is linking with the latest version of stub for mylib2 |
| 1108 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1109 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| 1110 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 1111 | |
| 1112 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| 1113 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so") |
| 1114 | // .. and not linking to the stubs variant of mylib3 |
| 1115 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so") |
| 1116 | |
| 1117 | // Ensure that stubs libs are built without -include flags |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 1118 | 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] | 1119 | ensureNotContains(t, mylib2Cflags, "-include ") |
| 1120 | |
| 1121 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 1122 | 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] | 1123 | |
| 1124 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1125 | "lib64/mylib.so", |
| 1126 | "lib64/mylib3.so", |
| 1127 | "lib64/mylib4.so", |
| 1128 | }) |
| 1129 | } |
| 1130 | |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1131 | func TestApex_PlatformUsesLatestStubFromApex(t *testing.T) { |
| 1132 | t.Parallel() |
| 1133 | // myapex (Z) |
| 1134 | // mylib -----------------. |
| 1135 | // | |
| 1136 | // otherapex (29) | |
| 1137 | // libstub's versions: 29 Z current |
| 1138 | // | |
| 1139 | // <platform> | |
| 1140 | // libplatform ----------------' |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1141 | ctx := testApex(t, ` |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1142 | apex { |
| 1143 | name: "myapex", |
| 1144 | key: "myapex.key", |
| 1145 | native_shared_libs: ["mylib"], |
| 1146 | min_sdk_version: "Z", // non-final |
| 1147 | } |
| 1148 | |
| 1149 | cc_library { |
| 1150 | name: "mylib", |
| 1151 | srcs: ["mylib.cpp"], |
| 1152 | shared_libs: ["libstub"], |
| 1153 | apex_available: ["myapex"], |
| 1154 | min_sdk_version: "Z", |
| 1155 | } |
| 1156 | |
| 1157 | apex_key { |
| 1158 | name: "myapex.key", |
| 1159 | public_key: "testkey.avbpubkey", |
| 1160 | private_key: "testkey.pem", |
| 1161 | } |
| 1162 | |
| 1163 | apex { |
| 1164 | name: "otherapex", |
| 1165 | key: "myapex.key", |
| 1166 | native_shared_libs: ["libstub"], |
| 1167 | min_sdk_version: "29", |
| 1168 | } |
| 1169 | |
| 1170 | cc_library { |
| 1171 | name: "libstub", |
| 1172 | srcs: ["mylib.cpp"], |
| 1173 | stubs: { |
| 1174 | versions: ["29", "Z", "current"], |
| 1175 | }, |
| 1176 | apex_available: ["otherapex"], |
| 1177 | min_sdk_version: "29", |
| 1178 | } |
| 1179 | |
| 1180 | // platform module depending on libstub from otherapex should use the latest stub("current") |
| 1181 | cc_library { |
| 1182 | name: "libplatform", |
| 1183 | srcs: ["mylib.cpp"], |
| 1184 | shared_libs: ["libstub"], |
| 1185 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1186 | `, |
| 1187 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1188 | variables.Platform_sdk_codename = proptools.StringPtr("Z") |
| 1189 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
| 1190 | variables.Platform_version_active_codenames = []string{"Z"} |
| 1191 | }), |
| 1192 | ) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1193 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1194 | // Ensure that mylib from myapex is built against the latest stub (current) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1195 | 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] | 1196 | ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=10000 ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1197 | 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] | 1198 | ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1199 | |
| 1200 | // Ensure that libplatform is built against latest stub ("current") of mylib3 from the apex |
| 1201 | libplatformCflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1202 | ensureContains(t, libplatformCflags, "-D__LIBSTUB_API__=10000 ") // "current" maps to 10000 |
| 1203 | libplatformLdflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1204 | ensureContains(t, libplatformLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
| 1205 | } |
| 1206 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1207 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1208 | ctx := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1209 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1210 | name: "myapex2", |
| 1211 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1212 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1213 | updatable: false, |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1217 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1218 | public_key: "testkey.avbpubkey", |
| 1219 | private_key: "testkey.pem", |
| 1220 | } |
| 1221 | |
| 1222 | cc_library { |
| 1223 | name: "mylib", |
| 1224 | srcs: ["mylib.cpp"], |
| 1225 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1226 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1227 | system_shared_libs: [], |
| 1228 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1229 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | cc_library { |
| 1233 | name: "libfoo", |
| 1234 | srcs: ["mylib.cpp"], |
| 1235 | shared_libs: ["libbar"], |
| 1236 | system_shared_libs: [], |
| 1237 | stl: "none", |
| 1238 | stubs: { |
| 1239 | versions: ["10", "20", "30"], |
| 1240 | }, |
| 1241 | } |
| 1242 | |
| 1243 | cc_library { |
| 1244 | name: "libbar", |
| 1245 | srcs: ["mylib.cpp"], |
| 1246 | system_shared_libs: [], |
| 1247 | stl: "none", |
| 1248 | } |
| 1249 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1250 | cc_library_static { |
| 1251 | name: "libbaz", |
| 1252 | srcs: ["mylib.cpp"], |
| 1253 | system_shared_libs: [], |
| 1254 | stl: "none", |
| 1255 | apex_available: [ "myapex2" ], |
| 1256 | } |
| 1257 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1258 | `) |
| 1259 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1260 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1261 | copyCmds := apexRule.Args["copy_commands"] |
| 1262 | |
| 1263 | // Ensure that direct non-stubs dep is always included |
| 1264 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1265 | |
| 1266 | // Ensure that indirect stubs dep is not included |
| 1267 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1268 | |
| 1269 | // Ensure that dependency of stubs is not included |
| 1270 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1271 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1272 | 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] | 1273 | |
| 1274 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1275 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1276 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1277 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1278 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1279 | 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] | 1280 | |
| 1281 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 1282 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1283 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1284 | 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] | 1285 | ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1286 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1287 | 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] | 1288 | ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1289 | } |
| 1290 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1291 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 1292 | /* |
| 1293 | myapex |
| 1294 | | |
| 1295 | v (runtime_libs) |
| 1296 | mylib ------+------> libfoo [provides stub] |
| 1297 | | |
| 1298 | `------> libbar |
| 1299 | */ |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1300 | ctx := testApex(t, ` |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1301 | apex { |
| 1302 | name: "myapex", |
| 1303 | key: "myapex.key", |
| 1304 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1305 | updatable: false, |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | apex_key { |
| 1309 | name: "myapex.key", |
| 1310 | public_key: "testkey.avbpubkey", |
| 1311 | private_key: "testkey.pem", |
| 1312 | } |
| 1313 | |
| 1314 | cc_library { |
| 1315 | name: "mylib", |
| 1316 | srcs: ["mylib.cpp"], |
| 1317 | runtime_libs: ["libfoo", "libbar"], |
| 1318 | system_shared_libs: [], |
| 1319 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1320 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | cc_library { |
| 1324 | name: "libfoo", |
| 1325 | srcs: ["mylib.cpp"], |
| 1326 | system_shared_libs: [], |
| 1327 | stl: "none", |
| 1328 | stubs: { |
| 1329 | versions: ["10", "20", "30"], |
| 1330 | }, |
| 1331 | } |
| 1332 | |
| 1333 | cc_library { |
| 1334 | name: "libbar", |
| 1335 | srcs: ["mylib.cpp"], |
| 1336 | system_shared_libs: [], |
| 1337 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1338 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | `) |
| 1342 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1343 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1344 | copyCmds := apexRule.Args["copy_commands"] |
| 1345 | |
| 1346 | // Ensure that direct non-stubs dep is always included |
| 1347 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1348 | |
| 1349 | // Ensure that indirect stubs dep is not included |
| 1350 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1351 | |
| 1352 | // Ensure that runtime_libs dep in included |
| 1353 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1354 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1355 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1356 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1357 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1358 | |
| 1359 | } |
| 1360 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1361 | var prepareForTestOfRuntimeApexWithHwasan = android.GroupFixturePreparers( |
| 1362 | cc.PrepareForTestWithCcBuildComponents, |
| 1363 | PrepareForTestWithApexBuildComponents, |
| 1364 | android.FixtureAddTextFile("bionic/apex/Android.bp", ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1365 | apex { |
| 1366 | name: "com.android.runtime", |
| 1367 | key: "com.android.runtime.key", |
| 1368 | native_shared_libs: ["libc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1369 | updatable: false, |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | apex_key { |
| 1373 | name: "com.android.runtime.key", |
| 1374 | public_key: "testkey.avbpubkey", |
| 1375 | private_key: "testkey.pem", |
| 1376 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1377 | `), |
| 1378 | android.FixtureAddFile("system/sepolicy/apex/com.android.runtime-file_contexts", nil), |
| 1379 | ) |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1380 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1381 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1382 | result := android.GroupFixturePreparers(prepareForTestOfRuntimeApexWithHwasan).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1383 | cc_library { |
| 1384 | name: "libc", |
| 1385 | no_libcrt: true, |
| 1386 | nocrt: true, |
| 1387 | stl: "none", |
| 1388 | system_shared_libs: [], |
| 1389 | stubs: { versions: ["1"] }, |
| 1390 | apex_available: ["com.android.runtime"], |
| 1391 | |
| 1392 | sanitize: { |
| 1393 | hwaddress: true, |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | cc_prebuilt_library_shared { |
| 1398 | name: "libclang_rt.hwasan-aarch64-android", |
| 1399 | no_libcrt: true, |
| 1400 | nocrt: true, |
| 1401 | stl: "none", |
| 1402 | system_shared_libs: [], |
| 1403 | srcs: [""], |
| 1404 | stubs: { versions: ["1"] }, |
| 1405 | |
| 1406 | sanitize: { |
| 1407 | never: true, |
| 1408 | }, |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1409 | } `) |
| 1410 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1411 | |
| 1412 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1413 | "lib64/bionic/libc.so", |
| 1414 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1415 | }) |
| 1416 | |
| 1417 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1418 | |
| 1419 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1420 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1421 | |
| 1422 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1423 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1424 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1425 | } |
| 1426 | |
| 1427 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1428 | result := android.GroupFixturePreparers( |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1429 | prepareForTestOfRuntimeApexWithHwasan, |
| 1430 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1431 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1432 | }), |
| 1433 | ).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1434 | cc_library { |
| 1435 | name: "libc", |
| 1436 | no_libcrt: true, |
| 1437 | nocrt: true, |
| 1438 | stl: "none", |
| 1439 | system_shared_libs: [], |
| 1440 | stubs: { versions: ["1"] }, |
| 1441 | apex_available: ["com.android.runtime"], |
| 1442 | } |
| 1443 | |
| 1444 | cc_prebuilt_library_shared { |
| 1445 | name: "libclang_rt.hwasan-aarch64-android", |
| 1446 | no_libcrt: true, |
| 1447 | nocrt: true, |
| 1448 | stl: "none", |
| 1449 | system_shared_libs: [], |
| 1450 | srcs: [""], |
| 1451 | stubs: { versions: ["1"] }, |
| 1452 | |
| 1453 | sanitize: { |
| 1454 | never: true, |
| 1455 | }, |
| 1456 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1457 | `) |
| 1458 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1459 | |
| 1460 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1461 | "lib64/bionic/libc.so", |
| 1462 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1463 | }) |
| 1464 | |
| 1465 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1466 | |
| 1467 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1468 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1469 | |
| 1470 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1471 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1472 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1473 | } |
| 1474 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1475 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1476 | testcases := []struct { |
| 1477 | name string |
| 1478 | minSdkVersion string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1479 | apexVariant string |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1480 | shouldLink string |
| 1481 | shouldNotLink []string |
| 1482 | }{ |
| 1483 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1484 | name: "unspecified version links to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1485 | minSdkVersion: "", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1486 | apexVariant: "apex10000", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1487 | shouldLink: "current", |
| 1488 | shouldNotLink: []string{"29", "30"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1489 | }, |
| 1490 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1491 | name: "always use the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1492 | minSdkVersion: "min_sdk_version: \"29\",", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1493 | apexVariant: "apex29", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1494 | shouldLink: "current", |
| 1495 | shouldNotLink: []string{"29", "30"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1496 | }, |
| 1497 | } |
| 1498 | for _, tc := range testcases { |
| 1499 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1500 | ctx := testApex(t, ` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1501 | apex { |
| 1502 | name: "myapex", |
| 1503 | key: "myapex.key", |
| 1504 | use_vendor: true, |
| 1505 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1506 | updatable: false, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1507 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1508 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1509 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1510 | apex_key { |
| 1511 | name: "myapex.key", |
| 1512 | public_key: "testkey.avbpubkey", |
| 1513 | private_key: "testkey.pem", |
| 1514 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1515 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1516 | cc_library { |
| 1517 | name: "mylib", |
| 1518 | srcs: ["mylib.cpp"], |
| 1519 | vendor_available: true, |
| 1520 | shared_libs: ["libbar"], |
| 1521 | system_shared_libs: [], |
| 1522 | stl: "none", |
| 1523 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1524 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1525 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1526 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1527 | cc_library { |
| 1528 | name: "libbar", |
| 1529 | srcs: ["mylib.cpp"], |
| 1530 | system_shared_libs: [], |
| 1531 | stl: "none", |
| 1532 | stubs: { versions: ["29","30"] }, |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1533 | llndk: { |
| 1534 | symbol_file: "libbar.map.txt", |
| 1535 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1536 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1537 | `, |
| 1538 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 1539 | withUnbundledBuild, |
| 1540 | ) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1541 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1542 | // Ensure that LLNDK dep is not included |
| 1543 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1544 | "lib64/mylib.so", |
| 1545 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1546 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1547 | // Ensure that LLNDK dep is required |
| 1548 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1549 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1550 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1551 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1552 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.29_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"] |
| 1553 | 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] | 1554 | for _, ver := range tc.shouldNotLink { |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1555 | 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] | 1556 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1557 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1558 | 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] | 1559 | ver := tc.shouldLink |
| 1560 | if tc.shouldLink == "current" { |
| 1561 | ver = strconv.Itoa(android.FutureApiLevelInt) |
| 1562 | } |
| 1563 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+ver) |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1564 | }) |
| 1565 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1566 | } |
| 1567 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1568 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1569 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1570 | apex { |
| 1571 | name: "myapex", |
| 1572 | key: "myapex.key", |
| 1573 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1574 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | apex_key { |
| 1578 | name: "myapex.key", |
| 1579 | public_key: "testkey.avbpubkey", |
| 1580 | private_key: "testkey.pem", |
| 1581 | } |
| 1582 | |
| 1583 | cc_library { |
| 1584 | name: "mylib", |
| 1585 | srcs: ["mylib.cpp"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1586 | system_shared_libs: ["libc", "libm"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1587 | shared_libs: ["libdl#27"], |
| 1588 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1589 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | cc_library_shared { |
| 1593 | name: "mylib_shared", |
| 1594 | srcs: ["mylib.cpp"], |
| 1595 | shared_libs: ["libdl#27"], |
| 1596 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1597 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1601 | name: "libBootstrap", |
| 1602 | srcs: ["mylib.cpp"], |
| 1603 | stl: "none", |
| 1604 | bootstrap: true, |
| 1605 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1606 | `) |
| 1607 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1608 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1609 | copyCmds := apexRule.Args["copy_commands"] |
| 1610 | |
| 1611 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1612 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1613 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1614 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1615 | |
| 1616 | // 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] | 1617 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1618 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1619 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1620 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1621 | 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] | 1622 | |
| 1623 | // For dependency to libc |
| 1624 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1625 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_current/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1626 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1627 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1628 | // ... Cflags from stub is correctly exported to mylib |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1629 | ensureContains(t, mylibCFlags, "__LIBC_API__=10000") |
| 1630 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1631 | |
| 1632 | // For dependency to libm |
| 1633 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1634 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1635 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1636 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1637 | // ... and is not compiling with the stub |
| 1638 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1639 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1640 | |
| 1641 | // For dependency to libdl |
| 1642 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1643 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1644 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1645 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1646 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1647 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1648 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1649 | // ... Cflags from stub is correctly exported to mylib |
| 1650 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1651 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1652 | |
| 1653 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1654 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1655 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1656 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1657 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1658 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1659 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1660 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1661 | // there are three links between liba --> libz. |
| 1662 | // 1) myapex -> libx -> liba -> libz : this should be #30 link |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1663 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1664 | // 3) (platform) -> liba -> libz : this should be non-stub link |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1665 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1666 | apex { |
| 1667 | name: "myapex", |
| 1668 | key: "myapex.key", |
| 1669 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1670 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | apex { |
| 1674 | name: "otherapex", |
| 1675 | key: "myapex.key", |
| 1676 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1677 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | apex_key { |
| 1681 | name: "myapex.key", |
| 1682 | public_key: "testkey.avbpubkey", |
| 1683 | private_key: "testkey.pem", |
| 1684 | } |
| 1685 | |
| 1686 | cc_library { |
| 1687 | name: "libx", |
| 1688 | shared_libs: ["liba"], |
| 1689 | system_shared_libs: [], |
| 1690 | stl: "none", |
| 1691 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1692 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | cc_library { |
| 1696 | name: "liby", |
| 1697 | shared_libs: ["liba"], |
| 1698 | system_shared_libs: [], |
| 1699 | stl: "none", |
| 1700 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1701 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | cc_library { |
| 1705 | name: "liba", |
| 1706 | shared_libs: ["libz"], |
| 1707 | system_shared_libs: [], |
| 1708 | stl: "none", |
| 1709 | apex_available: [ |
| 1710 | "//apex_available:anyapex", |
| 1711 | "//apex_available:platform", |
| 1712 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1713 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | cc_library { |
| 1717 | name: "libz", |
| 1718 | system_shared_libs: [], |
| 1719 | stl: "none", |
| 1720 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1721 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1722 | }, |
| 1723 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1724 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1725 | |
| 1726 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1727 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1728 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1729 | } |
| 1730 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1731 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1732 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1733 | } |
| 1734 | // platform liba is linked to non-stub version |
| 1735 | expectLink("liba", "shared", "libz", "shared") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1736 | // liba in myapex is linked to current |
| 1737 | expectLink("liba", "shared_apex29", "libz", "shared_current") |
| 1738 | expectNoLink("liba", "shared_apex29", "libz", "shared_30") |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1739 | expectNoLink("liba", "shared_apex29", "libz", "shared_28") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1740 | expectNoLink("liba", "shared_apex29", "libz", "shared") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1741 | // liba in otherapex is linked to current |
| 1742 | expectLink("liba", "shared_apex30", "libz", "shared_current") |
| 1743 | expectNoLink("liba", "shared_apex30", "libz", "shared_30") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1744 | expectNoLink("liba", "shared_apex30", "libz", "shared_28") |
| 1745 | expectNoLink("liba", "shared_apex30", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1746 | } |
| 1747 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1748 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1749 | ctx := testApex(t, ` |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1750 | apex { |
| 1751 | name: "myapex", |
| 1752 | key: "myapex.key", |
| 1753 | native_shared_libs: ["libx"], |
| 1754 | min_sdk_version: "R", |
| 1755 | } |
| 1756 | |
| 1757 | apex_key { |
| 1758 | name: "myapex.key", |
| 1759 | public_key: "testkey.avbpubkey", |
| 1760 | private_key: "testkey.pem", |
| 1761 | } |
| 1762 | |
| 1763 | cc_library { |
| 1764 | name: "libx", |
| 1765 | shared_libs: ["libz"], |
| 1766 | system_shared_libs: [], |
| 1767 | stl: "none", |
| 1768 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1769 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | cc_library { |
| 1773 | name: "libz", |
| 1774 | system_shared_libs: [], |
| 1775 | stl: "none", |
| 1776 | stubs: { |
| 1777 | versions: ["29", "R"], |
| 1778 | }, |
| 1779 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1780 | `, |
| 1781 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1782 | variables.Platform_version_active_codenames = []string{"R"} |
| 1783 | }), |
| 1784 | ) |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1785 | |
| 1786 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1787 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1788 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1789 | } |
| 1790 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1791 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1792 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1793 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1794 | expectLink("libx", "shared_apex10000", "libz", "shared_current") |
| 1795 | expectNoLink("libx", "shared_apex10000", "libz", "shared_R") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1796 | expectNoLink("libx", "shared_apex10000", "libz", "shared_29") |
| 1797 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1798 | } |
| 1799 | |
Jooyung Han | 4c4da06 | 2021-06-23 10:23:16 +0900 | [diff] [blame] | 1800 | func TestApexMinSdkVersion_SupportsCodeNames_JavaLibs(t *testing.T) { |
| 1801 | testApex(t, ` |
| 1802 | apex { |
| 1803 | name: "myapex", |
| 1804 | key: "myapex.key", |
| 1805 | java_libs: ["libx"], |
| 1806 | min_sdk_version: "S", |
| 1807 | } |
| 1808 | |
| 1809 | apex_key { |
| 1810 | name: "myapex.key", |
| 1811 | public_key: "testkey.avbpubkey", |
| 1812 | private_key: "testkey.pem", |
| 1813 | } |
| 1814 | |
| 1815 | java_library { |
| 1816 | name: "libx", |
| 1817 | srcs: ["a.java"], |
| 1818 | apex_available: [ "myapex" ], |
| 1819 | sdk_version: "current", |
| 1820 | min_sdk_version: "S", // should be okay |
| 1821 | } |
| 1822 | `, |
| 1823 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1824 | variables.Platform_version_active_codenames = []string{"S"} |
| 1825 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 1826 | }), |
| 1827 | ) |
| 1828 | } |
| 1829 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1830 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1831 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1832 | apex { |
| 1833 | name: "myapex", |
| 1834 | key: "myapex.key", |
| 1835 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1836 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | apex_key { |
| 1840 | name: "myapex.key", |
| 1841 | public_key: "testkey.avbpubkey", |
| 1842 | private_key: "testkey.pem", |
| 1843 | } |
| 1844 | |
| 1845 | cc_library { |
| 1846 | name: "libx", |
| 1847 | shared_libs: ["libz"], |
| 1848 | system_shared_libs: [], |
| 1849 | stl: "none", |
| 1850 | apex_available: [ "myapex" ], |
| 1851 | } |
| 1852 | |
| 1853 | cc_library { |
| 1854 | name: "libz", |
| 1855 | system_shared_libs: [], |
| 1856 | stl: "none", |
| 1857 | stubs: { |
| 1858 | versions: ["1", "2"], |
| 1859 | }, |
| 1860 | } |
| 1861 | `) |
| 1862 | |
| 1863 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1864 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1865 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1866 | } |
| 1867 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1868 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1869 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1870 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1871 | expectLink("libx", "shared_apex10000", "libz", "shared_current") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1872 | expectNoLink("libx", "shared_apex10000", "libz", "shared_1") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1873 | expectNoLink("libx", "shared_apex10000", "libz", "shared_2") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1874 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1875 | } |
| 1876 | |
Jiyong Park | 5df7bd3 | 2021-08-25 16:18:46 +0900 | [diff] [blame^] | 1877 | func TestApexMinSdkVersion_crtobjectInVendorApex(t *testing.T) { |
| 1878 | ctx := testApex(t, ` |
| 1879 | apex { |
| 1880 | name: "myapex", |
| 1881 | key: "myapex.key", |
| 1882 | native_shared_libs: ["mylib"], |
| 1883 | updatable: false, |
| 1884 | vendor: true, |
| 1885 | min_sdk_version: "29", |
| 1886 | } |
| 1887 | |
| 1888 | apex_key { |
| 1889 | name: "myapex.key", |
| 1890 | public_key: "testkey.avbpubkey", |
| 1891 | private_key: "testkey.pem", |
| 1892 | } |
| 1893 | |
| 1894 | cc_library { |
| 1895 | name: "mylib", |
| 1896 | vendor_available: true, |
| 1897 | system_shared_libs: [], |
| 1898 | stl: "none", |
| 1899 | apex_available: [ "myapex" ], |
| 1900 | min_sdk_version: "29", |
| 1901 | } |
| 1902 | `) |
| 1903 | |
| 1904 | vendorVariant := "android_vendor.29_arm64_armv8-a" |
| 1905 | |
| 1906 | // First check that the correct variant of crtbegin_so is used. |
| 1907 | ldRule := ctx.ModuleForTests("mylib", vendorVariant+"_shared_apex29").Rule("ld") |
| 1908 | crtBegin := names(ldRule.Args["crtBegin"]) |
| 1909 | ensureListContains(t, crtBegin, "out/soong/.intermediates/"+cc.DefaultCcCommonTestModulesDir+"crtbegin_so/"+vendorVariant+"_apex29/crtbegin_so.o") |
| 1910 | |
| 1911 | // Ensure that the crtbegin_so used by the APEX is targeting 29 |
| 1912 | cflags := ctx.ModuleForTests("crtbegin_so", vendorVariant+"_apex29").Rule("cc").Args["cFlags"] |
| 1913 | android.AssertStringDoesContain(t, "cflags", cflags, "-target aarch64-linux-android29") |
| 1914 | } |
| 1915 | |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1916 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1917 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1918 | apex { |
| 1919 | name: "myapex", |
| 1920 | key: "myapex.key", |
| 1921 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1922 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | apex_key { |
| 1926 | name: "myapex.key", |
| 1927 | public_key: "testkey.avbpubkey", |
| 1928 | private_key: "testkey.pem", |
| 1929 | } |
| 1930 | |
| 1931 | cc_library { |
| 1932 | name: "libx", |
| 1933 | system_shared_libs: [], |
| 1934 | stl: "none", |
| 1935 | apex_available: [ "myapex" ], |
| 1936 | stubs: { |
| 1937 | versions: ["1", "2"], |
| 1938 | }, |
| 1939 | } |
| 1940 | |
| 1941 | cc_library { |
| 1942 | name: "libz", |
| 1943 | shared_libs: ["libx"], |
| 1944 | system_shared_libs: [], |
| 1945 | stl: "none", |
| 1946 | } |
| 1947 | `) |
| 1948 | |
| 1949 | expectLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1950 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1951 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1952 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1953 | } |
| 1954 | expectNoLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1955 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1956 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1957 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1958 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1959 | expectLink("libz", "shared", "libx", "shared_current") |
| 1960 | expectNoLink("libz", "shared", "libx", "shared_2") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1961 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1962 | expectNoLink("libz", "shared", "libz", "shared") |
| 1963 | } |
| 1964 | |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1965 | var prepareForTestWithSantitizeHwaddress = android.FixtureModifyProductVariables( |
| 1966 | func(variables android.FixtureProductVariables) { |
| 1967 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1968 | }, |
| 1969 | ) |
| 1970 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1971 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1972 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1973 | apex { |
| 1974 | name: "myapex", |
| 1975 | key: "myapex.key", |
| 1976 | native_shared_libs: ["libx"], |
| 1977 | min_sdk_version: "29", |
| 1978 | } |
| 1979 | |
| 1980 | apex_key { |
| 1981 | name: "myapex.key", |
| 1982 | public_key: "testkey.avbpubkey", |
| 1983 | private_key: "testkey.pem", |
| 1984 | } |
| 1985 | |
| 1986 | cc_library { |
| 1987 | name: "libx", |
| 1988 | shared_libs: ["libbar"], |
| 1989 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1990 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | cc_library { |
| 1994 | name: "libbar", |
| 1995 | stubs: { |
| 1996 | versions: ["29", "30"], |
| 1997 | }, |
| 1998 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1999 | `, |
| 2000 | prepareForTestWithSantitizeHwaddress, |
| 2001 | ) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2002 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2003 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2004 | libFlags := ld.Args["libFlags"] |
| 2005 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2006 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2007 | expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_current") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2008 | } |
| 2009 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 2010 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2011 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2012 | apex { |
| 2013 | name: "myapex", |
| 2014 | key: "myapex.key", |
| 2015 | native_shared_libs: ["libx"], |
| 2016 | min_sdk_version: "29", |
| 2017 | } |
| 2018 | |
| 2019 | apex_key { |
| 2020 | name: "myapex.key", |
| 2021 | public_key: "testkey.avbpubkey", |
| 2022 | private_key: "testkey.pem", |
| 2023 | } |
| 2024 | |
| 2025 | cc_library { |
| 2026 | name: "libx", |
| 2027 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2028 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2029 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 2030 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2031 | |
| 2032 | // ensure apex variant of c++ is linked with static unwinder |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2033 | 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] | 2034 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2035 | // note that platform variant is not. |
| 2036 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 2037 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2038 | } |
| 2039 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2040 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 2041 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2042 | apex { |
| 2043 | name: "myapex", |
| 2044 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2045 | native_shared_libs: ["mylib"], |
| 2046 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | apex_key { |
| 2050 | name: "myapex.key", |
| 2051 | public_key: "testkey.avbpubkey", |
| 2052 | private_key: "testkey.pem", |
| 2053 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2054 | |
| 2055 | cc_library { |
| 2056 | name: "mylib", |
| 2057 | srcs: ["mylib.cpp"], |
| 2058 | system_shared_libs: [], |
| 2059 | stl: "none", |
| 2060 | apex_available: [ |
| 2061 | "myapex", |
| 2062 | ], |
| 2063 | min_sdk_version: "30", |
| 2064 | } |
| 2065 | `) |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 2066 | |
| 2067 | testApexError(t, `module "libfoo.ffi".*: should support min_sdk_version\(29\)`, ` |
| 2068 | apex { |
| 2069 | name: "myapex", |
| 2070 | key: "myapex.key", |
| 2071 | native_shared_libs: ["libfoo.ffi"], |
| 2072 | min_sdk_version: "29", |
| 2073 | } |
| 2074 | |
| 2075 | apex_key { |
| 2076 | name: "myapex.key", |
| 2077 | public_key: "testkey.avbpubkey", |
| 2078 | private_key: "testkey.pem", |
| 2079 | } |
| 2080 | |
| 2081 | rust_ffi_shared { |
| 2082 | name: "libfoo.ffi", |
| 2083 | srcs: ["foo.rs"], |
| 2084 | crate_name: "foo", |
| 2085 | apex_available: [ |
| 2086 | "myapex", |
| 2087 | ], |
| 2088 | min_sdk_version: "30", |
| 2089 | } |
| 2090 | `) |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2091 | |
| 2092 | testApexError(t, `module "libfoo".*: should support min_sdk_version\(29\)`, ` |
| 2093 | apex { |
| 2094 | name: "myapex", |
| 2095 | key: "myapex.key", |
| 2096 | java_libs: ["libfoo"], |
| 2097 | min_sdk_version: "29", |
| 2098 | } |
| 2099 | |
| 2100 | apex_key { |
| 2101 | name: "myapex.key", |
| 2102 | public_key: "testkey.avbpubkey", |
| 2103 | private_key: "testkey.pem", |
| 2104 | } |
| 2105 | |
| 2106 | java_import { |
| 2107 | name: "libfoo", |
| 2108 | jars: ["libfoo.jar"], |
| 2109 | apex_available: [ |
| 2110 | "myapex", |
| 2111 | ], |
| 2112 | min_sdk_version: "30", |
| 2113 | } |
| 2114 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 2118 | testApex(t, ` |
| 2119 | apex { |
| 2120 | name: "myapex", |
| 2121 | key: "myapex.key", |
| 2122 | native_shared_libs: ["libfoo"], |
| 2123 | java_libs: ["libbar"], |
| 2124 | min_sdk_version: "29", |
| 2125 | } |
| 2126 | |
| 2127 | apex_key { |
| 2128 | name: "myapex.key", |
| 2129 | public_key: "testkey.avbpubkey", |
| 2130 | private_key: "testkey.pem", |
| 2131 | } |
| 2132 | |
| 2133 | cc_library { |
| 2134 | name: "libfoo", |
| 2135 | srcs: ["mylib.cpp"], |
| 2136 | shared_libs: ["libfoo_dep"], |
| 2137 | apex_available: ["myapex"], |
| 2138 | min_sdk_version: "29", |
| 2139 | } |
| 2140 | |
| 2141 | cc_library { |
| 2142 | name: "libfoo_dep", |
| 2143 | srcs: ["mylib.cpp"], |
| 2144 | apex_available: ["myapex"], |
| 2145 | min_sdk_version: "29", |
| 2146 | } |
| 2147 | |
| 2148 | java_library { |
| 2149 | name: "libbar", |
| 2150 | sdk_version: "current", |
| 2151 | srcs: ["a.java"], |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2152 | static_libs: [ |
| 2153 | "libbar_dep", |
| 2154 | "libbar_import_dep", |
| 2155 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2156 | apex_available: ["myapex"], |
| 2157 | min_sdk_version: "29", |
| 2158 | } |
| 2159 | |
| 2160 | java_library { |
| 2161 | name: "libbar_dep", |
| 2162 | sdk_version: "current", |
| 2163 | srcs: ["a.java"], |
| 2164 | apex_available: ["myapex"], |
| 2165 | min_sdk_version: "29", |
| 2166 | } |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2167 | |
| 2168 | java_import { |
| 2169 | name: "libbar_import_dep", |
| 2170 | jars: ["libbar.jar"], |
| 2171 | apex_available: ["myapex"], |
| 2172 | min_sdk_version: "29", |
| 2173 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2174 | `) |
| 2175 | } |
| 2176 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2177 | func TestJavaStableSdkVersion(t *testing.T) { |
| 2178 | testCases := []struct { |
| 2179 | name string |
| 2180 | expectedError string |
| 2181 | bp string |
| 2182 | }{ |
| 2183 | { |
| 2184 | name: "Non-updatable apex with non-stable dep", |
| 2185 | bp: ` |
| 2186 | apex { |
| 2187 | name: "myapex", |
| 2188 | java_libs: ["myjar"], |
| 2189 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2190 | updatable: false, |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2191 | } |
| 2192 | apex_key { |
| 2193 | name: "myapex.key", |
| 2194 | public_key: "testkey.avbpubkey", |
| 2195 | private_key: "testkey.pem", |
| 2196 | } |
| 2197 | java_library { |
| 2198 | name: "myjar", |
| 2199 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2200 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2201 | apex_available: ["myapex"], |
| 2202 | } |
| 2203 | `, |
| 2204 | }, |
| 2205 | { |
| 2206 | name: "Updatable apex with stable dep", |
| 2207 | bp: ` |
| 2208 | apex { |
| 2209 | name: "myapex", |
| 2210 | java_libs: ["myjar"], |
| 2211 | key: "myapex.key", |
| 2212 | updatable: true, |
| 2213 | min_sdk_version: "29", |
| 2214 | } |
| 2215 | apex_key { |
| 2216 | name: "myapex.key", |
| 2217 | public_key: "testkey.avbpubkey", |
| 2218 | private_key: "testkey.pem", |
| 2219 | } |
| 2220 | java_library { |
| 2221 | name: "myjar", |
| 2222 | srcs: ["foo/bar/MyClass.java"], |
| 2223 | sdk_version: "current", |
| 2224 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2225 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2226 | } |
| 2227 | `, |
| 2228 | }, |
| 2229 | { |
| 2230 | name: "Updatable apex with non-stable dep", |
| 2231 | expectedError: "cannot depend on \"myjar\"", |
| 2232 | bp: ` |
| 2233 | apex { |
| 2234 | name: "myapex", |
| 2235 | java_libs: ["myjar"], |
| 2236 | key: "myapex.key", |
| 2237 | updatable: true, |
| 2238 | } |
| 2239 | apex_key { |
| 2240 | name: "myapex.key", |
| 2241 | public_key: "testkey.avbpubkey", |
| 2242 | private_key: "testkey.pem", |
| 2243 | } |
| 2244 | java_library { |
| 2245 | name: "myjar", |
| 2246 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2247 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2248 | apex_available: ["myapex"], |
| 2249 | } |
| 2250 | `, |
| 2251 | }, |
| 2252 | { |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2253 | name: "Updatable apex with non-stable transitive dep", |
| 2254 | // This is not actually detecting that the transitive dependency is unstable, rather it is |
| 2255 | // detecting that the transitive dependency is building against a wider API surface than the |
| 2256 | // module that depends on it is using. |
Jiyong Park | 670e0f6 | 2021-02-18 13:10:18 +0900 | [diff] [blame] | 2257 | 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] | 2258 | bp: ` |
| 2259 | apex { |
| 2260 | name: "myapex", |
| 2261 | java_libs: ["myjar"], |
| 2262 | key: "myapex.key", |
| 2263 | updatable: true, |
| 2264 | } |
| 2265 | apex_key { |
| 2266 | name: "myapex.key", |
| 2267 | public_key: "testkey.avbpubkey", |
| 2268 | private_key: "testkey.pem", |
| 2269 | } |
| 2270 | java_library { |
| 2271 | name: "myjar", |
| 2272 | srcs: ["foo/bar/MyClass.java"], |
| 2273 | sdk_version: "current", |
| 2274 | apex_available: ["myapex"], |
| 2275 | static_libs: ["transitive-jar"], |
| 2276 | } |
| 2277 | java_library { |
| 2278 | name: "transitive-jar", |
| 2279 | srcs: ["foo/bar/MyClass.java"], |
| 2280 | sdk_version: "core_platform", |
| 2281 | apex_available: ["myapex"], |
| 2282 | } |
| 2283 | `, |
| 2284 | }, |
| 2285 | } |
| 2286 | |
| 2287 | for _, test := range testCases { |
| 2288 | t.Run(test.name, func(t *testing.T) { |
| 2289 | if test.expectedError == "" { |
| 2290 | testApex(t, test.bp) |
| 2291 | } else { |
| 2292 | testApexError(t, test.expectedError, test.bp) |
| 2293 | } |
| 2294 | }) |
| 2295 | } |
| 2296 | } |
| 2297 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2298 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 2299 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2300 | apex { |
| 2301 | name: "myapex", |
| 2302 | key: "myapex.key", |
| 2303 | native_shared_libs: ["mylib"], |
| 2304 | min_sdk_version: "29", |
| 2305 | } |
| 2306 | |
| 2307 | apex_key { |
| 2308 | name: "myapex.key", |
| 2309 | public_key: "testkey.avbpubkey", |
| 2310 | private_key: "testkey.pem", |
| 2311 | } |
| 2312 | |
| 2313 | cc_library { |
| 2314 | name: "mylib", |
| 2315 | srcs: ["mylib.cpp"], |
| 2316 | shared_libs: ["mylib2"], |
| 2317 | system_shared_libs: [], |
| 2318 | stl: "none", |
| 2319 | apex_available: [ |
| 2320 | "myapex", |
| 2321 | ], |
| 2322 | min_sdk_version: "29", |
| 2323 | } |
| 2324 | |
| 2325 | // indirect part of the apex |
| 2326 | cc_library { |
| 2327 | name: "mylib2", |
| 2328 | srcs: ["mylib.cpp"], |
| 2329 | system_shared_libs: [], |
| 2330 | stl: "none", |
| 2331 | apex_available: [ |
| 2332 | "myapex", |
| 2333 | ], |
| 2334 | min_sdk_version: "30", |
| 2335 | } |
| 2336 | `) |
| 2337 | } |
| 2338 | |
| 2339 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 2340 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2341 | apex { |
| 2342 | name: "myapex", |
| 2343 | key: "myapex.key", |
| 2344 | apps: ["AppFoo"], |
| 2345 | min_sdk_version: "29", |
| 2346 | } |
| 2347 | |
| 2348 | apex_key { |
| 2349 | name: "myapex.key", |
| 2350 | public_key: "testkey.avbpubkey", |
| 2351 | private_key: "testkey.pem", |
| 2352 | } |
| 2353 | |
| 2354 | android_app { |
| 2355 | name: "AppFoo", |
| 2356 | srcs: ["foo/bar/MyClass.java"], |
| 2357 | sdk_version: "current", |
| 2358 | min_sdk_version: "29", |
| 2359 | system_modules: "none", |
| 2360 | stl: "none", |
| 2361 | static_libs: ["bar"], |
| 2362 | apex_available: [ "myapex" ], |
| 2363 | } |
| 2364 | |
| 2365 | java_library { |
| 2366 | name: "bar", |
| 2367 | sdk_version: "current", |
| 2368 | srcs: ["a.java"], |
| 2369 | apex_available: [ "myapex" ], |
| 2370 | } |
| 2371 | `) |
| 2372 | } |
| 2373 | |
| 2374 | func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2375 | ctx := testApex(t, ` |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2376 | apex { |
| 2377 | name: "myapex", |
| 2378 | key: "myapex.key", |
| 2379 | native_shared_libs: ["mylib"], |
| 2380 | min_sdk_version: "29", |
| 2381 | } |
| 2382 | |
| 2383 | apex_key { |
| 2384 | name: "myapex.key", |
| 2385 | public_key: "testkey.avbpubkey", |
| 2386 | private_key: "testkey.pem", |
| 2387 | } |
| 2388 | |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2389 | // mylib in myapex will link to mylib2#current |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2390 | // mylib in otherapex will link to mylib2(non-stub) in otherapex as well |
| 2391 | cc_library { |
| 2392 | name: "mylib", |
| 2393 | srcs: ["mylib.cpp"], |
| 2394 | shared_libs: ["mylib2"], |
| 2395 | system_shared_libs: [], |
| 2396 | stl: "none", |
| 2397 | apex_available: ["myapex", "otherapex"], |
| 2398 | min_sdk_version: "29", |
| 2399 | } |
| 2400 | |
| 2401 | cc_library { |
| 2402 | name: "mylib2", |
| 2403 | srcs: ["mylib.cpp"], |
| 2404 | system_shared_libs: [], |
| 2405 | stl: "none", |
| 2406 | apex_available: ["otherapex"], |
| 2407 | stubs: { versions: ["29", "30"] }, |
| 2408 | min_sdk_version: "30", |
| 2409 | } |
| 2410 | |
| 2411 | apex { |
| 2412 | name: "otherapex", |
| 2413 | key: "myapex.key", |
| 2414 | native_shared_libs: ["mylib", "mylib2"], |
| 2415 | min_sdk_version: "30", |
| 2416 | } |
| 2417 | `) |
| 2418 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2419 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2420 | libFlags := ld.Args["libFlags"] |
| 2421 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2422 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2423 | expectLink("mylib", "shared_apex29", "mylib2", "shared_current") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2424 | expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2425 | } |
| 2426 | |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2427 | func TestApexMinSdkVersion_WorksWithSdkCodename(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2428 | withSAsActiveCodeNames := android.FixtureModifyProductVariables( |
| 2429 | func(variables android.FixtureProductVariables) { |
| 2430 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2431 | variables.Platform_version_active_codenames = []string{"S"} |
| 2432 | }, |
| 2433 | ) |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2434 | testApexError(t, `libbar.*: should support min_sdk_version\(S\)`, ` |
| 2435 | apex { |
| 2436 | name: "myapex", |
| 2437 | key: "myapex.key", |
| 2438 | native_shared_libs: ["libfoo"], |
| 2439 | min_sdk_version: "S", |
| 2440 | } |
| 2441 | apex_key { |
| 2442 | name: "myapex.key", |
| 2443 | public_key: "testkey.avbpubkey", |
| 2444 | private_key: "testkey.pem", |
| 2445 | } |
| 2446 | cc_library { |
| 2447 | name: "libfoo", |
| 2448 | shared_libs: ["libbar"], |
| 2449 | apex_available: ["myapex"], |
| 2450 | min_sdk_version: "29", |
| 2451 | } |
| 2452 | cc_library { |
| 2453 | name: "libbar", |
| 2454 | apex_available: ["myapex"], |
| 2455 | } |
| 2456 | `, withSAsActiveCodeNames) |
| 2457 | } |
| 2458 | |
| 2459 | func TestApexMinSdkVersion_WorksWithActiveCodenames(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2460 | withSAsActiveCodeNames := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2461 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2462 | variables.Platform_version_active_codenames = []string{"S", "T"} |
| 2463 | }) |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2464 | ctx := testApex(t, ` |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2465 | apex { |
| 2466 | name: "myapex", |
| 2467 | key: "myapex.key", |
| 2468 | native_shared_libs: ["libfoo"], |
| 2469 | min_sdk_version: "S", |
| 2470 | } |
| 2471 | apex_key { |
| 2472 | name: "myapex.key", |
| 2473 | public_key: "testkey.avbpubkey", |
| 2474 | private_key: "testkey.pem", |
| 2475 | } |
| 2476 | cc_library { |
| 2477 | name: "libfoo", |
| 2478 | shared_libs: ["libbar"], |
| 2479 | apex_available: ["myapex"], |
| 2480 | min_sdk_version: "S", |
| 2481 | } |
| 2482 | cc_library { |
| 2483 | name: "libbar", |
| 2484 | stubs: { |
| 2485 | symbol_file: "libbar.map.txt", |
| 2486 | versions: ["30", "S", "T"], |
| 2487 | }, |
| 2488 | } |
| 2489 | `, withSAsActiveCodeNames) |
| 2490 | |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2491 | // ensure libfoo is linked with current version of libbar stub |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2492 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_apex10000") |
| 2493 | libFlags := libfoo.Rule("ld").Args["libFlags"] |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2494 | ensureContains(t, libFlags, "android_arm64_armv8-a_shared_current/libbar.so") |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2495 | } |
| 2496 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2497 | func TestFilesInSubDir(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2498 | ctx := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2499 | apex { |
| 2500 | name: "myapex", |
| 2501 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2502 | native_shared_libs: ["mylib"], |
| 2503 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2504 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2505 | compile_multilib: "both", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2506 | updatable: false, |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | apex_key { |
| 2510 | name: "myapex.key", |
| 2511 | public_key: "testkey.avbpubkey", |
| 2512 | private_key: "testkey.pem", |
| 2513 | } |
| 2514 | |
| 2515 | prebuilt_etc { |
| 2516 | name: "myetc", |
| 2517 | src: "myprebuilt", |
| 2518 | sub_dir: "foo/bar", |
| 2519 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2520 | |
| 2521 | cc_library { |
| 2522 | name: "mylib", |
| 2523 | srcs: ["mylib.cpp"], |
| 2524 | relative_install_path: "foo/bar", |
| 2525 | system_shared_libs: [], |
| 2526 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2527 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | cc_binary { |
| 2531 | name: "mybin", |
| 2532 | srcs: ["mylib.cpp"], |
| 2533 | relative_install_path: "foo/bar", |
| 2534 | system_shared_libs: [], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2535 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2536 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2537 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2538 | `) |
| 2539 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2540 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2541 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 2542 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2543 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2544 | ensureListContains(t, dirs, "etc") |
| 2545 | ensureListContains(t, dirs, "etc/foo") |
| 2546 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2547 | ensureListContains(t, dirs, "lib64") |
| 2548 | ensureListContains(t, dirs, "lib64/foo") |
| 2549 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 2550 | ensureListContains(t, dirs, "lib") |
| 2551 | ensureListContains(t, dirs, "lib/foo") |
| 2552 | ensureListContains(t, dirs, "lib/foo/bar") |
| 2553 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 2554 | ensureListContains(t, dirs, "bin") |
| 2555 | ensureListContains(t, dirs, "bin/foo") |
| 2556 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2557 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2558 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2559 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2560 | ctx := testApex(t, ` |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2561 | apex { |
| 2562 | name: "myapex", |
| 2563 | key: "myapex.key", |
| 2564 | multilib: { |
| 2565 | both: { |
| 2566 | native_shared_libs: ["mylib"], |
| 2567 | binaries: ["mybin"], |
| 2568 | }, |
| 2569 | }, |
| 2570 | compile_multilib: "both", |
| 2571 | native_bridge_supported: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2572 | updatable: false, |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | apex_key { |
| 2576 | name: "myapex.key", |
| 2577 | public_key: "testkey.avbpubkey", |
| 2578 | private_key: "testkey.pem", |
| 2579 | } |
| 2580 | |
| 2581 | cc_library { |
| 2582 | name: "mylib", |
| 2583 | relative_install_path: "foo/bar", |
| 2584 | system_shared_libs: [], |
| 2585 | stl: "none", |
| 2586 | apex_available: [ "myapex" ], |
| 2587 | native_bridge_supported: true, |
| 2588 | } |
| 2589 | |
| 2590 | cc_binary { |
| 2591 | name: "mybin", |
| 2592 | relative_install_path: "foo/bar", |
| 2593 | system_shared_libs: [], |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2594 | stl: "none", |
| 2595 | apex_available: [ "myapex" ], |
| 2596 | native_bridge_supported: true, |
| 2597 | compile_multilib: "both", // default is "first" for binary |
| 2598 | multilib: { |
| 2599 | lib64: { |
| 2600 | suffix: "64", |
| 2601 | }, |
| 2602 | }, |
| 2603 | } |
| 2604 | `, withNativeBridgeEnabled) |
| 2605 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2606 | "bin/foo/bar/mybin", |
| 2607 | "bin/foo/bar/mybin64", |
| 2608 | "bin/arm/foo/bar/mybin", |
| 2609 | "bin/arm64/foo/bar/mybin64", |
| 2610 | "lib/foo/bar/mylib.so", |
| 2611 | "lib/arm/foo/bar/mylib.so", |
| 2612 | "lib64/foo/bar/mylib.so", |
| 2613 | "lib64/arm64/foo/bar/mylib.so", |
| 2614 | }) |
| 2615 | } |
| 2616 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2617 | func TestUseVendor(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2618 | ctx := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2619 | apex { |
| 2620 | name: "myapex", |
| 2621 | key: "myapex.key", |
| 2622 | native_shared_libs: ["mylib"], |
| 2623 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2624 | updatable: false, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | apex_key { |
| 2628 | name: "myapex.key", |
| 2629 | public_key: "testkey.avbpubkey", |
| 2630 | private_key: "testkey.pem", |
| 2631 | } |
| 2632 | |
| 2633 | cc_library { |
| 2634 | name: "mylib", |
| 2635 | srcs: ["mylib.cpp"], |
| 2636 | shared_libs: ["mylib2"], |
| 2637 | system_shared_libs: [], |
| 2638 | vendor_available: true, |
| 2639 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2640 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | cc_library { |
| 2644 | name: "mylib2", |
| 2645 | srcs: ["mylib.cpp"], |
| 2646 | system_shared_libs: [], |
| 2647 | vendor_available: true, |
| 2648 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2649 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2650 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2651 | `, |
| 2652 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2653 | ) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2654 | |
| 2655 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2656 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2657 | for _, implicit := range i.Implicits { |
| 2658 | inputsList = append(inputsList, implicit.String()) |
| 2659 | } |
| 2660 | } |
| 2661 | inputsString := strings.Join(inputsList, " ") |
| 2662 | |
| 2663 | // 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] | 2664 | ensureContains(t, inputsString, "android_vendor.29_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2665 | 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] | 2666 | |
| 2667 | // ensure that the apex does not include core variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2668 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2669 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2670 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2671 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2672 | func TestUseVendorNotAllowedForSystemApexes(t *testing.T) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2673 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 2674 | apex { |
| 2675 | name: "myapex", |
| 2676 | key: "myapex.key", |
| 2677 | use_vendor: true, |
| 2678 | } |
| 2679 | apex_key { |
| 2680 | name: "myapex.key", |
| 2681 | public_key: "testkey.avbpubkey", |
| 2682 | private_key: "testkey.pem", |
| 2683 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2684 | `, |
| 2685 | setUseVendorAllowListForTest([]string{""}), |
| 2686 | ) |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2687 | // no error with allow list |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2688 | testApex(t, ` |
| 2689 | apex { |
| 2690 | name: "myapex", |
| 2691 | key: "myapex.key", |
| 2692 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2693 | updatable: false, |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2694 | } |
| 2695 | apex_key { |
| 2696 | name: "myapex.key", |
| 2697 | public_key: "testkey.avbpubkey", |
| 2698 | private_key: "testkey.pem", |
| 2699 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2700 | `, |
| 2701 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2702 | ) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2703 | } |
| 2704 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2705 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 2706 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 2707 | apex { |
| 2708 | name: "myapex", |
| 2709 | key: "myapex.key", |
| 2710 | native_shared_libs: ["mylib"], |
| 2711 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2712 | updatable: false, |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | apex_key { |
| 2716 | name: "myapex.key", |
| 2717 | public_key: "testkey.avbpubkey", |
| 2718 | private_key: "testkey.pem", |
| 2719 | } |
| 2720 | |
| 2721 | cc_library { |
| 2722 | name: "mylib", |
| 2723 | srcs: ["mylib.cpp"], |
| 2724 | system_shared_libs: [], |
| 2725 | stl: "none", |
| 2726 | } |
| 2727 | `) |
| 2728 | } |
| 2729 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2730 | func TestVendorApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2731 | ctx := testApex(t, ` |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2732 | apex { |
| 2733 | name: "myapex", |
| 2734 | key: "myapex.key", |
| 2735 | binaries: ["mybin"], |
| 2736 | vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2737 | updatable: false, |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2738 | } |
| 2739 | apex_key { |
| 2740 | name: "myapex.key", |
| 2741 | public_key: "testkey.avbpubkey", |
| 2742 | private_key: "testkey.pem", |
| 2743 | } |
| 2744 | cc_binary { |
| 2745 | name: "mybin", |
| 2746 | vendor: true, |
| 2747 | shared_libs: ["libfoo"], |
| 2748 | } |
| 2749 | cc_library { |
| 2750 | name: "libfoo", |
| 2751 | proprietary: true, |
| 2752 | } |
| 2753 | `) |
| 2754 | |
| 2755 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2756 | "bin/mybin", |
| 2757 | "lib64/libfoo.so", |
| 2758 | // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX |
| 2759 | "lib64/libc++.so", |
| 2760 | }) |
| 2761 | |
| 2762 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2763 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2764 | name := apexBundle.BaseModuleName() |
| 2765 | prefix := "TARGET_" |
| 2766 | var builder strings.Builder |
| 2767 | data.Custom(&builder, name, prefix, "", data) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2768 | androidMk := android.StringRelativeToTop(ctx.Config(), builder.String()) |
| 2769 | installPath := "out/target/product/test_device/vendor/apex" |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 2770 | ensureContains(t, androidMk, "LOCAL_MODULE_PATH := "+installPath) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2771 | |
| 2772 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2773 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2774 | ensureListNotContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2775 | } |
| 2776 | |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2777 | func TestVendorApex_use_vndk_as_stable(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2778 | ctx := testApex(t, ` |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2779 | apex { |
| 2780 | name: "myapex", |
| 2781 | key: "myapex.key", |
| 2782 | binaries: ["mybin"], |
| 2783 | vendor: true, |
| 2784 | use_vndk_as_stable: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2785 | updatable: false, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2786 | } |
| 2787 | apex_key { |
| 2788 | name: "myapex.key", |
| 2789 | public_key: "testkey.avbpubkey", |
| 2790 | private_key: "testkey.pem", |
| 2791 | } |
| 2792 | cc_binary { |
| 2793 | name: "mybin", |
| 2794 | vendor: true, |
| 2795 | shared_libs: ["libvndk", "libvendor"], |
| 2796 | } |
| 2797 | cc_library { |
| 2798 | name: "libvndk", |
| 2799 | vndk: { |
| 2800 | enabled: true, |
| 2801 | }, |
| 2802 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2803 | product_available: true, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2804 | } |
| 2805 | cc_library { |
| 2806 | name: "libvendor", |
| 2807 | vendor: true, |
| 2808 | } |
| 2809 | `) |
| 2810 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2811 | vendorVariant := "android_vendor.29_arm64_armv8-a" |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2812 | |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 2813 | ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_apex10000").Rule("ld") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2814 | libs := names(ldRule.Args["libFlags"]) |
| 2815 | // VNDK libs(libvndk/libc++) as they are |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2816 | ensureListContains(t, libs, "out/soong/.intermediates/libvndk/"+vendorVariant+"_shared/libvndk.so") |
| 2817 | 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] | 2818 | // non-stable Vendor libs as APEX variants |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2819 | ensureListContains(t, libs, "out/soong/.intermediates/libvendor/"+vendorVariant+"_shared_apex10000/libvendor.so") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2820 | |
| 2821 | // VNDK libs are not included when use_vndk_as_stable: true |
| 2822 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2823 | "bin/mybin", |
| 2824 | "lib64/libvendor.so", |
| 2825 | }) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2826 | |
| 2827 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2828 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2829 | ensureListContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2830 | } |
| 2831 | |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2832 | func TestProductVariant(t *testing.T) { |
| 2833 | ctx := testApex(t, ` |
| 2834 | apex { |
| 2835 | name: "myapex", |
| 2836 | key: "myapex.key", |
| 2837 | updatable: false, |
| 2838 | product_specific: true, |
| 2839 | binaries: ["foo"], |
| 2840 | } |
| 2841 | |
| 2842 | apex_key { |
| 2843 | name: "myapex.key", |
| 2844 | public_key: "testkey.avbpubkey", |
| 2845 | private_key: "testkey.pem", |
| 2846 | } |
| 2847 | |
| 2848 | cc_binary { |
| 2849 | name: "foo", |
| 2850 | product_available: true, |
| 2851 | apex_available: ["myapex"], |
| 2852 | srcs: ["foo.cpp"], |
| 2853 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2854 | `, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2855 | variables.ProductVndkVersion = proptools.StringPtr("current") |
| 2856 | }), |
| 2857 | ) |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2858 | |
| 2859 | cflags := strings.Fields( |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2860 | 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] | 2861 | ensureListContains(t, cflags, "-D__ANDROID_VNDK__") |
| 2862 | ensureListContains(t, cflags, "-D__ANDROID_APEX__") |
| 2863 | ensureListContains(t, cflags, "-D__ANDROID_PRODUCT__") |
| 2864 | ensureListNotContains(t, cflags, "-D__ANDROID_VENDOR__") |
| 2865 | } |
| 2866 | |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2867 | func TestApex_withPrebuiltFirmware(t *testing.T) { |
| 2868 | testCases := []struct { |
| 2869 | name string |
| 2870 | additionalProp string |
| 2871 | }{ |
| 2872 | {"system apex with prebuilt_firmware", ""}, |
| 2873 | {"vendor apex with prebuilt_firmware", "vendor: true,"}, |
| 2874 | } |
| 2875 | for _, tc := range testCases { |
| 2876 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2877 | ctx := testApex(t, ` |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2878 | apex { |
| 2879 | name: "myapex", |
| 2880 | key: "myapex.key", |
| 2881 | prebuilts: ["myfirmware"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2882 | updatable: false, |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2883 | `+tc.additionalProp+` |
| 2884 | } |
| 2885 | apex_key { |
| 2886 | name: "myapex.key", |
| 2887 | public_key: "testkey.avbpubkey", |
| 2888 | private_key: "testkey.pem", |
| 2889 | } |
| 2890 | prebuilt_firmware { |
| 2891 | name: "myfirmware", |
| 2892 | src: "myfirmware.bin", |
| 2893 | filename_from_src: true, |
| 2894 | `+tc.additionalProp+` |
| 2895 | } |
| 2896 | `) |
| 2897 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2898 | "etc/firmware/myfirmware.bin", |
| 2899 | }) |
| 2900 | }) |
| 2901 | } |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 2902 | } |
| 2903 | |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2904 | func TestAndroidMk_UseVendorRequired(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2905 | ctx := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2906 | apex { |
| 2907 | name: "myapex", |
| 2908 | key: "myapex.key", |
| 2909 | use_vendor: true, |
| 2910 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2911 | updatable: false, |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | apex_key { |
| 2915 | name: "myapex.key", |
| 2916 | public_key: "testkey.avbpubkey", |
| 2917 | private_key: "testkey.pem", |
| 2918 | } |
| 2919 | |
| 2920 | cc_library { |
| 2921 | name: "mylib", |
| 2922 | vendor_available: true, |
| 2923 | apex_available: ["myapex"], |
| 2924 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2925 | `, |
| 2926 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2927 | ) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2928 | |
| 2929 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2930 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2931 | name := apexBundle.BaseModuleName() |
| 2932 | prefix := "TARGET_" |
| 2933 | var builder strings.Builder |
| 2934 | data.Custom(&builder, name, prefix, "", data) |
| 2935 | androidMk := builder.String() |
| 2936 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc libm libdl\n") |
| 2937 | } |
| 2938 | |
| 2939 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2940 | ctx := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2941 | apex { |
| 2942 | name: "myapex", |
| 2943 | key: "myapex.key", |
| 2944 | vendor: true, |
| 2945 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2946 | updatable: false, |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | apex_key { |
| 2950 | name: "myapex.key", |
| 2951 | public_key: "testkey.avbpubkey", |
| 2952 | private_key: "testkey.pem", |
| 2953 | } |
| 2954 | |
| 2955 | cc_library { |
| 2956 | name: "mylib", |
| 2957 | vendor_available: true, |
| 2958 | } |
| 2959 | `) |
| 2960 | |
| 2961 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2962 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2963 | name := apexBundle.BaseModuleName() |
| 2964 | prefix := "TARGET_" |
| 2965 | var builder strings.Builder |
| 2966 | data.Custom(&builder, name, prefix, "", data) |
| 2967 | androidMk := builder.String() |
| 2968 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc.vendor libm.vendor libdl.vendor\n") |
| 2969 | } |
| 2970 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2971 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2972 | ctx := testApex(t, ` |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2973 | apex { |
| 2974 | name: "myapex", |
| 2975 | key: "myapex.key", |
| 2976 | vintf_fragments: ["fragment.xml"], |
| 2977 | init_rc: ["init.rc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2978 | updatable: false, |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2979 | } |
| 2980 | apex_key { |
| 2981 | name: "myapex.key", |
| 2982 | public_key: "testkey.avbpubkey", |
| 2983 | private_key: "testkey.pem", |
| 2984 | } |
| 2985 | cc_binary { |
| 2986 | name: "mybin", |
| 2987 | } |
| 2988 | `) |
| 2989 | |
| 2990 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2991 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2992 | name := apexBundle.BaseModuleName() |
| 2993 | prefix := "TARGET_" |
| 2994 | var builder strings.Builder |
| 2995 | data.Custom(&builder, name, prefix, "", data) |
| 2996 | androidMk := builder.String() |
Liz Kammer | 7b3dc8a | 2021-04-16 16:41:59 -0400 | [diff] [blame] | 2997 | ensureContains(t, androidMk, "LOCAL_FULL_VINTF_FRAGMENTS := fragment.xml\n") |
Liz Kammer | 0c4f71c | 2021-04-06 10:35:10 -0400 | [diff] [blame] | 2998 | ensureContains(t, androidMk, "LOCAL_FULL_INIT_RC := init.rc\n") |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2999 | } |
| 3000 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3001 | func TestStaticLinking(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3002 | ctx := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3003 | apex { |
| 3004 | name: "myapex", |
| 3005 | key: "myapex.key", |
| 3006 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3007 | updatable: false, |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | apex_key { |
| 3011 | name: "myapex.key", |
| 3012 | public_key: "testkey.avbpubkey", |
| 3013 | private_key: "testkey.pem", |
| 3014 | } |
| 3015 | |
| 3016 | cc_library { |
| 3017 | name: "mylib", |
| 3018 | srcs: ["mylib.cpp"], |
| 3019 | system_shared_libs: [], |
| 3020 | stl: "none", |
| 3021 | stubs: { |
| 3022 | versions: ["1", "2", "3"], |
| 3023 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3024 | apex_available: [ |
| 3025 | "//apex_available:platform", |
| 3026 | "myapex", |
| 3027 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | cc_binary { |
| 3031 | name: "not_in_apex", |
| 3032 | srcs: ["mylib.cpp"], |
| 3033 | static_libs: ["mylib"], |
| 3034 | static_executable: true, |
| 3035 | system_shared_libs: [], |
| 3036 | stl: "none", |
| 3037 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3038 | `) |
| 3039 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3040 | 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] | 3041 | |
| 3042 | // 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] | 3043 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3044 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3045 | |
| 3046 | func TestKeys(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3047 | ctx := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3048 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3049 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3050 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3051 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3052 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3053 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3054 | updatable: false, |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | cc_library { |
| 3058 | name: "mylib", |
| 3059 | srcs: ["mylib.cpp"], |
| 3060 | system_shared_libs: [], |
| 3061 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3062 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | apex_key { |
| 3066 | name: "myapex.key", |
| 3067 | public_key: "testkey.avbpubkey", |
| 3068 | private_key: "testkey.pem", |
| 3069 | } |
| 3070 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3071 | android_app_certificate { |
| 3072 | name: "myapex.certificate", |
| 3073 | certificate: "testkey", |
| 3074 | } |
| 3075 | |
| 3076 | android_app_certificate { |
| 3077 | name: "myapex.certificate.override", |
| 3078 | certificate: "testkey.override", |
| 3079 | } |
| 3080 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3081 | `) |
| 3082 | |
| 3083 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3084 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3085 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 3086 | if keys.publicKeyFile.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 3087 | t.Errorf("public key %q is not %q", keys.publicKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3088 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 3089 | } |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 3090 | if keys.privateKeyFile.String() != "vendor/foo/devkeys/testkey.pem" { |
| 3091 | t.Errorf("private key %q is not %q", keys.privateKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3092 | "vendor/foo/devkeys/testkey.pem") |
| 3093 | } |
| 3094 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3095 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3096 | 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] | 3097 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3098 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3099 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3100 | } |
| 3101 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3102 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3103 | func TestCertificate(t *testing.T) { |
| 3104 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3105 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3106 | apex { |
| 3107 | name: "myapex", |
| 3108 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3109 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3110 | } |
| 3111 | apex_key { |
| 3112 | name: "myapex.key", |
| 3113 | public_key: "testkey.avbpubkey", |
| 3114 | private_key: "testkey.pem", |
| 3115 | }`) |
| 3116 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 3117 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 3118 | if actual := rule.Args["certificates"]; actual != expected { |
| 3119 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3120 | } |
| 3121 | }) |
| 3122 | t.Run("override when unspecified", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3123 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3124 | apex { |
| 3125 | name: "myapex_keytest", |
| 3126 | key: "myapex.key", |
| 3127 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3128 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3129 | } |
| 3130 | apex_key { |
| 3131 | name: "myapex.key", |
| 3132 | public_key: "testkey.avbpubkey", |
| 3133 | private_key: "testkey.pem", |
| 3134 | } |
| 3135 | android_app_certificate { |
| 3136 | name: "myapex.certificate.override", |
| 3137 | certificate: "testkey.override", |
| 3138 | }`) |
| 3139 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 3140 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 3141 | if actual := rule.Args["certificates"]; actual != expected { |
| 3142 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3143 | } |
| 3144 | }) |
| 3145 | 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] | 3146 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3147 | apex { |
| 3148 | name: "myapex", |
| 3149 | key: "myapex.key", |
| 3150 | certificate: ":myapex.certificate", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3151 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3152 | } |
| 3153 | apex_key { |
| 3154 | name: "myapex.key", |
| 3155 | public_key: "testkey.avbpubkey", |
| 3156 | private_key: "testkey.pem", |
| 3157 | } |
| 3158 | android_app_certificate { |
| 3159 | name: "myapex.certificate", |
| 3160 | certificate: "testkey", |
| 3161 | }`) |
| 3162 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 3163 | expected := "testkey.x509.pem testkey.pk8" |
| 3164 | if actual := rule.Args["certificates"]; actual != expected { |
| 3165 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3166 | } |
| 3167 | }) |
| 3168 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3169 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3170 | apex { |
| 3171 | name: "myapex_keytest", |
| 3172 | key: "myapex.key", |
| 3173 | file_contexts: ":myapex-file_contexts", |
| 3174 | certificate: ":myapex.certificate", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3175 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3176 | } |
| 3177 | apex_key { |
| 3178 | name: "myapex.key", |
| 3179 | public_key: "testkey.avbpubkey", |
| 3180 | private_key: "testkey.pem", |
| 3181 | } |
| 3182 | android_app_certificate { |
| 3183 | name: "myapex.certificate.override", |
| 3184 | certificate: "testkey.override", |
| 3185 | }`) |
| 3186 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 3187 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 3188 | if actual := rule.Args["certificates"]; actual != expected { |
| 3189 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3190 | } |
| 3191 | }) |
| 3192 | 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] | 3193 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3194 | apex { |
| 3195 | name: "myapex", |
| 3196 | key: "myapex.key", |
| 3197 | certificate: "testkey", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3198 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3199 | } |
| 3200 | apex_key { |
| 3201 | name: "myapex.key", |
| 3202 | public_key: "testkey.avbpubkey", |
| 3203 | private_key: "testkey.pem", |
| 3204 | }`) |
| 3205 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 3206 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 3207 | if actual := rule.Args["certificates"]; actual != expected { |
| 3208 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3209 | } |
| 3210 | }) |
| 3211 | t.Run("override when specified as <name>", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3212 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3213 | apex { |
| 3214 | name: "myapex_keytest", |
| 3215 | key: "myapex.key", |
| 3216 | file_contexts: ":myapex-file_contexts", |
| 3217 | certificate: "testkey", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3218 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3219 | } |
| 3220 | apex_key { |
| 3221 | name: "myapex.key", |
| 3222 | public_key: "testkey.avbpubkey", |
| 3223 | private_key: "testkey.pem", |
| 3224 | } |
| 3225 | android_app_certificate { |
| 3226 | name: "myapex.certificate.override", |
| 3227 | certificate: "testkey.override", |
| 3228 | }`) |
| 3229 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 3230 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 3231 | if actual := rule.Args["certificates"]; actual != expected { |
| 3232 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3233 | } |
| 3234 | }) |
| 3235 | } |
| 3236 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3237 | func TestMacro(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3238 | ctx := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3239 | apex { |
| 3240 | name: "myapex", |
| 3241 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3242 | native_shared_libs: ["mylib", "mylib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3243 | updatable: false, |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | apex { |
| 3247 | name: "otherapex", |
| 3248 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3249 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3250 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | apex_key { |
| 3254 | name: "myapex.key", |
| 3255 | public_key: "testkey.avbpubkey", |
| 3256 | private_key: "testkey.pem", |
| 3257 | } |
| 3258 | |
| 3259 | cc_library { |
| 3260 | name: "mylib", |
| 3261 | srcs: ["mylib.cpp"], |
| 3262 | system_shared_libs: [], |
| 3263 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3264 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3265 | "myapex", |
| 3266 | "otherapex", |
| 3267 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3268 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3269 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3270 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3271 | cc_library { |
| 3272 | name: "mylib2", |
| 3273 | srcs: ["mylib.cpp"], |
| 3274 | system_shared_libs: [], |
| 3275 | stl: "none", |
| 3276 | apex_available: [ |
| 3277 | "myapex", |
| 3278 | "otherapex", |
| 3279 | ], |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3280 | static_libs: ["mylib3"], |
| 3281 | recovery_available: true, |
| 3282 | min_sdk_version: "29", |
| 3283 | } |
| 3284 | cc_library { |
| 3285 | name: "mylib3", |
| 3286 | srcs: ["mylib.cpp"], |
| 3287 | system_shared_libs: [], |
| 3288 | stl: "none", |
| 3289 | apex_available: [ |
| 3290 | "myapex", |
| 3291 | "otherapex", |
| 3292 | ], |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3293 | use_apex_name_macro: true, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3294 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3295 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3296 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3297 | `) |
| 3298 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3299 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3300 | 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] | 3301 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3302 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3303 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3304 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3305 | 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] | 3306 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3307 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3308 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3309 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3310 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3311 | 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] | 3312 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3313 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3314 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3315 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3316 | // When a cc_library sets use_apex_name_macro: true each apex gets a unique variant and |
| 3317 | // each variant defines additional macros to distinguish which apex variant it is built for |
| 3318 | |
| 3319 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3320 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3321 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3322 | |
| 3323 | // APEX variant has __ANDROID_APEX__ defined |
| 3324 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 3325 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3326 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3327 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3328 | |
| 3329 | // APEX variant has __ANDROID_APEX__ defined |
| 3330 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 3331 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3332 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3333 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3334 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3335 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3336 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3337 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3338 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3339 | |
| 3340 | // When a dependency of a cc_library sets use_apex_name_macro: true each apex gets a unique |
| 3341 | // variant. |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3342 | |
| 3343 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3344 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3345 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3346 | |
| 3347 | // APEX variant has __ANDROID_APEX__ defined |
| 3348 | 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] | 3349 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3350 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3351 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3352 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3353 | // APEX variant has __ANDROID_APEX__ defined |
| 3354 | 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] | 3355 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3356 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3357 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3358 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3359 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3360 | 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] | 3361 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3362 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3363 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3364 | |
| 3365 | func TestHeaderLibsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3366 | ctx := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3367 | apex { |
| 3368 | name: "myapex", |
| 3369 | key: "myapex.key", |
| 3370 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3371 | updatable: false, |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | apex_key { |
| 3375 | name: "myapex.key", |
| 3376 | public_key: "testkey.avbpubkey", |
| 3377 | private_key: "testkey.pem", |
| 3378 | } |
| 3379 | |
| 3380 | cc_library_headers { |
| 3381 | name: "mylib_headers", |
| 3382 | export_include_dirs: ["my_include"], |
| 3383 | system_shared_libs: [], |
| 3384 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3385 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | cc_library { |
| 3389 | name: "mylib", |
| 3390 | srcs: ["mylib.cpp"], |
| 3391 | system_shared_libs: [], |
| 3392 | stl: "none", |
| 3393 | header_libs: ["mylib_headers"], |
| 3394 | export_header_lib_headers: ["mylib_headers"], |
| 3395 | stubs: { |
| 3396 | versions: ["1", "2", "3"], |
| 3397 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3398 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | cc_library { |
| 3402 | name: "otherlib", |
| 3403 | srcs: ["mylib.cpp"], |
| 3404 | system_shared_libs: [], |
| 3405 | stl: "none", |
| 3406 | shared_libs: ["mylib"], |
| 3407 | } |
| 3408 | `) |
| 3409 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3410 | 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] | 3411 | |
| 3412 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 3413 | ensureContains(t, cFlags, "-Imy_include") |
| 3414 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3415 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3416 | type fileInApex struct { |
| 3417 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3418 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3419 | isLink bool |
| 3420 | } |
| 3421 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3422 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3423 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3424 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3425 | copyCmds := apexRule.Args["copy_commands"] |
| 3426 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3427 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3428 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 3429 | cmd = strings.TrimSpace(cmd) |
| 3430 | if cmd == "" { |
| 3431 | continue |
| 3432 | } |
| 3433 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3434 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3435 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3436 | switch terms[0] { |
| 3437 | case "mkdir": |
| 3438 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3439 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3440 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 3441 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3442 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3443 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3444 | isLink = false |
| 3445 | case "ln": |
| 3446 | if len(terms) != 3 && len(terms) != 4 { |
| 3447 | // ln LINK TARGET or ln -s LINK TARGET |
| 3448 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 3449 | } |
| 3450 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3451 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3452 | isLink = true |
| 3453 | default: |
| 3454 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 3455 | } |
| 3456 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3457 | index := strings.Index(dst, imageApexDir) |
| 3458 | if index == -1 { |
| 3459 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 3460 | } |
| 3461 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3462 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3463 | } |
| 3464 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3465 | return ret |
| 3466 | } |
| 3467 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3468 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 3469 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3470 | var failed bool |
| 3471 | var surplus []string |
| 3472 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3473 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3474 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3475 | for _, expected := range files { |
| 3476 | if matched, _ := path.Match(expected, file.path); matched { |
| 3477 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3478 | mactchFound = true |
| 3479 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3480 | } |
| 3481 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3482 | if !mactchFound { |
| 3483 | surplus = append(surplus, file.path) |
| 3484 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3485 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3486 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3487 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3488 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3489 | t.Log("surplus files", surplus) |
| 3490 | failed = true |
| 3491 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3492 | |
| 3493 | if len(files) > len(filesMatched) { |
| 3494 | var missing []string |
| 3495 | for _, expected := range files { |
| 3496 | if !filesMatched[expected] { |
| 3497 | missing = append(missing, expected) |
| 3498 | } |
| 3499 | } |
| 3500 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3501 | t.Log("missing files", missing) |
| 3502 | failed = true |
| 3503 | } |
| 3504 | if failed { |
| 3505 | t.Fail() |
| 3506 | } |
| 3507 | } |
| 3508 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3509 | func TestVndkApexCurrent(t *testing.T) { |
Jooyung Han | 7d6e79b | 2021-06-24 01:53:43 +0900 | [diff] [blame] | 3510 | commonFiles := []string{ |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3511 | "lib/libc++.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3512 | "lib64/libc++.so", |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 3513 | "etc/llndk.libraries.29.txt", |
| 3514 | "etc/vndkcore.libraries.29.txt", |
| 3515 | "etc/vndksp.libraries.29.txt", |
| 3516 | "etc/vndkprivate.libraries.29.txt", |
| 3517 | "etc/vndkproduct.libraries.29.txt", |
Jooyung Han | 7d6e79b | 2021-06-24 01:53:43 +0900 | [diff] [blame] | 3518 | } |
| 3519 | testCases := []struct { |
| 3520 | vndkVersion string |
| 3521 | expectedFiles []string |
| 3522 | }{ |
| 3523 | { |
| 3524 | vndkVersion: "current", |
| 3525 | expectedFiles: append(commonFiles, |
| 3526 | "lib/libvndk.so", |
| 3527 | "lib/libvndksp.so", |
| 3528 | "lib64/libvndk.so", |
| 3529 | "lib64/libvndksp.so"), |
| 3530 | }, |
| 3531 | { |
| 3532 | vndkVersion: "", |
| 3533 | expectedFiles: append(commonFiles, |
| 3534 | // Legacy VNDK APEX contains only VNDK-SP files (of core variant) |
| 3535 | "lib/libvndksp.so", |
| 3536 | "lib64/libvndksp.so"), |
| 3537 | }, |
| 3538 | } |
| 3539 | for _, tc := range testCases { |
| 3540 | t.Run("VNDK.current with DeviceVndkVersion="+tc.vndkVersion, func(t *testing.T) { |
| 3541 | ctx := testApex(t, ` |
| 3542 | apex_vndk { |
| 3543 | name: "com.android.vndk.current", |
| 3544 | key: "com.android.vndk.current.key", |
| 3545 | updatable: false, |
| 3546 | } |
| 3547 | |
| 3548 | apex_key { |
| 3549 | name: "com.android.vndk.current.key", |
| 3550 | public_key: "testkey.avbpubkey", |
| 3551 | private_key: "testkey.pem", |
| 3552 | } |
| 3553 | |
| 3554 | cc_library { |
| 3555 | name: "libvndk", |
| 3556 | srcs: ["mylib.cpp"], |
| 3557 | vendor_available: true, |
| 3558 | product_available: true, |
| 3559 | vndk: { |
| 3560 | enabled: true, |
| 3561 | }, |
| 3562 | system_shared_libs: [], |
| 3563 | stl: "none", |
| 3564 | apex_available: [ "com.android.vndk.current" ], |
| 3565 | } |
| 3566 | |
| 3567 | cc_library { |
| 3568 | name: "libvndksp", |
| 3569 | srcs: ["mylib.cpp"], |
| 3570 | vendor_available: true, |
| 3571 | product_available: true, |
| 3572 | vndk: { |
| 3573 | enabled: true, |
| 3574 | support_system_process: true, |
| 3575 | }, |
| 3576 | system_shared_libs: [], |
| 3577 | stl: "none", |
| 3578 | apex_available: [ "com.android.vndk.current" ], |
| 3579 | } |
| 3580 | |
| 3581 | // VNDK-Ext should not cause any problems |
| 3582 | |
| 3583 | cc_library { |
| 3584 | name: "libvndk.ext", |
| 3585 | srcs: ["mylib2.cpp"], |
| 3586 | vendor: true, |
| 3587 | vndk: { |
| 3588 | enabled: true, |
| 3589 | extends: "libvndk", |
| 3590 | }, |
| 3591 | system_shared_libs: [], |
| 3592 | stl: "none", |
| 3593 | } |
| 3594 | |
| 3595 | cc_library { |
| 3596 | name: "libvndksp.ext", |
| 3597 | srcs: ["mylib2.cpp"], |
| 3598 | vendor: true, |
| 3599 | vndk: { |
| 3600 | enabled: true, |
| 3601 | support_system_process: true, |
| 3602 | extends: "libvndksp", |
| 3603 | }, |
| 3604 | system_shared_libs: [], |
| 3605 | stl: "none", |
| 3606 | } |
| 3607 | `+vndkLibrariesTxtFiles("current"), android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 3608 | variables.DeviceVndkVersion = proptools.StringPtr(tc.vndkVersion) |
| 3609 | })) |
| 3610 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", tc.expectedFiles) |
| 3611 | }) |
| 3612 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3613 | } |
| 3614 | |
| 3615 | func TestVndkApexWithPrebuilt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3616 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3617 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3618 | name: "com.android.vndk.current", |
| 3619 | key: "com.android.vndk.current.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3620 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3624 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3625 | public_key: "testkey.avbpubkey", |
| 3626 | private_key: "testkey.pem", |
| 3627 | } |
| 3628 | |
| 3629 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3630 | name: "libvndk", |
| 3631 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3632 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3633 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3634 | vndk: { |
| 3635 | enabled: true, |
| 3636 | }, |
| 3637 | system_shared_libs: [], |
| 3638 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3639 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3640 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3641 | |
| 3642 | cc_prebuilt_library_shared { |
| 3643 | name: "libvndk.arm", |
| 3644 | srcs: ["libvndk.arm.so"], |
| 3645 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3646 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3647 | vndk: { |
| 3648 | enabled: true, |
| 3649 | }, |
| 3650 | enabled: false, |
| 3651 | arch: { |
| 3652 | arm: { |
| 3653 | enabled: true, |
| 3654 | }, |
| 3655 | }, |
| 3656 | system_shared_libs: [], |
| 3657 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3658 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3659 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3660 | `+vndkLibrariesTxtFiles("current"), |
| 3661 | withFiles(map[string][]byte{ |
| 3662 | "libvndk.so": nil, |
| 3663 | "libvndk.arm.so": nil, |
| 3664 | })) |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3665 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3666 | "lib/libvndk.so", |
| 3667 | "lib/libvndk.arm.so", |
| 3668 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3669 | "lib/libc++.so", |
| 3670 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3671 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3672 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3673 | } |
| 3674 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3675 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 3676 | for _, v := range vers { |
| 3677 | if v == "current" { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3678 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3679 | result += ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 3680 | ` + txt + `_libraries_txt { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3681 | name: "` + txt + `.libraries.txt", |
| 3682 | } |
| 3683 | ` |
| 3684 | } |
| 3685 | } else { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3686 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3687 | result += ` |
| 3688 | prebuilt_etc { |
| 3689 | name: "` + txt + `.libraries.` + v + `.txt", |
| 3690 | src: "dummy.txt", |
| 3691 | } |
| 3692 | ` |
| 3693 | } |
| 3694 | } |
| 3695 | } |
| 3696 | return |
| 3697 | } |
| 3698 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3699 | func TestVndkApexVersion(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3700 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3701 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3702 | name: "com.android.vndk.v27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3703 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3704 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3705 | vndk_version: "27", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3706 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3707 | } |
| 3708 | |
| 3709 | apex_key { |
| 3710 | name: "myapex.key", |
| 3711 | public_key: "testkey.avbpubkey", |
| 3712 | private_key: "testkey.pem", |
| 3713 | } |
| 3714 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3715 | vndk_prebuilt_shared { |
| 3716 | name: "libvndk27", |
| 3717 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3718 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3719 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3720 | vndk: { |
| 3721 | enabled: true, |
| 3722 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3723 | target_arch: "arm64", |
| 3724 | arch: { |
| 3725 | arm: { |
| 3726 | srcs: ["libvndk27_arm.so"], |
| 3727 | }, |
| 3728 | arm64: { |
| 3729 | srcs: ["libvndk27_arm64.so"], |
| 3730 | }, |
| 3731 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3732 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | vndk_prebuilt_shared { |
| 3736 | name: "libvndk27", |
| 3737 | version: "27", |
| 3738 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3739 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3740 | vndk: { |
| 3741 | enabled: true, |
| 3742 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3743 | target_arch: "x86_64", |
| 3744 | arch: { |
| 3745 | x86: { |
| 3746 | srcs: ["libvndk27_x86.so"], |
| 3747 | }, |
| 3748 | x86_64: { |
| 3749 | srcs: ["libvndk27_x86_64.so"], |
| 3750 | }, |
| 3751 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3752 | } |
| 3753 | `+vndkLibrariesTxtFiles("27"), |
| 3754 | withFiles(map[string][]byte{ |
| 3755 | "libvndk27_arm.so": nil, |
| 3756 | "libvndk27_arm64.so": nil, |
| 3757 | "libvndk27_x86.so": nil, |
| 3758 | "libvndk27_x86_64.so": nil, |
| 3759 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3760 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3761 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3762 | "lib/libvndk27_arm.so", |
| 3763 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3764 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3765 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3766 | } |
| 3767 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3768 | func TestVndkApexNameRule(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3769 | ctx := testApex(t, ` |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3770 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3771 | name: "com.android.vndk.current", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3772 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3773 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3774 | updatable: false, |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3775 | } |
| 3776 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3777 | name: "com.android.vndk.v28", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3778 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3779 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3780 | vndk_version: "28", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3781 | updatable: false, |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3782 | } |
| 3783 | apex_key { |
| 3784 | name: "myapex.key", |
| 3785 | public_key: "testkey.avbpubkey", |
| 3786 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3787 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3788 | |
| 3789 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3790 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3791 | actual := proptools.String(bundle.properties.Apex_name) |
| 3792 | if !reflect.DeepEqual(actual, expected) { |
| 3793 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3794 | } |
| 3795 | } |
| 3796 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 3797 | assertApexName("com.android.vndk.v29", "com.android.vndk.current") |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3798 | assertApexName("com.android.vndk.v28", "com.android.vndk.v28") |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3799 | } |
| 3800 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3801 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3802 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3803 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3804 | name: "com.android.vndk.current", |
| 3805 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3806 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3807 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3811 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3812 | public_key: "testkey.avbpubkey", |
| 3813 | private_key: "testkey.pem", |
| 3814 | } |
| 3815 | |
| 3816 | cc_library { |
| 3817 | name: "libvndk", |
| 3818 | srcs: ["mylib.cpp"], |
| 3819 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3820 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3821 | native_bridge_supported: true, |
| 3822 | host_supported: true, |
| 3823 | vndk: { |
| 3824 | enabled: true, |
| 3825 | }, |
| 3826 | system_shared_libs: [], |
| 3827 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3828 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3829 | } |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3830 | `+vndkLibrariesTxtFiles("current"), |
| 3831 | withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3832 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3833 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3834 | "lib/libvndk.so", |
| 3835 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3836 | "lib/libc++.so", |
| 3837 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3838 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3839 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3843 | 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] | 3844 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3845 | name: "com.android.vndk.current", |
| 3846 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3847 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3848 | native_bridge_supported: true, |
| 3849 | } |
| 3850 | |
| 3851 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3852 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3853 | public_key: "testkey.avbpubkey", |
| 3854 | private_key: "testkey.pem", |
| 3855 | } |
| 3856 | |
| 3857 | cc_library { |
| 3858 | name: "libvndk", |
| 3859 | srcs: ["mylib.cpp"], |
| 3860 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3861 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3862 | native_bridge_supported: true, |
| 3863 | host_supported: true, |
| 3864 | vndk: { |
| 3865 | enabled: true, |
| 3866 | }, |
| 3867 | system_shared_libs: [], |
| 3868 | stl: "none", |
| 3869 | } |
| 3870 | `) |
| 3871 | } |
| 3872 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3873 | func TestVndkApexWithBinder32(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3874 | ctx := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3875 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3876 | name: "com.android.vndk.v27", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3877 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3878 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3879 | vndk_version: "27", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3880 | updatable: false, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | apex_key { |
| 3884 | name: "myapex.key", |
| 3885 | public_key: "testkey.avbpubkey", |
| 3886 | private_key: "testkey.pem", |
| 3887 | } |
| 3888 | |
| 3889 | vndk_prebuilt_shared { |
| 3890 | name: "libvndk27", |
| 3891 | version: "27", |
| 3892 | target_arch: "arm", |
| 3893 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3894 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3895 | vndk: { |
| 3896 | enabled: true, |
| 3897 | }, |
| 3898 | arch: { |
| 3899 | arm: { |
| 3900 | srcs: ["libvndk27.so"], |
| 3901 | } |
| 3902 | }, |
| 3903 | } |
| 3904 | |
| 3905 | vndk_prebuilt_shared { |
| 3906 | name: "libvndk27", |
| 3907 | version: "27", |
| 3908 | target_arch: "arm", |
| 3909 | binder32bit: true, |
| 3910 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3911 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3912 | vndk: { |
| 3913 | enabled: true, |
| 3914 | }, |
| 3915 | arch: { |
| 3916 | arm: { |
| 3917 | srcs: ["libvndk27binder32.so"], |
| 3918 | } |
| 3919 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3920 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3921 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3922 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3923 | withFiles(map[string][]byte{ |
| 3924 | "libvndk27.so": nil, |
| 3925 | "libvndk27binder32.so": nil, |
| 3926 | }), |
| 3927 | withBinder32bit, |
| 3928 | withTargets(map[android.OsType][]android.Target{ |
| 3929 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3930 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3931 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3932 | }, |
| 3933 | }), |
| 3934 | ) |
| 3935 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3936 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3937 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3938 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3939 | }) |
| 3940 | } |
| 3941 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3942 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3943 | ctx := testApex(t, ` |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3944 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3945 | name: "com.android.vndk.current", |
| 3946 | key: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3947 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3948 | updatable: false, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3949 | } |
| 3950 | |
| 3951 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3952 | name: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3953 | public_key: "testkey.avbpubkey", |
| 3954 | private_key: "testkey.pem", |
| 3955 | } |
| 3956 | |
| 3957 | cc_library { |
| 3958 | name: "libz", |
| 3959 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3960 | product_available: true, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3961 | vndk: { |
| 3962 | enabled: true, |
| 3963 | }, |
| 3964 | stubs: { |
| 3965 | symbol_file: "libz.map.txt", |
| 3966 | versions: ["30"], |
| 3967 | } |
| 3968 | } |
| 3969 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3970 | "libz.map.txt": nil, |
| 3971 | })) |
| 3972 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3973 | apexManifestRule := ctx.ModuleForTests("com.android.vndk.current", "android_common_image").Rule("apexManifestRule") |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3974 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3975 | ensureListEmpty(t, provideNativeLibs) |
| 3976 | } |
| 3977 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3978 | func TestDependenciesInApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3979 | ctx := testApex(t, ` |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3980 | apex { |
| 3981 | name: "myapex_nodep", |
| 3982 | key: "myapex.key", |
| 3983 | native_shared_libs: ["lib_nodep"], |
| 3984 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3985 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3986 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | apex { |
| 3990 | name: "myapex_dep", |
| 3991 | key: "myapex.key", |
| 3992 | native_shared_libs: ["lib_dep"], |
| 3993 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3994 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3995 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | apex { |
| 3999 | name: "myapex_provider", |
| 4000 | key: "myapex.key", |
| 4001 | native_shared_libs: ["libfoo"], |
| 4002 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4003 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4004 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | apex { |
| 4008 | name: "myapex_selfcontained", |
| 4009 | key: "myapex.key", |
| 4010 | native_shared_libs: ["lib_dep", "libfoo"], |
| 4011 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4012 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4013 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | apex_key { |
| 4017 | name: "myapex.key", |
| 4018 | public_key: "testkey.avbpubkey", |
| 4019 | private_key: "testkey.pem", |
| 4020 | } |
| 4021 | |
| 4022 | cc_library { |
| 4023 | name: "lib_nodep", |
| 4024 | srcs: ["mylib.cpp"], |
| 4025 | system_shared_libs: [], |
| 4026 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4027 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | cc_library { |
| 4031 | name: "lib_dep", |
| 4032 | srcs: ["mylib.cpp"], |
| 4033 | shared_libs: ["libfoo"], |
| 4034 | system_shared_libs: [], |
| 4035 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4036 | apex_available: [ |
| 4037 | "myapex_dep", |
| 4038 | "myapex_provider", |
| 4039 | "myapex_selfcontained", |
| 4040 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | cc_library { |
| 4044 | name: "libfoo", |
| 4045 | srcs: ["mytest.cpp"], |
| 4046 | stubs: { |
| 4047 | versions: ["1"], |
| 4048 | }, |
| 4049 | system_shared_libs: [], |
| 4050 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4051 | apex_available: [ |
| 4052 | "myapex_provider", |
| 4053 | "myapex_selfcontained", |
| 4054 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4055 | } |
| 4056 | `) |
| 4057 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4058 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4059 | var provideNativeLibs, requireNativeLibs []string |
| 4060 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4061 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4062 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 4063 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4064 | ensureListEmpty(t, provideNativeLibs) |
| 4065 | ensureListEmpty(t, requireNativeLibs) |
| 4066 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4067 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4068 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 4069 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4070 | ensureListEmpty(t, provideNativeLibs) |
| 4071 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 4072 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4073 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4074 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 4075 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4076 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 4077 | ensureListEmpty(t, requireNativeLibs) |
| 4078 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4079 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4080 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 4081 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4082 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 4083 | ensureListEmpty(t, requireNativeLibs) |
| 4084 | } |
| 4085 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4086 | func TestApexName(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4087 | ctx := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4088 | apex { |
| 4089 | name: "myapex", |
| 4090 | key: "myapex.key", |
| 4091 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 4092 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4093 | updatable: false, |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | apex_key { |
| 4097 | name: "myapex.key", |
| 4098 | public_key: "testkey.avbpubkey", |
| 4099 | private_key: "testkey.pem", |
| 4100 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 4101 | |
| 4102 | cc_library { |
| 4103 | name: "mylib", |
| 4104 | srcs: ["mylib.cpp"], |
| 4105 | system_shared_libs: [], |
| 4106 | stl: "none", |
| 4107 | apex_available: [ |
| 4108 | "//apex_available:platform", |
| 4109 | "myapex", |
| 4110 | ], |
| 4111 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4112 | `) |
| 4113 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 4114 | module := ctx.ModuleForTests("myapex", "android_common_com.android.myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4115 | apexManifestRule := module.Rule("apexManifestRule") |
| 4116 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 4117 | apexRule := module.Rule("apexRule") |
| 4118 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 4119 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 4120 | apexBundle := module.Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4121 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 4122 | name := apexBundle.BaseModuleName() |
| 4123 | prefix := "TARGET_" |
| 4124 | var builder strings.Builder |
| 4125 | data.Custom(&builder, name, prefix, "", data) |
| 4126 | androidMk := builder.String() |
| 4127 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 4128 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4129 | } |
| 4130 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4131 | func TestNonTestApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4132 | ctx := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4133 | apex { |
| 4134 | name: "myapex", |
| 4135 | key: "myapex.key", |
| 4136 | native_shared_libs: ["mylib_common"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4137 | updatable: false, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4138 | } |
| 4139 | |
| 4140 | apex_key { |
| 4141 | name: "myapex.key", |
| 4142 | public_key: "testkey.avbpubkey", |
| 4143 | private_key: "testkey.pem", |
| 4144 | } |
| 4145 | |
| 4146 | cc_library { |
| 4147 | name: "mylib_common", |
| 4148 | srcs: ["mylib.cpp"], |
| 4149 | system_shared_libs: [], |
| 4150 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4151 | apex_available: [ |
| 4152 | "//apex_available:platform", |
| 4153 | "myapex", |
| 4154 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4155 | } |
| 4156 | `) |
| 4157 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4158 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4159 | apexRule := module.Rule("apexRule") |
| 4160 | copyCmds := apexRule.Args["copy_commands"] |
| 4161 | |
| 4162 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 4163 | t.Log("Apex was a test apex!") |
| 4164 | t.Fail() |
| 4165 | } |
| 4166 | // Ensure that main rule creates an output |
| 4167 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 4168 | |
| 4169 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4170 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4171 | |
| 4172 | // Ensure that both direct and indirect deps are copied into apex |
| 4173 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 4174 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4175 | // Ensure that the platform variant ends with _shared |
| 4176 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4177 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 4178 | 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] | 4179 | t.Log("Found mylib_common not in any apex!") |
| 4180 | t.Fail() |
| 4181 | } |
| 4182 | } |
| 4183 | |
| 4184 | func TestTestApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4185 | ctx := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4186 | apex_test { |
| 4187 | name: "myapex", |
| 4188 | key: "myapex.key", |
| 4189 | native_shared_libs: ["mylib_common_test"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4190 | updatable: false, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | apex_key { |
| 4194 | name: "myapex.key", |
| 4195 | public_key: "testkey.avbpubkey", |
| 4196 | private_key: "testkey.pem", |
| 4197 | } |
| 4198 | |
| 4199 | cc_library { |
| 4200 | name: "mylib_common_test", |
| 4201 | srcs: ["mylib.cpp"], |
| 4202 | system_shared_libs: [], |
| 4203 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4204 | // TODO: remove //apex_available:platform |
| 4205 | apex_available: [ |
| 4206 | "//apex_available:platform", |
| 4207 | "myapex", |
| 4208 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4209 | } |
| 4210 | `) |
| 4211 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4212 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4213 | apexRule := module.Rule("apexRule") |
| 4214 | copyCmds := apexRule.Args["copy_commands"] |
| 4215 | |
| 4216 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 4217 | t.Log("Apex was not a test apex!") |
| 4218 | t.Fail() |
| 4219 | } |
| 4220 | // Ensure that main rule creates an output |
| 4221 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 4222 | |
| 4223 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4224 | 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] | 4225 | |
| 4226 | // Ensure that both direct and indirect deps are copied into apex |
| 4227 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 4228 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4229 | // Ensure that the platform variant ends with _shared |
| 4230 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4231 | } |
| 4232 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4233 | func TestApexWithTarget(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4234 | ctx := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4235 | apex { |
| 4236 | name: "myapex", |
| 4237 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4238 | updatable: false, |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4239 | multilib: { |
| 4240 | first: { |
| 4241 | native_shared_libs: ["mylib_common"], |
| 4242 | } |
| 4243 | }, |
| 4244 | target: { |
| 4245 | android: { |
| 4246 | multilib: { |
| 4247 | first: { |
| 4248 | native_shared_libs: ["mylib"], |
| 4249 | } |
| 4250 | } |
| 4251 | }, |
| 4252 | host: { |
| 4253 | multilib: { |
| 4254 | first: { |
| 4255 | native_shared_libs: ["mylib2"], |
| 4256 | } |
| 4257 | } |
| 4258 | } |
| 4259 | } |
| 4260 | } |
| 4261 | |
| 4262 | apex_key { |
| 4263 | name: "myapex.key", |
| 4264 | public_key: "testkey.avbpubkey", |
| 4265 | private_key: "testkey.pem", |
| 4266 | } |
| 4267 | |
| 4268 | cc_library { |
| 4269 | name: "mylib", |
| 4270 | srcs: ["mylib.cpp"], |
| 4271 | system_shared_libs: [], |
| 4272 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4273 | // TODO: remove //apex_available:platform |
| 4274 | apex_available: [ |
| 4275 | "//apex_available:platform", |
| 4276 | "myapex", |
| 4277 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | cc_library { |
| 4281 | name: "mylib_common", |
| 4282 | srcs: ["mylib.cpp"], |
| 4283 | system_shared_libs: [], |
| 4284 | stl: "none", |
| 4285 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4286 | // TODO: remove //apex_available:platform |
| 4287 | apex_available: [ |
| 4288 | "//apex_available:platform", |
| 4289 | "myapex", |
| 4290 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4291 | } |
| 4292 | |
| 4293 | cc_library { |
| 4294 | name: "mylib2", |
| 4295 | srcs: ["mylib.cpp"], |
| 4296 | system_shared_libs: [], |
| 4297 | stl: "none", |
| 4298 | compile_multilib: "first", |
| 4299 | } |
| 4300 | `) |
| 4301 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4302 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4303 | copyCmds := apexRule.Args["copy_commands"] |
| 4304 | |
| 4305 | // Ensure that main rule creates an output |
| 4306 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 4307 | |
| 4308 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4309 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 4310 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
| 4311 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4312 | |
| 4313 | // Ensure that both direct and indirect deps are copied into apex |
| 4314 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 4315 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 4316 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 4317 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4318 | // Ensure that the platform variant ends with _shared |
| 4319 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 4320 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 4321 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4322 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4323 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4324 | func TestApexWithArch(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4325 | ctx := testApex(t, ` |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4326 | apex { |
| 4327 | name: "myapex", |
| 4328 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4329 | updatable: false, |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4330 | arch: { |
| 4331 | arm64: { |
| 4332 | native_shared_libs: ["mylib.arm64"], |
| 4333 | }, |
| 4334 | x86_64: { |
| 4335 | native_shared_libs: ["mylib.x64"], |
| 4336 | }, |
| 4337 | } |
| 4338 | } |
| 4339 | |
| 4340 | apex_key { |
| 4341 | name: "myapex.key", |
| 4342 | public_key: "testkey.avbpubkey", |
| 4343 | private_key: "testkey.pem", |
| 4344 | } |
| 4345 | |
| 4346 | cc_library { |
| 4347 | name: "mylib.arm64", |
| 4348 | srcs: ["mylib.cpp"], |
| 4349 | system_shared_libs: [], |
| 4350 | stl: "none", |
| 4351 | // TODO: remove //apex_available:platform |
| 4352 | apex_available: [ |
| 4353 | "//apex_available:platform", |
| 4354 | "myapex", |
| 4355 | ], |
| 4356 | } |
| 4357 | |
| 4358 | cc_library { |
| 4359 | name: "mylib.x64", |
| 4360 | srcs: ["mylib.cpp"], |
| 4361 | system_shared_libs: [], |
| 4362 | stl: "none", |
| 4363 | // TODO: remove //apex_available:platform |
| 4364 | apex_available: [ |
| 4365 | "//apex_available:platform", |
| 4366 | "myapex", |
| 4367 | ], |
| 4368 | } |
| 4369 | `) |
| 4370 | |
| 4371 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 4372 | copyCmds := apexRule.Args["copy_commands"] |
| 4373 | |
| 4374 | // Ensure that apex variant is created for the direct dep |
| 4375 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib.arm64"), "android_arm64_armv8-a_shared_apex10000") |
| 4376 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib.x64"), "android_arm64_armv8-a_shared_apex10000") |
| 4377 | |
| 4378 | // Ensure that both direct and indirect deps are copied into apex |
| 4379 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.arm64.so") |
| 4380 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib.x64.so") |
| 4381 | } |
| 4382 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4383 | func TestApexWithShBinary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4384 | ctx := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4385 | apex { |
| 4386 | name: "myapex", |
| 4387 | key: "myapex.key", |
| 4388 | binaries: ["myscript"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4389 | updatable: false, |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | apex_key { |
| 4393 | name: "myapex.key", |
| 4394 | public_key: "testkey.avbpubkey", |
| 4395 | private_key: "testkey.pem", |
| 4396 | } |
| 4397 | |
| 4398 | sh_binary { |
| 4399 | name: "myscript", |
| 4400 | src: "mylib.cpp", |
| 4401 | filename: "myscript.sh", |
| 4402 | sub_dir: "script", |
| 4403 | } |
| 4404 | `) |
| 4405 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4406 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4407 | copyCmds := apexRule.Args["copy_commands"] |
| 4408 | |
| 4409 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 4410 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4411 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4412 | func TestApexInVariousPartition(t *testing.T) { |
| 4413 | testcases := []struct { |
| 4414 | propName, parition, flattenedPartition string |
| 4415 | }{ |
| 4416 | {"", "system", "system_ext"}, |
| 4417 | {"product_specific: true", "product", "product"}, |
| 4418 | {"soc_specific: true", "vendor", "vendor"}, |
| 4419 | {"proprietary: true", "vendor", "vendor"}, |
| 4420 | {"vendor: true", "vendor", "vendor"}, |
| 4421 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 4422 | } |
| 4423 | for _, tc := range testcases { |
| 4424 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4425 | ctx := testApex(t, ` |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4426 | apex { |
| 4427 | name: "myapex", |
| 4428 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4429 | updatable: false, |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4430 | `+tc.propName+` |
| 4431 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4432 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4433 | apex_key { |
| 4434 | name: "myapex.key", |
| 4435 | public_key: "testkey.avbpubkey", |
| 4436 | private_key: "testkey.pem", |
| 4437 | } |
| 4438 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4439 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4440 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 4441 | expected := "out/soong/target/product/test_device/" + tc.parition + "/apex" |
| 4442 | actual := apex.installDir.RelativeToTop().String() |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4443 | if actual != expected { |
| 4444 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4445 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4446 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4447 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 4448 | expected = "out/soong/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 4449 | actual = flattened.installDir.RelativeToTop().String() |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4450 | if actual != expected { |
| 4451 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4452 | } |
| 4453 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4454 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4455 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4456 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4457 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4458 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4459 | apex { |
| 4460 | name: "myapex", |
| 4461 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4462 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4463 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4464 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4465 | apex_key { |
| 4466 | name: "myapex.key", |
| 4467 | public_key: "testkey.avbpubkey", |
| 4468 | private_key: "testkey.pem", |
| 4469 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4470 | `) |
| 4471 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4472 | rule := module.Output("file_contexts") |
| 4473 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 4474 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4475 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4476 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4477 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4478 | apex { |
| 4479 | name: "myapex", |
| 4480 | key: "myapex.key", |
| 4481 | file_contexts: "my_own_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4482 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4483 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4484 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4485 | apex_key { |
| 4486 | name: "myapex.key", |
| 4487 | public_key: "testkey.avbpubkey", |
| 4488 | private_key: "testkey.pem", |
| 4489 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4490 | `, withFiles(map[string][]byte{ |
| 4491 | "my_own_file_contexts": nil, |
| 4492 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4493 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4494 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4495 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4496 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4497 | apex { |
| 4498 | name: "myapex", |
| 4499 | key: "myapex.key", |
| 4500 | product_specific: true, |
| 4501 | file_contexts: "product_specific_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4502 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4503 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4504 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4505 | apex_key { |
| 4506 | name: "myapex.key", |
| 4507 | public_key: "testkey.avbpubkey", |
| 4508 | private_key: "testkey.pem", |
| 4509 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4510 | `) |
| 4511 | |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4512 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4513 | apex { |
| 4514 | name: "myapex", |
| 4515 | key: "myapex.key", |
| 4516 | product_specific: true, |
| 4517 | file_contexts: "product_specific_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4518 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4519 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4520 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4521 | apex_key { |
| 4522 | name: "myapex.key", |
| 4523 | public_key: "testkey.avbpubkey", |
| 4524 | private_key: "testkey.pem", |
| 4525 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4526 | `, withFiles(map[string][]byte{ |
| 4527 | "product_specific_file_contexts": nil, |
| 4528 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4529 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4530 | rule := module.Output("file_contexts") |
| 4531 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 4532 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4533 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4534 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4535 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4536 | apex { |
| 4537 | name: "myapex", |
| 4538 | key: "myapex.key", |
| 4539 | product_specific: true, |
| 4540 | file_contexts: ":my-file-contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4541 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4542 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4543 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4544 | apex_key { |
| 4545 | name: "myapex.key", |
| 4546 | public_key: "testkey.avbpubkey", |
| 4547 | private_key: "testkey.pem", |
| 4548 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4549 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4550 | filegroup { |
| 4551 | name: "my-file-contexts", |
| 4552 | srcs: ["product_specific_file_contexts"], |
| 4553 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4554 | `, withFiles(map[string][]byte{ |
| 4555 | "product_specific_file_contexts": nil, |
| 4556 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4557 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4558 | rule := module.Output("file_contexts") |
| 4559 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4560 | } |
| 4561 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4562 | func TestApexKeyFromOtherModule(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4563 | ctx := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4564 | apex_key { |
| 4565 | name: "myapex.key", |
| 4566 | public_key: ":my.avbpubkey", |
| 4567 | private_key: ":my.pem", |
| 4568 | product_specific: true, |
| 4569 | } |
| 4570 | |
| 4571 | filegroup { |
| 4572 | name: "my.avbpubkey", |
| 4573 | srcs: ["testkey2.avbpubkey"], |
| 4574 | } |
| 4575 | |
| 4576 | filegroup { |
| 4577 | name: "my.pem", |
| 4578 | srcs: ["testkey2.pem"], |
| 4579 | } |
| 4580 | `) |
| 4581 | |
| 4582 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 4583 | expected_pubkey := "testkey2.avbpubkey" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4584 | actual_pubkey := apex_key.publicKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4585 | if actual_pubkey != expected_pubkey { |
| 4586 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 4587 | } |
| 4588 | expected_privkey := "testkey2.pem" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4589 | actual_privkey := apex_key.privateKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4590 | if actual_privkey != expected_privkey { |
| 4591 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 4592 | } |
| 4593 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4594 | |
| 4595 | func TestPrebuilt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4596 | ctx := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4597 | prebuilt_apex { |
| 4598 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4599 | arch: { |
| 4600 | arm64: { |
| 4601 | src: "myapex-arm64.apex", |
| 4602 | }, |
| 4603 | arm: { |
| 4604 | src: "myapex-arm.apex", |
| 4605 | }, |
| 4606 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4607 | } |
| 4608 | `) |
| 4609 | |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 4610 | prebuilt := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*Prebuilt) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4611 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4612 | expectedInput := "myapex-arm64.apex" |
| 4613 | if prebuilt.inputApex.String() != expectedInput { |
| 4614 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 4615 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4616 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4617 | |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 4618 | func TestPrebuiltMissingSrc(t *testing.T) { |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 4619 | testApexError(t, `module "myapex" variant "android_common_myapex".*: prebuilt_apex does not support "arm64_armv8-a"`, ` |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 4620 | prebuilt_apex { |
| 4621 | name: "myapex", |
| 4622 | } |
| 4623 | `) |
| 4624 | } |
| 4625 | |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4626 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4627 | ctx := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4628 | prebuilt_apex { |
| 4629 | name: "myapex", |
| 4630 | src: "myapex-arm.apex", |
| 4631 | filename: "notmyapex.apex", |
| 4632 | } |
| 4633 | `) |
| 4634 | |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 4635 | p := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*Prebuilt) |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4636 | |
| 4637 | expected := "notmyapex.apex" |
| 4638 | if p.installFilename != expected { |
| 4639 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 4640 | } |
| 4641 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4642 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4643 | func TestPrebuiltOverrides(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4644 | ctx := testApex(t, ` |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4645 | prebuilt_apex { |
| 4646 | name: "myapex.prebuilt", |
| 4647 | src: "myapex-arm.apex", |
| 4648 | overrides: [ |
| 4649 | "myapex", |
| 4650 | ], |
| 4651 | } |
| 4652 | `) |
| 4653 | |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 4654 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common_myapex.prebuilt").Module().(*Prebuilt) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4655 | |
| 4656 | expected := []string{"myapex"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4657 | actual := android.AndroidMkEntriesForTest(t, ctx, p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4658 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 4659 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4660 | } |
| 4661 | } |
| 4662 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 4663 | func TestPrebuiltApexName(t *testing.T) { |
| 4664 | testApex(t, ` |
| 4665 | prebuilt_apex { |
| 4666 | name: "com.company.android.myapex", |
| 4667 | apex_name: "com.android.myapex", |
| 4668 | src: "company-myapex-arm.apex", |
| 4669 | } |
| 4670 | `).ModuleForTests("com.company.android.myapex", "android_common_com.android.myapex") |
| 4671 | |
| 4672 | testApex(t, ` |
| 4673 | apex_set { |
| 4674 | name: "com.company.android.myapex", |
| 4675 | apex_name: "com.android.myapex", |
| 4676 | set: "company-myapex.apks", |
| 4677 | } |
| 4678 | `).ModuleForTests("com.company.android.myapex", "android_common_com.android.myapex") |
| 4679 | } |
| 4680 | |
| 4681 | func TestPrebuiltApexNameWithPlatformBootclasspath(t *testing.T) { |
| 4682 | _ = android.GroupFixturePreparers( |
| 4683 | java.PrepareForTestWithJavaDefaultModules, |
| 4684 | PrepareForTestWithApexBuildComponents, |
| 4685 | android.FixtureWithRootAndroidBp(` |
| 4686 | platform_bootclasspath { |
| 4687 | name: "platform-bootclasspath", |
| 4688 | fragments: [ |
| 4689 | { |
| 4690 | apex: "com.android.art", |
| 4691 | module: "art-bootclasspath-fragment", |
| 4692 | }, |
| 4693 | ], |
| 4694 | } |
| 4695 | |
| 4696 | prebuilt_apex { |
| 4697 | name: "com.company.android.art", |
| 4698 | apex_name: "com.android.art", |
| 4699 | src: "com.company.android.art-arm.apex", |
| 4700 | exported_bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 4701 | } |
| 4702 | |
| 4703 | prebuilt_bootclasspath_fragment { |
| 4704 | name: "art-bootclasspath-fragment", |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 4705 | image_name: "art", |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 4706 | contents: ["core-oj"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 4707 | hidden_api: { |
| 4708 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 4709 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 4710 | index: "my-bootclasspath-fragment/index.csv", |
| 4711 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 4712 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 4713 | }, |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | java_import { |
| 4717 | name: "core-oj", |
| 4718 | jars: ["prebuilt.jar"], |
| 4719 | } |
| 4720 | `), |
| 4721 | ).RunTest(t) |
| 4722 | } |
| 4723 | |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4724 | // These tests verify that the prebuilt_apex/deapexer to java_import wiring allows for the |
| 4725 | // 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] | 4726 | func TestPrebuiltExportDexImplementationJars(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 4727 | transform := android.NullFixturePreparer |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4728 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4729 | checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4730 | // 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] | 4731 | p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4732 | dexJarBuildPath := p.DexJarBuildPath() |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4733 | stem := android.RemoveOptionalPrebuiltPrefix(name) |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4734 | android.AssertStringEquals(t, "DexJarBuildPath should be apex-related path.", |
| 4735 | ".intermediates/myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar", |
| 4736 | android.NormalizePathForTesting(dexJarBuildPath)) |
| 4737 | } |
| 4738 | |
| 4739 | checkDexJarInstallPath := func(t *testing.T, ctx *android.TestContext, name string) { |
| 4740 | // Make sure the import has been given the correct path to the dex jar. |
| 4741 | p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) |
| 4742 | dexJarBuildPath := p.DexJarInstallPath() |
| 4743 | stem := android.RemoveOptionalPrebuiltPrefix(name) |
| 4744 | android.AssertStringEquals(t, "DexJarInstallPath should be apex-related path.", |
| 4745 | "target/product/test_device/apex/myapex/javalib/"+stem+".jar", |
| 4746 | android.NormalizePathForTesting(dexJarBuildPath)) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4747 | } |
| 4748 | |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4749 | ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4750 | // Make sure that an apex variant is not created for the source module. |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4751 | android.AssertArrayString(t, "Check if there is no source variant", |
| 4752 | []string{"android_common"}, |
| 4753 | ctx.ModuleVariantsForTests(name)) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4754 | } |
| 4755 | |
| 4756 | t.Run("prebuilt only", func(t *testing.T) { |
| 4757 | bp := ` |
| 4758 | prebuilt_apex { |
| 4759 | name: "myapex", |
| 4760 | arch: { |
| 4761 | arm64: { |
| 4762 | src: "myapex-arm64.apex", |
| 4763 | }, |
| 4764 | arm: { |
| 4765 | src: "myapex-arm.apex", |
| 4766 | }, |
| 4767 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4768 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | java_import { |
| 4772 | name: "libfoo", |
| 4773 | jars: ["libfoo.jar"], |
| 4774 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4775 | |
| 4776 | java_sdk_library_import { |
| 4777 | name: "libbar", |
| 4778 | public: { |
| 4779 | jars: ["libbar.jar"], |
| 4780 | }, |
| 4781 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4782 | ` |
| 4783 | |
| 4784 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4785 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4786 | |
Paul Duffin | f6932af | 2021-02-26 18:21:56 +0000 | [diff] [blame] | 4787 | // Make sure that the deapexer has the correct input APEX. |
| 4788 | deapexer := ctx.ModuleForTests("myapex.deapexer", "android_common") |
| 4789 | rule := deapexer.Rule("deapexer") |
| 4790 | if expected, actual := []string{"myapex-arm64.apex"}, android.NormalizePathsForTesting(rule.Implicits); !reflect.DeepEqual(expected, actual) { |
| 4791 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4792 | } |
| 4793 | |
Paul Duffin | 0d10c3c | 2021-03-01 17:09:32 +0000 | [diff] [blame] | 4794 | // Make sure that the prebuilt_apex has the correct input APEX. |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 4795 | prebuiltApex := ctx.ModuleForTests("myapex", "android_common_myapex") |
Paul Duffin | 0d10c3c | 2021-03-01 17:09:32 +0000 | [diff] [blame] | 4796 | rule = prebuiltApex.Rule("android/soong/android.Cp") |
| 4797 | if expected, actual := "myapex-arm64.apex", android.NormalizePathForTesting(rule.Input); !reflect.DeepEqual(expected, actual) { |
| 4798 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4799 | } |
| 4800 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4801 | checkDexJarBuildPath(t, ctx, "libfoo") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4802 | checkDexJarInstallPath(t, ctx, "libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4803 | |
| 4804 | checkDexJarBuildPath(t, ctx, "libbar") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4805 | checkDexJarInstallPath(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4806 | }) |
| 4807 | |
| 4808 | t.Run("prebuilt with source preferred", func(t *testing.T) { |
| 4809 | |
| 4810 | bp := ` |
| 4811 | prebuilt_apex { |
| 4812 | name: "myapex", |
| 4813 | arch: { |
| 4814 | arm64: { |
| 4815 | src: "myapex-arm64.apex", |
| 4816 | }, |
| 4817 | arm: { |
| 4818 | src: "myapex-arm.apex", |
| 4819 | }, |
| 4820 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4821 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4822 | } |
| 4823 | |
| 4824 | java_import { |
| 4825 | name: "libfoo", |
| 4826 | jars: ["libfoo.jar"], |
| 4827 | } |
| 4828 | |
| 4829 | java_library { |
| 4830 | name: "libfoo", |
| 4831 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4832 | |
| 4833 | java_sdk_library_import { |
| 4834 | name: "libbar", |
| 4835 | public: { |
| 4836 | jars: ["libbar.jar"], |
| 4837 | }, |
| 4838 | } |
| 4839 | |
| 4840 | java_sdk_library { |
| 4841 | name: "libbar", |
| 4842 | srcs: ["foo/bar/MyClass.java"], |
| 4843 | unsafe_ignore_missing_latest_api: true, |
| 4844 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4845 | ` |
| 4846 | |
| 4847 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4848 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4849 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4850 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4851 | checkDexJarInstallPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4852 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4853 | |
| 4854 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4855 | checkDexJarInstallPath(t, ctx, "prebuilt_libbar") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4856 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4857 | }) |
| 4858 | |
| 4859 | t.Run("prebuilt preferred with source", func(t *testing.T) { |
| 4860 | bp := ` |
| 4861 | prebuilt_apex { |
| 4862 | name: "myapex", |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4863 | arch: { |
| 4864 | arm64: { |
| 4865 | src: "myapex-arm64.apex", |
| 4866 | }, |
| 4867 | arm: { |
| 4868 | src: "myapex-arm.apex", |
| 4869 | }, |
| 4870 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4871 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | java_import { |
| 4875 | name: "libfoo", |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4876 | prefer: true, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4877 | jars: ["libfoo.jar"], |
| 4878 | } |
| 4879 | |
| 4880 | java_library { |
| 4881 | name: "libfoo", |
| 4882 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4883 | |
| 4884 | java_sdk_library_import { |
| 4885 | name: "libbar", |
| 4886 | prefer: true, |
| 4887 | public: { |
| 4888 | jars: ["libbar.jar"], |
| 4889 | }, |
| 4890 | } |
| 4891 | |
| 4892 | java_sdk_library { |
| 4893 | name: "libbar", |
| 4894 | srcs: ["foo/bar/MyClass.java"], |
| 4895 | unsafe_ignore_missing_latest_api: true, |
| 4896 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4897 | ` |
| 4898 | |
| 4899 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4900 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4901 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4902 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4903 | checkDexJarInstallPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4904 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4905 | |
| 4906 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4907 | checkDexJarInstallPath(t, ctx, "prebuilt_libbar") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4908 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4909 | }) |
| 4910 | } |
| 4911 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4912 | func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { |
Paul Duffin | b6f53c0 | 2021-05-14 07:52:42 +0100 | [diff] [blame] | 4913 | preparer := android.GroupFixturePreparers( |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 4914 | java.FixtureConfigureApexBootJars("myapex:libfoo", "myapex:libbar"), |
Paul Duffin | b6f53c0 | 2021-05-14 07:52:42 +0100 | [diff] [blame] | 4915 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 4916 | // is disabled. |
| 4917 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 4918 | ) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4919 | |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4920 | checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) { |
| 4921 | t.Helper() |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 4922 | s := ctx.ModuleForTests("platform-bootclasspath", "android_common") |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4923 | foundLibfooJar := false |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4924 | base := stem + ".jar" |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4925 | for _, output := range s.AllOutputs() { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4926 | if filepath.Base(output) == base { |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4927 | foundLibfooJar = true |
| 4928 | buildRule := s.Output(output) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 4929 | android.AssertStringEquals(t, "boot dex jar path", bootDexJarPath, buildRule.Input.String()) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4930 | } |
| 4931 | } |
| 4932 | if !foundLibfooJar { |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 4933 | 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] | 4934 | } |
| 4935 | } |
| 4936 | |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 4937 | checkHiddenAPIIndexFromClassesInputs := func(t *testing.T, ctx *android.TestContext, expectedIntermediateInputs string) { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4938 | t.Helper() |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 4939 | platformBootclasspath := ctx.ModuleForTests("platform-bootclasspath", "android_common") |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 4940 | var rule android.TestingBuildParams |
| 4941 | |
| 4942 | rule = platformBootclasspath.Output("hiddenapi-monolithic/index-from-classes.csv") |
| 4943 | java.CheckHiddenAPIRuleInputs(t, "intermediate index", expectedIntermediateInputs, rule) |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4944 | } |
| 4945 | |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 4946 | checkHiddenAPIIndexFromFlagsInputs := func(t *testing.T, ctx *android.TestContext, expectedIntermediateInputs string) { |
| 4947 | t.Helper() |
| 4948 | platformBootclasspath := ctx.ModuleForTests("platform-bootclasspath", "android_common") |
| 4949 | var rule android.TestingBuildParams |
| 4950 | |
| 4951 | rule = platformBootclasspath.Output("hiddenapi-index.csv") |
| 4952 | java.CheckHiddenAPIRuleInputs(t, "monolithic index", expectedIntermediateInputs, rule) |
| 4953 | } |
| 4954 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 4955 | fragment := java.ApexVariantReference{ |
| 4956 | Apex: proptools.StringPtr("myapex"), |
| 4957 | Module: proptools.StringPtr("my-bootclasspath-fragment"), |
| 4958 | } |
| 4959 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4960 | t.Run("prebuilt only", func(t *testing.T) { |
| 4961 | bp := ` |
| 4962 | prebuilt_apex { |
| 4963 | name: "myapex", |
| 4964 | arch: { |
| 4965 | arm64: { |
| 4966 | src: "myapex-arm64.apex", |
| 4967 | }, |
| 4968 | arm: { |
| 4969 | src: "myapex-arm.apex", |
| 4970 | }, |
| 4971 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 4972 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 4973 | } |
| 4974 | |
| 4975 | prebuilt_bootclasspath_fragment { |
| 4976 | name: "my-bootclasspath-fragment", |
| 4977 | contents: ["libfoo", "libbar"], |
| 4978 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 4979 | hidden_api: { |
| 4980 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 4981 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 4982 | index: "my-bootclasspath-fragment/index.csv", |
| 4983 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 4984 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 4985 | }, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | java_import { |
| 4989 | name: "libfoo", |
| 4990 | jars: ["libfoo.jar"], |
| 4991 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 4992 | permitted_packages: ["foo"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4993 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4994 | |
| 4995 | java_sdk_library_import { |
| 4996 | name: "libbar", |
| 4997 | public: { |
| 4998 | jars: ["libbar.jar"], |
| 4999 | }, |
| 5000 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5001 | shared_library: false, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5002 | permitted_packages: ["bar"], |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5003 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5004 | ` |
| 5005 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5006 | ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 5007 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 5008 | 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] | 5009 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 5010 | // Verify the correct module jars contribute to the hiddenapi index file. |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5011 | checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5012 | checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5013 | my-bootclasspath-fragment/index.csv |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5014 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 5015 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5016 | }) |
| 5017 | |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5018 | t.Run("apex_set only", func(t *testing.T) { |
| 5019 | bp := ` |
| 5020 | apex_set { |
| 5021 | name: "myapex", |
| 5022 | set: "myapex.apks", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5023 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 5024 | } |
| 5025 | |
| 5026 | prebuilt_bootclasspath_fragment { |
| 5027 | name: "my-bootclasspath-fragment", |
| 5028 | contents: ["libfoo", "libbar"], |
| 5029 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5030 | hidden_api: { |
| 5031 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5032 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5033 | index: "my-bootclasspath-fragment/index.csv", |
| 5034 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 5035 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 5036 | }, |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | java_import { |
| 5040 | name: "libfoo", |
| 5041 | jars: ["libfoo.jar"], |
| 5042 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5043 | permitted_packages: ["foo"], |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | java_sdk_library_import { |
| 5047 | name: "libbar", |
| 5048 | public: { |
| 5049 | jars: ["libbar.jar"], |
| 5050 | }, |
| 5051 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5052 | shared_library: false, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5053 | permitted_packages: ["bar"], |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5054 | } |
| 5055 | ` |
| 5056 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5057 | ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5058 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 5059 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
| 5060 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 5061 | // Verify the correct module jars contribute to the hiddenapi index file. |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5062 | checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5063 | checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5064 | my-bootclasspath-fragment/index.csv |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5065 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 5066 | `) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5067 | }) |
| 5068 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5069 | t.Run("prebuilt with source library preferred", func(t *testing.T) { |
| 5070 | bp := ` |
| 5071 | prebuilt_apex { |
| 5072 | name: "myapex", |
| 5073 | arch: { |
| 5074 | arm64: { |
| 5075 | src: "myapex-arm64.apex", |
| 5076 | }, |
| 5077 | arm: { |
| 5078 | src: "myapex-arm.apex", |
| 5079 | }, |
| 5080 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5081 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 5082 | } |
| 5083 | |
| 5084 | prebuilt_bootclasspath_fragment { |
| 5085 | name: "my-bootclasspath-fragment", |
| 5086 | contents: ["libfoo", "libbar"], |
| 5087 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5088 | hidden_api: { |
| 5089 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5090 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5091 | index: "my-bootclasspath-fragment/index.csv", |
| 5092 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 5093 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 5094 | }, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5095 | } |
| 5096 | |
| 5097 | java_import { |
| 5098 | name: "libfoo", |
| 5099 | jars: ["libfoo.jar"], |
| 5100 | apex_available: ["myapex"], |
| 5101 | } |
| 5102 | |
| 5103 | java_library { |
| 5104 | name: "libfoo", |
| 5105 | srcs: ["foo/bar/MyClass.java"], |
| 5106 | apex_available: ["myapex"], |
| 5107 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5108 | |
| 5109 | java_sdk_library_import { |
| 5110 | name: "libbar", |
| 5111 | public: { |
| 5112 | jars: ["libbar.jar"], |
| 5113 | }, |
| 5114 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5115 | shared_library: false, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | java_sdk_library { |
| 5119 | name: "libbar", |
| 5120 | srcs: ["foo/bar/MyClass.java"], |
| 5121 | unsafe_ignore_missing_latest_api: true, |
| 5122 | apex_available: ["myapex"], |
| 5123 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5124 | ` |
| 5125 | |
| 5126 | // In this test the source (java_library) libfoo is active since the |
| 5127 | // prebuilt (java_import) defaults to prefer:false. However the |
| 5128 | // prebuilt_apex module always depends on the prebuilt, and so it doesn't |
| 5129 | // find the dex boot jar in it. We either need to disable the source libfoo |
| 5130 | // or make the prebuilt libfoo preferred. |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5131 | testDexpreoptWithApexes(t, bp, "module libfoo does not provide a dex boot jar", preparer, fragment) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5132 | }) |
| 5133 | |
| 5134 | t.Run("prebuilt library preferred with source", func(t *testing.T) { |
| 5135 | bp := ` |
| 5136 | prebuilt_apex { |
| 5137 | name: "myapex", |
| 5138 | arch: { |
| 5139 | arm64: { |
| 5140 | src: "myapex-arm64.apex", |
| 5141 | }, |
| 5142 | arm: { |
| 5143 | src: "myapex-arm.apex", |
| 5144 | }, |
| 5145 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5146 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 5147 | } |
| 5148 | |
| 5149 | prebuilt_bootclasspath_fragment { |
| 5150 | name: "my-bootclasspath-fragment", |
| 5151 | contents: ["libfoo", "libbar"], |
| 5152 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5153 | hidden_api: { |
| 5154 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5155 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5156 | index: "my-bootclasspath-fragment/index.csv", |
| 5157 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 5158 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 5159 | }, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | java_import { |
| 5163 | name: "libfoo", |
| 5164 | prefer: true, |
| 5165 | jars: ["libfoo.jar"], |
| 5166 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5167 | permitted_packages: ["foo"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5168 | } |
| 5169 | |
| 5170 | java_library { |
| 5171 | name: "libfoo", |
| 5172 | srcs: ["foo/bar/MyClass.java"], |
| 5173 | apex_available: ["myapex"], |
| 5174 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5175 | |
| 5176 | java_sdk_library_import { |
| 5177 | name: "libbar", |
| 5178 | prefer: true, |
| 5179 | public: { |
| 5180 | jars: ["libbar.jar"], |
| 5181 | }, |
| 5182 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5183 | shared_library: false, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5184 | permitted_packages: ["bar"], |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5185 | } |
| 5186 | |
| 5187 | java_sdk_library { |
| 5188 | name: "libbar", |
| 5189 | srcs: ["foo/bar/MyClass.java"], |
| 5190 | unsafe_ignore_missing_latest_api: true, |
| 5191 | apex_available: ["myapex"], |
| 5192 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5193 | ` |
| 5194 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5195 | ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 5196 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 5197 | 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] | 5198 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 5199 | // Verify the correct module jars contribute to the hiddenapi index file. |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5200 | checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5201 | checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5202 | my-bootclasspath-fragment/index.csv |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5203 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 5204 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5205 | }) |
| 5206 | |
| 5207 | t.Run("prebuilt with source apex preferred", func(t *testing.T) { |
| 5208 | bp := ` |
| 5209 | apex { |
| 5210 | name: "myapex", |
| 5211 | key: "myapex.key", |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5212 | java_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5213 | updatable: false, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | apex_key { |
| 5217 | name: "myapex.key", |
| 5218 | public_key: "testkey.avbpubkey", |
| 5219 | private_key: "testkey.pem", |
| 5220 | } |
| 5221 | |
| 5222 | prebuilt_apex { |
| 5223 | name: "myapex", |
| 5224 | arch: { |
| 5225 | arm64: { |
| 5226 | src: "myapex-arm64.apex", |
| 5227 | }, |
| 5228 | arm: { |
| 5229 | src: "myapex-arm.apex", |
| 5230 | }, |
| 5231 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5232 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 5233 | } |
| 5234 | |
| 5235 | prebuilt_bootclasspath_fragment { |
| 5236 | name: "my-bootclasspath-fragment", |
| 5237 | contents: ["libfoo", "libbar"], |
| 5238 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5239 | hidden_api: { |
| 5240 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5241 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5242 | index: "my-bootclasspath-fragment/index.csv", |
| 5243 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 5244 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 5245 | }, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | java_import { |
| 5249 | name: "libfoo", |
| 5250 | jars: ["libfoo.jar"], |
| 5251 | apex_available: ["myapex"], |
| 5252 | } |
| 5253 | |
| 5254 | java_library { |
| 5255 | name: "libfoo", |
| 5256 | srcs: ["foo/bar/MyClass.java"], |
| 5257 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5258 | permitted_packages: ["foo"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5259 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5260 | |
| 5261 | java_sdk_library_import { |
| 5262 | name: "libbar", |
| 5263 | public: { |
| 5264 | jars: ["libbar.jar"], |
| 5265 | }, |
| 5266 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5267 | shared_library: false, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5268 | } |
| 5269 | |
| 5270 | java_sdk_library { |
| 5271 | name: "libbar", |
| 5272 | srcs: ["foo/bar/MyClass.java"], |
| 5273 | unsafe_ignore_missing_latest_api: true, |
| 5274 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5275 | permitted_packages: ["bar"], |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5276 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5277 | ` |
| 5278 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5279 | ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 5280 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar") |
| 5281 | 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] | 5282 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 5283 | // Verify the correct module jars contribute to the hiddenapi index file. |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5284 | checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5285 | checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5286 | my-bootclasspath-fragment/index.csv |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5287 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 5288 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5289 | }) |
| 5290 | |
| 5291 | t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) { |
| 5292 | bp := ` |
| 5293 | apex { |
| 5294 | name: "myapex", |
| 5295 | enabled: false, |
| 5296 | key: "myapex.key", |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 5297 | java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | apex_key { |
| 5301 | name: "myapex.key", |
| 5302 | public_key: "testkey.avbpubkey", |
| 5303 | private_key: "testkey.pem", |
| 5304 | } |
| 5305 | |
| 5306 | prebuilt_apex { |
| 5307 | name: "myapex", |
| 5308 | arch: { |
| 5309 | arm64: { |
| 5310 | src: "myapex-arm64.apex", |
| 5311 | }, |
| 5312 | arm: { |
| 5313 | src: "myapex-arm.apex", |
| 5314 | }, |
| 5315 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5316 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 5317 | } |
| 5318 | |
| 5319 | prebuilt_bootclasspath_fragment { |
| 5320 | name: "my-bootclasspath-fragment", |
| 5321 | contents: ["libfoo", "libbar"], |
| 5322 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5323 | hidden_api: { |
| 5324 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5325 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5326 | index: "my-bootclasspath-fragment/index.csv", |
| 5327 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 5328 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 5329 | }, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | java_import { |
| 5333 | name: "libfoo", |
| 5334 | prefer: true, |
| 5335 | jars: ["libfoo.jar"], |
| 5336 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5337 | permitted_packages: ["foo"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | java_library { |
| 5341 | name: "libfoo", |
| 5342 | srcs: ["foo/bar/MyClass.java"], |
| 5343 | apex_available: ["myapex"], |
| 5344 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5345 | |
| 5346 | java_sdk_library_import { |
| 5347 | name: "libbar", |
| 5348 | prefer: true, |
| 5349 | public: { |
| 5350 | jars: ["libbar.jar"], |
| 5351 | }, |
| 5352 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5353 | shared_library: false, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5354 | permitted_packages: ["bar"], |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | java_sdk_library { |
| 5358 | name: "libbar", |
| 5359 | srcs: ["foo/bar/MyClass.java"], |
| 5360 | unsafe_ignore_missing_latest_api: true, |
| 5361 | apex_available: ["myapex"], |
| 5362 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5363 | ` |
| 5364 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5365 | ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 5366 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 5367 | 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] | 5368 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 5369 | // Verify the correct module jars contribute to the hiddenapi index file. |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5370 | checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5371 | checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5372 | my-bootclasspath-fragment/index.csv |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5373 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 5374 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5375 | }) |
| 5376 | } |
| 5377 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5378 | func TestApexWithTests(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5379 | ctx := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5380 | apex_test { |
| 5381 | name: "myapex", |
| 5382 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5383 | updatable: false, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5384 | tests: [ |
| 5385 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5386 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5387 | ], |
| 5388 | } |
| 5389 | |
| 5390 | apex_key { |
| 5391 | name: "myapex.key", |
| 5392 | public_key: "testkey.avbpubkey", |
| 5393 | private_key: "testkey.pem", |
| 5394 | } |
| 5395 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 5396 | filegroup { |
| 5397 | name: "fg", |
| 5398 | srcs: [ |
| 5399 | "baz", |
| 5400 | "bar/baz" |
| 5401 | ], |
| 5402 | } |
| 5403 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5404 | cc_test { |
| 5405 | name: "mytest", |
| 5406 | gtest: false, |
| 5407 | srcs: ["mytest.cpp"], |
| 5408 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 5409 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5410 | system_shared_libs: [], |
| 5411 | static_executable: true, |
| 5412 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 5413 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5414 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5415 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 5416 | cc_library { |
| 5417 | name: "mylib", |
| 5418 | srcs: ["mylib.cpp"], |
| 5419 | system_shared_libs: [], |
| 5420 | stl: "none", |
| 5421 | } |
| 5422 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 5423 | filegroup { |
| 5424 | name: "fg2", |
| 5425 | srcs: [ |
| 5426 | "testdata/baz" |
| 5427 | ], |
| 5428 | } |
| 5429 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5430 | cc_test { |
| 5431 | name: "mytests", |
| 5432 | gtest: false, |
| 5433 | srcs: [ |
| 5434 | "mytest1.cpp", |
| 5435 | "mytest2.cpp", |
| 5436 | "mytest3.cpp", |
| 5437 | ], |
| 5438 | test_per_src: true, |
| 5439 | relative_install_path: "test", |
| 5440 | system_shared_libs: [], |
| 5441 | static_executable: true, |
| 5442 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 5443 | data: [ |
| 5444 | ":fg", |
| 5445 | ":fg2", |
| 5446 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5447 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5448 | `) |
| 5449 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5450 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5451 | copyCmds := apexRule.Args["copy_commands"] |
| 5452 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 5453 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5454 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 5455 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5456 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 5457 | //Ensure that test data are copied into apex. |
| 5458 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 5459 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 5460 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5461 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 5462 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 5463 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 5464 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 5465 | |
| 5466 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 5467 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5468 | data := android.AndroidMkDataForTest(t, ctx, bundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 5469 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 5470 | prefix := "TARGET_" |
| 5471 | var builder strings.Builder |
| 5472 | data.Custom(&builder, name, prefix, "", data) |
| 5473 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 5474 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 5475 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 5476 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 5477 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5478 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 5479 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 5480 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 5481 | |
| 5482 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5483 | data = android.AndroidMkDataForTest(t, ctx, flatBundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 5484 | data.Custom(&builder, name, prefix, "", data) |
| 5485 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 5486 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 5487 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5488 | } |
| 5489 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5490 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5491 | ctx := testApex(t, ` |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5492 | apex { |
| 5493 | name: "myapex", |
| 5494 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5495 | updatable: false, |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5496 | } |
| 5497 | apex_key { |
| 5498 | name: "myapex.key", |
| 5499 | public_key: "testkey.avbpubkey", |
| 5500 | private_key: "testkey.pem", |
| 5501 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 5502 | `, |
| 5503 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 5504 | variables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 5505 | }), |
| 5506 | ) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5507 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 5508 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5509 | mk := android.AndroidMkDataForTest(t, ctx, ab) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5510 | var builder strings.Builder |
| 5511 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 5512 | androidMk := builder.String() |
| 5513 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 5514 | } |
| 5515 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5516 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 5517 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 5518 | apex { |
| 5519 | name: "myapex", |
| 5520 | key: "myapex.key", |
| 5521 | native_shared_libs: ["libfoo"], |
| 5522 | } |
| 5523 | |
| 5524 | apex_key { |
| 5525 | name: "myapex.key", |
| 5526 | public_key: "testkey.avbpubkey", |
| 5527 | private_key: "testkey.pem", |
| 5528 | } |
| 5529 | |
| 5530 | cc_library { |
| 5531 | name: "libfoo", |
| 5532 | stl: "none", |
| 5533 | system_shared_libs: [], |
| 5534 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5535 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5536 | } |
| 5537 | `) |
| 5538 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 5539 | apex { |
| 5540 | name: "myapex", |
| 5541 | key: "myapex.key", |
| 5542 | java_libs: ["myjar"], |
| 5543 | } |
| 5544 | |
| 5545 | apex_key { |
| 5546 | name: "myapex.key", |
| 5547 | public_key: "testkey.avbpubkey", |
| 5548 | private_key: "testkey.pem", |
| 5549 | } |
| 5550 | |
| 5551 | java_library { |
| 5552 | name: "myjar", |
| 5553 | srcs: ["foo/bar/MyClass.java"], |
| 5554 | sdk_version: "none", |
| 5555 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5556 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5557 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5558 | } |
| 5559 | `) |
| 5560 | } |
| 5561 | |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5562 | func TestApexWithJavaImport(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5563 | ctx := testApex(t, ` |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5564 | apex { |
| 5565 | name: "myapex", |
| 5566 | key: "myapex.key", |
| 5567 | java_libs: ["myjavaimport"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5568 | updatable: false, |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | apex_key { |
| 5572 | name: "myapex.key", |
| 5573 | public_key: "testkey.avbpubkey", |
| 5574 | private_key: "testkey.pem", |
| 5575 | } |
| 5576 | |
| 5577 | java_import { |
| 5578 | name: "myjavaimport", |
| 5579 | apex_available: ["myapex"], |
| 5580 | jars: ["my.jar"], |
| 5581 | compile_dex: true, |
| 5582 | } |
| 5583 | `) |
| 5584 | |
| 5585 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5586 | apexRule := module.Rule("apexRule") |
| 5587 | copyCmds := apexRule.Args["copy_commands"] |
| 5588 | ensureContains(t, copyCmds, "image.apex/javalib/myjavaimport.jar") |
| 5589 | } |
| 5590 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5591 | func TestApexWithApps(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5592 | ctx := testApex(t, ` |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5593 | apex { |
| 5594 | name: "myapex", |
| 5595 | key: "myapex.key", |
| 5596 | apps: [ |
| 5597 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5598 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5599 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5600 | updatable: false, |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | apex_key { |
| 5604 | name: "myapex.key", |
| 5605 | public_key: "testkey.avbpubkey", |
| 5606 | private_key: "testkey.pem", |
| 5607 | } |
| 5608 | |
| 5609 | android_app { |
| 5610 | name: "AppFoo", |
| 5611 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5612 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5613 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5614 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5615 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5616 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5617 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5618 | |
| 5619 | android_app { |
| 5620 | name: "AppFooPriv", |
| 5621 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5622 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5623 | system_modules: "none", |
| 5624 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5625 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5626 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5627 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5628 | |
| 5629 | cc_library_shared { |
| 5630 | name: "libjni", |
| 5631 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5632 | shared_libs: ["libfoo"], |
| 5633 | stl: "none", |
| 5634 | system_shared_libs: [], |
| 5635 | apex_available: [ "myapex" ], |
| 5636 | sdk_version: "current", |
| 5637 | } |
| 5638 | |
| 5639 | cc_library_shared { |
| 5640 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5641 | stl: "none", |
| 5642 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 5643 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5644 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5645 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5646 | `) |
| 5647 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5648 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5649 | apexRule := module.Rule("apexRule") |
| 5650 | copyCmds := apexRule.Args["copy_commands"] |
| 5651 | |
| 5652 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5653 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5654 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5655 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5656 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5657 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5658 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5659 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5660 | // JNI libraries including transitive deps are |
| 5661 | for _, jni := range []string{"libjni", "libfoo"} { |
Paul Duffin | afdd406 | 2021-03-30 19:44:07 +0100 | [diff] [blame] | 5662 | 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] | 5663 | // ... embedded inside APK (jnilibs.zip) |
| 5664 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 5665 | // ... and not directly inside the APEX |
| 5666 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 5667 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5668 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5669 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5670 | func TestApexWithAppImports(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5671 | ctx := testApex(t, ` |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5672 | apex { |
| 5673 | name: "myapex", |
| 5674 | key: "myapex.key", |
| 5675 | apps: [ |
| 5676 | "AppFooPrebuilt", |
| 5677 | "AppFooPrivPrebuilt", |
| 5678 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5679 | updatable: false, |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | apex_key { |
| 5683 | name: "myapex.key", |
| 5684 | public_key: "testkey.avbpubkey", |
| 5685 | private_key: "testkey.pem", |
| 5686 | } |
| 5687 | |
| 5688 | android_app_import { |
| 5689 | name: "AppFooPrebuilt", |
| 5690 | apk: "PrebuiltAppFoo.apk", |
| 5691 | presigned: true, |
| 5692 | dex_preopt: { |
| 5693 | enabled: false, |
| 5694 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5695 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | android_app_import { |
| 5699 | name: "AppFooPrivPrebuilt", |
| 5700 | apk: "PrebuiltAppFooPriv.apk", |
| 5701 | privileged: true, |
| 5702 | presigned: true, |
| 5703 | dex_preopt: { |
| 5704 | enabled: false, |
| 5705 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5706 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5707 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5708 | } |
| 5709 | `) |
| 5710 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5711 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5712 | apexRule := module.Rule("apexRule") |
| 5713 | copyCmds := apexRule.Args["copy_commands"] |
| 5714 | |
| 5715 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5716 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 5717 | } |
| 5718 | |
| 5719 | func TestApexWithAppImportsPrefer(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5720 | ctx := testApex(t, ` |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5721 | apex { |
| 5722 | name: "myapex", |
| 5723 | key: "myapex.key", |
| 5724 | apps: [ |
| 5725 | "AppFoo", |
| 5726 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5727 | updatable: false, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | apex_key { |
| 5731 | name: "myapex.key", |
| 5732 | public_key: "testkey.avbpubkey", |
| 5733 | private_key: "testkey.pem", |
| 5734 | } |
| 5735 | |
| 5736 | android_app { |
| 5737 | name: "AppFoo", |
| 5738 | srcs: ["foo/bar/MyClass.java"], |
| 5739 | sdk_version: "none", |
| 5740 | system_modules: "none", |
| 5741 | apex_available: [ "myapex" ], |
| 5742 | } |
| 5743 | |
| 5744 | android_app_import { |
| 5745 | name: "AppFoo", |
| 5746 | apk: "AppFooPrebuilt.apk", |
| 5747 | filename: "AppFooPrebuilt.apk", |
| 5748 | presigned: true, |
| 5749 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5750 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5751 | } |
| 5752 | `, withFiles(map[string][]byte{ |
| 5753 | "AppFooPrebuilt.apk": nil, |
| 5754 | })) |
| 5755 | |
| 5756 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 86feead | 2021-03-08 13:11:48 +0900 | [diff] [blame] | 5757 | "app/AppFoo/AppFooPrebuilt.apk", |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5758 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5759 | } |
| 5760 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5761 | func TestApexWithTestHelperApp(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5762 | ctx := testApex(t, ` |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5763 | apex { |
| 5764 | name: "myapex", |
| 5765 | key: "myapex.key", |
| 5766 | apps: [ |
| 5767 | "TesterHelpAppFoo", |
| 5768 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5769 | updatable: false, |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5770 | } |
| 5771 | |
| 5772 | apex_key { |
| 5773 | name: "myapex.key", |
| 5774 | public_key: "testkey.avbpubkey", |
| 5775 | private_key: "testkey.pem", |
| 5776 | } |
| 5777 | |
| 5778 | android_test_helper_app { |
| 5779 | name: "TesterHelpAppFoo", |
| 5780 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5781 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | `) |
| 5785 | |
| 5786 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5787 | apexRule := module.Rule("apexRule") |
| 5788 | copyCmds := apexRule.Args["copy_commands"] |
| 5789 | |
| 5790 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 5791 | } |
| 5792 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5793 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 5794 | // libfoo's apex_available comes from cc_defaults |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5795 | 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] | 5796 | apex { |
| 5797 | name: "myapex", |
| 5798 | key: "myapex.key", |
| 5799 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5800 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | apex_key { |
| 5804 | name: "myapex.key", |
| 5805 | public_key: "testkey.avbpubkey", |
| 5806 | private_key: "testkey.pem", |
| 5807 | } |
| 5808 | |
| 5809 | apex { |
| 5810 | name: "otherapex", |
| 5811 | key: "myapex.key", |
| 5812 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5813 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | cc_defaults { |
| 5817 | name: "libfoo-defaults", |
| 5818 | apex_available: ["otherapex"], |
| 5819 | } |
| 5820 | |
| 5821 | cc_library { |
| 5822 | name: "libfoo", |
| 5823 | defaults: ["libfoo-defaults"], |
| 5824 | stl: "none", |
| 5825 | system_shared_libs: [], |
| 5826 | }`) |
| 5827 | } |
| 5828 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5829 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5830 | // libfoo is not available to myapex, but only to otherapex |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5831 | 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] | 5832 | apex { |
| 5833 | name: "myapex", |
| 5834 | key: "myapex.key", |
| 5835 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5836 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5837 | } |
| 5838 | |
| 5839 | apex_key { |
| 5840 | name: "myapex.key", |
| 5841 | public_key: "testkey.avbpubkey", |
| 5842 | private_key: "testkey.pem", |
| 5843 | } |
| 5844 | |
| 5845 | apex { |
| 5846 | name: "otherapex", |
| 5847 | key: "otherapex.key", |
| 5848 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5849 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5850 | } |
| 5851 | |
| 5852 | apex_key { |
| 5853 | name: "otherapex.key", |
| 5854 | public_key: "testkey.avbpubkey", |
| 5855 | private_key: "testkey.pem", |
| 5856 | } |
| 5857 | |
| 5858 | cc_library { |
| 5859 | name: "libfoo", |
| 5860 | stl: "none", |
| 5861 | system_shared_libs: [], |
| 5862 | apex_available: ["otherapex"], |
| 5863 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5864 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5865 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5866 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5867 | // libbbaz is an indirect dep |
Jiyong Park | 767dbd9 | 2021-03-04 13:03:10 +0900 | [diff] [blame] | 5868 | 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] | 5869 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5870 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5871 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5872 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5873 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 5874 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5875 | apex { |
| 5876 | name: "myapex", |
| 5877 | key: "myapex.key", |
| 5878 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5879 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5880 | } |
| 5881 | |
| 5882 | apex_key { |
| 5883 | name: "myapex.key", |
| 5884 | public_key: "testkey.avbpubkey", |
| 5885 | private_key: "testkey.pem", |
| 5886 | } |
| 5887 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5888 | cc_library { |
| 5889 | name: "libfoo", |
| 5890 | stl: "none", |
| 5891 | shared_libs: ["libbar"], |
| 5892 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5893 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | cc_library { |
| 5897 | name: "libbar", |
| 5898 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5899 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5900 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5901 | apex_available: ["myapex"], |
| 5902 | } |
| 5903 | |
| 5904 | cc_library { |
| 5905 | name: "libbaz", |
| 5906 | stl: "none", |
| 5907 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5908 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5909 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5910 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5911 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5912 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 5913 | apex { |
| 5914 | name: "myapex", |
| 5915 | key: "myapex.key", |
| 5916 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5917 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | apex_key { |
| 5921 | name: "myapex.key", |
| 5922 | public_key: "testkey.avbpubkey", |
| 5923 | private_key: "testkey.pem", |
| 5924 | } |
| 5925 | |
| 5926 | cc_library { |
| 5927 | name: "libfoo", |
| 5928 | stl: "none", |
| 5929 | system_shared_libs: [], |
| 5930 | apex_available: ["otherapex"], |
| 5931 | }`) |
| 5932 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5933 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5934 | apex { |
| 5935 | name: "myapex", |
| 5936 | key: "myapex.key", |
| 5937 | native_shared_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5938 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | apex_key { |
| 5942 | name: "myapex.key", |
| 5943 | public_key: "testkey.avbpubkey", |
| 5944 | private_key: "testkey.pem", |
| 5945 | } |
| 5946 | |
| 5947 | cc_library { |
| 5948 | name: "libfoo", |
| 5949 | stl: "none", |
| 5950 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5951 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5952 | apex_available: ["myapex"], |
| 5953 | } |
| 5954 | |
| 5955 | cc_library { |
| 5956 | name: "libbar", |
| 5957 | stl: "none", |
| 5958 | system_shared_libs: [], |
| 5959 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5960 | } |
| 5961 | |
| 5962 | cc_library { |
| 5963 | name: "libbaz", |
| 5964 | stl: "none", |
| 5965 | system_shared_libs: [], |
| 5966 | stubs: { |
| 5967 | versions: ["10", "20", "30"], |
| 5968 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5969 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5970 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5971 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5972 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5973 | ctx := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5974 | apex { |
| 5975 | name: "myapex", |
| 5976 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5977 | native_shared_libs: ["libbar", "libbaz"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5978 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5979 | } |
| 5980 | |
| 5981 | apex_key { |
| 5982 | name: "myapex.key", |
| 5983 | public_key: "testkey.avbpubkey", |
| 5984 | private_key: "testkey.pem", |
| 5985 | } |
| 5986 | |
| 5987 | cc_library { |
| 5988 | name: "libfoo", |
| 5989 | stl: "none", |
| 5990 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5991 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5992 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5993 | } |
| 5994 | |
| 5995 | cc_library { |
| 5996 | name: "libfoo2", |
| 5997 | stl: "none", |
| 5998 | system_shared_libs: [], |
| 5999 | shared_libs: ["libbaz"], |
| 6000 | apex_available: ["//apex_available:platform"], |
| 6001 | } |
| 6002 | |
| 6003 | cc_library { |
| 6004 | name: "libbar", |
| 6005 | stl: "none", |
| 6006 | system_shared_libs: [], |
| 6007 | apex_available: ["myapex"], |
| 6008 | } |
| 6009 | |
| 6010 | cc_library { |
| 6011 | name: "libbaz", |
| 6012 | stl: "none", |
| 6013 | system_shared_libs: [], |
| 6014 | apex_available: ["myapex"], |
| 6015 | stubs: { |
| 6016 | versions: ["1"], |
| 6017 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6018 | }`) |
| 6019 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6020 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 6021 | // because it depends on libbar which isn't available to platform |
| 6022 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 6023 | if libfoo.NotAvailableForPlatform() != true { |
| 6024 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 6025 | } |
| 6026 | |
| 6027 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 6028 | // stubs |
| 6029 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 6030 | if libfoo2.NotAvailableForPlatform() == true { |
| 6031 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 6032 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 6033 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 6034 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 6035 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6036 | ctx := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 6037 | apex { |
| 6038 | name: "myapex", |
| 6039 | key: "myapex.key", |
| 6040 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6041 | updatable: false, |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | apex_key { |
| 6045 | name: "myapex.key", |
| 6046 | public_key: "testkey.avbpubkey", |
| 6047 | private_key: "testkey.pem", |
| 6048 | } |
| 6049 | |
| 6050 | cc_library { |
| 6051 | name: "libfoo", |
| 6052 | stl: "none", |
| 6053 | system_shared_libs: [], |
| 6054 | apex_available: ["myapex"], |
| 6055 | static: { |
| 6056 | apex_available: ["//apex_available:platform"], |
| 6057 | }, |
| 6058 | }`) |
| 6059 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6060 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 6061 | if libfooShared.NotAvailableForPlatform() != true { |
| 6062 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 6063 | } |
| 6064 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 6065 | if libfooStatic.NotAvailableForPlatform() != false { |
| 6066 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 6067 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6068 | } |
| 6069 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6070 | func TestOverrideApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6071 | ctx := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6072 | apex { |
| 6073 | name: "myapex", |
| 6074 | key: "myapex.key", |
| 6075 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 6076 | overrides: ["oldapex"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6077 | updatable: false, |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6078 | } |
| 6079 | |
| 6080 | override_apex { |
| 6081 | name: "override_myapex", |
| 6082 | base: "myapex", |
| 6083 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 6084 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 6085 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 6086 | package_name: "test.overridden.package", |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 6087 | key: "mynewapex.key", |
| 6088 | certificate: ":myapex.certificate", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | apex_key { |
| 6092 | name: "myapex.key", |
| 6093 | public_key: "testkey.avbpubkey", |
| 6094 | private_key: "testkey.pem", |
| 6095 | } |
| 6096 | |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 6097 | apex_key { |
| 6098 | name: "mynewapex.key", |
| 6099 | public_key: "testkey2.avbpubkey", |
| 6100 | private_key: "testkey2.pem", |
| 6101 | } |
| 6102 | |
| 6103 | android_app_certificate { |
| 6104 | name: "myapex.certificate", |
| 6105 | certificate: "testkey", |
| 6106 | } |
| 6107 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6108 | android_app { |
| 6109 | name: "app", |
| 6110 | srcs: ["foo/bar/MyClass.java"], |
| 6111 | package_name: "foo", |
| 6112 | sdk_version: "none", |
| 6113 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6114 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6115 | } |
| 6116 | |
| 6117 | override_android_app { |
| 6118 | name: "override_app", |
| 6119 | base: "app", |
| 6120 | package_name: "bar", |
| 6121 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 6122 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6123 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 6124 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 6125 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 6126 | if originalVariant.GetOverriddenBy() != "" { |
| 6127 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 6128 | } |
| 6129 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 6130 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 6131 | } |
| 6132 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6133 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 6134 | apexRule := module.Rule("apexRule") |
| 6135 | copyCmds := apexRule.Args["copy_commands"] |
| 6136 | |
| 6137 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 6138 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6139 | |
| 6140 | apexBundle := module.Module().(*apexBundle) |
| 6141 | name := apexBundle.Name() |
| 6142 | if name != "override_myapex" { |
| 6143 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 6144 | } |
| 6145 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 6146 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 6147 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 6148 | } |
| 6149 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 6150 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 6151 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 6152 | ensureContains(t, optFlags, "--pubkey testkey2.avbpubkey") |
| 6153 | |
| 6154 | signApkRule := module.Rule("signapk") |
| 6155 | ensureEquals(t, signApkRule.Args["certificates"], "testkey.x509.pem testkey.pk8") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 6156 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6157 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6158 | var builder strings.Builder |
| 6159 | data.Custom(&builder, name, "TARGET_", "", data) |
| 6160 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 6161 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6162 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 6163 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 6164 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6165 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 6166 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6167 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 6168 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6169 | } |
| 6170 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6171 | func TestLegacyAndroid10Support(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6172 | ctx := testApex(t, ` |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6173 | apex { |
| 6174 | name: "myapex", |
| 6175 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6176 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 6177 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | apex_key { |
| 6181 | name: "myapex.key", |
| 6182 | public_key: "testkey.avbpubkey", |
| 6183 | private_key: "testkey.pem", |
| 6184 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6185 | |
| 6186 | cc_library { |
| 6187 | name: "mylib", |
| 6188 | srcs: ["mylib.cpp"], |
| 6189 | stl: "libc++", |
| 6190 | system_shared_libs: [], |
| 6191 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6192 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6193 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6194 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6195 | |
| 6196 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 6197 | args := module.Rule("apexRule").Args |
| 6198 | 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] | 6199 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6200 | |
| 6201 | // The copies of the libraries in the apex should have one more dependency than |
| 6202 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 6203 | // the dependency names directly here but for some reason the names are blank in |
| 6204 | // this test. |
| 6205 | for _, lib := range []string{"libc++", "mylib"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6206 | 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] | 6207 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 6208 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 6209 | t.Errorf("%q missing unwinder dep", lib) |
| 6210 | } |
| 6211 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6212 | } |
| 6213 | |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 6214 | var filesForSdkLibrary = android.MockFS{ |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6215 | "api/current.txt": nil, |
| 6216 | "api/removed.txt": nil, |
| 6217 | "api/system-current.txt": nil, |
| 6218 | "api/system-removed.txt": nil, |
| 6219 | "api/test-current.txt": nil, |
| 6220 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6221 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6222 | "100/public/api/foo.txt": nil, |
| 6223 | "100/public/api/foo-removed.txt": nil, |
| 6224 | "100/system/api/foo.txt": nil, |
| 6225 | "100/system/api/foo-removed.txt": nil, |
| 6226 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6227 | // For java_sdk_library_import |
| 6228 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6229 | } |
| 6230 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6231 | func TestJavaSDKLibrary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6232 | ctx := testApex(t, ` |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6233 | apex { |
| 6234 | name: "myapex", |
| 6235 | key: "myapex.key", |
| 6236 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6237 | updatable: false, |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | apex_key { |
| 6241 | name: "myapex.key", |
| 6242 | public_key: "testkey.avbpubkey", |
| 6243 | private_key: "testkey.pem", |
| 6244 | } |
| 6245 | |
| 6246 | java_sdk_library { |
| 6247 | name: "foo", |
| 6248 | srcs: ["a.java"], |
| 6249 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6250 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6251 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6252 | |
| 6253 | prebuilt_apis { |
| 6254 | name: "sdk", |
| 6255 | api_dirs: ["100"], |
| 6256 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6257 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6258 | |
| 6259 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6260 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6261 | "javalib/foo.jar", |
| 6262 | "etc/permissions/foo.xml", |
| 6263 | }) |
| 6264 | // 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] | 6265 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 6266 | 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] | 6267 | } |
| 6268 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6269 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6270 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6271 | apex { |
| 6272 | name: "myapex", |
| 6273 | key: "myapex.key", |
| 6274 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6275 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6276 | } |
| 6277 | |
| 6278 | apex_key { |
| 6279 | name: "myapex.key", |
| 6280 | public_key: "testkey.avbpubkey", |
| 6281 | private_key: "testkey.pem", |
| 6282 | } |
| 6283 | |
| 6284 | java_sdk_library { |
| 6285 | name: "foo", |
| 6286 | srcs: ["a.java"], |
| 6287 | api_packages: ["foo"], |
| 6288 | apex_available: ["myapex"], |
| 6289 | sdk_version: "none", |
| 6290 | system_modules: "none", |
| 6291 | } |
| 6292 | |
| 6293 | java_library { |
| 6294 | name: "bar", |
| 6295 | srcs: ["a.java"], |
| 6296 | libs: ["foo"], |
| 6297 | apex_available: ["myapex"], |
| 6298 | sdk_version: "none", |
| 6299 | system_modules: "none", |
| 6300 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6301 | |
| 6302 | prebuilt_apis { |
| 6303 | name: "sdk", |
| 6304 | api_dirs: ["100"], |
| 6305 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6306 | `, withFiles(filesForSdkLibrary)) |
| 6307 | |
| 6308 | // java_sdk_library installs both impl jar and permission XML |
| 6309 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6310 | "javalib/bar.jar", |
| 6311 | "javalib/foo.jar", |
| 6312 | "etc/permissions/foo.xml", |
| 6313 | }) |
| 6314 | |
| 6315 | // The bar library should depend on the implementation jar. |
| 6316 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 6317 | 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] | 6318 | t.Errorf("expected %q, found %#q", expected, actual) |
| 6319 | } |
| 6320 | } |
| 6321 | |
| 6322 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6323 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6324 | apex { |
| 6325 | name: "myapex", |
| 6326 | key: "myapex.key", |
| 6327 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6328 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | apex_key { |
| 6332 | name: "myapex.key", |
| 6333 | public_key: "testkey.avbpubkey", |
| 6334 | private_key: "testkey.pem", |
| 6335 | } |
| 6336 | |
| 6337 | java_sdk_library { |
| 6338 | name: "foo", |
| 6339 | srcs: ["a.java"], |
| 6340 | api_packages: ["foo"], |
| 6341 | apex_available: ["myapex"], |
| 6342 | sdk_version: "none", |
| 6343 | system_modules: "none", |
| 6344 | } |
| 6345 | |
| 6346 | java_library { |
| 6347 | name: "bar", |
| 6348 | srcs: ["a.java"], |
| 6349 | libs: ["foo"], |
| 6350 | sdk_version: "none", |
| 6351 | system_modules: "none", |
| 6352 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6353 | |
| 6354 | prebuilt_apis { |
| 6355 | name: "sdk", |
| 6356 | api_dirs: ["100"], |
| 6357 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6358 | `, withFiles(filesForSdkLibrary)) |
| 6359 | |
| 6360 | // java_sdk_library installs both impl jar and permission XML |
| 6361 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6362 | "javalib/foo.jar", |
| 6363 | "etc/permissions/foo.xml", |
| 6364 | }) |
| 6365 | |
| 6366 | // The bar library should depend on the stubs jar. |
| 6367 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 6368 | 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] | 6369 | t.Errorf("expected %q, found %#q", expected, actual) |
| 6370 | } |
| 6371 | } |
| 6372 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6373 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6374 | ctx := testApex(t, ` |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6375 | prebuilt_apis { |
| 6376 | name: "sdk", |
| 6377 | api_dirs: ["100"], |
| 6378 | }`, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6379 | withFiles(map[string][]byte{ |
| 6380 | "apex/a.java": nil, |
| 6381 | "apex/apex_manifest.json": nil, |
| 6382 | "apex/Android.bp": []byte(` |
| 6383 | package { |
| 6384 | default_visibility: ["//visibility:private"], |
| 6385 | } |
| 6386 | |
| 6387 | apex { |
| 6388 | name: "myapex", |
| 6389 | key: "myapex.key", |
| 6390 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6391 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6392 | } |
| 6393 | |
| 6394 | apex_key { |
| 6395 | name: "myapex.key", |
| 6396 | public_key: "testkey.avbpubkey", |
| 6397 | private_key: "testkey.pem", |
| 6398 | } |
| 6399 | |
| 6400 | java_library { |
| 6401 | name: "bar", |
| 6402 | srcs: ["a.java"], |
| 6403 | libs: ["foo"], |
| 6404 | apex_available: ["myapex"], |
| 6405 | sdk_version: "none", |
| 6406 | system_modules: "none", |
| 6407 | } |
| 6408 | `), |
| 6409 | "source/a.java": nil, |
| 6410 | "source/api/current.txt": nil, |
| 6411 | "source/api/removed.txt": nil, |
| 6412 | "source/Android.bp": []byte(` |
| 6413 | package { |
| 6414 | default_visibility: ["//visibility:private"], |
| 6415 | } |
| 6416 | |
| 6417 | java_sdk_library { |
| 6418 | name: "foo", |
| 6419 | visibility: ["//apex"], |
| 6420 | srcs: ["a.java"], |
| 6421 | api_packages: ["foo"], |
| 6422 | apex_available: ["myapex"], |
| 6423 | sdk_version: "none", |
| 6424 | system_modules: "none", |
| 6425 | public: { |
| 6426 | enabled: true, |
| 6427 | }, |
| 6428 | } |
| 6429 | `), |
| 6430 | "prebuilt/a.jar": nil, |
| 6431 | "prebuilt/Android.bp": []byte(` |
| 6432 | package { |
| 6433 | default_visibility: ["//visibility:private"], |
| 6434 | } |
| 6435 | |
| 6436 | java_sdk_library_import { |
| 6437 | name: "foo", |
| 6438 | visibility: ["//apex", "//source"], |
| 6439 | apex_available: ["myapex"], |
| 6440 | prefer: true, |
| 6441 | public: { |
| 6442 | jars: ["a.jar"], |
| 6443 | }, |
| 6444 | } |
| 6445 | `), |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6446 | }), withFiles(filesForSdkLibrary), |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6447 | ) |
| 6448 | |
| 6449 | // java_sdk_library installs both impl jar and permission XML |
| 6450 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6451 | "javalib/bar.jar", |
| 6452 | "javalib/foo.jar", |
| 6453 | "etc/permissions/foo.xml", |
| 6454 | }) |
| 6455 | |
| 6456 | // The bar library should depend on the implementation jar. |
| 6457 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 6458 | 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] | 6459 | t.Errorf("expected %q, found %#q", expected, actual) |
| 6460 | } |
| 6461 | } |
| 6462 | |
| 6463 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 6464 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 6465 | apex { |
| 6466 | name: "myapex", |
| 6467 | key: "myapex.key", |
| 6468 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6469 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6470 | } |
| 6471 | |
| 6472 | apex_key { |
| 6473 | name: "myapex.key", |
| 6474 | public_key: "testkey.avbpubkey", |
| 6475 | private_key: "testkey.pem", |
| 6476 | } |
| 6477 | |
| 6478 | java_sdk_library_import { |
| 6479 | name: "foo", |
| 6480 | apex_available: ["myapex"], |
| 6481 | prefer: true, |
| 6482 | public: { |
| 6483 | jars: ["a.jar"], |
| 6484 | }, |
| 6485 | } |
| 6486 | |
| 6487 | `, withFiles(filesForSdkLibrary)) |
| 6488 | } |
| 6489 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6490 | func TestCompatConfig(t *testing.T) { |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 6491 | result := android.GroupFixturePreparers( |
| 6492 | prepareForApexTest, |
| 6493 | java.PrepareForTestWithPlatformCompatConfig, |
| 6494 | ).RunTestWithBp(t, ` |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6495 | apex { |
| 6496 | name: "myapex", |
| 6497 | key: "myapex.key", |
Paul Duffin | 3abc174 | 2021-03-15 19:32:23 +0000 | [diff] [blame] | 6498 | compat_configs: ["myjar-platform-compat-config"], |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6499 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6500 | updatable: false, |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6501 | } |
| 6502 | |
| 6503 | apex_key { |
| 6504 | name: "myapex.key", |
| 6505 | public_key: "testkey.avbpubkey", |
| 6506 | private_key: "testkey.pem", |
| 6507 | } |
| 6508 | |
| 6509 | platform_compat_config { |
| 6510 | name: "myjar-platform-compat-config", |
| 6511 | src: ":myjar", |
| 6512 | } |
| 6513 | |
| 6514 | java_library { |
| 6515 | name: "myjar", |
| 6516 | srcs: ["foo/bar/MyClass.java"], |
| 6517 | sdk_version: "none", |
| 6518 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6519 | apex_available: [ "myapex" ], |
| 6520 | } |
Paul Duffin | 1b29e00 | 2021-03-16 15:06:54 +0000 | [diff] [blame] | 6521 | |
| 6522 | // Make sure that a preferred prebuilt does not affect the apex contents. |
| 6523 | prebuilt_platform_compat_config { |
| 6524 | name: "myjar-platform-compat-config", |
| 6525 | metadata: "compat-config/metadata.xml", |
| 6526 | prefer: true, |
| 6527 | } |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6528 | `) |
Paul Duffin | a369c7b | 2021-03-09 03:08:05 +0000 | [diff] [blame] | 6529 | ctx := result.TestContext |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6530 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6531 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 6532 | "javalib/myjar.jar", |
| 6533 | }) |
| 6534 | } |
| 6535 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6536 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 6537 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 6538 | apex { |
| 6539 | name: "myapex", |
| 6540 | key: "myapex.key", |
| 6541 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6542 | updatable: false, |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6543 | } |
| 6544 | |
| 6545 | apex_key { |
| 6546 | name: "myapex.key", |
| 6547 | public_key: "testkey.avbpubkey", |
| 6548 | private_key: "testkey.pem", |
| 6549 | } |
| 6550 | |
| 6551 | java_library { |
| 6552 | name: "myjar", |
| 6553 | srcs: ["foo/bar/MyClass.java"], |
| 6554 | sdk_version: "none", |
| 6555 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 6556 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 6557 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6558 | } |
| 6559 | `) |
| 6560 | } |
| 6561 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6562 | func TestCarryRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6563 | ctx := testApex(t, ` |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6564 | apex { |
| 6565 | name: "myapex", |
| 6566 | key: "myapex.key", |
| 6567 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6568 | updatable: false, |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6569 | } |
| 6570 | |
| 6571 | apex_key { |
| 6572 | name: "myapex.key", |
| 6573 | public_key: "testkey.avbpubkey", |
| 6574 | private_key: "testkey.pem", |
| 6575 | } |
| 6576 | |
| 6577 | cc_library { |
| 6578 | name: "mylib", |
| 6579 | srcs: ["mylib.cpp"], |
| 6580 | system_shared_libs: [], |
| 6581 | stl: "none", |
| 6582 | required: ["a", "b"], |
| 6583 | host_required: ["c", "d"], |
| 6584 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6585 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6586 | } |
| 6587 | `) |
| 6588 | |
| 6589 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6590 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6591 | name := apexBundle.BaseModuleName() |
| 6592 | prefix := "TARGET_" |
| 6593 | var builder strings.Builder |
| 6594 | data.Custom(&builder, name, prefix, "", data) |
| 6595 | androidMk := builder.String() |
| 6596 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 6597 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 6598 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 6599 | } |
| 6600 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6601 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 6602 | bp := ` |
| 6603 | apex { |
| 6604 | name: "myapex", |
| 6605 | key: "myapex.key", |
| 6606 | native_shared_libs: ["mylib"], |
| 6607 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6608 | updatable: false, |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6609 | } |
| 6610 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6611 | apex { |
| 6612 | name: "myapex.updatable", |
| 6613 | key: "myapex.key", |
| 6614 | native_shared_libs: ["mylib"], |
| 6615 | java_libs: ["myjar"], |
| 6616 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6617 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6618 | } |
| 6619 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6620 | apex_key { |
| 6621 | name: "myapex.key", |
| 6622 | public_key: "testkey.avbpubkey", |
| 6623 | private_key: "testkey.pem", |
| 6624 | } |
| 6625 | |
| 6626 | cc_library { |
| 6627 | name: "mylib", |
| 6628 | srcs: ["mylib.cpp"], |
| 6629 | shared_libs: ["myotherlib"], |
| 6630 | system_shared_libs: [], |
| 6631 | stl: "none", |
| 6632 | apex_available: [ |
| 6633 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6634 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6635 | "//apex_available:platform", |
| 6636 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6637 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6638 | } |
| 6639 | |
| 6640 | cc_library { |
| 6641 | name: "myotherlib", |
| 6642 | srcs: ["mylib.cpp"], |
| 6643 | system_shared_libs: [], |
| 6644 | stl: "none", |
| 6645 | apex_available: [ |
| 6646 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6647 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6648 | "//apex_available:platform", |
| 6649 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6650 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6651 | } |
| 6652 | |
| 6653 | java_library { |
| 6654 | name: "myjar", |
| 6655 | srcs: ["foo/bar/MyClass.java"], |
| 6656 | sdk_version: "none", |
| 6657 | system_modules: "none", |
| 6658 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6659 | apex_available: [ |
| 6660 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6661 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6662 | "//apex_available:platform", |
| 6663 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6664 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6665 | } |
| 6666 | |
| 6667 | java_library { |
| 6668 | name: "myotherjar", |
| 6669 | srcs: ["foo/bar/MyClass.java"], |
| 6670 | sdk_version: "none", |
| 6671 | system_modules: "none", |
| 6672 | apex_available: [ |
| 6673 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6674 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6675 | "//apex_available:platform", |
| 6676 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6677 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6678 | } |
| 6679 | ` |
| 6680 | |
| 6681 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 6682 | for _, f := range files { |
| 6683 | if f.path == file { |
| 6684 | if f.isLink { |
| 6685 | t.Errorf("%q is not a real file", file) |
| 6686 | } |
| 6687 | return |
| 6688 | } |
| 6689 | } |
| 6690 | t.Errorf("%q is not found", file) |
| 6691 | } |
| 6692 | |
| 6693 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 6694 | for _, f := range files { |
| 6695 | if f.path == file { |
| 6696 | if !f.isLink { |
| 6697 | t.Errorf("%q is not a symlink", file) |
| 6698 | } |
| 6699 | return |
| 6700 | } |
| 6701 | } |
| 6702 | t.Errorf("%q is not found", file) |
| 6703 | } |
| 6704 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6705 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 6706 | // is updatable or not |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6707 | ctx := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6708 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6709 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6710 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6711 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6712 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6713 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6714 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6715 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6716 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6717 | |
| 6718 | // 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] | 6719 | ctx = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6720 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6721 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6722 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6723 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6724 | |
| 6725 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6726 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6727 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6728 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6729 | } |
| 6730 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6731 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6732 | ctx := testApex(t, ` |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6733 | apex { |
| 6734 | name: "myapex", |
| 6735 | key: "myapex.key", |
| 6736 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6737 | updatable: false, |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | apex_key { |
| 6741 | name: "myapex.key", |
| 6742 | public_key: "testkey.avbpubkey", |
| 6743 | private_key: "testkey.pem", |
| 6744 | } |
| 6745 | |
| 6746 | cc_library_shared { |
| 6747 | name: "mylib", |
| 6748 | srcs: ["mylib.cpp"], |
| 6749 | shared_libs: ["myotherlib"], |
| 6750 | system_shared_libs: [], |
| 6751 | stl: "none", |
| 6752 | apex_available: [ |
| 6753 | "myapex", |
| 6754 | "//apex_available:platform", |
| 6755 | ], |
| 6756 | } |
| 6757 | |
| 6758 | cc_prebuilt_library_shared { |
| 6759 | name: "myotherlib", |
| 6760 | srcs: ["prebuilt.so"], |
| 6761 | system_shared_libs: [], |
| 6762 | stl: "none", |
| 6763 | apex_available: [ |
| 6764 | "myapex", |
| 6765 | "//apex_available:platform", |
| 6766 | ], |
| 6767 | } |
| 6768 | `) |
| 6769 | |
| 6770 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6771 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6772 | var builder strings.Builder |
| 6773 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 6774 | androidMk := builder.String() |
| 6775 | // `myotherlib` is added to `myapex` as symlink |
| 6776 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 6777 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 6778 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 6779 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 6780 | 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] | 6781 | } |
| 6782 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6783 | func TestApexWithJniLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6784 | ctx := testApex(t, ` |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6785 | apex { |
| 6786 | name: "myapex", |
| 6787 | key: "myapex.key", |
| 6788 | jni_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6789 | updatable: false, |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6790 | } |
| 6791 | |
| 6792 | apex_key { |
| 6793 | name: "myapex.key", |
| 6794 | public_key: "testkey.avbpubkey", |
| 6795 | private_key: "testkey.pem", |
| 6796 | } |
| 6797 | |
| 6798 | cc_library { |
| 6799 | name: "mylib", |
| 6800 | srcs: ["mylib.cpp"], |
| 6801 | shared_libs: ["mylib2"], |
| 6802 | system_shared_libs: [], |
| 6803 | stl: "none", |
| 6804 | apex_available: [ "myapex" ], |
| 6805 | } |
| 6806 | |
| 6807 | cc_library { |
| 6808 | name: "mylib2", |
| 6809 | srcs: ["mylib.cpp"], |
| 6810 | system_shared_libs: [], |
| 6811 | stl: "none", |
| 6812 | apex_available: [ "myapex" ], |
| 6813 | } |
| 6814 | `) |
| 6815 | |
| 6816 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 6817 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 6818 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 6819 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6820 | "lib64/mylib.so", |
| 6821 | "lib64/mylib2.so", |
| 6822 | }) |
| 6823 | } |
| 6824 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6825 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6826 | ctx := testApex(t, ` |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6827 | apex { |
| 6828 | name: "myapex", |
| 6829 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6830 | updatable: false, |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6831 | } |
| 6832 | apex_key { |
| 6833 | name: "myapex.key", |
| 6834 | public_key: "testkey.avbpubkey", |
| 6835 | private_key: "testkey.pem", |
| 6836 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 6837 | `, |
| 6838 | android.FixtureModifyConfig(func(config android.Config) { |
| 6839 | delete(config.Targets, android.Android) |
| 6840 | config.AndroidCommonTarget = android.Target{} |
| 6841 | }), |
| 6842 | ) |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6843 | |
| 6844 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 6845 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 6846 | } |
| 6847 | } |
| 6848 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6849 | func TestAppBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6850 | ctx := testApex(t, ` |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6851 | apex { |
| 6852 | name: "myapex", |
| 6853 | key: "myapex.key", |
| 6854 | apps: ["AppFoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6855 | updatable: false, |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6856 | } |
| 6857 | |
| 6858 | apex_key { |
| 6859 | name: "myapex.key", |
| 6860 | public_key: "testkey.avbpubkey", |
| 6861 | private_key: "testkey.pem", |
| 6862 | } |
| 6863 | |
| 6864 | android_app { |
| 6865 | name: "AppFoo", |
| 6866 | srcs: ["foo/bar/MyClass.java"], |
| 6867 | sdk_version: "none", |
| 6868 | system_modules: "none", |
| 6869 | apex_available: [ "myapex" ], |
| 6870 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6871 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6872 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6873 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json") |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6874 | content := bundleConfigRule.Args["content"] |
| 6875 | |
| 6876 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6877 | 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] | 6878 | } |
| 6879 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6880 | func TestAppSetBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6881 | ctx := testApex(t, ` |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6882 | apex { |
| 6883 | name: "myapex", |
| 6884 | key: "myapex.key", |
| 6885 | apps: ["AppSet"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6886 | updatable: false, |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6887 | } |
| 6888 | |
| 6889 | apex_key { |
| 6890 | name: "myapex.key", |
| 6891 | public_key: "testkey.avbpubkey", |
| 6892 | private_key: "testkey.pem", |
| 6893 | } |
| 6894 | |
| 6895 | android_app_set { |
| 6896 | name: "AppSet", |
| 6897 | set: "AppSet.apks", |
| 6898 | }`) |
| 6899 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6900 | bundleConfigRule := mod.Output("bundle_config.json") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6901 | content := bundleConfigRule.Args["content"] |
| 6902 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 6903 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 6904 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 6905 | if len(copyCmds) != 3 { |
| 6906 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 6907 | } |
| 6908 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 6909 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 6910 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 6911 | } |
| 6912 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6913 | func TestAppSetBundlePrebuilt(t *testing.T) { |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6914 | bp := ` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6915 | apex_set { |
| 6916 | name: "myapex", |
| 6917 | filename: "foo_v2.apex", |
| 6918 | sanitized: { |
| 6919 | none: { set: "myapex.apks", }, |
| 6920 | hwaddress: { set: "myapex.hwasan.apks", }, |
| 6921 | }, |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6922 | } |
| 6923 | ` |
| 6924 | ctx := testApex(t, bp, prepareForTestWithSantitizeHwaddress) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6925 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6926 | // Check that the extractor produces the correct output file from the correct input file. |
| 6927 | 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] | 6928 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6929 | m := ctx.ModuleForTests("myapex.apex.extractor", "android_common") |
| 6930 | extractedApex := m.Output(extractorOutput) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6931 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6932 | android.AssertArrayString(t, "extractor input", []string{"myapex.hwasan.apks"}, extractedApex.Inputs.Strings()) |
| 6933 | |
| 6934 | // Ditto for the apex. |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 6935 | m = ctx.ModuleForTests("myapex", "android_common_myapex") |
| 6936 | copiedApex := m.Output("out/soong/.intermediates/myapex/android_common_myapex/foo_v2.apex") |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 6937 | |
| 6938 | android.AssertStringEquals(t, "myapex input", extractorOutput, copiedApex.Input.String()) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6939 | } |
| 6940 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 6941 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, preparer android.FixturePreparer, fragments ...java.ApexVariantReference) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6942 | t.Helper() |
| 6943 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6944 | bp := ` |
| 6945 | java_library { |
| 6946 | name: "some-updatable-apex-lib", |
| 6947 | srcs: ["a.java"], |
| 6948 | sdk_version: "current", |
| 6949 | apex_available: [ |
| 6950 | "some-updatable-apex", |
| 6951 | ], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 6952 | permitted_packages: ["some.updatable.apex.lib"], |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6953 | } |
| 6954 | |
| 6955 | java_library { |
| 6956 | name: "some-non-updatable-apex-lib", |
| 6957 | srcs: ["a.java"], |
| 6958 | apex_available: [ |
| 6959 | "some-non-updatable-apex", |
| 6960 | ], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 6961 | compile_dex: true, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 6962 | permitted_packages: ["some.non.updatable.apex.lib"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | bootclasspath_fragment { |
| 6966 | name: "some-non-updatable-fragment", |
| 6967 | contents: ["some-non-updatable-apex-lib"], |
| 6968 | apex_available: [ |
| 6969 | "some-non-updatable-apex", |
| 6970 | ], |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6971 | } |
| 6972 | |
| 6973 | java_library { |
| 6974 | name: "some-platform-lib", |
| 6975 | srcs: ["a.java"], |
| 6976 | sdk_version: "current", |
| 6977 | installable: true, |
| 6978 | } |
| 6979 | |
| 6980 | java_library { |
| 6981 | name: "some-art-lib", |
| 6982 | srcs: ["a.java"], |
| 6983 | sdk_version: "current", |
| 6984 | apex_available: [ |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6985 | "com.android.art.debug", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6986 | ], |
| 6987 | hostdex: true, |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 6988 | compile_dex: true, |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6989 | } |
| 6990 | |
| 6991 | apex { |
| 6992 | name: "some-updatable-apex", |
| 6993 | key: "some-updatable-apex.key", |
| 6994 | java_libs: ["some-updatable-apex-lib"], |
| 6995 | updatable: true, |
| 6996 | min_sdk_version: "current", |
| 6997 | } |
| 6998 | |
| 6999 | apex { |
| 7000 | name: "some-non-updatable-apex", |
| 7001 | key: "some-non-updatable-apex.key", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7002 | bootclasspath_fragments: ["some-non-updatable-fragment"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7003 | updatable: false, |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7004 | } |
| 7005 | |
| 7006 | apex_key { |
| 7007 | name: "some-updatable-apex.key", |
| 7008 | } |
| 7009 | |
| 7010 | apex_key { |
| 7011 | name: "some-non-updatable-apex.key", |
| 7012 | } |
| 7013 | |
| 7014 | apex { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7015 | name: "com.android.art.debug", |
| 7016 | key: "com.android.art.debug.key", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7017 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7018 | updatable: true, |
| 7019 | min_sdk_version: "current", |
| 7020 | } |
| 7021 | |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 7022 | bootclasspath_fragment { |
| 7023 | name: "art-bootclasspath-fragment", |
| 7024 | image_name: "art", |
| 7025 | contents: ["some-art-lib"], |
| 7026 | apex_available: [ |
| 7027 | "com.android.art.debug", |
| 7028 | ], |
| 7029 | } |
| 7030 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7031 | apex_key { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7032 | name: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7033 | } |
| 7034 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7035 | filegroup { |
| 7036 | name: "some-updatable-apex-file_contexts", |
| 7037 | srcs: [ |
| 7038 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 7039 | ], |
| 7040 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 7041 | |
| 7042 | filegroup { |
| 7043 | name: "some-non-updatable-apex-file_contexts", |
| 7044 | srcs: [ |
| 7045 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 7046 | ], |
| 7047 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7048 | ` |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 7049 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7050 | testDexpreoptWithApexes(t, bp, errmsg, preparer, fragments...) |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 7051 | } |
| 7052 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7053 | func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, preparer android.FixturePreparer, fragments ...java.ApexVariantReference) *android.TestContext { |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 7054 | t.Helper() |
| 7055 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7056 | fs := android.MockFS{ |
| 7057 | "a.java": nil, |
| 7058 | "a.jar": nil, |
| 7059 | "apex_manifest.json": nil, |
| 7060 | "AndroidManifest.xml": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 7061 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7062 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
| 7063 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
| 7064 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 7065 | "framework/aidl/a.aidl": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7066 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7067 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7068 | errorHandler := android.FixtureExpectsNoErrors |
| 7069 | if errmsg != "" { |
| 7070 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7071 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7072 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7073 | result := android.GroupFixturePreparers( |
| 7074 | cc.PrepareForTestWithCcDefaultModules, |
| 7075 | java.PrepareForTestWithHiddenApiBuildComponents, |
| 7076 | java.PrepareForTestWithJavaDefaultModules, |
| 7077 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 7078 | PrepareForTestWithApexBuildComponents, |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7079 | preparer, |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7080 | fs.AddToFixture(), |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7081 | android.FixtureModifyMockFS(func(fs android.MockFS) { |
| 7082 | if _, ok := fs["frameworks/base/boot/Android.bp"]; !ok { |
| 7083 | insert := "" |
| 7084 | for _, fragment := range fragments { |
| 7085 | insert += fmt.Sprintf("{apex: %q, module: %q},\n", *fragment.Apex, *fragment.Module) |
| 7086 | } |
| 7087 | fs["frameworks/base/boot/Android.bp"] = []byte(fmt.Sprintf(` |
| 7088 | platform_bootclasspath { |
| 7089 | name: "platform-bootclasspath", |
| 7090 | fragments: [ |
| 7091 | %s |
| 7092 | ], |
| 7093 | } |
| 7094 | `, insert)) |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 7095 | } |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7096 | }), |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7097 | ). |
| 7098 | ExtendWithErrorHandler(errorHandler). |
| 7099 | RunTestWithBp(t, bp) |
| 7100 | |
| 7101 | return result.TestContext |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7102 | } |
| 7103 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 7104 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 7105 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 7106 | apex { |
| 7107 | name: "myapex", |
| 7108 | key: "myapex.key", |
| 7109 | updatable: true, |
| 7110 | } |
| 7111 | |
| 7112 | apex_key { |
| 7113 | name: "myapex.key", |
| 7114 | public_key: "testkey.avbpubkey", |
| 7115 | private_key: "testkey.pem", |
| 7116 | } |
| 7117 | `) |
| 7118 | } |
| 7119 | |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7120 | func TestUpdatableDefault_should_set_min_sdk_version(t *testing.T) { |
| 7121 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 7122 | apex { |
| 7123 | name: "myapex", |
| 7124 | key: "myapex.key", |
| 7125 | } |
| 7126 | |
| 7127 | apex_key { |
| 7128 | name: "myapex.key", |
| 7129 | public_key: "testkey.avbpubkey", |
| 7130 | private_key: "testkey.pem", |
| 7131 | } |
| 7132 | `) |
| 7133 | } |
| 7134 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 7135 | func TestUpdatable_should_not_set_generate_classpaths_proto(t *testing.T) { |
| 7136 | testApexError(t, `"mysystemserverclasspathfragment" .* it must not set generate_classpaths_proto to false`, ` |
| 7137 | apex { |
| 7138 | name: "myapex", |
| 7139 | key: "myapex.key", |
| 7140 | systemserverclasspath_fragments: [ |
| 7141 | "mysystemserverclasspathfragment", |
| 7142 | ], |
| 7143 | min_sdk_version: "29", |
| 7144 | updatable: true, |
| 7145 | } |
| 7146 | |
| 7147 | apex_key { |
| 7148 | name: "myapex.key", |
| 7149 | public_key: "testkey.avbpubkey", |
| 7150 | private_key: "testkey.pem", |
| 7151 | } |
| 7152 | |
| 7153 | java_library { |
| 7154 | name: "foo", |
| 7155 | srcs: ["b.java"], |
| 7156 | min_sdk_version: "29", |
| 7157 | installable: true, |
| 7158 | apex_available: [ |
| 7159 | "myapex", |
| 7160 | ], |
| 7161 | } |
| 7162 | |
| 7163 | systemserverclasspath_fragment { |
| 7164 | name: "mysystemserverclasspathfragment", |
| 7165 | generate_classpaths_proto: false, |
| 7166 | contents: [ |
| 7167 | "foo", |
| 7168 | ], |
| 7169 | apex_available: [ |
| 7170 | "myapex", |
| 7171 | ], |
| 7172 | } |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7173 | `, |
| 7174 | dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), |
| 7175 | ) |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 7176 | } |
| 7177 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7178 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7179 | // Set the BootJars in dexpreopt.GlobalConfig and productVariables to the same value. This can |
| 7180 | // result in an invalid configuration as it does not set the ArtApexJars and allows art apex |
| 7181 | // modules to be included in the BootJars. |
| 7182 | prepareSetBootJars := func(bootJars ...string) android.FixturePreparer { |
| 7183 | return android.GroupFixturePreparers( |
| 7184 | dexpreopt.FixtureSetBootJars(bootJars...), |
| 7185 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7186 | variables.BootJars = android.CreateTestConfiguredJarList(bootJars) |
| 7187 | }), |
| 7188 | ) |
| 7189 | } |
| 7190 | |
| 7191 | // Set the ArtApexJars and BootJars in dexpreopt.GlobalConfig and productVariables all to the |
| 7192 | // same value. This can result in an invalid configuration as it allows non art apex jars to be |
| 7193 | // specified in the ArtApexJars configuration. |
| 7194 | prepareSetArtJars := func(bootJars ...string) android.FixturePreparer { |
| 7195 | return android.GroupFixturePreparers( |
| 7196 | dexpreopt.FixtureSetArtBootJars(bootJars...), |
| 7197 | dexpreopt.FixtureSetBootJars(bootJars...), |
| 7198 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7199 | variables.BootJars = android.CreateTestConfiguredJarList(bootJars) |
| 7200 | }), |
| 7201 | ) |
| 7202 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7203 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7204 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7205 | preparer := android.GroupFixturePreparers( |
| 7206 | java.FixtureConfigureBootJars("com.android.art.debug:some-art-lib"), |
| 7207 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7208 | ) |
| 7209 | fragments := []java.ApexVariantReference{ |
| 7210 | { |
| 7211 | Apex: proptools.StringPtr("com.android.art.debug"), |
| 7212 | Module: proptools.StringPtr("art-bootclasspath-fragment"), |
| 7213 | }, |
| 7214 | { |
| 7215 | Apex: proptools.StringPtr("some-non-updatable-apex"), |
| 7216 | Module: proptools.StringPtr("some-non-updatable-fragment"), |
| 7217 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7218 | } |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7219 | testNoUpdatableJarsInBootImage(t, "", preparer, fragments...) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7220 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7221 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7222 | 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] | 7223 | err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image` |
| 7224 | // Update the dexpreopt BootJars directly. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7225 | preparer := android.GroupFixturePreparers( |
| 7226 | prepareSetBootJars("com.android.art.debug:some-art-lib"), |
| 7227 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7228 | ) |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7229 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7230 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7231 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7232 | t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 7233 | err := `ArtApexJars expects this to be in apex "some-updatable-apex" but this is only in apexes.*"com.android.art.debug"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7234 | // Update the dexpreopt ArtApexJars directly. |
| 7235 | preparer := prepareSetArtJars("some-updatable-apex:some-updatable-apex-lib") |
| 7236 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7237 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7238 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7239 | t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 7240 | err := `ArtApexJars expects this to be in apex "some-non-updatable-apex" but this is only in apexes.*"com.android.art.debug"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7241 | // Update the dexpreopt ArtApexJars directly. |
| 7242 | preparer := prepareSetArtJars("some-non-updatable-apex:some-non-updatable-apex-lib") |
| 7243 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7244 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 7245 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7246 | 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] | 7247 | err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image` |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7248 | preparer := android.GroupFixturePreparers( |
| 7249 | java.FixtureConfigureBootJars("some-updatable-apex:some-updatable-apex-lib"), |
| 7250 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7251 | ) |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7252 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7253 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7254 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7255 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7256 | preparer := java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib") |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7257 | fragment := java.ApexVariantReference{ |
| 7258 | Apex: proptools.StringPtr("some-non-updatable-apex"), |
| 7259 | Module: proptools.StringPtr("some-non-updatable-fragment"), |
| 7260 | } |
| 7261 | testNoUpdatableJarsInBootImage(t, "", preparer, fragment) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7262 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 7263 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7264 | 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] | 7265 | err := `"platform-bootclasspath" depends on undefined module "nonexistent"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7266 | preparer := java.FixtureConfigureBootJars("platform:nonexistent") |
| 7267 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7268 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7269 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7270 | 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] | 7271 | err := `"platform-bootclasspath" depends on undefined module "nonexistent"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7272 | preparer := java.FixtureConfigureBootJars("platform:nonexistent") |
| 7273 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7274 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7275 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7276 | t.Run("platform jar in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 7277 | err := `ArtApexJars is invalid as it requests a platform variant of "some-platform-lib"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7278 | // Update the dexpreopt ArtApexJars directly. |
| 7279 | preparer := prepareSetArtJars("platform:some-platform-lib") |
| 7280 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7281 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7282 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7283 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7284 | preparer := android.GroupFixturePreparers( |
| 7285 | java.FixtureConfigureBootJars("platform:some-platform-lib"), |
| 7286 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7287 | ) |
| 7288 | fragments := []java.ApexVariantReference{ |
| 7289 | { |
| 7290 | Apex: proptools.StringPtr("some-non-updatable-apex"), |
| 7291 | Module: proptools.StringPtr("some-non-updatable-fragment"), |
| 7292 | }, |
| 7293 | } |
| 7294 | testNoUpdatableJarsInBootImage(t, "", preparer, fragments...) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7295 | }) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7296 | } |
| 7297 | |
| 7298 | func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7299 | preparer := java.FixtureConfigureApexBootJars("myapex:libfoo") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7300 | t.Run("prebuilt no source", func(t *testing.T) { |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7301 | fragment := java.ApexVariantReference{ |
| 7302 | Apex: proptools.StringPtr("myapex"), |
| 7303 | Module: proptools.StringPtr("my-bootclasspath-fragment"), |
| 7304 | } |
| 7305 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7306 | testDexpreoptWithApexes(t, ` |
| 7307 | prebuilt_apex { |
| 7308 | name: "myapex" , |
| 7309 | arch: { |
| 7310 | arm64: { |
| 7311 | src: "myapex-arm64.apex", |
| 7312 | }, |
| 7313 | arm: { |
| 7314 | src: "myapex-arm.apex", |
| 7315 | }, |
| 7316 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7317 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 7318 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7319 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7320 | prebuilt_bootclasspath_fragment { |
| 7321 | name: "my-bootclasspath-fragment", |
| 7322 | contents: ["libfoo"], |
| 7323 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 7324 | hidden_api: { |
| 7325 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 7326 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 7327 | index: "my-bootclasspath-fragment/index.csv", |
| 7328 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 7329 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 7330 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7331 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7332 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7333 | java_import { |
| 7334 | name: "libfoo", |
| 7335 | jars: ["libfoo.jar"], |
| 7336 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7337 | permitted_packages: ["libfoo"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7338 | } |
| 7339 | `, "", preparer, fragment) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7340 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7341 | } |
| 7342 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 7343 | func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, bootJars []string, rules []android.Rule) { |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7344 | t.Helper() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7345 | bp += ` |
| 7346 | apex_key { |
| 7347 | name: "myapex.key", |
| 7348 | public_key: "testkey.avbpubkey", |
| 7349 | private_key: "testkey.pem", |
| 7350 | }` |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7351 | fs := android.MockFS{ |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7352 | "lib1/src/A.java": nil, |
| 7353 | "lib2/src/B.java": nil, |
| 7354 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 7355 | } |
| 7356 | |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7357 | errorHandler := android.FixtureExpectsNoErrors |
| 7358 | if errmsg != "" { |
| 7359 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 7360 | } |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 7361 | |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7362 | android.GroupFixturePreparers( |
| 7363 | android.PrepareForTestWithAndroidBuildComponents, |
| 7364 | java.PrepareForTestWithJavaBuildComponents, |
| 7365 | PrepareForTestWithApexBuildComponents, |
| 7366 | android.PrepareForTestWithNeverallowRules(rules), |
| 7367 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 7368 | apexBootJars := make([]string, 0, len(bootJars)) |
| 7369 | for _, apexBootJar := range bootJars { |
| 7370 | apexBootJars = append(apexBootJars, "myapex:"+apexBootJar) |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7371 | } |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 7372 | variables.ApexBootJars = android.CreateTestConfiguredJarList(apexBootJars) |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7373 | }), |
| 7374 | fs.AddToFixture(), |
| 7375 | ). |
| 7376 | ExtendWithErrorHandler(errorHandler). |
| 7377 | RunTestWithBp(t, bp) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7378 | } |
| 7379 | |
| 7380 | func TestApexPermittedPackagesRules(t *testing.T) { |
| 7381 | testcases := []struct { |
| 7382 | name string |
| 7383 | expectedError string |
| 7384 | bp string |
| 7385 | bootJars []string |
| 7386 | modulesPackages map[string][]string |
| 7387 | }{ |
| 7388 | |
| 7389 | { |
| 7390 | name: "Non-Bootclasspath apex jar not satisfying allowed module packages.", |
| 7391 | expectedError: "", |
| 7392 | bp: ` |
| 7393 | java_library { |
| 7394 | name: "bcp_lib1", |
| 7395 | srcs: ["lib1/src/*.java"], |
| 7396 | permitted_packages: ["foo.bar"], |
| 7397 | apex_available: ["myapex"], |
| 7398 | sdk_version: "none", |
| 7399 | system_modules: "none", |
| 7400 | } |
| 7401 | java_library { |
| 7402 | name: "nonbcp_lib2", |
| 7403 | srcs: ["lib2/src/*.java"], |
| 7404 | apex_available: ["myapex"], |
| 7405 | permitted_packages: ["a.b"], |
| 7406 | sdk_version: "none", |
| 7407 | system_modules: "none", |
| 7408 | } |
| 7409 | apex { |
| 7410 | name: "myapex", |
| 7411 | key: "myapex.key", |
| 7412 | java_libs: ["bcp_lib1", "nonbcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7413 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7414 | }`, |
| 7415 | bootJars: []string{"bcp_lib1"}, |
| 7416 | modulesPackages: map[string][]string{ |
| 7417 | "myapex": []string{ |
| 7418 | "foo.bar", |
| 7419 | }, |
| 7420 | }, |
| 7421 | }, |
| 7422 | { |
| 7423 | name: "Bootclasspath apex jar not satisfying allowed module packages.", |
| 7424 | 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.`, |
| 7425 | bp: ` |
| 7426 | java_library { |
| 7427 | name: "bcp_lib1", |
| 7428 | srcs: ["lib1/src/*.java"], |
| 7429 | apex_available: ["myapex"], |
| 7430 | permitted_packages: ["foo.bar"], |
| 7431 | sdk_version: "none", |
| 7432 | system_modules: "none", |
| 7433 | } |
| 7434 | java_library { |
| 7435 | name: "bcp_lib2", |
| 7436 | srcs: ["lib2/src/*.java"], |
| 7437 | apex_available: ["myapex"], |
| 7438 | permitted_packages: ["foo.bar", "bar.baz"], |
| 7439 | sdk_version: "none", |
| 7440 | system_modules: "none", |
| 7441 | } |
| 7442 | apex { |
| 7443 | name: "myapex", |
| 7444 | key: "myapex.key", |
| 7445 | java_libs: ["bcp_lib1", "bcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7446 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7447 | } |
| 7448 | `, |
| 7449 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
| 7450 | modulesPackages: map[string][]string{ |
| 7451 | "myapex": []string{ |
| 7452 | "foo.bar", |
| 7453 | }, |
| 7454 | }, |
| 7455 | }, |
| 7456 | } |
| 7457 | for _, tc := range testcases { |
| 7458 | t.Run(tc.name, func(t *testing.T) { |
| 7459 | rules := createApexPermittedPackagesRules(tc.modulesPackages) |
| 7460 | testApexPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules) |
| 7461 | }) |
| 7462 | } |
| 7463 | } |
| 7464 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7465 | func TestTestFor(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7466 | ctx := testApex(t, ` |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7467 | apex { |
| 7468 | name: "myapex", |
| 7469 | key: "myapex.key", |
| 7470 | native_shared_libs: ["mylib", "myprivlib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7471 | updatable: false, |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7472 | } |
| 7473 | |
| 7474 | apex_key { |
| 7475 | name: "myapex.key", |
| 7476 | public_key: "testkey.avbpubkey", |
| 7477 | private_key: "testkey.pem", |
| 7478 | } |
| 7479 | |
| 7480 | cc_library { |
| 7481 | name: "mylib", |
| 7482 | srcs: ["mylib.cpp"], |
| 7483 | system_shared_libs: [], |
| 7484 | stl: "none", |
| 7485 | stubs: { |
| 7486 | versions: ["1"], |
| 7487 | }, |
| 7488 | apex_available: ["myapex"], |
| 7489 | } |
| 7490 | |
| 7491 | cc_library { |
| 7492 | name: "myprivlib", |
| 7493 | srcs: ["mylib.cpp"], |
| 7494 | system_shared_libs: [], |
| 7495 | stl: "none", |
| 7496 | apex_available: ["myapex"], |
| 7497 | } |
| 7498 | |
| 7499 | |
| 7500 | cc_test { |
| 7501 | name: "mytest", |
| 7502 | gtest: false, |
| 7503 | srcs: ["mylib.cpp"], |
| 7504 | system_shared_libs: [], |
| 7505 | stl: "none", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 7506 | shared_libs: ["mylib", "myprivlib", "mytestlib"], |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7507 | test_for: ["myapex"] |
| 7508 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 7509 | |
| 7510 | cc_library { |
| 7511 | name: "mytestlib", |
| 7512 | srcs: ["mylib.cpp"], |
| 7513 | system_shared_libs: [], |
| 7514 | shared_libs: ["mylib", "myprivlib"], |
| 7515 | stl: "none", |
| 7516 | test_for: ["myapex"], |
| 7517 | } |
| 7518 | |
| 7519 | cc_benchmark { |
| 7520 | name: "mybench", |
| 7521 | srcs: ["mylib.cpp"], |
| 7522 | system_shared_libs: [], |
| 7523 | shared_libs: ["mylib", "myprivlib"], |
| 7524 | stl: "none", |
| 7525 | test_for: ["myapex"], |
| 7526 | } |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7527 | `) |
| 7528 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7529 | ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) { |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 7530 | ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ") |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7531 | mylibLdFlags := android.FilterListPred(ldFlags, func(s string) bool { return strings.HasPrefix(s, linkedLib) }) |
| 7532 | android.AssertArrayString(t, "unexpected "+linkedLib+" link library for "+mod, []string{linkedLib + expectedVariant}, mylibLdFlags) |
| 7533 | } |
| 7534 | |
| 7535 | // These modules are tests for the apex, therefore are linked to the |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7536 | // actual implementation of mylib instead of its stub. |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7537 | ensureLinkedLibIs("mytest", "android_arm64_armv8-a", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 7538 | ensureLinkedLibIs("mytestlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 7539 | ensureLinkedLibIs("mybench", "android_arm64_armv8-a", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 7540 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 7541 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7542 | func TestIndirectTestFor(t *testing.T) { |
| 7543 | ctx := testApex(t, ` |
| 7544 | apex { |
| 7545 | name: "myapex", |
| 7546 | key: "myapex.key", |
| 7547 | native_shared_libs: ["mylib", "myprivlib"], |
| 7548 | updatable: false, |
| 7549 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 7550 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7551 | apex_key { |
| 7552 | name: "myapex.key", |
| 7553 | public_key: "testkey.avbpubkey", |
| 7554 | private_key: "testkey.pem", |
| 7555 | } |
| 7556 | |
| 7557 | cc_library { |
| 7558 | name: "mylib", |
| 7559 | srcs: ["mylib.cpp"], |
| 7560 | system_shared_libs: [], |
| 7561 | stl: "none", |
| 7562 | stubs: { |
| 7563 | versions: ["1"], |
| 7564 | }, |
| 7565 | apex_available: ["myapex"], |
| 7566 | } |
| 7567 | |
| 7568 | cc_library { |
| 7569 | name: "myprivlib", |
| 7570 | srcs: ["mylib.cpp"], |
| 7571 | system_shared_libs: [], |
| 7572 | stl: "none", |
| 7573 | shared_libs: ["mylib"], |
| 7574 | apex_available: ["myapex"], |
| 7575 | } |
| 7576 | |
| 7577 | cc_library { |
| 7578 | name: "mytestlib", |
| 7579 | srcs: ["mylib.cpp"], |
| 7580 | system_shared_libs: [], |
| 7581 | shared_libs: ["myprivlib"], |
| 7582 | stl: "none", |
| 7583 | test_for: ["myapex"], |
| 7584 | } |
| 7585 | `) |
| 7586 | |
| 7587 | ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) { |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 7588 | ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ") |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7589 | mylibLdFlags := android.FilterListPred(ldFlags, func(s string) bool { return strings.HasPrefix(s, linkedLib) }) |
| 7590 | android.AssertArrayString(t, "unexpected "+linkedLib+" link library for "+mod, []string{linkedLib + expectedVariant}, mylibLdFlags) |
| 7591 | } |
| 7592 | |
| 7593 | // The platform variant of mytestlib links to the platform variant of the |
| 7594 | // internal myprivlib. |
| 7595 | ensureLinkedLibIs("mytestlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/myprivlib/", "android_arm64_armv8-a_shared/myprivlib.so") |
| 7596 | |
| 7597 | // The platform variant of myprivlib links to the platform variant of mylib |
| 7598 | // and bypasses its stubs. |
| 7599 | 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] | 7600 | } |
| 7601 | |
Martin Stjernholm | ec00900 | 2021-03-27 15:18:31 +0000 | [diff] [blame] | 7602 | func TestTestForForLibInOtherApex(t *testing.T) { |
| 7603 | // This case is only allowed for known overlapping APEXes, i.e. the ART APEXes. |
| 7604 | _ = testApex(t, ` |
| 7605 | apex { |
| 7606 | name: "com.android.art", |
| 7607 | key: "myapex.key", |
| 7608 | native_shared_libs: ["mylib"], |
| 7609 | updatable: false, |
| 7610 | } |
| 7611 | |
| 7612 | apex { |
| 7613 | name: "com.android.art.debug", |
| 7614 | key: "myapex.key", |
| 7615 | native_shared_libs: ["mylib", "mytestlib"], |
| 7616 | updatable: false, |
| 7617 | } |
| 7618 | |
| 7619 | apex_key { |
| 7620 | name: "myapex.key", |
| 7621 | public_key: "testkey.avbpubkey", |
| 7622 | private_key: "testkey.pem", |
| 7623 | } |
| 7624 | |
| 7625 | cc_library { |
| 7626 | name: "mylib", |
| 7627 | srcs: ["mylib.cpp"], |
| 7628 | system_shared_libs: [], |
| 7629 | stl: "none", |
| 7630 | stubs: { |
| 7631 | versions: ["1"], |
| 7632 | }, |
| 7633 | apex_available: ["com.android.art", "com.android.art.debug"], |
| 7634 | } |
| 7635 | |
| 7636 | cc_library { |
| 7637 | name: "mytestlib", |
| 7638 | srcs: ["mylib.cpp"], |
| 7639 | system_shared_libs: [], |
| 7640 | shared_libs: ["mylib"], |
| 7641 | stl: "none", |
| 7642 | apex_available: ["com.android.art.debug"], |
| 7643 | test_for: ["com.android.art"], |
| 7644 | } |
| 7645 | `, |
| 7646 | android.MockFS{ |
| 7647 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 7648 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
| 7649 | }.AddToFixture()) |
| 7650 | } |
| 7651 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7652 | // TODO(jungjw): Move this to proptools |
| 7653 | func intPtr(i int) *int { |
| 7654 | return &i |
| 7655 | } |
| 7656 | |
| 7657 | func TestApexSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7658 | ctx := testApex(t, ` |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7659 | apex_set { |
| 7660 | name: "myapex", |
| 7661 | set: "myapex.apks", |
| 7662 | filename: "foo_v2.apex", |
| 7663 | overrides: ["foo"], |
| 7664 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 7665 | `, |
| 7666 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7667 | variables.Platform_sdk_version = intPtr(30) |
| 7668 | }), |
| 7669 | android.FixtureModifyConfig(func(config android.Config) { |
| 7670 | config.Targets[android.Android] = []android.Target{ |
| 7671 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}}, |
| 7672 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}}, |
| 7673 | } |
| 7674 | }), |
| 7675 | ) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7676 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7677 | m := ctx.ModuleForTests("myapex.apex.extractor", "android_common") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7678 | |
| 7679 | // Check extract_apks tool parameters. |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7680 | extractedApex := m.Output("extracted/myapex.apks") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7681 | actual := extractedApex.Args["abis"] |
| 7682 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 7683 | if actual != expected { |
| 7684 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 7685 | } |
| 7686 | actual = extractedApex.Args["sdk-version"] |
| 7687 | expected = "30" |
| 7688 | if actual != expected { |
| 7689 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 7690 | } |
| 7691 | |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 7692 | m = ctx.ModuleForTests("myapex", "android_common_myapex") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7693 | a := m.Module().(*ApexSet) |
| 7694 | expectedOverrides := []string{"foo"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7695 | actualOverrides := android.AndroidMkEntriesForTest(t, ctx, a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7696 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 7697 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 7698 | } |
| 7699 | } |
| 7700 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 7701 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 7702 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 7703 | apex { |
| 7704 | name: "myapex", |
| 7705 | key: "myapex.key", |
| 7706 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7707 | updatable: false, |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 7708 | } |
| 7709 | |
| 7710 | apex_key { |
| 7711 | name: "myapex.key", |
| 7712 | public_key: "testkey.avbpubkey", |
| 7713 | private_key: "testkey.pem", |
| 7714 | } |
| 7715 | |
| 7716 | cc_library { |
| 7717 | name: "mylib", |
| 7718 | srcs: ["mylib.cpp"], |
| 7719 | static_libs: ["otherlib"], |
| 7720 | system_shared_libs: [], |
| 7721 | stl: "none", |
| 7722 | apex_available: [ "myapex" ], |
| 7723 | } |
| 7724 | |
| 7725 | cc_library { |
| 7726 | name: "otherlib", |
| 7727 | srcs: ["mylib.cpp"], |
| 7728 | system_shared_libs: [], |
| 7729 | stl: "none", |
| 7730 | stubs: { |
| 7731 | versions: ["1", "2", "3"], |
| 7732 | }, |
| 7733 | apex_available: [ "myapex" ], |
| 7734 | } |
| 7735 | `) |
| 7736 | } |
| 7737 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 7738 | func TestApexKeysTxt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7739 | ctx := testApex(t, ` |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 7740 | apex { |
| 7741 | name: "myapex", |
| 7742 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7743 | updatable: false, |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 7744 | } |
| 7745 | |
| 7746 | apex_key { |
| 7747 | name: "myapex.key", |
| 7748 | public_key: "testkey.avbpubkey", |
| 7749 | private_key: "testkey.pem", |
| 7750 | } |
| 7751 | |
| 7752 | prebuilt_apex { |
| 7753 | name: "myapex", |
| 7754 | prefer: true, |
| 7755 | arch: { |
| 7756 | arm64: { |
| 7757 | src: "myapex-arm64.apex", |
| 7758 | }, |
| 7759 | arm: { |
| 7760 | src: "myapex-arm.apex", |
| 7761 | }, |
| 7762 | }, |
| 7763 | } |
| 7764 | |
| 7765 | apex_set { |
| 7766 | name: "myapex_set", |
| 7767 | set: "myapex.apks", |
| 7768 | filename: "myapex_set.apex", |
| 7769 | overrides: ["myapex"], |
| 7770 | } |
| 7771 | `) |
| 7772 | |
| 7773 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 7774 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 7775 | 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] | 7776 | 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] | 7777 | } |
| 7778 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 7779 | func TestAllowedFiles(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7780 | ctx := testApex(t, ` |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 7781 | apex { |
| 7782 | name: "myapex", |
| 7783 | key: "myapex.key", |
| 7784 | apps: ["app"], |
| 7785 | allowed_files: "allowed.txt", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7786 | updatable: false, |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 7787 | } |
| 7788 | |
| 7789 | apex_key { |
| 7790 | name: "myapex.key", |
| 7791 | public_key: "testkey.avbpubkey", |
| 7792 | private_key: "testkey.pem", |
| 7793 | } |
| 7794 | |
| 7795 | android_app { |
| 7796 | name: "app", |
| 7797 | srcs: ["foo/bar/MyClass.java"], |
| 7798 | package_name: "foo", |
| 7799 | sdk_version: "none", |
| 7800 | system_modules: "none", |
| 7801 | apex_available: [ "myapex" ], |
| 7802 | } |
| 7803 | `, withFiles(map[string][]byte{ |
| 7804 | "sub/Android.bp": []byte(` |
| 7805 | override_apex { |
| 7806 | name: "override_myapex", |
| 7807 | base: "myapex", |
| 7808 | apps: ["override_app"], |
| 7809 | allowed_files: ":allowed", |
| 7810 | } |
| 7811 | // Overridable "path" property should be referenced indirectly |
| 7812 | filegroup { |
| 7813 | name: "allowed", |
| 7814 | srcs: ["allowed.txt"], |
| 7815 | } |
| 7816 | override_android_app { |
| 7817 | name: "override_app", |
| 7818 | base: "app", |
| 7819 | package_name: "bar", |
| 7820 | } |
| 7821 | `), |
| 7822 | })) |
| 7823 | |
| 7824 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 7825 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 7826 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 7827 | } |
| 7828 | |
| 7829 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 7830 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 7831 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 7832 | } |
| 7833 | } |
| 7834 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7835 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7836 | testApex(t, ` |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7837 | apex { |
| 7838 | name: "myapex", |
| 7839 | key: "myapex.key", |
| 7840 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7841 | updatable: false, |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7842 | } |
| 7843 | |
| 7844 | apex_key { |
| 7845 | name: "myapex.key", |
| 7846 | public_key: "testkey.avbpubkey", |
| 7847 | private_key: "testkey.pem", |
| 7848 | } |
| 7849 | |
| 7850 | cc_library { |
| 7851 | name: "mylib", |
| 7852 | srcs: ["mylib.cpp"], |
| 7853 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 7854 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7855 | }, |
| 7856 | apex_available: ["myapex"], |
| 7857 | } |
| 7858 | |
| 7859 | cc_prebuilt_library_shared { |
| 7860 | name: "mylib", |
| 7861 | prefer: false, |
| 7862 | srcs: ["prebuilt.so"], |
| 7863 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 7864 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7865 | }, |
| 7866 | apex_available: ["myapex"], |
| 7867 | } |
| 7868 | `) |
| 7869 | } |
| 7870 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7871 | func TestCompressedApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7872 | ctx := testApex(t, ` |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7873 | apex { |
| 7874 | name: "myapex", |
| 7875 | key: "myapex.key", |
| 7876 | compressible: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7877 | updatable: false, |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7878 | } |
| 7879 | apex_key { |
| 7880 | name: "myapex.key", |
| 7881 | public_key: "testkey.avbpubkey", |
| 7882 | private_key: "testkey.pem", |
| 7883 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 7884 | `, |
| 7885 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7886 | variables.CompressedApex = proptools.BoolPtr(true) |
| 7887 | }), |
| 7888 | ) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7889 | |
| 7890 | compressRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("compressRule") |
| 7891 | ensureContains(t, compressRule.Output.String(), "myapex.capex.unsigned") |
| 7892 | |
| 7893 | signApkRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("sign compressedApex") |
| 7894 | ensureEquals(t, signApkRule.Input.String(), compressRule.Output.String()) |
| 7895 | |
| 7896 | // Make sure output of bundle is .capex |
| 7897 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 7898 | ensureContains(t, ab.outputFile.String(), "myapex.capex") |
| 7899 | |
| 7900 | // Verify android.mk rules |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7901 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7902 | var builder strings.Builder |
| 7903 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7904 | androidMk := builder.String() |
| 7905 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.capex\n") |
| 7906 | } |
| 7907 | |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7908 | func TestPreferredPrebuiltSharedLibDep(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7909 | ctx := testApex(t, ` |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7910 | apex { |
| 7911 | name: "myapex", |
| 7912 | key: "myapex.key", |
| 7913 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7914 | updatable: false, |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7915 | } |
| 7916 | |
| 7917 | apex_key { |
| 7918 | name: "myapex.key", |
| 7919 | public_key: "testkey.avbpubkey", |
| 7920 | private_key: "testkey.pem", |
| 7921 | } |
| 7922 | |
| 7923 | cc_library { |
| 7924 | name: "mylib", |
| 7925 | srcs: ["mylib.cpp"], |
| 7926 | apex_available: ["myapex"], |
| 7927 | shared_libs: ["otherlib"], |
| 7928 | system_shared_libs: [], |
| 7929 | } |
| 7930 | |
| 7931 | cc_library { |
| 7932 | name: "otherlib", |
| 7933 | srcs: ["mylib.cpp"], |
| 7934 | stubs: { |
| 7935 | versions: ["current"], |
| 7936 | }, |
| 7937 | } |
| 7938 | |
| 7939 | cc_prebuilt_library_shared { |
| 7940 | name: "otherlib", |
| 7941 | prefer: true, |
| 7942 | srcs: ["prebuilt.so"], |
| 7943 | stubs: { |
| 7944 | versions: ["current"], |
| 7945 | }, |
| 7946 | } |
| 7947 | `) |
| 7948 | |
| 7949 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7950 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7951 | var builder strings.Builder |
| 7952 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7953 | androidMk := builder.String() |
| 7954 | |
| 7955 | // The make level dependency needs to be on otherlib - prebuilt_otherlib isn't |
| 7956 | // a thing there. |
| 7957 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherlib\n") |
| 7958 | } |
| 7959 | |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7960 | func TestExcludeDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7961 | ctx := testApex(t, ` |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7962 | apex { |
| 7963 | name: "myapex", |
| 7964 | key: "myapex.key", |
| 7965 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7966 | updatable: false, |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7967 | } |
| 7968 | |
| 7969 | apex_key { |
| 7970 | name: "myapex.key", |
| 7971 | public_key: "testkey.avbpubkey", |
| 7972 | private_key: "testkey.pem", |
| 7973 | } |
| 7974 | |
| 7975 | cc_library { |
| 7976 | name: "mylib", |
| 7977 | srcs: ["mylib.cpp"], |
| 7978 | system_shared_libs: [], |
| 7979 | stl: "none", |
| 7980 | apex_available: ["myapex"], |
| 7981 | shared_libs: ["mylib2"], |
| 7982 | target: { |
| 7983 | apex: { |
| 7984 | exclude_shared_libs: ["mylib2"], |
| 7985 | }, |
| 7986 | }, |
| 7987 | } |
| 7988 | |
| 7989 | cc_library { |
| 7990 | name: "mylib2", |
| 7991 | srcs: ["mylib.cpp"], |
| 7992 | system_shared_libs: [], |
| 7993 | stl: "none", |
| 7994 | } |
| 7995 | `) |
| 7996 | |
| 7997 | // Check if mylib is linked to mylib2 for the non-apex target |
| 7998 | ldFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 7999 | ensureContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 8000 | |
| 8001 | // Make sure that the link doesn't occur for the apex target |
| 8002 | ldFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 8003 | ensureNotContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared_apex10000/mylib2.so") |
| 8004 | |
| 8005 | // It shouldn't appear in the copy cmd as well. |
| 8006 | copyCmds := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").Args["copy_commands"] |
| 8007 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 8008 | } |
| 8009 | |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8010 | func TestPrebuiltStubLibDep(t *testing.T) { |
| 8011 | bpBase := ` |
| 8012 | apex { |
| 8013 | name: "myapex", |
| 8014 | key: "myapex.key", |
| 8015 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8016 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8017 | } |
| 8018 | apex_key { |
| 8019 | name: "myapex.key", |
| 8020 | public_key: "testkey.avbpubkey", |
| 8021 | private_key: "testkey.pem", |
| 8022 | } |
| 8023 | cc_library { |
| 8024 | name: "mylib", |
| 8025 | srcs: ["mylib.cpp"], |
| 8026 | apex_available: ["myapex"], |
| 8027 | shared_libs: ["stublib"], |
| 8028 | system_shared_libs: [], |
| 8029 | } |
| 8030 | apex { |
| 8031 | name: "otherapex", |
| 8032 | enabled: %s, |
| 8033 | key: "myapex.key", |
| 8034 | native_shared_libs: ["stublib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8035 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8036 | } |
| 8037 | ` |
| 8038 | |
| 8039 | stublibSourceBp := ` |
| 8040 | cc_library { |
| 8041 | name: "stublib", |
| 8042 | srcs: ["mylib.cpp"], |
| 8043 | apex_available: ["otherapex"], |
| 8044 | system_shared_libs: [], |
| 8045 | stl: "none", |
| 8046 | stubs: { |
| 8047 | versions: ["1"], |
| 8048 | }, |
| 8049 | } |
| 8050 | ` |
| 8051 | |
| 8052 | stublibPrebuiltBp := ` |
| 8053 | cc_prebuilt_library_shared { |
| 8054 | name: "stublib", |
| 8055 | srcs: ["prebuilt.so"], |
| 8056 | apex_available: ["otherapex"], |
| 8057 | stubs: { |
| 8058 | versions: ["1"], |
| 8059 | }, |
| 8060 | %s |
| 8061 | } |
| 8062 | ` |
| 8063 | |
| 8064 | tests := []struct { |
| 8065 | name string |
| 8066 | stublibBp string |
| 8067 | usePrebuilt bool |
| 8068 | modNames []string // Modules to collect AndroidMkEntries for |
| 8069 | otherApexEnabled []string |
| 8070 | }{ |
| 8071 | { |
| 8072 | name: "only_source", |
| 8073 | stublibBp: stublibSourceBp, |
| 8074 | usePrebuilt: false, |
| 8075 | modNames: []string{"stublib"}, |
| 8076 | otherApexEnabled: []string{"true", "false"}, |
| 8077 | }, |
| 8078 | { |
| 8079 | name: "source_preferred", |
| 8080 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, ""), |
| 8081 | usePrebuilt: false, |
| 8082 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 8083 | otherApexEnabled: []string{"true", "false"}, |
| 8084 | }, |
| 8085 | { |
| 8086 | name: "prebuilt_preferred", |
| 8087 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, "prefer: true,"), |
| 8088 | usePrebuilt: true, |
| 8089 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 8090 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 8091 | }, |
| 8092 | { |
| 8093 | name: "only_prebuilt", |
| 8094 | stublibBp: fmt.Sprintf(stublibPrebuiltBp, ""), |
| 8095 | usePrebuilt: true, |
| 8096 | modNames: []string{"stublib"}, |
| 8097 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 8098 | }, |
| 8099 | } |
| 8100 | |
| 8101 | for _, test := range tests { |
| 8102 | t.Run(test.name, func(t *testing.T) { |
| 8103 | for _, otherApexEnabled := range test.otherApexEnabled { |
| 8104 | t.Run("otherapex_enabled_"+otherApexEnabled, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8105 | ctx := testApex(t, fmt.Sprintf(bpBase, otherApexEnabled)+test.stublibBp) |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8106 | |
| 8107 | type modAndMkEntries struct { |
| 8108 | mod *cc.Module |
| 8109 | mkEntries android.AndroidMkEntries |
| 8110 | } |
| 8111 | entries := []*modAndMkEntries{} |
| 8112 | |
| 8113 | // Gather shared lib modules that are installable |
| 8114 | for _, modName := range test.modNames { |
| 8115 | for _, variant := range ctx.ModuleVariantsForTests(modName) { |
| 8116 | if !strings.HasPrefix(variant, "android_arm64_armv8-a_shared") { |
| 8117 | continue |
| 8118 | } |
| 8119 | mod := ctx.ModuleForTests(modName, variant).Module().(*cc.Module) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 8120 | if !mod.Enabled() || mod.IsHideFromMake() { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8121 | continue |
| 8122 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 8123 | for _, ent := range android.AndroidMkEntriesForTest(t, ctx, mod) { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8124 | if ent.Disabled { |
| 8125 | continue |
| 8126 | } |
| 8127 | entries = append(entries, &modAndMkEntries{ |
| 8128 | mod: mod, |
| 8129 | mkEntries: ent, |
| 8130 | }) |
| 8131 | } |
| 8132 | } |
| 8133 | } |
| 8134 | |
| 8135 | var entry *modAndMkEntries = nil |
| 8136 | for _, ent := range entries { |
| 8137 | if strings.Join(ent.mkEntries.EntryMap["LOCAL_MODULE"], ",") == "stublib" { |
| 8138 | if entry != nil { |
| 8139 | t.Errorf("More than one AndroidMk entry for \"stublib\": %s and %s", entry.mod, ent.mod) |
| 8140 | } else { |
| 8141 | entry = ent |
| 8142 | } |
| 8143 | } |
| 8144 | } |
| 8145 | |
| 8146 | if entry == nil { |
| 8147 | t.Errorf("AndroidMk entry for \"stublib\" missing") |
| 8148 | } else { |
| 8149 | isPrebuilt := entry.mod.Prebuilt() != nil |
| 8150 | if isPrebuilt != test.usePrebuilt { |
| 8151 | t.Errorf("Wrong module for \"stublib\" AndroidMk entry: got prebuilt %t, want prebuilt %t", isPrebuilt, test.usePrebuilt) |
| 8152 | } |
| 8153 | if !entry.mod.IsStubs() { |
| 8154 | t.Errorf("Module for \"stublib\" AndroidMk entry isn't a stub: %s", entry.mod) |
| 8155 | } |
| 8156 | if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil { |
| 8157 | t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries) |
| 8158 | } |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 8159 | cflags := entry.mkEntries.EntryMap["LOCAL_EXPORT_CFLAGS"] |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 8160 | expected := "-D__STUBLIB_API__=10000" |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 8161 | if !android.InList(expected, cflags) { |
| 8162 | t.Errorf("LOCAL_EXPORT_CFLAGS expected to have %q, but got %q", expected, cflags) |
| 8163 | } |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8164 | } |
| 8165 | }) |
| 8166 | } |
| 8167 | }) |
| 8168 | } |
| 8169 | } |
| 8170 | |
Martin Stjernholm | df298b3 | 2021-05-21 20:57:29 +0100 | [diff] [blame] | 8171 | func TestHostApexInHostOnlyBuild(t *testing.T) { |
| 8172 | testApex(t, ` |
| 8173 | apex { |
| 8174 | name: "myapex", |
| 8175 | host_supported: true, |
| 8176 | key: "myapex.key", |
| 8177 | updatable: false, |
| 8178 | payload_type: "zip", |
| 8179 | } |
| 8180 | apex_key { |
| 8181 | name: "myapex.key", |
| 8182 | public_key: "testkey.avbpubkey", |
| 8183 | private_key: "testkey.pem", |
| 8184 | } |
| 8185 | `, |
| 8186 | android.FixtureModifyConfig(func(config android.Config) { |
| 8187 | // We may not have device targets in all builds, e.g. in |
| 8188 | // prebuilts/build-tools/build-prebuilts.sh |
| 8189 | config.Targets[android.Android] = []android.Target{} |
| 8190 | })) |
| 8191 | } |
| 8192 | |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 8193 | func TestApexJavaCoverage(t *testing.T) { |
| 8194 | bp := ` |
| 8195 | apex { |
| 8196 | name: "myapex", |
| 8197 | key: "myapex.key", |
| 8198 | java_libs: ["mylib"], |
| 8199 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 8200 | systemserverclasspath_fragments: ["mysystemserverclasspathfragment"], |
| 8201 | updatable: false, |
| 8202 | } |
| 8203 | |
| 8204 | apex_key { |
| 8205 | name: "myapex.key", |
| 8206 | public_key: "testkey.avbpubkey", |
| 8207 | private_key: "testkey.pem", |
| 8208 | } |
| 8209 | |
| 8210 | java_library { |
| 8211 | name: "mylib", |
| 8212 | srcs: ["mylib.java"], |
| 8213 | apex_available: ["myapex"], |
| 8214 | compile_dex: true, |
| 8215 | } |
| 8216 | |
| 8217 | bootclasspath_fragment { |
| 8218 | name: "mybootclasspathfragment", |
| 8219 | contents: ["mybootclasspathlib"], |
| 8220 | apex_available: ["myapex"], |
| 8221 | } |
| 8222 | |
| 8223 | java_library { |
| 8224 | name: "mybootclasspathlib", |
| 8225 | srcs: ["mybootclasspathlib.java"], |
| 8226 | apex_available: ["myapex"], |
| 8227 | compile_dex: true, |
| 8228 | } |
| 8229 | |
| 8230 | systemserverclasspath_fragment { |
| 8231 | name: "mysystemserverclasspathfragment", |
| 8232 | contents: ["mysystemserverclasspathlib"], |
| 8233 | apex_available: ["myapex"], |
| 8234 | } |
| 8235 | |
| 8236 | java_library { |
| 8237 | name: "mysystemserverclasspathlib", |
| 8238 | srcs: ["mysystemserverclasspathlib.java"], |
| 8239 | apex_available: ["myapex"], |
| 8240 | compile_dex: true, |
| 8241 | } |
| 8242 | ` |
| 8243 | |
| 8244 | result := android.GroupFixturePreparers( |
| 8245 | PrepareForTestWithApexBuildComponents, |
| 8246 | prepareForTestWithMyapex, |
| 8247 | java.PrepareForTestWithJavaDefaultModules, |
| 8248 | android.PrepareForTestWithAndroidBuildComponents, |
| 8249 | android.FixtureWithRootAndroidBp(bp), |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 8250 | dexpreopt.FixtureSetApexBootJars("myapex:mybootclasspathlib"), |
| 8251 | dexpreopt.FixtureSetApexSystemServerJars("myapex:mysystemserverclasspathlib"), |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 8252 | android.FixtureMergeEnv(map[string]string{ |
| 8253 | "EMMA_INSTRUMENT": "true", |
| 8254 | }), |
| 8255 | ).RunTest(t) |
| 8256 | |
| 8257 | // Make sure jacoco ran on both mylib and mybootclasspathlib |
| 8258 | if result.ModuleForTests("mylib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { |
| 8259 | t.Errorf("Failed to find jacoco rule for mylib") |
| 8260 | } |
| 8261 | if result.ModuleForTests("mybootclasspathlib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { |
| 8262 | t.Errorf("Failed to find jacoco rule for mybootclasspathlib") |
| 8263 | } |
| 8264 | if result.ModuleForTests("mysystemserverclasspathlib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { |
| 8265 | t.Errorf("Failed to find jacoco rule for mysystemserverclasspathlib") |
| 8266 | } |
| 8267 | } |
| 8268 | |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame] | 8269 | func TestProhibitStaticExecutable(t *testing.T) { |
| 8270 | testApexError(t, `executable mybin is static`, ` |
| 8271 | apex { |
| 8272 | name: "myapex", |
| 8273 | key: "myapex.key", |
| 8274 | binaries: ["mybin"], |
| 8275 | min_sdk_version: "29", |
| 8276 | } |
| 8277 | |
| 8278 | apex_key { |
| 8279 | name: "myapex.key", |
| 8280 | public_key: "testkey.avbpubkey", |
| 8281 | private_key: "testkey.pem", |
| 8282 | } |
| 8283 | |
| 8284 | cc_binary { |
| 8285 | name: "mybin", |
| 8286 | srcs: ["mylib.cpp"], |
| 8287 | relative_install_path: "foo/bar", |
| 8288 | static_executable: true, |
| 8289 | system_shared_libs: [], |
| 8290 | stl: "none", |
| 8291 | apex_available: [ "myapex" ], |
Jiyong Park | d12979d | 2021-08-03 13:36:09 +0900 | [diff] [blame] | 8292 | min_sdk_version: "29", |
| 8293 | } |
| 8294 | `) |
| 8295 | |
| 8296 | testApexError(t, `executable mybin.rust is static`, ` |
| 8297 | apex { |
| 8298 | name: "myapex", |
| 8299 | key: "myapex.key", |
| 8300 | binaries: ["mybin.rust"], |
| 8301 | min_sdk_version: "29", |
| 8302 | } |
| 8303 | |
| 8304 | apex_key { |
| 8305 | name: "myapex.key", |
| 8306 | public_key: "testkey.avbpubkey", |
| 8307 | private_key: "testkey.pem", |
| 8308 | } |
| 8309 | |
| 8310 | rust_binary { |
| 8311 | name: "mybin.rust", |
| 8312 | srcs: ["foo.rs"], |
| 8313 | static_executable: true, |
| 8314 | apex_available: ["myapex"], |
| 8315 | min_sdk_version: "29", |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame] | 8316 | } |
| 8317 | `) |
| 8318 | } |
| 8319 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 8320 | func TestMain(m *testing.M) { |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 8321 | os.Exit(m.Run()) |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 8322 | } |