blob: ba54f2e54ecc5e5212df95770c8f2ab7a32c443a [file] [log] [blame]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
Jiyong Park25fc6a92018-11-18 18:02:45 +090018 "io/ioutil"
19 "os"
Jooyung Han39edb6c2019-11-06 16:53:07 +090020 "path"
Jaewoong Jung22f7d182019-07-16 18:25:41 -070021 "reflect"
Jooyung Han31c470b2019-10-18 16:26:59 +090022 "sort"
Jiyong Park25fc6a92018-11-18 18:02:45 +090023 "strings"
24 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090025
26 "github.com/google/blueprint/proptools"
27
28 "android/soong/android"
29 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090030 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090031)
32
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070033var buildDir string
34
Jooyung Hand3639552019-08-09 12:57:43 +090035// names returns name list from white space separated string
36func names(s string) (ns []string) {
37 for _, n := range strings.Split(s, " ") {
38 if len(n) > 0 {
39 ns = append(ns, n)
40 }
41 }
42 return
43}
44
Jooyung Han344d5432019-08-23 11:17:39 +090045func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) {
46 t.Helper()
47 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090048 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
49 if len(errs) > 0 {
50 android.FailIfNoMatchingErrors(t, pattern, errs)
51 return
52 }
53 _, errs = ctx.PrepareBuildActions(config)
54 if len(errs) > 0 {
55 android.FailIfNoMatchingErrors(t, pattern, errs)
56 return
57 }
58
59 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
60}
61
Jooyung Han344d5432019-08-23 11:17:39 +090062func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
63 t.Helper()
64 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090065 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
66 android.FailIfErrored(t, errs)
67 _, errs = ctx.PrepareBuildActions(config)
68 android.FailIfErrored(t, errs)
Jaewoong Jung22f7d182019-07-16 18:25:41 -070069 return ctx, config
Jooyung Han5c998b92019-06-27 11:30:33 +090070}
71
Jooyung Han344d5432019-08-23 11:17:39 +090072type testCustomizer func(fs map[string][]byte, config android.Config)
73
74func withFiles(files map[string][]byte) testCustomizer {
75 return func(fs map[string][]byte, config android.Config) {
76 for k, v := range files {
77 fs[k] = v
78 }
79 }
80}
81
82func withTargets(targets map[android.OsType][]android.Target) testCustomizer {
83 return func(fs map[string][]byte, config android.Config) {
84 for k, v := range targets {
85 config.Targets[k] = v
86 }
87 }
88}
89
Jiyong Parkaf8998c2020-02-28 16:51:07 +090090func withManifestPackageNameOverrides(specs []string) testCustomizer {
91 return func(fs map[string][]byte, config android.Config) {
92 config.TestProductVariables.ManifestPackageNameOverrides = specs
93 }
94}
95
Jooyung Han31c470b2019-10-18 16:26:59 +090096func withBinder32bit(fs map[string][]byte, config android.Config) {
97 config.TestProductVariables.Binder32bit = proptools.BoolPtr(true)
98}
99
Jiyong Park7cd10e32020-01-14 09:22:18 +0900100func withUnbundledBuild(fs map[string][]byte, config android.Config) {
101 config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
102}
103
Jooyung Han344d5432019-08-23 11:17:39 +0900104func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
Jooyung Han671f1ce2019-12-17 12:47:13 +0900105 android.ClearApexDependency()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900106
107 bp = bp + `
Jooyung Han54aca7b2019-11-20 02:26:02 +0900108 filegroup {
109 name: "myapex-file_contexts",
110 srcs: [
111 "system/sepolicy/apex/myapex-file_contexts",
112 ],
113 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900114 `
Colin Cross98be1bb2019-12-13 20:41:13 -0800115
Colin Crossf9aabd72020-02-15 11:29:50 -0800116 bp = bp + cc.GatherRequiredDepsForTest(android.Android)
117
Dario Frenicde2a032019-10-27 00:29:22 +0100118 bp = bp + java.GatherRequiredDepsForTest()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900119
Jooyung Han344d5432019-08-23 11:17:39 +0900120 fs := map[string][]byte{
Jooyung Han54aca7b2019-11-20 02:26:02 +0900121 "a.java": nil,
122 "PrebuiltAppFoo.apk": nil,
123 "PrebuiltAppFooPriv.apk": nil,
124 "build/make/target/product/security": nil,
125 "apex_manifest.json": nil,
126 "AndroidManifest.xml": nil,
127 "system/sepolicy/apex/myapex-file_contexts": nil,
Jiyong Park9d677202020-02-19 16:29:35 +0900128 "system/sepolicy/apex/myapex.updatable-file_contexts": nil,
Jiyong Park83dc74b2020-01-14 18:38:44 +0900129 "system/sepolicy/apex/myapex2-file_contexts": nil,
Jooyung Han54aca7b2019-11-20 02:26:02 +0900130 "system/sepolicy/apex/otherapex-file_contexts": nil,
131 "system/sepolicy/apex/commonapex-file_contexts": nil,
132 "system/sepolicy/apex/com.android.vndk-file_contexts": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -0800133 "mylib.cpp": nil,
134 "mylib_common.cpp": nil,
135 "mytest.cpp": nil,
136 "mytest1.cpp": nil,
137 "mytest2.cpp": nil,
138 "mytest3.cpp": nil,
139 "myprebuilt": nil,
140 "my_include": nil,
141 "foo/bar/MyClass.java": nil,
142 "prebuilt.jar": nil,
143 "vendor/foo/devkeys/test.x509.pem": nil,
144 "vendor/foo/devkeys/test.pk8": nil,
145 "testkey.x509.pem": nil,
146 "testkey.pk8": nil,
147 "testkey.override.x509.pem": nil,
148 "testkey.override.pk8": nil,
149 "vendor/foo/devkeys/testkey.avbpubkey": nil,
150 "vendor/foo/devkeys/testkey.pem": nil,
151 "NOTICE": nil,
152 "custom_notice": nil,
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
235// ensure that 'result' contains 'expected'
236func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900237 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900238 if !strings.Contains(result, expected) {
239 t.Errorf("%q is not found in %q", expected, result)
240 }
241}
242
243// ensures that 'result' does not contain 'notExpected'
244func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900245 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900246 if strings.Contains(result, notExpected) {
247 t.Errorf("%q is found in %q", notExpected, result)
248 }
249}
250
251func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900252 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900253 if !android.InList(expected, result) {
254 t.Errorf("%q is not found in %v", expected, result)
255 }
256}
257
258func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900259 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900260 if android.InList(notExpected, result) {
261 t.Errorf("%q is found in %v", notExpected, result)
262 }
263}
264
Jooyung Hane1633032019-08-01 17:41:43 +0900265func ensureListEmpty(t *testing.T, result []string) {
266 t.Helper()
267 if len(result) > 0 {
268 t.Errorf("%q is expected to be empty", result)
269 }
270}
271
Jiyong Park25fc6a92018-11-18 18:02:45 +0900272// Minimal test
273func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700274 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900275 apex_defaults {
276 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900277 manifest: ":myapex.manifest",
278 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900279 key: "myapex.key",
280 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800281 multilib: {
282 both: {
283 binaries: ["foo",],
284 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900285 },
Jooyung Han5a80d9f2019-12-23 15:38:34 +0900286 java_libs: ["myjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900287 }
288
Jiyong Park30ca9372019-02-07 16:27:23 +0900289 apex {
290 name: "myapex",
291 defaults: ["myapex-defaults"],
292 }
293
Jiyong Park25fc6a92018-11-18 18:02:45 +0900294 apex_key {
295 name: "myapex.key",
296 public_key: "testkey.avbpubkey",
297 private_key: "testkey.pem",
298 }
299
Jiyong Park809bb722019-02-13 21:33:49 +0900300 filegroup {
301 name: "myapex.manifest",
302 srcs: ["apex_manifest.json"],
303 }
304
305 filegroup {
306 name: "myapex.androidmanifest",
307 srcs: ["AndroidManifest.xml"],
308 }
309
Jiyong Park25fc6a92018-11-18 18:02:45 +0900310 cc_library {
311 name: "mylib",
312 srcs: ["mylib.cpp"],
313 shared_libs: ["mylib2"],
314 system_shared_libs: [],
315 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000316 // TODO: remove //apex_available:platform
317 apex_available: [
318 "//apex_available:platform",
319 "myapex",
320 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900321 }
322
Alex Light3d673592019-01-18 14:37:31 -0800323 cc_binary {
324 name: "foo",
325 srcs: ["mylib.cpp"],
326 compile_multilib: "both",
327 multilib: {
328 lib32: {
329 suffix: "32",
330 },
331 lib64: {
332 suffix: "64",
333 },
334 },
335 symlinks: ["foo_link_"],
336 symlink_preferred_arch: true,
337 system_shared_libs: [],
338 static_executable: true,
339 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000340 apex_available: [ "myapex" ],
Alex Light3d673592019-01-18 14:37:31 -0800341 }
342
Jiyong Park25fc6a92018-11-18 18:02:45 +0900343 cc_library {
344 name: "mylib2",
345 srcs: ["mylib.cpp"],
346 system_shared_libs: [],
347 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900348 notice: "custom_notice",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000349 // TODO: remove //apex_available:platform
350 apex_available: [
351 "//apex_available:platform",
352 "myapex",
353 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900354 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900355
356 java_library {
357 name: "myjar",
358 srcs: ["foo/bar/MyClass.java"],
359 sdk_version: "none",
360 system_modules: "none",
Jiyong Park7f7766d2019-07-25 22:02:35 +0900361 static_libs: ["myotherjar"],
Jiyong Park3ff16992019-12-27 14:11:47 +0900362 libs: ["mysharedjar"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000363 // TODO: remove //apex_available:platform
364 apex_available: [
365 "//apex_available:platform",
366 "myapex",
367 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900368 }
369
370 java_library {
371 name: "myotherjar",
372 srcs: ["foo/bar/MyClass.java"],
373 sdk_version: "none",
374 system_modules: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +0900375 // TODO: remove //apex_available:platform
376 apex_available: [
377 "//apex_available:platform",
378 "myapex",
379 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900380 }
Jiyong Park3ff16992019-12-27 14:11:47 +0900381
382 java_library {
383 name: "mysharedjar",
384 srcs: ["foo/bar/MyClass.java"],
385 sdk_version: "none",
386 system_modules: "none",
Jiyong Park3ff16992019-12-27 14:11:47 +0900387 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900388 `)
389
Sundong Ahnabb64432019-10-22 13:58:29 +0900390 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900391
392 optFlags := apexRule.Args["opt_flags"]
393 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700394 // Ensure that the NOTICE output is being packaged as an asset.
Sundong Ahnabb64432019-10-22 13:58:29 +0900395 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900396
Jiyong Park25fc6a92018-11-18 18:02:45 +0900397 copyCmds := apexRule.Args["copy_commands"]
398
399 // Ensure that main rule creates an output
400 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
401
402 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800403 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900404 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900405
406 // Ensure that apex variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800407 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900408 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900409
410 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800411 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
412 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900413 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
414 // .. but not for java libs
415 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Jiyong Park3ff16992019-12-27 14:11:47 +0900416 ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800417
Colin Cross7113d202019-11-20 16:39:12 -0800418 // Ensure that the platform variant ends with _shared or _common
419 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
420 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900421 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
422 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park3ff16992019-12-27 14:11:47 +0900423 ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common")
424
425 // Ensure that dynamic dependency to java libs are not included
426 ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex")
Alex Light3d673592019-01-18 14:37:31 -0800427
428 // Ensure that all symlinks are present.
429 found_foo_link_64 := false
430 found_foo := false
431 for _, cmd := range strings.Split(copyCmds, " && ") {
Jiyong Park7cd10e32020-01-14 09:22:18 +0900432 if strings.HasPrefix(cmd, "ln -sfn foo64") {
Alex Light3d673592019-01-18 14:37:31 -0800433 if strings.HasSuffix(cmd, "bin/foo") {
434 found_foo = true
435 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
436 found_foo_link_64 = true
437 }
438 }
439 }
440 good := found_foo && found_foo_link_64
441 if !good {
442 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
443 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900444
Sundong Ahnabb64432019-10-22 13:58:29 +0900445 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700446 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700447 if len(noticeInputs) != 2 {
448 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900449 }
450 ensureListContains(t, noticeInputs, "NOTICE")
451 ensureListContains(t, noticeInputs, "custom_notice")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900452
453 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 +0900454 ensureListContains(t, depsInfo, "myjar <- myapex")
455 ensureListContains(t, depsInfo, "mylib <- myapex")
456 ensureListContains(t, depsInfo, "mylib2 <- mylib")
457 ensureListContains(t, depsInfo, "myotherjar <- myjar")
458 ensureListContains(t, depsInfo, "mysharedjar (external) <- myjar")
Alex Light5098a612018-11-29 17:12:15 -0800459}
460
Jooyung Hanf21c7972019-12-16 22:32:06 +0900461func TestDefaults(t *testing.T) {
462 ctx, _ := testApex(t, `
463 apex_defaults {
464 name: "myapex-defaults",
465 key: "myapex.key",
466 prebuilts: ["myetc"],
467 native_shared_libs: ["mylib"],
468 java_libs: ["myjar"],
469 apps: ["AppFoo"],
470 }
471
472 prebuilt_etc {
473 name: "myetc",
474 src: "myprebuilt",
475 }
476
477 apex {
478 name: "myapex",
479 defaults: ["myapex-defaults"],
480 }
481
482 apex_key {
483 name: "myapex.key",
484 public_key: "testkey.avbpubkey",
485 private_key: "testkey.pem",
486 }
487
488 cc_library {
489 name: "mylib",
490 system_shared_libs: [],
491 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000492 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900493 }
494
495 java_library {
496 name: "myjar",
497 srcs: ["foo/bar/MyClass.java"],
498 sdk_version: "none",
499 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000500 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900501 }
502
503 android_app {
504 name: "AppFoo",
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 `)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000511 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Hanf21c7972019-12-16 22:32:06 +0900512 "etc/myetc",
513 "javalib/myjar.jar",
514 "lib64/mylib.so",
515 "app/AppFoo/AppFoo.apk",
516 })
517}
518
Jooyung Han01a3ee22019-11-02 02:52:25 +0900519func TestApexManifest(t *testing.T) {
520 ctx, _ := testApex(t, `
521 apex {
522 name: "myapex",
523 key: "myapex.key",
524 }
525
526 apex_key {
527 name: "myapex.key",
528 public_key: "testkey.avbpubkey",
529 private_key: "testkey.pem",
530 }
531 `)
532
533 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han214bf372019-11-12 13:03:50 +0900534 args := module.Rule("apexRule").Args
535 if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() {
536 t.Error("manifest should be apex_manifest.pb, but " + manifest)
537 }
Jooyung Han01a3ee22019-11-02 02:52:25 +0900538}
539
Alex Light5098a612018-11-29 17:12:15 -0800540func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700541 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800542 apex {
543 name: "myapex",
544 key: "myapex.key",
545 payload_type: "zip",
546 native_shared_libs: ["mylib"],
547 }
548
549 apex_key {
550 name: "myapex.key",
551 public_key: "testkey.avbpubkey",
552 private_key: "testkey.pem",
553 }
554
555 cc_library {
556 name: "mylib",
557 srcs: ["mylib.cpp"],
558 shared_libs: ["mylib2"],
559 system_shared_libs: [],
560 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000561 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800562 }
563
564 cc_library {
565 name: "mylib2",
566 srcs: ["mylib.cpp"],
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
Sundong Ahnabb64432019-10-22 13:58:29 +0900573 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
Alex Light5098a612018-11-29 17:12:15 -0800574 copyCmds := zipApexRule.Args["copy_commands"]
575
576 // Ensure that main rule creates an output
577 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
578
579 // Ensure that APEX variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800580 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800581
582 // Ensure that APEX variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800583 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800584
585 // Ensure that both direct and indirect deps are copied into apex
586 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
587 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900588}
589
590func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700591 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900592 apex {
593 name: "myapex",
594 key: "myapex.key",
595 native_shared_libs: ["mylib", "mylib3"],
596 }
597
598 apex_key {
599 name: "myapex.key",
600 public_key: "testkey.avbpubkey",
601 private_key: "testkey.pem",
602 }
603
604 cc_library {
605 name: "mylib",
606 srcs: ["mylib.cpp"],
607 shared_libs: ["mylib2", "mylib3"],
608 system_shared_libs: [],
609 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000610 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900611 }
612
613 cc_library {
614 name: "mylib2",
615 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900616 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900617 system_shared_libs: [],
618 stl: "none",
619 stubs: {
620 versions: ["1", "2", "3"],
621 },
622 }
623
624 cc_library {
625 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900626 srcs: ["mylib.cpp"],
627 shared_libs: ["mylib4"],
628 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900629 stl: "none",
630 stubs: {
631 versions: ["10", "11", "12"],
632 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000633 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900634 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900635
636 cc_library {
637 name: "mylib4",
638 srcs: ["mylib.cpp"],
639 system_shared_libs: [],
640 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000641 apex_available: [ "myapex" ],
Jiyong Park28d395a2018-12-07 22:42:47 +0900642 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900643 `)
644
Sundong Ahnabb64432019-10-22 13:58:29 +0900645 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900646 copyCmds := apexRule.Args["copy_commands"]
647
648 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800649 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900650
651 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800652 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900653
654 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800655 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900656
Colin Cross7113d202019-11-20 16:39:12 -0800657 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900658
659 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900660 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900661 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900662 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900663
664 // 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 -0800665 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900666 // .. and not linking to the stubs variant of mylib3
Colin Cross7113d202019-11-20 16:39:12 -0800667 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900668
669 // Ensure that stubs libs are built without -include flags
Jiyong Park0f80c182020-01-31 02:49:53 +0900670 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900671 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900672
673 // Ensure that genstub is invoked with --apex
Jiyong Park3ff16992019-12-27 14:11:47 +0900674 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"])
Jooyung Han671f1ce2019-12-17 12:47:13 +0900675
Jooyung Hana57af4a2020-01-23 05:36:59 +0000676 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han671f1ce2019-12-17 12:47:13 +0900677 "lib64/mylib.so",
678 "lib64/mylib3.so",
679 "lib64/mylib4.so",
680 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900681}
682
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900683func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700684 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900685 apex {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900686 name: "myapex2",
687 key: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900688 native_shared_libs: ["mylib"],
689 }
690
691 apex_key {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900692 name: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900693 public_key: "testkey.avbpubkey",
694 private_key: "testkey.pem",
695 }
696
697 cc_library {
698 name: "mylib",
699 srcs: ["mylib.cpp"],
700 shared_libs: ["libfoo#10"],
Jiyong Park678c8812020-02-07 17:25:49 +0900701 static_libs: ["libbaz"],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900702 system_shared_libs: [],
703 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000704 apex_available: [ "myapex2" ],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900705 }
706
707 cc_library {
708 name: "libfoo",
709 srcs: ["mylib.cpp"],
710 shared_libs: ["libbar"],
711 system_shared_libs: [],
712 stl: "none",
713 stubs: {
714 versions: ["10", "20", "30"],
715 },
716 }
717
718 cc_library {
719 name: "libbar",
720 srcs: ["mylib.cpp"],
721 system_shared_libs: [],
722 stl: "none",
723 }
724
Jiyong Park678c8812020-02-07 17:25:49 +0900725 cc_library_static {
726 name: "libbaz",
727 srcs: ["mylib.cpp"],
728 system_shared_libs: [],
729 stl: "none",
730 apex_available: [ "myapex2" ],
731 }
732
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900733 `)
734
Jiyong Park83dc74b2020-01-14 18:38:44 +0900735 apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900736 copyCmds := apexRule.Args["copy_commands"]
737
738 // Ensure that direct non-stubs dep is always included
739 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
740
741 // Ensure that indirect stubs dep is not included
742 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
743
744 // Ensure that dependency of stubs is not included
745 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
746
Jiyong Park83dc74b2020-01-14 18:38:44 +0900747 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900748
749 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900750 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900751 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900752 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900753
Jiyong Park3ff16992019-12-27 14:11:47 +0900754 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900755
756 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
757 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900758
759 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 +0900760
761 ensureListContains(t, depsInfo, "mylib <- myapex2")
762 ensureListContains(t, depsInfo, "libbaz <- mylib")
763 ensureListContains(t, depsInfo, "libfoo (external) <- mylib")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900764}
765
Jooyung Hand3639552019-08-09 12:57:43 +0900766func TestApexWithRuntimeLibsDependency(t *testing.T) {
767 /*
768 myapex
769 |
770 v (runtime_libs)
771 mylib ------+------> libfoo [provides stub]
772 |
773 `------> libbar
774 */
775 ctx, _ := testApex(t, `
776 apex {
777 name: "myapex",
778 key: "myapex.key",
779 native_shared_libs: ["mylib"],
780 }
781
782 apex_key {
783 name: "myapex.key",
784 public_key: "testkey.avbpubkey",
785 private_key: "testkey.pem",
786 }
787
788 cc_library {
789 name: "mylib",
790 srcs: ["mylib.cpp"],
791 runtime_libs: ["libfoo", "libbar"],
792 system_shared_libs: [],
793 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000794 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900795 }
796
797 cc_library {
798 name: "libfoo",
799 srcs: ["mylib.cpp"],
800 system_shared_libs: [],
801 stl: "none",
802 stubs: {
803 versions: ["10", "20", "30"],
804 },
805 }
806
807 cc_library {
808 name: "libbar",
809 srcs: ["mylib.cpp"],
810 system_shared_libs: [],
811 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000812 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900813 }
814
815 `)
816
Sundong Ahnabb64432019-10-22 13:58:29 +0900817 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Hand3639552019-08-09 12:57:43 +0900818 copyCmds := apexRule.Args["copy_commands"]
819
820 // Ensure that direct non-stubs dep is always included
821 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
822
823 // Ensure that indirect stubs dep is not included
824 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
825
826 // Ensure that runtime_libs dep in included
827 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
828
Sundong Ahnabb64432019-10-22 13:58:29 +0900829 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900830 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
831 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900832
833}
834
Jooyung Han9c80bae2019-08-20 17:30:57 +0900835func TestApexDependencyToLLNDK(t *testing.T) {
836 ctx, _ := testApex(t, `
837 apex {
838 name: "myapex",
839 key: "myapex.key",
840 use_vendor: true,
841 native_shared_libs: ["mylib"],
842 }
843
844 apex_key {
845 name: "myapex.key",
846 public_key: "testkey.avbpubkey",
847 private_key: "testkey.pem",
848 }
849
850 cc_library {
851 name: "mylib",
852 srcs: ["mylib.cpp"],
853 vendor_available: true,
854 shared_libs: ["libbar"],
855 system_shared_libs: [],
856 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000857 apex_available: [ "myapex" ],
Jooyung Han9c80bae2019-08-20 17:30:57 +0900858 }
859
860 cc_library {
861 name: "libbar",
862 srcs: ["mylib.cpp"],
863 system_shared_libs: [],
864 stl: "none",
865 }
866
867 llndk_library {
868 name: "libbar",
869 symbol_file: "",
870 }
Jooyung Handc782442019-11-01 03:14:38 +0900871 `, func(fs map[string][]byte, config android.Config) {
872 setUseVendorWhitelistForTest(config, []string{"myapex"})
873 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900874
Sundong Ahnabb64432019-10-22 13:58:29 +0900875 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900876 copyCmds := apexRule.Args["copy_commands"]
877
878 // Ensure that LLNDK dep is not included
879 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
880
Sundong Ahnabb64432019-10-22 13:58:29 +0900881 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900882 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900883
884 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900885 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900886
887}
888
Jiyong Park25fc6a92018-11-18 18:02:45 +0900889func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700890 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900891 apex {
892 name: "myapex",
893 key: "myapex.key",
894 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
895 }
896
897 apex_key {
898 name: "myapex.key",
899 public_key: "testkey.avbpubkey",
900 private_key: "testkey.pem",
901 }
902
903 cc_library {
904 name: "mylib",
905 srcs: ["mylib.cpp"],
906 shared_libs: ["libdl#27"],
907 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000908 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900909 }
910
911 cc_library_shared {
912 name: "mylib_shared",
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 {
Jiyong Parkb0788572018-12-20 22:10:17 +0900920 name: "libBootstrap",
921 srcs: ["mylib.cpp"],
922 stl: "none",
923 bootstrap: true,
924 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900925 `)
926
Sundong Ahnabb64432019-10-22 13:58:29 +0900927 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900928 copyCmds := apexRule.Args["copy_commands"]
929
930 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800931 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900932 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
933 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900934
935 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900936 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900937
Colin Cross7113d202019-11-20 16:39:12 -0800938 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
939 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
940 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900941
942 // For dependency to libc
943 // Ensure that mylib is linking with the latest version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +0900944 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900945 // ... and not linking to the non-stub (impl) variant
Jiyong Park3ff16992019-12-27 14:11:47 +0900946 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900947 // ... Cflags from stub is correctly exported to mylib
948 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
949 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
950
951 // For dependency to libm
952 // Ensure that mylib is linking with the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -0800953 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900954 // ... and not linking to the stub variant
Jiyong Park3ff16992019-12-27 14:11:47 +0900955 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900956 // ... and is not compiling with the stub
957 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
958 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
959
960 // For dependency to libdl
961 // Ensure that mylib is linking with the specified version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +0900962 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900963 // ... and not linking to the other versions of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +0900964 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so")
965 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900966 // ... and not linking to the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -0800967 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900968 // ... Cflags from stub is correctly exported to mylib
969 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
970 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900971
972 // Ensure that libBootstrap is depending on the platform variant of bionic libs
Colin Cross7113d202019-11-20 16:39:12 -0800973 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"]
974 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so")
975 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so")
976 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900977}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900978
Jooyung Han0c4e0162020-02-26 22:45:42 +0900979func TestApexUseStubsAccordingToMinSdkVersionInUnbundledBuild(t *testing.T) {
980 // there are three links between liba --> libz
981 // 1) myapex -> libx -> liba -> libz : this should be #2 link, but fallback to #1
982 // 2) otherapex -> liby -> liba -> libz : this should be #3 link
983 // 3) (platform) -> liba -> libz : this should be non-stub link
984 ctx, _ := testApex(t, `
985 apex {
986 name: "myapex",
987 key: "myapex.key",
988 native_shared_libs: ["libx"],
989 min_sdk_version: "2",
990 }
991
992 apex {
993 name: "otherapex",
994 key: "myapex.key",
995 native_shared_libs: ["liby"],
996 min_sdk_version: "3",
997 }
998
999 apex_key {
1000 name: "myapex.key",
1001 public_key: "testkey.avbpubkey",
1002 private_key: "testkey.pem",
1003 }
1004
1005 cc_library {
1006 name: "libx",
1007 shared_libs: ["liba"],
1008 system_shared_libs: [],
1009 stl: "none",
1010 apex_available: [ "myapex" ],
1011 }
1012
1013 cc_library {
1014 name: "liby",
1015 shared_libs: ["liba"],
1016 system_shared_libs: [],
1017 stl: "none",
1018 apex_available: [ "otherapex" ],
1019 }
1020
1021 cc_library {
1022 name: "liba",
1023 shared_libs: ["libz"],
1024 system_shared_libs: [],
1025 stl: "none",
1026 apex_available: [
1027 "//apex_available:anyapex",
1028 "//apex_available:platform",
1029 ],
1030 }
1031
1032 cc_library {
1033 name: "libz",
1034 system_shared_libs: [],
1035 stl: "none",
1036 stubs: {
1037 versions: ["1", "3"],
1038 },
1039 }
1040 `, withUnbundledBuild)
1041
1042 expectLink := func(from, from_variant, to, to_variant string) {
1043 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1044 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1045 }
1046 expectNoLink := func(from, from_variant, to, to_variant string) {
1047 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1048 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1049 }
1050 // platform liba is linked to non-stub version
1051 expectLink("liba", "shared", "libz", "shared")
1052 // liba in myapex is linked to #1
1053 expectLink("liba", "shared_myapex", "libz", "shared_1")
1054 expectNoLink("liba", "shared_myapex", "libz", "shared_3")
1055 expectNoLink("liba", "shared_myapex", "libz", "shared")
1056 // liba in otherapex is linked to #3
1057 expectLink("liba", "shared_otherapex", "libz", "shared_3")
1058 expectNoLink("liba", "shared_otherapex", "libz", "shared_1")
1059 expectNoLink("liba", "shared_otherapex", "libz", "shared")
1060}
1061
1062func TestApexMinSdkVersionDefaultsToLatest(t *testing.T) {
1063 ctx, _ := testApex(t, `
1064 apex {
1065 name: "myapex",
1066 key: "myapex.key",
1067 native_shared_libs: ["libx"],
1068 }
1069
1070 apex_key {
1071 name: "myapex.key",
1072 public_key: "testkey.avbpubkey",
1073 private_key: "testkey.pem",
1074 }
1075
1076 cc_library {
1077 name: "libx",
1078 shared_libs: ["libz"],
1079 system_shared_libs: [],
1080 stl: "none",
1081 apex_available: [ "myapex" ],
1082 }
1083
1084 cc_library {
1085 name: "libz",
1086 system_shared_libs: [],
1087 stl: "none",
1088 stubs: {
1089 versions: ["1", "2"],
1090 },
1091 }
1092 `)
1093
1094 expectLink := func(from, from_variant, to, to_variant string) {
1095 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1096 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1097 }
1098 expectNoLink := func(from, from_variant, to, to_variant string) {
1099 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1100 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1101 }
1102 expectLink("libx", "shared_myapex", "libz", "shared_2")
1103 expectNoLink("libx", "shared_myapex", "libz", "shared_1")
1104 expectNoLink("libx", "shared_myapex", "libz", "shared")
1105}
1106
1107func TestPlatformUsesLatestStubsFromApexes(t *testing.T) {
1108 ctx, _ := testApex(t, `
1109 apex {
1110 name: "myapex",
1111 key: "myapex.key",
1112 native_shared_libs: ["libx"],
1113 }
1114
1115 apex_key {
1116 name: "myapex.key",
1117 public_key: "testkey.avbpubkey",
1118 private_key: "testkey.pem",
1119 }
1120
1121 cc_library {
1122 name: "libx",
1123 system_shared_libs: [],
1124 stl: "none",
1125 apex_available: [ "myapex" ],
1126 stubs: {
1127 versions: ["1", "2"],
1128 },
1129 }
1130
1131 cc_library {
1132 name: "libz",
1133 shared_libs: ["libx"],
1134 system_shared_libs: [],
1135 stl: "none",
1136 }
1137 `)
1138
1139 expectLink := func(from, from_variant, to, to_variant string) {
1140 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1141 ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1142 }
1143 expectNoLink := func(from, from_variant, to, to_variant string) {
1144 ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
1145 ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1146 }
1147 expectLink("libz", "shared", "libx", "shared_2")
1148 expectNoLink("libz", "shared", "libz", "shared_1")
1149 expectNoLink("libz", "shared", "libz", "shared")
1150}
1151
1152func TestQApexesUseLatestStubsInBundledBuilds(t *testing.T) {
1153 ctx, _ := testApex(t, `
1154 apex {
1155 name: "myapex",
1156 key: "myapex.key",
1157 native_shared_libs: ["libx"],
1158 min_sdk_version: "29",
1159 }
1160
1161 apex_key {
1162 name: "myapex.key",
1163 public_key: "testkey.avbpubkey",
1164 private_key: "testkey.pem",
1165 }
1166
1167 cc_library {
1168 name: "libx",
1169 shared_libs: ["libbar"],
1170 apex_available: [ "myapex" ],
1171 }
1172
1173 cc_library {
1174 name: "libbar",
1175 stubs: {
1176 versions: ["29", "30"],
1177 },
1178 }
1179 `)
1180 expectLink := func(from, from_variant, to, to_variant string) {
1181 ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld")
1182 libFlags := ld.Args["libFlags"]
1183 ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
1184 }
1185 expectLink("libx", "shared_myapex", "libbar", "shared_30")
1186}
1187
1188func TestQTargetApexUseStaticUnwinder(t *testing.T) {
1189 ctx, _ := testApex(t, `
1190 apex {
1191 name: "myapex",
1192 key: "myapex.key",
1193 native_shared_libs: ["libx"],
1194 min_sdk_version: "29",
1195 }
1196
1197 apex_key {
1198 name: "myapex.key",
1199 public_key: "testkey.avbpubkey",
1200 private_key: "testkey.pem",
1201 }
1202
1203 cc_library {
1204 name: "libx",
1205 apex_available: [ "myapex" ],
1206 }
1207
1208 `, withUnbundledBuild)
1209
1210 // ensure apex variant of c++ is linked with static unwinder
1211 cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module)
1212 ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
1213 // note that platform variant is not.
1214 cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module)
1215 ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
1216
1217 libFlags := ctx.ModuleForTests("libx", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
1218 ensureContains(t, libFlags, "android_arm64_armv8-a_shared_myapex/libc++.so")
1219 ensureContains(t, libFlags, "android_arm64_armv8-a_shared_29/libc.so") // min_sdk_version applied
1220}
1221
1222func TestInvalidMinSdkVersion(t *testing.T) {
1223 testApexError(t, `"libz" .*: min_sdk_version is set 29.*`, `
1224 apex {
1225 name: "myapex",
1226 key: "myapex.key",
1227 native_shared_libs: ["libx"],
1228 min_sdk_version: "29",
1229 }
1230
1231 apex_key {
1232 name: "myapex.key",
1233 public_key: "testkey.avbpubkey",
1234 private_key: "testkey.pem",
1235 }
1236
1237 cc_library {
1238 name: "libx",
1239 shared_libs: ["libz"],
1240 system_shared_libs: [],
1241 stl: "none",
1242 apex_available: [ "myapex" ],
1243 }
1244
1245 cc_library {
1246 name: "libz",
1247 system_shared_libs: [],
1248 stl: "none",
1249 stubs: {
1250 versions: ["30"],
1251 },
1252 }
1253 `, withUnbundledBuild)
1254
1255 testApexError(t, `"myapex" .*: min_sdk_version: should be .*`, `
1256 apex {
1257 name: "myapex",
1258 key: "myapex.key",
1259 min_sdk_version: "R",
1260 }
1261
1262 apex_key {
1263 name: "myapex.key",
1264 public_key: "testkey.avbpubkey",
1265 private_key: "testkey.pem",
1266 }
1267 `)
1268}
1269
Jiyong Park7c2ee712018-12-07 00:42:25 +09001270func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001271 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +09001272 apex {
1273 name: "myapex",
1274 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001275 native_shared_libs: ["mylib"],
1276 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +09001277 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001278 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +09001279 }
1280
1281 apex_key {
1282 name: "myapex.key",
1283 public_key: "testkey.avbpubkey",
1284 private_key: "testkey.pem",
1285 }
1286
1287 prebuilt_etc {
1288 name: "myetc",
1289 src: "myprebuilt",
1290 sub_dir: "foo/bar",
1291 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001292
1293 cc_library {
1294 name: "mylib",
1295 srcs: ["mylib.cpp"],
1296 relative_install_path: "foo/bar",
1297 system_shared_libs: [],
1298 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001299 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001300 }
1301
1302 cc_binary {
1303 name: "mybin",
1304 srcs: ["mylib.cpp"],
1305 relative_install_path: "foo/bar",
1306 system_shared_libs: [],
1307 static_executable: true,
1308 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001309 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001310 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001311 `)
1312
Sundong Ahnabb64432019-10-22 13:58:29 +09001313 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001314 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1315
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001316 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001317 ensureListContains(t, dirs, "etc")
1318 ensureListContains(t, dirs, "etc/foo")
1319 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001320 ensureListContains(t, dirs, "lib64")
1321 ensureListContains(t, dirs, "lib64/foo")
1322 ensureListContains(t, dirs, "lib64/foo/bar")
1323 ensureListContains(t, dirs, "lib")
1324 ensureListContains(t, dirs, "lib/foo")
1325 ensureListContains(t, dirs, "lib/foo/bar")
1326
Jiyong Parkbd13e442019-03-15 18:10:35 +09001327 ensureListContains(t, dirs, "bin")
1328 ensureListContains(t, dirs, "bin/foo")
1329 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001330}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001331
1332func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001333 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001334 apex {
1335 name: "myapex",
1336 key: "myapex.key",
1337 native_shared_libs: ["mylib"],
1338 use_vendor: true,
1339 }
1340
1341 apex_key {
1342 name: "myapex.key",
1343 public_key: "testkey.avbpubkey",
1344 private_key: "testkey.pem",
1345 }
1346
1347 cc_library {
1348 name: "mylib",
1349 srcs: ["mylib.cpp"],
1350 shared_libs: ["mylib2"],
1351 system_shared_libs: [],
1352 vendor_available: true,
1353 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001354 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001355 }
1356
1357 cc_library {
1358 name: "mylib2",
1359 srcs: ["mylib.cpp"],
1360 system_shared_libs: [],
1361 vendor_available: true,
1362 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001363 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001364 }
Jooyung Handc782442019-11-01 03:14:38 +09001365 `, func(fs map[string][]byte, config android.Config) {
1366 setUseVendorWhitelistForTest(config, []string{"myapex"})
1367 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001368
1369 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001370 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001371 for _, implicit := range i.Implicits {
1372 inputsList = append(inputsList, implicit.String())
1373 }
1374 }
1375 inputsString := strings.Join(inputsList, " ")
1376
1377 // ensure that the apex includes vendor variants of the direct and indirect deps
Colin Crossfb0c16e2019-11-20 17:12:35 -08001378 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so")
1379 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001380
1381 // ensure that the apex does not include core variants
Colin Cross7113d202019-11-20 16:39:12 -08001382 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so")
1383 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001384}
Jiyong Park16e91a02018-12-20 18:18:08 +09001385
Jooyung Handc782442019-11-01 03:14:38 +09001386func TestUseVendorRestriction(t *testing.T) {
1387 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1388 apex {
1389 name: "myapex",
1390 key: "myapex.key",
1391 use_vendor: true,
1392 }
1393 apex_key {
1394 name: "myapex.key",
1395 public_key: "testkey.avbpubkey",
1396 private_key: "testkey.pem",
1397 }
1398 `, func(fs map[string][]byte, config android.Config) {
1399 setUseVendorWhitelistForTest(config, []string{""})
1400 })
1401 // no error with whitelist
1402 testApex(t, `
1403 apex {
1404 name: "myapex",
1405 key: "myapex.key",
1406 use_vendor: true,
1407 }
1408 apex_key {
1409 name: "myapex.key",
1410 public_key: "testkey.avbpubkey",
1411 private_key: "testkey.pem",
1412 }
1413 `, func(fs map[string][]byte, config android.Config) {
1414 setUseVendorWhitelistForTest(config, []string{"myapex"})
1415 })
1416}
1417
Jooyung Han5c998b92019-06-27 11:30:33 +09001418func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1419 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1420 apex {
1421 name: "myapex",
1422 key: "myapex.key",
1423 native_shared_libs: ["mylib"],
1424 use_vendor: true,
1425 }
1426
1427 apex_key {
1428 name: "myapex.key",
1429 public_key: "testkey.avbpubkey",
1430 private_key: "testkey.pem",
1431 }
1432
1433 cc_library {
1434 name: "mylib",
1435 srcs: ["mylib.cpp"],
1436 system_shared_libs: [],
1437 stl: "none",
1438 }
1439 `)
1440}
1441
Jiyong Park16e91a02018-12-20 18:18:08 +09001442func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001443 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001444 apex {
1445 name: "myapex",
1446 key: "myapex.key",
1447 native_shared_libs: ["mylib"],
1448 }
1449
1450 apex_key {
1451 name: "myapex.key",
1452 public_key: "testkey.avbpubkey",
1453 private_key: "testkey.pem",
1454 }
1455
1456 cc_library {
1457 name: "mylib",
1458 srcs: ["mylib.cpp"],
1459 system_shared_libs: [],
1460 stl: "none",
1461 stubs: {
1462 versions: ["1", "2", "3"],
1463 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001464 apex_available: [
1465 "//apex_available:platform",
1466 "myapex",
1467 ],
Jiyong Park16e91a02018-12-20 18:18:08 +09001468 }
1469
1470 cc_binary {
1471 name: "not_in_apex",
1472 srcs: ["mylib.cpp"],
1473 static_libs: ["mylib"],
1474 static_executable: true,
1475 system_shared_libs: [],
1476 stl: "none",
1477 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001478 `)
1479
Colin Cross7113d202019-11-20 16:39:12 -08001480 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
Jiyong Park16e91a02018-12-20 18:18:08 +09001481
1482 // Ensure that not_in_apex is linking with the static variant of mylib
Colin Cross7113d202019-11-20 16:39:12 -08001483 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001484}
Jiyong Park9335a262018-12-24 11:31:58 +09001485
1486func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001487 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001488 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001489 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001490 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001491 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001492 native_shared_libs: ["mylib"],
Jooyung Han54aca7b2019-11-20 02:26:02 +09001493 file_contexts: ":myapex-file_contexts",
Jiyong Park9335a262018-12-24 11:31:58 +09001494 }
1495
1496 cc_library {
1497 name: "mylib",
1498 srcs: ["mylib.cpp"],
1499 system_shared_libs: [],
1500 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001501 apex_available: [ "myapex_keytest" ],
Jiyong Park9335a262018-12-24 11:31:58 +09001502 }
1503
1504 apex_key {
1505 name: "myapex.key",
1506 public_key: "testkey.avbpubkey",
1507 private_key: "testkey.pem",
1508 }
1509
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001510 android_app_certificate {
1511 name: "myapex.certificate",
1512 certificate: "testkey",
1513 }
1514
1515 android_app_certificate {
1516 name: "myapex.certificate.override",
1517 certificate: "testkey.override",
1518 }
1519
Jiyong Park9335a262018-12-24 11:31:58 +09001520 `)
1521
1522 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001523 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001524
1525 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1526 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1527 "vendor/foo/devkeys/testkey.avbpubkey")
1528 }
1529 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1530 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1531 "vendor/foo/devkeys/testkey.pem")
1532 }
1533
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001534 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001535 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001536 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001537 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001538 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001539 }
1540}
Jiyong Park58e364a2019-01-19 19:24:06 +09001541
Jooyung Hanf121a652019-12-17 14:30:11 +09001542func TestCertificate(t *testing.T) {
1543 t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) {
1544 ctx, _ := testApex(t, `
1545 apex {
1546 name: "myapex",
1547 key: "myapex.key",
1548 }
1549 apex_key {
1550 name: "myapex.key",
1551 public_key: "testkey.avbpubkey",
1552 private_key: "testkey.pem",
1553 }`)
1554 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1555 expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8"
1556 if actual := rule.Args["certificates"]; actual != expected {
1557 t.Errorf("certificates should be %q, not %q", expected, actual)
1558 }
1559 })
1560 t.Run("override when unspecified", func(t *testing.T) {
1561 ctx, _ := testApex(t, `
1562 apex {
1563 name: "myapex_keytest",
1564 key: "myapex.key",
1565 file_contexts: ":myapex-file_contexts",
1566 }
1567 apex_key {
1568 name: "myapex.key",
1569 public_key: "testkey.avbpubkey",
1570 private_key: "testkey.pem",
1571 }
1572 android_app_certificate {
1573 name: "myapex.certificate.override",
1574 certificate: "testkey.override",
1575 }`)
1576 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1577 expected := "testkey.override.x509.pem testkey.override.pk8"
1578 if actual := rule.Args["certificates"]; actual != expected {
1579 t.Errorf("certificates should be %q, not %q", expected, actual)
1580 }
1581 })
1582 t.Run("if specified as :module, it respects the prop", func(t *testing.T) {
1583 ctx, _ := testApex(t, `
1584 apex {
1585 name: "myapex",
1586 key: "myapex.key",
1587 certificate: ":myapex.certificate",
1588 }
1589 apex_key {
1590 name: "myapex.key",
1591 public_key: "testkey.avbpubkey",
1592 private_key: "testkey.pem",
1593 }
1594 android_app_certificate {
1595 name: "myapex.certificate",
1596 certificate: "testkey",
1597 }`)
1598 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1599 expected := "testkey.x509.pem testkey.pk8"
1600 if actual := rule.Args["certificates"]; actual != expected {
1601 t.Errorf("certificates should be %q, not %q", expected, actual)
1602 }
1603 })
1604 t.Run("override when specifiec as <:module>", func(t *testing.T) {
1605 ctx, _ := testApex(t, `
1606 apex {
1607 name: "myapex_keytest",
1608 key: "myapex.key",
1609 file_contexts: ":myapex-file_contexts",
1610 certificate: ":myapex.certificate",
1611 }
1612 apex_key {
1613 name: "myapex.key",
1614 public_key: "testkey.avbpubkey",
1615 private_key: "testkey.pem",
1616 }
1617 android_app_certificate {
1618 name: "myapex.certificate.override",
1619 certificate: "testkey.override",
1620 }`)
1621 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1622 expected := "testkey.override.x509.pem testkey.override.pk8"
1623 if actual := rule.Args["certificates"]; actual != expected {
1624 t.Errorf("certificates should be %q, not %q", expected, actual)
1625 }
1626 })
1627 t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) {
1628 ctx, _ := testApex(t, `
1629 apex {
1630 name: "myapex",
1631 key: "myapex.key",
1632 certificate: "testkey",
1633 }
1634 apex_key {
1635 name: "myapex.key",
1636 public_key: "testkey.avbpubkey",
1637 private_key: "testkey.pem",
1638 }`)
1639 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1640 expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8"
1641 if actual := rule.Args["certificates"]; actual != expected {
1642 t.Errorf("certificates should be %q, not %q", expected, actual)
1643 }
1644 })
1645 t.Run("override when specified as <name>", func(t *testing.T) {
1646 ctx, _ := testApex(t, `
1647 apex {
1648 name: "myapex_keytest",
1649 key: "myapex.key",
1650 file_contexts: ":myapex-file_contexts",
1651 certificate: "testkey",
1652 }
1653 apex_key {
1654 name: "myapex.key",
1655 public_key: "testkey.avbpubkey",
1656 private_key: "testkey.pem",
1657 }
1658 android_app_certificate {
1659 name: "myapex.certificate.override",
1660 certificate: "testkey.override",
1661 }`)
1662 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1663 expected := "testkey.override.x509.pem testkey.override.pk8"
1664 if actual := rule.Args["certificates"]; actual != expected {
1665 t.Errorf("certificates should be %q, not %q", expected, actual)
1666 }
1667 })
1668}
1669
Jiyong Park58e364a2019-01-19 19:24:06 +09001670func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001671 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001672 apex {
1673 name: "myapex",
1674 key: "myapex.key",
Jooyung Han68e511e2020-03-02 17:44:33 +09001675 native_shared_libs: ["mylib", "mylib2"],
Jiyong Park58e364a2019-01-19 19:24:06 +09001676 }
1677
1678 apex {
1679 name: "otherapex",
1680 key: "myapex.key",
Jooyung Han68e511e2020-03-02 17:44:33 +09001681 native_shared_libs: ["mylib", "mylib2"],
Jooyung Han61c41542020-03-07 03:45:53 +09001682 min_sdk_version: "29",
Jiyong Park58e364a2019-01-19 19:24:06 +09001683 }
1684
1685 apex_key {
1686 name: "myapex.key",
1687 public_key: "testkey.avbpubkey",
1688 private_key: "testkey.pem",
1689 }
1690
1691 cc_library {
1692 name: "mylib",
1693 srcs: ["mylib.cpp"],
1694 system_shared_libs: [],
1695 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001696 apex_available: [
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001697 "myapex",
1698 "otherapex",
1699 ],
Jiyong Park58e364a2019-01-19 19:24:06 +09001700 }
Jooyung Han68e511e2020-03-02 17:44:33 +09001701 cc_library {
1702 name: "mylib2",
1703 srcs: ["mylib.cpp"],
1704 system_shared_libs: [],
1705 stl: "none",
1706 apex_available: [
1707 "myapex",
1708 "otherapex",
1709 ],
1710 use_apex_name_macro: true,
1711 }
Jiyong Park58e364a2019-01-19 19:24:06 +09001712 `)
1713
Jooyung Han68e511e2020-03-02 17:44:33 +09001714 // non-APEX variant does not have __ANDROID_APEX__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001715 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001716 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han61c41542020-03-07 03:45:53 +09001717 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
Jooyung Han68e511e2020-03-02 17:44:33 +09001718
Jooyung Han61c41542020-03-07 03:45:53 +09001719 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Jooyung Han68e511e2020-03-02 17:44:33 +09001720 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
1721 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han61c41542020-03-07 03:45:53 +09001722 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
Jooyung Han77988572019-10-18 16:26:16 +09001723 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
Jooyung Han68e511e2020-03-02 17:44:33 +09001724
Jooyung Han61c41542020-03-07 03:45:53 +09001725 // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
Jooyung Han68e511e2020-03-02 17:44:33 +09001726 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
1727 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han61c41542020-03-07 03:45:53 +09001728 ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29")
Jooyung Han77988572019-10-18 16:26:16 +09001729 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001730
Jooyung Han68e511e2020-03-02 17:44:33 +09001731 // When cc_library sets use_apex_name_macro: true
1732 // apex variants define additional macro to distinguish which apex variant it is built for
1733
1734 // non-APEX variant does not have __ANDROID_APEX__ defined
1735 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
1736 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
1737
1738 // APEX variant has __ANDROID_APEX__ defined
1739 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001740 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001741 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1742 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001743
Jooyung Han68e511e2020-03-02 17:44:33 +09001744 // APEX variant has __ANDROID_APEX__ defined
1745 mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001746 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001747 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1748 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001749}
Jiyong Park7e636d02019-01-28 16:16:54 +09001750
1751func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001752 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001753 apex {
1754 name: "myapex",
1755 key: "myapex.key",
1756 native_shared_libs: ["mylib"],
1757 }
1758
1759 apex_key {
1760 name: "myapex.key",
1761 public_key: "testkey.avbpubkey",
1762 private_key: "testkey.pem",
1763 }
1764
1765 cc_library_headers {
1766 name: "mylib_headers",
1767 export_include_dirs: ["my_include"],
1768 system_shared_libs: [],
1769 stl: "none",
Jiyong Park0f80c182020-01-31 02:49:53 +09001770 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001771 }
1772
1773 cc_library {
1774 name: "mylib",
1775 srcs: ["mylib.cpp"],
1776 system_shared_libs: [],
1777 stl: "none",
1778 header_libs: ["mylib_headers"],
1779 export_header_lib_headers: ["mylib_headers"],
1780 stubs: {
1781 versions: ["1", "2", "3"],
1782 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001783 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001784 }
1785
1786 cc_library {
1787 name: "otherlib",
1788 srcs: ["mylib.cpp"],
1789 system_shared_libs: [],
1790 stl: "none",
1791 shared_libs: ["mylib"],
1792 }
1793 `)
1794
Colin Cross7113d202019-11-20 16:39:12 -08001795 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park7e636d02019-01-28 16:16:54 +09001796
1797 // Ensure that the include path of the header lib is exported to 'otherlib'
1798 ensureContains(t, cFlags, "-Imy_include")
1799}
Alex Light9670d332019-01-29 18:07:33 -08001800
Jiyong Park7cd10e32020-01-14 09:22:18 +09001801type fileInApex struct {
1802 path string // path in apex
Jooyung Hana57af4a2020-01-23 05:36:59 +00001803 src string // src path
Jiyong Park7cd10e32020-01-14 09:22:18 +09001804 isLink bool
1805}
1806
Jooyung Hana57af4a2020-01-23 05:36:59 +00001807func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex {
Jooyung Han31c470b2019-10-18 16:26:59 +09001808 t.Helper()
Jooyung Hana57af4a2020-01-23 05:36:59 +00001809 apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001810 copyCmds := apexRule.Args["copy_commands"]
1811 imageApexDir := "/image.apex/"
Jiyong Park7cd10e32020-01-14 09:22:18 +09001812 var ret []fileInApex
Jooyung Han31c470b2019-10-18 16:26:59 +09001813 for _, cmd := range strings.Split(copyCmds, "&&") {
1814 cmd = strings.TrimSpace(cmd)
1815 if cmd == "" {
1816 continue
1817 }
1818 terms := strings.Split(cmd, " ")
Jooyung Hana57af4a2020-01-23 05:36:59 +00001819 var dst, src string
Jiyong Park7cd10e32020-01-14 09:22:18 +09001820 var isLink bool
Jooyung Han31c470b2019-10-18 16:26:59 +09001821 switch terms[0] {
1822 case "mkdir":
1823 case "cp":
Jiyong Park7cd10e32020-01-14 09:22:18 +09001824 if len(terms) != 3 && len(terms) != 4 {
Jooyung Han31c470b2019-10-18 16:26:59 +09001825 t.Fatal("copyCmds contains invalid cp command", cmd)
1826 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001827 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001828 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001829 isLink = false
1830 case "ln":
1831 if len(terms) != 3 && len(terms) != 4 {
1832 // ln LINK TARGET or ln -s LINK TARGET
1833 t.Fatal("copyCmds contains invalid ln command", cmd)
1834 }
1835 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001836 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001837 isLink = true
1838 default:
1839 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1840 }
1841 if dst != "" {
Jooyung Han31c470b2019-10-18 16:26:59 +09001842 index := strings.Index(dst, imageApexDir)
1843 if index == -1 {
1844 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1845 }
1846 dstFile := dst[index+len(imageApexDir):]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001847 ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink})
Jooyung Han31c470b2019-10-18 16:26:59 +09001848 }
1849 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001850 return ret
1851}
1852
Jooyung Hana57af4a2020-01-23 05:36:59 +00001853func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) {
1854 t.Helper()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001855 var failed bool
1856 var surplus []string
1857 filesMatched := make(map[string]bool)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001858 for _, file := range getFiles(t, ctx, moduleName, variant) {
Jooyung Han8d8906c2020-02-27 13:31:56 +09001859 mactchFound := false
Jiyong Park7cd10e32020-01-14 09:22:18 +09001860 for _, expected := range files {
1861 if matched, _ := path.Match(expected, file.path); matched {
1862 filesMatched[expected] = true
Jooyung Han8d8906c2020-02-27 13:31:56 +09001863 mactchFound = true
1864 break
Jiyong Park7cd10e32020-01-14 09:22:18 +09001865 }
1866 }
Jooyung Han8d8906c2020-02-27 13:31:56 +09001867 if !mactchFound {
1868 surplus = append(surplus, file.path)
1869 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001870 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001871
Jooyung Han31c470b2019-10-18 16:26:59 +09001872 if len(surplus) > 0 {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001873 sort.Strings(surplus)
Jooyung Han31c470b2019-10-18 16:26:59 +09001874 t.Log("surplus files", surplus)
1875 failed = true
1876 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001877
1878 if len(files) > len(filesMatched) {
1879 var missing []string
1880 for _, expected := range files {
1881 if !filesMatched[expected] {
1882 missing = append(missing, expected)
1883 }
1884 }
1885 sort.Strings(missing)
Jooyung Han31c470b2019-10-18 16:26:59 +09001886 t.Log("missing files", missing)
1887 failed = true
1888 }
1889 if failed {
1890 t.Fail()
1891 }
1892}
1893
Jooyung Han344d5432019-08-23 11:17:39 +09001894func TestVndkApexCurrent(t *testing.T) {
1895 ctx, _ := testApex(t, `
1896 apex_vndk {
1897 name: "myapex",
1898 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001899 }
1900
1901 apex_key {
1902 name: "myapex.key",
1903 public_key: "testkey.avbpubkey",
1904 private_key: "testkey.pem",
1905 }
1906
1907 cc_library {
1908 name: "libvndk",
1909 srcs: ["mylib.cpp"],
1910 vendor_available: true,
1911 vndk: {
1912 enabled: true,
1913 },
1914 system_shared_libs: [],
1915 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001916 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001917 }
1918
1919 cc_library {
1920 name: "libvndksp",
1921 srcs: ["mylib.cpp"],
1922 vendor_available: true,
1923 vndk: {
1924 enabled: true,
1925 support_system_process: true,
1926 },
1927 system_shared_libs: [],
1928 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001929 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001930 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001931 `+vndkLibrariesTxtFiles("current"))
Jooyung Han344d5432019-08-23 11:17:39 +09001932
Jooyung Hana57af4a2020-01-23 05:36:59 +00001933 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001934 "lib/libvndk.so",
1935 "lib/libvndksp.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09001936 "lib/libc++.so",
Jooyung Han31c470b2019-10-18 16:26:59 +09001937 "lib64/libvndk.so",
1938 "lib64/libvndksp.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09001939 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001940 "etc/llndk.libraries.VER.txt",
1941 "etc/vndkcore.libraries.VER.txt",
1942 "etc/vndksp.libraries.VER.txt",
1943 "etc/vndkprivate.libraries.VER.txt",
Jooyung Han31c470b2019-10-18 16:26:59 +09001944 })
Jooyung Han344d5432019-08-23 11:17:39 +09001945}
1946
1947func TestVndkApexWithPrebuilt(t *testing.T) {
1948 ctx, _ := testApex(t, `
1949 apex_vndk {
1950 name: "myapex",
1951 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001952 }
1953
1954 apex_key {
1955 name: "myapex.key",
1956 public_key: "testkey.avbpubkey",
1957 private_key: "testkey.pem",
1958 }
1959
1960 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001961 name: "libvndk",
1962 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001963 vendor_available: true,
1964 vndk: {
1965 enabled: true,
1966 },
1967 system_shared_libs: [],
1968 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001969 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001970 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001971
1972 cc_prebuilt_library_shared {
1973 name: "libvndk.arm",
1974 srcs: ["libvndk.arm.so"],
1975 vendor_available: true,
1976 vndk: {
1977 enabled: true,
1978 },
1979 enabled: false,
1980 arch: {
1981 arm: {
1982 enabled: true,
1983 },
1984 },
1985 system_shared_libs: [],
1986 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001987 apex_available: [ "myapex" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09001988 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001989 `+vndkLibrariesTxtFiles("current"),
1990 withFiles(map[string][]byte{
1991 "libvndk.so": nil,
1992 "libvndk.arm.so": nil,
1993 }))
Jooyung Han344d5432019-08-23 11:17:39 +09001994
Jooyung Hana57af4a2020-01-23 05:36:59 +00001995 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001996 "lib/libvndk.so",
1997 "lib/libvndk.arm.so",
1998 "lib64/libvndk.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09001999 "lib/libc++.so",
2000 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002001 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002002 })
Jooyung Han344d5432019-08-23 11:17:39 +09002003}
2004
Jooyung Han39edb6c2019-11-06 16:53:07 +09002005func vndkLibrariesTxtFiles(vers ...string) (result string) {
2006 for _, v := range vers {
2007 if v == "current" {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +09002008 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002009 result += `
2010 vndk_libraries_txt {
2011 name: "` + txt + `.libraries.txt",
2012 }
2013 `
2014 }
2015 } else {
2016 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
2017 result += `
2018 prebuilt_etc {
2019 name: "` + txt + `.libraries.` + v + `.txt",
2020 src: "dummy.txt",
2021 }
2022 `
2023 }
2024 }
2025 }
2026 return
2027}
2028
Jooyung Han344d5432019-08-23 11:17:39 +09002029func TestVndkApexVersion(t *testing.T) {
2030 ctx, _ := testApex(t, `
2031 apex_vndk {
2032 name: "myapex_v27",
2033 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002034 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002035 vndk_version: "27",
2036 }
2037
2038 apex_key {
2039 name: "myapex.key",
2040 public_key: "testkey.avbpubkey",
2041 private_key: "testkey.pem",
2042 }
2043
Jooyung Han31c470b2019-10-18 16:26:59 +09002044 vndk_prebuilt_shared {
2045 name: "libvndk27",
2046 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09002047 vendor_available: true,
2048 vndk: {
2049 enabled: true,
2050 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002051 target_arch: "arm64",
2052 arch: {
2053 arm: {
2054 srcs: ["libvndk27_arm.so"],
2055 },
2056 arm64: {
2057 srcs: ["libvndk27_arm64.so"],
2058 },
2059 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002060 apex_available: [ "myapex_v27" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002061 }
2062
2063 vndk_prebuilt_shared {
2064 name: "libvndk27",
2065 version: "27",
2066 vendor_available: true,
2067 vndk: {
2068 enabled: true,
2069 },
Jooyung Han31c470b2019-10-18 16:26:59 +09002070 target_arch: "x86_64",
2071 arch: {
2072 x86: {
2073 srcs: ["libvndk27_x86.so"],
2074 },
2075 x86_64: {
2076 srcs: ["libvndk27_x86_64.so"],
2077 },
2078 },
Jooyung Han39edb6c2019-11-06 16:53:07 +09002079 }
2080 `+vndkLibrariesTxtFiles("27"),
2081 withFiles(map[string][]byte{
2082 "libvndk27_arm.so": nil,
2083 "libvndk27_arm64.so": nil,
2084 "libvndk27_x86.so": nil,
2085 "libvndk27_x86_64.so": nil,
2086 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002087
Jooyung Hana57af4a2020-01-23 05:36:59 +00002088 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002089 "lib/libvndk27_arm.so",
2090 "lib64/libvndk27_arm64.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002091 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002092 })
Jooyung Han344d5432019-08-23 11:17:39 +09002093}
2094
2095func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
2096 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
2097 apex_vndk {
2098 name: "myapex_v27",
2099 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002100 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002101 vndk_version: "27",
2102 }
2103 apex_vndk {
2104 name: "myapex_v27_other",
2105 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002106 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002107 vndk_version: "27",
2108 }
2109
2110 apex_key {
2111 name: "myapex.key",
2112 public_key: "testkey.avbpubkey",
2113 private_key: "testkey.pem",
2114 }
2115
2116 cc_library {
2117 name: "libvndk",
2118 srcs: ["mylib.cpp"],
2119 vendor_available: true,
2120 vndk: {
2121 enabled: true,
2122 },
2123 system_shared_libs: [],
2124 stl: "none",
2125 }
2126
2127 vndk_prebuilt_shared {
2128 name: "libvndk",
2129 version: "27",
2130 vendor_available: true,
2131 vndk: {
2132 enabled: true,
2133 },
2134 srcs: ["libvndk.so"],
2135 }
2136 `, withFiles(map[string][]byte{
2137 "libvndk.so": nil,
2138 }))
2139}
2140
Jooyung Han90eee022019-10-01 20:02:42 +09002141func TestVndkApexNameRule(t *testing.T) {
2142 ctx, _ := testApex(t, `
2143 apex_vndk {
2144 name: "myapex",
2145 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002146 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002147 }
2148 apex_vndk {
2149 name: "myapex_v28",
2150 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002151 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09002152 vndk_version: "28",
2153 }
2154 apex_key {
2155 name: "myapex.key",
2156 public_key: "testkey.avbpubkey",
2157 private_key: "testkey.pem",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002158 }`+vndkLibrariesTxtFiles("28", "current"))
Jooyung Han90eee022019-10-01 20:02:42 +09002159
2160 assertApexName := func(expected, moduleName string) {
Jooyung Hana57af4a2020-01-23 05:36:59 +00002161 bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09002162 actual := proptools.String(bundle.properties.Apex_name)
2163 if !reflect.DeepEqual(actual, expected) {
2164 t.Errorf("Got '%v', expected '%v'", actual, expected)
2165 }
2166 }
2167
2168 assertApexName("com.android.vndk.vVER", "myapex")
2169 assertApexName("com.android.vndk.v28", "myapex_v28")
2170}
2171
Jooyung Han344d5432019-08-23 11:17:39 +09002172func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
2173 ctx, _ := testApex(t, `
2174 apex_vndk {
2175 name: "myapex",
2176 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002177 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002178 }
2179
2180 apex_key {
2181 name: "myapex.key",
2182 public_key: "testkey.avbpubkey",
2183 private_key: "testkey.pem",
2184 }
2185
2186 cc_library {
2187 name: "libvndk",
2188 srcs: ["mylib.cpp"],
2189 vendor_available: true,
2190 native_bridge_supported: true,
2191 host_supported: true,
2192 vndk: {
2193 enabled: true,
2194 },
2195 system_shared_libs: [],
2196 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002197 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09002198 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002199 `+vndkLibrariesTxtFiles("current"),
2200 withTargets(map[android.OsType][]android.Target{
2201 android.Android: []android.Target{
2202 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2203 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2204 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
2205 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
2206 },
2207 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002208
Jooyung Hana57af4a2020-01-23 05:36:59 +00002209 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002210 "lib/libvndk.so",
2211 "lib64/libvndk.so",
Jooyung Han8d8906c2020-02-27 13:31:56 +09002212 "lib/libc++.so",
2213 "lib64/libc++.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002214 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002215 })
Jooyung Han344d5432019-08-23 11:17:39 +09002216}
2217
2218func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
2219 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
2220 apex_vndk {
2221 name: "myapex",
2222 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002223 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002224 native_bridge_supported: true,
2225 }
2226
2227 apex_key {
2228 name: "myapex.key",
2229 public_key: "testkey.avbpubkey",
2230 private_key: "testkey.pem",
2231 }
2232
2233 cc_library {
2234 name: "libvndk",
2235 srcs: ["mylib.cpp"],
2236 vendor_available: true,
2237 native_bridge_supported: true,
2238 host_supported: true,
2239 vndk: {
2240 enabled: true,
2241 },
2242 system_shared_libs: [],
2243 stl: "none",
2244 }
2245 `)
2246}
2247
Jooyung Han31c470b2019-10-18 16:26:59 +09002248func TestVndkApexWithBinder32(t *testing.T) {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002249 ctx, _ := testApex(t, `
Jooyung Han31c470b2019-10-18 16:26:59 +09002250 apex_vndk {
2251 name: "myapex_v27",
2252 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002253 file_contexts: ":myapex-file_contexts",
Jooyung Han31c470b2019-10-18 16:26:59 +09002254 vndk_version: "27",
2255 }
2256
2257 apex_key {
2258 name: "myapex.key",
2259 public_key: "testkey.avbpubkey",
2260 private_key: "testkey.pem",
2261 }
2262
2263 vndk_prebuilt_shared {
2264 name: "libvndk27",
2265 version: "27",
2266 target_arch: "arm",
2267 vendor_available: true,
2268 vndk: {
2269 enabled: true,
2270 },
2271 arch: {
2272 arm: {
2273 srcs: ["libvndk27.so"],
2274 }
2275 },
2276 }
2277
2278 vndk_prebuilt_shared {
2279 name: "libvndk27",
2280 version: "27",
2281 target_arch: "arm",
2282 binder32bit: true,
2283 vendor_available: true,
2284 vndk: {
2285 enabled: true,
2286 },
2287 arch: {
2288 arm: {
2289 srcs: ["libvndk27binder32.so"],
2290 }
2291 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002292 apex_available: [ "myapex_v27" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002293 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002294 `+vndkLibrariesTxtFiles("27"),
Jooyung Han31c470b2019-10-18 16:26:59 +09002295 withFiles(map[string][]byte{
2296 "libvndk27.so": nil,
2297 "libvndk27binder32.so": nil,
2298 }),
2299 withBinder32bit,
2300 withTargets(map[android.OsType][]android.Target{
2301 android.Android: []android.Target{
2302 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2303 },
2304 }),
2305 )
2306
Jooyung Hana57af4a2020-01-23 05:36:59 +00002307 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002308 "lib/libvndk27binder32.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002309 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002310 })
2311}
2312
Jooyung Hane1633032019-08-01 17:41:43 +09002313func TestDependenciesInApexManifest(t *testing.T) {
2314 ctx, _ := testApex(t, `
2315 apex {
2316 name: "myapex_nodep",
2317 key: "myapex.key",
2318 native_shared_libs: ["lib_nodep"],
2319 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002320 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002321 }
2322
2323 apex {
2324 name: "myapex_dep",
2325 key: "myapex.key",
2326 native_shared_libs: ["lib_dep"],
2327 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002328 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002329 }
2330
2331 apex {
2332 name: "myapex_provider",
2333 key: "myapex.key",
2334 native_shared_libs: ["libfoo"],
2335 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002336 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002337 }
2338
2339 apex {
2340 name: "myapex_selfcontained",
2341 key: "myapex.key",
2342 native_shared_libs: ["lib_dep", "libfoo"],
2343 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002344 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002345 }
2346
2347 apex_key {
2348 name: "myapex.key",
2349 public_key: "testkey.avbpubkey",
2350 private_key: "testkey.pem",
2351 }
2352
2353 cc_library {
2354 name: "lib_nodep",
2355 srcs: ["mylib.cpp"],
2356 system_shared_libs: [],
2357 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002358 apex_available: [ "myapex_nodep" ],
Jooyung Hane1633032019-08-01 17:41:43 +09002359 }
2360
2361 cc_library {
2362 name: "lib_dep",
2363 srcs: ["mylib.cpp"],
2364 shared_libs: ["libfoo"],
2365 system_shared_libs: [],
2366 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002367 apex_available: [
2368 "myapex_dep",
2369 "myapex_provider",
2370 "myapex_selfcontained",
2371 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002372 }
2373
2374 cc_library {
2375 name: "libfoo",
2376 srcs: ["mytest.cpp"],
2377 stubs: {
2378 versions: ["1"],
2379 },
2380 system_shared_libs: [],
2381 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002382 apex_available: [
2383 "myapex_provider",
2384 "myapex_selfcontained",
2385 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002386 }
2387 `)
2388
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002389 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09002390 var provideNativeLibs, requireNativeLibs []string
2391
Sundong Ahnabb64432019-10-22 13:58:29 +09002392 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002393 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2394 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002395 ensureListEmpty(t, provideNativeLibs)
2396 ensureListEmpty(t, requireNativeLibs)
2397
Sundong Ahnabb64432019-10-22 13:58:29 +09002398 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002399 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2400 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002401 ensureListEmpty(t, provideNativeLibs)
2402 ensureListContains(t, requireNativeLibs, "libfoo.so")
2403
Sundong Ahnabb64432019-10-22 13:58:29 +09002404 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002405 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2406 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002407 ensureListContains(t, provideNativeLibs, "libfoo.so")
2408 ensureListEmpty(t, requireNativeLibs)
2409
Sundong Ahnabb64432019-10-22 13:58:29 +09002410 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002411 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2412 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002413 ensureListContains(t, provideNativeLibs, "libfoo.so")
2414 ensureListEmpty(t, requireNativeLibs)
2415}
2416
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002417func TestApexName(t *testing.T) {
Jiyong Parkdb334862020-02-05 17:19:28 +09002418 ctx, config := testApex(t, `
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002419 apex {
2420 name: "myapex",
2421 key: "myapex.key",
2422 apex_name: "com.android.myapex",
Jiyong Parkdb334862020-02-05 17:19:28 +09002423 native_shared_libs: ["mylib"],
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002424 }
2425
2426 apex_key {
2427 name: "myapex.key",
2428 public_key: "testkey.avbpubkey",
2429 private_key: "testkey.pem",
2430 }
Jiyong Parkdb334862020-02-05 17:19:28 +09002431
2432 cc_library {
2433 name: "mylib",
2434 srcs: ["mylib.cpp"],
2435 system_shared_libs: [],
2436 stl: "none",
2437 apex_available: [
2438 "//apex_available:platform",
2439 "myapex",
2440 ],
2441 }
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002442 `)
2443
Sundong Ahnabb64432019-10-22 13:58:29 +09002444 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002445 apexManifestRule := module.Rule("apexManifestRule")
2446 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
2447 apexRule := module.Rule("apexRule")
2448 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
Jiyong Parkdb334862020-02-05 17:19:28 +09002449
2450 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2451 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2452 name := apexBundle.BaseModuleName()
2453 prefix := "TARGET_"
2454 var builder strings.Builder
2455 data.Custom(&builder, name, prefix, "", data)
2456 androidMk := builder.String()
2457 ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n")
2458 ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002459}
2460
Alex Light0851b882019-02-07 13:20:53 -08002461func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002462 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002463 apex {
2464 name: "myapex",
2465 key: "myapex.key",
2466 native_shared_libs: ["mylib_common"],
2467 }
2468
2469 apex_key {
2470 name: "myapex.key",
2471 public_key: "testkey.avbpubkey",
2472 private_key: "testkey.pem",
2473 }
2474
2475 cc_library {
2476 name: "mylib_common",
2477 srcs: ["mylib.cpp"],
2478 system_shared_libs: [],
2479 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002480 apex_available: [
2481 "//apex_available:platform",
2482 "myapex",
2483 ],
Alex Light0851b882019-02-07 13:20:53 -08002484 }
2485 `)
2486
Sundong Ahnabb64432019-10-22 13:58:29 +09002487 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002488 apexRule := module.Rule("apexRule")
2489 copyCmds := apexRule.Args["copy_commands"]
2490
2491 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
2492 t.Log("Apex was a test apex!")
2493 t.Fail()
2494 }
2495 // Ensure that main rule creates an output
2496 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2497
2498 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002499 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002500
2501 // Ensure that both direct and indirect deps are copied into apex
2502 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2503
Colin Cross7113d202019-11-20 16:39:12 -08002504 // Ensure that the platform variant ends with _shared
2505 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002506
2507 if !android.InAnyApex("mylib_common") {
2508 t.Log("Found mylib_common not in any apex!")
2509 t.Fail()
2510 }
2511}
2512
2513func TestTestApex(t *testing.T) {
2514 if android.InAnyApex("mylib_common_test") {
2515 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!")
2516 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002517 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002518 apex_test {
2519 name: "myapex",
2520 key: "myapex.key",
2521 native_shared_libs: ["mylib_common_test"],
2522 }
2523
2524 apex_key {
2525 name: "myapex.key",
2526 public_key: "testkey.avbpubkey",
2527 private_key: "testkey.pem",
2528 }
2529
2530 cc_library {
2531 name: "mylib_common_test",
2532 srcs: ["mylib.cpp"],
2533 system_shared_libs: [],
2534 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002535 // TODO: remove //apex_available:platform
2536 apex_available: [
2537 "//apex_available:platform",
2538 "myapex",
2539 ],
Alex Light0851b882019-02-07 13:20:53 -08002540 }
2541 `)
2542
Sundong Ahnabb64432019-10-22 13:58:29 +09002543 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002544 apexRule := module.Rule("apexRule")
2545 copyCmds := apexRule.Args["copy_commands"]
2546
2547 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
2548 t.Log("Apex was not a test apex!")
2549 t.Fail()
2550 }
2551 // Ensure that main rule creates an output
2552 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2553
2554 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002555 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002556
2557 // Ensure that both direct and indirect deps are copied into apex
2558 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
2559
Colin Cross7113d202019-11-20 16:39:12 -08002560 // Ensure that the platform variant ends with _shared
2561 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002562}
2563
Alex Light9670d332019-01-29 18:07:33 -08002564func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002565 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08002566 apex {
2567 name: "myapex",
2568 key: "myapex.key",
2569 multilib: {
2570 first: {
2571 native_shared_libs: ["mylib_common"],
2572 }
2573 },
2574 target: {
2575 android: {
2576 multilib: {
2577 first: {
2578 native_shared_libs: ["mylib"],
2579 }
2580 }
2581 },
2582 host: {
2583 multilib: {
2584 first: {
2585 native_shared_libs: ["mylib2"],
2586 }
2587 }
2588 }
2589 }
2590 }
2591
2592 apex_key {
2593 name: "myapex.key",
2594 public_key: "testkey.avbpubkey",
2595 private_key: "testkey.pem",
2596 }
2597
2598 cc_library {
2599 name: "mylib",
2600 srcs: ["mylib.cpp"],
2601 system_shared_libs: [],
2602 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002603 // TODO: remove //apex_available:platform
2604 apex_available: [
2605 "//apex_available:platform",
2606 "myapex",
2607 ],
Alex Light9670d332019-01-29 18:07:33 -08002608 }
2609
2610 cc_library {
2611 name: "mylib_common",
2612 srcs: ["mylib.cpp"],
2613 system_shared_libs: [],
2614 stl: "none",
2615 compile_multilib: "first",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002616 // TODO: remove //apex_available:platform
2617 apex_available: [
2618 "//apex_available:platform",
2619 "myapex",
2620 ],
Alex Light9670d332019-01-29 18:07:33 -08002621 }
2622
2623 cc_library {
2624 name: "mylib2",
2625 srcs: ["mylib.cpp"],
2626 system_shared_libs: [],
2627 stl: "none",
2628 compile_multilib: "first",
2629 }
2630 `)
2631
Sundong Ahnabb64432019-10-22 13:58:29 +09002632 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002633 copyCmds := apexRule.Args["copy_commands"]
2634
2635 // Ensure that main rule creates an output
2636 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2637
2638 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002639 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2640 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
2641 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light9670d332019-01-29 18:07:33 -08002642
2643 // Ensure that both direct and indirect deps are copied into apex
2644 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2645 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2646 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2647
Colin Cross7113d202019-11-20 16:39:12 -08002648 // Ensure that the platform variant ends with _shared
2649 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
2650 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
2651 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Alex Light9670d332019-01-29 18:07:33 -08002652}
Jiyong Park04480cf2019-02-06 00:16:29 +09002653
2654func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002655 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002656 apex {
2657 name: "myapex",
2658 key: "myapex.key",
2659 binaries: ["myscript"],
2660 }
2661
2662 apex_key {
2663 name: "myapex.key",
2664 public_key: "testkey.avbpubkey",
2665 private_key: "testkey.pem",
2666 }
2667
2668 sh_binary {
2669 name: "myscript",
2670 src: "mylib.cpp",
2671 filename: "myscript.sh",
2672 sub_dir: "script",
2673 }
2674 `)
2675
Sundong Ahnabb64432019-10-22 13:58:29 +09002676 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002677 copyCmds := apexRule.Args["copy_commands"]
2678
2679 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2680}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002681
Jooyung Han91df2082019-11-20 01:49:42 +09002682func TestApexInVariousPartition(t *testing.T) {
2683 testcases := []struct {
2684 propName, parition, flattenedPartition string
2685 }{
2686 {"", "system", "system_ext"},
2687 {"product_specific: true", "product", "product"},
2688 {"soc_specific: true", "vendor", "vendor"},
2689 {"proprietary: true", "vendor", "vendor"},
2690 {"vendor: true", "vendor", "vendor"},
2691 {"system_ext_specific: true", "system_ext", "system_ext"},
2692 }
2693 for _, tc := range testcases {
2694 t.Run(tc.propName+":"+tc.parition, func(t *testing.T) {
2695 ctx, _ := testApex(t, `
2696 apex {
2697 name: "myapex",
2698 key: "myapex.key",
2699 `+tc.propName+`
2700 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002701
Jooyung Han91df2082019-11-20 01:49:42 +09002702 apex_key {
2703 name: "myapex.key",
2704 public_key: "testkey.avbpubkey",
2705 private_key: "testkey.pem",
2706 }
2707 `)
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002708
Jooyung Han91df2082019-11-20 01:49:42 +09002709 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2710 expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex"
2711 actual := apex.installDir.String()
2712 if actual != expected {
2713 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2714 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002715
Jooyung Han91df2082019-11-20 01:49:42 +09002716 flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
2717 expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex"
2718 actual = flattened.installDir.String()
2719 if actual != expected {
2720 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2721 }
2722 })
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002723 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002724}
Jiyong Park67882562019-03-21 01:11:21 +09002725
Jooyung Han54aca7b2019-11-20 02:26:02 +09002726func TestFileContexts(t *testing.T) {
2727 ctx, _ := testApex(t, `
2728 apex {
2729 name: "myapex",
2730 key: "myapex.key",
2731 }
2732
2733 apex_key {
2734 name: "myapex.key",
2735 public_key: "testkey.avbpubkey",
2736 private_key: "testkey.pem",
2737 }
2738 `)
2739 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
2740 apexRule := module.Rule("apexRule")
2741 actual := apexRule.Args["file_contexts"]
2742 expected := "system/sepolicy/apex/myapex-file_contexts"
2743 if actual != expected {
2744 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2745 }
2746
2747 testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
2748 apex {
2749 name: "myapex",
2750 key: "myapex.key",
2751 file_contexts: "my_own_file_contexts",
2752 }
2753
2754 apex_key {
2755 name: "myapex.key",
2756 public_key: "testkey.avbpubkey",
2757 private_key: "testkey.pem",
2758 }
2759 `, withFiles(map[string][]byte{
2760 "my_own_file_contexts": nil,
2761 }))
2762
2763 testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
2764 apex {
2765 name: "myapex",
2766 key: "myapex.key",
2767 product_specific: true,
2768 file_contexts: "product_specific_file_contexts",
2769 }
2770
2771 apex_key {
2772 name: "myapex.key",
2773 public_key: "testkey.avbpubkey",
2774 private_key: "testkey.pem",
2775 }
2776 `)
2777
2778 ctx, _ = testApex(t, `
2779 apex {
2780 name: "myapex",
2781 key: "myapex.key",
2782 product_specific: true,
2783 file_contexts: "product_specific_file_contexts",
2784 }
2785
2786 apex_key {
2787 name: "myapex.key",
2788 public_key: "testkey.avbpubkey",
2789 private_key: "testkey.pem",
2790 }
2791 `, withFiles(map[string][]byte{
2792 "product_specific_file_contexts": nil,
2793 }))
2794 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2795 apexRule = module.Rule("apexRule")
2796 actual = apexRule.Args["file_contexts"]
2797 expected = "product_specific_file_contexts"
2798 if actual != expected {
2799 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2800 }
2801
2802 ctx, _ = testApex(t, `
2803 apex {
2804 name: "myapex",
2805 key: "myapex.key",
2806 product_specific: true,
2807 file_contexts: ":my-file-contexts",
2808 }
2809
2810 apex_key {
2811 name: "myapex.key",
2812 public_key: "testkey.avbpubkey",
2813 private_key: "testkey.pem",
2814 }
2815
2816 filegroup {
2817 name: "my-file-contexts",
2818 srcs: ["product_specific_file_contexts"],
2819 }
2820 `, withFiles(map[string][]byte{
2821 "product_specific_file_contexts": nil,
2822 }))
2823 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2824 apexRule = module.Rule("apexRule")
2825 actual = apexRule.Args["file_contexts"]
2826 expected = "product_specific_file_contexts"
2827 if actual != expected {
2828 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2829 }
2830}
2831
Jiyong Park67882562019-03-21 01:11:21 +09002832func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002833 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002834 apex_key {
2835 name: "myapex.key",
2836 public_key: ":my.avbpubkey",
2837 private_key: ":my.pem",
2838 product_specific: true,
2839 }
2840
2841 filegroup {
2842 name: "my.avbpubkey",
2843 srcs: ["testkey2.avbpubkey"],
2844 }
2845
2846 filegroup {
2847 name: "my.pem",
2848 srcs: ["testkey2.pem"],
2849 }
2850 `)
2851
2852 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2853 expected_pubkey := "testkey2.avbpubkey"
2854 actual_pubkey := apex_key.public_key_file.String()
2855 if actual_pubkey != expected_pubkey {
2856 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2857 }
2858 expected_privkey := "testkey2.pem"
2859 actual_privkey := apex_key.private_key_file.String()
2860 if actual_privkey != expected_privkey {
2861 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2862 }
2863}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002864
2865func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002866 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002867 prebuilt_apex {
2868 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002869 arch: {
2870 arm64: {
2871 src: "myapex-arm64.apex",
2872 },
2873 arm: {
2874 src: "myapex-arm.apex",
2875 },
2876 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002877 }
2878 `)
2879
2880 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2881
Jiyong Parkc95714e2019-03-29 14:23:10 +09002882 expectedInput := "myapex-arm64.apex"
2883 if prebuilt.inputApex.String() != expectedInput {
2884 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2885 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002886}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002887
2888func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002889 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002890 prebuilt_apex {
2891 name: "myapex",
2892 src: "myapex-arm.apex",
2893 filename: "notmyapex.apex",
2894 }
2895 `)
2896
2897 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2898
2899 expected := "notmyapex.apex"
2900 if p.installFilename != expected {
2901 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2902 }
2903}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002904
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002905func TestPrebuiltOverrides(t *testing.T) {
2906 ctx, config := testApex(t, `
2907 prebuilt_apex {
2908 name: "myapex.prebuilt",
2909 src: "myapex-arm.apex",
2910 overrides: [
2911 "myapex",
2912 ],
2913 }
2914 `)
2915
2916 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2917
2918 expected := []string{"myapex"}
Jiyong Park0b0e1b92019-12-03 13:24:29 +09002919 actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002920 if !reflect.DeepEqual(actual, expected) {
Jiyong Parkb0a012c2019-11-14 17:17:03 +09002921 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002922 }
2923}
2924
Roland Levillain630846d2019-06-26 12:48:34 +01002925func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002926 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002927 apex_test {
2928 name: "myapex",
2929 key: "myapex.key",
2930 tests: [
2931 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002932 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002933 ],
2934 }
2935
2936 apex_key {
2937 name: "myapex.key",
2938 public_key: "testkey.avbpubkey",
2939 private_key: "testkey.pem",
2940 }
2941
2942 cc_test {
2943 name: "mytest",
2944 gtest: false,
2945 srcs: ["mytest.cpp"],
2946 relative_install_path: "test",
2947 system_shared_libs: [],
2948 static_executable: true,
2949 stl: "none",
2950 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002951
2952 cc_test {
2953 name: "mytests",
2954 gtest: false,
2955 srcs: [
2956 "mytest1.cpp",
2957 "mytest2.cpp",
2958 "mytest3.cpp",
2959 ],
2960 test_per_src: true,
2961 relative_install_path: "test",
2962 system_shared_libs: [],
2963 static_executable: true,
2964 stl: "none",
2965 }
Roland Levillain630846d2019-06-26 12:48:34 +01002966 `)
2967
Sundong Ahnabb64432019-10-22 13:58:29 +09002968 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01002969 copyCmds := apexRule.Args["copy_commands"]
2970
2971 // Ensure that test dep is copied into apex.
2972 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002973
2974 // Ensure that test deps built with `test_per_src` are copied into apex.
2975 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2976 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2977 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002978
2979 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09002980 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01002981 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2982 name := apexBundle.BaseModuleName()
2983 prefix := "TARGET_"
2984 var builder strings.Builder
2985 data.Custom(&builder, name, prefix, "", data)
2986 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09002987 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2988 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2989 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2990 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
Jooyung Han214bf372019-11-12 13:03:50 +09002991 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
Jooyung Han31c470b2019-10-18 16:26:59 +09002992 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01002993 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002994}
2995
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002996func TestInstallExtraFlattenedApexes(t *testing.T) {
2997 ctx, config := testApex(t, `
2998 apex {
2999 name: "myapex",
3000 key: "myapex.key",
3001 }
3002 apex_key {
3003 name: "myapex.key",
3004 public_key: "testkey.avbpubkey",
3005 private_key: "testkey.pem",
3006 }
3007 `, func(fs map[string][]byte, config android.Config) {
3008 config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
3009 })
3010 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Jiyong Park83dc74b2020-01-14 18:38:44 +09003011 ensureListContains(t, ab.requiredDeps, "myapex.flattened")
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09003012 mk := android.AndroidMkDataForTest(t, config, "", ab)
3013 var builder strings.Builder
3014 mk.Custom(&builder, ab.Name(), "TARGET_", "", mk)
3015 androidMk := builder.String()
3016 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened")
3017}
3018
Jooyung Han5c998b92019-06-27 11:30:33 +09003019func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07003020 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09003021 apex {
3022 name: "myapex",
3023 key: "myapex.key",
3024 native_shared_libs: ["mylib"],
3025 uses: ["commonapex"],
3026 }
3027
3028 apex {
3029 name: "commonapex",
3030 key: "myapex.key",
3031 native_shared_libs: ["libcommon"],
3032 provide_cpp_shared_libs: true,
3033 }
3034
3035 apex_key {
3036 name: "myapex.key",
3037 public_key: "testkey.avbpubkey",
3038 private_key: "testkey.pem",
3039 }
3040
3041 cc_library {
3042 name: "mylib",
3043 srcs: ["mylib.cpp"],
3044 shared_libs: ["libcommon"],
3045 system_shared_libs: [],
3046 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003047 apex_available: [ "myapex" ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003048 }
3049
3050 cc_library {
3051 name: "libcommon",
3052 srcs: ["mylib_common.cpp"],
3053 system_shared_libs: [],
3054 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003055 // TODO: remove //apex_available:platform
3056 apex_available: [
3057 "//apex_available:platform",
3058 "commonapex",
3059 "myapex",
3060 ],
Jooyung Han5c998b92019-06-27 11:30:33 +09003061 }
3062 `)
3063
Sundong Ahnabb64432019-10-22 13:58:29 +09003064 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003065 apexRule1 := module1.Rule("apexRule")
3066 copyCmds1 := apexRule1.Args["copy_commands"]
3067
Sundong Ahnabb64432019-10-22 13:58:29 +09003068 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09003069 apexRule2 := module2.Rule("apexRule")
3070 copyCmds2 := apexRule2.Args["copy_commands"]
3071
Colin Cross7113d202019-11-20 16:39:12 -08003072 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
3073 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex")
Jooyung Han5c998b92019-06-27 11:30:33 +09003074 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
3075 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
3076 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
3077}
3078
3079func TestApexUsesFailsIfNotProvided(t *testing.T) {
3080 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
3081 apex {
3082 name: "myapex",
3083 key: "myapex.key",
3084 uses: ["commonapex"],
3085 }
3086
3087 apex {
3088 name: "commonapex",
3089 key: "myapex.key",
3090 }
3091
3092 apex_key {
3093 name: "myapex.key",
3094 public_key: "testkey.avbpubkey",
3095 private_key: "testkey.pem",
3096 }
3097 `)
3098 testApexError(t, `uses: "commonapex" is not a provider`, `
3099 apex {
3100 name: "myapex",
3101 key: "myapex.key",
3102 uses: ["commonapex"],
3103 }
3104
3105 cc_library {
3106 name: "commonapex",
3107 system_shared_libs: [],
3108 stl: "none",
3109 }
3110
3111 apex_key {
3112 name: "myapex.key",
3113 public_key: "testkey.avbpubkey",
3114 private_key: "testkey.pem",
3115 }
3116 `)
3117}
3118
3119func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
3120 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
3121 apex {
3122 name: "myapex",
3123 key: "myapex.key",
3124 use_vendor: true,
3125 uses: ["commonapex"],
3126 }
3127
3128 apex {
3129 name: "commonapex",
3130 key: "myapex.key",
3131 provide_cpp_shared_libs: true,
3132 }
3133
3134 apex_key {
3135 name: "myapex.key",
3136 public_key: "testkey.avbpubkey",
3137 private_key: "testkey.pem",
3138 }
Jooyung Handc782442019-11-01 03:14:38 +09003139 `, func(fs map[string][]byte, config android.Config) {
3140 setUseVendorWhitelistForTest(config, []string{"myapex"})
3141 })
Jooyung Han5c998b92019-06-27 11:30:33 +09003142}
3143
Jooyung Hand48f3c32019-08-23 11:18:57 +09003144func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
3145 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
3146 apex {
3147 name: "myapex",
3148 key: "myapex.key",
3149 native_shared_libs: ["libfoo"],
3150 }
3151
3152 apex_key {
3153 name: "myapex.key",
3154 public_key: "testkey.avbpubkey",
3155 private_key: "testkey.pem",
3156 }
3157
3158 cc_library {
3159 name: "libfoo",
3160 stl: "none",
3161 system_shared_libs: [],
3162 enabled: false,
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003163 apex_available: ["myapex"],
Jooyung Hand48f3c32019-08-23 11:18:57 +09003164 }
3165 `)
3166 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
3167 apex {
3168 name: "myapex",
3169 key: "myapex.key",
3170 java_libs: ["myjar"],
3171 }
3172
3173 apex_key {
3174 name: "myapex.key",
3175 public_key: "testkey.avbpubkey",
3176 private_key: "testkey.pem",
3177 }
3178
3179 java_library {
3180 name: "myjar",
3181 srcs: ["foo/bar/MyClass.java"],
3182 sdk_version: "none",
3183 system_modules: "none",
Jooyung Hand48f3c32019-08-23 11:18:57 +09003184 enabled: false,
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003185 apex_available: ["myapex"],
Jooyung Hand48f3c32019-08-23 11:18:57 +09003186 }
3187 `)
3188}
3189
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003190func TestApexWithApps(t *testing.T) {
3191 ctx, _ := testApex(t, `
3192 apex {
3193 name: "myapex",
3194 key: "myapex.key",
3195 apps: [
3196 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09003197 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003198 ],
3199 }
3200
3201 apex_key {
3202 name: "myapex.key",
3203 public_key: "testkey.avbpubkey",
3204 private_key: "testkey.pem",
3205 }
3206
3207 android_app {
3208 name: "AppFoo",
3209 srcs: ["foo/bar/MyClass.java"],
3210 sdk_version: "none",
3211 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09003212 jni_libs: ["libjni"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003213 apex_available: [ "myapex" ],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003214 }
Jiyong Parkf7487312019-10-17 12:54:30 +09003215
3216 android_app {
3217 name: "AppFooPriv",
3218 srcs: ["foo/bar/MyClass.java"],
3219 sdk_version: "none",
3220 system_modules: "none",
3221 privileged: true,
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003222 apex_available: [ "myapex" ],
Jiyong Parkf7487312019-10-17 12:54:30 +09003223 }
Jiyong Park8be103b2019-11-08 15:53:48 +09003224
3225 cc_library_shared {
3226 name: "libjni",
3227 srcs: ["mylib.cpp"],
Jooyung Han65041792020-02-25 16:59:29 +09003228 shared_libs: ["libfoo"],
Jiyong Park8be103b2019-11-08 15:53:48 +09003229 stl: "none",
3230 system_shared_libs: [],
Jiyong Park0f80c182020-01-31 02:49:53 +09003231 apex_available: [ "myapex" ],
Jooyung Han65041792020-02-25 16:59:29 +09003232 sdk_version: "current",
3233 }
3234
3235 cc_library_shared {
3236 name: "libfoo",
3237 stl: "none",
3238 system_shared_libs: [],
3239 apex_available: [ "myapex" ],
3240 sdk_version: "current",
Jiyong Park8be103b2019-11-08 15:53:48 +09003241 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003242 `)
3243
Sundong Ahnabb64432019-10-22 13:58:29 +09003244 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003245 apexRule := module.Rule("apexRule")
3246 copyCmds := apexRule.Args["copy_commands"]
3247
3248 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09003249 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003250
Jooyung Han65041792020-02-25 16:59:29 +09003251 appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs")
3252 // JNI libraries are uncompressed
Jiyong Park52cd06f2019-11-11 10:14:32 +09003253 if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
Jooyung Han65041792020-02-25 16:59:29 +09003254 t.Errorf("jni libs are not uncompressed for AppFoo")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003255 }
Jooyung Han65041792020-02-25 16:59:29 +09003256 // JNI libraries including transitive deps are
3257 for _, jni := range []string{"libjni", "libfoo"} {
3258 jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile()
3259 // ... embedded inside APK (jnilibs.zip)
3260 ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String())
3261 // ... and not directly inside the APEX
3262 ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so")
3263 }
Dario Frenicde2a032019-10-27 00:29:22 +01003264}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003265
Dario Frenicde2a032019-10-27 00:29:22 +01003266func TestApexWithAppImports(t *testing.T) {
3267 ctx, _ := testApex(t, `
3268 apex {
3269 name: "myapex",
3270 key: "myapex.key",
3271 apps: [
3272 "AppFooPrebuilt",
3273 "AppFooPrivPrebuilt",
3274 ],
3275 }
3276
3277 apex_key {
3278 name: "myapex.key",
3279 public_key: "testkey.avbpubkey",
3280 private_key: "testkey.pem",
3281 }
3282
3283 android_app_import {
3284 name: "AppFooPrebuilt",
3285 apk: "PrebuiltAppFoo.apk",
3286 presigned: true,
3287 dex_preopt: {
3288 enabled: false,
3289 },
3290 }
3291
3292 android_app_import {
3293 name: "AppFooPrivPrebuilt",
3294 apk: "PrebuiltAppFooPriv.apk",
3295 privileged: true,
3296 presigned: true,
3297 dex_preopt: {
3298 enabled: false,
3299 },
3300 }
3301 `)
3302
Sundong Ahnabb64432019-10-22 13:58:29 +09003303 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01003304 apexRule := module.Rule("apexRule")
3305 copyCmds := apexRule.Args["copy_commands"]
3306
3307 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
3308 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003309}
3310
Dario Freni6f3937c2019-12-20 22:58:03 +00003311func TestApexWithTestHelperApp(t *testing.T) {
3312 ctx, _ := testApex(t, `
3313 apex {
3314 name: "myapex",
3315 key: "myapex.key",
3316 apps: [
3317 "TesterHelpAppFoo",
3318 ],
3319 }
3320
3321 apex_key {
3322 name: "myapex.key",
3323 public_key: "testkey.avbpubkey",
3324 private_key: "testkey.pem",
3325 }
3326
3327 android_test_helper_app {
3328 name: "TesterHelpAppFoo",
3329 srcs: ["foo/bar/MyClass.java"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003330 apex_available: [ "myapex" ],
Dario Freni6f3937c2019-12-20 22:58:03 +00003331 }
3332
3333 `)
3334
3335 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3336 apexRule := module.Rule("apexRule")
3337 copyCmds := apexRule.Args["copy_commands"]
3338
3339 ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk")
3340}
3341
Jooyung Han18020ea2019-11-13 10:50:48 +09003342func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
3343 // libfoo's apex_available comes from cc_defaults
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003344 testApexError(t, `requires "libfoo" that is not available for the APEX`, `
Jooyung Han18020ea2019-11-13 10:50:48 +09003345 apex {
3346 name: "myapex",
3347 key: "myapex.key",
3348 native_shared_libs: ["libfoo"],
3349 }
3350
3351 apex_key {
3352 name: "myapex.key",
3353 public_key: "testkey.avbpubkey",
3354 private_key: "testkey.pem",
3355 }
3356
3357 apex {
3358 name: "otherapex",
3359 key: "myapex.key",
3360 native_shared_libs: ["libfoo"],
3361 }
3362
3363 cc_defaults {
3364 name: "libfoo-defaults",
3365 apex_available: ["otherapex"],
3366 }
3367
3368 cc_library {
3369 name: "libfoo",
3370 defaults: ["libfoo-defaults"],
3371 stl: "none",
3372 system_shared_libs: [],
3373 }`)
3374}
3375
Jiyong Park127b40b2019-09-30 16:04:35 +09003376func TestApexAvailable(t *testing.T) {
3377 // libfoo is not available to myapex, but only to otherapex
3378 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
3379 apex {
3380 name: "myapex",
3381 key: "myapex.key",
3382 native_shared_libs: ["libfoo"],
3383 }
3384
3385 apex_key {
3386 name: "myapex.key",
3387 public_key: "testkey.avbpubkey",
3388 private_key: "testkey.pem",
3389 }
3390
3391 apex {
3392 name: "otherapex",
3393 key: "otherapex.key",
3394 native_shared_libs: ["libfoo"],
3395 }
3396
3397 apex_key {
3398 name: "otherapex.key",
3399 public_key: "testkey.avbpubkey",
3400 private_key: "testkey.pem",
3401 }
3402
3403 cc_library {
3404 name: "libfoo",
3405 stl: "none",
3406 system_shared_libs: [],
3407 apex_available: ["otherapex"],
3408 }`)
3409
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003410 // libbbaz is an indirect dep
3411 testApexError(t, "requires \"libbaz\" that is not available for the APEX", `
Jiyong Park127b40b2019-09-30 16:04:35 +09003412 apex {
3413 name: "myapex",
3414 key: "myapex.key",
3415 native_shared_libs: ["libfoo"],
3416 }
3417
3418 apex_key {
3419 name: "myapex.key",
3420 public_key: "testkey.avbpubkey",
3421 private_key: "testkey.pem",
3422 }
3423
Jiyong Park127b40b2019-09-30 16:04:35 +09003424 cc_library {
3425 name: "libfoo",
3426 stl: "none",
3427 shared_libs: ["libbar"],
3428 system_shared_libs: [],
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003429 apex_available: ["myapex"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003430 }
3431
3432 cc_library {
3433 name: "libbar",
3434 stl: "none",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003435 shared_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003436 system_shared_libs: [],
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003437 apex_available: ["myapex"],
3438 }
3439
3440 cc_library {
3441 name: "libbaz",
3442 stl: "none",
3443 system_shared_libs: [],
Jiyong Park127b40b2019-09-30 16:04:35 +09003444 }`)
3445
3446 testApexError(t, "\"otherapex\" is not a valid module name", `
3447 apex {
3448 name: "myapex",
3449 key: "myapex.key",
3450 native_shared_libs: ["libfoo"],
3451 }
3452
3453 apex_key {
3454 name: "myapex.key",
3455 public_key: "testkey.avbpubkey",
3456 private_key: "testkey.pem",
3457 }
3458
3459 cc_library {
3460 name: "libfoo",
3461 stl: "none",
3462 system_shared_libs: [],
3463 apex_available: ["otherapex"],
3464 }`)
3465
3466 ctx, _ := testApex(t, `
3467 apex {
3468 name: "myapex",
3469 key: "myapex.key",
3470 native_shared_libs: ["libfoo", "libbar"],
3471 }
3472
3473 apex_key {
3474 name: "myapex.key",
3475 public_key: "testkey.avbpubkey",
3476 private_key: "testkey.pem",
3477 }
3478
3479 cc_library {
3480 name: "libfoo",
3481 stl: "none",
3482 system_shared_libs: [],
Jiyong Park9f14b9b2020-03-01 17:29:06 +09003483 runtime_libs: ["libbaz"],
Jiyong Park127b40b2019-09-30 16:04:35 +09003484 apex_available: ["myapex"],
3485 }
3486
3487 cc_library {
3488 name: "libbar",
3489 stl: "none",
3490 system_shared_libs: [],
3491 apex_available: ["//apex_available:anyapex"],
Jiyong Park9f14b9b2020-03-01 17:29:06 +09003492 }
3493
3494 cc_library {
3495 name: "libbaz",
3496 stl: "none",
3497 system_shared_libs: [],
3498 stubs: {
3499 versions: ["10", "20", "30"],
3500 },
Jiyong Park127b40b2019-09-30 16:04:35 +09003501 }`)
3502
3503 // check that libfoo and libbar are created only for myapex, but not for the platform
Jiyong Park0f80c182020-01-31 02:49:53 +09003504 // TODO(jiyong) the checks for the platform variant are removed because we now create
3505 // the platform variant regardless of the apex_availability. Instead, we will make sure that
3506 // the platform variants are not used from other platform modules. When that is done,
3507 // these checks will be replaced by expecting a specific error message that will be
3508 // emitted when the platform variant is used.
3509 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3510 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3511 // ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
3512 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")
Jiyong Park127b40b2019-09-30 16:04:35 +09003513
3514 ctx, _ = testApex(t, `
3515 apex {
3516 name: "myapex",
3517 key: "myapex.key",
3518 }
3519
3520 apex_key {
3521 name: "myapex.key",
3522 public_key: "testkey.avbpubkey",
3523 private_key: "testkey.pem",
3524 }
3525
3526 cc_library {
3527 name: "libfoo",
3528 stl: "none",
3529 system_shared_libs: [],
3530 apex_available: ["//apex_available:platform"],
3531 }`)
3532
3533 // check that libfoo is created only for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003534 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3535 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003536
3537 ctx, _ = testApex(t, `
3538 apex {
3539 name: "myapex",
3540 key: "myapex.key",
3541 native_shared_libs: ["libfoo"],
3542 }
3543
3544 apex_key {
3545 name: "myapex.key",
3546 public_key: "testkey.avbpubkey",
3547 private_key: "testkey.pem",
3548 }
3549
3550 cc_library {
3551 name: "libfoo",
3552 stl: "none",
3553 system_shared_libs: [],
3554 apex_available: ["myapex"],
3555 static: {
3556 apex_available: ["//apex_available:platform"],
3557 },
3558 }`)
3559
3560 // shared variant of libfoo is only available to myapex
Jiyong Park0f80c182020-01-31 02:49:53 +09003561 // TODO(jiyong) the checks for the platform variant are removed because we now create
3562 // the platform variant regardless of the apex_availability. Instead, we will make sure that
3563 // the platform variants are not used from other platform modules. When that is done,
3564 // these checks will be replaced by expecting a specific error message that will be
3565 // emitted when the platform variant is used.
3566 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3567 // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3568 // // but the static variant is available to both myapex and the platform
3569 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
3570 // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09003571}
3572
Jiyong Park5d790c32019-11-15 18:40:32 +09003573func TestOverrideApex(t *testing.T) {
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003574 ctx, config := testApex(t, `
Jiyong Park5d790c32019-11-15 18:40:32 +09003575 apex {
3576 name: "myapex",
3577 key: "myapex.key",
3578 apps: ["app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003579 overrides: ["oldapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003580 }
3581
3582 override_apex {
3583 name: "override_myapex",
3584 base: "myapex",
3585 apps: ["override_app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003586 overrides: ["unknownapex"],
Baligh Uddin004d7172020-02-19 21:29:28 -08003587 logging_parent: "com.foo.bar",
Baligh Uddincb6aa122020-03-15 13:01:05 -07003588 package_name: "test.overridden.package",
Jiyong Park5d790c32019-11-15 18:40:32 +09003589 }
3590
3591 apex_key {
3592 name: "myapex.key",
3593 public_key: "testkey.avbpubkey",
3594 private_key: "testkey.pem",
3595 }
3596
3597 android_app {
3598 name: "app",
3599 srcs: ["foo/bar/MyClass.java"],
3600 package_name: "foo",
3601 sdk_version: "none",
3602 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003603 apex_available: [ "myapex" ],
Jiyong Park5d790c32019-11-15 18:40:32 +09003604 }
3605
3606 override_android_app {
3607 name: "override_app",
3608 base: "app",
3609 package_name: "bar",
3610 }
Jiyong Parka519c542020-03-03 11:45:41 +09003611 `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"}))
Jiyong Park5d790c32019-11-15 18:40:32 +09003612
Jiyong Park317645e2019-12-05 13:20:58 +09003613 originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule)
3614 overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule)
3615 if originalVariant.GetOverriddenBy() != "" {
3616 t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
3617 }
3618 if overriddenVariant.GetOverriddenBy() != "override_myapex" {
3619 t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
3620 }
3621
Jiyong Park5d790c32019-11-15 18:40:32 +09003622 module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image")
3623 apexRule := module.Rule("apexRule")
3624 copyCmds := apexRule.Args["copy_commands"]
3625
3626 ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk")
3627 ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003628
3629 apexBundle := module.Module().(*apexBundle)
3630 name := apexBundle.Name()
3631 if name != "override_myapex" {
3632 t.Errorf("name should be \"override_myapex\", but was %q", name)
3633 }
3634
Baligh Uddin004d7172020-02-19 21:29:28 -08003635 if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" {
3636 t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent)
3637 }
3638
Jiyong Parka519c542020-03-03 11:45:41 +09003639 optFlags := apexRule.Args["opt_flags"]
Baligh Uddincb6aa122020-03-15 13:01:05 -07003640 ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package")
Jiyong Parka519c542020-03-03 11:45:41 +09003641
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003642 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3643 var builder strings.Builder
3644 data.Custom(&builder, name, "TARGET_", "", data)
3645 androidMk := builder.String()
Jiyong Parkf653b052019-11-18 15:39:01 +09003646 ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003647 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
3648 ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003649 ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003650 ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
Jiyong Parkf653b052019-11-18 15:39:01 +09003651 ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003652 ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
3653 ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
Jiyong Park5d790c32019-11-15 18:40:32 +09003654}
3655
Jooyung Han214bf372019-11-12 13:03:50 +09003656func TestLegacyAndroid10Support(t *testing.T) {
3657 ctx, _ := testApex(t, `
3658 apex {
3659 name: "myapex",
3660 key: "myapex.key",
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003661 native_shared_libs: ["mylib"],
Jooyung Han23b0adf2020-03-12 18:37:20 +09003662 min_sdk_version: "29",
Jooyung Han214bf372019-11-12 13:03:50 +09003663 }
3664
3665 apex_key {
3666 name: "myapex.key",
3667 public_key: "testkey.avbpubkey",
3668 private_key: "testkey.pem",
3669 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003670
3671 cc_library {
3672 name: "mylib",
3673 srcs: ["mylib.cpp"],
3674 stl: "libc++",
3675 system_shared_libs: [],
3676 apex_available: [ "myapex" ],
3677 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003678 `, withUnbundledBuild)
Jooyung Han214bf372019-11-12 13:03:50 +09003679
3680 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3681 args := module.Rule("apexRule").Args
3682 ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String())
Dario Frenie3546902020-01-14 23:50:25 +00003683 ensureNotContains(t, args["opt_flags"], "--no_hashtree")
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003684
3685 // The copies of the libraries in the apex should have one more dependency than
3686 // the ones outside the apex, namely the unwinder. Ideally we should check
3687 // the dependency names directly here but for some reason the names are blank in
3688 // this test.
3689 for _, lib := range []string{"libc++", "mylib"} {
3690 apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits
3691 nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits
3692 if len(apexImplicits) != len(nonApexImplicits)+1 {
3693 t.Errorf("%q missing unwinder dep", lib)
3694 }
3695 }
Jooyung Han214bf372019-11-12 13:03:50 +09003696}
3697
Jooyung Han58f26ab2019-12-18 15:34:32 +09003698func TestJavaSDKLibrary(t *testing.T) {
3699 ctx, _ := testApex(t, `
3700 apex {
3701 name: "myapex",
3702 key: "myapex.key",
3703 java_libs: ["foo"],
3704 }
3705
3706 apex_key {
3707 name: "myapex.key",
3708 public_key: "testkey.avbpubkey",
3709 private_key: "testkey.pem",
3710 }
3711
3712 java_sdk_library {
3713 name: "foo",
3714 srcs: ["a.java"],
3715 api_packages: ["foo"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003716 apex_available: [ "myapex" ],
Jooyung Han58f26ab2019-12-18 15:34:32 +09003717 }
3718 `, withFiles(map[string][]byte{
3719 "api/current.txt": nil,
3720 "api/removed.txt": nil,
3721 "api/system-current.txt": nil,
3722 "api/system-removed.txt": nil,
3723 "api/test-current.txt": nil,
3724 "api/test-removed.txt": nil,
3725 }))
3726
3727 // java_sdk_library installs both impl jar and permission XML
Jooyung Hana57af4a2020-01-23 05:36:59 +00003728 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han58f26ab2019-12-18 15:34:32 +09003729 "javalib/foo.jar",
3730 "etc/permissions/foo.xml",
3731 })
3732 // Permission XML should point to the activated path of impl jar of java_sdk_library
Jiyong Parke3833882020-02-17 17:28:10 +09003733 sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml")
3734 ensureContains(t, sdkLibrary.RuleParams.Command, `<library name=\"foo\" file=\"/apex/myapex/javalib/foo.jar\"`)
Jooyung Han58f26ab2019-12-18 15:34:32 +09003735}
3736
atrost6e126252020-01-27 17:01:16 +00003737func TestCompatConfig(t *testing.T) {
3738 ctx, _ := testApex(t, `
3739 apex {
3740 name: "myapex",
3741 key: "myapex.key",
3742 prebuilts: ["myjar-platform-compat-config"],
3743 java_libs: ["myjar"],
3744 }
3745
3746 apex_key {
3747 name: "myapex.key",
3748 public_key: "testkey.avbpubkey",
3749 private_key: "testkey.pem",
3750 }
3751
3752 platform_compat_config {
3753 name: "myjar-platform-compat-config",
3754 src: ":myjar",
3755 }
3756
3757 java_library {
3758 name: "myjar",
3759 srcs: ["foo/bar/MyClass.java"],
3760 sdk_version: "none",
3761 system_modules: "none",
atrost6e126252020-01-27 17:01:16 +00003762 apex_available: [ "myapex" ],
3763 }
3764 `)
3765 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
3766 "etc/compatconfig/myjar-platform-compat-config.xml",
3767 "javalib/myjar.jar",
3768 })
3769}
3770
Jiyong Park479321d2019-12-16 11:47:12 +09003771func TestRejectNonInstallableJavaLibrary(t *testing.T) {
3772 testApexError(t, `"myjar" is not configured to be compiled into dex`, `
3773 apex {
3774 name: "myapex",
3775 key: "myapex.key",
3776 java_libs: ["myjar"],
3777 }
3778
3779 apex_key {
3780 name: "myapex.key",
3781 public_key: "testkey.avbpubkey",
3782 private_key: "testkey.pem",
3783 }
3784
3785 java_library {
3786 name: "myjar",
3787 srcs: ["foo/bar/MyClass.java"],
3788 sdk_version: "none",
3789 system_modules: "none",
Jiyong Park6b21c7d2020-02-11 09:16:01 +09003790 compile_dex: false,
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09003791 apex_available: ["myapex"],
Jiyong Park479321d2019-12-16 11:47:12 +09003792 }
3793 `)
3794}
3795
Jiyong Park7afd1072019-12-30 16:56:33 +09003796func TestCarryRequiredModuleNames(t *testing.T) {
3797 ctx, config := testApex(t, `
3798 apex {
3799 name: "myapex",
3800 key: "myapex.key",
3801 native_shared_libs: ["mylib"],
3802 }
3803
3804 apex_key {
3805 name: "myapex.key",
3806 public_key: "testkey.avbpubkey",
3807 private_key: "testkey.pem",
3808 }
3809
3810 cc_library {
3811 name: "mylib",
3812 srcs: ["mylib.cpp"],
3813 system_shared_libs: [],
3814 stl: "none",
3815 required: ["a", "b"],
3816 host_required: ["c", "d"],
3817 target_required: ["e", "f"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003818 apex_available: [ "myapex" ],
Jiyong Park7afd1072019-12-30 16:56:33 +09003819 }
3820 `)
3821
3822 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
3823 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3824 name := apexBundle.BaseModuleName()
3825 prefix := "TARGET_"
3826 var builder strings.Builder
3827 data.Custom(&builder, name, prefix, "", data)
3828 androidMk := builder.String()
3829 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n")
3830 ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n")
3831 ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n")
3832}
3833
Jiyong Park7cd10e32020-01-14 09:22:18 +09003834func TestSymlinksFromApexToSystem(t *testing.T) {
3835 bp := `
3836 apex {
3837 name: "myapex",
3838 key: "myapex.key",
3839 native_shared_libs: ["mylib"],
3840 java_libs: ["myjar"],
3841 }
3842
Jiyong Park9d677202020-02-19 16:29:35 +09003843 apex {
3844 name: "myapex.updatable",
3845 key: "myapex.key",
3846 native_shared_libs: ["mylib"],
3847 java_libs: ["myjar"],
3848 updatable: true,
3849 }
3850
Jiyong Park7cd10e32020-01-14 09:22:18 +09003851 apex_key {
3852 name: "myapex.key",
3853 public_key: "testkey.avbpubkey",
3854 private_key: "testkey.pem",
3855 }
3856
3857 cc_library {
3858 name: "mylib",
3859 srcs: ["mylib.cpp"],
3860 shared_libs: ["myotherlib"],
3861 system_shared_libs: [],
3862 stl: "none",
3863 apex_available: [
3864 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003865 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003866 "//apex_available:platform",
3867 ],
3868 }
3869
3870 cc_library {
3871 name: "myotherlib",
3872 srcs: ["mylib.cpp"],
3873 system_shared_libs: [],
3874 stl: "none",
3875 apex_available: [
3876 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003877 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003878 "//apex_available:platform",
3879 ],
3880 }
3881
3882 java_library {
3883 name: "myjar",
3884 srcs: ["foo/bar/MyClass.java"],
3885 sdk_version: "none",
3886 system_modules: "none",
3887 libs: ["myotherjar"],
Jiyong Park7cd10e32020-01-14 09:22:18 +09003888 apex_available: [
3889 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003890 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003891 "//apex_available:platform",
3892 ],
3893 }
3894
3895 java_library {
3896 name: "myotherjar",
3897 srcs: ["foo/bar/MyClass.java"],
3898 sdk_version: "none",
3899 system_modules: "none",
3900 apex_available: [
3901 "myapex",
Jiyong Park9d677202020-02-19 16:29:35 +09003902 "myapex.updatable",
Jiyong Park7cd10e32020-01-14 09:22:18 +09003903 "//apex_available:platform",
3904 ],
3905 }
3906 `
3907
3908 ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) {
3909 for _, f := range files {
3910 if f.path == file {
3911 if f.isLink {
3912 t.Errorf("%q is not a real file", file)
3913 }
3914 return
3915 }
3916 }
3917 t.Errorf("%q is not found", file)
3918 }
3919
3920 ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) {
3921 for _, f := range files {
3922 if f.path == file {
3923 if !f.isLink {
3924 t.Errorf("%q is not a symlink", file)
3925 }
3926 return
3927 }
3928 }
3929 t.Errorf("%q is not found", file)
3930 }
3931
Jiyong Park9d677202020-02-19 16:29:35 +09003932 // For unbundled build, symlink shouldn't exist regardless of whether an APEX
3933 // is updatable or not
Jiyong Park7cd10e32020-01-14 09:22:18 +09003934 ctx, _ := testApex(t, bp, withUnbundledBuild)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003935 files := getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003936 ensureRealfileExists(t, files, "javalib/myjar.jar")
3937 ensureRealfileExists(t, files, "lib64/mylib.so")
3938 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3939
Jiyong Park9d677202020-02-19 16:29:35 +09003940 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
3941 ensureRealfileExists(t, files, "javalib/myjar.jar")
3942 ensureRealfileExists(t, files, "lib64/mylib.so")
3943 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3944
3945 // For bundled build, symlink to the system for the non-updatable APEXes only
Jiyong Park7cd10e32020-01-14 09:22:18 +09003946 ctx, _ = testApex(t, bp)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003947 files = getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003948 ensureRealfileExists(t, files, "javalib/myjar.jar")
3949 ensureRealfileExists(t, files, "lib64/mylib.so")
3950 ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
Jiyong Park9d677202020-02-19 16:29:35 +09003951
3952 files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
3953 ensureRealfileExists(t, files, "javalib/myjar.jar")
3954 ensureRealfileExists(t, files, "lib64/mylib.so")
3955 ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
Jiyong Park7cd10e32020-01-14 09:22:18 +09003956}
3957
Jiyong Parkd93e1b12020-02-28 15:22:21 +09003958func TestAppBundle(t *testing.T) {
3959 ctx, _ := testApex(t, `
3960 apex {
3961 name: "myapex",
3962 key: "myapex.key",
3963 apps: ["AppFoo"],
3964 }
3965
3966 apex_key {
3967 name: "myapex.key",
3968 public_key: "testkey.avbpubkey",
3969 private_key: "testkey.pem",
3970 }
3971
3972 android_app {
3973 name: "AppFoo",
3974 srcs: ["foo/bar/MyClass.java"],
3975 sdk_version: "none",
3976 system_modules: "none",
3977 apex_available: [ "myapex" ],
3978 }
Jiyong Parkaf8998c2020-02-28 16:51:07 +09003979 `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"}))
Jiyong Parkd93e1b12020-02-28 15:22:21 +09003980
3981 bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config")
3982 content := bundleConfigRule.Args["content"]
3983
3984 ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
Jiyong Parkaf8998c2020-02-28 16:51:07 +09003985 ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`)
Jiyong Parkd93e1b12020-02-28 15:22:21 +09003986}
3987
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07003988func TestMain(m *testing.M) {
3989 run := func() int {
3990 setUp()
3991 defer tearDown()
3992
3993 return m.Run()
3994 }
3995
3996 os.Exit(run())
3997}