blob: b7ec056b12464015f455523da706119a306ced6b [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 Han9c80bae2019-08-20 17:30:57 +0900851func TestApexDependencyToLLNDK(t *testing.T) {
852 ctx, _ := testApex(t, `
853 apex {
854 name: "myapex",
855 key: "myapex.key",
856 use_vendor: true,
857 native_shared_libs: ["mylib"],
858 }
859
860 apex_key {
861 name: "myapex.key",
862 public_key: "testkey.avbpubkey",
863 private_key: "testkey.pem",
864 }
865
866 cc_library {
867 name: "mylib",
868 srcs: ["mylib.cpp"],
869 vendor_available: true,
870 shared_libs: ["libbar"],
871 system_shared_libs: [],
872 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000873 apex_available: [ "myapex" ],
Jooyung Han9c80bae2019-08-20 17:30:57 +0900874 }
875
876 cc_library {
877 name: "libbar",
878 srcs: ["mylib.cpp"],
879 system_shared_libs: [],
880 stl: "none",
881 }
882
883 llndk_library {
884 name: "libbar",
885 symbol_file: "",
886 }
Jooyung Handc782442019-11-01 03:14:38 +0900887 `, func(fs map[string][]byte, config android.Config) {
888 setUseVendorWhitelistForTest(config, []string{"myapex"})
889 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900890
Sundong Ahnabb64432019-10-22 13:58:29 +0900891 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900892 copyCmds := apexRule.Args["copy_commands"]
893
894 // Ensure that LLNDK dep is not included
895 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
896
Sundong Ahnabb64432019-10-22 13:58:29 +0900897 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900898 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900899
900 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900901 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900902
903}
904
Jiyong Park25fc6a92018-11-18 18:02:45 +0900905func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700906 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900907 apex {
908 name: "myapex",
909 key: "myapex.key",
910 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
911 }
912
913 apex_key {
914 name: "myapex.key",
915 public_key: "testkey.avbpubkey",
916 private_key: "testkey.pem",
917 }
918
919 cc_library {
920 name: "mylib",
921 srcs: ["mylib.cpp"],
922 shared_libs: ["libdl#27"],
923 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000924 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900925 }
926
927 cc_library_shared {
928 name: "mylib_shared",
929 srcs: ["mylib.cpp"],
930 shared_libs: ["libdl#27"],
931 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000932 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900933 }
934
935 cc_library {
Jiyong Parkb0788572018-12-20 22:10:17 +0900936 name: "libBootstrap",
937 srcs: ["mylib.cpp"],
938 stl: "none",
939 bootstrap: true,
940 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900941 `)
942
Sundong Ahnabb64432019-10-22 13:58:29 +0900943 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900944 copyCmds := apexRule.Args["copy_commands"]
945
946 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800947 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900948 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
949 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900950
951 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900952 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900953
Colin Cross7113d202019-11-20 16:39:12 -0800954 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
955 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
956 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900957
958 // For dependency to libc
959 // Ensure that mylib is linking with the latest version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +0900960 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900961 // ... and not linking to the non-stub (impl) variant
Jiyong Park3ff16992019-12-27 14:11:47 +0900962 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900963 // ... Cflags from stub is correctly exported to mylib
964 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
965 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
966
967 // For dependency to libm
968 // Ensure that mylib is linking with the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -0800969 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900970 // ... and not linking to the stub variant
Jiyong Park3ff16992019-12-27 14:11:47 +0900971 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900972 // ... and is not compiling with the stub
973 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
974 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
975
976 // For dependency to libdl
977 // Ensure that mylib is linking with the specified version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +0900978 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900979 // ... and not linking to the other versions of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +0900980 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so")
981 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900982 // ... and not linking to the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -0800983 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900984 // ... Cflags from stub is correctly exported to mylib
985 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
986 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900987
988 // Ensure that libBootstrap is depending on the platform variant of bionic libs
Colin Cross7113d202019-11-20 16:39:12 -0800989 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"]
990 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so")
991 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so")
992 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900993}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900994
Jooyung Han0c4e0162020-02-26 22:45:42 +0900995func TestApexUseStubsAccordingToMinSdkVersionInUnbundledBuild(t *testing.T) {
996 // there are three links between liba --> libz
997 // 1) myapex -> libx -> liba -> libz : this should be #2 link, but fallback to #1
998 // 2) otherapex -> liby -> liba -> libz : this should be #3 link
999 // 3) (platform) -> liba -> libz : this should be non-stub link
1000 ctx, _ := testApex(t, `
1001 apex {
1002 name: "myapex",
1003 key: "myapex.key",
1004 native_shared_libs: ["libx"],
1005 min_sdk_version: "2",
1006 }
1007
1008 apex {
1009 name: "otherapex",
1010 key: "myapex.key",
1011 native_shared_libs: ["liby"],
1012 min_sdk_version: "3",
1013 }
1014
1015 apex_key {
1016 name: "myapex.key",
1017 public_key: "testkey.avbpubkey",
1018 private_key: "testkey.pem",
1019 }
1020
1021 cc_library {
1022 name: "libx",
1023 shared_libs: ["liba"],
1024 system_shared_libs: [],
1025 stl: "none",
1026 apex_available: [ "myapex" ],
1027 }
1028
1029 cc_library {
1030 name: "liby",
1031 shared_libs: ["liba"],
1032 system_shared_libs: [],
1033 stl: "none",
1034 apex_available: [ "otherapex" ],
1035 }
1036
1037 cc_library {
1038 name: "liba",
1039 shared_libs: ["libz"],
1040 system_shared_libs: [],
1041 stl: "none",
1042 apex_available: [
1043 "//apex_available:anyapex",
1044 "//apex_available:platform",
1045 ],
1046 }
1047
1048 cc_library {
1049 name: "libz",
1050 system_shared_libs: [],
1051 stl: "none",
1052 stubs: {
1053 versions: ["1", "3"],
1054 },
1055 }
1056 `, withUnbundledBuild)
1057
1058 expectLink := func(from, from_variant, to, to_variant string) {
1059 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1060 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1061 }
1062 expectNoLink := func(from, from_variant, to, to_variant string) {
1063 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1064 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1065 }
1066 // platform liba is linked to non-stub version
1067 expectLink("liba", "shared", "libz", "shared")
1068 // liba in myapex is linked to #1
1069 expectLink("liba", "shared_myapex", "libz", "shared_1")
1070 expectNoLink("liba", "shared_myapex", "libz", "shared_3")
1071 expectNoLink("liba", "shared_myapex", "libz", "shared")
1072 // liba in otherapex is linked to #3
1073 expectLink("liba", "shared_otherapex", "libz", "shared_3")
1074 expectNoLink("liba", "shared_otherapex", "libz", "shared_1")
1075 expectNoLink("liba", "shared_otherapex", "libz", "shared")
1076}
1077
1078func TestApexMinSdkVersionDefaultsToLatest(t *testing.T) {
1079 ctx, _ := testApex(t, `
1080 apex {
1081 name: "myapex",
1082 key: "myapex.key",
1083 native_shared_libs: ["libx"],
1084 }
1085
1086 apex_key {
1087 name: "myapex.key",
1088 public_key: "testkey.avbpubkey",
1089 private_key: "testkey.pem",
1090 }
1091
1092 cc_library {
1093 name: "libx",
1094 shared_libs: ["libz"],
1095 system_shared_libs: [],
1096 stl: "none",
1097 apex_available: [ "myapex" ],
1098 }
1099
1100 cc_library {
1101 name: "libz",
1102 system_shared_libs: [],
1103 stl: "none",
1104 stubs: {
1105 versions: ["1", "2"],
1106 },
1107 }
1108 `)
1109
1110 expectLink := func(from, from_variant, to, to_variant string) {
1111 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1112 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1113 }
1114 expectNoLink := func(from, from_variant, to, to_variant string) {
1115 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1116 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1117 }
1118 expectLink("libx", "shared_myapex", "libz", "shared_2")
1119 expectNoLink("libx", "shared_myapex", "libz", "shared_1")
1120 expectNoLink("libx", "shared_myapex", "libz", "shared")
1121}
1122
1123func TestPlatformUsesLatestStubsFromApexes(t *testing.T) {
1124 ctx, _ := testApex(t, `
1125 apex {
1126 name: "myapex",
1127 key: "myapex.key",
1128 native_shared_libs: ["libx"],
1129 }
1130
1131 apex_key {
1132 name: "myapex.key",
1133 public_key: "testkey.avbpubkey",
1134 private_key: "testkey.pem",
1135 }
1136
1137 cc_library {
1138 name: "libx",
1139 system_shared_libs: [],
1140 stl: "none",
1141 apex_available: [ "myapex" ],
1142 stubs: {
1143 versions: ["1", "2"],
1144 },
1145 }
1146
1147 cc_library {
1148 name: "libz",
1149 shared_libs: ["libx"],
1150 system_shared_libs: [],
1151 stl: "none",
1152 }
1153 `)
1154
1155 expectLink := func(from, from_variant, to, to_variant string) {
1156 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1157 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1158 }
1159 expectNoLink := func(from, from_variant, to, to_variant string) {
1160 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1161 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1162 }
1163 expectLink("libz", "shared", "libx", "shared_2")
1164 expectNoLink("libz", "shared", "libz", "shared_1")
1165 expectNoLink("libz", "shared", "libz", "shared")
1166}
1167
1168func TestQApexesUseLatestStubsInBundledBuilds(t *testing.T) {
1169 ctx, _ := testApex(t, `
1170 apex {
1171 name: "myapex",
1172 key: "myapex.key",
1173 native_shared_libs: ["libx"],
1174 min_sdk_version: "29",
1175 }
1176
1177 apex_key {
1178 name: "myapex.key",
1179 public_key: "testkey.avbpubkey",
1180 private_key: "testkey.pem",
1181 }
1182
1183 cc_library {
1184 name: "libx",
1185 shared_libs: ["libbar"],
1186 apex_available: [ "myapex" ],
1187 }
1188
1189 cc_library {
1190 name: "libbar",
1191 stubs: {
1192 versions: ["29", "30"],
1193 },
1194 }
1195 `)
1196 expectLink := func(from, from_variant, to, to_variant string) {
1197 ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld")
1198 libFlags := ld.Args["libFlags"]
1199 ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1200 }
1201 expectLink("libx", "shared_myapex", "libbar", "shared_30")
1202}
1203
1204func TestQTargetApexUseStaticUnwinder(t *testing.T) {
1205 ctx, _ := testApex(t, `
1206 apex {
1207 name: "myapex",
1208 key: "myapex.key",
1209 native_shared_libs: ["libx"],
1210 min_sdk_version: "29",
1211 }
1212
1213 apex_key {
1214 name: "myapex.key",
1215 public_key: "testkey.avbpubkey",
1216 private_key: "testkey.pem",
1217 }
1218
1219 cc_library {
1220 name: "libx",
1221 apex_available: [ "myapex" ],
1222 }
1223
1224 `, withUnbundledBuild)
1225
1226 // ensure apex variant of c++ is linked with static unwinder
1227 cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module)
1228 ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
1229 // note that platform variant is not.
1230 cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module)
1231 ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
1232
1233 libFlags := ctx.ModuleForTests("libx", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
1234 ensureContains(t, libFlags, "android_arm64_armv8-a_shared_myapex/libc++.so")
1235 ensureContains(t, libFlags, "android_arm64_armv8-a_shared_29/libc.so") // min_sdk_version applied
1236}
1237
1238func TestInvalidMinSdkVersion(t *testing.T) {
1239 testApexError(t, `"libz" .*: min_sdk_version is set 29.*`, `
1240 apex {
1241 name: "myapex",
1242 key: "myapex.key",
1243 native_shared_libs: ["libx"],
1244 min_sdk_version: "29",
1245 }
1246
1247 apex_key {
1248 name: "myapex.key",
1249 public_key: "testkey.avbpubkey",
1250 private_key: "testkey.pem",
1251 }
1252
1253 cc_library {
1254 name: "libx",
1255 shared_libs: ["libz"],
1256 system_shared_libs: [],
1257 stl: "none",
1258 apex_available: [ "myapex" ],
1259 }
1260
1261 cc_library {
1262 name: "libz",
1263 system_shared_libs: [],
1264 stl: "none",
1265 stubs: {
1266 versions: ["30"],
1267 },
1268 }
1269 `, withUnbundledBuild)
1270
1271 testApexError(t, `"myapex" .*: min_sdk_version: should be .*`, `
1272 apex {
1273 name: "myapex",
1274 key: "myapex.key",
1275 min_sdk_version: "R",
1276 }
1277
1278 apex_key {
1279 name: "myapex.key",
1280 public_key: "testkey.avbpubkey",
1281 private_key: "testkey.pem",
1282 }
1283 `)
1284}
1285
Jiyong Park7c2ee712018-12-07 00:42:25 +09001286func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001287 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +09001288 apex {
1289 name: "myapex",
1290 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001291 native_shared_libs: ["mylib"],
1292 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +09001293 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001294 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +09001295 }
1296
1297 apex_key {
1298 name: "myapex.key",
1299 public_key: "testkey.avbpubkey",
1300 private_key: "testkey.pem",
1301 }
1302
1303 prebuilt_etc {
1304 name: "myetc",
1305 src: "myprebuilt",
1306 sub_dir: "foo/bar",
1307 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001308
1309 cc_library {
1310 name: "mylib",
1311 srcs: ["mylib.cpp"],
1312 relative_install_path: "foo/bar",
1313 system_shared_libs: [],
1314 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001315 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001316 }
1317
1318 cc_binary {
1319 name: "mybin",
1320 srcs: ["mylib.cpp"],
1321 relative_install_path: "foo/bar",
1322 system_shared_libs: [],
1323 static_executable: true,
1324 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001325 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001326 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001327 `)
1328
Sundong Ahnabb64432019-10-22 13:58:29 +09001329 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001330 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1331
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001332 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001333 ensureListContains(t, dirs, "etc")
1334 ensureListContains(t, dirs, "etc/foo")
1335 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001336 ensureListContains(t, dirs, "lib64")
1337 ensureListContains(t, dirs, "lib64/foo")
1338 ensureListContains(t, dirs, "lib64/foo/bar")
1339 ensureListContains(t, dirs, "lib")
1340 ensureListContains(t, dirs, "lib/foo")
1341 ensureListContains(t, dirs, "lib/foo/bar")
1342
Jiyong Parkbd13e442019-03-15 18:10:35 +09001343 ensureListContains(t, dirs, "bin")
1344 ensureListContains(t, dirs, "bin/foo")
1345 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001346}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001347
1348func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001349 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001350 apex {
1351 name: "myapex",
1352 key: "myapex.key",
1353 native_shared_libs: ["mylib"],
1354 use_vendor: true,
1355 }
1356
1357 apex_key {
1358 name: "myapex.key",
1359 public_key: "testkey.avbpubkey",
1360 private_key: "testkey.pem",
1361 }
1362
1363 cc_library {
1364 name: "mylib",
1365 srcs: ["mylib.cpp"],
1366 shared_libs: ["mylib2"],
1367 system_shared_libs: [],
1368 vendor_available: true,
1369 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001370 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001371 }
1372
1373 cc_library {
1374 name: "mylib2",
1375 srcs: ["mylib.cpp"],
1376 system_shared_libs: [],
1377 vendor_available: true,
1378 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001379 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001380 }
Jooyung Handc782442019-11-01 03:14:38 +09001381 `, func(fs map[string][]byte, config android.Config) {
1382 setUseVendorWhitelistForTest(config, []string{"myapex"})
1383 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001384
1385 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001386 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001387 for _, implicit := range i.Implicits {
1388 inputsList = append(inputsList, implicit.String())
1389 }
1390 }
1391 inputsString := strings.Join(inputsList, " ")
1392
1393 // ensure that the apex includes vendor variants of the direct and indirect deps
Colin Crossfb0c16e2019-11-20 17:12:35 -08001394 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so")
1395 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001396
1397 // ensure that the apex does not include core variants
Colin Cross7113d202019-11-20 16:39:12 -08001398 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so")
1399 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001400}
Jiyong Park16e91a02018-12-20 18:18:08 +09001401
Jooyung Handc782442019-11-01 03:14:38 +09001402func TestUseVendorRestriction(t *testing.T) {
1403 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1404 apex {
1405 name: "myapex",
1406 key: "myapex.key",
1407 use_vendor: true,
1408 }
1409 apex_key {
1410 name: "myapex.key",
1411 public_key: "testkey.avbpubkey",
1412 private_key: "testkey.pem",
1413 }
1414 `, func(fs map[string][]byte, config android.Config) {
1415 setUseVendorWhitelistForTest(config, []string{""})
1416 })
1417 // no error with whitelist
1418 testApex(t, `
1419 apex {
1420 name: "myapex",
1421 key: "myapex.key",
1422 use_vendor: true,
1423 }
1424 apex_key {
1425 name: "myapex.key",
1426 public_key: "testkey.avbpubkey",
1427 private_key: "testkey.pem",
1428 }
1429 `, func(fs map[string][]byte, config android.Config) {
1430 setUseVendorWhitelistForTest(config, []string{"myapex"})
1431 })
1432}
1433
Jooyung Han5c998b92019-06-27 11:30:33 +09001434func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1435 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1436 apex {
1437 name: "myapex",
1438 key: "myapex.key",
1439 native_shared_libs: ["mylib"],
1440 use_vendor: true,
1441 }
1442
1443 apex_key {
1444 name: "myapex.key",
1445 public_key: "testkey.avbpubkey",
1446 private_key: "testkey.pem",
1447 }
1448
1449 cc_library {
1450 name: "mylib",
1451 srcs: ["mylib.cpp"],
1452 system_shared_libs: [],
1453 stl: "none",
1454 }
1455 `)
1456}
1457
Jiyong Park16e91a02018-12-20 18:18:08 +09001458func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001459 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001460 apex {
1461 name: "myapex",
1462 key: "myapex.key",
1463 native_shared_libs: ["mylib"],
1464 }
1465
1466 apex_key {
1467 name: "myapex.key",
1468 public_key: "testkey.avbpubkey",
1469 private_key: "testkey.pem",
1470 }
1471
1472 cc_library {
1473 name: "mylib",
1474 srcs: ["mylib.cpp"],
1475 system_shared_libs: [],
1476 stl: "none",
1477 stubs: {
1478 versions: ["1", "2", "3"],
1479 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001480 apex_available: [
1481 "//apex_available:platform",
1482 "myapex",
1483 ],
Jiyong Park16e91a02018-12-20 18:18:08 +09001484 }
1485
1486 cc_binary {
1487 name: "not_in_apex",
1488 srcs: ["mylib.cpp"],
1489 static_libs: ["mylib"],
1490 static_executable: true,
1491 system_shared_libs: [],
1492 stl: "none",
1493 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001494 `)
1495
Colin Cross7113d202019-11-20 16:39:12 -08001496 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
Jiyong Park16e91a02018-12-20 18:18:08 +09001497
1498 // Ensure that not_in_apex is linking with the static variant of mylib
Colin Cross7113d202019-11-20 16:39:12 -08001499 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001500}
Jiyong Park9335a262018-12-24 11:31:58 +09001501
1502func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001503 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001504 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001505 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001506 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001507 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001508 native_shared_libs: ["mylib"],
Jooyung Han54aca7b2019-11-20 02:26:02 +09001509 file_contexts: ":myapex-file_contexts",
Jiyong Park9335a262018-12-24 11:31:58 +09001510 }
1511
1512 cc_library {
1513 name: "mylib",
1514 srcs: ["mylib.cpp"],
1515 system_shared_libs: [],
1516 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001517 apex_available: [ "myapex_keytest" ],
Jiyong Park9335a262018-12-24 11:31:58 +09001518 }
1519
1520 apex_key {
1521 name: "myapex.key",
1522 public_key: "testkey.avbpubkey",
1523 private_key: "testkey.pem",
1524 }
1525
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001526 android_app_certificate {
1527 name: "myapex.certificate",
1528 certificate: "testkey",
1529 }
1530
1531 android_app_certificate {
1532 name: "myapex.certificate.override",
1533 certificate: "testkey.override",
1534 }
1535
Jiyong Park9335a262018-12-24 11:31:58 +09001536 `)
1537
1538 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001539 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001540
1541 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1542 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1543 "vendor/foo/devkeys/testkey.avbpubkey")
1544 }
1545 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1546 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1547 "vendor/foo/devkeys/testkey.pem")
1548 }
1549
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001550 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001551 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001552 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001553 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001554 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001555 }
1556}
Jiyong Park58e364a2019-01-19 19:24:06 +09001557
Jooyung Hanf121a652019-12-17 14:30:11 +09001558func TestCertificate(t *testing.T) {
1559 t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) {
1560 ctx, _ := testApex(t, `
1561 apex {
1562 name: "myapex",
1563 key: "myapex.key",
1564 }
1565 apex_key {
1566 name: "myapex.key",
1567 public_key: "testkey.avbpubkey",
1568 private_key: "testkey.pem",
1569 }`)
1570 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1571 expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8"
1572 if actual := rule.Args["certificates"]; actual != expected {
1573 t.Errorf("certificates should be %q, not %q", expected, actual)
1574 }
1575 })
1576 t.Run("override when unspecified", func(t *testing.T) {
1577 ctx, _ := testApex(t, `
1578 apex {
1579 name: "myapex_keytest",
1580 key: "myapex.key",
1581 file_contexts: ":myapex-file_contexts",
1582 }
1583 apex_key {
1584 name: "myapex.key",
1585 public_key: "testkey.avbpubkey",
1586 private_key: "testkey.pem",
1587 }
1588 android_app_certificate {
1589 name: "myapex.certificate.override",
1590 certificate: "testkey.override",
1591 }`)
1592 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1593 expected := "testkey.override.x509.pem testkey.override.pk8"
1594 if actual := rule.Args["certificates"]; actual != expected {
1595 t.Errorf("certificates should be %q, not %q", expected, actual)
1596 }
1597 })
1598 t.Run("if specified as :module, it respects the prop", func(t *testing.T) {
1599 ctx, _ := testApex(t, `
1600 apex {
1601 name: "myapex",
1602 key: "myapex.key",
1603 certificate: ":myapex.certificate",
1604 }
1605 apex_key {
1606 name: "myapex.key",
1607 public_key: "testkey.avbpubkey",
1608 private_key: "testkey.pem",
1609 }
1610 android_app_certificate {
1611 name: "myapex.certificate",
1612 certificate: "testkey",
1613 }`)
1614 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1615 expected := "testkey.x509.pem testkey.pk8"
1616 if actual := rule.Args["certificates"]; actual != expected {
1617 t.Errorf("certificates should be %q, not %q", expected, actual)
1618 }
1619 })
1620 t.Run("override when specifiec as <:module>", func(t *testing.T) {
1621 ctx, _ := testApex(t, `
1622 apex {
1623 name: "myapex_keytest",
1624 key: "myapex.key",
1625 file_contexts: ":myapex-file_contexts",
1626 certificate: ":myapex.certificate",
1627 }
1628 apex_key {
1629 name: "myapex.key",
1630 public_key: "testkey.avbpubkey",
1631 private_key: "testkey.pem",
1632 }
1633 android_app_certificate {
1634 name: "myapex.certificate.override",
1635 certificate: "testkey.override",
1636 }`)
1637 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1638 expected := "testkey.override.x509.pem testkey.override.pk8"
1639 if actual := rule.Args["certificates"]; actual != expected {
1640 t.Errorf("certificates should be %q, not %q", expected, actual)
1641 }
1642 })
1643 t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) {
1644 ctx, _ := testApex(t, `
1645 apex {
1646 name: "myapex",
1647 key: "myapex.key",
1648 certificate: "testkey",
1649 }
1650 apex_key {
1651 name: "myapex.key",
1652 public_key: "testkey.avbpubkey",
1653 private_key: "testkey.pem",
1654 }`)
1655 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1656 expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8"
1657 if actual := rule.Args["certificates"]; actual != expected {
1658 t.Errorf("certificates should be %q, not %q", expected, actual)
1659 }
1660 })
1661 t.Run("override when specified as <name>", func(t *testing.T) {
1662 ctx, _ := testApex(t, `
1663 apex {
1664 name: "myapex_keytest",
1665 key: "myapex.key",
1666 file_contexts: ":myapex-file_contexts",
1667 certificate: "testkey",
1668 }
1669 apex_key {
1670 name: "myapex.key",
1671 public_key: "testkey.avbpubkey",
1672 private_key: "testkey.pem",
1673 }
1674 android_app_certificate {
1675 name: "myapex.certificate.override",
1676 certificate: "testkey.override",
1677 }`)
1678 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1679 expected := "testkey.override.x509.pem testkey.override.pk8"
1680 if actual := rule.Args["certificates"]; actual != expected {
1681 t.Errorf("certificates should be %q, not %q", expected, actual)
1682 }
1683 })
1684}
1685
Jiyong Park58e364a2019-01-19 19:24:06 +09001686func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001687 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001688 apex {
1689 name: "myapex",
1690 key: "myapex.key",
Jooyung Han68e511e2020-03-02 17:44:33 +09001691 native_shared_libs: ["mylib", "mylib2"],
Jiyong Park58e364a2019-01-19 19:24:06 +09001692 }
1693
1694 apex {
1695 name: "otherapex",
1696 key: "myapex.key",
Jooyung Han68e511e2020-03-02 17:44:33 +09001697 native_shared_libs: ["mylib", "mylib2"],
Jooyung Han61c41542020-03-07 03:45:53 +09001698 min_sdk_version: "29",
Jiyong Park58e364a2019-01-19 19:24:06 +09001699 }
1700
1701 apex_key {
1702 name: "myapex.key",
1703 public_key: "testkey.avbpubkey",
1704 private_key: "testkey.pem",
1705 }
1706
1707 cc_library {
1708 name: "mylib",
1709 srcs: ["mylib.cpp"],
1710 system_shared_libs: [],
1711 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001712 apex_available: [
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001713 "myapex",
1714 "otherapex",
1715 ],
Jiyong Park58e364a2019-01-19 19:24:06 +09001716 }
Jooyung Han68e511e2020-03-02 17:44:33 +09001717 cc_library {
1718 name: "mylib2",
1719 srcs: ["mylib.cpp"],
1720 system_shared_libs: [],
1721 stl: "none",
1722 apex_available: [
1723 "myapex",
1724 "otherapex",
1725 ],
1726 use_apex_name_macro: true,
1727 }
Jiyong Park58e364a2019-01-19 19:24:06 +09001728 `)
1729
Jooyung Han68e511e2020-03-02 17:44:33 +09001730 // non-APEX variant does not have __ANDROID_APEX__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001731 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001732 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han61c41542020-03-07 03:45:53 +09001733 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
Jooyung Han68e511e2020-03-02 17:44:33 +09001734
Jooyung Han61c41542020-03-07 03:45:53 +09001735 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Jooyung Han68e511e2020-03-02 17:44:33 +09001736 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
1737 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han61c41542020-03-07 03:45:53 +09001738 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
Jooyung Han77988572019-10-18 16:26:16 +09001739 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
Jooyung Han68e511e2020-03-02 17:44:33 +09001740
Jooyung Han61c41542020-03-07 03:45:53 +09001741 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Jooyung Han68e511e2020-03-02 17:44:33 +09001742 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
1743 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han61c41542020-03-07 03:45:53 +09001744 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29")
Jooyung Han77988572019-10-18 16:26:16 +09001745 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001746
Jooyung Han68e511e2020-03-02 17:44:33 +09001747 // When cc_library sets use_apex_name_macro: true
1748 // apex variants define additional macro to distinguish which apex variant it is built for
1749
1750 // non-APEX variant does not have __ANDROID_APEX__ defined
1751 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
1752 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
1753
1754 // APEX variant has __ANDROID_APEX__ defined
1755 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001756 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001757 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1758 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001759
Jooyung Han68e511e2020-03-02 17:44:33 +09001760 // APEX variant has __ANDROID_APEX__ defined
1761 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001762 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001763 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1764 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001765}
Jiyong Park7e636d02019-01-28 16:16:54 +09001766
1767func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001768 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001769 apex {
1770 name: "myapex",
1771 key: "myapex.key",
1772 native_shared_libs: ["mylib"],
1773 }
1774
1775 apex_key {
1776 name: "myapex.key",
1777 public_key: "testkey.avbpubkey",
1778 private_key: "testkey.pem",
1779 }
1780
1781 cc_library_headers {
1782 name: "mylib_headers",
1783 export_include_dirs: ["my_include"],
1784 system_shared_libs: [],
1785 stl: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +09001786 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001787 }
1788
1789 cc_library {
1790 name: "mylib",
1791 srcs: ["mylib.cpp"],
1792 system_shared_libs: [],
1793 stl: "none",
1794 header_libs: ["mylib_headers"],
1795 export_header_lib_headers: ["mylib_headers"],
1796 stubs: {
1797 versions: ["1", "2", "3"],
1798 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001799 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001800 }
1801
1802 cc_library {
1803 name: "otherlib",
1804 srcs: ["mylib.cpp"],
1805 system_shared_libs: [],
1806 stl: "none",
1807 shared_libs: ["mylib"],
1808 }
1809 `)
1810
Colin Cross7113d202019-11-20 16:39:12 -08001811 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park7e636d02019-01-28 16:16:54 +09001812
1813 // Ensure that the include path of the header lib is exported to 'otherlib'
1814 ensureContains(t, cFlags, "-Imy_include")
1815}
Alex Light9670d332019-01-29 18:07:33 -08001816
Jiyong Park7cd10e32020-01-14 09:22:18 +09001817type fileInApex struct {
1818 path string // path in apex
Jooyung Hana57af4a2020-01-23 05:36:59 +00001819 src string // src path
Jiyong Park7cd10e32020-01-14 09:22:18 +09001820 isLink bool
1821}
1822
Jooyung Hana57af4a2020-01-23 05:36:59 +00001823func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex {
Jooyung Han31c470b2019-10-18 16:26:59 +09001824 t.Helper()
Jooyung Hana57af4a2020-01-23 05:36:59 +00001825 apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001826 copyCmds := apexRule.Args["copy_commands"]
1827 imageApexDir := "/image.apex/"
Jiyong Park7cd10e32020-01-14 09:22:18 +09001828 var ret []fileInApex
Jooyung Han31c470b2019-10-18 16:26:59 +09001829 for _, cmd := range strings.Split(copyCmds, "&&") {
1830 cmd = strings.TrimSpace(cmd)
1831 if cmd == "" {
1832 continue
1833 }
1834 terms := strings.Split(cmd, " ")
Jooyung Hana57af4a2020-01-23 05:36:59 +00001835 var dst, src string
Jiyong Park7cd10e32020-01-14 09:22:18 +09001836 var isLink bool
Jooyung Han31c470b2019-10-18 16:26:59 +09001837 switch terms[0] {
1838 case "mkdir":
1839 case "cp":
Jiyong Park7cd10e32020-01-14 09:22:18 +09001840 if len(terms) != 3 && len(terms) != 4 {
Jooyung Han31c470b2019-10-18 16:26:59 +09001841 t.Fatal("copyCmds contains invalid cp command", cmd)
1842 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001843 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001844 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001845 isLink = false
1846 case "ln":
1847 if len(terms) != 3 && len(terms) != 4 {
1848 // ln LINK TARGET or ln -s LINK TARGET
1849 t.Fatal("copyCmds contains invalid ln command", cmd)
1850 }
1851 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001852 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001853 isLink = true
1854 default:
1855 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1856 }
1857 if dst != "" {
Jooyung Han31c470b2019-10-18 16:26:59 +09001858 index := strings.Index(dst, imageApexDir)
1859 if index == -1 {
1860 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1861 }
1862 dstFile := dst[index+len(imageApexDir):]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001863 ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink})
Jooyung Han31c470b2019-10-18 16:26:59 +09001864 }
1865 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001866 return ret
1867}
1868
Jooyung Hana57af4a2020-01-23 05:36:59 +00001869func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) {
1870 t.Helper()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001871 var failed bool
1872 var surplus []string
1873 filesMatched := make(map[string]bool)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001874 for _, file := range getFiles(t, ctx, moduleName, variant) {
Jooyung Han8d8906c2020-02-27 13:31:56 +09001875 mactchFound := false
Jiyong Park7cd10e32020-01-14 09:22:18 +09001876 for _, expected := range files {
1877 if matched, _ := path.Match(expected, file.path); matched {
1878 filesMatched[expected] = true
Jooyung Han8d8906c2020-02-27 13:31:56 +09001879 mactchFound = true
1880 break
Jiyong Park7cd10e32020-01-14 09:22:18 +09001881 }
1882 }
Jooyung Han8d8906c2020-02-27 13:31:56 +09001883 if !mactchFound {
1884 surplus = append(surplus, file.path)
1885 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001886 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001887
Jooyung Han31c470b2019-10-18 16:26:59 +09001888 if len(surplus) > 0 {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001889 sort.Strings(surplus)
Jooyung Han31c470b2019-10-18 16:26:59 +09001890 t.Log("surplus files", surplus)
1891 failed = true
1892 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001893
1894 if len(files) > len(filesMatched) {
1895 var missing []string
1896 for _, expected := range files {
1897 if !filesMatched[expected] {
1898 missing = append(missing, expected)
1899 }
1900 }
1901 sort.Strings(missing)
Jooyung Han31c470b2019-10-18 16:26:59 +09001902 t.Log("missing files", missing)
1903 failed = true
1904 }
1905 if failed {
1906 t.Fail()
1907 }
1908}
1909
Jooyung Han344d5432019-08-23 11:17:39 +09001910func TestVndkApexCurrent(t *testing.T) {
1911 ctx, _ := testApex(t, `
1912 apex_vndk {
1913 name: "myapex",
1914 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001915 }
1916
1917 apex_key {
1918 name: "myapex.key",
1919 public_key: "testkey.avbpubkey",
1920 private_key: "testkey.pem",
1921 }
1922
1923 cc_library {
1924 name: "libvndk",
1925 srcs: ["mylib.cpp"],
1926 vendor_available: true,
1927 vndk: {
1928 enabled: true,
1929 },
1930 system_shared_libs: [],
1931 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001932 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001933 }
1934
1935 cc_library {
1936 name: "libvndksp",
1937 srcs: ["mylib.cpp"],
1938 vendor_available: true,
1939 vndk: {
1940 enabled: true,
1941 support_system_process: true,
1942 },
1943 system_shared_libs: [],
1944 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001945 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001946 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001947 `+vndkLibrariesTxtFiles("current"))
Jooyung Han344d5432019-08-23 11:17:39 +09001948
Jooyung Hana57af4a2020-01-23 05:36:59 +00001949 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001950 "lib/libvndk.so",
1951 "lib/libvndksp.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09001952 "lib/libc++.so",
Jooyung Han31c470b2019-10-18 16:26:59 +09001953 "lib64/libvndk.so",
1954 "lib64/libvndksp.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09001955 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001956 "etc/llndk.libraries.VER.txt",
1957 "etc/vndkcore.libraries.VER.txt",
1958 "etc/vndksp.libraries.VER.txt",
1959 "etc/vndkprivate.libraries.VER.txt",
Jooyung Han31c470b2019-10-18 16:26:59 +09001960 })
Jooyung Han344d5432019-08-23 11:17:39 +09001961}
1962
1963func TestVndkApexWithPrebuilt(t *testing.T) {
1964 ctx, _ := testApex(t, `
1965 apex_vndk {
1966 name: "myapex",
1967 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001968 }
1969
1970 apex_key {
1971 name: "myapex.key",
1972 public_key: "testkey.avbpubkey",
1973 private_key: "testkey.pem",
1974 }
1975
1976 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001977 name: "libvndk",
1978 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001979 vendor_available: true,
1980 vndk: {
1981 enabled: true,
1982 },
1983 system_shared_libs: [],
1984 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001985 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001986 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001987
1988 cc_prebuilt_library_shared {
1989 name: "libvndk.arm",
1990 srcs: ["libvndk.arm.so"],
1991 vendor_available: true,
1992 vndk: {
1993 enabled: true,
1994 },
1995 enabled: false,
1996 arch: {
1997 arm: {
1998 enabled: true,
1999 },
2000 },
2001 system_shared_libs: [],
2002 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002003 apex_available: [ "myapex" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002004 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002005 `+vndkLibrariesTxtFiles("current"),
2006 withFiles(map[string][]byte{
2007 "libvndk.so": nil,
2008 "libvndk.arm.so": nil,
2009 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002010
Jooyung Hana57af4a2020-01-23 05:36:59 +00002011 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002012 "lib/libvndk.so",
2013 "lib/libvndk.arm.so",
2014 "lib64/libvndk.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09002015 "lib/libc++.so",
2016 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002017 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002018 })
Jooyung Han344d5432019-08-23 11:17:39 +09002019}
2020
Jooyung Han39edb6c2019-11-06 16:53:07 +09002021func vndkLibrariesTxtFiles(vers ...string) (result string) {
2022 for _, v := range vers {
2023 if v == "current" {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +09002024 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002025 result += `
2026 vndk_libraries_txt {
2027 name: "` + txt + `.libraries.txt",
2028 }
2029 `
2030 }
2031 } else {
2032 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
2033 result += `
2034 prebuilt_etc {
2035 name: "` + txt + `.libraries.` + v + `.txt",
2036 src: "dummy.txt",
2037 }
2038 `
2039 }
2040 }
2041 }
2042 return
2043}
2044
Jooyung Han344d5432019-08-23 11:17:39 +09002045func TestVndkApexVersion(t *testing.T) {
2046 ctx, _ := testApex(t, `
2047 apex_vndk {
2048 name: "myapex_v27",
2049 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002050 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002051 vndk_version: "27",
2052 }
2053
2054 apex_key {
2055 name: "myapex.key",
2056 public_key: "testkey.avbpubkey",
2057 private_key: "testkey.pem",
2058 }
2059
Jooyung Han31c470b2019-10-18 16:26:59 +09002060 vndk_prebuilt_shared {
2061 name: "libvndk27",
2062 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09002063 vendor_available: true,
2064 vndk: {
2065 enabled: true,
2066 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002067 target_arch: "arm64",
2068 arch: {
2069 arm: {
2070 srcs: ["libvndk27_arm.so"],
2071 },
2072 arm64: {
2073 srcs: ["libvndk27_arm64.so"],
2074 },
2075 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002076 apex_available: [ "myapex_v27" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002077 }
2078
2079 vndk_prebuilt_shared {
2080 name: "libvndk27",
2081 version: "27",
2082 vendor_available: true,
2083 vndk: {
2084 enabled: true,
2085 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002086 target_arch: "x86_64",
2087 arch: {
2088 x86: {
2089 srcs: ["libvndk27_x86.so"],
2090 },
2091 x86_64: {
2092 srcs: ["libvndk27_x86_64.so"],
2093 },
2094 },
Jooyung Han39edb6c2019-11-06 16:53:07 +09002095 }
2096 `+vndkLibrariesTxtFiles("27"),
2097 withFiles(map[string][]byte{
2098 "libvndk27_arm.so": nil,
2099 "libvndk27_arm64.so": nil,
2100 "libvndk27_x86.so": nil,
2101 "libvndk27_x86_64.so": nil,
2102 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002103
Jooyung Hana57af4a2020-01-23 05:36:59 +00002104 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002105 "lib/libvndk27_arm.so",
2106 "lib64/libvndk27_arm64.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002107 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002108 })
Jooyung Han344d5432019-08-23 11:17:39 +09002109}
2110
2111func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
2112 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
2113 apex_vndk {
2114 name: "myapex_v27",
2115 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002116 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002117 vndk_version: "27",
2118 }
2119 apex_vndk {
2120 name: "myapex_v27_other",
2121 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002122 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002123 vndk_version: "27",
2124 }
2125
2126 apex_key {
2127 name: "myapex.key",
2128 public_key: "testkey.avbpubkey",
2129 private_key: "testkey.pem",
2130 }
2131
2132 cc_library {
2133 name: "libvndk",
2134 srcs: ["mylib.cpp"],
2135 vendor_available: true,
2136 vndk: {
2137 enabled: true,
2138 },
2139 system_shared_libs: [],
2140 stl: "none",
2141 }
2142
2143 vndk_prebuilt_shared {
2144 name: "libvndk",
2145 version: "27",
2146 vendor_available: true,
2147 vndk: {
2148 enabled: true,
2149 },
2150 srcs: ["libvndk.so"],
2151 }
2152 `, withFiles(map[string][]byte{
2153 "libvndk.so": nil,
2154 }))
2155}
2156
Jooyung Han90eee022019-10-01 20:02:42 +09002157func TestVndkApexNameRule(t *testing.T) {
2158 ctx, _ := testApex(t, `
2159 apex_vndk {
2160 name: "myapex",
2161 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002162 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002163 }
2164 apex_vndk {
2165 name: "myapex_v28",
2166 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002167 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002168 vndk_version: "28",
2169 }
2170 apex_key {
2171 name: "myapex.key",
2172 public_key: "testkey.avbpubkey",
2173 private_key: "testkey.pem",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002174 }`+vndkLibrariesTxtFiles("28", "current"))
Jooyung Han90eee022019-10-01 20:02:42 +09002175
2176 assertApexName := func(expected, moduleName string) {
Jooyung Hana57af4a2020-01-23 05:36:59 +00002177 bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09002178 actual := proptools.String(bundle.properties.Apex_name)
2179 if !reflect.DeepEqual(actual, expected) {
2180 t.Errorf("Got '%v', expected '%v'", actual, expected)
2181 }
2182 }
2183
2184 assertApexName("com.android.vndk.vVER", "myapex")
2185 assertApexName("com.android.vndk.v28", "myapex_v28")
2186}
2187
Jooyung Han344d5432019-08-23 11:17:39 +09002188func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
2189 ctx, _ := testApex(t, `
2190 apex_vndk {
2191 name: "myapex",
2192 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002193 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002194 }
2195
2196 apex_key {
2197 name: "myapex.key",
2198 public_key: "testkey.avbpubkey",
2199 private_key: "testkey.pem",
2200 }
2201
2202 cc_library {
2203 name: "libvndk",
2204 srcs: ["mylib.cpp"],
2205 vendor_available: true,
2206 native_bridge_supported: true,
2207 host_supported: true,
2208 vndk: {
2209 enabled: true,
2210 },
2211 system_shared_libs: [],
2212 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002213 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002214 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002215 `+vndkLibrariesTxtFiles("current"),
2216 withTargets(map[android.OsType][]android.Target{
2217 android.Android: []android.Target{
2218 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2219 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2220 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
2221 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
2222 },
2223 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002224
Jooyung Hana57af4a2020-01-23 05:36:59 +00002225 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002226 "lib/libvndk.so",
2227 "lib64/libvndk.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09002228 "lib/libc++.so",
2229 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002230 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002231 })
Jooyung Han344d5432019-08-23 11:17:39 +09002232}
2233
2234func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
2235 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
2236 apex_vndk {
2237 name: "myapex",
2238 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002239 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002240 native_bridge_supported: true,
2241 }
2242
2243 apex_key {
2244 name: "myapex.key",
2245 public_key: "testkey.avbpubkey",
2246 private_key: "testkey.pem",
2247 }
2248
2249 cc_library {
2250 name: "libvndk",
2251 srcs: ["mylib.cpp"],
2252 vendor_available: true,
2253 native_bridge_supported: true,
2254 host_supported: true,
2255 vndk: {
2256 enabled: true,
2257 },
2258 system_shared_libs: [],
2259 stl: "none",
2260 }
2261 `)
2262}
2263
Jooyung Han31c470b2019-10-18 16:26:59 +09002264func TestVndkApexWithBinder32(t *testing.T) {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002265 ctx, _ := testApex(t, `
Jooyung Han31c470b2019-10-18 16:26:59 +09002266 apex_vndk {
2267 name: "myapex_v27",
2268 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002269 file_contexts: ":myapex-file_contexts",
Jooyung Han31c470b2019-10-18 16:26:59 +09002270 vndk_version: "27",
2271 }
2272
2273 apex_key {
2274 name: "myapex.key",
2275 public_key: "testkey.avbpubkey",
2276 private_key: "testkey.pem",
2277 }
2278
2279 vndk_prebuilt_shared {
2280 name: "libvndk27",
2281 version: "27",
2282 target_arch: "arm",
2283 vendor_available: true,
2284 vndk: {
2285 enabled: true,
2286 },
2287 arch: {
2288 arm: {
2289 srcs: ["libvndk27.so"],
2290 }
2291 },
2292 }
2293
2294 vndk_prebuilt_shared {
2295 name: "libvndk27",
2296 version: "27",
2297 target_arch: "arm",
2298 binder32bit: true,
2299 vendor_available: true,
2300 vndk: {
2301 enabled: true,
2302 },
2303 arch: {
2304 arm: {
2305 srcs: ["libvndk27binder32.so"],
2306 }
2307 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002308 apex_available: [ "myapex_v27" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002309 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002310 `+vndkLibrariesTxtFiles("27"),
Jooyung Han31c470b2019-10-18 16:26:59 +09002311 withFiles(map[string][]byte{
2312 "libvndk27.so": nil,
2313 "libvndk27binder32.so": nil,
2314 }),
2315 withBinder32bit,
2316 withTargets(map[android.OsType][]android.Target{
2317 android.Android: []android.Target{
2318 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2319 },
2320 }),
2321 )
2322
Jooyung Hana57af4a2020-01-23 05:36:59 +00002323 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002324 "lib/libvndk27binder32.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002325 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002326 })
2327}
2328
Jooyung Hane1633032019-08-01 17:41:43 +09002329func TestDependenciesInApexManifest(t *testing.T) {
2330 ctx, _ := testApex(t, `
2331 apex {
2332 name: "myapex_nodep",
2333 key: "myapex.key",
2334 native_shared_libs: ["lib_nodep"],
2335 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002336 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002337 }
2338
2339 apex {
2340 name: "myapex_dep",
2341 key: "myapex.key",
2342 native_shared_libs: ["lib_dep"],
2343 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002344 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002345 }
2346
2347 apex {
2348 name: "myapex_provider",
2349 key: "myapex.key",
2350 native_shared_libs: ["libfoo"],
2351 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002352 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002353 }
2354
2355 apex {
2356 name: "myapex_selfcontained",
2357 key: "myapex.key",
2358 native_shared_libs: ["lib_dep", "libfoo"],
2359 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002360 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002361 }
2362
2363 apex_key {
2364 name: "myapex.key",
2365 public_key: "testkey.avbpubkey",
2366 private_key: "testkey.pem",
2367 }
2368
2369 cc_library {
2370 name: "lib_nodep",
2371 srcs: ["mylib.cpp"],
2372 system_shared_libs: [],
2373 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002374 apex_available: [ "myapex_nodep" ],
Jooyung Hane1633032019-08-01 17:41:43 +09002375 }
2376
2377 cc_library {
2378 name: "lib_dep",
2379 srcs: ["mylib.cpp"],
2380 shared_libs: ["libfoo"],
2381 system_shared_libs: [],
2382 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002383 apex_available: [
2384 "myapex_dep",
2385 "myapex_provider",
2386 "myapex_selfcontained",
2387 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002388 }
2389
2390 cc_library {
2391 name: "libfoo",
2392 srcs: ["mytest.cpp"],
2393 stubs: {
2394 versions: ["1"],
2395 },
2396 system_shared_libs: [],
2397 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002398 apex_available: [
2399 "myapex_provider",
2400 "myapex_selfcontained",
2401 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002402 }
2403 `)
2404
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002405 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09002406 var provideNativeLibs, requireNativeLibs []string
2407
Sundong Ahnabb64432019-10-22 13:58:29 +09002408 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002409 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2410 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002411 ensureListEmpty(t, provideNativeLibs)
2412 ensureListEmpty(t, requireNativeLibs)
2413
Sundong Ahnabb64432019-10-22 13:58:29 +09002414 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002415 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2416 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002417 ensureListEmpty(t, provideNativeLibs)
2418 ensureListContains(t, requireNativeLibs, "libfoo.so")
2419
Sundong Ahnabb64432019-10-22 13:58:29 +09002420 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002421 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2422 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002423 ensureListContains(t, provideNativeLibs, "libfoo.so")
2424 ensureListEmpty(t, requireNativeLibs)
2425
Sundong Ahnabb64432019-10-22 13:58:29 +09002426 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002427 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2428 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002429 ensureListContains(t, provideNativeLibs, "libfoo.so")
2430 ensureListEmpty(t, requireNativeLibs)
2431}
2432
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002433func TestApexName(t *testing.T) {
Jiyong Parkdb334862020-02-05 17:19:28 +09002434 ctx, config := testApex(t, `
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002435 apex {
2436 name: "myapex",
2437 key: "myapex.key",
2438 apex_name: "com.android.myapex",
Jiyong Parkdb334862020-02-05 17:19:28 +09002439 native_shared_libs: ["mylib"],
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002440 }
2441
2442 apex_key {
2443 name: "myapex.key",
2444 public_key: "testkey.avbpubkey",
2445 private_key: "testkey.pem",
2446 }
Jiyong Parkdb334862020-02-05 17:19:28 +09002447
2448 cc_library {
2449 name: "mylib",
2450 srcs: ["mylib.cpp"],
2451 system_shared_libs: [],
2452 stl: "none",
2453 apex_available: [
2454 "//apex_available:platform",
2455 "myapex",
2456 ],
2457 }
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002458 `)
2459
Sundong Ahnabb64432019-10-22 13:58:29 +09002460 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002461 apexManifestRule := module.Rule("apexManifestRule")
2462 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
2463 apexRule := module.Rule("apexRule")
2464 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
Jiyong Parkdb334862020-02-05 17:19:28 +09002465
2466 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2467 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2468 name := apexBundle.BaseModuleName()
2469 prefix := "TARGET_"
2470 var builder strings.Builder
2471 data.Custom(&builder, name, prefix, "", data)
2472 androidMk := builder.String()
2473 ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n")
2474 ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002475}
2476
Alex Light0851b882019-02-07 13:20:53 -08002477func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002478 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002479 apex {
2480 name: "myapex",
2481 key: "myapex.key",
2482 native_shared_libs: ["mylib_common"],
2483 }
2484
2485 apex_key {
2486 name: "myapex.key",
2487 public_key: "testkey.avbpubkey",
2488 private_key: "testkey.pem",
2489 }
2490
2491 cc_library {
2492 name: "mylib_common",
2493 srcs: ["mylib.cpp"],
2494 system_shared_libs: [],
2495 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002496 apex_available: [
2497 "//apex_available:platform",
2498 "myapex",
2499 ],
Alex Light0851b882019-02-07 13:20:53 -08002500 }
2501 `)
2502
Sundong Ahnabb64432019-10-22 13:58:29 +09002503 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002504 apexRule := module.Rule("apexRule")
2505 copyCmds := apexRule.Args["copy_commands"]
2506
2507 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
2508 t.Log("Apex was a test apex!")
2509 t.Fail()
2510 }
2511 // Ensure that main rule creates an output
2512 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2513
2514 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002515 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002516
2517 // Ensure that both direct and indirect deps are copied into apex
2518 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2519
Colin Cross7113d202019-11-20 16:39:12 -08002520 // Ensure that the platform variant ends with _shared
2521 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002522
2523 if !android.InAnyApex("mylib_common") {
2524 t.Log("Found mylib_common not in any apex!")
2525 t.Fail()
2526 }
2527}
2528
2529func TestTestApex(t *testing.T) {
2530 if android.InAnyApex("mylib_common_test") {
2531 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!")
2532 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002533 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002534 apex_test {
2535 name: "myapex",
2536 key: "myapex.key",
2537 native_shared_libs: ["mylib_common_test"],
2538 }
2539
2540 apex_key {
2541 name: "myapex.key",
2542 public_key: "testkey.avbpubkey",
2543 private_key: "testkey.pem",
2544 }
2545
2546 cc_library {
2547 name: "mylib_common_test",
2548 srcs: ["mylib.cpp"],
2549 system_shared_libs: [],
2550 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002551 // TODO: remove //apex_available:platform
2552 apex_available: [
2553 "//apex_available:platform",
2554 "myapex",
2555 ],
Alex Light0851b882019-02-07 13:20:53 -08002556 }
2557 `)
2558
Sundong Ahnabb64432019-10-22 13:58:29 +09002559 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002560 apexRule := module.Rule("apexRule")
2561 copyCmds := apexRule.Args["copy_commands"]
2562
2563 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
2564 t.Log("Apex was not a test apex!")
2565 t.Fail()
2566 }
2567 // Ensure that main rule creates an output
2568 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2569
2570 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002571 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002572
2573 // Ensure that both direct and indirect deps are copied into apex
2574 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
2575
Colin Cross7113d202019-11-20 16:39:12 -08002576 // Ensure that the platform variant ends with _shared
2577 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002578}
2579
Alex Light9670d332019-01-29 18:07:33 -08002580func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002581 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08002582 apex {
2583 name: "myapex",
2584 key: "myapex.key",
2585 multilib: {
2586 first: {
2587 native_shared_libs: ["mylib_common"],
2588 }
2589 },
2590 target: {
2591 android: {
2592 multilib: {
2593 first: {
2594 native_shared_libs: ["mylib"],
2595 }
2596 }
2597 },
2598 host: {
2599 multilib: {
2600 first: {
2601 native_shared_libs: ["mylib2"],
2602 }
2603 }
2604 }
2605 }
2606 }
2607
2608 apex_key {
2609 name: "myapex.key",
2610 public_key: "testkey.avbpubkey",
2611 private_key: "testkey.pem",
2612 }
2613
2614 cc_library {
2615 name: "mylib",
2616 srcs: ["mylib.cpp"],
2617 system_shared_libs: [],
2618 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002619 // TODO: remove //apex_available:platform
2620 apex_available: [
2621 "//apex_available:platform",
2622 "myapex",
2623 ],
Alex Light9670d332019-01-29 18:07:33 -08002624 }
2625
2626 cc_library {
2627 name: "mylib_common",
2628 srcs: ["mylib.cpp"],
2629 system_shared_libs: [],
2630 stl: "none",
2631 compile_multilib: "first",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002632 // TODO: remove //apex_available:platform
2633 apex_available: [
2634 "//apex_available:platform",
2635 "myapex",
2636 ],
Alex Light9670d332019-01-29 18:07:33 -08002637 }
2638
2639 cc_library {
2640 name: "mylib2",
2641 srcs: ["mylib.cpp"],
2642 system_shared_libs: [],
2643 stl: "none",
2644 compile_multilib: "first",
2645 }
2646 `)
2647
Sundong Ahnabb64432019-10-22 13:58:29 +09002648 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002649 copyCmds := apexRule.Args["copy_commands"]
2650
2651 // Ensure that main rule creates an output
2652 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2653
2654 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002655 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2656 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
2657 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light9670d332019-01-29 18:07:33 -08002658
2659 // Ensure that both direct and indirect deps are copied into apex
2660 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2661 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2662 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2663
Colin Cross7113d202019-11-20 16:39:12 -08002664 // Ensure that the platform variant ends with _shared
2665 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
2666 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
2667 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Alex Light9670d332019-01-29 18:07:33 -08002668}
Jiyong Park04480cf2019-02-06 00:16:29 +09002669
2670func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002671 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002672 apex {
2673 name: "myapex",
2674 key: "myapex.key",
2675 binaries: ["myscript"],
2676 }
2677
2678 apex_key {
2679 name: "myapex.key",
2680 public_key: "testkey.avbpubkey",
2681 private_key: "testkey.pem",
2682 }
2683
2684 sh_binary {
2685 name: "myscript",
2686 src: "mylib.cpp",
2687 filename: "myscript.sh",
2688 sub_dir: "script",
2689 }
2690 `)
2691
Sundong Ahnabb64432019-10-22 13:58:29 +09002692 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002693 copyCmds := apexRule.Args["copy_commands"]
2694
2695 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2696}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002697
Jooyung Han91df2082019-11-20 01:49:42 +09002698func TestApexInVariousPartition(t *testing.T) {
2699 testcases := []struct {
2700 propName, parition, flattenedPartition string
2701 }{
2702 {"", "system", "system_ext"},
2703 {"product_specific: true", "product", "product"},
2704 {"soc_specific: true", "vendor", "vendor"},
2705 {"proprietary: true", "vendor", "vendor"},
2706 {"vendor: true", "vendor", "vendor"},
2707 {"system_ext_specific: true", "system_ext", "system_ext"},
2708 }
2709 for _, tc := range testcases {
2710 t.Run(tc.propName+":"+tc.parition, func(t *testing.T) {
2711 ctx, _ := testApex(t, `
2712 apex {
2713 name: "myapex",
2714 key: "myapex.key",
2715 `+tc.propName+`
2716 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002717
Jooyung Han91df2082019-11-20 01:49:42 +09002718 apex_key {
2719 name: "myapex.key",
2720 public_key: "testkey.avbpubkey",
2721 private_key: "testkey.pem",
2722 }
2723 `)
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002724
Jooyung Han91df2082019-11-20 01:49:42 +09002725 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2726 expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex"
2727 actual := apex.installDir.String()
2728 if actual != expected {
2729 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2730 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002731
Jooyung Han91df2082019-11-20 01:49:42 +09002732 flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
2733 expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex"
2734 actual = flattened.installDir.String()
2735 if actual != expected {
2736 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2737 }
2738 })
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002739 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002740}
Jiyong Park67882562019-03-21 01:11:21 +09002741
Jooyung Han54aca7b2019-11-20 02:26:02 +09002742func TestFileContexts(t *testing.T) {
2743 ctx, _ := testApex(t, `
2744 apex {
2745 name: "myapex",
2746 key: "myapex.key",
2747 }
2748
2749 apex_key {
2750 name: "myapex.key",
2751 public_key: "testkey.avbpubkey",
2752 private_key: "testkey.pem",
2753 }
2754 `)
2755 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
2756 apexRule := module.Rule("apexRule")
2757 actual := apexRule.Args["file_contexts"]
2758 expected := "system/sepolicy/apex/myapex-file_contexts"
2759 if actual != expected {
2760 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2761 }
2762
2763 testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
2764 apex {
2765 name: "myapex",
2766 key: "myapex.key",
2767 file_contexts: "my_own_file_contexts",
2768 }
2769
2770 apex_key {
2771 name: "myapex.key",
2772 public_key: "testkey.avbpubkey",
2773 private_key: "testkey.pem",
2774 }
2775 `, withFiles(map[string][]byte{
2776 "my_own_file_contexts": nil,
2777 }))
2778
2779 testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
2780 apex {
2781 name: "myapex",
2782 key: "myapex.key",
2783 product_specific: true,
2784 file_contexts: "product_specific_file_contexts",
2785 }
2786
2787 apex_key {
2788 name: "myapex.key",
2789 public_key: "testkey.avbpubkey",
2790 private_key: "testkey.pem",
2791 }
2792 `)
2793
2794 ctx, _ = testApex(t, `
2795 apex {
2796 name: "myapex",
2797 key: "myapex.key",
2798 product_specific: true,
2799 file_contexts: "product_specific_file_contexts",
2800 }
2801
2802 apex_key {
2803 name: "myapex.key",
2804 public_key: "testkey.avbpubkey",
2805 private_key: "testkey.pem",
2806 }
2807 `, withFiles(map[string][]byte{
2808 "product_specific_file_contexts": nil,
2809 }))
2810 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2811 apexRule = module.Rule("apexRule")
2812 actual = apexRule.Args["file_contexts"]
2813 expected = "product_specific_file_contexts"
2814 if actual != expected {
2815 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2816 }
2817
2818 ctx, _ = testApex(t, `
2819 apex {
2820 name: "myapex",
2821 key: "myapex.key",
2822 product_specific: true,
2823 file_contexts: ":my-file-contexts",
2824 }
2825
2826 apex_key {
2827 name: "myapex.key",
2828 public_key: "testkey.avbpubkey",
2829 private_key: "testkey.pem",
2830 }
2831
2832 filegroup {
2833 name: "my-file-contexts",
2834 srcs: ["product_specific_file_contexts"],
2835 }
2836 `, withFiles(map[string][]byte{
2837 "product_specific_file_contexts": nil,
2838 }))
2839 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2840 apexRule = module.Rule("apexRule")
2841 actual = apexRule.Args["file_contexts"]
2842 expected = "product_specific_file_contexts"
2843 if actual != expected {
2844 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2845 }
2846}
2847
Jiyong Park67882562019-03-21 01:11:21 +09002848func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002849 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002850 apex_key {
2851 name: "myapex.key",
2852 public_key: ":my.avbpubkey",
2853 private_key: ":my.pem",
2854 product_specific: true,
2855 }
2856
2857 filegroup {
2858 name: "my.avbpubkey",
2859 srcs: ["testkey2.avbpubkey"],
2860 }
2861
2862 filegroup {
2863 name: "my.pem",
2864 srcs: ["testkey2.pem"],
2865 }
2866 `)
2867
2868 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2869 expected_pubkey := "testkey2.avbpubkey"
2870 actual_pubkey := apex_key.public_key_file.String()
2871 if actual_pubkey != expected_pubkey {
2872 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2873 }
2874 expected_privkey := "testkey2.pem"
2875 actual_privkey := apex_key.private_key_file.String()
2876 if actual_privkey != expected_privkey {
2877 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2878 }
2879}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002880
2881func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002882 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002883 prebuilt_apex {
2884 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002885 arch: {
2886 arm64: {
2887 src: "myapex-arm64.apex",
2888 },
2889 arm: {
2890 src: "myapex-arm.apex",
2891 },
2892 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002893 }
2894 `)
2895
2896 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2897
Jiyong Parkc95714e2019-03-29 14:23:10 +09002898 expectedInput := "myapex-arm64.apex"
2899 if prebuilt.inputApex.String() != expectedInput {
2900 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2901 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002902}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002903
2904func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002905 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002906 prebuilt_apex {
2907 name: "myapex",
2908 src: "myapex-arm.apex",
2909 filename: "notmyapex.apex",
2910 }
2911 `)
2912
2913 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2914
2915 expected := "notmyapex.apex"
2916 if p.installFilename != expected {
2917 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2918 }
2919}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002920
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002921func TestPrebuiltOverrides(t *testing.T) {
2922 ctx, config := testApex(t, `
2923 prebuilt_apex {
2924 name: "myapex.prebuilt",
2925 src: "myapex-arm.apex",
2926 overrides: [
2927 "myapex",
2928 ],
2929 }
2930 `)
2931
2932 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2933
2934 expected := []string{"myapex"}
Jiyong Park0b0e1b92019-12-03 13:24:29 +09002935 actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002936 if !reflect.DeepEqual(actual, expected) {
Jiyong Parkb0a012c2019-11-14 17:17:03 +09002937 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002938 }
2939}
2940
Roland Levillain630846d2019-06-26 12:48:34 +01002941func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002942 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002943 apex_test {
2944 name: "myapex",
2945 key: "myapex.key",
2946 tests: [
2947 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002948 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002949 ],
2950 }
2951
2952 apex_key {
2953 name: "myapex.key",
2954 public_key: "testkey.avbpubkey",
2955 private_key: "testkey.pem",
2956 }
2957
2958 cc_test {
2959 name: "mytest",
2960 gtest: false,
2961 srcs: ["mytest.cpp"],
2962 relative_install_path: "test",
2963 system_shared_libs: [],
2964 static_executable: true,
2965 stl: "none",
2966 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002967
2968 cc_test {
2969 name: "mytests",
2970 gtest: false,
2971 srcs: [
2972 "mytest1.cpp",
2973 "mytest2.cpp",
2974 "mytest3.cpp",
2975 ],
2976 test_per_src: true,
2977 relative_install_path: "test",
2978 system_shared_libs: [],
2979 static_executable: true,
2980 stl: "none",
2981 }
Roland Levillain630846d2019-06-26 12:48:34 +01002982 `)
2983
Sundong Ahnabb64432019-10-22 13:58:29 +09002984 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01002985 copyCmds := apexRule.Args["copy_commands"]
2986
2987 // Ensure that test dep is copied into apex.
2988 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002989
2990 // Ensure that test deps built with `test_per_src` are copied into apex.
2991 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2992 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2993 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002994
2995 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09002996 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01002997 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2998 name := apexBundle.BaseModuleName()
2999 prefix := "TARGET_"
3000 var builder strings.Builder
3001 data.Custom(&builder, name, prefix, "", data)
3002 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09003003 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
3004 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
3005 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
3006 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
Jooyung Han214bf372019-11-12 13:03:50 +09003007 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
Jooyung Han31c470b2019-10-18 16:26:59 +09003008 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01003009 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01003010}
3011
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003012func TestInstallExtraFlattenedApexes(t *testing.T) {
3013 ctx, config := testApex(t, `
3014 apex {
3015 name: "myapex",
3016 key: "myapex.key",
3017 }
3018 apex_key {
3019 name: "myapex.key",
3020 public_key: "testkey.avbpubkey",
3021 private_key: "testkey.pem",
3022 }
3023 `, func(fs map[string][]byte, config android.Config) {
3024 config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
3025 })
3026 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Jiyong Park83dc74b2020-01-14 18:38:44 +09003027 ensureListContains(t, ab.requiredDeps, "myapex.flattened")
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003028 mk := android.AndroidMkDataForTest(t, config, "", ab)
3029 var builder strings.Builder
3030 mk.Custom(&builder, ab.Name(), "TARGET_", "", mk)
3031 androidMk := builder.String()
3032 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened")
3033}
3034
Jooyung Han5c998b92019-06-27 11:30:33 +09003035func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003036 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09003037 apex {
3038 name: "myapex",
3039 key: "myapex.key",
3040 native_shared_libs: ["mylib"],
3041 uses: ["commonapex"],
3042 }
3043
3044 apex {
3045 name: "commonapex",
3046 key: "myapex.key",
3047 native_shared_libs: ["libcommon"],
3048 provide_cpp_shared_libs: true,
3049 }
3050
3051 apex_key {
3052 name: "myapex.key",
3053 public_key: "testkey.avbpubkey",
3054 private_key: "testkey.pem",
3055 }
3056
3057 cc_library {
3058 name: "mylib",
3059 srcs: ["mylib.cpp"],
3060 shared_libs: ["libcommon"],
3061 system_shared_libs: [],
3062 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003063 apex_available: [ "myapex" ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003064 }
3065
3066 cc_library {
3067 name: "libcommon",
3068 srcs: ["mylib_common.cpp"],
3069 system_shared_libs: [],
3070 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003071 // TODO: remove //apex_available:platform
3072 apex_available: [
3073 "//apex_available:platform",
3074 "commonapex",
3075 "myapex",
3076 ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003077 }
3078 `)
3079
Sundong Ahnabb64432019-10-22 13:58:29 +09003080 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003081 apexRule1 := module1.Rule("apexRule")
3082 copyCmds1 := apexRule1.Args["copy_commands"]
3083
Sundong Ahnabb64432019-10-22 13:58:29 +09003084 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003085 apexRule2 := module2.Rule("apexRule")
3086 copyCmds2 := apexRule2.Args["copy_commands"]
3087
Colin Cross7113d202019-11-20 16:39:12 -08003088 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
3089 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex")
Jooyung Han5c998b92019-06-27 11:30:33 +09003090 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
3091 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
3092 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
3093}
3094
3095func TestApexUsesFailsIfNotProvided(t *testing.T) {
3096 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
3097 apex {
3098 name: "myapex",
3099 key: "myapex.key",
3100 uses: ["commonapex"],
3101 }
3102
3103 apex {
3104 name: "commonapex",
3105 key: "myapex.key",
3106 }
3107
3108 apex_key {
3109 name: "myapex.key",
3110 public_key: "testkey.avbpubkey",
3111 private_key: "testkey.pem",
3112 }
3113 `)
3114 testApexError(t, `uses: "commonapex" is not a provider`, `
3115 apex {
3116 name: "myapex",
3117 key: "myapex.key",
3118 uses: ["commonapex"],
3119 }
3120
3121 cc_library {
3122 name: "commonapex",
3123 system_shared_libs: [],
3124 stl: "none",
3125 }
3126
3127 apex_key {
3128 name: "myapex.key",
3129 public_key: "testkey.avbpubkey",
3130 private_key: "testkey.pem",
3131 }
3132 `)
3133}
3134
3135func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
3136 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
3137 apex {
3138 name: "myapex",
3139 key: "myapex.key",
3140 use_vendor: true,
3141 uses: ["commonapex"],
3142 }
3143
3144 apex {
3145 name: "commonapex",
3146 key: "myapex.key",
3147 provide_cpp_shared_libs: true,
3148 }
3149
3150 apex_key {
3151 name: "myapex.key",
3152 public_key: "testkey.avbpubkey",
3153 private_key: "testkey.pem",
3154 }
Jooyung Handc782442019-11-01 03:14:38 +09003155 `, func(fs map[string][]byte, config android.Config) {
3156 setUseVendorWhitelistForTest(config, []string{"myapex"})
3157 })
Jooyung Han5c998b92019-06-27 11:30:33 +09003158}
3159
Jooyung Hand48f3c32019-08-23 11:18:57 +09003160func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
3161 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
3162 apex {
3163 name: "myapex",
3164 key: "myapex.key",
3165 native_shared_libs: ["libfoo"],
3166 }
3167
3168 apex_key {
3169 name: "myapex.key",
3170 public_key: "testkey.avbpubkey",
3171 private_key: "testkey.pem",
3172 }
3173
3174 cc_library {
3175 name: "libfoo",
3176 stl: "none",
3177 system_shared_libs: [],
3178 enabled: false,
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003179 apex_available: ["myapex"],
Jooyung Hand48f3c32019-08-23 11:18:57 +09003180 }
3181 `)
3182 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
3183 apex {
3184 name: "myapex",
3185 key: "myapex.key",
3186 java_libs: ["myjar"],
3187 }
3188
3189 apex_key {
3190 name: "myapex.key",
3191 public_key: "testkey.avbpubkey",
3192 private_key: "testkey.pem",
3193 }
3194
3195 java_library {
3196 name: "myjar",
3197 srcs: ["foo/bar/MyClass.java"],
3198 sdk_version: "none",
3199 system_modules: "none",
Jooyung Hand48f3c32019-08-23 11:18:57 +09003200 enabled: false,
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003201 apex_available: ["myapex"],
Jooyung Hand48f3c32019-08-23 11:18:57 +09003202 }
3203 `)
3204}
3205
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003206func TestApexWithApps(t *testing.T) {
3207 ctx, _ := testApex(t, `
3208 apex {
3209 name: "myapex",
3210 key: "myapex.key",
3211 apps: [
3212 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09003213 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003214 ],
3215 }
3216
3217 apex_key {
3218 name: "myapex.key",
3219 public_key: "testkey.avbpubkey",
3220 private_key: "testkey.pem",
3221 }
3222
3223 android_app {
3224 name: "AppFoo",
3225 srcs: ["foo/bar/MyClass.java"],
3226 sdk_version: "none",
3227 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09003228 jni_libs: ["libjni"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003229 apex_available: [ "myapex" ],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003230 }
Jiyong Parkf7487312019-10-17 12:54:30 +09003231
3232 android_app {
3233 name: "AppFooPriv",
3234 srcs: ["foo/bar/MyClass.java"],
3235 sdk_version: "none",
3236 system_modules: "none",
3237 privileged: true,
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003238 apex_available: [ "myapex" ],
Jiyong Parkf7487312019-10-17 12:54:30 +09003239 }
Jiyong Park8be103b2019-11-08 15:53:48 +09003240
3241 cc_library_shared {
3242 name: "libjni",
3243 srcs: ["mylib.cpp"],
Jooyung Han65041792020-02-25 16:59:29 +09003244 shared_libs: ["libfoo"],
Jiyong Park8be103b2019-11-08 15:53:48 +09003245 stl: "none",
3246 system_shared_libs: [],
Jiyong Park0f80c182020-01-31 02:49:53 +09003247 apex_available: [ "myapex" ],
Jooyung Han65041792020-02-25 16:59:29 +09003248 sdk_version: "current",
3249 }
3250
3251 cc_library_shared {
3252 name: "libfoo",
3253 stl: "none",
3254 system_shared_libs: [],
3255 apex_available: [ "myapex" ],
3256 sdk_version: "current",
Jiyong Park8be103b2019-11-08 15:53:48 +09003257 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003258 `)
3259
Sundong Ahnabb64432019-10-22 13:58:29 +09003260 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003261 apexRule := module.Rule("apexRule")
3262 copyCmds := apexRule.Args["copy_commands"]
3263
3264 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09003265 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003266
Jooyung Han65041792020-02-25 16:59:29 +09003267 appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs")
3268 // JNI libraries are uncompressed
Jiyong Park52cd06f2019-11-11 10:14:32 +09003269 if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
Jooyung Han65041792020-02-25 16:59:29 +09003270 t.Errorf("jni libs are not uncompressed for AppFoo")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003271 }
Jooyung Han65041792020-02-25 16:59:29 +09003272 // JNI libraries including transitive deps are
3273 for _, jni := range []string{"libjni", "libfoo"} {
3274 jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile()
3275 // ... embedded inside APK (jnilibs.zip)
3276 ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String())
3277 // ... and not directly inside the APEX
3278 ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so")
3279 }
Dario Frenicde2a032019-10-27 00:29:22 +01003280}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003281
Dario Frenicde2a032019-10-27 00:29:22 +01003282func TestApexWithAppImports(t *testing.T) {
3283 ctx, _ := testApex(t, `
3284 apex {
3285 name: "myapex",
3286 key: "myapex.key",
3287 apps: [
3288 "AppFooPrebuilt",
3289 "AppFooPrivPrebuilt",
3290 ],
3291 }
3292
3293 apex_key {
3294 name: "myapex.key",
3295 public_key: "testkey.avbpubkey",
3296 private_key: "testkey.pem",
3297 }
3298
3299 android_app_import {
3300 name: "AppFooPrebuilt",
3301 apk: "PrebuiltAppFoo.apk",
3302 presigned: true,
3303 dex_preopt: {
3304 enabled: false,
3305 },
3306 }
3307
3308 android_app_import {
3309 name: "AppFooPrivPrebuilt",
3310 apk: "PrebuiltAppFooPriv.apk",
3311 privileged: true,
3312 presigned: true,
3313 dex_preopt: {
3314 enabled: false,
3315 },
3316 }
3317 `)
3318
Sundong Ahnabb64432019-10-22 13:58:29 +09003319 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01003320 apexRule := module.Rule("apexRule")
3321 copyCmds := apexRule.Args["copy_commands"]
3322
3323 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
3324 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003325}
3326
Dario Freni6f3937c2019-12-20 22:58:03 +00003327func TestApexWithTestHelperApp(t *testing.T) {
3328 ctx, _ := testApex(t, `
3329 apex {
3330 name: "myapex",
3331 key: "myapex.key",
3332 apps: [
3333 "TesterHelpAppFoo",
3334 ],
3335 }
3336
3337 apex_key {
3338 name: "myapex.key",
3339 public_key: "testkey.avbpubkey",
3340 private_key: "testkey.pem",
3341 }
3342
3343 android_test_helper_app {
3344 name: "TesterHelpAppFoo",
3345 srcs: ["foo/bar/MyClass.java"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003346 apex_available: [ "myapex" ],
Dario Freni6f3937c2019-12-20 22:58:03 +00003347 }
3348
3349 `)
3350
3351 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3352 apexRule := module.Rule("apexRule")
3353 copyCmds := apexRule.Args["copy_commands"]
3354
3355 ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk")
3356}
3357
Jooyung Han18020ea2019-11-13 10:50:48 +09003358func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
3359 // libfoo's apex_available comes from cc_defaults
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003360 testApexError(t, `requires "libfoo" that is not available for the APEX`, `
Jooyung Han18020ea2019-11-13 10:50:48 +09003361 apex {
3362 name: "myapex",
3363 key: "myapex.key",
3364 native_shared_libs: ["libfoo"],
3365 }
3366
3367 apex_key {
3368 name: "myapex.key",
3369 public_key: "testkey.avbpubkey",
3370 private_key: "testkey.pem",
3371 }
3372
3373 apex {
3374 name: "otherapex",
3375 key: "myapex.key",
3376 native_shared_libs: ["libfoo"],
3377 }
3378
3379 cc_defaults {
3380 name: "libfoo-defaults",
3381 apex_available: ["otherapex"],
3382 }
3383
3384 cc_library {
3385 name: "libfoo",
3386 defaults: ["libfoo-defaults"],
3387 stl: "none",
3388 system_shared_libs: [],
3389 }`)
3390}
3391
Jiyong Park127b40b2019-09-30 16:04:35 +09003392func TestApexAvailable(t *testing.T) {
3393 // libfoo is not available to myapex, but only to otherapex
3394 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
3395 apex {
3396 name: "myapex",
3397 key: "myapex.key",
3398 native_shared_libs: ["libfoo"],
3399 }
3400
3401 apex_key {
3402 name: "myapex.key",
3403 public_key: "testkey.avbpubkey",
3404 private_key: "testkey.pem",
3405 }
3406
3407 apex {
3408 name: "otherapex",
3409 key: "otherapex.key",
3410 native_shared_libs: ["libfoo"],
3411 }
3412
3413 apex_key {
3414 name: "otherapex.key",
3415 public_key: "testkey.avbpubkey",
3416 private_key: "testkey.pem",
3417 }
3418
3419 cc_library {
3420 name: "libfoo",
3421 stl: "none",
3422 system_shared_libs: [],
3423 apex_available: ["otherapex"],
3424 }`)
3425
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003426 // libbbaz is an indirect dep
3427 testApexError(t, "requires \"libbaz\" that is not available for the APEX", `
Jiyong Park127b40b2019-09-30 16:04:35 +09003428 apex {
3429 name: "myapex",
3430 key: "myapex.key",
3431 native_shared_libs: ["libfoo"],
3432 }
3433
3434 apex_key {
3435 name: "myapex.key",
3436 public_key: "testkey.avbpubkey",
3437 private_key: "testkey.pem",
3438 }
3439
Jiyong Park127b40b2019-09-30 16:04:35 +09003440 cc_library {
3441 name: "libfoo",
3442 stl: "none",
3443 shared_libs: ["libbar"],
3444 system_shared_libs: [],
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003445 apex_available: ["myapex"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003446 }
3447
3448 cc_library {
3449 name: "libbar",
3450 stl: "none",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003451 shared_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003452 system_shared_libs: [],
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003453 apex_available: ["myapex"],
3454 }
3455
3456 cc_library {
3457 name: "libbaz",
3458 stl: "none",
3459 system_shared_libs: [],
Jiyong Park127b40b2019-09-30 16:04:35 +09003460 }`)
3461
3462 testApexError(t, "\"otherapex\" is not a valid module name", `
3463 apex {
3464 name: "myapex",
3465 key: "myapex.key",
3466 native_shared_libs: ["libfoo"],
3467 }
3468
3469 apex_key {
3470 name: "myapex.key",
3471 public_key: "testkey.avbpubkey",
3472 private_key: "testkey.pem",
3473 }
3474
3475 cc_library {
3476 name: "libfoo",
3477 stl: "none",
3478 system_shared_libs: [],
3479 apex_available: ["otherapex"],
3480 }`)
3481
3482 ctx, _ := testApex(t, `
3483 apex {
3484 name: "myapex",
3485 key: "myapex.key",
3486 native_shared_libs: ["libfoo", "libbar"],
3487 }
3488
3489 apex_key {
3490 name: "myapex.key",
3491 public_key: "testkey.avbpubkey",
3492 private_key: "testkey.pem",
3493 }
3494
3495 cc_library {
3496 name: "libfoo",
3497 stl: "none",
3498 system_shared_libs: [],
Jiyong Park9f14b9b2020-03-01 17:29:06 +09003499 runtime_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003500 apex_available: ["myapex"],
3501 }
3502
3503 cc_library {
3504 name: "libbar",
3505 stl: "none",
3506 system_shared_libs: [],
3507 apex_available: ["//apex_available:anyapex"],
Jiyong Park9f14b9b2020-03-01 17:29:06 +09003508 }
3509
3510 cc_library {
3511 name: "libbaz",
3512 stl: "none",
3513 system_shared_libs: [],
3514 stubs: {
3515 versions: ["10", "20", "30"],
3516 },
Jiyong Park127b40b2019-09-30 16:04:35 +09003517 }`)
3518
3519 // check that libfoo and libbar are created only for myapex, but not for the platform
Jiyong Park0f80c182020-01-31 02:49:53 +09003520 // TODO(jiyong) the checks for the platform variant are removed because we now create
3521 // the platform variant regardless of the apex_availability. Instead, we will make sure that
3522 // the platform variants are not used from other platform modules. When that is done,
3523 // these checks will be replaced by expecting a specific error message that will be
3524 // emitted when the platform variant is used.
3525 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3526 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3527 // ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
3528 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")
Jiyong Park127b40b2019-09-30 16:04:35 +09003529
3530 ctx, _ = testApex(t, `
3531 apex {
3532 name: "myapex",
3533 key: "myapex.key",
3534 }
3535
3536 apex_key {
3537 name: "myapex.key",
3538 public_key: "testkey.avbpubkey",
3539 private_key: "testkey.pem",
3540 }
3541
3542 cc_library {
3543 name: "libfoo",
3544 stl: "none",
3545 system_shared_libs: [],
3546 apex_available: ["//apex_available:platform"],
3547 }`)
3548
3549 // check that libfoo is created only for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003550 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3551 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003552
3553 ctx, _ = testApex(t, `
3554 apex {
3555 name: "myapex",
3556 key: "myapex.key",
3557 native_shared_libs: ["libfoo"],
3558 }
3559
3560 apex_key {
3561 name: "myapex.key",
3562 public_key: "testkey.avbpubkey",
3563 private_key: "testkey.pem",
3564 }
3565
3566 cc_library {
3567 name: "libfoo",
3568 stl: "none",
3569 system_shared_libs: [],
3570 apex_available: ["myapex"],
3571 static: {
3572 apex_available: ["//apex_available:platform"],
3573 },
3574 }`)
3575
3576 // shared variant of libfoo is only available to myapex
Jiyong Park0f80c182020-01-31 02:49:53 +09003577 // TODO(jiyong) the checks for the platform variant are removed because we now create
3578 // the platform variant regardless of the apex_availability. Instead, we will make sure that
3579 // the platform variants are not used from other platform modules. When that is done,
3580 // these checks will be replaced by expecting a specific error message that will be
3581 // emitted when the platform variant is used.
3582 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3583 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3584 // // but the static variant is available to both myapex and the platform
3585 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
3586 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09003587}
3588
Jiyong Park5d790c32019-11-15 18:40:32 +09003589func TestOverrideApex(t *testing.T) {
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003590 ctx, config := testApex(t, `
Jiyong Park5d790c32019-11-15 18:40:32 +09003591 apex {
3592 name: "myapex",
3593 key: "myapex.key",
3594 apps: ["app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003595 overrides: ["oldapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003596 }
3597
3598 override_apex {
3599 name: "override_myapex",
3600 base: "myapex",
3601 apps: ["override_app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003602 overrides: ["unknownapex"],
Baligh Uddin004d7172020-02-19 21:29:28 -08003603 logging_parent: "com.foo.bar",
Baligh Uddincb6aa122020-03-15 13:01:05 -07003604 package_name: "test.overridden.package",
Jiyong Park5d790c32019-11-15 18:40:32 +09003605 }
3606
3607 apex_key {
3608 name: "myapex.key",
3609 public_key: "testkey.avbpubkey",
3610 private_key: "testkey.pem",
3611 }
3612
3613 android_app {
3614 name: "app",
3615 srcs: ["foo/bar/MyClass.java"],
3616 package_name: "foo",
3617 sdk_version: "none",
3618 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003619 apex_available: [ "myapex" ],
Jiyong Park5d790c32019-11-15 18:40:32 +09003620 }
3621
3622 override_android_app {
3623 name: "override_app",
3624 base: "app",
3625 package_name: "bar",
3626 }
Jiyong Parka519c542020-03-03 11:45:41 +09003627 `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"}))
Jiyong Park5d790c32019-11-15 18:40:32 +09003628
Jiyong Park317645e2019-12-05 13:20:58 +09003629 originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule)
3630 overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule)
3631 if originalVariant.GetOverriddenBy() != "" {
3632 t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
3633 }
3634 if overriddenVariant.GetOverriddenBy() != "override_myapex" {
3635 t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
3636 }
3637
Jiyong Park5d790c32019-11-15 18:40:32 +09003638 module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image")
3639 apexRule := module.Rule("apexRule")
3640 copyCmds := apexRule.Args["copy_commands"]
3641
3642 ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk")
3643 ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003644
3645 apexBundle := module.Module().(*apexBundle)
3646 name := apexBundle.Name()
3647 if name != "override_myapex" {
3648 t.Errorf("name should be \"override_myapex\", but was %q", name)
3649 }
3650
Baligh Uddin004d7172020-02-19 21:29:28 -08003651 if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" {
3652 t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent)
3653 }
3654
Jiyong Parka519c542020-03-03 11:45:41 +09003655 optFlags := apexRule.Args["opt_flags"]
Baligh Uddincb6aa122020-03-15 13:01:05 -07003656 ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package")
Jiyong Parka519c542020-03-03 11:45:41 +09003657
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003658 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3659 var builder strings.Builder
3660 data.Custom(&builder, name, "TARGET_", "", data)
3661 androidMk := builder.String()
Jiyong Parkf653b052019-11-18 15:39:01 +09003662 ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003663 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
3664 ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003665 ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003666 ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
Jiyong Parkf653b052019-11-18 15:39:01 +09003667 ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003668 ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
3669 ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
Jiyong Park5d790c32019-11-15 18:40:32 +09003670}
3671
Jooyung Han214bf372019-11-12 13:03:50 +09003672func TestLegacyAndroid10Support(t *testing.T) {
3673 ctx, _ := testApex(t, `
3674 apex {
3675 name: "myapex",
3676 key: "myapex.key",
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003677 native_shared_libs: ["mylib"],
Jooyung Han23b0adf2020-03-12 18:37:20 +09003678 min_sdk_version: "29",
Jooyung Han214bf372019-11-12 13:03:50 +09003679 }
3680
3681 apex_key {
3682 name: "myapex.key",
3683 public_key: "testkey.avbpubkey",
3684 private_key: "testkey.pem",
3685 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003686
3687 cc_library {
3688 name: "mylib",
3689 srcs: ["mylib.cpp"],
3690 stl: "libc++",
3691 system_shared_libs: [],
3692 apex_available: [ "myapex" ],
3693 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003694 `, withUnbundledBuild)
Jooyung Han214bf372019-11-12 13:03:50 +09003695
3696 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3697 args := module.Rule("apexRule").Args
3698 ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String())
Dario Frenie3546902020-01-14 23:50:25 +00003699 ensureNotContains(t, args["opt_flags"], "--no_hashtree")
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003700
3701 // The copies of the libraries in the apex should have one more dependency than
3702 // the ones outside the apex, namely the unwinder. Ideally we should check
3703 // the dependency names directly here but for some reason the names are blank in
3704 // this test.
3705 for _, lib := range []string{"libc++", "mylib"} {
3706 apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits
3707 nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits
3708 if len(apexImplicits) != len(nonApexImplicits)+1 {
3709 t.Errorf("%q missing unwinder dep", lib)
3710 }
3711 }
Jooyung Han214bf372019-11-12 13:03:50 +09003712}
3713
Jooyung Han58f26ab2019-12-18 15:34:32 +09003714func TestJavaSDKLibrary(t *testing.T) {
3715 ctx, _ := testApex(t, `
3716 apex {
3717 name: "myapex",
3718 key: "myapex.key",
3719 java_libs: ["foo"],
3720 }
3721
3722 apex_key {
3723 name: "myapex.key",
3724 public_key: "testkey.avbpubkey",
3725 private_key: "testkey.pem",
3726 }
3727
3728 java_sdk_library {
3729 name: "foo",
3730 srcs: ["a.java"],
3731 api_packages: ["foo"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003732 apex_available: [ "myapex" ],
Jooyung Han58f26ab2019-12-18 15:34:32 +09003733 }
3734 `, withFiles(map[string][]byte{
3735 "api/current.txt": nil,
3736 "api/removed.txt": nil,
3737 "api/system-current.txt": nil,
3738 "api/system-removed.txt": nil,
3739 "api/test-current.txt": nil,
3740 "api/test-removed.txt": nil,
3741 }))
3742
3743 // java_sdk_library installs both impl jar and permission XML
Jooyung Hana57af4a2020-01-23 05:36:59 +00003744 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han58f26ab2019-12-18 15:34:32 +09003745 "javalib/foo.jar",
3746 "etc/permissions/foo.xml",
3747 })
3748 // Permission XML should point to the activated path of impl jar of java_sdk_library
Jiyong Parke3833882020-02-17 17:28:10 +09003749 sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml")
3750 ensureContains(t, sdkLibrary.RuleParams.Command, `<library name=\"foo\" file=\"/apex/myapex/javalib/foo.jar\"`)
Jooyung Han58f26ab2019-12-18 15:34:32 +09003751}
3752
atrost6e126252020-01-27 17:01:16 +00003753func TestCompatConfig(t *testing.T) {
3754 ctx, _ := testApex(t, `
3755 apex {
3756 name: "myapex",
3757 key: "myapex.key",
3758 prebuilts: ["myjar-platform-compat-config"],
3759 java_libs: ["myjar"],
3760 }
3761
3762 apex_key {
3763 name: "myapex.key",
3764 public_key: "testkey.avbpubkey",
3765 private_key: "testkey.pem",
3766 }
3767
3768 platform_compat_config {
3769 name: "myjar-platform-compat-config",
3770 src: ":myjar",
3771 }
3772
3773 java_library {
3774 name: "myjar",
3775 srcs: ["foo/bar/MyClass.java"],
3776 sdk_version: "none",
3777 system_modules: "none",
atrost6e126252020-01-27 17:01:16 +00003778 apex_available: [ "myapex" ],
3779 }
3780 `)
3781 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
3782 "etc/compatconfig/myjar-platform-compat-config.xml",
3783 "javalib/myjar.jar",
3784 })
3785}
3786
Jiyong Park479321d2019-12-16 11:47:12 +09003787func TestRejectNonInstallableJavaLibrary(t *testing.T) {
3788 testApexError(t, `"myjar" is not configured to be compiled into dex`, `
3789 apex {
3790 name: "myapex",
3791 key: "myapex.key",
3792 java_libs: ["myjar"],
3793 }
3794
3795 apex_key {
3796 name: "myapex.key",
3797 public_key: "testkey.avbpubkey",
3798 private_key: "testkey.pem",
3799 }
3800
3801 java_library {
3802 name: "myjar",
3803 srcs: ["foo/bar/MyClass.java"],
3804 sdk_version: "none",
3805 system_modules: "none",
Jiyong Park6b21c7d2020-02-11 09:16:01 +09003806 compile_dex: false,
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003807 apex_available: ["myapex"],
Jiyong Park479321d2019-12-16 11:47:12 +09003808 }
3809 `)
3810}
3811
Jiyong Park7afd1072019-12-30 16:56:33 +09003812func TestCarryRequiredModuleNames(t *testing.T) {
3813 ctx, config := testApex(t, `
3814 apex {
3815 name: "myapex",
3816 key: "myapex.key",
3817 native_shared_libs: ["mylib"],
3818 }
3819
3820 apex_key {
3821 name: "myapex.key",
3822 public_key: "testkey.avbpubkey",
3823 private_key: "testkey.pem",
3824 }
3825
3826 cc_library {
3827 name: "mylib",
3828 srcs: ["mylib.cpp"],
3829 system_shared_libs: [],
3830 stl: "none",
3831 required: ["a", "b"],
3832 host_required: ["c", "d"],
3833 target_required: ["e", "f"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003834 apex_available: [ "myapex" ],
Jiyong Park7afd1072019-12-30 16:56:33 +09003835 }
3836 `)
3837
3838 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
3839 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3840 name := apexBundle.BaseModuleName()
3841 prefix := "TARGET_"
3842 var builder strings.Builder
3843 data.Custom(&builder, name, prefix, "", data)
3844 androidMk := builder.String()
3845 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n")
3846 ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n")
3847 ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n")
3848}
3849
Jiyong Park7cd10e32020-01-14 09:22:18 +09003850func TestSymlinksFromApexToSystem(t *testing.T) {
3851 bp := `
3852 apex {
3853 name: "myapex",
3854 key: "myapex.key",
3855 native_shared_libs: ["mylib"],
3856 java_libs: ["myjar"],
3857 }
3858
Jiyong Park9d677202020-02-19 16:29:35 +09003859 apex {
3860 name: "myapex.updatable",
3861 key: "myapex.key",
3862 native_shared_libs: ["mylib"],
3863 java_libs: ["myjar"],
3864 updatable: true,
3865 }
3866
Jiyong Park7cd10e32020-01-14 09:22:18 +09003867 apex_key {
3868 name: "myapex.key",
3869 public_key: "testkey.avbpubkey",
3870 private_key: "testkey.pem",
3871 }
3872
3873 cc_library {
3874 name: "mylib",
3875 srcs: ["mylib.cpp"],
3876 shared_libs: ["myotherlib"],
3877 system_shared_libs: [],
3878 stl: "none",
3879 apex_available: [
3880 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003881 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003882 "//apex_available:platform",
3883 ],
3884 }
3885
3886 cc_library {
3887 name: "myotherlib",
3888 srcs: ["mylib.cpp"],
3889 system_shared_libs: [],
3890 stl: "none",
3891 apex_available: [
3892 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003893 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003894 "//apex_available:platform",
3895 ],
3896 }
3897
3898 java_library {
3899 name: "myjar",
3900 srcs: ["foo/bar/MyClass.java"],
3901 sdk_version: "none",
3902 system_modules: "none",
3903 libs: ["myotherjar"],
Jiyong Park7cd10e32020-01-14 09:22:18 +09003904 apex_available: [
3905 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003906 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003907 "//apex_available:platform",
3908 ],
3909 }
3910
3911 java_library {
3912 name: "myotherjar",
3913 srcs: ["foo/bar/MyClass.java"],
3914 sdk_version: "none",
3915 system_modules: "none",
3916 apex_available: [
3917 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003918 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003919 "//apex_available:platform",
3920 ],
3921 }
3922 `
3923
3924 ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) {
3925 for _, f := range files {
3926 if f.path == file {
3927 if f.isLink {
3928 t.Errorf("%q is not a real file", file)
3929 }
3930 return
3931 }
3932 }
3933 t.Errorf("%q is not found", file)
3934 }
3935
3936 ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) {
3937 for _, f := range files {
3938 if f.path == file {
3939 if !f.isLink {
3940 t.Errorf("%q is not a symlink", file)
3941 }
3942 return
3943 }
3944 }
3945 t.Errorf("%q is not found", file)
3946 }
3947
Jiyong Park9d677202020-02-19 16:29:35 +09003948 // For unbundled build, symlink shouldn't exist regardless of whether an APEX
3949 // is updatable or not
Jiyong Park7cd10e32020-01-14 09:22:18 +09003950 ctx, _ := testApex(t, bp, withUnbundledBuild)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003951 files := getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003952 ensureRealfileExists(t, files, "javalib/myjar.jar")
3953 ensureRealfileExists(t, files, "lib64/mylib.so")
3954 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3955
Jiyong Park9d677202020-02-19 16:29:35 +09003956 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
3957 ensureRealfileExists(t, files, "javalib/myjar.jar")
3958 ensureRealfileExists(t, files, "lib64/mylib.so")
3959 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3960
3961 // For bundled build, symlink to the system for the non-updatable APEXes only
Jiyong Park7cd10e32020-01-14 09:22:18 +09003962 ctx, _ = testApex(t, bp)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003963 files = getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003964 ensureRealfileExists(t, files, "javalib/myjar.jar")
3965 ensureRealfileExists(t, files, "lib64/mylib.so")
3966 ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
Jiyong Park9d677202020-02-19 16:29:35 +09003967
3968 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
3969 ensureRealfileExists(t, files, "javalib/myjar.jar")
3970 ensureRealfileExists(t, files, "lib64/mylib.so")
3971 ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
Jiyong Park7cd10e32020-01-14 09:22:18 +09003972}
3973
Jiyong Parkd93e1b12020-02-28 15:22:21 +09003974func TestAppBundle(t *testing.T) {
3975 ctx, _ := testApex(t, `
3976 apex {
3977 name: "myapex",
3978 key: "myapex.key",
3979 apps: ["AppFoo"],
3980 }
3981
3982 apex_key {
3983 name: "myapex.key",
3984 public_key: "testkey.avbpubkey",
3985 private_key: "testkey.pem",
3986 }
3987
3988 android_app {
3989 name: "AppFoo",
3990 srcs: ["foo/bar/MyClass.java"],
3991 sdk_version: "none",
3992 system_modules: "none",
3993 apex_available: [ "myapex" ],
3994 }
Jiyong Parkaf8998c2020-02-28 16:51:07 +09003995 `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"}))
Jiyong Parkd93e1b12020-02-28 15:22:21 +09003996
3997 bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config")
3998 content := bundleConfigRule.Args["content"]
3999
4000 ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
Jiyong Parkaf8998c2020-02-28 16:51:07 +09004001 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 +09004002}
4003
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07004004func TestMain(m *testing.M) {
4005 run := func() int {
4006 setUp()
4007 defer tearDown()
4008
4009 return m.Run()
4010 }
4011
4012 os.Exit(run())
4013}