blob: a2dcfafd9fe6aafa55edaf6909761498adbb9ad9 [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 Parkcfaa1642020-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,
153 "testkey2.avbpubkey": nil,
154 "testkey2.pem": nil,
155 "myapex-arm64.apex": nil,
156 "myapex-arm.apex": nil,
157 "frameworks/base/api/current.txt": nil,
158 "framework/aidl/a.aidl": nil,
159 "build/make/core/proguard.flags": nil,
160 "build/make/core/proguard_basic_keeps.flags": nil,
161 "dummy.txt": nil,
Jooyung Han344d5432019-08-23 11:17:39 +0900162 }
163
Colin Crossf9aabd72020-02-15 11:29:50 -0800164 cc.GatherRequiredFilesForTest(fs)
165
Jooyung Han344d5432019-08-23 11:17:39 +0900166 for _, handler := range handlers {
Colin Cross98be1bb2019-12-13 20:41:13 -0800167 // The fs now needs to be populated before creating the config, call handlers twice
168 // for now, once to get any fs changes, and later after the config was created to
169 // set product variables or targets.
170 tempConfig := android.TestArchConfig(buildDir, nil, bp, fs)
171 handler(fs, tempConfig)
Jooyung Han344d5432019-08-23 11:17:39 +0900172 }
173
Colin Cross98be1bb2019-12-13 20:41:13 -0800174 config := android.TestArchConfig(buildDir, nil, bp, fs)
175 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
176 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
177 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
178 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
179 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
180 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
181
182 for _, handler := range handlers {
183 // The fs now needs to be populated before creating the config, call handlers twice
184 // for now, earlier to get any fs changes, and now after the config was created to
185 // set product variables or targets.
186 tempFS := map[string][]byte{}
187 handler(tempFS, config)
188 }
189
190 ctx := android.NewTestArchContext()
191 ctx.RegisterModuleType("apex", BundleFactory)
192 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
193 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
194 ctx.RegisterModuleType("apex_key", ApexKeyFactory)
195 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
196 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
197 ctx.RegisterModuleType("override_apex", overrideApexFactory)
198
Jooyung Hana57af4a2020-01-23 05:36:59 +0000199 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
200 ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
201
Paul Duffin77980a82019-12-19 16:01:36 +0000202 cc.RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross98be1bb2019-12-13 20:41:13 -0800203 ctx.RegisterModuleType("cc_test", cc.TestFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800204 ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory)
205 ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800206 ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory)
atrost6e126252020-01-27 17:01:16 +0000207 ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800208 ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800209 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000210 java.RegisterJavaBuildComponents(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000211 java.RegisterSystemModulesBuildComponents(ctx)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000212 java.RegisterAppBuildComponents(ctx)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900213 ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800214
Colin Cross98be1bb2019-12-13 20:41:13 -0800215 ctx.PreDepsMutators(RegisterPreDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800216 ctx.PostDepsMutators(RegisterPostDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800217
218 ctx.Register(config)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900219
Jooyung Han5c998b92019-06-27 11:30:33 +0900220 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900221}
222
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700223func setUp() {
224 var err error
225 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900226 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700227 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900228 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900229}
230
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700231func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900232 os.RemoveAll(buildDir)
233}
234
Jooyung Han643adc42020-02-27 13:50:06 +0900235// ensure that 'result' equals 'expected'
236func ensureEquals(t *testing.T, result string, expected string) {
237 t.Helper()
238 if result != expected {
239 t.Errorf("%q != %q", expected, result)
240 }
241}
242
Jiyong Park25fc6a92018-11-18 18:02:45 +0900243// ensure that 'result' contains 'expected'
244func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900245 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900246 if !strings.Contains(result, expected) {
247 t.Errorf("%q is not found in %q", expected, result)
248 }
249}
250
251// ensures that 'result' does not contain 'notExpected'
252func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900253 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900254 if strings.Contains(result, notExpected) {
255 t.Errorf("%q is found in %q", notExpected, result)
256 }
257}
258
259func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900260 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900261 if !android.InList(expected, result) {
262 t.Errorf("%q is not found in %v", expected, result)
263 }
264}
265
266func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900267 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900268 if android.InList(notExpected, result) {
269 t.Errorf("%q is found in %v", notExpected, result)
270 }
271}
272
Jooyung Hane1633032019-08-01 17:41:43 +0900273func ensureListEmpty(t *testing.T, result []string) {
274 t.Helper()
275 if len(result) > 0 {
276 t.Errorf("%q is expected to be empty", result)
277 }
278}
279
Jiyong Park25fc6a92018-11-18 18:02:45 +0900280// Minimal test
281func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700282 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900283 apex_defaults {
284 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900285 manifest: ":myapex.manifest",
286 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900287 key: "myapex.key",
288 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800289 multilib: {
290 both: {
291 binaries: ["foo",],
292 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900293 },
Jooyung Han5a80d9f2019-12-23 15:38:34 +0900294 java_libs: ["myjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900295 }
296
Jiyong Park30ca9372019-02-07 16:27:23 +0900297 apex {
298 name: "myapex",
299 defaults: ["myapex-defaults"],
300 }
301
Jiyong Park25fc6a92018-11-18 18:02:45 +0900302 apex_key {
303 name: "myapex.key",
304 public_key: "testkey.avbpubkey",
305 private_key: "testkey.pem",
306 }
307
Jiyong Park809bb722019-02-13 21:33:49 +0900308 filegroup {
309 name: "myapex.manifest",
310 srcs: ["apex_manifest.json"],
311 }
312
313 filegroup {
314 name: "myapex.androidmanifest",
315 srcs: ["AndroidManifest.xml"],
316 }
317
Jiyong Park25fc6a92018-11-18 18:02:45 +0900318 cc_library {
319 name: "mylib",
320 srcs: ["mylib.cpp"],
321 shared_libs: ["mylib2"],
322 system_shared_libs: [],
323 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000324 // TODO: remove //apex_available:platform
325 apex_available: [
326 "//apex_available:platform",
327 "myapex",
328 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900329 }
330
Alex Light3d673592019-01-18 14:37:31 -0800331 cc_binary {
332 name: "foo",
333 srcs: ["mylib.cpp"],
334 compile_multilib: "both",
335 multilib: {
336 lib32: {
337 suffix: "32",
338 },
339 lib64: {
340 suffix: "64",
341 },
342 },
343 symlinks: ["foo_link_"],
344 symlink_preferred_arch: true,
345 system_shared_libs: [],
346 static_executable: true,
347 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000348 apex_available: [ "myapex" ],
Alex Light3d673592019-01-18 14:37:31 -0800349 }
350
Jiyong Park25fc6a92018-11-18 18:02:45 +0900351 cc_library {
352 name: "mylib2",
353 srcs: ["mylib.cpp"],
354 system_shared_libs: [],
355 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900356 notice: "custom_notice",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000357 // TODO: remove //apex_available:platform
358 apex_available: [
359 "//apex_available:platform",
360 "myapex",
361 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900362 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900363
364 java_library {
365 name: "myjar",
366 srcs: ["foo/bar/MyClass.java"],
367 sdk_version: "none",
368 system_modules: "none",
Jiyong Park7f7766d2019-07-25 22:02:35 +0900369 static_libs: ["myotherjar"],
Jiyong Park3ff16992019-12-27 14:11:47 +0900370 libs: ["mysharedjar"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000371 // TODO: remove //apex_available:platform
372 apex_available: [
373 "//apex_available:platform",
374 "myapex",
375 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900376 }
377
378 java_library {
379 name: "myotherjar",
380 srcs: ["foo/bar/MyClass.java"],
381 sdk_version: "none",
382 system_modules: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +0900383 // TODO: remove //apex_available:platform
384 apex_available: [
385 "//apex_available:platform",
386 "myapex",
387 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900388 }
Jiyong Park3ff16992019-12-27 14:11:47 +0900389
390 java_library {
391 name: "mysharedjar",
392 srcs: ["foo/bar/MyClass.java"],
393 sdk_version: "none",
394 system_modules: "none",
Jiyong Park3ff16992019-12-27 14:11:47 +0900395 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900396 `)
397
Sundong Ahnabb64432019-10-22 13:58:29 +0900398 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900399
400 optFlags := apexRule.Args["opt_flags"]
401 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700402 // Ensure that the NOTICE output is being packaged as an asset.
Sundong Ahnabb64432019-10-22 13:58:29 +0900403 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900404
Jiyong Park25fc6a92018-11-18 18:02:45 +0900405 copyCmds := apexRule.Args["copy_commands"]
406
407 // Ensure that main rule creates an output
408 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
409
410 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800411 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900412 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900413
414 // Ensure that apex variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800415 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900416 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900417
418 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800419 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
420 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900421 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
422 // .. but not for java libs
423 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Jiyong Park3ff16992019-12-27 14:11:47 +0900424 ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800425
Colin Cross7113d202019-11-20 16:39:12 -0800426 // Ensure that the platform variant ends with _shared or _common
427 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
428 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900429 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
430 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park3ff16992019-12-27 14:11:47 +0900431 ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common")
432
433 // Ensure that dynamic dependency to java libs are not included
434 ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex")
Alex Light3d673592019-01-18 14:37:31 -0800435
436 // Ensure that all symlinks are present.
437 found_foo_link_64 := false
438 found_foo := false
439 for _, cmd := range strings.Split(copyCmds, " && ") {
Jiyong Park7cd10e32020-01-14 09:22:18 +0900440 if strings.HasPrefix(cmd, "ln -sfn foo64") {
Alex Light3d673592019-01-18 14:37:31 -0800441 if strings.HasSuffix(cmd, "bin/foo") {
442 found_foo = true
443 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
444 found_foo_link_64 = true
445 }
446 }
447 }
448 good := found_foo && found_foo_link_64
449 if !good {
450 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
451 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900452
Sundong Ahnabb64432019-10-22 13:58:29 +0900453 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700454 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700455 if len(noticeInputs) != 2 {
456 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900457 }
458 ensureListContains(t, noticeInputs, "NOTICE")
459 ensureListContains(t, noticeInputs, "custom_notice")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900460
461 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 +0900462 ensureListContains(t, depsInfo, "myjar <- myapex")
463 ensureListContains(t, depsInfo, "mylib <- myapex")
464 ensureListContains(t, depsInfo, "mylib2 <- mylib")
465 ensureListContains(t, depsInfo, "myotherjar <- myjar")
466 ensureListContains(t, depsInfo, "mysharedjar (external) <- myjar")
Alex Light5098a612018-11-29 17:12:15 -0800467}
468
Jooyung Hanf21c7972019-12-16 22:32:06 +0900469func TestDefaults(t *testing.T) {
470 ctx, _ := testApex(t, `
471 apex_defaults {
472 name: "myapex-defaults",
473 key: "myapex.key",
474 prebuilts: ["myetc"],
475 native_shared_libs: ["mylib"],
476 java_libs: ["myjar"],
477 apps: ["AppFoo"],
478 }
479
480 prebuilt_etc {
481 name: "myetc",
482 src: "myprebuilt",
483 }
484
485 apex {
486 name: "myapex",
487 defaults: ["myapex-defaults"],
488 }
489
490 apex_key {
491 name: "myapex.key",
492 public_key: "testkey.avbpubkey",
493 private_key: "testkey.pem",
494 }
495
496 cc_library {
497 name: "mylib",
498 system_shared_libs: [],
499 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000500 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900501 }
502
503 java_library {
504 name: "myjar",
505 srcs: ["foo/bar/MyClass.java"],
506 sdk_version: "none",
507 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000508 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900509 }
510
511 android_app {
512 name: "AppFoo",
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 `)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000519 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Hanf21c7972019-12-16 22:32:06 +0900520 "etc/myetc",
521 "javalib/myjar.jar",
522 "lib64/mylib.so",
523 "app/AppFoo/AppFoo.apk",
524 })
525}
526
Jooyung Han01a3ee22019-11-02 02:52:25 +0900527func TestApexManifest(t *testing.T) {
528 ctx, _ := testApex(t, `
529 apex {
530 name: "myapex",
531 key: "myapex.key",
532 }
533
534 apex_key {
535 name: "myapex.key",
536 public_key: "testkey.avbpubkey",
537 private_key: "testkey.pem",
538 }
539 `)
540
541 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han214bf372019-11-12 13:03:50 +0900542 args := module.Rule("apexRule").Args
543 if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() {
544 t.Error("manifest should be apex_manifest.pb, but " + manifest)
545 }
Jooyung Han01a3ee22019-11-02 02:52:25 +0900546}
547
Alex Light5098a612018-11-29 17:12:15 -0800548func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700549 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800550 apex {
551 name: "myapex",
552 key: "myapex.key",
553 payload_type: "zip",
554 native_shared_libs: ["mylib"],
555 }
556
557 apex_key {
558 name: "myapex.key",
559 public_key: "testkey.avbpubkey",
560 private_key: "testkey.pem",
561 }
562
563 cc_library {
564 name: "mylib",
565 srcs: ["mylib.cpp"],
566 shared_libs: ["mylib2"],
567 system_shared_libs: [],
568 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000569 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800570 }
571
572 cc_library {
573 name: "mylib2",
574 srcs: ["mylib.cpp"],
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
Sundong Ahnabb64432019-10-22 13:58:29 +0900581 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
Alex Light5098a612018-11-29 17:12:15 -0800582 copyCmds := zipApexRule.Args["copy_commands"]
583
584 // Ensure that main rule creates an output
585 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
586
587 // Ensure that APEX variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800588 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800589
590 // Ensure that APEX variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800591 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800592
593 // Ensure that both direct and indirect deps are copied into apex
594 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
595 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900596}
597
598func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700599 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900600 apex {
601 name: "myapex",
602 key: "myapex.key",
603 native_shared_libs: ["mylib", "mylib3"],
604 }
605
606 apex_key {
607 name: "myapex.key",
608 public_key: "testkey.avbpubkey",
609 private_key: "testkey.pem",
610 }
611
612 cc_library {
613 name: "mylib",
614 srcs: ["mylib.cpp"],
615 shared_libs: ["mylib2", "mylib3"],
616 system_shared_libs: [],
617 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000618 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900619 }
620
621 cc_library {
622 name: "mylib2",
623 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900624 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900625 system_shared_libs: [],
626 stl: "none",
627 stubs: {
628 versions: ["1", "2", "3"],
629 },
630 }
631
632 cc_library {
633 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900634 srcs: ["mylib.cpp"],
635 shared_libs: ["mylib4"],
636 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900637 stl: "none",
638 stubs: {
639 versions: ["10", "11", "12"],
640 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000641 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900642 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900643
644 cc_library {
645 name: "mylib4",
646 srcs: ["mylib.cpp"],
647 system_shared_libs: [],
648 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000649 apex_available: [ "myapex" ],
Jiyong Park28d395a2018-12-07 22:42:47 +0900650 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900651 `)
652
Sundong Ahnabb64432019-10-22 13:58:29 +0900653 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900654 copyCmds := apexRule.Args["copy_commands"]
655
656 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800657 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900658
659 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800660 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900661
662 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800663 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900664
Colin Cross7113d202019-11-20 16:39:12 -0800665 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900666
667 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900668 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900669 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900670 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900671
672 // 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 -0800673 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900674 // .. and not linking to the stubs variant of mylib3
Colin Cross7113d202019-11-20 16:39:12 -0800675 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900676
677 // Ensure that stubs libs are built without -include flags
Jiyong Park0f80c182020-01-31 02:49:53 +0900678 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900679 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900680
681 // Ensure that genstub is invoked with --apex
Jiyong Park3ff16992019-12-27 14:11:47 +0900682 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"])
Jooyung Han671f1ce2019-12-17 12:47:13 +0900683
Jooyung Hana57af4a2020-01-23 05:36:59 +0000684 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han671f1ce2019-12-17 12:47:13 +0900685 "lib64/mylib.so",
686 "lib64/mylib3.so",
687 "lib64/mylib4.so",
688 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900689}
690
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900691func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700692 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900693 apex {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900694 name: "myapex2",
695 key: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900696 native_shared_libs: ["mylib"],
697 }
698
699 apex_key {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900700 name: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900701 public_key: "testkey.avbpubkey",
702 private_key: "testkey.pem",
703 }
704
705 cc_library {
706 name: "mylib",
707 srcs: ["mylib.cpp"],
708 shared_libs: ["libfoo#10"],
Jiyong Park678c8812020-02-07 17:25:49 +0900709 static_libs: ["libbaz"],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900710 system_shared_libs: [],
711 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000712 apex_available: [ "myapex2" ],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900713 }
714
715 cc_library {
716 name: "libfoo",
717 srcs: ["mylib.cpp"],
718 shared_libs: ["libbar"],
719 system_shared_libs: [],
720 stl: "none",
721 stubs: {
722 versions: ["10", "20", "30"],
723 },
724 }
725
726 cc_library {
727 name: "libbar",
728 srcs: ["mylib.cpp"],
729 system_shared_libs: [],
730 stl: "none",
731 }
732
Jiyong Park678c8812020-02-07 17:25:49 +0900733 cc_library_static {
734 name: "libbaz",
735 srcs: ["mylib.cpp"],
736 system_shared_libs: [],
737 stl: "none",
738 apex_available: [ "myapex2" ],
739 }
740
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900741 `)
742
Jiyong Park83dc74b2020-01-14 18:38:44 +0900743 apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900744 copyCmds := apexRule.Args["copy_commands"]
745
746 // Ensure that direct non-stubs dep is always included
747 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
748
749 // Ensure that indirect stubs dep is not included
750 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
751
752 // Ensure that dependency of stubs is not included
753 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
754
Jiyong Park83dc74b2020-01-14 18:38:44 +0900755 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900756
757 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900758 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900759 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900760 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900761
Jiyong Park3ff16992019-12-27 14:11:47 +0900762 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900763
764 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
765 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900766
767 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 +0900768
769 ensureListContains(t, depsInfo, "mylib <- myapex2")
770 ensureListContains(t, depsInfo, "libbaz <- mylib")
771 ensureListContains(t, depsInfo, "libfoo (external) <- mylib")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900772}
773
Jooyung Hand3639552019-08-09 12:57:43 +0900774func TestApexWithRuntimeLibsDependency(t *testing.T) {
775 /*
776 myapex
777 |
778 v (runtime_libs)
779 mylib ------+------> libfoo [provides stub]
780 |
781 `------> libbar
782 */
783 ctx, _ := testApex(t, `
784 apex {
785 name: "myapex",
786 key: "myapex.key",
787 native_shared_libs: ["mylib"],
788 }
789
790 apex_key {
791 name: "myapex.key",
792 public_key: "testkey.avbpubkey",
793 private_key: "testkey.pem",
794 }
795
796 cc_library {
797 name: "mylib",
798 srcs: ["mylib.cpp"],
799 runtime_libs: ["libfoo", "libbar"],
800 system_shared_libs: [],
801 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000802 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900803 }
804
805 cc_library {
806 name: "libfoo",
807 srcs: ["mylib.cpp"],
808 system_shared_libs: [],
809 stl: "none",
810 stubs: {
811 versions: ["10", "20", "30"],
812 },
813 }
814
815 cc_library {
816 name: "libbar",
817 srcs: ["mylib.cpp"],
818 system_shared_libs: [],
819 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000820 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900821 }
822
823 `)
824
Sundong Ahnabb64432019-10-22 13:58:29 +0900825 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Hand3639552019-08-09 12:57:43 +0900826 copyCmds := apexRule.Args["copy_commands"]
827
828 // Ensure that direct non-stubs dep is always included
829 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
830
831 // Ensure that indirect stubs dep is not included
832 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
833
834 // Ensure that runtime_libs dep in included
835 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
836
Sundong Ahnabb64432019-10-22 13:58:29 +0900837 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900838 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
839 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900840
841}
842
Jooyung Han9c80bae2019-08-20 17:30:57 +0900843func TestApexDependencyToLLNDK(t *testing.T) {
844 ctx, _ := testApex(t, `
845 apex {
846 name: "myapex",
847 key: "myapex.key",
848 use_vendor: true,
849 native_shared_libs: ["mylib"],
850 }
851
852 apex_key {
853 name: "myapex.key",
854 public_key: "testkey.avbpubkey",
855 private_key: "testkey.pem",
856 }
857
858 cc_library {
859 name: "mylib",
860 srcs: ["mylib.cpp"],
861 vendor_available: true,
862 shared_libs: ["libbar"],
863 system_shared_libs: [],
864 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000865 apex_available: [ "myapex" ],
Jooyung Han9c80bae2019-08-20 17:30:57 +0900866 }
867
868 cc_library {
869 name: "libbar",
870 srcs: ["mylib.cpp"],
871 system_shared_libs: [],
872 stl: "none",
873 }
874
875 llndk_library {
876 name: "libbar",
877 symbol_file: "",
878 }
Jooyung Handc782442019-11-01 03:14:38 +0900879 `, func(fs map[string][]byte, config android.Config) {
880 setUseVendorWhitelistForTest(config, []string{"myapex"})
881 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900882
Sundong Ahnabb64432019-10-22 13:58:29 +0900883 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900884 copyCmds := apexRule.Args["copy_commands"]
885
886 // Ensure that LLNDK dep is not included
887 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
888
Sundong Ahnabb64432019-10-22 13:58:29 +0900889 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900890 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900891
892 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900893 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900894
895}
896
Jiyong Park25fc6a92018-11-18 18:02:45 +0900897func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700898 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900899 apex {
900 name: "myapex",
901 key: "myapex.key",
902 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
903 }
904
905 apex_key {
906 name: "myapex.key",
907 public_key: "testkey.avbpubkey",
908 private_key: "testkey.pem",
909 }
910
911 cc_library {
912 name: "mylib",
913 srcs: ["mylib.cpp"],
914 shared_libs: ["libdl#27"],
915 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000916 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900917 }
918
919 cc_library_shared {
920 name: "mylib_shared",
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 {
Jiyong Parkb0788572018-12-20 22:10:17 +0900928 name: "libBootstrap",
929 srcs: ["mylib.cpp"],
930 stl: "none",
931 bootstrap: true,
932 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900933 `)
934
Sundong Ahnabb64432019-10-22 13:58:29 +0900935 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900936 copyCmds := apexRule.Args["copy_commands"]
937
938 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800939 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900940 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
941 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900942
943 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900944 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900945
Colin Cross7113d202019-11-20 16:39:12 -0800946 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
947 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
948 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900949
950 // For dependency to libc
951 // Ensure that mylib is linking with the latest version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +0900952 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900953 // ... and not linking to the non-stub (impl) variant
Jiyong Park3ff16992019-12-27 14:11:47 +0900954 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900955 // ... Cflags from stub is correctly exported to mylib
956 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
957 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
958
959 // For dependency to libm
960 // Ensure that mylib is linking with the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -0800961 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900962 // ... and not linking to the stub variant
Jiyong Park3ff16992019-12-27 14:11:47 +0900963 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900964 // ... and is not compiling with the stub
965 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
966 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
967
968 // For dependency to libdl
969 // Ensure that mylib is linking with the specified version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +0900970 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900971 // ... and not linking to the other versions of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +0900972 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so")
973 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900974 // ... and not linking to the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -0800975 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900976 // ... Cflags from stub is correctly exported to mylib
977 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
978 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900979
980 // Ensure that libBootstrap is depending on the platform variant of bionic libs
Colin Cross7113d202019-11-20 16:39:12 -0800981 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"]
982 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so")
983 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so")
984 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900985}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900986
Jooyung Han03b51852020-02-26 22:45:42 +0900987func TestApexUseStubsAccordingToMinSdkVersionInUnbundledBuild(t *testing.T) {
988 // there are three links between liba --> libz
989 // 1) myapex -> libx -> liba -> libz : this should be #2 link, but fallback to #1
990 // 2) otherapex -> liby -> liba -> libz : this should be #3 link
991 // 3) (platform) -> liba -> libz : this should be non-stub link
992 ctx, _ := testApex(t, `
993 apex {
994 name: "myapex",
995 key: "myapex.key",
996 native_shared_libs: ["libx"],
997 min_sdk_version: "2",
998 }
999
1000 apex {
1001 name: "otherapex",
1002 key: "myapex.key",
1003 native_shared_libs: ["liby"],
1004 min_sdk_version: "3",
1005 }
1006
1007 apex_key {
1008 name: "myapex.key",
1009 public_key: "testkey.avbpubkey",
1010 private_key: "testkey.pem",
1011 }
1012
1013 cc_library {
1014 name: "libx",
1015 shared_libs: ["liba"],
1016 system_shared_libs: [],
1017 stl: "none",
1018 apex_available: [ "myapex" ],
1019 }
1020
1021 cc_library {
1022 name: "liby",
1023 shared_libs: ["liba"],
1024 system_shared_libs: [],
1025 stl: "none",
1026 apex_available: [ "otherapex" ],
1027 }
1028
1029 cc_library {
1030 name: "liba",
1031 shared_libs: ["libz"],
1032 system_shared_libs: [],
1033 stl: "none",
1034 apex_available: [
1035 "//apex_available:anyapex",
1036 "//apex_available:platform",
1037 ],
1038 }
1039
1040 cc_library {
1041 name: "libz",
1042 system_shared_libs: [],
1043 stl: "none",
1044 stubs: {
1045 versions: ["1", "3"],
1046 },
1047 }
1048 `, withUnbundledBuild)
1049
1050 expectLink := func(from, from_variant, to, to_variant string) {
1051 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1052 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1053 }
1054 expectNoLink := func(from, from_variant, to, to_variant string) {
1055 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1056 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1057 }
1058 // platform liba is linked to non-stub version
1059 expectLink("liba", "shared", "libz", "shared")
1060 // liba in myapex is linked to #1
1061 expectLink("liba", "shared_myapex", "libz", "shared_1")
1062 expectNoLink("liba", "shared_myapex", "libz", "shared_3")
1063 expectNoLink("liba", "shared_myapex", "libz", "shared")
1064 // liba in otherapex is linked to #3
1065 expectLink("liba", "shared_otherapex", "libz", "shared_3")
1066 expectNoLink("liba", "shared_otherapex", "libz", "shared_1")
1067 expectNoLink("liba", "shared_otherapex", "libz", "shared")
1068}
1069
1070func TestApexMinSdkVersionDefaultsToLatest(t *testing.T) {
1071 ctx, _ := testApex(t, `
1072 apex {
1073 name: "myapex",
1074 key: "myapex.key",
1075 native_shared_libs: ["libx"],
1076 }
1077
1078 apex_key {
1079 name: "myapex.key",
1080 public_key: "testkey.avbpubkey",
1081 private_key: "testkey.pem",
1082 }
1083
1084 cc_library {
1085 name: "libx",
1086 shared_libs: ["libz"],
1087 system_shared_libs: [],
1088 stl: "none",
1089 apex_available: [ "myapex" ],
1090 }
1091
1092 cc_library {
1093 name: "libz",
1094 system_shared_libs: [],
1095 stl: "none",
1096 stubs: {
1097 versions: ["1", "2"],
1098 },
1099 }
1100 `)
1101
1102 expectLink := func(from, from_variant, to, to_variant string) {
1103 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1104 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1105 }
1106 expectNoLink := func(from, from_variant, to, to_variant string) {
1107 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1108 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1109 }
1110 expectLink("libx", "shared_myapex", "libz", "shared_2")
1111 expectNoLink("libx", "shared_myapex", "libz", "shared_1")
1112 expectNoLink("libx", "shared_myapex", "libz", "shared")
1113}
1114
1115func TestPlatformUsesLatestStubsFromApexes(t *testing.T) {
1116 ctx, _ := testApex(t, `
1117 apex {
1118 name: "myapex",
1119 key: "myapex.key",
1120 native_shared_libs: ["libx"],
1121 }
1122
1123 apex_key {
1124 name: "myapex.key",
1125 public_key: "testkey.avbpubkey",
1126 private_key: "testkey.pem",
1127 }
1128
1129 cc_library {
1130 name: "libx",
1131 system_shared_libs: [],
1132 stl: "none",
1133 apex_available: [ "myapex" ],
1134 stubs: {
1135 versions: ["1", "2"],
1136 },
1137 }
1138
1139 cc_library {
1140 name: "libz",
1141 shared_libs: ["libx"],
1142 system_shared_libs: [],
1143 stl: "none",
1144 }
1145 `)
1146
1147 expectLink := func(from, from_variant, to, to_variant string) {
1148 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1149 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1150 }
1151 expectNoLink := func(from, from_variant, to, to_variant string) {
1152 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1153 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1154 }
1155 expectLink("libz", "shared", "libx", "shared_2")
1156 expectNoLink("libz", "shared", "libz", "shared_1")
1157 expectNoLink("libz", "shared", "libz", "shared")
1158}
1159
1160func TestQApexesUseLatestStubsInBundledBuilds(t *testing.T) {
1161 ctx, _ := testApex(t, `
1162 apex {
1163 name: "myapex",
1164 key: "myapex.key",
1165 native_shared_libs: ["libx"],
1166 min_sdk_version: "29",
1167 }
1168
1169 apex_key {
1170 name: "myapex.key",
1171 public_key: "testkey.avbpubkey",
1172 private_key: "testkey.pem",
1173 }
1174
1175 cc_library {
1176 name: "libx",
1177 shared_libs: ["libbar"],
1178 apex_available: [ "myapex" ],
1179 }
1180
1181 cc_library {
1182 name: "libbar",
1183 stubs: {
1184 versions: ["29", "30"],
1185 },
1186 }
1187 `)
1188 expectLink := func(from, from_variant, to, to_variant string) {
1189 ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld")
1190 libFlags := ld.Args["libFlags"]
1191 ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1192 }
1193 expectLink("libx", "shared_myapex", "libbar", "shared_30")
1194}
1195
1196func TestQTargetApexUseStaticUnwinder(t *testing.T) {
1197 ctx, _ := testApex(t, `
1198 apex {
1199 name: "myapex",
1200 key: "myapex.key",
1201 native_shared_libs: ["libx"],
1202 min_sdk_version: "29",
1203 }
1204
1205 apex_key {
1206 name: "myapex.key",
1207 public_key: "testkey.avbpubkey",
1208 private_key: "testkey.pem",
1209 }
1210
1211 cc_library {
1212 name: "libx",
1213 apex_available: [ "myapex" ],
1214 }
1215
1216 `, withUnbundledBuild)
1217
1218 // ensure apex variant of c++ is linked with static unwinder
1219 cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module)
1220 ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
1221 // note that platform variant is not.
1222 cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module)
1223 ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
1224
1225 libFlags := ctx.ModuleForTests("libx", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
1226 ensureContains(t, libFlags, "android_arm64_armv8-a_shared_myapex/libc++.so")
1227 ensureContains(t, libFlags, "android_arm64_armv8-a_shared_29/libc.so") // min_sdk_version applied
1228}
1229
1230func TestInvalidMinSdkVersion(t *testing.T) {
1231 testApexError(t, `"libz" .*: min_sdk_version is set 29.*`, `
1232 apex {
1233 name: "myapex",
1234 key: "myapex.key",
1235 native_shared_libs: ["libx"],
1236 min_sdk_version: "29",
1237 }
1238
1239 apex_key {
1240 name: "myapex.key",
1241 public_key: "testkey.avbpubkey",
1242 private_key: "testkey.pem",
1243 }
1244
1245 cc_library {
1246 name: "libx",
1247 shared_libs: ["libz"],
1248 system_shared_libs: [],
1249 stl: "none",
1250 apex_available: [ "myapex" ],
1251 }
1252
1253 cc_library {
1254 name: "libz",
1255 system_shared_libs: [],
1256 stl: "none",
1257 stubs: {
1258 versions: ["30"],
1259 },
1260 }
1261 `, withUnbundledBuild)
1262
1263 testApexError(t, `"myapex" .*: min_sdk_version: should be .*`, `
1264 apex {
1265 name: "myapex",
1266 key: "myapex.key",
1267 min_sdk_version: "R",
1268 }
1269
1270 apex_key {
1271 name: "myapex.key",
1272 public_key: "testkey.avbpubkey",
1273 private_key: "testkey.pem",
1274 }
1275 `)
1276}
1277
Jiyong Park7c2ee712018-12-07 00:42:25 +09001278func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001279 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +09001280 apex {
1281 name: "myapex",
1282 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001283 native_shared_libs: ["mylib"],
1284 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +09001285 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001286 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +09001287 }
1288
1289 apex_key {
1290 name: "myapex.key",
1291 public_key: "testkey.avbpubkey",
1292 private_key: "testkey.pem",
1293 }
1294
1295 prebuilt_etc {
1296 name: "myetc",
1297 src: "myprebuilt",
1298 sub_dir: "foo/bar",
1299 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001300
1301 cc_library {
1302 name: "mylib",
1303 srcs: ["mylib.cpp"],
1304 relative_install_path: "foo/bar",
1305 system_shared_libs: [],
1306 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001307 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001308 }
1309
1310 cc_binary {
1311 name: "mybin",
1312 srcs: ["mylib.cpp"],
1313 relative_install_path: "foo/bar",
1314 system_shared_libs: [],
1315 static_executable: true,
1316 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001317 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001318 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001319 `)
1320
Sundong Ahnabb64432019-10-22 13:58:29 +09001321 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001322 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1323
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001324 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001325 ensureListContains(t, dirs, "etc")
1326 ensureListContains(t, dirs, "etc/foo")
1327 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001328 ensureListContains(t, dirs, "lib64")
1329 ensureListContains(t, dirs, "lib64/foo")
1330 ensureListContains(t, dirs, "lib64/foo/bar")
1331 ensureListContains(t, dirs, "lib")
1332 ensureListContains(t, dirs, "lib/foo")
1333 ensureListContains(t, dirs, "lib/foo/bar")
1334
Jiyong Parkbd13e442019-03-15 18:10:35 +09001335 ensureListContains(t, dirs, "bin")
1336 ensureListContains(t, dirs, "bin/foo")
1337 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001338}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001339
1340func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001341 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001342 apex {
1343 name: "myapex",
1344 key: "myapex.key",
1345 native_shared_libs: ["mylib"],
1346 use_vendor: true,
1347 }
1348
1349 apex_key {
1350 name: "myapex.key",
1351 public_key: "testkey.avbpubkey",
1352 private_key: "testkey.pem",
1353 }
1354
1355 cc_library {
1356 name: "mylib",
1357 srcs: ["mylib.cpp"],
1358 shared_libs: ["mylib2"],
1359 system_shared_libs: [],
1360 vendor_available: true,
1361 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001362 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001363 }
1364
1365 cc_library {
1366 name: "mylib2",
1367 srcs: ["mylib.cpp"],
1368 system_shared_libs: [],
1369 vendor_available: true,
1370 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001371 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001372 }
Jooyung Handc782442019-11-01 03:14:38 +09001373 `, func(fs map[string][]byte, config android.Config) {
1374 setUseVendorWhitelistForTest(config, []string{"myapex"})
1375 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001376
1377 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001378 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001379 for _, implicit := range i.Implicits {
1380 inputsList = append(inputsList, implicit.String())
1381 }
1382 }
1383 inputsString := strings.Join(inputsList, " ")
1384
1385 // ensure that the apex includes vendor variants of the direct and indirect deps
Colin Crossfb0c16e2019-11-20 17:12:35 -08001386 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so")
1387 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001388
1389 // ensure that the apex does not include core variants
Colin Cross7113d202019-11-20 16:39:12 -08001390 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so")
1391 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001392}
Jiyong Park16e91a02018-12-20 18:18:08 +09001393
Jooyung Handc782442019-11-01 03:14:38 +09001394func TestUseVendorRestriction(t *testing.T) {
1395 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1396 apex {
1397 name: "myapex",
1398 key: "myapex.key",
1399 use_vendor: true,
1400 }
1401 apex_key {
1402 name: "myapex.key",
1403 public_key: "testkey.avbpubkey",
1404 private_key: "testkey.pem",
1405 }
1406 `, func(fs map[string][]byte, config android.Config) {
1407 setUseVendorWhitelistForTest(config, []string{""})
1408 })
1409 // no error with whitelist
1410 testApex(t, `
1411 apex {
1412 name: "myapex",
1413 key: "myapex.key",
1414 use_vendor: true,
1415 }
1416 apex_key {
1417 name: "myapex.key",
1418 public_key: "testkey.avbpubkey",
1419 private_key: "testkey.pem",
1420 }
1421 `, func(fs map[string][]byte, config android.Config) {
1422 setUseVendorWhitelistForTest(config, []string{"myapex"})
1423 })
1424}
1425
Jooyung Han5c998b92019-06-27 11:30:33 +09001426func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1427 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1428 apex {
1429 name: "myapex",
1430 key: "myapex.key",
1431 native_shared_libs: ["mylib"],
1432 use_vendor: true,
1433 }
1434
1435 apex_key {
1436 name: "myapex.key",
1437 public_key: "testkey.avbpubkey",
1438 private_key: "testkey.pem",
1439 }
1440
1441 cc_library {
1442 name: "mylib",
1443 srcs: ["mylib.cpp"],
1444 system_shared_libs: [],
1445 stl: "none",
1446 }
1447 `)
1448}
1449
Jiyong Park16e91a02018-12-20 18:18:08 +09001450func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001451 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001452 apex {
1453 name: "myapex",
1454 key: "myapex.key",
1455 native_shared_libs: ["mylib"],
1456 }
1457
1458 apex_key {
1459 name: "myapex.key",
1460 public_key: "testkey.avbpubkey",
1461 private_key: "testkey.pem",
1462 }
1463
1464 cc_library {
1465 name: "mylib",
1466 srcs: ["mylib.cpp"],
1467 system_shared_libs: [],
1468 stl: "none",
1469 stubs: {
1470 versions: ["1", "2", "3"],
1471 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001472 apex_available: [
1473 "//apex_available:platform",
1474 "myapex",
1475 ],
Jiyong Park16e91a02018-12-20 18:18:08 +09001476 }
1477
1478 cc_binary {
1479 name: "not_in_apex",
1480 srcs: ["mylib.cpp"],
1481 static_libs: ["mylib"],
1482 static_executable: true,
1483 system_shared_libs: [],
1484 stl: "none",
1485 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001486 `)
1487
Colin Cross7113d202019-11-20 16:39:12 -08001488 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
Jiyong Park16e91a02018-12-20 18:18:08 +09001489
1490 // Ensure that not_in_apex is linking with the static variant of mylib
Colin Cross7113d202019-11-20 16:39:12 -08001491 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001492}
Jiyong Park9335a262018-12-24 11:31:58 +09001493
1494func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001495 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001496 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001497 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001498 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001499 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001500 native_shared_libs: ["mylib"],
Jooyung Han54aca7b2019-11-20 02:26:02 +09001501 file_contexts: ":myapex-file_contexts",
Jiyong Park9335a262018-12-24 11:31:58 +09001502 }
1503
1504 cc_library {
1505 name: "mylib",
1506 srcs: ["mylib.cpp"],
1507 system_shared_libs: [],
1508 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001509 apex_available: [ "myapex_keytest" ],
Jiyong Park9335a262018-12-24 11:31:58 +09001510 }
1511
1512 apex_key {
1513 name: "myapex.key",
1514 public_key: "testkey.avbpubkey",
1515 private_key: "testkey.pem",
1516 }
1517
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001518 android_app_certificate {
1519 name: "myapex.certificate",
1520 certificate: "testkey",
1521 }
1522
1523 android_app_certificate {
1524 name: "myapex.certificate.override",
1525 certificate: "testkey.override",
1526 }
1527
Jiyong Park9335a262018-12-24 11:31:58 +09001528 `)
1529
1530 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001531 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001532
1533 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1534 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1535 "vendor/foo/devkeys/testkey.avbpubkey")
1536 }
1537 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1538 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1539 "vendor/foo/devkeys/testkey.pem")
1540 }
1541
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001542 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001543 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001544 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001545 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001546 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001547 }
1548}
Jiyong Park58e364a2019-01-19 19:24:06 +09001549
Jooyung Hanf121a652019-12-17 14:30:11 +09001550func TestCertificate(t *testing.T) {
1551 t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) {
1552 ctx, _ := testApex(t, `
1553 apex {
1554 name: "myapex",
1555 key: "myapex.key",
1556 }
1557 apex_key {
1558 name: "myapex.key",
1559 public_key: "testkey.avbpubkey",
1560 private_key: "testkey.pem",
1561 }`)
1562 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1563 expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8"
1564 if actual := rule.Args["certificates"]; actual != expected {
1565 t.Errorf("certificates should be %q, not %q", expected, actual)
1566 }
1567 })
1568 t.Run("override when unspecified", func(t *testing.T) {
1569 ctx, _ := testApex(t, `
1570 apex {
1571 name: "myapex_keytest",
1572 key: "myapex.key",
1573 file_contexts: ":myapex-file_contexts",
1574 }
1575 apex_key {
1576 name: "myapex.key",
1577 public_key: "testkey.avbpubkey",
1578 private_key: "testkey.pem",
1579 }
1580 android_app_certificate {
1581 name: "myapex.certificate.override",
1582 certificate: "testkey.override",
1583 }`)
1584 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1585 expected := "testkey.override.x509.pem testkey.override.pk8"
1586 if actual := rule.Args["certificates"]; actual != expected {
1587 t.Errorf("certificates should be %q, not %q", expected, actual)
1588 }
1589 })
1590 t.Run("if specified as :module, it respects the prop", func(t *testing.T) {
1591 ctx, _ := testApex(t, `
1592 apex {
1593 name: "myapex",
1594 key: "myapex.key",
1595 certificate: ":myapex.certificate",
1596 }
1597 apex_key {
1598 name: "myapex.key",
1599 public_key: "testkey.avbpubkey",
1600 private_key: "testkey.pem",
1601 }
1602 android_app_certificate {
1603 name: "myapex.certificate",
1604 certificate: "testkey",
1605 }`)
1606 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1607 expected := "testkey.x509.pem testkey.pk8"
1608 if actual := rule.Args["certificates"]; actual != expected {
1609 t.Errorf("certificates should be %q, not %q", expected, actual)
1610 }
1611 })
1612 t.Run("override when specifiec as <:module>", func(t *testing.T) {
1613 ctx, _ := testApex(t, `
1614 apex {
1615 name: "myapex_keytest",
1616 key: "myapex.key",
1617 file_contexts: ":myapex-file_contexts",
1618 certificate: ":myapex.certificate",
1619 }
1620 apex_key {
1621 name: "myapex.key",
1622 public_key: "testkey.avbpubkey",
1623 private_key: "testkey.pem",
1624 }
1625 android_app_certificate {
1626 name: "myapex.certificate.override",
1627 certificate: "testkey.override",
1628 }`)
1629 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1630 expected := "testkey.override.x509.pem testkey.override.pk8"
1631 if actual := rule.Args["certificates"]; actual != expected {
1632 t.Errorf("certificates should be %q, not %q", expected, actual)
1633 }
1634 })
1635 t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) {
1636 ctx, _ := testApex(t, `
1637 apex {
1638 name: "myapex",
1639 key: "myapex.key",
1640 certificate: "testkey",
1641 }
1642 apex_key {
1643 name: "myapex.key",
1644 public_key: "testkey.avbpubkey",
1645 private_key: "testkey.pem",
1646 }`)
1647 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1648 expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8"
1649 if actual := rule.Args["certificates"]; actual != expected {
1650 t.Errorf("certificates should be %q, not %q", expected, actual)
1651 }
1652 })
1653 t.Run("override when specified as <name>", func(t *testing.T) {
1654 ctx, _ := testApex(t, `
1655 apex {
1656 name: "myapex_keytest",
1657 key: "myapex.key",
1658 file_contexts: ":myapex-file_contexts",
1659 certificate: "testkey",
1660 }
1661 apex_key {
1662 name: "myapex.key",
1663 public_key: "testkey.avbpubkey",
1664 private_key: "testkey.pem",
1665 }
1666 android_app_certificate {
1667 name: "myapex.certificate.override",
1668 certificate: "testkey.override",
1669 }`)
1670 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1671 expected := "testkey.override.x509.pem testkey.override.pk8"
1672 if actual := rule.Args["certificates"]; actual != expected {
1673 t.Errorf("certificates should be %q, not %q", expected, actual)
1674 }
1675 })
1676}
1677
Jiyong Park58e364a2019-01-19 19:24:06 +09001678func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001679 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001680 apex {
1681 name: "myapex",
1682 key: "myapex.key",
Jooyung Hanc87a0592020-03-02 17:44:33 +09001683 native_shared_libs: ["mylib", "mylib2"],
Jiyong Park58e364a2019-01-19 19:24:06 +09001684 }
1685
1686 apex {
1687 name: "otherapex",
1688 key: "myapex.key",
Jooyung Hanc87a0592020-03-02 17:44:33 +09001689 native_shared_libs: ["mylib", "mylib2"],
Jooyung Hanccce2f22020-03-07 03:45:53 +09001690 min_sdk_version: "29",
Jiyong Park58e364a2019-01-19 19:24:06 +09001691 }
1692
1693 apex_key {
1694 name: "myapex.key",
1695 public_key: "testkey.avbpubkey",
1696 private_key: "testkey.pem",
1697 }
1698
1699 cc_library {
1700 name: "mylib",
1701 srcs: ["mylib.cpp"],
1702 system_shared_libs: [],
1703 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001704 apex_available: [
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001705 "myapex",
1706 "otherapex",
1707 ],
Jiyong Park58e364a2019-01-19 19:24:06 +09001708 }
Jooyung Hanc87a0592020-03-02 17:44:33 +09001709 cc_library {
1710 name: "mylib2",
1711 srcs: ["mylib.cpp"],
1712 system_shared_libs: [],
1713 stl: "none",
1714 apex_available: [
1715 "myapex",
1716 "otherapex",
1717 ],
1718 use_apex_name_macro: true,
1719 }
Jiyong Park58e364a2019-01-19 19:24:06 +09001720 `)
1721
Jooyung Hanc87a0592020-03-02 17:44:33 +09001722 // non-APEX variant does not have __ANDROID_APEX__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001723 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001724 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Hanccce2f22020-03-07 03:45:53 +09001725 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
Jooyung Hanc87a0592020-03-02 17:44:33 +09001726
Jooyung Hanccce2f22020-03-07 03:45:53 +09001727 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Jooyung Hanc87a0592020-03-02 17:44:33 +09001728 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
1729 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Hanccce2f22020-03-07 03:45:53 +09001730 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
Jooyung Han77988572019-10-18 16:26:16 +09001731 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
Jooyung Hanc87a0592020-03-02 17:44:33 +09001732
Jooyung Hanccce2f22020-03-07 03:45:53 +09001733 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Jooyung Hanc87a0592020-03-02 17:44:33 +09001734 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
1735 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Hanccce2f22020-03-07 03:45:53 +09001736 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29")
Jooyung Han77988572019-10-18 16:26:16 +09001737 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001738
Jooyung Hanc87a0592020-03-02 17:44:33 +09001739 // When cc_library sets use_apex_name_macro: true
1740 // apex variants define additional macro to distinguish which apex variant it is built for
1741
1742 // non-APEX variant does not have __ANDROID_APEX__ defined
1743 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
1744 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
1745
1746 // APEX variant has __ANDROID_APEX__ defined
1747 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001748 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001749 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1750 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001751
Jooyung Hanc87a0592020-03-02 17:44:33 +09001752 // APEX variant has __ANDROID_APEX__ defined
1753 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001754 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001755 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1756 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001757}
Jiyong Park7e636d02019-01-28 16:16:54 +09001758
1759func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001760 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001761 apex {
1762 name: "myapex",
1763 key: "myapex.key",
1764 native_shared_libs: ["mylib"],
1765 }
1766
1767 apex_key {
1768 name: "myapex.key",
1769 public_key: "testkey.avbpubkey",
1770 private_key: "testkey.pem",
1771 }
1772
1773 cc_library_headers {
1774 name: "mylib_headers",
1775 export_include_dirs: ["my_include"],
1776 system_shared_libs: [],
1777 stl: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +09001778 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001779 }
1780
1781 cc_library {
1782 name: "mylib",
1783 srcs: ["mylib.cpp"],
1784 system_shared_libs: [],
1785 stl: "none",
1786 header_libs: ["mylib_headers"],
1787 export_header_lib_headers: ["mylib_headers"],
1788 stubs: {
1789 versions: ["1", "2", "3"],
1790 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001791 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001792 }
1793
1794 cc_library {
1795 name: "otherlib",
1796 srcs: ["mylib.cpp"],
1797 system_shared_libs: [],
1798 stl: "none",
1799 shared_libs: ["mylib"],
1800 }
1801 `)
1802
Colin Cross7113d202019-11-20 16:39:12 -08001803 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park7e636d02019-01-28 16:16:54 +09001804
1805 // Ensure that the include path of the header lib is exported to 'otherlib'
1806 ensureContains(t, cFlags, "-Imy_include")
1807}
Alex Light9670d332019-01-29 18:07:33 -08001808
Jiyong Park7cd10e32020-01-14 09:22:18 +09001809type fileInApex struct {
1810 path string // path in apex
Jooyung Hana57af4a2020-01-23 05:36:59 +00001811 src string // src path
Jiyong Park7cd10e32020-01-14 09:22:18 +09001812 isLink bool
1813}
1814
Jooyung Hana57af4a2020-01-23 05:36:59 +00001815func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex {
Jooyung Han31c470b2019-10-18 16:26:59 +09001816 t.Helper()
Jooyung Hana57af4a2020-01-23 05:36:59 +00001817 apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001818 copyCmds := apexRule.Args["copy_commands"]
1819 imageApexDir := "/image.apex/"
Jiyong Park7cd10e32020-01-14 09:22:18 +09001820 var ret []fileInApex
Jooyung Han31c470b2019-10-18 16:26:59 +09001821 for _, cmd := range strings.Split(copyCmds, "&&") {
1822 cmd = strings.TrimSpace(cmd)
1823 if cmd == "" {
1824 continue
1825 }
1826 terms := strings.Split(cmd, " ")
Jooyung Hana57af4a2020-01-23 05:36:59 +00001827 var dst, src string
Jiyong Park7cd10e32020-01-14 09:22:18 +09001828 var isLink bool
Jooyung Han31c470b2019-10-18 16:26:59 +09001829 switch terms[0] {
1830 case "mkdir":
1831 case "cp":
Jiyong Park7cd10e32020-01-14 09:22:18 +09001832 if len(terms) != 3 && len(terms) != 4 {
Jooyung Han31c470b2019-10-18 16:26:59 +09001833 t.Fatal("copyCmds contains invalid cp command", cmd)
1834 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001835 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001836 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001837 isLink = false
1838 case "ln":
1839 if len(terms) != 3 && len(terms) != 4 {
1840 // ln LINK TARGET or ln -s LINK TARGET
1841 t.Fatal("copyCmds contains invalid ln command", cmd)
1842 }
1843 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 = true
1846 default:
1847 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1848 }
1849 if dst != "" {
Jooyung Han31c470b2019-10-18 16:26:59 +09001850 index := strings.Index(dst, imageApexDir)
1851 if index == -1 {
1852 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1853 }
1854 dstFile := dst[index+len(imageApexDir):]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001855 ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink})
Jooyung Han31c470b2019-10-18 16:26:59 +09001856 }
1857 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001858 return ret
1859}
1860
Jooyung Hana57af4a2020-01-23 05:36:59 +00001861func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) {
1862 t.Helper()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001863 var failed bool
1864 var surplus []string
1865 filesMatched := make(map[string]bool)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001866 for _, file := range getFiles(t, ctx, moduleName, variant) {
Jooyung Hane6436d72020-02-27 13:31:56 +09001867 mactchFound := false
Jiyong Park7cd10e32020-01-14 09:22:18 +09001868 for _, expected := range files {
1869 if matched, _ := path.Match(expected, file.path); matched {
1870 filesMatched[expected] = true
Jooyung Hane6436d72020-02-27 13:31:56 +09001871 mactchFound = true
1872 break
Jiyong Park7cd10e32020-01-14 09:22:18 +09001873 }
1874 }
Jooyung Hane6436d72020-02-27 13:31:56 +09001875 if !mactchFound {
1876 surplus = append(surplus, file.path)
1877 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001878 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001879
Jooyung Han31c470b2019-10-18 16:26:59 +09001880 if len(surplus) > 0 {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001881 sort.Strings(surplus)
Jooyung Han31c470b2019-10-18 16:26:59 +09001882 t.Log("surplus files", surplus)
1883 failed = true
1884 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001885
1886 if len(files) > len(filesMatched) {
1887 var missing []string
1888 for _, expected := range files {
1889 if !filesMatched[expected] {
1890 missing = append(missing, expected)
1891 }
1892 }
1893 sort.Strings(missing)
Jooyung Han31c470b2019-10-18 16:26:59 +09001894 t.Log("missing files", missing)
1895 failed = true
1896 }
1897 if failed {
1898 t.Fail()
1899 }
1900}
1901
Jooyung Han344d5432019-08-23 11:17:39 +09001902func TestVndkApexCurrent(t *testing.T) {
1903 ctx, _ := testApex(t, `
1904 apex_vndk {
1905 name: "myapex",
1906 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001907 }
1908
1909 apex_key {
1910 name: "myapex.key",
1911 public_key: "testkey.avbpubkey",
1912 private_key: "testkey.pem",
1913 }
1914
1915 cc_library {
1916 name: "libvndk",
1917 srcs: ["mylib.cpp"],
1918 vendor_available: true,
1919 vndk: {
1920 enabled: true,
1921 },
1922 system_shared_libs: [],
1923 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001924 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001925 }
1926
1927 cc_library {
1928 name: "libvndksp",
1929 srcs: ["mylib.cpp"],
1930 vendor_available: true,
1931 vndk: {
1932 enabled: true,
1933 support_system_process: true,
1934 },
1935 system_shared_libs: [],
1936 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001937 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001938 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001939 `+vndkLibrariesTxtFiles("current"))
Jooyung Han344d5432019-08-23 11:17:39 +09001940
Jooyung Hana57af4a2020-01-23 05:36:59 +00001941 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001942 "lib/libvndk.so",
1943 "lib/libvndksp.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09001944 "lib/libc++.so",
Jooyung Han31c470b2019-10-18 16:26:59 +09001945 "lib64/libvndk.so",
1946 "lib64/libvndksp.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09001947 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001948 "etc/llndk.libraries.VER.txt",
1949 "etc/vndkcore.libraries.VER.txt",
1950 "etc/vndksp.libraries.VER.txt",
1951 "etc/vndkprivate.libraries.VER.txt",
Jooyung Han31c470b2019-10-18 16:26:59 +09001952 })
Jooyung Han344d5432019-08-23 11:17:39 +09001953}
1954
1955func TestVndkApexWithPrebuilt(t *testing.T) {
1956 ctx, _ := testApex(t, `
1957 apex_vndk {
1958 name: "myapex",
1959 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001960 }
1961
1962 apex_key {
1963 name: "myapex.key",
1964 public_key: "testkey.avbpubkey",
1965 private_key: "testkey.pem",
1966 }
1967
1968 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001969 name: "libvndk",
1970 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001971 vendor_available: true,
1972 vndk: {
1973 enabled: true,
1974 },
1975 system_shared_libs: [],
1976 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001977 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001978 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001979
1980 cc_prebuilt_library_shared {
1981 name: "libvndk.arm",
1982 srcs: ["libvndk.arm.so"],
1983 vendor_available: true,
1984 vndk: {
1985 enabled: true,
1986 },
1987 enabled: false,
1988 arch: {
1989 arm: {
1990 enabled: true,
1991 },
1992 },
1993 system_shared_libs: [],
1994 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001995 apex_available: [ "myapex" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09001996 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001997 `+vndkLibrariesTxtFiles("current"),
1998 withFiles(map[string][]byte{
1999 "libvndk.so": nil,
2000 "libvndk.arm.so": nil,
2001 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002002
Jooyung Hana57af4a2020-01-23 05:36:59 +00002003 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002004 "lib/libvndk.so",
2005 "lib/libvndk.arm.so",
2006 "lib64/libvndk.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09002007 "lib/libc++.so",
2008 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002009 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002010 })
Jooyung Han344d5432019-08-23 11:17:39 +09002011}
2012
Jooyung Han39edb6c2019-11-06 16:53:07 +09002013func vndkLibrariesTxtFiles(vers ...string) (result string) {
2014 for _, v := range vers {
2015 if v == "current" {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +09002016 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002017 result += `
2018 vndk_libraries_txt {
2019 name: "` + txt + `.libraries.txt",
2020 }
2021 `
2022 }
2023 } else {
2024 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
2025 result += `
2026 prebuilt_etc {
2027 name: "` + txt + `.libraries.` + v + `.txt",
2028 src: "dummy.txt",
2029 }
2030 `
2031 }
2032 }
2033 }
2034 return
2035}
2036
Jooyung Han344d5432019-08-23 11:17:39 +09002037func TestVndkApexVersion(t *testing.T) {
2038 ctx, _ := testApex(t, `
2039 apex_vndk {
2040 name: "myapex_v27",
2041 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002042 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002043 vndk_version: "27",
2044 }
2045
2046 apex_key {
2047 name: "myapex.key",
2048 public_key: "testkey.avbpubkey",
2049 private_key: "testkey.pem",
2050 }
2051
Jooyung Han31c470b2019-10-18 16:26:59 +09002052 vndk_prebuilt_shared {
2053 name: "libvndk27",
2054 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09002055 vendor_available: true,
2056 vndk: {
2057 enabled: true,
2058 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002059 target_arch: "arm64",
2060 arch: {
2061 arm: {
2062 srcs: ["libvndk27_arm.so"],
2063 },
2064 arm64: {
2065 srcs: ["libvndk27_arm64.so"],
2066 },
2067 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002068 apex_available: [ "myapex_v27" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002069 }
2070
2071 vndk_prebuilt_shared {
2072 name: "libvndk27",
2073 version: "27",
2074 vendor_available: true,
2075 vndk: {
2076 enabled: true,
2077 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002078 target_arch: "x86_64",
2079 arch: {
2080 x86: {
2081 srcs: ["libvndk27_x86.so"],
2082 },
2083 x86_64: {
2084 srcs: ["libvndk27_x86_64.so"],
2085 },
2086 },
Jooyung Han39edb6c2019-11-06 16:53:07 +09002087 }
2088 `+vndkLibrariesTxtFiles("27"),
2089 withFiles(map[string][]byte{
2090 "libvndk27_arm.so": nil,
2091 "libvndk27_arm64.so": nil,
2092 "libvndk27_x86.so": nil,
2093 "libvndk27_x86_64.so": nil,
2094 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002095
Jooyung Hana57af4a2020-01-23 05:36:59 +00002096 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002097 "lib/libvndk27_arm.so",
2098 "lib64/libvndk27_arm64.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002099 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002100 })
Jooyung Han344d5432019-08-23 11:17:39 +09002101}
2102
2103func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
2104 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
2105 apex_vndk {
2106 name: "myapex_v27",
2107 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002108 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002109 vndk_version: "27",
2110 }
2111 apex_vndk {
2112 name: "myapex_v27_other",
2113 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002114 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002115 vndk_version: "27",
2116 }
2117
2118 apex_key {
2119 name: "myapex.key",
2120 public_key: "testkey.avbpubkey",
2121 private_key: "testkey.pem",
2122 }
2123
2124 cc_library {
2125 name: "libvndk",
2126 srcs: ["mylib.cpp"],
2127 vendor_available: true,
2128 vndk: {
2129 enabled: true,
2130 },
2131 system_shared_libs: [],
2132 stl: "none",
2133 }
2134
2135 vndk_prebuilt_shared {
2136 name: "libvndk",
2137 version: "27",
2138 vendor_available: true,
2139 vndk: {
2140 enabled: true,
2141 },
2142 srcs: ["libvndk.so"],
2143 }
2144 `, withFiles(map[string][]byte{
2145 "libvndk.so": nil,
2146 }))
2147}
2148
Jooyung Han90eee022019-10-01 20:02:42 +09002149func TestVndkApexNameRule(t *testing.T) {
2150 ctx, _ := testApex(t, `
2151 apex_vndk {
2152 name: "myapex",
2153 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002154 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002155 }
2156 apex_vndk {
2157 name: "myapex_v28",
2158 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002159 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002160 vndk_version: "28",
2161 }
2162 apex_key {
2163 name: "myapex.key",
2164 public_key: "testkey.avbpubkey",
2165 private_key: "testkey.pem",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002166 }`+vndkLibrariesTxtFiles("28", "current"))
Jooyung Han90eee022019-10-01 20:02:42 +09002167
2168 assertApexName := func(expected, moduleName string) {
Jooyung Hana57af4a2020-01-23 05:36:59 +00002169 bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09002170 actual := proptools.String(bundle.properties.Apex_name)
2171 if !reflect.DeepEqual(actual, expected) {
2172 t.Errorf("Got '%v', expected '%v'", actual, expected)
2173 }
2174 }
2175
2176 assertApexName("com.android.vndk.vVER", "myapex")
2177 assertApexName("com.android.vndk.v28", "myapex_v28")
2178}
2179
Jooyung Han344d5432019-08-23 11:17:39 +09002180func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
2181 ctx, _ := testApex(t, `
2182 apex_vndk {
2183 name: "myapex",
2184 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002185 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002186 }
2187
2188 apex_key {
2189 name: "myapex.key",
2190 public_key: "testkey.avbpubkey",
2191 private_key: "testkey.pem",
2192 }
2193
2194 cc_library {
2195 name: "libvndk",
2196 srcs: ["mylib.cpp"],
2197 vendor_available: true,
2198 native_bridge_supported: true,
2199 host_supported: true,
2200 vndk: {
2201 enabled: true,
2202 },
2203 system_shared_libs: [],
2204 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002205 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002206 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002207 `+vndkLibrariesTxtFiles("current"),
2208 withTargets(map[android.OsType][]android.Target{
2209 android.Android: []android.Target{
2210 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2211 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2212 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
2213 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
2214 },
2215 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002216
Jooyung Hana57af4a2020-01-23 05:36:59 +00002217 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002218 "lib/libvndk.so",
2219 "lib64/libvndk.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09002220 "lib/libc++.so",
2221 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002222 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002223 })
Jooyung Han344d5432019-08-23 11:17:39 +09002224}
2225
2226func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
2227 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
2228 apex_vndk {
2229 name: "myapex",
2230 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002231 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002232 native_bridge_supported: true,
2233 }
2234
2235 apex_key {
2236 name: "myapex.key",
2237 public_key: "testkey.avbpubkey",
2238 private_key: "testkey.pem",
2239 }
2240
2241 cc_library {
2242 name: "libvndk",
2243 srcs: ["mylib.cpp"],
2244 vendor_available: true,
2245 native_bridge_supported: true,
2246 host_supported: true,
2247 vndk: {
2248 enabled: true,
2249 },
2250 system_shared_libs: [],
2251 stl: "none",
2252 }
2253 `)
2254}
2255
Jooyung Han31c470b2019-10-18 16:26:59 +09002256func TestVndkApexWithBinder32(t *testing.T) {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002257 ctx, _ := testApex(t, `
Jooyung Han31c470b2019-10-18 16:26:59 +09002258 apex_vndk {
2259 name: "myapex_v27",
2260 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002261 file_contexts: ":myapex-file_contexts",
Jooyung Han31c470b2019-10-18 16:26:59 +09002262 vndk_version: "27",
2263 }
2264
2265 apex_key {
2266 name: "myapex.key",
2267 public_key: "testkey.avbpubkey",
2268 private_key: "testkey.pem",
2269 }
2270
2271 vndk_prebuilt_shared {
2272 name: "libvndk27",
2273 version: "27",
2274 target_arch: "arm",
2275 vendor_available: true,
2276 vndk: {
2277 enabled: true,
2278 },
2279 arch: {
2280 arm: {
2281 srcs: ["libvndk27.so"],
2282 }
2283 },
2284 }
2285
2286 vndk_prebuilt_shared {
2287 name: "libvndk27",
2288 version: "27",
2289 target_arch: "arm",
2290 binder32bit: true,
2291 vendor_available: true,
2292 vndk: {
2293 enabled: true,
2294 },
2295 arch: {
2296 arm: {
2297 srcs: ["libvndk27binder32.so"],
2298 }
2299 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002300 apex_available: [ "myapex_v27" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002301 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002302 `+vndkLibrariesTxtFiles("27"),
Jooyung Han31c470b2019-10-18 16:26:59 +09002303 withFiles(map[string][]byte{
2304 "libvndk27.so": nil,
2305 "libvndk27binder32.so": nil,
2306 }),
2307 withBinder32bit,
2308 withTargets(map[android.OsType][]android.Target{
2309 android.Android: []android.Target{
2310 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2311 },
2312 }),
2313 )
2314
Jooyung Hana57af4a2020-01-23 05:36:59 +00002315 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002316 "lib/libvndk27binder32.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002317 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002318 })
2319}
2320
Jooyung Hane1633032019-08-01 17:41:43 +09002321func TestDependenciesInApexManifest(t *testing.T) {
2322 ctx, _ := testApex(t, `
2323 apex {
2324 name: "myapex_nodep",
2325 key: "myapex.key",
2326 native_shared_libs: ["lib_nodep"],
2327 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002328 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002329 }
2330
2331 apex {
2332 name: "myapex_dep",
2333 key: "myapex.key",
2334 native_shared_libs: ["lib_dep"],
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_provider",
2341 key: "myapex.key",
2342 native_shared_libs: ["libfoo"],
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_selfcontained",
2349 key: "myapex.key",
2350 native_shared_libs: ["lib_dep", "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_key {
2356 name: "myapex.key",
2357 public_key: "testkey.avbpubkey",
2358 private_key: "testkey.pem",
2359 }
2360
2361 cc_library {
2362 name: "lib_nodep",
2363 srcs: ["mylib.cpp"],
2364 system_shared_libs: [],
2365 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002366 apex_available: [ "myapex_nodep" ],
Jooyung Hane1633032019-08-01 17:41:43 +09002367 }
2368
2369 cc_library {
2370 name: "lib_dep",
2371 srcs: ["mylib.cpp"],
2372 shared_libs: ["libfoo"],
2373 system_shared_libs: [],
2374 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002375 apex_available: [
2376 "myapex_dep",
2377 "myapex_provider",
2378 "myapex_selfcontained",
2379 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002380 }
2381
2382 cc_library {
2383 name: "libfoo",
2384 srcs: ["mytest.cpp"],
2385 stubs: {
2386 versions: ["1"],
2387 },
2388 system_shared_libs: [],
2389 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002390 apex_available: [
2391 "myapex_provider",
2392 "myapex_selfcontained",
2393 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002394 }
2395 `)
2396
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002397 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09002398 var provideNativeLibs, requireNativeLibs []string
2399
Sundong Ahnabb64432019-10-22 13:58:29 +09002400 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002401 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2402 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002403 ensureListEmpty(t, provideNativeLibs)
2404 ensureListEmpty(t, requireNativeLibs)
2405
Sundong Ahnabb64432019-10-22 13:58:29 +09002406 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002407 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2408 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002409 ensureListEmpty(t, provideNativeLibs)
2410 ensureListContains(t, requireNativeLibs, "libfoo.so")
2411
Sundong Ahnabb64432019-10-22 13:58:29 +09002412 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002413 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2414 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002415 ensureListContains(t, provideNativeLibs, "libfoo.so")
2416 ensureListEmpty(t, requireNativeLibs)
2417
Sundong Ahnabb64432019-10-22 13:58:29 +09002418 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002419 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2420 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002421 ensureListContains(t, provideNativeLibs, "libfoo.so")
2422 ensureListEmpty(t, requireNativeLibs)
2423}
2424
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002425func TestApexName(t *testing.T) {
Jiyong Parkdb334862020-02-05 17:19:28 +09002426 ctx, config := testApex(t, `
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002427 apex {
2428 name: "myapex",
2429 key: "myapex.key",
2430 apex_name: "com.android.myapex",
Jiyong Parkdb334862020-02-05 17:19:28 +09002431 native_shared_libs: ["mylib"],
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002432 }
2433
2434 apex_key {
2435 name: "myapex.key",
2436 public_key: "testkey.avbpubkey",
2437 private_key: "testkey.pem",
2438 }
Jiyong Parkdb334862020-02-05 17:19:28 +09002439
2440 cc_library {
2441 name: "mylib",
2442 srcs: ["mylib.cpp"],
2443 system_shared_libs: [],
2444 stl: "none",
2445 apex_available: [
2446 "//apex_available:platform",
2447 "myapex",
2448 ],
2449 }
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002450 `)
2451
Sundong Ahnabb64432019-10-22 13:58:29 +09002452 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002453 apexManifestRule := module.Rule("apexManifestRule")
2454 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
2455 apexRule := module.Rule("apexRule")
2456 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
Jiyong Parkdb334862020-02-05 17:19:28 +09002457
2458 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2459 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2460 name := apexBundle.BaseModuleName()
2461 prefix := "TARGET_"
2462 var builder strings.Builder
2463 data.Custom(&builder, name, prefix, "", data)
2464 androidMk := builder.String()
2465 ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n")
2466 ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002467}
2468
Alex Light0851b882019-02-07 13:20:53 -08002469func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002470 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002471 apex {
2472 name: "myapex",
2473 key: "myapex.key",
2474 native_shared_libs: ["mylib_common"],
2475 }
2476
2477 apex_key {
2478 name: "myapex.key",
2479 public_key: "testkey.avbpubkey",
2480 private_key: "testkey.pem",
2481 }
2482
2483 cc_library {
2484 name: "mylib_common",
2485 srcs: ["mylib.cpp"],
2486 system_shared_libs: [],
2487 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002488 apex_available: [
2489 "//apex_available:platform",
2490 "myapex",
2491 ],
Alex Light0851b882019-02-07 13:20:53 -08002492 }
2493 `)
2494
Sundong Ahnabb64432019-10-22 13:58:29 +09002495 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002496 apexRule := module.Rule("apexRule")
2497 copyCmds := apexRule.Args["copy_commands"]
2498
2499 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
2500 t.Log("Apex was a test apex!")
2501 t.Fail()
2502 }
2503 // Ensure that main rule creates an output
2504 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2505
2506 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002507 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002508
2509 // Ensure that both direct and indirect deps are copied into apex
2510 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2511
Colin Cross7113d202019-11-20 16:39:12 -08002512 // Ensure that the platform variant ends with _shared
2513 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002514
2515 if !android.InAnyApex("mylib_common") {
2516 t.Log("Found mylib_common not in any apex!")
2517 t.Fail()
2518 }
2519}
2520
2521func TestTestApex(t *testing.T) {
2522 if android.InAnyApex("mylib_common_test") {
2523 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!")
2524 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002525 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002526 apex_test {
2527 name: "myapex",
2528 key: "myapex.key",
2529 native_shared_libs: ["mylib_common_test"],
2530 }
2531
2532 apex_key {
2533 name: "myapex.key",
2534 public_key: "testkey.avbpubkey",
2535 private_key: "testkey.pem",
2536 }
2537
2538 cc_library {
2539 name: "mylib_common_test",
2540 srcs: ["mylib.cpp"],
2541 system_shared_libs: [],
2542 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002543 // TODO: remove //apex_available:platform
2544 apex_available: [
2545 "//apex_available:platform",
2546 "myapex",
2547 ],
Alex Light0851b882019-02-07 13:20:53 -08002548 }
2549 `)
2550
Sundong Ahnabb64432019-10-22 13:58:29 +09002551 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002552 apexRule := module.Rule("apexRule")
2553 copyCmds := apexRule.Args["copy_commands"]
2554
2555 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
2556 t.Log("Apex was not a test apex!")
2557 t.Fail()
2558 }
2559 // Ensure that main rule creates an output
2560 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2561
2562 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002563 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002564
2565 // Ensure that both direct and indirect deps are copied into apex
2566 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
2567
Colin Cross7113d202019-11-20 16:39:12 -08002568 // Ensure that the platform variant ends with _shared
2569 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002570}
2571
Alex Light9670d332019-01-29 18:07:33 -08002572func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002573 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08002574 apex {
2575 name: "myapex",
2576 key: "myapex.key",
2577 multilib: {
2578 first: {
2579 native_shared_libs: ["mylib_common"],
2580 }
2581 },
2582 target: {
2583 android: {
2584 multilib: {
2585 first: {
2586 native_shared_libs: ["mylib"],
2587 }
2588 }
2589 },
2590 host: {
2591 multilib: {
2592 first: {
2593 native_shared_libs: ["mylib2"],
2594 }
2595 }
2596 }
2597 }
2598 }
2599
2600 apex_key {
2601 name: "myapex.key",
2602 public_key: "testkey.avbpubkey",
2603 private_key: "testkey.pem",
2604 }
2605
2606 cc_library {
2607 name: "mylib",
2608 srcs: ["mylib.cpp"],
2609 system_shared_libs: [],
2610 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002611 // TODO: remove //apex_available:platform
2612 apex_available: [
2613 "//apex_available:platform",
2614 "myapex",
2615 ],
Alex Light9670d332019-01-29 18:07:33 -08002616 }
2617
2618 cc_library {
2619 name: "mylib_common",
2620 srcs: ["mylib.cpp"],
2621 system_shared_libs: [],
2622 stl: "none",
2623 compile_multilib: "first",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002624 // TODO: remove //apex_available:platform
2625 apex_available: [
2626 "//apex_available:platform",
2627 "myapex",
2628 ],
Alex Light9670d332019-01-29 18:07:33 -08002629 }
2630
2631 cc_library {
2632 name: "mylib2",
2633 srcs: ["mylib.cpp"],
2634 system_shared_libs: [],
2635 stl: "none",
2636 compile_multilib: "first",
2637 }
2638 `)
2639
Sundong Ahnabb64432019-10-22 13:58:29 +09002640 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002641 copyCmds := apexRule.Args["copy_commands"]
2642
2643 // Ensure that main rule creates an output
2644 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2645
2646 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002647 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2648 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
2649 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light9670d332019-01-29 18:07:33 -08002650
2651 // Ensure that both direct and indirect deps are copied into apex
2652 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2653 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2654 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2655
Colin Cross7113d202019-11-20 16:39:12 -08002656 // Ensure that the platform variant ends with _shared
2657 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
2658 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
2659 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Alex Light9670d332019-01-29 18:07:33 -08002660}
Jiyong Park04480cf2019-02-06 00:16:29 +09002661
2662func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002663 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002664 apex {
2665 name: "myapex",
2666 key: "myapex.key",
2667 binaries: ["myscript"],
2668 }
2669
2670 apex_key {
2671 name: "myapex.key",
2672 public_key: "testkey.avbpubkey",
2673 private_key: "testkey.pem",
2674 }
2675
2676 sh_binary {
2677 name: "myscript",
2678 src: "mylib.cpp",
2679 filename: "myscript.sh",
2680 sub_dir: "script",
2681 }
2682 `)
2683
Sundong Ahnabb64432019-10-22 13:58:29 +09002684 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002685 copyCmds := apexRule.Args["copy_commands"]
2686
2687 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2688}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002689
Jooyung Han91df2082019-11-20 01:49:42 +09002690func TestApexInVariousPartition(t *testing.T) {
2691 testcases := []struct {
2692 propName, parition, flattenedPartition string
2693 }{
2694 {"", "system", "system_ext"},
2695 {"product_specific: true", "product", "product"},
2696 {"soc_specific: true", "vendor", "vendor"},
2697 {"proprietary: true", "vendor", "vendor"},
2698 {"vendor: true", "vendor", "vendor"},
2699 {"system_ext_specific: true", "system_ext", "system_ext"},
2700 }
2701 for _, tc := range testcases {
2702 t.Run(tc.propName+":"+tc.parition, func(t *testing.T) {
2703 ctx, _ := testApex(t, `
2704 apex {
2705 name: "myapex",
2706 key: "myapex.key",
2707 `+tc.propName+`
2708 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002709
Jooyung Han91df2082019-11-20 01:49:42 +09002710 apex_key {
2711 name: "myapex.key",
2712 public_key: "testkey.avbpubkey",
2713 private_key: "testkey.pem",
2714 }
2715 `)
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002716
Jooyung Han91df2082019-11-20 01:49:42 +09002717 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2718 expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex"
2719 actual := apex.installDir.String()
2720 if actual != expected {
2721 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2722 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002723
Jooyung Han91df2082019-11-20 01:49:42 +09002724 flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
2725 expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex"
2726 actual = flattened.installDir.String()
2727 if actual != expected {
2728 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2729 }
2730 })
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002731 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002732}
Jiyong Park67882562019-03-21 01:11:21 +09002733
Jooyung Han54aca7b2019-11-20 02:26:02 +09002734func TestFileContexts(t *testing.T) {
2735 ctx, _ := testApex(t, `
2736 apex {
2737 name: "myapex",
2738 key: "myapex.key",
2739 }
2740
2741 apex_key {
2742 name: "myapex.key",
2743 public_key: "testkey.avbpubkey",
2744 private_key: "testkey.pem",
2745 }
2746 `)
2747 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
2748 apexRule := module.Rule("apexRule")
2749 actual := apexRule.Args["file_contexts"]
2750 expected := "system/sepolicy/apex/myapex-file_contexts"
2751 if actual != expected {
2752 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2753 }
2754
2755 testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
2756 apex {
2757 name: "myapex",
2758 key: "myapex.key",
2759 file_contexts: "my_own_file_contexts",
2760 }
2761
2762 apex_key {
2763 name: "myapex.key",
2764 public_key: "testkey.avbpubkey",
2765 private_key: "testkey.pem",
2766 }
2767 `, withFiles(map[string][]byte{
2768 "my_own_file_contexts": nil,
2769 }))
2770
2771 testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
2772 apex {
2773 name: "myapex",
2774 key: "myapex.key",
2775 product_specific: true,
2776 file_contexts: "product_specific_file_contexts",
2777 }
2778
2779 apex_key {
2780 name: "myapex.key",
2781 public_key: "testkey.avbpubkey",
2782 private_key: "testkey.pem",
2783 }
2784 `)
2785
2786 ctx, _ = testApex(t, `
2787 apex {
2788 name: "myapex",
2789 key: "myapex.key",
2790 product_specific: true,
2791 file_contexts: "product_specific_file_contexts",
2792 }
2793
2794 apex_key {
2795 name: "myapex.key",
2796 public_key: "testkey.avbpubkey",
2797 private_key: "testkey.pem",
2798 }
2799 `, withFiles(map[string][]byte{
2800 "product_specific_file_contexts": nil,
2801 }))
2802 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2803 apexRule = module.Rule("apexRule")
2804 actual = apexRule.Args["file_contexts"]
2805 expected = "product_specific_file_contexts"
2806 if actual != expected {
2807 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2808 }
2809
2810 ctx, _ = testApex(t, `
2811 apex {
2812 name: "myapex",
2813 key: "myapex.key",
2814 product_specific: true,
2815 file_contexts: ":my-file-contexts",
2816 }
2817
2818 apex_key {
2819 name: "myapex.key",
2820 public_key: "testkey.avbpubkey",
2821 private_key: "testkey.pem",
2822 }
2823
2824 filegroup {
2825 name: "my-file-contexts",
2826 srcs: ["product_specific_file_contexts"],
2827 }
2828 `, withFiles(map[string][]byte{
2829 "product_specific_file_contexts": nil,
2830 }))
2831 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2832 apexRule = module.Rule("apexRule")
2833 actual = apexRule.Args["file_contexts"]
2834 expected = "product_specific_file_contexts"
2835 if actual != expected {
2836 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2837 }
2838}
2839
Jiyong Park67882562019-03-21 01:11:21 +09002840func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002841 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002842 apex_key {
2843 name: "myapex.key",
2844 public_key: ":my.avbpubkey",
2845 private_key: ":my.pem",
2846 product_specific: true,
2847 }
2848
2849 filegroup {
2850 name: "my.avbpubkey",
2851 srcs: ["testkey2.avbpubkey"],
2852 }
2853
2854 filegroup {
2855 name: "my.pem",
2856 srcs: ["testkey2.pem"],
2857 }
2858 `)
2859
2860 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2861 expected_pubkey := "testkey2.avbpubkey"
2862 actual_pubkey := apex_key.public_key_file.String()
2863 if actual_pubkey != expected_pubkey {
2864 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2865 }
2866 expected_privkey := "testkey2.pem"
2867 actual_privkey := apex_key.private_key_file.String()
2868 if actual_privkey != expected_privkey {
2869 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2870 }
2871}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002872
2873func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002874 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002875 prebuilt_apex {
2876 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002877 arch: {
2878 arm64: {
2879 src: "myapex-arm64.apex",
2880 },
2881 arm: {
2882 src: "myapex-arm.apex",
2883 },
2884 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002885 }
2886 `)
2887
2888 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2889
Jiyong Parkc95714e2019-03-29 14:23:10 +09002890 expectedInput := "myapex-arm64.apex"
2891 if prebuilt.inputApex.String() != expectedInput {
2892 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2893 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002894}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002895
2896func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002897 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002898 prebuilt_apex {
2899 name: "myapex",
2900 src: "myapex-arm.apex",
2901 filename: "notmyapex.apex",
2902 }
2903 `)
2904
2905 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2906
2907 expected := "notmyapex.apex"
2908 if p.installFilename != expected {
2909 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2910 }
2911}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002912
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002913func TestPrebuiltOverrides(t *testing.T) {
2914 ctx, config := testApex(t, `
2915 prebuilt_apex {
2916 name: "myapex.prebuilt",
2917 src: "myapex-arm.apex",
2918 overrides: [
2919 "myapex",
2920 ],
2921 }
2922 `)
2923
2924 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2925
2926 expected := []string{"myapex"}
Jiyong Park0b0e1b92019-12-03 13:24:29 +09002927 actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002928 if !reflect.DeepEqual(actual, expected) {
Jiyong Parkb0a012c2019-11-14 17:17:03 +09002929 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002930 }
2931}
2932
Roland Levillain630846d2019-06-26 12:48:34 +01002933func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002934 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002935 apex_test {
2936 name: "myapex",
2937 key: "myapex.key",
2938 tests: [
2939 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002940 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002941 ],
2942 }
2943
2944 apex_key {
2945 name: "myapex.key",
2946 public_key: "testkey.avbpubkey",
2947 private_key: "testkey.pem",
2948 }
2949
2950 cc_test {
2951 name: "mytest",
2952 gtest: false,
2953 srcs: ["mytest.cpp"],
2954 relative_install_path: "test",
2955 system_shared_libs: [],
2956 static_executable: true,
2957 stl: "none",
2958 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002959
2960 cc_test {
2961 name: "mytests",
2962 gtest: false,
2963 srcs: [
2964 "mytest1.cpp",
2965 "mytest2.cpp",
2966 "mytest3.cpp",
2967 ],
2968 test_per_src: true,
2969 relative_install_path: "test",
2970 system_shared_libs: [],
2971 static_executable: true,
2972 stl: "none",
2973 }
Roland Levillain630846d2019-06-26 12:48:34 +01002974 `)
2975
Sundong Ahnabb64432019-10-22 13:58:29 +09002976 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01002977 copyCmds := apexRule.Args["copy_commands"]
2978
2979 // Ensure that test dep is copied into apex.
2980 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002981
2982 // Ensure that test deps built with `test_per_src` are copied into apex.
2983 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2984 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2985 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002986
2987 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09002988 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01002989 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2990 name := apexBundle.BaseModuleName()
2991 prefix := "TARGET_"
2992 var builder strings.Builder
2993 data.Custom(&builder, name, prefix, "", data)
2994 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09002995 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2996 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2997 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2998 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
Jooyung Han214bf372019-11-12 13:03:50 +09002999 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
Jooyung Han31c470b2019-10-18 16:26:59 +09003000 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01003001 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01003002}
3003
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003004func TestInstallExtraFlattenedApexes(t *testing.T) {
3005 ctx, config := testApex(t, `
3006 apex {
3007 name: "myapex",
3008 key: "myapex.key",
3009 }
3010 apex_key {
3011 name: "myapex.key",
3012 public_key: "testkey.avbpubkey",
3013 private_key: "testkey.pem",
3014 }
3015 `, func(fs map[string][]byte, config android.Config) {
3016 config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
3017 })
3018 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Jiyong Park83dc74b2020-01-14 18:38:44 +09003019 ensureListContains(t, ab.requiredDeps, "myapex.flattened")
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003020 mk := android.AndroidMkDataForTest(t, config, "", ab)
3021 var builder strings.Builder
3022 mk.Custom(&builder, ab.Name(), "TARGET_", "", mk)
3023 androidMk := builder.String()
3024 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened")
3025}
3026
Jooyung Han5c998b92019-06-27 11:30:33 +09003027func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003028 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09003029 apex {
3030 name: "myapex",
3031 key: "myapex.key",
3032 native_shared_libs: ["mylib"],
3033 uses: ["commonapex"],
3034 }
3035
3036 apex {
3037 name: "commonapex",
3038 key: "myapex.key",
3039 native_shared_libs: ["libcommon"],
3040 provide_cpp_shared_libs: true,
3041 }
3042
3043 apex_key {
3044 name: "myapex.key",
3045 public_key: "testkey.avbpubkey",
3046 private_key: "testkey.pem",
3047 }
3048
3049 cc_library {
3050 name: "mylib",
3051 srcs: ["mylib.cpp"],
3052 shared_libs: ["libcommon"],
3053 system_shared_libs: [],
3054 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003055 apex_available: [ "myapex" ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003056 }
3057
3058 cc_library {
3059 name: "libcommon",
3060 srcs: ["mylib_common.cpp"],
3061 system_shared_libs: [],
3062 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003063 // TODO: remove //apex_available:platform
3064 apex_available: [
3065 "//apex_available:platform",
3066 "commonapex",
3067 "myapex",
3068 ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003069 }
3070 `)
3071
Sundong Ahnabb64432019-10-22 13:58:29 +09003072 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003073 apexRule1 := module1.Rule("apexRule")
3074 copyCmds1 := apexRule1.Args["copy_commands"]
3075
Sundong Ahnabb64432019-10-22 13:58:29 +09003076 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003077 apexRule2 := module2.Rule("apexRule")
3078 copyCmds2 := apexRule2.Args["copy_commands"]
3079
Colin Cross7113d202019-11-20 16:39:12 -08003080 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
3081 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex")
Jooyung Han5c998b92019-06-27 11:30:33 +09003082 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
3083 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
3084 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
3085}
3086
3087func TestApexUsesFailsIfNotProvided(t *testing.T) {
3088 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
3089 apex {
3090 name: "myapex",
3091 key: "myapex.key",
3092 uses: ["commonapex"],
3093 }
3094
3095 apex {
3096 name: "commonapex",
3097 key: "myapex.key",
3098 }
3099
3100 apex_key {
3101 name: "myapex.key",
3102 public_key: "testkey.avbpubkey",
3103 private_key: "testkey.pem",
3104 }
3105 `)
3106 testApexError(t, `uses: "commonapex" is not a provider`, `
3107 apex {
3108 name: "myapex",
3109 key: "myapex.key",
3110 uses: ["commonapex"],
3111 }
3112
3113 cc_library {
3114 name: "commonapex",
3115 system_shared_libs: [],
3116 stl: "none",
3117 }
3118
3119 apex_key {
3120 name: "myapex.key",
3121 public_key: "testkey.avbpubkey",
3122 private_key: "testkey.pem",
3123 }
3124 `)
3125}
3126
3127func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
3128 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
3129 apex {
3130 name: "myapex",
3131 key: "myapex.key",
3132 use_vendor: true,
3133 uses: ["commonapex"],
3134 }
3135
3136 apex {
3137 name: "commonapex",
3138 key: "myapex.key",
3139 provide_cpp_shared_libs: true,
3140 }
3141
3142 apex_key {
3143 name: "myapex.key",
3144 public_key: "testkey.avbpubkey",
3145 private_key: "testkey.pem",
3146 }
Jooyung Handc782442019-11-01 03:14:38 +09003147 `, func(fs map[string][]byte, config android.Config) {
3148 setUseVendorWhitelistForTest(config, []string{"myapex"})
3149 })
Jooyung Han5c998b92019-06-27 11:30:33 +09003150}
3151
Jooyung Hand48f3c32019-08-23 11:18:57 +09003152func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
3153 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
3154 apex {
3155 name: "myapex",
3156 key: "myapex.key",
3157 native_shared_libs: ["libfoo"],
3158 }
3159
3160 apex_key {
3161 name: "myapex.key",
3162 public_key: "testkey.avbpubkey",
3163 private_key: "testkey.pem",
3164 }
3165
3166 cc_library {
3167 name: "libfoo",
3168 stl: "none",
3169 system_shared_libs: [],
3170 enabled: false,
3171 }
3172 `)
3173 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
3174 apex {
3175 name: "myapex",
3176 key: "myapex.key",
3177 java_libs: ["myjar"],
3178 }
3179
3180 apex_key {
3181 name: "myapex.key",
3182 public_key: "testkey.avbpubkey",
3183 private_key: "testkey.pem",
3184 }
3185
3186 java_library {
3187 name: "myjar",
3188 srcs: ["foo/bar/MyClass.java"],
3189 sdk_version: "none",
3190 system_modules: "none",
Jooyung Hand48f3c32019-08-23 11:18:57 +09003191 enabled: false,
3192 }
3193 `)
3194}
3195
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003196func TestApexWithApps(t *testing.T) {
3197 ctx, _ := testApex(t, `
3198 apex {
3199 name: "myapex",
3200 key: "myapex.key",
3201 apps: [
3202 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09003203 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003204 ],
3205 }
3206
3207 apex_key {
3208 name: "myapex.key",
3209 public_key: "testkey.avbpubkey",
3210 private_key: "testkey.pem",
3211 }
3212
3213 android_app {
3214 name: "AppFoo",
3215 srcs: ["foo/bar/MyClass.java"],
Colin Cross094cde42020-02-15 10:38:00 -08003216 sdk_version: "current",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003217 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09003218 jni_libs: ["libjni"],
Colin Cross094cde42020-02-15 10:38:00 -08003219 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003220 apex_available: [ "myapex" ],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003221 }
Jiyong Parkf7487312019-10-17 12:54:30 +09003222
3223 android_app {
3224 name: "AppFooPriv",
3225 srcs: ["foo/bar/MyClass.java"],
Colin Cross094cde42020-02-15 10:38:00 -08003226 sdk_version: "current",
Jiyong Parkf7487312019-10-17 12:54:30 +09003227 system_modules: "none",
3228 privileged: true,
Colin Cross094cde42020-02-15 10:38:00 -08003229 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003230 apex_available: [ "myapex" ],
Jiyong Parkf7487312019-10-17 12:54:30 +09003231 }
Jiyong Park8be103b2019-11-08 15:53:48 +09003232
3233 cc_library_shared {
3234 name: "libjni",
3235 srcs: ["mylib.cpp"],
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003236 shared_libs: ["libfoo"],
3237 stl: "none",
3238 system_shared_libs: [],
3239 apex_available: [ "myapex" ],
3240 sdk_version: "current",
3241 }
3242
3243 cc_library_shared {
3244 name: "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" ],
Colin Cross094cde42020-02-15 10:38:00 -08003248 sdk_version: "current",
Jiyong Park8be103b2019-11-08 15:53:48 +09003249 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003250 `)
3251
Sundong Ahnabb64432019-10-22 13:58:29 +09003252 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003253 apexRule := module.Rule("apexRule")
3254 copyCmds := apexRule.Args["copy_commands"]
3255
3256 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09003257 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003258
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003259 appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs")
3260 // JNI libraries are uncompressed
Jiyong Park52cd06f2019-11-11 10:14:32 +09003261 if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003262 t.Errorf("jni libs are not uncompressed for AppFoo")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003263 }
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003264 // JNI libraries including transitive deps are
3265 for _, jni := range []string{"libjni", "libfoo"} {
3266 jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile()
3267 // ... embedded inside APK (jnilibs.zip)
3268 ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String())
3269 // ... and not directly inside the APEX
3270 ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so")
3271 }
Dario Frenicde2a032019-10-27 00:29:22 +01003272}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003273
Dario Frenicde2a032019-10-27 00:29:22 +01003274func TestApexWithAppImports(t *testing.T) {
3275 ctx, _ := testApex(t, `
3276 apex {
3277 name: "myapex",
3278 key: "myapex.key",
3279 apps: [
3280 "AppFooPrebuilt",
3281 "AppFooPrivPrebuilt",
3282 ],
3283 }
3284
3285 apex_key {
3286 name: "myapex.key",
3287 public_key: "testkey.avbpubkey",
3288 private_key: "testkey.pem",
3289 }
3290
3291 android_app_import {
3292 name: "AppFooPrebuilt",
3293 apk: "PrebuiltAppFoo.apk",
3294 presigned: true,
3295 dex_preopt: {
3296 enabled: false,
3297 },
3298 }
3299
3300 android_app_import {
3301 name: "AppFooPrivPrebuilt",
3302 apk: "PrebuiltAppFooPriv.apk",
3303 privileged: true,
3304 presigned: true,
3305 dex_preopt: {
3306 enabled: false,
3307 },
3308 }
3309 `)
3310
Sundong Ahnabb64432019-10-22 13:58:29 +09003311 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01003312 apexRule := module.Rule("apexRule")
3313 copyCmds := apexRule.Args["copy_commands"]
3314
3315 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
3316 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003317}
3318
Dario Freni6f3937c2019-12-20 22:58:03 +00003319func TestApexWithTestHelperApp(t *testing.T) {
3320 ctx, _ := testApex(t, `
3321 apex {
3322 name: "myapex",
3323 key: "myapex.key",
3324 apps: [
3325 "TesterHelpAppFoo",
3326 ],
3327 }
3328
3329 apex_key {
3330 name: "myapex.key",
3331 public_key: "testkey.avbpubkey",
3332 private_key: "testkey.pem",
3333 }
3334
3335 android_test_helper_app {
3336 name: "TesterHelpAppFoo",
3337 srcs: ["foo/bar/MyClass.java"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003338 apex_available: [ "myapex" ],
Dario Freni6f3937c2019-12-20 22:58:03 +00003339 }
3340
3341 `)
3342
3343 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3344 apexRule := module.Rule("apexRule")
3345 copyCmds := apexRule.Args["copy_commands"]
3346
3347 ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk")
3348}
3349
Jooyung Han18020ea2019-11-13 10:50:48 +09003350func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
3351 // libfoo's apex_available comes from cc_defaults
3352 testApexError(t, `"myapex" .*: requires "libfoo" that is not available for the APEX`, `
3353 apex {
3354 name: "myapex",
3355 key: "myapex.key",
3356 native_shared_libs: ["libfoo"],
3357 }
3358
3359 apex_key {
3360 name: "myapex.key",
3361 public_key: "testkey.avbpubkey",
3362 private_key: "testkey.pem",
3363 }
3364
3365 apex {
3366 name: "otherapex",
3367 key: "myapex.key",
3368 native_shared_libs: ["libfoo"],
3369 }
3370
3371 cc_defaults {
3372 name: "libfoo-defaults",
3373 apex_available: ["otherapex"],
3374 }
3375
3376 cc_library {
3377 name: "libfoo",
3378 defaults: ["libfoo-defaults"],
3379 stl: "none",
3380 system_shared_libs: [],
3381 }`)
3382}
3383
Jiyong Park127b40b2019-09-30 16:04:35 +09003384func TestApexAvailable(t *testing.T) {
3385 // libfoo is not available to myapex, but only to otherapex
3386 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
3387 apex {
3388 name: "myapex",
3389 key: "myapex.key",
3390 native_shared_libs: ["libfoo"],
3391 }
3392
3393 apex_key {
3394 name: "myapex.key",
3395 public_key: "testkey.avbpubkey",
3396 private_key: "testkey.pem",
3397 }
3398
3399 apex {
3400 name: "otherapex",
3401 key: "otherapex.key",
3402 native_shared_libs: ["libfoo"],
3403 }
3404
3405 apex_key {
3406 name: "otherapex.key",
3407 public_key: "testkey.avbpubkey",
3408 private_key: "testkey.pem",
3409 }
3410
3411 cc_library {
3412 name: "libfoo",
3413 stl: "none",
3414 system_shared_libs: [],
3415 apex_available: ["otherapex"],
3416 }`)
3417
3418 // libbar is an indirect dep
3419 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
3420 apex {
3421 name: "myapex",
3422 key: "myapex.key",
3423 native_shared_libs: ["libfoo"],
3424 }
3425
3426 apex_key {
3427 name: "myapex.key",
3428 public_key: "testkey.avbpubkey",
3429 private_key: "testkey.pem",
3430 }
3431
3432 apex {
3433 name: "otherapex",
3434 key: "otherapex.key",
3435 native_shared_libs: ["libfoo"],
3436 }
3437
3438 apex_key {
3439 name: "otherapex.key",
3440 public_key: "testkey.avbpubkey",
3441 private_key: "testkey.pem",
3442 }
3443
3444 cc_library {
3445 name: "libfoo",
3446 stl: "none",
3447 shared_libs: ["libbar"],
3448 system_shared_libs: [],
3449 apex_available: ["myapex", "otherapex"],
3450 }
3451
3452 cc_library {
3453 name: "libbar",
3454 stl: "none",
3455 system_shared_libs: [],
3456 apex_available: ["otherapex"],
3457 }`)
3458
3459 testApexError(t, "\"otherapex\" is not a valid module name", `
3460 apex {
3461 name: "myapex",
3462 key: "myapex.key",
3463 native_shared_libs: ["libfoo"],
3464 }
3465
3466 apex_key {
3467 name: "myapex.key",
3468 public_key: "testkey.avbpubkey",
3469 private_key: "testkey.pem",
3470 }
3471
3472 cc_library {
3473 name: "libfoo",
3474 stl: "none",
3475 system_shared_libs: [],
3476 apex_available: ["otherapex"],
3477 }`)
3478
3479 ctx, _ := testApex(t, `
3480 apex {
3481 name: "myapex",
3482 key: "myapex.key",
3483 native_shared_libs: ["libfoo", "libbar"],
3484 }
3485
3486 apex_key {
3487 name: "myapex.key",
3488 public_key: "testkey.avbpubkey",
3489 private_key: "testkey.pem",
3490 }
3491
3492 cc_library {
3493 name: "libfoo",
3494 stl: "none",
3495 system_shared_libs: [],
Jiyong Park323a4c32020-03-01 17:29:06 +09003496 runtime_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003497 apex_available: ["myapex"],
3498 }
3499
3500 cc_library {
3501 name: "libbar",
3502 stl: "none",
3503 system_shared_libs: [],
3504 apex_available: ["//apex_available:anyapex"],
Jiyong Park323a4c32020-03-01 17:29:06 +09003505 }
3506
3507 cc_library {
3508 name: "libbaz",
3509 stl: "none",
3510 system_shared_libs: [],
3511 stubs: {
3512 versions: ["10", "20", "30"],
3513 },
Jiyong Park127b40b2019-09-30 16:04:35 +09003514 }`)
3515
3516 // check that libfoo and libbar are created only for myapex, but not for the platform
Jiyong Park0f80c182020-01-31 02:49:53 +09003517 // TODO(jiyong) the checks for the platform variant are removed because we now create
3518 // the platform variant regardless of the apex_availability. Instead, we will make sure that
3519 // the platform variants are not used from other platform modules. When that is done,
3520 // these checks will be replaced by expecting a specific error message that will be
3521 // emitted when the platform variant is used.
3522 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3523 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3524 // ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
3525 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")
Jiyong Park127b40b2019-09-30 16:04:35 +09003526
3527 ctx, _ = testApex(t, `
3528 apex {
3529 name: "myapex",
3530 key: "myapex.key",
3531 }
3532
3533 apex_key {
3534 name: "myapex.key",
3535 public_key: "testkey.avbpubkey",
3536 private_key: "testkey.pem",
3537 }
3538
3539 cc_library {
3540 name: "libfoo",
3541 stl: "none",
3542 system_shared_libs: [],
3543 apex_available: ["//apex_available:platform"],
3544 }`)
3545
3546 // check that libfoo is created only for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003547 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3548 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003549
3550 ctx, _ = testApex(t, `
3551 apex {
3552 name: "myapex",
3553 key: "myapex.key",
3554 native_shared_libs: ["libfoo"],
3555 }
3556
3557 apex_key {
3558 name: "myapex.key",
3559 public_key: "testkey.avbpubkey",
3560 private_key: "testkey.pem",
3561 }
3562
3563 cc_library {
3564 name: "libfoo",
3565 stl: "none",
3566 system_shared_libs: [],
3567 apex_available: ["myapex"],
3568 static: {
3569 apex_available: ["//apex_available:platform"],
3570 },
3571 }`)
3572
3573 // shared variant of libfoo is only available to myapex
Jiyong Park0f80c182020-01-31 02:49:53 +09003574 // TODO(jiyong) the checks for the platform variant are removed because we now create
3575 // the platform variant regardless of the apex_availability. Instead, we will make sure that
3576 // the platform variants are not used from other platform modules. When that is done,
3577 // these checks will be replaced by expecting a specific error message that will be
3578 // emitted when the platform variant is used.
3579 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3580 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3581 // // but the static variant is available to both myapex and the platform
3582 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
3583 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09003584}
3585
Jiyong Park5d790c32019-11-15 18:40:32 +09003586func TestOverrideApex(t *testing.T) {
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003587 ctx, config := testApex(t, `
Jiyong Park5d790c32019-11-15 18:40:32 +09003588 apex {
3589 name: "myapex",
3590 key: "myapex.key",
3591 apps: ["app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003592 overrides: ["oldapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003593 }
3594
3595 override_apex {
3596 name: "override_myapex",
3597 base: "myapex",
3598 apps: ["override_app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003599 overrides: ["unknownapex"],
Baligh Uddin004d7172020-02-19 21:29:28 -08003600 logging_parent: "com.foo.bar",
Jiyong Park5d790c32019-11-15 18:40:32 +09003601 }
3602
3603 apex_key {
3604 name: "myapex.key",
3605 public_key: "testkey.avbpubkey",
3606 private_key: "testkey.pem",
3607 }
3608
3609 android_app {
3610 name: "app",
3611 srcs: ["foo/bar/MyClass.java"],
3612 package_name: "foo",
3613 sdk_version: "none",
3614 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003615 apex_available: [ "myapex" ],
Jiyong Park5d790c32019-11-15 18:40:32 +09003616 }
3617
3618 override_android_app {
3619 name: "override_app",
3620 base: "app",
3621 package_name: "bar",
3622 }
Jiyong Park20bacab2020-03-03 11:45:41 +09003623 `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"}))
Jiyong Park5d790c32019-11-15 18:40:32 +09003624
Jiyong Park317645e2019-12-05 13:20:58 +09003625 originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule)
3626 overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule)
3627 if originalVariant.GetOverriddenBy() != "" {
3628 t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
3629 }
3630 if overriddenVariant.GetOverriddenBy() != "override_myapex" {
3631 t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
3632 }
3633
Jiyong Park5d790c32019-11-15 18:40:32 +09003634 module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image")
3635 apexRule := module.Rule("apexRule")
3636 copyCmds := apexRule.Args["copy_commands"]
3637
3638 ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk")
3639 ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003640
3641 apexBundle := module.Module().(*apexBundle)
3642 name := apexBundle.Name()
3643 if name != "override_myapex" {
3644 t.Errorf("name should be \"override_myapex\", but was %q", name)
3645 }
3646
Baligh Uddin004d7172020-02-19 21:29:28 -08003647 if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" {
3648 t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent)
3649 }
3650
Jiyong Park20bacab2020-03-03 11:45:41 +09003651 optFlags := apexRule.Args["opt_flags"]
3652 ensureContains(t, optFlags, "--override_apk_package_name com.android.myapex")
3653
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003654 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3655 var builder strings.Builder
3656 data.Custom(&builder, name, "TARGET_", "", data)
3657 androidMk := builder.String()
Jiyong Parkf653b052019-11-18 15:39:01 +09003658 ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003659 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
3660 ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003661 ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003662 ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
Jiyong Parkf653b052019-11-18 15:39:01 +09003663 ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003664 ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
3665 ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
Jiyong Park5d790c32019-11-15 18:40:32 +09003666}
3667
Jooyung Han214bf372019-11-12 13:03:50 +09003668func TestLegacyAndroid10Support(t *testing.T) {
3669 ctx, _ := testApex(t, `
3670 apex {
3671 name: "myapex",
3672 key: "myapex.key",
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003673 native_shared_libs: ["mylib"],
Jooyung Han214bf372019-11-12 13:03:50 +09003674 legacy_android10_support: true,
3675 }
3676
3677 apex_key {
3678 name: "myapex.key",
3679 public_key: "testkey.avbpubkey",
3680 private_key: "testkey.pem",
3681 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003682
3683 cc_library {
3684 name: "mylib",
3685 srcs: ["mylib.cpp"],
3686 stl: "libc++",
3687 system_shared_libs: [],
3688 apex_available: [ "myapex" ],
3689 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003690 `, withUnbundledBuild)
Jooyung Han214bf372019-11-12 13:03:50 +09003691
3692 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3693 args := module.Rule("apexRule").Args
3694 ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String())
Dario Frenie3546902020-01-14 23:50:25 +00003695 ensureNotContains(t, args["opt_flags"], "--no_hashtree")
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003696
3697 // The copies of the libraries in the apex should have one more dependency than
3698 // the ones outside the apex, namely the unwinder. Ideally we should check
3699 // the dependency names directly here but for some reason the names are blank in
3700 // this test.
3701 for _, lib := range []string{"libc++", "mylib"} {
3702 apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits
3703 nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits
3704 if len(apexImplicits) != len(nonApexImplicits)+1 {
3705 t.Errorf("%q missing unwinder dep", lib)
3706 }
3707 }
Jooyung Han214bf372019-11-12 13:03:50 +09003708}
3709
Jooyung Han58f26ab2019-12-18 15:34:32 +09003710func TestJavaSDKLibrary(t *testing.T) {
3711 ctx, _ := testApex(t, `
3712 apex {
3713 name: "myapex",
3714 key: "myapex.key",
3715 java_libs: ["foo"],
3716 }
3717
3718 apex_key {
3719 name: "myapex.key",
3720 public_key: "testkey.avbpubkey",
3721 private_key: "testkey.pem",
3722 }
3723
3724 java_sdk_library {
3725 name: "foo",
3726 srcs: ["a.java"],
3727 api_packages: ["foo"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003728 apex_available: [ "myapex" ],
Jooyung Han58f26ab2019-12-18 15:34:32 +09003729 }
3730 `, withFiles(map[string][]byte{
3731 "api/current.txt": nil,
3732 "api/removed.txt": nil,
3733 "api/system-current.txt": nil,
3734 "api/system-removed.txt": nil,
3735 "api/test-current.txt": nil,
3736 "api/test-removed.txt": nil,
3737 }))
3738
3739 // java_sdk_library installs both impl jar and permission XML
Jooyung Hana57af4a2020-01-23 05:36:59 +00003740 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han58f26ab2019-12-18 15:34:32 +09003741 "javalib/foo.jar",
3742 "etc/permissions/foo.xml",
3743 })
3744 // Permission XML should point to the activated path of impl jar of java_sdk_library
Jiyong Parke3833882020-02-17 17:28:10 +09003745 sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml")
3746 ensureContains(t, sdkLibrary.RuleParams.Command, `<library name=\"foo\" file=\"/apex/myapex/javalib/foo.jar\"`)
Jooyung Han58f26ab2019-12-18 15:34:32 +09003747}
3748
atrost6e126252020-01-27 17:01:16 +00003749func TestCompatConfig(t *testing.T) {
3750 ctx, _ := testApex(t, `
3751 apex {
3752 name: "myapex",
3753 key: "myapex.key",
3754 prebuilts: ["myjar-platform-compat-config"],
3755 java_libs: ["myjar"],
3756 }
3757
3758 apex_key {
3759 name: "myapex.key",
3760 public_key: "testkey.avbpubkey",
3761 private_key: "testkey.pem",
3762 }
3763
3764 platform_compat_config {
3765 name: "myjar-platform-compat-config",
3766 src: ":myjar",
3767 }
3768
3769 java_library {
3770 name: "myjar",
3771 srcs: ["foo/bar/MyClass.java"],
3772 sdk_version: "none",
3773 system_modules: "none",
atrost6e126252020-01-27 17:01:16 +00003774 apex_available: [ "myapex" ],
3775 }
3776 `)
3777 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
3778 "etc/compatconfig/myjar-platform-compat-config.xml",
3779 "javalib/myjar.jar",
3780 })
3781}
3782
Jiyong Park479321d2019-12-16 11:47:12 +09003783func TestRejectNonInstallableJavaLibrary(t *testing.T) {
3784 testApexError(t, `"myjar" is not configured to be compiled into dex`, `
3785 apex {
3786 name: "myapex",
3787 key: "myapex.key",
3788 java_libs: ["myjar"],
3789 }
3790
3791 apex_key {
3792 name: "myapex.key",
3793 public_key: "testkey.avbpubkey",
3794 private_key: "testkey.pem",
3795 }
3796
3797 java_library {
3798 name: "myjar",
3799 srcs: ["foo/bar/MyClass.java"],
3800 sdk_version: "none",
3801 system_modules: "none",
Jiyong Park6b21c7d2020-02-11 09:16:01 +09003802 compile_dex: false,
Jiyong Park479321d2019-12-16 11:47:12 +09003803 }
3804 `)
3805}
3806
Jiyong Park7afd1072019-12-30 16:56:33 +09003807func TestCarryRequiredModuleNames(t *testing.T) {
3808 ctx, config := testApex(t, `
3809 apex {
3810 name: "myapex",
3811 key: "myapex.key",
3812 native_shared_libs: ["mylib"],
3813 }
3814
3815 apex_key {
3816 name: "myapex.key",
3817 public_key: "testkey.avbpubkey",
3818 private_key: "testkey.pem",
3819 }
3820
3821 cc_library {
3822 name: "mylib",
3823 srcs: ["mylib.cpp"],
3824 system_shared_libs: [],
3825 stl: "none",
3826 required: ["a", "b"],
3827 host_required: ["c", "d"],
3828 target_required: ["e", "f"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003829 apex_available: [ "myapex" ],
Jiyong Park7afd1072019-12-30 16:56:33 +09003830 }
3831 `)
3832
3833 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
3834 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3835 name := apexBundle.BaseModuleName()
3836 prefix := "TARGET_"
3837 var builder strings.Builder
3838 data.Custom(&builder, name, prefix, "", data)
3839 androidMk := builder.String()
3840 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n")
3841 ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n")
3842 ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n")
3843}
3844
Jiyong Park7cd10e32020-01-14 09:22:18 +09003845func TestSymlinksFromApexToSystem(t *testing.T) {
3846 bp := `
3847 apex {
3848 name: "myapex",
3849 key: "myapex.key",
3850 native_shared_libs: ["mylib"],
3851 java_libs: ["myjar"],
3852 }
3853
Jiyong Park9d677202020-02-19 16:29:35 +09003854 apex {
3855 name: "myapex.updatable",
3856 key: "myapex.key",
3857 native_shared_libs: ["mylib"],
3858 java_libs: ["myjar"],
3859 updatable: true,
3860 }
3861
Jiyong Park7cd10e32020-01-14 09:22:18 +09003862 apex_key {
3863 name: "myapex.key",
3864 public_key: "testkey.avbpubkey",
3865 private_key: "testkey.pem",
3866 }
3867
3868 cc_library {
3869 name: "mylib",
3870 srcs: ["mylib.cpp"],
3871 shared_libs: ["myotherlib"],
3872 system_shared_libs: [],
3873 stl: "none",
3874 apex_available: [
3875 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003876 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003877 "//apex_available:platform",
3878 ],
3879 }
3880
3881 cc_library {
3882 name: "myotherlib",
3883 srcs: ["mylib.cpp"],
3884 system_shared_libs: [],
3885 stl: "none",
3886 apex_available: [
3887 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003888 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003889 "//apex_available:platform",
3890 ],
3891 }
3892
3893 java_library {
3894 name: "myjar",
3895 srcs: ["foo/bar/MyClass.java"],
3896 sdk_version: "none",
3897 system_modules: "none",
3898 libs: ["myotherjar"],
Jiyong Park7cd10e32020-01-14 09:22:18 +09003899 apex_available: [
3900 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003901 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003902 "//apex_available:platform",
3903 ],
3904 }
3905
3906 java_library {
3907 name: "myotherjar",
3908 srcs: ["foo/bar/MyClass.java"],
3909 sdk_version: "none",
3910 system_modules: "none",
3911 apex_available: [
3912 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003913 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003914 "//apex_available:platform",
3915 ],
3916 }
3917 `
3918
3919 ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) {
3920 for _, f := range files {
3921 if f.path == file {
3922 if f.isLink {
3923 t.Errorf("%q is not a real file", file)
3924 }
3925 return
3926 }
3927 }
3928 t.Errorf("%q is not found", file)
3929 }
3930
3931 ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) {
3932 for _, f := range files {
3933 if f.path == file {
3934 if !f.isLink {
3935 t.Errorf("%q is not a symlink", file)
3936 }
3937 return
3938 }
3939 }
3940 t.Errorf("%q is not found", file)
3941 }
3942
Jiyong Park9d677202020-02-19 16:29:35 +09003943 // For unbundled build, symlink shouldn't exist regardless of whether an APEX
3944 // is updatable or not
Jiyong Park7cd10e32020-01-14 09:22:18 +09003945 ctx, _ := testApex(t, bp, withUnbundledBuild)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003946 files := getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003947 ensureRealfileExists(t, files, "javalib/myjar.jar")
3948 ensureRealfileExists(t, files, "lib64/mylib.so")
3949 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3950
Jiyong Park9d677202020-02-19 16:29:35 +09003951 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
3952 ensureRealfileExists(t, files, "javalib/myjar.jar")
3953 ensureRealfileExists(t, files, "lib64/mylib.so")
3954 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3955
3956 // For bundled build, symlink to the system for the non-updatable APEXes only
Jiyong Park7cd10e32020-01-14 09:22:18 +09003957 ctx, _ = testApex(t, bp)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003958 files = getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003959 ensureRealfileExists(t, files, "javalib/myjar.jar")
3960 ensureRealfileExists(t, files, "lib64/mylib.so")
3961 ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
Jiyong Park9d677202020-02-19 16:29:35 +09003962
3963 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
3964 ensureRealfileExists(t, files, "javalib/myjar.jar")
3965 ensureRealfileExists(t, files, "lib64/mylib.so")
3966 ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
Jiyong Park7cd10e32020-01-14 09:22:18 +09003967}
3968
Jooyung Han643adc42020-02-27 13:50:06 +09003969func TestApexWithJniLibs(t *testing.T) {
3970 ctx, _ := testApex(t, `
3971 apex {
3972 name: "myapex",
3973 key: "myapex.key",
3974 jni_libs: ["mylib"],
3975 }
3976
3977 apex_key {
3978 name: "myapex.key",
3979 public_key: "testkey.avbpubkey",
3980 private_key: "testkey.pem",
3981 }
3982
3983 cc_library {
3984 name: "mylib",
3985 srcs: ["mylib.cpp"],
3986 shared_libs: ["mylib2"],
3987 system_shared_libs: [],
3988 stl: "none",
3989 apex_available: [ "myapex" ],
3990 }
3991
3992 cc_library {
3993 name: "mylib2",
3994 srcs: ["mylib.cpp"],
3995 system_shared_libs: [],
3996 stl: "none",
3997 apex_available: [ "myapex" ],
3998 }
3999 `)
4000
4001 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
4002 // Notice mylib2.so (transitive dep) is not added as a jni_lib
4003 ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so")
4004 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
4005 "lib64/mylib.so",
4006 "lib64/mylib2.so",
4007 })
4008}
4009
4010func TestApexWithJniLibs_Errors(t *testing.T) {
4011 testApexError(t, `jni_libs: "xxx" is not a cc_library`, `
4012 apex {
4013 name: "myapex",
4014 key: "myapex.key",
4015 jni_libs: ["xxx"],
4016 }
4017
4018 apex_key {
4019 name: "myapex.key",
4020 public_key: "testkey.avbpubkey",
4021 private_key: "testkey.pem",
4022 }
4023
4024 prebuilt_etc {
4025 name: "xxx",
4026 src: "xxx",
4027 }
4028 `, withFiles(map[string][]byte{
4029 "xxx": nil,
4030 }))
4031}
4032
Jiyong Parkbd159612020-02-28 15:22:21 +09004033func TestAppBundle(t *testing.T) {
4034 ctx, _ := testApex(t, `
4035 apex {
4036 name: "myapex",
4037 key: "myapex.key",
4038 apps: ["AppFoo"],
4039 }
4040
4041 apex_key {
4042 name: "myapex.key",
4043 public_key: "testkey.avbpubkey",
4044 private_key: "testkey.pem",
4045 }
4046
4047 android_app {
4048 name: "AppFoo",
4049 srcs: ["foo/bar/MyClass.java"],
4050 sdk_version: "none",
4051 system_modules: "none",
4052 apex_available: [ "myapex" ],
4053 }
Jiyong Parkcfaa1642020-02-28 16:51:07 +09004054 `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"}))
Jiyong Parkbd159612020-02-28 15:22:21 +09004055
4056 bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config")
4057 content := bundleConfigRule.Args["content"]
4058
4059 ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
Jiyong Parkcfaa1642020-02-28 16:51:07 +09004060 ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`)
Jiyong Parkbd159612020-02-28 15:22:21 +09004061}
4062
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07004063func TestMain(m *testing.M) {
4064 run := func() int {
4065 setUp()
4066 defer tearDown()
4067
4068 return m.Run()
4069 }
4070
4071 os.Exit(run())
4072}