blob: a220a063c34b7dd6396aeac68ec1a0d45da56634 [file] [log] [blame]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001// 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
15package apex
16
17import (
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +090018 "fmt"
Jiyong Park25fc6a92018-11-18 18:02:45 +090019 "os"
Jooyung Han39edb6c2019-11-06 16:53:07 +090020 "path"
Paul Duffin37856732021-02-26 14:24:15 +000021 "path/filepath"
Jaewoong Jung22f7d182019-07-16 18:25:41 -070022 "reflect"
Paul Duffin9b879592020-05-26 13:21:35 +010023 "regexp"
Jooyung Han31c470b2019-10-18 16:26:59 +090024 "sort"
Jiyong Park25fc6a92018-11-18 18:02:45 +090025 "strings"
26 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090027
28 "github.com/google/blueprint/proptools"
29
30 "android/soong/android"
markchien2f59ec92020-09-02 16:23:38 +080031 "android/soong/bpf"
Jiyong Parkda6eb592018-12-19 17:12:36 +090032 "android/soong/cc"
Ulya Trafimovichb28cc372020-01-13 15:18:16 +000033 "android/soong/dexpreopt"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070034 prebuilt_etc "android/soong/etc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090035 "android/soong/java"
Jiyong Park99644e92020-11-17 22:21:02 +090036 "android/soong/rust"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070037 "android/soong/sh"
Jiyong Park25fc6a92018-11-18 18:02:45 +090038)
39
Jooyung Hand3639552019-08-09 12:57:43 +090040// names returns name list from white space separated string
41func 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 Duffin40b62572021-03-20 11:39:01 +000050func testApexError(t *testing.T, pattern, bp string, preparers ...android.FixturePreparer) {
Jooyung Han344d5432019-08-23 11:17:39 +090051 t.Helper()
Paul Duffin40b62572021-03-20 11:39:01 +000052 apexFixtureFactory.Extend(preparers...).
Paul Duffine05480a2021-03-08 15:07:14 +000053 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
Paul Duffin40b62572021-03-20 11:39:01 +000054 RunTestWithBp(t, bp)
Jooyung Han5c998b92019-06-27 11:30:33 +090055}
56
Paul Duffin40b62572021-03-20 11:39:01 +000057func testApex(t *testing.T, bp string, preparers ...android.FixturePreparer) *android.TestContext {
Jooyung Han344d5432019-08-23 11:17:39 +090058 t.Helper()
Paul Duffin40b62572021-03-20 11:39:01 +000059 factory := apexFixtureFactory.Extend(preparers...)
60 if bp != "" {
61 factory = factory.Extend(android.FixtureWithRootAndroidBp(bp))
62 }
63 result := factory.RunTest(t)
Paul Duffine05480a2021-03-08 15:07:14 +000064 return result.TestContext
Jooyung Han5c998b92019-06-27 11:30:33 +090065}
66
Paul Duffin810f33d2021-03-09 14:12:32 +000067func withFiles(files android.MockFS) android.FixturePreparer {
68 return files.AddToFixture()
Jooyung Han344d5432019-08-23 11:17:39 +090069}
70
Paul Duffin810f33d2021-03-09 14:12:32 +000071func withTargets(targets map[android.OsType][]android.Target) android.FixturePreparer {
72 return android.FixtureModifyConfig(func(config android.Config) {
Jooyung Han344d5432019-08-23 11:17:39 +090073 for k, v := range targets {
74 config.Targets[k] = v
75 }
Paul Duffin810f33d2021-03-09 14:12:32 +000076 })
Jooyung Han344d5432019-08-23 11:17:39 +090077}
78
Jooyung Han35155c42020-02-06 17:33:20 +090079// 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 Duffin810f33d2021-03-09 14:12:32 +000084var 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
99func withManifestPackageNameOverrides(specs []string) android.FixturePreparer {
100 return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
101 variables.ManifestPackageNameOverrides = specs
102 })
Jooyung Han35155c42020-02-06 17:33:20 +0900103}
104
Paul Duffin810f33d2021-03-09 14:12:32 +0000105var withBinder32bit = android.FixtureModifyProductVariables(
106 func(variables android.FixtureProductVariables) {
107 variables.Binder32bit = proptools.BoolPtr(true)
108 },
109)
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900110
Paul Duffin810f33d2021-03-09 14:12:32 +0000111var withUnbundledBuild = android.FixtureModifyProductVariables(
112 func(variables android.FixtureProductVariables) {
113 variables.Unbundled_build = proptools.BoolPtr(true)
114 },
115)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900116
Paul Duffin37aad602021-03-08 09:47:16 +0000117var apexFixtureFactory = android.NewFixtureFactory(
Paul Duffin37ba3442021-03-29 00:21:08 +0100118 nil,
Paul Duffin37aad602021-03-08 09:47:16 +0000119 // 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 Duffin52bfaa42021-03-23 23:40:12 +0000140 prepareForTestWithMyapex,
Paul Duffin37aad602021-03-08 09:47:16 +0000141 android.FixtureMergeMockFs(android.MockFS{
Paul Duffin52bfaa42021-03-23 23:40:12 +0000142 "a.java": nil,
143 "PrebuiltAppFoo.apk": nil,
144 "PrebuiltAppFooPriv.apk": nil,
145 "apex_manifest.json": nil,
146 "AndroidManifest.xml": nil,
Paul Duffin37aad602021-03-08 09:47:16 +0000147 "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 Duffin52bfaa42021-03-23 23:40:12 +0000204var prepareForTestWithMyapex = android.FixtureMergeMockFs(android.MockFS{
205 "system/sepolicy/apex/myapex-file_contexts": nil,
206})
207
Jooyung Han643adc42020-02-27 13:50:06 +0900208// ensure that 'result' equals 'expected'
209func 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 Park25fc6a92018-11-18 18:02:45 +0900216// ensure that 'result' contains 'expected'
217func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900218 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900219 if !strings.Contains(result, expected) {
220 t.Errorf("%q is not found in %q", expected, result)
221 }
222}
223
Liz Kammer5bd365f2020-05-27 15:15:11 -0700224// ensure that 'result' contains 'expected' exactly one time
225func 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 Park25fc6a92018-11-18 18:02:45 +0900233// ensures that 'result' does not contain 'notExpected'
234func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900235 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900236 if strings.Contains(result, notExpected) {
237 t.Errorf("%q is found in %q", notExpected, result)
238 }
239}
240
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700241func 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 Park25fc6a92018-11-18 18:02:45 +0900252func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900253 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900254 if !android.InList(expected, result) {
255 t.Errorf("%q is not found in %v", expected, result)
256 }
257}
258
259func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900260 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900261 if android.InList(notExpected, result) {
262 t.Errorf("%q is found in %v", notExpected, result)
263 }
264}
265
Jooyung Hane1633032019-08-01 17:41:43 +0900266func 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 Islam3cd005d2020-11-26 13:32:26 +0000273func 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 Park25fc6a92018-11-18 18:02:45 +0900280// Minimal test
281func TestBasicApex(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -0800282 ctx := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900283 apex_defaults {
284 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900285 manifest: ":myapex.manifest",
286 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900287 key: "myapex.key",
Jiyong Park99644e92020-11-17 22:21:02 +0900288 binaries: ["foo.rust"],
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900289 native_shared_libs: [
290 "mylib",
291 "libfoo.ffi",
292 ],
Jiyong Park99644e92020-11-17 22:21:02 +0900293 rust_dyn_libs: ["libfoo.dylib.rust"],
Alex Light3d673592019-01-18 14:37:31 -0800294 multilib: {
295 both: {
Jiyong Park99644e92020-11-17 22:21:02 +0900296 binaries: ["foo"],
Alex Light3d673592019-01-18 14:37:31 -0800297 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900298 },
Jiyong Park77acec62020-06-01 21:39:15 +0900299 java_libs: [
300 "myjar",
301 "myjar_dex",
302 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000303 updatable: false,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900304 }
305
Jiyong Park30ca9372019-02-07 16:27:23 +0900306 apex {
307 name: "myapex",
308 defaults: ["myapex-defaults"],
309 }
310
Jiyong Park25fc6a92018-11-18 18:02:45 +0900311 apex_key {
312 name: "myapex.key",
313 public_key: "testkey.avbpubkey",
314 private_key: "testkey.pem",
315 }
316
Jiyong Park809bb722019-02-13 21:33:49 +0900317 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 Park25fc6a92018-11-18 18:02:45 +0900327 cc_library {
328 name: "mylib",
329 srcs: ["mylib.cpp"],
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900330 shared_libs: [
331 "mylib2",
332 "libbar.ffi",
333 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900334 system_shared_libs: [],
335 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000336 // TODO: remove //apex_available:platform
337 apex_available: [
338 "//apex_available:platform",
339 "myapex",
340 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900341 }
342
Alex Light3d673592019-01-18 14:37:31 -0800343 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 Hongd22a84a2020-07-28 17:37:46 -0700360 apex_available: [ "myapex", "com.android.gki.*" ],
361 }
362
Jiyong Park99644e92020-11-17 22:21:02 +0900363 rust_binary {
Artur Satayev533b98c2021-03-11 18:03:42 +0000364 name: "foo.rust",
Jiyong Park99644e92020-11-17 22:21:02 +0900365 srcs: ["foo.rs"],
366 rlibs: ["libfoo.rlib.rust"],
367 dylibs: ["libfoo.dylib.rust"],
368 apex_available: ["myapex"],
369 }
370
371 rust_library_rlib {
Artur Satayev533b98c2021-03-11 18:03:42 +0000372 name: "libfoo.rlib.rust",
Jiyong Park99644e92020-11-17 22:21:02 +0900373 srcs: ["foo.rs"],
374 crate_name: "foo",
375 apex_available: ["myapex"],
376 }
377
378 rust_library_dylib {
Artur Satayev533b98c2021-03-11 18:03:42 +0000379 name: "libfoo.dylib.rust",
Jiyong Park99644e92020-11-17 22:21:02 +0900380 srcs: ["foo.rs"],
381 crate_name: "foo",
382 apex_available: ["myapex"],
383 }
384
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900385 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 Hongd22a84a2020-07-28 17:37:46 -0700399 apex {
400 name: "com.android.gki.fake",
401 binaries: ["foo"],
402 key: "myapex.key",
403 file_contexts: ":myapex-file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000404 updatable: false,
Alex Light3d673592019-01-18 14:37:31 -0800405 }
406
Paul Duffindddd5462020-04-07 15:25:44 +0100407 cc_library_shared {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900408 name: "mylib2",
409 srcs: ["mylib.cpp"],
410 system_shared_libs: [],
411 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900412 notice: "custom_notice",
Jiyong Park9918e1a2020-03-17 19:16:40 +0900413 static_libs: ["libstatic"],
414 // TODO: remove //apex_available:platform
415 apex_available: [
416 "//apex_available:platform",
417 "myapex",
418 ],
419 }
420
Paul Duffindddd5462020-04-07 15:25:44 +0100421 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 Park9918e1a2020-03-17 19:16:40 +0900431 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 Hanssoneec79eb2020-01-10 15:12:39 +0000437 // TODO: remove //apex_available:platform
438 apex_available: [
439 "//apex_available:platform",
440 "myapex",
441 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900442 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900443
444 java_library {
445 name: "myjar",
446 srcs: ["foo/bar/MyClass.java"],
Jiyong Parka62aa232020-05-28 23:46:55 +0900447 stem: "myjar_stem",
Jiyong Park7f7766d2019-07-25 22:02:35 +0900448 sdk_version: "none",
449 system_modules: "none",
Jiyong Park7f7766d2019-07-25 22:02:35 +0900450 static_libs: ["myotherjar"],
Jiyong Park3ff16992019-12-27 14:11:47 +0900451 libs: ["mysharedjar"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000452 // TODO: remove //apex_available:platform
453 apex_available: [
454 "//apex_available:platform",
455 "myapex",
456 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900457 }
458
Jiyong Park77acec62020-06-01 21:39:15 +0900459 dex_import {
460 name: "myjar_dex",
461 jars: ["prebuilt.jar"],
462 apex_available: [
463 "//apex_available:platform",
464 "myapex",
465 ],
466 }
467
Jiyong Park7f7766d2019-07-25 22:02:35 +0900468 java_library {
469 name: "myotherjar",
470 srcs: ["foo/bar/MyClass.java"],
471 sdk_version: "none",
472 system_modules: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +0900473 // TODO: remove //apex_available:platform
474 apex_available: [
475 "//apex_available:platform",
476 "myapex",
477 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900478 }
Jiyong Park3ff16992019-12-27 14:11:47 +0900479
480 java_library {
481 name: "mysharedjar",
482 srcs: ["foo/bar/MyClass.java"],
483 sdk_version: "none",
484 system_modules: "none",
Jiyong Park3ff16992019-12-27 14:11:47 +0900485 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900486 `)
487
Paul Duffina71a67a2021-03-29 00:42:57 +0100488 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900489
Jiyong Park9e83f0b2020-06-11 00:35:03 +0900490 // Make sure that Android.mk is created
491 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Colin Crossaa255532020-07-03 13:18:24 -0700492 data := android.AndroidMkDataForTest(t, ctx, ab)
Jiyong Park9e83f0b2020-06-11 00:35:03 +0900493 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 Park42cca6c2019-04-01 11:15:50 +0900500 optFlags := apexRule.Args["opt_flags"]
501 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700502 // Ensure that the NOTICE output is being packaged as an asset.
Paul Duffin37ba3442021-03-29 00:21:08 +0100503 ensureContains(t, optFlags, "--assets_dir out/soong/.intermediates/myapex/android_common_myapex_image/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900504
Jiyong Park25fc6a92018-11-18 18:02:45 +0900505 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 Crossaede88c2020-08-11 12:17:01 -0700511 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 Park99644e92020-11-17 22:21:02 +0900514 ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000")
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900515 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900516
517 // Ensure that apex variant is created for the indirect dep
Colin Crossaede88c2020-08-11 12:17:01 -0700518 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000")
519 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000")
Jiyong Park99644e92020-11-17 22:21:02 +0900520 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 Parkf2cc1b72020-12-09 00:20:45 +0900522 ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900523
524 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800525 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
526 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Parka62aa232020-05-28 23:46:55 +0900527 ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar")
Jiyong Park77acec62020-06-01 21:39:15 +0900528 ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar")
Jiyong Park99644e92020-11-17 22:21:02 +0900529 ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so")
Jiyong Parkf2cc1b72020-12-09 00:20:45 +0900530 ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so")
531 ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900532 // .. but not for java libs
533 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Jiyong Park3ff16992019-12-27 14:11:47 +0900534 ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800535
Colin Cross7113d202019-11-20 16:39:12 -0800536 // 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 Park7f7766d2019-07-25 22:02:35 +0900539 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
540 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park3ff16992019-12-27 14:11:47 +0900541 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 Light3d673592019-01-18 14:37:31 -0800545
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 Park7cd10e32020-01-14 09:22:18 +0900550 if strings.HasPrefix(cmd, "ln -sfn foo64") {
Alex Light3d673592019-01-18 14:37:31 -0800551 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 Park52818fc2019-03-18 12:01:38 +0900562
Sundong Ahnabb64432019-10-22 13:58:29 +0900563 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700564 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jiyong Park9918e1a2020-03-17 19:16:40 +0900565 if len(noticeInputs) != 3 {
566 t.Errorf("number of input notice files: expected = 3, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900567 }
568 ensureListContains(t, noticeInputs, "NOTICE")
569 ensureListContains(t, noticeInputs, "custom_notice")
Jiyong Park9918e1a2020-03-17 19:16:40 +0900570 ensureListContains(t, noticeInputs, "custom_notice_for_static_lib")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900571
Artur Satayeva8bd1132020-04-27 18:07:06 +0100572 fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n")
Artur Satayev4e1f2bd2020-05-14 15:15:01 +0100573 ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex")
Artur Satayev4e1f2bd2020-05-14 15:15:01 +0100574 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 Satayeva8bd1132020-04-27 18:07:06 +0100577
578 flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n")
Artur Satayev4e1f2bd2020-05-14 15:15:01 +0100579 ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))")
Artur Satayev4e1f2bd2020-05-14 15:15:01 +0100580 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 Light5098a612018-11-29 17:12:15 -0800583}
584
Jooyung Hanf21c7972019-12-16 22:32:06 +0900585func TestDefaults(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -0800586 ctx := testApex(t, `
Jooyung Hanf21c7972019-12-16 22:32:06 +0900587 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 Park69aeba92020-04-24 21:16:36 +0900594 rros: ["rro"],
markchien2f59ec92020-09-02 16:23:38 +0800595 bpfs: ["bpf"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000596 updatable: false,
Jooyung Hanf21c7972019-12-16 22:32:06 +0900597 }
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 Hanssoneec79eb2020-01-10 15:12:39 +0000619 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900620 }
621
622 java_library {
623 name: "myjar",
624 srcs: ["foo/bar/MyClass.java"],
625 sdk_version: "none",
626 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000627 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900628 }
629
630 android_app {
631 name: "AppFoo",
632 srcs: ["foo/bar/MyClass.java"],
633 sdk_version: "none",
634 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000635 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900636 }
Jiyong Park69aeba92020-04-24 21:16:36 +0900637
638 runtime_resource_overlay {
639 name: "rro",
640 theme: "blue",
641 }
642
markchien2f59ec92020-09-02 16:23:38 +0800643 bpf {
644 name: "bpf",
645 srcs: ["bpf.c", "bpf2.c"],
646 }
647
Jooyung Hanf21c7972019-12-16 22:32:06 +0900648 `)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000649 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Hanf21c7972019-12-16 22:32:06 +0900650 "etc/myetc",
651 "javalib/myjar.jar",
652 "lib64/mylib.so",
653 "app/AppFoo/AppFoo.apk",
Jiyong Park69aeba92020-04-24 21:16:36 +0900654 "overlay/blue/rro.apk",
markchien2f59ec92020-09-02 16:23:38 +0800655 "etc/bpf/bpf.o",
656 "etc/bpf/bpf2.o",
Jooyung Hanf21c7972019-12-16 22:32:06 +0900657 })
658}
659
Jooyung Han01a3ee22019-11-02 02:52:25 +0900660func TestApexManifest(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -0800661 ctx := testApex(t, `
Jooyung Han01a3ee22019-11-02 02:52:25 +0900662 apex {
663 name: "myapex",
664 key: "myapex.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000665 updatable: false,
Jooyung Han01a3ee22019-11-02 02:52:25 +0900666 }
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 Han214bf372019-11-12 13:03:50 +0900676 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 Han01a3ee22019-11-02 02:52:25 +0900680}
681
Alex Light5098a612018-11-29 17:12:15 -0800682func TestBasicZipApex(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -0800683 ctx := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800684 apex {
685 name: "myapex",
686 key: "myapex.key",
687 payload_type: "zip",
688 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000689 updatable: false,
Alex Light5098a612018-11-29 17:12:15 -0800690 }
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 Hanssoneec79eb2020-01-10 15:12:39 +0000704 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800705 }
706
707 cc_library {
708 name: "mylib2",
709 srcs: ["mylib.cpp"],
710 system_shared_libs: [],
711 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000712 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800713 }
714 `)
715
Sundong Ahnabb64432019-10-22 13:58:29 +0900716 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
Alex Light5098a612018-11-29 17:12:15 -0800717 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 Crossaede88c2020-08-11 12:17:01 -0700723 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000")
Alex Light5098a612018-11-29 17:12:15 -0800724
725 // Ensure that APEX variant is created for the indirect dep
Colin Crossaede88c2020-08-11 12:17:01 -0700726 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000")
Alex Light5098a612018-11-29 17:12:15 -0800727
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 Park25fc6a92018-11-18 18:02:45 +0900731}
732
733func TestApexWithStubs(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -0800734 ctx := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900735 apex {
736 name: "myapex",
737 key: "myapex.key",
738 native_shared_libs: ["mylib", "mylib3"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000739 updatable: false,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900740 }
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 Hanssoneec79eb2020-01-10 15:12:39 +0000754 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900755 }
756
757 cc_library {
758 name: "mylib2",
759 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900760 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900761 system_shared_libs: [],
762 stl: "none",
763 stubs: {
764 versions: ["1", "2", "3"],
765 },
766 }
767
768 cc_library {
769 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900770 srcs: ["mylib.cpp"],
771 shared_libs: ["mylib4"],
772 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900773 stl: "none",
774 stubs: {
775 versions: ["10", "11", "12"],
776 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000777 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900778 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900779
780 cc_library {
781 name: "mylib4",
782 srcs: ["mylib.cpp"],
783 system_shared_libs: [],
784 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000785 apex_available: [ "myapex" ],
Jiyong Park28d395a2018-12-07 22:42:47 +0900786 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900787 `)
788
Sundong Ahnabb64432019-10-22 13:58:29 +0900789 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900790 copyCmds := apexRule.Args["copy_commands"]
791
792 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800793 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900794
795 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800796 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900797
798 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800799 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900800
Colin Crossaede88c2020-08-11 12:17:01 -0700801 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900802
803 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900804 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900805 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900806 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900807
808 // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
Colin Crossaede88c2020-08-11 12:17:01 -0700809 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900810 // .. and not linking to the stubs variant of mylib3
Colin Crossaede88c2020-08-11 12:17:01 -0700811 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900812
813 // Ensure that stubs libs are built without -include flags
Jiyong Park0f80c182020-01-31 02:49:53 +0900814 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900815 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900816
817 // Ensure that genstub is invoked with --apex
Colin Crossa717db72020-10-23 14:53:06 -0700818 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_3").Rule("genStubSrc").Args["flags"])
Jooyung Han671f1ce2019-12-17 12:47:13 +0900819
Jooyung Hana57af4a2020-01-23 05:36:59 +0000820 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han671f1ce2019-12-17 12:47:13 +0900821 "lib64/mylib.so",
822 "lib64/mylib3.so",
823 "lib64/mylib4.so",
824 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900825}
826
Colin Cross7812fd32020-09-25 12:35:10 -0700827func TestApexWithStubsWithMinSdkVersion(t *testing.T) {
828 t.Parallel()
Colin Cross1c460562021-02-16 17:55:47 -0800829 ctx := testApex(t, `
Colin Cross7812fd32020-09-25 12:35:10 -0700830 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 Park55549df2021-02-26 23:57:23 +0900902 // 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 Cross7812fd32020-09-25 12:35:10 -0700904 // ... 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 Crossa717db72020-10-23 14:53:06 -0700913 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("cc").Args["cFlags"]
Colin Cross7812fd32020-09-25 12:35:10 -0700914 ensureNotContains(t, mylib2Cflags, "-include ")
915
916 // Ensure that genstub is invoked with --apex
Colin Crossa717db72020-10-23 14:53:06 -0700917 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("genStubSrc").Args["flags"])
Colin Cross7812fd32020-09-25 12:35:10 -0700918
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 Han11b0fbd2021-02-05 02:28:22 +0900926func 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 Cross1c460562021-02-16 17:55:47 -0800936 ctx := testApex(t, `
Jooyung Han11b0fbd2021-02-05 02:28:22 +0900937 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 Duffin0a49fdc2021-03-08 11:28:25 +0000981 `,
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 Han11b0fbd2021-02-05 02:28:22 +0900988
Jiyong Park55549df2021-02-26 23:57:23 +0900989 // Ensure that mylib from myapex is built against the latest stub (current)
Jooyung Han11b0fbd2021-02-05 02:28:22 +0900990 mylibCflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"]
Jiyong Park55549df2021-02-26 23:57:23 +0900991 ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=10000 ")
Jooyung Han11b0fbd2021-02-05 02:28:22 +0900992 mylibLdflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"]
Jiyong Park55549df2021-02-26 23:57:23 +0900993 ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ")
Jooyung Han11b0fbd2021-02-05 02:28:22 +0900994
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 Park0ddfcd12018-12-11 01:35:25 +09001002func TestApexWithExplicitStubsDependency(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08001003 ctx := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001004 apex {
Jiyong Park83dc74b2020-01-14 18:38:44 +09001005 name: "myapex2",
1006 key: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001007 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001008 updatable: false,
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001009 }
1010
1011 apex_key {
Jiyong Park83dc74b2020-01-14 18:38:44 +09001012 name: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001013 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 Park678c8812020-02-07 17:25:49 +09001021 static_libs: ["libbaz"],
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001022 system_shared_libs: [],
1023 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001024 apex_available: [ "myapex2" ],
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001025 }
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 Park678c8812020-02-07 17:25:49 +09001045 cc_library_static {
1046 name: "libbaz",
1047 srcs: ["mylib.cpp"],
1048 system_shared_libs: [],
1049 stl: "none",
1050 apex_available: [ "myapex2" ],
1051 }
1052
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001053 `)
1054
Jiyong Park83dc74b2020-01-14 18:38:44 +09001055 apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule")
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001056 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 Crossaede88c2020-08-11 12:17:01 -07001067 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001068
1069 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +09001070 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001071 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +09001072 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001073
Jiyong Park3ff16992019-12-27 14:11:47 +09001074 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001075
1076 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
1077 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
Jiyong Park83dc74b2020-01-14 18:38:44 +09001078
Artur Satayeva8bd1132020-04-27 18:07:06 +01001079 fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n")
Artur Satayev4e1f2bd2020-05-14 15:15:01 +01001080 ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib")
Jiyong Park678c8812020-02-07 17:25:49 +09001081
Artur Satayeva8bd1132020-04-27 18:07:06 +01001082 flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n")
Artur Satayev4e1f2bd2020-05-14 15:15:01 +01001083 ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)")
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001084}
1085
Jooyung Hand3639552019-08-09 12:57:43 +09001086func TestApexWithRuntimeLibsDependency(t *testing.T) {
1087 /*
1088 myapex
1089 |
1090 v (runtime_libs)
1091 mylib ------+------> libfoo [provides stub]
1092 |
1093 `------> libbar
1094 */
Colin Cross1c460562021-02-16 17:55:47 -08001095 ctx := testApex(t, `
Jooyung Hand3639552019-08-09 12:57:43 +09001096 apex {
1097 name: "myapex",
1098 key: "myapex.key",
1099 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001100 updatable: false,
Jooyung Hand3639552019-08-09 12:57:43 +09001101 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00001115 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +09001116 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00001133 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +09001134 }
1135
1136 `)
1137
Sundong Ahnabb64432019-10-22 13:58:29 +09001138 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Hand3639552019-08-09 12:57:43 +09001139 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 Ahnabb64432019-10-22 13:58:29 +09001150 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001151 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
1152 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +09001153
1154}
1155
Paul Duffina02cae32021-03-09 01:44:06 +00001156var prepareForTestOfRuntimeApexWithHwasan = android.GroupFixturePreparers(
1157 cc.PrepareForTestWithCcBuildComponents,
1158 PrepareForTestWithApexBuildComponents,
1159 android.FixtureAddTextFile("bionic/apex/Android.bp", `
Jooyung Han8ce8db92020-05-15 19:05:05 +09001160 apex {
1161 name: "com.android.runtime",
1162 key: "com.android.runtime.key",
1163 native_shared_libs: ["libc"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001164 updatable: false,
Jooyung Han8ce8db92020-05-15 19:05:05 +09001165 }
1166
1167 apex_key {
1168 name: "com.android.runtime.key",
1169 public_key: "testkey.avbpubkey",
1170 private_key: "testkey.pem",
1171 }
Paul Duffina02cae32021-03-09 01:44:06 +00001172 `),
1173 android.FixtureAddFile("system/sepolicy/apex/com.android.runtime-file_contexts", nil),
1174)
Jooyung Han8ce8db92020-05-15 19:05:05 +09001175
Paul Duffina02cae32021-03-09 01:44:06 +00001176func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) {
Paul Duffin70d3bee2021-03-21 11:26:05 +00001177 result := android.GroupFixturePreparers(prepareForTestOfRuntimeApexWithHwasan).RunTestWithBp(t, `
Jooyung Han8ce8db92020-05-15 19:05:05 +09001178 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 Duffina02cae32021-03-09 01:44:06 +00001204 } `)
1205 ctx := result.TestContext
Jooyung Han8ce8db92020-05-15 19:05:05 +09001206
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
1222func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) {
Paul Duffin70d3bee2021-03-21 11:26:05 +00001223 result := android.GroupFixturePreparers(
Paul Duffina02cae32021-03-09 01:44:06 +00001224 prepareForTestOfRuntimeApexWithHwasan,
1225 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1226 variables.SanitizeDevice = []string{"hwaddress"}
1227 }),
1228 ).RunTestWithBp(t, `
Jooyung Han8ce8db92020-05-15 19:05:05 +09001229 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 Duffina02cae32021-03-09 01:44:06 +00001252 `)
1253 ctx := result.TestContext
Jooyung Han8ce8db92020-05-15 19:05:05 +09001254
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 Han61b66e92020-03-21 14:21:46 +00001270func TestApexDependsOnLLNDKTransitively(t *testing.T) {
1271 testcases := []struct {
1272 name string
1273 minSdkVersion string
Colin Crossaede88c2020-08-11 12:17:01 -07001274 apexVariant string
Jooyung Han61b66e92020-03-21 14:21:46 +00001275 shouldLink string
1276 shouldNotLink []string
1277 }{
1278 {
Jiyong Park55549df2021-02-26 23:57:23 +09001279 name: "unspecified version links to the latest",
Jooyung Han749dc692020-04-15 11:03:39 +09001280 minSdkVersion: "",
Colin Crossaede88c2020-08-11 12:17:01 -07001281 apexVariant: "apex10000",
Jooyung Han61b66e92020-03-21 14:21:46 +00001282 shouldLink: "30",
1283 shouldNotLink: []string{"29"},
1284 },
1285 {
Jiyong Park55549df2021-02-26 23:57:23 +09001286 name: "always use the latest",
Jooyung Han749dc692020-04-15 11:03:39 +09001287 minSdkVersion: "min_sdk_version: \"29\",",
Colin Crossaede88c2020-08-11 12:17:01 -07001288 apexVariant: "apex29",
Jiyong Park55549df2021-02-26 23:57:23 +09001289 shouldLink: "30",
1290 shouldNotLink: []string{"29"},
Jooyung Han61b66e92020-03-21 14:21:46 +00001291 },
1292 }
1293 for _, tc := range testcases {
1294 t.Run(tc.name, func(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08001295 ctx := testApex(t, `
Jooyung Han61b66e92020-03-21 14:21:46 +00001296 apex {
1297 name: "myapex",
1298 key: "myapex.key",
1299 use_vendor: true,
1300 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001301 updatable: false,
Jooyung Han749dc692020-04-15 11:03:39 +09001302 `+tc.minSdkVersion+`
Jooyung Han61b66e92020-03-21 14:21:46 +00001303 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001304
Jooyung Han61b66e92020-03-21 14:21:46 +00001305 apex_key {
1306 name: "myapex.key",
1307 public_key: "testkey.avbpubkey",
1308 private_key: "testkey.pem",
1309 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001310
Jooyung Han61b66e92020-03-21 14:21:46 +00001311 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 Han749dc692020-04-15 11:03:39 +09001319 min_sdk_version: "29",
Jooyung Han61b66e92020-03-21 14:21:46 +00001320 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001321
Jooyung Han61b66e92020-03-21 14:21:46 +00001322 cc_library {
1323 name: "libbar",
1324 srcs: ["mylib.cpp"],
1325 system_shared_libs: [],
1326 stl: "none",
1327 stubs: { versions: ["29","30"] },
Colin Cross0477b422020-10-13 18:43:54 -07001328 llndk_stubs: "libbar.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00001329 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001330
Jooyung Han61b66e92020-03-21 14:21:46 +00001331 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001332 name: "libbar.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00001333 symbol_file: "",
1334 }
Paul Duffin0a49fdc2021-03-08 11:28:25 +00001335 `,
1336 setUseVendorAllowListForTest([]string{"myapex"}),
1337 withUnbundledBuild,
1338 )
Jooyung Han9c80bae2019-08-20 17:30:57 +09001339
Jooyung Han61b66e92020-03-21 14:21:46 +00001340 // Ensure that LLNDK dep is not included
1341 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
1342 "lib64/mylib.so",
1343 })
Jooyung Han9c80bae2019-08-20 17:30:57 +09001344
Jooyung Han61b66e92020-03-21 14:21:46 +00001345 // 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 Han9c80bae2019-08-20 17:30:57 +09001349
Colin Crossaede88c2020-08-11 12:17:01 -07001350 mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"]
Colin Cross127bb8b2020-12-16 16:46:01 -08001351 ensureContains(t, mylibLdFlags, "libbar/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so")
Jooyung Han61b66e92020-03-21 14:21:46 +00001352 for _, ver := range tc.shouldNotLink {
Colin Cross127bb8b2020-12-16 16:46:01 -08001353 ensureNotContains(t, mylibLdFlags, "libbar/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so")
Jooyung Han61b66e92020-03-21 14:21:46 +00001354 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001355
Colin Crossaede88c2020-08-11 12:17:01 -07001356 mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_"+tc.apexVariant).Rule("cc").Args["cFlags"]
Jooyung Han61b66e92020-03-21 14:21:46 +00001357 ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink)
1358 })
1359 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09001360}
1361
Jiyong Park25fc6a92018-11-18 18:02:45 +09001362func TestApexWithSystemLibsStubs(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08001363 ctx := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +09001364 apex {
1365 name: "myapex",
1366 key: "myapex.key",
1367 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001368 updatable: false,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001369 }
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 Cross0de8a1e2020-09-18 14:15:30 -07001380 system_shared_libs: ["libc", "libm"],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001381 shared_libs: ["libdl#27"],
1382 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001383 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001384 }
1385
1386 cc_library_shared {
1387 name: "mylib_shared",
1388 srcs: ["mylib.cpp"],
1389 shared_libs: ["libdl#27"],
1390 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001391 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001392 }
1393
1394 cc_library {
Jiyong Parkb0788572018-12-20 22:10:17 +09001395 name: "libBootstrap",
1396 srcs: ["mylib.cpp"],
1397 stl: "none",
1398 bootstrap: true,
1399 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001400 `)
1401
Sundong Ahnabb64432019-10-22 13:58:29 +09001402 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001403 copyCmds := apexRule.Args["copy_commands"]
1404
1405 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -08001406 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +09001407 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
1408 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001409
1410 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +09001411 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001412
Colin Crossaede88c2020-08-11 12:17:01 -07001413 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 Park25fc6a92018-11-18 18:02:45 +09001416
1417 // For dependency to libc
1418 // Ensure that mylib is linking with the latest version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001419 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001420 // ... and not linking to the non-stub (impl) variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001421 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001422 // ... 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 Crossaede88c2020-08-11 12:17:01 -07001428 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001429 // ... and not linking to the stub variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001430 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001431 // ... 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 Park3ff16992019-12-27 14:11:47 +09001437 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001438 // ... and not linking to the other versions of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001439 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 Park25fc6a92018-11-18 18:02:45 +09001441 // ... and not linking to the non-stub (impl) variant
Colin Crossaede88c2020-08-11 12:17:01 -07001442 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001443 // ... Cflags from stub is correctly exported to mylib
1444 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
1445 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +09001446
1447 // Ensure that libBootstrap is depending on the platform variant of bionic libs
Colin Cross7113d202019-11-20 16:39:12 -08001448 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 Park25fc6a92018-11-18 18:02:45 +09001452}
Jiyong Park7c2ee712018-12-07 00:42:25 +09001453
Jooyung Han749dc692020-04-15 11:03:39 +09001454func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) {
Jiyong Park55549df2021-02-26 23:57:23 +09001455 // there are three links between liba --> libz.
1456 // 1) myapex -> libx -> liba -> libz : this should be #30 link
Jooyung Han749dc692020-04-15 11:03:39 +09001457 // 2) otherapex -> liby -> liba -> libz : this should be #30 link
Jooyung Han03b51852020-02-26 22:45:42 +09001458 // 3) (platform) -> liba -> libz : this should be non-stub link
Colin Cross1c460562021-02-16 17:55:47 -08001459 ctx := testApex(t, `
Jooyung Han03b51852020-02-26 22:45:42 +09001460 apex {
1461 name: "myapex",
1462 key: "myapex.key",
1463 native_shared_libs: ["libx"],
Jooyung Han749dc692020-04-15 11:03:39 +09001464 min_sdk_version: "29",
Jooyung Han03b51852020-02-26 22:45:42 +09001465 }
1466
1467 apex {
1468 name: "otherapex",
1469 key: "myapex.key",
1470 native_shared_libs: ["liby"],
Jooyung Han749dc692020-04-15 11:03:39 +09001471 min_sdk_version: "30",
Jooyung Han03b51852020-02-26 22:45:42 +09001472 }
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 Han749dc692020-04-15 11:03:39 +09001486 min_sdk_version: "29",
Jooyung Han03b51852020-02-26 22:45:42 +09001487 }
1488
1489 cc_library {
1490 name: "liby",
1491 shared_libs: ["liba"],
1492 system_shared_libs: [],
1493 stl: "none",
1494 apex_available: [ "otherapex" ],
Jooyung Han749dc692020-04-15 11:03:39 +09001495 min_sdk_version: "29",
Jooyung Han03b51852020-02-26 22:45:42 +09001496 }
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 Han749dc692020-04-15 11:03:39 +09001507 min_sdk_version: "29",
Jooyung Han03b51852020-02-26 22:45:42 +09001508 }
1509
1510 cc_library {
1511 name: "libz",
1512 system_shared_libs: [],
1513 stl: "none",
1514 stubs: {
Jooyung Han749dc692020-04-15 11:03:39 +09001515 versions: ["28", "30"],
Jooyung Han03b51852020-02-26 22:45:42 +09001516 },
1517 }
Jooyung Han749dc692020-04-15 11:03:39 +09001518 `)
Jooyung Han03b51852020-02-26 22:45:42 +09001519
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 Park55549df2021-02-26 23:57:23 +09001530 // liba in myapex is linked to #30
1531 expectLink("liba", "shared_apex29", "libz", "shared_30")
1532 expectNoLink("liba", "shared_apex29", "libz", "shared_28")
Colin Crossaede88c2020-08-11 12:17:01 -07001533 expectNoLink("liba", "shared_apex29", "libz", "shared")
Jooyung Han749dc692020-04-15 11:03:39 +09001534 // liba in otherapex is linked to #30
Colin Crossaede88c2020-08-11 12:17:01 -07001535 expectLink("liba", "shared_apex30", "libz", "shared_30")
1536 expectNoLink("liba", "shared_apex30", "libz", "shared_28")
1537 expectNoLink("liba", "shared_apex30", "libz", "shared")
Jooyung Han03b51852020-02-26 22:45:42 +09001538}
1539
Jooyung Hanaed150d2020-04-02 01:41:41 +09001540func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08001541 ctx := testApex(t, `
Jooyung Hanaed150d2020-04-02 01:41:41 +09001542 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 Han749dc692020-04-15 11:03:39 +09001561 min_sdk_version: "R",
Jooyung Hanaed150d2020-04-02 01:41:41 +09001562 }
1563
1564 cc_library {
1565 name: "libz",
1566 system_shared_libs: [],
1567 stl: "none",
1568 stubs: {
1569 versions: ["29", "R"],
1570 },
1571 }
Paul Duffin0a49fdc2021-03-08 11:28:25 +00001572 `,
1573 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1574 variables.Platform_version_active_codenames = []string{"R"}
1575 }),
1576 )
Jooyung Hanaed150d2020-04-02 01:41:41 +09001577
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 Albertc8060532020-07-22 22:32:17 -07001586 expectLink("libx", "shared_apex10000", "libz", "shared_R")
Colin Crossaede88c2020-08-11 12:17:01 -07001587 expectNoLink("libx", "shared_apex10000", "libz", "shared_29")
1588 expectNoLink("libx", "shared_apex10000", "libz", "shared")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001589}
1590
Jooyung Han749dc692020-04-15 11:03:39 +09001591func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08001592 ctx := testApex(t, `
Jooyung Han03b51852020-02-26 22:45:42 +09001593 apex {
1594 name: "myapex",
1595 key: "myapex.key",
1596 native_shared_libs: ["libx"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001597 updatable: false,
Jooyung Han03b51852020-02-26 22:45:42 +09001598 }
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 Crossaede88c2020-08-11 12:17:01 -07001632 expectLink("libx", "shared_apex10000", "libz", "shared_2")
1633 expectNoLink("libx", "shared_apex10000", "libz", "shared_1")
1634 expectNoLink("libx", "shared_apex10000", "libz", "shared")
Jooyung Han03b51852020-02-26 22:45:42 +09001635}
1636
1637func TestPlatformUsesLatestStubsFromApexes(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08001638 ctx := testApex(t, `
Jooyung Han03b51852020-02-26 22:45:42 +09001639 apex {
1640 name: "myapex",
1641 key: "myapex.key",
1642 native_shared_libs: ["libx"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00001643 updatable: false,
Jooyung Han03b51852020-02-26 22:45:42 +09001644 }
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 Cross56a83212020-09-15 18:30:11 -07001671 t.Helper()
Jooyung Han03b51852020-02-26 22:45:42 +09001672 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 Cross56a83212020-09-15 18:30:11 -07001676 t.Helper()
Jooyung Han03b51852020-02-26 22:45:42 +09001677 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 Duffin0a49fdc2021-03-08 11:28:25 +00001685var prepareForTestWithSantitizeHwaddress = android.FixtureModifyProductVariables(
1686 func(variables android.FixtureProductVariables) {
1687 variables.SanitizeDevice = []string{"hwaddress"}
1688 },
1689)
1690
Jooyung Han75568392020-03-20 04:29:24 +09001691func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08001692 ctx := testApex(t, `
Jooyung Han03b51852020-02-26 22:45:42 +09001693 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 Han749dc692020-04-15 11:03:39 +09001710 min_sdk_version: "29",
Jooyung Han03b51852020-02-26 22:45:42 +09001711 }
1712
1713 cc_library {
1714 name: "libbar",
1715 stubs: {
1716 versions: ["29", "30"],
1717 },
1718 }
Paul Duffin0a49fdc2021-03-08 11:28:25 +00001719 `,
1720 prepareForTestWithSantitizeHwaddress,
1721 )
Jooyung Han03b51852020-02-26 22:45:42 +09001722 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 Crossaede88c2020-08-11 12:17:01 -07001727 expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_30")
Jooyung Han03b51852020-02-26 22:45:42 +09001728}
1729
Jooyung Han75568392020-03-20 04:29:24 +09001730func TestQTargetApexUsesStaticUnwinder(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08001731 ctx := testApex(t, `
Jooyung Han03b51852020-02-26 22:45:42 +09001732 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 Han749dc692020-04-15 11:03:39 +09001748 min_sdk_version: "29",
Jooyung Han03b51852020-02-26 22:45:42 +09001749 }
Jooyung Han75568392020-03-20 04:29:24 +09001750 `)
Jooyung Han03b51852020-02-26 22:45:42 +09001751
1752 // ensure apex variant of c++ is linked with static unwinder
Colin Crossaede88c2020-08-11 12:17:01 -07001753 cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_apex29").Module().(*cc.Module)
Ryan Prichardb35a85e2021-01-13 19:18:53 -08001754 ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind")
Jooyung Han03b51852020-02-26 22:45:42 +09001755 // note that platform variant is not.
1756 cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Ryan Prichardb35a85e2021-01-13 19:18:53 -08001757 ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind")
Jooyung Han03b51852020-02-26 22:45:42 +09001758}
1759
Jooyung Han749dc692020-04-15 11:03:39 +09001760func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) {
1761 testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, `
Jooyung Han03b51852020-02-26 22:45:42 +09001762 apex {
1763 name: "myapex",
1764 key: "myapex.key",
Jooyung Han749dc692020-04-15 11:03:39 +09001765 native_shared_libs: ["mylib"],
1766 min_sdk_version: "29",
Jooyung Han03b51852020-02-26 22:45:42 +09001767 }
1768
1769 apex_key {
1770 name: "myapex.key",
1771 public_key: "testkey.avbpubkey",
1772 private_key: "testkey.pem",
1773 }
Jooyung Han749dc692020-04-15 11:03:39 +09001774
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 Lozano3e9f9e42020-12-04 15:05:43 -05001786
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 Jung6d15d632021-03-31 11:58:46 -07001811
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 Han749dc692020-04-15 11:03:39 +09001835}
1836
1837func 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 Jung6d15d632021-03-31 11:58:46 -07001872 static_libs: [
1873 "libbar_dep",
1874 "libbar_import_dep",
1875 ],
Jooyung Han749dc692020-04-15 11:03:39 +09001876 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 Jung6d15d632021-03-31 11:58:46 -07001887
1888 java_import {
1889 name: "libbar_import_dep",
1890 jars: ["libbar.jar"],
1891 apex_available: ["myapex"],
1892 min_sdk_version: "29",
1893 }
Jooyung Han03b51852020-02-26 22:45:42 +09001894 `)
1895}
1896
Artur Satayev8cf899a2020-04-15 17:29:42 +01001897func 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 Inwoodf8dcf5e2021-02-16 11:40:16 +00001910 updatable: false,
Artur Satayev8cf899a2020-04-15 17:29:42 +01001911 }
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 Duffin043f5e72021-03-05 00:00:01 +00001920 sdk_version: "test_current",
Artur Satayev8cf899a2020-04-15 17:29:42 +01001921 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 Han749dc692020-04-15 11:03:39 +09001945 min_sdk_version: "29",
Artur Satayev8cf899a2020-04-15 17:29:42 +01001946 }
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 Duffin043f5e72021-03-05 00:00:01 +00001967 sdk_version: "test_current",
Artur Satayev8cf899a2020-04-15 17:29:42 +01001968 apex_available: ["myapex"],
1969 }
1970 `,
1971 },
1972 {
Paul Duffin043f5e72021-03-05 00:00:01 +00001973 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 Park670e0f62021-02-18 13:10:18 +09001977 expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against private API.",
Artur Satayev8cf899a2020-04-15 17:29:42 +01001978 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 Han749dc692020-04-15 11:03:39 +09002018func 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
2059func 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
2094func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002095 ctx := testApex(t, `
Jooyung Han749dc692020-04-15 11:03:39 +09002096 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 Park55549df2021-02-26 23:57:23 +09002109 // mylib in myapex will link to mylib2#30
Jooyung Han749dc692020-04-15 11:03:39 +09002110 // 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 Park55549df2021-02-26 23:57:23 +09002143 expectLink("mylib", "shared_apex29", "mylib2", "shared_30")
Colin Crossaede88c2020-08-11 12:17:01 -07002144 expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30")
Jooyung Han749dc692020-04-15 11:03:39 +09002145}
2146
Jooyung Haned124c32021-01-26 11:43:46 +09002147func TestApexMinSdkVersion_WorksWithSdkCodename(t *testing.T) {
Paul Duffin0a49fdc2021-03-08 11:28:25 +00002148 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 Haned124c32021-01-26 11:43:46 +09002154 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
2179func TestApexMinSdkVersion_WorksWithActiveCodenames(t *testing.T) {
Paul Duffin0a49fdc2021-03-08 11:28:25 +00002180 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 Cross1c460562021-02-16 17:55:47 -08002184 ctx := testApex(t, `
Jooyung Haned124c32021-01-26 11:43:46 +09002185 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 Park55549df2021-02-26 23:57:23 +09002214 ensureContains(t, libFlags, "android_arm64_armv8-a_shared_T/libbar.so")
Jooyung Haned124c32021-01-26 11:43:46 +09002215}
2216
Jiyong Park7c2ee712018-12-07 00:42:25 +09002217func TestFilesInSubDir(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002218 ctx := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +09002219 apex {
2220 name: "myapex",
2221 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +09002222 native_shared_libs: ["mylib"],
2223 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +09002224 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09002225 compile_multilib: "both",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002226 updatable: false,
Jiyong Park7c2ee712018-12-07 00:42:25 +09002227 }
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 Parkb7c24df2019-02-01 12:03:59 +09002240
2241 cc_library {
2242 name: "mylib",
2243 srcs: ["mylib.cpp"],
2244 relative_install_path: "foo/bar",
2245 system_shared_libs: [],
2246 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002247 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09002248 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00002257 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09002258 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09002259 `)
2260
Sundong Ahnabb64432019-10-22 13:58:29 +09002261 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09002262 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
2263
Jiyong Parkb7c24df2019-02-01 12:03:59 +09002264 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09002265 ensureListContains(t, dirs, "etc")
2266 ensureListContains(t, dirs, "etc/foo")
2267 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09002268 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 Parkbd13e442019-03-15 18:10:35 +09002275 ensureListContains(t, dirs, "bin")
2276 ensureListContains(t, dirs, "bin/foo")
2277 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09002278}
Jiyong Parkda6eb592018-12-19 17:12:36 +09002279
Jooyung Han35155c42020-02-06 17:33:20 +09002280func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002281 ctx := testApex(t, `
Jooyung Han35155c42020-02-06 17:33:20 +09002282 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 Inwoodf8dcf5e2021-02-16 11:40:16 +00002293 updatable: false,
Jooyung Han35155c42020-02-06 17:33:20 +09002294 }
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 Parkda6eb592018-12-19 17:12:36 +09002339func TestUseVendor(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002340 ctx := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09002341 apex {
2342 name: "myapex",
2343 key: "myapex.key",
2344 native_shared_libs: ["mylib"],
2345 use_vendor: true,
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002346 updatable: false,
Jiyong Parkda6eb592018-12-19 17:12:36 +09002347 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00002362 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09002363 }
2364
2365 cc_library {
2366 name: "mylib2",
2367 srcs: ["mylib.cpp"],
2368 system_shared_libs: [],
2369 vendor_available: true,
2370 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002371 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09002372 }
Paul Duffin0a49fdc2021-03-08 11:28:25 +00002373 `,
2374 setUseVendorAllowListForTest([]string{"myapex"}),
2375 )
Jiyong Parkda6eb592018-12-19 17:12:36 +09002376
2377 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09002378 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09002379 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 Crossaede88c2020-08-11 12:17:01 -07002386 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 Parkda6eb592018-12-19 17:12:36 +09002388
2389 // ensure that the apex does not include core variants
Colin Crossaede88c2020-08-11 12:17:01 -07002390 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib.so")
2391 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09002392}
Jiyong Park16e91a02018-12-20 18:18:08 +09002393
Jooyung Han85d61762020-06-24 23:50:26 +09002394func TestUseVendorNotAllowedForSystemApexes(t *testing.T) {
Jooyung Handc782442019-11-01 03:14:38 +09002395 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 Duffin0a49fdc2021-03-08 11:28:25 +00002406 `,
2407 setUseVendorAllowListForTest([]string{""}),
2408 )
Colin Cross440e0d02020-06-11 11:32:11 -07002409 // no error with allow list
Jooyung Handc782442019-11-01 03:14:38 +09002410 testApex(t, `
2411 apex {
2412 name: "myapex",
2413 key: "myapex.key",
2414 use_vendor: true,
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002415 updatable: false,
Jooyung Handc782442019-11-01 03:14:38 +09002416 }
2417 apex_key {
2418 name: "myapex.key",
2419 public_key: "testkey.avbpubkey",
2420 private_key: "testkey.pem",
2421 }
Paul Duffin0a49fdc2021-03-08 11:28:25 +00002422 `,
2423 setUseVendorAllowListForTest([]string{"myapex"}),
2424 )
Jooyung Handc782442019-11-01 03:14:38 +09002425}
2426
Jooyung Han5c998b92019-06-27 11:30:33 +09002427func 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 Inwoodf8dcf5e2021-02-16 11:40:16 +00002434 updatable: false,
Jooyung Han5c998b92019-06-27 11:30:33 +09002435 }
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 Han85d61762020-06-24 23:50:26 +09002452func TestVendorApex(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002453 ctx := testApex(t, `
Jooyung Han85d61762020-06-24 23:50:26 +09002454 apex {
2455 name: "myapex",
2456 key: "myapex.key",
2457 binaries: ["mybin"],
2458 vendor: true,
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002459 updatable: false,
Jooyung Han85d61762020-06-24 23:50:26 +09002460 }
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 Crossaa255532020-07-03 13:18:24 -07002485 data := android.AndroidMkDataForTest(t, ctx, apexBundle)
Jooyung Han85d61762020-06-24 23:50:26 +09002486 name := apexBundle.BaseModuleName()
2487 prefix := "TARGET_"
2488 var builder strings.Builder
2489 data.Custom(&builder, name, prefix, "", data)
Paul Duffin37ba3442021-03-29 00:21:08 +01002490 androidMk := android.StringRelativeToTop(ctx.Config(), builder.String())
2491 installPath := "out/target/product/test_device/vendor/apex"
Lukacs T. Berki7690c092021-02-26 14:27:36 +01002492 ensureContains(t, androidMk, "LOCAL_MODULE_PATH := "+installPath)
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002493
2494 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
2495 requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"])
2496 ensureListNotContains(t, requireNativeLibs, ":vndk")
Jooyung Han85d61762020-06-24 23:50:26 +09002497}
2498
Jooyung Handf78e212020-07-22 15:54:47 +09002499func TestVendorApex_use_vndk_as_stable(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002500 ctx := testApex(t, `
Jooyung Handf78e212020-07-22 15:54:47 +09002501 apex {
2502 name: "myapex",
2503 key: "myapex.key",
2504 binaries: ["mybin"],
2505 vendor: true,
2506 use_vndk_as_stable: true,
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002507 updatable: false,
Jooyung Handf78e212020-07-22 15:54:47 +09002508 }
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 Yun63e9ec72020-10-29 16:49:43 +09002525 product_available: true,
Jooyung Handf78e212020-07-22 15:54:47 +09002526 }
2527 cc_library {
2528 name: "libvendor",
2529 vendor: true,
2530 }
2531 `)
2532
2533 vendorVariant := "android_vendor.VER_arm64_armv8-a"
2534
Paul Duffina71a67a2021-03-29 00:42:57 +01002535 ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_apex10000").Rule("ld")
Jooyung Handf78e212020-07-22 15:54:47 +09002536 libs := names(ldRule.Args["libFlags"])
2537 // VNDK libs(libvndk/libc++) as they are
Paul Duffin37ba3442021-03-29 00:21:08 +01002538 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 Handf78e212020-07-22 15:54:47 +09002540 // non-stable Vendor libs as APEX variants
Paul Duffin37ba3442021-03-29 00:21:08 +01002541 ensureListContains(t, libs, "out/soong/.intermediates/libvendor/"+vendorVariant+"_shared_apex10000/libvendor.so")
Jooyung Handf78e212020-07-22 15:54:47 +09002542
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 Han6c4cc9c2020-07-29 16:00:54 +09002548
2549 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
2550 requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"])
2551 ensureListContains(t, requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002552}
2553
Justin Yun13decfb2021-03-08 19:25:55 +09002554func 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 Duffin0a49fdc2021-03-08 11:28:25 +00002576 `, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
2577 variables.ProductVndkVersion = proptools.StringPtr("current")
2578 }),
2579 )
Justin Yun13decfb2021-03-08 19:25:55 +09002580
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 Han8e5685d2020-09-21 11:02:57 +09002589func 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 Cross1c460562021-02-16 17:55:47 -08002599 ctx := testApex(t, `
Jooyung Han8e5685d2020-09-21 11:02:57 +09002600 apex {
2601 name: "myapex",
2602 key: "myapex.key",
2603 prebuilts: ["myfirmware"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002604 updatable: false,
Jooyung Han8e5685d2020-09-21 11:02:57 +09002605 `+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 Han0703fd82020-08-26 22:11:53 +09002624}
2625
Jooyung Hanefb184e2020-06-25 17:14:25 +09002626func TestAndroidMk_UseVendorRequired(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002627 ctx := testApex(t, `
Jooyung Hanefb184e2020-06-25 17:14:25 +09002628 apex {
2629 name: "myapex",
2630 key: "myapex.key",
2631 use_vendor: true,
2632 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002633 updatable: false,
Jooyung Hanefb184e2020-06-25 17:14:25 +09002634 }
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 Duffin0a49fdc2021-03-08 11:28:25 +00002647 `,
2648 setUseVendorAllowListForTest([]string{"myapex"}),
2649 )
Jooyung Hanefb184e2020-06-25 17:14:25 +09002650
2651 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Colin Crossaa255532020-07-03 13:18:24 -07002652 data := android.AndroidMkDataForTest(t, ctx, apexBundle)
Jooyung Hanefb184e2020-06-25 17:14:25 +09002653 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
2661func TestAndroidMk_VendorApexRequired(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002662 ctx := testApex(t, `
Jooyung Hanefb184e2020-06-25 17:14:25 +09002663 apex {
2664 name: "myapex",
2665 key: "myapex.key",
2666 vendor: true,
2667 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002668 updatable: false,
Jooyung Hanefb184e2020-06-25 17:14:25 +09002669 }
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 Crossaa255532020-07-03 13:18:24 -07002684 data := android.AndroidMkDataForTest(t, ctx, apexBundle)
Jooyung Hanefb184e2020-06-25 17:14:25 +09002685 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 Han2ed99d02020-06-24 23:26:26 +09002693func TestAndroidMkWritesCommonProperties(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002694 ctx := testApex(t, `
Jooyung Han2ed99d02020-06-24 23:26:26 +09002695 apex {
2696 name: "myapex",
2697 key: "myapex.key",
2698 vintf_fragments: ["fragment.xml"],
2699 init_rc: ["init.rc"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002700 updatable: false,
Jooyung Han2ed99d02020-06-24 23:26:26 +09002701 }
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 Crossaa255532020-07-03 13:18:24 -07002713 data := android.AndroidMkDataForTest(t, ctx, apexBundle)
Jooyung Han2ed99d02020-06-24 23:26:26 +09002714 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 Park16e91a02018-12-20 18:18:08 +09002723func TestStaticLinking(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002724 ctx := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09002725 apex {
2726 name: "myapex",
2727 key: "myapex.key",
2728 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002729 updatable: false,
Jiyong Park16e91a02018-12-20 18:18:08 +09002730 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00002746 apex_available: [
2747 "//apex_available:platform",
2748 "myapex",
2749 ],
Jiyong Park16e91a02018-12-20 18:18:08 +09002750 }
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 Park16e91a02018-12-20 18:18:08 +09002760 `)
2761
Colin Cross7113d202019-11-20 16:39:12 -08002762 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
Jiyong Park16e91a02018-12-20 18:18:08 +09002763
2764 // Ensure that not_in_apex is linking with the static variant of mylib
Colin Cross7113d202019-11-20 16:39:12 -08002765 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09002766}
Jiyong Park9335a262018-12-24 11:31:58 +09002767
2768func TestKeys(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002769 ctx := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09002770 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09002771 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09002772 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09002773 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09002774 native_shared_libs: ["mylib"],
Jooyung Han54aca7b2019-11-20 02:26:02 +09002775 file_contexts: ":myapex-file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002776 updatable: false,
Jiyong Park9335a262018-12-24 11:31:58 +09002777 }
2778
2779 cc_library {
2780 name: "mylib",
2781 srcs: ["mylib.cpp"],
2782 system_shared_libs: [],
2783 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002784 apex_available: [ "myapex_keytest" ],
Jiyong Park9335a262018-12-24 11:31:58 +09002785 }
2786
2787 apex_key {
2788 name: "myapex.key",
2789 public_key: "testkey.avbpubkey",
2790 private_key: "testkey.pem",
2791 }
2792
Jiyong Parkb2742fd2019-02-11 11:38:15 +09002793 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 Park9335a262018-12-24 11:31:58 +09002803 `)
2804
2805 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002806 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09002807
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002808 if keys.publicKeyFile.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
2809 t.Errorf("public key %q is not %q", keys.publicKeyFile.String(),
Jiyong Park9335a262018-12-24 11:31:58 +09002810 "vendor/foo/devkeys/testkey.avbpubkey")
2811 }
Jaewoong Jung18aefc12020-12-21 09:11:10 -08002812 if keys.privateKeyFile.String() != "vendor/foo/devkeys/testkey.pem" {
2813 t.Errorf("private key %q is not %q", keys.privateKeyFile.String(),
Jiyong Park9335a262018-12-24 11:31:58 +09002814 "vendor/foo/devkeys/testkey.pem")
2815 }
2816
Jiyong Parkb2742fd2019-02-11 11:38:15 +09002817 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09002818 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09002819 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09002820 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09002821 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09002822 }
2823}
Jiyong Park58e364a2019-01-19 19:24:06 +09002824
Jooyung Hanf121a652019-12-17 14:30:11 +09002825func TestCertificate(t *testing.T) {
2826 t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002827 ctx := testApex(t, `
Jooyung Hanf121a652019-12-17 14:30:11 +09002828 apex {
2829 name: "myapex",
2830 key: "myapex.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002831 updatable: false,
Jooyung Hanf121a652019-12-17 14:30:11 +09002832 }
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 Cross1c460562021-02-16 17:55:47 -08002845 ctx := testApex(t, `
Jooyung Hanf121a652019-12-17 14:30:11 +09002846 apex {
2847 name: "myapex_keytest",
2848 key: "myapex.key",
2849 file_contexts: ":myapex-file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002850 updatable: false,
Jooyung Hanf121a652019-12-17 14:30:11 +09002851 }
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 Cross1c460562021-02-16 17:55:47 -08002868 ctx := testApex(t, `
Jooyung Hanf121a652019-12-17 14:30:11 +09002869 apex {
2870 name: "myapex",
2871 key: "myapex.key",
2872 certificate: ":myapex.certificate",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002873 updatable: false,
Jooyung Hanf121a652019-12-17 14:30:11 +09002874 }
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 Cross1c460562021-02-16 17:55:47 -08002891 ctx := testApex(t, `
Jooyung Hanf121a652019-12-17 14:30:11 +09002892 apex {
2893 name: "myapex_keytest",
2894 key: "myapex.key",
2895 file_contexts: ":myapex-file_contexts",
2896 certificate: ":myapex.certificate",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002897 updatable: false,
Jooyung Hanf121a652019-12-17 14:30:11 +09002898 }
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 Cross1c460562021-02-16 17:55:47 -08002915 ctx := testApex(t, `
Jooyung Hanf121a652019-12-17 14:30:11 +09002916 apex {
2917 name: "myapex",
2918 key: "myapex.key",
2919 certificate: "testkey",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002920 updatable: false,
Jooyung Hanf121a652019-12-17 14:30:11 +09002921 }
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 Cross1c460562021-02-16 17:55:47 -08002934 ctx := testApex(t, `
Jooyung Hanf121a652019-12-17 14:30:11 +09002935 apex {
2936 name: "myapex_keytest",
2937 key: "myapex.key",
2938 file_contexts: ":myapex-file_contexts",
2939 certificate: "testkey",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002940 updatable: false,
Jooyung Hanf121a652019-12-17 14:30:11 +09002941 }
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 Park58e364a2019-01-19 19:24:06 +09002959func TestMacro(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08002960 ctx := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09002961 apex {
2962 name: "myapex",
2963 key: "myapex.key",
Jooyung Hanc87a0592020-03-02 17:44:33 +09002964 native_shared_libs: ["mylib", "mylib2"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00002965 updatable: false,
Jiyong Park58e364a2019-01-19 19:24:06 +09002966 }
2967
2968 apex {
2969 name: "otherapex",
2970 key: "myapex.key",
Jooyung Hanc87a0592020-03-02 17:44:33 +09002971 native_shared_libs: ["mylib", "mylib2"],
Jooyung Hanccce2f22020-03-07 03:45:53 +09002972 min_sdk_version: "29",
Jiyong Park58e364a2019-01-19 19:24:06 +09002973 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00002986 apex_available: [
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002987 "myapex",
2988 "otherapex",
2989 ],
Jooyung Han24282772020-03-21 23:20:55 +09002990 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +09002991 min_sdk_version: "29",
Jiyong Park58e364a2019-01-19 19:24:06 +09002992 }
Jooyung Hanc87a0592020-03-02 17:44:33 +09002993 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 Crossaede88c2020-08-11 12:17:01 -07003002 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 Hanc87a0592020-03-02 17:44:33 +09003015 use_apex_name_macro: true,
Colin Crossaede88c2020-08-11 12:17:01 -07003016 recovery_available: true,
Jooyung Han749dc692020-04-15 11:03:39 +09003017 min_sdk_version: "29",
Jooyung Hanc87a0592020-03-02 17:44:33 +09003018 }
Jiyong Park58e364a2019-01-19 19:24:06 +09003019 `)
3020
Jooyung Hanc87a0592020-03-02 17:44:33 +09003021 // non-APEX variant does not have __ANDROID_APEX__ defined
Colin Cross7113d202019-11-20 16:39:12 -08003022 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09003023 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Dan Albertb19953d2020-11-17 15:29:36 -08003024 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__")
Jooyung Hanc87a0592020-03-02 17:44:33 +09003025
Jooyung Hanccce2f22020-03-07 03:45:53 +09003026 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Colin Crossaede88c2020-08-11 12:17:01 -07003027 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"]
Jooyung Hanc87a0592020-03-02 17:44:33 +09003028 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Dan Albertb19953d2020-11-17 15:29:36 -08003029 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=10000")
Jooyung Han77988572019-10-18 16:26:16 +09003030 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
Jooyung Hanc87a0592020-03-02 17:44:33 +09003031
Jooyung Hanccce2f22020-03-07 03:45:53 +09003032 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Colin Crossaede88c2020-08-11 12:17:01 -07003033 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex29").Rule("cc").Args["cFlags"]
Jooyung Hanc87a0592020-03-02 17:44:33 +09003034 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Dan Albertb19953d2020-11-17 15:29:36 -08003035 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=29")
Jooyung Han77988572019-10-18 16:26:16 +09003036 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09003037
Colin Crossaede88c2020-08-11 12:17:01 -07003038 // 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 Albertb19953d2020-11-17 15:29:36 -08003057 // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__
Colin Crossaede88c2020-08-11 12:17:01 -07003058 mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
3059 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Dan Albertb19953d2020-11-17 15:29:36 -08003060 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__")
Colin Crossaede88c2020-08-11 12:17:01 -07003061
3062 // When a dependency of a cc_library sets use_apex_name_macro: true each apex gets a unique
3063 // variant.
Jooyung Hanc87a0592020-03-02 17:44:33 +09003064
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 Han6b8459b2019-10-30 08:29:25 +09003071 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Colin Crossaede88c2020-08-11 12:17:01 -07003072 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
Jooyung Han77988572019-10-18 16:26:16 +09003073 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09003074
Jooyung Hanc87a0592020-03-02 17:44:33 +09003075 // APEX variant has __ANDROID_APEX__ defined
3076 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09003077 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09003078 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
Colin Crossaede88c2020-08-11 12:17:01 -07003079 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jooyung Han24282772020-03-21 23:20:55 +09003080
Dan Albertb19953d2020-11-17 15:29:36 -08003081 // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__
Colin Crossaede88c2020-08-11 12:17:01 -07003082 mylibCFlags = ctx.ModuleForTests("mylib2", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han24282772020-03-21 23:20:55 +09003083 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Dan Albertb19953d2020-11-17 15:29:36 -08003084 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__")
Jiyong Park58e364a2019-01-19 19:24:06 +09003085}
Jiyong Park7e636d02019-01-28 16:16:54 +09003086
3087func TestHeaderLibsDependency(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003088 ctx := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09003089 apex {
3090 name: "myapex",
3091 key: "myapex.key",
3092 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003093 updatable: false,
Jiyong Park7e636d02019-01-28 16:16:54 +09003094 }
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 Park0f80c182020-01-31 02:49:53 +09003107 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09003108 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00003120 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09003121 }
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 Cross7113d202019-11-20 16:39:12 -08003132 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park7e636d02019-01-28 16:16:54 +09003133
3134 // Ensure that the include path of the header lib is exported to 'otherlib'
3135 ensureContains(t, cFlags, "-Imy_include")
3136}
Alex Light9670d332019-01-29 18:07:33 -08003137
Jiyong Park7cd10e32020-01-14 09:22:18 +09003138type fileInApex struct {
3139 path string // path in apex
Jooyung Hana57af4a2020-01-23 05:36:59 +00003140 src string // src path
Jiyong Park7cd10e32020-01-14 09:22:18 +09003141 isLink bool
3142}
3143
Jooyung Hana57af4a2020-01-23 05:36:59 +00003144func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex {
Jooyung Han31c470b2019-10-18 16:26:59 +09003145 t.Helper()
Jooyung Hana57af4a2020-01-23 05:36:59 +00003146 apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09003147 copyCmds := apexRule.Args["copy_commands"]
3148 imageApexDir := "/image.apex/"
Jiyong Park7cd10e32020-01-14 09:22:18 +09003149 var ret []fileInApex
Jooyung Han31c470b2019-10-18 16:26:59 +09003150 for _, cmd := range strings.Split(copyCmds, "&&") {
3151 cmd = strings.TrimSpace(cmd)
3152 if cmd == "" {
3153 continue
3154 }
3155 terms := strings.Split(cmd, " ")
Jooyung Hana57af4a2020-01-23 05:36:59 +00003156 var dst, src string
Jiyong Park7cd10e32020-01-14 09:22:18 +09003157 var isLink bool
Jooyung Han31c470b2019-10-18 16:26:59 +09003158 switch terms[0] {
3159 case "mkdir":
3160 case "cp":
Jiyong Park7cd10e32020-01-14 09:22:18 +09003161 if len(terms) != 3 && len(terms) != 4 {
Jooyung Han31c470b2019-10-18 16:26:59 +09003162 t.Fatal("copyCmds contains invalid cp command", cmd)
3163 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09003164 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00003165 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09003166 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 Hana57af4a2020-01-23 05:36:59 +00003173 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09003174 isLink = true
3175 default:
3176 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
3177 }
3178 if dst != "" {
Jooyung Han31c470b2019-10-18 16:26:59 +09003179 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 Hana57af4a2020-01-23 05:36:59 +00003184 ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink})
Jooyung Han31c470b2019-10-18 16:26:59 +09003185 }
3186 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09003187 return ret
3188}
3189
Jooyung Hana57af4a2020-01-23 05:36:59 +00003190func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) {
3191 t.Helper()
Jiyong Park7cd10e32020-01-14 09:22:18 +09003192 var failed bool
3193 var surplus []string
3194 filesMatched := make(map[string]bool)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003195 for _, file := range getFiles(t, ctx, moduleName, variant) {
Jooyung Hane6436d72020-02-27 13:31:56 +09003196 mactchFound := false
Jiyong Park7cd10e32020-01-14 09:22:18 +09003197 for _, expected := range files {
3198 if matched, _ := path.Match(expected, file.path); matched {
3199 filesMatched[expected] = true
Jooyung Hane6436d72020-02-27 13:31:56 +09003200 mactchFound = true
3201 break
Jiyong Park7cd10e32020-01-14 09:22:18 +09003202 }
3203 }
Jooyung Hane6436d72020-02-27 13:31:56 +09003204 if !mactchFound {
3205 surplus = append(surplus, file.path)
3206 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09003207 }
Jooyung Han31c470b2019-10-18 16:26:59 +09003208
Jooyung Han31c470b2019-10-18 16:26:59 +09003209 if len(surplus) > 0 {
Jooyung Han39edb6c2019-11-06 16:53:07 +09003210 sort.Strings(surplus)
Jooyung Han31c470b2019-10-18 16:26:59 +09003211 t.Log("surplus files", surplus)
3212 failed = true
3213 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09003214
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 Han31c470b2019-10-18 16:26:59 +09003223 t.Log("missing files", missing)
3224 failed = true
3225 }
3226 if failed {
3227 t.Fail()
3228 }
3229}
3230
Jooyung Han344d5432019-08-23 11:17:39 +09003231func TestVndkApexCurrent(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003232 ctx := testApex(t, `
Jooyung Han344d5432019-08-23 11:17:39 +09003233 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -08003234 name: "com.android.vndk.current",
3235 key: "com.android.vndk.current.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003236 updatable: false,
Jooyung Han344d5432019-08-23 11:17:39 +09003237 }
3238
3239 apex_key {
Colin Cross2807f002021-03-02 10:15:29 -08003240 name: "com.android.vndk.current.key",
Jooyung Han344d5432019-08-23 11:17:39 +09003241 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 Yun63e9ec72020-10-29 16:49:43 +09003249 product_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +09003250 vndk: {
3251 enabled: true,
3252 },
3253 system_shared_libs: [],
3254 stl: "none",
Colin Cross2807f002021-03-02 10:15:29 -08003255 apex_available: [ "com.android.vndk.current" ],
Jooyung Han344d5432019-08-23 11:17:39 +09003256 }
3257
3258 cc_library {
3259 name: "libvndksp",
3260 srcs: ["mylib.cpp"],
3261 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003262 product_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +09003263 vndk: {
3264 enabled: true,
3265 support_system_process: true,
3266 },
3267 system_shared_libs: [],
3268 stl: "none",
Colin Cross2807f002021-03-02 10:15:29 -08003269 apex_available: [ "com.android.vndk.current" ],
Jooyung Han344d5432019-08-23 11:17:39 +09003270 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09003271 `+vndkLibrariesTxtFiles("current"))
Jooyung Han344d5432019-08-23 11:17:39 +09003272
Colin Cross2807f002021-03-02 10:15:29 -08003273 ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09003274 "lib/libvndk.so",
3275 "lib/libvndksp.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09003276 "lib/libc++.so",
Jooyung Han31c470b2019-10-18 16:26:59 +09003277 "lib64/libvndk.so",
3278 "lib64/libvndksp.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09003279 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09003280 "etc/llndk.libraries.VER.txt",
3281 "etc/vndkcore.libraries.VER.txt",
3282 "etc/vndksp.libraries.VER.txt",
3283 "etc/vndkprivate.libraries.VER.txt",
Justin Yun8a2600c2020-12-07 12:44:03 +09003284 "etc/vndkproduct.libraries.VER.txt",
Jooyung Han31c470b2019-10-18 16:26:59 +09003285 })
Jooyung Han344d5432019-08-23 11:17:39 +09003286}
3287
3288func TestVndkApexWithPrebuilt(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003289 ctx := testApex(t, `
Jooyung Han344d5432019-08-23 11:17:39 +09003290 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -08003291 name: "com.android.vndk.current",
3292 key: "com.android.vndk.current.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003293 updatable: false,
Jooyung Han344d5432019-08-23 11:17:39 +09003294 }
3295
3296 apex_key {
Colin Cross2807f002021-03-02 10:15:29 -08003297 name: "com.android.vndk.current.key",
Jooyung Han344d5432019-08-23 11:17:39 +09003298 public_key: "testkey.avbpubkey",
3299 private_key: "testkey.pem",
3300 }
3301
3302 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09003303 name: "libvndk",
3304 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09003305 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003306 product_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +09003307 vndk: {
3308 enabled: true,
3309 },
3310 system_shared_libs: [],
3311 stl: "none",
Colin Cross2807f002021-03-02 10:15:29 -08003312 apex_available: [ "com.android.vndk.current" ],
Jooyung Han344d5432019-08-23 11:17:39 +09003313 }
Jooyung Han31c470b2019-10-18 16:26:59 +09003314
3315 cc_prebuilt_library_shared {
3316 name: "libvndk.arm",
3317 srcs: ["libvndk.arm.so"],
3318 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003319 product_available: true,
Jooyung Han31c470b2019-10-18 16:26:59 +09003320 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 Cross2807f002021-03-02 10:15:29 -08003331 apex_available: [ "com.android.vndk.current" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09003332 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09003333 `+vndkLibrariesTxtFiles("current"),
3334 withFiles(map[string][]byte{
3335 "libvndk.so": nil,
3336 "libvndk.arm.so": nil,
3337 }))
Colin Cross2807f002021-03-02 10:15:29 -08003338 ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09003339 "lib/libvndk.so",
3340 "lib/libvndk.arm.so",
3341 "lib64/libvndk.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09003342 "lib/libc++.so",
3343 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09003344 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09003345 })
Jooyung Han344d5432019-08-23 11:17:39 +09003346}
3347
Jooyung Han39edb6c2019-11-06 16:53:07 +09003348func vndkLibrariesTxtFiles(vers ...string) (result string) {
3349 for _, v := range vers {
3350 if v == "current" {
Justin Yun8a2600c2020-12-07 12:44:03 +09003351 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09003352 result += `
Colin Crosse4e44bc2020-12-28 13:50:21 -08003353 ` + txt + `_libraries_txt {
Jooyung Han39edb6c2019-11-06 16:53:07 +09003354 name: "` + txt + `.libraries.txt",
3355 }
3356 `
3357 }
3358 } else {
Justin Yun8a2600c2020-12-07 12:44:03 +09003359 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09003360 result += `
3361 prebuilt_etc {
3362 name: "` + txt + `.libraries.` + v + `.txt",
3363 src: "dummy.txt",
3364 }
3365 `
3366 }
3367 }
3368 }
3369 return
3370}
3371
Jooyung Han344d5432019-08-23 11:17:39 +09003372func TestVndkApexVersion(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003373 ctx := testApex(t, `
Jooyung Han344d5432019-08-23 11:17:39 +09003374 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -08003375 name: "com.android.vndk.v27",
Jooyung Han344d5432019-08-23 11:17:39 +09003376 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09003377 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09003378 vndk_version: "27",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003379 updatable: false,
Jooyung Han344d5432019-08-23 11:17:39 +09003380 }
3381
3382 apex_key {
3383 name: "myapex.key",
3384 public_key: "testkey.avbpubkey",
3385 private_key: "testkey.pem",
3386 }
3387
Jooyung Han31c470b2019-10-18 16:26:59 +09003388 vndk_prebuilt_shared {
3389 name: "libvndk27",
3390 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09003391 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003392 product_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +09003393 vndk: {
3394 enabled: true,
3395 },
Jooyung Han31c470b2019-10-18 16:26:59 +09003396 target_arch: "arm64",
3397 arch: {
3398 arm: {
3399 srcs: ["libvndk27_arm.so"],
3400 },
3401 arm64: {
3402 srcs: ["libvndk27_arm64.so"],
3403 },
3404 },
Colin Cross2807f002021-03-02 10:15:29 -08003405 apex_available: [ "com.android.vndk.v27" ],
Jooyung Han344d5432019-08-23 11:17:39 +09003406 }
3407
3408 vndk_prebuilt_shared {
3409 name: "libvndk27",
3410 version: "27",
3411 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003412 product_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +09003413 vndk: {
3414 enabled: true,
3415 },
Jooyung Han31c470b2019-10-18 16:26:59 +09003416 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 Han39edb6c2019-11-06 16:53:07 +09003425 }
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 Han344d5432019-08-23 11:17:39 +09003433
Colin Cross2807f002021-03-02 10:15:29 -08003434 ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09003435 "lib/libvndk27_arm.so",
3436 "lib64/libvndk27_arm64.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09003437 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09003438 })
Jooyung Han344d5432019-08-23 11:17:39 +09003439}
3440
Jooyung Han90eee022019-10-01 20:02:42 +09003441func TestVndkApexNameRule(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003442 ctx := testApex(t, `
Jooyung Han90eee022019-10-01 20:02:42 +09003443 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -08003444 name: "com.android.vndk.current",
Jooyung Han90eee022019-10-01 20:02:42 +09003445 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09003446 file_contexts: ":myapex-file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003447 updatable: false,
Jooyung Han90eee022019-10-01 20:02:42 +09003448 }
3449 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -08003450 name: "com.android.vndk.v28",
Jooyung Han90eee022019-10-01 20:02:42 +09003451 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09003452 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09003453 vndk_version: "28",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003454 updatable: false,
Jooyung Han90eee022019-10-01 20:02:42 +09003455 }
3456 apex_key {
3457 name: "myapex.key",
3458 public_key: "testkey.avbpubkey",
3459 private_key: "testkey.pem",
Jooyung Han39edb6c2019-11-06 16:53:07 +09003460 }`+vndkLibrariesTxtFiles("28", "current"))
Jooyung Han90eee022019-10-01 20:02:42 +09003461
3462 assertApexName := func(expected, moduleName string) {
Jooyung Hana57af4a2020-01-23 05:36:59 +00003463 bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09003464 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 Cross2807f002021-03-02 10:15:29 -08003470 assertApexName("com.android.vndk.vVER", "com.android.vndk.current")
3471 assertApexName("com.android.vndk.v28", "com.android.vndk.v28")
Jooyung Han90eee022019-10-01 20:02:42 +09003472}
3473
Jooyung Han344d5432019-08-23 11:17:39 +09003474func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003475 ctx := testApex(t, `
Jooyung Han344d5432019-08-23 11:17:39 +09003476 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -08003477 name: "com.android.vndk.current",
3478 key: "com.android.vndk.current.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09003479 file_contexts: ":myapex-file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003480 updatable: false,
Jooyung Han344d5432019-08-23 11:17:39 +09003481 }
3482
3483 apex_key {
Colin Cross2807f002021-03-02 10:15:29 -08003484 name: "com.android.vndk.current.key",
Jooyung Han344d5432019-08-23 11:17:39 +09003485 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 Yun63e9ec72020-10-29 16:49:43 +09003493 product_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +09003494 native_bridge_supported: true,
3495 host_supported: true,
3496 vndk: {
3497 enabled: true,
3498 },
3499 system_shared_libs: [],
3500 stl: "none",
Colin Cross2807f002021-03-02 10:15:29 -08003501 apex_available: [ "com.android.vndk.current" ],
Jooyung Han344d5432019-08-23 11:17:39 +09003502 }
Colin Cross2807f002021-03-02 10:15:29 -08003503 `+vndkLibrariesTxtFiles("current"),
3504 withNativeBridgeEnabled)
Jooyung Han344d5432019-08-23 11:17:39 +09003505
Colin Cross2807f002021-03-02 10:15:29 -08003506 ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09003507 "lib/libvndk.so",
3508 "lib64/libvndk.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09003509 "lib/libc++.so",
3510 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09003511 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09003512 })
Jooyung Han344d5432019-08-23 11:17:39 +09003513}
3514
3515func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
Colin Cross2807f002021-03-02 10:15:29 -08003516 testApexError(t, `module "com.android.vndk.current" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
Jooyung Han344d5432019-08-23 11:17:39 +09003517 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -08003518 name: "com.android.vndk.current",
3519 key: "com.android.vndk.current.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09003520 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09003521 native_bridge_supported: true,
3522 }
3523
3524 apex_key {
Colin Cross2807f002021-03-02 10:15:29 -08003525 name: "com.android.vndk.current.key",
Jooyung Han344d5432019-08-23 11:17:39 +09003526 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 Yun63e9ec72020-10-29 16:49:43 +09003534 product_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +09003535 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 Han31c470b2019-10-18 16:26:59 +09003546func TestVndkApexWithBinder32(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003547 ctx := testApex(t, `
Jooyung Han31c470b2019-10-18 16:26:59 +09003548 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -08003549 name: "com.android.vndk.v27",
Jooyung Han31c470b2019-10-18 16:26:59 +09003550 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09003551 file_contexts: ":myapex-file_contexts",
Jooyung Han31c470b2019-10-18 16:26:59 +09003552 vndk_version: "27",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003553 updatable: false,
Jooyung Han31c470b2019-10-18 16:26:59 +09003554 }
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 Yun63e9ec72020-10-29 16:49:43 +09003567 product_available: true,
Jooyung Han31c470b2019-10-18 16:26:59 +09003568 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 Yun63e9ec72020-10-29 16:49:43 +09003584 product_available: true,
Jooyung Han31c470b2019-10-18 16:26:59 +09003585 vndk: {
3586 enabled: true,
3587 },
3588 arch: {
3589 arm: {
3590 srcs: ["libvndk27binder32.so"],
3591 }
3592 },
Colin Cross2807f002021-03-02 10:15:29 -08003593 apex_available: [ "com.android.vndk.v27" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09003594 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09003595 `+vndkLibrariesTxtFiles("27"),
Jooyung Han31c470b2019-10-18 16:26:59 +09003596 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 Han35155c42020-02-06 17:33:20 +09003603 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}},
3604 NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
Jooyung Han31c470b2019-10-18 16:26:59 +09003605 },
3606 }),
3607 )
3608
Colin Cross2807f002021-03-02 10:15:29 -08003609 ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09003610 "lib/libvndk27binder32.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09003611 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09003612 })
3613}
3614
Jooyung Han45a96772020-06-15 14:59:42 +09003615func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003616 ctx := testApex(t, `
Jooyung Han45a96772020-06-15 14:59:42 +09003617 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -08003618 name: "com.android.vndk.current",
3619 key: "com.android.vndk.current.key",
Jooyung Han45a96772020-06-15 14:59:42 +09003620 file_contexts: ":myapex-file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003621 updatable: false,
Jooyung Han45a96772020-06-15 14:59:42 +09003622 }
3623
3624 apex_key {
Colin Cross2807f002021-03-02 10:15:29 -08003625 name: "com.android.vndk.current.key",
Jooyung Han45a96772020-06-15 14:59:42 +09003626 public_key: "testkey.avbpubkey",
3627 private_key: "testkey.pem",
3628 }
3629
3630 cc_library {
3631 name: "libz",
3632 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003633 product_available: true,
Jooyung Han45a96772020-06-15 14:59:42 +09003634 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 Cross2807f002021-03-02 10:15:29 -08003646 apexManifestRule := ctx.ModuleForTests("com.android.vndk.current", "android_common_image").Rule("apexManifestRule")
Jooyung Han45a96772020-06-15 14:59:42 +09003647 provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"])
3648 ensureListEmpty(t, provideNativeLibs)
3649}
3650
Jooyung Hane1633032019-08-01 17:41:43 +09003651func TestDependenciesInApexManifest(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003652 ctx := testApex(t, `
Jooyung Hane1633032019-08-01 17:41:43 +09003653 apex {
3654 name: "myapex_nodep",
3655 key: "myapex.key",
3656 native_shared_libs: ["lib_nodep"],
3657 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09003658 file_contexts: ":myapex-file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003659 updatable: false,
Jooyung Hane1633032019-08-01 17:41:43 +09003660 }
3661
3662 apex {
3663 name: "myapex_dep",
3664 key: "myapex.key",
3665 native_shared_libs: ["lib_dep"],
3666 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09003667 file_contexts: ":myapex-file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003668 updatable: false,
Jooyung Hane1633032019-08-01 17:41:43 +09003669 }
3670
3671 apex {
3672 name: "myapex_provider",
3673 key: "myapex.key",
3674 native_shared_libs: ["libfoo"],
3675 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09003676 file_contexts: ":myapex-file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003677 updatable: false,
Jooyung Hane1633032019-08-01 17:41:43 +09003678 }
3679
3680 apex {
3681 name: "myapex_selfcontained",
3682 key: "myapex.key",
3683 native_shared_libs: ["lib_dep", "libfoo"],
3684 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09003685 file_contexts: ":myapex-file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003686 updatable: false,
Jooyung Hane1633032019-08-01 17:41:43 +09003687 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00003700 apex_available: [ "myapex_nodep" ],
Jooyung Hane1633032019-08-01 17:41:43 +09003701 }
3702
3703 cc_library {
3704 name: "lib_dep",
3705 srcs: ["mylib.cpp"],
3706 shared_libs: ["libfoo"],
3707 system_shared_libs: [],
3708 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003709 apex_available: [
3710 "myapex_dep",
3711 "myapex_provider",
3712 "myapex_selfcontained",
3713 ],
Jooyung Hane1633032019-08-01 17:41:43 +09003714 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00003724 apex_available: [
3725 "myapex_provider",
3726 "myapex_selfcontained",
3727 ],
Jooyung Hane1633032019-08-01 17:41:43 +09003728 }
3729 `)
3730
Jooyung Hand15aa1f2019-09-27 00:38:03 +09003731 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09003732 var provideNativeLibs, requireNativeLibs []string
3733
Sundong Ahnabb64432019-10-22 13:58:29 +09003734 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09003735 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
3736 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09003737 ensureListEmpty(t, provideNativeLibs)
3738 ensureListEmpty(t, requireNativeLibs)
3739
Sundong Ahnabb64432019-10-22 13:58:29 +09003740 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09003741 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
3742 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09003743 ensureListEmpty(t, provideNativeLibs)
3744 ensureListContains(t, requireNativeLibs, "libfoo.so")
3745
Sundong Ahnabb64432019-10-22 13:58:29 +09003746 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09003747 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
3748 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09003749 ensureListContains(t, provideNativeLibs, "libfoo.so")
3750 ensureListEmpty(t, requireNativeLibs)
3751
Sundong Ahnabb64432019-10-22 13:58:29 +09003752 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09003753 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
3754 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09003755 ensureListContains(t, provideNativeLibs, "libfoo.so")
3756 ensureListEmpty(t, requireNativeLibs)
3757}
3758
Jooyung Hand15aa1f2019-09-27 00:38:03 +09003759func TestApexName(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003760 ctx := testApex(t, `
Jooyung Hand15aa1f2019-09-27 00:38:03 +09003761 apex {
3762 name: "myapex",
3763 key: "myapex.key",
3764 apex_name: "com.android.myapex",
Jiyong Parkdb334862020-02-05 17:19:28 +09003765 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003766 updatable: false,
Jooyung Hand15aa1f2019-09-27 00:38:03 +09003767 }
3768
3769 apex_key {
3770 name: "myapex.key",
3771 public_key: "testkey.avbpubkey",
3772 private_key: "testkey.pem",
3773 }
Jiyong Parkdb334862020-02-05 17:19:28 +09003774
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 Hand15aa1f2019-09-27 00:38:03 +09003785 `)
3786
Sundong Ahnabb64432019-10-22 13:58:29 +09003787 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09003788 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 Parkdb334862020-02-05 17:19:28 +09003792
3793 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Colin Crossaa255532020-07-03 13:18:24 -07003794 data := android.AndroidMkDataForTest(t, ctx, apexBundle)
Jiyong Parkdb334862020-02-05 17:19:28 +09003795 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 Hand15aa1f2019-09-27 00:38:03 +09003802}
3803
Alex Light0851b882019-02-07 13:20:53 -08003804func TestNonTestApex(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003805 ctx := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08003806 apex {
3807 name: "myapex",
3808 key: "myapex.key",
3809 native_shared_libs: ["mylib_common"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003810 updatable: false,
Alex Light0851b882019-02-07 13:20:53 -08003811 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00003824 apex_available: [
3825 "//apex_available:platform",
3826 "myapex",
3827 ],
Alex Light0851b882019-02-07 13:20:53 -08003828 }
3829 `)
3830
Sundong Ahnabb64432019-10-22 13:58:29 +09003831 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08003832 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 Crossaede88c2020-08-11 12:17:01 -07003843 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000")
Alex Light0851b882019-02-07 13:20:53 -08003844
3845 // Ensure that both direct and indirect deps are copied into apex
3846 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
3847
Colin Cross7113d202019-11-20 16:39:12 -08003848 // Ensure that the platform variant ends with _shared
3849 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08003850
Colin Cross56a83212020-09-15 18:30:11 -07003851 if !ctx.ModuleForTests("mylib_common", "android_arm64_armv8-a_shared_apex10000").Module().(*cc.Module).InAnyApex() {
Alex Light0851b882019-02-07 13:20:53 -08003852 t.Log("Found mylib_common not in any apex!")
3853 t.Fail()
3854 }
3855}
3856
3857func TestTestApex(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003858 ctx := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08003859 apex_test {
3860 name: "myapex",
3861 key: "myapex.key",
3862 native_shared_libs: ["mylib_common_test"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003863 updatable: false,
Alex Light0851b882019-02-07 13:20:53 -08003864 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00003877 // TODO: remove //apex_available:platform
3878 apex_available: [
3879 "//apex_available:platform",
3880 "myapex",
3881 ],
Alex Light0851b882019-02-07 13:20:53 -08003882 }
3883 `)
3884
Sundong Ahnabb64432019-10-22 13:58:29 +09003885 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08003886 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 Crossaede88c2020-08-11 12:17:01 -07003897 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_apex10000")
Alex Light0851b882019-02-07 13:20:53 -08003898
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 Cross7113d202019-11-20 16:39:12 -08003902 // Ensure that the platform variant ends with _shared
3903 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08003904}
3905
Alex Light9670d332019-01-29 18:07:33 -08003906func TestApexWithTarget(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003907 ctx := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08003908 apex {
3909 name: "myapex",
3910 key: "myapex.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00003911 updatable: false,
Alex Light9670d332019-01-29 18:07:33 -08003912 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 Hanssoneec79eb2020-01-10 15:12:39 +00003946 // TODO: remove //apex_available:platform
3947 apex_available: [
3948 "//apex_available:platform",
3949 "myapex",
3950 ],
Alex Light9670d332019-01-29 18:07:33 -08003951 }
3952
3953 cc_library {
3954 name: "mylib_common",
3955 srcs: ["mylib.cpp"],
3956 system_shared_libs: [],
3957 stl: "none",
3958 compile_multilib: "first",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003959 // TODO: remove //apex_available:platform
3960 apex_available: [
3961 "//apex_available:platform",
3962 "myapex",
3963 ],
Alex Light9670d332019-01-29 18:07:33 -08003964 }
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 Ahnabb64432019-10-22 13:58:29 +09003975 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08003976 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 Crossaede88c2020-08-11 12:17:01 -07003982 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 Light9670d332019-01-29 18:07:33 -08003985
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 Cross7113d202019-11-20 16:39:12 -08003991 // 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 Light9670d332019-01-29 18:07:33 -08003995}
Jiyong Park04480cf2019-02-06 00:16:29 +09003996
Jiyong Park59140302020-12-14 18:44:04 +09003997func TestApexWithArch(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08003998 ctx := testApex(t, `
Jiyong Park59140302020-12-14 18:44:04 +09003999 apex {
4000 name: "myapex",
4001 key: "myapex.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004002 updatable: false,
Jiyong Park59140302020-12-14 18:44:04 +09004003 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 Park04480cf2019-02-06 00:16:29 +09004056func TestApexWithShBinary(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08004057 ctx := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09004058 apex {
4059 name: "myapex",
4060 key: "myapex.key",
4061 binaries: ["myscript"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004062 updatable: false,
Jiyong Park04480cf2019-02-06 00:16:29 +09004063 }
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 Ahnabb64432019-10-22 13:58:29 +09004079 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09004080 copyCmds := apexRule.Args["copy_commands"]
4081
4082 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
4083}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09004084
Jooyung Han91df2082019-11-20 01:49:42 +09004085func 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 Cross1c460562021-02-16 17:55:47 -08004098 ctx := testApex(t, `
Jooyung Han91df2082019-11-20 01:49:42 +09004099 apex {
4100 name: "myapex",
4101 key: "myapex.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004102 updatable: false,
Jooyung Han91df2082019-11-20 01:49:42 +09004103 `+tc.propName+`
4104 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09004105
Jooyung Han91df2082019-11-20 01:49:42 +09004106 apex_key {
4107 name: "myapex.key",
4108 public_key: "testkey.avbpubkey",
4109 private_key: "testkey.pem",
4110 }
4111 `)
Jiyong Parkd1e293d2019-03-15 02:13:21 +09004112
Jooyung Han91df2082019-11-20 01:49:42 +09004113 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Paul Duffin37ba3442021-03-29 00:21:08 +01004114 expected := "out/soong/target/product/test_device/" + tc.parition + "/apex"
4115 actual := apex.installDir.RelativeToTop().String()
Jooyung Han91df2082019-11-20 01:49:42 +09004116 if actual != expected {
4117 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
4118 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09004119
Jooyung Han91df2082019-11-20 01:49:42 +09004120 flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
Paul Duffin37ba3442021-03-29 00:21:08 +01004121 expected = "out/soong/target/product/test_device/" + tc.flattenedPartition + "/apex"
4122 actual = flattened.installDir.RelativeToTop().String()
Jooyung Han91df2082019-11-20 01:49:42 +09004123 if actual != expected {
4124 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
4125 }
4126 })
Jiyong Parkd1e293d2019-03-15 02:13:21 +09004127 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09004128}
Jiyong Park67882562019-03-21 01:11:21 +09004129
Jooyung Han580eb4f2020-06-24 19:33:06 +09004130func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08004131 ctx := testApex(t, `
Jooyung Han580eb4f2020-06-24 19:33:06 +09004132 apex {
4133 name: "myapex",
4134 key: "myapex.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004135 updatable: false,
Jooyung Han580eb4f2020-06-24 19:33:06 +09004136 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004137
Jooyung Han580eb4f2020-06-24 19:33:06 +09004138 apex_key {
4139 name: "myapex.key",
4140 public_key: "testkey.avbpubkey",
4141 private_key: "testkey.pem",
4142 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004143 `)
4144 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han580eb4f2020-06-24 19:33:06 +09004145 rule := module.Output("file_contexts")
4146 ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts")
4147}
Jooyung Han54aca7b2019-11-20 02:26:02 +09004148
Jooyung Han580eb4f2020-06-24 19:33:06 +09004149func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) {
Jooyung Han54aca7b2019-11-20 02:26:02 +09004150 testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
Jooyung Han580eb4f2020-06-24 19:33:06 +09004151 apex {
4152 name: "myapex",
4153 key: "myapex.key",
4154 file_contexts: "my_own_file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004155 updatable: false,
Jooyung Han580eb4f2020-06-24 19:33:06 +09004156 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004157
Jooyung Han580eb4f2020-06-24 19:33:06 +09004158 apex_key {
4159 name: "myapex.key",
4160 public_key: "testkey.avbpubkey",
4161 private_key: "testkey.pem",
4162 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004163 `, withFiles(map[string][]byte{
4164 "my_own_file_contexts": nil,
4165 }))
Jooyung Han580eb4f2020-06-24 19:33:06 +09004166}
Jooyung Han54aca7b2019-11-20 02:26:02 +09004167
Jooyung Han580eb4f2020-06-24 19:33:06 +09004168func TestFileContexts_ProductSpecificApexes(t *testing.T) {
Jooyung Han54aca7b2019-11-20 02:26:02 +09004169 testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
Jooyung Han580eb4f2020-06-24 19:33:06 +09004170 apex {
4171 name: "myapex",
4172 key: "myapex.key",
4173 product_specific: true,
4174 file_contexts: "product_specific_file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004175 updatable: false,
Jooyung Han580eb4f2020-06-24 19:33:06 +09004176 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004177
Jooyung Han580eb4f2020-06-24 19:33:06 +09004178 apex_key {
4179 name: "myapex.key",
4180 public_key: "testkey.avbpubkey",
4181 private_key: "testkey.pem",
4182 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004183 `)
4184
Colin Cross1c460562021-02-16 17:55:47 -08004185 ctx := testApex(t, `
Jooyung Han580eb4f2020-06-24 19:33:06 +09004186 apex {
4187 name: "myapex",
4188 key: "myapex.key",
4189 product_specific: true,
4190 file_contexts: "product_specific_file_contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004191 updatable: false,
Jooyung Han580eb4f2020-06-24 19:33:06 +09004192 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004193
Jooyung Han580eb4f2020-06-24 19:33:06 +09004194 apex_key {
4195 name: "myapex.key",
4196 public_key: "testkey.avbpubkey",
4197 private_key: "testkey.pem",
4198 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004199 `, withFiles(map[string][]byte{
4200 "product_specific_file_contexts": nil,
4201 }))
Jooyung Han580eb4f2020-06-24 19:33:06 +09004202 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 Han54aca7b2019-11-20 02:26:02 +09004206
Jooyung Han580eb4f2020-06-24 19:33:06 +09004207func TestFileContexts_SetViaFileGroup(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08004208 ctx := testApex(t, `
Jooyung Han580eb4f2020-06-24 19:33:06 +09004209 apex {
4210 name: "myapex",
4211 key: "myapex.key",
4212 product_specific: true,
4213 file_contexts: ":my-file-contexts",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004214 updatable: false,
Jooyung Han580eb4f2020-06-24 19:33:06 +09004215 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004216
Jooyung Han580eb4f2020-06-24 19:33:06 +09004217 apex_key {
4218 name: "myapex.key",
4219 public_key: "testkey.avbpubkey",
4220 private_key: "testkey.pem",
4221 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004222
Jooyung Han580eb4f2020-06-24 19:33:06 +09004223 filegroup {
4224 name: "my-file-contexts",
4225 srcs: ["product_specific_file_contexts"],
4226 }
Jooyung Han54aca7b2019-11-20 02:26:02 +09004227 `, withFiles(map[string][]byte{
4228 "product_specific_file_contexts": nil,
4229 }))
Jooyung Han580eb4f2020-06-24 19:33:06 +09004230 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 Han54aca7b2019-11-20 02:26:02 +09004233}
4234
Jiyong Park67882562019-03-21 01:11:21 +09004235func TestApexKeyFromOtherModule(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08004236 ctx := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09004237 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 Jung18aefc12020-12-21 09:11:10 -08004257 actual_pubkey := apex_key.publicKeyFile.String()
Jiyong Park67882562019-03-21 01:11:21 +09004258 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 Jung18aefc12020-12-21 09:11:10 -08004262 actual_privkey := apex_key.privateKeyFile.String()
Jiyong Park67882562019-03-21 01:11:21 +09004263 if actual_privkey != expected_privkey {
4264 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
4265 }
4266}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07004267
4268func TestPrebuilt(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08004269 ctx := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07004270 prebuilt_apex {
4271 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09004272 arch: {
4273 arm64: {
4274 src: "myapex-arm64.apex",
4275 },
4276 arm: {
4277 src: "myapex-arm.apex",
4278 },
4279 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07004280 }
4281 `)
4282
4283 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
4284
Jiyong Parkc95714e2019-03-29 14:23:10 +09004285 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 Jung939ebd52019-03-26 15:07:36 -07004289}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01004290
4291func TestPrebuiltFilenameOverride(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08004292 ctx := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01004293 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 Jungc1001ec2019-06-25 11:20:53 -07004307
Jaewoong Jung22f7d182019-07-16 18:25:41 -07004308func TestPrebuiltOverrides(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08004309 ctx := testApex(t, `
Jaewoong Jung22f7d182019-07-16 18:25:41 -07004310 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 Crossaa255532020-07-03 13:18:24 -07004322 actual := android.AndroidMkEntriesForTest(t, ctx, p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jung22f7d182019-07-16 18:25:41 -07004323 if !reflect.DeepEqual(actual, expected) {
Jiyong Parkb0a012c2019-11-14 17:17:03 +09004324 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
Jaewoong Jung22f7d182019-07-16 18:25:41 -07004325 }
4326}
4327
Paul Duffin092153d2021-01-26 11:42:39 +00004328// 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 Duffin064b70c2020-11-02 17:32:38 +00004330func TestPrebuiltExportDexImplementationJars(t *testing.T) {
4331 transform := func(config *dexpreopt.GlobalConfig) {
Paul Duffin092153d2021-01-26 11:42:39 +00004332 // Empty transformation.
Paul Duffin064b70c2020-11-02 17:32:38 +00004333 }
4334
Paul Duffin89886cb2021-02-05 16:44:03 +00004335 checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) {
Paul Duffin064b70c2020-11-02 17:32:38 +00004336 // Make sure the import has been given the correct path to the dex jar.
Colin Crossdcf71b22021-02-01 13:59:03 -08004337 p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency)
Paul Duffin064b70c2020-11-02 17:32:38 +00004338 dexJarBuildPath := p.DexJarBuildPath()
Paul Duffin39853512021-02-26 11:09:39 +00004339 stem := android.RemoveOptionalPrebuiltPrefix(name)
4340 if expected, actual := ".intermediates/myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar", android.NormalizePathForTesting(dexJarBuildPath); actual != expected {
Paul Duffin064b70c2020-11-02 17:32:38 +00004341 t.Errorf("Incorrect DexJarBuildPath value '%s', expected '%s'", actual, expected)
4342 }
4343 }
4344
Paul Duffin39853512021-02-26 11:09:39 +00004345 ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) {
Paul Duffin064b70c2020-11-02 17:32:38 +00004346 // Make sure that an apex variant is not created for the source module.
Paul Duffin39853512021-02-26 11:09:39 +00004347 if expected, actual := []string{"android_common"}, ctx.ModuleVariantsForTests(name); !reflect.DeepEqual(expected, actual) {
Paul Duffin064b70c2020-11-02 17:32:38 +00004348 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 Duffin39853512021-02-26 11:09:39 +00004364 exported_java_libs: ["libfoo", "libbar"],
Paul Duffin064b70c2020-11-02 17:32:38 +00004365 }
4366
4367 java_import {
4368 name: "libfoo",
4369 jars: ["libfoo.jar"],
4370 }
Paul Duffin39853512021-02-26 11:09:39 +00004371
4372 java_sdk_library_import {
4373 name: "libbar",
4374 public: {
4375 jars: ["libbar.jar"],
4376 },
4377 }
Paul Duffin064b70c2020-11-02 17:32:38 +00004378 `
4379
4380 // Make sure that dexpreopt can access dex implementation files from the prebuilt.
4381 ctx := testDexpreoptWithApexes(t, bp, "", transform)
4382
Paul Duffinf6932af2021-02-26 18:21:56 +00004383 // 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 Duffin0d10c3c2021-03-01 17:09:32 +00004390 // 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 Duffin89886cb2021-02-05 16:44:03 +00004397 checkDexJarBuildPath(t, ctx, "libfoo")
Paul Duffin39853512021-02-26 11:09:39 +00004398
4399 checkDexJarBuildPath(t, ctx, "libbar")
Paul Duffin064b70c2020-11-02 17:32:38 +00004400 })
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 Duffin39853512021-02-26 11:09:39 +00004415 exported_java_libs: ["libfoo", "libbar"],
Paul Duffin064b70c2020-11-02 17:32:38 +00004416 }
4417
4418 java_import {
4419 name: "libfoo",
4420 jars: ["libfoo.jar"],
4421 }
4422
4423 java_library {
4424 name: "libfoo",
4425 }
Paul Duffin39853512021-02-26 11:09:39 +00004426
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 Duffin064b70c2020-11-02 17:32:38 +00004439 `
4440
4441 // Make sure that dexpreopt can access dex implementation files from the prebuilt.
4442 ctx := testDexpreoptWithApexes(t, bp, "", transform)
4443
Paul Duffin89886cb2021-02-05 16:44:03 +00004444 checkDexJarBuildPath(t, ctx, "prebuilt_libfoo")
Paul Duffin39853512021-02-26 11:09:39 +00004445 ensureNoSourceVariant(t, ctx, "libfoo")
4446
4447 checkDexJarBuildPath(t, ctx, "prebuilt_libbar")
4448 ensureNoSourceVariant(t, ctx, "libbar")
Paul Duffin064b70c2020-11-02 17:32:38 +00004449 })
4450
4451 t.Run("prebuilt preferred with source", func(t *testing.T) {
4452 bp := `
4453 prebuilt_apex {
4454 name: "myapex",
Paul Duffin064b70c2020-11-02 17:32:38 +00004455 arch: {
4456 arm64: {
4457 src: "myapex-arm64.apex",
4458 },
4459 arm: {
4460 src: "myapex-arm.apex",
4461 },
4462 },
Paul Duffin39853512021-02-26 11:09:39 +00004463 exported_java_libs: ["libfoo", "libbar"],
Paul Duffin064b70c2020-11-02 17:32:38 +00004464 }
4465
4466 java_import {
4467 name: "libfoo",
Paul Duffin092153d2021-01-26 11:42:39 +00004468 prefer: true,
Paul Duffin064b70c2020-11-02 17:32:38 +00004469 jars: ["libfoo.jar"],
4470 }
4471
4472 java_library {
4473 name: "libfoo",
4474 }
Paul Duffin39853512021-02-26 11:09:39 +00004475
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 Duffin064b70c2020-11-02 17:32:38 +00004489 `
4490
4491 // Make sure that dexpreopt can access dex implementation files from the prebuilt.
4492 ctx := testDexpreoptWithApexes(t, bp, "", transform)
4493
Paul Duffin89886cb2021-02-05 16:44:03 +00004494 checkDexJarBuildPath(t, ctx, "prebuilt_libfoo")
Paul Duffin39853512021-02-26 11:09:39 +00004495 ensureNoSourceVariant(t, ctx, "libfoo")
4496
4497 checkDexJarBuildPath(t, ctx, "prebuilt_libbar")
4498 ensureNoSourceVariant(t, ctx, "libbar")
Paul Duffin064b70c2020-11-02 17:32:38 +00004499 })
4500}
4501
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004502func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
4503 transform := func(config *dexpreopt.GlobalConfig) {
Paul Duffin37856732021-02-26 14:24:15 +00004504 config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo", "myapex:libbar"})
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004505 }
4506
Paul Duffin37856732021-02-26 14:24:15 +00004507 checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) {
4508 t.Helper()
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004509 s := ctx.SingletonForTests("dex_bootjars")
4510 foundLibfooJar := false
Paul Duffin37856732021-02-26 14:24:15 +00004511 base := stem + ".jar"
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004512 for _, output := range s.AllOutputs() {
Paul Duffin37856732021-02-26 14:24:15 +00004513 if filepath.Base(output) == base {
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004514 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 Duffin4fd997b2021-02-03 20:06:33 +00004527 checkHiddenAPIIndexInputs := func(t *testing.T, ctx *android.TestContext, expectedInputs string) {
Paul Duffin37856732021-02-26 14:24:15 +00004528 t.Helper()
Paul Duffin4fd997b2021-02-03 20:06:33 +00004529 hiddenAPIIndex := ctx.SingletonForTests("hiddenapi_index")
4530 indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index")
4531 java.CheckHiddenAPIRuleInputs(t, expectedInputs, indexRule)
4532 }
4533
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004534 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 Duffin37856732021-02-26 14:24:15 +00004546 exported_java_libs: ["libfoo", "libbar"],
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004547 }
4548
4549 java_import {
4550 name: "libfoo",
4551 jars: ["libfoo.jar"],
4552 apex_available: ["myapex"],
4553 }
Paul Duffin37856732021-02-26 14:24:15 +00004554
4555 java_sdk_library_import {
4556 name: "libbar",
4557 public: {
4558 jars: ["libbar.jar"],
4559 },
4560 apex_available: ["myapex"],
4561 }
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004562 `
4563
4564 ctx := testDexpreoptWithApexes(t, bp, "", transform)
Paul Duffin37856732021-02-26 14:24:15 +00004565 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 Duffin4fd997b2021-02-03 20:06:33 +00004567
Paul Duffin9d67ca62021-02-03 20:06:33 +00004568 // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file.
4569 checkHiddenAPIIndexInputs(t, ctx, `
Paul Duffin37856732021-02-26 14:24:15 +00004570.intermediates/libbar/android_common_myapex/hiddenapi/index.csv
Paul Duffin9d67ca62021-02-03 20:06:33 +00004571.intermediates/libfoo/android_common_myapex/hiddenapi/index.csv
4572`)
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004573 })
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 Duffin37856732021-02-26 14:24:15 +00004587 exported_java_libs: ["libfoo", "libbar"],
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004588 }
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 Duffin37856732021-02-26 14:24:15 +00004601
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 Stjernholm1dc0d6d2021-01-17 21:05:12 +00004616 `
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 Duffin37856732021-02-26 14:24:15 +00004638 exported_java_libs: ["libfoo", "libbar"],
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004639 }
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 Duffin37856732021-02-26 14:24:15 +00004653
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 Stjernholm1dc0d6d2021-01-17 21:05:12 +00004669 `
4670
4671 ctx := testDexpreoptWithApexes(t, bp, "", transform)
Paul Duffin37856732021-02-26 14:24:15 +00004672 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 Duffin4fd997b2021-02-03 20:06:33 +00004674
Paul Duffin9d67ca62021-02-03 20:06:33 +00004675 // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file.
4676 checkHiddenAPIIndexInputs(t, ctx, `
Paul Duffin37856732021-02-26 14:24:15 +00004677.intermediates/prebuilt_libbar/android_common_myapex/hiddenapi/index.csv
Paul Duffin9d67ca62021-02-03 20:06:33 +00004678.intermediates/prebuilt_libfoo/android_common_myapex/hiddenapi/index.csv
4679`)
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004680 })
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 Duffin37856732021-02-26 14:24:15 +00004687 java_libs: ["libfoo", "libbar"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004688 updatable: false,
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004689 }
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 Duffin37856732021-02-26 14:24:15 +00004707 exported_java_libs: ["libfoo", "libbar"],
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004708 }
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 Duffin37856732021-02-26 14:24:15 +00004721
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 Stjernholm1dc0d6d2021-01-17 21:05:12 +00004736 `
4737
4738 ctx := testDexpreoptWithApexes(t, bp, "", transform)
Paul Duffin37856732021-02-26 14:24:15 +00004739 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 Duffin4fd997b2021-02-03 20:06:33 +00004741
4742 // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file.
4743 checkHiddenAPIIndexInputs(t, ctx, `
Paul Duffin37856732021-02-26 14:24:15 +00004744.intermediates/libbar/android_common_myapex/hiddenapi/index.csv
Paul Duffin4fd997b2021-02-03 20:06:33 +00004745.intermediates/libfoo/android_common_apex10000/hiddenapi/index.csv
4746`)
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004747 })
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 Duffin37856732021-02-26 14:24:15 +00004774 exported_java_libs: ["libfoo", "libbar"],
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004775 }
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 Duffin37856732021-02-26 14:24:15 +00004789
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 Stjernholm1dc0d6d2021-01-17 21:05:12 +00004805 `
4806
4807 ctx := testDexpreoptWithApexes(t, bp, "", transform)
Paul Duffin37856732021-02-26 14:24:15 +00004808 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 Duffin4fd997b2021-02-03 20:06:33 +00004810
Paul Duffin9d67ca62021-02-03 20:06:33 +00004811 // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file.
4812 checkHiddenAPIIndexInputs(t, ctx, `
Paul Duffin37856732021-02-26 14:24:15 +00004813.intermediates/prebuilt_libbar/android_common_prebuilt_myapex/hiddenapi/index.csv
Paul Duffin9d67ca62021-02-03 20:06:33 +00004814.intermediates/prebuilt_libfoo/android_common_prebuilt_myapex/hiddenapi/index.csv
4815`)
Martin Stjernholm1dc0d6d2021-01-17 21:05:12 +00004816 })
4817}
4818
Roland Levillain630846d2019-06-26 12:48:34 +01004819func TestApexWithTests(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08004820 ctx := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01004821 apex_test {
4822 name: "myapex",
4823 key: "myapex.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004824 updatable: false,
Roland Levillain630846d2019-06-26 12:48:34 +01004825 tests: [
4826 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01004827 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01004828 ],
4829 }
4830
4831 apex_key {
4832 name: "myapex.key",
4833 public_key: "testkey.avbpubkey",
4834 private_key: "testkey.pem",
4835 }
4836
Liz Kammer1c14a212020-05-12 15:26:55 -07004837 filegroup {
4838 name: "fg",
4839 srcs: [
4840 "baz",
4841 "bar/baz"
4842 ],
4843 }
4844
Roland Levillain630846d2019-06-26 12:48:34 +01004845 cc_test {
4846 name: "mytest",
4847 gtest: false,
4848 srcs: ["mytest.cpp"],
4849 relative_install_path: "test",
Jiyong Parkaf9539f2020-05-04 10:31:32 +09004850 shared_libs: ["mylib"],
Roland Levillain630846d2019-06-26 12:48:34 +01004851 system_shared_libs: [],
4852 static_executable: true,
4853 stl: "none",
Liz Kammer1c14a212020-05-12 15:26:55 -07004854 data: [":fg"],
Roland Levillain630846d2019-06-26 12:48:34 +01004855 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01004856
Jiyong Parkaf9539f2020-05-04 10:31:32 +09004857 cc_library {
4858 name: "mylib",
4859 srcs: ["mylib.cpp"],
4860 system_shared_libs: [],
4861 stl: "none",
4862 }
4863
Liz Kammer5bd365f2020-05-27 15:15:11 -07004864 filegroup {
4865 name: "fg2",
4866 srcs: [
4867 "testdata/baz"
4868 ],
4869 }
4870
Roland Levillain9b5fde92019-06-28 15:41:19 +01004871 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 Kammer5bd365f2020-05-27 15:15:11 -07004884 data: [
4885 ":fg",
4886 ":fg2",
4887 ],
Roland Levillain9b5fde92019-06-28 15:41:19 +01004888 }
Roland Levillain630846d2019-06-26 12:48:34 +01004889 `)
4890
Sundong Ahnabb64432019-10-22 13:58:29 +09004891 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01004892 copyCmds := apexRule.Args["copy_commands"]
4893
Jiyong Parkaf9539f2020-05-04 10:31:32 +09004894 // Ensure that test dep (and their transitive dependencies) are copied into apex.
Roland Levillain630846d2019-06-26 12:48:34 +01004895 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Jiyong Parkaf9539f2020-05-04 10:31:32 +09004896 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Roland Levillain9b5fde92019-06-28 15:41:19 +01004897
Liz Kammer1c14a212020-05-12 15:26:55 -07004898 //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 Levillain9b5fde92019-06-28 15:41:19 +01004902 // 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 Levillainf89cd092019-07-29 16:22:59 +01004906
4907 // Ensure the module is correctly translated.
Liz Kammer81faaaf2020-05-20 09:57:08 -07004908 bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Colin Crossaa255532020-07-03 13:18:24 -07004909 data := android.AndroidMkDataForTest(t, ctx, bundle)
Liz Kammer81faaaf2020-05-20 09:57:08 -07004910 name := bundle.BaseModuleName()
Roland Levillainf89cd092019-07-29 16:22:59 +01004911 prefix := "TARGET_"
4912 var builder strings.Builder
4913 data.Custom(&builder, name, prefix, "", data)
4914 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09004915 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 Han214bf372019-11-12 13:03:50 +09004919 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
Jooyung Han31c470b2019-10-18 16:26:59 +09004920 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01004921 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Liz Kammer81faaaf2020-05-20 09:57:08 -07004922
4923 flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
Colin Crossaa255532020-07-03 13:18:24 -07004924 data = android.AndroidMkDataForTest(t, ctx, flatBundle)
Liz Kammer81faaaf2020-05-20 09:57:08 -07004925 data.Custom(&builder, name, prefix, "", data)
4926 flatAndroidMk := builder.String()
Liz Kammer5bd365f2020-05-27 15:15:11 -07004927 ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n")
4928 ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n")
Roland Levillain630846d2019-06-26 12:48:34 +01004929}
4930
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09004931func TestInstallExtraFlattenedApexes(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08004932 ctx := testApex(t, `
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09004933 apex {
4934 name: "myapex",
4935 key: "myapex.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00004936 updatable: false,
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09004937 }
4938 apex_key {
4939 name: "myapex.key",
4940 public_key: "testkey.avbpubkey",
4941 private_key: "testkey.pem",
4942 }
Paul Duffin0a49fdc2021-03-08 11:28:25 +00004943 `,
4944 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
4945 variables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
4946 }),
4947 )
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09004948 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Jiyong Park83dc74b2020-01-14 18:38:44 +09004949 ensureListContains(t, ab.requiredDeps, "myapex.flattened")
Colin Crossaa255532020-07-03 13:18:24 -07004950 mk := android.AndroidMkDataForTest(t, ctx, ab)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09004951 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 Hand48f3c32019-08-23 11:18:57 +09004957func 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 Han5e9013b2020-03-10 06:23:13 +09004976 apex_available: ["myapex"],
Jooyung Hand48f3c32019-08-23 11:18:57 +09004977 }
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 Hand48f3c32019-08-23 11:18:57 +09004997 enabled: false,
Jooyung Han5e9013b2020-03-10 06:23:13 +09004998 apex_available: ["myapex"],
Jooyung Hand48f3c32019-08-23 11:18:57 +09004999 }
5000 `)
5001}
5002
Bill Peckhama41a6962021-01-11 10:58:54 -08005003func TestApexWithJavaImport(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005004 ctx := testApex(t, `
Bill Peckhama41a6962021-01-11 10:58:54 -08005005 apex {
5006 name: "myapex",
5007 key: "myapex.key",
5008 java_libs: ["myjavaimport"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005009 updatable: false,
Bill Peckhama41a6962021-01-11 10:58:54 -08005010 }
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 Ahne1f05aa2019-08-27 13:55:42 +09005032func TestApexWithApps(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005033 ctx := testApex(t, `
Sundong Ahne1f05aa2019-08-27 13:55:42 +09005034 apex {
5035 name: "myapex",
5036 key: "myapex.key",
5037 apps: [
5038 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09005039 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09005040 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005041 updatable: false,
Sundong Ahne1f05aa2019-08-27 13:55:42 +09005042 }
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 Cross094cde42020-02-15 10:38:00 -08005053 sdk_version: "current",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09005054 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09005055 jni_libs: ["libjni"],
Colin Cross094cde42020-02-15 10:38:00 -08005056 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00005057 apex_available: [ "myapex" ],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09005058 }
Jiyong Parkf7487312019-10-17 12:54:30 +09005059
5060 android_app {
5061 name: "AppFooPriv",
5062 srcs: ["foo/bar/MyClass.java"],
Colin Cross094cde42020-02-15 10:38:00 -08005063 sdk_version: "current",
Jiyong Parkf7487312019-10-17 12:54:30 +09005064 system_modules: "none",
5065 privileged: true,
Colin Cross094cde42020-02-15 10:38:00 -08005066 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00005067 apex_available: [ "myapex" ],
Jiyong Parkf7487312019-10-17 12:54:30 +09005068 }
Jiyong Park8be103b2019-11-08 15:53:48 +09005069
5070 cc_library_shared {
5071 name: "libjni",
5072 srcs: ["mylib.cpp"],
Jooyung Hanb7bebe22020-02-25 16:59:29 +09005073 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 Park8be103b2019-11-08 15:53:48 +09005082 stl: "none",
5083 system_shared_libs: [],
Jiyong Park0f80c182020-01-31 02:49:53 +09005084 apex_available: [ "myapex" ],
Colin Cross094cde42020-02-15 10:38:00 -08005085 sdk_version: "current",
Jiyong Park8be103b2019-11-08 15:53:48 +09005086 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09005087 `)
5088
Sundong Ahnabb64432019-10-22 13:58:29 +09005089 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09005090 apexRule := module.Rule("apexRule")
5091 copyCmds := apexRule.Args["copy_commands"]
5092
5093 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09005094 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park52cd06f2019-11-11 10:14:32 +09005095
Colin Crossaede88c2020-08-11 12:17:01 -07005096 appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs")
Jooyung Hanb7bebe22020-02-25 16:59:29 +09005097 // JNI libraries are uncompressed
Jiyong Park52cd06f2019-11-11 10:14:32 +09005098 if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09005099 t.Errorf("jni libs are not uncompressed for AppFoo")
Jiyong Park52cd06f2019-11-11 10:14:32 +09005100 }
Jooyung Hanb7bebe22020-02-25 16:59:29 +09005101 // JNI libraries including transitive deps are
5102 for _, jni := range []string{"libjni", "libfoo"} {
Paul Duffinafdd4062021-03-30 19:44:07 +01005103 jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_sdk_shared_apex10000").Module().(*cc.Module).OutputFile().RelativeToTop()
Jooyung Hanb7bebe22020-02-25 16:59:29 +09005104 // ... 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 Frenicde2a032019-10-27 00:29:22 +01005109}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09005110
Dario Frenicde2a032019-10-27 00:29:22 +01005111func TestApexWithAppImports(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005112 ctx := testApex(t, `
Dario Frenicde2a032019-10-27 00:29:22 +01005113 apex {
5114 name: "myapex",
5115 key: "myapex.key",
5116 apps: [
5117 "AppFooPrebuilt",
5118 "AppFooPrivPrebuilt",
5119 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005120 updatable: false,
Dario Frenicde2a032019-10-27 00:29:22 +01005121 }
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 Park592a6a42020-04-21 22:34:28 +09005136 apex_available: ["myapex"],
Dario Frenicde2a032019-10-27 00:29:22 +01005137 }
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 Han39ee1192020-03-23 20:21:11 +09005147 filename: "AwesomePrebuiltAppFooPriv.apk",
Jiyong Park592a6a42020-04-21 22:34:28 +09005148 apex_available: ["myapex"],
Dario Frenicde2a032019-10-27 00:29:22 +01005149 }
5150 `)
5151
Sundong Ahnabb64432019-10-22 13:58:29 +09005152 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01005153 apexRule := module.Rule("apexRule")
5154 copyCmds := apexRule.Args["copy_commands"]
5155
5156 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
Jooyung Han39ee1192020-03-23 20:21:11 +09005157 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk")
5158}
5159
5160func TestApexWithAppImportsPrefer(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005161 ctx := testApex(t, `
Jooyung Han39ee1192020-03-23 20:21:11 +09005162 apex {
5163 name: "myapex",
5164 key: "myapex.key",
5165 apps: [
5166 "AppFoo",
5167 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005168 updatable: false,
Jooyung Han39ee1192020-03-23 20:21:11 +09005169 }
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 Park592a6a42020-04-21 22:34:28 +09005191 apex_available: ["myapex"],
Jooyung Han39ee1192020-03-23 20:21:11 +09005192 }
5193 `, withFiles(map[string][]byte{
5194 "AppFooPrebuilt.apk": nil,
5195 }))
5196
5197 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han86feead2021-03-08 13:11:48 +09005198 "app/AppFoo/AppFooPrebuilt.apk",
Jooyung Han39ee1192020-03-23 20:21:11 +09005199 })
Sundong Ahne1f05aa2019-08-27 13:55:42 +09005200}
5201
Dario Freni6f3937c2019-12-20 22:58:03 +00005202func TestApexWithTestHelperApp(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005203 ctx := testApex(t, `
Dario Freni6f3937c2019-12-20 22:58:03 +00005204 apex {
5205 name: "myapex",
5206 key: "myapex.key",
5207 apps: [
5208 "TesterHelpAppFoo",
5209 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005210 updatable: false,
Dario Freni6f3937c2019-12-20 22:58:03 +00005211 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00005222 apex_available: [ "myapex" ],
Dario Freni6f3937c2019-12-20 22:58:03 +00005223 }
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 Han18020ea2019-11-13 10:50:48 +09005234func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
5235 // libfoo's apex_available comes from cc_defaults
Steven Moreland6e36cd62020-10-22 01:08:35 +00005236 testApexError(t, `requires "libfoo" that doesn't list the APEX under 'apex_available'.`, `
Jooyung Han18020ea2019-11-13 10:50:48 +09005237 apex {
5238 name: "myapex",
5239 key: "myapex.key",
5240 native_shared_libs: ["libfoo"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005241 updatable: false,
Jooyung Han18020ea2019-11-13 10:50:48 +09005242 }
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 Inwoodf8dcf5e2021-02-16 11:40:16 +00005254 updatable: false,
Jooyung Han18020ea2019-11-13 10:50:48 +09005255 }
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 Duffine52e66f2020-03-30 17:54:29 +01005270func TestApexAvailable_DirectDep(t *testing.T) {
Jiyong Park127b40b2019-09-30 16:04:35 +09005271 // libfoo is not available to myapex, but only to otherapex
Steven Moreland6e36cd62020-10-22 01:08:35 +00005272 testApexError(t, "requires \"libfoo\" that doesn't list the APEX under 'apex_available'.", `
Jiyong Park127b40b2019-09-30 16:04:35 +09005273 apex {
5274 name: "myapex",
5275 key: "myapex.key",
5276 native_shared_libs: ["libfoo"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005277 updatable: false,
Jiyong Park127b40b2019-09-30 16:04:35 +09005278 }
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 Inwoodf8dcf5e2021-02-16 11:40:16 +00005290 updatable: false,
Jiyong Park127b40b2019-09-30 16:04:35 +09005291 }
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 Duffine52e66f2020-03-30 17:54:29 +01005305}
Jiyong Park127b40b2019-09-30 16:04:35 +09005306
Paul Duffine52e66f2020-03-30 17:54:29 +01005307func TestApexAvailable_IndirectDep(t *testing.T) {
Jooyung Han5e9013b2020-03-10 06:23:13 +09005308 // libbbaz is an indirect dep
Jiyong Park767dbd92021-03-04 13:03:10 +09005309 testApexError(t, `requires "libbaz" that doesn't list the APEX under 'apex_available'.\n\nDependency path:
Colin Cross6e511a92020-07-27 21:26:48 -07005310.*via tag apex\.dependencyTag.*name:sharedLib.*
Paul Duffindf915ff2020-03-30 17:58:21 +01005311.*-> libfoo.*link:shared.*
Colin Cross6e511a92020-07-27 21:26:48 -07005312.*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.*
Paul Duffindf915ff2020-03-30 17:58:21 +01005313.*-> libbar.*link:shared.*
Colin Cross6e511a92020-07-27 21:26:48 -07005314.*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.*
Paul Duffin65347702020-03-31 15:23:40 +01005315.*-> libbaz.*link:shared.*`, `
Jiyong Park127b40b2019-09-30 16:04:35 +09005316 apex {
5317 name: "myapex",
5318 key: "myapex.key",
5319 native_shared_libs: ["libfoo"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005320 updatable: false,
Jiyong Park127b40b2019-09-30 16:04:35 +09005321 }
5322
5323 apex_key {
5324 name: "myapex.key",
5325 public_key: "testkey.avbpubkey",
5326 private_key: "testkey.pem",
5327 }
5328
Jiyong Park127b40b2019-09-30 16:04:35 +09005329 cc_library {
5330 name: "libfoo",
5331 stl: "none",
5332 shared_libs: ["libbar"],
5333 system_shared_libs: [],
Jooyung Han5e9013b2020-03-10 06:23:13 +09005334 apex_available: ["myapex"],
Jiyong Park127b40b2019-09-30 16:04:35 +09005335 }
5336
5337 cc_library {
5338 name: "libbar",
5339 stl: "none",
Jooyung Han5e9013b2020-03-10 06:23:13 +09005340 shared_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09005341 system_shared_libs: [],
Jooyung Han5e9013b2020-03-10 06:23:13 +09005342 apex_available: ["myapex"],
5343 }
5344
5345 cc_library {
5346 name: "libbaz",
5347 stl: "none",
5348 system_shared_libs: [],
Jiyong Park127b40b2019-09-30 16:04:35 +09005349 }`)
Paul Duffine52e66f2020-03-30 17:54:29 +01005350}
Jiyong Park127b40b2019-09-30 16:04:35 +09005351
Paul Duffine52e66f2020-03-30 17:54:29 +01005352func TestApexAvailable_InvalidApexName(t *testing.T) {
Jiyong Park127b40b2019-09-30 16:04:35 +09005353 testApexError(t, "\"otherapex\" is not a valid module name", `
5354 apex {
5355 name: "myapex",
5356 key: "myapex.key",
5357 native_shared_libs: ["libfoo"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005358 updatable: false,
Jiyong Park127b40b2019-09-30 16:04:35 +09005359 }
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 Duffine52e66f2020-03-30 17:54:29 +01005374 testApex(t, `
Jiyong Park127b40b2019-09-30 16:04:35 +09005375 apex {
5376 name: "myapex",
5377 key: "myapex.key",
5378 native_shared_libs: ["libfoo", "libbar"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005379 updatable: false,
Jiyong Park127b40b2019-09-30 16:04:35 +09005380 }
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 Park323a4c32020-03-01 17:29:06 +09005392 runtime_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09005393 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 Park323a4c32020-03-01 17:29:06 +09005401 }
5402
5403 cc_library {
5404 name: "libbaz",
5405 stl: "none",
5406 system_shared_libs: [],
5407 stubs: {
5408 versions: ["10", "20", "30"],
5409 },
Jiyong Park127b40b2019-09-30 16:04:35 +09005410 }`)
Paul Duffine52e66f2020-03-30 17:54:29 +01005411}
Jiyong Park127b40b2019-09-30 16:04:35 +09005412
Jiyong Park89e850a2020-04-07 16:37:39 +09005413func TestApexAvailable_CheckForPlatform(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005414 ctx := testApex(t, `
Jiyong Park127b40b2019-09-30 16:04:35 +09005415 apex {
5416 name: "myapex",
5417 key: "myapex.key",
Jiyong Park89e850a2020-04-07 16:37:39 +09005418 native_shared_libs: ["libbar", "libbaz"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005419 updatable: false,
Jiyong Park127b40b2019-09-30 16:04:35 +09005420 }
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 Park89e850a2020-04-07 16:37:39 +09005432 shared_libs: ["libbar"],
Jiyong Park127b40b2019-09-30 16:04:35 +09005433 apex_available: ["//apex_available:platform"],
Jiyong Park89e850a2020-04-07 16:37:39 +09005434 }
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 Park127b40b2019-09-30 16:04:35 +09005459 }`)
5460
Jiyong Park89e850a2020-04-07 16:37:39 +09005461 // 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 Duffine52e66f2020-03-30 17:54:29 +01005474}
Jiyong Parka90ca002019-10-07 15:47:24 +09005475
Paul Duffine52e66f2020-03-30 17:54:29 +01005476func TestApexAvailable_CreatedForApex(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005477 ctx := testApex(t, `
Jiyong Parka90ca002019-10-07 15:47:24 +09005478 apex {
5479 name: "myapex",
5480 key: "myapex.key",
5481 native_shared_libs: ["libfoo"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005482 updatable: false,
Jiyong Parka90ca002019-10-07 15:47:24 +09005483 }
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 Park89e850a2020-04-07 16:37:39 +09005501 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 Park127b40b2019-09-30 16:04:35 +09005509}
5510
Jiyong Park5d790c32019-11-15 18:40:32 +09005511func TestOverrideApex(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005512 ctx := testApex(t, `
Jiyong Park5d790c32019-11-15 18:40:32 +09005513 apex {
5514 name: "myapex",
5515 key: "myapex.key",
5516 apps: ["app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08005517 overrides: ["oldapex"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005518 updatable: false,
Jiyong Park5d790c32019-11-15 18:40:32 +09005519 }
5520
5521 override_apex {
5522 name: "override_myapex",
5523 base: "myapex",
5524 apps: ["override_app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08005525 overrides: ["unknownapex"],
Baligh Uddin004d7172020-02-19 21:29:28 -08005526 logging_parent: "com.foo.bar",
Baligh Uddin5b57dba2020-03-15 13:01:05 -07005527 package_name: "test.overridden.package",
Jiyong Park5d790c32019-11-15 18:40:32 +09005528 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00005542 apex_available: [ "myapex" ],
Jiyong Park5d790c32019-11-15 18:40:32 +09005543 }
5544
5545 override_android_app {
5546 name: "override_app",
5547 base: "app",
5548 package_name: "bar",
5549 }
Jiyong Park20bacab2020-03-03 11:45:41 +09005550 `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"}))
Jiyong Park5d790c32019-11-15 18:40:32 +09005551
Jiyong Park317645e2019-12-05 13:20:58 +09005552 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 Park5d790c32019-11-15 18:40:32 +09005561 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 Han39ee1192020-03-23 20:21:11 +09005566 ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08005567
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 Uddin004d7172020-02-19 21:29:28 -08005574 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 Park20bacab2020-03-03 11:45:41 +09005578 optFlags := apexRule.Args["opt_flags"]
Baligh Uddin5b57dba2020-03-15 13:01:05 -07005579 ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package")
Jiyong Park20bacab2020-03-03 11:45:41 +09005580
Colin Crossaa255532020-07-03 13:18:24 -07005581 data := android.AndroidMkDataForTest(t, ctx, apexBundle)
Jaewoong Jung1670ca02019-11-22 14:50:42 -08005582 var builder strings.Builder
5583 data.Custom(&builder, name, "TARGET_", "", data)
5584 androidMk := builder.String()
Jiyong Parkf653b052019-11-18 15:39:01 +09005585 ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08005586 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
5587 ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08005588 ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08005589 ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
Jiyong Parkf653b052019-11-18 15:39:01 +09005590 ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08005591 ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
5592 ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
Jiyong Park5d790c32019-11-15 18:40:32 +09005593}
5594
Jooyung Han214bf372019-11-12 13:03:50 +09005595func TestLegacyAndroid10Support(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005596 ctx := testApex(t, `
Jooyung Han214bf372019-11-12 13:03:50 +09005597 apex {
5598 name: "myapex",
5599 key: "myapex.key",
Peter Collingbournedc4f9862020-02-12 17:13:25 -08005600 native_shared_libs: ["mylib"],
Jooyung Han5417f772020-03-12 18:37:20 +09005601 min_sdk_version: "29",
Jooyung Han214bf372019-11-12 13:03:50 +09005602 }
5603
5604 apex_key {
5605 name: "myapex.key",
5606 public_key: "testkey.avbpubkey",
5607 private_key: "testkey.pem",
5608 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08005609
5610 cc_library {
5611 name: "mylib",
5612 srcs: ["mylib.cpp"],
5613 stl: "libc++",
5614 system_shared_libs: [],
5615 apex_available: [ "myapex" ],
Jooyung Han749dc692020-04-15 11:03:39 +09005616 min_sdk_version: "29",
Peter Collingbournedc4f9862020-02-12 17:13:25 -08005617 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08005618 `, withUnbundledBuild)
Jooyung Han214bf372019-11-12 13:03:50 +09005619
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 Frenie3546902020-01-14 23:50:25 +00005623 ensureNotContains(t, args["opt_flags"], "--no_hashtree")
Peter Collingbournedc4f9862020-02-12 17:13:25 -08005624
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 Crossaede88c2020-08-11 12:17:01 -07005630 apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_apex29").Rule("ld").Implicits
Peter Collingbournedc4f9862020-02-12 17:13:25 -08005631 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 Han214bf372019-11-12 13:03:50 +09005636}
5637
Paul Duffine05480a2021-03-08 15:07:14 +00005638var filesForSdkLibrary = android.MockFS{
Paul Duffin9b879592020-05-26 13:21:35 +01005639 "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 Duffineedc5d52020-06-12 17:46:39 +01005645
Anton Hanssondff2c782020-12-21 17:10:01 +00005646 "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 Duffineedc5d52020-06-12 17:46:39 +01005651 // For java_sdk_library_import
5652 "a.jar": nil,
Paul Duffin9b879592020-05-26 13:21:35 +01005653}
5654
Jooyung Han58f26ab2019-12-18 15:34:32 +09005655func TestJavaSDKLibrary(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005656 ctx := testApex(t, `
Jooyung Han58f26ab2019-12-18 15:34:32 +09005657 apex {
5658 name: "myapex",
5659 key: "myapex.key",
5660 java_libs: ["foo"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005661 updatable: false,
Jooyung Han58f26ab2019-12-18 15:34:32 +09005662 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00005674 apex_available: [ "myapex" ],
Jooyung Han58f26ab2019-12-18 15:34:32 +09005675 }
Anton Hanssondff2c782020-12-21 17:10:01 +00005676
5677 prebuilt_apis {
5678 name: "sdk",
5679 api_dirs: ["100"],
5680 }
Paul Duffin9b879592020-05-26 13:21:35 +01005681 `, withFiles(filesForSdkLibrary))
Jooyung Han58f26ab2019-12-18 15:34:32 +09005682
5683 // java_sdk_library installs both impl jar and permission XML
Jooyung Hana57af4a2020-01-23 05:36:59 +00005684 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han58f26ab2019-12-18 15:34:32 +09005685 "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 Parke3833882020-02-17 17:28:10 +09005689 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 Han58f26ab2019-12-18 15:34:32 +09005691}
5692
Paul Duffin9b879592020-05-26 13:21:35 +01005693func TestJavaSDKLibrary_WithinApex(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005694 ctx := testApex(t, `
Paul Duffin9b879592020-05-26 13:21:35 +01005695 apex {
5696 name: "myapex",
5697 key: "myapex.key",
5698 java_libs: ["foo", "bar"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005699 updatable: false,
Paul Duffin9b879592020-05-26 13:21:35 +01005700 }
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 Hanssondff2c782020-12-21 17:10:01 +00005725
5726 prebuilt_apis {
5727 name: "sdk",
5728 api_dirs: ["100"],
5729 }
Paul Duffin9b879592020-05-26 13:21:35 +01005730 `, 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 Duffincf8d7db2021-03-29 00:29:53 +01005741 if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) {
Paul Duffin9b879592020-05-26 13:21:35 +01005742 t.Errorf("expected %q, found %#q", expected, actual)
5743 }
5744}
5745
5746func TestJavaSDKLibrary_CrossBoundary(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005747 ctx := testApex(t, `
Paul Duffin9b879592020-05-26 13:21:35 +01005748 apex {
5749 name: "myapex",
5750 key: "myapex.key",
5751 java_libs: ["foo"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005752 updatable: false,
Paul Duffin9b879592020-05-26 13:21:35 +01005753 }
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 Hanssondff2c782020-12-21 17:10:01 +00005777
5778 prebuilt_apis {
5779 name: "sdk",
5780 api_dirs: ["100"],
5781 }
Paul Duffin9b879592020-05-26 13:21:35 +01005782 `, 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 Duffincf8d7db2021-03-29 00:29:53 +01005792 if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) {
Paul Duffin9b879592020-05-26 13:21:35 +01005793 t.Errorf("expected %q, found %#q", expected, actual)
5794 }
5795}
5796
Paul Duffineedc5d52020-06-12 17:46:39 +01005797func TestJavaSDKLibrary_ImportPreferred(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005798 ctx := testApex(t, `
Anton Hanssondff2c782020-12-21 17:10:01 +00005799 prebuilt_apis {
5800 name: "sdk",
5801 api_dirs: ["100"],
5802 }`,
Paul Duffineedc5d52020-06-12 17:46:39 +01005803 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 Inwoodf8dcf5e2021-02-16 11:40:16 +00005815 updatable: false,
Paul Duffineedc5d52020-06-12 17:46:39 +01005816 }
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 Hanssondff2c782020-12-21 17:10:01 +00005870 }), withFiles(filesForSdkLibrary),
Paul Duffineedc5d52020-06-12 17:46:39 +01005871 )
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 Duffincf8d7db2021-03-29 00:29:53 +01005882 if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.impl\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) {
Paul Duffineedc5d52020-06-12 17:46:39 +01005883 t.Errorf("expected %q, found %#q", expected, actual)
5884 }
5885}
5886
5887func 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 Inwoodf8dcf5e2021-02-16 11:40:16 +00005893 updatable: false,
Paul Duffineedc5d52020-06-12 17:46:39 +01005894 }
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
atrost6e126252020-01-27 17:01:16 +00005914func TestCompatConfig(t *testing.T) {
Paul Duffina369c7b2021-03-09 03:08:05 +00005915 result := apexFixtureFactory.
5916 Extend(java.PrepareForTestWithPlatformCompatConfig).
5917 RunTestWithBp(t, `
atrost6e126252020-01-27 17:01:16 +00005918 apex {
5919 name: "myapex",
5920 key: "myapex.key",
Paul Duffin3abc1742021-03-15 19:32:23 +00005921 compat_configs: ["myjar-platform-compat-config"],
atrost6e126252020-01-27 17:01:16 +00005922 java_libs: ["myjar"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005923 updatable: false,
atrost6e126252020-01-27 17:01:16 +00005924 }
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",
atrost6e126252020-01-27 17:01:16 +00005942 apex_available: [ "myapex" ],
5943 }
Paul Duffin1b29e002021-03-16 15:06:54 +00005944
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 }
atrost6e126252020-01-27 17:01:16 +00005951 `)
Paul Duffina369c7b2021-03-09 03:08:05 +00005952 ctx := result.TestContext
atrost6e126252020-01-27 17:01:16 +00005953 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 Park479321d2019-12-16 11:47:12 +09005959func 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 Inwoodf8dcf5e2021-02-16 11:40:16 +00005965 updatable: false,
Jiyong Park479321d2019-12-16 11:47:12 +09005966 }
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 Park6b21c7d2020-02-11 09:16:01 +09005979 compile_dex: false,
Jooyung Han5e9013b2020-03-10 06:23:13 +09005980 apex_available: ["myapex"],
Jiyong Park479321d2019-12-16 11:47:12 +09005981 }
5982 `)
5983}
5984
Jiyong Park7afd1072019-12-30 16:56:33 +09005985func TestCarryRequiredModuleNames(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08005986 ctx := testApex(t, `
Jiyong Park7afd1072019-12-30 16:56:33 +09005987 apex {
5988 name: "myapex",
5989 key: "myapex.key",
5990 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00005991 updatable: false,
Jiyong Park7afd1072019-12-30 16:56:33 +09005992 }
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 Hanssoneec79eb2020-01-10 15:12:39 +00006008 apex_available: [ "myapex" ],
Jiyong Park7afd1072019-12-30 16:56:33 +09006009 }
6010 `)
6011
6012 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Colin Crossaa255532020-07-03 13:18:24 -07006013 data := android.AndroidMkDataForTest(t, ctx, apexBundle)
Jiyong Park7afd1072019-12-30 16:56:33 +09006014 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 Park7cd10e32020-01-14 09:22:18 +09006024func 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 Inwoodf8dcf5e2021-02-16 11:40:16 +00006031 updatable: false,
Jiyong Park7cd10e32020-01-14 09:22:18 +09006032 }
6033
Jiyong Park9d677202020-02-19 16:29:35 +09006034 apex {
6035 name: "myapex.updatable",
6036 key: "myapex.key",
6037 native_shared_libs: ["mylib"],
6038 java_libs: ["myjar"],
6039 updatable: true,
Jooyung Han548640b2020-04-27 12:10:30 +09006040 min_sdk_version: "current",
Jiyong Park9d677202020-02-19 16:29:35 +09006041 }
6042
Jiyong Park7cd10e32020-01-14 09:22:18 +09006043 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 Park9d677202020-02-19 16:29:35 +09006057 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09006058 "//apex_available:platform",
6059 ],
Jooyung Han749dc692020-04-15 11:03:39 +09006060 min_sdk_version: "current",
Jiyong Park7cd10e32020-01-14 09:22:18 +09006061 }
6062
6063 cc_library {
6064 name: "myotherlib",
6065 srcs: ["mylib.cpp"],
6066 system_shared_libs: [],
6067 stl: "none",
6068 apex_available: [
6069 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09006070 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09006071 "//apex_available:platform",
6072 ],
Jooyung Han749dc692020-04-15 11:03:39 +09006073 min_sdk_version: "current",
Jiyong Park7cd10e32020-01-14 09:22:18 +09006074 }
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 Park7cd10e32020-01-14 09:22:18 +09006082 apex_available: [
6083 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09006084 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09006085 "//apex_available:platform",
6086 ],
Jooyung Han749dc692020-04-15 11:03:39 +09006087 min_sdk_version: "current",
Jiyong Park7cd10e32020-01-14 09:22:18 +09006088 }
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 Park9d677202020-02-19 16:29:35 +09006097 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09006098 "//apex_available:platform",
6099 ],
Jooyung Han749dc692020-04-15 11:03:39 +09006100 min_sdk_version: "current",
Jiyong Park7cd10e32020-01-14 09:22:18 +09006101 }
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 Park9d677202020-02-19 16:29:35 +09006128 // For unbundled build, symlink shouldn't exist regardless of whether an APEX
6129 // is updatable or not
Colin Cross1c460562021-02-16 17:55:47 -08006130 ctx := testApex(t, bp, withUnbundledBuild)
Jooyung Hana57af4a2020-01-23 05:36:59 +00006131 files := getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09006132 ensureRealfileExists(t, files, "javalib/myjar.jar")
6133 ensureRealfileExists(t, files, "lib64/mylib.so")
6134 ensureRealfileExists(t, files, "lib64/myotherlib.so")
6135
Jiyong Park9d677202020-02-19 16:29:35 +09006136 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 Cross1c460562021-02-16 17:55:47 -08006142 ctx = testApex(t, bp)
Jooyung Hana57af4a2020-01-23 05:36:59 +00006143 files = getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09006144 ensureRealfileExists(t, files, "javalib/myjar.jar")
6145 ensureRealfileExists(t, files, "lib64/mylib.so")
6146 ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
Jiyong Park9d677202020-02-19 16:29:35 +09006147
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 Park7cd10e32020-01-14 09:22:18 +09006152}
6153
Yo Chiange8128052020-07-23 20:09:18 +08006154func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08006155 ctx := testApex(t, `
Yo Chiange8128052020-07-23 20:09:18 +08006156 apex {
6157 name: "myapex",
6158 key: "myapex.key",
6159 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00006160 updatable: false,
Yo Chiange8128052020-07-23 20:09:18 +08006161 }
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 Crossaa255532020-07-03 13:18:24 -07006194 data := android.AndroidMkDataForTest(t, ctx, apexBundle)
Yo Chiange8128052020-07-23 20:09:18 +08006195 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 Park57621b22021-01-20 20:33:11 +09006203 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += mylib.myapex:64 myotherlib:64 apex_manifest.pb.myapex apex_pubkey.myapex\n")
Yo Chiange8128052020-07-23 20:09:18 +08006204}
6205
Jooyung Han643adc42020-02-27 13:50:06 +09006206func TestApexWithJniLibs(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08006207 ctx := testApex(t, `
Jooyung Han643adc42020-02-27 13:50:06 +09006208 apex {
6209 name: "myapex",
6210 key: "myapex.key",
6211 jni_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00006212 updatable: false,
Jooyung Han643adc42020-02-27 13:50:06 +09006213 }
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 Han49f67012020-04-17 13:43:10 +09006248func TestApexMutatorsDontRunIfDisabled(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08006249 ctx := testApex(t, `
Jooyung Han49f67012020-04-17 13:43:10 +09006250 apex {
6251 name: "myapex",
6252 key: "myapex.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00006253 updatable: false,
Jooyung Han49f67012020-04-17 13:43:10 +09006254 }
6255 apex_key {
6256 name: "myapex.key",
6257 public_key: "testkey.avbpubkey",
6258 private_key: "testkey.pem",
6259 }
Paul Duffin0a49fdc2021-03-08 11:28:25 +00006260 `,
6261 android.FixtureModifyConfig(func(config android.Config) {
6262 delete(config.Targets, android.Android)
6263 config.AndroidCommonTarget = android.Target{}
6264 }),
6265 )
Jooyung Han49f67012020-04-17 13:43:10 +09006266
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 Parkbd159612020-02-28 15:22:21 +09006272func TestAppBundle(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08006273 ctx := testApex(t, `
Jiyong Parkbd159612020-02-28 15:22:21 +09006274 apex {
6275 name: "myapex",
6276 key: "myapex.key",
6277 apps: ["AppFoo"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00006278 updatable: false,
Jiyong Parkbd159612020-02-28 15:22:21 +09006279 }
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 Parkcfaa1642020-02-28 16:51:07 +09006294 `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"}))
Jiyong Parkbd159612020-02-28 15:22:21 +09006295
Colin Crosscf371cc2020-11-13 11:48:42 -08006296 bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json")
Jiyong Parkbd159612020-02-28 15:22:21 +09006297 content := bundleConfigRule.Args["content"]
6298
6299 ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
Jiyong Parkcfaa1642020-02-28 16:51:07 +09006300 ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`)
Jiyong Parkbd159612020-02-28 15:22:21 +09006301}
6302
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006303func TestAppSetBundle(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08006304 ctx := testApex(t, `
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006305 apex {
6306 name: "myapex",
6307 key: "myapex.key",
6308 apps: ["AppSet"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00006309 updatable: false,
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006310 }
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 Crosscf371cc2020-11-13 11:48:42 -08006323 bundleConfigRule := mod.Output("bundle_config.json")
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006324 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 Stepanov2080bfe2020-07-24 15:35:40 -07006336func TestAppSetBundlePrebuilt(t *testing.T) {
Paul Duffin0a49fdc2021-03-08 11:28:25 +00006337 ctx := testApex(t, "", android.FixtureModifyMockFS(func(fs android.MockFS) {
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -07006338 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 Duffin0a49fdc2021-03-08 11:28:25 +00006348 }),
6349 prepareForTestWithSantitizeHwaddress,
6350 )
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -07006351
6352 m := ctx.ModuleForTests("myapex", "android_common")
Paul Duffin37ba3442021-03-29 00:21:08 +01006353 extractedApex := m.Output("out/soong/.intermediates/myapex/android_common/foo_v2.apex")
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -07006354
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 Trafimovich7caef202020-05-19 12:00:52 +01006366func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) {
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006367 t.Helper()
6368
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006369 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 Duffind376f792021-01-26 11:59:35 +00006399 "com.android.art.debug",
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006400 ],
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 Inwoodf8dcf5e2021-02-16 11:40:16 +00006416 updatable: false,
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006417 }
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 Duffind376f792021-01-26 11:59:35 +00006428 name: "com.android.art.debug",
6429 key: "com.android.art.debug.key",
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006430 java_libs: ["some-art-lib"],
6431 updatable: true,
6432 min_sdk_version: "current",
6433 }
6434
6435 apex_key {
Paul Duffind376f792021-01-26 11:59:35 +00006436 name: "com.android.art.debug.key",
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006437 }
6438
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006439 filegroup {
6440 name: "some-updatable-apex-file_contexts",
6441 srcs: [
6442 "system/sepolicy/apex/some-updatable-apex-file_contexts",
6443 ],
6444 }
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01006445
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 Trafimovichb28cc372020-01-13 15:18:16 +00006452 `
Paul Duffinc3bbb962020-12-10 19:15:49 +00006453
6454 testDexpreoptWithApexes(t, bp, errmsg, transformDexpreoptConfig)
6455}
6456
Paul Duffin064b70c2020-11-02 17:32:38 +00006457func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) *android.TestContext {
Paul Duffinc3bbb962020-12-10 19:15:49 +00006458 t.Helper()
6459
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006460 bp += cc.GatherRequiredDepsForTest(android.Android)
6461 bp += java.GatherRequiredDepsForTest()
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006462
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 Stjernholm1dc0d6d2021-01-17 21:05:12 +00006469 "system/sepolicy/apex/myapex-file_contexts": nil,
Paul Duffind376f792021-01-26 11:59:35 +00006470 "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 Stjernholm1dc0d6d2021-01-17 21:05:12 +00006473 "framework/aidl/a.aidl": nil,
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006474 }
6475 cc.GatherRequiredFilesForTest(fs)
6476
Paul Duffin39853512021-02-26 11:09:39 +00006477 for k, v := range filesForSdkLibrary {
6478 fs[k] = v
6479 }
Paul Duffin37ba3442021-03-29 00:21:08 +01006480 config := android.TestArchConfig(t.TempDir(), nil, bp, fs)
Colin Crossae8600b2020-10-29 17:09:13 -07006481
6482 ctx := android.NewTestArchContext(config)
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006483 ctx.RegisterModuleType("apex", BundleFactory)
6484 ctx.RegisterModuleType("apex_key", ApexKeyFactory)
Paul Duffin064b70c2020-11-02 17:32:38 +00006485 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006486 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Paul Duffinc988c8e2020-04-29 18:27:14 +01006487 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin37856732021-02-26 14:24:15 +00006488 ctx.PreArchMutators(android.RegisterComponentsMutator)
Paul Duffin021f4e52020-07-30 16:04:17 +01006489 android.RegisterPrebuiltMutators(ctx)
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006490 cc.RegisterRequiredBuildComponentsForTest(ctx)
Paul Duffinc059c8c2021-01-20 17:13:52 +00006491 java.RegisterRequiredBuildComponentsForTest(ctx)
Paul Duffinf38931c2021-02-05 16:58:28 +00006492 java.RegisterHiddenApiSingletonComponents(ctx)
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006493 ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
6494 ctx.PreDepsMutators(RegisterPreDepsMutators)
6495 ctx.PostDepsMutators(RegisterPostDepsMutators)
6496
Colin Crossae8600b2020-10-29 17:09:13 -07006497 ctx.Register()
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006498
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006499 pathCtx := android.PathContextForTesting(config)
6500 dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
6501 transformDexpreoptConfig(dexpreoptConfig)
6502 dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
6503
Paul Duffinf38931c2021-02-05 16:58:28 +00006504 // Make sure that any changes to these dexpreopt properties are mirrored in the corresponding
Paul Duffin4fd997b2021-02-03 20:06:33 +00006505 // product variables.
Paul Duffinf38931c2021-02-05 16:58:28 +00006506 config.TestProductVariables.BootJars = dexpreoptConfig.BootJars
6507 config.TestProductVariables.UpdatableBootJars = dexpreoptConfig.UpdatableBootJars
6508
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006509 _, 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 Trafimovichb28cc372020-01-13 15:18:16 +00006517 } else {
6518 t.Fatalf("missing expected error %q (0 errors are returned)", errmsg)
6519 }
Paul Duffin064b70c2020-11-02 17:32:38 +00006520
6521 return ctx
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006522}
6523
Jooyung Han548640b2020-04-27 12:10:30 +09006524func 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 Inwoodf8dcf5e2021-02-16 11:40:16 +00006540func 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 Trafimovichb28cc372020-01-13 15:18:16 +00006555func TestNoUpdatableJarsInBootImage(t *testing.T) {
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006556 var err string
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006557 var transform func(*dexpreopt.GlobalConfig)
6558
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006559 t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) {
6560 transform = func(config *dexpreopt.GlobalConfig) {
Paul Duffind376f792021-01-26 11:59:35 +00006561 config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"})
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006562 }
6563 testNoUpdatableJarsInBootImage(t, "", transform)
6564 })
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006565
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006566 t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) {
Paul Duffind376f792021-01-26 11:59:35 +00006567 err = `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image`
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006568 transform = func(config *dexpreopt.GlobalConfig) {
Paul Duffind376f792021-01-26 11:59:35 +00006569 config.BootJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"})
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006570 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006571 testNoUpdatableJarsInBootImage(t, err, transform)
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006572 })
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006573
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006574 t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) {
Colin Crossaede88c2020-08-11 12:17:01 -07006575 err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the ART boot image`
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006576 transform = func(config *dexpreopt.GlobalConfig) {
Paul Duffine10dfa42020-10-23 21:23:44 +01006577 config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"})
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006578 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006579 testNoUpdatableJarsInBootImage(t, err, transform)
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006580 })
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006581
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006582 t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) {
Colin Crossaede88c2020-08-11 12:17:01 -07006583 err = `module "some-non-updatable-apex-lib" is not allowed in the ART boot image`
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006584 transform = func(config *dexpreopt.GlobalConfig) {
Paul Duffine10dfa42020-10-23 21:23:44 +01006585 config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"})
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006586 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006587 testNoUpdatableJarsInBootImage(t, err, transform)
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006588 })
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01006589
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006590 t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) {
Colin Crossaede88c2020-08-11 12:17:01 -07006591 err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image`
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006592 transform = func(config *dexpreopt.GlobalConfig) {
Paul Duffine10dfa42020-10-23 21:23:44 +01006593 config.BootJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"})
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006594 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006595 testNoUpdatableJarsInBootImage(t, err, transform)
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006596 })
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006597
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006598 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 Duffine10dfa42020-10-23 21:23:44 +01006600 config.BootJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"})
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006601 }
6602 testNoUpdatableJarsInBootImage(t, "", transform)
6603 })
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01006604
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006605 t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) {
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006606 err = "failed to find a dex jar path for module 'nonexistent'"
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006607 transform = func(config *dexpreopt.GlobalConfig) {
Paul Duffine10dfa42020-10-23 21:23:44 +01006608 config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"})
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006609 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006610 testNoUpdatableJarsInBootImage(t, err, transform)
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006611 })
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006612
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006613 t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) {
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006614 err = "failed to find a dex jar path for module 'nonexistent'"
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006615 transform = func(config *dexpreopt.GlobalConfig) {
Paul Duffine10dfa42020-10-23 21:23:44 +01006616 config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"})
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006617 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006618 testNoUpdatableJarsInBootImage(t, err, transform)
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006619 })
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006620
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006621 t.Run("platform jar in the ART boot image => error", func(t *testing.T) {
Colin Crossaede88c2020-08-11 12:17:01 -07006622 err = `module "some-platform-lib" is not allowed in the ART boot image`
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006623 transform = func(config *dexpreopt.GlobalConfig) {
Paul Duffine10dfa42020-10-23 21:23:44 +01006624 config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"})
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006625 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -07006626 testNoUpdatableJarsInBootImage(t, err, transform)
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006627 })
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00006628
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006629 t.Run("platform jar in the framework boot image => ok", func(t *testing.T) {
6630 transform = func(config *dexpreopt.GlobalConfig) {
Paul Duffine10dfa42020-10-23 21:23:44 +01006631 config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"})
Ulya Trafimovich7caef202020-05-19 12:00:52 +01006632 }
6633 testNoUpdatableJarsInBootImage(t, "", transform)
6634 })
Paul Duffin064b70c2020-11-02 17:32:38 +00006635
6636}
6637
6638func 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 Trafimovichb28cc372020-01-13 15:18:16 +00006685}
6686
Andrei Onea115e7e72020-06-05 21:14:03 +01006687func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) {
6688 t.Helper()
Andrei Onea115e7e72020-06-05 21:14:03 +01006689 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 Duffin37ba3442021-03-29 00:21:08 +01006701 config := android.TestArchConfig(t.TempDir(), nil, bp, fs)
Colin Crossae8600b2020-10-29 17:09:13 -07006702 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 Onea115e7e72020-06-05 21:14:03 +01006710 ctx.RegisterModuleType("apex", BundleFactory)
6711 ctx.RegisterModuleType("apex_key", ApexKeyFactory)
6712 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
6713 cc.RegisterRequiredBuildComponentsForTest(ctx)
Paul Duffinc059c8c2021-01-20 17:13:52 +00006714 java.RegisterRequiredBuildComponentsForTest(ctx)
Andrei Onea115e7e72020-06-05 21:14:03 +01006715 ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
6716 ctx.PreDepsMutators(RegisterPreDepsMutators)
6717 ctx.PostDepsMutators(RegisterPostDepsMutators)
6718 ctx.PostDepsMutators(android.RegisterNeverallowMutator)
6719
Colin Crossae8600b2020-10-29 17:09:13 -07006720 ctx.Register()
Andrei Onea115e7e72020-06-05 21:14:03 +01006721
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
6736func 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 Inwoodf8dcf5e2021-02-16 11:40:16 +00006769 updatable: false,
Andrei Onea115e7e72020-06-05 21:14:03 +01006770 }`,
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 Inwoodf8dcf5e2021-02-16 11:40:16 +00006802 updatable: false,
Andrei Onea115e7e72020-06-05 21:14:03 +01006803 }
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 Park62304bb2020-04-13 16:19:48 +09006821func TestTestFor(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08006822 ctx := testApex(t, `
Jiyong Park62304bb2020-04-13 16:19:48 +09006823 apex {
6824 name: "myapex",
6825 key: "myapex.key",
6826 native_shared_libs: ["mylib", "myprivlib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00006827 updatable: false,
Jiyong Park62304bb2020-04-13 16:19:48 +09006828 }
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 Park46a512f2020-12-04 18:02:13 +09006862 shared_libs: ["mylib", "myprivlib", "mytestlib"],
Jiyong Park62304bb2020-04-13 16:19:48 +09006863 test_for: ["myapex"]
6864 }
Jiyong Park46a512f2020-12-04 18:02:13 +09006865
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 Park62304bb2020-04-13 16:19:48 +09006883 `)
6884
Martin Stjernholm4e6c2692021-03-25 01:25:06 +00006885 ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) {
Paul Duffina71a67a2021-03-29 00:42:57 +01006886 ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ")
Martin Stjernholm4e6c2692021-03-25 01:25:06 +00006887 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 Park62304bb2020-04-13 16:19:48 +09006892 // actual implementation of mylib instead of its stub.
Martin Stjernholm4e6c2692021-03-25 01:25:06 +00006893 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 Park46a512f2020-12-04 18:02:13 +09006897
Martin Stjernholm4e6c2692021-03-25 01:25:06 +00006898func 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 Park46a512f2020-12-04 18:02:13 +09006906
Martin Stjernholm4e6c2692021-03-25 01:25:06 +00006907 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 Duffina71a67a2021-03-29 00:42:57 +01006944 ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ")
Martin Stjernholm4e6c2692021-03-25 01:25:06 +00006945 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 Park62304bb2020-04-13 16:19:48 +09006956}
6957
Jaewoong Jungfa00c062020-05-14 14:15:24 -07006958// TODO(jungjw): Move this to proptools
6959func intPtr(i int) *int {
6960 return &i
6961}
6962
6963func TestApexSet(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08006964 ctx := testApex(t, `
Jaewoong Jungfa00c062020-05-14 14:15:24 -07006965 apex_set {
6966 name: "myapex",
6967 set: "myapex.apks",
6968 filename: "foo_v2.apex",
6969 overrides: ["foo"],
6970 }
Paul Duffin0a49fdc2021-03-08 11:28:25 +00006971 `,
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 Jungfa00c062020-05-14 14:15:24 -07006982
6983 m := ctx.ModuleForTests("myapex", "android_common")
6984
6985 // Check extract_apks tool parameters.
Paul Duffin37ba3442021-03-29 00:21:08 +01006986 extractedApex := m.Output("out/soong/.intermediates/myapex/android_common/foo_v2.apex")
Jaewoong Jungfa00c062020-05-14 14:15:24 -07006987 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 Crossaa255532020-07-03 13:18:24 -07007000 actualOverrides := android.AndroidMkEntriesForTest(t, ctx, a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jungfa00c062020-05-14 14:15:24 -07007001 if !reflect.DeepEqual(actualOverrides, expectedOverrides) {
7002 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides)
7003 }
7004}
7005
Jiyong Park7d95a512020-05-10 15:16:24 +09007006func 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 Inwoodf8dcf5e2021-02-16 11:40:16 +00007012 updatable: false,
Jiyong Park7d95a512020-05-10 15:16:24 +09007013 }
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 Park8d6c51e2020-06-12 17:26:31 +09007043func TestApexKeysTxt(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08007044 ctx := testApex(t, `
Jiyong Park8d6c51e2020-06-12 17:26:31 +09007045 apex {
7046 name: "myapex",
7047 key: "myapex.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00007048 updatable: false,
Jiyong Park8d6c51e2020-06-12 17:26:31 +09007049 }
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 Park03a7f3e2020-06-18 19:34:42 +09007081 ensureContains(t, content, `name="myapex.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`)
Jiyong Park8d6c51e2020-06-12 17:26:31 +09007082}
7083
Jooyung Han938b5932020-06-20 12:47:47 +09007084func TestAllowedFiles(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08007085 ctx := testApex(t, `
Jooyung Han938b5932020-06-20 12:47:47 +09007086 apex {
7087 name: "myapex",
7088 key: "myapex.key",
7089 apps: ["app"],
7090 allowed_files: "allowed.txt",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00007091 updatable: false,
Jooyung Han938b5932020-06-20 12:47:47 +09007092 }
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 Stjernholm58c33f02020-07-06 22:56:01 +01007140func TestNonPreferredPrebuiltDependency(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08007141 testApex(t, `
Martin Stjernholm58c33f02020-07-06 22:56:01 +01007142 apex {
7143 name: "myapex",
7144 key: "myapex.key",
7145 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00007146 updatable: false,
Martin Stjernholm58c33f02020-07-06 22:56:01 +01007147 }
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 Albertc8060532020-07-22 22:32:17 -07007159 versions: ["current"],
Martin Stjernholm58c33f02020-07-06 22:56:01 +01007160 },
7161 apex_available: ["myapex"],
7162 }
7163
7164 cc_prebuilt_library_shared {
7165 name: "mylib",
7166 prefer: false,
7167 srcs: ["prebuilt.so"],
7168 stubs: {
Dan Albertc8060532020-07-22 22:32:17 -07007169 versions: ["current"],
Martin Stjernholm58c33f02020-07-06 22:56:01 +01007170 },
7171 apex_available: ["myapex"],
7172 }
7173 `)
7174}
7175
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +00007176func TestCompressedApex(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08007177 ctx := testApex(t, `
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +00007178 apex {
7179 name: "myapex",
7180 key: "myapex.key",
7181 compressible: true,
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00007182 updatable: false,
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +00007183 }
7184 apex_key {
7185 name: "myapex.key",
7186 public_key: "testkey.avbpubkey",
7187 private_key: "testkey.pem",
7188 }
Paul Duffin0a49fdc2021-03-08 11:28:25 +00007189 `,
7190 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
7191 variables.CompressedApex = proptools.BoolPtr(true)
7192 }),
7193 )
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +00007194
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 Crossaa255532020-07-03 13:18:24 -07007206 data := android.AndroidMkDataForTest(t, ctx, ab)
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +00007207 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 Stjernholm2856c662020-12-02 15:03:42 +00007213func TestPreferredPrebuiltSharedLibDep(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08007214 ctx := testApex(t, `
Martin Stjernholm2856c662020-12-02 15:03:42 +00007215 apex {
7216 name: "myapex",
7217 key: "myapex.key",
7218 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00007219 updatable: false,
Martin Stjernholm2856c662020-12-02 15:03:42 +00007220 }
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 Crossaa255532020-07-03 13:18:24 -07007255 data := android.AndroidMkDataForTest(t, ctx, ab)
Martin Stjernholm2856c662020-12-02 15:03:42 +00007256 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 Parke3867542020-12-03 17:28:25 +09007265func TestExcludeDependency(t *testing.T) {
Colin Cross1c460562021-02-16 17:55:47 -08007266 ctx := testApex(t, `
Jiyong Parke3867542020-12-03 17:28:25 +09007267 apex {
7268 name: "myapex",
7269 key: "myapex.key",
7270 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00007271 updatable: false,
Jiyong Parke3867542020-12-03 17:28:25 +09007272 }
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 Parkf7c3bbe2020-12-09 21:18:56 +09007315func TestPrebuiltStubLibDep(t *testing.T) {
7316 bpBase := `
7317 apex {
7318 name: "myapex",
7319 key: "myapex.key",
7320 native_shared_libs: ["mylib"],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +00007321 updatable: false,
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +09007322 }
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 Inwoodf8dcf5e2021-02-16 11:40:16 +00007340 updatable: false,
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +09007341 }
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 Cross1c460562021-02-16 17:55:47 -08007410 ctx := testApex(t, fmt.Sprintf(bpBase, otherApexEnabled)+test.stublibBp)
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +09007411
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 Crossa9c8c9f2020-12-16 10:20:23 -08007425 if !mod.Enabled() || mod.IsHideFromMake() {
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +09007426 continue
7427 }
Colin Crossaa255532020-07-03 13:18:24 -07007428 for _, ent := range android.AndroidMkEntriesForTest(t, ctx, mod) {
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +09007429 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 Park892a98f2020-12-14 09:20:00 +09007464 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 Parkf7c3bbe2020-12-09 21:18:56 +09007469 }
7470 })
7471 }
7472 })
7473 }
7474}
7475
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07007476func TestMain(m *testing.M) {
Paul Duffin37ba3442021-03-29 00:21:08 +01007477 os.Exit(m.Run())
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07007478}