blob: bb59a540ebce53dfa74c5fea321217d488d9243d [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 Park25fc6a92018-11-18 18:02:45 +090018 "io/ioutil"
19 "os"
Jooyung Han39edb6c2019-11-06 16:53:07 +090020 "path"
Jaewoong Jung22f7d182019-07-16 18:25:41 -070021 "reflect"
Jooyung Han31c470b2019-10-18 16:26:59 +090022 "sort"
Jiyong Park25fc6a92018-11-18 18:02:45 +090023 "strings"
24 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090025
26 "github.com/google/blueprint/proptools"
27
28 "android/soong/android"
29 "android/soong/cc"
Ulya Trafimovichb28cc372020-01-13 15:18:16 +000030 "android/soong/dexpreopt"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090031 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090032)
33
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070034var buildDir string
35
Jooyung Hand3639552019-08-09 12:57:43 +090036// names returns name list from white space separated string
37func names(s string) (ns []string) {
38 for _, n := range strings.Split(s, " ") {
39 if len(n) > 0 {
40 ns = append(ns, n)
41 }
42 }
43 return
44}
45
Jooyung Han344d5432019-08-23 11:17:39 +090046func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) {
47 t.Helper()
48 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090049 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
50 if len(errs) > 0 {
51 android.FailIfNoMatchingErrors(t, pattern, errs)
52 return
53 }
54 _, errs = ctx.PrepareBuildActions(config)
55 if len(errs) > 0 {
56 android.FailIfNoMatchingErrors(t, pattern, errs)
57 return
58 }
59
60 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
61}
62
Jooyung Han344d5432019-08-23 11:17:39 +090063func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
64 t.Helper()
65 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090066 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
67 android.FailIfErrored(t, errs)
68 _, errs = ctx.PrepareBuildActions(config)
69 android.FailIfErrored(t, errs)
Jaewoong Jung22f7d182019-07-16 18:25:41 -070070 return ctx, config
Jooyung Han5c998b92019-06-27 11:30:33 +090071}
72
Jooyung Han344d5432019-08-23 11:17:39 +090073type testCustomizer func(fs map[string][]byte, config android.Config)
74
75func withFiles(files map[string][]byte) testCustomizer {
76 return func(fs map[string][]byte, config android.Config) {
77 for k, v := range files {
78 fs[k] = v
79 }
80 }
81}
82
83func withTargets(targets map[android.OsType][]android.Target) testCustomizer {
84 return func(fs map[string][]byte, config android.Config) {
85 for k, v := range targets {
86 config.Targets[k] = v
87 }
88 }
89}
90
Jooyung Han35155c42020-02-06 17:33:20 +090091// withNativeBridgeTargets sets configuration with targets including:
92// - X86_64 (primary)
93// - X86 (secondary)
94// - Arm64 on X86_64 (native bridge)
95// - Arm on X86 (native bridge)
96func withNativeBridgeEnabled(fs map[string][]byte, config android.Config) {
97 config.Targets[android.Android] = []android.Target{
98 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}},
99 NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
100 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}},
101 NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
102 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}},
103 NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"},
104 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}},
105 NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"},
106 }
107}
108
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900109func withManifestPackageNameOverrides(specs []string) testCustomizer {
110 return func(fs map[string][]byte, config android.Config) {
111 config.TestProductVariables.ManifestPackageNameOverrides = specs
112 }
113}
114
Jooyung Han31c470b2019-10-18 16:26:59 +0900115func withBinder32bit(fs map[string][]byte, config android.Config) {
116 config.TestProductVariables.Binder32bit = proptools.BoolPtr(true)
117}
118
Jiyong Park7cd10e32020-01-14 09:22:18 +0900119func withUnbundledBuild(fs map[string][]byte, config android.Config) {
120 config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
121}
122
Jooyung Han344d5432019-08-23 11:17:39 +0900123func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
Jooyung Han671f1ce2019-12-17 12:47:13 +0900124 android.ClearApexDependency()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900125
126 bp = bp + `
Jooyung Han54aca7b2019-11-20 02:26:02 +0900127 filegroup {
128 name: "myapex-file_contexts",
129 srcs: [
130 "system/sepolicy/apex/myapex-file_contexts",
131 ],
132 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900133 `
Colin Cross98be1bb2019-12-13 20:41:13 -0800134
Colin Crossf9aabd72020-02-15 11:29:50 -0800135 bp = bp + cc.GatherRequiredDepsForTest(android.Android)
136
Dario Frenicde2a032019-10-27 00:29:22 +0100137 bp = bp + java.GatherRequiredDepsForTest()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900138
Jooyung Han344d5432019-08-23 11:17:39 +0900139 fs := map[string][]byte{
Jooyung Han54aca7b2019-11-20 02:26:02 +0900140 "a.java": nil,
141 "PrebuiltAppFoo.apk": nil,
142 "PrebuiltAppFooPriv.apk": nil,
143 "build/make/target/product/security": nil,
144 "apex_manifest.json": nil,
145 "AndroidManifest.xml": nil,
146 "system/sepolicy/apex/myapex-file_contexts": nil,
Jiyong Park9d677202020-02-19 16:29:35 +0900147 "system/sepolicy/apex/myapex.updatable-file_contexts": nil,
Jiyong Park83dc74b2020-01-14 18:38:44 +0900148 "system/sepolicy/apex/myapex2-file_contexts": nil,
Jooyung Han54aca7b2019-11-20 02:26:02 +0900149 "system/sepolicy/apex/otherapex-file_contexts": nil,
150 "system/sepolicy/apex/commonapex-file_contexts": nil,
151 "system/sepolicy/apex/com.android.vndk-file_contexts": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -0800152 "mylib.cpp": nil,
153 "mylib_common.cpp": nil,
154 "mytest.cpp": nil,
155 "mytest1.cpp": nil,
156 "mytest2.cpp": nil,
157 "mytest3.cpp": nil,
158 "myprebuilt": nil,
159 "my_include": nil,
160 "foo/bar/MyClass.java": nil,
161 "prebuilt.jar": nil,
Paul Duffindddd5462020-04-07 15:25:44 +0100162 "prebuilt.so": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -0800163 "vendor/foo/devkeys/test.x509.pem": nil,
164 "vendor/foo/devkeys/test.pk8": nil,
165 "testkey.x509.pem": nil,
166 "testkey.pk8": nil,
167 "testkey.override.x509.pem": nil,
168 "testkey.override.pk8": nil,
169 "vendor/foo/devkeys/testkey.avbpubkey": nil,
170 "vendor/foo/devkeys/testkey.pem": nil,
171 "NOTICE": nil,
172 "custom_notice": nil,
Jiyong Park9918e1a2020-03-17 19:16:40 +0900173 "custom_notice_for_static_lib": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -0800174 "testkey2.avbpubkey": nil,
175 "testkey2.pem": nil,
176 "myapex-arm64.apex": nil,
177 "myapex-arm.apex": 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,
Jooyung Han344d5432019-08-23 11:17:39 +0900183 }
184
Colin Crossf9aabd72020-02-15 11:29:50 -0800185 cc.GatherRequiredFilesForTest(fs)
186
Jooyung Han344d5432019-08-23 11:17:39 +0900187 for _, handler := range handlers {
Colin Cross98be1bb2019-12-13 20:41:13 -0800188 // The fs now needs to be populated before creating the config, call handlers twice
189 // for now, once to get any fs changes, and later after the config was created to
190 // set product variables or targets.
191 tempConfig := android.TestArchConfig(buildDir, nil, bp, fs)
192 handler(fs, tempConfig)
Jooyung Han344d5432019-08-23 11:17:39 +0900193 }
194
Colin Cross98be1bb2019-12-13 20:41:13 -0800195 config := android.TestArchConfig(buildDir, nil, bp, fs)
196 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
197 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
198 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
199 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
200 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
201 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
202
203 for _, handler := range handlers {
204 // The fs now needs to be populated before creating the config, call handlers twice
205 // for now, earlier to get any fs changes, and now after the config was created to
206 // set product variables or targets.
207 tempFS := map[string][]byte{}
208 handler(tempFS, config)
209 }
210
211 ctx := android.NewTestArchContext()
212 ctx.RegisterModuleType("apex", BundleFactory)
213 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
214 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
215 ctx.RegisterModuleType("apex_key", ApexKeyFactory)
216 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
217 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
218 ctx.RegisterModuleType("override_apex", overrideApexFactory)
219
Jooyung Hana57af4a2020-01-23 05:36:59 +0000220 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
221 ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
222
Paul Duffin77980a82019-12-19 16:01:36 +0000223 cc.RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross98be1bb2019-12-13 20:41:13 -0800224 ctx.RegisterModuleType("cc_test", cc.TestFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800225 ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory)
226 ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800227 ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory)
atrost6e126252020-01-27 17:01:16 +0000228 ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800229 ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800230 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000231 java.RegisterJavaBuildComponents(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000232 java.RegisterSystemModulesBuildComponents(ctx)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000233 java.RegisterAppBuildComponents(ctx)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900234 ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800235
Colin Cross98be1bb2019-12-13 20:41:13 -0800236 ctx.PreDepsMutators(RegisterPreDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800237 ctx.PostDepsMutators(RegisterPostDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800238
239 ctx.Register(config)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900240
Jooyung Han5c998b92019-06-27 11:30:33 +0900241 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900242}
243
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700244func setUp() {
245 var err error
246 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900247 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700248 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900249 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900250}
251
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700252func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900253 os.RemoveAll(buildDir)
254}
255
Jooyung Han643adc42020-02-27 13:50:06 +0900256// ensure that 'result' equals 'expected'
257func ensureEquals(t *testing.T, result string, expected string) {
258 t.Helper()
259 if result != expected {
260 t.Errorf("%q != %q", expected, result)
261 }
262}
263
Jiyong Park25fc6a92018-11-18 18:02:45 +0900264// ensure that 'result' contains 'expected'
265func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900266 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900267 if !strings.Contains(result, expected) {
268 t.Errorf("%q is not found in %q", expected, result)
269 }
270}
271
272// ensures that 'result' does not contain 'notExpected'
273func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900274 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900275 if strings.Contains(result, notExpected) {
276 t.Errorf("%q is found in %q", notExpected, result)
277 }
278}
279
280func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900281 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900282 if !android.InList(expected, result) {
283 t.Errorf("%q is not found in %v", expected, result)
284 }
285}
286
287func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900288 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900289 if android.InList(notExpected, result) {
290 t.Errorf("%q is found in %v", notExpected, result)
291 }
292}
293
Jooyung Hane1633032019-08-01 17:41:43 +0900294func ensureListEmpty(t *testing.T, result []string) {
295 t.Helper()
296 if len(result) > 0 {
297 t.Errorf("%q is expected to be empty", result)
298 }
299}
300
Jiyong Park25fc6a92018-11-18 18:02:45 +0900301// Minimal test
302func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700303 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900304 apex_defaults {
305 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900306 manifest: ":myapex.manifest",
307 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900308 key: "myapex.key",
309 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800310 multilib: {
311 both: {
312 binaries: ["foo",],
313 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900314 },
Jooyung Han5a80d9f2019-12-23 15:38:34 +0900315 java_libs: ["myjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900316 }
317
Jiyong Park30ca9372019-02-07 16:27:23 +0900318 apex {
319 name: "myapex",
320 defaults: ["myapex-defaults"],
321 }
322
Jiyong Park25fc6a92018-11-18 18:02:45 +0900323 apex_key {
324 name: "myapex.key",
325 public_key: "testkey.avbpubkey",
326 private_key: "testkey.pem",
327 }
328
Jiyong Park809bb722019-02-13 21:33:49 +0900329 filegroup {
330 name: "myapex.manifest",
331 srcs: ["apex_manifest.json"],
332 }
333
334 filegroup {
335 name: "myapex.androidmanifest",
336 srcs: ["AndroidManifest.xml"],
337 }
338
Jiyong Park25fc6a92018-11-18 18:02:45 +0900339 cc_library {
340 name: "mylib",
341 srcs: ["mylib.cpp"],
342 shared_libs: ["mylib2"],
343 system_shared_libs: [],
344 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000345 // TODO: remove //apex_available:platform
346 apex_available: [
347 "//apex_available:platform",
348 "myapex",
349 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900350 }
351
Alex Light3d673592019-01-18 14:37:31 -0800352 cc_binary {
353 name: "foo",
354 srcs: ["mylib.cpp"],
355 compile_multilib: "both",
356 multilib: {
357 lib32: {
358 suffix: "32",
359 },
360 lib64: {
361 suffix: "64",
362 },
363 },
364 symlinks: ["foo_link_"],
365 symlink_preferred_arch: true,
366 system_shared_libs: [],
367 static_executable: true,
368 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000369 apex_available: [ "myapex" ],
Alex Light3d673592019-01-18 14:37:31 -0800370 }
371
Paul Duffindddd5462020-04-07 15:25:44 +0100372 cc_library_shared {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900373 name: "mylib2",
374 srcs: ["mylib.cpp"],
375 system_shared_libs: [],
376 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900377 notice: "custom_notice",
Jiyong Park9918e1a2020-03-17 19:16:40 +0900378 static_libs: ["libstatic"],
379 // TODO: remove //apex_available:platform
380 apex_available: [
381 "//apex_available:platform",
382 "myapex",
383 ],
384 }
385
Paul Duffindddd5462020-04-07 15:25:44 +0100386 cc_prebuilt_library_shared {
387 name: "mylib2",
388 srcs: ["prebuilt.so"],
389 // TODO: remove //apex_available:platform
390 apex_available: [
391 "//apex_available:platform",
392 "myapex",
393 ],
394 }
395
Jiyong Park9918e1a2020-03-17 19:16:40 +0900396 cc_library_static {
397 name: "libstatic",
398 srcs: ["mylib.cpp"],
399 system_shared_libs: [],
400 stl: "none",
401 notice: "custom_notice_for_static_lib",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000402 // TODO: remove //apex_available:platform
403 apex_available: [
404 "//apex_available:platform",
405 "myapex",
406 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900407 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900408
409 java_library {
410 name: "myjar",
411 srcs: ["foo/bar/MyClass.java"],
412 sdk_version: "none",
413 system_modules: "none",
Jiyong Park7f7766d2019-07-25 22:02:35 +0900414 static_libs: ["myotherjar"],
Jiyong Park3ff16992019-12-27 14:11:47 +0900415 libs: ["mysharedjar"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000416 // TODO: remove //apex_available:platform
417 apex_available: [
418 "//apex_available:platform",
419 "myapex",
420 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900421 }
422
423 java_library {
424 name: "myotherjar",
425 srcs: ["foo/bar/MyClass.java"],
426 sdk_version: "none",
427 system_modules: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +0900428 // TODO: remove //apex_available:platform
429 apex_available: [
430 "//apex_available:platform",
431 "myapex",
432 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900433 }
Jiyong Park3ff16992019-12-27 14:11:47 +0900434
435 java_library {
436 name: "mysharedjar",
437 srcs: ["foo/bar/MyClass.java"],
438 sdk_version: "none",
439 system_modules: "none",
Jiyong Park3ff16992019-12-27 14:11:47 +0900440 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900441 `)
442
Sundong Ahnabb64432019-10-22 13:58:29 +0900443 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900444
445 optFlags := apexRule.Args["opt_flags"]
446 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700447 // Ensure that the NOTICE output is being packaged as an asset.
Sundong Ahnabb64432019-10-22 13:58:29 +0900448 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900449
Jiyong Park25fc6a92018-11-18 18:02:45 +0900450 copyCmds := apexRule.Args["copy_commands"]
451
452 // Ensure that main rule creates an output
453 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
454
455 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800456 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900457 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900458
459 // Ensure that apex variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800460 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900461 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900462
463 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800464 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
465 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900466 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
467 // .. but not for java libs
468 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Jiyong Park3ff16992019-12-27 14:11:47 +0900469 ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800470
Colin Cross7113d202019-11-20 16:39:12 -0800471 // Ensure that the platform variant ends with _shared or _common
472 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
473 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900474 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
475 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park3ff16992019-12-27 14:11:47 +0900476 ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common")
477
478 // Ensure that dynamic dependency to java libs are not included
479 ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex")
Alex Light3d673592019-01-18 14:37:31 -0800480
481 // Ensure that all symlinks are present.
482 found_foo_link_64 := false
483 found_foo := false
484 for _, cmd := range strings.Split(copyCmds, " && ") {
Jiyong Park7cd10e32020-01-14 09:22:18 +0900485 if strings.HasPrefix(cmd, "ln -sfn foo64") {
Alex Light3d673592019-01-18 14:37:31 -0800486 if strings.HasSuffix(cmd, "bin/foo") {
487 found_foo = true
488 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
489 found_foo_link_64 = true
490 }
491 }
492 }
493 good := found_foo && found_foo_link_64
494 if !good {
495 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
496 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900497
Sundong Ahnabb64432019-10-22 13:58:29 +0900498 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700499 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jiyong Park9918e1a2020-03-17 19:16:40 +0900500 if len(noticeInputs) != 3 {
501 t.Errorf("number of input notice files: expected = 3, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900502 }
503 ensureListContains(t, noticeInputs, "NOTICE")
504 ensureListContains(t, noticeInputs, "custom_notice")
Jiyong Park9918e1a2020-03-17 19:16:40 +0900505 ensureListContains(t, noticeInputs, "custom_notice_for_static_lib")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900506
507 depsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("myapex-deps-info.txt").Args["content"], "\\n")
Jiyong Park678c8812020-02-07 17:25:49 +0900508 ensureListContains(t, depsInfo, "myjar <- myapex")
509 ensureListContains(t, depsInfo, "mylib <- myapex")
510 ensureListContains(t, depsInfo, "mylib2 <- mylib")
511 ensureListContains(t, depsInfo, "myotherjar <- myjar")
512 ensureListContains(t, depsInfo, "mysharedjar (external) <- myjar")
Alex Light5098a612018-11-29 17:12:15 -0800513}
514
Jooyung Hanf21c7972019-12-16 22:32:06 +0900515func TestDefaults(t *testing.T) {
516 ctx, _ := testApex(t, `
517 apex_defaults {
518 name: "myapex-defaults",
519 key: "myapex.key",
520 prebuilts: ["myetc"],
521 native_shared_libs: ["mylib"],
522 java_libs: ["myjar"],
523 apps: ["AppFoo"],
524 }
525
526 prebuilt_etc {
527 name: "myetc",
528 src: "myprebuilt",
529 }
530
531 apex {
532 name: "myapex",
533 defaults: ["myapex-defaults"],
534 }
535
536 apex_key {
537 name: "myapex.key",
538 public_key: "testkey.avbpubkey",
539 private_key: "testkey.pem",
540 }
541
542 cc_library {
543 name: "mylib",
544 system_shared_libs: [],
545 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000546 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900547 }
548
549 java_library {
550 name: "myjar",
551 srcs: ["foo/bar/MyClass.java"],
552 sdk_version: "none",
553 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000554 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900555 }
556
557 android_app {
558 name: "AppFoo",
559 srcs: ["foo/bar/MyClass.java"],
560 sdk_version: "none",
561 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000562 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900563 }
564 `)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000565 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Hanf21c7972019-12-16 22:32:06 +0900566 "etc/myetc",
567 "javalib/myjar.jar",
568 "lib64/mylib.so",
569 "app/AppFoo/AppFoo.apk",
570 })
571}
572
Jooyung Han01a3ee22019-11-02 02:52:25 +0900573func TestApexManifest(t *testing.T) {
574 ctx, _ := testApex(t, `
575 apex {
576 name: "myapex",
577 key: "myapex.key",
578 }
579
580 apex_key {
581 name: "myapex.key",
582 public_key: "testkey.avbpubkey",
583 private_key: "testkey.pem",
584 }
585 `)
586
587 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han214bf372019-11-12 13:03:50 +0900588 args := module.Rule("apexRule").Args
589 if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() {
590 t.Error("manifest should be apex_manifest.pb, but " + manifest)
591 }
Jooyung Han01a3ee22019-11-02 02:52:25 +0900592}
593
Alex Light5098a612018-11-29 17:12:15 -0800594func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700595 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800596 apex {
597 name: "myapex",
598 key: "myapex.key",
599 payload_type: "zip",
600 native_shared_libs: ["mylib"],
601 }
602
603 apex_key {
604 name: "myapex.key",
605 public_key: "testkey.avbpubkey",
606 private_key: "testkey.pem",
607 }
608
609 cc_library {
610 name: "mylib",
611 srcs: ["mylib.cpp"],
612 shared_libs: ["mylib2"],
613 system_shared_libs: [],
614 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000615 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800616 }
617
618 cc_library {
619 name: "mylib2",
620 srcs: ["mylib.cpp"],
621 system_shared_libs: [],
622 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000623 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800624 }
625 `)
626
Sundong Ahnabb64432019-10-22 13:58:29 +0900627 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
Alex Light5098a612018-11-29 17:12:15 -0800628 copyCmds := zipApexRule.Args["copy_commands"]
629
630 // Ensure that main rule creates an output
631 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
632
633 // Ensure that APEX variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800634 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800635
636 // Ensure that APEX variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800637 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800638
639 // Ensure that both direct and indirect deps are copied into apex
640 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
641 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900642}
643
644func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700645 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900646 apex {
647 name: "myapex",
648 key: "myapex.key",
649 native_shared_libs: ["mylib", "mylib3"],
650 }
651
652 apex_key {
653 name: "myapex.key",
654 public_key: "testkey.avbpubkey",
655 private_key: "testkey.pem",
656 }
657
658 cc_library {
659 name: "mylib",
660 srcs: ["mylib.cpp"],
661 shared_libs: ["mylib2", "mylib3"],
662 system_shared_libs: [],
663 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000664 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900665 }
666
667 cc_library {
668 name: "mylib2",
669 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900670 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900671 system_shared_libs: [],
672 stl: "none",
673 stubs: {
674 versions: ["1", "2", "3"],
675 },
676 }
677
678 cc_library {
679 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900680 srcs: ["mylib.cpp"],
681 shared_libs: ["mylib4"],
682 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900683 stl: "none",
684 stubs: {
685 versions: ["10", "11", "12"],
686 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000687 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900688 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900689
690 cc_library {
691 name: "mylib4",
692 srcs: ["mylib.cpp"],
693 system_shared_libs: [],
694 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000695 apex_available: [ "myapex" ],
Jiyong Park28d395a2018-12-07 22:42:47 +0900696 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900697 `)
698
Sundong Ahnabb64432019-10-22 13:58:29 +0900699 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900700 copyCmds := apexRule.Args["copy_commands"]
701
702 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800703 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900704
705 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800706 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900707
708 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800709 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900710
Colin Cross7113d202019-11-20 16:39:12 -0800711 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900712
713 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900714 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900715 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900716 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900717
718 // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
Colin Cross7113d202019-11-20 16:39:12 -0800719 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900720 // .. and not linking to the stubs variant of mylib3
Colin Cross7113d202019-11-20 16:39:12 -0800721 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900722
723 // Ensure that stubs libs are built without -include flags
Jiyong Park0f80c182020-01-31 02:49:53 +0900724 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900725 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900726
727 // Ensure that genstub is invoked with --apex
Jiyong Park3ff16992019-12-27 14:11:47 +0900728 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"])
Jooyung Han671f1ce2019-12-17 12:47:13 +0900729
Jooyung Hana57af4a2020-01-23 05:36:59 +0000730 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han671f1ce2019-12-17 12:47:13 +0900731 "lib64/mylib.so",
732 "lib64/mylib3.so",
733 "lib64/mylib4.so",
734 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900735}
736
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900737func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700738 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900739 apex {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900740 name: "myapex2",
741 key: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900742 native_shared_libs: ["mylib"],
743 }
744
745 apex_key {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900746 name: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900747 public_key: "testkey.avbpubkey",
748 private_key: "testkey.pem",
749 }
750
751 cc_library {
752 name: "mylib",
753 srcs: ["mylib.cpp"],
754 shared_libs: ["libfoo#10"],
Jiyong Park678c8812020-02-07 17:25:49 +0900755 static_libs: ["libbaz"],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900756 system_shared_libs: [],
757 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000758 apex_available: [ "myapex2" ],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900759 }
760
761 cc_library {
762 name: "libfoo",
763 srcs: ["mylib.cpp"],
764 shared_libs: ["libbar"],
765 system_shared_libs: [],
766 stl: "none",
767 stubs: {
768 versions: ["10", "20", "30"],
769 },
770 }
771
772 cc_library {
773 name: "libbar",
774 srcs: ["mylib.cpp"],
775 system_shared_libs: [],
776 stl: "none",
777 }
778
Jiyong Park678c8812020-02-07 17:25:49 +0900779 cc_library_static {
780 name: "libbaz",
781 srcs: ["mylib.cpp"],
782 system_shared_libs: [],
783 stl: "none",
784 apex_available: [ "myapex2" ],
785 }
786
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900787 `)
788
Jiyong Park83dc74b2020-01-14 18:38:44 +0900789 apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900790 copyCmds := apexRule.Args["copy_commands"]
791
792 // Ensure that direct non-stubs dep is always included
793 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
794
795 // Ensure that indirect stubs dep is not included
796 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
797
798 // Ensure that dependency of stubs is not included
799 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
800
Jiyong Park83dc74b2020-01-14 18:38:44 +0900801 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900802
803 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900804 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900805 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900806 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900807
Jiyong Park3ff16992019-12-27 14:11:47 +0900808 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900809
810 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
811 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900812
813 depsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("myapex2-deps-info.txt").Args["content"], "\\n")
Jiyong Park678c8812020-02-07 17:25:49 +0900814
815 ensureListContains(t, depsInfo, "mylib <- myapex2")
816 ensureListContains(t, depsInfo, "libbaz <- mylib")
817 ensureListContains(t, depsInfo, "libfoo (external) <- mylib")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900818}
819
Jooyung Hand3639552019-08-09 12:57:43 +0900820func TestApexWithRuntimeLibsDependency(t *testing.T) {
821 /*
822 myapex
823 |
824 v (runtime_libs)
825 mylib ------+------> libfoo [provides stub]
826 |
827 `------> libbar
828 */
829 ctx, _ := testApex(t, `
830 apex {
831 name: "myapex",
832 key: "myapex.key",
833 native_shared_libs: ["mylib"],
834 }
835
836 apex_key {
837 name: "myapex.key",
838 public_key: "testkey.avbpubkey",
839 private_key: "testkey.pem",
840 }
841
842 cc_library {
843 name: "mylib",
844 srcs: ["mylib.cpp"],
845 runtime_libs: ["libfoo", "libbar"],
846 system_shared_libs: [],
847 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000848 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900849 }
850
851 cc_library {
852 name: "libfoo",
853 srcs: ["mylib.cpp"],
854 system_shared_libs: [],
855 stl: "none",
856 stubs: {
857 versions: ["10", "20", "30"],
858 },
859 }
860
861 cc_library {
862 name: "libbar",
863 srcs: ["mylib.cpp"],
864 system_shared_libs: [],
865 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000866 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900867 }
868
869 `)
870
Sundong Ahnabb64432019-10-22 13:58:29 +0900871 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Hand3639552019-08-09 12:57:43 +0900872 copyCmds := apexRule.Args["copy_commands"]
873
874 // Ensure that direct non-stubs dep is always included
875 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
876
877 // Ensure that indirect stubs dep is not included
878 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
879
880 // Ensure that runtime_libs dep in included
881 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
882
Sundong Ahnabb64432019-10-22 13:58:29 +0900883 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900884 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
885 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900886
887}
888
Jooyung Han61b66e92020-03-21 14:21:46 +0000889func TestApexDependsOnLLNDKTransitively(t *testing.T) {
890 testcases := []struct {
891 name string
892 minSdkVersion string
893 shouldLink string
894 shouldNotLink []string
895 }{
896 {
Jooyung Han75568392020-03-20 04:29:24 +0900897 name: "should link to the latest",
Jooyung Han61b66e92020-03-21 14:21:46 +0000898 minSdkVersion: "current",
899 shouldLink: "30",
900 shouldNotLink: []string{"29"},
901 },
902 {
903 name: "should link to llndk#29",
904 minSdkVersion: "29",
905 shouldLink: "29",
906 shouldNotLink: []string{"30"},
907 },
908 }
909 for _, tc := range testcases {
910 t.Run(tc.name, func(t *testing.T) {
911 ctx, _ := testApex(t, `
912 apex {
913 name: "myapex",
914 key: "myapex.key",
915 use_vendor: true,
916 native_shared_libs: ["mylib"],
917 min_sdk_version: "`+tc.minSdkVersion+`",
918 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900919
Jooyung Han61b66e92020-03-21 14:21:46 +0000920 apex_key {
921 name: "myapex.key",
922 public_key: "testkey.avbpubkey",
923 private_key: "testkey.pem",
924 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900925
Jooyung Han61b66e92020-03-21 14:21:46 +0000926 cc_library {
927 name: "mylib",
928 srcs: ["mylib.cpp"],
929 vendor_available: true,
930 shared_libs: ["libbar"],
931 system_shared_libs: [],
932 stl: "none",
933 apex_available: [ "myapex" ],
934 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900935
Jooyung Han61b66e92020-03-21 14:21:46 +0000936 cc_library {
937 name: "libbar",
938 srcs: ["mylib.cpp"],
939 system_shared_libs: [],
940 stl: "none",
941 stubs: { versions: ["29","30"] },
942 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900943
Jooyung Han61b66e92020-03-21 14:21:46 +0000944 llndk_library {
945 name: "libbar",
946 symbol_file: "",
947 }
948 `, func(fs map[string][]byte, config android.Config) {
949 setUseVendorWhitelistForTest(config, []string{"myapex"})
950 }, withUnbundledBuild)
Jooyung Han9c80bae2019-08-20 17:30:57 +0900951
Jooyung Han61b66e92020-03-21 14:21:46 +0000952 // Ensure that LLNDK dep is not included
953 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
954 "lib64/mylib.so",
955 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900956
Jooyung Han61b66e92020-03-21 14:21:46 +0000957 // Ensure that LLNDK dep is required
958 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
959 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
960 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900961
Jooyung Han61b66e92020-03-21 14:21:46 +0000962 mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
963 ensureContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so")
964 for _, ver := range tc.shouldNotLink {
965 ensureNotContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so")
966 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900967
Jooyung Han61b66e92020-03-21 14:21:46 +0000968 mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
969 ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink)
970 })
971 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900972}
973
Jiyong Park25fc6a92018-11-18 18:02:45 +0900974func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700975 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900976 apex {
977 name: "myapex",
978 key: "myapex.key",
979 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
980 }
981
982 apex_key {
983 name: "myapex.key",
984 public_key: "testkey.avbpubkey",
985 private_key: "testkey.pem",
986 }
987
988 cc_library {
989 name: "mylib",
990 srcs: ["mylib.cpp"],
991 shared_libs: ["libdl#27"],
992 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000993 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900994 }
995
996 cc_library_shared {
997 name: "mylib_shared",
998 srcs: ["mylib.cpp"],
999 shared_libs: ["libdl#27"],
1000 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001001 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001002 }
1003
1004 cc_library {
Jiyong Parkb0788572018-12-20 22:10:17 +09001005 name: "libBootstrap",
1006 srcs: ["mylib.cpp"],
1007 stl: "none",
1008 bootstrap: true,
1009 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001010 `)
1011
Sundong Ahnabb64432019-10-22 13:58:29 +09001012 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001013 copyCmds := apexRule.Args["copy_commands"]
1014
1015 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -08001016 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +09001017 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
1018 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001019
1020 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +09001021 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001022
Colin Cross7113d202019-11-20 16:39:12 -08001023 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
1024 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
1025 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001026
1027 // For dependency to libc
1028 // Ensure that mylib is linking with the latest version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001029 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001030 // ... and not linking to the non-stub (impl) variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001031 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001032 // ... Cflags from stub is correctly exported to mylib
1033 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
1034 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
1035
1036 // For dependency to libm
1037 // Ensure that mylib is linking with the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -08001038 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001039 // ... and not linking to the stub variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001040 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001041 // ... and is not compiling with the stub
1042 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
1043 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
1044
1045 // For dependency to libdl
1046 // Ensure that mylib is linking with the specified version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001047 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001048 // ... and not linking to the other versions of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001049 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so")
1050 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001051 // ... and not linking to the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -08001052 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001053 // ... Cflags from stub is correctly exported to mylib
1054 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
1055 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +09001056
1057 // Ensure that libBootstrap is depending on the platform variant of bionic libs
Colin Cross7113d202019-11-20 16:39:12 -08001058 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"]
1059 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so")
1060 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so")
1061 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001062}
Jiyong Park7c2ee712018-12-07 00:42:25 +09001063
Jooyung Han03b51852020-02-26 22:45:42 +09001064func TestApexUseStubsAccordingToMinSdkVersionInUnbundledBuild(t *testing.T) {
1065 // there are three links between liba --> libz
1066 // 1) myapex -> libx -> liba -> libz : this should be #2 link, but fallback to #1
1067 // 2) otherapex -> liby -> liba -> libz : this should be #3 link
1068 // 3) (platform) -> liba -> libz : this should be non-stub link
1069 ctx, _ := testApex(t, `
1070 apex {
1071 name: "myapex",
1072 key: "myapex.key",
1073 native_shared_libs: ["libx"],
1074 min_sdk_version: "2",
1075 }
1076
1077 apex {
1078 name: "otherapex",
1079 key: "myapex.key",
1080 native_shared_libs: ["liby"],
1081 min_sdk_version: "3",
1082 }
1083
1084 apex_key {
1085 name: "myapex.key",
1086 public_key: "testkey.avbpubkey",
1087 private_key: "testkey.pem",
1088 }
1089
1090 cc_library {
1091 name: "libx",
1092 shared_libs: ["liba"],
1093 system_shared_libs: [],
1094 stl: "none",
1095 apex_available: [ "myapex" ],
1096 }
1097
1098 cc_library {
1099 name: "liby",
1100 shared_libs: ["liba"],
1101 system_shared_libs: [],
1102 stl: "none",
1103 apex_available: [ "otherapex" ],
1104 }
1105
1106 cc_library {
1107 name: "liba",
1108 shared_libs: ["libz"],
1109 system_shared_libs: [],
1110 stl: "none",
1111 apex_available: [
1112 "//apex_available:anyapex",
1113 "//apex_available:platform",
1114 ],
1115 }
1116
1117 cc_library {
1118 name: "libz",
1119 system_shared_libs: [],
1120 stl: "none",
1121 stubs: {
1122 versions: ["1", "3"],
1123 },
1124 }
1125 `, withUnbundledBuild)
1126
1127 expectLink := func(from, from_variant, to, to_variant string) {
1128 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1129 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1130 }
1131 expectNoLink := func(from, from_variant, to, to_variant string) {
1132 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1133 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1134 }
1135 // platform liba is linked to non-stub version
1136 expectLink("liba", "shared", "libz", "shared")
1137 // liba in myapex is linked to #1
1138 expectLink("liba", "shared_myapex", "libz", "shared_1")
1139 expectNoLink("liba", "shared_myapex", "libz", "shared_3")
1140 expectNoLink("liba", "shared_myapex", "libz", "shared")
1141 // liba in otherapex is linked to #3
1142 expectLink("liba", "shared_otherapex", "libz", "shared_3")
1143 expectNoLink("liba", "shared_otherapex", "libz", "shared_1")
1144 expectNoLink("liba", "shared_otherapex", "libz", "shared")
1145}
1146
1147func TestApexMinSdkVersionDefaultsToLatest(t *testing.T) {
1148 ctx, _ := testApex(t, `
1149 apex {
1150 name: "myapex",
1151 key: "myapex.key",
1152 native_shared_libs: ["libx"],
1153 }
1154
1155 apex_key {
1156 name: "myapex.key",
1157 public_key: "testkey.avbpubkey",
1158 private_key: "testkey.pem",
1159 }
1160
1161 cc_library {
1162 name: "libx",
1163 shared_libs: ["libz"],
1164 system_shared_libs: [],
1165 stl: "none",
1166 apex_available: [ "myapex" ],
1167 }
1168
1169 cc_library {
1170 name: "libz",
1171 system_shared_libs: [],
1172 stl: "none",
1173 stubs: {
1174 versions: ["1", "2"],
1175 },
1176 }
1177 `)
1178
1179 expectLink := func(from, from_variant, to, to_variant string) {
1180 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1181 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1182 }
1183 expectNoLink := func(from, from_variant, to, to_variant string) {
1184 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1185 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1186 }
1187 expectLink("libx", "shared_myapex", "libz", "shared_2")
1188 expectNoLink("libx", "shared_myapex", "libz", "shared_1")
1189 expectNoLink("libx", "shared_myapex", "libz", "shared")
1190}
1191
1192func TestPlatformUsesLatestStubsFromApexes(t *testing.T) {
1193 ctx, _ := testApex(t, `
1194 apex {
1195 name: "myapex",
1196 key: "myapex.key",
1197 native_shared_libs: ["libx"],
1198 }
1199
1200 apex_key {
1201 name: "myapex.key",
1202 public_key: "testkey.avbpubkey",
1203 private_key: "testkey.pem",
1204 }
1205
1206 cc_library {
1207 name: "libx",
1208 system_shared_libs: [],
1209 stl: "none",
1210 apex_available: [ "myapex" ],
1211 stubs: {
1212 versions: ["1", "2"],
1213 },
1214 }
1215
1216 cc_library {
1217 name: "libz",
1218 shared_libs: ["libx"],
1219 system_shared_libs: [],
1220 stl: "none",
1221 }
1222 `)
1223
1224 expectLink := func(from, from_variant, to, to_variant string) {
1225 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1226 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1227 }
1228 expectNoLink := func(from, from_variant, to, to_variant string) {
1229 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1230 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1231 }
1232 expectLink("libz", "shared", "libx", "shared_2")
1233 expectNoLink("libz", "shared", "libz", "shared_1")
1234 expectNoLink("libz", "shared", "libz", "shared")
1235}
1236
Jooyung Han75568392020-03-20 04:29:24 +09001237func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) {
Jooyung Han03b51852020-02-26 22:45:42 +09001238 ctx, _ := testApex(t, `
1239 apex {
1240 name: "myapex",
1241 key: "myapex.key",
1242 native_shared_libs: ["libx"],
1243 min_sdk_version: "29",
1244 }
1245
1246 apex_key {
1247 name: "myapex.key",
1248 public_key: "testkey.avbpubkey",
1249 private_key: "testkey.pem",
1250 }
1251
1252 cc_library {
1253 name: "libx",
1254 shared_libs: ["libbar"],
1255 apex_available: [ "myapex" ],
1256 }
1257
1258 cc_library {
1259 name: "libbar",
1260 stubs: {
1261 versions: ["29", "30"],
1262 },
1263 }
Jooyung Han75568392020-03-20 04:29:24 +09001264 `, func(fs map[string][]byte, config android.Config) {
1265 config.TestProductVariables.SanitizeDevice = []string{"hwaddress"}
1266 })
Jooyung Han03b51852020-02-26 22:45:42 +09001267 expectLink := func(from, from_variant, to, to_variant string) {
1268 ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld")
1269 libFlags := ld.Args["libFlags"]
1270 ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1271 }
Jooyung Han75568392020-03-20 04:29:24 +09001272 expectLink("libx", "shared_hwasan_myapex", "libbar", "shared_30")
Jooyung Han03b51852020-02-26 22:45:42 +09001273}
1274
Jooyung Han75568392020-03-20 04:29:24 +09001275func TestQTargetApexUsesStaticUnwinder(t *testing.T) {
Jooyung Han03b51852020-02-26 22:45:42 +09001276 ctx, _ := testApex(t, `
1277 apex {
1278 name: "myapex",
1279 key: "myapex.key",
1280 native_shared_libs: ["libx"],
1281 min_sdk_version: "29",
1282 }
1283
1284 apex_key {
1285 name: "myapex.key",
1286 public_key: "testkey.avbpubkey",
1287 private_key: "testkey.pem",
1288 }
1289
1290 cc_library {
1291 name: "libx",
1292 apex_available: [ "myapex" ],
1293 }
Jooyung Han75568392020-03-20 04:29:24 +09001294 `)
Jooyung Han03b51852020-02-26 22:45:42 +09001295
1296 // ensure apex variant of c++ is linked with static unwinder
1297 cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module)
1298 ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
1299 // note that platform variant is not.
1300 cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module)
1301 ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
Jooyung Han03b51852020-02-26 22:45:42 +09001302}
1303
1304func TestInvalidMinSdkVersion(t *testing.T) {
Jooyung Han75568392020-03-20 04:29:24 +09001305 testApexError(t, `"libz" .*: not found a version\(<=29\)`, `
Jooyung Han03b51852020-02-26 22:45:42 +09001306 apex {
1307 name: "myapex",
1308 key: "myapex.key",
1309 native_shared_libs: ["libx"],
1310 min_sdk_version: "29",
1311 }
1312
1313 apex_key {
1314 name: "myapex.key",
1315 public_key: "testkey.avbpubkey",
1316 private_key: "testkey.pem",
1317 }
1318
1319 cc_library {
1320 name: "libx",
1321 shared_libs: ["libz"],
1322 system_shared_libs: [],
1323 stl: "none",
1324 apex_available: [ "myapex" ],
1325 }
1326
1327 cc_library {
1328 name: "libz",
1329 system_shared_libs: [],
1330 stl: "none",
1331 stubs: {
1332 versions: ["30"],
1333 },
1334 }
Jooyung Han75568392020-03-20 04:29:24 +09001335 `)
Jooyung Han03b51852020-02-26 22:45:42 +09001336
Jooyung Han75568392020-03-20 04:29:24 +09001337 testApexError(t, `"myapex" .*: min_sdk_version: should be "current" or <number>`, `
Jooyung Han03b51852020-02-26 22:45:42 +09001338 apex {
1339 name: "myapex",
1340 key: "myapex.key",
1341 min_sdk_version: "R",
1342 }
1343
1344 apex_key {
1345 name: "myapex.key",
1346 public_key: "testkey.avbpubkey",
1347 private_key: "testkey.pem",
1348 }
1349 `)
1350}
1351
Jiyong Park7c2ee712018-12-07 00:42:25 +09001352func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001353 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +09001354 apex {
1355 name: "myapex",
1356 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001357 native_shared_libs: ["mylib"],
1358 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +09001359 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001360 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +09001361 }
1362
1363 apex_key {
1364 name: "myapex.key",
1365 public_key: "testkey.avbpubkey",
1366 private_key: "testkey.pem",
1367 }
1368
1369 prebuilt_etc {
1370 name: "myetc",
1371 src: "myprebuilt",
1372 sub_dir: "foo/bar",
1373 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001374
1375 cc_library {
1376 name: "mylib",
1377 srcs: ["mylib.cpp"],
1378 relative_install_path: "foo/bar",
1379 system_shared_libs: [],
1380 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001381 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001382 }
1383
1384 cc_binary {
1385 name: "mybin",
1386 srcs: ["mylib.cpp"],
1387 relative_install_path: "foo/bar",
1388 system_shared_libs: [],
1389 static_executable: true,
1390 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001391 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001392 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001393 `)
1394
Sundong Ahnabb64432019-10-22 13:58:29 +09001395 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001396 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1397
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001398 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001399 ensureListContains(t, dirs, "etc")
1400 ensureListContains(t, dirs, "etc/foo")
1401 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001402 ensureListContains(t, dirs, "lib64")
1403 ensureListContains(t, dirs, "lib64/foo")
1404 ensureListContains(t, dirs, "lib64/foo/bar")
1405 ensureListContains(t, dirs, "lib")
1406 ensureListContains(t, dirs, "lib/foo")
1407 ensureListContains(t, dirs, "lib/foo/bar")
1408
Jiyong Parkbd13e442019-03-15 18:10:35 +09001409 ensureListContains(t, dirs, "bin")
1410 ensureListContains(t, dirs, "bin/foo")
1411 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001412}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001413
Jooyung Han35155c42020-02-06 17:33:20 +09001414func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) {
1415 ctx, _ := testApex(t, `
1416 apex {
1417 name: "myapex",
1418 key: "myapex.key",
1419 multilib: {
1420 both: {
1421 native_shared_libs: ["mylib"],
1422 binaries: ["mybin"],
1423 },
1424 },
1425 compile_multilib: "both",
1426 native_bridge_supported: true,
1427 }
1428
1429 apex_key {
1430 name: "myapex.key",
1431 public_key: "testkey.avbpubkey",
1432 private_key: "testkey.pem",
1433 }
1434
1435 cc_library {
1436 name: "mylib",
1437 relative_install_path: "foo/bar",
1438 system_shared_libs: [],
1439 stl: "none",
1440 apex_available: [ "myapex" ],
1441 native_bridge_supported: true,
1442 }
1443
1444 cc_binary {
1445 name: "mybin",
1446 relative_install_path: "foo/bar",
1447 system_shared_libs: [],
1448 static_executable: true,
1449 stl: "none",
1450 apex_available: [ "myapex" ],
1451 native_bridge_supported: true,
1452 compile_multilib: "both", // default is "first" for binary
1453 multilib: {
1454 lib64: {
1455 suffix: "64",
1456 },
1457 },
1458 }
1459 `, withNativeBridgeEnabled)
1460 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
1461 "bin/foo/bar/mybin",
1462 "bin/foo/bar/mybin64",
1463 "bin/arm/foo/bar/mybin",
1464 "bin/arm64/foo/bar/mybin64",
1465 "lib/foo/bar/mylib.so",
1466 "lib/arm/foo/bar/mylib.so",
1467 "lib64/foo/bar/mylib.so",
1468 "lib64/arm64/foo/bar/mylib.so",
1469 })
1470}
1471
Jiyong Parkda6eb592018-12-19 17:12:36 +09001472func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001473 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001474 apex {
1475 name: "myapex",
1476 key: "myapex.key",
1477 native_shared_libs: ["mylib"],
1478 use_vendor: true,
1479 }
1480
1481 apex_key {
1482 name: "myapex.key",
1483 public_key: "testkey.avbpubkey",
1484 private_key: "testkey.pem",
1485 }
1486
1487 cc_library {
1488 name: "mylib",
1489 srcs: ["mylib.cpp"],
1490 shared_libs: ["mylib2"],
1491 system_shared_libs: [],
1492 vendor_available: true,
1493 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001494 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001495 }
1496
1497 cc_library {
1498 name: "mylib2",
1499 srcs: ["mylib.cpp"],
1500 system_shared_libs: [],
1501 vendor_available: true,
1502 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001503 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001504 }
Jooyung Handc782442019-11-01 03:14:38 +09001505 `, func(fs map[string][]byte, config android.Config) {
1506 setUseVendorWhitelistForTest(config, []string{"myapex"})
1507 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001508
1509 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001510 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001511 for _, implicit := range i.Implicits {
1512 inputsList = append(inputsList, implicit.String())
1513 }
1514 }
1515 inputsString := strings.Join(inputsList, " ")
1516
1517 // ensure that the apex includes vendor variants of the direct and indirect deps
Colin Crossfb0c16e2019-11-20 17:12:35 -08001518 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so")
1519 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001520
1521 // ensure that the apex does not include core variants
Colin Cross7113d202019-11-20 16:39:12 -08001522 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so")
1523 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001524}
Jiyong Park16e91a02018-12-20 18:18:08 +09001525
Jooyung Handc782442019-11-01 03:14:38 +09001526func TestUseVendorRestriction(t *testing.T) {
1527 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1528 apex {
1529 name: "myapex",
1530 key: "myapex.key",
1531 use_vendor: true,
1532 }
1533 apex_key {
1534 name: "myapex.key",
1535 public_key: "testkey.avbpubkey",
1536 private_key: "testkey.pem",
1537 }
1538 `, func(fs map[string][]byte, config android.Config) {
1539 setUseVendorWhitelistForTest(config, []string{""})
1540 })
1541 // no error with whitelist
1542 testApex(t, `
1543 apex {
1544 name: "myapex",
1545 key: "myapex.key",
1546 use_vendor: true,
1547 }
1548 apex_key {
1549 name: "myapex.key",
1550 public_key: "testkey.avbpubkey",
1551 private_key: "testkey.pem",
1552 }
1553 `, func(fs map[string][]byte, config android.Config) {
1554 setUseVendorWhitelistForTest(config, []string{"myapex"})
1555 })
1556}
1557
Jooyung Han5c998b92019-06-27 11:30:33 +09001558func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1559 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1560 apex {
1561 name: "myapex",
1562 key: "myapex.key",
1563 native_shared_libs: ["mylib"],
1564 use_vendor: true,
1565 }
1566
1567 apex_key {
1568 name: "myapex.key",
1569 public_key: "testkey.avbpubkey",
1570 private_key: "testkey.pem",
1571 }
1572
1573 cc_library {
1574 name: "mylib",
1575 srcs: ["mylib.cpp"],
1576 system_shared_libs: [],
1577 stl: "none",
1578 }
1579 `)
1580}
1581
Jiyong Park16e91a02018-12-20 18:18:08 +09001582func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001583 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001584 apex {
1585 name: "myapex",
1586 key: "myapex.key",
1587 native_shared_libs: ["mylib"],
1588 }
1589
1590 apex_key {
1591 name: "myapex.key",
1592 public_key: "testkey.avbpubkey",
1593 private_key: "testkey.pem",
1594 }
1595
1596 cc_library {
1597 name: "mylib",
1598 srcs: ["mylib.cpp"],
1599 system_shared_libs: [],
1600 stl: "none",
1601 stubs: {
1602 versions: ["1", "2", "3"],
1603 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001604 apex_available: [
1605 "//apex_available:platform",
1606 "myapex",
1607 ],
Jiyong Park16e91a02018-12-20 18:18:08 +09001608 }
1609
1610 cc_binary {
1611 name: "not_in_apex",
1612 srcs: ["mylib.cpp"],
1613 static_libs: ["mylib"],
1614 static_executable: true,
1615 system_shared_libs: [],
1616 stl: "none",
1617 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001618 `)
1619
Colin Cross7113d202019-11-20 16:39:12 -08001620 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
Jiyong Park16e91a02018-12-20 18:18:08 +09001621
1622 // Ensure that not_in_apex is linking with the static variant of mylib
Colin Cross7113d202019-11-20 16:39:12 -08001623 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001624}
Jiyong Park9335a262018-12-24 11:31:58 +09001625
1626func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001627 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001628 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001629 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001630 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001631 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001632 native_shared_libs: ["mylib"],
Jooyung Han54aca7b2019-11-20 02:26:02 +09001633 file_contexts: ":myapex-file_contexts",
Jiyong Park9335a262018-12-24 11:31:58 +09001634 }
1635
1636 cc_library {
1637 name: "mylib",
1638 srcs: ["mylib.cpp"],
1639 system_shared_libs: [],
1640 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001641 apex_available: [ "myapex_keytest" ],
Jiyong Park9335a262018-12-24 11:31:58 +09001642 }
1643
1644 apex_key {
1645 name: "myapex.key",
1646 public_key: "testkey.avbpubkey",
1647 private_key: "testkey.pem",
1648 }
1649
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001650 android_app_certificate {
1651 name: "myapex.certificate",
1652 certificate: "testkey",
1653 }
1654
1655 android_app_certificate {
1656 name: "myapex.certificate.override",
1657 certificate: "testkey.override",
1658 }
1659
Jiyong Park9335a262018-12-24 11:31:58 +09001660 `)
1661
1662 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001663 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001664
1665 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1666 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1667 "vendor/foo/devkeys/testkey.avbpubkey")
1668 }
1669 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1670 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1671 "vendor/foo/devkeys/testkey.pem")
1672 }
1673
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001674 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001675 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001676 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001677 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001678 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001679 }
1680}
Jiyong Park58e364a2019-01-19 19:24:06 +09001681
Jooyung Hanf121a652019-12-17 14:30:11 +09001682func TestCertificate(t *testing.T) {
1683 t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) {
1684 ctx, _ := testApex(t, `
1685 apex {
1686 name: "myapex",
1687 key: "myapex.key",
1688 }
1689 apex_key {
1690 name: "myapex.key",
1691 public_key: "testkey.avbpubkey",
1692 private_key: "testkey.pem",
1693 }`)
1694 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1695 expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8"
1696 if actual := rule.Args["certificates"]; actual != expected {
1697 t.Errorf("certificates should be %q, not %q", expected, actual)
1698 }
1699 })
1700 t.Run("override when unspecified", func(t *testing.T) {
1701 ctx, _ := testApex(t, `
1702 apex {
1703 name: "myapex_keytest",
1704 key: "myapex.key",
1705 file_contexts: ":myapex-file_contexts",
1706 }
1707 apex_key {
1708 name: "myapex.key",
1709 public_key: "testkey.avbpubkey",
1710 private_key: "testkey.pem",
1711 }
1712 android_app_certificate {
1713 name: "myapex.certificate.override",
1714 certificate: "testkey.override",
1715 }`)
1716 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1717 expected := "testkey.override.x509.pem testkey.override.pk8"
1718 if actual := rule.Args["certificates"]; actual != expected {
1719 t.Errorf("certificates should be %q, not %q", expected, actual)
1720 }
1721 })
1722 t.Run("if specified as :module, it respects the prop", func(t *testing.T) {
1723 ctx, _ := testApex(t, `
1724 apex {
1725 name: "myapex",
1726 key: "myapex.key",
1727 certificate: ":myapex.certificate",
1728 }
1729 apex_key {
1730 name: "myapex.key",
1731 public_key: "testkey.avbpubkey",
1732 private_key: "testkey.pem",
1733 }
1734 android_app_certificate {
1735 name: "myapex.certificate",
1736 certificate: "testkey",
1737 }`)
1738 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1739 expected := "testkey.x509.pem testkey.pk8"
1740 if actual := rule.Args["certificates"]; actual != expected {
1741 t.Errorf("certificates should be %q, not %q", expected, actual)
1742 }
1743 })
1744 t.Run("override when specifiec as <:module>", func(t *testing.T) {
1745 ctx, _ := testApex(t, `
1746 apex {
1747 name: "myapex_keytest",
1748 key: "myapex.key",
1749 file_contexts: ":myapex-file_contexts",
1750 certificate: ":myapex.certificate",
1751 }
1752 apex_key {
1753 name: "myapex.key",
1754 public_key: "testkey.avbpubkey",
1755 private_key: "testkey.pem",
1756 }
1757 android_app_certificate {
1758 name: "myapex.certificate.override",
1759 certificate: "testkey.override",
1760 }`)
1761 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1762 expected := "testkey.override.x509.pem testkey.override.pk8"
1763 if actual := rule.Args["certificates"]; actual != expected {
1764 t.Errorf("certificates should be %q, not %q", expected, actual)
1765 }
1766 })
1767 t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) {
1768 ctx, _ := testApex(t, `
1769 apex {
1770 name: "myapex",
1771 key: "myapex.key",
1772 certificate: "testkey",
1773 }
1774 apex_key {
1775 name: "myapex.key",
1776 public_key: "testkey.avbpubkey",
1777 private_key: "testkey.pem",
1778 }`)
1779 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1780 expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8"
1781 if actual := rule.Args["certificates"]; actual != expected {
1782 t.Errorf("certificates should be %q, not %q", expected, actual)
1783 }
1784 })
1785 t.Run("override when specified as <name>", func(t *testing.T) {
1786 ctx, _ := testApex(t, `
1787 apex {
1788 name: "myapex_keytest",
1789 key: "myapex.key",
1790 file_contexts: ":myapex-file_contexts",
1791 certificate: "testkey",
1792 }
1793 apex_key {
1794 name: "myapex.key",
1795 public_key: "testkey.avbpubkey",
1796 private_key: "testkey.pem",
1797 }
1798 android_app_certificate {
1799 name: "myapex.certificate.override",
1800 certificate: "testkey.override",
1801 }`)
1802 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1803 expected := "testkey.override.x509.pem testkey.override.pk8"
1804 if actual := rule.Args["certificates"]; actual != expected {
1805 t.Errorf("certificates should be %q, not %q", expected, actual)
1806 }
1807 })
1808}
1809
Jiyong Park58e364a2019-01-19 19:24:06 +09001810func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001811 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001812 apex {
1813 name: "myapex",
1814 key: "myapex.key",
Jooyung Hanc87a0592020-03-02 17:44:33 +09001815 native_shared_libs: ["mylib", "mylib2"],
Jiyong Park58e364a2019-01-19 19:24:06 +09001816 }
1817
1818 apex {
1819 name: "otherapex",
1820 key: "myapex.key",
Jooyung Hanc87a0592020-03-02 17:44:33 +09001821 native_shared_libs: ["mylib", "mylib2"],
Jooyung Hanccce2f22020-03-07 03:45:53 +09001822 min_sdk_version: "29",
Jiyong Park58e364a2019-01-19 19:24:06 +09001823 }
1824
1825 apex_key {
1826 name: "myapex.key",
1827 public_key: "testkey.avbpubkey",
1828 private_key: "testkey.pem",
1829 }
1830
1831 cc_library {
1832 name: "mylib",
1833 srcs: ["mylib.cpp"],
1834 system_shared_libs: [],
1835 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001836 apex_available: [
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001837 "myapex",
1838 "otherapex",
1839 ],
Jooyung Han24282772020-03-21 23:20:55 +09001840 recovery_available: true,
Jiyong Park58e364a2019-01-19 19:24:06 +09001841 }
Jooyung Hanc87a0592020-03-02 17:44:33 +09001842 cc_library {
1843 name: "mylib2",
1844 srcs: ["mylib.cpp"],
1845 system_shared_libs: [],
1846 stl: "none",
1847 apex_available: [
1848 "myapex",
1849 "otherapex",
1850 ],
1851 use_apex_name_macro: true,
1852 }
Jiyong Park58e364a2019-01-19 19:24:06 +09001853 `)
1854
Jooyung Hanc87a0592020-03-02 17:44:33 +09001855 // non-APEX variant does not have __ANDROID_APEX__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001856 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001857 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han75568392020-03-20 04:29:24 +09001858 ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__")
Jooyung Hanc87a0592020-03-02 17:44:33 +09001859
Jooyung Hanccce2f22020-03-07 03:45:53 +09001860 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Jooyung Hanc87a0592020-03-02 17:44:33 +09001861 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
1862 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Hanccce2f22020-03-07 03:45:53 +09001863 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
Jooyung Han77988572019-10-18 16:26:16 +09001864 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
Jooyung Hanc87a0592020-03-02 17:44:33 +09001865
Jooyung Hanccce2f22020-03-07 03:45:53 +09001866 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Jooyung Hanc87a0592020-03-02 17:44:33 +09001867 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
1868 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Hanccce2f22020-03-07 03:45:53 +09001869 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29")
Jooyung Han77988572019-10-18 16:26:16 +09001870 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001871
Jooyung Hanc87a0592020-03-02 17:44:33 +09001872 // When cc_library sets use_apex_name_macro: true
1873 // apex variants define additional macro to distinguish which apex variant it is built for
1874
1875 // non-APEX variant does not have __ANDROID_APEX__ defined
1876 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
1877 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
1878
1879 // APEX variant has __ANDROID_APEX__ defined
1880 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001881 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001882 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1883 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001884
Jooyung Hanc87a0592020-03-02 17:44:33 +09001885 // APEX variant has __ANDROID_APEX__ defined
1886 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001887 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001888 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1889 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jooyung Han24282772020-03-21 23:20:55 +09001890
1891 // recovery variant does not set __ANDROID_SDK_VERSION__
1892 mylibCFlags = ctx.ModuleForTests("mylib", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
1893 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
1894 ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001895}
Jiyong Park7e636d02019-01-28 16:16:54 +09001896
1897func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001898 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001899 apex {
1900 name: "myapex",
1901 key: "myapex.key",
1902 native_shared_libs: ["mylib"],
1903 }
1904
1905 apex_key {
1906 name: "myapex.key",
1907 public_key: "testkey.avbpubkey",
1908 private_key: "testkey.pem",
1909 }
1910
1911 cc_library_headers {
1912 name: "mylib_headers",
1913 export_include_dirs: ["my_include"],
1914 system_shared_libs: [],
1915 stl: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +09001916 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001917 }
1918
1919 cc_library {
1920 name: "mylib",
1921 srcs: ["mylib.cpp"],
1922 system_shared_libs: [],
1923 stl: "none",
1924 header_libs: ["mylib_headers"],
1925 export_header_lib_headers: ["mylib_headers"],
1926 stubs: {
1927 versions: ["1", "2", "3"],
1928 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001929 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001930 }
1931
1932 cc_library {
1933 name: "otherlib",
1934 srcs: ["mylib.cpp"],
1935 system_shared_libs: [],
1936 stl: "none",
1937 shared_libs: ["mylib"],
1938 }
1939 `)
1940
Colin Cross7113d202019-11-20 16:39:12 -08001941 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park7e636d02019-01-28 16:16:54 +09001942
1943 // Ensure that the include path of the header lib is exported to 'otherlib'
1944 ensureContains(t, cFlags, "-Imy_include")
1945}
Alex Light9670d332019-01-29 18:07:33 -08001946
Jiyong Park7cd10e32020-01-14 09:22:18 +09001947type fileInApex struct {
1948 path string // path in apex
Jooyung Hana57af4a2020-01-23 05:36:59 +00001949 src string // src path
Jiyong Park7cd10e32020-01-14 09:22:18 +09001950 isLink bool
1951}
1952
Jooyung Hana57af4a2020-01-23 05:36:59 +00001953func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex {
Jooyung Han31c470b2019-10-18 16:26:59 +09001954 t.Helper()
Jooyung Hana57af4a2020-01-23 05:36:59 +00001955 apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001956 copyCmds := apexRule.Args["copy_commands"]
1957 imageApexDir := "/image.apex/"
Jiyong Park7cd10e32020-01-14 09:22:18 +09001958 var ret []fileInApex
Jooyung Han31c470b2019-10-18 16:26:59 +09001959 for _, cmd := range strings.Split(copyCmds, "&&") {
1960 cmd = strings.TrimSpace(cmd)
1961 if cmd == "" {
1962 continue
1963 }
1964 terms := strings.Split(cmd, " ")
Jooyung Hana57af4a2020-01-23 05:36:59 +00001965 var dst, src string
Jiyong Park7cd10e32020-01-14 09:22:18 +09001966 var isLink bool
Jooyung Han31c470b2019-10-18 16:26:59 +09001967 switch terms[0] {
1968 case "mkdir":
1969 case "cp":
Jiyong Park7cd10e32020-01-14 09:22:18 +09001970 if len(terms) != 3 && len(terms) != 4 {
Jooyung Han31c470b2019-10-18 16:26:59 +09001971 t.Fatal("copyCmds contains invalid cp command", cmd)
1972 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001973 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001974 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001975 isLink = false
1976 case "ln":
1977 if len(terms) != 3 && len(terms) != 4 {
1978 // ln LINK TARGET or ln -s LINK TARGET
1979 t.Fatal("copyCmds contains invalid ln command", cmd)
1980 }
1981 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001982 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001983 isLink = true
1984 default:
1985 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1986 }
1987 if dst != "" {
Jooyung Han31c470b2019-10-18 16:26:59 +09001988 index := strings.Index(dst, imageApexDir)
1989 if index == -1 {
1990 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1991 }
1992 dstFile := dst[index+len(imageApexDir):]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001993 ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink})
Jooyung Han31c470b2019-10-18 16:26:59 +09001994 }
1995 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001996 return ret
1997}
1998
Jooyung Hana57af4a2020-01-23 05:36:59 +00001999func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) {
2000 t.Helper()
Jiyong Park7cd10e32020-01-14 09:22:18 +09002001 var failed bool
2002 var surplus []string
2003 filesMatched := make(map[string]bool)
Jooyung Hana57af4a2020-01-23 05:36:59 +00002004 for _, file := range getFiles(t, ctx, moduleName, variant) {
Jooyung Hane6436d72020-02-27 13:31:56 +09002005 mactchFound := false
Jiyong Park7cd10e32020-01-14 09:22:18 +09002006 for _, expected := range files {
2007 if matched, _ := path.Match(expected, file.path); matched {
2008 filesMatched[expected] = true
Jooyung Hane6436d72020-02-27 13:31:56 +09002009 mactchFound = true
2010 break
Jiyong Park7cd10e32020-01-14 09:22:18 +09002011 }
2012 }
Jooyung Hane6436d72020-02-27 13:31:56 +09002013 if !mactchFound {
2014 surplus = append(surplus, file.path)
2015 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002016 }
Jooyung Han31c470b2019-10-18 16:26:59 +09002017
Jooyung Han31c470b2019-10-18 16:26:59 +09002018 if len(surplus) > 0 {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002019 sort.Strings(surplus)
Jooyung Han31c470b2019-10-18 16:26:59 +09002020 t.Log("surplus files", surplus)
2021 failed = true
2022 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002023
2024 if len(files) > len(filesMatched) {
2025 var missing []string
2026 for _, expected := range files {
2027 if !filesMatched[expected] {
2028 missing = append(missing, expected)
2029 }
2030 }
2031 sort.Strings(missing)
Jooyung Han31c470b2019-10-18 16:26:59 +09002032 t.Log("missing files", missing)
2033 failed = true
2034 }
2035 if failed {
2036 t.Fail()
2037 }
2038}
2039
Jooyung Han344d5432019-08-23 11:17:39 +09002040func TestVndkApexCurrent(t *testing.T) {
2041 ctx, _ := testApex(t, `
2042 apex_vndk {
2043 name: "myapex",
2044 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09002045 }
2046
2047 apex_key {
2048 name: "myapex.key",
2049 public_key: "testkey.avbpubkey",
2050 private_key: "testkey.pem",
2051 }
2052
2053 cc_library {
2054 name: "libvndk",
2055 srcs: ["mylib.cpp"],
2056 vendor_available: true,
2057 vndk: {
2058 enabled: true,
2059 },
2060 system_shared_libs: [],
2061 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002062 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002063 }
2064
2065 cc_library {
2066 name: "libvndksp",
2067 srcs: ["mylib.cpp"],
2068 vendor_available: true,
2069 vndk: {
2070 enabled: true,
2071 support_system_process: true,
2072 },
2073 system_shared_libs: [],
2074 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002075 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002076 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002077 `+vndkLibrariesTxtFiles("current"))
Jooyung Han344d5432019-08-23 11:17:39 +09002078
Jooyung Hana57af4a2020-01-23 05:36:59 +00002079 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002080 "lib/libvndk.so",
2081 "lib/libvndksp.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09002082 "lib/libc++.so",
Jooyung Han31c470b2019-10-18 16:26:59 +09002083 "lib64/libvndk.so",
2084 "lib64/libvndksp.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09002085 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002086 "etc/llndk.libraries.VER.txt",
2087 "etc/vndkcore.libraries.VER.txt",
2088 "etc/vndksp.libraries.VER.txt",
2089 "etc/vndkprivate.libraries.VER.txt",
Jooyung Han31c470b2019-10-18 16:26:59 +09002090 })
Jooyung Han344d5432019-08-23 11:17:39 +09002091}
2092
2093func TestVndkApexWithPrebuilt(t *testing.T) {
2094 ctx, _ := testApex(t, `
2095 apex_vndk {
2096 name: "myapex",
2097 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09002098 }
2099
2100 apex_key {
2101 name: "myapex.key",
2102 public_key: "testkey.avbpubkey",
2103 private_key: "testkey.pem",
2104 }
2105
2106 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09002107 name: "libvndk",
2108 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09002109 vendor_available: true,
2110 vndk: {
2111 enabled: true,
2112 },
2113 system_shared_libs: [],
2114 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002115 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002116 }
Jooyung Han31c470b2019-10-18 16:26:59 +09002117
2118 cc_prebuilt_library_shared {
2119 name: "libvndk.arm",
2120 srcs: ["libvndk.arm.so"],
2121 vendor_available: true,
2122 vndk: {
2123 enabled: true,
2124 },
2125 enabled: false,
2126 arch: {
2127 arm: {
2128 enabled: true,
2129 },
2130 },
2131 system_shared_libs: [],
2132 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002133 apex_available: [ "myapex" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002134 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002135 `+vndkLibrariesTxtFiles("current"),
2136 withFiles(map[string][]byte{
2137 "libvndk.so": nil,
2138 "libvndk.arm.so": nil,
2139 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002140
Jooyung Hana57af4a2020-01-23 05:36:59 +00002141 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002142 "lib/libvndk.so",
2143 "lib/libvndk.arm.so",
2144 "lib64/libvndk.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09002145 "lib/libc++.so",
2146 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002147 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002148 })
Jooyung Han344d5432019-08-23 11:17:39 +09002149}
2150
Jooyung Han39edb6c2019-11-06 16:53:07 +09002151func vndkLibrariesTxtFiles(vers ...string) (result string) {
2152 for _, v := range vers {
2153 if v == "current" {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +09002154 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002155 result += `
2156 vndk_libraries_txt {
2157 name: "` + txt + `.libraries.txt",
2158 }
2159 `
2160 }
2161 } else {
2162 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
2163 result += `
2164 prebuilt_etc {
2165 name: "` + txt + `.libraries.` + v + `.txt",
2166 src: "dummy.txt",
2167 }
2168 `
2169 }
2170 }
2171 }
2172 return
2173}
2174
Jooyung Han344d5432019-08-23 11:17:39 +09002175func TestVndkApexVersion(t *testing.T) {
2176 ctx, _ := testApex(t, `
2177 apex_vndk {
2178 name: "myapex_v27",
2179 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002180 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002181 vndk_version: "27",
2182 }
2183
2184 apex_key {
2185 name: "myapex.key",
2186 public_key: "testkey.avbpubkey",
2187 private_key: "testkey.pem",
2188 }
2189
Jooyung Han31c470b2019-10-18 16:26:59 +09002190 vndk_prebuilt_shared {
2191 name: "libvndk27",
2192 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09002193 vendor_available: true,
2194 vndk: {
2195 enabled: true,
2196 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002197 target_arch: "arm64",
2198 arch: {
2199 arm: {
2200 srcs: ["libvndk27_arm.so"],
2201 },
2202 arm64: {
2203 srcs: ["libvndk27_arm64.so"],
2204 },
2205 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002206 apex_available: [ "myapex_v27" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002207 }
2208
2209 vndk_prebuilt_shared {
2210 name: "libvndk27",
2211 version: "27",
2212 vendor_available: true,
2213 vndk: {
2214 enabled: true,
2215 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002216 target_arch: "x86_64",
2217 arch: {
2218 x86: {
2219 srcs: ["libvndk27_x86.so"],
2220 },
2221 x86_64: {
2222 srcs: ["libvndk27_x86_64.so"],
2223 },
2224 },
Jooyung Han39edb6c2019-11-06 16:53:07 +09002225 }
2226 `+vndkLibrariesTxtFiles("27"),
2227 withFiles(map[string][]byte{
2228 "libvndk27_arm.so": nil,
2229 "libvndk27_arm64.so": nil,
2230 "libvndk27_x86.so": nil,
2231 "libvndk27_x86_64.so": nil,
2232 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002233
Jooyung Hana57af4a2020-01-23 05:36:59 +00002234 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002235 "lib/libvndk27_arm.so",
2236 "lib64/libvndk27_arm64.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002237 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002238 })
Jooyung Han344d5432019-08-23 11:17:39 +09002239}
2240
2241func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
2242 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
2243 apex_vndk {
2244 name: "myapex_v27",
2245 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002246 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002247 vndk_version: "27",
2248 }
2249 apex_vndk {
2250 name: "myapex_v27_other",
2251 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002252 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002253 vndk_version: "27",
2254 }
2255
2256 apex_key {
2257 name: "myapex.key",
2258 public_key: "testkey.avbpubkey",
2259 private_key: "testkey.pem",
2260 }
2261
2262 cc_library {
2263 name: "libvndk",
2264 srcs: ["mylib.cpp"],
2265 vendor_available: true,
2266 vndk: {
2267 enabled: true,
2268 },
2269 system_shared_libs: [],
2270 stl: "none",
2271 }
2272
2273 vndk_prebuilt_shared {
2274 name: "libvndk",
2275 version: "27",
2276 vendor_available: true,
2277 vndk: {
2278 enabled: true,
2279 },
2280 srcs: ["libvndk.so"],
2281 }
2282 `, withFiles(map[string][]byte{
2283 "libvndk.so": nil,
2284 }))
2285}
2286
Jooyung Han90eee022019-10-01 20:02:42 +09002287func TestVndkApexNameRule(t *testing.T) {
2288 ctx, _ := testApex(t, `
2289 apex_vndk {
2290 name: "myapex",
2291 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002292 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002293 }
2294 apex_vndk {
2295 name: "myapex_v28",
2296 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002297 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002298 vndk_version: "28",
2299 }
2300 apex_key {
2301 name: "myapex.key",
2302 public_key: "testkey.avbpubkey",
2303 private_key: "testkey.pem",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002304 }`+vndkLibrariesTxtFiles("28", "current"))
Jooyung Han90eee022019-10-01 20:02:42 +09002305
2306 assertApexName := func(expected, moduleName string) {
Jooyung Hana57af4a2020-01-23 05:36:59 +00002307 bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09002308 actual := proptools.String(bundle.properties.Apex_name)
2309 if !reflect.DeepEqual(actual, expected) {
2310 t.Errorf("Got '%v', expected '%v'", actual, expected)
2311 }
2312 }
2313
2314 assertApexName("com.android.vndk.vVER", "myapex")
2315 assertApexName("com.android.vndk.v28", "myapex_v28")
2316}
2317
Jooyung Han344d5432019-08-23 11:17:39 +09002318func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
2319 ctx, _ := testApex(t, `
2320 apex_vndk {
2321 name: "myapex",
2322 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002323 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002324 }
2325
2326 apex_key {
2327 name: "myapex.key",
2328 public_key: "testkey.avbpubkey",
2329 private_key: "testkey.pem",
2330 }
2331
2332 cc_library {
2333 name: "libvndk",
2334 srcs: ["mylib.cpp"],
2335 vendor_available: true,
2336 native_bridge_supported: true,
2337 host_supported: true,
2338 vndk: {
2339 enabled: true,
2340 },
2341 system_shared_libs: [],
2342 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002343 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002344 }
Jooyung Han35155c42020-02-06 17:33:20 +09002345 `+vndkLibrariesTxtFiles("current"), withNativeBridgeEnabled)
Jooyung Han344d5432019-08-23 11:17:39 +09002346
Jooyung Hana57af4a2020-01-23 05:36:59 +00002347 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002348 "lib/libvndk.so",
2349 "lib64/libvndk.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09002350 "lib/libc++.so",
2351 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002352 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002353 })
Jooyung Han344d5432019-08-23 11:17:39 +09002354}
2355
2356func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
2357 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
2358 apex_vndk {
2359 name: "myapex",
2360 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002361 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002362 native_bridge_supported: true,
2363 }
2364
2365 apex_key {
2366 name: "myapex.key",
2367 public_key: "testkey.avbpubkey",
2368 private_key: "testkey.pem",
2369 }
2370
2371 cc_library {
2372 name: "libvndk",
2373 srcs: ["mylib.cpp"],
2374 vendor_available: true,
2375 native_bridge_supported: true,
2376 host_supported: true,
2377 vndk: {
2378 enabled: true,
2379 },
2380 system_shared_libs: [],
2381 stl: "none",
2382 }
2383 `)
2384}
2385
Jooyung Han31c470b2019-10-18 16:26:59 +09002386func TestVndkApexWithBinder32(t *testing.T) {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002387 ctx, _ := testApex(t, `
Jooyung Han31c470b2019-10-18 16:26:59 +09002388 apex_vndk {
2389 name: "myapex_v27",
2390 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002391 file_contexts: ":myapex-file_contexts",
Jooyung Han31c470b2019-10-18 16:26:59 +09002392 vndk_version: "27",
2393 }
2394
2395 apex_key {
2396 name: "myapex.key",
2397 public_key: "testkey.avbpubkey",
2398 private_key: "testkey.pem",
2399 }
2400
2401 vndk_prebuilt_shared {
2402 name: "libvndk27",
2403 version: "27",
2404 target_arch: "arm",
2405 vendor_available: true,
2406 vndk: {
2407 enabled: true,
2408 },
2409 arch: {
2410 arm: {
2411 srcs: ["libvndk27.so"],
2412 }
2413 },
2414 }
2415
2416 vndk_prebuilt_shared {
2417 name: "libvndk27",
2418 version: "27",
2419 target_arch: "arm",
2420 binder32bit: true,
2421 vendor_available: true,
2422 vndk: {
2423 enabled: true,
2424 },
2425 arch: {
2426 arm: {
2427 srcs: ["libvndk27binder32.so"],
2428 }
2429 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002430 apex_available: [ "myapex_v27" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002431 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002432 `+vndkLibrariesTxtFiles("27"),
Jooyung Han31c470b2019-10-18 16:26:59 +09002433 withFiles(map[string][]byte{
2434 "libvndk27.so": nil,
2435 "libvndk27binder32.so": nil,
2436 }),
2437 withBinder32bit,
2438 withTargets(map[android.OsType][]android.Target{
2439 android.Android: []android.Target{
Jooyung Han35155c42020-02-06 17:33:20 +09002440 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}},
2441 NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
Jooyung Han31c470b2019-10-18 16:26:59 +09002442 },
2443 }),
2444 )
2445
Jooyung Hana57af4a2020-01-23 05:36:59 +00002446 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002447 "lib/libvndk27binder32.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002448 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002449 })
2450}
2451
Jooyung Hane1633032019-08-01 17:41:43 +09002452func TestDependenciesInApexManifest(t *testing.T) {
2453 ctx, _ := testApex(t, `
2454 apex {
2455 name: "myapex_nodep",
2456 key: "myapex.key",
2457 native_shared_libs: ["lib_nodep"],
2458 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002459 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002460 }
2461
2462 apex {
2463 name: "myapex_dep",
2464 key: "myapex.key",
2465 native_shared_libs: ["lib_dep"],
2466 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002467 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002468 }
2469
2470 apex {
2471 name: "myapex_provider",
2472 key: "myapex.key",
2473 native_shared_libs: ["libfoo"],
2474 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002475 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002476 }
2477
2478 apex {
2479 name: "myapex_selfcontained",
2480 key: "myapex.key",
2481 native_shared_libs: ["lib_dep", "libfoo"],
2482 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002483 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002484 }
2485
2486 apex_key {
2487 name: "myapex.key",
2488 public_key: "testkey.avbpubkey",
2489 private_key: "testkey.pem",
2490 }
2491
2492 cc_library {
2493 name: "lib_nodep",
2494 srcs: ["mylib.cpp"],
2495 system_shared_libs: [],
2496 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002497 apex_available: [ "myapex_nodep" ],
Jooyung Hane1633032019-08-01 17:41:43 +09002498 }
2499
2500 cc_library {
2501 name: "lib_dep",
2502 srcs: ["mylib.cpp"],
2503 shared_libs: ["libfoo"],
2504 system_shared_libs: [],
2505 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002506 apex_available: [
2507 "myapex_dep",
2508 "myapex_provider",
2509 "myapex_selfcontained",
2510 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002511 }
2512
2513 cc_library {
2514 name: "libfoo",
2515 srcs: ["mytest.cpp"],
2516 stubs: {
2517 versions: ["1"],
2518 },
2519 system_shared_libs: [],
2520 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002521 apex_available: [
2522 "myapex_provider",
2523 "myapex_selfcontained",
2524 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002525 }
2526 `)
2527
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002528 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09002529 var provideNativeLibs, requireNativeLibs []string
2530
Sundong Ahnabb64432019-10-22 13:58:29 +09002531 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002532 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2533 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002534 ensureListEmpty(t, provideNativeLibs)
2535 ensureListEmpty(t, requireNativeLibs)
2536
Sundong Ahnabb64432019-10-22 13:58:29 +09002537 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002538 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2539 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002540 ensureListEmpty(t, provideNativeLibs)
2541 ensureListContains(t, requireNativeLibs, "libfoo.so")
2542
Sundong Ahnabb64432019-10-22 13:58:29 +09002543 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002544 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2545 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002546 ensureListContains(t, provideNativeLibs, "libfoo.so")
2547 ensureListEmpty(t, requireNativeLibs)
2548
Sundong Ahnabb64432019-10-22 13:58:29 +09002549 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002550 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2551 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002552 ensureListContains(t, provideNativeLibs, "libfoo.so")
2553 ensureListEmpty(t, requireNativeLibs)
2554}
2555
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002556func TestApexName(t *testing.T) {
Jiyong Parkdb334862020-02-05 17:19:28 +09002557 ctx, config := testApex(t, `
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002558 apex {
2559 name: "myapex",
2560 key: "myapex.key",
2561 apex_name: "com.android.myapex",
Jiyong Parkdb334862020-02-05 17:19:28 +09002562 native_shared_libs: ["mylib"],
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002563 }
2564
2565 apex_key {
2566 name: "myapex.key",
2567 public_key: "testkey.avbpubkey",
2568 private_key: "testkey.pem",
2569 }
Jiyong Parkdb334862020-02-05 17:19:28 +09002570
2571 cc_library {
2572 name: "mylib",
2573 srcs: ["mylib.cpp"],
2574 system_shared_libs: [],
2575 stl: "none",
2576 apex_available: [
2577 "//apex_available:platform",
2578 "myapex",
2579 ],
2580 }
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002581 `)
2582
Sundong Ahnabb64432019-10-22 13:58:29 +09002583 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002584 apexManifestRule := module.Rule("apexManifestRule")
2585 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
2586 apexRule := module.Rule("apexRule")
2587 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
Jiyong Parkdb334862020-02-05 17:19:28 +09002588
2589 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2590 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2591 name := apexBundle.BaseModuleName()
2592 prefix := "TARGET_"
2593 var builder strings.Builder
2594 data.Custom(&builder, name, prefix, "", data)
2595 androidMk := builder.String()
2596 ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n")
2597 ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002598}
2599
Alex Light0851b882019-02-07 13:20:53 -08002600func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002601 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002602 apex {
2603 name: "myapex",
2604 key: "myapex.key",
2605 native_shared_libs: ["mylib_common"],
2606 }
2607
2608 apex_key {
2609 name: "myapex.key",
2610 public_key: "testkey.avbpubkey",
2611 private_key: "testkey.pem",
2612 }
2613
2614 cc_library {
2615 name: "mylib_common",
2616 srcs: ["mylib.cpp"],
2617 system_shared_libs: [],
2618 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002619 apex_available: [
2620 "//apex_available:platform",
2621 "myapex",
2622 ],
Alex Light0851b882019-02-07 13:20:53 -08002623 }
2624 `)
2625
Sundong Ahnabb64432019-10-22 13:58:29 +09002626 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002627 apexRule := module.Rule("apexRule")
2628 copyCmds := apexRule.Args["copy_commands"]
2629
2630 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
2631 t.Log("Apex was a test apex!")
2632 t.Fail()
2633 }
2634 // Ensure that main rule creates an output
2635 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2636
2637 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002638 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002639
2640 // Ensure that both direct and indirect deps are copied into apex
2641 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2642
Colin Cross7113d202019-11-20 16:39:12 -08002643 // Ensure that the platform variant ends with _shared
2644 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002645
2646 if !android.InAnyApex("mylib_common") {
2647 t.Log("Found mylib_common not in any apex!")
2648 t.Fail()
2649 }
2650}
2651
2652func TestTestApex(t *testing.T) {
2653 if android.InAnyApex("mylib_common_test") {
2654 t.Fatal("mylib_common_test must not be used in any other tests since this checks that global state is not updated in an illegal way!")
2655 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002656 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002657 apex_test {
2658 name: "myapex",
2659 key: "myapex.key",
2660 native_shared_libs: ["mylib_common_test"],
2661 }
2662
2663 apex_key {
2664 name: "myapex.key",
2665 public_key: "testkey.avbpubkey",
2666 private_key: "testkey.pem",
2667 }
2668
2669 cc_library {
2670 name: "mylib_common_test",
2671 srcs: ["mylib.cpp"],
2672 system_shared_libs: [],
2673 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002674 // TODO: remove //apex_available:platform
2675 apex_available: [
2676 "//apex_available:platform",
2677 "myapex",
2678 ],
Alex Light0851b882019-02-07 13:20:53 -08002679 }
2680 `)
2681
Sundong Ahnabb64432019-10-22 13:58:29 +09002682 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002683 apexRule := module.Rule("apexRule")
2684 copyCmds := apexRule.Args["copy_commands"]
2685
2686 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
2687 t.Log("Apex was not a test apex!")
2688 t.Fail()
2689 }
2690 // Ensure that main rule creates an output
2691 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2692
2693 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002694 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002695
2696 // Ensure that both direct and indirect deps are copied into apex
2697 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
2698
Colin Cross7113d202019-11-20 16:39:12 -08002699 // Ensure that the platform variant ends with _shared
2700 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002701}
2702
Alex Light9670d332019-01-29 18:07:33 -08002703func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002704 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08002705 apex {
2706 name: "myapex",
2707 key: "myapex.key",
2708 multilib: {
2709 first: {
2710 native_shared_libs: ["mylib_common"],
2711 }
2712 },
2713 target: {
2714 android: {
2715 multilib: {
2716 first: {
2717 native_shared_libs: ["mylib"],
2718 }
2719 }
2720 },
2721 host: {
2722 multilib: {
2723 first: {
2724 native_shared_libs: ["mylib2"],
2725 }
2726 }
2727 }
2728 }
2729 }
2730
2731 apex_key {
2732 name: "myapex.key",
2733 public_key: "testkey.avbpubkey",
2734 private_key: "testkey.pem",
2735 }
2736
2737 cc_library {
2738 name: "mylib",
2739 srcs: ["mylib.cpp"],
2740 system_shared_libs: [],
2741 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002742 // TODO: remove //apex_available:platform
2743 apex_available: [
2744 "//apex_available:platform",
2745 "myapex",
2746 ],
Alex Light9670d332019-01-29 18:07:33 -08002747 }
2748
2749 cc_library {
2750 name: "mylib_common",
2751 srcs: ["mylib.cpp"],
2752 system_shared_libs: [],
2753 stl: "none",
2754 compile_multilib: "first",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002755 // TODO: remove //apex_available:platform
2756 apex_available: [
2757 "//apex_available:platform",
2758 "myapex",
2759 ],
Alex Light9670d332019-01-29 18:07:33 -08002760 }
2761
2762 cc_library {
2763 name: "mylib2",
2764 srcs: ["mylib.cpp"],
2765 system_shared_libs: [],
2766 stl: "none",
2767 compile_multilib: "first",
2768 }
2769 `)
2770
Sundong Ahnabb64432019-10-22 13:58:29 +09002771 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002772 copyCmds := apexRule.Args["copy_commands"]
2773
2774 // Ensure that main rule creates an output
2775 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2776
2777 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002778 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2779 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
2780 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light9670d332019-01-29 18:07:33 -08002781
2782 // Ensure that both direct and indirect deps are copied into apex
2783 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2784 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2785 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2786
Colin Cross7113d202019-11-20 16:39:12 -08002787 // Ensure that the platform variant ends with _shared
2788 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
2789 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
2790 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Alex Light9670d332019-01-29 18:07:33 -08002791}
Jiyong Park04480cf2019-02-06 00:16:29 +09002792
2793func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002794 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002795 apex {
2796 name: "myapex",
2797 key: "myapex.key",
2798 binaries: ["myscript"],
2799 }
2800
2801 apex_key {
2802 name: "myapex.key",
2803 public_key: "testkey.avbpubkey",
2804 private_key: "testkey.pem",
2805 }
2806
2807 sh_binary {
2808 name: "myscript",
2809 src: "mylib.cpp",
2810 filename: "myscript.sh",
2811 sub_dir: "script",
2812 }
2813 `)
2814
Sundong Ahnabb64432019-10-22 13:58:29 +09002815 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002816 copyCmds := apexRule.Args["copy_commands"]
2817
2818 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2819}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002820
Jooyung Han91df2082019-11-20 01:49:42 +09002821func TestApexInVariousPartition(t *testing.T) {
2822 testcases := []struct {
2823 propName, parition, flattenedPartition string
2824 }{
2825 {"", "system", "system_ext"},
2826 {"product_specific: true", "product", "product"},
2827 {"soc_specific: true", "vendor", "vendor"},
2828 {"proprietary: true", "vendor", "vendor"},
2829 {"vendor: true", "vendor", "vendor"},
2830 {"system_ext_specific: true", "system_ext", "system_ext"},
2831 }
2832 for _, tc := range testcases {
2833 t.Run(tc.propName+":"+tc.parition, func(t *testing.T) {
2834 ctx, _ := testApex(t, `
2835 apex {
2836 name: "myapex",
2837 key: "myapex.key",
2838 `+tc.propName+`
2839 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002840
Jooyung Han91df2082019-11-20 01:49:42 +09002841 apex_key {
2842 name: "myapex.key",
2843 public_key: "testkey.avbpubkey",
2844 private_key: "testkey.pem",
2845 }
2846 `)
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002847
Jooyung Han91df2082019-11-20 01:49:42 +09002848 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2849 expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex"
2850 actual := apex.installDir.String()
2851 if actual != expected {
2852 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2853 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002854
Jooyung Han91df2082019-11-20 01:49:42 +09002855 flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
2856 expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex"
2857 actual = flattened.installDir.String()
2858 if actual != expected {
2859 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2860 }
2861 })
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002862 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002863}
Jiyong Park67882562019-03-21 01:11:21 +09002864
Jooyung Han54aca7b2019-11-20 02:26:02 +09002865func TestFileContexts(t *testing.T) {
2866 ctx, _ := testApex(t, `
2867 apex {
2868 name: "myapex",
2869 key: "myapex.key",
2870 }
2871
2872 apex_key {
2873 name: "myapex.key",
2874 public_key: "testkey.avbpubkey",
2875 private_key: "testkey.pem",
2876 }
2877 `)
2878 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
2879 apexRule := module.Rule("apexRule")
2880 actual := apexRule.Args["file_contexts"]
2881 expected := "system/sepolicy/apex/myapex-file_contexts"
2882 if actual != expected {
2883 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2884 }
2885
2886 testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
2887 apex {
2888 name: "myapex",
2889 key: "myapex.key",
2890 file_contexts: "my_own_file_contexts",
2891 }
2892
2893 apex_key {
2894 name: "myapex.key",
2895 public_key: "testkey.avbpubkey",
2896 private_key: "testkey.pem",
2897 }
2898 `, withFiles(map[string][]byte{
2899 "my_own_file_contexts": nil,
2900 }))
2901
2902 testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
2903 apex {
2904 name: "myapex",
2905 key: "myapex.key",
2906 product_specific: true,
2907 file_contexts: "product_specific_file_contexts",
2908 }
2909
2910 apex_key {
2911 name: "myapex.key",
2912 public_key: "testkey.avbpubkey",
2913 private_key: "testkey.pem",
2914 }
2915 `)
2916
2917 ctx, _ = testApex(t, `
2918 apex {
2919 name: "myapex",
2920 key: "myapex.key",
2921 product_specific: true,
2922 file_contexts: "product_specific_file_contexts",
2923 }
2924
2925 apex_key {
2926 name: "myapex.key",
2927 public_key: "testkey.avbpubkey",
2928 private_key: "testkey.pem",
2929 }
2930 `, withFiles(map[string][]byte{
2931 "product_specific_file_contexts": nil,
2932 }))
2933 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2934 apexRule = module.Rule("apexRule")
2935 actual = apexRule.Args["file_contexts"]
2936 expected = "product_specific_file_contexts"
2937 if actual != expected {
2938 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2939 }
2940
2941 ctx, _ = testApex(t, `
2942 apex {
2943 name: "myapex",
2944 key: "myapex.key",
2945 product_specific: true,
2946 file_contexts: ":my-file-contexts",
2947 }
2948
2949 apex_key {
2950 name: "myapex.key",
2951 public_key: "testkey.avbpubkey",
2952 private_key: "testkey.pem",
2953 }
2954
2955 filegroup {
2956 name: "my-file-contexts",
2957 srcs: ["product_specific_file_contexts"],
2958 }
2959 `, withFiles(map[string][]byte{
2960 "product_specific_file_contexts": nil,
2961 }))
2962 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2963 apexRule = module.Rule("apexRule")
2964 actual = apexRule.Args["file_contexts"]
2965 expected = "product_specific_file_contexts"
2966 if actual != expected {
2967 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2968 }
2969}
2970
Jiyong Park67882562019-03-21 01:11:21 +09002971func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002972 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002973 apex_key {
2974 name: "myapex.key",
2975 public_key: ":my.avbpubkey",
2976 private_key: ":my.pem",
2977 product_specific: true,
2978 }
2979
2980 filegroup {
2981 name: "my.avbpubkey",
2982 srcs: ["testkey2.avbpubkey"],
2983 }
2984
2985 filegroup {
2986 name: "my.pem",
2987 srcs: ["testkey2.pem"],
2988 }
2989 `)
2990
2991 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2992 expected_pubkey := "testkey2.avbpubkey"
2993 actual_pubkey := apex_key.public_key_file.String()
2994 if actual_pubkey != expected_pubkey {
2995 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2996 }
2997 expected_privkey := "testkey2.pem"
2998 actual_privkey := apex_key.private_key_file.String()
2999 if actual_privkey != expected_privkey {
3000 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
3001 }
3002}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07003003
3004func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003005 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07003006 prebuilt_apex {
3007 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09003008 arch: {
3009 arm64: {
3010 src: "myapex-arm64.apex",
3011 },
3012 arm: {
3013 src: "myapex-arm.apex",
3014 },
3015 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07003016 }
3017 `)
3018
3019 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
3020
Jiyong Parkc95714e2019-03-29 14:23:10 +09003021 expectedInput := "myapex-arm64.apex"
3022 if prebuilt.inputApex.String() != expectedInput {
3023 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
3024 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07003025}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01003026
3027func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003028 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01003029 prebuilt_apex {
3030 name: "myapex",
3031 src: "myapex-arm.apex",
3032 filename: "notmyapex.apex",
3033 }
3034 `)
3035
3036 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
3037
3038 expected := "notmyapex.apex"
3039 if p.installFilename != expected {
3040 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
3041 }
3042}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07003043
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003044func TestPrebuiltOverrides(t *testing.T) {
3045 ctx, config := testApex(t, `
3046 prebuilt_apex {
3047 name: "myapex.prebuilt",
3048 src: "myapex-arm.apex",
3049 overrides: [
3050 "myapex",
3051 ],
3052 }
3053 `)
3054
3055 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
3056
3057 expected := []string{"myapex"}
Jiyong Park0b0e1b92019-12-03 13:24:29 +09003058 actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003059 if !reflect.DeepEqual(actual, expected) {
Jiyong Parkb0a012c2019-11-14 17:17:03 +09003060 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003061 }
3062}
3063
Roland Levillain630846d2019-06-26 12:48:34 +01003064func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01003065 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01003066 apex_test {
3067 name: "myapex",
3068 key: "myapex.key",
3069 tests: [
3070 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01003071 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01003072 ],
3073 }
3074
3075 apex_key {
3076 name: "myapex.key",
3077 public_key: "testkey.avbpubkey",
3078 private_key: "testkey.pem",
3079 }
3080
3081 cc_test {
3082 name: "mytest",
3083 gtest: false,
3084 srcs: ["mytest.cpp"],
3085 relative_install_path: "test",
3086 system_shared_libs: [],
3087 static_executable: true,
3088 stl: "none",
3089 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01003090
3091 cc_test {
3092 name: "mytests",
3093 gtest: false,
3094 srcs: [
3095 "mytest1.cpp",
3096 "mytest2.cpp",
3097 "mytest3.cpp",
3098 ],
3099 test_per_src: true,
3100 relative_install_path: "test",
3101 system_shared_libs: [],
3102 static_executable: true,
3103 stl: "none",
3104 }
Roland Levillain630846d2019-06-26 12:48:34 +01003105 `)
3106
Sundong Ahnabb64432019-10-22 13:58:29 +09003107 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01003108 copyCmds := apexRule.Args["copy_commands"]
3109
3110 // Ensure that test dep is copied into apex.
3111 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01003112
3113 // Ensure that test deps built with `test_per_src` are copied into apex.
3114 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
3115 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
3116 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01003117
3118 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09003119 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01003120 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3121 name := apexBundle.BaseModuleName()
3122 prefix := "TARGET_"
3123 var builder strings.Builder
3124 data.Custom(&builder, name, prefix, "", data)
3125 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09003126 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
3127 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
3128 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
3129 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
Jooyung Han214bf372019-11-12 13:03:50 +09003130 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
Jooyung Han31c470b2019-10-18 16:26:59 +09003131 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01003132 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01003133}
3134
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003135func TestInstallExtraFlattenedApexes(t *testing.T) {
3136 ctx, config := testApex(t, `
3137 apex {
3138 name: "myapex",
3139 key: "myapex.key",
3140 }
3141 apex_key {
3142 name: "myapex.key",
3143 public_key: "testkey.avbpubkey",
3144 private_key: "testkey.pem",
3145 }
3146 `, func(fs map[string][]byte, config android.Config) {
3147 config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
3148 })
3149 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Jiyong Park83dc74b2020-01-14 18:38:44 +09003150 ensureListContains(t, ab.requiredDeps, "myapex.flattened")
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003151 mk := android.AndroidMkDataForTest(t, config, "", ab)
3152 var builder strings.Builder
3153 mk.Custom(&builder, ab.Name(), "TARGET_", "", mk)
3154 androidMk := builder.String()
3155 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened")
3156}
3157
Jooyung Han5c998b92019-06-27 11:30:33 +09003158func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003159 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09003160 apex {
3161 name: "myapex",
3162 key: "myapex.key",
3163 native_shared_libs: ["mylib"],
3164 uses: ["commonapex"],
3165 }
3166
3167 apex {
3168 name: "commonapex",
3169 key: "myapex.key",
3170 native_shared_libs: ["libcommon"],
3171 provide_cpp_shared_libs: true,
3172 }
3173
3174 apex_key {
3175 name: "myapex.key",
3176 public_key: "testkey.avbpubkey",
3177 private_key: "testkey.pem",
3178 }
3179
3180 cc_library {
3181 name: "mylib",
3182 srcs: ["mylib.cpp"],
3183 shared_libs: ["libcommon"],
3184 system_shared_libs: [],
3185 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003186 apex_available: [ "myapex" ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003187 }
3188
3189 cc_library {
3190 name: "libcommon",
3191 srcs: ["mylib_common.cpp"],
3192 system_shared_libs: [],
3193 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003194 // TODO: remove //apex_available:platform
3195 apex_available: [
3196 "//apex_available:platform",
3197 "commonapex",
3198 "myapex",
3199 ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003200 }
3201 `)
3202
Sundong Ahnabb64432019-10-22 13:58:29 +09003203 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003204 apexRule1 := module1.Rule("apexRule")
3205 copyCmds1 := apexRule1.Args["copy_commands"]
3206
Sundong Ahnabb64432019-10-22 13:58:29 +09003207 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003208 apexRule2 := module2.Rule("apexRule")
3209 copyCmds2 := apexRule2.Args["copy_commands"]
3210
Colin Cross7113d202019-11-20 16:39:12 -08003211 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
3212 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex")
Jooyung Han5c998b92019-06-27 11:30:33 +09003213 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
3214 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
3215 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
3216}
3217
3218func TestApexUsesFailsIfNotProvided(t *testing.T) {
3219 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
3220 apex {
3221 name: "myapex",
3222 key: "myapex.key",
3223 uses: ["commonapex"],
3224 }
3225
3226 apex {
3227 name: "commonapex",
3228 key: "myapex.key",
3229 }
3230
3231 apex_key {
3232 name: "myapex.key",
3233 public_key: "testkey.avbpubkey",
3234 private_key: "testkey.pem",
3235 }
3236 `)
3237 testApexError(t, `uses: "commonapex" is not a provider`, `
3238 apex {
3239 name: "myapex",
3240 key: "myapex.key",
3241 uses: ["commonapex"],
3242 }
3243
3244 cc_library {
3245 name: "commonapex",
3246 system_shared_libs: [],
3247 stl: "none",
3248 }
3249
3250 apex_key {
3251 name: "myapex.key",
3252 public_key: "testkey.avbpubkey",
3253 private_key: "testkey.pem",
3254 }
3255 `)
3256}
3257
3258func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
3259 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
3260 apex {
3261 name: "myapex",
3262 key: "myapex.key",
3263 use_vendor: true,
3264 uses: ["commonapex"],
3265 }
3266
3267 apex {
3268 name: "commonapex",
3269 key: "myapex.key",
3270 provide_cpp_shared_libs: true,
3271 }
3272
3273 apex_key {
3274 name: "myapex.key",
3275 public_key: "testkey.avbpubkey",
3276 private_key: "testkey.pem",
3277 }
Jooyung Handc782442019-11-01 03:14:38 +09003278 `, func(fs map[string][]byte, config android.Config) {
3279 setUseVendorWhitelistForTest(config, []string{"myapex"})
3280 })
Jooyung Han5c998b92019-06-27 11:30:33 +09003281}
3282
Jooyung Hand48f3c32019-08-23 11:18:57 +09003283func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
3284 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
3285 apex {
3286 name: "myapex",
3287 key: "myapex.key",
3288 native_shared_libs: ["libfoo"],
3289 }
3290
3291 apex_key {
3292 name: "myapex.key",
3293 public_key: "testkey.avbpubkey",
3294 private_key: "testkey.pem",
3295 }
3296
3297 cc_library {
3298 name: "libfoo",
3299 stl: "none",
3300 system_shared_libs: [],
3301 enabled: false,
Jooyung Han5e9013b2020-03-10 06:23:13 +09003302 apex_available: ["myapex"],
Jooyung Hand48f3c32019-08-23 11:18:57 +09003303 }
3304 `)
3305 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
3306 apex {
3307 name: "myapex",
3308 key: "myapex.key",
3309 java_libs: ["myjar"],
3310 }
3311
3312 apex_key {
3313 name: "myapex.key",
3314 public_key: "testkey.avbpubkey",
3315 private_key: "testkey.pem",
3316 }
3317
3318 java_library {
3319 name: "myjar",
3320 srcs: ["foo/bar/MyClass.java"],
3321 sdk_version: "none",
3322 system_modules: "none",
Jooyung Hand48f3c32019-08-23 11:18:57 +09003323 enabled: false,
Jooyung Han5e9013b2020-03-10 06:23:13 +09003324 apex_available: ["myapex"],
Jooyung Hand48f3c32019-08-23 11:18:57 +09003325 }
3326 `)
3327}
3328
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003329func TestApexWithApps(t *testing.T) {
3330 ctx, _ := testApex(t, `
3331 apex {
3332 name: "myapex",
3333 key: "myapex.key",
3334 apps: [
3335 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09003336 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003337 ],
3338 }
3339
3340 apex_key {
3341 name: "myapex.key",
3342 public_key: "testkey.avbpubkey",
3343 private_key: "testkey.pem",
3344 }
3345
3346 android_app {
3347 name: "AppFoo",
3348 srcs: ["foo/bar/MyClass.java"],
Colin Cross094cde42020-02-15 10:38:00 -08003349 sdk_version: "current",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003350 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09003351 jni_libs: ["libjni"],
Colin Cross094cde42020-02-15 10:38:00 -08003352 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003353 apex_available: [ "myapex" ],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003354 }
Jiyong Parkf7487312019-10-17 12:54:30 +09003355
3356 android_app {
3357 name: "AppFooPriv",
3358 srcs: ["foo/bar/MyClass.java"],
Colin Cross094cde42020-02-15 10:38:00 -08003359 sdk_version: "current",
Jiyong Parkf7487312019-10-17 12:54:30 +09003360 system_modules: "none",
3361 privileged: true,
Colin Cross094cde42020-02-15 10:38:00 -08003362 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003363 apex_available: [ "myapex" ],
Jiyong Parkf7487312019-10-17 12:54:30 +09003364 }
Jiyong Park8be103b2019-11-08 15:53:48 +09003365
3366 cc_library_shared {
3367 name: "libjni",
3368 srcs: ["mylib.cpp"],
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003369 shared_libs: ["libfoo"],
3370 stl: "none",
3371 system_shared_libs: [],
3372 apex_available: [ "myapex" ],
3373 sdk_version: "current",
3374 }
3375
3376 cc_library_shared {
3377 name: "libfoo",
Jiyong Park8be103b2019-11-08 15:53:48 +09003378 stl: "none",
3379 system_shared_libs: [],
Jiyong Park0f80c182020-01-31 02:49:53 +09003380 apex_available: [ "myapex" ],
Colin Cross094cde42020-02-15 10:38:00 -08003381 sdk_version: "current",
Jiyong Park8be103b2019-11-08 15:53:48 +09003382 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003383 `)
3384
Sundong Ahnabb64432019-10-22 13:58:29 +09003385 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003386 apexRule := module.Rule("apexRule")
3387 copyCmds := apexRule.Args["copy_commands"]
3388
3389 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09003390 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003391
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003392 appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs")
3393 // JNI libraries are uncompressed
Jiyong Park52cd06f2019-11-11 10:14:32 +09003394 if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003395 t.Errorf("jni libs are not uncompressed for AppFoo")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003396 }
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003397 // JNI libraries including transitive deps are
3398 for _, jni := range []string{"libjni", "libfoo"} {
Colin Crossc511bc52020-04-07 16:50:32 +00003399 jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_sdk_shared_myapex").Module().(*cc.Module).OutputFile()
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003400 // ... embedded inside APK (jnilibs.zip)
3401 ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String())
3402 // ... and not directly inside the APEX
3403 ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so")
3404 }
Dario Frenicde2a032019-10-27 00:29:22 +01003405}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003406
Dario Frenicde2a032019-10-27 00:29:22 +01003407func TestApexWithAppImports(t *testing.T) {
3408 ctx, _ := testApex(t, `
3409 apex {
3410 name: "myapex",
3411 key: "myapex.key",
3412 apps: [
3413 "AppFooPrebuilt",
3414 "AppFooPrivPrebuilt",
3415 ],
3416 }
3417
3418 apex_key {
3419 name: "myapex.key",
3420 public_key: "testkey.avbpubkey",
3421 private_key: "testkey.pem",
3422 }
3423
3424 android_app_import {
3425 name: "AppFooPrebuilt",
3426 apk: "PrebuiltAppFoo.apk",
3427 presigned: true,
3428 dex_preopt: {
3429 enabled: false,
3430 },
Jiyong Park592a6a42020-04-21 22:34:28 +09003431 apex_available: ["myapex"],
Dario Frenicde2a032019-10-27 00:29:22 +01003432 }
3433
3434 android_app_import {
3435 name: "AppFooPrivPrebuilt",
3436 apk: "PrebuiltAppFooPriv.apk",
3437 privileged: true,
3438 presigned: true,
3439 dex_preopt: {
3440 enabled: false,
3441 },
Jooyung Han39ee1192020-03-23 20:21:11 +09003442 filename: "AwesomePrebuiltAppFooPriv.apk",
Jiyong Park592a6a42020-04-21 22:34:28 +09003443 apex_available: ["myapex"],
Dario Frenicde2a032019-10-27 00:29:22 +01003444 }
3445 `)
3446
Sundong Ahnabb64432019-10-22 13:58:29 +09003447 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01003448 apexRule := module.Rule("apexRule")
3449 copyCmds := apexRule.Args["copy_commands"]
3450
3451 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
Jooyung Han39ee1192020-03-23 20:21:11 +09003452 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk")
3453}
3454
3455func TestApexWithAppImportsPrefer(t *testing.T) {
3456 ctx, _ := testApex(t, `
3457 apex {
3458 name: "myapex",
3459 key: "myapex.key",
3460 apps: [
3461 "AppFoo",
3462 ],
3463 }
3464
3465 apex_key {
3466 name: "myapex.key",
3467 public_key: "testkey.avbpubkey",
3468 private_key: "testkey.pem",
3469 }
3470
3471 android_app {
3472 name: "AppFoo",
3473 srcs: ["foo/bar/MyClass.java"],
3474 sdk_version: "none",
3475 system_modules: "none",
3476 apex_available: [ "myapex" ],
3477 }
3478
3479 android_app_import {
3480 name: "AppFoo",
3481 apk: "AppFooPrebuilt.apk",
3482 filename: "AppFooPrebuilt.apk",
3483 presigned: true,
3484 prefer: true,
Jiyong Park592a6a42020-04-21 22:34:28 +09003485 apex_available: ["myapex"],
Jooyung Han39ee1192020-03-23 20:21:11 +09003486 }
3487 `, withFiles(map[string][]byte{
3488 "AppFooPrebuilt.apk": nil,
3489 }))
3490
3491 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
3492 "app/AppFoo/AppFooPrebuilt.apk",
3493 })
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003494}
3495
Dario Freni6f3937c2019-12-20 22:58:03 +00003496func TestApexWithTestHelperApp(t *testing.T) {
3497 ctx, _ := testApex(t, `
3498 apex {
3499 name: "myapex",
3500 key: "myapex.key",
3501 apps: [
3502 "TesterHelpAppFoo",
3503 ],
3504 }
3505
3506 apex_key {
3507 name: "myapex.key",
3508 public_key: "testkey.avbpubkey",
3509 private_key: "testkey.pem",
3510 }
3511
3512 android_test_helper_app {
3513 name: "TesterHelpAppFoo",
3514 srcs: ["foo/bar/MyClass.java"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003515 apex_available: [ "myapex" ],
Dario Freni6f3937c2019-12-20 22:58:03 +00003516 }
3517
3518 `)
3519
3520 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3521 apexRule := module.Rule("apexRule")
3522 copyCmds := apexRule.Args["copy_commands"]
3523
3524 ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk")
3525}
3526
Jooyung Han18020ea2019-11-13 10:50:48 +09003527func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
3528 // libfoo's apex_available comes from cc_defaults
Jooyung Han5e9013b2020-03-10 06:23:13 +09003529 testApexError(t, `requires "libfoo" that is not available for the APEX`, `
Jooyung Han18020ea2019-11-13 10:50:48 +09003530 apex {
3531 name: "myapex",
3532 key: "myapex.key",
3533 native_shared_libs: ["libfoo"],
3534 }
3535
3536 apex_key {
3537 name: "myapex.key",
3538 public_key: "testkey.avbpubkey",
3539 private_key: "testkey.pem",
3540 }
3541
3542 apex {
3543 name: "otherapex",
3544 key: "myapex.key",
3545 native_shared_libs: ["libfoo"],
3546 }
3547
3548 cc_defaults {
3549 name: "libfoo-defaults",
3550 apex_available: ["otherapex"],
3551 }
3552
3553 cc_library {
3554 name: "libfoo",
3555 defaults: ["libfoo-defaults"],
3556 stl: "none",
3557 system_shared_libs: [],
3558 }`)
3559}
3560
Paul Duffine52e66f2020-03-30 17:54:29 +01003561func TestApexAvailable_DirectDep(t *testing.T) {
Jiyong Park127b40b2019-09-30 16:04:35 +09003562 // libfoo is not available to myapex, but only to otherapex
3563 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
3564 apex {
3565 name: "myapex",
3566 key: "myapex.key",
3567 native_shared_libs: ["libfoo"],
3568 }
3569
3570 apex_key {
3571 name: "myapex.key",
3572 public_key: "testkey.avbpubkey",
3573 private_key: "testkey.pem",
3574 }
3575
3576 apex {
3577 name: "otherapex",
3578 key: "otherapex.key",
3579 native_shared_libs: ["libfoo"],
3580 }
3581
3582 apex_key {
3583 name: "otherapex.key",
3584 public_key: "testkey.avbpubkey",
3585 private_key: "testkey.pem",
3586 }
3587
3588 cc_library {
3589 name: "libfoo",
3590 stl: "none",
3591 system_shared_libs: [],
3592 apex_available: ["otherapex"],
3593 }`)
Paul Duffine52e66f2020-03-30 17:54:29 +01003594}
Jiyong Park127b40b2019-09-30 16:04:35 +09003595
Paul Duffine52e66f2020-03-30 17:54:29 +01003596func TestApexAvailable_IndirectDep(t *testing.T) {
Jooyung Han5e9013b2020-03-10 06:23:13 +09003597 // libbbaz is an indirect dep
Paul Duffindf915ff2020-03-30 17:58:21 +01003598 testApexError(t, `requires "libbaz" that is not available for the APEX. Dependency path:
Paul Duffinc5192442020-03-31 11:31:36 +01003599.*via tag apex\.dependencyTag.*"sharedLib".*
Paul Duffindf915ff2020-03-30 17:58:21 +01003600.*-> libfoo.*link:shared.*
Paul Duffin65347702020-03-31 15:23:40 +01003601.*via tag cc\.DependencyTag.*"shared".*
Paul Duffindf915ff2020-03-30 17:58:21 +01003602.*-> libbar.*link:shared.*
Paul Duffin65347702020-03-31 15:23:40 +01003603.*via tag cc\.DependencyTag.*"shared".*
3604.*-> libbaz.*link:shared.*`, `
Jiyong Park127b40b2019-09-30 16:04:35 +09003605 apex {
3606 name: "myapex",
3607 key: "myapex.key",
3608 native_shared_libs: ["libfoo"],
3609 }
3610
3611 apex_key {
3612 name: "myapex.key",
3613 public_key: "testkey.avbpubkey",
3614 private_key: "testkey.pem",
3615 }
3616
Jiyong Park127b40b2019-09-30 16:04:35 +09003617 cc_library {
3618 name: "libfoo",
3619 stl: "none",
3620 shared_libs: ["libbar"],
3621 system_shared_libs: [],
Jooyung Han5e9013b2020-03-10 06:23:13 +09003622 apex_available: ["myapex"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003623 }
3624
3625 cc_library {
3626 name: "libbar",
3627 stl: "none",
Jooyung Han5e9013b2020-03-10 06:23:13 +09003628 shared_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003629 system_shared_libs: [],
Jooyung Han5e9013b2020-03-10 06:23:13 +09003630 apex_available: ["myapex"],
3631 }
3632
3633 cc_library {
3634 name: "libbaz",
3635 stl: "none",
3636 system_shared_libs: [],
Jiyong Park127b40b2019-09-30 16:04:35 +09003637 }`)
Paul Duffine52e66f2020-03-30 17:54:29 +01003638}
Jiyong Park127b40b2019-09-30 16:04:35 +09003639
Paul Duffine52e66f2020-03-30 17:54:29 +01003640func TestApexAvailable_InvalidApexName(t *testing.T) {
Jiyong Park127b40b2019-09-30 16:04:35 +09003641 testApexError(t, "\"otherapex\" is not a valid module name", `
3642 apex {
3643 name: "myapex",
3644 key: "myapex.key",
3645 native_shared_libs: ["libfoo"],
3646 }
3647
3648 apex_key {
3649 name: "myapex.key",
3650 public_key: "testkey.avbpubkey",
3651 private_key: "testkey.pem",
3652 }
3653
3654 cc_library {
3655 name: "libfoo",
3656 stl: "none",
3657 system_shared_libs: [],
3658 apex_available: ["otherapex"],
3659 }`)
3660
Paul Duffine52e66f2020-03-30 17:54:29 +01003661 testApex(t, `
Jiyong Park127b40b2019-09-30 16:04:35 +09003662 apex {
3663 name: "myapex",
3664 key: "myapex.key",
3665 native_shared_libs: ["libfoo", "libbar"],
3666 }
3667
3668 apex_key {
3669 name: "myapex.key",
3670 public_key: "testkey.avbpubkey",
3671 private_key: "testkey.pem",
3672 }
3673
3674 cc_library {
3675 name: "libfoo",
3676 stl: "none",
3677 system_shared_libs: [],
Jiyong Park323a4c32020-03-01 17:29:06 +09003678 runtime_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003679 apex_available: ["myapex"],
3680 }
3681
3682 cc_library {
3683 name: "libbar",
3684 stl: "none",
3685 system_shared_libs: [],
3686 apex_available: ["//apex_available:anyapex"],
Jiyong Park323a4c32020-03-01 17:29:06 +09003687 }
3688
3689 cc_library {
3690 name: "libbaz",
3691 stl: "none",
3692 system_shared_libs: [],
3693 stubs: {
3694 versions: ["10", "20", "30"],
3695 },
Jiyong Park127b40b2019-09-30 16:04:35 +09003696 }`)
Paul Duffine52e66f2020-03-30 17:54:29 +01003697}
Jiyong Park127b40b2019-09-30 16:04:35 +09003698
Jiyong Park89e850a2020-04-07 16:37:39 +09003699func TestApexAvailable_CheckForPlatform(t *testing.T) {
Paul Duffine52e66f2020-03-30 17:54:29 +01003700 ctx, _ := testApex(t, `
Jiyong Park127b40b2019-09-30 16:04:35 +09003701 apex {
3702 name: "myapex",
3703 key: "myapex.key",
Jiyong Park89e850a2020-04-07 16:37:39 +09003704 native_shared_libs: ["libbar", "libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003705 }
3706
3707 apex_key {
3708 name: "myapex.key",
3709 public_key: "testkey.avbpubkey",
3710 private_key: "testkey.pem",
3711 }
3712
3713 cc_library {
3714 name: "libfoo",
3715 stl: "none",
3716 system_shared_libs: [],
Jiyong Park89e850a2020-04-07 16:37:39 +09003717 shared_libs: ["libbar"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003718 apex_available: ["//apex_available:platform"],
Jiyong Park89e850a2020-04-07 16:37:39 +09003719 }
3720
3721 cc_library {
3722 name: "libfoo2",
3723 stl: "none",
3724 system_shared_libs: [],
3725 shared_libs: ["libbaz"],
3726 apex_available: ["//apex_available:platform"],
3727 }
3728
3729 cc_library {
3730 name: "libbar",
3731 stl: "none",
3732 system_shared_libs: [],
3733 apex_available: ["myapex"],
3734 }
3735
3736 cc_library {
3737 name: "libbaz",
3738 stl: "none",
3739 system_shared_libs: [],
3740 apex_available: ["myapex"],
3741 stubs: {
3742 versions: ["1"],
3743 },
Jiyong Park127b40b2019-09-30 16:04:35 +09003744 }`)
3745
Jiyong Park89e850a2020-04-07 16:37:39 +09003746 // libfoo shouldn't be available to platform even though it has "//apex_available:platform",
3747 // because it depends on libbar which isn't available to platform
3748 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module)
3749 if libfoo.NotAvailableForPlatform() != true {
3750 t.Errorf("%q shouldn't be available to platform", libfoo.String())
3751 }
3752
3753 // libfoo2 however can be available to platform because it depends on libbaz which provides
3754 // stubs
3755 libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module)
3756 if libfoo2.NotAvailableForPlatform() == true {
3757 t.Errorf("%q should be available to platform", libfoo2.String())
3758 }
Paul Duffine52e66f2020-03-30 17:54:29 +01003759}
Jiyong Parka90ca002019-10-07 15:47:24 +09003760
Paul Duffine52e66f2020-03-30 17:54:29 +01003761func TestApexAvailable_CreatedForApex(t *testing.T) {
Jiyong Park89e850a2020-04-07 16:37:39 +09003762 ctx, _ := testApex(t, `
Jiyong Parka90ca002019-10-07 15:47:24 +09003763 apex {
3764 name: "myapex",
3765 key: "myapex.key",
3766 native_shared_libs: ["libfoo"],
3767 }
3768
3769 apex_key {
3770 name: "myapex.key",
3771 public_key: "testkey.avbpubkey",
3772 private_key: "testkey.pem",
3773 }
3774
3775 cc_library {
3776 name: "libfoo",
3777 stl: "none",
3778 system_shared_libs: [],
3779 apex_available: ["myapex"],
3780 static: {
3781 apex_available: ["//apex_available:platform"],
3782 },
3783 }`)
3784
Jiyong Park89e850a2020-04-07 16:37:39 +09003785 libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module)
3786 if libfooShared.NotAvailableForPlatform() != true {
3787 t.Errorf("%q shouldn't be available to platform", libfooShared.String())
3788 }
3789 libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module)
3790 if libfooStatic.NotAvailableForPlatform() != false {
3791 t.Errorf("%q should be available to platform", libfooStatic.String())
3792 }
Jiyong Park127b40b2019-09-30 16:04:35 +09003793}
3794
Jiyong Park5d790c32019-11-15 18:40:32 +09003795func TestOverrideApex(t *testing.T) {
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003796 ctx, config := testApex(t, `
Jiyong Park5d790c32019-11-15 18:40:32 +09003797 apex {
3798 name: "myapex",
3799 key: "myapex.key",
3800 apps: ["app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003801 overrides: ["oldapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003802 }
3803
3804 override_apex {
3805 name: "override_myapex",
3806 base: "myapex",
3807 apps: ["override_app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003808 overrides: ["unknownapex"],
Baligh Uddin004d7172020-02-19 21:29:28 -08003809 logging_parent: "com.foo.bar",
Baligh Uddin5b57dba2020-03-15 13:01:05 -07003810 package_name: "test.overridden.package",
Jiyong Park5d790c32019-11-15 18:40:32 +09003811 }
3812
3813 apex_key {
3814 name: "myapex.key",
3815 public_key: "testkey.avbpubkey",
3816 private_key: "testkey.pem",
3817 }
3818
3819 android_app {
3820 name: "app",
3821 srcs: ["foo/bar/MyClass.java"],
3822 package_name: "foo",
3823 sdk_version: "none",
3824 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003825 apex_available: [ "myapex" ],
Jiyong Park5d790c32019-11-15 18:40:32 +09003826 }
3827
3828 override_android_app {
3829 name: "override_app",
3830 base: "app",
3831 package_name: "bar",
3832 }
Jiyong Park20bacab2020-03-03 11:45:41 +09003833 `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"}))
Jiyong Park5d790c32019-11-15 18:40:32 +09003834
Jiyong Park317645e2019-12-05 13:20:58 +09003835 originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule)
3836 overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule)
3837 if originalVariant.GetOverriddenBy() != "" {
3838 t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
3839 }
3840 if overriddenVariant.GetOverriddenBy() != "override_myapex" {
3841 t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
3842 }
3843
Jiyong Park5d790c32019-11-15 18:40:32 +09003844 module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image")
3845 apexRule := module.Rule("apexRule")
3846 copyCmds := apexRule.Args["copy_commands"]
3847
3848 ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk")
Jooyung Han39ee1192020-03-23 20:21:11 +09003849 ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003850
3851 apexBundle := module.Module().(*apexBundle)
3852 name := apexBundle.Name()
3853 if name != "override_myapex" {
3854 t.Errorf("name should be \"override_myapex\", but was %q", name)
3855 }
3856
Baligh Uddin004d7172020-02-19 21:29:28 -08003857 if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" {
3858 t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent)
3859 }
3860
Jiyong Park20bacab2020-03-03 11:45:41 +09003861 optFlags := apexRule.Args["opt_flags"]
Baligh Uddin5b57dba2020-03-15 13:01:05 -07003862 ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package")
Jiyong Park20bacab2020-03-03 11:45:41 +09003863
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003864 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3865 var builder strings.Builder
3866 data.Custom(&builder, name, "TARGET_", "", data)
3867 androidMk := builder.String()
Jiyong Parkf653b052019-11-18 15:39:01 +09003868 ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003869 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
3870 ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003871 ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003872 ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
Jiyong Parkf653b052019-11-18 15:39:01 +09003873 ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003874 ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
3875 ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
Jiyong Park5d790c32019-11-15 18:40:32 +09003876}
3877
Jooyung Han214bf372019-11-12 13:03:50 +09003878func TestLegacyAndroid10Support(t *testing.T) {
3879 ctx, _ := testApex(t, `
3880 apex {
3881 name: "myapex",
3882 key: "myapex.key",
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003883 native_shared_libs: ["mylib"],
Jooyung Han5417f772020-03-12 18:37:20 +09003884 min_sdk_version: "29",
Jooyung Han214bf372019-11-12 13:03:50 +09003885 }
3886
3887 apex_key {
3888 name: "myapex.key",
3889 public_key: "testkey.avbpubkey",
3890 private_key: "testkey.pem",
3891 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003892
3893 cc_library {
3894 name: "mylib",
3895 srcs: ["mylib.cpp"],
3896 stl: "libc++",
3897 system_shared_libs: [],
3898 apex_available: [ "myapex" ],
3899 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003900 `, withUnbundledBuild)
Jooyung Han214bf372019-11-12 13:03:50 +09003901
3902 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3903 args := module.Rule("apexRule").Args
3904 ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String())
Dario Frenie3546902020-01-14 23:50:25 +00003905 ensureNotContains(t, args["opt_flags"], "--no_hashtree")
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003906
3907 // The copies of the libraries in the apex should have one more dependency than
3908 // the ones outside the apex, namely the unwinder. Ideally we should check
3909 // the dependency names directly here but for some reason the names are blank in
3910 // this test.
3911 for _, lib := range []string{"libc++", "mylib"} {
3912 apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits
3913 nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits
3914 if len(apexImplicits) != len(nonApexImplicits)+1 {
3915 t.Errorf("%q missing unwinder dep", lib)
3916 }
3917 }
Jooyung Han214bf372019-11-12 13:03:50 +09003918}
3919
Jooyung Han58f26ab2019-12-18 15:34:32 +09003920func TestJavaSDKLibrary(t *testing.T) {
3921 ctx, _ := testApex(t, `
3922 apex {
3923 name: "myapex",
3924 key: "myapex.key",
3925 java_libs: ["foo"],
3926 }
3927
3928 apex_key {
3929 name: "myapex.key",
3930 public_key: "testkey.avbpubkey",
3931 private_key: "testkey.pem",
3932 }
3933
3934 java_sdk_library {
3935 name: "foo",
3936 srcs: ["a.java"],
3937 api_packages: ["foo"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003938 apex_available: [ "myapex" ],
Jooyung Han58f26ab2019-12-18 15:34:32 +09003939 }
3940 `, withFiles(map[string][]byte{
3941 "api/current.txt": nil,
3942 "api/removed.txt": nil,
3943 "api/system-current.txt": nil,
3944 "api/system-removed.txt": nil,
3945 "api/test-current.txt": nil,
3946 "api/test-removed.txt": nil,
3947 }))
3948
3949 // java_sdk_library installs both impl jar and permission XML
Jooyung Hana57af4a2020-01-23 05:36:59 +00003950 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han58f26ab2019-12-18 15:34:32 +09003951 "javalib/foo.jar",
3952 "etc/permissions/foo.xml",
3953 })
3954 // Permission XML should point to the activated path of impl jar of java_sdk_library
Jiyong Parke3833882020-02-17 17:28:10 +09003955 sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml")
3956 ensureContains(t, sdkLibrary.RuleParams.Command, `<library name=\"foo\" file=\"/apex/myapex/javalib/foo.jar\"`)
Jooyung Han58f26ab2019-12-18 15:34:32 +09003957}
3958
atrost6e126252020-01-27 17:01:16 +00003959func TestCompatConfig(t *testing.T) {
3960 ctx, _ := testApex(t, `
3961 apex {
3962 name: "myapex",
3963 key: "myapex.key",
3964 prebuilts: ["myjar-platform-compat-config"],
3965 java_libs: ["myjar"],
3966 }
3967
3968 apex_key {
3969 name: "myapex.key",
3970 public_key: "testkey.avbpubkey",
3971 private_key: "testkey.pem",
3972 }
3973
3974 platform_compat_config {
3975 name: "myjar-platform-compat-config",
3976 src: ":myjar",
3977 }
3978
3979 java_library {
3980 name: "myjar",
3981 srcs: ["foo/bar/MyClass.java"],
3982 sdk_version: "none",
3983 system_modules: "none",
atrost6e126252020-01-27 17:01:16 +00003984 apex_available: [ "myapex" ],
3985 }
3986 `)
3987 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
3988 "etc/compatconfig/myjar-platform-compat-config.xml",
3989 "javalib/myjar.jar",
3990 })
3991}
3992
Jiyong Park479321d2019-12-16 11:47:12 +09003993func TestRejectNonInstallableJavaLibrary(t *testing.T) {
3994 testApexError(t, `"myjar" is not configured to be compiled into dex`, `
3995 apex {
3996 name: "myapex",
3997 key: "myapex.key",
3998 java_libs: ["myjar"],
3999 }
4000
4001 apex_key {
4002 name: "myapex.key",
4003 public_key: "testkey.avbpubkey",
4004 private_key: "testkey.pem",
4005 }
4006
4007 java_library {
4008 name: "myjar",
4009 srcs: ["foo/bar/MyClass.java"],
4010 sdk_version: "none",
4011 system_modules: "none",
Jiyong Park6b21c7d2020-02-11 09:16:01 +09004012 compile_dex: false,
Jooyung Han5e9013b2020-03-10 06:23:13 +09004013 apex_available: ["myapex"],
Jiyong Park479321d2019-12-16 11:47:12 +09004014 }
4015 `)
4016}
4017
Jiyong Park7afd1072019-12-30 16:56:33 +09004018func TestCarryRequiredModuleNames(t *testing.T) {
4019 ctx, config := testApex(t, `
4020 apex {
4021 name: "myapex",
4022 key: "myapex.key",
4023 native_shared_libs: ["mylib"],
4024 }
4025
4026 apex_key {
4027 name: "myapex.key",
4028 public_key: "testkey.avbpubkey",
4029 private_key: "testkey.pem",
4030 }
4031
4032 cc_library {
4033 name: "mylib",
4034 srcs: ["mylib.cpp"],
4035 system_shared_libs: [],
4036 stl: "none",
4037 required: ["a", "b"],
4038 host_required: ["c", "d"],
4039 target_required: ["e", "f"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00004040 apex_available: [ "myapex" ],
Jiyong Park7afd1072019-12-30 16:56:33 +09004041 }
4042 `)
4043
4044 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
4045 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
4046 name := apexBundle.BaseModuleName()
4047 prefix := "TARGET_"
4048 var builder strings.Builder
4049 data.Custom(&builder, name, prefix, "", data)
4050 androidMk := builder.String()
4051 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n")
4052 ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n")
4053 ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n")
4054}
4055
Jiyong Park7cd10e32020-01-14 09:22:18 +09004056func TestSymlinksFromApexToSystem(t *testing.T) {
4057 bp := `
4058 apex {
4059 name: "myapex",
4060 key: "myapex.key",
4061 native_shared_libs: ["mylib"],
4062 java_libs: ["myjar"],
4063 }
4064
Jiyong Park9d677202020-02-19 16:29:35 +09004065 apex {
4066 name: "myapex.updatable",
4067 key: "myapex.key",
4068 native_shared_libs: ["mylib"],
4069 java_libs: ["myjar"],
4070 updatable: true,
4071 }
4072
Jiyong Park7cd10e32020-01-14 09:22:18 +09004073 apex_key {
4074 name: "myapex.key",
4075 public_key: "testkey.avbpubkey",
4076 private_key: "testkey.pem",
4077 }
4078
4079 cc_library {
4080 name: "mylib",
4081 srcs: ["mylib.cpp"],
4082 shared_libs: ["myotherlib"],
4083 system_shared_libs: [],
4084 stl: "none",
4085 apex_available: [
4086 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09004087 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09004088 "//apex_available:platform",
4089 ],
4090 }
4091
4092 cc_library {
4093 name: "myotherlib",
4094 srcs: ["mylib.cpp"],
4095 system_shared_libs: [],
4096 stl: "none",
4097 apex_available: [
4098 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09004099 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09004100 "//apex_available:platform",
4101 ],
4102 }
4103
4104 java_library {
4105 name: "myjar",
4106 srcs: ["foo/bar/MyClass.java"],
4107 sdk_version: "none",
4108 system_modules: "none",
4109 libs: ["myotherjar"],
Jiyong Park7cd10e32020-01-14 09:22:18 +09004110 apex_available: [
4111 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09004112 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09004113 "//apex_available:platform",
4114 ],
4115 }
4116
4117 java_library {
4118 name: "myotherjar",
4119 srcs: ["foo/bar/MyClass.java"],
4120 sdk_version: "none",
4121 system_modules: "none",
4122 apex_available: [
4123 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09004124 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09004125 "//apex_available:platform",
4126 ],
4127 }
4128 `
4129
4130 ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) {
4131 for _, f := range files {
4132 if f.path == file {
4133 if f.isLink {
4134 t.Errorf("%q is not a real file", file)
4135 }
4136 return
4137 }
4138 }
4139 t.Errorf("%q is not found", file)
4140 }
4141
4142 ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) {
4143 for _, f := range files {
4144 if f.path == file {
4145 if !f.isLink {
4146 t.Errorf("%q is not a symlink", file)
4147 }
4148 return
4149 }
4150 }
4151 t.Errorf("%q is not found", file)
4152 }
4153
Jiyong Park9d677202020-02-19 16:29:35 +09004154 // For unbundled build, symlink shouldn't exist regardless of whether an APEX
4155 // is updatable or not
Jiyong Park7cd10e32020-01-14 09:22:18 +09004156 ctx, _ := testApex(t, bp, withUnbundledBuild)
Jooyung Hana57af4a2020-01-23 05:36:59 +00004157 files := getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09004158 ensureRealfileExists(t, files, "javalib/myjar.jar")
4159 ensureRealfileExists(t, files, "lib64/mylib.so")
4160 ensureRealfileExists(t, files, "lib64/myotherlib.so")
4161
Jiyong Park9d677202020-02-19 16:29:35 +09004162 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
4163 ensureRealfileExists(t, files, "javalib/myjar.jar")
4164 ensureRealfileExists(t, files, "lib64/mylib.so")
4165 ensureRealfileExists(t, files, "lib64/myotherlib.so")
4166
4167 // For bundled build, symlink to the system for the non-updatable APEXes only
Jiyong Park7cd10e32020-01-14 09:22:18 +09004168 ctx, _ = testApex(t, bp)
Jooyung Hana57af4a2020-01-23 05:36:59 +00004169 files = getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09004170 ensureRealfileExists(t, files, "javalib/myjar.jar")
4171 ensureRealfileExists(t, files, "lib64/mylib.so")
4172 ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
Jiyong Park9d677202020-02-19 16:29:35 +09004173
4174 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
4175 ensureRealfileExists(t, files, "javalib/myjar.jar")
4176 ensureRealfileExists(t, files, "lib64/mylib.so")
4177 ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
Jiyong Park7cd10e32020-01-14 09:22:18 +09004178}
4179
Jooyung Han643adc42020-02-27 13:50:06 +09004180func TestApexWithJniLibs(t *testing.T) {
4181 ctx, _ := testApex(t, `
4182 apex {
4183 name: "myapex",
4184 key: "myapex.key",
4185 jni_libs: ["mylib"],
4186 }
4187
4188 apex_key {
4189 name: "myapex.key",
4190 public_key: "testkey.avbpubkey",
4191 private_key: "testkey.pem",
4192 }
4193
4194 cc_library {
4195 name: "mylib",
4196 srcs: ["mylib.cpp"],
4197 shared_libs: ["mylib2"],
4198 system_shared_libs: [],
4199 stl: "none",
4200 apex_available: [ "myapex" ],
4201 }
4202
4203 cc_library {
4204 name: "mylib2",
4205 srcs: ["mylib.cpp"],
4206 system_shared_libs: [],
4207 stl: "none",
4208 apex_available: [ "myapex" ],
4209 }
4210 `)
4211
4212 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
4213 // Notice mylib2.so (transitive dep) is not added as a jni_lib
4214 ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so")
4215 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
4216 "lib64/mylib.so",
4217 "lib64/mylib2.so",
4218 })
4219}
4220
Jooyung Han49f67012020-04-17 13:43:10 +09004221func TestApexMutatorsDontRunIfDisabled(t *testing.T) {
4222 ctx, _ := testApex(t, `
4223 apex {
4224 name: "myapex",
4225 key: "myapex.key",
4226 }
4227 apex_key {
4228 name: "myapex.key",
4229 public_key: "testkey.avbpubkey",
4230 private_key: "testkey.pem",
4231 }
4232 `, func(fs map[string][]byte, config android.Config) {
4233 delete(config.Targets, android.Android)
4234 config.AndroidCommonTarget = android.Target{}
4235 })
4236
4237 if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) {
4238 t.Errorf("Expected variants: %v, but got: %v", expected, got)
4239 }
4240}
4241
Jooyung Han643adc42020-02-27 13:50:06 +09004242func TestApexWithJniLibs_Errors(t *testing.T) {
4243 testApexError(t, `jni_libs: "xxx" is not a cc_library`, `
4244 apex {
4245 name: "myapex",
4246 key: "myapex.key",
4247 jni_libs: ["xxx"],
4248 }
4249
4250 apex_key {
4251 name: "myapex.key",
4252 public_key: "testkey.avbpubkey",
4253 private_key: "testkey.pem",
4254 }
4255
4256 prebuilt_etc {
4257 name: "xxx",
4258 src: "xxx",
4259 }
4260 `, withFiles(map[string][]byte{
4261 "xxx": nil,
4262 }))
4263}
4264
Jiyong Parkbd159612020-02-28 15:22:21 +09004265func TestAppBundle(t *testing.T) {
4266 ctx, _ := testApex(t, `
4267 apex {
4268 name: "myapex",
4269 key: "myapex.key",
4270 apps: ["AppFoo"],
4271 }
4272
4273 apex_key {
4274 name: "myapex.key",
4275 public_key: "testkey.avbpubkey",
4276 private_key: "testkey.pem",
4277 }
4278
4279 android_app {
4280 name: "AppFoo",
4281 srcs: ["foo/bar/MyClass.java"],
4282 sdk_version: "none",
4283 system_modules: "none",
4284 apex_available: [ "myapex" ],
4285 }
Jiyong Parkcfaa1642020-02-28 16:51:07 +09004286 `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"}))
Jiyong Parkbd159612020-02-28 15:22:21 +09004287
4288 bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config")
4289 content := bundleConfigRule.Args["content"]
4290
4291 ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
Jiyong Parkcfaa1642020-02-28 16:51:07 +09004292 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 +09004293}
4294
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00004295func testNoUpdatableJarsInBootImage(t *testing.T, errmsg, bp string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) {
4296 t.Helper()
4297
4298 bp = bp + `
4299 filegroup {
4300 name: "some-updatable-apex-file_contexts",
4301 srcs: [
4302 "system/sepolicy/apex/some-updatable-apex-file_contexts",
4303 ],
4304 }
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01004305
4306 filegroup {
4307 name: "some-non-updatable-apex-file_contexts",
4308 srcs: [
4309 "system/sepolicy/apex/some-non-updatable-apex-file_contexts",
4310 ],
4311 }
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00004312 `
4313 bp += cc.GatherRequiredDepsForTest(android.Android)
4314 bp += java.GatherRequiredDepsForTest()
4315 bp += dexpreopt.BpToolModulesForTest()
4316
4317 fs := map[string][]byte{
4318 "a.java": nil,
4319 "a.jar": nil,
4320 "build/make/target/product/security": nil,
4321 "apex_manifest.json": nil,
4322 "AndroidManifest.xml": nil,
4323 "system/sepolicy/apex/some-updatable-apex-file_contexts": nil,
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01004324 "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil,
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00004325 "system/sepolicy/apex/com.android.art.something-file_contexts": nil,
4326 "framework/aidl/a.aidl": nil,
4327 }
4328 cc.GatherRequiredFilesForTest(fs)
4329
4330 ctx := android.NewTestArchContext()
4331 ctx.RegisterModuleType("apex", BundleFactory)
4332 ctx.RegisterModuleType("apex_key", ApexKeyFactory)
4333 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
4334 cc.RegisterRequiredBuildComponentsForTest(ctx)
4335 java.RegisterJavaBuildComponents(ctx)
4336 java.RegisterSystemModulesBuildComponents(ctx)
4337 java.RegisterAppBuildComponents(ctx)
4338 java.RegisterDexpreoptBootJarsComponents(ctx)
4339 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
4340 ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
4341 ctx.PreDepsMutators(RegisterPreDepsMutators)
4342 ctx.PostDepsMutators(RegisterPostDepsMutators)
4343
4344 config := android.TestArchConfig(buildDir, nil, bp, fs)
4345 ctx.Register(config)
4346
4347 _ = dexpreopt.GlobalSoongConfigForTests(config)
4348 dexpreopt.RegisterToolModulesForTest(ctx)
4349 pathCtx := android.PathContextForTesting(config)
4350 dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
4351 transformDexpreoptConfig(dexpreoptConfig)
4352 dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
4353
4354 _, errs := ctx.ParseBlueprintsFiles("Android.bp")
4355 android.FailIfErrored(t, errs)
4356
4357 _, errs = ctx.PrepareBuildActions(config)
4358 if errmsg == "" {
4359 android.FailIfErrored(t, errs)
4360 } else if len(errs) > 0 {
4361 android.FailIfNoMatchingErrors(t, errmsg, errs)
4362 return
4363 } else {
4364 t.Fatalf("missing expected error %q (0 errors are returned)", errmsg)
4365 }
4366}
4367
4368func TestNoUpdatableJarsInBootImage(t *testing.T) {
4369 bp := `
4370 java_library {
4371 name: "some-updatable-apex-lib",
4372 srcs: ["a.java"],
4373 apex_available: [
4374 "some-updatable-apex",
4375 ],
4376 }
4377
4378 java_library {
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01004379 name: "some-non-updatable-apex-lib",
4380 srcs: ["a.java"],
4381 apex_available: [
4382 "some-non-updatable-apex",
4383 ],
4384 }
4385
4386 java_library {
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00004387 name: "some-platform-lib",
4388 srcs: ["a.java"],
4389 installable: true,
4390 }
4391
4392 java_library {
4393 name: "some-art-lib",
4394 srcs: ["a.java"],
4395 apex_available: [
4396 "com.android.art.something",
4397 ],
4398 hostdex: true,
4399 }
4400
4401 apex {
4402 name: "some-updatable-apex",
4403 key: "some-updatable-apex.key",
4404 java_libs: ["some-updatable-apex-lib"],
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01004405 updatable: true,
4406 }
4407
4408 apex {
4409 name: "some-non-updatable-apex",
4410 key: "some-non-updatable-apex.key",
4411 java_libs: ["some-non-updatable-apex-lib"],
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00004412 }
4413
4414 apex_key {
4415 name: "some-updatable-apex.key",
4416 }
4417
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01004418 apex_key {
4419 name: "some-non-updatable-apex.key",
4420 }
4421
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00004422 apex {
4423 name: "com.android.art.something",
4424 key: "com.android.art.something.key",
4425 java_libs: ["some-art-lib"],
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01004426 updatable: true,
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00004427 }
4428
4429 apex_key {
4430 name: "com.android.art.something.key",
4431 }
4432 `
4433
4434 var error string
4435 var transform func(*dexpreopt.GlobalConfig)
4436
4437 // updatable jar from ART apex in the ART boot image => ok
4438 transform = func(config *dexpreopt.GlobalConfig) {
4439 config.ArtApexJars = []string{"some-art-lib"}
4440 }
4441 testNoUpdatableJarsInBootImage(t, "", bp, transform)
4442
4443 // updatable jar from ART apex in the framework boot image => error
4444 error = "module 'some-art-lib' from updatable apex 'com.android.art.something' is not allowed in the framework boot image"
4445 transform = func(config *dexpreopt.GlobalConfig) {
4446 config.BootJars = []string{"some-art-lib"}
4447 }
4448 testNoUpdatableJarsInBootImage(t, error, bp, transform)
4449
4450 // updatable jar from some other apex in the ART boot image => error
4451 error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the ART boot image"
4452 transform = func(config *dexpreopt.GlobalConfig) {
4453 config.ArtApexJars = []string{"some-updatable-apex-lib"}
4454 }
4455 testNoUpdatableJarsInBootImage(t, error, bp, transform)
4456
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01004457 // non-updatable jar from some other apex in the ART boot image => error
4458 error = "module 'some-non-updatable-apex-lib' is not allowed in the ART boot image"
4459 transform = func(config *dexpreopt.GlobalConfig) {
4460 config.ArtApexJars = []string{"some-non-updatable-apex-lib"}
4461 }
4462 testNoUpdatableJarsInBootImage(t, error, bp, transform)
4463
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00004464 // updatable jar from some other apex in the framework boot image => error
4465 error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the framework boot image"
4466 transform = func(config *dexpreopt.GlobalConfig) {
4467 config.BootJars = []string{"some-updatable-apex-lib"}
4468 }
4469 testNoUpdatableJarsInBootImage(t, error, bp, transform)
4470
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01004471 // non-updatable jar from some other apex in the framework boot image => ok
4472 transform = func(config *dexpreopt.GlobalConfig) {
4473 config.BootJars = []string{"some-non-updatable-apex-lib"}
4474 }
4475 testNoUpdatableJarsInBootImage(t, "", bp, transform)
4476
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00004477 // nonexistent jar in the ART boot image => error
4478 error = "failed to find a dex jar path for module 'nonexistent'"
4479 transform = func(config *dexpreopt.GlobalConfig) {
4480 config.ArtApexJars = []string{"nonexistent"}
4481 }
4482 testNoUpdatableJarsInBootImage(t, error, bp, transform)
4483
4484 // nonexistent jar in the framework boot image => error
4485 error = "failed to find a dex jar path for module 'nonexistent'"
4486 transform = func(config *dexpreopt.GlobalConfig) {
4487 config.BootJars = []string{"nonexistent"}
4488 }
4489 testNoUpdatableJarsInBootImage(t, error, bp, transform)
4490
4491 // platform jar in the ART boot image => error
Ulya Trafimovich7c140d82020-04-22 18:05:58 +01004492 error = "module 'some-platform-lib' is not allowed in the ART boot image"
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00004493 transform = func(config *dexpreopt.GlobalConfig) {
4494 config.ArtApexJars = []string{"some-platform-lib"}
4495 }
4496 testNoUpdatableJarsInBootImage(t, error, bp, transform)
4497
4498 // platform jar in the framework boot image => ok
4499 transform = func(config *dexpreopt.GlobalConfig) {
4500 config.BootJars = []string{"some-platform-lib"}
4501 }
4502 testNoUpdatableJarsInBootImage(t, "", bp, transform)
4503}
4504
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07004505func TestMain(m *testing.M) {
4506 run := func() int {
4507 setUp()
4508 defer tearDown()
4509
4510 return m.Run()
4511 }
4512
4513 os.Exit(run())
4514}