blob: cde80c13136832a8568bcaeea3855de3df3edb79 [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"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090030 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090031)
32
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070033var buildDir string
34
Jooyung Hand3639552019-08-09 12:57:43 +090035// names returns name list from white space separated string
36func names(s string) (ns []string) {
37 for _, n := range strings.Split(s, " ") {
38 if len(n) > 0 {
39 ns = append(ns, n)
40 }
41 }
42 return
43}
44
Jooyung Han344d5432019-08-23 11:17:39 +090045func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) {
46 t.Helper()
47 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090048 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
49 if len(errs) > 0 {
50 android.FailIfNoMatchingErrors(t, pattern, errs)
51 return
52 }
53 _, errs = ctx.PrepareBuildActions(config)
54 if len(errs) > 0 {
55 android.FailIfNoMatchingErrors(t, pattern, errs)
56 return
57 }
58
59 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
60}
61
Jooyung Han344d5432019-08-23 11:17:39 +090062func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
63 t.Helper()
64 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090065 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
66 android.FailIfErrored(t, errs)
67 _, errs = ctx.PrepareBuildActions(config)
68 android.FailIfErrored(t, errs)
Jaewoong Jung22f7d182019-07-16 18:25:41 -070069 return ctx, config
Jooyung Han5c998b92019-06-27 11:30:33 +090070}
71
Jooyung Han344d5432019-08-23 11:17:39 +090072type testCustomizer func(fs map[string][]byte, config android.Config)
73
74func withFiles(files map[string][]byte) testCustomizer {
75 return func(fs map[string][]byte, config android.Config) {
76 for k, v := range files {
77 fs[k] = v
78 }
79 }
80}
81
82func withTargets(targets map[android.OsType][]android.Target) testCustomizer {
83 return func(fs map[string][]byte, config android.Config) {
84 for k, v := range targets {
85 config.Targets[k] = v
86 }
87 }
88}
89
Jiyong Parkaf8998c2020-02-28 16:51:07 +090090func withManifestPackageNameOverrides(specs []string) testCustomizer {
91 return func(fs map[string][]byte, config android.Config) {
92 config.TestProductVariables.ManifestPackageNameOverrides = specs
93 }
94}
95
Jooyung Han31c470b2019-10-18 16:26:59 +090096func withBinder32bit(fs map[string][]byte, config android.Config) {
97 config.TestProductVariables.Binder32bit = proptools.BoolPtr(true)
98}
99
Jiyong Park7cd10e32020-01-14 09:22:18 +0900100func withUnbundledBuild(fs map[string][]byte, config android.Config) {
101 config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
102}
103
Jooyung Han344d5432019-08-23 11:17:39 +0900104func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
Jooyung Han671f1ce2019-12-17 12:47:13 +0900105 android.ClearApexDependency()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900106
107 bp = bp + `
Jooyung Han54aca7b2019-11-20 02:26:02 +0900108 filegroup {
109 name: "myapex-file_contexts",
110 srcs: [
111 "system/sepolicy/apex/myapex-file_contexts",
112 ],
113 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900114 `
Colin Cross98be1bb2019-12-13 20:41:13 -0800115
Colin Crossf9aabd72020-02-15 11:29:50 -0800116 bp = bp + cc.GatherRequiredDepsForTest(android.Android)
117
Dario Frenicde2a032019-10-27 00:29:22 +0100118 bp = bp + java.GatherRequiredDepsForTest()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900119
Jooyung Han344d5432019-08-23 11:17:39 +0900120 fs := map[string][]byte{
Jooyung Han54aca7b2019-11-20 02:26:02 +0900121 "a.java": nil,
122 "PrebuiltAppFoo.apk": nil,
123 "PrebuiltAppFooPriv.apk": nil,
124 "build/make/target/product/security": nil,
125 "apex_manifest.json": nil,
126 "AndroidManifest.xml": nil,
127 "system/sepolicy/apex/myapex-file_contexts": nil,
Jiyong Park9d677202020-02-19 16:29:35 +0900128 "system/sepolicy/apex/myapex.updatable-file_contexts": nil,
Jiyong Park83dc74b2020-01-14 18:38:44 +0900129 "system/sepolicy/apex/myapex2-file_contexts": nil,
Jooyung Han54aca7b2019-11-20 02:26:02 +0900130 "system/sepolicy/apex/otherapex-file_contexts": nil,
131 "system/sepolicy/apex/commonapex-file_contexts": nil,
132 "system/sepolicy/apex/com.android.vndk-file_contexts": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -0800133 "mylib.cpp": nil,
134 "mylib_common.cpp": nil,
135 "mytest.cpp": nil,
136 "mytest1.cpp": nil,
137 "mytest2.cpp": nil,
138 "mytest3.cpp": nil,
139 "myprebuilt": nil,
140 "my_include": nil,
141 "foo/bar/MyClass.java": nil,
142 "prebuilt.jar": nil,
143 "vendor/foo/devkeys/test.x509.pem": nil,
144 "vendor/foo/devkeys/test.pk8": nil,
145 "testkey.x509.pem": nil,
146 "testkey.pk8": nil,
147 "testkey.override.x509.pem": nil,
148 "testkey.override.pk8": nil,
149 "vendor/foo/devkeys/testkey.avbpubkey": nil,
150 "vendor/foo/devkeys/testkey.pem": nil,
151 "NOTICE": nil,
152 "custom_notice": nil,
Jiyong Park162e8442020-03-17 19:16:40 +0900153 "custom_notice_for_static_lib": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -0800154 "testkey2.avbpubkey": nil,
155 "testkey2.pem": nil,
156 "myapex-arm64.apex": nil,
157 "myapex-arm.apex": nil,
158 "frameworks/base/api/current.txt": nil,
159 "framework/aidl/a.aidl": nil,
160 "build/make/core/proguard.flags": nil,
161 "build/make/core/proguard_basic_keeps.flags": nil,
162 "dummy.txt": nil,
Jooyung Han344d5432019-08-23 11:17:39 +0900163 }
164
Colin Crossf9aabd72020-02-15 11:29:50 -0800165 cc.GatherRequiredFilesForTest(fs)
166
Jooyung Han344d5432019-08-23 11:17:39 +0900167 for _, handler := range handlers {
Colin Cross98be1bb2019-12-13 20:41:13 -0800168 // The fs now needs to be populated before creating the config, call handlers twice
169 // for now, once to get any fs changes, and later after the config was created to
170 // set product variables or targets.
171 tempConfig := android.TestArchConfig(buildDir, nil, bp, fs)
172 handler(fs, tempConfig)
Jooyung Han344d5432019-08-23 11:17:39 +0900173 }
174
Colin Cross98be1bb2019-12-13 20:41:13 -0800175 config := android.TestArchConfig(buildDir, nil, bp, fs)
176 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
177 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
178 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
179 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
180 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
181 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
182
183 for _, handler := range handlers {
184 // The fs now needs to be populated before creating the config, call handlers twice
185 // for now, earlier to get any fs changes, and now after the config was created to
186 // set product variables or targets.
187 tempFS := map[string][]byte{}
188 handler(tempFS, config)
189 }
190
191 ctx := android.NewTestArchContext()
192 ctx.RegisterModuleType("apex", BundleFactory)
193 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
194 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
195 ctx.RegisterModuleType("apex_key", ApexKeyFactory)
196 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
197 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
198 ctx.RegisterModuleType("override_apex", overrideApexFactory)
199
Jooyung Hana57af4a2020-01-23 05:36:59 +0000200 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
201 ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
202
Paul Duffin77980a82019-12-19 16:01:36 +0000203 cc.RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross98be1bb2019-12-13 20:41:13 -0800204 ctx.RegisterModuleType("cc_test", cc.TestFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800205 ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory)
206 ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800207 ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory)
atrost6e126252020-01-27 17:01:16 +0000208 ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800209 ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800210 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000211 java.RegisterJavaBuildComponents(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000212 java.RegisterSystemModulesBuildComponents(ctx)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000213 java.RegisterAppBuildComponents(ctx)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900214 ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800215
Colin Cross98be1bb2019-12-13 20:41:13 -0800216 ctx.PreDepsMutators(RegisterPreDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800217 ctx.PostDepsMutators(RegisterPostDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800218
219 ctx.Register(config)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900220
Jooyung Han5c998b92019-06-27 11:30:33 +0900221 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900222}
223
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700224func setUp() {
225 var err error
226 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900227 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700228 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900229 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900230}
231
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700232func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900233 os.RemoveAll(buildDir)
234}
235
236// ensure that 'result' contains 'expected'
237func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900238 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900239 if !strings.Contains(result, expected) {
240 t.Errorf("%q is not found in %q", expected, result)
241 }
242}
243
244// ensures that 'result' does not contain 'notExpected'
245func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900246 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900247 if strings.Contains(result, notExpected) {
248 t.Errorf("%q is found in %q", notExpected, result)
249 }
250}
251
252func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900253 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900254 if !android.InList(expected, result) {
255 t.Errorf("%q is not found in %v", expected, result)
256 }
257}
258
259func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900260 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900261 if android.InList(notExpected, result) {
262 t.Errorf("%q is found in %v", notExpected, result)
263 }
264}
265
Jooyung Hane1633032019-08-01 17:41:43 +0900266func ensureListEmpty(t *testing.T, result []string) {
267 t.Helper()
268 if len(result) > 0 {
269 t.Errorf("%q is expected to be empty", result)
270 }
271}
272
Jiyong Park25fc6a92018-11-18 18:02:45 +0900273// Minimal test
274func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700275 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900276 apex_defaults {
277 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900278 manifest: ":myapex.manifest",
279 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900280 key: "myapex.key",
281 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800282 multilib: {
283 both: {
284 binaries: ["foo",],
285 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900286 },
Jooyung Han5a80d9f2019-12-23 15:38:34 +0900287 java_libs: ["myjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900288 }
289
Jiyong Park30ca9372019-02-07 16:27:23 +0900290 apex {
291 name: "myapex",
292 defaults: ["myapex-defaults"],
293 }
294
Jiyong Park25fc6a92018-11-18 18:02:45 +0900295 apex_key {
296 name: "myapex.key",
297 public_key: "testkey.avbpubkey",
298 private_key: "testkey.pem",
299 }
300
Jiyong Park809bb722019-02-13 21:33:49 +0900301 filegroup {
302 name: "myapex.manifest",
303 srcs: ["apex_manifest.json"],
304 }
305
306 filegroup {
307 name: "myapex.androidmanifest",
308 srcs: ["AndroidManifest.xml"],
309 }
310
Jiyong Park25fc6a92018-11-18 18:02:45 +0900311 cc_library {
312 name: "mylib",
313 srcs: ["mylib.cpp"],
314 shared_libs: ["mylib2"],
315 system_shared_libs: [],
316 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000317 // TODO: remove //apex_available:platform
318 apex_available: [
319 "//apex_available:platform",
320 "myapex",
321 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900322 }
323
Alex Light3d673592019-01-18 14:37:31 -0800324 cc_binary {
325 name: "foo",
326 srcs: ["mylib.cpp"],
327 compile_multilib: "both",
328 multilib: {
329 lib32: {
330 suffix: "32",
331 },
332 lib64: {
333 suffix: "64",
334 },
335 },
336 symlinks: ["foo_link_"],
337 symlink_preferred_arch: true,
338 system_shared_libs: [],
339 static_executable: true,
340 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000341 apex_available: [ "myapex" ],
Alex Light3d673592019-01-18 14:37:31 -0800342 }
343
Jiyong Park25fc6a92018-11-18 18:02:45 +0900344 cc_library {
345 name: "mylib2",
346 srcs: ["mylib.cpp"],
347 system_shared_libs: [],
348 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900349 notice: "custom_notice",
Jiyong Park162e8442020-03-17 19:16:40 +0900350 static_libs: ["libstatic"],
351 // TODO: remove //apex_available:platform
352 apex_available: [
353 "//apex_available:platform",
354 "myapex",
355 ],
356 }
357
358 cc_library_static {
359 name: "libstatic",
360 srcs: ["mylib.cpp"],
361 system_shared_libs: [],
362 stl: "none",
363 notice: "custom_notice_for_static_lib",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000364 // TODO: remove //apex_available:platform
365 apex_available: [
366 "//apex_available:platform",
367 "myapex",
368 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900369 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900370
371 java_library {
372 name: "myjar",
373 srcs: ["foo/bar/MyClass.java"],
374 sdk_version: "none",
375 system_modules: "none",
Jiyong Park7f7766d2019-07-25 22:02:35 +0900376 static_libs: ["myotherjar"],
Jiyong Park3ff16992019-12-27 14:11:47 +0900377 libs: ["mysharedjar"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000378 // TODO: remove //apex_available:platform
379 apex_available: [
380 "//apex_available:platform",
381 "myapex",
382 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900383 }
384
385 java_library {
386 name: "myotherjar",
387 srcs: ["foo/bar/MyClass.java"],
388 sdk_version: "none",
389 system_modules: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +0900390 // TODO: remove //apex_available:platform
391 apex_available: [
392 "//apex_available:platform",
393 "myapex",
394 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900395 }
Jiyong Park3ff16992019-12-27 14:11:47 +0900396
397 java_library {
398 name: "mysharedjar",
399 srcs: ["foo/bar/MyClass.java"],
400 sdk_version: "none",
401 system_modules: "none",
Jiyong Park3ff16992019-12-27 14:11:47 +0900402 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900403 `)
404
Sundong Ahnabb64432019-10-22 13:58:29 +0900405 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900406
407 optFlags := apexRule.Args["opt_flags"]
408 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700409 // Ensure that the NOTICE output is being packaged as an asset.
Sundong Ahnabb64432019-10-22 13:58:29 +0900410 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900411
Jiyong Park25fc6a92018-11-18 18:02:45 +0900412 copyCmds := apexRule.Args["copy_commands"]
413
414 // Ensure that main rule creates an output
415 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
416
417 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800418 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900419 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900420
421 // Ensure that apex variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800422 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900423 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900424
425 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800426 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
427 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900428 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
429 // .. but not for java libs
430 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Jiyong Park3ff16992019-12-27 14:11:47 +0900431 ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800432
Colin Cross7113d202019-11-20 16:39:12 -0800433 // Ensure that the platform variant ends with _shared or _common
434 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
435 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900436 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
437 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park3ff16992019-12-27 14:11:47 +0900438 ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common")
439
440 // Ensure that dynamic dependency to java libs are not included
441 ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex")
Alex Light3d673592019-01-18 14:37:31 -0800442
443 // Ensure that all symlinks are present.
444 found_foo_link_64 := false
445 found_foo := false
446 for _, cmd := range strings.Split(copyCmds, " && ") {
Jiyong Park7cd10e32020-01-14 09:22:18 +0900447 if strings.HasPrefix(cmd, "ln -sfn foo64") {
Alex Light3d673592019-01-18 14:37:31 -0800448 if strings.HasSuffix(cmd, "bin/foo") {
449 found_foo = true
450 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
451 found_foo_link_64 = true
452 }
453 }
454 }
455 good := found_foo && found_foo_link_64
456 if !good {
457 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
458 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900459
Sundong Ahnabb64432019-10-22 13:58:29 +0900460 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700461 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jiyong Park162e8442020-03-17 19:16:40 +0900462 if len(noticeInputs) != 3 {
463 t.Errorf("number of input notice files: expected = 3, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900464 }
465 ensureListContains(t, noticeInputs, "NOTICE")
466 ensureListContains(t, noticeInputs, "custom_notice")
Jiyong Park162e8442020-03-17 19:16:40 +0900467 ensureListContains(t, noticeInputs, "custom_notice_for_static_lib")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900468
469 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 +0900470 ensureListContains(t, depsInfo, "myjar <- myapex")
471 ensureListContains(t, depsInfo, "mylib <- myapex")
472 ensureListContains(t, depsInfo, "mylib2 <- mylib")
473 ensureListContains(t, depsInfo, "myotherjar <- myjar")
474 ensureListContains(t, depsInfo, "mysharedjar (external) <- myjar")
Alex Light5098a612018-11-29 17:12:15 -0800475}
476
Jooyung Hanf21c7972019-12-16 22:32:06 +0900477func TestDefaults(t *testing.T) {
478 ctx, _ := testApex(t, `
479 apex_defaults {
480 name: "myapex-defaults",
481 key: "myapex.key",
482 prebuilts: ["myetc"],
483 native_shared_libs: ["mylib"],
484 java_libs: ["myjar"],
485 apps: ["AppFoo"],
486 }
487
488 prebuilt_etc {
489 name: "myetc",
490 src: "myprebuilt",
491 }
492
493 apex {
494 name: "myapex",
495 defaults: ["myapex-defaults"],
496 }
497
498 apex_key {
499 name: "myapex.key",
500 public_key: "testkey.avbpubkey",
501 private_key: "testkey.pem",
502 }
503
504 cc_library {
505 name: "mylib",
506 system_shared_libs: [],
507 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000508 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900509 }
510
511 java_library {
512 name: "myjar",
513 srcs: ["foo/bar/MyClass.java"],
514 sdk_version: "none",
515 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000516 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900517 }
518
519 android_app {
520 name: "AppFoo",
521 srcs: ["foo/bar/MyClass.java"],
522 sdk_version: "none",
523 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000524 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900525 }
526 `)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000527 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Hanf21c7972019-12-16 22:32:06 +0900528 "etc/myetc",
529 "javalib/myjar.jar",
530 "lib64/mylib.so",
531 "app/AppFoo/AppFoo.apk",
532 })
533}
534
Jooyung Han01a3ee22019-11-02 02:52:25 +0900535func TestApexManifest(t *testing.T) {
536 ctx, _ := testApex(t, `
537 apex {
538 name: "myapex",
539 key: "myapex.key",
540 }
541
542 apex_key {
543 name: "myapex.key",
544 public_key: "testkey.avbpubkey",
545 private_key: "testkey.pem",
546 }
547 `)
548
549 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han214bf372019-11-12 13:03:50 +0900550 args := module.Rule("apexRule").Args
551 if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() {
552 t.Error("manifest should be apex_manifest.pb, but " + manifest)
553 }
Jooyung Han01a3ee22019-11-02 02:52:25 +0900554}
555
Alex Light5098a612018-11-29 17:12:15 -0800556func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700557 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800558 apex {
559 name: "myapex",
560 key: "myapex.key",
561 payload_type: "zip",
562 native_shared_libs: ["mylib"],
563 }
564
565 apex_key {
566 name: "myapex.key",
567 public_key: "testkey.avbpubkey",
568 private_key: "testkey.pem",
569 }
570
571 cc_library {
572 name: "mylib",
573 srcs: ["mylib.cpp"],
574 shared_libs: ["mylib2"],
575 system_shared_libs: [],
576 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000577 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800578 }
579
580 cc_library {
581 name: "mylib2",
582 srcs: ["mylib.cpp"],
583 system_shared_libs: [],
584 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000585 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800586 }
587 `)
588
Sundong Ahnabb64432019-10-22 13:58:29 +0900589 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
Alex Light5098a612018-11-29 17:12:15 -0800590 copyCmds := zipApexRule.Args["copy_commands"]
591
592 // Ensure that main rule creates an output
593 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
594
595 // Ensure that APEX variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800596 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800597
598 // Ensure that APEX variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800599 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800600
601 // Ensure that both direct and indirect deps are copied into apex
602 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
603 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900604}
605
606func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700607 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900608 apex {
609 name: "myapex",
610 key: "myapex.key",
611 native_shared_libs: ["mylib", "mylib3"],
612 }
613
614 apex_key {
615 name: "myapex.key",
616 public_key: "testkey.avbpubkey",
617 private_key: "testkey.pem",
618 }
619
620 cc_library {
621 name: "mylib",
622 srcs: ["mylib.cpp"],
623 shared_libs: ["mylib2", "mylib3"],
624 system_shared_libs: [],
625 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000626 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900627 }
628
629 cc_library {
630 name: "mylib2",
631 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900632 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900633 system_shared_libs: [],
634 stl: "none",
635 stubs: {
636 versions: ["1", "2", "3"],
637 },
638 }
639
640 cc_library {
641 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900642 srcs: ["mylib.cpp"],
643 shared_libs: ["mylib4"],
644 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900645 stl: "none",
646 stubs: {
647 versions: ["10", "11", "12"],
648 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000649 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900650 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900651
652 cc_library {
653 name: "mylib4",
654 srcs: ["mylib.cpp"],
655 system_shared_libs: [],
656 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000657 apex_available: [ "myapex" ],
Jiyong Park28d395a2018-12-07 22:42:47 +0900658 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900659 `)
660
Sundong Ahnabb64432019-10-22 13:58:29 +0900661 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900662 copyCmds := apexRule.Args["copy_commands"]
663
664 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800665 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900666
667 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800668 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900669
670 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800671 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900672
Colin Cross7113d202019-11-20 16:39:12 -0800673 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900674
675 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900676 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900677 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900678 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900679
680 // 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 -0800681 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900682 // .. and not linking to the stubs variant of mylib3
Colin Cross7113d202019-11-20 16:39:12 -0800683 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900684
685 // Ensure that stubs libs are built without -include flags
Jiyong Park0f80c182020-01-31 02:49:53 +0900686 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900687 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900688
689 // Ensure that genstub is invoked with --apex
Jiyong Park3ff16992019-12-27 14:11:47 +0900690 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"])
Jooyung Han671f1ce2019-12-17 12:47:13 +0900691
Jooyung Hana57af4a2020-01-23 05:36:59 +0000692 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han671f1ce2019-12-17 12:47:13 +0900693 "lib64/mylib.so",
694 "lib64/mylib3.so",
695 "lib64/mylib4.so",
696 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900697}
698
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900699func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700700 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900701 apex {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900702 name: "myapex2",
703 key: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900704 native_shared_libs: ["mylib"],
705 }
706
707 apex_key {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900708 name: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900709 public_key: "testkey.avbpubkey",
710 private_key: "testkey.pem",
711 }
712
713 cc_library {
714 name: "mylib",
715 srcs: ["mylib.cpp"],
716 shared_libs: ["libfoo#10"],
Jiyong Park678c8812020-02-07 17:25:49 +0900717 static_libs: ["libbaz"],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900718 system_shared_libs: [],
719 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000720 apex_available: [ "myapex2" ],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900721 }
722
723 cc_library {
724 name: "libfoo",
725 srcs: ["mylib.cpp"],
726 shared_libs: ["libbar"],
727 system_shared_libs: [],
728 stl: "none",
729 stubs: {
730 versions: ["10", "20", "30"],
731 },
732 }
733
734 cc_library {
735 name: "libbar",
736 srcs: ["mylib.cpp"],
737 system_shared_libs: [],
738 stl: "none",
739 }
740
Jiyong Park678c8812020-02-07 17:25:49 +0900741 cc_library_static {
742 name: "libbaz",
743 srcs: ["mylib.cpp"],
744 system_shared_libs: [],
745 stl: "none",
746 apex_available: [ "myapex2" ],
747 }
748
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900749 `)
750
Jiyong Park83dc74b2020-01-14 18:38:44 +0900751 apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900752 copyCmds := apexRule.Args["copy_commands"]
753
754 // Ensure that direct non-stubs dep is always included
755 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
756
757 // Ensure that indirect stubs dep is not included
758 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
759
760 // Ensure that dependency of stubs is not included
761 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
762
Jiyong Park83dc74b2020-01-14 18:38:44 +0900763 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900764
765 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900766 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900767 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900768 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900769
Jiyong Park3ff16992019-12-27 14:11:47 +0900770 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900771
772 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
773 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900774
775 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 +0900776
777 ensureListContains(t, depsInfo, "mylib <- myapex2")
778 ensureListContains(t, depsInfo, "libbaz <- mylib")
779 ensureListContains(t, depsInfo, "libfoo (external) <- mylib")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900780}
781
Jooyung Hand3639552019-08-09 12:57:43 +0900782func TestApexWithRuntimeLibsDependency(t *testing.T) {
783 /*
784 myapex
785 |
786 v (runtime_libs)
787 mylib ------+------> libfoo [provides stub]
788 |
789 `------> libbar
790 */
791 ctx, _ := testApex(t, `
792 apex {
793 name: "myapex",
794 key: "myapex.key",
795 native_shared_libs: ["mylib"],
796 }
797
798 apex_key {
799 name: "myapex.key",
800 public_key: "testkey.avbpubkey",
801 private_key: "testkey.pem",
802 }
803
804 cc_library {
805 name: "mylib",
806 srcs: ["mylib.cpp"],
807 runtime_libs: ["libfoo", "libbar"],
808 system_shared_libs: [],
809 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000810 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900811 }
812
813 cc_library {
814 name: "libfoo",
815 srcs: ["mylib.cpp"],
816 system_shared_libs: [],
817 stl: "none",
818 stubs: {
819 versions: ["10", "20", "30"],
820 },
821 }
822
823 cc_library {
824 name: "libbar",
825 srcs: ["mylib.cpp"],
826 system_shared_libs: [],
827 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000828 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900829 }
830
831 `)
832
Sundong Ahnabb64432019-10-22 13:58:29 +0900833 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Hand3639552019-08-09 12:57:43 +0900834 copyCmds := apexRule.Args["copy_commands"]
835
836 // Ensure that direct non-stubs dep is always included
837 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
838
839 // Ensure that indirect stubs dep is not included
840 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
841
842 // Ensure that runtime_libs dep in included
843 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
844
Sundong Ahnabb64432019-10-22 13:58:29 +0900845 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900846 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
847 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900848
849}
850
Jooyung Han67a96cd2020-03-13 15:23:36 +0900851func TestApexDependsOnLLNDKTransitively(t *testing.T) {
852 testcases := []struct {
853 name string
854 minSdkVersion string
855 shouldLink string
856 shouldNotLink []string
857 }{
858 {
859 name: "should link to test latest",
860 minSdkVersion: "current",
861 shouldLink: "30",
862 shouldNotLink: []string{"29"},
863 },
864 {
865 name: "should link to llndk#29",
866 minSdkVersion: "29",
867 shouldLink: "29",
868 shouldNotLink: []string{"30"},
869 },
870 }
871 for _, tc := range testcases {
872 t.Run(tc.name, func(t *testing.T) {
873 ctx, _ := testApex(t, `
874 apex {
875 name: "myapex",
876 key: "myapex.key",
877 use_vendor: true,
878 native_shared_libs: ["mylib"],
879 min_sdk_version: "`+tc.minSdkVersion+`",
880 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900881
Jooyung Han67a96cd2020-03-13 15:23:36 +0900882 apex_key {
883 name: "myapex.key",
884 public_key: "testkey.avbpubkey",
885 private_key: "testkey.pem",
886 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900887
Jooyung Han67a96cd2020-03-13 15:23:36 +0900888 cc_library {
889 name: "mylib",
890 srcs: ["mylib.cpp"],
891 vendor_available: true,
892 shared_libs: ["libbar"],
893 system_shared_libs: [],
894 stl: "none",
895 apex_available: [ "myapex" ],
896 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900897
Jooyung Han67a96cd2020-03-13 15:23:36 +0900898 cc_library {
899 name: "libbar",
900 srcs: ["mylib.cpp"],
901 system_shared_libs: [],
902 stl: "none",
903 stubs: { versions: ["29","30"] },
904 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900905
Jooyung Han67a96cd2020-03-13 15:23:36 +0900906 llndk_library {
907 name: "libbar",
908 symbol_file: "",
909 }
910 `, func(fs map[string][]byte, config android.Config) {
911 setUseVendorWhitelistForTest(config, []string{"myapex"})
912 }, withUnbundledBuild)
Jooyung Han9c80bae2019-08-20 17:30:57 +0900913
Jooyung Han67a96cd2020-03-13 15:23:36 +0900914 // Ensure that LLNDK dep is not included
915 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
916 "lib64/mylib.so",
917 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900918
Jooyung Han67a96cd2020-03-13 15:23:36 +0900919 // Ensure that LLNDK dep is required
920 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
921 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
922 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900923
Jooyung Han67a96cd2020-03-13 15:23:36 +0900924 mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
925 ensureContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so")
926 for _, ver := range tc.shouldNotLink {
927 ensureNotContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so")
928 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900929
Jooyung Han67a96cd2020-03-13 15:23:36 +0900930 mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
931 ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink)
932 })
933 }
Jooyung Han9c80bae2019-08-20 17:30:57 +0900934}
935
Jiyong Park25fc6a92018-11-18 18:02:45 +0900936func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700937 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900938 apex {
939 name: "myapex",
940 key: "myapex.key",
941 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
942 }
943
944 apex_key {
945 name: "myapex.key",
946 public_key: "testkey.avbpubkey",
947 private_key: "testkey.pem",
948 }
949
950 cc_library {
951 name: "mylib",
952 srcs: ["mylib.cpp"],
953 shared_libs: ["libdl#27"],
954 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000955 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900956 }
957
958 cc_library_shared {
959 name: "mylib_shared",
960 srcs: ["mylib.cpp"],
961 shared_libs: ["libdl#27"],
962 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000963 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900964 }
965
966 cc_library {
Jiyong Parkb0788572018-12-20 22:10:17 +0900967 name: "libBootstrap",
968 srcs: ["mylib.cpp"],
969 stl: "none",
970 bootstrap: true,
971 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900972 `)
973
Sundong Ahnabb64432019-10-22 13:58:29 +0900974 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900975 copyCmds := apexRule.Args["copy_commands"]
976
977 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800978 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900979 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
980 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900981
982 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900983 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900984
Colin Cross7113d202019-11-20 16:39:12 -0800985 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
986 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
987 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900988
989 // For dependency to libc
990 // Ensure that mylib is linking with the latest version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +0900991 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900992 // ... and not linking to the non-stub (impl) variant
Jiyong Park3ff16992019-12-27 14:11:47 +0900993 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900994 // ... Cflags from stub is correctly exported to mylib
995 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
996 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
997
998 // For dependency to libm
999 // Ensure that mylib is linking with the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -08001000 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001001 // ... and not linking to the stub variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001002 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001003 // ... and is not compiling with the stub
1004 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
1005 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
1006
1007 // For dependency to libdl
1008 // Ensure that mylib is linking with the specified version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001009 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001010 // ... and not linking to the other versions of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001011 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so")
1012 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001013 // ... and not linking to the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -08001014 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001015 // ... Cflags from stub is correctly exported to mylib
1016 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
1017 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +09001018
1019 // Ensure that libBootstrap is depending on the platform variant of bionic libs
Colin Cross7113d202019-11-20 16:39:12 -08001020 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"]
1021 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so")
1022 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so")
1023 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001024}
Jiyong Park7c2ee712018-12-07 00:42:25 +09001025
Jooyung Han0c4e0162020-02-26 22:45:42 +09001026func TestApexUseStubsAccordingToMinSdkVersionInUnbundledBuild(t *testing.T) {
1027 // there are three links between liba --> libz
1028 // 1) myapex -> libx -> liba -> libz : this should be #2 link, but fallback to #1
1029 // 2) otherapex -> liby -> liba -> libz : this should be #3 link
1030 // 3) (platform) -> liba -> libz : this should be non-stub link
1031 ctx, _ := testApex(t, `
1032 apex {
1033 name: "myapex",
1034 key: "myapex.key",
1035 native_shared_libs: ["libx"],
1036 min_sdk_version: "2",
1037 }
1038
1039 apex {
1040 name: "otherapex",
1041 key: "myapex.key",
1042 native_shared_libs: ["liby"],
1043 min_sdk_version: "3",
1044 }
1045
1046 apex_key {
1047 name: "myapex.key",
1048 public_key: "testkey.avbpubkey",
1049 private_key: "testkey.pem",
1050 }
1051
1052 cc_library {
1053 name: "libx",
1054 shared_libs: ["liba"],
1055 system_shared_libs: [],
1056 stl: "none",
1057 apex_available: [ "myapex" ],
1058 }
1059
1060 cc_library {
1061 name: "liby",
1062 shared_libs: ["liba"],
1063 system_shared_libs: [],
1064 stl: "none",
1065 apex_available: [ "otherapex" ],
1066 }
1067
1068 cc_library {
1069 name: "liba",
1070 shared_libs: ["libz"],
1071 system_shared_libs: [],
1072 stl: "none",
1073 apex_available: [
1074 "//apex_available:anyapex",
1075 "//apex_available:platform",
1076 ],
1077 }
1078
1079 cc_library {
1080 name: "libz",
1081 system_shared_libs: [],
1082 stl: "none",
1083 stubs: {
1084 versions: ["1", "3"],
1085 },
1086 }
1087 `, withUnbundledBuild)
1088
1089 expectLink := func(from, from_variant, to, to_variant string) {
1090 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1091 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1092 }
1093 expectNoLink := func(from, from_variant, to, to_variant string) {
1094 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1095 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1096 }
1097 // platform liba is linked to non-stub version
1098 expectLink("liba", "shared", "libz", "shared")
1099 // liba in myapex is linked to #1
1100 expectLink("liba", "shared_myapex", "libz", "shared_1")
1101 expectNoLink("liba", "shared_myapex", "libz", "shared_3")
1102 expectNoLink("liba", "shared_myapex", "libz", "shared")
1103 // liba in otherapex is linked to #3
1104 expectLink("liba", "shared_otherapex", "libz", "shared_3")
1105 expectNoLink("liba", "shared_otherapex", "libz", "shared_1")
1106 expectNoLink("liba", "shared_otherapex", "libz", "shared")
1107}
1108
1109func TestApexMinSdkVersionDefaultsToLatest(t *testing.T) {
1110 ctx, _ := testApex(t, `
1111 apex {
1112 name: "myapex",
1113 key: "myapex.key",
1114 native_shared_libs: ["libx"],
1115 }
1116
1117 apex_key {
1118 name: "myapex.key",
1119 public_key: "testkey.avbpubkey",
1120 private_key: "testkey.pem",
1121 }
1122
1123 cc_library {
1124 name: "libx",
1125 shared_libs: ["libz"],
1126 system_shared_libs: [],
1127 stl: "none",
1128 apex_available: [ "myapex" ],
1129 }
1130
1131 cc_library {
1132 name: "libz",
1133 system_shared_libs: [],
1134 stl: "none",
1135 stubs: {
1136 versions: ["1", "2"],
1137 },
1138 }
1139 `)
1140
1141 expectLink := func(from, from_variant, to, to_variant string) {
1142 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1143 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1144 }
1145 expectNoLink := func(from, from_variant, to, to_variant string) {
1146 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1147 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1148 }
1149 expectLink("libx", "shared_myapex", "libz", "shared_2")
1150 expectNoLink("libx", "shared_myapex", "libz", "shared_1")
1151 expectNoLink("libx", "shared_myapex", "libz", "shared")
1152}
1153
1154func TestPlatformUsesLatestStubsFromApexes(t *testing.T) {
1155 ctx, _ := testApex(t, `
1156 apex {
1157 name: "myapex",
1158 key: "myapex.key",
1159 native_shared_libs: ["libx"],
1160 }
1161
1162 apex_key {
1163 name: "myapex.key",
1164 public_key: "testkey.avbpubkey",
1165 private_key: "testkey.pem",
1166 }
1167
1168 cc_library {
1169 name: "libx",
1170 system_shared_libs: [],
1171 stl: "none",
1172 apex_available: [ "myapex" ],
1173 stubs: {
1174 versions: ["1", "2"],
1175 },
1176 }
1177
1178 cc_library {
1179 name: "libz",
1180 shared_libs: ["libx"],
1181 system_shared_libs: [],
1182 stl: "none",
1183 }
1184 `)
1185
1186 expectLink := func(from, from_variant, to, to_variant string) {
1187 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1188 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1189 }
1190 expectNoLink := func(from, from_variant, to, to_variant string) {
1191 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1192 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1193 }
1194 expectLink("libz", "shared", "libx", "shared_2")
1195 expectNoLink("libz", "shared", "libz", "shared_1")
1196 expectNoLink("libz", "shared", "libz", "shared")
1197}
1198
1199func TestQApexesUseLatestStubsInBundledBuilds(t *testing.T) {
1200 ctx, _ := testApex(t, `
1201 apex {
1202 name: "myapex",
1203 key: "myapex.key",
1204 native_shared_libs: ["libx"],
1205 min_sdk_version: "29",
1206 }
1207
1208 apex_key {
1209 name: "myapex.key",
1210 public_key: "testkey.avbpubkey",
1211 private_key: "testkey.pem",
1212 }
1213
1214 cc_library {
1215 name: "libx",
1216 shared_libs: ["libbar"],
1217 apex_available: [ "myapex" ],
1218 }
1219
1220 cc_library {
1221 name: "libbar",
1222 stubs: {
1223 versions: ["29", "30"],
1224 },
1225 }
1226 `)
1227 expectLink := func(from, from_variant, to, to_variant string) {
1228 ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld")
1229 libFlags := ld.Args["libFlags"]
1230 ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1231 }
1232 expectLink("libx", "shared_myapex", "libbar", "shared_30")
1233}
1234
1235func TestQTargetApexUseStaticUnwinder(t *testing.T) {
1236 ctx, _ := testApex(t, `
1237 apex {
1238 name: "myapex",
1239 key: "myapex.key",
1240 native_shared_libs: ["libx"],
1241 min_sdk_version: "29",
1242 }
1243
1244 apex_key {
1245 name: "myapex.key",
1246 public_key: "testkey.avbpubkey",
1247 private_key: "testkey.pem",
1248 }
1249
1250 cc_library {
1251 name: "libx",
1252 apex_available: [ "myapex" ],
1253 }
1254
1255 `, withUnbundledBuild)
1256
1257 // ensure apex variant of c++ is linked with static unwinder
1258 cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module)
1259 ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
1260 // note that platform variant is not.
1261 cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module)
1262 ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
Jooyung Han0c4e0162020-02-26 22:45:42 +09001263}
1264
1265func TestInvalidMinSdkVersion(t *testing.T) {
1266 testApexError(t, `"libz" .*: min_sdk_version is set 29.*`, `
1267 apex {
1268 name: "myapex",
1269 key: "myapex.key",
1270 native_shared_libs: ["libx"],
1271 min_sdk_version: "29",
1272 }
1273
1274 apex_key {
1275 name: "myapex.key",
1276 public_key: "testkey.avbpubkey",
1277 private_key: "testkey.pem",
1278 }
1279
1280 cc_library {
1281 name: "libx",
1282 shared_libs: ["libz"],
1283 system_shared_libs: [],
1284 stl: "none",
1285 apex_available: [ "myapex" ],
1286 }
1287
1288 cc_library {
1289 name: "libz",
1290 system_shared_libs: [],
1291 stl: "none",
1292 stubs: {
1293 versions: ["30"],
1294 },
1295 }
1296 `, withUnbundledBuild)
1297
1298 testApexError(t, `"myapex" .*: min_sdk_version: should be .*`, `
1299 apex {
1300 name: "myapex",
1301 key: "myapex.key",
1302 min_sdk_version: "R",
1303 }
1304
1305 apex_key {
1306 name: "myapex.key",
1307 public_key: "testkey.avbpubkey",
1308 private_key: "testkey.pem",
1309 }
1310 `)
1311}
1312
Jiyong Park7c2ee712018-12-07 00:42:25 +09001313func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001314 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +09001315 apex {
1316 name: "myapex",
1317 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001318 native_shared_libs: ["mylib"],
1319 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +09001320 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001321 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +09001322 }
1323
1324 apex_key {
1325 name: "myapex.key",
1326 public_key: "testkey.avbpubkey",
1327 private_key: "testkey.pem",
1328 }
1329
1330 prebuilt_etc {
1331 name: "myetc",
1332 src: "myprebuilt",
1333 sub_dir: "foo/bar",
1334 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001335
1336 cc_library {
1337 name: "mylib",
1338 srcs: ["mylib.cpp"],
1339 relative_install_path: "foo/bar",
1340 system_shared_libs: [],
1341 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001342 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001343 }
1344
1345 cc_binary {
1346 name: "mybin",
1347 srcs: ["mylib.cpp"],
1348 relative_install_path: "foo/bar",
1349 system_shared_libs: [],
1350 static_executable: true,
1351 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001352 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001353 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001354 `)
1355
Sundong Ahnabb64432019-10-22 13:58:29 +09001356 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001357 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1358
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001359 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001360 ensureListContains(t, dirs, "etc")
1361 ensureListContains(t, dirs, "etc/foo")
1362 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001363 ensureListContains(t, dirs, "lib64")
1364 ensureListContains(t, dirs, "lib64/foo")
1365 ensureListContains(t, dirs, "lib64/foo/bar")
1366 ensureListContains(t, dirs, "lib")
1367 ensureListContains(t, dirs, "lib/foo")
1368 ensureListContains(t, dirs, "lib/foo/bar")
1369
Jiyong Parkbd13e442019-03-15 18:10:35 +09001370 ensureListContains(t, dirs, "bin")
1371 ensureListContains(t, dirs, "bin/foo")
1372 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001373}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001374
1375func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001376 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001377 apex {
1378 name: "myapex",
1379 key: "myapex.key",
1380 native_shared_libs: ["mylib"],
1381 use_vendor: true,
1382 }
1383
1384 apex_key {
1385 name: "myapex.key",
1386 public_key: "testkey.avbpubkey",
1387 private_key: "testkey.pem",
1388 }
1389
1390 cc_library {
1391 name: "mylib",
1392 srcs: ["mylib.cpp"],
1393 shared_libs: ["mylib2"],
1394 system_shared_libs: [],
1395 vendor_available: true,
1396 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001397 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001398 }
1399
1400 cc_library {
1401 name: "mylib2",
1402 srcs: ["mylib.cpp"],
1403 system_shared_libs: [],
1404 vendor_available: true,
1405 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001406 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001407 }
Jooyung Handc782442019-11-01 03:14:38 +09001408 `, func(fs map[string][]byte, config android.Config) {
1409 setUseVendorWhitelistForTest(config, []string{"myapex"})
1410 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001411
1412 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001413 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001414 for _, implicit := range i.Implicits {
1415 inputsList = append(inputsList, implicit.String())
1416 }
1417 }
1418 inputsString := strings.Join(inputsList, " ")
1419
1420 // ensure that the apex includes vendor variants of the direct and indirect deps
Colin Crossfb0c16e2019-11-20 17:12:35 -08001421 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so")
1422 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001423
1424 // ensure that the apex does not include core variants
Colin Cross7113d202019-11-20 16:39:12 -08001425 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so")
1426 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001427}
Jiyong Park16e91a02018-12-20 18:18:08 +09001428
Jooyung Handc782442019-11-01 03:14:38 +09001429func TestUseVendorRestriction(t *testing.T) {
1430 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1431 apex {
1432 name: "myapex",
1433 key: "myapex.key",
1434 use_vendor: true,
1435 }
1436 apex_key {
1437 name: "myapex.key",
1438 public_key: "testkey.avbpubkey",
1439 private_key: "testkey.pem",
1440 }
1441 `, func(fs map[string][]byte, config android.Config) {
1442 setUseVendorWhitelistForTest(config, []string{""})
1443 })
1444 // no error with whitelist
1445 testApex(t, `
1446 apex {
1447 name: "myapex",
1448 key: "myapex.key",
1449 use_vendor: true,
1450 }
1451 apex_key {
1452 name: "myapex.key",
1453 public_key: "testkey.avbpubkey",
1454 private_key: "testkey.pem",
1455 }
1456 `, func(fs map[string][]byte, config android.Config) {
1457 setUseVendorWhitelistForTest(config, []string{"myapex"})
1458 })
1459}
1460
Jooyung Han5c998b92019-06-27 11:30:33 +09001461func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1462 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1463 apex {
1464 name: "myapex",
1465 key: "myapex.key",
1466 native_shared_libs: ["mylib"],
1467 use_vendor: true,
1468 }
1469
1470 apex_key {
1471 name: "myapex.key",
1472 public_key: "testkey.avbpubkey",
1473 private_key: "testkey.pem",
1474 }
1475
1476 cc_library {
1477 name: "mylib",
1478 srcs: ["mylib.cpp"],
1479 system_shared_libs: [],
1480 stl: "none",
1481 }
1482 `)
1483}
1484
Jiyong Park16e91a02018-12-20 18:18:08 +09001485func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001486 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001487 apex {
1488 name: "myapex",
1489 key: "myapex.key",
1490 native_shared_libs: ["mylib"],
1491 }
1492
1493 apex_key {
1494 name: "myapex.key",
1495 public_key: "testkey.avbpubkey",
1496 private_key: "testkey.pem",
1497 }
1498
1499 cc_library {
1500 name: "mylib",
1501 srcs: ["mylib.cpp"],
1502 system_shared_libs: [],
1503 stl: "none",
1504 stubs: {
1505 versions: ["1", "2", "3"],
1506 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001507 apex_available: [
1508 "//apex_available:platform",
1509 "myapex",
1510 ],
Jiyong Park16e91a02018-12-20 18:18:08 +09001511 }
1512
1513 cc_binary {
1514 name: "not_in_apex",
1515 srcs: ["mylib.cpp"],
1516 static_libs: ["mylib"],
1517 static_executable: true,
1518 system_shared_libs: [],
1519 stl: "none",
1520 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001521 `)
1522
Colin Cross7113d202019-11-20 16:39:12 -08001523 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
Jiyong Park16e91a02018-12-20 18:18:08 +09001524
1525 // Ensure that not_in_apex is linking with the static variant of mylib
Colin Cross7113d202019-11-20 16:39:12 -08001526 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001527}
Jiyong Park9335a262018-12-24 11:31:58 +09001528
1529func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001530 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001531 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001532 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001533 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001534 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001535 native_shared_libs: ["mylib"],
Jooyung Han54aca7b2019-11-20 02:26:02 +09001536 file_contexts: ":myapex-file_contexts",
Jiyong Park9335a262018-12-24 11:31:58 +09001537 }
1538
1539 cc_library {
1540 name: "mylib",
1541 srcs: ["mylib.cpp"],
1542 system_shared_libs: [],
1543 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001544 apex_available: [ "myapex_keytest" ],
Jiyong Park9335a262018-12-24 11:31:58 +09001545 }
1546
1547 apex_key {
1548 name: "myapex.key",
1549 public_key: "testkey.avbpubkey",
1550 private_key: "testkey.pem",
1551 }
1552
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001553 android_app_certificate {
1554 name: "myapex.certificate",
1555 certificate: "testkey",
1556 }
1557
1558 android_app_certificate {
1559 name: "myapex.certificate.override",
1560 certificate: "testkey.override",
1561 }
1562
Jiyong Park9335a262018-12-24 11:31:58 +09001563 `)
1564
1565 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001566 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001567
1568 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1569 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1570 "vendor/foo/devkeys/testkey.avbpubkey")
1571 }
1572 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1573 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1574 "vendor/foo/devkeys/testkey.pem")
1575 }
1576
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001577 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001578 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001579 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001580 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001581 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001582 }
1583}
Jiyong Park58e364a2019-01-19 19:24:06 +09001584
Jooyung Hanf121a652019-12-17 14:30:11 +09001585func TestCertificate(t *testing.T) {
1586 t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) {
1587 ctx, _ := testApex(t, `
1588 apex {
1589 name: "myapex",
1590 key: "myapex.key",
1591 }
1592 apex_key {
1593 name: "myapex.key",
1594 public_key: "testkey.avbpubkey",
1595 private_key: "testkey.pem",
1596 }`)
1597 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1598 expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8"
1599 if actual := rule.Args["certificates"]; actual != expected {
1600 t.Errorf("certificates should be %q, not %q", expected, actual)
1601 }
1602 })
1603 t.Run("override when unspecified", func(t *testing.T) {
1604 ctx, _ := testApex(t, `
1605 apex {
1606 name: "myapex_keytest",
1607 key: "myapex.key",
1608 file_contexts: ":myapex-file_contexts",
1609 }
1610 apex_key {
1611 name: "myapex.key",
1612 public_key: "testkey.avbpubkey",
1613 private_key: "testkey.pem",
1614 }
1615 android_app_certificate {
1616 name: "myapex.certificate.override",
1617 certificate: "testkey.override",
1618 }`)
1619 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1620 expected := "testkey.override.x509.pem testkey.override.pk8"
1621 if actual := rule.Args["certificates"]; actual != expected {
1622 t.Errorf("certificates should be %q, not %q", expected, actual)
1623 }
1624 })
1625 t.Run("if specified as :module, it respects the prop", func(t *testing.T) {
1626 ctx, _ := testApex(t, `
1627 apex {
1628 name: "myapex",
1629 key: "myapex.key",
1630 certificate: ":myapex.certificate",
1631 }
1632 apex_key {
1633 name: "myapex.key",
1634 public_key: "testkey.avbpubkey",
1635 private_key: "testkey.pem",
1636 }
1637 android_app_certificate {
1638 name: "myapex.certificate",
1639 certificate: "testkey",
1640 }`)
1641 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1642 expected := "testkey.x509.pem testkey.pk8"
1643 if actual := rule.Args["certificates"]; actual != expected {
1644 t.Errorf("certificates should be %q, not %q", expected, actual)
1645 }
1646 })
1647 t.Run("override when specifiec as <:module>", func(t *testing.T) {
1648 ctx, _ := testApex(t, `
1649 apex {
1650 name: "myapex_keytest",
1651 key: "myapex.key",
1652 file_contexts: ":myapex-file_contexts",
1653 certificate: ":myapex.certificate",
1654 }
1655 apex_key {
1656 name: "myapex.key",
1657 public_key: "testkey.avbpubkey",
1658 private_key: "testkey.pem",
1659 }
1660 android_app_certificate {
1661 name: "myapex.certificate.override",
1662 certificate: "testkey.override",
1663 }`)
1664 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1665 expected := "testkey.override.x509.pem testkey.override.pk8"
1666 if actual := rule.Args["certificates"]; actual != expected {
1667 t.Errorf("certificates should be %q, not %q", expected, actual)
1668 }
1669 })
1670 t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) {
1671 ctx, _ := testApex(t, `
1672 apex {
1673 name: "myapex",
1674 key: "myapex.key",
1675 certificate: "testkey",
1676 }
1677 apex_key {
1678 name: "myapex.key",
1679 public_key: "testkey.avbpubkey",
1680 private_key: "testkey.pem",
1681 }`)
1682 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1683 expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8"
1684 if actual := rule.Args["certificates"]; actual != expected {
1685 t.Errorf("certificates should be %q, not %q", expected, actual)
1686 }
1687 })
1688 t.Run("override when specified as <name>", func(t *testing.T) {
1689 ctx, _ := testApex(t, `
1690 apex {
1691 name: "myapex_keytest",
1692 key: "myapex.key",
1693 file_contexts: ":myapex-file_contexts",
1694 certificate: "testkey",
1695 }
1696 apex_key {
1697 name: "myapex.key",
1698 public_key: "testkey.avbpubkey",
1699 private_key: "testkey.pem",
1700 }
1701 android_app_certificate {
1702 name: "myapex.certificate.override",
1703 certificate: "testkey.override",
1704 }`)
1705 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1706 expected := "testkey.override.x509.pem testkey.override.pk8"
1707 if actual := rule.Args["certificates"]; actual != expected {
1708 t.Errorf("certificates should be %q, not %q", expected, actual)
1709 }
1710 })
1711}
1712
Jiyong Park58e364a2019-01-19 19:24:06 +09001713func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001714 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001715 apex {
1716 name: "myapex",
1717 key: "myapex.key",
Jooyung Han68e511e2020-03-02 17:44:33 +09001718 native_shared_libs: ["mylib", "mylib2"],
Jiyong Park58e364a2019-01-19 19:24:06 +09001719 }
1720
1721 apex {
1722 name: "otherapex",
1723 key: "myapex.key",
Jooyung Han68e511e2020-03-02 17:44:33 +09001724 native_shared_libs: ["mylib", "mylib2"],
Jooyung Han61c41542020-03-07 03:45:53 +09001725 min_sdk_version: "29",
Jiyong Park58e364a2019-01-19 19:24:06 +09001726 }
1727
1728 apex_key {
1729 name: "myapex.key",
1730 public_key: "testkey.avbpubkey",
1731 private_key: "testkey.pem",
1732 }
1733
1734 cc_library {
1735 name: "mylib",
1736 srcs: ["mylib.cpp"],
1737 system_shared_libs: [],
1738 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001739 apex_available: [
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001740 "myapex",
1741 "otherapex",
1742 ],
Jiyong Park58e364a2019-01-19 19:24:06 +09001743 }
Jooyung Han68e511e2020-03-02 17:44:33 +09001744 cc_library {
1745 name: "mylib2",
1746 srcs: ["mylib.cpp"],
1747 system_shared_libs: [],
1748 stl: "none",
1749 apex_available: [
1750 "myapex",
1751 "otherapex",
1752 ],
1753 use_apex_name_macro: true,
1754 }
Jiyong Park58e364a2019-01-19 19:24:06 +09001755 `)
1756
Jooyung Han68e511e2020-03-02 17:44:33 +09001757 // non-APEX variant does not have __ANDROID_APEX__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001758 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001759 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han61c41542020-03-07 03:45:53 +09001760 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
Jooyung Han68e511e2020-03-02 17:44:33 +09001761
Jooyung Han61c41542020-03-07 03:45:53 +09001762 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Jooyung Han68e511e2020-03-02 17:44:33 +09001763 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
1764 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han61c41542020-03-07 03:45:53 +09001765 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
Jooyung Han77988572019-10-18 16:26:16 +09001766 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
Jooyung Han68e511e2020-03-02 17:44:33 +09001767
Jooyung Han61c41542020-03-07 03:45:53 +09001768 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Jooyung Han68e511e2020-03-02 17:44:33 +09001769 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
1770 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han61c41542020-03-07 03:45:53 +09001771 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29")
Jooyung Han77988572019-10-18 16:26:16 +09001772 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001773
Jooyung Han68e511e2020-03-02 17:44:33 +09001774 // When cc_library sets use_apex_name_macro: true
1775 // apex variants define additional macro to distinguish which apex variant it is built for
1776
1777 // non-APEX variant does not have __ANDROID_APEX__ defined
1778 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
1779 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
1780
1781 // APEX variant has __ANDROID_APEX__ defined
1782 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001783 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001784 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1785 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001786
Jooyung Han68e511e2020-03-02 17:44:33 +09001787 // APEX variant has __ANDROID_APEX__ defined
1788 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001789 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001790 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1791 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001792}
Jiyong Park7e636d02019-01-28 16:16:54 +09001793
1794func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001795 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001796 apex {
1797 name: "myapex",
1798 key: "myapex.key",
1799 native_shared_libs: ["mylib"],
1800 }
1801
1802 apex_key {
1803 name: "myapex.key",
1804 public_key: "testkey.avbpubkey",
1805 private_key: "testkey.pem",
1806 }
1807
1808 cc_library_headers {
1809 name: "mylib_headers",
1810 export_include_dirs: ["my_include"],
1811 system_shared_libs: [],
1812 stl: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +09001813 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001814 }
1815
1816 cc_library {
1817 name: "mylib",
1818 srcs: ["mylib.cpp"],
1819 system_shared_libs: [],
1820 stl: "none",
1821 header_libs: ["mylib_headers"],
1822 export_header_lib_headers: ["mylib_headers"],
1823 stubs: {
1824 versions: ["1", "2", "3"],
1825 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001826 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001827 }
1828
1829 cc_library {
1830 name: "otherlib",
1831 srcs: ["mylib.cpp"],
1832 system_shared_libs: [],
1833 stl: "none",
1834 shared_libs: ["mylib"],
1835 }
1836 `)
1837
Colin Cross7113d202019-11-20 16:39:12 -08001838 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park7e636d02019-01-28 16:16:54 +09001839
1840 // Ensure that the include path of the header lib is exported to 'otherlib'
1841 ensureContains(t, cFlags, "-Imy_include")
1842}
Alex Light9670d332019-01-29 18:07:33 -08001843
Jiyong Park7cd10e32020-01-14 09:22:18 +09001844type fileInApex struct {
1845 path string // path in apex
Jooyung Hana57af4a2020-01-23 05:36:59 +00001846 src string // src path
Jiyong Park7cd10e32020-01-14 09:22:18 +09001847 isLink bool
1848}
1849
Jooyung Hana57af4a2020-01-23 05:36:59 +00001850func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex {
Jooyung Han31c470b2019-10-18 16:26:59 +09001851 t.Helper()
Jooyung Hana57af4a2020-01-23 05:36:59 +00001852 apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001853 copyCmds := apexRule.Args["copy_commands"]
1854 imageApexDir := "/image.apex/"
Jiyong Park7cd10e32020-01-14 09:22:18 +09001855 var ret []fileInApex
Jooyung Han31c470b2019-10-18 16:26:59 +09001856 for _, cmd := range strings.Split(copyCmds, "&&") {
1857 cmd = strings.TrimSpace(cmd)
1858 if cmd == "" {
1859 continue
1860 }
1861 terms := strings.Split(cmd, " ")
Jooyung Hana57af4a2020-01-23 05:36:59 +00001862 var dst, src string
Jiyong Park7cd10e32020-01-14 09:22:18 +09001863 var isLink bool
Jooyung Han31c470b2019-10-18 16:26:59 +09001864 switch terms[0] {
1865 case "mkdir":
1866 case "cp":
Jiyong Park7cd10e32020-01-14 09:22:18 +09001867 if len(terms) != 3 && len(terms) != 4 {
Jooyung Han31c470b2019-10-18 16:26:59 +09001868 t.Fatal("copyCmds contains invalid cp command", cmd)
1869 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001870 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001871 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001872 isLink = false
1873 case "ln":
1874 if len(terms) != 3 && len(terms) != 4 {
1875 // ln LINK TARGET or ln -s LINK TARGET
1876 t.Fatal("copyCmds contains invalid ln command", cmd)
1877 }
1878 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001879 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001880 isLink = true
1881 default:
1882 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1883 }
1884 if dst != "" {
Jooyung Han31c470b2019-10-18 16:26:59 +09001885 index := strings.Index(dst, imageApexDir)
1886 if index == -1 {
1887 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1888 }
1889 dstFile := dst[index+len(imageApexDir):]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001890 ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink})
Jooyung Han31c470b2019-10-18 16:26:59 +09001891 }
1892 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001893 return ret
1894}
1895
Jooyung Hana57af4a2020-01-23 05:36:59 +00001896func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) {
1897 t.Helper()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001898 var failed bool
1899 var surplus []string
1900 filesMatched := make(map[string]bool)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001901 for _, file := range getFiles(t, ctx, moduleName, variant) {
Jooyung Han8d8906c2020-02-27 13:31:56 +09001902 mactchFound := false
Jiyong Park7cd10e32020-01-14 09:22:18 +09001903 for _, expected := range files {
1904 if matched, _ := path.Match(expected, file.path); matched {
1905 filesMatched[expected] = true
Jooyung Han8d8906c2020-02-27 13:31:56 +09001906 mactchFound = true
1907 break
Jiyong Park7cd10e32020-01-14 09:22:18 +09001908 }
1909 }
Jooyung Han8d8906c2020-02-27 13:31:56 +09001910 if !mactchFound {
1911 surplus = append(surplus, file.path)
1912 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001913 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001914
Jooyung Han31c470b2019-10-18 16:26:59 +09001915 if len(surplus) > 0 {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001916 sort.Strings(surplus)
Jooyung Han31c470b2019-10-18 16:26:59 +09001917 t.Log("surplus files", surplus)
1918 failed = true
1919 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001920
1921 if len(files) > len(filesMatched) {
1922 var missing []string
1923 for _, expected := range files {
1924 if !filesMatched[expected] {
1925 missing = append(missing, expected)
1926 }
1927 }
1928 sort.Strings(missing)
Jooyung Han31c470b2019-10-18 16:26:59 +09001929 t.Log("missing files", missing)
1930 failed = true
1931 }
1932 if failed {
1933 t.Fail()
1934 }
1935}
1936
Jooyung Han344d5432019-08-23 11:17:39 +09001937func TestVndkApexCurrent(t *testing.T) {
1938 ctx, _ := testApex(t, `
1939 apex_vndk {
1940 name: "myapex",
1941 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001942 }
1943
1944 apex_key {
1945 name: "myapex.key",
1946 public_key: "testkey.avbpubkey",
1947 private_key: "testkey.pem",
1948 }
1949
1950 cc_library {
1951 name: "libvndk",
1952 srcs: ["mylib.cpp"],
1953 vendor_available: true,
1954 vndk: {
1955 enabled: true,
1956 },
1957 system_shared_libs: [],
1958 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001959 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001960 }
1961
1962 cc_library {
1963 name: "libvndksp",
1964 srcs: ["mylib.cpp"],
1965 vendor_available: true,
1966 vndk: {
1967 enabled: true,
1968 support_system_process: true,
1969 },
1970 system_shared_libs: [],
1971 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001972 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001973 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001974 `+vndkLibrariesTxtFiles("current"))
Jooyung Han344d5432019-08-23 11:17:39 +09001975
Jooyung Hana57af4a2020-01-23 05:36:59 +00001976 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001977 "lib/libvndk.so",
1978 "lib/libvndksp.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09001979 "lib/libc++.so",
Jooyung Han31c470b2019-10-18 16:26:59 +09001980 "lib64/libvndk.so",
1981 "lib64/libvndksp.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09001982 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001983 "etc/llndk.libraries.VER.txt",
1984 "etc/vndkcore.libraries.VER.txt",
1985 "etc/vndksp.libraries.VER.txt",
1986 "etc/vndkprivate.libraries.VER.txt",
Jooyung Han31c470b2019-10-18 16:26:59 +09001987 })
Jooyung Han344d5432019-08-23 11:17:39 +09001988}
1989
1990func TestVndkApexWithPrebuilt(t *testing.T) {
1991 ctx, _ := testApex(t, `
1992 apex_vndk {
1993 name: "myapex",
1994 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001995 }
1996
1997 apex_key {
1998 name: "myapex.key",
1999 public_key: "testkey.avbpubkey",
2000 private_key: "testkey.pem",
2001 }
2002
2003 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09002004 name: "libvndk",
2005 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09002006 vendor_available: true,
2007 vndk: {
2008 enabled: true,
2009 },
2010 system_shared_libs: [],
2011 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002012 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002013 }
Jooyung Han31c470b2019-10-18 16:26:59 +09002014
2015 cc_prebuilt_library_shared {
2016 name: "libvndk.arm",
2017 srcs: ["libvndk.arm.so"],
2018 vendor_available: true,
2019 vndk: {
2020 enabled: true,
2021 },
2022 enabled: false,
2023 arch: {
2024 arm: {
2025 enabled: true,
2026 },
2027 },
2028 system_shared_libs: [],
2029 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002030 apex_available: [ "myapex" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002031 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002032 `+vndkLibrariesTxtFiles("current"),
2033 withFiles(map[string][]byte{
2034 "libvndk.so": nil,
2035 "libvndk.arm.so": nil,
2036 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002037
Jooyung Hana57af4a2020-01-23 05:36:59 +00002038 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002039 "lib/libvndk.so",
2040 "lib/libvndk.arm.so",
2041 "lib64/libvndk.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09002042 "lib/libc++.so",
2043 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002044 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002045 })
Jooyung Han344d5432019-08-23 11:17:39 +09002046}
2047
Jooyung Han39edb6c2019-11-06 16:53:07 +09002048func vndkLibrariesTxtFiles(vers ...string) (result string) {
2049 for _, v := range vers {
2050 if v == "current" {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +09002051 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002052 result += `
2053 vndk_libraries_txt {
2054 name: "` + txt + `.libraries.txt",
2055 }
2056 `
2057 }
2058 } else {
2059 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
2060 result += `
2061 prebuilt_etc {
2062 name: "` + txt + `.libraries.` + v + `.txt",
2063 src: "dummy.txt",
2064 }
2065 `
2066 }
2067 }
2068 }
2069 return
2070}
2071
Jooyung Han344d5432019-08-23 11:17:39 +09002072func TestVndkApexVersion(t *testing.T) {
2073 ctx, _ := testApex(t, `
2074 apex_vndk {
2075 name: "myapex_v27",
2076 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002077 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002078 vndk_version: "27",
2079 }
2080
2081 apex_key {
2082 name: "myapex.key",
2083 public_key: "testkey.avbpubkey",
2084 private_key: "testkey.pem",
2085 }
2086
Jooyung Han31c470b2019-10-18 16:26:59 +09002087 vndk_prebuilt_shared {
2088 name: "libvndk27",
2089 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09002090 vendor_available: true,
2091 vndk: {
2092 enabled: true,
2093 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002094 target_arch: "arm64",
2095 arch: {
2096 arm: {
2097 srcs: ["libvndk27_arm.so"],
2098 },
2099 arm64: {
2100 srcs: ["libvndk27_arm64.so"],
2101 },
2102 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002103 apex_available: [ "myapex_v27" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002104 }
2105
2106 vndk_prebuilt_shared {
2107 name: "libvndk27",
2108 version: "27",
2109 vendor_available: true,
2110 vndk: {
2111 enabled: true,
2112 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002113 target_arch: "x86_64",
2114 arch: {
2115 x86: {
2116 srcs: ["libvndk27_x86.so"],
2117 },
2118 x86_64: {
2119 srcs: ["libvndk27_x86_64.so"],
2120 },
2121 },
Jooyung Han39edb6c2019-11-06 16:53:07 +09002122 }
2123 `+vndkLibrariesTxtFiles("27"),
2124 withFiles(map[string][]byte{
2125 "libvndk27_arm.so": nil,
2126 "libvndk27_arm64.so": nil,
2127 "libvndk27_x86.so": nil,
2128 "libvndk27_x86_64.so": nil,
2129 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002130
Jooyung Hana57af4a2020-01-23 05:36:59 +00002131 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002132 "lib/libvndk27_arm.so",
2133 "lib64/libvndk27_arm64.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002134 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002135 })
Jooyung Han344d5432019-08-23 11:17:39 +09002136}
2137
2138func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
2139 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
2140 apex_vndk {
2141 name: "myapex_v27",
2142 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002143 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002144 vndk_version: "27",
2145 }
2146 apex_vndk {
2147 name: "myapex_v27_other",
2148 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002149 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002150 vndk_version: "27",
2151 }
2152
2153 apex_key {
2154 name: "myapex.key",
2155 public_key: "testkey.avbpubkey",
2156 private_key: "testkey.pem",
2157 }
2158
2159 cc_library {
2160 name: "libvndk",
2161 srcs: ["mylib.cpp"],
2162 vendor_available: true,
2163 vndk: {
2164 enabled: true,
2165 },
2166 system_shared_libs: [],
2167 stl: "none",
2168 }
2169
2170 vndk_prebuilt_shared {
2171 name: "libvndk",
2172 version: "27",
2173 vendor_available: true,
2174 vndk: {
2175 enabled: true,
2176 },
2177 srcs: ["libvndk.so"],
2178 }
2179 `, withFiles(map[string][]byte{
2180 "libvndk.so": nil,
2181 }))
2182}
2183
Jooyung Han90eee022019-10-01 20:02:42 +09002184func TestVndkApexNameRule(t *testing.T) {
2185 ctx, _ := testApex(t, `
2186 apex_vndk {
2187 name: "myapex",
2188 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002189 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002190 }
2191 apex_vndk {
2192 name: "myapex_v28",
2193 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002194 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002195 vndk_version: "28",
2196 }
2197 apex_key {
2198 name: "myapex.key",
2199 public_key: "testkey.avbpubkey",
2200 private_key: "testkey.pem",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002201 }`+vndkLibrariesTxtFiles("28", "current"))
Jooyung Han90eee022019-10-01 20:02:42 +09002202
2203 assertApexName := func(expected, moduleName string) {
Jooyung Hana57af4a2020-01-23 05:36:59 +00002204 bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09002205 actual := proptools.String(bundle.properties.Apex_name)
2206 if !reflect.DeepEqual(actual, expected) {
2207 t.Errorf("Got '%v', expected '%v'", actual, expected)
2208 }
2209 }
2210
2211 assertApexName("com.android.vndk.vVER", "myapex")
2212 assertApexName("com.android.vndk.v28", "myapex_v28")
2213}
2214
Jooyung Han344d5432019-08-23 11:17:39 +09002215func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
2216 ctx, _ := testApex(t, `
2217 apex_vndk {
2218 name: "myapex",
2219 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002220 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002221 }
2222
2223 apex_key {
2224 name: "myapex.key",
2225 public_key: "testkey.avbpubkey",
2226 private_key: "testkey.pem",
2227 }
2228
2229 cc_library {
2230 name: "libvndk",
2231 srcs: ["mylib.cpp"],
2232 vendor_available: true,
2233 native_bridge_supported: true,
2234 host_supported: true,
2235 vndk: {
2236 enabled: true,
2237 },
2238 system_shared_libs: [],
2239 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002240 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002241 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002242 `+vndkLibrariesTxtFiles("current"),
2243 withTargets(map[android.OsType][]android.Target{
2244 android.Android: []android.Target{
2245 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2246 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2247 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
2248 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
2249 },
2250 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002251
Jooyung Hana57af4a2020-01-23 05:36:59 +00002252 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002253 "lib/libvndk.so",
2254 "lib64/libvndk.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09002255 "lib/libc++.so",
2256 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002257 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002258 })
Jooyung Han344d5432019-08-23 11:17:39 +09002259}
2260
2261func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
2262 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
2263 apex_vndk {
2264 name: "myapex",
2265 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002266 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002267 native_bridge_supported: true,
2268 }
2269
2270 apex_key {
2271 name: "myapex.key",
2272 public_key: "testkey.avbpubkey",
2273 private_key: "testkey.pem",
2274 }
2275
2276 cc_library {
2277 name: "libvndk",
2278 srcs: ["mylib.cpp"],
2279 vendor_available: true,
2280 native_bridge_supported: true,
2281 host_supported: true,
2282 vndk: {
2283 enabled: true,
2284 },
2285 system_shared_libs: [],
2286 stl: "none",
2287 }
2288 `)
2289}
2290
Jooyung Han31c470b2019-10-18 16:26:59 +09002291func TestVndkApexWithBinder32(t *testing.T) {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002292 ctx, _ := testApex(t, `
Jooyung Han31c470b2019-10-18 16:26:59 +09002293 apex_vndk {
2294 name: "myapex_v27",
2295 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002296 file_contexts: ":myapex-file_contexts",
Jooyung Han31c470b2019-10-18 16:26:59 +09002297 vndk_version: "27",
2298 }
2299
2300 apex_key {
2301 name: "myapex.key",
2302 public_key: "testkey.avbpubkey",
2303 private_key: "testkey.pem",
2304 }
2305
2306 vndk_prebuilt_shared {
2307 name: "libvndk27",
2308 version: "27",
2309 target_arch: "arm",
2310 vendor_available: true,
2311 vndk: {
2312 enabled: true,
2313 },
2314 arch: {
2315 arm: {
2316 srcs: ["libvndk27.so"],
2317 }
2318 },
2319 }
2320
2321 vndk_prebuilt_shared {
2322 name: "libvndk27",
2323 version: "27",
2324 target_arch: "arm",
2325 binder32bit: true,
2326 vendor_available: true,
2327 vndk: {
2328 enabled: true,
2329 },
2330 arch: {
2331 arm: {
2332 srcs: ["libvndk27binder32.so"],
2333 }
2334 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002335 apex_available: [ "myapex_v27" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002336 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002337 `+vndkLibrariesTxtFiles("27"),
Jooyung Han31c470b2019-10-18 16:26:59 +09002338 withFiles(map[string][]byte{
2339 "libvndk27.so": nil,
2340 "libvndk27binder32.so": nil,
2341 }),
2342 withBinder32bit,
2343 withTargets(map[android.OsType][]android.Target{
2344 android.Android: []android.Target{
2345 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2346 },
2347 }),
2348 )
2349
Jooyung Hana57af4a2020-01-23 05:36:59 +00002350 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002351 "lib/libvndk27binder32.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002352 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002353 })
2354}
2355
Jooyung Hane1633032019-08-01 17:41:43 +09002356func TestDependenciesInApexManifest(t *testing.T) {
2357 ctx, _ := testApex(t, `
2358 apex {
2359 name: "myapex_nodep",
2360 key: "myapex.key",
2361 native_shared_libs: ["lib_nodep"],
2362 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002363 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002364 }
2365
2366 apex {
2367 name: "myapex_dep",
2368 key: "myapex.key",
2369 native_shared_libs: ["lib_dep"],
2370 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002371 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002372 }
2373
2374 apex {
2375 name: "myapex_provider",
2376 key: "myapex.key",
2377 native_shared_libs: ["libfoo"],
2378 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002379 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002380 }
2381
2382 apex {
2383 name: "myapex_selfcontained",
2384 key: "myapex.key",
2385 native_shared_libs: ["lib_dep", "libfoo"],
2386 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002387 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002388 }
2389
2390 apex_key {
2391 name: "myapex.key",
2392 public_key: "testkey.avbpubkey",
2393 private_key: "testkey.pem",
2394 }
2395
2396 cc_library {
2397 name: "lib_nodep",
2398 srcs: ["mylib.cpp"],
2399 system_shared_libs: [],
2400 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002401 apex_available: [ "myapex_nodep" ],
Jooyung Hane1633032019-08-01 17:41:43 +09002402 }
2403
2404 cc_library {
2405 name: "lib_dep",
2406 srcs: ["mylib.cpp"],
2407 shared_libs: ["libfoo"],
2408 system_shared_libs: [],
2409 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002410 apex_available: [
2411 "myapex_dep",
2412 "myapex_provider",
2413 "myapex_selfcontained",
2414 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002415 }
2416
2417 cc_library {
2418 name: "libfoo",
2419 srcs: ["mytest.cpp"],
2420 stubs: {
2421 versions: ["1"],
2422 },
2423 system_shared_libs: [],
2424 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002425 apex_available: [
2426 "myapex_provider",
2427 "myapex_selfcontained",
2428 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002429 }
2430 `)
2431
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002432 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09002433 var provideNativeLibs, requireNativeLibs []string
2434
Sundong Ahnabb64432019-10-22 13:58:29 +09002435 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002436 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2437 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002438 ensureListEmpty(t, provideNativeLibs)
2439 ensureListEmpty(t, requireNativeLibs)
2440
Sundong Ahnabb64432019-10-22 13:58:29 +09002441 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002442 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2443 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002444 ensureListEmpty(t, provideNativeLibs)
2445 ensureListContains(t, requireNativeLibs, "libfoo.so")
2446
Sundong Ahnabb64432019-10-22 13:58:29 +09002447 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002448 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2449 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002450 ensureListContains(t, provideNativeLibs, "libfoo.so")
2451 ensureListEmpty(t, requireNativeLibs)
2452
Sundong Ahnabb64432019-10-22 13:58:29 +09002453 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002454 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2455 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002456 ensureListContains(t, provideNativeLibs, "libfoo.so")
2457 ensureListEmpty(t, requireNativeLibs)
2458}
2459
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002460func TestApexName(t *testing.T) {
Jiyong Parkdb334862020-02-05 17:19:28 +09002461 ctx, config := testApex(t, `
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002462 apex {
2463 name: "myapex",
2464 key: "myapex.key",
2465 apex_name: "com.android.myapex",
Jiyong Parkdb334862020-02-05 17:19:28 +09002466 native_shared_libs: ["mylib"],
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002467 }
2468
2469 apex_key {
2470 name: "myapex.key",
2471 public_key: "testkey.avbpubkey",
2472 private_key: "testkey.pem",
2473 }
Jiyong Parkdb334862020-02-05 17:19:28 +09002474
2475 cc_library {
2476 name: "mylib",
2477 srcs: ["mylib.cpp"],
2478 system_shared_libs: [],
2479 stl: "none",
2480 apex_available: [
2481 "//apex_available:platform",
2482 "myapex",
2483 ],
2484 }
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002485 `)
2486
Sundong Ahnabb64432019-10-22 13:58:29 +09002487 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002488 apexManifestRule := module.Rule("apexManifestRule")
2489 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
2490 apexRule := module.Rule("apexRule")
2491 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
Jiyong Parkdb334862020-02-05 17:19:28 +09002492
2493 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2494 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2495 name := apexBundle.BaseModuleName()
2496 prefix := "TARGET_"
2497 var builder strings.Builder
2498 data.Custom(&builder, name, prefix, "", data)
2499 androidMk := builder.String()
2500 ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n")
2501 ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002502}
2503
Alex Light0851b882019-02-07 13:20:53 -08002504func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002505 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002506 apex {
2507 name: "myapex",
2508 key: "myapex.key",
2509 native_shared_libs: ["mylib_common"],
2510 }
2511
2512 apex_key {
2513 name: "myapex.key",
2514 public_key: "testkey.avbpubkey",
2515 private_key: "testkey.pem",
2516 }
2517
2518 cc_library {
2519 name: "mylib_common",
2520 srcs: ["mylib.cpp"],
2521 system_shared_libs: [],
2522 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002523 apex_available: [
2524 "//apex_available:platform",
2525 "myapex",
2526 ],
Alex Light0851b882019-02-07 13:20:53 -08002527 }
2528 `)
2529
Sundong Ahnabb64432019-10-22 13:58:29 +09002530 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002531 apexRule := module.Rule("apexRule")
2532 copyCmds := apexRule.Args["copy_commands"]
2533
2534 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
2535 t.Log("Apex was a test apex!")
2536 t.Fail()
2537 }
2538 // Ensure that main rule creates an output
2539 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2540
2541 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002542 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002543
2544 // Ensure that both direct and indirect deps are copied into apex
2545 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2546
Colin Cross7113d202019-11-20 16:39:12 -08002547 // Ensure that the platform variant ends with _shared
2548 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002549
2550 if !android.InAnyApex("mylib_common") {
2551 t.Log("Found mylib_common not in any apex!")
2552 t.Fail()
2553 }
2554}
2555
2556func TestTestApex(t *testing.T) {
2557 if android.InAnyApex("mylib_common_test") {
2558 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!")
2559 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002560 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002561 apex_test {
2562 name: "myapex",
2563 key: "myapex.key",
2564 native_shared_libs: ["mylib_common_test"],
2565 }
2566
2567 apex_key {
2568 name: "myapex.key",
2569 public_key: "testkey.avbpubkey",
2570 private_key: "testkey.pem",
2571 }
2572
2573 cc_library {
2574 name: "mylib_common_test",
2575 srcs: ["mylib.cpp"],
2576 system_shared_libs: [],
2577 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002578 // TODO: remove //apex_available:platform
2579 apex_available: [
2580 "//apex_available:platform",
2581 "myapex",
2582 ],
Alex Light0851b882019-02-07 13:20:53 -08002583 }
2584 `)
2585
Sundong Ahnabb64432019-10-22 13:58:29 +09002586 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002587 apexRule := module.Rule("apexRule")
2588 copyCmds := apexRule.Args["copy_commands"]
2589
2590 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
2591 t.Log("Apex was not a test apex!")
2592 t.Fail()
2593 }
2594 // Ensure that main rule creates an output
2595 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2596
2597 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002598 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002599
2600 // Ensure that both direct and indirect deps are copied into apex
2601 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
2602
Colin Cross7113d202019-11-20 16:39:12 -08002603 // Ensure that the platform variant ends with _shared
2604 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002605}
2606
Alex Light9670d332019-01-29 18:07:33 -08002607func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002608 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08002609 apex {
2610 name: "myapex",
2611 key: "myapex.key",
2612 multilib: {
2613 first: {
2614 native_shared_libs: ["mylib_common"],
2615 }
2616 },
2617 target: {
2618 android: {
2619 multilib: {
2620 first: {
2621 native_shared_libs: ["mylib"],
2622 }
2623 }
2624 },
2625 host: {
2626 multilib: {
2627 first: {
2628 native_shared_libs: ["mylib2"],
2629 }
2630 }
2631 }
2632 }
2633 }
2634
2635 apex_key {
2636 name: "myapex.key",
2637 public_key: "testkey.avbpubkey",
2638 private_key: "testkey.pem",
2639 }
2640
2641 cc_library {
2642 name: "mylib",
2643 srcs: ["mylib.cpp"],
2644 system_shared_libs: [],
2645 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002646 // TODO: remove //apex_available:platform
2647 apex_available: [
2648 "//apex_available:platform",
2649 "myapex",
2650 ],
Alex Light9670d332019-01-29 18:07:33 -08002651 }
2652
2653 cc_library {
2654 name: "mylib_common",
2655 srcs: ["mylib.cpp"],
2656 system_shared_libs: [],
2657 stl: "none",
2658 compile_multilib: "first",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002659 // TODO: remove //apex_available:platform
2660 apex_available: [
2661 "//apex_available:platform",
2662 "myapex",
2663 ],
Alex Light9670d332019-01-29 18:07:33 -08002664 }
2665
2666 cc_library {
2667 name: "mylib2",
2668 srcs: ["mylib.cpp"],
2669 system_shared_libs: [],
2670 stl: "none",
2671 compile_multilib: "first",
2672 }
2673 `)
2674
Sundong Ahnabb64432019-10-22 13:58:29 +09002675 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002676 copyCmds := apexRule.Args["copy_commands"]
2677
2678 // Ensure that main rule creates an output
2679 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2680
2681 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002682 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2683 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
2684 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light9670d332019-01-29 18:07:33 -08002685
2686 // Ensure that both direct and indirect deps are copied into apex
2687 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2688 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2689 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2690
Colin Cross7113d202019-11-20 16:39:12 -08002691 // Ensure that the platform variant ends with _shared
2692 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
2693 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
2694 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Alex Light9670d332019-01-29 18:07:33 -08002695}
Jiyong Park04480cf2019-02-06 00:16:29 +09002696
2697func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002698 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002699 apex {
2700 name: "myapex",
2701 key: "myapex.key",
2702 binaries: ["myscript"],
2703 }
2704
2705 apex_key {
2706 name: "myapex.key",
2707 public_key: "testkey.avbpubkey",
2708 private_key: "testkey.pem",
2709 }
2710
2711 sh_binary {
2712 name: "myscript",
2713 src: "mylib.cpp",
2714 filename: "myscript.sh",
2715 sub_dir: "script",
2716 }
2717 `)
2718
Sundong Ahnabb64432019-10-22 13:58:29 +09002719 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002720 copyCmds := apexRule.Args["copy_commands"]
2721
2722 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2723}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002724
Jooyung Han91df2082019-11-20 01:49:42 +09002725func TestApexInVariousPartition(t *testing.T) {
2726 testcases := []struct {
2727 propName, parition, flattenedPartition string
2728 }{
2729 {"", "system", "system_ext"},
2730 {"product_specific: true", "product", "product"},
2731 {"soc_specific: true", "vendor", "vendor"},
2732 {"proprietary: true", "vendor", "vendor"},
2733 {"vendor: true", "vendor", "vendor"},
2734 {"system_ext_specific: true", "system_ext", "system_ext"},
2735 }
2736 for _, tc := range testcases {
2737 t.Run(tc.propName+":"+tc.parition, func(t *testing.T) {
2738 ctx, _ := testApex(t, `
2739 apex {
2740 name: "myapex",
2741 key: "myapex.key",
2742 `+tc.propName+`
2743 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002744
Jooyung Han91df2082019-11-20 01:49:42 +09002745 apex_key {
2746 name: "myapex.key",
2747 public_key: "testkey.avbpubkey",
2748 private_key: "testkey.pem",
2749 }
2750 `)
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002751
Jooyung Han91df2082019-11-20 01:49:42 +09002752 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2753 expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex"
2754 actual := apex.installDir.String()
2755 if actual != expected {
2756 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2757 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002758
Jooyung Han91df2082019-11-20 01:49:42 +09002759 flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
2760 expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex"
2761 actual = flattened.installDir.String()
2762 if actual != expected {
2763 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2764 }
2765 })
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002766 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002767}
Jiyong Park67882562019-03-21 01:11:21 +09002768
Jooyung Han54aca7b2019-11-20 02:26:02 +09002769func TestFileContexts(t *testing.T) {
2770 ctx, _ := testApex(t, `
2771 apex {
2772 name: "myapex",
2773 key: "myapex.key",
2774 }
2775
2776 apex_key {
2777 name: "myapex.key",
2778 public_key: "testkey.avbpubkey",
2779 private_key: "testkey.pem",
2780 }
2781 `)
2782 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
2783 apexRule := module.Rule("apexRule")
2784 actual := apexRule.Args["file_contexts"]
2785 expected := "system/sepolicy/apex/myapex-file_contexts"
2786 if actual != expected {
2787 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2788 }
2789
2790 testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
2791 apex {
2792 name: "myapex",
2793 key: "myapex.key",
2794 file_contexts: "my_own_file_contexts",
2795 }
2796
2797 apex_key {
2798 name: "myapex.key",
2799 public_key: "testkey.avbpubkey",
2800 private_key: "testkey.pem",
2801 }
2802 `, withFiles(map[string][]byte{
2803 "my_own_file_contexts": nil,
2804 }))
2805
2806 testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
2807 apex {
2808 name: "myapex",
2809 key: "myapex.key",
2810 product_specific: true,
2811 file_contexts: "product_specific_file_contexts",
2812 }
2813
2814 apex_key {
2815 name: "myapex.key",
2816 public_key: "testkey.avbpubkey",
2817 private_key: "testkey.pem",
2818 }
2819 `)
2820
2821 ctx, _ = testApex(t, `
2822 apex {
2823 name: "myapex",
2824 key: "myapex.key",
2825 product_specific: true,
2826 file_contexts: "product_specific_file_contexts",
2827 }
2828
2829 apex_key {
2830 name: "myapex.key",
2831 public_key: "testkey.avbpubkey",
2832 private_key: "testkey.pem",
2833 }
2834 `, withFiles(map[string][]byte{
2835 "product_specific_file_contexts": nil,
2836 }))
2837 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2838 apexRule = module.Rule("apexRule")
2839 actual = apexRule.Args["file_contexts"]
2840 expected = "product_specific_file_contexts"
2841 if actual != expected {
2842 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2843 }
2844
2845 ctx, _ = testApex(t, `
2846 apex {
2847 name: "myapex",
2848 key: "myapex.key",
2849 product_specific: true,
2850 file_contexts: ":my-file-contexts",
2851 }
2852
2853 apex_key {
2854 name: "myapex.key",
2855 public_key: "testkey.avbpubkey",
2856 private_key: "testkey.pem",
2857 }
2858
2859 filegroup {
2860 name: "my-file-contexts",
2861 srcs: ["product_specific_file_contexts"],
2862 }
2863 `, withFiles(map[string][]byte{
2864 "product_specific_file_contexts": nil,
2865 }))
2866 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2867 apexRule = module.Rule("apexRule")
2868 actual = apexRule.Args["file_contexts"]
2869 expected = "product_specific_file_contexts"
2870 if actual != expected {
2871 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2872 }
2873}
2874
Jiyong Park67882562019-03-21 01:11:21 +09002875func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002876 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002877 apex_key {
2878 name: "myapex.key",
2879 public_key: ":my.avbpubkey",
2880 private_key: ":my.pem",
2881 product_specific: true,
2882 }
2883
2884 filegroup {
2885 name: "my.avbpubkey",
2886 srcs: ["testkey2.avbpubkey"],
2887 }
2888
2889 filegroup {
2890 name: "my.pem",
2891 srcs: ["testkey2.pem"],
2892 }
2893 `)
2894
2895 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2896 expected_pubkey := "testkey2.avbpubkey"
2897 actual_pubkey := apex_key.public_key_file.String()
2898 if actual_pubkey != expected_pubkey {
2899 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2900 }
2901 expected_privkey := "testkey2.pem"
2902 actual_privkey := apex_key.private_key_file.String()
2903 if actual_privkey != expected_privkey {
2904 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2905 }
2906}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002907
2908func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002909 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002910 prebuilt_apex {
2911 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002912 arch: {
2913 arm64: {
2914 src: "myapex-arm64.apex",
2915 },
2916 arm: {
2917 src: "myapex-arm.apex",
2918 },
2919 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002920 }
2921 `)
2922
2923 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2924
Jiyong Parkc95714e2019-03-29 14:23:10 +09002925 expectedInput := "myapex-arm64.apex"
2926 if prebuilt.inputApex.String() != expectedInput {
2927 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2928 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002929}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002930
2931func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002932 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002933 prebuilt_apex {
2934 name: "myapex",
2935 src: "myapex-arm.apex",
2936 filename: "notmyapex.apex",
2937 }
2938 `)
2939
2940 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2941
2942 expected := "notmyapex.apex"
2943 if p.installFilename != expected {
2944 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2945 }
2946}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002947
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002948func TestPrebuiltOverrides(t *testing.T) {
2949 ctx, config := testApex(t, `
2950 prebuilt_apex {
2951 name: "myapex.prebuilt",
2952 src: "myapex-arm.apex",
2953 overrides: [
2954 "myapex",
2955 ],
2956 }
2957 `)
2958
2959 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2960
2961 expected := []string{"myapex"}
Jiyong Park0b0e1b92019-12-03 13:24:29 +09002962 actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002963 if !reflect.DeepEqual(actual, expected) {
Jiyong Parkb0a012c2019-11-14 17:17:03 +09002964 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002965 }
2966}
2967
Roland Levillain630846d2019-06-26 12:48:34 +01002968func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002969 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002970 apex_test {
2971 name: "myapex",
2972 key: "myapex.key",
2973 tests: [
2974 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002975 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002976 ],
2977 }
2978
2979 apex_key {
2980 name: "myapex.key",
2981 public_key: "testkey.avbpubkey",
2982 private_key: "testkey.pem",
2983 }
2984
2985 cc_test {
2986 name: "mytest",
2987 gtest: false,
2988 srcs: ["mytest.cpp"],
2989 relative_install_path: "test",
2990 system_shared_libs: [],
2991 static_executable: true,
2992 stl: "none",
2993 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002994
2995 cc_test {
2996 name: "mytests",
2997 gtest: false,
2998 srcs: [
2999 "mytest1.cpp",
3000 "mytest2.cpp",
3001 "mytest3.cpp",
3002 ],
3003 test_per_src: true,
3004 relative_install_path: "test",
3005 system_shared_libs: [],
3006 static_executable: true,
3007 stl: "none",
3008 }
Roland Levillain630846d2019-06-26 12:48:34 +01003009 `)
3010
Sundong Ahnabb64432019-10-22 13:58:29 +09003011 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01003012 copyCmds := apexRule.Args["copy_commands"]
3013
3014 // Ensure that test dep is copied into apex.
3015 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01003016
3017 // Ensure that test deps built with `test_per_src` are copied into apex.
3018 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
3019 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
3020 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01003021
3022 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09003023 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01003024 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3025 name := apexBundle.BaseModuleName()
3026 prefix := "TARGET_"
3027 var builder strings.Builder
3028 data.Custom(&builder, name, prefix, "", data)
3029 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09003030 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
3031 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
3032 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
3033 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
Jooyung Han214bf372019-11-12 13:03:50 +09003034 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
Jooyung Han31c470b2019-10-18 16:26:59 +09003035 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01003036 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01003037}
3038
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003039func TestInstallExtraFlattenedApexes(t *testing.T) {
3040 ctx, config := testApex(t, `
3041 apex {
3042 name: "myapex",
3043 key: "myapex.key",
3044 }
3045 apex_key {
3046 name: "myapex.key",
3047 public_key: "testkey.avbpubkey",
3048 private_key: "testkey.pem",
3049 }
3050 `, func(fs map[string][]byte, config android.Config) {
3051 config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
3052 })
3053 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Jiyong Park83dc74b2020-01-14 18:38:44 +09003054 ensureListContains(t, ab.requiredDeps, "myapex.flattened")
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003055 mk := android.AndroidMkDataForTest(t, config, "", ab)
3056 var builder strings.Builder
3057 mk.Custom(&builder, ab.Name(), "TARGET_", "", mk)
3058 androidMk := builder.String()
3059 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened")
3060}
3061
Jooyung Han5c998b92019-06-27 11:30:33 +09003062func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003063 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09003064 apex {
3065 name: "myapex",
3066 key: "myapex.key",
3067 native_shared_libs: ["mylib"],
3068 uses: ["commonapex"],
3069 }
3070
3071 apex {
3072 name: "commonapex",
3073 key: "myapex.key",
3074 native_shared_libs: ["libcommon"],
3075 provide_cpp_shared_libs: true,
3076 }
3077
3078 apex_key {
3079 name: "myapex.key",
3080 public_key: "testkey.avbpubkey",
3081 private_key: "testkey.pem",
3082 }
3083
3084 cc_library {
3085 name: "mylib",
3086 srcs: ["mylib.cpp"],
3087 shared_libs: ["libcommon"],
3088 system_shared_libs: [],
3089 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003090 apex_available: [ "myapex" ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003091 }
3092
3093 cc_library {
3094 name: "libcommon",
3095 srcs: ["mylib_common.cpp"],
3096 system_shared_libs: [],
3097 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003098 // TODO: remove //apex_available:platform
3099 apex_available: [
3100 "//apex_available:platform",
3101 "commonapex",
3102 "myapex",
3103 ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003104 }
3105 `)
3106
Sundong Ahnabb64432019-10-22 13:58:29 +09003107 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003108 apexRule1 := module1.Rule("apexRule")
3109 copyCmds1 := apexRule1.Args["copy_commands"]
3110
Sundong Ahnabb64432019-10-22 13:58:29 +09003111 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003112 apexRule2 := module2.Rule("apexRule")
3113 copyCmds2 := apexRule2.Args["copy_commands"]
3114
Colin Cross7113d202019-11-20 16:39:12 -08003115 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
3116 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex")
Jooyung Han5c998b92019-06-27 11:30:33 +09003117 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
3118 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
3119 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
3120}
3121
3122func TestApexUsesFailsIfNotProvided(t *testing.T) {
3123 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
3124 apex {
3125 name: "myapex",
3126 key: "myapex.key",
3127 uses: ["commonapex"],
3128 }
3129
3130 apex {
3131 name: "commonapex",
3132 key: "myapex.key",
3133 }
3134
3135 apex_key {
3136 name: "myapex.key",
3137 public_key: "testkey.avbpubkey",
3138 private_key: "testkey.pem",
3139 }
3140 `)
3141 testApexError(t, `uses: "commonapex" is not a provider`, `
3142 apex {
3143 name: "myapex",
3144 key: "myapex.key",
3145 uses: ["commonapex"],
3146 }
3147
3148 cc_library {
3149 name: "commonapex",
3150 system_shared_libs: [],
3151 stl: "none",
3152 }
3153
3154 apex_key {
3155 name: "myapex.key",
3156 public_key: "testkey.avbpubkey",
3157 private_key: "testkey.pem",
3158 }
3159 `)
3160}
3161
3162func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
3163 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
3164 apex {
3165 name: "myapex",
3166 key: "myapex.key",
3167 use_vendor: true,
3168 uses: ["commonapex"],
3169 }
3170
3171 apex {
3172 name: "commonapex",
3173 key: "myapex.key",
3174 provide_cpp_shared_libs: true,
3175 }
3176
3177 apex_key {
3178 name: "myapex.key",
3179 public_key: "testkey.avbpubkey",
3180 private_key: "testkey.pem",
3181 }
Jooyung Handc782442019-11-01 03:14:38 +09003182 `, func(fs map[string][]byte, config android.Config) {
3183 setUseVendorWhitelistForTest(config, []string{"myapex"})
3184 })
Jooyung Han5c998b92019-06-27 11:30:33 +09003185}
3186
Jooyung Hand48f3c32019-08-23 11:18:57 +09003187func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
3188 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
3189 apex {
3190 name: "myapex",
3191 key: "myapex.key",
3192 native_shared_libs: ["libfoo"],
3193 }
3194
3195 apex_key {
3196 name: "myapex.key",
3197 public_key: "testkey.avbpubkey",
3198 private_key: "testkey.pem",
3199 }
3200
3201 cc_library {
3202 name: "libfoo",
3203 stl: "none",
3204 system_shared_libs: [],
3205 enabled: false,
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003206 apex_available: ["myapex"],
Jooyung Hand48f3c32019-08-23 11:18:57 +09003207 }
3208 `)
3209 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
3210 apex {
3211 name: "myapex",
3212 key: "myapex.key",
3213 java_libs: ["myjar"],
3214 }
3215
3216 apex_key {
3217 name: "myapex.key",
3218 public_key: "testkey.avbpubkey",
3219 private_key: "testkey.pem",
3220 }
3221
3222 java_library {
3223 name: "myjar",
3224 srcs: ["foo/bar/MyClass.java"],
3225 sdk_version: "none",
3226 system_modules: "none",
Jooyung Hand48f3c32019-08-23 11:18:57 +09003227 enabled: false,
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003228 apex_available: ["myapex"],
Jooyung Hand48f3c32019-08-23 11:18:57 +09003229 }
3230 `)
3231}
3232
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003233func TestApexWithApps(t *testing.T) {
3234 ctx, _ := testApex(t, `
3235 apex {
3236 name: "myapex",
3237 key: "myapex.key",
3238 apps: [
3239 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09003240 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003241 ],
3242 }
3243
3244 apex_key {
3245 name: "myapex.key",
3246 public_key: "testkey.avbpubkey",
3247 private_key: "testkey.pem",
3248 }
3249
3250 android_app {
3251 name: "AppFoo",
3252 srcs: ["foo/bar/MyClass.java"],
3253 sdk_version: "none",
3254 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09003255 jni_libs: ["libjni"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003256 apex_available: [ "myapex" ],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003257 }
Jiyong Parkf7487312019-10-17 12:54:30 +09003258
3259 android_app {
3260 name: "AppFooPriv",
3261 srcs: ["foo/bar/MyClass.java"],
3262 sdk_version: "none",
3263 system_modules: "none",
3264 privileged: true,
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003265 apex_available: [ "myapex" ],
Jiyong Parkf7487312019-10-17 12:54:30 +09003266 }
Jiyong Park8be103b2019-11-08 15:53:48 +09003267
3268 cc_library_shared {
3269 name: "libjni",
3270 srcs: ["mylib.cpp"],
Jooyung Han65041792020-02-25 16:59:29 +09003271 shared_libs: ["libfoo"],
Jiyong Park8be103b2019-11-08 15:53:48 +09003272 stl: "none",
3273 system_shared_libs: [],
Jiyong Park0f80c182020-01-31 02:49:53 +09003274 apex_available: [ "myapex" ],
Jooyung Han65041792020-02-25 16:59:29 +09003275 sdk_version: "current",
3276 }
3277
3278 cc_library_shared {
3279 name: "libfoo",
3280 stl: "none",
3281 system_shared_libs: [],
3282 apex_available: [ "myapex" ],
3283 sdk_version: "current",
Jiyong Park8be103b2019-11-08 15:53:48 +09003284 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003285 `)
3286
Sundong Ahnabb64432019-10-22 13:58:29 +09003287 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003288 apexRule := module.Rule("apexRule")
3289 copyCmds := apexRule.Args["copy_commands"]
3290
3291 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09003292 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003293
Jooyung Han65041792020-02-25 16:59:29 +09003294 appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs")
3295 // JNI libraries are uncompressed
Jiyong Park52cd06f2019-11-11 10:14:32 +09003296 if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
Jooyung Han65041792020-02-25 16:59:29 +09003297 t.Errorf("jni libs are not uncompressed for AppFoo")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003298 }
Jooyung Han65041792020-02-25 16:59:29 +09003299 // JNI libraries including transitive deps are
3300 for _, jni := range []string{"libjni", "libfoo"} {
3301 jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile()
3302 // ... embedded inside APK (jnilibs.zip)
3303 ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String())
3304 // ... and not directly inside the APEX
3305 ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so")
3306 }
Dario Frenicde2a032019-10-27 00:29:22 +01003307}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003308
Dario Frenicde2a032019-10-27 00:29:22 +01003309func TestApexWithAppImports(t *testing.T) {
3310 ctx, _ := testApex(t, `
3311 apex {
3312 name: "myapex",
3313 key: "myapex.key",
3314 apps: [
3315 "AppFooPrebuilt",
3316 "AppFooPrivPrebuilt",
3317 ],
3318 }
3319
3320 apex_key {
3321 name: "myapex.key",
3322 public_key: "testkey.avbpubkey",
3323 private_key: "testkey.pem",
3324 }
3325
3326 android_app_import {
3327 name: "AppFooPrebuilt",
3328 apk: "PrebuiltAppFoo.apk",
3329 presigned: true,
3330 dex_preopt: {
3331 enabled: false,
3332 },
3333 }
3334
3335 android_app_import {
3336 name: "AppFooPrivPrebuilt",
3337 apk: "PrebuiltAppFooPriv.apk",
3338 privileged: true,
3339 presigned: true,
3340 dex_preopt: {
3341 enabled: false,
3342 },
3343 }
3344 `)
3345
Sundong Ahnabb64432019-10-22 13:58:29 +09003346 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01003347 apexRule := module.Rule("apexRule")
3348 copyCmds := apexRule.Args["copy_commands"]
3349
3350 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
3351 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003352}
3353
Dario Freni6f3937c2019-12-20 22:58:03 +00003354func TestApexWithTestHelperApp(t *testing.T) {
3355 ctx, _ := testApex(t, `
3356 apex {
3357 name: "myapex",
3358 key: "myapex.key",
3359 apps: [
3360 "TesterHelpAppFoo",
3361 ],
3362 }
3363
3364 apex_key {
3365 name: "myapex.key",
3366 public_key: "testkey.avbpubkey",
3367 private_key: "testkey.pem",
3368 }
3369
3370 android_test_helper_app {
3371 name: "TesterHelpAppFoo",
3372 srcs: ["foo/bar/MyClass.java"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003373 apex_available: [ "myapex" ],
Dario Freni6f3937c2019-12-20 22:58:03 +00003374 }
3375
3376 `)
3377
3378 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3379 apexRule := module.Rule("apexRule")
3380 copyCmds := apexRule.Args["copy_commands"]
3381
3382 ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk")
3383}
3384
Jooyung Han18020ea2019-11-13 10:50:48 +09003385func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
3386 // libfoo's apex_available comes from cc_defaults
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003387 testApexError(t, `requires "libfoo" that is not available for the APEX`, `
Jooyung Han18020ea2019-11-13 10:50:48 +09003388 apex {
3389 name: "myapex",
3390 key: "myapex.key",
3391 native_shared_libs: ["libfoo"],
3392 }
3393
3394 apex_key {
3395 name: "myapex.key",
3396 public_key: "testkey.avbpubkey",
3397 private_key: "testkey.pem",
3398 }
3399
3400 apex {
3401 name: "otherapex",
3402 key: "myapex.key",
3403 native_shared_libs: ["libfoo"],
3404 }
3405
3406 cc_defaults {
3407 name: "libfoo-defaults",
3408 apex_available: ["otherapex"],
3409 }
3410
3411 cc_library {
3412 name: "libfoo",
3413 defaults: ["libfoo-defaults"],
3414 stl: "none",
3415 system_shared_libs: [],
3416 }`)
3417}
3418
Jiyong Park127b40b2019-09-30 16:04:35 +09003419func TestApexAvailable(t *testing.T) {
3420 // libfoo is not available to myapex, but only to otherapex
3421 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
3422 apex {
3423 name: "myapex",
3424 key: "myapex.key",
3425 native_shared_libs: ["libfoo"],
3426 }
3427
3428 apex_key {
3429 name: "myapex.key",
3430 public_key: "testkey.avbpubkey",
3431 private_key: "testkey.pem",
3432 }
3433
3434 apex {
3435 name: "otherapex",
3436 key: "otherapex.key",
3437 native_shared_libs: ["libfoo"],
3438 }
3439
3440 apex_key {
3441 name: "otherapex.key",
3442 public_key: "testkey.avbpubkey",
3443 private_key: "testkey.pem",
3444 }
3445
3446 cc_library {
3447 name: "libfoo",
3448 stl: "none",
3449 system_shared_libs: [],
3450 apex_available: ["otherapex"],
3451 }`)
3452
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003453 // libbbaz is an indirect dep
3454 testApexError(t, "requires \"libbaz\" that is not available for the APEX", `
Jiyong Park127b40b2019-09-30 16:04:35 +09003455 apex {
3456 name: "myapex",
3457 key: "myapex.key",
3458 native_shared_libs: ["libfoo"],
3459 }
3460
3461 apex_key {
3462 name: "myapex.key",
3463 public_key: "testkey.avbpubkey",
3464 private_key: "testkey.pem",
3465 }
3466
Jiyong Park127b40b2019-09-30 16:04:35 +09003467 cc_library {
3468 name: "libfoo",
3469 stl: "none",
3470 shared_libs: ["libbar"],
3471 system_shared_libs: [],
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003472 apex_available: ["myapex"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003473 }
3474
3475 cc_library {
3476 name: "libbar",
3477 stl: "none",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003478 shared_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003479 system_shared_libs: [],
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003480 apex_available: ["myapex"],
3481 }
3482
3483 cc_library {
3484 name: "libbaz",
3485 stl: "none",
3486 system_shared_libs: [],
Jiyong Park127b40b2019-09-30 16:04:35 +09003487 }`)
3488
3489 testApexError(t, "\"otherapex\" is not a valid module name", `
3490 apex {
3491 name: "myapex",
3492 key: "myapex.key",
3493 native_shared_libs: ["libfoo"],
3494 }
3495
3496 apex_key {
3497 name: "myapex.key",
3498 public_key: "testkey.avbpubkey",
3499 private_key: "testkey.pem",
3500 }
3501
3502 cc_library {
3503 name: "libfoo",
3504 stl: "none",
3505 system_shared_libs: [],
3506 apex_available: ["otherapex"],
3507 }`)
3508
3509 ctx, _ := testApex(t, `
3510 apex {
3511 name: "myapex",
3512 key: "myapex.key",
3513 native_shared_libs: ["libfoo", "libbar"],
3514 }
3515
3516 apex_key {
3517 name: "myapex.key",
3518 public_key: "testkey.avbpubkey",
3519 private_key: "testkey.pem",
3520 }
3521
3522 cc_library {
3523 name: "libfoo",
3524 stl: "none",
3525 system_shared_libs: [],
Jiyong Park9f14b9b2020-03-01 17:29:06 +09003526 runtime_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003527 apex_available: ["myapex"],
3528 }
3529
3530 cc_library {
3531 name: "libbar",
3532 stl: "none",
3533 system_shared_libs: [],
3534 apex_available: ["//apex_available:anyapex"],
Jiyong Park9f14b9b2020-03-01 17:29:06 +09003535 }
3536
3537 cc_library {
3538 name: "libbaz",
3539 stl: "none",
3540 system_shared_libs: [],
3541 stubs: {
3542 versions: ["10", "20", "30"],
3543 },
Jiyong Park127b40b2019-09-30 16:04:35 +09003544 }`)
3545
3546 // check that libfoo and libbar are created only for myapex, but not for the platform
Jiyong Park0f80c182020-01-31 02:49:53 +09003547 // TODO(jiyong) the checks for the platform variant are removed because we now create
3548 // the platform variant regardless of the apex_availability. Instead, we will make sure that
3549 // the platform variants are not used from other platform modules. When that is done,
3550 // these checks will be replaced by expecting a specific error message that will be
3551 // emitted when the platform variant is used.
3552 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3553 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3554 // ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
3555 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")
Jiyong Park127b40b2019-09-30 16:04:35 +09003556
3557 ctx, _ = testApex(t, `
3558 apex {
3559 name: "myapex",
3560 key: "myapex.key",
3561 }
3562
3563 apex_key {
3564 name: "myapex.key",
3565 public_key: "testkey.avbpubkey",
3566 private_key: "testkey.pem",
3567 }
3568
3569 cc_library {
3570 name: "libfoo",
3571 stl: "none",
3572 system_shared_libs: [],
3573 apex_available: ["//apex_available:platform"],
3574 }`)
3575
3576 // check that libfoo is created only for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003577 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3578 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003579
3580 ctx, _ = testApex(t, `
3581 apex {
3582 name: "myapex",
3583 key: "myapex.key",
3584 native_shared_libs: ["libfoo"],
3585 }
3586
3587 apex_key {
3588 name: "myapex.key",
3589 public_key: "testkey.avbpubkey",
3590 private_key: "testkey.pem",
3591 }
3592
3593 cc_library {
3594 name: "libfoo",
3595 stl: "none",
3596 system_shared_libs: [],
3597 apex_available: ["myapex"],
3598 static: {
3599 apex_available: ["//apex_available:platform"],
3600 },
3601 }`)
3602
3603 // shared variant of libfoo is only available to myapex
Jiyong Park0f80c182020-01-31 02:49:53 +09003604 // TODO(jiyong) the checks for the platform variant are removed because we now create
3605 // the platform variant regardless of the apex_availability. Instead, we will make sure that
3606 // the platform variants are not used from other platform modules. When that is done,
3607 // these checks will be replaced by expecting a specific error message that will be
3608 // emitted when the platform variant is used.
3609 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3610 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3611 // // but the static variant is available to both myapex and the platform
3612 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
3613 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09003614}
3615
Jiyong Park5d790c32019-11-15 18:40:32 +09003616func TestOverrideApex(t *testing.T) {
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003617 ctx, config := testApex(t, `
Jiyong Park5d790c32019-11-15 18:40:32 +09003618 apex {
3619 name: "myapex",
3620 key: "myapex.key",
3621 apps: ["app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003622 overrides: ["oldapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003623 }
3624
3625 override_apex {
3626 name: "override_myapex",
3627 base: "myapex",
3628 apps: ["override_app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003629 overrides: ["unknownapex"],
Baligh Uddin004d7172020-02-19 21:29:28 -08003630 logging_parent: "com.foo.bar",
Baligh Uddincb6aa122020-03-15 13:01:05 -07003631 package_name: "test.overridden.package",
Jiyong Park5d790c32019-11-15 18:40:32 +09003632 }
3633
3634 apex_key {
3635 name: "myapex.key",
3636 public_key: "testkey.avbpubkey",
3637 private_key: "testkey.pem",
3638 }
3639
3640 android_app {
3641 name: "app",
3642 srcs: ["foo/bar/MyClass.java"],
3643 package_name: "foo",
3644 sdk_version: "none",
3645 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003646 apex_available: [ "myapex" ],
Jiyong Park5d790c32019-11-15 18:40:32 +09003647 }
3648
3649 override_android_app {
3650 name: "override_app",
3651 base: "app",
3652 package_name: "bar",
3653 }
Jiyong Parka519c542020-03-03 11:45:41 +09003654 `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"}))
Jiyong Park5d790c32019-11-15 18:40:32 +09003655
Jiyong Park317645e2019-12-05 13:20:58 +09003656 originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule)
3657 overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule)
3658 if originalVariant.GetOverriddenBy() != "" {
3659 t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
3660 }
3661 if overriddenVariant.GetOverriddenBy() != "override_myapex" {
3662 t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
3663 }
3664
Jiyong Park5d790c32019-11-15 18:40:32 +09003665 module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image")
3666 apexRule := module.Rule("apexRule")
3667 copyCmds := apexRule.Args["copy_commands"]
3668
3669 ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk")
3670 ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003671
3672 apexBundle := module.Module().(*apexBundle)
3673 name := apexBundle.Name()
3674 if name != "override_myapex" {
3675 t.Errorf("name should be \"override_myapex\", but was %q", name)
3676 }
3677
Baligh Uddin004d7172020-02-19 21:29:28 -08003678 if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" {
3679 t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent)
3680 }
3681
Jiyong Parka519c542020-03-03 11:45:41 +09003682 optFlags := apexRule.Args["opt_flags"]
Baligh Uddincb6aa122020-03-15 13:01:05 -07003683 ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package")
Jiyong Parka519c542020-03-03 11:45:41 +09003684
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003685 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3686 var builder strings.Builder
3687 data.Custom(&builder, name, "TARGET_", "", data)
3688 androidMk := builder.String()
Jiyong Parkf653b052019-11-18 15:39:01 +09003689 ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003690 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
3691 ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003692 ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003693 ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
Jiyong Parkf653b052019-11-18 15:39:01 +09003694 ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003695 ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
3696 ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
Jiyong Park5d790c32019-11-15 18:40:32 +09003697}
3698
Jooyung Han214bf372019-11-12 13:03:50 +09003699func TestLegacyAndroid10Support(t *testing.T) {
3700 ctx, _ := testApex(t, `
3701 apex {
3702 name: "myapex",
3703 key: "myapex.key",
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003704 native_shared_libs: ["mylib"],
Jooyung Han23b0adf2020-03-12 18:37:20 +09003705 min_sdk_version: "29",
Jooyung Han214bf372019-11-12 13:03:50 +09003706 }
3707
3708 apex_key {
3709 name: "myapex.key",
3710 public_key: "testkey.avbpubkey",
3711 private_key: "testkey.pem",
3712 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003713
3714 cc_library {
3715 name: "mylib",
3716 srcs: ["mylib.cpp"],
3717 stl: "libc++",
3718 system_shared_libs: [],
3719 apex_available: [ "myapex" ],
3720 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003721 `, withUnbundledBuild)
Jooyung Han214bf372019-11-12 13:03:50 +09003722
3723 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3724 args := module.Rule("apexRule").Args
3725 ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String())
Dario Frenie3546902020-01-14 23:50:25 +00003726 ensureNotContains(t, args["opt_flags"], "--no_hashtree")
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003727
3728 // The copies of the libraries in the apex should have one more dependency than
3729 // the ones outside the apex, namely the unwinder. Ideally we should check
3730 // the dependency names directly here but for some reason the names are blank in
3731 // this test.
3732 for _, lib := range []string{"libc++", "mylib"} {
3733 apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits
3734 nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits
3735 if len(apexImplicits) != len(nonApexImplicits)+1 {
3736 t.Errorf("%q missing unwinder dep", lib)
3737 }
3738 }
Jooyung Han214bf372019-11-12 13:03:50 +09003739}
3740
Jooyung Han58f26ab2019-12-18 15:34:32 +09003741func TestJavaSDKLibrary(t *testing.T) {
3742 ctx, _ := testApex(t, `
3743 apex {
3744 name: "myapex",
3745 key: "myapex.key",
3746 java_libs: ["foo"],
3747 }
3748
3749 apex_key {
3750 name: "myapex.key",
3751 public_key: "testkey.avbpubkey",
3752 private_key: "testkey.pem",
3753 }
3754
3755 java_sdk_library {
3756 name: "foo",
3757 srcs: ["a.java"],
3758 api_packages: ["foo"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003759 apex_available: [ "myapex" ],
Jooyung Han58f26ab2019-12-18 15:34:32 +09003760 }
3761 `, withFiles(map[string][]byte{
3762 "api/current.txt": nil,
3763 "api/removed.txt": nil,
3764 "api/system-current.txt": nil,
3765 "api/system-removed.txt": nil,
3766 "api/test-current.txt": nil,
3767 "api/test-removed.txt": nil,
3768 }))
3769
3770 // java_sdk_library installs both impl jar and permission XML
Jooyung Hana57af4a2020-01-23 05:36:59 +00003771 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han58f26ab2019-12-18 15:34:32 +09003772 "javalib/foo.jar",
3773 "etc/permissions/foo.xml",
3774 })
3775 // Permission XML should point to the activated path of impl jar of java_sdk_library
Jiyong Parke3833882020-02-17 17:28:10 +09003776 sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml")
3777 ensureContains(t, sdkLibrary.RuleParams.Command, `<library name=\"foo\" file=\"/apex/myapex/javalib/foo.jar\"`)
Jooyung Han58f26ab2019-12-18 15:34:32 +09003778}
3779
atrost6e126252020-01-27 17:01:16 +00003780func TestCompatConfig(t *testing.T) {
3781 ctx, _ := testApex(t, `
3782 apex {
3783 name: "myapex",
3784 key: "myapex.key",
3785 prebuilts: ["myjar-platform-compat-config"],
3786 java_libs: ["myjar"],
3787 }
3788
3789 apex_key {
3790 name: "myapex.key",
3791 public_key: "testkey.avbpubkey",
3792 private_key: "testkey.pem",
3793 }
3794
3795 platform_compat_config {
3796 name: "myjar-platform-compat-config",
3797 src: ":myjar",
3798 }
3799
3800 java_library {
3801 name: "myjar",
3802 srcs: ["foo/bar/MyClass.java"],
3803 sdk_version: "none",
3804 system_modules: "none",
atrost6e126252020-01-27 17:01:16 +00003805 apex_available: [ "myapex" ],
3806 }
3807 `)
3808 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
3809 "etc/compatconfig/myjar-platform-compat-config.xml",
3810 "javalib/myjar.jar",
3811 })
3812}
3813
Jiyong Park479321d2019-12-16 11:47:12 +09003814func TestRejectNonInstallableJavaLibrary(t *testing.T) {
3815 testApexError(t, `"myjar" is not configured to be compiled into dex`, `
3816 apex {
3817 name: "myapex",
3818 key: "myapex.key",
3819 java_libs: ["myjar"],
3820 }
3821
3822 apex_key {
3823 name: "myapex.key",
3824 public_key: "testkey.avbpubkey",
3825 private_key: "testkey.pem",
3826 }
3827
3828 java_library {
3829 name: "myjar",
3830 srcs: ["foo/bar/MyClass.java"],
3831 sdk_version: "none",
3832 system_modules: "none",
Jiyong Park6b21c7d2020-02-11 09:16:01 +09003833 compile_dex: false,
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003834 apex_available: ["myapex"],
Jiyong Park479321d2019-12-16 11:47:12 +09003835 }
3836 `)
3837}
3838
Jiyong Park7afd1072019-12-30 16:56:33 +09003839func TestCarryRequiredModuleNames(t *testing.T) {
3840 ctx, config := testApex(t, `
3841 apex {
3842 name: "myapex",
3843 key: "myapex.key",
3844 native_shared_libs: ["mylib"],
3845 }
3846
3847 apex_key {
3848 name: "myapex.key",
3849 public_key: "testkey.avbpubkey",
3850 private_key: "testkey.pem",
3851 }
3852
3853 cc_library {
3854 name: "mylib",
3855 srcs: ["mylib.cpp"],
3856 system_shared_libs: [],
3857 stl: "none",
3858 required: ["a", "b"],
3859 host_required: ["c", "d"],
3860 target_required: ["e", "f"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003861 apex_available: [ "myapex" ],
Jiyong Park7afd1072019-12-30 16:56:33 +09003862 }
3863 `)
3864
3865 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
3866 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3867 name := apexBundle.BaseModuleName()
3868 prefix := "TARGET_"
3869 var builder strings.Builder
3870 data.Custom(&builder, name, prefix, "", data)
3871 androidMk := builder.String()
3872 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n")
3873 ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n")
3874 ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n")
3875}
3876
Jiyong Park7cd10e32020-01-14 09:22:18 +09003877func TestSymlinksFromApexToSystem(t *testing.T) {
3878 bp := `
3879 apex {
3880 name: "myapex",
3881 key: "myapex.key",
3882 native_shared_libs: ["mylib"],
3883 java_libs: ["myjar"],
3884 }
3885
Jiyong Park9d677202020-02-19 16:29:35 +09003886 apex {
3887 name: "myapex.updatable",
3888 key: "myapex.key",
3889 native_shared_libs: ["mylib"],
3890 java_libs: ["myjar"],
3891 updatable: true,
3892 }
3893
Jiyong Park7cd10e32020-01-14 09:22:18 +09003894 apex_key {
3895 name: "myapex.key",
3896 public_key: "testkey.avbpubkey",
3897 private_key: "testkey.pem",
3898 }
3899
3900 cc_library {
3901 name: "mylib",
3902 srcs: ["mylib.cpp"],
3903 shared_libs: ["myotherlib"],
3904 system_shared_libs: [],
3905 stl: "none",
3906 apex_available: [
3907 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003908 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003909 "//apex_available:platform",
3910 ],
3911 }
3912
3913 cc_library {
3914 name: "myotherlib",
3915 srcs: ["mylib.cpp"],
3916 system_shared_libs: [],
3917 stl: "none",
3918 apex_available: [
3919 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003920 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003921 "//apex_available:platform",
3922 ],
3923 }
3924
3925 java_library {
3926 name: "myjar",
3927 srcs: ["foo/bar/MyClass.java"],
3928 sdk_version: "none",
3929 system_modules: "none",
3930 libs: ["myotherjar"],
Jiyong Park7cd10e32020-01-14 09:22:18 +09003931 apex_available: [
3932 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003933 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003934 "//apex_available:platform",
3935 ],
3936 }
3937
3938 java_library {
3939 name: "myotherjar",
3940 srcs: ["foo/bar/MyClass.java"],
3941 sdk_version: "none",
3942 system_modules: "none",
3943 apex_available: [
3944 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003945 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003946 "//apex_available:platform",
3947 ],
3948 }
3949 `
3950
3951 ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) {
3952 for _, f := range files {
3953 if f.path == file {
3954 if f.isLink {
3955 t.Errorf("%q is not a real file", file)
3956 }
3957 return
3958 }
3959 }
3960 t.Errorf("%q is not found", file)
3961 }
3962
3963 ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) {
3964 for _, f := range files {
3965 if f.path == file {
3966 if !f.isLink {
3967 t.Errorf("%q is not a symlink", file)
3968 }
3969 return
3970 }
3971 }
3972 t.Errorf("%q is not found", file)
3973 }
3974
Jiyong Park9d677202020-02-19 16:29:35 +09003975 // For unbundled build, symlink shouldn't exist regardless of whether an APEX
3976 // is updatable or not
Jiyong Park7cd10e32020-01-14 09:22:18 +09003977 ctx, _ := testApex(t, bp, withUnbundledBuild)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003978 files := getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003979 ensureRealfileExists(t, files, "javalib/myjar.jar")
3980 ensureRealfileExists(t, files, "lib64/mylib.so")
3981 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3982
Jiyong Park9d677202020-02-19 16:29:35 +09003983 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
3984 ensureRealfileExists(t, files, "javalib/myjar.jar")
3985 ensureRealfileExists(t, files, "lib64/mylib.so")
3986 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3987
3988 // For bundled build, symlink to the system for the non-updatable APEXes only
Jiyong Park7cd10e32020-01-14 09:22:18 +09003989 ctx, _ = testApex(t, bp)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003990 files = getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003991 ensureRealfileExists(t, files, "javalib/myjar.jar")
3992 ensureRealfileExists(t, files, "lib64/mylib.so")
3993 ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
Jiyong Park9d677202020-02-19 16:29:35 +09003994
3995 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
3996 ensureRealfileExists(t, files, "javalib/myjar.jar")
3997 ensureRealfileExists(t, files, "lib64/mylib.so")
3998 ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
Jiyong Park7cd10e32020-01-14 09:22:18 +09003999}
4000
Jiyong Parkd93e1b12020-02-28 15:22:21 +09004001func TestAppBundle(t *testing.T) {
4002 ctx, _ := testApex(t, `
4003 apex {
4004 name: "myapex",
4005 key: "myapex.key",
4006 apps: ["AppFoo"],
4007 }
4008
4009 apex_key {
4010 name: "myapex.key",
4011 public_key: "testkey.avbpubkey",
4012 private_key: "testkey.pem",
4013 }
4014
4015 android_app {
4016 name: "AppFoo",
4017 srcs: ["foo/bar/MyClass.java"],
4018 sdk_version: "none",
4019 system_modules: "none",
4020 apex_available: [ "myapex" ],
4021 }
Jiyong Parkaf8998c2020-02-28 16:51:07 +09004022 `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"}))
Jiyong Parkd93e1b12020-02-28 15:22:21 +09004023
4024 bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config")
4025 content := bundleConfigRule.Args["content"]
4026
4027 ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
Jiyong Parkaf8998c2020-02-28 16:51:07 +09004028 ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`)
Jiyong Parkd93e1b12020-02-28 15:22:21 +09004029}
4030
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07004031func TestMain(m *testing.M) {
4032 run := func() int {
4033 setUp()
4034 defer tearDown()
4035
4036 return m.Run()
4037 }
4038
4039 os.Exit(run())
4040}