blob: 2b13197419b838445a158cfa386894c0d1b2e636 [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"],
Jiyong Park58e364a2019-01-19 19:24:06 +09001690 }
1691
1692 apex_key {
1693 name: "myapex.key",
1694 public_key: "testkey.avbpubkey",
1695 private_key: "testkey.pem",
1696 }
1697
1698 cc_library {
1699 name: "mylib",
1700 srcs: ["mylib.cpp"],
1701 system_shared_libs: [],
1702 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001703 apex_available: [
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001704 "myapex",
1705 "otherapex",
1706 ],
Jiyong Park58e364a2019-01-19 19:24:06 +09001707 }
Jooyung Hanc87a0592020-03-02 17:44:33 +09001708 cc_library {
1709 name: "mylib2",
1710 srcs: ["mylib.cpp"],
1711 system_shared_libs: [],
1712 stl: "none",
1713 apex_available: [
1714 "myapex",
1715 "otherapex",
1716 ],
1717 use_apex_name_macro: true,
1718 }
Jiyong Park58e364a2019-01-19 19:24:06 +09001719 `)
1720
Jooyung Hanc87a0592020-03-02 17:44:33 +09001721 // non-APEX variant does not have __ANDROID_APEX__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001722 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001723 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Hanc87a0592020-03-02 17:44:33 +09001724
1725 // APEX variant has __ANDROID_APEX__ defined
1726 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
1727 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001728 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
Jooyung Hanc87a0592020-03-02 17:44:33 +09001729
1730 // APEX variant has __ANDROID_APEX__ defined
1731 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
1732 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001733 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001734
Jooyung Hanc87a0592020-03-02 17:44:33 +09001735 // When cc_library sets use_apex_name_macro: true
1736 // apex variants define additional macro to distinguish which apex variant it is built for
1737
1738 // non-APEX variant does not have __ANDROID_APEX__ defined
1739 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
1740 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
1741
1742 // APEX variant has __ANDROID_APEX__ defined
1743 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001744 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001745 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1746 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001747
Jooyung Hanc87a0592020-03-02 17:44:33 +09001748 // APEX variant has __ANDROID_APEX__ defined
1749 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001750 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001751 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1752 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001753}
Jiyong Park7e636d02019-01-28 16:16:54 +09001754
1755func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001756 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001757 apex {
1758 name: "myapex",
1759 key: "myapex.key",
1760 native_shared_libs: ["mylib"],
1761 }
1762
1763 apex_key {
1764 name: "myapex.key",
1765 public_key: "testkey.avbpubkey",
1766 private_key: "testkey.pem",
1767 }
1768
1769 cc_library_headers {
1770 name: "mylib_headers",
1771 export_include_dirs: ["my_include"],
1772 system_shared_libs: [],
1773 stl: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +09001774 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001775 }
1776
1777 cc_library {
1778 name: "mylib",
1779 srcs: ["mylib.cpp"],
1780 system_shared_libs: [],
1781 stl: "none",
1782 header_libs: ["mylib_headers"],
1783 export_header_lib_headers: ["mylib_headers"],
1784 stubs: {
1785 versions: ["1", "2", "3"],
1786 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001787 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001788 }
1789
1790 cc_library {
1791 name: "otherlib",
1792 srcs: ["mylib.cpp"],
1793 system_shared_libs: [],
1794 stl: "none",
1795 shared_libs: ["mylib"],
1796 }
1797 `)
1798
Colin Cross7113d202019-11-20 16:39:12 -08001799 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park7e636d02019-01-28 16:16:54 +09001800
1801 // Ensure that the include path of the header lib is exported to 'otherlib'
1802 ensureContains(t, cFlags, "-Imy_include")
1803}
Alex Light9670d332019-01-29 18:07:33 -08001804
Jiyong Park7cd10e32020-01-14 09:22:18 +09001805type fileInApex struct {
1806 path string // path in apex
Jooyung Hana57af4a2020-01-23 05:36:59 +00001807 src string // src path
Jiyong Park7cd10e32020-01-14 09:22:18 +09001808 isLink bool
1809}
1810
Jooyung Hana57af4a2020-01-23 05:36:59 +00001811func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex {
Jooyung Han31c470b2019-10-18 16:26:59 +09001812 t.Helper()
Jooyung Hana57af4a2020-01-23 05:36:59 +00001813 apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001814 copyCmds := apexRule.Args["copy_commands"]
1815 imageApexDir := "/image.apex/"
Jiyong Park7cd10e32020-01-14 09:22:18 +09001816 var ret []fileInApex
Jooyung Han31c470b2019-10-18 16:26:59 +09001817 for _, cmd := range strings.Split(copyCmds, "&&") {
1818 cmd = strings.TrimSpace(cmd)
1819 if cmd == "" {
1820 continue
1821 }
1822 terms := strings.Split(cmd, " ")
Jooyung Hana57af4a2020-01-23 05:36:59 +00001823 var dst, src string
Jiyong Park7cd10e32020-01-14 09:22:18 +09001824 var isLink bool
Jooyung Han31c470b2019-10-18 16:26:59 +09001825 switch terms[0] {
1826 case "mkdir":
1827 case "cp":
Jiyong Park7cd10e32020-01-14 09:22:18 +09001828 if len(terms) != 3 && len(terms) != 4 {
Jooyung Han31c470b2019-10-18 16:26:59 +09001829 t.Fatal("copyCmds contains invalid cp command", cmd)
1830 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001831 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001832 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001833 isLink = false
1834 case "ln":
1835 if len(terms) != 3 && len(terms) != 4 {
1836 // ln LINK TARGET or ln -s LINK TARGET
1837 t.Fatal("copyCmds contains invalid ln command", cmd)
1838 }
1839 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001840 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001841 isLink = true
1842 default:
1843 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1844 }
1845 if dst != "" {
Jooyung Han31c470b2019-10-18 16:26:59 +09001846 index := strings.Index(dst, imageApexDir)
1847 if index == -1 {
1848 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1849 }
1850 dstFile := dst[index+len(imageApexDir):]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001851 ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink})
Jooyung Han31c470b2019-10-18 16:26:59 +09001852 }
1853 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001854 return ret
1855}
1856
Jooyung Hana57af4a2020-01-23 05:36:59 +00001857func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) {
1858 t.Helper()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001859 var failed bool
1860 var surplus []string
1861 filesMatched := make(map[string]bool)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001862 for _, file := range getFiles(t, ctx, moduleName, variant) {
Jooyung Hane6436d72020-02-27 13:31:56 +09001863 mactchFound := false
Jiyong Park7cd10e32020-01-14 09:22:18 +09001864 for _, expected := range files {
1865 if matched, _ := path.Match(expected, file.path); matched {
1866 filesMatched[expected] = true
Jooyung Hane6436d72020-02-27 13:31:56 +09001867 mactchFound = true
1868 break
Jiyong Park7cd10e32020-01-14 09:22:18 +09001869 }
1870 }
Jooyung Hane6436d72020-02-27 13:31:56 +09001871 if !mactchFound {
1872 surplus = append(surplus, file.path)
1873 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001874 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001875
Jooyung Han31c470b2019-10-18 16:26:59 +09001876 if len(surplus) > 0 {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001877 sort.Strings(surplus)
Jooyung Han31c470b2019-10-18 16:26:59 +09001878 t.Log("surplus files", surplus)
1879 failed = true
1880 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001881
1882 if len(files) > len(filesMatched) {
1883 var missing []string
1884 for _, expected := range files {
1885 if !filesMatched[expected] {
1886 missing = append(missing, expected)
1887 }
1888 }
1889 sort.Strings(missing)
Jooyung Han31c470b2019-10-18 16:26:59 +09001890 t.Log("missing files", missing)
1891 failed = true
1892 }
1893 if failed {
1894 t.Fail()
1895 }
1896}
1897
Jooyung Han344d5432019-08-23 11:17:39 +09001898func TestVndkApexCurrent(t *testing.T) {
1899 ctx, _ := testApex(t, `
1900 apex_vndk {
1901 name: "myapex",
1902 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001903 }
1904
1905 apex_key {
1906 name: "myapex.key",
1907 public_key: "testkey.avbpubkey",
1908 private_key: "testkey.pem",
1909 }
1910
1911 cc_library {
1912 name: "libvndk",
1913 srcs: ["mylib.cpp"],
1914 vendor_available: true,
1915 vndk: {
1916 enabled: true,
1917 },
1918 system_shared_libs: [],
1919 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001920 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001921 }
1922
1923 cc_library {
1924 name: "libvndksp",
1925 srcs: ["mylib.cpp"],
1926 vendor_available: true,
1927 vndk: {
1928 enabled: true,
1929 support_system_process: true,
1930 },
1931 system_shared_libs: [],
1932 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001933 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001934 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001935 `+vndkLibrariesTxtFiles("current"))
Jooyung Han344d5432019-08-23 11:17:39 +09001936
Jooyung Hana57af4a2020-01-23 05:36:59 +00001937 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001938 "lib/libvndk.so",
1939 "lib/libvndksp.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09001940 "lib/libc++.so",
Jooyung Han31c470b2019-10-18 16:26:59 +09001941 "lib64/libvndk.so",
1942 "lib64/libvndksp.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09001943 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001944 "etc/llndk.libraries.VER.txt",
1945 "etc/vndkcore.libraries.VER.txt",
1946 "etc/vndksp.libraries.VER.txt",
1947 "etc/vndkprivate.libraries.VER.txt",
Jooyung Han31c470b2019-10-18 16:26:59 +09001948 })
Jooyung Han344d5432019-08-23 11:17:39 +09001949}
1950
1951func TestVndkApexWithPrebuilt(t *testing.T) {
1952 ctx, _ := testApex(t, `
1953 apex_vndk {
1954 name: "myapex",
1955 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001956 }
1957
1958 apex_key {
1959 name: "myapex.key",
1960 public_key: "testkey.avbpubkey",
1961 private_key: "testkey.pem",
1962 }
1963
1964 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001965 name: "libvndk",
1966 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001967 vendor_available: true,
1968 vndk: {
1969 enabled: true,
1970 },
1971 system_shared_libs: [],
1972 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001973 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001974 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001975
1976 cc_prebuilt_library_shared {
1977 name: "libvndk.arm",
1978 srcs: ["libvndk.arm.so"],
1979 vendor_available: true,
1980 vndk: {
1981 enabled: true,
1982 },
1983 enabled: false,
1984 arch: {
1985 arm: {
1986 enabled: true,
1987 },
1988 },
1989 system_shared_libs: [],
1990 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001991 apex_available: [ "myapex" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09001992 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001993 `+vndkLibrariesTxtFiles("current"),
1994 withFiles(map[string][]byte{
1995 "libvndk.so": nil,
1996 "libvndk.arm.so": nil,
1997 }))
Jooyung Han344d5432019-08-23 11:17:39 +09001998
Jooyung Hana57af4a2020-01-23 05:36:59 +00001999 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002000 "lib/libvndk.so",
2001 "lib/libvndk.arm.so",
2002 "lib64/libvndk.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09002003 "lib/libc++.so",
2004 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002005 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002006 })
Jooyung Han344d5432019-08-23 11:17:39 +09002007}
2008
Jooyung Han39edb6c2019-11-06 16:53:07 +09002009func vndkLibrariesTxtFiles(vers ...string) (result string) {
2010 for _, v := range vers {
2011 if v == "current" {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +09002012 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002013 result += `
2014 vndk_libraries_txt {
2015 name: "` + txt + `.libraries.txt",
2016 }
2017 `
2018 }
2019 } else {
2020 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
2021 result += `
2022 prebuilt_etc {
2023 name: "` + txt + `.libraries.` + v + `.txt",
2024 src: "dummy.txt",
2025 }
2026 `
2027 }
2028 }
2029 }
2030 return
2031}
2032
Jooyung Han344d5432019-08-23 11:17:39 +09002033func TestVndkApexVersion(t *testing.T) {
2034 ctx, _ := testApex(t, `
2035 apex_vndk {
2036 name: "myapex_v27",
2037 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002038 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002039 vndk_version: "27",
2040 }
2041
2042 apex_key {
2043 name: "myapex.key",
2044 public_key: "testkey.avbpubkey",
2045 private_key: "testkey.pem",
2046 }
2047
Jooyung Han31c470b2019-10-18 16:26:59 +09002048 vndk_prebuilt_shared {
2049 name: "libvndk27",
2050 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09002051 vendor_available: true,
2052 vndk: {
2053 enabled: true,
2054 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002055 target_arch: "arm64",
2056 arch: {
2057 arm: {
2058 srcs: ["libvndk27_arm.so"],
2059 },
2060 arm64: {
2061 srcs: ["libvndk27_arm64.so"],
2062 },
2063 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002064 apex_available: [ "myapex_v27" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002065 }
2066
2067 vndk_prebuilt_shared {
2068 name: "libvndk27",
2069 version: "27",
2070 vendor_available: true,
2071 vndk: {
2072 enabled: true,
2073 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002074 target_arch: "x86_64",
2075 arch: {
2076 x86: {
2077 srcs: ["libvndk27_x86.so"],
2078 },
2079 x86_64: {
2080 srcs: ["libvndk27_x86_64.so"],
2081 },
2082 },
Jooyung Han39edb6c2019-11-06 16:53:07 +09002083 }
2084 `+vndkLibrariesTxtFiles("27"),
2085 withFiles(map[string][]byte{
2086 "libvndk27_arm.so": nil,
2087 "libvndk27_arm64.so": nil,
2088 "libvndk27_x86.so": nil,
2089 "libvndk27_x86_64.so": nil,
2090 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002091
Jooyung Hana57af4a2020-01-23 05:36:59 +00002092 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002093 "lib/libvndk27_arm.so",
2094 "lib64/libvndk27_arm64.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002095 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002096 })
Jooyung Han344d5432019-08-23 11:17:39 +09002097}
2098
2099func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
2100 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
2101 apex_vndk {
2102 name: "myapex_v27",
2103 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002104 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002105 vndk_version: "27",
2106 }
2107 apex_vndk {
2108 name: "myapex_v27_other",
2109 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002110 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002111 vndk_version: "27",
2112 }
2113
2114 apex_key {
2115 name: "myapex.key",
2116 public_key: "testkey.avbpubkey",
2117 private_key: "testkey.pem",
2118 }
2119
2120 cc_library {
2121 name: "libvndk",
2122 srcs: ["mylib.cpp"],
2123 vendor_available: true,
2124 vndk: {
2125 enabled: true,
2126 },
2127 system_shared_libs: [],
2128 stl: "none",
2129 }
2130
2131 vndk_prebuilt_shared {
2132 name: "libvndk",
2133 version: "27",
2134 vendor_available: true,
2135 vndk: {
2136 enabled: true,
2137 },
2138 srcs: ["libvndk.so"],
2139 }
2140 `, withFiles(map[string][]byte{
2141 "libvndk.so": nil,
2142 }))
2143}
2144
Jooyung Han90eee022019-10-01 20:02:42 +09002145func TestVndkApexNameRule(t *testing.T) {
2146 ctx, _ := testApex(t, `
2147 apex_vndk {
2148 name: "myapex",
2149 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002150 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002151 }
2152 apex_vndk {
2153 name: "myapex_v28",
2154 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002155 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002156 vndk_version: "28",
2157 }
2158 apex_key {
2159 name: "myapex.key",
2160 public_key: "testkey.avbpubkey",
2161 private_key: "testkey.pem",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002162 }`+vndkLibrariesTxtFiles("28", "current"))
Jooyung Han90eee022019-10-01 20:02:42 +09002163
2164 assertApexName := func(expected, moduleName string) {
Jooyung Hana57af4a2020-01-23 05:36:59 +00002165 bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09002166 actual := proptools.String(bundle.properties.Apex_name)
2167 if !reflect.DeepEqual(actual, expected) {
2168 t.Errorf("Got '%v', expected '%v'", actual, expected)
2169 }
2170 }
2171
2172 assertApexName("com.android.vndk.vVER", "myapex")
2173 assertApexName("com.android.vndk.v28", "myapex_v28")
2174}
2175
Jooyung Han344d5432019-08-23 11:17:39 +09002176func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
2177 ctx, _ := testApex(t, `
2178 apex_vndk {
2179 name: "myapex",
2180 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002181 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002182 }
2183
2184 apex_key {
2185 name: "myapex.key",
2186 public_key: "testkey.avbpubkey",
2187 private_key: "testkey.pem",
2188 }
2189
2190 cc_library {
2191 name: "libvndk",
2192 srcs: ["mylib.cpp"],
2193 vendor_available: true,
2194 native_bridge_supported: true,
2195 host_supported: true,
2196 vndk: {
2197 enabled: true,
2198 },
2199 system_shared_libs: [],
2200 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002201 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002202 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002203 `+vndkLibrariesTxtFiles("current"),
2204 withTargets(map[android.OsType][]android.Target{
2205 android.Android: []android.Target{
2206 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2207 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2208 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
2209 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
2210 },
2211 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002212
Jooyung Hana57af4a2020-01-23 05:36:59 +00002213 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002214 "lib/libvndk.so",
2215 "lib64/libvndk.so",
Jooyung Hane6436d72020-02-27 13:31:56 +09002216 "lib/libc++.so",
2217 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002218 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002219 })
Jooyung Han344d5432019-08-23 11:17:39 +09002220}
2221
2222func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
2223 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
2224 apex_vndk {
2225 name: "myapex",
2226 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002227 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002228 native_bridge_supported: true,
2229 }
2230
2231 apex_key {
2232 name: "myapex.key",
2233 public_key: "testkey.avbpubkey",
2234 private_key: "testkey.pem",
2235 }
2236
2237 cc_library {
2238 name: "libvndk",
2239 srcs: ["mylib.cpp"],
2240 vendor_available: true,
2241 native_bridge_supported: true,
2242 host_supported: true,
2243 vndk: {
2244 enabled: true,
2245 },
2246 system_shared_libs: [],
2247 stl: "none",
2248 }
2249 `)
2250}
2251
Jooyung Han31c470b2019-10-18 16:26:59 +09002252func TestVndkApexWithBinder32(t *testing.T) {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002253 ctx, _ := testApex(t, `
Jooyung Han31c470b2019-10-18 16:26:59 +09002254 apex_vndk {
2255 name: "myapex_v27",
2256 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002257 file_contexts: ":myapex-file_contexts",
Jooyung Han31c470b2019-10-18 16:26:59 +09002258 vndk_version: "27",
2259 }
2260
2261 apex_key {
2262 name: "myapex.key",
2263 public_key: "testkey.avbpubkey",
2264 private_key: "testkey.pem",
2265 }
2266
2267 vndk_prebuilt_shared {
2268 name: "libvndk27",
2269 version: "27",
2270 target_arch: "arm",
2271 vendor_available: true,
2272 vndk: {
2273 enabled: true,
2274 },
2275 arch: {
2276 arm: {
2277 srcs: ["libvndk27.so"],
2278 }
2279 },
2280 }
2281
2282 vndk_prebuilt_shared {
2283 name: "libvndk27",
2284 version: "27",
2285 target_arch: "arm",
2286 binder32bit: true,
2287 vendor_available: true,
2288 vndk: {
2289 enabled: true,
2290 },
2291 arch: {
2292 arm: {
2293 srcs: ["libvndk27binder32.so"],
2294 }
2295 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002296 apex_available: [ "myapex_v27" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002297 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002298 `+vndkLibrariesTxtFiles("27"),
Jooyung Han31c470b2019-10-18 16:26:59 +09002299 withFiles(map[string][]byte{
2300 "libvndk27.so": nil,
2301 "libvndk27binder32.so": nil,
2302 }),
2303 withBinder32bit,
2304 withTargets(map[android.OsType][]android.Target{
2305 android.Android: []android.Target{
2306 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2307 },
2308 }),
2309 )
2310
Jooyung Hana57af4a2020-01-23 05:36:59 +00002311 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002312 "lib/libvndk27binder32.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002313 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002314 })
2315}
2316
Jooyung Hane1633032019-08-01 17:41:43 +09002317func TestDependenciesInApexManifest(t *testing.T) {
2318 ctx, _ := testApex(t, `
2319 apex {
2320 name: "myapex_nodep",
2321 key: "myapex.key",
2322 native_shared_libs: ["lib_nodep"],
2323 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002324 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002325 }
2326
2327 apex {
2328 name: "myapex_dep",
2329 key: "myapex.key",
2330 native_shared_libs: ["lib_dep"],
2331 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002332 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002333 }
2334
2335 apex {
2336 name: "myapex_provider",
2337 key: "myapex.key",
2338 native_shared_libs: ["libfoo"],
2339 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002340 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002341 }
2342
2343 apex {
2344 name: "myapex_selfcontained",
2345 key: "myapex.key",
2346 native_shared_libs: ["lib_dep", "libfoo"],
2347 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002348 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002349 }
2350
2351 apex_key {
2352 name: "myapex.key",
2353 public_key: "testkey.avbpubkey",
2354 private_key: "testkey.pem",
2355 }
2356
2357 cc_library {
2358 name: "lib_nodep",
2359 srcs: ["mylib.cpp"],
2360 system_shared_libs: [],
2361 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002362 apex_available: [ "myapex_nodep" ],
Jooyung Hane1633032019-08-01 17:41:43 +09002363 }
2364
2365 cc_library {
2366 name: "lib_dep",
2367 srcs: ["mylib.cpp"],
2368 shared_libs: ["libfoo"],
2369 system_shared_libs: [],
2370 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002371 apex_available: [
2372 "myapex_dep",
2373 "myapex_provider",
2374 "myapex_selfcontained",
2375 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002376 }
2377
2378 cc_library {
2379 name: "libfoo",
2380 srcs: ["mytest.cpp"],
2381 stubs: {
2382 versions: ["1"],
2383 },
2384 system_shared_libs: [],
2385 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002386 apex_available: [
2387 "myapex_provider",
2388 "myapex_selfcontained",
2389 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002390 }
2391 `)
2392
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002393 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09002394 var provideNativeLibs, requireNativeLibs []string
2395
Sundong Ahnabb64432019-10-22 13:58:29 +09002396 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002397 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2398 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002399 ensureListEmpty(t, provideNativeLibs)
2400 ensureListEmpty(t, requireNativeLibs)
2401
Sundong Ahnabb64432019-10-22 13:58:29 +09002402 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002403 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2404 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002405 ensureListEmpty(t, provideNativeLibs)
2406 ensureListContains(t, requireNativeLibs, "libfoo.so")
2407
Sundong Ahnabb64432019-10-22 13:58:29 +09002408 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002409 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2410 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002411 ensureListContains(t, provideNativeLibs, "libfoo.so")
2412 ensureListEmpty(t, requireNativeLibs)
2413
Sundong Ahnabb64432019-10-22 13:58:29 +09002414 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002415 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2416 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002417 ensureListContains(t, provideNativeLibs, "libfoo.so")
2418 ensureListEmpty(t, requireNativeLibs)
2419}
2420
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002421func TestApexName(t *testing.T) {
Jiyong Parkdb334862020-02-05 17:19:28 +09002422 ctx, config := testApex(t, `
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002423 apex {
2424 name: "myapex",
2425 key: "myapex.key",
2426 apex_name: "com.android.myapex",
Jiyong Parkdb334862020-02-05 17:19:28 +09002427 native_shared_libs: ["mylib"],
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002428 }
2429
2430 apex_key {
2431 name: "myapex.key",
2432 public_key: "testkey.avbpubkey",
2433 private_key: "testkey.pem",
2434 }
Jiyong Parkdb334862020-02-05 17:19:28 +09002435
2436 cc_library {
2437 name: "mylib",
2438 srcs: ["mylib.cpp"],
2439 system_shared_libs: [],
2440 stl: "none",
2441 apex_available: [
2442 "//apex_available:platform",
2443 "myapex",
2444 ],
2445 }
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002446 `)
2447
Sundong Ahnabb64432019-10-22 13:58:29 +09002448 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002449 apexManifestRule := module.Rule("apexManifestRule")
2450 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
2451 apexRule := module.Rule("apexRule")
2452 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
Jiyong Parkdb334862020-02-05 17:19:28 +09002453
2454 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2455 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2456 name := apexBundle.BaseModuleName()
2457 prefix := "TARGET_"
2458 var builder strings.Builder
2459 data.Custom(&builder, name, prefix, "", data)
2460 androidMk := builder.String()
2461 ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n")
2462 ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002463}
2464
Alex Light0851b882019-02-07 13:20:53 -08002465func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002466 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002467 apex {
2468 name: "myapex",
2469 key: "myapex.key",
2470 native_shared_libs: ["mylib_common"],
2471 }
2472
2473 apex_key {
2474 name: "myapex.key",
2475 public_key: "testkey.avbpubkey",
2476 private_key: "testkey.pem",
2477 }
2478
2479 cc_library {
2480 name: "mylib_common",
2481 srcs: ["mylib.cpp"],
2482 system_shared_libs: [],
2483 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002484 apex_available: [
2485 "//apex_available:platform",
2486 "myapex",
2487 ],
Alex Light0851b882019-02-07 13:20:53 -08002488 }
2489 `)
2490
Sundong Ahnabb64432019-10-22 13:58:29 +09002491 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002492 apexRule := module.Rule("apexRule")
2493 copyCmds := apexRule.Args["copy_commands"]
2494
2495 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
2496 t.Log("Apex was a test apex!")
2497 t.Fail()
2498 }
2499 // Ensure that main rule creates an output
2500 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2501
2502 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002503 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002504
2505 // Ensure that both direct and indirect deps are copied into apex
2506 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2507
Colin Cross7113d202019-11-20 16:39:12 -08002508 // Ensure that the platform variant ends with _shared
2509 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002510
2511 if !android.InAnyApex("mylib_common") {
2512 t.Log("Found mylib_common not in any apex!")
2513 t.Fail()
2514 }
2515}
2516
2517func TestTestApex(t *testing.T) {
2518 if android.InAnyApex("mylib_common_test") {
2519 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!")
2520 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002521 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002522 apex_test {
2523 name: "myapex",
2524 key: "myapex.key",
2525 native_shared_libs: ["mylib_common_test"],
2526 }
2527
2528 apex_key {
2529 name: "myapex.key",
2530 public_key: "testkey.avbpubkey",
2531 private_key: "testkey.pem",
2532 }
2533
2534 cc_library {
2535 name: "mylib_common_test",
2536 srcs: ["mylib.cpp"],
2537 system_shared_libs: [],
2538 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002539 // TODO: remove //apex_available:platform
2540 apex_available: [
2541 "//apex_available:platform",
2542 "myapex",
2543 ],
Alex Light0851b882019-02-07 13:20:53 -08002544 }
2545 `)
2546
Sundong Ahnabb64432019-10-22 13:58:29 +09002547 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002548 apexRule := module.Rule("apexRule")
2549 copyCmds := apexRule.Args["copy_commands"]
2550
2551 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
2552 t.Log("Apex was not a test apex!")
2553 t.Fail()
2554 }
2555 // Ensure that main rule creates an output
2556 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2557
2558 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002559 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002560
2561 // Ensure that both direct and indirect deps are copied into apex
2562 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
2563
Colin Cross7113d202019-11-20 16:39:12 -08002564 // Ensure that the platform variant ends with _shared
2565 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002566}
2567
Alex Light9670d332019-01-29 18:07:33 -08002568func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002569 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08002570 apex {
2571 name: "myapex",
2572 key: "myapex.key",
2573 multilib: {
2574 first: {
2575 native_shared_libs: ["mylib_common"],
2576 }
2577 },
2578 target: {
2579 android: {
2580 multilib: {
2581 first: {
2582 native_shared_libs: ["mylib"],
2583 }
2584 }
2585 },
2586 host: {
2587 multilib: {
2588 first: {
2589 native_shared_libs: ["mylib2"],
2590 }
2591 }
2592 }
2593 }
2594 }
2595
2596 apex_key {
2597 name: "myapex.key",
2598 public_key: "testkey.avbpubkey",
2599 private_key: "testkey.pem",
2600 }
2601
2602 cc_library {
2603 name: "mylib",
2604 srcs: ["mylib.cpp"],
2605 system_shared_libs: [],
2606 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002607 // TODO: remove //apex_available:platform
2608 apex_available: [
2609 "//apex_available:platform",
2610 "myapex",
2611 ],
Alex Light9670d332019-01-29 18:07:33 -08002612 }
2613
2614 cc_library {
2615 name: "mylib_common",
2616 srcs: ["mylib.cpp"],
2617 system_shared_libs: [],
2618 stl: "none",
2619 compile_multilib: "first",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002620 // TODO: remove //apex_available:platform
2621 apex_available: [
2622 "//apex_available:platform",
2623 "myapex",
2624 ],
Alex Light9670d332019-01-29 18:07:33 -08002625 }
2626
2627 cc_library {
2628 name: "mylib2",
2629 srcs: ["mylib.cpp"],
2630 system_shared_libs: [],
2631 stl: "none",
2632 compile_multilib: "first",
2633 }
2634 `)
2635
Sundong Ahnabb64432019-10-22 13:58:29 +09002636 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002637 copyCmds := apexRule.Args["copy_commands"]
2638
2639 // Ensure that main rule creates an output
2640 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2641
2642 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002643 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2644 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
2645 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light9670d332019-01-29 18:07:33 -08002646
2647 // Ensure that both direct and indirect deps are copied into apex
2648 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2649 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2650 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2651
Colin Cross7113d202019-11-20 16:39:12 -08002652 // Ensure that the platform variant ends with _shared
2653 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
2654 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
2655 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Alex Light9670d332019-01-29 18:07:33 -08002656}
Jiyong Park04480cf2019-02-06 00:16:29 +09002657
2658func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002659 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002660 apex {
2661 name: "myapex",
2662 key: "myapex.key",
2663 binaries: ["myscript"],
2664 }
2665
2666 apex_key {
2667 name: "myapex.key",
2668 public_key: "testkey.avbpubkey",
2669 private_key: "testkey.pem",
2670 }
2671
2672 sh_binary {
2673 name: "myscript",
2674 src: "mylib.cpp",
2675 filename: "myscript.sh",
2676 sub_dir: "script",
2677 }
2678 `)
2679
Sundong Ahnabb64432019-10-22 13:58:29 +09002680 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002681 copyCmds := apexRule.Args["copy_commands"]
2682
2683 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2684}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002685
Jooyung Han91df2082019-11-20 01:49:42 +09002686func TestApexInVariousPartition(t *testing.T) {
2687 testcases := []struct {
2688 propName, parition, flattenedPartition string
2689 }{
2690 {"", "system", "system_ext"},
2691 {"product_specific: true", "product", "product"},
2692 {"soc_specific: true", "vendor", "vendor"},
2693 {"proprietary: true", "vendor", "vendor"},
2694 {"vendor: true", "vendor", "vendor"},
2695 {"system_ext_specific: true", "system_ext", "system_ext"},
2696 }
2697 for _, tc := range testcases {
2698 t.Run(tc.propName+":"+tc.parition, func(t *testing.T) {
2699 ctx, _ := testApex(t, `
2700 apex {
2701 name: "myapex",
2702 key: "myapex.key",
2703 `+tc.propName+`
2704 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002705
Jooyung Han91df2082019-11-20 01:49:42 +09002706 apex_key {
2707 name: "myapex.key",
2708 public_key: "testkey.avbpubkey",
2709 private_key: "testkey.pem",
2710 }
2711 `)
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002712
Jooyung Han91df2082019-11-20 01:49:42 +09002713 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2714 expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex"
2715 actual := apex.installDir.String()
2716 if actual != expected {
2717 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2718 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002719
Jooyung Han91df2082019-11-20 01:49:42 +09002720 flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
2721 expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex"
2722 actual = flattened.installDir.String()
2723 if actual != expected {
2724 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2725 }
2726 })
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002727 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002728}
Jiyong Park67882562019-03-21 01:11:21 +09002729
Jooyung Han54aca7b2019-11-20 02:26:02 +09002730func TestFileContexts(t *testing.T) {
2731 ctx, _ := testApex(t, `
2732 apex {
2733 name: "myapex",
2734 key: "myapex.key",
2735 }
2736
2737 apex_key {
2738 name: "myapex.key",
2739 public_key: "testkey.avbpubkey",
2740 private_key: "testkey.pem",
2741 }
2742 `)
2743 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
2744 apexRule := module.Rule("apexRule")
2745 actual := apexRule.Args["file_contexts"]
2746 expected := "system/sepolicy/apex/myapex-file_contexts"
2747 if actual != expected {
2748 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2749 }
2750
2751 testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
2752 apex {
2753 name: "myapex",
2754 key: "myapex.key",
2755 file_contexts: "my_own_file_contexts",
2756 }
2757
2758 apex_key {
2759 name: "myapex.key",
2760 public_key: "testkey.avbpubkey",
2761 private_key: "testkey.pem",
2762 }
2763 `, withFiles(map[string][]byte{
2764 "my_own_file_contexts": nil,
2765 }))
2766
2767 testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
2768 apex {
2769 name: "myapex",
2770 key: "myapex.key",
2771 product_specific: true,
2772 file_contexts: "product_specific_file_contexts",
2773 }
2774
2775 apex_key {
2776 name: "myapex.key",
2777 public_key: "testkey.avbpubkey",
2778 private_key: "testkey.pem",
2779 }
2780 `)
2781
2782 ctx, _ = testApex(t, `
2783 apex {
2784 name: "myapex",
2785 key: "myapex.key",
2786 product_specific: true,
2787 file_contexts: "product_specific_file_contexts",
2788 }
2789
2790 apex_key {
2791 name: "myapex.key",
2792 public_key: "testkey.avbpubkey",
2793 private_key: "testkey.pem",
2794 }
2795 `, withFiles(map[string][]byte{
2796 "product_specific_file_contexts": nil,
2797 }))
2798 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2799 apexRule = module.Rule("apexRule")
2800 actual = apexRule.Args["file_contexts"]
2801 expected = "product_specific_file_contexts"
2802 if actual != expected {
2803 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2804 }
2805
2806 ctx, _ = testApex(t, `
2807 apex {
2808 name: "myapex",
2809 key: "myapex.key",
2810 product_specific: true,
2811 file_contexts: ":my-file-contexts",
2812 }
2813
2814 apex_key {
2815 name: "myapex.key",
2816 public_key: "testkey.avbpubkey",
2817 private_key: "testkey.pem",
2818 }
2819
2820 filegroup {
2821 name: "my-file-contexts",
2822 srcs: ["product_specific_file_contexts"],
2823 }
2824 `, withFiles(map[string][]byte{
2825 "product_specific_file_contexts": nil,
2826 }))
2827 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2828 apexRule = module.Rule("apexRule")
2829 actual = apexRule.Args["file_contexts"]
2830 expected = "product_specific_file_contexts"
2831 if actual != expected {
2832 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2833 }
2834}
2835
Jiyong Park67882562019-03-21 01:11:21 +09002836func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002837 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002838 apex_key {
2839 name: "myapex.key",
2840 public_key: ":my.avbpubkey",
2841 private_key: ":my.pem",
2842 product_specific: true,
2843 }
2844
2845 filegroup {
2846 name: "my.avbpubkey",
2847 srcs: ["testkey2.avbpubkey"],
2848 }
2849
2850 filegroup {
2851 name: "my.pem",
2852 srcs: ["testkey2.pem"],
2853 }
2854 `)
2855
2856 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2857 expected_pubkey := "testkey2.avbpubkey"
2858 actual_pubkey := apex_key.public_key_file.String()
2859 if actual_pubkey != expected_pubkey {
2860 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2861 }
2862 expected_privkey := "testkey2.pem"
2863 actual_privkey := apex_key.private_key_file.String()
2864 if actual_privkey != expected_privkey {
2865 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2866 }
2867}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002868
2869func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002870 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002871 prebuilt_apex {
2872 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002873 arch: {
2874 arm64: {
2875 src: "myapex-arm64.apex",
2876 },
2877 arm: {
2878 src: "myapex-arm.apex",
2879 },
2880 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002881 }
2882 `)
2883
2884 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2885
Jiyong Parkc95714e2019-03-29 14:23:10 +09002886 expectedInput := "myapex-arm64.apex"
2887 if prebuilt.inputApex.String() != expectedInput {
2888 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2889 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002890}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002891
2892func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002893 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002894 prebuilt_apex {
2895 name: "myapex",
2896 src: "myapex-arm.apex",
2897 filename: "notmyapex.apex",
2898 }
2899 `)
2900
2901 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2902
2903 expected := "notmyapex.apex"
2904 if p.installFilename != expected {
2905 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2906 }
2907}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002908
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002909func TestPrebuiltOverrides(t *testing.T) {
2910 ctx, config := testApex(t, `
2911 prebuilt_apex {
2912 name: "myapex.prebuilt",
2913 src: "myapex-arm.apex",
2914 overrides: [
2915 "myapex",
2916 ],
2917 }
2918 `)
2919
2920 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2921
2922 expected := []string{"myapex"}
Jiyong Park0b0e1b92019-12-03 13:24:29 +09002923 actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002924 if !reflect.DeepEqual(actual, expected) {
Jiyong Parkb0a012c2019-11-14 17:17:03 +09002925 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002926 }
2927}
2928
Roland Levillain630846d2019-06-26 12:48:34 +01002929func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002930 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002931 apex_test {
2932 name: "myapex",
2933 key: "myapex.key",
2934 tests: [
2935 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002936 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002937 ],
2938 }
2939
2940 apex_key {
2941 name: "myapex.key",
2942 public_key: "testkey.avbpubkey",
2943 private_key: "testkey.pem",
2944 }
2945
2946 cc_test {
2947 name: "mytest",
2948 gtest: false,
2949 srcs: ["mytest.cpp"],
2950 relative_install_path: "test",
2951 system_shared_libs: [],
2952 static_executable: true,
2953 stl: "none",
2954 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002955
2956 cc_test {
2957 name: "mytests",
2958 gtest: false,
2959 srcs: [
2960 "mytest1.cpp",
2961 "mytest2.cpp",
2962 "mytest3.cpp",
2963 ],
2964 test_per_src: true,
2965 relative_install_path: "test",
2966 system_shared_libs: [],
2967 static_executable: true,
2968 stl: "none",
2969 }
Roland Levillain630846d2019-06-26 12:48:34 +01002970 `)
2971
Sundong Ahnabb64432019-10-22 13:58:29 +09002972 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01002973 copyCmds := apexRule.Args["copy_commands"]
2974
2975 // Ensure that test dep is copied into apex.
2976 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002977
2978 // Ensure that test deps built with `test_per_src` are copied into apex.
2979 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2980 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2981 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002982
2983 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09002984 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01002985 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2986 name := apexBundle.BaseModuleName()
2987 prefix := "TARGET_"
2988 var builder strings.Builder
2989 data.Custom(&builder, name, prefix, "", data)
2990 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09002991 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2992 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2993 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2994 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
Jooyung Han214bf372019-11-12 13:03:50 +09002995 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
Jooyung Han31c470b2019-10-18 16:26:59 +09002996 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01002997 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002998}
2999
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003000func TestInstallExtraFlattenedApexes(t *testing.T) {
3001 ctx, config := testApex(t, `
3002 apex {
3003 name: "myapex",
3004 key: "myapex.key",
3005 }
3006 apex_key {
3007 name: "myapex.key",
3008 public_key: "testkey.avbpubkey",
3009 private_key: "testkey.pem",
3010 }
3011 `, func(fs map[string][]byte, config android.Config) {
3012 config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
3013 })
3014 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Jiyong Park83dc74b2020-01-14 18:38:44 +09003015 ensureListContains(t, ab.requiredDeps, "myapex.flattened")
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003016 mk := android.AndroidMkDataForTest(t, config, "", ab)
3017 var builder strings.Builder
3018 mk.Custom(&builder, ab.Name(), "TARGET_", "", mk)
3019 androidMk := builder.String()
3020 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened")
3021}
3022
Jooyung Han5c998b92019-06-27 11:30:33 +09003023func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003024 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09003025 apex {
3026 name: "myapex",
3027 key: "myapex.key",
3028 native_shared_libs: ["mylib"],
3029 uses: ["commonapex"],
3030 }
3031
3032 apex {
3033 name: "commonapex",
3034 key: "myapex.key",
3035 native_shared_libs: ["libcommon"],
3036 provide_cpp_shared_libs: true,
3037 }
3038
3039 apex_key {
3040 name: "myapex.key",
3041 public_key: "testkey.avbpubkey",
3042 private_key: "testkey.pem",
3043 }
3044
3045 cc_library {
3046 name: "mylib",
3047 srcs: ["mylib.cpp"],
3048 shared_libs: ["libcommon"],
3049 system_shared_libs: [],
3050 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003051 apex_available: [ "myapex" ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003052 }
3053
3054 cc_library {
3055 name: "libcommon",
3056 srcs: ["mylib_common.cpp"],
3057 system_shared_libs: [],
3058 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003059 // TODO: remove //apex_available:platform
3060 apex_available: [
3061 "//apex_available:platform",
3062 "commonapex",
3063 "myapex",
3064 ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003065 }
3066 `)
3067
Sundong Ahnabb64432019-10-22 13:58:29 +09003068 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003069 apexRule1 := module1.Rule("apexRule")
3070 copyCmds1 := apexRule1.Args["copy_commands"]
3071
Sundong Ahnabb64432019-10-22 13:58:29 +09003072 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003073 apexRule2 := module2.Rule("apexRule")
3074 copyCmds2 := apexRule2.Args["copy_commands"]
3075
Colin Cross7113d202019-11-20 16:39:12 -08003076 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
3077 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex")
Jooyung Han5c998b92019-06-27 11:30:33 +09003078 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
3079 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
3080 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
3081}
3082
3083func TestApexUsesFailsIfNotProvided(t *testing.T) {
3084 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
3085 apex {
3086 name: "myapex",
3087 key: "myapex.key",
3088 uses: ["commonapex"],
3089 }
3090
3091 apex {
3092 name: "commonapex",
3093 key: "myapex.key",
3094 }
3095
3096 apex_key {
3097 name: "myapex.key",
3098 public_key: "testkey.avbpubkey",
3099 private_key: "testkey.pem",
3100 }
3101 `)
3102 testApexError(t, `uses: "commonapex" is not a provider`, `
3103 apex {
3104 name: "myapex",
3105 key: "myapex.key",
3106 uses: ["commonapex"],
3107 }
3108
3109 cc_library {
3110 name: "commonapex",
3111 system_shared_libs: [],
3112 stl: "none",
3113 }
3114
3115 apex_key {
3116 name: "myapex.key",
3117 public_key: "testkey.avbpubkey",
3118 private_key: "testkey.pem",
3119 }
3120 `)
3121}
3122
3123func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
3124 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
3125 apex {
3126 name: "myapex",
3127 key: "myapex.key",
3128 use_vendor: true,
3129 uses: ["commonapex"],
3130 }
3131
3132 apex {
3133 name: "commonapex",
3134 key: "myapex.key",
3135 provide_cpp_shared_libs: true,
3136 }
3137
3138 apex_key {
3139 name: "myapex.key",
3140 public_key: "testkey.avbpubkey",
3141 private_key: "testkey.pem",
3142 }
Jooyung Handc782442019-11-01 03:14:38 +09003143 `, func(fs map[string][]byte, config android.Config) {
3144 setUseVendorWhitelistForTest(config, []string{"myapex"})
3145 })
Jooyung Han5c998b92019-06-27 11:30:33 +09003146}
3147
Jooyung Hand48f3c32019-08-23 11:18:57 +09003148func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
3149 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
3150 apex {
3151 name: "myapex",
3152 key: "myapex.key",
3153 native_shared_libs: ["libfoo"],
3154 }
3155
3156 apex_key {
3157 name: "myapex.key",
3158 public_key: "testkey.avbpubkey",
3159 private_key: "testkey.pem",
3160 }
3161
3162 cc_library {
3163 name: "libfoo",
3164 stl: "none",
3165 system_shared_libs: [],
3166 enabled: false,
3167 }
3168 `)
3169 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
3170 apex {
3171 name: "myapex",
3172 key: "myapex.key",
3173 java_libs: ["myjar"],
3174 }
3175
3176 apex_key {
3177 name: "myapex.key",
3178 public_key: "testkey.avbpubkey",
3179 private_key: "testkey.pem",
3180 }
3181
3182 java_library {
3183 name: "myjar",
3184 srcs: ["foo/bar/MyClass.java"],
3185 sdk_version: "none",
3186 system_modules: "none",
Jooyung Hand48f3c32019-08-23 11:18:57 +09003187 enabled: false,
3188 }
3189 `)
3190}
3191
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003192func TestApexWithApps(t *testing.T) {
3193 ctx, _ := testApex(t, `
3194 apex {
3195 name: "myapex",
3196 key: "myapex.key",
3197 apps: [
3198 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09003199 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003200 ],
3201 }
3202
3203 apex_key {
3204 name: "myapex.key",
3205 public_key: "testkey.avbpubkey",
3206 private_key: "testkey.pem",
3207 }
3208
3209 android_app {
3210 name: "AppFoo",
3211 srcs: ["foo/bar/MyClass.java"],
Colin Cross094cde42020-02-15 10:38:00 -08003212 sdk_version: "current",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003213 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09003214 jni_libs: ["libjni"],
Colin Cross094cde42020-02-15 10:38:00 -08003215 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003216 apex_available: [ "myapex" ],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003217 }
Jiyong Parkf7487312019-10-17 12:54:30 +09003218
3219 android_app {
3220 name: "AppFooPriv",
3221 srcs: ["foo/bar/MyClass.java"],
Colin Cross094cde42020-02-15 10:38:00 -08003222 sdk_version: "current",
Jiyong Parkf7487312019-10-17 12:54:30 +09003223 system_modules: "none",
3224 privileged: true,
Colin Cross094cde42020-02-15 10:38:00 -08003225 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003226 apex_available: [ "myapex" ],
Jiyong Parkf7487312019-10-17 12:54:30 +09003227 }
Jiyong Park8be103b2019-11-08 15:53:48 +09003228
3229 cc_library_shared {
3230 name: "libjni",
3231 srcs: ["mylib.cpp"],
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003232 shared_libs: ["libfoo"],
3233 stl: "none",
3234 system_shared_libs: [],
3235 apex_available: [ "myapex" ],
3236 sdk_version: "current",
3237 }
3238
3239 cc_library_shared {
3240 name: "libfoo",
Jiyong Park8be103b2019-11-08 15:53:48 +09003241 stl: "none",
3242 system_shared_libs: [],
Jiyong Park0f80c182020-01-31 02:49:53 +09003243 apex_available: [ "myapex" ],
Colin Cross094cde42020-02-15 10:38:00 -08003244 sdk_version: "current",
Jiyong Park8be103b2019-11-08 15:53:48 +09003245 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003246 `)
3247
Sundong Ahnabb64432019-10-22 13:58:29 +09003248 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003249 apexRule := module.Rule("apexRule")
3250 copyCmds := apexRule.Args["copy_commands"]
3251
3252 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09003253 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003254
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003255 appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs")
3256 // JNI libraries are uncompressed
Jiyong Park52cd06f2019-11-11 10:14:32 +09003257 if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003258 t.Errorf("jni libs are not uncompressed for AppFoo")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003259 }
Jooyung Hanb7bebe22020-02-25 16:59:29 +09003260 // JNI libraries including transitive deps are
3261 for _, jni := range []string{"libjni", "libfoo"} {
3262 jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile()
3263 // ... embedded inside APK (jnilibs.zip)
3264 ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String())
3265 // ... and not directly inside the APEX
3266 ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so")
3267 }
Dario Frenicde2a032019-10-27 00:29:22 +01003268}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003269
Dario Frenicde2a032019-10-27 00:29:22 +01003270func TestApexWithAppImports(t *testing.T) {
3271 ctx, _ := testApex(t, `
3272 apex {
3273 name: "myapex",
3274 key: "myapex.key",
3275 apps: [
3276 "AppFooPrebuilt",
3277 "AppFooPrivPrebuilt",
3278 ],
3279 }
3280
3281 apex_key {
3282 name: "myapex.key",
3283 public_key: "testkey.avbpubkey",
3284 private_key: "testkey.pem",
3285 }
3286
3287 android_app_import {
3288 name: "AppFooPrebuilt",
3289 apk: "PrebuiltAppFoo.apk",
3290 presigned: true,
3291 dex_preopt: {
3292 enabled: false,
3293 },
3294 }
3295
3296 android_app_import {
3297 name: "AppFooPrivPrebuilt",
3298 apk: "PrebuiltAppFooPriv.apk",
3299 privileged: true,
3300 presigned: true,
3301 dex_preopt: {
3302 enabled: false,
3303 },
3304 }
3305 `)
3306
Sundong Ahnabb64432019-10-22 13:58:29 +09003307 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01003308 apexRule := module.Rule("apexRule")
3309 copyCmds := apexRule.Args["copy_commands"]
3310
3311 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
3312 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003313}
3314
Dario Freni6f3937c2019-12-20 22:58:03 +00003315func TestApexWithTestHelperApp(t *testing.T) {
3316 ctx, _ := testApex(t, `
3317 apex {
3318 name: "myapex",
3319 key: "myapex.key",
3320 apps: [
3321 "TesterHelpAppFoo",
3322 ],
3323 }
3324
3325 apex_key {
3326 name: "myapex.key",
3327 public_key: "testkey.avbpubkey",
3328 private_key: "testkey.pem",
3329 }
3330
3331 android_test_helper_app {
3332 name: "TesterHelpAppFoo",
3333 srcs: ["foo/bar/MyClass.java"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003334 apex_available: [ "myapex" ],
Dario Freni6f3937c2019-12-20 22:58:03 +00003335 }
3336
3337 `)
3338
3339 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3340 apexRule := module.Rule("apexRule")
3341 copyCmds := apexRule.Args["copy_commands"]
3342
3343 ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk")
3344}
3345
Jooyung Han18020ea2019-11-13 10:50:48 +09003346func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
3347 // libfoo's apex_available comes from cc_defaults
3348 testApexError(t, `"myapex" .*: requires "libfoo" that is not available for the APEX`, `
3349 apex {
3350 name: "myapex",
3351 key: "myapex.key",
3352 native_shared_libs: ["libfoo"],
3353 }
3354
3355 apex_key {
3356 name: "myapex.key",
3357 public_key: "testkey.avbpubkey",
3358 private_key: "testkey.pem",
3359 }
3360
3361 apex {
3362 name: "otherapex",
3363 key: "myapex.key",
3364 native_shared_libs: ["libfoo"],
3365 }
3366
3367 cc_defaults {
3368 name: "libfoo-defaults",
3369 apex_available: ["otherapex"],
3370 }
3371
3372 cc_library {
3373 name: "libfoo",
3374 defaults: ["libfoo-defaults"],
3375 stl: "none",
3376 system_shared_libs: [],
3377 }`)
3378}
3379
Jiyong Park127b40b2019-09-30 16:04:35 +09003380func TestApexAvailable(t *testing.T) {
3381 // libfoo is not available to myapex, but only to otherapex
3382 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
3383 apex {
3384 name: "myapex",
3385 key: "myapex.key",
3386 native_shared_libs: ["libfoo"],
3387 }
3388
3389 apex_key {
3390 name: "myapex.key",
3391 public_key: "testkey.avbpubkey",
3392 private_key: "testkey.pem",
3393 }
3394
3395 apex {
3396 name: "otherapex",
3397 key: "otherapex.key",
3398 native_shared_libs: ["libfoo"],
3399 }
3400
3401 apex_key {
3402 name: "otherapex.key",
3403 public_key: "testkey.avbpubkey",
3404 private_key: "testkey.pem",
3405 }
3406
3407 cc_library {
3408 name: "libfoo",
3409 stl: "none",
3410 system_shared_libs: [],
3411 apex_available: ["otherapex"],
3412 }`)
3413
3414 // libbar is an indirect dep
3415 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
3416 apex {
3417 name: "myapex",
3418 key: "myapex.key",
3419 native_shared_libs: ["libfoo"],
3420 }
3421
3422 apex_key {
3423 name: "myapex.key",
3424 public_key: "testkey.avbpubkey",
3425 private_key: "testkey.pem",
3426 }
3427
3428 apex {
3429 name: "otherapex",
3430 key: "otherapex.key",
3431 native_shared_libs: ["libfoo"],
3432 }
3433
3434 apex_key {
3435 name: "otherapex.key",
3436 public_key: "testkey.avbpubkey",
3437 private_key: "testkey.pem",
3438 }
3439
3440 cc_library {
3441 name: "libfoo",
3442 stl: "none",
3443 shared_libs: ["libbar"],
3444 system_shared_libs: [],
3445 apex_available: ["myapex", "otherapex"],
3446 }
3447
3448 cc_library {
3449 name: "libbar",
3450 stl: "none",
3451 system_shared_libs: [],
3452 apex_available: ["otherapex"],
3453 }`)
3454
3455 testApexError(t, "\"otherapex\" is not a valid module name", `
3456 apex {
3457 name: "myapex",
3458 key: "myapex.key",
3459 native_shared_libs: ["libfoo"],
3460 }
3461
3462 apex_key {
3463 name: "myapex.key",
3464 public_key: "testkey.avbpubkey",
3465 private_key: "testkey.pem",
3466 }
3467
3468 cc_library {
3469 name: "libfoo",
3470 stl: "none",
3471 system_shared_libs: [],
3472 apex_available: ["otherapex"],
3473 }`)
3474
3475 ctx, _ := testApex(t, `
3476 apex {
3477 name: "myapex",
3478 key: "myapex.key",
3479 native_shared_libs: ["libfoo", "libbar"],
3480 }
3481
3482 apex_key {
3483 name: "myapex.key",
3484 public_key: "testkey.avbpubkey",
3485 private_key: "testkey.pem",
3486 }
3487
3488 cc_library {
3489 name: "libfoo",
3490 stl: "none",
3491 system_shared_libs: [],
Jiyong Park323a4c32020-03-01 17:29:06 +09003492 runtime_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003493 apex_available: ["myapex"],
3494 }
3495
3496 cc_library {
3497 name: "libbar",
3498 stl: "none",
3499 system_shared_libs: [],
3500 apex_available: ["//apex_available:anyapex"],
Jiyong Park323a4c32020-03-01 17:29:06 +09003501 }
3502
3503 cc_library {
3504 name: "libbaz",
3505 stl: "none",
3506 system_shared_libs: [],
3507 stubs: {
3508 versions: ["10", "20", "30"],
3509 },
Jiyong Park127b40b2019-09-30 16:04:35 +09003510 }`)
3511
3512 // check that libfoo and libbar are created only for myapex, but not for the platform
Jiyong Park0f80c182020-01-31 02:49:53 +09003513 // TODO(jiyong) the checks for the platform variant are removed because we now create
3514 // the platform variant regardless of the apex_availability. Instead, we will make sure that
3515 // the platform variants are not used from other platform modules. When that is done,
3516 // these checks will be replaced by expecting a specific error message that will be
3517 // emitted when the platform variant is used.
3518 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3519 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3520 // ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
3521 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")
Jiyong Park127b40b2019-09-30 16:04:35 +09003522
3523 ctx, _ = testApex(t, `
3524 apex {
3525 name: "myapex",
3526 key: "myapex.key",
3527 }
3528
3529 apex_key {
3530 name: "myapex.key",
3531 public_key: "testkey.avbpubkey",
3532 private_key: "testkey.pem",
3533 }
3534
3535 cc_library {
3536 name: "libfoo",
3537 stl: "none",
3538 system_shared_libs: [],
3539 apex_available: ["//apex_available:platform"],
3540 }`)
3541
3542 // check that libfoo is created only for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003543 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3544 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003545
3546 ctx, _ = testApex(t, `
3547 apex {
3548 name: "myapex",
3549 key: "myapex.key",
3550 native_shared_libs: ["libfoo"],
3551 }
3552
3553 apex_key {
3554 name: "myapex.key",
3555 public_key: "testkey.avbpubkey",
3556 private_key: "testkey.pem",
3557 }
3558
3559 cc_library {
3560 name: "libfoo",
3561 stl: "none",
3562 system_shared_libs: [],
3563 apex_available: ["myapex"],
3564 static: {
3565 apex_available: ["//apex_available:platform"],
3566 },
3567 }`)
3568
3569 // shared variant of libfoo is only available to myapex
Jiyong Park0f80c182020-01-31 02:49:53 +09003570 // TODO(jiyong) the checks for the platform variant are removed because we now create
3571 // the platform variant regardless of the apex_availability. Instead, we will make sure that
3572 // the platform variants are not used from other platform modules. When that is done,
3573 // these checks will be replaced by expecting a specific error message that will be
3574 // emitted when the platform variant is used.
3575 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3576 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3577 // // but the static variant is available to both myapex and the platform
3578 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
3579 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09003580}
3581
Jiyong Park5d790c32019-11-15 18:40:32 +09003582func TestOverrideApex(t *testing.T) {
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003583 ctx, config := testApex(t, `
Jiyong Park5d790c32019-11-15 18:40:32 +09003584 apex {
3585 name: "myapex",
3586 key: "myapex.key",
3587 apps: ["app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003588 overrides: ["oldapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003589 }
3590
3591 override_apex {
3592 name: "override_myapex",
3593 base: "myapex",
3594 apps: ["override_app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003595 overrides: ["unknownapex"],
Baligh Uddin004d7172020-02-19 21:29:28 -08003596 logging_parent: "com.foo.bar",
Jiyong Park5d790c32019-11-15 18:40:32 +09003597 }
3598
3599 apex_key {
3600 name: "myapex.key",
3601 public_key: "testkey.avbpubkey",
3602 private_key: "testkey.pem",
3603 }
3604
3605 android_app {
3606 name: "app",
3607 srcs: ["foo/bar/MyClass.java"],
3608 package_name: "foo",
3609 sdk_version: "none",
3610 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003611 apex_available: [ "myapex" ],
Jiyong Park5d790c32019-11-15 18:40:32 +09003612 }
3613
3614 override_android_app {
3615 name: "override_app",
3616 base: "app",
3617 package_name: "bar",
3618 }
Jiyong Park20bacab2020-03-03 11:45:41 +09003619 `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"}))
Jiyong Park5d790c32019-11-15 18:40:32 +09003620
Jiyong Park317645e2019-12-05 13:20:58 +09003621 originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule)
3622 overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule)
3623 if originalVariant.GetOverriddenBy() != "" {
3624 t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
3625 }
3626 if overriddenVariant.GetOverriddenBy() != "override_myapex" {
3627 t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
3628 }
3629
Jiyong Park5d790c32019-11-15 18:40:32 +09003630 module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image")
3631 apexRule := module.Rule("apexRule")
3632 copyCmds := apexRule.Args["copy_commands"]
3633
3634 ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk")
3635 ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003636
3637 apexBundle := module.Module().(*apexBundle)
3638 name := apexBundle.Name()
3639 if name != "override_myapex" {
3640 t.Errorf("name should be \"override_myapex\", but was %q", name)
3641 }
3642
Baligh Uddin004d7172020-02-19 21:29:28 -08003643 if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" {
3644 t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent)
3645 }
3646
Jiyong Park20bacab2020-03-03 11:45:41 +09003647 optFlags := apexRule.Args["opt_flags"]
3648 ensureContains(t, optFlags, "--override_apk_package_name com.android.myapex")
3649
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003650 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3651 var builder strings.Builder
3652 data.Custom(&builder, name, "TARGET_", "", data)
3653 androidMk := builder.String()
Jiyong Parkf653b052019-11-18 15:39:01 +09003654 ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003655 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
3656 ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003657 ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003658 ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
Jiyong Parkf653b052019-11-18 15:39:01 +09003659 ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003660 ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
3661 ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
Jiyong Park5d790c32019-11-15 18:40:32 +09003662}
3663
Jooyung Han214bf372019-11-12 13:03:50 +09003664func TestLegacyAndroid10Support(t *testing.T) {
3665 ctx, _ := testApex(t, `
3666 apex {
3667 name: "myapex",
3668 key: "myapex.key",
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003669 native_shared_libs: ["mylib"],
Jooyung Han214bf372019-11-12 13:03:50 +09003670 legacy_android10_support: true,
3671 }
3672
3673 apex_key {
3674 name: "myapex.key",
3675 public_key: "testkey.avbpubkey",
3676 private_key: "testkey.pem",
3677 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003678
3679 cc_library {
3680 name: "mylib",
3681 srcs: ["mylib.cpp"],
3682 stl: "libc++",
3683 system_shared_libs: [],
3684 apex_available: [ "myapex" ],
3685 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003686 `, withUnbundledBuild)
Jooyung Han214bf372019-11-12 13:03:50 +09003687
3688 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3689 args := module.Rule("apexRule").Args
3690 ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String())
Dario Frenie3546902020-01-14 23:50:25 +00003691 ensureNotContains(t, args["opt_flags"], "--no_hashtree")
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003692
3693 // The copies of the libraries in the apex should have one more dependency than
3694 // the ones outside the apex, namely the unwinder. Ideally we should check
3695 // the dependency names directly here but for some reason the names are blank in
3696 // this test.
3697 for _, lib := range []string{"libc++", "mylib"} {
3698 apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits
3699 nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits
3700 if len(apexImplicits) != len(nonApexImplicits)+1 {
3701 t.Errorf("%q missing unwinder dep", lib)
3702 }
3703 }
Jooyung Han214bf372019-11-12 13:03:50 +09003704}
3705
Jooyung Han58f26ab2019-12-18 15:34:32 +09003706func TestJavaSDKLibrary(t *testing.T) {
3707 ctx, _ := testApex(t, `
3708 apex {
3709 name: "myapex",
3710 key: "myapex.key",
3711 java_libs: ["foo"],
3712 }
3713
3714 apex_key {
3715 name: "myapex.key",
3716 public_key: "testkey.avbpubkey",
3717 private_key: "testkey.pem",
3718 }
3719
3720 java_sdk_library {
3721 name: "foo",
3722 srcs: ["a.java"],
3723 api_packages: ["foo"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003724 apex_available: [ "myapex" ],
Jooyung Han58f26ab2019-12-18 15:34:32 +09003725 }
3726 `, withFiles(map[string][]byte{
3727 "api/current.txt": nil,
3728 "api/removed.txt": nil,
3729 "api/system-current.txt": nil,
3730 "api/system-removed.txt": nil,
3731 "api/test-current.txt": nil,
3732 "api/test-removed.txt": nil,
3733 }))
3734
3735 // java_sdk_library installs both impl jar and permission XML
Jooyung Hana57af4a2020-01-23 05:36:59 +00003736 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han58f26ab2019-12-18 15:34:32 +09003737 "javalib/foo.jar",
3738 "etc/permissions/foo.xml",
3739 })
3740 // Permission XML should point to the activated path of impl jar of java_sdk_library
Jiyong Parke3833882020-02-17 17:28:10 +09003741 sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml")
3742 ensureContains(t, sdkLibrary.RuleParams.Command, `<library name=\"foo\" file=\"/apex/myapex/javalib/foo.jar\"`)
Jooyung Han58f26ab2019-12-18 15:34:32 +09003743}
3744
atrost6e126252020-01-27 17:01:16 +00003745func TestCompatConfig(t *testing.T) {
3746 ctx, _ := testApex(t, `
3747 apex {
3748 name: "myapex",
3749 key: "myapex.key",
3750 prebuilts: ["myjar-platform-compat-config"],
3751 java_libs: ["myjar"],
3752 }
3753
3754 apex_key {
3755 name: "myapex.key",
3756 public_key: "testkey.avbpubkey",
3757 private_key: "testkey.pem",
3758 }
3759
3760 platform_compat_config {
3761 name: "myjar-platform-compat-config",
3762 src: ":myjar",
3763 }
3764
3765 java_library {
3766 name: "myjar",
3767 srcs: ["foo/bar/MyClass.java"],
3768 sdk_version: "none",
3769 system_modules: "none",
atrost6e126252020-01-27 17:01:16 +00003770 apex_available: [ "myapex" ],
3771 }
3772 `)
3773 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
3774 "etc/compatconfig/myjar-platform-compat-config.xml",
3775 "javalib/myjar.jar",
3776 })
3777}
3778
Jiyong Park479321d2019-12-16 11:47:12 +09003779func TestRejectNonInstallableJavaLibrary(t *testing.T) {
3780 testApexError(t, `"myjar" is not configured to be compiled into dex`, `
3781 apex {
3782 name: "myapex",
3783 key: "myapex.key",
3784 java_libs: ["myjar"],
3785 }
3786
3787 apex_key {
3788 name: "myapex.key",
3789 public_key: "testkey.avbpubkey",
3790 private_key: "testkey.pem",
3791 }
3792
3793 java_library {
3794 name: "myjar",
3795 srcs: ["foo/bar/MyClass.java"],
3796 sdk_version: "none",
3797 system_modules: "none",
Jiyong Park6b21c7d2020-02-11 09:16:01 +09003798 compile_dex: false,
Jiyong Park479321d2019-12-16 11:47:12 +09003799 }
3800 `)
3801}
3802
Jiyong Park7afd1072019-12-30 16:56:33 +09003803func TestCarryRequiredModuleNames(t *testing.T) {
3804 ctx, config := testApex(t, `
3805 apex {
3806 name: "myapex",
3807 key: "myapex.key",
3808 native_shared_libs: ["mylib"],
3809 }
3810
3811 apex_key {
3812 name: "myapex.key",
3813 public_key: "testkey.avbpubkey",
3814 private_key: "testkey.pem",
3815 }
3816
3817 cc_library {
3818 name: "mylib",
3819 srcs: ["mylib.cpp"],
3820 system_shared_libs: [],
3821 stl: "none",
3822 required: ["a", "b"],
3823 host_required: ["c", "d"],
3824 target_required: ["e", "f"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003825 apex_available: [ "myapex" ],
Jiyong Park7afd1072019-12-30 16:56:33 +09003826 }
3827 `)
3828
3829 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
3830 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3831 name := apexBundle.BaseModuleName()
3832 prefix := "TARGET_"
3833 var builder strings.Builder
3834 data.Custom(&builder, name, prefix, "", data)
3835 androidMk := builder.String()
3836 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n")
3837 ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n")
3838 ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n")
3839}
3840
Jiyong Park7cd10e32020-01-14 09:22:18 +09003841func TestSymlinksFromApexToSystem(t *testing.T) {
3842 bp := `
3843 apex {
3844 name: "myapex",
3845 key: "myapex.key",
3846 native_shared_libs: ["mylib"],
3847 java_libs: ["myjar"],
3848 }
3849
Jiyong Park9d677202020-02-19 16:29:35 +09003850 apex {
3851 name: "myapex.updatable",
3852 key: "myapex.key",
3853 native_shared_libs: ["mylib"],
3854 java_libs: ["myjar"],
3855 updatable: true,
3856 }
3857
Jiyong Park7cd10e32020-01-14 09:22:18 +09003858 apex_key {
3859 name: "myapex.key",
3860 public_key: "testkey.avbpubkey",
3861 private_key: "testkey.pem",
3862 }
3863
3864 cc_library {
3865 name: "mylib",
3866 srcs: ["mylib.cpp"],
3867 shared_libs: ["myotherlib"],
3868 system_shared_libs: [],
3869 stl: "none",
3870 apex_available: [
3871 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003872 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003873 "//apex_available:platform",
3874 ],
3875 }
3876
3877 cc_library {
3878 name: "myotherlib",
3879 srcs: ["mylib.cpp"],
3880 system_shared_libs: [],
3881 stl: "none",
3882 apex_available: [
3883 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003884 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003885 "//apex_available:platform",
3886 ],
3887 }
3888
3889 java_library {
3890 name: "myjar",
3891 srcs: ["foo/bar/MyClass.java"],
3892 sdk_version: "none",
3893 system_modules: "none",
3894 libs: ["myotherjar"],
Jiyong Park7cd10e32020-01-14 09:22:18 +09003895 apex_available: [
3896 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003897 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003898 "//apex_available:platform",
3899 ],
3900 }
3901
3902 java_library {
3903 name: "myotherjar",
3904 srcs: ["foo/bar/MyClass.java"],
3905 sdk_version: "none",
3906 system_modules: "none",
3907 apex_available: [
3908 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003909 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003910 "//apex_available:platform",
3911 ],
3912 }
3913 `
3914
3915 ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) {
3916 for _, f := range files {
3917 if f.path == file {
3918 if f.isLink {
3919 t.Errorf("%q is not a real file", file)
3920 }
3921 return
3922 }
3923 }
3924 t.Errorf("%q is not found", file)
3925 }
3926
3927 ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) {
3928 for _, f := range files {
3929 if f.path == file {
3930 if !f.isLink {
3931 t.Errorf("%q is not a symlink", file)
3932 }
3933 return
3934 }
3935 }
3936 t.Errorf("%q is not found", file)
3937 }
3938
Jiyong Park9d677202020-02-19 16:29:35 +09003939 // For unbundled build, symlink shouldn't exist regardless of whether an APEX
3940 // is updatable or not
Jiyong Park7cd10e32020-01-14 09:22:18 +09003941 ctx, _ := testApex(t, bp, withUnbundledBuild)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003942 files := getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003943 ensureRealfileExists(t, files, "javalib/myjar.jar")
3944 ensureRealfileExists(t, files, "lib64/mylib.so")
3945 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3946
Jiyong Park9d677202020-02-19 16:29:35 +09003947 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
3948 ensureRealfileExists(t, files, "javalib/myjar.jar")
3949 ensureRealfileExists(t, files, "lib64/mylib.so")
3950 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3951
3952 // For bundled build, symlink to the system for the non-updatable APEXes only
Jiyong Park7cd10e32020-01-14 09:22:18 +09003953 ctx, _ = testApex(t, bp)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003954 files = getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003955 ensureRealfileExists(t, files, "javalib/myjar.jar")
3956 ensureRealfileExists(t, files, "lib64/mylib.so")
3957 ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
Jiyong Park9d677202020-02-19 16:29:35 +09003958
3959 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
3960 ensureRealfileExists(t, files, "javalib/myjar.jar")
3961 ensureRealfileExists(t, files, "lib64/mylib.so")
3962 ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
Jiyong Park7cd10e32020-01-14 09:22:18 +09003963}
3964
Jooyung Han643adc42020-02-27 13:50:06 +09003965func TestApexWithJniLibs(t *testing.T) {
3966 ctx, _ := testApex(t, `
3967 apex {
3968 name: "myapex",
3969 key: "myapex.key",
3970 jni_libs: ["mylib"],
3971 }
3972
3973 apex_key {
3974 name: "myapex.key",
3975 public_key: "testkey.avbpubkey",
3976 private_key: "testkey.pem",
3977 }
3978
3979 cc_library {
3980 name: "mylib",
3981 srcs: ["mylib.cpp"],
3982 shared_libs: ["mylib2"],
3983 system_shared_libs: [],
3984 stl: "none",
3985 apex_available: [ "myapex" ],
3986 }
3987
3988 cc_library {
3989 name: "mylib2",
3990 srcs: ["mylib.cpp"],
3991 system_shared_libs: [],
3992 stl: "none",
3993 apex_available: [ "myapex" ],
3994 }
3995 `)
3996
3997 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
3998 // Notice mylib2.so (transitive dep) is not added as a jni_lib
3999 ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so")
4000 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
4001 "lib64/mylib.so",
4002 "lib64/mylib2.so",
4003 })
4004}
4005
4006func TestApexWithJniLibs_Errors(t *testing.T) {
4007 testApexError(t, `jni_libs: "xxx" is not a cc_library`, `
4008 apex {
4009 name: "myapex",
4010 key: "myapex.key",
4011 jni_libs: ["xxx"],
4012 }
4013
4014 apex_key {
4015 name: "myapex.key",
4016 public_key: "testkey.avbpubkey",
4017 private_key: "testkey.pem",
4018 }
4019
4020 prebuilt_etc {
4021 name: "xxx",
4022 src: "xxx",
4023 }
4024 `, withFiles(map[string][]byte{
4025 "xxx": nil,
4026 }))
4027}
4028
Jiyong Parkbd159612020-02-28 15:22:21 +09004029func TestAppBundle(t *testing.T) {
4030 ctx, _ := testApex(t, `
4031 apex {
4032 name: "myapex",
4033 key: "myapex.key",
4034 apps: ["AppFoo"],
4035 }
4036
4037 apex_key {
4038 name: "myapex.key",
4039 public_key: "testkey.avbpubkey",
4040 private_key: "testkey.pem",
4041 }
4042
4043 android_app {
4044 name: "AppFoo",
4045 srcs: ["foo/bar/MyClass.java"],
4046 sdk_version: "none",
4047 system_modules: "none",
4048 apex_available: [ "myapex" ],
4049 }
Jiyong Parkcfaa1642020-02-28 16:51:07 +09004050 `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"}))
Jiyong Parkbd159612020-02-28 15:22:21 +09004051
4052 bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config")
4053 content := bundleConfigRule.Args["content"]
4054
4055 ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
Jiyong Parkcfaa1642020-02-28 16:51:07 +09004056 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 +09004057}
4058
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07004059func TestMain(m *testing.M) {
4060 run := func() int {
4061 setUp()
4062 defer tearDown()
4063
4064 return m.Run()
4065 }
4066
4067 os.Exit(run())
4068}