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 | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 25 | "strings" |
| 26 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 27 | |
| 28 | "github.com/google/blueprint/proptools" |
| 29 | |
| 30 | "android/soong/android" |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 31 | "android/soong/bpf" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 32 | "android/soong/cc" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 33 | "android/soong/dexpreopt" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 34 | prebuilt_etc "android/soong/etc" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 35 | "android/soong/java" |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 36 | "android/soong/rust" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 37 | "android/soong/sh" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 38 | ) |
| 39 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 40 | // names returns name list from white space separated string |
| 41 | func names(s string) (ns []string) { |
| 42 | for _, n := range strings.Split(s, " ") { |
| 43 | if len(n) > 0 { |
| 44 | ns = append(ns, n) |
| 45 | } |
| 46 | } |
| 47 | return |
| 48 | } |
| 49 | |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 50 | func testApexError(t *testing.T, pattern, bp string, preparers ...android.FixturePreparer) { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 51 | t.Helper() |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 52 | apexFixtureFactory.Extend(preparers...). |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 53 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 54 | RunTestWithBp(t, bp) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 55 | } |
| 56 | |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 57 | func testApex(t *testing.T, bp string, preparers ...android.FixturePreparer) *android.TestContext { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 58 | t.Helper() |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 59 | factory := apexFixtureFactory.Extend(preparers...) |
| 60 | if bp != "" { |
| 61 | factory = factory.Extend(android.FixtureWithRootAndroidBp(bp)) |
| 62 | } |
| 63 | result := factory.RunTest(t) |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 64 | return result.TestContext |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 65 | } |
| 66 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 67 | func withFiles(files android.MockFS) android.FixturePreparer { |
| 68 | return files.AddToFixture() |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 69 | } |
| 70 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 71 | func withTargets(targets map[android.OsType][]android.Target) android.FixturePreparer { |
| 72 | return android.FixtureModifyConfig(func(config android.Config) { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 73 | for k, v := range targets { |
| 74 | config.Targets[k] = v |
| 75 | } |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 76 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 77 | } |
| 78 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 79 | // withNativeBridgeTargets sets configuration with targets including: |
| 80 | // - X86_64 (primary) |
| 81 | // - X86 (secondary) |
| 82 | // - Arm64 on X86_64 (native bridge) |
| 83 | // - Arm on X86 (native bridge) |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 84 | var withNativeBridgeEnabled = android.FixtureModifyConfig( |
| 85 | func(config android.Config) { |
| 86 | config.Targets[android.Android] = []android.Target{ |
| 87 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, |
| 88 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 89 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, |
| 90 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 91 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, |
| 92 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"}, |
| 93 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 94 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"}, |
| 95 | } |
| 96 | }, |
| 97 | ) |
| 98 | |
| 99 | func withManifestPackageNameOverrides(specs []string) android.FixturePreparer { |
| 100 | return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 101 | variables.ManifestPackageNameOverrides = specs |
| 102 | }) |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 103 | } |
| 104 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 105 | var withBinder32bit = android.FixtureModifyProductVariables( |
| 106 | func(variables android.FixtureProductVariables) { |
| 107 | variables.Binder32bit = proptools.BoolPtr(true) |
| 108 | }, |
| 109 | ) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 110 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 111 | var withUnbundledBuild = android.FixtureModifyProductVariables( |
| 112 | func(variables android.FixtureProductVariables) { |
| 113 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 114 | }, |
| 115 | ) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 116 | |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 117 | var apexFixtureFactory = android.NewFixtureFactory( |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 118 | nil, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 119 | // General preparers in alphabetical order as test infrastructure will enforce correct |
| 120 | // registration order. |
| 121 | android.PrepareForTestWithAndroidBuildComponents, |
| 122 | bpf.PrepareForTestWithBpf, |
| 123 | cc.PrepareForTestWithCcBuildComponents, |
| 124 | java.PrepareForTestWithJavaDefaultModules, |
| 125 | prebuilt_etc.PrepareForTestWithPrebuiltEtc, |
| 126 | rust.PrepareForTestWithRustDefaultModules, |
| 127 | sh.PrepareForTestWithShBuildComponents, |
| 128 | |
| 129 | PrepareForTestWithApexBuildComponents, |
| 130 | |
| 131 | // Additional apex test specific preparers. |
| 132 | android.FixtureAddTextFile("system/sepolicy/Android.bp", ` |
| 133 | filegroup { |
| 134 | name: "myapex-file_contexts", |
| 135 | srcs: [ |
| 136 | "apex/myapex-file_contexts", |
| 137 | ], |
| 138 | } |
| 139 | `), |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 140 | prepareForTestWithMyapex, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 141 | android.FixtureMergeMockFs(android.MockFS{ |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 142 | "a.java": nil, |
| 143 | "PrebuiltAppFoo.apk": nil, |
| 144 | "PrebuiltAppFooPriv.apk": nil, |
| 145 | "apex_manifest.json": nil, |
| 146 | "AndroidManifest.xml": nil, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 147 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
| 148 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
| 149 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 150 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
| 151 | "system/sepolicy/apex/com.android.vndk.current-file_contexts": nil, |
| 152 | "mylib.cpp": nil, |
| 153 | "mytest.cpp": nil, |
| 154 | "mytest1.cpp": nil, |
| 155 | "mytest2.cpp": nil, |
| 156 | "mytest3.cpp": nil, |
| 157 | "myprebuilt": nil, |
| 158 | "my_include": nil, |
| 159 | "foo/bar/MyClass.java": nil, |
| 160 | "prebuilt.jar": nil, |
| 161 | "prebuilt.so": nil, |
| 162 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 163 | "vendor/foo/devkeys/test.pk8": nil, |
| 164 | "testkey.x509.pem": nil, |
| 165 | "testkey.pk8": nil, |
| 166 | "testkey.override.x509.pem": nil, |
| 167 | "testkey.override.pk8": nil, |
| 168 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 169 | "vendor/foo/devkeys/testkey.pem": nil, |
| 170 | "NOTICE": nil, |
| 171 | "custom_notice": nil, |
| 172 | "custom_notice_for_static_lib": nil, |
| 173 | "testkey2.avbpubkey": nil, |
| 174 | "testkey2.pem": nil, |
| 175 | "myapex-arm64.apex": nil, |
| 176 | "myapex-arm.apex": nil, |
| 177 | "myapex.apks": nil, |
| 178 | "frameworks/base/api/current.txt": nil, |
| 179 | "framework/aidl/a.aidl": nil, |
| 180 | "build/make/core/proguard.flags": nil, |
| 181 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 182 | "dummy.txt": nil, |
| 183 | "baz": nil, |
| 184 | "bar/baz": nil, |
| 185 | "testdata/baz": nil, |
| 186 | "AppSet.apks": nil, |
| 187 | "foo.rs": nil, |
| 188 | "libfoo.jar": nil, |
| 189 | "libbar.jar": nil, |
| 190 | }, |
| 191 | ), |
| 192 | |
| 193 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 194 | variables.DeviceVndkVersion = proptools.StringPtr("current") |
| 195 | variables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 196 | variables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 197 | variables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 198 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
| 199 | variables.Platform_version_active_codenames = []string{"Q"} |
| 200 | variables.Platform_vndk_version = proptools.StringPtr("VER") |
| 201 | }), |
| 202 | ) |
| 203 | |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 204 | var prepareForTestWithMyapex = android.FixtureMergeMockFs(android.MockFS{ |
| 205 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 206 | }) |
| 207 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 208 | // ensure that 'result' equals 'expected' |
| 209 | func ensureEquals(t *testing.T, result string, expected string) { |
| 210 | t.Helper() |
| 211 | if result != expected { |
| 212 | t.Errorf("%q != %q", expected, result) |
| 213 | } |
| 214 | } |
| 215 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 216 | // ensure that 'result' contains 'expected' |
| 217 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 218 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 219 | if !strings.Contains(result, expected) { |
| 220 | t.Errorf("%q is not found in %q", expected, result) |
| 221 | } |
| 222 | } |
| 223 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 224 | // ensure that 'result' contains 'expected' exactly one time |
| 225 | func ensureContainsOnce(t *testing.T, result string, expected string) { |
| 226 | t.Helper() |
| 227 | count := strings.Count(result, expected) |
| 228 | if count != 1 { |
| 229 | t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result) |
| 230 | } |
| 231 | } |
| 232 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 233 | // ensures that 'result' does not contain 'notExpected' |
| 234 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 235 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 236 | if strings.Contains(result, notExpected) { |
| 237 | t.Errorf("%q is found in %q", notExpected, result) |
| 238 | } |
| 239 | } |
| 240 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 241 | func ensureMatches(t *testing.T, result string, expectedRex string) { |
| 242 | ok, err := regexp.MatchString(expectedRex, result) |
| 243 | if err != nil { |
| 244 | t.Fatalf("regexp failure trying to match %s against `%s` expression: %s", result, expectedRex, err) |
| 245 | return |
| 246 | } |
| 247 | if !ok { |
| 248 | t.Errorf("%s does not match regular expession %s", result, expectedRex) |
| 249 | } |
| 250 | } |
| 251 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 252 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 253 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 254 | if !android.InList(expected, result) { |
| 255 | t.Errorf("%q is not found in %v", expected, result) |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 260 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 261 | if android.InList(notExpected, result) { |
| 262 | t.Errorf("%q is found in %v", notExpected, result) |
| 263 | } |
| 264 | } |
| 265 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 266 | func ensureListEmpty(t *testing.T, result []string) { |
| 267 | t.Helper() |
| 268 | if len(result) > 0 { |
| 269 | t.Errorf("%q is expected to be empty", result) |
| 270 | } |
| 271 | } |
| 272 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 273 | func ensureListNotEmpty(t *testing.T, result []string) { |
| 274 | t.Helper() |
| 275 | if len(result) == 0 { |
| 276 | t.Errorf("%q is expected to be not empty", result) |
| 277 | } |
| 278 | } |
| 279 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 280 | // Minimal test |
| 281 | func TestBasicApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 282 | ctx := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 283 | apex_defaults { |
| 284 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 285 | manifest: ":myapex.manifest", |
| 286 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 287 | key: "myapex.key", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 288 | binaries: ["foo.rust"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 289 | native_shared_libs: [ |
| 290 | "mylib", |
| 291 | "libfoo.ffi", |
| 292 | ], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 293 | rust_dyn_libs: ["libfoo.dylib.rust"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 294 | multilib: { |
| 295 | both: { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 296 | binaries: ["foo"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 297 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 298 | }, |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 299 | java_libs: [ |
| 300 | "myjar", |
| 301 | "myjar_dex", |
| 302 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 303 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 304 | } |
| 305 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 306 | apex { |
| 307 | name: "myapex", |
| 308 | defaults: ["myapex-defaults"], |
| 309 | } |
| 310 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 311 | apex_key { |
| 312 | name: "myapex.key", |
| 313 | public_key: "testkey.avbpubkey", |
| 314 | private_key: "testkey.pem", |
| 315 | } |
| 316 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 317 | filegroup { |
| 318 | name: "myapex.manifest", |
| 319 | srcs: ["apex_manifest.json"], |
| 320 | } |
| 321 | |
| 322 | filegroup { |
| 323 | name: "myapex.androidmanifest", |
| 324 | srcs: ["AndroidManifest.xml"], |
| 325 | } |
| 326 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 327 | cc_library { |
| 328 | name: "mylib", |
| 329 | srcs: ["mylib.cpp"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 330 | shared_libs: [ |
| 331 | "mylib2", |
| 332 | "libbar.ffi", |
| 333 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 334 | system_shared_libs: [], |
| 335 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 336 | // TODO: remove //apex_available:platform |
| 337 | apex_available: [ |
| 338 | "//apex_available:platform", |
| 339 | "myapex", |
| 340 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 341 | } |
| 342 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 343 | cc_binary { |
| 344 | name: "foo", |
| 345 | srcs: ["mylib.cpp"], |
| 346 | compile_multilib: "both", |
| 347 | multilib: { |
| 348 | lib32: { |
| 349 | suffix: "32", |
| 350 | }, |
| 351 | lib64: { |
| 352 | suffix: "64", |
| 353 | }, |
| 354 | }, |
| 355 | symlinks: ["foo_link_"], |
| 356 | symlink_preferred_arch: true, |
| 357 | system_shared_libs: [], |
| 358 | static_executable: true, |
| 359 | stl: "none", |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 360 | apex_available: [ "myapex", "com.android.gki.*" ], |
| 361 | } |
| 362 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 363 | rust_binary { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 364 | name: "foo.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 365 | srcs: ["foo.rs"], |
| 366 | rlibs: ["libfoo.rlib.rust"], |
| 367 | dylibs: ["libfoo.dylib.rust"], |
| 368 | apex_available: ["myapex"], |
| 369 | } |
| 370 | |
| 371 | rust_library_rlib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 372 | name: "libfoo.rlib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 373 | srcs: ["foo.rs"], |
| 374 | crate_name: "foo", |
| 375 | apex_available: ["myapex"], |
| 376 | } |
| 377 | |
| 378 | rust_library_dylib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 379 | name: "libfoo.dylib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 380 | srcs: ["foo.rs"], |
| 381 | crate_name: "foo", |
| 382 | apex_available: ["myapex"], |
| 383 | } |
| 384 | |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 385 | rust_ffi_shared { |
| 386 | name: "libfoo.ffi", |
| 387 | srcs: ["foo.rs"], |
| 388 | crate_name: "foo", |
| 389 | apex_available: ["myapex"], |
| 390 | } |
| 391 | |
| 392 | rust_ffi_shared { |
| 393 | name: "libbar.ffi", |
| 394 | srcs: ["foo.rs"], |
| 395 | crate_name: "bar", |
| 396 | apex_available: ["myapex"], |
| 397 | } |
| 398 | |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 399 | apex { |
| 400 | name: "com.android.gki.fake", |
| 401 | binaries: ["foo"], |
| 402 | key: "myapex.key", |
| 403 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 404 | updatable: false, |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 407 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 408 | name: "mylib2", |
| 409 | srcs: ["mylib.cpp"], |
| 410 | system_shared_libs: [], |
| 411 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 412 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 413 | static_libs: ["libstatic"], |
| 414 | // TODO: remove //apex_available:platform |
| 415 | apex_available: [ |
| 416 | "//apex_available:platform", |
| 417 | "myapex", |
| 418 | ], |
| 419 | } |
| 420 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 421 | cc_prebuilt_library_shared { |
| 422 | name: "mylib2", |
| 423 | srcs: ["prebuilt.so"], |
| 424 | // TODO: remove //apex_available:platform |
| 425 | apex_available: [ |
| 426 | "//apex_available:platform", |
| 427 | "myapex", |
| 428 | ], |
| 429 | } |
| 430 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 431 | cc_library_static { |
| 432 | name: "libstatic", |
| 433 | srcs: ["mylib.cpp"], |
| 434 | system_shared_libs: [], |
| 435 | stl: "none", |
| 436 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 437 | // TODO: remove //apex_available:platform |
| 438 | apex_available: [ |
| 439 | "//apex_available:platform", |
| 440 | "myapex", |
| 441 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 442 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 443 | |
| 444 | java_library { |
| 445 | name: "myjar", |
| 446 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 447 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 448 | sdk_version: "none", |
| 449 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 450 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 451 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 452 | // TODO: remove //apex_available:platform |
| 453 | apex_available: [ |
| 454 | "//apex_available:platform", |
| 455 | "myapex", |
| 456 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 457 | } |
| 458 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 459 | dex_import { |
| 460 | name: "myjar_dex", |
| 461 | jars: ["prebuilt.jar"], |
| 462 | apex_available: [ |
| 463 | "//apex_available:platform", |
| 464 | "myapex", |
| 465 | ], |
| 466 | } |
| 467 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 468 | java_library { |
| 469 | name: "myotherjar", |
| 470 | srcs: ["foo/bar/MyClass.java"], |
| 471 | sdk_version: "none", |
| 472 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 473 | // TODO: remove //apex_available:platform |
| 474 | apex_available: [ |
| 475 | "//apex_available:platform", |
| 476 | "myapex", |
| 477 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 478 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 479 | |
| 480 | java_library { |
| 481 | name: "mysharedjar", |
| 482 | srcs: ["foo/bar/MyClass.java"], |
| 483 | sdk_version: "none", |
| 484 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 485 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 486 | `) |
| 487 | |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 488 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 489 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 490 | // Make sure that Android.mk is created |
| 491 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 492 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 493 | var builder strings.Builder |
| 494 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 495 | |
| 496 | androidMk := builder.String() |
| 497 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 498 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 499 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 500 | optFlags := apexRule.Args["opt_flags"] |
| 501 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 502 | // Ensure that the NOTICE output is being packaged as an asset. |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 503 | 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] | 504 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 505 | copyCmds := apexRule.Args["copy_commands"] |
| 506 | |
| 507 | // Ensure that main rule creates an output |
| 508 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 509 | |
| 510 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 511 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 512 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") |
| 513 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 514 | ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 515 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 516 | |
| 517 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 518 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
| 519 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 520 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000") |
| 521 | 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] | 522 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 523 | |
| 524 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 525 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 526 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 527 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 528 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 529 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 530 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so") |
| 531 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 532 | // .. but not for java libs |
| 533 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 534 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 535 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 536 | // Ensure that the platform variant ends with _shared or _common |
| 537 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 538 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 539 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 540 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 541 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 542 | |
| 543 | // Ensure that dynamic dependency to java libs are not included |
| 544 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 545 | |
| 546 | // Ensure that all symlinks are present. |
| 547 | found_foo_link_64 := false |
| 548 | found_foo := false |
| 549 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 550 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 551 | if strings.HasSuffix(cmd, "bin/foo") { |
| 552 | found_foo = true |
| 553 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 554 | found_foo_link_64 = true |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | good := found_foo && found_foo_link_64 |
| 559 | if !good { |
| 560 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 561 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 562 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 563 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 564 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 565 | if len(noticeInputs) != 3 { |
| 566 | 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] | 567 | } |
| 568 | ensureListContains(t, noticeInputs, "NOTICE") |
| 569 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 570 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 571 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 572 | 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] | 573 | ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 574 | ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib") |
| 575 | ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar") |
| 576 | ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 577 | |
| 578 | 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] | 579 | ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 580 | ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))") |
| 581 | ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))") |
| 582 | ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 583 | } |
| 584 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 585 | func TestDefaults(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 586 | ctx := testApex(t, ` |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 587 | apex_defaults { |
| 588 | name: "myapex-defaults", |
| 589 | key: "myapex.key", |
| 590 | prebuilts: ["myetc"], |
| 591 | native_shared_libs: ["mylib"], |
| 592 | java_libs: ["myjar"], |
| 593 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 594 | rros: ["rro"], |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 595 | bpfs: ["bpf"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 596 | updatable: false, |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | prebuilt_etc { |
| 600 | name: "myetc", |
| 601 | src: "myprebuilt", |
| 602 | } |
| 603 | |
| 604 | apex { |
| 605 | name: "myapex", |
| 606 | defaults: ["myapex-defaults"], |
| 607 | } |
| 608 | |
| 609 | apex_key { |
| 610 | name: "myapex.key", |
| 611 | public_key: "testkey.avbpubkey", |
| 612 | private_key: "testkey.pem", |
| 613 | } |
| 614 | |
| 615 | cc_library { |
| 616 | name: "mylib", |
| 617 | system_shared_libs: [], |
| 618 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 619 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | java_library { |
| 623 | name: "myjar", |
| 624 | srcs: ["foo/bar/MyClass.java"], |
| 625 | sdk_version: "none", |
| 626 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 627 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | android_app { |
| 631 | name: "AppFoo", |
| 632 | srcs: ["foo/bar/MyClass.java"], |
| 633 | sdk_version: "none", |
| 634 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 635 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 636 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 637 | |
| 638 | runtime_resource_overlay { |
| 639 | name: "rro", |
| 640 | theme: "blue", |
| 641 | } |
| 642 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 643 | bpf { |
| 644 | name: "bpf", |
| 645 | srcs: ["bpf.c", "bpf2.c"], |
| 646 | } |
| 647 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 648 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 649 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 650 | "etc/myetc", |
| 651 | "javalib/myjar.jar", |
| 652 | "lib64/mylib.so", |
| 653 | "app/AppFoo/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 654 | "overlay/blue/rro.apk", |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 655 | "etc/bpf/bpf.o", |
| 656 | "etc/bpf/bpf2.o", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 657 | }) |
| 658 | } |
| 659 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 660 | func TestApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 661 | ctx := testApex(t, ` |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 662 | apex { |
| 663 | name: "myapex", |
| 664 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 665 | updatable: false, |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | apex_key { |
| 669 | name: "myapex.key", |
| 670 | public_key: "testkey.avbpubkey", |
| 671 | private_key: "testkey.pem", |
| 672 | } |
| 673 | `) |
| 674 | |
| 675 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 676 | args := module.Rule("apexRule").Args |
| 677 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 678 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 679 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 680 | } |
| 681 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 682 | func TestBasicZipApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 683 | ctx := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 684 | apex { |
| 685 | name: "myapex", |
| 686 | key: "myapex.key", |
| 687 | payload_type: "zip", |
| 688 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 689 | updatable: false, |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | apex_key { |
| 693 | name: "myapex.key", |
| 694 | public_key: "testkey.avbpubkey", |
| 695 | private_key: "testkey.pem", |
| 696 | } |
| 697 | |
| 698 | cc_library { |
| 699 | name: "mylib", |
| 700 | srcs: ["mylib.cpp"], |
| 701 | shared_libs: ["mylib2"], |
| 702 | system_shared_libs: [], |
| 703 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 704 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | cc_library { |
| 708 | name: "mylib2", |
| 709 | srcs: ["mylib.cpp"], |
| 710 | system_shared_libs: [], |
| 711 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 712 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 713 | } |
| 714 | `) |
| 715 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 716 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 717 | copyCmds := zipApexRule.Args["copy_commands"] |
| 718 | |
| 719 | // Ensure that main rule creates an output |
| 720 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 721 | |
| 722 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 723 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 724 | |
| 725 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 726 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 727 | |
| 728 | // Ensure that both direct and indirect deps are copied into apex |
| 729 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 730 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | func TestApexWithStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 734 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 735 | apex { |
| 736 | name: "myapex", |
| 737 | key: "myapex.key", |
| 738 | native_shared_libs: ["mylib", "mylib3"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 739 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | apex_key { |
| 743 | name: "myapex.key", |
| 744 | public_key: "testkey.avbpubkey", |
| 745 | private_key: "testkey.pem", |
| 746 | } |
| 747 | |
| 748 | cc_library { |
| 749 | name: "mylib", |
| 750 | srcs: ["mylib.cpp"], |
| 751 | shared_libs: ["mylib2", "mylib3"], |
| 752 | system_shared_libs: [], |
| 753 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 754 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | cc_library { |
| 758 | name: "mylib2", |
| 759 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 760 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 761 | system_shared_libs: [], |
| 762 | stl: "none", |
| 763 | stubs: { |
| 764 | versions: ["1", "2", "3"], |
| 765 | }, |
| 766 | } |
| 767 | |
| 768 | cc_library { |
| 769 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 770 | srcs: ["mylib.cpp"], |
| 771 | shared_libs: ["mylib4"], |
| 772 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 773 | stl: "none", |
| 774 | stubs: { |
| 775 | versions: ["10", "11", "12"], |
| 776 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 777 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 778 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 779 | |
| 780 | cc_library { |
| 781 | name: "mylib4", |
| 782 | srcs: ["mylib.cpp"], |
| 783 | system_shared_libs: [], |
| 784 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 785 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 786 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 787 | `) |
| 788 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 789 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 790 | copyCmds := apexRule.Args["copy_commands"] |
| 791 | |
| 792 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 793 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 794 | |
| 795 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 796 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 797 | |
| 798 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 799 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 800 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 801 | 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] | 802 | |
| 803 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 804 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 805 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 806 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 807 | |
| 808 | // 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] | 809 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 810 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 811 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 812 | |
| 813 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 814 | 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] | 815 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 816 | |
| 817 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 818 | 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] | 819 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 820 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 821 | "lib64/mylib.so", |
| 822 | "lib64/mylib3.so", |
| 823 | "lib64/mylib4.so", |
| 824 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 825 | } |
| 826 | |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 827 | func TestApexWithStubsWithMinSdkVersion(t *testing.T) { |
| 828 | t.Parallel() |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 829 | ctx := testApex(t, ` |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 830 | apex { |
| 831 | name: "myapex", |
| 832 | key: "myapex.key", |
| 833 | native_shared_libs: ["mylib", "mylib3"], |
| 834 | min_sdk_version: "29", |
| 835 | } |
| 836 | |
| 837 | apex_key { |
| 838 | name: "myapex.key", |
| 839 | public_key: "testkey.avbpubkey", |
| 840 | private_key: "testkey.pem", |
| 841 | } |
| 842 | |
| 843 | cc_library { |
| 844 | name: "mylib", |
| 845 | srcs: ["mylib.cpp"], |
| 846 | shared_libs: ["mylib2", "mylib3"], |
| 847 | system_shared_libs: [], |
| 848 | stl: "none", |
| 849 | apex_available: [ "myapex" ], |
| 850 | min_sdk_version: "28", |
| 851 | } |
| 852 | |
| 853 | cc_library { |
| 854 | name: "mylib2", |
| 855 | srcs: ["mylib.cpp"], |
| 856 | cflags: ["-include mylib.h"], |
| 857 | system_shared_libs: [], |
| 858 | stl: "none", |
| 859 | stubs: { |
| 860 | versions: ["28", "29", "30", "current"], |
| 861 | }, |
| 862 | min_sdk_version: "28", |
| 863 | } |
| 864 | |
| 865 | cc_library { |
| 866 | name: "mylib3", |
| 867 | srcs: ["mylib.cpp"], |
| 868 | shared_libs: ["mylib4"], |
| 869 | system_shared_libs: [], |
| 870 | stl: "none", |
| 871 | stubs: { |
| 872 | versions: ["28", "29", "30", "current"], |
| 873 | }, |
| 874 | apex_available: [ "myapex" ], |
| 875 | min_sdk_version: "28", |
| 876 | } |
| 877 | |
| 878 | cc_library { |
| 879 | name: "mylib4", |
| 880 | srcs: ["mylib.cpp"], |
| 881 | system_shared_libs: [], |
| 882 | stl: "none", |
| 883 | apex_available: [ "myapex" ], |
| 884 | min_sdk_version: "28", |
| 885 | } |
| 886 | `) |
| 887 | |
| 888 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 889 | copyCmds := apexRule.Args["copy_commands"] |
| 890 | |
| 891 | // Ensure that direct non-stubs dep is always included |
| 892 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 893 | |
| 894 | // Ensure that indirect stubs dep is not included |
| 895 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 896 | |
| 897 | // Ensure that direct stubs dep is included |
| 898 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 899 | |
| 900 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"] |
| 901 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 902 | // Ensure that mylib is linking with the latest version of stub for mylib2 |
| 903 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 904 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| 905 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 906 | |
| 907 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| 908 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so") |
| 909 | // .. and not linking to the stubs variant of mylib3 |
| 910 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so") |
| 911 | |
| 912 | // Ensure that stubs libs are built without -include flags |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 913 | 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] | 914 | ensureNotContains(t, mylib2Cflags, "-include ") |
| 915 | |
| 916 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 917 | 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] | 918 | |
| 919 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 920 | "lib64/mylib.so", |
| 921 | "lib64/mylib3.so", |
| 922 | "lib64/mylib4.so", |
| 923 | }) |
| 924 | } |
| 925 | |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 926 | func TestApex_PlatformUsesLatestStubFromApex(t *testing.T) { |
| 927 | t.Parallel() |
| 928 | // myapex (Z) |
| 929 | // mylib -----------------. |
| 930 | // | |
| 931 | // otherapex (29) | |
| 932 | // libstub's versions: 29 Z current |
| 933 | // | |
| 934 | // <platform> | |
| 935 | // libplatform ----------------' |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 936 | ctx := testApex(t, ` |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 937 | apex { |
| 938 | name: "myapex", |
| 939 | key: "myapex.key", |
| 940 | native_shared_libs: ["mylib"], |
| 941 | min_sdk_version: "Z", // non-final |
| 942 | } |
| 943 | |
| 944 | cc_library { |
| 945 | name: "mylib", |
| 946 | srcs: ["mylib.cpp"], |
| 947 | shared_libs: ["libstub"], |
| 948 | apex_available: ["myapex"], |
| 949 | min_sdk_version: "Z", |
| 950 | } |
| 951 | |
| 952 | apex_key { |
| 953 | name: "myapex.key", |
| 954 | public_key: "testkey.avbpubkey", |
| 955 | private_key: "testkey.pem", |
| 956 | } |
| 957 | |
| 958 | apex { |
| 959 | name: "otherapex", |
| 960 | key: "myapex.key", |
| 961 | native_shared_libs: ["libstub"], |
| 962 | min_sdk_version: "29", |
| 963 | } |
| 964 | |
| 965 | cc_library { |
| 966 | name: "libstub", |
| 967 | srcs: ["mylib.cpp"], |
| 968 | stubs: { |
| 969 | versions: ["29", "Z", "current"], |
| 970 | }, |
| 971 | apex_available: ["otherapex"], |
| 972 | min_sdk_version: "29", |
| 973 | } |
| 974 | |
| 975 | // platform module depending on libstub from otherapex should use the latest stub("current") |
| 976 | cc_library { |
| 977 | name: "libplatform", |
| 978 | srcs: ["mylib.cpp"], |
| 979 | shared_libs: ["libstub"], |
| 980 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 981 | `, |
| 982 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 983 | variables.Platform_sdk_codename = proptools.StringPtr("Z") |
| 984 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
| 985 | variables.Platform_version_active_codenames = []string{"Z"} |
| 986 | }), |
| 987 | ) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 988 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 989 | // Ensure that mylib from myapex is built against the latest stub (current) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 990 | 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] | 991 | ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=10000 ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 992 | 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] | 993 | ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 994 | |
| 995 | // Ensure that libplatform is built against latest stub ("current") of mylib3 from the apex |
| 996 | libplatformCflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 997 | ensureContains(t, libplatformCflags, "-D__LIBSTUB_API__=10000 ") // "current" maps to 10000 |
| 998 | libplatformLdflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 999 | ensureContains(t, libplatformLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
| 1000 | } |
| 1001 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1002 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1003 | ctx := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1004 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1005 | name: "myapex2", |
| 1006 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1007 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1008 | updatable: false, |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1012 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1013 | public_key: "testkey.avbpubkey", |
| 1014 | private_key: "testkey.pem", |
| 1015 | } |
| 1016 | |
| 1017 | cc_library { |
| 1018 | name: "mylib", |
| 1019 | srcs: ["mylib.cpp"], |
| 1020 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1021 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1022 | system_shared_libs: [], |
| 1023 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1024 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | cc_library { |
| 1028 | name: "libfoo", |
| 1029 | srcs: ["mylib.cpp"], |
| 1030 | shared_libs: ["libbar"], |
| 1031 | system_shared_libs: [], |
| 1032 | stl: "none", |
| 1033 | stubs: { |
| 1034 | versions: ["10", "20", "30"], |
| 1035 | }, |
| 1036 | } |
| 1037 | |
| 1038 | cc_library { |
| 1039 | name: "libbar", |
| 1040 | srcs: ["mylib.cpp"], |
| 1041 | system_shared_libs: [], |
| 1042 | stl: "none", |
| 1043 | } |
| 1044 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1045 | cc_library_static { |
| 1046 | name: "libbaz", |
| 1047 | srcs: ["mylib.cpp"], |
| 1048 | system_shared_libs: [], |
| 1049 | stl: "none", |
| 1050 | apex_available: [ "myapex2" ], |
| 1051 | } |
| 1052 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1053 | `) |
| 1054 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1055 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1056 | copyCmds := apexRule.Args["copy_commands"] |
| 1057 | |
| 1058 | // Ensure that direct non-stubs dep is always included |
| 1059 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1060 | |
| 1061 | // Ensure that indirect stubs dep is not included |
| 1062 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1063 | |
| 1064 | // Ensure that dependency of stubs is not included |
| 1065 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1066 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1067 | 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] | 1068 | |
| 1069 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1070 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1071 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1072 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1073 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1074 | 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] | 1075 | |
| 1076 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 1077 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1078 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1079 | 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] | 1080 | ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1081 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1082 | 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] | 1083 | ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1084 | } |
| 1085 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1086 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 1087 | /* |
| 1088 | myapex |
| 1089 | | |
| 1090 | v (runtime_libs) |
| 1091 | mylib ------+------> libfoo [provides stub] |
| 1092 | | |
| 1093 | `------> libbar |
| 1094 | */ |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1095 | ctx := testApex(t, ` |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1096 | apex { |
| 1097 | name: "myapex", |
| 1098 | key: "myapex.key", |
| 1099 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1100 | updatable: false, |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | apex_key { |
| 1104 | name: "myapex.key", |
| 1105 | public_key: "testkey.avbpubkey", |
| 1106 | private_key: "testkey.pem", |
| 1107 | } |
| 1108 | |
| 1109 | cc_library { |
| 1110 | name: "mylib", |
| 1111 | srcs: ["mylib.cpp"], |
| 1112 | runtime_libs: ["libfoo", "libbar"], |
| 1113 | system_shared_libs: [], |
| 1114 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1115 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | cc_library { |
| 1119 | name: "libfoo", |
| 1120 | srcs: ["mylib.cpp"], |
| 1121 | system_shared_libs: [], |
| 1122 | stl: "none", |
| 1123 | stubs: { |
| 1124 | versions: ["10", "20", "30"], |
| 1125 | }, |
| 1126 | } |
| 1127 | |
| 1128 | cc_library { |
| 1129 | name: "libbar", |
| 1130 | srcs: ["mylib.cpp"], |
| 1131 | system_shared_libs: [], |
| 1132 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1133 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | `) |
| 1137 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1138 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1139 | copyCmds := apexRule.Args["copy_commands"] |
| 1140 | |
| 1141 | // Ensure that direct non-stubs dep is always included |
| 1142 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1143 | |
| 1144 | // Ensure that indirect stubs dep is not included |
| 1145 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1146 | |
| 1147 | // Ensure that runtime_libs dep in included |
| 1148 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1149 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1150 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1151 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1152 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1153 | |
| 1154 | } |
| 1155 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1156 | var prepareForTestOfRuntimeApexWithHwasan = android.GroupFixturePreparers( |
| 1157 | cc.PrepareForTestWithCcBuildComponents, |
| 1158 | PrepareForTestWithApexBuildComponents, |
| 1159 | android.FixtureAddTextFile("bionic/apex/Android.bp", ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1160 | apex { |
| 1161 | name: "com.android.runtime", |
| 1162 | key: "com.android.runtime.key", |
| 1163 | native_shared_libs: ["libc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1164 | updatable: false, |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | apex_key { |
| 1168 | name: "com.android.runtime.key", |
| 1169 | public_key: "testkey.avbpubkey", |
| 1170 | private_key: "testkey.pem", |
| 1171 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1172 | `), |
| 1173 | android.FixtureAddFile("system/sepolicy/apex/com.android.runtime-file_contexts", nil), |
| 1174 | ) |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1175 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1176 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1177 | result := android.GroupFixturePreparers(prepareForTestOfRuntimeApexWithHwasan).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1178 | cc_library { |
| 1179 | name: "libc", |
| 1180 | no_libcrt: true, |
| 1181 | nocrt: true, |
| 1182 | stl: "none", |
| 1183 | system_shared_libs: [], |
| 1184 | stubs: { versions: ["1"] }, |
| 1185 | apex_available: ["com.android.runtime"], |
| 1186 | |
| 1187 | sanitize: { |
| 1188 | hwaddress: true, |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | cc_prebuilt_library_shared { |
| 1193 | name: "libclang_rt.hwasan-aarch64-android", |
| 1194 | no_libcrt: true, |
| 1195 | nocrt: true, |
| 1196 | stl: "none", |
| 1197 | system_shared_libs: [], |
| 1198 | srcs: [""], |
| 1199 | stubs: { versions: ["1"] }, |
| 1200 | |
| 1201 | sanitize: { |
| 1202 | never: true, |
| 1203 | }, |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1204 | } `) |
| 1205 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1206 | |
| 1207 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1208 | "lib64/bionic/libc.so", |
| 1209 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1210 | }) |
| 1211 | |
| 1212 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1213 | |
| 1214 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1215 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1216 | |
| 1217 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1218 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1219 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1220 | } |
| 1221 | |
| 1222 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1223 | result := android.GroupFixturePreparers( |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1224 | prepareForTestOfRuntimeApexWithHwasan, |
| 1225 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1226 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1227 | }), |
| 1228 | ).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1229 | cc_library { |
| 1230 | name: "libc", |
| 1231 | no_libcrt: true, |
| 1232 | nocrt: true, |
| 1233 | stl: "none", |
| 1234 | system_shared_libs: [], |
| 1235 | stubs: { versions: ["1"] }, |
| 1236 | apex_available: ["com.android.runtime"], |
| 1237 | } |
| 1238 | |
| 1239 | cc_prebuilt_library_shared { |
| 1240 | name: "libclang_rt.hwasan-aarch64-android", |
| 1241 | no_libcrt: true, |
| 1242 | nocrt: true, |
| 1243 | stl: "none", |
| 1244 | system_shared_libs: [], |
| 1245 | srcs: [""], |
| 1246 | stubs: { versions: ["1"] }, |
| 1247 | |
| 1248 | sanitize: { |
| 1249 | never: true, |
| 1250 | }, |
| 1251 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1252 | `) |
| 1253 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1254 | |
| 1255 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1256 | "lib64/bionic/libc.so", |
| 1257 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1258 | }) |
| 1259 | |
| 1260 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1261 | |
| 1262 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1263 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1264 | |
| 1265 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1266 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1267 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1268 | } |
| 1269 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1270 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1271 | testcases := []struct { |
| 1272 | name string |
| 1273 | minSdkVersion string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1274 | apexVariant string |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1275 | shouldLink string |
| 1276 | shouldNotLink []string |
| 1277 | }{ |
| 1278 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1279 | name: "unspecified version links to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1280 | minSdkVersion: "", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1281 | apexVariant: "apex10000", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1282 | shouldLink: "30", |
| 1283 | shouldNotLink: []string{"29"}, |
| 1284 | }, |
| 1285 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1286 | name: "always use the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1287 | minSdkVersion: "min_sdk_version: \"29\",", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1288 | apexVariant: "apex29", |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1289 | shouldLink: "30", |
| 1290 | shouldNotLink: []string{"29"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1291 | }, |
| 1292 | } |
| 1293 | for _, tc := range testcases { |
| 1294 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1295 | ctx := testApex(t, ` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1296 | apex { |
| 1297 | name: "myapex", |
| 1298 | key: "myapex.key", |
| 1299 | use_vendor: true, |
| 1300 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1301 | updatable: false, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1302 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1303 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1304 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1305 | apex_key { |
| 1306 | name: "myapex.key", |
| 1307 | public_key: "testkey.avbpubkey", |
| 1308 | private_key: "testkey.pem", |
| 1309 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1310 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1311 | cc_library { |
| 1312 | name: "mylib", |
| 1313 | srcs: ["mylib.cpp"], |
| 1314 | vendor_available: true, |
| 1315 | shared_libs: ["libbar"], |
| 1316 | system_shared_libs: [], |
| 1317 | stl: "none", |
| 1318 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1319 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1320 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1321 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1322 | cc_library { |
| 1323 | name: "libbar", |
| 1324 | srcs: ["mylib.cpp"], |
| 1325 | system_shared_libs: [], |
| 1326 | stl: "none", |
| 1327 | stubs: { versions: ["29","30"] }, |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1328 | llndk_stubs: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1329 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1330 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1331 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1332 | name: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1333 | symbol_file: "", |
| 1334 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1335 | `, |
| 1336 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 1337 | withUnbundledBuild, |
| 1338 | ) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1339 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1340 | // Ensure that LLNDK dep is not included |
| 1341 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1342 | "lib64/mylib.so", |
| 1343 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1344 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1345 | // Ensure that LLNDK dep is required |
| 1346 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1347 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1348 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1349 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1350 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"] |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 1351 | ensureContains(t, mylibLdFlags, "libbar/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1352 | for _, ver := range tc.shouldNotLink { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 1353 | ensureNotContains(t, mylibLdFlags, "libbar/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1354 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1355 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1356 | mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_"+tc.apexVariant).Rule("cc").Args["cFlags"] |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1357 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink) |
| 1358 | }) |
| 1359 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1360 | } |
| 1361 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1362 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1363 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1364 | apex { |
| 1365 | name: "myapex", |
| 1366 | key: "myapex.key", |
| 1367 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1368 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | apex_key { |
| 1372 | name: "myapex.key", |
| 1373 | public_key: "testkey.avbpubkey", |
| 1374 | private_key: "testkey.pem", |
| 1375 | } |
| 1376 | |
| 1377 | cc_library { |
| 1378 | name: "mylib", |
| 1379 | srcs: ["mylib.cpp"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1380 | system_shared_libs: ["libc", "libm"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1381 | shared_libs: ["libdl#27"], |
| 1382 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1383 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | cc_library_shared { |
| 1387 | name: "mylib_shared", |
| 1388 | srcs: ["mylib.cpp"], |
| 1389 | shared_libs: ["libdl#27"], |
| 1390 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1391 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1395 | name: "libBootstrap", |
| 1396 | srcs: ["mylib.cpp"], |
| 1397 | stl: "none", |
| 1398 | bootstrap: true, |
| 1399 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1400 | `) |
| 1401 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1402 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1403 | copyCmds := apexRule.Args["copy_commands"] |
| 1404 | |
| 1405 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1406 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1407 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1408 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1409 | |
| 1410 | // 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] | 1411 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1412 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1413 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1414 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1415 | 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] | 1416 | |
| 1417 | // For dependency to libc |
| 1418 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1419 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1420 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1421 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1422 | // ... Cflags from stub is correctly exported to mylib |
| 1423 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 1424 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 1425 | |
| 1426 | // For dependency to libm |
| 1427 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1428 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1429 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1430 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1431 | // ... and is not compiling with the stub |
| 1432 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1433 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1434 | |
| 1435 | // For dependency to libdl |
| 1436 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1437 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1438 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1439 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1440 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1441 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1442 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1443 | // ... Cflags from stub is correctly exported to mylib |
| 1444 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1445 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1446 | |
| 1447 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1448 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1449 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1450 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1451 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1452 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1453 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1454 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1455 | // there are three links between liba --> libz. |
| 1456 | // 1) myapex -> libx -> liba -> libz : this should be #30 link |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1457 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1458 | // 3) (platform) -> liba -> libz : this should be non-stub link |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1459 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1460 | apex { |
| 1461 | name: "myapex", |
| 1462 | key: "myapex.key", |
| 1463 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1464 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | apex { |
| 1468 | name: "otherapex", |
| 1469 | key: "myapex.key", |
| 1470 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1471 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | apex_key { |
| 1475 | name: "myapex.key", |
| 1476 | public_key: "testkey.avbpubkey", |
| 1477 | private_key: "testkey.pem", |
| 1478 | } |
| 1479 | |
| 1480 | cc_library { |
| 1481 | name: "libx", |
| 1482 | shared_libs: ["liba"], |
| 1483 | system_shared_libs: [], |
| 1484 | stl: "none", |
| 1485 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1486 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | cc_library { |
| 1490 | name: "liby", |
| 1491 | shared_libs: ["liba"], |
| 1492 | system_shared_libs: [], |
| 1493 | stl: "none", |
| 1494 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1495 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | cc_library { |
| 1499 | name: "liba", |
| 1500 | shared_libs: ["libz"], |
| 1501 | system_shared_libs: [], |
| 1502 | stl: "none", |
| 1503 | apex_available: [ |
| 1504 | "//apex_available:anyapex", |
| 1505 | "//apex_available:platform", |
| 1506 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1507 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | cc_library { |
| 1511 | name: "libz", |
| 1512 | system_shared_libs: [], |
| 1513 | stl: "none", |
| 1514 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1515 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1516 | }, |
| 1517 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1518 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1519 | |
| 1520 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1521 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1522 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1523 | } |
| 1524 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1525 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1526 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1527 | } |
| 1528 | // platform liba is linked to non-stub version |
| 1529 | expectLink("liba", "shared", "libz", "shared") |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1530 | // liba in myapex is linked to #30 |
| 1531 | expectLink("liba", "shared_apex29", "libz", "shared_30") |
| 1532 | expectNoLink("liba", "shared_apex29", "libz", "shared_28") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1533 | expectNoLink("liba", "shared_apex29", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1534 | // liba in otherapex is linked to #30 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1535 | expectLink("liba", "shared_apex30", "libz", "shared_30") |
| 1536 | expectNoLink("liba", "shared_apex30", "libz", "shared_28") |
| 1537 | expectNoLink("liba", "shared_apex30", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1538 | } |
| 1539 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1540 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1541 | ctx := testApex(t, ` |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1542 | apex { |
| 1543 | name: "myapex", |
| 1544 | key: "myapex.key", |
| 1545 | native_shared_libs: ["libx"], |
| 1546 | min_sdk_version: "R", |
| 1547 | } |
| 1548 | |
| 1549 | apex_key { |
| 1550 | name: "myapex.key", |
| 1551 | public_key: "testkey.avbpubkey", |
| 1552 | private_key: "testkey.pem", |
| 1553 | } |
| 1554 | |
| 1555 | cc_library { |
| 1556 | name: "libx", |
| 1557 | shared_libs: ["libz"], |
| 1558 | system_shared_libs: [], |
| 1559 | stl: "none", |
| 1560 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1561 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | cc_library { |
| 1565 | name: "libz", |
| 1566 | system_shared_libs: [], |
| 1567 | stl: "none", |
| 1568 | stubs: { |
| 1569 | versions: ["29", "R"], |
| 1570 | }, |
| 1571 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1572 | `, |
| 1573 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1574 | variables.Platform_version_active_codenames = []string{"R"} |
| 1575 | }), |
| 1576 | ) |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1577 | |
| 1578 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1579 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1580 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1581 | } |
| 1582 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1583 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1584 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1585 | } |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1586 | expectLink("libx", "shared_apex10000", "libz", "shared_R") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1587 | expectNoLink("libx", "shared_apex10000", "libz", "shared_29") |
| 1588 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1589 | } |
| 1590 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1591 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1592 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1593 | apex { |
| 1594 | name: "myapex", |
| 1595 | key: "myapex.key", |
| 1596 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1597 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | apex_key { |
| 1601 | name: "myapex.key", |
| 1602 | public_key: "testkey.avbpubkey", |
| 1603 | private_key: "testkey.pem", |
| 1604 | } |
| 1605 | |
| 1606 | cc_library { |
| 1607 | name: "libx", |
| 1608 | shared_libs: ["libz"], |
| 1609 | system_shared_libs: [], |
| 1610 | stl: "none", |
| 1611 | apex_available: [ "myapex" ], |
| 1612 | } |
| 1613 | |
| 1614 | cc_library { |
| 1615 | name: "libz", |
| 1616 | system_shared_libs: [], |
| 1617 | stl: "none", |
| 1618 | stubs: { |
| 1619 | versions: ["1", "2"], |
| 1620 | }, |
| 1621 | } |
| 1622 | `) |
| 1623 | |
| 1624 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1625 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1626 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1627 | } |
| 1628 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1629 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1630 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1631 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1632 | expectLink("libx", "shared_apex10000", "libz", "shared_2") |
| 1633 | expectNoLink("libx", "shared_apex10000", "libz", "shared_1") |
| 1634 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1638 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1639 | apex { |
| 1640 | name: "myapex", |
| 1641 | key: "myapex.key", |
| 1642 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1643 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | apex_key { |
| 1647 | name: "myapex.key", |
| 1648 | public_key: "testkey.avbpubkey", |
| 1649 | private_key: "testkey.pem", |
| 1650 | } |
| 1651 | |
| 1652 | cc_library { |
| 1653 | name: "libx", |
| 1654 | system_shared_libs: [], |
| 1655 | stl: "none", |
| 1656 | apex_available: [ "myapex" ], |
| 1657 | stubs: { |
| 1658 | versions: ["1", "2"], |
| 1659 | }, |
| 1660 | } |
| 1661 | |
| 1662 | cc_library { |
| 1663 | name: "libz", |
| 1664 | shared_libs: ["libx"], |
| 1665 | system_shared_libs: [], |
| 1666 | stl: "none", |
| 1667 | } |
| 1668 | `) |
| 1669 | |
| 1670 | expectLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1671 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1672 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1673 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1674 | } |
| 1675 | expectNoLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1676 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1677 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1678 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1679 | } |
| 1680 | expectLink("libz", "shared", "libx", "shared_2") |
| 1681 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1682 | expectNoLink("libz", "shared", "libz", "shared") |
| 1683 | } |
| 1684 | |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1685 | var prepareForTestWithSantitizeHwaddress = android.FixtureModifyProductVariables( |
| 1686 | func(variables android.FixtureProductVariables) { |
| 1687 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1688 | }, |
| 1689 | ) |
| 1690 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1691 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1692 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1693 | apex { |
| 1694 | name: "myapex", |
| 1695 | key: "myapex.key", |
| 1696 | native_shared_libs: ["libx"], |
| 1697 | min_sdk_version: "29", |
| 1698 | } |
| 1699 | |
| 1700 | apex_key { |
| 1701 | name: "myapex.key", |
| 1702 | public_key: "testkey.avbpubkey", |
| 1703 | private_key: "testkey.pem", |
| 1704 | } |
| 1705 | |
| 1706 | cc_library { |
| 1707 | name: "libx", |
| 1708 | shared_libs: ["libbar"], |
| 1709 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1710 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | cc_library { |
| 1714 | name: "libbar", |
| 1715 | stubs: { |
| 1716 | versions: ["29", "30"], |
| 1717 | }, |
| 1718 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1719 | `, |
| 1720 | prepareForTestWithSantitizeHwaddress, |
| 1721 | ) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1722 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1723 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1724 | libFlags := ld.Args["libFlags"] |
| 1725 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1726 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1727 | expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_30") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1728 | } |
| 1729 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1730 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1731 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1732 | apex { |
| 1733 | name: "myapex", |
| 1734 | key: "myapex.key", |
| 1735 | native_shared_libs: ["libx"], |
| 1736 | min_sdk_version: "29", |
| 1737 | } |
| 1738 | |
| 1739 | apex_key { |
| 1740 | name: "myapex.key", |
| 1741 | public_key: "testkey.avbpubkey", |
| 1742 | private_key: "testkey.pem", |
| 1743 | } |
| 1744 | |
| 1745 | cc_library { |
| 1746 | name: "libx", |
| 1747 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1748 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1749 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1750 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1751 | |
| 1752 | // ensure apex variant of c++ is linked with static unwinder |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1753 | 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] | 1754 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1755 | // note that platform variant is not. |
| 1756 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 1757 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1758 | } |
| 1759 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1760 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 1761 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1762 | apex { |
| 1763 | name: "myapex", |
| 1764 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1765 | native_shared_libs: ["mylib"], |
| 1766 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | apex_key { |
| 1770 | name: "myapex.key", |
| 1771 | public_key: "testkey.avbpubkey", |
| 1772 | private_key: "testkey.pem", |
| 1773 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1774 | |
| 1775 | cc_library { |
| 1776 | name: "mylib", |
| 1777 | srcs: ["mylib.cpp"], |
| 1778 | system_shared_libs: [], |
| 1779 | stl: "none", |
| 1780 | apex_available: [ |
| 1781 | "myapex", |
| 1782 | ], |
| 1783 | min_sdk_version: "30", |
| 1784 | } |
| 1785 | `) |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1786 | |
| 1787 | testApexError(t, `module "libfoo.ffi".*: should support min_sdk_version\(29\)`, ` |
| 1788 | apex { |
| 1789 | name: "myapex", |
| 1790 | key: "myapex.key", |
| 1791 | native_shared_libs: ["libfoo.ffi"], |
| 1792 | min_sdk_version: "29", |
| 1793 | } |
| 1794 | |
| 1795 | apex_key { |
| 1796 | name: "myapex.key", |
| 1797 | public_key: "testkey.avbpubkey", |
| 1798 | private_key: "testkey.pem", |
| 1799 | } |
| 1800 | |
| 1801 | rust_ffi_shared { |
| 1802 | name: "libfoo.ffi", |
| 1803 | srcs: ["foo.rs"], |
| 1804 | crate_name: "foo", |
| 1805 | apex_available: [ |
| 1806 | "myapex", |
| 1807 | ], |
| 1808 | min_sdk_version: "30", |
| 1809 | } |
| 1810 | `) |
Jaewoong Jung | 6d15d63 | 2021-03-31 11:58:46 -0700 | [diff] [blame] | 1811 | |
| 1812 | testApexError(t, `module "libfoo".*: should support min_sdk_version\(29\)`, ` |
| 1813 | apex { |
| 1814 | name: "myapex", |
| 1815 | key: "myapex.key", |
| 1816 | java_libs: ["libfoo"], |
| 1817 | min_sdk_version: "29", |
| 1818 | } |
| 1819 | |
| 1820 | apex_key { |
| 1821 | name: "myapex.key", |
| 1822 | public_key: "testkey.avbpubkey", |
| 1823 | private_key: "testkey.pem", |
| 1824 | } |
| 1825 | |
| 1826 | java_import { |
| 1827 | name: "libfoo", |
| 1828 | jars: ["libfoo.jar"], |
| 1829 | apex_available: [ |
| 1830 | "myapex", |
| 1831 | ], |
| 1832 | min_sdk_version: "30", |
| 1833 | } |
| 1834 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 1838 | testApex(t, ` |
| 1839 | apex { |
| 1840 | name: "myapex", |
| 1841 | key: "myapex.key", |
| 1842 | native_shared_libs: ["libfoo"], |
| 1843 | java_libs: ["libbar"], |
| 1844 | min_sdk_version: "29", |
| 1845 | } |
| 1846 | |
| 1847 | apex_key { |
| 1848 | name: "myapex.key", |
| 1849 | public_key: "testkey.avbpubkey", |
| 1850 | private_key: "testkey.pem", |
| 1851 | } |
| 1852 | |
| 1853 | cc_library { |
| 1854 | name: "libfoo", |
| 1855 | srcs: ["mylib.cpp"], |
| 1856 | shared_libs: ["libfoo_dep"], |
| 1857 | apex_available: ["myapex"], |
| 1858 | min_sdk_version: "29", |
| 1859 | } |
| 1860 | |
| 1861 | cc_library { |
| 1862 | name: "libfoo_dep", |
| 1863 | srcs: ["mylib.cpp"], |
| 1864 | apex_available: ["myapex"], |
| 1865 | min_sdk_version: "29", |
| 1866 | } |
| 1867 | |
| 1868 | java_library { |
| 1869 | name: "libbar", |
| 1870 | sdk_version: "current", |
| 1871 | srcs: ["a.java"], |
Jaewoong Jung | 6d15d63 | 2021-03-31 11:58:46 -0700 | [diff] [blame] | 1872 | static_libs: [ |
| 1873 | "libbar_dep", |
| 1874 | "libbar_import_dep", |
| 1875 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1876 | apex_available: ["myapex"], |
| 1877 | min_sdk_version: "29", |
| 1878 | } |
| 1879 | |
| 1880 | java_library { |
| 1881 | name: "libbar_dep", |
| 1882 | sdk_version: "current", |
| 1883 | srcs: ["a.java"], |
| 1884 | apex_available: ["myapex"], |
| 1885 | min_sdk_version: "29", |
| 1886 | } |
Jaewoong Jung | 6d15d63 | 2021-03-31 11:58:46 -0700 | [diff] [blame] | 1887 | |
| 1888 | java_import { |
| 1889 | name: "libbar_import_dep", |
| 1890 | jars: ["libbar.jar"], |
| 1891 | apex_available: ["myapex"], |
| 1892 | min_sdk_version: "29", |
| 1893 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1894 | `) |
| 1895 | } |
| 1896 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1897 | func TestJavaStableSdkVersion(t *testing.T) { |
| 1898 | testCases := []struct { |
| 1899 | name string |
| 1900 | expectedError string |
| 1901 | bp string |
| 1902 | }{ |
| 1903 | { |
| 1904 | name: "Non-updatable apex with non-stable dep", |
| 1905 | bp: ` |
| 1906 | apex { |
| 1907 | name: "myapex", |
| 1908 | java_libs: ["myjar"], |
| 1909 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1910 | updatable: false, |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1911 | } |
| 1912 | apex_key { |
| 1913 | name: "myapex.key", |
| 1914 | public_key: "testkey.avbpubkey", |
| 1915 | private_key: "testkey.pem", |
| 1916 | } |
| 1917 | java_library { |
| 1918 | name: "myjar", |
| 1919 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 1920 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1921 | apex_available: ["myapex"], |
| 1922 | } |
| 1923 | `, |
| 1924 | }, |
| 1925 | { |
| 1926 | name: "Updatable apex with stable dep", |
| 1927 | bp: ` |
| 1928 | apex { |
| 1929 | name: "myapex", |
| 1930 | java_libs: ["myjar"], |
| 1931 | key: "myapex.key", |
| 1932 | updatable: true, |
| 1933 | min_sdk_version: "29", |
| 1934 | } |
| 1935 | apex_key { |
| 1936 | name: "myapex.key", |
| 1937 | public_key: "testkey.avbpubkey", |
| 1938 | private_key: "testkey.pem", |
| 1939 | } |
| 1940 | java_library { |
| 1941 | name: "myjar", |
| 1942 | srcs: ["foo/bar/MyClass.java"], |
| 1943 | sdk_version: "current", |
| 1944 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1945 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1946 | } |
| 1947 | `, |
| 1948 | }, |
| 1949 | { |
| 1950 | name: "Updatable apex with non-stable dep", |
| 1951 | expectedError: "cannot depend on \"myjar\"", |
| 1952 | bp: ` |
| 1953 | apex { |
| 1954 | name: "myapex", |
| 1955 | java_libs: ["myjar"], |
| 1956 | key: "myapex.key", |
| 1957 | updatable: true, |
| 1958 | } |
| 1959 | apex_key { |
| 1960 | name: "myapex.key", |
| 1961 | public_key: "testkey.avbpubkey", |
| 1962 | private_key: "testkey.pem", |
| 1963 | } |
| 1964 | java_library { |
| 1965 | name: "myjar", |
| 1966 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 1967 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1968 | apex_available: ["myapex"], |
| 1969 | } |
| 1970 | `, |
| 1971 | }, |
| 1972 | { |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 1973 | name: "Updatable apex with non-stable transitive dep", |
| 1974 | // This is not actually detecting that the transitive dependency is unstable, rather it is |
| 1975 | // detecting that the transitive dependency is building against a wider API surface than the |
| 1976 | // module that depends on it is using. |
Jiyong Park | 670e0f6 | 2021-02-18 13:10:18 +0900 | [diff] [blame] | 1977 | 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] | 1978 | bp: ` |
| 1979 | apex { |
| 1980 | name: "myapex", |
| 1981 | java_libs: ["myjar"], |
| 1982 | key: "myapex.key", |
| 1983 | updatable: true, |
| 1984 | } |
| 1985 | apex_key { |
| 1986 | name: "myapex.key", |
| 1987 | public_key: "testkey.avbpubkey", |
| 1988 | private_key: "testkey.pem", |
| 1989 | } |
| 1990 | java_library { |
| 1991 | name: "myjar", |
| 1992 | srcs: ["foo/bar/MyClass.java"], |
| 1993 | sdk_version: "current", |
| 1994 | apex_available: ["myapex"], |
| 1995 | static_libs: ["transitive-jar"], |
| 1996 | } |
| 1997 | java_library { |
| 1998 | name: "transitive-jar", |
| 1999 | srcs: ["foo/bar/MyClass.java"], |
| 2000 | sdk_version: "core_platform", |
| 2001 | apex_available: ["myapex"], |
| 2002 | } |
| 2003 | `, |
| 2004 | }, |
| 2005 | } |
| 2006 | |
| 2007 | for _, test := range testCases { |
| 2008 | t.Run(test.name, func(t *testing.T) { |
| 2009 | if test.expectedError == "" { |
| 2010 | testApex(t, test.bp) |
| 2011 | } else { |
| 2012 | testApexError(t, test.expectedError, test.bp) |
| 2013 | } |
| 2014 | }) |
| 2015 | } |
| 2016 | } |
| 2017 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2018 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 2019 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2020 | apex { |
| 2021 | name: "myapex", |
| 2022 | key: "myapex.key", |
| 2023 | native_shared_libs: ["mylib"], |
| 2024 | min_sdk_version: "29", |
| 2025 | } |
| 2026 | |
| 2027 | apex_key { |
| 2028 | name: "myapex.key", |
| 2029 | public_key: "testkey.avbpubkey", |
| 2030 | private_key: "testkey.pem", |
| 2031 | } |
| 2032 | |
| 2033 | cc_library { |
| 2034 | name: "mylib", |
| 2035 | srcs: ["mylib.cpp"], |
| 2036 | shared_libs: ["mylib2"], |
| 2037 | system_shared_libs: [], |
| 2038 | stl: "none", |
| 2039 | apex_available: [ |
| 2040 | "myapex", |
| 2041 | ], |
| 2042 | min_sdk_version: "29", |
| 2043 | } |
| 2044 | |
| 2045 | // indirect part of the apex |
| 2046 | cc_library { |
| 2047 | name: "mylib2", |
| 2048 | srcs: ["mylib.cpp"], |
| 2049 | system_shared_libs: [], |
| 2050 | stl: "none", |
| 2051 | apex_available: [ |
| 2052 | "myapex", |
| 2053 | ], |
| 2054 | min_sdk_version: "30", |
| 2055 | } |
| 2056 | `) |
| 2057 | } |
| 2058 | |
| 2059 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 2060 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2061 | apex { |
| 2062 | name: "myapex", |
| 2063 | key: "myapex.key", |
| 2064 | apps: ["AppFoo"], |
| 2065 | min_sdk_version: "29", |
| 2066 | } |
| 2067 | |
| 2068 | apex_key { |
| 2069 | name: "myapex.key", |
| 2070 | public_key: "testkey.avbpubkey", |
| 2071 | private_key: "testkey.pem", |
| 2072 | } |
| 2073 | |
| 2074 | android_app { |
| 2075 | name: "AppFoo", |
| 2076 | srcs: ["foo/bar/MyClass.java"], |
| 2077 | sdk_version: "current", |
| 2078 | min_sdk_version: "29", |
| 2079 | system_modules: "none", |
| 2080 | stl: "none", |
| 2081 | static_libs: ["bar"], |
| 2082 | apex_available: [ "myapex" ], |
| 2083 | } |
| 2084 | |
| 2085 | java_library { |
| 2086 | name: "bar", |
| 2087 | sdk_version: "current", |
| 2088 | srcs: ["a.java"], |
| 2089 | apex_available: [ "myapex" ], |
| 2090 | } |
| 2091 | `) |
| 2092 | } |
| 2093 | |
| 2094 | func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2095 | ctx := testApex(t, ` |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2096 | apex { |
| 2097 | name: "myapex", |
| 2098 | key: "myapex.key", |
| 2099 | native_shared_libs: ["mylib"], |
| 2100 | min_sdk_version: "29", |
| 2101 | } |
| 2102 | |
| 2103 | apex_key { |
| 2104 | name: "myapex.key", |
| 2105 | public_key: "testkey.avbpubkey", |
| 2106 | private_key: "testkey.pem", |
| 2107 | } |
| 2108 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 2109 | // mylib in myapex will link to mylib2#30 |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2110 | // mylib in otherapex will link to mylib2(non-stub) in otherapex as well |
| 2111 | cc_library { |
| 2112 | name: "mylib", |
| 2113 | srcs: ["mylib.cpp"], |
| 2114 | shared_libs: ["mylib2"], |
| 2115 | system_shared_libs: [], |
| 2116 | stl: "none", |
| 2117 | apex_available: ["myapex", "otherapex"], |
| 2118 | min_sdk_version: "29", |
| 2119 | } |
| 2120 | |
| 2121 | cc_library { |
| 2122 | name: "mylib2", |
| 2123 | srcs: ["mylib.cpp"], |
| 2124 | system_shared_libs: [], |
| 2125 | stl: "none", |
| 2126 | apex_available: ["otherapex"], |
| 2127 | stubs: { versions: ["29", "30"] }, |
| 2128 | min_sdk_version: "30", |
| 2129 | } |
| 2130 | |
| 2131 | apex { |
| 2132 | name: "otherapex", |
| 2133 | key: "myapex.key", |
| 2134 | native_shared_libs: ["mylib", "mylib2"], |
| 2135 | min_sdk_version: "30", |
| 2136 | } |
| 2137 | `) |
| 2138 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2139 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2140 | libFlags := ld.Args["libFlags"] |
| 2141 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2142 | } |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 2143 | expectLink("mylib", "shared_apex29", "mylib2", "shared_30") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2144 | expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2145 | } |
| 2146 | |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2147 | func TestApexMinSdkVersion_WorksWithSdkCodename(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2148 | withSAsActiveCodeNames := android.FixtureModifyProductVariables( |
| 2149 | func(variables android.FixtureProductVariables) { |
| 2150 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2151 | variables.Platform_version_active_codenames = []string{"S"} |
| 2152 | }, |
| 2153 | ) |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2154 | testApexError(t, `libbar.*: should support min_sdk_version\(S\)`, ` |
| 2155 | apex { |
| 2156 | name: "myapex", |
| 2157 | key: "myapex.key", |
| 2158 | native_shared_libs: ["libfoo"], |
| 2159 | min_sdk_version: "S", |
| 2160 | } |
| 2161 | apex_key { |
| 2162 | name: "myapex.key", |
| 2163 | public_key: "testkey.avbpubkey", |
| 2164 | private_key: "testkey.pem", |
| 2165 | } |
| 2166 | cc_library { |
| 2167 | name: "libfoo", |
| 2168 | shared_libs: ["libbar"], |
| 2169 | apex_available: ["myapex"], |
| 2170 | min_sdk_version: "29", |
| 2171 | } |
| 2172 | cc_library { |
| 2173 | name: "libbar", |
| 2174 | apex_available: ["myapex"], |
| 2175 | } |
| 2176 | `, withSAsActiveCodeNames) |
| 2177 | } |
| 2178 | |
| 2179 | func TestApexMinSdkVersion_WorksWithActiveCodenames(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2180 | withSAsActiveCodeNames := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2181 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2182 | variables.Platform_version_active_codenames = []string{"S", "T"} |
| 2183 | }) |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2184 | ctx := testApex(t, ` |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2185 | apex { |
| 2186 | name: "myapex", |
| 2187 | key: "myapex.key", |
| 2188 | native_shared_libs: ["libfoo"], |
| 2189 | min_sdk_version: "S", |
| 2190 | } |
| 2191 | apex_key { |
| 2192 | name: "myapex.key", |
| 2193 | public_key: "testkey.avbpubkey", |
| 2194 | private_key: "testkey.pem", |
| 2195 | } |
| 2196 | cc_library { |
| 2197 | name: "libfoo", |
| 2198 | shared_libs: ["libbar"], |
| 2199 | apex_available: ["myapex"], |
| 2200 | min_sdk_version: "S", |
| 2201 | } |
| 2202 | cc_library { |
| 2203 | name: "libbar", |
| 2204 | stubs: { |
| 2205 | symbol_file: "libbar.map.txt", |
| 2206 | versions: ["30", "S", "T"], |
| 2207 | }, |
| 2208 | } |
| 2209 | `, withSAsActiveCodeNames) |
| 2210 | |
| 2211 | // ensure libfoo is linked with "S" version of libbar stub |
| 2212 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_apex10000") |
| 2213 | libFlags := libfoo.Rule("ld").Args["libFlags"] |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 2214 | ensureContains(t, libFlags, "android_arm64_armv8-a_shared_T/libbar.so") |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2215 | } |
| 2216 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2217 | func TestFilesInSubDir(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2218 | ctx := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2219 | apex { |
| 2220 | name: "myapex", |
| 2221 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2222 | native_shared_libs: ["mylib"], |
| 2223 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2224 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2225 | compile_multilib: "both", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2226 | updatable: false, |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | apex_key { |
| 2230 | name: "myapex.key", |
| 2231 | public_key: "testkey.avbpubkey", |
| 2232 | private_key: "testkey.pem", |
| 2233 | } |
| 2234 | |
| 2235 | prebuilt_etc { |
| 2236 | name: "myetc", |
| 2237 | src: "myprebuilt", |
| 2238 | sub_dir: "foo/bar", |
| 2239 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2240 | |
| 2241 | cc_library { |
| 2242 | name: "mylib", |
| 2243 | srcs: ["mylib.cpp"], |
| 2244 | relative_install_path: "foo/bar", |
| 2245 | system_shared_libs: [], |
| 2246 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2247 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | cc_binary { |
| 2251 | name: "mybin", |
| 2252 | srcs: ["mylib.cpp"], |
| 2253 | relative_install_path: "foo/bar", |
| 2254 | system_shared_libs: [], |
| 2255 | static_executable: true, |
| 2256 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2257 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2258 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2259 | `) |
| 2260 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2261 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2262 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 2263 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2264 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2265 | ensureListContains(t, dirs, "etc") |
| 2266 | ensureListContains(t, dirs, "etc/foo") |
| 2267 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2268 | ensureListContains(t, dirs, "lib64") |
| 2269 | ensureListContains(t, dirs, "lib64/foo") |
| 2270 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 2271 | ensureListContains(t, dirs, "lib") |
| 2272 | ensureListContains(t, dirs, "lib/foo") |
| 2273 | ensureListContains(t, dirs, "lib/foo/bar") |
| 2274 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 2275 | ensureListContains(t, dirs, "bin") |
| 2276 | ensureListContains(t, dirs, "bin/foo") |
| 2277 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2278 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2279 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2280 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2281 | ctx := testApex(t, ` |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2282 | apex { |
| 2283 | name: "myapex", |
| 2284 | key: "myapex.key", |
| 2285 | multilib: { |
| 2286 | both: { |
| 2287 | native_shared_libs: ["mylib"], |
| 2288 | binaries: ["mybin"], |
| 2289 | }, |
| 2290 | }, |
| 2291 | compile_multilib: "both", |
| 2292 | native_bridge_supported: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2293 | updatable: false, |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | apex_key { |
| 2297 | name: "myapex.key", |
| 2298 | public_key: "testkey.avbpubkey", |
| 2299 | private_key: "testkey.pem", |
| 2300 | } |
| 2301 | |
| 2302 | cc_library { |
| 2303 | name: "mylib", |
| 2304 | relative_install_path: "foo/bar", |
| 2305 | system_shared_libs: [], |
| 2306 | stl: "none", |
| 2307 | apex_available: [ "myapex" ], |
| 2308 | native_bridge_supported: true, |
| 2309 | } |
| 2310 | |
| 2311 | cc_binary { |
| 2312 | name: "mybin", |
| 2313 | relative_install_path: "foo/bar", |
| 2314 | system_shared_libs: [], |
| 2315 | static_executable: true, |
| 2316 | stl: "none", |
| 2317 | apex_available: [ "myapex" ], |
| 2318 | native_bridge_supported: true, |
| 2319 | compile_multilib: "both", // default is "first" for binary |
| 2320 | multilib: { |
| 2321 | lib64: { |
| 2322 | suffix: "64", |
| 2323 | }, |
| 2324 | }, |
| 2325 | } |
| 2326 | `, withNativeBridgeEnabled) |
| 2327 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2328 | "bin/foo/bar/mybin", |
| 2329 | "bin/foo/bar/mybin64", |
| 2330 | "bin/arm/foo/bar/mybin", |
| 2331 | "bin/arm64/foo/bar/mybin64", |
| 2332 | "lib/foo/bar/mylib.so", |
| 2333 | "lib/arm/foo/bar/mylib.so", |
| 2334 | "lib64/foo/bar/mylib.so", |
| 2335 | "lib64/arm64/foo/bar/mylib.so", |
| 2336 | }) |
| 2337 | } |
| 2338 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2339 | func TestUseVendor(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2340 | ctx := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2341 | apex { |
| 2342 | name: "myapex", |
| 2343 | key: "myapex.key", |
| 2344 | native_shared_libs: ["mylib"], |
| 2345 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2346 | updatable: false, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | apex_key { |
| 2350 | name: "myapex.key", |
| 2351 | public_key: "testkey.avbpubkey", |
| 2352 | private_key: "testkey.pem", |
| 2353 | } |
| 2354 | |
| 2355 | cc_library { |
| 2356 | name: "mylib", |
| 2357 | srcs: ["mylib.cpp"], |
| 2358 | shared_libs: ["mylib2"], |
| 2359 | system_shared_libs: [], |
| 2360 | vendor_available: true, |
| 2361 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2362 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | cc_library { |
| 2366 | name: "mylib2", |
| 2367 | srcs: ["mylib.cpp"], |
| 2368 | system_shared_libs: [], |
| 2369 | vendor_available: true, |
| 2370 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2371 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2372 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2373 | `, |
| 2374 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2375 | ) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2376 | |
| 2377 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2378 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2379 | for _, implicit := range i.Implicits { |
| 2380 | inputsList = append(inputsList, implicit.String()) |
| 2381 | } |
| 2382 | } |
| 2383 | inputsString := strings.Join(inputsList, " ") |
| 2384 | |
| 2385 | // ensure that the apex includes vendor variants of the direct and indirect deps |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2386 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2387 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2388 | |
| 2389 | // ensure that the apex does not include core variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2390 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2391 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2392 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2393 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2394 | func TestUseVendorNotAllowedForSystemApexes(t *testing.T) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2395 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 2396 | apex { |
| 2397 | name: "myapex", |
| 2398 | key: "myapex.key", |
| 2399 | use_vendor: true, |
| 2400 | } |
| 2401 | apex_key { |
| 2402 | name: "myapex.key", |
| 2403 | public_key: "testkey.avbpubkey", |
| 2404 | private_key: "testkey.pem", |
| 2405 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2406 | `, |
| 2407 | setUseVendorAllowListForTest([]string{""}), |
| 2408 | ) |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2409 | // no error with allow list |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2410 | testApex(t, ` |
| 2411 | apex { |
| 2412 | name: "myapex", |
| 2413 | key: "myapex.key", |
| 2414 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2415 | updatable: false, |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2416 | } |
| 2417 | apex_key { |
| 2418 | name: "myapex.key", |
| 2419 | public_key: "testkey.avbpubkey", |
| 2420 | private_key: "testkey.pem", |
| 2421 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2422 | `, |
| 2423 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2424 | ) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2425 | } |
| 2426 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2427 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 2428 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 2429 | apex { |
| 2430 | name: "myapex", |
| 2431 | key: "myapex.key", |
| 2432 | native_shared_libs: ["mylib"], |
| 2433 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2434 | updatable: false, |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | apex_key { |
| 2438 | name: "myapex.key", |
| 2439 | public_key: "testkey.avbpubkey", |
| 2440 | private_key: "testkey.pem", |
| 2441 | } |
| 2442 | |
| 2443 | cc_library { |
| 2444 | name: "mylib", |
| 2445 | srcs: ["mylib.cpp"], |
| 2446 | system_shared_libs: [], |
| 2447 | stl: "none", |
| 2448 | } |
| 2449 | `) |
| 2450 | } |
| 2451 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2452 | func TestVendorApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2453 | ctx := testApex(t, ` |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2454 | apex { |
| 2455 | name: "myapex", |
| 2456 | key: "myapex.key", |
| 2457 | binaries: ["mybin"], |
| 2458 | vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2459 | updatable: false, |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2460 | } |
| 2461 | apex_key { |
| 2462 | name: "myapex.key", |
| 2463 | public_key: "testkey.avbpubkey", |
| 2464 | private_key: "testkey.pem", |
| 2465 | } |
| 2466 | cc_binary { |
| 2467 | name: "mybin", |
| 2468 | vendor: true, |
| 2469 | shared_libs: ["libfoo"], |
| 2470 | } |
| 2471 | cc_library { |
| 2472 | name: "libfoo", |
| 2473 | proprietary: true, |
| 2474 | } |
| 2475 | `) |
| 2476 | |
| 2477 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2478 | "bin/mybin", |
| 2479 | "lib64/libfoo.so", |
| 2480 | // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX |
| 2481 | "lib64/libc++.so", |
| 2482 | }) |
| 2483 | |
| 2484 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2485 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2486 | name := apexBundle.BaseModuleName() |
| 2487 | prefix := "TARGET_" |
| 2488 | var builder strings.Builder |
| 2489 | data.Custom(&builder, name, prefix, "", data) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2490 | androidMk := android.StringRelativeToTop(ctx.Config(), builder.String()) |
| 2491 | installPath := "out/target/product/test_device/vendor/apex" |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 2492 | ensureContains(t, androidMk, "LOCAL_MODULE_PATH := "+installPath) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2493 | |
| 2494 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2495 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2496 | ensureListNotContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2497 | } |
| 2498 | |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2499 | func TestVendorApex_use_vndk_as_stable(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2500 | ctx := testApex(t, ` |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2501 | apex { |
| 2502 | name: "myapex", |
| 2503 | key: "myapex.key", |
| 2504 | binaries: ["mybin"], |
| 2505 | vendor: true, |
| 2506 | use_vndk_as_stable: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2507 | updatable: false, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2508 | } |
| 2509 | apex_key { |
| 2510 | name: "myapex.key", |
| 2511 | public_key: "testkey.avbpubkey", |
| 2512 | private_key: "testkey.pem", |
| 2513 | } |
| 2514 | cc_binary { |
| 2515 | name: "mybin", |
| 2516 | vendor: true, |
| 2517 | shared_libs: ["libvndk", "libvendor"], |
| 2518 | } |
| 2519 | cc_library { |
| 2520 | name: "libvndk", |
| 2521 | vndk: { |
| 2522 | enabled: true, |
| 2523 | }, |
| 2524 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2525 | product_available: true, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2526 | } |
| 2527 | cc_library { |
| 2528 | name: "libvendor", |
| 2529 | vendor: true, |
| 2530 | } |
| 2531 | `) |
| 2532 | |
| 2533 | vendorVariant := "android_vendor.VER_arm64_armv8-a" |
| 2534 | |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 2535 | ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_apex10000").Rule("ld") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2536 | libs := names(ldRule.Args["libFlags"]) |
| 2537 | // VNDK libs(libvndk/libc++) as they are |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2538 | ensureListContains(t, libs, "out/soong/.intermediates/libvndk/"+vendorVariant+"_shared/libvndk.so") |
| 2539 | 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] | 2540 | // non-stable Vendor libs as APEX variants |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2541 | ensureListContains(t, libs, "out/soong/.intermediates/libvendor/"+vendorVariant+"_shared_apex10000/libvendor.so") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2542 | |
| 2543 | // VNDK libs are not included when use_vndk_as_stable: true |
| 2544 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2545 | "bin/mybin", |
| 2546 | "lib64/libvendor.so", |
| 2547 | }) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2548 | |
| 2549 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2550 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2551 | ensureListContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2552 | } |
| 2553 | |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2554 | func TestProductVariant(t *testing.T) { |
| 2555 | ctx := testApex(t, ` |
| 2556 | apex { |
| 2557 | name: "myapex", |
| 2558 | key: "myapex.key", |
| 2559 | updatable: false, |
| 2560 | product_specific: true, |
| 2561 | binaries: ["foo"], |
| 2562 | } |
| 2563 | |
| 2564 | apex_key { |
| 2565 | name: "myapex.key", |
| 2566 | public_key: "testkey.avbpubkey", |
| 2567 | private_key: "testkey.pem", |
| 2568 | } |
| 2569 | |
| 2570 | cc_binary { |
| 2571 | name: "foo", |
| 2572 | product_available: true, |
| 2573 | apex_available: ["myapex"], |
| 2574 | srcs: ["foo.cpp"], |
| 2575 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2576 | `, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2577 | variables.ProductVndkVersion = proptools.StringPtr("current") |
| 2578 | }), |
| 2579 | ) |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2580 | |
| 2581 | cflags := strings.Fields( |
| 2582 | ctx.ModuleForTests("foo", "android_product.VER_arm64_armv8-a_apex10000").Rule("cc").Args["cFlags"]) |
| 2583 | ensureListContains(t, cflags, "-D__ANDROID_VNDK__") |
| 2584 | ensureListContains(t, cflags, "-D__ANDROID_APEX__") |
| 2585 | ensureListContains(t, cflags, "-D__ANDROID_PRODUCT__") |
| 2586 | ensureListNotContains(t, cflags, "-D__ANDROID_VENDOR__") |
| 2587 | } |
| 2588 | |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2589 | func TestApex_withPrebuiltFirmware(t *testing.T) { |
| 2590 | testCases := []struct { |
| 2591 | name string |
| 2592 | additionalProp string |
| 2593 | }{ |
| 2594 | {"system apex with prebuilt_firmware", ""}, |
| 2595 | {"vendor apex with prebuilt_firmware", "vendor: true,"}, |
| 2596 | } |
| 2597 | for _, tc := range testCases { |
| 2598 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2599 | ctx := testApex(t, ` |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2600 | apex { |
| 2601 | name: "myapex", |
| 2602 | key: "myapex.key", |
| 2603 | prebuilts: ["myfirmware"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2604 | updatable: false, |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2605 | `+tc.additionalProp+` |
| 2606 | } |
| 2607 | apex_key { |
| 2608 | name: "myapex.key", |
| 2609 | public_key: "testkey.avbpubkey", |
| 2610 | private_key: "testkey.pem", |
| 2611 | } |
| 2612 | prebuilt_firmware { |
| 2613 | name: "myfirmware", |
| 2614 | src: "myfirmware.bin", |
| 2615 | filename_from_src: true, |
| 2616 | `+tc.additionalProp+` |
| 2617 | } |
| 2618 | `) |
| 2619 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2620 | "etc/firmware/myfirmware.bin", |
| 2621 | }) |
| 2622 | }) |
| 2623 | } |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 2624 | } |
| 2625 | |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2626 | func TestAndroidMk_UseVendorRequired(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2627 | ctx := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2628 | apex { |
| 2629 | name: "myapex", |
| 2630 | key: "myapex.key", |
| 2631 | use_vendor: true, |
| 2632 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2633 | updatable: false, |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | apex_key { |
| 2637 | name: "myapex.key", |
| 2638 | public_key: "testkey.avbpubkey", |
| 2639 | private_key: "testkey.pem", |
| 2640 | } |
| 2641 | |
| 2642 | cc_library { |
| 2643 | name: "mylib", |
| 2644 | vendor_available: true, |
| 2645 | apex_available: ["myapex"], |
| 2646 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2647 | `, |
| 2648 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2649 | ) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2650 | |
| 2651 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2652 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2653 | name := apexBundle.BaseModuleName() |
| 2654 | prefix := "TARGET_" |
| 2655 | var builder strings.Builder |
| 2656 | data.Custom(&builder, name, prefix, "", data) |
| 2657 | androidMk := builder.String() |
| 2658 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc libm libdl\n") |
| 2659 | } |
| 2660 | |
| 2661 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2662 | ctx := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2663 | apex { |
| 2664 | name: "myapex", |
| 2665 | key: "myapex.key", |
| 2666 | vendor: true, |
| 2667 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2668 | updatable: false, |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | apex_key { |
| 2672 | name: "myapex.key", |
| 2673 | public_key: "testkey.avbpubkey", |
| 2674 | private_key: "testkey.pem", |
| 2675 | } |
| 2676 | |
| 2677 | cc_library { |
| 2678 | name: "mylib", |
| 2679 | vendor_available: true, |
| 2680 | } |
| 2681 | `) |
| 2682 | |
| 2683 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2684 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2685 | name := apexBundle.BaseModuleName() |
| 2686 | prefix := "TARGET_" |
| 2687 | var builder strings.Builder |
| 2688 | data.Custom(&builder, name, prefix, "", data) |
| 2689 | androidMk := builder.String() |
| 2690 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc.vendor libm.vendor libdl.vendor\n") |
| 2691 | } |
| 2692 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2693 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2694 | ctx := testApex(t, ` |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2695 | apex { |
| 2696 | name: "myapex", |
| 2697 | key: "myapex.key", |
| 2698 | vintf_fragments: ["fragment.xml"], |
| 2699 | init_rc: ["init.rc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2700 | updatable: false, |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2701 | } |
| 2702 | apex_key { |
| 2703 | name: "myapex.key", |
| 2704 | public_key: "testkey.avbpubkey", |
| 2705 | private_key: "testkey.pem", |
| 2706 | } |
| 2707 | cc_binary { |
| 2708 | name: "mybin", |
| 2709 | } |
| 2710 | `) |
| 2711 | |
| 2712 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2713 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2714 | name := apexBundle.BaseModuleName() |
| 2715 | prefix := "TARGET_" |
| 2716 | var builder strings.Builder |
| 2717 | data.Custom(&builder, name, prefix, "", data) |
| 2718 | androidMk := builder.String() |
| 2719 | ensureContains(t, androidMk, "LOCAL_VINTF_FRAGMENTS := fragment.xml\n") |
| 2720 | ensureContains(t, androidMk, "LOCAL_INIT_RC := init.rc\n") |
| 2721 | } |
| 2722 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2723 | func TestStaticLinking(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2724 | ctx := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2725 | apex { |
| 2726 | name: "myapex", |
| 2727 | key: "myapex.key", |
| 2728 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2729 | updatable: false, |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | apex_key { |
| 2733 | name: "myapex.key", |
| 2734 | public_key: "testkey.avbpubkey", |
| 2735 | private_key: "testkey.pem", |
| 2736 | } |
| 2737 | |
| 2738 | cc_library { |
| 2739 | name: "mylib", |
| 2740 | srcs: ["mylib.cpp"], |
| 2741 | system_shared_libs: [], |
| 2742 | stl: "none", |
| 2743 | stubs: { |
| 2744 | versions: ["1", "2", "3"], |
| 2745 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2746 | apex_available: [ |
| 2747 | "//apex_available:platform", |
| 2748 | "myapex", |
| 2749 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | cc_binary { |
| 2753 | name: "not_in_apex", |
| 2754 | srcs: ["mylib.cpp"], |
| 2755 | static_libs: ["mylib"], |
| 2756 | static_executable: true, |
| 2757 | system_shared_libs: [], |
| 2758 | stl: "none", |
| 2759 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2760 | `) |
| 2761 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2762 | 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] | 2763 | |
| 2764 | // 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] | 2765 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2766 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2767 | |
| 2768 | func TestKeys(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2769 | ctx := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2770 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2771 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2772 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2773 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2774 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2775 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2776 | updatable: false, |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | cc_library { |
| 2780 | name: "mylib", |
| 2781 | srcs: ["mylib.cpp"], |
| 2782 | system_shared_libs: [], |
| 2783 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2784 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | apex_key { |
| 2788 | name: "myapex.key", |
| 2789 | public_key: "testkey.avbpubkey", |
| 2790 | private_key: "testkey.pem", |
| 2791 | } |
| 2792 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2793 | android_app_certificate { |
| 2794 | name: "myapex.certificate", |
| 2795 | certificate: "testkey", |
| 2796 | } |
| 2797 | |
| 2798 | android_app_certificate { |
| 2799 | name: "myapex.certificate.override", |
| 2800 | certificate: "testkey.override", |
| 2801 | } |
| 2802 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2803 | `) |
| 2804 | |
| 2805 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2806 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2807 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2808 | if keys.publicKeyFile.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 2809 | t.Errorf("public key %q is not %q", keys.publicKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2810 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 2811 | } |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2812 | if keys.privateKeyFile.String() != "vendor/foo/devkeys/testkey.pem" { |
| 2813 | t.Errorf("private key %q is not %q", keys.privateKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2814 | "vendor/foo/devkeys/testkey.pem") |
| 2815 | } |
| 2816 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2817 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2818 | 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] | 2819 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2820 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2821 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2822 | } |
| 2823 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2824 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2825 | func TestCertificate(t *testing.T) { |
| 2826 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2827 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2828 | apex { |
| 2829 | name: "myapex", |
| 2830 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2831 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2832 | } |
| 2833 | apex_key { |
| 2834 | name: "myapex.key", |
| 2835 | public_key: "testkey.avbpubkey", |
| 2836 | private_key: "testkey.pem", |
| 2837 | }`) |
| 2838 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2839 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 2840 | if actual := rule.Args["certificates"]; actual != expected { |
| 2841 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2842 | } |
| 2843 | }) |
| 2844 | t.Run("override when unspecified", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2845 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2846 | apex { |
| 2847 | name: "myapex_keytest", |
| 2848 | key: "myapex.key", |
| 2849 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2850 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2851 | } |
| 2852 | apex_key { |
| 2853 | name: "myapex.key", |
| 2854 | public_key: "testkey.avbpubkey", |
| 2855 | private_key: "testkey.pem", |
| 2856 | } |
| 2857 | android_app_certificate { |
| 2858 | name: "myapex.certificate.override", |
| 2859 | certificate: "testkey.override", |
| 2860 | }`) |
| 2861 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2862 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2863 | if actual := rule.Args["certificates"]; actual != expected { |
| 2864 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2865 | } |
| 2866 | }) |
| 2867 | 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] | 2868 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2869 | apex { |
| 2870 | name: "myapex", |
| 2871 | key: "myapex.key", |
| 2872 | certificate: ":myapex.certificate", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2873 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2874 | } |
| 2875 | apex_key { |
| 2876 | name: "myapex.key", |
| 2877 | public_key: "testkey.avbpubkey", |
| 2878 | private_key: "testkey.pem", |
| 2879 | } |
| 2880 | android_app_certificate { |
| 2881 | name: "myapex.certificate", |
| 2882 | certificate: "testkey", |
| 2883 | }`) |
| 2884 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2885 | expected := "testkey.x509.pem testkey.pk8" |
| 2886 | if actual := rule.Args["certificates"]; actual != expected { |
| 2887 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2888 | } |
| 2889 | }) |
| 2890 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2891 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2892 | apex { |
| 2893 | name: "myapex_keytest", |
| 2894 | key: "myapex.key", |
| 2895 | file_contexts: ":myapex-file_contexts", |
| 2896 | certificate: ":myapex.certificate", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2897 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2898 | } |
| 2899 | apex_key { |
| 2900 | name: "myapex.key", |
| 2901 | public_key: "testkey.avbpubkey", |
| 2902 | private_key: "testkey.pem", |
| 2903 | } |
| 2904 | android_app_certificate { |
| 2905 | name: "myapex.certificate.override", |
| 2906 | certificate: "testkey.override", |
| 2907 | }`) |
| 2908 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2909 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2910 | if actual := rule.Args["certificates"]; actual != expected { |
| 2911 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2912 | } |
| 2913 | }) |
| 2914 | 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] | 2915 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2916 | apex { |
| 2917 | name: "myapex", |
| 2918 | key: "myapex.key", |
| 2919 | certificate: "testkey", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2920 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2921 | } |
| 2922 | apex_key { |
| 2923 | name: "myapex.key", |
| 2924 | public_key: "testkey.avbpubkey", |
| 2925 | private_key: "testkey.pem", |
| 2926 | }`) |
| 2927 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2928 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 2929 | if actual := rule.Args["certificates"]; actual != expected { |
| 2930 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2931 | } |
| 2932 | }) |
| 2933 | t.Run("override when specified as <name>", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2934 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2935 | apex { |
| 2936 | name: "myapex_keytest", |
| 2937 | key: "myapex.key", |
| 2938 | file_contexts: ":myapex-file_contexts", |
| 2939 | certificate: "testkey", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2940 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2941 | } |
| 2942 | apex_key { |
| 2943 | name: "myapex.key", |
| 2944 | public_key: "testkey.avbpubkey", |
| 2945 | private_key: "testkey.pem", |
| 2946 | } |
| 2947 | android_app_certificate { |
| 2948 | name: "myapex.certificate.override", |
| 2949 | certificate: "testkey.override", |
| 2950 | }`) |
| 2951 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2952 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2953 | if actual := rule.Args["certificates"]; actual != expected { |
| 2954 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2955 | } |
| 2956 | }) |
| 2957 | } |
| 2958 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2959 | func TestMacro(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2960 | ctx := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2961 | apex { |
| 2962 | name: "myapex", |
| 2963 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2964 | native_shared_libs: ["mylib", "mylib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2965 | updatable: false, |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | apex { |
| 2969 | name: "otherapex", |
| 2970 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2971 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2972 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | apex_key { |
| 2976 | name: "myapex.key", |
| 2977 | public_key: "testkey.avbpubkey", |
| 2978 | private_key: "testkey.pem", |
| 2979 | } |
| 2980 | |
| 2981 | cc_library { |
| 2982 | name: "mylib", |
| 2983 | srcs: ["mylib.cpp"], |
| 2984 | system_shared_libs: [], |
| 2985 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2986 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2987 | "myapex", |
| 2988 | "otherapex", |
| 2989 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2990 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2991 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2992 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2993 | cc_library { |
| 2994 | name: "mylib2", |
| 2995 | srcs: ["mylib.cpp"], |
| 2996 | system_shared_libs: [], |
| 2997 | stl: "none", |
| 2998 | apex_available: [ |
| 2999 | "myapex", |
| 3000 | "otherapex", |
| 3001 | ], |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3002 | static_libs: ["mylib3"], |
| 3003 | recovery_available: true, |
| 3004 | min_sdk_version: "29", |
| 3005 | } |
| 3006 | cc_library { |
| 3007 | name: "mylib3", |
| 3008 | srcs: ["mylib.cpp"], |
| 3009 | system_shared_libs: [], |
| 3010 | stl: "none", |
| 3011 | apex_available: [ |
| 3012 | "myapex", |
| 3013 | "otherapex", |
| 3014 | ], |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3015 | use_apex_name_macro: true, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3016 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3017 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3018 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3019 | `) |
| 3020 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3021 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3022 | 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] | 3023 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3024 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3025 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3026 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3027 | 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] | 3028 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3029 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3030 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3031 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3032 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3033 | 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] | 3034 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3035 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3036 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3037 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3038 | // When a cc_library sets use_apex_name_macro: true each apex gets a unique variant and |
| 3039 | // each variant defines additional macros to distinguish which apex variant it is built for |
| 3040 | |
| 3041 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3042 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3043 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3044 | |
| 3045 | // APEX variant has __ANDROID_APEX__ defined |
| 3046 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 3047 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3048 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3049 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3050 | |
| 3051 | // APEX variant has __ANDROID_APEX__ defined |
| 3052 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 3053 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3054 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3055 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3056 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3057 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3058 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3059 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3060 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3061 | |
| 3062 | // When a dependency of a cc_library sets use_apex_name_macro: true each apex gets a unique |
| 3063 | // variant. |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3064 | |
| 3065 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3066 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3067 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3068 | |
| 3069 | // APEX variant has __ANDROID_APEX__ defined |
| 3070 | 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] | 3071 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3072 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3073 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3074 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3075 | // APEX variant has __ANDROID_APEX__ defined |
| 3076 | 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] | 3077 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3078 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3079 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3080 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3081 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3082 | 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] | 3083 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3084 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3085 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3086 | |
| 3087 | func TestHeaderLibsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3088 | ctx := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3089 | apex { |
| 3090 | name: "myapex", |
| 3091 | key: "myapex.key", |
| 3092 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3093 | updatable: false, |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | apex_key { |
| 3097 | name: "myapex.key", |
| 3098 | public_key: "testkey.avbpubkey", |
| 3099 | private_key: "testkey.pem", |
| 3100 | } |
| 3101 | |
| 3102 | cc_library_headers { |
| 3103 | name: "mylib_headers", |
| 3104 | export_include_dirs: ["my_include"], |
| 3105 | system_shared_libs: [], |
| 3106 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3107 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | cc_library { |
| 3111 | name: "mylib", |
| 3112 | srcs: ["mylib.cpp"], |
| 3113 | system_shared_libs: [], |
| 3114 | stl: "none", |
| 3115 | header_libs: ["mylib_headers"], |
| 3116 | export_header_lib_headers: ["mylib_headers"], |
| 3117 | stubs: { |
| 3118 | versions: ["1", "2", "3"], |
| 3119 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3120 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | cc_library { |
| 3124 | name: "otherlib", |
| 3125 | srcs: ["mylib.cpp"], |
| 3126 | system_shared_libs: [], |
| 3127 | stl: "none", |
| 3128 | shared_libs: ["mylib"], |
| 3129 | } |
| 3130 | `) |
| 3131 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3132 | 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] | 3133 | |
| 3134 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 3135 | ensureContains(t, cFlags, "-Imy_include") |
| 3136 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3137 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3138 | type fileInApex struct { |
| 3139 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3140 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3141 | isLink bool |
| 3142 | } |
| 3143 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3144 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3145 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3146 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3147 | copyCmds := apexRule.Args["copy_commands"] |
| 3148 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3149 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3150 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 3151 | cmd = strings.TrimSpace(cmd) |
| 3152 | if cmd == "" { |
| 3153 | continue |
| 3154 | } |
| 3155 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3156 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3157 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3158 | switch terms[0] { |
| 3159 | case "mkdir": |
| 3160 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3161 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3162 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 3163 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3164 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3165 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3166 | isLink = false |
| 3167 | case "ln": |
| 3168 | if len(terms) != 3 && len(terms) != 4 { |
| 3169 | // ln LINK TARGET or ln -s LINK TARGET |
| 3170 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 3171 | } |
| 3172 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3173 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3174 | isLink = true |
| 3175 | default: |
| 3176 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 3177 | } |
| 3178 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3179 | index := strings.Index(dst, imageApexDir) |
| 3180 | if index == -1 { |
| 3181 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 3182 | } |
| 3183 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3184 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3185 | } |
| 3186 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3187 | return ret |
| 3188 | } |
| 3189 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3190 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 3191 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3192 | var failed bool |
| 3193 | var surplus []string |
| 3194 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3195 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3196 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3197 | for _, expected := range files { |
| 3198 | if matched, _ := path.Match(expected, file.path); matched { |
| 3199 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3200 | mactchFound = true |
| 3201 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3202 | } |
| 3203 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3204 | if !mactchFound { |
| 3205 | surplus = append(surplus, file.path) |
| 3206 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3207 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3208 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3209 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3210 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3211 | t.Log("surplus files", surplus) |
| 3212 | failed = true |
| 3213 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3214 | |
| 3215 | if len(files) > len(filesMatched) { |
| 3216 | var missing []string |
| 3217 | for _, expected := range files { |
| 3218 | if !filesMatched[expected] { |
| 3219 | missing = append(missing, expected) |
| 3220 | } |
| 3221 | } |
| 3222 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3223 | t.Log("missing files", missing) |
| 3224 | failed = true |
| 3225 | } |
| 3226 | if failed { |
| 3227 | t.Fail() |
| 3228 | } |
| 3229 | } |
| 3230 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3231 | func TestVndkApexCurrent(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3232 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3233 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3234 | name: "com.android.vndk.current", |
| 3235 | key: "com.android.vndk.current.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3236 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3240 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3241 | public_key: "testkey.avbpubkey", |
| 3242 | private_key: "testkey.pem", |
| 3243 | } |
| 3244 | |
| 3245 | cc_library { |
| 3246 | name: "libvndk", |
| 3247 | srcs: ["mylib.cpp"], |
| 3248 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3249 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3250 | vndk: { |
| 3251 | enabled: true, |
| 3252 | }, |
| 3253 | system_shared_libs: [], |
| 3254 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3255 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | cc_library { |
| 3259 | name: "libvndksp", |
| 3260 | srcs: ["mylib.cpp"], |
| 3261 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3262 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3263 | vndk: { |
| 3264 | enabled: true, |
| 3265 | support_system_process: true, |
| 3266 | }, |
| 3267 | system_shared_libs: [], |
| 3268 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3269 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3270 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3271 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3272 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3273 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3274 | "lib/libvndk.so", |
| 3275 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3276 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3277 | "lib64/libvndk.so", |
| 3278 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3279 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3280 | "etc/llndk.libraries.VER.txt", |
| 3281 | "etc/vndkcore.libraries.VER.txt", |
| 3282 | "etc/vndksp.libraries.VER.txt", |
| 3283 | "etc/vndkprivate.libraries.VER.txt", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3284 | "etc/vndkproduct.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3285 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | func TestVndkApexWithPrebuilt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3289 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3290 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3291 | name: "com.android.vndk.current", |
| 3292 | key: "com.android.vndk.current.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3293 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3294 | } |
| 3295 | |
| 3296 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3297 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3298 | public_key: "testkey.avbpubkey", |
| 3299 | private_key: "testkey.pem", |
| 3300 | } |
| 3301 | |
| 3302 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3303 | name: "libvndk", |
| 3304 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3305 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3306 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3307 | vndk: { |
| 3308 | enabled: true, |
| 3309 | }, |
| 3310 | system_shared_libs: [], |
| 3311 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3312 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3313 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3314 | |
| 3315 | cc_prebuilt_library_shared { |
| 3316 | name: "libvndk.arm", |
| 3317 | srcs: ["libvndk.arm.so"], |
| 3318 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3319 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3320 | vndk: { |
| 3321 | enabled: true, |
| 3322 | }, |
| 3323 | enabled: false, |
| 3324 | arch: { |
| 3325 | arm: { |
| 3326 | enabled: true, |
| 3327 | }, |
| 3328 | }, |
| 3329 | system_shared_libs: [], |
| 3330 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3331 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3332 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3333 | `+vndkLibrariesTxtFiles("current"), |
| 3334 | withFiles(map[string][]byte{ |
| 3335 | "libvndk.so": nil, |
| 3336 | "libvndk.arm.so": nil, |
| 3337 | })) |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3338 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3339 | "lib/libvndk.so", |
| 3340 | "lib/libvndk.arm.so", |
| 3341 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3342 | "lib/libc++.so", |
| 3343 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3344 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3345 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3346 | } |
| 3347 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3348 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 3349 | for _, v := range vers { |
| 3350 | if v == "current" { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3351 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3352 | result += ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 3353 | ` + txt + `_libraries_txt { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3354 | name: "` + txt + `.libraries.txt", |
| 3355 | } |
| 3356 | ` |
| 3357 | } |
| 3358 | } else { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3359 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3360 | result += ` |
| 3361 | prebuilt_etc { |
| 3362 | name: "` + txt + `.libraries.` + v + `.txt", |
| 3363 | src: "dummy.txt", |
| 3364 | } |
| 3365 | ` |
| 3366 | } |
| 3367 | } |
| 3368 | } |
| 3369 | return |
| 3370 | } |
| 3371 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3372 | func TestVndkApexVersion(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3373 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3374 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3375 | name: "com.android.vndk.v27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3376 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3377 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3378 | vndk_version: "27", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3379 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | apex_key { |
| 3383 | name: "myapex.key", |
| 3384 | public_key: "testkey.avbpubkey", |
| 3385 | private_key: "testkey.pem", |
| 3386 | } |
| 3387 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3388 | vndk_prebuilt_shared { |
| 3389 | name: "libvndk27", |
| 3390 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3391 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3392 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3393 | vndk: { |
| 3394 | enabled: true, |
| 3395 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3396 | target_arch: "arm64", |
| 3397 | arch: { |
| 3398 | arm: { |
| 3399 | srcs: ["libvndk27_arm.so"], |
| 3400 | }, |
| 3401 | arm64: { |
| 3402 | srcs: ["libvndk27_arm64.so"], |
| 3403 | }, |
| 3404 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3405 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | vndk_prebuilt_shared { |
| 3409 | name: "libvndk27", |
| 3410 | version: "27", |
| 3411 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3412 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3413 | vndk: { |
| 3414 | enabled: true, |
| 3415 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3416 | target_arch: "x86_64", |
| 3417 | arch: { |
| 3418 | x86: { |
| 3419 | srcs: ["libvndk27_x86.so"], |
| 3420 | }, |
| 3421 | x86_64: { |
| 3422 | srcs: ["libvndk27_x86_64.so"], |
| 3423 | }, |
| 3424 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3425 | } |
| 3426 | `+vndkLibrariesTxtFiles("27"), |
| 3427 | withFiles(map[string][]byte{ |
| 3428 | "libvndk27_arm.so": nil, |
| 3429 | "libvndk27_arm64.so": nil, |
| 3430 | "libvndk27_x86.so": nil, |
| 3431 | "libvndk27_x86_64.so": nil, |
| 3432 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3433 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3434 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3435 | "lib/libvndk27_arm.so", |
| 3436 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3437 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3438 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3439 | } |
| 3440 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3441 | func TestVndkApexNameRule(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3442 | ctx := testApex(t, ` |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3443 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3444 | name: "com.android.vndk.current", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3445 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3446 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3447 | updatable: false, |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3448 | } |
| 3449 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3450 | name: "com.android.vndk.v28", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3451 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3452 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3453 | vndk_version: "28", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3454 | updatable: false, |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3455 | } |
| 3456 | apex_key { |
| 3457 | name: "myapex.key", |
| 3458 | public_key: "testkey.avbpubkey", |
| 3459 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3460 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3461 | |
| 3462 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3463 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3464 | actual := proptools.String(bundle.properties.Apex_name) |
| 3465 | if !reflect.DeepEqual(actual, expected) { |
| 3466 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3467 | } |
| 3468 | } |
| 3469 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3470 | assertApexName("com.android.vndk.vVER", "com.android.vndk.current") |
| 3471 | assertApexName("com.android.vndk.v28", "com.android.vndk.v28") |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3472 | } |
| 3473 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3474 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3475 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3476 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3477 | name: "com.android.vndk.current", |
| 3478 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3479 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3480 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3481 | } |
| 3482 | |
| 3483 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3484 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3485 | public_key: "testkey.avbpubkey", |
| 3486 | private_key: "testkey.pem", |
| 3487 | } |
| 3488 | |
| 3489 | cc_library { |
| 3490 | name: "libvndk", |
| 3491 | srcs: ["mylib.cpp"], |
| 3492 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3493 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3494 | native_bridge_supported: true, |
| 3495 | host_supported: true, |
| 3496 | vndk: { |
| 3497 | enabled: true, |
| 3498 | }, |
| 3499 | system_shared_libs: [], |
| 3500 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3501 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3502 | } |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3503 | `+vndkLibrariesTxtFiles("current"), |
| 3504 | withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3505 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3506 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3507 | "lib/libvndk.so", |
| 3508 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3509 | "lib/libc++.so", |
| 3510 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3511 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3512 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3516 | 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] | 3517 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3518 | name: "com.android.vndk.current", |
| 3519 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3520 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3521 | native_bridge_supported: true, |
| 3522 | } |
| 3523 | |
| 3524 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3525 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3526 | public_key: "testkey.avbpubkey", |
| 3527 | private_key: "testkey.pem", |
| 3528 | } |
| 3529 | |
| 3530 | cc_library { |
| 3531 | name: "libvndk", |
| 3532 | srcs: ["mylib.cpp"], |
| 3533 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3534 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3535 | native_bridge_supported: true, |
| 3536 | host_supported: true, |
| 3537 | vndk: { |
| 3538 | enabled: true, |
| 3539 | }, |
| 3540 | system_shared_libs: [], |
| 3541 | stl: "none", |
| 3542 | } |
| 3543 | `) |
| 3544 | } |
| 3545 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3546 | func TestVndkApexWithBinder32(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3547 | ctx := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3548 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3549 | name: "com.android.vndk.v27", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3550 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3551 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3552 | vndk_version: "27", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3553 | updatable: false, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | apex_key { |
| 3557 | name: "myapex.key", |
| 3558 | public_key: "testkey.avbpubkey", |
| 3559 | private_key: "testkey.pem", |
| 3560 | } |
| 3561 | |
| 3562 | vndk_prebuilt_shared { |
| 3563 | name: "libvndk27", |
| 3564 | version: "27", |
| 3565 | target_arch: "arm", |
| 3566 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3567 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3568 | vndk: { |
| 3569 | enabled: true, |
| 3570 | }, |
| 3571 | arch: { |
| 3572 | arm: { |
| 3573 | srcs: ["libvndk27.so"], |
| 3574 | } |
| 3575 | }, |
| 3576 | } |
| 3577 | |
| 3578 | vndk_prebuilt_shared { |
| 3579 | name: "libvndk27", |
| 3580 | version: "27", |
| 3581 | target_arch: "arm", |
| 3582 | binder32bit: true, |
| 3583 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3584 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3585 | vndk: { |
| 3586 | enabled: true, |
| 3587 | }, |
| 3588 | arch: { |
| 3589 | arm: { |
| 3590 | srcs: ["libvndk27binder32.so"], |
| 3591 | } |
| 3592 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3593 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3594 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3595 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3596 | withFiles(map[string][]byte{ |
| 3597 | "libvndk27.so": nil, |
| 3598 | "libvndk27binder32.so": nil, |
| 3599 | }), |
| 3600 | withBinder32bit, |
| 3601 | withTargets(map[android.OsType][]android.Target{ |
| 3602 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3603 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3604 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3605 | }, |
| 3606 | }), |
| 3607 | ) |
| 3608 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3609 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3610 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3611 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3612 | }) |
| 3613 | } |
| 3614 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3615 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3616 | ctx := testApex(t, ` |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +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", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3620 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3621 | updatable: false, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3625 | name: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3626 | public_key: "testkey.avbpubkey", |
| 3627 | private_key: "testkey.pem", |
| 3628 | } |
| 3629 | |
| 3630 | cc_library { |
| 3631 | name: "libz", |
| 3632 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3633 | product_available: true, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3634 | vndk: { |
| 3635 | enabled: true, |
| 3636 | }, |
| 3637 | stubs: { |
| 3638 | symbol_file: "libz.map.txt", |
| 3639 | versions: ["30"], |
| 3640 | } |
| 3641 | } |
| 3642 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3643 | "libz.map.txt": nil, |
| 3644 | })) |
| 3645 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3646 | apexManifestRule := ctx.ModuleForTests("com.android.vndk.current", "android_common_image").Rule("apexManifestRule") |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3647 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3648 | ensureListEmpty(t, provideNativeLibs) |
| 3649 | } |
| 3650 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3651 | func TestDependenciesInApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3652 | ctx := testApex(t, ` |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3653 | apex { |
| 3654 | name: "myapex_nodep", |
| 3655 | key: "myapex.key", |
| 3656 | native_shared_libs: ["lib_nodep"], |
| 3657 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3658 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3659 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | apex { |
| 3663 | name: "myapex_dep", |
| 3664 | key: "myapex.key", |
| 3665 | native_shared_libs: ["lib_dep"], |
| 3666 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3667 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3668 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | apex { |
| 3672 | name: "myapex_provider", |
| 3673 | key: "myapex.key", |
| 3674 | native_shared_libs: ["libfoo"], |
| 3675 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3676 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3677 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | apex { |
| 3681 | name: "myapex_selfcontained", |
| 3682 | key: "myapex.key", |
| 3683 | native_shared_libs: ["lib_dep", "libfoo"], |
| 3684 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3685 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3686 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | apex_key { |
| 3690 | name: "myapex.key", |
| 3691 | public_key: "testkey.avbpubkey", |
| 3692 | private_key: "testkey.pem", |
| 3693 | } |
| 3694 | |
| 3695 | cc_library { |
| 3696 | name: "lib_nodep", |
| 3697 | srcs: ["mylib.cpp"], |
| 3698 | system_shared_libs: [], |
| 3699 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3700 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | cc_library { |
| 3704 | name: "lib_dep", |
| 3705 | srcs: ["mylib.cpp"], |
| 3706 | shared_libs: ["libfoo"], |
| 3707 | system_shared_libs: [], |
| 3708 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3709 | apex_available: [ |
| 3710 | "myapex_dep", |
| 3711 | "myapex_provider", |
| 3712 | "myapex_selfcontained", |
| 3713 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3714 | } |
| 3715 | |
| 3716 | cc_library { |
| 3717 | name: "libfoo", |
| 3718 | srcs: ["mytest.cpp"], |
| 3719 | stubs: { |
| 3720 | versions: ["1"], |
| 3721 | }, |
| 3722 | system_shared_libs: [], |
| 3723 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3724 | apex_available: [ |
| 3725 | "myapex_provider", |
| 3726 | "myapex_selfcontained", |
| 3727 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3728 | } |
| 3729 | `) |
| 3730 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3731 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3732 | var provideNativeLibs, requireNativeLibs []string |
| 3733 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3734 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3735 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3736 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3737 | ensureListEmpty(t, provideNativeLibs) |
| 3738 | ensureListEmpty(t, requireNativeLibs) |
| 3739 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3740 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3741 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3742 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3743 | ensureListEmpty(t, provideNativeLibs) |
| 3744 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 3745 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3746 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3747 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3748 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3749 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3750 | ensureListEmpty(t, requireNativeLibs) |
| 3751 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3752 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3753 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3754 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3755 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3756 | ensureListEmpty(t, requireNativeLibs) |
| 3757 | } |
| 3758 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3759 | func TestApexName(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3760 | ctx := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3761 | apex { |
| 3762 | name: "myapex", |
| 3763 | key: "myapex.key", |
| 3764 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3765 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3766 | updatable: false, |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | apex_key { |
| 3770 | name: "myapex.key", |
| 3771 | public_key: "testkey.avbpubkey", |
| 3772 | private_key: "testkey.pem", |
| 3773 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3774 | |
| 3775 | cc_library { |
| 3776 | name: "mylib", |
| 3777 | srcs: ["mylib.cpp"], |
| 3778 | system_shared_libs: [], |
| 3779 | stl: "none", |
| 3780 | apex_available: [ |
| 3781 | "//apex_available:platform", |
| 3782 | "myapex", |
| 3783 | ], |
| 3784 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3785 | `) |
| 3786 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3787 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3788 | apexManifestRule := module.Rule("apexManifestRule") |
| 3789 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 3790 | apexRule := module.Rule("apexRule") |
| 3791 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3792 | |
| 3793 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3794 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3795 | name := apexBundle.BaseModuleName() |
| 3796 | prefix := "TARGET_" |
| 3797 | var builder strings.Builder |
| 3798 | data.Custom(&builder, name, prefix, "", data) |
| 3799 | androidMk := builder.String() |
| 3800 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 3801 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3802 | } |
| 3803 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3804 | func TestNonTestApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3805 | ctx := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3806 | apex { |
| 3807 | name: "myapex", |
| 3808 | key: "myapex.key", |
| 3809 | native_shared_libs: ["mylib_common"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3810 | updatable: false, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | apex_key { |
| 3814 | name: "myapex.key", |
| 3815 | public_key: "testkey.avbpubkey", |
| 3816 | private_key: "testkey.pem", |
| 3817 | } |
| 3818 | |
| 3819 | cc_library { |
| 3820 | name: "mylib_common", |
| 3821 | srcs: ["mylib.cpp"], |
| 3822 | system_shared_libs: [], |
| 3823 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3824 | apex_available: [ |
| 3825 | "//apex_available:platform", |
| 3826 | "myapex", |
| 3827 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3828 | } |
| 3829 | `) |
| 3830 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3831 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3832 | apexRule := module.Rule("apexRule") |
| 3833 | copyCmds := apexRule.Args["copy_commands"] |
| 3834 | |
| 3835 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 3836 | t.Log("Apex was a test apex!") |
| 3837 | t.Fail() |
| 3838 | } |
| 3839 | // Ensure that main rule creates an output |
| 3840 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3841 | |
| 3842 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3843 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3844 | |
| 3845 | // Ensure that both direct and indirect deps are copied into apex |
| 3846 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3847 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3848 | // Ensure that the platform variant ends with _shared |
| 3849 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3850 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3851 | 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] | 3852 | t.Log("Found mylib_common not in any apex!") |
| 3853 | t.Fail() |
| 3854 | } |
| 3855 | } |
| 3856 | |
| 3857 | func TestTestApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3858 | ctx := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3859 | apex_test { |
| 3860 | name: "myapex", |
| 3861 | key: "myapex.key", |
| 3862 | native_shared_libs: ["mylib_common_test"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3863 | updatable: false, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | apex_key { |
| 3867 | name: "myapex.key", |
| 3868 | public_key: "testkey.avbpubkey", |
| 3869 | private_key: "testkey.pem", |
| 3870 | } |
| 3871 | |
| 3872 | cc_library { |
| 3873 | name: "mylib_common_test", |
| 3874 | srcs: ["mylib.cpp"], |
| 3875 | system_shared_libs: [], |
| 3876 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3877 | // TODO: remove //apex_available:platform |
| 3878 | apex_available: [ |
| 3879 | "//apex_available:platform", |
| 3880 | "myapex", |
| 3881 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3882 | } |
| 3883 | `) |
| 3884 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3885 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3886 | apexRule := module.Rule("apexRule") |
| 3887 | copyCmds := apexRule.Args["copy_commands"] |
| 3888 | |
| 3889 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 3890 | t.Log("Apex was not a test apex!") |
| 3891 | t.Fail() |
| 3892 | } |
| 3893 | // Ensure that main rule creates an output |
| 3894 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3895 | |
| 3896 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3897 | 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] | 3898 | |
| 3899 | // Ensure that both direct and indirect deps are copied into apex |
| 3900 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 3901 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3902 | // Ensure that the platform variant ends with _shared |
| 3903 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3904 | } |
| 3905 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3906 | func TestApexWithTarget(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3907 | ctx := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3908 | apex { |
| 3909 | name: "myapex", |
| 3910 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3911 | updatable: false, |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3912 | multilib: { |
| 3913 | first: { |
| 3914 | native_shared_libs: ["mylib_common"], |
| 3915 | } |
| 3916 | }, |
| 3917 | target: { |
| 3918 | android: { |
| 3919 | multilib: { |
| 3920 | first: { |
| 3921 | native_shared_libs: ["mylib"], |
| 3922 | } |
| 3923 | } |
| 3924 | }, |
| 3925 | host: { |
| 3926 | multilib: { |
| 3927 | first: { |
| 3928 | native_shared_libs: ["mylib2"], |
| 3929 | } |
| 3930 | } |
| 3931 | } |
| 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | apex_key { |
| 3936 | name: "myapex.key", |
| 3937 | public_key: "testkey.avbpubkey", |
| 3938 | private_key: "testkey.pem", |
| 3939 | } |
| 3940 | |
| 3941 | cc_library { |
| 3942 | name: "mylib", |
| 3943 | srcs: ["mylib.cpp"], |
| 3944 | system_shared_libs: [], |
| 3945 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3946 | // TODO: remove //apex_available:platform |
| 3947 | apex_available: [ |
| 3948 | "//apex_available:platform", |
| 3949 | "myapex", |
| 3950 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | cc_library { |
| 3954 | name: "mylib_common", |
| 3955 | srcs: ["mylib.cpp"], |
| 3956 | system_shared_libs: [], |
| 3957 | stl: "none", |
| 3958 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3959 | // TODO: remove //apex_available:platform |
| 3960 | apex_available: [ |
| 3961 | "//apex_available:platform", |
| 3962 | "myapex", |
| 3963 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | cc_library { |
| 3967 | name: "mylib2", |
| 3968 | srcs: ["mylib.cpp"], |
| 3969 | system_shared_libs: [], |
| 3970 | stl: "none", |
| 3971 | compile_multilib: "first", |
| 3972 | } |
| 3973 | `) |
| 3974 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3975 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3976 | copyCmds := apexRule.Args["copy_commands"] |
| 3977 | |
| 3978 | // Ensure that main rule creates an output |
| 3979 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3980 | |
| 3981 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3982 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 3983 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
| 3984 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3985 | |
| 3986 | // Ensure that both direct and indirect deps are copied into apex |
| 3987 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 3988 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3989 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 3990 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3991 | // Ensure that the platform variant ends with _shared |
| 3992 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 3993 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 3994 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3995 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3996 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 3997 | func TestApexWithArch(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3998 | ctx := testApex(t, ` |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 3999 | apex { |
| 4000 | name: "myapex", |
| 4001 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4002 | updatable: false, |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4003 | arch: { |
| 4004 | arm64: { |
| 4005 | native_shared_libs: ["mylib.arm64"], |
| 4006 | }, |
| 4007 | x86_64: { |
| 4008 | native_shared_libs: ["mylib.x64"], |
| 4009 | }, |
| 4010 | } |
| 4011 | } |
| 4012 | |
| 4013 | apex_key { |
| 4014 | name: "myapex.key", |
| 4015 | public_key: "testkey.avbpubkey", |
| 4016 | private_key: "testkey.pem", |
| 4017 | } |
| 4018 | |
| 4019 | cc_library { |
| 4020 | name: "mylib.arm64", |
| 4021 | srcs: ["mylib.cpp"], |
| 4022 | system_shared_libs: [], |
| 4023 | stl: "none", |
| 4024 | // TODO: remove //apex_available:platform |
| 4025 | apex_available: [ |
| 4026 | "//apex_available:platform", |
| 4027 | "myapex", |
| 4028 | ], |
| 4029 | } |
| 4030 | |
| 4031 | cc_library { |
| 4032 | name: "mylib.x64", |
| 4033 | srcs: ["mylib.cpp"], |
| 4034 | system_shared_libs: [], |
| 4035 | stl: "none", |
| 4036 | // TODO: remove //apex_available:platform |
| 4037 | apex_available: [ |
| 4038 | "//apex_available:platform", |
| 4039 | "myapex", |
| 4040 | ], |
| 4041 | } |
| 4042 | `) |
| 4043 | |
| 4044 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 4045 | copyCmds := apexRule.Args["copy_commands"] |
| 4046 | |
| 4047 | // Ensure that apex variant is created for the direct dep |
| 4048 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib.arm64"), "android_arm64_armv8-a_shared_apex10000") |
| 4049 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib.x64"), "android_arm64_armv8-a_shared_apex10000") |
| 4050 | |
| 4051 | // Ensure that both direct and indirect deps are copied into apex |
| 4052 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.arm64.so") |
| 4053 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib.x64.so") |
| 4054 | } |
| 4055 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4056 | func TestApexWithShBinary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4057 | ctx := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4058 | apex { |
| 4059 | name: "myapex", |
| 4060 | key: "myapex.key", |
| 4061 | binaries: ["myscript"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4062 | updatable: false, |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | apex_key { |
| 4066 | name: "myapex.key", |
| 4067 | public_key: "testkey.avbpubkey", |
| 4068 | private_key: "testkey.pem", |
| 4069 | } |
| 4070 | |
| 4071 | sh_binary { |
| 4072 | name: "myscript", |
| 4073 | src: "mylib.cpp", |
| 4074 | filename: "myscript.sh", |
| 4075 | sub_dir: "script", |
| 4076 | } |
| 4077 | `) |
| 4078 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4079 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4080 | copyCmds := apexRule.Args["copy_commands"] |
| 4081 | |
| 4082 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 4083 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4084 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4085 | func TestApexInVariousPartition(t *testing.T) { |
| 4086 | testcases := []struct { |
| 4087 | propName, parition, flattenedPartition string |
| 4088 | }{ |
| 4089 | {"", "system", "system_ext"}, |
| 4090 | {"product_specific: true", "product", "product"}, |
| 4091 | {"soc_specific: true", "vendor", "vendor"}, |
| 4092 | {"proprietary: true", "vendor", "vendor"}, |
| 4093 | {"vendor: true", "vendor", "vendor"}, |
| 4094 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 4095 | } |
| 4096 | for _, tc := range testcases { |
| 4097 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4098 | ctx := testApex(t, ` |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4099 | apex { |
| 4100 | name: "myapex", |
| 4101 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4102 | updatable: false, |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4103 | `+tc.propName+` |
| 4104 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4105 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4106 | apex_key { |
| 4107 | name: "myapex.key", |
| 4108 | public_key: "testkey.avbpubkey", |
| 4109 | private_key: "testkey.pem", |
| 4110 | } |
| 4111 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4112 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4113 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 4114 | expected := "out/soong/target/product/test_device/" + tc.parition + "/apex" |
| 4115 | actual := apex.installDir.RelativeToTop().String() |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4116 | if actual != expected { |
| 4117 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4118 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4119 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4120 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 4121 | expected = "out/soong/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 4122 | actual = flattened.installDir.RelativeToTop().String() |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4123 | if actual != expected { |
| 4124 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4125 | } |
| 4126 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4127 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4128 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4129 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4130 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4131 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4132 | apex { |
| 4133 | name: "myapex", |
| 4134 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4135 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4136 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4137 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4138 | apex_key { |
| 4139 | name: "myapex.key", |
| 4140 | public_key: "testkey.avbpubkey", |
| 4141 | private_key: "testkey.pem", |
| 4142 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4143 | `) |
| 4144 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4145 | rule := module.Output("file_contexts") |
| 4146 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 4147 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4148 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4149 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4150 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4151 | apex { |
| 4152 | name: "myapex", |
| 4153 | key: "myapex.key", |
| 4154 | file_contexts: "my_own_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4155 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4156 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4157 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4158 | apex_key { |
| 4159 | name: "myapex.key", |
| 4160 | public_key: "testkey.avbpubkey", |
| 4161 | private_key: "testkey.pem", |
| 4162 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4163 | `, withFiles(map[string][]byte{ |
| 4164 | "my_own_file_contexts": nil, |
| 4165 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4166 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4167 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4168 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4169 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4170 | apex { |
| 4171 | name: "myapex", |
| 4172 | key: "myapex.key", |
| 4173 | product_specific: true, |
| 4174 | file_contexts: "product_specific_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4175 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4176 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4177 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4178 | apex_key { |
| 4179 | name: "myapex.key", |
| 4180 | public_key: "testkey.avbpubkey", |
| 4181 | private_key: "testkey.pem", |
| 4182 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4183 | `) |
| 4184 | |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4185 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4186 | apex { |
| 4187 | name: "myapex", |
| 4188 | key: "myapex.key", |
| 4189 | product_specific: true, |
| 4190 | file_contexts: "product_specific_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4191 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4192 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4193 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4194 | apex_key { |
| 4195 | name: "myapex.key", |
| 4196 | public_key: "testkey.avbpubkey", |
| 4197 | private_key: "testkey.pem", |
| 4198 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4199 | `, withFiles(map[string][]byte{ |
| 4200 | "product_specific_file_contexts": nil, |
| 4201 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4202 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4203 | rule := module.Output("file_contexts") |
| 4204 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 4205 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4206 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4207 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4208 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4209 | apex { |
| 4210 | name: "myapex", |
| 4211 | key: "myapex.key", |
| 4212 | product_specific: true, |
| 4213 | file_contexts: ":my-file-contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4214 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4215 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4216 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4217 | apex_key { |
| 4218 | name: "myapex.key", |
| 4219 | public_key: "testkey.avbpubkey", |
| 4220 | private_key: "testkey.pem", |
| 4221 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4222 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4223 | filegroup { |
| 4224 | name: "my-file-contexts", |
| 4225 | srcs: ["product_specific_file_contexts"], |
| 4226 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4227 | `, withFiles(map[string][]byte{ |
| 4228 | "product_specific_file_contexts": nil, |
| 4229 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4230 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4231 | rule := module.Output("file_contexts") |
| 4232 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4233 | } |
| 4234 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4235 | func TestApexKeyFromOtherModule(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4236 | ctx := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4237 | apex_key { |
| 4238 | name: "myapex.key", |
| 4239 | public_key: ":my.avbpubkey", |
| 4240 | private_key: ":my.pem", |
| 4241 | product_specific: true, |
| 4242 | } |
| 4243 | |
| 4244 | filegroup { |
| 4245 | name: "my.avbpubkey", |
| 4246 | srcs: ["testkey2.avbpubkey"], |
| 4247 | } |
| 4248 | |
| 4249 | filegroup { |
| 4250 | name: "my.pem", |
| 4251 | srcs: ["testkey2.pem"], |
| 4252 | } |
| 4253 | `) |
| 4254 | |
| 4255 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 4256 | expected_pubkey := "testkey2.avbpubkey" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4257 | actual_pubkey := apex_key.publicKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4258 | if actual_pubkey != expected_pubkey { |
| 4259 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 4260 | } |
| 4261 | expected_privkey := "testkey2.pem" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4262 | actual_privkey := apex_key.privateKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4263 | if actual_privkey != expected_privkey { |
| 4264 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 4265 | } |
| 4266 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4267 | |
| 4268 | func TestPrebuilt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4269 | ctx := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4270 | prebuilt_apex { |
| 4271 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4272 | arch: { |
| 4273 | arm64: { |
| 4274 | src: "myapex-arm64.apex", |
| 4275 | }, |
| 4276 | arm: { |
| 4277 | src: "myapex-arm.apex", |
| 4278 | }, |
| 4279 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4280 | } |
| 4281 | `) |
| 4282 | |
| 4283 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4284 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4285 | expectedInput := "myapex-arm64.apex" |
| 4286 | if prebuilt.inputApex.String() != expectedInput { |
| 4287 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 4288 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4289 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4290 | |
| 4291 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4292 | ctx := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4293 | prebuilt_apex { |
| 4294 | name: "myapex", |
| 4295 | src: "myapex-arm.apex", |
| 4296 | filename: "notmyapex.apex", |
| 4297 | } |
| 4298 | `) |
| 4299 | |
| 4300 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4301 | |
| 4302 | expected := "notmyapex.apex" |
| 4303 | if p.installFilename != expected { |
| 4304 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 4305 | } |
| 4306 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4307 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4308 | func TestPrebuiltOverrides(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4309 | ctx := testApex(t, ` |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4310 | prebuilt_apex { |
| 4311 | name: "myapex.prebuilt", |
| 4312 | src: "myapex-arm.apex", |
| 4313 | overrides: [ |
| 4314 | "myapex", |
| 4315 | ], |
| 4316 | } |
| 4317 | `) |
| 4318 | |
| 4319 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 4320 | |
| 4321 | expected := []string{"myapex"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4322 | actual := android.AndroidMkEntriesForTest(t, ctx, p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4323 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 4324 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4325 | } |
| 4326 | } |
| 4327 | |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4328 | // These tests verify that the prebuilt_apex/deapexer to java_import wiring allows for the |
| 4329 | // 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] | 4330 | func TestPrebuiltExportDexImplementationJars(t *testing.T) { |
| 4331 | transform := func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4332 | // Empty transformation. |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4333 | } |
| 4334 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4335 | checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4336 | // 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] | 4337 | p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4338 | dexJarBuildPath := p.DexJarBuildPath() |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4339 | stem := android.RemoveOptionalPrebuiltPrefix(name) |
| 4340 | if expected, actual := ".intermediates/myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar", android.NormalizePathForTesting(dexJarBuildPath); actual != expected { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4341 | t.Errorf("Incorrect DexJarBuildPath value '%s', expected '%s'", actual, expected) |
| 4342 | } |
| 4343 | } |
| 4344 | |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4345 | ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4346 | // Make sure that an apex variant is not created for the source module. |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4347 | if expected, actual := []string{"android_common"}, ctx.ModuleVariantsForTests(name); !reflect.DeepEqual(expected, actual) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4348 | t.Errorf("invalid set of variants for %q: expected %q, found %q", "libfoo", expected, actual) |
| 4349 | } |
| 4350 | } |
| 4351 | |
| 4352 | t.Run("prebuilt only", func(t *testing.T) { |
| 4353 | bp := ` |
| 4354 | prebuilt_apex { |
| 4355 | name: "myapex", |
| 4356 | arch: { |
| 4357 | arm64: { |
| 4358 | src: "myapex-arm64.apex", |
| 4359 | }, |
| 4360 | arm: { |
| 4361 | src: "myapex-arm.apex", |
| 4362 | }, |
| 4363 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4364 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | java_import { |
| 4368 | name: "libfoo", |
| 4369 | jars: ["libfoo.jar"], |
| 4370 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4371 | |
| 4372 | java_sdk_library_import { |
| 4373 | name: "libbar", |
| 4374 | public: { |
| 4375 | jars: ["libbar.jar"], |
| 4376 | }, |
| 4377 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4378 | ` |
| 4379 | |
| 4380 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4381 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4382 | |
Paul Duffin | f6932af | 2021-02-26 18:21:56 +0000 | [diff] [blame] | 4383 | // Make sure that the deapexer has the correct input APEX. |
| 4384 | deapexer := ctx.ModuleForTests("myapex.deapexer", "android_common") |
| 4385 | rule := deapexer.Rule("deapexer") |
| 4386 | if expected, actual := []string{"myapex-arm64.apex"}, android.NormalizePathsForTesting(rule.Implicits); !reflect.DeepEqual(expected, actual) { |
| 4387 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4388 | } |
| 4389 | |
Paul Duffin | 0d10c3c | 2021-03-01 17:09:32 +0000 | [diff] [blame] | 4390 | // Make sure that the prebuilt_apex has the correct input APEX. |
| 4391 | prebuiltApex := ctx.ModuleForTests("myapex", "android_common") |
| 4392 | rule = prebuiltApex.Rule("android/soong/android.Cp") |
| 4393 | if expected, actual := "myapex-arm64.apex", android.NormalizePathForTesting(rule.Input); !reflect.DeepEqual(expected, actual) { |
| 4394 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4395 | } |
| 4396 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4397 | checkDexJarBuildPath(t, ctx, "libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4398 | |
| 4399 | checkDexJarBuildPath(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4400 | }) |
| 4401 | |
| 4402 | t.Run("prebuilt with source preferred", func(t *testing.T) { |
| 4403 | |
| 4404 | bp := ` |
| 4405 | prebuilt_apex { |
| 4406 | name: "myapex", |
| 4407 | arch: { |
| 4408 | arm64: { |
| 4409 | src: "myapex-arm64.apex", |
| 4410 | }, |
| 4411 | arm: { |
| 4412 | src: "myapex-arm.apex", |
| 4413 | }, |
| 4414 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4415 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | java_import { |
| 4419 | name: "libfoo", |
| 4420 | jars: ["libfoo.jar"], |
| 4421 | } |
| 4422 | |
| 4423 | java_library { |
| 4424 | name: "libfoo", |
| 4425 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4426 | |
| 4427 | java_sdk_library_import { |
| 4428 | name: "libbar", |
| 4429 | public: { |
| 4430 | jars: ["libbar.jar"], |
| 4431 | }, |
| 4432 | } |
| 4433 | |
| 4434 | java_sdk_library { |
| 4435 | name: "libbar", |
| 4436 | srcs: ["foo/bar/MyClass.java"], |
| 4437 | unsafe_ignore_missing_latest_api: true, |
| 4438 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4439 | ` |
| 4440 | |
| 4441 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4442 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4443 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4444 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4445 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4446 | |
| 4447 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
| 4448 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4449 | }) |
| 4450 | |
| 4451 | t.Run("prebuilt preferred with source", func(t *testing.T) { |
| 4452 | bp := ` |
| 4453 | prebuilt_apex { |
| 4454 | name: "myapex", |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4455 | arch: { |
| 4456 | arm64: { |
| 4457 | src: "myapex-arm64.apex", |
| 4458 | }, |
| 4459 | arm: { |
| 4460 | src: "myapex-arm.apex", |
| 4461 | }, |
| 4462 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4463 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | java_import { |
| 4467 | name: "libfoo", |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4468 | prefer: true, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4469 | jars: ["libfoo.jar"], |
| 4470 | } |
| 4471 | |
| 4472 | java_library { |
| 4473 | name: "libfoo", |
| 4474 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4475 | |
| 4476 | java_sdk_library_import { |
| 4477 | name: "libbar", |
| 4478 | prefer: true, |
| 4479 | public: { |
| 4480 | jars: ["libbar.jar"], |
| 4481 | }, |
| 4482 | } |
| 4483 | |
| 4484 | java_sdk_library { |
| 4485 | name: "libbar", |
| 4486 | srcs: ["foo/bar/MyClass.java"], |
| 4487 | unsafe_ignore_missing_latest_api: true, |
| 4488 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4489 | ` |
| 4490 | |
| 4491 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4492 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4493 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4494 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4495 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4496 | |
| 4497 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
| 4498 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4499 | }) |
| 4500 | } |
| 4501 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4502 | func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { |
| 4503 | transform := func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4504 | config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo", "myapex:libbar"}) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4507 | checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) { |
| 4508 | t.Helper() |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4509 | s := ctx.SingletonForTests("dex_bootjars") |
| 4510 | foundLibfooJar := false |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4511 | base := stem + ".jar" |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4512 | for _, output := range s.AllOutputs() { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4513 | if filepath.Base(output) == base { |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4514 | foundLibfooJar = true |
| 4515 | buildRule := s.Output(output) |
| 4516 | actual := android.NormalizePathForTesting(buildRule.Input) |
| 4517 | if actual != bootDexJarPath { |
| 4518 | t.Errorf("Incorrect boot dex jar path '%s', expected '%s'", actual, bootDexJarPath) |
| 4519 | } |
| 4520 | } |
| 4521 | } |
| 4522 | if !foundLibfooJar { |
| 4523 | t.Errorf("Rule for libfoo.jar missing in dex_bootjars singleton outputs") |
| 4524 | } |
| 4525 | } |
| 4526 | |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4527 | checkHiddenAPIIndexInputs := func(t *testing.T, ctx *android.TestContext, expectedInputs string) { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4528 | t.Helper() |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4529 | hiddenAPIIndex := ctx.SingletonForTests("hiddenapi_index") |
| 4530 | indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index") |
| 4531 | java.CheckHiddenAPIRuleInputs(t, expectedInputs, indexRule) |
| 4532 | } |
| 4533 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4534 | t.Run("prebuilt only", func(t *testing.T) { |
| 4535 | bp := ` |
| 4536 | prebuilt_apex { |
| 4537 | name: "myapex", |
| 4538 | arch: { |
| 4539 | arm64: { |
| 4540 | src: "myapex-arm64.apex", |
| 4541 | }, |
| 4542 | arm: { |
| 4543 | src: "myapex-arm.apex", |
| 4544 | }, |
| 4545 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4546 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4547 | } |
| 4548 | |
| 4549 | java_import { |
| 4550 | name: "libfoo", |
| 4551 | jars: ["libfoo.jar"], |
| 4552 | apex_available: ["myapex"], |
| 4553 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4554 | |
| 4555 | java_sdk_library_import { |
| 4556 | name: "libbar", |
| 4557 | public: { |
| 4558 | jars: ["libbar.jar"], |
| 4559 | }, |
| 4560 | apex_available: ["myapex"], |
| 4561 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4562 | ` |
| 4563 | |
| 4564 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4565 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4566 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4567 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4568 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4569 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4570 | .intermediates/libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4571 | .intermediates/libfoo/android_common_myapex/hiddenapi/index.csv |
| 4572 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4573 | }) |
| 4574 | |
| 4575 | t.Run("prebuilt with source library preferred", func(t *testing.T) { |
| 4576 | bp := ` |
| 4577 | prebuilt_apex { |
| 4578 | name: "myapex", |
| 4579 | arch: { |
| 4580 | arm64: { |
| 4581 | src: "myapex-arm64.apex", |
| 4582 | }, |
| 4583 | arm: { |
| 4584 | src: "myapex-arm.apex", |
| 4585 | }, |
| 4586 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4587 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4588 | } |
| 4589 | |
| 4590 | java_import { |
| 4591 | name: "libfoo", |
| 4592 | jars: ["libfoo.jar"], |
| 4593 | apex_available: ["myapex"], |
| 4594 | } |
| 4595 | |
| 4596 | java_library { |
| 4597 | name: "libfoo", |
| 4598 | srcs: ["foo/bar/MyClass.java"], |
| 4599 | apex_available: ["myapex"], |
| 4600 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4601 | |
| 4602 | java_sdk_library_import { |
| 4603 | name: "libbar", |
| 4604 | public: { |
| 4605 | jars: ["libbar.jar"], |
| 4606 | }, |
| 4607 | apex_available: ["myapex"], |
| 4608 | } |
| 4609 | |
| 4610 | java_sdk_library { |
| 4611 | name: "libbar", |
| 4612 | srcs: ["foo/bar/MyClass.java"], |
| 4613 | unsafe_ignore_missing_latest_api: true, |
| 4614 | apex_available: ["myapex"], |
| 4615 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4616 | ` |
| 4617 | |
| 4618 | // In this test the source (java_library) libfoo is active since the |
| 4619 | // prebuilt (java_import) defaults to prefer:false. However the |
| 4620 | // prebuilt_apex module always depends on the prebuilt, and so it doesn't |
| 4621 | // find the dex boot jar in it. We either need to disable the source libfoo |
| 4622 | // or make the prebuilt libfoo preferred. |
| 4623 | testDexpreoptWithApexes(t, bp, "failed to find a dex jar path for module 'libfoo'", transform) |
| 4624 | }) |
| 4625 | |
| 4626 | t.Run("prebuilt library preferred with source", func(t *testing.T) { |
| 4627 | bp := ` |
| 4628 | prebuilt_apex { |
| 4629 | name: "myapex", |
| 4630 | arch: { |
| 4631 | arm64: { |
| 4632 | src: "myapex-arm64.apex", |
| 4633 | }, |
| 4634 | arm: { |
| 4635 | src: "myapex-arm.apex", |
| 4636 | }, |
| 4637 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4638 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | java_import { |
| 4642 | name: "libfoo", |
| 4643 | prefer: true, |
| 4644 | jars: ["libfoo.jar"], |
| 4645 | apex_available: ["myapex"], |
| 4646 | } |
| 4647 | |
| 4648 | java_library { |
| 4649 | name: "libfoo", |
| 4650 | srcs: ["foo/bar/MyClass.java"], |
| 4651 | apex_available: ["myapex"], |
| 4652 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4653 | |
| 4654 | java_sdk_library_import { |
| 4655 | name: "libbar", |
| 4656 | prefer: true, |
| 4657 | public: { |
| 4658 | jars: ["libbar.jar"], |
| 4659 | }, |
| 4660 | apex_available: ["myapex"], |
| 4661 | } |
| 4662 | |
| 4663 | java_sdk_library { |
| 4664 | name: "libbar", |
| 4665 | srcs: ["foo/bar/MyClass.java"], |
| 4666 | unsafe_ignore_missing_latest_api: true, |
| 4667 | apex_available: ["myapex"], |
| 4668 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4669 | ` |
| 4670 | |
| 4671 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4672 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4673 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4674 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4675 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4676 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4677 | .intermediates/prebuilt_libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4678 | .intermediates/prebuilt_libfoo/android_common_myapex/hiddenapi/index.csv |
| 4679 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4680 | }) |
| 4681 | |
| 4682 | t.Run("prebuilt with source apex preferred", func(t *testing.T) { |
| 4683 | bp := ` |
| 4684 | apex { |
| 4685 | name: "myapex", |
| 4686 | key: "myapex.key", |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4687 | java_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4688 | updatable: false, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | apex_key { |
| 4692 | name: "myapex.key", |
| 4693 | public_key: "testkey.avbpubkey", |
| 4694 | private_key: "testkey.pem", |
| 4695 | } |
| 4696 | |
| 4697 | prebuilt_apex { |
| 4698 | name: "myapex", |
| 4699 | arch: { |
| 4700 | arm64: { |
| 4701 | src: "myapex-arm64.apex", |
| 4702 | }, |
| 4703 | arm: { |
| 4704 | src: "myapex-arm.apex", |
| 4705 | }, |
| 4706 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4707 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | java_import { |
| 4711 | name: "libfoo", |
| 4712 | jars: ["libfoo.jar"], |
| 4713 | apex_available: ["myapex"], |
| 4714 | } |
| 4715 | |
| 4716 | java_library { |
| 4717 | name: "libfoo", |
| 4718 | srcs: ["foo/bar/MyClass.java"], |
| 4719 | apex_available: ["myapex"], |
| 4720 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4721 | |
| 4722 | java_sdk_library_import { |
| 4723 | name: "libbar", |
| 4724 | public: { |
| 4725 | jars: ["libbar.jar"], |
| 4726 | }, |
| 4727 | apex_available: ["myapex"], |
| 4728 | } |
| 4729 | |
| 4730 | java_sdk_library { |
| 4731 | name: "libbar", |
| 4732 | srcs: ["foo/bar/MyClass.java"], |
| 4733 | unsafe_ignore_missing_latest_api: true, |
| 4734 | apex_available: ["myapex"], |
| 4735 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4736 | ` |
| 4737 | |
| 4738 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4739 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar") |
| 4740 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/libbar/android_common_myapex/hiddenapi/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4741 | |
| 4742 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4743 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4744 | .intermediates/libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4745 | .intermediates/libfoo/android_common_apex10000/hiddenapi/index.csv |
| 4746 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4747 | }) |
| 4748 | |
| 4749 | t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) { |
| 4750 | bp := ` |
| 4751 | apex { |
| 4752 | name: "myapex", |
| 4753 | enabled: false, |
| 4754 | key: "myapex.key", |
| 4755 | java_libs: ["libfoo"], |
| 4756 | } |
| 4757 | |
| 4758 | apex_key { |
| 4759 | name: "myapex.key", |
| 4760 | public_key: "testkey.avbpubkey", |
| 4761 | private_key: "testkey.pem", |
| 4762 | } |
| 4763 | |
| 4764 | prebuilt_apex { |
| 4765 | name: "myapex", |
| 4766 | arch: { |
| 4767 | arm64: { |
| 4768 | src: "myapex-arm64.apex", |
| 4769 | }, |
| 4770 | arm: { |
| 4771 | src: "myapex-arm.apex", |
| 4772 | }, |
| 4773 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4774 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | java_import { |
| 4778 | name: "libfoo", |
| 4779 | prefer: true, |
| 4780 | jars: ["libfoo.jar"], |
| 4781 | apex_available: ["myapex"], |
| 4782 | } |
| 4783 | |
| 4784 | java_library { |
| 4785 | name: "libfoo", |
| 4786 | srcs: ["foo/bar/MyClass.java"], |
| 4787 | apex_available: ["myapex"], |
| 4788 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4789 | |
| 4790 | java_sdk_library_import { |
| 4791 | name: "libbar", |
| 4792 | prefer: true, |
| 4793 | public: { |
| 4794 | jars: ["libbar.jar"], |
| 4795 | }, |
| 4796 | apex_available: ["myapex"], |
| 4797 | } |
| 4798 | |
| 4799 | java_sdk_library { |
| 4800 | name: "libbar", |
| 4801 | srcs: ["foo/bar/MyClass.java"], |
| 4802 | unsafe_ignore_missing_latest_api: true, |
| 4803 | apex_available: ["myapex"], |
| 4804 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4805 | ` |
| 4806 | |
| 4807 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4808 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4809 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4810 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4811 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4812 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4813 | .intermediates/prebuilt_libbar/android_common_prebuilt_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4814 | .intermediates/prebuilt_libfoo/android_common_prebuilt_myapex/hiddenapi/index.csv |
| 4815 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4816 | }) |
| 4817 | } |
| 4818 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4819 | func TestApexWithTests(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4820 | ctx := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4821 | apex_test { |
| 4822 | name: "myapex", |
| 4823 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4824 | updatable: false, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4825 | tests: [ |
| 4826 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4827 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4828 | ], |
| 4829 | } |
| 4830 | |
| 4831 | apex_key { |
| 4832 | name: "myapex.key", |
| 4833 | public_key: "testkey.avbpubkey", |
| 4834 | private_key: "testkey.pem", |
| 4835 | } |
| 4836 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4837 | filegroup { |
| 4838 | name: "fg", |
| 4839 | srcs: [ |
| 4840 | "baz", |
| 4841 | "bar/baz" |
| 4842 | ], |
| 4843 | } |
| 4844 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4845 | cc_test { |
| 4846 | name: "mytest", |
| 4847 | gtest: false, |
| 4848 | srcs: ["mytest.cpp"], |
| 4849 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4850 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4851 | system_shared_libs: [], |
| 4852 | static_executable: true, |
| 4853 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4854 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4855 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4856 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4857 | cc_library { |
| 4858 | name: "mylib", |
| 4859 | srcs: ["mylib.cpp"], |
| 4860 | system_shared_libs: [], |
| 4861 | stl: "none", |
| 4862 | } |
| 4863 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4864 | filegroup { |
| 4865 | name: "fg2", |
| 4866 | srcs: [ |
| 4867 | "testdata/baz" |
| 4868 | ], |
| 4869 | } |
| 4870 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4871 | cc_test { |
| 4872 | name: "mytests", |
| 4873 | gtest: false, |
| 4874 | srcs: [ |
| 4875 | "mytest1.cpp", |
| 4876 | "mytest2.cpp", |
| 4877 | "mytest3.cpp", |
| 4878 | ], |
| 4879 | test_per_src: true, |
| 4880 | relative_install_path: "test", |
| 4881 | system_shared_libs: [], |
| 4882 | static_executable: true, |
| 4883 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4884 | data: [ |
| 4885 | ":fg", |
| 4886 | ":fg2", |
| 4887 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4888 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4889 | `) |
| 4890 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4891 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4892 | copyCmds := apexRule.Args["copy_commands"] |
| 4893 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4894 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4895 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4896 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4897 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4898 | //Ensure that test data are copied into apex. |
| 4899 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 4900 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 4901 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4902 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 4903 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 4904 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 4905 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4906 | |
| 4907 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4908 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4909 | data := android.AndroidMkDataForTest(t, ctx, bundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4910 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4911 | prefix := "TARGET_" |
| 4912 | var builder strings.Builder |
| 4913 | data.Custom(&builder, name, prefix, "", data) |
| 4914 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4915 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 4916 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 4917 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 4918 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4919 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4920 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4921 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4922 | |
| 4923 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4924 | data = android.AndroidMkDataForTest(t, ctx, flatBundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4925 | data.Custom(&builder, name, prefix, "", data) |
| 4926 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4927 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 4928 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4929 | } |
| 4930 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4931 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4932 | ctx := testApex(t, ` |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4933 | apex { |
| 4934 | name: "myapex", |
| 4935 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4936 | updatable: false, |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4937 | } |
| 4938 | apex_key { |
| 4939 | name: "myapex.key", |
| 4940 | public_key: "testkey.avbpubkey", |
| 4941 | private_key: "testkey.pem", |
| 4942 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 4943 | `, |
| 4944 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4945 | variables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 4946 | }), |
| 4947 | ) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4948 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 4949 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4950 | mk := android.AndroidMkDataForTest(t, ctx, ab) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4951 | var builder strings.Builder |
| 4952 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 4953 | androidMk := builder.String() |
| 4954 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 4955 | } |
| 4956 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4957 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 4958 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 4959 | apex { |
| 4960 | name: "myapex", |
| 4961 | key: "myapex.key", |
| 4962 | native_shared_libs: ["libfoo"], |
| 4963 | } |
| 4964 | |
| 4965 | apex_key { |
| 4966 | name: "myapex.key", |
| 4967 | public_key: "testkey.avbpubkey", |
| 4968 | private_key: "testkey.pem", |
| 4969 | } |
| 4970 | |
| 4971 | cc_library { |
| 4972 | name: "libfoo", |
| 4973 | stl: "none", |
| 4974 | system_shared_libs: [], |
| 4975 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4976 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4977 | } |
| 4978 | `) |
| 4979 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 4980 | apex { |
| 4981 | name: "myapex", |
| 4982 | key: "myapex.key", |
| 4983 | java_libs: ["myjar"], |
| 4984 | } |
| 4985 | |
| 4986 | apex_key { |
| 4987 | name: "myapex.key", |
| 4988 | public_key: "testkey.avbpubkey", |
| 4989 | private_key: "testkey.pem", |
| 4990 | } |
| 4991 | |
| 4992 | java_library { |
| 4993 | name: "myjar", |
| 4994 | srcs: ["foo/bar/MyClass.java"], |
| 4995 | sdk_version: "none", |
| 4996 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4997 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4998 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4999 | } |
| 5000 | `) |
| 5001 | } |
| 5002 | |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5003 | func TestApexWithJavaImport(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5004 | ctx := testApex(t, ` |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5005 | apex { |
| 5006 | name: "myapex", |
| 5007 | key: "myapex.key", |
| 5008 | java_libs: ["myjavaimport"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5009 | updatable: false, |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | apex_key { |
| 5013 | name: "myapex.key", |
| 5014 | public_key: "testkey.avbpubkey", |
| 5015 | private_key: "testkey.pem", |
| 5016 | } |
| 5017 | |
| 5018 | java_import { |
| 5019 | name: "myjavaimport", |
| 5020 | apex_available: ["myapex"], |
| 5021 | jars: ["my.jar"], |
| 5022 | compile_dex: true, |
| 5023 | } |
| 5024 | `) |
| 5025 | |
| 5026 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5027 | apexRule := module.Rule("apexRule") |
| 5028 | copyCmds := apexRule.Args["copy_commands"] |
| 5029 | ensureContains(t, copyCmds, "image.apex/javalib/myjavaimport.jar") |
| 5030 | } |
| 5031 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5032 | func TestApexWithApps(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5033 | ctx := testApex(t, ` |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5034 | apex { |
| 5035 | name: "myapex", |
| 5036 | key: "myapex.key", |
| 5037 | apps: [ |
| 5038 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5039 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5040 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5041 | updatable: false, |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | apex_key { |
| 5045 | name: "myapex.key", |
| 5046 | public_key: "testkey.avbpubkey", |
| 5047 | private_key: "testkey.pem", |
| 5048 | } |
| 5049 | |
| 5050 | android_app { |
| 5051 | name: "AppFoo", |
| 5052 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5053 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5054 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5055 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5056 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5057 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5058 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5059 | |
| 5060 | android_app { |
| 5061 | name: "AppFooPriv", |
| 5062 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5063 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5064 | system_modules: "none", |
| 5065 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5066 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5067 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5068 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5069 | |
| 5070 | cc_library_shared { |
| 5071 | name: "libjni", |
| 5072 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5073 | shared_libs: ["libfoo"], |
| 5074 | stl: "none", |
| 5075 | system_shared_libs: [], |
| 5076 | apex_available: [ "myapex" ], |
| 5077 | sdk_version: "current", |
| 5078 | } |
| 5079 | |
| 5080 | cc_library_shared { |
| 5081 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5082 | stl: "none", |
| 5083 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 5084 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5085 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5086 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5087 | `) |
| 5088 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5089 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5090 | apexRule := module.Rule("apexRule") |
| 5091 | copyCmds := apexRule.Args["copy_commands"] |
| 5092 | |
| 5093 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5094 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5095 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5096 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5097 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5098 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5099 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5100 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5101 | // JNI libraries including transitive deps are |
| 5102 | for _, jni := range []string{"libjni", "libfoo"} { |
Paul Duffin | afdd406 | 2021-03-30 19:44:07 +0100 | [diff] [blame] | 5103 | 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] | 5104 | // ... embedded inside APK (jnilibs.zip) |
| 5105 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 5106 | // ... and not directly inside the APEX |
| 5107 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 5108 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5109 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5110 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5111 | func TestApexWithAppImports(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5112 | ctx := testApex(t, ` |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5113 | apex { |
| 5114 | name: "myapex", |
| 5115 | key: "myapex.key", |
| 5116 | apps: [ |
| 5117 | "AppFooPrebuilt", |
| 5118 | "AppFooPrivPrebuilt", |
| 5119 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5120 | updatable: false, |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | apex_key { |
| 5124 | name: "myapex.key", |
| 5125 | public_key: "testkey.avbpubkey", |
| 5126 | private_key: "testkey.pem", |
| 5127 | } |
| 5128 | |
| 5129 | android_app_import { |
| 5130 | name: "AppFooPrebuilt", |
| 5131 | apk: "PrebuiltAppFoo.apk", |
| 5132 | presigned: true, |
| 5133 | dex_preopt: { |
| 5134 | enabled: false, |
| 5135 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5136 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5137 | } |
| 5138 | |
| 5139 | android_app_import { |
| 5140 | name: "AppFooPrivPrebuilt", |
| 5141 | apk: "PrebuiltAppFooPriv.apk", |
| 5142 | privileged: true, |
| 5143 | presigned: true, |
| 5144 | dex_preopt: { |
| 5145 | enabled: false, |
| 5146 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5147 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5148 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5149 | } |
| 5150 | `) |
| 5151 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5152 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5153 | apexRule := module.Rule("apexRule") |
| 5154 | copyCmds := apexRule.Args["copy_commands"] |
| 5155 | |
| 5156 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5157 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 5158 | } |
| 5159 | |
| 5160 | func TestApexWithAppImportsPrefer(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5161 | ctx := testApex(t, ` |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5162 | apex { |
| 5163 | name: "myapex", |
| 5164 | key: "myapex.key", |
| 5165 | apps: [ |
| 5166 | "AppFoo", |
| 5167 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5168 | updatable: false, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5169 | } |
| 5170 | |
| 5171 | apex_key { |
| 5172 | name: "myapex.key", |
| 5173 | public_key: "testkey.avbpubkey", |
| 5174 | private_key: "testkey.pem", |
| 5175 | } |
| 5176 | |
| 5177 | android_app { |
| 5178 | name: "AppFoo", |
| 5179 | srcs: ["foo/bar/MyClass.java"], |
| 5180 | sdk_version: "none", |
| 5181 | system_modules: "none", |
| 5182 | apex_available: [ "myapex" ], |
| 5183 | } |
| 5184 | |
| 5185 | android_app_import { |
| 5186 | name: "AppFoo", |
| 5187 | apk: "AppFooPrebuilt.apk", |
| 5188 | filename: "AppFooPrebuilt.apk", |
| 5189 | presigned: true, |
| 5190 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5191 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5192 | } |
| 5193 | `, withFiles(map[string][]byte{ |
| 5194 | "AppFooPrebuilt.apk": nil, |
| 5195 | })) |
| 5196 | |
| 5197 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 86feead | 2021-03-08 13:11:48 +0900 | [diff] [blame] | 5198 | "app/AppFoo/AppFooPrebuilt.apk", |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5199 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5200 | } |
| 5201 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5202 | func TestApexWithTestHelperApp(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5203 | ctx := testApex(t, ` |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5204 | apex { |
| 5205 | name: "myapex", |
| 5206 | key: "myapex.key", |
| 5207 | apps: [ |
| 5208 | "TesterHelpAppFoo", |
| 5209 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5210 | updatable: false, |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | apex_key { |
| 5214 | name: "myapex.key", |
| 5215 | public_key: "testkey.avbpubkey", |
| 5216 | private_key: "testkey.pem", |
| 5217 | } |
| 5218 | |
| 5219 | android_test_helper_app { |
| 5220 | name: "TesterHelpAppFoo", |
| 5221 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5222 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5223 | } |
| 5224 | |
| 5225 | `) |
| 5226 | |
| 5227 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5228 | apexRule := module.Rule("apexRule") |
| 5229 | copyCmds := apexRule.Args["copy_commands"] |
| 5230 | |
| 5231 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 5232 | } |
| 5233 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5234 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 5235 | // libfoo's apex_available comes from cc_defaults |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5236 | 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] | 5237 | apex { |
| 5238 | name: "myapex", |
| 5239 | key: "myapex.key", |
| 5240 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5241 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | apex_key { |
| 5245 | name: "myapex.key", |
| 5246 | public_key: "testkey.avbpubkey", |
| 5247 | private_key: "testkey.pem", |
| 5248 | } |
| 5249 | |
| 5250 | apex { |
| 5251 | name: "otherapex", |
| 5252 | key: "myapex.key", |
| 5253 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5254 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | cc_defaults { |
| 5258 | name: "libfoo-defaults", |
| 5259 | apex_available: ["otherapex"], |
| 5260 | } |
| 5261 | |
| 5262 | cc_library { |
| 5263 | name: "libfoo", |
| 5264 | defaults: ["libfoo-defaults"], |
| 5265 | stl: "none", |
| 5266 | system_shared_libs: [], |
| 5267 | }`) |
| 5268 | } |
| 5269 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5270 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5271 | // libfoo is not available to myapex, but only to otherapex |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5272 | 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] | 5273 | apex { |
| 5274 | name: "myapex", |
| 5275 | key: "myapex.key", |
| 5276 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5277 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5278 | } |
| 5279 | |
| 5280 | apex_key { |
| 5281 | name: "myapex.key", |
| 5282 | public_key: "testkey.avbpubkey", |
| 5283 | private_key: "testkey.pem", |
| 5284 | } |
| 5285 | |
| 5286 | apex { |
| 5287 | name: "otherapex", |
| 5288 | key: "otherapex.key", |
| 5289 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5290 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | apex_key { |
| 5294 | name: "otherapex.key", |
| 5295 | public_key: "testkey.avbpubkey", |
| 5296 | private_key: "testkey.pem", |
| 5297 | } |
| 5298 | |
| 5299 | cc_library { |
| 5300 | name: "libfoo", |
| 5301 | stl: "none", |
| 5302 | system_shared_libs: [], |
| 5303 | apex_available: ["otherapex"], |
| 5304 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5305 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5306 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5307 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5308 | // libbbaz is an indirect dep |
Jiyong Park | 767dbd9 | 2021-03-04 13:03:10 +0900 | [diff] [blame] | 5309 | 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] | 5310 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5311 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5312 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5313 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5314 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 5315 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5316 | apex { |
| 5317 | name: "myapex", |
| 5318 | key: "myapex.key", |
| 5319 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5320 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | apex_key { |
| 5324 | name: "myapex.key", |
| 5325 | public_key: "testkey.avbpubkey", |
| 5326 | private_key: "testkey.pem", |
| 5327 | } |
| 5328 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5329 | cc_library { |
| 5330 | name: "libfoo", |
| 5331 | stl: "none", |
| 5332 | shared_libs: ["libbar"], |
| 5333 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5334 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | cc_library { |
| 5338 | name: "libbar", |
| 5339 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5340 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5341 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5342 | apex_available: ["myapex"], |
| 5343 | } |
| 5344 | |
| 5345 | cc_library { |
| 5346 | name: "libbaz", |
| 5347 | stl: "none", |
| 5348 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5349 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5350 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5351 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5352 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5353 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 5354 | apex { |
| 5355 | name: "myapex", |
| 5356 | key: "myapex.key", |
| 5357 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5358 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | apex_key { |
| 5362 | name: "myapex.key", |
| 5363 | public_key: "testkey.avbpubkey", |
| 5364 | private_key: "testkey.pem", |
| 5365 | } |
| 5366 | |
| 5367 | cc_library { |
| 5368 | name: "libfoo", |
| 5369 | stl: "none", |
| 5370 | system_shared_libs: [], |
| 5371 | apex_available: ["otherapex"], |
| 5372 | }`) |
| 5373 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5374 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5375 | apex { |
| 5376 | name: "myapex", |
| 5377 | key: "myapex.key", |
| 5378 | native_shared_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5379 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | apex_key { |
| 5383 | name: "myapex.key", |
| 5384 | public_key: "testkey.avbpubkey", |
| 5385 | private_key: "testkey.pem", |
| 5386 | } |
| 5387 | |
| 5388 | cc_library { |
| 5389 | name: "libfoo", |
| 5390 | stl: "none", |
| 5391 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5392 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5393 | apex_available: ["myapex"], |
| 5394 | } |
| 5395 | |
| 5396 | cc_library { |
| 5397 | name: "libbar", |
| 5398 | stl: "none", |
| 5399 | system_shared_libs: [], |
| 5400 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | cc_library { |
| 5404 | name: "libbaz", |
| 5405 | stl: "none", |
| 5406 | system_shared_libs: [], |
| 5407 | stubs: { |
| 5408 | versions: ["10", "20", "30"], |
| 5409 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5410 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5411 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5412 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5413 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5414 | ctx := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5415 | apex { |
| 5416 | name: "myapex", |
| 5417 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5418 | native_shared_libs: ["libbar", "libbaz"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5419 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | apex_key { |
| 5423 | name: "myapex.key", |
| 5424 | public_key: "testkey.avbpubkey", |
| 5425 | private_key: "testkey.pem", |
| 5426 | } |
| 5427 | |
| 5428 | cc_library { |
| 5429 | name: "libfoo", |
| 5430 | stl: "none", |
| 5431 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5432 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5433 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5434 | } |
| 5435 | |
| 5436 | cc_library { |
| 5437 | name: "libfoo2", |
| 5438 | stl: "none", |
| 5439 | system_shared_libs: [], |
| 5440 | shared_libs: ["libbaz"], |
| 5441 | apex_available: ["//apex_available:platform"], |
| 5442 | } |
| 5443 | |
| 5444 | cc_library { |
| 5445 | name: "libbar", |
| 5446 | stl: "none", |
| 5447 | system_shared_libs: [], |
| 5448 | apex_available: ["myapex"], |
| 5449 | } |
| 5450 | |
| 5451 | cc_library { |
| 5452 | name: "libbaz", |
| 5453 | stl: "none", |
| 5454 | system_shared_libs: [], |
| 5455 | apex_available: ["myapex"], |
| 5456 | stubs: { |
| 5457 | versions: ["1"], |
| 5458 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5459 | }`) |
| 5460 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5461 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 5462 | // because it depends on libbar which isn't available to platform |
| 5463 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5464 | if libfoo.NotAvailableForPlatform() != true { |
| 5465 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 5466 | } |
| 5467 | |
| 5468 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 5469 | // stubs |
| 5470 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5471 | if libfoo2.NotAvailableForPlatform() == true { |
| 5472 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 5473 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5474 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5475 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5476 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5477 | ctx := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5478 | apex { |
| 5479 | name: "myapex", |
| 5480 | key: "myapex.key", |
| 5481 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5482 | updatable: false, |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5483 | } |
| 5484 | |
| 5485 | apex_key { |
| 5486 | name: "myapex.key", |
| 5487 | public_key: "testkey.avbpubkey", |
| 5488 | private_key: "testkey.pem", |
| 5489 | } |
| 5490 | |
| 5491 | cc_library { |
| 5492 | name: "libfoo", |
| 5493 | stl: "none", |
| 5494 | system_shared_libs: [], |
| 5495 | apex_available: ["myapex"], |
| 5496 | static: { |
| 5497 | apex_available: ["//apex_available:platform"], |
| 5498 | }, |
| 5499 | }`) |
| 5500 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5501 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5502 | if libfooShared.NotAvailableForPlatform() != true { |
| 5503 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 5504 | } |
| 5505 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 5506 | if libfooStatic.NotAvailableForPlatform() != false { |
| 5507 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 5508 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5509 | } |
| 5510 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5511 | func TestOverrideApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5512 | ctx := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5513 | apex { |
| 5514 | name: "myapex", |
| 5515 | key: "myapex.key", |
| 5516 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5517 | overrides: ["oldapex"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5518 | updatable: false, |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | override_apex { |
| 5522 | name: "override_myapex", |
| 5523 | base: "myapex", |
| 5524 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5525 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5526 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5527 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5528 | } |
| 5529 | |
| 5530 | apex_key { |
| 5531 | name: "myapex.key", |
| 5532 | public_key: "testkey.avbpubkey", |
| 5533 | private_key: "testkey.pem", |
| 5534 | } |
| 5535 | |
| 5536 | android_app { |
| 5537 | name: "app", |
| 5538 | srcs: ["foo/bar/MyClass.java"], |
| 5539 | package_name: "foo", |
| 5540 | sdk_version: "none", |
| 5541 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5542 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5543 | } |
| 5544 | |
| 5545 | override_android_app { |
| 5546 | name: "override_app", |
| 5547 | base: "app", |
| 5548 | package_name: "bar", |
| 5549 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5550 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5551 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 5552 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 5553 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 5554 | if originalVariant.GetOverriddenBy() != "" { |
| 5555 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 5556 | } |
| 5557 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 5558 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 5559 | } |
| 5560 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5561 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 5562 | apexRule := module.Rule("apexRule") |
| 5563 | copyCmds := apexRule.Args["copy_commands"] |
| 5564 | |
| 5565 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5566 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5567 | |
| 5568 | apexBundle := module.Module().(*apexBundle) |
| 5569 | name := apexBundle.Name() |
| 5570 | if name != "override_myapex" { |
| 5571 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 5572 | } |
| 5573 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5574 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 5575 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 5576 | } |
| 5577 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5578 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5579 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5580 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5581 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5582 | var builder strings.Builder |
| 5583 | data.Custom(&builder, name, "TARGET_", "", data) |
| 5584 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5585 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5586 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 5587 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5588 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5589 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5590 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5591 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 5592 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5593 | } |
| 5594 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5595 | func TestLegacyAndroid10Support(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5596 | ctx := testApex(t, ` |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5597 | apex { |
| 5598 | name: "myapex", |
| 5599 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5600 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 5601 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | apex_key { |
| 5605 | name: "myapex.key", |
| 5606 | public_key: "testkey.avbpubkey", |
| 5607 | private_key: "testkey.pem", |
| 5608 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5609 | |
| 5610 | cc_library { |
| 5611 | name: "mylib", |
| 5612 | srcs: ["mylib.cpp"], |
| 5613 | stl: "libc++", |
| 5614 | system_shared_libs: [], |
| 5615 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5616 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5617 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5618 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5619 | |
| 5620 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5621 | args := module.Rule("apexRule").Args |
| 5622 | 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] | 5623 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5624 | |
| 5625 | // The copies of the libraries in the apex should have one more dependency than |
| 5626 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 5627 | // the dependency names directly here but for some reason the names are blank in |
| 5628 | // this test. |
| 5629 | for _, lib := range []string{"libc++", "mylib"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5630 | 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] | 5631 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 5632 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 5633 | t.Errorf("%q missing unwinder dep", lib) |
| 5634 | } |
| 5635 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5636 | } |
| 5637 | |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 5638 | var filesForSdkLibrary = android.MockFS{ |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5639 | "api/current.txt": nil, |
| 5640 | "api/removed.txt": nil, |
| 5641 | "api/system-current.txt": nil, |
| 5642 | "api/system-removed.txt": nil, |
| 5643 | "api/test-current.txt": nil, |
| 5644 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5645 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5646 | "100/public/api/foo.txt": nil, |
| 5647 | "100/public/api/foo-removed.txt": nil, |
| 5648 | "100/system/api/foo.txt": nil, |
| 5649 | "100/system/api/foo-removed.txt": nil, |
| 5650 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5651 | // For java_sdk_library_import |
| 5652 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5653 | } |
| 5654 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5655 | func TestJavaSDKLibrary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5656 | ctx := testApex(t, ` |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5657 | apex { |
| 5658 | name: "myapex", |
| 5659 | key: "myapex.key", |
| 5660 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5661 | updatable: false, |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5662 | } |
| 5663 | |
| 5664 | apex_key { |
| 5665 | name: "myapex.key", |
| 5666 | public_key: "testkey.avbpubkey", |
| 5667 | private_key: "testkey.pem", |
| 5668 | } |
| 5669 | |
| 5670 | java_sdk_library { |
| 5671 | name: "foo", |
| 5672 | srcs: ["a.java"], |
| 5673 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5674 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5675 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5676 | |
| 5677 | prebuilt_apis { |
| 5678 | name: "sdk", |
| 5679 | api_dirs: ["100"], |
| 5680 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5681 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5682 | |
| 5683 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5684 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5685 | "javalib/foo.jar", |
| 5686 | "etc/permissions/foo.xml", |
| 5687 | }) |
| 5688 | // 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] | 5689 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 5690 | 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] | 5691 | } |
| 5692 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5693 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5694 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5695 | apex { |
| 5696 | name: "myapex", |
| 5697 | key: "myapex.key", |
| 5698 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5699 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5700 | } |
| 5701 | |
| 5702 | apex_key { |
| 5703 | name: "myapex.key", |
| 5704 | public_key: "testkey.avbpubkey", |
| 5705 | private_key: "testkey.pem", |
| 5706 | } |
| 5707 | |
| 5708 | java_sdk_library { |
| 5709 | name: "foo", |
| 5710 | srcs: ["a.java"], |
| 5711 | api_packages: ["foo"], |
| 5712 | apex_available: ["myapex"], |
| 5713 | sdk_version: "none", |
| 5714 | system_modules: "none", |
| 5715 | } |
| 5716 | |
| 5717 | java_library { |
| 5718 | name: "bar", |
| 5719 | srcs: ["a.java"], |
| 5720 | libs: ["foo"], |
| 5721 | apex_available: ["myapex"], |
| 5722 | sdk_version: "none", |
| 5723 | system_modules: "none", |
| 5724 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5725 | |
| 5726 | prebuilt_apis { |
| 5727 | name: "sdk", |
| 5728 | api_dirs: ["100"], |
| 5729 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5730 | `, withFiles(filesForSdkLibrary)) |
| 5731 | |
| 5732 | // java_sdk_library installs both impl jar and permission XML |
| 5733 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5734 | "javalib/bar.jar", |
| 5735 | "javalib/foo.jar", |
| 5736 | "etc/permissions/foo.xml", |
| 5737 | }) |
| 5738 | |
| 5739 | // The bar library should depend on the implementation jar. |
| 5740 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 5741 | 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] | 5742 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5743 | } |
| 5744 | } |
| 5745 | |
| 5746 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5747 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5748 | apex { |
| 5749 | name: "myapex", |
| 5750 | key: "myapex.key", |
| 5751 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5752 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5753 | } |
| 5754 | |
| 5755 | apex_key { |
| 5756 | name: "myapex.key", |
| 5757 | public_key: "testkey.avbpubkey", |
| 5758 | private_key: "testkey.pem", |
| 5759 | } |
| 5760 | |
| 5761 | java_sdk_library { |
| 5762 | name: "foo", |
| 5763 | srcs: ["a.java"], |
| 5764 | api_packages: ["foo"], |
| 5765 | apex_available: ["myapex"], |
| 5766 | sdk_version: "none", |
| 5767 | system_modules: "none", |
| 5768 | } |
| 5769 | |
| 5770 | java_library { |
| 5771 | name: "bar", |
| 5772 | srcs: ["a.java"], |
| 5773 | libs: ["foo"], |
| 5774 | sdk_version: "none", |
| 5775 | system_modules: "none", |
| 5776 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5777 | |
| 5778 | prebuilt_apis { |
| 5779 | name: "sdk", |
| 5780 | api_dirs: ["100"], |
| 5781 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5782 | `, withFiles(filesForSdkLibrary)) |
| 5783 | |
| 5784 | // java_sdk_library installs both impl jar and permission XML |
| 5785 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5786 | "javalib/foo.jar", |
| 5787 | "etc/permissions/foo.xml", |
| 5788 | }) |
| 5789 | |
| 5790 | // The bar library should depend on the stubs jar. |
| 5791 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 5792 | 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] | 5793 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5794 | } |
| 5795 | } |
| 5796 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5797 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5798 | ctx := testApex(t, ` |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5799 | prebuilt_apis { |
| 5800 | name: "sdk", |
| 5801 | api_dirs: ["100"], |
| 5802 | }`, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5803 | withFiles(map[string][]byte{ |
| 5804 | "apex/a.java": nil, |
| 5805 | "apex/apex_manifest.json": nil, |
| 5806 | "apex/Android.bp": []byte(` |
| 5807 | package { |
| 5808 | default_visibility: ["//visibility:private"], |
| 5809 | } |
| 5810 | |
| 5811 | apex { |
| 5812 | name: "myapex", |
| 5813 | key: "myapex.key", |
| 5814 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5815 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | apex_key { |
| 5819 | name: "myapex.key", |
| 5820 | public_key: "testkey.avbpubkey", |
| 5821 | private_key: "testkey.pem", |
| 5822 | } |
| 5823 | |
| 5824 | java_library { |
| 5825 | name: "bar", |
| 5826 | srcs: ["a.java"], |
| 5827 | libs: ["foo"], |
| 5828 | apex_available: ["myapex"], |
| 5829 | sdk_version: "none", |
| 5830 | system_modules: "none", |
| 5831 | } |
| 5832 | `), |
| 5833 | "source/a.java": nil, |
| 5834 | "source/api/current.txt": nil, |
| 5835 | "source/api/removed.txt": nil, |
| 5836 | "source/Android.bp": []byte(` |
| 5837 | package { |
| 5838 | default_visibility: ["//visibility:private"], |
| 5839 | } |
| 5840 | |
| 5841 | java_sdk_library { |
| 5842 | name: "foo", |
| 5843 | visibility: ["//apex"], |
| 5844 | srcs: ["a.java"], |
| 5845 | api_packages: ["foo"], |
| 5846 | apex_available: ["myapex"], |
| 5847 | sdk_version: "none", |
| 5848 | system_modules: "none", |
| 5849 | public: { |
| 5850 | enabled: true, |
| 5851 | }, |
| 5852 | } |
| 5853 | `), |
| 5854 | "prebuilt/a.jar": nil, |
| 5855 | "prebuilt/Android.bp": []byte(` |
| 5856 | package { |
| 5857 | default_visibility: ["//visibility:private"], |
| 5858 | } |
| 5859 | |
| 5860 | java_sdk_library_import { |
| 5861 | name: "foo", |
| 5862 | visibility: ["//apex", "//source"], |
| 5863 | apex_available: ["myapex"], |
| 5864 | prefer: true, |
| 5865 | public: { |
| 5866 | jars: ["a.jar"], |
| 5867 | }, |
| 5868 | } |
| 5869 | `), |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5870 | }), withFiles(filesForSdkLibrary), |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5871 | ) |
| 5872 | |
| 5873 | // java_sdk_library installs both impl jar and permission XML |
| 5874 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5875 | "javalib/bar.jar", |
| 5876 | "javalib/foo.jar", |
| 5877 | "etc/permissions/foo.xml", |
| 5878 | }) |
| 5879 | |
| 5880 | // The bar library should depend on the implementation jar. |
| 5881 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 5882 | 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] | 5883 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5884 | } |
| 5885 | } |
| 5886 | |
| 5887 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 5888 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 5889 | apex { |
| 5890 | name: "myapex", |
| 5891 | key: "myapex.key", |
| 5892 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5893 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | apex_key { |
| 5897 | name: "myapex.key", |
| 5898 | public_key: "testkey.avbpubkey", |
| 5899 | private_key: "testkey.pem", |
| 5900 | } |
| 5901 | |
| 5902 | java_sdk_library_import { |
| 5903 | name: "foo", |
| 5904 | apex_available: ["myapex"], |
| 5905 | prefer: true, |
| 5906 | public: { |
| 5907 | jars: ["a.jar"], |
| 5908 | }, |
| 5909 | } |
| 5910 | |
| 5911 | `, withFiles(filesForSdkLibrary)) |
| 5912 | } |
| 5913 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5914 | func TestCompatConfig(t *testing.T) { |
Paul Duffin | a369c7b | 2021-03-09 03:08:05 +0000 | [diff] [blame] | 5915 | result := apexFixtureFactory. |
| 5916 | Extend(java.PrepareForTestWithPlatformCompatConfig). |
| 5917 | RunTestWithBp(t, ` |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5918 | apex { |
| 5919 | name: "myapex", |
| 5920 | key: "myapex.key", |
Paul Duffin | 3abc174 | 2021-03-15 19:32:23 +0000 | [diff] [blame] | 5921 | compat_configs: ["myjar-platform-compat-config"], |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5922 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5923 | updatable: false, |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | apex_key { |
| 5927 | name: "myapex.key", |
| 5928 | public_key: "testkey.avbpubkey", |
| 5929 | private_key: "testkey.pem", |
| 5930 | } |
| 5931 | |
| 5932 | platform_compat_config { |
| 5933 | name: "myjar-platform-compat-config", |
| 5934 | src: ":myjar", |
| 5935 | } |
| 5936 | |
| 5937 | java_library { |
| 5938 | name: "myjar", |
| 5939 | srcs: ["foo/bar/MyClass.java"], |
| 5940 | sdk_version: "none", |
| 5941 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5942 | apex_available: [ "myapex" ], |
| 5943 | } |
Paul Duffin | 1b29e00 | 2021-03-16 15:06:54 +0000 | [diff] [blame] | 5944 | |
| 5945 | // Make sure that a preferred prebuilt does not affect the apex contents. |
| 5946 | prebuilt_platform_compat_config { |
| 5947 | name: "myjar-platform-compat-config", |
| 5948 | metadata: "compat-config/metadata.xml", |
| 5949 | prefer: true, |
| 5950 | } |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5951 | `) |
Paul Duffin | a369c7b | 2021-03-09 03:08:05 +0000 | [diff] [blame] | 5952 | ctx := result.TestContext |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5953 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5954 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 5955 | "javalib/myjar.jar", |
| 5956 | }) |
| 5957 | } |
| 5958 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5959 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 5960 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 5961 | apex { |
| 5962 | name: "myapex", |
| 5963 | key: "myapex.key", |
| 5964 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5965 | updatable: false, |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | apex_key { |
| 5969 | name: "myapex.key", |
| 5970 | public_key: "testkey.avbpubkey", |
| 5971 | private_key: "testkey.pem", |
| 5972 | } |
| 5973 | |
| 5974 | java_library { |
| 5975 | name: "myjar", |
| 5976 | srcs: ["foo/bar/MyClass.java"], |
| 5977 | sdk_version: "none", |
| 5978 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 5979 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5980 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5981 | } |
| 5982 | `) |
| 5983 | } |
| 5984 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5985 | func TestCarryRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5986 | ctx := testApex(t, ` |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5987 | apex { |
| 5988 | name: "myapex", |
| 5989 | key: "myapex.key", |
| 5990 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5991 | updatable: false, |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5992 | } |
| 5993 | |
| 5994 | apex_key { |
| 5995 | name: "myapex.key", |
| 5996 | public_key: "testkey.avbpubkey", |
| 5997 | private_key: "testkey.pem", |
| 5998 | } |
| 5999 | |
| 6000 | cc_library { |
| 6001 | name: "mylib", |
| 6002 | srcs: ["mylib.cpp"], |
| 6003 | system_shared_libs: [], |
| 6004 | stl: "none", |
| 6005 | required: ["a", "b"], |
| 6006 | host_required: ["c", "d"], |
| 6007 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6008 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6009 | } |
| 6010 | `) |
| 6011 | |
| 6012 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6013 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6014 | name := apexBundle.BaseModuleName() |
| 6015 | prefix := "TARGET_" |
| 6016 | var builder strings.Builder |
| 6017 | data.Custom(&builder, name, prefix, "", data) |
| 6018 | androidMk := builder.String() |
| 6019 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 6020 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 6021 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 6022 | } |
| 6023 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6024 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 6025 | bp := ` |
| 6026 | apex { |
| 6027 | name: "myapex", |
| 6028 | key: "myapex.key", |
| 6029 | native_shared_libs: ["mylib"], |
| 6030 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6031 | updatable: false, |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6032 | } |
| 6033 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6034 | apex { |
| 6035 | name: "myapex.updatable", |
| 6036 | key: "myapex.key", |
| 6037 | native_shared_libs: ["mylib"], |
| 6038 | java_libs: ["myjar"], |
| 6039 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6040 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6041 | } |
| 6042 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6043 | apex_key { |
| 6044 | name: "myapex.key", |
| 6045 | public_key: "testkey.avbpubkey", |
| 6046 | private_key: "testkey.pem", |
| 6047 | } |
| 6048 | |
| 6049 | cc_library { |
| 6050 | name: "mylib", |
| 6051 | srcs: ["mylib.cpp"], |
| 6052 | shared_libs: ["myotherlib"], |
| 6053 | system_shared_libs: [], |
| 6054 | stl: "none", |
| 6055 | apex_available: [ |
| 6056 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6057 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6058 | "//apex_available:platform", |
| 6059 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6060 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | cc_library { |
| 6064 | name: "myotherlib", |
| 6065 | srcs: ["mylib.cpp"], |
| 6066 | system_shared_libs: [], |
| 6067 | stl: "none", |
| 6068 | apex_available: [ |
| 6069 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6070 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6071 | "//apex_available:platform", |
| 6072 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6073 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6074 | } |
| 6075 | |
| 6076 | java_library { |
| 6077 | name: "myjar", |
| 6078 | srcs: ["foo/bar/MyClass.java"], |
| 6079 | sdk_version: "none", |
| 6080 | system_modules: "none", |
| 6081 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6082 | apex_available: [ |
| 6083 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6084 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6085 | "//apex_available:platform", |
| 6086 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6087 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6088 | } |
| 6089 | |
| 6090 | java_library { |
| 6091 | name: "myotherjar", |
| 6092 | srcs: ["foo/bar/MyClass.java"], |
| 6093 | sdk_version: "none", |
| 6094 | system_modules: "none", |
| 6095 | apex_available: [ |
| 6096 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6097 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6098 | "//apex_available:platform", |
| 6099 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6100 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6101 | } |
| 6102 | ` |
| 6103 | |
| 6104 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 6105 | for _, f := range files { |
| 6106 | if f.path == file { |
| 6107 | if f.isLink { |
| 6108 | t.Errorf("%q is not a real file", file) |
| 6109 | } |
| 6110 | return |
| 6111 | } |
| 6112 | } |
| 6113 | t.Errorf("%q is not found", file) |
| 6114 | } |
| 6115 | |
| 6116 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 6117 | for _, f := range files { |
| 6118 | if f.path == file { |
| 6119 | if !f.isLink { |
| 6120 | t.Errorf("%q is not a symlink", file) |
| 6121 | } |
| 6122 | return |
| 6123 | } |
| 6124 | } |
| 6125 | t.Errorf("%q is not found", file) |
| 6126 | } |
| 6127 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6128 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 6129 | // is updatable or not |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6130 | ctx := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6131 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6132 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6133 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6134 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6135 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6136 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6137 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6138 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6139 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6140 | |
| 6141 | // 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] | 6142 | ctx = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6143 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6144 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6145 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6146 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6147 | |
| 6148 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6149 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6150 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6151 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6152 | } |
| 6153 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6154 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6155 | ctx := testApex(t, ` |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6156 | apex { |
| 6157 | name: "myapex", |
| 6158 | key: "myapex.key", |
| 6159 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6160 | updatable: false, |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6161 | } |
| 6162 | |
| 6163 | apex_key { |
| 6164 | name: "myapex.key", |
| 6165 | public_key: "testkey.avbpubkey", |
| 6166 | private_key: "testkey.pem", |
| 6167 | } |
| 6168 | |
| 6169 | cc_library_shared { |
| 6170 | name: "mylib", |
| 6171 | srcs: ["mylib.cpp"], |
| 6172 | shared_libs: ["myotherlib"], |
| 6173 | system_shared_libs: [], |
| 6174 | stl: "none", |
| 6175 | apex_available: [ |
| 6176 | "myapex", |
| 6177 | "//apex_available:platform", |
| 6178 | ], |
| 6179 | } |
| 6180 | |
| 6181 | cc_prebuilt_library_shared { |
| 6182 | name: "myotherlib", |
| 6183 | srcs: ["prebuilt.so"], |
| 6184 | system_shared_libs: [], |
| 6185 | stl: "none", |
| 6186 | apex_available: [ |
| 6187 | "myapex", |
| 6188 | "//apex_available:platform", |
| 6189 | ], |
| 6190 | } |
| 6191 | `) |
| 6192 | |
| 6193 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6194 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6195 | var builder strings.Builder |
| 6196 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 6197 | androidMk := builder.String() |
| 6198 | // `myotherlib` is added to `myapex` as symlink |
| 6199 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 6200 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 6201 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 6202 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 6203 | 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] | 6204 | } |
| 6205 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6206 | func TestApexWithJniLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6207 | ctx := testApex(t, ` |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6208 | apex { |
| 6209 | name: "myapex", |
| 6210 | key: "myapex.key", |
| 6211 | jni_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6212 | updatable: false, |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | apex_key { |
| 6216 | name: "myapex.key", |
| 6217 | public_key: "testkey.avbpubkey", |
| 6218 | private_key: "testkey.pem", |
| 6219 | } |
| 6220 | |
| 6221 | cc_library { |
| 6222 | name: "mylib", |
| 6223 | srcs: ["mylib.cpp"], |
| 6224 | shared_libs: ["mylib2"], |
| 6225 | system_shared_libs: [], |
| 6226 | stl: "none", |
| 6227 | apex_available: [ "myapex" ], |
| 6228 | } |
| 6229 | |
| 6230 | cc_library { |
| 6231 | name: "mylib2", |
| 6232 | srcs: ["mylib.cpp"], |
| 6233 | system_shared_libs: [], |
| 6234 | stl: "none", |
| 6235 | apex_available: [ "myapex" ], |
| 6236 | } |
| 6237 | `) |
| 6238 | |
| 6239 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 6240 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 6241 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 6242 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6243 | "lib64/mylib.so", |
| 6244 | "lib64/mylib2.so", |
| 6245 | }) |
| 6246 | } |
| 6247 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6248 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6249 | ctx := testApex(t, ` |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6250 | apex { |
| 6251 | name: "myapex", |
| 6252 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6253 | updatable: false, |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6254 | } |
| 6255 | apex_key { |
| 6256 | name: "myapex.key", |
| 6257 | public_key: "testkey.avbpubkey", |
| 6258 | private_key: "testkey.pem", |
| 6259 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 6260 | `, |
| 6261 | android.FixtureModifyConfig(func(config android.Config) { |
| 6262 | delete(config.Targets, android.Android) |
| 6263 | config.AndroidCommonTarget = android.Target{} |
| 6264 | }), |
| 6265 | ) |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6266 | |
| 6267 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 6268 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 6269 | } |
| 6270 | } |
| 6271 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6272 | func TestAppBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6273 | ctx := testApex(t, ` |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6274 | apex { |
| 6275 | name: "myapex", |
| 6276 | key: "myapex.key", |
| 6277 | apps: ["AppFoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6278 | updatable: false, |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6279 | } |
| 6280 | |
| 6281 | apex_key { |
| 6282 | name: "myapex.key", |
| 6283 | public_key: "testkey.avbpubkey", |
| 6284 | private_key: "testkey.pem", |
| 6285 | } |
| 6286 | |
| 6287 | android_app { |
| 6288 | name: "AppFoo", |
| 6289 | srcs: ["foo/bar/MyClass.java"], |
| 6290 | sdk_version: "none", |
| 6291 | system_modules: "none", |
| 6292 | apex_available: [ "myapex" ], |
| 6293 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6294 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6295 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6296 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json") |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6297 | content := bundleConfigRule.Args["content"] |
| 6298 | |
| 6299 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6300 | 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] | 6301 | } |
| 6302 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6303 | func TestAppSetBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6304 | ctx := testApex(t, ` |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6305 | apex { |
| 6306 | name: "myapex", |
| 6307 | key: "myapex.key", |
| 6308 | apps: ["AppSet"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6309 | updatable: false, |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6310 | } |
| 6311 | |
| 6312 | apex_key { |
| 6313 | name: "myapex.key", |
| 6314 | public_key: "testkey.avbpubkey", |
| 6315 | private_key: "testkey.pem", |
| 6316 | } |
| 6317 | |
| 6318 | android_app_set { |
| 6319 | name: "AppSet", |
| 6320 | set: "AppSet.apks", |
| 6321 | }`) |
| 6322 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6323 | bundleConfigRule := mod.Output("bundle_config.json") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6324 | content := bundleConfigRule.Args["content"] |
| 6325 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 6326 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 6327 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 6328 | if len(copyCmds) != 3 { |
| 6329 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 6330 | } |
| 6331 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 6332 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 6333 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 6334 | } |
| 6335 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6336 | func TestAppSetBundlePrebuilt(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 6337 | ctx := testApex(t, "", android.FixtureModifyMockFS(func(fs android.MockFS) { |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6338 | bp := ` |
| 6339 | apex_set { |
| 6340 | name: "myapex", |
| 6341 | filename: "foo_v2.apex", |
| 6342 | sanitized: { |
| 6343 | none: { set: "myapex.apks", }, |
| 6344 | hwaddress: { set: "myapex.hwasan.apks", }, |
| 6345 | }, |
| 6346 | }` |
| 6347 | fs["Android.bp"] = []byte(bp) |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 6348 | }), |
| 6349 | prepareForTestWithSantitizeHwaddress, |
| 6350 | ) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6351 | |
| 6352 | m := ctx.ModuleForTests("myapex", "android_common") |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 6353 | extractedApex := m.Output("out/soong/.intermediates/myapex/android_common/foo_v2.apex") |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6354 | |
| 6355 | actual := extractedApex.Inputs |
| 6356 | if len(actual) != 1 { |
| 6357 | t.Errorf("expected a single input") |
| 6358 | } |
| 6359 | |
| 6360 | expected := "myapex.hwasan.apks" |
| 6361 | if actual[0].String() != expected { |
| 6362 | t.Errorf("expected %s, got %s", expected, actual[0].String()) |
| 6363 | } |
| 6364 | } |
| 6365 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6366 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6367 | t.Helper() |
| 6368 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6369 | bp := ` |
| 6370 | java_library { |
| 6371 | name: "some-updatable-apex-lib", |
| 6372 | srcs: ["a.java"], |
| 6373 | sdk_version: "current", |
| 6374 | apex_available: [ |
| 6375 | "some-updatable-apex", |
| 6376 | ], |
| 6377 | } |
| 6378 | |
| 6379 | java_library { |
| 6380 | name: "some-non-updatable-apex-lib", |
| 6381 | srcs: ["a.java"], |
| 6382 | apex_available: [ |
| 6383 | "some-non-updatable-apex", |
| 6384 | ], |
| 6385 | } |
| 6386 | |
| 6387 | java_library { |
| 6388 | name: "some-platform-lib", |
| 6389 | srcs: ["a.java"], |
| 6390 | sdk_version: "current", |
| 6391 | installable: true, |
| 6392 | } |
| 6393 | |
| 6394 | java_library { |
| 6395 | name: "some-art-lib", |
| 6396 | srcs: ["a.java"], |
| 6397 | sdk_version: "current", |
| 6398 | apex_available: [ |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6399 | "com.android.art.debug", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6400 | ], |
| 6401 | hostdex: true, |
| 6402 | } |
| 6403 | |
| 6404 | apex { |
| 6405 | name: "some-updatable-apex", |
| 6406 | key: "some-updatable-apex.key", |
| 6407 | java_libs: ["some-updatable-apex-lib"], |
| 6408 | updatable: true, |
| 6409 | min_sdk_version: "current", |
| 6410 | } |
| 6411 | |
| 6412 | apex { |
| 6413 | name: "some-non-updatable-apex", |
| 6414 | key: "some-non-updatable-apex.key", |
| 6415 | java_libs: ["some-non-updatable-apex-lib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6416 | updatable: false, |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6417 | } |
| 6418 | |
| 6419 | apex_key { |
| 6420 | name: "some-updatable-apex.key", |
| 6421 | } |
| 6422 | |
| 6423 | apex_key { |
| 6424 | name: "some-non-updatable-apex.key", |
| 6425 | } |
| 6426 | |
| 6427 | apex { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6428 | name: "com.android.art.debug", |
| 6429 | key: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6430 | java_libs: ["some-art-lib"], |
| 6431 | updatable: true, |
| 6432 | min_sdk_version: "current", |
| 6433 | } |
| 6434 | |
| 6435 | apex_key { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6436 | name: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6437 | } |
| 6438 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6439 | filegroup { |
| 6440 | name: "some-updatable-apex-file_contexts", |
| 6441 | srcs: [ |
| 6442 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 6443 | ], |
| 6444 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6445 | |
| 6446 | filegroup { |
| 6447 | name: "some-non-updatable-apex-file_contexts", |
| 6448 | srcs: [ |
| 6449 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 6450 | ], |
| 6451 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6452 | ` |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 6453 | |
| 6454 | testDexpreoptWithApexes(t, bp, errmsg, transformDexpreoptConfig) |
| 6455 | } |
| 6456 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6457 | func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) *android.TestContext { |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 6458 | t.Helper() |
| 6459 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6460 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 6461 | bp += java.GatherRequiredDepsForTest() |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6462 | |
| 6463 | fs := map[string][]byte{ |
| 6464 | "a.java": nil, |
| 6465 | "a.jar": nil, |
| 6466 | "build/make/target/product/security": nil, |
| 6467 | "apex_manifest.json": nil, |
| 6468 | "AndroidManifest.xml": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 6469 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6470 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
| 6471 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
| 6472 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 6473 | "framework/aidl/a.aidl": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6474 | } |
| 6475 | cc.GatherRequiredFilesForTest(fs) |
| 6476 | |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 6477 | for k, v := range filesForSdkLibrary { |
| 6478 | fs[k] = v |
| 6479 | } |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 6480 | config := android.TestArchConfig(t.TempDir(), nil, bp, fs) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6481 | |
| 6482 | ctx := android.NewTestArchContext(config) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6483 | ctx.RegisterModuleType("apex", BundleFactory) |
| 6484 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6485 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6486 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 6487 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 6488 | ctx.PreArchMutators(android.RegisterComponentsMutator) |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 6489 | android.RegisterPrebuiltMutators(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6490 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 6491 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6492 | java.RegisterHiddenApiSingletonComponents(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6493 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 6494 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 6495 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 6496 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6497 | ctx.Register() |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6498 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6499 | pathCtx := android.PathContextForTesting(config) |
| 6500 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 6501 | transformDexpreoptConfig(dexpreoptConfig) |
| 6502 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 6503 | |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6504 | // Make sure that any changes to these dexpreopt properties are mirrored in the corresponding |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 6505 | // product variables. |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6506 | config.TestProductVariables.BootJars = dexpreoptConfig.BootJars |
| 6507 | config.TestProductVariables.UpdatableBootJars = dexpreoptConfig.UpdatableBootJars |
| 6508 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6509 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 6510 | android.FailIfErrored(t, errs) |
| 6511 | |
| 6512 | _, errs = ctx.PrepareBuildActions(config) |
| 6513 | if errmsg == "" { |
| 6514 | android.FailIfErrored(t, errs) |
| 6515 | } else if len(errs) > 0 { |
| 6516 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6517 | } else { |
| 6518 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 6519 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6520 | |
| 6521 | return ctx |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6522 | } |
| 6523 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6524 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 6525 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 6526 | apex { |
| 6527 | name: "myapex", |
| 6528 | key: "myapex.key", |
| 6529 | updatable: true, |
| 6530 | } |
| 6531 | |
| 6532 | apex_key { |
| 6533 | name: "myapex.key", |
| 6534 | public_key: "testkey.avbpubkey", |
| 6535 | private_key: "testkey.pem", |
| 6536 | } |
| 6537 | `) |
| 6538 | } |
| 6539 | |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6540 | func TestUpdatableDefault_should_set_min_sdk_version(t *testing.T) { |
| 6541 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 6542 | apex { |
| 6543 | name: "myapex", |
| 6544 | key: "myapex.key", |
| 6545 | } |
| 6546 | |
| 6547 | apex_key { |
| 6548 | name: "myapex.key", |
| 6549 | public_key: "testkey.avbpubkey", |
| 6550 | private_key: "testkey.pem", |
| 6551 | } |
| 6552 | `) |
| 6553 | } |
| 6554 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6555 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6556 | var err string |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6557 | var transform func(*dexpreopt.GlobalConfig) |
| 6558 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6559 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
| 6560 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6561 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6562 | } |
| 6563 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6564 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6565 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6566 | t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6567 | err = `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6568 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6569 | config.BootJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6570 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6571 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6572 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6573 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6574 | t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6575 | err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6576 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6577 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6578 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6579 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6580 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6581 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6582 | t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6583 | err = `module "some-non-updatable-apex-lib" is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6584 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6585 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6586 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6587 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6588 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6589 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6590 | t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6591 | err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6592 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6593 | config.BootJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6594 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6595 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6596 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6597 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6598 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
| 6599 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6600 | config.BootJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6601 | } |
| 6602 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6603 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6604 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6605 | t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6606 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6607 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6608 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6609 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6610 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6611 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6612 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6613 | t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6614 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6615 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6616 | config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6617 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6618 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6619 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6620 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6621 | t.Run("platform jar in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6622 | err = `module "some-platform-lib" is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6623 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6624 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6625 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6626 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6627 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6628 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6629 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
| 6630 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6631 | config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6632 | } |
| 6633 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6634 | }) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6635 | |
| 6636 | } |
| 6637 | |
| 6638 | func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { |
| 6639 | transform := func(config *dexpreopt.GlobalConfig) { |
| 6640 | config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo"}) |
| 6641 | } |
| 6642 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6643 | testDexpreoptWithApexes(t, ` |
| 6644 | prebuilt_apex { |
| 6645 | name: "myapex" , |
| 6646 | arch: { |
| 6647 | arm64: { |
| 6648 | src: "myapex-arm64.apex", |
| 6649 | }, |
| 6650 | arm: { |
| 6651 | src: "myapex-arm.apex", |
| 6652 | }, |
| 6653 | }, |
| 6654 | exported_java_libs: ["libfoo"], |
| 6655 | } |
| 6656 | |
| 6657 | java_import { |
| 6658 | name: "libfoo", |
| 6659 | jars: ["libfoo.jar"], |
| 6660 | } |
| 6661 | `, "", transform) |
| 6662 | }) |
| 6663 | |
| 6664 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6665 | testDexpreoptWithApexes(t, ` |
| 6666 | prebuilt_apex { |
| 6667 | name: "myapex" , |
| 6668 | arch: { |
| 6669 | arm64: { |
| 6670 | src: "myapex-arm64.apex", |
| 6671 | }, |
| 6672 | arm: { |
| 6673 | src: "myapex-arm.apex", |
| 6674 | }, |
| 6675 | }, |
| 6676 | exported_java_libs: ["libfoo"], |
| 6677 | } |
| 6678 | |
| 6679 | java_import { |
| 6680 | name: "libfoo", |
| 6681 | jars: ["libfoo.jar"], |
| 6682 | } |
| 6683 | `, "", transform) |
| 6684 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6685 | } |
| 6686 | |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6687 | func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) { |
| 6688 | t.Helper() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6689 | bp += ` |
| 6690 | apex_key { |
| 6691 | name: "myapex.key", |
| 6692 | public_key: "testkey.avbpubkey", |
| 6693 | private_key: "testkey.pem", |
| 6694 | }` |
| 6695 | fs := map[string][]byte{ |
| 6696 | "lib1/src/A.java": nil, |
| 6697 | "lib2/src/B.java": nil, |
| 6698 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 6699 | } |
| 6700 | |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 6701 | config := android.TestArchConfig(t.TempDir(), nil, bp, fs) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6702 | android.SetTestNeverallowRules(config, rules) |
| 6703 | updatableBootJars := make([]string, 0, len(apexBootJars)) |
| 6704 | for _, apexBootJar := range apexBootJars { |
| 6705 | updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar) |
| 6706 | } |
| 6707 | config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars) |
| 6708 | |
| 6709 | ctx := android.NewTestArchContext(config) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6710 | ctx.RegisterModuleType("apex", BundleFactory) |
| 6711 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 6712 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 6713 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 6714 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6715 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 6716 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 6717 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 6718 | ctx.PostDepsMutators(android.RegisterNeverallowMutator) |
| 6719 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6720 | ctx.Register() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6721 | |
| 6722 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 6723 | android.FailIfErrored(t, errs) |
| 6724 | |
| 6725 | _, errs = ctx.PrepareBuildActions(config) |
| 6726 | if errmsg == "" { |
| 6727 | android.FailIfErrored(t, errs) |
| 6728 | } else if len(errs) > 0 { |
| 6729 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 6730 | return |
| 6731 | } else { |
| 6732 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | func TestApexPermittedPackagesRules(t *testing.T) { |
| 6737 | testcases := []struct { |
| 6738 | name string |
| 6739 | expectedError string |
| 6740 | bp string |
| 6741 | bootJars []string |
| 6742 | modulesPackages map[string][]string |
| 6743 | }{ |
| 6744 | |
| 6745 | { |
| 6746 | name: "Non-Bootclasspath apex jar not satisfying allowed module packages.", |
| 6747 | expectedError: "", |
| 6748 | bp: ` |
| 6749 | java_library { |
| 6750 | name: "bcp_lib1", |
| 6751 | srcs: ["lib1/src/*.java"], |
| 6752 | permitted_packages: ["foo.bar"], |
| 6753 | apex_available: ["myapex"], |
| 6754 | sdk_version: "none", |
| 6755 | system_modules: "none", |
| 6756 | } |
| 6757 | java_library { |
| 6758 | name: "nonbcp_lib2", |
| 6759 | srcs: ["lib2/src/*.java"], |
| 6760 | apex_available: ["myapex"], |
| 6761 | permitted_packages: ["a.b"], |
| 6762 | sdk_version: "none", |
| 6763 | system_modules: "none", |
| 6764 | } |
| 6765 | apex { |
| 6766 | name: "myapex", |
| 6767 | key: "myapex.key", |
| 6768 | java_libs: ["bcp_lib1", "nonbcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6769 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6770 | }`, |
| 6771 | bootJars: []string{"bcp_lib1"}, |
| 6772 | modulesPackages: map[string][]string{ |
| 6773 | "myapex": []string{ |
| 6774 | "foo.bar", |
| 6775 | }, |
| 6776 | }, |
| 6777 | }, |
| 6778 | { |
| 6779 | name: "Bootclasspath apex jar not satisfying allowed module packages.", |
| 6780 | 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.`, |
| 6781 | bp: ` |
| 6782 | java_library { |
| 6783 | name: "bcp_lib1", |
| 6784 | srcs: ["lib1/src/*.java"], |
| 6785 | apex_available: ["myapex"], |
| 6786 | permitted_packages: ["foo.bar"], |
| 6787 | sdk_version: "none", |
| 6788 | system_modules: "none", |
| 6789 | } |
| 6790 | java_library { |
| 6791 | name: "bcp_lib2", |
| 6792 | srcs: ["lib2/src/*.java"], |
| 6793 | apex_available: ["myapex"], |
| 6794 | permitted_packages: ["foo.bar", "bar.baz"], |
| 6795 | sdk_version: "none", |
| 6796 | system_modules: "none", |
| 6797 | } |
| 6798 | apex { |
| 6799 | name: "myapex", |
| 6800 | key: "myapex.key", |
| 6801 | java_libs: ["bcp_lib1", "bcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6802 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6803 | } |
| 6804 | `, |
| 6805 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
| 6806 | modulesPackages: map[string][]string{ |
| 6807 | "myapex": []string{ |
| 6808 | "foo.bar", |
| 6809 | }, |
| 6810 | }, |
| 6811 | }, |
| 6812 | } |
| 6813 | for _, tc := range testcases { |
| 6814 | t.Run(tc.name, func(t *testing.T) { |
| 6815 | rules := createApexPermittedPackagesRules(tc.modulesPackages) |
| 6816 | testApexPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules) |
| 6817 | }) |
| 6818 | } |
| 6819 | } |
| 6820 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6821 | func TestTestFor(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6822 | ctx := testApex(t, ` |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6823 | apex { |
| 6824 | name: "myapex", |
| 6825 | key: "myapex.key", |
| 6826 | native_shared_libs: ["mylib", "myprivlib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6827 | updatable: false, |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6828 | } |
| 6829 | |
| 6830 | apex_key { |
| 6831 | name: "myapex.key", |
| 6832 | public_key: "testkey.avbpubkey", |
| 6833 | private_key: "testkey.pem", |
| 6834 | } |
| 6835 | |
| 6836 | cc_library { |
| 6837 | name: "mylib", |
| 6838 | srcs: ["mylib.cpp"], |
| 6839 | system_shared_libs: [], |
| 6840 | stl: "none", |
| 6841 | stubs: { |
| 6842 | versions: ["1"], |
| 6843 | }, |
| 6844 | apex_available: ["myapex"], |
| 6845 | } |
| 6846 | |
| 6847 | cc_library { |
| 6848 | name: "myprivlib", |
| 6849 | srcs: ["mylib.cpp"], |
| 6850 | system_shared_libs: [], |
| 6851 | stl: "none", |
| 6852 | apex_available: ["myapex"], |
| 6853 | } |
| 6854 | |
| 6855 | |
| 6856 | cc_test { |
| 6857 | name: "mytest", |
| 6858 | gtest: false, |
| 6859 | srcs: ["mylib.cpp"], |
| 6860 | system_shared_libs: [], |
| 6861 | stl: "none", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6862 | shared_libs: ["mylib", "myprivlib", "mytestlib"], |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6863 | test_for: ["myapex"] |
| 6864 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6865 | |
| 6866 | cc_library { |
| 6867 | name: "mytestlib", |
| 6868 | srcs: ["mylib.cpp"], |
| 6869 | system_shared_libs: [], |
| 6870 | shared_libs: ["mylib", "myprivlib"], |
| 6871 | stl: "none", |
| 6872 | test_for: ["myapex"], |
| 6873 | } |
| 6874 | |
| 6875 | cc_benchmark { |
| 6876 | name: "mybench", |
| 6877 | srcs: ["mylib.cpp"], |
| 6878 | system_shared_libs: [], |
| 6879 | shared_libs: ["mylib", "myprivlib"], |
| 6880 | stl: "none", |
| 6881 | test_for: ["myapex"], |
| 6882 | } |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6883 | `) |
| 6884 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6885 | ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) { |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 6886 | ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ") |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6887 | mylibLdFlags := android.FilterListPred(ldFlags, func(s string) bool { return strings.HasPrefix(s, linkedLib) }) |
| 6888 | android.AssertArrayString(t, "unexpected "+linkedLib+" link library for "+mod, []string{linkedLib + expectedVariant}, mylibLdFlags) |
| 6889 | } |
| 6890 | |
| 6891 | // These modules are tests for the apex, therefore are linked to the |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6892 | // actual implementation of mylib instead of its stub. |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6893 | ensureLinkedLibIs("mytest", "android_arm64_armv8-a", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 6894 | ensureLinkedLibIs("mytestlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 6895 | ensureLinkedLibIs("mybench", "android_arm64_armv8-a", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 6896 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6897 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6898 | func TestIndirectTestFor(t *testing.T) { |
| 6899 | ctx := testApex(t, ` |
| 6900 | apex { |
| 6901 | name: "myapex", |
| 6902 | key: "myapex.key", |
| 6903 | native_shared_libs: ["mylib", "myprivlib"], |
| 6904 | updatable: false, |
| 6905 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6906 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6907 | apex_key { |
| 6908 | name: "myapex.key", |
| 6909 | public_key: "testkey.avbpubkey", |
| 6910 | private_key: "testkey.pem", |
| 6911 | } |
| 6912 | |
| 6913 | cc_library { |
| 6914 | name: "mylib", |
| 6915 | srcs: ["mylib.cpp"], |
| 6916 | system_shared_libs: [], |
| 6917 | stl: "none", |
| 6918 | stubs: { |
| 6919 | versions: ["1"], |
| 6920 | }, |
| 6921 | apex_available: ["myapex"], |
| 6922 | } |
| 6923 | |
| 6924 | cc_library { |
| 6925 | name: "myprivlib", |
| 6926 | srcs: ["mylib.cpp"], |
| 6927 | system_shared_libs: [], |
| 6928 | stl: "none", |
| 6929 | shared_libs: ["mylib"], |
| 6930 | apex_available: ["myapex"], |
| 6931 | } |
| 6932 | |
| 6933 | cc_library { |
| 6934 | name: "mytestlib", |
| 6935 | srcs: ["mylib.cpp"], |
| 6936 | system_shared_libs: [], |
| 6937 | shared_libs: ["myprivlib"], |
| 6938 | stl: "none", |
| 6939 | test_for: ["myapex"], |
| 6940 | } |
| 6941 | `) |
| 6942 | |
| 6943 | ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) { |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 6944 | ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ") |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 6945 | mylibLdFlags := android.FilterListPred(ldFlags, func(s string) bool { return strings.HasPrefix(s, linkedLib) }) |
| 6946 | android.AssertArrayString(t, "unexpected "+linkedLib+" link library for "+mod, []string{linkedLib + expectedVariant}, mylibLdFlags) |
| 6947 | } |
| 6948 | |
| 6949 | // The platform variant of mytestlib links to the platform variant of the |
| 6950 | // internal myprivlib. |
| 6951 | ensureLinkedLibIs("mytestlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/myprivlib/", "android_arm64_armv8-a_shared/myprivlib.so") |
| 6952 | |
| 6953 | // The platform variant of myprivlib links to the platform variant of mylib |
| 6954 | // and bypasses its stubs. |
| 6955 | 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] | 6956 | } |
| 6957 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6958 | // TODO(jungjw): Move this to proptools |
| 6959 | func intPtr(i int) *int { |
| 6960 | return &i |
| 6961 | } |
| 6962 | |
| 6963 | func TestApexSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6964 | ctx := testApex(t, ` |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6965 | apex_set { |
| 6966 | name: "myapex", |
| 6967 | set: "myapex.apks", |
| 6968 | filename: "foo_v2.apex", |
| 6969 | overrides: ["foo"], |
| 6970 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 6971 | `, |
| 6972 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 6973 | variables.Platform_sdk_version = intPtr(30) |
| 6974 | }), |
| 6975 | android.FixtureModifyConfig(func(config android.Config) { |
| 6976 | config.Targets[android.Android] = []android.Target{ |
| 6977 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}}, |
| 6978 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}}, |
| 6979 | } |
| 6980 | }), |
| 6981 | ) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6982 | |
| 6983 | m := ctx.ModuleForTests("myapex", "android_common") |
| 6984 | |
| 6985 | // Check extract_apks tool parameters. |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 6986 | extractedApex := m.Output("out/soong/.intermediates/myapex/android_common/foo_v2.apex") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6987 | actual := extractedApex.Args["abis"] |
| 6988 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 6989 | if actual != expected { |
| 6990 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6991 | } |
| 6992 | actual = extractedApex.Args["sdk-version"] |
| 6993 | expected = "30" |
| 6994 | if actual != expected { |
| 6995 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6996 | } |
| 6997 | |
| 6998 | a := m.Module().(*ApexSet) |
| 6999 | expectedOverrides := []string{"foo"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7000 | actualOverrides := android.AndroidMkEntriesForTest(t, ctx, a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 7001 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 7002 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 7003 | } |
| 7004 | } |
| 7005 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 7006 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 7007 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 7008 | apex { |
| 7009 | name: "myapex", |
| 7010 | key: "myapex.key", |
| 7011 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7012 | updatable: false, |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 7013 | } |
| 7014 | |
| 7015 | apex_key { |
| 7016 | name: "myapex.key", |
| 7017 | public_key: "testkey.avbpubkey", |
| 7018 | private_key: "testkey.pem", |
| 7019 | } |
| 7020 | |
| 7021 | cc_library { |
| 7022 | name: "mylib", |
| 7023 | srcs: ["mylib.cpp"], |
| 7024 | static_libs: ["otherlib"], |
| 7025 | system_shared_libs: [], |
| 7026 | stl: "none", |
| 7027 | apex_available: [ "myapex" ], |
| 7028 | } |
| 7029 | |
| 7030 | cc_library { |
| 7031 | name: "otherlib", |
| 7032 | srcs: ["mylib.cpp"], |
| 7033 | system_shared_libs: [], |
| 7034 | stl: "none", |
| 7035 | stubs: { |
| 7036 | versions: ["1", "2", "3"], |
| 7037 | }, |
| 7038 | apex_available: [ "myapex" ], |
| 7039 | } |
| 7040 | `) |
| 7041 | } |
| 7042 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 7043 | func TestApexKeysTxt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7044 | ctx := testApex(t, ` |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 7045 | apex { |
| 7046 | name: "myapex", |
| 7047 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7048 | updatable: false, |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | apex_key { |
| 7052 | name: "myapex.key", |
| 7053 | public_key: "testkey.avbpubkey", |
| 7054 | private_key: "testkey.pem", |
| 7055 | } |
| 7056 | |
| 7057 | prebuilt_apex { |
| 7058 | name: "myapex", |
| 7059 | prefer: true, |
| 7060 | arch: { |
| 7061 | arm64: { |
| 7062 | src: "myapex-arm64.apex", |
| 7063 | }, |
| 7064 | arm: { |
| 7065 | src: "myapex-arm.apex", |
| 7066 | }, |
| 7067 | }, |
| 7068 | } |
| 7069 | |
| 7070 | apex_set { |
| 7071 | name: "myapex_set", |
| 7072 | set: "myapex.apks", |
| 7073 | filename: "myapex_set.apex", |
| 7074 | overrides: ["myapex"], |
| 7075 | } |
| 7076 | `) |
| 7077 | |
| 7078 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 7079 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 7080 | 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] | 7081 | 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] | 7082 | } |
| 7083 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 7084 | func TestAllowedFiles(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7085 | ctx := testApex(t, ` |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 7086 | apex { |
| 7087 | name: "myapex", |
| 7088 | key: "myapex.key", |
| 7089 | apps: ["app"], |
| 7090 | allowed_files: "allowed.txt", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7091 | updatable: false, |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 7092 | } |
| 7093 | |
| 7094 | apex_key { |
| 7095 | name: "myapex.key", |
| 7096 | public_key: "testkey.avbpubkey", |
| 7097 | private_key: "testkey.pem", |
| 7098 | } |
| 7099 | |
| 7100 | android_app { |
| 7101 | name: "app", |
| 7102 | srcs: ["foo/bar/MyClass.java"], |
| 7103 | package_name: "foo", |
| 7104 | sdk_version: "none", |
| 7105 | system_modules: "none", |
| 7106 | apex_available: [ "myapex" ], |
| 7107 | } |
| 7108 | `, withFiles(map[string][]byte{ |
| 7109 | "sub/Android.bp": []byte(` |
| 7110 | override_apex { |
| 7111 | name: "override_myapex", |
| 7112 | base: "myapex", |
| 7113 | apps: ["override_app"], |
| 7114 | allowed_files: ":allowed", |
| 7115 | } |
| 7116 | // Overridable "path" property should be referenced indirectly |
| 7117 | filegroup { |
| 7118 | name: "allowed", |
| 7119 | srcs: ["allowed.txt"], |
| 7120 | } |
| 7121 | override_android_app { |
| 7122 | name: "override_app", |
| 7123 | base: "app", |
| 7124 | package_name: "bar", |
| 7125 | } |
| 7126 | `), |
| 7127 | })) |
| 7128 | |
| 7129 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 7130 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 7131 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 7132 | } |
| 7133 | |
| 7134 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 7135 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 7136 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 7137 | } |
| 7138 | } |
| 7139 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7140 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7141 | testApex(t, ` |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7142 | apex { |
| 7143 | name: "myapex", |
| 7144 | key: "myapex.key", |
| 7145 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7146 | updatable: false, |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7147 | } |
| 7148 | |
| 7149 | apex_key { |
| 7150 | name: "myapex.key", |
| 7151 | public_key: "testkey.avbpubkey", |
| 7152 | private_key: "testkey.pem", |
| 7153 | } |
| 7154 | |
| 7155 | cc_library { |
| 7156 | name: "mylib", |
| 7157 | srcs: ["mylib.cpp"], |
| 7158 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 7159 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7160 | }, |
| 7161 | apex_available: ["myapex"], |
| 7162 | } |
| 7163 | |
| 7164 | cc_prebuilt_library_shared { |
| 7165 | name: "mylib", |
| 7166 | prefer: false, |
| 7167 | srcs: ["prebuilt.so"], |
| 7168 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 7169 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7170 | }, |
| 7171 | apex_available: ["myapex"], |
| 7172 | } |
| 7173 | `) |
| 7174 | } |
| 7175 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7176 | func TestCompressedApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7177 | ctx := testApex(t, ` |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7178 | apex { |
| 7179 | name: "myapex", |
| 7180 | key: "myapex.key", |
| 7181 | compressible: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7182 | updatable: false, |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7183 | } |
| 7184 | apex_key { |
| 7185 | name: "myapex.key", |
| 7186 | public_key: "testkey.avbpubkey", |
| 7187 | private_key: "testkey.pem", |
| 7188 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 7189 | `, |
| 7190 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7191 | variables.CompressedApex = proptools.BoolPtr(true) |
| 7192 | }), |
| 7193 | ) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7194 | |
| 7195 | compressRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("compressRule") |
| 7196 | ensureContains(t, compressRule.Output.String(), "myapex.capex.unsigned") |
| 7197 | |
| 7198 | signApkRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("sign compressedApex") |
| 7199 | ensureEquals(t, signApkRule.Input.String(), compressRule.Output.String()) |
| 7200 | |
| 7201 | // Make sure output of bundle is .capex |
| 7202 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 7203 | ensureContains(t, ab.outputFile.String(), "myapex.capex") |
| 7204 | |
| 7205 | // Verify android.mk rules |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7206 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7207 | var builder strings.Builder |
| 7208 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7209 | androidMk := builder.String() |
| 7210 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.capex\n") |
| 7211 | } |
| 7212 | |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7213 | func TestPreferredPrebuiltSharedLibDep(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7214 | ctx := testApex(t, ` |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7215 | apex { |
| 7216 | name: "myapex", |
| 7217 | key: "myapex.key", |
| 7218 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7219 | updatable: false, |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7220 | } |
| 7221 | |
| 7222 | apex_key { |
| 7223 | name: "myapex.key", |
| 7224 | public_key: "testkey.avbpubkey", |
| 7225 | private_key: "testkey.pem", |
| 7226 | } |
| 7227 | |
| 7228 | cc_library { |
| 7229 | name: "mylib", |
| 7230 | srcs: ["mylib.cpp"], |
| 7231 | apex_available: ["myapex"], |
| 7232 | shared_libs: ["otherlib"], |
| 7233 | system_shared_libs: [], |
| 7234 | } |
| 7235 | |
| 7236 | cc_library { |
| 7237 | name: "otherlib", |
| 7238 | srcs: ["mylib.cpp"], |
| 7239 | stubs: { |
| 7240 | versions: ["current"], |
| 7241 | }, |
| 7242 | } |
| 7243 | |
| 7244 | cc_prebuilt_library_shared { |
| 7245 | name: "otherlib", |
| 7246 | prefer: true, |
| 7247 | srcs: ["prebuilt.so"], |
| 7248 | stubs: { |
| 7249 | versions: ["current"], |
| 7250 | }, |
| 7251 | } |
| 7252 | `) |
| 7253 | |
| 7254 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7255 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7256 | var builder strings.Builder |
| 7257 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7258 | androidMk := builder.String() |
| 7259 | |
| 7260 | // The make level dependency needs to be on otherlib - prebuilt_otherlib isn't |
| 7261 | // a thing there. |
| 7262 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherlib\n") |
| 7263 | } |
| 7264 | |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7265 | func TestExcludeDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7266 | ctx := testApex(t, ` |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7267 | apex { |
| 7268 | name: "myapex", |
| 7269 | key: "myapex.key", |
| 7270 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7271 | updatable: false, |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7272 | } |
| 7273 | |
| 7274 | apex_key { |
| 7275 | name: "myapex.key", |
| 7276 | public_key: "testkey.avbpubkey", |
| 7277 | private_key: "testkey.pem", |
| 7278 | } |
| 7279 | |
| 7280 | cc_library { |
| 7281 | name: "mylib", |
| 7282 | srcs: ["mylib.cpp"], |
| 7283 | system_shared_libs: [], |
| 7284 | stl: "none", |
| 7285 | apex_available: ["myapex"], |
| 7286 | shared_libs: ["mylib2"], |
| 7287 | target: { |
| 7288 | apex: { |
| 7289 | exclude_shared_libs: ["mylib2"], |
| 7290 | }, |
| 7291 | }, |
| 7292 | } |
| 7293 | |
| 7294 | cc_library { |
| 7295 | name: "mylib2", |
| 7296 | srcs: ["mylib.cpp"], |
| 7297 | system_shared_libs: [], |
| 7298 | stl: "none", |
| 7299 | } |
| 7300 | `) |
| 7301 | |
| 7302 | // Check if mylib is linked to mylib2 for the non-apex target |
| 7303 | ldFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 7304 | ensureContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 7305 | |
| 7306 | // Make sure that the link doesn't occur for the apex target |
| 7307 | ldFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 7308 | ensureNotContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared_apex10000/mylib2.so") |
| 7309 | |
| 7310 | // It shouldn't appear in the copy cmd as well. |
| 7311 | copyCmds := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").Args["copy_commands"] |
| 7312 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 7313 | } |
| 7314 | |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7315 | func TestPrebuiltStubLibDep(t *testing.T) { |
| 7316 | bpBase := ` |
| 7317 | apex { |
| 7318 | name: "myapex", |
| 7319 | key: "myapex.key", |
| 7320 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7321 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7322 | } |
| 7323 | apex_key { |
| 7324 | name: "myapex.key", |
| 7325 | public_key: "testkey.avbpubkey", |
| 7326 | private_key: "testkey.pem", |
| 7327 | } |
| 7328 | cc_library { |
| 7329 | name: "mylib", |
| 7330 | srcs: ["mylib.cpp"], |
| 7331 | apex_available: ["myapex"], |
| 7332 | shared_libs: ["stublib"], |
| 7333 | system_shared_libs: [], |
| 7334 | } |
| 7335 | apex { |
| 7336 | name: "otherapex", |
| 7337 | enabled: %s, |
| 7338 | key: "myapex.key", |
| 7339 | native_shared_libs: ["stublib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7340 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7341 | } |
| 7342 | ` |
| 7343 | |
| 7344 | stublibSourceBp := ` |
| 7345 | cc_library { |
| 7346 | name: "stublib", |
| 7347 | srcs: ["mylib.cpp"], |
| 7348 | apex_available: ["otherapex"], |
| 7349 | system_shared_libs: [], |
| 7350 | stl: "none", |
| 7351 | stubs: { |
| 7352 | versions: ["1"], |
| 7353 | }, |
| 7354 | } |
| 7355 | ` |
| 7356 | |
| 7357 | stublibPrebuiltBp := ` |
| 7358 | cc_prebuilt_library_shared { |
| 7359 | name: "stublib", |
| 7360 | srcs: ["prebuilt.so"], |
| 7361 | apex_available: ["otherapex"], |
| 7362 | stubs: { |
| 7363 | versions: ["1"], |
| 7364 | }, |
| 7365 | %s |
| 7366 | } |
| 7367 | ` |
| 7368 | |
| 7369 | tests := []struct { |
| 7370 | name string |
| 7371 | stublibBp string |
| 7372 | usePrebuilt bool |
| 7373 | modNames []string // Modules to collect AndroidMkEntries for |
| 7374 | otherApexEnabled []string |
| 7375 | }{ |
| 7376 | { |
| 7377 | name: "only_source", |
| 7378 | stublibBp: stublibSourceBp, |
| 7379 | usePrebuilt: false, |
| 7380 | modNames: []string{"stublib"}, |
| 7381 | otherApexEnabled: []string{"true", "false"}, |
| 7382 | }, |
| 7383 | { |
| 7384 | name: "source_preferred", |
| 7385 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, ""), |
| 7386 | usePrebuilt: false, |
| 7387 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 7388 | otherApexEnabled: []string{"true", "false"}, |
| 7389 | }, |
| 7390 | { |
| 7391 | name: "prebuilt_preferred", |
| 7392 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, "prefer: true,"), |
| 7393 | usePrebuilt: true, |
| 7394 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 7395 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 7396 | }, |
| 7397 | { |
| 7398 | name: "only_prebuilt", |
| 7399 | stublibBp: fmt.Sprintf(stublibPrebuiltBp, ""), |
| 7400 | usePrebuilt: true, |
| 7401 | modNames: []string{"stublib"}, |
| 7402 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 7403 | }, |
| 7404 | } |
| 7405 | |
| 7406 | for _, test := range tests { |
| 7407 | t.Run(test.name, func(t *testing.T) { |
| 7408 | for _, otherApexEnabled := range test.otherApexEnabled { |
| 7409 | t.Run("otherapex_enabled_"+otherApexEnabled, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7410 | ctx := testApex(t, fmt.Sprintf(bpBase, otherApexEnabled)+test.stublibBp) |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7411 | |
| 7412 | type modAndMkEntries struct { |
| 7413 | mod *cc.Module |
| 7414 | mkEntries android.AndroidMkEntries |
| 7415 | } |
| 7416 | entries := []*modAndMkEntries{} |
| 7417 | |
| 7418 | // Gather shared lib modules that are installable |
| 7419 | for _, modName := range test.modNames { |
| 7420 | for _, variant := range ctx.ModuleVariantsForTests(modName) { |
| 7421 | if !strings.HasPrefix(variant, "android_arm64_armv8-a_shared") { |
| 7422 | continue |
| 7423 | } |
| 7424 | mod := ctx.ModuleForTests(modName, variant).Module().(*cc.Module) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 7425 | if !mod.Enabled() || mod.IsHideFromMake() { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7426 | continue |
| 7427 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7428 | for _, ent := range android.AndroidMkEntriesForTest(t, ctx, mod) { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7429 | if ent.Disabled { |
| 7430 | continue |
| 7431 | } |
| 7432 | entries = append(entries, &modAndMkEntries{ |
| 7433 | mod: mod, |
| 7434 | mkEntries: ent, |
| 7435 | }) |
| 7436 | } |
| 7437 | } |
| 7438 | } |
| 7439 | |
| 7440 | var entry *modAndMkEntries = nil |
| 7441 | for _, ent := range entries { |
| 7442 | if strings.Join(ent.mkEntries.EntryMap["LOCAL_MODULE"], ",") == "stublib" { |
| 7443 | if entry != nil { |
| 7444 | t.Errorf("More than one AndroidMk entry for \"stublib\": %s and %s", entry.mod, ent.mod) |
| 7445 | } else { |
| 7446 | entry = ent |
| 7447 | } |
| 7448 | } |
| 7449 | } |
| 7450 | |
| 7451 | if entry == nil { |
| 7452 | t.Errorf("AndroidMk entry for \"stublib\" missing") |
| 7453 | } else { |
| 7454 | isPrebuilt := entry.mod.Prebuilt() != nil |
| 7455 | if isPrebuilt != test.usePrebuilt { |
| 7456 | t.Errorf("Wrong module for \"stublib\" AndroidMk entry: got prebuilt %t, want prebuilt %t", isPrebuilt, test.usePrebuilt) |
| 7457 | } |
| 7458 | if !entry.mod.IsStubs() { |
| 7459 | t.Errorf("Module for \"stublib\" AndroidMk entry isn't a stub: %s", entry.mod) |
| 7460 | } |
| 7461 | if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil { |
| 7462 | t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries) |
| 7463 | } |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 7464 | cflags := entry.mkEntries.EntryMap["LOCAL_EXPORT_CFLAGS"] |
| 7465 | expected := "-D__STUBLIB_API__=1" |
| 7466 | if !android.InList(expected, cflags) { |
| 7467 | t.Errorf("LOCAL_EXPORT_CFLAGS expected to have %q, but got %q", expected, cflags) |
| 7468 | } |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7469 | } |
| 7470 | }) |
| 7471 | } |
| 7472 | }) |
| 7473 | } |
| 7474 | } |
| 7475 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 7476 | func TestMain(m *testing.M) { |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 7477 | os.Exit(m.Run()) |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 7478 | } |